<div dir="ltr">Hi<div><br></div><div>I'm using Kamailio 4.2.4 and rtpengine 4.0.0.0+0~mr4.0.0.0. Kamailio is configured with sip users that can register. I have also configured a sip trunk to PSTN. I'm using rtpengine to handle RTP when a client want's to call to PSTN.</div><div><br></div><div>When a user behind NAT wants to make a call to PSTN and sends INVITE, then the rtpengine gets the SDP info from kamailio and rtppengine creates the new SDP info to be forwarded to PSTN.</div><div><br></div><div>The problem is that when the call is established rtpengine sends RTP to 10.0.0.100 instead of sending RTP to the NAT'ed users public IP 80.71.X.X ?</div><div><br></div><div>I thought that "fix_nated_sdp("2")" would do the job before "rtpengine_offer("asymmetric")" but it dosen't have any effect?</div><div><br></div><div>I have included kamailio.cfg, rtpengine logs and ngrep between kamailio and rtpengine.</div><div><br></div><div>Cheers,</div><div>Martin</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div>kamailio.cfg</div><div>---------------------------------------<br></div><div><div>#!KAMAILIO</div><div><br></div><div>## !define WITH_DEBUG</div><div><br></div><div>#!define WITH_MYSQL</div><div>#!define WITH_AUTH</div><div>#!define WITH_USRLOCDB</div><div>#!define WITH_NAT</div><div>#!define WITH_TLS</div><div>#!define WITH_PSTN</div><div><br></div><div>#</div><div># Kamailio (OpenSER) SIP Server v3.1 - default configuration script</div><div>#     - web: <a href="http://www.kamailio.org">http://www.kamailio.org</a></div><div>#     - git: <a href="http://sip-router.org">http://sip-router.org</a></div><div>#</div><div># Direct your questions about this file to: <<a href="mailto:sr-users@lists.sip-router.org">sr-users@lists.sip-router.org</a>></div><div>#</div><div># Refer to the Core CookBook at <a href="http://www.kamailio.org/dokuwiki/doku.php">http://www.kamailio.org/dokuwiki/doku.php</a></div><div># for an explanation of possible statements, functions and parameters.</div><div>#</div><div># Several features can be enabled using '#!define WITH_FEATURE' directives:</div><div>#</div><div># *** To run in debug mode: </div><div>#     - define WITH_DEBUG</div><div>#</div><div># *** To enable mysql: </div><div>#     - define WITH_MYSQL</div><div>#</div><div># *** To enable authentication execute:</div><div>#     - enable mysql</div><div>#     - define WITH_AUTH</div><div>#     - add users using 'kamctl'</div><div>#</div><div># *** To enable IP authentication execute:</div><div>#     - enable mysql</div><div>#     - enable authentication</div><div>#     - define WITH_IPAUTH</div><div>#     - add IP addresses with group id '1' to 'address' table</div><div>#</div><div># *** To enable persistent user location execute:</div><div>#     - enable mysql</div><div>#     - define WITH_USRLOCDB</div><div>#</div><div># *** To enable presence server execute:</div><div>#     - enable mysql</div><div>#     - define WITH_PRESENCE</div><div>#</div><div># *** To enable nat traversal execute:</div><div>#     - define WITH_NAT</div><div>#     - install RTPProxy: <a href="http://www.rtpproxy.org">http://www.rtpproxy.org</a></div><div>#     - start RTPProxy:</div><div>#        rtpproxy -l _your_public_ip_ -s udp:localhost:7722</div><div>#</div><div># *** To enable PSTN gateway routing execute:</div><div>#     - define WITH_PSTN</div><div>#     - set the value of pstn.gw_ip</div><div>#     - check route[PSTN] for regexp routing condition</div><div>#</div><div># *** To enable database aliases lookup execute:</div><div>#     - enable mysql</div><div>#     - define WITH_ALIASDB</div><div>#</div><div># *** To enable multi-domain support execute:</div><div>#     - enable mysql</div><div>#     - define WITH_MULTIDOMAIN</div><div>#</div><div># *** To enable TLS support execute:</div><div>#     - adjust CFGDIR/tls.cfg as needed</div><div>#     - define WITH_TLS</div><div>#</div><div># *** To enable XMLRPC support execute:</div><div>#     - define WITH_XMLRPC</div><div>#     - adjust route[XMLRPC] for access policy</div><div>#</div><div># *** To enable anti-flood detection execute:</div><div>#     - adjust pike and htable=>ipban settings as needed (default is</div><div>#       block if more than 16 requests in 2 seconds and ban for 300 seconds)</div><div>#     - define WITH_ANTIFLOOD</div><div>#</div><div># *** To enhance accounting execute:</div><div>#     - enable mysql</div><div>#     - define WITH_ACCDB</div><div>#     - add following columns to database</div><div>#!ifdef ACCDB_COMMENT</div><div>  ALTER TABLE acc ADD COLUMN src_user VARCHAR(64) NOT NULL DEFAULT '';</div><div>  ALTER TABLE acc ADD COLUMN src_domain VARCHAR(128) NOT NULL DEFAULT '';</div><div>  ALTER TABLE acc ADD COLUMN dst_ouser VARCHAR(64) NOT NULL DEFAULT '';</div><div>  ALTER TABLE acc ADD COLUMN dst_user VARCHAR(64) NOT NULL DEFAULT '';</div><div>  ALTER TABLE acc ADD COLUMN dst_domain VARCHAR(128) NOT NULL DEFAULT '';</div><div>  ALTER TABLE missed_calls ADD COLUMN src_user VARCHAR(64) NOT NULL DEFAULT '';</div><div>  ALTER TABLE missed_calls ADD COLUMN src_domain VARCHAR(128) NOT NULL DEFAULT '';</div><div>  ALTER TABLE missed_calls ADD COLUMN dst_ouser VARCHAR(64) NOT NULL DEFAULT '';</div><div>  ALTER TABLE missed_calls ADD COLUMN dst_user VARCHAR(64) NOT NULL DEFAULT '';</div><div>  ALTER TABLE missed_calls ADD COLUMN dst_domain VARCHAR(128) NOT NULL DEFAULT '';</div><div>#!endif</div><div><br></div><div>####### Defined Values #########</div><div><br></div><div># *** Value defines - IDs used later in config</div><div>#!ifdef WITH_MYSQL</div><div># - database URL - used to connect to database server by modules such</div><div>#       as: auth_db, acc, usrloc, a.s.o.</div><div>#!define DBURL "mysql://kamailio:kamailiorw@localhost/kamailio"</div><div>#!endif</div><div>#!ifdef WITH_MULTIDOMAIN</div><div># - the value for 'use_domain' parameters</div><div>#!define MULTIDOMAIN 1</div><div>#!else</div><div>#!define MULTIDOMAIN 0</div><div>#!endif</div><div><br></div><div># - flags</div><div>#   FLT_ - per transaction (message) flags</div><div>#<span class="" style="white-space:pre">  </span>FLB_ - per branch flags</div><div>#!define FLT_ACC 1</div><div>#!define FLT_ACCMISSED 2</div><div>#!define FLT_ACCFAILED 3</div><div>#!define FLT_NATS 5</div><div><br></div><div>#!define FLB_NATB 6</div><div>#!define FLB_NATSIPPING 7</div><div><br></div><div>####### Global Parameters #########</div><div><br></div><div>#!ifdef WITH_DEBUG</div><div>debug=4</div><div>log_stderror=yes</div><div>#!else</div><div>debug=2</div><div>log_stderror=no</div><div>#!endif</div><div><br></div><div>memdbg=5</div><div>memlog=5</div><div><br></div><div>log_facility=LOG_LOCAL0</div><div><br></div><div>fork=yes</div><div>children=4</div><div><br></div><div>/* uncomment the next line to disable TCP (default on) */</div><div>#disable_tcp=yes</div><div><br></div><div>/* uncomment the next line to disable the auto discovery of local aliases</div><div>   based on reverse DNS on IPs (default on) */</div><div>#auto_aliases=no</div><div><br></div><div>/* add local domain aliases */</div><div>#alias="<a href="http://sip.mydomain.com">sip.mydomain.com</a>"</div><div><br></div><div>/* uncomment and configure the following line if you want Kamailio to </div><div>   bind on a specific interface/port/proto (default bind on all available) */</div><div>#listen=udp:<a href="http://10.0.0.10:5060">10.0.0.10:5060</a></div><div><br></div><div>/* port to listen to</div><div> * - can be specified more than once if needed to listen on many ports */</div><div>port=5060</div><div><br></div><div>#!ifdef WITH_TLS</div><div>enable_tls=yes</div><div>#!endif</div><div><br></div><div>tcp_connection_lifetime=3605</div><div><br></div><div>####### Custom Parameters #########</div><div><br></div><div># These parameters can be modified runtime via RPC interface</div><div># - see the documentation of 'cfg_rpc' module.</div><div>#</div><div># Format: <a href="http://group.id">group.id</a> = value 'desc' description</div><div># Access: $sel(<a href="http://cfg_get.group.id">cfg_get.group.id</a>) or @<a href="http://cfg_get.group.id">cfg_get.group.id</a></div><div>#</div><div><br></div><div>#!ifdef WITH_PSTN</div><div># PSTN GW Routing</div><div>#</div><div># - pstn.gw_ip: valid IP or hostname as string value, example:</div><div># pstn.gw_ip = "10.0.0.101" desc "My PSTN GW Address"</div><div>#</div><div># - by default is empty to avoid misrouting</div><div>pstn.gw_ip = "<a href="http://trunk.testconnect.dk">trunk.testconnect.dk</a>" desc "PSTN GW Address"</div><div>#!endif</div><div><br></div><div><br></div><div>####### Modules Section ########</div><div><br></div><div># set paths to location of modules</div><div>#!ifdef LOCAL_TEST_RUN</div><div>mpath="modules"</div><div>#!else</div><div>mpath="/usr/lib/x86_64-linux-gnu/kamailio/modules/"</div><div>#!endif</div><div><br></div><div>#!ifdef WITH_MYSQL</div><div>loadmodule "db_mysql.so"</div><div>#!endif</div><div><br></div><div>loadmodule "mi_fifo.so"</div><div>loadmodule "kex.so"</div><div>loadmodule "tm.so"</div><div>loadmodule "tmx.so"</div><div>loadmodule "sl.so"</div><div>loadmodule "rr.so"</div><div>loadmodule "pv.so"</div><div>loadmodule "maxfwd.so"</div><div>loadmodule "usrloc.so"</div><div>loadmodule "registrar.so"</div><div>loadmodule "textops.so"</div><div>loadmodule "siputils.so"</div><div>loadmodule "xlog.so"</div><div>loadmodule "sanity.so"</div><div>loadmodule "ctl.so"</div><div>loadmodule "mi_rpc.so"</div><div>loadmodule "acc.so"</div><div># loadmodule "rtpengine.so"</div><div><br></div><div>#!ifdef WITH_AUTH</div><div>loadmodule "auth.so"</div><div>loadmodule "auth_db.so"</div><div>#!ifdef WITH_IPAUTH</div><div>loadmodule "permissions.so"</div><div>#!endif</div><div>#!endif</div><div><br></div><div>#!ifdef WITH_ALIASDB</div><div>loadmodule "alias_db.so"</div><div>#!endif</div><div><br></div><div>#!ifdef WITH_MULTIDOMAIN</div><div>loadmodule "domain.so"</div><div>#!endif</div><div><br></div><div>#!ifdef WITH_PRESENCE</div><div>loadmodule "presence.so"</div><div>loadmodule "presence_xml.so"</div><div>#!endif</div><div><br></div><div>#!ifdef WITH_NAT</div><div>loadmodule "nathelper.so"</div><div># loadmodule "rtpproxy.so"</div><div>loadmodule "rtpengine.so"</div><div>loadmodule "path.so"</div><div>#!endif</div><div><br></div><div>#!ifdef WITH_TLS</div><div>loadmodule "tls.so"</div><div>#!endif</div><div><br></div><div>#!ifdef WITH_ANTIFLOOD</div><div>loadmodule "htable.so"</div><div>loadmodule "pike.so"</div><div>#!endif</div><div><br></div><div>#!ifdef WITH_XMLRPC</div><div>loadmodule "xmlrpc.so"</div><div>#!endif</div><div><br></div><div># ----------------- setting module-specific parameters ---------------</div><div><br></div><div><br></div><div># ----- mi_fifo params -----</div><div>modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")</div><div><br></div><div><br></div><div># ----- tm params -----</div><div># auto-discard branches from previous serial forking leg</div><div>modparam("tm", "failure_reply_mode", 3)</div><div># default retransmission timeout: 30sec</div><div>modparam("tm", "fr_timer", 30000)</div><div># default invite retransmission timeout after 1xx: 120sec</div><div>modparam("tm", "fr_inv_timer", 120000)</div><div><br></div><div><br></div><div># ----- rr params -----</div><div># add value to ;lr param to cope with most of the UAs</div><div>modparam("rr", "enable_full_lr", 1)</div><div># do not append from tag to the RR (no need for this script)</div><div>modparam("rr", "append_fromtag", 0)</div><div><br></div><div><br></div><div># ----- registrar params -----</div><div>modparam("registrar", "method_filtering", 1)</div><div>/* uncomment the next line to disable parallel forking via location */</div><div># modparam("registrar", "append_branches", 0)</div><div>/* uncomment the next line not to allow more than 10 contacts per AOR */</div><div>#modparam("registrar", "max_contacts", 10)</div><div><br></div><div><br></div><div># ----- acc params -----</div><div>/* what special events should be accounted ? */</div><div>modparam("acc", "early_media", 0)</div><div>modparam("acc", "report_ack", 0)</div><div>modparam("acc", "report_cancels", 0)</div><div>/* by default ww do not adjust the direct of the sequential requests.</div><div>   if you enable this parameter, be sure the enable "append_fromtag"</div><div>   in "rr" module */</div><div>modparam("acc", "detect_direction", 0)</div><div>/* account triggers (flags) */</div><div>modparam("acc", "log_flag", FLT_ACC)</div><div>modparam("acc", "log_missed_flag", FLT_ACCMISSED)</div><div>modparam("acc", "log_extra", </div><div><span class="" style="white-space:pre">       </span>"src_user=$fU;src_domain=$fd;dst_ouser=$tU;dst_user=$rU;dst_domain=$rd")</div><div>modparam("acc", "failed_transaction_flag", FLT_ACCFAILED)</div><div>/* enhanced DB accounting */</div><div>#!ifdef WITH_ACCDB</div><div>modparam("acc", "db_flag", FLT_ACC)</div><div>modparam("acc", "db_missed_flag", FLT_ACCMISSED)</div><div>modparam("acc", "db_url", DBURL)</div><div>modparam("acc", "db_extra",</div><div><span class="" style="white-space:pre">       </span>"src_user=$fU;src_domain=$fd;dst_ouser=$tU;dst_user=$rU;dst_domain=$rd")</div><div>#!endif</div><div><br></div><div><br></div><div># ----- usrloc params -----</div><div>/* enable DB persistency for location entries */</div><div>#!ifdef WITH_USRLOCDB</div><div>modparam("usrloc", "db_url", DBURL)</div><div>modparam("usrloc", "db_mode", 2)</div><div>modparam("usrloc", "use_domain", MULTIDOMAIN)</div><div>#!endif</div><div><br></div><div><br></div><div># ----- auth_db params -----</div><div>#!ifdef WITH_AUTH</div><div>modparam("auth_db", "db_url", DBURL)</div><div>modparam("auth_db", "calculate_ha1", yes)</div><div>modparam("auth_db", "password_column", "password")</div><div>modparam("auth_db", "load_credentials", "")</div><div>modparam("auth_db", "use_domain", MULTIDOMAIN)</div><div><br></div><div># ----- permissions params -----</div><div>#!ifdef WITH_IPAUTH</div><div>modparam("permissions", "db_url", DBURL)</div><div>modparam("permissions", "db_mode", 1)</div><div>#!endif</div><div><br></div><div>#!endif</div><div><br></div><div><br></div><div># ----- alias_db params -----</div><div>#!ifdef WITH_ALIASDB</div><div>modparam("alias_db", "db_url", DBURL)</div><div>modparam("alias_db", "use_domain", MULTIDOMAIN)</div><div>#!endif</div><div><br></div><div><br></div><div># ----- domain params -----</div><div>#!ifdef WITH_MULTIDOMAIN</div><div>modparam("domain", "db_url", DBURL)</div><div># use caching</div><div>modparam("domain", "db_mode", 1)</div><div># register callback to match myself condition with domains list</div><div>modparam("domain", "register_myself", 1)</div><div>#!endif</div><div><br></div><div><br></div><div>#!ifdef WITH_PRESENCE</div><div># ----- presence params -----</div><div>modparam("presence", "db_url", DBURL)</div><div><br></div><div># ----- presence_xml params -----</div><div>modparam("presence_xml", "db_url", DBURL)</div><div>modparam("presence_xml", "force_active", 1)</div><div>#!endif</div><div><br></div><div><br></div><div>#!ifdef WITH_NAT</div><div># ----- rtpproxy params -----</div><div># modparam("rtpproxy", "rtpproxy_sock", "udp:<a href="http://127.0.0.1:7722">127.0.0.1:7722</a>")</div><div># modparam("rtpproxy", "rtpproxy_sock", "unix:/var/run/rtpproxy/rtpproxy.sock")</div><div><br></div><div># single rtproxy</div><div>#modparam("rtpengine", "rtpengine_disable_tout", -1)</div><div>#modparam("rtpengine", "rtpengine_sock", "udp:localhost:12222")</div><div>modparam("rtpengine", "rtpengine_sock", "udp:localhost:22222")</div><div>modparam("path", "use_received", 1);</div><div><br></div><div># ----- nathelper params -----</div><div>modparam("nathelper", "natping_interval", 30)</div><div>modparam("nathelper", "ping_nated_only", 1)</div><div>modparam("nathelper", "sipping_bflag", FLB_NATSIPPING)</div><div>modparam("nathelper", "sipping_from", "<a href="mailto:sip%3Apinger@kamailio.org">sip:pinger@kamailio.org</a>")</div><div><br></div><div># params needed for NAT traversal in other modules</div><div>modparam("nathelper|registrar", "received_avp", "$avp(RECEIVED)")</div><div>modparam("usrloc", "nat_bflag", FLB_NATB)</div><div>#!endif</div><div><br></div><div><br></div><div>#!ifdef WITH_TLS</div><div># ----- tls params -----</div><div>modparam("tls", "config", "/etc/kamailio/tls.cfg")</div><div>#!endif</div><div><br></div><div>#!ifdef WITH_ANTIFLOOD</div><div># ----- pike params -----</div><div>modparam("pike", "sampling_time_unit", 2)</div><div>modparam("pike", "reqs_density_per_unit", 16)</div><div>modparam("pike", "remove_latency", 4)</div><div><br></div><div># ----- htable params -----</div><div># ip ban htable with autoexpire after 5 minutes</div><div>modparam("htable", "htable", "ipban=>size=8;autoexpire=300;")</div><div>#!endif</div><div><br></div><div>#!ifdef WITH_XMLRPC</div><div># ----- xmlrpc params -----</div><div>modparam("xmlrpc", "route", "XMLRPC");</div><div>modparam("xmlrpc", "url_match", "^/RPC")</div><div>#!endif</div><div><br></div><div>####### Routing Logic ########</div><div><br></div><div><br></div><div># Main SIP request routing logic</div><div># - processing of any incoming SIP request starts with this route</div><div>route {</div><div><br></div><div><span class="" style="white-space:pre"> </span>if($rU=~"^\+[1-9][0-9]{3,20}$") {</div><div><span class="" style="white-space:pre">                </span>xlog("L_INFO", "MS: BEFORE STRIP $rm from $fu:$sp) to $ru\n");</div><div><span class="" style="white-space:pre">         </span>strip(3);</div><div><span class="" style="white-space:pre">          </span>xlog("L_INFO", "MS: AFTER STRIP $rm from $fu:$sp) to $ru\n");</div><div><span class="" style="white-space:pre">  </span>} else if($rU=~"^00[1-9][0-9]{3,20}$") {</div><div><span class="" style="white-space:pre">         </span>xlog("L_INFO", "MS: BEFORE STRIP $rm from $fu:$sp) to $ru\n");</div><div><span class="" style="white-space:pre">         </span>strip(4);</div><div><span class="" style="white-space:pre">          </span>xlog("L_INFO", "MS: AFTER STRIP $rm from $fu:$sp) to $ru\n");</div><div><span class="" style="white-space:pre">  </span>}</div><div><br></div><div><span class="" style="white-space:pre"> </span>xlog("L_INFO", "MS: BEFORE REQINIT $rm from $fu:$sp) to $ru\n");</div><div><br></div><div><span class="" style="white-space:pre">      </span># per request initial checks</div><div><span class="" style="white-space:pre">       </span>route(REQINIT);</div><div><br></div><div><span class="" style="white-space:pre">   </span>xlog("L_INFO", "MS: AFTER REQINIT $rm from $fu:$sp) to $ru\n");</div><div><br></div><div><span class="" style="white-space:pre">       </span># NAT detection</div><div><span class="" style="white-space:pre">    </span>route(NAT);</div><div><br></div><div><span class="" style="white-space:pre">       </span>xlog("L_INFO", "MS: AFTER NAT $rm from $fu:$sp) to $ru\n");</div><div><br></div><div><span class="" style="white-space:pre">   </span># handle requests within SIP dialogs</div><div><span class="" style="white-space:pre">       </span>route(WITHINDLG);</div><div><br></div><div><span class="" style="white-space:pre"> </span>xlog("L_INFO", "MS: AFTER WITHINDLG $rm from $fu:$sp) to $ru\n");</div><div><br></div><div><span class="" style="white-space:pre">     </span>### only initial requests (no To tag)</div><div><br></div><div><span class="" style="white-space:pre">     </span># CANCEL processing</div><div><span class="" style="white-space:pre">        </span>if (is_method("CANCEL"))</div><div><span class="" style="white-space:pre"> </span>{</div><div><span class="" style="white-space:pre">          </span>if (t_check_trans())</div><div><span class="" style="white-space:pre">                       </span>t_relay();</div><div><span class="" style="white-space:pre">         </span>exit;</div><div><span class="" style="white-space:pre">      </span>}</div><div><br></div><div><span class="" style="white-space:pre"> </span>t_check_trans();</div><div><br></div><div><span class="" style="white-space:pre">  </span># authentication</div><div><span class="" style="white-space:pre">   </span>route(AUTH);</div><div><br></div><div><span class="" style="white-space:pre">      </span># record routing for dialog forming requests (in case they are routed)</div><div><span class="" style="white-space:pre">     </span># - remove preloaded route headers</div><div><span class="" style="white-space:pre"> </span>remove_hf("Route");</div><div><span class="" style="white-space:pre">      </span>if (is_method("INVITE|SUBSCRIBE"))</div><div><span class="" style="white-space:pre">               </span>record_route();</div><div><br></div><div><span class="" style="white-space:pre">   </span># account only INVITEs</div><div><span class="" style="white-space:pre">     </span>if (is_method("INVITE"))</div><div><span class="" style="white-space:pre"> </span>{</div><div><span class="" style="white-space:pre">          </span>setflag(FLT_ACC); # do accounting</div><div><span class="" style="white-space:pre">  </span>}</div><div><br></div><div><span class="" style="white-space:pre"> </span># dispatch requests to foreign domains</div><div><span class="" style="white-space:pre">     </span>route(SIPOUT);</div><div><br></div><div><span class="" style="white-space:pre">    </span>### requests for my local domains</div><div><br></div><div><span class="" style="white-space:pre"> </span># handle presence related requests</div><div><span class="" style="white-space:pre"> </span>route(PRESENCE);</div><div><br></div><div><span class="" style="white-space:pre">  </span>xlog("L_INFO", "MS: AFTER PRESENCE $rm from $fu:$sp) to $ru\n");</div><div><br></div><div><span class="" style="white-space:pre">      </span># handle registrations</div><div><span class="" style="white-space:pre">     </span>route(REGISTRAR);</div><div><br></div><div><span class="" style="white-space:pre"> </span>xlog("L_INFO", "MS: AFTER REGISTRAR $rm from $fu:$sp) to $ru\n");</div><div><br></div><div><span class="" style="white-space:pre">     </span>if ($rU==$null)</div><div><span class="" style="white-space:pre">    </span>{</div><div><span class="" style="white-space:pre">          </span># request with no Username in RURI</div><div><span class="" style="white-space:pre">         </span>sl_send_reply("484","Address Incomplete");</div><div><span class="" style="white-space:pre">             </span>exit;</div><div><span class="" style="white-space:pre">      </span>}</div><div><br></div><div><span class="" style="white-space:pre"> </span>xlog("L_INFO", "MS: BEFORE PSTN $rm from $fu:$sp) to $ru\n");</div><div><br></div><div><span class="" style="white-space:pre"> </span># dispatch destinations to PSTN</div><div><span class="" style="white-space:pre">    </span>route(PSTN);</div><div><br></div><div><span class="" style="white-space:pre">      </span>xlog("L_INFO", "MS: AFTER PSTN $rm from $fu:$sp) to $ru\n");</div><div><br></div><div><span class="" style="white-space:pre">  </span># user location service</div><div><span class="" style="white-space:pre">    </span>route(LOCATION);</div><div><br></div><div><span class="" style="white-space:pre">  </span>route(RELAY);</div><div>}</div><div><br></div><div><br></div><div>route[RELAY] {</div><div>#!ifdef WITH_NAT</div><div><span class="" style="white-space:pre">        </span>if (check_route_param("nat=yes")) {</div><div><span class="" style="white-space:pre">              </span>setbflag(FLB_NATB);</div><div><span class="" style="white-space:pre">        </span>}</div><div><span class="" style="white-space:pre">  </span>if (isflagset(FLT_NATS) || isbflagset(FLB_NATB)) {</div><div><span class="" style="white-space:pre">         </span>xlog("L_INFO", "MS: RELAY NAT RTPPROXY $rm from $fu:$sp) to $ru\n");</div><div><span class="" style="white-space:pre">           </span>route(RTPPROXY);</div><div><span class="" style="white-space:pre">   </span>}</div><div>#!endif</div><div><br></div><div><span class="" style="white-space:pre">   </span>#if (!isflagset(FLT_NATS) && !isbflagset(FLB_NATB) && is_method("INVITE")) {</div><div><span class="" style="white-space:pre">     </span>#<span class="" style="white-space:pre"> </span>xlog("L_INFO", "MS: RELAY ALWAYS RTPPROXY $rm from $fu:$sp) to $ru\n");</div><div><span class="" style="white-space:pre">        </span>#<span class="" style="white-space:pre"> </span>route(RTPPROXY);</div><div><span class="" style="white-space:pre">   </span>#}</div><div><br></div><div><span class="" style="white-space:pre">        </span>#rtpengine_manage();</div><div><br></div><div><span class="" style="white-space:pre">      </span>/* example how to enable some additional event routes */</div><div><span class="" style="white-space:pre">   </span>if (is_method("INVITE")) {</div><div><span class="" style="white-space:pre">               </span>#t_on_branch("BRANCH_ONE");</div><div><span class="" style="white-space:pre">              </span>t_on_reply("REPLY_ONE");</div><div><span class="" style="white-space:pre">         </span>t_on_failure("FAIL_ONE");</div><div><span class="" style="white-space:pre">        </span>}</div><div><br></div><div><span class="" style="white-space:pre"> </span>if (!t_relay()) {</div><div><span class="" style="white-space:pre">          </span>sl_reply_error();</div><div><span class="" style="white-space:pre">  </span>}</div><div><span class="" style="white-space:pre">  </span>exit;</div><div>}</div><div><br></div><div># Per SIP request initial checks</div><div>route[REQINIT] {</div><div>#!ifdef WITH_ANTIFLOOD</div><div><span class="" style="white-space:pre">  </span># flood dection from same IP and traffic ban for a while</div><div><span class="" style="white-space:pre">   </span># be sure you exclude checking trusted peers, such as pstn gateways</div><div><span class="" style="white-space:pre">        </span># - local host excluded (e.g., loop to self)</div><div><span class="" style="white-space:pre">       </span>if(src_ip!=myself)</div><div><span class="" style="white-space:pre"> </span>{</div><div><span class="" style="white-space:pre">          </span>if($sht(ipban=>$si)!=$null)</div><div><span class="" style="white-space:pre">             </span>{</div><div><span class="" style="white-space:pre">                  </span># ip is already blocked</div><div><span class="" style="white-space:pre">                    </span>xdbg("request from blocked IP - $rm from $fu (IP:$si:$sp)\n");</div><div><span class="" style="white-space:pre">                   </span>exit;</div><div><span class="" style="white-space:pre">              </span>}</div><div><span class="" style="white-space:pre">          </span>if (!pike_check_req())</div><div><span class="" style="white-space:pre">             </span>{</div><div><span class="" style="white-space:pre">                  </span>xlog("L_ALERT","ALERT: pike blocking $rm from $fu (IP:$si:$sp)\n");</div><div><span class="" style="white-space:pre">                    </span>$sht(ipban=>$si) = 1;</div><div><span class="" style="white-space:pre">                   </span>exit;</div><div><span class="" style="white-space:pre">              </span>}</div><div><span class="" style="white-space:pre">  </span>}</div><div>#!endif</div><div><br></div><div><span class="" style="white-space:pre">   </span>if (!mf_process_maxfwd_header("10")) {</div><div><span class="" style="white-space:pre">           </span>sl_send_reply("483","Too Many Hops");</div><div><span class="" style="white-space:pre">          </span>exit;</div><div><span class="" style="white-space:pre">      </span>}</div><div><br></div><div><span class="" style="white-space:pre"> </span>if(!sanity_check("1511", "7"))</div><div><span class="" style="white-space:pre"> </span>{</div><div><span class="" style="white-space:pre">          </span>xlog("Malformed SIP message from $si:$sp\n");</div><div><span class="" style="white-space:pre">            </span>exit;</div><div><span class="" style="white-space:pre">      </span>}</div><div>}</div><div><br></div><div># Handle requests within SIP dialogs</div><div>route[WITHINDLG] {</div><div><span class="" style="white-space:pre">     </span>if (has_totag()) {</div><div><span class="" style="white-space:pre">         </span># sequential request withing a dialog should</div><div><span class="" style="white-space:pre">               </span># take the path determined by record-routing</div><div><span class="" style="white-space:pre">               </span>if (loose_route()) {</div><div><span class="" style="white-space:pre">                       </span>if (is_method("BYE")) {</div><div><span class="" style="white-space:pre">                          </span>setflag(FLT_ACC); # do accounting ...</div><div><span class="" style="white-space:pre">                              </span>setflag(FLT_ACCFAILED); # ... even if the transaction fails</div><div><span class="" style="white-space:pre">                        </span>}</div><div><span class="" style="white-space:pre">                  </span>route(RELAY);</div><div><span class="" style="white-space:pre">              </span>} else {</div><div><span class="" style="white-space:pre">                   </span>if (is_method("SUBSCRIBE") && uri == myself) {</div><div><span class="" style="white-space:pre">                           </span># in-dialog subscribe requests</div><div><span class="" style="white-space:pre">                             </span>route(PRESENCE);</div><div><span class="" style="white-space:pre">                           </span>exit;</div><div><span class="" style="white-space:pre">                      </span>}</div><div><span class="" style="white-space:pre">                  </span>if ( is_method("ACK") ) {</div><div><span class="" style="white-space:pre">                                </span>if ( t_check_trans() ) {</div><div><span class="" style="white-space:pre">                                   </span># no loose-route, but stateful ACK;</div><div><span class="" style="white-space:pre">                                        </span># must be an ACK after a 487</div><div><span class="" style="white-space:pre">                                       </span># or e.g. 404 from upstream server</div><div><span class="" style="white-space:pre">                                 </span>t_relay();</div><div><span class="" style="white-space:pre">                                 </span>exit;</div><div><span class="" style="white-space:pre">                              </span>} else {</div><div><span class="" style="white-space:pre">                                   </span># ACK without matching transaction ... ignore and discard</div><div><span class="" style="white-space:pre">                                  </span>exit;</div><div><span class="" style="white-space:pre">                              </span>}</div><div><span class="" style="white-space:pre">                  </span>}</div><div><span class="" style="white-space:pre">                  </span>xlog("L_INFO", "MS: route[WITHINDLG] 404 $rm from $fu:$sp) to $ru\n");</div><div><span class="" style="white-space:pre">                 </span>sl_send_reply("404","Not here");</div><div><span class="" style="white-space:pre">               </span>}</div><div><span class="" style="white-space:pre">          </span>exit;</div><div><span class="" style="white-space:pre">      </span>}</div><div>}</div><div><br></div><div># Handle SIP registrations</div><div>route[REGISTRAR] {</div><div><span class="" style="white-space:pre">       </span>if (is_method("REGISTER"))</div><div><span class="" style="white-space:pre">       </span>{</div><div><span class="" style="white-space:pre">          </span>if(isflagset(FLT_NATS))</div><div><span class="" style="white-space:pre">            </span>{</div><div><span class="" style="white-space:pre">                  </span>setbflag(FLB_NATB);</div><div><span class="" style="white-space:pre">                        </span># uncomment next line to do SIP NAT pinging </div><div><span class="" style="white-space:pre">                      </span>## setbflag(FLB_NATSIPPING);</div><div><span class="" style="white-space:pre">               </span>}</div><div><span class="" style="white-space:pre">          </span>if (!save("location"))</div><div><span class="" style="white-space:pre">                   </span>sl_reply_error();</div><div><br></div><div><span class="" style="white-space:pre">         </span>exit;</div><div><span class="" style="white-space:pre">      </span>}</div><div>}</div><div><br></div><div># USER location service</div><div>route[LOCATION] {</div><div><br></div><div>#!ifdef WITH_ALIASDB</div><div><span class="" style="white-space:pre">       </span># search in DB-based aliases</div><div><span class="" style="white-space:pre">       </span>alias_db_lookup("dbaliases");</div><div>#!endif</div><div><br></div><div><span class="" style="white-space:pre">     </span>if (!lookup("location")) {</div><div><span class="" style="white-space:pre">               </span>switch ($rc) {</div><div><span class="" style="white-space:pre">                     </span>case -1:</div><div><span class="" style="white-space:pre">                   </span>case -3:</div><div><span class="" style="white-space:pre">                           </span>t_newtran();</div><div><span class="" style="white-space:pre">                               </span>xlog("L_INFO", "MS: LOCATION 404 $rm from $fu:$sp) to $ru\n");</div><div><span class="" style="white-space:pre">                         </span>t_reply("404", "Not Found");</div><div><span class="" style="white-space:pre">                           </span>exit;</div><div><span class="" style="white-space:pre">                      </span>case -2:</div><div><span class="" style="white-space:pre">                           </span>sl_send_reply("405", "Method Not Allowed");</div><div><span class="" style="white-space:pre">                            </span>exit;</div><div><span class="" style="white-space:pre">              </span>}</div><div><span class="" style="white-space:pre">  </span>}</div><div><br></div><div><span class="" style="white-space:pre"> </span># when routing via usrloc, log the missed calls also</div><div><span class="" style="white-space:pre">       </span>if (is_method("INVITE"))</div><div><span class="" style="white-space:pre"> </span>{</div><div><span class="" style="white-space:pre">          </span>setflag(FLT_ACCMISSED);</div><div><span class="" style="white-space:pre">    </span>}</div><div>}</div><div><br></div><div># Presence server route</div><div>route[PRESENCE] {</div><div><span class="" style="white-space:pre">   </span>if(!is_method("PUBLISH|SUBSCRIBE"))</div><div><span class="" style="white-space:pre">              </span>return;</div><div><br></div><div>#!ifdef WITH_PRESENCE</div><div><span class="" style="white-space:pre">       </span>if (!t_newtran())</div><div><span class="" style="white-space:pre">  </span>{</div><div><span class="" style="white-space:pre">          </span>sl_reply_error();</div><div><span class="" style="white-space:pre">          </span>exit;</div><div><span class="" style="white-space:pre">      </span>};</div><div><br></div><div><span class="" style="white-space:pre">        </span>if(is_method("PUBLISH"))</div><div><span class="" style="white-space:pre"> </span>{</div><div><span class="" style="white-space:pre">          </span>handle_publish();</div><div><span class="" style="white-space:pre">          </span>t_release();</div><div><span class="" style="white-space:pre">       </span>}</div><div><span class="" style="white-space:pre">  </span>else</div><div><span class="" style="white-space:pre">       </span>if( is_method("SUBSCRIBE"))</div><div><span class="" style="white-space:pre">      </span>{</div><div><span class="" style="white-space:pre">          </span>handle_subscribe();</div><div><span class="" style="white-space:pre">                </span>t_release();</div><div><span class="" style="white-space:pre">       </span>}</div><div><span class="" style="white-space:pre">  </span>exit;</div><div>#!endif</div><div><span class="" style="white-space:pre">        </span></div><div><span class="" style="white-space:pre">   </span># if presence enabled, this part will not be executed</div><div><span class="" style="white-space:pre">      </span>if (is_method("PUBLISH") || $rU==$null)</div><div><span class="" style="white-space:pre">  </span>{</div><div><span class="" style="white-space:pre">          </span>sl_send_reply("404", "Not here");</div><div><span class="" style="white-space:pre">              </span>exit;</div><div><span class="" style="white-space:pre">      </span>}</div><div><span class="" style="white-space:pre">  </span>return;</div><div>}</div><div><br></div><div># Authentication route</div><div>route[AUTH] {</div><div>#!ifdef WITH_AUTH</div><div><span class="" style="white-space:pre">  </span>if (is_method("REGISTER"))</div><div><span class="" style="white-space:pre">       </span>{</div><div><span class="" style="white-space:pre">          </span># authenticate the REGISTER requests (uncomment to enable auth)</div><div><span class="" style="white-space:pre">            </span>if (!www_authorize("$td", "subscriber"))</div><div><span class="" style="white-space:pre">               </span>{</div><div><span class="" style="white-space:pre">                  </span>www_challenge("$td", "0");</div><div><span class="" style="white-space:pre">                     </span>exit;</div><div><span class="" style="white-space:pre">              </span>}</div><div><br></div><div><span class="" style="white-space:pre">         </span>if ($au!=$tU)</div><div><span class="" style="white-space:pre">              </span>{</div><div><span class="" style="white-space:pre">                  </span>sl_send_reply("403","Forbidden auth ID");</div><div><span class="" style="white-space:pre">                      </span>exit;</div><div><span class="" style="white-space:pre">              </span>}</div><div><span class="" style="white-space:pre">  </span>} else {</div><div><br></div><div>#!ifdef WITH_IPAUTH</div><div><span class="" style="white-space:pre">                </span>if(allow_source_address())</div><div><span class="" style="white-space:pre">         </span>{</div><div><span class="" style="white-space:pre">                  </span># source IP allowed</div><div><span class="" style="white-space:pre">                        </span>return;</div><div><span class="" style="white-space:pre">            </span>}</div><div>#!endif</div><div><br></div><div><span class="" style="white-space:pre">           </span># authenticate if from local subscriber</div><div><span class="" style="white-space:pre">            </span>if (from_uri==myself)</div><div><span class="" style="white-space:pre">              </span>{</div><div><span class="" style="white-space:pre">                  </span>if (!proxy_authorize("$fd", "subscriber")) {</div><div><span class="" style="white-space:pre">                           </span>proxy_challenge("$fd", "0");</div><div><span class="" style="white-space:pre">                           </span>exit;</div><div><span class="" style="white-space:pre">                      </span>}</div><div><span class="" style="white-space:pre">                  </span>if (is_method("PUBLISH"))</div><div><span class="" style="white-space:pre">                        </span>{</div><div><span class="" style="white-space:pre">                          </span>if ($au!=$tU) {</div><div><span class="" style="white-space:pre">                                    </span>sl_send_reply("403","Forbidden auth ID");</div><div><span class="" style="white-space:pre">                                      </span>exit;</div><div><span class="" style="white-space:pre">                              </span>}</div><div><span class="" style="white-space:pre">                  </span>} else {</div><div><span class="" style="white-space:pre">                           </span>if ($au!=$fU) {</div><div><span class="" style="white-space:pre">                                    </span>sl_send_reply("403","Forbidden auth ID");</div><div><span class="" style="white-space:pre">                                      </span>exit;</div><div><span class="" style="white-space:pre">                              </span>}</div><div><span class="" style="white-space:pre">                  </span>}</div><div><br></div><div><span class="" style="white-space:pre">                 </span>consume_credentials();</div><div><span class="" style="white-space:pre">                     </span># caller authenticated</div><div><span class="" style="white-space:pre">             </span>} else {</div><div><span class="" style="white-space:pre">                   </span># caller is not local subscriber, then check if it calls</div><div><span class="" style="white-space:pre">                   </span># a local destination, otherwise deny, not an open relay here</div><div><span class="" style="white-space:pre">                      </span>if (!uri==myself)</div><div><span class="" style="white-space:pre">                  </span>{</div><div><span class="" style="white-space:pre">                          </span>sl_send_reply("403","Not relaying");</div><div><span class="" style="white-space:pre">                           </span>exit;</div><div><span class="" style="white-space:pre">                      </span>}</div><div><span class="" style="white-space:pre">          </span>}</div><div><span class="" style="white-space:pre">  </span>}</div><div>#!endif</div><div><span class="" style="white-space:pre">    </span>return;</div><div>}</div><div><br></div><div># Caller NAT detection route</div><div>route[NAT] {</div><div>#!ifdef WITH_NAT</div><div><span class="" style="white-space:pre">      </span>force_rport();</div><div><span class="" style="white-space:pre">     </span>setflag(FLT_NATS);</div><div><span class="" style="white-space:pre"> </span>if (nat_uac_test("19")) {</div><div><span class="" style="white-space:pre">                </span>if (method=="REGISTER") {</div><div><span class="" style="white-space:pre">                        </span>fix_nated_register();</div><div><span class="" style="white-space:pre">              </span>} else {</div><div><span class="" style="white-space:pre">                   </span>fix_nated_contact();</div><div><span class="" style="white-space:pre">               </span>}</div><div><span class="" style="white-space:pre">          </span>if (method=="INVITE" && has_body("application/sdp")) {</div><div><span class="" style="white-space:pre">                 </span>xlog("L_INFO", "MS: fix_nated_sdp $rm from $fu:$sp) to $ru\n");</div><div><span class="" style="white-space:pre">                        </span>#fix_nated_sdp("11");</div><div><span class="" style="white-space:pre">                    </span>#fix_nated_sdp("2");</div><div><span class="" style="white-space:pre">                     </span>#fix_nated_sdp("8");</div><div><span class="" style="white-space:pre">             </span>}</div><div><span class="" style="white-space:pre">          </span>setflag(FLT_NATS);</div><div><span class="" style="white-space:pre"> </span>}</div><div>#!endif</div><div><span class="" style="white-space:pre">    </span>return;</div><div>}</div><div><br></div><div># RTPProxy control</div><div>route[RTPPROXY] {</div><div>#!ifdef WITH_NAT</div><div><span class="" style="white-space:pre">   </span>if (is_method("BYE")) {</div><div><span class="" style="white-space:pre">          </span>## unforce_rtp_proxy();</div><div><span class="" style="white-space:pre">            </span>rtpengine_delete();</div><div><span class="" style="white-space:pre">        </span>} else if (is_method("INVITE")){</div><div><span class="" style="white-space:pre">         </span># force_rtp_proxy();</div><div><span class="" style="white-space:pre">               </span>## rtpproxy_offer();</div><div><span class="" style="white-space:pre">               </span>#rtpengine_manage();</div><div><span class="" style="white-space:pre">               </span>rtpengine_offer("asymmetric");</div><div><span class="" style="white-space:pre">   </span>}</div><div><br></div><div><span class="" style="white-space:pre"> </span>if (!has_totag()) add_rr_param(";nat=yes");</div><div>#!endif</div><div><span class="" style="white-space:pre">        </span>return;</div><div>}</div><div><br></div><div># Routing to foreign domains</div><div>route[SIPOUT] {</div><div><span class="" style="white-space:pre">  </span>if (!uri==myself)</div><div><span class="" style="white-space:pre">  </span>{</div><div><span class="" style="white-space:pre">          </span>append_hf("P-hint: outbound\r\n");</div><div><span class="" style="white-space:pre">               </span>route(RELAY);</div><div><span class="" style="white-space:pre">      </span>}</div><div>}</div><div><br></div><div># PSTN GW routing</div><div>route[PSTN] {</div><div>#!ifdef WITH_PSTN</div><div><span class="" style="white-space:pre">     </span># check if PSTN GW IP is defined</div><div><span class="" style="white-space:pre">   </span>if (strempty($sel(cfg_get.pstn.gw_ip))) {</div><div><span class="" style="white-space:pre">          </span>xlog("SCRIPT: PSTN rotuing enabled but pstn.gw_ip not defined\n");</div><div><span class="" style="white-space:pre">               </span>return;</div><div><span class="" style="white-space:pre">    </span>}</div><div><br></div><div><span class="" style="white-space:pre"> </span># route to PSTN dialed numbers starting with '+' or '00'</div><div><span class="" style="white-space:pre">   </span>#     (international format)</div><div><span class="" style="white-space:pre">     </span># - update the condition to match your dialing rules for PSTN routing</div><div><span class="" style="white-space:pre">      </span>#if(!($rU=~"^(\+|00)[1-9][0-9]{3,20}$")) {</div><div><span class="" style="white-space:pre">       </span>#<span class="" style="white-space:pre"> </span>xlog("L_INFO", "MS: PSTN not international $rm from $fu:$sp) to $ru\n");</div><div><span class="" style="white-space:pre">       </span>#<span class="" style="white-space:pre"> </span>xlog("L_INFO", "MS: PSTN not international rU=$rU\n");</div><div><span class="" style="white-space:pre"> </span>#<span class="" style="white-space:pre"> </span>return;</div><div><span class="" style="white-space:pre">    </span>#}</div><div><span class="" style="white-space:pre"> </span>xlog("L_INFO", "MS: PSTN check myself $rm from $fu:$sp) to $rU\n");</div><div><span class="" style="white-space:pre">    </span>if($rU=~"^201111[0-9][0-9]$") {</div><div><span class="" style="white-space:pre">          </span>xlog("L_INFO", "MS: PSTN to myself $rm from $fu:$sp) to $ru\n");</div><div><span class="" style="white-space:pre">               </span>return;</div><div><span class="" style="white-space:pre">    </span>}</div><div><br></div><div><span class="" style="white-space:pre"> </span># only local users allowed to call</div><div><span class="" style="white-space:pre"> </span>if(from_uri!=myself) {</div><div><span class="" style="white-space:pre">             </span>xlog("L_INFO", "MS: PSTN 403 $rm from $fu:$sp) to $ru\n");</div><div><span class="" style="white-space:pre">             </span>sl_send_reply("403", "Not Allowed");</div><div><span class="" style="white-space:pre">           </span>exit;</div><div><span class="" style="white-space:pre">      </span>}</div><div><br></div><div><span class="" style="white-space:pre"> </span>#if (is_method("INVITE")) {</div><div><span class="" style="white-space:pre">      </span>#<span class="" style="white-space:pre"> </span>rtpproxy_offer();</div><div><span class="" style="white-space:pre">  </span>#}</div><div><br></div><div><span class="" style="white-space:pre">        </span>xlog("L_INFO", "MS: PSTN before rewrite $rm from $fu:$sp) to $ru\n");</div><div><span class="" style="white-space:pre">  </span>$ru = "sip:" + $rU + "@" + $sel(cfg_get.pstn.gw_ip);</div><div><span class="" style="white-space:pre">   </span>xlog("L_INFO", "MS: PSTN before rewrite $rm from $fu:$sp) to $ru\n");</div><div><br></div><div><span class="" style="white-space:pre"> </span>route(RELAY);</div><div><span class="" style="white-space:pre">      </span>exit;</div><div>#!endif</div><div><br></div><div><span class="" style="white-space:pre">       </span>return;</div><div>}</div><div><br></div><div># XMLRPC routing</div><div>#!ifdef WITH_XMLRPC</div><div>route[XMLRPC]</div><div>{</div><div><span class="" style="white-space:pre">      </span># allow XMLRPC from localhost</div><div><span class="" style="white-space:pre">      </span>if ((method=="POST" || method=="GET")</div><div><span class="" style="white-space:pre">                  </span>&& (src_ip==127.0.0.1)) {</div><div><span class="" style="white-space:pre">          </span># close connection only for xmlrpclib user agents (there is a bug in</div><div><span class="" style="white-space:pre">               </span># xmlrpclib: it waits for EOF before interpreting the response).</div><div><span class="" style="white-space:pre">           </span>if ($hdr(User-Agent) =~ "xmlrpclib")</div><div><span class="" style="white-space:pre">                     </span>set_reply_close();</div><div><span class="" style="white-space:pre">         </span>set_reply_no_connect();</div><div><span class="" style="white-space:pre">            </span>dispatch_rpc();</div><div><span class="" style="white-space:pre">            </span>exit;</div><div><span class="" style="white-space:pre">      </span>}</div><div><span class="" style="white-space:pre">  </span>send_reply("403", "Forbidden");</div><div><span class="" style="white-space:pre">        </span>exit;</div><div>}</div><div>#!endif</div><div><br></div><div># Sample branch router</div><div>branch_route[BRANCH_ONE] {</div><div><span class="" style="white-space:pre"> </span>xdbg("new branch at $ru\n");</div><div>}</div><div><br></div><div># Sample onreply route</div><div>onreply_route[REPLY_ONE] {</div><div><span class="" style="white-space:pre">      </span>xdbg("incoming reply\n");</div><div>#!ifdef WITH_NAT</div><div><span class="" style="white-space:pre"> </span>if ((isflagset(FLT_NATS) || isbflagset(FLB_NATB))</div><div><span class="" style="white-space:pre">                  </span>&& status=~"(183)|(2[0-9][0-9])") {</div><div><span class="" style="white-space:pre">              </span># force_rtp_proxy();</div><div><span class="" style="white-space:pre">               </span>## rtpproxy_answer();</div><div><span class="" style="white-space:pre">              </span>rtpengine_answer("asymmetric");</div><div><span class="" style="white-space:pre">  </span>}</div><div><span class="" style="white-space:pre">  </span>if (isbflagset("6")) {</div><div><span class="" style="white-space:pre">           </span>fix_nated_contact();</div><div><span class="" style="white-space:pre">       </span>}</div><div>#!endif</div><div>}</div><div><br></div><div># Sample failure route</div><div>failure_route[FAIL_ONE] {</div><div>#!ifdef WITH_NAT</div><div><span class="" style="white-space:pre">       </span>if (is_method("INVITE")</div><div><span class="" style="white-space:pre">                  </span>&& (isbflagset(FLB_NATB) || isflagset(FLT_NATS))) {</div><div><span class="" style="white-space:pre">                </span>#unforce_rtp_proxy();</div><div><span class="" style="white-space:pre">              </span>rtpengine_delete();</div><div><span class="" style="white-space:pre">        </span>}</div><div>#!endif</div><div><br></div><div><span class="" style="white-space:pre">   </span>if (t_is_canceled()) {</div><div><span class="" style="white-space:pre">             </span>exit;</div><div><span class="" style="white-space:pre">      </span>}</div><div><br></div><div><span class="" style="white-space:pre"> </span># uncomment the following lines if you want to block client </div><div><span class="" style="white-space:pre">      </span># redirect based on 3xx replies.</div><div><span class="" style="white-space:pre">   </span>##if (t_check_status("3[0-9][0-9]")) {</div><div><span class="" style="white-space:pre">   </span>##t_reply("404","Not found");</div><div><span class="" style="white-space:pre">  </span>##<span class="" style="white-space:pre">        </span>exit;</div><div><span class="" style="white-space:pre">      </span>##}</div><div><br></div><div><span class="" style="white-space:pre">       </span># uncomment the following lines if you want to redirect the failed </div><div><span class="" style="white-space:pre">       </span># calls to a different new destination</div><div><span class="" style="white-space:pre">     </span>##if (t_check_status("486|408")) {</div><div><span class="" style="white-space:pre">       </span>##<span class="" style="white-space:pre">        </span>sethostport("<a href="http://192.168.2.100:5060">192.168.2.100:5060</a>");</div><div><span class="" style="white-space:pre"> </span>##<span class="" style="white-space:pre">        </span>append_branch();</div><div><span class="" style="white-space:pre">   </span>##<span class="" style="white-space:pre">        </span># do not set the missed call flag again</div><div><span class="" style="white-space:pre">    </span>##<span class="" style="white-space:pre">        </span>t_relay();</div><div><span class="" style="white-space:pre"> </span>##}</div><div>}</div></div><div>---------------------------------------<br></div><div><br></div><div><br></div><div>rtpengine logs -  rtpengine offer</div><div>---------------------------------------<br></div><div><div><div>Apr 23 00:52:30 sipserver-01 rtpengine[27441]: [1040bcc4797199cf13f2820d7e0bea88@0:0:0:0:0:0:0:0] Received command 'offer' from <a href="http://127.0.0.1:56696">127.0.0.1:56696</a></div><div>Apr 23 00:52:30 sipserver-01 rtpengine[27441]: [1040bcc4797199cf13f2820d7e0bea88@0:0:0:0:0:0:0:0] Dump for 'offer' from <a href="http://127.0.0.1:56696">127.0.0.1:56696</a>: { "sdp": "v=0#015#012o=<a href="http://20111101-jitsi.org">20111101-jitsi.org</a> 0 0 IN IP4 10.0.0.100#015#012s=-#015#012c=IN IP4 10.0.0.100#015#012t=0 0#015#012m=audio 5034 RTP/AVP 0 101#015#012a=rtpmap:0 PCMU/8000#015#012a=rtpmap:101 telephone-event/8000#015#012a=extmap:1 urn:ietf:params:rtp-hdrext:csrc-audio-level#015#012a=extmap:2 urn:ietf:params:rtp-hdrext:ssrc-audio-level#015#012a=rtcp-xr:voip-metrics#015#012", "flags": [ "asymmetric" ], "call-id": "1040bcc4797199cf13f2820d7e0bea88@0:0:0:0:0:0:0:0", "received-from": [ "IP4", "80.71.X.X" ], "from-tag" ...</div><div>Apr 23 00:52:30 sipserver-01 rtpengine[27441]: [1040bcc4797199cf13f2820d7e0bea88@0:0:0:0:0:0:0:0] ... : "6bb9cb39", "command": "offer" }</div><div>Apr 23 00:52:30 sipserver-01 rtpengine[27441]: [1040bcc4797199cf13f2820d7e0bea88@0:0:0:0:0:0:0:0] Creating new call</div><div>Apr 23 00:52:30 sipserver-01 rtpengine[27441]: [1040bcc4797199cf13f2820d7e0bea88@0:0:0:0:0:0:0:0] Opened ports 10728..10729 for media relay</div><div>Apr 23 00:52:30 sipserver-01 rtpengine[27441]: [1040bcc4797199cf13f2820d7e0bea88@0:0:0:0:0:0:0:0] Opened ports 10746..10747 for media relay</div><div>Apr 23 00:52:30 sipserver-01 rtpengine[27441]: [1040bcc4797199cf13f2820d7e0bea88@0:0:0:0:0:0:0:0] Shutting down ICE agent (nothing to do)</div><div>Apr 23 00:52:30 sipserver-01 rtpengine[27441]: [1040bcc4797199cf13f2820d7e0bea88@0:0:0:0:0:0:0:0] Replying to 'offer' from <a href="http://127.0.0.1:56696">127.0.0.1:56696</a></div><div>Apr 23 00:52:30 sipserver-01 rtpengine[27441]: [1040bcc4797199cf13f2820d7e0bea88@0:0:0:0:0:0:0:0] Response dump for 'offer' to <a href="http://127.0.0.1:56696">127.0.0.1:56696</a>: { "sdp": "v=0#015#012o=<a href="http://20111101-jitsi.org">20111101-jitsi.org</a> 0 0 IN IP4 10.0.0.100#015#012s=-#015#012c=IN IP4 188.166.X.X#015#012t=0 0#015#012m=audio 10728 RTP/AVP 0 101#015#012a=rtpmap:0 PCMU/8000#015#012a=rtpmap:101 telephone-event/8000#015#012a=rtcp-xr:voip-metrics#015#012a=sendrecv#015#012a=rtcp:10729#015#012a=ice-ufrag:LA1hlEBj#015#012a=ice-pwd:S99AwTSnHtaGnaeCv0DL795QH7#015#012a=candidate:rPBAvp2vmOwOv6BS 1 UDP 2130706431 188.166.X.X 10728 typ host#015#012a=candidate:rPBAvp2vmOwOv6BS 2 UDP 2130706430 188.166.X.X 10729 typ host#015#012", "result": " ...</div><div>Apr 23 00:52:30 sipserver-01 rtpengine[27441]: [1040bcc4797199cf13f2820d7e0bea88@0:0:0:0:0:0:0:0] ... ok" }</div></div><div><br></div><div><div>rtpengine logs -  rtpengine delete</div><div>---------------------------------------</div></div><div><div>Apr 23 00:53:16 sipserver-01 rtpengine[27441]: [1040bcc4797199cf13f2820d7e0bea88@0:0:0:0:0:0:0:0] Call branch '6bb9cb39' deleted, no more branches remaining</div><div>Apr 23 00:53:16 sipserver-01 rtpengine[27441]: [1040bcc4797199cf13f2820d7e0bea88@0:0:0:0:0:0:0:0] Final packet stats:</div><div>Apr 23 00:53:16 sipserver-01 rtpengine[27441]: [1040bcc4797199cf13f2820d7e0bea88@0:0:0:0:0:0:0:0] --- Tag 'gK04ca43fa', created 0:46 ago, in dialogue with '6bb9cb39'</div><div>Apr 23 00:53:16 sipserver-01 rtpengine[27441]: [1040bcc4797199cf13f2820d7e0bea88@0:0:0:0:0:0:0:0] ------ Media #1 (audio over RTP/AVP) using PCMU/8000</div><div>Apr 23 00:53:16 sipserver-01 rtpengine[27441]: [1040bcc4797199cf13f2820d7e0bea88@0:0:0:0:0:0:0:0] --------- Port 10728 <> 188.226.X.X:10146, 544 p, 93568 b, 0 e, 1429743164 last_packet</div><div>Apr 23 00:53:16 sipserver-01 rtpengine[27441]: [1040bcc4797199cf13f2820d7e0bea88@0:0:0:0:0:0:0:0] --------- Port 10729 <> 188.226.X.X:10147 (RTCP), 0 p, 0 b, 0 e, 1429743150 last_packet</div><div>Apr 23 00:53:16 sipserver-01 rtpengine[27441]: [1040bcc4797199cf13f2820d7e0bea88@0:0:0:0:0:0:0:0] --- Tag '6bb9cb39', created 0:46 ago, in dialogue with 'gK04ca43fa'</div><div>Apr 23 00:53:16 sipserver-01 rtpengine[27441]: [1040bcc4797199cf13f2820d7e0bea88@0:0:0:0:0:0:0:0] ------ Media #1 (audio over RTP/AVP) using PCMU/8000</div><div>Apr 23 00:53:16 sipserver-01 rtpengine[27441]: [1040bcc4797199cf13f2820d7e0bea88@0:0:0:0:0:0:0:0] --------- Port 10746 <>      <a href="http://10.0.0.100:5034">10.0.0.100:5034</a> , 595 p, 102340 b, 0 e, 1429743166 last_packet</div><div>Apr 23 00:53:16 sipserver-01 rtpengine[27441]: [1040bcc4797199cf13f2820d7e0bea88@0:0:0:0:0:0:0:0] --------- Port 10747 <>      <a href="http://10.0.0.100:5035">10.0.0.100:5035</a>  (RTCP), 3 p, 228 b, 0 e, 1429743166 last_packet</div><div>Apr 23 00:53:16 sipserver-01 rtpengine[27441]: ci=1040bcc4797199cf13f2820d7e0bea88@0:0:0:0:0:0:0:0, created_from=<a href="http://127.0.0.1:56696">127.0.0.1:56696</a>, last_signal=1429743164, tos=0, ml0_start_time=1429743160.638873, ml0_end_time=1429743166.013947, ml0_duration=5.375074, ml0_termination=REGULAR, ml0_local_tag=gK04ca43fa, ml0_local_tag_type=FROM_TAG, ml0_remote_tag=6bb9cb39, ml0_midx1_rtp_endpoint_ip=188.226.X.X, ml0_midx1_rtp_endpoint_port=10146, ml0_midx1_rtp_local_relay_port=10728, ml0_midx1_rtp_relayed_packets=544, ml0_midx1_rtp_relayed_bytes=93568, ml0_midx1_rtp_relayed_errors=0, ml0_midx1_rtp_last_packet=1429743164, ml0_midx1_rtcp_endpoint_ip=188.226.X.X, ml0_midx1_rtcp_endpoint_port=10147, ml0_midx1_rtcp_local_relay_port=10729, ml0_midx1_rtcp_relayed_packets=0, ml0_midx1_rtcp_relayed_bytes=0, ml0_midx1_rtcp_relayed_errors=0, ml0_midx1_rtcp_last_packet=1429743150, ml1_start_time=1429743164.196879, ml1_end_time=1429743166.013948, ml1_duration=1.817069, ml1_termination=REGULAR, ml1_local_tag=6bb9cb39, ml1_local_tag_type=TO_TAG, ml1_remote_tag=gK04ca43fa, ml1_midx1_rtp_endpoint_ip=10.0.0.100, ml1_midx1_rtp_endpoint_port=5034, ml1_midx1_rtp_local_relay_port=10746, ml1_midx1_rtp_relayed_packets=595, ml1_midx1_rtp_relayed_bytes=102340, ml1_midx1_rtp_relayed_errors=0, ml1_midx1_rtp_last_packet=1429743166, ml1_midx1_rtcp_endpoint_ip=10.0.0.100, ml1_midx1_rtcp_endpoint_port=5035, ml1_midx1_rtcp_local_relay_port=10747, ml1_midx1_rtcp_relayed_packets=3, ml1_midx1_rtcp_relayed_bytes=228, ml1_midx1_rtcp_relayed_errors=0, ml1_midx1_rtcp_last_packet=1429743166, </div></div></div><div>--------------------------------<br></div><div><br></div><div><br></div><div>ngrep - SDP send between kamailio and rtpengine:</div><div>--------------------------------</div><div><div>U <a href="http://127.0.0.1:56696">127.0.0.1:56696</a> -> <a href="http://127.0.0.1:22222">127.0.0.1:22222</a></div><div>10856_6 d3:sdp303:v=0.</div><div>o=<a href="http://20111101-jitsi.org">20111101-jitsi.org</a> 0 0 IN IP4 10.0.0.100.</div><div>s=-.</div><div>c=IN IP4 10.0.0.100.</div><div>t=0 0.</div><div>m=audio 5034 RTP/AVP 0 101.</div><div>a=rtpmap:0 PCMU/8000.</div><div>a=rtpmap:101 telephone-event/8000.</div><div>a=extmap:1 urn:ietf:params:rtp-hdrext:csrc-audio-level.</div><div>a=extmap:2 urn:ietf:params:rtp-hdrext:ssrc-audio-level.</div><div>a=rtcp-xr:voip-metrics.</div><div>5:flagsl10:asymmetrice7:call-id48:1040bcc4797199cf13f2820d7e0bea88@0:0:0:0:0:0:0:013:received-froml3:IP413:80.71.X.Xe8:from-tag8:6bb9cb397:command5:offere</div><div>#</div><div>U <a href="http://127.0.0.1:22222">127.0.0.1:22222</a> -> <a href="http://127.0.0.1:56696">127.0.0.1:56696</a></div><div>10856_6 d3:sdp430:v=0.</div><div>o=<a href="http://20111101-jitsi.org">20111101-jitsi.org</a> 0 0 IN IP4 10.0.0.100.</div><div>s=-.</div><div>c=IN IP4 188.166.X.X.</div><div>t=0 0.</div><div>m=audio 10728 RTP/AVP 0 101.</div><div>a=rtpmap:0 PCMU/8000.</div><div>a=rtpmap:101 telephone-event/8000.</div><div>a=rtcp-xr:voip-metrics.</div><div>a=sendrecv.</div><div>a=rtcp:10729.</div><div>a=ice-ufrag:LA1hlEBj.</div><div>a=ice-pwd:S99AwTSnHtaGnaeCv0DL795QH7.</div><div>a=candidate:rPBAvp2vmOwOv6BS 1 UDP 2130706431 188.166.X.X 10728 typ host.</div><div>a=candidate:rPBAvp2vmOwOv6BS 2 UDP 2130706430 188.166.X.X 10729 typ host.</div><div>6:result2:oke</div><div>#</div></div><div>--------------------------------</div></div>