ipv6: distinguish frag queues by device for multicast and link-local packets
[linux/fpc-iii.git] / net / ipv6 / reassembly.c
bloba1fb511da3b5bd0ded7cfcdb090d88f0d6e06968
1 /*
2 * IPv6 fragment reassembly
3 * Linux INET6 implementation
5 * Authors:
6 * Pedro Roque <roque@di.fc.ul.pt>
8 * Based on: net/ipv4/ip_fragment.c
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
17 * Fixes:
18 * Andi Kleen Make it work with multiple hosts.
19 * More RFC compliance.
21 * Horst von Brand Add missing #include <linux/string.h>
22 * Alexey Kuznetsov SMP races, threading, cleanup.
23 * Patrick McHardy LRU queue of frag heads for evictor.
24 * Mitsuru KANDA @USAGI Register inet6_protocol{}.
25 * David Stevens and
26 * YOSHIFUJI,H. @USAGI Always remove fragment header to
27 * calculate ICV correctly.
30 #define pr_fmt(fmt) "IPv6: " fmt
32 #include <linux/errno.h>
33 #include <linux/types.h>
34 #include <linux/string.h>
35 #include <linux/socket.h>
36 #include <linux/sockios.h>
37 #include <linux/jiffies.h>
38 #include <linux/net.h>
39 #include <linux/list.h>
40 #include <linux/netdevice.h>
41 #include <linux/in6.h>
42 #include <linux/ipv6.h>
43 #include <linux/icmpv6.h>
44 #include <linux/random.h>
45 #include <linux/jhash.h>
46 #include <linux/skbuff.h>
47 #include <linux/slab.h>
48 #include <linux/export.h>
50 #include <net/sock.h>
51 #include <net/snmp.h>
53 #include <net/ipv6.h>
54 #include <net/ip6_route.h>
55 #include <net/protocol.h>
56 #include <net/transp_v6.h>
57 #include <net/rawv6.h>
58 #include <net/ndisc.h>
59 #include <net/addrconf.h>
60 #include <net/inet_frag.h>
61 #include <net/inet_ecn.h>
63 struct ip6frag_skb_cb
65 struct inet6_skb_parm h;
66 int offset;
69 #define FRAG6_CB(skb) ((struct ip6frag_skb_cb*)((skb)->cb))
71 static inline u8 ip6_frag_ecn(const struct ipv6hdr *ipv6h)
73 return 1 << (ipv6_get_dsfield(ipv6h) & INET_ECN_MASK);
76 static struct inet_frags ip6_frags;
78 static int ip6_frag_reasm(struct frag_queue *fq, struct sk_buff *prev,
79 struct net_device *dev);
82 * callers should be careful not to use the hash value outside the ipfrag_lock
83 * as doing so could race with ipfrag_hash_rnd being recalculated.
85 unsigned int inet6_hash_frag(__be32 id, const struct in6_addr *saddr,
86 const struct in6_addr *daddr, u32 rnd)
88 u32 c;
90 c = jhash_3words(ipv6_addr_hash(saddr), ipv6_addr_hash(daddr),
91 (__force u32)id, rnd);
93 return c & (INETFRAGS_HASHSZ - 1);
95 EXPORT_SYMBOL_GPL(inet6_hash_frag);
97 static unsigned int ip6_hashfn(struct inet_frag_queue *q)
99 struct frag_queue *fq;
101 fq = container_of(q, struct frag_queue, q);
102 return inet6_hash_frag(fq->id, &fq->saddr, &fq->daddr, ip6_frags.rnd);
105 bool ip6_frag_match(struct inet_frag_queue *q, void *a)
107 struct frag_queue *fq;
108 struct ip6_create_arg *arg = a;
110 fq = container_of(q, struct frag_queue, q);
111 return fq->id == arg->id &&
112 fq->user == arg->user &&
113 ipv6_addr_equal(&fq->saddr, arg->src) &&
114 ipv6_addr_equal(&fq->daddr, arg->dst) &&
115 (arg->iif == fq->iif ||
116 !(ipv6_addr_type(arg->dst) & (IPV6_ADDR_MULTICAST |
117 IPV6_ADDR_LINKLOCAL)));
119 EXPORT_SYMBOL(ip6_frag_match);
121 void ip6_frag_init(struct inet_frag_queue *q, void *a)
123 struct frag_queue *fq = container_of(q, struct frag_queue, q);
124 struct ip6_create_arg *arg = a;
126 fq->id = arg->id;
127 fq->user = arg->user;
128 fq->saddr = *arg->src;
129 fq->daddr = *arg->dst;
130 fq->ecn = arg->ecn;
132 EXPORT_SYMBOL(ip6_frag_init);
134 void ip6_expire_frag_queue(struct net *net, struct frag_queue *fq,
135 struct inet_frags *frags)
137 struct net_device *dev = NULL;
139 spin_lock(&fq->q.lock);
141 if (fq->q.last_in & INET_FRAG_COMPLETE)
142 goto out;
144 inet_frag_kill(&fq->q, frags);
146 rcu_read_lock();
147 dev = dev_get_by_index_rcu(net, fq->iif);
148 if (!dev)
149 goto out_rcu_unlock;
151 IP6_INC_STATS_BH(net, __in6_dev_get(dev), IPSTATS_MIB_REASMTIMEOUT);
152 IP6_INC_STATS_BH(net, __in6_dev_get(dev), IPSTATS_MIB_REASMFAILS);
154 /* Don't send error if the first segment did not arrive. */
155 if (!(fq->q.last_in & INET_FRAG_FIRST_IN) || !fq->q.fragments)
156 goto out_rcu_unlock;
159 But use as source device on which LAST ARRIVED
160 segment was received. And do not use fq->dev
161 pointer directly, device might already disappeared.
163 fq->q.fragments->dev = dev;
164 icmpv6_send(fq->q.fragments, ICMPV6_TIME_EXCEED, ICMPV6_EXC_FRAGTIME, 0);
165 out_rcu_unlock:
166 rcu_read_unlock();
167 out:
168 spin_unlock(&fq->q.lock);
169 inet_frag_put(&fq->q, frags);
171 EXPORT_SYMBOL(ip6_expire_frag_queue);
173 static void ip6_frag_expire(unsigned long data)
175 struct frag_queue *fq;
176 struct net *net;
178 fq = container_of((struct inet_frag_queue *)data, struct frag_queue, q);
179 net = container_of(fq->q.net, struct net, ipv6.frags);
181 ip6_expire_frag_queue(net, fq, &ip6_frags);
184 static __inline__ struct frag_queue *
185 fq_find(struct net *net, __be32 id, const struct in6_addr *src,
186 const struct in6_addr *dst, int iif, u8 ecn)
188 struct inet_frag_queue *q;
189 struct ip6_create_arg arg;
190 unsigned int hash;
192 arg.id = id;
193 arg.user = IP6_DEFRAG_LOCAL_DELIVER;
194 arg.src = src;
195 arg.dst = dst;
196 arg.iif = iif;
197 arg.ecn = ecn;
199 read_lock(&ip6_frags.lock);
200 hash = inet6_hash_frag(id, src, dst, ip6_frags.rnd);
202 q = inet_frag_find(&net->ipv6.frags, &ip6_frags, &arg, hash);
203 if (IS_ERR_OR_NULL(q)) {
204 inet_frag_maybe_warn_overflow(q, pr_fmt());
205 return NULL;
207 return container_of(q, struct frag_queue, q);
210 static int ip6_frag_queue(struct frag_queue *fq, struct sk_buff *skb,
211 struct frag_hdr *fhdr, int nhoff)
213 struct sk_buff *prev, *next;
214 struct net_device *dev;
215 int offset, end;
216 struct net *net = dev_net(skb_dst(skb)->dev);
217 u8 ecn;
219 if (fq->q.last_in & INET_FRAG_COMPLETE)
220 goto err;
222 offset = ntohs(fhdr->frag_off) & ~0x7;
223 end = offset + (ntohs(ipv6_hdr(skb)->payload_len) -
224 ((u8 *)(fhdr + 1) - (u8 *)(ipv6_hdr(skb) + 1)));
226 if ((unsigned int)end > IPV6_MAXPLEN) {
227 IP6_INC_STATS_BH(net, ip6_dst_idev(skb_dst(skb)),
228 IPSTATS_MIB_INHDRERRORS);
229 icmpv6_param_prob(skb, ICMPV6_HDR_FIELD,
230 ((u8 *)&fhdr->frag_off -
231 skb_network_header(skb)));
232 return -1;
235 ecn = ip6_frag_ecn(ipv6_hdr(skb));
237 if (skb->ip_summed == CHECKSUM_COMPLETE) {
238 const unsigned char *nh = skb_network_header(skb);
239 skb->csum = csum_sub(skb->csum,
240 csum_partial(nh, (u8 *)(fhdr + 1) - nh,
241 0));
244 /* Is this the final fragment? */
245 if (!(fhdr->frag_off & htons(IP6_MF))) {
246 /* If we already have some bits beyond end
247 * or have different end, the segment is corrupted.
249 if (end < fq->q.len ||
250 ((fq->q.last_in & INET_FRAG_LAST_IN) && end != fq->q.len))
251 goto err;
252 fq->q.last_in |= INET_FRAG_LAST_IN;
253 fq->q.len = end;
254 } else {
255 /* Check if the fragment is rounded to 8 bytes.
256 * Required by the RFC.
258 if (end & 0x7) {
259 /* RFC2460 says always send parameter problem in
260 * this case. -DaveM
262 IP6_INC_STATS_BH(net, ip6_dst_idev(skb_dst(skb)),
263 IPSTATS_MIB_INHDRERRORS);
264 icmpv6_param_prob(skb, ICMPV6_HDR_FIELD,
265 offsetof(struct ipv6hdr, payload_len));
266 return -1;
268 if (end > fq->q.len) {
269 /* Some bits beyond end -> corruption. */
270 if (fq->q.last_in & INET_FRAG_LAST_IN)
271 goto err;
272 fq->q.len = end;
276 if (end == offset)
277 goto err;
279 /* Point into the IP datagram 'data' part. */
280 if (!pskb_pull(skb, (u8 *) (fhdr + 1) - skb->data))
281 goto err;
283 if (pskb_trim_rcsum(skb, end - offset))
284 goto err;
286 /* Find out which fragments are in front and at the back of us
287 * in the chain of fragments so far. We must know where to put
288 * this fragment, right?
290 prev = fq->q.fragments_tail;
291 if (!prev || FRAG6_CB(prev)->offset < offset) {
292 next = NULL;
293 goto found;
295 prev = NULL;
296 for(next = fq->q.fragments; next != NULL; next = next->next) {
297 if (FRAG6_CB(next)->offset >= offset)
298 break; /* bingo! */
299 prev = next;
302 found:
303 /* RFC5722, Section 4, amended by Errata ID : 3089
304 * When reassembling an IPv6 datagram, if
305 * one or more its constituent fragments is determined to be an
306 * overlapping fragment, the entire datagram (and any constituent
307 * fragments) MUST be silently discarded.
310 /* Check for overlap with preceding fragment. */
311 if (prev &&
312 (FRAG6_CB(prev)->offset + prev->len) > offset)
313 goto discard_fq;
315 /* Look for overlap with succeeding segment. */
316 if (next && FRAG6_CB(next)->offset < end)
317 goto discard_fq;
319 FRAG6_CB(skb)->offset = offset;
321 /* Insert this fragment in the chain of fragments. */
322 skb->next = next;
323 if (!next)
324 fq->q.fragments_tail = skb;
325 if (prev)
326 prev->next = skb;
327 else
328 fq->q.fragments = skb;
330 dev = skb->dev;
331 if (dev) {
332 fq->iif = dev->ifindex;
333 skb->dev = NULL;
335 fq->q.stamp = skb->tstamp;
336 fq->q.meat += skb->len;
337 fq->ecn |= ecn;
338 add_frag_mem_limit(&fq->q, skb->truesize);
340 /* The first fragment.
341 * nhoffset is obtained from the first fragment, of course.
343 if (offset == 0) {
344 fq->nhoffset = nhoff;
345 fq->q.last_in |= INET_FRAG_FIRST_IN;
348 if (fq->q.last_in == (INET_FRAG_FIRST_IN | INET_FRAG_LAST_IN) &&
349 fq->q.meat == fq->q.len) {
350 int res;
351 unsigned long orefdst = skb->_skb_refdst;
353 skb->_skb_refdst = 0UL;
354 res = ip6_frag_reasm(fq, prev, dev);
355 skb->_skb_refdst = orefdst;
356 return res;
359 skb_dst_drop(skb);
360 inet_frag_lru_move(&fq->q);
361 return -1;
363 discard_fq:
364 inet_frag_kill(&fq->q, &ip6_frags);
365 err:
366 IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)),
367 IPSTATS_MIB_REASMFAILS);
368 kfree_skb(skb);
369 return -1;
373 * Check if this packet is complete.
374 * Returns NULL on failure by any reason, and pointer
375 * to current nexthdr field in reassembled frame.
377 * It is called with locked fq, and caller must check that
378 * queue is eligible for reassembly i.e. it is not COMPLETE,
379 * the last and the first frames arrived and all the bits are here.
381 static int ip6_frag_reasm(struct frag_queue *fq, struct sk_buff *prev,
382 struct net_device *dev)
384 struct net *net = container_of(fq->q.net, struct net, ipv6.frags);
385 struct sk_buff *fp, *head = fq->q.fragments;
386 int payload_len;
387 unsigned int nhoff;
388 int sum_truesize;
389 u8 ecn;
391 inet_frag_kill(&fq->q, &ip6_frags);
393 ecn = ip_frag_ecn_table[fq->ecn];
394 if (unlikely(ecn == 0xff))
395 goto out_fail;
397 /* Make the one we just received the head. */
398 if (prev) {
399 head = prev->next;
400 fp = skb_clone(head, GFP_ATOMIC);
402 if (!fp)
403 goto out_oom;
405 fp->next = head->next;
406 if (!fp->next)
407 fq->q.fragments_tail = fp;
408 prev->next = fp;
410 skb_morph(head, fq->q.fragments);
411 head->next = fq->q.fragments->next;
413 consume_skb(fq->q.fragments);
414 fq->q.fragments = head;
417 WARN_ON(head == NULL);
418 WARN_ON(FRAG6_CB(head)->offset != 0);
420 /* Unfragmented part is taken from the first segment. */
421 payload_len = ((head->data - skb_network_header(head)) -
422 sizeof(struct ipv6hdr) + fq->q.len -
423 sizeof(struct frag_hdr));
424 if (payload_len > IPV6_MAXPLEN)
425 goto out_oversize;
427 /* Head of list must not be cloned. */
428 if (skb_unclone(head, GFP_ATOMIC))
429 goto out_oom;
431 /* If the first fragment is fragmented itself, we split
432 * it to two chunks: the first with data and paged part
433 * and the second, holding only fragments. */
434 if (skb_has_frag_list(head)) {
435 struct sk_buff *clone;
436 int i, plen = 0;
438 if ((clone = alloc_skb(0, GFP_ATOMIC)) == NULL)
439 goto out_oom;
440 clone->next = head->next;
441 head->next = clone;
442 skb_shinfo(clone)->frag_list = skb_shinfo(head)->frag_list;
443 skb_frag_list_init(head);
444 for (i = 0; i < skb_shinfo(head)->nr_frags; i++)
445 plen += skb_frag_size(&skb_shinfo(head)->frags[i]);
446 clone->len = clone->data_len = head->data_len - plen;
447 head->data_len -= clone->len;
448 head->len -= clone->len;
449 clone->csum = 0;
450 clone->ip_summed = head->ip_summed;
451 add_frag_mem_limit(&fq->q, clone->truesize);
454 /* We have to remove fragment header from datagram and to relocate
455 * header in order to calculate ICV correctly. */
456 nhoff = fq->nhoffset;
457 skb_network_header(head)[nhoff] = skb_transport_header(head)[0];
458 memmove(head->head + sizeof(struct frag_hdr), head->head,
459 (head->data - head->head) - sizeof(struct frag_hdr));
460 head->mac_header += sizeof(struct frag_hdr);
461 head->network_header += sizeof(struct frag_hdr);
463 skb_reset_transport_header(head);
464 skb_push(head, head->data - skb_network_header(head));
466 sum_truesize = head->truesize;
467 for (fp = head->next; fp;) {
468 bool headstolen;
469 int delta;
470 struct sk_buff *next = fp->next;
472 sum_truesize += fp->truesize;
473 if (head->ip_summed != fp->ip_summed)
474 head->ip_summed = CHECKSUM_NONE;
475 else if (head->ip_summed == CHECKSUM_COMPLETE)
476 head->csum = csum_add(head->csum, fp->csum);
478 if (skb_try_coalesce(head, fp, &headstolen, &delta)) {
479 kfree_skb_partial(fp, headstolen);
480 } else {
481 if (!skb_shinfo(head)->frag_list)
482 skb_shinfo(head)->frag_list = fp;
483 head->data_len += fp->len;
484 head->len += fp->len;
485 head->truesize += fp->truesize;
487 fp = next;
489 sub_frag_mem_limit(&fq->q, sum_truesize);
491 head->next = NULL;
492 head->dev = dev;
493 head->tstamp = fq->q.stamp;
494 ipv6_hdr(head)->payload_len = htons(payload_len);
495 ipv6_change_dsfield(ipv6_hdr(head), 0xff, ecn);
496 IP6CB(head)->nhoff = nhoff;
497 IP6CB(head)->flags |= IP6SKB_FRAGMENTED;
499 /* Yes, and fold redundant checksum back. 8) */
500 if (head->ip_summed == CHECKSUM_COMPLETE)
501 head->csum = csum_partial(skb_network_header(head),
502 skb_network_header_len(head),
503 head->csum);
505 rcu_read_lock();
506 IP6_INC_STATS_BH(net, __in6_dev_get(dev), IPSTATS_MIB_REASMOKS);
507 rcu_read_unlock();
508 fq->q.fragments = NULL;
509 fq->q.fragments_tail = NULL;
510 return 1;
512 out_oversize:
513 net_dbg_ratelimited("ip6_frag_reasm: payload len = %d\n", payload_len);
514 goto out_fail;
515 out_oom:
516 net_dbg_ratelimited("ip6_frag_reasm: no memory for reassembly\n");
517 out_fail:
518 rcu_read_lock();
519 IP6_INC_STATS_BH(net, __in6_dev_get(dev), IPSTATS_MIB_REASMFAILS);
520 rcu_read_unlock();
521 return -1;
524 static int ipv6_frag_rcv(struct sk_buff *skb)
526 struct frag_hdr *fhdr;
527 struct frag_queue *fq;
528 const struct ipv6hdr *hdr = ipv6_hdr(skb);
529 struct net *net = dev_net(skb_dst(skb)->dev);
530 int evicted;
532 if (IP6CB(skb)->flags & IP6SKB_FRAGMENTED)
533 goto fail_hdr;
535 IP6_INC_STATS_BH(net, ip6_dst_idev(skb_dst(skb)), IPSTATS_MIB_REASMREQDS);
537 /* Jumbo payload inhibits frag. header */
538 if (hdr->payload_len==0)
539 goto fail_hdr;
541 if (!pskb_may_pull(skb, (skb_transport_offset(skb) +
542 sizeof(struct frag_hdr))))
543 goto fail_hdr;
545 hdr = ipv6_hdr(skb);
546 fhdr = (struct frag_hdr *)skb_transport_header(skb);
548 if (!(fhdr->frag_off & htons(0xFFF9))) {
549 /* It is not a fragmented frame */
550 skb->transport_header += sizeof(struct frag_hdr);
551 IP6_INC_STATS_BH(net,
552 ip6_dst_idev(skb_dst(skb)), IPSTATS_MIB_REASMOKS);
554 IP6CB(skb)->nhoff = (u8 *)fhdr - skb_network_header(skb);
555 IP6CB(skb)->flags |= IP6SKB_FRAGMENTED;
556 return 1;
559 evicted = inet_frag_evictor(&net->ipv6.frags, &ip6_frags, false);
560 if (evicted)
561 IP6_ADD_STATS_BH(net, ip6_dst_idev(skb_dst(skb)),
562 IPSTATS_MIB_REASMFAILS, evicted);
564 fq = fq_find(net, fhdr->identification, &hdr->saddr, &hdr->daddr,
565 skb->dev ? skb->dev->ifindex : 0, ip6_frag_ecn(hdr));
566 if (fq != NULL) {
567 int ret;
569 spin_lock(&fq->q.lock);
571 ret = ip6_frag_queue(fq, skb, fhdr, IP6CB(skb)->nhoff);
573 spin_unlock(&fq->q.lock);
574 inet_frag_put(&fq->q, &ip6_frags);
575 return ret;
578 IP6_INC_STATS_BH(net, ip6_dst_idev(skb_dst(skb)), IPSTATS_MIB_REASMFAILS);
579 kfree_skb(skb);
580 return -1;
582 fail_hdr:
583 IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)), IPSTATS_MIB_INHDRERRORS);
584 icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, skb_network_header_len(skb));
585 return -1;
588 static const struct inet6_protocol frag_protocol =
590 .handler = ipv6_frag_rcv,
591 .flags = INET6_PROTO_NOPOLICY,
594 #ifdef CONFIG_SYSCTL
595 static struct ctl_table ip6_frags_ns_ctl_table[] = {
597 .procname = "ip6frag_high_thresh",
598 .data = &init_net.ipv6.frags.high_thresh,
599 .maxlen = sizeof(int),
600 .mode = 0644,
601 .proc_handler = proc_dointvec
604 .procname = "ip6frag_low_thresh",
605 .data = &init_net.ipv6.frags.low_thresh,
606 .maxlen = sizeof(int),
607 .mode = 0644,
608 .proc_handler = proc_dointvec
611 .procname = "ip6frag_time",
612 .data = &init_net.ipv6.frags.timeout,
613 .maxlen = sizeof(int),
614 .mode = 0644,
615 .proc_handler = proc_dointvec_jiffies,
620 static struct ctl_table ip6_frags_ctl_table[] = {
622 .procname = "ip6frag_secret_interval",
623 .data = &ip6_frags.secret_interval,
624 .maxlen = sizeof(int),
625 .mode = 0644,
626 .proc_handler = proc_dointvec_jiffies,
631 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
633 struct ctl_table *table;
634 struct ctl_table_header *hdr;
636 table = ip6_frags_ns_ctl_table;
637 if (!net_eq(net, &init_net)) {
638 table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
639 if (table == NULL)
640 goto err_alloc;
642 table[0].data = &net->ipv6.frags.high_thresh;
643 table[1].data = &net->ipv6.frags.low_thresh;
644 table[2].data = &net->ipv6.frags.timeout;
646 /* Don't export sysctls to unprivileged users */
647 if (net->user_ns != &init_user_ns)
648 table[0].procname = NULL;
651 hdr = register_net_sysctl(net, "net/ipv6", table);
652 if (hdr == NULL)
653 goto err_reg;
655 net->ipv6.sysctl.frags_hdr = hdr;
656 return 0;
658 err_reg:
659 if (!net_eq(net, &init_net))
660 kfree(table);
661 err_alloc:
662 return -ENOMEM;
665 static void __net_exit ip6_frags_ns_sysctl_unregister(struct net *net)
667 struct ctl_table *table;
669 table = net->ipv6.sysctl.frags_hdr->ctl_table_arg;
670 unregister_net_sysctl_table(net->ipv6.sysctl.frags_hdr);
671 if (!net_eq(net, &init_net))
672 kfree(table);
675 static struct ctl_table_header *ip6_ctl_header;
677 static int ip6_frags_sysctl_register(void)
679 ip6_ctl_header = register_net_sysctl(&init_net, "net/ipv6",
680 ip6_frags_ctl_table);
681 return ip6_ctl_header == NULL ? -ENOMEM : 0;
684 static void ip6_frags_sysctl_unregister(void)
686 unregister_net_sysctl_table(ip6_ctl_header);
688 #else
689 static inline int ip6_frags_ns_sysctl_register(struct net *net)
691 return 0;
694 static inline void ip6_frags_ns_sysctl_unregister(struct net *net)
698 static inline int ip6_frags_sysctl_register(void)
700 return 0;
703 static inline void ip6_frags_sysctl_unregister(void)
706 #endif
708 static int __net_init ipv6_frags_init_net(struct net *net)
710 net->ipv6.frags.high_thresh = IPV6_FRAG_HIGH_THRESH;
711 net->ipv6.frags.low_thresh = IPV6_FRAG_LOW_THRESH;
712 net->ipv6.frags.timeout = IPV6_FRAG_TIMEOUT;
714 inet_frags_init_net(&net->ipv6.frags);
716 return ip6_frags_ns_sysctl_register(net);
719 static void __net_exit ipv6_frags_exit_net(struct net *net)
721 ip6_frags_ns_sysctl_unregister(net);
722 inet_frags_exit_net(&net->ipv6.frags, &ip6_frags);
725 static struct pernet_operations ip6_frags_ops = {
726 .init = ipv6_frags_init_net,
727 .exit = ipv6_frags_exit_net,
730 int __init ipv6_frag_init(void)
732 int ret;
734 ret = inet6_add_protocol(&frag_protocol, IPPROTO_FRAGMENT);
735 if (ret)
736 goto out;
738 ret = ip6_frags_sysctl_register();
739 if (ret)
740 goto err_sysctl;
742 ret = register_pernet_subsys(&ip6_frags_ops);
743 if (ret)
744 goto err_pernet;
746 ip6_frags.hashfn = ip6_hashfn;
747 ip6_frags.constructor = ip6_frag_init;
748 ip6_frags.destructor = NULL;
749 ip6_frags.skb_free = NULL;
750 ip6_frags.qsize = sizeof(struct frag_queue);
751 ip6_frags.match = ip6_frag_match;
752 ip6_frags.frag_expire = ip6_frag_expire;
753 ip6_frags.secret_interval = 10 * 60 * HZ;
754 inet_frags_init(&ip6_frags);
755 out:
756 return ret;
758 err_pernet:
759 ip6_frags_sysctl_unregister();
760 err_sysctl:
761 inet6_del_protocol(&frag_protocol, IPPROTO_FRAGMENT);
762 goto out;
765 void ipv6_frag_exit(void)
767 inet_frags_fini(&ip6_frags);
768 ip6_frags_sysctl_unregister();
769 unregister_pernet_subsys(&ip6_frags_ops);
770 inet6_del_protocol(&frag_protocol, IPPROTO_FRAGMENT);