Skip to content

Commit 91c523c

Browse files
authored
Merge pull request #3527 from NormB/master
dispatcher: Add ping_sock as a partition parameter
2 parents 1e46a4b + a8c885c commit 91c523c

File tree

4 files changed

+63
-5
lines changed

4 files changed

+63
-5
lines changed

modules/dispatcher/README

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -710,10 +710,24 @@ modparam("dispatcher", "cluster_probing_mode", "distributed")
710710
1.3.26. partition (string)
711711

712712
Define a new partition (data source) with the following
713-
properties: "db_url", "table_name", "dst_avp", "grp_avp",
713+
properties:
714+
715+
"db_url", "table_name", "dst_avp", "grp_avp",
714716
"cnt_avp", "sock_avp", "attrs_avp", "script_attrs",
715-
"ds_define_blacklist". All these properties are optional,
716-
having appropriate default values.
717+
"ds_define_blacklist", "ping_sock"
718+
719+
All these properties are optional, having appropriate default values.
720+
721+
If the OpenSIPS server has multiple interfaces the "ping_sock" can be
722+
used to specify the interface to be used for sending pings.
723+
724+
For example, a server acting as an SBC may have a public and a private interface.
725+
There can be two partitions defined, one for carriers and the other for proxies.
726+
Using the "ping_sock" parameter, the server can send pings to the carriers over
727+
the public interface and to the proxies over the private interface. Additional
728+
value can be realized when multiple SBCs are able to use the same carriers and
729+
proxies tables. In this case, each SBC can use its own public and private
730+
interfaces to send pings to the carriers and proxies.
717731

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

761+
Example 1.29. Define the 'carriers' and 'proxies' partitions
762+
using the 'ping_sock' to specify which interface is to be used
763+
to send pings.
764+
...
765+
modparam("dispatcher", "partition",
766+
"carriers:
767+
db_url = mysql://user:passwd@localhost/database;
768+
table_name = carriers;
769+
ping_sock = udp:public_ip:public_port")
770+
771+
modparam("dispatcher", "partition",
772+
"proxies:
773+
db_url = mysql://user:passwd@localhost/database;
774+
table_name = proxies;
775+
ping_sock = udp:private_ip:private_port")
776+
...
777+
747778
1.3.27. table_name (string)
748779

749780
The default name of the table from which to load dispatcher

modules/dispatcher/dispatch.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2781,7 +2781,9 @@ void ds_check_timer(unsigned int ticks, void* param)
27812781
&partition->ping_from:
27822782
&ds_ping_from),
27832783
&pack->params.uri, NULL, NULL,
2784-
pack->sock?pack->sock:probing_sock,
2784+
pack->sock?pack->sock:(partition->ping_sock.len?
2785+
partition->ping_sock_info:
2786+
probing_sock),
27852787
&dlg) != 0 ) {
27862788
LM_ERR("failed to create new TM dlg\n");
27872789
continue;

modules/dispatcher/dispatch.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ typedef struct _ds_partition
119119
str ping_method;
120120
int persistent_state;
121121

122+
str ping_sock;
123+
struct socket_info *ping_sock_info;
124+
122125
db_con_t **db_handle;
123126
db_func_t dbf;
124127
ds_data_t **data; /* dispatching data holder */

modules/dispatcher/dispatcher.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ typedef struct _ds_db_head
9999
str ping_method;
100100
str persistent_state;
101101

102+
str ping_sock;
103+
struct socket_info *ping_sock_info;
104+
102105
struct _ds_db_head *next;
103106
} ds_db_head_t;
104107

@@ -119,6 +122,9 @@ ds_db_head_t default_db_head = {
119122
{NULL, -1},
120123
{"1", 1},
121124

125+
{NULL, -1},
126+
NULL,
127+
122128
NULL
123129
};
124130
ds_db_head_t *ds_db_heads = NULL;
@@ -420,6 +426,7 @@ DEF_GETTER_FUNC(script_attrs_avp);
420426
DEF_GETTER_FUNC(ping_from);
421427
DEF_GETTER_FUNC(ping_method);
422428
DEF_GETTER_FUNC(persistent_state);
429+
DEF_GETTER_FUNC(ping_sock);
423430

424431
static partition_specific_param_t partition_params[] = {
425432
{str_init("db_url"), {NULL, 0}, GETTER_FUNC(db_url)},
@@ -433,6 +440,7 @@ static partition_specific_param_t partition_params[] = {
433440
PARTITION_SPECIFIC_PARAM (ping_from, ""),
434441
PARTITION_SPECIFIC_PARAM (ping_method, ""),
435442
PARTITION_SPECIFIC_PARAM (persistent_state, "1"),
443+
PARTITION_SPECIFIC_PARAM (ping_sock, ""),
436444
};
437445

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

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

@@ -759,6 +767,20 @@ static int partition_init(ds_db_head_t *db_head, ds_partition_t *partition)
759767
if (pkg_str_dup(&partition->ping_method, &db_head->ping_method) < 0)
760768
LM_ERR("cannot duplicate ping_method\n");
761769
}
770+
771+
if (db_head->ping_sock.s && db_head->ping_sock.len > 0) {
772+
if (pkg_str_dup(&partition->ping_sock, &db_head->ping_sock) < 0) {
773+
LM_ERR("cannot duplicate ping_sock\n");
774+
return -1;
775+
}
776+
partition->ping_sock_info = (struct socket_info *)parse_sock_info(&partition->ping_sock);
777+
if (partition->ping_sock_info==NULL) {
778+
LM_ERR("socket <%.*s> is not local to opensips (we must listen "
779+
"on it\n", partition->ping_sock.len, partition->ping_sock.s);
780+
return -1;
781+
}
782+
}
783+
762784
partition->persistent_state = ds_persistent_state;
763785
if (str_strcmp(&db_head->persistent_state, const_str("0")) ||
764786
str_strcmp(&db_head->persistent_state, const_str("no")) ||

0 commit comments

Comments
 (0)