From 51d6dac142d253dfdd5127bf4d6670ccbf44e72a Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 12 Aug 2017 13:49:02 +0200 Subject: [PATCH] Limit number of sessions to 768 --- app/src/main/jni/netguard/netguard.h | 1 + app/src/main/jni/netguard/session.c | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/src/main/jni/netguard/netguard.h b/app/src/main/jni/netguard/netguard.h index 6587a076..b4d5affb 100644 --- a/app/src/main/jni/netguard/netguard.h +++ b/app/src/main/jni/netguard/netguard.h @@ -55,6 +55,7 @@ #define TCP_KEEP_TIMEOUT 300 // seconds // https://en.wikipedia.org/wiki/Maximum_segment_lifetime +#define SESSION_MAX 768 // number #define SESSION_LIMIT 40 // percent #define SOCKS5_NONE 1 diff --git a/app/src/main/jni/netguard/session.c b/app/src/main/jni/netguard/session.c index 76284e3b..3f90d5c5 100644 --- a/app/src/main/jni/netguard/session.c +++ b/app/src/main/jni/netguard/session.c @@ -58,17 +58,18 @@ void *handle_events(void *a) { } args->env = env; - // Get max sessions - int maxsessions = 1024; + // Get max number of sessions + int maxsessions = SESSION_MAX; struct rlimit rlim; if (getrlimit(RLIMIT_NOFILE, &rlim)) log_android(ANDROID_LOG_WARN, "getrlimit error %d: %s", errno, strerror(errno)); - else + else { + maxsessions = (int) (rlim.rlim_cur * SESSION_LIMIT / 100); + if (maxsessions > SESSION_MAX) + maxsessions = SESSION_MAX; log_android(ANDROID_LOG_WARN, "getrlimit soft %d hard %d max sessions %d", rlim.rlim_cur, rlim.rlim_max, maxsessions); - maxsessions = (int) (rlim.rlim_cur * SESSION_LIMIT / 100); - if (maxsessions > 1000) - maxsessions = 1000; + } // Terminate existing sessions not allowed anymore check_allowed(args);