* 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)
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;
}
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)
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;
} 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;