From 4b92d14e1fe6078dcbb5a60e1739ad814a9f6376 Mon Sep 17 00:00:00 2001 From: smititelu Date: Fri, 16 Oct 2015 16:35:32 +0200 Subject: [PATCH 1/7] Allow more than 65536 open files RTPengine starts with 1048575 (1<<20 - 1) maximum open files limit. Make the maximum number of open files configurable using "rtpengine-ctl set max-open-files 'open_files_num'" command. Update utils script. --- daemon/cli.c | 69 ++++++++++++++++++++++++++++++++++++++++++--- daemon/main.c | 2 +- daemon/str.h | 16 +++++++++++ utils/rtpengine-ctl | 3 ++ 4 files changed, 85 insertions(+), 5 deletions(-) diff --git a/daemon/cli.c b/daemon/cli.c index f6069f84f..de6233432 100644 --- a/daemon/cli.c +++ b/daemon/cli.c @@ -212,6 +212,45 @@ static void cli_incoming_list_callid(char* buffer, int len, struct callmaster* m obj_put(c); } +static void cli_incoming_set_max_open_files(char* buffer, int len, struct callmaster* m, char* replybuffer, const char* outbufend) { + int printlen = 0; + unsigned int open_files_num; + str open_files; + pid_t pid; + + // limit the minimum number of open files to avoid rtpengine freeze for low open_files_num values + unsigned int min_open_files_num = (1 << 16); + + if (len<=1) { + printlen = snprintf(replybuffer,(outbufend-replybuffer), "%s\n", "More parameters required."); + ADJUSTLEN(printlen,outbufend,replybuffer); + return; + } + + ++buffer; --len; // one space + open_files.s = buffer; + open_files.len = len; + open_files_num = str_to_ui(&open_files, -1); + + if (open_files_num == -1) { + printlen = snprintf (replybuffer,(outbufend-replybuffer), "Fail setting open_files to %.*s; not an unsigned integer\n", open_files.len, open_files.s); + ADJUSTLEN(printlen,outbufend,replybuffer); + return; + } else if (open_files_num < min_open_files_num) { + printlen = snprintf (replybuffer,(outbufend-replybuffer), "Fail setting open_files to %.*s; can't set it under %u\n", open_files.len, open_files.s, min_open_files_num); + ADJUSTLEN(printlen,outbufend,replybuffer); + return; + } else if (rlim(RLIMIT_NOFILE, open_files_num) == -1){ + printlen = snprintf (replybuffer,(outbufend-replybuffer), "Fail setting open_files to %.*s; errno = %d\n", open_files.len, open_files.s, errno); + ADJUSTLEN(printlen,outbufend,replybuffer); + return; + } else { + pid = getpid(); + printlen = snprintf (replybuffer,(outbufend-replybuffer), "Success setting open_files to %.*s; cat /proc/%u/limits\n", open_files.len, open_files.s, pid); + ADJUSTLEN(printlen,outbufend,replybuffer); + } +} + static void cli_incoming_list(char* buffer, int len, struct callmaster* m, char* replybuffer, const char* outbufend) { GHashTableIter iter; gpointer key, value; @@ -262,6 +301,26 @@ static void cli_incoming_list(char* buffer, int len, struct callmaster* m, char* } } +static void cli_incoming_set(char* buffer, int len, struct callmaster* m, char* replybuffer, const char* outbufend) { + int printlen=0; + + static const char* SET_OPEN_FILES = "max-open-files"; + + if (len<=1) { + printlen = snprintf(replybuffer, outbufend-replybuffer, "%s\n", "More parameters required."); + ADJUSTLEN(printlen,outbufend,replybuffer); + return; + } + ++buffer; --len; // one space + + if (len>=strlen(SET_OPEN_FILES) && strncmp(buffer,SET_OPEN_FILES,strlen(SET_OPEN_FILES)) == 0) { + cli_incoming_set_max_open_files(buffer+strlen(SET_OPEN_FILES), len-strlen(SET_OPEN_FILES), m, replybuffer, outbufend); + } else { + printlen = snprintf(replybuffer, outbufend-replybuffer, "%s:%s\n", "Unknown 'set' command", buffer); + ADJUSTLEN(printlen,outbufend,replybuffer); + } +} + static void cli_incoming_terminate(char* buffer, int len, struct callmaster* m, char* replybuffer, const char* outbufend) { str termparam; struct call* c=0; @@ -334,9 +393,9 @@ static void cli_incoming(int fd, void *p, uintptr_t u) { struct cli *cli = (void *) p; socklen_t sinl; static const int BUFLENGTH = 4096*1024; - char replybuffer[BUFLENGTH]; - char* outbuf = replybuffer; - const char* outbufend = replybuffer+BUFLENGTH; + char replybuffer[BUFLENGTH]; + char* outbuf = replybuffer; + const char* outbufend = replybuffer+BUFLENGTH; static const int MAXINPUT = 1024; char inbuf[MAXINPUT]; int inlen = 0, readbytes = 0; @@ -374,12 +433,14 @@ next: static const char* LIST = "list"; static const char* TERMINATE = "terminate"; + static const char* SET = "set"; if (strncmp(inbuf,LIST,strlen(LIST)) == 0) { cli_incoming_list(inbuf+strlen(LIST), inlen-strlen(LIST), cli->callmaster, outbuf, outbufend); - } else if (strncmp(inbuf,TERMINATE,strlen(TERMINATE)) == 0) { cli_incoming_terminate(inbuf+strlen(TERMINATE), inlen-strlen(TERMINATE), cli->callmaster, outbuf, outbufend); + } else if (strncmp(inbuf,SET,strlen(SET)) == 0) { + cli_incoming_set(inbuf+strlen(SET), inlen-strlen(SET), cli->callmaster, outbuf, outbufend); } else { sprintf(replybuffer, "%s:%s\n", "Unknown or incomplete command:", inbuf); } diff --git a/daemon/main.c b/daemon/main.c index 3b6241567..3b671e397 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -149,7 +149,7 @@ static void resources(void) { int tryv; rlim(RLIMIT_CORE, RLIM_INFINITY); - for (tryv = ((1<<16) - 1); tryv && rlim(RLIMIT_NOFILE, tryv) == -1; tryv >>= 1) + for (tryv = ((1<<20) - 1); tryv && rlim(RLIMIT_NOFILE, tryv) == -1; tryv >>= 1) ; rlim(RLIMIT_DATA, RLIM_INFINITY); diff --git a/daemon/str.h b/daemon/str.h index 084017a3b..dc42b4f85 100644 --- a/daemon/str.h +++ b/daemon/str.h @@ -63,6 +63,8 @@ INLINE int str_str(const str *s, const char *sub); INLINE void str_swap(str *a, str *b); /* parses a string into an int, returns default if conversion fails */ INLINE int str_to_i(str *s, int def); +/* parses a string uinto an int, returns default if conversion fails */ +INLINE uint str_to_ui(str *s, int def); /* asprintf() analogs */ #define str_sprintf(fmt, a...) __str_sprintf(STR_MALLOC_PADDING fmt, a) @@ -256,4 +258,18 @@ INLINE int str_to_i(str *s, int def) { return ret; } +INLINE unsigned int str_to_ui(str *s, int def) { + char c, *ep; + long ret; + if (s->len <= 0) + return def; + c = s->s[s->len]; + s->s[s->len] = '\0'; + ret = strtol(s->s, &ep, 10); + s->s[s->len] = c; + if (ep == s->s) + return def; + return ret; +} + #endif diff --git a/utils/rtpengine-ctl b/utils/rtpengine-ctl index d39c48f25..4179197ab 100755 --- a/utils/rtpengine-ctl +++ b/utils/rtpengine-ctl @@ -72,6 +72,9 @@ sub showusage { print " all : terminates all current sessions\n"; print " : session is immediately terminated\n"; print "\n"; + print " set [ max-open-files ]\n"; + print " max-open-files : increase the max nr of allowed open files\n"; + print "\n"; print "\n"; print " Return Value:\n"; print " 0 on success with ouput from server side, other values for failure.\n"; From c44c35af5590dace165cf7f867d22f1fc9bccda0 Mon Sep 17 00:00:00 2001 From: smititelu Date: Thu, 19 Nov 2015 15:53:43 +0100 Subject: [PATCH 2/7] Add 'rtpengine-ctl list maxsessions' command --- daemon/cli.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/daemon/cli.c b/daemon/cli.c index de6233432..6e4254367 100644 --- a/daemon/cli.c +++ b/daemon/cli.c @@ -104,6 +104,14 @@ static void cli_incoming_list_totals(char* buffer, int len, struct callmaster* m g_list_free(list); } +static void cli_incoming_list_maxsessions(char* buffer, int len, struct callmaster* m, char* replybuffer, const char* outbufend) { + int printlen=0; + + /* don't lock while reading the value */ + printlen = snprintf(replybuffer,(outbufend-replybuffer), "Maximum sessions configured on rtpengine: %d\n", m->conf.max_sessions); + ADJUSTLEN(printlen,outbufend,replybuffer); +} + static void cli_incoming_list_callid(char* buffer, int len, struct callmaster* m, char* replybuffer, const char* outbufend) { str callid; struct call* c=0; @@ -262,6 +270,7 @@ static void cli_incoming_list(char* buffer, int len, struct callmaster* m, char* static const char* LIST_SESSIONS = "sessions"; static const char* LIST_SESSION = "session"; static const char* LIST_TOTALS = "totals"; + static const char* LIST_MAX_SESSIONS = "maxsessions"; if (len<=1) { printlen = snprintf(replybuffer, outbufend-replybuffer, "%s\n", "More parameters required."); @@ -272,7 +281,7 @@ static void cli_incoming_list(char* buffer, int len, struct callmaster* m, char* if (len>=strlen(LIST_NUMSESSIONS) && strncmp(buffer,LIST_NUMSESSIONS,strlen(LIST_NUMSESSIONS)) == 0) { rwlock_lock_r(&m->hashlock); - printlen = snprintf(replybuffer, outbufend-replybuffer, "Current Sessions on rtpengine:%i\n", g_hash_table_size(m->callhash)); + printlen = snprintf(replybuffer, outbufend-replybuffer, "Current sessions running on rtpengine: %i\n", g_hash_table_size(m->callhash)); ADJUSTLEN(printlen,outbufend,replybuffer); rwlock_unlock_r(&m->hashlock); } else if (len>=strlen(LIST_SESSIONS) && strncmp(buffer,LIST_SESSIONS,strlen(LIST_SESSIONS)) == 0) { @@ -295,6 +304,8 @@ static void cli_incoming_list(char* buffer, int len, struct callmaster* m, char* cli_incoming_list_callid(buffer+strlen(LIST_SESSION), len-strlen(LIST_SESSION), m, replybuffer, outbufend); } else if (len>=strlen(LIST_TOTALS) && strncmp(buffer,LIST_TOTALS,strlen(LIST_TOTALS)) == 0) { cli_incoming_list_totals(buffer+strlen(LIST_TOTALS), len-strlen(LIST_TOTALS), m, replybuffer, outbufend); + } else if (len>=strlen(LIST_MAX_SESSIONS) && strncmp(buffer,LIST_MAX_SESSIONS,strlen(LIST_MAX_SESSIONS)) == 0) { + cli_incoming_list_maxsessions(buffer+strlen(LIST_MAX_SESSIONS), len-strlen(LIST_MAX_SESSIONS), m, replybuffer, outbufend); } else { printlen = snprintf(replybuffer, outbufend-replybuffer, "%s:%s\n", "Unknown 'list' command", buffer); ADJUSTLEN(printlen,outbufend,replybuffer); From 00bb10bba7d14c1321d0d5822b92e62d26ae74e6 Mon Sep 17 00:00:00 2001 From: smititelu Date: Fri, 20 Nov 2015 08:59:31 +0100 Subject: [PATCH 3/7] Add 'rtpengine-ctl set maxsessions X' command --- daemon/cli.c | 37 ++++++++++++++++++++++++++++++++++++- daemon/str.h | 3 +++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/daemon/cli.c b/daemon/cli.c index 6e4254367..763f8d3fb 100644 --- a/daemon/cli.c +++ b/daemon/cli.c @@ -107,7 +107,7 @@ static void cli_incoming_list_totals(char* buffer, int len, struct callmaster* m static void cli_incoming_list_maxsessions(char* buffer, int len, struct callmaster* m, char* replybuffer, const char* outbufend) { int printlen=0; - /* don't lock while reading the value */ + /* don't lock anything while reading the value */ printlen = snprintf(replybuffer,(outbufend-replybuffer), "Maximum sessions configured on rtpengine: %d\n", m->conf.max_sessions); ADJUSTLEN(printlen,outbufend,replybuffer); } @@ -259,6 +259,38 @@ static void cli_incoming_set_max_open_files(char* buffer, int len, struct callma } } +static void cli_incoming_set_maxsessions(char* buffer, int len, struct callmaster* m, char* replybuffer, const char* outbufend) { + int printlen = 0; + int maxsessions_num; + str maxsessions; + + if (len<=1) { + printlen = snprintf(replybuffer,(outbufend-replybuffer), "%s\n", "More parameters required."); + ADJUSTLEN(printlen,outbufend,replybuffer); + return; + } + + ++buffer; --len; // one space + maxsessions.s = buffer; + maxsessions.len = len; + maxsessions_num = str_to_i(&maxsessions, -1); + + if (maxsessions_num == -1) { + printlen = snprintf (replybuffer,(outbufend-replybuffer), "Fail setting maxsessions to %.*s; not an integer\n", maxsessions.len, maxsessions.s); + ADJUSTLEN(printlen,outbufend,replybuffer); + return; + } else if (maxsessions_num < 0) { + printlen = snprintf (replybuffer,(outbufend-replybuffer), "Fail setting maxsessions to %d; negative value\n", maxsessions_num); + ADJUSTLEN(printlen,outbufend,replybuffer); + return; + } else { + /* don't lock anything while writing the value - only this command modifies its value */ + m->conf.max_sessions = maxsessions_num; + printlen = snprintf (replybuffer,(outbufend-replybuffer), "Success setting maxsessions to %d\n", maxsessions_num); + ADJUSTLEN(printlen,outbufend,replybuffer); + } +} + static void cli_incoming_list(char* buffer, int len, struct callmaster* m, char* replybuffer, const char* outbufend) { GHashTableIter iter; gpointer key, value; @@ -316,6 +348,7 @@ static void cli_incoming_set(char* buffer, int len, struct callmaster* m, char* int printlen=0; static const char* SET_OPEN_FILES = "max-open-files"; + static const char* SET_MAX_SESSIONS = "maxsessions"; if (len<=1) { printlen = snprintf(replybuffer, outbufend-replybuffer, "%s\n", "More parameters required."); @@ -326,6 +359,8 @@ static void cli_incoming_set(char* buffer, int len, struct callmaster* m, char* if (len>=strlen(SET_OPEN_FILES) && strncmp(buffer,SET_OPEN_FILES,strlen(SET_OPEN_FILES)) == 0) { cli_incoming_set_max_open_files(buffer+strlen(SET_OPEN_FILES), len-strlen(SET_OPEN_FILES), m, replybuffer, outbufend); + } else if (len>=strlen(SET_MAX_SESSIONS) && strncmp(buffer,SET_MAX_SESSIONS,strlen(SET_MAX_SESSIONS)) == 0) { + cli_incoming_set_maxsessions(buffer+strlen(SET_MAX_SESSIONS), len-strlen(SET_MAX_SESSIONS), m, replybuffer, outbufend); } else { printlen = snprintf(replybuffer, outbufend-replybuffer, "%s:%s\n", "Unknown 'set' command", buffer); ADJUSTLEN(printlen,outbufend,replybuffer); diff --git a/daemon/str.h b/daemon/str.h index dc42b4f85..90b449374 100644 --- a/daemon/str.h +++ b/daemon/str.h @@ -247,6 +247,7 @@ INLINE void str_swap(str *a, str *b) { INLINE int str_to_i(str *s, int def) { char c, *ep; long ret; + int maxint = 0x7FFFFFFF; if (s->len <= 0) return def; c = s->s[s->len]; @@ -255,6 +256,8 @@ INLINE int str_to_i(str *s, int def) { s->s[s->len] = c; if (ep == s->s) return def; + if (ret > maxint) + return def; return ret; } From 012bcc4b2172a96f9eb753b2610eeaad5ac0b4a6 Mon Sep 17 00:00:00 2001 From: smititelu Date: Mon, 23 Nov 2015 17:14:00 +0100 Subject: [PATCH 4/7] Add 'rtpengine-ctl list maxopenfiles' command --- daemon/cli.c | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/daemon/cli.c b/daemon/cli.c index 763f8d3fb..ba3d1007e 100644 --- a/daemon/cli.c +++ b/daemon/cli.c @@ -110,6 +110,30 @@ static void cli_incoming_list_maxsessions(char* buffer, int len, struct callmast /* don't lock anything while reading the value */ printlen = snprintf(replybuffer,(outbufend-replybuffer), "Maximum sessions configured on rtpengine: %d\n", m->conf.max_sessions); ADJUSTLEN(printlen,outbufend,replybuffer); + + return ; +} + +static void cli_incoming_list_maxopenfiles(char* buffer, int len, struct callmaster* m, char* replybuffer, const char* outbufend) { + int printlen=0; + struct rlimit rlim; + pid_t pid = getpid(); + + if (getrlimit(RLIMIT_NOFILE, &rlim) == -1) { + printlen = snprintf(replybuffer,(outbufend-replybuffer), "Fail getting rtpengine configured limits; cat /proc/%u/limits\n", pid); + ADJUSTLEN(printlen,outbufend,replybuffer); + return ; + } + + if (rlim.rlim_cur == RLIM_INFINITY) { + printlen = snprintf(replybuffer,(outbufend-replybuffer), "Maximum open-files configured on rtpengine: infinite; cat /proc/%u/limits\n", pid); + ADJUSTLEN(printlen,outbufend,replybuffer); + } else { + printlen = snprintf(replybuffer,(outbufend-replybuffer), "Maximum open-files configured on rtpengine: %lld; cat /proc/%u/limits\n", (long long) rlim.rlim_cur, pid); + ADJUSTLEN(printlen,outbufend,replybuffer); + } + + return ; } static void cli_incoming_list_callid(char* buffer, int len, struct callmaster* m, char* replybuffer, const char* outbufend) { @@ -220,7 +244,7 @@ static void cli_incoming_list_callid(char* buffer, int len, struct callmaster* m obj_put(c); } -static void cli_incoming_set_max_open_files(char* buffer, int len, struct callmaster* m, char* replybuffer, const char* outbufend) { +static void cli_incoming_set_maxopenfiles(char* buffer, int len, struct callmaster* m, char* replybuffer, const char* outbufend) { int printlen = 0; unsigned int open_files_num; str open_files; @@ -302,6 +326,7 @@ static void cli_incoming_list(char* buffer, int len, struct callmaster* m, char* static const char* LIST_SESSIONS = "sessions"; static const char* LIST_SESSION = "session"; static const char* LIST_TOTALS = "totals"; + static const char* LIST_MAX_OPEN_FILES = "maxopenfiles"; static const char* LIST_MAX_SESSIONS = "maxsessions"; if (len<=1) { @@ -338,6 +363,8 @@ static void cli_incoming_list(char* buffer, int len, struct callmaster* m, char* cli_incoming_list_totals(buffer+strlen(LIST_TOTALS), len-strlen(LIST_TOTALS), m, replybuffer, outbufend); } else if (len>=strlen(LIST_MAX_SESSIONS) && strncmp(buffer,LIST_MAX_SESSIONS,strlen(LIST_MAX_SESSIONS)) == 0) { cli_incoming_list_maxsessions(buffer+strlen(LIST_MAX_SESSIONS), len-strlen(LIST_MAX_SESSIONS), m, replybuffer, outbufend); + } else if (len>=strlen(LIST_MAX_OPEN_FILES) && strncmp(buffer,LIST_MAX_OPEN_FILES,strlen(LIST_MAX_OPEN_FILES)) == 0) { + cli_incoming_list_maxopenfiles(buffer+strlen(LIST_MAX_OPEN_FILES), len-strlen(LIST_MAX_OPEN_FILES), m, replybuffer, outbufend); } else { printlen = snprintf(replybuffer, outbufend-replybuffer, "%s:%s\n", "Unknown 'list' command", buffer); ADJUSTLEN(printlen,outbufend,replybuffer); @@ -347,7 +374,7 @@ static void cli_incoming_list(char* buffer, int len, struct callmaster* m, char* static void cli_incoming_set(char* buffer, int len, struct callmaster* m, char* replybuffer, const char* outbufend) { int printlen=0; - static const char* SET_OPEN_FILES = "max-open-files"; + static const char* SET_MAX_OPEN_FILES = "maxopenfiles"; static const char* SET_MAX_SESSIONS = "maxsessions"; if (len<=1) { @@ -357,8 +384,8 @@ static void cli_incoming_set(char* buffer, int len, struct callmaster* m, char* } ++buffer; --len; // one space - if (len>=strlen(SET_OPEN_FILES) && strncmp(buffer,SET_OPEN_FILES,strlen(SET_OPEN_FILES)) == 0) { - cli_incoming_set_max_open_files(buffer+strlen(SET_OPEN_FILES), len-strlen(SET_OPEN_FILES), m, replybuffer, outbufend); + if (len>=strlen(SET_MAX_OPEN_FILES) && strncmp(buffer,SET_MAX_OPEN_FILES,strlen(SET_MAX_OPEN_FILES)) == 0) { + cli_incoming_set_maxopenfiles(buffer+strlen(SET_MAX_OPEN_FILES), len-strlen(SET_MAX_OPEN_FILES), m, replybuffer, outbufend); } else if (len>=strlen(SET_MAX_SESSIONS) && strncmp(buffer,SET_MAX_SESSIONS,strlen(SET_MAX_SESSIONS)) == 0) { cli_incoming_set_maxsessions(buffer+strlen(SET_MAX_SESSIONS), len-strlen(SET_MAX_SESSIONS), m, replybuffer, outbufend); } else { From 06b129335af06f4a690886e420766ea13e3667ff Mon Sep 17 00:00:00 2001 From: smititelu Date: Fri, 20 Nov 2015 09:10:30 +0100 Subject: [PATCH 5/7] Update rtpengine-ctl util --- utils/rtpengine-ctl | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/utils/rtpengine-ctl b/utils/rtpengine-ctl index 4179197ab..3959bc3e7 100755 --- a/utils/rtpengine-ctl +++ b/utils/rtpengine-ctl @@ -62,8 +62,10 @@ sub showusage { print "\n"; print " Supported commands are:\n"; print "\n"; - print " list [ numsessions | sessions | session | totals ]\n"; - print " numsessions : prints the number of sessions\n"; + print " list [ numsessions | maxsessions | maxopenfiles | sessions | session | totals ]\n"; + print " numsessions : print the number of sessions\n"; + print " maxsessions : print the number of allowed sessions\n"; + print " maxopenfiles : print the number of allowed open files\n"; print " sessions : print one-liner session information\n"; print " session : print detail about one session\n"; print " totals : print total statistics\n"; @@ -72,8 +74,9 @@ sub showusage { print " all : terminates all current sessions\n"; print " : session is immediately terminated\n"; print "\n"; - print " set [ max-open-files ]\n"; - print " max-open-files : increase the max nr of allowed open files\n"; + print " set [ maxopenfiles | maxsessions ]\n"; + print " maxsessions : set the max nr of allowed sessions\n"; + print " maxopenfiles : set the max nr of allowed open files\n"; print "\n"; print "\n"; print " Return Value:\n"; From c969ab9f60a73e5815ca915ae59e69d818860aba Mon Sep 17 00:00:00 2001 From: smititelu Date: Tue, 24 Nov 2015 13:10:14 +0100 Subject: [PATCH 6/7] Change maxsessions feature behaviour * 0 will allow 0 sessions (e.g. can be used for draining rtpengine) * -1 will disable the feature and will be treated the same way as if MAX_SESSIONS variable has not been set via configuration file (or has been set to -1 in configuration file) * < -1 will not be taken into consideration * add check for minint range also --- daemon/call_interfaces.c | 2 +- daemon/cli.c | 19 +++++++++++++------ daemon/main.c | 5 ++++- daemon/str.h | 3 +++ 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index a98064d17..fa2783359 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -752,7 +752,7 @@ out: const char *call_offer_ng(bencode_item_t *input, struct callmaster *m, bencode_item_t *output, const char* addr, const struct sockaddr_in6 *sin) { - if (m->conf.max_sessions>0) { + if (m->conf.max_sessions>=0) { rwlock_lock_r(&m->hashlock); if (g_hash_table_size(m->callhash) >= m->conf.max_sessions) { rwlock_unlock_r(&m->hashlock); diff --git a/daemon/cli.c b/daemon/cli.c index ba3d1007e..7341c5596 100644 --- a/daemon/cli.c +++ b/daemon/cli.c @@ -286,6 +286,8 @@ static void cli_incoming_set_maxopenfiles(char* buffer, int len, struct callmast static void cli_incoming_set_maxsessions(char* buffer, int len, struct callmaster* m, char* replybuffer, const char* outbufend) { int printlen = 0; int maxsessions_num; + int err = 0x80000000; + int disabled = -1; str maxsessions; if (len<=1) { @@ -297,22 +299,27 @@ static void cli_incoming_set_maxsessions(char* buffer, int len, struct callmaste ++buffer; --len; // one space maxsessions.s = buffer; maxsessions.len = len; - maxsessions_num = str_to_i(&maxsessions, -1); + maxsessions_num = str_to_i(&maxsessions, err); - if (maxsessions_num == -1) { + if (maxsessions_num == err) { printlen = snprintf (replybuffer,(outbufend-replybuffer), "Fail setting maxsessions to %.*s; not an integer\n", maxsessions.len, maxsessions.s); ADJUSTLEN(printlen,outbufend,replybuffer); - return; - } else if (maxsessions_num < 0) { - printlen = snprintf (replybuffer,(outbufend-replybuffer), "Fail setting maxsessions to %d; negative value\n", maxsessions_num); + } else if (maxsessions_num < disabled) { + printlen = snprintf (replybuffer,(outbufend-replybuffer), "Fail setting maxsessions to %d; either positive or -1 values allowed\n", maxsessions_num); + ADJUSTLEN(printlen,outbufend,replybuffer); + } else if (maxsessions_num == disabled) { + /* don't lock anything while writing the value - only this command modifies its value */ + m->conf.max_sessions = maxsessions_num; + printlen = snprintf (replybuffer,(outbufend-replybuffer), "Success setting maxsessions to %d; disable feature\n", maxsessions_num); ADJUSTLEN(printlen,outbufend,replybuffer); - return; } else { /* don't lock anything while writing the value - only this command modifies its value */ m->conf.max_sessions = maxsessions_num; printlen = snprintf (replybuffer,(outbufend-replybuffer), "Success setting maxsessions to %d\n", maxsessions_num); ADJUSTLEN(printlen,outbufend,replybuffer); } + + return; } static void cli_incoming_list(char* buffer, int len, struct callmaster* m, char* replybuffer, const char* outbufend) { diff --git a/daemon/main.c b/daemon/main.c index 3b671e397..b31260ab0 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -72,7 +72,7 @@ static int timeout; static int silent_timeout; static int port_min = 30000; static int port_max = 40000; -static int max_sessions = 0; +static int max_sessions = -1; static u_int32_t redis_ip; static u_int16_t redis_port; static int redis_db = -1; @@ -530,6 +530,9 @@ no_kernel: mc.interfaces = &interfaces; mc.port_min = port_min; mc.port_max = port_max; + if (max_sessions < -1) { + max_sessions = -1; + } mc.max_sessions = max_sessions; mc.timeout = timeout; mc.silent_timeout = silent_timeout; diff --git a/daemon/str.h b/daemon/str.h index 90b449374..ff017445c 100644 --- a/daemon/str.h +++ b/daemon/str.h @@ -248,6 +248,7 @@ INLINE int str_to_i(str *s, int def) { char c, *ep; long ret; int maxint = 0x7FFFFFFF; + int minint = 0x80000000; if (s->len <= 0) return def; c = s->s[s->len]; @@ -258,6 +259,8 @@ INLINE int str_to_i(str *s, int def) { return def; if (ret > maxint) return def; + if (ret < minint) + return def; return ret; } From 32a42993dc6f417f0ebfc05d387ddab2fc8d3b44 Mon Sep 17 00:00:00 2001 From: smititelu Date: Tue, 24 Nov 2015 17:02:56 +0100 Subject: [PATCH 7/7] Update README.md for --max-sessions --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 9ea866401..d8e4596ef 100644 --- a/README.md +++ b/README.md @@ -376,6 +376,16 @@ The options are described in more detail below. Add a prefix for every graphite line. +* --max-sessions + + Limit the number of maximum concurrent sessions. Set at startup via MAX_SESSIONS in config file. Set at runtime via rtpengine-ctl util. + Setting the 'rtpengine-ctl set maxsessions 0' can be used in draining rtpengine sessions. + Enable feature: 'MAX_SESSIONS=1000' + Enable feature: 'rtpengine-ctl set maxsessions' >=0 + Disable feature: 'rtpengine-ctl set maxsessions -1' + By default, the feature is disabled (i.e. maxsessions == -1). + + A typical command line (enabling both UDP and NG protocols) thus may look like: /usr/sbin/rtpengine --table=0 --interface=10.64.73.31 --interface=2001:db8::4f3:3d \