Skip to content

Commit

Permalink
Merge pull request #3527 from NormB/master
Browse files Browse the repository at this point in the history
dispatcher: Add ping_sock as a partition parameter
  • Loading branch information
liviuchircu authored Nov 26, 2024
2 parents 1e46a4b + a8c885c commit 91c523c
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 5 deletions.
37 changes: 34 additions & 3 deletions modules/dispatcher/README
Original file line number Diff line number Diff line change
Expand Up @@ -710,10 +710,24 @@ modparam("dispatcher", "cluster_probing_mode", "distributed")
1.3.26. partition (string)

Define a new partition (data source) with the following
properties: "db_url", "table_name", "dst_avp", "grp_avp",
properties:

"db_url", "table_name", "dst_avp", "grp_avp",
"cnt_avp", "sock_avp", "attrs_avp", "script_attrs",
"ds_define_blacklist". All these properties are optional,
having appropriate default values.
"ds_define_blacklist", "ping_sock"

All these properties are optional, having appropriate default values.

If the OpenSIPS server has multiple interfaces the "ping_sock" can be
used to specify the interface to be used for sending pings.

For example, a server acting as an SBC may have a public and a private interface.
There can be two partitions defined, one for carriers and the other for proxies.
Using the "ping_sock" parameter, the server can send pings to the carriers over
the public interface and to the proxies over the private interface. Additional
value can be realized when multiple SBCs are able to use the same carriers and
proxies tables. In this case, each SBC can use its own public and private
interfaces to send pings to the carriers and proxies.

The syntax is: "partition_name: param1 = value1; param2 =
value2". Each value format is the same as the one used to
Expand Down Expand Up @@ -744,6 +758,23 @@ modparam("dispatcher", "partition",
modparam("dispatcher", "partition", "default: trunks")
...

Example 1.29. Define the 'carriers' and 'proxies' partitions
using the 'ping_sock' to specify which interface is to be used
to send pings.
...
modparam("dispatcher", "partition",
"carriers:
db_url = mysql://user:passwd@localhost/database;
table_name = carriers;
ping_sock = udp:public_ip:public_port")

modparam("dispatcher", "partition",
"proxies:
db_url = mysql://user:passwd@localhost/database;
table_name = proxies;
ping_sock = udp:private_ip:private_port")
...

1.3.27. table_name (string)

The default name of the table from which to load dispatcher
Expand Down
4 changes: 3 additions & 1 deletion modules/dispatcher/dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -2781,7 +2781,9 @@ void ds_check_timer(unsigned int ticks, void* param)
&partition->ping_from:
&ds_ping_from),
&pack->params.uri, NULL, NULL,
pack->sock?pack->sock:probing_sock,
pack->sock?pack->sock:(partition->ping_sock.len?
partition->ping_sock_info:
probing_sock),
&dlg) != 0 ) {
LM_ERR("failed to create new TM dlg\n");
continue;
Expand Down
3 changes: 3 additions & 0 deletions modules/dispatcher/dispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ typedef struct _ds_partition
str ping_method;
int persistent_state;

str ping_sock;
struct socket_info *ping_sock_info;

db_con_t **db_handle;
db_func_t dbf;
ds_data_t **data; /* dispatching data holder */
Expand Down
24 changes: 23 additions & 1 deletion modules/dispatcher/dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ typedef struct _ds_db_head
str ping_method;
str persistent_state;

str ping_sock;
struct socket_info *ping_sock_info;

struct _ds_db_head *next;
} ds_db_head_t;

Expand All @@ -119,6 +122,9 @@ ds_db_head_t default_db_head = {
{NULL, -1},
{"1", 1},

{NULL, -1},
NULL,

NULL
};
ds_db_head_t *ds_db_heads = NULL;
Expand Down Expand Up @@ -420,6 +426,7 @@ DEF_GETTER_FUNC(script_attrs_avp);
DEF_GETTER_FUNC(ping_from);
DEF_GETTER_FUNC(ping_method);
DEF_GETTER_FUNC(persistent_state);
DEF_GETTER_FUNC(ping_sock);

static partition_specific_param_t partition_params[] = {
{str_init("db_url"), {NULL, 0}, GETTER_FUNC(db_url)},
Expand All @@ -433,6 +440,7 @@ static partition_specific_param_t partition_params[] = {
PARTITION_SPECIFIC_PARAM (ping_from, ""),
PARTITION_SPECIFIC_PARAM (ping_method, ""),
PARTITION_SPECIFIC_PARAM (persistent_state, "1"),
PARTITION_SPECIFIC_PARAM (ping_sock, ""),
};

static const unsigned int partition_param_count = sizeof (partition_params) /
Expand Down Expand Up @@ -483,7 +491,7 @@ static int split_partition_argument(str *arg, str *partition_name)
arg->len -= partition_name->len + 1;

trim(partition_name);
for (;arg->s[0] == ' ' && arg->len; ++arg->s, --arg->len);
for (;(arg->s[0] == ' ' || arg->s[0] == '\n') && arg->len; ++arg->s, --arg->len);
return 0;
}

Expand Down Expand Up @@ -759,6 +767,20 @@ static int partition_init(ds_db_head_t *db_head, ds_partition_t *partition)
if (pkg_str_dup(&partition->ping_method, &db_head->ping_method) < 0)
LM_ERR("cannot duplicate ping_method\n");
}

if (db_head->ping_sock.s && db_head->ping_sock.len > 0) {
if (pkg_str_dup(&partition->ping_sock, &db_head->ping_sock) < 0) {
LM_ERR("cannot duplicate ping_sock\n");
return -1;
}
partition->ping_sock_info = (struct socket_info *)parse_sock_info(&partition->ping_sock);
if (partition->ping_sock_info==NULL) {
LM_ERR("socket <%.*s> is not local to opensips (we must listen "
"on it\n", partition->ping_sock.len, partition->ping_sock.s);
return -1;
}
}

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

0 comments on commit 91c523c

Please sign in to comment.