Implemented TCP 2MSL (Timed-wait) timer.

Cleanup and various bugfixes in network code.

git-svn-id: svn://kolibrios.org@5976 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2015-12-16 21:20:53 +00:00
parent 092530d560
commit 0be26c4c22
9 changed files with 790 additions and 732 deletions

View File

@ -61,15 +61,15 @@ local .fail
.fail: .fail:
} }
;----------------------------------------------------------------- ;-----------------------------------------------------------------;
; ; ;
; LOOP_input ; LOOP_input ;
; ; ;
; IN: [esp+4] = Pointer to buffer ; IN: [esp+4] = Pointer to buffer ;
; ; ;
; OUT: / ; OUT: / ;
; ; ;
;----------------------------------------------------------------- ;-----------------------------------------------------------------;
align 4 align 4
LOOP_input: LOOP_input:
@ -105,19 +105,19 @@ LOOP_input:
ret ret
;----------------------------------------------------------------- ;-----------------------------------------------------------------;
; ; ;
; LOOP_output ; LOOP_output ;
; ; ;
; IN: ecx = packet size ; IN: ecx = packet size ;
; edi = address family ; edi = address family ;
; ; ;
; OUT: eax = start of net frame / 0 on error ; OUT: eax = start of net frame / 0 on error ;
; ebx = to device structure ; ebx = to device structure ;
; ecx = unchanged (packet size of embedded data) ; ecx = unchanged (packet size of embedded data) ;
; edi = start of payload ; edi = start of payload ;
; ; ;
;----------------------------------------------------------------- ;-----------------------------------------------------------------;
align 4 align 4
LOOP_output: LOOP_output:

File diff suppressed because it is too large Load Diff

View File

@ -201,13 +201,11 @@ align 4
endg endg
;----------------------------------------------------------------- ;-----------------------------------------------------------------;
; ; ;
; TCP_init ; TCP_init: Resets all TCP variables. ;
; ; ;
; This function resets all TCP variables ;-----------------------------------------------------------------;
;
;-----------------------------------------------------------------
macro TCP_init { macro TCP_init {
xor eax, eax xor eax, eax
@ -246,19 +244,17 @@ include 'tcp_input.inc'
include 'tcp_output.inc' include 'tcp_output.inc'
;--------------------------------------------------------------------------- ;------------------------------------------------------------------;
; ; ;
; TCP_API ; TCP_api: This function is called by system function 76 ;
; ; ;
; This function is called by system function 76 ; IN: bl = subfunction number ;
; ; bh = device number ;
; IN: subfunction number in bl ; ecx, edx, .. depends on subfunction ;
; device number in bh ; ;
; ecx, edx, .. depends on subfunction ; OUT: depends on subfunction ;
; ; ;
; OUT: ;------------------------------------------------------------------;
;
;---------------------------------------------------------------------------
align 4 align 4
TCP_api: TCP_api:

View File

@ -16,23 +16,20 @@
$Revision$ $Revision$
;----------------------------------------------------------------- ;-----------------------------------------------------------------;
; ; ;
; TCP_input: ; TCP_input: Add a segment to the incoming TCP queue. ;
; ; ;
; Add a segment to the incoming TCP queue ; IN: [esp] = ptr to buffer ;
; ; ebx = ptr to device struct ;
; IN: [esp] = ptr to buffer ; ecx = TCP segment size ;
; ebx = ptr to device struct ; edx = ptr to IPv4 header ;
; ecx = TCP segment size ; esi = ptr to TCP segment ;
; edx = ptr to IPv4 header ; edi = interface number*4 ;
; esi = ptr to TCP segment ; ;
; edi = interface number*4 ; OUT: / ;
; ; ;
; OUT: / ;-----------------------------------------------------------------;
;
;-----------------------------------------------------------------
align 4 align 4
TCP_input: TCP_input:
@ -488,8 +485,8 @@ endl
inc eax inc eax
call TCP_xmit_timer call TCP_xmit_timer
jmp .rtt_done jmp .rtt_done
.no_timestamp_rtt: .no_timestamp_rtt:
cmp [ebx + TCP_SOCKET.t_rtt], 0 cmp [ebx + TCP_SOCKET.t_rtt], 0
je .rtt_done je .rtt_done
mov eax, [edx + TCP_header.AckNumber] mov eax, [edx + TCP_header.AckNumber]
@ -497,7 +494,6 @@ endl
jbe .rtt_done jbe .rtt_done
mov eax, [ebx + TCP_SOCKET.t_rtt] mov eax, [ebx + TCP_SOCKET.t_rtt]
call TCP_xmit_timer call TCP_xmit_timer
.rtt_done: .rtt_done:
; update window pointers ; update window pointers

View File

@ -16,14 +16,15 @@
$Revision$ $Revision$
;----------------------------------------------------------------- ;-----------------------------------------------------------------;
; ; ;
; TCP_output ; TCP_output ;
; ; ;
; IN: eax = socket pointer ; IN: eax = socket pointer ;
; OUT: eax = 0 on success/errorcode ; ;
; ; OUT: eax = 0 on success/errorcode ;
;----------------------------------------------------------------- ; ;
;-----------------------------------------------------------------;
align 4 align 4
proc TCP_output proc TCP_output

View File

@ -104,18 +104,17 @@ macro TCP_init_socket socket {
} }
;--------------------------- ;-----------------------------------------------------------------;
; ; ;
; TCP_pull_out_of_band ; TCP_pull_out_of_band ;
; ; ;
; IN: eax = ; IN: eax = ? ;
; ebx = socket ptr ; ebx = socket ptr ;
; edx = tcp packet ptr ; edx = tcp packet ptr ;
; ; ;
; OUT: / ; OUT: / ;
; ; ;
;--------------------------- ;-----------------------------------------------------------------;
align 4 align 4
TCP_pull_out_of_band: TCP_pull_out_of_band:
@ -127,21 +126,16 @@ TCP_pull_out_of_band:
;-----------------------------------------------------------------;
; ;
; TCP_drop ;
; ;
; IN: eax = socket ptr ;
;------------------------- ; ebx = error number ;
; ; ;
; TCP_drop ; OUT: eax = socket ptr ;
; ; ;
; IN: eax = socket ptr ;-----------------------------------------------------------------;
; ebx = error number
;
; OUT: eax = socket ptr
;
;-------------------------
align 4 align 4
TCP_drop: ; FIXME CHECKME TODO TCP_drop: ; FIXME CHECKME TODO
@ -171,14 +165,15 @@ TCP_drop: ; FIXME CHECKME TODO
;------------------------- ;-----------------------------------------------------------------;
; ; ;
; TCP_disconnect ; TCP_disconnect ;
; ; ;
; IN: eax = socket ptr ; IN: eax = socket ptr ;
; OUT: eax = socket ptr / 0 ; ;
; ; OUT: eax = socket ptr / 0 ;
;------------------------- ; ;
;-----------------------------------------------------------------;
align 4 align 4
TCP_disconnect: TCP_disconnect:
@ -198,18 +193,18 @@ TCP_disconnect:
call TCP_output call TCP_output
pop eax pop eax
@@: @@:
ret ret
;------------------------- ;-----------------------------------------------------------------;
; ; ;
; TCP_close ; TCP_close ;
; ; ;
; IN: eax = socket ptr ; IN: eax = socket ptr ;
; OUT: / ; ;
; ; OUT: / ;
;------------------------- ; ;
;-----------------------------------------------------------------;
align 4 align 4
TCP_close: TCP_close:
@ -222,21 +217,19 @@ TCP_close:
call SOCKET_free call SOCKET_free
xor eax, eax xor eax, eax
ret ret
;-----------------------------------------------------------------;
;------------------------- ; ;
; ; TCP_outflags ;
; TCP_outflags ; ;
; ; IN: eax = socket ptr ;
; IN: eax = socket ptr ; ;
; ; OUT: edx = flags ;
; OUT: edx = flags ; ;
; ;-----------------------------------------------------------------;
;-------------------------
align 4 align 4
TCP_outflags: TCP_outflags:
@ -266,19 +259,16 @@ TCP_outflags:
;----------------------------------------------------------------- ;-----------------------------------------------------------------;
; ; ;
; The fast way to send an ACK/RST/keepalive segment ; TCP_respond: Fast way to send an ACK/RST/keepalive segment. ;
; ; ;
; TCP_respond ; IN: ebx = socket ptr ;
; ; cl = flags ;
; IN: ebx = socket ptr ; ;
; cl = flags ; OUT: / ;
; ; ;
; OUT: / ;-----------------------------------------------------------------;
;
;-----------------------------------------------------------------
align 4 align 4
TCP_respond: TCP_respond:
@ -351,19 +341,18 @@ TCP_respond:
ret ret
;----------------------------------------------------------------- ;-----------------------------------------------------------------;
; ; ;
; TCP_respond_segment: ; TCP_respond_segment ;
; ; ;
; IN: ebx = device ptr ; IN: ebx = device ptr ;
; edx = segment ptr (a previously received segment) ; edx = segment ptr (a previously received segment) ;
; edi = ptr to IPv4 header ; edi = ptr to IPv4 header ;
; cl = flags ; cl = flags ;
; ; ;
; OUT: / ; OUT: / ;
; ; ;
;----------------------------------------------------------------- ;-----------------------------------------------------------------;
align 4 align 4
TCP_respond_segment: TCP_respond_segment:
@ -457,7 +446,11 @@ local .done
.done: .done:
} }
;-----------------------------------------------------------------;
; ;
; TCP_set_persist ;
; ;
;-----------------------------------------------------------------;
align 4 align 4
TCP_set_persist: TCP_set_persist:
@ -494,13 +487,20 @@ TCP_set_persist:
; eax = rtt ;-----------------------------------------------------------------;
; ebx = socket ptr ; ;
; TCP_xmit_timer: Calculate new smoothed RTT. ;
; ;
; IN: eax = rtt ;
; ebx = socket ptr ;
; ;
; OUT: / ;
; ;
;-----------------------------------------------------------------;
align 4 align 4
TCP_xmit_timer: TCP_xmit_timer:
DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_xmit_timer: socket=%x rtt=%d0ms\n", ebx, eax DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_xmit_timer: socket=0x%x rtt=%d0ms\n", ebx, eax
;TODO: update stats ;TODO: update stats
@ -549,7 +549,6 @@ TCP_xmit_timer:
.no_rtt_yet: .no_rtt_yet:
push ecx push ecx
mov ecx, eax mov ecx, eax
shl ecx, TCP_RTT_SHIFT shl ecx, TCP_RTT_SHIFT
@ -562,10 +561,16 @@ TCP_xmit_timer:
ret ret
;-----------------------------------------------------------------;
; ;
; eax = max segment size ; TCP_mss: Update maximum segment size ;
; ebx = socket ptr ; ;
; IN: eax = max segment size ;
; ebx = socket ptr ;
; ;
; OUT: / ;
; ;
;-----------------------------------------------------------------;
align 4 align 4
TCP_mss: TCP_mss:
@ -580,13 +585,20 @@ TCP_mss:
;-----------------------------------------------------------------;
; ebx = socket ptr ; ;
; edx = segment ptr ; TCP_reassemble ;
; ;
; IN: ebx = socket ptr ;
; edx = segment ptr ;
; ;
; OUT: / ;
; ;
;-----------------------------------------------------------------;
align 4 align 4
TCP_reassemble: TCP_reassemble:
;;;;; TODO
ret ret

View File

@ -23,9 +23,6 @@ timer_flag_persist = 1 shl 3
timer_flag_wait = 1 shl 4 timer_flag_wait = 1 shl 4
;----------------------
; 160 ms timer
;----------------------
macro TCP_timer_160ms { macro TCP_timer_160ms {
local .loop local .loop
@ -150,9 +147,9 @@ proc TCP_timer_640ms ; TODO: implement timed wait timer!
.check_more5: .check_more5:
dec [eax + TCP_SOCKET.timer_persist] dec [eax + TCP_SOCKET.timer_persist]
jnz .loop jnz .check_more6
test [eax + TCP_SOCKET.timer_flags], timer_flag_persist test [eax + TCP_SOCKET.timer_flags], timer_flag_persist
jz .loop jz .check_more6
DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: persist timer expired\n", eax DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: persist timer expired\n", eax
@ -163,14 +160,33 @@ proc TCP_timer_640ms ; TODO: implement timed wait timer!
pop eax pop eax
mov [eax + TCP_SOCKET.t_force], 0 mov [eax + TCP_SOCKET.t_force], 0
jmp .loop .check_more6:
dec [eax + TCP_SOCKET.timer_timed_wait]
jnz .loop
test [eax + TCP_SOCKET.timer_flags], timer_flag_wait
jz .loop
DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: timed wait timer expired\n", eax
push [eax + SOCKET.NextPtr]
call TCP_close
pop eax
jmp .check_only
endp endp
;-----------------------------------------------------------------;
; eax = socket ; ;
; TCP_cancel_timers ;
; ;
; IN: eax = socket ;
; ;
; OUT: / ;
; ;
;-----------------------------------------------------------------;
align 4
TCP_cancel_timers: TCP_cancel_timers:
mov [eax + TCP_SOCKET.timer_flags], 0 mov [eax + TCP_SOCKET.timer_flags], 0

View File

@ -17,15 +17,15 @@
$Revision$ $Revision$
;------------------------- ;-----------------------------------------------------------------;
; ; ;
; TCP_usrclose ; TCP_usrclosed ;
; ; ;
; Move connection to next state, based on process close. ; IN: eax = socket ptr ;
; ; ;
; IN: eax = socket ptr ; OUT: / ;
; ; ;
;------------------------- ;-----------------------------------------------------------------;
align 4 align 4
TCP_usrclosed: TCP_usrclosed:
@ -37,7 +37,6 @@ TCP_usrclosed:
jmp ebx jmp ebx
.switch: .switch:
dd .close ; TCPS_CLOSED dd .close ; TCPS_CLOSED
dd .close ; TCPS_LISTEN dd .close ; TCPS_LISTEN
dd .close ; TCPS_SYN_SENT dd .close ; TCPS_SYN_SENT
@ -50,7 +49,6 @@ TCP_usrclosed:
dd .disc ; TCPS_FIN_WAIT_2 dd .disc ; TCPS_FIN_WAIT_2
dd .disc ; TCPS_TIMED_WAIT dd .disc ; TCPS_TIMED_WAIT
.close: .close:
mov [eax + TCP_SOCKET.t_state], TCPS_CLOSED mov [eax + TCP_SOCKET.t_state], TCPS_CLOSED
call TCP_close call TCP_close
@ -74,15 +72,17 @@ TCP_usrclosed:
ret ret
;------------------------- ;-----------------------------------------------------------------;
; ; ;
; TCP_connect ; TCP_connect ;
; ; ;
; IN: eax = socket ptr ; IN: eax = socket ptr ;
; OUT: eax = 0 ok / -1 error ; ;
; ebx = error code ; OUT: eax = 0 on success ;
; ; eax = -1 on error ;
;------------------------- ; ebx = error code on error ;
; ;
;-----------------------------------------------------------------;
align 4 align 4
TCP_connect: TCP_connect:

View File

@ -36,13 +36,11 @@ align 4
endg endg
;----------------------------------------------------------------- ;-----------------------------------------------------------------;
; ; ;
; UDP_init ; UDP_init: This function resets all UDP variables ;
; ; ;
; This function resets all UDP variables ;-----------------------------------------------------------------;
;
;-----------------------------------------------------------------
macro UDP_init { macro UDP_init {
xor eax, eax xor eax, eax
@ -98,23 +96,20 @@ macro UDP_checksum IP1, IP2 { ; esi = ptr to udp packet, ecx = packet size
} }
;----------------------------------------------------------------- ;-----------------------------------------------------------------;
; ; ;
; UDP_input: ; UDP_input: Inject the UDP data in the application sockets. ;
; ; ;
; Called by IPv4_input, ; IN: [esp] = ptr to buffer ;
; this procedure will inject the UDP data in the application sockets. ; ebx = ptr to device struct ;
; ; ecx = UDP packet size ;
; IN: [esp] = ptr to buffer ; edx = ptr to IPv4 header ;
; ebx = ptr to device struct ; esi = ptr to UDP packet data ;
; ecx = UDP packet size ; edi = interface number*4 ;
; edx = ptr to IPv4 header ; ;
; esi = ptr to UDP packet data ; OUT: / ;
; edi = interface number*4 ; ;
; ;-----------------------------------------------------------------;
; OUT: /
;
;-----------------------------------------------------------------
align 4 align 4
UDP_input: UDP_input:
@ -230,17 +225,17 @@ UDP_input:
;----------------------------------------------------------------- ;-----------------------------------------------------------------;
; ; ;
; UDP_output ; UDP_output: Create an UDP packet. ;
; ; ;
; IN: eax = socket pointer ; IN: eax = socket pointer ;
; ecx = number of bytes to send ; ecx = number of bytes to send ;
; esi = pointer to data ; esi = pointer to data ;
; ; ;
; OUT: eax = -1 on error ; OUT: eax = -1 on error ;
; ; ;
;----------------------------------------------------------------- ;-----------------------------------------------------------------;
align 4 align 4
UDP_output: UDP_output:
@ -305,15 +300,17 @@ UDP_output:
;----------------------------------------------------------------- ;-----------------------------------------------------------------;
; ; ;
; UDP_connect ; UDP_connect ;
; ; ;
; IN: eax = socket pointer ; IN: eax = socket pointer ;
; OUT: eax = 0 ok / -1 error ; ;
; ebx = error code ; OUT: eax = 0 on success ;
; ; eax = -1 on error ;
;------------------------- ; ebx = error code on error ;
; ;
;-----------------------------------------------------------------;
align 4 align 4
UDP_connect: UDP_connect:
@ -357,14 +354,15 @@ UDP_connect:
ret ret
;----------------------------------------------------------------- ;-----------------------------------------------------------------;
; ; ;
; UDP_disconnect ; UDP_disconnect ;
; ; ;
; IN: eax = socket pointer ; IN: eax = socket pointer ;
; OUT: eax = socket pointer ; ;
; ; OUT: eax = socket pointer ;
;------------------------- ; ;
;-----------------------------------------------------------------;
align 4 align 4
UDP_disconnect: UDP_disconnect:
@ -378,20 +376,17 @@ UDP_disconnect:
;--------------------------------------------------------------------------- ;-----------------------------------------------------------------;
; ; ;
; UDP_API ; UDP_api: This function is called by system function 76 ;
; ; ;
; This function is called by system function 75 ; IN: bl = subfunction number in bl ;
; ; bh = device number in bh ;
; IN: subfunction number in bl ; ecx, edx, .. depends on subfunction ;
; device number in bh ; ;
; ecx, edx, .. depends on subfunction ; OUT: depends on subfunction ;
; ; ;
; OUT: ;-----------------------------------------------------------------;
;
;---------------------------------------------------------------------------
align 4 align 4
UDP_api: UDP_api: