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@xxxxxxxxxx> --- 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