[Asterisk-Dev] ENUM multiple records handling
Edwin Groothuis
edwin at mavetju.org
Thu Feb 10 08:10:57 MST 2005
Hello,
Just tried to play around with EnumLookup() and it seems it has a
funny behaviour when using multiple NAPTR records with different
preferences and priorities.
After some debugging, it seems always to return the first entry the
answer section of the DNS reply.
How do NAPTR records look like:
order preference flags service regexp replacement
The records should be processed in order sort, then on preference.
Right now if you do a NAPTR lookup for something which has more
than one NAPTR record (for example: 9.9.1.6.1.8.3.0.5.6.1.mavetju.org),
it will always use the first record. Debugging and TCP output has
confirmed this:
-----
15:35:43.801587 202.83.176.1.domain > 10.10.10.4.33429: 52325* 5/2/2 NAPTR , NAPTR , NAPTR , NAPTR , NAPTR (473)
0x0000 4500 01f5 ead1 0000 4011 ffc3 ca53 b001 E....... at ....S..
0x0010 0a0a 0a04 0035 8295 01e1 922a cc65 8580 .....5.....*.e..
0x0020 0001 0005 0002 0002 0139 0139 0131 0136 .........9.9.1.6
0x0030 0131 0138 0133 0130 0135 0136 0131 076d .1.8.3.0.5.6.1.m
0x0040 6176 6574 6a75 036f 7267 0000 2300 01c0 avetju.org..#...
0x0050 0c00 2300 0100 000e 1000 3200 0a00 6401 ..#.......2...d.
0x0060 7507 7465 6c2b 4532 5522 215e 5c2b 3136 u.tel+E2U"!^\+16
0x0070 3530 3338 3136 3139 3924 2174 656c 3a2b 503816199$!tel:+
0x0080 3631 3239 3532 3733 3532 3721 00c0 0c00 61295273527!....
Feb 10 15:35:43 NOTICE[7231]: app_enumlookup.c:123 enumlookup_exec: tel: ENUM set to "61295273527"
-- Executing NoOp("SIP/10.10.12.2-0815b2a0", "TEL") in new stack
-- Executing NoOp("SIP/10.10.12.2-0815b2a0", "61295273527") in new stack
-----
15:36:40.362791 202.83.176.1.domain > 10.10.10.4.33429: 31650* 5/2/2 NAPTR , NAPTR , NAPTR , NAPTR , NAPTR (473)
0x0000 4500 01f5 2b75 0000 4011 bf20 ca53 b001 E...+u.. at ....S..
0x0010 0a0a 0a04 0035 8295 01e1 7e52 7ba2 8580 .....5....~R{...
0x0020 0001 0005 0002 0002 0139 0139 0131 0136 .........9.9.1.6
0x0030 0131 0138 0133 0130 0135 0136 0131 076d .1.8.3.0.5.6.1.m
0x0040 6176 6574 6a75 036f 7267 0000 2300 01c0 avetju.org..#...
0x0050 0c00 2300 0100 000e 1000 3900 1e00 6401 ..#.......9...d.
0x0060 7507 7369 702b 4532 5529 215e 5c2b 3136 u.sip+E2U)!^\+16
0x0070 3530 3338 3136 3139 3924 2173 6970 3a65 503816199$!sip:e
0x0080 6477 696e 4062 6172 6e65 742e 636f 6d2e dwin at barnet.com.
0x0090 6175 2100 c00c 0023 0001 0000 0e10 0032 au!....#.......2
Feb 10 15:36:40 DEBUG[7270]: enum.c:120 parse_naptr: input='+16503816199', flags='u', services='sip+E2U', regexp='!^\+16503816199$!sip:edwin at barnet.com.au!', repl=''
-- Executing NoOp("SIP/10.10.12.2-0815b2a0", "SIP") in new stack
-- Executing NoOp("SIP/10.10.12.2-0815b2a0", "SIP/edwin at barnet.com.au") in new stack
-----
15:40:15.604325 202.83.176.1.domain > 10.10.10.4.33429: 51499* 5/2/2 NAPTR , NAPTR , NAPTR , NAPTR , NAPTR (473)
0x0000 4500 01f5 3857 0000 4011 b23e ca53 b001 E...8W.. at ..>.S..
0x0010 0a0a 0a04 0035 8295 01e1 52a7 c92b 8580 .....5....R..+..
0x0020 0001 0005 0002 0002 0139 0139 0131 0136 .........9.9.1.6
0x0030 0131 0138 0133 0130 0135 0136 0131 076d .1.8.3.0.5.6.1.m
0x0040 6176 6574 6a75 036f 7267 0000 2300 01c0 avetju.org..#...
0x0050 0c00 2300 0100 000e 1000 3f00 1900 6401 ..#.......?...d.
0x0060 7507 7369 702b 4532 552f 215e 5c2b 3136 u.sip+E2U/!^\+16
0x0070 3530 3338 3136 3139 3924 2173 6970 3a36 503816199$!sip:6
0x0080 3132 3933 3335 3330 3135 4062 6172 6e65 1293353015 at barne
0x0090 742e 636f 6d2e 6175 2100 c00c 0023 0001 t.com.au!....#..
Feb 10 15:40:15 DEBUG[7739]: enum.c:120 parse_naptr: input='+16503816199', flags='u', services='sip+E2U', regexp='!^\+16503816199$!sip:61293353015 at barnet.com.au!', repl=''
-- Executing NoOp("SIP/10.10.12.2-0815b2a0", "SIP") in new stack
-- Executing NoOp("SIP/10.10.12.2-0815b2a0", "SIP/61293353015 at barnet.com.au") in new stack
I have changed asterisk/enum.c a little bit and it now supports
multiple NAPTR records and takes the order and preference into
account. It works as follows: The first time EnumLookup() is called,
it loads all NAPTR records in a linked list and returns the first
entry (order and preference wise). Every next call to EnumLookup()
returns the next one (order and preference wise).
How long does this linked list exist? Each element in the list has
the PID of the thread which asked for the lookup first and it has
a timer and after 15 minutes they get cleaned up. Is 15 minutes a
lot? Yes/No. Yes because if you do a lot of lookups, it can grow a
bit. No because you have to take timeouts into account, so if you
have four phone numbers in it, you need a timeout of say 4x45 seconds
which already makes 3 minutes. I can probably set it to 5 minutes
or so, it just has to be determined later.
A test program would be: Do a lookup, echo the type, echo the ENUM
variable and jump back to the lookup until it fails.
exten => 700,1,NoOp(ENUM TEST)
exten => 700,n,EnumLookup(16503816199)
exten => 700,n,NoOp(SIP)
exten => 700,n,NoOp(${ENUM})
exten => 700,n,GoTo(2)
exten => 700,53,NoOp(TEL)
exten => 700,n,NoOp(${ENUM})
exten => 700,n,GoTo(2)
exten => 700,103,NoOp(FAIL)
exten => 700,n,Hangup()
This will print all NAPTR records for (16503816199).mavetju.org,
and in the right order:
-- Executing NoOp("SIP/128.177.195.13-08144708", "ENUM TEST") in new stack
-- Executing EnumLookup("SIP/128.177.195.13-08144708", "16503816199") in new stack
[...]
ENUM got '1'
Feb 11 02:03:06 NOTICE[29941]: app_enumlookup.c:124 enumlookup_exec: tel: ENUM set to "61295273527"
-- Executing NoOp("SIP/128.177.195.13-08144708", "TEL") in new stack
-- Executing NoOp("SIP/128.177.195.13-08144708", "61295273527") in new stack
-- Executing Goto("SIP/128.177.195.13-08144708", "2") in new stack
-- Goto (barnet-from-internet,700,2)
-- Executing EnumLookup("SIP/128.177.195.13-08144708", "16503816199") in new stack
ENUM got '1'
Feb 11 02:03:06 NOTICE[29941]: app_enumlookup.c:124 enumlookup_exec: tel: ENUM set to "61409227633"
-- Executing NoOp("SIP/128.177.195.13-08144708", "TEL") in new stack
-- Executing NoOp("SIP/128.177.195.13-08144708", "61409227633") in new stack
-- Executing Goto("SIP/128.177.195.13-08144708", "2") in new stack
-- Goto (barnet-from-internet,700,2)
-- Executing EnumLookup("SIP/128.177.195.13-08144708", "16503816199") in new stack
ENUM got '1'
Feb 11 02:03:06 NOTICE[29941]: app_enumlookup.c:83 enumlookup_exec: sip: ENUM set to "SIP/61293353015 at barnet.com.au"
-- Executing NoOp("SIP/128.177.195.13-08144708", "SIP") in new stack
-- Executing NoOp("SIP/128.177.195.13-08144708", "SIP/61293353015 at barnet.com.au") in new stack
-- Executing Goto("SIP/128.177.195.13-08144708", "2") in new stack
-- Goto (barnet-from-internet,700,2)
-- Executing EnumLookup("SIP/128.177.195.13-08144708", "16503816199") in new stack
ENUM got '1'
Feb 11 02:03:06 NOTICE[29941]: app_enumlookup.c:83 enumlookup_exec: sip: ENUM set to "SIP/edwin at barnet.com.au"
-- Executing NoOp("SIP/128.177.195.13-08144708", "SIP") in new stack
-- Executing NoOp("SIP/128.177.195.13-08144708", "SIP/edwin at barnet.com.au") in new stack
-- Executing Goto("SIP/128.177.195.13-08144708", "2") in new stack
-- Goto (barnet-from-internet,700,2)
-- Executing EnumLookup("SIP/128.177.195.13-08144708", "16503816199") in new stack
ENUM got '0'
-- Executing NoOp("SIP/128.177.195.13-08144708", "FAIL") in new stack
-- Executing Hangup("SIP/128.177.195.13-08144708", "") in new stack
(verbose 3 is happy spamming here :-)
I have made patches against the latest HEAD and the full new enum.c:
http://www.mavetju.org/~edwin/patch-enum.c
http://www.mavetju.org/~edwin/enum.c
If you are interested, please test and let me know if it works. I
will test it further on production machines and submit a patch to
the bugs database.
Edwin
--
Edwin Groothuis | Personal website: http://www.mavetju.org
edwin at mavetju.org | Weblog: http://weblog.barnet.com.au/edwin/
More information about the asterisk-dev
mailing list