Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applications running on host not receiving UDP multicast packets sent from WSL2 #12122

Open
1 of 2 tasks
EliasJRH opened this issue Oct 3, 2024 · 12 comments
Open
1 of 2 tasks
Labels

Comments

@EliasJRH
Copy link

EliasJRH commented Oct 3, 2024

Windows Version

Microsoft Windows [Version 10.0.22631.4249]

WSL Version

2.0.14.0

Are you using WSL 1 or WSL 2?

  • WSL 2
  • WSL 1

Kernel Version

5.15.133.1-1

Distro Version

Ubuntu 22.04

Other Software

Wireshark Version 4.2.3

Repro Steps

First create a .wslconfig config file and set networkingMode=mirrored under [wsl2] as per https://learn.microsoft.com/en-us/windows/wsl/networking#mirrored-mode-networking. File should look like

[wsl2]
networkingMode=mirrored

Shutdown and restart wsl2
In wsl2 run program that sends UDP packets to a valid multicast address. I'm using the following python script:

import socket
import struct
import time

MULTICAST_GROUP = '224.1.1.1'  # Change to your desired multicast address
PORT = 5004  # Change to your desired port

# Create the socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)

# Set the socket option to allow multicast
sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2)

# Send multicast packets
while True:
    message = b'This is a multicast message'
    sock.sendto(message, (MULTICAST_GROUP, PORT))
    print(f'Sent: {message}')
    time.sleep(1)  # Send a packet every second

In separate powershell terminal, run program that reads from the same multicast address. I'm using the following python scripts:

import socket
import struct

MULTICAST_GROUP = '224.1.1.1'  # Match the address used in the sender
PORT = 5004  # Match the port used in the sender

# Create the socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(('', PORT))

# Tell the operating system to add the socket to the multicast group
group = socket.inet_aton(MULTICAST_GROUP)
mreq = struct.pack('4sL', group, socket.INADDR_ANY)
sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)

print(f'Ready to receive on {MULTICAST_GROUP}:{PORT}')

# Receive multicast packets
while True:
    data, addr = sock.recvfrom(1024)  # Buffer size is 1024 bytes
    print(f'Received message: {data} from {addr}')

Expected Behavior

Receiving script should correctly read packets from multicast address. When both programs are run on powershell, output of receiving script will look like this:
image
The source ip address will be the ip address from wsl2

Actual Behavior

Receiving script receives no packets. This behavior is particularly strange as Wireshark is able to see these packets
image
Note that the source ip address is that of eth1, output of ip addr in wsl2:
image

Diagnostic Logs

No response

Copy link

github-actions bot commented Oct 3, 2024

Logs are required for review from WSL team

If this a feature request, please reply with '/feature'. If this is a question, reply with '/question'.
Otherwise please attach logs by following the instructions below, your issue will not be reviewed unless they are added. These logs will help us understand what is going on in your machine.

How to collect WSL logs

Download and execute collect-wsl-logs.ps1 in an administrative powershell prompt:

Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/collect-wsl-logs.ps1" -OutFile collect-wsl-logs.ps1
Set-ExecutionPolicy Bypass -Scope Process -Force
.\collect-wsl-logs.ps1

The script will output the path of the log file once done.

If this is a networking issue, please use collect-networking-logs.ps1, following the instructions here

Once completed please upload the output files to this Github issue.

Click here for more info on logging
If you choose to email these logs instead of attaching to the bug, please send them to [email protected] with the number of the github issue in the subject, and in the message a link to your comment in the github issue and reply with '/emailed-logs'.

View similar issues

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@EliasJRH
Copy link
Author

EliasJRH commented Oct 3, 2024

Copy link

github-actions bot commented Oct 3, 2024

Diagnostic information
Multiple log files found, using: https://github.com/user-attachments/files/17247050/WslLogs-2024-10-03_12-06-03.zip
.wslconfig found
Detected appx version: 2.0.14.0

@OneBlue OneBlue added the network label Oct 3, 2024
@EliasJRH
Copy link
Author

EliasJRH commented Oct 8, 2024

Bump for visibility

@borjamunozf
Copy link

Wonder if could be related to a missing kernel option?
The 5.15. x does not have the option enabled by default, but the 6.6.x

CONFIG_IP_MULTICAST=y

do you have it enabled?

@EliasJRH
Copy link
Author

EliasJRH commented Oct 25, 2024

Wonder if could be related to a missing kernel option? The 5.15. x does not have the option enabled by default, but the 6.6.x

CONFIG_IP_MULTICAST=y

do you have it enabled?

By running zcat /proc/config.gz | grep MULTICAST, I can see that CONFIG_IP_MULTICAST is not set. I'm wondering why this was omitted from the wsl2 documentation if it is required for multicast to work.

@borjamunozf
Copy link

By the way, I tested your app with CONFIG_IP_MULTICAST but I have the same issue as you:

  • Windows app side does not receive multicast
  • Traffic in Wireshark could be seen from WSL to Windows.
  • Tried to setup sender in Windows and receiver in WSL, same result (can see packets sent from Windows to WSL)

Tested with:

  • firewall=true / firewall=false and applying HyperV firewall rules to allow inboud/outbound UDP traffix.

Did you find the issue?

@EliasJRH
Copy link
Author

EliasJRH commented Nov 8, 2024

I did not try any solution that would involve setting CONFIG_IP_MULTICAST (to my knowledge this would require using a new kernel in wsl2). For what I was doing, I created a new distro and set its version number to 1 which allowed wsl to share the network interface of the host and that allowed inbound/outbound multicast traffic.

Apart from using a kernel with CONFIG_IP_MULTICAST enabled, I'm not sure what the issue could be.

@borjamunozf
Copy link

borjamunozf commented Nov 8, 2024

I did not try any solution that would involve setting CONFIG_IP_MULTICAST (to my knowledge this would require using a new kernel in wsl2). For what I was doing, I created a new distro and set its version number to 1 which allowed wsl to share the network interface of the host and that allowed inbound/outbound multicast traffic.

Apart from using a kernel with CONFIG_IP_MULTICAST enabled, I'm not sure what the issue could be.

Wel,, it seems that CONFIG_IP_MULTICAST (I built a custom kernel with it enabled 5.15.153...) is not enough.

However, you're right that using WSL1 makes the app work. But something is missing in WSL2 with mirrored... but what?
I'm starting to consider that this issue we're facing could be related... #11966

EDITED: @EliasJRH I made it working in WSL2 using:

_networkingMode=bridged

Creating VMSwitch External for my Ethernet Windows interface._

Setting up systemd & assigning IP...

Image

Image

@hen-ning-r
Copy link

hen-ning-r commented Nov 13, 2024

Since months observing the release notes, I would appreciate if UDP Multicast would finally work within a Windows 11/WSL2/DevContainer environment.

To give some motivation for roadmap priority:

Many machinery/industry protocols use derivates of UDP protocols, using UDP Multicast for fast communication and automated discovery. Examples are GigE for industrial vision or Cyclone DDS used in ROS2. Using those protocols independently from the environment is a missing link in context of DevContainers which becoming best practice meanwhile.

While UDP Multicast in Linux<>DevContainer (most often used with "host-networking" works well I found no documented success for Windows<>DevContainer till now. So: congratulations that you finally found this solution (sadly I had no time to validate for me). Generally I look for ways to ease the "entry" into ROS2 programming for students coming with their personal devices. A user-friendly solution by default WSL is sorely missed - or just unknown by the public.

@borjamunozf
Copy link

FYI: Tested with latest 2.4.4 prerelease, just in case.

Same result, it does not work.

@shixudong2020
Copy link

multicast between Windows host and WSL2 (mirrored) not need CONFIG_IP_MULTICAST=y
1.Windows host-> WSL2 (mirrored)
Run a multicast receiver simultaneously on the Windows host. Then, when the Windows host sends a multicast packet, it also sends a copy to the loopback device, and mirrors the multicast packet to the receiving direction of the WSL2's mirrored NIC. In this way, WSL2 can receive the multicast packet from the Windows host smoothly.
2.WSL2 (mirrored)->Windows host
hostAddressLoopback=true,and WSL executes "sudo ip route add 224.1.1.1 via 169.254.73.152 dev eth0 onlink", then Windows host can successfully receive multicast packets from WSL2 (mirrored)
for detail,please see WSL2 and multicast(https://blog.csdn.net/sxd2001/article/details/144649381)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants