* [RFC PATCH net-next 0/2] refactor the module and net init/exit functions in tc_action
@ 2022-09-16 8:51 Zhengchao Shao
2022-09-16 8:51 ` [RFC PATCH net-next 1/2] net: sched: act_api: add helper macro for tcf_action in module and net init/exit Zhengchao Shao
2022-09-16 8:51 ` [RFC PATCH net-next 2/2] net: sched: use module_net_tcf_action macro when module and net init/exit in action Zhengchao Shao
0 siblings, 2 replies; 6+ messages in thread
From: Zhengchao Shao @ 2022-09-16 8:51 UTC (permalink / raw)
To: netdev, bpf, davem, edumazet, kuba, pabeni, jhs, xiyou.wangcong,
jiri
Cc: ast, daniel, andrii, martin.lau, song, yhs, john.fastabend,
kpsingh, sdf, haoluo, jolsa, weiyongjun1, yuehaibing,
shaozhengchao
Most action modules have their own module and net registration and
unregistration interfaces, so add macros helper and replace them with
it.
Zhengchao Shao (2):
net: sched: act_api: add helper macro for tcf_action in module and net
init/exit
net: sched: use module_net_tcf_action macro when module and net
init/exit in action
include/net/act_api.h | 26 ++++++++++++++++++++++++++
net/sched/act_bpf.c | 32 +-------------------------------
net/sched/act_connmark.c | 31 +------------------------------
net/sched/act_csum.c | 32 +-------------------------------
net/sched/act_ctinfo.c | 31 +------------------------------
net/sched/act_gate.c | 31 +------------------------------
net/sched/act_ife.c | 32 +-------------------------------
net/sched/act_mpls.c | 32 +-------------------------------
net/sched/act_nat.c | 32 +-------------------------------
net/sched/act_pedit.c | 32 +-------------------------------
net/sched/act_police.c | 32 +-------------------------------
net/sched/act_sample.c | 32 +-------------------------------
net/sched/act_skbedit.c | 32 +-------------------------------
net/sched/act_skbmod.c | 32 +-------------------------------
net/sched/act_tunnel_key.c | 32 +-------------------------------
net/sched/act_vlan.c | 32 +-------------------------------
16 files changed, 41 insertions(+), 462 deletions(-)
--
2.17.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [RFC PATCH net-next 1/2] net: sched: act_api: add helper macro for tcf_action in module and net init/exit
2022-09-16 8:51 [RFC PATCH net-next 0/2] refactor the module and net init/exit functions in tc_action Zhengchao Shao
@ 2022-09-16 8:51 ` Zhengchao Shao
2022-09-17 19:03 ` Cong Wang
2022-09-16 8:51 ` [RFC PATCH net-next 2/2] net: sched: use module_net_tcf_action macro when module and net init/exit in action Zhengchao Shao
1 sibling, 1 reply; 6+ messages in thread
From: Zhengchao Shao @ 2022-09-16 8:51 UTC (permalink / raw)
To: netdev, bpf, davem, edumazet, kuba, pabeni, jhs, xiyou.wangcong,
jiri
Cc: ast, daniel, andrii, martin.lau, song, yhs, john.fastabend,
kpsingh, sdf, haoluo, jolsa, weiyongjun1, yuehaibing,
shaozhengchao
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@huawei.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
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [RFC PATCH net-next 2/2] net: sched: use module_net_tcf_action macro when module and net init/exit in action
2022-09-16 8:51 [RFC PATCH net-next 0/2] refactor the module and net init/exit functions in tc_action Zhengchao Shao
2022-09-16 8:51 ` [RFC PATCH net-next 1/2] net: sched: act_api: add helper macro for tcf_action in module and net init/exit Zhengchao Shao
@ 2022-09-16 8:51 ` Zhengchao Shao
1 sibling, 0 replies; 6+ messages in thread
From: Zhengchao Shao @ 2022-09-16 8:51 UTC (permalink / raw)
To: netdev, bpf, davem, edumazet, kuba, pabeni, jhs, xiyou.wangcong,
jiri
Cc: ast, daniel, andrii, martin.lau, song, yhs, john.fastabend,
kpsingh, sdf, haoluo, jolsa, weiyongjun1, yuehaibing,
shaozhengchao
Use module_net_tcf_action macro when module and net init/exit in action.
Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
---
net/sched/act_bpf.c | 32 +-------------------------------
net/sched/act_connmark.c | 31 +------------------------------
net/sched/act_csum.c | 32 +-------------------------------
net/sched/act_ctinfo.c | 31 +------------------------------
net/sched/act_gate.c | 31 +------------------------------
net/sched/act_ife.c | 32 +-------------------------------
net/sched/act_mpls.c | 32 +-------------------------------
net/sched/act_nat.c | 32 +-------------------------------
net/sched/act_pedit.c | 32 +-------------------------------
net/sched/act_police.c | 32 +-------------------------------
net/sched/act_sample.c | 32 +-------------------------------
net/sched/act_skbedit.c | 32 +-------------------------------
net/sched/act_skbmod.c | 32 +-------------------------------
net/sched/act_tunnel_key.c | 32 +-------------------------------
net/sched/act_vlan.c | 32 +-------------------------------
15 files changed, 15 insertions(+), 462 deletions(-)
diff --git a/net/sched/act_bpf.c b/net/sched/act_bpf.c
index c5dbb68e6b78..ad1b0dbfd47d 100644
--- a/net/sched/act_bpf.c
+++ b/net/sched/act_bpf.c
@@ -400,37 +400,7 @@ static struct tc_action_ops act_bpf_ops __read_mostly = {
.size = sizeof(struct tcf_bpf),
};
-static __net_init int bpf_init_net(struct net *net)
-{
- struct tc_action_net *tn = net_generic(net, act_bpf_ops.net_id);
-
- return tc_action_net_init(net, tn, &act_bpf_ops);
-}
-
-static void __net_exit bpf_exit_net(struct list_head *net_list)
-{
- tc_action_net_exit(net_list, act_bpf_ops.net_id);
-}
-
-static struct pernet_operations bpf_net_ops = {
- .init = bpf_init_net,
- .exit_batch = bpf_exit_net,
- .id = &act_bpf_ops.net_id,
- .size = sizeof(struct tc_action_net),
-};
-
-static int __init bpf_init_module(void)
-{
- return tcf_register_action(&act_bpf_ops, &bpf_net_ops);
-}
-
-static void __exit bpf_cleanup_module(void)
-{
- tcf_unregister_action(&act_bpf_ops, &bpf_net_ops);
-}
-
-module_init(bpf_init_module);
-module_exit(bpf_cleanup_module);
+module_net_tcf_action(bpf, act_bpf_ops);
MODULE_AUTHOR("Jiri Pirko <jiri@resnulli.us>");
MODULE_DESCRIPTION("TC BPF based action");
diff --git a/net/sched/act_connmark.c b/net/sched/act_connmark.c
index 66b143bb04ac..58161da6e856 100644
--- a/net/sched/act_connmark.c
+++ b/net/sched/act_connmark.c
@@ -209,37 +209,8 @@ static struct tc_action_ops act_connmark_ops = {
.size = sizeof(struct tcf_connmark_info),
};
-static __net_init int connmark_init_net(struct net *net)
-{
- struct tc_action_net *tn = net_generic(net, act_connmark_ops.net_id);
-
- return tc_action_net_init(net, tn, &act_connmark_ops);
-}
-
-static void __net_exit connmark_exit_net(struct list_head *net_list)
-{
- tc_action_net_exit(net_list, act_connmark_ops.net_id);
-}
-
-static struct pernet_operations connmark_net_ops = {
- .init = connmark_init_net,
- .exit_batch = connmark_exit_net,
- .id = &act_connmark_ops.net_id,
- .size = sizeof(struct tc_action_net),
-};
-
-static int __init connmark_init_module(void)
-{
- return tcf_register_action(&act_connmark_ops, &connmark_net_ops);
-}
-
-static void __exit connmark_cleanup_module(void)
-{
- tcf_unregister_action(&act_connmark_ops, &connmark_net_ops);
-}
+module_net_tcf_action(connmark, act_connmark_ops);
-module_init(connmark_init_module);
-module_exit(connmark_cleanup_module);
MODULE_AUTHOR("Felix Fietkau <nbd@openwrt.org>");
MODULE_DESCRIPTION("Connection tracking mark restoring");
MODULE_LICENSE("GPL");
diff --git a/net/sched/act_csum.c b/net/sched/act_csum.c
index 1366adf9b909..4d8edc93a33f 100644
--- a/net/sched/act_csum.c
+++ b/net/sched/act_csum.c
@@ -709,37 +709,7 @@ static struct tc_action_ops act_csum_ops = {
.size = sizeof(struct tcf_csum),
};
-static __net_init int csum_init_net(struct net *net)
-{
- struct tc_action_net *tn = net_generic(net, act_csum_ops.net_id);
-
- return tc_action_net_init(net, tn, &act_csum_ops);
-}
-
-static void __net_exit csum_exit_net(struct list_head *net_list)
-{
- tc_action_net_exit(net_list, act_csum_ops.net_id);
-}
-
-static struct pernet_operations csum_net_ops = {
- .init = csum_init_net,
- .exit_batch = csum_exit_net,
- .id = &act_csum_ops.net_id,
- .size = sizeof(struct tc_action_net),
-};
+module_net_tcf_action(csum, act_csum_ops);
MODULE_DESCRIPTION("Checksum updating actions");
MODULE_LICENSE("GPL");
-
-static int __init csum_init_module(void)
-{
- return tcf_register_action(&act_csum_ops, &csum_net_ops);
-}
-
-static void __exit csum_cleanup_module(void)
-{
- tcf_unregister_action(&act_csum_ops, &csum_net_ops);
-}
-
-module_init(csum_init_module);
-module_exit(csum_cleanup_module);
diff --git a/net/sched/act_ctinfo.c b/net/sched/act_ctinfo.c
index d4102f0a9abd..21d1cd20c8d3 100644
--- a/net/sched/act_ctinfo.c
+++ b/net/sched/act_ctinfo.c
@@ -362,37 +362,8 @@ static struct tc_action_ops act_ctinfo_ops = {
.size = sizeof(struct tcf_ctinfo),
};
-static __net_init int ctinfo_init_net(struct net *net)
-{
- struct tc_action_net *tn = net_generic(net, act_ctinfo_ops.net_id);
-
- return tc_action_net_init(net, tn, &act_ctinfo_ops);
-}
-
-static void __net_exit ctinfo_exit_net(struct list_head *net_list)
-{
- tc_action_net_exit(net_list, act_ctinfo_ops.net_id);
-}
-
-static struct pernet_operations ctinfo_net_ops = {
- .init = ctinfo_init_net,
- .exit_batch = ctinfo_exit_net,
- .id = &act_ctinfo_ops.net_id,
- .size = sizeof(struct tc_action_net),
-};
-
-static int __init ctinfo_init_module(void)
-{
- return tcf_register_action(&act_ctinfo_ops, &ctinfo_net_ops);
-}
-
-static void __exit ctinfo_cleanup_module(void)
-{
- tcf_unregister_action(&act_ctinfo_ops, &ctinfo_net_ops);
-}
+module_net_tcf_action(ctinfo, act_ctinfo_ops);
-module_init(ctinfo_init_module);
-module_exit(ctinfo_cleanup_module);
MODULE_AUTHOR("Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>");
MODULE_DESCRIPTION("Connection tracking mark actions");
MODULE_LICENSE("GPL");
diff --git a/net/sched/act_gate.c b/net/sched/act_gate.c
index 3049878e7315..59a4dbb144e7 100644
--- a/net/sched/act_gate.c
+++ b/net/sched/act_gate.c
@@ -642,35 +642,6 @@ static struct tc_action_ops act_gate_ops = {
.size = sizeof(struct tcf_gate),
};
-static __net_init int gate_init_net(struct net *net)
-{
- struct tc_action_net *tn = net_generic(net, act_gate_ops.net_id);
-
- return tc_action_net_init(net, tn, &act_gate_ops);
-}
-
-static void __net_exit gate_exit_net(struct list_head *net_list)
-{
- tc_action_net_exit(net_list, act_gate_ops.net_id);
-}
-
-static struct pernet_operations gate_net_ops = {
- .init = gate_init_net,
- .exit_batch = gate_exit_net,
- .id = &act_gate_ops.net_id,
- .size = sizeof(struct tc_action_net),
-};
-
-static int __init gate_init_module(void)
-{
- return tcf_register_action(&act_gate_ops, &gate_net_ops);
-}
-
-static void __exit gate_cleanup_module(void)
-{
- tcf_unregister_action(&act_gate_ops, &gate_net_ops);
-}
+module_net_tcf_action(gate, act_gate_ops);
-module_init(gate_init_module);
-module_exit(gate_cleanup_module);
MODULE_LICENSE("GPL v2");
diff --git a/net/sched/act_ife.c b/net/sched/act_ife.c
index 41d63b33461d..efbdddcacdea 100644
--- a/net/sched/act_ife.c
+++ b/net/sched/act_ife.c
@@ -888,37 +888,7 @@ static struct tc_action_ops act_ife_ops = {
.size = sizeof(struct tcf_ife_info),
};
-static __net_init int ife_init_net(struct net *net)
-{
- struct tc_action_net *tn = net_generic(net, act_ife_ops.net_id);
-
- return tc_action_net_init(net, tn, &act_ife_ops);
-}
-
-static void __net_exit ife_exit_net(struct list_head *net_list)
-{
- tc_action_net_exit(net_list, act_ife_ops.net_id);
-}
-
-static struct pernet_operations ife_net_ops = {
- .init = ife_init_net,
- .exit_batch = ife_exit_net,
- .id = &act_ife_ops.net_id,
- .size = sizeof(struct tc_action_net),
-};
-
-static int __init ife_init_module(void)
-{
- return tcf_register_action(&act_ife_ops, &ife_net_ops);
-}
-
-static void __exit ife_cleanup_module(void)
-{
- tcf_unregister_action(&act_ife_ops, &ife_net_ops);
-}
-
-module_init(ife_init_module);
-module_exit(ife_cleanup_module);
+module_net_tcf_action(ife, act_ife_ops);
MODULE_AUTHOR("Jamal Hadi Salim(2015)");
MODULE_DESCRIPTION("Inter-FE LFB action");
diff --git a/net/sched/act_mpls.c b/net/sched/act_mpls.c
index 8ad25cc8ccd5..aa9a354ef308 100644
--- a/net/sched/act_mpls.c
+++ b/net/sched/act_mpls.c
@@ -437,37 +437,7 @@ static struct tc_action_ops act_mpls_ops = {
.size = sizeof(struct tcf_mpls),
};
-static __net_init int mpls_init_net(struct net *net)
-{
- struct tc_action_net *tn = net_generic(net, act_mpls_ops.net_id);
-
- return tc_action_net_init(net, tn, &act_mpls_ops);
-}
-
-static void __net_exit mpls_exit_net(struct list_head *net_list)
-{
- tc_action_net_exit(net_list, act_mpls_ops.net_id);
-}
-
-static struct pernet_operations mpls_net_ops = {
- .init = mpls_init_net,
- .exit_batch = mpls_exit_net,
- .id = &act_mpls_ops.net_id,
- .size = sizeof(struct tc_action_net),
-};
-
-static int __init mpls_init_module(void)
-{
- return tcf_register_action(&act_mpls_ops, &mpls_net_ops);
-}
-
-static void __exit mpls_cleanup_module(void)
-{
- tcf_unregister_action(&act_mpls_ops, &mpls_net_ops);
-}
-
-module_init(mpls_init_module);
-module_exit(mpls_cleanup_module);
+module_net_tcf_action(mpls, act_mpls_ops);
MODULE_SOFTDEP("post: mpls_gso");
MODULE_AUTHOR("Netronome Systems <oss-drivers@netronome.com>");
diff --git a/net/sched/act_nat.c b/net/sched/act_nat.c
index 9265145f1040..e14e8d2819bc 100644
--- a/net/sched/act_nat.c
+++ b/net/sched/act_nat.c
@@ -298,37 +298,7 @@ static struct tc_action_ops act_nat_ops = {
.size = sizeof(struct tcf_nat),
};
-static __net_init int nat_init_net(struct net *net)
-{
- struct tc_action_net *tn = net_generic(net, act_nat_ops.net_id);
-
- return tc_action_net_init(net, tn, &act_nat_ops);
-}
-
-static void __net_exit nat_exit_net(struct list_head *net_list)
-{
- tc_action_net_exit(net_list, act_nat_ops.net_id);
-}
-
-static struct pernet_operations nat_net_ops = {
- .init = nat_init_net,
- .exit_batch = nat_exit_net,
- .id = &act_nat_ops.net_id,
- .size = sizeof(struct tc_action_net),
-};
+module_net_tcf_action(nat, act_nat_ops);
MODULE_DESCRIPTION("Stateless NAT actions");
MODULE_LICENSE("GPL");
-
-static int __init nat_init_module(void)
-{
- return tcf_register_action(&act_nat_ops, &nat_net_ops);
-}
-
-static void __exit nat_cleanup_module(void)
-{
- tcf_unregister_action(&act_nat_ops, &nat_net_ops);
-}
-
-module_init(nat_init_module);
-module_exit(nat_cleanup_module);
diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c
index 94ed5857ce67..713432ac4fa7 100644
--- a/net/sched/act_pedit.c
+++ b/net/sched/act_pedit.c
@@ -539,38 +539,8 @@ static struct tc_action_ops act_pedit_ops = {
.size = sizeof(struct tcf_pedit),
};
-static __net_init int pedit_init_net(struct net *net)
-{
- struct tc_action_net *tn = net_generic(net, act_pedit_ops.net_id);
-
- return tc_action_net_init(net, tn, &act_pedit_ops);
-}
-
-static void __net_exit pedit_exit_net(struct list_head *net_list)
-{
- tc_action_net_exit(net_list, act_pedit_ops.net_id);
-}
-
-static struct pernet_operations pedit_net_ops = {
- .init = pedit_init_net,
- .exit_batch = pedit_exit_net,
- .id = &act_pedit_ops.net_id,
- .size = sizeof(struct tc_action_net),
-};
+module_net_tcf_action(pedit, act_pedit_ops);
MODULE_AUTHOR("Jamal Hadi Salim(2002-4)");
MODULE_DESCRIPTION("Generic Packet Editor actions");
MODULE_LICENSE("GPL");
-
-static int __init pedit_init_module(void)
-{
- return tcf_register_action(&act_pedit_ops, &pedit_net_ops);
-}
-
-static void __exit pedit_cleanup_module(void)
-{
- tcf_unregister_action(&act_pedit_ops, &pedit_net_ops);
-}
-
-module_init(pedit_init_module);
-module_exit(pedit_cleanup_module);
diff --git a/net/sched/act_police.c b/net/sched/act_police.c
index 0adb26e366a7..9e26b14ca86a 100644
--- a/net/sched/act_police.c
+++ b/net/sched/act_police.c
@@ -500,34 +500,4 @@ static struct tc_action_ops act_police_ops = {
.size = sizeof(struct tcf_police),
};
-static __net_init int police_init_net(struct net *net)
-{
- struct tc_action_net *tn = net_generic(net, act_police_ops.net_id);
-
- return tc_action_net_init(net, tn, &act_police_ops);
-}
-
-static void __net_exit police_exit_net(struct list_head *net_list)
-{
- tc_action_net_exit(net_list, act_police_ops.net_id);
-}
-
-static struct pernet_operations police_net_ops = {
- .init = police_init_net,
- .exit_batch = police_exit_net,
- .id = &act_police_ops.net_id,
- .size = sizeof(struct tc_action_net),
-};
-
-static int __init police_init_module(void)
-{
- return tcf_register_action(&act_police_ops, &police_net_ops);
-}
-
-static void __exit police_cleanup_module(void)
-{
- tcf_unregister_action(&act_police_ops, &police_net_ops);
-}
-
-module_init(police_init_module);
-module_exit(police_cleanup_module);
+module_net_tcf_action(police, act_police_ops);
diff --git a/net/sched/act_sample.c b/net/sched/act_sample.c
index 5ba36f70e3a1..bb9afb154698 100644
--- a/net/sched/act_sample.c
+++ b/net/sched/act_sample.c
@@ -308,37 +308,7 @@ static struct tc_action_ops act_sample_ops = {
.size = sizeof(struct tcf_sample),
};
-static __net_init int sample_init_net(struct net *net)
-{
- struct tc_action_net *tn = net_generic(net, act_sample_ops.net_id);
-
- return tc_action_net_init(net, tn, &act_sample_ops);
-}
-
-static void __net_exit sample_exit_net(struct list_head *net_list)
-{
- tc_action_net_exit(net_list, act_sample_ops.net_id);
-}
-
-static struct pernet_operations sample_net_ops = {
- .init = sample_init_net,
- .exit_batch = sample_exit_net,
- .id = &act_sample_ops.net_id,
- .size = sizeof(struct tc_action_net),
-};
-
-static int __init sample_init_module(void)
-{
- return tcf_register_action(&act_sample_ops, &sample_net_ops);
-}
-
-static void __exit sample_cleanup_module(void)
-{
- tcf_unregister_action(&act_sample_ops, &sample_net_ops);
-}
-
-module_init(sample_init_module);
-module_exit(sample_cleanup_module);
+module_net_tcf_action(sample, act_sample_ops);
MODULE_AUTHOR("Yotam Gigi <yotam.gi@gmail.com>");
MODULE_DESCRIPTION("Packet sampling action");
diff --git a/net/sched/act_skbedit.c b/net/sched/act_skbedit.c
index 7f598784fd30..d054b0b6b4ce 100644
--- a/net/sched/act_skbedit.c
+++ b/net/sched/act_skbedit.c
@@ -415,38 +415,8 @@ static struct tc_action_ops act_skbedit_ops = {
.size = sizeof(struct tcf_skbedit),
};
-static __net_init int skbedit_init_net(struct net *net)
-{
- struct tc_action_net *tn = net_generic(net, act_skbedit_ops.net_id);
-
- return tc_action_net_init(net, tn, &act_skbedit_ops);
-}
-
-static void __net_exit skbedit_exit_net(struct list_head *net_list)
-{
- tc_action_net_exit(net_list, act_skbedit_ops.net_id);
-}
-
-static struct pernet_operations skbedit_net_ops = {
- .init = skbedit_init_net,
- .exit_batch = skbedit_exit_net,
- .id = &act_skbedit_ops.net_id,
- .size = sizeof(struct tc_action_net),
-};
+module_net_tcf_action(skbedit, act_skbedit_ops);
MODULE_AUTHOR("Alexander Duyck, <alexander.h.duyck@intel.com>");
MODULE_DESCRIPTION("SKB Editing");
MODULE_LICENSE("GPL");
-
-static int __init skbedit_init_module(void)
-{
- return tcf_register_action(&act_skbedit_ops, &skbedit_net_ops);
-}
-
-static void __exit skbedit_cleanup_module(void)
-{
- tcf_unregister_action(&act_skbedit_ops, &skbedit_net_ops);
-}
-
-module_init(skbedit_init_module);
-module_exit(skbedit_cleanup_module);
diff --git a/net/sched/act_skbmod.c b/net/sched/act_skbmod.c
index d98758a63934..b3f712b2a453 100644
--- a/net/sched/act_skbmod.c
+++ b/net/sched/act_skbmod.c
@@ -286,38 +286,8 @@ static struct tc_action_ops act_skbmod_ops = {
.size = sizeof(struct tcf_skbmod),
};
-static __net_init int skbmod_init_net(struct net *net)
-{
- struct tc_action_net *tn = net_generic(net, act_skbmod_ops.net_id);
-
- return tc_action_net_init(net, tn, &act_skbmod_ops);
-}
-
-static void __net_exit skbmod_exit_net(struct list_head *net_list)
-{
- tc_action_net_exit(net_list, act_skbmod_ops.net_id);
-}
-
-static struct pernet_operations skbmod_net_ops = {
- .init = skbmod_init_net,
- .exit_batch = skbmod_exit_net,
- .id = &act_skbmod_ops.net_id,
- .size = sizeof(struct tc_action_net),
-};
+module_net_tcf_action(skbmod, act_skbmod_ops);
MODULE_AUTHOR("Jamal Hadi Salim, <jhs@mojatatu.com>");
MODULE_DESCRIPTION("SKB data mod-ing");
MODULE_LICENSE("GPL");
-
-static int __init skbmod_init_module(void)
-{
- return tcf_register_action(&act_skbmod_ops, &skbmod_net_ops);
-}
-
-static void __exit skbmod_cleanup_module(void)
-{
- tcf_unregister_action(&act_skbmod_ops, &skbmod_net_ops);
-}
-
-module_init(skbmod_init_module);
-module_exit(skbmod_cleanup_module);
diff --git a/net/sched/act_tunnel_key.c b/net/sched/act_tunnel_key.c
index 2691a3d8e451..f4fea32c9e10 100644
--- a/net/sched/act_tunnel_key.c
+++ b/net/sched/act_tunnel_key.c
@@ -836,37 +836,7 @@ static struct tc_action_ops act_tunnel_key_ops = {
.size = sizeof(struct tcf_tunnel_key),
};
-static __net_init int tunnel_key_init_net(struct net *net)
-{
- struct tc_action_net *tn = net_generic(net, act_tunnel_key_ops.net_id);
-
- return tc_action_net_init(net, tn, &act_tunnel_key_ops);
-}
-
-static void __net_exit tunnel_key_exit_net(struct list_head *net_list)
-{
- tc_action_net_exit(net_list, act_tunnel_key_ops.net_id);
-}
-
-static struct pernet_operations tunnel_key_net_ops = {
- .init = tunnel_key_init_net,
- .exit_batch = tunnel_key_exit_net,
- .id = &act_tunnel_key_ops.net_id,
- .size = sizeof(struct tc_action_net),
-};
-
-static int __init tunnel_key_init_module(void)
-{
- return tcf_register_action(&act_tunnel_key_ops, &tunnel_key_net_ops);
-}
-
-static void __exit tunnel_key_cleanup_module(void)
-{
- tcf_unregister_action(&act_tunnel_key_ops, &tunnel_key_net_ops);
-}
-
-module_init(tunnel_key_init_module);
-module_exit(tunnel_key_cleanup_module);
+module_net_tcf_action(tunnel_key, act_tunnel_key_ops);
MODULE_AUTHOR("Amir Vadai <amir@vadai.me>");
MODULE_DESCRIPTION("ip tunnel manipulation actions");
diff --git a/net/sched/act_vlan.c b/net/sched/act_vlan.c
index 7b24e898a3e6..6490a5a0f737 100644
--- a/net/sched/act_vlan.c
+++ b/net/sched/act_vlan.c
@@ -426,37 +426,7 @@ static struct tc_action_ops act_vlan_ops = {
.size = sizeof(struct tcf_vlan),
};
-static __net_init int vlan_init_net(struct net *net)
-{
- struct tc_action_net *tn = net_generic(net, act_vlan_ops.net_id);
-
- return tc_action_net_init(net, tn, &act_vlan_ops);
-}
-
-static void __net_exit vlan_exit_net(struct list_head *net_list)
-{
- tc_action_net_exit(net_list, act_vlan_ops.net_id);
-}
-
-static struct pernet_operations vlan_net_ops = {
- .init = vlan_init_net,
- .exit_batch = vlan_exit_net,
- .id = &act_vlan_ops.net_id,
- .size = sizeof(struct tc_action_net),
-};
-
-static int __init vlan_init_module(void)
-{
- return tcf_register_action(&act_vlan_ops, &vlan_net_ops);
-}
-
-static void __exit vlan_cleanup_module(void)
-{
- tcf_unregister_action(&act_vlan_ops, &vlan_net_ops);
-}
-
-module_init(vlan_init_module);
-module_exit(vlan_cleanup_module);
+module_net_tcf_action(vlan, act_vlan_ops);
MODULE_AUTHOR("Jiri Pirko <jiri@resnulli.us>");
MODULE_DESCRIPTION("vlan manipulation actions");
--
2.17.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [RFC PATCH net-next 1/2] net: sched: act_api: add helper macro for tcf_action in module and net init/exit
2022-09-16 8:51 ` [RFC PATCH net-next 1/2] net: sched: act_api: add helper macro for tcf_action in module and net init/exit Zhengchao Shao
@ 2022-09-17 19:03 ` Cong Wang
2022-09-19 11:07 ` shaozhengchao
0 siblings, 1 reply; 6+ messages in thread
From: Cong Wang @ 2022-09-17 19:03 UTC (permalink / raw)
To: Zhengchao Shao
Cc: netdev, bpf, davem, edumazet, kuba, pabeni, jhs, jiri, ast,
daniel, andrii, martin.lau, song, yhs, john.fastabend, kpsingh,
sdf, haoluo, jolsa, weiyongjun1, yuehaibing
On Fri, Sep 16, 2022 at 04:51:54PM +0800, Zhengchao Shao wrote:
> 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().
>
This looks over engineering to me. I don't think this reduces any code
size or help any readability.
Thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFC PATCH net-next 1/2] net: sched: act_api: add helper macro for tcf_action in module and net init/exit
2022-09-17 19:03 ` Cong Wang
@ 2022-09-19 11:07 ` shaozhengchao
2022-09-19 16:50 ` Cong Wang
0 siblings, 1 reply; 6+ messages in thread
From: shaozhengchao @ 2022-09-19 11:07 UTC (permalink / raw)
To: Cong Wang
Cc: netdev, bpf, davem, edumazet, kuba, pabeni, jhs, jiri, ast,
daniel, andrii, martin.lau, song, yhs, john.fastabend, kpsingh,
sdf, haoluo, jolsa, weiyongjun1, yuehaibing
On 2022/9/18 3:03, Cong Wang wrote:
> On Fri, Sep 16, 2022 at 04:51:54PM +0800, Zhengchao Shao wrote:
>> 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().
>>
>
> This looks over engineering to me. I don't think this reduces any code
> size or help any readability.
>
> Thanks.
Hi Wang:
Thank you for your review. I think this macro can simplify
repeated code when adding action modules later.
Zhengchao Shao
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFC PATCH net-next 1/2] net: sched: act_api: add helper macro for tcf_action in module and net init/exit
2022-09-19 11:07 ` shaozhengchao
@ 2022-09-19 16:50 ` Cong Wang
0 siblings, 0 replies; 6+ messages in thread
From: Cong Wang @ 2022-09-19 16:50 UTC (permalink / raw)
To: shaozhengchao
Cc: netdev, bpf, davem, edumazet, kuba, pabeni, jhs, jiri, ast,
daniel, andrii, martin.lau, song, yhs, john.fastabend, kpsingh,
sdf, haoluo, jolsa, weiyongjun1, yuehaibing
On Mon, Sep 19, 2022 at 07:07:22PM +0800, shaozhengchao wrote:
>
>
> On 2022/9/18 3:03, Cong Wang wrote:
> > On Fri, Sep 16, 2022 at 04:51:54PM +0800, Zhengchao Shao wrote:
> > > 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().
> > >
> >
> > This looks over engineering to me. I don't think this reduces any code
> > size or help any readability.
> >
> > Thanks.
> Hi Wang:
> Thank you for your review. I think this macro can simplify
> repeated code when adding action modules later.
>
I don't think so, it hides the actual code in a less readable way. I'd
like to read the non-macro code.
Thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-09-19 16:52 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-16 8:51 [RFC PATCH net-next 0/2] refactor the module and net init/exit functions in tc_action Zhengchao Shao
2022-09-16 8:51 ` [RFC PATCH net-next 1/2] net: sched: act_api: add helper macro for tcf_action in module and net init/exit Zhengchao Shao
2022-09-17 19:03 ` Cong Wang
2022-09-19 11:07 ` shaozhengchao
2022-09-19 16:50 ` Cong Wang
2022-09-16 8:51 ` [RFC PATCH net-next 2/2] net: sched: use module_net_tcf_action macro when module and net init/exit in action Zhengchao Shao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox