home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.07k stars 29.73k forks source link

cant set DLNA Event listener port #73607

Closed addich closed 2 years ago

addich commented 2 years ago

The problem

I have two DNLA integrations in home assistant behind a ufw firewall. I set for both of them different Event listener ports, but home assistant does not listen on those. After each restart the port do random change.

I run a docker image on ubuntu with network_mode: host

What version of Home Assistant Core has the issue?

core-2022.6.6

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

dlna_dmr

Link to integration documentation on our website

https://www.home-assistant.io/integrations/dlna_dmr

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

probot-home-assistant[bot] commented 2 years ago

dlna_dmr documentation dlna_dmr source (message by IssueLinks)

probot-home-assistant[bot] commented 2 years ago

Hey there @stevenlooman, @chishm, mind taking a look at this issue as it has been labeled with an integration (dlna_dmr) you are listed as a code owner for? Thanks! (message by CodeOwnersMention)

chishm commented 2 years ago

Thank you for the bug report. I've tried recreating the issue on my machine, but cannot. Can you please enable the following logging settings and try again:

logger:
  default: warning
  logs:
    homeassistant.components.dlna_dmr: debug

I'm interested in seeing lines akin to:

2022-06-19 21:21:24 DEBUG (MainThread) [homeassistant.components.dlna_dmr] SSDP SsdpChange.ALIVE notification of device uuid:<device-uuid>::urn:schemas-upnp-org:device:MediaRenderer:1 at http://<device-ip>:1314/
2022-06-19 21:21:24 DEBUG (MainThread) [homeassistant.components.dlna_dmr] Connecting to device at http://<device-ip>:1314/
2022-06-19 21:21:24 DEBUG (MainThread) [homeassistant.components.dlna_dmr] Getting event handler for EventListenAddr(host='<ha-ip>', port=1337, callback_url=None)
2022-06-19 21:21:24 DEBUG (MainThread) [homeassistant.components.dlna_dmr] Started event handler at http://<ha-ip>:1337/notify

Just FYI, you can use the same event port for both devices, in which case the dlna_dmr component will re-use the same event handler for both.

addich commented 2 years ago

thanks for your quick feedback.

app_1   | 2022-06-20 10:07:57 DEBUG (MainThread) [homeassistant.components.dlna_dmr] SSDP SsdpChange.ALIVE notification of device uuid:09896800-00a0-1000-a058-4844f7589b67::urn:schemas-upnp-org:device:MediaRenderer:1 at http://192.168.32.134:7676/smp_14_
app_1   | 2022-06-20 10:07:57 DEBUG (MainThread) [homeassistant.components.dlna_dmr] Connecting to device at http://192.168.32.134:7676/smp_14_
app_1   | 2022-06-20 10:07:57 DEBUG (MainThread) [homeassistant.components.dlna_dmr] Getting event handler for EventListenAddr(host='192.168.32.2', port=36582, callback_url=None)
app_1   | 2022-06-20 10:07:57 DEBUG (MainThread) [homeassistant.components.dlna_dmr] Started event handler at http://192.168.32.2:36582/notify
$ sudo netstat -lnp|grep 36582
tcp        0      0 192.168.32.2:36582      0.0.0.0:*               LISTEN      1004054/python3

=> the listener works correct!!! Sorry. my bad, I was not clear how it works. Based on the debug entries I understood now that the listener get started when device is conniting. But still I get many firewall log entries related to the same client ip, but on UDP port.

$ sudo grep 192.168.32.134 /var/log/ufw.log| tail
Jun 20 10:13:49 raspberry kernel: [834177.037759] [UFW BLOCK] IN=eth0 OUT= MAC=dc:a6:32:a2:97:1b:30:14:4a:3d:2b:b7:08:00 SRC=192.168.32.134 DST=192.168.32.2 LEN=378 TOS=0x00 PREC=0x00 TTL=64 ID=0 DF PROTO=UDP SPT=56312 DPT=42272 LEN=358
Jun 20 10:13:49 raspberry kernel: [834177.038270] [UFW BLOCK] IN=eth0 OUT= MAC=dc:a6:32:a2:97:1b:30:14:4a:3d:2b:b7:08:00 SRC=192.168.32.134 DST=192.168.32.2 LEN=366 TOS=0x00 PREC=0x00 TTL=64 ID=0 DF PROTO=UDP SPT=57438 DPT=42272 LEN=346
Jun 20 10:13:49 raspberry kernel: [834177.039881] [UFW BLOCK] IN=eth0 OUT= MAC=dc:a6:32:a2:97:1b:30:14:4a:3d:2b:b7:08:00 SRC=192.168.32.134 DST=192.168.32.2 LEN=316 TOS=0x00 PREC=0x00 TTL=64 ID=0 DF PROTO=UDP SPT=41308 DPT=42272 LEN=296
Jun 20 10:13:49 raspberry kernel: [834177.048638] [UFW BLOCK] IN=eth0 OUT= MAC=dc:a6:32:a2:97:1b:30:14:4a:3d:2b:b7:08:00 SRC=192.168.32.134 DST=192.168.32.2 LEN=325 TOS=0x00 PREC=0x00 TTL=64 ID=0 DF PROTO=UDP SPT=35557 DPT=42272 LEN=305
Jun 20 10:15:49 raspberry kernel: [834297.034013] [UFW BLOCK] IN=eth0 OUT= MAC=dc:a6:32:a2:97:1b:30:14:4a:3d:2b:b7:08:00 SRC=192.168.32.134 DST=192.168.32.2 LEN=316 TOS=0x00 PREC=0x00 TTL=64 ID=0 DF PROTO=UDP 
$ sudo netstat -lnp|grep 42272
udp        0      0 192.168.32.2:42272      0.0.0.0:*                           1004054/python3

I thought this is the listener port, but I was wrong. This port change random after each restart of home assistant.

any idea what this is from? because i dont have any log entris to this port

StevenLooman commented 2 years ago

SSDP does use UDP for discovery (using multicast), but this should be port 1900. UPnP traffic is over TCP (HTTP and SOAP over HTTP.)

Googling udp port 42272 I see a mention of iTunes radio streams, though not very many pages mention this. Perhaps the easiest way to find out more is to use wireshark or tcpdump and see what the packets contain?

addich commented 2 years ago

Sorry it took a while until I had enogh knowlage. But i figured out that is related to SSDP. Seams SSDP use two addtional random upd ports aside of udp/1900. one for Ipv4 and one for ipv6. Many thanks for your help