From 439af62bca4794d78d53fb4634f560d6a75f0adb Mon Sep 17 00:00:00 2001 From: Vadim Kochan Date: Sat, 29 Jul 2017 12:46:09 +0300 Subject: trafgen: Dump proto headers in *.cfg format Added trafgen_dump.c module which dumps headers from packet in .cfg format. Packet is dumped if -o .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 Signed-off-by: Tobias Klauser --- trafgen.8 | 4 +- trafgen.c | 54 ++++++------ trafgen/Makefile | 1 + trafgen_conf.h | 2 + trafgen_dev.c | 36 +++++++- trafgen_dev.h | 4 +- trafgen_dump.c | 258 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ trafgen_dump.h | 8 ++ trafgen_l2.c | 33 +++++++ trafgen_l3.c | 21 ++++- trafgen_parser.y | 5 ++ trafgen_proto.c | 69 +++++++++++++-- trafgen_proto.h | 7 ++ 13 files changed, 460 insertions(+), 42 deletions(-) create mode 100644 trafgen_dump.c create mode 100644 trafgen_dump.h diff --git a/trafgen.8 b/trafgen.8 index 67aaaf9..f720043 100644 --- a/trafgen.8 +++ b/trafgen.8 @@ -74,9 +74,9 @@ It is also possible to specify PCAP file with .pcap extension via -i,--in option by default packets will be sent at rate considering timestamp from PCAP file which might be reset via -b/-t options. .PP -.SS -o , -d , --out , --dev +.SS -o , -d , --out , --dev Defines the outgoing networking device such as eth0, wlan0 and others or -a pcap file. +a *.pcap or *.cfg file. Pcap and configuration files are identified by extension. .PP .SS -p, --cpp Pass the packet configuration to the C preprocessor before reading it into diff --git a/trafgen.c b/trafgen.c index 97ac046..9b54399 100644 --- a/trafgen.c +++ b/trafgen.c @@ -185,31 +185,31 @@ static void __noreturn help(void) puts("http://www.netsniff-ng.org\n\n" "Usage: trafgen [options] [packet]\n" "Options:\n" - " -i|-c|--in|--conf Packet configuration file/stdin\n" - " -o|-d|--out|--dev Networking device i.e., eth0\n" - " -p|--cpp Run packet config through C preprocessor\n" - " -D|--define Add macro/define for C preprocessor\n" - " -J|--jumbo-support Support 64KB super jumbo frames (def: 2048B)\n" - " -R|--rfraw Inject raw 802.11 frames\n" - " -s|--smoke-test Probe if machine survived fuzz-tested packet\n" - " -n|--num Number of packets until exit (def: 0)\n" - " -r|--rand Randomize packet selection (def: round robin)\n" - " -P|--cpus Specify number of forks(<= CPUs) (def: #CPUs)\n" - " -t|--gap