From c444c05a5f14ca211e6a9aac93be9b19b242fafd Mon Sep 17 00:00:00 2001 From: Frederic-Philippe Metz Date: Mon, 4 May 2015 14:26:05 +0200 Subject: [PATCH] Implemented MAX_SESSIONS limit or calls. related to RTPENGINE-20 --- daemon/call.h | 1 + daemon/call_interfaces.c | 12 ++++++++++++ daemon/main.c | 3 +++ debian/ngcp-rtpengine-daemon.default | 1 + debian/ngcp-rtpengine-daemon.init | 2 ++ el/rtpengine.init | 5 +++++ 6 files changed, 24 insertions(+) diff --git a/daemon/call.h b/daemon/call.h index ab9ab85bd..40c0ca699 100644 --- a/daemon/call.h +++ b/daemon/call.h @@ -426,6 +426,7 @@ struct callmaster_config { GQueue *interfaces; /* struct interface_address */ int port_min; int port_max; + int max_sessions; unsigned int timeout; unsigned int silent_timeout; unsigned int delete_delay; diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index f9f495803..242a82134 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -691,6 +691,18 @@ 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) { + static char *errstr[64]; memset(errstr,0,64); + + 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); + ilog(LOG_ERROR, "Parallel session limit reached (%i)",m->conf.max_sessions); + snprintf(errstr, 64, "Parallel session limit reached (%i)",m->conf.max_sessions); + return errstr; + } + rwlock_unlock_r(&m->hashlock); + } return call_offer_answer_ng(input, m, output, OP_OFFER, addr, sin); } diff --git a/daemon/main.c b/daemon/main.c index 660080128..a0b7cf58a 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -101,6 +101,7 @@ static int timeout; static int silent_timeout; static int port_min = 30000; static int port_max = 40000; +static int max_sessions = 0; static u_int32_t redis_ip; static u_int16_t redis_port; static int redis_db = -1; @@ -297,6 +298,7 @@ static void options(int *argc, char ***argv) { { "delete-delay", 'd', 0, G_OPTION_ARG_INT, &delete_delay, "Delay for deleting a session from memory.", "INT" }, { "sip-source", 0, 0, G_OPTION_ARG_NONE, &sip_source, "Use SIP source address by default", NULL }, { "dtls-passive", 0, 0, G_OPTION_ARG_NONE, &dtls_passive_def,"Always prefer DTLS passive role", NULL }, + { "max-sessions", 0, 0, G_OPTION_ARG_INT, &max_sessions, "Limit of maximum number of sessions", NULL }, { NULL, } }; @@ -572,6 +574,7 @@ no_kernel: mc.interfaces = &interfaces; mc.port_min = port_min; mc.port_max = port_max; + mc.max_sessions = max_sessions; mc.timeout = timeout; mc.silent_timeout = silent_timeout; mc.delete_delay = delete_delay; diff --git a/debian/ngcp-rtpengine-daemon.default b/debian/ngcp-rtpengine-daemon.default index d06a56e74..afa883027 100644 --- a/debian/ngcp-rtpengine-daemon.default +++ b/debian/ngcp-rtpengine-daemon.default @@ -27,3 +27,4 @@ TABLE=0 # GRAPHITE=9006 # GRAPHITE_INTERVAL=60 # GRAPHITE_PREFIX=myownprefix +# MAX_SESSIONS=5000 diff --git a/debian/ngcp-rtpengine-daemon.init b/debian/ngcp-rtpengine-daemon.init index f3001db7f..7be49ea14 100755 --- a/debian/ngcp-rtpengine-daemon.init +++ b/debian/ngcp-rtpengine-daemon.init @@ -76,6 +76,8 @@ OPTIONS="$OPTIONS --table=$TABLE" [ -z "$GRAPHITE" ] || OPTIONS="$OPTIONS --graphite=$GRAPHITE" [ -z "$GRAPHITE_INTERVAL" ] || OPTIONS="$OPTIONS --graphite-interval=$GRAPHITE_INTERVAL" [ -z "$GRAPHITE_PREFIX" ] || OPTIONS="$OPTIONS --graphite-prefix=$GRAPHITE_PREFIX" +[ -z "$MAX_SESSIONS" ] || OPTIONS="$OPTIONS --max-sessions=$MAX_SESSIONS" + if test "$FORK" = "no" ; then OPTIONS="$OPTIONS --foreground" fi diff --git a/el/rtpengine.init b/el/rtpengine.init index 3cf2930ad..cf3ff51c1 100644 --- a/el/rtpengine.init +++ b/el/rtpengine.init @@ -167,6 +167,11 @@ build_opts() { then OPTS+=" --log-facility-rtcp=$LOG_FACILITY_RTCP" fi + + if [[ -n "$MAX_SESSIONS" ]] + then + OPTS+=" --max-sessions=$MAX_SESSIONS" + fi } start() {