Skip to content

Conversation

@liveans
Copy link
Member

@liveans liveans commented Sep 4, 2025

Fixes #118654 and #113827

With this fix we can set MulticastInterface socket option successfully, I tested the Multicast capabilities, and it seems to be working as expected.

Seems like Apple doesn't support ip_mreqn struct with IPv4 Sockets. Kernel header file description

sw_vers
ProductName:		macOS
ProductVersion:		26.0
BuildVersion:		25A5349a
../../../../../dotnet.sh build /t:test /p:outerloop=true /p:xunitoptions="-method System.Net.Sockets.Tests.SocketOptionNameTest.MulticastInterface_Set_AnyInterface_Succeeds"

  Determining projects to restore...
  All projects are up-to-date for restore.
  TestUtilities -> /Users/liveans/Desktop/dotnet-runtime/artifacts/bin/TestUtilities/Debug/net8.0/TestUtilities.dll
  StreamConformanceTests -> /Users/liveans/Desktop/dotnet-runtime/artifacts/bin/StreamConformanceTests/Debug/net10.0/StreamConformanceTests.dll
  System.Net.Sockets.Tests -> /Users/liveans/Desktop/dotnet-runtime/artifacts/bin/System.Net.Sockets.Tests/Debug/net10.0-unix/System.Net.Sockets.Tests.dll
  ========================= Begin custom configuration settings ==============================
  export __IsXUnitLogCheckerSupported=1
  export XUNIT_HIDE_PASSING_OUTPUT_DIAGNOSTICS=1
  ========================== End custom configuration settings ===============================
  ----- start Thu Sep 4 17:36:24 +03 2025 =============== To repro directly: =====================================================
  pushd /Users/liveans/Desktop/dotnet-runtime/artifacts/bin/System.Net.Sockets.Tests/Debug/net10.0-unix
  /Users/liveans/Desktop/dotnet-runtime/artifacts/bin/testhost/net10.0-osx-Debug-arm64/dotnet exec --runtimeconfig System.Net.Sockets.Tests.runtimeconfig.json --depsfile System.Net.Sockets.Tests.deps.json /Users/liveans/.nuget/packages/microsoft.dotnet.xunitconsolerunner/2.9.3-beta.25420.121/build/../tools/net/xunit.console.dll System.Net.Sockets.Tests.dll -xml testResults.xml -nologo -notrait category=failing -method System.Net.Sockets.Tests.SocketOptionNameTest.MulticastInterface_Set_AnyInterface_Succeeds 
  popd
  ===========================================================================================================
  ~/Desktop/dotnet-runtime/artifacts/bin/System.Net.Sockets.Tests/Debug/net10.0-unix ~/Desktop/dotnet-runtime/src/libraries/System.Net.Sockets/tests/FunctionalTests
    Discovering: System.Net.Sockets.Tests (method display = ClassAndMethod, method display options = None)
    Discovered:  System.Net.Sockets.Tests (found 1 of 1875 test case)
    Starting:    System.Net.Sockets.Tests (parallel test collections = on [16 threads], stop on fail = off)
    Finished:    System.Net.Sockets.Tests
  === TEST EXECUTION SUMMARY ===
     System.Net.Sockets.Tests  Total: 1, Errors: 0, Failed: 0, Skipped: 0, Time: 0,041s
  ~/Desktop/dotnet-runtime/src/libraries/System.Net.Sockets/tests/FunctionalTests
  ----- end Thu Sep 4 17:36:24 +03 2025 ----- exit code 0 ----------------------------------------------------------
  exit code 0 means Exited Successfully

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:03.15

/cc @vcsjones @wfurt

Copilot AI review requested due to automatic review settings September 4, 2025 14:45
@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Sep 4, 2025
@liveans liveans changed the title On OSX ip_mreqn struct is not supported for IPv4 [OSX] ip_mreqn struct is not supported for IPv4 Multicast Sep 4, 2025
@liveans liveans added area-System.Net.Sockets and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Sep 4, 2025
@dotnet-policy-service
Copy link
Contributor

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

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 fixes a macOS compatibility issue where the ip_mreqn struct is not supported for IPv4 multicast socket operations. The fix prevents the use of ip_mreqn on Apple platforms, resolving exceptions when setting the MulticastInterface socket option.

Key changes:

  • Excludes Apple platforms from using the ip_mreqn struct in IPv4 multicast operations
  • Allows the code to fall back to alternative multicast handling approaches on macOS

@wfurt
Copy link
Member

wfurt commented Sep 4, 2025

Looking at the code, we will throw if the interface index is set since ip_mreq does not have a filed, right? We can perhaps document that but it would be nice to actually verify that the multicast subscription works as expected and one can pin the interface using SocketOptionName.MulticastInterface.

@liveans
Copy link
Member Author

liveans commented Sep 5, 2025

While reading the kernel code to understand how to make it work, I stumbled upon IP_MULTICAST_IFINDEX and it seems to be specific to Apple platforms. Tested it through Wireshark it works as expected. I can make condition even more specified to check for both Addresses should be zero etc, but in this way, if we provide a InterfaceIndex, it will take over priority.

/cc @wfurt

@liveans liveans force-pushed the ipv4_multicast_osx_fix branch from 8cbb38d to 5cc12a8 Compare September 5, 2025 02:37
@liveans liveans requested a review from wfurt September 5, 2025 02:52
@vcsjones
Copy link
Member

vcsjones commented Sep 5, 2025

Do we think this will fix it for iOS too?

The test MulticastInterface_Set_AnyInterface_Succeeds has been disabled on iOS for quite a while now. It would be interesting to try removing the ActiveIssue and running the iOS pipelines and seeing what happens if we think there is a chance this chance will apply to iOS as well.

@liveans
Copy link
Member Author

liveans commented Sep 5, 2025

/azp list

@azure-pipelines
Copy link

CI/CD Pipelines for this repository:

@liveans
Copy link
Member Author

liveans commented Sep 5, 2025

Should I run ioslike pipeline for it ? @vcsjones

@vcsjones
Copy link
Member

vcsjones commented Sep 5, 2025

/azp run runtime-extra-platforms

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@liveans
Copy link
Member Author

liveans commented Sep 6, 2025

This PR also fixes the issue for other Apple platforms, only left issue is:

  • MacCatalyst test returns "SocketException: No route to host". (This might be due to reason of missing entitlement).

@wfurt
Copy link
Member

wfurt commented Sep 6, 2025

note that the routing error sometimes happens on other platforms as well.. #90491
(IPv6 but essentially same problem)

Also since you at multicast can you please check following issues? Maybe there is some hope for them as well.
#53767
#110889

@liveans liveans requested a review from wfurt September 8, 2025 18:44
Copy link
Member

@wfurt wfurt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. thanks @liveans for diffing in.

@liveans
Copy link
Member Author

liveans commented Sep 9, 2025

/ba-g xml test failure is not related

@liveans liveans merged commit 0e3562e into dotnet:main Sep 9, 2025
159 of 161 checks passed
@liveans
Copy link
Member Author

liveans commented Sep 9, 2025

/backport to release/10.0

@github-actions
Copy link
Contributor

github-actions bot commented Sep 9, 2025

@liveans
Copy link
Member Author

liveans commented Sep 9, 2025

/backport to release/9.0-staging

@liveans
Copy link
Member Author

liveans commented Sep 9, 2025

/backport to release/8.0-staging

@github-actions
Copy link
Contributor

github-actions bot commented Sep 9, 2025

Started backporting to release/8.0-staging: https://github.com/dotnet/runtime/actions/runs/17574101803

@github-actions
Copy link
Contributor

github-actions bot commented Sep 9, 2025

Started backporting to release/9.0-staging: https://github.com/dotnet/runtime/actions/runs/17574100129

@github-actions
Copy link
Contributor

github-actions bot commented Sep 9, 2025

@liveans backporting to "release/8.0-staging" failed, the patch most likely resulted in conflicts:

$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: Fix IPv4 multicast on macOS by handling ip_mreqn struct compatibility
Applying: Remove Active Issue for iOS
Using index info to reconstruct a base tree...
M	src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketOptionNameTest.cs
Falling back to patching base and 3-way merge...
Auto-merging src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketOptionNameTest.cs
CONFLICT (content): Merge conflict in src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketOptionNameTest.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0002 Remove Active Issue for iOS
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

@github-actions
Copy link
Contributor

github-actions bot commented Sep 9, 2025

@liveans backporting to "release/9.0-staging" failed, the patch most likely resulted in conflicts:

$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: Fix IPv4 multicast on macOS by handling ip_mreqn struct compatibility
Applying: Remove Active Issue for iOS
Using index info to reconstruct a base tree...
M	src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketOptionNameTest.cs
Falling back to patching base and 3-way merge...
Auto-merging src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketOptionNameTest.cs
CONFLICT (content): Merge conflict in src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketOptionNameTest.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0002 Remove Active Issue for iOS
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

liveans added a commit to liveans/dotnet-runtime that referenced this pull request Sep 9, 2025
)

* Fix IPv4 multicast on macOS by handling ip_mreqn struct compatibility

* Remove Active Issue for iOS

* Add support for IP_MULTICAST_IFINDEX

* Refactor IPv4 multicast option handling to directly use IP_MULTICAST_IFINDEX for interface index specification

* Accept 0 interface as valid

---------

Co-authored-by: Tomas Weinfurt <[email protected]>
liveans added a commit to liveans/dotnet-runtime that referenced this pull request Sep 9, 2025
)

* Fix IPv4 multicast on macOS by handling ip_mreqn struct compatibility

* Remove Active Issue for iOS

* Add support for IP_MULTICAST_IFINDEX

* Refactor IPv4 multicast option handling to directly use IP_MULTICAST_IFINDEX for interface index specification

* Accept 0 interface as valid

---------

Co-authored-by: Tomas Weinfurt <[email protected]>
@github-actions github-actions bot locked and limited conversation to collaborators Oct 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MulticastInterface_Set_AnyInterface_Succeeds fails on macOS 26 beta 6

4 participants