From nobody Mon Apr 6 21:57:13 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9646C6FA85 for ; Fri, 2 Sep 2022 11:22:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235672AbiIBLWp (ORCPT ); Fri, 2 Sep 2022 07:22:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234778AbiIBLWf (ORCPT ); Fri, 2 Sep 2022 07:22:35 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E080AC2E81; Fri, 2 Sep 2022 04:22:33 -0700 (PDT) Received: from dggpeml500026.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4MJwQd3bSrzkWrn; Fri, 2 Sep 2022 19:18:49 +0800 (CST) Received: from huawei.com (10.175.101.6) by dggpeml500026.china.huawei.com (7.185.36.106) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 2 Sep 2022 19:22:30 +0800 From: Zhengchao Shao To: , , , , , , , , , , CC: , , , , , , , , , , , , Subject: [PATCH net-next 01/22] net: sched: act_api: implement generic walker and search for tc action Date: Fri, 2 Sep 2022 19:24:25 +0800 Message-ID: <20220902112446.29858-2-shaozhengchao@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220902112446.29858-1-shaozhengchao@huawei.com> References: <20220902112446.29858-1-shaozhengchao@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpeml500026.china.huawei.com (7.185.36.106) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Being able to get tc_action_net by using net_id stored in tc_action_ops and execute the generic walk/search function, add __tcf_generic_walker() and __tcf_idr_search() helpers. Signed-off-by: Zhengchao Shao --- include/net/act_api.h | 1 + net/sched/act_api.c | 48 +++++++++++++++++++++++++++++++++++++------ 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/include/net/act_api.h b/include/net/act_api.h index 9cf6870b526e..a79d6e58519e 100644 --- a/include/net/act_api.h +++ b/include/net/act_api.h @@ -113,6 +113,7 @@ struct tc_action_ops { enum tca_id id; /* identifier should match kind */ size_t size; struct module *owner; + unsigned int *net_id; int (*act)(struct sk_buff *, const struct tc_action *, struct tcf_result *); /* called under RCU BH lock*/ int (*dump)(struct sk_buff *, struct tc_action *, int, int); diff --git a/net/sched/act_api.c b/net/sched/act_api.c index 817065aa2833..7063d2004199 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -676,6 +676,25 @@ int tcf_idr_search(struct tc_action_net *tn, struct tc= _action **a, u32 index) } EXPORT_SYMBOL(tcf_idr_search); =20 +static int __tcf_generic_walker(struct net *net, struct sk_buff *skb, + struct netlink_callback *cb, int type, + const struct tc_action_ops *ops, + struct netlink_ext_ack *extack) +{ + struct tc_action_net *tn =3D net_generic(net, *ops->net_id); + + return tcf_generic_walker(tn, skb, cb, type, ops, extack); +} + +static int __tcf_idr_search(struct net *net, + const struct tc_action_ops *ops, + struct tc_action **a, u32 index) +{ + struct tc_action_net *tn =3D net_generic(net, *ops->net_id); + + return tcf_idr_search(tn, a, index); +} + static int tcf_idr_delete_index(struct tcf_idrinfo *idrinfo, u32 index) { struct tc_action *p; @@ -926,7 +945,8 @@ int tcf_register_action(struct tc_action_ops *act, struct tc_action_ops *a; int ret; =20 - if (!act->act || !act->dump || !act->init || !act->walk || !act->lookup) + if (!act->act || !act->dump || !act->init || + (!act->net_id && (!act->walk || !act->lookup))) return -EINVAL; =20 /* We have to register pernet ops before making the action ops visible, @@ -1638,9 +1658,16 @@ static struct tc_action *tcf_action_get_1(struct net= *net, struct nlattr *nla, goto err_out; } err =3D -ENOENT; - if (ops->lookup(net, &a, index) =3D=3D 0) { - NL_SET_ERR_MSG(extack, "TC action with specified index not found"); - goto err_mod; + if (ops->lookup) { + if (ops->lookup(net, &a, index) =3D=3D 0) { + NL_SET_ERR_MSG(extack, "TC action with specified index not found"); + goto err_mod; + } + } else { + if (__tcf_idr_search(net, ops, &a, index) =3D=3D 0) { + NL_SET_ERR_MSG(extack, "TC action with specified index not found"); + goto err_mod; + } } =20 module_put(ops->owner); @@ -1703,7 +1730,12 @@ static int tca_action_flush(struct net *net, struct = nlattr *nla, goto out_module_put; } =20 - err =3D ops->walk(net, skb, &dcb, RTM_DELACTION, ops, extack); + if (ops->walk) { + err =3D ops->walk(net, skb, &dcb, RTM_DELACTION, ops, extack); + } else { + err =3D __tcf_generic_walker(net, skb, &dcb, RTM_DELACTION, ops, extack); + } + if (err <=3D 0) { nla_nest_cancel(skb, nest); goto out_module_put; @@ -2121,7 +2153,11 @@ static int tc_dump_action(struct sk_buff *skb, struc= t netlink_callback *cb) if (nest =3D=3D NULL) goto out_module_put; =20 - ret =3D a_o->walk(net, skb, cb, RTM_GETACTION, a_o, NULL); + if (a_o->walk) + ret =3D a_o->walk(net, skb, cb, RTM_GETACTION, a_o, NULL); + else + ret =3D __tcf_generic_walker(net, skb, cb, RTM_GETACTION, a_o, NULL); + if (ret < 0) goto out_module_put; =20 --=20 2.17.1