simplify nf_tables family and filter chain infra
Subsystems (3)
Pablo Neira Ayuso
maintainercover simplify nf_tables family and filter chain infra
Hi,
This patchset simplifies the nf_tables infrastructure by removing the family abstraction. As a side effect, nf_tables netns support also consumes 48 bytes less in x86_64 and its logic becomes simpler.
Last patch consolidate all filter chain definitions.
Note that this patchset depends on removal of the raw socket check [1].
Compiled tested only, will send a new iteration after a more accurate review and test.
[1] http://patchwork.ozlabs.org/patch/854171/
Pablo Neira Ayuso (8):
netfilter: nf_tables: remove nhooks field from struct nft_af_info
netfilter: nf_tables: remove flag field from struct nft_af_info
netfilter: nf_tables: no need for struct nft_af_info to enable/disable table
netfilter: nf_tables: remove struct nft_af_info parameter in nf_tables_chain_type_lookup()
netfilter: nf_tables: add single table list for all families
netfilter: nf_tables: get rid of pernet families
netfilter: nf_tables: get rid of struct nft_af_info abstraction
netfilter: nf_tables: consolidate filter chain definitions
include/net/netfilter/nf_tables.h | 40 +- include/net/netns/nftables.h | 7 +- net/bridge/netfilter/Makefile | 1 - net/bridge/netfilter/nf_tables_bridge.c | 129 ------ net/ipv4/netfilter/Makefile | 2 - net/ipv4/netfilter/nf_tables_arp.c | 49 +-- net/ipv4/netfilter/nf_tables_ipv4.c | 112 ------ net/ipv6/netfilter/Makefile | 1 - net/ipv6/netfilter/nf_tables_ipv6.c | 110 ------ net/netfilter/Makefile | 5 +- net/netfilter/nf_tables_api.c | 680 ++++++++++++-------------------- net/netfilter/nf_tables_inet.c | 141 ------- net/netfilter/nf_tables_netdev.c | 186 --------- net/netfilter/nft_chain_filter.c | 294 ++++++++++++++ 14 files changed, 565 insertions(+), 1192 deletions(-) delete mode 100644 net/bridge/netfilter/nf_tables_bridge.c delete mode 100644 net/ipv4/netfilter/nf_tables_ipv4.c delete mode 100644 net/ipv6/netfilter/nf_tables_ipv6.c delete mode 100644 net/netfilter/nf_tables_inet.c delete mode 100644 net/netfilter/nf_tables_netdev.c create mode 100644 net/netfilter/nft_chain_filter.c
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerRFC PATCH 1/8 netfilter: nf_tables: remove nhooks field from struct nft_af_info
We already validate the hook through bitmask, so this check is superfluous.
--- include/net/netfilter/nf_tables.h | 2 -- net/bridge/netfilter/nf_tables_bridge.c | 1 - net/ipv4/netfilter/nf_tables_arp.c | 1 - net/ipv4/netfilter/nf_tables_ipv4.c | 1 - net/ipv6/netfilter/nf_tables_ipv6.c | 1 - net/netfilter/nf_tables_api.c | 4 ---- net/netfilter/nf_tables_inet.c | 1 - net/netfilter/nf_tables_netdev.c | 1 - 8 files changed, 12 deletions(-)
include/net/netfilter/nf_tables.h +0 -2
@@ -970,7 +970,6 @@ enum nft_af_flags {* * @list: used internally * @family: address family -* @nhooks: number of hooks in this family * @owner: module owner * @tables: used internally * @flags: family flags
@@ -978,7 +977,6 @@ enum nft_af_flags {struct nft_af_info {struct list_head list;int family; -unsigned int nhooks;struct module *owner;struct list_head tables;u32 flags;
net/bridge/netfilter/nf_tables_bridge.c +0 -1
@@ -44,7 +44,6 @@ nft_do_chain_bridge(void *priv,static struct nft_af_info nft_af_bridge__read_mostly = { .family =NFPROTO_BRIDGE , - .nhooks =NF_BR_NUMHOOKS , .owner =THIS_MODULE , };
net/ipv4/netfilter/nf_tables_arp.c +0 -1
@@ -29,7 +29,6 @@ nft_do_chain_arp(void *priv,static struct nft_af_info nft_af_arp__read_mostly = { .family =NFPROTO_ARP , - .nhooks =NF_ARP_NUMHOOKS , .owner =THIS_MODULE , };
net/ipv4/netfilter/nf_tables_ipv4.c +0 -1
@@ -32,7 +32,6 @@ static unsigned int nft_do_chain_ipv4(void *priv,static struct nft_af_info nft_af_ipv4__read_mostly = { .family =NFPROTO_IPV4 , - .nhooks =NF_INET_NUMHOOKS , .owner =THIS_MODULE , };
net/ipv6/netfilter/nf_tables_ipv6.c +0 -1
@@ -30,7 +30,6 @@ static unsigned int nft_do_chain_ipv6(void *priv,static struct nft_af_info nft_af_ipv6__read_mostly = { .family =NFPROTO_IPV6 , - .nhooks =NF_INET_NUMHOOKS , .owner =THIS_MODULE , };
net/netfilter/nf_tables_api.c +0 -4
@@ -1283,10 +1283,6 @@ static int nft_chain_parse_hook(struct net *net, ha[NFTA_HOOK_PRIORITY] == NULL)return -EINVAL ; - hook->num =ntohl (nla_get_be32 (ha[NFTA_HOOK_HOOKNUM ])); -if (hook->num >= afi->nhooks) -return -EINVAL ; - hook->priority =ntohl (nla_get_be32 (ha[NFTA_HOOK_PRIORITY ])); type = chain_type[afi->family][NFT_CHAIN_T_DEFAULT ];
net/netfilter/nf_tables_inet.c +0 -1
@@ -61,7 +61,6 @@ static unsigned int nft_inet_output(void *priv, struct sk_buff *skb,static struct nft_af_info nft_af_inet__read_mostly = { .family =NFPROTO_INET , - .nhooks =NF_INET_NUMHOOKS , .owner =THIS_MODULE , };
net/netfilter/nf_tables_netdev.c +0 -1
@@ -40,7 +40,6 @@ nft_do_chain_netdev(void *priv, struct sk_buff *skb,static struct nft_af_info nft_af_netdev__read_mostly = { .family =NFPROTO_NETDEV , - .nhooks =NF_NETDEV_NUMHOOKS , .owner =THIS_MODULE , .flags =NFT_AF_NEEDS_DEV , };
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerRFC PATCH 2/8 netfilter: nf_tables: remove flag field from struct nft_af_info
In reply to Pablo Neira AyusoReplace it by a direct check for the netdev protocol family.
--- include/net/netfilter/nf_tables.h | 6 ------ net/netfilter/nf_tables_api.c | 2 +- net/netfilter/nf_tables_netdev.c | 1 - 3 files changed, 1 insertion(+), 8 deletions(-)
include/net/netfilter/nf_tables.h +0 -6
@@ -961,10 +961,6 @@ struct nft_table {char *name; }; -enum nft_af_flags { -NFT_AF_NEEDS_DEV = (1 <<0 ), -}; -/** * struct nft_af_info - nf_tables address family info *
@@ -972,14 +968,12 @@ enum nft_af_flags {* @family: address family * @owner: module owner * @tables: used internally -* @flags: family flags */ struct nft_af_info {struct list_head list;int family;struct module *owner;struct list_head tables; -u32 flags; };int nft_register_afinfo (struct net *,struct nft_af_info *);
net/netfilter/nf_tables_api.c +1 -1
@@ -1305,7 +1305,7 @@ static int nft_chain_parse_hook(struct net *net, hook->type = type; hook->dev =NULL ; -if (afi->flags &NFT_AF_NEEDS_DEV ) { +if (afi->family ==NFPROTO_NETDEV ) {char ifname[IFNAMSIZ ];if (!ha[NFTA_HOOK_DEV ]) {
net/netfilter/nf_tables_netdev.c +0 -1
@@ -41,7 +41,6 @@ nft_do_chain_netdev(void *priv, struct sk_buff *skb,static struct nft_af_info nft_af_netdev__read_mostly = { .family =NFPROTO_NETDEV , .owner =THIS_MODULE , - .flags =NFT_AF_NEEDS_DEV , };static int nf_tables_netdev_init_net (struct net *net)
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerRFC PATCH 3/8 netfilter: nf_tables: no need for struct nft_af_info to enable/disable table
In reply to Pablo Neira Ayusonf_tables_table_enable() and nf_tables_table_disable() take a pointer to struct nft_af_info that is never used, remove it.
--- net/netfilter/nf_tables_api.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-)
net/netfilter/nf_tables_api.c +6 -15
@@ -575,10 +575,7 @@ static int nf_tables_gettable(struct net *net, struct sock *nlsk,return err; } -static void _nf_tables_table_disable (struct net *net, -const struct nft_af_info *afi, -struct nft_table *table, -u32 cnt) +static void nft_table_disable (struct net *net,struct nft_table *table,u32 cnt) {struct nft_chain *chain;u32 i =0 ;
@@ -596,9 +593,7 @@ static void _nf_tables_table_disable(struct net *net, } } -static int nf_tables_table_enable (struct net *net, -const struct nft_af_info *afi, -struct nft_table *table) +static int nf_tables_table_enable (struct net *net,struct nft_table *table) {struct nft_chain *chain;int err, i =0 ;
@@ -618,15 +613,13 @@ static int nf_tables_table_enable(struct net *net,return 0 ; err:if (i) -_nf_tables_table_disable (net, afi, table, i); +nft_table_disable (net, table, i);return err; } -static void nf_tables_table_disable (struct net *net, -const struct nft_af_info *afi, -struct nft_table *table) +static void nf_tables_table_disable (struct net *net,struct nft_table *table) { -_nf_tables_table_disable (net, afi, table,0 ); +nft_table_disable (net, table,0 ); }static int nf_tables_updtable (struct nft_ctx *ctx)
@@ -655,7 +648,7 @@ static int nf_tables_updtable(struct nft_ctx *ctx)nft_trans_table_enable (trans) = false; }else if (!(flags &NFT_TABLE_F_DORMANT ) && ctx->table->flags &NFT_TABLE_F_DORMANT ) { - ret =nf_tables_table_enable (ctx->net, ctx->afi, ctx->table); + ret =nf_tables_table_enable (ctx->net, ctx->table);if (ret >=0 ) { ctx->table->flags &= ~NFT_TABLE_F_DORMANT ;nft_trans_table_enable (trans) = true;
@@ -5088,7 +5081,6 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb)if (nft_trans_table_update (trans)) {if (!nft_trans_table_enable (trans)) {nf_tables_table_disable (net, - trans->ctx.afi, trans->ctx.table); trans->ctx.table->flags |=NFT_TABLE_F_DORMANT ; }
@@ -5232,7 +5224,6 @@ static int nf_tables_abort(struct net *net, struct sk_buff *skb)if (nft_trans_table_update (trans)) {if (nft_trans_table_enable (trans)) {nf_tables_table_disable (net, - trans->ctx.afi, trans->ctx.table); trans->ctx.table->flags |=NFT_TABLE_F_DORMANT ; }
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerRFC PATCH 4/8 netfilter: nf_tables: remove struct nft_af_info parameter in nf_tables_chain_type_lookup()
In reply to Pablo Neira AyusoPass family instead.
--- net/netfilter/nf_tables_api.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
net/netfilter/nf_tables_api.c +7 -9
@@ -387,7 +387,7 @@ static inline u64 nf_tables_alloc_handle(struct nft_table *table)static const struct nf_chain_type *chain_type[NFPROTO_NUMPROTO ][NFT_CHAIN_T_MAX ];static const struct nf_chain_type * -__nf_tables_chain_type_lookup (int family,const struct nlattr *nla) +__nf_tables_chain_type_lookup (const struct nlattr *nla,u8 family) {int i;
@@ -400,22 +400,20 @@ __nf_tables_chain_type_lookup(int family, const struct nlattr *nla) }static const struct nf_chain_type * -nf_tables_chain_type_lookup (const struct nft_af_info *afi, -const struct nlattr *nla, -bool autoload) +nf_tables_chain_type_lookup (const struct nlattr *nla,u8 family,bool autoload) {const struct nf_chain_type *type; - type =__nf_tables_chain_type_lookup (afi->family, nla); + type =__nf_tables_chain_type_lookup (nla, family);if (type !=NULL )return type;#ifdef CONFIG_MODULES if (autoload) {nfnl_unlock (NFNL_SUBSYS_NFTABLES ); -request_module ("nft-chain-%u-%.*s" , afi->family, +request_module ("nft-chain-%u-%.*s" , family,nla_len (nla), (const char *)nla_data (nla));nfnl_lock (NFNL_SUBSYS_NFTABLES ); - type =__nf_tables_chain_type_lookup (afi->family, nla); + type =__nf_tables_chain_type_lookup (nla, family);if (type !=NULL )return ERR_PTR (-EAGAIN ); }
@@ -1280,8 +1278,8 @@ static int nft_chain_parse_hook(struct net *net, type = chain_type[afi->family][NFT_CHAIN_T_DEFAULT ];if (nla[NFTA_CHAIN_TYPE ]) { - type =nf_tables_chain_type_lookup (afi, nla[NFTA_CHAIN_TYPE ], - create); + type =nf_tables_chain_type_lookup (nla[NFTA_CHAIN_TYPE ], + afi->family, create);if (IS_ERR (type))return PTR_ERR (type); }
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerRFC PATCH 5/8 netfilter: nf_tables: add single table list for all families
In reply to Pablo Neira Ayuso--- include/net/netfilter/nf_tables.h | 8 +- include/net/netns/nftables.h | 1 + net/netfilter/nf_tables_api.c | 438 ++++++++++++++++++-------------------- net/netfilter/nf_tables_netdev.c | 21 +- 4 files changed, 227 insertions(+), 241 deletions(-)
include/net/netfilter/nf_tables.h +4 -4
@@ -142,22 +142,22 @@ static inline void nft_data_debug(const struct nft_data *data)* struct nft_ctx - nf_tables rule/set context * * @net: net namespace -* @afi: address family info * @table: the table the chain is contained in * @chain: the chain the rule is contained in * @nla: netlink attributes * @portid: netlink portID of the original message * @seq: netlink sequence number +* @family: protocol family * @report: notify via unicast netlink message */ struct nft_ctx {struct net *net; -struct nft_af_info *afi;struct nft_table *table;struct nft_chain *chain;const struct nlattr *const *nla;u32 portid;u32 seq; +u8 family;bool report; };
@@ -947,6 +947,7 @@ unsigned int nft_do_chain(struct nft_pktinfo *pkt, void *priv);* @use: number of chain references to this table * @flags: table flag (see enum nft_table_flags) * @genmask: generation mask +* @afinfo: address family info * @name: name of the table */ struct nft_table {
@@ -958,6 +959,7 @@ struct nft_table {u32 use; u16 flags:14, genmask:2; +struct nft_af_info *afi;char *name; };
@@ -967,13 +969,11 @@ struct nft_table {* @list: used internally * @family: address family * @owner: module owner -* @tables: used internally */ struct nft_af_info {struct list_head list;int family;struct module *owner; -struct list_head tables; };int nft_register_afinfo (struct net *,struct nft_af_info *);
include/net/netns/nftables.h +1 -0
@@ -8,6 +8,7 @@ struct nft_af_info;struct netns_nftables {struct list_head af_info; +struct list_head tables;struct list_head commit_list;struct nft_af_info *ipv4;struct nft_af_info *ipv6;
net/netfilter/nf_tables_api.c +213 -225
877 lines not on this page · raw message
net/netfilter/nf_tables_netdev.c +9 -12
@@ -107,7 +107,6 @@ static int nf_tables_netdev_event(struct notifier_block *this, unsigned long event, void *ptr) { struct net_device *dev = netdev_notifier_info_to_dev(ptr); -struct nft_af_info *afi;struct nft_table *table;struct nft_chain *chain, *nr; struct nft_ctx ctx = {
@@ -119,20 +118,18 @@ static int nf_tables_netdev_event(struct notifier_block *this,return NOTIFY_DONE ;nfnl_lock (NFNL_SUBSYS_NFTABLES ); -list_for_each_entry (afi, &dev_net (dev)->nft.af_info, list) { - ctx.afi = afi; -if (afi->family !=NFPROTO_NETDEV ) +list_for_each_entry (table, &ctx.net->nft.tables, list) { +if (table->afi->family !=NFPROTO_NETDEV )continue ; -list_for_each_entry (table, &afi->tables, list) { - ctx.table = table; -list_for_each_entry_safe (chain, nr, &table->chains, list) { -if (!nft_is_base_chain (chain)) -continue ; + ctx.family = table->afi->family; + ctx.table = table; +list_for_each_entry_safe (chain, nr, &table->chains, list) { +if (!nft_is_base_chain (chain)) +continue ; - ctx.chain = chain; -nft_netdev_event (event, dev, &ctx); - } + ctx.chain = chain; +nft_netdev_event (event, dev, &ctx); } }nfnl_unlock (NFNL_SUBSYS_NFTABLES );
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerRFC PATCH 6/8 netfilter: nf_tables: get rid of pernet families
In reply to Pablo Neira AyusoNow that we have a single table list for each netns, we can get rid of one pointer per family, thus, shrinking struct netns for nftables.
Call __nft_release_afinfo() from __net_exit path.
--- include/net/netfilter/nf_tables.h | 4 +-- include/net/netns/nftables.h | 6 ----- net/bridge/netfilter/nf_tables_bridge.c | 38 ++++----------------------- net/ipv4/netfilter/nf_tables_arp.c | 41 +++++++---------------------- net/ipv4/netfilter/nf_tables_ipv4.c | 40 ++++++---------------------- net/ipv6/netfilter/nf_tables_ipv6.c | 40 ++++++---------------------- net/netfilter/nf_tables_api.c | 40 +++++++++++++++------------- net/netfilter/nf_tables_inet.c | 41 ++++++----------------------- net/netfilter/nf_tables_netdev.c | 46 +++++++-------------------------- 9 files changed, 71 insertions(+), 225 deletions(-)
include/net/netfilter/nf_tables.h +2 -2
@@ -976,8 +976,8 @@ struct nft_af_info {struct module *owner; }; -int nft_register_afinfo (struct net *,struct nft_af_info *); -void nft_unregister_afinfo (struct net *,struct nft_af_info *); +int nft_register_afinfo (struct nft_af_info *); +void nft_unregister_afinfo (struct nft_af_info *);int nft_register_chain_type (const struct nf_chain_type *);void nft_unregister_chain_type (const struct nf_chain_type *);
include/net/netns/nftables.h +0 -6
@@ -10,12 +10,6 @@ struct netns_nftables {struct list_head af_info;struct list_head tables;struct list_head commit_list; -struct nft_af_info *ipv4; -struct nft_af_info *ipv6; -struct nft_af_info *inet; -struct nft_af_info *arp; -struct nft_af_info *bridge; -struct nft_af_info *netdev;unsigned int base_seq;u8 gencursor; };
net/bridge/netfilter/nf_tables_bridge.c +5 -33
@@ -47,34 +47,6 @@ static struct nft_af_info nft_af_bridge __read_mostly = { .owner = THIS_MODULE, }; -static int nf_tables_bridge_init_net (struct net *net) -{ - net->nft.bridge =kmalloc (sizeof (struct nft_af_info ),GFP_KERNEL ); -if (net->nft.bridge ==NULL ) -return -ENOMEM ; - -memcpy (net->nft.bridge, &nft_af_bridge,sizeof (nft_af_bridge)); - -if (nft_register_afinfo (net, net->nft.bridge) <0 ) - goto err; - -return 0 ; -err: -kfree (net->nft.bridge); -return -ENOMEM ; -} - -static void nf_tables_bridge_exit_net (struct net *net) -{ -nft_unregister_afinfo (net, net->nft.bridge); -kfree (net->nft.bridge); -} - -static struct pernet_operations nf_tables_bridge_net_ops = { - .init = nf_tables_bridge_init_net, - .exit = nf_tables_bridge_exit_net, -}; -static const struct nf_chain_type filter_bridge = { .name ="filter" , .type =NFT_CHAIN_T_DEFAULT ,
@@ -98,17 +70,17 @@ static int __init nf_tables_bridge_init(void) {int ret; - ret =nft_register_chain_type (&filter_bridge); + ret =nft_register_afinfo (&nft_af_bridge);if (ret <0 )return ret; - ret =register_pernet_subsys (&nf_tables_bridge_net_ops); + ret =nft_register_chain_type (&filter_bridge);if (ret <0 ) - goto err_register_subsys; + goto err_register_chain;return ret; -err_register_subsys: +err_register_chain:nft_unregister_chain_type (&filter_bridge);return ret;
@@ -116,8 +88,8 @@ static int __init nf_tables_bridge_init(void) static void __exit nf_tables_bridge_exit(void) { -unregister_pernet_subsys (&nf_tables_bridge_net_ops);nft_unregister_chain_type (&filter_bridge); +nft_unregister_afinfo (&nft_af_bridge); }module_init (nf_tables_bridge_init);
net/ipv4/netfilter/nf_tables_arp.c +9 -32
64 lines not on this page · raw message
net/ipv4/netfilter/nf_tables_ipv4.c +8 -32
@@ -35,34 +35,6 @@ static struct nft_af_info nft_af_ipv4 __read_mostly = { .owner = THIS_MODULE, }; -static int nf_tables_ipv4_init_net (struct net *net) -{ - net->nft.ipv4 =kmalloc (sizeof (struct nft_af_info ),GFP_KERNEL ); -if (net->nft.ipv4 ==NULL ) -return -ENOMEM ; - -memcpy (net->nft.ipv4, &nft_af_ipv4,sizeof (nft_af_ipv4)); - -if (nft_register_afinfo (net, net->nft.ipv4) <0 ) - goto err; - -return 0 ; -err: -kfree (net->nft.ipv4); -return -ENOMEM ; -} - -static void nf_tables_ipv4_exit_net (struct net *net) -{ -nft_unregister_afinfo (net, net->nft.ipv4); -kfree (net->nft.ipv4); -} - -static struct pernet_operations nf_tables_ipv4_net_ops = { - .init = nf_tables_ipv4_init_net, - .exit = nf_tables_ipv4_exit_net, -}; -static const struct nf_chain_type filter_ipv4 = { .name ="filter" , .type =NFT_CHAIN_T_DEFAULT ,
@@ -86,21 +58,25 @@ static int __init nf_tables_ipv4_init(void) {int ret; - ret =nft_register_chain_type (&filter_ipv4); + ret =nft_register_afinfo (&nft_af_ipv4);if (ret <0 )return ret; - ret =register_pernet_subsys (&nf_tables_ipv4_net_ops); + ret =nft_register_chain_type (&filter_ipv4);if (ret <0 ) -nft_unregister_chain_type (&filter_ipv4); + goto err_register_chain; + +return 0 ; +err_register_chain: +nft_unregister_afinfo (&nft_af_ipv4);return ret; } static void __exit nf_tables_ipv4_exit(void) { -unregister_pernet_subsys (&nf_tables_ipv4_net_ops);nft_unregister_chain_type (&filter_ipv4); +nft_unregister_afinfo (&nft_af_ipv4); }module_init (nf_tables_ipv4_init);
net/ipv6/netfilter/nf_tables_ipv6.c +8 -32
@@ -33,34 +33,6 @@ static struct nft_af_info nft_af_ipv6 __read_mostly = { .owner = THIS_MODULE, }; -static int nf_tables_ipv6_init_net (struct net *net) -{ - net->nft.ipv6 =kmalloc (sizeof (struct nft_af_info ),GFP_KERNEL ); -if (net->nft.ipv6 ==NULL ) -return -ENOMEM ; - -memcpy (net->nft.ipv6, &nft_af_ipv6,sizeof (nft_af_ipv6)); - -if (nft_register_afinfo (net, net->nft.ipv6) <0 ) - goto err; - -return 0 ; -err: -kfree (net->nft.ipv6); -return -ENOMEM ; -} - -static void nf_tables_ipv6_exit_net (struct net *net) -{ -nft_unregister_afinfo (net, net->nft.ipv6); -kfree (net->nft.ipv6); -} - -static struct pernet_operations nf_tables_ipv6_net_ops = { - .init = nf_tables_ipv6_init_net, - .exit = nf_tables_ipv6_exit_net, -}; -static const struct nf_chain_type filter_ipv6 = { .name ="filter" , .type =NFT_CHAIN_T_DEFAULT ,
@@ -84,20 +56,24 @@ static int __init nf_tables_ipv6_init(void) {int ret; - ret =nft_register_chain_type (&filter_ipv6); + ret =nft_register_afinfo (&nft_af_ipv6);if (ret <0 )return ret; - ret =register_pernet_subsys (&nf_tables_ipv6_net_ops); + ret =nft_register_chain_type (&filter_ipv6);if (ret <0 ) -nft_unregister_chain_type (&filter_ipv6); + goto err_register_chain; + +return 0 ; +err_register_chain: +nft_unregister_afinfo (&nft_af_ipv6);return ret; } static void __exit nf_tables_ipv6_exit(void) { -unregister_pernet_subsys (&nf_tables_ipv6_net_ops); +nft_unregister_afinfo (&nft_af_ipv6);nft_unregister_chain_type (&filter_ipv6); }
net/netfilter/nf_tables_api.c +22 -18
@@ -24,6 +24,7 @@static LIST_HEAD (nf_tables_expressions);static LIST_HEAD (nf_tables_objects); +static LIST_HEAD (nf_tables_af_info);/** * nft_register_afinfo - register nf_tables address family info
@@ -33,17 +34,15 @@ static LIST_HEAD(nf_tables_objects);* Register the address family for use with nf_tables. Returns zero on * success or a negative errno code otherwise. */ -int nft_register_afinfo (struct net *net,struct nft_af_info *afi) +int nft_register_afinfo (struct nft_af_info *afi) {nfnl_lock (NFNL_SUBSYS_NFTABLES ); -list_add_tail_rcu (&afi->list, &net->nft.af_info); +list_add_tail_rcu (&afi->list, &nf_tables_af_info);nfnl_unlock (NFNL_SUBSYS_NFTABLES );return 0 ; }EXPORT_SYMBOL_GPL (nft_register_afinfo); -static void __nft_release_afinfo (struct net *net,struct nft_af_info *afi); -/** * nft_unregister_afinfo - unregister nf_tables address family info *
@@ -51,10 +50,9 @@ static void __nft_release_afinfo(struct net *net, struct nft_af_info *afi);* * Unregister the address family for use with nf_tables. */ -void nft_unregister_afinfo (struct net *net,struct nft_af_info *afi) +void nft_unregister_afinfo (struct nft_af_info *afi) {nfnl_lock (NFNL_SUBSYS_NFTABLES ); -__nft_release_afinfo (net, afi);list_del_rcu (&afi->list);nfnl_unlock (NFNL_SUBSYS_NFTABLES ); }
@@ -5800,15 +5798,6 @@ int nft_data_dump(struct sk_buff *skb, int attr, const struct nft_data *data, }EXPORT_SYMBOL_GPL (nft_data_dump); -static int __net_init nf_tables_init_net (struct net *net) -{ -INIT_LIST_HEAD (&net->nft.af_info); -INIT_LIST_HEAD (&net->nft.tables); -INIT_LIST_HEAD (&net->nft.commit_list); - net->nft.base_seq =1 ; -return 0 ; -} -int __nft_release_basechain (struct nft_ctx *ctx) {struct nft_rule *rule, *nr;
@@ -5829,8 +5818,7 @@ int __nft_release_basechain(struct nft_ctx *ctx) }EXPORT_SYMBOL_GPL (__nft_release_basechain); -/* Called by nft_unregister_afinfo() from __net_exit path, nfnl_lock is held. */ -static void __nft_release_afinfo (struct net *net,struct nft_af_info *afi) +static void __nft_release_afinfo (struct net *net) {struct nft_table *table, *nt;struct nft_chain *chain, *nc;
@@ -5839,10 +5827,11 @@ static void __nft_release_afinfo(struct net *net, struct nft_af_info *afi)struct nft_set *set, *ns;struct nft_ctx ctx = { .net = net, - .family = afi->family, };list_for_each_entry_safe (table, nt, &net->nft.tables, list) { + ctx.family = table->afi->family; +list_for_each_entry (chain, &table->chains, list)nf_tables_unregister_hook (net, table, chain);/* No packets are walking on these chains anymore. */
@@ -5875,8 +5864,23 @@ static void __nft_release_afinfo(struct net *net, struct nft_af_info *afi) } } +static int __net_init nf_tables_init_net (struct net *net) +{ +INIT_LIST_HEAD (&net->nft.af_info); +INIT_LIST_HEAD (&net->nft.tables); +INIT_LIST_HEAD (&net->nft.commit_list); + net->nft.base_seq =1 ; +return 0 ; +} + +static void __net_exit nf_tables_exit_net(struct net *net) +{ +__nft_release_afinfo (net); +} +static struct pernet_operations nf_tables_net_ops = { .init = nf_tables_init_net, + .exit = nf_tables_exit_net, };static int __init nf_tables_module_init (void )
net/netfilter/nf_tables_inet.c +8 -33
63 lines not on this page · raw message
net/netfilter/nf_tables_netdev.c +9 -37
75 lines not on this page · raw message
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerRFC PATCH 7/8 netfilter: nf_tables: get rid of struct nft_af_info abstraction
In reply to Pablo Neira Ayuso--- include/net/netfilter/nf_tables.h | 23 +-- net/bridge/netfilter/nf_tables_bridge.c | 25 +-- net/ipv4/netfilter/nf_tables_arp.c | 25 +-- net/ipv4/netfilter/nf_tables_ipv4.c | 24 +-- net/ipv6/netfilter/nf_tables_ipv6.c | 24 +-- net/netfilter/nf_tables_api.c | 260 +++++++------------------------- net/netfilter/nf_tables_inet.c | 23 +-- net/netfilter/nf_tables_netdev.c | 19 +-- 8 files changed, 72 insertions(+), 351 deletions(-)
include/net/netfilter/nf_tables.h +2 -21
@@ -957,28 +957,12 @@ struct nft_table {struct list_head objects;u64 hgenerator;u32 use; - u16 flags:14, + u16 family:6, + flags:8, genmask:2; -struct nft_af_info *afi;char *name; }; -/** -* struct nft_af_info - nf_tables address family info -* -* @list: used internally -* @family: address family -* @owner: module owner -*/ -struct nft_af_info { -struct list_head list; -int family; -struct module *owner; -}; - -int nft_register_afinfo (struct nft_af_info *); -void nft_unregister_afinfo (struct nft_af_info *); -int nft_register_chain_type (const struct nf_chain_type *);void nft_unregister_chain_type (const struct nf_chain_type *);
@@ -1108,9 +1092,6 @@ void nft_trace_notify(struct nft_traceinfo *info);#define nft_dereference (p) \ nfnl_dereference(p, NFNL_SUBSYS_NFTABLES) -#define MODULE_ALIAS_NFT_FAMILY (family) \ - MODULE_ALIAS("nft-afinfo-" __stringify(family)) -#define MODULE_ALIAS_NFT_CHAIN (family, name) \ MODULE_ALIAS("nft-chain-" __stringify(family) "-" name)
net/bridge/netfilter/nf_tables_bridge.c +2 -23
@@ -42,11 +42,6 @@ nft_do_chain_bridge(void *priv,return nft_do_chain (&pkt, priv); } -static struct nft_af_info nft_af_bridge__read_mostly = { - .family =NFPROTO_BRIDGE , - .owner =THIS_MODULE , -}; -static const struct nf_chain_type filter_bridge = { .name ="filter" , .type =NFT_CHAIN_T_DEFAULT ,
@@ -68,28 +63,12 @@ static const struct nf_chain_type filter_bridge = {static int __init nf_tables_bridge_init (void ) { -int ret; - - ret =nft_register_afinfo (&nft_af_bridge); -if (ret <0 ) -return ret; - - ret =nft_register_chain_type (&filter_bridge); -if (ret <0 ) - goto err_register_chain; - -return ret; - -err_register_chain: -nft_unregister_chain_type (&filter_bridge); - -return ret; +return nft_register_chain_type (&filter_bridge); } static void __exit nf_tables_bridge_exit(void) {nft_unregister_chain_type (&filter_bridge); -nft_unregister_afinfo (&nft_af_bridge); }module_init (nf_tables_bridge_init);
@@ -97,4 +76,4 @@ module_exit(nf_tables_bridge_exit);MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Patrick McHardy <[email protected]>" ); -MODULE_ALIAS_NFT_FAMILY (AF_BRIDGE ); +MODULE_ALIAS_NFT_CHAIN (AF_BRIDGE ,"filter" );
net/ipv4/netfilter/nf_tables_arp.c +2 -23
@@ -27,11 +27,6 @@ nft_do_chain_arp(void *priv,return nft_do_chain (&pkt, priv); } -static struct nft_af_info nft_af_arp__read_mostly = { - .family =NFPROTO_ARP , - .owner =THIS_MODULE , -}; -static const struct nf_chain_type filter_arp = { .name ="filter" , .type =NFT_CHAIN_T_DEFAULT ,
@@ -47,28 +42,12 @@ static const struct nf_chain_type filter_arp = {static int __init nf_tables_arp_init (void ) { -int ret; - - ret =nft_register_afinfo (&nft_af_arp); -if (ret <0 ) -return ret; - - ret =nft_register_chain_type (&filter_arp); -if (ret <0 ) - goto err_register_chain; - -return 0 ; - -err_register_chain: -nft_unregister_chain_type (&filter_arp); - -return ret; +return nft_register_chain_type (&filter_arp); } static void __exit nf_tables_arp_exit(void) {nft_unregister_chain_type (&filter_arp); -nft_unregister_afinfo (&nft_af_arp); }module_init (nf_tables_arp_init);
@@ -76,4 +55,4 @@ module_exit(nf_tables_arp_exit);MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Patrick McHardy <[email protected]>" ); -MODULE_ALIAS_NFT_FAMILY (3 );/* NFPROTO_ARP */ +MODULE_ALIAS_NFT_CHAIN (3 ,"filter" );/* NFPROTO_ARP */
net/ipv4/netfilter/nf_tables_ipv4.c +2 -22
@@ -30,11 +30,6 @@ static unsigned int nft_do_chain_ipv4(void *priv,return nft_do_chain (&pkt, priv); } -static struct nft_af_info nft_af_ipv4__read_mostly = { - .family =NFPROTO_IPV4 , - .owner =THIS_MODULE , -}; -static const struct nf_chain_type filter_ipv4 = { .name ="filter" , .type =NFT_CHAIN_T_DEFAULT ,
@@ -56,27 +51,12 @@ static const struct nf_chain_type filter_ipv4 = {static int __init nf_tables_ipv4_init (void ) { -int ret; - - ret =nft_register_afinfo (&nft_af_ipv4); -if (ret <0 ) -return ret; - - ret =nft_register_chain_type (&filter_ipv4); -if (ret <0 ) - goto err_register_chain; - -return 0 ; - -err_register_chain: -nft_unregister_afinfo (&nft_af_ipv4); -return ret; +return nft_register_chain_type (&filter_ipv4); } static void __exit nf_tables_ipv4_exit(void) {nft_unregister_chain_type (&filter_ipv4); -nft_unregister_afinfo (&nft_af_ipv4); }module_init (nf_tables_ipv4_init);
@@ -84,4 +64,4 @@ module_exit(nf_tables_ipv4_exit);MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Patrick McHardy <[email protected]>" ); -MODULE_ALIAS_NFT_FAMILY (AF_INET ); +MODULE_ALIAS_NFT_CHAIN (AF_INET ,"filter" );
net/ipv6/netfilter/nf_tables_ipv6.c +2 -22
@@ -28,11 +28,6 @@ static unsigned int nft_do_chain_ipv6(void *priv,return nft_do_chain (&pkt, priv); } -static struct nft_af_info nft_af_ipv6__read_mostly = { - .family =NFPROTO_IPV6 , - .owner =THIS_MODULE , -}; -static const struct nf_chain_type filter_ipv6 = { .name ="filter" , .type =NFT_CHAIN_T_DEFAULT ,
@@ -54,26 +49,11 @@ static const struct nf_chain_type filter_ipv6 = {static int __init nf_tables_ipv6_init (void ) { -int ret; - - ret =nft_register_afinfo (&nft_af_ipv6); -if (ret <0 ) -return ret; - - ret =nft_register_chain_type (&filter_ipv6); -if (ret <0 ) - goto err_register_chain; - -return 0 ; - -err_register_chain: -nft_unregister_afinfo (&nft_af_ipv6); -return ret; +return nft_register_chain_type (&filter_ipv6); } static void __exit nf_tables_ipv6_exit(void) { -nft_unregister_afinfo (&nft_af_ipv6);nft_unregister_chain_type (&filter_ipv6); }
@@ -82,4 +62,4 @@ module_exit(nf_tables_ipv6_exit);MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Patrick McHardy <[email protected]>" ); -MODULE_ALIAS_NFT_FAMILY (AF_INET6 ); +MODULE_ALIAS_NFT_CHAIN (AF_INET6 ,"filter" );
net/netfilter/nf_tables_api.c +56 -204
637 lines not on this page · raw message
net/netfilter/nf_tables_inet.c +2 -21
@@ -59,11 +59,6 @@ static unsigned int nft_inet_output(void *priv, struct sk_buff *skb,return nft_do_chain (&pkt, priv); } -static struct nft_af_info nft_af_inet__read_mostly = { - .family =NFPROTO_INET , - .owner =THIS_MODULE , -}; -static const struct nf_chain_type filter_inet = { .name ="filter" , .type =NFT_CHAIN_T_DEFAULT ,
@@ -85,26 +80,12 @@ static const struct nf_chain_type filter_inet = {static int __init nf_tables_inet_init (void ) { -int ret; - -if (nft_register_afinfo (&nft_af_inet) <0 ) -return ret; - - ret =nft_register_chain_type (&filter_inet); -if (ret <0 ) - goto err_register_chain; - -return ret; - -err_register_chain: -nft_unregister_afinfo (&nft_af_inet); -return ret; +return nft_register_chain_type (&filter_inet); } static void __exit nf_tables_inet_exit(void) {nft_unregister_chain_type (&filter_inet); -nft_unregister_afinfo (&nft_af_inet); }module_init (nf_tables_inet_init);
@@ -112,4 +93,4 @@ module_exit(nf_tables_inet_exit);MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Patrick McHardy <[email protected]>" ); -MODULE_ALIAS_NFT_FAMILY (1 ); ++MODULE_ALIAS_NFT_CHAIN (1 ,"filter" );
net/netfilter/nf_tables_netdev.c +4 -15
@@ -38,11 +38,6 @@ nft_do_chain_netdev(void *priv, struct sk_buff *skb,return nft_do_chain (&pkt, priv); } -static struct nft_af_info nft_af_netdev__read_mostly = { - .family =NFPROTO_NETDEV , - .owner =THIS_MODULE , -}; -static const struct nf_chain_type nft_filter_chain_netdev = { .name ="filter" , .type =NFT_CHAIN_T_DEFAULT ,
@@ -91,10 +86,10 @@ static int nf_tables_netdev_event(struct notifier_block *this,nfnl_lock (NFNL_SUBSYS_NFTABLES );list_for_each_entry (table, &ctx.net->nft.tables, list) { -if (table->afi->family !=NFPROTO_NETDEV ) +if (table->family !=NFPROTO_NETDEV )continue ; - ctx.family = table->afi->family; + ctx.family = table->family; ctx.table = table;list_for_each_entry_safe (chain, nr, &table->chains, list) {if (!nft_is_base_chain (chain))
@@ -117,12 +112,9 @@ static int __init nf_tables_netdev_init(void) {int ret; -if (nft_register_afinfo (&nft_af_netdev) <0 ) -return ret; - ret =nft_register_chain_type (&nft_filter_chain_netdev);if (ret) - goto err_register_chain_type; +return ret; ret =register_netdevice_notifier (&nf_tables_netdev_notifier);if (ret)
@@ -132,8 +124,6 @@ static int __init nf_tables_netdev_init(void) err_register_netdevice_notifier:nft_unregister_chain_type (&nft_filter_chain_netdev); -err_register_chain_type: -nft_unregister_afinfo (&nft_af_netdev);return ret; }
@@ -142,7 +132,6 @@ static void __exit nf_tables_netdev_exit(void) {unregister_netdevice_notifier (&nf_tables_netdev_notifier);nft_unregister_chain_type (&nft_filter_chain_netdev); -nft_unregister_afinfo (&nft_af_netdev); }module_init (nf_tables_netdev_init);
@@ -150,4 +139,4 @@ module_exit(nf_tables_netdev_exit);MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Pablo Neira Ayuso <[email protected]>" ); -MODULE_ALIAS_NFT_FAMILY (5 );/* NFPROTO_NETDEV */ +MODULE_ALIAS_NFT_CHAIN (5 ,"filter" );/* NFPROTO_NETDEV */
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerRFC PATCH 8/8 netfilter: nf_tables: consolidate filter chain definitions
In reply to Pablo Neira AyusoEnable filter chain by default. This was not the case in iptables, given this came with an implicit hook registration that has a performance penalty. In nftables, this is not the case anymore given that chains are explicitly define by the user.
Place all filter chains in one single file to get rid of quite a bit of boiler plate code.
--- include/net/netfilter/nf_tables.h | 3 + net/bridge/netfilter/Makefile | 1 - net/bridge/netfilter/nf_tables_bridge.c | 79 --------- net/ipv4/netfilter/Makefile | 2 - net/ipv4/netfilter/nf_tables_ipv4.c | 67 -------- net/ipv6/netfilter/Makefile | 1 - net/ipv6/netfilter/nf_tables_ipv6.c | 65 ------- net/netfilter/Makefile | 5 +- net/netfilter/nf_tables_api.c | 9 +- net/netfilter/nf_tables_inet.c | 96 ----------- net/netfilter/nf_tables_netdev.c | 142 --------------- net/netfilter/nft_chain_filter.c | 294 ++++++++++++++++++++++++++++++++ 12 files changed, 307 insertions(+), 457 deletions(-) delete mode 100644 net/bridge/netfilter/nf_tables_bridge.c delete mode 100644 net/ipv4/netfilter/nf_tables_ipv4.c delete mode 100644 net/ipv6/netfilter/nf_tables_ipv6.c delete mode 100644 net/netfilter/nf_tables_inet.c delete mode 100644 net/netfilter/nf_tables_netdev.c create mode 100644 net/netfilter/nft_chain_filter.c
include/net/netfilter/nf_tables.h +3 -0
@@ -1089,6 +1089,9 @@ void nft_trace_init(struct nft_traceinfo *info, const struct nft_pktinfo *pkt,void nft_trace_notify (struct nft_traceinfo *info); +int nf_tables_filter_init (void ); +void nf_tables_filter_fini (void ); +#define nft_dereference (p) \ nfnl_dereference(p, NFNL_SUBSYS_NFTABLES)
net/bridge/netfilter/Makefile +0 -1
@@ -3,7 +3,6 @@ # Makefile for the netfilter modules for Link Layer filtering on a bridge. # -obj-$(CONFIG_NF_TABLES_BRIDGE) += nf_tables_bridge.o obj-$(CONFIG_NFT_BRIDGE_META) += nft_meta_bridge.o obj-$(CONFIG_NFT_BRIDGE_REJECT) += nft_reject_bridge.o
net/bridge/netfilter/nf_tables_bridge.c deleted +0 -79
79 lines not on this page · raw message
net/ipv4/netfilter/Makefile +0 -2
@@ -33,7 +33,6 @@ obj-$(CONFIG_NF_NAT_MASQUERADE_IPV4) += nf_nat_masquerade_ipv4.o # NAT protocols (nf_nat) obj-$(CONFIG_NF_NAT_PROTO_GRE) += nf_nat_proto_gre.o -obj-$(CONFIG_NF_TABLES_IPV4) += nf_tables_ipv4.o obj-$(CONFIG_NFT_CHAIN_ROUTE_IPV4) += nft_chain_route_ipv4.o obj-$(CONFIG_NFT_CHAIN_NAT_IPV4) += nft_chain_nat_ipv4.o obj-$(CONFIG_NFT_REJECT_IPV4) += nft_reject_ipv4.o
@@ -41,7 +40,6 @@ obj-$(CONFIG_NFT_FIB_IPV4) += nft_fib_ipv4.o obj-$(CONFIG_NFT_MASQ_IPV4) += nft_masq_ipv4.o obj-$(CONFIG_NFT_REDIR_IPV4) += nft_redir_ipv4.o obj-$(CONFIG_NFT_DUP_IPV4) += nft_dup_ipv4.o -obj-$(CONFIG_NF_TABLES_ARP) += nf_tables_arp.o # generic IP tables obj-$(CONFIG_IP_NF_IPTABLES) += ip_tables.o
net/ipv4/netfilter/nf_tables_ipv4.c deleted +0 -67
67 lines not on this page · raw message
net/ipv6/netfilter/Makefile +0 -1
@@ -36,7 +36,6 @@ obj-$(CONFIG_NF_REJECT_IPV6) += nf_reject_ipv6.o obj-$(CONFIG_NF_DUP_IPV6) += nf_dup_ipv6.o # nf_tables -obj-$(CONFIG_NF_TABLES_IPV6) += nf_tables_ipv6.o obj-$(CONFIG_NFT_CHAIN_ROUTE_IPV6) += nft_chain_route_ipv6.o obj-$(CONFIG_NFT_CHAIN_NAT_IPV6) += nft_chain_nat_ipv6.o obj-$(CONFIG_NFT_REJECT_IPV6) += nft_reject_ipv6.o
net/ipv6/netfilter/nf_tables_ipv6.c deleted +0 -65
65 lines not on this page · raw message
net/netfilter/Makefile +2 -3
@@ -73,13 +73,12 @@ obj-$(CONFIG_NETFILTER_CONNCOUNT) += nf_conncount.o obj-$(CONFIG_NF_DUP_NETDEV) += nf_dup_netdev.o # nf_tables -nf_tables-objs := nf_tables_core.o nf_tables_api.o nf_tables_trace.o \ +nf_tables-objs := nf_tables_core.o nft_chain_filter.o \ + nf_tables_api.o nf_tables_trace.o \ nft_immediate.o nft_cmp.o nft_range.o nft_bitwise.o \ nft_byteorder.o nft_payload.o nft_lookup.o nft_dynset.o obj-$(CONFIG_NF_TABLES) += nf_tables.o -obj-$(CONFIG_NF_TABLES_INET) += nf_tables_inet.o -obj-$(CONFIG_NF_TABLES_NETDEV) += nf_tables_netdev.o obj-$(CONFIG_NFT_COMPAT) += nft_compat.o obj-$(CONFIG_NFT_EXTHDR) += nft_exthdr.o obj-$(CONFIG_NFT_META) += nft_meta.o
net/netfilter/nf_tables_api.c +8 -1
@@ -5750,12 +5750,18 @@ static int __init nf_tables_module_init(void)if (err <0 ) goto err2; - err =nfnetlink_subsys_register (&nf_tables_subsys); + err =nf_tables_filter_init ();if (err <0 ) goto err3; + err =nfnetlink_subsys_register (&nf_tables_subsys); +if (err <0 ) + goto err4; +pr_info ("nf_tables: (c) 2007-2009 Patrick McHardy <[email protected]>\n" );return register_pernet_subsys (&nf_tables_net_ops); +err4: +nf_tables_filter_fini (); err3:nf_tables_core_module_exit (); err2:
@@ -5768,6 +5774,7 @@ static void __exit nf_tables_module_exit(void) {unregister_pernet_subsys (&nf_tables_net_ops);nfnetlink_subsys_unregister (&nf_tables_subsys); +nf_tables_filter_fini ();rcu_barrier ();nf_tables_core_module_exit ();kfree (info);
net/netfilter/nf_tables_inet.c deleted +0 -96
96 lines not on this page · raw message
net/netfilter/nf_tables_netdev.c deleted +0 -142
142 lines not on this page · raw message
net/netfilter/nft_chain_filter.c new file +294 -0
294 lines not on this page · raw message
Signature · 1 line
2.11.0