diff options
author | Vadim Kochan <vadim4j@gmail.com> | 2017-07-29 12:46:09 +0300 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2017-08-10 09:03:46 +0200 |
commit | 439af62bca4794d78d53fb4634f560d6a75f0adb (patch) | |
tree | 346cc168c42bbe1d7f0eb6bd493d244016172a01 /trafgen_l3.c | |
parent | 19348cec323373d84674c1d2cf34315cbf47c80d (diff) |
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 <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>
Diffstat (limited to 'trafgen_l3.c')
-rw-r--r-- | trafgen_l3.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/trafgen_l3.c b/trafgen_l3.c index 48790e5..a3f711d 100644 --- a/trafgen_l3.c +++ b/trafgen_l3.c @@ -38,7 +38,7 @@ static void ipv4_header_init(struct proto_hdr *hdr) struct dev_io *dev = proto_dev_get(); /* In case of tun interface we do not need to create Ethernet header */ - if (dev_io_is_pcap(dev) || device_type(dev_io_name_get(dev)) != ARPHRD_NONE) + if (!dev_io_is_netdev(dev) || device_type(dev_io_name_get(dev)) != ARPHRD_NONE) proto_lower_default_add(hdr, PROTO_ETH); proto_header_fields_add(hdr, ipv4_fields, array_size(ipv4_fields)); @@ -117,6 +117,24 @@ static void ipv4_set_next_proto(struct proto_hdr *hdr, enum proto_id pid) proto_hdr_field_set_default_u8(hdr, IP4_PROTO, ip_proto); } +static enum proto_id ipv4_get_next_proto(struct proto_hdr *hdr) +{ + switch (proto_hdr_field_get_u8(hdr, IP4_PROTO)) { + case IPPROTO_IPIP: + return PROTO_IP4; + case IPPROTO_IPV6: + return PROTO_IP6; + case IPPROTO_ICMP: + return PROTO_ICMP4; + case IPPROTO_UDP: + return PROTO_UDP; + case IPPROTO_TCP: + return PROTO_TCP; + default: + return __PROTO_MAX; + } +} + static const struct proto_ops ipv4_proto_ops = { .id = PROTO_IP4, .layer = PROTO_L3, @@ -125,6 +143,7 @@ static const struct proto_ops ipv4_proto_ops = { .field_changed = ipv4_field_changed, .packet_finish = ipv4_packet_finish, .set_next_proto = ipv4_set_next_proto, + .get_next_proto = ipv4_get_next_proto, }; static struct proto_field ipv6_fields[] = { |