Skip to content

Fix ForwardingEnabled always returning true on Windows - #138263

Merged
wfurt merged 1 commit into
dotnet:mainfrom
aaronfranke:fix-1.9-forwarding-always-true-windows
Nov 25, 2026
Merged

wfurt merged 1 commit into
dotnet:mainfrom
aaronfranke:fix-1.9-forwarding-always-true-windows

Conversation

@aaronfranke

Copy link
Copy Markdown
Contributor

The possible values of the Windows MIB_IPSTATS_FORWARDING enum, returned by GetIpStatisticsEx, are:

  • MIB_IP_FORWARDING = 1
  • MIB_IP_NOT_FORWARDING = 2

The existing .NET runtime code incorrectly compares with != 0:

public override bool ForwardingEnabled { get { return _stats.forwardingEnabled != 0; } }

This means that MIB_IP_NOT_FORWARDING is reported as ForwardingEnabled = 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.

The possible initialized values are 1 and 2,
so this always returns true when initialized.
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Nov 25, 2026
@azure-pipelines

Copy link
Copy Markdown
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.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @karelz, @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

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

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 ForwardingEnabled as true only for Forwarding, 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

@aaronfranke

Copy link
Copy Markdown
Contributor Author

No unit test is practical, since the value depends on machine configuration.

@wfurt
wfurt merged commit cdcba20 into dotnet:main Nov 25, 2026
77 of 79 checks passed
@aaronfranke
aaronfranke deleted the fix-1.9-forwarding-always-true-windows branch November 25, 2026 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Net community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants