From: Ansis Atteka Date: Tue, 6 Nov 2012 15:12:38 +0000 (+0200) Subject: datapath: improve ipv6_find_hdr() function for IPv6 'set' action X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=248a2130b0374d046057b2995c645c23172d4b84;p=openvswitch datapath: improve ipv6_find_hdr() function for IPv6 'set' action This patch prepares ipv6_find_hdr() function so that it could be able to skip routing headers, where segements_left is 0. This is required for us to handle multiple routing header case correctly. Signed-off-by: Ansis Atteka --- diff --git a/datapath/linux/compat/exthdrs_core.c b/datapath/linux/compat/exthdrs_core.c index 1749c066..eb56e6b2 100644 --- a/datapath/linux/compat/exthdrs_core.c +++ b/datapath/linux/compat/exthdrs_core.c @@ -70,7 +70,8 @@ int rpl_ipv6_skip_exthdr(const struct sk_buff *skb, int start, * if flags is not NULL and it's a fragment, then the frag flag * OVS_IP6T_FH_F_FRAG will be set. If it's an AH header, the * OVS_IP6T_FH_F_AUTH flag is set and target < 0, then this function will - * stop at the AH header. + * stop at the AH header. If OVS_IP6T_FH_F_SKIP_RH flag was passed, then this + * function will skip all those routing headers, where segements_left was 0. */ int rpl_ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset, int target, unsigned short *fragoff, int *flags) @@ -78,6 +79,7 @@ int rpl_ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset, unsigned int start = skb_network_offset(skb) + sizeof(struct ipv6hdr); u8 nexthdr = ipv6_hdr(skb)->nexthdr; unsigned int len; + bool found; if (fragoff) *fragoff = 0; @@ -95,9 +97,10 @@ int rpl_ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset, } len = skb->len - start; - while (nexthdr != target) { + do { struct ipv6_opt_hdr _hdr, *hp; unsigned int hdrlen; + found = (nexthdr == target); if ((!ipv6_ext_hdr(nexthdr)) || nexthdr == NEXTHDR_NONE) { if (target < 0) @@ -108,6 +111,20 @@ int rpl_ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset, hp = skb_header_pointer(skb, start, sizeof(_hdr), &_hdr); if (hp == NULL) return -EBADMSG; + + if (nexthdr == NEXTHDR_ROUTING) { + struct ipv6_rt_hdr _rh, *rh; + + rh = skb_header_pointer(skb, start, sizeof(_rh), + &_rh); + if (rh == NULL) + return -EBADMSG; + + if (flags && (*flags & OVS_IP6T_FH_F_SKIP_RH) && + rh->segments_left == 0) + found = false; + } + if (nexthdr == NEXTHDR_FRAGMENT) { unsigned short _frag_off; __be16 *fp; @@ -142,10 +159,12 @@ int rpl_ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset, } else hdrlen = ipv6_optlen(hp); - nexthdr = hp->nexthdr; - len -= hdrlen; - start += hdrlen; - } + if (!found) { + nexthdr = hp->nexthdr; + len -= hdrlen; + start += hdrlen; + } + } while (!found); *offset = start; return nexthdr; diff --git a/datapath/linux/compat/include/net/ipv6.h b/datapath/linux/compat/include/net/ipv6.h index 9ba85594..09115a49 100644 --- a/datapath/linux/compat/include/net/ipv6.h +++ b/datapath/linux/compat/include/net/ipv6.h @@ -6,6 +6,7 @@ enum { OVS_IP6T_FH_F_FRAG = (1 << 0), OVS_IP6T_FH_F_AUTH = (1 << 1), + OVS_IP6T_FH_F_SKIP_RH = (1 << 2), }; /* This function is upstream but not the version which supplies the