reassembly.c 14.1 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0-or-later
L
Linus Torvalds 已提交
2 3
/*
 *	IPv6 fragment reassembly
4
 *	Linux INET6 implementation
L
Linus Torvalds 已提交
5 6
 *
 *	Authors:
7
 *	Pedro Roque		<roque@di.fc.ul.pt>
L
Linus Torvalds 已提交
8 9 10 11
 *
 *	Based on: net/ipv4/ip_fragment.c
 */

12 13
/*
 *	Fixes:
L
Linus Torvalds 已提交
14 15 16 17 18 19 20 21 22 23 24
 *	Andi Kleen	Make it work with multiple hosts.
 *			More RFC compliance.
 *
 *      Horst von Brand Add missing #include <linux/string.h>
 *	Alexey Kuznetsov	SMP races, threading, cleanup.
 *	Patrick McHardy		LRU queue of frag heads for evictor.
 *	Mitsuru KANDA @USAGI	Register inet6_protocol{}.
 *	David Stevens and
 *	YOSHIFUJI,H. @USAGI	Always remove fragment header to
 *				calculate ICV correctly.
 */
25 26 27

#define pr_fmt(fmt) "IPv6: " fmt

L
Linus Torvalds 已提交
28 29 30 31 32 33 34 35 36 37 38 39 40 41
#include <linux/errno.h>
#include <linux/types.h>
#include <linux/string.h>
#include <linux/socket.h>
#include <linux/sockios.h>
#include <linux/jiffies.h>
#include <linux/net.h>
#include <linux/list.h>
#include <linux/netdevice.h>
#include <linux/in6.h>
#include <linux/ipv6.h>
#include <linux/icmpv6.h>
#include <linux/random.h>
#include <linux/jhash.h>
42
#include <linux/skbuff.h>
43
#include <linux/slab.h>
44
#include <linux/export.h>
L
Linus Torvalds 已提交
45 46 47 48 49

#include <net/sock.h>
#include <net/snmp.h>

#include <net/ipv6.h>
50
#include <net/ip6_route.h>
L
Linus Torvalds 已提交
51 52 53 54 55
#include <net/protocol.h>
#include <net/transp_v6.h>
#include <net/rawv6.h>
#include <net/ndisc.h>
#include <net/addrconf.h>
56
#include <net/ipv6_frag.h>
57
#include <net/inet_ecn.h>
L
Linus Torvalds 已提交
58

59 60
static const char ip6_frag_cache_name[] = "ip6-frags";

61
static u8 ip6_frag_ecn(const struct ipv6hdr *ipv6h)
62 63 64
{
	return 1 << (ipv6_get_dsfield(ipv6h) & INET_ECN_MASK);
}
L
Linus Torvalds 已提交
65

66
static struct inet_frags ip6_frags;
L
Linus Torvalds 已提交
67

68 69
static int ip6_frag_reasm(struct frag_queue *fq, struct sk_buff *skb,
			  struct sk_buff *prev_tail, struct net_device *dev);
70

71
static void ip6_frag_expire(struct timer_list *t)
72
{
73
	struct inet_frag_queue *frag = from_timer(frag, t, timer);
74 75
	struct frag_queue *fq;

76
	fq = container_of(frag, struct frag_queue, q);
77

78
	ip6frag_expire_frag_queue(fq->q.fqdir->net, fq);
L
Linus Torvalds 已提交
79 80
}

81
static struct frag_queue *
82
fq_find(struct net *net, __be32 id, const struct ipv6hdr *hdr, int iif)
L
Linus Torvalds 已提交
83
{
84 85 86 87 88 89 90
	struct frag_v6_compare_key key = {
		.id = id,
		.saddr = hdr->saddr,
		.daddr = hdr->daddr,
		.user = IP6_DEFRAG_LOCAL_DELIVER,
		.iif = iif,
	};
91
	struct inet_frag_queue *q;
92

93 94 95
	if (!(ipv6_addr_type(&hdr->daddr) & (IPV6_ADDR_MULTICAST |
					    IPV6_ADDR_LINKLOCAL)))
		key.iif = 0;
L
Linus Torvalds 已提交
96

97
	q = inet_frag_find(net->ipv6.fqdir, &key);
98
	if (!q)
99
		return NULL;
100

101
	return container_of(q, struct frag_queue, q);
L
Linus Torvalds 已提交
102 103
}

104
static int ip6_frag_queue(struct frag_queue *fq, struct sk_buff *skb,
105 106
			  struct frag_hdr *fhdr, int nhoff,
			  u32 *prob_offset)
L
Linus Torvalds 已提交
107
{
E
Eric Dumazet 已提交
108
	struct net *net = dev_net(skb_dst(skb)->dev);
109 110 111 112
	int offset, end, fragsize;
	struct sk_buff *prev_tail;
	struct net_device *dev;
	int err = -ENOENT;
113
	u8 ecn;
L
Linus Torvalds 已提交
114

115
	if (fq->q.flags & INET_FRAG_COMPLETE)
L
Linus Torvalds 已提交
116 117
		goto err;

118
	err = -EINVAL;
L
Linus Torvalds 已提交
119
	offset = ntohs(fhdr->frag_off) & ~0x7;
120 121
	end = offset + (ntohs(ipv6_hdr(skb)->payload_len) -
			((u8 *)(fhdr + 1) - (u8 *)(ipv6_hdr(skb) + 1)));
L
Linus Torvalds 已提交
122 123

	if ((unsigned int)end > IPV6_MAXPLEN) {
124
		*prob_offset = (u8 *)&fhdr->frag_off - skb_network_header(skb);
125 126 127
		/* note that if prob_offset is set, the skb is freed elsewhere,
		 * we do not free it here.
		 */
128
		return -1;
L
Linus Torvalds 已提交
129 130
	}

131 132
	ecn = ip6_frag_ecn(ipv6_hdr(skb));

133 134
	if (skb->ip_summed == CHECKSUM_COMPLETE) {
		const unsigned char *nh = skb_network_header(skb);
135
		skb->csum = csum_sub(skb->csum,
136 137 138
				     csum_partial(nh, (u8 *)(fhdr + 1) - nh,
						  0));
	}
L
Linus Torvalds 已提交
139 140 141 142 143 144

	/* Is this the final fragment? */
	if (!(fhdr->frag_off & htons(IP6_MF))) {
		/* If we already have some bits beyond end
		 * or have different end, the segment is corrupted.
		 */
145
		if (end < fq->q.len ||
146
		    ((fq->q.flags & INET_FRAG_LAST_IN) && end != fq->q.len))
147
			goto discard_fq;
148
		fq->q.flags |= INET_FRAG_LAST_IN;
149
		fq->q.len = end;
L
Linus Torvalds 已提交
150 151 152 153 154 155 156 157
	} else {
		/* Check if the fragment is rounded to 8 bytes.
		 * Required by the RFC.
		 */
		if (end & 0x7) {
			/* RFC2460 says always send parameter problem in
			 * this case. -DaveM
			 */
158
			*prob_offset = offsetof(struct ipv6hdr, payload_len);
159
			return -1;
L
Linus Torvalds 已提交
160
		}
161
		if (end > fq->q.len) {
L
Linus Torvalds 已提交
162
			/* Some bits beyond end -> corruption. */
163
			if (fq->q.flags & INET_FRAG_LAST_IN)
164
				goto discard_fq;
165
			fq->q.len = end;
L
Linus Torvalds 已提交
166 167 168 169
		}
	}

	if (end == offset)
170
		goto discard_fq;
L
Linus Torvalds 已提交
171

172
	err = -ENOMEM;
L
Linus Torvalds 已提交
173 174
	/* Point into the IP datagram 'data' part. */
	if (!pskb_pull(skb, (u8 *) (fhdr + 1) - skb->data))
175
		goto discard_fq;
176

177 178
	err = pskb_trim_rcsum(skb, end - offset);
	if (err)
179
		goto discard_fq;
L
Linus Torvalds 已提交
180

181
	/* Note : skb->rbnode and skb->dev share the same location. */
182 183 184
	dev = skb->dev;
	/* Makes sure compiler wont do silly aliasing games */
	barrier();
L
Linus Torvalds 已提交
185

186 187 188 189 190 191 192
	prev_tail = fq->q.fragments_tail;
	err = inet_frag_queue_insert(&fq->q, skb, offset, end);
	if (err)
		goto insert_error;

	if (dev)
		fq->iif = dev->ifindex;
L
Linus Torvalds 已提交
193

194 195
	fq->q.stamp = skb->tstamp;
	fq->q.meat += skb->len;
196
	fq->ecn |= ecn;
E
Eric Dumazet 已提交
197
	add_frag_mem_limit(fq->q.fqdir, skb->truesize);
L
Linus Torvalds 已提交
198

199 200 201 202
	fragsize = -skb_network_offset(skb) + skb->len;
	if (fragsize > fq->q.max_size)
		fq->q.max_size = fragsize;

L
Linus Torvalds 已提交
203 204 205 206 207
	/* The first fragment.
	 * nhoffset is obtained from the first fragment, of course.
	 */
	if (offset == 0) {
		fq->nhoffset = nhoff;
208
		fq->q.flags |= INET_FRAG_FIRST_IN;
L
Linus Torvalds 已提交
209
	}
210

211
	if (fq->q.flags == (INET_FRAG_FIRST_IN | INET_FRAG_LAST_IN) &&
212 213 214 215
	    fq->q.meat == fq->q.len) {
		unsigned long orefdst = skb->_skb_refdst;

		skb->_skb_refdst = 0UL;
216
		err = ip6_frag_reasm(fq, skb, prev_tail, dev);
217
		skb->_skb_refdst = orefdst;
218
		return err;
219
	}
220

221
	skb_dst_drop(skb);
222
	return -EINPROGRESS;
L
Linus Torvalds 已提交
223

224 225 226 227 228 229 230 231
insert_error:
	if (err == IPFRAG_DUP) {
		kfree_skb(skb);
		return -EINVAL;
	}
	err = -EINVAL;
	__IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)),
			IPSTATS_MIB_REASM_OVERLAPS);
232
discard_fq:
233
	inet_frag_kill(&fq->q);
E
Eric Dumazet 已提交
234 235
	__IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)),
			IPSTATS_MIB_REASMFAILS);
236
err:
L
Linus Torvalds 已提交
237
	kfree_skb(skb);
238
	return err;
L
Linus Torvalds 已提交
239 240 241 242 243 244 245 246 247
}

/*
 *	Check if this packet is complete.
 *
 *	It is called with locked fq, and caller must check that
 *	queue is eligible for reassembly i.e. it is not COMPLETE,
 *	the last and the first frames arrived and all the bits are here.
 */
248 249
static int ip6_frag_reasm(struct frag_queue *fq, struct sk_buff *skb,
			  struct sk_buff *prev_tail, struct net_device *dev)
L
Linus Torvalds 已提交
250
{
251
	struct net *net = fq->q.fqdir->net;
L
Linus Torvalds 已提交
252
	unsigned int nhoff;
253 254
	void *reasm_data;
	int payload_len;
255
	u8 ecn;
L
Linus Torvalds 已提交
256

257
	inet_frag_kill(&fq->q);
L
Linus Torvalds 已提交
258

259 260 261 262
	ecn = ip_frag_ecn_table[fq->ecn];
	if (unlikely(ecn == 0xff))
		goto out_fail;

263 264 265
	reasm_data = inet_frag_reasm_prepare(&fq->q, skb, prev_tail);
	if (!reasm_data)
		goto out_oom;
L
Linus Torvalds 已提交
266

267
	payload_len = ((skb->data - skb_network_header(skb)) -
268
		       sizeof(struct ipv6hdr) + fq->q.len -
269
		       sizeof(struct frag_hdr));
L
Linus Torvalds 已提交
270 271 272 273 274 275
	if (payload_len > IPV6_MAXPLEN)
		goto out_oversize;

	/* We have to remove fragment header from datagram and to relocate
	 * header in order to calculate ICV correctly. */
	nhoff = fq->nhoffset;
276 277 278 279 280 281 282 283 284
	skb_network_header(skb)[nhoff] = skb_transport_header(skb)[0];
	memmove(skb->head + sizeof(struct frag_hdr), skb->head,
		(skb->data - skb->head) - sizeof(struct frag_hdr));
	if (skb_mac_header_was_set(skb))
		skb->mac_header += sizeof(struct frag_hdr);
	skb->network_header += sizeof(struct frag_hdr);

	skb_reset_transport_header(skb);

285
	inet_frag_reasm_finish(&fq->q, skb, reasm_data, true);
L
Linus Torvalds 已提交
286

287 288 289 290 291 292
	skb->dev = dev;
	ipv6_hdr(skb)->payload_len = htons(payload_len);
	ipv6_change_dsfield(ipv6_hdr(skb), 0xff, ecn);
	IP6CB(skb)->nhoff = nhoff;
	IP6CB(skb)->flags |= IP6SKB_FRAGMENTED;
	IP6CB(skb)->frag_max_size = fq->q.max_size;
L
Linus Torvalds 已提交
293 294

	/* Yes, and fold redundant checksum back. 8) */
295 296
	skb_postpush_rcsum(skb, skb_network_header(skb),
			   skb_network_header_len(skb));
L
Linus Torvalds 已提交
297

298
	rcu_read_lock();
299
	__IP6_INC_STATS(net, __in6_dev_stats_get(dev, skb), IPSTATS_MIB_REASMOKS);
300
	rcu_read_unlock();
301
	fq->q.rb_fragments = RB_ROOT;
302
	fq->q.fragments_tail = NULL;
303
	fq->q.last_run_head = NULL;
L
Linus Torvalds 已提交
304 305 306
	return 1;

out_oversize:
307
	net_dbg_ratelimited("ip6_frag_reasm: payload len = %d\n", payload_len);
L
Linus Torvalds 已提交
308 309
	goto out_fail;
out_oom:
310
	net_dbg_ratelimited("ip6_frag_reasm: no memory for reassembly\n");
L
Linus Torvalds 已提交
311
out_fail:
312
	rcu_read_lock();
313
	__IP6_INC_STATS(net, __in6_dev_stats_get(dev, skb), IPSTATS_MIB_REASMFAILS);
314
	rcu_read_unlock();
315
	inet_frag_kill(&fq->q);
L
Linus Torvalds 已提交
316 317 318
	return -1;
}

319
static int ipv6_frag_rcv(struct sk_buff *skb)
L
Linus Torvalds 已提交
320 321 322
{
	struct frag_hdr *fhdr;
	struct frag_queue *fq;
323
	const struct ipv6hdr *hdr = ipv6_hdr(skb);
E
Eric Dumazet 已提交
324
	struct net *net = dev_net(skb_dst(skb)->dev);
325
	int iif;
L
Linus Torvalds 已提交
326

327 328 329
	if (IP6CB(skb)->flags & IP6SKB_FRAGMENTED)
		goto fail_hdr;

E
Eric Dumazet 已提交
330
	__IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)), IPSTATS_MIB_REASMREQDS);
L
Linus Torvalds 已提交
331 332

	/* Jumbo payload inhibits frag. header */
333
	if (hdr->payload_len == 0)
334 335
		goto fail_hdr;

336
	if (!pskb_may_pull(skb, (skb_transport_offset(skb) +
337 338
				 sizeof(struct frag_hdr))))
		goto fail_hdr;
L
Linus Torvalds 已提交
339

340
	hdr = ipv6_hdr(skb);
341
	fhdr = (struct frag_hdr *)skb_transport_header(skb);
L
Linus Torvalds 已提交
342 343 344

	if (!(fhdr->frag_off & htons(0xFFF9))) {
		/* It is not a fragmented frame */
345
		skb->transport_header += sizeof(struct frag_hdr);
E
Eric Dumazet 已提交
346 347
		__IP6_INC_STATS(net,
				ip6_dst_idev(skb_dst(skb)), IPSTATS_MIB_REASMOKS);
L
Linus Torvalds 已提交
348

349
		IP6CB(skb)->nhoff = (u8 *)fhdr - skb_network_header(skb);
350
		IP6CB(skb)->flags |= IP6SKB_FRAGMENTED;
L
Linus Torvalds 已提交
351 352 353
		return 1;
	}

354 355
	iif = skb->dev ? skb->dev->ifindex : 0;
	fq = fq_find(net, fhdr->identification, hdr, iif);
356
	if (fq) {
357
		u32 prob_offset = 0;
358
		int ret;
L
Linus Torvalds 已提交
359

360
		spin_lock(&fq->q.lock);
L
Linus Torvalds 已提交
361

362
		fq->iif = iif;
363 364
		ret = ip6_frag_queue(fq, skb, fhdr, IP6CB(skb)->nhoff,
				     &prob_offset);
L
Linus Torvalds 已提交
365

366
		spin_unlock(&fq->q.lock);
367
		inet_frag_put(&fq->q);
368 369 370
		if (prob_offset) {
			__IP6_INC_STATS(net, __in6_dev_get_safely(skb->dev),
					IPSTATS_MIB_INHDRERRORS);
371
			/* icmpv6_param_prob() calls kfree_skb(skb) */
372 373
			icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, prob_offset);
		}
L
Linus Torvalds 已提交
374 375 376
		return ret;
	}

E
Eric Dumazet 已提交
377
	__IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)), IPSTATS_MIB_REASMFAILS);
L
Linus Torvalds 已提交
378 379
	kfree_skb(skb);
	return -1;
380 381

fail_hdr:
382
	__IP6_INC_STATS(net, __in6_dev_get_safely(skb->dev),
E
Eric Dumazet 已提交
383
			IPSTATS_MIB_INHDRERRORS);
384 385
	icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, skb_network_header_len(skb));
	return -1;
L
Linus Torvalds 已提交
386 387
}

388
static const struct inet6_protocol frag_protocol = {
L
Linus Torvalds 已提交
389 390 391 392
	.handler	=	ipv6_frag_rcv,
	.flags		=	INET6_PROTO_NOPOLICY,
};

393
#ifdef CONFIG_SYSCTL
394

395
static struct ctl_table ip6_frags_ns_ctl_table[] = {
396 397
	{
		.procname	= "ip6frag_high_thresh",
398
		.maxlen		= sizeof(unsigned long),
399
		.mode		= 0644,
400
		.proc_handler	= proc_doulongvec_minmax,
401 402 403
	},
	{
		.procname	= "ip6frag_low_thresh",
404
		.maxlen		= sizeof(unsigned long),
405
		.mode		= 0644,
406
		.proc_handler	= proc_doulongvec_minmax,
407 408 409 410 411
	},
	{
		.procname	= "ip6frag_time",
		.maxlen		= sizeof(int),
		.mode		= 0644,
A
Alexey Dobriyan 已提交
412
		.proc_handler	= proc_dointvec_jiffies,
413
	},
414 415 416
	{ }
};

417 418
/* secret interval has been deprecated */
static int ip6_frags_secret_interval_unused;
419
static struct ctl_table ip6_frags_ctl_table[] = {
420 421
	{
		.procname	= "ip6frag_secret_interval",
422
		.data		= &ip6_frags_secret_interval_unused,
423 424
		.maxlen		= sizeof(int),
		.mode		= 0644,
A
Alexey Dobriyan 已提交
425
		.proc_handler	= proc_dointvec_jiffies,
426 427 428 429
	},
	{ }
};

430
static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
431
{
432
	struct ctl_table *table;
433 434
	struct ctl_table_header *hdr;

435
	table = ip6_frags_ns_ctl_table;
O
Octavian Purdila 已提交
436
	if (!net_eq(net, &init_net)) {
437
		table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
438
		if (!table)
439 440 441
			goto err_alloc;

	}
442 443 444 445 446
	table[0].data	= &net->ipv6.fqdir->high_thresh;
	table[0].extra1	= &net->ipv6.fqdir->low_thresh;
	table[1].data	= &net->ipv6.fqdir->low_thresh;
	table[1].extra2	= &net->ipv6.fqdir->high_thresh;
	table[2].data	= &net->ipv6.fqdir->timeout;
447

448
	hdr = register_net_sysctl(net, "net/ipv6", table);
449
	if (!hdr)
450 451 452 453 454 455
		goto err_reg;

	net->ipv6.sysctl.frags_hdr = hdr;
	return 0;

err_reg:
O
Octavian Purdila 已提交
456
	if (!net_eq(net, &init_net))
457 458 459 460 461
		kfree(table);
err_alloc:
	return -ENOMEM;
}

462
static void __net_exit ip6_frags_ns_sysctl_unregister(struct net *net)
463 464 465 466 467
{
	struct ctl_table *table;

	table = net->ipv6.sysctl.frags_hdr->ctl_table_arg;
	unregister_net_sysctl_table(net->ipv6.sysctl.frags_hdr);
468 469
	if (!net_eq(net, &init_net))
		kfree(table);
470
}
471 472 473 474 475

static struct ctl_table_header *ip6_ctl_header;

static int ip6_frags_sysctl_register(void)
{
476
	ip6_ctl_header = register_net_sysctl(&init_net, "net/ipv6",
477 478 479 480 481 482 483 484
			ip6_frags_ctl_table);
	return ip6_ctl_header == NULL ? -ENOMEM : 0;
}

static void ip6_frags_sysctl_unregister(void)
{
	unregister_net_sysctl_table(ip6_ctl_header);
}
485
#else
486
static int ip6_frags_ns_sysctl_register(struct net *net)
487
{
488 489
	return 0;
}
490

491
static void ip6_frags_ns_sysctl_unregister(struct net *net)
492 493
{
}
494

495
static int ip6_frags_sysctl_register(void)
496 497 498 499
{
	return 0;
}

500
static void ip6_frags_sysctl_unregister(void)
501 502
{
}
503
#endif
D
Daniel Lezcano 已提交
504

505
static int __net_init ipv6_frags_init_net(struct net *net)
506
{
507 508
	int res;

509
	res = fqdir_init(&net->ipv6.fqdir, &ip6_frags, net);
510 511
	if (res < 0)
		return res;
512

513 514 515 516
	net->ipv6.fqdir->high_thresh = IPV6_FRAG_HIGH_THRESH;
	net->ipv6.fqdir->low_thresh = IPV6_FRAG_LOW_THRESH;
	net->ipv6.fqdir->timeout = IPV6_FRAG_TIMEOUT;

517 518
	res = ip6_frags_ns_sysctl_register(net);
	if (res < 0)
519
		fqdir_exit(net->ipv6.fqdir);
520
	return res;
521 522
}

523 524 525 526 527
static void __net_exit ipv6_frags_pre_exit_net(struct net *net)
{
	fqdir_pre_exit(net->ipv6.fqdir);
}

528
static void __net_exit ipv6_frags_exit_net(struct net *net)
529
{
530
	ip6_frags_ns_sysctl_unregister(net);
531
	fqdir_exit(net->ipv6.fqdir);
532 533 534
}

static struct pernet_operations ip6_frags_ops = {
535 536 537
	.init		= ipv6_frags_init_net,
	.pre_exit	= ipv6_frags_pre_exit_net,
	.exit		= ipv6_frags_exit_net,
538 539
};

540
static const struct rhashtable_params ip6_rhash_params = {
541
	.head_offset		= offsetof(struct inet_frag_queue, node),
542 543 544
	.hashfn			= ip6frag_key_hashfn,
	.obj_hashfn		= ip6frag_obj_hashfn,
	.obj_cmpfn		= ip6frag_obj_cmpfn,
545 546 547
	.automatic_shrinking	= true,
};

548
int __init ipv6_frag_init(void)
L
Linus Torvalds 已提交
549
{
550
	int ret;
L
Linus Torvalds 已提交
551

552
	ip6_frags.constructor = ip6frag_init;
553 554 555 556
	ip6_frags.destructor = NULL;
	ip6_frags.qsize = sizeof(struct frag_queue);
	ip6_frags.frag_expire = ip6_frag_expire;
	ip6_frags.frags_cache_name = ip6_frag_cache_name;
557
	ip6_frags.rhash_params = ip6_rhash_params;
558
	ret = inet_frags_init(&ip6_frags);
559 560
	if (ret)
		goto out;
561

562 563 564 565
	ret = inet6_add_protocol(&frag_protocol, IPPROTO_FRAGMENT);
	if (ret)
		goto err_protocol;

566 567 568 569
	ret = ip6_frags_sysctl_register();
	if (ret)
		goto err_sysctl;

570 571 572
	ret = register_pernet_subsys(&ip6_frags_ops);
	if (ret)
		goto err_pernet;
573

574 575
out:
	return ret;
576 577

err_pernet:
578 579
	ip6_frags_sysctl_unregister();
err_sysctl:
580
	inet6_del_protocol(&frag_protocol, IPPROTO_FRAGMENT);
581 582
err_protocol:
	inet_frags_fini(&ip6_frags);
583
	goto out;
584 585 586 587
}

void ipv6_frag_exit(void)
{
588
	ip6_frags_sysctl_unregister();
589
	unregister_pernet_subsys(&ip6_frags_ops);
590
	inet6_del_protocol(&frag_protocol, IPPROTO_FRAGMENT);
591
	inet_frags_fini(&ip6_frags);
L
Linus Torvalds 已提交
592
}