diff --git a/app/src/main/jni/netguard/netguard.h b/app/src/main/jni/netguard/netguard.h index 2844a395..79b5d6a9 100644 --- a/app/src/main/jni/netguard/netguard.h +++ b/app/src/main/jni/netguard/netguard.h @@ -136,7 +136,6 @@ struct udp_session { struct tcp_session { jint uid; time_t time; - time_t keep_alive; int version; uint16_t recv_window; // host notation uint16_t send_window; // host notation diff --git a/app/src/main/jni/netguard/tcp.c b/app/src/main/jni/netguard/tcp.c index e2397478..67abfce1 100644 --- a/app/src/main/jni/netguard/tcp.c +++ b/app/src/main/jni/netguard/tcp.c @@ -65,12 +65,9 @@ int get_tcp_timeout(const struct tcp_session *t, int sessions, int maxsessions) int timeout; if (t->state == TCP_LISTEN || t->state == TCP_SYN_RECV) timeout = TCP_INIT_TIMEOUT; - else if (t->state == TCP_ESTABLISHED) { - if (t->keep_alive) - timeout = TCP_IDLE_TIMEOUT; - else - timeout = TCP_IDLE_TIMEOUT / 2; - } else + else if (t->state == TCP_ESTABLISHED) + timeout = TCP_IDLE_TIMEOUT; + else timeout = TCP_CLOSE_TIMEOUT; int scale = 100 - sessions * 100 / maxsessions; @@ -101,42 +98,30 @@ void check_tcp_sessions(const struct arguments *args, int sessions, int maxsessi int timeout = get_tcp_timeout(t, sessions, maxsessions); - // Keep alive - if (t->state == TCP_ESTABLISHED && t->keep_alive == 0 && t->time + timeout < now) { - log_android(ANDROID_LOG_WARN, "%s keep alive %d/%d sec ", - session, now - t->time, timeout); - t->keep_alive = time(NULL); - t->local_seq--; - write_ack(args, t); - t->local_seq++; - + // Check session timeout + if (t->state != TCP_CLOSING && t->state != TCP_CLOSE && t->time + timeout < now) { + log_android(ANDROID_LOG_WARN, "%s idle %d/%d sec ", session, now - t->time, + timeout); + if (t->state == TCP_LISTEN) + t->state = TCP_CLOSING; + else + write_rst(args, t); } - else { - // Check session timeout - if (t->state != TCP_CLOSING && t->state != TCP_CLOSE && t->time + timeout < now) { - log_android(ANDROID_LOG_WARN, "%s idle %d/%d sec ", session, now - t->time, - timeout); - if (t->state == TCP_LISTEN) - t->state = TCP_CLOSING; + + // Check closing sessions + if (t->state == TCP_CLOSING) { + // eof closes socket + if (t->socket >= 0) { + if (close(t->socket)) + log_android(ANDROID_LOG_ERROR, "%s close error %d: %s", + session, errno, strerror(errno)); else - write_rst(args, t); + log_android(ANDROID_LOG_WARN, "%s close", session); + t->socket = -1; } - // Check closing sessions - if (t->state == TCP_CLOSING) { - // eof closes socket - if (t->socket >= 0) { - if (close(t->socket)) - log_android(ANDROID_LOG_ERROR, "%s close error %d: %s", - session, errno, strerror(errno)); - else - log_android(ANDROID_LOG_WARN, "%s close", session); - t->socket = -1; - } - - t->time = time(NULL); - t->state = TCP_CLOSE; - } + t->time = time(NULL); + t->state = TCP_CLOSE; } if ((t->state == TCP_CLOSING || t->state == TCP_CLOSE) && (t->sent || t->received)) { @@ -467,7 +452,6 @@ jboolean handle_tcp(const struct arguments *args, // Register session struct tcp_session *syn = malloc(sizeof(struct tcp_session)); syn->time = time(NULL); - syn->keep_alive = 0; syn->uid = uid; syn->version = version; syn->recv_window = TCP_RECV_WINDOW; @@ -571,21 +555,6 @@ jboolean handle_tcp(const struct arguments *args, cur->time = time(NULL); cur->send_window = ntohs(tcphdr->window); - // Enable socket keep alive - if (cur->keep_alive) { - cur->keep_alive = 0; - - if (cur->state == TCP_ESTABLISHED) { - int on = 1; - if (setsockopt(cur->socket, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on))) - log_android(ANDROID_LOG_ERROR, - "%s setsockopt SO_KEEPALIVE error %d: %s", - session, errno, strerror(errno)); - else - log_android(ANDROID_LOG_WARN, "%s enabled keep alive", session); - } - } - // Do not change the order of the conditions // Queue data to forward