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