Skip to content

Commit

Permalink
Prefer route with gateway when adding static route.
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Hallgren <[email protected]>
  • Loading branch information
thallgren committed Feb 4, 2025
1 parent 7986105 commit 7a4a4d8
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions pkg/vif/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,22 @@ func (rt *Router) addStaticOverrides(ctx context.Context, neverProxy, neverProxy
if err != nil {
return err
}
pr = &routing.Route{
Interface: ifd,
for _, addr := range addrs {
pfx, err := netip.ParsePrefix(addr.String())
if err != nil {
return err
}
pr, err = routing.GetRoute(ctx, pfx)
if err != nil {
return err
}
if pr.Gateway.IsValid() {
break
}
}
if len(addrs) > 0 {
if pfx, err := netip.ParsePrefix(addrs[0].String()); err == nil {
pr.LocalIP = pfx.Addr()
if pr == nil {
pr = &routing.Route{
Interface: ifd,
}
}
}
Expand Down

0 comments on commit 7a4a4d8

Please sign in to comment.