[Home]

Summary:ASTERISK-19720: Using SIP realtime with caching incoming calls are routed to dialplan context specified in sip.conf general context and not the context specified in SIP peer context until peer is refreshed from database
Reporter:Serge Wagener (foxi352)Labels:
Date Opened:2012-04-13 09:33:33Date Closed:
Priority:MajorRegression?
Status:Open/NewComponents:Channels/chan_sip/General PBX/pbx_realtime
Versions:1.8.11.0 13.18.4 Frequency of
Occurrence
Constant
Related
Issues:
Environment:Ubuntu Lucid 10.04, Asterisk 1.8.11.0-1digium1~lucid built by pbuilder @ nighthawk on a x86_64 running Linux on 2012-04-03 14:12:25 UTCAttachments:
Description:I work for an OSS project which relies on asterisk for telecom. My task was to port asterisk config from flat files to realtime db. Everything works great except the following:

I have a "from-sip-external" context set up in general section of sip.conf for unknown incoming sip calls.
Then i have a "from-trunk" context associated to the SIP peer's in sip_devices table for incoming calls on these defined sip trunks.
Caching is enabled, just as info.

After a core reload, or fresh asterisk service start, the SIP peer table is obviously empty. Incoming calls on any DID get then redirected to the "from-sip-external" context set in general of sip.conf instead of the context set in the peer table.

After doing one outgoing call on the same line i can see the line in the SIP peer cache, which is normal since i enabled caching. As long as the peer is in the cache table incoming calls work like a charm, and callers get directed to the right context set in peer definition in sip_devices table.

So as long as i do not restart asterisk or reload core it will be fine forever ....

Experts in #asterisk think this might be a bug. See a call example here, my comments in CAPS to easely identify:

PEER DUMP JUST AFTER ASTERISK RELOAD:

dcerouter*CLI> sip show peers
Name/username              Host                                    Dyn Forcerport ACL Port     Status     Realtime
313/313                    192.168.80.177                           D   N             5060     Unmonitored Cached RT
1 sip peers [Monitored: 0 online, 0 offline Unmonitored: 1 online, 0 offline]


THIS DUMP SHOWS ONE OF THE PHONES THAT JUST REGISTERED AFTER MY CORE RELOAD

INCOMING CALL USING WRONG CONTEXT:

 == Using SIP RTP CoS mark 5
   -- Executing [498621@from-sip-external:1] NoOp("SIP/85.93.219.122-00000084", "Received incoming SIP connection from unknown peer to 498621") in new stack
   -- Executing [498621@from-sip-external:2] Set("SIP/85.93.219.122-00000084", "DID=498621") in new stack
   -- Executing [498621@from-sip-external:3] Goto("SIP/85.93.219.122-00000084", "s,1") in new stack
   -- Goto (from-sip-external,s,1)
   -- Executing [s@from-sip-external:1] GotoIf("SIP/85.93.219.122-00000084", "0?from-trunk,498621,1") in new stack
   -- Executing [s@from-sip-external:2] Set("SIP/85.93.219.122-00000084", "TIMEOUT(absolute)=15") in new stack
Channel will hangup at 2012-04-13 14:33:51.265 CEST.
   -- Executing [s@from-sip-external:3] Answer("SIP/85.93.219.122-00000084", "") in new stack
   -- Executing [s@from-sip-external:4] Wait("SIP/85.93.219.122-00000084", "2") in new stack
   -- Executing [s@from-sip-external:5] Playback("SIP/85.93.219.122-00000084", "ss-noservice") in new stack
   -- <SIP/85.93.219.122-00000084> Playing 'ss-noservice.gsm' (language 'en')
 == Spawn extension (from-sip-external, s, 5) exited non-zero on 'SIP/85.93.219.122-00000084'
   -- Executing [h@from-sip-external:1] NoOp("SIP/85.93.219.122-00000084", "Hangup") in new stack
dcerouter*CLI> 498621


SIP SHOW PEERS IS STILL THE SAME AFTER THIS INCOMING CALL.
SO I MAKE AN OUTGOING CALL USING THIS PHONELINE, AND THEN A NEW SIP SHOW PEERS:

dcerouter*CLI> sip show peers
Name/username              Host                                    Dyn Forcerport ACL Port     Status     Realtime
313/313                    192.168.80.177                           D   N             5060     Unmonitored Cached RT
498621/498621              85.93.219.114                                N             5060     UNKNOWN    Cached RT
2 sip peers [Monitored: 0 online, 1 offline Unmonitored: 1 online, 0 offline]


THE PHONELINE IS NOW IN PEER CACHE AND INCOMING CALLS WORK, THIS TIME IS USES RIGHT CONTEXT:

 == Using SIP RTP CoS mark 5
   -- Executing [498621@from-trunk:1] Set("SIP/498621-00000087", "__FROM_DID=498621")
   -- Executing [498621@from-trunk:2] Set("SIP/498621-00000087", "CALLERID(num)=691543912")
   -- Executing [498621@from-trunk:3] Noop("SIP/498621-00000087", "Incoming call from 691543912")
   -- Executing [498621@from-trunk:4] Set("SIP/498621-00000087", "FAX_RX=")
   -- Executing [498621@from-trunk:5] Goto("SIP/498621-00000087", "custom-linuxmce,106,1")
   -- Goto (custom-linuxmce,106,1)
   -- Executing [106@custom-linuxmce:1] AGI("SIP/498621-00000087", "lmce-phonebook-lookup.agi")
   -- Launched AGI Script /usr/share/asterisk/agi-bin/lmce-phonebook-lookup.agi
   -- AGI Script Executing Application: (NoOp) Options: (Checking if name exists for 691543912 in phone book and attempting to add caller name)
   -- AGI Script Executing Application: (NoOp) Options: (Number found in phone book, PK_CONTACT is 2)
   -- AGI Script Executing Application: (NoOp) Options: (Name for 691543912 is Serge Wagener)
   -- AGI Script Executing Application: (Set) Options: (CALLERID(name)=Serge Wagener)
   -- <SIP/498621-00000087>AGI Script lmce-phonebook-lookup.agi completed, returning 0

[... cut here ...]


SIP_DEVICES TABLE DUMP

--
-- Table structure for table `sip_devices`
--

CREATE TABLE IF NOT EXISTS `sip_devices` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `name` varchar(80) NOT NULL DEFAULT '',
 `context` varchar(80) DEFAULT NULL,
 `callingpres` enum('allowed_not_screened','allowed_passed_screen','allowed_failed_screen','allowed','prohib_not_screened','prohib_passed_screen','prohib_failed_screen','prohib','unavailable') DEFAULT 'allowed_not_screened',
 `deny` varchar(95) DEFAULT NULL,
 `permit` varchar(95) DEFAULT NULL,
 `secret` varchar(80) DEFAULT NULL,
 `md5secret` varchar(80) DEFAULT NULL,
 `remotesecret` varchar(250) DEFAULT NULL,
 `transport` enum('tcp','udp','udp,tcp') DEFAULT 'udp,tcp',
 `host` varchar(31) NOT NULL DEFAULT 'dynamic',
 `nat` varchar(5) NOT NULL DEFAULT 'yes',
 `type` enum('user','peer','friend') NOT NULL DEFAULT 'friend',
 `accountcode` varchar(20) DEFAULT NULL,
 `amaflags` varchar(13) DEFAULT NULL,
 `callgroup` varchar(10) DEFAULT NULL,
 `callerid` varchar(80) DEFAULT NULL,
 `defaultip` varchar(15) DEFAULT NULL,
 `dtmfmode` varchar(7) DEFAULT 'auto',
 `fromuser` varchar(80) DEFAULT NULL,
 `fromdomain` varchar(80) DEFAULT NULL,
 `insecure` varchar(20) DEFAULT NULL,
 `language` char(2) DEFAULT NULL,
 `mailbox` varchar(50) DEFAULT NULL,
 `pickupgroup` varchar(10) DEFAULT NULL,
 `qualify` char(3) DEFAULT 'no',
 `regexten` varchar(80) DEFAULT NULL,
 `rtptimeout` char(3) DEFAULT NULL,
 `rtpholdtimeout` char(3) DEFAULT NULL,
 `setvar` varchar(100) DEFAULT NULL,
 `disallow` varchar(100) DEFAULT 'all',
 `allow` varchar(100) DEFAULT 'alaw;ulaw',
 `fullcontact` varchar(80) NOT NULL DEFAULT '',
 `ipaddr` varchar(45) NOT NULL,
 `port` mediumint(5) unsigned NOT NULL DEFAULT '0',
 `defaultuser` varchar(80) NOT NULL DEFAULT '',
 `subscribecontext` varchar(80) DEFAULT NULL,
 `directmedia` enum('yes','no') DEFAULT 'no',
 `trustrpid` enum('yes','no') DEFAULT NULL,
 `sendrpid` enum('yes','no') DEFAULT NULL,
 `progressinband` enum('never','yes','no') DEFAULT NULL,
 `promiscredir` enum('yes','no') DEFAULT NULL,
 `useclientcode` enum('yes','no') DEFAULT NULL,
 `callcounter` enum('yes','no') DEFAULT NULL,
 `busylevel` int(10) unsigned DEFAULT NULL,
 `allowoverlap` enum('yes','no') DEFAULT 'yes',
 `allowsubscribe` enum('yes','no') DEFAULT 'yes',
 `allowtransfer` enum('yes','no') DEFAULT 'yes',
 `ignoresdpversion` enum('yes','no') DEFAULT 'no',
 `template` varchar(100) DEFAULT NULL,
 `videosupport` enum('yes','no','always') DEFAULT 'no',
 `maxcallbitrate` int(10) unsigned DEFAULT NULL,
 `rfc2833compensate` enum('yes','no') DEFAULT 'yes',
 `session-timers` enum('originate','accept','refuse') DEFAULT 'accept',
 `session-expires` int(5) unsigned DEFAULT '1800',
 `session-minse` int(5) unsigned DEFAULT '90',
 `session-refresher` enum('uac','uas') DEFAULT 'uas',
 `t38pt_usertpsource` enum('yes','no') DEFAULT NULL,
 `outboundproxy` varchar(250) DEFAULT NULL,
 `callbackextension` varchar(250) DEFAULT NULL,
 `registertrying` enum('yes','no') DEFAULT 'yes',
 `timert1` int(5) unsigned DEFAULT '500',
 `timerb` int(8) unsigned DEFAULT NULL,
 `qualifyfreq` int(5) unsigned DEFAULT '120',
 `contactpermit` varchar(250) DEFAULT NULL,
 `contactdeny` varchar(250) DEFAULT NULL,
 `lastms` int(11) NOT NULL,
 `regserver` varchar(100) NOT NULL DEFAULT '',
 `regseconds` int(11) NOT NULL DEFAULT '0',
 `useragent` varchar(50) NOT NULL DEFAULT '',
 PRIMARY KEY (`id`),
 UNIQUE KEY `name` (`name`,`fromuser`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=12 ;

--
-- Dumping data for table `sip_devices`
--

INSERT INTO `sip_devices` (`id`, `name`, `context`, `callingpres`, `deny`, `permit`, `secret`, `md5secret`, `remotesecret`, `transport`, `host`, `nat`, `type`, `accountcode`, `amaflags`, `callgroup`, `callerid`, `defaultip`, `dtmfmode`, `fromuser`, `fromdomain`, `insecure`, `language`, `mailbox`, `pickupgroup`, `qualify`, `regexten`, `rtptimeout`, `rtpholdtimeout`, `setvar`, `disallow`, `allow`, `fullcontact`, `ipaddr`, `port`, `defaultuser`, `subscribecontext`, `directmedia`, `trustrpid`, `sendrpid`, `progressinband`, `promiscredir`, `useclientcode`, `callcounter`, `busylevel`, `allowoverlap`, `allowsubscribe`, `allowtransfer`, `ignoresdpversion`, `template`, `videosupport`, `maxcallbitrate`, `rfc2833compensate`, `session-timers`, `session-expires`, `session-minse`, `session-refresher`, `t38pt_usertpsource`, `outboundproxy`, `callbackextension`, `registertrying`, `timert1`, `timerb`, `qualifyfreq`, `contactpermit`, `contactdeny`, `lastms`, `regserver`, `regseconds`, `useragent`) VALUES
(1, '200', 'from-internal', 'allowed_not_screened', NULL, NULL, 'toto', NULL, NULL, 'udp,tcp', 'dynamic', 'yes', 'friend', NULL, NULL, NULL, 'device <200>', NULL, 'auto', NULL, NULL, NULL, NULL, '200@device', NULL, 'no', NULL, NULL, NULL, NULL, 'all', 'alaw;ulaw', '', '', 5061, '200', NULL, 'no', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'yes', 'yes', 'yes', 'no', NULL, 'no', NULL, 'yes', 'accept', 1800, 90, 'uas', NULL, NULL, NULL, 'yes', 500, NULL, 120, NULL, NULL, 0, '', 0, ''),
(6, '313', 'from-internal', 'allowed_not_screened', NULL, NULL, 'toto', NULL, NULL, 'udp,tcp', 'dynamic', 'yes', 'friend', NULL, NULL, NULL, 'device <313>', NULL, 'auto', NULL, NULL, NULL, NULL, '313@device', NULL, 'no', NULL, NULL, NULL, NULL, 'all', 'alaw;ulaw', 'sip:313@192.168.80.177:5060', '192.168.80.177', 5060, '313', NULL, 'no', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'yes', 'yes', 'yes', 'no', NULL, 'no', NULL, 'yes', 'accept', 1800, 90, 'uas', NULL, NULL, NULL, 'yes', 500, NULL, 120, NULL, NULL, 0, '', 1334321186, 'C610 IP/42.051.01.000.000'),
(11, '498621', 'from-trunk', 'allowed_not_screened', NULL, NULL, 'toto', NULL, NULL, 'udp,tcp', 'tel.lu', 'yes', 'peer', NULL, NULL, NULL, '498621', NULL, 'auto', '498621', 'tel.lu', 'port,invite', NULL, NULL, NULL, 'yes', NULL, NULL, NULL, NULL, 'all', 'alaw;ulaw', '', '', 5060, '498621', NULL, 'no', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'yes', 'yes', 'yes', 'no', NULL, 'no', NULL, 'yes', 'accept', 1800, 90, 'uas', NULL, NULL, NULL, 'yes', 500, NULL, 120, NULL, NULL, 0, '', 0, '');
Comments:By: Ben Ronsse (brononius) 2012-11-20 04:40:21.558-0600

Is there a workaround for this issue?
I'm having the same sympton on my LinuxMCE installation...

By: Ben Ronsse (brononius) 2012-11-21 05:23:27.310-0600

A temp workaoround is a small script that dials out each day... :$

check out: http://forum.linuxmce.org/index.php/topic,12950.0.html


By: Walter Doekes (wdoekes) 2012-11-24 18:29:31.494-0600

I think you're experiencing the problem that peer matching (by IP:port) is not done for realtime peers (until they are cached).

Matching by hostname (tel.lu) in the peer table is not done.

You could either replace the hostname with an IP or switch to user-matching (by From: or digest user).

(I know that the former solution might not be satisfactory and the second one might not work (if there is no distuinguishable username), but doing full DNS record lookups on the peer table at INVITE time is not the right solution either.)

By: Serge Wagener (foxi352) 2013-04-08 11:26:53.152-0500

If that is really the problem then the solution should be simple ?

Why a DNS lookup on each INVITE ? It should be enough to do add the trunks to the peer caching table during registering, as anyway the DNS lookup is done then ?

It would be a pitty, but after a year without any reaction to this bug i feel we must find another solution in our project. Maybe convert trunks back to flatfile :-(