]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - net/ipv6/output_core.c
ipv6: Correct comparisons and calculations using skb->tail and skb-transport_header
[mirror_ubuntu-bionic-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/ipv6.h>
7 #include <net/ip6_fib.h>
8
9 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
10 {
11 static atomic_t ipv6_fragmentation_id;
12 int old, new;
13
14 #if IS_ENABLED(CONFIG_IPV6)
15 if (rt && !(rt->dst.flags & DST_NOPEER)) {
16 struct inet_peer *peer;
17 struct net *net;
18
19 net = dev_net(rt->dst.dev);
20 peer = inet_getpeer_v6(net->ipv6.peers, &rt->rt6i_dst.addr, 1);
21 if (peer) {
22 fhdr->identification = htonl(inet_getid(peer, 0));
23 inet_putpeer(peer);
24 return;
25 }
26 }
27 #endif
28 do {
29 old = atomic_read(&ipv6_fragmentation_id);
30 new = old + 1;
31 if (!new)
32 new = 1;
33 } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
34 fhdr->identification = htonl(new);
35 }
36 EXPORT_SYMBOL(ipv6_select_ident);
37
38 int ip6_find_1stfragopt(struct sk_buff *skb, u8 **nexthdr)
39 {
40 u16 offset = sizeof(struct ipv6hdr);
41 struct ipv6_opt_hdr *exthdr =
42 (struct ipv6_opt_hdr *)(ipv6_hdr(skb) + 1);
43 unsigned int packet_len = skb_tail_pointer(skb) -
44 skb_network_header(skb);
45 int found_rhdr = 0;
46 *nexthdr = &ipv6_hdr(skb)->nexthdr;
47
48 while (offset + 1 <= packet_len) {
49
50 switch (**nexthdr) {
51
52 case NEXTHDR_HOP:
53 break;
54 case NEXTHDR_ROUTING:
55 found_rhdr = 1;
56 break;
57 case NEXTHDR_DEST:
58 #if IS_ENABLED(CONFIG_IPV6_MIP6)
59 if (ipv6_find_tlv(skb, offset, IPV6_TLV_HAO) >= 0)
60 break;
61 #endif
62 if (found_rhdr)
63 return offset;
64 break;
65 default :
66 return offset;
67 }
68
69 offset += ipv6_optlen(exthdr);
70 *nexthdr = &exthdr->nexthdr;
71 exthdr = (struct ipv6_opt_hdr *)(skb_network_header(skb) +
72 offset);
73 }
74
75 return offset;
76 }
77 EXPORT_SYMBOL(ip6_find_1stfragopt);