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