]>
Commit | Line | Data |
---|---|---|
3c73a036 VY |
1 | /* |
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> | |
3ce9b35f | 8 | #include <net/addrconf.h> |
6dfac5c3 | 9 | #include <net/secure_seq.h> |
3c73a036 VY |
10 | |
11 | void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt) | |
12 | { | |
13 | static atomic_t ipv6_fragmentation_id; | |
6dfac5c3 | 14 | struct in6_addr addr; |
3c73a036 VY |
15 | int old, new; |
16 | ||
17 | #if IS_ENABLED(CONFIG_IPV6) | |
6dfac5c3 HFS |
18 | struct inet_peer *peer; |
19 | struct net *net; | |
3c73a036 | 20 | |
6dfac5c3 HFS |
21 | net = dev_net(rt->dst.dev); |
22 | peer = inet_getpeer_v6(net->ipv6.peers, &rt->rt6i_dst.addr, 1); | |
23 | if (peer) { | |
24 | fhdr->identification = htonl(inet_getid(peer, 0)); | |
25 | inet_putpeer(peer); | |
26 | return; | |
3c73a036 VY |
27 | } |
28 | #endif | |
29 | do { | |
30 | old = atomic_read(&ipv6_fragmentation_id); | |
31 | new = old + 1; | |
32 | if (!new) | |
33 | new = 1; | |
34 | } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old); | |
6dfac5c3 HFS |
35 | |
36 | addr = rt->rt6i_dst.addr; | |
37 | addr.s6_addr32[0] ^= (__force __be32)new; | |
38 | fhdr->identification = htonl(secure_ipv6_id(addr.s6_addr32)); | |
3c73a036 VY |
39 | } |
40 | EXPORT_SYMBOL(ipv6_select_ident); | |
41 | ||
42 | int ip6_find_1stfragopt(struct sk_buff *skb, u8 **nexthdr) | |
43 | { | |
44 | u16 offset = sizeof(struct ipv6hdr); | |
45 | struct ipv6_opt_hdr *exthdr = | |
46 | (struct ipv6_opt_hdr *)(ipv6_hdr(skb) + 1); | |
29a3cad5 SH |
47 | unsigned int packet_len = skb_tail_pointer(skb) - |
48 | skb_network_header(skb); | |
3c73a036 VY |
49 | int found_rhdr = 0; |
50 | *nexthdr = &ipv6_hdr(skb)->nexthdr; | |
51 | ||
52 | while (offset + 1 <= packet_len) { | |
53 | ||
54 | switch (**nexthdr) { | |
55 | ||
56 | case NEXTHDR_HOP: | |
57 | break; | |
58 | case NEXTHDR_ROUTING: | |
59 | found_rhdr = 1; | |
60 | break; | |
61 | case NEXTHDR_DEST: | |
62 | #if IS_ENABLED(CONFIG_IPV6_MIP6) | |
63 | if (ipv6_find_tlv(skb, offset, IPV6_TLV_HAO) >= 0) | |
64 | break; | |
65 | #endif | |
66 | if (found_rhdr) | |
67 | return offset; | |
68 | break; | |
69 | default : | |
70 | return offset; | |
71 | } | |
72 | ||
73 | offset += ipv6_optlen(exthdr); | |
74 | *nexthdr = &exthdr->nexthdr; | |
75 | exthdr = (struct ipv6_opt_hdr *)(skb_network_header(skb) + | |
76 | offset); | |
77 | } | |
78 | ||
79 | return offset; | |
80 | } | |
81 | EXPORT_SYMBOL(ip6_find_1stfragopt); | |
3ce9b35f CW |
82 | |
83 | #if IS_ENABLED(CONFIG_IPV6) | |
84 | int ip6_dst_hoplimit(struct dst_entry *dst) | |
85 | { | |
86 | int hoplimit = dst_metric_raw(dst, RTAX_HOPLIMIT); | |
87 | if (hoplimit == 0) { | |
88 | struct net_device *dev = dst->dev; | |
89 | struct inet6_dev *idev; | |
90 | ||
91 | rcu_read_lock(); | |
92 | idev = __in6_dev_get(dev); | |
93 | if (idev) | |
94 | hoplimit = idev->cnf.hop_limit; | |
95 | else | |
96 | hoplimit = dev_net(dev)->ipv6.devconf_all->hop_limit; | |
97 | rcu_read_unlock(); | |
98 | } | |
99 | return hoplimit; | |
100 | } | |
101 | EXPORT_SYMBOL(ip6_dst_hoplimit); | |
102 | #endif | |
788787b5 CW |
103 | |
104 | int __ip6_local_out(struct sk_buff *skb) | |
105 | { | |
106 | int len; | |
107 | ||
108 | len = skb->len - sizeof(struct ipv6hdr); | |
109 | if (len > IPV6_MAXPLEN) | |
110 | len = 0; | |
111 | ipv6_hdr(skb)->payload_len = htons(len); | |
112 | ||
113 | return nf_hook(NFPROTO_IPV6, NF_INET_LOCAL_OUT, skb, NULL, | |
114 | skb_dst(skb)->dev, dst_output); | |
115 | } | |
116 | EXPORT_SYMBOL_GPL(__ip6_local_out); | |
117 | ||
118 | int ip6_local_out(struct sk_buff *skb) | |
119 | { | |
120 | int err; | |
121 | ||
122 | err = __ip6_local_out(skb); | |
123 | if (likely(err == 1)) | |
124 | err = dst_output(skb); | |
125 | ||
126 | return err; | |
127 | } | |
128 | EXPORT_SYMBOL_GPL(ip6_local_out); |