ipv6: Change skb->data before using icmpv6_notify() to propagate redirect
[deliverable/linux.git] / net / ipv6 / exthdrs_core.c
index 8ea253ad35b1762e4b30dfa7e20ea71d092bc642..c5e83fae4df423ccbe02bed8bf31ffd415014ad2 100644 (file)
@@ -112,6 +112,50 @@ int ipv6_skip_exthdr(const struct sk_buff *skb, int start, u8 *nexthdrp,
 }
 EXPORT_SYMBOL(ipv6_skip_exthdr);
 
+int ipv6_find_tlv(struct sk_buff *skb, int offset, int type)
+{
+       const unsigned char *nh = skb_network_header(skb);
+       int packet_len = skb->tail - skb->network_header;
+       struct ipv6_opt_hdr *hdr;
+       int len;
+
+       if (offset + 2 > packet_len)
+               goto bad;
+       hdr = (struct ipv6_opt_hdr *)(nh + offset);
+       len = ((hdr->hdrlen + 1) << 3);
+
+       if (offset + len > packet_len)
+               goto bad;
+
+       offset += 2;
+       len -= 2;
+
+       while (len > 0) {
+               int opttype = nh[offset];
+               int optlen;
+
+               if (opttype == type)
+                       return offset;
+
+               switch (opttype) {
+               case IPV6_TLV_PAD1:
+                       optlen = 1;
+                       break;
+               default:
+                       optlen = nh[offset + 1] + 2;
+                       if (optlen > len)
+                               goto bad;
+                       break;
+               }
+               offset += optlen;
+               len -= optlen;
+       }
+       /* not_found */
+ bad:
+       return -1;
+}
+EXPORT_SYMBOL_GPL(ipv6_find_tlv);
+
 /*
  * find the offset to specified header or the protocol number of last header
  * if target < 0. "last header" is transport protocol header, ESP, or
@@ -132,9 +176,11 @@ EXPORT_SYMBOL(ipv6_skip_exthdr);
  * *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 IP6_FH_F_FRAG
- * will be set. If it's an AH header, the IP6_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
+ * IP6_FH_F_FRAG will be set. If it's an AH header, the
+ * IP6_FH_F_AUTH flag is set and target < 0, then this function will
+ * stop at the AH header. If IP6_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)
@@ -142,6 +188,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;
@@ -159,9 +206,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)
@@ -172,6 +220,20 @@ 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 & IP6_FH_F_SKIP_RH) &&
+                           rh->segments_left == 0)
+                               found = false;
+               }
+
                if (nexthdr == NEXTHDR_FRAGMENT) {
                        unsigned short _frag_off;
                        __be16 *fp;
@@ -205,12 +267,15 @@ int 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;
 }
 EXPORT_SYMBOL(ipv6_find_hdr);
+
This page took 0.026188 seconds and 5 git commands to generate.