1 /*
2 * IPv6 fragment reassembly for connection tracking
3 *
4 * Copyright (C)2004 USAGI/WIDE Project
5 *
6 * Author:
7 * Yasuyuki Kozakai @USAGI <yasuyuki.kozakai@toshiba.co.jp>
8 *
9 * Based on: net/ipv6/reassembly.c
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version
14 * 2 of the License, or (at your option) any later version.
15 */
16
17 #define pr_fmt(fmt) "IPv6-nf: " fmt
18
19 #include <linux/errno.h>
20 #include <linux/types.h>
21 #include <linux/string.h>
22 #include <linux/socket.h>
23 #include <linux/sockios.h>
24 #include <linux/jiffies.h>
25 #include <linux/net.h>
26 #include <linux/list.h>
27 #include <linux/netdevice.h>
28 #include <linux/in6.h>
29 #include <linux/ipv6.h>
30 #include <linux/icmpv6.h>
31 #include <linux/random.h>
32 #include <linux/slab.h>
33
34 #include <net/sock.h>
35 #include <net/snmp.h>
36 #include <net/inet_frag.h>
37
38 #include <net/ipv6.h>
39 #include <net/protocol.h>
40 #include <net/transp_v6.h>
41 #include <net/rawv6.h>
42 #include <net/ndisc.h>
43 #include <net/addrconf.h>
44 #include <net/inet_ecn.h>
45 #include <net/netfilter/ipv6/nf_conntrack_ipv6.h>
46 #include <linux/sysctl.h>
47 #include <linux/netfilter.h>
48 #include <linux/netfilter_ipv6.h>
49 #include <linux/kernel.h>
50 #include <linux/module.h>
51 #include <net/netfilter/ipv6/nf_defrag_ipv6.h>
52
53
54 struct nf_ct_frag6_skb_cb
55 {
56 struct inet6_skb_parm h;
57 int offset;
58 struct sk_buff *orig;
59 };
60
61 #define NFCT_FRAG6_CB(skb) ((struct nf_ct_frag6_skb_cb*)((skb)->cb))
62
63 static struct inet_frags nf_frags;
64
65 #ifdef CONFIG_SYSCTL
66 static struct ctl_table nf_ct_frag6_sysctl_table[] = {
67 {
68 .procname = "nf_conntrack_frag6_timeout",
69 .data = &init_net.nf_frag.frags.timeout,
70 .maxlen = sizeof(unsigned int),
71 .mode = 0644,
72 .proc_handler = proc_dointvec_jiffies,
73 },
74 {
75 .procname = "nf_conntrack_frag6_low_thresh",
76 .data = &init_net.nf_frag.frags.low_thresh,
77 .maxlen = sizeof(unsigned int),
78 .mode = 0644,
79 .proc_handler = proc_dointvec,
80 },
81 {
82 .procname = "nf_conntrack_frag6_high_thresh",
83 .data = &init_net.nf_frag.frags.high_thresh,
84 .maxlen = sizeof(unsigned int),
85 .mode = 0644,
86 .proc_handler = proc_dointvec,
87 },
88 { }
89 };
90
nf_ct_frag6_sysctl_register(struct net * net)91 static int nf_ct_frag6_sysctl_register(struct net *net)
92 {
93 struct ctl_table *table;
94 struct ctl_table_header *hdr;
95
96 table = nf_ct_frag6_sysctl_table;
97 if (!net_eq(net, &init_net)) {
98 table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
99 GFP_KERNEL);
100 if (table == NULL)
101 goto err_alloc;
102
103 table[0].data = &net->nf_frag.frags.timeout;
104 table[1].data = &net->nf_frag.frags.low_thresh;
105 table[2].data = &net->nf_frag.frags.high_thresh;
106 }
107
108 hdr = register_net_sysctl(net, "net/netfilter", table);
109 if (hdr == NULL)
110 goto err_reg;
111
112 net->nf_frag.sysctl.frags_hdr = hdr;
113 return 0;
114
115 err_reg:
116 if (!net_eq(net, &init_net))
117 kfree(table);
118 err_alloc:
119 return -ENOMEM;
120 }
121
nf_ct_frags6_sysctl_unregister(struct net * net)122 static void __net_exit nf_ct_frags6_sysctl_unregister(struct net *net)
123 {
124 struct ctl_table *table;
125
126 table = net->nf_frag.sysctl.frags_hdr->ctl_table_arg;
127 unregister_net_sysctl_table(net->nf_frag.sysctl.frags_hdr);
128 if (!net_eq(net, &init_net))
129 kfree(table);
130 }
131
132 #else
nf_ct_frag6_sysctl_register(struct net * net)133 static int nf_ct_frag6_sysctl_register(struct net *net)
134 {
135 return 0;
136 }
nf_ct_frags6_sysctl_unregister(struct net * net)137 static void __net_exit nf_ct_frags6_sysctl_unregister(struct net *net)
138 {
139 }
140 #endif
141
ip6_frag_ecn(const struct ipv6hdr * ipv6h)142 static inline u8 ip6_frag_ecn(const struct ipv6hdr *ipv6h)
143 {
144 return 1 << (ipv6_get_dsfield(ipv6h) & INET_ECN_MASK);
145 }
146
nf_hashfn(struct inet_frag_queue * q)147 static unsigned int nf_hashfn(struct inet_frag_queue *q)
148 {
149 const struct frag_queue *nq;
150
151 nq = container_of(q, struct frag_queue, q);
152 return inet6_hash_frag(nq->id, &nq->saddr, &nq->daddr, nf_frags.rnd);
153 }
154
nf_skb_free(struct sk_buff * skb)155 static void nf_skb_free(struct sk_buff *skb)
156 {
157 if (NFCT_FRAG6_CB(skb)->orig)
158 kfree_skb(NFCT_FRAG6_CB(skb)->orig);
159 }
160
nf_ct_frag6_expire(unsigned long data)161 static void nf_ct_frag6_expire(unsigned long data)
162 {
163 struct frag_queue *fq;
164 struct net *net;
165
166 fq = container_of((struct inet_frag_queue *)data, struct frag_queue, q);
167 net = container_of(fq->q.net, struct net, nf_frag.frags);
168
169 ip6_expire_frag_queue(net, fq, &nf_frags);
170 }
171
172 /* Creation primitives. */
fq_find(struct net * net,__be32 id,u32 user,struct in6_addr * src,struct in6_addr * dst,u8 ecn)173 static inline struct frag_queue *fq_find(struct net *net, __be32 id,
174 u32 user, struct in6_addr *src,
175 struct in6_addr *dst, u8 ecn)
176 {
177 struct inet_frag_queue *q;
178 struct ip6_create_arg arg;
179 unsigned int hash;
180
181 arg.id = id;
182 arg.user = user;
183 arg.src = src;
184 arg.dst = dst;
185 arg.ecn = ecn;
186
187 read_lock_bh(&nf_frags.lock);
188 hash = inet6_hash_frag(id, src, dst, nf_frags.rnd);
189
190 q = inet_frag_find(&net->nf_frag.frags, &nf_frags, &arg, hash);
191 local_bh_enable();
192 if (IS_ERR_OR_NULL(q)) {
193 inet_frag_maybe_warn_overflow(q, pr_fmt());
194 return NULL;
195 }
196 return container_of(q, struct frag_queue, q);
197 }
198
199
nf_ct_frag6_queue(struct frag_queue * fq,struct sk_buff * skb,const struct frag_hdr * fhdr,int nhoff)200 static int nf_ct_frag6_queue(struct frag_queue *fq, struct sk_buff *skb,
201 const struct frag_hdr *fhdr, int nhoff)
202 {
203 struct sk_buff *prev, *next;
204 unsigned int payload_len;
205 int offset, end;
206 u8 ecn;
207
208 if (fq->q.last_in & INET_FRAG_COMPLETE) {
209 pr_debug("Already completed\n");
210 goto err;
211 }
212
213 payload_len = ntohs(ipv6_hdr(skb)->payload_len);
214
215 offset = ntohs(fhdr->frag_off) & ~0x7;
216 end = offset + (payload_len -
217 ((u8 *)(fhdr + 1) - (u8 *)(ipv6_hdr(skb) + 1)));
218
219 if ((unsigned int)end > IPV6_MAXPLEN) {
220 pr_debug("offset is too large.\n");
221 return -1;
222 }
223
224 ecn = ip6_frag_ecn(ipv6_hdr(skb));
225
226 if (skb->ip_summed == CHECKSUM_COMPLETE) {
227 const unsigned char *nh = skb_network_header(skb);
228 skb->csum = csum_sub(skb->csum,
229 csum_partial(nh, (u8 *)(fhdr + 1) - nh,
230 0));
231 }
232
233 /* Is this the final fragment? */
234 if (!(fhdr->frag_off & htons(IP6_MF))) {
235 /* If we already have some bits beyond end
236 * or have different end, the segment is corrupted.
237 */
238 if (end < fq->q.len ||
239 ((fq->q.last_in & INET_FRAG_LAST_IN) && end != fq->q.len)) {
240 pr_debug("already received last fragment\n");
241 goto err;
242 }
243 fq->q.last_in |= INET_FRAG_LAST_IN;
244 fq->q.len = end;
245 } else {
246 /* Check if the fragment is rounded to 8 bytes.
247 * Required by the RFC.
248 */
249 if (end & 0x7) {
250 /* RFC2460 says always send parameter problem in
251 * this case. -DaveM
252 */
253 pr_debug("end of fragment not rounded to 8 bytes.\n");
254 return -1;
255 }
256 if (end > fq->q.len) {
257 /* Some bits beyond end -> corruption. */
258 if (fq->q.last_in & INET_FRAG_LAST_IN) {
259 pr_debug("last packet already reached.\n");
260 goto err;
261 }
262 fq->q.len = end;
263 }
264 }
265
266 if (end == offset)
267 goto err;
268
269 /* Point into the IP datagram 'data' part. */
270 if (!pskb_pull(skb, (u8 *) (fhdr + 1) - skb->data)) {
271 pr_debug("queue: message is too short.\n");
272 goto err;
273 }
274 if (pskb_trim_rcsum(skb, end - offset)) {
275 pr_debug("Can't trim\n");
276 goto err;
277 }
278
279 /* Find out which fragments are in front and at the back of us
280 * in the chain of fragments so far. We must know where to put
281 * this fragment, right?
282 */
283 prev = fq->q.fragments_tail;
284 if (!prev || NFCT_FRAG6_CB(prev)->offset < offset) {
285 next = NULL;
286 goto found;
287 }
288 prev = NULL;
289 for (next = fq->q.fragments; next != NULL; next = next->next) {
290 if (NFCT_FRAG6_CB(next)->offset >= offset)
291 break; /* bingo! */
292 prev = next;
293 }
294
295 found:
296 /* RFC5722, Section 4:
297 * When reassembling an IPv6 datagram, if
298 * one or more its constituent fragments is determined to be an
299 * overlapping fragment, the entire datagram (and any constituent
300 * fragments, including those not yet received) MUST be silently
301 * discarded.
302 */
303
304 /* Check for overlap with preceding fragment. */
305 if (prev &&
306 (NFCT_FRAG6_CB(prev)->offset + prev->len) > offset)
307 goto discard_fq;
308
309 /* Look for overlap with succeeding segment. */
310 if (next && NFCT_FRAG6_CB(next)->offset < end)
311 goto discard_fq;
312
313 NFCT_FRAG6_CB(skb)->offset = offset;
314
315 /* Insert this fragment in the chain of fragments. */
316 skb->next = next;
317 if (!next)
318 fq->q.fragments_tail = skb;
319 if (prev)
320 prev->next = skb;
321 else
322 fq->q.fragments = skb;
323
324 if (skb->dev) {
325 fq->iif = skb->dev->ifindex;
326 skb->dev = NULL;
327 }
328 fq->q.stamp = skb->tstamp;
329 fq->q.meat += skb->len;
330 fq->ecn |= ecn;
331 if (payload_len > fq->q.max_size)
332 fq->q.max_size = payload_len;
333 add_frag_mem_limit(&fq->q, skb->truesize);
334
335 /* The first fragment.
336 * nhoffset is obtained from the first fragment, of course.
337 */
338 if (offset == 0) {
339 fq->nhoffset = nhoff;
340 fq->q.last_in |= INET_FRAG_FIRST_IN;
341 }
342
343 inet_frag_lru_move(&fq->q);
344 return 0;
345
346 discard_fq:
347 inet_frag_kill(&fq->q, &nf_frags);
348 err:
349 return -1;
350 }
351
352 /*
353 * Check if this packet is complete.
354 * Returns NULL on failure by any reason, and pointer
355 * to current nexthdr field in reassembled frame.
356 *
357 * It is called with locked fq, and caller must check that
358 * queue is eligible for reassembly i.e. it is not COMPLETE,
359 * the last and the first frames arrived and all the bits are here.
360 */
361 static struct sk_buff *
nf_ct_frag6_reasm(struct frag_queue * fq,struct net_device * dev)362 nf_ct_frag6_reasm(struct frag_queue *fq, struct net_device *dev)
363 {
364 struct sk_buff *fp, *op, *head = fq->q.fragments;
365 int payload_len;
366 u8 ecn;
367
368 inet_frag_kill(&fq->q, &nf_frags);
369
370 WARN_ON(head == NULL);
371 WARN_ON(NFCT_FRAG6_CB(head)->offset != 0);
372
373 ecn = ip_frag_ecn_table[fq->ecn];
374 if (unlikely(ecn == 0xff))
375 goto out_fail;
376
377 /* Unfragmented part is taken from the first segment. */
378 payload_len = ((head->data - skb_network_header(head)) -
379 sizeof(struct ipv6hdr) + fq->q.len -
380 sizeof(struct frag_hdr));
381 if (payload_len > IPV6_MAXPLEN) {
382 pr_debug("payload len is too large.\n");
383 goto out_oversize;
384 }
385
386 /* Head of list must not be cloned. */
387 if (skb_unclone(head, GFP_ATOMIC)) {
388 pr_debug("skb is cloned but can't expand head");
389 goto out_oom;
390 }
391
392 /* If the first fragment is fragmented itself, we split
393 * it to two chunks: the first with data and paged part
394 * and the second, holding only fragments. */
395 if (skb_has_frag_list(head)) {
396 struct sk_buff *clone;
397 int i, plen = 0;
398
399 clone = alloc_skb(0, GFP_ATOMIC);
400 if (clone == NULL)
401 goto out_oom;
402
403 clone->next = head->next;
404 head->next = clone;
405 skb_shinfo(clone)->frag_list = skb_shinfo(head)->frag_list;
406 skb_frag_list_init(head);
407 for (i = 0; i < skb_shinfo(head)->nr_frags; i++)
408 plen += skb_frag_size(&skb_shinfo(head)->frags[i]);
409 clone->len = clone->data_len = head->data_len - plen;
410 head->data_len -= clone->len;
411 head->len -= clone->len;
412 clone->csum = 0;
413 clone->ip_summed = head->ip_summed;
414
415 NFCT_FRAG6_CB(clone)->orig = NULL;
416 add_frag_mem_limit(&fq->q, clone->truesize);
417 }
418
419 /* We have to remove fragment header from datagram and to relocate
420 * header in order to calculate ICV correctly. */
421 skb_network_header(head)[fq->nhoffset] = skb_transport_header(head)[0];
422 memmove(head->head + sizeof(struct frag_hdr), head->head,
423 (head->data - head->head) - sizeof(struct frag_hdr));
424 head->mac_header += sizeof(struct frag_hdr);
425 head->network_header += sizeof(struct frag_hdr);
426
427 skb_shinfo(head)->frag_list = head->next;
428 skb_reset_transport_header(head);
429 skb_push(head, head->data - skb_network_header(head));
430
431 for (fp=head->next; fp; fp = fp->next) {
432 head->data_len += fp->len;
433 head->len += fp->len;
434 if (head->ip_summed != fp->ip_summed)
435 head->ip_summed = CHECKSUM_NONE;
436 else if (head->ip_summed == CHECKSUM_COMPLETE)
437 head->csum = csum_add(head->csum, fp->csum);
438 head->truesize += fp->truesize;
439 }
440 sub_frag_mem_limit(&fq->q, head->truesize);
441
442 head->local_df = 1;
443 head->next = NULL;
444 head->dev = dev;
445 head->tstamp = fq->q.stamp;
446 ipv6_hdr(head)->payload_len = htons(payload_len);
447 ipv6_change_dsfield(ipv6_hdr(head), 0xff, ecn);
448 IP6CB(head)->frag_max_size = sizeof(struct ipv6hdr) + fq->q.max_size;
449
450 /* Yes, and fold redundant checksum back. 8) */
451 if (head->ip_summed == CHECKSUM_COMPLETE)
452 head->csum = csum_partial(skb_network_header(head),
453 skb_network_header_len(head),
454 head->csum);
455
456 fq->q.fragments = NULL;
457 fq->q.fragments_tail = NULL;
458
459 /* all original skbs are linked into the NFCT_FRAG6_CB(head).orig */
460 fp = skb_shinfo(head)->frag_list;
461 if (fp && NFCT_FRAG6_CB(fp)->orig == NULL)
462 /* at above code, head skb is divided into two skbs. */
463 fp = fp->next;
464
465 op = NFCT_FRAG6_CB(head)->orig;
466 for (; fp; fp = fp->next) {
467 struct sk_buff *orig = NFCT_FRAG6_CB(fp)->orig;
468
469 op->next = orig;
470 op = orig;
471 NFCT_FRAG6_CB(fp)->orig = NULL;
472 }
473
474 return head;
475
476 out_oversize:
477 net_dbg_ratelimited("nf_ct_frag6_reasm: payload len = %d\n",
478 payload_len);
479 goto out_fail;
480 out_oom:
481 net_dbg_ratelimited("nf_ct_frag6_reasm: no memory for reassembly\n");
482 out_fail:
483 return NULL;
484 }
485
486 /*
487 * find the header just before Fragment Header.
488 *
489 * if success return 0 and set ...
490 * (*prevhdrp): the value of "Next Header Field" in the header
491 * just before Fragment Header.
492 * (*prevhoff): the offset of "Next Header Field" in the header
493 * just before Fragment Header.
494 * (*fhoff) : the offset of Fragment Header.
495 *
496 * Based on ipv6_skip_hdr() in net/ipv6/exthdr.c
497 *
498 */
499 static int
find_prev_fhdr(struct sk_buff * skb,u8 * prevhdrp,int * prevhoff,int * fhoff)500 find_prev_fhdr(struct sk_buff *skb, u8 *prevhdrp, int *prevhoff, int *fhoff)
501 {
502 u8 nexthdr = ipv6_hdr(skb)->nexthdr;
503 const int netoff = skb_network_offset(skb);
504 u8 prev_nhoff = netoff + offsetof(struct ipv6hdr, nexthdr);
505 int start = netoff + sizeof(struct ipv6hdr);
506 int len = skb->len - start;
507 u8 prevhdr = NEXTHDR_IPV6;
508
509 while (nexthdr != NEXTHDR_FRAGMENT) {
510 struct ipv6_opt_hdr hdr;
511 int hdrlen;
512
513 if (!ipv6_ext_hdr(nexthdr)) {
514 return -1;
515 }
516 if (nexthdr == NEXTHDR_NONE) {
517 pr_debug("next header is none\n");
518 return -1;
519 }
520 if (len < (int)sizeof(struct ipv6_opt_hdr)) {
521 pr_debug("too short\n");
522 return -1;
523 }
524 if (skb_copy_bits(skb, start, &hdr, sizeof(hdr)))
525 BUG();
526 if (nexthdr == NEXTHDR_AUTH)
527 hdrlen = (hdr.hdrlen+2)<<2;
528 else
529 hdrlen = ipv6_optlen(&hdr);
530
531 prevhdr = nexthdr;
532 prev_nhoff = start;
533
534 nexthdr = hdr.nexthdr;
535 len -= hdrlen;
536 start += hdrlen;
537 }
538
539 if (len < 0)
540 return -1;
541
542 *prevhdrp = prevhdr;
543 *prevhoff = prev_nhoff;
544 *fhoff = start;
545
546 return 0;
547 }
548
nf_ct_frag6_gather(struct sk_buff * skb,u32 user)549 struct sk_buff *nf_ct_frag6_gather(struct sk_buff *skb, u32 user)
550 {
551 struct sk_buff *clone;
552 struct net_device *dev = skb->dev;
553 struct net *net = skb_dst(skb) ? dev_net(skb_dst(skb)->dev)
554 : dev_net(skb->dev);
555 struct frag_hdr *fhdr;
556 struct frag_queue *fq;
557 struct ipv6hdr *hdr;
558 int fhoff, nhoff;
559 u8 prevhdr;
560 struct sk_buff *ret_skb = NULL;
561
562 /* Jumbo payload inhibits frag. header */
563 if (ipv6_hdr(skb)->payload_len == 0) {
564 pr_debug("payload len = 0\n");
565 return skb;
566 }
567
568 if (find_prev_fhdr(skb, &prevhdr, &nhoff, &fhoff) < 0)
569 return skb;
570
571 clone = skb_clone(skb, GFP_ATOMIC);
572 if (clone == NULL) {
573 pr_debug("Can't clone skb\n");
574 return skb;
575 }
576
577 NFCT_FRAG6_CB(clone)->orig = skb;
578
579 if (!pskb_may_pull(clone, fhoff + sizeof(*fhdr))) {
580 pr_debug("message is too short.\n");
581 goto ret_orig;
582 }
583
584 skb_set_transport_header(clone, fhoff);
585 hdr = ipv6_hdr(clone);
586 fhdr = (struct frag_hdr *)skb_transport_header(clone);
587
588 local_bh_disable();
589 inet_frag_evictor(&net->nf_frag.frags, &nf_frags, false);
590 local_bh_enable();
591
592 fq = fq_find(net, fhdr->identification, user, &hdr->saddr, &hdr->daddr,
593 ip6_frag_ecn(hdr));
594 if (fq == NULL) {
595 pr_debug("Can't find and can't create new queue\n");
596 goto ret_orig;
597 }
598
599 spin_lock_bh(&fq->q.lock);
600
601 if (nf_ct_frag6_queue(fq, clone, fhdr, nhoff) < 0) {
602 spin_unlock_bh(&fq->q.lock);
603 pr_debug("Can't insert skb to queue\n");
604 inet_frag_put(&fq->q, &nf_frags);
605 goto ret_orig;
606 }
607
608 if (fq->q.last_in == (INET_FRAG_FIRST_IN | INET_FRAG_LAST_IN) &&
609 fq->q.meat == fq->q.len) {
610 ret_skb = nf_ct_frag6_reasm(fq, dev);
611 if (ret_skb == NULL)
612 pr_debug("Can't reassemble fragmented packets\n");
613 }
614 spin_unlock_bh(&fq->q.lock);
615
616 inet_frag_put(&fq->q, &nf_frags);
617 return ret_skb;
618
619 ret_orig:
620 kfree_skb(clone);
621 return skb;
622 }
623
nf_ct_frag6_output(unsigned int hooknum,struct sk_buff * skb,struct net_device * in,struct net_device * out,int (* okfn)(struct sk_buff *))624 void nf_ct_frag6_output(unsigned int hooknum, struct sk_buff *skb,
625 struct net_device *in, struct net_device *out,
626 int (*okfn)(struct sk_buff *))
627 {
628 struct sk_buff *s, *s2;
629 unsigned int ret = 0;
630
631 for (s = NFCT_FRAG6_CB(skb)->orig; s;) {
632 nf_conntrack_put_reasm(s->nfct_reasm);
633 nf_conntrack_get_reasm(skb);
634 s->nfct_reasm = skb;
635
636 s2 = s->next;
637 s->next = NULL;
638
639 if (ret != -ECANCELED)
640 ret = NF_HOOK_THRESH(NFPROTO_IPV6, hooknum, s,
641 in, out, okfn,
642 NF_IP6_PRI_CONNTRACK_DEFRAG + 1);
643 else
644 kfree_skb(s);
645
646 s = s2;
647 }
648 nf_conntrack_put_reasm(skb);
649 }
650
nf_ct_net_init(struct net * net)651 static int nf_ct_net_init(struct net *net)
652 {
653 net->nf_frag.frags.high_thresh = IPV6_FRAG_HIGH_THRESH;
654 net->nf_frag.frags.low_thresh = IPV6_FRAG_LOW_THRESH;
655 net->nf_frag.frags.timeout = IPV6_FRAG_TIMEOUT;
656 inet_frags_init_net(&net->nf_frag.frags);
657
658 return nf_ct_frag6_sysctl_register(net);
659 }
660
nf_ct_net_exit(struct net * net)661 static void nf_ct_net_exit(struct net *net)
662 {
663 nf_ct_frags6_sysctl_unregister(net);
664 inet_frags_exit_net(&net->nf_frag.frags, &nf_frags);
665 }
666
667 static struct pernet_operations nf_ct_net_ops = {
668 .init = nf_ct_net_init,
669 .exit = nf_ct_net_exit,
670 };
671
nf_ct_frag6_init(void)672 int nf_ct_frag6_init(void)
673 {
674 int ret = 0;
675
676 nf_frags.hashfn = nf_hashfn;
677 nf_frags.constructor = ip6_frag_init;
678 nf_frags.destructor = NULL;
679 nf_frags.skb_free = nf_skb_free;
680 nf_frags.qsize = sizeof(struct frag_queue);
681 nf_frags.match = ip6_frag_match;
682 nf_frags.frag_expire = nf_ct_frag6_expire;
683 nf_frags.secret_interval = 10 * 60 * HZ;
684 inet_frags_init(&nf_frags);
685
686 ret = register_pernet_subsys(&nf_ct_net_ops);
687 if (ret)
688 inet_frags_fini(&nf_frags);
689
690 return ret;
691 }
692
nf_ct_frag6_cleanup(void)693 void nf_ct_frag6_cleanup(void)
694 {
695 unregister_pernet_subsys(&nf_ct_net_ops);
696 inet_frags_fini(&nf_frags);
697 }
698