Vlad Yasevich | 3c73a03 | 2012-11-15 08:49:20 +0000 | [diff] [blame] | 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> |
Cong Wang | 3ce9b35 | 2013-08-31 13:44:28 +0800 | [diff] [blame] | 8 | #include <net/addrconf.h> |
Hannes Frederic Sowa | 6dfac5c | 2014-03-30 18:28:03 +0200 | [diff] [blame] | 9 | #include <net/secure_seq.h> |
Vlad Yasevich | 3c73a03 | 2012-11-15 08:49:20 +0000 | [diff] [blame] | 10 | |
| 11 | void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt) |
| 12 | { |
| 13 | static atomic_t ipv6_fragmentation_id; |
Hannes Frederic Sowa | 6dfac5c | 2014-03-30 18:28:03 +0200 | [diff] [blame] | 14 | struct in6_addr addr; |
Eric Dumazet | 39c3609 | 2014-05-29 08:45:14 -0700 | [diff] [blame] | 15 | int ident; |
Vlad Yasevich | 3c73a03 | 2012-11-15 08:49:20 +0000 | [diff] [blame] | 16 | |
| 17 | #if IS_ENABLED(CONFIG_IPV6) |
Hannes Frederic Sowa | 6dfac5c | 2014-03-30 18:28:03 +0200 | [diff] [blame] | 18 | struct inet_peer *peer; |
| 19 | struct net *net; |
Vlad Yasevich | 3c73a03 | 2012-11-15 08:49:20 +0000 | [diff] [blame] | 20 | |
Hannes Frederic Sowa | 6dfac5c | 2014-03-30 18:28:03 +0200 | [diff] [blame] | 21 | net = dev_net(rt->dst.dev); |
| 22 | peer = inet_getpeer_v6(net->ipv6.peers, &rt->rt6i_dst.addr, 1); |
| 23 | if (peer) { |
| 24 | fhdr->identification = htonl(inet_getid(peer, 0)); |
| 25 | inet_putpeer(peer); |
| 26 | return; |
Vlad Yasevich | 3c73a03 | 2012-11-15 08:49:20 +0000 | [diff] [blame] | 27 | } |
| 28 | #endif |
Eric Dumazet | 39c3609 | 2014-05-29 08:45:14 -0700 | [diff] [blame] | 29 | ident = atomic_inc_return(&ipv6_fragmentation_id); |
Hannes Frederic Sowa | 6dfac5c | 2014-03-30 18:28:03 +0200 | [diff] [blame] | 30 | |
| 31 | addr = rt->rt6i_dst.addr; |
Eric Dumazet | 39c3609 | 2014-05-29 08:45:14 -0700 | [diff] [blame] | 32 | addr.s6_addr32[0] ^= (__force __be32)ident; |
Hannes Frederic Sowa | 6dfac5c | 2014-03-30 18:28:03 +0200 | [diff] [blame] | 33 | fhdr->identification = htonl(secure_ipv6_id(addr.s6_addr32)); |
Vlad Yasevich | 3c73a03 | 2012-11-15 08:49:20 +0000 | [diff] [blame] | 34 | } |
| 35 | EXPORT_SYMBOL(ipv6_select_ident); |
| 36 | |
| 37 | int ip6_find_1stfragopt(struct sk_buff *skb, u8 **nexthdr) |
| 38 | { |
| 39 | u16 offset = sizeof(struct ipv6hdr); |
| 40 | struct ipv6_opt_hdr *exthdr = |
| 41 | (struct ipv6_opt_hdr *)(ipv6_hdr(skb) + 1); |
Simon Horman | 29a3cad | 2013-05-28 20:34:26 +0000 | [diff] [blame] | 42 | unsigned int packet_len = skb_tail_pointer(skb) - |
| 43 | skb_network_header(skb); |
Vlad Yasevich | 3c73a03 | 2012-11-15 08:49:20 +0000 | [diff] [blame] | 44 | int found_rhdr = 0; |
| 45 | *nexthdr = &ipv6_hdr(skb)->nexthdr; |
| 46 | |
| 47 | while (offset + 1 <= packet_len) { |
| 48 | |
| 49 | switch (**nexthdr) { |
| 50 | |
| 51 | case NEXTHDR_HOP: |
| 52 | break; |
| 53 | case NEXTHDR_ROUTING: |
| 54 | found_rhdr = 1; |
| 55 | break; |
| 56 | case NEXTHDR_DEST: |
| 57 | #if IS_ENABLED(CONFIG_IPV6_MIP6) |
| 58 | if (ipv6_find_tlv(skb, offset, IPV6_TLV_HAO) >= 0) |
| 59 | break; |
| 60 | #endif |
| 61 | if (found_rhdr) |
| 62 | return offset; |
| 63 | break; |
| 64 | default : |
| 65 | return offset; |
| 66 | } |
| 67 | |
| 68 | offset += ipv6_optlen(exthdr); |
| 69 | *nexthdr = &exthdr->nexthdr; |
| 70 | exthdr = (struct ipv6_opt_hdr *)(skb_network_header(skb) + |
| 71 | offset); |
| 72 | } |
| 73 | |
| 74 | return offset; |
| 75 | } |
| 76 | EXPORT_SYMBOL(ip6_find_1stfragopt); |
Cong Wang | 3ce9b35 | 2013-08-31 13:44:28 +0800 | [diff] [blame] | 77 | |
| 78 | #if IS_ENABLED(CONFIG_IPV6) |
| 79 | int ip6_dst_hoplimit(struct dst_entry *dst) |
| 80 | { |
| 81 | int hoplimit = dst_metric_raw(dst, RTAX_HOPLIMIT); |
| 82 | if (hoplimit == 0) { |
| 83 | struct net_device *dev = dst->dev; |
| 84 | struct inet6_dev *idev; |
| 85 | |
| 86 | rcu_read_lock(); |
| 87 | idev = __in6_dev_get(dev); |
| 88 | if (idev) |
| 89 | hoplimit = idev->cnf.hop_limit; |
| 90 | else |
| 91 | hoplimit = dev_net(dev)->ipv6.devconf_all->hop_limit; |
| 92 | rcu_read_unlock(); |
| 93 | } |
| 94 | return hoplimit; |
| 95 | } |
| 96 | EXPORT_SYMBOL(ip6_dst_hoplimit); |
| 97 | #endif |
Cong Wang | 788787b | 2013-08-31 13:44:29 +0800 | [diff] [blame] | 98 | |
| 99 | int __ip6_local_out(struct sk_buff *skb) |
| 100 | { |
| 101 | int len; |
| 102 | |
| 103 | len = skb->len - sizeof(struct ipv6hdr); |
| 104 | if (len > IPV6_MAXPLEN) |
| 105 | len = 0; |
| 106 | ipv6_hdr(skb)->payload_len = htons(len); |
huizhang | f6c20c5 | 2014-06-09 12:37:25 +0800 | [diff] [blame^] | 107 | IP6CB(skb)->nhoff = offsetof(struct ipv6hdr, nexthdr); |
Cong Wang | 788787b | 2013-08-31 13:44:29 +0800 | [diff] [blame] | 108 | |
| 109 | return nf_hook(NFPROTO_IPV6, NF_INET_LOCAL_OUT, skb, NULL, |
| 110 | skb_dst(skb)->dev, dst_output); |
| 111 | } |
| 112 | EXPORT_SYMBOL_GPL(__ip6_local_out); |
| 113 | |
| 114 | int ip6_local_out(struct sk_buff *skb) |
| 115 | { |
| 116 | int err; |
| 117 | |
| 118 | err = __ip6_local_out(skb); |
| 119 | if (likely(err == 1)) |
| 120 | err = dst_output(skb); |
| 121 | |
| 122 | return err; |
| 123 | } |
| 124 | EXPORT_SYMBOL_GPL(ip6_local_out); |