alsmith / multicast-relay

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

problems with modern kernels that won't pass Sonos broadcasts (255.255.255.255:6969) #41

Closed chassell closed 3 years ago

chassell commented 3 years ago

I found the broadcast IP was used but that never received any packets on a 4.19 kernel. T

diff --git a/multicast-relay.py b/multicast-relay.py
index 77b07a7..4fb7f83 100755
--- a/multicast-relay.py
+++ b/multicast-relay.py
@@ -8,6 +8,7 @@ import os
 import re
 import select
 import socket
+import IN
 import struct
 import sys
 import time
@@ -284,11 +285,12 @@ class PacketRelay():
                 rx = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_UDP)
                 rx.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
                 rx.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
+                rx.setsockopt(socket.SOL_SOCKET, IN.SO_BINDTODEVICE, ifname)

-                rx.bind((broadcast, port))
+                rx.bind(('0.0.0.0', port))

                 self.receivers.append(rx)
-                listenIP = broadcast
+                listenIP = '255.255.255.255'

             elif self.isMulticast(addr):
                 packedAddress = struct.pack('4s4s', socket.inet_aton(addr), socket.inet_aton(ip))
dlashua commented 3 years ago

@chassell THANK YOU! This is exactly what I needed to get this working for my use case on UDM-Base.

GoodOlClint commented 3 years ago

I had to use rx.setsockopt(socket.SOL_SOCKET, socket.SO_BINDTODEVICE, ifname.encode('utf-8')) for this to work on my UDM-Pro, but it does work and I can relay arbitrary UDP broadcasts now.

alsmith commented 3 years ago

Fixed in PR#47 - thanks for the patch contribution!

chassell commented 3 years ago

Glad to help. I'll go see if I can pull in the new version for my firewall.

On Mon, Feb 8, 2021 at 2:18 AM Al Smith notifications@github.com wrote:

Fixed in PR#47 - thanks for the patch contribution!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/alsmith/multicast-relay/issues/41#issuecomment-774997933, or unsubscribe https://github.com/notifications/unsubscribe-auth/AG4RPLSHKHBP52FL7AKORL3S56T5BANCNFSM4VH2DZKA .

-- The people who achieve are those who want knowledge so badly, they seek it while conditions are still unfavorable -- C.S. Lewis