Age | Commit message (Collapse) | Author | Files | Lines |
|
Currently, using -t 0 option calls shaper_set_delay with 0 sec and 0 ns,
which results in sh->type to be SHAPER_NONE. This in turn causes trafgen
to use TX_RING.
Expected behavior, from "man trafgen":
If this option is given, then instead of packet(7)'s TX_RING
interface, trafgen will use sendto(2) I/O for network packets, even
if the argument is 0.
This patch forces sh->type to be set to SHAPER_DELAY even if
the delay is 0. shaper_delay already handles the case where
sh->type is SHAPER_DELAY and the delay is 0.
Fixes #208
Signed-off-by: Quentin Chateau <quentin.chateau@gmail.com>
[tklauser: adjusted commit message to include change description]
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
Usage: csumicmp6(14, 54)
Signed-off-by: Radoslav Bodo <bodik@cesnet.cz>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
There is no need to explicity use the builtins. According to [1], GCC
will recognize mem{cpy,set} as built-in functions, unless the
corresponding -fno-builtin-* option is specified (which is not the case
for netsniff-ng).
[1] https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
They are opened in main_loop which is only executed in the child(ren),
so close them there again. This avoids closing the devices twice, which
may lead to segfaults.
Fixes #188
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
currently, after dinc(), the valued stored inside the packet is
not in the (min, max) range but in the (0, max - min + 1) range,
'counter->val' should be used instead of 'val'.
Additionally the values computed for ddec() are corrupted, in:
val = (val - counter->inc) % (counter->min - counter->max + 1);
the divider is negative, we should use (counter->max - counter->min + 1)
as in the INC case.
Finally we can avoid the switch statement at update time, inverting
the value of 'counter->inc' for decrement and using a data type wide
enough for the 'inc' field.
v1 -> v2:
- changed 'counter->inc' type to int
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
If trafgen is called with the -i option, it currently crashes due to an
NULL pointer dereference. Fix it.
Fixes Coverity CID 1381809
Fixes: 82a3c204c6f1 ("trafgen: Allow send packets from pcap file")
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
The commit 78c13b71e196 ("trafgen: Allow to generate packets
to output pcap file") introduced a regression when output is
a network device and multiple CPU are in use: the packet
socket is created before fork() and thus the socket is shared
among all the processes: all of them except the first will
fail while setting the tx_ring.
Fix it splitting the io open() helper in a create() op,
called before forking, and the open() op called by each process.
Fixes: 78c13b71e196 ("trafgen: Allow to generate packets to output pcap file")
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
Added trafgen_dump.c module which dumps headers from packet
in .cfg format. Packet is dumped if -o <file>.cfg was specified,
it might be useful to specify *.pcap file as input and convert it
into .cfg file to edit proto fields in human readable format.
To make it possible several main changes were added:
1) packet id is embedded into struct packet.id, and
it is updated on each realloc_packet()
2) Added new struct proto_hdr.get_next_proto callback
to make possible apply fields of next header.
3) Added new dev_io ops for writting packets into .cfg file,
to re-use common dev_io mechsnism for packets dumping.
Before dump the default ETH_PROTO fields are applied as first header and
then next proto_hdr is identified via .get_next_proto(...) callback.
Meanwhile only eth, arp, vlan, ip4, udp, & tcp protos can be dissected
into *.cfg format.
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
Refactor dev_io_ops read & write to specify struct packet *,
it may simplify a bit a caller logic. And it allow to keep
required members within one struct packet object.
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
Simplify a bit of creation rfraw device by delegating it to the dev_io
API, also in case the output device is pcap file the --rfraw option
sets the link type to ieee80211 radio tap.
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
pull_and_flush_tx_ring_wait() in the exit path of xmit_fastpath_or_die()
might return with errno ENOBUFS (due to the other CPU's processes
concurrent access) but will eventually suceed. Thus retry
pull_and_flush_tx_ring_wait() as in the main loop of
xmit_fastpath_or_die().
Fixes #175
Reported-by: Eduardo Miravalls Sierra
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
Trim output name to IFNAMSIZ only if the output is a networking device,
otherwise the following error occured if output name is greater then
IFNAMSIZ:
$ trafgen -n 1 '{ udp() }' -o /tmp/xxxxxxxxxxxxxx.pcap
No networking device or pcap file: /tmp/xxxxxxxxxx
Failed to open output device
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
Add trafgen_dev.c module which provides generic way of
reading and writing packets to/from networking device or a pcap file.
Also allow to handle output pcap file via '-o, --out, --dev' option.
It might be useful in future for testing some link protocols which is
not easy to capture (e.g. wlan packets) w/o having some special setup.
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
[tklauser: fix whitespace issues]
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
Add ability to send packets from pcap file if it has
".pcap" extension via "-i,--in" option.
By default packet sending is delayed considering original
packets timestamps if no rate or delay is specified via -b/-t options.
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
Also sightly adjust the description in the usage text.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
All tools (except mausezahn) use getopt_long() and pass a pointer to a
local opt_index variable for the longindex parameter. However, this
variable is never read afterwards.
According to getopt(3) it's perfectly fine to pass NULL as the longindex
parameter instead, so do that.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
Add basic infrastructure for update proto field value at runtime by
dynamic field function.
Extended 'struct packet_dyn' with proto fields which has dynamically
changing values at runtime.
Added 'field_changed' callback for proto header which may be used for
check if csum updating is needed. This callback is called after field
was changed at runtime.
Added 'packet_update' callback to let proto header know when to apply
final proto header changes at runtime (e.g. - csum update).
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
The same code for applying dynamic elements to a packet is used for both
slow & fast path modes, so let's move it into one inlined function.
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
Use the mkostemp_or_die() wrapper introduced in commit a87f181bd836
("ioops: Add mkostemp_or_die") to safely create a unique temporary file
instead of using rand() to manually create a (potentially unsafe)
temporary filename.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
Add new trafgen_proto.c module with basic protocol header fields
generation logic. This will allow to support protocol specific keywords
in the trafgen configuration language.
Each protocol must implement struct proto_hdr and register it to the
global proto list.
Protocol headers consist of a set of fields, and each field must be
described via struct proto_field by specifying unique id, length and
offset (relative to the header start). Fields smaller than 8 bits can be
described via left shift & mask.
The following callbacks are invoked to perform special actions to build
the header during parsing:
1) header_init - required fields must be added to the packet and
initialized with default values.
2) header_finish - it is invoked when header is specified, all user
specified fields are set.
3) packet_finish - callback is invoked from upper to lower header
to calculate fields depending on upper layers such as total
length or checksum.
The protocol generation API provides convenience protocol field
setters/getters to to be used in the parser while crafting the packet.
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
[tk: wordsmithing on commit message, minor variable type changes]
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
Lets strtoul(...) func set pointer of unit name for ring size option,
instead of check each character by isdigit(...).
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
It is not needed to parse each character to find
unit name in the option string but just let to do it
via strtoul providing the pointer which will keep non numeric
value.
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
Move gap feature into rate shaper, as these features
means the same - delay the packet sending.
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
Use 'kbit' instead of kBit in usage and manpage to actually reflect what
trafgen expects.
Fixes: 9ece0fe02096 ("trafgen: Add option to specify packets sending rate")
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
Added -b,--rate option in units of:
pps/B/kB/MB/kBit/Mbit/Gbit/KiB/MiB/GiB
to specify rate at which packets will be sent.
Similarly to -t,--gap option the packets will be sent
in slow mode with 1 CPU.
Tested with ifpps.
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
Add -D,--define option which allows to pass multiple
macro/defines which can be used in trafgen script
(e.g. by #ifdef ).
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
No need to duplicate the call to preprocess_packets(), just call it
directly after compile_packets()/compile_packets_str().
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
The `ccsum' parameter to calc_csum() is never used and is set to 0 by
all callers. There's no reason to keep it, so remove it.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
Craft packet directly from command line with same syntax as for conf file.
It might be as first step to extend current syntax with specific proto fields.
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
Just add a newline before notes.
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
|
|
Let AF_PACKET do this job to fail in case boundaries are too small or
too large. I found it quite useful for testing the kernel.
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
|
|
Spell out "resolve" properly.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
The TCP/UDP checksums cannot be calculated in the parser as the packet
payload following the TCP/UDP header is not yet know. However, we can
calculate these checksums before the send loop if the only dynamic
elements of the packet are checksums.
This change avoids the overhead of recalculating the checksums for every
iteration the send loop in these cases.
Suggested-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
Replace bugs@netsniff-ng.com with netsniff-ng@googlegroups.com
which is used in REPORTING-BUGS file.
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
Move has_dynamic_elems() to to trafgen_conf.h, rename it to
packet_dyn_has_elems() and use it to check whether dynamic
packet elements are present.
Also change the return type to bool and use || instead of + to
potentially make use of short-circuit evaluation.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
The return value of xmit_packet_precheck() is always 0 and it calls
panic() in any error cases, so its return value isn't of any use.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
Add the csumudp6 and csumtcp6 helper functions in order to simplify
checksum generation for TCP/UDP packets sent over IPv6.
trafgen example for TCP over IPv6:
{
/* MAC Destination */
fill(0xff, 6),
/* MAC Source */
0x00, 0x02, 0xb3, drnd(3),
/* IPv6 Protocol */
c16(0x86DD),
/* Version, Traffic Class, Flow Label */
0b01100000, c8(0), c16(0),
/* Payload Length */
c16(54),
/* Next Header (TCP) */
c8(6),
/* Hop Limit */
c8(64),
/* Source IPv6 */
0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xba, 0xac, 0x6f, 0xff, 0xfe, 0xa4, 0x12, 0xe3,
/* Destination IPv6 */
0xfe, 0x80, 0x82, 0x2e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xde, 0xff, 0xfe, 0x00, 0x06, 0xde,
/* TCP Source Port */
c16(55042),
/* TCP Destination Port */
c16(55043),
/* TCP Sequence Number */
drnd(4),
/* TCP Ackn. Number */
c32(0),
/* TCP Header length + TCP SYN/ECN Flag */
c16((8 << 12) | (1 << 1) | (1 << 6))
/* Window Size */
c16(16),
/* TCP Checksum (offset IPv6, offset TCP) */
csumtcp6(14, 54),
/* TCP Options */
0x00, 0x00, 0x01, 0x01, 0x08, 0x0a, 0x06,
0x91, 0x68, 0x7d, 0x06, 0x91, 0x68, 0x6f,
/* Data blob */
"foobar!",
}
Suggested-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
Print minimum needed packet size in case if validation error.
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
Create PF_PACKET socket with proto=0 which does not setup packet handler
and will not capture packets until bind() will be invoked.
Also replaced pf_tx_socket by pf_socket as these funcs became the same,
as proto arg is set to 0.
Suggested-by: Daniel Borkmann <borkmann@iogearbox.net>
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
Rename xxx_panic_func(s) to xxx_panic_handler(s) which is more
understandable than 'func'.
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
Fixed case when rfmon mac80211 created device remains after trafgen
failed (for ex. - incorrect cfg file), so just delete it when panic
occured.
Also made panic handlers invoking per process and only once.
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
Trafgen uses all the online CPUs even if the number of packets specified
by -n is less than the number of selected CPUs. Such behaviour leads to
issues:
- trafgen re-calculates number of packets per CPU which
leads to rounding it to 0 then no packets will be sent.
- trafgen might send more packets than specified by -n because
of using all the online cpus.
Fixed by taking min(#CPUs, #packets) as the number of CPUs if a number
of packets is specified by -n.
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
[tklauser: moved code and added explanatory comment]
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
We no longer ship example trafgen config files. Instead, mention the
netsniff-ng conversion facility.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
linux has default time slack of 50 usec, which means that trafgen
'gap' option is unable to precisely control delays.
Set the process timer slack to the minimum of 1 nsec.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
|
|
No need for some of the empty lines, remove them to make the output a
bit denser.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
Move the copyright/bug report/license string to an own constant and use
it for the output of help() and version() to avoid duplication and
prevent the strings from getting out of sync. This makes the text
section of trafgen.o slightly smaller:
before:
text data bss dec hex filename
18512 0 104 18616 48b8 trafgen/trafgen.o
after:
text data bss dec hex filename
18240 0 104 18344 47a8 trafgen/trafgen.o
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
The number of CPUs is stored in ctx.cpus which is unsigned int, so use
unsigned int consistently when using CPU number. Negative CPU numbers
wont occur anyhow.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
Use zmalloc()'ed buffer or statically sized array to replace usage of
variable sized arrays. Found by the sparse static checker.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
Pushed last commit a bit too fast. The help text described that
the single letter option for "--no-sock-mem" were "-m", which is
wrong the right option is "-A" (only help txt, correct in the code
and manual).
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
|