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

WSL2 networking mirrored - multicast support (Windows host <> WSL distro) #12344

Open
borjamunozf opened this issue Dec 4, 2024 · 4 comments
Labels

Comments

@borjamunozf
Copy link

Is your feature request related to a problem? Please describe.

Theorically, the documentation for WSL2 mirrored says that Multicast support is already in place, but there's a lof of issues linked to this:

#10735
#12122
#11966
#10614

I have faced myself this frustating problem through my company with a ROS2 app: Windows <> WSL2.
The default NAT mode is not a solution because it has other strange problem explained in #11966

Describe the solution you'd like

Multicast works in Mirrored mode between Windows and WSL Distro.

Describe alternatives you've considered

Additional context
The basic example I've been using to do quick test of multicast sender/receiver:

sender

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

receiver

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}')
Copy link

github-actions bot commented Dec 4, 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 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.

@borjamunozf
Copy link
Author

/feature

Copy link

github-actions bot commented Dec 4, 2024

Diagnostic information
Found '/feature', adding tag 'feature'

@shixudong2020
Copy link

shixudong2020 commented Dec 22, 2024

1.Windows host-> WSL distro
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.WSL distro->Windows host
hostAddressLoopback=true,and WSL executes "sudo ip route add 224.1.1.1 via 169.254.73.152 dev eth0 onlink", Here eth0 denotes the NIC on which the default route is located.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

2 participants