All,
The Kamailio-Asterisk integration that is described here
asterisk:realtime:kamailio-4.0.x-asterisk-11.3.0-astdb [Asipto - SIP and VoIP 
Knowledge Base Site]
is limited to Asterisk servers with a fixed IP address. The reason is that 
Kamailio identifies and authorizes traffic from Asterisk based on the source IP 
address. Attached is a patch to kamailio.cfg that adds support for dynamic 
Asterisk hosts. It introduces the option to define a fully-qualified domain 
name instead of the IP address to identify the Asterisk server. The host name 
can be dynamically updated to always point at the (changing) IP address of the 
Asterisk server. Defining WITH_ASTERISK_FQDN enables the new option.
When WITH_ASTERISK_FQDN is set, Kamailio will perform a DNS search on the host 
name in the asterisk.bindhost variable. It will authorize incoming traffic if 
it originates from one of the IP addresses the DNS lookup returns (and matches 
the asterisk.bindport variable as before).
Furthermore, the patch introduce the option to automatically set the IP address 
of the server that Kamailio is running on. This does away with the need to 
properly define kamailio.bindip on every server that the configuration is 
running on. This option is enabled by defining WITH_AUTOIP.
With the suggested changes I have been able to successfully run an Asterisk 
server in my home, having a dynamic public IP address and connecting to the 
Kamailio proxy on a VPS server with a static IP addres.
Please let me know if you have any comments or suggestions.
Kind regards,Rudy Eschauzier.


|   |
|   |  |   |   |   |   |   |
| asterisk:realtime:kamailio-4.0.x-asterisk-11.3.0-astdb [...Table of Contents 
Kamailio 4.0.x and Asterisk 11.3.0 Realtime Integration using Asterisk Database 
Architecture Registration Call Initiation Requirements MySQL Insta... |
|  |
| View on kb.asipto.com | Preview by Yahoo |
|  |
|   |


--- kamailio.cfg-AST-ORG	2015-07-25 11:56:38.517743705 +0200
+++ kamailio.cfg	2015-08-16 18:11:31.709043036 +0200
@@ -1,9 +1,14 @@
 #!KAMAILIO
  
 # #!define WITH_MYSQL
-# #!define WITH_AUTH
+#!define WITH_AUTH
 # #!define WITH_USRLOCDB
-# #!define WITH_ASTERISK
+#!define WITH_ASTERISK
+#!define WITH_ASTERISK_FQDN
+#!define WITH_AUTOIP
+# #!define WITH_DEBUG
+#!define WITH_NAT
+#!define WITH_TEXTDB
  
 #
 # Kamailio (OpenSER) SIP Server v4.0 - default configuration script
@@ -23,6 +28,9 @@
 # *** To enable mysql: 
 #     - define WITH_MYSQL
 #
+# *** To use text database backend:
+#     - define WITH_TEXTDB
+#
 # *** To enable authentication execute:
 #     - enable mysql
 #     - define WITH_AUTH
@@ -47,6 +55,7 @@
 #     - install RTPProxy: http://www.rtpproxy.org
 #     - start RTPProxy:
 #        rtpproxy -l _your_public_ip_ -s udp:localhost:7722
+#     - option for NAT SIP OPTIONS keepalives: WITH_NATSIPPING
 #
 # *** To enable PSTN gateway routing execute:
 #     - define WITH_PSTN
@@ -86,6 +95,14 @@
 #     - set the value of voicemail.srv_ip
 #     - adjust the value of voicemail.srv_port
 #
+# *** To enable Asterisk hostname lookup execute (for dynamic IPs):
+#     - define WITH_ASTERISK_FQDN
+#     - set the value of asterisk.bindhost
+#
+# *** To enable automatically looking up Kamailio server IP:
+#     - define WITH_AUTOIP
+#     - set the value of kamailio.bindport
+#
 # *** To enhance accounting execute:
 #     - enable mysql
 #     - define WITH_ACCDB
@@ -116,6 +133,12 @@
 #!define DBASTURL "mysql://asterisk:asterisk_password@localhost/asterisk"
 #!endif
 #!endif
+#!ifdef WITH_TEXTDB
+#!define DBURL "text:///etc/kamailio/dbtext"
+#!ifdef WITH_ASTERISK
+#!define DBASTURL "text:///etc/kamailio/dbtext"
+#!endif
+#!endif
 #!ifdef WITH_MULTIDOMAIN
 # - the value for 'use_domain' parameters
 #!define MULTIDOMAIN 1
@@ -135,7 +158,7 @@
 #!define FLB_NATSIPPING 7
  
 ####### Global Parameters #########
- 
+
 #!ifdef WITH_DEBUG
 debug=4
 log_stderror=yes
@@ -143,7 +166,7 @@
 debug=2
 log_stderror=no
 #!endif
- 
+
 memdbg=5
 memlog=5
  
@@ -205,26 +228,35 @@
 voicemail.srv_port = "5060" desc "VoiceMail Port"
 #!endif
  
- 
 #!ifdef WITH_ASTERISK
-asterisk.bindip = "192.168.178.25" desc "Asterisk IP Address"
-asterisk.bindport = "5080" desc "Asterisk Port"
-kamailio.bindip = "192.168.178.25" desc "Kamailio IP Address"
+asterisk.bindip = "XX.XX.XX.XX" desc "Asterisk IP Address"
+# asterisk.bindport = "5080" desc "Asterisk Port"
+asterisk.bindport = "5060" desc "Asterisk Port"
+kamailio.bindip = "XX.XX.XX.XX" desc "Kamailio IP Address"
 kamailio.bindport = "5060" desc "Kamailio Port"
 #!endif
- 
+
+#!ifdef WITH_ASTERISK_FQDN
+asterisk.bindhost = "ddns.example.com" desc "Asterisk Host Name"
+#!endif
+
 ####### Modules Section ########
  
 # set paths to location of modules (to sources or installation folders)
 #!ifdef WITH_SRCPATH
 mpath="modules_k:modules"
 #!else
-mpath="/usr/local/lib/kamailio/modules_k/:/usr/local/lib/kamailio/modules/"
+mpath="usr/lib64/kamailio/modules/:/usr/local/lib/kamailio/modules_k/:/usr/local/lib/kamailio/modules/"
 #!endif
  
 #!ifdef WITH_MYSQL
 loadmodule "db_mysql.so"
 #!endif
+
+#!ifdef WITH_TEXTDB
+loadmodule "db_text.so"
+#modparam("db_text", "db_mode", 1)
+#!endif
  
 loadmodule "mi_fifo.so"
 loadmodule "kex.so"
@@ -291,10 +323,14 @@
 #!ifdef WITH_DEBUG
 loadmodule "debugger.so"
 #!endif
- 
+
 #!ifdef WITH_ASTERISK
 loadmodule "uac.so"
+loadmodule "ipops.so"
 #!endif
+
+modparam("ctl", "user", "kamailio")
+modparam("ctl", "group", "kamailio")
  
 # ----------------- setting module-specific parameters ---------------
  
@@ -543,7 +579,6 @@
  
  
 route[RELAY] {
- 
 	# enable additional event routes for forwarded requests
 	# - serial forking, RTP relaying handling, a.s.o.
 	if (is_method("INVITE|SUBSCRIBE")) {
@@ -641,12 +676,14 @@
 		if(isflagset(FLT_NATS))
 		{
 			setbflag(FLB_NATB);
-			# uncomment next line to do SIP NAT pinging 
-			## setbflag(FLB_NATSIPPING);
+#!ifdef WITH_NATSIPPING
+                        # do SIP NAT pinging
+                        setbflag(FLB_NATSIPPING);
+#!endif
 		}
 		if (!save("location"))
 			sl_reply_error();
- 
+
 #!ifdef WITH_ASTERISK
 		route(REGFWD);
 #!endif
@@ -953,16 +990,49 @@
 #!ifdef WITH_ASTERISK
 # Test if coming from Asterisk
 route[FROMASTERISK] {
+#!ifdef WITH_ASTERISK_FQDN
+ if ($sp!=$sel(cfg_get.asterisk.bindport))
+  return -1;
+
+ if(dns_query($sel(cfg_get.asterisk.bindhost), "dns"))
+  {
+   xdbg(" number of addresses: $dns(dns=>count)\n");
+   $var(r) = 0;
+   $var(i) = 0;
+   while($var(i)<$dns(dns=>count) && !$var(r))
+   {
+    xdbg(" #[$var(i)] type ($dns(dns=>type[$var(i)]))"
+         " addr [$dns(dns=>addr[$var(i)])]\n");
+    $var(r)=$si==$dns(dns=>addr[$var(i)]);
+    $var(i) = $var(i) + 1;
+   }
+   xdbg("Result: $var(r)");
+   if ($var(r))
+    return 1;
+   return -1;
+  }
+ else
+  {
+   xlog("L_ERROR","Host lookup $sel(cfg_get.asterisk.bindhost) failed");
+   return -1;
+  }
+#!else
 	if($si==$sel(cfg_get.asterisk.bindip)
 			&& $sp==$sel(cfg_get.asterisk.bindport))
 		return 1;
 	return -1;
+#!endif
 }
  
 # Send to Asterisk
 route[TOASTERISK] {
+#!ifdef WITH_ASTERISK_FQDN
+        $du = "sip:" + $sel(cfg_get.asterisk.bindhost) + ":"
+                        + $sel(cfg_get.asterisk.bindport);
+#!else
 	$du = "sip:" + $sel(cfg_get.asterisk.bindip) + ":"
 			+ $sel(cfg_get.asterisk.bindport);
+#!endif
 	route(RELAY);
 	exit;
 }
@@ -973,14 +1043,25 @@
 	{
 		return;
 	}
+#!ifdef WITH_ASTERISK_FQDN
+        $var(rip) = $sel(cfg_get.asterisk.bindhost);
+#!else
 	$var(rip) = $sel(cfg_get.asterisk.bindip);
+#!endif
 	$uac_req(method)="REGISTER";
 	$uac_req(ruri)="sip:" + $var(rip) + ":" + $sel(cfg_get.asterisk.bindport);
 	$uac_req(furi)="sip:" + $au + "@" + $var(rip);
 	$uac_req(turi)="sip:" + $au + "@" + $var(rip);
-	$uac_req(hdrs)="Contact: <sip:" + $au + "@"
+#!ifdef WITH_AUTOIP
+        xdbg("IP address of server: $HN(i)");
+        $uac_req(hdrs)="Contact: <sip:" + $au + "@"
+                                + $HN(i)
+                                + ":" + $sel(cfg_get.kamailio.bindport) + ">\r\n";
+#!else
+        $uac_req(hdrs)="Contact: <sip:" + $au + "@"
 				+ $sel(cfg_get.kamailio.bindip)
 				+ ":" + $sel(cfg_get.kamailio.bindport) + ">\r\n";
+#!endif
 	if($sel(contact.expires) != $null)
 		$uac_req(hdrs)= $uac_req(hdrs) + "Expires: " + $sel(contact.expires) + "\r\n";
 	else
_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
sr-users@lists.sip-router.org
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users

Reply via email to