public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Justin Iurman <justin.iurman@6wind.com>
To: netdev@vger.kernel.org
Cc: dsahern@kernel.org, stephen@networkplumber.org,
	andrea.mayer@uniroma2.it, justin.iurman@gmail.com,
	nicolas.dichtel@6wind.com, stefano.salsano@uniroma2.it,
	paolo.lungaroni@uniroma2.it, ahabdels@cisco.com,
	Justin Iurman <justin.iurman@6wind.com>
Subject: [PATCH iproute2-next 1/2] seg6: add tunsrc support in iproute_lwtunnel
Date: Mon, 16 Mar 2026 17:49:06 +0100	[thread overview]
Message-ID: <20260316164907.1255510-2-justin.iurman@6wind.com> (raw)
In-Reply-To: <20260316164907.1255510-1-justin.iurman@6wind.com>

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 <justin.iurman@6wind.com>
---
 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


  reply	other threads:[~2026-03-16 16:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-16 16:49 [PATCH iproute2-next 0/2] Add support for seg6 tunsrc Justin Iurman
2026-03-16 16:49 ` Justin Iurman [this message]
2026-03-17 11:10   ` [PATCH iproute2-next 1/2] seg6: add tunsrc support in iproute_lwtunnel Andrea Mayer
2026-03-18 12:07     ` Justin Iurman
2026-03-16 16:49 ` [PATCH iproute2-next 2/2] man8: update seg6 encap documentation Justin Iurman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260316164907.1255510-2-justin.iurman@6wind.com \
    --to=justin.iurman@6wind.com \
    --cc=ahabdels@cisco.com \
    --cc=andrea.mayer@uniroma2.it \
    --cc=dsahern@kernel.org \
    --cc=justin.iurman@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=nicolas.dichtel@6wind.com \
    --cc=paolo.lungaroni@uniroma2.it \
    --cc=stefano.salsano@uniroma2.it \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox