alsmith / multicast-relay

Relay multicast and broadcast packets between interfaces.
GNU General Public License v3.0
304 stars 47 forks source link

Rceivers are not bound to a specific port #44

Closed vvd170501 closed 3 years ago

vvd170501 commented 3 years ago

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:

  1. The second machine (or any other peer) sends some data to the first machine over the Wireguard tunnel.
  2. 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.
  3. The second relay sends the packets to 192.168.0.10 (they are routed via the Wireguard tunnel).
  4. 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:

  1. Use sockets of type SOCK_DGRAM as receivers (may break something)
  2. Check port for each incoming packet (this part of code may help, if used before relaying to remotes) https://github.com/alsmith/multicast-relay/blob/e9db7fb8fd7ea796cc7f0844cb5bdb70913c1952/multicast-relay.py#L586
vvd170501 commented 3 years ago

Fixed in #45