@samitouri / QOSAMI-WSL / commits / 681619a7

Fix default route classification logic (#41278)

Only 0.0.0.0/0 and ::/0 should be treated as default routes. This PR adds the prefix length == 0 comparison to the condition.

Feng Wang committed Aug 10, 2026 at 10:04 UTC 681619a739494dca161aec379287d744f3735dbb
2 files changed +24 -2
src/windows/common/WslCoreNetworkEndpointSettings.h
+2 -2
@@ -222,8 +222,8 @@ struct EndpointRoute
222
223 bool IsDefault() const noexcept
224 {
225 - return (Family == AF_INET && DestinationPrefixString == LX_INIT_UNSPECIFIED_ADDRESS) ||
226 - (Family == AF_INET6 && DestinationPrefixString == LX_INIT_UNSPECIFIED_V6_ADDRESS);
225 + return DestinationPrefix.PrefixLength == 0 && ((Family == AF_INET && DestinationPrefixString == LX_INIT_UNSPECIFIED_ADDRESS) ||
226 + (Family == AF_INET6 && DestinationPrefixString == LX_INIT_UNSPECIFIED_V6_ADDRESS));
227 }
228
229 bool IsUnicastAddressRoute() const noexcept
test/windows/NetworkTests.cpp
+22
@@ -17,6 +17,7 @@ Abstract:
17 #include "Common.h"
18 #include "wslpolicies.h"
19 #include "hns_schema.h"
20 +#include "WslCoreNetworkEndpointSettings.h"
21
22 #include <mstcpip.h>
23 #include <winhttp.h>
@@ -296,6 +297,27 @@ class NetworkTests
297 return true;
298 }
299
300 + TEST_METHOD(DefaultRouteClassification)
301 + {
302 + const auto makeRoute = [](ADDRESS_FAMILY family, const wchar_t* destination, uint8_t prefixLength) {
303 + MIB_IPFORWARD_ROW2 routeRow{};
304 + routeRow.DestinationPrefix.Prefix = wsl::windows::common::string::StringToSockAddrInet(destination);
305 + routeRow.DestinationPrefix.PrefixLength = prefixLength;
306 + routeRow.NextHop.si_family = family;
307 + return wsl::core::networking::EndpointRoute(routeRow);
308 + };
309 +
310 + VERIFY_IS_TRUE(makeRoute(AF_INET, L"0.0.0.0", 0).IsDefault());
311 + VERIFY_IS_FALSE(makeRoute(AF_INET, L"0.0.0.0", 1).IsDefault());
312 + VERIFY_IS_FALSE(makeRoute(AF_INET, L"128.0.0.0", 1).IsDefault());
313 + VERIFY_IS_FALSE(makeRoute(AF_INET, L"0.0.0.0", 32).IsDefault());
314 +
315 + VERIFY_IS_TRUE(makeRoute(AF_INET6, L"::", 0).IsDefault());
316 + VERIFY_IS_FALSE(makeRoute(AF_INET6, L"::", 1).IsDefault());
317 + VERIFY_IS_FALSE(makeRoute(AF_INET6, L"8000::", 1).IsDefault());
318 + VERIFY_IS_FALSE(makeRoute(AF_INET6, L"::", 128).IsDefault());
319 + }
320 +
321 WSL2_TEST_METHOD(RemoveAndAddDefaultRoute)
322 {
323 TestCase({{L"eth0", {{L"192.168.0.2", 24}}, L"192.168.0.1", {{L"fc00::2", 64}}, L"fc00::1"}});