Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete route from system only if added by the client #1841

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions client/internal/routemanager/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type clientNetwork struct {
chosenRoute *route.Route
network netip.Prefix
updateSerial uint64
systemUpdated bool
}

func newClientNetworkWatcher(ctx context.Context, wgInterface *iface.WGIface, statusRecorder *peer.Status, network netip.Prefix) *clientNetwork {
Expand Down Expand Up @@ -215,8 +216,11 @@ func (c *clientNetwork) removeRouteFromWireguardPeer(peerKey string) error {

func (c *clientNetwork) removeRouteFromPeerAndSystem() error {
if c.chosenRoute != nil {
if err := removeVPNRoute(c.network, c.wgInterface.Name()); err != nil {
return fmt.Errorf("remove route %s from system, err: %v", c.network, err)
if c.systemUpdated {
mlsmaycon marked this conversation as resolved.
Show resolved Hide resolved
if err := removeVPNRoute(c.network, c.wgInterface.Name()); err != nil {
return fmt.Errorf("remove route %s from system, err: %v", c.network, err)
}
c.systemUpdated = false
}

if err := c.removeRouteFromWireguardPeer(c.chosenRoute.Peer); err != nil {
Expand Down Expand Up @@ -260,6 +264,8 @@ func (c *clientNetwork) recalculateRouteAndUpdatePeerAndSystem() error {
return fmt.Errorf("route %s couldn't be added for peer %s, err: %v",
c.network.String(), c.wgInterface.Address().IP.String(), err)
}

c.systemUpdated = true
}

c.chosenRoute = c.routes[chosen]
Expand Down
3 changes: 1 addition & 2 deletions client/internal/routemanager/systemops.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,7 @@ func addNonExistingRoute(prefix netip.Prefix, intf string) error {
return fmt.Errorf("exists in route table: %w", err)
}
if ok {
log.Warnf("Skipping adding a new route for network %s because it already exists", prefix)
return nil
return fmt.Errorf("Skipping adding a new route for network %s because it already exists", prefix)
mlsmaycon marked this conversation as resolved.
Show resolved Hide resolved
}

ok, err = isSubRange(prefix)
Expand Down
Loading