home-assistant-libs / voip-utils

Apache License 2.0
1 stars 5 forks source link

SIP not working when running homeassistant without host networking #10

Open mattkasa opened 1 year ago

mattkasa commented 1 year ago
Logger: voip_utils.sip
Source: /usr/local/lib/python3.10/site-packages/voip_utils/sip.py:134
First occurred: 12:37:10 PM (3 occurrences)
Last logged: 1:54:58 PM

Unexpected error handling SIP INVITE
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/voip_utils/sip.py", line 123, in datagram_received
    self.on_call(
  File "/usr/local/lib/python3.10/site-packages/voip_utils/voip.py", line 53, in on_call
    sock.bind((call_info.server_ip, 0))
OSError: [Errno 99] Address not available

I think this is happening because the address (call_info.server_ip) is taken from the INVITE, which looks like this:

INVITE sip:192.168.1.10:5060 SIP/2.0

Without host networking, the homeassistant container has an IP like 172.26.0.20 and cannot bind to 192.168.1.10.

To fix this, maybe we could bind to INADDR_ANY instead of trusting the IP from the INVITE which will not be correct in a lot of networking scenarios?

Something like:

sock.bind(('', 0))

https://github.com/home-assistant-libs/voip-utils/blob/e9e58f3576de52376877f705e76e6d2529d339ec/voip_utils/voip.py#L53

mattkasa commented 1 year ago

I just tried binding to INADDR_ANY and it works and gets farther, the next issue seems to be binding to a random port for RTP. We would need to bind to a known range of ports in order to expose those to the network, similarly to how frigate/go2rtc/rtsptoweb support configuring ranges of ports.

synesthesiam commented 1 year ago

I've added the bind to INADDR_ANY and verified it works on my end. I'm not sure how to get the bind to work in a port range, though.

deggle commented 1 year ago

Hi, I'm having this same issue (posted on Discord and was pointed here).

I (kinda) understand the docker networking, but I'm confused as to why the container can't bind to 192.168.1.10 - in my case, I can ping the calling IP, and even TCP connect to it - so this just routes though docker out to the LAN (outbound ports don't need to be mapped like inbound).

I'm going to try to change the .py file as per above and see if that works.

deggle commented 1 year ago

So, I get a call connecting now, but no voice data coming though so I guess that's the port not getting though. I'm on 'host' networking mode so I thought it may work. I'm also seeing HA update the "Call in progress" flag but it never clears.