Skip to content

Commit

Permalink
dispatcher: provide ping_from and ping_method per partition
Browse files Browse the repository at this point in the history
  • Loading branch information
razvancrainea committed Jul 27, 2023
1 parent 7e866d5 commit 695f666
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
8 changes: 6 additions & 2 deletions modules/dispatcher/dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -2771,7 +2771,9 @@ 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,
if (tmb.new_auto_dlg_uac((partition->ping_from.len?
&partition->ping_from:
&ds_ping_from),
&pack->params.uri, NULL, NULL,
pack->sock?pack->sock:probing_sock,
&dlg) != 0 ) {
Expand All @@ -2787,7 +2789,9 @@ void ds_check_timer(unsigned int ticks, void* param)
dlg->avps = pack->avps;
pack->avps = NULL;

if (tmb.t_request_within(&ds_ping_method,
if (tmb.t_request_within((partition->ping_method.len?
&partition->ping_method:
&ds_ping_method),
NULL,
NULL,
dlg,
Expand Down
2 changes: 2 additions & 0 deletions modules/dispatcher/dispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ typedef struct _ds_partition
str name; /* Partition name */
str table_name; /* Table name */
str db_url; /* DB url */
str ping_from;
str ping_method;
int persistent_state;

db_con_t **db_handle;
Expand Down
20 changes: 19 additions & 1 deletion modules/dispatcher/dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ typedef struct _ds_db_head
str attrs_avp;
str script_attrs_avp;

str ping_from;
str ping_method;
str persistent_state;

struct _ds_db_head *next;
Expand All @@ -106,14 +108,17 @@ ds_db_head_t default_db_head = {
{NULL, -1},
{NULL, -1},


{NULL, -1},
{NULL, -1},
{NULL, -1},
{NULL, -1},
{NULL, -1},
{NULL, -1},

{NULL, -1},
{NULL, -1},
{"1", 1},

NULL
};
ds_db_head_t *ds_db_heads = NULL;
Expand Down Expand Up @@ -412,6 +417,8 @@ DEF_GETTER_FUNC(cnt_avp);
DEF_GETTER_FUNC(sock_avp);
DEF_GETTER_FUNC(attrs_avp);
DEF_GETTER_FUNC(script_attrs_avp);
DEF_GETTER_FUNC(ping_from);
DEF_GETTER_FUNC(ping_method);
DEF_GETTER_FUNC(persistent_state);

static partition_specific_param_t partition_params[] = {
Expand All @@ -423,6 +430,8 @@ static partition_specific_param_t partition_params[] = {
PARTITION_SPECIFIC_PARAM (sock_avp, "$avp(ds_sock_failover)"),
PARTITION_SPECIFIC_PARAM (attrs_avp, ""),
PARTITION_SPECIFIC_PARAM (script_attrs_avp, ""),
PARTITION_SPECIFIC_PARAM (ping_from, ""),
PARTITION_SPECIFIC_PARAM (ping_method, ""),
PARTITION_SPECIFIC_PARAM (persistent_state, "1"),
};

Expand Down Expand Up @@ -740,6 +749,15 @@ static int partition_init(ds_db_head_t *db_head, ds_partition_t *partition)
partition->script_attrs_avp_name = -1;
partition->script_attrs_avp_type = 0;
}

if (db_head->ping_from.s && db_head->ping_from.len > 0) {
if (pkg_str_dup(&partition->ping_from, &db_head->ping_from) < 0)
LM_ERR("cannot duplicate ping_from\n");
}
if (db_head->ping_method.s && db_head->ping_method.len > 0) {
if (pkg_str_dup(&partition->ping_method, &db_head->ping_method) < 0)
LM_ERR("cannot duplicate ping_method\n");
}
partition->persistent_state = ds_persistent_state;
if (str_strcmp(&db_head->persistent_state, const_str("0")) ||
str_strcmp(&db_head->persistent_state, const_str("no")) ||
Expand Down
14 changes: 11 additions & 3 deletions modules/dispatcher/doc/dispatcher_admin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
Starting with version 2.1, the dispatcher module keeps its destination sets
into different partitions. Each partition is described by its own
"db_url", "table_name", "dst_avp", "grp_avp", "cnt_avp", "sock_avp",
"attr_avp", "blacklists" and "persistent_state" set of attributes.
Setting any of these module parameters will only alter the "default"
partition's properties.
"attr_avp", "blacklists", "ping_from", "ping_method" and
"persistent_state" set of attributes. Setting any of these
module parameters will only alter the "default" partition's properties.
</para>
<para>
In order to create a new partition, the <xref linkend="param_partition"/>
Expand Down Expand Up @@ -275,6 +275,10 @@ modparam("dispatcher", "setid_pvar", "$var(setid)")
the probing of failed gateways enabled.
</para>
<para>
Use the 'partition' parameter if you want to define the ping method
other partitions.
</para>
<para>
<emphasis>
Default value is <quote>OPTIONS</quote>.
</emphasis>
Expand All @@ -297,6 +301,10 @@ modparam("dispatcher", "ds_ping_method", "INFO")
compiled with the probing of failed gateways enabled.
</para>
<para>
Use the 'partition' parameter if you want to define the "From:"
ping header of other partitions.
</para>
<para>
<emphasis>
Default value is <quote>sip:dispatcher@localhost</quote>.
</emphasis>
Expand Down

0 comments on commit 695f666

Please sign in to comment.