Skip to content

Commit

Permalink
Fixed interface matching in loose_route()
Browse files Browse the repository at this point in the history
If port is missing in Route URI, do not assume default 5060, but consider the schema and protocol (they may require a different default port).
Ex: sip:10.0.0.5;transport=tls was previously handled as sip:10.0.0.5:5060;transport=tls, which is wrong as the default TLS port is 5061
Reported on mailing list by Ravitez Dondeti.

(cherry picked from commit 3593a5f)
  • Loading branch information
bogdan-iancu committed May 30, 2016
1 parent ff237c8 commit f595cf4
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions modules/rr/loose.c
Expand Up @@ -224,14 +224,27 @@ static inline int is_2rr(str* _params)
* Check if URI is myself
*/
#ifdef ENABLE_USER_CHECK
static inline int is_myself(str *_user, str* _host, unsigned short _port)
static inline int is_myself(str *_user, struct sip_uri* _uri)
#else
static inline int is_myself(str* _host, unsigned short _port)
static inline int is_myself(struct sip_uri* _uri)
#endif
{
int ret;
unsigned short port;
unsigned short proto;

/* known protocol? */
if ((proto=_uri->proto)==PROTO_NONE) {
/* use UDP as default proto, but TLS for secure schemas */
proto = (_uri->type==SIPS_URI_T || _uri->type==TELS_URI_T)?
PROTO_TLS : PROTO_UDP ;
}

/* known port? */
if ((port=_uri->port_no)==0)
port = protos[proto].default_port;

ret = check_self(_host, _port ? _port : SIP_PORT, 0);/* match all protos*/
ret = check_self(&_uri->host, port, proto);
if (ret < 0) return 0;

#ifdef ENABLE_USER_CHECK
Expand Down Expand Up @@ -509,9 +522,9 @@ static inline int after_strict(struct sip_msg* _m)

if ( enable_double_rr && is_2rr(&puri.params) &&
#ifdef ENABLE_USER_CHECK
is_myself(&puri.user, &puri.host, puri.port_no)
is_myself(&puri.user, &puri)
#else
is_myself(&puri.host, puri.port_no)
is_myself(&puri)
#endif
) {
/* double route may occure due different IP and port, so force as
Expand Down Expand Up @@ -718,10 +731,10 @@ static inline int after_loose(struct sip_msg* _m, int preloaded)

/* IF the URI was added by me, remove it */
#ifdef ENABLE_USER_CHECK
ret=is_myself(&puri.user, &puri.host, puri.port_no);
ret=is_myself(&puri.user, &puri);
if (ret>0)
#else
if (is_myself(&puri.host, puri.port_no))
if (is_myself(&puri))
#endif
{
LM_DBG("Topmost route URI: '%.*s' is me\n",
Expand Down Expand Up @@ -899,10 +912,9 @@ int loose_route(struct sip_msg* _m)
return after_loose(_m, 1);
} else {
#ifdef ENABLE_USER_CHECK
if (is_myself(&_m->parsed_uri.user, &_m->parsed_uri.host,
_m->parsed_uri.port_no) && !(_m->parsed_uri.gr.s && _m->parsed_uri.gr.len)) {
if (is_myself(&_m->parsed_uri.user, &_m->parsed_uri) && !(_m->parsed_uri.gr.s && _m->parsed_uri.gr.len)) {
#else
if (is_myself(&_m->parsed_uri.host, _m->parsed_uri.port_no) && !(_m->parsed_uri.gr.s && _m->parsed_uri.gr.len)) {
if (is_myself(&_m->parsed_uri) && !(_m->parsed_uri.gr.s && _m->parsed_uri.gr.len)) {
#endif
return after_strict(_m);
} else {
Expand Down

0 comments on commit f595cf4

Please sign in to comment.