From 65ba0860baa53670e79211edbd047a8080ec1f8a Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Thu, 8 Mar 2018 18:10:37 +0100 Subject: trafgen: support dumping IPv6 protocol header command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Support dissecting IPv6 headers into the îp6' trafgen protocol header command. Signed-off-by: Tobias Klauser --- trafgen_dump.c | 29 +++++++++++++++++++++++++++++ trafgen_l3.c | 15 +++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/trafgen_dump.c b/trafgen_dump.c index ff68e8b..d44bf58 100644 --- a/trafgen_dump.c +++ b/trafgen_dump.c @@ -138,6 +138,33 @@ static int proto_dump_ip4(struct dump_ctx *ctx, struct proto_hdr *hdr) return 0; } +static int proto_dump_ip6(struct dump_ctx *ctx, struct proto_hdr *hdr) +{ + char ip_sa_str[INET6_ADDRSTRLEN]; + char ip_da_str[INET6_ADDRSTRLEN]; + uint8_t *ip; + + ip = proto_hdr_field_get_bytes(hdr, IP6_SADDR); + inet_ntop(AF_INET6, ip, ip_sa_str, sizeof(ip_sa_str)); + + ip = proto_hdr_field_get_bytes(hdr, IP6_DADDR); + inet_ntop(AF_INET6, ip, ip_da_str, sizeof(ip_da_str)); + + HDR_START("ip6"); + + FIELD_START("ver=0x%x", proto_hdr_field_get_u32(hdr, IP6_VER)); + FIELD("tc=0x%x", proto_hdr_field_get_u32(hdr, IP6_CLASS)); + FIELD("fl=0x%x", proto_hdr_field_get_u32(hdr, IP6_FLOW_LBL)); + FIELD("len=%d", proto_hdr_field_get_u16(hdr, IP6_LEN)); + FIELD("nh=0x%x", proto_hdr_field_get_u8(hdr, IP6_NEXT_HDR)); + FIELD("hl=%d", proto_hdr_field_get_u8(hdr, IP6_HOP_LIMIT)); + FIELD("sa=%s", ip_sa_str); + FIELD_END("da=%s", ip_da_str); + + HDR_END(); + return 0; +} + static int proto_dump_udp(struct dump_ctx *ctx, struct proto_hdr *hdr) { HDR_START("udp"); @@ -195,6 +222,8 @@ static int proto_dump_hdr(struct dump_ctx *ctx, struct proto_hdr *hdr) return proto_dump_arp(ctx, hdr); case PROTO_IP4: return proto_dump_ip4(ctx, hdr); + case PROTO_IP6: + return proto_dump_ip6(ctx, hdr); case PROTO_UDP: return proto_dump_udp(ctx, hdr); case PROTO_TCP: diff --git a/trafgen_l3.c b/trafgen_l3.c index a3f711d..9d0d930 100644 --- a/trafgen_l3.c +++ b/trafgen_l3.c @@ -212,6 +212,20 @@ static void ipv6_set_next_proto(struct proto_hdr *hdr, enum proto_id pid) proto_hdr_field_set_default_u8(hdr, IP6_NEXT_HDR, ip_proto); } +static enum proto_id ipv6_get_next_proto(struct proto_hdr *hdr) +{ + switch (proto_hdr_field_get_u8(hdr, IP6_NEXT_HDR)) { + case IPPROTO_ICMPV6: + return PROTO_IP4; + case IPPROTO_UDP: + return PROTO_UDP; + case IPPROTO_TCP: + return PROTO_TCP; + default: + return __PROTO_MAX; + } +} + static const struct proto_ops ipv6_proto_ops = { .id = PROTO_IP6, .layer = PROTO_L3, @@ -219,6 +233,7 @@ static const struct proto_ops ipv6_proto_ops = { .field_changed = ipv6_field_changed, .packet_finish = ipv6_packet_finish, .set_next_proto = ipv6_set_next_proto, + .get_next_proto = ipv6_get_next_proto, }; void protos_l3_init(void) -- cgit v1.2.3-54-g00ecf