From 1d6496a0a27737270473713c44a43e856bba2a40 Mon Sep 17 00:00:00 2001 From: Norm Brandinger Date: Fri, 22 Nov 2024 21:04:01 -0500 Subject: [PATCH 1/3] dispatcher: Add ping_sock as a partition parameter --- modules/dispatcher/README | 37 ++++++++++++++++++++++++++++++--- modules/dispatcher/dispatch.c | 4 +++- modules/dispatcher/dispatch.h | 3 +++ modules/dispatcher/dispatcher.c | 23 +++++++++++++++++++- 4 files changed, 62 insertions(+), 5 deletions(-) diff --git a/modules/dispatcher/README b/modules/dispatcher/README index 41ff632a308..83aca1cbb73 100644 --- a/modules/dispatcher/README +++ b/modules/dispatcher/README @@ -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 @@ -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", + "prioxies: + 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 diff --git a/modules/dispatcher/dispatch.c b/modules/dispatcher/dispatch.c index 76643227825..552ecaae5c7 100644 --- a/modules/dispatcher/dispatch.c +++ b/modules/dispatcher/dispatch.c @@ -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; diff --git a/modules/dispatcher/dispatch.h b/modules/dispatcher/dispatch.h index 7e746921ce2..f470941ac5f 100644 --- a/modules/dispatcher/dispatch.h +++ b/modules/dispatcher/dispatch.h @@ -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 */ diff --git a/modules/dispatcher/dispatcher.c b/modules/dispatcher/dispatcher.c index 789ff837c21..1d7e0f6972d 100644 --- a/modules/dispatcher/dispatcher.c +++ b/modules/dispatcher/dispatcher.c @@ -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; @@ -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; @@ -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)}, @@ -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) / @@ -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; } @@ -759,6 +767,19 @@ 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"); + + partition->ping_sock_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")) || From df9bb26a98e7f6dc0b5745e213e5a4c8b0751413 Mon Sep 17 00:00:00 2001 From: Norm Brandinger Date: Fri, 22 Nov 2024 21:43:44 -0500 Subject: [PATCH 2/3] Return -1 in the case of a failure to create the socket --- modules/dispatcher/README | 2 +- modules/dispatcher/dispatcher.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/dispatcher/README b/modules/dispatcher/README index 83aca1cbb73..fa580ce1f52 100644 --- a/modules/dispatcher/README +++ b/modules/dispatcher/README @@ -769,7 +769,7 @@ modparam("dispatcher", "partition", ping_sock = udp:public_ip:public_port") modparam("dispatcher", "partition", - "prioxies: + "proxies: db_url = mysql://user:passwd@localhost/database; table_name = proxies; ping_sock = udp:private_ip:private_port") diff --git a/modules/dispatcher/dispatcher.c b/modules/dispatcher/dispatcher.c index 1d7e0f6972d..10f9bd855d2 100644 --- a/modules/dispatcher/dispatcher.c +++ b/modules/dispatcher/dispatcher.c @@ -769,9 +769,10 @@ static int partition_init(ds_db_head_t *db_head, ds_partition_t *partition) } if (db_head->ping_sock.s && db_head->ping_sock.len > 0) { - if (pkg_str_dup(&partition->ping_sock, &db_head->ping_sock) < 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 = parse_sock_info(&partition->ping_sock); if (partition->ping_sock_info==NULL) { LM_ERR("socket <%.*s> is not local to opensips (we must listen " From a8c885cf354e9c5edc8803903b78437527821064 Mon Sep 17 00:00:00 2001 From: Norm Brandinger Date: Mon, 25 Nov 2024 16:02:26 -0500 Subject: [PATCH 3/3] Cast parse_sock_info() into (struct socket_info *) --- modules/dispatcher/dispatcher.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/dispatcher/dispatcher.c b/modules/dispatcher/dispatcher.c index 10f9bd855d2..ae9fd6a81e6 100644 --- a/modules/dispatcher/dispatcher.c +++ b/modules/dispatcher/dispatcher.c @@ -773,7 +773,7 @@ static int partition_init(ds_db_head_t *db_head, ds_partition_t *partition) LM_ERR("cannot duplicate ping_sock\n"); return -1; } - partition->ping_sock_info = parse_sock_info(&partition->ping_sock); + 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);