mirror of
https://github.com/M66B/NetGuard.git
synced 2025-01-01 12:54:07 +00:00
TCP keep alive
This commit is contained in:
parent
07e0a46e6e
commit
935df7491c
2 changed files with 19 additions and 2 deletions
|
@ -50,10 +50,11 @@
|
|||
#define UDP_KEEP_TIMEOUT 60 // seconds
|
||||
|
||||
#define TCP_INIT_TIMEOUT 30 // seconds ~net.inet.tcp.keepinit
|
||||
#define TCP_IDLE_TIMEOUT 3600 // seconds ~net.inet.tcp.keepidle
|
||||
#define TCP_IDLE_TIMEOUT 29 // seconds ~net.inet.tcp.keepidle
|
||||
#define TCP_CLOSE_TIMEOUT 30 // seconds
|
||||
#define TCP_KEEP_TIMEOUT 300 // seconds
|
||||
// https://en.wikipedia.org/wiki/Maximum_segment_lifetime
|
||||
#define TCP_KEEP_ALIVE 30 // seconds
|
||||
|
||||
#define UID_DELAY 1 // milliseconds
|
||||
#define UID_DELAYTRY 10 // milliseconds
|
||||
|
|
|
@ -128,8 +128,11 @@ int monitor_tcp_session(const struct arguments *args, struct ng_session *s, int
|
|||
}
|
||||
else if (s->tcp.state == TCP_ESTABLISHED || s->tcp.state == TCP_CLOSE_WAIT) {
|
||||
|
||||
uint32_t rwindow = get_receive_window(s);
|
||||
uint32_t swindow = get_send_window(&s->tcp);
|
||||
|
||||
// Check for incoming data
|
||||
if (get_send_window(&s->tcp) > 0)
|
||||
if (swindow > 0)
|
||||
events = events | EPOLLIN;
|
||||
else {
|
||||
recheck = 1;
|
||||
|
@ -153,6 +156,19 @@ int monitor_tcp_session(const struct arguments *args, struct ng_session *s, int
|
|||
else
|
||||
recheck = 1;
|
||||
}
|
||||
|
||||
// Keep alive
|
||||
if (rwindow > 0 && swindow > 0) {
|
||||
long long ms = get_ms();
|
||||
if (s->tcp.time + TCP_KEEP_ALIVE < time(NULL) &&
|
||||
ms - s->tcp.last_keep_alive > TCP_KEEP_ALIVE * 1000) {
|
||||
s->tcp.last_keep_alive = ms;
|
||||
log_android(ANDROID_LOG_WARN, "Sending keep alive");
|
||||
s->tcp.remote_seq--;
|
||||
write_ack(args, &s->tcp);
|
||||
s->tcp.remote_seq++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (events != s->ev.events) {
|
||||
|
|
Loading…
Reference in a new issue