inet_fragment.c (277e650ddfc6944ef5f5466fd898b8da7f06cd82) inet_fragment.c (321a3a99e4717b960e21c62fc6a140d21453df7f)
1/*
2 * inet fragments management
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 *
9 * Authors: Pavel Emelyanov <xemul@openvz.org>
10 * Started as consolidation of ipv4/ip_fragment.c,
11 * ipv6/reassembly. and ipv6 nf conntrack reassembly
12 */
13
14#include <linux/list.h>
15#include <linux/spinlock.h>
16#include <linux/module.h>
17#include <linux/timer.h>
18#include <linux/mm.h>
1/*
2 * inet fragments management
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 *
9 * Authors: Pavel Emelyanov <xemul@openvz.org>
10 * Started as consolidation of ipv4/ip_fragment.c,
11 * ipv6/reassembly. and ipv6 nf conntrack reassembly
12 */
13
14#include <linux/list.h>
15#include <linux/spinlock.h>
16#include <linux/module.h>
17#include <linux/timer.h>
18#include <linux/mm.h>
19#include <linux/random.h>
19
20#include <net/inet_frag.h>
21
20
21#include <net/inet_frag.h>
22
23static void inet_frag_secret_rebuild(unsigned long dummy)
24{
25 struct inet_frags *f = (struct inet_frags *)dummy;
26 unsigned long now = jiffies;
27 int i;
28
29 write_lock(&f->lock);
30 get_random_bytes(&f->rnd, sizeof(u32));
31 for (i = 0; i < INETFRAGS_HASHSZ; i++) {
32 struct inet_frag_queue *q;
33 struct hlist_node *p, *n;
34
35 hlist_for_each_entry_safe(q, p, n, &f->hash[i], list) {
36 unsigned int hval = f->hashfn(q);
37
38 if (hval != i) {
39 hlist_del(&q->list);
40
41 /* Relink to new hash chain. */
42 hlist_add_head(&q->list, &f->hash[hval]);
43 }
44 }
45 }
46 write_unlock(&f->lock);
47
48 mod_timer(&f->secret_timer, now + f->ctl->secret_interval);
49}
50
22void inet_frags_init(struct inet_frags *f)
23{
24 int i;
25
26 for (i = 0; i < INETFRAGS_HASHSZ; i++)
27 INIT_HLIST_HEAD(&f->hash[i]);
28
29 INIT_LIST_HEAD(&f->lru_list);
30 rwlock_init(&f->lock);
31
32 f->rnd = (u32) ((num_physpages ^ (num_physpages>>7)) ^
33 (jiffies ^ (jiffies >> 6)));
34
35 f->nqueues = 0;
36 atomic_set(&f->mem, 0);
37
51void inet_frags_init(struct inet_frags *f)
52{
53 int i;
54
55 for (i = 0; i < INETFRAGS_HASHSZ; i++)
56 INIT_HLIST_HEAD(&f->hash[i]);
57
58 INIT_LIST_HEAD(&f->lru_list);
59 rwlock_init(&f->lock);
60
61 f->rnd = (u32) ((num_physpages ^ (num_physpages>>7)) ^
62 (jiffies ^ (jiffies >> 6)));
63
64 f->nqueues = 0;
65 atomic_set(&f->mem, 0);
66
67 init_timer(&f->secret_timer);
68 f->secret_timer.function = inet_frag_secret_rebuild;
69 f->secret_timer.data = (unsigned long)f;
70 f->secret_timer.expires = jiffies + f->ctl->secret_interval;
71 add_timer(&f->secret_timer);
38}
39EXPORT_SYMBOL(inet_frags_init);
40
41void inet_frags_fini(struct inet_frags *f)
42{
72}
73EXPORT_SYMBOL(inet_frags_init);
74
75void inet_frags_fini(struct inet_frags *f)
76{
77 del_timer(&f->secret_timer);
43}
44EXPORT_SYMBOL(inet_frags_fini);
45
46static inline void fq_unlink(struct inet_frag_queue *fq, struct inet_frags *f)
47{
48 write_lock(&f->lock);
49 hlist_del(&fq->list);
50 list_del(&fq->lru_list);

--- 17 unchanged lines hidden ---
78}
79EXPORT_SYMBOL(inet_frags_fini);
80
81static inline void fq_unlink(struct inet_frag_queue *fq, struct inet_frags *f)
82{
83 write_lock(&f->lock);
84 hlist_del(&fq->list);
85 list_del(&fq->lru_list);

--- 17 unchanged lines hidden ---