Skip to content

Commit

Permalink
Add generate_data_md5 param
Browse files Browse the repository at this point in the history
  • Loading branch information
vladpaiu committed Feb 23, 2024
1 parent d0f238c commit ee6ff95
Show file tree
Hide file tree
Showing 8 changed files with 219 additions and 47 deletions.
77 changes: 45 additions & 32 deletions modules/drouting/README
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Dynamic Routing Module
1.3.36. extra_prefix_chars (str)
1.3.37. extra_id_chars (str)
1.3.38. rule_tables_query (str)
1.3.39. generate_data_md5 (int)

1.4. Exported Functions

Expand Down Expand Up @@ -168,22 +169,23 @@ Dynamic Routing Module
1.36. Set extra_prefix_chars parameter
1.37. Set extra_id_chars parameter
1.38. Set the rule_tables_query parameter
1.39. do_routing usage
1.40. route_to_carrier usage
1.41. route_to_gw usage
1.42. use_next_gw usage
1.43. goes_to_gw usage
1.44. is_from_gw usage
1.45. dr_is_gw usage
1.46. dr_disable() usage
1.47. dr_match usage
1.48. dr_gw_status usage when use_partitions is set to 0
1.49. dr_gw_status usage when use_partitionsis set to 1
1.50. dr_carrier_status usage when use_partitions is 0
1.51. dr_carrier_status usage when use_partitions is 1
1.52. dr_reload_status usage when use_partitions is 0
1.53. dr_reload_status usage when use_partitions is 1
1.54. dr_enable_probing usage
1.39. Set the generate_data_md5 parameter
1.40. do_routing usage
1.41. route_to_carrier usage
1.42. route_to_gw usage
1.43. use_next_gw usage
1.44. goes_to_gw usage
1.45. is_from_gw usage
1.46. dr_is_gw usage
1.47. dr_disable() usage
1.48. dr_match usage
1.49. dr_gw_status usage when use_partitions is set to 0
1.50. dr_gw_status usage when use_partitionsis set to 1
1.51. dr_carrier_status usage when use_partitions is 0
1.52. dr_carrier_status usage when use_partitions is 1
1.53. dr_reload_status usage when use_partitions is 0
1.54. dr_reload_status usage when use_partitions is 1
1.55. dr_enable_probing usage

Chapter 1. Admin Guide

Expand Down Expand Up @@ -1072,6 +1074,17 @@ modparam("drouting", "rule_tables_query", "
SELECT 'dr_rules_a' UNION SELECT 'dr_rules_b'")
...

1.3.39. generate_data_md5 (int)

If enabled, it will generate MD5 hashes for drouting data,
attach that to the reload_status MI command output and to the
reload generated status reports

Example 1.39. Set the generate_data_md5 parameter
...
modparam("drouting", "generate_data_md5", 1)
...

1.4. Exported Functions

1.4.1. do_routing([groupID], [flags], [gw_whitelist],
Expand Down Expand Up @@ -1126,7 +1139,7 @@ modparam("drouting", "rule_tables_query", "
specifing the name of one partition, you can use the "*"
wildcard sign to force routing over all partitions.

Example 1.39. do_routing usage
Example 1.40. do_routing usage
...
# all groups, sort on order, use_partitions is 0
do_routing();
Expand Down Expand Up @@ -1182,7 +1195,7 @@ do_routing(2, "F", , , $var(gw_attributes));
"use_partition" module parameter is turned on. Wildcard
sign is not accepted by the function.

Example 1.40. route_to_carrier usage
Example 1.41. route_to_carrier usage
...
# use_partitions is not set
if ( route_to_carrier("my_top_carrier, def_carrier", , $var(carrier_att)
Expand Down Expand Up @@ -1237,7 +1250,7 @@ if ( route_to_carrier($var(carrierId), , , $var(my_partition)) ) {
"use_partition" module parameter is turned on. Wildcard
sign is not accepted by the function.

Example 1.41. route_to_gw usage
Example 1.42. route_to_gw usage
...
# use_partitions is not set
if ( route_to_gw("gw_europe") ) {
Expand Down Expand Up @@ -1303,7 +1316,7 @@ if ( route_to_gw("gw1,gw2,gw3", $var(gw_attrs), , "my_partition") ) {
"use_partition" module parameter is turned on. Wildcard
sign is not accepted by the function.

Example 1.42. use_next_gw usage
Example 1.43. use_next_gw usage
...
# use_partitions is not set
if (use_next_gw()) {
Expand Down Expand Up @@ -1380,7 +1393,7 @@ if (use_next_gw( , ,$var(carrier_attrs), "my_partition")) {
"use_partition" module parameter is turned on. Wildcard
sign is accepted by this function.

Example 1.43. goes_to_gw usage
Example 1.44. goes_to_gw usage
...
# use_partitions is not set
if (goes_to_gw( 1, , $var(gw_attrs))) {
Expand Down Expand Up @@ -1440,7 +1453,7 @@ if (goes_to_gw(1, , $var(gw_attrs), , "my_partition")) {
"use_partition" module parameter is turned on. Wildcard
sign is accepted by this function.

Example 1.44. is_from_gw usage
Example 1.45. is_from_gw usage
# use_partitions is not set
# match the source IP (only) against all gateways
if (is_from_gw(-1, "n")) {
Expand Down Expand Up @@ -1499,7 +1512,7 @@ if (is_from_gw(, "c", , , "outbound")) {
"use_partition" module parameter is turned on. Wildcard
sign is accepted by this function.

Example 1.45. dr_is_gw usage
Example 1.46. dr_is_gw usage
# match the SIP URI host within $var(uac) against all gateways
if (dr_is_gw( $var(uac), , "n")) {
...
Expand Down Expand Up @@ -1533,7 +1546,7 @@ if (dr_is_gw( $avp(uac), , "n", , , "partition")) {
"use_partition" module parameter is turned on. Wildcard
sign is accepted by this function.

Example 1.46. dr_disable() usage
Example 1.47. dr_disable() usage
...
if (t_check_status("(408)|(5[0-9][0-9])")) {
dr_disable();
Expand Down Expand Up @@ -1575,7 +1588,7 @@ if (t_check_status("(408)|(5[0-9][0-9])")) {
to be used. This parameter is to be defined ONLY if the
"use_partition" module parameter is turned on.

Example 1.47. dr_match usage
Example 1.48. dr_match usage
...
if ( dr_match( 1, "L" , $fU, ,"dids") )
xlog("Full From Username $fU found in group 1 partition DIDS\n")
Expand Down Expand Up @@ -1635,7 +1648,7 @@ if ( dr_match( 1, , $var(did) ) )
GW (0 - disable, 1 - enable). Only makes sense if
gw_id is provided.

Example 1.48. dr_gw_status usage when use_partitions is set to
Example 1.49. dr_gw_status usage when use_partitions is set to
0
$ opensips-cli -x mi dr_gw_status gw_id=2
State:: Active
Expand All @@ -1645,7 +1658,7 @@ Enabled:: Disabled MI
$ opensips-cli -x mi dr_gw_status gw_id=3
Enabled:: Inactive

Example 1.49. dr_gw_status usage when use_partitionsis set to 1
Example 1.50. dr_gw_status usage when use_partitionsis set to 1
$ opensips-cli -x mi dr_gw_status partition_name=part_1 gw_id=my_gw
State:: Active
$ opensips-cli -x mi dr_gw_status partition_name=part_1 gw_id=my_gw stat
Expand Down Expand Up @@ -1680,14 +1693,14 @@ enabled:: inactive
carrier (0 - disable, 1 - enable). Only makes sense if
carrier_id is provided.

Example 1.50. dr_carrier_status usage when use_partitions is 0
Example 1.51. dr_carrier_status usage when use_partitions is 0
$ opensips-cli -x mi dr_carrier_status carrier_id=CR1
Enabled:: no
$ opensips-cli -x mi dr_carrier_status carrier_id=CR1 status=1
$ opensips-cli -x mi dr_carrier_status carrier_id=CR1
Enabled:: yes

Example 1.51. dr_carrier_status usage when use_partitions is 1
Example 1.52. dr_carrier_status usage when use_partitions is 1
$ opensips-cli -x mi dr_carrier_status partition_name=my_partition carri
er_id=CR1
Enabled:: no
Expand All @@ -1709,11 +1722,11 @@ Enabled:: yes
every partition. Otherwise, the function will list the
time of the last reload for the given partition.

Example 1.52. dr_reload_status usage when use_partitions is 0
Example 1.53. dr_reload_status usage when use_partitions is 0
$ opensips-cli -x mi dr_reload_status
Date:: Tue Aug 12 12:26:00 2014

Example 1.53. dr_reload_status usage when use_partitions is 1
Example 1.54. dr_reload_status usage when use_partitions is 1
$ opensips-cli -x mi dr_reload_status
Partition:: part_test Date=Tue Aug 12 12:24:13 2014
Partition:: part_2 Date=Tue Aug 12 12:24:13 2014
Expand Down Expand Up @@ -1749,7 +1762,7 @@ Partition:: part_test Date=Tue Aug 12 12:24:13 2014
Parameters:
* status (optional) - 1 - enable, 0 - disable gateway probing

Example 1.54. dr_enable_probing usage
Example 1.55. dr_enable_probing usage
$ opensips-cli -x mi dr_enable_probing
Status:: 1
$ opensips-cli -x mi dr_enable_probing 0
Expand Down
15 changes: 15 additions & 0 deletions modules/drouting/doc/drouting_admin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1412,6 +1412,21 @@ modparam("drouting", "rule_tables_query", "
</example>
</section>

<section id="param_generate_data_md5" xreflabel="generate_data_md5">
<title><varname>generate_data_md5</varname> (int)</title>
<para>
If enabled, it will generate MD5 hashes for drouting data, attach that to the reload_status MI command output and to the reload generated status reports
</para>
<example>
<title>Set the <varname>generate_data_md5</varname> parameter</title>
<programlisting format="linespecific">
...
modparam("drouting", "generate_data_md5", 1)
...
</programlisting>
</example>
</section>

</section>

<section id="exported_functions" xreflabel="exported_functions">
Expand Down
38 changes: 33 additions & 5 deletions modules/drouting/dr_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,32 @@ int dr_set_gw_sock_filter_mode(char *mode)
return -1;
}

void hash_rule(char* grplst, str* prefix, rt_info_t* rule, MD5_CTX* hash_ctx)
{
int i;

if (hash_ctx == NULL)
return;

MD5Update(hash_ctx, grplst, strlen(grplst));
if (prefix->s && prefix->len)
MD5Update(hash_ctx, prefix->s, prefix->len);

MD5Update(hash_ctx, (char *)&rule->priority, sizeof(rule->priority));
if (rule->attrs.s && rule->attrs.len)
MD5Update(hash_ctx, rule->attrs.s, rule->attrs.len);
MD5Update(hash_ctx, (char *)rule->sort_alg, sizeof(rule->sort_alg));

for (i=0;i<rule->pgwa_len;i++) {
if (rule->pgwl[i].is_carrier == 1)
hash_carrier(rule->pgwl[i].dst.carrier,hash_ctx);
else
hash_dst(rule->pgwl[i].dst.gw,hash_ctx);
}
}

static int add_rule(rt_data_t *rdata, char *grplst, str *prefix,
rt_info_t *rule, osips_malloc_f malloc_f, osips_free_f free_f)
rt_info_t *rule, osips_malloc_f malloc_f, osips_free_f free_f,MD5_CTX* hash_ctx)
{
long int t;
char *tmp;
Expand Down Expand Up @@ -164,6 +188,8 @@ static int add_rule(rt_data_t *rdata, char *grplst, str *prefix,
goto error;
}

hash_rule(grplst,prefix,rule,hash_ctx);

return 0;
error:
return -1;
Expand Down Expand Up @@ -283,7 +309,7 @@ void dr_update_head_cache(struct head_db *head)
extern struct custom_rule_table *custom_rule_tables;

rt_data_t* dr_load_routing_info(struct head_db *part,
int persistent_state, str *rules_tables, int rules_tables_no)
int persistent_state, str *rules_tables, int rules_tables_no,MD5_CTX* hash_ctx)
{
int int_vals[5];
char * str_vals[7];
Expand Down Expand Up @@ -453,7 +479,8 @@ rt_data_t* dr_load_routing_info(struct head_db *part,
sock,
int_vals[INT_VALS_STATE_DRD_COL],
part->malloc,
part->free )<0 ) {
part->free,
hash_ctx )<0 ) {
LM_ERR("failed to add destination <%s>(%s) -> skipping\n",
str_vals[STR_VALS_GWID_DRD_COL],
str_vals[STR_VALS_ID_DRD_COL]);
Expand Down Expand Up @@ -575,7 +602,8 @@ rt_data_t* dr_load_routing_info(struct head_db *part,
str_vals[STR_VALS_ATTRS_DRC_COL],
int_vals[INT_VALS_STATE_DRC_COL], rdata,
part->malloc,
part->free) != 0 ) {
part->free,
hash_ctx) != 0 ) {
LM_ERR("failed to add carrier db_id <%s> -> skipping\n",
str_vals[STR_VALS_ID_DRC_COL]);
discarded_cr++;
Expand Down Expand Up @@ -724,7 +752,7 @@ rt_data_t* dr_load_routing_info(struct head_db *part,
}
/* add the rule */
if (add_rule(rdata, str_vals[STR_VALS_GROUP_DRR_COL], &tmp, ri,
part->malloc, part->free)!=0) {
part->malloc, part->free,hash_ctx)!=0) {
LM_ERR("failed to add rule id %d -> skipping\n",
int_vals[INT_VALS_RULE_ID_DRR_COL]);
free_rt_info(ri, part->free);
Expand Down
2 changes: 1 addition & 1 deletion modules/drouting/dr_load.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ int dr_set_gw_sock_filter_mode(char *mode);
void dr_update_head_cache(struct head_db *head);

rt_data_t* dr_load_routing_info(struct head_db *current_partition,
int persistent_state, str *rules_tables, int rules_no);
int persistent_state, str *rules_tables, int rules_no, MD5_CTX *hash_ctx);

#endif
9 changes: 9 additions & 0 deletions modules/drouting/dr_partitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,18 @@
#include "../../parser/parse_uri.h"
#include "../../mi/mi.h"
#include "../tm/tm_load.h"
#include "../../md5global.h"
#include "../../md5.h"

extern int use_partitions;
extern rw_lock_t *reload_lock;

#define HASHLEN 16
typedef char HASH[HASHLEN];

#define HASHHEXLEN 32
typedef char HASHHEX[HASHHEXLEN+1];

struct head_db {
str db_url;
str partition;
Expand Down Expand Up @@ -74,6 +82,7 @@ struct head_db {
int carrier_attrs_avp;
int restart_persistent;
rt_data_t *rdata;
HASHHEX md5;
rw_lock_t *ref_lock;
int ongoing_reload;
struct head_db *next;
Expand Down

0 comments on commit ee6ff95

Please sign in to comment.