Add support for the new optional "tunsrc" parameter. Now, a tunnel source address can be configured per route and has priority over the configured per-netns source address (if any). Example: ip -6 r a 2001:db8:1::/64 encap seg6 mode encap tunsrc 2001:db8:ab:: segs 2001:db8:42::1,2001:db8:ffff::2 dev eth0 Signed-off-by: Justin Iurman --- ip/iproute_lwtunnel.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/ip/iproute_lwtunnel.c b/ip/iproute_lwtunnel.c index a7885dba28c1..00b4f7565be6 100644 --- a/ip/iproute_lwtunnel.c +++ b/ip/iproute_lwtunnel.c @@ -266,6 +266,13 @@ static void print_encap_seg6(FILE *fp, struct rtattr *encap) print_string(PRINT_ANY, "mode", "mode %s ", format_seg6mode_type(tuninfo->mode)); + if (tb[SEG6_IPTUNNEL_SRC]) { + print_color_string(PRINT_ANY, COLOR_INET6, + "tunsrc", "tunsrc %s ", + rt_addr_n2a_rta(AF_INET6, + tb[SEG6_IPTUNNEL_SRC])); + } + print_srh(fp, tuninfo->srh); } @@ -953,6 +960,8 @@ 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 tunsrc = false; + inet_prefix saddr; int argc = *argcp; int encap = -1; __u32 hmac = 0; @@ -967,6 +976,22 @@ static int parse_encap_seg6(struct rtattr *rta, size_t len, int *argcp, encap = read_seg6mode_type(*argv); if (encap < 0) invarg("\"mode\" value is invalid\n", *argv); + } else if (strcmp(*argv, "tunsrc") == 0) { + NEXT_ARG(); + if (encap == -1) + invarg("\"tunsrc\" provided before \"mode\"\n", + *argv); + if (encap == SEG6_IPTUN_MODE_INLINE) + invarg("\"tunsrc\" invalid with inline mode\n", + *argv); + if (tunsrc) + duparg2("tunsrc", *argv); + + get_addr(&saddr, *argv, AF_INET6); + if (saddr.family != AF_INET6 || saddr.bytelen != 16) + invarg("\"tunsrc\" value is invalid\n", *argv); + + tunsrc = true; } else if (strcmp(*argv, "segs") == 0) { NEXT_ARG(); if (segs_ok++) @@ -1005,6 +1030,12 @@ static int parse_encap_seg6(struct rtattr *rta, size_t len, int *argcp, sizeof(*tuninfo) + srhlen)) goto out; + if (tunsrc) { + if (rta_addattr_l(rta, len, SEG6_IPTUNNEL_SRC, + &saddr.data, saddr.bytelen)) + goto out; + } + *argcp = argc + 1; *argvp = argv - 1; ret = 0; -- 2.39.2 Include "tunsrc" in the man page. Signed-off-by: Justin Iurman --- man/man8/ip-route.8.in | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/man/man8/ip-route.8.in b/man/man8/ip-route.8.in index aafa6d98a4c2..9f29fd436f59 100644 --- a/man/man8/ip-route.8.in +++ b/man/man8/ip-route.8.in @@ -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 tunsrc +.IR ADDRESS " ]" .B segs .IR SEGMENTS " [ " .B hmac @@ -893,6 +895,15 @@ applying the reduced segment list. When there is only one segment and the HMAC is not present, the SRH is omitted. .sp +.B tunsrc +.I ADDRESS +- IPv6 address of the tunnel source (outer header), not used with inline mode. +It is optional: if not provided, the tunnel source address is chosen based on +the per-netns configuration ("ip sr tunsrc set ADDRESS") or, if not configured, +it is dynamically resolved. If provided, it takes priority over the per-netns +configuration and dynamic resolution. +.sp + .I SEGMENTS - List of comma-separated IPv6 addresses .sp -- 2.39.2