[Home]

Summary:ASTERISK-23767: [patch] Dynamic IAX2 registration stops trying if ever not able to resolve
Reporter:David Herselman (bbs2web)Labels:
Date Opened:2014-05-21 03:32:43Date Closed:2014-08-28 15:28:13
Priority:MajorRegression?No
Status:Closed/CompleteComponents:Channels/chan_iax2
Versions:11.9.0 Frequency of
Occurrence
Constant
Related
Issues:
is duplicated byASTERISK-23809 IAX2 registration fails after temporary dns failure
is related toASTERISK-23813 DNS Manager (dnsmgr) does not restore port
Environment:IAX2 registration to dynamic hostnameAttachments:( 0) asterisk-23767-dns_reg_retry_and_set_port_11_v3.diff
Description:Upgraded Asterisk from 10.7.1 to 11.9.0 on 55 hosts and are now experiencing an issue relating to IAX2 registrations, when the remote host is utilising a dynamic hostname.

Alpha and Omega register with each other using IAX2 trunks. Both sides are set as 'host=dynamic' and rely on registrations to ascertain the remote point's IP address. This has been extremely reliable prior to our upgrade to 11.9.0.


Problem: If DNS resolution is ever unavailable (Telco here kicks ADSL sessions off after 24 hours so that they reconnect) the registration gets set with a '(null)' host address and never retries the registration. Issuing a 'iax2 reload' doesn't help either, only completely unloading and reloading the chan_iax2 module works.

Alpha has the following iax registration:
{noformat}
register=Alpha:*******@sip.crffac.golden-era.co.za{noformat}


Alpha shows the host for the registration as being '(null)' although DNS resolution is currently operational (interruption was 6+ hours ago):
{noformat}
alpha*CLI> iax2 show registry
Host                  dnsmgr  Username    Perceived             Refresh  State
(null)                N       Alpha       <Unregistered>             60  Unregistered
1 IAX2 registrations.

alpha*CLI> iax2 show peers
Name/Username    Host                 Mask             Port          Status      Description
Omega/Alpha      165.145.109.36  (D)  255.255.255.255  4569 (T)      OK (27 ms)
1 iax2 peers [1 online, 0 offline, 0 unmonitored]
{noformat}

Omega correctly shows the Alpha peer as being unavailable, as it hasn't registered:
{noformat}
omega*CLI> iax2 show registry
Host                  dnsmgr  Username    Perceived             Refresh  State
196.15.196.130:4569   N       Omega       165.145.109.36:4569        60  Registered
1 IAX2 registrations.

omega*CLI> iax2 show peers
Name/Username    Host                 Mask             Port          Status      Description
Alpha/Omega      (null)          (D)  255.255.255.255  0    (T)      UNKNOWN
1 iax2 peers [0 online, 1 offline, 0 unmonitored]
{noformat}


Issuing a 'reload iax2' does absolutely nothing, only completely unloading the chan_iax2 module and reloading it restores operation:
{noformat}
alpha*CLI> module unload chan_iax2.so
Unloaded chan_iax2.so
alpha*CLI> module load chan_iax2.so
Loaded chan_iax2.so
alpha*CLI> iax2 show registry
Host                  dnsmgr  Username    Perceived             Refresh  State
165.145.109.36:4569   N       Alpha       196.15.196.130:4569        60  Registered
1 IAX2 registrations.

omega*CLI> iax2 show peers
Name/Username    Host                 Mask             Port          Status      Description
Alpha/Omega      196.15.196.130  (D)  255.255.255.255  4569 (T)      OK (27 ms)
1 iax2 peers [1 online, 0 offline, 0 unmonitored]
{noformat}
Comments:By: David Herselman (bbs2web) 2014-05-21 12:52:43.963-0500

Appears to be related to ASTERISK-19106:
https://issues.asterisk.org/jira/plugins/servlet/mobile#issue/ASTERISK-19106

The referenced bug appears to deal with the same issue when working with dynamic SIP registrations...

By: David Herselman (bbs2web) 2014-05-22 07:16:55.636-0500

One is supposed to be able to use 'dnsmgr' to work around Asterisk's inability to cope with DNS names which can't be resolved, but that has it's own issue of not restoring the port (setting the port as '0') once the name can be resolved again. This is another, separate, issue from the one reported here...

ie: This bug report deals with the issue that, should Asterisk ever not be able to resolve a DNS hostname for an IAX2 registration, it never tries again.

Real life scenario: System boots up and starts Asterisk prior to ADSL coming online. IAX registration is marked as 'null' and never tries to resolve the name again, even once internet connectivity is available.

By: Rusty Newton (rnewton) 2014-05-27 18:39:54.860-0500

Can you attach your iax.conf and dnsmgr.conf files (scrubbed of course).  I can't reproduce your described issue in the latest 11. 10 works fine as well, as you described.

I also noticed in your first set of command line output that dnsmgr is disabled for that iax2 peer, yet enabled in other output you show. Are you experiencing this issue with or without Asterisk's DNS manager enabled?

By: David Herselman (bbs2web) 2014-05-29 02:07:42.513-0500

We manage our Asterisk installations by installing and using the FreePBX GUI. FreePBX generates various iax configuration files which are pulled in by iax.conf so I've combined the switches and options in the exact order Asterisk's IAX module essentially sees them:

/etc/asterisk/iax.conf:
{noformat}
[general]
mailboxdetail=yes
tos=ef
disallow=all
allow=ulaw
allow=alaw
allow=gsm
calltokenoptional=10.0.0.0/255.0.0.0
calltokenoptional=172.16.0.0/255.240.0.0
calltokenoptional=192.168.0.0/255.255.0.0
register=Alpha:*******@sip.crffac.golden-era.co.za
allow=adpcm
allow=g729
allow=g723
allow=g722
allow=gsm
allow=slin
allow=speex
allow=lpc10
allow=ilbc
allow=g726aal2
allow=g726
allow=h261
allow=h263
allow=h263p
allow=h264
videosupport=yes
tcpenable=yes

[guest]
disallow=ulaw,alaw,adpcm
type=user
context=from-trunk

[Omega]
disallow=all
host=dynamic
username=Alpha
secret=************
requirecalltoken=yes
qualify=yes
allow=g729
trunk=yes
trunktimestamps=yes
jitterbuffer=yes
transfer=no
type=friend
context=from-internal
{noformat}

/etc/asterisk/dnsmgr.conf:
{noformat}
[general]
{noformat}


We are not using Asterisk's dnsmgr module, as it correclty switches the IP from 0.0.0.0 to whatever it should be but doesn't restore the port from 0 (when unavailable) to 4569 (when available). The dnsmgr issue is, as such, a separate issue from the one reported here.


To reproduce:
1. Create a DNS record with a short (eg 60 second) TTL (or simply reference sip.crffac.golden-era.co.za).
2. Don't bother configuring a trunk, the issue affects Asterisk's ability to perform a remote registration so simply add the following to /etc/asterisk/iax.conf (yes, use it 'as is' with the 'InvalidUser' and 'InvalidPassword'):
{noformat}
register=InvalidUser:InvalidPassword@sip.crffac.golden-era.co.za
{noformat}
3. Issue 'iax2 reload' to have Asterisk reload the configuration file and verify that Asterisk is attempting the registration with the 'iax2 show registry' command:
{noformat}
sip*CLI> iax2 show registry
Host                  dnsmgr  Username    Perceived             Refresh  State
165.145.108.250:4569  N       InvalidUse  <Unregistered>             60  Request Sent
1 IAX2 registrations.
{noformat}

4. Break your DNS resolution and wait about 2 minutes for the DNS record to expire and for Asterisk to retry the registration. Perhaps simply load a firewall rule to drop outgoing DNS requests:
{noformat}
iptables -I OUTPUT -p udp --dport 53 -j DROP
{noformat}

5. Review the Asterisk registration configuration:
{noformat}
sip*CLI> module unload chan_iax2
Unloaded chan_iax2
sip*CLI> module load chan_iax2
Loaded chan_iax2
[2014-05-29 08:59:42] ERROR[26485]: netsock2.c:269 ast_sockaddr_resolve: getaddrinfo("sip.crffac.golden-era.co.za", "(null)", ...): Temporary failure in name resolution
[2014-05-29 08:59:42] WARNING[26485]: acl.c:833 resolve_first: Unable to lookup 'sip.crffac.golden-era.co.za'
sip*CLI> iax2 show registry
Host                  dnsmgr  Username    Perceived             Refresh  State
(null)                N       InvalidUse  <Unregistered>             60  Unregistered
1 IAX2 registrations.
{noformat}

6. Restore DNS resolution:
{noformat}
[root@sip ~]# iptables -D OUTPUT -p udp --dport 53 -j DROP
[root@sip ~]# host sip.crffac.golden-era.co.za
sip.crffac.golden-era.co.za is an alias for dynamic2.crffac.golden-era.co.za.
dynamic2.crffac.golden-era.co.za has address 165.145.108.250
{noformat}

7. Asterisk never retries registration:
{noformat}
sip*CLI> iax2 show registry
Host                  dnsmgr  Username    Perceived             Refresh  State
(null)                N       InvalidUse  <Unregistered>             60  Unregistered
1 IAX2 registrations.
{noformat}


By: Michael L. Young (elguero) 2014-06-01 21:21:41.767-0500

Please give this patch a try and report back.

Thanks

By: David Herselman (bbs2web) 2014-06-03 01:22:02.219-0500

This works perfectly, many thanks!

Repeating the steps listed above:
5. Review the Asterisk registration configuration:
{noformat}
sip*CLI> module unload chan_iax2
Unloaded chan_iax2
sip*CLI> module load chan_iax2
Loaded chan_iax2
[2014-06-03 08:08:05] ERROR[21148]: netsock2.c:269 ast_sockaddr_resolve: getaddrinfo("sip.crffac.golden-era.co.za", "(null)", ...): Name or service not known
[2014-06-03 08:08:05] WARNING[21148]: acl.c:833 resolve_first: Unable to lookup 'sip.crffac.golden-era.co.za'
sip*CLI> iax2 show registry
Host                  dnsmgr  Username    Perceived             Refresh  State
(null)                N       InvalidUse  <Unregistered>             60  Unregistered
1 IAX2 registrations.
{noformat}

7. Asterisk now retries registrations every 60 seconds:
{noformat}
sip*CLI> iax2 show registry
Host                  dnsmgr  Username    Perceived             Refresh  State
165.145.108.145:4569  N       InvalidUse  <Unregistered>             60  Timeout
1 IAX2 registrations.
{noformat}


By: Michael L. Young (elguero) 2014-06-03 08:56:05.394-0500

Please give this updated patch a try in order to solve the port not being set when using DNS Manager.

Since the fix depends on the changes in the original patch, it is best to do this all together under one issue, one patch.

Thanks for your feedback.

By: David Herselman (bbs2web) 2014-06-03 10:15:15.185-0500

Excellent!

Herewith confirmation that:
 1. This patch still fixes the original case reported here (dnsmgr disabled)
 2. This patch also fixed the issue where dnsmgr was working but not restoring the port

The NOTICE logged by dnsmgr.c is still wrong though, but it works:
{noformat}
[2014-06-03 17:13:24] NOTICE[31007]: dnsmgr.c:215 dnsmgr_refresh: dnssrv: host 'sip.crffac.golden-era.co.za' changed from (null) to 165.145.108.145:0
sip*CLI> iax2 show registry
Host                  dnsmgr  Username    Perceived             Refresh  State
165.145.108.145:4569  Y       InvalidUse  <Unregistered>             60  Request Sent
1 IAX2 registrations.
{noformat}





By: Michael L. Young (elguero) 2014-06-03 11:01:19.772-0500

Actually, the message is correct.  DNS Manager is not setting the port and that is why chan_iax2 has to check if it was set by DNS Manger or not.  If it has not been set, then it will set the port according to the configuration line for this registration.  If the port was not specified in the settings for the registration line, then it will use the default IAX port (4569).

Thank you for thoroughly testing the patch.

By: David Herselman (bbs2web) 2014-07-01 17:08:24.504-0500

Do I still need to do anything further to mark this as solved and hopefully have your patch merged?

By: Michael L. Young (elguero) 2014-07-01 17:12:05.956-0500

David, there is nothing further to be done.  It is now waiting on me to submit the patch for review.  There was someone on IRC that was going to test this and provide feeback  as well but I think he hasn't been able to do so yet.

I was going to go ahead and submit this patch but just haven't been able to do so.  I will work on getting this submitted over the next couple of days.

Thanks for checking on this and giving me a reminder :)

By: David Herselman (bbs2web) 2014-07-21 03:44:54.347-0500

Bump... ;)

By: David Brillert (aragon) 2014-08-08 12:42:10.016-0500

Bump too... :)

By: Michael L. Young (elguero) 2014-08-08 12:50:26.819-0500

There is no need to add comments saying "bump".  If you look at the top, you will see the issue is in progress and it is going through the code review process.  If you would like to follow the review process, go to the review board link in the details section of the issue.

Thanks

By: David Brillert (aragon) 2014-08-28 09:31:30.825-0500

Joshua Colp
Posted 1 week, 3 days ago (Aug. 18, 2014, 9:25 a.m.)

Ship It!

Will this patch be submitted in time for 11.13 ?

By: Matt Jordan (mjordan) 2014-08-28 09:42:10.131-0500

We haven't cut release candidates yet, so yes :-)

By: Michael L. Young (elguero) 2014-08-28 14:59:20.634-0500

Yep, it will be.  Some of us don't have the pleasure of working full time on Asterisk... we choose to contribute our time when we can :)  I was, believe it or not, working on this yesterday so that I could commit it today.  I was distracted with updating the commit_msg.py template in the repotools.

Sorry for the delay on my part.

By: David Brillert (aragon) 2014-08-28 15:07:39.727-0500

Yes, I didn't want to come off obnoxious when I bumped, because I understand you are a contributor.  But I didn't want to have to wait for another official release either...
Thanks for the patch :) much appreciated.