<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 8.00.6001.18999">
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT size=2 face=Arial>Hello,</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial>We are using kamailio 1.5 and we have the following 
problem with ldap_search:</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial>A call comes in. If it is to a VOIP user, it will 
be routed to kamailio, and eventually go to the ldap lookup route: route[10] to 
look up the user.<BR>This is always successful (LDAP can connect).<BR>It will 
then look up user preferences (call forwarding etc.) from SQL in route[12] and 
route based on this result in route[13].<BR>If the result is "CFU (call forward 
unconditional) = on", the URI is changed and route[10] (LDAP lookup) is called 
again.<BR>This is always successful (LDAP can connect).<BR>If the result is "CFB 
(call forward busy) = on" and the user is busy, the URI is changed and route[10] 
(LDAP lookup) is called again.<BR>This is also always successful (LDAP can 
connect).<BR>If the result is "CFNR (call forward no reply) = on", the timeout 
is changed and the call is delivered to the phone through route[14] (location) 
and route[15] (relay).<BR>If the user does not answer, the URI is changed in 
failure_route[1] and route[10] is called.<BR>For some unknown reason, 
ldap_search always fails in this scenario with the messages: "ldap_session not 
found", "couldn't get ldap session" and then "no LDAP entry 
found".<BR>Why?<BR>And why does this result in the -1 return code and not the -2 
return code for ldap_search?</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial>The only differences I can think of is that the 
unsuccessful scenario comes from FAILURE_ROUTE instead of REQUEST_ROUTE, and 
that longer time has passed since the original invite.</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial>Here's a sample log:<BR>NOTE the three ERROR lines, 
the INFO line and the ROUTE 10 line.</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial>Dec 27 13:31:55 [3373]: INVITE received from 
sip:&lt;CALLER&gt;@&lt;SBC_IP&gt; &lt;source IP: &lt;SBC_IP&gt;&gt; to 
sip:&lt;CALLEE&gt;@&lt;KAM_IP&gt;:<BR>Dec 27 13:31:55 [3373]: 
ERROR:ldap:ldap_reconnect: [ldapprod]: LDAP reconnect successful<BR>Dec 27 
13:31:55 [3373]: ROUTE 10: LDAP returned: UID = &lt;UID&gt;, voipSipPrimaryUri = 
&lt;PRIMARY_URI&gt;, voipExtensionUri = sip:&lt;CALLEE&gt;@&lt;DOMAIN&gt;<BR>Dec 
27 13:31:55 [3373]: ROUTE 12: Effective user properties for UID &lt;UID&gt;: 
CFU: off &lt;FORWARDTO&gt;, CFB: off &lt;FORWARDTO&gt;, CFNR: on:25 
&lt;FORWARDTO&gt;, CFNC: off &lt;FORWARDTO&gt;, VM: &lt;CALLEE&gt;, busy_level: 
1, DBrows: 1<BR>Dec 27 13:31:55 [3373]:&nbsp;-------------------- Calling 
sip:&lt;CALLEE&gt;@&lt;DOMAIN&gt; for 25 seconds. --------------------<BR>Dec 27 
13:31:55 [3373]: ROUTE 15: Sending 105 INVITE from 
sip:&lt;CALLER&gt;@&lt;SBC_IP&gt; to sip:&lt;CALLEE&gt;@&lt;CALLEE_IP&gt; (via 
&lt;&lt;null&gt;&gt;)<BR>Dec 27 13:31:55 [3383]: Response 100 Trying to Cseq 102 
INVITE received from &lt;PROTO&gt;:&lt;CALLEE_IP&gt;:&lt;PORT&gt;<BR>Dec 27 
13:31:55 [3385]: Response 180 Ringing to Cseq 102 INVITE received from 
&lt;PROTO&gt;:&lt;CALLEE_IP&gt;:&lt;PORT&gt;</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial>Dec 27 13:32:20 [3388]: FAILURE_ROUTE 1: Timeout 
for: 104 INVITE from &lt;CALLER&gt; -&gt; &lt;CALLEE&gt;<BR>Dec 27 13:32:20 
[3388]: -------------------- Forwarding on no reply to &lt;FORWARDTO&gt; 
--------------------<BR>Dec 27 13:32:20 [3388]: 
ERROR:ldap:get_connected_ldap_session: [ldapprod]: ldap_session not found<BR>Dec 
27 13:32:20 [3388]: ERROR:ldap:lds_search: [ldapprod]: couldn't get ldap 
session<BR>Dec 27 13:32:20 [3388]: INFO:ldap:ldap_search_impl: no LDAP entry 
found<BR>Dec 27 13:32:20 [3388]: ROUTE 11: Number lookup results for 
&lt;FORWARDTO&gt;: Node: VOIP.<BR>Dec 27 13:32:20 [3388]: CONFIG ERROR: VOIP 
number not found in LDAP. Hanging up.<BR>Dec 27 13:32:20 [3373]: Response 487 
Request Cancelled to Cseq 102 INVITE received from 
&lt;PROTO&gt;:&lt;CALLEE_IP&gt;:&lt;PORT&gt;</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial>Here's the ldap config file:</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial>[ldapprod]<BR>ldap_server_url = "<A 
href="ldap://ldap.<DOMAIN">ldap://ldap.&lt;DOMAIN</A>&gt;"<BR>ldap_network_timeout 
= 500<BR>ldap_client_bind_timeout = 500</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial>kamailio config snippets (in case you need 
them):</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial># LDAP lookup for UID and primary URI<BR>route[10] 
{<BR>...<BR>&nbsp;&nbsp;ldap_search("<A 
href="ldap://ldapprod/<DN>?uid,voipSipPrimaryUri,voipExtensionUri?one?(&amp;(objectClass=voipAddress)(|(voipSipUri=sip:$rU@uio.no)(|(voipSipUri=$var(uri))(voipSipUri=$var(e164uri">ldap://ldapprod/&lt;DN&gt;?uid,voipSipPrimaryUri,voipExtensionUri?one?(&amp;(objectClass=voipAddress)(|(voipSipUri=sip:$rU@uio.no)(|(voipSipUri=$var(uri))(voipSipUri=$var(e164uri</A>)))))");<BR>&nbsp;&nbsp;if 
($retcode &lt; 1) {<BR>&nbsp;&nbsp;&nbsp;switch ($retcode) 
{<BR>&nbsp;&nbsp;&nbsp;case -1:<BR>&nbsp;&nbsp;&nbsp;&nbsp;# no LDAP entry 
found<BR>&nbsp;&nbsp;&nbsp;&nbsp;route(11);<BR>&nbsp;&nbsp;&nbsp;&nbsp;return(1);<BR>&nbsp;&nbsp;&nbsp;case 
-2:<BR>&nbsp;&nbsp;&nbsp;&nbsp;# internal 
error<BR>&nbsp;&nbsp;&nbsp;&nbsp;sl_send_reply("500", "Internal server 
error");<BR>&nbsp;&nbsp;&nbsp;&nbsp;exit;<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;ldap_result("uid/$avp(s:uid)");<BR>&nbsp;&nbsp;$avp(s:exten) 
= null;<BR>&nbsp;&nbsp;if (!ldap_result("voipExtensionUri/$avp(s:exten)")) 
{<BR>&nbsp;&nbsp;&nbsp;xlog("L_INFO", "voipExtensionUri not 
found.\n");<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;if 
(!ldap_result("voipSipPrimaryUri/$avp(s:p-uri)")) 
{<BR>&nbsp;&nbsp;&nbsp;xlog("L_WARN", "voipSipPrimaryUri not 
found.\n");<BR>&nbsp;&nbsp;&nbsp;#exit here?<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;if 
(isflagset(1)) {<BR>&nbsp;&nbsp;&nbsp;xlog("L_INFO", "ROUTE 10: LDAP returned: 
UID = $avp(s:uid), voipSipPrimaryUri = $avp(s:p-uri), voipExtensionUri = 
$avp(s:exten)\n");<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;if $avp(s:exten) != null 
{<BR>&nbsp;&nbsp;&nbsp;$ru=$avp(s:exten);<BR>&nbsp;&nbsp;} else 
{<BR>&nbsp;&nbsp;&nbsp;$ru=$avp(s:p-uri);<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;route(12);<BR>&nbsp;}<BR>}</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial># Number lookup. Non-VoIP URI's go 
here.<BR>route[11] {<BR>...<BR>}</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial># Database lookup for call forwarding.<BR>route[12] 
{<BR>...<BR>}</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial># Call forwarding logic<BR>route[13] {<BR>&nbsp;if 
(is_method("INVITE")) {<BR>&nbsp;&nbsp;$avp(s:uio_timer_avp) = 
"300";<BR>&nbsp;&nbsp;if ($avp(s:cfu_status) == "on") {<BR>&nbsp;&nbsp;&nbsp;# 
Forward immediately<BR>&nbsp;&nbsp;&nbsp;xlog("L_INFO", "-------------------- 
$rU forwarded unconditionally to $avp(s:cfu_number). 
--------------------\n");<BR>&nbsp;&nbsp;&nbsp;$rU = 
$avp(s:cfu_number);<BR>&nbsp;&nbsp;&nbsp;route(10);<BR>&nbsp;&nbsp;}<BR>...<BR>&nbsp;&nbsp;&nbsp;if 
( $var(dlg_busy) &gt;= $avp(s:busy_level) ) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;if 
($avp(s:cfb_status) == "on") {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xlog("L_INFO", 
"-------------------- $rU has $var(dlg_busy) active calls. Treshold 
$avp(s:busy_level). Forwarding on busy to $avp(s:cfb_number) 
--------------------\n");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$rU = 
$avp(s:cfb_number);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;route(10);<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>...<BR>&nbsp;&nbsp;&nbsp;else 
if ($avp(s:cfnr_status) == "on") {<BR>&nbsp;&nbsp;&nbsp;&nbsp;# Forward to phone 
with timeout then to $avp(s:cfnr_number).<BR>&nbsp;&nbsp;&nbsp;&nbsp;# 
t_set_fr($avp(s:cfnr_timeout) + "000"); # Recommended method in 3.1. Function 
does not exist in 1.5. Using old method 
(avp).<BR>&nbsp;&nbsp;&nbsp;&nbsp;$avp(s:uio_timer_avp) = 
$avp(s:cfnr_timeout);<BR>&nbsp;&nbsp;&nbsp;&nbsp;xlog("L_INFO", 
"-------------------- Calling $ru for $avp(s:uio_timer_avp) seconds. 
--------------------\n");<BR>&nbsp;&nbsp;&nbsp;&nbsp;route(14);<BR>&nbsp;&nbsp;&nbsp;}<BR>...<BR>}</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial>failure_route[1] {<BR>...<BR>&nbsp;&nbsp;if 
$avp(s:cfnr_status) == "on" {<BR>&nbsp;&nbsp;&nbsp;if (isflagset(1)) 
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;xlog("L_INFO", "FAILURE_ROUTE 1: Timeout for: $mi 
$rm from $fU -&gt; 
$rU\n");<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;revert_uri();<BR>&nbsp;&nbsp;&nbsp;$rU 
= $avp(s:cfnr_number);<BR>&nbsp;&nbsp;&nbsp;xlog("L_INFO", "-------------------- 
Forwarding on no reply to $rU 
--------------------\n");<BR>&nbsp;&nbsp;&nbsp;route(10);<BR>&nbsp;&nbsp;}<BR>...<BR>}</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial>With kind 
regards,<BR>Pan</FONT></DIV></BODY></HTML>