hc
2024-02-20 e636c8d336489bf3eed5878299e6cc045bbad077
kernel/include/net/inet_frag.h
....@@ -3,19 +3,24 @@
33 #define __NET_FRAG_H__
44
55 #include <linux/rhashtable-types.h>
6
+#include <linux/completion.h>
67
7
-struct netns_frags {
8
+/* Per netns frag queues directory */
9
+struct fqdir {
810 /* sysctls */
911 long high_thresh;
1012 long low_thresh;
1113 int timeout;
1214 int max_dist;
1315 struct inet_frags *f;
16
+ struct net *net;
17
+ bool dead;
1418
1519 struct rhashtable rhashtable ____cacheline_aligned_in_smp;
1620
1721 /* Keep atomic mem on separate cachelines in structs that include it */
1822 atomic_long_t mem ____cacheline_aligned_in_smp;
23
+ struct work_struct destroy_work;
1924 };
2025
2126 /**
....@@ -24,11 +29,13 @@
2429 * @INET_FRAG_FIRST_IN: first fragment has arrived
2530 * @INET_FRAG_LAST_IN: final fragment has arrived
2631 * @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
2733 */
2834 enum {
2935 INET_FRAG_FIRST_IN = BIT(0),
3036 INET_FRAG_LAST_IN = BIT(1),
3137 INET_FRAG_COMPLETE = BIT(2),
38
+ INET_FRAG_HASH_DEAD = BIT(3),
3239 };
3340
3441 struct frag_v4_compare_key {
....@@ -56,7 +63,6 @@
5663 * @timer: queue expiration timer
5764 * @lock: spinlock protecting this frag
5865 * @refcnt: reference count of the queue
59
- * @fragments: received fragments head
6066 * @rb_fragments: received fragments rb-tree root
6167 * @fragments_tail: received fragments tail
6268 * @last_run_head: the head of the last "run". see ip_fragment.c
....@@ -65,7 +71,7 @@
6571 * @meat: length of received fragments so far
6672 * @flags: fragment queue flags
6773 * @max_size: maximum received fragment size
68
- * @net: namespace that this frag belongs to
74
+ * @fqdir: pointer to struct fqdir
6975 * @rcu: rcu head for freeing deferall
7076 */
7177 struct inet_frag_queue {
....@@ -77,8 +83,7 @@
7783 struct timer_list timer;
7884 spinlock_t lock;
7985 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;
8287 struct sk_buff *fragments_tail;
8388 struct sk_buff *last_run_head;
8489 ktime_t stamp;
....@@ -86,7 +91,7 @@
8691 int meat;
8792 __u8 flags;
8893 u16 max_size;
89
- struct netns_frags *net;
94
+ struct fqdir *fqdir;
9095 struct rcu_head rcu;
9196 };
9297
....@@ -100,21 +105,32 @@
100105 struct kmem_cache *frags_cachep;
101106 const char *frags_cache_name;
102107 struct rhashtable_params rhash_params;
108
+ refcount_t refcnt;
109
+ struct completion completion;
103110 };
104111
105112 int inet_frags_init(struct inet_frags *);
106113 void inet_frags_fini(struct inet_frags *);
107114
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)
109118 {
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);
112128 }
113
-void inet_frags_exit_net(struct netns_frags *nf);
129
+void fqdir_exit(struct fqdir *fqdir);
114130
115131 void inet_frag_kill(struct inet_frag_queue *q);
116132 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);
118134
119135 /* Free all skbs in the queue; return the sum of their truesizes. */
120136 unsigned int inet_frag_rbtree_purge(struct rb_root *root);
....@@ -127,19 +143,19 @@
127143
128144 /* Memory Tracking Functions. */
129145
130
-static inline long frag_mem_limit(const struct netns_frags *nf)
146
+static inline long frag_mem_limit(const struct fqdir *fqdir)
131147 {
132
- return atomic_long_read(&nf->mem);
148
+ return atomic_long_read(&fqdir->mem);
133149 }
134150
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)
136152 {
137
- atomic_long_sub(val, &nf->mem);
153
+ atomic_long_sub(val, &fqdir->mem);
138154 }
139155
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)
141157 {
142
- atomic_long_add(val, &nf->mem);
158
+ atomic_long_add(val, &fqdir->mem);
143159 }
144160
145161 /* RFC 3168 support :
....@@ -162,7 +178,7 @@
162178 void *inet_frag_reasm_prepare(struct inet_frag_queue *q, struct sk_buff *skb,
163179 struct sk_buff *parent);
164180 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);
166182 struct sk_buff *inet_frag_pull_head(struct inet_frag_queue *q);
167183
168184 #endif