iproute2: fully support for geneve/vxlan/erspan options
Subsystems (2)
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/
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 | 362 ++++++++++++++++++++++++++++++++++++++++++++++- man/man8/tc-flower.8 | 26 ++++ man/man8/tc-tunnel_key.8 | 20 ++- tc/f_flower.c | 300 ++++++++++++++++++++++++++++++++++++--- tc/m_tunnel_key.c | 209 +++++++++++++++++++++++++-- 5 files changed, 889 insertions(+), 28 deletions(-)
Signature · 1 line
2.1.0
PATCH 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.
With this patch, users can add and dump geneve options like:
# ip net d a; ip net d b; ip net a a; ip net a b
# ip -n a l a eth0 type veth peer name eth0 netns b
# ip -n a l s eth0 up; ip -n b link set eth0 up
# ip -n a a a 10.1.0.1/24 dev eth0; ip -n b a a 10.1.0.2/24 dev eth0
# ip -n b l a geneve1 type geneve id 1 remote 10.1.0.1 ttl 64
# ip -n b a a 1.1.1.1/24 dev geneve1; ip -n b l s geneve1 up
# ip -n b r a 2.1.1.0/24 dev geneve1
# ip -n a l a geneve1 type geneve external
# ip -n a a a 2.1.1.1/24 dev geneve1; ip -n a l s geneve1 up
# ip -n a r a 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 r s; echo ''; ip net 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 0001:01:1212121234567890,0001:01: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
--- ip/iproute_lwtunnel.c | 170 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 168 insertions(+), 2 deletions(-)
ip/iproute_lwtunnel.c +168 -2
@@ -294,6 +294,50 @@ 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,char *opt) +{ +struct rtattr *tb[LWTUNNEL_IP_OPT_GENEVE_MAX +1 ]; +int data_len, offset =0 , slen =0 ; +struct rtattr *i =RTA_DATA (attr); +int rem =RTA_PAYLOAD (attr); +char data[rem *2 +1 ]; +__u16 class; +__u8 type; + +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; + slen +=sprintf (opt + slen,"%04x:%02x:%s" , class, type, data); +if (rem) + slen +=sprintf (opt + slen,"," ); + } +print_string (PRINT_FP ,"enc_opt" ,"\n geneve_opts %s " , opt); +} + +static void lwtunnel_print_opts (struct rtattr *attr) +{ +struct rtattr *tb_opt[LWTUNNEL_IP_OPTS_MAX +1 ]; +char *opt; + + opt =malloc (RTA_PAYLOAD (attr) *2 +1 ); +if (!opt) +return ; + +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 ], + opt); + +free (opt); +} +static void print_encap_ip (FILE *fp,struct rtattr *encap) {struct rtattr *tb[LWTUNNEL_IP_MAX +1 ];
@@ -332,6 +376,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 +451,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 +848,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,16 ); +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,16 ); +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 +990,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 +1120,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 +1174,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 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 one hex value for gbp only, and vxlan doesn't support multiple options.
With this patch, users can add and dump vxlan options like:
# ip net d a; ip net d b; ip net a a; ip net a b
# ip -n a l a eth0 type veth peer name eth0 netns b
# ip -n a l s eth0 up; ip -n b link set eth0 up
# ip -n a a a 10.1.0.1/24 dev eth0; ip -n b a a 10.1.0.2/24 dev eth0
# ip -n b l a vxlan1 type vxlan id 1 local 10.1.0.2 remote 10.1.0.1 \
dev eth0 ttl 64 gbp
# ip -n b a a 1.1.1.1/24 dev vxlan1; ip -n b l s vxlan1 up
# ip -n b r a 2.1.1.0/24 dev vxlan1
# ip -n a l a vxlan1 type vxlan local 10.1.0.1 dev eth0 ttl 64 \
gbp external
# ip -n a a a 2.1.1.1/24 dev vxlan1; ip -n a l s vxlan1 up
# ip -n a r a 1.1.1.0/24 encap ip id 1 \
vxlan_opts 456 dst 10.1.0.2 dev vxlan1
# ip -n a r s; echo ''; ip net 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 456 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
--- ip/iproute_lwtunnel.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+)
ip/iproute_lwtunnel.c +60 -0
@@ -321,6 +321,18 @@ static void lwtunnel_print_geneve_opts(struct rtattr *attr, char *opt)print_string (PRINT_FP ,"enc_opt" ,"\n geneve_opts %s " , opt); } +static void lwtunnel_print_vxlan_opts (struct rtattr *attr,char *opt) +{ +struct rtattr *tb[LWTUNNEL_IP_OPT_VXLAN_MAX +1 ]; +__u32 gbp; + +parse_rtattr (tb,LWTUNNEL_IP_OPT_VXLAN_MAX ,RTA_DATA (attr), +RTA_PAYLOAD (attr)); + gbp =rta_getattr_u32 (tb[LWTUNNEL_IP_OPT_VXLAN_GBP ]); +sprintf (opt,"%x" , gbp); +print_string (PRINT_FP ,"enc_opt" ,"\n vxlan_opts %s " , opt); +} +static void lwtunnel_print_opts (struct rtattr *attr) {struct rtattr *tb_opt[LWTUNNEL_IP_OPTS_MAX +1 ];
@@ -334,6 +346,8 @@ static void lwtunnel_print_opts(struct rtattr *attr)if (tb_opt[LWTUNNEL_IP_OPTS_GENEVE ])lwtunnel_print_geneve_opts (tb_opt[LWTUNNEL_IP_OPTS_GENEVE ], opt); +else if (tb_opt[LWTUNNEL_IP_OPTS_VXLAN ]) +lwtunnel_print_vxlan_opts (tb_opt[LWTUNNEL_IP_OPTS_VXLAN ], opt);free (opt); }
@@ -934,6 +948,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,16 ); +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) {
@@ -1005,6 +1035,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);
@@ -1189,6 +1234,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 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. erspan doesn't support multiple options.
With this patch, users can add and dump erspan options like:
# ip net d a; ip net d b; ip net a a; ip net a b
# ip -n a l a eth0 type veth peer name eth0 netns b
# ip -n a l s eth0 up; ip -n b link set eth0 up
# ip -n a a a 10.1.0.1/24 dev eth0; ip -n b a a 10.1.0.2/24 dev eth0
# ip -n b l a erspan1 type erspan key 1 seq erspan 123 \
local 10.1.0.2 remote 10.1.0.1
# ip -n b a a 1.1.1.1/24 dev erspan1; ip -n b l s erspan1 up
# ip -n b r a 2.1.1.0/24 dev erspan1
# ip -n a l a erspan1 type erspan key 1 seq local 10.1.0.1 external
# ip -n a a a 2.1.1.1/24 dev erspan1; ip -n a l s erspan1 up
# ip -n a r a 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 r s; ip net 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
erspan_opts 02:00000000:01:02 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
--- ip/iproute_lwtunnel.c | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+)
ip/iproute_lwtunnel.c +132 -0
@@ -333,6 +333,29 @@ static void lwtunnel_print_vxlan_opts(struct rtattr *attr, char *opt)print_string (PRINT_FP ,"enc_opt" ,"\n vxlan_opts %s " , opt); } +static void lwtunnel_print_erspan_opts (struct rtattr *attr,char *opt) +{ +struct rtattr *tb[LWTUNNEL_IP_OPT_ERSPAN_MAX +1 ]; +__u8 ver, hwid, dir; +__u32 index; + +parse_rtattr (tb,LWTUNNEL_IP_OPT_ERSPAN_MAX ,RTA_DATA (attr), +RTA_PAYLOAD (attr)); + ver =rta_getattr_u8 (tb[LWTUNNEL_IP_OPT_ERSPAN_VER ]); +if (ver ==1 ) { + index =rta_getattr_be32 (tb[LWTUNNEL_IP_OPT_ERSPAN_INDEX ]); + hwid =0 ; + dir =0 ; + }else { + index =0 ; + hwid =rta_getattr_u8 (tb[LWTUNNEL_IP_OPT_ERSPAN_HWID ]); + dir =rta_getattr_u8 (tb[LWTUNNEL_IP_OPT_ERSPAN_DIR ]); + } + +sprintf (opt,"%02x:%08x:%02x:%02x" , ver, index, dir, hwid); +print_string (PRINT_FP ,"enc_opt" ,"\n erspan_opts %s " , opt); +} +static void lwtunnel_print_opts (struct rtattr *attr) {struct rtattr *tb_opt[LWTUNNEL_IP_OPTS_MAX +1 ];
@@ -348,6 +371,9 @@ static void lwtunnel_print_opts(struct rtattr *attr) opt); else if (tb_opt[LWTUNNEL_IP_OPTS_VXLAN]) lwtunnel_print_vxlan_opts(tb_opt[LWTUNNEL_IP_OPTS_VXLAN], opt); + else if (tb_opt[LWTUNNEL_IP_OPTS_ERSPAN]) + lwtunnel_print_erspan_opts(tb_opt[LWTUNNEL_IP_OPTS_ERSPAN], + opt);free (opt); }
@@ -964,6 +990,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,16 ); +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,16 ); +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,16 ); +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,16 ); +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) {
@@ -1050,6 +1152,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);
@@ -1249,6 +1366,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 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 hexadecimal value 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 010101 \
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 00010101
...--- man/man8/tc-tunnel_key.8 | 10 +++++- tc/m_tunnel_key.c | 89 +++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 89 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 hexadecimal value. Multiple options +is not supported. +.TP .B tos Outer header TOS .TP
tc/m_tunnel_key.c +80 -9
148 lines not on this page · raw message
Signature · 1 line
2.1.0
PATCH 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 01:00000002:00:00
csum pipe
index 2 ref 1 bind 1
...--- man/man8/tc-tunnel_key.8 | 12 ++++- tc/m_tunnel_key.c | 122 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 132 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 hexadecimal value. 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 hexadecimal value, INDEX as an 32bit hexadecimal value, DIR and HWID +as a 8bit hexadecimal value. 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 +121 -1
158 lines not on this page · raw message
Signature · 1 line
2.1.0
PATCH 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 hexadecimal value 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 010101/eeeeee3e \
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_opt 00010101/eeeeee3e
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 0--- man/man8/tc-flower.8 | 12 +++++ tc/f_flower.c | 129 ++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 125 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 hexadecimal value. .TP .BI ip_flags " IP_FLAGS" .I IP_FLAGS
tc/f_flower.c +113 -16
195 lines not on this page · raw message
Signature · 1 line
2.1.0
PATCH 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/01:ffffffff:00:00 \
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_opt 01:00000002:00:00/01:ffffffff:00:00
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 0--- man/man8/tc-flower.8 | 14 +++++ tc/f_flower.c | 171 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 185 insertions(+)
man/man8/tc-flower.8 +14 -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,16 @@ 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 hexadecimal value. +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 hexadecimal value, INDEX as an 32bit hexadecimal value, +DIR and HWID as a 8bit hexadecimal value. 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: [PATCH iproute2-next 2/7] iproute_lwtunnel: add options support for vxlan metadata
In reply to Xin Longip/iproute_lwtunnel.c static void lwtunnel_print_geneve_opts(struct rtattr *attr, char *opt) · line 333
Quoted 10 lines · On Mon, 3 Feb 2020 13:39:53 +0800 Xin Long <[email protected]> wrote:
ip/iproute_lwtunnel.c +10
-0+static void lwtunnel_print_vxlan_opts (struct rtattr *attr,char *opt) +{ +struct rtattr *tb[LWTUNNEL_IP_OPT_VXLAN_MAX +1 ]; +__u32 gbp; + +parse_rtattr (tb,LWTUNNEL_IP_OPT_VXLAN_MAX ,RTA_DATA (attr), +RTA_PAYLOAD (attr)); + gbp =rta_getattr_u32 (tb[LWTUNNEL_IP_OPT_VXLAN_GBP ]); +sprintf (opt,"%x" , gbp); +print_string (PRINT_FP ,"enc_opt" ,"\n vxlan_opts %s " , opt);
You need to handle single line mode and JSON.
Proper way is something like:
print_nl(); print_0xhex(PRINT_ANY, "enc_opt", " vxlan_opts %#x", gpb);
Also, why the hex format, this is a an opaque user interface?
Re: [PATCH iproute2-next 2/7] iproute_lwtunnel: add options support for vxlan metadata
Quoted 17 lines · Stephen Hemminger
ip/iproute_lwtunnel.c static void lwtunnel_print_geneve_opts(struct rtattr *attr, char *opt) · line 333
Quoted 10 lines · On Mon, 3 Feb 2020 13:39:53 +0800 Xin Long <[email protected]> wrote:
ip/iproute_lwtunnel.c +10
-0+static void lwtunnel_print_vxlan_opts (struct rtattr *attr,char *opt) +{ +struct rtattr *tb[LWTUNNEL_IP_OPT_VXLAN_MAX +1 ]; +__u32 gbp; + +parse_rtattr (tb,LWTUNNEL_IP_OPT_VXLAN_MAX ,RTA_DATA (attr), +RTA_PAYLOAD (attr)); + gbp =rta_getattr_u32 (tb[LWTUNNEL_IP_OPT_VXLAN_GBP ]); +sprintf (opt,"%x" , gbp); +print_string (PRINT_FP ,"enc_opt" ,"\n vxlan_opts %s " , opt);You need to handle single line mode and JSON.
Quoted 5 lines
Proper way is something like:
print_nl(); print_0xhex(PRINT_ANY, "enc_opt", " vxlan_opts %#x", gpb);
yeah, right, didn't notice that, thanks.
Quoted 2 lines
Also, why the hex format, this is a an opaque user interface?
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|G|R|R|R|I|R|R|R|R|D|R|R|A|R|R|R| Group Policy ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+This is the gbp field in vxlan header, defined in:
https://tools.ietf.org/html/draft-smith-vxlan-group-policy-05
I think 'hex' makes it clearer than decimal to see which bit is set for users, no?
Re: [PATCH iproute2-next 1/7] iproute_lwtunnel: add options support for geneve metadata
In reply to Xin LongQuoted 8 lines · Xin Long
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.
With this patch, users can add and dump geneve options like:
Quoted 14 lines
# ip net d a; ip net d b; ip net a a; ip net a b
# ip -n a l a eth0 type veth peer name eth0 netns b
# ip -n a l s eth0 up; ip -n b link set eth0 up
# ip -n a a a 10.1.0.1/24 dev eth0; ip -n b a a 10.1.0.2/24 dev eth0
# ip -n b l a geneve1 type geneve id 1 remote 10.1.0.1 ttl 64
# ip -n b a a 1.1.1.1/24 dev geneve1; ip -n b l s geneve1 up
# ip -n b r a 2.1.1.0/24 dev geneve1
# ip -n a l a geneve1 type geneve external
# ip -n a a a 2.1.1.1/24 dev geneve1; ip -n a l s geneve1 up
# ip -n a r a 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 r s; echo ''; ip net exec a ping 1.1.1.1 -c 1Thanks for the command list and example. It would be a lot easier to read if commands were 1 per line and used the long form.
Same for patches 2 and 3
Re: [PATCH iproute2-next 1/7] iproute_lwtunnel: add options support for geneve metadata
Quoted 25 lines · David Ahern
Quoted 8 lines · Xin Long
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.
With this patch, users can add and dump geneve options like:
Quoted 14 lines
# ip net d a; ip net d b; ip net a a; ip net a b # ip -n a l a eth0 type veth peer name eth0 netns b # ip -n a l s eth0 up; ip -n b link set eth0 up # ip -n a a a 10.1.0.1/24 dev eth0; ip -n b a a 10.1.0.2/24 dev eth0 # ip -n b l a geneve1 type geneve id 1 remote 10.1.0.1 ttl 64 # ip -n b a a 1.1.1.1/24 dev geneve1; ip -n b l s geneve1 up # ip -n b r a 2.1.1.0/24 dev geneve1 # ip -n a l a geneve1 type geneve external # ip -n a a a 2.1.1.1/24 dev geneve1; ip -n a l s geneve1 up # ip -n a r a 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 r s; echo ''; ip net exec a ping 1.1.1.1 -c 1
Quoted 2 lines
Thanks for the command list and example. It would be a lot easier to read if commands were 1 per line and used the long form.
Yep, thanks, will do in v2.
Quoted 3 lines
Same for patches 2 and 3