]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - net/ipv6/exthdrs_core.c
vlan: Move vlan_set_encap_proto() to vlan header file
[mirror_ubuntu-artful-kernel.git] / net / ipv6 / exthdrs_core.c
CommitLineData
1da177e4
LT
1/*
2 * IPv6 library code, needed by static components when full IPv6 support is
3 * not configured or static.
4 */
bc3b2d7f 5#include <linux/export.h>
1da177e4
LT
6#include <net/ipv6.h>
7
1ab1457c 8/*
1da177e4
LT
9 * find out if nexthdr is a well-known extension header or a protocol
10 */
11
12int ipv6_ext_hdr(u8 nexthdr)
13{
1ab1457c 14 /*
1da177e4
LT
15 * find out if nexthdr is an extension header or a protocol
16 */
a02cec21 17 return (nexthdr == NEXTHDR_HOP) ||
1da177e4
LT
18 (nexthdr == NEXTHDR_ROUTING) ||
19 (nexthdr == NEXTHDR_FRAGMENT) ||
20 (nexthdr == NEXTHDR_AUTH) ||
21 (nexthdr == NEXTHDR_NONE) ||
a02cec21 22 (nexthdr == NEXTHDR_DEST);
1da177e4
LT
23}
24
25/*
26 * Skip any extension headers. This is used by the ICMP module.
27 *
28 * Note that strictly speaking this conflicts with RFC 2460 4.0:
1ab1457c 29 * ...The contents and semantics of each extension header determine whether
1da177e4
LT
30 * or not to proceed to the next header. Therefore, extension headers must
31 * be processed strictly in the order they appear in the packet; a
32 * receiver must not, for example, scan through a packet looking for a
33 * particular kind of extension header and process that header prior to
34 * processing all preceding ones.
1ab1457c 35 *
1da177e4 36 * We do exactly this. This is a protocol bug. We can't decide after a
1ab1457c 37 * seeing an unknown discard-with-error flavour TLV option if it's a
1da177e4
LT
38 * ICMP error message or not (errors should never be send in reply to
39 * ICMP error messages).
1ab1457c 40 *
1da177e4
LT
41 * But I see no other way to do this. This might need to be reexamined
42 * when Linux implements ESP (and maybe AUTH) headers.
43 * --AK
44 *
0d3d077c
HX
45 * This function parses (probably truncated) exthdr set "hdr".
46 * "nexthdrp" initially points to some place,
1da177e4
LT
47 * where type of the first header can be found.
48 *
49 * It skips all well-known exthdrs, and returns pointer to the start
50 * of unparsable area i.e. the first header with unknown type.
51 * If it is not NULL *nexthdr is updated by type/protocol of this header.
52 *
53 * NOTES: - if packet terminated with NEXTHDR_NONE it returns NULL.
54 * - it may return pointer pointing beyond end of packet,
55 * if the last recognized header is truncated in the middle.
56 * - if packet is truncated, so that all parsed headers are skipped,
57 * it returns NULL.
58 * - First fragment header is skipped, not-first ones
59 * are considered as unparsable.
60 * - ESP is unparsable for now and considered like
61 * normal payload protocol.
62 * - Note also special handling of AUTH header. Thanks to IPsec wizards.
63 *
64 * --ANK (980726)
65 */
66
0d3d077c 67int ipv6_skip_exthdr(const struct sk_buff *skb, int start, u8 *nexthdrp)
1da177e4
LT
68{
69 u8 nexthdr = *nexthdrp;
70
71 while (ipv6_ext_hdr(nexthdr)) {
72 struct ipv6_opt_hdr _hdr, *hp;
73 int hdrlen;
74
1da177e4
LT
75 if (nexthdr == NEXTHDR_NONE)
76 return -1;
77 hp = skb_header_pointer(skb, start, sizeof(_hdr), &_hdr);
78 if (hp == NULL)
0d3d077c 79 return -1;
1da177e4 80 if (nexthdr == NEXTHDR_FRAGMENT) {
e69a4adc 81 __be16 _frag_off, *fp;
1da177e4
LT
82 fp = skb_header_pointer(skb,
83 start+offsetof(struct frag_hdr,
84 frag_off),
85 sizeof(_frag_off),
86 &_frag_off);
87 if (fp == NULL)
88 return -1;
89
90 if (ntohs(*fp) & ~0x7)
91 break;
92 hdrlen = 8;
93 } else if (nexthdr == NEXTHDR_AUTH)
1ab1457c 94 hdrlen = (hp->hdrlen+2)<<2;
1da177e4 95 else
1ab1457c 96 hdrlen = ipv6_optlen(hp);
1da177e4
LT
97
98 nexthdr = hp->nexthdr;
1da177e4
LT
99 start += hdrlen;
100 }
101
102 *nexthdrp = nexthdr;
103 return start;
104}
105
106EXPORT_SYMBOL(ipv6_ext_hdr);
107EXPORT_SYMBOL(ipv6_skip_exthdr);