Commit | Line | Data |
---|---|---|
7240cdec AA |
1 | /* 6LoWPAN fragment reassembly |
2 | * | |
3 | * | |
4 | * Authors: | |
5 | * Alexander Aring <aar@pengutronix.de> | |
6 | * | |
7 | * Based on: net/ipv6/reassembly.c | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or | |
10 | * modify it under the terms of the GNU General Public License | |
11 | * as published by the Free Software Foundation; either version | |
12 | * 2 of the License, or (at your option) any later version. | |
13 | */ | |
14 | ||
15 | #define pr_fmt(fmt) "6LoWPAN: " fmt | |
16 | ||
17 | #include <linux/net.h> | |
18 | #include <linux/list.h> | |
19 | #include <linux/netdevice.h> | |
20 | #include <linux/random.h> | |
21 | #include <linux/jhash.h> | |
22 | #include <linux/skbuff.h> | |
23 | #include <linux/slab.h> | |
24 | #include <linux/export.h> | |
25 | ||
26 | #include <net/ieee802154_netdev.h> | |
cefc8c8a | 27 | #include <net/6lowpan.h> |
7240cdec AA |
28 | #include <net/ipv6.h> |
29 | #include <net/inet_frag.h> | |
30 | ||
7240cdec AA |
31 | #include "reassembly.h" |
32 | ||
a13061ec PB |
33 | struct lowpan_frag_info { |
34 | __be16 d_tag; | |
35 | u16 d_size; | |
36 | u8 d_offset; | |
37 | }; | |
38 | ||
94716d2f | 39 | static struct lowpan_frag_info *lowpan_cb(struct sk_buff *skb) |
a13061ec PB |
40 | { |
41 | return (struct lowpan_frag_info *)skb->cb; | |
42 | } | |
43 | ||
7240cdec AA |
44 | static struct inet_frags lowpan_frags; |
45 | ||
46 | static int lowpan_frag_reasm(struct lowpan_frag_queue *fq, | |
47 | struct sk_buff *prev, struct net_device *dev); | |
48 | ||
4c7f778e | 49 | static unsigned int lowpan_hash_frag(__be16 tag, u16 d_size, |
ae531b94 PB |
50 | const struct ieee802154_addr *saddr, |
51 | const struct ieee802154_addr *daddr) | |
7240cdec | 52 | { |
7240cdec | 53 | net_get_random_once(&lowpan_frags.rnd, sizeof(lowpan_frags.rnd)); |
fb3cfe6e FW |
54 | return jhash_3words(ieee802154_addr_hash(saddr), |
55 | ieee802154_addr_hash(daddr), | |
56 | (__force u32)(tag + (d_size << 16)), | |
57 | lowpan_frags.rnd); | |
7240cdec AA |
58 | } |
59 | ||
36c77782 | 60 | static unsigned int lowpan_hashfn(const struct inet_frag_queue *q) |
7240cdec | 61 | { |
36c77782 | 62 | const struct lowpan_frag_queue *fq; |
7240cdec AA |
63 | |
64 | fq = container_of(q, struct lowpan_frag_queue, q); | |
65 | return lowpan_hash_frag(fq->tag, fq->d_size, &fq->saddr, &fq->daddr); | |
66 | } | |
67 | ||
36c77782 | 68 | static bool lowpan_frag_match(const struct inet_frag_queue *q, const void *a) |
7240cdec | 69 | { |
36c77782 FW |
70 | const struct lowpan_frag_queue *fq; |
71 | const struct lowpan_create_arg *arg = a; | |
7240cdec AA |
72 | |
73 | fq = container_of(q, struct lowpan_frag_queue, q); | |
74 | return fq->tag == arg->tag && fq->d_size == arg->d_size && | |
ae531b94 PB |
75 | ieee802154_addr_equal(&fq->saddr, arg->src) && |
76 | ieee802154_addr_equal(&fq->daddr, arg->dst); | |
7240cdec | 77 | } |
7240cdec | 78 | |
36c77782 | 79 | static void lowpan_frag_init(struct inet_frag_queue *q, const void *a) |
7240cdec | 80 | { |
36c77782 | 81 | const struct lowpan_create_arg *arg = a; |
7240cdec | 82 | struct lowpan_frag_queue *fq; |
7240cdec AA |
83 | |
84 | fq = container_of(q, struct lowpan_frag_queue, q); | |
85 | ||
86 | fq->tag = arg->tag; | |
87 | fq->d_size = arg->d_size; | |
88 | fq->saddr = *arg->src; | |
89 | fq->daddr = *arg->dst; | |
90 | } | |
7240cdec AA |
91 | |
92 | static void lowpan_frag_expire(unsigned long data) | |
93 | { | |
94 | struct frag_queue *fq; | |
95 | struct net *net; | |
96 | ||
97 | fq = container_of((struct inet_frag_queue *)data, struct frag_queue, q); | |
98 | net = container_of(fq->q.net, struct net, ieee802154_lowpan.frags); | |
99 | ||
17794326 FW |
100 | spin_lock(&fq->q.lock); |
101 | ||
102 | if (fq->q.last_in & INET_FRAG_COMPLETE) | |
103 | goto out; | |
104 | ||
105 | inet_frag_kill(&fq->q, &lowpan_frags); | |
106 | out: | |
107 | spin_unlock(&fq->q.lock); | |
108 | inet_frag_put(&fq->q, &lowpan_frags); | |
7240cdec AA |
109 | } |
110 | ||
111 | static inline struct lowpan_frag_queue * | |
a13061ec | 112 | fq_find(struct net *net, const struct lowpan_frag_info *frag_info, |
ae531b94 PB |
113 | const struct ieee802154_addr *src, |
114 | const struct ieee802154_addr *dst) | |
7240cdec AA |
115 | { |
116 | struct inet_frag_queue *q; | |
117 | struct lowpan_create_arg arg; | |
118 | unsigned int hash; | |
599018a7 LR |
119 | struct netns_ieee802154_lowpan *ieee802154_lowpan = |
120 | net_ieee802154_lowpan(net); | |
7240cdec AA |
121 | |
122 | arg.tag = frag_info->d_tag; | |
123 | arg.d_size = frag_info->d_size; | |
124 | arg.src = src; | |
125 | arg.dst = dst; | |
126 | ||
7240cdec AA |
127 | hash = lowpan_hash_frag(frag_info->d_tag, frag_info->d_size, src, dst); |
128 | ||
599018a7 | 129 | q = inet_frag_find(&ieee802154_lowpan->frags, |
7240cdec AA |
130 | &lowpan_frags, &arg, hash); |
131 | if (IS_ERR_OR_NULL(q)) { | |
132 | inet_frag_maybe_warn_overflow(q, pr_fmt()); | |
133 | return NULL; | |
134 | } | |
135 | return container_of(q, struct lowpan_frag_queue, q); | |
136 | } | |
137 | ||
138 | static int lowpan_frag_queue(struct lowpan_frag_queue *fq, | |
139 | struct sk_buff *skb, const u8 frag_type) | |
140 | { | |
141 | struct sk_buff *prev, *next; | |
142 | struct net_device *dev; | |
143 | int end, offset; | |
144 | ||
145 | if (fq->q.last_in & INET_FRAG_COMPLETE) | |
146 | goto err; | |
147 | ||
a13061ec PB |
148 | offset = lowpan_cb(skb)->d_offset << 3; |
149 | end = lowpan_cb(skb)->d_size; | |
7240cdec AA |
150 | |
151 | /* Is this the final fragment? */ | |
152 | if (offset + skb->len == end) { | |
153 | /* If we already have some bits beyond end | |
154 | * or have different end, the segment is corrupted. | |
155 | */ | |
156 | if (end < fq->q.len || | |
157 | ((fq->q.last_in & INET_FRAG_LAST_IN) && end != fq->q.len)) | |
158 | goto err; | |
159 | fq->q.last_in |= INET_FRAG_LAST_IN; | |
160 | fq->q.len = end; | |
161 | } else { | |
162 | if (end > fq->q.len) { | |
163 | /* Some bits beyond end -> corruption. */ | |
164 | if (fq->q.last_in & INET_FRAG_LAST_IN) | |
165 | goto err; | |
166 | fq->q.len = end; | |
167 | } | |
168 | } | |
169 | ||
170 | /* Find out which fragments are in front and at the back of us | |
171 | * in the chain of fragments so far. We must know where to put | |
172 | * this fragment, right? | |
173 | */ | |
174 | prev = fq->q.fragments_tail; | |
a13061ec | 175 | if (!prev || lowpan_cb(prev)->d_offset < lowpan_cb(skb)->d_offset) { |
7240cdec AA |
176 | next = NULL; |
177 | goto found; | |
178 | } | |
179 | prev = NULL; | |
180 | for (next = fq->q.fragments; next != NULL; next = next->next) { | |
a13061ec | 181 | if (lowpan_cb(next)->d_offset >= lowpan_cb(skb)->d_offset) |
7240cdec AA |
182 | break; /* bingo! */ |
183 | prev = next; | |
184 | } | |
185 | ||
186 | found: | |
187 | /* Insert this fragment in the chain of fragments. */ | |
188 | skb->next = next; | |
189 | if (!next) | |
190 | fq->q.fragments_tail = skb; | |
191 | if (prev) | |
192 | prev->next = skb; | |
193 | else | |
194 | fq->q.fragments = skb; | |
195 | ||
196 | dev = skb->dev; | |
197 | if (dev) | |
198 | skb->dev = NULL; | |
199 | ||
200 | fq->q.stamp = skb->tstamp; | |
201 | if (frag_type == LOWPAN_DISPATCH_FRAG1) { | |
202 | /* Calculate uncomp. 6lowpan header to estimate full size */ | |
203 | fq->q.meat += lowpan_uncompress_size(skb, NULL); | |
204 | fq->q.last_in |= INET_FRAG_FIRST_IN; | |
205 | } else { | |
206 | fq->q.meat += skb->len; | |
207 | } | |
208 | add_frag_mem_limit(&fq->q, skb->truesize); | |
209 | ||
210 | if (fq->q.last_in == (INET_FRAG_FIRST_IN | INET_FRAG_LAST_IN) && | |
211 | fq->q.meat == fq->q.len) { | |
212 | int res; | |
213 | unsigned long orefdst = skb->_skb_refdst; | |
214 | ||
215 | skb->_skb_refdst = 0UL; | |
216 | res = lowpan_frag_reasm(fq, prev, dev); | |
217 | skb->_skb_refdst = orefdst; | |
218 | return res; | |
219 | } | |
220 | ||
7240cdec AA |
221 | return -1; |
222 | err: | |
223 | kfree_skb(skb); | |
224 | return -1; | |
225 | } | |
226 | ||
227 | /* Check if this packet is complete. | |
228 | * Returns NULL on failure by any reason, and pointer | |
229 | * to current nexthdr field in reassembled frame. | |
230 | * | |
231 | * It is called with locked fq, and caller must check that | |
232 | * queue is eligible for reassembly i.e. it is not COMPLETE, | |
233 | * the last and the first frames arrived and all the bits are here. | |
234 | */ | |
235 | static int lowpan_frag_reasm(struct lowpan_frag_queue *fq, struct sk_buff *prev, | |
236 | struct net_device *dev) | |
237 | { | |
238 | struct sk_buff *fp, *head = fq->q.fragments; | |
239 | int sum_truesize; | |
240 | ||
241 | inet_frag_kill(&fq->q, &lowpan_frags); | |
242 | ||
243 | /* Make the one we just received the head. */ | |
244 | if (prev) { | |
245 | head = prev->next; | |
246 | fp = skb_clone(head, GFP_ATOMIC); | |
247 | ||
248 | if (!fp) | |
249 | goto out_oom; | |
250 | ||
251 | fp->next = head->next; | |
252 | if (!fp->next) | |
253 | fq->q.fragments_tail = fp; | |
254 | prev->next = fp; | |
255 | ||
256 | skb_morph(head, fq->q.fragments); | |
257 | head->next = fq->q.fragments->next; | |
258 | ||
259 | consume_skb(fq->q.fragments); | |
260 | fq->q.fragments = head; | |
261 | } | |
262 | ||
263 | /* Head of list must not be cloned. */ | |
264 | if (skb_unclone(head, GFP_ATOMIC)) | |
265 | goto out_oom; | |
266 | ||
267 | /* If the first fragment is fragmented itself, we split | |
268 | * it to two chunks: the first with data and paged part | |
269 | * and the second, holding only fragments. | |
270 | */ | |
271 | if (skb_has_frag_list(head)) { | |
272 | struct sk_buff *clone; | |
273 | int i, plen = 0; | |
274 | ||
275 | clone = alloc_skb(0, GFP_ATOMIC); | |
276 | if (!clone) | |
277 | goto out_oom; | |
278 | clone->next = head->next; | |
279 | head->next = clone; | |
280 | skb_shinfo(clone)->frag_list = skb_shinfo(head)->frag_list; | |
281 | skb_frag_list_init(head); | |
282 | for (i = 0; i < skb_shinfo(head)->nr_frags; i++) | |
283 | plen += skb_frag_size(&skb_shinfo(head)->frags[i]); | |
284 | clone->len = head->data_len - plen; | |
285 | clone->data_len = clone->len; | |
286 | head->data_len -= clone->len; | |
287 | head->len -= clone->len; | |
288 | add_frag_mem_limit(&fq->q, clone->truesize); | |
289 | } | |
290 | ||
291 | WARN_ON(head == NULL); | |
292 | ||
293 | sum_truesize = head->truesize; | |
294 | for (fp = head->next; fp;) { | |
295 | bool headstolen; | |
296 | int delta; | |
297 | struct sk_buff *next = fp->next; | |
298 | ||
299 | sum_truesize += fp->truesize; | |
300 | if (skb_try_coalesce(head, fp, &headstolen, &delta)) { | |
301 | kfree_skb_partial(fp, headstolen); | |
302 | } else { | |
303 | if (!skb_shinfo(head)->frag_list) | |
304 | skb_shinfo(head)->frag_list = fp; | |
305 | head->data_len += fp->len; | |
306 | head->len += fp->len; | |
307 | head->truesize += fp->truesize; | |
308 | } | |
309 | fp = next; | |
310 | } | |
311 | sub_frag_mem_limit(&fq->q, sum_truesize); | |
312 | ||
313 | head->next = NULL; | |
314 | head->dev = dev; | |
315 | head->tstamp = fq->q.stamp; | |
316 | ||
317 | fq->q.fragments = NULL; | |
318 | fq->q.fragments_tail = NULL; | |
319 | ||
320 | return 1; | |
321 | out_oom: | |
322 | net_dbg_ratelimited("lowpan_frag_reasm: no memory for reassembly\n"); | |
323 | return -1; | |
324 | } | |
325 | ||
326 | static int lowpan_get_frag_info(struct sk_buff *skb, const u8 frag_type, | |
a13061ec | 327 | struct lowpan_frag_info *frag_info) |
7240cdec AA |
328 | { |
329 | bool fail; | |
330 | u8 pattern = 0, low = 0; | |
331 | ||
332 | fail = lowpan_fetch_skb(skb, &pattern, 1); | |
333 | fail |= lowpan_fetch_skb(skb, &low, 1); | |
334 | frag_info->d_size = (pattern & 7) << 8 | low; | |
335 | fail |= lowpan_fetch_skb(skb, &frag_info->d_tag, 2); | |
336 | ||
337 | if (frag_type == LOWPAN_DISPATCH_FRAGN) { | |
338 | fail |= lowpan_fetch_skb(skb, &frag_info->d_offset, 1); | |
339 | } else { | |
340 | skb_reset_network_header(skb); | |
341 | frag_info->d_offset = 0; | |
342 | } | |
343 | ||
344 | if (unlikely(fail)) | |
345 | return -EIO; | |
346 | ||
347 | return 0; | |
348 | } | |
349 | ||
350 | int lowpan_frag_rcv(struct sk_buff *skb, const u8 frag_type) | |
351 | { | |
352 | struct lowpan_frag_queue *fq; | |
353 | struct net *net = dev_net(skb->dev); | |
a13061ec | 354 | struct lowpan_frag_info *frag_info = lowpan_cb(skb); |
ae531b94 | 355 | struct ieee802154_addr source, dest; |
599018a7 LR |
356 | struct netns_ieee802154_lowpan *ieee802154_lowpan = |
357 | net_ieee802154_lowpan(net); | |
7240cdec AA |
358 | int err; |
359 | ||
ae531b94 PB |
360 | source = mac_cb(skb)->source; |
361 | dest = mac_cb(skb)->dest; | |
362 | ||
7240cdec AA |
363 | err = lowpan_get_frag_info(skb, frag_type, frag_info); |
364 | if (err < 0) | |
365 | goto err; | |
366 | ||
599018a7 | 367 | if (frag_info->d_size > ieee802154_lowpan->max_dsize) |
7240cdec AA |
368 | goto err; |
369 | ||
ae531b94 | 370 | fq = fq_find(net, frag_info, &source, &dest); |
7240cdec AA |
371 | if (fq != NULL) { |
372 | int ret; | |
4710d806 | 373 | |
7240cdec AA |
374 | spin_lock(&fq->q.lock); |
375 | ret = lowpan_frag_queue(fq, skb, frag_type); | |
376 | spin_unlock(&fq->q.lock); | |
377 | ||
378 | inet_frag_put(&fq->q, &lowpan_frags); | |
379 | return ret; | |
380 | } | |
381 | ||
382 | err: | |
383 | kfree_skb(skb); | |
384 | return -1; | |
385 | } | |
386 | EXPORT_SYMBOL(lowpan_frag_rcv); | |
387 | ||
388 | #ifdef CONFIG_SYSCTL | |
389 | static struct ctl_table lowpan_frags_ns_ctl_table[] = { | |
390 | { | |
391 | .procname = "6lowpanfrag_high_thresh", | |
392 | .data = &init_net.ieee802154_lowpan.frags.high_thresh, | |
393 | .maxlen = sizeof(int), | |
394 | .mode = 0644, | |
395 | .proc_handler = proc_dointvec | |
396 | }, | |
397 | { | |
398 | .procname = "6lowpanfrag_low_thresh", | |
399 | .data = &init_net.ieee802154_lowpan.frags.low_thresh, | |
400 | .maxlen = sizeof(int), | |
401 | .mode = 0644, | |
402 | .proc_handler = proc_dointvec | |
403 | }, | |
404 | { | |
405 | .procname = "6lowpanfrag_time", | |
406 | .data = &init_net.ieee802154_lowpan.frags.timeout, | |
407 | .maxlen = sizeof(int), | |
408 | .mode = 0644, | |
409 | .proc_handler = proc_dointvec_jiffies, | |
410 | }, | |
411 | { | |
412 | .procname = "6lowpanfrag_max_datagram_size", | |
413 | .data = &init_net.ieee802154_lowpan.max_dsize, | |
414 | .maxlen = sizeof(int), | |
415 | .mode = 0644, | |
416 | .proc_handler = proc_dointvec | |
417 | }, | |
418 | { } | |
419 | }; | |
420 | ||
e3a57d18 FW |
421 | /* secret interval has been deprecated */ |
422 | static int lowpan_frags_secret_interval_unused; | |
7240cdec AA |
423 | static struct ctl_table lowpan_frags_ctl_table[] = { |
424 | { | |
425 | .procname = "6lowpanfrag_secret_interval", | |
e3a57d18 | 426 | .data = &lowpan_frags_secret_interval_unused, |
7240cdec AA |
427 | .maxlen = sizeof(int), |
428 | .mode = 0644, | |
429 | .proc_handler = proc_dointvec_jiffies, | |
430 | }, | |
431 | { } | |
432 | }; | |
433 | ||
434 | static int __net_init lowpan_frags_ns_sysctl_register(struct net *net) | |
435 | { | |
436 | struct ctl_table *table; | |
437 | struct ctl_table_header *hdr; | |
599018a7 LR |
438 | struct netns_ieee802154_lowpan *ieee802154_lowpan = |
439 | net_ieee802154_lowpan(net); | |
7240cdec AA |
440 | |
441 | table = lowpan_frags_ns_ctl_table; | |
442 | if (!net_eq(net, &init_net)) { | |
443 | table = kmemdup(table, sizeof(lowpan_frags_ns_ctl_table), | |
444 | GFP_KERNEL); | |
445 | if (table == NULL) | |
446 | goto err_alloc; | |
447 | ||
599018a7 LR |
448 | table[0].data = &ieee802154_lowpan->frags.high_thresh; |
449 | table[1].data = &ieee802154_lowpan->frags.low_thresh; | |
450 | table[2].data = &ieee802154_lowpan->frags.timeout; | |
451 | table[3].data = &ieee802154_lowpan->max_dsize; | |
7240cdec AA |
452 | |
453 | /* Don't export sysctls to unprivileged users */ | |
454 | if (net->user_ns != &init_user_ns) | |
455 | table[0].procname = NULL; | |
456 | } | |
457 | ||
458 | hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table); | |
459 | if (hdr == NULL) | |
460 | goto err_reg; | |
461 | ||
599018a7 | 462 | ieee802154_lowpan->sysctl.frags_hdr = hdr; |
7240cdec AA |
463 | return 0; |
464 | ||
465 | err_reg: | |
466 | if (!net_eq(net, &init_net)) | |
467 | kfree(table); | |
468 | err_alloc: | |
469 | return -ENOMEM; | |
470 | } | |
471 | ||
472 | static void __net_exit lowpan_frags_ns_sysctl_unregister(struct net *net) | |
473 | { | |
474 | struct ctl_table *table; | |
599018a7 LR |
475 | struct netns_ieee802154_lowpan *ieee802154_lowpan = |
476 | net_ieee802154_lowpan(net); | |
7240cdec | 477 | |
599018a7 LR |
478 | table = ieee802154_lowpan->sysctl.frags_hdr->ctl_table_arg; |
479 | unregister_net_sysctl_table(ieee802154_lowpan->sysctl.frags_hdr); | |
7240cdec AA |
480 | if (!net_eq(net, &init_net)) |
481 | kfree(table); | |
482 | } | |
483 | ||
484 | static struct ctl_table_header *lowpan_ctl_header; | |
485 | ||
486 | static int lowpan_frags_sysctl_register(void) | |
487 | { | |
488 | lowpan_ctl_header = register_net_sysctl(&init_net, | |
489 | "net/ieee802154/6lowpan", | |
490 | lowpan_frags_ctl_table); | |
491 | return lowpan_ctl_header == NULL ? -ENOMEM : 0; | |
492 | } | |
493 | ||
494 | static void lowpan_frags_sysctl_unregister(void) | |
495 | { | |
496 | unregister_net_sysctl_table(lowpan_ctl_header); | |
497 | } | |
498 | #else | |
499 | static inline int lowpan_frags_ns_sysctl_register(struct net *net) | |
500 | { | |
501 | return 0; | |
502 | } | |
503 | ||
504 | static inline void lowpan_frags_ns_sysctl_unregister(struct net *net) | |
505 | { | |
506 | } | |
507 | ||
508 | static inline int lowpan_frags_sysctl_register(void) | |
509 | { | |
510 | return 0; | |
511 | } | |
512 | ||
513 | static inline void lowpan_frags_sysctl_unregister(void) | |
514 | { | |
515 | } | |
516 | #endif | |
517 | ||
518 | static int __net_init lowpan_frags_init_net(struct net *net) | |
519 | { | |
599018a7 LR |
520 | struct netns_ieee802154_lowpan *ieee802154_lowpan = |
521 | net_ieee802154_lowpan(net); | |
7240cdec | 522 | |
599018a7 LR |
523 | ieee802154_lowpan->frags.high_thresh = IPV6_FRAG_HIGH_THRESH; |
524 | ieee802154_lowpan->frags.low_thresh = IPV6_FRAG_LOW_THRESH; | |
525 | ieee802154_lowpan->frags.timeout = IPV6_FRAG_TIMEOUT; | |
526 | ieee802154_lowpan->max_dsize = 0xFFFF; | |
527 | ||
528 | inet_frags_init_net(&ieee802154_lowpan->frags); | |
7240cdec AA |
529 | |
530 | return lowpan_frags_ns_sysctl_register(net); | |
531 | } | |
532 | ||
533 | static void __net_exit lowpan_frags_exit_net(struct net *net) | |
534 | { | |
599018a7 LR |
535 | struct netns_ieee802154_lowpan *ieee802154_lowpan = |
536 | net_ieee802154_lowpan(net); | |
537 | ||
7240cdec | 538 | lowpan_frags_ns_sysctl_unregister(net); |
599018a7 | 539 | inet_frags_exit_net(&ieee802154_lowpan->frags, &lowpan_frags); |
7240cdec AA |
540 | } |
541 | ||
542 | static struct pernet_operations lowpan_frags_ops = { | |
543 | .init = lowpan_frags_init_net, | |
544 | .exit = lowpan_frags_exit_net, | |
545 | }; | |
546 | ||
547 | int __init lowpan_net_frag_init(void) | |
548 | { | |
549 | int ret; | |
550 | ||
551 | ret = lowpan_frags_sysctl_register(); | |
552 | if (ret) | |
37147652 | 553 | return ret; |
7240cdec AA |
554 | |
555 | ret = register_pernet_subsys(&lowpan_frags_ops); | |
556 | if (ret) | |
557 | goto err_pernet; | |
558 | ||
559 | lowpan_frags.hashfn = lowpan_hashfn; | |
560 | lowpan_frags.constructor = lowpan_frag_init; | |
561 | lowpan_frags.destructor = NULL; | |
562 | lowpan_frags.skb_free = NULL; | |
563 | lowpan_frags.qsize = sizeof(struct frag_queue); | |
564 | lowpan_frags.match = lowpan_frag_match; | |
565 | lowpan_frags.frag_expire = lowpan_frag_expire; | |
7240cdec | 566 | inet_frags_init(&lowpan_frags); |
37147652 AA |
567 | |
568 | return ret; | |
7240cdec AA |
569 | err_pernet: |
570 | lowpan_frags_sysctl_unregister(); | |
7240cdec AA |
571 | return ret; |
572 | } | |
573 | ||
574 | void lowpan_net_frag_exit(void) | |
575 | { | |
576 | inet_frags_fini(&lowpan_frags); | |
577 | lowpan_frags_sysctl_unregister(); | |
578 | unregister_pernet_subsys(&lowpan_frags_ops); | |
579 | } |