Lines Matching refs:chain

52 	return jhash_3words(tp->chain->index, tp->prio,
56 static void tcf_proto_signal_destroying(struct tcf_chain *chain,
59 struct tcf_block *block = chain->block;
70 return tp1->chain->index == tp2->chain->index &&
75 static bool tcf_proto_exists_destroying(struct tcf_chain *chain,
83 hash_for_each_possible_rcu(chain->block->proto_destroy_ht, iter,
96 tcf_proto_signal_destroyed(struct tcf_chain *chain, struct tcf_proto *tp)
98 struct tcf_block *block = chain->block;
250 u32 prio, struct tcf_chain *chain,
269 tp->chain = chain;
290 static void tcf_chain_put(struct tcf_chain *chain);
297 tcf_proto_signal_destroyed(tp->chain, tp);
298 tcf_chain_put(tp->chain);
349 struct tcf_chain *chain;
353 chain = kzalloc(sizeof(*chain), GFP_KERNEL);
354 if (!chain)
356 list_add_tail_rcu(&chain->list, &block->chain_list);
357 mutex_init(&chain->filter_chain_lock);
358 chain->block = block;
359 chain->index = chain_index;
360 chain->refcnt = 1;
361 if (!chain->index)
362 block->chain0.chain = chain;
363 return chain;
373 static void tcf_chain0_head_change(struct tcf_chain *chain,
377 struct tcf_block *block = chain->block;
379 if (chain->index)
390 static bool tcf_chain_detach(struct tcf_chain *chain)
392 struct tcf_block *block = chain->block;
396 list_del_rcu(&chain->list);
397 if (!chain->index)
398 block->chain0.chain = NULL;
414 static void tcf_chain_destroy(struct tcf_chain *chain, bool free_block)
416 struct tcf_block *block = chain->block;
418 mutex_destroy(&chain->filter_chain_lock);
419 kfree_rcu(chain, rcu);
424 static void tcf_chain_hold(struct tcf_chain *chain)
426 ASSERT_BLOCK_LOCKED(chain->block);
428 ++chain->refcnt;
431 static bool tcf_chain_held_by_acts_only(struct tcf_chain *chain)
433 ASSERT_BLOCK_LOCKED(chain->block);
436 * chain should not be shown to the user.
438 return chain->refcnt == chain->action_refcnt;
444 struct tcf_chain *chain;
448 list_for_each_entry(chain, &block->chain_list, list) {
449 if (chain->index == chain_index)
450 return chain;
459 struct tcf_chain *chain;
461 list_for_each_entry_rcu(chain, &block->chain_list, list) {
462 if (chain->index == chain_index)
463 return chain;
469 static int tc_chain_notify(struct tcf_chain *chain, struct sk_buff *oskb,
476 struct tcf_chain *chain = NULL;
480 chain = tcf_chain_lookup(block, chain_index);
481 if (chain) {
482 tcf_chain_hold(chain);
486 chain = tcf_chain_create(block, chain_index);
487 if (!chain)
492 ++chain->action_refcnt;
493 is_first_reference = chain->refcnt - chain->action_refcnt == 1;
497 * non-action reference. Until then, the chain acts only as
502 tc_chain_notify(chain, NULL, 0, NLM_F_CREATE | NLM_F_EXCL,
505 return chain;
509 return chain;
531 static void __tcf_chain_put(struct tcf_chain *chain, bool by_act,
534 struct tcf_block *block = chain->block;
542 if (!chain->explicitly_created) {
546 chain->explicitly_created = false;
550 chain->action_refcnt--;
553 * However, when block is unlocked chain can be changed concurrently, so
556 refcnt = --chain->refcnt;
557 non_act_refcnt = refcnt - chain->action_refcnt;
558 tmplt_ops = chain->tmplt_ops;
559 tmplt_priv = chain->tmplt_priv;
561 if (non_act_refcnt == chain->explicitly_created && !by_act) {
564 chain->index, block, NULL, 0, 0,
566 /* Last reference to chain, no need to lock. */
567 chain->flushing = false;
571 free_block = tcf_chain_detach(chain);
576 tcf_chain_destroy(chain, free_block);
580 static void tcf_chain_put(struct tcf_chain *chain)
582 __tcf_chain_put(chain, false, false);
585 void tcf_chain_put_by_act(struct tcf_chain *chain)
587 __tcf_chain_put(chain, true, false);
591 static void tcf_chain_put_explicitly_created(struct tcf_chain *chain)
593 __tcf_chain_put(chain, false, true);
596 static void tcf_chain_flush(struct tcf_chain *chain, bool rtnl_held)
600 mutex_lock(&chain->filter_chain_lock);
601 tp = tcf_chain_dereference(chain->filter_chain, chain);
604 tcf_proto_signal_destroying(chain, tp);
607 tp = tcf_chain_dereference(chain->filter_chain, chain);
608 RCU_INIT_POINTER(chain->filter_chain, NULL);
609 tcf_chain0_head_change(chain, NULL);
610 chain->flushing = true;
611 mutex_unlock(&chain->filter_chain_lock);
777 chain0 = block->chain0.chain;
815 if (block->chain0.chain)
910 __tcf_get_next_chain(struct tcf_block *block, struct tcf_chain *chain)
913 if (chain)
914 chain = list_is_last(&chain->list, &block->chain_list) ?
915 NULL : list_next_entry(chain, list);
917 chain = list_first_entry_or_null(&block->chain_list,
921 while (chain && tcf_chain_held_by_acts_only(chain))
922 chain = list_is_last(&chain->list, &block->chain_list) ?
923 NULL : list_next_entry(chain, list);
925 if (chain)
926 tcf_chain_hold(chain);
929 return chain;
933 * block. It properly obtains block->lock and takes reference to chain before
934 * returning it. Users of this function must be tolerant to concurrent chain
935 * insertion/deletion or ensure that no concurrent chain modification is
942 tcf_get_next_chain(struct tcf_block *block, struct tcf_chain *chain)
944 struct tcf_chain *chain_next = __tcf_get_next_chain(block, chain);
946 if (chain)
947 tcf_chain_put(chain);
954 __tcf_get_next_proto(struct tcf_chain *chain, struct tcf_proto *tp)
959 mutex_lock(&chain->filter_chain_lock);
962 tp = tcf_chain_dereference(chain->filter_chain, chain);
964 /* 'deleting' flag is set and chain->filter_chain_lock was
969 tp = tcf_chain_dereference(chain->filter_chain, chain);
971 for (; tp; tp = tcf_chain_dereference(tp->next, chain))
975 tp = tcf_chain_dereference(tp->next, chain);
981 mutex_unlock(&chain->filter_chain_lock);
987 * chain. Users of this function must be tolerant to concurrent tp
988 * insertion/deletion or ensure that no concurrent chain modification is
995 tcf_get_next_proto(struct tcf_chain *chain, struct tcf_proto *tp,
998 struct tcf_proto *tp_next = __tcf_get_next_proto(chain, tp);
1009 struct tcf_chain *chain;
1014 for (chain = tcf_get_next_chain(block, NULL);
1015 chain;
1016 chain = tcf_get_next_chain(block, chain)) {
1017 tcf_chain_put_explicitly_created(chain);
1018 tcf_chain_flush(chain, rtnl_held);
1163 * deallocated when last chain is freed. However, if chain_list
1374 /* XXX: Standalone actions are not allowed to jump to any chain, and bound
1405 struct tcf_chain *chain, *chain_prev;
1411 for (chain = __tcf_get_next_chain(block, NULL);
1412 chain;
1413 chain_prev = chain,
1414 chain = __tcf_get_next_chain(block, chain),
1416 for (tp = __tcf_get_next_proto(chain, NULL); tp;
1418 tp = __tcf_get_next_proto(chain, tp),
1437 tcf_chain_put(chain);
1525 /* Main classifier routine: scans classifier chain attached
1555 *last_executed_chain = first_tp->chain->index;
1572 tp->chain->block->index,
1604 u32 last_executed_chain = tp ? tp->chain->index : 0;
1611 if (ext && ext->chain) {
1614 fchain = tcf_chain_lookup_rcu(ingress_block, ext->chain);
1628 /* If we missed on some chain */
1633 ext->chain = last_executed_chain;
1647 static struct tcf_proto *tcf_chain_tp_prev(struct tcf_chain *chain,
1650 return tcf_chain_dereference(*chain_info->pprev, chain);
1653 static int tcf_chain_tp_insert(struct tcf_chain *chain,
1657 if (chain->flushing)
1660 RCU_INIT_POINTER(tp->next, tcf_chain_tp_prev(chain, chain_info));
1661 if (*chain_info->pprev == chain->filter_chain)
1662 tcf_chain0_head_change(chain, tp);
1669 static void tcf_chain_tp_remove(struct tcf_chain *chain,
1673 struct tcf_proto *next = tcf_chain_dereference(chain_info->next, chain);
1676 if (tp == chain->filter_chain)
1677 tcf_chain0_head_change(chain, next);
1681 static struct tcf_proto *tcf_chain_tp_find(struct tcf_chain *chain,
1691 static struct tcf_proto *tcf_chain_tp_insert_unique(struct tcf_chain *chain,
1700 mutex_lock(&chain->filter_chain_lock);
1702 if (tcf_proto_exists_destroying(chain, tp_new)) {
1703 mutex_unlock(&chain->filter_chain_lock);
1708 tp = tcf_chain_tp_find(chain, &chain_info,
1711 err = tcf_chain_tp_insert(chain, &chain_info, tp_new);
1712 mutex_unlock(&chain->filter_chain_lock);
1725 static void tcf_chain_tp_delete_empty(struct tcf_chain *chain,
1734 mutex_lock(&chain->filter_chain_lock);
1736 /* Atomically find and remove tp from chain. */
1737 for (pprev = &chain->filter_chain;
1738 (tp_iter = tcf_chain_dereference(*pprev, chain));
1752 mutex_unlock(&chain->filter_chain_lock);
1756 tcf_proto_signal_destroying(chain, tp);
1757 next = tcf_chain_dereference(chain_info.next, chain);
1758 if (tp == chain->filter_chain)
1759 tcf_chain0_head_change(chain, next);
1761 mutex_unlock(&chain->filter_chain_lock);
1766 static struct tcf_proto *tcf_chain_tp_find(struct tcf_chain *chain,
1774 /* Check the chain for existence of proto-tcf with this priority */
1775 for (pprev = &chain->filter_chain;
1776 (tp = tcf_chain_dereference(*pprev, chain));
1826 if (nla_put_u32(skb, TCA_CHAIN, tp->chain->index))
1929 struct tcf_chain *chain, int event,
1934 for (tp = tcf_get_next_proto(chain, NULL, rtnl_held);
1935 tp; tp = tcf_get_next_proto(chain, tp, rtnl_held))
1960 struct tcf_chain *chain;
1989 chain = NULL;
2004 /* Find head of filter chain. */
2041 NL_SET_ERR_MSG(extack, "Specified chain index exceeds upper limit");
2045 chain = tcf_chain_get(block, chain_index, true);
2046 if (!chain) {
2047 NL_SET_ERR_MSG(extack, "Cannot create specified filter chain");
2052 mutex_lock(&chain->filter_chain_lock);
2053 tp = tcf_chain_tp_find(chain, &chain_info, protocol,
2064 if (chain->flushing) {
2084 prio = tcf_auto_prio(tcf_chain_tp_prev(chain,
2087 mutex_unlock(&chain->filter_chain_lock);
2088 tp_new = tcf_proto_create(name, protocol, prio, chain,
2096 tp = tcf_chain_tp_insert_unique(chain, tp_new, protocol, prio,
2103 mutex_unlock(&chain->filter_chain_lock);
2127 if (chain->tmplt_ops && chain->tmplt_ops != tp->ops) {
2148 tcf_chain_tp_delete_empty(chain, tp, rtnl_held, NULL);
2150 if (chain) {
2154 tcf_chain_put(chain);
2163 * of target chain.
2172 mutex_unlock(&chain->filter_chain_lock);
2189 struct tcf_chain *chain = NULL;
2215 /* Find head of filter chain. */
2226 /* Take rtnl mutex if flushing whole chain, block is shared (no qdisc
2250 NL_SET_ERR_MSG(extack, "Specified chain index exceeds upper limit");
2254 chain = tcf_chain_get(block, chain_index, false);
2255 if (!chain) {
2256 /* User requested flush on non-existent chain. Nothing to do,
2263 NL_SET_ERR_MSG(extack, "Cannot find specified filter chain");
2270 chain, RTM_DELTFILTER, rtnl_held);
2271 tcf_chain_flush(chain, rtnl_held);
2276 mutex_lock(&chain->filter_chain_lock);
2277 tp = tcf_chain_tp_find(chain, &chain_info, protocol,
2288 tcf_proto_signal_destroying(chain, tp);
2289 tcf_chain_tp_remove(chain, &chain_info, tp);
2290 mutex_unlock(&chain->filter_chain_lock);
2298 mutex_unlock(&chain->filter_chain_lock);
2315 tcf_chain_tp_delete_empty(chain, tp, rtnl_held, extack);
2319 if (chain) {
2322 tcf_chain_put(chain);
2332 mutex_unlock(&chain->filter_chain_lock);
2349 struct tcf_chain *chain = NULL;
2372 /* Find head of filter chain. */
2406 NL_SET_ERR_MSG(extack, "Specified chain index exceeds upper limit");
2410 chain = tcf_chain_get(block, chain_index, false);
2411 if (!chain) {
2412 NL_SET_ERR_MSG(extack, "Cannot find specified filter chain");
2417 mutex_lock(&chain->filter_chain_lock);
2418 tp = tcf_chain_tp_find(chain, &chain_info, protocol,
2420 mutex_unlock(&chain->filter_chain_lock);
2445 if (chain) {
2448 tcf_chain_put(chain);
2479 static bool tcf_chain_dump(struct tcf_chain *chain, struct Qdisc *q, u32 parent,
2484 struct tcf_block *block = chain->block;
2489 for (tp = __tcf_get_next_proto(chain, NULL);
2492 tp = __tcf_get_next_proto(chain, tp),
2547 struct tcf_chain *chain, *chain_prev;
2622 for (chain = __tcf_get_next_chain(block, NULL);
2623 chain;
2624 chain_prev = chain,
2625 chain = __tcf_get_next_chain(block, chain),
2628 nla_get_u32(tca[TCA_CHAIN]) != chain->index)
2630 if (!tcf_chain_dump(chain, q, parent, skb, cb,
2632 tcf_chain_put(chain);
2699 static int tc_chain_notify(struct tcf_chain *chain, struct sk_buff *oskb,
2703 struct tcf_block *block = chain->block;
2712 if (tc_chain_fill_node(chain->tmplt_ops, chain->tmplt_priv,
2713 chain->index, net, skb, block, portid,
2755 static int tc_chain_tmplt_add(struct tcf_chain *chain, struct net *net,
2768 NL_SET_ERR_MSG(extack, "Specified TC chain template name too long");
2781 tmplt_priv = ops->tmplt_create(net, chain, tca, extack);
2786 chain->tmplt_ops = ops;
2787 chain->tmplt_priv = tmplt_priv;
2802 /* Add/delete/get a chain */
2813 struct tcf_chain *chain;
2840 NL_SET_ERR_MSG(extack, "Specified chain index exceeds upper limit");
2846 chain = tcf_chain_lookup(block, chain_index);
2848 if (chain) {
2849 if (tcf_chain_held_by_acts_only(chain)) {
2850 /* The chain exists only because there is
2853 tcf_chain_hold(chain);
2855 NL_SET_ERR_MSG(extack, "Filter chain already exists");
2861 NL_SET_ERR_MSG(extack, "Need both RTM_NEWCHAIN and NLM_F_CREATE to create a new chain");
2865 chain = tcf_chain_create(block, chain_index);
2866 if (!chain) {
2867 NL_SET_ERR_MSG(extack, "Failed to create filter chain");
2873 if (!chain || tcf_chain_held_by_acts_only(chain)) {
2874 NL_SET_ERR_MSG(extack, "Cannot find specified filter chain");
2878 tcf_chain_hold(chain);
2882 /* Modifying chain requires holding parent block lock. In case
2883 * the chain was successfully added, take a reference to the
2884 * chain. This ensures that an empty chain does not disappear at
2887 tcf_chain_hold(chain);
2888 chain->explicitly_created = true;
2894 err = tc_chain_tmplt_add(chain, net, tca, extack);
2896 tcf_chain_put_explicitly_created(chain);
2900 tc_chain_notify(chain, NULL, 0, NLM_F_CREATE | NLM_F_EXCL,
2905 chain, RTM_DELTFILTER, true);
2906 /* Flush the chain first as the user requested chain removal. */
2907 tcf_chain_flush(chain, true);
2908 /* In case the chain was successfully deleted, put a reference
2909 * to the chain previously taken during addition.
2911 tcf_chain_put_explicitly_created(chain);
2914 err = tc_chain_notify(chain, skb, n->nlmsg_seq,
2917 NL_SET_ERR_MSG(extack, "Failed to send chain notify message");
2926 tcf_chain_put(chain);
2947 struct tcf_chain *chain;
3011 list_for_each_entry(chain, &block->chain_list, list) {
3013 nla_get_u32(tca[TCA_CHAIN]) != chain->index))
3019 if (tcf_chain_held_by_acts_only(chain))
3021 err = tc_chain_fill_node(chain->tmplt_ops, chain->tmplt_priv,
3022 chain->index, net, skb, block,