.\" netsniff-ng - the packet sniffing beast .\" Copyright 2013 Daniel Borkmann. .\" Subject to the GPL, version 2. .TH TRAFGEN 8 "03 March 2013" "Linux" "netsniff-ng toolkit" .SH NAME trafgen \- a fast, multithreaded network packet generator .PP .SH SYNOPSIS .PP \fBtrafgen\fP [\fIoptions\fP] [\fIpacket\fP] .PP .SH DESCRIPTION .PP trafgen is a fast, zero-copy network traffic generator for debugging, performance evaluation, and fuzz-testing. trafgen utilizes the .BR packet (7) socket interface of Linux which postpones complete control over packet data and packet headers into the user space. It has a powerful packet configuration language, which is rather low-level and not limited to particular protocols. Thus, trafgen can be used for many purposes. Its only limitation is that it cannot mimic full streams resp. sessions. However, it is very useful for various kinds of load testing in order to analyze and subsequently improve systems behaviour under DoS attack scenarios, for instance. .PP trafgen is Linux specific, meaning there is no support for other operating systems, same as .BR netsniff-ng (8), thus we can keep the code footprint quite minimal and to the point. trafgen makes use of .BR packet (7) socket's TX_RING interface of the Linux kernel, which is a .BR mmap (2)'ed ring buffer shared between user and kernel space. .PP By default, trafgen starts as many processes as available CPUs, pins each of them to their respective CPU and sets up the ring buffer each in their own process space after having compiled a list of packets to transmit. Thus, this is likely the fastest one can get out of the box in terms of transmission performance from user space, without having to load unsupported or non-mainline third-party kernel modules. On Gigabit Ethernet, trafgen has a comparable performance to pktgen, the built-in Linux kernel traffic generator, except that trafgen is more flexible in terms of packet configuration possibilities. On 10-Gigabit-per-second Ethernet, trafgen might be slower than pktgen due to the user/kernel space overhead but still has a fairly high performance for out of the box kernels. .PP trafgen has the potential to do fuzz testing, meaning a packet configuration can be built with random numbers on all or certain packet offsets that are freshly generated each time a packet is sent out. With a built-in IPv4 ping, trafgen can send out an ICMP probe after each packet injection to the remote host in order to test if it is still responsive/alive. Assuming there is no answer from the remote host after a certain threshold of probes, the machine is considered dead and the last sent packet is printed together with the random seed that was used by trafgen. You might not really get lucky fuzz-testing the Linux kernel, but presumably there are buggy closed-source embedded systems or network driver's firmware files that are prone to bugs, where trafgen could help in finding them. .PP trafgen's configuration language is quite powerful, also due to the fact, that it supports C preprocessor macros. A stddef.h is being shipped with trafgen for this purpose, so that well known defines from Linux kernel or network programming can be reused. After a configuration file has passed the C preprocessor stage, it is processed by the trafgen packet compiler. The language itself supports a couple of features that are useful when assembling packets, such as built-in runtime checksum support for IP, UDP and TCP. Also it has an expression evaluator where arithmetic (basic operations, bit operations, bit shifting, ...) on constant expressions is being reduced to a single constant on compile time. Other features are ''fill'' macros, where a packet can be filled with n bytes by a constant, a compile-time random number or run-time random number (as mentioned with fuzz testing). Also, .BR netsniff-ng (8) is able to convert a pcap file into a trafgen configuration file, thus such a configuration can be further tweaked for a given scenario. .PP .SH OPTIONS .TP .B -i , -c , --in , --conf Defines the input configuration file that can either be passed as a normal plain text file or via stdin (''-''). Note that currently, if a configuration is passed through stdin, only 1 CPU will be used. It is also possible to specify PCAP file with .pcap extension via \fB-i\fP/\fB--in\fP option, by default packets will be sent at rate considering timestamp from PCAP file which might be reset via the \fB-b\fP or \fB-t\fP option. .TP .B -o , -d , --out , --dev Defines the outgoing networking device such as eth0, wlan0 and others or a *.pcap or *.cfg file. Pcap and configuration files are identified by extension. .TP .B -p, --cpp Pass the packet configuration to the C preprocessor before reading it into trafgen. This allows #define and #include directives (e.g. to include definitions from system headers) to be used in the trafgen configuration file. .TP .B -D =, --define = Add macro definition for the C preprocessor to use it within trafgen file. This option is used in combination with the \fB-p\fP/\fB--cpp\fP option. .TP .B -J, --jumbo-support By default trafgen's ring buffer frames are of a fixed size of 2048 bytes. This means that if you're expecting jumbo frames or even super jumbo frames to pass your line, then you will need to enable support for that with the help of this option. However, this has the disadvantage of a performance regression and a bigger memory footprint for the ring buffer. .TP .B -R, --rfraw In case the output networking device is a wireless device, it is possible with trafgen to turn this into monitor mode and create a mon device that trafgen will be transmitting on instead of wlan, for instance. This enables trafgen to inject raw 802.11 frames. In case if the output is a pcap file the link type is set to 127 (ieee80211 radio tap). .TP .B -s , --smoke-test In case this option is enabled, trafgen will perform a smoke test. In other words, it will probe the remote end, specified by an address, that is being ''attacked'' with trafgen network traffic, if it is still alive and responsive. That means, after each transmitted packet that has been configured, trafgen sends out ICMP echo requests and waits for an answer before it continues. In case the remote end stays unresponsive, trafgen assumes that the machine has crashed and will print out the content of the last packet as a trafgen packet configuration and the random seed that has been used in order to reproduce a possible bug. This might be useful when testing proprietary embedded devices. It is recommended to have a direct link between the host running trafgen and the host being attacked by trafgen. .TP .B -n <0|uint>, --num <0|uint> Process a number of packets and then exit. If the number of packets is 0, then this is equivalent to infinite packets resp. processing until interrupted. Otherwise, a number given as an unsigned integer will limit processing. .TP .B -r, --rand Randomize the packet selection of the configuration file. By default, if more than one packet is defined in a packet configuration, packets are scheduled for transmission in a round robin fashion. With this option, they are selected randomly instread. .TP .B -P [-], --cpus [-] Specify the number of processes trafgen shall .BR fork (2) off or list exact CPUs to use. By default trafgen will start as many processes as CPUs that are online and pin them to each, respectively. A single integer within interval [1,CPUs] overrides number of processes, which will be spawned starting from the first CPU. A pair of integers within interval [0,CPUs-1], and separated using ''-'' represents an interval of CPUs, which will be used to spawn worker processes. .TP .B -t