[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220916085155.33750-2-shaozhengchao@huawei.com>
Date: Fri, 16 Sep 2022 16:51:54 +0800
From: Zhengchao Shao <shaozhengchao@...wei.com>
To: <netdev@...r.kernel.org>, <bpf@...r.kernel.org>,
<davem@...emloft.net>, <edumazet@...gle.com>, <kuba@...nel.org>,
<pabeni@...hat.com>, <jhs@...atatu.com>,
<xiyou.wangcong@...il.com>, <jiri@...nulli.us>
CC: <ast@...nel.org>, <daniel@...earbox.net>, <andrii@...nel.org>,
<martin.lau@...ux.dev>, <song@...nel.org>, <yhs@...com>,
<john.fastabend@...il.com>, <kpsingh@...nel.org>, <sdf@...gle.com>,
<haoluo@...gle.com>, <jolsa@...nel.org>, <weiyongjun1@...wei.com>,
<yuehaibing@...wei.com>, <shaozhengchao@...wei.com>
Subject: [RFC PATCH net-next 1/2] net: sched: act_api: add helper macro for tcf_action in module and net init/exit
Helper macro for tcf_action that don't do anything special in module
and net init/exit. This eliminates a lot of boilerplate. Each module
may only use this macro once, and calling it replaces module/net_init()
and module/net_exit().
Signed-off-by: Zhengchao Shao <shaozhengchao@...wei.com>
---
include/net/act_api.h | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/include/net/act_api.h b/include/net/act_api.h
index 61f2ceb3939e..dac8c6475efc 100644
--- a/include/net/act_api.h
+++ b/include/net/act_api.h
@@ -292,5 +292,31 @@ static inline void tcf_action_stats_update(struct tc_action *a, u64 bytes,
#endif
}
+#define module_net_tcf_action(__mod, __act_ops) \
+static __net_init int __mod##_init_net(struct net *net) \
+{ \
+ struct tc_action_net *tn = net_generic(net, __act_ops.net_id);\
+ return tc_action_net_init(net, tn, &__act_ops);\
+} \
+static void __net_exit __mod##_exit_net(struct list_head *net_list) \
+{ \
+ tc_action_net_exit(net_list, __act_ops.net_id); \
+} \
+static struct pernet_operations __mod##_net_ops = { \
+ .init = __mod##_init_net, \
+ .exit_batch = __mod##_exit_net, \
+ .id = &__act_ops.net_id, \
+ .size = sizeof(struct tc_action_net), \
+}; \
+static int __init __mod##_init_module(void) \
+{ \
+ return tcf_register_action(&__act_ops, &(__mod##_net_ops)); \
+} \
+module_init(__mod##_init_module); \
+static void __exit __mod##_cleanup_module(void) \
+{ \
+ tcf_unregister_action(&__act_ops, &(__mod##_net_ops)); \
+} \
+module_exit(__mod##_cleanup_module)
#endif
--
2.17.1
Powered by blists - more mailing lists