alsmith / multicast-relay

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

OpenWRT and python3 #72

Closed luisfavila closed 1 year ago

luisfavila commented 1 year ago

Hi,

I've just tried running on openwrt 22.03.3 which only has python 3.10 available. Without the openwrt-python-encodings supplied, I get:

('Adding broadcast relay for 255.255.255.255:6969 (Sonos Setup Discovery)',) {}
Traceback (most recent call last):
  File "/root/multicast-relay/./multicast-relay.py", line 1029, in <module>
    sys.exit(main())
  File "/root/multicast-relay/./multicast-relay.py", line 1024, in main
    packetRelay.addListener(addr, port, relay[1])
  File "/root/multicast-relay/./multicast-relay.py", line 298, in addListener
    (ifname, mac, ip, netmask, broadcast) = self.getInterface(interface)
  File "/root/multicast-relay/./multicast-relay.py", line 738, in getInterface
    if interface in self.nif.interfaces():
  File "/root/multicast-relay/./multicast-relay.py", line 98, in interfaces
    ifNames = ifNames.tostring()
AttributeError: 'array.array' object has no attribute 'tostring'

With them put in the /usr/lib/python3.10/encodings directory, it instead errors with:

Python path configuration:
  PYTHONHOME = (not set)
  PYTHONPATH = (not set)
  program name = 'python'
  isolated = 0
  environment = 1
  user site = 1
  import site = 1
  sys._base_executable = '/usr/bin/python'
  sys.base_prefix = '/usr'
  sys.base_exec_prefix = '/usr'
  sys.platlibdir = 'lib'
  sys.executable = '/usr/bin/python'
  sys.prefix = '/usr'
  sys.exec_prefix = '/usr'
  sys.path = [
    '/usr/lib/python310.zip',
    '/usr/lib/python3.10',
    '/usr/lib/python3.10/lib-dynload',
  ]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
  File "/usr/lib/python3.10/encodings/__init__.py", line 123
    raise CodecRegistryError,\
                            ^
SyntaxError: invalid syntax

Current thread 0x77ed5d80 (most recent call first):
  <no Python frame>

Are you able to provide any pointers?

yitzhaq commented 1 year ago

I think the clue here is the netifaces module, which with Python 3 is now finally available as a package in OpenWRT, removing the need for special hacks. So I think you can just scratch the entirety of the OpenWRT-specific instructions now, and just do this instead:

opkg install python3-light python3-netifaces

This has been working just fine for me for some time now.

Guess the docs should be updated to reflect the same?

luisfavila commented 1 year ago

Yap, that works flawlessly. Thank you!

yitzhaq commented 1 year ago

Happy to hear this worked for you! However, I wonder if this might be worth reopening until the docs are updated, so others can benefit from the same solution? I know whenever I encounter trouble, I always check the open bug reports first to see if someone else has experienced the same thing, and maybe found a fix or workaround which the author hasn't had a chance to implement yet.

alsmith commented 1 year ago

Docs have been updated.