netfilter: nft_tunnel: a bunch of fixes and improvements
Subsystems (3)
v2 cover netfilter: nft_tunnel: a bunch of fixes and improvements
This patchset adds some fixes and improvements for nft_tunnel.
Note the patch for adding support for geneve opts in nft_tunnel will be posted in another patch after this one.
Xin Long (5):
netfilter: nft_tunnel: no need to call htons() when dumping ports
netfilter: nft_tunnel: add the missing ERSPAN_VERSION nla_policy
netfilter: nft_tunnel: also dump ERSPAN_VERSION
netfilter: nft_tunnel: also dump OPTS_ERSPAN/VXLAN
netfilter: nft_tunnel: add the missing nla_nest_cancel()
net/netfilter/nft_tunnel.c | 52 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 13 deletions(-)
Signature · 1 line
2.1.0
PATCH v2 1/5 netfilter: nft_tunnel: no need to call htons() when dumping ports
info->key.tp_src and tp_dst are __be16, when using nla_put_be16() to dump them, htons() is not needed, so remove it in this patch.
v1->v2:
- add Fixes tag.
--- net/netfilter/nft_tunnel.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nft_tunnel.c +2 -2
@@ -501,8 +501,8 @@ static int nft_tunnel_opts_dump(struct sk_buff *skb,static int nft_tunnel_ports_dump (struct sk_buff *skb,struct ip_tunnel_info *info) { -if (nla_put_be16 (skb,NFTA_TUNNEL_KEY_SPORT ,htons (info->key.tp_src)) <0 || -nla_put_be16 (skb,NFTA_TUNNEL_KEY_DPORT ,htons (info->key.tp_dst)) <0 ) +if (nla_put_be16 (skb,NFTA_TUNNEL_KEY_SPORT , info->key.tp_src) <0 || +nla_put_be16 (skb,NFTA_TUNNEL_KEY_DPORT , info->key.tp_dst) <0 )return -1 ;return 0 ;
Signature · 1 line
2.1.0
PATCH v2 2/5 netfilter: nft_tunnel: add the missing ERSPAN_VERSION nla_policy
ERSPAN_VERSION is an attribute parsed in kernel side, nla_policy type should be added for it, like other attributes.
--- net/netfilter/nft_tunnel.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/netfilter/nft_tunnel.c +2 -1
@@ -248,8 +248,9 @@ static int nft_tunnel_obj_vxlan_init(const struct nlattr *attr, }static const struct nla_policy nft_tunnel_opts_erspan_policy[NFTA_TUNNEL_KEY_ERSPAN_MAX +1 ] = { + [NFTA_TUNNEL_KEY_ERSPAN_VERSION ] = { .type =NLA_U32 }, [NFTA_TUNNEL_KEY_ERSPAN_V1_INDEX ] = { .type =NLA_U32 }, - [NFTA_TUNNEL_KEY_ERSPAN_V2_DIR ] = { .type =NLA_U8 }, + [NFTA_TUNNEL_KEY_ERSPAN_V2_DIR ] = { .type =NLA_U8 }, [NFTA_TUNNEL_KEY_ERSPAN_V2_HWID ] = { .type =NLA_U8 }, };
Signature · 1 line
2.1.0
PATCH v2 3/5 netfilter: nft_tunnel: also dump ERSPAN_VERSION
This is not necessary, but it'll be easier to parse in userspace, also given that other places like act_tunnel_key, cls_flower and ip_tunnel_core are also doing so.
--- net/netfilter/nft_tunnel.c | 3 +++ 1 file changed, 3 insertions(+)
net/netfilter/nft_tunnel.c +3 -0
@@ -479,6 +479,9 @@ static int nft_tunnel_opts_dump(struct sk_buff *skb, htonl(opts->u.vxlan.gbp)))return -1 ; }else if (opts->flags &TUNNEL_ERSPAN_OPT ) { +if (nla_put_be32 (skb,NFTA_TUNNEL_KEY_ERSPAN_VERSION , +htonl (opts->u.erspan.version))) +return -1 ;switch (opts->u.erspan.version) {case ERSPAN_VERSION : if (nla_put_be32(skb, NFTA_TUNNEL_KEY_ERSPAN_V1_INDEX,
Signature · 1 line
2.1.0
PATCH v2 4/5 netfilter: nft_tunnel: also dump OPTS_ERSPAN/VXLAN
This patch is to add the nest attr OPTS_ERSPAN/VXLAN when dumping KEY_OPTS, and it would be helpful when parsing in userpace. Also, this is needed for supporting multiple geneve opts in the future patches.
--- net/netfilter/nft_tunnel.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
net/netfilter/nft_tunnel.c +9 -1
@@ -468,17 +468,24 @@ static int nft_tunnel_opts_dump(struct sk_buff *skb, struct nft_tunnel_obj *priv) {struct nft_tunnel_opts *opts = &priv->opts; -struct nlattr *nest; +struct nlattr *nest, *inner; nest =nla_nest_start_noflag (skb,NFTA_TUNNEL_KEY_OPTS );if (!nest)return -1 ;if (opts->flags &TUNNEL_VXLAN_OPT ) { + inner =nla_nest_start_noflag (skb,NFTA_TUNNEL_KEY_OPTS_VXLAN ); +if (!inner) +return -1 ;if (nla_put_be32 (skb,NFTA_TUNNEL_KEY_VXLAN_GBP ,htonl (opts->u.vxlan.gbp)))return -1 ; +nla_nest_end (skb, inner); }else if (opts->flags &TUNNEL_ERSPAN_OPT ) { + inner =nla_nest_start_noflag (skb,NFTA_TUNNEL_KEY_OPTS_ERSPAN ); +if (!inner) +return -1 ;if (nla_put_be32 (skb,NFTA_TUNNEL_KEY_ERSPAN_VERSION ,htonl (opts->u.erspan.version)))return -1 ;
@@ -496,6 +503,7 @@ static int nft_tunnel_opts_dump(struct sk_buff *skb,return -1 ;break ; } +nla_nest_end (skb, inner); }nla_nest_end (skb, nest);
Signature · 1 line
2.1.0
PATCH v2 5/5 netfilter: nft_tunnel: add the missing nla_nest_cancel()
When nla_put_xxx() fails under nla_nest_start_noflag(), nla_nest_cancel() should be called, so that the skb can be trimmed properly.
--- net/netfilter/nft_tunnel.c | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-)
net/netfilter/nft_tunnel.c +26 -12
@@ -443,10 +443,15 @@ static int nft_tunnel_ip_dump(struct sk_buff *skb, struct ip_tunnel_info *info)if (!nest)return -1 ; -if (nla_put_in6_addr (skb,NFTA_TUNNEL_KEY_IP6_SRC , &info->key.u.ipv6.src) <0 || -nla_put_in6_addr (skb,NFTA_TUNNEL_KEY_IP6_DST , &info->key.u.ipv6.dst) <0 || -nla_put_be32 (skb,NFTA_TUNNEL_KEY_IP6_FLOWLABEL , info->key.label)) +if (nla_put_in6_addr (skb,NFTA_TUNNEL_KEY_IP6_SRC , + &info->key.u.ipv6.src) <0 || +nla_put_in6_addr (skb,NFTA_TUNNEL_KEY_IP6_DST , + &info->key.u.ipv6.dst) <0 || +nla_put_be32 (skb,NFTA_TUNNEL_KEY_IP6_FLOWLABEL , + info->key.label)) { +nla_nest_cancel (skb, nest);return -1 ; + }nla_nest_end (skb, nest); }else {
@@ -454,9 +459,13 @@ static int nft_tunnel_ip_dump(struct sk_buff *skb, struct ip_tunnel_info *info)if (!nest)return -1 ; -if (nla_put_in_addr (skb,NFTA_TUNNEL_KEY_IP_SRC , info->key.u.ipv4.src) <0 || -nla_put_in_addr (skb,NFTA_TUNNEL_KEY_IP_DST , info->key.u.ipv4.dst) <0 ) +if (nla_put_in_addr (skb,NFTA_TUNNEL_KEY_IP_SRC , + info->key.u.ipv4.src) <0 || +nla_put_in_addr (skb,NFTA_TUNNEL_KEY_IP_DST , + info->key.u.ipv4.dst) <0 ) { +nla_nest_cancel (skb, nest);return -1 ; + }nla_nest_end (skb, nest); }
@@ -477,37 +486,42 @@ static int nft_tunnel_opts_dump(struct sk_buff *skb,if (opts->flags &TUNNEL_VXLAN_OPT ) { inner =nla_nest_start_noflag (skb,NFTA_TUNNEL_KEY_OPTS_VXLAN );if (!inner) -return -1 ; + goto failure;if (nla_put_be32 (skb,NFTA_TUNNEL_KEY_VXLAN_GBP ,htonl (opts->u.vxlan.gbp))) -return -1 ; + goto inner_failure;nla_nest_end (skb, inner); }else if (opts->flags &TUNNEL_ERSPAN_OPT ) { inner =nla_nest_start_noflag (skb,NFTA_TUNNEL_KEY_OPTS_ERSPAN );if (!inner) -return -1 ; + goto failure;if (nla_put_be32 (skb,NFTA_TUNNEL_KEY_ERSPAN_VERSION ,htonl (opts->u.erspan.version))) -return -1 ; + goto inner_failure;switch (opts->u.erspan.version) {case ERSPAN_VERSION :if (nla_put_be32 (skb,NFTA_TUNNEL_KEY_ERSPAN_V1_INDEX , opts->u.erspan.u.index)) -return -1 ; + goto inner_failure;break ;case ERSPAN_VERSION2 :if (nla_put_u8 (skb,NFTA_TUNNEL_KEY_ERSPAN_V2_HWID ,get_hwid (&opts->u.erspan.u.md2)) ||nla_put_u8 (skb,NFTA_TUNNEL_KEY_ERSPAN_V2_DIR , opts->u.erspan.u.md2.dir)) -return -1 ; + goto inner_failure;break ; }nla_nest_end (skb, inner); }nla_nest_end (skb, nest); -return 0 ; + +inner_failure: +nla_nest_cancel (skb, inner); +failure: +nla_nest_cancel (skb, nest); +return -1 ; } static int nft_tunnel_ports_dump(struct sk_buff *skb,
Signature · 1 line
2.1.0
Re: [PATCHv2 nf-next 5/5] netfilter: nft_tunnel: add the missing nla_nest_cancel()
Quoted 6 lines · Xin Long
When
nla_put_xxx()fails undernla_nest_start_noflag(),nla_nest_cancel()should be called, so that the skb can be trimmed properly.Signed-off-by Xin Long <[email protected]>
Re: [PATCHv2 nf-next 4/5] netfilter: nft_tunnel: also dump OPTS_ERSPAN/VXLAN
In reply to Xin LongQuoted 7 lines · Xin Long
This patch is to add the nest attr OPTS_ERSPAN/VXLAN when dumping
KEY_OPTS, and it would be helpful when parsing in userpace. Also, this is needed for supporting multiple geneve opts in the future patches.Signed-off-by Xin Long <[email protected]>
Re: [PATCHv2 nf-next 3/5] netfilter: nft_tunnel: also dump ERSPAN_VERSION
In reply to Xin LongQuoted 6 lines · Xin Long
This is not necessary, but it'll be easier to parse in userspace, also given that other places like
act_tunnel_key,cls_flowerandip_tunnel_coreare also doing so.Signed-off-by Xin Long <[email protected]>
Quoted 21 lines
--- net/netfilter/nft_tunnel.c | 3 +++ 1 file changed, 3 insertions(+)net/netfilter/nft_tunnel.c +3
-0@@ -479,6 +479,9 @@ static int nft_tunnel_opts_dump(struct sk_buff *skb, htonl(opts->u.vxlan.gbp)))return -1 ; }else if (opts->flags &TUNNEL_ERSPAN_OPT ) { +if (nla_put_be32 (skb,NFTA_TUNNEL_KEY_ERSPAN_VERSION , +htonl (opts->u.erspan.version))) +return -1 ;switch (opts->u.erspan.version) {case ERSPAN_VERSION : if (nla_put_be32(skb, NFTA_TUNNEL_KEY_ERSPAN_V1_INDEX,Signature · 1 line
2.1.0
Re: [PATCHv2 nf-next 2/5] netfilter: nft_tunnel: add the missing ERSPAN_VERSION nla_policy
In reply to Xin LongQuoted 4 lines · Xin Long
ERSPAN_VERSIONis an attribute parsed in kernel side,nla_policytype should be added for it, like other attributes.Fixes af308b94a2a4 ("netfilter: nf_tables: add tunnel support")
Is this really a fix?
Quoted 2 lines
Signed-off-by Xin Long <[email protected]>
Quoted 22 lines
--- net/netfilter/nft_tunnel.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)net/netfilter/nft_tunnel.c +2
-1@@ -248,8 +248,9 @@ static int nft_tunnel_obj_vxlan_init(const struct nlattr *attr, }static const struct nla_policy nft_tunnel_opts_erspan_policy[NFTA_TUNNEL_KEY_ERSPAN_MAX +1 ] = { + [NFTA_TUNNEL_KEY_ERSPAN_VERSION ] = { .type =NLA_U32 }, [NFTA_TUNNEL_KEY_ERSPAN_V1_INDEX ] = { .type =NLA_U32 }, - [NFTA_TUNNEL_KEY_ERSPAN_V2_DIR ] = { .type =NLA_U8 }, + [NFTA_TUNNEL_KEY_ERSPAN_V2_DIR ] = { .type =NLA_U8 }, [NFTA_TUNNEL_KEY_ERSPAN_V2_HWID ] = { .type =NLA_U8 }, };Signature · 1 line
2.1.0
Pablo Neira Ayuso
maintainerRe: [PATCHv2 nf-next 2/5] netfilter: nft_tunnel: add the missing ERSPAN_VERSION nla_policy
Quoted 7 lines · Simon Horman
Quoted 4 lines · Xin Long
ERSPAN_VERSIONis an attribute parsed in kernel side,nla_policytype should be added for it, like other attributes.Fixes af308b94a2a4 ("netfilter: nf_tables: add tunnel support")Is this really a fix?
I think so. Netlink attribute validation forNFTA_TUNNEL_KEY_ERSPAN_VERSION is missing.
Re: [PATCHv2 nf-next 2/5] netfilter: nft_tunnel: add the missing ERSPAN_VERSION nla_policy
Quoted 11 lines · Pablo Neira Ayuso
Quoted 7 lines · Simon Horman
Quoted 4 lines · Xin Long
ERSPAN_VERSIONis an attribute parsed in kernel side,nla_policytype should be added for it, like other attributes.Fixes af308b94a2a4 ("netfilter: nf_tables: add tunnel support")Is this really a fix?
I think so. Netlink attribute validation for
NFTA_TUNNEL_KEY_ERSPAN_VERSIONis missing.
Ok, I accept that reasoning.
Re: [PATCHv2 nf-next 1/5] netfilter: nft_tunnel: no need to call htons() when dumping ports
In reply to Xin LongQuoted 9 lines · Xin Long
info->key.tp_srcandtp_dstare__be16, when usingnla_put_be16()to dump them,htons()is not needed, so remove it in this patch.
v1->v2:
- add Fixes tag.Fixes af308b94a2a4 ("netfilter: nf_tables: add tunnel support")Signed-off-by Xin Long <[email protected]>
Quoted 22 lines
--- net/netfilter/nft_tunnel.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)net/netfilter/nft_tunnel.c +2
-2@@ -501,8 +501,8 @@ static int nft_tunnel_opts_dump(struct sk_buff *skb,static int nft_tunnel_ports_dump (struct sk_buff *skb,struct ip_tunnel_info *info) { -if (nla_put_be16 (skb,NFTA_TUNNEL_KEY_SPORT ,htons (info->key.tp_src)) <0 || -nla_put_be16 (skb,NFTA_TUNNEL_KEY_DPORT ,htons (info->key.tp_dst)) <0 ) +if (nla_put_be16 (skb,NFTA_TUNNEL_KEY_SPORT , info->key.tp_src) <0 || +nla_put_be16 (skb,NFTA_TUNNEL_KEY_DPORT , info->key.tp_dst) <0 )return -1 ;return 0 ;Signature · 1 line
2.1.0
Pablo Neira Ayuso
maintainerQuoted 4 lines · Xin Long
This patchset adds some fixes and improvements for
nft_tunnel.Note the patch for adding support for geneve opts in
nft_tunnelwill be posted in another patch after this one.
Series applied, thanks.