Correct .gbs.conf settings
[platform/adaptation/renesas_rcar/renesas_kernel.git] / net / ipv6 / output_core.c
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/ip.h>
7 #include <net/ipv6.h>
8 #include <net/ip6_fib.h>
9 #include <net/addrconf.h>
10
11 /* This function exists only for tap drivers that must support broken
12  * clients requesting UFO without specifying an IPv6 fragment ID.
13  *
14  * This is similar to ipv6_select_ident() but we use an independent hash
15  * seed to limit information leakage.
16  *
17  * The network header must be set before calling this.
18  */
19 void ipv6_proxy_select_ident(struct sk_buff *skb)
20 {
21         static u32 ip6_proxy_idents_hashrnd __read_mostly;
22         struct in6_addr buf[2];
23         struct in6_addr *addrs;
24         u32 hash, id;
25
26         addrs = skb_header_pointer(skb,
27                                    skb_network_offset(skb) +
28                                    offsetof(struct ipv6hdr, saddr),
29                                    sizeof(buf), buf);
30         if (!addrs)
31                 return;
32
33         net_get_random_once(&ip6_proxy_idents_hashrnd,
34                             sizeof(ip6_proxy_idents_hashrnd));
35
36         hash = __ipv6_addr_jhash(&addrs[1], ip6_proxy_idents_hashrnd);
37         hash = __ipv6_addr_jhash(&addrs[0], hash);
38
39         id = ip_idents_reserve(hash, 1);
40         skb_shinfo(skb)->ip6_frag_id = htonl(id);
41 }
42 EXPORT_SYMBOL_GPL(ipv6_proxy_select_ident);
43
44 int ip6_find_1stfragopt(struct sk_buff *skb, u8 **nexthdr)
45 {
46         u16 offset = sizeof(struct ipv6hdr);
47         struct ipv6_opt_hdr *exthdr =
48                                 (struct ipv6_opt_hdr *)(ipv6_hdr(skb) + 1);
49         unsigned int packet_len = skb_tail_pointer(skb) -
50                 skb_network_header(skb);
51         int found_rhdr = 0;
52         *nexthdr = &ipv6_hdr(skb)->nexthdr;
53
54         while (offset + 1 <= packet_len) {
55
56                 switch (**nexthdr) {
57
58                 case NEXTHDR_HOP:
59                         break;
60                 case NEXTHDR_ROUTING:
61                         found_rhdr = 1;
62                         break;
63                 case NEXTHDR_DEST:
64 #if IS_ENABLED(CONFIG_IPV6_MIP6)
65                         if (ipv6_find_tlv(skb, offset, IPV6_TLV_HAO) >= 0)
66                                 break;
67 #endif
68                         if (found_rhdr)
69                                 return offset;
70                         break;
71                 default :
72                         return offset;
73                 }
74
75                 offset += ipv6_optlen(exthdr);
76                 *nexthdr = &exthdr->nexthdr;
77                 exthdr = (struct ipv6_opt_hdr *)(skb_network_header(skb) +
78                                                  offset);
79         }
80
81         return offset;
82 }
83 EXPORT_SYMBOL(ip6_find_1stfragopt);
84
85 #if IS_ENABLED(CONFIG_IPV6)
86 int ip6_dst_hoplimit(struct dst_entry *dst)
87 {
88         int hoplimit = dst_metric_raw(dst, RTAX_HOPLIMIT);
89         if (hoplimit == 0) {
90                 struct net_device *dev = dst->dev;
91                 struct inet6_dev *idev;
92
93                 rcu_read_lock();
94                 idev = __in6_dev_get(dev);
95                 if (idev)
96                         hoplimit = idev->cnf.hop_limit;
97                 else
98                         hoplimit = dev_net(dev)->ipv6.devconf_all->hop_limit;
99                 rcu_read_unlock();
100         }
101         return hoplimit;
102 }
103 EXPORT_SYMBOL(ip6_dst_hoplimit);
104 #endif
105
106 int __ip6_local_out(struct sk_buff *skb)
107 {
108         int len;
109
110         len = skb->len - sizeof(struct ipv6hdr);
111         if (len > IPV6_MAXPLEN)
112                 len = 0;
113         ipv6_hdr(skb)->payload_len = htons(len);
114
115         return nf_hook(NFPROTO_IPV6, NF_INET_LOCAL_OUT, skb, NULL,
116                        skb_dst(skb)->dev, dst_output);
117 }
118 EXPORT_SYMBOL_GPL(__ip6_local_out);
119
120 int ip6_local_out(struct sk_buff *skb)
121 {
122         int err;
123
124         err = __ip6_local_out(skb);
125         if (likely(err == 1))
126                 err = dst_output(skb);
127
128         return err;
129 }
130 EXPORT_SYMBOL_GPL(ip6_local_out);