2 * IPv6 library code, needed by static components when full IPv6 support is
3 * not configured or static.
5 #include <linux/export.h>
9 * find out if nexthdr is a well-known extension header or a protocol
12 bool ipv6_ext_hdr(u8 nexthdr
)
15 * find out if nexthdr is an extension header or a protocol
17 return (nexthdr
== NEXTHDR_HOP
) ||
18 (nexthdr
== NEXTHDR_ROUTING
) ||
19 (nexthdr
== NEXTHDR_FRAGMENT
) ||
20 (nexthdr
== NEXTHDR_AUTH
) ||
21 (nexthdr
== NEXTHDR_NONE
) ||
22 (nexthdr
== NEXTHDR_DEST
);
24 EXPORT_SYMBOL(ipv6_ext_hdr
);
27 * Skip any extension headers. This is used by the ICMP module.
29 * Note that strictly speaking this conflicts with RFC 2460 4.0:
30 * ...The contents and semantics of each extension header determine whether
31 * or not to proceed to the next header. Therefore, extension headers must
32 * be processed strictly in the order they appear in the packet; a
33 * receiver must not, for example, scan through a packet looking for a
34 * particular kind of extension header and process that header prior to
35 * processing all preceding ones.
37 * We do exactly this. This is a protocol bug. We can't decide after a
38 * seeing an unknown discard-with-error flavour TLV option if it's a
39 * ICMP error message or not (errors should never be send in reply to
40 * ICMP error messages).
42 * But I see no other way to do this. This might need to be reexamined
43 * when Linux implements ESP (and maybe AUTH) headers.
46 * This function parses (probably truncated) exthdr set "hdr".
47 * "nexthdrp" initially points to some place,
48 * where type of the first header can be found.
50 * It skips all well-known exthdrs, and returns pointer to the start
51 * of unparsable area i.e. the first header with unknown type.
52 * If it is not NULL *nexthdr is updated by type/protocol of this header.
54 * NOTES: - if packet terminated with NEXTHDR_NONE it returns NULL.
55 * - it may return pointer pointing beyond end of packet,
56 * if the last recognized header is truncated in the middle.
57 * - if packet is truncated, so that all parsed headers are skipped,
59 * - First fragment header is skipped, not-first ones
60 * are considered as unparsable.
61 * - Reports the offset field of the final fragment header so it is
62 * possible to tell whether this is a first fragment, later fragment,
64 * - ESP is unparsable for now and considered like
65 * normal payload protocol.
66 * - Note also special handling of AUTH header. Thanks to IPsec wizards.
71 int ipv6_skip_exthdr(const struct sk_buff
*skb
, int start
, u8
*nexthdrp
,
74 u8 nexthdr
= *nexthdrp
;
78 while (ipv6_ext_hdr(nexthdr
)) {
79 struct ipv6_opt_hdr _hdr
, *hp
;
82 if (nexthdr
== NEXTHDR_NONE
)
84 hp
= skb_header_pointer(skb
, start
, sizeof(_hdr
), &_hdr
);
87 if (nexthdr
== NEXTHDR_FRAGMENT
) {
88 __be16 _frag_off
, *fp
;
89 fp
= skb_header_pointer(skb
,
90 start
+offsetof(struct frag_hdr
,
98 if (ntohs(*frag_offp
) & ~0x7)
101 } else if (nexthdr
== NEXTHDR_AUTH
)
102 hdrlen
= (hp
->hdrlen
+2)<<2;
104 hdrlen
= ipv6_optlen(hp
);
106 nexthdr
= hp
->nexthdr
;
113 EXPORT_SYMBOL(ipv6_skip_exthdr
);