From patchwork Fri Sep 16 08:51:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shaozhengchao X-Patchwork-Id: 12978271 X-Patchwork-Delegate: kuba@kernel.org 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 4D2EFC6FA8B for ; Fri, 16 Sep 2022 08:50:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229725AbiIPIu3 (ORCPT ); Fri, 16 Sep 2022 04:50:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229621AbiIPIu1 (ORCPT ); Fri, 16 Sep 2022 04:50:27 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6AF809C2FC; Fri, 16 Sep 2022 01:50:26 -0700 (PDT) Received: from dggpeml500026.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4MTSNH63wQz14QPq; Fri, 16 Sep 2022 16:46:23 +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.31; Fri, 16 Sep 2022 16:50:23 +0800 From: Zhengchao Shao To: , , , , , , , , CC: , , , , , , , , , , , , , Subject: [RFC PATCH net-next 1/2] net: sched: act_api: add helper macro for tcf_action in module and net init/exit Date: Fri, 16 Sep 2022 16:51:54 +0800 Message-ID: <20220916085155.33750-2-shaozhengchao@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220916085155.33750-1-shaozhengchao@huawei.com> References: <20220916085155.33750-1-shaozhengchao@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpeml500026.china.huawei.com (7.185.36.106) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC 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 --- 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