2015-07-26 11:57:47

by Vaishali Thakkar

[permalink] [raw]
Subject: [PATCH] netfilter: xtables: Add helper macro for xt_match boilerplate

For simple modules that contain a single xt_match without any
additional setup code then ends up being a block of duplicated
boilerplate. This patch adds a new macro, module_xt_match(),
which replaces the module_init()/module_exit() registrations with
template functions.

Signed-off-by: Vaishali Thakkar <[email protected]>
---
include/linux/netfilter/x_tables.h | 10 ++++++++++
1 file changed, 10 insertions(+)

diff --git a/include/linux/netfilter/x_tables.h b/include/linux/netfilter/x_tables.h
index 286098a..4ebf66b 100644
--- a/include/linux/netfilter/x_tables.h
+++ b/include/linux/netfilter/x_tables.h
@@ -142,6 +142,16 @@ struct xt_match {
unsigned short family;
};

+/**
+ * module_xt_match() - Helper macro for registering a netfilter driver
+ * @__xt_match: xt_match struct
+ * Helper macro for netfilter drivers which do not do anything special in module
+ * init/exit. This eliminates a lot of boilerplate. Each module may only
+ * use this macro once, and calling it replaces module_init() and module_exit()
+ */
+#define module_xt_match(__xt_match) \
+ module_driver(__xt_match, xt_register_match, xt_unregister_match)
+
/* Registration hooks for targets. */
struct xt_target {
struct list_head list;
--
1.9.1


2015-07-30 12:18:48

by Pablo Neira Ayuso

[permalink] [raw]
Subject: Re: [PATCH] netfilter: xtables: Add helper macro for xt_match boilerplate

On Sun, Jul 26, 2015 at 05:27:37PM +0530, Vaishali Thakkar wrote:
> For simple modules that contain a single xt_match without any
> additional setup code then ends up being a block of duplicated
> boilerplate. This patch adds a new macro, module_xt_match(),
> which replaces the module_init()/module_exit() registrations with
> template functions.

I prefer not to use this macro, we may need to add something to the
module_init()/module_exit() path in the future to these netfilter
extensions and then we'll have to revert the follow up conversions
patches that you will likely send.

Thanks anyway.

2015-07-31 02:03:23

by Vaishali Thakkar

[permalink] [raw]
Subject: Re: [PATCH] netfilter: xtables: Add helper macro for xt_match boilerplate

On Thu, Jul 30, 2015 at 5:54 PM, Pablo Neira Ayuso <[email protected]> wrote:
> On Sun, Jul 26, 2015 at 05:27:37PM +0530, Vaishali Thakkar wrote:
>> For simple modules that contain a single xt_match without any
>> additional setup code then ends up being a block of duplicated
>> boilerplate. This patch adds a new macro, module_xt_match(),
>> which replaces the module_init()/module_exit() registrations with
>> template functions.
>
> I prefer not to use this macro, we may need to add something to the
> module_init()/module_exit() path in the future to these netfilter
> extensions and then we'll have to revert the follow up conversions
> patches that you will likely send.

Ok. This makes sense. I think in that case you can drop the patch.

Thank You.

> Thanks anyway.



--
Vaishali