wireguard: allow routes to overlap with other routes #60818
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation for this change
I like to use wireguard to maintain a constant connection to my office and my home network, but I'm frequently physically connected to those networks. Without this patch, starting wireguard would fail for whichever network I was physically connected to, because
ip route replace
didn't play nicely with the (correct) overlapping local routes.This patch fixes this by explicitly deleting the routes for the wireguard interface, then re-adding the new ones (in case they have changed). I didn't make an attempt to avoid deleting and re-adding unchanged routes, because I figure people will expect restarting wireguard to entail a short downtime (and this is very short).
I also arbitrarily picked a metric of 10000 to ensure that traffic is directed to the local connection in preference to wireguard, when the local connection is available. I'm sure there's a better way of choosing a metric, but this works 100% reliably for me, and I suspect it will also for most others.
This is the kind of PR that often languishes, so if I don't get any pushback within the next week or so, I'll assume it's good and go ahead and merge.
Things done
sandbox
innix.conf
on non-NixOS)nix-shell -p nix-review --run "nix-review wip"
./result/bin/
)nix path-info -S
before and after)