Navigation


Changeset 1387:d70f5f6cb306 in freeDiameter


Ignore:
Timestamp:
Oct 15, 2019, 11:25:47 PM (5 years ago)
Author:
Thomas Klausner <tk@giga.or.at>
Branch:
default
Phase:
public
Message:

rt_ereg: improve logging and locking

Location:
extensions/rt_ereg
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • extensions/rt_ereg/rtereg.c

    r1338 r1387  
    9494                struct fd_list * c;
    9595
    96                 TRACE_DEBUG(ANNOYING, "Attempt pattern matching of '%.*s' with rule '%s'", (int)len, value, r->pattern);
     96                LOG_D("[rt_ereg] attempting pattern matching of '%.*s' with rule '%s'", (int)len, value, r->pattern);
    9797
    9898                #ifdef HAVE_REG_STARTEND
     
    119119
    120120                        /* Error while compiling the regex */
    121                         TRACE_DEBUG(INFO, "Error while executing the regular expression '%s':", r->pattern);
     121                        LOG_E("[rt_ereg] error while executing the regular expression '%s':", r->pattern);
    122122
    123123                        /* Get the error message size */
     
    129129                        /* Get the error message content */
    130130                        regerror(err, &r->preg, errstr, bl);
    131                         TRACE_DEBUG(INFO, "\t%s", errstr);
     131                        LOG_E("\t%s", errstr);
    132132
    133133                        /* Free the buffer, return the error */
     
    138138
    139139                /* From this point, the expression matched the AVP value */
    140                 TRACE_DEBUG(FULL, "[rt_ereg] Match: '%s' to value '%.*s' => '%s' += %d",
    141                                         r->pattern,
    142                                         (int)len,
    143                                         value,
    144                                         r->server,
    145                                         r->score);
     140                LOG_D("[rt_ereg] Match: '%s' to value '%.*s' => '%s' += %d", r->pattern, (int)len, value, r->server, r->score);
    146141
    147142                for (c = candidates->next; c != candidates; c = c->next) {
     
    168163//      for (i = 0; i<rtereg_conf[j].level; i++) {
    169164        if (level > rtereg_conf[conf_index].level) {
    170                 TRACE_DEBUG(INFO, "internal error, dug too deep");
     165                LOG_E("internal error, dug too deep");
    171166                return 1;
    172167        }
     
    179174                if ((avp_hdr->avp_code == dictdata.avp_code) && (avp_hdr->avp_vendor == dictdata.avp_vendor)) {
    180175                        if (level != rtereg_conf[conf_index].level - 1) {
    181                                 TRACE_DEBUG(INFO, "[rt_ereg] found grouped AVP %d (vendor %d), digging deeper", avp_hdr->avp_code, avp_hdr->avp_vendor);
     176                                LOG_D("[rt_ereg] found grouped AVP %d (vendor %d), digging deeper", avp_hdr->avp_code, avp_hdr->avp_vendor);
    182177                                CHECK_FCT(find_avp(nextavp, conf_index, level+1, candidates));
    183178                        } else {
    184                                 TRACE_DEBUG(INFO, "[rt_ereg] found AVP %d (vendor %d)", avp_hdr->avp_code, avp_hdr->avp_vendor);
     179                                struct dictionary * dict;
     180                                LOG_D("[rt_ereg] found AVP %d (vendor %d)", avp_hdr->avp_code, avp_hdr->avp_vendor);
     181                                CHECK_FCT(fd_dict_getdict(what, &dict));
     182                                CHECK_FCT_DO(fd_msg_parse_dict(nextavp, dict, NULL), /* nothing */);
    185183                                if (avp_hdr->avp_value != NULL) {
     184                                        LOG_A("avp_hdr->avp_value NOT NULL, matching");
    186185#ifndef HAVE_REG_STARTEND
    187186                                        int ret;
     
    224223        int j, ret;
    225224
    226         TRACE_ENTRY("%p %p %p", cbdata, *pmsg, candidates);
     225        LOG_A("[rt_ereg] rtereg_out arguments: %p %p %p", cbdata, *pmsg, candidates);
    227226
    228227        CHECK_PARAMS(pmsg && *pmsg && candidates);
     
    239238                for (j=0; j<rtereg_conf_size; j++) {
    240239                        where = *pmsg;
    241                         TRACE_DEBUG(INFO, "[rt_ereg] iterating over AVP group %d", j);
     240                        LOG_D("[rt_ereg] iterating over AVP group %d", j);
    242241                        if ((ret=find_avp(where, j, 0, candidates)) != 0) {
    243242                                break;
     
    302301static int rtereg_entry(char * conffile)
    303302{
    304         TRACE_ENTRY("%p", conffile);
     303        LOG_A("[rt_ereg] started with conffile '%p'", conffile);
    305304
    306305        rt_ereg_config_file = conffile;
    307306
    308307        if (rtereg_init() != 0) {
    309             return 1;
     308                return 1;
    310309        }
    311310
     
    322321        /* Initialize the configuration */
    323322        if ((rtereg_conf=malloc(sizeof(*rtereg_conf))) == NULL) {
    324             TRACE_DEBUG(INFO, "malloc failured");
    325             return 1;
     323                LOG_E("[rt_ereg] malloc failured");
     324                return 1;
    326325        }
    327326        rtereg_conf_size = 1;
     
    367366static void rtereg_fini(void)
    368367{
    369         TRACE_ENTRY();
    370 
    371368        /* Unregister the cb */
    372369        CHECK_FCT_DO( fd_rt_out_unregister ( rtereg_hdl, NULL ), /* continue */ );
    373370
     371#ifndef HAVE_REG_STARTEND
     372        free(buf);
     373        buf = NULL;
     374#endif /* HAVE_REG_STARTEND */
     375
     376        if (pthread_rwlock_wrlock(&rte_lock) != 0) {
     377                fd_log_error("%s: write-locking failed in fini, giving up", MODULE_NAME);
     378                return;
     379        }
    374380        /* Destroy the data */
    375381        rtereg_conf_free(rtereg_conf, rtereg_conf_size);
    376382        rtereg_conf = NULL;
    377383        rtereg_conf_size = 0;
    378 #ifndef HAVE_REG_STARTEND
    379         free(buf);
    380         buf = NULL;
    381 #endif /* HAVE_REG_STARTEND */
     384
     385        if (pthread_rwlock_unlock(&rte_lock) != 0) {
     386                fd_log_error("%s: write-unlocking failed in fini", MODULE_NAME);
     387                return;
     388        }
    382389
    383390        /* Done */
  • extensions/rt_ereg/rtereg_conf.l

    r1127 r1387  
    8181                                CHECK_MALLOC_DO( yylval->string = strdup(yytext+1),
    8282                                {
    83                                         TRACE_DEBUG(INFO, "Unable to copy the string '%s': %s", yytext, strerror(errno));
     83                                        LOG_E("[rt_ereg] unable to copy the string '%s': %s", yytext, strerror(errno));
    8484                                        return LEX_ERROR; /* trig an error in yacc parser */
    8585                                } );
  • extensions/rt_ereg/rtereg_conf.y

    r1342 r1387  
    6262        int ret;
    6363
    64         TRACE_ENTRY("%p", conffile);
    65 
    66         TRACE_DEBUG (FULL, "Parsing configuration file: %s...", conffile);
     64        LOG_D("[rt_ereg] parsing configuration file '%s'", conffile);
    6765
    6866        rtereg_confin = fopen(conffile, "r");
     
    7068                ret = errno;
    7169                fd_log_debug("Unable to open extension configuration file %s for reading: %s", conffile, strerror(ret));
    72                 TRACE_DEBUG (INFO, "rt_ereg: error occurred, message logged -- configuration file.");
     70                LOG_E("[rt_ereg] error occurred, message logged -- configuration file.");
    7371                return ret;
    7472        }
     
    8078
    8179        if (rtereg_conf[rtereg_conf_size-1].finished == 0) {
    82                 TRACE_DEBUG(INFO, "rt_ereg: configuration invalid, AVP ended without OCTETSTRING AVP");
     80                LOG_E("[rt_ereg] configuration invalid, AVP ended without OCTETSTRING AVP");
    8381                return EINVAL;
    8482        }
    8583
    8684        if (ret != 0) {
    87                 TRACE_DEBUG(INFO, "rt_ereg: unable to parse the configuration file.");
     85                LOG_E("[rt_ereg] unable to parse the configuration file.");
    8886                return EINVAL;
    8987        } else {
     
    9290                        sum += rtereg_conf[i].rules_nb;
    9391                }
    94                 TRACE_DEBUG(FULL, "[rt-ereg] Added %d rules successfully.", sum);
     92                LOG_D("[rt-ereg] Added %d rules successfully.", sum);
    9593        }
    9694
     
    105103        if (rtereg_conf[rtereg_conf_size-1].finished) {
    106104                if ((ret = realloc(rtereg_conf, sizeof(*rtereg_conf)*(rtereg_conf_size+1))) == NULL) {
    107                         TRACE_DEBUG(INFO, "rt_ereg: realloc failed");
     105                        LOG_E("[rt_ereg] realloc failed");
    108106                        return -1;
    109107                }
     
    111109                rtereg_conf = ret;
    112110                memset(&rtereg_conf[rtereg_conf_size-1], 0, sizeof(*rtereg_conf));
    113                 TRACE_DEBUG(INFO, "rt_ereg: New AVP group found starting with %s", name);
     111                LOG_D("[rt_ereg] New AVP group found starting with %s", name);
    114112        }
    115113        level = rtereg_conf[rtereg_conf_size-1].level + 1;
    116114
    117115        if ((ret = realloc(rtereg_conf[rtereg_conf_size-1].avps, sizeof(*rtereg_conf[rtereg_conf_size-1].avps)*level)) == NULL) {
    118                 TRACE_DEBUG(INFO, "rt_ereg: realloc failed");
     116                LOG_E("[rt_ereg] realloc failed");
    119117                return -1;
    120118        }
     
    123121        CHECK_FCT_DO( fd_dict_search ( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME_ALL_VENDORS, name, &rtereg_conf[rtereg_conf_size-1].avps[level-1], ENOENT ),
    124122                      {
    125                               TRACE_DEBUG(INFO, "rt_ereg: Unable to find '%s' AVP in the loaded dictionaries.", name);
     123                              LOG_E("[rt_ereg] Unable to find '%s' AVP in the loaded dictionaries.", name);
    126124                              return -1;
    127125                      } );
     
    134132                        rtereg_conf[rtereg_conf_size-1].finished = 1;
    135133                } else if (data.avp_basetype != AVP_TYPE_GROUPED) {
    136                         TRACE_DEBUG(INFO, "rt_ereg: '%s' AVP is not an OCTETSTRING nor GROUPED AVP (%d).", name, data.avp_basetype);
     134                        LOG_E("[rt_ereg] '%s' AVP is not an OCTETSTRING nor GROUPED AVP (%d).", name, data.avp_basetype);
    137135                        return -1;
    138136                }
     
    148146void yyerror (YYLTYPE *ploc, char * conffile, char const *s)
    149147{
    150         TRACE_DEBUG(INFO, "rt_ereg: error in configuration parsing");
     148        LOG_E("[rt_ereg] error in configuration parsing");
    151149
    152150        if (ploc->first_line != ploc->last_line)
     
    223221
    224222                                                /* Error while compiling the regex */
    225                                                 TRACE_DEBUG(INFO, "rt_ereg: error while compiling the regular expression '%s':", new->pattern);
     223                                                LOG_E("[rt_ereg] error while compiling the regular expression '%s':", new->pattern);
    226224
    227225                                                /* Get the error message size */
     
    233231                                                /* Get the error message content */
    234232                                                regerror(err, &new->preg, buf, bl);
    235                                                 TRACE_DEBUG(INFO, "\t%s", buf);
     233                                                LOG_E("\t%s", buf);
    236234
    237235                                                /* Free the buffer, return the error */
Note: See TracChangeset for help on using the changeset viewer.