Skip to content

Commit

Permalink
[b2b_entities] fixed RURI matching against our sockets/listeners
Browse files Browse the repository at this point in the history
The proto and port must be correctly expanded to default values, if not present
For example, if TLS, the default port is 5061 and not 5060
Fixes #3546
  • Loading branch information
bogdan-iancu committed Jan 16, 2025
1 parent 178c138 commit 9f2aa5b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
34 changes: 20 additions & 14 deletions forward.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (C) 2008-2025 OpenSIPS Project
* Copyright (C) 2001-2003 FhG Fokus
*
* This file is part of opensips, a free SIP server.
Expand All @@ -15,16 +16,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* History:
* -------
* 2001-??-?? created by andrei
* ????-??-?? lots of changes by a lot of people
* 2003-02-11 added inline msg_send (andrei)
* 2003-04-07 changed all ports to host byte order (andrei)
* 2003-04-12 FORCE_RPORT_T added (andrei)
* 2003-04-15 added tcp_disable support (andrei)
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

/*!
Expand All @@ -48,13 +40,27 @@
#include "socket_info.h"

const struct socket_info* get_send_socket(struct sip_msg* msg,
const union sockaddr_union* su, int proto);
const struct socket_info* get_out_socket(const union sockaddr_union* to, int proto);
const union sockaddr_union* su, int proto);

const struct socket_info* get_out_socket(const union sockaddr_union* to,
int proto);

int check_self(str* host, unsigned short port, unsigned short proto);

/*! \brief checks if the proto:host:port is one of the address we listen on
*
* if port==0, the port number is expended to default
* if proto==0 (PROTO_NONE) the protocol is considered UDP
* returns 1 if true, 0 if false, -1 on error
*/
#define check_self_strict( _host, _port, _proto) \
check_self(_host,_port?_port:protos[_proto?_proto:PROTO_UDP].default_port,\
_proto?_proto:PROTO_UDP)

int forward_request( struct sip_msg* msg, struct proxy_l* p);

int update_sock_struct_from_via( union sockaddr_union* to,
struct sip_msg* msg,
struct via_body* via );
struct sip_msg* msg, struct via_body* via );

/*! \brief use src_ip, port=src_port if rport, via port if via port, 5060 otherwise */
#define update_sock_struct_from_ip( to, msg ) \
Expand Down
11 changes: 5 additions & 6 deletions modules/b2b_entities/dlg.c
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@ int b2b_register_cb(b2b_cb_t cb, int cb_type, str *mod_name)
return 0;
}


int b2b_prescript_f(struct sip_msg *msg, void *uparam)
{
str b2b_key;
Expand Down Expand Up @@ -766,8 +767,7 @@ int b2b_prescript_f(struct sip_msg *msg, void *uparam)
rt->nameaddr.uri.len,rt->nameaddr.uri.s);
return SCB_RUN_ALL;
}
if (check_self( &puri.host, puri.port_no?puri.port_no:SIP_PORT,
puri.proto?puri.proto:PROTO_UDP)!= 1 ) {
if (check_self_strict( &puri.host, puri.port_no, puri.proto)!= 1 ) {
LM_DBG("First Route uri is not mine\n");
return SCB_RUN_ALL; /* not for b2b */

Expand All @@ -785,13 +785,12 @@ int b2b_prescript_f(struct sip_msg *msg, void *uparam)
}
}
if (rt) {
if ( parse_uri(rt->nameaddr.uri.s,rt->nameaddr.uri.len,&puri)!=0 ) {
if ( parse_uri(rt->nameaddr.uri.s,rt->nameaddr.uri.len,&puri)!=0 ){
LM_ERR("Second route uri is not valid <%.*s>\n",
rt->nameaddr.uri.len,rt->nameaddr.uri.s);
return SCB_RUN_ALL;
}
if (check_self( &puri.host, puri.port_no?puri.port_no:SIP_PORT,
puri.proto?puri.proto:PROTO_UDP)!= 1 ) {
if (check_self_strict( &puri.host, puri.port_no, puri.proto)!= 1 ){
LM_DBG("Second Route uri is not mine\n");
return SCB_RUN_ALL; /* not for b2b */
}
Expand Down Expand Up @@ -822,7 +821,7 @@ int b2b_prescript_f(struct sip_msg *msg, void *uparam)
if(method_value!= METHOD_CANCEL)
{
LM_DBG("<uri> host:port [%.*s][%d]\n", host.len, host.s, port);
if (!check_self( &host, port ? port : SIP_PORT, msg->rcv.proto))
if (check_self_strict( &host, port, msg->parsed_uri.proto)!= 1 )
{
LM_DBG("RURI does not point to me\n");
return SCB_RUN_ALL;
Expand Down

0 comments on commit 9f2aa5b

Please sign in to comment.