diff --git a/core/AmConfig.cpp b/core/AmConfig.cpp index b6485863..8ea2c904 100644 --- a/core/AmConfig.cpp +++ b/core/AmConfig.cpp @@ -71,6 +71,7 @@ int AmConfig::LocalSIPPort = 5060; string AmConfig::LocalSIPIP = ""; string AmConfig::OutboundProxy = ""; bool AmConfig::ForceOutboundProxy = false; +bool AmConfig::ProxyStickyAuth = false; string AmConfig::Signature = ""; unsigned int AmConfig::MaxForwards = MAX_FORWARDS; bool AmConfig::SingleCodecInOK = false; @@ -286,6 +287,10 @@ int AmConfig::readConfiguration() if(cfg.hasParameter("force_outbound_proxy")) { ForceOutboundProxy = (cfg.getParameter("force_outbound_proxy") == "yes"); } + + if(cfg.hasParameter("proxy_sticky_auth")) { + ProxyStickyAuth = (cfg.getParameter("proxy_sticky_auth") == "yes"); + } // plugin_path if (cfg.hasParameter("plugin_path")) diff --git a/core/AmConfig.h b/core/AmConfig.h index b7226490..f587b400 100644 --- a/core/AmConfig.h +++ b/core/AmConfig.h @@ -102,6 +102,8 @@ struct AmConfig static string OutboundProxy; /** force Outbound Proxy to be used for in dialog requests */ static bool ForceOutboundProxy; + /** update ruri-host to previously resolved IP:port on SIP auth */ + static bool ProxyStickyAuth; /** Server/User-Agent header (optional) */ static string Signature; /** Value of Max-Forward header field for new requests */ diff --git a/core/etc/sems.conf.sample b/core/etc/sems.conf.sample index f53c0dbb..d2d84181 100644 --- a/core/etc/sems.conf.sample +++ b/core/etc/sems.conf.sample @@ -394,6 +394,16 @@ use_default_signature=yes # #100rel=require +# Make SIP authenticated requests sticky to the proxy? [yes | no] +# +# If enabled, host of request-URI of out-of-dialog requests that are +# authenticated with SIP auth is changed to the previously resolved +# next-hop IP:port. +# +# default: no +# +# proxy_sticky_auth=yes + # # Accept final replies without To-tag? [yes|no] # diff --git a/core/plug-in/uac_auth/UACAuth.cpp b/core/plug-in/uac_auth/UACAuth.cpp index e9fb675f..82bbdd78 100644 --- a/core/plug-in/uac_auth/UACAuth.cpp +++ b/core/plug-in/uac_auth/UACAuth.cpp @@ -167,6 +167,17 @@ bool UACAuth::onSipReply(const AmSipReply& reply, int old_dlg_status, const stri // reset remote tag so remote party // thinks its new dlg dlg->remote_tag = ""; + + if (AmConfig::ProxyStickyAuth) { + // update remote URI to resolved IP + size_t hpos = dlg->remote_uri.find("@"); + if (hpos != string::npos && reply.remote_ip.length()) { + dlg->remote_uri = dlg->remote_uri.substr(0, hpos+1) + + reply.remote_ip + ":"+int2str(reply.remote_port); + DBG("updated remote URI to '%s'\n", dlg->remote_uri.c_str()); + } + } + } // resend request if (dlg->sendRequest(ri->second.method,