diff --git a/forward.h b/forward.h index 585991ca6f..3f4cf9e30e 100644 --- a/forward.h +++ b/forward.h @@ -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. @@ -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 */ /*! @@ -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 ) \ diff --git a/modules/b2b_entities/dlg.c b/modules/b2b_entities/dlg.c index ddcb35d6f0..e163d67743 100644 --- a/modules/b2b_entities/dlg.c +++ b/modules/b2b_entities/dlg.c @@ -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; @@ -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 */ @@ -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 */ } @@ -822,7 +821,7 @@ int b2b_prescript_f(struct sip_msg *msg, void *uparam) if(method_value!= METHOD_CANCEL) { LM_DBG(" 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;