All listeners (broadcast / multicast / SSDP unicast) are of type SOCK_RAW and cannot be bound to any specific port. When rx.bind((addr, port)) is called, the sockets are bound only to the specified address and receive packets regardless of destination port.
For example, if Sonos discovery is enabled, then all UDP broadcast packets will be relayed.
Also, this can lead to infinite retransmission of packets.
Consider two machines connected by a Wireguard tunnel.
The first one has an Ethernet interface eth0 with address 192.168.0.10 and a Wireguard interface wg0 with address 10.0.0.1, which uses eth0 to connect to peers.
The second one has a Wireguard interface wg0 with address 10.0.0.2 and an interface lan1. Also, the second machine routes all requests to 192.168.0.0/24 via the Wireguard tunnel.
On the first machine, a relay is run with options --interfaces eth0 --ssdpUnicastAddr 192.168.0.10 --listen 10.0.0.2
On the second one, a relay is run with options --interfaces lan1 --remote 10.0.0.1
Possible cause of infinite retransmission in this setup:
The second machine (or any other peer) sends some data to the first machine over the Wireguard tunnel.
The unicast receiver (on the first machine) receives encrypted data encapsulated in UDP packets (with destination address 192.168.0.10). It retransmits these packets to the relay on the second machine.
The second relay sends the packets to 192.168.0.10 (they are routed via the Wireguard tunnel).
The unicast receiver receives new packets (with increased size). goto step 2
This can possibly lead to a crash of the relay or the machine may run out of memory
Possible solutions:
Use sockets of type SOCK_DGRAM as receivers (may break something)
All listeners (broadcast / multicast / SSDP unicast) are of type
SOCK_RAW
and cannot be bound to any specific port. Whenrx.bind((addr, port))
is called, the sockets are bound only to the specified address and receive packets regardless of destination port.For example, if Sonos discovery is enabled, then all UDP broadcast packets will be relayed.
Also, this can lead to infinite retransmission of packets. Consider two machines connected by a Wireguard tunnel. The first one has an Ethernet interface
eth0
with address192.168.0.10
and a Wireguard interfacewg0
with address10.0.0.1
, which useseth0
to connect to peers. The second one has a Wireguard interfacewg0
with address10.0.0.2
and an interfacelan1
. Also, the second machine routes all requests to192.168.0.0/24
via the Wireguard tunnel. On the first machine, a relay is run with options--interfaces eth0 --ssdpUnicastAddr 192.168.0.10 --listen 10.0.0.2
On the second one, a relay is run with options--interfaces lan1 --remote 10.0.0.1
Possible cause of infinite retransmission in this setup:192.168.0.10
). It retransmits these packets to the relay on the second machine.192.168.0.10
(they are routed via the Wireguard tunnel).Possible solutions: