Lines Matching refs:chain

54 	const struct tcf_chain *chain;
91 n->chain_index = tp->chain->index;
92 n->chain = tp->chain;
174 return jhash_3words(tp->chain->index, tp->prio,
178 static void tcf_proto_signal_destroying(struct tcf_chain *chain,
181 struct tcf_block *block = chain->block;
192 return tp1->chain->index == tp2->chain->index &&
197 static bool tcf_proto_exists_destroying(struct tcf_chain *chain,
205 hash_for_each_possible_rcu(chain->block->proto_destroy_ht, iter,
218 tcf_proto_signal_destroyed(struct tcf_chain *chain, struct tcf_proto *tp)
220 struct tcf_block *block = chain->block;
373 u32 prio, struct tcf_chain *chain,
392 tp->chain = chain;
413 static void tcf_chain_put(struct tcf_chain *chain);
420 tcf_proto_signal_destroyed(tp->chain, tp);
421 tcf_chain_put(tp->chain);
472 struct tcf_chain *chain;
476 chain = kzalloc(sizeof(*chain), GFP_KERNEL);
477 if (!chain)
479 list_add_tail_rcu(&chain->list, &block->chain_list);
480 mutex_init(&chain->filter_chain_lock);
481 chain->block = block;
482 chain->index = chain_index;
483 chain->refcnt = 1;
484 if (!chain->index)
485 block->chain0.chain = chain;
486 return chain;
496 static void tcf_chain0_head_change(struct tcf_chain *chain,
500 struct tcf_block *block = chain->block;
502 if (chain->index)
513 static bool tcf_chain_detach(struct tcf_chain *chain)
515 struct tcf_block *block = chain->block;
519 list_del_rcu(&chain->list);
520 if (!chain->index)
521 block->chain0.chain = NULL;
537 static void tcf_chain_destroy(struct tcf_chain *chain, bool free_block)
539 struct tcf_block *block = chain->block;
541 mutex_destroy(&chain->filter_chain_lock);
542 kfree_rcu(chain, rcu);
547 static void tcf_chain_hold(struct tcf_chain *chain)
549 ASSERT_BLOCK_LOCKED(chain->block);
551 ++chain->refcnt;
554 static bool tcf_chain_held_by_acts_only(struct tcf_chain *chain)
556 ASSERT_BLOCK_LOCKED(chain->block);
559 * chain should not be shown to the user.
561 return chain->refcnt == chain->action_refcnt;
567 struct tcf_chain *chain;
571 list_for_each_entry(chain, &block->chain_list, list) {
572 if (chain->index == chain_index)
573 return chain;
582 struct tcf_chain *chain;
584 list_for_each_entry_rcu(chain, &block->chain_list, list) {
585 if (chain->index == chain_index)
586 return chain;
592 static int tc_chain_notify(struct tcf_chain *chain, struct sk_buff *oskb,
600 struct tcf_chain *chain = NULL;
604 chain = tcf_chain_lookup(block, chain_index);
605 if (chain) {
606 tcf_chain_hold(chain);
610 chain = tcf_chain_create(block, chain_index);
611 if (!chain)
616 ++chain->action_refcnt;
617 is_first_reference = chain->refcnt - chain->action_refcnt == 1;
621 * non-action reference. Until then, the chain acts only as
626 tc_chain_notify(chain, NULL, 0, NLM_F_CREATE | NLM_F_EXCL,
629 return chain;
633 return chain;
655 static void __tcf_chain_put(struct tcf_chain *chain, bool by_act,
658 struct tcf_block *block = chain->block;
666 if (!chain->explicitly_created) {
670 chain->explicitly_created = false;
674 chain->action_refcnt--;
677 * However, when block is unlocked chain can be changed concurrently, so
680 refcnt = --chain->refcnt;
681 non_act_refcnt = refcnt - chain->action_refcnt;
682 tmplt_ops = chain->tmplt_ops;
683 tmplt_priv = chain->tmplt_priv;
685 if (non_act_refcnt == chain->explicitly_created && !by_act) {
688 chain->index, block, NULL, 0, 0,
690 /* Last reference to chain, no need to lock. */
691 chain->flushing = false;
695 free_block = tcf_chain_detach(chain);
700 tcf_chain_destroy(chain, free_block);
704 static void tcf_chain_put(struct tcf_chain *chain)
706 __tcf_chain_put(chain, false, false);
709 void tcf_chain_put_by_act(struct tcf_chain *chain)
711 __tcf_chain_put(chain, true, false);
715 static void tcf_chain_put_explicitly_created(struct tcf_chain *chain)
717 __tcf_chain_put(chain, false, true);
720 static void tcf_chain_flush(struct tcf_chain *chain, bool rtnl_held)
724 mutex_lock(&chain->filter_chain_lock);
725 tp = tcf_chain_dereference(chain->filter_chain, chain);
728 tcf_proto_signal_destroying(chain, tp);
731 tp = tcf_chain_dereference(chain->filter_chain, chain);
732 RCU_INIT_POINTER(chain->filter_chain, NULL);
733 tcf_chain0_head_change(chain, NULL);
734 chain->flushing = true;
735 mutex_unlock(&chain->filter_chain_lock);
901 chain0 = block->chain0.chain;
939 if (block->chain0.chain)
1034 __tcf_get_next_chain(struct tcf_block *block, struct tcf_chain *chain)
1037 if (chain)
1038 chain = list_is_last(&chain->list, &block->chain_list) ?
1039 NULL : list_next_entry(chain, list);
1041 chain = list_first_entry_or_null(&block->chain_list,
1045 while (chain && tcf_chain_held_by_acts_only(chain))
1046 chain = list_is_last(&chain->list, &block->chain_list) ?
1047 NULL : list_next_entry(chain, list);
1049 if (chain)
1050 tcf_chain_hold(chain);
1053 return chain;
1057 * block. It properly obtains block->lock and takes reference to chain before
1058 * returning it. Users of this function must be tolerant to concurrent chain
1059 * insertion/deletion or ensure that no concurrent chain modification is
1066 tcf_get_next_chain(struct tcf_block *block, struct tcf_chain *chain)
1068 struct tcf_chain *chain_next = __tcf_get_next_chain(block, chain);
1070 if (chain)
1071 tcf_chain_put(chain);
1078 __tcf_get_next_proto(struct tcf_chain *chain, struct tcf_proto *tp)
1083 mutex_lock(&chain->filter_chain_lock);
1086 tp = tcf_chain_dereference(chain->filter_chain, chain);
1088 /* 'deleting' flag is set and chain->filter_chain_lock was
1093 tp = tcf_chain_dereference(chain->filter_chain, chain);
1095 for (; tp; tp = tcf_chain_dereference(tp->next, chain))
1099 tp = tcf_chain_dereference(tp->next, chain);
1105 mutex_unlock(&chain->filter_chain_lock);
1111 * chain. Users of this function must be tolerant to concurrent tp
1112 * insertion/deletion or ensure that no concurrent chain modification is
1119 tcf_get_next_proto(struct tcf_chain *chain, struct tcf_proto *tp)
1121 struct tcf_proto *tp_next = __tcf_get_next_proto(chain, tp);
1132 struct tcf_chain *chain;
1137 for (chain = tcf_get_next_chain(block, NULL);
1138 chain;
1139 chain = tcf_get_next_chain(block, chain)) {
1140 tcf_chain_put_explicitly_created(chain);
1141 tcf_chain_flush(chain, rtnl_held);
1286 * deallocated when last chain is freed. However, if chain_list
1497 /* XXX: Standalone actions are not allowed to jump to any chain, and bound
1528 struct tcf_chain *chain, *chain_prev;
1534 for (chain = __tcf_get_next_chain(block, NULL);
1535 chain;
1536 chain_prev = chain,
1537 chain = __tcf_get_next_chain(block, chain),
1539 if (chain->tmplt_ops && add)
1540 chain->tmplt_ops->tmplt_reoffload(chain, true, cb,
1542 for (tp = __tcf_get_next_proto(chain, NULL); tp;
1544 tp = __tcf_get_next_proto(chain, tp),
1557 if (chain->tmplt_ops && !add)
1558 chain->tmplt_ops->tmplt_reoffload(chain, false, cb,
1566 tcf_chain_put(chain);
1654 /* Main classifier routine: scans classifier chain attached
1684 /* We re-lookup the tp and chain based on index instead
1686 * check if any of tp,chain,exts was replaced by the
1689 if (unlikely(n->tp != tp || n->tp->chain != n->chain ||
1709 *last_executed_chain = first_tp->chain->index;
1729 tp->chain->block->index,
1751 u32 last_executed_chain = tp ? tp->chain->index : 0;
1761 if (ext && (ext->chain || ext->act_miss)) {
1763 u32 chain;
1771 chain = n->chain_index;
1773 chain = ext->chain;
1776 fchain = tcf_chain_lookup_rcu(block, chain);
1792 /* If we missed on some chain */
1799 ext->chain = last_executed_chain;
1818 static struct tcf_proto *tcf_chain_tp_prev(struct tcf_chain *chain,
1821 return tcf_chain_dereference(*chain_info->pprev, chain);
1824 static int tcf_chain_tp_insert(struct tcf_chain *chain,
1828 if (chain->flushing)
1831 RCU_INIT_POINTER(tp->next, tcf_chain_tp_prev(chain, chain_info));
1832 if (*chain_info->pprev == chain->filter_chain)
1833 tcf_chain0_head_change(chain, tp);
1840 static void tcf_chain_tp_remove(struct tcf_chain *chain,
1844 struct tcf_proto *next = tcf_chain_dereference(chain_info->next, chain);
1847 if (tp == chain->filter_chain)
1848 tcf_chain0_head_change(chain, next);
1852 static struct tcf_proto *tcf_chain_tp_find(struct tcf_chain *chain,
1862 static struct tcf_proto *tcf_chain_tp_insert_unique(struct tcf_chain *chain,
1871 mutex_lock(&chain->filter_chain_lock);
1873 if (tcf_proto_exists_destroying(chain, tp_new)) {
1874 mutex_unlock(&chain->filter_chain_lock);
1879 tp = tcf_chain_tp_find(chain, &chain_info,
1882 err = tcf_chain_tp_insert(chain, &chain_info, tp_new);
1883 mutex_unlock(&chain->filter_chain_lock);
1896 static void tcf_chain_tp_delete_empty(struct tcf_chain *chain,
1905 mutex_lock(&chain->filter_chain_lock);
1907 /* Atomically find and remove tp from chain. */
1908 for (pprev = &chain->filter_chain;
1909 (tp_iter = tcf_chain_dereference(*pprev, chain));
1923 mutex_unlock(&chain->filter_chain_lock);
1927 tcf_proto_signal_destroying(chain, tp);
1928 next = tcf_chain_dereference(chain_info.next, chain);
1929 if (tp == chain->filter_chain)
1930 tcf_chain0_head_change(chain, next);
1932 mutex_unlock(&chain->filter_chain_lock);
1937 static struct tcf_proto *tcf_chain_tp_find(struct tcf_chain *chain,
1945 /* Check the chain for existence of proto-tcf with this priority */
1946 for (pprev = &chain->filter_chain;
1947 (tp = tcf_chain_dereference(*pprev, chain));
1998 if (nla_put_u32(skb, TCA_CHAIN, tp->chain->index))
2102 struct tcf_chain *chain, int event,
2107 for (tp = tcf_get_next_proto(chain, NULL);
2108 tp; tp = tcf_get_next_proto(chain, tp))
2138 struct tcf_chain *chain;
2165 chain = NULL;
2181 /* Find head of filter chain. */
2218 NL_SET_ERR_MSG(extack, "Specified chain index exceeds upper limit");
2222 chain = tcf_chain_get(block, chain_index, true);
2223 if (!chain) {
2224 NL_SET_ERR_MSG(extack, "Cannot create specified filter chain");
2229 mutex_lock(&chain->filter_chain_lock);
2230 tp = tcf_chain_tp_find(chain, &chain_info, protocol,
2241 if (chain->flushing) {
2261 prio = tcf_auto_prio(tcf_chain_tp_prev(chain,
2264 mutex_unlock(&chain->filter_chain_lock);
2265 tp_new = tcf_proto_create(name, protocol, prio, chain,
2273 tp = tcf_chain_tp_insert_unique(chain, tp_new, protocol, prio,
2280 mutex_unlock(&chain->filter_chain_lock);
2304 if (chain->tmplt_ops && chain->tmplt_ops != tp->ops) {
2330 tcf_chain_tp_delete_empty(chain, tp, rtnl_held, NULL);
2332 if (chain) {
2336 tcf_chain_put(chain);
2345 * of target chain.
2354 mutex_unlock(&chain->filter_chain_lock);
2371 struct tcf_chain *chain = NULL;
2394 /* Find head of filter chain. */
2405 /* Take rtnl mutex if flushing whole chain, block is shared (no qdisc
2429 NL_SET_ERR_MSG(extack, "Specified chain index exceeds upper limit");
2433 chain = tcf_chain_get(block, chain_index, false);
2434 if (!chain) {
2435 /* User requested flush on non-existent chain. Nothing to do,
2442 NL_SET_ERR_MSG(extack, "Cannot find specified filter chain");
2449 chain, RTM_DELTFILTER, extack);
2450 tcf_chain_flush(chain, rtnl_held);
2455 mutex_lock(&chain->filter_chain_lock);
2456 tp = tcf_chain_tp_find(chain, &chain_info, protocol,
2467 tcf_proto_signal_destroying(chain, tp);
2468 tcf_chain_tp_remove(chain, &chain_info, tp);
2469 mutex_unlock(&chain->filter_chain_lock);
2477 mutex_unlock(&chain->filter_chain_lock);
2494 tcf_chain_tp_delete_empty(chain, tp, rtnl_held, extack);
2498 if (chain) {
2501 tcf_chain_put(chain);
2511 mutex_unlock(&chain->filter_chain_lock);
2528 struct tcf_chain *chain = NULL;
2551 /* Find head of filter chain. */
2585 NL_SET_ERR_MSG(extack, "Specified chain index exceeds upper limit");
2589 chain = tcf_chain_get(block, chain_index, false);
2590 if (!chain) {
2591 NL_SET_ERR_MSG(extack, "Cannot find specified filter chain");
2596 mutex_lock(&chain->filter_chain_lock);
2597 tp = tcf_chain_tp_find(chain, &chain_info, protocol,
2599 mutex_unlock(&chain->filter_chain_lock);
2624 if (chain) {
2627 tcf_chain_put(chain);
2658 static bool tcf_chain_dump(struct tcf_chain *chain, struct Qdisc *q, u32 parent,
2663 struct tcf_block *block = chain->block;
2668 for (tp = __tcf_get_next_proto(chain, NULL);
2671 tp = __tcf_get_next_proto(chain, tp),
2726 struct tcf_chain *chain, *chain_prev;
2801 for (chain = __tcf_get_next_chain(block, NULL);
2802 chain;
2803 chain_prev = chain,
2804 chain = __tcf_get_next_chain(block, chain),
2807 nla_get_u32(tca[TCA_CHAIN]) != chain->index)
2809 if (!tcf_chain_dump(chain, q, parent, skb, cb,
2811 tcf_chain_put(chain);
2884 static int tc_chain_notify(struct tcf_chain *chain, struct sk_buff *oskb,
2889 struct tcf_block *block = chain->block;
2898 if (tc_chain_fill_node(chain->tmplt_ops, chain->tmplt_priv,
2899 chain->index, net, skb, block, portid,
2939 static int tc_chain_tmplt_add(struct tcf_chain *chain, struct net *net,
2952 NL_SET_ERR_MSG(extack, "Specified TC chain template name too long");
2966 tmplt_priv = ops->tmplt_create(net, chain, tca, extack);
2971 chain->tmplt_ops = ops;
2972 chain->tmplt_priv = tmplt_priv;
2987 /* Add/delete/get a chain */
2998 struct tcf_chain *chain;
3021 NL_SET_ERR_MSG(extack, "Specified chain index exceeds upper limit");
3027 chain = tcf_chain_lookup(block, chain_index);
3029 if (chain) {
3030 if (tcf_chain_held_by_acts_only(chain)) {
3031 /* The chain exists only because there is
3034 tcf_chain_hold(chain);
3036 NL_SET_ERR_MSG(extack, "Filter chain already exists");
3042 NL_SET_ERR_MSG(extack, "Need both RTM_NEWCHAIN and NLM_F_CREATE to create a new chain");
3046 chain = tcf_chain_create(block, chain_index);
3047 if (!chain) {
3048 NL_SET_ERR_MSG(extack, "Failed to create filter chain");
3054 if (!chain || tcf_chain_held_by_acts_only(chain)) {
3055 NL_SET_ERR_MSG(extack, "Cannot find specified filter chain");
3059 tcf_chain_hold(chain);
3063 /* Modifying chain requires holding parent block lock. In case
3064 * the chain was successfully added, take a reference to the
3065 * chain. This ensures that an empty chain does not disappear at
3068 tcf_chain_hold(chain);
3069 chain->explicitly_created = true;
3075 err = tc_chain_tmplt_add(chain, net, tca, extack);
3077 tcf_chain_put_explicitly_created(chain);
3081 tc_chain_notify(chain, NULL, 0, NLM_F_CREATE | NLM_F_EXCL,
3086 chain, RTM_DELTFILTER, extack);
3087 /* Flush the chain first as the user requested chain removal. */
3088 tcf_chain_flush(chain, true);
3089 /* In case the chain was successfully deleted, put a reference
3090 * to the chain previously taken during addition.
3092 tcf_chain_put_explicitly_created(chain);
3095 err = tc_chain_notify(chain, skb, n->nlmsg_seq,
3098 NL_SET_ERR_MSG(extack, "Failed to send chain notify message");
3107 tcf_chain_put(chain);
3128 struct tcf_chain *chain;
3182 list_for_each_entry(chain, &block->chain_list, list) {
3184 nla_get_u32(tca[TCA_CHAIN]) != chain->index))
3190 if (tcf_chain_held_by_acts_only(chain))
3192 err = tc_chain_fill_node(chain->tmplt_ops, chain->tmplt_priv,
3193 chain->index, net, skb, block,