iproute2: fully support for geneve/vxlan/erspan options
Subsystems (2)
v2 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.
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 | 364 ++++++++++++++++++++++++++++++++++++++++++++++- man/man8/tc-flower.8 | 26 ++++ man/man8/tc-tunnel_key.8 | 20 ++- tc/f_flower.c | 300 +++++++++++++++++++++++++++++++++++--- tc/m_tunnel_key.c | 207 +++++++++++++++++++++++++-- 5 files changed, 889 insertions(+), 28 deletions(-)
Signature · 1 line
2.1.0
PATCH v2 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 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 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
v1->v2:
- improve the changelog.
- use PRINT_ANY to support dumping with json format.
--- ip/iproute_lwtunnel.c | 171 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 169 insertions(+), 2 deletions(-)
ip/iproute_lwtunnel.c +169 -2
@@ -294,6 +294,51 @@ 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_nl (); +print_string (PRINT_ANY ,"geneve_opts" ," 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 +377,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 +452,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 +849,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 +991,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 +1121,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 +1175,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 v2 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 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 0x456 dst 10.1.0.2 dev vxlan1
# 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
vxlan_opts 0x456 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.
--- ip/iproute_lwtunnel.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+)
ip/iproute_lwtunnel.c +60 -0
@@ -322,6 +322,18 @@ static void lwtunnel_print_geneve_opts(struct rtattr *attr, char *opt)print_string (PRINT_ANY ,"geneve_opts" ," 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 ]); +print_nl (); +print_uint (PRINT_ANY ,"vxlan_opts" ," vxlan_opts 0x%x " , gbp); +} +static void lwtunnel_print_opts (struct rtattr *attr) {struct rtattr *tb_opt[LWTUNNEL_IP_OPTS_MAX +1 ];
@@ -335,6 +347,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); }
@@ -935,6 +949,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) {
@@ -1006,6 +1036,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);
@@ -1190,6 +1235,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 v2 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 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 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
v1->v2:
- improve the changelog.
- use PRINT_ANY to support dumping with json format.
--- ip/iproute_lwtunnel.c | 133 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+)
ip/iproute_lwtunnel.c +133 -0
@@ -334,6 +334,30 @@ static void lwtunnel_print_vxlan_opts(struct rtattr *attr, char *opt)print_uint (PRINT_ANY ,"vxlan_opts" ," vxlan_opts 0x%x " , gbp); } +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_nl (); +print_string (PRINT_ANY ,"erspan_opts" ," erspan_opts %s " , opt); +} +static void lwtunnel_print_opts (struct rtattr *attr) {struct rtattr *tb_opt[LWTUNNEL_IP_OPTS_MAX +1 ];
@@ -349,6 +373,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); }
@@ -965,6 +992,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) {
@@ -1051,6 +1154,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);
@@ -1250,6 +1368,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 v2 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 0x10101 \
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 0x10101
...v1->v2:
- get_u32 with base = 0 for gbp.
- use to print_unint("0x%x") to print gbp.
--- man/man8/tc-tunnel_key.8 | 10 +++++- tc/m_tunnel_key.c | 87 +++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 87 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 +78 -9
146 lines not on this page · raw message
Signature · 1 line
2.1.0
PATCH v2 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
...v1->v2:
- no change.
--- 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 v2 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 0x10101/0xeeeeee3e \
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 0x10101/0xeeeeee3e
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.
--- 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 v2 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 0v1->v2:
- no change.
--- 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: [PATCHv2 iproute2-next 1/7] iproute_lwtunnel: add options support for geneve metadata
In reply to Xin Longip/iproute_lwtunnel.c static void print_encap_mpls(FILE *fp, struct rtattr *encap) · line 324
Quoted 13 lines · On Thu, 13 Feb 2020 19:56:59 +0800 Xin Long <[email protected]> wrote:
ip/iproute_lwtunnel.c +13
-0+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) +
Please implement proper JSON array for these. Not just bunch of strings.
Re: [PATCHv2 iproute2-next 1/7] iproute_lwtunnel: add options support for geneve metadata
Quoted 18 lines · Stephen Hemminger
ip/iproute_lwtunnel.c static void print_encap_mpls(FILE *fp, struct rtattr *encap) · line 324
Quoted 13 lines · On Thu, 13 Feb 2020 19:56:59 +0800 Xin Long <[email protected]> wrote:
ip/iproute_lwtunnel.c +13
-0+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) +
Quoted 1 line
Please implement proper JSON array for these. Not just bunch of strings.
will post v3, thanks