Skip to content

Commit

Permalink
[tm] t_uac() gets a preferred socket too
Browse files Browse the repository at this point in the history
The function already receives a send_socket (a forced socket) which overrides the protocol given by the destination URI. But are cases were we need a milder approach, like a preffered socket to be used if not conflicting with the protocol given by the RURI.
What we have now:
* send_socket - it is a forced socket, overrides the proto given by RURI, it will be used for sure
* pref_socket - a preferred socket, to be used if no send_socket is given and if there is no conflict with the proto given by RURI (in case of a conflict, the pref_socket is discarded and a new socket is looked up based on the RURI info).

First part fix for #3138

(cherry picked from commit 2824a38)
  • Loading branch information
bogdan-iancu committed Sep 15, 2023
1 parent c01ebd5 commit 8700f69
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
3 changes: 2 additions & 1 deletion modules/tm/dlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ typedef struct dlg {
* can be reused when building a message (to
* prevent repeated analyzing of the dialog data
*/
struct socket_info* send_sock;
struct socket_info* send_sock; /* forced sock, overrides dst proto */
struct socket_info* pref_sock; /* preffered sock, if no proto conflict */
unsigned short mf_enforced; /* if Max-Forward is to be enforced */
unsigned short mf_value; /* the Mx-Forward values, if enforced */
void *dialog_ctx; /* backpointer to dialog ctx */
Expand Down
44 changes: 29 additions & 15 deletions modules/tm/uac.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,21 +231,28 @@ static int run_local_route( struct cell *new_cell, char **buf, int *buf_len,
/* calculate the socket corresponding to next hop */
new_proxy = uri2proxy(
req->dst_uri.s ? &(req->dst_uri) : &req->new_uri,
PROTO_NONE );
req->force_send_socket?req->force_send_socket->proto:PROTO_NONE);
if (new_proxy==0)
goto skip_update;
/* use the first address */
hostent2su( &new_to_su,
&new_proxy->host, new_proxy->addr_idx,
new_proxy->port ? new_proxy->port:SIP_PORT);
/* get the send socket */
new_send_sock = get_send_socket( req, &new_to_su,
new_proxy->proto);
if (new_send_sock==NULL) {
free_proxy( new_proxy );
pkg_free( new_proxy );
LM_ERR("no socket found for the new destination\n");
goto skip_update;
if (req->force_send_socket) {
new_send_sock = req->force_send_socket;
} else if (dialog->pref_sock &&
dialog->pref_sock->proto==new_proxy->proto) {
new_send_sock = dialog->pref_sock;
} else {
new_send_sock = get_send_socket( req, &new_to_su,
new_proxy->proto);
if (new_send_sock==NULL) {
free_proxy( new_proxy );
pkg_free( new_proxy );
LM_ERR("no socket found for the new destination\n");
goto skip_update;
}
}
}

Expand Down Expand Up @@ -430,7 +437,8 @@ int t_uac(str* method, str* headers, str* body, dlg_t* dialog,
LM_DBG("next_hop=<%.*s>\n",dialog->hooks.next_hop->len,
dialog->hooks.next_hop->s);

/* calculate the socket corresponding to next hop */
/* calculate the socket corresponding to next hop ; here we take
* into consideration the protocol forced by the "send_sock" */
proxy = uri2proxy( dialog->hooks.next_hop,
dialog->send_sock ? dialog->send_sock->proto : PROTO_NONE );
if (proxy==0) {
Expand All @@ -449,12 +457,18 @@ int t_uac(str* method, str* headers, str* body, dlg_t* dialog,
dialog->send_sock = NULL;
}
if (dialog->send_sock==NULL) {
/* get the send socket */
dialog->send_sock = get_send_socket(NULL/*msg*/, &to_su, proxy->proto);
if (!dialog->send_sock) {
LM_ERR("no corresponding socket for af %d\n", to_su.s.sa_family);
ser_error = E_NO_SOCKET;
goto error3;
if (dialog->pref_sock && proxy->proto == dialog->pref_sock->proto) {
dialog->send_sock = dialog->pref_sock;
} else {
/* get the send socket */
dialog->send_sock = get_send_socket(NULL/*msg*/, &to_su,
proxy->proto);
if (!dialog->send_sock) {
LM_ERR("no corresponding socket for af %d\n",
to_su.s.sa_family);
ser_error = E_NO_SOCKET;
goto error3;
}
}
}
LM_DBG("sending socket is %.*s \n",
Expand Down

0 comments on commit 8700f69

Please sign in to comment.