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 u32 __ipv6_select_ident(u32 hashrnd, struct in6_addr *dst, struct in6_addr *src)
16 hash = __ipv6_addr_jhash(dst, hashrnd);
17 hash = __ipv6_addr_jhash(src, hash);
19 /* Treat id of 0 as unset and if we get 0 back from ip_idents_reserve,
20 * set the hight order instead thus minimizing possible future
23 id = ip_idents_reserve(hash, 1);
30 /* This function exists only for tap drivers that must support broken
31 * clients requesting UFO without specifying an IPv6 fragment ID.
33 * This is similar to ipv6_select_ident() but we use an independent hash
34 * seed to limit information leakage.
36 * The network header must be set before calling this.
38 void ipv6_proxy_select_ident(struct sk_buff *skb)
40 static u32 ip6_proxy_idents_hashrnd __read_mostly;
41 struct in6_addr buf[2];
42 struct in6_addr *addrs;
45 addrs = skb_header_pointer(skb,
46 skb_network_offset(skb) +
47 offsetof(struct ipv6hdr, saddr),
52 net_get_random_once(&ip6_proxy_idents_hashrnd,
53 sizeof(ip6_proxy_idents_hashrnd));
55 id = __ipv6_select_ident(ip6_proxy_idents_hashrnd,
56 &addrs[1], &addrs[0]);
57 skb_shinfo(skb)->ip6_frag_id = id;
59 EXPORT_SYMBOL_GPL(ipv6_proxy_select_ident);
61 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
63 static u32 ip6_idents_hashrnd __read_mostly;
66 net_get_random_once(&ip6_idents_hashrnd, sizeof(ip6_idents_hashrnd));
68 id = __ipv6_select_ident(ip6_idents_hashrnd, &rt->rt6i_dst.addr,
70 fhdr->identification = htonl(id);
72 EXPORT_SYMBOL(ipv6_select_ident);
74 int ip6_find_1stfragopt(struct sk_buff *skb, u8 **nexthdr)
76 u16 offset = sizeof(struct ipv6hdr);
77 struct ipv6_opt_hdr *exthdr =
78 (struct ipv6_opt_hdr *)(ipv6_hdr(skb) + 1);
79 unsigned int packet_len = skb_tail_pointer(skb) -
80 skb_network_header(skb);
82 *nexthdr = &ipv6_hdr(skb)->nexthdr;
84 while (offset + 1 <= packet_len) {
94 #if IS_ENABLED(CONFIG_IPV6_MIP6)
95 if (ipv6_find_tlv(skb, offset, IPV6_TLV_HAO) >= 0)
105 offset += ipv6_optlen(exthdr);
106 *nexthdr = &exthdr->nexthdr;
107 exthdr = (struct ipv6_opt_hdr *)(skb_network_header(skb) +
113 EXPORT_SYMBOL(ip6_find_1stfragopt);
115 #if IS_ENABLED(CONFIG_IPV6)
116 int ip6_dst_hoplimit(struct dst_entry *dst)
118 int hoplimit = dst_metric_raw(dst, RTAX_HOPLIMIT);
120 struct net_device *dev = dst->dev;
121 struct inet6_dev *idev;
124 idev = __in6_dev_get(dev);
126 hoplimit = idev->cnf.hop_limit;
128 hoplimit = dev_net(dev)->ipv6.devconf_all->hop_limit;
133 EXPORT_SYMBOL(ip6_dst_hoplimit);
136 int __ip6_local_out(struct sk_buff *skb)
140 len = skb->len - sizeof(struct ipv6hdr);
141 if (len > IPV6_MAXPLEN)
143 ipv6_hdr(skb)->payload_len = htons(len);
144 IP6CB(skb)->nhoff = offsetof(struct ipv6hdr, nexthdr);
146 return nf_hook(NFPROTO_IPV6, NF_INET_LOCAL_OUT, skb, NULL,
147 skb_dst(skb)->dev, dst_output);
149 EXPORT_SYMBOL_GPL(__ip6_local_out);
151 int ip6_local_out(struct sk_buff *skb)
155 err = __ip6_local_out(skb);
156 if (likely(err == 1))
157 err = dst_output(skb);
161 EXPORT_SYMBOL_GPL(ip6_local_out);