2013-05-28 23:09:31 +04:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2015-06-01 22:18:07 +03:00
|
|
|
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
|
2013-05-28 23:09:31 +04: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 ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2016-01-19 01:18:04 +03:00
|
|
|
$Revision: 6011 $
|
2013-05-28 23:09:31 +04:00
|
|
|
|
2013-06-08 17:00:38 +04: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
|
|
|
|
|
|
|
|
|
2016-01-19 01:18:04 +03:00
|
|
|
macro tcp_timer_160ms {
|
2013-05-28 23:09:31 +04:00
|
|
|
|
|
|
|
local .loop
|
|
|
|
local .exit
|
|
|
|
|
|
|
|
mov ebx, net_sockets
|
|
|
|
.loop:
|
|
|
|
mov ebx, [ebx + SOCKET.NextPtr]
|
2013-06-08 17:00:38 +04:00
|
|
|
test ebx, ebx
|
2013-05-28 23:09:31 +04: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-08 17:00:38 +04:00
|
|
|
|
2013-05-28 23:09:31 +04:00
|
|
|
and [ebx + TCP_SOCKET.t_flags], not (TF_DELACK)
|
|
|
|
|
|
|
|
push ebx
|
|
|
|
mov cl, TH_ACK
|
2016-01-19 01:18:04 +03:00
|
|
|
call tcp_respond
|
2013-05-28 23:09:31 +04:00
|
|
|
pop ebx
|
|
|
|
|
2015-06-01 22:18:07 +03:00
|
|
|
inc [TCPS_delack] ; update stats
|
|
|
|
|
2013-05-28 23:09:31 +04:00
|
|
|
jmp .loop
|
|
|
|
|
|
|
|
.exit:
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-01 06:51:07 +03:00
|
|
|
align 4
|
2016-01-19 01:18:04 +03:00
|
|
|
proc tcp_timer_640ms
|
2013-05-28 23:09:31 +04:00
|
|
|
|
2014-12-01 06:51:07 +03: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 23:09:31 +04:00
|
|
|
|
|
|
|
; Update TCP sequence number
|
|
|
|
|
|
|
|
add [TCP_sequence_num], 64000
|
|
|
|
|
2016-01-19 01:18:04 +03:00
|
|
|
; Scan through all the active TCP sockets, decrementing all active timers
|
|
|
|
; When a timer reaches zero, run its handler.
|
2013-05-28 23:09:31 +04:00
|
|
|
|
|
|
|
mov eax, net_sockets
|
|
|
|
.loop:
|
|
|
|
mov eax, [eax + SOCKET.NextPtr]
|
|
|
|
.check_only:
|
|
|
|
or eax, eax
|
2014-12-01 06:51:07 +03:00
|
|
|
jz .wait
|
2013-05-28 23:09:31 +04: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-08 17:00:38 +04:00
|
|
|
|
|
|
|
test [eax + TCP_SOCKET.timer_flags], timer_flag_retransmission
|
|
|
|
jz .check_more2
|
2016-01-19 01:18:04 +03:00
|
|
|
dec [eax + TCP_SOCKET.timer_retransmission]
|
|
|
|
jnz .check_more2
|
2013-05-28 23:09:31 +04:00
|
|
|
|
2013-06-02 14:40:22 +04:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: Retransmission timer expired\n", eax
|
2013-05-28 23:09:31 +04:00
|
|
|
|
|
|
|
push eax
|
2016-01-19 01:18:04 +03:00
|
|
|
call tcp_output
|
2013-05-28 23:09:31 +04:00
|
|
|
pop eax
|
|
|
|
|
|
|
|
.check_more2:
|
2013-06-08 17:00:38 +04:00
|
|
|
test [eax + TCP_SOCKET.timer_flags], timer_flag_keepalive
|
|
|
|
jz .check_more3
|
2016-01-19 01:18:04 +03:00
|
|
|
dec [eax + TCP_SOCKET.timer_keepalive]
|
|
|
|
jnz .check_more3
|
2013-05-28 23:09:31 +04:00
|
|
|
|
2013-06-02 14:40:22 +04:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: Keepalive expired\n", eax
|
2013-05-28 23:09:31 +04:00
|
|
|
|
|
|
|
cmp [eax + TCP_SOCKET.state], TCPS_ESTABLISHED
|
|
|
|
ja .dont_kill
|
|
|
|
|
|
|
|
push eax
|
2016-01-19 01:18:04 +03:00
|
|
|
call tcp_disconnect
|
2013-05-28 23:09:31 +04:00
|
|
|
pop eax
|
|
|
|
jmp .loop
|
|
|
|
|
|
|
|
.dont_kill:
|
|
|
|
test [eax + SOCKET.options], SO_KEEPALIVE
|
|
|
|
jz .reset_keepalive
|
|
|
|
|
|
|
|
push eax
|
|
|
|
mov ebx, eax
|
|
|
|
xor cl, cl
|
2016-01-19 01:18:04 +03:00
|
|
|
call tcp_respond ; send keepalive
|
2013-05-28 23:09:31 +04: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-08 17:00:38 +04:00
|
|
|
test [eax + TCP_SOCKET.timer_flags], timer_flag_2msl
|
|
|
|
jz .check_more5
|
2016-01-19 01:18:04 +03:00
|
|
|
dec [eax + TCP_SOCKET.timer_timed_wait]
|
|
|
|
jnz .check_more5
|
2013-05-28 23:09:31 +04:00
|
|
|
|
2013-06-02 14:40:22 +04:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: 2MSL timer expired\n", eax
|
2013-05-28 23:09:31 +04:00
|
|
|
|
|
|
|
.check_more5:
|
2013-06-08 17:00:38 +04:00
|
|
|
test [eax + TCP_SOCKET.timer_flags], timer_flag_persist
|
2015-12-18 12:22:50 +03:00
|
|
|
jz .check_more6
|
2016-01-19 01:18:04 +03:00
|
|
|
dec [eax + TCP_SOCKET.timer_persist]
|
|
|
|
jnz .check_more6
|
2013-05-28 23:09:31 +04:00
|
|
|
|
2013-06-02 14:40:22 +04:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: persist timer expired\n", eax
|
2013-05-28 23:09:31 +04:00
|
|
|
|
2016-01-19 01:18:04 +03:00
|
|
|
call tcp_set_persist
|
2013-05-28 23:09:31 +04:00
|
|
|
mov [eax + TCP_SOCKET.t_force], 1
|
|
|
|
push eax
|
2016-01-19 01:18:04 +03:00
|
|
|
call tcp_output
|
2013-05-28 23:09:31 +04:00
|
|
|
pop eax
|
|
|
|
mov [eax + TCP_SOCKET.t_force], 0
|
|
|
|
|
2015-12-18 12:22:50 +03:00
|
|
|
.check_more6:
|
|
|
|
test [eax + TCP_SOCKET.timer_flags], timer_flag_wait
|
|
|
|
jz .loop
|
2016-01-19 01:18:04 +03:00
|
|
|
dec [eax + TCP_SOCKET.timer_timed_wait]
|
|
|
|
jnz .loop
|
2013-05-28 23:09:31 +04:00
|
|
|
|
2015-12-18 12:22:50 +03:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: timed wait timer expired\n", eax
|
2013-05-28 23:09:31 +04:00
|
|
|
|
2015-12-18 12:22:50 +03:00
|
|
|
push [eax + SOCKET.NextPtr]
|
2016-01-19 01:18:04 +03:00
|
|
|
call tcp_close
|
2015-12-18 12:22:50 +03:00
|
|
|
pop eax
|
2013-05-28 23:09:31 +04:00
|
|
|
|
2015-12-18 12:22:50 +03:00
|
|
|
jmp .check_only
|
2013-05-28 23:09:31 +04:00
|
|
|
|
2015-12-18 12:22:50 +03:00
|
|
|
endp
|
2013-05-28 23:09:31 +04:00
|
|
|
|
2015-12-18 12:22:50 +03:00
|
|
|
|
|
|
|
;-----------------------------------------------------------------;
|
|
|
|
; ;
|
|
|
|
; TCP_cancel_timers ;
|
|
|
|
; ;
|
|
|
|
; IN: eax = socket ;
|
|
|
|
; ;
|
|
|
|
; OUT: / ;
|
|
|
|
; ;
|
|
|
|
;-----------------------------------------------------------------;
|
|
|
|
align 4
|
2016-01-19 01:18:04 +03:00
|
|
|
tcp_cancel_timers:
|
2013-05-28 23:09:31 +04:00
|
|
|
|
2013-06-08 17:00:38 +04:00
|
|
|
mov [eax + TCP_SOCKET.timer_flags], 0
|
2013-05-28 23:09:31 +04:00
|
|
|
|
|
|
|
ret
|