]> bbs.cooldavid.org Git - net-next-2.6.git/blame - net/ipv6/netfilter/nf_conntrack_reasm.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6
[net-next-2.6.git] / net / ipv6 / netfilter / nf_conntrack_reasm.c
CommitLineData
9fb9cbb1
YK
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
9fb9cbb1
YK
17#include <linux/errno.h>
18#include <linux/types.h>
19#include <linux/string.h>
20#include <linux/socket.h>
21#include <linux/sockios.h>
22#include <linux/jiffies.h>
23#include <linux/net.h>
24#include <linux/list.h>
25#include <linux/netdevice.h>
26#include <linux/in6.h>
27#include <linux/ipv6.h>
28#include <linux/icmpv6.h>
29#include <linux/random.h>
5a0e3ad6 30#include <linux/slab.h>
9fb9cbb1
YK
31
32#include <net/sock.h>
33#include <net/snmp.h>
5ab11c98 34#include <net/inet_frag.h>
9fb9cbb1
YK
35
36#include <net/ipv6.h>
37#include <net/protocol.h>
38#include <net/transp_v6.h>
39#include <net/rawv6.h>
40#include <net/ndisc.h>
41#include <net/addrconf.h>
99fa5f53 42#include <net/netfilter/ipv6/nf_conntrack_ipv6.h>
9fb9cbb1
YK
43#include <linux/sysctl.h>
44#include <linux/netfilter.h>
45#include <linux/netfilter_ipv6.h>
46#include <linux/kernel.h>
47#include <linux/module.h>
48
9fb9cbb1 49
9fb9cbb1
YK
50struct nf_ct_frag6_skb_cb
51{
52 struct inet6_skb_parm h;
53 int offset;
54 struct sk_buff *orig;
55};
56
57#define NFCT_FRAG6_CB(skb) ((struct nf_ct_frag6_skb_cb*)((skb)->cb))
58
59struct nf_ct_frag6_queue
60{
5ab11c98 61 struct inet_frag_queue q;
9fb9cbb1 62
bff9a89b 63 __be32 id; /* fragment id */
c92b544b 64 u32 user;
9fb9cbb1
YK
65 struct in6_addr saddr;
66 struct in6_addr daddr;
67
9fb9cbb1 68 unsigned int csum;
9fb9cbb1 69 __u16 nhoffset;
9fb9cbb1
YK
70};
71
7eb95156 72static struct inet_frags nf_frags;
ac18e750 73static struct netns_frags nf_init_frags;
9fb9cbb1 74
8d8354d2
PE
75#ifdef CONFIG_SYSCTL
76struct ctl_table nf_ct_ipv6_sysctl_table[] = {
77 {
78 .procname = "nf_conntrack_frag6_timeout",
b2fd5321 79 .data = &nf_init_frags.timeout,
8d8354d2
PE
80 .maxlen = sizeof(unsigned int),
81 .mode = 0644,
6d9f239a 82 .proc_handler = proc_dointvec_jiffies,
8d8354d2
PE
83 },
84 {
8d8354d2 85 .procname = "nf_conntrack_frag6_low_thresh",
e31e0bdc 86 .data = &nf_init_frags.low_thresh,
8d8354d2
PE
87 .maxlen = sizeof(unsigned int),
88 .mode = 0644,
6d9f239a 89 .proc_handler = proc_dointvec,
8d8354d2
PE
90 },
91 {
8d8354d2 92 .procname = "nf_conntrack_frag6_high_thresh",
e31e0bdc 93 .data = &nf_init_frags.high_thresh,
8d8354d2
PE
94 .maxlen = sizeof(unsigned int),
95 .mode = 0644,
6d9f239a 96 .proc_handler = proc_dointvec,
8d8354d2 97 },
f8572d8f 98 { }
8d8354d2
PE
99};
100#endif
101
321a3a99 102static unsigned int nf_hashfn(struct inet_frag_queue *q)
9fb9cbb1 103{
58c0fb0d 104 const struct nf_ct_frag6_queue *nq;
9fb9cbb1 105
321a3a99 106 nq = container_of(q, struct nf_ct_frag6_queue, q);
93c8b90f 107 return inet6_hash_frag(nq->id, &nq->saddr, &nq->daddr, nf_frags.rnd);
9fb9cbb1
YK
108}
109
1e4b8287
PE
110static void nf_skb_free(struct sk_buff *skb)
111{
112 if (NFCT_FRAG6_CB(skb)->orig)
113 kfree_skb(NFCT_FRAG6_CB(skb)->orig);
114}
115
9fb9cbb1
YK
116/* Destruction primitives. */
117
4b6cb5d8 118static __inline__ void fq_put(struct nf_ct_frag6_queue *fq)
9fb9cbb1 119{
762cc408 120 inet_frag_put(&fq->q, &nf_frags);
9fb9cbb1
YK
121}
122
123/* Kill fq entry. It is not destroyed immediately,
124 * because caller (and someone more) holds reference count.
125 */
126static __inline__ void fq_kill(struct nf_ct_frag6_queue *fq)
127{
277e650d 128 inet_frag_kill(&fq->q, &nf_frags);
9fb9cbb1
YK
129}
130
131static void nf_ct_frag6_evictor(void)
132{
e8e16b70 133 local_bh_disable();
6ddc0822 134 inet_frag_evictor(&nf_init_frags, &nf_frags);
e8e16b70 135 local_bh_enable();
9fb9cbb1
YK
136}
137
138static void nf_ct_frag6_expire(unsigned long data)
139{
e521db9d
PE
140 struct nf_ct_frag6_queue *fq;
141
142 fq = container_of((struct inet_frag_queue *)data,
143 struct nf_ct_frag6_queue, q);
9fb9cbb1 144
5ab11c98 145 spin_lock(&fq->q.lock);
9fb9cbb1 146
bc578a54 147 if (fq->q.last_in & INET_FRAG_COMPLETE)
9fb9cbb1
YK
148 goto out;
149
150 fq_kill(fq);
151
152out:
5ab11c98 153 spin_unlock(&fq->q.lock);
4b6cb5d8 154 fq_put(fq);
9fb9cbb1
YK
155}
156
157/* Creation primitives. */
158
abd6523d 159static __inline__ struct nf_ct_frag6_queue *
0b5ccb2e 160fq_find(__be32 id, u32 user, struct in6_addr *src, struct in6_addr *dst)
9fb9cbb1 161{
2588fe1d 162 struct inet_frag_queue *q;
c6fda282 163 struct ip6_create_arg arg;
abd6523d 164 unsigned int hash;
9fb9cbb1 165
c6fda282 166 arg.id = id;
0b5ccb2e 167 arg.user = user;
c6fda282
PE
168 arg.src = src;
169 arg.dst = dst;
9a375803
PE
170
171 read_lock_bh(&nf_frags.lock);
93c8b90f 172 hash = inet6_hash_frag(id, src, dst, nf_frags.rnd);
9fb9cbb1 173
ac18e750 174 q = inet_frag_find(&nf_init_frags, &nf_frags, &arg, hash);
b9c69896 175 local_bh_enable();
c6fda282 176 if (q == NULL)
9fb9cbb1 177 goto oom;
9fb9cbb1 178
c6fda282 179 return container_of(q, struct nf_ct_frag6_queue, q);
9fb9cbb1
YK
180
181oom:
c6fda282 182 pr_debug("Can't alloc new queue\n");
9fb9cbb1
YK
183 return NULL;
184}
185
9fb9cbb1 186
1ab1457c 187static int nf_ct_frag6_queue(struct nf_ct_frag6_queue *fq, struct sk_buff *skb,
58c0fb0d 188 const struct frag_hdr *fhdr, int nhoff)
9fb9cbb1
YK
189{
190 struct sk_buff *prev, *next;
191 int offset, end;
192
bc578a54 193 if (fq->q.last_in & INET_FRAG_COMPLETE) {
698f9315 194 pr_debug("Already completed\n");
9fb9cbb1
YK
195 goto err;
196 }
197
198 offset = ntohs(fhdr->frag_off) & ~0x7;
0660e03f
ACM
199 end = offset + (ntohs(ipv6_hdr(skb)->payload_len) -
200 ((u8 *)(fhdr + 1) - (u8 *)(ipv6_hdr(skb) + 1)));
9fb9cbb1
YK
201
202 if ((unsigned int)end > IPV6_MAXPLEN) {
0d53778e 203 pr_debug("offset is too large.\n");
1ab1457c 204 return -1;
9fb9cbb1
YK
205 }
206
d56f90a7
ACM
207 if (skb->ip_summed == CHECKSUM_COMPLETE) {
208 const unsigned char *nh = skb_network_header(skb);
1ab1457c 209 skb->csum = csum_sub(skb->csum,
d56f90a7 210 csum_partial(nh, (u8 *)(fhdr + 1) - nh,
9fb9cbb1 211 0));
d56f90a7 212 }
9fb9cbb1
YK
213
214 /* Is this the final fragment? */
215 if (!(fhdr->frag_off & htons(IP6_MF))) {
216 /* If we already have some bits beyond end
217 * or have different end, the segment is corrupted.
218 */
5ab11c98 219 if (end < fq->q.len ||
bc578a54 220 ((fq->q.last_in & INET_FRAG_LAST_IN) && end != fq->q.len)) {
0d53778e 221 pr_debug("already received last fragment\n");
9fb9cbb1
YK
222 goto err;
223 }
bc578a54 224 fq->q.last_in |= INET_FRAG_LAST_IN;
5ab11c98 225 fq->q.len = end;
9fb9cbb1
YK
226 } else {
227 /* Check if the fragment is rounded to 8 bytes.
228 * Required by the RFC.
229 */
230 if (end & 0x7) {
231 /* RFC2460 says always send parameter problem in
232 * this case. -DaveM
233 */
0d53778e 234 pr_debug("end of fragment not rounded to 8 bytes.\n");
9fb9cbb1
YK
235 return -1;
236 }
5ab11c98 237 if (end > fq->q.len) {
9fb9cbb1 238 /* Some bits beyond end -> corruption. */
bc578a54 239 if (fq->q.last_in & INET_FRAG_LAST_IN) {
0d53778e 240 pr_debug("last packet already reached.\n");
9fb9cbb1
YK
241 goto err;
242 }
5ab11c98 243 fq->q.len = end;
9fb9cbb1
YK
244 }
245 }
246
247 if (end == offset)
248 goto err;
249
250 /* Point into the IP datagram 'data' part. */
251 if (!pskb_pull(skb, (u8 *) (fhdr + 1) - skb->data)) {
0d53778e 252 pr_debug("queue: message is too short.\n");
9fb9cbb1
YK
253 goto err;
254 }
b38dfee3 255 if (pskb_trim_rcsum(skb, end - offset)) {
0d53778e 256 pr_debug("Can't trim\n");
b38dfee3 257 goto err;
9fb9cbb1
YK
258 }
259
260 /* Find out which fragments are in front and at the back of us
261 * in the chain of fragments so far. We must know where to put
262 * this fragment, right?
263 */
ea8fbe8f
CG
264 prev = fq->q.fragments_tail;
265 if (!prev || NFCT_FRAG6_CB(prev)->offset < offset) {
266 next = NULL;
267 goto found;
268 }
9fb9cbb1 269 prev = NULL;
5ab11c98 270 for (next = fq->q.fragments; next != NULL; next = next->next) {
9fb9cbb1
YK
271 if (NFCT_FRAG6_CB(next)->offset >= offset)
272 break; /* bingo! */
273 prev = next;
274 }
275
ea8fbe8f 276found:
1ee89bd0
ND
277 /* RFC5722, Section 4:
278 * When reassembling an IPv6 datagram, if
279 * one or more its constituent fragments is determined to be an
280 * overlapping fragment, the entire datagram (and any constituent
281 * fragments, including those not yet received) MUST be silently
282 * discarded.
9fb9cbb1 283 */
9fb9cbb1 284
1ee89bd0
ND
285 /* Check for overlap with preceding fragment. */
286 if (prev &&
287 (NFCT_FRAG6_CB(prev)->offset + prev->len) - offset > 0)
288 goto discard_fq;
9fb9cbb1 289
1ee89bd0
ND
290 /* Look for overlap with succeeding segment. */
291 if (next && NFCT_FRAG6_CB(next)->offset < end)
292 goto discard_fq;
9fb9cbb1
YK
293
294 NFCT_FRAG6_CB(skb)->offset = offset;
295
296 /* Insert this fragment in the chain of fragments. */
297 skb->next = next;
ea8fbe8f
CG
298 if (!next)
299 fq->q.fragments_tail = skb;
9fb9cbb1
YK
300 if (prev)
301 prev->next = skb;
302 else
5ab11c98 303 fq->q.fragments = skb;
9fb9cbb1
YK
304
305 skb->dev = NULL;
5ab11c98
PE
306 fq->q.stamp = skb->tstamp;
307 fq->q.meat += skb->len;
6ddc0822 308 atomic_add(skb->truesize, &nf_init_frags.mem);
9fb9cbb1
YK
309
310 /* The first fragment.
311 * nhoffset is obtained from the first fragment, of course.
312 */
313 if (offset == 0) {
314 fq->nhoffset = nhoff;
bc578a54 315 fq->q.last_in |= INET_FRAG_FIRST_IN;
9fb9cbb1 316 }
7eb95156 317 write_lock(&nf_frags.lock);
3140c25c 318 list_move_tail(&fq->q.lru_list, &nf_init_frags.lru_list);
7eb95156 319 write_unlock(&nf_frags.lock);
9fb9cbb1
YK
320 return 0;
321
1ee89bd0
ND
322discard_fq:
323 fq_kill(fq);
9fb9cbb1
YK
324err:
325 return -1;
326}
327
328/*
329 * Check if this packet is complete.
330 * Returns NULL on failure by any reason, and pointer
331 * to current nexthdr field in reassembled frame.
332 *
333 * It is called with locked fq, and caller must check that
334 * queue is eligible for reassembly i.e. it is not COMPLETE,
335 * the last and the first frames arrived and all the bits are here.
336 */
337static struct sk_buff *
338nf_ct_frag6_reasm(struct nf_ct_frag6_queue *fq, struct net_device *dev)
339{
5ab11c98 340 struct sk_buff *fp, *op, *head = fq->q.fragments;
9fb9cbb1
YK
341 int payload_len;
342
343 fq_kill(fq);
344
547b792c
IJ
345 WARN_ON(head == NULL);
346 WARN_ON(NFCT_FRAG6_CB(head)->offset != 0);
9fb9cbb1
YK
347
348 /* Unfragmented part is taken from the first segment. */
d56f90a7 349 payload_len = ((head->data - skb_network_header(head)) -
5ab11c98 350 sizeof(struct ipv6hdr) + fq->q.len -
d56f90a7 351 sizeof(struct frag_hdr));
9fb9cbb1 352 if (payload_len > IPV6_MAXPLEN) {
0d53778e 353 pr_debug("payload len is too large.\n");
9fb9cbb1
YK
354 goto out_oversize;
355 }
356
357 /* Head of list must not be cloned. */
358 if (skb_cloned(head) && pskb_expand_head(head, 0, 0, GFP_ATOMIC)) {
0d53778e 359 pr_debug("skb is cloned but can't expand head");
9fb9cbb1
YK
360 goto out_oom;
361 }
362
363 /* If the first fragment is fragmented itself, we split
364 * it to two chunks: the first with data and paged part
365 * and the second, holding only fragments. */
343a9972 366 if (skb_has_frags(head)) {
9fb9cbb1
YK
367 struct sk_buff *clone;
368 int i, plen = 0;
369
370 if ((clone = alloc_skb(0, GFP_ATOMIC)) == NULL) {
0d53778e 371 pr_debug("Can't alloc skb\n");
9fb9cbb1
YK
372 goto out_oom;
373 }
374 clone->next = head->next;
375 head->next = clone;
376 skb_shinfo(clone)->frag_list = skb_shinfo(head)->frag_list;
343a9972 377 skb_frag_list_init(head);
9fb9cbb1
YK
378 for (i=0; i<skb_shinfo(head)->nr_frags; i++)
379 plen += skb_shinfo(head)->frags[i].size;
380 clone->len = clone->data_len = head->data_len - plen;
381 head->data_len -= clone->len;
382 head->len -= clone->len;
383 clone->csum = 0;
384 clone->ip_summed = head->ip_summed;
385
386 NFCT_FRAG6_CB(clone)->orig = NULL;
6ddc0822 387 atomic_add(clone->truesize, &nf_init_frags.mem);
9fb9cbb1
YK
388 }
389
390 /* We have to remove fragment header from datagram and to relocate
391 * header in order to calculate ICV correctly. */
bff9b61c 392 skb_network_header(head)[fq->nhoffset] = skb_transport_header(head)[0];
1ab1457c 393 memmove(head->head + sizeof(struct frag_hdr), head->head,
9fb9cbb1 394 (head->data - head->head) - sizeof(struct frag_hdr));
b0e380b1
ACM
395 head->mac_header += sizeof(struct frag_hdr);
396 head->network_header += sizeof(struct frag_hdr);
9fb9cbb1
YK
397
398 skb_shinfo(head)->frag_list = head->next;
badff6d0 399 skb_reset_transport_header(head);
d56f90a7 400 skb_push(head, head->data - skb_network_header(head));
9fb9cbb1
YK
401
402 for (fp=head->next; fp; fp = fp->next) {
403 head->data_len += fp->len;
404 head->len += fp->len;
405 if (head->ip_summed != fp->ip_summed)
406 head->ip_summed = CHECKSUM_NONE;
84fa7933 407 else if (head->ip_summed == CHECKSUM_COMPLETE)
9fb9cbb1
YK
408 head->csum = csum_add(head->csum, fp->csum);
409 head->truesize += fp->truesize;
9fb9cbb1 410 }
841a5940 411 atomic_sub(head->truesize, &nf_init_frags.mem);
9fb9cbb1
YK
412
413 head->next = NULL;
414 head->dev = dev;
5ab11c98 415 head->tstamp = fq->q.stamp;
0660e03f 416 ipv6_hdr(head)->payload_len = htons(payload_len);
9fb9cbb1
YK
417
418 /* Yes, and fold redundant checksum back. 8) */
84fa7933 419 if (head->ip_summed == CHECKSUM_COMPLETE)
d56f90a7 420 head->csum = csum_partial(skb_network_header(head),
cfe1fc77 421 skb_network_header_len(head),
d56f90a7 422 head->csum);
9fb9cbb1 423
5ab11c98 424 fq->q.fragments = NULL;
ea8fbe8f 425 fq->q.fragments_tail = NULL;
9fb9cbb1
YK
426
427 /* all original skbs are linked into the NFCT_FRAG6_CB(head).orig */
428 fp = skb_shinfo(head)->frag_list;
9e2dcf72 429 if (fp && NFCT_FRAG6_CB(fp)->orig == NULL)
9fb9cbb1
YK
430 /* at above code, head skb is divided into two skbs. */
431 fp = fp->next;
432
433 op = NFCT_FRAG6_CB(head)->orig;
434 for (; fp; fp = fp->next) {
435 struct sk_buff *orig = NFCT_FRAG6_CB(fp)->orig;
436
437 op->next = orig;
438 op = orig;
439 NFCT_FRAG6_CB(fp)->orig = NULL;
440 }
441
442 return head;
443
444out_oversize:
445 if (net_ratelimit())
446 printk(KERN_DEBUG "nf_ct_frag6_reasm: payload len = %d\n", payload_len);
447 goto out_fail;
448out_oom:
449 if (net_ratelimit())
450 printk(KERN_DEBUG "nf_ct_frag6_reasm: no memory for reassembly\n");
451out_fail:
452 return NULL;
453}
454
455/*
456 * find the header just before Fragment Header.
457 *
458 * if success return 0 and set ...
459 * (*prevhdrp): the value of "Next Header Field" in the header
460 * just before Fragment Header.
461 * (*prevhoff): the offset of "Next Header Field" in the header
462 * just before Fragment Header.
463 * (*fhoff) : the offset of Fragment Header.
464 *
465 * Based on ipv6_skip_hdr() in net/ipv6/exthdr.c
466 *
467 */
468static int
469find_prev_fhdr(struct sk_buff *skb, u8 *prevhdrp, int *prevhoff, int *fhoff)
470{
0660e03f 471 u8 nexthdr = ipv6_hdr(skb)->nexthdr;
6b88dd96
ACM
472 const int netoff = skb_network_offset(skb);
473 u8 prev_nhoff = netoff + offsetof(struct ipv6hdr, nexthdr);
474 int start = netoff + sizeof(struct ipv6hdr);
9fb9cbb1
YK
475 int len = skb->len - start;
476 u8 prevhdr = NEXTHDR_IPV6;
477
1ab1457c
YH
478 while (nexthdr != NEXTHDR_FRAGMENT) {
479 struct ipv6_opt_hdr hdr;
480 int hdrlen;
9fb9cbb1
YK
481
482 if (!ipv6_ext_hdr(nexthdr)) {
483 return -1;
484 }
1ab1457c 485 if (nexthdr == NEXTHDR_NONE) {
0d53778e 486 pr_debug("next header is none\n");
9fb9cbb1
YK
487 return -1;
488 }
d1238d53
CP
489 if (len < (int)sizeof(struct ipv6_opt_hdr)) {
490 pr_debug("too short\n");
491 return -1;
492 }
1ab1457c
YH
493 if (skb_copy_bits(skb, start, &hdr, sizeof(hdr)))
494 BUG();
495 if (nexthdr == NEXTHDR_AUTH)
496 hdrlen = (hdr.hdrlen+2)<<2;
497 else
498 hdrlen = ipv6_optlen(&hdr);
9fb9cbb1
YK
499
500 prevhdr = nexthdr;
501 prev_nhoff = start;
502
1ab1457c
YH
503 nexthdr = hdr.nexthdr;
504 len -= hdrlen;
505 start += hdrlen;
506 }
9fb9cbb1
YK
507
508 if (len < 0)
509 return -1;
510
511 *prevhdrp = prevhdr;
512 *prevhoff = prev_nhoff;
513 *fhoff = start;
514
515 return 0;
516}
517
0b5ccb2e 518struct sk_buff *nf_ct_frag6_gather(struct sk_buff *skb, u32 user)
9fb9cbb1 519{
1ab1457c 520 struct sk_buff *clone;
9fb9cbb1
YK
521 struct net_device *dev = skb->dev;
522 struct frag_hdr *fhdr;
523 struct nf_ct_frag6_queue *fq;
524 struct ipv6hdr *hdr;
525 int fhoff, nhoff;
526 u8 prevhdr;
527 struct sk_buff *ret_skb = NULL;
528
529 /* Jumbo payload inhibits frag. header */
0660e03f 530 if (ipv6_hdr(skb)->payload_len == 0) {
0d53778e 531 pr_debug("payload len = 0\n");
9fb9cbb1
YK
532 return skb;
533 }
534
535 if (find_prev_fhdr(skb, &prevhdr, &nhoff, &fhoff) < 0)
536 return skb;
537
538 clone = skb_clone(skb, GFP_ATOMIC);
539 if (clone == NULL) {
0d53778e 540 pr_debug("Can't clone skb\n");
9fb9cbb1
YK
541 return skb;
542 }
543
544 NFCT_FRAG6_CB(clone)->orig = skb;
545
546 if (!pskb_may_pull(clone, fhoff + sizeof(*fhdr))) {
0d53778e 547 pr_debug("message is too short.\n");
9fb9cbb1
YK
548 goto ret_orig;
549 }
550
967b05f6 551 skb_set_transport_header(clone, fhoff);
0660e03f 552 hdr = ipv6_hdr(clone);
bff9b61c 553 fhdr = (struct frag_hdr *)skb_transport_header(clone);
9fb9cbb1 554
e31e0bdc 555 if (atomic_read(&nf_init_frags.mem) > nf_init_frags.high_thresh)
9fb9cbb1
YK
556 nf_ct_frag6_evictor();
557
0b5ccb2e 558 fq = fq_find(fhdr->identification, user, &hdr->saddr, &hdr->daddr);
9fb9cbb1 559 if (fq == NULL) {
0d53778e 560 pr_debug("Can't find and can't create new queue\n");
9fb9cbb1
YK
561 goto ret_orig;
562 }
563
b9c69896 564 spin_lock_bh(&fq->q.lock);
9fb9cbb1
YK
565
566 if (nf_ct_frag6_queue(fq, clone, fhdr, nhoff) < 0) {
b9c69896 567 spin_unlock_bh(&fq->q.lock);
0d53778e 568 pr_debug("Can't insert skb to queue\n");
4b6cb5d8 569 fq_put(fq);
9fb9cbb1
YK
570 goto ret_orig;
571 }
572
bc578a54
JP
573 if (fq->q.last_in == (INET_FRAG_FIRST_IN | INET_FRAG_LAST_IN) &&
574 fq->q.meat == fq->q.len) {
9fb9cbb1
YK
575 ret_skb = nf_ct_frag6_reasm(fq, dev);
576 if (ret_skb == NULL)
0d53778e 577 pr_debug("Can't reassemble fragmented packets\n");
9fb9cbb1 578 }
b9c69896 579 spin_unlock_bh(&fq->q.lock);
9fb9cbb1 580
4b6cb5d8 581 fq_put(fq);
9fb9cbb1
YK
582 return ret_skb;
583
584ret_orig:
585 kfree_skb(clone);
586 return skb;
587}
588
589void nf_ct_frag6_output(unsigned int hooknum, struct sk_buff *skb,
590 struct net_device *in, struct net_device *out,
591 int (*okfn)(struct sk_buff *))
592{
593 struct sk_buff *s, *s2;
594
595 for (s = NFCT_FRAG6_CB(skb)->orig; s;) {
596 nf_conntrack_put_reasm(s->nfct_reasm);
597 nf_conntrack_get_reasm(skb);
598 s->nfct_reasm = skb;
599
600 s2 = s->next;
f9f02cca
PM
601 s->next = NULL;
602
b2e0b385 603 NF_HOOK_THRESH(NFPROTO_IPV6, hooknum, s, in, out, okfn,
9fb9cbb1
YK
604 NF_IP6_PRI_CONNTRACK_DEFRAG + 1);
605 s = s2;
606 }
607 nf_conntrack_put_reasm(skb);
608}
609
9fb9cbb1
YK
610int nf_ct_frag6_init(void)
611{
321a3a99 612 nf_frags.hashfn = nf_hashfn;
c6fda282 613 nf_frags.constructor = ip6_frag_init;
c9547709 614 nf_frags.destructor = NULL;
1e4b8287
PE
615 nf_frags.skb_free = nf_skb_free;
616 nf_frags.qsize = sizeof(struct nf_ct_frag6_queue);
abd6523d 617 nf_frags.match = ip6_frag_match;
e521db9d 618 nf_frags.frag_expire = nf_ct_frag6_expire;
3b4bc4a2 619 nf_frags.secret_interval = 10 * 60 * HZ;
b2fd5321 620 nf_init_frags.timeout = IPV6_FRAG_TIMEOUT;
7c070aa9
SW
621 nf_init_frags.high_thresh = IPV6_FRAG_HIGH_THRESH;
622 nf_init_frags.low_thresh = IPV6_FRAG_LOW_THRESH;
e5a2bb84 623 inet_frags_init_net(&nf_init_frags);
7eb95156 624 inet_frags_init(&nf_frags);
9fb9cbb1
YK
625
626 return 0;
627}
628
629void nf_ct_frag6_cleanup(void)
630{
7eb95156
PE
631 inet_frags_fini(&nf_frags);
632
e31e0bdc 633 nf_init_frags.low_thresh = 0;
9fb9cbb1
YK
634 nf_ct_frag6_evictor();
635}