erspan: add erspan version II support
Subsystems (2)
PATCH v2 1/1 erspan: add erspan version II support
The patch adds support for configuring the erspan v2, for both ipv4 and ipv6 erspan implementation. Three additional fields are added: 'erspan_ver' for distinguishing v1 or v2, 'erspan_dir' for specifying direction of the mirrored traffic, and 'erspan_hwid' for users to set ERSPAN engine ID within a system.
As for manpage, the ERSPAN descriptions used to be under GRE, IPIP, SIT Type paragraph. Since IP6GRE/IP6GRETAP also supports ERSPAN, the patch removes the old one, creates a separate ERSPAN paragrah, and adds an example.
---
change in v2:
- fix typo ETH_P_ERSPAN2
- fix space and indent
--- include/uapi/linux/if_ether.h | 1 + include/uapi/linux/if_tunnel.h | 3 ++ ip/link_gre.c | 59 ++++++++++++++++++++++++-- ip/link_gre6.c | 60 +++++++++++++++++++++++++-- man/man8/ip-link.8.in | 94 ++++++++++++++++++++++++++++++++++++------ 5 files changed, 198 insertions(+), 19 deletions(-)
include/uapi/linux/if_ether.h +1 -0
@@ -47,6 +47,7 @@#define ETH_P_PUP 0x0200/* Xerox PUP packet */ #define ETH_P_PUPAT 0x0201/* Xerox PUP Addr Trans packet */ #define ETH_P_TSN 0x22F0/* TSN (IEEE 1722) packet */ +#define ETH_P_ERSPAN2 0x22EB/* ERSPAN version 2 (type III) */ #define ETH_P_IP 0x0800/* Internet Protocol packet */ #define ETH_P_X25 0x0805/* CCITT X.25 */ #define ETH_P_ARP 0x0806/* Address Resolution packet */
include/uapi/linux/if_tunnel.h +3 -0
@@ -137,6 +137,9 @@ enum {IFLA_GRE_IGNORE_DF ,IFLA_GRE_FWMARK ,IFLA_GRE_ERSPAN_INDEX , +IFLA_GRE_ERSPAN_VER , +IFLA_GRE_ERSPAN_DIR , +IFLA_GRE_ERSPAN_HWID , __IFLA_GRE_MAX, };
ip/link_gre.c +56 -3
89 lines not on this page · raw message
ip/link_gre6.c +56 -4
90 lines not on this page · raw message
man/man8/ip-link.8.in +82 -12
128 lines not on this page · raw message
Signature · 1 line
2.7.4
Quoted 6 lines · William Tu
ip/link_gre.c +2
-0@@ -343,6 +355,22 @@ get_failed:invarg ("invalid erspan index\n" , *argv);if (erspan_idx & ~((1 <<20 ) -1 ) || erspan_idx ==0 )invarg ("erspan index must be > 0 and <= 20-bit\n" , *argv); + }else if (strcmp (*argv,"erspan_ver" ) ==0 ) { +NEXT_ARG ();
ip/link_gre.c get_failed: · line 369
Quoted 10 lines
ip/link_gre.c +10
-0+if (get_u8 (&erspan_ver, *argv,0 )) +invarg ("invalid erspan version\n" , *argv); +if (erspan_ver !=1 && erspan_ver !=2 ) +invarg ("erspan version must be 1 or 2\n" , *argv); + }else if (strcmp (*argv,"erspan_dir" ) ==0 ) { +NEXT_ARG (); +if (get_u8 (&erspan_dir, *argv,0 )) +invarg ("invalid erspan direction\n" , *argv); +if (erspan_dir !=0 && erspan_dir !=1 ) +invarg ("erspan direction must be 0(Ingress) or 1(Egress)\n" , *argv);
Why not allow ingress and egress as strings and using matches()? e.g., '... erspan_dir in[gress] ...' or '... erspan_dir e[gress] ...'
Seems much more intuitive than remembering "0" = ingress and "1" = egress.
Quoted 26 lines
ip/link_gre.c +12
-3@@ -374,8 +402,15 @@ get_failed:addattr_l (n,1024 ,IFLA_GRE_TTL , &ttl,1 );addattr_l (n,1024 ,IFLA_GRE_TOS , &tos,1 );addattr32 (n,1024 ,IFLA_GRE_FWMARK , fwmark); -if (erspan_idx !=0 ) -addattr32 (n,1024 ,IFLA_GRE_ERSPAN_INDEX , erspan_idx); +if (erspan_ver) { +addattr8 (n,1024 ,IFLA_GRE_ERSPAN_VER , erspan_ver); +if (erspan_ver ==1 && erspan_idx !=0 ) { +addattr32 (n,1024 ,IFLA_GRE_ERSPAN_INDEX , erspan_idx); + }else if (erspan_ver ==2 ) { +addattr8 (n,1024 ,IFLA_GRE_ERSPAN_DIR , erspan_dir); +addattr16 (n,1024 ,IFLA_GRE_ERSPAN_HWID , erspan_hwid); + } + } }else {addattr_l (n,1024 ,IFLA_GRE_COLLECT_METADATA ,NULL ,0 ); }@@ -514,7 +549,25 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])if (tb[IFLA_GRE_ERSPAN_INDEX ]) {__u32 erspan_idx =rta_getattr_u32 (tb[IFLA_GRE_ERSPAN_INDEX ]); -fprintf (f,"erspan_index %u " , erspan_idx); +print_uint (PRINT_ANY ,"erspan_index" ,"erspan_index %u" , erspan_idx); + } +
ip/link_gre.c static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) · line 564
Quoted 10 lines
ip/link_gre.c +10
-0+if (tb[IFLA_GRE_ERSPAN_VER ]) { +__u8 erspan_ver =rta_getattr_u8 (tb[IFLA_GRE_ERSPAN_VER ]); + +print_uint (PRINT_ANY ,"erspan_ver" ,"erspan_ver %u" , erspan_ver); + } + +if (tb[IFLA_GRE_ERSPAN_DIR ]) { +__u8 erspan_dir =rta_getattr_u8 (tb[IFLA_GRE_ERSPAN_DIR ]); + +print_uint (PRINT_ANY ,"erspan_dir" ,"erspan_dir %u" , erspan_dir);
similarly, here can convert the 0/1 to a human string.
Same comments for the changes to link_gre6.c
Quoted 62 lines · David Ahern
Quoted 6 lines · William Tu
ip/link_gre.c +2
-0@@ -343,6 +355,22 @@ get_failed:invarg ("invalid erspan index\n" , *argv);if (erspan_idx & ~((1 <<20 ) -1 ) || erspan_idx ==0 )invarg ("erspan index must be > 0 and <= 20-bit\n" , *argv); + }else if (strcmp (*argv,"erspan_ver" ) ==0 ) { +NEXT_ARG ();ip/link_gre.c get_failed: · line 369
Quoted 10 lines
ip/link_gre.c +10
-0+if (get_u8 (&erspan_ver, *argv,0 )) +invarg ("invalid erspan version\n" , *argv); +if (erspan_ver !=1 && erspan_ver !=2 ) +invarg ("erspan version must be 1 or 2\n" , *argv); + }else if (strcmp (*argv,"erspan_dir" ) ==0 ) { +NEXT_ARG (); +if (get_u8 (&erspan_dir, *argv,0 )) +invarg ("invalid erspan direction\n" , *argv); +if (erspan_dir !=0 && erspan_dir !=1 ) +invarg ("erspan direction must be 0(Ingress) or 1(Egress)\n" , *argv);Why not allow ingress and egress as strings and using
matches()? e.g., '...erspan_dirin[gress] ...' or '...erspan_dire[gress] ...'Seems much more intuitive than remembering "0" = ingress and "1" = egress.
Quoted 26 lines
ip/link_gre.c +12
-3@@ -374,8 +402,15 @@ get_failed:addattr_l (n,1024 ,IFLA_GRE_TTL , &ttl,1 );addattr_l (n,1024 ,IFLA_GRE_TOS , &tos,1 );addattr32 (n,1024 ,IFLA_GRE_FWMARK , fwmark); -if (erspan_idx !=0 ) -addattr32 (n,1024 ,IFLA_GRE_ERSPAN_INDEX , erspan_idx); +if (erspan_ver) { +addattr8 (n,1024 ,IFLA_GRE_ERSPAN_VER , erspan_ver); +if (erspan_ver ==1 && erspan_idx !=0 ) { +addattr32 (n,1024 ,IFLA_GRE_ERSPAN_INDEX , erspan_idx); + }else if (erspan_ver ==2 ) { +addattr8 (n,1024 ,IFLA_GRE_ERSPAN_DIR , erspan_dir); +addattr16 (n,1024 ,IFLA_GRE_ERSPAN_HWID , erspan_hwid); + } + } }else {addattr_l (n,1024 ,IFLA_GRE_COLLECT_METADATA ,NULL ,0 ); }@@ -514,7 +549,25 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])if (tb[IFLA_GRE_ERSPAN_INDEX ]) {__u32 erspan_idx =rta_getattr_u32 (tb[IFLA_GRE_ERSPAN_INDEX ]); -fprintf (f,"erspan_index %u " , erspan_idx); +print_uint (PRINT_ANY ,"erspan_index" ,"erspan_index %u" , erspan_idx); + } +ip/link_gre.c static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) · line 564
Quoted 10 lines
ip/link_gre.c +10
-0+if (tb[IFLA_GRE_ERSPAN_VER ]) { +__u8 erspan_ver =rta_getattr_u8 (tb[IFLA_GRE_ERSPAN_VER ]); + +print_uint (PRINT_ANY ,"erspan_ver" ,"erspan_ver %u" , erspan_ver); + } + +if (tb[IFLA_GRE_ERSPAN_DIR ]) { +__u8 erspan_dir =rta_getattr_u8 (tb[IFLA_GRE_ERSPAN_DIR ]); + +print_uint (PRINT_ANY ,"erspan_dir" ,"erspan_dir %u" , erspan_dir);similarly, here can convert the 0/1 to a human string.
Quoted 2 lines
Same comments for the changes to
link_gre6.c
Hi David,
Thanks for the feedback. I will convert to human string and resubmit. William