naccyde / rpms / iproute

Forked from rpms/iproute 10 months ago
Clone
36cfb7
From b9961cdb54c22fa1b3f1eac5446a008fde7532e6 Mon Sep 17 00:00:00 2001
36cfb7
From: Andrea Claudi <aclaudi@redhat.com>
36cfb7
Date: Wed, 5 Jun 2019 13:13:31 +0200
36cfb7
Subject: [PATCH] gre6: add collect metadata support
36cfb7
36cfb7
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1714660
36cfb7
Upstream Status: iproute2.git commit 6231c5bec6d25
36cfb7
Conflicts:
36cfb7
* Context change due to missing commit
36cfb7
  ad4b1425c3182 ("iplink: Expose IFLA_*_FWMARK attributes for supported link types")
36cfb7
* Adjusted gre_print_opt() to missing commit 6856fb65484ba
36cfb7
  ("ip: link_gre6.c: add json output support")
36cfb7
36cfb7
commit 6231c5bec6d256f7861f39d3a578f5259f274cc4
36cfb7
Author: William Tu <u9012063@gmail.com>
36cfb7
Date:   Tue Dec 12 18:22:52 2017 -0800
36cfb7
36cfb7
    gre6: add collect metadata support
36cfb7
36cfb7
    The patch adds 'external' option to support collect metadata
36cfb7
    gre6 tunnel.  The 'external' keyword is already used to set the
36cfb7
    device into collect metadata mode such as vxlan, geneve, ipip,
36cfb7
    etc.  This patch extends support for ipv6 gre and gretap.
36cfb7
    Example of L3 and L2 gre device:
36cfb7
    bash:~# ip link add dev ip6gre123 type ip6gre external
36cfb7
    bash:~# ip link add dev ip6gretap123 type ip6gretap external
36cfb7
36cfb7
    Signed-off-by: William Tu <u9012063@gmail.com>
36cfb7
    Cc: Daniel Borkmann <daniel@iogearbox.net>
36cfb7
---
36cfb7
 ip/link_gre6.c        | 49 ++++++++++++++++++++++++++++---------------
36cfb7
 man/man8/ip-link.8.in | 17 +++++++++++++++
36cfb7
 2 files changed, 49 insertions(+), 17 deletions(-)
36cfb7
36cfb7
diff --git a/ip/link_gre6.c b/ip/link_gre6.c
36cfb7
index 127e51de4ab73..ea42fb1a9f664 100644
36cfb7
--- a/ip/link_gre6.c
36cfb7
+++ b/ip/link_gre6.c
36cfb7
@@ -102,6 +102,7 @@ static int gre_parse_opt(struct link_util *lu, int argc, char **argv,
36cfb7
 	__u16 encapflags = TUNNEL_ENCAP_FLAG_CSUM6;
36cfb7
 	__u16 encapsport = 0;
36cfb7
 	__u16 encapdport = 0;
36cfb7
+	__u8 metadata = 0;
36cfb7
 	int len;
36cfb7
 
36cfb7
 	if (!(n->nlmsg_flags & NLM_F_CREATE)) {
36cfb7
@@ -173,6 +174,9 @@ get_failed:
36cfb7
 		if (greinfo[IFLA_GRE_ENCAP_SPORT])
36cfb7
 			encapsport = rta_getattr_u16(greinfo[IFLA_GRE_ENCAP_SPORT]);
36cfb7
 
36cfb7
+		if (greinfo[IFLA_GRE_COLLECT_METADATA])
36cfb7
+			metadata = 1;
36cfb7
+
36cfb7
 		if (greinfo[IFLA_GRE_ENCAP_DPORT])
36cfb7
 			encapdport = rta_getattr_u16(greinfo[IFLA_GRE_ENCAP_DPORT]);
36cfb7
 
36cfb7
@@ -333,6 +337,8 @@ get_failed:
36cfb7
 			encapflags |= TUNNEL_ENCAP_FLAG_REMCSUM;
36cfb7
 		} else if (strcmp(*argv, "noencap-remcsum") == 0) {
36cfb7
 			encapflags &= ~TUNNEL_ENCAP_FLAG_REMCSUM;
36cfb7
+		} else if (strcmp(*argv, "external") == 0) {
36cfb7
+			metadata = 1;
36cfb7
 		} else if (strcmp(*argv, "encaplimit") == 0) {
36cfb7
 			NEXT_ARG();
36cfb7
 			if (strcmp(*argv, "none") == 0) {
36cfb7
@@ -350,23 +356,27 @@ get_failed:
36cfb7
 		argc--; argv++;
36cfb7
 	}
36cfb7
 
36cfb7
-	addattr32(n, 1024, IFLA_GRE_IKEY, ikey);
36cfb7
-	addattr32(n, 1024, IFLA_GRE_OKEY, okey);
36cfb7
-	addattr_l(n, 1024, IFLA_GRE_IFLAGS, &iflags, 2);
36cfb7
-	addattr_l(n, 1024, IFLA_GRE_OFLAGS, &oflags, 2);
36cfb7
-	addattr_l(n, 1024, IFLA_GRE_LOCAL, &laddr, sizeof(laddr));
36cfb7
-	addattr_l(n, 1024, IFLA_GRE_REMOTE, &raddr, sizeof(raddr));
36cfb7
-	if (link)
36cfb7
-		addattr32(n, 1024, IFLA_GRE_LINK, link);
36cfb7
-	addattr_l(n, 1024, IFLA_GRE_TTL, &hop_limit, 1);
36cfb7
-	addattr_l(n, 1024, IFLA_GRE_ENCAP_LIMIT, &encap_limit, 1);
36cfb7
-	addattr_l(n, 1024, IFLA_GRE_FLOWINFO, &flowinfo, 4);
36cfb7
-	addattr32(n, 1024, IFLA_GRE_FLAGS, flags);
36cfb7
-
36cfb7
-	addattr16(n, 1024, IFLA_GRE_ENCAP_TYPE, encaptype);
36cfb7
-	addattr16(n, 1024, IFLA_GRE_ENCAP_FLAGS, encapflags);
36cfb7
-	addattr16(n, 1024, IFLA_GRE_ENCAP_SPORT, htons(encapsport));
36cfb7
-	addattr16(n, 1024, IFLA_GRE_ENCAP_DPORT, htons(encapdport));
36cfb7
+	if (!metadata) {
36cfb7
+		addattr32(n, 1024, IFLA_GRE_IKEY, ikey);
36cfb7
+		addattr32(n, 1024, IFLA_GRE_OKEY, okey);
36cfb7
+		addattr_l(n, 1024, IFLA_GRE_IFLAGS, &iflags, 2);
36cfb7
+		addattr_l(n, 1024, IFLA_GRE_OFLAGS, &oflags, 2);
36cfb7
+		addattr_l(n, 1024, IFLA_GRE_LOCAL, &laddr, sizeof(laddr));
36cfb7
+		addattr_l(n, 1024, IFLA_GRE_REMOTE, &raddr, sizeof(raddr));
36cfb7
+		if (link)
36cfb7
+			addattr32(n, 1024, IFLA_GRE_LINK, link);
36cfb7
+		addattr_l(n, 1024, IFLA_GRE_TTL, &hop_limit, 1);
36cfb7
+		addattr_l(n, 1024, IFLA_GRE_ENCAP_LIMIT, &encap_limit, 1);
36cfb7
+		addattr_l(n, 1024, IFLA_GRE_FLOWINFO, &flowinfo, 4);
36cfb7
+		addattr32(n, 1024, IFLA_GRE_FLAGS, flags);
36cfb7
+
36cfb7
+		addattr16(n, 1024, IFLA_GRE_ENCAP_TYPE, encaptype);
36cfb7
+		addattr16(n, 1024, IFLA_GRE_ENCAP_FLAGS, encapflags);
36cfb7
+		addattr16(n, 1024, IFLA_GRE_ENCAP_SPORT, htons(encapsport));
36cfb7
+		addattr16(n, 1024, IFLA_GRE_ENCAP_DPORT, htons(encapdport));
36cfb7
+	} else {
36cfb7
+		addattr_l(n, 1024, IFLA_GRE_COLLECT_METADATA, NULL, 0);
36cfb7
+	}
36cfb7
 
36cfb7
 	return 0;
36cfb7
 }
36cfb7
@@ -385,6 +395,11 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
36cfb7
 	if (!tb)
36cfb7
 		return;
36cfb7
 
36cfb7
+	if (tb[IFLA_GRE_COLLECT_METADATA]) {
36cfb7
+		fprintf(f, "external");
36cfb7
+		return;
36cfb7
+	}
36cfb7
+
36cfb7
 	if (tb[IFLA_GRE_FLAGS])
36cfb7
 		flags = rta_getattr_u32(tb[IFLA_GRE_FLAGS]);
36cfb7
 
36cfb7
diff --git a/man/man8/ip-link.8.in b/man/man8/ip-link.8.in
36cfb7
index 8be5d5e1e9fd6..612bd8ce92696 100644
36cfb7
--- a/man/man8/ip-link.8.in
36cfb7
+++ b/man/man8/ip-link.8.in
36cfb7
@@ -877,6 +877,8 @@ the following additional arguments are supported:
36cfb7
 .BI "dscp inherit"
36cfb7
 ] [
36cfb7
 .BI dev " PHYS_DEV "
36cfb7
+] [
36cfb7
+.RB external
36cfb7
 ]
36cfb7
 
36cfb7
 .in +8
36cfb7
@@ -958,6 +960,21 @@ or
36cfb7
 .IR 00 ".." ff
36cfb7
 when tunneling non-IP packets. The default value is 00.
36cfb7
 
36cfb7
+.sp
36cfb7
+.RB external
36cfb7
+- make this tunnel externally controlled (or not, which is the default).
36cfb7
+In the kernel, this is referred to as collect metadata mode.  This flag is
36cfb7
+mutually exclusive with the
36cfb7
+.BR remote ,
36cfb7
+.BR local ,
36cfb7
+.BR seq ,
36cfb7
+.BR key,
36cfb7
+.BR csum,
36cfb7
+.BR hoplimit,
36cfb7
+.BR encaplimit,
36cfb7
+.BR flowlabel " and " tclass
36cfb7
+options.
36cfb7
+
36cfb7
 .in -8
36cfb7
 
36cfb7
 .TP
36cfb7
-- 
e138d9
2.21.0
36cfb7