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 <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
Tomasz Bursztyka 2017-04-07 12:04:28 +02:00 committed by Jukka Rissanen
commit c18016b69b
3 changed files with 13 additions and 29 deletions

View file

@ -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;

View file

@ -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,

View file

@ -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