Netfilter/IPVS updates for net-next
Subsystems (9)
Pablo Neira Ayuso
maintainercover Netfilter/IPVS updates for net-next
Hi David,
The following patchset contains Netfilter updates for net-next:
1) Remove the broute pseudo hook, implement this from the bridge prerouting hook instead. Now broute becomes real table in ebtables, from Florian Westphal. This also includes a size reduction patch for the bridge control buffer area via squashing boolean into bitfields and a selftest.
2) Add OS passive fingerprint version matching, from Fernando Fernandez.
3) Support for gue encapsulation for IPVS, from Jacky Hu.
4) Add support for NAT to the inet family, from Florian Westphal. This includes support for masquerade, redirect and nat extensions.
5) Skip interface lookup in flowtable, use device in the dst object.
6) Add jiffies64_to_msecs() and use it, from Li RongQing.
7) Remove unused parameter in nf_tables_set_desc_parse(), from Colin Ian King.
8) Statify several functions, patches from YueHaibing and Florian Westphal.
9) Add an optimized version of nf_inet_addr_cmp(), from Li RongQing.
10) Merge route extension to core, also from Florian.
11) Use IS_ENABLED(CONFIG_NF_NAT) instead of NF_NAT_NEEDED, from Florian.
12) Merge ip/ip6 masquerade extensions, from Florian. This includes netdevice notifier unification.
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git
Thanks!
----------------------------------------------------------------
The following changes since commit ed514fc5615d7688b7c227a76863e98a92fb0d54:
cxgb4: Don't return EAGAIN when TCAM is full. (2019-04-08 10:01:50 -0700)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git HEAD
for you to fetch changes up to dc2f4189dcd2c87e211d30d9524ae8ebe19af577:
bridge: only include nf_queue.h if needed (2019-04-15 18:47:36 +0200)
----------------------------------------------------------------
Colin Ian King (1):
netfilter: nf_tables: remove unused parameter ctx
Fernando Fernandez Mancera (1):
netfilter: nft_osf: Add version option support
Florian Westphal (14):
netfilter: nat: add inet family nat support
netfilter: nf_tables: merge route type into core
netfilter: replace NF_NAT_NEEDED with IS_ENABLED(CONFIG_NF_NAT)
netfilter: nft_masq: add inet support
netfilter: nft_redir: add inet support
kselftests: extend nft_nat with inet family based nat hooks
netfilter: make two functions static
netfilter: nf_nat: merge ip/ip6 masquerade headers
netfilter: x_tables: merge ip and ipv6 masquerade modules
netfilter: nf_nat_masquerade: unify ipv4/6 notifier registration
selftests: netfilter: add ebtables broute test case
bridge: reduce size of input cb to 16 bytes
bridge: netfilter: unroll NF_HOOK helper in bridge input path
bridge: broute: make broute a real ebtables table
Jacky Hu (1):
ipvs: allow tunneling with gue encapsulation
Li RongQing (2):
time: Introduce jiffies64_to_msecs()
netfilter: optimize nf_inet_addr_cmp
Pablo Neira Ayuso (1):
netfilter: nf_flowtable: skip device lookup from interface index
Stephen Rothwell (1):
bridge: only include nf_queue.h if needed
YueHaibing (1):
netfilter: nft_redir: Make nft_redir_dump static
include/linux/if_bridge.h | 3 -
include/linux/jiffies.h | 1 +
include/linux/netfilter.h | 9 +-
include/linux/netfilter/nfnetlink_osf.h | 11 +-
include/linux/netfilter/x_tables.h | 1 -
include/linux/netfilter_ipv6.h | 15 ++
include/net/ip_vs.h | 5 +
include/net/netfilter/ipv4/nf_nat_masquerade.h | 15 --
include/net/netfilter/ipv6/nf_nat_masquerade.h | 11 --
include/net/netfilter/nf_conntrack_expect.h | 2 +-
include/net/netfilter/nf_nat.h | 7 +-
include/net/netfilter/nf_nat_masquerade.h | 19 +++
include/net/netfilter/nf_queue.h | 3 +
include/net/netfilter/nf_tables.h | 4 +-
include/uapi/linux/ip_vs.h | 11 ++
include/uapi/linux/netfilter/nf_tables.h | 6 +
kernel/time/time.c | 10 ++
net/bridge/br_arp_nd_proxy.c | 18 +--
net/bridge/br_input.c | 77 +++++++---
net/bridge/br_private.h | 15 +-
net/bridge/netfilter/ebtable_broute.c | 63 +++++---
net/bridge/netfilter/ebtables.c | 7 +-
net/ipv4/netfilter/Kconfig | 20 +--
net/ipv4/netfilter/Makefile | 2 -
net/ipv4/netfilter/nft_chain_route_ipv4.c | 89 -----------
net/ipv6/netfilter/Kconfig | 19 +--
net/ipv6/netfilter/Makefile | 2 -
net/ipv6/netfilter/ip6t_MASQUERADE.c | 81 ----------
net/ipv6/netfilter/nft_chain_route_ipv6.c | 91 -----------
net/netfilter/Kconfig | 19 ++-
net/netfilter/Makefile | 4 +-
net/netfilter/core.c | 1 +
net/netfilter/ipvs/ip_vs_ctl.c | 35 ++++-
net/netfilter/ipvs/ip_vs_xmit.c | 84 +++++++++-
net/netfilter/nf_conntrack_expect.c | 2 +-
net/netfilter/nf_conntrack_netlink.c | 16 +-
net/netfilter/nf_conntrack_sip.c | 2 +-
net/netfilter/nf_flow_table_ip.c | 10 +-
net/netfilter/nf_internals.h | 3 -
net/netfilter/nf_nat_core.c | 16 +-
net/netfilter/nf_nat_masquerade.c | 104 +++++--------
net/netfilter/nf_nat_proto.c | 59 ++++---
net/netfilter/nf_queue.c | 1 +
net/netfilter/nf_tables_api.c | 16 +-
net/netfilter/nfnetlink_osf.c | 14 +-
net/netfilter/nft_chain_nat.c | 36 +++++
net/netfilter/nft_chain_route.c | 169 +++++++++++++++++++++
net/netfilter/nft_masq.c | 83 ++++++++--
net/netfilter/nft_nat.c | 58 ++++++-
net/netfilter/nft_osf.c | 30 +++-
net/netfilter/nft_redir.c | 63 +++++++-
net/netfilter/x_tables.c | 3 +-
.../ipt_MASQUERADE.c => netfilter/xt_MASQUERADE.c} | 84 ++++++----
net/openvswitch/conntrack.c | 18 +--
tools/testing/selftests/netfilter/Makefile | 2 +-
.../testing/selftests/netfilter/bridge_brouter.sh | 146 ++++++++++++++++++
tools/testing/selftests/netfilter/nft_nat.sh | 130 +++++++++++-----
57 files changed, 1187 insertions(+), 638 deletions(-)
delete mode 100644 include/net/netfilter/ipv4/nf_nat_masquerade.h
delete mode 100644 include/net/netfilter/ipv6/nf_nat_masquerade.h
create mode 100644 include/net/netfilter/nf_nat_masquerade.h
delete mode 100644 net/ipv4/netfilter/nft_chain_route_ipv4.c
delete mode 100644 net/ipv6/netfilter/ip6t_MASQUERADE.c
delete mode 100644 net/ipv6/netfilter/nft_chain_route_ipv6.c
create mode 100644 net/netfilter/nft_chain_route.c
rename net/{ipv4/netfilter/ipt_MASQUERADE.c => netfilter/xt_MASQUERADE.c} (52%)
create mode 100755 tools/testing/selftests/netfilter/bridge_brouter.shPablo Neira Ayuso
maintainerPATCH 1/22 time: Introduce jiffies64_to_msecs()
From: Li RongQing <[email protected]>
there is a similar helper in net/netfilter/nf_tables_api.c, this maybe become a common request someday, so move it to time.c
--- include/linux/jiffies.h | 1 + kernel/time/time.c | 10 ++++++++++ net/netfilter/nf_tables_api.c | 4 +--- 3 files changed, 12 insertions(+), 3 deletions(-)
include/linux/jiffies.h +1 -0
@@ -297,6 +297,7 @@ static inline u64 jiffies_to_nsecs(const unsigned long j) }extern u64 jiffies64_to_nsecs (u64 j); +extern u64 jiffies64_to_msecs (u64 j);extern unsigned long __msecs_to_jiffies (const unsigned int m);#if HZ <=MSEC_PER_SEC && !(MSEC_PER_SEC %HZ )
kernel/time/time.c +10 -0
@@ -783,6 +783,16 @@ u64 jiffies64_to_nsecs(u64 j) }EXPORT_SYMBOL (jiffies64_to_nsecs); +u64 jiffies64_to_msecs (const u64 j) +{ +#if HZ <=MSEC_PER_SEC && !(MSEC_PER_SEC %HZ ) +return (MSEC_PER_SEC /HZ ) * j; +#else +return div_u64 (j *HZ_TO_MSEC_NUM ,HZ_TO_MSEC_DEN ); +#endif +} +EXPORT_SYMBOL (jiffies64_to_msecs); +/** * nsecs_to_jiffies64 - Convert nsecs in u64 to jiffies64 *
net/netfilter/nf_tables_api.c +1 -3
@@ -3193,9 +3193,7 @@ static int nf_msecs_to_jiffies64(const struct nlattr *nla, u64 *result)static __be64 nf_jiffies64_to_msecs (u64 input) { -u64 ms =jiffies64_to_nsecs (input); - -return cpu_to_be64 (div_u64 (ms,NSEC_PER_MSEC )); +return cpu_to_be64 (jiffies64_to_msecs (input)); } static int nf_tables_fill_set(struct sk_buff *skb, const struct nft_ctx *ctx,
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 2/22 netfilter: nf_tables: remove unused parameter ctx
In reply to Pablo Neira AyusoFrom: Colin Ian King <[email protected]>
Function nf_tables_set_desc_parse parameter ctx is not being used so remove it as it is redundant.
--- net/netfilter/nf_tables_api.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
net/netfilter/nf_tables_api.c +2 -3
@@ -3436,8 +3436,7 @@ static int nf_tables_getset(struct net *net, struct sock *nlsk,return err; } -static int nf_tables_set_desc_parse (const struct nft_ctx *ctx, -struct nft_set_desc *desc, +static int nf_tables_set_desc_parse (struct nft_set_desc *desc,const struct nlattr *nla) {struct nlattr *da[NFTA_SET_DESC_MAX +1 ];
@@ -3563,7 +3562,7 @@ static int nf_tables_newset(struct net *net, struct sock *nlsk, policy =ntohl (nla_get_be32 (nla[NFTA_SET_POLICY ]));if (nla[NFTA_SET_DESC ] !=NULL ) { - err =nf_tables_set_desc_parse (&ctx, &desc, nla[NFTA_SET_DESC ]); + err =nf_tables_set_desc_parse (&desc, nla[NFTA_SET_DESC ]);if (err <0 )return err; }
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 3/22 netfilter: nft_redir: Make nft_redir_dump static
In reply to Pablo Neira AyusoFrom: YueHaibing <[email protected]>
Fix sparse warning:
net/netfilter/nft_redir.c:85:5:
warning: symbol 'nft_redir_dump' was not declared. Should it be static?
--- net/netfilter/nft_redir.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nft_redir.c +1 -1
@@ -82,7 +82,7 @@ static int nft_redir_init(const struct nft_ctx *ctx,return nf_ct_netns_get (ctx->net, ctx->family); } -int nft_redir_dump (struct sk_buff *skb,const struct nft_expr *expr) +static int nft_redir_dump (struct sk_buff *skb,const struct nft_expr *expr) {const struct nft_redir *priv =nft_expr_priv (expr);
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 4/22 netfilter: nf_flowtable: skip device lookup from interface index
In reply to Pablo Neira AyusoUse the output device from the route that we cache in the flowtable entry.
--- net/netfilter/nf_flow_table_ip.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
net/netfilter/nf_flow_table_ip.c +2 -8
@@ -235,13 +235,10 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb,if (tuplehash ==NULL )return NF_ACCEPT ; - outdev =dev_get_by_index_rcu (state->net, tuplehash->tuple.oifidx); -if (!outdev) -return NF_ACCEPT ; - dir = tuplehash->tuple.dir; flow = container_of(tuplehash, struct flow_offload, tuplehash[dir]); rt = (struct rtable *)flow->tuplehash[dir].tuple.dst_cache; + outdev = rt->dst.dev;if (unlikely (nf_flow_exceeds_mtu (skb, flow->tuplehash[dir].tuple.mtu)) && (ip_hdr (skb)->frag_off &htons (IP_DF )) !=0 )
@@ -452,13 +449,10 @@ nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb,if (tuplehash ==NULL )return NF_ACCEPT ; - outdev =dev_get_by_index_rcu (state->net, tuplehash->tuple.oifidx); -if (!outdev) -return NF_ACCEPT ; - dir = tuplehash->tuple.dir; flow = container_of(tuplehash, struct flow_offload, tuplehash[dir]); rt = (struct rt6_info *)flow->tuplehash[dir].tuple.dst_cache; + outdev = rt->dst.dev;if (unlikely (nf_flow_exceeds_mtu (skb, flow->tuplehash[dir].tuple.mtu)))return NF_ACCEPT ;
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 5/22 ipvs: allow tunneling with gue encapsulation
In reply to Pablo Neira AyusoFrom: Jacky Hu <[email protected]>
ipip packets are blocked in some public cloud environments, this patch allows gue encapsulation with the tunneling method, which would make tunneling working in those environments.
--- include/net/ip_vs.h | 5 +++ include/uapi/linux/ip_vs.h | 11 ++++++ net/netfilter/ipvs/ip_vs_ctl.c | 35 ++++++++++++++++- net/netfilter/ipvs/ip_vs_xmit.c | 84 +++++++++++++++++++++++++++++++++++++++-- 4 files changed, 130 insertions(+), 5 deletions(-)
include/net/ip_vs.h +5 -0
@@ -600,6 +600,9 @@ struct ip_vs_dest_user_kern {/* Address family of addr */ u16 af; + +u16 tun_type;/* tunnel type */ +__be16 tun_port;/* tunnel port */ };
@@ -660,6 +663,8 @@ struct ip_vs_dest {atomic_t conn_flags;/* flags to copy to conn */ atomic_t weight;/* server weight */ atomic_t last_weight;/* server latest weight */ +__u16 tun_type;/* tunnel type */ +__be16 tun_port;/* tunnel port */ refcount_t refcnt;/* reference counter */ struct ip_vs_stats stats;/* statistics */
include/uapi/linux/ip_vs.h +11 -0
@@ -124,6 +124,13 @@#define IP_VS_PEDATA_MAXLEN 255 +/* Tunnel types */ +enum { +IP_VS_CONN_F_TUNNEL_TYPE_IPIP =0 ,/* IPIP */ +IP_VS_CONN_F_TUNNEL_TYPE_GUE ,/* GUE */ +IP_VS_CONN_F_TUNNEL_TYPE_MAX , +}; +/* * The struct ip_vs_service_user and struct ip_vs_dest_user are * used to set IPVS rules through setsockopt.
@@ -392,6 +399,10 @@ enum {IPVS_DEST_ATTR_STATS64 ,/* nested attribute for dest stats */ +IPVS_DEST_ATTR_TUN_TYPE ,/* tunnel type */ + +IPVS_DEST_ATTR_TUN_PORT ,/* tunnel port */ + __IPVS_DEST_ATTR_MAX, };
net/netfilter/ipvs/ip_vs_ctl.c +34 -1
@@ -831,6 +831,10 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest, conn_flags = udest->conn_flags &IP_VS_CONN_F_DEST_MASK ; conn_flags |=IP_VS_CONN_F_INACTIVE ; +/* set the tunnel info */ + dest->tun_type = udest->tun_type; + dest->tun_port = udest->tun_port; +/* set the IP_VS_CONN_F_NOOUTPUT flag if not masquerading/NAT */ if ((conn_flags &IP_VS_CONN_F_FWD_MASK ) !=IP_VS_CONN_F_MASQ ) { conn_flags |=IP_VS_CONN_F_NOOUTPUT ;
@@ -987,6 +991,13 @@ ip_vs_add_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)return -ERANGE ; } +if (udest->tun_type ==IP_VS_CONN_F_TUNNEL_TYPE_GUE ) { +if (udest->tun_port ==0 ) { +pr_err ("%s(): tunnel port is zero\n" , __func__); +return -EINVAL ; + } + } +ip_vs_addr_copy (udest->af, &daddr, &udest->addr);/* We use function that requires RCU lock */
@@ -1051,6 +1062,13 @@ ip_vs_edit_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)return -ERANGE ; } +if (udest->tun_type ==IP_VS_CONN_F_TUNNEL_TYPE_GUE ) { +if (udest->tun_port ==0 ) { +pr_err ("%s(): tunnel port is zero\n" , __func__); +return -EINVAL ; + } + } +ip_vs_addr_copy (udest->af, &daddr, &udest->addr);/* We use function that requires RCU lock */
@@ -2333,6 +2351,7 @@ static void ip_vs_copy_udest_compat(struct ip_vs_dest_user_kern *udest, udest->u_threshold = udest_compat->u_threshold; udest->l_threshold = udest_compat->l_threshold; udest->af =AF_INET ; + udest->tun_type =IP_VS_CONN_F_TUNNEL_TYPE_IPIP ; } static int
@@ -2890,6 +2909,8 @@ static const struct nla_policy ip_vs_dest_policy[IPVS_DEST_ATTR_MAX + 1] = { [IPVS_DEST_ATTR_PERSIST_CONNS] = { .type = NLA_U32 }, [IPVS_DEST_ATTR_STATS] = { .type = NLA_NESTED }, [IPVS_DEST_ATTR_ADDR_FAMILY] = { .type = NLA_U16 }, + [IPVS_DEST_ATTR_TUN_TYPE] = { .type = NLA_U8 }, + [IPVS_DEST_ATTR_TUN_PORT] = { .type = NLA_U16 }, }; static int ip_vs_genl_fill_stats(struct sk_buff *skb, int container_type,
@@ -3193,6 +3214,10 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest) IP_VS_CONN_F_FWD_MASK)) ||nla_put_u32 (skb,IPVS_DEST_ATTR_WEIGHT ,atomic_read (&dest->weight)) || +nla_put_u8 (skb,IPVS_DEST_ATTR_TUN_TYPE , + dest->tun_type) || +nla_put_be16 (skb,IPVS_DEST_ATTR_TUN_PORT , + dest->tun_port) ||nla_put_u32 (skb,IPVS_DEST_ATTR_U_THRESH , dest->u_threshold) ||nla_put_u32 (skb,IPVS_DEST_ATTR_L_THRESH , dest->l_threshold) || nla_put_u32(skb, IPVS_DEST_ATTR_ACTIVE_CONNS,
@@ -3315,12 +3340,14 @@ static int ip_vs_genl_parse_dest(struct ip_vs_dest_user_kern *udest,/* If a full entry was requested, check for the additional fields */ if (full_entry) {struct nlattr *nla_fwd, *nla_weight, *nla_u_thresh, - *nla_l_thresh; + *nla_l_thresh, *nla_tun_type, *nla_tun_port; nla_fwd = attrs[IPVS_DEST_ATTR_FWD_METHOD ]; nla_weight = attrs[IPVS_DEST_ATTR_WEIGHT ]; nla_u_thresh = attrs[IPVS_DEST_ATTR_U_THRESH ]; nla_l_thresh = attrs[IPVS_DEST_ATTR_L_THRESH ]; + nla_tun_type = attrs[IPVS_DEST_ATTR_TUN_TYPE ]; + nla_tun_port = attrs[IPVS_DEST_ATTR_TUN_PORT ];if (!(nla_fwd && nla_weight && nla_u_thresh && nla_l_thresh))return -EINVAL ;
@@ -3330,6 +3357,12 @@ static int ip_vs_genl_parse_dest(struct ip_vs_dest_user_kern *udest, udest->weight =nla_get_u32 (nla_weight); udest->u_threshold =nla_get_u32 (nla_u_thresh); udest->l_threshold =nla_get_u32 (nla_l_thresh); + +if (nla_tun_type) + udest->tun_type =nla_get_u8 (nla_tun_type); + +if (nla_tun_port) + udest->tun_port =nla_get_be16 (nla_tun_port); }return 0 ;
net/netfilter/ipvs/ip_vs_xmit.c +80 -4
167 lines not on this page · raw message
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 6/22 netfilter: optimize nf_inet_addr_cmp
In reply to Pablo Neira AyusoFrom: Li RongQing <[email protected]>
optimize nf_inet_addr_cmp by 64bit xor computation similar to ipv6_addr_equal()
--- include/linux/netfilter.h | 7 +++++++ 1 file changed, 7 insertions(+)
include/linux/netfilter.h +7 -0
@@ -24,10 +24,17 @@ static inline int NF_DROP_GETERR(int verdict)static inline int nf_inet_addr_cmp (const union nf_inet_addr *a1,const union nf_inet_addr *a2) { +#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS ) &&BITS_PER_LONG ==64 +const unsigned long *ul1 = (const unsigned long *)a1; +const unsigned long *ul2 = (const unsigned long *)a2; + +return ((ul1[0 ] ^ ul2[0 ]) | (ul1[1 ] ^ ul2[1 ])) ==0UL ; +#else return a1->all[0 ] == a2->all[0 ] && a1->all[1 ] == a2->all[1 ] && a1->all[2 ] == a2->all[2 ] && a1->all[3 ] == a2->all[3 ]; +#endif } static inline void nf_inet_addr_mask(const union nf_inet_addr *a1,
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 7/22 netfilter: nat: add inet family nat support
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
We need minimal support from the nat core for this, as we do not want to register additional base hooks.
When an inet hook is registered, interally register ipv4 and ipv6 hooks for them and unregister those when inet hooks are removed.
--- include/net/netfilter/nf_nat.h | 7 +++-- net/netfilter/nf_nat_core.c | 16 +++++------- net/netfilter/nf_nat_proto.c | 43 ++++++++++++++++++++++++++----- net/netfilter/nft_chain_nat.c | 36 ++++++++++++++++++++++++++ net/netfilter/nft_nat.c | 58 ++++++++++++++++++++++++++++++++++++++++-- 5 files changed, 141 insertions(+), 19 deletions(-)
include/net/netfilter/nf_nat.h +5 -2
@@ -69,9 +69,9 @@ static inline bool nf_nat_oif_changed(unsigned int hooknum,#endif } -int nf_nat_register_fn (struct net *net,const struct nf_hook_ops *ops, +int nf_nat_register_fn (struct net *net,u8 pf,const struct nf_hook_ops *ops,const struct nf_hook_ops *nat_ops,unsigned int ops_count); -void nf_nat_unregister_fn (struct net *net,const struct nf_hook_ops *ops, +void nf_nat_unregister_fn (struct net *net,u8 pf,const struct nf_hook_ops *ops,unsigned int ops_count); unsigned int nf_nat_packet(struct nf_conn *ct, enum ip_conntrack_info ctinfo,
@@ -98,6 +98,9 @@ void nf_nat_ipv4_unregister_fn(struct net *net, const struct nf_hook_ops *ops);int nf_nat_ipv6_register_fn (struct net *net,const struct nf_hook_ops *ops);void nf_nat_ipv6_unregister_fn (struct net *net,const struct nf_hook_ops *ops); +int nf_nat_inet_register_fn (struct net *net,const struct nf_hook_ops *ops); +void nf_nat_inet_unregister_fn (struct net *net,const struct nf_hook_ops *ops); +unsigned int nf_nat_inet_fn (void *priv,struct sk_buff *skb,const struct nf_hook_state *state);
net/netfilter/nf_nat_core.c +7 -9
@@ -1009,7 +1009,7 @@ static struct nf_ct_helper_expectfn follow_master_nat = { .expectfn = nf_nat_follow_master, }; -int nf_nat_register_fn (struct net *net,const struct nf_hook_ops *ops, +int nf_nat_register_fn (struct net *net,u8 pf,const struct nf_hook_ops *ops,const struct nf_hook_ops *orig_nat_ops,unsigned int ops_count) {struct nat_net *nat_net =net_generic (net, nat_net_id);
@@ -1019,14 +1019,12 @@ int nf_nat_register_fn(struct net *net, const struct nf_hook_ops *ops,struct nf_hook_ops *nat_ops;int i, ret; -if (WARN_ON_ONCE (ops->pf >=ARRAY_SIZE (nat_net->nat_proto_net))) +if (WARN_ON_ONCE (pf >=ARRAY_SIZE (nat_net->nat_proto_net)))return -EINVAL ; - nat_proto_net = &nat_net->nat_proto_net[ops->pf]; + nat_proto_net = &nat_net->nat_proto_net[pf];for (i =0 ; i < ops_count; i++) { -if (WARN_ON (orig_nat_ops[i].pf != ops->pf)) -return -EINVAL ;if (orig_nat_ops[i].hooknum == hooknum) { hooknum = i;break ;
@@ -1086,8 +1084,8 @@ int nf_nat_register_fn(struct net *net, const struct nf_hook_ops *ops,return ret; } -void nf_nat_unregister_fn (struct net *net,const struct nf_hook_ops *ops, -unsigned int ops_count) +void nf_nat_unregister_fn (struct net *net,u8 pf,const struct nf_hook_ops *ops, +unsigned int ops_count) {struct nat_net *nat_net =net_generic (net, nat_net_id);struct nf_nat_hooks_net *nat_proto_net;
@@ -1096,10 +1094,10 @@ void nf_nat_unregister_fn(struct net *net, const struct nf_hook_ops *ops,int hooknum = ops->hooknum;int i; -if (ops->pf >=ARRAY_SIZE (nat_net->nat_proto_net)) +if (pf >=ARRAY_SIZE (nat_net->nat_proto_net))return ; - nat_proto_net = &nat_net->nat_proto_net[ops->pf]; + nat_proto_net = &nat_net->nat_proto_net[pf];mutex_lock (&nf_nat_proto_mutex);if (WARN_ON (nat_proto_net->users ==0 ))
net/netfilter/nf_nat_proto.c +37 -6
78 lines not on this page · raw message
net/netfilter/nft_chain_nat.c +36 -0
@@ -74,6 +74,36 @@ static const struct nft_chain_type nft_chain_nat_ipv6 = { };#endif +#ifdef CONFIG_NF_TABLES_INET +static int nft_nat_inet_reg (struct net *net,const struct nf_hook_ops *ops) +{ +return nf_nat_inet_register_fn (net, ops); +} + +static void nft_nat_inet_unreg (struct net *net,const struct nf_hook_ops *ops) +{ +nf_nat_inet_unregister_fn (net, ops); +} + +static const struct nft_chain_type nft_chain_nat_inet = { + .name ="nat" , + .type =NFT_CHAIN_T_NAT , + .family =NFPROTO_INET , + .hook_mask = (1 <<NF_INET_PRE_ROUTING ) | + (1 <<NF_INET_LOCAL_IN ) | + (1 <<NF_INET_LOCAL_OUT ) | + (1 <<NF_INET_POST_ROUTING ), + .hooks = { + [NF_INET_PRE_ROUTING ] = nft_nat_do_chain, + [NF_INET_LOCAL_IN ] = nft_nat_do_chain, + [NF_INET_LOCAL_OUT ] = nft_nat_do_chain, + [NF_INET_POST_ROUTING ] = nft_nat_do_chain, + }, + .ops_register = nft_nat_inet_reg, + .ops_unregister = nft_nat_inet_unreg, +}; +#endif +static int __init nft_chain_nat_init (void ) {#ifdef CONFIG_NF_TABLES_IPV6
@@ -82,6 +112,9 @@ static int __init nft_chain_nat_init(void)#ifdef CONFIG_NF_TABLES_IPV4 nft_register_chain_type (&nft_chain_nat_ipv4);#endif +#ifdef CONFIG_NF_TABLES_INET +nft_register_chain_type (&nft_chain_nat_inet); +#endif return 0 ; }
@@ -94,6 +127,9 @@ static void __exit nft_chain_nat_exit(void)#ifdef CONFIG_NF_TABLES_IPV6 nft_unregister_chain_type (&nft_chain_nat_ipv6);#endif +#ifdef CONFIG_NF_TABLES_INET +nft_unregister_chain_type (&nft_chain_nat_inet); +#endif }module_init (nft_chain_nat_init);
net/netfilter/nft_nat.c +56 -2
76 lines not on this page · raw message
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 8/22 netfilter: nf_tables: merge route type into core
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
very little code, so it really doesn't make sense to have extra modules or even a kconfig knob for this.
Merge them and make functionality available unconditionally. The merge makes inet family route support trivial, so add it as well here.
Before:
text data bss dec hex filename
835 832 0 1667 683 nft_chain_route_ipv4.ko
870 832 0 1702 6a6 nft_chain_route_ipv6.ko111568 2556 529 114653 1bfdd nf_tables.ko
After:
text data bss dec hex filename 113133 2556 529 116218 1c5fa nf_tables.ko
--- include/linux/netfilter_ipv6.h | 15 +++ include/net/netfilter/nf_tables.h | 2 + net/ipv4/netfilter/Kconfig | 8 -- net/ipv4/netfilter/Makefile | 1 - net/ipv4/netfilter/nft_chain_route_ipv4.c | 89 ---------------- net/ipv6/netfilter/Kconfig | 8 -- net/ipv6/netfilter/Makefile | 1 - net/ipv6/netfilter/nft_chain_route_ipv6.c | 91 ---------------- net/netfilter/Makefile | 3 +- net/netfilter/nf_nat_proto.c | 16 +-- net/netfilter/nf_tables_api.c | 2 + net/netfilter/nft_chain_route.c | 169 ++++++++++++++++++++++++++++++ 12 files changed, 191 insertions(+), 214 deletions(-) delete mode 100644 net/ipv4/netfilter/nft_chain_route_ipv4.c delete mode 100644 net/ipv6/netfilter/nft_chain_route_ipv6.c create mode 100644 net/netfilter/nft_chain_route.c
include/linux/netfilter_ipv6.h +15 -0
@@ -87,6 +87,21 @@ static inline int nf_ip6_route(struct net *net, struct dst_entry **dst, }int ip6_route_me_harder (struct net *net,struct sk_buff *skb); + +static inline int nf_ip6_route_me_harder (struct net *net,struct sk_buff *skb) +{ +#if IS_MODULE (CONFIG_IPV6 ) +const struct nf_ipv6_ops *v6_ops =nf_get_ipv6_ops (); + +if (!v6_ops) +return -EHOSTUNREACH ; + +return v6_ops->route_me_harder (net, skb); +#else +return ip6_route_me_harder (net, skb); +#endif +} +__sum16 nf_ip6_checksum (struct sk_buff *skb,unsigned int hook,unsigned int dataoff,u_int8_t protocol);
include/net/netfilter/nf_tables.h +2 -0
@@ -1411,4 +1411,6 @@ struct nft_trans_flowtable {int __init nft_chain_filter_init (void );void nft_chain_filter_fini (void ); +void __init nft_chain_route_init (void ); +void nft_chain_route_fini (void );#endif /* _NET_NF_TABLES_H */
net/ipv4/netfilter/Kconfig +0 -8
@@ -27,14 +27,6 @@ config NF_TABLES_IPV4 if NF_TABLES_IPV4 -config NFT_CHAIN_ROUTE_IPV4 - tristate "IPv4 nf_tables route chain support" - help - This option enables the "route" chain for IPv4 in nf_tables. This - chain type is used to force packet re-routing after mangling header - fields such as the source, destination, type of service and - the packet mark. - config NFT_REJECT_IPV4 select NF_REJECT_IPV4 default NFT_REJECT
net/ipv4/netfilter/Makefile +0 -1
@@ -24,7 +24,6 @@ nf_nat_snmp_basic-y := nf_nat_snmp_basic.asn1.o nf_nat_snmp_basic_main.o $(obj)/nf_nat_snmp_basic_main.o: $(obj)/nf_nat_snmp_basic.asn1.h obj-$(CONFIG_NF_NAT_SNMP_BASIC) += nf_nat_snmp_basic.o -obj-$(CONFIG_NFT_CHAIN_ROUTE_IPV4) += nft_chain_route_ipv4.o obj-$(CONFIG_NFT_REJECT_IPV4) += nft_reject_ipv4.o obj-$(CONFIG_NFT_FIB_IPV4) += nft_fib_ipv4.o obj-$(CONFIG_NFT_DUP_IPV4) += nft_dup_ipv4.o
net/ipv4/netfilter/nft_chain_route_ipv4.c deleted +0 -89
89 lines not on this page · raw message
net/ipv6/netfilter/Kconfig +0 -8
@@ -23,14 +23,6 @@ config NF_TABLES_IPV6 if NF_TABLES_IPV6 -config NFT_CHAIN_ROUTE_IPV6 - tristate "IPv6 nf_tables route chain support" - help - This option enables the "route" chain for IPv6 in nf_tables. This - chain type is used to force packet re-routing after mangling header - fields such as the source, destination, flowlabel, hop-limit and - the packet mark. - config NFT_REJECT_IPV6 select NF_REJECT_IPV6 default NFT_REJECT
net/ipv6/netfilter/Makefile +0 -1
@@ -27,7 +27,6 @@ obj-$(CONFIG_NF_REJECT_IPV6) += nf_reject_ipv6.o obj-$(CONFIG_NF_DUP_IPV6) += nf_dup_ipv6.o # nf_tables -obj-$(CONFIG_NFT_CHAIN_ROUTE_IPV6) += nft_chain_route_ipv6.o obj-$(CONFIG_NFT_REJECT_IPV6) += nft_reject_ipv6.o obj-$(CONFIG_NFT_DUP_IPV6) += nft_dup_ipv6.o obj-$(CONFIG_NFT_FIB_IPV6) += nft_fib_ipv6.o
net/ipv6/netfilter/nft_chain_route_ipv6.c deleted +0 -91
91 lines not on this page · raw message
net/netfilter/Makefile +2 -1
@@ -77,7 +77,8 @@ obj-$(CONFIG_NF_DUP_NETDEV) += nf_dup_netdev.o nf_tables-objs := nf_tables_core.o nf_tables_api.o nft_chain_filter.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 nft_meta.o nft_rt.o nft_exthdr.o + nft_dynset.o nft_meta.o nft_rt.o nft_exthdr.o \ + nft_chain_route.o nf_tables_set-objs := nf_tables_set_core.o \ nft_set_hash.o nft_set_bitmap.o nft_set_rbtree.o
net/netfilter/nf_nat_proto.c +1 -15
@@ -926,20 +926,6 @@ nf_nat_ipv6_out(void *priv, struct sk_buff *skb,return ret; } -static int nat_route_me_harder (struct net *net,struct sk_buff *skb) -{ -#ifdef CONFIG_IPV6_MODULE -const struct nf_ipv6_ops *v6_ops =nf_get_ipv6_ops (); - -if (!v6_ops) -return -EHOSTUNREACH ; - -return v6_ops->route_me_harder (net, skb); -#else -return ip6_route_me_harder (net, skb); -#endif -} -static unsigned int nf_nat_ipv6_local_fn (void *priv,struct sk_buff *skb,const struct nf_hook_state *state)
@@ -959,7 +945,7 @@ nf_nat_ipv6_local_fn(void *priv, struct sk_buff *skb,if (!nf_inet_addr_cmp (&ct->tuplehash[dir].tuple.dst.u3, &ct->tuplehash[!dir].tuple.src.u3)) { - err =nat_route_me_harder (state->net, skb); + err =nf_ip6_route_me_harder (state->net, skb);if (err <0 ) ret =NF_DROP_ERR (err); }
net/netfilter/nf_tables_api.c +2 -0
@@ -7530,6 +7530,7 @@ static int __init nf_tables_module_init(void)if (err <0 ) goto err5; +nft_chain_route_init ();return err; err5:rhltable_destroy (&nft_objname_ht);
@@ -7549,6 +7550,7 @@ static void __exit nf_tables_module_exit(void)nfnetlink_subsys_unregister (&nf_tables_subsys);unregister_netdevice_notifier (&nf_tables_flowtable_notifier);nft_chain_filter_fini (); +nft_chain_route_fini ();unregister_pernet_subsys (&nf_tables_net_ops);cancel_work_sync (&trans_destroy_work);rcu_barrier ();
net/netfilter/nft_chain_route.c new file +169 -0
169 lines not on this page · raw message
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 9/22 netfilter: replace NF_NAT_NEEDED with IS_ENABLED(CONFIG_NF_NAT)
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
NF_NAT_NEEDED is true whenever nat support for either ipv4 or ipv6 is enabled. Now that the af-specific nat configuration switches have been removed, IS_ENABLED(CONFIG_NF_NAT) has the same effect.
--- include/linux/netfilter.h | 2 +- include/net/netfilter/nf_conntrack_expect.h | 2 +- net/netfilter/Kconfig | 5 ----- net/netfilter/nf_conntrack_expect.c | 2 +- net/netfilter/nf_conntrack_netlink.c | 16 ++++++++-------- net/netfilter/nf_conntrack_sip.c | 2 +- net/openvswitch/conntrack.c | 18 +++++++++--------- 7 files changed, 21 insertions(+), 26 deletions(-)
include/linux/netfilter.h +1 -1
@@ -367,7 +367,7 @@ extern struct nf_nat_hook __rcu *nf_nat_hook;static inline void nf_nat_decode_session (struct sk_buff *skb,struct flowi *fl,u_int8_t family) { -#ifdef CONFIG_NF_NAT_NEEDED +#if IS_ENABLED (CONFIG_NF_NAT )struct nf_nat_hook *nat_hook;rcu_read_lock ();
include/net/netfilter/nf_conntrack_expect.h +1 -1
@@ -48,7 +48,7 @@ struct nf_conntrack_expect {/* Expectation class */ unsigned int class; -#ifdef CONFIG_NF_NAT_NEEDED +#if IS_ENABLED (CONFIG_NF_NAT )union nf_inet_addr saved_addr;/* This is the original per-proto part, used to map the * expected connection the way the recipient expects. */
net/netfilter/Kconfig +0 -5
@@ -404,11 +404,6 @@ config NF_NAT forms of full Network Address Port Translation. This can be controlled by iptables, ip6tables or nft. -config NF_NAT_NEEDED - bool - depends on NF_NAT - default y - config NF_NAT_AMANDA tristate depends on NF_CONNTRACK && NF_NAT
net/netfilter/nf_conntrack_expect.c +1 -1
@@ -336,7 +336,7 @@ void nf_ct_expect_init(struct nf_conntrack_expect *exp, unsigned int class, exp->tuple.dst.u.all = *dst; -#ifdef CONFIG_NF_NAT_NEEDED +#if IS_ENABLED (CONFIG_NF_NAT )memset (&exp->saved_addr,0 ,sizeof (exp->saved_addr));memset (&exp->saved_proto,0 ,sizeof (exp->saved_proto));#endif
net/netfilter/nf_conntrack_netlink.c +8 -8
@@ -45,7 +45,7 @@#include <net/netfilter/nf_conntrack_timestamp.h> #include <net/netfilter/nf_conntrack_labels.h> #include <net/netfilter/nf_conntrack_synproxy.h> -#ifdef CONFIG_NF_NAT_NEEDED +#if IS_ENABLED (CONFIG_NF_NAT )#include <net/netfilter/nf_nat.h> #include <net/netfilter/nf_nat_helper.h> #endif
@@ -655,7 +655,7 @@ static size_t ctnetlink_nlmsg_size(const struct nf_conn *ct) +nla_total_size (0 )/* CTA_HELP */ +nla_total_size (NF_CT_HELPER_NAME_LEN )/* CTA_HELP_NAME */ + ctnetlink_secctx_size(ct) -#ifdef CONFIG_NF_NAT_NEEDED +#if IS_ENABLED (CONFIG_NF_NAT ) +2 *nla_total_size (0 )/* CTA_NAT_SEQ_ADJ_ORIG|REPL */ + 6 * nla_total_size(sizeof(u_int32_t)) /* CTA_NAT_SEQ_OFFSET */#endif
@@ -1494,7 +1494,7 @@ static int ctnetlink_get_ct_unconfirmed(struct net *net, struct sock *ctnl,return -EOPNOTSUPP ; } -#ifdef CONFIG_NF_NAT_NEEDED +#if IS_ENABLED (CONFIG_NF_NAT ) static int ctnetlink_parse_nat_setup(struct nf_conn *ct, enum nf_nat_manip_type manip,
@@ -1586,7 +1586,7 @@ ctnetlink_change_status(struct nf_conn *ct, const struct nlattr * const cda[])static int ctnetlink_setup_nat (struct nf_conn *ct,const struct nlattr *const cda[]) { -#ifdef CONFIG_NF_NAT_NEEDED +#if IS_ENABLED (CONFIG_NF_NAT )int ret;if (!cda[CTA_NAT_DST ] && !cda[CTA_NAT_SRC ])
@@ -2369,7 +2369,7 @@ ctnetlink_glue_build_size(const struct nf_conn *ct) +nla_total_size (0 )/* CTA_HELP */ +nla_total_size (NF_CT_HELPER_NAME_LEN )/* CTA_HELP_NAME */ + ctnetlink_secctx_size(ct) -#ifdef CONFIG_NF_NAT_NEEDED +#if IS_ENABLED (CONFIG_NF_NAT ) +2 *nla_total_size (0 )/* CTA_NAT_SEQ_ADJ_ORIG|REPL */ + 6 * nla_total_size(sizeof(u_int32_t)) /* CTA_NAT_SEQ_OFFSET */#endif
@@ -2699,7 +2699,7 @@ ctnetlink_exp_dump_expect(struct sk_buff *skb,struct nf_conn *master = exp->master;long timeout = ((long )exp->timeout.expires - (long )jiffies) /HZ ;struct nf_conn_help *help; -#ifdef CONFIG_NF_NAT_NEEDED +#if IS_ENABLED (CONFIG_NF_NAT )struct nlattr *nest_parms;struct nf_conntrack_tuple nat_tuple = {};#endif
@@ -2717,7 +2717,7 @@ ctnetlink_exp_dump_expect(struct sk_buff *skb, CTA_EXPECT_MASTER) < 0) goto nla_put_failure; -#ifdef CONFIG_NF_NAT_NEEDED +#if IS_ENABLED (CONFIG_NF_NAT )if (!nf_inet_addr_cmp (&exp->saved_addr, &any_addr) || exp->saved_proto.all) { nest_parms =nla_nest_start (skb,CTA_EXPECT_NAT |NLA_F_NESTED );
@@ -3180,7 +3180,7 @@ ctnetlink_parse_expect_nat(const struct nlattr *attr, struct nf_conntrack_expect *exp, u_int8_t u3) { -#ifdef CONFIG_NF_NAT_NEEDED +#if IS_ENABLED (CONFIG_NF_NAT )struct nlattr *tb[CTA_EXPECT_NAT_MAX +1 ];struct nf_conntrack_tuple nat_tuple = {};int err;
net/netfilter/nf_conntrack_sip.c +1 -1
@@ -928,7 +928,7 @@ static int set_expected_rtp_rtcp(struct sk_buff *skb, unsigned int protoff,nfct_help (exp->master)->helper !=nfct_help (ct)->helper || exp->class != class) break; -#ifdef CONFIG_NF_NAT_NEEDED +#if IS_ENABLED (CONFIG_NF_NAT ) if (!direct_rtp && (!nf_inet_addr_cmp(&exp->saved_addr, &exp->tuple.dst.u3) || exp->saved_proto.udp.port != exp->tuple.dst.u.udp.port) &&
net/openvswitch/conntrack.c +9 -9
@@ -29,7 +29,7 @@#include <net/netfilter/ipv6/nf_defrag_ipv6.h> #include <net/ipv6_frag.h> -#ifdef CONFIG_NF_NAT_NEEDED +#if IS_ENABLED (CONFIG_NF_NAT )#include <net/netfilter/nf_nat.h> #endif
@@ -75,7 +75,7 @@ struct ovs_conntrack_info {struct md_mark mark;struct md_labels labels;char timeout[CTNL_TIMEOUT_NAME_MAX ]; -#ifdef CONFIG_NF_NAT_NEEDED +#if IS_ENABLED (CONFIG_NF_NAT )struct nf_nat_range2 range;/* Only present for SRC NAT and DST NAT. */ #endif };
@@ -721,7 +721,7 @@ static bool skb_nfct_cached(struct net *net,return ct_executed; } -#ifdef CONFIG_NF_NAT_NEEDED +#if IS_ENABLED (CONFIG_NF_NAT )/* Modelled after nf_nat_ipv[46]_fn(). * range is only used for new, uninitialized NAT state. * Returns either NF_ACCEPT or NF_DROP.
@@ -903,7 +903,7 @@ static int ovs_ct_nat(struct net *net, struct sw_flow_key *key,return err; } -#else /* !CONFIG_NF_NAT_NEEDED */ +#else /* !CONFIG_NF_NAT */ static int ovs_ct_nat(struct net *net, struct sw_flow_key *key, const struct ovs_conntrack_info *info, struct sk_buff *skb, struct nf_conn *ct,
@@ -1330,7 +1330,7 @@ static int ovs_ct_add_helper(struct ovs_conntrack_info *info, const char *name,return 0 ; } -#ifdef CONFIG_NF_NAT_NEEDED +#if IS_ENABLED (CONFIG_NF_NAT )static int parse_nat (const struct nlattr *attr,struct ovs_conntrack_info *info,bool log) {
@@ -1467,7 +1467,7 @@ static const struct ovs_ct_len_tbl ovs_ct_attr_lens[OVS_CT_ATTR_MAX + 1] = { .maxlen = sizeof(struct md_labels) }, [OVS_CT_ATTR_HELPER] = { .minlen = 1, .maxlen = NF_CT_HELPER_NAME_LEN }, -#ifdef CONFIG_NF_NAT_NEEDED +#if IS_ENABLED (CONFIG_NF_NAT ) /* NAT length is checked when parsing the nested attributes. */ [OVS_CT_ATTR_NAT] = { .minlen = 0, .maxlen = INT_MAX },#endif
@@ -1547,7 +1547,7 @@ static int parse_ct(const struct nlattr *attr, struct ovs_conntrack_info *info,return -EINVAL ; }break ; -#ifdef CONFIG_NF_NAT_NEEDED +#if IS_ENABLED (CONFIG_NF_NAT )case OVS_CT_ATTR_NAT : {int err =parse_nat (a, info, log);
@@ -1677,7 +1677,7 @@ int ovs_ct_copy_action(struct net *net, const struct nlattr *attr,return err; } -#ifdef CONFIG_NF_NAT_NEEDED +#if IS_ENABLED (CONFIG_NF_NAT )static bool ovs_ct_nat_to_attr (const struct ovs_conntrack_info *info,struct sk_buff *skb) {
@@ -1783,7 +1783,7 @@ int ovs_ct_action_to_attr(const struct ovs_conntrack_info *ct_info,return -EMSGSIZE ; } -#ifdef CONFIG_NF_NAT_NEEDED +#if IS_ENABLED (CONFIG_NF_NAT )if (ct_info->nat && !ovs_ct_nat_to_attr (ct_info, skb))return -EMSGSIZE ;#endif
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 10/22 netfilter: nft_masq: add inet support
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
This allows use of a single masquerade rule in nat inet family to handle both ipv4 and ipv6.
--- net/netfilter/nft_masq.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+)
net/netfilter/nft_masq.c +64 -0
@@ -218,6 +218,61 @@ static inline int nft_masq_module_init_ipv6(void) { return 0; }static inline void nft_masq_module_exit_ipv6 (void ) {}#endif +#ifdef CONFIG_NF_TABLES_INET +static void nft_masq_inet_eval (const struct nft_expr *expr, +struct nft_regs *regs, +const struct nft_pktinfo *pkt) +{ +switch (nft_pf (pkt)) { +case NFPROTO_IPV4 : +return nft_masq_ipv4_eval (expr, regs, pkt); +case NFPROTO_IPV6 : +return nft_masq_ipv6_eval (expr, regs, pkt); + } + +WARN_ON_ONCE (1 ); +} + +static void +nft_masq_inet_destroy (const struct nft_ctx *ctx,const struct nft_expr *expr) +{ +nf_ct_netns_put (ctx->net,NFPROTO_INET ); +} + +static struct nft_expr_type nft_masq_inet_type; +static const struct nft_expr_ops nft_masq_inet_ops = { + .type = &nft_masq_inet_type, + .size =NFT_EXPR_SIZE (sizeof (struct nft_masq )), + .eval = nft_masq_inet_eval, + .init = nft_masq_init, + .destroy = nft_masq_inet_destroy, + .dump = nft_masq_dump, + .validate = nft_masq_validate, +}; + +static struct nft_expr_type nft_masq_inet_type__read_mostly = { + .family =NFPROTO_INET , + .name ="masq" , + .ops = &nft_masq_inet_ops, + .policy = nft_masq_policy, + .maxattr =NFTA_MASQ_MAX , + .owner =THIS_MODULE , +}; + +static int __init nft_masq_module_init_inet (void ) +{ +return nft_register_expr (&nft_masq_inet_type); +} + +static void nft_masq_module_exit_inet (void ) +{ +nft_unregister_expr (&nft_masq_inet_type); +} +#else +static inline int nft_masq_module_init_inet (void ) {return 0 ; } +static inline void nft_masq_module_exit_inet (void ) {} +#endif +static int __init nft_masq_module_init (void ) {int ret;
@@ -226,8 +281,15 @@ static int __init nft_masq_module_init(void)if (ret <0 )return ret; + ret =nft_masq_module_init_inet (); +if (ret <0 ) { +nft_masq_module_exit_ipv6 (); +return ret; + } + ret =nft_register_expr (&nft_masq_ipv4_type);if (ret <0 ) { +nft_masq_module_exit_inet ();nft_masq_module_exit_ipv6 ();return ret; }
@@ -235,6 +297,7 @@ static int __init nft_masq_module_init(void) ret =nf_nat_masquerade_ipv4_register_notifier ();if (ret <0 ) {nft_masq_module_exit_ipv6 (); +nft_masq_module_exit_inet ();nft_unregister_expr (&nft_masq_ipv4_type);return ret; }
@@ -245,6 +308,7 @@ static int __init nft_masq_module_init(void) static void __exit nft_masq_module_exit(void) {nft_masq_module_exit_ipv6 (); +nft_masq_module_exit_inet ();nft_unregister_expr (&nft_masq_ipv4_type);nf_nat_masquerade_ipv4_unregister_notifier (); }
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 11/22 netfilter: nft_redir: add inet support
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
allows to redirect both ipv4 and ipv6 with a single rule in an inet nat table.
--- net/netfilter/nft_redir.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+)
net/netfilter/nft_redir.c +61 -0
@@ -202,6 +202,55 @@ static struct nft_expr_type nft_redir_ipv6_type __read_mostly = { };#endif +#ifdef CONFIG_NF_TABLES_INET +static void nft_redir_inet_eval (const struct nft_expr *expr, +struct nft_regs *regs, +const struct nft_pktinfo *pkt) +{ +switch (nft_pf (pkt)) { +case NFPROTO_IPV4 : +return nft_redir_ipv4_eval (expr, regs, pkt); +case NFPROTO_IPV6 : +return nft_redir_ipv6_eval (expr, regs, pkt); + } + +WARN_ON_ONCE (1 ); +} + +static void +nft_redir_inet_destroy (const struct nft_ctx *ctx,const struct nft_expr *expr) +{ +nf_ct_netns_put (ctx->net,NFPROTO_INET ); +} + +static struct nft_expr_type nft_redir_inet_type; +static const struct nft_expr_ops nft_redir_inet_ops = { + .type = &nft_redir_inet_type, + .size =NFT_EXPR_SIZE (sizeof (struct nft_redir )), + .eval = nft_redir_inet_eval, + .init = nft_redir_init, + .destroy = nft_redir_inet_destroy, + .dump = nft_redir_dump, + .validate = nft_redir_validate, +}; + +static struct nft_expr_type nft_redir_inet_type__read_mostly = { + .family =NFPROTO_INET , + .name ="redir" , + .ops = &nft_redir_inet_ops, + .policy = nft_redir_policy, + .maxattr =NFTA_MASQ_MAX , + .owner =THIS_MODULE , +}; + +static int __init nft_redir_module_init_inet (void ) +{ +return nft_register_expr (&nft_redir_inet_type); +} +#else +static inline int nft_redir_module_init_inet (void ) {return 0 ; } +#endif +static int __init nft_redir_module_init (void ) {int ret =nft_register_expr (&nft_redir_ipv4_type);
@@ -217,6 +266,15 @@ static int __init nft_redir_module_init(void) }#endif + ret =nft_redir_module_init_inet (); +if (ret <0 ) { +nft_unregister_expr (&nft_redir_ipv4_type); +#ifdef CONFIG_NF_TABLES_IPV6 +nft_unregister_expr (&nft_redir_ipv6_type); +#endif +return ret; + } +return ret; }
@@ -226,6 +284,9 @@ static void __exit nft_redir_module_exit(void)#ifdef CONFIG_NF_TABLES_IPV6 nft_unregister_expr (&nft_redir_ipv6_type);#endif +#ifdef CONFIG_NF_TABLES_INET +nft_unregister_expr (&nft_redir_inet_type); +#endif }module_init (nft_redir_module_init);
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 12/22 kselftests: extend nft_nat with inet family based nat hooks
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
With older nft versions, this will cause:
[..]
PASS: ipv6 ping to ns1 was ip6 NATted to ns2
/dev/stdin:4:30-31: Error: syntax error, unexpected to, expecting newline or semicolon
ip daddr 10.0.1.99 dnat ip to 10.0.2.99
^^SKIP: inet nat tests
PASS: ip IP masquerade for ns2
[..]
as there is currently no way to detect if nft will be able to parse the inet format.
redirect and masquerade tests need to be skipped in this case for inet too because nft userspace has overzealous family check and rejects their use in the inet family.
--- tools/testing/selftests/netfilter/nft_nat.sh | 130 +++++++++++++++++++-------- 1 file changed, 94 insertions(+), 36 deletions(-)
tools/testing/selftests/netfilter/nft_nat.sh +94 -36
@@ -6,6 +6,7 @@ # Kselftest framework requirement - SKIP code is 4. ksft_skip=4 ret=0 +test_inet_nat=true nft --version > /dev/null 2>&1 if [ $? -ne 0 ];then
@@ -141,17 +142,24 @@ reset_counters() test_local_dnat6() { + local family=$1 local lret=0 + local IPF="" + + if [ $family = "inet" ];then + IPF="ip6" + fi + ip netns exec ns0 nft -f - <<EOF -table ip6 nat { +table $family nat { chain output { type nat hook output priority 0; policy accept; - ip6 daddr dead:1::99 dnat to dead:2::99 + ip6 daddr dead:1::99 dnat $IPF to dead:2::99 } } EOF if [ $? -ne 0 ]; then - echo "SKIP: Could not add add ip6 dnat hook" + echo "SKIP: Could not add add $family dnat hook" return $ksft_skip fi
@@ -201,7 +209,7 @@ EOF fi done - test $lret -eq 0 && echo "PASS: ipv6 ping to ns1 was NATted to ns2" + test $lret -eq 0 && echo "PASS: ipv6 ping to ns1 was $family NATted to ns2" ip netns exec ns0 nft flush chain ip6 nat output return $lret
@@ -209,15 +217,32 @@ EOF test_local_dnat() { + local family=$1 local lret=0 -ip netns exec ns0 nft -f - <<EOF -table ip nat { + local IPF="" + + if [ $family = "inet" ];then + IPF="ip" + fi + +ip netns exec ns0 nft -f - <<EOF 2>/dev/null +table $family nat { chain output { type nat hook output priority 0; policy accept; - ip daddr 10.0.1.99 dnat to 10.0.2.99 + ip daddr 10.0.1.99 dnat $IPF to 10.0.2.99 } } EOF + if [ $? -ne 0 ]; then + if [ $family = "inet" ];then + echo "SKIP: inet nat tests" + test_inet_nat=false + return $ksft_skip + fi + echo "SKIP: Could not add add $family dnat hook" + return $ksft_skip + fi + # ping netns1, expect rewrite to netns2 ip netns exec ns0 ping -q -c 1 10.0.1.99 > /dev/null if [ $? -ne 0 ]; then
@@ -264,9 +289,9 @@ EOF fi done - test $lret -eq 0 && echo "PASS: ping to ns1 was NATted to ns2" + test $lret -eq 0 && echo "PASS: ping to ns1 was $family NATted to ns2" - ip netns exec ns0 nft flush chain ip nat output + ip netns exec ns0 nft flush chain $family nat output reset_counters ip netns exec ns0 ping -q -c 1 10.0.1.99 > /dev/null
@@ -313,7 +338,7 @@ EOF fi done - test $lret -eq 0 && echo "PASS: ping to ns1 OK after nat output chain flush" + test $lret -eq 0 && echo "PASS: ping to ns1 OK after $family nat output chain flush" return $lret }
@@ -321,6 +346,7 @@ EOF test_masquerade6() { + local family=$1 local lret=0 ip netns exec ns0 sysctl net.ipv6.conf.all.forwarding=1 > /dev/null
@@ -351,16 +377,21 @@ test_masquerade6() # add masquerading rule ip netns exec ns0 nft -f - <<EOF -table ip6 nat { +table $family nat { chain postrouting { type nat hook postrouting priority 0; policy accept; meta oif veth0 masquerade } } EOF + if [ $? -ne 0 ]; then + echo "SKIP: Could not add add $family masquerade hook" + return $ksft_skip + fi + ip netns exec ns2 ping -q -c 1 dead:1::99 > /dev/null # ping ns2->ns1 if [ $? -ne 0 ] ; then - echo "ERROR: cannot ping ns1 from ns2 with active ipv6 masquerading" + echo "ERROR: cannot ping ns1 from ns2 with active $family masquerading" lret=1 fi
@@ -397,19 +428,20 @@ EOF fi done - ip netns exec ns0 nft flush chain ip6 nat postrouting + ip netns exec ns0 nft flush chain $family nat postrouting if [ $? -ne 0 ]; then - echo "ERROR: Could not flush ip6 nat postrouting" 1>&2 + echo "ERROR: Could not flush $family nat postrouting" 1>&2 lret=1 fi - test $lret -eq 0 && echo "PASS: IPv6 masquerade for ns2" + test $lret -eq 0 && echo "PASS: $family IPv6 masquerade for ns2" return $lret } test_masquerade() { + local family=$1 local lret=0 ip netns exec ns0 sysctl net.ipv4.conf.veth0.forwarding=1 > /dev/null
@@ -440,16 +472,21 @@ test_masquerade() # add masquerading rule ip netns exec ns0 nft -f - <<EOF -table ip nat { +table $family nat { chain postrouting { type nat hook postrouting priority 0; policy accept; meta oif veth0 masquerade } } EOF + if [ $? -ne 0 ]; then + echo "SKIP: Could not add add $family masquerade hook" + return $ksft_skip + fi + ip netns exec ns2 ping -q -c 1 10.0.1.99 > /dev/null # ping ns2->ns1 if [ $? -ne 0 ] ; then - echo "ERROR: cannot ping ns1 from ns2 with active ip masquerading" + echo "ERROR: cannot ping ns1 from ns2 with active $family masquerading" lret=1 fi
@@ -485,19 +522,20 @@ EOF fi done - ip netns exec ns0 nft flush chain ip nat postrouting + ip netns exec ns0 nft flush chain $family nat postrouting if [ $? -ne 0 ]; then - echo "ERROR: Could not flush nat postrouting" 1>&2 + echo "ERROR: Could not flush $family nat postrouting" 1>&2 lret=1 fi - test $lret -eq 0 && echo "PASS: IP masquerade for ns2" + test $lret -eq 0 && echo "PASS: $family IP masquerade for ns2" return $lret } test_redirect6() { + local family=$1 local lret=0 ip netns exec ns0 sysctl net.ipv6.conf.all.forwarding=1 > /dev/null
@@ -527,16 +565,21 @@ test_redirect6() # add redirect rule ip netns exec ns0 nft -f - <<EOF -table ip6 nat { +table $family nat { chain prerouting { type nat hook prerouting priority 0; policy accept; meta iif veth1 meta l4proto icmpv6 ip6 saddr dead:2::99 ip6 daddr dead:1::99 redirect } } EOF + if [ $? -ne 0 ]; then + echo "SKIP: Could not add add $family redirect hook" + return $ksft_skip + fi + ip netns exec ns2 ping -q -c 1 dead:1::99 > /dev/null # ping ns2->ns1 if [ $? -ne 0 ] ; then - echo "ERROR: cannot ping ns1 from ns2 with active ip6 redirect" + echo "ERROR: cannot ping ns1 from ns2 via ipv6 with active $family redirect" lret=1 fi
@@ -560,19 +603,20 @@ EOF fi done - ip netns exec ns0 nft delete table ip6 nat + ip netns exec ns0 nft delete table $family nat if [ $? -ne 0 ]; then - echo "ERROR: Could not delete ip6 nat table" 1>&2 + echo "ERROR: Could not delete $family nat table" 1>&2 lret=1 fi - test $lret -eq 0 && echo "PASS: IPv6 redirection for ns2" + test $lret -eq 0 && echo "PASS: $family IPv6 redirection for ns2" return $lret } test_redirect() { + local family=$1 local lret=0 ip netns exec ns0 sysctl net.ipv4.conf.veth0.forwarding=1 > /dev/null
@@ -603,16 +647,21 @@ test_redirect() # add redirect rule ip netns exec ns0 nft -f - <<EOF -table ip nat { +table $family nat { chain prerouting { type nat hook prerouting priority 0; policy accept; meta iif veth1 ip protocol icmp ip saddr 10.0.2.99 ip daddr 10.0.1.99 redirect } } EOF + if [ $? -ne 0 ]; then + echo "SKIP: Could not add add $family redirect hook" + return $ksft_skip + fi + ip netns exec ns2 ping -q -c 1 10.0.1.99 > /dev/null # ping ns2->ns1 if [ $? -ne 0 ] ; then - echo "ERROR: cannot ping ns1 from ns2 with active ip redirect" + echo "ERROR: cannot ping ns1 from ns2 with active $family ip redirect" lret=1 fi
@@ -637,13 +686,13 @@ EOF fi done - ip netns exec ns0 nft delete table ip nat + ip netns exec ns0 nft delete table $family nat if [ $? -ne 0 ]; then - echo "ERROR: Could not delete nat table" 1>&2 + echo "ERROR: Could not delete $family nat table" 1>&2 lret=1 fi - test $lret -eq 0 && echo "PASS: IP redirection for ns2" + test $lret -eq 0 && echo "PASS: $family IP redirection for ns2" return $lret }
@@ -746,16 +795,25 @@ if [ $ret -eq 0 ];then fi reset_counters -test_local_dnat -test_local_dnat6 +test_local_dnat ip +test_local_dnat6 ip6 +reset_counters +$test_inet_nat && test_local_dnat inet +$test_inet_nat && test_local_dnat6 inet reset_counters -test_masquerade -test_masquerade6 +test_masquerade ip +test_masquerade6 ip6 +reset_counters +$test_inet_nat && test_masquerade inet +$test_inet_nat && test_masquerade6 inet reset_counters -test_redirect -test_redirect6 +test_redirect ip +test_redirect6 ip6 +reset_counters +$test_inet_nat && test_redirect inet +$test_inet_nat && test_redirect6 inet for i in 0 1 2; do ip netns del ns$i;done
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 13/22 netfilter: nft_osf: Add version option support
In reply to Pablo Neira AyusoFrom: Fernando Fernandez Mancera <[email protected]>
Add version option support to the nftables "osf" expression.
--- include/linux/netfilter/nfnetlink_osf.h | 11 ++++++++--- include/uapi/linux/netfilter/nf_tables.h | 6 ++++++ net/netfilter/nfnetlink_osf.c | 14 +++++++------- net/netfilter/nft_osf.c | 30 +++++++++++++++++++++++++----- 4 files changed, 46 insertions(+), 15 deletions(-)
include/linux/netfilter/nfnetlink_osf.h +8 -3
@@ -21,13 +21,18 @@ struct nf_osf_finger { struct nf_osf_user_finger finger; }; +struct nf_osf_data { +const char *genre; +const char *version; +}; +bool nf_osf_match (const struct sk_buff *skb,u_int8_t family,int hooknum,struct net_device *in,struct net_device *out,const struct nf_osf_info *info,struct net *net,const struct list_head *nf_osf_fingers); -const char *nf_osf_find (const struct sk_buff *skb, -const struct list_head *nf_osf_fingers, -const int ttl_check); +bool nf_osf_find (const struct sk_buff *skb, +const struct list_head *nf_osf_fingers, +const int ttl_check,struct nf_osf_data *data);#endif /* _NFOSF_H */
include/uapi/linux/netfilter/nf_tables.h +6 -0
@@ -1522,15 +1522,21 @@ enum nft_flowtable_hook_attributes {* * @NFTA_OSF_DREG: destination register (NLA_U32: nft_registers) * @NFTA_OSF_TTL: Value of the TTL osf option (NLA_U8) +* @NFTA_OSF_FLAGS: flags (NLA_U32) */ enum nft_osf_attributes {NFTA_OSF_UNSPEC ,NFTA_OSF_DREG ,NFTA_OSF_TTL , +NFTA_OSF_FLAGS , __NFTA_OSF_MAX, };#define NFTA_OSF_MAX (__NFTA_OSF_MAX - 1) +enum nft_osf_flags { +NFT_OSF_F_VERSION = (1 <<0 ), +}; +/** * enum nft_device_attributes - nf_tables device netlink attributes *
net/netfilter/nfnetlink_osf.c +7 -7
@@ -255,9 +255,9 @@ nf_osf_match(const struct sk_buff *skb, u_int8_t family, }EXPORT_SYMBOL_GPL (nf_osf_match); -const char *nf_osf_find (const struct sk_buff *skb, -const struct list_head *nf_osf_fingers, -const int ttl_check) +bool nf_osf_find (const struct sk_buff *skb, +const struct list_head *nf_osf_fingers, +const int ttl_check,struct nf_osf_data *data) {const struct iphdr *ip =ip_hdr (skb);const struct nf_osf_user_finger *f;
@@ -265,24 +265,24 @@ const char *nf_osf_find(const struct sk_buff *skb,const struct nf_osf_finger *kf;struct nf_osf_hdr_ctx ctx;const struct tcphdr *tcp; -const char *genre =NULL ;memset (&ctx,0 ,sizeof (ctx)); tcp =nf_osf_hdr_ctx_init (&ctx, skb, ip, opts);if (!tcp) -return NULL ; +return false;list_for_each_entry_rcu (kf, &nf_osf_fingers[ctx.df], finger_entry) { f = &kf->finger;if (!nf_osf_match_one (skb, f, ttl_check, &ctx))continue ; - genre = f->genre; + data->genre = f->genre; + data->version = f->version;break ; } -return genre; +return true; }EXPORT_SYMBOL_GPL (nf_osf_find);
net/netfilter/nft_osf.c +25 -5
@@ -7,11 +7,13 @@struct nft_osf {enum nft_registers dreg:8 ;u8 ttl; +u32 flags; };static const struct nla_policy nft_osf_policy[NFTA_OSF_MAX +1 ] = { [NFTA_OSF_DREG ] = { .type =NLA_U32 }, [NFTA_OSF_TTL ] = { .type =NLA_U8 }, + [NFTA_OSF_FLAGS ] = { .type =NLA_U32 }, }; static void nft_osf_eval(const struct nft_expr *expr, struct nft_regs *regs,
@@ -20,9 +22,10 @@ static void nft_osf_eval(const struct nft_expr *expr, struct nft_regs *regs,struct nft_osf *priv =nft_expr_priv (expr);u32 *dest = ®s->data[priv->dreg];struct sk_buff *skb = pkt->skb; +char os_match[NFT_OSF_MAXGENRELEN +1 ];const struct tcphdr *tcp; +struct nf_osf_data data;struct tcphdr _tcph; -const char *os_name; tcp =skb_header_pointer (skb,ip_hdrlen (skb),sizeof (struct tcphdr ), &_tcph);
@@ -35,11 +38,17 @@ static void nft_osf_eval(const struct nft_expr *expr, struct nft_regs *regs,return ; } - os_name =nf_osf_find (skb, nf_osf_fingers, priv->ttl); -if (!os_name) +if (!nf_osf_find (skb, nf_osf_fingers, priv->ttl, &data)) {strncpy ((char *)dest,"unknown" ,NFT_OSF_MAXGENRELEN ); -else -strncpy ((char *)dest, os_name,NFT_OSF_MAXGENRELEN ); + }else { +if (priv->flags &NFT_OSF_F_VERSION ) +snprintf (os_match,NFT_OSF_MAXGENRELEN ,"%s:%s" , + data.genre, data.version); +else +strlcpy (os_match, data.genre,NFT_OSF_MAXGENRELEN ); + +strncpy ((char *)dest, os_match,NFT_OSF_MAXGENRELEN ); + } } static int nft_osf_init(const struct nft_ctx *ctx,
@@ -47,6 +56,7 @@ static int nft_osf_init(const struct nft_ctx *ctx, const struct nlattr * const tb[]) {struct nft_osf *priv =nft_expr_priv (expr); +u32 flags;int err;u8 ttl;
@@ -57,6 +67,13 @@ static int nft_osf_init(const struct nft_ctx *ctx, priv->ttl = ttl; } +if (tb[NFTA_OSF_FLAGS ]) { + flags =ntohl (nla_get_be32 (tb[NFTA_OSF_FLAGS ])); +if (flags !=NFT_OSF_F_VERSION ) +return -EINVAL ; + priv->flags = flags; + } + priv->dreg =nft_parse_register (tb[NFTA_OSF_DREG ]); err =nft_validate_register_store (ctx, priv->dreg,NULL ,NFT_DATA_VALUE ,NFT_OSF_MAXGENRELEN );
@@ -73,6 +90,9 @@ static int nft_osf_dump(struct sk_buff *skb, const struct nft_expr *expr)if (nla_put_u8 (skb,NFTA_OSF_TTL , priv->ttl)) goto nla_put_failure; +if (nla_put_be32 (skb,NFTA_OSF_FLAGS ,ntohl (priv->flags))) + goto nla_put_failure; +if (nft_dump_register (skb,NFTA_OSF_DREG , priv->dreg)) goto nla_put_failure;
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 14/22 netfilter: make two functions static
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
They have no external callers anymore.
--- include/linux/netfilter/x_tables.h | 1 - include/net/netfilter/nf_tables.h | 2 -- net/netfilter/nf_tables_api.c | 5 ++--- net/netfilter/x_tables.c | 3 +-- 4 files changed, 3 insertions(+), 8 deletions(-)
include/linux/netfilter/x_tables.h +0 -1
@@ -317,7 +317,6 @@ struct xt_table_info *xt_replace_table(struct xt_table *table, int *error);struct xt_match *xt_find_match (u8 af,const char *name,u8 revision); -struct xt_target *xt_find_target (u8 af,const char *name,u8 revision);struct xt_match *xt_request_find_match (u8 af,const char *name,u8 revision);struct xt_target *xt_request_find_target (u8 af,const char *name,u8 revision); int xt_find_revision(u8 af, const char *name, u8 revision, int target,
include/net/netfilter/nf_tables.h +0 -2
@@ -475,8 +475,6 @@ void nf_tables_deactivate_set(const struct nft_ctx *ctx, struct nft_set *set, enum nft_trans_phase phase);int nf_tables_bind_set (const struct nft_ctx *ctx,struct nft_set *set,struct nft_set_binding *binding); -void nf_tables_unbind_set (const struct nft_ctx *ctx,struct nft_set *set, -struct nft_set_binding *binding,bool commit);void nf_tables_destroy_set (const struct nft_ctx *ctx,struct nft_set *set);/**
net/netfilter/nf_tables_api.c +2 -3
@@ -3782,8 +3782,8 @@ int nf_tables_bind_set(const struct nft_ctx *ctx, struct nft_set *set, }EXPORT_SYMBOL_GPL (nf_tables_bind_set); -void nf_tables_unbind_set (const struct nft_ctx *ctx,struct nft_set *set, -struct nft_set_binding *binding,bool event) +static void nf_tables_unbind_set (const struct nft_ctx *ctx,struct nft_set *set, +struct nft_set_binding *binding,bool event) {list_del_rcu (&binding->list);
@@ -3794,7 +3794,6 @@ void nf_tables_unbind_set(const struct nft_ctx *ctx, struct nft_set *set, GFP_KERNEL); } } -EXPORT_SYMBOL_GPL (nf_tables_unbind_set); void nf_tables_deactivate_set(const struct nft_ctx *ctx, struct nft_set *set, struct nft_set_binding *binding,
net/netfilter/x_tables.c +1 -2
@@ -227,7 +227,7 @@ xt_request_find_match(uint8_t nfproto, const char *name, uint8_t revision)EXPORT_SYMBOL_GPL (xt_request_find_match);/* Find target, grabs ref. Returns ERR_PTR() on error. */ -struct xt_target *xt_find_target (u8 af,const char *name,u8 revision) +static struct xt_target *xt_find_target (u8 af,const char *name,u8 revision) {struct xt_target *t;int err = -ENOENT ;
@@ -255,7 +255,6 @@ struct xt_target *xt_find_target(u8 af, const char *name, u8 revision)return ERR_PTR (err); } -EXPORT_SYMBOL (xt_find_target);struct xt_target *xt_request_find_target (u8 af,const char *name,u8 revision) {
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 15/22 netfilter: nf_nat: merge ip/ip6 masquerade headers
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Both are now implemented by nf_nat_masquerade.c, so no need to keep different headers.
--- include/net/netfilter/ipv4/nf_nat_masquerade.h | 15 --------------- include/net/netfilter/ipv6/nf_nat_masquerade.h | 11 ----------- include/net/netfilter/nf_nat_masquerade.h | 21 +++++++++++++++++++++ net/ipv4/netfilter/ipt_MASQUERADE.c | 2 +- net/ipv6/netfilter/ip6t_MASQUERADE.c | 2 +- net/netfilter/nf_nat_masquerade.c | 3 +-- net/netfilter/nft_masq.c | 3 +-- 7 files changed, 25 insertions(+), 32 deletions(-) delete mode 100644 include/net/netfilter/ipv4/nf_nat_masquerade.h delete mode 100644 include/net/netfilter/ipv6/nf_nat_masquerade.h create mode 100644 include/net/netfilter/nf_nat_masquerade.h
include/net/netfilter/ipv4/nf_nat_masquerade.h deleted +0 -15
@@ -1,15 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef _NF_NAT_MASQUERADE_IPV4_H_ -#define _NF_NAT_MASQUERADE_IPV4_H_ - -#include <net/netfilter/nf_nat.h> - -unsigned int -nf_nat_masquerade_ipv4 (struct sk_buff *skb,unsigned int hooknum, -const struct nf_nat_range2 *range, -const struct net_device *out); - -int nf_nat_masquerade_ipv4_register_notifier (void ); -void nf_nat_masquerade_ipv4_unregister_notifier (void ); - -#endif /*_NF_NAT_MASQUERADE_IPV4_H_ */
include/net/netfilter/ipv6/nf_nat_masquerade.h deleted +0 -11
@@ -1,11 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef _NF_NAT_MASQUERADE_IPV6_H_ -#define _NF_NAT_MASQUERADE_IPV6_H_ - -unsigned int -nf_nat_masquerade_ipv6 (struct sk_buff *skb,const struct nf_nat_range2 *range, -const struct net_device *out); -int nf_nat_masquerade_ipv6_register_notifier (void ); -void nf_nat_masquerade_ipv6_unregister_notifier (void ); - -#endif /* _NF_NAT_MASQUERADE_IPV6_H_ */
include/net/netfilter/nf_nat_masquerade.h new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _NF_NAT_MASQUERADE_H_ +#define _NF_NAT_MASQUERADE_H_ + +#include <net/netfilter/nf_nat.h> + +unsigned int +nf_nat_masquerade_ipv4 (struct sk_buff *skb,unsigned int hooknum, +const struct nf_nat_range2 *range, +const struct net_device *out); + +int nf_nat_masquerade_ipv4_register_notifier (void ); +void nf_nat_masquerade_ipv4_unregister_notifier (void ); + +unsigned int +nf_nat_masquerade_ipv6 (struct sk_buff *skb,const struct nf_nat_range2 *range, +const struct net_device *out); +int nf_nat_masquerade_ipv6_register_notifier (void ); +void nf_nat_masquerade_ipv6_unregister_notifier (void ); + +#endif /*_NF_NAT_MASQUERADE_H_ */
net/ipv4/netfilter/ipt_MASQUERADE.c +1 -1
@@ -22,7 +22,7 @@#include <linux/netfilter_ipv4.h> #include <linux/netfilter/x_tables.h> #include <net/netfilter/nf_nat.h> -#include <net/netfilter/ipv4/nf_nat_masquerade.h> +#include <net/netfilter/nf_nat_masquerade.h> MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Netfilter Core Team <[email protected]>" );
net/ipv6/netfilter/ip6t_MASQUERADE.c +1 -1
@@ -19,7 +19,7 @@#include <net/netfilter/nf_nat.h> #include <net/addrconf.h> #include <net/ipv6.h> -#include <net/netfilter/ipv6/nf_nat_masquerade.h> +#include <net/netfilter/nf_nat_masquerade.h> static unsigned int masquerade_tg6 (struct sk_buff *skb,const struct xt_action_param *par)
net/netfilter/nf_nat_masquerade.c +1 -2
@@ -7,8 +7,7 @@#include <linux/netfilter_ipv4.h> #include <linux/netfilter_ipv6.h> -#include <net/netfilter/ipv4/nf_nat_masquerade.h> -#include <net/netfilter/ipv6/nf_nat_masquerade.h> +#include <net/netfilter/nf_nat_masquerade.h> static DEFINE_MUTEX (masq_mutex);static unsigned int masq_refcnt4__read_mostly ;
net/netfilter/nft_masq.c +1 -2
@@ -14,8 +14,7 @@#include <linux/netfilter/nf_tables.h> #include <net/netfilter/nf_tables.h> #include <net/netfilter/nf_nat.h> -#include <net/netfilter/ipv4/nf_nat_masquerade.h> -#include <net/netfilter/ipv6/nf_nat_masquerade.h> +#include <net/netfilter/nf_nat_masquerade.h> struct nft_masq {u32 flags;
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 16/22 netfilter: x_tables: merge ip and ipv6 masquerade modules
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
No need to have separate modules for this.
before:
text data bss dec filename 2038 1168 0 3206 net/ipv4/netfilter/ipt_MASQUERADE.ko 1526 1024 0 2550 net/ipv6/netfilter/ip6t_MASQUERADE.ko after: text data bss dec filename 2521 1296 0 3817 net/netfilter/xt_MASQUERADE.ko
--- net/ipv4/netfilter/Kconfig | 12 +-- net/ipv4/netfilter/Makefile | 1 - net/ipv4/netfilter/ipt_MASQUERADE.c | 101 ------------------------- net/ipv6/netfilter/Kconfig | 11 +-- net/ipv6/netfilter/Makefile | 1 - net/ipv6/netfilter/ip6t_MASQUERADE.c | 81 -------------------- net/netfilter/Kconfig | 14 ++++ net/netfilter/Makefile | 1 + net/netfilter/xt_MASQUERADE.c | 143 +++++++++++++++++++++++++++++++++++ 9 files changed, 164 insertions(+), 201 deletions(-) delete mode 100644 net/ipv4/netfilter/ipt_MASQUERADE.c delete mode 100644 net/ipv6/netfilter/ip6t_MASQUERADE.c create mode 100644 net/netfilter/xt_MASQUERADE.c
net/ipv4/netfilter/Kconfig +3 -9
@@ -224,16 +224,10 @@ if IP_NF_NAT config IP_NF_TARGET_MASQUERADE tristate "MASQUERADE target support" - select NF_NAT_MASQUERADE - default m if NETFILTER_ADVANCED=n + select NETFILTER_XT_TARGET_MASQUERADE help - Masquerading is a special case of NAT: all outgoing connections are - changed to seem to come from a particular interface's address, and - if the interface goes down, those connections are lost. This is - only useful for dialup accounts with dynamic IP address (ie. your IP - address will be different on next dialup). - - To compile it as a module, choose M here. If unsure, say N. + This is a backwards-compat option for the user's convenience + (e.g. when running oldconfig). It selects NETFILTER_XT_TARGET_MASQUERADE. config IP_NF_TARGET_NETMAP tristate "NETMAP target support"
net/ipv4/netfilter/Makefile +0 -1
@@ -48,7 +48,6 @@ obj-$(CONFIG_IP_NF_MATCH_RPFILTER) += ipt_rpfilter.o # targets obj-$(CONFIG_IP_NF_TARGET_CLUSTERIP) += ipt_CLUSTERIP.o obj-$(CONFIG_IP_NF_TARGET_ECN) += ipt_ECN.o -obj-$(CONFIG_IP_NF_TARGET_MASQUERADE) += ipt_MASQUERADE.o obj-$(CONFIG_IP_NF_TARGET_REJECT) += ipt_REJECT.o obj-$(CONFIG_IP_NF_TARGET_SYNPROXY) += ipt_SYNPROXY.o
net/ipv4/netfilter/ipt_MASQUERADE.c deleted +0 -101
101 lines not on this page · raw message
net/ipv6/netfilter/Kconfig +3 -8
@@ -270,15 +270,10 @@ if IP6_NF_NAT config IP6_NF_TARGET_MASQUERADE tristate "MASQUERADE target support" - select NF_NAT_MASQUERADE + select NETFILTER_XT_TARGET_MASQUERADE help - Masquerading is a special case of NAT: all outgoing connections are - changed to seem to come from a particular interface's address, and - if the interface goes down, those connections are lost. This is - only useful for dialup accounts with dynamic IP address (ie. your IP - address will be different on next dialup). - - To compile it as a module, choose M here. If unsure, say N. + This is a backwards-compat option for the user's convenience + (e.g. when running oldconfig). It selects NETFILTER_XT_TARGET_MASQUERADE. config IP6_NF_TARGET_NPT tristate "NPT (Network Prefix translation) target support"
net/ipv6/netfilter/Makefile +0 -1
@@ -46,7 +46,6 @@ obj-$(CONFIG_IP6_NF_MATCH_RT) += ip6t_rt.o obj-$(CONFIG_IP6_NF_MATCH_SRH) += ip6t_srh.o # targets -obj-$(CONFIG_IP6_NF_TARGET_MASQUERADE) += ip6t_MASQUERADE.o obj-$(CONFIG_IP6_NF_TARGET_NPT) += ip6t_NPT.o obj-$(CONFIG_IP6_NF_TARGET_REJECT) += ip6t_REJECT.o obj-$(CONFIG_IP6_NF_TARGET_SYNPROXY) += ip6t_SYNPROXY.o
net/ipv6/netfilter/ip6t_MASQUERADE.c deleted +0 -81
81 lines not on this page · raw message
net/netfilter/Kconfig +14 -0
@@ -997,6 +997,20 @@ config NETFILTER_XT_TARGET_REDIRECT To compile it as a module, choose M here. If unsure, say N. +config NETFILTER_XT_TARGET_MASQUERADE + tristate "MASQUERADE target support" + depends on NF_NAT + default m if NETFILTER_ADVANCED=n + select NF_NAT_MASQUERADE + help + Masquerading is a special case of NAT: all outgoing connections are + changed to seem to come from a particular interface's address, and + if the interface goes down, those connections are lost. This is + only useful for dialup accounts with dynamic IP address (ie. your IP + address will be different on next dialup). + + To compile it as a module, choose M here. If unsure, say N. + config NETFILTER_XT_TARGET_TEE tristate '"TEE" - packet cloning to alternate destination' depends on NETFILTER_ADVANCED
net/netfilter/Makefile +1 -0
@@ -148,6 +148,7 @@ obj-$(CONFIG_NETFILTER_XT_TARGET_NFLOG) += xt_NFLOG.o obj-$(CONFIG_NETFILTER_XT_TARGET_NFQUEUE) += xt_NFQUEUE.o obj-$(CONFIG_NETFILTER_XT_TARGET_RATEEST) += xt_RATEEST.o obj-$(CONFIG_NETFILTER_XT_TARGET_REDIRECT) += xt_REDIRECT.o +obj-$(CONFIG_NETFILTER_XT_TARGET_MASQUERADE) += xt_MASQUERADE.o obj-$(CONFIG_NETFILTER_XT_TARGET_SECMARK) += xt_SECMARK.o obj-$(CONFIG_NETFILTER_XT_TARGET_TPROXY) += xt_TPROXY.o obj-$(CONFIG_NETFILTER_XT_TARGET_TCPMSS) += xt_TCPMSS.o
net/netfilter/xt_MASQUERADE.c new file +143 -0
143 lines not on this page · raw message
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 17/22 netfilter: nf_nat_masquerade: unify ipv4/6 notifier registration
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Only reason for having two different register functions was because of ipt_MASQUERADE and ip6t_MASQUERADE being two different modules.
Previous patch merged those into xt_MASQUERADE, so we can merge this too.
--- include/net/netfilter/nf_nat_masquerade.h | 6 +- net/netfilter/nf_nat_masquerade.c | 101 +++++++++++------------------- net/netfilter/nft_masq.c | 16 +---- net/netfilter/xt_MASQUERADE.c | 16 +---- 4 files changed, 44 insertions(+), 95 deletions(-)
include/net/netfilter/nf_nat_masquerade.h +2 -4
@@ -9,13 +9,11 @@ nf_nat_masquerade_ipv4(struct sk_buff *skb, unsigned int hooknum,const struct nf_nat_range2 *range, const struct net_device *out); -int nf_nat_masquerade_ipv4_register_notifier (void ); -void nf_nat_masquerade_ipv4_unregister_notifier (void ); +int nf_nat_masquerade_inet_register_notifiers (void ); +void nf_nat_masquerade_inet_unregister_notifiers (void );unsigned int nf_nat_masquerade_ipv6 (struct sk_buff *skb,const struct nf_nat_range2 *range,const struct net_device *out); -int nf_nat_masquerade_ipv6_register_notifier (void ); -void nf_nat_masquerade_ipv6_unregister_notifier (void );#endif /*_NF_NAT_MASQUERADE_H_ */
net/netfilter/nf_nat_masquerade.c +37 -64
145 lines not on this page · raw message
net/netfilter/nft_masq.c +3 -13
@@ -195,22 +195,12 @@ static struct nft_expr_type nft_masq_ipv6_type __read_mostly = {static int __init nft_masq_module_init_ipv6 (void ) { -int ret =nft_register_expr (&nft_masq_ipv6_type); - -if (ret) -return ret; - - ret =nf_nat_masquerade_ipv6_register_notifier (); -if (ret <0 ) -nft_unregister_expr (&nft_masq_ipv6_type); - -return ret; +return nft_register_expr (&nft_masq_ipv6_type); }static void nft_masq_module_exit_ipv6 (void ) {nft_unregister_expr (&nft_masq_ipv6_type); -nf_nat_masquerade_ipv6_unregister_notifier (); }#else static inline int nft_masq_module_init_ipv6 (void ) {return 0 ; }
@@ -293,7 +283,7 @@ static int __init nft_masq_module_init(void)return ret; } - ret =nf_nat_masquerade_ipv4_register_notifier (); + ret =nf_nat_masquerade_inet_register_notifiers ();if (ret <0 ) {nft_masq_module_exit_ipv6 ();nft_masq_module_exit_inet ();
@@ -309,7 +299,7 @@ static void __exit nft_masq_module_exit(void)nft_masq_module_exit_ipv6 ();nft_masq_module_exit_inet ();nft_unregister_expr (&nft_masq_ipv4_type); -nf_nat_masquerade_ipv4_unregister_notifier (); +nf_nat_masquerade_inet_unregister_notifiers (); }module_init (nft_masq_module_init);
net/netfilter/xt_MASQUERADE.c +2 -14
@@ -107,32 +107,20 @@ static int __init masquerade_tg_init(void)if (ret)return ret; - ret =nf_nat_masquerade_ipv4_register_notifier (); + ret =nf_nat_masquerade_inet_register_notifiers ();if (ret) {xt_unregister_targets (masquerade_tg_reg,ARRAY_SIZE (masquerade_tg_reg));return ret; } -#if IS_ENABLED (CONFIG_IPV6 ) - ret =nf_nat_masquerade_ipv6_register_notifier (); -if (ret) { -xt_unregister_targets (masquerade_tg_reg, -ARRAY_SIZE (masquerade_tg_reg)); -nf_nat_masquerade_ipv4_unregister_notifier (); -return ret; - } -#endif return ret; } static void __exit masquerade_tg_exit(void) {xt_unregister_targets (masquerade_tg_reg,ARRAY_SIZE (masquerade_tg_reg)); -nf_nat_masquerade_ipv4_unregister_notifier (); -#if IS_ENABLED (CONFIG_IPV6 ) -nf_nat_masquerade_ipv6_unregister_notifier (); -#endif +nf_nat_masquerade_inet_unregister_notifiers (); }module_init (masquerade_tg_init);
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 18/22 selftests: netfilter: add ebtables broute test case
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
ebtables -t broute allows to redirect packets in a way that they get pushed up the stack, even if the interface is part of a bridge.
In case of IP packets to non-local address, this means those IP packets are routed instead of bridged-forwarded, just as if the bridge would not have existed.
Expected test output is:
PASS: netns connectivity: ns1 and ns2 can reach each other
PASS: ns1/ns2 connectivity with active broute rule
PASS: ns1/ns2 connectivity with active broute rule and bridge forward drop
--- tools/testing/selftests/netfilter/Makefile | 2 +- .../testing/selftests/netfilter/bridge_brouter.sh | 146 +++++++++++++++++++++ 2 files changed, 147 insertions(+), 1 deletion(-) create mode 100755 tools/testing/selftests/netfilter/bridge_brouter.sh
tools/testing/selftests/netfilter/Makefile +1 -1
@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 # Makefile for netfilter selftests -TEST_PROGS := nft_trans_stress.sh nft_nat.sh +TEST_PROGS := nft_trans_stress.sh nft_nat.sh bridge_brouter.sh include ../lib.mk
tools/testing/selftests/netfilter/bridge_brouter.sh new file +146 -0
146 lines not on this page · raw message
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 19/22 bridge: reduce size of input cb to 16 bytes
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Reduce size of br_input_skb_cb from 24 to 16 bytes by using bitfield for those values that can only be 0 or 1.
igmp is the igmp type value, so it needs to be at least u8.
Furthermore, the bridge currently relies on step-by-step initialization of br_input_skb_cb fields as the skb passes through the stack.
Explicitly zero out the bridge input cb instead, this avoids having to review/validate that no BR_INPUT_SKB_CB(skb)->foo test can see a 'random' value from previous protocol cb.
AFAICS all current fields are always set up before they are read again, so this is not a bug fix.
--- net/bridge/br_arp_nd_proxy.c | 18 +++++++++--------- net/bridge/br_input.c | 2 ++ net/bridge/br_private.h | 12 +++++------- 3 files changed, 16 insertions(+), 16 deletions(-)
net/bridge/br_arp_nd_proxy.c +9 -9
@@ -131,7 +131,7 @@ void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br,u8 *arpptr, *sha;__be32 sip, tip; -BR_INPUT_SKB_CB (skb)->proxyarp_replied = false; +BR_INPUT_SKB_CB (skb)->proxyarp_replied =0 ;if ((dev->flags &IFF_NOARP ) || !pskb_may_pull (skb,arp_hdr_len (dev)))
@@ -161,7 +161,7 @@ void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br,return ;if (ipv4_is_zeronet (sip) || sip == tip) {/* prevent flooding to neigh suppress ports */ -BR_INPUT_SKB_CB (skb)->proxyarp_replied = true; +BR_INPUT_SKB_CB (skb)->proxyarp_replied =1 ;return ; } }
@@ -181,7 +181,7 @@ void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br,/* its our local ip, so don't proxy reply * and don't forward to neigh suppress ports */ -BR_INPUT_SKB_CB (skb)->proxyarp_replied = true; +BR_INPUT_SKB_CB (skb)->proxyarp_replied =1 ;return ; }
@@ -217,7 +217,7 @@ void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br,*/ if (replied ||br_opt_get (br,BROPT_NEIGH_SUPPRESS_ENABLED )) -BR_INPUT_SKB_CB (skb)->proxyarp_replied = true; +BR_INPUT_SKB_CB (skb)->proxyarp_replied =1 ; }neigh_release (n);
@@ -393,7 +393,7 @@ void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br,struct ipv6hdr *iphdr;struct neighbour *n; -BR_INPUT_SKB_CB (skb)->proxyarp_replied = false; +BR_INPUT_SKB_CB (skb)->proxyarp_replied =0 ;if (p && (p->flags &BR_NEIGH_SUPPRESS ))return ;
@@ -401,7 +401,7 @@ void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br,if (msg->icmph.icmp6_type ==NDISC_NEIGHBOUR_ADVERTISEMENT && !msg->icmph.icmp6_solicited) {/* prevent flooding to neigh suppress ports */ -BR_INPUT_SKB_CB (skb)->proxyarp_replied = true; +BR_INPUT_SKB_CB (skb)->proxyarp_replied =1 ;return ; }
@@ -414,7 +414,7 @@ void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br,if (ipv6_addr_any (saddr) || !ipv6_addr_cmp (saddr, daddr)) {/* prevent flooding to neigh suppress ports */ -BR_INPUT_SKB_CB (skb)->proxyarp_replied = true; +BR_INPUT_SKB_CB (skb)->proxyarp_replied =1 ;return ; }
@@ -432,7 +432,7 @@ void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br,/* its our own ip, so don't proxy reply * and don't forward to arp suppress ports */ -BR_INPUT_SKB_CB (skb)->proxyarp_replied = true; +BR_INPUT_SKB_CB (skb)->proxyarp_replied =1 ;return ; }
@@ -465,7 +465,7 @@ void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br,*/ if (replied ||br_opt_get (br,BROPT_NEIGH_SUPPRESS_ENABLED )) -BR_INPUT_SKB_CB (skb)->proxyarp_replied = true; +BR_INPUT_SKB_CB (skb)->proxyarp_replied =1 ; }neigh_release (n); }
net/bridge/br_input.c +2 -0
@@ -227,6 +227,8 @@ rx_handler_result_t br_handle_frame(struct sk_buff **pskb)if (!skb)return RX_HANDLER_CONSUMED ; +memset (skb->cb,0 ,sizeof (struct br_input_skb_cb )); + p =br_port_get_rcu (skb->dev);if (p->flags &BR_VLAN_TUNNEL ) { if (br_handle_ingress_vlan_tunnel(skb, p,
net/bridge/br_private.h +5 -7
@@ -425,15 +425,13 @@ struct br_input_skb_cb {struct net_device *brdev;#ifdef CONFIG_BRIDGE_IGMP_SNOOPING -int igmp; -int mrouters_only; +u8 igmp; + u8 mrouters_only:1;#endif - -bool proxyarp_replied; -bool src_port_isolated; - + u8 proxyarp_replied:1; + u8 src_port_isolated:1;#ifdef CONFIG_BRIDGE_VLAN_FILTERING -bool vlan_filtered; + u8 vlan_filtered:1;#endif #ifdef CONFIG_NET_SWITCHDEV
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 20/22 bridge: netfilter: unroll NF_HOOK helper in bridge input path
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Replace NF_HOOK() based invocation of the netfilter hooks with a private copy of nf_hook_slow().
This copy has one difference: it can return the rx handler value expected by the stack, i.e. RX_HANDLER_CONSUMED or RX_HANDLER_PASS.
This is needed by the next patch to invoke the ebtables "broute" table via the standard netfilter hooks rather than the custom "br_should_route_hook" indirection that is used now.
When the skb is to be "brouted", we must return RX_HANDLER_PASS from the bridge rx input handler, but there is no way to indicate this via NF_HOOK(), unless perhaps by some hack such as exposing bridge_cb in the netfilter core or a percpu flag.
text data bss dec filename 3369 56 0 3425 net/bridge/br_input.o.before 3458 40 0 3498 net/bridge/br_input.o.after
This allows removal of the "br_should_route_hook" in the next patch.
--- include/net/netfilter/nf_queue.h | 3 +++ net/bridge/br_input.c | 55 +++++++++++++++++++++++++++++++++++++--- net/netfilter/core.c | 1 + net/netfilter/nf_internals.h | 3 --- net/netfilter/nf_queue.c | 1 + 5 files changed, 56 insertions(+), 7 deletions(-)
include/net/netfilter/nf_queue.h +3 -0
@@ -119,4 +119,7 @@ nfqueue_hash(const struct sk_buff *skb, u16 queue, u16 queues_total, u8 family, return queue; } +int nf_queue (struct sk_buff *skb,struct nf_hook_state *state, +const struct nf_hook_entries *entries,unsigned int index, +unsigned int verdict);#endif /* _NF_QUEUE_H */
net/bridge/br_input.c +51 -4
73 lines not on this page · raw message
net/netfilter/core.c +1 -0
@@ -23,6 +23,7 @@#include <linux/mm.h> #include <linux/rcupdate.h> #include <net/net_namespace.h> +#include <net/netfilter/nf_queue.h> #include <net/sock.h> #include "nf_internals.h"
net/netfilter/nf_internals.h +0 -3
@@ -7,9 +7,6 @@#include <linux/netdevice.h> /* nf_queue.c */ -int nf_queue (struct sk_buff *skb,struct nf_hook_state *state, -const struct nf_hook_entries *entries,unsigned int index, -unsigned int verdict);void nf_queue_nf_hook_drop (struct net *net);/* nf_log.c */
net/netfilter/nf_queue.c +1 -0
@@ -240,6 +240,7 @@ int nf_queue(struct sk_buff *skb, struct nf_hook_state *state,return 0 ; } +EXPORT_SYMBOL_GPL (nf_queue); static unsigned int nf_iterate(struct sk_buff *skb, struct nf_hook_state *state,
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 21/22 bridge: broute: make broute a real ebtables table
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
This makes broute a normal ebtables table, hooking at PREROUTING. The broute hook is removed.
It uses skb->cb to signal to bridge rx handler that the skb should be routed instead of being bridged.
This change is backwards compatible with ebtables as no userspace visible parts are changed.
This means we can also remove the !ops test in ebt_register_table, it was only there for broute table sake.
--- include/linux/if_bridge.h | 3 -- net/bridge/br_input.c | 18 +++------- net/bridge/br_private.h | 3 ++ net/bridge/netfilter/ebtable_broute.c | 63 ++++++++++++++++++++++++----------- net/bridge/netfilter/ebtables.c | 7 +--- 5 files changed, 52 insertions(+), 42 deletions(-)
include/linux/if_bridge.h +0 -3
@@ -56,9 +56,6 @@ struct br_ip_list {extern void brioctl_set (int (*ioctl_hook)(struct net *,unsigned int ,void __user *)); -typedef int br_should_route_hook_t (struct sk_buff *skb); -extern br_should_route_hook_t __rcu *br_should_route_hook; -#if IS_ENABLED (CONFIG_BRIDGE ) &&IS_ENABLED (CONFIG_BRIDGE_IGMP_SNOOPING )int br_multicast_list_adjacent (struct net_device *dev,struct list_head *br_ip_list);
net/bridge/br_input.c +4 -14
@@ -24,10 +24,6 @@#include "br_private.h" #include "br_private_tunnel.h" -/* Hook for brouter */ -br_should_route_hook_t __rcu *br_should_route_hook__read_mostly ; -EXPORT_SYMBOL (br_should_route_hook); -static int br_netif_receive_skb (struct net *net,struct sock *sk,struct sk_buff *skb) {
@@ -234,6 +230,10 @@ static int nf_hook_bridge_pre(struct sk_buff *skb, struct sk_buff **pskb) verdict =nf_hook_entry_hookfn (&e->hooks[i], skb, &state);switch (verdict &NF_VERDICT_MASK ) {case NF_ACCEPT : +if (BR_INPUT_SKB_CB (skb)->br_netfilter_broute) { + *pskb = skb; +return RX_HANDLER_PASS ; + }break ;case NF_DROP :kfree_skb (skb);
@@ -265,7 +265,6 @@ rx_handler_result_t br_handle_frame(struct sk_buff **pskb)struct net_bridge_port *p;struct sk_buff *skb = *pskb;const unsigned char *dest =eth_hdr (skb)->h_dest; -br_should_route_hook_t *rhook;if (unlikely (skb->pkt_type ==PACKET_LOOPBACK ))return RX_HANDLER_PASS ;
@@ -341,15 +340,6 @@ rx_handler_result_t br_handle_frame(struct sk_buff **pskb) forward:switch (p->state) {case BR_STATE_FORWARDING : - rhook =rcu_dereference (br_should_route_hook); -if (rhook) { -if ((*rhook)(skb)) { - *pskb = skb; -return RX_HANDLER_PASS ; - } - dest =eth_hdr (skb)->h_dest; - } -/* fall through */ case BR_STATE_LEARNING :if (ether_addr_equal (p->br->dev->dev_addr, dest)) skb->pkt_type =PACKET_HOST ;
net/bridge/br_private.h +3 -0
@@ -433,6 +433,9 @@ struct br_input_skb_cb {#ifdef CONFIG_BRIDGE_VLAN_FILTERING u8 vlan_filtered:1;#endif +#ifdef CONFIG_NETFILTER_FAMILY_BRIDGE + u8 br_netfilter_broute:1; +#endif #ifdef CONFIG_NET_SWITCHDEV int offload_fwd_mark;
net/bridge/netfilter/ebtable_broute.c +44 -19
101 lines not on this page · raw message
net/bridge/netfilter/ebtables.c +1 -6
@@ -1221,10 +1221,6 @@ int ebt_register_table(struct net *net, const struct ebt_table *input_table,mutex_unlock (&ebt_mutex);WRITE_ONCE (*res, table); - -if (!ops) -return 0 ; - ret =nf_register_net_hooks (net, ops,hweight32 (table->valid_hooks));if (ret) {__ebt_unregister_table (net, table);
@@ -1248,8 +1244,7 @@ int ebt_register_table(struct net *net, const struct ebt_table *input_table,void ebt_unregister_table (struct net *net,struct ebt_table *table,const struct nf_hook_ops *ops) { -if (ops) -nf_unregister_net_hooks (net, ops,hweight32 (table->valid_hooks)); +nf_unregister_net_hooks (net, ops,hweight32 (table->valid_hooks));__ebt_unregister_table (net, table); }
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 22/22 bridge: only include nf_queue.h if needed
In reply to Pablo Neira AyusoFrom: Stephen Rothwell <[email protected]>
After merging the netfilter-next tree, today's linux-next build (powerpc ppc44x_defconfig) failed like this:
In file included from net/bridge/br_input.c:19:include/net/netfilter/nf_queue.h:16:23: error: field 'state' has incomplete type
struct nf_hook_state state;
^~~~~--- net/bridge/br_input.c | 2 ++ 1 file changed, 2 insertions(+)
net/bridge/br_input.c +2 -0
@@ -16,7 +16,9 @@#include <linux/netdevice.h> #include <linux/etherdevice.h> #include <linux/netfilter_bridge.h> +#ifdef CONFIG_NETFILTER_FAMILY_BRIDGE #include <net/netfilter/nf_queue.h> +#endif #include <linux/neighbour.h> #include <net/arp.h> #include <linux/export.h>
Signature · 1 line
2.11.0
David Miller
maintainerFrom: Pablo Neira Ayuso <[email protected]>
Date: Mon, 15 Apr 2019 19:00:06 +0200
Quoted 1 line
The following patchset contains Netfilter updates for net-next:
...
Quoted 3 lines
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git
Looks good, pulled.