diff --git a/daemon/call.c b/daemon/call.c index 29d379650..e6ce9cb32 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -240,7 +240,7 @@ no_sfd: check = atomic_get_na(&rtpe_config.timeout) * 1000000LL; // XXX scale to micro tmp_t_reason = TIMEOUT; if (!MEDIA_ISSET(ps->media, RECV) || !sfd) { - check = atomic_get_na(&rtpe_config.silent_timeout) * 1000000LL; // XXX scale to micro + check = atomic_get_na(&rtpe_config.silent_timeout_us); tmp_t_reason = SILENT_TIMEOUT; } else if (!PS_ISSET(ps, FILLED)) { diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index 40f4d117e..ead232c78 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -420,7 +420,7 @@ str call_query_udp(char **out) { rwlock_unlock_w(&c->master_lock); ret = str_sprintf("%s %" PRId64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 "\n", out[RE_UDP_COOKIE], - atomic_get_na(&rtpe_config.silent_timeout) * 1000000L - (rtpe_now - stats.last_packet_us), // XXX scale to micro + atomic_get_na(&rtpe_config.silent_timeout_us) - (rtpe_now - stats.last_packet_us), atomic64_get_na(&stats.totals[0].packets), atomic64_get_na(&stats.totals[1].packets), atomic64_get_na(&stats.totals[2].packets), atomic64_get_na(&stats.totals[3].packets)); goto out; diff --git a/daemon/cli.c b/daemon/cli.c index d5399dc18..508dd149e 100644 --- a/daemon/cli.c +++ b/daemon/cli.c @@ -411,8 +411,8 @@ RTPE_CONFIG_BOOL_PARAMS RTPE_CONFIG_ENUM_PARAMS #undef X -#define X(s) cw->cw_printf(cw, #s " = %" PRIu64"\n", initial_rtpe_config.s); -RTPE_CONFIG_UINT64_PARAMS +#define X(s) cw->cw_printf(cw, #s " = %" PRId64"\n", initial_rtpe_config.s); +RTPE_CONFIG_INT64_PARAMS #undef X cw->cw_printf(cw, "[max-cpu = %.1f]\n" @@ -463,8 +463,8 @@ RTPE_CONFIG_BOOL_PARAMS RTPE_CONFIG_ENUM_PARAMS #undef X -#define X(s) cw->cw_printf(cw, #s " = %" PRIu64"\n", rtpe_config.s); -RTPE_CONFIG_UINT64_PARAMS +#define X(s) cw->cw_printf(cw, #s " = %" PRId64"\n", rtpe_config.s); +RTPE_CONFIG_INT64_PARAMS #undef X cw->cw_printf(cw, "[max-cpu = %.1f]\n" @@ -515,7 +515,7 @@ RTPE_CONFIG_ENDPOINT_QUEUE_PARAMS X(load_limit, "max-load") \ X(bw_limit, "max-bw") \ X(timeout, "timeout") \ - X(silent_timeout, "silent-timeout") \ + X(silent_timeout_us, "silent-timeout") \ X(final_timeout, "final-timeout") \ X(control_tos, "control-tos") \ X(redis_allowed_errors, "redis_allowed_errors") \ @@ -654,7 +654,7 @@ static void cli_incoming_list_timeout(str *instr, struct cli_writer *cw, const c cw->cw_printf(cw, "TIMEOUT=%u\n", rtpe_config.timeout); } static void cli_incoming_list_silenttimeout(str *instr, struct cli_writer *cw, const cli_handler_t *handler) { - cw->cw_printf(cw, "SILENT_TIMEOUT=%u\n", rtpe_config.silent_timeout); + cw->cw_printf(cw, "SILENT_TIMEOUT=%" PRId64 "\n", rtpe_config.silent_timeout_us / 1000000L); } static void cli_incoming_list_finaltimeout(str *instr, struct cli_writer *cw, const cli_handler_t *handler) { cw->cw_printf(cw, "FINAL_TIMEOUT=%u\n", rtpe_config.final_timeout); @@ -1053,11 +1053,35 @@ static void cli_incoming_set_gentimeout(str *instr, struct cli_writer *cw, int * } } +static void cli_incoming_set_gentimeout_us(str *instr, struct cli_writer *cw, int64_t *conf_timeout) { + long timeout_num; + char *endptr; + + if (instr->len == 0) { + cw->cw_printf(cw, "More parameters required.\n"); + return; + } + + errno = 0; + timeout_num = strtol(instr->s, &endptr, 10); + + if ((errno == ERANGE && (timeout_num == ULONG_MAX)) || (errno != 0 && timeout_num == 0) || timeout_num < 0 || timeout_num >= INT_MAX) { + cw->cw_printf(cw, "Fail setting timeout to %s; errno=%d\n", instr->s, errno); + return; + } else if (endptr == instr->s) { + cw->cw_printf(cw, "Fail setting timeout to %s; no digits found\n", instr->s); + return; + } else { + atomic_set_na(conf_timeout, timeout_num * 1000000LL); + cw->cw_printf(cw, "Success setting timeout to %lu\n", timeout_num); + } +} + static void cli_incoming_set_timeout(str *instr, struct cli_writer *cw, const cli_handler_t *handler) { cli_incoming_set_gentimeout(instr, cw, &rtpe_config.timeout); } static void cli_incoming_set_silenttimeout(str *instr, struct cli_writer *cw, const cli_handler_t *handler) { - cli_incoming_set_gentimeout(instr, cw, &rtpe_config.silent_timeout); + cli_incoming_set_gentimeout_us(instr, cw, &rtpe_config.silent_timeout_us); } static void cli_incoming_set_finaltimeout(str *instr, struct cli_writer *cw, const cli_handler_t *handler) { cli_incoming_set_gentimeout(instr, cw, &rtpe_config.final_timeout); diff --git a/daemon/main.c b/daemon/main.c index ea39fc6f4..16d337ef8 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -672,6 +672,7 @@ static void options(int *argc, char ***argv, charp_ht templates) { g_autoptr(char) templates_section = NULL; g_autoptr(char) interfaces_config = NULL; g_autoptr(char) transcode_config = NULL; + int silent_timeout = 0; GOptionEntry e[] = { { "table", 't', 0, G_OPTION_ARG_INT, &rtpe_config.kernel_table, "Kernel table to use", "INT" }, @@ -703,7 +704,7 @@ static void options(int *argc, char ***argv, charp_ht templates) { { "control-tos",0 , 0, G_OPTION_ARG_INT, &rtpe_config.control_tos, "Default TOS value to set on control-ng", "INT" }, { "control-pmtu", 0,0, G_OPTION_ARG_STRING, &control_pmtu, "Path MTU discovery behaviour on UDP control sockets", "want|dont" }, { "timeout", 'o', 0, G_OPTION_ARG_INT, &rtpe_config.timeout, "RTP timeout", "SECS" }, - { "silent-timeout",'s',0,G_OPTION_ARG_INT, &rtpe_config.silent_timeout,"RTP timeout for muted", "SECS" }, + { "silent-timeout",'s',0,G_OPTION_ARG_INT, &silent_timeout, "RTP timeout for muted", "SECS" }, { "final-timeout",'a',0,G_OPTION_ARG_INT, &rtpe_config.final_timeout, "Call timeout", "SECS" }, { "offer-timeout",0,0, G_OPTION_ARG_INT, &rtpe_config.offer_timeout, "Timeout for incomplete one-sided calls", "SECS" }, { "port-min", 'm', 0, G_OPTION_ARG_INT, &rtpe_config.port_min, "Lowest port to use for RTP", "INT" }, @@ -1074,8 +1075,9 @@ static void options(int *argc, char ***argv, charp_ht templates) { if (rtpe_config.timeout <= 0) rtpe_config.timeout = 60; - if (rtpe_config.silent_timeout <= 0) - rtpe_config.silent_timeout = 3600; + rtpe_config.silent_timeout_us = silent_timeout * 1000000LL; + if (rtpe_config.silent_timeout_us <= 0) + rtpe_config.silent_timeout_us = 3600 * 1000000LL; if (rtpe_config.offer_timeout <= 0) rtpe_config.offer_timeout = 3600; @@ -1385,7 +1387,7 @@ static void fill_initial_rtpe_cfg(struct rtpengine_config* ini_rtpe_cfg) { #define X(s) ini_rtpe_cfg->s = rtpe_config.s; RTPE_CONFIG_INT_PARAMS -RTPE_CONFIG_UINT64_PARAMS +RTPE_CONFIG_INT64_PARAMS RTPE_CONFIG_BOOL_PARAMS RTPE_CONFIG_ENDPOINT_PARAMS RTPE_CONFIG_ENUM_PARAMS diff --git a/include/main.h b/include/main.h index 1550ef174..96025736e 100644 --- a/include/main.h +++ b/include/main.h @@ -37,7 +37,6 @@ enum endpoint_learning { X(kernel_table) \ X(max_sessions) \ X(timeout) \ - X(silent_timeout) \ X(final_timeout) \ X(offer_timeout) \ X(moh_max_duration) \ @@ -104,8 +103,9 @@ enum endpoint_learning { X(ng_client_timeout) \ X(ng_client_retries) \ -#define RTPE_CONFIG_UINT64_PARAMS \ - X(bw_limit) +#define RTPE_CONFIG_INT64_PARAMS \ + X(bw_limit) \ + X(silent_timeout_us) \ #define RTPE_CONFIG_BOOL_PARAMS \ X(homer_rtcp_off) \ @@ -222,8 +222,8 @@ struct rtpengine_config { RTPE_CONFIG_INT_PARAMS #undef X -#define X(s) uint64_t s; -RTPE_CONFIG_UINT64_PARAMS +#define X(s) int64_t s; +RTPE_CONFIG_INT64_PARAMS #undef X #define X(s) gboolean s;