2013-05-28 19:34:26 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2024-05-22 17:15:14 +02:00
|
|
|
;; Copyright (C) KolibriOS team 2004-2024. All rights reserved. ;;
|
2013-05-28 19:34:26 +02:00
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
|
|
|
;; Part of the TCP/IP network stack for KolibriOS ;;
|
|
|
|
;; ;;
|
|
|
|
;; Written by hidnplayr@kolibrios.org ;;
|
|
|
|
;; ;;
|
|
|
|
;; Based on the code of 4.4BSD ;;
|
|
|
|
;; ;;
|
|
|
|
;; GNU GENERAL PUBLIC LICENSE ;;
|
|
|
|
;; Version 2, June 1991 ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
|
2013-06-04 16:12:37 +02:00
|
|
|
timer_flag_retransmission = 1 shl 0
|
|
|
|
timer_flag_keepalive = 1 shl 1
|
|
|
|
timer_flag_2msl = 1 shl 2
|
|
|
|
timer_flag_persist = 1 shl 3
|
|
|
|
timer_flag_wait = 1 shl 4
|
|
|
|
|
|
|
|
|
2015-12-27 16:37:31 +01:00
|
|
|
macro tcp_timer_160ms {
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
local .loop
|
|
|
|
local .exit
|
|
|
|
|
|
|
|
mov ebx, net_sockets
|
|
|
|
.loop:
|
|
|
|
mov ebx, [ebx + SOCKET.NextPtr]
|
2013-06-04 16:12:37 +02:00
|
|
|
test ebx, ebx
|
2013-05-28 19:34:26 +02:00
|
|
|
jz .exit
|
|
|
|
|
|
|
|
cmp [ebx + SOCKET.Domain], AF_INET4
|
|
|
|
jne .loop
|
|
|
|
cmp [ebx + SOCKET.Protocol], IP_PROTO_TCP
|
|
|
|
jne .loop
|
|
|
|
test [ebx + TCP_SOCKET.t_flags], TF_DELACK
|
|
|
|
jz .loop
|
2013-06-04 16:12:37 +02:00
|
|
|
|
2013-05-28 19:34:26 +02:00
|
|
|
and [ebx + TCP_SOCKET.t_flags], not (TF_DELACK)
|
2017-10-17 21:59:47 +02:00
|
|
|
or [ebx + TCP_SOCKET.t_flags], TF_ACKNOW
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
push ebx
|
2017-10-17 21:59:47 +02:00
|
|
|
mov eax, ebx
|
|
|
|
call tcp_output
|
2013-05-28 19:34:26 +02:00
|
|
|
pop ebx
|
|
|
|
|
2015-02-21 16:07:30 +01:00
|
|
|
inc [TCPS_delack] ; update stats
|
|
|
|
|
2013-05-28 19:34:26 +02:00
|
|
|
jmp .loop
|
|
|
|
|
|
|
|
.exit:
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-30 11:44:18 +02:00
|
|
|
align 4
|
2015-12-27 16:37:31 +01:00
|
|
|
proc tcp_timer_640ms
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2014-07-30 11:44:18 +02:00
|
|
|
xor esi, esi
|
|
|
|
mov ecx, MANUAL_DESTROY
|
|
|
|
call create_event
|
|
|
|
mov [TCP_timer1_event], eax
|
|
|
|
|
|
|
|
.wait:
|
|
|
|
mov eax, [TCP_timer1_event]
|
|
|
|
mov ebx, [eax + EVENT.id]
|
|
|
|
call wait_event
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
; Update TCP sequence number
|
|
|
|
|
|
|
|
add [TCP_sequence_num], 64000
|
|
|
|
|
2015-12-27 16:37:31 +01:00
|
|
|
; Scan through all the active TCP sockets, decrementing all active timers
|
|
|
|
; When a timer reaches zero, run its handler.
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
mov eax, net_sockets
|
|
|
|
.loop:
|
|
|
|
mov eax, [eax + SOCKET.NextPtr]
|
|
|
|
.check_only:
|
|
|
|
or eax, eax
|
2014-07-30 11:44:18 +02:00
|
|
|
jz .wait
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
cmp [eax + SOCKET.Domain], AF_INET4
|
|
|
|
jne .loop
|
|
|
|
|
|
|
|
cmp [eax + SOCKET.Protocol], IP_PROTO_TCP
|
|
|
|
jne .loop
|
|
|
|
|
|
|
|
inc [eax + TCP_SOCKET.t_idle]
|
2013-06-04 16:12:37 +02:00
|
|
|
|
|
|
|
test [eax + TCP_SOCKET.timer_flags], timer_flag_retransmission
|
|
|
|
jz .check_more2
|
2015-12-27 16:37:31 +01:00
|
|
|
dec [eax + TCP_SOCKET.timer_retransmission]
|
|
|
|
jnz .check_more2
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2013-05-28 21:19:23 +02:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: Retransmission timer expired\n", eax
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
push eax
|
2015-12-27 16:37:31 +01:00
|
|
|
call tcp_output
|
2013-05-28 19:34:26 +02:00
|
|
|
pop eax
|
|
|
|
|
|
|
|
.check_more2:
|
2013-06-04 16:12:37 +02:00
|
|
|
test [eax + TCP_SOCKET.timer_flags], timer_flag_keepalive
|
|
|
|
jz .check_more3
|
2015-12-27 16:37:31 +01:00
|
|
|
dec [eax + TCP_SOCKET.timer_keepalive]
|
|
|
|
jnz .check_more3
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2013-05-28 21:19:23 +02:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: Keepalive expired\n", eax
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
cmp [eax + TCP_SOCKET.state], TCPS_ESTABLISHED
|
|
|
|
ja .dont_kill
|
|
|
|
|
|
|
|
push eax
|
2015-12-27 16:37:31 +01:00
|
|
|
call tcp_disconnect
|
2013-05-28 19:34:26 +02:00
|
|
|
pop eax
|
|
|
|
jmp .loop
|
|
|
|
|
|
|
|
.dont_kill:
|
|
|
|
test [eax + SOCKET.options], SO_KEEPALIVE
|
|
|
|
jz .reset_keepalive
|
|
|
|
|
|
|
|
push eax
|
|
|
|
mov ebx, eax
|
|
|
|
xor cl, cl
|
2015-12-27 16:37:31 +01:00
|
|
|
call tcp_respond ; send keepalive
|
2013-05-28 19:34:26 +02:00
|
|
|
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:
|
2013-06-04 16:12:37 +02:00
|
|
|
test [eax + TCP_SOCKET.timer_flags], timer_flag_2msl
|
|
|
|
jz .check_more5
|
2015-12-27 16:37:31 +01:00
|
|
|
dec [eax + TCP_SOCKET.timer_timed_wait]
|
|
|
|
jnz .check_more5
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2013-05-28 21:19:23 +02:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: 2MSL timer expired\n", eax
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
.check_more5:
|
2013-06-04 16:12:37 +02:00
|
|
|
test [eax + TCP_SOCKET.timer_flags], timer_flag_persist
|
2015-12-16 22:20:53 +01:00
|
|
|
jz .check_more6
|
2015-12-27 16:37:31 +01:00
|
|
|
dec [eax + TCP_SOCKET.timer_persist]
|
|
|
|
jnz .check_more6
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2013-05-28 21:19:23 +02:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: persist timer expired\n", eax
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-12-27 16:37:31 +01:00
|
|
|
call tcp_set_persist
|
2017-05-31 19:54:16 +02:00
|
|
|
or [eax + TCP_SOCKET.t_flags], TF_FORCE
|
2013-05-28 19:34:26 +02:00
|
|
|
push eax
|
2015-12-27 16:37:31 +01:00
|
|
|
call tcp_output
|
2013-05-28 19:34:26 +02:00
|
|
|
pop eax
|
2017-05-31 19:54:16 +02:00
|
|
|
and [eax + TCP_SOCKET.t_flags], not TF_FORCE
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-12-16 22:20:53 +01:00
|
|
|
.check_more6:
|
|
|
|
test [eax + TCP_SOCKET.timer_flags], timer_flag_wait
|
|
|
|
jz .loop
|
2015-12-27 16:37:31 +01:00
|
|
|
dec [eax + TCP_SOCKET.timer_timed_wait]
|
|
|
|
jnz .loop
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-12-16 22:20:53 +01:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: timed wait timer expired\n", eax
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-12-16 22:20:53 +01:00
|
|
|
push [eax + SOCKET.NextPtr]
|
2015-12-27 16:37:31 +01:00
|
|
|
call tcp_close
|
2015-12-16 22:20:53 +01:00
|
|
|
pop eax
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-12-16 22:20:53 +01:00
|
|
|
jmp .check_only
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-12-16 22:20:53 +01:00
|
|
|
endp
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-12-16 22:20:53 +01:00
|
|
|
|
|
|
|
;-----------------------------------------------------------------;
|
|
|
|
; ;
|
|
|
|
; TCP_cancel_timers ;
|
|
|
|
; ;
|
|
|
|
; IN: eax = socket ;
|
|
|
|
; ;
|
|
|
|
; OUT: / ;
|
|
|
|
; ;
|
|
|
|
;-----------------------------------------------------------------;
|
|
|
|
align 4
|
2015-12-27 16:37:31 +01:00
|
|
|
tcp_cancel_timers:
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2013-06-04 16:12:37 +02:00
|
|
|
mov [eax + TCP_SOCKET.timer_flags], 0
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2024-05-22 17:15:14 +02:00
|
|
|
ret
|