nf_tables: remove struct nft_af_info
Subsystems (3)
Pablo Neira Ayuso
maintainercover nf_tables: remove struct nft_af_info
This is a follow up after the RFC patchset posted in late December [1].
This patch gets rid of quite a bit of complexity by removing the family layer and it saves us 64 bytes per netns. Families are basically defining the default filter chain hooks, that can be placed in the filter chain definition instead. Then, there is already a hook validation field that is redundant these days and some fields that are very much specific of NFPROTO_NETDEV that we can also remove.
Result is less code to maintain (~500 LOC), and hence more simple infrastructure.
No functional changes after this patchset.
[1] https://marc.info/?l=netfilter-devel&m=151467563814063&w=2
Pablo Neira Ayuso (7):
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
include/net/netfilter/nf_tables.h | 37 +- include/net/netns/nftables.h | 8 +- net/bridge/netfilter/nf_tables_bridge.c | 54 +-- net/ipv4/netfilter/nf_tables_arp.c | 49 +- net/ipv4/netfilter/nf_tables_ipv4.c | 49 +- net/ipv6/netfilter/nf_tables_ipv6.c | 49 +- net/netfilter/nf_tables_api.c | 787 ++++++++++++-------------------- net/netfilter/nf_tables_inet.c | 49 +- net/netfilter/nf_tables_netdev.c | 70 +-- net/netfilter/nft_compat.c | 16 +- net/netfilter/nft_ct.c | 16 +- net/netfilter/nft_flow_offload.c | 4 +- net/netfilter/nft_log.c | 4 +- net/netfilter/nft_masq.c | 2 +- net/netfilter/nft_meta.c | 4 +- net/netfilter/nft_nat.c | 2 +- net/netfilter/nft_redir.c | 2 +- 17 files changed, 348 insertions(+), 854 deletions(-)
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 1/7 netfilter: nf_tables: remove nhooks field from struct nft_af_info
We already validate the hook through bitmask, so this check is superfluous. When removing this, this patch is also fixing a bug in the new flowtable codebase, since ctx->afi points to the table family instead of the netdev family which is where the flowtable is really hooked in.
--- 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 | 5 +---- net/netfilter/nf_tables_inet.c | 1 - net/netfilter/nf_tables_netdev.c | 1 - 8 files changed, 1 insertion(+), 12 deletions(-)
include/net/netfilter/nf_tables.h +0 -2
@@ -973,7 +973,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
@@ -981,7 +980,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 +1 -4
@@ -1328,9 +1328,6 @@ static int nft_chain_parse_hook(struct net *net,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 ];
@@ -4991,7 +4988,7 @@ static int nf_tables_flowtable_parse_hook(const struct nft_ctx *ctx,return -EINVAL ; hooknum =ntohl (nla_get_be32 (tb[NFTA_FLOWTABLE_HOOK_NUM ])); -if (hooknum >= ctx->afi->nhooks) +if (hooknum !=NF_NETDEV_INGRESS )return -EINVAL ; priority =ntohl (nla_get_be32 (tb[NFTA_FLOWTABLE_HOOK_PRIORITY ]));
net/netfilter/nf_tables_inet.c +0 -1
@@ -40,7 +40,6 @@ static unsigned int nft_do_chain_inet(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
maintainerPATCH 2/7 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
@@ -964,10 +964,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 *
@@ -975,14 +971,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
@@ -1350,7 +1350,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
maintainerPATCH 3/7 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
@@ -611,10 +611,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 ;
@@ -632,9 +629,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 ;
@@ -654,15 +649,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)
@@ -691,7 +684,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;
@@ -5793,7 +5786,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 ; }
@@ -5955,7 +5947,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
maintainerPATCH 4/7 netfilter: nf_tables: remove struct nft_af_info parameter in nf_tables_chain_type_lookup()
In reply to Pablo Neira AyusoPass family number instead, this comes in preparation for the removal of struct nft_af_info.
--- net/netfilter/nf_tables_api.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
net/netfilter/nf_tables_api.c +7 -9
@@ -423,7 +423,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;
@@ -436,22 +436,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 ); }
@@ -1325,8 +1323,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
maintainerPATCH 5/7 netfilter: nf_tables: add single table list for all families
In reply to Pablo Neira AyusoPlace all existing user defined tables in struct net *, instead of having one list per family. This saves us from one level of indentation in netlink dump functions.
Place pointer to struct nft_af_info in struct nft_table temporarily, as we still need this to put back reference module reference counter on table removal.
This patch comes in preparation for the removal of struct nft_af_info.
--- include/net/netfilter/nf_tables.h | 8 +- include/net/netns/nftables.h | 1 + net/netfilter/nf_tables_api.c | 509 ++++++++++++++++++-------------------- net/netfilter/nf_tables_netdev.c | 21 +- net/netfilter/nft_compat.c | 16 +- net/netfilter/nft_ct.c | 16 +- net/netfilter/nft_flow_offload.c | 4 +- net/netfilter/nft_log.c | 4 +- net/netfilter/nft_masq.c | 2 +- net/netfilter/nft_meta.c | 4 +- net/netfilter/nft_nat.c | 2 +- net/netfilter/nft_redir.c | 2 +- 12 files changed, 286 insertions(+), 303 deletions(-)
include/net/netfilter/nf_tables.h +4 -4
@@ -143,22 +143,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; };
@@ -949,6 +949,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 {
@@ -961,6 +962,7 @@ struct nft_table {u32 use; u16 flags:14, genmask:2; +struct nft_af_info *afi;char *name; };
@@ -970,13 +972,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 +247 -262
1,017 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 );
net/netfilter/nft_compat.c +8 -8
@@ -144,7 +144,7 @@ nft_target_set_tgchk_param(struct xt_tgchk_param *par, { par->net = ctx->net; par->table = ctx->table->name; -switch (ctx->afi->family) { +switch (ctx->family) {case AF_INET : entry->e4.ip.proto = proto; entry->e4.ip.invflags = inv ?IPT_INV_PROTO :0 ;
@@ -175,7 +175,7 @@ nft_target_set_tgchk_param(struct xt_tgchk_param *par, }else { par->hook_mask =0 ; } - par->family = ctx->afi->family; + par->family = ctx->family; par->nft_compat = true; }
@@ -267,7 +267,7 @@ nft_target_destroy(const struct nft_ctx *ctx, const struct nft_expr *expr) par.net = ctx->net; par.target = target; par.targinfo = info; - par.family = ctx->afi->family; + par.family = ctx->family;if (par.target->destroy !=NULL ) par.target->destroy (&par);
@@ -358,7 +358,7 @@ nft_match_set_mtchk_param(struct xt_mtchk_param *par, const struct nft_ctx *ctx, { par->net = ctx->net; par->table = ctx->table->name; -switch (ctx->afi->family) { +switch (ctx->family) {case AF_INET : entry->e4.ip.proto = proto; entry->e4.ip.invflags = inv ?IPT_INV_PROTO :0 ;
@@ -389,7 +389,7 @@ nft_match_set_mtchk_param(struct xt_mtchk_param *par, const struct nft_ctx *ctx, }else { par->hook_mask =0 ; } - par->family = ctx->afi->family; + par->family = ctx->family; par->nft_compat = true; }
@@ -446,7 +446,7 @@ nft_match_destroy(const struct nft_ctx *ctx, const struct nft_expr *expr) par.net = ctx->net; par.match = match; par.matchinfo = info; - par.family = ctx->afi->family; + par.family = ctx->family;if (par.match->destroy !=NULL ) par.match->destroy (&par);
@@ -648,7 +648,7 @@ nft_match_select_ops(const struct nft_ctx *ctx, mt_name =nla_data (tb[NFTA_MATCH_NAME ]); rev =ntohl (nla_get_be32 (tb[NFTA_MATCH_REV ])); - family = ctx->afi->family; + family = ctx->family;/* Re-use the existing match if it's already loaded. */ list_for_each_entry (nft_match, &nft_match_list, head) {
@@ -733,7 +733,7 @@ nft_target_select_ops(const struct nft_ctx *ctx, tg_name =nla_data (tb[NFTA_TARGET_NAME ]); rev =ntohl (nla_get_be32 (tb[NFTA_TARGET_REV ])); - family = ctx->afi->family; + family = ctx->family;/* Re-use the existing target if it's already loaded. */ list_for_each_entry (nft_target, &nft_target_list, head) {
net/netfilter/nft_ct.c +8 -8
@@ -405,7 +405,7 @@ static int nft_ct_get_init(const struct nft_ctx *ctx,if (tb[NFTA_CT_DIRECTION ] ==NULL )return -EINVAL ; -switch (ctx->afi->family) { +switch (ctx->family) {case NFPROTO_IPV4 : len = FIELD_SIZEOF(struct nf_conntrack_tuple, src.u3.ip);
@@ -456,7 +456,7 @@ static int nft_ct_get_init(const struct nft_ctx *ctx,if (err <0 )return err; - err =nf_ct_netns_get (ctx->net, ctx->afi->family); + err =nf_ct_netns_get (ctx->net, ctx->family);if (err <0 )return err;
@@ -550,7 +550,7 @@ static int nft_ct_set_init(const struct nft_ctx *ctx,if (err <0 ) goto err1; - err =nf_ct_netns_get (ctx->net, ctx->afi->family); + err =nf_ct_netns_get (ctx->net, ctx->family);if (err <0 ) goto err1;
@@ -564,7 +564,7 @@ static int nft_ct_set_init(const struct nft_ctx *ctx,static void nft_ct_get_destroy (const struct nft_ctx *ctx,const struct nft_expr *expr) { -nf_ct_netns_put (ctx->net, ctx->afi->family); +nf_ct_netns_put (ctx->net, ctx->family); } static void nft_ct_set_destroy(const struct nft_ctx *ctx,
@@ -573,7 +573,7 @@ static void nft_ct_set_destroy(const struct nft_ctx *ctx,struct nft_ct *priv =nft_expr_priv (expr);__nft_ct_set_destroy (ctx, priv); -nf_ct_netns_put (ctx->net, ctx->afi->family); +nf_ct_netns_put (ctx->net, ctx->family); }static int nft_ct_get_dump (struct sk_buff *skb,const struct nft_expr *expr)
@@ -734,7 +734,7 @@ static int nft_ct_helper_obj_init(const struct nft_ctx *ctx,struct nft_ct_helper_obj *priv =nft_obj_data (obj);struct nf_conntrack_helper *help4, *help6;char name[NF_CT_HELPER_NAME_LEN ]; -int family = ctx->afi->family; +int family = ctx->family;if (!tb[NFTA_CT_HELPER_NAME ] || !tb[NFTA_CT_HELPER_L4PROTO ])return -EINVAL ;
@@ -753,14 +753,14 @@ static int nft_ct_helper_obj_init(const struct nft_ctx *ctx,switch (family) {case NFPROTO_IPV4 : -if (ctx->afi->family ==NFPROTO_IPV6 ) +if (ctx->family ==NFPROTO_IPV6 )return -EINVAL ; help4 =nf_conntrack_helper_try_module_get (name, family, priv->l4proto);break ;case NFPROTO_IPV6 : -if (ctx->afi->family ==NFPROTO_IPV4 ) +if (ctx->family ==NFPROTO_IPV4 )return -EINVAL ; help6 = nf_conntrack_helper_try_module_get(name, family,
net/netfilter/nft_flow_offload.c +2 -2
@@ -151,7 +151,7 @@ static int nft_flow_offload_init(const struct nft_ctx *ctx, priv->flowtable = flowtable; flowtable->use++; -return nf_ct_netns_get (ctx->net, ctx->afi->family); +return nf_ct_netns_get (ctx->net, ctx->family); } static void nft_flow_offload_destroy(const struct nft_ctx *ctx,
@@ -160,7 +160,7 @@ static void nft_flow_offload_destroy(const struct nft_ctx *ctx,struct nft_flow_offload *priv =nft_expr_priv (expr); priv->flowtable->use--; -nf_ct_netns_put (ctx->net, ctx->afi->family); +nf_ct_netns_put (ctx->net, ctx->family); }static int nft_flow_offload_dump (struct sk_buff *skb,const struct nft_expr *expr)
net/netfilter/nft_log.c +2 -2
@@ -112,7 +112,7 @@ static int nft_log_init(const struct nft_ctx *ctx,break ; } - err =nf_logger_find_get (ctx->afi->family, li->type); + err =nf_logger_find_get (ctx->family, li->type);if (err <0 ) goto err1;
@@ -133,7 +133,7 @@ static void nft_log_destroy(const struct nft_ctx *ctx,if (priv->prefix != nft_log_null_prefix)kfree (priv->prefix); -nf_logger_put (ctx->afi->family, li->type); +nf_logger_put (ctx->family, li->type); }static int nft_log_dump (struct sk_buff *skb,const struct nft_expr *expr)
net/netfilter/nft_masq.c +1 -1
@@ -73,7 +73,7 @@ int nft_masq_init(const struct nft_ctx *ctx, } } -return nf_ct_netns_get (ctx->net, ctx->afi->family); +return nf_ct_netns_get (ctx->net, ctx->family); }EXPORT_SYMBOL_GPL (nft_masq_init);
net/netfilter/nft_meta.c +2 -2
@@ -339,7 +339,7 @@ static int nft_meta_get_validate(const struct nft_ctx *ctx,if (priv->key !=NFT_META_SECPATH )return 0 ; -switch (ctx->afi->family) { +switch (ctx->family) {case NFPROTO_NETDEV : hooks =1 <<NF_NETDEV_INGRESS ;break ;
@@ -370,7 +370,7 @@ int nft_meta_set_validate(const struct nft_ctx *ctx,if (priv->key !=NFT_META_PKTTYPE )return 0 ; -switch (ctx->afi->family) { +switch (ctx->family) {case NFPROTO_BRIDGE : hooks =1 <<NF_BR_PRE_ROUTING ;break ;
net/netfilter/nft_nat.c +1 -1
@@ -142,7 +142,7 @@ static int nft_nat_init(const struct nft_ctx *ctx, const struct nft_expr *expr,return -EINVAL ; family =ntohl (nla_get_be32 (tb[NFTA_NAT_FAMILY ])); -if (family != ctx->afi->family) +if (family != ctx->family)return -EOPNOTSUPP ;switch (family) {
net/netfilter/nft_redir.c +1 -1
@@ -75,7 +75,7 @@ int nft_redir_init(const struct nft_ctx *ctx,return -EINVAL ; } -return nf_ct_netns_get (ctx->net, ctx->afi->family); +return nf_ct_netns_get (ctx->net, ctx->family); }EXPORT_SYMBOL_GPL (nft_redir_init);
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 6/7 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 and the global afinfo list, thus, shrinking struct netns for nftables that now becomes 64 bytes smaller.
And call __nft_release_afinfo() from __net_exit path accordingly to release netnamespace objects on removal.
--- include/net/netfilter/nf_tables.h | 4 +-- include/net/netns/nftables.h | 7 ---- 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 | 57 +++++++++++++++------------------ net/netfilter/nf_tables_inet.c | 41 +++++------------------- net/netfilter/nf_tables_netdev.c | 46 ++++++-------------------- 9 files changed, 75 insertions(+), 239 deletions(-)
include/net/netfilter/nf_tables.h +2 -2
@@ -979,8 +979,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 -7
@@ -7,15 +7,8 @@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; -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 +26 -31
126 lines not on this page · raw message
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
maintainerPATCH 7/7 netfilter: nf_tables: get rid of struct nft_af_info abstraction
In reply to Pablo Neira AyusoRemove the infrastructure to register/unregister nft_af_info structure, this structure stores no useful information anymore.
--- 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 | 305 ++++++++------------------------ net/netfilter/nf_tables_inet.c | 23 +-- net/netfilter/nf_tables_netdev.c | 19 +- 8 files changed, 86 insertions(+), 382 deletions(-)
include/net/netfilter/nf_tables.h +2 -21
@@ -960,28 +960,12 @@ struct nft_table {struct list_head flowtables;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 *);
@@ -1146,9 +1130,6 @@ void nft_trace_init(struct nft_traceinfo *info, const struct nft_pktinfo *pkt,void nft_trace_notify (struct nft_traceinfo *info); -#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 +70 -235
774 lines not on this page · raw message
net/netfilter/nf_tables_inet.c +2 -21
@@ -38,11 +38,6 @@ static unsigned int nft_do_chain_inet(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 ,
@@ -64,26 +59,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);
@@ -91,4 +72,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