Skip to content

Commit db4a4a5

Browse files
committed
mesh: set preferred source for WireGuard routes
Set Route.Src for routes installed via the kilo interface to the node private IP when available. Without an explicit source, the kernel may pick the WireGuard overlay address (for example 100.66.0.x). In environments like Azure SDN this can break return traffic because the overlay address is not routable by the underlay. Update route expectations in TestRoutes to assert Src across the affected logical and full topology cases. Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
1 parent 062f897 commit db4a4a5

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

pkg/mesh/routes.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,14 @@ func (t *Topology) Routes(kiloIfaceName string, kiloIface, privIface, tunlIface
135135
}
136136
return routes, rules
137137
}
138+
// Compute the preferred source address for routes through the WireGuard interface.
139+
// Without this, the kernel picks the WireGuard overlay IP (e.g. 100.66.0.x) as the
140+
// source, which can cause issues in environments like Azure SDN where the overlay
141+
// IP is unknown to the network fabric and reply packets cannot be routed back.
142+
var src net.IP
143+
if t.privateIP != nil {
144+
src = t.privateIP.IP
145+
}
138146
for _, segment := range t.segments {
139147
// Add routes for the current segment if local is true.
140148
if segment.location == t.location {
@@ -190,6 +198,7 @@ func (t *Topology) Routes(kiloIfaceName string, kiloIface, privIface, tunlIface
190198
Flags: int(netlink.FLAG_ONLINK),
191199
Gw: segment.wireGuardIP,
192200
LinkIndex: kiloIface,
201+
Src: src,
193202
Protocol: unix.RTPROT_STATIC,
194203
})
195204
// Don't add routes through Kilo if the private IP
@@ -207,6 +216,7 @@ func (t *Topology) Routes(kiloIfaceName string, kiloIface, privIface, tunlIface
207216
Flags: int(netlink.FLAG_ONLINK),
208217
Gw: segment.wireGuardIP,
209218
LinkIndex: kiloIface,
219+
Src: src,
210220
Protocol: unix.RTPROT_STATIC,
211221
})
212222
}
@@ -218,6 +228,7 @@ func (t *Topology) Routes(kiloIfaceName string, kiloIface, privIface, tunlIface
218228
Flags: int(netlink.FLAG_ONLINK),
219229
Gw: segment.wireGuardIP,
220230
LinkIndex: kiloIface,
231+
Src: src,
221232
Protocol: unix.RTPROT_STATIC,
222233
})
223234
}
@@ -228,6 +239,7 @@ func (t *Topology) Routes(kiloIfaceName string, kiloIface, privIface, tunlIface
228239
routes = append(routes, &netlink.Route{
229240
Dst: &peer.AllowedIPs[i],
230241
LinkIndex: kiloIface,
242+
Src: src,
231243
Protocol: unix.RTPROT_STATIC,
232244
})
233245
}

0 commit comments

Comments
 (0)