Skip to content

Commit

Permalink
Fix advertised port and address per branch.
Browse files Browse the repository at this point in the history
Before the advertised_port/address are preserved only in the UAS part of the transaction - that means it is only one value and it is from the setting done in Request Route; whatever later setting done in Failure Route or Branch Route are not preserved at transaction level (even if they are used on the spot, for sending out the INVITE).
So, when we have to build a local request (ACK or CANCEL), we do not remember which specific address/port were advertised for that particular UAC (branch).

Fixes OpenSIPS#917.
  • Loading branch information
bogdan-iancu committed Jul 12, 2016
1 parent 7fa9cee commit eb850a2
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 5 deletions.
6 changes: 6 additions & 0 deletions modules/tm/h_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ void free_cell( struct cell* dead_cell )
if (dead_cell->uac[i].path_vec.s) {
tm_shm_free_unsafe(dead_cell->uac[i].path_vec.s);
}
if (dead_cell->uac[i].adv_address.s) {
tm_shm_free_unsafe(dead_cell->uac[i].adv_address.s);
}
if (dead_cell->uac[i].adv_port.s) {
tm_shm_free_unsafe(dead_cell->uac[i].adv_port.s);
}
if (dead_cell->uac[i].duri.s) {
tm_shm_free_unsafe(dead_cell->uac[i].duri.s);
}
Expand Down
4 changes: 4 additions & 0 deletions modules/tm/h_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ typedef struct ua_client
str duri;
/* the path vector used for this branch */
str path_vec;
/* the advertised address used for this branch */
str adv_address;
/* the advertised port used for this branch */
str adv_port;
/* number of RR headers that were locally added for this branch */
unsigned int added_rr;
/* if we store a reply (branch picking), this is where it is */
Expand Down
42 changes: 41 additions & 1 deletion modules/tm/t_fwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,33 @@ static inline int pre_print_uac_request( struct cell *t, int branch,
request->path_vec.len+1);
}

/* do the same for the advertised port & address */
if (request->set_global_address.len) {
t->uac[branch].adv_address.s = shm_resize(t->uac[branch].adv_address.s,
request->set_global_address.len+1);
if (t->uac[branch].adv_address.s==NULL) {
LM_ERR("shm_resize failed for storing the advertised address "
"(len=%d)\n",request->set_global_address.len);
goto error;
}
t->uac[branch].adv_address.len = request->set_global_address.len;
memcpy( t->uac[branch].adv_address.s, request->set_global_address.s,
request->set_global_address.len+1);
}
if (request->set_global_port.len) {
t->uac[branch].adv_port.s = shm_resize(t->uac[branch].adv_port.s,
request->set_global_port.len+1);
if (t->uac[branch].adv_port.s==NULL) {
LM_ERR("shm_resize failed for storing the advertised port "
"(len=%d)\n",request->set_global_port.len);
goto error;
}
t->uac[branch].adv_port.len = request->set_global_port.len;
memcpy( t->uac[branch].adv_port.s, request->set_global_port.s,
request->set_global_port.len+1);
}


/********** run route & callback ************/

/* run branch route, if any; run it before RURI's DNS lookup
Expand Down Expand Up @@ -430,6 +457,10 @@ static int add_uac( struct cell *t, struct sip_msg *request, str *uri,
destroy_avp_list(&t->uac[branch].user_avps);
if (t->uac[branch].path_vec.s)
shm_free(t->uac[branch].path_vec.s);
if (t->uac[branch].adv_address.s)
shm_free(t->uac[branch].adv_address.s);
if (t->uac[branch].adv_port.s)
shm_free(t->uac[branch].adv_port.s);
if (t->uac[branch].duri.s)
shm_free(t->uac[branch].duri.s);
memset(&t->uac[branch],0,sizeof(t->uac[branch]));
Expand All @@ -447,6 +478,8 @@ int e2e_cancel_branch( struct sip_msg *cancel_msg, struct cell *t_cancel,
unsigned int len;
str bk_dst_uri;
str bk_path_vec;
str bk_adv_address;
str bk_adv_port;

if (t_cancel->uac[branch].request.buffer.s) {
LM_CRIT("buffer rewrite attempt\n");
Expand All @@ -458,9 +491,13 @@ int e2e_cancel_branch( struct sip_msg *cancel_msg, struct cell *t_cancel,
cancel_msg->parsed_uri_ok=0;
bk_dst_uri = cancel_msg->dst_uri;
bk_path_vec = cancel_msg->path_vec;
bk_adv_address = cancel_msg->set_global_address;
bk_adv_port = cancel_msg->set_global_port;

/* force same path as for request */
/* force same path & advertising as for request */
cancel_msg->path_vec = t_invite->uac[branch].path_vec;
cancel_msg->set_global_address = t_invite->uac[branch].adv_address;
cancel_msg->set_global_port = t_invite->uac[branch].adv_port;

if ( pre_print_uac_request( t_cancel, branch, cancel_msg)!= 0 ) {
ret = -1;
Expand Down Expand Up @@ -502,6 +539,8 @@ int e2e_cancel_branch( struct sip_msg *cancel_msg, struct cell *t_cancel,
&bk_dst_uri);
cancel_msg->dst_uri = bk_dst_uri;
cancel_msg->path_vec = bk_path_vec;
cancel_msg->set_global_address = bk_adv_address;
cancel_msg->set_global_port = bk_adv_port;
error:
return ret;
}
Expand Down Expand Up @@ -626,6 +665,7 @@ int t_forward_nonack( struct cell *t, struct sip_msg* p_msg ,
bk_sock = p_msg->force_send_socket;
bk_path = p_msg->path_vec;
bk_bflags = p_msg->ruri_bflags;
/* advertised address/port are not changed */

/* check if the UAS retranmission port needs to be updated */
if ( (p_msg->msg_flags ^ t->uas.request->msg_flags) & FL_FORCE_RPORT )
Expand Down
4 changes: 4 additions & 0 deletions modules/tm/t_msgbuilder.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ char *build_local(struct cell *Trans,unsigned int branch,
if (!t_calc_branch(Trans, branch, branch_str.s, &branch_str.len ))
goto error;
set_hostport(&hp, (is_local(Trans))?0:req);
if (Trans->uac[branch].adv_address.len)
hp.host = &Trans->uac[branch].adv_address;
if (Trans->uac[branch].adv_port.len)
hp.port = &Trans->uac[branch].adv_port;
via=via_builder(&via_len, Trans->uac[branch].request.dst.send_sock,
&branch_str, 0, Trans->uac[branch].request.dst.proto, &hp );
if (!via){
Expand Down
4 changes: 0 additions & 4 deletions modules/tm/t_msgbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,6 @@ static inline int fake_req(struct sip_msg *faked_req, struct sip_msg *shm_msg,
shm_msg->path_vec.len);
}


/* we could also restore dst_uri, but will be confusing from script,
* so let it set to NULL */

/* set as flags the global flags and the branch flags from the
* elected branch */
faked_req->flags = uas->request->flags;
Expand Down

0 comments on commit eb850a2

Please sign in to comment.