diff --git a/README.md b/README.md index d73a8134c..053b3f4ef 100644 --- a/README.md +++ b/README.md @@ -296,7 +296,8 @@ The options are described in more detail below. * --control-tos Takes an integer as argument and if given, specifies the TOS value that should be set in the control-ng - interface packets. The default is to leave the TOS field untouched. + interface packets. The default is to leave the TOS field untouched. This parameter can also be set or listed + via rtpengine-ctl. * -o, --timeout diff --git a/daemon/cli.c b/daemon/cli.c index 7b8f67f84..4d48c9a74 100644 --- a/daemon/cli.c +++ b/daemon/cli.c @@ -51,6 +51,7 @@ static void cli_incoming_set_redisallowederrors(str *instr, struct streambuf *re static void cli_incoming_set_redisdisabletime(str *instr, struct streambuf *replybuffer); static void cli_incoming_set_redisconnecttimeout(str *instr, struct streambuf *replybuffer); static void cli_incoming_set_rediscmdtimeout(str *instr, struct streambuf *replybuffer); +static void cli_incoming_set_controltos(str *instr, struct streambuf *replybuffer); static void cli_incoming_list_numsessions(str *instr, struct streambuf *replybuffer); static void cli_incoming_list_maxsessions(str *instr, struct streambuf *replybuffer); @@ -66,6 +67,7 @@ static void cli_incoming_list_redisallowederrors(str *instr, struct streambuf *r static void cli_incoming_list_redisdisabletime(str *instr, struct streambuf *replybuffer); static void cli_incoming_list_redisconnecttimeout(str *instr, struct streambuf *replybuffer); static void cli_incoming_list_rediscmdtimeout(str *instr, struct streambuf *replybuffer); +static void cli_incoming_list_controltos(str *instr, struct streambuf *replybuffer); static const cli_handler_t cli_top_handlers[] = { { "list", cli_incoming_list }, @@ -88,6 +90,7 @@ static const cli_handler_t cli_set_handlers[] = { { "redisdisabletime", cli_incoming_set_redisdisabletime }, { "redisconnecttimeout", cli_incoming_set_redisconnecttimeout }, { "rediscmdtimeout", cli_incoming_set_rediscmdtimeout }, + { "controltos", cli_incoming_set_controltos }, { NULL, }, }; static const cli_handler_t cli_list_handlers[] = { @@ -104,6 +107,7 @@ static const cli_handler_t cli_list_handlers[] = { { "redisdisabletime", cli_incoming_list_redisdisabletime }, { "redisconnecttimeout", cli_incoming_list_redisconnecttimeout }, { "rediscmdtimeout", cli_incoming_list_rediscmdtimeout }, + { "controltos", cli_incoming_list_controltos }, { NULL, }, }; @@ -1026,3 +1030,38 @@ static void cli_incoming_set_rediscmdtimeout(str *instr, struct streambuf *reply if (!fail) streambuf_printf(replybuffer, "Success setting redis-cmd-timeout to %ld\n", timeout); } + +static void cli_incoming_list_controltos(str *instr, struct streambuf *replybuffer) { + rwlock_lock_r(&rtpe_config.config_lock); + streambuf_printf(replybuffer, "%d\n", rtpe_config.control_tos); + rwlock_unlock_r(&rtpe_config.config_lock); +} + +static void cli_incoming_set_controltos(str *instr, struct streambuf *replybuffer) { + long tos; + char *endptr; + int i; + + if (str_shift(instr, 1)) { + streambuf_printf(replybuffer, "%s\n", "More parameters required."); + return ; + } + + tos = strtol(instr->s, &endptr, 10); + if (tos < 0 || tos > 255) { + streambuf_printf(replybuffer, "Invalid control-tos value %ld, must be between 0 and 255\n", tos); + return; + } + + rwlock_lock_w(&rtpe_config.config_lock); + rtpe_config.control_tos = tos; + rwlock_unlock_w(&rtpe_config.config_lock); + + for (i=0; i < G_N_ELEMENTS(rtpe_control_ng->udp_listeners); i++) { + if (rtpe_control_ng->udp_listeners[i].fd != -1) { + set_tos(&rtpe_control_ng->udp_listeners[i],tos); + } + } + + streambuf_printf(replybuffer, "Success setting redis-connect-timeout to %ld\n", tos); +} diff --git a/daemon/control_ng.c b/daemon/control_ng.c index a41318991..d73c267b6 100644 --- a/daemon/control_ng.c +++ b/daemon/control_ng.c @@ -18,7 +18,7 @@ mutex_t rtpe_cngs_lock; GHashTable *rtpe_cngs_hash; - +struct control_ng *rtpe_control_ng; static void timeval_update_request_time(struct request_time *request, const struct timeval *offer_diff) { @@ -323,6 +323,8 @@ struct control_ng *control_ng_new(struct poller *p, endpoint_t *ep, unsigned cha c = obj_alloc0("control_ng", sizeof(*c), NULL); cookie_cache_init(&c->cookie_cache); + c->udp_listeners[0].fd = -1; + c->udp_listeners[1].fd = -1; if (udp_listener_init(&c->udp_listeners[0], p, ep, control_ng_incoming, &c->obj)) goto fail2; diff --git a/daemon/control_ng.h b/daemon/control_ng.h index e5f2d0429..c0dbb3af7 100644 --- a/daemon/control_ng.h +++ b/daemon/control_ng.h @@ -33,5 +33,6 @@ void control_ng_init(void); extern mutex_t rtpe_cngs_lock; extern GHashTable *rtpe_cngs_hash; +extern struct control_ng *rtpe_control_ng; #endif diff --git a/daemon/main.c b/daemon/main.c index f2ae67116..bd594c876 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -501,7 +501,6 @@ static void init_everything() { static void create_everything(void) { struct control_tcp *ct; struct control_udp *cu; - struct control_ng *cn; struct cli *cl; struct timeval tmp_tv; struct timeval redis_start, redis_stop; @@ -556,11 +555,11 @@ no_kernel: die("Failed to open UDP control connection port"); } - cn = NULL; + rtpe_control_ng = NULL; if (rtpe_config.ng_listen_ep.port) { interfaces_exclude_port(rtpe_config.ng_listen_ep.port); - cn = control_ng_new(rtpe_poller, &rtpe_config.ng_listen_ep, rtpe_config.control_tos); - if (!cn) + rtpe_control_ng = control_ng_new(rtpe_poller, &rtpe_config.ng_listen_ep, rtpe_config.control_tos); + if (!rtpe_control_ng) die("Failed to open UDP control connection port"); }