Skip to content

Commit c61a404

Browse files
Masahide NAKAMURADavid S. Miller
authored andcommitted
[IPV6]: Find option offset by type.
This is a helper to search option offset from extension header which can carry TLV option like destination options header. Mobile IPv6 home address option will use it. Based on MIPL2 kernel patch. Signed-off-by: Masahide NAKAMURA <[email protected]> Signed-off-by: YOSHIFUJI Hideaki <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 280a9d3 commit c61a404

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

include/net/ipv6.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,8 @@ extern int ipv6_skip_exthdr(const struct sk_buff *, int start,
506506

507507
extern int ipv6_ext_hdr(u8 nexthdr);
508508

509+
extern int ipv6_find_tlv(struct sk_buff *skb, int offset, int type);
510+
509511
extern struct ipv6_txoptions * ipv6_invert_rthdr(struct sock *sk,
510512
struct ipv6_rt_hdr *hdr);
511513

net/ipv6/exthdrs.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,49 @@
4949

5050
#include <asm/uaccess.h>
5151

52+
int ipv6_find_tlv(struct sk_buff *skb, int offset, int type)
53+
{
54+
int packet_len = skb->tail - skb->nh.raw;
55+
struct ipv6_opt_hdr *hdr;
56+
int len;
57+
58+
if (offset + 2 > packet_len)
59+
goto bad;
60+
hdr = (struct ipv6_opt_hdr*)(skb->nh.raw + offset);
61+
len = ((hdr->hdrlen + 1) << 3);
62+
63+
if (offset + len > packet_len)
64+
goto bad;
65+
66+
offset += 2;
67+
len -= 2;
68+
69+
while (len > 0) {
70+
int opttype = skb->nh.raw[offset];
71+
int optlen;
72+
73+
if (opttype == type)
74+
return offset;
75+
76+
switch (opttype) {
77+
case IPV6_TLV_PAD0:
78+
optlen = 1;
79+
break;
80+
default:
81+
optlen = skb->nh.raw[offset + 1] + 2;
82+
if (optlen > len)
83+
goto bad;
84+
break;
85+
}
86+
offset += optlen;
87+
len -= optlen;
88+
}
89+
/* not_found */
90+
return -1;
91+
bad:
92+
return -1;
93+
}
94+
5295
/*
5396
* Parsing tlv encoded headers.
5497
*

0 commit comments

Comments
 (0)