netfilter: nft_tunnel: reinforce key opts support
Subsystems (3)
cover netfilter: nft_tunnel: reinforce key opts support
This patchset improves quite a few places to make vxlan/erspan opts in nft_tunnel work with userspace nftables/libnftnl, and also keep consistent with the support for vxlan/erspan opts in act_tunnel_key, cls_flower and ip_tunnel_core.
Meanwhile, add support for geneve opts in nft_tunnel. One patch for nftables and one for libnftnl will be posted here for the testing. With them, nft_tunnel can be set and used by:
# nft add table ip filter
# nft add chain ip filter input { type filter hook input priority 0 \; }
# nft add tunnel filter vxlan_01 { type vxlan\; id 2\; \
ip saddr 192.168.1.1\; ip daddr 192.168.1.2\; \
sport 9000\; dport 9001\; dscp 1234\; ttl 64\; flags 1\; \
opts \"ffff\"\; }
# nft add tunnel filter erspan_01 { type erspan\; id 2\; \
ip saddr 192.168.1.1\; ip daddr 192.168.1.2\; \
sport 9000\; dport 9001\; dscp 1234\; ttl 64\; flags 1\; \
opts \"1:1:0:0\"\; }
# nft add tunnel filter erspan_02 { type erspan\; id 2\; \
ip saddr 192.168.1.1\; ip daddr 192.168.1.2\; \
sport 9000\; dport 9001\; dscp 1234\; ttl 64\; flags 1\; \
opts \"2:0:1:1\"\; }
# nft add tunnel filter geneve_01 { type geneve\; id 2\; \
ip saddr 192.168.1.1\; ip daddr 192.168.1.2\; \
sport 9000\; dport 9001\; dscp 1234\; ttl 64\; flags 1\; \
opts \"1:1:1212121234567890\"\; }
# nft add tunnel filter geneve_02 { type geneve\; id 2\; \
ip saddr 192.168.1.1\; ip daddr 192.168.1.2\; \
sport 9000\; dport 9001\; dscp 1234\; ttl 64\; flags 1\; \
opts \"1:1:34567890,2:2:12121212,3:3:1212121234567890\"\; }
# nft list tunnels table filter
# nft add rule filter input ip protocol udp tunnel name geneve_02
# nft add rule filter input meta l4proto udp tunnel id 2 drop
# nft add rule filter input meta l4proto udp tunnel path 0 drop
# nft list chain filter input -aXin Long (7):
netfilter: nft_tunnel: parse ERSPAN_VERSION attr as u8
netfilter: nft_tunnel: parse VXLAN_GBP attr as u32 in nft_tunnel
netfilter: nft_tunnel: no need to call htons() when dumping ports
netfilter: nft_tunnel: also dump ERSPAN_VERSION
netfilter: nft_tunnel: also dump OPTS_ERSPAN/VXLAN
netfilter: nft_tunnel: add the missing nla_nest_cancel()
netfilter: nft_tunnel: add support for geneve opts
include/uapi/linux/netfilter/nf_tables.h | 10 ++ net/netfilter/nft_tunnel.c | 170 +++++++++++++++++++++++++------ 2 files changed, 151 insertions(+), 29 deletions(-)
Signature · 1 line
2.1.0
PATCH 1/7 netfilter: nft_tunnel: parse ERSPAN_VERSION attr as u8
To keep consistent with ipgre_policy, it's better to parse ERSPAN_VERSION attr as u8, as it does in act_tunnel_key, cls_flower and ip_tunnel_core.
--- net/netfilter/nft_tunnel.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
net/netfilter/nft_tunnel.c +3 -2
@@ -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_U8 }, [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 }, };
@@ -266,7 +267,7 @@ static int nft_tunnel_obj_erspan_init(const struct nlattr *attr,if (err <0 )return err; - version =ntohl (nla_get_be32 (tb[NFTA_TUNNEL_KEY_ERSPAN_VERSION ])); + version =nla_get_u8 (tb[NFTA_TUNNEL_KEY_ERSPAN_VERSION ]);switch (version) {case ERSPAN_VERSION :if (!tb[NFTA_TUNNEL_KEY_ERSPAN_V1_INDEX ])
Signature · 1 line
2.1.0
PATCH 2/7 netfilter: nft_tunnel: parse VXLAN_GBP attr as u32 in nft_tunnel
Both user and kernel sides want VXLAN_GBP opt as u32, so there's no need to convert it on each side.
--- net/netfilter/nft_tunnel.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/netfilter/nft_tunnel.c +3 -3
@@ -239,7 +239,7 @@ static int nft_tunnel_obj_vxlan_init(const struct nlattr *attr,if (!tb[NFTA_TUNNEL_KEY_VXLAN_GBP ])return -EINVAL ; - opts->u.vxlan.gbp =ntohl (nla_get_be32 (tb[NFTA_TUNNEL_KEY_VXLAN_GBP ])); + opts->u.vxlan.gbp =nla_get_u32 (tb[NFTA_TUNNEL_KEY_VXLAN_GBP ]); opts->len =sizeof (struct vxlan_metadata ); opts->flags =TUNNEL_VXLAN_OPT ;
@@ -475,8 +475,8 @@ static int nft_tunnel_opts_dump(struct sk_buff *skb,return -1 ;if (opts->flags &TUNNEL_VXLAN_OPT ) { -if (nla_put_be32 (skb,NFTA_TUNNEL_KEY_VXLAN_GBP , -htonl (opts->u.vxlan.gbp))) +if (nla_put_u32 (skb,NFTA_TUNNEL_KEY_VXLAN_GBP , + opts->u.vxlan.gbp))return -1 ; }else if (opts->flags &TUNNEL_ERSPAN_OPT ) {switch (opts->u.erspan.version) {
Signature · 1 line
2.1.0
PATCH 3/7 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.
--- net/netfilter/nft_tunnel.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nft_tunnel.c +2 -2
@@ -502,8 +502,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 4/7 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, opts->u.vxlan.gbp))return -1 ; }else if (opts->flags &TUNNEL_ERSPAN_OPT ) { +if (nla_put_u8 (skb,NFTA_TUNNEL_KEY_ERSPAN_VERSION , + 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 5/7 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_u32 (skb,NFTA_TUNNEL_KEY_VXLAN_GBP , 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_u8 (skb,NFTA_TUNNEL_KEY_ERSPAN_VERSION , 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 6/7 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_u32 (skb,NFTA_TUNNEL_KEY_VXLAN_GBP , 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_u8 (skb,NFTA_TUNNEL_KEY_ERSPAN_VERSION , 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
PATCH 7/7 netfilter: nft_tunnel: add support for geneve opts
Like vxlan and erspan opts, geneve opts should also be supported in nft_tunnel. The difference is geneve RFC (draft-ietf-nvo3-geneve-14) allows a geneve packet to carry multiple geneve opts. So with this patch, nftables/libnftnl would do:
# nft add table ip filter
# nft add chain ip filter input { type filter hook input priority 0 \; }
# nft add tunnel filter geneve_02 { type geneve\; id 2\; \
ip saddr 192.168.1.1\; ip daddr 192.168.1.2\; \
sport 9000\; dport 9001\; dscp 1234\; ttl 64\; flags 1\; \
opts \"1:1:34567890,2:2:12121212,3:3:1212121234567890\"\; }
# nft list tunnels table filter
table ip filter {
tunnel geneve_02 {
id 2
ip saddr 192.168.1.1
ip daddr 192.168.1.2
sport 9000
dport 9001
tos 18
ttl 64
flags 1
geneve opts 1:1:34567890,2:2:12121212,3:3:1212121234567890
}
}--- include/uapi/linux/netfilter/nf_tables.h | 10 +++ net/netfilter/nft_tunnel.c | 110 +++++++++++++++++++++++++++---- 2 files changed, 108 insertions(+), 12 deletions(-)
include/uapi/linux/netfilter/nf_tables.h +10 -0
@@ -1729,6 +1729,7 @@ enum nft_tunnel_opts_attributes {NFTA_TUNNEL_KEY_OPTS_UNSPEC ,NFTA_TUNNEL_KEY_OPTS_VXLAN ,NFTA_TUNNEL_KEY_OPTS_ERSPAN , +NFTA_TUNNEL_KEY_OPTS_GENEVE , __NFTA_TUNNEL_KEY_OPTS_MAX };#define NFTA_TUNNEL_KEY_OPTS_MAX (__NFTA_TUNNEL_KEY_OPTS_MAX - 1)
@@ -1750,6 +1751,15 @@ enum nft_tunnel_opts_erspan_attributes { };#define NFTA_TUNNEL_KEY_ERSPAN_MAX (__NFTA_TUNNEL_KEY_ERSPAN_MAX - 1) +enum nft_tunnel_opts_geneve_attributes { +NFTA_TUNNEL_KEY_GENEVE_UNSPEC , +NFTA_TUNNEL_KEY_GENEVE_CLASS , +NFTA_TUNNEL_KEY_GENEVE_TYPE , +NFTA_TUNNEL_KEY_GENEVE_DATA , + __NFTA_TUNNEL_KEY_GENEVE_MAX +}; +#define NFTA_TUNNEL_KEY_GENEVE_MAX (__NFTA_TUNNEL_KEY_GENEVE_MAX - 1) +enum nft_tunnel_flags {NFT_TUNNEL_F_ZERO_CSUM_TX = (1 <<0 ),NFT_TUNNEL_F_DONT_FRAGMENT = (1 <<1 ),
net/netfilter/nft_tunnel.c +98 -12
147 lines not on this page · raw message
Signature · 1 line
2.1.0
The 1st patch file for libnftnl is
Based on:
git://git.netfilter.org/libnftnl
The 2nd patch file for nftables is:
Based on:
git://git.netfilter.org/nftables: d42e9a1 (tag: v0.9.2) build:
Bump version to v0.9.2
plusing:
https://patchwork.ozlabs.org/patch/1136755/
https://patchwork.ozlabs.org/patch/1136756/
Dependencies:
Some fixes in libnftnl, which are in another patch.Quoted 47 lines · Xin Long
This patchset improves quite a few places to make vxlan/erspan opts in
nft_tunnelwork with userspace nftables/libnftnl, and also keep consistent with the support for vxlan/erspan opts inact_tunnel_key,cls_flowerandip_tunnel_core.Meanwhile, add support for geneve opts in
nft_tunnel. One patch for nftables and one for libnftnl will be posted here for the testing. With them,nft_tunnelcan be set and used by:# nft add table ip filter # nft add chain ip filter input { type filter hook input priority 0 \; } # nft add tunnel filter vxlan_01 { type vxlan\; id 2\; \ ip saddr 192.168.1.1\; ip daddr 192.168.1.2\; \ sport 9000\; dport 9001\; dscp 1234\; ttl 64\; flags 1\; \ opts \"ffff\"\; } # nft add tunnel filter erspan_01 { type erspan\; id 2\; \ ip saddr 192.168.1.1\; ip daddr 192.168.1.2\; \ sport 9000\; dport 9001\; dscp 1234\; ttl 64\; flags 1\; \ opts \"1:1:0:0\"\; } # nft add tunnel filter erspan_02 { type erspan\; id 2\; \ ip saddr 192.168.1.1\; ip daddr 192.168.1.2\; \ sport 9000\; dport 9001\; dscp 1234\; ttl 64\; flags 1\; \ opts \"2:0:1:1\"\; } # nft add tunnel filter geneve_01 { type geneve\; id 2\; \ ip saddr 192.168.1.1\; ip daddr 192.168.1.2\; \ sport 9000\; dport 9001\; dscp 1234\; ttl 64\; flags 1\; \ opts \"1:1:1212121234567890\"\; } # nft add tunnel filter geneve_02 { type geneve\; id 2\; \ ip saddr 192.168.1.1\; ip daddr 192.168.1.2\; \ sport 9000\; dport 9001\; dscp 1234\; ttl 64\; flags 1\; \ opts \"1:1:34567890,2:2:12121212,3:3:1212121234567890\"\; } # nft list tunnels table filter # nft add rule filter input ip protocol udp tunnel name geneve_02 # nft add rule filter input meta l4proto udp tunnel id 2 drop # nft add rule filter input meta l4proto udp tunnel path 0 drop # nft list chain filter input -aXin Long (7):
netfilter:nft_tunnel: parseERSPAN_VERSIONattr as u8
netfilter:nft_tunnel: parseVXLAN_GBPattr as u32 innft_tunnel
netfilter:nft_tunnel: no need to callhtons()when dumping ports
netfilter:nft_tunnel: also dumpERSPAN_VERSION
netfilter:nft_tunnel: also dump OPTS_ERSPAN/VXLAN
netfilter:nft_tunnel: add the missingnla_nest_cancel()
netfilter:nft_tunnel: add support for geneve opts
Quoted 7 lines
include/uapi/linux/netfilter/nf_tables.h | 10 ++ net/netfilter/nft_tunnel.c | 170 +++++++++++++++++++++++++------ 2 files changed, 151 insertions(+), 29 deletions(-)--
2.1.0
From 2456ad53c66489d6f2d4aac7d95216d553f94b83 Mon Sep 17 00:00:00 2001
From: Xin Long <[email protected]>
Date: Fri, 6 Dec 2019 04:31:10 -0500
Subject: [PATCH] libnftnl: nft_tunnel: add support for parsing geneve opts
--- include/libnftnl/object.h | 3 + include/linux/netfilter/nf_tables.h | 10 +++ include/obj.h | 13 +++- src/libnftnl.map | 1 + src/obj/tunnel.c | 109 ++++++++++++++++++++++++++-- src/object.c | 4 +- 6 files changed, 129 insertions(+), 11 deletions(-)
include/libnftnl/object.h +3 -0
@@ -109,6 +109,9 @@ enum {NFTNL_OBJ_TUNNEL_ERSPAN_V1_INDEX ,NFTNL_OBJ_TUNNEL_ERSPAN_V2_HWID ,NFTNL_OBJ_TUNNEL_ERSPAN_V2_DIR , +NFTNL_OBJ_TUNNEL_GENEVE_CLASS , +NFTNL_OBJ_TUNNEL_GENEVE_TYPE , + NFTNL_OBJ_TUNNEL_GENEVE_DATA, }; enum {
include/linux/netfilter/nf_tables.h +10 -0
@@ -1729,6 +1729,7 @@ enum nft_tunnel_opts_attributes {NFTA_TUNNEL_KEY_OPTS_UNSPEC ,NFTA_TUNNEL_KEY_OPTS_VXLAN ,NFTA_TUNNEL_KEY_OPTS_ERSPAN , +NFTA_TUNNEL_KEY_OPTS_GENEVE , __NFTA_TUNNEL_KEY_OPTS_MAX };#define NFTA_TUNNEL_KEY_OPTS_MAX (__NFTA_TUNNEL_KEY_OPTS_MAX - 1)
@@ -1750,6 +1751,15 @@ enum nft_tunnel_opts_erspan_attributes { };#define NFTA_TUNNEL_KEY_ERSPAN_MAX (__NFTA_TUNNEL_KEY_ERSPAN_MAX - 1) +enum nft_tunnel_opts_geneve_attributes { +NFTA_TUNNEL_KEY_GENEVE_UNSPEC , +NFTA_TUNNEL_KEY_GENEVE_CLASS , +NFTA_TUNNEL_KEY_GENEVE_TYPE , +NFTA_TUNNEL_KEY_GENEVE_DATA , + __NFTA_TUNNEL_KEY_GENEVE_MAX +}; +#define NFTA_TUNNEL_KEY_GENEVE_MAX (__NFTA_TUNNEL_KEY_GENEVE_MAX - 1) +enum nft_tunnel_flags {NFT_TUNNEL_F_ZERO_CSUM_TX = (1 <<0 ),NFT_TUNNEL_F_DONT_FRAGMENT = (1 <<1 ),
include/obj.h +11 -2
@@ -19,7 +19,7 @@ struct nftnl_obj {uint32_t family;uint32_t use; -uint32_t flags; +uint64_t flags;uint64_t handle;union {
@@ -78,7 +78,7 @@ struct nftnl_obj {uint32_t gbp; } tun_vxlan; struct { - uint32_t version; + uint8_t version; union { uint32_t v1_index; struct {
@@ -87,6 +87,15 @@ struct nftnl_obj { } v2; } u; } tun_erspan; +struct { +struct geneve_opt { +uint16_t class; +uint8_t type; +uint8_t *data; +uint8_t data_len; + } opts[64 ]; +uint8_t opt_num; + } tun_geneve; } u; } tunnel;struct nftnl_obj_secmark {
src/libnftnl.map +1 -0
@@ -357,5 +357,6 @@ LIBNFTNL_12 { LIBNFTNL_13 { nftnl_set_list_lookup_byname; nftnl_obj_set_data; + nftnl_obj_get_data; nftnl_flowtable_set_data; } LIBNFTNL_12;
src/obj/tunnel.c +102 -7
187 lines not on this page · raw message
src/object.c +2 -2
@@ -109,7 +109,7 @@ void nftnl_obj_set_data(struct nftnl_obj *obj, uint16_t attr, obj->ops->set (obj, attr, data, data_len);break ; } - obj->flags |= (1 << attr); + obj->flags |= (1lu << attr); } void nftnl_obj_set(struct nftnl_obj *obj, uint16_t attr, const void *data) __visible;
@@ -152,7 +152,7 @@ EXPORT_SYMBOL(nftnl_obj_get_data);const void *nftnl_obj_get_data (struct nftnl_obj *obj,uint16_t attr,uint32_t *data_len) { -if (!(obj->flags & (1 << attr))) +if (!(obj->flags & (1lu << attr)))return NULL ;switch (attr) {
Signature · 1 line
2.18.1
From ac451f621050fcb80f023084fb890363f8646776 Mon Sep 17 00:00:00 2001
From: Xin Long <[email protected]>
Date: Fri, 6 Dec 2019 04:19:53 -0500
Subject: [PATCH] nftables: nft_tunnel: add support for dumping
vxlan/erspan/geneve opts
Based on:
git://git.netfilter.org/nftables: d42e9a1 (tag: v0.9.2) build: Bump version to v0.9.2 plusing:
https://patchwork.ozlabs.org/patch/1136755/ https://patchwork.ozlabs.org/patch/1136756/
Dependencies:
Some fixes in libnftnl, which are in another patch.
Examples:
# nft add table ip filter
# nft add chain ip filter input { type filter hook input priority 0 \; }
# nft add tunnel filter vxlan_01 { type vxlan\; id 2\; ip saddr 192.168.1.1\; ip daddr 192.168.1.2\; sport 9000\; dport 9001\; dscp 1234\; ttl 64\; flags 1\; opts \"ffff\"\; }
# nft add tunnel filter erspan_01 { type erspan\; id 2\; ip saddr 192.168.1.1\; ip daddr 192.168.1.2\; sport 9000\; dport 9001\; dscp 1234\; ttl 64\; flags 1\; opts \"1:1:0:0\"\; }
# nft add tunnel filter erspan_02 { type erspan\; id 2\; ip saddr 192.168.1.1\; ip daddr 192.168.1.2\; sport 9000\; dport 9001\; dscp 1234\; ttl 64\; flags 1\; opts \"2:0:1:1\"\; }
# nft add tunnel filter geneve_01 { type geneve\; id 2\; ip saddr 192.168.1.1\; ip daddr 192.168.1.2\; sport 9000\; dport 9001\; dscp 1234\; ttl 64\; flags 1\; opts \"1:1:1212121234567890\"\; }
# nft add tunnel filter geneve_02 { type geneve\; id 2\; ip saddr 192.168.1.1\; ip daddr 192.168.1.2\; sport 9000\; dport 9001\; dscp 1234\; ttl 64\; flags 1\; opts \"1:1:1212121234567890,2:2:1212121234567890,3:3:1212121234567890\"\; }
# nft list tunnels table filter
# nft add rule filter input ip protocol udp tunnel name geneve_02
# nft add rule filter input meta l4proto udp tunnel id 2 drop
# nft add rule filter input meta l4proto udp tunnel path 0 drop
# nft list chain filter input -a--- include/rule.h | 3 +- src/evaluate.c | 4 ++ src/json.c | 4 ++ src/mnl.c | 108 +++++++++++++++++++++++++++++++++++++++++++++ src/netlink.c | 72 ++++++++++++++++++++++++++++++ src/parser_bison.y | 27 +++++++++++- src/rule.c | 21 +++++++++ src/scanner.l | 1 + 8 files changed, 237 insertions(+), 3 deletions(-)
include/rule.h +2 -1
@@ -408,11 +408,12 @@ struct tunnel {uint32_t id;struct expr *src;struct expr *dst; -uint32_t label; +uint32_t flags;uint16_t sport;uint16_t dport;uint8_t tos;uint8_t ttl; +const char *opts; };/**
src/evaluate.c +4 -0
@@ -3717,6 +3717,7 @@ static int cmd_evaluate_delete(struct eval_ctx *ctx, struct cmd *cmd)case CMD_OBJ_CT_HELPER :case CMD_OBJ_CT_TIMEOUT :case CMD_OBJ_LIMIT : +case CMD_OBJ_TUNNEL :case CMD_OBJ_SECMARK :case CMD_OBJ_CT_EXPECT :return 0 ;
@@ -3860,6 +3861,8 @@ static int cmd_evaluate_list(struct eval_ctx *ctx, struct cmd *cmd)return cmd_evaluate_list_obj (ctx, cmd,NFT_OBJECT_CT_TIMEOUT );case CMD_OBJ_LIMIT :return cmd_evaluate_list_obj (ctx, cmd,NFT_OBJECT_LIMIT ); +case CMD_OBJ_TUNNEL : +return cmd_evaluate_list_obj (ctx, cmd,NFT_OBJECT_TUNNEL );case CMD_OBJ_SECMARK :return cmd_evaluate_list_obj (ctx, cmd,NFT_OBJECT_SECMARK );case CMD_OBJ_CT_EXPECT :
@@ -3868,6 +3871,7 @@ static int cmd_evaluate_list(struct eval_ctx *ctx, struct cmd *cmd)case CMD_OBJ_QUOTAS :case CMD_OBJ_CT_HELPERS :case CMD_OBJ_LIMITS : +case CMD_OBJ_TUNNELS :case CMD_OBJ_SETS :case CMD_OBJ_FLOWTABLES :case CMD_OBJ_SECMARKS :
src/json.c +4 -0
@@ -1772,6 +1772,10 @@ int do_command_list_json(struct netlink_ctx *ctx, struct cmd *cmd)case CMD_OBJ_COUNTERS : root =do_list_obj_json (ctx, cmd,NFT_OBJECT_COUNTER );break ; +case CMD_OBJ_TUNNEL : +case CMD_OBJ_TUNNELS : + root =do_list_obj_json (ctx, cmd,NFT_OBJECT_TUNNEL ); +break ;case CMD_OBJ_QUOTA :case CMD_OBJ_QUOTAS : root =do_list_obj_json (ctx, cmd,NFT_OBJECT_QUOTA );
src/mnl.c +108 -0
126 lines not on this page · raw message
src/netlink.c +72 -0
90 lines not on this page · raw message
src/parser_bison.y +25 -2
@@ -546,6 +546,7 @@ int nft_lex(void *, void *, void *); %token IN "in" %token OUT "out" +%token OPTS "opts" %type <string> identifier type_identifier string comment_spec %destructor { xfree($$); } identifier type_identifier string comment_spec
@@ -1016,7 +1017,7 @@ add_cmd : TABLE table_spec } | TUNNEL obj_spec tunnel_obj '{' tunnel_block '}' stmt_separator { - $$ = cmd_alloc_obj_ct(CMD_ADD, CMD_OBJ_TUNNEL, &$2, &@$, $3); + $$ = cmd_alloc(CMD_ADD, CMD_OBJ_TUNNEL, &$2, &@$, $3); } ;
@@ -1113,7 +1114,7 @@ create_cmd : TABLE table_spec } | TUNNEL obj_spec tunnel_obj '{' tunnel_block '}' stmt_separator { - $$ = cmd_alloc_obj_ct(CMD_CREATE, CMD_OBJ_TUNNEL, &$2, &@$, $3); + $$ = cmd_alloc(CMD_CREATE, CMD_OBJ_TUNNEL, &$2, &@$, $3); } ;
@@ -1199,6 +1200,14 @@ delete_cmd : TABLE table_spec { $$ = cmd_alloc(CMD_DELETE, CMD_OBJ_SECMARK, &$2, &@$, NULL); } + | TUNNEL obj_spec + { + $$ = cmd_alloc(CMD_DELETE, CMD_OBJ_TUNNEL, &$2, &@$, NULL); + } + | TUNNEL objid_spec + { + $$ = cmd_alloc(CMD_DELETE, CMD_OBJ_TUNNEL, &$2, &@$, NULL); + } ; get_cmd : ELEMENT set_spec set_block_expr
@@ -1271,6 +1280,18 @@ list_cmd : TABLE table_spec { $$ = cmd_alloc(CMD_LIST, CMD_OBJ_LIMIT, &$2, &@$, NULL); } + | TUNNELS ruleset_spec + { + $$ = cmd_alloc(CMD_LIST, CMD_OBJ_TUNNELS, &$2, &@$, NULL); + } + | TUNNELS TABLE table_spec + { + $$ = cmd_alloc(CMD_LIST, CMD_OBJ_TUNNELS, &$3, &@$, NULL); + } + | TUNNEL obj_spec + { + $$ = cmd_alloc(CMD_LIST, CMD_OBJ_TUNNEL, &$2, &@$, NULL); + } | SECMARKS ruleset_spec { $$ = cmd_alloc(CMD_LIST, CMD_OBJ_SECMARKS, &$2, &@$, NULL);
@@ -3774,6 +3795,8 @@ tunnel_config : TYPE string stmt_separator { $<obj>0->tunnel.type = $2; } | DPORT NUM stmt_separator { $<obj>0->tunnel.dport = $2; } | DSCP NUM stmt_separator { $<obj>0->tunnel.tos = $2 << 2; } | TTL NUM stmt_separator { $<obj>0->tunnel.ttl = $2; } + | FLAGS NUM stmt_separator { $<obj>0->tunnel.flags = $2; } + | OPTS string stmt_separator { $<obj>0->tunnel.opts = $2; } ; tunnel_block : /* empty */ { $$ = $<obj>-1; }
src/rule.c +21 -0
@@ -1921,10 +1921,31 @@ static void obj_print_data(const struct obj *obj,nft_print (octx,"%s%sid %u%s" , opts->tab, opts->tab, obj->tunnel.id, opts->nl); +if (obj->tunnel.src) { +nft_print (octx,"%s%sip saddr " , + opts->tab, opts->tab); +expr_print (obj->tunnel.src, octx); +nft_print (octx,"%s" , opts->nl); + }if (obj->tunnel.dst) {nft_print (octx,"%s%sip daddr " , opts->tab, opts->tab);expr_print (obj->tunnel.dst, octx); +nft_print (octx,"%s" , opts->nl); + } +nft_print (octx,"%s%ssport %d%s" , opts->tab, opts->tab, + obj->tunnel.sport, opts->nl); +nft_print (octx,"%s%sdport %d%s" , opts->tab, opts->tab, + obj->tunnel.dport, opts->nl); +nft_print (octx,"%s%stos %d%s" , opts->tab, opts->tab, + obj->tunnel.tos, opts->nl); +nft_print (octx,"%s%sttl %d%s" , opts->tab, opts->tab, + obj->tunnel.ttl, opts->nl); +nft_print (octx,"%s%sflags %x%s" , opts->tab, opts->tab, + obj->tunnel.flags, opts->nl); +if (obj->tunnel.opts) { +nft_print (octx,"%s%s%s opts %s%s" , opts->tab, opts->tab, + obj->tunnel.type, obj->tunnel.opts, opts->nl); }break ;default :
src/scanner.l +1 -0
@@ -388,6 +388,7 @@ addrstring ({macaddr}|{ip4addr}|{ip6addr}) "saddr" { return SADDR; } "daddr" { return DADDR; } "type" { return TYPE; } +"opts" { return OPTS; } "vlan" { return VLAN; } "id" { return ID; }
Signature · 1 line
2.18.1
Re: [PATCH nf-next 1/7] netfilter: nft_tunnel: parse ERSPAN_VERSION attr as u8
In reply to Xin LongHi Xin,
Quoted 25 lines · Xin Long
To keep consistent with
ipgre_policy, it's better to parseERSPAN_VERSIONattr as u8, as it does inact_tunnel_key,cls_flowerandip_tunnel_core.Signed-off-by Xin Long <[email protected]>--- net/netfilter/nft_tunnel.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)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_U8 }, [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 }, };
net/netfilter/nft_tunnel.c static int nft_tunnel_obj_erspan_init(const struct nlattr *attr, · line 270
Quoted 5 lines
net/netfilter/nft_tunnel.c +1
-1@@ -266,7 +267,7 @@ static int nft_tunnel_obj_erspan_init(const struct nlattr *attr,if (err <0 )return err; - version =ntohl (nla_get_be32 (tb[NFTA_TUNNEL_KEY_ERSPAN_VERSION ])); + version =nla_get_u8 (tb[NFTA_TUNNEL_KEY_ERSPAN_VERSION ]);
I have concerns about this change and backwards-compatibility with existing users of this UAPI. Likewise, with other changes to the encoding of existing attributes elsewhere in this series.
Quoted 6 lines
net/netfilter/nft_tunnel.c +0
-0switch (version) {case ERSPAN_VERSION :if (!tb[NFTA_TUNNEL_KEY_ERSPAN_V1_INDEX ])Signature · 1 line
2.1.0
Re: [PATCH nf-next 1/7] netfilter: nft_tunnel: parse ERSPAN_VERSION attr as u8
Quoted 32 lines · Simon Horman
Hi Xin,
Quoted 28 lines · Xin Long
To keep consistent with
ipgre_policy, it's better to parseERSPAN_VERSIONattr as u8, as it does inact_tunnel_key,cls_flowerandip_tunnel_core.Signed-off-by Xin Long <[email protected]>--- net/netfilter/nft_tunnel.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)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_U8 }, [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 }, };@@ -266,7 +267,7 @@ static int nft_tunnel_obj_erspan_init(const struct nlattr *attr,if (err <0 )return err;
Quoted 6 lines
net/netfilter/nft_tunnel.c static int nft_tunnel_obj_erspan_init(const struct nlattr *attr, · line 270
Quoted 2 lines
net/netfilter/nft_tunnel.c +1
-1- version =ntohl (nla_get_be32 (tb[NFTA_TUNNEL_KEY_ERSPAN_VERSION ])); + version =nla_get_u8 (tb[NFTA_TUNNEL_KEY_ERSPAN_VERSION ]);I have concerns about this change and backwards-compatibility with existing users of this UAPI. Likewise, with other changes to the encoding of existing attributes elsewhere in this series.
userspace(nftables/libnftnl) is not ready for nft_tunnel, I don't think there will be
any backwards-compatibility issue.
Pablo?
Quoted 7 lines
Quoted 7 lines
net/netfilter/nft_tunnel.c +0
-1switch (version) {case ERSPAN_VERSION :if (!tb[NFTA_TUNNEL_KEY_ERSPAN_V1_INDEX ]) --2.1.0
Pablo Neira Ayuso
maintainerRe: [PATCH nf-next 1/7] netfilter: nft_tunnel: parse ERSPAN_VERSION attr as u8
In reply to Xin LongHi,
Quoted 25 lines · Xin Long
To keep consistent with
ipgre_policy, it's better to parseERSPAN_VERSIONattr as u8, as it does inact_tunnel_key,cls_flowerandip_tunnel_core.Signed-off-by Xin Long <[email protected]>--- net/netfilter/nft_tunnel.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)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_U8 }, [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 }, };
net/netfilter/nft_tunnel.c static int nft_tunnel_obj_erspan_init(const struct nlattr *attr, · line 270
Quoted 5 lines
net/netfilter/nft_tunnel.c +1
-1@@ -266,7 +267,7 @@ static int nft_tunnel_obj_erspan_init(const struct nlattr *attr,if (err <0 )return err; - version =ntohl (nla_get_be32 (tb[NFTA_TUNNEL_KEY_ERSPAN_VERSION ])); + version =nla_get_u8 (tb[NFTA_TUNNEL_KEY_ERSPAN_VERSION ]);
I think NFTA_TUNNEL_KEY_ERSPAN_VERSION as 32-bit is just fine.
Netlink will be adding the padding anyway for u8.
I would suggest you leave this as is.
Thanks.
Pablo Neira Ayuso
maintainerRe: [PATCH nf-next 2/7] netfilter: nft_tunnel: parse VXLAN_GBP attr as u32 in nft_tunnel
In reply to Xin LongQuoted 13 lines · Xin Long
Both user and kernel sides want
VXLAN_GBPopt as u32, so there's no need to convert it on each side.Signed-off-by Xin Long <[email protected]>--- net/netfilter/nft_tunnel.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)net/netfilter/nft_tunnel.c +0
-0
net/netfilter/nft_tunnel.c static int nft_tunnel_obj_vxlan_init(const struct nlattr *attr, · line 242
Quoted 5 lines
net/netfilter/nft_tunnel.c +1
-1@@ -239,7 +239,7 @@ static int nft_tunnel_obj_vxlan_init(const struct nlattr *attr,if (!tb[NFTA_TUNNEL_KEY_VXLAN_GBP ])return -EINVAL ; - opts->u.vxlan.gbp =ntohl (nla_get_be32 (tb[NFTA_TUNNEL_KEY_VXLAN_GBP ])); + opts->u.vxlan.gbp =nla_get_u32 (tb[NFTA_TUNNEL_KEY_VXLAN_GBP ]);
In netfilter, attributes go in network byte order to make it easier to send them over the wire. The only remaining part that needs to be converted to network byte order is the netlink header.
Please, leave this one as is.
Pablo Neira Ayuso
maintainerRe: [PATCH nf-next 3/7] netfilter: nft_tunnel: no need to call htons() when dumping ports
In reply to Xin LongQuoted 13 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.Signed-off-by Xin Long <[email protected]>--- net/netfilter/nft_tunnel.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)net/netfilter/nft_tunnel.c +0
-0
net/netfilter/nft_tunnel.c static int nft_tunnel_opts_dump(struct sk_buff *skb, · line 506
Quoted 7 lines
net/netfilter/nft_tunnel.c +2
-2@@ -502,8 +502,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 )
info->key.tp_src is already in __be16 as you describe. So I would take this as a consistency fix. I would take this as a fix.
Re: [PATCH nf-next 4/7] netfilter: nft_tunnel: also dump ERSPAN_VERSION
In reply to Xin LongQuoted 5 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]>
Re: [PATCH nf-next 5/7] netfilter: nft_tunnel: also dump OPTS_ERSPAN/VXLAN
In reply to Xin LongQuoted 6 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: [PATCH nf-next 6/7] netfilter: nft_tunnel: add the missing nla_nest_cancel()
In reply to Xin LongQuoted 5 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: [PATCH nf-next 3/7] netfilter: nft_tunnel: no need to call htons() when dumping ports
In reply to Xin LongQuoted 4 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.Signed-off-by Xin Long <[email protected]>
Pablo Neira Ayuso
maintainerRe: [PATCH nf-next 3/7] netfilter: nft_tunnel: no need to call htons() when dumping ports
In reply to Pablo Neira AyusoQuoted 9 lines · Pablo Neira Ayuso
Quoted 8 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.Signed-off-by Xin Long <[email protected]>--- net/netfilter/nft_tunnel.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 15 lines
net/netfilter/nft_tunnel.c static int nft_tunnel_opts_dump(struct sk_buff *skb, · line 506
Quoted 12 lines
net/netfilter/nft_tunnel.c +2
-2@@ -502,8 +502,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 )
info->key.tp_srcis already in__be16as you describe. So I would take this as a consistency fix. I would take this as a fix.
I mean, I think this is worth fixing it indeed.
Re: [PATCH nf-next 3/7] netfilter: nft_tunnel: no need to call htons() when dumping ports
Quoted 26 lines · Pablo Neira Ayuso
Quoted 9 lines · Pablo Neira Ayuso
Quoted 8 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.Signed-off-by Xin Long <[email protected]>--- net/netfilter/nft_tunnel.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)Quoted 15 lines
net/netfilter/nft_tunnel.c static int nft_tunnel_opts_dump(struct sk_buff *skb, · line 506
Quoted 12 lines
net/netfilter/nft_tunnel.c +2
-2@@ -502,8 +502,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 )
info->key.tp_srcis already in__be16as you describe. So I would take this as a consistency fix. I would take this as a fix.
Quoted 1 line
I mean, I think this is worth fixing it indeed.
Quoted 29 lines · Xin Long
This patchset improves quite a few places to make vxlan/erspan opts in
nft_tunnelwork with userspace nftables/libnftnl, and also keep consistent with the support for vxlan/erspan opts inact_tunnel_key,cls_flowerandip_tunnel_core.Meanwhile, add support for geneve opts in
nft_tunnel. One patch for nftables and one for libnftnl will be posted here for the testing. With them,nft_tunnelcan be set and used by:# nft add table ip filter # nft add chain ip filter input { type filter hook input priority 0 \; } # nft add tunnel filter vxlan_01 { type vxlan\; id 2\; \ ip saddr 192.168.1.1\; ip daddr 192.168.1.2\; \ sport 9000\; dport 9001\; dscp 1234\; ttl 64\; flags 1\; \ opts \"ffff\"\; } # nft add tunnel filter erspan_01 { type erspan\; id 2\; \ ip saddr 192.168.1.1\; ip daddr 192.168.1.2\; \ sport 9000\; dport 9001\; dscp 1234\; ttl 64\; flags 1\; \ opts \"1:1:0:0\"\; } # nft add tunnel filter erspan_02 { type erspan\; id 2\; \ ip saddr 192.168.1.1\; ip daddr 192.168.1.2\; \ sport 9000\; dport 9001\; dscp 1234\; ttl 64\; flags 1\; \ opts \"2:0:1:1\"\; } # nft add tunnel filter geneve_01 { type geneve\; id 2\; \ ip saddr 192.168.1.1\; ip daddr 192.168.1.2\; \ sport 9000\; dport 9001\; dscp 1234\; ttl 64\; flags 1\; \ opts \"1:1:1212121234567890\"\; } # nft add tunnel filter geneve_02 { type geneve\; id 2\; \
Quoted 8 lines
ip saddr 192.168.1.1\; ip daddr 192.168.1.2\; \
sport 9000\; dport 9001\; dscp 1234\; ttl 64\; flags 1\; \
opts \"1:1:34567890,2:2:12121212,3:3:1212121234567890\"\; }
# nft list tunnels table filter
# nft add rule filter input ip protocol udp tunnel name geneve_02
# nft add rule filter input meta l4proto udp tunnel id 2 drop
# nft add rule filter input meta l4proto udp tunnel path 0 drop
# nft list chain filter input -aHi, Pablo
as you commented on other patches, I will post v2 and
Quoted 4 lines
Xin Long (7):
netfilter:nft_tunnel: parseERSPAN_VERSIONattr as u8
netfilter:nft_tunnel: parseVXLAN_GBPattr as u32 innft_tunnel
drop these two patches
Quoted 1 line
netfilter:
nft_tunnel: no need to callhtons()when dumping ports
move this one to nf.git
Quoted 3 lines
netfilter:
nft_tunnel: also dumpERSPAN_VERSION
netfilter:nft_tunnel: also dump OPTS_ERSPAN/VXLAN
netfilter:nft_tunnel: add the missingnla_nest_cancel()
adjust these three for nf-next.git
Quoted 1 line
netfilter:
nft_tunnel: add support for geneve opts
will you also check this one before my posting v2?
Thanks.
Re: [PATCH nf-next 1/7] netfilter: nft_tunnel: parse ERSPAN_VERSION attr as u8
In reply to Pablo Neira AyusoQuoted 32 lines · Pablo Neira Ayuso
Hi,
Quoted 28 lines · Xin Long
To keep consistent with
ipgre_policy, it's better to parseERSPAN_VERSIONattr as u8, as it does inact_tunnel_key,cls_flowerandip_tunnel_core.Signed-off-by Xin Long <[email protected]>--- net/netfilter/nft_tunnel.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)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_U8 }, [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 }, };@@ -266,7 +267,7 @@ static int nft_tunnel_obj_erspan_init(const struct nlattr *attr,if (err <0 )return err;
Quoted 8 lines
net/netfilter/nft_tunnel.c static int nft_tunnel_obj_erspan_init(const struct nlattr *attr, · line 270
Quoted 2 lines
net/netfilter/nft_tunnel.c +1
-1- version =ntohl (nla_get_be32 (tb[NFTA_TUNNEL_KEY_ERSPAN_VERSION ])); + version =nla_get_u8 (tb[NFTA_TUNNEL_KEY_ERSPAN_VERSION ]);I think
NFTA_TUNNEL_KEY_ERSPAN_VERSIONas 32-bit is just fine.Netlink will be adding the padding anyway for u8.
I would suggest you leave this as is.
okay.
do you think I should prepare another patch/fix for the missing nla_policy part?
[NFTA_TUNNEL_KEY_ERSPAN_VERSION] = { .type = NLA_U32 },
Thanks.
Pablo Neira Ayuso
maintainerRe: [PATCH nf-next 1/7] netfilter: nft_tunnel: parse ERSPAN_VERSION attr as u8
Quoted 38 lines · Xin Long
Quoted 37 lines · Pablo Neira Ayuso
Hi,
Quoted 25 lines · Xin Long
To keep consistent with
ipgre_policy, it's better to parseERSPAN_VERSIONattr as u8, as it does inact_tunnel_key,cls_flowerandip_tunnel_core.Signed-off-by Xin Long <[email protected]>--- net/netfilter/nft_tunnel.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)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_U8 }, [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 }, };net/netfilter/nft_tunnel.c static int nft_tunnel_obj_erspan_init(const struct nlattr *attr, · line 270
Quoted 5 lines
net/netfilter/nft_tunnel.c +1
-1@@ -266,7 +267,7 @@ static int nft_tunnel_obj_erspan_init(const struct nlattr *attr,if (err <0 )return err; - version =ntohl (nla_get_be32 (tb[NFTA_TUNNEL_KEY_ERSPAN_VERSION ])); + version =nla_get_u8 (tb[NFTA_TUNNEL_KEY_ERSPAN_VERSION ]);I think
NFTA_TUNNEL_KEY_ERSPAN_VERSIONas 32-bit is just fine.
Quoted 7 lines
Quoted 3 lines
Netlink will be adding the padding anyway for u8.
I would suggest you leave this as is.
okay.
do you think I should prepare another patch/fix for the missing
nla_policypart?
[NFTA_TUNNEL_KEY_ERSPAN_VERSION] = { .type =NLA_U32},
Yes, please, thanks.
Pablo Neira Ayuso
maintainerOn Thu, Dec 12, 2019 at 11:02:19AM +0800, Xin Long wrote:
[...]
Quoted 7 lines
Hi, Pablo
as you commented on other patches, I will post v2 andQuoted 4 lines
Xin Long (7):
netfilter:nft_tunnel: parseERSPAN_VERSIONattr as u8
netfilter:nft_tunnel: parseVXLAN_GBPattr as u32 innft_tunneldrop these two patches
Yes, you will still need the netlink policy validation for ERSPAN_VERSION which is missing, so at least one patch will be needed for this one.
Quoted 2 lines
Quoted 1 line
netfilter:
nft_tunnel: no need to callhtons()when dumping portsmove this one to nf.git
Given that nft_tunnel really needs care and that there is no upstream userspace code using this extension, I think using nf-next.git in this case is fine.
Thanks.
Re: [PATCH nf-next 1/7] netfilter: nft_tunnel: parse ERSPAN_VERSION attr as u8
In reply to Xin LongQuoted 39 lines · Xin Long
Quoted 32 lines · Simon Horman
Hi Xin,
Quoted 28 lines · Xin Long
To keep consistent with
ipgre_policy, it's better to parseERSPAN_VERSIONattr as u8, as it does inact_tunnel_key,cls_flowerandip_tunnel_core.Signed-off-by Xin Long <[email protected]>--- net/netfilter/nft_tunnel.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)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_U8 }, [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 }, };@@ -266,7 +267,7 @@ static int nft_tunnel_obj_erspan_init(const struct nlattr *attr,if (err <0 )return err;Quoted 6 lines
net/netfilter/nft_tunnel.c static int nft_tunnel_obj_erspan_init(const struct nlattr *attr, · line 270
Quoted 2 lines
net/netfilter/nft_tunnel.c +1
-1- version =ntohl (nla_get_be32 (tb[NFTA_TUNNEL_KEY_ERSPAN_VERSION ])); + version =nla_get_u8 (tb[NFTA_TUNNEL_KEY_ERSPAN_VERSION ]);I have concerns about this change and backwards-compatibility with existing users of this UAPI. Likewise, with other changes to the encoding of existing attributes elsewhere in this series.
Quoted 5 lines
userspace(nftables/libnftnl) is not ready for
nft_tunnel, I don't think there will be
any backwards-compatibility issue.Pablo?
Thanks, I'm happy to defer to Pablo on this question.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
net/netfilter/nft_tunnel.c +0
-1switch (version) {case ERSPAN_VERSION :if (!tb[NFTA_TUNNEL_KEY_ERSPAN_V1_INDEX ]) --2.1.0
Pablo Neira Ayuso
maintainerRe: [PATCH nf-next 1/7] netfilter: nft_tunnel: parse ERSPAN_VERSION attr as u8
Hi Simon,
Quoted 41 lines · Simon Horman
Quoted 40 lines · Xin Long
Quoted 38 lines · Simon Horman
Hi Xin,
Quoted 25 lines · Xin Long
To keep consistent with
ipgre_policy, it's better to parseERSPAN_VERSIONattr as u8, as it does inact_tunnel_key,cls_flowerandip_tunnel_core.Signed-off-by Xin Long <[email protected]>--- net/netfilter/nft_tunnel.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)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_U8 }, [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 }, };net/netfilter/nft_tunnel.c static int nft_tunnel_obj_erspan_init(const struct nlattr *attr, · line 270
Quoted 5 lines
net/netfilter/nft_tunnel.c +1
-1@@ -266,7 +267,7 @@ static int nft_tunnel_obj_erspan_init(const struct nlattr *attr,if (err <0 )return err; - version =ntohl (nla_get_be32 (tb[NFTA_TUNNEL_KEY_ERSPAN_VERSION ])); + version =nla_get_u8 (tb[NFTA_TUNNEL_KEY_ERSPAN_VERSION ]);I have concerns about this change and backwards-compatibility with existing users of this UAPI. Likewise, with other changes to the encoding of existing attributes elsewhere in this series.
Quoted 6 lines
Quoted 4 lines
userspace(nftables/libnftnl) is not ready for
nft_tunnel, I don't think there will be any backwards-compatibility issue.Pablo?
Thanks, I'm happy to defer to Pablo on this question.
I agree with Xin. This uapi is not in good shape and there is no upstream userspace code for this, no nftables support for this yet. In this particular case I'm inclined to fix uapi, better sooner than never.
Thanks.