Skip to content

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

@EliasJRH

Description

@EliasJRH

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions