diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /net/ipv6/exthdrs_core.c |
Linux-2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'net/ipv6/exthdrs_core.c')
-rw-r--r-- | net/ipv6/exthdrs_core.c | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/net/ipv6/exthdrs_core.c b/net/ipv6/exthdrs_core.c new file mode 100644 index 00000000000..6dda815c013 --- /dev/null +++ b/net/ipv6/exthdrs_core.c | |||
@@ -0,0 +1,109 @@ | |||
1 | /* | ||
2 | * IPv6 library code, needed by static components when full IPv6 support is | ||
3 | * not configured or static. | ||
4 | */ | ||
5 | #include <net/ipv6.h> | ||
6 | |||
7 | /* | ||
8 | * find out if nexthdr is a well-known extension header or a protocol | ||
9 | */ | ||
10 | |||
11 | int ipv6_ext_hdr(u8 nexthdr) | ||
12 | { | ||
13 | /* | ||
14 | * find out if nexthdr is an extension header or a protocol | ||
15 | */ | ||
16 | return ( (nexthdr == NEXTHDR_HOP) || | ||
17 | (nexthdr == NEXTHDR_ROUTING) || | ||
18 | (nexthdr == NEXTHDR_FRAGMENT) || | ||
19 | (nexthdr == NEXTHDR_AUTH) || | ||
20 | (nexthdr == NEXTHDR_NONE) || | ||
21 | (nexthdr == NEXTHDR_DEST) ); | ||
22 | } | ||
23 | |||
24 | /* | ||
25 | * Skip any extension headers. This is used by the ICMP module. | ||
26 | * | ||
27 | * Note that strictly speaking this conflicts with RFC 2460 4.0: | ||
28 | * ...The contents and semantics of each extension header determine whether | ||
29 | * or not to proceed to the next header. Therefore, extension headers must | ||
30 | * be processed strictly in the order they appear in the packet; a | ||
31 | * receiver must not, for example, scan through a packet looking for a | ||
32 | * particular kind of extension header and process that header prior to | ||
33 | * processing all preceding ones. | ||
34 | * | ||
35 | * We do exactly this. This is a protocol bug. We can't decide after a | ||
36 | * seeing an unknown discard-with-error flavour TLV option if it's a | ||
37 | * ICMP error message or not (errors should never be send in reply to | ||
38 | * ICMP error messages). | ||
39 | * | ||
40 | * But I see no other way to do this. This might need to be reexamined | ||
41 | * when Linux implements ESP (and maybe AUTH) headers. | ||
42 | * --AK | ||
43 | * | ||
44 | * This function parses (probably truncated) exthdr set "hdr" | ||
45 | * of length "len". "nexthdrp" initially points to some place, | ||
46 | * where type of the first header can be found. | ||
47 | * | ||
48 | * It skips all well-known exthdrs, and returns pointer to the start | ||
49 | * of unparsable area i.e. the first header with unknown type. | ||
50 | * If it is not NULL *nexthdr is updated by type/protocol of this header. | ||
51 | * | ||
52 | * NOTES: - if packet terminated with NEXTHDR_NONE it returns NULL. | ||
53 | * - it may return pointer pointing beyond end of packet, | ||
54 | * if the last recognized header is truncated in the middle. | ||
55 | * - if packet is truncated, so that all parsed headers are skipped, | ||
56 | * it returns NULL. | ||
57 | * - First fragment header is skipped, not-first ones | ||
58 | * are considered as unparsable. | ||
59 | * - ESP is unparsable for now and considered like | ||
60 | * normal payload protocol. | ||
61 | * - Note also special handling of AUTH header. Thanks to IPsec wizards. | ||
62 | * | ||
63 | * --ANK (980726) | ||
64 | */ | ||
65 | |||
66 | int ipv6_skip_exthdr(const struct sk_buff *skb, int start, u8 *nexthdrp, int len) | ||
67 | { | ||
68 | u8 nexthdr = *nexthdrp; | ||
69 | |||
70 | while (ipv6_ext_hdr(nexthdr)) { | ||
71 | struct ipv6_opt_hdr _hdr, *hp; | ||
72 | int hdrlen; | ||
73 | |||
74 | if (len < (int)sizeof(struct ipv6_opt_hdr)) | ||
75 | return -1; | ||
76 | if (nexthdr == NEXTHDR_NONE) | ||
77 | return -1; | ||
78 | hp = skb_header_pointer(skb, start, sizeof(_hdr), &_hdr); | ||
79 | if (hp == NULL) | ||
80 | BUG(); | ||
81 | if (nexthdr == NEXTHDR_FRAGMENT) { | ||
82 | unsigned short _frag_off, *fp; | ||
83 | fp = skb_header_pointer(skb, | ||
84 | start+offsetof(struct frag_hdr, | ||
85 | frag_off), | ||
86 | sizeof(_frag_off), | ||
87 | &_frag_off); | ||
88 | if (fp == NULL) | ||
89 | return -1; | ||
90 | |||
91 | if (ntohs(*fp) & ~0x7) | ||
92 | break; | ||
93 | hdrlen = 8; | ||
94 | } else if (nexthdr == NEXTHDR_AUTH) | ||
95 | hdrlen = (hp->hdrlen+2)<<2; | ||
96 | else | ||
97 | hdrlen = ipv6_optlen(hp); | ||
98 | |||
99 | nexthdr = hp->nexthdr; | ||
100 | len -= hdrlen; | ||
101 | start += hdrlen; | ||
102 | } | ||
103 | |||
104 | *nexthdrp = nexthdr; | ||
105 | return start; | ||
106 | } | ||
107 | |||
108 | EXPORT_SYMBOL(ipv6_ext_hdr); | ||
109 | EXPORT_SYMBOL(ipv6_skip_exthdr); | ||