Linux 3.8-rc7
[cris-mirror.git] / net / ipv6 / output_core.c
blobc2e73e647e440745acd32dcaa1564031f4323e38
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>
9 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
11 static atomic_t ipv6_fragmentation_id;
12 int old, new;
14 #if IS_ENABLED(CONFIG_IPV6)
15 if (rt && !(rt->dst.flags & DST_NOPEER)) {
16 struct inet_peer *peer;
17 struct net *net;
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;
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);
36 EXPORT_SYMBOL(ipv6_select_ident);
38 int ip6_find_1stfragopt(struct sk_buff *skb, u8 **nexthdr)
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 - skb->network_header;
44 int found_rhdr = 0;
45 *nexthdr = &ipv6_hdr(skb)->nexthdr;
47 while (offset + 1 <= packet_len) {
49 switch (**nexthdr) {
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;
68 offset += ipv6_optlen(exthdr);
69 *nexthdr = &exthdr->nexthdr;
70 exthdr = (struct ipv6_opt_hdr *)(skb_network_header(skb) +
71 offset);
74 return offset;
76 EXPORT_SYMBOL(ip6_find_1stfragopt);