Skip to content

Port System.Net.NetworkInformation to SunOS - #125054

Closed
gwr wants to merge 6 commits into
dotnet:mainfrom
gwr:sunos-netif
Closed

Port System.Net.NetworkInformation to SunOS#125054
gwr wants to merge 6 commits into
dotnet:mainfrom
gwr:sunos-netif

Conversation

@gwr

@gwrgwr commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

Use PF_LINK on SunOS
getifaddrs on illumos needs -lsocket -lnsl
Get MTU for IF_LINK in SystemNative_GetNetworkInterfaces Add NetworkInterface support files for SunOS

Test passes: System.Net.NetworkInformation.Functional.Tests
System.Net.NetworkInformation.Functional.Tests
Total: 239, Errors: 0, Failed: 20, Skipped: 1, Time: 2.088s

This PR should replace #124728

CopilotAI review requested due to automatic review settings March 2, 2026 14:13
@dotnet-policy-servicedotnet-policy-serviceBot added the community-contribution Indicates that the PR has been added by a community member label Mar 2, 2026
@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.

@gwrgwr mentioned this pull request Mar 2, 2026

CopilotAI 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 PR ports portions of System.Net.NetworkInformation to SunOS (Solaris/illumos) by enabling interface enumeration via getifaddrs, preferring AF_LINK/PF_LINK over AF_PACKET, and wiring up SunOS-specific managed and native build plumbing.

Changes:

  • Update native configuration/build logic for SunOS (CMake, address family mapping, interface MTU for AF_LINK).
  • Add SunOS-specific managed implementations for NetworkInterfacePal / IPGlobalPropertiesPal and related types.
  • Remove UnsupportedOSPlatform annotations for illumos/solaris on NetworkInterface / IPGlobalProperties.

Reviewed changes

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

Show a summary per file
FileDescription
src/native/libs/configure.cmakeAdjusts configure-time linking for getifaddrs on SunOS.
src/native/libs/System.Native/CMakeLists.txtAdds SunOS-native source selection (incl. SunOS network statistics stub).
src/native/libs/System.Native/pal_networkstatistics_sunos.cIntroduces SunOS stubbed network statistics entrypoints.
src/native/libs/System.Native/pal_networking.hAdds PAL AF_LINK address family constant.
src/native/libs/System.Native/pal_networking.cAdds AF_LINK conversions between platform and PAL.
src/native/libs/System.Native/pal_maphardwaretype.cAvoids AF_PACKET on SunOS to prevent private-header dependencies.
src/native/libs/System.Native/pal_interfaceaddresses.cPrefers AF_LINK, skips invalid alias indices, and fetches MTU for AF_LINK.
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkInterface.csRemoves illumos/solaris unsupported annotations.
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPGlobalProperties.csRemoves illumos/solaris unsupported annotations.
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkInterfacePal.SunOS.csImplements NetworkInterfacePal for SunOS via getifaddrs interop.
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SunOSNetworkInterface.csAdds SunOS UnixNetworkInterface implementation.
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SunOSIPInterfaceProperties.csAdds SunOS IP interface properties type.
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SunOSIPv4InterfaceProperties.csAdds SunOS IPv4 properties (mostly unsupported beyond MTU).
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SunOSIPv6InterfaceProperties.csAdds SunOS IPv6 properties (scope ID + MTU).
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPGlobalPropertiesPal.SunOS.csWires SunOS IPGlobalPropertiesPal.
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SunOSIPGlobalProperties.csAdds SunOS global properties implementation (currently throws for most APIs).
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SunOSIPGlobalStatistics.csAdds SunOS minimal global statistics implementation.
src/libraries/System.Net.NetworkInformation/src/System.Net.NetworkInformation.csprojIncludes SunOS-specific managed sources for illumos/solaris.
Comments suppressed due to low confidence (5)

src/libraries/System.Net.NetworkInformation/src/System.Net.NetworkInformation.csproj:221

  • Spelling in the comment: "uisng" should be "using".
 <Compile Include="System\Net\NetworkInformation\NetworkAddressChange.UnknownUnix.cs" />
<!-- Could port NetworkAddressChange.Android.cs uisng a PF_ROUTE socket -->
</ItemGroup>

src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SunOSNetworkInterface.cs:123

  • Spelling in comments: "iplement" should be "implement".
 // Future: iplement via kstats
public override IPInterfaceStatistics GetIPStatistics()
=> throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform);
// Future: iplement via kstats

src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SunOSNetworkInterface.cs:132

  • Spelling in comments: "iplement" should be "implement".
 // Future: iplement via kstats
// Just return zero for now.

src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SunOSNetworkInterface.cs:6

  • Spelling: "Eveything" should be "Everything" in the file header comment.
// Similar to the BSD and Linux code in use of getifaddrs()
// Eveything else is different (properties and statistics via kstats)

src/native/libs/System.Native/pal_interfaceaddresses.c:476

  • There are tab characters in this block (notably the closing brace indentation and the #endif comment alignment). Repo-wide .editorconfig specifies indent_style = space, so these should be converted to spaces to match formatting conventions.
 if (ioctl(socketfd, SIOCGIFMTU, &ifr) == 0)
{
nii->Mtu = ifr.ifr_mtu;
}
}

Comment threadsrc/native/libs/configure.cmake
Comment threadsrc/native/libs/System.Native/pal_networkstatistics_sunos.c Outdated
@jkotasjkotas added the os-SunOS SunOS, currently not officially supported label Mar 2, 2026
Use PF_LINK on SunOS
getifaddrs on illumos needs -lsocket -lnsl
Get MTU for IF_LINK in SystemNative_GetNetworkInterfaces
Add NetworkInterface support files for SunOS
Passes most of: System.Net.NetworkInformation.Functional.Tests
Co-authored-by: Copilot <Copilot@users.noreply.github.com>
@am11

am11 commented Mar 2, 2026

Copy link
Copy Markdown
Member

Failed: 20

Use SkipOnPlatform attribute (#124728 (comment)) and bring this count to 0. Those 20 should either be Skipped if the functionality is conclusively unsupported (underlying OS doesn't provide the info) or Passed (functionality is missing; in which case implement or add TODO in a reason message if it's something we need to tackle later).

@gwr

gwr commented Mar 2, 2026

Copy link
Copy Markdown
ContributorAuthor

Failed: 20

Use SkipOnPlatform attribute ([#124728 (comment)]

Thanks. Working on that.

CopilotAI review requested due to automatic review settings March 3, 2026 00:36
@gwr

gwr commented Mar 3, 2026

Copy link
Copy Markdown
ContributorAuthor

Added SkipOnPlatform lines. Now I see:

=== TEST EXECUTION SUMMARY ===
System.Net.NetworkInformation.Functional.Tests Total: 219, Errors: 0, Failed: 0, Skipped: 1, Time: 1.899s
/tank/ws/dotnet/runtime/test-netinfo
----- end March 2, 2026 at 07:24:10 PM EST ----- exit code 0 ----------------------------------------------------------
exit code 0 means Exited Successfully

CopilotAI 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 25 out of 25 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SunOSNetworkInterface.cs:66

  • The local variable is named lni (LinuxNetworkInterface) in a SunOS-specific implementation, which makes the code harder to read/maintain. Rename it (and the matching TryGetValue out var below) to something SunOS-appropriate like sni or sunOsNi.
 {
var lni = new SunOSNetworkInterface(Utf8StringMarshaller.ConvertToManaged(nii->Name)!, nii->InterfaceIndex);
lni._interfaceType = (NetworkInterfaceType)nii->HardwareType;
lni._speed = nii->Speed; // Note: not filled in (-1)

…workInformation/SunOSNetworkInterface.cs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
CopilotAI review requested due to automatic review settings March 3, 2026 00:49

CopilotAI 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 25 out of 25 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SunOSNetworkInterface.cs:69

  • The local variable name lni in SunOSNetworkInterface is a copy/paste artifact (it reads like "LinuxNetworkInterface") and makes the code harder to follow on this platform. Rename it (and the corresponding out-var) to something SunOS-specific like sni to avoid confusion.
 var lni = new SunOSNetworkInterface(Utf8StringMarshaller.ConvertToManaged(nii->Name)!, nii->InterfaceIndex);
lni._interfaceType = (NetworkInterfaceType)nii->HardwareType;
lni._speed = nii->Speed; // Note: not filled in (-1)
lni._operationalStatus = (OperationalStatus)nii->OperationalState;
lni._mtu = nii->Mtu;
lni._supportsMulticast = nii->SupportsMulticast != 0;

Comment threadsrc/native/libs/System.Native/pal_interfaceaddresses.c Outdated
CopilotAI review requested due to automatic review settings March 3, 2026 01:30
@am11am11 added the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Mar 3, 2026
@am11

am11 commented Mar 3, 2026

Copy link
Copy Markdown
Member

@dotnet/ncl, I have added No Merge label as this is not a complete port. I suggest we shouldn't take incomplete changes which are more meaningless than saying NotSupported assembly as we have in main.

CopilotAI 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 25 out of 25 changed files in this pull request and generated no new comments.

@gwr

gwr commented Mar 3, 2026

Copy link
Copy Markdown
ContributorAuthor

@dotnet/ncl, I have added No Merge label as this is not a complete port. I suggest we shouldn't take incomplete changes which are more meaningless than saying NotSupported assembly as we have in main.

Can you offer a list of what would be needed to let this be considered "complete"?

Would you rather see something like #124728 until this network interface work can do more than show you the local interfaces etc?

@am11

am11 commented Mar 3, 2026

Copy link
Copy Markdown
Member

what would be needed to let this be considered "complete"?

By implementing the functionality.. All currently failing (skipped) tests that are not skipped on FreeBSD should be passing for this PR to be considered complete port. If something is not available on the OS, we need to understand and decide whether to throw NotSupportedException, return some sentinel/default value or some such. We can't just mislabel stuff and move on like you did in 03882c1. You cannot just reason "Not supported on SunOS" on something like NetworkAddressChanged_AddRemove_Success which is probably the most basic API in this entire namespace!

@gwr
gwr marked this pull request as draft March 3, 2026 13:08
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Draft Pull Request was automatically closed for 30 days of inactivity. Please let us know if you'd like to reopen it.

@github-actionsgithub-actionsBot locked and limited conversation to collaborators May 3, 2026
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Netcommunity-contributionIndicates that the PR has been added by a community memberNO-MERGEThe PR is not ready for merge yet (see discussion for detailed reasons)os-SunOSSunOS, currently not officially supported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@gwr@am11@jkotas