]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - net/ipv6/output_core.c
inetpeer: get rid of ip_id_count
[karo-tx-linux.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/ipv6.h>
7 #include <net/ip6_fib.h>
8 #include <net/addrconf.h>
9 #include <net/secure_seq.h>
10
11
12 int ip6_find_1stfragopt(struct sk_buff *skb, u8 **nexthdr)
13 {
14         u16 offset = sizeof(struct ipv6hdr);
15         struct ipv6_opt_hdr *exthdr =
16                                 (struct ipv6_opt_hdr *)(ipv6_hdr(skb) + 1);
17         unsigned int packet_len = skb_tail_pointer(skb) -
18                 skb_network_header(skb);
19         int found_rhdr = 0;
20         *nexthdr = &ipv6_hdr(skb)->nexthdr;
21
22         while (offset + 1 <= packet_len) {
23
24                 switch (**nexthdr) {
25
26                 case NEXTHDR_HOP:
27                         break;
28                 case NEXTHDR_ROUTING:
29                         found_rhdr = 1;
30                         break;
31                 case NEXTHDR_DEST:
32 #if IS_ENABLED(CONFIG_IPV6_MIP6)
33                         if (ipv6_find_tlv(skb, offset, IPV6_TLV_HAO) >= 0)
34                                 break;
35 #endif
36                         if (found_rhdr)
37                                 return offset;
38                         break;
39                 default :
40                         return offset;
41                 }
42
43                 offset += ipv6_optlen(exthdr);
44                 *nexthdr = &exthdr->nexthdr;
45                 exthdr = (struct ipv6_opt_hdr *)(skb_network_header(skb) +
46                                                  offset);
47         }
48
49         return offset;
50 }
51 EXPORT_SYMBOL(ip6_find_1stfragopt);
52
53 #if IS_ENABLED(CONFIG_IPV6)
54 int ip6_dst_hoplimit(struct dst_entry *dst)
55 {
56         int hoplimit = dst_metric_raw(dst, RTAX_HOPLIMIT);
57         if (hoplimit == 0) {
58                 struct net_device *dev = dst->dev;
59                 struct inet6_dev *idev;
60
61                 rcu_read_lock();
62                 idev = __in6_dev_get(dev);
63                 if (idev)
64                         hoplimit = idev->cnf.hop_limit;
65                 else
66                         hoplimit = dev_net(dev)->ipv6.devconf_all->hop_limit;
67                 rcu_read_unlock();
68         }
69         return hoplimit;
70 }
71 EXPORT_SYMBOL(ip6_dst_hoplimit);
72 #endif
73
74 int __ip6_local_out(struct sk_buff *skb)
75 {
76         int len;
77
78         len = skb->len - sizeof(struct ipv6hdr);
79         if (len > IPV6_MAXPLEN)
80                 len = 0;
81         ipv6_hdr(skb)->payload_len = htons(len);
82
83         return nf_hook(NFPROTO_IPV6, NF_INET_LOCAL_OUT, skb, NULL,
84                        skb_dst(skb)->dev, dst_output);
85 }
86 EXPORT_SYMBOL_GPL(__ip6_local_out);
87
88 int ip6_local_out(struct sk_buff *skb)
89 {
90         int err;
91
92         err = __ip6_local_out(skb);
93         if (likely(err == 1))
94                 err = dst_output(skb);
95
96         return err;
97 }
98 EXPORT_SYMBOL_GPL(ip6_local_out);