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 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'trafgen_dump.c') 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: -- cgit v1.2.3-54-g00ecf