Skip to contentSkip to conversation

erspan: add erspan version II support

PATCH Superseded William Tu 2 participants 3 messages Dec 20, 2017

Subsystems (2)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

William Tu

author
#0 lore raw

PATCH v3 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 v3:
- change erspan_dir 0/1 to "in[gress]/e[gress]"
- update manpage
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                  | 68 +++++++++++++++++++++++++++++--
 ip/link_gre6.c                 | 69 +++++++++++++++++++++++++++++--
 man/man8/ip-link.8.in          | 92 ++++++++++++++++++++++++++++++++++++------
 5 files changed, 214 insertions(+), 19 deletions(-)
include/uapi/linux/if_ether.h +1 -0
index 2eb529a90250..133567bf2e04 100644
@@ -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
index 38cdf90692f8..ecdc76669cfd 100644
@@ -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 +65 -3

98 lines not on this page · raw message

ip/link_gre6.c +65 -4

99 lines not on this page · raw message

man/man8/ip-link.8.in +80 -12

126 lines not on this page · raw message

Signature · 1 line
2.7.4
#1 lore raw

Hi William:

Quoted 7 lines · William Tu
ip/link_gre.c +3 -0
@@ -343,6 +355,26 @@ 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();
+			if (get_u8(&erspan_ver, *argv, 0))

ip/link_gre.c get_failed: · line 370

Quoted 10 lines
ip/link_gre.c +10 -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 (strcmp(*argv, "ingress") == 0 ||
+			    strcmp(*argv, "in") == 0)
+				erspan_dir = 0;
+			else if (strcmp(*argv, "egress") == 0 ||
+				 strcmp(*argv, "e") == 0)

iproute2 has a matches() function that should be used -- it basically allows whatever shorthand notation matches -- in this case e, eg, egr, egres, egress all match. Checkout ip/iplink.c and search for matches.

author
#2 lore raw
Quoted 16 lines · David Ahern

Hi William:

Quoted 13 lines · William Tu
ip/link_gre.c +9 -0
@@ -343,6 +355,26 @@ 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();
+                     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 (strcmp(*argv, "ingress") == 0 ||
Quoted 9 lines

ip/link_gre.c get_failed: · line 370

Quoted 4 lines
ip/link_gre.c +4 -0
+                         strcmp(*argv, "in") == 0)
+                             erspan_dir = 0;
+                     else if (strcmp(*argv, "egress") == 0 ||
+                              strcmp(*argv, "e") == 0)

iproute2 has a matches() function that should be used -- it basically allows whatever shorthand notation matches -- in this case e, eg, egr, egres, egress all match. Checkout ip/iplink.c and search for matches.

Hi David,
Thanks, will fix it in next version.
William