From c18016b69b1b8bdb313c38871793deb55e1e0776 Mon Sep 17 00:00:00 2001 From: Tomasz Bursztyka Date: Fri, 7 Apr 2017 12:04:28 +0200 Subject: [PATCH] net_pkt: Externalize ext_bitmap handling IPv6 next headers are processed in a way so it is not required to store which header has been already seen in the net_pkt, as the processing loop can store internally which one it has seen already. Change-Id: I266ba8a3a0081a162318cdafb474a0fc44a3185e Signed-off-by: Tomasz Bursztyka --- include/net/net_pkt.h | 16 ---------------- subsys/net/ip/ipv6.c | 9 ++++----- subsys/net/ip/ipv6.h | 17 +++++++++-------- 3 files changed, 13 insertions(+), 29 deletions(-) diff --git a/include/net/net_pkt.h b/include/net/net_pkt.h index a06a7e78781..ce82db09f98 100644 --- a/include/net/net_pkt.h +++ b/include/net/net_pkt.h @@ -91,7 +91,6 @@ struct net_pkt { uint8_t family; /* IPv4 vs IPv6 */ uint8_t ip_hdr_len; /* pre-filled in order to avoid func call */ uint8_t ext_len; /* length of extension headers */ - uint8_t ext_bitmap; #if defined(CONFIG_NET_IPV6) uint8_t ext_opt_len; /* IPv6 ND option length */ @@ -192,21 +191,6 @@ static inline void net_pkt_set_ext_len(struct net_pkt *pkt, uint8_t len) pkt->ext_len = len; } -static inline uint8_t net_pkt_ext_bitmap(struct net_pkt *pkt) -{ - return pkt->ext_bitmap; -} - -static inline void net_pkt_set_ext_bitmap(struct net_pkt *pkt, uint8_t bm) -{ - pkt->ext_bitmap = bm; -} - -static inline void net_pkt_add_ext_bitmap(struct net_pkt *pkt, uint8_t bm) -{ - pkt->ext_bitmap |= bm; -} - static inline uint8_t *net_pkt_next_hdr(struct net_pkt *pkt) { return pkt->next_hdr; diff --git a/subsys/net/ip/ipv6.c b/subsys/net/ip/ipv6.c index a7d14e26e03..cba587561cf 100644 --- a/subsys/net/ip/ipv6.c +++ b/subsys/net/ip/ipv6.c @@ -3493,6 +3493,7 @@ enum net_verdict net_ipv6_process_pkt(struct net_pkt *pkt) uint8_t next, next_hdr, length; uint8_t first_option; uint16_t offset, total_len = 0; + uint8_t ext_bitmap; if (real_len != pkt_len) { NET_DBG("IPv6 packet size %d pkt len %d", pkt_len, real_len); @@ -3556,7 +3557,6 @@ enum net_verdict net_ipv6_process_pkt(struct net_pkt *pkt) /* Check extension headers */ net_pkt_set_next_hdr(pkt, &hdr->nexthdr); net_pkt_set_ext_len(pkt, 0); - net_pkt_set_ext_bitmap(pkt, 0); net_pkt_set_ip_hdr_len(pkt, sizeof(struct net_ipv6_hdr)); /* Fast path for main upper layer protocols. The handling of extension @@ -3572,6 +3572,7 @@ enum net_verdict net_ipv6_process_pkt(struct net_pkt *pkt) frag = pkt->frags; next = hdr->nexthdr; first_option = next; + ext_bitmap = 0; offset = sizeof(struct net_ipv6_hdr); prev_hdr = &NET_IPV6_BUF(pkt)->nexthdr - &NET_IPV6_BUF(pkt)->vtc; @@ -3621,13 +3622,11 @@ enum net_verdict net_ipv6_process_pkt(struct net_pkt *pkt) } /* Hop by hop option */ - if (net_pkt_ext_bitmap(pkt) & - NET_IPV6_EXT_HDR_BITMAP_HBHO) { + if (ext_bitmap & NET_IPV6_EXT_HDR_BITMAP_HBHO) { goto bad_hdr; } - net_pkt_add_ext_bitmap(pkt, - NET_IPV6_EXT_HDR_BITMAP_HBHO); + ext_bitmap |= NET_IPV6_EXT_HDR_BITMAP_HBHO; frag = handle_ext_hdr_options(pkt, frag, real_len, length, offset, &offset, diff --git a/subsys/net/ip/ipv6.h b/subsys/net/ip/ipv6.h index e6a8d09c6b2..4a6079abe77 100644 --- a/subsys/net/ip/ipv6.h +++ b/subsys/net/ip/ipv6.h @@ -35,16 +35,17 @@ * * When processing extension headers, we record which one we have seen. * This is done as the network packet cannot have twice the same header, - * except for destination option. This information is stored in bitfield variable. + * except for destination option. + * This information is stored in bitfield variable. * The order of the bitmap is the order recommended in RFC 2460. */ -#define NET_IPV6_EXT_HDR_BITMAP_HBHO 0x01 -#define NET_IPV6_EXT_HDR_BITMAP_DESTO1 0x02 -#define NET_IPV6_EXT_HDR_BITMAP_ROUTING 0x04 -#define NET_IPV6_EXT_HDR_BITMAP_FRAG 0x08 -#define NET_IPV6_EXT_HDR_BITMAP_AH 0x10 -#define NET_IPV6_EXT_HDR_BITMAP_ESP 0x20 -#define NET_IPV6_EXT_HDR_BITMAP_DESTO2 0x40 +#define NET_IPV6_EXT_HDR_BITMAP_HBHO 0x01 +#define NET_IPV6_EXT_HDR_BITMAP_DESTO1 0x02 +#define NET_IPV6_EXT_HDR_BITMAP_ROUTING 0x04 +#define NET_IPV6_EXT_HDR_BITMAP_FRAG 0x08 +#define NET_IPV6_EXT_HDR_BITMAP_AH 0x10 +#define NET_IPV6_EXT_HDR_BITMAP_ESP 0x20 +#define NET_IPV6_EXT_HDR_BITMAP_DESTO2 0x40 /** * @brief Destination and Hop By Hop extension headers option types