Mercurial > hg > freeDiameter
comparison extensions/rt_default/rtd_rules.c @ 1336:cec0812038bb
rt_default: add reload support.
When SIGUSR1 is sent to the freeDiameter process, rt_default reloads
its config file.
Written for Effortel Technologies SA, published with their consent.
author | Thomas Klausner <tk@giga.or.at> |
---|---|
date | Tue, 09 Apr 2019 15:46:50 +0200 |
parents | f5e9b53d6f86 |
children | 566bb46cc73f |
comparison
equal
deleted
inserted
replaced
1335:870eecffa3fe | 1336:cec0812038bb |
---|---|
44 * - first, the TARGETS defined with a regular expression. We will try matching all regexp to all candidates in the list. | 44 * - first, the TARGETS defined with a regular expression. We will try matching all regexp to all candidates in the list. |
45 * - then, the TARGETS defined by a plain text. We don't have to compare the whole list to each candidate since the list is ordered. | 45 * - then, the TARGETS defined by a plain text. We don't have to compare the whole list to each candidate since the list is ordered. |
46 * | 46 * |
47 * Under each TARGET element, we have the list of RULES that are defined for this target, ordered by CRITERIA type, then is_regex, then string value. | 47 * Under each TARGET element, we have the list of RULES that are defined for this target, ordered by CRITERIA type, then is_regex, then string value. |
48 * | 48 * |
49 * Note: Except during configuration parsing and module termination, the lists are only ever accessed read-only, so we do not need a lock. | 49 * Note: Access these only when holding rtd_lock; config reload may change the underlying data. |
50 */ | 50 */ |
51 | 51 |
52 /* Structure to hold the data that is used for matching. */ | 52 /* Structure to hold the data that is used for matching. */ |
53 struct match_data { | 53 struct match_data { |
54 int is_regex; /* determines how the string is matched */ | 54 int is_regex; /* determines how the string is matched */ |
387 } | 387 } |
388 | 388 |
389 return 0; | 389 return 0; |
390 } | 390 } |
391 | 391 |
392 /* Destroy the module's data */ | 392 static void free_targets(void) |
393 void rtd_fini(void) | |
394 { | 393 { |
395 int i; | 394 int i; |
396 | |
397 TRACE_ENTRY(); | |
398 | 395 |
399 for (i = 0; i < RTD_TAR_MAX; i++) { | 396 for (i = 0; i < RTD_TAR_MAX; i++) { |
400 while (!FD_IS_LIST_EMPTY(&TARGETS[i])) { | 397 while (!FD_IS_LIST_EMPTY(&TARGETS[i])) { |
401 del_target((struct target *) TARGETS[i].next); | 398 del_target((struct target *) TARGETS[i].next); |
402 } | 399 } |
403 } | 400 } |
404 | 401 } |
402 | |
403 /* Destroy the module's data */ | |
404 void rtd_fini(void) | |
405 { | |
406 TRACE_ENTRY(); | |
407 | |
408 free_targets(); | |
405 } | 409 } |
406 | 410 |
407 /* Add a new rule in the repository. this is called when the configuration file is being parsed */ | 411 /* Add a new rule in the repository. this is called when the configuration file is being parsed */ |
408 int rtd_add(enum rtd_crit_type ct, char * criteria, enum rtd_targ_type tt, char * target, int score, int flags) | 412 int rtd_add(enum rtd_crit_type ct, char * criteria, enum rtd_targ_type tt, char * target, int score, int flags) |
409 { | 413 { |
490 fd_list_insert_before( rule_suiv, &rul->chain ); | 494 fd_list_insert_before( rule_suiv, &rul->chain ); |
491 } | 495 } |
492 } | 496 } |
493 | 497 |
494 return 0; | 498 return 0; |
499 } | |
500 | |
501 void rtd_conf_reload(char *config_file) | |
502 { | |
503 /* save old config in case reload goes wrong */ | |
504 struct fd_list old_config[RTD_TAR_MAX]; | |
505 int i; | |
506 | |
507 for (i = 0; i < RTD_TAR_MAX; i++) { | |
508 old_config[i] = TARGETS[i]; | |
509 } | |
510 memset(TARGETS, 0, sizeof(*TARGETS) * RTD_TAR_MAX); | |
511 for (i = 0; i < RTD_TAR_MAX; i++) { | |
512 fd_list_init(&TARGETS[i], NULL); | |
513 } | |
514 | |
515 if (rtd_conf_handle(config_file) != 0) { | |
516 fd_log_notice("rt_default: error reloading configuration, restoring previous configuration"); | |
517 free_targets(); | |
518 for (i = 0; i < RTD_TAR_MAX; i++) { | |
519 TARGETS[i] = old_config[i]; | |
520 } | |
521 } else { | |
522 /* this has to be done in this weird way because the items contain back pointers referencing TARGETS */ | |
523 struct fd_list save_config[RTD_TAR_MAX]; | |
524 for (i = 0; i < RTD_TAR_MAX; i++) { | |
525 save_config[i] = TARGETS[i]; | |
526 TARGETS[i] = old_config[i]; | |
527 } | |
528 free_targets(); | |
529 for (i = 0; i < RTD_TAR_MAX; i++) { | |
530 TARGETS[i] = save_config[i]; | |
531 } | |
532 } | |
495 } | 533 } |
496 | 534 |
497 /* Check if a message and list of eligible candidate match any of our rules, and update its score according to it. */ | 535 /* Check if a message and list of eligible candidate match any of our rules, and update its score according to it. */ |
498 int rtd_process( struct msg * msg, struct fd_list * candidates ) | 536 int rtd_process( struct msg * msg, struct fd_list * candidates ) |
499 { | 537 { |