blob: ab92a3673fbbddd9f3d32b69730c3b1b61fbcbde [file] [log] [blame]
Vlad Yasevich3c73a032012-11-15 08:49:20 +00001/*
2 * IPv6 library code, needed by static components when full IPv6 support is
3 * not configured or static. These functions are needed by GSO/GRO implementation.
4 */
5#include <linux/export.h>
6#include <net/ipv6.h>
7#include <net/ip6_fib.h>
8
9void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
10{
11 static atomic_t ipv6_fragmentation_id;
12 int old, new;
13
14#if IS_ENABLED(CONFIG_IPV6)
15 if (rt && !(rt->dst.flags & DST_NOPEER)) {
16 struct inet_peer *peer;
17 struct net *net;
18
19 net = dev_net(rt->dst.dev);
20 peer = inet_getpeer_v6(net->ipv6.peers, &rt->rt6i_dst.addr, 1);
21 if (peer) {
22 fhdr->identification = htonl(inet_getid(peer, 0));
23 inet_putpeer(peer);
24 return;
25 }
26 }
27#endif
28 do {
29 old = atomic_read(&ipv6_fragmentation_id);
30 new = old + 1;
31 if (!new)
32 new = 1;
33 } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
34 fhdr->identification = htonl(new);
35}
36EXPORT_SYMBOL(ipv6_select_ident);
37
38int ip6_find_1stfragopt(struct sk_buff *skb, u8 **nexthdr)
39{
40 u16 offset = sizeof(struct ipv6hdr);
41 struct ipv6_opt_hdr *exthdr =
42 (struct ipv6_opt_hdr *)(ipv6_hdr(skb) + 1);
Simon Horman29a3cad2013-05-28 20:34:26 +000043 unsigned int packet_len = skb_tail_pointer(skb) -
44 skb_network_header(skb);
Vlad Yasevich3c73a032012-11-15 08:49:20 +000045 int found_rhdr = 0;
46 *nexthdr = &ipv6_hdr(skb)->nexthdr;
47
48 while (offset + 1 <= packet_len) {
49
50 switch (**nexthdr) {
51
52 case NEXTHDR_HOP:
53 break;
54 case NEXTHDR_ROUTING:
55 found_rhdr = 1;
56 break;
57 case NEXTHDR_DEST:
58#if IS_ENABLED(CONFIG_IPV6_MIP6)
59 if (ipv6_find_tlv(skb, offset, IPV6_TLV_HAO) >= 0)
60 break;
61#endif
62 if (found_rhdr)
63 return offset;
64 break;
65 default :
66 return offset;
67 }
68
69 offset += ipv6_optlen(exthdr);
70 *nexthdr = &exthdr->nexthdr;
71 exthdr = (struct ipv6_opt_hdr *)(skb_network_header(skb) +
72 offset);
73 }
74
75 return offset;
76}
77EXPORT_SYMBOL(ip6_find_1stfragopt);