iproute2: fully support for geneve/vxlan/erspan options
Subsystems (2)
v4 cover iproute2: fully support for geneve/vxlan/erspan options
Patch 1-3 add the geneve/vxlan/erspan options support for iproute_lwtunnel, and Patch 4-5 add the vxlan/erspan options for tc m_tunnel_key, and Patch 6-7 add the vxlan/erspan options for tc f_flower.
In kernel space, these features have been supported since these patchsets:
https://patchwork.ozlabs.org/cover/1190172/
https://patchwork.ozlabs.org/cover/1198854/
v1->v2:
- improve the bash commands in changelog as David A. suggested.
- use PRINT_ANY to support dummping with json format as Stephen suggested.v2->v3:
- implement proper JSON array for opts as Stephen suggested.v3->v4:
- Basically we print all options as uint, other than 'data' in the 1st patch as a hex string.
- As Stephen's suggestion, we keep all those options of the same format between input and output, and between json and non json.
Xin Long (7):
iproute_lwtunnel: add options support for geneve metadata
iproute_lwtunnel: add options support for vxlan metadata
iproute_lwtunnel: add options support for erspan metadata
tc: m_tunnel_key: add options support for vxlan
tc: m_tunnel_key: add options support for erpsan
tc: f_flower: add options support for vxlan
tc: f_flower: add options support for erspan
ip/iproute_lwtunnel.c | 382 ++++++++++++++++++++++++++++++++++++++++++++++- man/man8/tc-flower.8 | 25 ++++ man/man8/tc-tunnel_key.8 | 20 ++- tc/f_flower.c | 301 +++++++++++++++++++++++++++++++++++-- tc/m_tunnel_key.c | 199 ++++++++++++++++++++++-- 5 files changed, 899 insertions(+), 28 deletions(-)
Signature · 1 line
2.1.0
PATCH v4 1/7 iproute_lwtunnel: add options support for geneve metadata
This patch is to add LWTUNNEL_IP(6)_OPTS and LWTUNNEL_IP_OPTS_GENEVE's parse and print to implement geneve options support in iproute_lwtunnel.
Options are expressed as class:type:data and multiple options may be listed using a comma delimiter, class and type are numbers and data is a hex string.
With this patch, users can add and dump geneve options like:
# ip netns add a
# ip netns add b
# ip -n a link add eth0 type veth peer name eth0 netns b
# ip -n a link set eth0 up; ip -n b link set eth0 up
# ip -n a addr add 10.1.0.1/24 dev eth0
# ip -n b addr add 10.1.0.2/24 dev eth0
# ip -n b link add geneve1 type geneve id 1 remote 10.1.0.1 ttl 64
# ip -n b addr add 1.1.1.1/24 dev geneve1
# ip -n b link set geneve1 up
# ip -n b route add 2.1.1.0/24 dev geneve1
# ip -n a link add geneve1 type geneve external
# ip -n a addr add 2.1.1.1/24 dev geneve1
# ip -n a link set geneve1 up
# ip -n a route add 1.1.1.0/24 encap ip id 1 geneve_opts \
1:1:1212121234567890,1:1:1212121234567890,1:1:1212121234567890 \
dst 10.1.0.2 dev geneve1
# ip -n a route show
# ip netns exec a ping 1.1.1.1 -c 11.1.1.0/24 encap ip id 1 src 0.0.0.0 dst 10.1.0.2 ttl 0 tos 0
geneve_opts 1:1:1212121234567890,1:1:1212121234567890 ...
PING 1.1.1.1 (1.1.1.1) 56(84) bytes of data. 64 bytes from 1.1.1.1: icmp_seq=1 ttl=64 time=0.079 ms
v1->v2:
- improve the changelog.
- use PRINT_ANY to support dumping with json format.v2->v3:
- implement proper JSON array for opts instead of just bunch of strings.v3->v4:
- keep the same format between input and output, json and non json.
- print class and type as uint and print data as hex string.
--- ip/iproute_lwtunnel.c | 174 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 172 insertions(+), 2 deletions(-)
ip/iproute_lwtunnel.c +172 -2
@@ -294,6 +294,54 @@ static void print_encap_mpls(FILE *fp, struct rtattr *encap) rta_getattr_u8(tb[MPLS_IPTUNNEL_TTL])); } +static void lwtunnel_print_geneve_opts (struct rtattr *attr) +{ +struct rtattr *tb[LWTUNNEL_IP_OPT_GENEVE_MAX +1 ]; +struct rtattr *i =RTA_DATA (attr); +int rem =RTA_PAYLOAD (attr); +char *name ="geneve_opts" ; +int data_len, offset =0 ; +char data[rem *2 +1 ]; +__u16 class; +__u8 type; + +print_nl (); +print_string (PRINT_FP , name,"\t%s " , name); +open_json_array (PRINT_JSON , name); + +while (rem) { +parse_rtattr (tb,LWTUNNEL_IP_OPT_GENEVE_MAX , i, rem); + class =rta_getattr_be16 (tb[LWTUNNEL_IP_OPT_GENEVE_CLASS ]); + type =rta_getattr_u8 (tb[LWTUNNEL_IP_OPT_GENEVE_TYPE ]); + data_len =RTA_PAYLOAD (tb[LWTUNNEL_IP_OPT_GENEVE_DATA ]); +hexstring_n2a (RTA_DATA (tb[LWTUNNEL_IP_OPT_GENEVE_DATA ]), + data_len, data,sizeof (data)); + offset += data_len +20 ; + rem -= data_len +20 ; + i =RTA_DATA (attr) + offset; + +open_json_object (NULL ); +print_uint (PRINT_ANY ,"class" ,"%u" , class); +print_uint (PRINT_ANY ,"type" ,":%u" , type); +if (rem) +print_string (PRINT_ANY ,"data" ,":%s," , data); +else +print_string (PRINT_ANY ,"data" ,":%s " , data); +close_json_object (); + } + +close_json_array (PRINT_JSON , name); +} + +static void lwtunnel_print_opts (struct rtattr *attr) +{ +struct rtattr *tb_opt[LWTUNNEL_IP_OPTS_MAX +1 ]; + +parse_rtattr_nested (tb_opt,LWTUNNEL_IP_OPTS_MAX , attr); +if (tb_opt[LWTUNNEL_IP_OPTS_GENEVE ]) +lwtunnel_print_geneve_opts (tb_opt[LWTUNNEL_IP_OPTS_GENEVE ]); +} +static void print_encap_ip (FILE *fp,struct rtattr *encap) {struct rtattr *tb[LWTUNNEL_IP_MAX +1 ];
@@ -332,6 +380,9 @@ static void print_encap_ip(FILE *fp, struct rtattr *encap)if (flags &TUNNEL_SEQ )print_bool (PRINT_ANY ,"seq" ,"seq " , true); } + +if (tb[LWTUNNEL_IP_OPTS ]) +lwtunnel_print_opts (tb[LWTUNNEL_IP_OPTS ]); }static void print_encap_ila (FILE *fp,struct rtattr *encap)
@@ -404,6 +455,9 @@ static void print_encap_ip6(FILE *fp, struct rtattr *encap)if (flags &TUNNEL_SEQ )print_bool (PRINT_ANY ,"seq" ,"seq " , true); } + +if (tb[LWTUNNEL_IP6_OPTS ]) +lwtunnel_print_opts (tb[LWTUNNEL_IP6_OPTS ]); }static void print_encap_bpf (FILE *fp,struct rtattr *encap)
@@ -798,11 +852,97 @@ static int parse_encap_mpls(struct rtattr *rta, size_t len,return 0 ; } +static int lwtunnel_parse_geneve_opt (char *str,size_t len,struct rtattr *rta) +{ +struct rtattr *nest; +char *token; +int i, err; + + nest =rta_nest (rta, len,LWTUNNEL_IP_OPTS_GENEVE |NLA_F_NESTED ); + i =1 ; + token =strsep (&str,":" ); +while (token) { +switch (i) { +case LWTUNNEL_IP_OPT_GENEVE_CLASS : + { +__be16 opt_class; + +if (!strlen (token)) +break ; + err =get_be16 (&opt_class, token,0 ); +if (err) +return err; + +rta_addattr16 (rta, len, i, opt_class); +break ; + } +case LWTUNNEL_IP_OPT_GENEVE_TYPE : + { +__u8 opt_type; + +if (!strlen (token)) +break ; + err =get_u8 (&opt_type, token,0 ); +if (err) +return err; + +rta_addattr8 (rta, len, i, opt_type); +break ; + } +case LWTUNNEL_IP_OPT_GENEVE_DATA : + { +size_t token_len =strlen (token); +__u8 *opts; + +if (!token_len) +break ; + opts =malloc (token_len /2 ); +if (!opts) +return -1 ; +if (hex2mem (token, opts, token_len /2 ) <0 ) { +free (opts); +return -1 ; + } +rta_addattr_l (rta, len, i, opts, token_len /2 ); +free (opts); + +break ; + } +default : +fprintf (stderr,"Unknown \"geneve_opts\" type\n" ); +return -1 ; + } + + token =strsep (&str,":" ); + i++; + } +rta_nest_end (rta, nest); + +return 0 ; +} + +static int lwtunnel_parse_geneve_opts (char *str,size_t len,struct rtattr *rta) +{ +char *token; +int err; + + token =strsep (&str,"," ); +while (token) { + err =lwtunnel_parse_geneve_opt (token, len, rta); +if (err) +return err; + + token =strsep (&str,"," ); + } + +return 0 ; +} +static int parse_encap_ip (struct rtattr *rta,size_t len,int *argcp,char ***argvp) {int id_ok =0 , dst_ok =0 , src_ok =0 , tos_ok =0 , ttl_ok =0 ; -int key_ok =0 , csum_ok =0 , seq_ok =0 ; +int key_ok =0 , csum_ok =0 , seq_ok =0 , opts_ok =0 ;char **argv = *argvp;int argc = *argcp;int ret =0 ;
@@ -854,6 +994,21 @@ static int parse_encap_ip(struct rtattr *rta, size_t len,if (get_u8 (&ttl, *argv,0 ))invarg ("\"ttl\" value is invalid\n" , *argv); ret =rta_addattr8 (rta, len,LWTUNNEL_IP_TTL , ttl); + }else if (strcmp (*argv,"geneve_opts" ) ==0 ) { +struct rtattr *nest; + +if (opts_ok++) +duparg2 ("opts" , *argv); + +NEXT_ARG (); + + nest =rta_nest (rta, len, +LWTUNNEL_IP_OPTS |NLA_F_NESTED ); + ret =lwtunnel_parse_geneve_opts (*argv, len, rta); +if (ret) +invarg ("\"geneve_opts\" value is invalid\n" , + *argv); +rta_nest_end (rta, nest); }else if (strcmp (*argv,"key" ) ==0 ) {if (key_ok++)duparg2 ("key" , *argv);
@@ -969,7 +1124,7 @@ static int parse_encap_ip6(struct rtattr *rta, size_t len, int *argcp, char ***argvp) { int id_ok = 0, dst_ok = 0, src_ok = 0, tos_ok = 0, ttl_ok = 0; -int key_ok =0 , csum_ok =0 , seq_ok =0 ; +int key_ok =0 , csum_ok =0 , seq_ok =0 , opts_ok =0 ;char **argv = *argvp;int argc = *argcp;int ret =0 ;
@@ -1023,6 +1178,21 @@ static int parse_encap_ip6(struct rtattr *rta, size_t len, *argv); ret =rta_addattr8 (rta, len,LWTUNNEL_IP6_HOPLIMIT , hoplimit); + }else if (strcmp (*argv,"geneve_opts" ) ==0 ) { +struct rtattr *nest; + +if (opts_ok++) +duparg2 ("opts" , *argv); + +NEXT_ARG (); + + nest =rta_nest (rta, len, +LWTUNNEL_IP_OPTS |NLA_F_NESTED ); + ret =lwtunnel_parse_geneve_opts (*argv, len, rta); +if (ret) +invarg ("\"geneve_opts\" value is invalid\n" , + *argv); +rta_nest_end (rta, nest); }else if (strcmp (*argv,"key" ) ==0 ) {if (key_ok++)duparg2 ("key" , *argv);
Signature · 1 line
2.1.0
PATCH v4 2/7 iproute_lwtunnel: add options support for vxlan metadata
This patch is to add LWTUNNEL_IP_OPTS_VXLAN's parse and print to implement vxlan options support in iproute_lwtunnel.
Option is expressed a number for gbp only, and vxlan doesn't support multiple options.
With this patch, users can add and dump vxlan options like:
# ip netns add a
# ip netns add b
# ip -n a link add eth0 type veth peer name eth0 netns b
# ip -n a link set eth0 up
# ip -n b link set eth0 up
# ip -n a addr add 10.1.0.1/24 dev eth0
# ip -n b addr add 10.1.0.2/24 dev eth0
# ip -n b link add vxlan1 type vxlan id 1 local 10.1.0.2 \
remote 10.1.0.1 dev eth0 ttl 64 gbp
# ip -n b addr add 1.1.1.1/24 dev vxlan1
# ip -n b link set vxlan1 up
# ip -n b route add 2.1.1.0/24 dev vxlan1
# ip -n a link add vxlan1 type vxlan local 10.1.0.1 dev eth0 ttl 64 \
gbp external
# ip -n a addr add 2.1.1.1/24 dev vxlan1
# ip -n a link set vxlan1 up
# ip -n a route add 1.1.1.0/24 encap ip id 1 \
vxlan_opts 1110 dst 10.1.0.2 dev vxlan1
# ip -n a route show
# ip netns exec a ping 1.1.1.1 -c 1 1.1.1.0/24 encap ip id 1 src 0.0.0.0 dst 10.1.0.2 ttl 0 tos 0
vxlan_opts 1110 dev vxlan1 scope link
PING 1.1.1.1 (1.1.1.1) 56(84) bytes of data. 64 bytes from 1.1.1.1: icmp_seq=1 ttl=64 time=0.111 ms
v1->v2:
- improve the changelog.
- get_u32 with base = 0 for gbp.
- use PRINT_ANY to support dumping with json format.v2->v3:
- implement proper JSON array for opts.v3->v4:
- keep the same format between input and output, json and non json.
- print gbp as uint.
--- ip/iproute_lwtunnel.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+)
ip/iproute_lwtunnel.c +68 -0
@@ -333,6 +333,26 @@ static void lwtunnel_print_geneve_opts(struct rtattr *attr)close_json_array (PRINT_JSON , name); } +static void lwtunnel_print_vxlan_opts (struct rtattr *attr) +{ +struct rtattr *tb[LWTUNNEL_IP_OPT_VXLAN_MAX +1 ]; +struct rtattr *i =RTA_DATA (attr); +int rem =RTA_PAYLOAD (attr); +char *name ="vxlan_opts" ; +__u32 gbp; + +parse_rtattr (tb,LWTUNNEL_IP_OPT_VXLAN_MAX , i, rem); + gbp =rta_getattr_u32 (tb[LWTUNNEL_IP_OPT_VXLAN_GBP ]); + +print_nl (); +print_string (PRINT_FP , name,"\t%s " , name); +open_json_array (PRINT_JSON , name); +open_json_object (NULL ); +print_uint (PRINT_ANY ,"gdp" ,"%u " , gbp); +close_json_object (); +close_json_array (PRINT_JSON , name); +} +static void lwtunnel_print_opts (struct rtattr *attr) {struct rtattr *tb_opt[LWTUNNEL_IP_OPTS_MAX +1 ];
@@ -340,6 +360,8 @@ static void lwtunnel_print_opts(struct rtattr *attr)parse_rtattr_nested (tb_opt,LWTUNNEL_IP_OPTS_MAX , attr);if (tb_opt[LWTUNNEL_IP_OPTS_GENEVE ])lwtunnel_print_geneve_opts (tb_opt[LWTUNNEL_IP_OPTS_GENEVE ]); +else if (tb_opt[LWTUNNEL_IP_OPTS_VXLAN ]) +lwtunnel_print_vxlan_opts (tb_opt[LWTUNNEL_IP_OPTS_VXLAN ]); }static void print_encap_ip (FILE *fp,struct rtattr *encap)
@@ -938,6 +960,22 @@ static int lwtunnel_parse_geneve_opts(char *str, size_t len, struct rtattr *rta)return 0 ; } +static int lwtunnel_parse_vxlan_opts (char *str,size_t len,struct rtattr *rta) +{ +struct rtattr *nest; +__u32 gbp; +int err; + + nest =rta_nest (rta, len,LWTUNNEL_IP_OPTS_VXLAN |NLA_F_NESTED ); + err =get_u32 (&gbp, str,0 ); +if (err) +return err; +rta_addattr32 (rta, len,LWTUNNEL_IP_OPT_VXLAN_GBP , gbp); + +rta_nest_end (rta, nest); +return 0 ; +} +static int parse_encap_ip (struct rtattr *rta,size_t len,int *argcp,char ***argvp) {
@@ -1009,6 +1047,21 @@ static int parse_encap_ip(struct rtattr *rta, size_t len,invarg ("\"geneve_opts\" value is invalid\n" , *argv);rta_nest_end (rta, nest); + }else if (strcmp (*argv,"vxlan_opts" ) ==0 ) { +struct rtattr *nest; + +if (opts_ok++) +duparg2 ("opts" , *argv); + +NEXT_ARG (); + + nest =rta_nest (rta, len, +LWTUNNEL_IP_OPTS |NLA_F_NESTED ); + ret =lwtunnel_parse_vxlan_opts (*argv, len, rta); +if (ret) +invarg ("\"vxlan_opts\" value is invalid\n" , + *argv); +rta_nest_end (rta, nest); }else if (strcmp (*argv,"key" ) ==0 ) {if (key_ok++)duparg2 ("key" , *argv);
@@ -1193,6 +1246,21 @@ static int parse_encap_ip6(struct rtattr *rta, size_t len,invarg ("\"geneve_opts\" value is invalid\n" , *argv);rta_nest_end (rta, nest); + }else if (strcmp (*argv,"vxlan_opts" ) ==0 ) { +struct rtattr *nest; + +if (opts_ok++) +duparg2 ("opts" , *argv); + +NEXT_ARG (); + + nest =rta_nest (rta, len, +LWTUNNEL_IP_OPTS |NLA_F_NESTED ); + ret =lwtunnel_parse_vxlan_opts (*argv, len, rta); +if (ret) +invarg ("\"vxlan_opts\" value is invalid\n" , + *argv); +rta_nest_end (rta, nest); }else if (strcmp (*argv,"key" ) ==0 ) {if (key_ok++)duparg2 ("key" , *argv);
Signature · 1 line
2.1.0
PATCH v4 3/7 iproute_lwtunnel: add options support for erspan metadata
This patch is to add LWTUNNEL_IP_OPTS_ERSPAN's parse and print to implement erspan options support in iproute_lwtunnel.
Option is expressed as version:index:dir:hwid, dir and hwid will be parsed when version is 2, while index will be parsed when version is 1. All of these are numbers. erspan doesn't support multiple options.
With this patch, users can add and dump erspan options like:
# ip netns add a
# ip netns add b
# ip -n a link add eth0 type veth peer name eth0 netns b
# ip -n a link set eth0 up
# ip -n b link set eth0 up
# ip -n a addr add 10.1.0.1/24 dev eth0
# ip -n b addr add 10.1.0.2/24 dev eth0
# ip -n b link add erspan1 type erspan key 1 seq erspan 123 \
local 10.1.0.2 remote 10.1.0.1
# ip -n b addr add 1.1.1.1/24 dev erspan1
# ip -n b link set erspan1 up
# ip -n b route add 2.1.1.0/24 dev erspan1
# ip -n a link add erspan1 type erspan key 1 seq local 10.1.0.1 external
# ip -n a addr add 2.1.1.1/24 dev erspan1
# ip -n a link set erspan1 up
# ip -n a route add 1.1.1.0/24 encap ip id 1 \
erspan_opts 2:123:1:2 dst 10.1.0.2 dev erspan1
# ip -n a route show
# ip netns exec a ping 1.1.1.1 -c 1 1.1.1.0/24 encap ip id 1 src 0.0.0.0 dst 10.1.0.2 ttl 0 tos 0
erspan_opts 2:0:1:2 dev erspan1 scope link
PING 1.1.1.1 (1.1.1.1) 56(84) bytes of data. 64 bytes from 1.1.1.1: icmp_seq=1 ttl=64 time=0.124 ms
v1->v2:
- improve the changelog.
- use PRINT_ANY to support dumping with json format.v2->v3:
- implement proper JSON object for opts instead of just bunch of strings.v3->v4:
- keep the same format between input and output, json and non json.
- print version, index, dir and hwid as uint.
--- ip/iproute_lwtunnel.c | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+)
ip/iproute_lwtunnel.c +140 -0
@@ -353,6 +353,38 @@ static void lwtunnel_print_vxlan_opts(struct rtattr *attr)close_json_array (PRINT_JSON , name); } +static void lwtunnel_print_erspan_opts (struct rtattr *attr) +{ +struct rtattr *tb[LWTUNNEL_IP_OPT_ERSPAN_MAX +1 ]; +struct rtattr *i =RTA_DATA (attr); +char *name ="erspan_opts" ; +__u8 ver, hwid, dir; +__u32 idx; + +parse_rtattr (tb,LWTUNNEL_IP_OPT_ERSPAN_MAX , i,RTA_PAYLOAD (attr)); + ver =rta_getattr_u8 (tb[LWTUNNEL_IP_OPT_ERSPAN_VER ]); +if (ver ==1 ) { + idx =rta_getattr_be32 (tb[LWTUNNEL_IP_OPT_ERSPAN_INDEX ]); + dir =0 ; + hwid =0 ; + }else { + idx =0 ; + dir =rta_getattr_u8 (tb[LWTUNNEL_IP_OPT_ERSPAN_DIR ]); + hwid =rta_getattr_u8 (tb[LWTUNNEL_IP_OPT_ERSPAN_HWID ]); + } + +print_nl (); +print_string (PRINT_FP , name,"\t%s " , name); +open_json_array (PRINT_JSON , name); +open_json_object (NULL ); +print_uint (PRINT_ANY ,"ver" ,"%u" , ver); +print_uint (PRINT_ANY ,"index" ,":%u" , idx); +print_uint (PRINT_ANY ,"dir" ,":%u" , dir); +print_uint (PRINT_ANY ,"hwid" ,":%u " , hwid); +close_json_object (); +close_json_array (PRINT_JSON , name); +} +static void lwtunnel_print_opts (struct rtattr *attr) {struct rtattr *tb_opt[LWTUNNEL_IP_OPTS_MAX +1 ];
@@ -362,6 +394,8 @@ static void lwtunnel_print_opts(struct rtattr *attr)lwtunnel_print_geneve_opts (tb_opt[LWTUNNEL_IP_OPTS_GENEVE ]); else if (tb_opt[LWTUNNEL_IP_OPTS_VXLAN]) lwtunnel_print_vxlan_opts(tb_opt[LWTUNNEL_IP_OPTS_VXLAN]); + else if (tb_opt[LWTUNNEL_IP_OPTS_ERSPAN]) + lwtunnel_print_erspan_opts(tb_opt[LWTUNNEL_IP_OPTS_ERSPAN]); }static void print_encap_ip (FILE *fp,struct rtattr *encap)
@@ -976,6 +1010,82 @@ static int lwtunnel_parse_vxlan_opts(char *str, size_t len, struct rtattr *rta)return 0 ; } +static int lwtunnel_parse_erspan_opts (char *str,size_t len,struct rtattr *rta) +{ +struct rtattr *nest; +char *token; +int i, err; + + nest =rta_nest (rta, len,LWTUNNEL_IP_OPTS_ERSPAN |NLA_F_NESTED ); + i =1 ; + token =strsep (&str,":" ); +while (token) { +switch (i) { +case LWTUNNEL_IP_OPT_ERSPAN_VER : + { +__u8 opt_type; + +if (!strlen (token)) +break ; + err =get_u8 (&opt_type, token,0 ); +if (err) +return err; + +rta_addattr8 (rta, len, i, opt_type); +break ; + } +case LWTUNNEL_IP_OPT_ERSPAN_INDEX : + { +__be32 opt_class; + +if (!strlen (token)) +break ; + err =get_be32 (&opt_class, token,0 ); +if (err) +return err; + +rta_addattr32 (rta, len, i, opt_class); +break ; + } +case LWTUNNEL_IP_OPT_ERSPAN_DIR : + { +__u8 opt_type; + +if (!strlen (token)) +break ; + err =get_u8 (&opt_type, token,0 ); +if (err) +return err; + +rta_addattr8 (rta, len, i, opt_type); +break ; + } +case LWTUNNEL_IP_OPT_ERSPAN_HWID : + { +__u8 opt_type; + +if (!strlen (token)) +break ; + err =get_u8 (&opt_type, token,0 ); +if (err) +return err; + +rta_addattr8 (rta, len, i, opt_type); +break ; + } +default : +fprintf (stderr,"Unknown \"geneve_opts\" type\n" ); +return -1 ; + } + + token =strsep (&str,":" ); + i++; + } + +rta_nest_end (rta, nest); +return 0 ; +} +static int parse_encap_ip (struct rtattr *rta,size_t len,int *argcp,char ***argvp) {
@@ -1062,6 +1172,21 @@ static int parse_encap_ip(struct rtattr *rta, size_t len,invarg ("\"vxlan_opts\" value is invalid\n" , *argv);rta_nest_end (rta, nest); + }else if (strcmp (*argv,"erspan_opts" ) ==0 ) { +struct rtattr *nest; + +if (opts_ok++) +duparg2 ("opts" , *argv); + +NEXT_ARG (); + + nest =rta_nest (rta, len, +LWTUNNEL_IP_OPTS |NLA_F_NESTED ); + ret =lwtunnel_parse_erspan_opts (*argv, len, rta); +if (ret) +invarg ("\"erspan_opts\" value is invalid\n" , + *argv); +rta_nest_end (rta, nest); }else if (strcmp (*argv,"key" ) ==0 ) {if (key_ok++)duparg2 ("key" , *argv);
@@ -1261,6 +1386,21 @@ static int parse_encap_ip6(struct rtattr *rta, size_t len,invarg ("\"vxlan_opts\" value is invalid\n" , *argv);rta_nest_end (rta, nest); + }else if (strcmp (*argv,"erspan_opts" ) ==0 ) { +struct rtattr *nest; + +if (opts_ok++) +duparg2 ("opts" , *argv); + +NEXT_ARG (); + + nest =rta_nest (rta, len, +LWTUNNEL_IP_OPTS |NLA_F_NESTED ); + ret =lwtunnel_parse_erspan_opts (*argv, len, rta); +if (ret) +invarg ("\"erspan_opts\" value is invalid\n" , + *argv); +rta_nest_end (rta, nest); }else if (strcmp (*argv,"key" ) ==0 ) {if (key_ok++)duparg2 ("key" , *argv);
Signature · 1 line
2.1.0
PATCH v4 4/7 tc: m_tunnel_key: add options support for vxlan
This patch is to add TCA_TUNNEL_KEY_ENC_OPTS_VXLAN's parse and print to implement vxlan options support in m_tunnel_key, like Commit 6217917a3826 ("tc: m_tunnel_key: Add tunnel option support to act_tunnel_key") for geneve options support.
Option is expressed a 32bit number for gbp only, and vxlan doesn't support multiple options.
With this patch, users can add and dump vxlan options like:
# ip link add name vxlan1 type vxlan dstport 0 external
# tc qdisc add dev eth0 ingress
# tc filter add dev eth0 protocol ip parent ffff: \
flower indev eth0 \
ip_proto udp \
action tunnel_key \
set src_ip 10.0.99.192 \
dst_ip 10.0.99.193 \
dst_port 6081 \
id 11 \
vxlan_opts 65793 \
action mirred egress redirect dev vxlan1
# tc -s filter show dev eth0 parent ffff: filter protocol ip pref 49152 flower chain 0 handle 0x1
indev eth0
eth_type ipv4
ip_proto udp
not_in_hw
action order 1: tunnel_key set
src_ip 10.0.99.192
dst_ip 10.0.99.193
key_id 11
dst_port 6081
vxlan_opts 65793
...v1->v2:
- get_u32 with base = 0 for gbp.
- use to print_unint("0x%x") to print gbp.v2->v3:
- implement proper JSON array for opts.v3->v4:
- keep the same format between input and output, json and non json.
- print gbp as uint.
--- man/man8/tc-tunnel_key.8 | 10 +++++- tc/m_tunnel_key.c | 84 ++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 84 insertions(+), 10 deletions(-)
man/man8/tc-tunnel_key.8 +9 -1
@@ -66,8 +66,10 @@ options. .B id , .B dst_port -and +, .B geneve_opts +and +.B vxlan_opts are optional. .RS .TP
@@ -91,6 +93,12 @@ is specified in the form CLASS:TYPE:DATA, where CLASS is represented as a variable length hexadecimal value. Additionally multiple options may be listed using a comma delimiter. .TP +.B vxlan_opts +Vxlan metatdata options. +.B vxlan_opts +is specified in the form GBP, as a 32bit number. Multiple options is not +supported. +.TP .B tos Outer header TOS .TP
tc/m_tunnel_key.c +75 -9
143 lines not on this page · raw message
Signature · 1 line
2.1.0
PATCH v4 5/7 tc: m_tunnel_key: add options support for erpsan
This patch is to add TCA_TUNNEL_KEY_ENC_OPTS_ERSPAN's parse and print to implement erspan options support in m_tunnel_key, like Commit 6217917a3826 ("tc: m_tunnel_key: Add tunnel option support to act_tunnel_key") for geneve options support.
Option is expressed as version:index:dir:hwid, dir and hwid will be parsed when version is 2, while index will be parsed when version is 1. erspan doesn't support multiple options.
With this patch, users can add and dump erspan options like:
# ip link add name erspan1 type erspan external
# tc qdisc add dev eth0 ingress
# tc filter add dev eth0 protocol ip parent ffff: \
flower indev eth0 \
ip_proto udp \
action tunnel_key \
set src_ip 10.0.99.192 \
dst_ip 10.0.99.193 \
dst_port 6081 \
id 11 \
erspan_opts 1:2:0:0 \
action mirred egress redirect dev erspan1
# tc -s filter show dev eth0 parent ffff: filter protocol ip pref 49151 flower chain 0 handle 0x1
indev eth0
eth_type ipv4
ip_proto udp
not_in_hw
action order 1: tunnel_key set
src_ip 10.0.99.192
dst_ip 10.0.99.193
key_id 11
dst_port 6081
erspan_opts 1:2:0:0
csum pipe
index 2 ref 1 bind 1
...v1->v2:
- no change.v2->v3:
- no change.v3->v4:
- keep the same format between input and output, json and non json.
- print version, index, dir and hwid as uint.
--- man/man8/tc-tunnel_key.8 | 12 ++++- tc/m_tunnel_key.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 127 insertions(+), 2 deletions(-)
man/man8/tc-tunnel_key.8 +11 -1
@@ -68,8 +68,10 @@ options. .B dst_port , .B geneve_opts -and +, .B vxlan_opts +and +.B erspan_opts are optional. .RS .TP
@@ -99,6 +101,14 @@ Vxlan metatdata options. is specified in the form GBP, as a 32bit number. Multiple options is not supported. .TP +.B erspan_opts +Erspan metatdata options. +.B erspan_opts +is specified in the form VERSION:INDEX:DIR:HWID, where VERSION is represented +as a 8bit number, INDEX as an 32bit number, DIR and HWID as a 8bit number. +Multiple options is not supported. Note INDEX is used when VERSION is 1, +and DIR and HWID are used when VERSION is 2. +.TP .B tos Outer header TOS .TP
tc/m_tunnel_key.c +116 -1
153 lines not on this page · raw message
Signature · 1 line
2.1.0
PATCH v4 6/7 tc: f_flower: add options support for vxlan
This patch is to add TCA_FLOWER_KEY_ENC_OPTS_VXLAN's parse and print to implement vxlan options support in m_tunnel_key, like Commit 56155d4df86d ("tc: f_flower: add geneve option match support to flower") for geneve options support.
Option is expressed a 32bit number for gbp only, and vxlan doesn't support multiple options.
With this patch, users can add and dump vxlan options like:
# ip link add name vxlan1 type vxlan dstport 0 external
# tc qdisc add dev vxlan1 ingress
# tc filter add dev vxlan1 protocol ip parent ffff: \
flower \
enc_src_ip 10.0.99.192 \
enc_dst_ip 10.0.99.193 \
enc_key_id 11 \
vxlan_opts 65793/4008635966 \
ip_proto udp \
action mirred egress redirect dev eth1
# tc -s filter show dev vxlan1 parent ffff: filter protocol ip pref 49152 flower chain 0 handle 0x1
eth_type ipv4
ip_proto udp
enc_dst_ip 10.0.99.193
enc_src_ip 10.0.99.192
enc_key_id 11
vxlan_opts 65793/4008635966
not_in_hw
action order 1: mirred (Egress Redirect to device eth1) stolen
index 3 ref 1 bind 1
Action statistics:
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
backlog 0b 0p requeues 0v1->v2:
- get_u32 with base = 0 for gbp.v2->v3:
- implement proper JSON array for opts.v3->v4:
- keep the same format between input and output, json and non json.
- print gbp as uint.
--- man/man8/tc-flower.8 | 12 +++++ tc/f_flower.c | 130 ++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 126 insertions(+), 16 deletions(-)
man/man8/tc-flower.8 +12 -0
@@ -81,7 +81,11 @@ flower \- flow based traffic control filter .IR TOS " | " .B enc_ttl .IR TTL " | " +{ .B geneve_opts +| +.B vxlan_opts +} .IR OPTIONS " | " .BR ip_flags .IR IP_FLAGS
@@ -326,6 +330,8 @@ Match the connection zone, and can be masked. .RE .TP .BI geneve_opts " OPTIONS" +.TQ +.BI vxlan_opts " OPTIONS" Match on IP tunnel metadata. Key id .I NUMBER is a 32 bit tunnel key id (e.g. VNI for VXLAN tunnel).
@@ -346,6 +352,12 @@ the masks is missing, \fBtc\fR assumes a full-length match. The options can be described in the form CLASS:TYPE:DATA/CLASS_MASK:TYPE_MASK:DATA_MASK, where CLASS is represented as a 16bit hexadecimal value, TYPE as an 8bit hexadecimal value and DATA as a variable length hexadecimal value. +vxlan_opts +.I OPTIONS +doesn't support multiple options, and it consists of a key followed by a slash +and corresponding mask. If the mask is missing, \fBtc\fR assumes a full-length +match. The option can be described in the form GBP/GBP_MASK, where GBP is +represented as a 32bit number. .TP .BI ip_flags " IP_FLAGS" .I IP_FLAGS
tc/f_flower.c +114 -16
196 lines not on this page · raw message
Signature · 1 line
2.1.0
PATCH v4 7/7 tc: f_flower: add options support for erspan
This patch is to add TCA_FLOWER_KEY_ENC_OPTS_ERSPAN's parse and print to implement erspan options support in m_tunnel_key, like Commit 56155d4df86d ("tc: f_flower: add geneve option match support to flower") for geneve options support.
Option is expressed as version:index:dir:hwid, dir and hwid will be parsed when version is 2, while index will be parsed when version is 1. erspan doesn't support multiple options.
With this patch, users can add and dump erspan options like:
# ip link add name erspan1 type erspan external
# tc qdisc add dev erspan1 ingress
# tc filter add dev erspan1 protocol ip parent ffff: \
flower \
enc_src_ip 10.0.99.192 \
enc_dst_ip 10.0.99.193 \
enc_key_id 11 \
erspan_opts 1:2:0:0/1:255:0:0 \
ip_proto udp \
action mirred egress redirect dev eth1
# tc -s filter show dev erspan1 parent ffff: filter protocol ip pref 49152 flower chain 0 handle 0x1
eth_type ipv4
ip_proto udp
enc_dst_ip 10.0.99.193
enc_src_ip 10.0.99.192
enc_key_id 11
erspan_opts 1:2:0:0/1:255:0:0
not_in_hw
action order 1: mirred (Egress Redirect to device eth1) stolen
index 1 ref 1 bind 1
Action statistics:
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
backlog 0b 0p requeues 0v1->v2:
- no change.v2->v3:
- no change.v3->v4:
- keep the same format between input and output, json and non json.
- print version, index, dir and hwid as uint.
--- man/man8/tc-flower.8 | 13 ++++ tc/f_flower.c | 171 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 184 insertions(+)
man/man8/tc-flower.8 +13 -0
@@ -85,6 +85,8 @@ flower \- flow based traffic control filter .B geneve_opts | .B vxlan_opts +| +.B erspan_opts } .IR OPTIONS " | " .BR ip_flags
@@ -332,6 +334,8 @@ Match the connection zone, and can be masked. .BI geneve_opts " OPTIONS" .TQ .BI vxlan_opts " OPTIONS" +.TQ +.BI erspan_opts " OPTIONS" Match on IP tunnel metadata. Key id .I NUMBER is a 32 bit tunnel key id (e.g. VNI for VXLAN tunnel).
@@ -358,6 +362,15 @@ doesn't support multiple options, and it consists of a key followed by a slash and corresponding mask. If the mask is missing, \fBtc\fR assumes a full-length match. The option can be described in the form GBP/GBP_MASK, where GBP is represented as a 32bit number. +erspan_opts +.I OPTIONS +doesn't support multiple options, and it consists of a key followed by a slash +and corresponding mask. If the mask is missing, \fBtc\fR assumes a full-length +match. The option can be described in the form +VERSION:INDEX:DIR:HWID/VERSION:INDEX_MASK:DIR_MASK:HWID_MASK, where VERSION is +represented as a 8bit number, INDEX as an 32bit number, DIR and HWID as a 8bit +number. Multiple options is not supported. Note INDEX/INDEX_MASK is used when +VERSION is 1, and DIR/DIR_MASK and HWID/HWID_MASK are used when VERSION is 2. .TP .BI ip_flags " IP_FLAGS" .I IP_FLAGS
tc/f_flower.c +171 -0
207 lines not on this page · raw message
Signature · 1 line
2.1.0
Re: [PATCHv4 iproute2-next 2/7] iproute_lwtunnel: add options support for vxlan metadata
In reply to Xin LongQuoted 14 lines · Xin Long
ip/iproute_lwtunnel.c +6
-0@@ -333,6 +333,26 @@ static void lwtunnel_print_geneve_opts(struct rtattr *attr)close_json_array (PRINT_JSON , name); } +static void lwtunnel_print_vxlan_opts (struct rtattr *attr) +{ +struct rtattr *tb[LWTUNNEL_IP_OPT_VXLAN_MAX +1 ]; +struct rtattr *i =RTA_DATA (attr); +int rem =RTA_PAYLOAD (attr); +char *name ="vxlan_opts" ;
ip/iproute_lwtunnel.c static void lwtunnel_print_geneve_opts(struct rtattr *attr) · line 351
Quoted 10 lines
ip/iproute_lwtunnel.c +10
-0+__u32 gbp; + +parse_rtattr (tb,LWTUNNEL_IP_OPT_VXLAN_MAX , i, rem); + gbp =rta_getattr_u32 (tb[LWTUNNEL_IP_OPT_VXLAN_GBP ]); + +print_nl (); +print_string (PRINT_FP , name,"\t%s " , name); +open_json_array (PRINT_JSON , name); +open_json_object (NULL ); +print_uint (PRINT_ANY ,"gdp" ,"%u " , gbp);
gdp? should that be 'gbp'?
Re: [PATCHv4 iproute2-next 2/7] iproute_lwtunnel: add options support for vxlan metadata
Quoted 20 lines · David Ahern
Quoted 18 lines · Xin Long
ip/iproute_lwtunnel.c +10
-0@@ -333,6 +333,26 @@ static void lwtunnel_print_geneve_opts(struct rtattr *attr)close_json_array (PRINT_JSON , name); } +static void lwtunnel_print_vxlan_opts (struct rtattr *attr) +{ +struct rtattr *tb[LWTUNNEL_IP_OPT_VXLAN_MAX +1 ]; +struct rtattr *i =RTA_DATA (attr); +int rem =RTA_PAYLOAD (attr); +char *name ="vxlan_opts" ; +__u32 gbp; + +parse_rtattr (tb,LWTUNNEL_IP_OPT_VXLAN_MAX , i, rem); + gbp =rta_getattr_u32 (tb[LWTUNNEL_IP_OPT_VXLAN_GBP ]);
Quoted 8 lines
ip/iproute_lwtunnel.c static void lwtunnel_print_geneve_opts(struct rtattr *attr) · line 351
Quoted 6 lines
ip/iproute_lwtunnel.c +6
-0+ +print_nl (); +print_string (PRINT_FP , name,"\t%s " , name); +open_json_array (PRINT_JSON , name); +open_json_object (NULL ); +print_uint (PRINT_ANY ,"gdp" ,"%u " , gbp);gdp? should that be 'gbp'?
Right, should be 'gbp'. Sorry.
The same mistake also exists in:
[PATCHv4 iproute2-next 4/7] tc: m_tunnel_key: add options support for vxlan
Any other comments? Otherwise, I will post v5 with the fix.
Thanks.
Re: [PATCHv4 iproute2-next 2/7] iproute_lwtunnel: add options support for vxlan metadata
Quoted 6 lines · Xin Long
Quoted 2 lines
gdp? should that be 'gbp'?
Right, should be 'gbp'. Sorry.
The same mistake also exists in:[PATCHv4 iproute2-next 4/7] tc:
m_tunnel_key: add options support for vxlan
yep, saw that.
Quoted 3 lines
Any other comments? Otherwise, I will post v5 with the fix.
LGTM. I can just edit the patches and fix before applying.
Re: [PATCHv4 iproute2-next 2/7] iproute_lwtunnel: add options support for vxlan metadata
Quoted 9 lines · David Ahern
Quoted 6 lines · Xin Long
Quoted 2 lines
gdp? should that be 'gbp'?
Right, should be 'gbp'. Sorry.
The same mistake also exists in:[PATCHv4 iproute2-next 4/7] tc:
m_tunnel_key: add options support for vxlan
Quoted 7 lines
yep, saw that.
Quoted 3 lines
Any other comments? Otherwise, I will post v5 with the fix.
LGTM. I can just edit the patches and fix before applying.
Great. thanks!
Quoted 11 lines · Xin Long
Patch 1-3 add the geneve/vxlan/erspan options support for
iproute_lwtunnel, and Patch 4-5 add the vxlan/erspan options for tcm_tunnel_key, and Patch 6-7 add the vxlan/erspan options for tcf_flower.In kernel space, these features have been supported since these patchsets:
https://patchwork.ozlabs.org/cover/1190172/
https://patchwork.ozlabs.org/cover/1198854/
fixed the gdp -> gbp typo and applied to iproute2-next. Thanks