Lines Matching refs:chain
54 return jhash_3words(tp->chain->index, tp->prio, in destroy_obj_hashfn()
58 static void tcf_proto_signal_destroying(struct tcf_chain *chain, in tcf_proto_signal_destroying() argument
61 struct tcf_block *block = chain->block; in tcf_proto_signal_destroying()
72 return tp1->chain->index == tp2->chain->index && in tcf_proto_cmp()
77 static bool tcf_proto_exists_destroying(struct tcf_chain *chain, in tcf_proto_exists_destroying() argument
85 hash_for_each_possible_rcu(chain->block->proto_destroy_ht, iter, in tcf_proto_exists_destroying()
98 tcf_proto_signal_destroyed(struct tcf_chain *chain, struct tcf_proto *tp) in tcf_proto_signal_destroyed() argument
100 struct tcf_block *block = chain->block; in tcf_proto_signal_destroyed()
252 u32 prio, struct tcf_chain *chain, in tcf_proto_create() argument
271 tp->chain = chain; in tcf_proto_create()
292 static void tcf_chain_put(struct tcf_chain *chain);
299 tcf_proto_signal_destroyed(tp->chain, tp); in tcf_proto_destroy()
300 tcf_chain_put(tp->chain); in tcf_proto_destroy()
351 struct tcf_chain *chain; in tcf_chain_create() local
355 chain = kzalloc(sizeof(*chain), GFP_KERNEL); in tcf_chain_create()
356 if (!chain) in tcf_chain_create()
358 list_add_tail_rcu(&chain->list, &block->chain_list); in tcf_chain_create()
359 mutex_init(&chain->filter_chain_lock); in tcf_chain_create()
360 chain->block = block; in tcf_chain_create()
361 chain->index = chain_index; in tcf_chain_create()
362 chain->refcnt = 1; in tcf_chain_create()
363 if (!chain->index) in tcf_chain_create()
364 block->chain0.chain = chain; in tcf_chain_create()
365 return chain; in tcf_chain_create()
375 static void tcf_chain0_head_change(struct tcf_chain *chain, in tcf_chain0_head_change() argument
379 struct tcf_block *block = chain->block; in tcf_chain0_head_change()
381 if (chain->index) in tcf_chain0_head_change()
392 static bool tcf_chain_detach(struct tcf_chain *chain) in tcf_chain_detach() argument
394 struct tcf_block *block = chain->block; in tcf_chain_detach()
398 list_del_rcu(&chain->list); in tcf_chain_detach()
399 if (!chain->index) in tcf_chain_detach()
400 block->chain0.chain = NULL; in tcf_chain_detach()
416 static void tcf_chain_destroy(struct tcf_chain *chain, bool free_block) in tcf_chain_destroy() argument
418 struct tcf_block *block = chain->block; in tcf_chain_destroy()
420 mutex_destroy(&chain->filter_chain_lock); in tcf_chain_destroy()
421 kfree_rcu(chain, rcu); in tcf_chain_destroy()
426 static void tcf_chain_hold(struct tcf_chain *chain) in tcf_chain_hold() argument
428 ASSERT_BLOCK_LOCKED(chain->block); in tcf_chain_hold()
430 ++chain->refcnt; in tcf_chain_hold()
433 static bool tcf_chain_held_by_acts_only(struct tcf_chain *chain) in tcf_chain_held_by_acts_only() argument
435 ASSERT_BLOCK_LOCKED(chain->block); in tcf_chain_held_by_acts_only()
440 return chain->refcnt == chain->action_refcnt; in tcf_chain_held_by_acts_only()
446 struct tcf_chain *chain; in tcf_chain_lookup() local
450 list_for_each_entry(chain, &block->chain_list, list) { in tcf_chain_lookup()
451 if (chain->index == chain_index) in tcf_chain_lookup()
452 return chain; in tcf_chain_lookup()
461 struct tcf_chain *chain; in tcf_chain_lookup_rcu() local
463 list_for_each_entry_rcu(chain, &block->chain_list, list) { in tcf_chain_lookup_rcu()
464 if (chain->index == chain_index) in tcf_chain_lookup_rcu()
465 return chain; in tcf_chain_lookup_rcu()
471 static int tc_chain_notify(struct tcf_chain *chain, struct sk_buff *oskb,
478 struct tcf_chain *chain = NULL; in __tcf_chain_get() local
482 chain = tcf_chain_lookup(block, chain_index); in __tcf_chain_get()
483 if (chain) { in __tcf_chain_get()
484 tcf_chain_hold(chain); in __tcf_chain_get()
488 chain = tcf_chain_create(block, chain_index); in __tcf_chain_get()
489 if (!chain) in __tcf_chain_get()
494 ++chain->action_refcnt; in __tcf_chain_get()
495 is_first_reference = chain->refcnt - chain->action_refcnt == 1; in __tcf_chain_get()
504 tc_chain_notify(chain, NULL, 0, NLM_F_CREATE | NLM_F_EXCL, in __tcf_chain_get()
507 return chain; in __tcf_chain_get()
511 return chain; in __tcf_chain_get()
533 static void __tcf_chain_put(struct tcf_chain *chain, bool by_act, in __tcf_chain_put() argument
536 struct tcf_block *block = chain->block; in __tcf_chain_put()
544 if (!chain->explicitly_created) { in __tcf_chain_put()
548 chain->explicitly_created = false; in __tcf_chain_put()
552 chain->action_refcnt--; in __tcf_chain_put()
558 refcnt = --chain->refcnt; in __tcf_chain_put()
559 tmplt_ops = chain->tmplt_ops; in __tcf_chain_put()
560 tmplt_priv = chain->tmplt_priv; in __tcf_chain_put()
563 if (refcnt - chain->action_refcnt == 0 && !by_act) { in __tcf_chain_put()
564 tc_chain_notify_delete(tmplt_ops, tmplt_priv, chain->index, in __tcf_chain_put()
567 chain->flushing = false; in __tcf_chain_put()
571 free_block = tcf_chain_detach(chain); in __tcf_chain_put()
576 tcf_chain_destroy(chain, free_block); in __tcf_chain_put()
580 static void tcf_chain_put(struct tcf_chain *chain) in tcf_chain_put() argument
582 __tcf_chain_put(chain, false, false); in tcf_chain_put()
585 void tcf_chain_put_by_act(struct tcf_chain *chain) in tcf_chain_put_by_act() argument
587 __tcf_chain_put(chain, true, false); in tcf_chain_put_by_act()
591 static void tcf_chain_put_explicitly_created(struct tcf_chain *chain) in tcf_chain_put_explicitly_created() argument
593 __tcf_chain_put(chain, false, true); in tcf_chain_put_explicitly_created()
596 static void tcf_chain_flush(struct tcf_chain *chain, bool rtnl_held) in tcf_chain_flush() argument
600 mutex_lock(&chain->filter_chain_lock); in tcf_chain_flush()
601 tp = tcf_chain_dereference(chain->filter_chain, chain); in tcf_chain_flush()
604 tcf_proto_signal_destroying(chain, tp); in tcf_chain_flush()
607 tp = tcf_chain_dereference(chain->filter_chain, chain); in tcf_chain_flush()
608 RCU_INIT_POINTER(chain->filter_chain, NULL); in tcf_chain_flush()
609 tcf_chain0_head_change(chain, NULL); in tcf_chain_flush()
610 chain->flushing = true; in tcf_chain_flush()
611 mutex_unlock(&chain->filter_chain_lock); in tcf_chain_flush()
777 chain0 = block->chain0.chain; in tcf_chain0_head_change_cb_add()
815 if (block->chain0.chain) in tcf_chain0_head_change_cb_del()
910 __tcf_get_next_chain(struct tcf_block *block, struct tcf_chain *chain) in __tcf_get_next_chain() argument
913 if (chain) in __tcf_get_next_chain()
914 chain = list_is_last(&chain->list, &block->chain_list) ? in __tcf_get_next_chain()
915 NULL : list_next_entry(chain, list); in __tcf_get_next_chain()
917 chain = list_first_entry_or_null(&block->chain_list, in __tcf_get_next_chain()
921 while (chain && tcf_chain_held_by_acts_only(chain)) in __tcf_get_next_chain()
922 chain = list_is_last(&chain->list, &block->chain_list) ? in __tcf_get_next_chain()
923 NULL : list_next_entry(chain, list); in __tcf_get_next_chain()
925 if (chain) in __tcf_get_next_chain()
926 tcf_chain_hold(chain); in __tcf_get_next_chain()
929 return chain; in __tcf_get_next_chain()
942 tcf_get_next_chain(struct tcf_block *block, struct tcf_chain *chain) in tcf_get_next_chain() argument
944 struct tcf_chain *chain_next = __tcf_get_next_chain(block, chain); in tcf_get_next_chain()
946 if (chain) in tcf_get_next_chain()
947 tcf_chain_put(chain); in tcf_get_next_chain()
954 __tcf_get_next_proto(struct tcf_chain *chain, struct tcf_proto *tp) in __tcf_get_next_proto() argument
959 mutex_lock(&chain->filter_chain_lock); in __tcf_get_next_proto()
962 tp = tcf_chain_dereference(chain->filter_chain, chain); in __tcf_get_next_proto()
969 tp = tcf_chain_dereference(chain->filter_chain, chain); in __tcf_get_next_proto()
971 for (; tp; tp = tcf_chain_dereference(tp->next, chain)) in __tcf_get_next_proto()
975 tp = tcf_chain_dereference(tp->next, chain); in __tcf_get_next_proto()
981 mutex_unlock(&chain->filter_chain_lock); in __tcf_get_next_proto()
995 tcf_get_next_proto(struct tcf_chain *chain, struct tcf_proto *tp) in tcf_get_next_proto() argument
997 struct tcf_proto *tp_next = __tcf_get_next_proto(chain, tp); in tcf_get_next_proto()
1008 struct tcf_chain *chain; in tcf_block_flush_all_chains() local
1013 for (chain = tcf_get_next_chain(block, NULL); in tcf_block_flush_all_chains()
1014 chain; in tcf_block_flush_all_chains()
1015 chain = tcf_get_next_chain(block, chain)) { in tcf_block_flush_all_chains()
1016 tcf_chain_put_explicitly_created(chain); in tcf_block_flush_all_chains()
1017 tcf_chain_flush(chain, rtnl_held); in tcf_block_flush_all_chains()
1404 struct tcf_chain *chain, *chain_prev; in tcf_block_playback_offloads() local
1410 for (chain = __tcf_get_next_chain(block, NULL); in tcf_block_playback_offloads()
1411 chain; in tcf_block_playback_offloads()
1412 chain_prev = chain, in tcf_block_playback_offloads()
1413 chain = __tcf_get_next_chain(block, chain), in tcf_block_playback_offloads()
1415 for (tp = __tcf_get_next_proto(chain, NULL); tp; in tcf_block_playback_offloads()
1417 tp = __tcf_get_next_proto(chain, tp), in tcf_block_playback_offloads()
1436 tcf_chain_put(chain); in tcf_block_playback_offloads()
1553 *last_executed_chain = first_tp->chain->index; in __tcf_classify()
1570 tp->chain->block->index, in __tcf_classify()
1592 u32 last_executed_chain = tp ? tp->chain->index : 0; in tcf_classify()
1600 if (ext && ext->chain) { in tcf_classify()
1603 fchain = tcf_chain_lookup_rcu(block, ext->chain); in tcf_classify()
1625 ext->chain = last_executed_chain; in tcf_classify()
1641 static struct tcf_proto *tcf_chain_tp_prev(struct tcf_chain *chain, in tcf_chain_tp_prev() argument
1644 return tcf_chain_dereference(*chain_info->pprev, chain); in tcf_chain_tp_prev()
1647 static int tcf_chain_tp_insert(struct tcf_chain *chain, in tcf_chain_tp_insert() argument
1651 if (chain->flushing) in tcf_chain_tp_insert()
1654 if (*chain_info->pprev == chain->filter_chain) in tcf_chain_tp_insert()
1655 tcf_chain0_head_change(chain, tp); in tcf_chain_tp_insert()
1657 RCU_INIT_POINTER(tp->next, tcf_chain_tp_prev(chain, chain_info)); in tcf_chain_tp_insert()
1663 static void tcf_chain_tp_remove(struct tcf_chain *chain, in tcf_chain_tp_remove() argument
1667 struct tcf_proto *next = tcf_chain_dereference(chain_info->next, chain); in tcf_chain_tp_remove()
1670 if (tp == chain->filter_chain) in tcf_chain_tp_remove()
1671 tcf_chain0_head_change(chain, next); in tcf_chain_tp_remove()
1675 static struct tcf_proto *tcf_chain_tp_find(struct tcf_chain *chain,
1685 static struct tcf_proto *tcf_chain_tp_insert_unique(struct tcf_chain *chain, in tcf_chain_tp_insert_unique() argument
1694 mutex_lock(&chain->filter_chain_lock); in tcf_chain_tp_insert_unique()
1696 if (tcf_proto_exists_destroying(chain, tp_new)) { in tcf_chain_tp_insert_unique()
1697 mutex_unlock(&chain->filter_chain_lock); in tcf_chain_tp_insert_unique()
1702 tp = tcf_chain_tp_find(chain, &chain_info, in tcf_chain_tp_insert_unique()
1705 err = tcf_chain_tp_insert(chain, &chain_info, tp_new); in tcf_chain_tp_insert_unique()
1706 mutex_unlock(&chain->filter_chain_lock); in tcf_chain_tp_insert_unique()
1719 static void tcf_chain_tp_delete_empty(struct tcf_chain *chain, in tcf_chain_tp_delete_empty() argument
1728 mutex_lock(&chain->filter_chain_lock); in tcf_chain_tp_delete_empty()
1731 for (pprev = &chain->filter_chain; in tcf_chain_tp_delete_empty()
1732 (tp_iter = tcf_chain_dereference(*pprev, chain)); in tcf_chain_tp_delete_empty()
1746 mutex_unlock(&chain->filter_chain_lock); in tcf_chain_tp_delete_empty()
1750 tcf_proto_signal_destroying(chain, tp); in tcf_chain_tp_delete_empty()
1751 next = tcf_chain_dereference(chain_info.next, chain); in tcf_chain_tp_delete_empty()
1752 if (tp == chain->filter_chain) in tcf_chain_tp_delete_empty()
1753 tcf_chain0_head_change(chain, next); in tcf_chain_tp_delete_empty()
1755 mutex_unlock(&chain->filter_chain_lock); in tcf_chain_tp_delete_empty()
1760 static struct tcf_proto *tcf_chain_tp_find(struct tcf_chain *chain, in tcf_chain_tp_find() argument
1769 for (pprev = &chain->filter_chain; in tcf_chain_tp_find()
1770 (tp = tcf_chain_dereference(*pprev, chain)); in tcf_chain_tp_find()
1820 if (nla_put_u32(skb, TCA_CHAIN, tp->chain->index)) in tcf_fill_node()
1918 struct tcf_chain *chain, int event) in tfilter_notify_chain() argument
1922 for (tp = tcf_get_next_proto(chain, NULL); in tfilter_notify_chain()
1923 tp; tp = tcf_get_next_proto(chain, tp)) in tfilter_notify_chain()
1948 struct tcf_chain *chain = NULL; in tc_new_tfilter() local
2033 chain = tcf_chain_get(block, chain_index, true); in tc_new_tfilter()
2034 if (!chain) { in tc_new_tfilter()
2040 mutex_lock(&chain->filter_chain_lock); in tc_new_tfilter()
2041 tp = tcf_chain_tp_find(chain, &chain_info, protocol, in tc_new_tfilter()
2052 if (chain->flushing) { in tc_new_tfilter()
2072 prio = tcf_auto_prio(tcf_chain_tp_prev(chain, in tc_new_tfilter()
2075 mutex_unlock(&chain->filter_chain_lock); in tc_new_tfilter()
2076 tp_new = tcf_proto_create(name, protocol, prio, chain, in tc_new_tfilter()
2084 tp = tcf_chain_tp_insert_unique(chain, tp_new, protocol, prio, in tc_new_tfilter()
2091 mutex_unlock(&chain->filter_chain_lock); in tc_new_tfilter()
2115 if (chain->tmplt_ops && chain->tmplt_ops != tp->ops) { in tc_new_tfilter()
2138 tcf_chain_tp_delete_empty(chain, tp, rtnl_held, NULL); in tc_new_tfilter()
2140 if (chain) { in tc_new_tfilter()
2144 tcf_chain_put(chain); in tc_new_tfilter()
2162 mutex_unlock(&chain->filter_chain_lock); in tc_new_tfilter()
2179 struct tcf_chain *chain = NULL; in tc_del_tfilter() local
2244 chain = tcf_chain_get(block, chain_index, false); in tc_del_tfilter()
2245 if (!chain) { in tc_del_tfilter()
2260 chain, RTM_DELTFILTER); in tc_del_tfilter()
2261 tcf_chain_flush(chain, rtnl_held); in tc_del_tfilter()
2266 mutex_lock(&chain->filter_chain_lock); in tc_del_tfilter()
2267 tp = tcf_chain_tp_find(chain, &chain_info, protocol, in tc_del_tfilter()
2278 tcf_proto_signal_destroying(chain, tp); in tc_del_tfilter()
2279 tcf_chain_tp_remove(chain, &chain_info, tp); in tc_del_tfilter()
2280 mutex_unlock(&chain->filter_chain_lock); in tc_del_tfilter()
2288 mutex_unlock(&chain->filter_chain_lock); in tc_del_tfilter()
2305 tcf_chain_tp_delete_empty(chain, tp, rtnl_held, extack); in tc_del_tfilter()
2309 if (chain) { in tc_del_tfilter()
2312 tcf_chain_put(chain); in tc_del_tfilter()
2322 mutex_unlock(&chain->filter_chain_lock); in tc_del_tfilter()
2339 struct tcf_chain *chain = NULL; in tc_get_tfilter() local
2400 chain = tcf_chain_get(block, chain_index, false); in tc_get_tfilter()
2401 if (!chain) { in tc_get_tfilter()
2407 mutex_lock(&chain->filter_chain_lock); in tc_get_tfilter()
2408 tp = tcf_chain_tp_find(chain, &chain_info, protocol, in tc_get_tfilter()
2410 mutex_unlock(&chain->filter_chain_lock); in tc_get_tfilter()
2435 if (chain) { in tc_get_tfilter()
2438 tcf_chain_put(chain); in tc_get_tfilter()
2469 static bool tcf_chain_dump(struct tcf_chain *chain, struct Qdisc *q, u32 parent, in tcf_chain_dump() argument
2474 struct tcf_block *block = chain->block; in tcf_chain_dump()
2479 for (tp = __tcf_get_next_proto(chain, NULL); in tcf_chain_dump()
2482 tp = __tcf_get_next_proto(chain, tp), in tcf_chain_dump()
2537 struct tcf_chain *chain, *chain_prev; in tc_dump_tfilter() local
2612 for (chain = __tcf_get_next_chain(block, NULL); in tc_dump_tfilter()
2613 chain; in tc_dump_tfilter()
2614 chain_prev = chain, in tc_dump_tfilter()
2615 chain = __tcf_get_next_chain(block, chain), in tc_dump_tfilter()
2618 nla_get_u32(tca[TCA_CHAIN]) != chain->index) in tc_dump_tfilter()
2620 if (!tcf_chain_dump(chain, q, parent, skb, cb, in tc_dump_tfilter()
2622 tcf_chain_put(chain); in tc_dump_tfilter()
2689 static int tc_chain_notify(struct tcf_chain *chain, struct sk_buff *oskb, in tc_chain_notify() argument
2693 struct tcf_block *block = chain->block; in tc_chain_notify()
2702 if (tc_chain_fill_node(chain->tmplt_ops, chain->tmplt_priv, in tc_chain_notify()
2703 chain->index, net, skb, block, portid, in tc_chain_notify()
2743 static int tc_chain_tmplt_add(struct tcf_chain *chain, struct net *net, in tc_chain_tmplt_add() argument
2768 tmplt_priv = ops->tmplt_create(net, chain, tca, extack); in tc_chain_tmplt_add()
2773 chain->tmplt_ops = ops; in tc_chain_tmplt_add()
2774 chain->tmplt_priv = tmplt_priv; in tc_chain_tmplt_add()
2800 struct tcf_chain *chain = NULL; in tc_ctl_chain() local
2832 chain = tcf_chain_lookup(block, chain_index); in tc_ctl_chain()
2834 if (chain) { in tc_ctl_chain()
2835 if (tcf_chain_held_by_acts_only(chain)) { in tc_ctl_chain()
2839 tcf_chain_hold(chain); in tc_ctl_chain()
2851 chain = tcf_chain_create(block, chain_index); in tc_ctl_chain()
2852 if (!chain) { in tc_ctl_chain()
2859 if (!chain || tcf_chain_held_by_acts_only(chain)) { in tc_ctl_chain()
2864 tcf_chain_hold(chain); in tc_ctl_chain()
2873 tcf_chain_hold(chain); in tc_ctl_chain()
2874 chain->explicitly_created = true; in tc_ctl_chain()
2880 err = tc_chain_tmplt_add(chain, net, tca, extack); in tc_ctl_chain()
2882 tcf_chain_put_explicitly_created(chain); in tc_ctl_chain()
2886 tc_chain_notify(chain, NULL, 0, NLM_F_CREATE | NLM_F_EXCL, in tc_ctl_chain()
2891 chain, RTM_DELTFILTER); in tc_ctl_chain()
2893 tcf_chain_flush(chain, true); in tc_ctl_chain()
2897 tcf_chain_put_explicitly_created(chain); in tc_ctl_chain()
2900 err = tc_chain_notify(chain, skb, n->nlmsg_seq, in tc_ctl_chain()
2912 tcf_chain_put(chain); in tc_ctl_chain()
2933 struct tcf_chain *chain; in tc_dump_chain() local
2987 list_for_each_entry(chain, &block->chain_list, list) { in tc_dump_chain()
2989 nla_get_u32(tca[TCA_CHAIN]) != chain->index)) in tc_dump_chain()
2995 if (tcf_chain_held_by_acts_only(chain)) in tc_dump_chain()
2997 err = tc_chain_fill_node(chain->tmplt_ops, chain->tmplt_priv, in tc_dump_chain()
2998 chain->index, net, skb, block, in tc_dump_chain()