From 796973b682f2d94502ad53998ff530b1628c26d4 Mon Sep 17 00:00:00 2001 From: Andrei Kvapil Date: Fri, 13 Feb 2026 21:09:35 +0100 Subject: [PATCH] mesh: set src for encapsulated tunl routes --- pkg/mesh/routes.go | 7 ++++++- pkg/mesh/routes_test.go | 13 +++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/pkg/mesh/routes.go b/pkg/mesh/routes.go index 1f6b9aa1..2821e48f 100644 --- a/pkg/mesh/routes.go +++ b/pkg/mesh/routes.go @@ -76,6 +76,7 @@ func (t *Topology) Routes(kiloIfaceName string, kiloIface, privIface, tunlIface Flags: int(netlink.FLAG_ONLINK), Gw: segment.privateIPs[i], LinkIndex: tunlIface, + Src: t.privateIP.IP, Protocol: unix.RTPROT_STATIC, Table: kiloTableIndex, }) @@ -161,6 +162,7 @@ func (t *Topology) Routes(kiloIfaceName string, kiloIface, privIface, tunlIface Flags: int(netlink.FLAG_ONLINK), Gw: segment.privateIPs[i], LinkIndex: tunlIface, + Src: t.privateIP.IP, Protocol: unix.RTPROT_STATIC, Table: kiloTableIndex, }) @@ -304,8 +306,11 @@ func (t *Topology) PeerRoutes(name string, kiloIface int, additionalAllowedIPs [ } func encapsulateRoute(route *netlink.Route, encapsulate encapsulation.Strategy, subnet *net.IPNet, tunlIface int) *netlink.Route { - if encapsulate == encapsulation.Always || (encapsulate == encapsulation.CrossSubnet && !subnet.Contains(route.Gw)) { + if encapsulate == encapsulation.Always || (encapsulate == encapsulation.CrossSubnet && subnet != nil && !subnet.Contains(route.Gw)) { route.LinkIndex = tunlIface + if subnet != nil && route.Src == nil { + route.Src = subnet.IP + } } return route } diff --git a/pkg/mesh/routes_test.go b/pkg/mesh/routes_test.go index b9157752..fc12b1ab 100644 --- a/pkg/mesh/routes_test.go +++ b/pkg/mesh/routes_test.go @@ -680,6 +680,7 @@ func TestRoutes(t *testing.T) { Flags: int(netlink.FLAG_ONLINK), Gw: nodes["c"].InternalIP.IP, LinkIndex: tunlIface, + Src: nodes["b"].InternalIP.IP, Protocol: unix.RTPROT_STATIC, }, { @@ -687,6 +688,7 @@ func TestRoutes(t *testing.T) { Flags: int(netlink.FLAG_ONLINK), Gw: nodes["c"].InternalIP.IP, LinkIndex: tunlIface, + Src: nodes["b"].InternalIP.IP, Protocol: unix.RTPROT_STATIC, Table: kiloTableIndex, }, @@ -815,6 +817,7 @@ func TestRoutes(t *testing.T) { Flags: int(netlink.FLAG_ONLINK), Gw: nodes["b"].InternalIP.IP, LinkIndex: tunlIface, + Src: nodes["c"].InternalIP.IP, Protocol: unix.RTPROT_STATIC, }, { @@ -822,6 +825,7 @@ func TestRoutes(t *testing.T) { Flags: int(netlink.FLAG_ONLINK), Gw: nodes["b"].InternalIP.IP, LinkIndex: tunlIface, + Src: nodes["c"].InternalIP.IP, Protocol: unix.RTPROT_STATIC, }, { @@ -829,6 +833,7 @@ func TestRoutes(t *testing.T) { Flags: int(netlink.FLAG_ONLINK), Gw: nodes["b"].InternalIP.IP, LinkIndex: tunlIface, + Src: nodes["c"].InternalIP.IP, Protocol: unix.RTPROT_STATIC, }, { @@ -836,6 +841,7 @@ func TestRoutes(t *testing.T) { Flags: int(netlink.FLAG_ONLINK), Gw: nodes["b"].InternalIP.IP, LinkIndex: tunlIface, + Src: nodes["c"].InternalIP.IP, Protocol: unix.RTPROT_STATIC, }, { @@ -843,6 +849,7 @@ func TestRoutes(t *testing.T) { Flags: int(netlink.FLAG_ONLINK), Gw: nodes["b"].InternalIP.IP, LinkIndex: tunlIface, + Src: nodes["c"].InternalIP.IP, Protocol: unix.RTPROT_STATIC, }, { @@ -850,6 +857,7 @@ func TestRoutes(t *testing.T) { Flags: int(netlink.FLAG_ONLINK), Gw: nodes["b"].InternalIP.IP, LinkIndex: tunlIface, + Src: nodes["c"].InternalIP.IP, Protocol: unix.RTPROT_STATIC, Table: kiloTableIndex, }, @@ -858,6 +866,7 @@ func TestRoutes(t *testing.T) { Flags: int(netlink.FLAG_ONLINK), Gw: nodes["b"].InternalIP.IP, LinkIndex: tunlIface, + Src: nodes["c"].InternalIP.IP, Protocol: unix.RTPROT_STATIC, }, { @@ -865,6 +874,7 @@ func TestRoutes(t *testing.T) { Flags: int(netlink.FLAG_ONLINK), Gw: nodes["b"].InternalIP.IP, LinkIndex: tunlIface, + Src: nodes["c"].InternalIP.IP, Protocol: unix.RTPROT_STATIC, }, { @@ -872,6 +882,7 @@ func TestRoutes(t *testing.T) { Flags: int(netlink.FLAG_ONLINK), Gw: nodes["b"].InternalIP.IP, LinkIndex: tunlIface, + Src: nodes["c"].InternalIP.IP, Protocol: unix.RTPROT_STATIC, }, { @@ -879,6 +890,7 @@ func TestRoutes(t *testing.T) { Flags: int(netlink.FLAG_ONLINK), Gw: nodes["b"].InternalIP.IP, LinkIndex: tunlIface, + Src: nodes["c"].InternalIP.IP, Protocol: unix.RTPROT_STATIC, }, { @@ -886,6 +898,7 @@ func TestRoutes(t *testing.T) { Flags: int(netlink.FLAG_ONLINK), Gw: nodes["b"].InternalIP.IP, LinkIndex: tunlIface, + Src: nodes["c"].InternalIP.IP, Protocol: unix.RTPROT_STATIC, }, },