1
0
Fork 0
mirror of https://github.com/M66B/NetGuard.git synced 2025-01-30 19:31:26 +00:00

Limit number of sessions to 768

This commit is contained in:
M66B 2017-08-12 13:49:02 +02:00
parent 0f5fa4bfe9
commit 51d6dac142
2 changed files with 8 additions and 6 deletions

View file

@ -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

View file

@ -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);