Commit ff1acc4964ccde61a4134c789314593d40dd3c93
Committed by
Pablo Neira Ayuso
1 parent
446a8268b7
netfilter: nf_ct_helper: use nf_ct_iterate_destroy to unlink helper objs
When we unlink the helper objects, we will iterate the nf_conntrack_hash, iterate the unconfirmed list, handle the hash resize situation, etc. Actually this logic is same as the nf_ct_iterate_destroy, so we can use it 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 4 additions and 46 deletions Side-by-side Diff
net/netfilter/nf_conntrack_helper.c
... | ... | @@ -285,16 +285,16 @@ |
285 | 285 | EXPORT_SYMBOL_GPL(__nf_ct_try_assign_helper); |
286 | 286 | |
287 | 287 | /* appropriate ct lock protecting must be taken by caller */ |
288 | -static inline int unhelp(struct nf_conntrack_tuple_hash *i, | |
289 | - const struct nf_conntrack_helper *me) | |
288 | +static int unhelp(struct nf_conn *ct, void *me) | |
290 | 289 | { |
291 | - struct nf_conn *ct = nf_ct_tuplehash_to_ctrack(i); | |
292 | 290 | struct nf_conn_help *help = nfct_help(ct); |
293 | 291 | |
294 | 292 | if (help && rcu_dereference_raw(help->helper) == me) { |
295 | 293 | nf_conntrack_event(IPCT_HELPER, ct); |
296 | 294 | RCU_INIT_POINTER(help->helper, NULL); |
297 | 295 | } |
296 | + | |
297 | + /* We are not intended to delete this conntrack. */ | |
298 | 298 | return 0; |
299 | 299 | } |
300 | 300 | |
301 | 301 | |
302 | 302 | |
... | ... | @@ -437,33 +437,10 @@ |
437 | 437 | } |
438 | 438 | EXPORT_SYMBOL_GPL(nf_conntrack_helper_register); |
439 | 439 | |
440 | -static void __nf_conntrack_helper_unregister(struct nf_conntrack_helper *me, | |
441 | - struct net *net) | |
442 | -{ | |
443 | - struct nf_conntrack_tuple_hash *h; | |
444 | - const struct hlist_nulls_node *nn; | |
445 | - int cpu; | |
446 | - | |
447 | - /* Get rid of expecteds, set helpers to NULL. */ | |
448 | - for_each_possible_cpu(cpu) { | |
449 | - struct ct_pcpu *pcpu = per_cpu_ptr(net->ct.pcpu_lists, cpu); | |
450 | - | |
451 | - spin_lock_bh(&pcpu->lock); | |
452 | - hlist_nulls_for_each_entry(h, nn, &pcpu->unconfirmed, hnnode) | |
453 | - unhelp(h, me); | |
454 | - spin_unlock_bh(&pcpu->lock); | |
455 | - } | |
456 | -} | |
457 | - | |
458 | 440 | void nf_conntrack_helper_unregister(struct nf_conntrack_helper *me) |
459 | 441 | { |
460 | - struct nf_conntrack_tuple_hash *h; | |
461 | 442 | struct nf_conntrack_expect *exp; |
462 | 443 | const struct hlist_node *next; |
463 | - const struct hlist_nulls_node *nn; | |
464 | - unsigned int last_hsize; | |
465 | - spinlock_t *lock; | |
466 | - struct net *net; | |
467 | 444 | unsigned int i; |
468 | 445 | |
469 | 446 | mutex_lock(&nf_ct_helper_mutex); |
... | ... | @@ -491,26 +468,7 @@ |
491 | 468 | } |
492 | 469 | spin_unlock_bh(&nf_conntrack_expect_lock); |
493 | 470 | |
494 | - rtnl_lock(); | |
495 | - for_each_net(net) | |
496 | - __nf_conntrack_helper_unregister(me, net); | |
497 | - rtnl_unlock(); | |
498 | - | |
499 | - local_bh_disable(); | |
500 | -restart: | |
501 | - last_hsize = nf_conntrack_htable_size; | |
502 | - for (i = 0; i < last_hsize; i++) { | |
503 | - lock = &nf_conntrack_locks[i % CONNTRACK_LOCKS]; | |
504 | - nf_conntrack_lock(lock); | |
505 | - if (last_hsize != nf_conntrack_htable_size) { | |
506 | - spin_unlock(lock); | |
507 | - goto restart; | |
508 | - } | |
509 | - hlist_nulls_for_each_entry(h, nn, &nf_conntrack_hash[i], hnnode) | |
510 | - unhelp(h, me); | |
511 | - spin_unlock(lock); | |
512 | - } | |
513 | - local_bh_enable(); | |
471 | + nf_ct_iterate_destroy(unhelp, me); | |
514 | 472 | } |
515 | 473 | EXPORT_SYMBOL_GPL(nf_conntrack_helper_unregister); |
516 | 474 |