Skip to content

Port System.Net.NetworkInformation to SunOS#125054

Draft
gwr wants to merge 6 commits intodotnet:mainfrom
gwr:sunos-netif
Draft

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

Conversation

@gwr
Copy link
Contributor

@gwr gwr commented 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

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

Copilot AI review requested due to automatic review settings March 2, 2026 14:13
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Mar 2, 2026
@dotnet-policy-service
Copy link
Contributor

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

@gwr gwr mentioned this pull request Mar 2, 2026
Copy link
Contributor

Copilot AI left a comment

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
File Description
src/native/libs/configure.cmake Adjusts configure-time linking for getifaddrs on SunOS.
src/native/libs/System.Native/CMakeLists.txt Adds SunOS-native source selection (incl. SunOS network statistics stub).
src/native/libs/System.Native/pal_networkstatistics_sunos.c Introduces SunOS stubbed network statistics entrypoints.
src/native/libs/System.Native/pal_networking.h Adds PAL AF_LINK address family constant.
src/native/libs/System.Native/pal_networking.c Adds AF_LINK conversions between platform and PAL.
src/native/libs/System.Native/pal_maphardwaretype.c Avoids AF_PACKET on SunOS to prevent private-header dependencies.
src/native/libs/System.Native/pal_interfaceaddresses.c Prefers AF_LINK, skips invalid alias indices, and fetches MTU for AF_LINK.
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkInterface.cs Removes illumos/solaris unsupported annotations.
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPGlobalProperties.cs Removes illumos/solaris unsupported annotations.
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkInterfacePal.SunOS.cs Implements NetworkInterfacePal for SunOS via getifaddrs interop.
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SunOSNetworkInterface.cs Adds SunOS UnixNetworkInterface implementation.
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SunOSIPInterfaceProperties.cs Adds SunOS IP interface properties type.
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SunOSIPv4InterfaceProperties.cs Adds SunOS IPv4 properties (mostly unsupported beyond MTU).
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SunOSIPv6InterfaceProperties.cs Adds SunOS IPv6 properties (scope ID + MTU).
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPGlobalPropertiesPal.SunOS.cs Wires SunOS IPGlobalPropertiesPal.
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SunOSIPGlobalProperties.cs Adds SunOS global properties implementation (currently throws for most APIs).
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SunOSIPGlobalStatistics.cs Adds SunOS minimal global statistics implementation.
src/libraries/System.Net.NetworkInformation/src/System.Net.NetworkInformation.csproj Includes 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;
                }
	    }

@jkotas jkotas 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
Copy link
Member

am11 commented Mar 2, 2026

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
Copy link
Contributor Author

gwr commented Mar 2, 2026

Failed: 20

Use SkipOnPlatform attribute ([#124728 (comment)]

Thanks. Working on that.

Copilot AI review requested due to automatic review settings March 3, 2026 00:36
@gwr
Copy link
Contributor Author

gwr commented Mar 3, 2026

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

Copy link
Contributor

Copilot AI left a comment

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>
Copilot AI review requested due to automatic review settings March 3, 2026 00:49
Copy link
Contributor

Copilot AI left a comment

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;

Copilot AI review requested due to automatic review settings March 3, 2026 01:30
@am11 am11 added the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Mar 3, 2026
@am11
Copy link
Member

am11 commented Mar 3, 2026

@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.

Copy link
Contributor

Copilot AI left a comment

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
Copy link
Contributor Author

gwr commented Mar 3, 2026

@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
Copy link
Member

am11 commented Mar 3, 2026

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
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 NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) os-SunOS SunOS, currently not officially supported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants