christgau / wsdd

A Web Service Discovery host daemon.
MIT License
861 stars 101 forks source link

error in main loop #45

Closed mrplumber closed 4 years ago

mrplumber commented 4 years ago

Hi, using latest git version (0.6) of wsdd, I'm getting errors (see below, please) although it still works.

# uname -a
Linux geras 4.19.0-9-amd64 #1 SMP Debian 4.19.118-2 (2020-04-29) x86_64 GNU/Linux
# cat /etc/debian_version
10.4
# /usr/local/bin/wsdd --verbose --interface br0 --chroot /run/wsdd/chroot/ -u nobody:nogroup
2020-06-06 18:47:09,950:wsdd INFO(pid 9265): using pre-defined UUID c4424de1-fe72-51b7-b552-adb441448b53
2020-06-06 18:47:09,961:wsdd INFO(pid 9265): chrooted successfully to /run/wsdd/chroot/
2020-06-06 18:47:09,961:wsdd INFO(pid 9265): running as nobody:nogroup (65534:65534)
2020-06-06 18:47:09,962:wsdd INFO(pid 9265): joined multicast group ('239.255.255.250', 3702) on 192.168.118.1%br0
2020-06-06 18:47:09,965:wsdd ERROR(pid 9265): error in main loop
Traceback (most recent call last):
  File "/usr/local/bin/wsdd", line 1626, in main
  File "/usr/local/bin/wsdd", line 1195, in handle_request
KeyError: 3
2020-06-06 18:47:09,974:wsdd INFO(pid 9265): 192.168.118.143 - - "POST /c4424de1-fe72-51b7-b552-adb441448b53 HTTP/1.1" 200 -
2020-06-06 18:47:09,977:wsdd INFO(pid 9265): 192.168.118.143 - - "POST /c4424de1-fe72-51b7-b552-adb441448b53 HTTP/1.1" 200 -
2020-06-06 18:47:10,016:wsdd INFO(pid 9265): 192.168.118.114 - - "POST /c4424de1-fe72-51b7-b552-adb441448b53 HTTP/1.1" 200 -

After refreshing 'Network' window on Windows 10 machine:

2020-06-06 18:49:10,784:wsdd INFO(pid 9265): 192.168.118.143:60472(br0) - - "Probe urn:uuid:31f774e8-bb70-47eb-8aa0-ec5157dfdb53 UDP" - -
2020-06-06 18:49:10,831:wsdd INFO(pid 9265): 192.168.118.143:60474(br0) - - "Resolve urn:uuid:85046a4f-62e6-4337-829b-2183943dea7d UDP" - -
2020-06-06 18:49:10,843:wsdd INFO(pid 9265): 192.168.118.143 - - "POST /c4424de1-fe72-51b7-b552-adb441448b53 HTTP/1.1" 200 -
2020-06-06 18:49:11,503:wsdd INFO(pid 9265): 192.168.118.143:60474(br0) - - "Resolve urn:uuid:3f737d43-1ffc-46f6-bf73-714c1de7d468 UDP" - -
2020-06-06 18:49:11,504:wsdd WARNING(pid 9265): invalid resolve request: address (urn:uuid:de8a0699-ffe6-593c-9964-c867d65adce0) does not match own one (urn:uuid:c4424de1-fe72-51b7-b552-adb441448b53)
christgau commented 4 years ago

Yeah, there is an apparently wrong assumption in the code that the interface (name) is always known before the index is used. I'll fix that. Although is it strange that the kernel provides information that refers to another information not yet provided...

maxfield-allison commented 4 years ago

@christgau are you currently aware of a temp workaround?

christgau commented 4 years ago

@christgau are you currently aware of a temp workaround?

Yes. The following should solve the problem.

diff --git a/src/wsdd.py b/src/wsdd.py
index c91eaa3..71e90f1 100755
--- a/src/wsdd.py
+++ b/src/wsdd.py
@@ -1192,11 +1192,14 @@ class NetlinkAddressMonitor(NetworkAddressMonitor):
                 offset += ((msg_len + 1) // NLM_HDR_ALIGNTO) * NLM_HDR_ALIGNTO
                 continue

-            iface = self.interfaces[ifa_idx]
-            if h_type == self.RTM_NEWADDR:
-                self.handle_new_address(addr, ifa_family, iface)
-            elif h_type == self.RTM_DELADDR:
-                self.handle_deleted_address(addr, ifa_family, iface)
+            if ifa_idx in self.interfaces:
+                iface = self.interfaces[ifa_idx]
+                if h_type == self.RTM_NEWADDR:
+                    self.handle_new_address(addr, ifa_family, iface)
+                elif h_type == self.RTM_DELADDR:
+                    self.handle_deleted_address(addr, ifa_family, iface)
+            else:
+                logger.debug('unknown interface index: {}'.format(ifa_idx))

             offset += ((msg_len + 1) // NLM_HDR_ALIGNTO) * NLM_HDR_ALIGNTO