[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230124170510.316970-7-jhs@mojatatu.com>
Date: Tue, 24 Jan 2023 12:04:57 -0500
From: Jamal Hadi Salim <jhs@...atatu.com>
To: netdev@...r.kernel.org
Cc: kernel@...atatu.com, deb.chatterjee@...el.com,
anjali.singhai@...el.com, namrata.limaye@...el.com,
khalidm@...dia.com, tom@...anda.io, pratyush@...anda.io,
jiri@...nulli.us, xiyou.wangcong@...il.com, davem@...emloft.net,
edumazet@...gle.com, kuba@...nel.org, pabeni@...hat.com,
vladbu@...dia.com, simon.horman@...igine.com
Subject: [PATCH net-next RFC 07/20] net/sched: act_api: create and export __tcf_register_action
Create and export __tcf_register_action, which will register an action
without registering per net ops for it. This is necessary for dynamic
P4TC actions, which are bound to a P4 pipeline which is bound to a namespace;
for this reason they only need to store themselves in the act_base API, but
don't need to be propagated to all net namespaces.
Signed-off-by: Victor Nogueira <victor@...atatu.com>
Signed-off-by: Pedro Tammela <pctammela@...atatu.com>
Signed-off-by: Jamal Hadi Salim <jhs@...atatu.com>
---
include/net/act_api.h | 2 ++
net/sched/act_api.c | 74 +++++++++++++++++++++++++++++++++----------
2 files changed, 60 insertions(+), 16 deletions(-)
diff --git a/include/net/act_api.h b/include/net/act_api.h
index 7328183b4..26d8d33f9 100644
--- a/include/net/act_api.h
+++ b/include/net/act_api.h
@@ -206,9 +206,11 @@ int tcf_idr_check_alloc(struct tc_action_net *tn, u32 *index,
int tcf_idr_release(struct tc_action *a, bool bind);
int tcf_register_action(struct tc_action_ops *a, struct pernet_operations *ops);
+int __tcf_register_action(struct tc_action_ops *a);
struct tc_action_ops *tc_lookup_action_byid(u32 act_id);
int tcf_unregister_action(struct tc_action_ops *a,
struct pernet_operations *ops);
+int __tcf_unregister_action(struct tc_action_ops *a);
int tcf_action_destroy(struct tc_action *actions[], int bind);
int tcf_action_exec(struct sk_buff *skb, struct tc_action **actions,
int nr_actions, struct tcf_result *res);
diff --git a/net/sched/act_api.c b/net/sched/act_api.c
index c730078bb..628447669 100644
--- a/net/sched/act_api.c
+++ b/net/sched/act_api.c
@@ -946,18 +946,10 @@ static void tcf_pernet_del_id_list(unsigned int id)
mutex_unlock(&act_id_mutex);
}
-int tcf_register_action(struct tc_action_ops *act,
- struct pernet_operations *ops)
+static int tcf_register_action_pernet(struct pernet_operations *ops)
{
int ret;
- if (!act->act || !act->dump || (!act->init && !act->init_ops))
- return -EINVAL;
-
- /* We have to register pernet ops before making the action ops visible,
- * otherwise tcf_action_init_1() could get a partially initialized
- * netns.
- */
ret = register_pernet_subsys(ops);
if (ret)
return ret;
@@ -968,6 +960,17 @@ int tcf_register_action(struct tc_action_ops *act,
goto err_id;
}
+ return 0;
+
+err_id:
+ unregister_pernet_subsys(ops);
+ return ret;
+}
+
+int __tcf_register_action(struct tc_action_ops *act)
+{
+ int ret;
+
write_lock(&act_mod_lock);
if (act->id) {
if (idr_find(&act_base, act->id)) {
@@ -993,16 +996,46 @@ int tcf_register_action(struct tc_action_ops *act,
err_out:
write_unlock(&act_mod_lock);
- if (ops->id)
- tcf_pernet_del_id_list(*ops->id);
+ return ret;
+}
+EXPORT_SYMBOL(__tcf_register_action);
+
+int tcf_register_action(struct tc_action_ops *act,
+ struct pernet_operations *ops)
+{
+ int ret;
+
+ if (!act->act || !act->dump || !act->init)
+ return -EINVAL;
+
+ /* We have to register pernet ops before making the action ops visible,
+ * otherwise tcf_action_init_1() could get a partially initialized
+ * netns.
+ */
+ ret = tcf_register_action_pernet(ops);
+ if (ret)
+ return ret;
+
+ ret = __tcf_register_action(act);
+ if (ret < 0)
+ goto err_id;
+
+ return 0;
+
err_id:
unregister_pernet_subsys(ops);
return ret;
}
EXPORT_SYMBOL(tcf_register_action);
-int tcf_unregister_action(struct tc_action_ops *act,
- struct pernet_operations *ops)
+static void tcf_unregister_action_pernet(struct pernet_operations *ops)
+{
+ unregister_pernet_subsys(ops);
+ if (ops->id)
+ tcf_pernet_del_id_list(*ops->id);
+}
+
+int __tcf_unregister_action(struct tc_action_ops *act)
{
int err = 0;
@@ -1011,10 +1044,19 @@ int tcf_unregister_action(struct tc_action_ops *act,
err = -EINVAL;
write_unlock(&act_mod_lock);
+
+ return err;
+}
+EXPORT_SYMBOL(__tcf_unregister_action);
+
+int tcf_unregister_action(struct tc_action_ops *act,
+ struct pernet_operations *ops)
+{
+ int err;
+
+ err = __tcf_unregister_action(act);
if (!err) {
- unregister_pernet_subsys(ops);
- if (ops->id)
- tcf_pernet_del_id_list(*ops->id);
+ tcf_unregister_action_pernet(ops);
}
return err;
}
--
2.34.1
Powered by blists - more mailing lists