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 <aatt...@nicira.com>
---
 datapath/linux/compat/exthdrs_core.c     |   41 ++++++++++++++++++++++--------
 datapath/linux/compat/include/net/ipv6.h |    5 ++--
 2 files changed, 34 insertions(+), 12 deletions(-)

diff --git a/datapath/linux/compat/exthdrs_core.c 
b/datapath/linux/compat/exthdrs_core.c
index ca5597f..2022ac2 100644
--- a/datapath/linux/compat/exthdrs_core.c
+++ b/datapath/linux/compat/exthdrs_core.c
@@ -67,9 +67,11 @@ int rpl_ipv6_skip_exthdr(const struct sk_buff *skb, int 
start,
  * *offset is meaningless and fragment offset is stored in *fragoff if fragoff
  * isn't NULL.
  *
- * if flags is not NULL and it's a fragment, then the frag flag IP6T_FH_F_FRAG
- * will be set. If it's an AH header, the IP6T_FH_F_AUTH flag is set and
- * target < 0, then this function will stop at the AH header.
+ * 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. 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 ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset,
                  int target, unsigned short *fragoff, int *flags)
@@ -77,6 +79,7 @@ int 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;
@@ -94,9 +97,10 @@ int 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)
@@ -107,12 +111,26 @@ int 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;
 
                        if (flags)      /* Indicate that this is a fragment */
-                               *flags |= IP6T_FH_F_FRAG;
+                               *flags |= OVS_IP6T_FH_F_FRAG;
                        fp = skb_header_pointer(skb,
                                                start+offsetof(struct frag_hdr,
                                                               frag_off),
@@ -134,16 +152,19 @@ int ipv6_find_hdr(const struct sk_buff *skb, unsigned int 
*offset,
                        }
                        hdrlen = 8;
                } else if (nexthdr == NEXTHDR_AUTH) {
-                       if (flags && (*flags & IP6T_FH_F_AUTH) && (target < 0))
+                       if (flags && (*flags & OVS_IP6T_FH_F_AUTH) &&
+                           (target < 0))
                                break;
                        hdrlen = (hp->hdrlen + 2) << 2;
                } 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 0b82ec2..09115a4 100644
--- a/datapath/linux/compat/include/net/ipv6.h
+++ b/datapath/linux/compat/include/net/ipv6.h
@@ -4,8 +4,9 @@
 #include_next <net/ipv6.h>
 
 enum {
-       IP6T_FH_F_FRAG  = (1 << 0),
-       IP6T_FH_F_AUTH  = (1 << 1),
+       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
-- 
1.7.9.5

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to