nf_conntrack_reasm.c 17 KB

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