Skip to content

Commit

Permalink
[b2b_entities/logic] use the newly added pref_socket
Browse files Browse the repository at this point in the history
When creating a new B2B client, avoid using the UAS side incoming socket as a forced socket. By doing that we override the proto given by the UAC RURI (and forcing to use the same proto as the UAS side - of course, unless we do not do a force send socket from script to manually indicate a new socket/proto). Shortly, th dynamic selection of the correct UAC socket is broken.

With this change, we do:
* if the UAS/msg side has a forced socket (from script), we will push it as forced socket to the UAC too (as before this change).
* if there is no forcing, the current UAS/msg incoming socket is passed as "preferred" socket to the UAC - like use it as time as it fits the RURI proto. This helps in preserving (during the whole b2b logic) the same socket when having multiple sockets serving the same protocol.

Fixes #3138
  • Loading branch information
bogdan-iancu committed Sep 15, 2023
1 parent 2824a38 commit 4244c28
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions modules/b2b_entities/b2be_load.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ typedef struct client_info
unsigned int cseq;
unsigned int maxfwd;
struct socket_info* send_sock;
struct socket_info* pref_sock;
struct usr_avp *avps;
}client_info_t;

Expand Down
6 changes: 4 additions & 2 deletions modules/b2b_entities/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,9 @@ str* _client_new(client_info_t* ci,b2b_notify_t b2b_cback,
}
dlg->state = B2B_NEW;
dlg->cseq[CALLER_LEG] =(ci->cseq?ci->cseq:1);
dlg->send_sock = ci->send_sock;

random_info.s = int2str(rand(), &random_info.len);

dlg->send_sock = ci->send_sock;
dlg->id = core_hash(&from_tag, random_info.s?&random_info:NULL, HASH_SIZE);

/* callid must have the special format */
Expand Down Expand Up @@ -223,6 +221,7 @@ str* _client_new(client_info_t* ci,b2b_notify_t b2b_cback,
td.T_flags=T_NO_AUTOACK_FLAG|T_PASS_PROVISIONAL_FLAG ;

td.send_sock = ci->send_sock;
td.pref_sock = ci->pref_sock;

if(ci->dst_uri.len)
td.obp = ci->dst_uri;
Expand Down Expand Up @@ -253,6 +252,8 @@ str* _client_new(client_info_t* ci,b2b_notify_t b2b_cback,
shm_free(b2b_key_shm);
return NULL;
}
/* update the dialog sock with actual socket used when sending the req */
dlg->send_sock = td.send_sock;
tmb.setlocalTholder(NULL);

LM_DBG("new client entity [%p] callid=[%.*s] tag=[%.*s] param=[%.*s]"
Expand Down Expand Up @@ -347,6 +348,7 @@ dlg_t* b2b_client_build_dlg(b2b_dlg_t* dlg, dlg_leg_t* leg, unsigned int maxfwd)
if(dlg->send_sock)
LM_DBG("send sock= %.*s\n", dlg->send_sock->address_str.len,
dlg->send_sock->address_str.s);
td->pref_sock = NULL; /* in-dialog req, use only the forced socket */

return td;
error:
Expand Down
15 changes: 8 additions & 7 deletions modules/b2b_logic/logic.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,8 @@ b2bl_entity_id_t *b2bl_new_client(client_info_t *ci, b2bl_tuple_t *tuple,
b2bl_entity_id_t* entity;

ci->method = method_invite;
ci->send_sock = msg ?
(msg->force_send_socket?msg->force_send_socket:msg->rcv.bind_address):NULL;
ci->send_sock = msg ? msg->force_send_socket : NULL;
ci->pref_sock = msg ? msg->rcv.bind_address : NULL;

if (adv_ct) {
ci->local_contact = *adv_ct;
Expand Down Expand Up @@ -727,8 +727,8 @@ int retry_init_bridge(struct sip_msg *msg, b2bl_tuple_t* tuple,
ci.extra_headers = tuple->extra_headers;
ci.client_headers= hdrs;
ci.body = &tuple->bridge_entities[0]->in_sdp;
ci.send_sock = msg ? (msg->force_send_socket?
msg->force_send_socket:msg->rcv.bind_address):NULL;
ci.send_sock = msg ? msg->force_send_socket : NULL;
ci.pref_sock = msg ? msg->rcv.bind_address : NULL;

ci.maxfwd = tuple->bridge_entities[0]->init_maxfwd;

Expand Down Expand Up @@ -2491,7 +2491,8 @@ str* create_top_hiding_entities(struct sip_msg* msg, b2bl_cback_f cbf,
ci.dst_uri = msg->dst_uri;
ci.extra_headers = &extra_headers;
ci.body = (body.s?&body:NULL);
ci.send_sock = msg->force_send_socket?msg->force_send_socket:msg->rcv.bind_address;
ci.send_sock = msg->force_send_socket;
ci.pref_sock = msg->rcv.bind_address;

memset(&ct_uri, 0, sizeof(struct sip_uri));
if (contact_user && parse_uri(ci.from_uri.s, ci.from_uri.len, &ct_uri) < 0) {
Expand Down Expand Up @@ -2938,8 +2939,8 @@ str* b2b_process_scenario_init(struct sip_msg* msg, b2bl_cback_f cbf,
ci.extra_headers = tuple->extra_headers;
ci.client_headers= hdrs;
ci.body = (body.s?&body:NULL);
ci.send_sock = msg->force_send_socket?
msg->force_send_socket:msg->rcv.bind_address;
ci.send_sock = msg->force_send_socket;
ci.pref_sock = msg->rcv.bind_address;

/* Decrement Max-Forwards value */
if ((maxfwd = b2b_msg_get_maxfwd(msg)) > 0) {
Expand Down

0 comments on commit 4244c28

Please sign in to comment.