microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.5k stars 822 forks source link

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

Open EliasJRH opened 1 month ago

EliasJRH commented 1 month ago

Windows Version

Microsoft Windows [Version 10.0.22631.4249]

WSL Version

2.0.14.0

Are you using WSL 1 or WSL 2?

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

github-actions[bot] commented 1 month ago

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](https://github.com/Microsoft/WSL/blob/master/diagnostics/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](https://github.com/Microsoft/WSL/blob/master/diagnostics/collect-networking-logs.ps1), following the instructions [here](https://github.com/microsoft/WSL/blob/master/CONTRIBUTING.md#collect-wsl-logs-for-networking-issues) Once completed please upload the output files to this Github issue. [Click here for more info on logging](https://github.com/microsoft/WSL/blob/master/CONTRIBUTING.md#8-collect-wsl-logs-recommended-method) If you choose to email these logs instead of attaching to the bug, please send them to wsl-gh-logs@microsoft.com 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 commented 1 month ago

Log zips: WslLogs-2024-10-03_12-06-03.zip WslNetworkingLogs-2024-10-03_12-05-08.zip

github-actions[bot] commented 1 month ago
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 ```
EliasJRH commented 1 month ago

Bump for visibility

borjamunozf commented 4 weeks ago

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 commented 4 weeks ago

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 commented 2 weeks ago

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

Tested with:

Did you find the issue?

EliasJRH commented 2 weeks ago

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 commented 2 weeks ago

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 commented 1 week ago

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 commented 2 days ago

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

Same result, it does not work.