From 14077f9230f447ecfafeef0c1b32517c5238ba0c Mon Sep 17 00:00:00 2001 From: hidnplayr Date: Fri, 28 Dec 2012 19:56:52 +0000 Subject: [PATCH] Fixed TCP keepalive git-svn-id: svn://kolibrios.org@3143 a494cfbc-eb01-0410-851d-a64ba20cac60 --- kernel/branches/net/network/IPv4.inc | 2 +- kernel/branches/net/network/socket.inc | 13 ++++++------ kernel/branches/net/network/tcp.inc | 4 ++-- kernel/branches/net/network/tcp_input.inc | 8 ++++---- kernel/branches/net/network/tcp_output.inc | 2 +- kernel/branches/net/network/tcp_subr.inc | 6 +++--- kernel/branches/net/network/tcp_timer.inc | 24 +++++++++++++++++++--- 7 files changed, 39 insertions(+), 20 deletions(-) diff --git a/kernel/branches/net/network/IPv4.inc b/kernel/branches/net/network/IPv4.inc index 9cb5c55b2d..3045c9fac6 100644 --- a/kernel/branches/net/network/IPv4.inc +++ b/kernel/branches/net/network/IPv4.inc @@ -5,7 +5,7 @@ ;; ;; ;; IPv4.INC ;; ;; ;; -;; Part of the tcp/ip network stack for KolibriOS ;; +;; Part of the TCP/IP network stack for KolibriOS ;; ;; ;; ;; Based on the work of [Johnny_B] and [smb] ;; ;; ;; diff --git a/kernel/branches/net/network/socket.inc b/kernel/branches/net/network/socket.inc index 50a1d0f9ce..209a11a4e7 100644 --- a/kernel/branches/net/network/socket.inc +++ b/kernel/branches/net/network/socket.inc @@ -3,7 +3,7 @@ ;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;; ;; Distributed under terms of the GNU General Public License ;; ;; ;; -;; Part of the tcp/ip network stack for KolibriOS ;; +;; Part of the TCP/IP network stack for KolibriOS ;; ;; ;; ;; Written by hidnplayr@kolibrios.org, ;; ;; and Clevermouse. ;; @@ -238,10 +238,11 @@ macro SOCKET_block socket, loop, done { test [socket + SOCKET.options], SO_BLOCK ; Is this a blocking socket? jz done ; No, return immediately - push esi - mov esi, 5 ; yes, wait for event - call delay_ms - pop esi + pusha + mov eax, EVENT_NETWORK + mov ebx, 1337 ; UID: ???? + call wait_event + popa jmp loop @@ -1199,7 +1200,7 @@ SOCKET_check_port: cmp [esi + UDP_SOCKET.LocalPort], bx jne .next_socket - DEBUGF 1,"local port %u already in use\n", bx + DEBUGF 1,"local port %x already in use\n", bx ; FIXME: find a way to print big endian values with debugf ret .port_ok: diff --git a/kernel/branches/net/network/tcp.inc b/kernel/branches/net/network/tcp.inc index 05188c6980..f0e14a329e 100644 --- a/kernel/branches/net/network/tcp.inc +++ b/kernel/branches/net/network/tcp.inc @@ -3,7 +3,7 @@ ;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;; ;; Distributed under terms of the GNU General Public License ;; ;; ;; -;; Part of the tcp/ip network stack for KolibriOS ;; +;; Part of the TCP/IP network stack for KolibriOS ;; ;; ;; ;; Written by hidnplayr@kolibrios.org ;; ;; ;; @@ -64,7 +64,7 @@ TCP_time_re_min = 2 ; min retransmission (1,28s) TCP_time_re_max = 100 ; max retransmission (64s) TCP_time_pers_min = 8 ; min persist (5,12s) TCP_time_pers_max = 94 ; max persist (60,16s) -TCP_time_keep_init = 118 ; connectione stablishment (75,52s) +TCP_time_keep_init = 118 ; connection establishment (75,52s) TCP_time_keep_idle = 4608 ; idle time before 1st probe (2h) TCP_time_keep_interval = 118 ; between probes when no response (75,52s) TCP_time_rtt_default = 5 ; default Round Trip Time (3,2s) diff --git a/kernel/branches/net/network/tcp_input.inc b/kernel/branches/net/network/tcp_input.inc index e482ee8340..e2e2c9c056 100644 --- a/kernel/branches/net/network/tcp_input.inc +++ b/kernel/branches/net/network/tcp_input.inc @@ -3,7 +3,7 @@ ;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;; ;; Distributed under terms of the GNU General Public License ;; ;; ;; -;; Part of the tcp/ip network stack for KolibriOS ;; +;; Part of the TCP/IP network stack for KolibriOS ;; ;; ;; ;; Written by hidnplayr@kolibrios.org ;; ;; ;; @@ -191,7 +191,7 @@ TCP_input: ; Reset idle timer and keepalive timer mov [ebx + TCP_SOCKET.t_idle], 0 - mov [ebx + TCP_SOCKET.timer_keepalive], TCP_time_keep_interval + mov [ebx + TCP_SOCKET.timer_keepalive], TCP_time_keep_idle ;-------------------- ; Process TCP options @@ -1501,7 +1501,7 @@ align 4 .respond_ack: push ebx mov cl, TH_RST - call TCP_respond_socket + call TCP_respond pop ebx jmp .destroy_new_socket @@ -1509,7 +1509,7 @@ align 4 .respond_syn: push ebx mov cl, TH_RST + TH_ACK - call TCP_respond_socket + call TCP_respond pop ebx jmp .destroy_new_socket diff --git a/kernel/branches/net/network/tcp_output.inc b/kernel/branches/net/network/tcp_output.inc index 0570b3c6aa..c63807d107 100644 --- a/kernel/branches/net/network/tcp_output.inc +++ b/kernel/branches/net/network/tcp_output.inc @@ -3,7 +3,7 @@ ;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;; ;; Distributed under terms of the GNU General Public License ;; ;; ;; -;; Part of the tcp/ip network stack for KolibriOS ;; +;; Part of the TCP/IP network stack for KolibriOS ;; ;; ;; ;; Written by hidnplayr@kolibrios.org ;; ;; ;; diff --git a/kernel/branches/net/network/tcp_subr.inc b/kernel/branches/net/network/tcp_subr.inc index 128bf05e88..5bedabeaac 100644 --- a/kernel/branches/net/network/tcp_subr.inc +++ b/kernel/branches/net/network/tcp_subr.inc @@ -3,7 +3,7 @@ ;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;; ;; Distributed under terms of the GNU General Public License ;; ;; ;; -;; Part of the tcp/ip network stack for KolibriOS ;; +;; Part of the TCP/IP network stack for KolibriOS ;; ;; ;; ;; Written by hidnplayr@kolibrios.org ;; ;; ;; @@ -319,14 +319,14 @@ TCP_outflags: ; ; The fast way to send an ACK/RST/keepalive segment ; -; TCP_respond_socket: +; TCP_respond ; ; IN: ebx = socket ptr ; cl = flags ; ;-------------------------------------- align 4 -TCP_respond_socket: +TCP_respond: DEBUGF 1,"TCP_respond_socket: socket=%x flags=%x\n", ebx, cl diff --git a/kernel/branches/net/network/tcp_timer.inc b/kernel/branches/net/network/tcp_timer.inc index 1e8b46e7bc..388aa456b3 100644 --- a/kernel/branches/net/network/tcp_timer.inc +++ b/kernel/branches/net/network/tcp_timer.inc @@ -1,9 +1,9 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; -;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;; +;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;; ;; Distributed under terms of the GNU General Public License ;; ;; ;; -;; Part of the tcp/ip network stack for KolibriOS ;; +;; Part of the TCP/IP network stack for KolibriOS ;; ;; ;; ;; Written by hidnplayr@kolibrios.org ;; ;; ;; @@ -42,7 +42,7 @@ local .exit push ebx mov cl, TH_ACK - call TCP_respond_socket + call TCP_respond ; and [ebx + TCP_SOCKET.t_flags], TF_ACKNOW ;; ; mov eax, ebx ;; ; call TCP_output ;; @@ -99,11 +99,29 @@ local .exit DEBUGF 1,"socket %x: Keepalive expired\n", eax + cmp [eax + TCP_SOCKET.state], TCPS_ESTABLISHED + ja .dont_kill + push eax call TCP_disconnect pop eax jmp .loop + .dont_kill: + test [eax + SOCKET.options], SO_KEEPALIVE + jz .reset_keepalive + + push eax + mov ebx, eax + xor cl, cl + call TCP_respond ; send keepalive + pop eax + mov [eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_interval + jmp .check_more3 + + .reset_keepalive: + mov [eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_idle + .check_more3: dec [eax + TCP_SOCKET.timer_timed_wait] jnz .check_more5