Skip to content

In mirrored mode, handle route update as add instead of replace - #41391

Merged
FetoiuCatalin merged 11 commits into
masterfrom
user/cfetoiu/handle_update_as_add
Sep 17, 2026
Merged

FetoiuCatalin merged 11 commits into
masterfrom
user/cfetoiu/handle_update_as_add

Conversation

@FetoiuCatalin

@FetoiuCatalin FetoiuCatalin commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary of the Pull Request

GNS is handling a route update operation using the NLM_F_REPLACE flag (equivalent to ip route replace), which collapses multiple routes that have the same destination, metric, tos, even if they have different next hops or interfaces. E.g. replacing one of the 2 routes below will collapse them into 1.
default via 10.130.174.1 dev eth1 proto kernel metric 25
default via 10.120.186.1 dev eth0 proto kernel metric 25

This was found when adding and removing and adapter on a test windows host VM - if the new adapter happens to have the same default route with same metric as existing one, after removing the new one connectivity will be lost in WSL as the route of the original one will be deleted if an update happens for the route of the new one.

Detailed Description of the Pull Request / Additional comments

The mirrored mode route synchronization logic never attempts an in-place update of a route. Whenever a route change occurs on the host (ProcessRouteChange), we mark for removal the routes that are known to have been synced in Linux but are no longer part of the latest set of host routes, we do not do a diff of the route properties to determine if an in-place update is needed.

Handling an update as an Add (ignoring already exists error, which already happens) is the intended behavior for route updates.

Note: NAT and virtio modes already use just add and remove operations for Routes

Validation Steps Performed

Scenario that found the bug: Add-VMNetworkAdapter/Remove-VMNetworkAdapter on a windows host VM and verifying connectivity
Connecting/disconnecting OpenVPN multiple times and verifying connectivity, which leads to routes being added/deleted multiple times
Existing automated NetworkTests + new tests that validate host route updates are correctly mirrored

Copilot AI lite review requested due to automatic review settings August 19, 2026 21:38
@FetoiuCatalin FetoiuCatalin changed the title Handle route update as add instead of replace [draft] Handle route update as add instead of replace Aug 19, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This draft PR changes Linux route “Update” handling in netlinkutil to avoid inadvertently replacing another interface’s route when multiple routes share the same destination/metric key, and adds a Windows networking test to validate the new behavior.

Changes:

  • Update route modification logic to omit NLM_F_REPLACE for Update operations (treat Update as “ensure exists” / add-only).
  • Add a regression test that creates two same-metric default routes on different interfaces and verifies both persist after an Update.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/linux/netlinkutil/RoutingTable.cpp Changes Update route flags to avoid NLM_F_REPLACE overwriting another interface’s route.
test/windows/NetworkTests.cpp Adds a WSL2 test validating that updating eth0’s default route does not remove another interface’s same-metric default route.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/linux/netlinkutil/RoutingTable.cpp Resolved
Comment thread test/windows/NetworkTests.cpp Resolved
Copilot AI review requested due to automatic review settings August 19, 2026 21:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Suppressed comments (1)

src/linux/netlinkutil/RoutingTable.cpp:103

  • Remove the leftover commented-out assignment (// flags = NLM_F_CREATE;). It’s redundant with the next line and makes it look like the code is mid-edit.
        // Note: The EEXIST error is already treated as non-fatal.
        // flags = NLM_F_CREATE;
        flags = NLM_F_CREATE;

Copilot AI review requested due to automatic review settings August 19, 2026 22:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Suppressed comments (1)

src/windows/service/exe/WslMirroredNetworking.cpp:1415

  • In the refresh-all-routes retry path, the code sets SyncStatus = PendingUpdate, but this PR now treats PendingUpdate identically to PendingAdd (both send ModifyRequestType::Add). Setting PendingAdd here would better reflect the actual retry operation and avoid future confusion when debugging route-sync state transitions.
                    hr = SendRouteRequestToGns(endpoint, trackedRoute, hns::ModifyRequestType::Add);
                    if (FAILED(hr.value()))
                    {
                        trackedRoute.SyncStatus = PendingUpdate;
                        trackedRoute.SyncRetryCount = TrackedRoute::MaxSyncRetryCount;
                    }

Copilot AI review requested due to automatic review settings August 19, 2026 23:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Suppressed comments (1)

src/windows/service/exe/WslMirroredNetworking.cpp:1416

  • In the refresh-all-routes retry path, the code now only ever sends ModifyRequestType::Add, but on failure it sets SyncStatus = PendingUpdate. Since PendingUpdate no longer results in an Update request (it’s handled identically to PendingAdd), keeping the status as PendingUpdate is misleading and makes future debugging harder. Consider using PendingAdd here (or renaming the enum more broadly) to match the actual behavior.
                    hr = SendRouteRequestToGns(endpoint, trackedRoute, hns::ModifyRequestType::Add);
                    if (FAILED(hr.value()))
                    {
                        trackedRoute.SyncStatus = PendingUpdate;
                        trackedRoute.SyncRetryCount = TrackedRoute::MaxSyncRetryCount;
                    }

Copilot AI review requested due to automatic review settings August 20, 2026 20:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Suppressed comments (1)

src/windows/service/exe/WslMirroredNetworking.cpp:1403

  • Grammar: use "A" (not "An") before "ModifyRequestType::Add".
            // An ModifyRequestType::Add plumbs a new route or leaves an existing one in place (EEXIST is ignored),

@FetoiuCatalin FetoiuCatalin changed the title [draft] Handle route update as add instead of replace In mirrored mode, handle route update as add instead of replace Aug 21, 2026
@FetoiuCatalin
FetoiuCatalin marked this pull request as ready for review August 21, 2026 19:24
@FetoiuCatalin
FetoiuCatalin requested a review from a team as a code owner August 21, 2026 19:24
OneBlue
Blue (OneBlue) previously approved these changes Aug 21, 2026
@benhillis

Copy link
Copy Markdown
Member

FetoiuCatalin - is this ready to be merged?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Fix the test gateways so routes are valid on-link, and correct the comment typo.

Get a fresh assessment by requesting another Copilot review.

Review details

Suppressed comments (1)

src/windows/service/exe/WslMirroredNetworking.cpp:1403

  • The newly added comment has a grammatical typo: use “A ModifyRequestType::Add” rather than “An ModifyRequestType::Add.”
            // An ModifyRequestType::Add plumbs a new route or leaves an existing one in place (EEXIST is ignored),
  • Files reviewed: 4/4 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread test/windows/NetworkTests.cpp Resolved
@FetoiuCatalin
FetoiuCatalin marked this pull request as ready for review September 15, 2026 23:46
@FetoiuCatalin
FetoiuCatalin requested a review from a team as a code owner September 15, 2026 23:46
Copilot AI review requested due to automatic review settings September 15, 2026 23:50