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:
}
;-----------------------------------------------------------------
;
; LOOP_input
;
; IN: [esp+4] = Pointer to buffer
;
; OUT: /
;
;-----------------------------------------------------------------
;-----------------------------------------------------------------;
; ;
; LOOP_input ;
; ;
; IN: [esp+4] = Pointer to buffer ;
; ;
; OUT: / ;
; ;
;-----------------------------------------------------------------;
align 4
LOOP_input:
@ -105,19 +105,19 @@ LOOP_input:
ret
;-----------------------------------------------------------------
;
; LOOP_output
;
; IN: ecx = packet size
; edi = address family
;
; OUT: eax = start of net frame / 0 on error
; ebx = to device structure
; ecx = unchanged (packet size of embedded data)
; edi = start of payload
;
;-----------------------------------------------------------------
;-----------------------------------------------------------------;
; ;
; LOOP_output ;
; ;
; IN: ecx = packet size ;
; edi = address family ;
; ;
; OUT: eax = start of net frame / 0 on error ;
; ebx = to device structure ;
; ecx = unchanged (packet size of embedded data) ;
; edi = start of payload ;
; ;
;-----------------------------------------------------------------;
align 4
LOOP_output:

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

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

View File

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

View File

@ -23,9 +23,6 @@ timer_flag_persist = 1 shl 3
timer_flag_wait = 1 shl 4
;----------------------
; 160 ms timer
;----------------------
macro TCP_timer_160ms {
local .loop
@ -150,9 +147,9 @@ proc TCP_timer_640ms ; TODO: implement timed wait timer!
.check_more5:
dec [eax + TCP_SOCKET.timer_persist]
jnz .loop
jnz .check_more6
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
@ -163,14 +160,33 @@ proc TCP_timer_640ms ; TODO: implement timed wait timer!
pop eax
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
; eax = socket
;-----------------------------------------------------------------;
; ;
; TCP_cancel_timers ;
; ;
; IN: eax = socket ;
; ;
; OUT: / ;
; ;
;-----------------------------------------------------------------;
align 4
TCP_cancel_timers:
mov [eax + TCP_SOCKET.timer_flags], 0

View File

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

View File

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