CHANGELOG0000644000175000017500000002121513740610711012757 0ustar fredericofredericoT50 - Experimental Mixed Packet Injector Legend: + Added feature * Improved/changed feature - Bug fixed ! Known issue / missing feature T50 5.8.8 + Preliminary avoidance of CTE for Intel Processors in the Makefile. T50 5.8.7 - Fixed tcphdr.doff calculation. T50 5.8.5 - Aug 30th, 2019 * Fixed possible pointer arithmetic problems in modules * Regression: back using size_t instead of uint32_t * Improved readbility (using while loops, instead of for) T50 5.8.4 - Apr 23rd, 2019 - ^C is not shown when user stops the flooding process. T50 5.8.3 - Nov 24th, 2018 - Makefile now checks GCC version (5 or greater needed!) T50 5.8.2 - Sep 10th, 2018 - cksum() RFC 1071 compliance and endianess fixes. T50 5.8.1 - Sep 4th, 2018 * Some routines were simplified to increase performance. + Display Statistics on process termination: Number of packets and throughput (experimental). (each process will print their statistics preceeded by [PID:...]). T50 5.8 - Jun 27th, 2018 - Lots of fields were in little endian format (Intel platforms); - TCP option --ack-seq wasn't being evaluated at command line; - TCP option --sequence wasn't being evaluated at command ilne; - TCP option --data-offset wasn't being evaluated at command line; - TCP option --urg-pointer wasn't being evaluated at command line; - Corrected range checkings for options; - Checksums were in little endian format as well (Intel platforms); * Make sure functions with more than one pointer as arguments have __restrict__ keyword in all of them. This is a hint to the compiler optimization routines in C99/C11. * Makefile compile and link options changed -z norelro and -z execstack were reported to cause freezes; * Using -ftree-vectorize only for x86-64 (Intel), 'cause not all i386 supports SIMD. T50 5.7.3 - Jun 19th, 2018 * No more GNU Build System. Plain Makefile, bogus configuration script and maintainer's setversion.sh. Version configuration are in src/include/configuration.h file. - Forgot to enable USE_ANSI feature on Makefile. * Added execstack and norelro options to linker (smaller executable). T50 5.7.2 - Apr 29th, 2018 - When configuring with --enable-debug, lots of compile erros occur. fixed! * Prefeer to use RDRAND on Intel platforms, if it's implemented. * Simplification of randomizer functions due to the fact that RDRAND is, at least, 4 times faster than xorshift128+. T50 5.7.1 - Mar 9th, 2018 * Changed size_t types from some functions to uint32_t. T50 5.7.0 - Jul 26th, 2017 - Some IP addresses were in LITTLE ENDIAN format. * Improvements on configure.ac T50 5.6.15 - Jun 27th, 2017 T50 5.6.14 - Jun 26th, 2017 - Some bugs on inline assembly (SRANDOM()) syntax fixed. T50 5.6.13 - May 16th, 2017 + Added --shuffle option for T50 PROTOCOL, otherwise all protocols will be sent in the same sequence given by --list-protocols option. * SRANDOM() now uses RDRAND instruction for x86 machines, if available. * Got rid of get_number_of_registered_modules() function. The global var num_of_modules is available to that purpose. * Man page updated. - The command line bug is fixed... T50 5.6.12 - May 12th, 2017 - Minor bugs solved. * Made get_ordinal_suffix() smaller. ! OSPF protocol code is now more "readable". * Changed "hard coded" tests on configure.ac, using autoconf extensions. T50 5.6.11 - May 8th, 2017 * __RND, IPPORT_RND and IPADDR_RND macros now will only respect endianess if the returning value is not RANDOM. T50 5.6.10 - May 5th, 2017 * Changed the Linear Congruential Pseudo Number Generator by XorShift128+. T50 5.6.9 - April 18th, 2017 * Got rid of some asserts. * configure script improved. * Manpage updated. T50 5.6.8 - April 11th, 2017 * Total source code refactoring to better distribute the functions. * Got rid of common.h header file. * Added -fno-stack-protection option on compilation. * Changes on header files "namespaces" to avoid confusion with system's header files (added t50_ prefix). T50 5.6.7 - September 1st, 2016 * Checks for Linux on configure script * Uses compiler processor's optimizations options only for x86-64 and i?86. T50 5.6.6 - August, 2016 - Fixed a bug on command line parser. T50 5.6.3 - May 30th, 2016 * Project now compiles and installs with GNU Build System help. * Compiler option -mtune=native changed to -march=native. SSE options for i386 not necessary anymore. T50 5.5 - March 19th, 2016 * Minor fixes * Added comments to the code (for developers) T50 5.5 - March 16th, 2016 * SIGTSTP and SIGTRAP are now blocked. - Some nasty bugs based on kl0nEz discovery fixed. - A nasty bug detected by kl0nEz (shell crash!) was corrected. T50 5.5 - December 18th, 2015 + Added experimental xorshift128+ pseudo random number generator routine. T50 5.5 - December 1st, 2015 - The PRNG now generates 32 bit unsigned numbers. * t50.c changed to main.c T50 5.5 - February 3rd, 2015 ! Changed the behavior of signals from RESTART to INTERRUPT. * The raw socket is NON BLOCKING now. ! Improved command line parser: No more duplicated options accepted! --protocol is case insensitive now. - Add call to tcp_help() to usage(). * Support for RDRAND and BMI2 instruction set added. - Small bug when calculating IP address on t50.c fixed + Added some "post-mortem" debug routines * If sendto's errno is EPERM, show permission error message asking to check firewall settings. - Fixed bugs of modules memory allocations. * Code compiles fine with LLVM clang 3.x; * SSE is enabled by default in x86-64 architecture (commented on Makefile); * Changed return type of module funcions; * Small corrections on modules functions; * All files were converted to UNIX text format; * gre_encapsulation() was still not used on ospf.c; - Calls to sendto with second parameter were wrong; * Function ip_header() added to modules/ip.c. - On embeded systems the use of VLAs (Variable Length Arrays) in modules functions can be hazardous due to restricted stack space. "Differential" buffer reallocation on heap fix this problem; * cksum() 5 times faster now (summing QWORDs, DWORDs WORDs and BYTES, in that order); * Using a trick to deal with pointers of multiple types on modules functions; * New Makefile (still needs some tweaks) for better incremental compiling; * Minor fix on getOrdinalSuffix() function, no t50.c (11, 12 & 13 have a "th" suffix!). + Added comments with FIX, FIXME, NOTE prefix for better code reading. * Changed the way modules table are declared. See modules.c for advice. * Module table are not order dependant anymore! * Created src/help directory and src/include/help.h header to improve module "modularity". * Host name now can be a partial IP or name, optionally followed by "/cidr". Partial IP have the format 'a(.b(.c(.d)))'. Formats as 'a.b./cidr' are invalid. ! if a name or a full IP is given, the default cidr is 32. T50 will fail showing the message: "CIDR must be between 8 and 30.". - CIDR bug above fixed by Fernando Mercês. * socket descriptor isolated from anyone except sock.c. * "modules" just manipulates the packet buffer. main() actually sends the packet. * 'stdout' is now unbuffered on initialization. To avoid line buffer behavior oddities (if any). * Added -std=gnu99 to CFLAGS, on Makefile. ! Possible wrong way to calculate threshold for turbo mode. - Threshold bugs fixed. ! Possible wrong way to threat SIGCHLD signal. - Added a SIGALRM handler and a timeout of 5 seconds when main process waits for child. T50 5.4.1 - August 11th, 2013 - Fixed bug in option parsing. - Fixed license missing in some files. * Depecrecation of gethostbyname() - thanks to Cooler * Improved code, reduced memory consumption - thanks to Frederico Pissara * Improved Makefile, reduced compilation time, use of SS3 instructions. * Removed private IP address restriction. - Manpage moved to section 8. + Strip set by default. T50 5.4.0 - September 4th, 2011 + New version scheme . + Added manpage. * UPX and strip removed. * License limitations removed. * Removed libmath dependency. * New smaller Makefile reducing compile time. Many flags removed. ! We don't have support for IPv6 yet. ! T50 may not compile in other systems nor GNU/Linux distros. T50 5.3 - April 9th, 2011 + New License: it is, finally, licensed under GPL v2.0. Please, refer to LICENSE document for further information. + CIDR Support: Classless Inter-Domain Routing support for destination IP address, using a really tiny C algorithm. This would allow the new version to simulate DDoS in a laboratory environment. + New protocols support: IGMP, EGP, RIP, DCCP, RSVP, IPSec, GRE, EIGRP and OSPF. + TCP Options support. T50 2.45 - November 10th, 2010 First public release. LICENSE0000644000175000017500000004325513712774300012566 0ustar fredericofrederico GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. Makefile0000664000175000017500000001076314107316050013212 0ustar fredericofrederico# # __________ ________ _____ # |__ ___/| ____/ / _ \ the fastest packet injector. # | | |____ \ / /_\ \ # | | / \\ \_/ \ # |____| /________/\\_______/ # # NOTE: I've got rid of autoconf 'cause there is a dependency there. # This way you don't need anything other than this makefile to # compile the project. VERSION=5.8.7b #CC=gcc # # OBS: T50 will compile only on GCC 5 or above. If you are feeling lucky, # try GCC 4.9 or CLANG... But I don't recomended. # LD=$(CC) INCLUDEDIR=src/include CFLAGS=-std=gnu11 -I $(INCLUDEDIR) LDFLAGS= LDLIBS= # Just define DEBUG environment var to compile for debugging: # # $ DEBUG=1 make # ifdef DEBUG CFLAGS += -O0 -g else # Optimization level 2 (better results) and no canaries. CFLAGS += -O2 -DNDEBUG -ffast-math # strip symbols and turn more linker optimizations on (if available). LDFLAGS += -s -O2 ARCHITECTURE = $(shell arch) IS_GCC = $(shell $(CC) -v 2>&1 | sed -nE 's/^(.+) version.+$$/\1/p') CC_VERSION = $(shell $(CC) -v 2>&1 | sed -nE 's/^.+version (.).+$$/\1/p') # Options for x86-64 ifeq ($(ARCHITECTURE),x86_64) CFLAGS += -march=native -mtune=native -ftree-vectorize -flto -fno-stack-protector -mstringop-strategy=rep_byte # Avoid CTE on Intel Platforms. # Currently works on GCC 9+ (don't know if works on clang). ifeq ($(IS_GCC),gcc) ifeq ($(shell expr $(CC_VERSION) \>= 9),1) CFLAGS += -fcf-protection=none endif endif LDFLAGS += -flto endif # Options for i386 ifeq ($(ARCHITECTURE),i686) CFLAGS += -march=native -mtune=native -flto -fno-stack-protector -mstringop-strategy=rep_byte # Avoid CTE on Intel Platforms. # Currently works on GCC 9+ (don't know if works on clang). ifeq ($(IS_GCC),gcc) ifeq ($(shell expr $(CC_VERSION) \>= 9),1) CFLAGS += -fcf-protection=none endif endif LDFLAGS += -flto endif # TODO: tunning for arm-cortex-a7? (Raspberry PI?) # TODO: aarch64?! # Options for ARMv7-a ifneq ($(findstring armv7,$(ARCHITECTURE)),) CFLAGS += -march=armv7-a -fno-stack-protector -flto LDFLAGS += -flto endif # Options for ARMv8-a ifneq ($(findstring armv8,$(ARCHITECTURE)),) CFLAGS += -march=armv8-a -fno-stack-protector -flto LDFLAGS += -flto endif endif # Added to use ANSI CSI codes (beautifier). ifdef USE_ANSI CFLAGS += -DUSE_ANSI endif EXECUTABLE=bin/t50 OBJECTS=\ src/cidr.o \ src/cksum.o \ src/config.o \ src/errors.o \ src/main.o \ src/memalloc.o \ src/modules.o \ src/netio.o \ src/randomizer.o \ src/shuffle.o \ src/usage.o \ src/help/egp_help.o \ src/help/eigrp_help.o \ src/help/general_help.o \ src/help/gre_help.o \ src/help/icmp_help.o \ src/help/igmp_help.o \ src/help/ip_help.o \ src/help/ipsec_help.o \ src/help/ospf_help.o \ src/help/rip_help.o \ src/help/rsvp_help.o \ src/help/tcp_udp_dccp_help.o \ src/modules/dccp.o \ src/modules/egp.o \ src/modules/eigrp.o \ src/modules/gre.o \ src/modules/icmp.o \ src/modules/igmpv1.o \ src/modules/igmpv3.o \ src/modules/ip.o \ src/modules/ipsec.o \ src/modules/ospf.o \ src/modules/ripv1.o \ src/modules/ripv2.o \ src/modules/rsvp.o \ src/modules/tcp.o \ src/modules/udp.o .PHONY: all clean distclean dist install uninstall all: $(EXECUTABLE) # Now we'll compile to ./bin/ directory! # Explicit rule needed 'cause we have multiple objects. $(EXECUTABLE): $(OBJECTS) $(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS) # Implicit rules (all .c files will be compiled!) src/%.o: src/%.c src/help/%.o: src/help/%.c src/modules/%.o: src/modules/%.c # 'clean' only deletes the object files. clean: @echo 'Deleting .o files...' -find src/ -type f -name '*.o' -delete # distclean delete the object files AND the executable. distclean: clean -rm $(EXECUTABLE) dist/*.gz dist/*.asc # Shortcut to check if user has root privileges. define checkifroot if [ `id -u` -ne 0 ]; then \ echo 'Need root privileges!'; \ exit 1; \ fi endef # install and uninstall rules are very simple! install: @$(call checkifroot) @if [ ! -e "$(EXECUTABLE)" ]; then \ echo "Try 'make' first."; \ exit 1; \ fi; cp bin/t50 /sbin/; cp doc/t50.8 /usr/share/man/man8/; \ chown root: /sbin/t50 /usr/share/man/man8; \ chmod 4750 /sbin/t50; \ gzip -9 /usr/share/man/man8/t50.8; \ chmod 0644 /usr/share/man/man8/t50.8.gz uninstall: @$(call checkifroot) rm /sbin/t50 /usr/share/man/man8/t50.8.gz # Needed to build the project source tarball (no signature generation here). dist: distclean tar -czvf dist/t50-$(VERSION).tar.gz --exclude=*.tar.gz --exclude=*.asc * README.md0000644000175000017500000001156413712774300013036 0ustar fredericofrederico``` __________ ________ _____ |__ ___/| ____/ / _ \ the fastest packet injector. | | |____ \ / /_\ \ | | / \\ \_/ \ |____| /________/\\_______/ ``` T50 (f.k.a. F22 Raptor) is a tool designed to perform "Stress Testing". The concept started on 2001, right after release 'nb-isakmp.c', and the main goal was: * Having a tool to perform TCP/IP protocol fuzzer, covering common regular protocols, such as: ICMP, TCP and UDP. Things have changed, and the T50 became a good unique resource capable to perform "Stress Testing". And, after checking the "/usr/include/linux", some protocols were chosen to be part of its coverage: * ICMP - Internet Control Message Protocol * IGMP - Internet Group Management Protocol * TCP - Transmission Control Protocol * UDP - User Datagram Protocol Why "Stress Testing"? Well, because when people are designing a new network infra-structure (eg. Datacenter serving to Cloud Computing) they think about: * High-Availability * Load Balancing * Backup Sites (Cold Sites, Hot Sites, and Warm Sites) * Disaster Recovery * Data Redundancy * Service Level Agreements * Etc... But almost nobody thinks about "Stress Testing", or even performs any test to check how the networks infra-structure behaves under stress, under overload, and under attack. Even during a Penetration Test, people prefer not running any kind of Denial-of-Service testing. Even worse, those people are missing one of the three key concepts of security that are common to risk management: * Confidentiality * Integrity * AVAILABILITY T50 was designed to perform “Stress Testing” on a variety of infra-structure network devices (Version 2.45), using widely implemented protocols, and after some requests it was was re-designed to extend the tests (as of Version 5.3), covering some regular protocols (ICMP, TCP and UDP), some infra-structure specific protocols (GRE, IPSec and RSVP), and some routing protocols (RIP, EIGRP and OSPF). T50 is a powerful and unique packet injector tool, which is capable to: 1. Send sequentially the following fifteen (15) protocols: * ICMP - Internet Control Message Protocol * IGMPv1 - Internet Group Management Protocol v1 * IGMPv3 - Internet Group Management Protocol v3 * TCP - Transmission Control Protocol * EGP - Exterior Gateway Protocol * UDP - User Datagram Protocol * RIPv1 - Routing Information Protocol v1 * RIPv2 - Routing Information Protocol v2 * DCCP - Datagram Congestion Control Protocol * RSVP - Resource ReSerVation Protocol * GRE - Generic Routing Encapsulation * IPSec - Internet Protocol Security (AH/ESP) * EIGRP - Enhanced Interior Gateway Routing Protocol * OSPF - Open Shortest Path First 2. It is the only tool capable to encapsulate the protocols (listed above) within Generic Routing Encapsulation (GRE). 3. Send an (quite) incredible amount of packets per second, making it a "second to none" tool: * More than 1,000,000 pps of SYN Flood (+50% of the network uplink) in a 1000BASE-T Network (Gigabit Ethernet). * More than 120,000 pps of SYN Flood (+60% of the network uplink) in a 100BASE-TX Network (Fast Ethernet). * Perform "Stress Testing" on a variety of network infrastructure, network devices and security solutions in place. * Simulate "Distributed Denial-of-Service" & "Denial-of-Service" attacks, validating Firewall rules, Router ACLs, Intrusion Detection System and Intrusion Prevention System policies. The main differentiator of the T50 is that it is able to send all protocols, sequentially, using one single SOCKET, besides it is capable to be used to modify network routes, letting IT Security Professionals performing advanced "Penetration Test". ##HOW TO INSTALL ```bash $ make $ sudo make install ``` ##COMPILE OPTIONS Define environment variable DEBUG before compiling if you don't want full optimizations to take place and symbols linked on executable. Define USE_ANSI if you want some colorized texts, using ANSI CSI escape codes. Example: ```bash $ USE_ANSI=1 make ``` ##CHECKING TARBALL AUTHENTICITY I will attach a signature file for T50 tarballs on SourceForge. To get my public key with GPG: ```bash $ gpg --recv-keys fredericopissarra@gmail.com ``` Here, my actual public key fingerprint: ``` pub 4096R/C09C2054 2016-10-06 [expires: 2019-10-06] Key fingerprint = 11A5 2C9C E02A 24AA EBFC 046B 20AA 0246 C09C 2054 uid Frederico Lamberti Pissarra sub 4096R/F9AA8B75 2016-10-06 [expires: 2019-10-06] ``` After downloading the tar.gz file (f.i, t50-5.8.tar.gz), get the .asc file as well. To verify if the tarball is authentic, just type the following command: ```bash $ gpg --verify t50-5.8.tar.gz.asc t50-5.8.tar.gz gpg: Signature made Qua 25 Abr 2018 16:46:52 -03 using RSA key ID C09C2054 gpg: Good signature from "Frederico Lamberti Pissarra " ``` TODO0000644000175000017500000000147213712774300012244 0ustar fredericofredericoT50 - Experimental Mixed Packet Injector Legend: - Code unrelated + Code related * Ideas (t50 code unrelated) % Ideas (t50 code related) April 2nd, 2015 + Improve support for ports list on --dport option (maybe round robin?) % Add support for network interface binding. March 1st, 2014 - Improve t50 manpage documentation - Create some standard test scripts - Create DEB and RPM packaging (binary, dev and source packages. Maybe an PPA for Ununtu and repository for Debian too!) - Incorporate packaging on Makefile + Support for IPv6? + Are there any new protocols to implement? + Support for OS/X and BSD (and, "maybe", Windows)? % Add criteria "tcpdump" like on command line? % Change "fork()" use to pthreads (thinking on Windows port)? * Non Web GUI (using GTK+, since there is support for "Windows"!)? bin/0000755000175000017500000000000014107315626012321 5ustar fredericofredericobin/delete-me0000644000175000017500000000000013712774300014072 0ustar fredericofredericoconfigure0000755000175000017500000000063213712774300013460 0ustar fredericofrederico#/bin/sh # Checks if all necessary dependencies are in place. unset ERROR if ! which make > /dev/null 2>&1; then echo 'make needed...'; ERROR=1; fi if ! which gzip > /dev/null 2>&1; then echo 'gzip needed...'; ERROR=1; fi if [ ${ERROR} ]; then echo 'Packages missing. Aborted.' exit 1 fi cat <<@@ To comple and install: $ make $ sudo make install To uninstall: $ sudo make uninstall @@ exit 0 dist/0000755000175000017500000000000014107316345012513 5ustar fredericofredericodist/signdist.sh0000755000175000017500000000013013712774300014670 0ustar fredericofrederico#!/bin/bash if [ -z "$1" ]; then echo Usage: $0 filename exit 1 fi gpg2 -sab "$1" dist/delete-me0000644000175000017500000000000013712774300014265 0ustar fredericofredericodoc/0000755000175000017500000000000013753750665012332 5ustar fredericofredericodoc/README.modules0000644000175000017500000003224213712774300014647 0ustar fredericofredericoHow to create a new module for T50 Suppose you want to add a new protocol for packet injection on T50. Let's say you want to add "Stream Control Transport Protocol" (SCTP). For this example I choose this protocol because it's defined in header as IPPROTO_SCTP. You can code any protocol you want. But if your protocol description (IPPROTO_xxx) isn't available on standard header files, you *MUST* create your own definition on 'src/include/defines.h' file. The IPPROTO_T50 definition, for instance, is defined there. Adding a module is a 5 step process: ** STEP 1: The first step is to create a module that re-allocate, fills the packet buffer and returns the packet buffer size to the caller. All module routines *MUST* follow the signature defined in "typedefs.h": ┌────────────────────────────────────────────────────────────────────────────────────────────────┐ │ typedef void (*module_func_ptr_t)(const struct config_options * const __restrict__, size_t *); │ └────────────────────────────────────────────────────────────────────────────────────────────────┘ Your module *MUST* be created in src/modules/ directory as 'sctp.c'. You *SHOULD* code something like this: ┌──────────────────────────────────────────────────────────────────────────────┐ │ #include /* Include all t50 definitions and prototypes. */ │ │ │ │ static void fill_sctp(void *buffer); │ │ static size_t get_sctp_buffer_size(void); │ │ │ │ /* This is the module! */ │ │ void sctp(const struct config_options * const __restrict__ co, size_t *size) │ │ { │ │ /* Working pointers to the buffer */ │ │ struct iphdr *ip; │ │ │ │ /* Get the packet size */ │ │ *size = sizeof(struct iphdr) + get_sctp_buffer_size(); │ │ │ │ /* Tries to reallocate space for the packet buffer, if necessary. */ │ │ alloc_packet(*size); │ │ │ │ /* Fill IP header */ │ │ ip = ip_header(packet, *size, │ │ │ │ fill_sctp(packet + sizeof(struct iphdr)); │ │ } │ │ │ │ /* This will fill the buffer part of sctp protocol. */ │ │ static void fill_sctp(void *buffer, size_t size) { ... } │ │ │ │ /* This is only an example! */ │ │ #define SCTP_SIZE 524 │ │ static size_t get_sctp_buffer_size(void) { return SCTP_SIZE; } │ └──────────────────────────────────────────────────────────────────────────────┘ Notice that "packet" is a global pointer to the packet buffer used by all modules. It is necessary to reallocate the buffer for every module, since the previous module who use it could leave a very small buffer behind. Any protocol specific structures, types *SHOULD* be defined in a separated header file 'sctp.h' in 'src/include/protocol/' directory and this header *MUST* be added to '/src/include/common.h' file. The prototype of the module function *MUST* be added to 'src/include/modules.h' file: ┌───────────────────────────────────────────────────────────────────────────────┐ │ extern void sctp(const struct config_options * const __restrict__, size_t *); │ └───────────────────────────────────────────────────────────────────────────────┘ Take a look at the actual modules. They are a little more complicated than this, but essentially, that's all they do. ** STEP 2: Create an entry on 'src/modules.c'. You *MUST* add a line like this before END_MODULES_TABLE declaration: ┌────────────────────────────────────────────────────────────────────────────────┐ │ MODULE_ENTRY(IPPROTO_SCTP, "SCTP","Stream Control Transport Protocol", sctp) │ │ END_MODULES_TABLE │ └────────────────────────────────────────────────────────────────────────────────┘ This way T50 now knows how to fill the packet for your protocol. ** STEP 3: Change config_options structure on 'src/config.c' and 'src/include/config.h'. Let's say that SCTP needs only one item called 'tag' (a 32 bits value) that could be a random value. You can add a new structure on config_options: ┌───────────────────────────────────────────────────────────────────────────┐ │ struct { │ │ uint32_t tag; │ │ } sctp; │ └───────────────────────────────────────────────────────────────────────────┘ OBS: The "random" part depends on the module. The macro __RND(), defined in 'src/include/defines.h' will return an random value if its parameter is 0. You acn use this on your function to garantee an random value if this 'tag' is informed as 0 or not informed at all in the command line. Now, add an OPTION_SCTP_TAG in the enumeration at the beggining of config.h file. Add a default value to config_options 'co' variable at config.c, if you need something different from 0. Add an entry called 'sctp-tag' on long_opt array to allow you to change this value through the command line: ┌───────────────────────────────────────────────────────────────────────────┐ │ { "sctp-tag", required_argument, NULL, OPTION_SCTP_TAG }, │ └───────────────────────────────────────────────────────────────────────────┘ And, finally, change getConfigOptions() function, adding a 'case' inside the 'switch(cli_opts)' block, like this: ┌───────────────────────────────────────────────────────────────────────────┐ │ case OPTION_SCTP_TAG: co.sctp.tag = atoi(optarg): break; │ └───────────────────────────────────────────────────────────────────────────┘ ** STEP 4 Create a routine showing the usage for SCTP protocol options and put it on sctp_help.c at 'src/help/' directory: ┌─────────────────────────────────────────────────────────────────────────────────────────────────┐ │ void sctp_help(void) │ │ { │ │ puts("SCTP Options:\n" │ │ " --sctp-tag NUM SCTP tag number (default RANDOM)\n"); │ │ } │ └─────────────────────────────────────────────────────────────────────────────────────────────────┘ To keep the standard, the first line starts with a description of the protocol followed by "Options:". The following lines are formated as (printf style): " --%-23s %-32s (default: %s)\n" Where the first string (max 23 chars) is the option. The second string (32 chars max) is a small description and the last string is a numeric value or "RANDOM", depending of what you did in config_options 'co' and your module. After creating the sctp_help() functiom, put a call on the usage routine at 'src/usage.c': ┌───────────────────────────────────────────────────────────────────────────────┐ │ ... │ │ rsvp_help(); │ │ ipsec_help(); │ │ eigrp_help(); │ │ ospf_help(); │ │ sctp_help(); /* Added sctp help */ │ └───────────────────────────────────────────────────────────────────────────────┘ ** STEP 5 (FINAL) Modify the Makefile adding the object filename (sctp.o) file location on OBJS var: ┌────────────────────────────────────────────────────────────────────────────────┐ │ ... │ │ $(OBJ_DIR)/modules/igmpv1.o \ │ │ $(OBJ_DIR)/modules/icmp.o \ │ │ $(OBJ_DIR)/modules/sctp.o \ <-- here! │ │ $(OBJ_DIR)/common.o \ │ │ ... │ └────────────────────────────────────────────────────────────────────────────────┘ And test everything trying to compile the project: $ make Don't forget to compile in DEBUG mode and test everything with your favorite debugger: $ DEBUG=1 make $ sudo gdb release/t50 Good luck! Frederico Lamberti Pissarra April 3rd, 2014 doc/DOWNLOAD.md0000644000175000017500000000057313712774300014053 0ustar fredericofredericoDownload and Installing {#download} ======================= Download T50 source code from sourceforge at http://t50.sf.net or from GitLab at http:://gitlab.com/fredericopissarra/t50 To compile and install just do:
  $ make
  $ sudo make install
To run t50 you'll need to have root privileges. For instance:
  $ sudo t50 --threshold 10 10 192.168.10.3
doc/t50.80000644000175000017500000001106413712774300013020 0ustar fredericofrederico.TH T50 8 2018-09-5 "5.8" "T50 man page" .SH NAME T50 - network packet injector .SH SYNOPSIS .B t50 [options] [\-\-] .IR host[/CIDR] .SH DESCRIPTION Experimental mixed packet injector tool. This is NOT a DoS tool, but a tool to inject packets using various protocols. .SH OPTIONS .TP .BI host[/CIDR] The host address is the target of T50. It can be informed in one of two formats: IP address or URI name. This address can be informed as a range of IPs (by omitting one or mode octects) or using a CIDR separating the IP (full or partial) or URI with "/##", for instance: "192.168/16" or "host.com.local/22". When using a partial IP address T50 will calculate CIDR automatically (8, 16 or 24 bits, if the first, second or third octect [from right to left] are omitted, respectively). Notice that, sometimes, the "host[/CIDR]" argument is misinterpreted as an option. When this happens, you can use the pseudo option '--' before the host address: .IP # t50 --flood -- 192.168.1.32/27 Also, to avoid this error you can provide the host address as the first argument. Notice, also, ONLY IPv4 addresses are allowed. T50 don't provide IPv6 support yet. .TP .BR \-\-threshold " NUM" Number of packets to inject (default 1000). .TP .BR \-\-flood Keep injecting packets until user terminates the process (^C). Cannot be used with \-\-threshold. .TP .BR \-B ", " \-\-bogus-csum Use a bogus "random " checksum instead of calculating the actual packet checksum. .TP .BR \-\-turbo Inject packets faster (creates a child process). .TP .BR \-\-shuffle When used with T50 "protocol", it will shuffle the available protocols. Otherwise they will be sent in the same order as listed with \-\-list-protocols option. This option will not work with any other "protocol". .TP .BR \-s ", " \-\-saddr " ADDR" IP header source address (default RANDOM). .TP .BR \-p ", " \-\-protocol " protoname" Select an specific protocol to use (default: TCP. Use \-\-list-protocols to see all protocols available). Use T50 if you want to inject all available protocols. The "protocolname" is case insensitive. .TP .BR \-h ", " \-\-help Display all available options and their defaults. .TP .BR \-v ", " \-\-version Display t50 version. .TP .BR \-l ", " \-\-list-protocols Lists all available protocols T50 can provide. .SH EXAMPLES See all available protocols: .IP .nf # t50 -l T50 Experimental Mixed Packet Injector Tool 5.6.15 Originally created by Nelson Brito Previously maintained by Fernando Mercês Maintained by Frederico Lamberti Pissarra [INFO] List of supported protocols (--protocol): 1 - ICMP (Internet Control Message Protocol) 2 - IGMPv1 (Internet Group Message Protocol v1) 3 - IGMPv3 (Internet Group Message Protocol v3) 4 - TCP (Transmission Control Protocol) 5 - EGP (Exterior Gateway Protocol) 6 - UDP (User Datagram Protocol) 7 - RIPv1 (Routing Internet Protocol v1) 8 - RIPv2 (Routing Internet Protocol v2) 9 - DCCP (Datagram Congestion Control Protocol) 10 - RSVP (Resource Reservation Protocol) 11 - IPSEC (Internet Security Protocl (AH/ESP)) 12 - EIGRP (Enhanced Interior Gateway Routing Protocol) 13 - OSPF (Open Shortest Path First) .fi .PP Send 500 packets to a single target: .IP # t50 192.168.0.100 --threshold 500 .PP Flooding targets from 192.168.0.1 to 192.168.0.254 (notice the partial IP) with TCP packets: .IP # t50 192.168.0 --flood .PP Flooding targets from 192.168.0.1 to 192.168.255.254 with all protocols T50 can provide in a random order using "Turbo" mode. .IP # t50 192.168 --flood -p t50 --shuffle --turbo .SH NOTES Root privilege is mandatory to run t50. .P There are lots of options. Please, use -h or --help to see them and their default values. .SH BUGS As noted before, the "host[/CIDR]" argument sometimes is misinterpreted as an option. This bug was introduced when the argument parser was changed to support flexible host "names". Someday I'll correct this (Frederico). .SH AUTHORS Nelson Brito .SH CONTRIBUTORS Fernando Mercês .br Frederico Lamberti Pissarra .SH BUGS and SOURCE CODE AVAILABILITY The latest release of the source code can be downloaded at: .UR https://\:gitlab.com/\:fredericopissarra/\:t50 T50 GitLab Repository .UE \. You can also report bugs there or at t50-dev google group via t50-dev@googlegroups.com (but gitlab's is preferable!). .SH COPYRIGHT Copyright © 2014-2018 T50 developers. Licensed GPLv3+: GNU GPL version 3 or later . This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. doc/README.md0000644000175000017500000001073313712774300013600 0ustar fredericofredericoHome {#mainpage} ====
      __________ ________  _____
     |__    ___/|   ____/ /  _  \ the fastest packet injector.
       |    |   |____  \ /  /_\  \
       |    |   /       \\\  \\_/   \
       |____|  /________/ \\_______/
T50 (f.k.a. F22 Raptor) is a tool designed to perform "Stress Testing". The concept started on 2001, right after release 'nb-isakmp.c', and the main goal was: - Having a tool to perform TCP/IP protocol fuzzer, covering common regular protocols, such as: ICMP, TCP and UDP. Things have changed, and the T50 became a good unique resource capable to perform "Stress Testing". And, after checking the "/usr/include/linux", some protocols were chosen to be part of its coverage: a) ICMP - Internet Control Message Protocol b) IGMP - Internet Group Management Protocol c) TCP - Transmission Control Protocol d) UDP - User Datagram Protocol Why "Stress Testing"? Well, because when people are designing a new network infra-structure (eg. Datacenter serving to Cloud Computing) they think about: a) High-Availability b) Load Balancing c) Backup Sites (Cold Sites, Hot Sites, and Warm Sites) d) Disaster Recovery e) Data Redundancy f) Service Level Agreements g) Etc... But almost nobody thinks about "Stress Testing", or even performs any test to check how the networks infra-structure behaves under stress, under overload, and under attack. Even during a Penetration Test, people prefer not running any kind of Denial-of-Service testing. Even worse, those people are missing one of the three key concepts of security that are common to risk management: - Confidentiality - Integrity - AVAILABILITY T50 was designed to perform “Stress Testing” on a variety of infra-structure network devices (Version 2.45), using widely implemented protocols, and after some requests it was was re-designed to extend the tests (as of Version 5.3), covering some regular protocols (ICMP, TCP and UDP), some infra-structure specific protocols (GRE, IPSec and RSVP), and some routing protocols (RIP, EIGRP and OSPF). This new version (Version 5.3) is focused on internal infra-structure, which allows people to test the availability of its resources, and cobering: a) Interior Gateway Protocols (Distance Vector Algorithm): 1. Routing Information Protocol (RIP) 2. Enhanced Interior Gateway Routing Protocol (EIGRP) b) Interior Gateway Protocols (Link State Algorithm): 1. Open Shortest Path First (OSPF) c) Quality-of-Service Protocols: 1. Resource ReSerVation Protocol (RSVP). d) Tunneling/Encapsulation Protocols: 1. Generic Routing Encapsulation (GRE). T50 is a powerful and unique packet injector tool, which is capable to: a) Send sequentially the following fifteen (15) protocols: 1. ICMP - Internet Control Message Protocol 2. IGMPv1 - Internet Group Management Protocol v1 3. IGMPv3 - Internet Group Management Protocol v3 4. TCP - Transmission Control Protocol 5. EGP - Exterior Gateway Protocol 6. UDP - User Datagram Protocol 7. RIPv1 - Routing Information Protocol v1 8. RIPv2 - Routing Information Protocol v2 9. DCCP - Datagram Congestion Control Protocol 10. RSVP - Resource ReSerVation Protocol 11. GRE - Generic Routing Encapsulation 12. IPSec - Internet Protocol Security (AH/ESP) 13. EIGRP - Enhanced Interior Gateway Routing Protocol 14. OSPF - Open Shortest Path First b) It is the only tool capable to encapsulate the protocols (listed above) within Generic Routing Encapsulation (GRE). c) Send an (quite) incredible amount of packets per second, making it a "second to none" tool: -> More than 1,000,000 pps of SYN Flood (+50% of the network uplink) in a 1000BASE-T Network (Gigabit Ethernet). -> More than 120,000 pps of SYN Flood (+60% of the network uplink) in a 100BASE-TX Network (Fast Ethernet). d) Perform "Stress Testing" on a variety of network infrastructure, network devices and security solutions in place. e) Simulate "Distributed Denial-of-Service" & "Denial-of-Service" attacks, validating Firewall rules, Router ACLs, Intrusion Detection System and Intrusion Prevention System policies. The main differentiator of the T50 is that it is able to send all protocols, sequentially, using one single SOCKET, besides it is capable to be used to modify network routes, letting IT Security Professionals performing advanced "Penetration Test". getversion.sh0000755000175000017500000000004413712774300014272 0ustar fredericofrederico#!/bin/bash grep ^VERSION Makefile mkdist.sh0000755000175000017500000000002713712774300013401 0ustar fredericofrederico#!/bin/bash make dist setversion.sh0000755000175000017500000000041713712774300014312 0ustar fredericofrederico#!/bin/sh if [ -z "$1" ]; then cat <<@@ Usage: $(basename $0) version Example: $ ./$(basename $0) 5.7.3 @@ exit 1 fi sed -i "s/PACKAGE_VERSION[ \t]\+\"\(.\+\)\"/PACKAGE_VERSION \"$1\"/" src/include/configuration.h sed -i "s/^VERSION=\(.\+\)/VERSION=$1/" Makefile src/0000755000175000017500000000000014107316050012330 5ustar fredericofredericosrc/cidr.c0000644000175000017500000000663113712774300013432 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /** @file cidr.c */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2019 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include // ntohl(). #include #include #include #include static struct cidr cidr = {0}; /** * CIDR configuration tiny C algorithm. * * This will setup cidr structure with values in host order. * * @param bits Number of "valid" bits on netmask. * @param address IP address from command line (in network order). * @return Pointer to cidr structure. */ struct cidr *config_cidr ( const config_options_T * const co ) { /* * nbrito -- Thu Dec 23 13:06:39 BRST 2010 * Here is a description of how to calculate, correctly, the number of * hosts and IP addresses based on CIDR -- three instructions line. * * (1) Calculate the 'Network Mask' (two simple operations): * a) Bitwise shift to the left (>>) '0xffffffff' using CIDR gives the * number of bits to calculate the 'Network Mask'. * b) Bitwise logic NOT (~) to turn off the bits that are on, and turn * on the bits that are off gives the 'Network Mask'. * * (2) Calculate the number of hosts' IP addresses available to the * current CIDR (two simple operations): * a) Subtract CIDR from 32 gives the host identifier's (bits) portion * for the IP address. * b) Two raised to the power (pow(3)) of host identifier (bits) gives * the number of all IP addresses available for the CIDR . * NOTE: Subtracting two from this math skips both 'Network Address' * and 'Broadcast Address'. * * (3) Calculate initial host IP address (two simple operations): * a) Convert IP address to little-endian ('ntohl()'). * b) Bitwise logic AND (&) of host identifier (bits) portion of the IP * address and 'Network Mask' adding one gives the first IP address * for the CIDR. */ // FIXME: Is this condition is really necessary? if ( co->bits < CIDR_MAXIMUM ) { uint32_t netmask; cidr.hostid = ( 1U << ( 32 - co->bits ) ) - 2U; /* XXX Sanitizing the maximum host identifier's IP addresses. * XXX Should never reaches here!!! */ if ( cidr.hostid > MAXIMUM_IP_ADDRESSES ) { error ( "internal error detecded -- please, report.\n" "cidr.hostid (%u) > MAXIMUM_IP_ADDRESSES (%u): Probably a specific platform error.", cidr.hostid, MAXIMUM_IP_ADDRESSES ); return NULL; } netmask = ~( ~0U >> co->bits ); cidr.__1st_addr = ( ntohl ( co->ip.daddr ) & netmask ) + 1; // avoid bit 0 = 0. } else { cidr.hostid = 0; // means "not random address". cidr.__1st_addr = ntohl ( co->ip.daddr ); } return &cidr; } src/memalloc.c0000644000175000017500000000406313712774300014277 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /** @file memalloc.c */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2019 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include void *packet = NULL; /* Actual packet buffer. Allocated dynamically. */ static size_t current_packet_size = 0; /* Used by alloc_packet(). */ /** * Preallocates the packet buffer. * * The function will reallocate memory only if the buffer isn't big enough to acomodate * new_packet_size bytes. Using IPPROTO_T50, after the first 'round', the buffer will be * big enough to accomodate all packets and no reallocations will be made. * * @param size Size of the new 'global' packet buffer. */ void alloc_packet ( size_t new_packet_size ) { void *p; assert( new_packet_size ); /* Realloc only ig the new packet size is greater than the old. */ /* NOTE: Assume the condition is false the majority of time. */ if ( new_packet_size > current_packet_size ) { /* Tries to reallocate memory. */ /* NOTE: Assume realloc will not fail. */ if ( ! ( p = realloc ( packet, new_packet_size ) ) ) fatal_error ( "Error reallocating packet buffer." ); /* Only assign a new pointer if successfull */ packet = p; current_packet_size = new_packet_size; } } void destroy_packet_buffer ( void ) { SAFE_FREE ( packet ); } src/include/0000755000175000017500000000000014107316050013753 5ustar fredericofredericosrc/include/t50_cidr.h0000644000175000017500000000224613712774300015550 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2014 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __CIDR_H__ #define __CIDR_H__ #include #include #include #define CIDR_MINIMUM 8 #define CIDR_MAXIMUM 32 // fix #7 /** @struct cidr T50 cidr structure. */ struct cidr { uint32_t hostid; /* hosts identifiers */ in_addr_t __1st_addr; /* first IP address */ }; struct cidr *config_cidr ( const config_options_T * const ); #endif src/include/t50_randomizer.h0000664000175000017500000000265114107316050016774 0ustar fredericofrederico#ifndef __RANDOMIZER_H__ #define __RANDOMIZER_H__ #include #include /* Randomizer macros and function */ /* NOTE: int8_t, int16_t, int32_t are synonimous of char, short and int. */ /* This macro will use htonX functions only if v is !0. */ /* Sometipes, v is a bitfield and NOT compatible with primitive types. Because of this, the default selector is necessary! */ /* RANDOM call results have not endianess! */ #define __RND(v) _Generic((v), \ _Bool: (!!(v) ? (v) : RANDOM()), \ int8_t: (!!(v) ? (v) : RANDOM()), \ int16_t: (!!(v) ? htons((v)) : RANDOM()), \ int32_t: (!!(v) ? htonl((v)) : RANDOM()), \ uint8_t: (!!(v) ? (v) : RANDOM()), \ uint16_t: (!!(v) ? htons((v)) : RANDOM()), \ uint32_t: (!!(v) ? htonl((v)) : RANDOM()), \ default: (!!(v) ? (v) : RANDOM())) // FIX: Random IP addresses and PORTS were reversed by __RND macro above. #define INADDR_RND(v) ((uint32_t)(!!(v) ? (v) : RANDOM())) #define IPPORT_RND(v) ((uint16_t)(!!(v) ? (v) : RANDOM())) #define RANDOM random_xorshift128plus #define SRANDOM get_random_seed extern uint32_t random_xorshift128plus( void ); extern void get_random_seed( void ); extern uint32_t NETMASK_RND ( uint32_t ); #endif src/include/protocol/0000755000175000017500000000000013712774300015623 5ustar fredericofredericosrc/include/protocol/t50_rip.h0000644000175000017500000000232413712774300017257 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2014 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __RIP_H__ #define __RIP_H__ #define IPPORT_RIP 520 #define RIP_HEADER_LENGTH 4 #define RIP_TRAILER_LENGTH 4 #define RIP_MESSAGE_LENGTH 20 #define RIP_AUTH_LENGTH 20 /** Calculating RIP Header length */ #define rip_hdr_len(foo) \ (RIP_HEADER_LENGTH + \ RIP_MESSAGE_LENGTH + \ ((foo) ? \ RIP_AUTH_LENGTH + \ RIP_TRAILER_LENGTH + \ AUTH_TLEN_HMACMD5 : \ 0)) #endif /* __RIP_H */ src/include/protocol/t50_gre.h0000644000175000017500000001476613712774300017257 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2014 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef GRE_H_INCLUDED_ #define GRE_H_INCLUDED_ #include #include #define GREVERSION 0 /* GRE Options */ #define GRE_OPTION_STRICT 0x01 #define GRE_OPTION_SEQUENCE 0x02 #define GRE_OPTION_KEY 0x04 #define GRE_OPTION_ROUTING 0x08 #define GRE_OPTION_CHECKSUM 0x10 #define GRE_OPTLEN_SEQUENCE sizeof(struct gre_seq_hdr) #define GRE_OPTLEN_KEY sizeof(struct gre_key_hdr) #define GRE_OPTLEN_CHECKSUM sizeof(struct gre_sum_hdr) /** * Generic Routing Encapsulation (GRE) (RFC 1701) * * The GRE packet header has form: * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * |C|R|K|S|s|Recur| Flags | Ver | Protocol Type | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Checksum (optional) | Offset (optional) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Key (optional) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Sequence Number (optional) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Routing (optional) * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * * Key and Sequence Number Extensions to GRE (RFC 2890) * * The proposed GRE header will have the following format: * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * |C| |K|S| Reserved0 | Ver | Protocol Type | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Checksum (optional) | Reserved1 (Optional) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Key (optional) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Sequence Number (Optional) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ struct gre_hdr { #if defined(__LITTLE_ENDIAN_BITFIELD) uint16_t recur: 3, /* recursion control */ s: 1, /* strict source route */ S: 1, /* sequence number present */ K: 1, /* key present */ R: 1, /* routing present */ C: 1, /* checksum present */ version: 3, /* version */ flags: 5; /* flags */ #elif defined(__BIG_ENDIAN_BITFIELD) uint16_t C: 1, /* checksum present */ R: 1, /* routing present */ K: 1, /* key present */ S: 1, /* sequence number present */ s: 1, /* strict source route */ recur: 3, /* recursion control */ flags: 5, /* flags */ version: 3; /* version */ #else # error "Adjust your defines" #endif uint16_t proto; /* protocol */ uint8_t __optional[0]; /* optional */ }; /** * Generic Routing Encapsulation (GRE) (RFC 1701) * * Offset (2 octets) * * The offset field indicates the octet offset from the start of the * Routing field to the first octet of the active Source Route Entry * to be examined. This field is present if the Routing Present or * the Checksum Present bit is set to 1, and contains valid information * only if the Routing Present bit is set to 1. * * Checksum (2 octets) * * The Checksum field contains the IP (one's complement) checksum of * the GRE header and the payload packet. This field is present if * the Routing Present or the Checksum Present bit is set to 1, and * contains valid information only if the Checksum Present bit is set * to 1. */ struct gre_sum_hdr { uint16_t check; /* checksum */ uint16_t offset; /* offset */ }; /** * Generic Routing Encapsulation (GRE) (RFC 1701) * * Key (4 octets) * * The Key field contains a four octet number which was inserted by * the encapsulator. It may be used by the receiver to authenticate the * source of the packet. The techniques for determining authenticity are * outside of the scope of this document. The Key field is only present * if the Key Present field is set to 1. */ struct gre_key_hdr { uint32_t key; /* key */ }; /** * Generic Routing Encapsulation (GRE) (RFC 1701) * * Sequence Number (4 octets) * * The Sequence Number field contains an unsigned 32 bit integer which * is inserted by the encapsulator. It may be used by the receiver to * establish the order in which packets have been transmitted from the * encapsulator to the receiver. The exact algorithms for the generation * of the Sequence Number and the semantics of their reception is * outside of the scope of this document. */ struct gre_seq_hdr { uint32_t sequence; /* sequence number */ }; struct config_options; /* Defined in config.h. */ size_t gre_opt_len ( const struct config_options * const ); struct iphdr *gre_encapsulation ( void * restrict, const struct config_options * const restrict, size_t ); void gre_checksum ( void * restrict, const struct config_options * const restrict, size_t ); #endif /* __GRE_H */ src/include/protocol/t50_ip.h0000644000175000017500000000176013712774300017100 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2014 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __IP_INC__ #define __IP_INC__ #include struct config_options; /* Defined in config.h. */ struct iphdr *ip_header ( void * restrict, uint32_t, const struct config_options * restrict ); #endif src/include/protocol/t50_rsvp.h0000644000175000017500000001444113712774300017462 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2014 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __RSVP_H__ #define __RSVP_H__ #include #define RSVPVERSION 1 /* RSVP Message Type */ #define RSVP_MESSAGE_TYPE_PATH 1 #define RSVP_MESSAGE_TYPE_RESV 2 #define RSVP_MESSAGE_TYPE_PATHERR 3 #define RSVP_MESSAGE_TYPE_RESVERR 4 #define RSVP_MESSAGE_TYPE_PATHTEAR 5 #define RSVP_MESSAGE_TYPE_RESVTEAR 6 #define RSVP_MESSAGE_TYPE_RESVCONF 7 #define RSVP_MESSAGE_TYPE_BUNDLE 12 #define RSVP_MESSAGE_TYPE_ACK 13 #define RSVP_MESSAGE_TYPE_SREFRESH 15 #define RSVP_MESSAGE_TYPE_HELLO 20 #define RSVP_MESSAGE_TYPE_NOTIFY 21 /** * Resource ReSerVation Protocol (RSVP) (RFC 2205) * * 3.1.2 Object Formats * * Every object consists of one or more 32-bit words with a one- * word header, with the following format: * * 0 1 2 3 * +-------------+-------------+-------------+-------------+ * | Length (bytes) | Class-Num | C-Type | * +-------------+-------------+-------------+-------------+ * | | * // (Object contents) // * | | * +-------------+-------------+-------------+-------------+ */ #define RSVP_OBJECT_HEADER_LENGTH sizeof(uint32_t) /* RSVP Object Class */ #define RSVP_OBJECT_SESSION 1 #define RSVP_OBJECT_RESV_HOP 3 #define RSVP_OBJECT_INTEGRITY 4 #define RSVP_OBJECT_TIME_VALUES 5 #define RSVP_OBJECT_ERROR_SPEC 6 #define RSVP_OBJECT_SCOPE 7 #define RSVP_OBJECT_STYLE 8 #define RSVP_OBJECT_FLOWSPEC 9 #define RSVP_OBJECT_FILTER_SPEC 10 #define RSVP_OBJECT_SENDER_TEMPLATE 11 #define RSVP_OBJECT_SENDER_TSPEC 12 #define RSVP_OBJECT_ADSPEC 13 #define RSVP_OBJECT_POLICY_DATA 14 #define RSVP_OBJECT_RESV_CONFIRM 15 #define RSVP_OBJECT_MESSAGE_ID 23 #define RSVP_OBJECT_MESSAGE_ID_ACK 24 #define RSVP_OBJECT_MESSAGE_ID_NACK 25 #define RSVP_LENGTH_SESSION (RSVP_OBJECT_HEADER_LENGTH + 8) #define RSVP_LENGTH_RESV_HOP (RSVP_OBJECT_HEADER_LENGTH + 8) #define RSVP_LENGTH_INTEGRITY (RSVP_OBJECT_HEADER_LENGTH + 20) #define RSVP_LENGTH_TIME_VALUES (RSVP_OBJECT_HEADER_LENGTH + 4) #define RSVP_LENGTH_ERROR_SPEC (RSVP_OBJECT_HEADER_LENGTH + 8) #define RSVP_LENGTH_SCOPE(foo) (RSVP_OBJECT_HEADER_LENGTH + ((foo) * sizeof(in_addr_t))) #define RSVP_LENGTH_STYLE (RSVP_OBJECT_HEADER_LENGTH + 4) #define RSVP_LENGTH_FLOWSPEC (RSVP_OBJECT_HEADER_LENGTH + 32) #define RSVP_LENGTH_FILTER_SPEC (RSVP_OBJECT_HEADER_LENGTH + 8) #define RSVP_LENGTH_SENDER_TEMPLATE (RSVP_OBJECT_HEADER_LENGTH + 8) #define RSVP_LENGTH_SENDER_TSPEC (RSVP_OBJECT_HEADER_LENGTH + 8) #define RSVP_LENGTH_ADSPEC (RSVP_OBJECT_HEADER_LENGTH + ADSPEC_MESSAGE_HEADER) #define RSVP_LENGTH_RESV_CONFIRM (RSVP_OBJECT_HEADER_LENGTH + 4) /* RSVP TSPEC Class Service */ #define TSPEC_MESSAGE_HEADER 4 #define TSPEC_TRAFFIC_SERVICE 1 #define TSPEC_GUARANTEED_SERVICE 2 #define TSPECT_TOKEN_BUCKET_SERVICE 127 #define TSPEC_TOKEN_BUCKET_LENGTH 24 #define TSPEC_SERVICES(foo) \ ((((foo) == TSPEC_TRAFFIC_SERVICE) || \ ((foo) == TSPEC_GUARANTEED_SERVICE)) ? \ TSPEC_TOKEN_BUCKET_LENGTH : 0) /* RSVP ADSPEC Class Service */ #define ADSPEC_PARAMETER_SERVICE 1 #define ADSPEC_GUARANTEED_SERVICE 2 #define ADSPEC_CONTROLLED_SERVICE 5 #define ADSPEC_MESSAGE_HEADER 4 #define ADSPEC_SERVDATA_HEADER 4 #define ADSPEC_PARAMETER_DATA 4 #define ADSPEC_PARAMETER_LENGTH (ADSPEC_MESSAGE_HEADER + ((ADSPEC_SERVDATA_HEADER + ADSPEC_PARAMETER_DATA) * 4)) #define ADSPEC_PARAMETER_ISHOPCNT 4 #define ADSPEC_PARAMETER_BANDWIDTH 6 #define ADSPEC_PARAMETER_LATENCY 8 #define ADSPEC_PARAMETER_COMPMTU 10 #define ADSPEC_GUARANTEED_LENGTH (ADSPEC_MESSAGE_HEADER + ((ADSPEC_SERVDATA_HEADER + ADSPEC_PARAMETER_DATA) * 4)) #define ADSPEC_CONTROLLED_LENGTH ADSPEC_MESSAGE_HEADER #define ADSPEC_SERVICES(foo) \ (ADSPEC_PARAMETER_LENGTH + \ ((((foo) == ADSPEC_CONTROLLED_SERVICE) || \ ((foo) == ADSPEC_GUARANTEED_SERVICE)) ? \ ADSPEC_GUARANTEED_LENGTH : 0) + \ (((foo) == ADSPEC_CONTROLLED_SERVICE) ? \ ADSPEC_CONTROLLED_LENGTH : 0)) /** * Resource ReSerVation Protocol (RSVP) (RFC 2205) * * 3.1.1 Common Header * * 0 1 2 3 * +------+------+-------------+---------------------------- * | Vers | Flags| Msg Type | RSVP Checksum | * +------+------+-------------+---------------------------+ * | Send_TTL | (Reserved) | RSVP Length | * --------------+-------------+---------------------------- */ struct rsvp_common_hdr { #if defined(__LITTLE_ENDIAN_BITFIELD) uint16_t flags: 4, /* flags */ version: 4, /* version */ type: 8; /* message type */ #elif defined(__BIG_ENDIAN_BITFIELD) uint16_t version: 4, /* version */ flags: 4, /* flags */ type: 8; /* message type */ #else # error "Adjust your defines" #endif uint16_t check; /* checksum */ uint8_t ttl; /* time to live */ uint8_t reserved; /* reserved */ uint16_t length; /* message length */ }; #endif /* __RSVP_H */ src/include/protocol/t50_ospf.h0000644000175000017500000002152313712774300017436 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2014 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __OSPF_H__ #define __OSPF_H__ #include #include #define OSPFVERSION 2 #define IPPROTO_OSPF 89 /* OSPF Message Type */ #define OSPF_TYPE_HELLO 1 #define OSPF_TYPE_DD 2 #define OSPF_TYPE_LSREQUEST 3 #define OSPF_TYPE_LSUPDATE 4 #define OSPF_TYPE_LSACK 5 #define OSPF_TLEN_NEIGHBOR(foo) ((foo) * sizeof(in_addr_t)) #define OSPF_TLEN_LSUPDATE 4 #define OSPF_TLEN_DD 8 #define OSPF_TLEN_LSREQUEST 12 #define OSPF_TLEN_HELLO 20 /* OSPF HELLO, DD and LSA Option */ #define OSPF_OPTION_TOS 0x01 #define OSPF_OPTION_EXTERNAL 0x02 #define OSPF_OPTION_MULTICAST 0x04 #define OSPF_OPTION_NSSA 0x08 #define OSPF_OPTION_LLS 0x10 #define OSPF_OPTION_DEMAND 0x20 #define OSPF_OPTION_OPAQUE 0x40 #define OSPF_OPTION_DOWN 0x80 /* OSPF DD DB Description */ #define DD_DBDESC_MSLAVE 0x01 #define DD_DBDESC_MORE 0x02 #define DD_DBDESC_INIT 0x04 #define DD_DBDESC_OOBRESYNC 0x08 /* OSPF LSA LS Type */ #define LSA_TYPE_ROUTER 1 #define LSA_TYPE_NETWORK 2 #define LSA_TYPE_SUMMARY_IP 3 #define LSA_TYPE_SUMMARY_AS 4 #define LSA_TYPE_ASBR 5 #define LSA_TYPE_MULTICAST 6 #define LSA_TYPE_NSSA 7 #define LSA_TYPE_OPAQUE_LINK 9 #define LSA_TYPE_OPAQUE_AREA 10 #define LSA_TYPE_OPAQUE_FLOOD 11 #define LSA_TLEN_GENERIC(x) \ (sizeof(struct ospf_lsa_hdr) + \ ((x) * sizeof(uint32_t))) #define LSA_TLEN_MULTICAST LSA_TLEN_GENERIC(2) #define LSA_TLEN_NETWORK LSA_TLEN_GENERIC(2) #define LSA_TLEN_SUMMARY LSA_TLEN_GENERIC(2) #define LSA_TLEN_ASBR LSA_TLEN_GENERIC(4) #define LSA_TLEN_ROUTER LSA_TLEN_GENERIC(4) #define LSA_TLEN_NSSA LSA_TLEN_ASBR /* OSPF Router-LSA Flag */ #define ROUTER_FLAG_BORDER 0x01 #define ROUTER_FLAG_EXTERNAL 0x02 #define ROUTER_FLAG_VIRTUAL 0x04 #define ROUTER_FLAG_WILD 0x08 #define ROUTER_FLAG_NSSA_TR 0x10 /* OSPF Router-LSA Link type */ #define LINK_TYPE_PTP 1 #define LINK_TYPE_TRANSIT 2 #define LINK_TYPE_STUB 3 #define LINK_TYPE_VIRTUAL 4 /* OSPF Group-LSA Type */ #define VERTEX_TYPE_ROUTER 1 #define VERTEX_TYPE_NETWORK 2 #define OSPF_TLV_HEADER sizeof(struct ospf_lls_hdr) /* OSPF LLS Type/Length/Value */ #define OSPF_TLV_RESERVED 0 #define OSPF_TLV_EXTENDED 1 #define OSPF_TLV_CRYPTO 2 #define OSPF_LEN_EXTENDED OSPF_TLV_HEADER #define EXTENDED_OPTIONS_LR 0x00000001 #define EXTENDED_OPTIONS_RS 0x00000002 #define OSPF_LEN_CRYPTO ( OSPF_TLV_HEADER + AUTH_TLEN_HMACMD5 ) /** Calculating OSPF LLS Type/Length/Value length */ #define ospf_tlv_len(foo, bar, baz) \ ((((foo) == OSPF_TYPE_HELLO) || \ ((foo) == OSPF_TYPE_DD)) ? \ ((bar) ? \ OSPF_TLV_HEADER * 2 + \ OSPF_LEN_EXTENDED + \ ((baz) ? \ OSPF_TLV_HEADER + \ OSPF_LEN_CRYPTO : \ 0) : \ 0) : \ 0) /** * OSPF Version 2 (RFC 2328) * * A.3.1 The OSPF packet header * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Version # | Type | Packet length | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Router ID | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Area ID | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Checksum | AuType | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ struct ospf_hdr { uint8_t version, /* version */ type; /* type */ uint16_t length; /* length */ in_addr_t rid; /* router ID */ in_addr_t aid; /* area ID */ uint16_t check; /* checksum */ uint16_t autype; /* authentication type */ uint8_t __ospf_auth[0]; /* authentication header */ uint8_t __ospf_type_hdr[0]; /* type header */ }; /** * OSPF Version 2 (RFC 2328) * * A.3.1 The OSPF packet header * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Authentication | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Authentication | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * * D.3 Cryptographic authentication * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | 0 | Key ID | Auth Data Len | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Cryptographic sequence number | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ struct ospf_auth_hdr { uint16_t reserved; /* reserved must be zero */ uint8_t key_id, /* authentication key ID */ length; /* authentication length */ uint32_t sequence; /* authentication sequence # */ }; /** * OSPF Version 2 (RFC 2328) * * A.4.1 The Link State Advertisement (LSA) header * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | LS age | Options | LS type | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Link State ID | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Advertising Router | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | LS sequence number | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | LS checksum | length | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ struct ospf_lsa_hdr { uint16_t age; /* LSA age */ uint8_t options; /* LSA options */ uint8_t type; /* LSA type */ in_addr_t lsid; /* LSA link state ID */ in_addr_t router; /* LSA advertising router */ uint32_t sequence; /* LSA sequence number */ uint16_t check; /* LSA checksum */ uint16_t length; /* LSA length */ }; /** * OSPF Link-Local Signaling (RFC 5613) * * 2.2. LLS Data Block * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Checksum | LLS Data Length | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | | * | LLS TLVs | * . . * . . * . . * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ struct ospf_lls_hdr { uint16_t check; /* LLS checksum */ uint16_t length; /* LLS length */ }; #endif /* __OSPF_H */ src/include/protocol/t50_tcp_options.h0000644000175000017500000000502313712774300021025 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2014 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __TCP_OPTIONS_H__ #define __TCP_OPTIONS_H__ #include #define TCPOPT_EOL 0 #define TCPOPT_NOP 1 #define TCPOPT_MSS 2 #define TCPOPT_WSOPT 3 #define TCPOPT_SACK_OK 4 #define TCPOPT_SACK_EDGE 5 #define TCPOPT_TSOPT 8 #define TCPOPT_CC 11 #define TCPOPT_CC_NEW 12 #define TCPOPT_CC_ECHO 13 #define TCPOPT_MD5 19 #define TCPOPT_AO 29 #define TCPOLEN_MSS 4 #define TCPOLEN_WSOPT 3 #define TCPOLEN_SACK_OK 2 #define TCPOLEN_CC 6 #define TCPOLEN_TSOPT 10 #define TCPOLEN_MD5 18 #define TCPOLEN_AO 20 /** * TCP Selective Acknowledgement Options (SACK) (RFC 2018) * * A SACK option that specifies n blocks will have a length of 8*n+2 * bytes, so the 40 bytes available for TCP options can specify a * maximum of 4 blocks. It is expected that SACK will often be used * in conjunction with the Timestamp option used for RTTM,which takes * an additional 10 bytes (plus two bytes of padding); thus a maximum * of 3 SACK blocks will be allowed in this case. */ #define TCPOLEN_SACK_EDGE(foo) (((foo) * (sizeof(uint32_t) * 2)) + TCPOLEN_SACK_OK) /** * Transmission Control Protocol (TCP) (RFC 793) * * Padding: variable * * The TCP header padding is used to ensure that the TCP header ends * and data begins on a 32 bit boundary. The padding is composed of * zeros. */ #define TCPOLEN_PADDING(foo) (((foo) & 3) ? sizeof(uint32_t) - ((foo) & 3) : 0) /* TCP Options bitmask. */ #define TCP_OPTION_MSS 0x01 #define TCP_OPTION_WSOPT 0x02 #define TCP_OPTION_TSOPT 0x04 #define TCP_OPTION_SACK_OK 0x08 #define TCP_OPTION_CC 0x10 #define TCP_OPTION_CC_NEXT 0x20 #define TCP_OPTION_SACK_EDGE 0x40 #endif /* __TCP_OPTIONS_H */ src/include/protocol/t50_egp.h0000644000175000017500000001404513712774300017243 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2014 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __EGP_H__ #define __EGP_H__ #define EGPVERSION 2 #include /* EGP Message Types */ #define EGP_NEIGHBOR_UPDATE_RESP 1 #define EGP_NEIGHBOR_POLL_COMMAND 2 #define EGP_NEIGHBOR_ACQUISITION 3 #define EGP_NEIGHBOR_REACHABILITY 5 #define EGP_NEIGHBOR_ERROR_RESP 8 /* EGP Message Neighbor Acquisition Codes */ #define EGP_ACQ_CODE_REQUEST_CMD 0 #define EGP_ACQ_CODE_CONFIRM_RESP 1 #define EGP_ACQ_CODE_REFUSE_RESP 2 #define EGP_ACQ_CODE_CEASE_CMD 3 #define EGP_ACQ_CODE_CEASE_ACKCMD 4 /* EGP Message Neighbor Acquisition Type */ #define EGP_ACQ_STAT_UNSPECIFIED 0 #define EGP_ACQ_STAT_ACTIVE_MODE 1 #define EGP_ACQ_STAT_PASSIVE_MODE 2 #define EGP_ACQ_STAT_INSUFFICIENT 3 #define EGP_ACQ_STAT_ADM_PROHIBIT 4 #define EGP_ACQ_STAT_GOING_DOWN 5 #define EGP_ACQ_STAT_PARAMETER 6 #define EGP_ACQ_STAT_VIOLATION 7 /** * Exterior Gateway Protocol (EGP) Formal Specification (RFC 904) * * Appendix A. EGP Message Formats * * The formats for the various EGP messages are described in this * section. All EGP messages include a ten-octet header of six fields, * which may be followed by additional fields depending on message type. * The format of the header is shown below along with a description of its * fields. * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * ----------------------------------------------------------------- * | EGP Version # | Type | Code | Status | * ----------------------------------------------------------------- * | Checksum | Autonomous System # | * ----------------------------------------------------------------- * | Sequence # | * --------------------------------- * * EGP Version # assigned number identifying the EGP version * (currently 2) * * Type identifies the message type * * Code identifies the message code (subtype) * * Status contains message-dependent status information * * Checksum The EGP checksum is the 16-bit one's complement * of the one's complement sum of the EGP message * starting with the EGP version number field. When * computing the checksum the checksum field itself * should be zero. * * Autonomous System # assigned number identifying the particular * autonomous system * * Sequence # send state variable (commands) or receive state * variable (responses and indications) */ struct egp_hdr { uint8_t version; /* version */ uint8_t type; /* type */ uint8_t code; /* code */ uint8_t status; /* status */ uint16_t check; /* checksum */ uint16_t as; /* autonomous system */ uint16_t sequence; /* sequence number */ uint8_t __data[0]; /* data */ }; /** * Exterior Gateway Protocol (EGP) Formal Specification (RFC 904) * * A.1. Neighbor Acquisition Messages * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * ----------------------------------------------------------------- * | EGP Version # | Type | Code | Status | * ----------------------------------------------------------------- * | Checksum | Autonomous System # | * ----------------------------------------------------------------- * | Sequence # | Hello Interval | * ----------------------------------------------------------------- * | Poll Interval | * --------------------------------- * * Note: the Hello Interval and Poll Interval fields are present only in * Request and Confirm messages. * * Type 3 * * Code 0 Request command * 1 Confirm response * 2 Refuse response * 3 Cease command * 4 Cease-ack response * * Status (see below) 0 unspecified * 1 active mode * 2 passive mode * 3 insufficient resources * 4 administratively prohibited * 5 going down * 6 parameter problem * 7 protocol violation * * Hello Interval minimum Hello command polling interval (seconds) * * Poll Interval minimum Poll command polling interval (seconds) */ struct egp_acq_hdr { uint16_t hello; /* hello interval */ uint16_t poll; /* poll interval */ }; #endif /* __EGP_H */ src/include/protocol/t50_igmp.h0000644000175000017500000000226213712774300017422 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2014 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __IGMP_H__ #define __IGMP_H__ /** IGMP Header DEFINITIONS. */ #define IGMPV3_TLEN_NSRCS(foo) ((foo) * sizeof(in_addr_t)) /** Calculating IGMPv3 Header length */ #define igmpv3_hdr_len(foo, bar) \ ((((foo) == IGMPV3_HOST_MEMBERSHIP_REPORT) ? \ sizeof(struct igmpv3_report) + sizeof(struct igmpv3_grec) : \ sizeof(struct igmpv3_query)) + \ IGMPV3_TLEN_NSRCS((bar))) #endif /* __IGMP_H */ src/include/protocol/t50_eigrp.h0000644000175000017500000001063113712774300017573 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2014 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __EIGRP_H__ #define __EIGRP_H__ #include #define IPPROTO_EIGRP 88 #define EIGRPVERSION 2 #define EIGRP_FLAG_INIT 0x00000001 #define EIGRP_FLAG_COND 0x00000002 /* EIGRP Message Opcode */ #define EIGRP_OPCODE_UPDATE 1 #define EIGRP_OPCODE_REQUEST 2 #define EIGRP_OPCODE_QUERY 3 #define EIGRP_OPCODE_REPLY 4 #define EIGRP_OPCODE_HELLO 5 #define EIGRP_OPCODE_IPX_SAP 6 /* EIGRP Message Type/Length/Value */ #define EIGRP_TYPE_PARAMETER 1 #define EIGRP_TYPE_AUTH 2 #define EIGRP_TYPE_SEQUENCE 3 #define EIGRP_TYPE_SOFTWARE 4 #define EIGRP_TYPE_MULTICAST 5 #define EIGRP_TYPE_INTERNAL 0x102 #define EIGRP_TYPE_EXTERNAL 0x103 #define EIGRP_TLEN_PARAMETER 12 #define EIGRP_TLEN_AUTH 40 #define EIGRP_PADDING_BLOCK 12 #define EIGRP_MAXIMUM_KEYID 2147483647 #define EIGRP_TLEN_SEQUENCE 9 #define EIGRP_TLEN_SOFTWARE 8 #define EIGRP_TLEN_MULTICAST 8 #define EIGRP_TLEN_INTERNAL 25 #define EIGRP_TLEN_EXTERNAL 45 #define EIGRP_DADDR_BUILD(foo, bar) \ ((foo) &= htonl(~(0xffffffffU >> (((bar) >> 3) * 8)))) #define EIGRP_DADDR_LENGTH(foo) \ ((((foo) >> 3) & 3) + ((foo) % 8 ? 1 : 0)) /* EIGRP K Values bitmask */ #define EIGRP_KVALUE_K1 0x01 #define EIGRP_KVALUE_K2 0x02 #define EIGRP_KVALUE_K3 0x04 #define EIGRP_KVALUE_K4 0x08 #define EIGRP_KVALUE_K5 0x10 /** * Enhanced Interior Gateway Routing Protocol (EIGRP) * * 0 1 2 3 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * ----------------------------------------------------------------- * | Version | Opcode | Checksum | * ----------------------------------------------------------------- * | Flags | * ----------------------------------------------------------------- * | Sequence Number | * ----------------------------------------------------------------- * | Acknowledgment Number | * ----------------------------------------------------------------- * | Autonomous System Number | * ----------------------------------------------------------------- * | | * // TLV (Type/Length/Value) // * | | * ----------------------------------------------------------------- * * Please, be advised that there is no deep information about EIGRP, no * other than EIGRP PCAP files public available. Due to that I have done * a deep analysis using live EIGRP PCAP files to build the EIGRP Packet. * * There are some really good resources, such as: * * http://www.protocolbase.net/protocols/protocol_EIGRP.php * http://packetlife.net/captures/category/cisco-proprietary/ * http://oreilly.com/catalog/iprouting/chapter/ch04.html */ struct eigrp_hdr { uint8_t version, /* version */ opcode; /* opcode */ uint16_t check; /* checksum */ uint32_t flags; /* flags */ uint32_t sequence; /* sequence number */ uint32_t acknowledge; /* acknowledgment sequence # */ uint32_t as; /* autonomous system */ uint8_t __tlv[0]; /* TLV (Type/Length/Value) */ }; #endif /* __EIGRP_H */ src/include/t50_shuffle.h0000644000175000017500000000166013712774300016262 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2014 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __T50_SHUFFLE_INCLUDED__ #define __T50_SHUFFLE_INCLUDED__ #include #include void shuffle ( uint32_t *, size_t ); #endif src/include/t50_help.h0000644000175000017500000000263713712774300015563 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2014 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __HELP_INCLUDED__ #define __HELP_INCLUDED__ /* Add usage function interface here. Add usage function definition for protocol at src/help/ directory. Change Makefile and src/usage.c. */ void general_help ( void ); void gre_help ( void ); void tcp_udp_dccp_help ( void ); void tcp_help ( void ); void ip_help ( void ); void icmp_help ( void ); void egp_help ( void ); void rip_help ( void ); void dccp_help ( void ); void rsvp_help ( void ); void ipsec_help ( void ); void eigrp_help ( void ); void ospf_help ( void ); void show_version ( void ); /* Prints version info. */ void usage ( void ); /* Prints usage message */ #endif src/include/t50_errors.h0000644000175000017500000000165013712774300016141 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2014 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __ERRORS_H__ #define __ERRORS_H__ void error ( const char * const fmt, ... ); void fatal_error ( const char * const fmt, ... ); #endif src/include/t50_cksum.h0000644000175000017500000000162413712774300015750 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2014 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __CKSUM_H__ #define __CKSUM_H__ #include #include uint16_t cksum ( void *, size_t ); #endif src/include/t50_modules.h0000664000175000017500000001157514107315014016276 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2014 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __MODULES_INCLUDED__ #define __MODULES_INCLUDED__ #include #include #include #include #include /* Purpose-built protocol libraries to be used by T50 modules */ #include #include #include #include #include #include #include #include #include /* NOTE: Insert your new protocol header here and change the modules table @ modules.c. */ /** * User Datagram Protocol (RFC 768) Pseudo Header structure. * * Checksum is the 16-bit one's complement of the one's complement sum of a * pseudo header of information from the IP header, the UDP header, and the * data, padded with zero octets at the end (if necessary) to make a * multiple of two octets. * * The pseudo header conceptually prefixed to the UDP header contains the * source address, the destination address, the protocol, and the UDP * length. This information gives protection against misrouted datagrams. * This checksum procedure is the same as is used in TCP. * * 0 7 8 15 16 23 24 31 * +--------+--------+--------+--------+ * | source address | * +--------+--------+--------+--------+ * | destination address | * +--------+--------+--------+--------+ * | zero |protocol| UDP length | * +--------+--------+--------+--------+ * * If the computed checksum is zero, it is transmitted as all ones (the * equivalent in one's complement arithmetic). An all zero transmitted * checksum value means that the transmitter generated no checksum (for * debugging or for higher level protocols that don't care). */ struct psdhdr { in_addr_t saddr; /* source address */ in_addr_t daddr; /* destination address */ uint8_t zero; /* must be zero */ uint8_t protocol; /* protocol */ uint16_t len; /* header length */ }; typedef void ( *module_func_ptr_t ) ( const config_options_T * const restrict, size_t * restrict ); /** * Modules entry structure. * * Used for modules definitions. And table iterators. */ typedef struct { int protocol_id; char *name; char *description; module_func_ptr_t func; int *valid_options; } modules_table_T; /* Macros used to define the modules table. */ #define BEGIN_MODULES_TABLE modules_table_T mod_table[] = { #define END_MODULES_TABLE { 0, NULL, NULL, NULL, NULL } }; #define MODULE_ENTRY(id,name,descr,func) { (id), name, descr, func, func ## _validopts }, #define VALID_OPTIONS_TABLE(func, ...) static int func ## _validopts[] = { __VA_ARGS__, 0 }; /** * The modules table is global through all the code. */ extern modules_table_T mod_table[]; // Must be extern here! extern const uint32_t number_of_modules; extern uint32_t indices[]; int *get_module_valid_options_list ( int ); void build_proto_indices ( void ); uint32_t get_proto_index ( config_options_T * ); /* Modules functions prototypes. */ void icmp ( const config_options_T * const restrict, size_t * restrict ); void igmpv1 ( const config_options_T * const restrict, size_t * restrict ); void igmpv3 ( const config_options_T * const restrict, size_t * restrict ); void tcp ( const config_options_T * const restrict, size_t * restrict ); void egp ( const config_options_T * const restrict, size_t * restrict ); void udp ( const config_options_T * const restrict, size_t * restrict ); void ripv1 ( const config_options_T * const restrict, size_t * restrict ); void ripv2 ( const config_options_T * const restrict, size_t * restrict ); void dccp ( const config_options_T * const restrict, size_t * restrict ); void rsvp ( const config_options_T * const restrict, size_t * restrict ); void ipsec ( const config_options_T * const restrict, size_t * restrict ); void eigrp ( const config_options_T * const restrict, size_t * restrict ); void ospf ( const config_options_T * const restrict, size_t * restrict ); /* --- add yours here */ #endif src/include/t50_typedefs.h0000644000175000017500000000312013712774300016442 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2014 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __TYPEDEFS_INCLUDED__ #define __TYPEDEFS_INCLUDED__ #include #include /* Data types */ typedef int threshold_T; /* FIX: If we need more than 2147483648 packets sent, this type can be changed to int64_t. */ /** * Union used to ease buffer pointer manipulation. * * This will help with pointer arithmetic. When we have to point to the next * field, on the packet buffer. * * Since an address have a fixed size, we have a generic pointer (void *) and * pointers to other types. When incrementing 'dword_ptr' on this union, we are * adding 4 to the pointer, for instance. */ typedef union { void *ptr; uint8_t *byte_ptr; uint16_t *word_ptr; uint32_t *dword_ptr; in_addr_t *inaddr_ptr; uint64_t *qword_ptr; } memptr_T; #endif src/include/configuration.h0000664000175000017500000000137714107316050017005 0ustar fredericofrederico#ifndef __CONFIGURATION_H_INCLUDED__ #define __CONFIGURATION_H_INCLUDED__ #if !defined(__GNUC__) && (__GNUC__ < 5) && (__STDC_VERSION__ < 201112) #error "Need GCC 5 or greater, with C11 standard support, to compile!" #endif /* Name of package */ #define PACKAGE "t50" /* Define to the version of this package. */ #define PACKAGE_VERSION "5.8.7b" /* Define to the address where bug reports for this package should be sent. */ #define PACKAGE_BUGREPORT "t50-dev@googlegroups.com" /* Define to the full name of this package. */ #define PACKAGE_NAME PACKAGE " " PACKAGE_VERSION /* Define to the home page for this package. */ #define PACKAGE_URL "https://gitlab.com/fredericopissarra/t50.git" /* Use fork to spawn extra process */ #define __HAVE_TURBO__ #endif src/include/t50_memalloc.h0000644000175000017500000000167314006276130016416 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2014 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __MEMALLOC_H__ #define __MEMALLOC_H__ #include extern void *packet; void alloc_packet ( size_t ); void destroy_packet_buffer( void ); #endif src/include/t50_config.h0000664000175000017500000005555214107315014016076 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2014 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef CONFIG_H #define CONFIG_H #include #include #include #include /* Command line interface options which do not have short options */ /* NOTE: All options are greater or equal than 128 to avoid ASCII character collision on getopt_long(). */ enum { OPTION_NULL = 0, OPTION_VERSION, OPTION_HELP, OPTION_QUIET, /* XXX COMMON OPTIONS */ OPTION_THRESHOLD, OPTION_FLOOD, OPTION_ENCAPSULATED, #ifdef __HAVE_TURBO__ OPTION_TURBO, #endif /* __HAVE_TURBO__ */ OPTION_LIST_PROTOCOLS, OPTION_BOGUSCSUM, OPTION_SHUFFLE, /* XXX DCCP, TCP & UDP HEADER OPTIONS */ OPTION_SOURCE, OPTION_DESTINATION, /* XXX IP HEADER OPTIONS (IPPROTO_IP = 0) */ OPTION_IP_TOS, OPTION_IP_ID, OPTION_IP_OFFSET, OPTION_IP_TTL, OPTION_IP_PROTOCOL, OPTION_IP_SOURCE, /* XXX GRE HEADER OPTIONS (IPPROTO_GRE = 47) */ OPTION_GRE_SEQUENCE_PRESENT, OPTION_GRE_KEY_PRESENT, OPTION_GRE_CHECKSUM_PRESENT, OPTION_GRE_KEY, OPTION_GRE_SEQUENCE, OPTION_GRE_SADDR, OPTION_GRE_DADDR, /* XXX ICMP HEADER OPTIONS (IPPROTO_ICMP = 1) */ OPTION_ICMP_TYPE, OPTION_ICMP_CODE, OPTION_ICMP_GATEWAY, OPTION_ICMP_ID, OPTION_ICMP_SEQUENCE, /* XXX IGMP HEADER OPTIONS (IPPROTO_IGMP = 2) */ OPTION_IGMP_TYPE, OPTION_IGMP_CODE, OPTION_IGMP_GROUP, OPTION_IGMP_QRV, OPTION_IGMP_SUPPRESS, OPTION_IGMP_QQIC, OPTION_IGMP_GREC_TYPE, OPTION_IGMP_SOURCES, OPTION_IGMP_GREC_MULTICAST, OPTION_IGMP_ADDRESS, /* XXX TCP HEADER OPTIONS (IPPROTO_TCP = 6) */ OPTION_TCP_ACK_SEQ, OPTION_TCP_SEQUENCE, OPTION_TCP_OFFSET, OPTION_TCP_FIN, OPTION_TCP_SYN, OPTION_TCP_RST, OPTION_TCP_PSH, OPTION_TCP_ACK, OPTION_TCP_URG, OPTION_TCP_ECE, OPTION_TCP_CWR, OPTION_TCP_WINDOW, OPTION_TCP_URGENT_POINTER, OPTION_TCP_MSS, OPTION_TCP_WSOPT, OPTION_TCP_TSOPT, OPTION_TCP_SACK_OK, OPTION_TCP_CC, OPTION_TCP_CC_NEW, OPTION_TCP_CC_ECHO, OPTION_TCP_SACK_EDGE, OPTION_TCP_MD5_SIGNATURE, OPTION_TCP_AUTHENTICATION, OPTION_TCP_AUTH_KEY_ID, OPTION_TCP_AUTH_NEXT_KEY, OPTION_TCP_NOP, /* XXX EGP HEADER OPTIONS (IPPROTO_EGP = 8) */ OPTION_EGP_TYPE, OPTION_EGP_CODE, OPTION_EGP_STATUS, OPTION_EGP_AS, OPTION_EGP_SEQUENCE, OPTION_EGP_HELLO, OPTION_EGP_POLL, /* XXX RIP HEADER OPTIONS (IPPROTO_UDP = 17) */ OPTION_RIP_COMMAND, OPTION_RIP_FAMILY, OPTION_RIP_ADDRESS, OPTION_RIP_METRIC, OPTION_RIP_DOMAIN, OPTION_RIP_TAG, OPTION_RIP_NETMASK, OPTION_RIP_NEXTHOP, OPTION_RIP_AUTHENTICATION, OPTION_RIP_AUTH_KEY_ID, OPTION_RIP_AUTH_SEQUENCE, /* XXX DCCP HEADER OPTIONS (IPPROTO_DCCP = 33) */ OPTION_DCCP_OFFSET, OPTION_DCCP_CSCOV, OPTION_DCCP_CCVAL, OPTION_DCCP_TYPE, OPTION_DCCP_EXTEND, OPTION_DCCP_SEQUENCE_01, OPTION_DCCP_SEQUENCE_02, OPTION_DCCP_SEQUENCE_03, OPTION_DCCP_SERVICE, OPTION_DCCP_ACKNOWLEDGE_01, OPTION_DCCP_ACKNOWLEDGE_02, OPTION_DCCP_RESET_CODE, /* XXX RSVP HEADER OPTIONS (IPPROTO_RSVP = 46) */ OPTION_RSVP_FLAGS, OPTION_RSVP_TYPE, OPTION_RSVP_TTL, OPTION_RSVP_SESSION_ADDRESS, OPTION_RSVP_SESSION_PROTOCOL, OPTION_RSVP_SESSION_FLAGS, OPTION_RSVP_SESSION_PORT, OPTION_RSVP_HOP_ADDRESS, OPTION_RSVP_HOP_IFACE, OPTION_RSVP_TIME_REFRESH, OPTION_RSVP_ERROR_ADDRESS, OPTION_RSVP_ERROR_FLAGS, OPTION_RSVP_ERROR_CODE, OPTION_RSVP_ERROR_VALUE, OPTION_RSVP_SCOPE, OPTION_RSVP_SCOPE_ADDRESS, OPTION_RSVP_STYLE_OPTION, OPTION_RSVP_SENDER_ADDRESS, OPTION_RSVP_SENDER_PORT, OPTION_RSVP_TSPEC_TRAFFIC, OPTION_RSVP_TSPEC_GUARANTEED, OPTION_RSVP_TSPEC_TOKEN_R, OPTION_RSVP_TSPEC_TOKEN_B, OPTION_RSVP_TSPEC_DATA_P, OPTION_RSVP_TSPEC_MINIMUM, OPTION_RSVP_TSPEC_MAXIMUM, OPTION_RSVP_ADSPEC_ISHOP, OPTION_RSVP_ADSPEC_PATH, OPTION_RSVP_ADSPEC_MINIMUM, OPTION_RSVP_ADSPEC_MTU, OPTION_RSVP_ADSPEC_GUARANTEED, OPTION_RSVP_ADSPEC_CONTROLLED, OPTION_RSVP_ADSPEC_CTOT, OPTION_RSVP_ADSPEC_DTOT, OPTION_RSVP_ADSPEC_CSUM, OPTION_RSVP_ADSPEC_DSUM, OPTION_RSVP_CONFIRM_ADDR, /* XXX IPSEC HEADER OPTIONS (IPPROTO_AH = 51 & IPPROTO_ESP = 50) */ OPTION_IPSEC_AH_LENGTH, OPTION_IPSEC_AH_SPI, OPTION_IPSEC_AH_SEQUENCE, OPTION_IPSEC_ESP_SPI, OPTION_IPSEC_ESP_SEQUENCE, /* XXX EIGRP HEADER OPTIONS (IPPROTO_EIGRP = 88) */ OPTION_EIGRP_OPCODE, OPTION_EIGRP_FLAGS, OPTION_EIGRP_SEQUENCE, OPTION_EIGRP_ACKNOWLEDGE, OPTION_EIGRP_AS, OPTION_EIGRP_TYPE, OPTION_EIGRP_LENGTH, OPTION_EIGRP_K1, OPTION_EIGRP_K2, OPTION_EIGRP_K3, OPTION_EIGRP_K4, OPTION_EIGRP_K5, OPTION_EIGRP_HOLD, OPTION_EIGRP_IOS_VERSION, OPTION_EIGRP_PROTO_VERSION, OPTION_EIGRP_NEXTHOP, OPTION_EIGRP_DELAY, OPTION_EIGRP_BANDWIDTH, OPTION_EIGRP_MTU, OPTION_EIGRP_HOP_COUNT, OPTION_EIGRP_LOAD, OPTION_EIGRP_RELIABILITY, OPTION_EIGRP_DESINATION, OPTION_EIGRP_SOURCE_ROUTER, OPTION_EIGRP_SOURCE_AS, OPTION_EIGRP_TAG, OPTION_EIGRP_METRIC, OPTION_EIGRP_ID, OPTION_EIGRP_EXTERNAL_FLAGS, OPTION_EIGRP_ADDRESS, OPTION_EIGRP_MULTICAST, OPTION_EIGRP_AUTHENTICATION, OPTION_EIGRP_AUTH_KEY_ID, /* XXX OSPF HEADER OPTIONS (IPPROTO_OSPF = 89) */ OPTION_OSPF_TYPE, OPTION_OSPF_LENGTH, OPTION_OSPF_ROUTER_ID, OPTION_OSPF_AREA_ID, OPTION_OSPF_NETMASK, OPTION_OSPF_MT, OPTION_OSPF_E, OPTION_OSPF_MC, OPTION_OSPF_NP, OPTION_OSPF_L, OPTION_OSPF_DC, OPTION_OSPF_O, OPTION_OSPF_DN, OPTION_OSPF_HELLO_INTERVAL, OPTION_OSPF_HELLO_PRIORITY, OPTION_OSPF_HELLO_DEAD, OPTION_OSPF_HELLO_DESIGN, OPTION_OSPF_HELLO_BACKUP, OPTION_OSPF_HELLO_NEIGHBOR, OPTION_OSPF_HELLO_ADDRESS, OPTION_OSPF_DD_MTU, OPTION_OSPF_DD_MASTER_SLAVE, OPTION_OSPF_DD_MORE, OPTION_OSPF_DD_INIT, OPTION_OSPF_DD_OOBRESYNC, OPTION_OSPF_DD_SEQUENCE, OPTION_OSPF_DD_INCLUDE_LSA, OPTION_OSPF_LSA_AGE, OPTION_OSPF_LSA_DO_NOT_AGE, OPTION_OSPF_LSA_TYPE, OPTION_OSPF_LSA_LSID, OPTION_OSPF_LSA_ROUTER, OPTION_OSPF_LSA_SEQUENCE, OPTION_OSPF_LSA_METRIC, OPTION_OSPF_LSA_FLAG_BORDER, OPTION_OSPF_LSA_FLAG_EXTERNAL, OPTION_OSPF_LSA_FLAG_VIRTUAL, OPTION_OSPF_LSA_FLAG_WILD, OPTION_OSPF_LSA_FLAG_NSSA_TR, OPTION_OSPF_LSA_LINK_ID, OPTION_OSPF_LSA_LINK_DATA, OPTION_OSPF_LSA_LINK_TYPE, OPTION_OSPF_LSA_ATTACHED, OPTION_OSPF_LSA_LARGER, OPTION_OSPF_LSA_FORWARD, OPTION_OSPF_LSA_EXTERNAL, OPTION_OSPF_VERTEX_ROUTER, OPTION_OSPF_VERTEX_NETWORK, OPTION_OSPF_VERTEX_ID, OPTION_OSPF_LLS_OPTION_LR, OPTION_OSPF_LLS_OPTION_RS, OPTION_OSPF_AUTHENTICATION, OPTION_OSPF_AUTH_KEY_ID, OPTION_OSPF_AUTH_SEQUENCE }; /** T50 Configuration structure. */ struct config_options { /* XXX COMMON OPTIONS */ threshold_T threshold; /* amount of packets */ _Bool flood; /* flood */ _Bool encapsulated; /* GRE encapsulated */ _Bool bogus_csum; /* bogus packet checksum */ _Bool shuffle; /* Shuffling option for T50 proto. */ _Bool quiet; /* Non-verbose mode. */ #ifdef __HAVE_TURBO__ _Bool turbo; /* duplicate the attack */ #endif /* __HAVE_TURBO__ */ /* XXX DCCP, TCP & UDP HEADER OPTIONS */ uint16_t source; /* general source port */ uint16_t dest; /* general destination port */ uint32_t bits; /* CIDR bits */ /* XXX IP HEADER OPTIONS (IPPROTO_IP = 0) */ struct { uint8_t tos; /* type of service */ uint16_t id; /* identification */ uint16_t frag_off; /* fragmentation offset */ uint8_t ttl; /* time to live */ uint8_t protocol; /* packet protocol */ uint32_t protoname; /* protocol name */ in_addr_t saddr; /* source address */ in_addr_t daddr; /* destination address */ } ip; /* XXX GRE HEADER OPTIONS (IPPROTO_GRE = 47) */ struct { /*uint8_t options;*/ /* GRE options bitmask */ _Bool S; /* sequence number present */ _Bool K; /* key present */ _Bool C; /* checksum present */ uint32_t key; /* key */ uint32_t sequence; /* sequence number */ in_addr_t saddr; /* GRE source address */ in_addr_t daddr; /* GRE destination address */ } gre; /* XXX ICMP HEADER OPTIONS (IPPROTO_ICMP = 1) */ struct { uint8_t type; /* type */ uint8_t code; /* code */ uint16_t id; /* identification */ uint16_t sequence; /* sequence number */ in_addr_t gateway; /* gateway address */ } icmp; /* XXX IGMP HEADER OPTIONS (IPPROTO_IGMP = 2) */ struct { uint8_t type; /* type */ uint8_t code; /* code */ in_addr_t group; /* group address */ uint8_t qrv: 3; /* querier robustness variable */ _Bool suppress; /* suppress router-side */ uint8_t qqic; /* querier query interv. code */ uint8_t grec_type; /* group record type */ uint8_t sources; /* number of sources */ in_addr_t grec_mca; /* group record multicast addr */ in_addr_t address[255]; /* source address(es) */ } igmp; /* XXX TCP HEADER OPTIONS (IPPROTO_TCP = 6) */ struct { uint32_t sequence; /* initial sequence number */ uint32_t acknowledge; /* acknowledgment sequence */ uint8_t doff: 4; /* data offset */ _Bool fin; /* end of data flag */ _Bool syn; /* synchronize ISN flag */ _Bool rst; /* reset connection flag */ _Bool psh; /* push flag */ _Bool ack; /* acknowledgment # valid flag */ _Bool urg; /* urgent pointer valid flag */ _Bool ece; /* ecn-echo */ _Bool cwr; /* congestion windows reduced */ uint16_t window; /* window size */ uint16_t urg_ptr; /* urgent pointer data */ uint8_t options; /* TCP options bitmask */ uint16_t mss; /* MSS option (RFC793) */ uint8_t wsopt; /* WSOPT option (RFC1323) */ uint32_t tsval; /* TSval option (RFC1323) */ uint32_t tsecr; /* TSecr option (RFC1323) */ uint32_t cc; /* T/TCP CC (RFC1644) */ uint32_t cc_new; /* T/TCP CC.NEW (RFC1644) */ uint32_t cc_echo; /* T/TCP CC.ECHO (RFC1644) */ uint32_t sack_left; /* SACK-Left option (RFC2018) */ uint32_t sack_right; /* SACK-Right option (RFC2018) */ _Bool md5; /* MD5 Option (RFC2385) */ _Bool auth; /* AO Option (RFC5925) */ uint8_t key_id; /* AO key ID (RFC5925) */ uint8_t next_key; /* AO next key ID (RFC5925) */ uint8_t nop; /* NOP option (RFC793) */ } tcp; /* XXX EGP HEADER OPTIONS (IPPROTO_EGP = 8) */ struct { uint8_t type; /* type */ uint8_t code; /* code */ uint8_t status; /* status */ uint16_t as; /* autonomous system */ uint16_t sequence; /* sequence number */ uint16_t hello; /* hello interval */ uint16_t poll; /* poll interval */ } egp; /* XXX RIP HEADER OPTIONS (IPPROTO_UDP = 17) */ struct { uint8_t command; /* command */ uint16_t family; /* address family identifier */ in_addr_t address; /* IP address */ uint32_t metric; /* metric */ uint16_t domain; /* router domain */ uint16_t tag; /* router tag */ in_addr_t netmask; /* subnet mask */ in_addr_t next_hop; /* next hop */ _Bool auth; /* authentication */ uint8_t key_id; /* authentication key ID */ uint32_t sequence; /* authentication sequence */ } rip; /* XXX DCCP HEADER OPTIONS (IPPROTO_DCCP = 33) */ struct { uint8_t doff; /* data offset */ uint8_t cscov: 4; /* checksum coverage */ uint8_t ccval: 4; /* HC-sender CCID */ uint8_t type: 4; /* DCCP type */ _Bool ext; /* extend the sequence number */ uint16_t sequence_01; /* sequence number */ uint8_t sequence_02; /* extended sequence number */ uint32_t sequence_03; /* low sequence number */ uint32_t service; /* service code */ uint16_t acknowledge_01; /* acknowledgment # high */ uint32_t acknowledge_02; /* acknowledgment # low */ uint8_t rst_code; /* reset code */ } dccp; /* XXX RSVP HEADER OPTIONS (IPPROTO_RSVP = 46) */ struct { uint8_t flags: 4; /* flags */ uint8_t type; /* message type */ uint8_t ttl; /* time to live */ in_addr_t session_addr; /* SESSION destination address */ uint8_t session_proto; /* SESSION protocol ID */ uint8_t session_flags; /* SESSION flags */ uint16_t session_port; /* SESSION destination port */ in_addr_t hop_addr; /* RESV_HOP neighbor address */ uint32_t hop_iface; /* RESV_HOP logical interface */ uint32_t time_refresh; /* TIME refresh interval */ in_addr_t error_addr; /* ERROR node address */ uint8_t error_flags: 3; /* ERROR flags */ uint8_t error_code; /* ERROR code */ uint16_t error_value; /* ERROR value */ uint8_t scope; /* number of SCOPE(s) */ in_addr_t address[255]; /* SCOPE address(es) */ uint32_t style_opt: 24; /* STYLE option vector */ in_addr_t sender_addr; /* SENDER TEMPLATE address */ uint16_t sender_port; /* SENDER TEMPLATE port */ uint8_t tspec; /* TSPEC services */ uint32_t tspec_r; /* TSPEC Token Bucket Rate */ uint32_t tspec_b; /* TSPEC Token Bucket Size */ uint32_t tspec_p; /* TSPEC Peak Data Rate */ uint32_t tspec_m; /* TSEPC Minimum Policed Unit */ uint32_t tspec_M; /* TSPEC Maximum Packet Size */ uint32_t adspec_hop; /* ADSPEC IS HOP cnt */ uint32_t adspec_path; /* ADSPEC Path b/w estimate */ uint32_t adspec_minimum; /* ADSPEC Minimum Path Latency */ uint32_t adspec_mtu; /* ADSPEC Composed MTU */ uint8_t adspec; /* ADSPEC services */ uint32_t adspec_Ctot; /* ADSPEC ETE composed value C */ uint32_t adspec_Dtot; /* ADSPEC ETE composed value D */ uint32_t adspec_Csum; /* ADSPEC SLR point composed C */ uint32_t adspec_Dsum; /* ADSPEC SLR point composed C */ in_addr_t confirm_addr; /* CONFIRM receiver address */ } rsvp; /* XXX IPSEC HEADER OPTIONS (IPPROTO_AH = 51 & IPPROTO_ESP = 50) */ struct { uint8_t ah_length; /* AH header length */ uint32_t ah_spi; /* AH SPI */ uint32_t ah_sequence; /* AH sequence number */ uint32_t esp_spi; /* ESP SPI */ uint32_t esp_sequence; /* ESP sequence number */ } ipsec; /* XXX EIGRP HEADER OPTIONS (IPPROTO_EIGRP = 88) */ struct { uint8_t opcode; /* opcode */ uint32_t flags; /* flags */ uint32_t sequence; /* sequence number */ uint32_t acknowledge; /* acknowledgment sequence # */ uint32_t as; /* autonomous system */ uint16_t type; /* type */ uint16_t length; /* length */ uint8_t values; /* EIGRP K values bitmask */ uint8_t k1; /* K1 value */ uint8_t k2; /* K2 value */ uint8_t k3; /* K3 value */ uint8_t k4; /* K4 value */ uint8_t k5; /* K5 value */ uint16_t hold; /* hold time */ uint8_t ios_major; /* IOS Major Version */ uint8_t ios_minor; /* IOS Minor Version */ uint8_t ver_major; /* EIGRP Major Version */ uint8_t ver_minor; /* EIGRP Minor Version */ in_addr_t next_hop; /* next hop address */ uint32_t delay; /* delay */ uint32_t bandwidth; /* bandwidth */ uint32_t mtu: 24; /* maximum transmission unit */ uint8_t hop_count; /* hop count */ uint8_t load; /* load */ uint8_t reliability; /* reliability */ uint8_t prefix: 5; /* subnet prefix - aka CIDR */ in_addr_t dest; /* destination address */ in_addr_t src_router; /* originating router */ uint32_t src_as; /* originating autonomous sys */ uint32_t tag; /* arbitrary tag */ uint32_t proto_metric; /* external protocol metric */ uint8_t proto_id; /* external protocol ID */ uint8_t ext_flags; /* external flags */ in_addr_t address; /* IP address sequence */ uint32_t multicast; /* multicast sequence */ _Bool auth; /* authentication */ uint32_t key_id; /* authentication key ID */ } eigrp; /* XXX OSPF HEADER OPTIONS (IPPROTO_OSPF = 89) */ struct { uint8_t type; /* type */ uint16_t length; /* length */ in_addr_t rid; /* router ID */ in_addr_t aid; /* area ID */ _Bool AID; /* area ID present */ uint8_t options; /* options */ in_addr_t netmask; /* subnet mask */ uint16_t hello_interval; /* HELLO interval */ uint8_t hello_priority; /* HELLO router priority */ uint32_t hello_dead; /* HELLO router dead interval */ in_addr_t hello_design; /* HELLO designated router */ in_addr_t hello_backup; /* HELLO backup designated */ uint8_t neighbor; /* HELLO number of neighbors */ in_addr_t address[255]; /* HELLO neighbor address(es) */ uint16_t dd_mtu; /* DD MTU */ uint8_t dd_dbdesc; /* DD DB description */ uint32_t dd_sequence; /* DD sequence number */ _Bool dd_include_lsa; /* DD LSA Header */ uint16_t lsa_age; /* LSA age */ _Bool lsa_dage; /* LSA do not age */ uint8_t lsa_type; /* LSA header type */ in_addr_t lsa_lsid; /* LSA ID */ in_addr_t lsa_router; /* LSA advertising router */ uint32_t lsa_sequence; /* LSA sequence number */ uint32_t lsa_metric: 24; /* LSA metric */ uint8_t lsa_flags; /* Router-LSA flags */ in_addr_t lsa_link_id; /* Router-LSA link ID */ in_addr_t lsa_link_data; /* Router-LSA link data */ uint8_t lsa_link_type; /* Router-LSA link type */ in_addr_t lsa_attached; /* Network-LSA attached router */ _Bool lsa_larger; /* ASBR/NSSA-LSA ext. larger */ in_addr_t lsa_forward; /* ASBR/NSSA-LSA forward */ in_addr_t lsa_external; /* ASBR/NSSA-LSA external */ uint32_t vertex_type; /* Group-LSA vertex type */ in_addr_t vertex_id; /* Group-LSA vertex ID */ uint32_t lls_options; /* LSS Extended TLV options */ _Bool auth; /* authentication */ uint8_t key_id; /* authentication key ID */ uint32_t sequence; /* authentication sequence */ } ospf; /* NOTE: Add structures configuration for new protocols here! */ }; typedef struct config_options config_options_T; /* Structure used to contain the command line options info. */ struct options_table_s { int id; /* This is the value returned by find_option(). */ char short_opt; /* Single char short option (ou '\0' if none). */ char *long_opt; /* String for long option name (or NULL is none.) */ _Bool has_arg; /* If option must have an argument, this is 1. */ /* "private" part. */ _Bool in_use_; /* Boolean used to check if option was already used. */ }; /* structure used in getConfigOptions() and get_ip_and_cidr_from_string() */ typedef struct { uint32_t addr; uint32_t cidr; } addr_T; config_options_T *parse_command_line ( char ** ); #endif /* CONFIG_H */ src/include/t50_netio.h0000644000175000017500000000271513712774300015746 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2014 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __NETIO_H__ #define __NETIO_H__ #include #include #include #include #include extern uint64_t bytes_sent; extern uint64_t packets_sent; /* Common routines used by code */ in_addr_t resolv ( char * ); /* Resolve name to ip address. */ void create_socket ( void ); /* Creates the sending socket */ void close_socket ( void ); /* Close the previously created socket */ /* Send the actual packet from buffer, with size bytes, using config options. */ int send_packet ( const void * const, size_t, const config_options_T * const restrict ); #endif src/include/t50_defines.h0000644000175000017500000000455314006276341016246 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2014 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __DEFINES_INCLUDED__ #define __DEFINES_INCLUDED__ #define _NOINLINE __attribute__((noinline)) #define _INIT __attribute__((constructor)) #define _FINI __attribute__((destructor)) /** * Amount of time, in seconds, to wait for child process termination. */ #define WAIT_FOR_CHILD_TIMEOUT 5 /** * Initial packet buffer preallocation size (2 kB). * * This size should be sufficient for all packets. * MTU usually is 1500 bytes long, over ethernet! */ #define INITIAL_PACKET_SIZE 2048 #define MAXIMUM_IP_ADDRESSES ((1U << 24) - 1) /* #define INADDR_ANY 0 */ // NOTE: Already defined in multiple headers (linux/in.h & netinet/in.h). #define IPPORT_ANY 0 /* Global common protocol definitions used by code */ #define AUTH_TYPE_HMACNUL 0 #define AUTH_TYPE_HMACMD5 2 #define AUTH_TLEN_HMACMD5 16 #define auth_hmac_md5_len(foo) ((foo) ? AUTH_TLEN_HMACMD5 : 0) /* T50 DEFINITIONS. */ #define IPPROTO_T50 69 #define FIELD_MUST_BE_ZERO 0 /** Macro used to test bitmasks */ #define TEST_BITS(x,bits) ((x) & (bits)) /** Used to test if "pid" from fork() is from a child process. */ /* NOTE: fork returns always 0 for the child process. */ #define IS_CHILD_PID(p) (!(p)) #define swap(a,b) { typeof((a)) t; t = (a); (a) = (b); (b) = t; } #define SAFE_FREE(ptr) { free((ptr)); (ptr) = NULL; } #ifdef USE_ANSI #define ERROR "\x1b[31m[ERROR]\x1b[0m" #define FATAL "\x1b[31;1m[FATAL]\x1b[0m" #define INFO "\x1b[33;1m[INFO]\x1b[0m " #define DEBUG "\x1b[34m[DEBUG]\x1b[0m" #else #define ERROR "[ERROR]" #define FATAL "[FATAL]" #define INFO "[INFO] " #define DEBUG "[DEBUG]" #endif #endif src/shuffle.c0000644000175000017500000000206513712774300014142 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /** @file shuffle.c */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2019 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include // Knuth-Fisher-Yates (this one) is faster! void shuffle ( uint32_t *p, size_t size ) { size_t i; while ( size ) { i = RANDOM() % size--; swap ( p[size], p[i] ); } } src/randomizer.c0000664000175000017500000000512714107316050014655 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /** @file randomizer.c */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2019 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include #include #include /* The Random SEED will be created by SRANDOM */ static uint64_t _seed[2]; /* xorshift128+ We don't have to worry about the lower bits been less random than the upper, in theory. */ uint32_t random_xorshift128plus ( void ) { uint64_t s0 = _seed[1]; uint64_t s1 = _seed[0]; _seed[0] = s0; s1 ^= s1 << 23; _seed[1] = s1 ^ s0 ^ ( s1 >> 18 ) ^ ( s0 >> 5 ); return ( _seed[1] + s0 ); } void get_random_seed ( void ) { // NOTE: Could use gettimeofday() and use it as seed, // but, this way I'll make sure the seed is random. int _fd, r; void *p, *endp; if ( ( _fd = open ( "/dev/urandom", O_RDONLY ) ) == -1 ) fatal_error ( "Cannot open /dev/urandom to get initial random seed." ); /* NOTE: initializes this code "global" _seed var. */ p = &_seed; endp = p + sizeof _seed; while ( p < endp ) { if ( ( r = read ( _fd, p, endp - p ) ) == -1 ) break; p += r; } close ( _fd ); if ( r == -1 ) fatal_error ( "Cannot read initial seed from /dev/urandom." ); } /** * Returns the Randomized netmask if foo is 0 or the parameter, otherwise. * * This routine shouldn't be inlined due to its compliexity. * * @param foo IPv4 netmask (or 0 if randomized). * @return Netmask (randomized or otherwise). */ uint32_t NETMASK_RND ( uint32_t foo ) { if ( ! foo ) { uint32_t t = RANDOM() & 0x1f; /* Here t is something between 0 and 31. */ /* NOTE: This is faster than 't %= 23'. */ if ( t > 22 ) t -= 23; /* Here t is something between 0 and 22 */ /* We need someting between 8 and 30 bits only! */ foo = htonl ( ~ ( ~0U >> ( t + 8 ) ) ); } return foo; } src/config.c0000664000175000017500000020651314107315014013751 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /** @file config.c */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2019 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* Local prototypes. */ static int check_if_option ( char * ); static int check_if_nul_option ( char * ); static void check_options_rules ( const config_options_T * ); _NOINLINE static struct options_table_s *find_option ( char * ); static void set_config_option ( config_options_T * restrict, char * restrict, int, char * restrict ); _NOINLINE static uint32_t toULong ( char * restrict, char * restrict ); _NOINLINE static uint32_t toULongCheckRange ( char * restrict, char * restrict, uint32_t, uint32_t ); _NOINLINE static void check_list_separators ( char * restrict, char * restrict ); static void set_destination_addresses ( char * restrict, config_options_T * restrict ); static void list_protocols ( void ); static void set_default_protocol ( config_options_T * ); static void get_ip_protocol ( config_options_T * restrict, char * restrict ); static int get_ip_and_cidr_from_string ( char const * const, addr_T * ); _NOINLINE static int get_dual_values ( char *, unsigned long *, unsigned long *, unsigned long, int, char, char * ); static int check_threshold ( const config_options_T * const ); static int check_for_valid_option ( int, int * ); // Must disable this warning 'cause the initializations are right! #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wmissing-field-initializers" /* Default command line interface options. */ static config_options_T co = { /* XXX COMMON OPTIONS */ .threshold = 1000, /* default threshold */ /* XXX IP HEADER OPTIONS (IPPROTO_IP = 0) */ .ip = { .tos = IPTOS_PREC_IMMEDIATE, /* default type of service */ .ttl = 255 /* default time to live */ }, /* XXX ICMP HEADER OPTIONS (IPPROTO_ICMP = 1) */ .icmp = { .type = ICMP_ECHO }, /* default type */ /* XXX IGMP HEADER OPTIONS (IPPROTO_IGMP = 2) */ .igmp = { .type = IGMP_HOST_MEMBERSHIP_QUERY, /* default type */ .grec_type = 1, /* default group record type */ .sources = 2 /* default number of sources */ }, /* XXX TCP HEADER OPTIONS (IPPROTO_TCP = 6) */ .tcp = { .key_id = 1, /* default AO key ID (RFC5925) */ .next_key = 1, /* default AO next key ID (RFC5925) */ .nop = TCPOPT_EOL /* default NOP option (RFC793) */ }, /* XXX EGP HEADER OPTIONS (IPPROTO_EGP = 8) */ .egp = { .type = EGP_NEIGHBOR_ACQUISITION, /* default type */ .code = EGP_ACQ_CODE_CEASE_CMD, /* default code */ .status = EGP_ACQ_STAT_ACTIVE_MODE /* default status */ }, /* XXX RIP HEADER OPTIONS (IPPROTO_UDP = 17) */ .rip = { .command = 2, /* default command */ .family = AF_INET, /* default address family identifier */ .key_id = 1 /* default authentication key ID */ }, /* XXX DCCP HEADER OPTIONS (IPPROTO_DCCP = 33) */ .dccp = { .type = DCCP_PKT_REQUEST }, /* default type */ /* XXX RSVP HEADER OPTIONS (IPPROTO_RSVP = 46) */ .rsvp = { .flags = 1, /* default flags */ .type = RSVP_MESSAGE_TYPE_PATH, /* default message type */ .ttl = 254, /* default time to live */ .session_proto = 1, /* default SESSION protocol ID */ .session_flags = 1, /* default SESSION flags */ .time_refresh = 360, /* default TIME refresh interval */ .error_flags = 2, /* default ERROR flags */ .error_code = 2, /* default ERROR code */ .error_value = 8, /* default ERROR value */ .scope = 1, /* default number of SCOPE(s) */ .style_opt = 18, /* default STYLE option vector */ .tspec = 6 /* default TSPEC service */ }, /* XXX EIGRP HEADER OPTIONS (IPPROTO_EIGRP = 88) */ .eigrp = { .opcode = EIGRP_OPCODE_UPDATE, /* default opcode */ .type = EIGRP_TYPE_INTERNAL, /* default type */ .k1 = 1, /* default K1 value */ .k3 = 1, /* default K3 value */ .hold = 360, /* default hold time */ .ios_major = 12, /* default IOS Major Version */ .ios_minor = 4, /* default IOS Minor Version */ .ver_major = 1, /* default EIGRP Major Version */ .ver_minor = 2, /* default EIGRP Minor Version */ .mtu = 1500, /* default maximum transmission unit */ .proto_id = 2, /* default external protocol ID */ .key_id = 1 /* default authentication key ID */ }, /* XXX OSPF HEADER OPTIONS (IPPROTO_OSPF = 89) */ .ospf = { .type = OSPF_TYPE_HELLO, /* default type */ .hello_priority = 1, /* default HELLO router priority */ .hello_dead = 360, /* default HELLO router dead interval */ .dd_mtu = 1500, /* default DD MTU */ .lsa_age = 360, /* default LSA age */ .lsa_type = LSA_TYPE_ROUTER, /* default LSA header type */ .lsa_link_type = LINK_TYPE_PTP, /* default Router-LSA link type */ .key_id = 1 /* default authentication key ID */ } /* NOTE: Add configuration structured values for new protocols here! */ }; /* The actual command line options table. */ static struct options_table_s options[] = { { OPTION_VERSION, 'v', "version", 0 }, { OPTION_HELP, 'h', "help", 0 }, { OPTION_LIST_PROTOCOLS, 'l', "list-protocols", 0 }, #ifdef __HAVE_TURBO__ { OPTION_TURBO, 0, "turbo", 0 }, #endif { OPTION_THRESHOLD, 0, "threshold", 1 }, { OPTION_FLOOD, 0, "flood", 0 }, { OPTION_ENCAPSULATED, 0, "encapsulated", 0 }, { OPTION_BOGUSCSUM, 'B', "bogus-csum", 0 }, { OPTION_SHUFFLE, 0, "shuffle", 0 }, { OPTION_QUIET, 'q', "quiet", 0 }, /* XXX GRE HEADER OPTIONS (IPPROTO_GRE = 47) */ { OPTION_GRE_SEQUENCE_PRESENT, 0, "gre-seq-present", 0 }, { OPTION_GRE_KEY_PRESENT, 0, "gre-key-present", 0 }, { OPTION_GRE_CHECKSUM_PRESENT, 0, "gre-sum-present", 0 }, { OPTION_GRE_KEY, 0, "gre-key", 1 }, { OPTION_GRE_SEQUENCE, 0, "gre-sequence", 1 }, { OPTION_GRE_SADDR, 0, "gre-saddr", 1 }, { OPTION_GRE_DADDR, 0, "gre-daddr", 1 }, /* XXX DCCP, TCP & UDP HEADER OPTIONS */ { OPTION_SOURCE, 0, "sport", 1 }, { OPTION_DESTINATION, 0, "dport", 1 }, /* XXX IP HEADER OPTIONS (IPPROTO_IP = 0) */ { OPTION_IP_SOURCE, 's', "saddr", 1 }, { OPTION_IP_TOS, 0, "tos", 1 }, { OPTION_IP_ID, 0, "id", 1 }, { OPTION_IP_OFFSET, 0, "frag-offset", 1 }, { OPTION_IP_TTL, 0, "ttl", 1 }, { OPTION_IP_PROTOCOL, 'p', "protocol", 1 }, /* XXX ICMP HEADER OPTIONS (IPPROTO_ICMP = 1) */ { OPTION_ICMP_TYPE, 0, "icmp-type", 1 }, { OPTION_ICMP_CODE, 0, "icmp-code", 1 }, { OPTION_ICMP_GATEWAY, 0, "icmp-gateway", 1 }, { OPTION_ICMP_ID, 0, "icmp-id", 1 }, { OPTION_ICMP_SEQUENCE, 0, "icmp-sequence", 1 }, /* XXX IGMP HEADER OPTIONS (IPPROTO_IGMP = 2) */ { OPTION_IGMP_TYPE, 0, "igmp-type", 1 }, { OPTION_IGMP_CODE, 0, "igmp-code", 1 }, { OPTION_IGMP_GROUP, 0, "igmp-group", 1 }, { OPTION_IGMP_QRV, 0, "igmp-qrv", 1 }, { OPTION_IGMP_SUPPRESS, 0, "igmp-suppress", 0 }, { OPTION_IGMP_QQIC, 0, "igmp-qqic", 1 }, { OPTION_IGMP_GREC_TYPE, 0, "igmp-grec-type", 1 }, { OPTION_IGMP_SOURCES, 0, "igmp-sources", 1 }, { OPTION_IGMP_GREC_MULTICAST, 0, "igmp-multicast", 1 }, { OPTION_IGMP_ADDRESS, 0, "igmp-address", 1 }, /* XXX TCP HEADER OPTIONS (IPPROTO_TCP = 6) */ { OPTION_TCP_ACK_SEQ, 0, "ack-seq", 1 }, { OPTION_TCP_SEQUENCE, 0, "sequence", 1 }, { OPTION_TCP_OFFSET, 0, "data-offset", 1 }, { OPTION_TCP_FIN, 'F', "fin", 0 }, { OPTION_TCP_SYN, 'S', "syn", 0 }, { OPTION_TCP_RST, 'R', "rst", 0 }, { OPTION_TCP_PSH, 'P', "psh", 0 }, { OPTION_TCP_ACK, 'A', "ack", 0 }, { OPTION_TCP_URG, 'U', "urg", 0 }, { OPTION_TCP_ECE, 'E', "ece", 0 }, { OPTION_TCP_CWR, 'C', "cwr", 0 }, { OPTION_TCP_WINDOW, 'W', "window", 1 }, { OPTION_TCP_URGENT_POINTER, 0, "urg-pointer", 1 }, { OPTION_TCP_MSS, 0, "mss", 1 }, { OPTION_TCP_WSOPT, 0, "wscale", 1 }, { OPTION_TCP_TSOPT, 0, "tstamp", 1 }, { OPTION_TCP_SACK_OK, 0, "sack-ok", 0 }, { OPTION_TCP_CC, 0, "cc", 1 }, { OPTION_TCP_CC_NEW, 0, "ccnew", 1 }, { OPTION_TCP_CC_ECHO, 0, "ccecho", 1 }, { OPTION_TCP_SACK_EDGE, 0, "sack", 1 }, { OPTION_TCP_MD5_SIGNATURE, 0, "md5-signature", 0 }, { OPTION_TCP_AUTHENTICATION, 0, "authentication", 0 }, { OPTION_TCP_AUTH_KEY_ID, 0, "auth-key-id", 1 }, { OPTION_TCP_AUTH_NEXT_KEY, 0, "auth-next-key", 1 }, { OPTION_TCP_NOP, 0, "nop", 0 }, /* XXX EGP HEADER OPTIONS (IPPROTO_EGP = 8) */ { OPTION_EGP_TYPE, 0, "egp-type", 1 }, { OPTION_EGP_CODE, 0, "egp-code", 1 }, { OPTION_EGP_STATUS, 0, "egp-status", 1 }, { OPTION_EGP_AS, 0, "egp-as", 1 }, { OPTION_EGP_SEQUENCE, 0, "egp-sequence", 1 }, { OPTION_EGP_HELLO, 0, "egp-hello", 1 }, { OPTION_EGP_POLL, 0, "egp-poll", 1 }, /* XXX RIP HEADER OPTIONS (IPPROTO_UDP = 17) */ { OPTION_RIP_COMMAND, 0, "rip-command", 1 }, { OPTION_RIP_FAMILY, 0, "rip-family", 1 }, { OPTION_RIP_ADDRESS, 0, "rip-address", 1 }, { OPTION_RIP_METRIC, 0, "rip-metric", 1 }, { OPTION_RIP_DOMAIN, 0, "rip-domain", 1 }, { OPTION_RIP_TAG, 0, "rip-tag", 1 }, { OPTION_RIP_NETMASK, 0, "rip-netmask", 1 }, { OPTION_RIP_NEXTHOP, 0, "rip-next-hop", 1 }, { OPTION_RIP_AUTHENTICATION, 0, "rip-authentication", 0 }, { OPTION_RIP_AUTH_KEY_ID, 0, "rip-auth-key-id", 1 }, { OPTION_RIP_AUTH_SEQUENCE, 0, "rip-auth-sequence", 1 }, /* XXX DCCP HEADER OPTIONS (IPPROTO_DCCP = 33) */ { OPTION_DCCP_OFFSET, 0, "dccp-data-offset", 1 }, { OPTION_DCCP_CSCOV, 0, "dccp-cscov", 1 }, { OPTION_DCCP_CCVAL, 0, "dccp-ccval", 1 }, { OPTION_DCCP_TYPE, 0, "dccp-type", 1 }, { OPTION_DCCP_EXTEND, 0, "dccp-extended", 0 }, { OPTION_DCCP_SEQUENCE_01, 0, "dccp-sequence-1", 1 }, { OPTION_DCCP_SEQUENCE_02, 0, "dccp-sequence-2", 1 }, { OPTION_DCCP_SEQUENCE_03, 0, "dccp-sequence-3", 1 }, { OPTION_DCCP_SERVICE, 0, "dccp-service", 1 }, { OPTION_DCCP_ACKNOWLEDGE_01, 0, "dccp-acknowledge-1", 1 }, { OPTION_DCCP_ACKNOWLEDGE_02, 0, "dccp-acknowledge-2", 1 }, { OPTION_DCCP_RESET_CODE, 0, "dccp-reset-code", 1 }, /* XXX RSVP HEADER OPTIONS (IPPROTO_RSVP = 46) */ { OPTION_RSVP_FLAGS, 0, "rsvp-flags", 1 }, { OPTION_RSVP_TYPE, 0, "rsvp-type", 1 }, { OPTION_RSVP_TTL, 0, "rsvp-ttl", 1 }, { OPTION_RSVP_SESSION_ADDRESS, 0, "rsvp-session-addr", 1 }, { OPTION_RSVP_SESSION_PROTOCOL, 0, "rsvp-session-proto", 1 }, { OPTION_RSVP_SESSION_FLAGS, 0, "rsvp-session-flags", 1 }, { OPTION_RSVP_SESSION_PORT, 0, "rsvp-session-port", 1 }, { OPTION_RSVP_HOP_ADDRESS, 0, "rsvp-hop-addr", 1 }, { OPTION_RSVP_HOP_IFACE, 0, "rsvp-hop-iface", 1 }, { OPTION_RSVP_TIME_REFRESH, 0, "rsvp-time-refresh", 1 }, { OPTION_RSVP_ERROR_ADDRESS, 0, "rsvp-error-addr", 1 }, { OPTION_RSVP_ERROR_FLAGS, 0, "rsvp-error-flags", 1 }, { OPTION_RSVP_ERROR_CODE, 0, "rsvp-error-code", 1 }, { OPTION_RSVP_ERROR_VALUE, 0, "rsvp-error-value", 1 }, { OPTION_RSVP_SCOPE, 0, "rsvp-scope", 1 }, { OPTION_RSVP_SCOPE_ADDRESS, 0, "rsvp-address", 1 }, { OPTION_RSVP_STYLE_OPTION, 0, "rsvp-style-option", 1 }, { OPTION_RSVP_SENDER_ADDRESS, 0, "rsvp-sender-addr", 1 }, { OPTION_RSVP_SENDER_PORT, 0, "rsvp-sender-port", 1 }, { OPTION_RSVP_TSPEC_TRAFFIC, 0, "rsvp-tspec-traffic", 0 }, { OPTION_RSVP_TSPEC_GUARANTEED, 0, "rsvp-tspec-guaranteed", 0 }, { OPTION_RSVP_TSPEC_TOKEN_R, 0, "rsvp-tspec-r", 1 }, { OPTION_RSVP_TSPEC_TOKEN_B, 0, "rsvp-tspec-b", 1 }, { OPTION_RSVP_TSPEC_DATA_P, 0, "rsvp-tspec-p", 1 }, { OPTION_RSVP_TSPEC_MINIMUM, 0, "rsvp-tspec-m", 1 }, { OPTION_RSVP_TSPEC_MAXIMUM, 0, "rsvp-tspec-M", 1 }, { OPTION_RSVP_ADSPEC_ISHOP, 0, "rsvp-adspec-ishop", 1 }, { OPTION_RSVP_ADSPEC_PATH, 0, "rsvp-adspec-path", 1 }, { OPTION_RSVP_ADSPEC_MINIMUM, 0, "rsvp-adspec-m", 1 }, { OPTION_RSVP_ADSPEC_MTU, 0, "rsvp-adspec-mtu", 1 }, { OPTION_RSVP_ADSPEC_GUARANTEED, 0, "rsvp-adspec-guaranteed", 0 }, { OPTION_RSVP_ADSPEC_CTOT, 0, "rsvp-adspec-Ctot", 1 }, { OPTION_RSVP_ADSPEC_DTOT, 0, "rsvp-adspec-Dtot", 1 }, { OPTION_RSVP_ADSPEC_CSUM, 0, "rsvp-adspec-Csum", 1 }, { OPTION_RSVP_ADSPEC_DSUM, 0, "rsvp-adspec-Dsum", 1 }, { OPTION_RSVP_ADSPEC_CONTROLLED, 0, "rsvp-adspec-controlled", 0 }, { OPTION_RSVP_CONFIRM_ADDR, 0, "rsvp-confirm-addr", 1 }, /*O_ESP = 50) XXX IPSEC HEADER OPTIONS (IPPROTO_AH = 51 & IPPROT*/ { OPTION_IPSEC_AH_LENGTH, 0, "ipsec-ah-length", 1 }, { OPTION_IPSEC_AH_SPI, 0, "ipsec-ah-spi", 1 }, { OPTION_IPSEC_AH_SEQUENCE, 0, "ipsec-ah-sequence", 1 }, { OPTION_IPSEC_ESP_SPI, 0, "ipsec-esp-spi", 1 }, { OPTION_IPSEC_ESP_SEQUENCE, 0, "ipsec-esp-sequence", 1 }, /* XXX EIGRP HEADER OPTIONS (IPPROTO_EIGRP = 88) */ { OPTION_EIGRP_OPCODE, 0, "eigrp-opcode", 1 }, { OPTION_EIGRP_FLAGS, 0, "eigrp-flags", 1 }, { OPTION_EIGRP_SEQUENCE, 0, "eigrp-sequence", 1 }, { OPTION_EIGRP_ACKNOWLEDGE, 0, "eigrp-acknowledge", 1 }, { OPTION_EIGRP_AS, 0, "eigrp-as", 1 }, { OPTION_EIGRP_TYPE, 0, "eigrp-type", 1 }, { OPTION_EIGRP_LENGTH, 0, "eigrp-length", 1 }, { OPTION_EIGRP_K1, 0, "eigrp-k1", 1 }, { OPTION_EIGRP_K2, 0, "eigrp-k2", 1 }, { OPTION_EIGRP_K3, 0, "eigrp-k3", 1 }, { OPTION_EIGRP_K4, 0, "eigrp-k4", 1 }, { OPTION_EIGRP_K5, 0, "eigrp-k5", 1 }, { OPTION_EIGRP_HOLD, 0, "eigrp-hold", 1 }, { OPTION_EIGRP_IOS_VERSION, 0, "eigrp-ios-ver", 1 }, { OPTION_EIGRP_PROTO_VERSION, 0, "eigrp-rel-ver", 1 }, { OPTION_EIGRP_NEXTHOP, 0, "eigrp-next-hop", 1 }, { OPTION_EIGRP_DELAY, 0, "eigrp-delay", 1 }, { OPTION_EIGRP_BANDWIDTH, 0, "eigrp-bandwidth", 1 }, { OPTION_EIGRP_MTU, 0, "eigrp-mtu", 1 }, { OPTION_EIGRP_HOP_COUNT, 0, "eigrp-hop-count", 1 }, { OPTION_EIGRP_LOAD, 0, "eigrp-load", 1 }, { OPTION_EIGRP_RELIABILITY, 0, "eigrp-reliability", 1 }, { OPTION_EIGRP_DESINATION, 0, "eigrp-daddr", 1 }, { OPTION_EIGRP_SOURCE_ROUTER, 0, "eigrp-src-router", 1 }, { OPTION_EIGRP_SOURCE_AS, 0, "eigrp-src-as", 1 }, { OPTION_EIGRP_TAG, 0, "eigrp-tag", 1 }, { OPTION_EIGRP_METRIC, 0, "eigrp-proto-metric", 1 }, { OPTION_EIGRP_ID, 0, "eigrp-proto-id", 1 }, { OPTION_EIGRP_EXTERNAL_FLAGS, 0, "eigrp-ext-flags", 1 }, { OPTION_EIGRP_ADDRESS, 0, "eigrp-address", 1 }, { OPTION_EIGRP_MULTICAST, 0, "eigrp-multicast", 1 }, { OPTION_EIGRP_AUTHENTICATION, 0, "eigrp-authentication", 0 }, { OPTION_EIGRP_AUTH_KEY_ID, 0, "eigrp-auth-key-id", 1 }, /* XXX OSPF HEADER OPTIONS (IPPROTO_OSPF = 89) */ { OPTION_OSPF_TYPE, 0, "ospf-type", 1 }, { OPTION_OSPF_LENGTH, 0, "ospf-length", 1 }, { OPTION_OSPF_ROUTER_ID, 0, "ospf-router-id", 1 }, { OPTION_OSPF_AREA_ID, 0, "ospf-area-id", 1 }, { OPTION_OSPF_MT, 0, "ospf-option-MT", 0 }, { OPTION_OSPF_E, '2', "ospf-option-E", 0 }, { OPTION_OSPF_MC, '3', "ospf-option-MC", 0 }, { OPTION_OSPF_NP, '4', "ospf-option-NP", 0 }, { OPTION_OSPF_L, '5', "ospf-option-L", 0 }, { OPTION_OSPF_DC, '6', "ospf-option-DC", 0 }, { OPTION_OSPF_O, '7', "ospf-option-O", 0 }, { OPTION_OSPF_DN, '8', "ospf-option-DN", 0 }, { OPTION_OSPF_NETMASK, 0, "ospf-netmask", 1 }, { OPTION_OSPF_HELLO_INTERVAL, 0, "ospf-hello-interval", 1 }, { OPTION_OSPF_HELLO_PRIORITY, 0, "ospf-hello-priority", 1 }, { OPTION_OSPF_HELLO_DEAD, 0, "ospf-hello-dead", 1 }, { OPTION_OSPF_HELLO_DESIGN, 0, "ospf-hello-design", 1 }, { OPTION_OSPF_HELLO_BACKUP, 0, "ospf-hello-backup", 1 }, { OPTION_OSPF_HELLO_NEIGHBOR, 0, "ospf-neighbor", 1 }, { OPTION_OSPF_HELLO_ADDRESS, 0, "ospf-address", 1 }, { OPTION_OSPF_DD_MTU, 0, "ospf-dd-mtu", 1 }, { OPTION_OSPF_DD_MASTER_SLAVE, 0, "ospf-dd-dbdesc-MS", 0 }, { OPTION_OSPF_DD_MORE, 0, "ospf-dd-dbdesc-M", 0 }, { OPTION_OSPF_DD_INIT, 0, "ospf-dd-dbdesc-I", 0 }, { OPTION_OSPF_DD_OOBRESYNC, 0, "ospf-dd-dbdesc-R", 0 }, { OPTION_OSPF_DD_SEQUENCE, 0, "ospf-dd-sequence", 1 }, { OPTION_OSPF_DD_INCLUDE_LSA, 0, "ospf-dd-include-lsa", 0 }, { OPTION_OSPF_LSA_AGE, 0, "ospf-lsa-age", 1 }, { OPTION_OSPF_LSA_DO_NOT_AGE, 0, "ospf-lsa-do-not-age", 0 }, { OPTION_OSPF_LSA_TYPE, 0, "ospf-lsa-type", 1 }, { OPTION_OSPF_LSA_LSID, 0, "ospf-lsa-id", 1 }, { OPTION_OSPF_LSA_ROUTER, 0, "ospf-lsa-router", 1 }, { OPTION_OSPF_LSA_SEQUENCE, 0, "ospf-lsa-sequence", 1 }, { OPTION_OSPF_LSA_METRIC, 0, "ospf-lsa-metric", 1 }, { OPTION_OSPF_LSA_FLAG_BORDER, 0, "ospf-lsa-flag-B", 0 }, { OPTION_OSPF_LSA_FLAG_EXTERNAL, 0, "ospf-lsa-flag-E", 0 }, { OPTION_OSPF_LSA_FLAG_VIRTUAL, 0, "ospf-lsa-flag-V", 0 }, { OPTION_OSPF_LSA_FLAG_WILD, 0, "ospf-lsa-flag-W", 0 }, { OPTION_OSPF_LSA_FLAG_NSSA_TR, 0, "ospf-lsa-flag-NT", 0 }, { OPTION_OSPF_LSA_LINK_ID, 0, "ospf-lsa-link-id", 1 }, { OPTION_OSPF_LSA_LINK_DATA, 0, "ospf-lsa-link-data", 1 }, { OPTION_OSPF_LSA_LINK_TYPE, 0, "ospf-lsa-link-type", 1 }, { OPTION_OSPF_LSA_ATTACHED, 0, "ospf-lsa-attached", 1 }, { OPTION_OSPF_LSA_LARGER, 0, "ospf-lsa-larger", 0 }, { OPTION_OSPF_LSA_FORWARD, 0, "ospf-lsa-forward", 1 }, { OPTION_OSPF_LSA_EXTERNAL, 0, "ospf-lsa-external", 1 }, { OPTION_OSPF_VERTEX_ROUTER, 0, "ospf-vertex-router", 0 }, { OPTION_OSPF_VERTEX_NETWORK, 0, "ospf-vertex-network", 0 }, { OPTION_OSPF_VERTEX_ID, 0, "ospf-vertex-id", 1 }, { OPTION_OSPF_LLS_OPTION_LR, 0, "ospf-lls-extended-LR", 0 }, { OPTION_OSPF_LLS_OPTION_RS, 0, "ospf-lls-extended-RS", 0 }, { OPTION_OSPF_AUTHENTICATION, 0, "ospf-authentication", 0 }, { OPTION_OSPF_AUTH_KEY_ID, 0, "ospf-auth-key-id", 1 }, { OPTION_OSPF_AUTH_SEQUENCE, 0, "ospf-auth-sequence", 1 }, /* Last item must be all zeroes. */ { 0 } }; #pragma GCC diagnostic pop /* Substitutes getConfigOptions() function. NOTE: This function expects &argv[0] as the first argument. */ config_options_T *parse_command_line ( char **argv ) { struct options_table_s *ptbl; int num_options; char *opt, *next_str, *dest_addr; // Used just to help the compiler to merge strings... static const char * const errfmt = "Option '-%c' (or '--%s') cannot be used with other options."; num_options = 0; dest_addr = NULL; /* Ugly hack! */ set_default_protocol ( &co ); /* Check each argument starting from the next one. */ num_options = 0; while ( *++argv ) { opt = *argv; if ( check_if_option ( opt ) ) { /* Skip '--'. */ if ( check_if_nul_option ( opt ) ) continue; if ( ( ptbl = find_option ( opt ) ) == NULL ) fatal_error ( "Unrecognized option '%s'.", opt ); /* This will assume each option should be used only once. */ if ( ptbl->in_use_ ) fatal_error ( "Option '%s' already given.", opt ); ptbl->in_use_ = 1; /* If the option needs an argument, get the next string. */ if ( !! ( next_str = * ( argv + 1 ) ) ) { static const char * const ferrfmt = "Option '%s' has no arguments."; if ( ptbl->has_arg ) { if ( check_if_nul_option ( next_str ) ) // -- is NOT allowed! fatal_error ( ferrfmt, opt ); argv++; } else { if ( !check_if_nul_option ( next_str ) ) // -- is allowed! if ( !check_if_option ( next_str ) ) // no values allowed! fatal_error ( ferrfmt, opt ); } } if ( ptbl->has_arg && !next_str ) fatal_error ( "option '%s' must have an argument.", opt ); set_config_option ( &co, opt, ptbl->id, next_str ); } else { /* NOTE: This is not an option, so it must be an IP address. */ /* Check if already got an address. */ if ( dest_addr ) fatal_error ( "Target address given twice. Aborting..." ); dest_addr = *argv; set_destination_addresses ( dest_addr, &co ); } /* How many options we got so far? */ num_options++; } /* end of command line scan. */ /* NOTE: -h, -v or -l can be called by non-privileged user! */ /* if '-h' (or '--help') option is given... */ if ( ( ptbl = find_option ( "-h" ) ) != NULL ) if ( ptbl->in_use_ ) { if ( num_options > 1 ) error ( errfmt, 'h', "help" ); else usage(); exit ( EXIT_FAILURE ); } /* if '-v' (or '--version') option is given... */ if ( ( ptbl = find_option ( "-v" ) ) != NULL ) if ( ptbl->in_use_ ) { if ( num_options > 1 ) error ( errfmt, 'v', "version" ); /* --- already showing version, by default! --- */ //else // show_version(); exit ( EXIT_FAILURE ); } /* if '-l' (or '--list-protocols') option is given... */ if ( ( ptbl = find_option ( "-l" ) ) != NULL ) if ( ptbl->in_use_ ) { if ( num_options > 1 ) error ( errfmt, 'l', "list-protocols" ); else list_protocols(); exit ( EXIT_FAILURE ); } if ( ( ptbl = find_option ( "-q" ) ) != NULL ) if ( ptbl->in_use_ ) { if ( num_options > 1 ) { error ( errfmt, 'q', "quiet" ); exit ( EXIT_FAILURE ); } else co.quiet = 1; } /* We got all the options. Now, check their rules! */ check_options_rules ( &co ); return &co; } /* Check if the argument is an option. */ int check_if_option ( char *s ) { return *s == '-'; } int check_if_nul_option ( char *s ) { return !strcmp ( s, "--" ); } /* NOTE: Ugly hack, but necessary! The default protocol is TCP, but we weren't able to adjust on config_options structure previously. Do it now. */ void set_default_protocol ( config_options_T *co ) { modules_table_T *ptbl; int i; co->ip.protocol = IPPROTO_TCP; i = 0; ptbl = mod_table; while ( ptbl->protocol_id ) { if ( ptbl->protocol_id == IPPROTO_TCP ) { co->ip.protoname = i; break; } i++; ptbl++; } } /* Scans the option table trying to find the option. NOTE: "option" points to a string beginning with '-', always! */ struct options_table_s *find_option ( char *option ) { struct options_table_s *ptbl; ptbl = options; while ( ptbl->id ) { /* Is it a long option? */ if ( * ( option + 1 ) == '-' ) { /* Find 'long option' */ if ( ( ptbl->long_opt != NULL ) && * ( option + 2 ) != '\0' ) if ( !strcmp ( option + 2, ptbl->long_opt ) ) return ptbl; } else /* ... or, is it a short option? */ if ( * ( option + 1 ) == ptbl->short_opt ) return ptbl; ptbl++; } /* Option not found. */ return NULL; } /* Check rules for options, after we get them all. */ void check_options_rules ( const config_options_T *co ) { struct options_table_s *ptbl; /* Address field is mandatory! */ if ( !co->ip.daddr ) fatal_error ( "Target address needed." ); #ifdef __HAVE_TURBO__ if ( co->turbo && !co->flood ) fatal_error ( "Turbo mode only available when flooding." ); #endif ptbl = find_option ( "--threshold" ); /* --flood and --threshold are mutually exclusive! */ if ( co->flood && ( ptbl && ptbl->in_use_ ) ) fatal_error ( "--flood and --threshold cannot be used at the same time.\n" ); /* Sanitizing the TCP Options SACK_Permitted and SACK Edges. */ if ( TEST_BITS ( co->tcp.options, TCP_OPTION_SACK_OK ) && TEST_BITS ( co->tcp.options, TCP_OPTION_SACK_EDGE ) ) fatal_error ( "TCP options SACK-Permitted and SACK Edges are not allowed." ); /* Sanitizing the TCP Options T/TCP CC and T/TCP CC.ECHO. */ if ( TEST_BITS ( co->tcp.options, TCP_OPTION_CC ) && ( co->tcp.cc_echo ) ) fatal_error ( "TCP options T/TCP CC and T/TCP CC.ECHO are not allowed." ); /* FIX: Checks only if flooding isn't used! */ if ( !co->flood ) if ( check_threshold ( co ) ) exit ( EXIT_FAILURE ); /* ***** NOTE: Insert other rules here! ***** */ // Checks here if protocol isn't IPPROTO_T50 and if the set of options // is applyable to the choosen protocol. if ( co->ip.protocol != IPPROTO_T50 ) { /* Need to scan only the begining with --encapsulated option. Notice that options are sequentially organized. */ struct options_table_s *popt_tbl; int *valid_list; if ( ( popt_tbl = find_option ( "--encapsulated" ) ) != NULL ) { valid_list = get_module_valid_options_list ( co->ip.protocol ); /* popt_tbl->id is an option id on options table entry. */ while ( popt_tbl->id ) { if ( popt_tbl->in_use_ && !check_for_valid_option ( popt_tbl->id, valid_list ) ) fatal_error ( "One or more options are not available to chosen protocol." ); popt_tbl++; } } } } /* Get the IP PROTOCOL. */ void get_ip_protocol ( config_options_T * restrict co, char * restrict arg ) { /* T50 protocol is a special case! It isn't in modules table! */ if ( !strcasecmp ( arg, "T50" ) ) { co->ip.protocol = IPPROTO_T50; co->ip.protoname = number_of_modules; /* Is this correct? */ } else { /* Scan the modules table trying to get the desired protocol. */ int i; modules_table_T *ptbl; i = 0; ptbl = mod_table; while ( ptbl->name ) { if ( !strcasecmp ( ptbl->name, arg ) ) { co->ip.protoname = i; co->ip.protocol = ptbl->protocol_id; return; } i++; ptbl++; } fatal_error ( "Unknown protocol %s.", arg ); } } void set_destination_addresses ( char * restrict arg, config_options_T * restrict co ) { char *p; addr_T addr; if ( get_ip_and_cidr_from_string ( arg, &addr ) ) { co->bits = addr.cidr; co->ip.daddr = htonl ( addr.addr ); } else { /* If get_ip_and_cidr_from_string() fails, it probably means that we have a name, instead of an IP. */ /* Tries to resolve the name. */ p = strtok ( arg, "/" ); co->ip.daddr = resolv ( p ); /* Get cidr if any. */ p = strtok( NULL, "/" ); if ( p ) co->bits = atoi ( p ); /* NOTE: Range will be checked later. */ else co->bits = CIDR_MAXIMUM; } } /* Setup an option. */ void set_config_option ( config_options_T * restrict co, char * restrict optname, int optid, char * restrict arg ) { uint32_t counter; char *tmp_ptr; unsigned long a, b; /* Temporaries. */ switch ( optid ) { // --- GLOBAL options #ifdef __HAVE_TURBO__ case OPTION_TURBO: co->turbo = 1; break; #endif case OPTION_THRESHOLD: co->threshold = toULong ( optname, arg ); break; case OPTION_FLOOD: co->flood = 1; break; case OPTION_ENCAPSULATED: co->encapsulated = 1; break; case OPTION_BOGUSCSUM: co->bogus_csum = 1; break; case OPTION_SHUFFLE: co->shuffle = 1; break; // --- GRE options // FIXME: gre.flags, gre.recur, optional gre.offset, not set here! case OPTION_GRE_SEQUENCE_PRESENT: co->gre.S = 1; break; case OPTION_GRE_KEY_PRESENT: co->gre.K = 1; break; case OPTION_GRE_CHECKSUM_PRESENT: co->gre.C = 1; break; case OPTION_GRE_KEY: co->gre.key = htonl ( toULong ( optname, arg ) ); break; case OPTION_GRE_SEQUENCE: co->gre.sequence = htonl ( toULong ( optname, arg ) ); break; case OPTION_GRE_SADDR: check_list_separators ( optname, arg ); co->gre.saddr = resolv ( arg ); break; case OPTION_GRE_DADDR: check_list_separators ( optname, arg ); co->gre.daddr = resolv ( arg ); break; //--- IP options case OPTION_IP_TOS: co->ip.tos = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_IP_ID: co->ip.id = htons ( toULongCheckRange ( optname, arg, 0, 65535 ) ); break; case OPTION_IP_OFFSET: // NOTE: byte swap made in ip.c co->ip.frag_off = toULongCheckRange ( optname, arg, 0, 0x1fff ); break; case OPTION_IP_TTL: co->ip.ttl = toULongCheckRange ( optname, arg, 0, 255 ); break; // --- ICMP options case OPTION_ICMP_TYPE: co->icmp.type = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_ICMP_CODE: co->icmp.code = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_ICMP_ID: co->icmp.id = htons ( toULongCheckRange ( optname, arg, 0, 65535 ) ); break; case OPTION_ICMP_SEQUENCE: co->icmp.sequence = htons ( toULongCheckRange ( optname, arg, 0, 65535 ) ); break; case OPTION_ICMP_GATEWAY: check_list_separators ( optname, arg ); co->icmp.gateway = resolv ( arg ); break; // --- IGMP options case OPTION_IGMP_TYPE: co->igmp.type = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_IGMP_CODE: co->igmp.code = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_IGMP_QRV: co->igmp.qrv = toULongCheckRange ( optname, arg, 0, 7 ); // only 3 bits. break; case OPTION_IGMP_SUPPRESS: co->igmp.suppress = 1; break; case OPTION_IGMP_QQIC: co->igmp.qqic = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_IGMP_GREC_TYPE: co->igmp.grec_type = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_IGMP_SOURCES: co->igmp.sources = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_IGMP_ADDRESS: /* FIXME: Need to check if an item is valid! */ /* More than 255 items will be ignored! */ counter = 0; tmp_ptr = strtok( arg, "," ); while ( tmp_ptr && ( counter < ( sizeof ( co->igmp.address ) / sizeof ( in_addr_t ) ) ) ) { co->igmp.address[counter++] = resolv( tmp_ptr ); tmp_ptr = strtok( NULL, "," ); } co->igmp.sources = counter; break; case OPTION_IGMP_GROUP: check_list_separators ( optname, arg ); co->igmp.group = resolv ( arg ); break; case OPTION_IGMP_GREC_MULTICAST: check_list_separators ( optname, arg ); co->igmp.grec_mca = resolv ( arg ); break; // --- TCP options case OPTION_TCP_SEQUENCE: co->tcp.sequence = htonl ( toULong ( optname, arg ) ); break; case OPTION_TCP_ACK_SEQ: co->tcp.acknowledge = htonl ( toULong ( optname, arg ) ); break; case OPTION_TCP_OFFSET: co->tcp.doff = toULongCheckRange ( optname, arg, 0, 15 ); // only 4 bits. break; case OPTION_TCP_FIN: co->tcp.fin = 1; break; case OPTION_TCP_SYN: co->tcp.syn = 1; break; case OPTION_TCP_RST: co->tcp.rst = 1; break; case OPTION_TCP_PSH: co->tcp.psh = 1; break; case OPTION_TCP_ACK: co->tcp.ack = 1; break; case OPTION_TCP_URG: co->tcp.urg = 1; break; case OPTION_TCP_ECE: co->tcp.ece = 1; break; case OPTION_TCP_CWR: co->tcp.cwr = 1; break; case OPTION_TCP_WINDOW: co->tcp.window = htons ( toULongCheckRange ( optname, arg, 0, 65535 ) ); break; case OPTION_TCP_URGENT_POINTER: co->tcp.urg_ptr = htons ( toULongCheckRange ( optname, arg, 0, 65535 ) ); break; case OPTION_TCP_MSS: co->tcp.options |= TCP_OPTION_MSS; co->tcp.mss = htons ( toULongCheckRange ( optname, arg, 0, 65535 ) ); break; case OPTION_TCP_WSOPT: co->tcp.options |= TCP_OPTION_WSOPT; co->tcp.wsopt = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_TCP_TSOPT: /* This option can contain 2 values separated by ':' (second is optional). */ /* FIXME: Shouldn't this be separated by ':', instead of '.' ? */ co->tcp.options |= TCP_OPTION_TSOPT; if ( get_dual_values ( arg, &a, &b, UINT_MAX, 1, '.', optname ) ) exit ( EXIT_FAILURE ); co->tcp.tsval = htonl ( a ); co->tcp.tsecr = htonl ( b ); break; case OPTION_TCP_SACK_OK: co->tcp.options |= TCP_OPTION_SACK_OK; break; case OPTION_TCP_CC: co->tcp.options |= TCP_OPTION_CC; co->tcp.cc = htonl ( toULong ( optname, arg ) ); break; case OPTION_TCP_CC_NEW: co->tcp.options |= TCP_OPTION_CC_NEXT; co->tcp.cc_new = htonl ( toULong ( optname, arg ) ); break; case OPTION_TCP_CC_ECHO: co->tcp.options |= TCP_OPTION_CC_NEXT; co->tcp.cc_echo = htonl ( toULong ( optname, arg ) ); break; case OPTION_TCP_SACK_EDGE: /* NOTE: This option expects 2 values, separated by ':'. */ co->tcp.options |= TCP_OPTION_SACK_EDGE; if ( get_dual_values ( arg, &a, &b, UINT_MAX, 0, ':', optname ) ) exit ( EXIT_FAILURE ); co->tcp.sack_left = htonl ( a ); co->tcp.sack_right = htonl ( b ); break; case OPTION_TCP_MD5_SIGNATURE: co->tcp.md5 = ! ( co->tcp.auth = 0 ); break; case OPTION_TCP_AUTHENTICATION: co->tcp.auth = ! ( co->tcp.md5 = 0 ); break; case OPTION_TCP_AUTH_KEY_ID: co->tcp.key_id = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_TCP_AUTH_NEXT_KEY: co->tcp.next_key = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_TCP_NOP: co->tcp.nop = TCPOPT_NOP; break; // --- EGP options case OPTION_EGP_TYPE: co->egp.type = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_EGP_CODE: co->egp.code = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_EGP_STATUS: co->egp.status = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_EGP_AS: co->egp.as = htons ( toULongCheckRange ( optname, arg, 0, 65535 ) ); break; case OPTION_EGP_SEQUENCE: co->egp.sequence = htons ( toULongCheckRange ( optname, arg, 0, 65535 ) ); break; case OPTION_EGP_HELLO: co->egp.hello = htons ( toULongCheckRange ( optname, arg, 0, 65535 ) ); break; case OPTION_EGP_POLL: co->egp.poll = htons ( toULongCheckRange ( optname, arg, 0, 65535 ) ); break; // --- RIP options case OPTION_RIP_COMMAND: co->rip.command = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_RIP_ADDRESS: check_list_separators ( optname, arg ); co->rip.address = resolv ( arg ); break; case OPTION_RIP_FAMILY: co->rip.family = htons ( toULongCheckRange ( optname, arg, 0, 65535 ) ); break; case OPTION_RIP_METRIC: co->rip.metric = htonl ( toULong ( optname, arg ) ); break; case OPTION_RIP_DOMAIN: co->rip.domain = htons ( toULongCheckRange ( optname, arg, 0, 65535 ) ); break; case OPTION_RIP_TAG: co->rip.tag = htons ( toULongCheckRange ( optname, arg, 0, 65535 ) ); break; case OPTION_RIP_NETMASK: /* FIXME: Is this correct? To resolve a 'netmask'? */ co->rip.netmask = resolv ( arg ); break; case OPTION_RIP_NEXTHOP: check_list_separators ( optname, arg ); co->rip.next_hop = resolv ( arg ); break; case OPTION_RIP_AUTHENTICATION: co->rip.auth = 1; break; case OPTION_RIP_AUTH_KEY_ID: co->rip.key_id = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_RIP_AUTH_SEQUENCE: co->rip.sequence = htonl ( toULong ( optname, arg ) ); break; // --- DCCP options case OPTION_DCCP_OFFSET: /* NOTE: byte swapped on tcp.c */ co->dccp.doff = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_DCCP_CSCOV: co->dccp.cscov = toULongCheckRange ( optname, arg, 0, 15 ); break; case OPTION_DCCP_CCVAL: co->dccp.ccval = toULongCheckRange ( optname, arg, 0, 15 ); break; case OPTION_DCCP_TYPE: co->dccp.type = toULongCheckRange ( optname, arg, 0, 15 ); break; case OPTION_DCCP_EXTEND: co->dccp.ext = 1; break; case OPTION_DCCP_SEQUENCE_01: co->dccp.sequence_01 = htons ( toULongCheckRange ( optname, arg, 0, 65535 ) ); break; case OPTION_DCCP_SEQUENCE_02: co->dccp.sequence_02 = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_DCCP_SEQUENCE_03: co->dccp.sequence_03 = htonl ( toULong ( optname, arg ) ); break; case OPTION_DCCP_SERVICE: co->dccp.service = htonl ( toULong ( optname, arg ) ); break; case OPTION_DCCP_ACKNOWLEDGE_01: co->dccp.acknowledge_01 = htons ( toULongCheckRange ( optname, arg, 0, 65535 ) ); break; case OPTION_DCCP_ACKNOWLEDGE_02: co->dccp.acknowledge_02 = htonl ( toULong ( optname, arg ) ); break; case OPTION_DCCP_RESET_CODE: co->dccp.rst_code = toULongCheckRange ( optname, arg, 0, 255 ); break; // --- RSVP options case OPTION_RSVP_FLAGS: co->rsvp.flags = toULongCheckRange ( optname, arg, 0, 15 ); break; case OPTION_RSVP_TYPE: co->rsvp.type = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_RSVP_TTL: co->rsvp.ttl = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_RSVP_SESSION_ADDRESS: check_list_separators ( optname, arg ); co->rsvp.session_addr = resolv ( arg ); break; case OPTION_RSVP_SESSION_PROTOCOL: check_list_separators ( optname, arg ); co->rsvp.session_proto = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_RSVP_SESSION_FLAGS: co->rsvp.session_flags = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_RSVP_SESSION_PORT: check_list_separators ( optname, arg ); co->rsvp.session_port = htons ( toULongCheckRange ( optname, arg, 0, 65535 ) ); break; case OPTION_RSVP_HOP_ADDRESS: check_list_separators ( optname, arg ); co->rsvp.hop_addr = resolv ( arg ); break; case OPTION_RSVP_HOP_IFACE: co->rsvp.hop_iface = htonl ( toULong ( optname, arg ) ); break; case OPTION_RSVP_TIME_REFRESH: co->rsvp.time_refresh = htonl ( toULong ( optname, arg ) ); break; case OPTION_RSVP_ERROR_ADDRESS: check_list_separators ( optname, arg ); co->rsvp.error_addr = resolv ( arg ); break; case OPTION_RSVP_ERROR_FLAGS: co->rsvp.error_flags = toULongCheckRange ( optname, arg, 0, 7 ); // 3 bits. break; case OPTION_RSVP_ERROR_CODE: co->rsvp.error_code = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_RSVP_ERROR_VALUE: co->rsvp.error_value = htons ( toULongCheckRange ( optname, arg, 0, 65535 ) ); break; case OPTION_RSVP_SCOPE: co->rsvp.scope = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_RSVP_SCOPE_ADDRESS: // FIXME: Must validate every item! counter = 0; tmp_ptr = strtok( arg, "," ); while ( tmp_ptr && ( counter < ( sizeof ( co->rsvp.address ) / sizeof ( in_addr_t ) ) ) ) { co->rsvp.address[counter++] = resolv( tmp_ptr ); tmp_ptr = strtok( NULL, "," ); } co->rsvp.scope = counter; break; case OPTION_RSVP_STYLE_OPTION: co->rsvp.style_opt = htonl ( toULongCheckRange ( optname, arg, 0, ( 1U << 24 ) - 1 ) ); // 24 bits! break; case OPTION_RSVP_SENDER_ADDRESS: check_list_separators ( optname, arg ); co->rsvp.sender_addr = resolv ( arg ); break; case OPTION_RSVP_SENDER_PORT: check_list_separators ( optname, arg ); co->rsvp.sender_port = htons ( toULongCheckRange ( optname, arg, 0, 65535 ) ); break; case OPTION_RSVP_CONFIRM_ADDR: check_list_separators ( optname, arg ); co->rsvp.confirm_addr = resolv ( arg ); break; case OPTION_RSVP_TSPEC_TRAFFIC: co->rsvp.tspec = TSPEC_TRAFFIC_SERVICE; break; case OPTION_RSVP_TSPEC_GUARANTEED: co->rsvp.tspec = TSPEC_GUARANTEED_SERVICE; break; case OPTION_RSVP_TSPEC_TOKEN_R: co->rsvp.tspec = TSPEC_TRAFFIC_SERVICE; co->rsvp.tspec_r = htonl ( toULong ( optname, arg ) ); break; case OPTION_RSVP_TSPEC_TOKEN_B: co->rsvp.tspec = TSPEC_TRAFFIC_SERVICE; co->rsvp.tspec_b = htonl ( toULong ( optname, arg ) ); break; case OPTION_RSVP_TSPEC_DATA_P: co->rsvp.tspec = TSPEC_TRAFFIC_SERVICE; co->rsvp.tspec_p = htonl ( toULong ( optname, arg ) ); break; case OPTION_RSVP_TSPEC_MINIMUM: co->rsvp.tspec = TSPEC_TRAFFIC_SERVICE; co->rsvp.tspec_m = htonl ( toULong ( optname, arg ) ); break; case OPTION_RSVP_TSPEC_MAXIMUM: co->rsvp.tspec = TSPEC_TRAFFIC_SERVICE; co->rsvp.tspec_M = htonl ( toULong ( optname, arg ) ); break; case OPTION_RSVP_ADSPEC_ISHOP: co->rsvp.adspec_hop = htonl ( toULong ( optname, arg ) ); break; case OPTION_RSVP_ADSPEC_PATH: co->rsvp.adspec_path = htonl ( toULong ( optname, arg ) ); break; case OPTION_RSVP_ADSPEC_MINIMUM: co->rsvp.adspec_minimum = htonl ( toULong ( optname, arg ) ); break; case OPTION_RSVP_ADSPEC_MTU: co->rsvp.adspec_mtu = htonl ( toULong ( optname, arg ) ); break; case OPTION_RSVP_ADSPEC_GUARANTEED: co->rsvp.adspec = ADSPEC_GUARANTEED_SERVICE; break; case OPTION_RSVP_ADSPEC_CTOT: co->rsvp.adspec = ADSPEC_GUARANTEED_SERVICE; co->rsvp.adspec_Ctot = htonl ( toULong ( optname, arg ) ); break; case OPTION_RSVP_ADSPEC_DTOT: co->rsvp.adspec = ADSPEC_GUARANTEED_SERVICE; co->rsvp.adspec_Dtot = htonl ( toULong ( optname, arg ) ); break; case OPTION_RSVP_ADSPEC_CSUM: co->rsvp.adspec = ADSPEC_GUARANTEED_SERVICE; co->rsvp.adspec_Csum = htonl ( toULong ( optname, arg ) ); break; case OPTION_RSVP_ADSPEC_DSUM: co->rsvp.adspec = ADSPEC_GUARANTEED_SERVICE; co->rsvp.adspec_Dsum = htonl ( toULong ( optname, arg ) ); break; case OPTION_RSVP_ADSPEC_CONTROLLED: co->rsvp.adspec = ADSPEC_CONTROLLED_SERVICE; break; // --- IPSEC options case OPTION_IPSEC_AH_LENGTH: co->ipsec.ah_length = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_IPSEC_AH_SPI: co->ipsec.ah_spi = htonl ( toULong ( optname, arg ) ); break; case OPTION_IPSEC_AH_SEQUENCE: co->ipsec.ah_sequence = htonl ( toULong ( optname, arg ) ); break; case OPTION_IPSEC_ESP_SPI: co->ipsec.esp_spi = htonl ( toULong ( optname, arg ) ); break; case OPTION_IPSEC_ESP_SEQUENCE: co->ipsec.esp_sequence = htonl ( toULong ( optname, arg ) ); break; // --- EIGRP options case OPTION_EIGRP_OPCODE: co->eigrp.opcode = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_EIGRP_FLAGS: co->eigrp.flags = htonl ( toULong ( optname, arg ) ); break; case OPTION_EIGRP_SEQUENCE: co->eigrp.sequence = htonl ( toULong ( optname, arg ) ); break; case OPTION_EIGRP_ACKNOWLEDGE: co->eigrp.acknowledge = htonl ( toULong ( optname, arg ) ); break; case OPTION_EIGRP_AS: co->eigrp.as = htonl ( toULong ( optname, arg ) ); break; case OPTION_EIGRP_TYPE: co->eigrp.type = htons ( toULongCheckRange ( optname, arg, 0, 65535 ) ); break; case OPTION_EIGRP_LENGTH: co->eigrp.length = htons ( toULongCheckRange ( optname, arg, 0, 65535 ) ); break; case OPTION_EIGRP_K1: co->eigrp.values |= EIGRP_KVALUE_K1; co->eigrp.k1 = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_EIGRP_K2: co->eigrp.values |= EIGRP_KVALUE_K2; co->eigrp.k2 = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_EIGRP_K3: co->eigrp.values |= EIGRP_KVALUE_K3; co->eigrp.k3 = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_EIGRP_K4: co->eigrp.values |= EIGRP_KVALUE_K4; co->eigrp.k4 = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_EIGRP_K5: co->eigrp.values |= EIGRP_KVALUE_K5; co->eigrp.k5 = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_EIGRP_HOLD: co->eigrp.hold = htons ( toULongCheckRange ( optname, arg, 0, 65535 ) ); break; case OPTION_EIGRP_IOS_VERSION: if ( get_dual_values ( arg, &a, &b, UCHAR_MAX, 0, '.', optname ) ) exit ( EXIT_FAILURE ); co->eigrp.ios_major = a; co->eigrp.ios_minor = b; break; case OPTION_EIGRP_PROTO_VERSION: if ( get_dual_values ( arg, &a, &b, UCHAR_MAX, 0, '.', optname ) ) exit ( EXIT_FAILURE ); co->eigrp.ver_major = a; co->eigrp.ver_minor = b; break; case OPTION_EIGRP_NEXTHOP: check_list_separators ( optname, arg ); co->eigrp.next_hop = resolv ( arg ); break; case OPTION_EIGRP_DELAY: co->eigrp.delay = htonl ( toULong ( optname, arg ) ); break; case OPTION_EIGRP_BANDWIDTH: co->eigrp.bandwidth = htonl ( toULong ( optname, arg ) ); break; case OPTION_EIGRP_MTU: co->eigrp.mtu = htonl ( toULongCheckRange ( optname, arg, 0, ( 1U << 24 ) - 1 ) ); // 24 bits break; case OPTION_EIGRP_HOP_COUNT: co->eigrp.hop_count = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_EIGRP_LOAD: co->eigrp.load = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_EIGRP_RELIABILITY: co->eigrp.reliability = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_EIGRP_DESINATION: tmp_ptr = strchr( arg, '/' ); if ( tmp_ptr ) { *tmp_ptr++ = '\0'; co->eigrp.prefix = htonl ( toULong ( optname, tmp_ptr ) ); } else co->eigrp.prefix = ( 1U << 5 ) - 1; co->eigrp.dest = resolv ( arg ); break; case OPTION_EIGRP_SOURCE_ROUTER: co->eigrp.src_router = resolv ( arg ); break; case OPTION_EIGRP_SOURCE_AS: co->eigrp.src_as = htonl ( toULong ( optname, arg ) ); break; case OPTION_EIGRP_TAG: co->eigrp.tag = htonl ( toULong ( optname, arg ) ); break; case OPTION_EIGRP_METRIC: co->eigrp.proto_metric = htonl ( toULong ( optname, arg ) ); break; case OPTION_EIGRP_ID: co->eigrp.proto_id = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_EIGRP_EXTERNAL_FLAGS: co->eigrp.ext_flags = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_EIGRP_ADDRESS: check_list_separators ( optname, arg ); co->eigrp.address = resolv ( arg ); break; case OPTION_EIGRP_MULTICAST: co->eigrp.multicast = htonl ( toULong ( optname, arg ) ); break; case OPTION_EIGRP_AUTHENTICATION: co->eigrp.auth = 1; break; case OPTION_EIGRP_AUTH_KEY_ID: co->eigrp.key_id = htonl ( toULong ( optname, arg ) ); break; // --- OSPF options case OPTION_OSPF_TYPE: co->ospf.type = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_OSPF_LENGTH: co->ospf.length = htons ( toULongCheckRange ( optname, arg, 0, 65535 ) ); break; case OPTION_OSPF_ROUTER_ID: co->ospf.rid = resolv ( arg ); break; case OPTION_OSPF_AREA_ID: co->ospf.AID = 1; co->ospf.aid = resolv ( arg ); break; case OPTION_OSPF_MT: co->ospf.options |= OSPF_OPTION_TOS; break; case OPTION_OSPF_E: co->ospf.options |= OSPF_OPTION_EXTERNAL; break; case OPTION_OSPF_MC: co->ospf.options |= OSPF_OPTION_MULTICAST; break; case OPTION_OSPF_NP: co->ospf.options |= OSPF_OPTION_NSSA; break; case OPTION_OSPF_L: co->ospf.options |= OSPF_OPTION_LLS; break; case OPTION_OSPF_DC: co->ospf.options |= OSPF_OPTION_DEMAND; break; case OPTION_OSPF_O: co->ospf.options |= OSPF_OPTION_OPAQUE; break; case OPTION_OSPF_DN: co->ospf.options |= OSPF_OPTION_DOWN; break; case OPTION_OSPF_NETMASK: co->ospf.netmask = resolv ( arg ); break; case OPTION_OSPF_HELLO_INTERVAL: co->ospf.hello_interval = htons ( toULongCheckRange ( optname, arg, 0, 65535 ) ); break; case OPTION_OSPF_HELLO_PRIORITY: co->ospf.hello_priority = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_OSPF_HELLO_DEAD: co->ospf.hello_dead = htonl ( toULong ( optname, arg ) ); break; case OPTION_OSPF_HELLO_DESIGN: co->ospf.hello_design = resolv ( arg ); break; case OPTION_OSPF_HELLO_BACKUP: co->ospf.hello_backup = resolv ( arg ); break; case OPTION_OSPF_HELLO_NEIGHBOR: co->ospf.neighbor = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_OSPF_HELLO_ADDRESS: counter = 0; tmp_ptr = strtok( arg, "," ); while ( tmp_ptr && ( counter < ( sizeof ( co->ospf.address ) / sizeof ( in_addr_t ) ) ) ) { co->ospf.address[counter++] = resolv( tmp_ptr ); tmp_ptr = strtok( NULL, "," ); } co->ospf.neighbor = counter; break; case OPTION_OSPF_DD_MTU: co->ospf.dd_mtu = htons ( toULongCheckRange ( optname, arg, 0, 65535 ) ); break; case OPTION_OSPF_DD_MASTER_SLAVE: co->ospf.dd_dbdesc |= DD_DBDESC_MSLAVE; break; case OPTION_OSPF_DD_MORE: co->ospf.dd_dbdesc |= DD_DBDESC_MORE; break; case OPTION_OSPF_DD_INIT: co->ospf.dd_dbdesc |= DD_DBDESC_INIT; break; case OPTION_OSPF_DD_OOBRESYNC: co->ospf.dd_dbdesc |= DD_DBDESC_OOBRESYNC; break; case OPTION_OSPF_DD_SEQUENCE: co->ospf.dd_sequence = htonl ( toULong ( optname, arg ) ); break; case OPTION_OSPF_DD_INCLUDE_LSA: co->ospf.dd_include_lsa = 1; break; case OPTION_OSPF_LSA_AGE: co->ospf.lsa_age = htons ( toULongCheckRange ( optname, arg, 0, 65535 ) ); break; case OPTION_OSPF_LSA_DO_NOT_AGE: co->ospf.lsa_dage = 1; break; case OPTION_OSPF_LSA_TYPE: co->ospf.lsa_type = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_OSPF_LSA_LSID: co->ospf.lsa_lsid = resolv ( arg ); break; case OPTION_OSPF_LSA_ROUTER: co->ospf.lsa_router = resolv ( arg ); break; case OPTION_OSPF_LSA_SEQUENCE: co->ospf.lsa_sequence = htonl ( toULong ( optname, arg ) ); break; case OPTION_OSPF_LSA_METRIC: co->ospf.lsa_metric = htonl ( toULong ( optname, arg ) ); break; case OPTION_OSPF_LSA_FLAG_BORDER: co->ospf.lsa_flags |= ROUTER_FLAG_BORDER; break; case OPTION_OSPF_LSA_FLAG_EXTERNAL: co->ospf.lsa_flags |= ROUTER_FLAG_EXTERNAL; break; case OPTION_OSPF_LSA_FLAG_VIRTUAL: co->ospf.lsa_flags |= ROUTER_FLAG_VIRTUAL; break; case OPTION_OSPF_LSA_FLAG_WILD: co->ospf.lsa_flags |= ROUTER_FLAG_WILD; break; case OPTION_OSPF_LSA_FLAG_NSSA_TR: co->ospf.lsa_flags |= ROUTER_FLAG_NSSA_TR; break; case OPTION_OSPF_LSA_LINK_ID: co->ospf.lsa_link_id = resolv ( arg ); break; case OPTION_OSPF_LSA_LINK_DATA: co->ospf.lsa_link_data = resolv ( arg ); break; case OPTION_OSPF_LSA_LINK_TYPE: co->ospf.lsa_link_type = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_OSPF_LSA_ATTACHED: co->ospf.lsa_attached = resolv ( arg ); break; case OPTION_OSPF_LSA_LARGER: co->ospf.lsa_larger = 1; break; case OPTION_OSPF_LSA_FORWARD: co->ospf.lsa_forward = resolv ( arg ); break; case OPTION_OSPF_LSA_EXTERNAL: co->ospf.lsa_external = resolv ( arg ); break; case OPTION_OSPF_VERTEX_ROUTER: co->ospf.vertex_type = VERTEX_TYPE_ROUTER; break; case OPTION_OSPF_VERTEX_NETWORK: co->ospf.vertex_type = VERTEX_TYPE_NETWORK; break; case OPTION_OSPF_VERTEX_ID: co->ospf.vertex_id = resolv ( arg ); break; case OPTION_OSPF_LLS_OPTION_LR: co->ospf.lls_options = EXTENDED_OPTIONS_LR; break; case OPTION_OSPF_LLS_OPTION_RS: co->ospf.lls_options = EXTENDED_OPTIONS_RS; break; case OPTION_OSPF_AUTHENTICATION: co->ospf.auth = 1; break; case OPTION_OSPF_AUTH_KEY_ID: co->ospf.key_id = toULongCheckRange ( optname, arg, 0, 255 ); break; case OPTION_OSPF_AUTH_SEQUENCE: co->ospf.sequence = htonl ( toULong ( optname, arg ) ); break; /* * FIXME: These options should deal with lists, but only the first item * is used... */ // Source port. case OPTION_SOURCE: check_list_separators ( optname, arg ); co->source = htons ( toULongCheckRange ( optname, arg, 0, 65535 ) ); break; // Destination port case OPTION_DESTINATION: check_list_separators ( optname, arg ); co->dest = htons ( toULongCheckRange ( optname, arg, 0, 65535 ) ); break; case OPTION_IP_SOURCE: check_list_separators ( optname, arg ); co->ip.saddr = resolv ( arg ); break; case OPTION_IP_PROTOCOL: check_list_separators ( optname, arg ); get_ip_protocol ( co, arg ); break; } } /* Tries to convert string to an unsigned value. NOTE: Marked as "noinline" because it's big enough! */ uint32_t toULong ( char * restrict optname, char * restrict value ) { unsigned long n; if ( !value || !*value ) return 0; // strtoul() accepts negative values, we don't! if ( strchr ( value, '-' ) ) goto error_exit; /* strtoul deals ok with hexadecimal, octal and decimal values. */ errno = 0; // errno is set only on error, so we have to reset it here. n = strtoul ( value, NULL, 0 ); // FIX: Check for greater values then 2³²-1 too. if ( errno || ( n & ( ( uint64_t ) __UINT32_MAX__ << 32 ) ) ) { error_exit: fatal_error ( "Invalid numeric value for option '%s'.", optname ); // we'll never get here, return 0 just in case! return 0; } return ( uint32_t ) n; } /* Tries to convert string to uint32_t, checking range. NOTE: 'min' MUST BE smaller than 'max'. NOTE: Marked as "noinline" because it's big enough. */ uint32_t toULongCheckRange ( char * restrict optname, char * restrict value, uint32_t min, uint32_t max ) { uint32_t n; if ( value && *value ) { if ( min > max ) fatal_error ( "Min & Max values when calling toULongCheckRange(\"%s\", \"%s\", %" PRIu32 ", %" PRIu32 ").", optname, value, min, max ); n = toULong ( optname, value ); if ( n < min || n > max ) fatal_error ( "Value out of range for option '%s'. Range must be between %u and %u.", optname, min, max ); } return n; } /* Check if there are any separators on string. */ void check_list_separators ( char * restrict optname, char * restrict arg ) { assert ( arg != NULL ); if ( strpbrk ( arg, ",;:" ) ) fatal_error ( "Option '%s' does not accept a list.\n", optname ); } /* List procotolos on modules table */ void list_protocols ( void ) { modules_table_T *ptbl; int i; puts ( INFO " List of supported protocols (--protocol):" ); i = 1; ptbl = mod_table; while ( ptbl->func ) { printf ( "\t% 2d - %s\t(%s)\n", i++, ptbl->name, ptbl->description ); ptbl++; } } /* TODO: Replace this regex routine with a screte function. */ /*--- Ok, this piece of code was, initially, an experiment. I have to review this code and get rip of this regex. --- */ /* POSIX Extended Regular Expression used to match IP addresses with optional CIDR. */ #define IP_REGEX "^([1-2]*[0-9]{1,2})" \ "(\\.[1-2]*[0-9]{1,2}){0,1}" \ "(\\.[1-2]*[0-9]{1,2}){0,1}" \ "(\\.[1-2]*[0-9]{1,2}){0,1}" \ "(/[0-9]{1,2}){0,1}$" /* Auxiliary "match" macros. */ #define MATCH(a) ((a).rm_so >= 0) #define MATCH_LENGTH(a) ((a).rm_eo - (a).rm_so) /* NOTE: There is a bug in strncpy() function. '\0' is not set at the end of substring. */ #define COPY_SUBSTRING(d, s, len) { \ strncpy((d), (s), (len)); \ *((char *)(d) + (len)) = '\0'; \ } /* Ok... this is UGLY. */ int get_ip_and_cidr_from_string ( char const * const addr, addr_T *addr_ptr ) { regex_t re; regmatch_t rm[6]; unsigned matches[5]; uint32_t i, len; char *t; int bits; addr_ptr->addr = addr_ptr->cidr = 0; /* Try to compile the regular expression. */ if ( regcomp ( &re, IP_REGEX, REG_EXTENDED ) ) return 0; /* Try to execute regex against the addr string. */ if ( regexec ( &re, addr, 6, rm, 0 ) ) { regfree ( &re ); return 0; } /* Allocate enough space for temporary string. */ if ( ( t = strdup ( addr ) ) == NULL ) error ( "Cannot allocate temporary string: " __FILE__ ":%d", __LINE__ ); /* Convert IP octects matches. */ len = MATCH_LENGTH ( rm[1] ); COPY_SUBSTRING ( t, addr + rm[1].rm_so, len ); matches[0] = atoi ( t ); bits = CIDR_MAXIMUM; /* default is 32 bits netmask. */ i = 2; while ( i <= 4 ) { if ( MATCH ( rm[i] ) ) { len = MATCH_LENGTH ( rm[i] ) - 1; COPY_SUBSTRING ( t, addr + rm[i].rm_so + 1, len ); matches[i - 1] = atoi ( t ); } else { /* if octect is missing, decrease 8 bits from netmask */ bits -= 8; matches[i - 1] = 0; } i++; } /* Convert cidr match. */ if ( MATCH ( rm[5] ) ) { len = MATCH_LENGTH ( rm[5] ) - 1; COPY_SUBSTRING ( t, addr + rm[5].rm_so + 1, len ); if ( ( matches[4] = atoi ( t ) ) == 0 ) { /* if cidr is actually '0', then it is an error! */ free ( t ); regfree ( &re ); return 0; } } else { /* if cidr is not given, use the calculated one. */ matches[4] = bits; } /* We don't need 't' string anymore. */ free ( t ); /* Validate ip octects */ i = 0; while ( i < 4 ) { if ( matches[i] > 255 ) { regfree ( &re ); return 0; } i++; } /* NOTE: Check 'bits' here! */ /* Validate cidr. */ if ( matches[4] < CIDR_MINIMUM || matches[4] > CIDR_MAXIMUM ) { error ( "CIDR must be between %u and %u.\n", CIDR_MINIMUM, CIDR_MAXIMUM ); regfree ( &re ); return 0; } regfree ( &re ); /* Prepare CIDR structure */ addr_ptr->cidr = matches[4]; addr_ptr->addr = ( matches[3] | ( matches[2] << 8 ) | ( matches[1] << 16 ) | ( matches[0] << 24 ) ) & ( ~0U << ( 32 - addr_ptr->cidr ) ); return 1; } /* Convert strings like "10.3" to it's components. check if both values conforms to a maximum (max). check if the second argument is optional. allows the use of 2 separators: '.' or ':'. Also, check for invalid separators: ',', ';'. If '.' is the separator, ':' and vice-versa. NOTE: Since this funcion is defined and used in this module, it's marked with the attribute "noinline". Because it's big! */ int get_dual_values ( char *arg, unsigned long *px, unsigned long *py, unsigned long max, int optional, char separator, char *optname ) { /* 'static' because we don't need to allocate these every time! */ static char nseps[] = " ,;"; static char sep[2] = " "; char *p1, *p2; jmp_buf jb; /* Error handling... safe because we won't use to longjmp outside this function! */ if ( setjmp ( jb ) ) { error ( "'%s' should be formatted as 'n%s'.", optname, optional ? "[.n]" : ".n" ); return !0; } nseps[0] = ( ( sep[0] = separator ) == '.' ) ? ':' : '.'; /* There are any invalid separators? */ if ( strpbrk ( arg, nseps ) ) longjmp ( jb, 1 ); p1 = strtok ( arg, sep ); p2 = strtok ( NULL, sep ); /* If the second parameter is mandatory, then if p2 is NULL we have a problem! */ if ( !optional && !p2 ) longjmp ( jb, 1 ); /* Error handling... */ if ( setjmp ( jb ) ) { error ( "'%s' arguments are out of range or invalid.", optname ); return !0; } /* Try to convert the first value. */ errno = 0; *px = strtoul ( p1, NULL, 10 ); if ( errno ) longjmp ( jb, 1 ); if ( !p2 ) { /* If the second parameter is optional and missing, assume 0, otherwise... error! */ if ( optional ) *py = 0; else longjmp ( jb, 1 ); } else { /* Try to convert the second value. */ errno = 0; *py = strtoul ( p2, NULL, 10 ); if ( errno ) longjmp ( jb, 1 ); } /* Check values ranges. */ if ( *px > max || *py > max ) { error ( "One or both arguments of '%s' option are out of range.", optname ); return 1; } /* Everything ok! */ return 0; } /* Checks if threshold is valid. */ /* NOTE: Moved here 'cause it's used just here. */ int check_threshold ( const config_options_T * const co ) { threshold_T minThreshold; if ( co->ip.protocol == IPPROTO_T50 ) /* When sending multiple packets using T50 "protocol", the threshold must be greater than the number of protocols! */ minThreshold = number_of_modules; else minThreshold = 1; if ( co->threshold < minThreshold ) { error ( "Protool %s cannot have threshold smaller than %d.", mod_table[co->ip.protoname].name, minThreshold ); return 1; } return 0; } // Cheks if an option is on a list of valid options. // The lists of valid options are contained on the modules table! int check_for_valid_option ( int opt, int *list ) { assert ( opt > 0 ); // If the first item is negative, all options are valid! if ( list ) // Scan the valid options list and cheks if 'option' is in it. while ( *list ) { if ( opt == *list ) return 1; list++; } return 0; } src/modules.c0000664000175000017500000003630714107315014014156 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /** @file modules.c */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2019 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include #include #include // --- Valid options tables for specific protocols --- VALID_OPTIONS_TABLE ( tcp, OPTION_ENCAPSULATED, OPTION_BOGUSCSUM, OPTION_SOURCE, OPTION_DESTINATION, \ OPTION_IP_TOS, OPTION_IP_ID, OPTION_IP_OFFSET, OPTION_IP_TTL, OPTION_IP_PROTOCOL, OPTION_IP_SOURCE, \ OPTION_GRE_SEQUENCE_PRESENT, OPTION_GRE_KEY_PRESENT, OPTION_GRE_CHECKSUM_PRESENT, OPTION_GRE_KEY, \ OPTION_GRE_SEQUENCE, OPTION_GRE_SADDR, OPTION_GRE_DADDR, OPTION_TCP_ACK_SEQ, OPTION_TCP_SEQUENCE, \ OPTION_TCP_OFFSET, OPTION_TCP_FIN, OPTION_TCP_SYN, OPTION_TCP_RST, OPTION_TCP_PSH, OPTION_TCP_ACK, \ OPTION_TCP_URG, OPTION_TCP_ECE, OPTION_TCP_CWR, OPTION_TCP_WINDOW, OPTION_TCP_URGENT_POINTER, \ OPTION_TCP_MSS, OPTION_TCP_WSOPT, OPTION_TCP_TSOPT, OPTION_TCP_SACK_OK, OPTION_TCP_CC, OPTION_TCP_CC_NEW, \ OPTION_TCP_CC_ECHO, OPTION_TCP_SACK_EDGE, OPTION_TCP_MD5_SIGNATURE, OPTION_TCP_AUTHENTICATION, OPTION_TCP_AUTH_KEY_ID, \ OPTION_TCP_AUTH_NEXT_KEY, OPTION_TCP_NOP ); VALID_OPTIONS_TABLE ( udp, OPTION_ENCAPSULATED, OPTION_BOGUSCSUM, OPTION_SOURCE, OPTION_DESTINATION, \ OPTION_IP_TOS, OPTION_IP_ID, OPTION_IP_OFFSET, OPTION_IP_TTL, OPTION_IP_PROTOCOL, OPTION_IP_SOURCE, OPTION_GRE_SEQUENCE_PRESENT, \ OPTION_GRE_KEY_PRESENT, OPTION_GRE_CHECKSUM_PRESENT, OPTION_GRE_KEY, OPTION_GRE_SEQUENCE, OPTION_GRE_SADDR, OPTION_GRE_DADDR ); VALID_OPTIONS_TABLE ( icmp, OPTION_ENCAPSULATED, OPTION_BOGUSCSUM, OPTION_SOURCE, OPTION_DESTINATION, OPTION_IP_TOS, \ OPTION_IP_ID, OPTION_IP_OFFSET, OPTION_IP_TTL, OPTION_IP_PROTOCOL, OPTION_IP_SOURCE, OPTION_GRE_SEQUENCE_PRESENT, \ OPTION_GRE_KEY_PRESENT, OPTION_GRE_CHECKSUM_PRESENT, OPTION_GRE_KEY, OPTION_GRE_SEQUENCE, OPTION_GRE_SADDR, OPTION_GRE_DADDR, \ OPTION_ICMP_TYPE, OPTION_ICMP_CODE, OPTION_ICMP_GATEWAY, OPTION_ICMP_ID, OPTION_ICMP_SEQUENCE ); VALID_OPTIONS_TABLE ( igmpv1, OPTION_ENCAPSULATED, OPTION_BOGUSCSUM, OPTION_SOURCE, OPTION_DESTINATION, OPTION_IP_TOS, \ OPTION_IP_ID, OPTION_IP_OFFSET, OPTION_IP_TTL, OPTION_IP_PROTOCOL, OPTION_IP_SOURCE, OPTION_GRE_SEQUENCE_PRESENT, \ OPTION_GRE_KEY_PRESENT, OPTION_GRE_CHECKSUM_PRESENT, OPTION_GRE_KEY, OPTION_GRE_SEQUENCE, OPTION_GRE_SADDR, OPTION_GRE_DADDR, \ OPTION_IGMP_TYPE, OPTION_IGMP_CODE, OPTION_IGMP_GROUP ); VALID_OPTIONS_TABLE ( igmpv3, OPTION_ENCAPSULATED, OPTION_BOGUSCSUM, OPTION_SOURCE, OPTION_DESTINATION, OPTION_IP_TOS, \ OPTION_IP_ID, OPTION_IP_OFFSET, OPTION_IP_TTL, OPTION_IP_PROTOCOL, OPTION_IP_SOURCE, OPTION_GRE_SEQUENCE_PRESENT, \ OPTION_GRE_KEY_PRESENT, OPTION_GRE_CHECKSUM_PRESENT, OPTION_GRE_KEY, OPTION_GRE_SEQUENCE, OPTION_GRE_SADDR, OPTION_GRE_DADDR, \ OPTION_IGMP_TYPE, OPTION_IGMP_CODE, OPTION_IGMP_GROUP, OPTION_IGMP_QRV, OPTION_IGMP_SUPPRESS, OPTION_IGMP_QQIC, \ OPTION_IGMP_GREC_TYPE, OPTION_IGMP_SOURCES, OPTION_IGMP_GREC_MULTICAST, OPTION_IGMP_ADDRESS ); VALID_OPTIONS_TABLE ( egp, OPTION_ENCAPSULATED, OPTION_BOGUSCSUM, OPTION_SOURCE, OPTION_DESTINATION, OPTION_IP_TOS, \ OPTION_IP_ID, OPTION_IP_OFFSET, OPTION_IP_TTL, OPTION_IP_PROTOCOL, OPTION_IP_SOURCE, OPTION_GRE_SEQUENCE_PRESENT, \ OPTION_GRE_KEY_PRESENT, OPTION_GRE_CHECKSUM_PRESENT, OPTION_GRE_KEY, OPTION_GRE_SEQUENCE, OPTION_GRE_SADDR, OPTION_GRE_DADDR, \ OPTION_EGP_TYPE, OPTION_EGP_CODE, OPTION_EGP_STATUS, OPTION_EGP_AS, OPTION_EGP_SEQUENCE, OPTION_EGP_HELLO, OPTION_EGP_POLL ); VALID_OPTIONS_TABLE ( ripv1, OPTION_ENCAPSULATED, OPTION_BOGUSCSUM, OPTION_SOURCE, OPTION_DESTINATION, OPTION_IP_TOS, \ OPTION_IP_ID, OPTION_IP_OFFSET, OPTION_IP_TTL, OPTION_IP_PROTOCOL, OPTION_IP_SOURCE, OPTION_GRE_SEQUENCE_PRESENT, \ OPTION_GRE_KEY_PRESENT, OPTION_GRE_CHECKSUM_PRESENT, OPTION_GRE_KEY, OPTION_GRE_SEQUENCE, OPTION_GRE_SADDR, OPTION_GRE_DADDR, \ OPTION_RIP_COMMAND, OPTION_RIP_FAMILY, OPTION_RIP_ADDRESS, OPTION_RIP_METRIC ); VALID_OPTIONS_TABLE ( ripv2, OPTION_ENCAPSULATED, OPTION_BOGUSCSUM, OPTION_SOURCE, OPTION_DESTINATION, OPTION_IP_TOS, \ OPTION_IP_ID, OPTION_IP_OFFSET, OPTION_IP_TTL, OPTION_IP_PROTOCOL, OPTION_IP_SOURCE, OPTION_GRE_SEQUENCE_PRESENT, \ OPTION_GRE_KEY_PRESENT, OPTION_GRE_CHECKSUM_PRESENT, OPTION_GRE_KEY, OPTION_GRE_SEQUENCE, OPTION_GRE_SADDR, OPTION_GRE_DADDR, \ OPTION_RIP_COMMAND, OPTION_RIP_FAMILY, OPTION_RIP_ADDRESS, OPTION_RIP_METRIC, OPTION_RIP_DOMAIN, OPTION_RIP_TAG, \ OPTION_RIP_NETMASK, OPTION_RIP_NEXTHOP, OPTION_RIP_AUTHENTICATION, OPTION_RIP_AUTH_KEY_ID, OPTION_RIP_AUTH_SEQUENCE ); VALID_OPTIONS_TABLE ( dccp, OPTION_ENCAPSULATED, OPTION_BOGUSCSUM, OPTION_SOURCE, OPTION_DESTINATION, OPTION_IP_TOS, \ OPTION_IP_ID, OPTION_IP_OFFSET, OPTION_IP_TTL, OPTION_IP_PROTOCOL, OPTION_IP_SOURCE, OPTION_GRE_SEQUENCE_PRESENT, \ OPTION_GRE_KEY_PRESENT, OPTION_GRE_CHECKSUM_PRESENT, OPTION_GRE_KEY, OPTION_GRE_SEQUENCE, OPTION_GRE_SADDR, OPTION_GRE_DADDR, \ OPTION_DCCP_OFFSET, OPTION_DCCP_CSCOV, OPTION_DCCP_CCVAL, OPTION_DCCP_TYPE, OPTION_DCCP_EXTEND, OPTION_DCCP_SEQUENCE_01, OPTION_DCCP_SEQUENCE_02, OPTION_DCCP_SEQUENCE_03, OPTION_DCCP_SERVICE, OPTION_DCCP_ACKNOWLEDGE_01, OPTION_DCCP_ACKNOWLEDGE_02, \ OPTION_DCCP_RESET_CODE ); VALID_OPTIONS_TABLE ( rsvp, OPTION_ENCAPSULATED, OPTION_BOGUSCSUM, OPTION_SOURCE, OPTION_DESTINATION, OPTION_IP_TOS, OPTION_IP_ID, \ OPTION_IP_OFFSET, OPTION_IP_TTL, OPTION_IP_PROTOCOL, OPTION_IP_SOURCE, OPTION_GRE_SEQUENCE_PRESENT, OPTION_GRE_KEY_PRESENT, \ OPTION_GRE_CHECKSUM_PRESENT, OPTION_GRE_KEY, OPTION_GRE_SEQUENCE, OPTION_GRE_SADDR, OPTION_GRE_DADDR, OPTION_RSVP_FLAGS, \ OPTION_RSVP_TYPE, OPTION_RSVP_TTL, OPTION_RSVP_SESSION_ADDRESS, OPTION_RSVP_SESSION_PROTOCOL, OPTION_RSVP_SESSION_FLAGS, \ OPTION_RSVP_SESSION_PORT, OPTION_RSVP_HOP_ADDRESS, OPTION_RSVP_HOP_IFACE, OPTION_RSVP_TIME_REFRESH, OPTION_RSVP_ERROR_ADDRESS, \ OPTION_RSVP_ERROR_FLAGS, OPTION_RSVP_ERROR_CODE, OPTION_RSVP_ERROR_VALUE, OPTION_RSVP_SCOPE, OPTION_RSVP_SCOPE_ADDRESS, \ OPTION_RSVP_STYLE_OPTION, OPTION_RSVP_SENDER_ADDRESS, OPTION_RSVP_SENDER_PORT, OPTION_RSVP_TSPEC_TRAFFIC, \ OPTION_RSVP_TSPEC_GUARANTEED, OPTION_RSVP_TSPEC_TOKEN_R, OPTION_RSVP_TSPEC_TOKEN_B, OPTION_RSVP_TSPEC_DATA_P, \ OPTION_RSVP_TSPEC_MINIMUM, OPTION_RSVP_TSPEC_MAXIMUM, OPTION_RSVP_ADSPEC_ISHOP, OPTION_RSVP_ADSPEC_PATH, \ OPTION_RSVP_ADSPEC_MINIMUM, OPTION_RSVP_ADSPEC_MTU, OPTION_RSVP_ADSPEC_GUARANTEED, OPTION_RSVP_ADSPEC_CONTROLLED, \ OPTION_RSVP_ADSPEC_CTOT, OPTION_RSVP_ADSPEC_DTOT, OPTION_RSVP_ADSPEC_CSUM, OPTION_RSVP_ADSPEC_DSUM, OPTION_RSVP_CONFIRM_ADDR ); VALID_OPTIONS_TABLE ( ipsec, OPTION_ENCAPSULATED, OPTION_BOGUSCSUM, OPTION_SOURCE, OPTION_DESTINATION, OPTION_IP_TOS, \ OPTION_IP_ID, OPTION_IP_OFFSET, OPTION_IP_TTL, OPTION_IP_PROTOCOL, OPTION_IP_SOURCE, OPTION_GRE_SEQUENCE_PRESENT, \ OPTION_GRE_KEY_PRESENT, OPTION_GRE_CHECKSUM_PRESENT, OPTION_GRE_KEY, OPTION_GRE_SEQUENCE, OPTION_GRE_SADDR, OPTION_GRE_DADDR, \ OPTION_IPSEC_AH_LENGTH, OPTION_IPSEC_AH_SPI, OPTION_IPSEC_AH_SEQUENCE, OPTION_IPSEC_ESP_SPI, OPTION_IPSEC_ESP_SEQUENCE ); VALID_OPTIONS_TABLE ( eigrp, OPTION_ENCAPSULATED, OPTION_BOGUSCSUM, OPTION_SOURCE, OPTION_DESTINATION, OPTION_IP_TOS, \ OPTION_IP_ID, OPTION_IP_OFFSET, OPTION_IP_TTL, OPTION_IP_PROTOCOL, OPTION_IP_SOURCE, OPTION_GRE_SEQUENCE_PRESENT, \ OPTION_GRE_KEY_PRESENT, OPTION_GRE_CHECKSUM_PRESENT, OPTION_GRE_KEY, OPTION_GRE_SEQUENCE, OPTION_GRE_SADDR, \ OPTION_GRE_DADDR, OPTION_EIGRP_OPCODE, OPTION_EIGRP_FLAGS, OPTION_EIGRP_SEQUENCE, OPTION_EIGRP_ACKNOWLEDGE, \ OPTION_EIGRP_AS, OPTION_EIGRP_TYPE, OPTION_EIGRP_LENGTH, OPTION_EIGRP_K1, OPTION_EIGRP_K2, OPTION_EIGRP_K3, \ OPTION_EIGRP_K4, OPTION_EIGRP_K5, OPTION_EIGRP_HOLD, OPTION_EIGRP_IOS_VERSION, OPTION_EIGRP_PROTO_VERSION, \ OPTION_EIGRP_NEXTHOP, OPTION_EIGRP_DELAY, OPTION_EIGRP_BANDWIDTH, OPTION_EIGRP_MTU, OPTION_EIGRP_HOP_COUNT, \ OPTION_EIGRP_LOAD, OPTION_EIGRP_RELIABILITY, OPTION_EIGRP_DESINATION, OPTION_EIGRP_SOURCE_ROUTER, OPTION_EIGRP_SOURCE_AS, \ OPTION_EIGRP_TAG, OPTION_EIGRP_METRIC, OPTION_EIGRP_ID, OPTION_EIGRP_EXTERNAL_FLAGS, OPTION_EIGRP_ADDRESS, \ OPTION_EIGRP_MULTICAST, OPTION_EIGRP_AUTHENTICATION, OPTION_EIGRP_AUTH_KEY_ID ); VALID_OPTIONS_TABLE ( ospf, OPTION_ENCAPSULATED, OPTION_BOGUSCSUM, OPTION_SOURCE, OPTION_DESTINATION, OPTION_IP_TOS, OPTION_IP_ID, \ OPTION_IP_OFFSET, OPTION_IP_TTL, OPTION_IP_PROTOCOL, OPTION_IP_SOURCE, OPTION_GRE_SEQUENCE_PRESENT, OPTION_GRE_KEY_PRESENT, \ OPTION_GRE_CHECKSUM_PRESENT, OPTION_GRE_KEY, OPTION_GRE_SEQUENCE, OPTION_GRE_SADDR, OPTION_GRE_DADDR, OPTION_EIGRP_OPCODE, \ OPTION_EIGRP_FLAGS, OPTION_EIGRP_SEQUENCE, OPTION_EIGRP_ACKNOWLEDGE, OPTION_EIGRP_AS, OPTION_EIGRP_TYPE, OPTION_EIGRP_LENGTH, \ OPTION_EIGRP_K1, OPTION_EIGRP_K2, OPTION_EIGRP_K3, OPTION_EIGRP_K4, OPTION_EIGRP_K5, OPTION_EIGRP_HOLD, \ OPTION_EIGRP_IOS_VERSION, OPTION_EIGRP_PROTO_VERSION, OPTION_EIGRP_NEXTHOP, OPTION_EIGRP_DELAY, OPTION_EIGRP_BANDWIDTH, \ OPTION_EIGRP_MTU, OPTION_EIGRP_HOP_COUNT, OPTION_EIGRP_LOAD, OPTION_EIGRP_RELIABILITY, OPTION_EIGRP_DESINATION, \ OPTION_EIGRP_SOURCE_ROUTER, OPTION_EIGRP_SOURCE_AS, OPTION_EIGRP_TAG, OPTION_EIGRP_METRIC, OPTION_EIGRP_ID, \ OPTION_EIGRP_EXTERNAL_FLAGS, OPTION_EIGRP_ADDRESS, OPTION_EIGRP_MULTICAST, OPTION_EIGRP_AUTHENTICATION, \ OPTION_EIGRP_AUTH_KEY_ID, OPTION_OSPF_TYPE, OPTION_OSPF_LENGTH, OPTION_OSPF_ROUTER_ID, OPTION_OSPF_AREA_ID, OPTION_OSPF_NETMASK, \ OPTION_OSPF_MT, OPTION_OSPF_E, OPTION_OSPF_MC, OPTION_OSPF_NP, OPTION_OSPF_L, OPTION_OSPF_DC, OPTION_OSPF_O, OPTION_OSPF_DN, \ OPTION_OSPF_HELLO_INTERVAL, OPTION_OSPF_HELLO_PRIORITY, OPTION_OSPF_HELLO_DEAD, OPTION_OSPF_HELLO_DESIGN, \ OPTION_OSPF_HELLO_BACKUP, OPTION_OSPF_HELLO_NEIGHBOR, OPTION_OSPF_HELLO_ADDRESS, OPTION_OSPF_DD_MTU, OPTION_OSPF_DD_MASTER_SLAVE, \ OPTION_OSPF_DD_MORE, OPTION_OSPF_DD_INIT, OPTION_OSPF_DD_OOBRESYNC, OPTION_OSPF_DD_SEQUENCE, OPTION_OSPF_DD_INCLUDE_LSA, \ OPTION_OSPF_LSA_AGE, OPTION_OSPF_LSA_DO_NOT_AGE, OPTION_OSPF_LSA_TYPE, OPTION_OSPF_LSA_LSID, OPTION_OSPF_LSA_ROUTER, \ OPTION_OSPF_LSA_SEQUENCE, OPTION_OSPF_LSA_METRIC, OPTION_OSPF_LSA_FLAG_BORDER, OPTION_OSPF_LSA_FLAG_EXTERNAL, \ OPTION_OSPF_LSA_FLAG_VIRTUAL, OPTION_OSPF_LSA_FLAG_WILD, OPTION_OSPF_LSA_FLAG_NSSA_TR, OPTION_OSPF_LSA_LINK_ID, \ OPTION_OSPF_LSA_LINK_DATA, OPTION_OSPF_LSA_LINK_TYPE, OPTION_OSPF_LSA_ATTACHED, OPTION_OSPF_LSA_LARGER, \ OPTION_OSPF_LSA_FORWARD, OPTION_OSPF_LSA_EXTERNAL, OPTION_OSPF_VERTEX_ROUTER, OPTION_OSPF_VERTEX_NETWORK, \ OPTION_OSPF_VERTEX_ID, OPTION_OSPF_LLS_OPTION_LR, OPTION_OSPF_LLS_OPTION_RS, OPTION_OSPF_AUTHENTICATION, \ OPTION_OSPF_AUTH_KEY_ID, OPTION_OSPF_AUTH_SEQUENCE ); /* A simple way to define the protocols table! To add a procotol, insert the proper header file on common.h (ex: protocol/xpto.h), change the Makefile, add a MODULE_ENTRY, modify config.c and usage.c and compile. That's it! */ BEGIN_MODULES_TABLE /* ( proto, name, description, function ) */ MODULE_ENTRY ( IPPROTO_ICMP, "ICMP", "Internet Control Message Protocol", icmp ) MODULE_ENTRY ( IPPROTO_IGMP, "IGMPv1", "Internet Group Message Protocol v1", igmpv1 ) MODULE_ENTRY ( IPPROTO_IGMP, "IGMPv3", "Internet Group Message Protocol v3", igmpv3 ) MODULE_ENTRY ( IPPROTO_TCP, "TCP", "Transmission Control Protocol", tcp ) MODULE_ENTRY ( IPPROTO_EGP, "EGP", "Exterior Gateway Protocol", egp ) MODULE_ENTRY ( IPPROTO_UDP, "UDP", "User Datagram Protocol", udp ) MODULE_ENTRY ( IPPROTO_UDP, "RIPv1", "Routing Internet Protocol v1", ripv1 ) MODULE_ENTRY ( IPPROTO_UDP, "RIPv2", "Routing Internet Protocol v2", ripv2 ) MODULE_ENTRY ( IPPROTO_DCCP, "DCCP", "Datagram Congestion Control Protocol", dccp ) MODULE_ENTRY ( IPPROTO_RSVP, "RSVP", "Resource Reservation Protocol", rsvp ) MODULE_ENTRY ( IPPROTO_AH, "IPSEC", "Internet Security Protocl (AH/ESP)", ipsec ) MODULE_ENTRY ( IPPROTO_EIGRP, "EIGRP", "Enhanced Interior Gateway Routing Protocol", eigrp ) MODULE_ENTRY ( IPPROTO_OSPF, "OSPF", "Open Shortest Path First", ospf ) END_MODULES_TABLE // Now we have the table above filled. It's safe to get it's size this way. #define NUM_OF_MODULES ((sizeof mod_table / sizeof mod_table[0])-1) const uint32_t number_of_modules = NUM_OF_MODULES; uint32_t indices[NUM_OF_MODULES]; static uint32_t next_index = 0; int *get_module_valid_options_list ( int protocol ) { modules_table_T *ptbl; ptbl = mod_table; while ( ptbl->func ) { if ( ptbl->protocol_id == protocol ) return ptbl->valid_options; ptbl++; } /* Returns NULL if not found. */ return NULL; } void build_proto_indices ( void ) { uint32_t i; // Without shuffling get the sequence. i = 0; while ( i < NUM_OF_MODULES ) { indices[i] = i; i++; // Here to avoid undefined behavior. } } uint32_t get_proto_index ( config_options_T *co ) { uint32_t n; if ( next_index >= NUM_OF_MODULES ) { // We hit the end of the indices array. // reshuffle if shuffling is used. if ( co->shuffle ) shuffle ( indices, NUM_OF_MODULES ); n = indices[next_index = 0]; } else n = indices[next_index++]; return n; } src/netio.c0000664000175000017500000002175514107315014013625 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /** @file netio.c */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2019 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* Maximum number of tries to send the packet. */ #define MAX_SENDTO_RETRYS 10 /* Polling timeout is 1 second. */ #define TIMEOUT 1000 /* Initialized for error condition, just in case! */ static int fd = -1; /* Used for statistics. */ uint64_t bytes_sent = 0ULL; uint64_t packets_sent = 0ULL; //static int wait_for_io ( int ); static void socket_setnonblocking( int ); static void socket_setiphdrincl( int ); static ssize_t socket_send ( int, struct sockaddr_in *, void *, size_t ); #ifdef SO_SNDBUF static void socket_setup_sendbuffer ( int ); #endif #ifdef SO_BROADCAST static void socket_setbroadcast( int ); #endif #ifdef SO_PRIORITY static void socket_setpriority( int ); #endif /** * Creates and configure a raw socket. */ void create_socket ( void ) { /* Setting SOCKET RAW. NOTE: Protocol must be IPPROTO_RAW on Linux. On FreeBSD, if we use 0 IPPROTO_RAW is assumed by default, but on linux will cause an error. */ if ( ( fd = socket ( AF_INET, SOCK_RAW, IPPROTO_RAW ) ) == -1 ) { #ifndef NDEBUG fatal_error ( "Cannot open raw socket: \"%s\"", strerror ( errno ) ); #else fatal_error ( "Cannot open raw socket" ); #endif } socket_setnonblocking( fd ); // FIXME: Possibly not necessary! socket_setiphdrincl( fd ); #ifdef SO_SNDBUF socket_setup_sendbuffer ( fd ); #endif #ifdef SO_BROADCAST socket_setbroadcast( fd ); #endif #ifdef SO_PRIORITY socket_setpriority( fd ); #endif } /** * Tiny routine used to make sure the socket file descriptor is closed. */ void close_socket ( void ) { /* Close only if the descriptor is valid. */ if ( fd > 0 ) { close ( fd ); // AS_SAFE! /* Added to avoid multiple socket closing. */ fd = -1; } } /** * Send a packet through the wire. * * @param buffer Pointer to the packet buffer. * @param size Size of the buffer. * @param co Pointer to configurations for T50. * @return true (success) or false (error). */ int send_packet ( const void * const buffer, size_t size, const config_options_T * const restrict co ) { struct sockaddr_in sin = { .sin_family = AF_INET, .sin_port = htons ( IPPORT_RND ( co->dest ) ), .sin_addr.s_addr = co->ip.daddr /* Already in network byte order! */ }; assert ( buffer != NULL ); assert ( size > 0 ); assert ( co != NULL ); /* Use socket_send(), below. */ errno = 0; if ( socket_send ( fd, &sin, ( void * ) buffer, size ) == -1 ) { if ( errno == EPERM ) fatal_error ( "Cannot send packet (Permission!?). Please check your firewall rules (iptables?)." ); return 0; } packets_sent++; return 1; } #ifdef SO_SNDBUF /* Taken from libdnet by Dug Song. */ void socket_setup_sendbuffer ( int fd ) { uint32_t i, n; socklen_t len; /* Getting SO_SNDBUF. */ len = sizeof ( n ); if ( getsockopt ( fd, SOL_SOCKET, SO_SNDBUF, &n, &len ) == -1 ) { #ifndef NDEBUG fatal_error ( "Cannot get socket buffer: \"%s\"", strerror ( errno ) ); #else fatal_error ( "Cannot get socket buffer" ); #endif } /* Setting the maximum SO_SNDBUF in bytes. * 128 = 1 Kib * 10485760 = 80 Mib */ i = n + 128; while ( i < 10485760 ) { /* Setting SO_SNDBUF. */ errno = 0; /* FIXME: On kernel's net/ipv4.raw.c seems that only ICMP_FILTER is a valid option. Must check! */ if ( setsockopt ( fd, SOL_SOCKET, SO_SNDBUF, &i, sizeof ( i ) ) == -1 ) { if ( errno == ENOBUFS ) break; fatal_error ( "Cannot set socket buffer" ); } i += 128; } } #endif /* SO_SNDBUF */ // FIXME: Maybe it is necessary to insert a counter, in case of multiple failures... static ssize_t socket_send ( int fd, struct sockaddr_in *saddr, void *buffer, size_t size ) { ssize_t r; /* sendto can set errno to EINTR if a signal interrupts the syscall or EAGAIN (or EWOULDBLOCK) if there is no room in the send buffer. */ retry: errno = 0; r = sendto ( fd, buffer, size, MSG_NOSIGNAL, ( struct sockaddr * ) saddr, sizeof ( struct sockaddr_in ) ); /* FIXME: Is this really necessary? */ switch ( errno ) { case EINTR: case EAGAIN: #if EWOULDBLOCK != EAGAIN case EWOULDBLOCK: #endif goto retry; } bytes_sent += size; return r; } /** * IPv4 name resolver using getaddrinfo(). * * Since T50 don't support IPv6 addresses, this routine will * try to get only the first IPv6 address mapped to IPv4, if * no IPv4 address can be found. * * @param name The name, as in "www.target.com"... * @return IPv4 address found (in network order), or 0 if not found. */ in_addr_t resolv ( char *name ) { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wmissing-field-initializers" /* FIXME: Hints getaddrinfo() to return only IPv4 compatible addresses. Not sure if it is wise to use AF_UNSPEC here... */ struct addrinfo hints = { .ai_family = AF_UNSPEC, .ai_flags = AI_ALL | AI_V4MAPPED }, *res, *res0 = NULL; #pragma GCC diagnostic pop in_addr_t addr = 0; int err; assert ( name != NULL ); if ( ( err = getaddrinfo ( name, NULL, &hints, &res0 ) ) != 0 ) { if ( res0 ) freeaddrinfo ( res0 ); error ( "Error on resolv(). getaddrinfo() reports: %s.", gai_strerror ( err ) ); } /* scan all the list. */ res = res0; while ( res && ! addr ) { switch ( res->ai_family ) { case AF_INET: addr = ( ( struct sockaddr_in * ) res->ai_addr )->sin_addr.s_addr; break; // FIXME: This is probably wrong! case AF_INET6: addr = ( ( struct sockaddr_in6 * ) res->ai_addr )->sin6_addr.s6_addr32[3]; } res = res->ai_next; } // Free the linked list. freeaddrinfo ( res0 ); return addr; } // FIXME: Accordingly to Nelson Brito, this is not necessary // because we're dealing with RAW sockets. Must check! void socket_setnonblocking( int fd ) { int flag; /* Try to change the socket mode to NON BLOCKING. */ if ( ( flag = fcntl ( fd, F_GETFL ) ) == -1 ) { #ifndef NDEBUG fatal_error ( "Cannot get socket flags: \"%s\"", strerror ( errno ) ); #else fatal_error ( "Cannot get socket flags" ); #endif } if ( fcntl ( fd, F_SETFL, flag | O_NONBLOCK ) == -1 ) { #ifndef NDEBUG fatal_error ( "Cannot set socket to non-blocking mode: \"%s\"", strerror ( errno ) ); #else fatal_error ( "Cannot set socket to non-blocking mode" ); #endif } } void socket_setiphdrincl( int fd ) { /* This is valid for Linux */ int n = 1; /* Setting IP_HDRINCL. */ /* NOTE: We will provide the IP header, but enabling this option, on linux, still makes the kernel calculates the checksum and total_length. */ /* FIXME: manpages says IP_HDRINCL enabled provides the IP packet checksum automatically. Must check! */ /* FIXME: On kernel's net/ipv4.raw.c seems that only ICMP_FILTER is a valid option. Must check! */ if ( setsockopt ( fd, IPPROTO_IP, IP_HDRINCL, &n, sizeof ( n ) ) == -1 ) { #ifndef NDEBUG fatal_error ( "Cannot set socket options: \"%s\"", strerror ( errno ) ); #else fatal_error ( "Cannot set socket options" ); #endif } } #ifdef SO_BROADCAST void socket_setbroadcast( int fd ) { int n = 1; /* FIXME: On kernel's net/ipv4.raw.c seems that only ICMP_FILTER is a valid option. Must check! */ if ( setsockopt ( fd, SOL_SOCKET, SO_BROADCAST, &n, sizeof ( n ) ) == -1 ) { #ifndef NDEBUG fatal_error ( "Cannot set socket broadcast flag: \"%s\"", strerror ( errno ) ); #else fatal_error ( "Cannot set socket broadcast flag" ); #endif } } #endif #ifdef SO_PRIORITY void socket_setpriority( int fd ) { int n = 1; /* FIXME: Is it a good idea to ajust the socket priority to 1? */ /* FIXME: On kernel's net/ipv4.raw.c seems that only ICMP_FILTER is a valid option. Must check! */ if ( setsockopt ( fd, SOL_SOCKET, SO_PRIORITY, &n, sizeof ( n ) ) == -1 ) { #ifndef NDEBUG fatal_error ( "Cannot set socket priority: \"%s\"", strerror ( errno ) ); #else fatal_error ( "Cannot set socket priority" ); #endif } } #endif src/modules/0000755000175000017500000000000014107315626014010 5ustar fredericofredericosrc/modules/eigrp.c0000644000175000017500000005643313712774300015274 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /** @file eigrp.c */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2019 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include #include #include #include #include static size_t eigrp_hdr_len ( const uint16_t, const uint16_t, const uint8_t, const int ); /** * EIGRP packet header configuration. * * This function configures and sends the EIGRP packet header. * * @param co Pointer to T50 configuration structure. * @param size Pointer to packet size (updated by the function). */ void eigrp ( const config_options_T *const restrict co, size_t *restrict size ) { size_t length, eigrp_tlv_len; /* EIGRP TLV size. */ in_addr_t dest; /* EIGRP Destination address */ uint32_t prefix; /* EIGRP Prefix */ /* Packet and Checksum. */ memptr_T buffer; struct iphdr *ip; struct eigrp_hdr *eigrp; assert ( co != NULL ); length = gre_opt_len ( co ); prefix = __RND ( co->eigrp.prefix ); eigrp_tlv_len = eigrp_hdr_len ( co->eigrp.opcode, co->eigrp.type, prefix, co->eigrp.auth ); *size = sizeof ( struct iphdr ) + sizeof ( struct eigrp_hdr ) + eigrp_tlv_len + length + 8; /* FIXME: Ugly workaround! Must change this later! */ /* Try to reallocate packet, if necessary */ alloc_packet ( *size ); /* IP Header structure making a pointer to Packet. */ ip = ip_header ( packet, *size, co ); /* GRE Encapsulation takes place. */ gre_encapsulation ( packet, co, sizeof ( struct iphdr ) + sizeof ( struct eigrp_hdr ) + eigrp_tlv_len ); /* * Please, be advised that there is no deep information about EIGRP, no * other than EIGRP PCAP files public available. Due to that I have done * a deep analysis using live EIGRP PCAP files to build the EIGRP Packet. * * There are some really good resources, such as: * http://www.protocolbase.net/protocols/protocol_EIGRP.php * http://packetlife.net/captures/category/cisco-proprietary/ * http://oreilly.com/catalog/iprouting/chapter/ch04.html * * EIGRP Header structure. */ eigrp = ( void * ) ( ip + 1 ) + length; eigrp->version = co->eigrp.ver_minor ? co->eigrp.ver_minor : EIGRPVERSION; eigrp->opcode = __RND ( co->eigrp.opcode ); eigrp->flags = __RND ( co->eigrp.flags ); eigrp->sequence = __RND ( co->eigrp.sequence ); eigrp->acknowledge = co->eigrp.type == EIGRP_TYPE_SEQUENCE ? __RND ( co->eigrp.acknowledge ) : 0; eigrp->as = __RND ( co->eigrp.as ); eigrp->check = 0; buffer.ptr = eigrp + 1; /* * Every live EIGRP PCAP file brings Authentication Data TLV first. * * The Authentication Data TVL must be used only in some cases: * 1. IP Internal or External Routes TLV for Update * 2. Software Version with Parameter TLVs for Hello * 3. Next Multicast Sequence TLV for Hello */ if ( co->eigrp.auth ) { if ( co->eigrp.opcode == EIGRP_OPCODE_UPDATE || ( co->eigrp.opcode == EIGRP_OPCODE_HELLO && ( co->eigrp.type == EIGRP_TYPE_MULTICAST || co->eigrp.type == EIGRP_TYPE_SOFTWARE ) ) ) { /* NOTE: stemp used to avoid multiple comparisons on loop below */ uint32_t stemp, counter; stemp = auth_hmac_md5_len ( co->eigrp.auth ); /* * Enhanced Interior Gateway Routing Protocol (EIGRP) * * Authentication Data TLV (EIGRP Type = 0x0002) * * 0 1 2 3 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Type | Length | * +---------------------------------------------------------------+ * | Authentication Method | Authentication Key Size | * +---------------------------------------------------------------+ * | Authentication Key ID | * +---------------------------------------------------------------+ * | | * + + * | Padding (?) | * + + * | | * +---------------------------------------------------------------+ * | | * + + * | Authentication Key Block | * + (MD5 Digest) + * | | * + + * | | * +---------------------------------------------------------------+ */ *buffer.word_ptr++ = htons ( EIGRP_TYPE_AUTH ); *buffer.word_ptr++ = htons ( co->eigrp.length ? co->eigrp.length : EIGRP_TLEN_AUTH ); *buffer.word_ptr++ = htons ( AUTH_TYPE_HMACMD5 ); *buffer.word_ptr++ = htons ( stemp ); *buffer.dword_ptr++ = __RND ( co->eigrp.key_id ); counter = 0; while ( counter++ < EIGRP_PADDING_BLOCK ) *buffer.byte_ptr++ = FIELD_MUST_BE_ZERO; /* * The Authentication key uses HMAC-MD5 or HMAC-SHA-1 digest. */ counter = 0; while ( counter++ < stemp ) *buffer.byte_ptr++ = RANDOM(); } } /* * AFAIK, there are differences when building the EIGRP packet for * Update, Request, Query and Reply. Any EIGRP PCAP file I saw does * not carry Paremeter, Software Version and/or Multicast Sequence, * instead, it carries Authentication Data, IP Internal and External * Routes or nothing (depends on the EIGRP Type). */ switch ( co->eigrp.opcode ) { case EIGRP_OPCODE_UPDATE: case EIGRP_OPCODE_REQUEST: case EIGRP_OPCODE_QUERY: case EIGRP_OPCODE_REPLY: if ( co->eigrp.type == EIGRP_TYPE_INTERNAL || co->eigrp.type == EIGRP_TYPE_EXTERNAL ) { /* * Enhanced Interior Gateway Routing Protocol (EIGRP) * * IP Internal Routes TLV (EIGRP Type = 0x0102) * * 0 1 2 3 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Type | Length | * +---------------------------------------------------------------+ * | Next Hop Address | * +---------------------------------------------------------------+ * | Delay | * +---------------------------------------------------------------+ * | Bandwidth | * +---------------------------------------------------------------+ * | Maximum Transmission Unit (MTU) | Hop Count | * +---------------------------------------------------------------+ * | Reliability | Load | Reserved | * +---------------------------------------------------------------+ * | Prefix // * +---------------+ * * +---------------------------------------------------------------+ * // Destination IP Address(es) (1-4 octets) | * +---------------------------------------------------------------+ * * IP External Routes TLV (EIGRP Type = 0x0103) * * 0 1 2 3 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Type | Length | * +---------------------------------------------------------------+ * | Next Hop Address | * +---------------------------------------------------------------+ * | Originating Router | * +---------------------------------------------------------------+ * | Originating Autonomous System | * +---------------------------------------------------------------+ * | Arbitrary TAG | * +---------------------------------------------------------------+ * | External Protocol Metric | * +---------------------------------------------------------------+ * | Reserved1 | Ext. Proto ID | Flags | * +---------------------------------------------------------------+ * | Delay | * +---------------------------------------------------------------+ * | Bandwidth | * +---------------------------------------------------------------+ * | Maximum Transmission Unit (MTU) | Hop Count | * +---------------------------------------------------------------+ * | Reliability | Load | Reserved2 | * +---------------------------------------------------------------+ * | Prefix // * +---------------+ * * +---------------------------------------------------------------+ * // Destination IP Address(es) (1-4 octets) | * +---------------------------------------------------------------+ * * The only difference between Internal and External Routes TLVs is 20 * octets. */ *buffer.word_ptr++ = htons ( co->eigrp.type == EIGRP_TYPE_INTERNAL ? EIGRP_TYPE_INTERNAL : EIGRP_TYPE_EXTERNAL ); /* * For both Internal and External Routes TLV the code must perform * an additional step to compute the EIGRP header length, because * it depends on the the EIGRP Prefix, and it can be 1-4 octets. */ *buffer.word_ptr++ = htons ( co->eigrp.length ? co->eigrp.length : ( co->eigrp.type == EIGRP_TYPE_INTERNAL ? EIGRP_TLEN_INTERNAL : EIGRP_TLEN_EXTERNAL ) + EIGRP_DADDR_LENGTH ( prefix ) ); *buffer.inaddr_ptr++ = INADDR_RND ( co->eigrp.next_hop ); /* * The only difference between Internal and External Routes TLVs is 20 * octets. Building 20 extra octets for IP External Routes TLV. */ if ( co->eigrp.type == EIGRP_TYPE_EXTERNAL ) { *buffer.inaddr_ptr++ = INADDR_RND ( co->eigrp.src_router ); *buffer.dword_ptr++ = __RND ( co->eigrp.src_as ); *buffer.dword_ptr++ = __RND ( co->eigrp.tag ); *buffer.dword_ptr++ = __RND ( co->eigrp.proto_metric ); *buffer.word_ptr++ = co->eigrp.opcode == EIGRP_OPCODE_UPDATE ? FIELD_MUST_BE_ZERO : htons ( 0x0004 ); *buffer.byte_ptr++ = __RND ( co->eigrp.proto_id ); *buffer.byte_ptr++ = __RND ( co->eigrp.ext_flags ); } dest = INADDR_RND ( co->eigrp.dest ); *buffer.dword_ptr++ = __RND ( co->eigrp.delay ); *buffer.dword_ptr++ = __RND ( co->eigrp.bandwidth ); { uint32_t temp; if ( co->eigrp.mtu ) temp = co->eigrp.mtu; else temp = RANDOM(); *buffer.dword_ptr++ = htonl ( temp << 8 ); // Lower bits always zero? } *buffer.byte_ptr++ = __RND ( co->eigrp.hop_count ); *buffer.byte_ptr++ = __RND ( co->eigrp.reliability ); *buffer.byte_ptr++ = __RND ( co->eigrp.load ); *buffer.word_ptr++ = co->eigrp.opcode == EIGRP_OPCODE_UPDATE ? FIELD_MUST_BE_ZERO : htons ( 0x0004 ); *buffer.byte_ptr++ = prefix; *buffer.inaddr_ptr++ = EIGRP_DADDR_BUILD ( dest, prefix ); // Is this correct? buffer.ptr += EIGRP_DADDR_LENGTH ( prefix ); // FIXME: Pointer really should not be updated here? } break; /* * In the other hand, EIGRP Packet for Hello can carry Paremeter, * Software Version, Multicast Sequence or nothing (Acknowledge). */ case EIGRP_OPCODE_HELLO: /* * AFAIK, EIGRP TLVs must follow a predefined sequence in order to * be built. I am not sure whether any TLV's precedence will impact * in the routers' processing of EIGRP Packet, so I am following * exactly what I saw on live EIGRP PCAP files. Read the code and * you will understand what I am talking about. */ switch ( co->eigrp.type ) { case EIGRP_TYPE_PARAMETER: case EIGRP_TYPE_SOFTWARE: case EIGRP_TYPE_MULTICAST: /* * Enhanced Interior Gateway Routing Protocol (EIGRP) * * General Parameter TLV (EIGRP Type = 0x0001) * * 0 1 2 3 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Type | Length | * +---------------------------------------------------------------+ * | K1 | K2 | K3 | K4 | * +---------------------------------------------------------------+ * | K5 | Reserved | Hold Time | * +---------------------------------------------------------------+ */ *buffer.word_ptr++ = htons ( EIGRP_TYPE_PARAMETER ); *buffer.word_ptr++ = htons ( co->eigrp.length ? co->eigrp.length : EIGRP_TLEN_PARAMETER ); *buffer.byte_ptr++ = TEST_BITS ( co->eigrp.values, EIGRP_KVALUE_K1 ) ? __RND ( co->eigrp.k1 ) : co->eigrp.k1; *buffer.byte_ptr++ = TEST_BITS ( co->eigrp.values, EIGRP_KVALUE_K2 ) ? __RND ( co->eigrp.k2 ) : co->eigrp.k2; *buffer.byte_ptr++ = TEST_BITS ( co->eigrp.values, EIGRP_KVALUE_K3 ) ? __RND ( co->eigrp.k3 ) : co->eigrp.k3; *buffer.byte_ptr++ = TEST_BITS ( co->eigrp.values, EIGRP_KVALUE_K4 ) ? __RND ( co->eigrp.k4 ) : co->eigrp.k4; *buffer.byte_ptr++ = TEST_BITS ( co->eigrp.values, EIGRP_KVALUE_K5 ) ? __RND ( co->eigrp.k5 ) : co->eigrp.k5; *buffer.byte_ptr++ = FIELD_MUST_BE_ZERO; *buffer.word_ptr++ = htons ( co->eigrp.hold ); /* Going to the next TLV, if it needs to do sco-> */ if ( co->eigrp.type == EIGRP_TYPE_SOFTWARE || co->eigrp.type == EIGRP_TYPE_MULTICAST ) { /* * Enhanced Interior Gateway Routing Protocol (EIGRP) * * Software Version TLV (EIGRP Type = 0x0004) * * 0 1 2 3 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Type | Length | * +---------------------------------------------------------------+ * | IOS Major | IOS Minor | EIGRP Major | EIGRP Minor | * +---------------------------------------------------------------+ */ *buffer.word_ptr++ = htons ( EIGRP_TYPE_SOFTWARE ); *buffer.word_ptr++ = htons ( co->eigrp.length ? co->eigrp.length : EIGRP_TLEN_SOFTWARE ); *buffer.byte_ptr++ = __RND ( co->eigrp.ios_major ); *buffer.byte_ptr++ = __RND ( co->eigrp.ios_minor ); *buffer.byte_ptr++ = __RND ( co->eigrp.ver_major ); *buffer.byte_ptr++ = __RND ( co->eigrp.ver_minor ); /* Going to the next TLV, if it needs to do sco-> */ if ( co->eigrp.type == EIGRP_TYPE_MULTICAST ) { /* * Enhanced Interior Gateway Routing Protocol (EIGRP) * * Sequence TLV (EIGRP Type = 0x0003) * * 0 1 2 3 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Type | Length | * +---------------------------------------------------------------+ * | Addr Length // * +---------------+ * * +---------------------------------------------------------------+ * // IP Address | * +---------------------------------------------------------------+ */ *buffer.word_ptr++ = htons ( EIGRP_TYPE_SEQUENCE ); *buffer.word_ptr++ = htons ( co->eigrp.length ? co->eigrp.length : EIGRP_TLEN_SEQUENCE ); *buffer.byte_ptr++ = sizeof ( co->eigrp.address ); *buffer.inaddr_ptr++ = INADDR_RND ( co->eigrp.address ); /* * Enhanced Interior Gateway Routing Protocol (EIGRP) * * Next Multicast Sequence TLV (EIGRP Type = 0x0005) * * 0 1 2 3 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Type | Length | * +---------------------------------------------------------------+ * | Next Multicast Sequence | * +---------------------------------------------------------------+ */ *buffer.word_ptr++ = htons ( EIGRP_TYPE_MULTICAST ); *buffer.word_ptr++ = htons ( co->eigrp.length ? co->eigrp.length : EIGRP_TLEN_MULTICAST ); *buffer.dword_ptr++ = __RND ( co->eigrp.multicast ); } } } } /* Computing the checksum. */ eigrp->check = co->bogus_csum ? RANDOM() : htons ( cksum ( eigrp, ( size_t ) buffer.ptr - ( size_t ) eigrp ) ); /* GRE Encapsulation takes place. */ gre_checksum ( packet, co, *size ); } /* EIGRP header size calculation */ size_t eigrp_hdr_len ( const uint16_t opcode, const uint16_t type, const uint8_t prefix, const int auth ) { /* The code starts with size '0' and it accumulates all the required * size if the conditionals match. Otherwise, it returns size '0'. */ size_t size = 0; /* * The Authentication Data TVL must be used only in some cases: * 1. IP Internal or External Routes TLV for Update * 2. Software Version with Parameter TLVs for Hello * 3. Next Multicast Sequence TLV for Hello */ if ( auth ) { if ( opcode == EIGRP_OPCODE_UPDATE || ( opcode == EIGRP_OPCODE_HELLO && ( type == EIGRP_TYPE_MULTICAST || type == EIGRP_TYPE_SOFTWARE ) ) ) size += EIGRP_TLEN_AUTH; } /* * AFAIK, there are differences when building the EIGRP packet for * Update, Request, Query and Reply. Any EIGRP PCAP file I saw does * not carry Parameter, Software Version and/or Multicast Sequence, * instead, it carries Authentication Data, IP Internal and External * Routes or nothing (depends on the EIGRP Type). */ switch ( opcode ) { case EIGRP_OPCODE_UPDATE: case EIGRP_OPCODE_REQUEST: case EIGRP_OPCODE_QUERY: case EIGRP_OPCODE_REPLY: /* * For both Internal and External Routes TLV the code must perform * an additional step to compute the EIGRP header length, because * it depends on the the EIGRP Prefix, and it can be 1-4 octets. */ switch ( type ) { case EIGRP_TYPE_INTERNAL: size += EIGRP_TLEN_INTERNAL; size += EIGRP_DADDR_LENGTH ( prefix ); break; case EIGRP_TYPE_EXTERNAL: size += EIGRP_TLEN_EXTERNAL; size += EIGRP_DADDR_LENGTH ( prefix ); } break; /* * In the other hand, EIGRP Packet for Hello can carry Parameter, * Software Version, Multicast Sequence or nothing (Acknowledge). */ case EIGRP_OPCODE_HELLO: /* * AFAIK, EIGRP TLVs must follow a predefined sequence in order to * be built. I am not sure whether any TLV's precedence will impact * in the routers' processing of EIGRP Packet, so I am following * exactly what I saw on live EIGRP PCAP files. Read the code and * you will understand what I am talking about. */ switch ( type ) { case EIGRP_TYPE_MULTICAST: size += EIGRP_TLEN_MULTICAST; size += EIGRP_TLEN_SEQUENCE; //break; case EIGRP_TYPE_SOFTWARE: size += EIGRP_TLEN_SOFTWARE; //break; case EIGRP_TYPE_PARAMETER: size += EIGRP_TLEN_PARAMETER; break; } } return size; } src/modules/igmpv1.c0000644000175000017500000000470713712774300015366 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /** @file igmpv1.c */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2019 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include #include #include #include #include #include /** * IGMPv1 packet header configuration. * * This function configures and sends the IGMPv1 packet header. * * @param co Pointer to T50 configuration structure. * @param size Pointer to packet size (updated by the function). */ void igmpv1 ( const config_options_T *const restrict co, size_t *restrict size ) { size_t length; struct iphdr *ip; /* IGMPv1 header. */ struct igmphdr *igmpv1; assert ( co != NULL ); /* GRE options size. */ length = gre_opt_len ( co ); /* Packet size. */ *size = sizeof ( struct iphdr ) + sizeof ( struct igmphdr ) + length; /* Try to reallocate packet, if necessary */ alloc_packet ( *size ); /* IP Header structure making a pointer to Packet. */ ip = ip_header ( packet, *size, co ); /* GRE Encapsulation takes place. */ gre_encapsulation ( packet, co, sizeof ( struct iphdr ) + sizeof ( struct igmphdr ) ); /* IGMPv1 Header structure making a pointer to Packet. */ igmpv1 = ( void * ) ( ip + 1 ) + length; igmpv1->type = co->igmp.type; igmpv1->code = co->igmp.code; igmpv1->group = INADDR_RND ( co->igmp.group ); igmpv1->csum = 0; /* Needed 'cause cksum() call, below! */ /* Computing the checksum. */ igmpv1->csum = co->bogus_csum ? RANDOM() : htons ( cksum ( igmpv1, sizeof ( struct igmphdr ) ) ); /* GRE Encapsulation takes place. */ gre_checksum ( packet, co, *size ); } src/modules/icmp.c0000644000175000017500000000524513712774300015111 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /** @file icmp.c */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2019 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include #include #include #include #include /** * ICMP packet header configuration. * * This function configures and sends the ICMP packet header. * * @param co Pointer to T50 configuration structure. * @param size Pointer to packet size (updated by the function). */ void icmp ( const config_options_T *const restrict co, size_t *restrict size ) { size_t greoptlen; /* GRE options size. */ struct iphdr *ip; /* ICMP header. */ struct icmphdr *icmp; assert ( co != NULL ); greoptlen = gre_opt_len ( co ); *size = sizeof ( struct iphdr ) + sizeof ( struct icmphdr ) + greoptlen; /* Try to reallocate packet, if necessary */ alloc_packet ( *size ); /* IP Header structure making a pointer to Packet. */ ip = ip_header ( packet, *size, co ); /* GRE Encapsulation takes place. */ gre_encapsulation ( packet, co, sizeof ( struct iphdr ) + sizeof ( struct icmphdr ) ); /* ICMP Header structure making a pointer to Packet. */ icmp = ( void * ) ( ip + 1 ) + greoptlen; icmp->type = co->icmp.type; icmp->code = co->icmp.code; icmp->un.echo.id = __RND ( co->icmp.id ); icmp->un.echo.sequence = __RND ( co->icmp.sequence ); if ( co->icmp.type == ICMP_REDIRECT ) switch ( co->icmp.code ) { case ICMP_REDIR_HOST: case ICMP_REDIR_NET: icmp->un.gateway = INADDR_RND ( co->icmp.gateway ); } icmp->checksum = 0; // needed! /* Computing the checksum. */ icmp->checksum = co->bogus_csum ? RANDOM() : htons ( cksum ( icmp, sizeof ( struct icmphdr ) ) ); /* GRE Encapsulation takes place. */ gre_checksum ( packet, co, *size ); } src/modules/ipsec.c0000644000175000017500000001100313712774300015251 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /** @file ipsec.c */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2019 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include #include #include #include #include /** * IPSec packet header configuration. * * This function configures and sends the IPSec packet header. * * @param co Pointer to T50 configuration structure. * @param size Pointer to packet size (updated by the function). */ void ipsec ( const config_options_T *const restrict co, size_t *size ) { /* IPSec AH Integrity Check Value (ICV). */ #define IP_AH_ICV (sizeof(uint32_t) * 3) size_t length, esp_data, /* IPSec ESP Data Encrypted (RANDOM). */ counter; /* Packet. */ memptr_T buffer; struct iphdr *ip; /* IPSec AH header and IPSec ESP Header. */ struct ip_auth_hdr *ip_auth; struct ip_esp_hdr *ip_esp; assert ( co != NULL ); length = gre_opt_len ( co ); esp_data = auth_hmac_md5_len ( 1 ); *size = sizeof ( struct iphdr ) + sizeof ( struct ip_auth_hdr ) + sizeof ( struct ip_esp_hdr ) + length + IP_AH_ICV + esp_data; /* Try to reallocate packet, if necessary */ alloc_packet ( *size ); ip = ip_header ( packet, *size, co ); /* GRE Encapsulation takes place. */ gre_encapsulation ( packet, co, sizeof ( struct iphdr ) + sizeof ( struct ip_auth_hdr ) + sizeof ( struct ip_esp_hdr ) + IP_AH_ICV + esp_data ); /* * IP Authentication Header (RFC 2402) * * 2. Authentication Header Format * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Next Header | Payload Len | RESERVED | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Security Parameters Index (SPI) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Sequence Number Field | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | | * + Authentication Data (variable) | * | | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ /* IPSec AH Header structure making a pointer to IP Header structure. */ ip_auth = ( void * ) ( ip + 1 ) + length; ip_auth->nexthdr = IPPROTO_ESP; ip_auth->hdrlen = co->ipsec.ah_length ? co->ipsec.ah_length : ( sizeof ( struct ip_auth_hdr ) / 4 ) + 1; /* FIX: The previous line was: (sizeof(struct ip_auth_hdr) / 4) + (ip_ah_icv / ip_ah_icv); */ ip_auth->spi = __RND ( co->ipsec.ah_spi ); ip_auth->seq_no = __RND ( co->ipsec.ah_sequence ); buffer.ptr = ip_auth + 1; /* Setting a fake encrypted content. */ counter = 0; while ( counter++ < IP_AH_ICV ) *buffer.byte_ptr++ = RANDOM(); /* IPSec ESP Header structure making a pointer to Checksum. */ ip_esp = buffer.ptr; ip_esp->spi = __RND ( co->ipsec.esp_spi ); ip_esp->seq_no = __RND ( co->ipsec.esp_sequence ); buffer.ptr = ip_esp + 1; /* Setting a fake encrypted content. */ counter = 0; while ( counter++ < esp_data ) *buffer.byte_ptr++ = RANDOM(); /* GRE Encapsulation takes place. */ gre_checksum ( packet, co, *size ); } src/modules/ripv1.c0000664000175000017500000001112614107315014015207 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /** @file ripv1.c */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2019 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #define RIPVERSION 1 #include #include #include #include #include #include #include #include #include #include /** * RIPv1 packet header configuration. * * This function configures and sends the RIPv1 packet header. * * @param co Pointer to T50 configuration structure. * @param size Pointer to packet size (updated by the function). */ void ripv1 ( const config_options_T *const restrict co, size_t *restrict size ) { size_t length; memptr_T buffer; struct iphdr *ip; struct iphdr *gre_ip; struct udphdr *udp; struct psdhdr *pseudo; assert ( co != NULL ); length = gre_opt_len ( co ); *size = sizeof ( struct iphdr ) + sizeof ( struct udphdr ) + sizeof ( struct psdhdr ) + length + rip_hdr_len ( 0 ); /* Try to reallocate packet, if necessary */ alloc_packet ( *size ); /* IP Header structure making a pointer to Packet. */ ip = ip_header ( packet, *size, co ); /* GRE Encapsulation takes place. */ gre_ip = gre_encapsulation ( packet, co, sizeof ( struct iphdr ) + sizeof ( struct udphdr ) + rip_hdr_len ( 0 ) ); /* UDP Header structure making a pointer to IP Header structure. */ udp = ( void * ) ( ip + 1 ) + length; udp->source = udp->dest = htons ( IPPORT_RIP ); udp->len = htons ( sizeof ( struct udphdr ) + rip_hdr_len ( 0 ) ); udp->check = 0; buffer.ptr = udp + 1; /* * Routing Information Protocol (RIP) (RFC 1058) * * 3.1 Message formats * * 0 1 2 3 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | command (1) | version (1) | must be zero (2) | * +---------------+---------------+-------------------------------+ * | address family identifier (2) | must be zero (2) | * +-------------------------------+-------------------------------+ * | IP address (4) | * +---------------------------------------------------------------+ * | must be zero (4) | * +---------------------------------------------------------------+ * | must be zero (4) | * +---------------------------------------------------------------+ * | metric (4) | * +---------------------------------------------------------------+ */ *buffer.byte_ptr++ = co->rip.command; *buffer.byte_ptr++ = RIPVERSION; *buffer.word_ptr++ = FIELD_MUST_BE_ZERO; *buffer.word_ptr++ = __RND ( co->rip.family ); *buffer.word_ptr++ = FIELD_MUST_BE_ZERO; *buffer.inaddr_ptr++ = INADDR_RND ( co->rip.address ); *buffer.inaddr_ptr++ = FIELD_MUST_BE_ZERO; *buffer.inaddr_ptr++ = FIELD_MUST_BE_ZERO; *buffer.inaddr_ptr++ = __RND ( co->rip.metric ); /* PSEUDO Header structure making a pointer to Checksum. */ pseudo = buffer.ptr; if ( co->encapsulated ) { pseudo->saddr = gre_ip->saddr; pseudo->daddr = gre_ip->daddr; } else { pseudo->saddr = ip->saddr; pseudo->daddr = ip->daddr; } pseudo->zero = 0; pseudo->protocol = co->ip.protocol; pseudo->len = htons ( ( size_t ) buffer.ptr - ( size_t ) udp ); /* Computing the checksum. */ udp->check = co->bogus_csum ? RANDOM() : htons ( cksum ( udp, ( size_t ) ( pseudo + 1 ) - ( size_t ) udp ) ); /* GRE Encapsulation takes place. */ gre_checksum ( packet, co, *size ); } src/modules/tcp.c0000664000175000017500000003715414107315014014745 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /** @file tcp.c */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2019 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include #include #include #include #include #include #include #include /* * prototypes. */ static size_t tcp_options_len ( const uint8_t, int, int ); /** * TCP packet header configuration. * * Configures the TCP packet header. * A pointer to this function will be on modules table. * * @param co Pointer to T50 configuration structure. * @param size Pointer to size of the packet (updated by the function). */ void tcp ( const config_options_T * const restrict co, size_t * restrict size ) { uint32_t tcpolen, /* TCP options size. */ tcpopt; /* TCP options total size. */ size_t length; memptr_T buffer; struct iphdr *ip; /* GRE Encapsulated IP Header. */ struct iphdr *gre_ip; /* TCP header and PSEUDO header. */ struct tcphdr *tcp; struct psdhdr *pseudo; assert ( co != NULL ); length = gre_opt_len ( co ); tcpolen = tcp_options_len ( co->tcp.options, co->tcp.md5, co->tcp.auth ); tcpopt = tcpolen + TCPOLEN_PADDING ( tcpolen ); *size = sizeof ( struct iphdr ) + sizeof ( struct tcphdr ) + sizeof ( struct psdhdr ) + tcpopt + length; /* Try to reallocate packet, if necessary */ alloc_packet ( *size ); /* IP Header structure making a pointer to Packet. */ ip = ip_header ( packet, *size, co ); gre_ip = gre_encapsulation ( packet, co, sizeof ( struct iphdr ) + sizeof ( struct tcphdr ) + tcpopt ); /* * The RFC 793 has defined a 4-bit field in the TCP header which encodes the size * of the header in 4-byte words. Thus the maximum header size is 15*4=60 bytes. * Of this, 20 bytes are taken up by non-options fields of the TCP header, which * leaves 40 bytes (TCP header * 2) for options. */ if ( tcpopt > ( sizeof ( struct tcphdr ) * 2 ) ) fatal_error ( "%s() - TCP option size (%zu bytes) is bigger than two times the TCP header size.", __FUNCTION__, tcpopt ); /* TCP Header structure making a pointer to IP Header structure. */ tcp = ( void * ) ( ip + 1 ) + length; tcp->source = IPPORT_RND ( co->source ); tcp->dest = IPPORT_RND ( co->dest ); tcp->res1 = TCP_RESERVED_BITS; tcp->doff = co->tcp.doff ? co->tcp.doff : ( ( sizeof ( struct tcphdr ) + tcpopt ) / 4 ); tcp->fin = co->tcp.fin; tcp->syn = co->tcp.syn; tcp->seq = co->tcp.syn ? __RND ( co->tcp.sequence ) : 0; tcp->rst = co->tcp.rst; tcp->psh = co->tcp.psh; tcp->ack = co->tcp.ack; tcp->ack_seq = co->tcp.ack ? __RND ( co->tcp.acknowledge ) : 0; tcp->urg = co->tcp.urg; tcp->urg_ptr = co->tcp.urg ? __RND ( co->tcp.urg_ptr ) : 0; tcp->ece = co->tcp.ece; tcp->cwr = co->tcp.cwr; tcp->window = __RND ( co->tcp.window ); tcp->check = 0; /* Needed 'cause of cksum() call */ buffer.ptr = tcp + 1; /* * Transmission Control Protocol (TCP) (RFC 793) * * TCP Maximum Segment Size * * Kind: 2 * * Length: 4 bytes * * +--------+--------+---------+--------+ * |00000010|00000100| max seg size | * +--------+--------+---------+--------+ */ if ( TEST_BITS ( co->tcp.options, TCP_OPTION_MSS ) ) { *buffer.byte_ptr++ = TCPOPT_MSS; *buffer.byte_ptr++ = TCPOLEN_MSS; *buffer.word_ptr++ = __RND ( co->tcp.mss ); } /* * TCP Extensions for High Performance (RFC 1323) * * TCP Window Scale Option (WSopt): * * Kind: 3 * * Length: 3 bytes * * +--------+--------+--------+ * |00000011|00000011| shift | * +--------+--------+--------+ */ if ( TEST_BITS ( co->tcp.options, TCP_OPTION_WSOPT ) ) { *buffer.byte_ptr++ = TCPOPT_WSOPT; *buffer.byte_ptr++ = TCPOLEN_WSOPT; *buffer.byte_ptr++ = __RND ( co->tcp.wsopt ); } /* * TCP Extensions for High Performance (RFC 1323) * * TCP Timestamps Option (TSopt): * * Kind: 8 * * Length: 10 bytes * * +--------+--------+ * |00001000|00001010| * +--------+--------+--------+--------+ * | TS Value (TSval) | * +--------+--------+--------+--------+ * | TS Echo Reply (TSecr) | * +--------+--------+--------+--------+ */ if ( TEST_BITS ( co->tcp.options, TCP_OPTION_TSOPT ) ) { /* * TCP Extensions for High Performance (RFC 1323) * * APPENDIX A: IMPLEMENTATION SUGGESTIONS * * The following layouts are recommended for sending options on non-SYN * segments, to achieve maximum feasible alignment of 32-bit and 64-bit * machines. * * * +--------+--------+--------+--------+ * | NOP | NOP | TSopt | 10 | * +--------+--------+--------+--------+ * | TSval timestamp | * +--------+--------+--------+--------+ * | TSecr timestamp | * +--------+--------+--------+--------+ */ if ( !co->tcp.syn ) { /* NOTE: Cannot assume anything about tcpolen. */ /* FIXME: Should avoid using a loop to increase speed, but probably this loop will be unrolled. */ while ( tcpolen & 3 ) { *buffer.byte_ptr++ = TCPOPT_NOP; tcpolen++; } } *buffer.byte_ptr++ = TCPOPT_TSOPT; *buffer.byte_ptr++ = TCPOLEN_TSOPT; *buffer.dword_ptr++ = __RND ( co->tcp.tsval ); *buffer.dword_ptr++ = __RND ( co->tcp.tsecr ); } /* * TCP Extensions for Transactions Functional Specification (RFC 1644) * * CC Option: * * Kind: 11 * * Length: 6 bytes * * +--------+--------+ * |00001011|00000110| * +--------+--------+--------+--------+ * | Connection Count: SEG.CC | * +--------+--------+--------+--------+ */ if ( TEST_BITS ( co->tcp.options, TCP_OPTION_CC ) ) { *buffer.byte_ptr++ = TCPOPT_CC; *buffer.byte_ptr++ = TCPOLEN_CC; *buffer.dword_ptr++ = __RND ( co->tcp.cc ); /* * TCP Extensions for Transactions Functional Specification (RFC 1644) * * 3.1 Data Structures * * This option may be sent in an initial SYN segment, and it may be sent * in other segments if a CC or CC.NEW option has been received for this * incarnation of the connection. Its SEG.CC value is the TCB.CCsend * value from the sender's TCB. */ tcp->syn = true; tcp->seq = __RND ( co->tcp.sequence ); } /* * TCP Extensions for Transactions Functional Specification (RFC 1644) * * CC.NEW Option: * * Kind: 12 * * Length: 6 bytes * * +--------+--------+ * |00001100|00000110| * +--------+--------+--------+--------+ * | Connection Count: SEG.CC | * +--------+--------+--------+--------+ * * CC.ECHO Option: * * Kind: 13 * * Length: 6 bytes * * +--------+--------+ * |00001101|00000110| * +--------+--------+--------+--------+ * | Connection Count: SEG.CC | * +--------+--------+--------+--------+ */ if ( TEST_BITS ( co->tcp.options, TCP_OPTION_CC_NEXT ) ) { *buffer.byte_ptr++ = co->tcp.cc_new ? TCPOPT_CC_NEW : TCPOPT_CC_ECHO; *buffer.byte_ptr++ = TCPOLEN_CC; *buffer.dword_ptr++ = co->tcp.cc_new ? __RND ( co->tcp.cc_new ) : __RND ( co->tcp.cc_echo ); tcp->syn = true; tcp->seq = __RND ( co->tcp.sequence ); /* * TCP Extensions for Transactions Functional Specification (RFC 1644) * * 3.1 Data Structures * * This option may be sent instead of a CC option in an initial * segment (i.e., SYN but not ACK bit), to indicate that the SEG.CC value * may not be larger than the previous value. Its SEG.CC value is the * TCB.CCsend value from the sender's TCB. */ if ( !co->tcp.cc_new ) { /* * TCP Extensions for Transactions Functional Specification (RFC 1644) * * 3.1 Data Structures * * This option may be sent instead of a CC option in an initial * This option must be sent (in addition to a CC option) in a segment * containing both a SYN and an ACK bit, if the initial SYN segment * contained a CC or CC.NEW option. Its SEG.CC value is the SEG.CC value * from the initial SYN. */ tcp->ack = true; tcp->ack_seq = __RND ( co->tcp.acknowledge ); } } /* * TCP Selective Acknowledgement Options (SACK) (RFC 2018) * * TCP Sack-Permitted Option: * * Kind: 4 * * Length: 2 bytes * * +--------+--------+ * |00000100|00000010| * +--------+--------+ */ if ( TEST_BITS ( co->tcp.options, TCP_OPTION_SACK_OK ) ) { *buffer.byte_ptr++ = TCPOPT_SACK_OK; *buffer.byte_ptr++ = TCPOLEN_SACK_OK; } /* * TCP Selective Acknowledgement Options (SACK) (RFC 2018) * * TCP SACK Option: * * Kind: 5 * * Length: Variable * * +--------+--------+ * |00000101| Length | * +--------+--------+--------+--------+ * | Left Edge of 1st Block | * +--------+--------+--------+--------+ * | Right Edge of 1st Block | * +--------+--------+--------+--------+ * | | * / . . . / * | | * +--------+--------+--------+--------+ * | Left Edge of nth Block | * +--------+--------+--------+--------+ * | Right Edge of nth Block | * +--------+--------+--------+--------+ */ if ( TEST_BITS ( co->tcp.options, TCP_OPTION_SACK_EDGE ) ) { *buffer.byte_ptr++ = TCPOPT_SACK_EDGE; *buffer.byte_ptr++ = TCPOLEN_SACK_EDGE ( 1 ); *buffer.dword_ptr++ = __RND ( co->tcp.sack_left ); *buffer.dword_ptr++ = __RND ( co->tcp.sack_right ); } /* * Protection of BGP Sessions via the TCP MD5 Signature Option (RFC 2385) * * TCP MD5 Option: * * Kind: 19 * * Length: 18 bytes * * +--------+--------+--------+--------+ * |00010011|00010010| MD5 digest... | * +--------+--------+--------+--------+ * | ...digest (con't)... | * +-----------------------------------+ * | ... | * +-----------------------------------+ * | ... | * +-----------------+-----------------+ * |...digest (con't)| * +-----------------+ */ if ( co->tcp.md5 ) { uint32_t stemp, counter; *buffer.byte_ptr++ = TCPOPT_MD5; *buffer.byte_ptr++ = TCPOLEN_MD5; /* * The Authentication key uses HMAC-MD5 digest. */ stemp = auth_hmac_md5_len ( co->tcp.md5 ); /* NOTE: Assume stemp > 0. */ counter = 0; while ( counter++ < stemp ) *buffer.byte_ptr++ = RANDOM(); } /* * The TCP Authentication Option (RFC 5925) * * TCP-AO Option: * * Kind: 29 * * Length: 20 bytes * * +--------+--------+--------+--------+ * |00011101|00010100| Key ID |Next Key| * +--------+--------+--------+--------+ * | MAC ... | * +-----------------------------------+ * | ... | * +-----------------------------------+ * | ... | * +-----------------+-----------------+ * | ... MAC | * +-----------------+ */ if ( co->tcp.auth ) { uint32_t stemp, counter; *buffer.byte_ptr++ = TCPOPT_AO; *buffer.byte_ptr++ = TCPOLEN_AO; *buffer.byte_ptr++ = __RND ( co->tcp.key_id ); *buffer.byte_ptr++ = __RND ( co->tcp.next_key ); /* * The Authentication key uses HMAC-MD5 digest. */ stemp = auth_hmac_md5_len ( co->tcp.auth ); /* NOTE: Assume stemp > 0. */ counter = 0; while ( counter++ < stemp ) *buffer.byte_ptr++ = RANDOM(); } /* Padding the TCP Options. */ while ( tcpolen & 3 ) { *buffer.byte_ptr++ = co->tcp.nop; tcpolen++; } /* Needed here 'cause we'll need to initialize pseudo->len. */ length = sizeof ( struct tcphdr ) + tcpolen; /* Fill PSEUDO Header structure. */ pseudo = buffer.ptr; if ( co->encapsulated ) { pseudo->saddr = gre_ip->saddr; pseudo->daddr = gre_ip->daddr; } else { pseudo->saddr = ip->saddr; pseudo->daddr = ip->daddr; } pseudo->zero = 0; pseudo->protocol = co->ip.protocol; pseudo->len = htons ( length ); // FIXME: Maybe it is safer to do: // length = (uint32_t)((size_t)(pseudo+1) - (size_t)tcp); length += sizeof ( struct psdhdr ); /* Computing the checksum. */ tcp->check = co->bogus_csum ? RANDOM() : htons ( cksum ( tcp, length ) ); gre_checksum ( packet, co, *size ); } /* TCP options size calculation. */ size_t tcp_options_len ( const uint8_t tcp_options, int useMD5, int useAuth ) { size_t size; /* * The code starts with size '0' and it accumulates all the required * size if the conditionals match. Otherwise, it returns size '0'. */ size = 0; /* * TCP Options has Maximum Segment Size (MSS) Option defined. */ if ( TEST_BITS ( tcp_options, TCP_OPTION_MSS ) ) size += TCPOLEN_MSS; /* * TCP Options has Window Scale (WSopt) Option defined. */ if ( TEST_BITS ( tcp_options, TCP_OPTION_WSOPT ) ) size += TCPOLEN_WSOPT; /* * TCP Options has Timestamp (TSopt) Option defined. */ if ( TEST_BITS ( tcp_options, TCP_OPTION_TSOPT ) ) size += TCPOLEN_TSOPT; /* * TCP Options has Selective Acknowledgement (SACK-Permitted) Option * defined. */ if ( TEST_BITS ( tcp_options, TCP_OPTION_SACK_OK ) ) size += TCPOLEN_SACK_OK; /* * TCP Options has Connection Count (CC) Option defined. */ if ( TEST_BITS ( tcp_options, TCP_OPTION_CC ) ) size += TCPOLEN_CC; /* * TCP Options has CC.NEW or CC.ECHO Option defined. */ if ( TEST_BITS ( tcp_options, TCP_OPTION_CC_NEXT ) ) size += TCPOLEN_CC; /* * TCP Options has Selective Acknowledgement (SACK) Option defined. */ if ( TEST_BITS ( tcp_options, TCP_OPTION_SACK_EDGE ) ) size += TCPOLEN_SACK_EDGE ( 1 ); /* * Defining it the size should use MD5 Signature Option or the brand * new TCP Authentication Option (TCP-AO). */ if ( useMD5 ) size += TCPOLEN_MD5; if ( useAuth ) size += TCPOLEN_AO; return size; } src/modules/gre.c0000664000175000017500000001520714107315014014727 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /** @file gre.c */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2019 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include #include #include #include #include #include /** * GRE encapsulation routine. * * @param buffer Pointer to the begining of the packet buffer. * @param co Pointer to T50 configuration structure. * @param total_len Length of the buffer. * @return Pointer to IP header (the begining of the buffer). */ struct iphdr *gre_encapsulation ( void * restrict buffer, const config_options_T * const restrict co, size_t total_len ) { struct iphdr *ip, *gre_ip; struct gre_hdr *gre; void *ptr; assert ( buffer != NULL ); assert ( co != NULL ); if ( !co->encapsulated ) return NULL; ip = buffer; /* GRE Header structure. */ /* 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |C|R|K|S|s|Recur| Flags | Ver | Protocol Type | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Checksum (optional) | Offset (optional) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Key (optional) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Sequence Number (optional) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Routing (optional) +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ gre = ( struct gre_hdr * ) ( ip + 1 ); gre->C = co->gre.C; gre->K = co->gre.K; gre->R = FIELD_MUST_BE_ZERO; gre->S = co->gre.S; gre->s = FIELD_MUST_BE_ZERO; gre->recur = FIELD_MUST_BE_ZERO; // That's why this is not in config.c! gre->version = GREVERSION; gre->flags = FIELD_MUST_BE_ZERO; gre->proto = htons ( ETH_P_IP ); /* Computing the GRE offset. */ ptr = gre + 1; /* GRE CHECKSUM? */ if ( co->gre.C ) { /* GRE CHECKSUM Header structure making a pointer to IP Header structure. */ struct gre_sum_hdr *gre_sum = ptr; gre_sum->offset = FIELD_MUST_BE_ZERO; gre_sum->check = 0; ptr = gre_sum + 1; } /* GRE KEY? */ if ( co->gre.K ) { /* GRE KEY Header structure making a pointer to IP Header structure. */ struct gre_key_hdr *gre_key = ptr; gre_key->key = __RND ( co->gre.key ); ptr = gre_key + 1; } /* GRE SEQUENCE? */ if ( co->gre.S ) { /* GRE SEQUENCE Header structure making a pointer to IP Header structure. */ struct gre_seq_hdr *gre_seq = ptr; gre_seq->sequence = __RND ( co->gre.sequence ); ptr = gre_seq + 1; } /* * Generic Routing Encapsulation over IPv4 networks (RFC 1702) * * IP as both delivery and payload protocol * * When IP is encapsulated in IP, the TTL, TOS, and IP security options * MAY be copied from the payload packet into the same fields in the * delivery packet. The payload packet's TTL MUST be decremented when the * packet is decapsulated to insure that no packet lives forever. */ /* GRE Encapsulated IP Header structure making a pointer to to IP Header structure. */ gre_ip = ptr; gre_ip->version = ip->version; gre_ip->ihl = ip->ihl; gre_ip->tos = ip->tos; gre_ip->frag_off = htons ( ip->frag_off ); // NOTE: Not swapped on config.c! gre_ip->tot_len = htons ( total_len ); gre_ip->id = ip->id; gre_ip->ttl = ip->ttl; gre_ip->protocol = co->ip.protocol; gre_ip->saddr = co->gre.saddr ? co->gre.saddr : ip->saddr; gre_ip->daddr = co->gre.daddr ? co->gre.daddr : ip->daddr; /* Computing the checksum. */ gre_ip->check = co->bogus_csum ? RANDOM() : htons ( cksum ( gre_ip, sizeof ( struct iphdr ) ) ); return gre_ip; } /** * Calculates GRE checksum. * * @param buffer Pointer to the begining of packet buffer. * @param co Pointer to T50 configuration structure. * @packet_size Size of the packet. */ void gre_checksum ( void * restrict buffer, const config_options_T * restrict const co, size_t packet_size ) { struct gre_hdr *gre; struct gre_sum_hdr *gre_sum; assert ( buffer != NULL ); assert ( co != NULL ); /* GRE Encapsulation takes place. */ if ( co->encapsulated && co->gre.C ) { gre = ( struct gre_hdr * ) ( ( struct iphdr * ) buffer + 1 ); gre_sum = ( struct gre_sum_hdr * ) ( gre + 1 ); /* Computing the checksum. */ gre_sum->check = co->bogus_csum ? RANDOM() : cksum ( gre, packet_size - sizeof ( struct iphdr ) ); // All packet, except the main IP header. } } /* GRE header size calculation. */ size_t gre_opt_len ( const config_options_T * const co ) { size_t size; /* * The code starts with size '0' and it accumulates all the required * size if the conditionals match. Otherwise, it returns size '0'. */ size = 0; /* * Returns the size of the entire GRE packet only in the case of * encapsulation has been defined ('--encapsulated'). */ if ( co->encapsulated ) { /* * First thing is to accumulate GRE Header size. * And the extra IP header size. */ size = sizeof ( struct gre_hdr ) + sizeof ( struct iphdr ); /* * Checking whether add OPTIONAL header size. * * CHECKSUM HEADER? */ if ( co->gre.C ) size += GRE_OPTLEN_CHECKSUM; /* KEY HEADER? */ if ( co->gre.K ) size += GRE_OPTLEN_KEY; /* SEQUENCE HEADER? */ if ( co->gre.S ) size += GRE_OPTLEN_SEQUENCE; } return size; } src/modules/ripv2.c0000664000175000017500000002574714107315014015226 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /** @file ripv2.c */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2019 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #define RIPVERSION 2 #include #include #include #include #include #include #include #include #include #include /** * RIPv2 packet header configuration. * * This function configures and sends the RIPv2 packet header. * * @param co Pointer to T50 configuration structure. * @param size Pointer to packet size (updated by the function). */ void ripv2 ( const config_options_T *const restrict co, size_t *restrict size ) { size_t greoptlen, /* GRE options size. */ length; memptr_T buffer; struct iphdr *ip; struct iphdr *gre_ip; struct udphdr *udp; struct psdhdr *pseudo; assert ( co != NULL ); greoptlen = gre_opt_len ( co ); *size = sizeof ( struct iphdr ) + sizeof ( struct udphdr ) + sizeof ( struct psdhdr ) + greoptlen + rip_hdr_len ( co->rip.auth ); /* Try to reallocate packet, if necessary */ alloc_packet ( *size ); /* IP Header structure making a pointer to Packet. */ ip = ip_header ( packet, *size, co ); /* GRE Encapsulation takes place. */ gre_ip = gre_encapsulation ( packet, co, sizeof ( struct iphdr ) + sizeof ( struct udphdr ) + rip_hdr_len ( co->rip.auth ) ); /* UDP Header structure making a pointer to IP Header structure. */ udp = ( void * ) ( ip + 1 ) + greoptlen; udp->source = udp->dest = htons ( IPPORT_RIP ); udp->len = htons ( sizeof ( struct udphdr ) + rip_hdr_len ( co->rip.auth ) ); udp->check = 0; buffer.ptr = udp + 1; /* * RIP Version 2 -- Carrying Additional Information (RFC 1388) * * 3. Protocol Extensions * * The new RIP datagram format is: * * 0 1 2 3 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Command (1) | Version (1) | Routing Domain (2) | * +---------------+---------------+-------------------------------+ * | Address Family Identifier (2) | Route Tag (2) | * +-------------------------------+-------------------------------+ * | IP Address (4) | * +---------------------------------------------------------------+ * | Subnet Mask (4) | * +---------------------------------------------------------------+ * | Next Hop (4) | * +---------------------------------------------------------------+ * | Metric (4) | * +---------------------------------------------------------------+ * * XXX Playing with: * * 0 1 2 3 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Command (1) | Version (1) | Routing Domain (2) | * +---------------+---------------+-------------------------------+ */ *buffer.byte_ptr++ = co->rip.command; *buffer.byte_ptr++ = RIPVERSION; *buffer.word_ptr++ = __RND ( co->rip.domain ); /* DON'T NEED THIS */ /* length = sizeof(struct udphdr) + RIP_HEADER_LENGTH; */ /* * RIP-2 MD5 Authentication (RFC 2082) * * 3.2. Processing Algorithm * * 0 1 2 3 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | 0xFFFF | Authentication Type (2) | * +-------------------------------+-------------------------------+ * | RIP-2 Packet Length | Key ID | Auth Data Len | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Sequence Number (non-decreasing) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | reserved must be zero | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | reserved must be zero | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | | * / (RIP-2 Packet Length - 24) bytes of Data / * | | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | 0xFFFF | 0x01 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * / Authentication Data (var. length; 16 bytes with Keyed MD5) / * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * * XXX Playing with: * * 0 1 2 3 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | 0xFFFF | Authentication Type (2) | * +-------------------------------+-------------------------------+ * | RIP-2 Packet Length | Key ID | Auth Data Len | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Sequence Number (non-decreasing) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | reserved must be zero | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | reserved must be zero | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ if ( co->rip.auth ) { *buffer.word_ptr++ = 0xffffU; *buffer.word_ptr++ = htons ( 3 ); *buffer.word_ptr++ = htons ( RIP_HEADER_LENGTH + RIP_AUTH_LENGTH + RIP_MESSAGE_LENGTH ); *buffer.byte_ptr++ = co->rip.key_id; *buffer.byte_ptr++ = RIP_AUTH_LENGTH; *buffer.dword_ptr++ = __RND ( co->rip.sequence ); *buffer.dword_ptr++ = FIELD_MUST_BE_ZERO; *buffer.dword_ptr++ = FIELD_MUST_BE_ZERO; } /* * XXX Playing with: * * RIP Version 2 -- Carrying Additional Information (RFC 1388) * * 0 1 2 3 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Address Family Identifier (2) | Route Tag (2) | * +-------------------------------+-------------------------------+ * | IP Address (4) | * +---------------------------------------------------------------+ * | Subnet Mask (4) | * +---------------------------------------------------------------+ * | Next Hop (4) | * +---------------------------------------------------------------+ * | Metric (4) | * +---------------------------------------------------------------+ * * RIP-2 MD5 Authentication (RFC 2082) * * 0 1 2 3 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | | * / (RIP-2 Packet Length - 24) bytes of Data / * | | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ *buffer.word_ptr++ = __RND ( co->rip.family ); *buffer.word_ptr++ = __RND ( co->rip.tag ); *buffer.inaddr_ptr++ = INADDR_RND ( co->rip.address ); *buffer.inaddr_ptr++ = NETMASK_RND ( co->rip.netmask ); *buffer.inaddr_ptr++ = INADDR_RND ( co->rip.next_hop ); *buffer.inaddr_ptr++ = __RND ( co->rip.metric ); /* * XXX Playing with: * * RIP-2 MD5 Authentication (RFC 2082) * * 0 1 2 3 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | 0xFFFF | 0x01 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * / Authentication Data (var. length; 16 bytes with Keyed MD5) / * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ if ( co->rip.auth ) { uint32_t size, counter; *buffer.word_ptr++ = 0xffffU; *buffer.word_ptr++ = htons ( 1 ); /* * The Authentication key uses HMAC-MD5 or HMAC-SHA-1 digest. */ size = auth_hmac_md5_len ( co->rip.auth ); /* NOTE: Assume size > 0. */ counter = 0; while ( counter++ < size ) *buffer.byte_ptr++ = RANDOM(); } /* PSEUDO Header structure making a pointer to Checksum. */ pseudo = buffer.ptr; if ( co->encapsulated ) { pseudo->saddr = gre_ip->saddr; pseudo->daddr = gre_ip->daddr; } else { pseudo->saddr = ip->saddr; pseudo->daddr = ip->daddr; } pseudo->zero = 0; pseudo->protocol = co->ip.protocol; pseudo->len = htons ( length = ( ( size_t ) buffer.ptr - ( size_t ) udp ) ); /* FIX: buffer.ptr points to 'pseudo' So, it is simple to calculate the size used by cksum() function. This is easier than accumulate the "length" through various conditionals above! */ /* Computing the checksum. */ udp->check = co->bogus_csum ? RANDOM() : htons ( cksum ( udp, ( size_t ) ( pseudo + 1 ) - ( size_t ) udp ) ); /* GRE Encapsulation takes place. */ gre_checksum ( packet, co, *size ); } src/modules/ip.c0000644000175000017500000000540613712774300014570 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /** @file ip.c */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2019 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include #include #include #include /* Defined here 'cause we need them just here. And since we are using linux/ip.h header, they are not defined there! */ #define IP_MF 0x2000 #define IP_DF 0x4000 /** * IP header configuration. * * Every module uses this to build the IP portion of the packet. * * @param buffer Pointer to the begining of the packet. * @param packet_size size of the buffer. * @param co Pointer to T50 configuration structure. * @return Pointer to IP header structure (points to the begining of the buffer). */ struct iphdr *ip_header ( void *restrict buffer, uint32_t packet_size, const config_options_T *restrict co ) { struct iphdr *ip; assert ( buffer != NULL ); assert ( co != NULL ); ip = buffer; ip->version = IPVERSION; ip->ihl = sizeof ( struct iphdr ) / 4; /* ihl is measured in DWORDs. */ /* FIXME: MAYBE TOS is filled by kernel through the SO_PRIORITY option and this is completly useless. */ ip->tos = co->ip.tos; // NOTE: frag_off must be byte swapped here, not in config.c. ip->frag_off = htons ( co->ip.frag_off ? ( co->ip.frag_off >> 3 ) | IP_MF : IP_DF ); /* FIXME: Is it necessary to fill tot_len when IP_HDRINCL is used? */ ip->tot_len = htons ( packet_size ); ip->id = __RND ( co->ip.id ); ip->ttl = co->ip.ttl; ip->protocol = co->encapsulated ? IPPROTO_GRE : co->ip.protocol; ip->saddr = INADDR_RND ( co->ip.saddr ); ip->daddr = co->ip.daddr; ip->check = 0; // NOTE: it will be calculated by the kernel! // FIXME: In case this code will be ported to other OSses, // we should calculate the checksum ourselves AFTER // the entire package is ready. // This can be done in main()'s main loop, before calling send_packet(). return ip; } src/modules/dccp.c0000644000175000017500000002376613712774300015102 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /** @file dccp.c */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2019 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include #include #include #include #include #include /** * DCCP packet header configuration. * * This function configures and sends the DCCP packet header. * * @param co Pointer to T50 configuration structure. * @param size Pointer to packet size (updated by the function). */ void dccp ( const config_options_T *const restrict co, size_t *restrict size ) { size_t length, dccp_length, /* DCCP header length. */ dccp_ext_length; /* DCCP Extended Sequence Number length. */ /* Packet and Checksum. */ void *buffer_ptr; struct iphdr *ip; /* GRE Encapsulated IP Header. */ struct iphdr *gre_ip; /* DCCP header and PSEUDO header. */ struct dccp_hdr *dccp; struct psdhdr *pseudo; /* DCCP Headers. */ struct dccp_hdr_ext *dccp_ext; struct dccp_hdr_request *dccp_req; struct dccp_hdr_response *dccp_res; struct dccp_hdr_ack_bits *dccp_ack; struct dccp_hdr_reset *dccp_rst; assert ( co != NULL ); length = gre_opt_len ( co ); dccp_length = dccp_packet_hdr_len ( co->dccp.type ); dccp_ext_length = ( co->dccp.ext ? sizeof ( struct dccp_hdr_ext ) : 0 ); *size = sizeof ( struct iphdr ) + sizeof ( struct dccp_hdr ) + sizeof ( struct psdhdr ) + dccp_ext_length + dccp_length + length; /* Try to reallocate packet, if necessary */ alloc_packet ( *size ); /* IP Header structure making a pointer to Packet. */ ip = ip_header ( packet, *size, co ); /* Prepare GRE encapsulation, if needed */ gre_ip = gre_encapsulation ( packet, co, sizeof ( struct iphdr ) + sizeof ( struct dccp_hdr ) + dccp_ext_length + dccp_length ); /* DCCP Header structure making a pointer to Packet. */ dccp = ( void * ) ( ip + 1 ) + length; dccp->dccph_sport = IPPORT_RND ( co->source ); dccp->dccph_dport = IPPORT_RND ( co->dest ); /* * Datagram Congestion Control Protocol (DCCP) (RFC 4340) * * Data Offset: 8 bits * The offset from the start of the packet's DCCP header to the start * of its application data area, in 32-bit words. The receiver MUST * ignore packets whose Data Offset is smaller than the minimum-sized * header for the given Type or larger than the DCCP packet itself. */ dccp->dccph_doff = co->dccp.doff ? co->dccp.doff : ( sizeof ( struct dccp_hdr ) + dccp_length + dccp_ext_length ) / 4; dccp->dccph_type = co->dccp.type; dccp->dccph_ccval = __RND ( co->dccp.ccval ); /* * Datagram Congestion Control Protocol (DCCP) (RFC 4340) * * 9.2. Header Checksum Coverage Field * * The Checksum Coverage field in the DCCP generic header (see Section * 5.1) specifies what parts of the packet are covered by the Checksum * field, as follows: * * CsCov = 0 The Checksum field covers the DCCP header, DCCP * options, network-layer pseudoheader, and all * application data in the packet, possibly padded on * the right with zeros to an even number of bytes. * * CsCov = 1-15 The Checksum field covers the DCCP header, DCCP * options, network-layer pseudoheader, and the initial * (CsCov-1)*4 bytes of the packet's application data. */ dccp->dccph_cscov = co->dccp.cscov ? ( co->dccp.cscov - 1 ) * 4 : ( co->bogus_csum ? ( uint8_t ) ( RANDOM() & 0xf ) : co->dccp.cscov ); /* * Datagram Congestion Control Protocol (DCCP) (RFC 4340) * * 5.1. Generic Header * * The DCCP generic header takes different forms depending on the value * of X, the Extended Sequence Numbers bit. If X is one, the Sequence * Number field is 48 bits long, and the generic header takes 16 bytes, * as follows. * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Source Port | Dest Port | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Data Offset | CCVal | CsCov | Checksum | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | | |X| | . * | Res | Type |=| Reserved | Sequence Number (high bits) . * | | |1| | . * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * . Sequence Number (low bits) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * * If X is zero, only the low 24 bits of the Sequence Number are * transmitted, and the generic header is 12 bytes long. * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Source Port | Dest Port | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Data Offset | CCVal | CsCov | Checksum | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | | |X| | * | Res | Type |=| Sequence Number (low bits) | * | | |0| | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ dccp->dccph_x = co->dccp.ext; dccp->dccph_seq = __RND ( co->dccp.sequence_01 ); dccp->dccph_seq2 = co->dccp.ext ? 0 : __RND ( co->dccp.sequence_02 ); dccp->dccph_checksum = 0; /* NOTE: Not using union 'memptr_T' this time!!! */ buffer_ptr = dccp + 1; /* DCCP Extended Header structure making a pointer to Checksum. */ if ( co->dccp.ext ) { dccp_ext = buffer_ptr; dccp_ext->dccph_seq_low = __RND ( co->dccp.sequence_03 ); buffer_ptr = dccp_ext + 1; } /* Identifying the DCCP Type and building it. */ switch ( co->dccp.type ) { case DCCP_PKT_REQUEST: /* DCCP Request Header structure making a pointer to Checksum. */ dccp_req = buffer_ptr; dccp_req->dccph_req_service = __RND ( co->dccp.service ); buffer_ptr = dccp_req + 1; break; case DCCP_PKT_RESPONSE: /* DCCP Response Header structure making a pointer to Checksum. */ dccp_res = buffer_ptr; dccp_res->dccph_resp_ack.dccph_reserved1 = FIELD_MUST_BE_ZERO; dccp_res->dccph_resp_ack.dccph_ack_nr_high = __RND ( co->dccp.acknowledge_01 ); dccp_res->dccph_resp_ack.dccph_ack_nr_low = __RND ( co->dccp.acknowledge_02 ); dccp_res->dccph_resp_service = __RND ( co->dccp.service ); buffer_ptr = dccp_res + 1; case DCCP_PKT_DATA: break; case DCCP_PKT_DATAACK: case DCCP_PKT_ACK: case DCCP_PKT_SYNC: case DCCP_PKT_SYNCACK: case DCCP_PKT_CLOSE: case DCCP_PKT_CLOSEREQ: /* DCCP Acknowledgment Header structure making a pointer to Checksum. */ dccp_ack = buffer_ptr; dccp_ack->dccph_reserved1 = FIELD_MUST_BE_ZERO; dccp_ack->dccph_ack_nr_high = __RND ( co->dccp.acknowledge_01 ); /* Until DCCP Options implementation. */ if ( co->dccp.type == DCCP_PKT_DATAACK || co->dccp.type == DCCP_PKT_ACK ) dccp_ack->dccph_ack_nr_low = htonl ( 1 ); else dccp_ack->dccph_ack_nr_low = __RND ( co->dccp.acknowledge_02 ); buffer_ptr = dccp_ack + 1; break; default: /* DCCP Reset Header structure making a pointer to Checksum. */ dccp_rst = buffer_ptr; dccp_rst->dccph_reset_ack.dccph_reserved1 = FIELD_MUST_BE_ZERO; dccp_rst->dccph_reset_ack.dccph_ack_nr_high = __RND ( co->dccp.acknowledge_01 ); dccp_rst->dccph_reset_ack.dccph_ack_nr_low = __RND ( co->dccp.acknowledge_02 ); dccp_rst->dccph_reset_code = __RND ( co->dccp.rst_code ); buffer_ptr = dccp_rst + 1; break; } /* PSEUDO Header structure??? */ pseudo = buffer_ptr; if ( co->encapsulated ) { pseudo->saddr = gre_ip->saddr; pseudo->daddr = gre_ip->daddr; } else { pseudo->saddr = ip->saddr; pseudo->daddr = ip->daddr; } pseudo->zero = 0; pseudo->protocol = co->ip.protocol; pseudo->len = htons ( ( size_t ) buffer_ptr - ( size_t ) dccp ); /* Computing the checksum. */ dccp->dccph_checksum = co->bogus_csum ? RANDOM() : htons ( cksum ( dccp, ( size_t ) ( pseudo + 1 ) - ( size_t ) dccp ) ); /* Finish GRE encapsulation, if needed */ gre_checksum ( packet, co, *size ); } src/modules/egp.c0000644000175000017500000000567413712774300014742 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /** @file egp.c */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2019 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include #include #include #include /** * EGP packet header configuration. * * This function configures and sends the EGP packet header. * * @param co Pointer to T50 configuration structure. * @param size Pointer to packet size (updated by the function). */ void egp ( const config_options_T *const restrict co, size_t *restrict size ) { size_t length; struct iphdr *ip; /* EGP header and EGP acquire header. */ struct egp_hdr *egp; struct egp_acq_hdr *egp_acq; assert ( co != NULL ); length = gre_opt_len ( co ); *size = sizeof ( struct iphdr ) + sizeof ( struct egp_hdr ) + sizeof ( struct egp_acq_hdr ) + length; /* Try to reallocate packet, if necessary */ alloc_packet ( *size ); /* IP Header structure making a pointer to Packet. */ ip = ip_header ( packet, *size, co ); /* GRE Encapsulation takes place. */ gre_encapsulation ( packet, co, sizeof ( struct iphdr ) + sizeof ( struct egp_hdr ) + sizeof ( struct egp_acq_hdr ) ); /* * @nbrito -- Tue Jan 18 11:09:34 BRST 2011 * XXX Have to work a little bit more deeply in packet building. * XXX Checking EGP Type and building appropriate header. */ /* EGP Header structure making a pointer to Packet. */ egp = ( void * ) ( ip + 1 ) + length; egp->version = EGPVERSION; egp->type = co->egp.type; egp->code = co->egp.code; egp->status = co->egp.status; egp->as = __RND ( co->egp.as ); egp->sequence = __RND ( co->egp.sequence ); egp->check = 0; /* EGP Acquire Header structure. */ egp_acq = ( struct egp_acq_hdr * ) ( egp + 1 ); egp_acq->hello = __RND ( co->egp.hello ); egp_acq->poll = __RND ( co->egp.poll ); /* Computing the checksum. */ egp->check = co->bogus_csum ? RANDOM() : htons ( cksum ( egp, ( size_t ) ( egp_acq + 1 ) - ( size_t ) egp ) ); /* GRE Encapsulation takes place. */ gre_checksum ( packet, co, *size ); } src/modules/igmpv3.c0000644000175000017500000001131413712774300015360 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /** @file igmpv3.c */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2019 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include #include #include #include #include #include /** * IGMPv3 packet header configuration. * * This function configures and sends the IGMPv3 packet header. * * @para co Pointer to T50 configuration structure. * @para size Pointer to packet size (updated by the function). */ void igmpv3 ( const config_options_T *const restrict co, size_t *restrict size ) { size_t length; /* Packet and Checksum. */ memptr_T buffer; struct iphdr *ip; /* IGMPv3 Query header, IGMPv3 Report header and IGMPv3 GREC header. */ struct igmpv3_query *igmpv3_query; struct igmpv3_report *igmpv3_report; struct igmpv3_grec *igmpv3_grec; assert ( co != NULL ); length = gre_opt_len ( co ); *size = sizeof ( struct iphdr ) + length + igmpv3_hdr_len ( co->igmp.type, co->igmp.sources ); /* Try to reallocate packet, if necessary */ alloc_packet ( *size ); /* IP Header structure making a pointer to Packet. */ ip = ip_header ( packet, *size, co ); /* GRE Encapsulation takes place. */ gre_encapsulation ( packet, co, sizeof ( struct iphdr ) + igmpv3_hdr_len ( co->igmp.type, co->igmp.sources ) ); /* Identifying the IGMP Type and building it. */ if ( co->igmp.type == IGMPV3_HOST_MEMBERSHIP_REPORT ) { uint32_t counter; /* IGMPv3 Report Header structure making a pointer to Packet. */ igmpv3_report = ( void * ) ( ip + 1 ) + length; igmpv3_report->type = co->igmp.type; igmpv3_report->resv1 = FIELD_MUST_BE_ZERO; igmpv3_report->resv2 = FIELD_MUST_BE_ZERO; igmpv3_report->ngrec = htons ( 1 ); igmpv3_report->csum = FIELD_MUST_BE_ZERO; /* IGMPv3 Group Record Header structure making a pointer to Checksum. */ igmpv3_grec = ( struct igmpv3_grec * ) ( igmpv3_report + 1 ); igmpv3_grec->grec_type = __RND ( co->igmp.grec_type ); igmpv3_grec->grec_auxwords = FIELD_MUST_BE_ZERO; igmpv3_grec->grec_nsrcs = htons ( co->igmp.sources ); // Necessary even if co->igmp.sources is a 8 bit value. igmpv3_grec->grec_mca = INADDR_RND ( co->igmp.grec_mca ); /* Dealing with source address(es). */ buffer.ptr = igmpv3_grec + 1; /* NOTE: Assume co->igmp.sources > 0. */ counter = 0; while ( counter < co->igmp.sources ) *buffer.inaddr_ptr++ = INADDR_RND ( co->igmp.address[counter++] ); /* Computing the checksum. */ length = ( size_t ) buffer.ptr - ( size_t ) igmpv3_report; igmpv3_report->csum = co->bogus_csum ? RANDOM() : htons ( cksum ( igmpv3_report, length ) ); } else { uint32_t counter; /* IGMPv3 Query Header structure making a pointer to Packet. */ igmpv3_query = ( void * ) ( ip + 1 ) + length; igmpv3_query->type = co->igmp.type; igmpv3_query->code = co->igmp.code; igmpv3_query->group = INADDR_RND ( co->igmp.group ); igmpv3_query->suppress = ( co->igmp.suppress != 0 ); igmpv3_query->qrv = __RND ( co->igmp.qrv ); igmpv3_query->qqic = __RND ( co->igmp.qqic ); igmpv3_query->nsrcs = htons ( co->igmp.sources ); igmpv3_query->csum = 0; /* Dealing with source address(es). */ buffer.ptr = igmpv3_query + 1; /* NOTE: Assume co->igmp.sources > 0. */ counter = 0; while ( counter < co->igmp.sources ) *buffer.inaddr_ptr++ = INADDR_RND ( co->igmp.address[counter++] ); /* Computing the checksum. */ length = ( size_t ) buffer.ptr - ( size_t ) igmpv3_query; igmpv3_query->csum = co->bogus_csum ? RANDOM() : htons ( cksum ( igmpv3_query, length ) ); } /* GRE Encapsulation takes place. */ gre_checksum ( packet, co, *size ); } src/modules/ospf.c0000644000175000017500000007607413712774300015140 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /** @file ospf.c */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2019 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include #include #include #include #include static size_t ospf_hdr_len ( uint32_t, int, int, int ); static void ospf_lsupdate ( const config_options_T *const restrict, void **restrict, struct ospf_lsa_hdr *restrict ); /** * OSPF packet header configuration. * * This function configures and sends the OSPF packet header. * * @param co Pointer to T50 configuration structure. * @param size Pointer to packet size (updated by the function). */ void ospf ( const config_options_T *const restrict co, size_t *restrict size ) { size_t length, ospf_length, /* OSPF header length. */ counter, stemp; uint8_t ospf_options, /* OSPF options? */ lls; /* OSPF LLS header? */ /* Packet and Checksum. */ memptr_T buffer; struct iphdr *ip; struct ospf_hdr *ospf; /* OSPF Auth header, LSA header and LLS TLVs. */ struct ospf_auth_hdr *ospf_auth; struct ospf_lsa_hdr *ospf_lsa; struct ospf_lls_hdr *ospf_lls; assert ( co != NULL ); length = gre_opt_len ( co ); ospf_options = __RND ( co->ospf.options ); lls = TEST_BITS ( ospf_options, OSPF_OPTION_LLS ) ? 1 : 0; ospf_length = ospf_hdr_len ( co->ospf.type, co->ospf.neighbor, co->ospf.lsa_type, co->ospf.dd_include_lsa ); *size = sizeof ( struct iphdr ) + sizeof ( struct ospf_hdr ) + sizeof ( struct ospf_auth_hdr ) + length + ospf_length + auth_hmac_md5_len ( co->ospf.auth ) + ospf_tlv_len ( co->ospf.type, lls, co->ospf.auth ); /* Try to reallocate packet, if necessary */ alloc_packet ( *size ); /* IP Header structure making a pointer to Packet. */ ip = ip_header ( packet, *size, co ); gre_encapsulation ( packet, co, sizeof ( struct iphdr ) + sizeof ( struct ospf_hdr ) + sizeof ( struct ospf_auth_hdr ) + ospf_length + auth_hmac_md5_len ( co->ospf.auth ) + ospf_tlv_len ( co->ospf.type, lls, co->ospf.auth ) ); /* OSPF Header structure making a pointer to IP Header structure. */ ospf = ( void * ) ( ip + 1 ) + length; ospf->version = OSPFVERSION; ospf->type = co->ospf.type; /* * OSPF Version 2 (RFC 2328) * * D.3 Cryptographic authentication * * The message digest appended to the OSPF packet is not actually * considered part of the OSPF protocol packet: the message digest * is not included in the OSPF header's packet length, although it * is included in the packet's IP header length field. */ ospf->length = htons ( co->ospf.length ? co->ospf.length : sizeof ( struct ospf_hdr ) + sizeof ( struct ospf_auth_hdr ) + ospf_length ); ospf->rid = INADDR_RND ( co->ospf.rid ); ospf->aid = co->ospf.AID ? INADDR_RND ( co->ospf.aid ) : co->ospf.aid; ospf->check = 0; /* OSPF Authentication Header structure making a pointer to OSPF Header structure. */ ospf_auth = ( struct ospf_auth_hdr * ) ( ospf + 1 ); /* Identifiyingt whether to use Authentication or not. */ ospf_auth->reserved = FIELD_MUST_BE_ZERO; if ( co->ospf.auth ) { /* * OSPF Version 2 (RFC 2328) * * D.3 Cryptographic authentication * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | 0 | Key ID | Auth Data Len | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Cryptographic sequence number | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ ospf->autype = htons ( AUTH_TYPE_HMACMD5 ); ospf_auth->key_id = __RND ( co->ospf.key_id ); ospf_auth->length = auth_hmac_md5_len ( co->ospf.auth ); ospf_auth->sequence = __RND ( co->ospf.sequence ); } else { /* * OSPF Version 2 (RFC 2328) * * A.3.1 The OSPF packet header * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Authentication | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Authentication | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ ospf->autype = AUTH_TYPE_HMACNUL; /* FIXME: Is this 0? */ ospf_auth->key_id = FIELD_MUST_BE_ZERO; ospf_auth->length = FIELD_MUST_BE_ZERO; ospf_auth->sequence = FIELD_MUST_BE_ZERO; } buffer.ptr = ospf_auth + 1; /* Identifying the OSPF Type and building it. */ switch ( co->ospf.type ) { case OSPF_TYPE_HELLO: /* * OSPF Version 2 (RFC 2328) * * A.3.2 The Hello packet * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Network Mask | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | HelloInterval | Options | Rtr Pri | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | RouterDeadInterval | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Designated Router | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Backup Designated Router | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Neighbor | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | ... | */ *buffer.inaddr_ptr++ = NETMASK_RND ( co->ospf.netmask ); *buffer.word_ptr++ = __RND ( co->ospf.hello_interval ); *buffer.byte_ptr++ = ospf_options; *buffer.byte_ptr++ = __RND ( co->ospf.hello_priority ); *buffer.dword_ptr++ = __RND ( co->ospf.hello_dead ); *buffer.inaddr_ptr++ = INADDR_RND ( co->ospf.hello_design ); *buffer.inaddr_ptr++ = INADDR_RND ( co->ospf.hello_backup ); /* Dealing with neighbor address(es). */ /* NOTE: Assume co->ospf.neighbor > 0. */ counter = 0; while ( counter < co->ospf.neighbor ) *buffer.inaddr_ptr++ = INADDR_RND ( co->ospf.address[counter++] ); break; case OSPF_TYPE_DD: /* * OSPF Version 2 (RFC 2328) * * A.3.3 The Database Description packet * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Interface MTU | Options |0|0|0|0|0|I|M|MS * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | DD sequence number | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | | * +- -+ * | | * +- An LSA Header -+ * | | * +- -+ * | | * +- -+ * | | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ *buffer.word_ptr++ = __RND ( co->ospf.dd_mtu ); *buffer.byte_ptr++ = ospf_options; *buffer.byte_ptr++ = __RND ( co->ospf.dd_dbdesc ); *buffer.dword_ptr++ = __RND ( co->ospf.dd_sequence ); break; case OSPF_TYPE_LSREQUEST: /* * OSPF Version 2 (RFC 2328) * * A.3.4 The Link State Request packet * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | LS type | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Link State ID | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Advertising Router | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ *buffer.dword_ptr++ = htonl ( co->ospf.lsa_type ); // lsa_type is a 8 bit value. *buffer.dword_ptr++ = __RND ( co->ospf.lsa_lsid ); *buffer.inaddr_ptr++ = INADDR_RND ( co->ospf.lsa_router ); break; case OSPF_TYPE_LSUPDATE: /* * OSPF Version 2 (RFC 2328) * * A.3.5 The Link State Update packet * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | # LSAs | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | | * +- +-+ * | LSAs | * +- +-+ * | ... | */ *buffer.inaddr_ptr++ = htonl ( 1 ); //break; case OSPF_TYPE_LSACK: /* * OSPF Version 2 (RFC 2328) * * A.3.6 The Link State Acknowledgment packet * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | | * +- -+ * | | * +- An LSA Header -+ * | | * +- -+ * | | * +- -+ * | | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ /* Going to the OSPF LSA Header and building it. */ goto build_ospf_lsa; } /* * OSPF Version 2 (RFC 2328) * * A.3.3 The Database Description packet * * The rest of the packet consists of a (possibly partial) list of the * link-state database's pieces. Each LSA in the database is described * by its LSA header. The LSA header is documented in Section A.4.1. * It contains all the information required to uniquely identify both * the LSA and the LSA's current instance. */ build_ospf_lsupdate: if ( co->ospf.type == OSPF_TYPE_DD ) { if ( co->ospf.dd_include_lsa ) { /* OSPF LSA Header structure making a pointer to Checksum. */ build_ospf_lsa: ospf_lsa = buffer.ptr; ospf_lsa->age = __RND ( co->ospf.lsa_age ); /* Deciding whether age or not. */ if ( co->ospf.lsa_dage ) ospf_lsa->age |= 0x80; ospf_lsa->type = co->ospf.lsa_type; ospf_lsa->options = ospf_options; ospf_lsa->lsid = INADDR_RND ( co->ospf.lsa_lsid ); ospf_lsa->router = INADDR_RND ( co->ospf.lsa_router ); ospf_lsa->sequence = __RND ( co->ospf.lsa_sequence ); ospf_lsa->check = 0; buffer.ptr = ospf_lsa + 1; /* Returning to the OSPF type LSUpdate and continue builing it. */ if ( co->ospf.type == OSPF_TYPE_LSUPDATE ) { ospf_lsupdate ( co, &buffer.ptr, ospf_lsa ); goto build_ospf_lsupdate; } /* * At this point, the code does not need to build the entiry LSA Type * Header. It just needs to set the correct OSPF LSA Header length. */ switch ( co->ospf.lsa_type ) { case LSA_TYPE_ROUTER: ospf_lsa->length = co->ospf.length ? co->ospf.length : htons ( LSA_TLEN_ROUTER ); break; case LSA_TYPE_NETWORK: ospf_lsa->length = co->ospf.length ? co->ospf.length : htons ( LSA_TLEN_NETWORK ); break; case LSA_TYPE_SUMMARY_IP: case LSA_TYPE_SUMMARY_AS: ospf_lsa->length = co->ospf.length ? co->ospf.length : htons ( LSA_TLEN_SUMMARY ); break; case LSA_TYPE_ASBR: case LSA_TYPE_NSSA: ospf_lsa->length = co->ospf.length ? co->ospf.length : htons ( LSA_TLEN_ASBR ); break; case LSA_TYPE_MULTICAST: ospf_lsa->length = co->ospf.length ? co->ospf.length : htons ( LSA_TLEN_MULTICAST ); break; default: ospf_lsa->length = co->ospf.length ? co->ospf.length : htons ( LSA_TLEN_GENERIC ( 0 ) ); } ospf_lsa->length = htons ( ospf_lsa->length ); /* Computing the checksum. */ ospf_lsa->check = co->bogus_csum ? RANDOM() : htons ( cksum ( ospf_lsa, LSA_TLEN_GENERIC ( 0 ) ) ); } } /* * The Authentication key uses HMAC-MD5 or HMAC-SHA-1 digest. */ stemp = auth_hmac_md5_len ( co->ospf.auth ); /* NOTE: Assume stemp > 0. */ counter = 0; while ( counter++ < stemp ) *buffer.byte_ptr++ = RANDOM(); /* * OSPF Link-Local Signaling (RFC 5613) * * 2.1. L-Bit in Options Field * * The L-bit MUST NOT be set except in Hello and DD packets that contain * an LLS block. */ if ( co->ospf.type == OSPF_TYPE_HELLO || co->ospf.type == OSPF_TYPE_DD ) { if ( lls ) { /* OSPF LLS TLVs structure making a pointer to Checksum. */ ospf_lls = buffer.ptr; ospf_lls->length = htons ( co->ospf.length ? co->ospf.length : ospf_tlv_len ( co->ospf.type, lls, co->ospf.auth ) / 4 ); ospf_lls->check = 0; buffer.ptr = ospf_lls + 1; /* * OSPF Link-Local Signaling (RFC 5613) * * 2.4. Extended Options and Flags TLV * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | 1 | 4 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Extended Options and Flags | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ *buffer.word_ptr++ = htons ( OSPF_TLV_EXTENDED ); *buffer.word_ptr++ = htons ( OSPF_LEN_EXTENDED ); *buffer.dword_ptr++ = htonl ( co->ospf.lls_options ); // byte swap is made here, not in config.c /* * OSPF Link-Local Signaling (RFC 5613) * * 2.2. LLS Data Block * * Note that if the OSPF packet is cryptographically authenticated, the * LLS data block MUST also be cryptographically authenticated. */ if ( co->ospf.auth ) { /* * OSPF Link-Local Signaling (RFC 5613) * * 2.5. Cryptographic Authentication TLV (OSPFv2 ONLY) * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | 2 | AuthLen | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Sequence Number | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | | * . . * . AuthData . * . . * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * * This document defines a special TLV that is used for cryptographic * authentication (CA-TLV) of the LLS data block. This TLV MUST only * be included in the LLS block when cryptographic authentication is * enabled on the corresponding interface. * * The CA-TLV MUST NOT appear more than once in the LLS block. Also, * when present, this TLV MUST be the last TLV in the LLS block. If * it appears more than once, only the first occurrence is processed * and any others MUST be ignored. */ *buffer.word_ptr++ = htons ( OSPF_TLV_CRYPTO ); *buffer.word_ptr++ = htons ( OSPF_LEN_CRYPTO ); *buffer.dword_ptr++ = __RND ( co->ospf.sequence ); /* * The Authentication key uses HMAC-MD5 or HMAC-SHA-1 digest. */ stemp = auth_hmac_md5_len ( co->ospf.auth ); /* NOTE: Assume stemp > 0. */ counter = 0; while ( counter++ < stemp ) *buffer.byte_ptr++ = RANDOM(); /* * OSPF Link-Local Signaling (RFC 5613) * * 2.2. LLS Data Block * * Note that if the OSPF packet is cryptographically authenticated, the * LLS data block MUST also be cryptographically authenticated. In this * case, the regular LLS checksum is not calculated, but is instead set * to 0. */ } else { /* Computing the checksum. */ ospf_lls->check = co->bogus_csum ? RANDOM() : htons ( cksum ( ospf_lls, ospf_tlv_len ( co->ospf.type, lls, co->ospf.auth ) ) ); } } } /* * OSPF Version 2 (RFC 2328) * * D.4.3 Generating Cryptographic authentication * * (2) The checksum field in the standard OSPF header is not * calculated, but is instead set to 0. */ if ( !co->ospf.auth ) /* Computing the checksum. */ ospf->check = co->bogus_csum ? RANDOM() : htons ( cksum ( ospf, ( size_t ) buffer.ptr - ( size_t ) ospf ) ); gre_checksum ( packet, co, *size ); } /* OSPF header size calculation. */ size_t ospf_hdr_len ( uint32_t type, int neighbor, int lsa_type, int dd_include_lsa ) { size_t size; /* * The code starts with size '0' and it accumulates all the required * size if the conditionals match. Otherwise, it returns size '0'. */ size = 0; switch ( type ) { /* * The size of a HELLO Message Type may vary based on the presence * of neighbor address and the number of neighbor address(es). */ case OSPF_TYPE_HELLO: size += OSPF_TLEN_HELLO + OSPF_TLEN_NEIGHBOR ( neighbor ); break; /* * The size of a Database Description (DD) Message Type may vary * based on the presence of a LSA Header, depending on the case, * it may or may not be included. */ case OSPF_TYPE_DD: size += OSPF_TLEN_DD; if ( dd_include_lsa ) size += LSA_TLEN_GENERIC ( 0 ); break; case OSPF_TYPE_LSREQUEST: size += OSPF_TLEN_LSREQUEST; break; /* * The size of a LS Update Message Type may vary based on the type * of the LSA Header included in the message. */ case OSPF_TYPE_LSUPDATE: size += OSPF_TLEN_LSUPDATE; switch ( lsa_type ) { case LSA_TYPE_ROUTER: size += LSA_TLEN_ROUTER; break; case LSA_TYPE_NETWORK: size += LSA_TLEN_NETWORK; break; case LSA_TYPE_SUMMARY_IP: case LSA_TYPE_SUMMARY_AS: size += LSA_TLEN_SUMMARY; break; case LSA_TYPE_ASBR: size += LSA_TLEN_ASBR; break; case LSA_TYPE_MULTICAST: size += LSA_TLEN_MULTICAST; break; case LSA_TYPE_NSSA: size += LSA_TLEN_NSSA; break; default: size += LSA_TLEN_GENERIC ( 0 ); } break; case OSPF_TYPE_LSACK: size += LSA_TLEN_GENERIC ( 0 ); break; } return size; } void ospf_lsupdate ( const config_options_T *const restrict co, void **restrict ptr, struct ospf_lsa_hdr *restrict ospf_lsa ) { memptr_T buffer; buffer.ptr = *ptr; if ( co->ospf.lsa_type == LSA_TYPE_ROUTER ) { /* Setting the correct OSPF LSA Header length. */ ospf_lsa->length = htons ( co->ospf.length ? co->ospf.length : LSA_TLEN_ROUTER ); /* * The OSPF Not-So-Stubby Area (NSSA) Option (RFC 3101) * * Appendix B: Router-LSAs * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | 0 Nt|W|V|E|B| 0 | # links | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Link ID | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Link Data | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Type | # TOS | metric | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ *buffer.byte_ptr++ = __RND ( co->ospf.lsa_flags ); *buffer.byte_ptr++ = FIELD_MUST_BE_ZERO; *buffer.word_ptr++ = htons ( 1 ); *buffer.inaddr_ptr++ = INADDR_RND ( co->ospf.lsa_link_id ); *buffer.inaddr_ptr++ = NETMASK_RND ( co->ospf.lsa_link_data ); *buffer.byte_ptr++ = __RND ( co->ospf.lsa_link_type ); *buffer.byte_ptr++ = FIELD_MUST_BE_ZERO; *buffer.word_ptr++ = __RND ( co->ospf.lsa_metric ); /* Computing the checksum. */ ospf_lsa->check = co->bogus_csum ? RANDOM() : htons ( cksum ( ospf_lsa, OSPF_TLEN_LSUPDATE + LSA_TLEN_ROUTER ) ); } else if ( co->ospf.lsa_type == LSA_TYPE_NETWORK ) { /* Setting the correct OSPF LSA Header length. */ ospf_lsa->length = htons ( co->ospf.length ? co->ospf.length : LSA_TLEN_NETWORK ); /* * OSPF Version 2 (RFC 2328) * * A.4.3 Network-LSAs * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Network Mask | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Attached Router | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ *buffer.inaddr_ptr++ = NETMASK_RND ( co->ospf.netmask ); *buffer.inaddr_ptr++ = INADDR_RND ( co->ospf.lsa_attached ); /* Computing the checksum. */ ospf_lsa->check = co->bogus_csum ? RANDOM() : htons ( cksum ( ospf_lsa, OSPF_TLEN_LSUPDATE + LSA_TLEN_NETWORK ) ); } else if ( co->ospf.lsa_type == LSA_TYPE_SUMMARY_IP || co->ospf.lsa_type == LSA_TYPE_SUMMARY_AS ) { /* Setting the correct OSPF LSA Header length. */ ospf_lsa->length = htons ( co->ospf.length ? co->ospf.length : LSA_TLEN_SUMMARY ); /* * OSPF Version 2 (RFC 2328) * * A.4.4 Summary-LSAs * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Network Mask | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | 0 | metric | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ *buffer.inaddr_ptr++ = NETMASK_RND ( co->ospf.netmask ); *buffer.byte_ptr++ = FIELD_MUST_BE_ZERO; { uint32_t temp; if ( co->ospf.lsa_metric ) temp = co->ospf.lsa_metric; else temp = RANDOM(); *buffer.dword_ptr++ = htonl ( temp << 8 ); // Lower bits of "metric" are always 0? } buffer.ptr--; /* hack! */ /* Computing the checksum. */ ospf_lsa->check = co->bogus_csum ? RANDOM() : htons ( cksum ( ospf_lsa, OSPF_TLEN_LSUPDATE + LSA_TLEN_SUMMARY ) ); } else if ( co->ospf.lsa_type == LSA_TYPE_ASBR || co->ospf.lsa_type == LSA_TYPE_NSSA ) { /* Setting the correct OSPF LSA Header length. */ ospf_lsa->length = htons ( co->ospf.length ? co->ospf.length : LSA_TLEN_ASBR ); /* * OSPF Version 2 (RFC 2328) * * A.4.5 AS-external-LSAs * * The OSPF NSSA Option (RFC 1587) * * Appendix A: Type-7 Packet Format * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Network Mask | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * |E| 0 | metric | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Forwarding address | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | External Route Tag | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ *buffer.inaddr_ptr++ = NETMASK_RND ( co->ospf.netmask ); *buffer.byte_ptr++ = ( co->ospf.lsa_larger ? 0x80 : 0 ); { uint32_t temp; if ( co->ospf.lsa_metric ) temp = co->ospf.lsa_metric; else temp = RANDOM(); *buffer.dword_ptr++ = htonl ( temp << 8 ); // lower bits always zero? } buffer.ptr--; /* hack! */ *buffer.inaddr_ptr++ = INADDR_RND ( co->ospf.lsa_forward ); *buffer.dword_ptr++ = __RND ( co->ospf.lsa_external ); /* Computing the checksum. */ ospf_lsa->check = co->bogus_csum ? RANDOM() : htons ( cksum ( ospf_lsa, OSPF_TLEN_LSUPDATE + LSA_TLEN_ASBR ) ); } else if ( co->ospf.lsa_type == LSA_TYPE_MULTICAST ) { /* Setting the correct OSPF LSA Header length. */ ospf_lsa->length = htons ( co->ospf.length ? co->ospf.length : LSA_TLEN_MULTICAST ); /* * Multicast Extensions to OSPF (RFC 1584) * * A.3 Group-membership-LSA * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Vertex type | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Vertex ID | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ *buffer.dword_ptr++ = __RND ( co->ospf.vertex_type ); *buffer.inaddr_ptr++ = INADDR_RND ( co->ospf.vertex_id ); /* Computing the checksum. */ ospf_lsa->check = co->bogus_csum ? RANDOM() : htons ( cksum ( ospf_lsa, OSPF_TLEN_LSUPDATE + LSA_TLEN_MULTICAST ) ); /* Building a generic OSPF LSA Header. */ } else { /* Setting the correct OSPF LSA Header length. */ ospf_lsa->length = htons ( co->ospf.length ? co->ospf.length : LSA_TLEN_GENERIC ( 0 ) ); /* Computing the checksum. */ ospf_lsa->check = co->bogus_csum ? RANDOM() : htons ( cksum ( ospf_lsa, OSPF_TLEN_LSUPDATE + LSA_TLEN_GENERIC ( 0 ) ) ); } *ptr = buffer.ptr; } src/modules/udp.c0000664000175000017500000000544014107315014014740 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /** @file udp.c */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2019 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include #include #include #include /** * UDP packet header configuration. * * Configures the UDP packet header. * A pointer to this function will be on modules table. * * @param co Pointer to T50 configuration structure. * @param size Pointer to packet size (updated by the function). */ void udp ( const config_options_T * const restrict co, size_t * restrict size ) { size_t length; struct iphdr *ip; struct iphdr *gre_ip; struct udphdr *udp; struct psdhdr *pseudo; assert ( co != NULL ); length = gre_opt_len ( co ); *size = sizeof ( struct iphdr ) + sizeof ( struct udphdr ) + sizeof ( struct psdhdr ) + length; /* Try to reallocate packet, if necessary */ alloc_packet ( *size ); /* Fill IP header. */ ip = ip_header ( packet, *size, co ); gre_ip = gre_encapsulation ( packet, co, sizeof ( struct iphdr ) + sizeof ( struct udphdr ) ); /* UDP Header structure making a pointer to IP Header structure. */ udp = ( void * ) ( ip + 1 ) + length; udp->source = IPPORT_RND ( co->source ); udp->dest = IPPORT_RND ( co->dest ); udp->len = htons ( sizeof ( struct udphdr ) ); udp->check = 0; /* needed 'cause of cksum(), below! */ /* Fill PSEUDO Header structure. */ pseudo = ( struct psdhdr * ) ( udp + 1 ); if ( co->encapsulated ) { pseudo->saddr = gre_ip->saddr; pseudo->daddr = gre_ip->daddr; } else { pseudo->saddr = ip->saddr; pseudo->daddr = ip->daddr; } pseudo->zero = 0; pseudo->protocol = co->ip.protocol; pseudo->len = htons ( sizeof ( struct udphdr ) ); /* Computing the checksum. */ udp->check = co->bogus_csum ? RANDOM() : htons ( cksum ( udp, ( size_t ) ( pseudo + 1 ) - ( size_t ) udp ) ); gre_checksum ( packet, co, *size ); } src/modules/rsvp.c0000644000175000017500000006675113712774300015164 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /** @file rsvp.c */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2019 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include #include #include #include #include static size_t rsvp_objects_len ( const uint8_t, const uint8_t, const uint8_t, const uint8_t ); /** * RSVP packet header configuration. * * This function configures and sends the RSVP packet header. * * @param co Pointer to T50 configuration structure. * @param size Pointer to packet size (updated by the function). */ void rsvp ( const config_options_T *const restrict co, size_t *restrict size ) { size_t greoptlen, /* GRE options size. */ objects_length; /* RSVP objects length. */ /* Packet and Checksum. */ memptr_T buffer; struct iphdr *ip; /* RSVP Common header. */ struct rsvp_common_hdr *rsvp; assert ( co != NULL ); greoptlen = gre_opt_len ( co ); objects_length = rsvp_objects_len ( co->rsvp.type, co->rsvp.scope, co->rsvp.adspec, co->rsvp.tspec ); *size = sizeof ( struct iphdr ) + sizeof ( struct rsvp_common_hdr ) + greoptlen + objects_length; /* Try to reallocate the packet, if necessary */ alloc_packet ( *size ); /* IP Header structure making a pointer to Packet. */ ip = ip_header ( packet, *size, co ); /* GRE Encapsulation takes place. */ gre_encapsulation ( packet, co, sizeof ( struct iphdr ) + sizeof ( struct rsvp_common_hdr ) + objects_length ); /* RSVP Header structure making a pointer to IP Header structure. */ rsvp = ( void * ) ( ip + 1 ) + greoptlen; rsvp->flags = __RND ( co->rsvp.flags ); rsvp->version = RSVPVERSION; rsvp->type = co->rsvp.type; rsvp->ttl = __RND ( co->rsvp.ttl ); rsvp->length = htons ( sizeof ( struct rsvp_common_hdr ) + objects_length ); rsvp->reserved = FIELD_MUST_BE_ZERO; rsvp->check = 0; buffer.ptr = rsvp + 1; /* * The SESSION Object Class is present for all RSVP Messages. * * Resource ReSerVation Protocol (RSVP) (RFC 2205) * * A.1 SESSION Class * * SESSION Class = 1. * * o IPv4/UDP SESSION object: Class = 1, C-Type = 1 * * +-------------+-------------+-------------+-------------+ * | IPv4 DestAddress (4 bytes) | * +-------------+-------------+-------------+-------------+ * | Protocol Id | Flags | DstPort | * +-------------+-------------+-------------+-------------+ */ *buffer.word_ptr++ = htons ( RSVP_LENGTH_SESSION ); *buffer.byte_ptr++ = RSVP_OBJECT_SESSION; *buffer.byte_ptr++ = 1; *buffer.inaddr_ptr++ = INADDR_RND ( co->rsvp.session_addr ); *buffer.byte_ptr++ = __RND ( co->rsvp.session_proto ); *buffer.byte_ptr++ = __RND ( co->rsvp.session_flags ); *buffer.word_ptr++ = __RND ( co->rsvp.session_port ); /* * The RESV_HOP Object Class is present for the following: * 3.1.3 Path Messages * 3.1.4 Resv Messages * 3.1.5 Path Teardown Messages * 3.1.6 Resv Teardown Messages * 3.1.8 Resv Error Messages */ if ( co->rsvp.type == RSVP_MESSAGE_TYPE_PATH || co->rsvp.type == RSVP_MESSAGE_TYPE_RESV || co->rsvp.type == RSVP_MESSAGE_TYPE_PATHTEAR || co->rsvp.type == RSVP_MESSAGE_TYPE_RESVTEAR || co->rsvp.type == RSVP_MESSAGE_TYPE_RESVERR ) { /* * Resource ReSerVation Protocol (RSVP) (RFC 2205) * * A.2 RSVP_HOP Class * * RSVP_HOP class = 3. * * o IPv4 RSVP_HOP object: Class = 3, C-Type = 1 * * +-------------+-------------+-------------+-------------+ * | IPv4 Next/Previous Hop Address | * +-------------+-------------+-------------+-------------+ * | Logical Interface Handle | * +-------------+-------------+-------------+-------------+ */ *buffer.word_ptr++ = htons ( RSVP_LENGTH_RESV_HOP ); *buffer.byte_ptr++ = RSVP_OBJECT_RESV_HOP; *buffer.byte_ptr++ = 1; *buffer.inaddr_ptr++ = INADDR_RND ( co->rsvp.hop_addr ); *buffer.dword_ptr++ = __RND ( co->rsvp.hop_iface ); } /* * The TIME_VALUES Object Class is present for the following: * 3.1.3 Path Messages * 3.1.4 Resv Messages */ if ( co->rsvp.type == RSVP_MESSAGE_TYPE_PATH || co->rsvp.type == RSVP_MESSAGE_TYPE_RESV ) { /* * Resource ReSerVation Protocol (RSVP) (RFC 2205) * * A.4 TIME_VALUES Class * * TIME_VALUES class = 5. * * o TIME_VALUES Object: Class = 5, C-Type = 1 * * +-------------+-------------+-------------+-------------+ * | Refresh Period R | * +-------------+-------------+-------------+-------------+ */ *buffer.word_ptr++ = htons ( RSVP_LENGTH_TIME_VALUES ); *buffer.byte_ptr++ = RSVP_OBJECT_TIME_VALUES; *buffer.byte_ptr++ = 1; *buffer.dword_ptr++ = __RND ( co->rsvp.time_refresh ); } /* * The ERROR_SPEC Object Class is present for the following: * 3.1.5 Path Teardown Messages * 3.1.8 Resv Error Messages * 3.1.9 Confirmation Messages */ if ( co->rsvp.type == RSVP_MESSAGE_TYPE_PATHERR || co->rsvp.type == RSVP_MESSAGE_TYPE_RESVERR || co->rsvp.type == RSVP_MESSAGE_TYPE_RESVCONF ) { /* * Resource ReSerVation Protocol (RSVP) (RFC 2205) * * A.5 ERROR_SPEC Class * * ERROR_SPEC class = 6. * * o IPv4 ERROR_SPEC object: Class = 6, C-Type = 1 * * +-------------+-------------+-------------+-------------+ * | IPv4 Error Node Address (4 bytes) | * +-------------+-------------+-------------+-------------+ * | Flags | Error Code | Error Value | * +-------------+-------------+-------------+-------------+ */ *buffer.word_ptr++ = htons ( RSVP_LENGTH_ERROR_SPEC ); *buffer.byte_ptr++ = RSVP_OBJECT_ERROR_SPEC; *buffer.byte_ptr++ = 1; *buffer.inaddr_ptr++ = INADDR_RND ( co->rsvp.error_addr ); *buffer.byte_ptr++ = __RND ( co->rsvp.error_flags ); *buffer.byte_ptr++ = __RND ( co->rsvp.error_code ); *buffer.word_ptr++ = __RND ( co->rsvp.error_value ); } /* * The SENDER_TEMPLATE, SENDER_TSPEC and ADSPEC Object Classes are * present for the following: * 3.1.3 Path Messages * 3.1.5 Path Teardown Messages * 3.1.7 Path Error Messages */ if ( co->rsvp.type == RSVP_MESSAGE_TYPE_PATH || co->rsvp.type == RSVP_MESSAGE_TYPE_PATHTEAR || co->rsvp.type == RSVP_MESSAGE_TYPE_PATHERR ) { /* * Resource ReSerVation Protocol (RSVP) (RFC 2205) * * A.10 SENDER_TEMPLATE Class * * SENDER_TEMPLATE class = 11. * * o IPv4 SENDER_TEMPLATE object: Class = 11, C-Type = 1 * * Definition same as IPv4/UDP FILTER_SPEC object. * * RSVP Extensions for IPSEC (RFC 2207) * * 3.3 SENDER_TEMPLATE Class * * SENDER_TEMPLATE class = 11. * * o IPv4/GPI SENDER_TEMPLATE object: Class = 11, C-Type = 4 * * Definition same as IPv4/GPI FILTER_SPEC object. */ *buffer.word_ptr++ = htons ( RSVP_LENGTH_SENDER_TEMPLATE ); *buffer.byte_ptr++ = RSVP_OBJECT_SENDER_TEMPLATE; *buffer.byte_ptr++ = 1; *buffer.inaddr_ptr++ = INADDR_RND ( co->rsvp.sender_addr ); *buffer.word_ptr++ = FIELD_MUST_BE_ZERO; *buffer.word_ptr++ = __RND ( co->rsvp.sender_port ); /* * Resource ReSerVation Protocol (RSVP) (RFC 2205) * * A.11 SENDER_TSPEC Class * * SENDER_TSPEC class = 12. * * o Intserv SENDER_TSPEC object: Class = 12, C-Type = 2 * * The contents and encoding rules for this object are specified * in documents prepared by the int-serv working group. */ *buffer.word_ptr++ = htons ( RSVP_LENGTH_SENDER_TSPEC + TSPEC_SERVICES ( co->rsvp.tspec ) ); *buffer.byte_ptr++ = RSVP_OBJECT_SENDER_TSPEC; *buffer.byte_ptr++ = 2; /* * The Use of RSVP with IETF Integrated Services (RFC 2210) * * 3.1. RSVP SENDER_TSPEC Object * * 31 24 23 16 15 8 7 0 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * 1 | 0 (a) | reserved | 7 (b) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * 2 | 1 (c) |0| reserved | 6 (d) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * 3 | 127 (e) | 0 (f) | 5 (g) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * 4 | Token Bucket Rate [r] (32-bit IEEE floating point number) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * 5 | Token Bucket Size [b] (32-bit IEEE floating point number) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * 6 | Peak Data Rate [p] (32-bit IEEE floating point number) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * 7 | Minimum Policed Unit [m] (32-bit integer) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * 8 | Maximum Packet Size [M] (32-bit integer) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ *buffer.word_ptr++ = FIELD_MUST_BE_ZERO; *buffer.word_ptr++ = htons ( ( TSPEC_SERVICES ( co->rsvp.tspec ) - RSVP_LENGTH_SENDER_TSPEC ) / 4 ); *buffer.byte_ptr++ = co->rsvp.tspec; *buffer.byte_ptr++ = FIELD_MUST_BE_ZERO; *buffer.word_ptr++ = htons ( TSPEC_SERVICES ( co->rsvp.tspec ) / 4 ); /* Identifying the RSVP TSPEC and building it. */ switch ( co->rsvp.tspec ) { case TSPEC_TRAFFIC_SERVICE: case TSPEC_GUARANTEED_SERVICE: *buffer.byte_ptr++ = TSPECT_TOKEN_BUCKET_SERVICE; *buffer.byte_ptr++ = FIELD_MUST_BE_ZERO; *buffer.word_ptr++ = htons ( ( TSPEC_SERVICES ( co->rsvp.tspec ) - TSPEC_MESSAGE_HEADER ) / 4 ); *buffer.dword_ptr++ = __RND ( co->rsvp.tspec_r ); *buffer.dword_ptr++ = __RND ( co->rsvp.tspec_b ); *buffer.dword_ptr++ = __RND ( co->rsvp.tspec_p ); *buffer.dword_ptr++ = __RND ( co->rsvp.tspec_m ); *buffer.dword_ptr++ = __RND ( co->rsvp.tspec_M ); } /* * Resource ReSerVation Protocol (RSVP) (RFC 2205) * * A.12 ADSPEC Class * * ADSPEC class = 13. * * o Intserv ADSPEC object: Class = 13, C-Type = 2 * * The contents and format for this object are specified in * documents prepared by the int-serv working group. */ *buffer.word_ptr++ = htons ( RSVP_LENGTH_ADSPEC + ADSPEC_SERVICES ( co->rsvp.adspec ) ); *buffer.byte_ptr++ = RSVP_OBJECT_ADSPEC; *buffer.byte_ptr++ = 2; /* * The Use of RSVP with IETF Integrated Services (RFC 2210) * * 3.3.1. RSVP ADSPEC format * * 31 24 23 16 15 8 7 0 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | 0 (a) | reserved | Msg length - 1 (b) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | | * | Default General Parameters fragment (Service 1) (c) | * | (Always Present) | * | | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | | * | Guaranteed Service Fragment (Service 2) (d) | * | (Present if application might use Guaranteed Service) | * | | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | | * | Controlled-Load Service Fragment (Service 5) (e) | * | (Present if application might use Controlled-Load Service) | * | | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ *buffer.word_ptr++ = FIELD_MUST_BE_ZERO; *buffer.word_ptr++ = htons ( ( ADSPEC_SERVICES ( co->rsvp.adspec ) - ADSPEC_MESSAGE_HEADER ) / 4 ); /* * The Use of RSVP with IETF Integrated Services (RFC 2210) * * 3.3.2. Default General Characterization Parameters ADSPEC data fragment * * 31 24 23 16 15 8 7 0 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * 1 | 1 (c) |x| reserved | 8 (d) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * 2 | 4 (e) | (f) | 1 (g) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * 3 | IS hop cnt (32-bit unsigned integer) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * 4 | 6 (h) | (i) | 1 (j) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * 5 | Path b/w estimate (32-bit IEEE floating point number) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * 6 | 8 (k) | (l) | 1 (m) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * 7 | Minimum path latency (32-bit integer) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * 8 | 10 (n) | (o) | 1 (p) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * 9 | Composed MTU (32-bit unsigned integer) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ *buffer.byte_ptr++ = ADSPEC_PARAMETER_SERVICE; *buffer.byte_ptr++ = FIELD_MUST_BE_ZERO; *buffer.word_ptr++ = htons ( ( ADSPEC_PARAMETER_LENGTH - ADSPEC_MESSAGE_HEADER ) / 4 ); *buffer.byte_ptr++ = ADSPEC_PARAMETER_ISHOPCNT; *buffer.byte_ptr++ = FIELD_MUST_BE_ZERO; *buffer.word_ptr++ = htons ( ADSPEC_SERVDATA_HEADER / 4 ); *buffer.dword_ptr++ = __RND ( co->rsvp.adspec_hop ); *buffer.byte_ptr++ = ADSPEC_PARAMETER_BANDWIDTH; *buffer.byte_ptr++ = FIELD_MUST_BE_ZERO; *buffer.word_ptr++ = htons ( ADSPEC_SERVDATA_HEADER / 4 ); *buffer.dword_ptr++ = __RND ( co->rsvp.adspec_path ); *buffer.byte_ptr++ = ADSPEC_PARAMETER_LATENCY; *buffer.byte_ptr++ = FIELD_MUST_BE_ZERO; *buffer.word_ptr++ = htons ( ADSPEC_SERVDATA_HEADER / 4 ); *buffer.dword_ptr++ = __RND ( co->rsvp.adspec_minimum ); *buffer.byte_ptr++ = ADSPEC_PARAMETER_COMPMTU; *buffer.byte_ptr++ = FIELD_MUST_BE_ZERO; *buffer.word_ptr++ = htons ( ADSPEC_SERVDATA_HEADER / 4 ); *buffer.dword_ptr++ = __RND ( co->rsvp.adspec_mtu ); /* Identifying the ADSPEC and building it. */ switch ( co->rsvp.adspec ) { case ADSPEC_GUARANTEED_SERVICE: case ADSPEC_CONTROLLED_SERVICE: /* * The Use of RSVP with IETF Integrated Services (RFC 2210) * * 3.3.3. Guaranteed Service ADSPEC data fragment * * 31 24 23 16 15 8 7 0 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * 1 | 2 (a) |x| reserved | N-1 (b) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * 2 | 133 (c) | 0 (d) | 1 (e) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * 3 | End-to-end composed value for C [Ctot] (32-bit integer) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * 4 | 134 (f) | (g) | 1 (h) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * 5 | End-to-end composed value for D [Dtot] (32-bit integer) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * 6 | 135 (i) | (j) | 1 (k) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * 7 | Since-last-reshaping point composed C [Csum] (32-bit integer) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * 8 | 136 (l) | (m) | 1 (n) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * 9 | Since-last-reshaping point composed D [Dsum] (32-bit integer) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * 10 | Service-specific general parameter headers/values, if present | * . +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * . * N | | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ *buffer.byte_ptr++ = ADSPEC_GUARANTEED_SERVICE; *buffer.byte_ptr++ = FIELD_MUST_BE_ZERO; *buffer.word_ptr++ = htons ( ( ADSPEC_GUARANTEED_LENGTH - ADSPEC_MESSAGE_HEADER ) / 4 ); *buffer.byte_ptr++ = 133; *buffer.byte_ptr++ = FIELD_MUST_BE_ZERO; *buffer.word_ptr++ = htons ( ADSPEC_SERVDATA_HEADER / 4 ); *buffer.dword_ptr++ = __RND ( co->rsvp.adspec_Ctot ); *buffer.byte_ptr++ = 134; *buffer.byte_ptr++ = FIELD_MUST_BE_ZERO; *buffer.word_ptr++ = htons ( ADSPEC_SERVDATA_HEADER / 4 ); *buffer.dword_ptr++ = __RND ( co->rsvp.adspec_Dtot ); *buffer.byte_ptr++ = 135; *buffer.byte_ptr++ = FIELD_MUST_BE_ZERO; *buffer.word_ptr++ = htons ( ADSPEC_SERVDATA_HEADER / 4 ); *buffer.dword_ptr++ = __RND ( co->rsvp.adspec_Csum ); *buffer.byte_ptr++ = 136; *buffer.byte_ptr++ = FIELD_MUST_BE_ZERO; *buffer.word_ptr++ = htons ( ADSPEC_SERVDATA_HEADER / 4 ); *buffer.dword_ptr++ = __RND ( co->rsvp.adspec_Dsum ); /* Going to the next ADSPEC, if it needs to do sco-> */ if ( co->rsvp.adspec == ADSPEC_CONTROLLED_SERVICE ) { /* * The Use of RSVP with IETF Integrated Services (RFC 2210) * * 3.3.4. Controlled-Load Service ADSPEC data fragment * * 31 24 23 16 15 8 7 0 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * 1 | 5 (a) |x| (b) | N-1 (c) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * 2 | Service-specific general parameter headers/values, if present | * . +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * . * N | | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ *buffer.byte_ptr++ = ADSPEC_CONTROLLED_SERVICE; *buffer.byte_ptr++ = FIELD_MUST_BE_ZERO; *buffer.word_ptr++ = htons ( ADSPEC_CONTROLLED_LENGTH - ADSPEC_MESSAGE_HEADER ); } } } /* * The RESV_CONFIRM Object Class is present for the following: * 3.1.4 Resv Messages * 3.1.9 Confirmation Messages */ if ( co->rsvp.type == RSVP_MESSAGE_TYPE_RESV || co->rsvp.type == RSVP_MESSAGE_TYPE_RESVCONF ) { /* * Resource ReSerVation Protocol (RSVP) (RFC 2205) * * A.14 Resv_CONFIRM Class * * RESV_CONFIRM class = 15. * * o IPv4 RESV_CONFIRM object: Class = 15, C-Type = 1 * * +-------------+-------------+-------------+-------------+ * | IPv4 Receiver Address (4 bytes) | * +-------------+-------------+-------------+-------------+ */ *buffer.word_ptr++ = htons ( RSVP_LENGTH_RESV_CONFIRM ); *buffer.byte_ptr++ = RSVP_OBJECT_RESV_CONFIRM; *buffer.byte_ptr++ = 1; *buffer.inaddr_ptr++ = INADDR_RND ( co->rsvp.confirm_addr ); } /* * The STYLE Object Classes is present for the following: * 3.1.4 Resv Messages * 3.1.6 Resv Teardown Messages * 3.1.8 Resv Error Messages * 3.1.9 Confirmation Messages */ if ( co->rsvp.type == RSVP_MESSAGE_TYPE_RESV || co->rsvp.type == RSVP_MESSAGE_TYPE_RESVTEAR || co->rsvp.type == RSVP_MESSAGE_TYPE_RESVERR || co->rsvp.type == RSVP_MESSAGE_TYPE_RESVCONF ) { /* * The SCOPE Object Classes is present for the following: * 3.1.4 Resv Messages * 3.1.6 Resv Teardown Messages * 3.1.8 Resv Error Messages */ if ( co->rsvp.type == RSVP_MESSAGE_TYPE_RESV || co->rsvp.type == RSVP_MESSAGE_TYPE_RESVTEAR || co->rsvp.type == RSVP_MESSAGE_TYPE_RESVERR ) { uint32_t counter; /* * Resource ReSerVation Protocol (RSVP) (RFC 2205) * * A.6 SCOPE Class * * SCOPE class = 7. * * o IPv4 SCOPE List object: Class = 7, C-Type = 1 * * +-------------+-------------+-------------+-------------+ * | IPv4 Src Address (4 bytes) | * +-------------+-------------+-------------+-------------+ * // // * +-------------+-------------+-------------+-------------+ * | IPv4 Src Address (4 bytes) | * +-------------+-------------+-------------+-------------+ */ *buffer.word_ptr++ = htons ( RSVP_LENGTH_SCOPE ( co->rsvp.scope ) ); *buffer.byte_ptr++ = RSVP_OBJECT_SCOPE; *buffer.byte_ptr++ = 1; /* Dealing with scope address(es). */ /* NOTE: Assume co->rsvp.scope > 0. */ counter = 0; while ( counter < co->rsvp.scope ) *buffer.inaddr_ptr++ = INADDR_RND ( co->rsvp.address[counter++] ); } /* * Resource ReSerVation Protocol (RSVP) (RFC 2205) * * A.7 STYLE Class * * STYLE class = 8. * * o STYLE object: Class = 8, C-Type = 1 * * +-------------+-------------+-------------+-------------+ * | Flags | Option Vector | * +-------------+-------------+-------------+-------------+ */ *buffer.word_ptr++ = htons ( RSVP_LENGTH_STYLE ); *buffer.byte_ptr++ = RSVP_OBJECT_STYLE; *buffer.byte_ptr++ = 1; *buffer.byte_ptr++ = FIELD_MUST_BE_ZERO; { uint32_t temp; if ( co->rsvp.style_opt ) temp = co->rsvp.style_opt; else temp = RANDOM(); *buffer.dword_ptr++ = htonl ( temp << 8 ); // FIXME: FLAGS is always zero? } } /* Computing the checksum. */ rsvp->check = co->bogus_csum ? RANDOM() : htons ( cksum ( rsvp, ( size_t ) buffer.ptr - ( size_t ) rsvp ) ); /* GRE Encapsulation takes place. */ gre_checksum ( packet, co, *size ); } /* RSVP objects size claculation. */ size_t rsvp_objects_len ( const uint8_t type, const uint8_t scope, const uint8_t adspec, const uint8_t tspec ) { size_t size; /* * The code starts with the size of SESSION Object Class (according * to the RFC 2205, this is required in every RSVP message), and, if * the appropriate RSVP Message type matches, size accumulates the * corresponded Object Class(s) size to build the appropriate RSVP * message. Otherwise, it just returns the size of SESSION Object * Class. */ size = RSVP_LENGTH_SESSION; /* * The RESV_HOP Object Class is present for the following: * 3.1.3 Path Messages * 3.1.4 Resv Messages * 3.1.5 Path Teardown Messages * 3.1.6 Resv Teardown Messages * 3.1.8 Resv Error Messages */ if ( type == RSVP_MESSAGE_TYPE_PATH || type == RSVP_MESSAGE_TYPE_RESV || type == RSVP_MESSAGE_TYPE_PATHTEAR || type == RSVP_MESSAGE_TYPE_RESVTEAR || type == RSVP_MESSAGE_TYPE_RESVERR ) size += RSVP_LENGTH_RESV_HOP; /* * The TIME_VALUES Object Class is present for the following: * 3.1.3 Path Messages * 3.1.4 Resv Messages */ if ( type == RSVP_MESSAGE_TYPE_PATH || type == RSVP_MESSAGE_TYPE_RESV ) size += RSVP_LENGTH_TIME_VALUES; /* * The ERROR_SPEC Object Class is present for the following: * 3.1.5 Path Teardown Messages * 3.1.8 Resv Error Messages * 3.1.9 Confirmation Messages */ if ( type == RSVP_MESSAGE_TYPE_PATHERR || type == RSVP_MESSAGE_TYPE_RESVERR || type == RSVP_MESSAGE_TYPE_RESVCONF ) size += RSVP_LENGTH_ERROR_SPEC; /* * The SENDER_TEMPLATE, SENDER_TSPEC and ADSPEC Object Classes are * present for the following: * 3.1.3 Path Messages * 3.1.5 Path Teardown Messages * 3.1.7 Path Error Messages */ if ( type == RSVP_MESSAGE_TYPE_PATH || type == RSVP_MESSAGE_TYPE_PATHTEAR || type == RSVP_MESSAGE_TYPE_PATHERR ) { size += RSVP_LENGTH_SENDER_TEMPLATE; size += RSVP_LENGTH_SENDER_TSPEC; size += TSPEC_SERVICES ( tspec ); size += RSVP_LENGTH_ADSPEC; size += ADSPEC_SERVICES ( adspec ); } /* * The RESV_CONFIRM Object Class is present for the following: * 3.1.4 Resv Messages * 3.1.9 Confirmation Messages */ if ( type == RSVP_MESSAGE_TYPE_RESV || type == RSVP_MESSAGE_TYPE_RESVCONF ) size += RSVP_LENGTH_RESV_CONFIRM; /* * The STYLE Object Classes is present for the following: * 3.1.4 Resv Messages * 3.1.6 Resv Teardown Messages * 3.1.8 Resv Error Messages * 3.1.9 Confirmation Messages */ if ( type == RSVP_MESSAGE_TYPE_RESV || type == RSVP_MESSAGE_TYPE_RESVTEAR || type == RSVP_MESSAGE_TYPE_RESVERR || type == RSVP_MESSAGE_TYPE_RESVCONF ) { /* * The SCOPE Object Classes is present for the following: * 3.1.4 Resv Messages * 3.1.6 Resv Teardown Messages * 3.1.8 Resv Error Messages */ if ( type == RSVP_MESSAGE_TYPE_RESV || type == RSVP_MESSAGE_TYPE_RESVTEAR || type == RSVP_MESSAGE_TYPE_RESVERR ) size += RSVP_LENGTH_SCOPE ( scope ); size += RSVP_LENGTH_STYLE; } return size; } src/help/0000755000175000017500000000000014107315626013270 5ustar fredericofredericosrc/help/egp_help.c0000644000175000017500000000324313712774300015220 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /** @file egp_help.c */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2015 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include /** EGP help */ void egp_help ( void ) { printf ( "EGP Options:\n" " --egp-type NUM EGP type (default %d)\n" " --egp-code NUM EGP code (default %d)\n" " --egp-status NUM EGP status (default %d)\n" " --egp-as NUM EGP autonomous system (default RANDOM)\n" " --egp-sequence NUM EGP sequence # (default RANDOM)\n" " --egp-hello NUM EGP hello interval (default RANDOM)\n" " --egp-poll NUM EGP poll interval (default RANDOM)\n\n", EGP_NEIGHBOR_ACQUISITION, EGP_ACQ_CODE_CEASE_CMD, EGP_ACQ_STAT_ACTIVE_MODE ); } src/help/tcp_udp_dccp_help.c0000644000175000017500000001160213712774300017072 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /** @file tcp_udp_dccp_help.c */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2015 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include /** UDP and DCCP options help. */ void tcp_udp_dccp_help ( void ) { puts ( "DCCP/TCP/UDP Options:\n" " --sport NUM DCCP|TCP|UDP source port (default RANDOM)\n" " --dport NUM DCCP|TCP|UDP destination port (default RANDOM)\n" ); } /** TCP options help. */ void tcp_help ( void ) { printf ( "TCP Options:\n" " --ack-seq NUM TCP ACK sequence # (default RANDOM)\n" " --sequence NUM TCP SYN sequence # (default RANDOM)\n" " --data-offset NUM TCP data offset (default %zu)\n" " -F,--fin TCP FIN flag (default OFF)\n" " -S,--syn TCP SYN flag (default OFF)\n" " -R,--rst TCP RST flag (default OFF)\n" " -P,--psh TCP PSH flag (default OFF)\n" " -A,--ack TCP ACK flag (default OFF)\n" " -U,--urg TCP URG flag (default OFF)\n" " -E,--ece TCP ECE flag (default OFF)\n" " -C,--cwr TCP CWR flag (default OFF)\n" " -W,--window NUM TCP Window size (default NONE)\n" " --urg-pointer NUM TCP URG pointer (default NONE)\n" " --mss NUM TCP Maximum Segment Size (default NONE)\n" " --wscale NUM TCP Window Scale (default NONE)\n" " --tstamp NUM:NUM TCP Timestamp (TSval:TSecr) (default NONE)\n" " --sack-ok TCP SACK-Permitted (default OFF)\n" " --ttcp-cc NUM T/TCP Connection Count (CC) (default NONE)\n" " --ccnew NUM T/TCP Connection Count (CC.NEW) (default NONE)\n" " --ccecho NUM T/TCP Connection Count (CC.ECHO) (default NONE)\n" " --sack NUM:NUM TCP SACK Edges (Left:Right) (default NONE)\n" " --md5-signature TCP MD5 signature included (default OFF)\n" " --authentication TCP-AO authentication included (default OFF)\n" " --auth-key-id NUM TCP-AO authentication key ID (default 1)\n" " --auth-next-key NUM TCP-AO authentication next key (default 1)\n" " --nop TCP No-Operation (default EOL)\n\n", ( sizeof ( struct tcphdr ) / 4 ) ); } /** DCCP only options help. */ void dccp_help ( void ) { printf ( "DCCP Options:\n" " --dccp-data-offset NUM DCCP data offset (default VARY)\n" " --dccp-cscov NUM DCCP checksum coverage (default 0)\n" " --dccp-ccval NUM DCCP HC-Sender CCID (default RANDOM)\n" " --dccp-type NUM DCCP type (default %d)\n" " --dccp-extended DCCP extend for sequence # (default OFF)\n" " --dccp-sequence-1 NUM DCCP sequence # (default RANDOM)\n" " --dccp-sequence-2 NUM DCCP extended sequence # (default RANDOM)\n" " --dccp-sequence-3 NUM DCCP sequence # low (default RANDOM)\n" " --dccp-service NUM DCCP service code (default RANDOM)\n" " --dccp-acknowledge-1 NUM DCCP acknowledgment # high (default RANDOM)\n" " --dccp-acknowledge-2 NUM DCCP acknowledgment # low (default RANDOM)\n" " --dccp-reset-code NUM DCCP reset code (default RANDOM)\n\n", DCCP_PKT_REQUEST ); } src/help/rip_help.c0000644000175000017500000000374213712774300015243 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /** @file rip_help.c */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2015 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include /** RIP options help. */ void rip_help ( void ) { printf ( "RIP Options:\n" " --rip-command NUM RIPv1/v2 command (default 2)\n" " --rip-family NUM RIPv1/v2 address family (default %d)\n" " --rip-address ADDR RIPv1/v2 router address (default RANDOM)\n" " --rip-metric NUM RIPv1/v2 router metric (default RANDOM)\n" " --rip-domain NUM RIPv2 router domain (default RANDOM)\n" " --rip-tag NUM RIPv2 router tag (default RANDOM)\n" " --rip-netmask ADDR RIPv2 router subnet mask (default RANDOM)\n" " --rip-next-hop ADDR RIPv2 router next hop (default RANDOM)\n" " --rip-authentication RIPv2 authentication included (default OFF)\n" " --rip-auth-key-id NUM RIPv2 authentication key ID (default 1)\n" " --rip-auth-sequence NUM RIPv2 authentication sequence # (default RANDOM)\n\n", AF_INET ); } src/help/ospf_help.c0000644000175000017500000001373713712774300015425 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /** @file ospf_help.c */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2015 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include /** OSPF options help. */ void ospf_help ( void ) { printf ( "OSPF Options:\n" " --ospf-type NUM OSPF type (default %d)\n" " --ospf-length NUM OSPF length (default NONE)\n" " --ospf-router-id ADDR OSPF router ID (default RANDOM)\n" " --ospf-area-id ADDR OSPF area ID (default 0.0.0.0)\n" " -1,--ospf-option-MT OSPF multi-topology / TOS-based (default RANDOM)\n" " -2,--ospf-option-E OSPF external routing capability (default RANDOM)\n" " -3,--ospf-option-MC OSPF multicast capable (default RANDOM)\n" " -4,--ospf-option-NP OSPF NSSA supported (default RANDOM)\n" " -5,--ospf-option-L OSPF LLS data block contained (default RANDOM)\n" " -6,--ospf-option-DC OSPF demand circuits supported (default RANDOM)\n" " -7,--ospf-option-O OSPF Opaque-LSA (default RANDOM)\n" " -8,--ospf-option-DN OSPF DOWN bit (default RANDOM)\n" " --ospf-netmask ADDR OSPF router subnet mask (default RANDOM)\n" " --ospf-hello-interval NUM OSPF HELLO interval (default RANDOM)\n" " --ospf-hello-priority NUM OSPF HELLO router priority (default 1)\n" " --ospf-hello-dead NUM OSPF HELLO router dead interval (default 360)\n" " --ospf-hello-design ADDR OSPF HELLO designated router (default RANDOM)\n" " --ospf-hello-backup ADDR OSPF HELLO backup designated (default RANDOM)\n" " --ospf-neighbor NUM OSPF HELLO # of neighbor(s) (default NONE)\n" " --ospf-address ADDR,... OSPF HELLO neighbor address(es) (default RANDOM)\n" " --ospf-dd-mtu NUM OSPF DD MTU (default 1500)\n" " --ospf-dd-dbdesc-MS OSPF DD master/slave bit option (default RANDOM)\n" " --ospf-dd-dbdesc-M OSPF DD more bit option (default RANDOM)\n" " --ospf-dd-dbdesc-I OSPF DD init bit option (default RANDOM)\n" " --ospf-dd-dbdesc-R OSPF DD out-of-band resync (default RANDOM)\n" " --ospf-dd-sequence NUM OSPF DD sequence # (default RANDOM)\n" " --ospf-dd-include-lsa OSPF DD include LSA header (default OFF)\n" " --ospf-lsa-age NUM OSPF LSA age (default 360)\n" " --ospf-lsa-do-not-age OSPF LSA do not age (default OFF)\n" " --ospf-lsa-type NUM OSPF LSA type (default %d)\n" " --ospf-lsa-id ADDR OSPF LSA ID address (default RANDOM)\n" " --ospf-lsa-router ADDR OSPF LSA advertising router (default RANDOM)\n" " --ospf-lsa-sequence NUM OSPF LSA sequence # (default RANDOM)\n" " --ospf-lsa-metric NUM OSPF LSA metric (default RANDOM)\n" " --ospf-lsa-flag-B OSPF Router-LSA border router (default RANDOM)\n" " --ospf-lsa-flag-E OSPF Router-LSA external router (default RANDOM)\n" " --ospf-lsa-flag-V OSPF Router-LSA virtual router (default RANDOM)\n" " --ospf-lsa-flag-W OSPF Router-LSA wild router (default RANDOM)\n" " --ospf-lsa-flag-NT OSPF Router-LSA NSSA translation (default RANDOM)\n" " --ospf-lsa-link-id ADDR OSPF Router-LSA link ID (default RANDOM)\n" " --ospf-lsa-link-data ADDR OSPF Router-LSA link data (default RANDOM)\n" " --ospf-lsa-link-type NUM OSPF Router-LSA link type (default %d)\n" " --ospf-lsa-attached ADDR OSPF Network-LSA attached router (default RANDOM)\n" " --ospf-lsa-larger OSPF ASBR/NSSA-LSA ext. larger (default OFF)\n" " --ospf-lsa-forward ADDR OSPF ASBR/NSSA-LSA forward (default RANDOM)\n" " --ospf-lsa-external ADDR OSPF ASBR/NSSA-LSA external (default RANDOM)\n" " --ospf-vertex-router OSPF Group-LSA type router (default RANDOM)\n" " --ospf-vertex-network OSPF Group-LSA type network (default RANDOM)\n" " --ospf-vertex-id ADDR OSPF Group-LSA vertex ID (default RANDOM)\n" " --ospf-lls-extended-LR OSPF LLS Extended option LR (default OFF)\n" " --ospf-lls-extended-RS OSPF LLS Extended option RS (default OFF)\n" " --ospf-authentication OSPF authentication included (default OFF)\n" " --ospf-auth-key-id NUM OSPF authentication key ID (default 1)\n" " --ospf-auth-sequence NUM OSPF authentication sequence # (default RANDOM)\n\n", OSPF_TYPE_HELLO, LSA_TYPE_ROUTER, LINK_TYPE_PTP ); } src/help/eigrp_help.c0000644000175000017500000000776713712774300015572 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /** @file eigrp_help.c */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2015 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include /** EIGRP help. */ void eigrp_help ( void ) { printf ( "EIGRP Options:\n" " --eigrp-opcode NUM EIGRP opcode (default %d)\n" " --eigrp-flags NUM EIGRP flags (default RANDOM)\n" " --eigrp-sequence NUM EIGRP sequence # (default RANDOM)\n" " --eigrp-acknowledge NUM EIGRP acknowledgment # (default RANDOM)\n" " --eigrp-as NUM EIGRP autonomous system (default RANDOM)\n" " --eigrp-type NUM EIGRP type (default %d)\n" " --eigrp-length NUM EIGRP length (default NONE)\n" " --eigrp-k1 NUM EIGRP parameter K1 value (default 1)\n" " --eigrp-k2 NUM EIGRP parameter K2 value (default 0)\n" " --eigrp-k3 NUM EIGRP parameter K3 value (default 1)\n" " --eigrp-k4 NUM EIGRP parameter K4 value (default 0)\n" " --eigrp-k5 NUM EIGRP parameter K5 value (default 0)\n" " --eigrp-hold NUM EIGRP parameter hold time (default 360)\n" " --eigrp-ios-ver NUM.NUM EIGRP IOS release version (default 12.4)\n" " --eigrp-rel-ver NUM.NUM EIGRP PROTO release version (default 1.2)\n" " --eigrp-next-hop ADDR EIGRP [in|ex]ternal next-hop (default RANDOM)\n" " --eigrp-delay NUM EIGRP [in|ex]ternal delay (default RANDOM)\n" " --eigrp-bandwidth NUM EIGRP [in|ex]ternal bandwidth (default RANDOM)\n" " --eigrp-mtu NUM EIGRP [in|ex]ternal MTU (default 1500)\n" " --eigrp-hop-count NUM EIGRP [in|ex]ternal hop count (default RANDOM)\n" " --eigrp-load NUM EIGRP [in|ex]ternal load (default RANDOM)\n" " --eigrp-reliability NUM EIGRP [in|ex]ternal reliability (default RANDOM)\n" " --eigrp-daddr ADDR/CIDR EIGRP [in|ex]ternal address(es) (default RANDOM)\n" " --eigrp-src-router ADDR EIGRP external source router (default RANDOM)\n" " --eigrp-src-as NUM EIGRP external autonomous system (default RANDOM)\n" " --eigrp-tag NUM EIGRP external arbitrary tag (default RANDOM)\n" " --eigrp-proto-metric NUM EIGRP external protocol metric (default RANDOM)\n" " --eigrp-proto-id NUM EIGRP external protocol ID (default 2)\n" " --eigrp-ext-flags NUM EIGRP external flags (default RANDOM)\n" " --eigrp-address ADDR EIGRP multicast sequence address (default RANDOM)\n" " --eigrp-multicast NUM EIGRP multicast sequence # (default RANDOM)\n" " --eigrp-authentication EIGRP authentication included (default OFF)\n" " --eigrp-auth-key-id NUM EIGRP authentication key ID (default 1)\n\n", EIGRP_OPCODE_UPDATE, EIGRP_TYPE_INTERNAL ); } src/help/icmp_help.c0000644000175000017500000000266613712774300015405 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /** @file icmp_help.c */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2015 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include /** ICMP options help. */ void icmp_help ( void ) { printf ( "ICMP Options:\n" " --icmp-type NUM ICMP type (default %d)\n" " --icmp-code NUM ICMP code (default 0)\n" " --icmp-gateway ADDR ICMP redirect gateway (default RANDOM)\n" " --icmp-id NUM ICMP identification (default RANDOM)\n" " --icmp-sequence NUM ICMP sequence # (default RANDOM)\n\n", ICMP_ECHO ); } src/help/ip_help.c0000644000175000017500000000277413712774300015065 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /** @file ip_help.c */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2015 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include /** IP options help. */ void ip_help ( void ) { printf ( "IP Options:\n" " -s,--saddr ADDR IP source IP address (default RANDOM)\n" " --tos NUM IP type of service (default 0x%x)\n" " --id NUM IP identification (default RANDOM)\n" " --frag-offset NUM IP fragmentation offset (default 0)\n" " --ttl NUM IP time to live (default 255)\n" " --protocol PROTO IP protocol (default TCP)\n\n", IPTOS_PREC_IMMEDIATE ); } src/help/gre_help.c0000644000175000017500000000306013712774300015217 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /** @file gre_help.c */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2015 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include /** GRE options help. */ void gre_help ( void ) { puts ( "GRE Options:\n" " --gre-seq-present GRE sequence # present (default OFF)\n" " --gre-key-present GRE key present (default OFF)\n" " --gre-sum-present GRE checksum present (default OFF)\n" " --gre-key NUM GRE key (default RANDOM)\n" " --gre-sequence NUM GRE sequence # (default RANDOM)\n" " --gre-saddr ADDR GRE IP source IP address (default RANDOM)\n" " --gre-daddr ADDR GRE IP destination IP address (default RANDOM)\n" ); } src/help/ipsec_help.c0000644000175000017500000000260513712774300015551 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /** @file ipsec_help.c */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2015 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include /** IPSec options help. */ void ipsec_help ( void ) { puts ( "IPSEC Options:\n" " --ipsec-ah-length NUM IPSec AH header length (default NONE)\n" " --ipsec-ah-spi NUM IPSec AH SPI (default RANDOM)\n" " --ipsec-ah-sequence NUM IPSec AH sequence # (default RANDOM)\n" " --ipsec-esp-spi NUM IPSec ESP SPI (default RANDOM)\n" " --ipsec-esp-sequence NUM IPSec ESP sequence # (default RANDOM)\n" ); } src/help/igmp_help.c0000644000175000017500000000362713712774300015407 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /** @file igmp_help.c */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2015 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include /** IGMP options help. */ void igmp_help ( void ) { printf ( "IGMP Options:\n" " --igmp-type NUM IGMPv1/v3 type (default 0x%x)\n" " --igmp-code NUM IGMPv1/v3 code (default 0)\n" " --igmp-group ADDR IGMPv1/v3 address (default RANDOM)\n" " --igmp-qrv NUM IGMPv3 QRV (default RANDOM)\n" " --igmp-suppress IGMPv3 suppress router-side (default OFF)\n" " --igmp-qqic NUM IGMPv3 QQIC (default RANDOM)\n" " --igmp-grec-type NUM IGMPv3 group record type (default 1)\n" " --igmp-sources NUM IGMPv3 # of sources (default 2)\n" " --igmp-multicast ADDR IGMPv3 group record multicast (default RANDOM)\n" " --igmp-address ADDR,... IGMPv3 source address(es) (default RANDOM)\n\n", IGMP_HOST_MEMBERSHIP_QUERY ); } src/help/rsvp_help.c0000644000175000017500000001034413712774300015437 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /** @file rsvp_help.c */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2015 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include /** RSVP options help. */ void rsvp_help ( void ) { puts ( "RSVP Options:\n" " --rsvp-flags NUM RSVP flags (default 1)\n" " --rsvp-type NUM RSVP message type (default 1)\n" " --rsvp-ttl NUM RSVP time to live (default 254)\n" " --rsvp-session-addr ADDR RSVP SESSION destination address (default RANDOM)\n" " --rsvp-session-proto NUM RSVP SESSION protocol ID (default 1)\n" " --rsvp-session-flags NUM RSVP SESSION flags (default 1)\n" " --rsvp-session-port NUM RSVP SESSION destination port (default RANDOM)\n" " --rsvp-hop-addr ADDR RSVP HOP neighbor address (default RANDOM)\n" " --rsvp-hop-iface NUM RSVP HOP logical interface (default RANDOM)\n" " --rsvp-time-refresh NUM RSVP TIME refresh interval (default 360)\n" " --rsvp-error-addr ADDR RSVP ERROR node address (default RANDOM)\n" " --rsvp-error-flags NUM RSVP ERROR flags (default 2)\n" " --rsvp-error-code NUM RSVP ERROR code (default 2)\n" " --rsvp-error-value NUM RSVP ERROR value (default 8)\n" " --rsvp-scope NUM RSVP SCOPE # of address(es) (default 1)\n" " --rsvp-address ADDR,... RSVP SCOPE address(es) (default RANDOM)\n" " --rsvp-style-option NUM RSVP STYLE option vector (default 18)\n" " --rsvp-sender-addr ADDR RSVP SENDER TEMPLATE address (default RANDOM)\n" " --rsvp-sender-port NUM RSVP SENDER TEMPLATE port (default RANDOM)\n" " --rsvp-tspec-traffic RSVP TSPEC service traffic (default OFF)\n" " --rsvp-tspec-guaranteed RSVP TSPEC service guaranteed (default OFF)\n" " --rsvp-tspec-r NUM RSVP TSPEC token bucket rate (default RANDOM)\n" " --rsvp-tspec-b NUM RSVP TSPEC token bucket size (default RANDOM)\n" " --rsvp-tspec-p NUM RSVP TSPEC peak data rate (default RANDOM)\n" " --rsvp-tspec-m NUM RSVP TSPEC minimum policed unit (default RANDOM)\n" " --rsvp-tspec-M NUM RSVP TSPEC maximum packet size (default RANDOM)\n" " --rsvp-adspec-ishop NUM RSVP ADSPEC IS HOP count (default RANDOM)\n" " --rsvp-adspec-path NUM RSVP ADSPEC path b/w estimate (default RANDOM)\n" " --rsvp-adspec-m NUM RSVP ADSPEC minimum path latency (default RANDOM)\n" " --rsvp-adspec-mtu NUM RSVP ADSPEC composed MTU (default RANDOM)\n" " --rsvp-adspec-guaranteed RSVP ADSPEC service guaranteed (default OFF)\n" " --rsvp-adspec-Ctot NUM RSVP ADSPEC ETE composed value C (default RANDOM)\n" " --rsvp-adspec-Dtot NUM RSVP ADSPEC ETE composed value D (default RANDOM)\n" " --rsvp-adspec-Csum NUM RSVP ADSPEC SLR point composed C (default RANDOM)\n" " --rsvp-adspec-Dsum NUM RSVP ADSPEC SLR point composed D (default RANDOM)\n" " --rsvp-adspec-controlled RSVP ADSPEC service controlled (default OFF)\n" " --rsvp-confirm-addr ADDR RSVP CONFIRM receiver address (default RANDOM)\n" ); } src/help/general_help.c0000644000175000017500000000343113712774300016061 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /** @file general_help.c */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2015 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include /** Common options help function. */ void general_help ( void ) { puts ( "Common Options:\n" " --threshold NUM Threshold of packets to send (default 1000)\n" " --flood This option supersedes the \'threshold\'\n" " --encapsulated Encapsulated protocol (GRE) (default OFF)\n" " -B,--bogus-csum Bogus checksum (default OFF)\n" " --shuffle Shuffling for T50 protocol (default OFF)\n" " -q,--quiet Disable INFOs\n" #ifdef __HAVE_TURBO__ " --turbo Extend the performance (default OFF)\n" #endif /* __HAVE_TURBO__ */ " -l,--list-protocols List all available protocols\n" " -v,--version Print version and exit\n" " -h,--help Display this help and exit\n" ); } src/main.c0000664000175000017500000002450514107315014013427 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /** @file main.c */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2019 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include #include #include #include #include #include #include #include #include /* POSIX.1 compliant */ #include #include #include #include #include #include #include #include #include #include #include #include static pid_t pid = -1; /* -1 is a trick used when __HAVE_TURBO__ isn't defined. */ static sig_atomic_t child_is_dead = 0; /* Used to kill child process if necessary. */ static double t0; /* Used to calcualte time spent on T50. */ static int echo_enabled = 1; _NOINLINE static void initialize ( const config_options_T * ); _NOINLINE static modules_table_T *selectProtocol ( const config_options_T *restrict, int *restrict ); static void show_statistics ( void ); #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-parameter" int main ( int argc, char *argv[] ) { config_options_T *co; struct cidr *cidr_ptr; modules_table_T *ptbl; int proto; time_t lt; struct timeval tv; setlocale ( LC_ALL, "C" ); show_version(); /* Parse_command_line() returns ONLY if there are no errors. This must be called before testing user privileges. */ co = parse_command_line ( argv ); /* If user don't have root privilege, abort. */ if ( getuid() ) fatal_error ( "User must have root privilege to run." ); initialize ( co ); create_socket(); /* Calculates CIDR for destination address. */ if ( ! ( cidr_ptr = config_cidr ( co ) ) ) return EXIT_FAILURE; #ifdef __HAVE_TURBO__ /* Creates the forked process only if turbo is turned on. */ if ( co->turbo ) { if ( ( co->ip.protocol == IPPROTO_T50 && co->threshold > number_of_modules ) || ( co->ip.protocol != IPPROTO_T50 && co->threshold > 1 ) ) { threshold_T new_threshold; if ( ( pid = fork() ) == -1 ) fatal_error ( "Cannot create child process" ); /* Distribute the number of packets between processes */ new_threshold = co->threshold / 2; if ( !IS_CHILD_PID ( pid ) ) new_threshold += ( co->threshold & 1 ); co->threshold = new_threshold; } } printf ( INFO "PID=%u\n", getpid() ); #endif /* __HAVE_TURBO__ */ /* This process must have higher priority. */ if ( setpriority ( PRIO_PROCESS, PRIO_PROCESS, -15 ) == -1 ) fatal_error ( "Cannot set process priority" ); /* Show launch info only for parent process. */ if ( !IS_CHILD_PID ( pid ) && !co->quiet ) { lt = time ( NULL ); printf ( INFO "" PACKAGE_NAME " successfully launched at %s\n", ctime ( < ) ); } // SRANDOM is here because each process must have its own // random seed. SRANDOM(); // Initialize indices used for IPPROTO_T50 shuffling. build_proto_indices(); /* Preallocate packet buffer. Register deallocator after successful allocation. */ alloc_packet ( INITIAL_PACKET_SIZE ); atexit ( destroy_packet_buffer ); /* Selects the initial protocol. */ if ( co->ip.protocol != IPPROTO_T50 ) ptbl = selectProtocol ( co, &proto ); else { proto = co->ip.protocol; shuffle ( indices, number_of_modules ); // do initial shuffle. // this maybe NOT be used afterwards. ptbl = &mod_table[get_proto_index ( co )]; } /* Used to calculate the time spent injecting packets */ gettimeofday ( &tv, NULL ); t0 = tv.tv_usec * 1e-6 + tv.tv_sec; atexit ( show_statistics ); // Register show_statistics() if // we got to this point. /* MAIN LOOP */ // OBS: flood means non stop injection. // threshold is the number of packets to inject. while ( co->flood || co->threshold ) { /* Will hold the actual packet size after module function call. */ size_t size; /* Set the destination IP address to RANDOM IP address. */ co->ip.daddr = cidr_ptr->__1st_addr; if ( cidr_ptr->hostid ) // cidr_ptr->hostid has bit 0=0. The remainder is always less // then the divisor, so we need to add 1. co->ip.daddr += RANDOM() % ( cidr_ptr->hostid + 1 ); co->ip.daddr = htonl ( co->ip.daddr ); /* Finally, calls the 'module' function to build the packet. */ co->ip.protocol = ptbl->protocol_id; ptbl->func ( co, &size ); /* Try to send the packet. */ if ( ! send_packet ( packet, size, co ) ) #ifndef NDEBUG error ( "Packet for protocol %s (%zu bytes long) not sent", ptbl->name, size ); /* continue trying to send other packets on debug mode! */ #else fatal_error ( "Unspecified error sending a packet" ); #endif /* If protocol is 'T50', then get the next true protocol. */ if ( proto == IPPROTO_T50 ) ptbl = &mod_table[get_proto_index ( co )]; /* Decrement the threshold only if not flooding! */ if ( !co->flood ) co->threshold--; } /* Show termination message only for parent process. */ if ( !IS_CHILD_PID ( pid ) ) { #ifdef __HAVE_TURBO__ // NOTE: Notice that for a single process pid will be -1! */ if ( pid > 0 ) { // Don't do this if child process is already dead! if ( !child_is_dead ) { /* Wait 5 seconds for the child to end... */ alarm ( WAIT_FOR_CHILD_TIMEOUT ); /* NOTE: SIGALRM will kill the child process if necessary! */ wait ( NULL ); child_is_dead = 1; alarm ( 0 ); } } #endif close_socket(); if ( !co->quiet ) { lt = time ( NULL ); printf ( INFO "" PACKAGE_NAME " successfully finished at %s\n", ctime ( < ) ); } } /* Everything went well. Exit. */ return EXIT_SUCCESS; } #pragma GCC diagnostic pop /* This function handles signal interrupts. */ static void signal_handler ( int signal ) { /* NOTE: SIGALRM and SIGCHLD will happen only in parent process! */ switch ( signal ) { case SIGALRM: if ( !IS_CHILD_PID ( pid ) ) kill ( pid, SIGKILL ); return; case SIGCHLD: child_is_dead = 1; return; } /* Every other signals will exit the process */ /* The shell documentation (bash) specifies that a process, when exits because a signal, must return 128+signal#. */ exit ( 128 + signal ); } void initialize ( const config_options_T *co ) { /* 0 is an invalid signal! (marks the end of the list) */ int handled_signals[] = { SIGPIPE, SIGINT, SIGCHLD, SIGALRM, 0 }; int *sigsp; /* allows libc calls to restart after a signal! */ struct sigaction sa = { .sa_handler = signal_handler, .sa_flags = SA_RESTART }; sigset_t sigset; struct termios tios; /* Hide ^X char output from terminal */ tcgetattr ( STDOUT_FILENO, &tios ); echo_enabled = tios.c_lflag & ECHO; if ( echo_enabled ) tios.c_lflag &= ~ECHO; tcsetattr ( STDOUT_FILENO, TCSANOW, &tios ); /* Blocks SIGTSTP avoiding ^Z behavior. */ sigemptyset ( &sigset ); sigaddset ( &sigset, SIGTSTP ); /* OBS: SIGSTOP cannot be caught, blocked or ignored! */ /* Don't need to block SIGCONT */ sigprocmask ( SIG_BLOCK, &sigset, NULL ); /* --- Initialize signal handlers --- */ /* All these signals are handled by our handle, except those blocked previously. */ sigfillset ( &sigset ); sa.sa_mask = sigset; sigsp = handled_signals; while ( *sigsp ) sigaction ( *sigsp++, &sa, NULL ); /* To simplify things, make sure stdout is unbuffered (otherwise, it's line buffered). */ fflush ( stdout ); setvbuf ( stdout, NULL, _IONBF, 0 ); /* Show some messages. */ if ( !co->quiet ) { if ( co->flood ) fputs ( INFO "Entering flood mode...", stdout ); else printf ( INFO "Sending %u packets...\n", co->threshold ); #ifdef __HAVE_TURBO__ if ( co->turbo ) puts ( INFO "Turbo mode active..." ); #endif if ( co->bits ) puts ( INFO "Performing stress testing..." ); puts ( INFO "Hit Ctrl+C to stop..." ); } } /* Selects the initial protocol based on the configuration. */ modules_table_T *selectProtocol ( const config_options_T *restrict co, int *restrict proto ) { modules_table_T *ptbl; ptbl = mod_table; // FIXME: Of course this is a 'hack'. Maybe I should divise something more portable here. if ( ( *proto = co->ip.protocol ) != IPPROTO_T50 ) ptbl += co->ip.protoname; return ptbl; } void show_statistics ( void ) { struct timeval tv; // FIXME: This is not as precise as I wanted. // A bunch of microseconds (maybe milisseconds) will // be accounted as the finalization queue routines // are dispatched. gettimeofday ( &tv, NULL ); close_socket(); // NOTE: This will 'flush' the buffers?! if ( packets_sent ) { pid_t pid; double t1; t1 = tv.tv_usec * 1e-6 + tv.tv_sec; pid = getpid(); printf ( INFO "(PID:%1$u) packets: %2$" PRIu64 " (%3$" PRIu64 " bytes sent).\n" INFO "(PID:%1$u) throughput: %4$.2f packets/second.\n", pid, packets_sent, bytes_sent, ( double ) packets_sent / ( t1 - t0 ) ); } } _FINI static void dtor ( void ) { struct termios tios; /* Restore terminal ECHO */ if ( echo_enabled ) { tcgetattr ( STDOUT_FILENO, &tios ); tios.c_lflag |= ECHO; tcsetattr ( STDOUT_FILENO, TCSANOW, &tios ); } } src/usage.c0000644000175000017500000000427713712774300013621 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /** @file usage.c */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2019 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include void show_version ( void ) { puts ( "T50 Experimental Mixed Packet Injector Tool v" PACKAGE_VERSION "\n" "Originally created by Nelson Brito \n" "Previously maintained by Fernando Mercês \n" "Maintained by Frederico Lamberti Pissarra \n" ); } /* Help and usage message */ void usage ( void ) { /* --- already showing version, by default! --- */ //show_version(); puts ( "Usage: t50 [options]" ); general_help(); gre_help(); tcp_udp_dccp_help(); tcp_help(); ip_help(); icmp_help(); egp_help(); rip_help(); dccp_help(); rsvp_help(); ipsec_help(); eigrp_help(); ospf_help(); puts ( "Some considerations while running this program:\n" " 1. There is no limitation of using as many options as possible.\n" " 2. Report " PACKAGE " bugs at " PACKAGE_URL ".\n" " 3. Some header fields with default values MUST be set to \'0\' for RANDOM.\n" " 4. Mandatory arguments to long options are mandatory for short options too.\n" " 5. Be nice when using " PACKAGE ", the author DENIES its use for DoS/DDoS purposes.\n" " 6. Running " PACKAGE " with \'--protocol T50\' option sends ALL protocols sequentially." ); exit ( EXIT_FAILURE ); } src/cksum.c0000644000175000017500000000352213712774300013627 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /** @file cksum.c */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2019 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include /** * Calculates checksum. * * RFC 1071 compliant checksum routine. * * FIXED: last implementation was WRONG... I can't find any faster way to do this! * Yet... There was another error that didn't consider BIG ENDIAN machines... * Note to myself: Don't mess with this routine again! * * That being said, I shold find a way to calculate the checksum faster. */ uint16_t cksum ( void *data, size_t length ) { uint16_t *ptr; uint32_t sum; sum = 0; ptr = data; while ( length > 1 ) { sum += *ptr++; length -= 2; } // if there is any additional bytes remaining... if ( length > 0 ) #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ sum += (uint16_t)(*(uint8_t *)ptr) << 8; // last byte must be // aligned to upper 8 bits. #else sum += *(uint8_t *)ptr; #endif // Add carry-outs... while ( sum >> 16 ) sum = ( sum & 0xffffU ) + ( sum >> 16 ); // NOTE: Let the caller put this in network order, if necessary! return ~sum; } src/errors.c0000644000175000017500000000343313712774300014022 0ustar fredericofrederico/* vim: set ts=2 et sw=2 : */ /** @file errors.c */ /* * T50 - Experimental Mixed Packet Injector * * Copyright (C) 2010 - 2019 - T50 developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ // Needed for asprintf(). #define _GNU_SOURCE #include #include #include #include #include /* --- Using vfprintf for flexibility. */ static void verror(const char * const fmt, va_list args) { char *str; if ((asprintf(&str, PACKAGE ": %s\n", fmt)) == -1) { fputs(PACKAGE ": Unknown error (not enough memory?).\n", stderr); exit(EXIT_FAILURE); } vfprintf(stderr, str, args); free(str); } /** * Standard error reporting routine. Non fatal version. */ void error(const char * const fmt, ...) { va_list args; fputs(ERROR " ", stderr); va_start(args, fmt); verror(fmt, args); va_end(args); } /** * Standard error reporting routine. Fatal Version. * * This function never returns! */ void fatal_error(const char * const fmt, ...) { va_list args; fputs(FATAL " ", stderr); va_start(args, fmt); verror(fmt,args); va_end(args); /* As expected. exit if a failure. */ exit(EXIT_FAILURE); }