handle NFPROTO_INET from core
Subsystems (3)
Pablo Neira Ayuso
maintainerv2 cover handle NFPROTO_INET from core
NFPROTO_INET only works for nf_tables, handle this pseudofamily from the core itself by expanding one NFPROTO_INET hook in two hook registrations, one for NFPROTO_IPV4 and another for NFPROTO_IPV6.
This removes quite a bit of ad-hoc infrastructure in nf_tables, so it makes it less complex.
There's a final patch that also removes the family-specific hooks for filter chains, now all hooks are already define in the chain type.
Pablo Neira Ayuso (7):
netfilter: core: add nf_remove_net_hook
netfilter: core: pass hook number, family and device to nf_find_hook_list()
netfilter: core: pass family as parameter to nf_remove_net_hook()
netfilter: core: support for NFPROTO_INET hook registration
netfilter: nf_tables_inet: don't use multihook infrastructure anymore
netfilter: nf_tables: remove multihook chains and families
netfilter: nf_tables: remove hooks from family definition
include/net/netfilter/nf_tables.h | 13 +--- include/net/netfilter/nf_tables_ipv4.h | 2 - include/net/netfilter/nf_tables_ipv6.h | 2 - net/bridge/netfilter/nf_tables_bridge.c | 15 +++-- net/ipv4/netfilter/nf_tables_arp.c | 9 ++- net/ipv4/netfilter/nf_tables_ipv4.c | 18 +++--- net/ipv6/netfilter/nf_tables_ipv6.c | 18 +++--- net/netfilter/core.c | 97 ++++++++++++++++++++---------- net/netfilter/nf_tables_api.c | 102 +++++++++++++------------------- net/netfilter/nf_tables_inet.c | 69 +++++++++++++++++---- net/netfilter/nf_tables_netdev.c | 9 ++- net/netfilter/nft_compat.c | 8 +-- 12 files changed, 202 insertions(+), 160 deletions(-)
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH v2 1/7 netfilter: core: add nf_remove_net_hook
Just a cleanup, __nf_unregister_net_hook() is used by a follow up patch when handling NFPROTO_INET as a real family from the core.
--- net/netfilter/core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/netfilter/core.c +4 -4
@@ -360,7 +360,7 @@ int nf_register_net_hook(struct net *net, const struct nf_hook_ops *reg)EXPORT_SYMBOL (nf_register_net_hook);/* -* __nf_unregister_net_hook - remove a hook from blob +* nf_remove_net_hook - remove a hook from blob * * @oldp: current address of hook blob * @unreg: hook to unregister
@@ -368,8 +368,8 @@ EXPORT_SYMBOL(nf_register_net_hook);* This cannot fail, hook unregistration must always succeed. * Therefore replace the to-be-removed hook with a dummy hook. */ -static void __nf_unregister_net_hook (struct nf_hook_entries *old, -const struct nf_hook_ops *unreg) +static void nf_remove_net_hook (struct nf_hook_entries *old, +const struct nf_hook_ops *unreg) {struct nf_hook_ops **orig_ops;bool found = false;
@@ -415,7 +415,7 @@ void nf_unregister_net_hook(struct net *net, const struct nf_hook_ops *reg)return ; } -__nf_unregister_net_hook (p, reg); +nf_remove_net_hook (p, reg); p =__nf_hook_entries_try_shrink (pp);mutex_unlock (&nf_hook_mutex);
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH v2 2/7 netfilter: core: pass hook number, family and device to nf_find_hook_list()
In reply to Pablo Neira AyusoInstead of passing struct nf_hook_ops, this is needed by follow up patches to handle NFPROTO_INET from the core.
--- net/netfilter/core.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-)
net/netfilter/core.c +19 -17
@@ -268,36 +268,38 @@ static void *__nf_hook_entries_try_shrink(struct nf_hook_entries __rcu **pp)return old; } -static struct nf_hook_entries __rcu **nf_hook_entry_head (struct net *net,const struct nf_hook_ops *reg) +static struct nf_hook_entries __rcu ** +nf_hook_entry_head (struct net *net,int pf,unsigned int hooknum, +struct net_device *dev) { -switch (reg->pf) { +switch (pf) {case NFPROTO_NETDEV :break ;#ifdef CONFIG_NETFILTER_FAMILY_ARP case NFPROTO_ARP : -if (WARN_ON_ONCE (ARRAY_SIZE (net->nf.hooks_arp) <= reg->hooknum)) +if (WARN_ON_ONCE (ARRAY_SIZE (net->nf.hooks_arp) <= hooknum))return NULL ; -return net->nf.hooks_arp + reg->hooknum; +return net->nf.hooks_arp + hooknum;#endif #ifdef CONFIG_NETFILTER_FAMILY_BRIDGE case NFPROTO_BRIDGE : -if (WARN_ON_ONCE (ARRAY_SIZE (net->nf.hooks_bridge) <= reg->hooknum)) +if (WARN_ON_ONCE (ARRAY_SIZE (net->nf.hooks_bridge) <= hooknum))return NULL ; -return net->nf.hooks_bridge + reg->hooknum; +return net->nf.hooks_bridge + hooknum;#endif case NFPROTO_IPV4 : -if (WARN_ON_ONCE (ARRAY_SIZE (net->nf.hooks_ipv4) <= reg->hooknum)) +if (WARN_ON_ONCE (ARRAY_SIZE (net->nf.hooks_ipv4) <= hooknum))return NULL ; -return net->nf.hooks_ipv4 + reg->hooknum; +return net->nf.hooks_ipv4 + hooknum;case NFPROTO_IPV6 : -if (WARN_ON_ONCE (ARRAY_SIZE (net->nf.hooks_ipv6) <= reg->hooknum)) +if (WARN_ON_ONCE (ARRAY_SIZE (net->nf.hooks_ipv6) <= hooknum))return NULL ; -return net->nf.hooks_ipv6 + reg->hooknum; +return net->nf.hooks_ipv6 + hooknum;#if IS_ENABLED (CONFIG_DECNET )case NFPROTO_DECNET : -if (WARN_ON_ONCE (ARRAY_SIZE (net->nf.hooks_decnet) <= reg->hooknum)) +if (WARN_ON_ONCE (ARRAY_SIZE (net->nf.hooks_decnet) <= hooknum))return NULL ; -return net->nf.hooks_decnet + reg->hooknum; +return net->nf.hooks_decnet + hooknum;#endif default :WARN_ON_ONCE (1 );
@@ -305,9 +307,9 @@ static struct nf_hook_entries __rcu **nf_hook_entry_head(struct net *net, const }#ifdef CONFIG_NETFILTER_INGRESS -if (reg->hooknum ==NF_NETDEV_INGRESS ) { -if (reg->dev &&dev_net (reg->dev) == net) -return ®->dev->nf_hooks_ingress; +if (hooknum ==NF_NETDEV_INGRESS ) { +if (dev &&dev_net (dev) == net) +return &dev->nf_hooks_ingress; }#endif WARN_ON_ONCE (1 );
@@ -329,7 +331,7 @@ int nf_register_net_hook(struct net *net, const struct nf_hook_ops *reg)return -EINVAL ; } - pp =nf_hook_entry_head (net, reg); + pp =nf_hook_entry_head (net, reg->pf, reg->hooknum, reg->dev);if (!pp)return -EINVAL ;
@@ -403,7 +405,7 @@ void nf_unregister_net_hook(struct net *net, const struct nf_hook_ops *reg)struct nf_hook_entries __rcu **pp;struct nf_hook_entries *p; - pp =nf_hook_entry_head (net, reg); + pp =nf_hook_entry_head (net, reg->pf, reg->hooknum, reg->dev);if (!pp)return ;
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH v2 3/7 netfilter: core: pass family as parameter to nf_remove_net_hook()
In reply to Pablo Neira AyusoSo static_key_slow_dec applies to the family behind NFPROTO_INET.
--- net/netfilter/core.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
net/netfilter/core.c +5 -5
@@ -371,7 +371,7 @@ EXPORT_SYMBOL(nf_register_net_hook);* Therefore replace the to-be-removed hook with a dummy hook. */ static void nf_remove_net_hook (struct nf_hook_entries *old, -const struct nf_hook_ops *unreg) +const struct nf_hook_ops *unreg,int pf) {struct nf_hook_ops **orig_ops;bool found = false;
@@ -389,14 +389,14 @@ static void nf_remove_net_hook(struct nf_hook_entries *old,if (found) {#ifdef CONFIG_NETFILTER_INGRESS -if (unreg->pf ==NFPROTO_NETDEV && unreg->hooknum ==NF_NETDEV_INGRESS ) +if (pf ==NFPROTO_NETDEV && unreg->hooknum ==NF_NETDEV_INGRESS )net_dec_ingress_queue ();#endif #ifdef HAVE_JUMP_LABEL -static_key_slow_dec (&nf_hooks_needed[unreg->pf][unreg->hooknum]); +static_key_slow_dec (&nf_hooks_needed[pf][unreg->hooknum]);#endif }else { -WARN_ONCE (1 ,"hook not found, pf %d num %d" , unreg->pf, unreg->hooknum); +WARN_ONCE (1 ,"hook not found, pf %d num %d" , pf, unreg->hooknum); } }
@@ -417,7 +417,7 @@ void nf_unregister_net_hook(struct net *net, const struct nf_hook_ops *reg)return ; } -nf_remove_net_hook (p, reg); +nf_remove_net_hook (p, reg, reg->pf); p =__nf_hook_entries_try_shrink (pp);mutex_unlock (&nf_hook_mutex);
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH v2 4/7 netfilter: core: support for NFPROTO_INET hook registration
In reply to Pablo Neira AyusoExpand NFPROTO_INET in two hook registrations, one for NFPROTO_IPV4 and another for NFPROTO_IPV6. Hence, we handle NFPROTO_INET from the core.
--- net/netfilter/core.c | 53 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 9 deletions(-)
net/netfilter/core.c +44 -9
@@ -316,12 +316,13 @@ nf_hook_entry_head(struct net *net, int pf, unsigned int hooknum,return NULL ; } -int nf_register_net_hook (struct net *net,const struct nf_hook_ops *reg) +static int __nf_register_net_hook (struct net *net,int pf, +const struct nf_hook_ops *reg) {struct nf_hook_entries *p, *new_hooks;struct nf_hook_entries __rcu **pp; -if (reg->pf ==NFPROTO_NETDEV ) { +if (pf ==NFPROTO_NETDEV ) {#ifndef CONFIG_NETFILTER_INGRESS if (reg->hooknum ==NF_NETDEV_INGRESS )return -EOPNOTSUPP ;
@@ -331,7 +332,7 @@ int nf_register_net_hook(struct net *net, const struct nf_hook_ops *reg)return -EINVAL ; } - pp =nf_hook_entry_head (net, reg->pf, reg->hooknum, reg->dev); + pp =nf_hook_entry_head (net, pf, reg->hooknum, reg->dev);if (!pp)return -EINVAL ;
@@ -349,17 +350,16 @@ int nf_register_net_hook(struct net *net, const struct nf_hook_ops *reg)hooks_validate (new_hooks);#ifdef CONFIG_NETFILTER_INGRESS -if (reg->pf ==NFPROTO_NETDEV && reg->hooknum ==NF_NETDEV_INGRESS ) +if (pf ==NFPROTO_NETDEV && reg->hooknum ==NF_NETDEV_INGRESS )net_inc_ingress_queue ();#endif #ifdef HAVE_JUMP_LABEL -static_key_slow_inc (&nf_hooks_needed[reg->pf][reg->hooknum]); +static_key_slow_inc (&nf_hooks_needed[pf][reg->hooknum]);#endif BUG_ON (p == new_hooks);nf_hook_entries_free (p);return 0 ; } -EXPORT_SYMBOL (nf_register_net_hook);/* * nf_remove_net_hook - remove a hook from blob
@@ -400,12 +400,13 @@ static void nf_remove_net_hook(struct nf_hook_entries *old, } } -void nf_unregister_net_hook (struct net *net,const struct nf_hook_ops *reg) +void __nf_unregister_net_hook (struct net *net,int pf, +const struct nf_hook_ops *reg) {struct nf_hook_entries __rcu **pp;struct nf_hook_entries *p; - pp =nf_hook_entry_head (net, reg->pf, reg->hooknum, reg->dev); + pp =nf_hook_entry_head (net, pf, reg->hooknum, reg->dev);if (!pp)return ;
@@ -417,7 +418,7 @@ void nf_unregister_net_hook(struct net *net, const struct nf_hook_ops *reg)return ; } -nf_remove_net_hook (p, reg, reg->pf); +nf_remove_net_hook (p, reg, pf); p =__nf_hook_entries_try_shrink (pp);mutex_unlock (&nf_hook_mutex);
@@ -427,8 +428,42 @@ void nf_unregister_net_hook(struct net *net, const struct nf_hook_ops *reg)nf_queue_nf_hook_drop (net);nf_hook_entries_free (p); } + +void nf_unregister_net_hook (struct net *net,const struct nf_hook_ops *reg) +{ +if (reg->pf ==NFPROTO_INET ) { +__nf_unregister_net_hook (net,NFPROTO_IPV4 , reg); +__nf_unregister_net_hook (net,NFPROTO_IPV6 , reg); + }else { +__nf_unregister_net_hook (net, reg->pf, reg); + } +}EXPORT_SYMBOL (nf_unregister_net_hook); +int nf_register_net_hook (struct net *net,const struct nf_hook_ops *reg) +{ +int err; + +if (reg->pf ==NFPROTO_INET ) { + err =__nf_register_net_hook (net,NFPROTO_IPV4 , reg); +if (err <0 ) +return err; + + err =__nf_register_net_hook (net,NFPROTO_IPV6 , reg); +if (err <0 ) { +__nf_unregister_net_hook (net,NFPROTO_IPV4 , reg); +return err; + } + }else { + err =__nf_register_net_hook (net, reg->pf, reg); +if (err <0 ) +return err; + } + +return 0 ; +} +EXPORT_SYMBOL (nf_register_net_hook); +int nf_register_net_hooks (struct net *net,const struct nf_hook_ops *reg,unsigned int n) {
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH v2 5/7 netfilter: nf_tables_inet: don't use multihook infrastructure anymore
In reply to Pablo Neira AyusoUse new native NFPROTO_INET support in netfilter core, this gets rid of ad-hoc code in the nf_tables API codebase.
--- include/net/netfilter/nf_tables_ipv4.h | 2 - include/net/netfilter/nf_tables_ipv6.h | 2 - net/ipv4/netfilter/nf_tables_ipv4.c | 3 +- net/ipv6/netfilter/nf_tables_ipv6.c | 3 +- net/netfilter/nf_tables_inet.c | 70 ++++++++++++++++++++++++++++------ 5 files changed, 60 insertions(+), 20 deletions(-)
include/net/netfilter/nf_tables_ipv4.h +0 -2
@@ -53,6 +53,4 @@ static inline void nft_set_pktinfo_ipv4_validate(struct nft_pktinfo *pkt, nft_set_pktinfo_unspec(pkt, skb); } -extern struct nft_af_info nft_af_ipv4; -#endif
include/net/netfilter/nf_tables_ipv6.h +0 -2
@@ -69,6 +69,4 @@ static inline void nft_set_pktinfo_ipv6_validate(struct nft_pktinfo *pkt, nft_set_pktinfo_unspec(pkt, skb); } -extern struct nft_af_info nft_af_ipv6; -#endif
net/ipv4/netfilter/nf_tables_ipv4.c +1 -2
@@ -45,7 +45,7 @@ static unsigned int nft_ipv4_output(void *priv,return nft_do_chain_ipv4 (priv, skb, state); } -struct nft_af_info nft_af_ipv4__read_mostly = { +static struct nft_af_info nft_af_ipv4__read_mostly = { .family =NFPROTO_IPV4 , .nhooks =NF_INET_NUMHOOKS , .owner =THIS_MODULE ,
@@ -58,7 +58,6 @@ struct nft_af_info nft_af_ipv4 __read_mostly = { [NF_INET_POST_ROUTING] = nft_do_chain_ipv4, }, }; -EXPORT_SYMBOL_GPL (nft_af_ipv4);static int nf_tables_ipv4_init_net (struct net *net) {
net/ipv6/netfilter/nf_tables_ipv6.c +1 -2
@@ -42,7 +42,7 @@ static unsigned int nft_ipv6_output(void *priv,return nft_do_chain_ipv6 (priv, skb, state); } -struct nft_af_info nft_af_ipv6__read_mostly = { +static struct nft_af_info nft_af_ipv6__read_mostly = { .family =NFPROTO_IPV6 , .nhooks =NF_INET_NUMHOOKS , .owner =THIS_MODULE ,
@@ -55,7 +55,6 @@ struct nft_af_info nft_af_ipv6 __read_mostly = { [NF_INET_POST_ROUTING] = nft_do_chain_ipv6, }, }; -EXPORT_SYMBOL_GPL (nft_af_ipv6);static int nf_tables_ipv6_init_net (struct net *net) {
net/netfilter/nf_tables_inet.c +58 -12
90 lines not on this page · raw message
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH v2 6/7 netfilter: nf_tables: remove multihook chains and families
In reply to Pablo Neira AyusoSince NFPROTO_INET is handled from the core, we don't need to maintain extra infrastructure in nf_tables to handle the double hook registration, one for IPv4 and another for IPv6.
--- include/net/netfilter/nf_tables.h | 9 +-- 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 | 102 ++++++++++++++------------------ net/netfilter/nf_tables_inet.c | 1 - net/netfilter/nf_tables_netdev.c | 3 +- net/netfilter/nft_compat.c | 8 +-- 9 files changed, 49 insertions(+), 78 deletions(-)
include/net/netfilter/nf_tables.h +1 -8
@@ -902,8 +902,6 @@ struct nft_stats {struct u64_stats_sync syncp; }; -#define NFT_HOOK_OPS_MAX 2 -/** * struct nft_base_chain - nf_tables base chain *
@@ -915,7 +913,7 @@ struct nft_stats {* @dev_name: device name that this base chain is attached to (if any) */ struct nft_base_chain { -struct nf_hook_ops ops[NFT_HOOK_OPS_MAX ]; +struct nf_hook_ops ops;const struct nf_chain_type *type;u8 policy;u8 flags;
@@ -976,8 +974,6 @@ enum nft_af_flags {* @owner: module owner * @tables: used internally * @flags: family flags -* @nops: number of hook ops in this family -* @hook_ops_init: initialization function for chain hook ops * @hooks: hookfn overrides for packet validation */ struct nft_af_info {
@@ -987,9 +983,6 @@ struct nft_af_info {struct module *owner;struct list_head tables;u32 flags; -unsigned int nops; -void (*hook_ops_init)(struct nf_hook_ops *, -unsigned int );nf_hookfn *hooks[NF_MAX_HOOKS ]; };
net/bridge/netfilter/nf_tables_bridge.c +0 -1
@@ -46,7 +46,6 @@ static struct nft_af_info nft_af_bridge __read_mostly = { .family = NFPROTO_BRIDGE, .nhooks = NF_BR_NUMHOOKS, .owner = THIS_MODULE, - .nops = 1, .hooks = { [NF_BR_PRE_ROUTING] = nft_do_chain_bridge, [NF_BR_LOCAL_IN] = nft_do_chain_bridge,
net/ipv4/netfilter/nf_tables_arp.c +0 -1
@@ -31,7 +31,6 @@ static struct nft_af_info nft_af_arp __read_mostly = { .family = NFPROTO_ARP, .nhooks = NF_ARP_NUMHOOKS, .owner = THIS_MODULE, - .nops = 1, .hooks = { [NF_ARP_IN] = nft_do_chain_arp, [NF_ARP_OUT] = nft_do_chain_arp,
net/ipv4/netfilter/nf_tables_ipv4.c +0 -1
@@ -49,7 +49,6 @@ static struct nft_af_info nft_af_ipv4 __read_mostly = { .family = NFPROTO_IPV4, .nhooks = NF_INET_NUMHOOKS, .owner = THIS_MODULE, - .nops = 1, .hooks = { [NF_INET_LOCAL_IN] = nft_do_chain_ipv4, [NF_INET_LOCAL_OUT] = nft_ipv4_output,
net/ipv6/netfilter/nf_tables_ipv6.c +0 -1
@@ -46,7 +46,6 @@ static struct nft_af_info nft_af_ipv6 __read_mostly = { .family = NFPROTO_IPV6, .nhooks = NF_INET_NUMHOOKS, .owner = THIS_MODULE, - .nops = 1, .hooks = { [NF_INET_LOCAL_IN] = nft_do_chain_ipv6, [NF_INET_LOCAL_OUT] = nft_ipv6_output,
net/netfilter/nf_tables_api.c +43 -59
216 lines not on this page · raw message
net/netfilter/nf_tables_inet.c +0 -1
@@ -74,7 +74,6 @@ static struct nft_af_info nft_af_inet __read_mostly = { .family = NFPROTO_INET, .nhooks = NF_INET_NUMHOOKS, .owner = THIS_MODULE, - .nops = 1, .hooks = { [NF_INET_LOCAL_IN] = nft_do_chain_inet, [NF_INET_LOCAL_OUT] = nft_inet_output,
net/netfilter/nf_tables_netdev.c +1 -2
@@ -43,7 +43,6 @@ static struct nft_af_info nft_af_netdev __read_mostly = { .nhooks = NF_NETDEV_NUMHOOKS, .owner = THIS_MODULE, .flags = NFT_AF_NEEDS_DEV, - .nops = 1, .hooks = { [NF_NETDEV_INGRESS] = nft_do_chain_netdev, },
@@ -98,7 +97,7 @@ static void nft_netdev_event(unsigned long event, struct net_device *dev,__nft_release_basechain (ctx);break ;case NETDEV_CHANGENAME : -if (dev->ifindex != basechain->ops[0 ].dev->ifindex) +if (dev->ifindex != basechain->ops.dev->ifindex)return ;strncpy (basechain->dev_name, dev->name,IFNAMSIZ );
net/netfilter/nft_compat.c +4 -4
@@ -169,7 +169,7 @@ nft_target_set_tgchk_param(struct xt_tgchk_param *par,if (nft_is_base_chain (ctx->chain)) {const struct nft_base_chain *basechain =nft_base_chain (ctx->chain); -const struct nf_hook_ops *ops = &basechain->ops[0 ]; +const struct nf_hook_ops *ops = &basechain->ops; par->hook_mask =1 << ops->hooknum; }else {
@@ -302,7 +302,7 @@ static int nft_target_validate(const struct nft_ctx *ctx,if (nft_is_base_chain (ctx->chain)) {const struct nft_base_chain *basechain =nft_base_chain (ctx->chain); -const struct nf_hook_ops *ops = &basechain->ops[0 ]; +const struct nf_hook_ops *ops = &basechain->ops; hook_mask =1 << ops->hooknum;if (target->hooks && !(hook_mask & target->hooks))
@@ -383,7 +383,7 @@ nft_match_set_mtchk_param(struct xt_mtchk_param *par, const struct nft_ctx *ctx,if (nft_is_base_chain (ctx->chain)) {const struct nft_base_chain *basechain =nft_base_chain (ctx->chain); -const struct nf_hook_ops *ops = &basechain->ops[0 ]; +const struct nf_hook_ops *ops = &basechain->ops; par->hook_mask =1 << ops->hooknum; }else {
@@ -481,7 +481,7 @@ static int nft_match_validate(const struct nft_ctx *ctx,if (nft_is_base_chain (ctx->chain)) {const struct nft_base_chain *basechain =nft_base_chain (ctx->chain); -const struct nf_hook_ops *ops = &basechain->ops[0 ]; +const struct nf_hook_ops *ops = &basechain->ops; hook_mask =1 << ops->hooknum;if (match->hooks && !(hook_mask & match->hooks))
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH v2 7/7 netfilter: nf_tables: remove hooks from family definition
In reply to Pablo Neira AyusoThey don't belong to the family definition, move them to the filter chain type definition instead.
--- include/net/netfilter/nf_tables.h | 4 +--- net/bridge/netfilter/nf_tables_bridge.c | 14 +++++++------- net/ipv4/netfilter/nf_tables_arp.c | 8 ++++---- net/ipv4/netfilter/nf_tables_ipv4.c | 14 +++++++------- net/ipv6/netfilter/nf_tables_ipv6.c | 14 +++++++------- net/netfilter/nf_tables_api.c | 6 +----- net/netfilter/nf_tables_inet.c | 14 +++++++------- net/netfilter/nf_tables_netdev.c | 6 +++--- 8 files changed, 37 insertions(+), 43 deletions(-)
include/net/netfilter/nf_tables.h +1 -3
@@ -880,7 +880,7 @@ enum nft_chain_type {* @family: address family * @owner: module owner * @hook_mask: mask of valid hooks -* @hooks: hookfn overrides +* @hooks: array of hook functions */ struct nf_chain_type {const char *name;
@@ -974,7 +974,6 @@ enum nft_af_flags {* @owner: module owner * @tables: used internally * @flags: family flags -* @hooks: hookfn overrides for packet validation */ struct nft_af_info {struct list_head list;
@@ -983,7 +982,6 @@ struct nft_af_info {struct module *owner;struct list_head tables;u32 flags; -nf_hookfn *hooks[NF_MAX_HOOKS ]; };int nft_register_afinfo (struct net *,struct nft_af_info *);
net/bridge/netfilter/nf_tables_bridge.c +7 -7
@@ -46,13 +46,6 @@ static struct nft_af_info nft_af_bridge __read_mostly = { .family = NFPROTO_BRIDGE, .nhooks = NF_BR_NUMHOOKS, .owner = THIS_MODULE, - .hooks = { - [NF_BR_PRE_ROUTING] = nft_do_chain_bridge, - [NF_BR_LOCAL_IN] = nft_do_chain_bridge, - [NF_BR_FORWARD] = nft_do_chain_bridge, - [NF_BR_LOCAL_OUT] = nft_do_chain_bridge, - [NF_BR_POST_ROUTING] = nft_do_chain_bridge, - }, };static int nf_tables_bridge_init_net (struct net *net)
@@ -93,6 +86,13 @@ static const struct nf_chain_type filter_bridge = { (1 <<NF_BR_FORWARD ) | (1 <<NF_BR_LOCAL_OUT ) | (1 << NF_BR_POST_ROUTING), + .hooks = { + [NF_BR_PRE_ROUTING] = nft_do_chain_bridge, + [NF_BR_LOCAL_IN] = nft_do_chain_bridge, + [NF_BR_FORWARD] = nft_do_chain_bridge, + [NF_BR_LOCAL_OUT] = nft_do_chain_bridge, + [NF_BR_POST_ROUTING] = nft_do_chain_bridge, + }, }; static void nf_br_saveroute(const struct sk_buff *skb,
net/ipv4/netfilter/nf_tables_arp.c +4 -4
@@ -31,10 +31,6 @@ static struct nft_af_info nft_af_arp __read_mostly = { .family = NFPROTO_ARP, .nhooks = NF_ARP_NUMHOOKS, .owner = THIS_MODULE, - .hooks = { - [NF_ARP_IN] = nft_do_chain_arp, - [NF_ARP_OUT] = nft_do_chain_arp, - }, };static int nf_tables_arp_init_net (struct net *net)
@@ -72,6 +68,10 @@ static const struct nf_chain_type filter_arp = { .owner = THIS_MODULE, .hook_mask = (1 << NF_ARP_IN) | (1 << NF_ARP_OUT), + .hooks = { + [NF_ARP_IN] = nft_do_chain_arp, + [NF_ARP_OUT] = nft_do_chain_arp, + }, };static int __init nf_tables_arp_init (void )
net/ipv4/netfilter/nf_tables_ipv4.c +7 -7
@@ -49,13 +49,6 @@ static struct nft_af_info nft_af_ipv4 __read_mostly = { .family = NFPROTO_IPV4, .nhooks = NF_INET_NUMHOOKS, .owner = THIS_MODULE, - .hooks = { - [NF_INET_LOCAL_IN] = nft_do_chain_ipv4, - [NF_INET_LOCAL_OUT] = nft_ipv4_output, - [NF_INET_FORWARD] = nft_do_chain_ipv4, - [NF_INET_PRE_ROUTING] = nft_do_chain_ipv4, - [NF_INET_POST_ROUTING] = nft_do_chain_ipv4, - }, };static int nf_tables_ipv4_init_net (struct net *net)
@@ -96,6 +89,13 @@ static const struct nf_chain_type filter_ipv4 = { (1 <<NF_INET_FORWARD ) | (1 <<NF_INET_PRE_ROUTING ) | (1 << NF_INET_POST_ROUTING), + .hooks = { + [NF_INET_LOCAL_IN] = nft_do_chain_ipv4, + [NF_INET_LOCAL_OUT] = nft_ipv4_output, + [NF_INET_FORWARD] = nft_do_chain_ipv4, + [NF_INET_PRE_ROUTING] = nft_do_chain_ipv4, + [NF_INET_POST_ROUTING] = nft_do_chain_ipv4, + }, };static int __init nf_tables_ipv4_init (void )
net/ipv6/netfilter/nf_tables_ipv6.c +7 -7
@@ -46,13 +46,6 @@ static struct nft_af_info nft_af_ipv6 __read_mostly = { .family = NFPROTO_IPV6, .nhooks = NF_INET_NUMHOOKS, .owner = THIS_MODULE, - .hooks = { - [NF_INET_LOCAL_IN] = nft_do_chain_ipv6, - [NF_INET_LOCAL_OUT] = nft_ipv6_output, - [NF_INET_FORWARD] = nft_do_chain_ipv6, - [NF_INET_PRE_ROUTING] = nft_do_chain_ipv6, - [NF_INET_POST_ROUTING] = nft_do_chain_ipv6, - }, };static int nf_tables_ipv6_init_net (struct net *net)
@@ -93,6 +86,13 @@ static const struct nf_chain_type filter_ipv6 = { (1 <<NF_INET_FORWARD ) | (1 <<NF_INET_PRE_ROUTING ) | (1 << NF_INET_POST_ROUTING), + .hooks = { + [NF_INET_LOCAL_IN] = nft_do_chain_ipv6, + [NF_INET_LOCAL_OUT] = nft_ipv6_output, + [NF_INET_FORWARD] = nft_do_chain_ipv6, + [NF_INET_PRE_ROUTING] = nft_do_chain_ipv6, + [NF_INET_POST_ROUTING] = nft_do_chain_ipv6, + }, };static int __init nf_tables_ipv6_init (void )
net/netfilter/nf_tables_api.c +1 -5
@@ -1357,7 +1357,6 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask,if (nla[NFTA_CHAIN_HOOK ]) {struct nft_chain_hook hook;struct nf_hook_ops *ops; -nf_hookfn *hookfn; err =nft_chain_parse_hook (net, nla, afi, &hook, create);if (err <0 )
@@ -1383,7 +1382,6 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask,static_branch_inc (&nft_counters_enabled); } - hookfn = hook.type->hooks[hook.num]; basechain->type = hook.type; chain = &basechain->chain;
@@ -1392,10 +1390,8 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask, ops->hooknum = hook.num; ops->priority = hook.priority; ops->priv = chain; - ops->hook = afi->hooks[ops->hooknum]; + ops->hook = hook.type->hooks[ops->hooknum]; ops->dev = hook.dev; -if (hookfn) - ops->hook = hookfn;if (basechain->type->type ==NFT_CHAIN_T_NAT ) ops->nat_hook = true;
net/netfilter/nf_tables_inet.c +7 -7
@@ -74,13 +74,6 @@ static struct nft_af_info nft_af_inet __read_mostly = { .family = NFPROTO_INET, .nhooks = NF_INET_NUMHOOKS, .owner = THIS_MODULE, - .hooks = { - [NF_INET_LOCAL_IN] = nft_do_chain_inet, - [NF_INET_LOCAL_OUT] = nft_inet_output, - [NF_INET_FORWARD] = nft_do_chain_inet, - [NF_INET_PRE_ROUTING] = nft_do_chain_inet, - [NF_INET_POST_ROUTING] = nft_do_chain_inet, - }, };static int __net_init nf_tables_inet_init_net (struct net *net)
@@ -121,6 +114,13 @@ static const struct nf_chain_type filter_inet = { (1 <<NF_INET_FORWARD ) | (1 <<NF_INET_PRE_ROUTING ) | (1 << NF_INET_POST_ROUTING), + .hooks = { + [NF_INET_LOCAL_IN] = nft_do_chain_inet, + [NF_INET_LOCAL_OUT] = nft_inet_output, + [NF_INET_FORWARD] = nft_do_chain_inet, + [NF_INET_PRE_ROUTING] = nft_do_chain_inet, + [NF_INET_POST_ROUTING] = nft_do_chain_inet, + }, };static int __init nf_tables_inet_init (void )
net/netfilter/nf_tables_netdev.c +3 -3
@@ -43,9 +43,6 @@ static struct nft_af_info nft_af_netdev __read_mostly = { .nhooks = NF_NETDEV_NUMHOOKS, .owner = THIS_MODULE, .flags = NFT_AF_NEEDS_DEV, - .hooks = { - [NF_NETDEV_INGRESS] = nft_do_chain_netdev, - }, };static int nf_tables_netdev_init_net (struct net *net)
@@ -82,6 +79,9 @@ static const struct nf_chain_type nft_filter_chain_netdev = { .family = NFPROTO_NETDEV, .owner = THIS_MODULE, .hook_mask = (1 << NF_NETDEV_INGRESS), + .hooks = { + [NF_NETDEV_INGRESS] = nft_do_chain_netdev, + }, }; static void nft_netdev_event(unsigned long event, struct net_device *dev,
Signature · 1 line
2.11.0