Skip to content

Commit

Permalink
usrloc: fexible logging for roundtrip details
Browse files Browse the repository at this point in the history
- new params ka_loglevel and ka_logmsg
  • Loading branch information
miconda committed Mar 28, 2020
1 parent 7883a5e commit 0d912f1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
18 changes: 15 additions & 3 deletions src/modules/usrloc/ul_keepalive.c
Expand Up @@ -32,6 +32,7 @@
#include "../../core/resolve.h"
#include "../../core/forward.h"
#include "../../core/globals.h"
#include "../../core/pvar.h"
#include "../../core/parser/parse_uri.h"
#include "../../core/parser/parse_from.h"
#include "../../core/parser/parse_to.h"
Expand Down Expand Up @@ -71,6 +72,9 @@ extern str ul_ka_domain;
extern str ul_ka_method;
extern int ul_ka_mode;
extern int ul_ka_filter;
extern int ul_ka_loglevel;
extern pv_elem_t *ul_ka_logfmt;

extern unsigned int nat_bflag;

static unsigned int _ul_ka_counter = 0;
Expand Down Expand Up @@ -417,11 +421,19 @@ int ul_ka_reply_received(sip_msg_t *msg)
gettimeofday(&tvn, NULL);
tvdiff = (tvn.tv_sec - tvm.tv_sec) * 1000000
+ (tvn.tv_usec - tvm.tv_usec);
ul_update_keepalive(aorhash, &ruid, tvn.tv_sec, tvdiff);

LM_DBG("reply for keepalive of [%.*s:%u] roundtrip: %u.%06usec\n",
ruid.len, ruid.s, aorhash, tvdiff/1000000, tvdiff%1000000);
if(ul_ka_loglevel != 255 && ul_ka_logfmt != NULL) {
if (pv_printf_s(msg, ul_ka_logfmt, &tok) == 0) {
LOG(ul_ka_loglevel, "keepalive roundtrip: %u.%06u sec - ruid [%.*s]%.*s\n",
tvdiff/1000000, tvdiff%1000000, ruid.len, ruid.s,
tok.len, tok.s);
return 0;
}
}

ul_update_keepalive(aorhash, &ruid, tvn.tv_sec, tvdiff);
LM_DBG("response of keepalive for ruid [%.*s] aorhash [%u] roundtrip: %u.%06u secs\n",
ruid.len, ruid.s, aorhash, tvdiff/1000000, tvdiff%1000000);

return 0;
}
18 changes: 15 additions & 3 deletions src/modules/usrloc/usrloc_mod.c
Expand Up @@ -123,6 +123,9 @@ str ul_ka_domain = str_init("kamailio.org");
str ul_ka_method = str_init("OPTIONS");
int ul_ka_mode = 0;
int ul_ka_filter = 0;
int ul_ka_loglevel = 255;
str ul_ka_logmsg = str_init(" to-uri: [$tu] src-uri: [$su]");
pv_elem_t *ul_ka_logfmt = NULL;

/* sruid to get internal uid for mi/rpc commands */
sruid_t _ul_sruid;
Expand Down Expand Up @@ -255,6 +258,7 @@ static param_export_t params[] = {
{"ka_domain", PARAM_STR, &ul_ka_domain},
{"ka_method", PARAM_STR, &ul_ka_method},
{"ka_filter", PARAM_INT, &ul_ka_filter},
{"ka_loglevel", PARAM_INT, &ul_ka_loglevel},
{0, 0, 0}
};

Expand Down Expand Up @@ -396,9 +400,17 @@ static int mod_init(void)
ul_set_xavp_contact_clone(1);
}

/* set max partition number for timers processing of db records */
if((ul_ka_mode != ULKA_NONE) && (ul_timer_procs > 1)) {
ul_set_max_partition((unsigned int)ul_timer_procs);
if(ul_ka_mode != ULKA_NONE) {
/* set max partition number for timers processing of db records */
if (ul_timer_procs > 1) {
ul_set_max_partition((unsigned int)ul_timer_procs);
}
if(ul_ka_logmsg.len > 0) {
if(pv_parse_format(&ul_ka_logmsg, &ul_ka_logfmt) < 0) {
LM_ERR("failed parsing ka log message format\n");
return -1;
}
}
}

init_flag = 1;
Expand Down

0 comments on commit 0d912f1

Please sign in to comment.