[Home]

Summary:ASTERISK-13833: [patch] Realtime - incorrect set peer ip-address and port after restart
Reporter:Alexei Gradinari (alexei gradinari)Labels:
Date Opened:2009-03-25 15:52:49Date Closed:2009-06-12 14:52:39
Priority:MinorRegression?No
Status:Closed/CompleteComponents:Channels/chan_sip/Registration
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:( 0) chan_sip_alexgrad.patch
( 1) chan_sip_fullcontact.patch
Description:After restarting asterisk sets peer ip-address and port based on fullcontact from database.
I think it's wrong because the SIP Contact may contain NAT inside ip-address.

For example
if the Contact is sip:TEST707@192.168.0.43
After restart asterisk and before SIP peer registers again
SIP peer ip-address and port are incorrect
asterisk -r -x 'sip show peer TEST707 load'
 Addr->IP     : 192.168.0.43 Port 5060
after SIP peer registers
 Addr->IP     : 64.231.137.147 Port 29277

The bug in the function 'sip_peer' in this code
================================================
       if (fullcontact->used > 0) {
               ast_copy_string(peer->fullcontact, fullcontact->str, sizeof(peer->fullcontact));
               peer->rt_fromcontact = TRUE;
               /* We have a hostname in the fullcontact, but if we don't have an
                * address listed on the entry (or if it's 'dynamic'), then we need to
                * parse the entry to obtain the IP address, so a dynamic host can be
                * contacted immediately after reload (as opposed to waiting for it to
                * register once again). */
               /* XXX May need to revisit the final argument; does the realtime DB store whether
                * the original contact was over TLS or not? XXX */
               __set_address_from_contact(fullcontact->str, &peer->addr, 0);
       }
================================================
The call of function __set_address_from_contact overwrite the peer ip-address and ports.

I think the code should be
================================================
       if (fullcontact->used > 0) {
               ast_copy_string(peer->fullcontact, fullcontact->str, sizeof(peer->fullcontact));
               peer->rt_fromcontact = TRUE;
               if (!(peer->addr.sin_addr..s_addr && peer->addr.sin_port)) {
                   /* We have a hostname in the fullcontact, but if we don't have an
                    * address listed on the entry (or if it's 'dynamic'), then we need to
                    * parse the entry to obtain the IP address, so a dynamic host can be
                    * contacted immediately after reload (as opposed to waiting for it to
                    * register once again). */
                   /* XXX May need to revisit the final argument; does the realtime DB store whether
                    * the original contact was over TLS or not? XXX */
                   __set_address_from_contact(fullcontact->str, &peer->addr, 0);
               }
       }
================================================
So we have to use 'fullcontact' only if peer ip-address or port aren't set.
Comments:By: Jon Creasy (johann8384) 2009-03-26 14:37:51

I believe I have this exact same issue. I am running an SVN revision of the 1.4 branch. I'll see if this change takes care of the issue.

One correction:
if (!(peer->addr.sin_addr..s_addr && peer->addr.sin_port)) {
Probably should be:
if (!(peer->addr.sin_addr.s_addr && peer->addr.sin_port)) {

By: Alexei Gradinari (alexei gradinari) 2009-03-26 15:58:03

johann8384,

You are right. It was my coping mistake.
In my case (version 1.6.0.6) my change fixes the issue.

By: snuffy (snuffy) 2009-03-28 03:42:37

If you want to make a patch.. please upload it as code, then we can use it.

By: Alexei Gradinari (alexei gradinari) 2009-03-29 14:55:45

I've attached patch chan_sip_fullcontact.patch

By: Jose Luis Painceira (josebaires) 2009-04-03 15:05:55

It happens also on 1.4.24

if for some reason you can't patch your asterisk, you can do something like

update sipusers set fullcontact=CONCAT(username,'@',ipaddr,':',port,';transport=udp')

in your database everytime after doing sip reload or a full reload.

By: Mark Michelson (mmichelson) 2009-06-12 14:43:52

I'm marking this for review since there is a patch here and it has been stated that the patch is working.

By: Mark Michelson (mmichelson) 2009-06-12 14:52:38

Actually, upon closer inspection, it appears that a similar fix has already been added to the 1.6.0 branch in revision 197704. This was committed to fix issue ASTERISK-14202. Since a fix for this issue already exists in the 1.6.0 branch, I am closing this issue.