Summary:ASTERISK-03029: [patch] SIP register problems on computers with dynamic IP addresses
Reporter:sailer (sailer)Labels:
Date Opened:2004-12-18 11:22:59.000-0600Date Closed:2008-01-15 15:25:50.000-0600
Versions:Frequency of
Environment:Attachments:( 0) asterisk-findouraddr.patch
( 1) asterisk-findouraddr.patch.txt
( 2) asterisk-findouraddr.patch.txt
( 3) asterisk-findouraddr.patch.txt
Description:I'm having problems registering to a SIP registry on a computer with dynamic (DHCP) IP addresses. Since the IP addresses are dynamic, I cannot use bindaddr= easily (i.e. w/o a post DHCP script that patches the config file). And the computer does not have a resolvable hostname (dhclient apparently does not update the hostname), the SIP channel fails when trying to resolve the hostname.

I'm currently using the attached patch. It does not fail when the hostname resolution fails, but tries to determine our IP address by resolving the IP address of the first SIP registry and then asking the kernel what IP address it will use to talk to that registry.

This patch admittedly is a workaround. IMO, the __ourip looks a bit fishy to me. As far as I can see it is mostly used as a fallback if ouraddrfor fails. Ouraddrfor shouldn't fail however, how are we going to communicate with a peer if we have no suitable own address to talk to it. And it is used to build the callid for register messages.


Disclaimer sent today.
Comments:By: Olle Johansson (oej) 2004-12-18 13:39:19.000-0600

Hmm. Ugly. Do you use dyn_dns?

edited on: 12-18-04 13:39

By: Olle Johansson (oej) 2004-12-18 13:45:15.000-0600

I would like a function to return false if it fails...

Is there a way not to use registrations? Seems like there has to be a better way. Maybe ast_ouraddrfor(our_router). This will also only help you at SIP load or reload.

We need to solve the dynamic IP address problem with a solution where
* you can set an expiry timer
* we can use a dyn_dns hostname as bindaddr and re-resolve that when we expire

I do not think assuming that we have an external SIP proxy is a solution that will work for everyone.

Any thoughts?

By: sailer (sailer) 2004-12-18 14:47:00.000-0600

No I don't use DDNS. And asterisk 1.0.3 is the first application that wants a resolvable hostname, even stable asteriskses <= 1.0.2 worked without (whether by accident I cannot tell).

Abt expiry timer: I think this is also a kludge, the real solution IMO is to not have a global __ourip variable. Because today even "simple" computers have different ip addresses: over the lo interface, some publicly routable internet IP, possibly some local VPN. Now which IP do you take as __ourip? The internet IP? But this IP might not be usable at the other end of the VPN tunnel.

So the solution IMO is to always use ouraddrfor, and to get rid of __ourip.

If you look at the __ourip uses:
1) fallback for ast_sip_ouraddrfor
2) transmit_register

1 is IMO silly, because if ouraddrfor fails, we can reasonably just bail out. We cannot communicate with a peer when we have no suitable ip address to talk to the peer!

2 should be possible to convert to ouraddrfor.

I can cook a patch if markster agrees that removing __ourip is a worthwile goal.

By: Olle Johansson (oej) 2004-12-18 14:52:58.000-0600

SIP kind of relies on resolvable host names and domains, so there is a reason the SIP channel wants host names.

By: sailer (sailer) 2004-12-18 15:02:36.000-0600

oej: why does sip require resolvable host names? please substantiate this unspecific blanket statement.

counterevidence: in current cvs asterisk, the hostname is only used for populating the __ourip variable, which is used in contexts it can easily be replaced (see my previous bugnote).

And it worked in stable asterisk <= 1.0.2

By: Mark Spencer (markster) 2005-01-05 20:57:55.000-0600

In CVS head we already allow "externhost=" and "externrefresh=", will that do it for you?

By: sailer (sailer) 2005-01-06 13:33:53.000-0600

The way I read the code, no. See chan_sip.c, lines 9126ff. If the host hame (ourhost, obtained in line 8931) lookup fails, and __ourip.s_addr is zero (which is the case during the first run of reload_config, then the sip channel still bails out, no matter whether externhost is set or not.

By: cherso (cherso) 2005-01-06 15:38:03.000-0600

related bugnote 3262
all the sip stack stop working when externhost is set and dns fails

in the latest CVS the ast_sip_ouraddrfor function should 1st try to test the localnet to handle the local sip calls, so at least the local sip calls can be made. Better performance and not so many dns query.
It should check the externhost and externrefresh just when it really needs. When the localnet test fails and we are on outgoing calls.
If the gethostbyname fails (temporary dns downtime) it should still use the latest externhost ip address resolved
If the gethostbyname fails (internet connction downtime) none to do... reporting unresolved externhost

edited on: 01-06-05 15:42

By: Mark Spencer (markster) 2005-01-12 23:43:58.000-0600

Now behaves this way in CVS head.

By: sailer (sailer) 2005-01-13 02:20:18.000-0600

While the externhost= thing may be fixed, asterisk still refuses to start SIP if the hostname is not resolvable.

The attached patch (disclaimer on file) tries harder to come up with a reasonable __ourip.

By: Mark Spencer (markster) 2005-01-13 09:01:58.000-0600

Okay, the attached patch shows promise, but this probably belongs in acl.c, not chan_sip.c, and if we're using the root DNS server, we should probably just stick with the root DNS server, period, right?  While I can appreciate the practical side of the first registration, I can also appreciate that finding out why adding a register => line makes outbound SIP activity change could be very challenging and non-intuitive for an asterisk user.

By: sailer (sailer) 2005-01-21 13:40:12.000-0600

Yes, you're right. My version is flawed because if the first sip register is to a nonpublic IP address (such as 10.x.x.x), then my version will pick the wrong IP address for __ourip.

By: Mark Spencer (markster) 2005-02-08 01:42:52.000-0600

So do you want to make an updated version or do you think this should be closed out?    How is this different from just calling ast_ouraddrfor() on a root DNS server?

By: sailer (sailer) 2005-02-08 16:34:58.000-0600

I've just attached the current version of my patch (against current CVS). And yes, it is basically just calling ast_ouraddrfor() on a root DNS server.

By: Mark Spencer (markster) 2005-02-08 21:22:26.000-0600

Added to CVS with minor modifications.  Thanks!

By: Russell Bryant (russell) 2005-02-20 22:42:56.000-0600

added to 1.0 as well, it will be in 1.0.6

By: Digium Subversion (svnbot) 2008-01-15 15:24:47.000-0600

Repository: asterisk
Revision: 4989

U   trunk/acl.c
U   trunk/channels/chan_sip.c
U   trunk/include/asterisk/acl.h

r4989 | markster | 2008-01-15 15:24:46 -0600 (Tue, 15 Jan 2008) | 2 lines

Handle DNS failures on startup more gracefully (bug ASTERISK-3029)



By: Digium Subversion (svnbot) 2008-01-15 15:25:50.000-0600

Repository: asterisk
Revision: 5061

U   branches/v1-0/acl.c
U   branches/v1-0/channels/chan_sip.c

r5061 | russell | 2008-01-15 15:25:50 -0600 (Tue, 15 Jan 2008) | 2 lines

handle DNS failures on startup more gracefully (bug ASTERISK-3029)