.. | .. |
---|
3 | 3 | #define __NET_FRAG_H__ |
---|
4 | 4 | |
---|
5 | 5 | #include <linux/rhashtable-types.h> |
---|
| 6 | +#include <linux/completion.h> |
---|
6 | 7 | |
---|
7 | | -struct netns_frags { |
---|
| 8 | +/* Per netns frag queues directory */ |
---|
| 9 | +struct fqdir { |
---|
8 | 10 | /* sysctls */ |
---|
9 | 11 | long high_thresh; |
---|
10 | 12 | long low_thresh; |
---|
11 | 13 | int timeout; |
---|
12 | 14 | int max_dist; |
---|
13 | 15 | struct inet_frags *f; |
---|
| 16 | + struct net *net; |
---|
| 17 | + bool dead; |
---|
14 | 18 | |
---|
15 | 19 | struct rhashtable rhashtable ____cacheline_aligned_in_smp; |
---|
16 | 20 | |
---|
17 | 21 | /* Keep atomic mem on separate cachelines in structs that include it */ |
---|
18 | 22 | atomic_long_t mem ____cacheline_aligned_in_smp; |
---|
| 23 | + struct work_struct destroy_work; |
---|
19 | 24 | }; |
---|
20 | 25 | |
---|
21 | 26 | /** |
---|
.. | .. |
---|
24 | 29 | * @INET_FRAG_FIRST_IN: first fragment has arrived |
---|
25 | 30 | * @INET_FRAG_LAST_IN: final fragment has arrived |
---|
26 | 31 | * @INET_FRAG_COMPLETE: frag queue has been processed and is due for destruction |
---|
| 32 | + * @INET_FRAG_HASH_DEAD: inet_frag_kill() has not removed fq from rhashtable |
---|
27 | 33 | */ |
---|
28 | 34 | enum { |
---|
29 | 35 | INET_FRAG_FIRST_IN = BIT(0), |
---|
30 | 36 | INET_FRAG_LAST_IN = BIT(1), |
---|
31 | 37 | INET_FRAG_COMPLETE = BIT(2), |
---|
| 38 | + INET_FRAG_HASH_DEAD = BIT(3), |
---|
32 | 39 | }; |
---|
33 | 40 | |
---|
34 | 41 | struct frag_v4_compare_key { |
---|
.. | .. |
---|
56 | 63 | * @timer: queue expiration timer |
---|
57 | 64 | * @lock: spinlock protecting this frag |
---|
58 | 65 | * @refcnt: reference count of the queue |
---|
59 | | - * @fragments: received fragments head |
---|
60 | 66 | * @rb_fragments: received fragments rb-tree root |
---|
61 | 67 | * @fragments_tail: received fragments tail |
---|
62 | 68 | * @last_run_head: the head of the last "run". see ip_fragment.c |
---|
.. | .. |
---|
65 | 71 | * @meat: length of received fragments so far |
---|
66 | 72 | * @flags: fragment queue flags |
---|
67 | 73 | * @max_size: maximum received fragment size |
---|
68 | | - * @net: namespace that this frag belongs to |
---|
| 74 | + * @fqdir: pointer to struct fqdir |
---|
69 | 75 | * @rcu: rcu head for freeing deferall |
---|
70 | 76 | */ |
---|
71 | 77 | struct inet_frag_queue { |
---|
.. | .. |
---|
77 | 83 | struct timer_list timer; |
---|
78 | 84 | spinlock_t lock; |
---|
79 | 85 | refcount_t refcnt; |
---|
80 | | - struct sk_buff *fragments; /* used in 6lopwpan IPv6. */ |
---|
81 | | - struct rb_root rb_fragments; /* Used in IPv4/IPv6. */ |
---|
| 86 | + struct rb_root rb_fragments; |
---|
82 | 87 | struct sk_buff *fragments_tail; |
---|
83 | 88 | struct sk_buff *last_run_head; |
---|
84 | 89 | ktime_t stamp; |
---|
.. | .. |
---|
86 | 91 | int meat; |
---|
87 | 92 | __u8 flags; |
---|
88 | 93 | u16 max_size; |
---|
89 | | - struct netns_frags *net; |
---|
| 94 | + struct fqdir *fqdir; |
---|
90 | 95 | struct rcu_head rcu; |
---|
91 | 96 | }; |
---|
92 | 97 | |
---|
.. | .. |
---|
100 | 105 | struct kmem_cache *frags_cachep; |
---|
101 | 106 | const char *frags_cache_name; |
---|
102 | 107 | struct rhashtable_params rhash_params; |
---|
| 108 | + refcount_t refcnt; |
---|
| 109 | + struct completion completion; |
---|
103 | 110 | }; |
---|
104 | 111 | |
---|
105 | 112 | int inet_frags_init(struct inet_frags *); |
---|
106 | 113 | void inet_frags_fini(struct inet_frags *); |
---|
107 | 114 | |
---|
108 | | -static inline int inet_frags_init_net(struct netns_frags *nf) |
---|
| 115 | +int fqdir_init(struct fqdir **fqdirp, struct inet_frags *f, struct net *net); |
---|
| 116 | + |
---|
| 117 | +static inline void fqdir_pre_exit(struct fqdir *fqdir) |
---|
109 | 118 | { |
---|
110 | | - atomic_long_set(&nf->mem, 0); |
---|
111 | | - return rhashtable_init(&nf->rhashtable, &nf->f->rhash_params); |
---|
| 119 | + /* Prevent creation of new frags. |
---|
| 120 | + * Pairs with READ_ONCE() in inet_frag_find(). |
---|
| 121 | + */ |
---|
| 122 | + WRITE_ONCE(fqdir->high_thresh, 0); |
---|
| 123 | + |
---|
| 124 | + /* Pairs with READ_ONCE() in inet_frag_kill(), ip_expire() |
---|
| 125 | + * and ip6frag_expire_frag_queue(). |
---|
| 126 | + */ |
---|
| 127 | + WRITE_ONCE(fqdir->dead, true); |
---|
112 | 128 | } |
---|
113 | | -void inet_frags_exit_net(struct netns_frags *nf); |
---|
| 129 | +void fqdir_exit(struct fqdir *fqdir); |
---|
114 | 130 | |
---|
115 | 131 | void inet_frag_kill(struct inet_frag_queue *q); |
---|
116 | 132 | void inet_frag_destroy(struct inet_frag_queue *q); |
---|
117 | | -struct inet_frag_queue *inet_frag_find(struct netns_frags *nf, void *key); |
---|
| 133 | +struct inet_frag_queue *inet_frag_find(struct fqdir *fqdir, void *key); |
---|
118 | 134 | |
---|
119 | 135 | /* Free all skbs in the queue; return the sum of their truesizes. */ |
---|
120 | 136 | unsigned int inet_frag_rbtree_purge(struct rb_root *root); |
---|
.. | .. |
---|
127 | 143 | |
---|
128 | 144 | /* Memory Tracking Functions. */ |
---|
129 | 145 | |
---|
130 | | -static inline long frag_mem_limit(const struct netns_frags *nf) |
---|
| 146 | +static inline long frag_mem_limit(const struct fqdir *fqdir) |
---|
131 | 147 | { |
---|
132 | | - return atomic_long_read(&nf->mem); |
---|
| 148 | + return atomic_long_read(&fqdir->mem); |
---|
133 | 149 | } |
---|
134 | 150 | |
---|
135 | | -static inline void sub_frag_mem_limit(struct netns_frags *nf, long val) |
---|
| 151 | +static inline void sub_frag_mem_limit(struct fqdir *fqdir, long val) |
---|
136 | 152 | { |
---|
137 | | - atomic_long_sub(val, &nf->mem); |
---|
| 153 | + atomic_long_sub(val, &fqdir->mem); |
---|
138 | 154 | } |
---|
139 | 155 | |
---|
140 | | -static inline void add_frag_mem_limit(struct netns_frags *nf, long val) |
---|
| 156 | +static inline void add_frag_mem_limit(struct fqdir *fqdir, long val) |
---|
141 | 157 | { |
---|
142 | | - atomic_long_add(val, &nf->mem); |
---|
| 158 | + atomic_long_add(val, &fqdir->mem); |
---|
143 | 159 | } |
---|
144 | 160 | |
---|
145 | 161 | /* RFC 3168 support : |
---|
.. | .. |
---|
162 | 178 | void *inet_frag_reasm_prepare(struct inet_frag_queue *q, struct sk_buff *skb, |
---|
163 | 179 | struct sk_buff *parent); |
---|
164 | 180 | void inet_frag_reasm_finish(struct inet_frag_queue *q, struct sk_buff *head, |
---|
165 | | - void *reasm_data); |
---|
| 181 | + void *reasm_data, bool try_coalesce); |
---|
166 | 182 | struct sk_buff *inet_frag_pull_head(struct inet_frag_queue *q); |
---|
167 | 183 | |
---|
168 | 184 | #endif |
---|