Skip to content

Commit

Permalink
[dispatcher] Fix hackish extraction of TO URI upon pinging
Browse files Browse the repository at this point in the history
Better use the URI stored in callback params, rather then using the hackish way of extracting the URI from the T-stored To hdr.

This is a side effect of 9af1926
Reported by @denyspozniak
Closes #3000
  • Loading branch information
bogdan-iancu committed Jan 27, 2023
1 parent 8f3c6a1 commit e7aeb97
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
34 changes: 13 additions & 21 deletions modules/dispatcher/dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -2599,9 +2599,7 @@ int ds_print_mi_list(mi_item_t *part_item, ds_partition_t *partition, int full)
static void ds_options_callback( struct cell *t, int type,
struct tmcb_params *ps )
{
str uri = {0, 0};

/* The Param does contain the group, in which the failed host
/* The Param contains the URI+ group, in which the failed host
* can be found.*/
if (!ps->param) {
LM_DBG("No parameter provided, OPTIONS-Request was finished"
Expand All @@ -2615,27 +2613,22 @@ static void ds_options_callback( struct cell *t, int type,
ds_options_callback_param_t *cb_param =
(ds_options_callback_param_t*)(*ps->param);

/* The SIP-URI is taken from the Transaction.
* Remove the "To: " (s+4) and the trailing new-line (s - 4 (To: )
* - 2 (\r\n)). */
uri.s = t->to.s + 4;
uri.len = t->to.len - 6;
LM_DBG("OPTIONS-Request was finished with code %d (to %.*s, group %d)\n",
ps->code, uri.len, uri.s, cb_param->set_id);
ps->code, cb_param->uri.len, cb_param->uri.s, cb_param->set_id);

/* ps->code contains the result-code of the request;
* We accept "200 OK" by default and the custom codes
* defined in options_reply_codes parameter*/
if ((ps->code == 200) || check_options_rplcode(ps->code)) {
/* Set the according entry back to "Active":
* remove the Probing/Inactive Flag and reset the failure counter. */
if (ds_set_state(cb_param->set_id, &uri,
if (ds_set_state(cb_param->set_id, &cb_param->uri,
DS_INACTIVE_DST|DS_PROBING_DST|DS_RESET_FAIL_DST, 0,
cb_param->partition, 1, 0, MI_SSTR("200 OK probing reply")
) != 0)
{
LM_ERR("Setting the state failed (%.*s, group %d)\n", uri.len,
uri.s, cb_param->set_id);
LM_ERR("Setting the state failed (%.*s, group %d)\n",
cb_param->uri.len, cb_param->uri.s, cb_param->set_id);
}
}
/* if we always probe, and we get a timeout
Expand All @@ -2644,11 +2637,11 @@ static void ds_options_callback( struct cell *t, int type,
if((ds_probing_mode==1 || cb_param->always_probe) && ps->code != 200 &&
(ps->code == 408 || !check_options_rplcode(ps->code)))
{
if (ds_set_state(cb_param->set_id, &uri, DS_PROBING_DST, 1,
if (ds_set_state(cb_param->set_id, &cb_param->uri, DS_PROBING_DST, 1,
cb_param->partition, 1, 0, MI_SSTR("negative probing reply")) != 0)
{
LM_ERR("Setting the probing state failed (%.*s, group %d)\n",
uri.len, uri.s, cb_param->set_id);
cb_param->uri.len, cb_param->uri.s, cb_param->set_id);
}
}

Expand All @@ -2668,7 +2661,6 @@ void ds_check_timer(unsigned int ticks, void* param)
ds_options_callback_param_t params;

struct socket_info *sock;
str uri;
struct usr_avp *avps;

struct gw_prob_pack *next;
Expand Down Expand Up @@ -2732,11 +2724,6 @@ void ds_check_timer(unsigned int ticks, void* param)
break;
}

pack->uri.s = (char*)(pack+1);
memcpy(pack->uri.s, list->dlist[j].uri.s,
list->dlist[j].uri.len);
pack->uri.len = list->dlist[j].uri.len;

pack->sock = list->dlist[j].sock;

if (partition->attrs_avp_name>=0) {
Expand All @@ -2751,6 +2738,11 @@ void ds_check_timer(unsigned int ticks, void* param)
} else
pack->avps = NULL;

pack->params.uri.s = (char*)(pack+1);
memcpy(pack->params.uri.s, list->dlist[j].uri.s,
list->dlist[j].uri.len);
pack->params.uri.len = list->dlist[j].uri.len;

pack->params.partition = partition;
pack->params.set_id = list->id;
pack->params.always_probe =
Expand Down Expand Up @@ -2778,7 +2770,7 @@ void ds_check_timer(unsigned int ticks, void* param)
/* Execute the Dialog using the "request"-Method of the
* TM-Module.*/
if (tmb.new_auto_dlg_uac(&ds_ping_from,
&pack->uri, NULL, NULL,
&pack->params.uri, NULL, NULL,
pack->sock?pack->sock:probing_sock,
&dlg) != 0 ) {
LM_ERR("failed to create new TM dlg\n");
Expand Down
2 changes: 2 additions & 0 deletions modules/dispatcher/dispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ typedef struct
ds_partition_t *partition;
int set_id;
int always_probe;
str uri; /* Note: the URI string is allocated together with
* this structure, so no need of separate freeing */
} ds_options_callback_param_t;

typedef struct _ds_selected_dst
Expand Down

0 comments on commit e7aeb97

Please sign in to comment.