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.
5 #include <linux/export.h>
8 #include <net/ip6_fib.h>
9 #include <net/addrconf.h>
10 #include <net/secure_seq.h>
12 static u32 __ipv6_select_ident(u32 hashrnd, struct in6_addr *dst,
17 hash = __ipv6_addr_jhash(dst, hashrnd);
18 hash = __ipv6_addr_jhash(src, hash);
20 /* Treat id of 0 as unset and if we get 0 back from ip_idents_reserve,
21 * set the hight order instead thus minimizing possible future
24 id = ip_idents_reserve(hash, 1);
31 /* This function exists only for tap drivers that must support broken
32 * clients requesting UFO without specifying an IPv6 fragment ID.
34 * This is similar to ipv6_select_ident() but we use an independent hash
35 * seed to limit information leakage.
37 * The network header must be set before calling this.
39 void ipv6_proxy_select_ident(struct sk_buff *skb)
41 static u32 ip6_proxy_idents_hashrnd __read_mostly;
42 struct in6_addr buf[2];
43 struct in6_addr *addrs;
46 addrs = skb_header_pointer(skb,
47 skb_network_offset(skb) +
48 offsetof(struct ipv6hdr, saddr),
53 net_get_random_once(&ip6_proxy_idents_hashrnd,
54 sizeof(ip6_proxy_idents_hashrnd));
56 id = __ipv6_select_ident(ip6_proxy_idents_hashrnd,
57 &addrs[1], &addrs[0]);
58 skb_shinfo(skb)->ip6_frag_id = htonl(id);
60 EXPORT_SYMBOL_GPL(ipv6_proxy_select_ident);
62 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
64 static u32 ip6_idents_hashrnd __read_mostly;
67 net_get_random_once(&ip6_idents_hashrnd, sizeof(ip6_idents_hashrnd));
69 id = __ipv6_select_ident(ip6_idents_hashrnd, &rt->rt6i_dst.addr,
71 fhdr->identification = htonl(id);
73 EXPORT_SYMBOL(ipv6_select_ident);
75 int ip6_find_1stfragopt(struct sk_buff *skb, u8 **nexthdr)
77 u16 offset = sizeof(struct ipv6hdr);
78 struct ipv6_opt_hdr *exthdr =
79 (struct ipv6_opt_hdr *)(ipv6_hdr(skb) + 1);
80 unsigned int packet_len = skb_tail_pointer(skb) -
81 skb_network_header(skb);
83 *nexthdr = &ipv6_hdr(skb)->nexthdr;
85 while (offset + 1 <= packet_len) {
95 #if IS_ENABLED(CONFIG_IPV6_MIP6)
96 if (ipv6_find_tlv(skb, offset, IPV6_TLV_HAO) >= 0)
106 offset += ipv6_optlen(exthdr);
107 *nexthdr = &exthdr->nexthdr;
108 exthdr = (struct ipv6_opt_hdr *)(skb_network_header(skb) +
114 EXPORT_SYMBOL(ip6_find_1stfragopt);
116 #if IS_ENABLED(CONFIG_IPV6)
117 int ip6_dst_hoplimit(struct dst_entry *dst)
119 int hoplimit = dst_metric_raw(dst, RTAX_HOPLIMIT);
121 struct net_device *dev = dst->dev;
122 struct inet6_dev *idev;
125 idev = __in6_dev_get(dev);
127 hoplimit = idev->cnf.hop_limit;
129 hoplimit = dev_net(dev)->ipv6.devconf_all->hop_limit;
134 EXPORT_SYMBOL(ip6_dst_hoplimit);
137 int __ip6_local_out(struct sk_buff *skb)
141 len = skb->len - sizeof(struct ipv6hdr);
142 if (len > IPV6_MAXPLEN)
144 ipv6_hdr(skb)->payload_len = htons(len);
145 IP6CB(skb)->nhoff = offsetof(struct ipv6hdr, nexthdr);
147 return nf_hook(NFPROTO_IPV6, NF_INET_LOCAL_OUT, skb, NULL,
148 skb_dst(skb)->dev, dst_output);
150 EXPORT_SYMBOL_GPL(__ip6_local_out);
152 int ip6_local_out(struct sk_buff *skb)
156 err = __ip6_local_out(skb);
157 if (likely(err == 1))
158 err = dst_output(skb);
162 EXPORT_SYMBOL_GPL(ip6_local_out);