netfilter: header cleanup
Subsystems (3)
cover netfilter: header cleanup
Having core header files in include/linux that in turn include other headers with a high number of includes implicitly degenerates into a formalism that hides what amounts to #include <linux/everything.h>
Some headers, like module.h and device.h are good examples that will essentially drag in almost everything.
There is nothing module specific about netfilter, but before we try and stop nf_tables.h from including module.h, we have to fix two instances of code which are implicitly relying on that module.h inclusion, so as to not introduce build regressions.
---
Paul Gortmaker (3):
netfilter: nf_tables: relocate header content to consumer
netfilter: nf_tables: fix implicit include of module.h
netfilter: nf_tables: drop include of module.h from nf_tables.h
include/net/netfilter/nf_tables.h | 20 ++------------------ net/netfilter/nf_tables_set_core.c | 1 + net/netfilter/nft_dynset.c | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 18 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/3 netfilter: nf_tables: relocate header content to consumer
The nf_tables.h header is used in a lot of files, but it turns out that there is only one actual user of nft_expr_clone().
Hence we relocate that function to be with the one consumer of it and avoid having to process it with CPP for all the other files.
This will also enable a reduction in the other headers that the nf_tables.h itself has to include just to be stand-alone, hence a pending further significant reduction in the CPP content that needs to get processed for each netfilter file.
Note that the explicit "inline" has been dropped as part of this relocation. In similar changes to this, I believe Dave has asked this be done, so we free up gcc to make the choice of whether to inline or not.
--- include/net/netfilter/nf_tables.h | 17 ----------------- net/netfilter/nft_dynset.c | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 17 deletions(-)
include/net/netfilter/nf_tables.h +0 -17
@@ -806,23 +806,6 @@ void nft_expr_destroy(const struct nft_ctx *ctx, struct nft_expr *expr);int nft_expr_dump (struct sk_buff *skb,unsigned int attr,const struct nft_expr *expr); -static inline int nft_expr_clone (struct nft_expr *dst,struct nft_expr *src) -{ -int err; - -if (src->ops->clone) { - dst->ops = src->ops; - err = src->ops->clone (dst, src); -if (err <0 ) -return err; - }else { -memcpy (dst, src, src->ops->size); - } - -__module_get (src->ops->type->owner); -return 0 ; -} -/** * struct nft_rule - nf_tables rule *
net/netfilter/nft_dynset.c +17 -0
@@ -28,6 +28,23 @@ struct nft_dynset {struct nft_set_binding binding; }; +static int nft_expr_clone (struct nft_expr *dst,struct nft_expr *src) +{ +int err; + +if (src->ops->clone) { + dst->ops = src->ops; + err = src->ops->clone (dst, src); +if (err <0 ) +return err; + }else { +memcpy (dst, src, src->ops->size); + } + +__module_get (src->ops->type->owner); +return 0 ; +} +static void *nft_dynset_new (struct nft_set *set,const struct nft_expr *expr,struct nft_regs *regs) {
Signature · 1 line
2.7.4
PATCH 2/3 netfilter: nf_tables: fix implicit include of module.h
In reply to Paul GortmakerThis file clearly uses modular infrastructure but does not call out the inclusion of <linux/module.h> explicitly. We add that include explicitly here, so we can tidy up some header usage elsewhere w/o causing build breakage.
--- net/netfilter/nf_tables_set_core.c | 1 + 1 file changed, 1 insertion(+)
net/netfilter/nf_tables_set_core.c +1 -0
@@ -1,4 +1,5 @@/* SPDX-License-Identifier: GPL-2.0 */ +#include <linux/module.h> #include <net/netfilter/nf_tables_core.h> static int __init nf_tables_set_module_init (void )
Signature · 1 line
2.7.4
PATCH 3/3 netfilter: nf_tables: drop include of module.h from nf_tables.h
In reply to Paul GortmakerIdeally, header files under include/linux shouldn't be adding includes of other headers, in anticipation of their consumers, but just the headers needed for the header itself to pass parsing with CPP.
The module.h is particularly bad in this sense, as it itself does include a whole bunch of other headers, due to the complexity of module support.
Since nf_tables.h is not going into a module struct looking for specific fields, we can just let it know that module is a struct, just like about 60 other include/linux headers already do.
--- include/net/netfilter/nf_tables.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
include/net/netfilter/nf_tables.h +2 -1
@@ -2,7 +2,6 @@#ifndef _NET_NF_TABLES_H#define _NET_NF_TABLES_H -#include <linux/module.h> #include <linux/list.h> #include <linux/netfilter.h> #include <linux/netfilter/nfnetlink.h>
@@ -13,6 +12,8 @@#include <net/netfilter/nf_flow_table.h> #include <net/netlink.h> +struct module ; +#define NFT_JUMP_STACK_SIZE 16struct nft_pktinfo {
Signature · 1 line
2.7.4
Pablo Neira Ayuso
maintainerQuoted 11 lines · Paul Gortmaker
Having core header files in
include/linuxthat in turn include other headers with a high number of includes implicitly degenerates into a formalism that hides what amounts to #include <linux/everything.h>Some headers, like
module.handdevice.hare good examples that will essentially drag in almost everything.There is nothing module specific about netfilter, but before we try and stop
nf_tables.hfrom includingmodule.h, we have to fix two instances of code which are implicitly relying on thatmodule.hinclusion, so as to not introduce build regressions.
Series applied.