Commit 34158151d2aa1138983bedb59e5b711d2e25c245
Committed by
Pablo Neira Ayuso
1 parent
ff1acc4964
netfilter: cttimeout: use nf_ct_iterate_cleanup_net to unlink timeout objs
Similar to nf_conntrack_helper, we can use nf_ct_iterare_cleanup_net to remove these copy & paste code. Signed-off-by: Liping Zhang <zlpnobody@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Showing 1 changed file with 5 additions and 34 deletions Side-by-side Diff
net/netfilter/nfnetlink_cttimeout.c
... | ... | @@ -287,49 +287,20 @@ |
287 | 287 | return ret; |
288 | 288 | } |
289 | 289 | |
290 | -static void untimeout(struct nf_conntrack_tuple_hash *i, | |
291 | - struct ctnl_timeout *timeout) | |
290 | +static int untimeout(struct nf_conn *ct, void *timeout) | |
292 | 291 | { |
293 | - struct nf_conn *ct = nf_ct_tuplehash_to_ctrack(i); | |
294 | 292 | struct nf_conn_timeout *timeout_ext = nf_ct_timeout_find(ct); |
295 | 293 | |
296 | 294 | if (timeout_ext && (!timeout || timeout_ext->timeout == timeout)) |
297 | 295 | RCU_INIT_POINTER(timeout_ext->timeout, NULL); |
296 | + | |
297 | + /* We are not intended to delete this conntrack. */ | |
298 | + return 0; | |
298 | 299 | } |
299 | 300 | |
300 | 301 | static void ctnl_untimeout(struct net *net, struct ctnl_timeout *timeout) |
301 | 302 | { |
302 | - struct nf_conntrack_tuple_hash *h; | |
303 | - const struct hlist_nulls_node *nn; | |
304 | - unsigned int last_hsize; | |
305 | - spinlock_t *lock; | |
306 | - int i, cpu; | |
307 | - | |
308 | - for_each_possible_cpu(cpu) { | |
309 | - struct ct_pcpu *pcpu = per_cpu_ptr(net->ct.pcpu_lists, cpu); | |
310 | - | |
311 | - spin_lock_bh(&pcpu->lock); | |
312 | - hlist_nulls_for_each_entry(h, nn, &pcpu->unconfirmed, hnnode) | |
313 | - untimeout(h, timeout); | |
314 | - spin_unlock_bh(&pcpu->lock); | |
315 | - } | |
316 | - | |
317 | - local_bh_disable(); | |
318 | -restart: | |
319 | - last_hsize = nf_conntrack_htable_size; | |
320 | - for (i = 0; i < last_hsize; i++) { | |
321 | - lock = &nf_conntrack_locks[i % CONNTRACK_LOCKS]; | |
322 | - nf_conntrack_lock(lock); | |
323 | - if (last_hsize != nf_conntrack_htable_size) { | |
324 | - spin_unlock(lock); | |
325 | - goto restart; | |
326 | - } | |
327 | - | |
328 | - hlist_nulls_for_each_entry(h, nn, &nf_conntrack_hash[i], hnnode) | |
329 | - untimeout(h, timeout); | |
330 | - spin_unlock(lock); | |
331 | - } | |
332 | - local_bh_enable(); | |
303 | + nf_ct_iterate_cleanup_net(net, untimeout, timeout, 0, 0); | |
333 | 304 | } |
334 | 305 | |
335 | 306 | /* try to delete object, fail if it is still in use. */ |