Repository navigation
Fix ForwardingEnabled always returning true on Windows - #138263
Merged
wfurt merged 1 commit intoNov 25, 2026
Merged
Conversation
The possible initialized values are 1 and 2, so this always returns true when initialized.
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @karelz, @dotnet/ncl |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Regression coverage is missing for native forwarding values 1 and 2 across both address-family paths, leaving the Windows behavior change unprotected against the original implementation.
1 open issue
What changed in this PR
Corrects Windows IP forwarding reporting in System.Net.NetworkInformation for both IPv4 and IPv6 statistics.
Changes:
- Defines a
uint-backed enum matching Windows’ native forwarding values. - Reports
ForwardingEnabledas true only forForwarding, rather than treating both native values as enabled.
| File | Description |
|---|---|
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemIPGlobalStatistics.cs |
Compares the native result with the explicit forwarding-enabled value. |
src/libraries/Common/src/Interop/Windows/IpHlpApi/Interop.NetworkInformation.cs |
Adds the forwarding enum and uses it in the native statistics structure, preserving field width. |
Review effort: Balanced
This was referenced Nov 25, 2026
Contributor
Author
|
No unit test is practical, since the value depends on machine configuration. |
wfurt
approved these changes
Nov 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

The possible values of the Windows
MIB_IPSTATS_FORWARDINGenum, returned byGetIpStatisticsEx, are:MIB_IP_FORWARDING= 1MIB_IP_NOT_FORWARDING= 2The existing .NET runtime code incorrectly compares with
!= 0:This means that
MIB_IP_NOT_FORWARDINGis reported asForwardingEnabled = true.This PR changes the code to include an enum. This is preferable over the constants per the guidelines because it both matches an external enum, and it covers all possible initialized values.
Minimal reproduction project: windows-ipglobalstatistics-forwarding.zip
AI usage disclaimer: I encountered these .NET runtime bugs when using an AI to work on an unrelated project. I had it fix the bugs as it went, and now I am submitting fixes to each after manually reviewing the changes, and fixing them as needed. Most of these lines of code are AI-generated, including the tests and the MRP. The PR description and commit message are entirely human-written, as is always the case with every PR I open.