Skip to contentSkip to conversation

seg6: add support of 'nh-vrf' flag

RFC PATCH New Nicolas Dichtel 1 participant 1 message Mar 27

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 seg6: add support of 'nh-vrf' flag

This new flag enables to have x-vrf routes.

---

A formal submission will be done once the kernel patch is merged.

 include/uapi/linux/seg6_iptunnel.h |  2 ++
 ip/iproute_lwtunnel.c              | 10 ++++++++++
 man/man8/ip-route.8.in             |  9 ++++++++-
 3 files changed, 20 insertions(+), 1 deletion(-)
include/uapi/linux/seg6_iptunnel.h +2 -0
index e1929d21c0b6..81e5c699d157 100644
@@ -20,6 +20,8 @@
 enum {
 	SEG6_IPTUNNEL_UNSPEC,
 	SEG6_IPTUNNEL_SRH,
+	SEG6_IPTUNNEL_SRC,	/* struct in6_addr */
+	SEG6_IPTUNNEL_NH_VRF,
 	__SEG6_IPTUNNEL_MAX,
 };
 #define SEG6_IPTUNNEL_MAX (__SEG6_IPTUNNEL_MAX - 1)
ip/iproute_lwtunnel.c +10 -0
index a7885dba28c1..e6a61c0d5046 100644
@@ -267,6 +267,9 @@ static void print_encap_seg6(FILE *fp, struct rtattr *encap)
 		     "mode %s ", format_seg6mode_type(tuninfo->mode));
 
 	print_srh(fp, tuninfo->srh);
+
+	if (tb[SEG6_IPTUNNEL_NH_VRF])
+		print_string(PRINT_ANY, NULL, "%s ", "nh-vrf");
 }
 
 static void print_rpl_srh(FILE *fp, struct ipv6_rpl_sr_hdr *srh)
@@ -953,6 +956,7 @@ static int parse_encap_seg6(struct rtattr *rta, size_t len, int *argcp,
 	struct ipv6_sr_hdr *srh;
 	char **argv = *argvp;
 	char segbuf[1024] = "";
+	bool nh_vrf = false;
 	int argc = *argcp;
 	int encap = -1;
 	__u32 hmac = 0;
@@ -981,6 +985,8 @@ static int parse_encap_seg6(struct rtattr *rta, size_t len, int *argcp,
 			if (hmac_ok++)
 				duparg2("hmac", *argv);
 			get_u32(&hmac, *argv, 0);
+		} else if (strcmp(*argv, "nh-vrf") == 0) {
+			nh_vrf = true;
 		} else {
 			break;
 		}
@@ -1005,6 +1011,10 @@ static int parse_encap_seg6(struct rtattr *rta, size_t len, int *argcp,
 			  sizeof(*tuninfo) + srhlen))
 		goto out;
 
+	if (nh_vrf &&
+	    rta_addattr_l(rta, len, SEG6_IPTUNNEL_NH_VRF, NULL, 0))
+		goto out;
+
 	*argcp = argc + 1;
 	*argvp = argv - 1;
 	ret = 0;
man/man8/ip-route.8.in +8 -1
index aafa6d98a4c2..37dcaae49195 100644
@@ -240,7 +240,9 @@ throw " | " unreachable " | " prohibit " | " blackhole " | " nat " ]"
 .IR ENCAP_SEG6 " := "
 .B seg6
 .BR mode " [ "
-.BR encap " | " encap.red " | " inline " | " l2encap " | " l2encap.red " ] "
+.BR encap " | " encap.red " | " inline " | " l2encap " | " l2encap.red " ] ["
+.B nh-vrf
+.IR "]"
 .B segs
 .IR SEGMENTS " [ "
 .B hmac
@@ -893,6 +895,11 @@ applying the reduced segment list. When there is only one segment
 and the HMAC is not present, the SRH is omitted.
 .sp
 
+.B nh-vrf
+- use the vrf attached to the next hop device to route the encapsulated
+packet.
+.sp
+
 .I SEGMENTS
 - List of comma-separated IPv6 addresses
 .sp
Signature · 1 line
2.52.0