Bugfixes & further development of TCP_output

git-svn-id: svn://kolibrios.org@2890 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2012-07-26 14:54:57 +00:00
parent d205bffbfa
commit 0287f5c75b
5 changed files with 87 additions and 60 deletions

View File

@ -68,7 +68,7 @@ struct TCP_SOCKET IP_SOCKET
; send sequence ; send sequence
SND_UNA dd ? ; sequence number of unack'ed sent Packets SND_UNA dd ? ; sequence number of unack'ed sent Packets
SND_NXT dd ? ; next send sequence number to use SND_NXT dd ? ; next send sequence number to use
SND_UP dd ? SND_UP dd ? ; urgent pointer
SND_WL1 dd ? ; window minus one SND_WL1 dd ? ; window minus one
SND_WL2 dd ? ; SND_WL2 dd ? ;
ISS dd ? ; initial send sequence number ISS dd ? ; initial send sequence number
@ -77,7 +77,7 @@ struct TCP_SOCKET IP_SOCKET
; receive sequence ; receive sequence
RCV_WND dw ? ; receive window RCV_WND dw ? ; receive window
RCV_NXT dd ? ; next receive sequence number to use RCV_NXT dd ? ; next receive sequence number to use
RCV_UP dd ? RCV_UP dd ? ; urgent pointer
IRS dd ? ; initial receive sequence number IRS dd ? ; initial receive sequence number
;--------------------- ;---------------------
@ -130,6 +130,10 @@ struct TCP_SOCKET IP_SOCKET
timer_keepalive dw ? ; keepalive/syn timeout timer_keepalive dw ? ; keepalive/syn timeout
timer_timed_wait dw ? ; also used as 2msl timer timer_timed_wait dw ? ; also used as 2msl timer
; extra
sendalot db ?
ends ends
struct UDP_SOCKET IP_SOCKET struct UDP_SOCKET IP_SOCKET
@ -696,7 +700,7 @@ SOCKET_close:
cmp [eax + TCP_SOCKET.t_state], TCPS_SYN_RECEIVED ; state must be LISTEN, SYN_SENT or CLOSED cmp [eax + TCP_SOCKET.t_state], TCPS_SYN_RECEIVED ; state must be LISTEN, SYN_SENT or CLOSED
jb .free jb .free
call TCP_drop call TCP_usrclosed
mov dword [esp+32], 0 mov dword [esp+32], 0
ret ret

View File

@ -133,6 +133,8 @@ TCP_input:
.found_socket: ; ebx now contains the socketpointer .found_socket: ; ebx now contains the socketpointer
DEBUGF 1,"Socket ptr: %x\n", ebx DEBUGF 1,"Socket ptr: %x\n", ebx
; update stats
inc [TCP_segments_rx] ; FIXME: correct interface?
;---------------------------- ;----------------------------
; Check if socket isnt closed ; Check if socket isnt closed
@ -1055,7 +1057,7 @@ align 4
;;; TODO: update stats ;;; TODO: update stats
DEBUGF 1,"We have an acceptable ACK of %x bytes\n", edi DEBUGF 1,"We have an acceptable ACK of %u bytes\n", edi

View File

@ -26,15 +26,10 @@ $Revision$
; ;
;----------------------------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
TCP_sendalot:
DEBUGF 1,"TCP_sendalot\n"
pop eax
;align 4
TCP_output: TCP_output:
DEBUGF 1,"TCP_output, socket: %x\n", eax DEBUGF 1,"TCP_output, socket: %x\n", eax
; We'll detect the length of the data to be transmitted, and flags to be used ; We'll detect the length of the data to be transmitted, and flags to be used
; If there is some data, or any critical controls to send (SYN / RST), then transmit ; If there is some data, or any critical controls to send (SYN / RST), then transmit
; Otherwise, investigate further ; Otherwise, investigate further
@ -55,6 +50,8 @@ TCP_output:
.not_idle: .not_idle:
.again: .again:
mov [eax + TCP_SOCKET.sendalot], 0
mov ebx, [eax + TCP_SOCKET.SND_NXT] ; calculate offset (71) mov ebx, [eax + TCP_SOCKET.SND_NXT] ; calculate offset (71)
sub ebx, [eax + TCP_SOCKET.SND_UNA] ; sub ebx, [eax + TCP_SOCKET.SND_UNA] ;
@ -82,7 +79,7 @@ TCP_output:
cmp ebx, [eax + STREAM_SOCKET.snd.size] cmp ebx, [eax + STREAM_SOCKET.snd.size]
jae @f jae @f
and dl, not (TH_FIN) ; clear the FIN flag ??? how can it be set before? and dl, not (TH_FIN)
@@: @@:
inc ecx inc ecx
@ -139,8 +136,7 @@ TCP_output:
jbe @f jbe @f
mov esi, [eax + TCP_SOCKET.t_maxseg] mov esi, [eax + TCP_SOCKET.t_maxseg]
push eax inc [eax + TCP_SOCKET.sendalot]
push dword TCP_sendalot
@@: @@:
;-------------------------------------------- ;--------------------------------------------
@ -149,9 +145,8 @@ TCP_output:
mov edi, [eax + TCP_SOCKET.SND_NXT] mov edi, [eax + TCP_SOCKET.SND_NXT]
add edi, esi add edi, esi
sub edi, [eax + TCP_SOCKET.SND_UNA] sub edi, [eax + TCP_SOCKET.SND_UNA]
sub edi, [eax + STREAM_SOCKET.snd.size] cmp edi, [eax + STREAM_SOCKET.snd.size]
jns @f jae @f
and dl, not (TH_FIN) and dl, not (TH_FIN)
@@: @@:
@ -171,13 +166,17 @@ TCP_output:
cmp esi, [eax + TCP_SOCKET.t_maxseg] cmp esi, [eax + TCP_SOCKET.t_maxseg]
je TCP_send je TCP_send
test [eax + TCP_SOCKET.t_flags], TF_NODELAY add ebx, esi ; offset + length
jnz @f
; TODO: if not 'idle', skip to next codeblock
@@:
add ebx, esi
cmp ebx, [eax + STREAM_SOCKET.snd.size] cmp ebx, [eax + STREAM_SOCKET.snd.size]
jae TCP_send jb @f
test [eax + TCP_SOCKET.t_flags], TF_NODELAY
jnz TCP_send
mov ebx, [eax + TCP_SOCKET.SND_MAX]
cmp ebx, [eax + TCP_SOCKET.SND_UNA]
je TCP_send
@@:
test [eax + TCP_SOCKET.t_force], -1 ;;; test [eax + TCP_SOCKET.t_force], -1 ;;;
jnz TCP_send jnz TCP_send
@ -238,7 +237,7 @@ TCP_output:
; FIN was set, only send if not already sent, or on retransmit ; FIN was set, only send if not already sent, or on retransmit
test [eax + TCP_SOCKET.t_flags], TF_SENTFIN test [eax + TCP_SOCKET.t_flags], TF_SENTFIN
jnz TCP_send jz TCP_send
mov ebx, [eax + TCP_SOCKET.SND_NXT] mov ebx, [eax + TCP_SOCKET.SND_NXT]
cmp ebx, [eax + TCP_SOCKET.SND_UNA] cmp ebx, [eax + TCP_SOCKET.SND_UNA]
@ -296,11 +295,9 @@ TCP_send:
DEBUGF 1,"TCP_send socket=%x length=%u flags=%x\n", eax, esi, dl DEBUGF 1,"TCP_send socket=%x length=%u flags=%x\n", eax, esi, dl
push eax ; save socket ptr
mov edi, sizeof.TCP_header ; edi will contain headersize mov edi, sizeof.TCP_header ; edi will contain headersize
sub esp, 8 ; create some space on stack
push eax ; save socket pointer
;------------------------------------ ;------------------------------------
; Send options with first SYN segment ; Send options with first SYN segment
@ -379,9 +376,7 @@ TCP_send:
jbe .no_overflow jbe .no_overflow
mov esi, [eax + TCP_SOCKET.t_maxseg] mov esi, [eax + TCP_SOCKET.t_maxseg]
;; push eax inc [eax + TCP_SOCKET.sendalot]
;; push dword TCP_sendalot
.no_overflow: .no_overflow:
;----------------------------------------------------------------- ;-----------------------------------------------------------------
@ -428,16 +423,16 @@ TCP_send:
push ecx push ecx
mov ecx, [esp + 4] mov ecx, [esp + 4]
lea esi, [esp+4+4] lea esi, [esp + 8]
shr ecx, 2 shr ecx, 2 ; count is in bytes, we will work with dwords
rep movsd rep movsd
pop ecx ; full TCP packet size pop ecx ; full TCP packet size
pop esi ; headersize pop esi ; headersize
add esp, esi add esp, esi ; remove it from stack
mov [esp + 4], eax ; packet ptr push edx ; packet size for send proc
mov [esp + 4+4], edx ; packet size push eax ; packet ptr for send proc
mov edx, edi ; begin of data mov edx, edi ; begin of data
sub edx, esi ; begin of packet (edi = begin of data) sub edx, esi ; begin of packet (edi = begin of data)
@ -451,7 +446,7 @@ TCP_send:
; ecx = buffer size ; ecx = buffer size
; edi = ptr to buffer ; edi = ptr to buffer
mov eax, [esp + 4] ; get socket ptr mov eax, [esp + 12] ; get socket ptr
add [eax + TCP_SOCKET.SND_NXT], ecx ; update sequence number add [eax + TCP_SOCKET.SND_NXT], ecx ; update sequence number
push edx push edx
@ -462,7 +457,8 @@ TCP_send:
.nodata: .nodata:
pop esi ; begin of data pop esi ; begin of data
pop ecx ; full packet size pop ecx ; full packet size
pop eax ; socket ptr mov eax, [esp + 8]
;---------------------------------- ;----------------------------------
; update sequence number and timers (400) ; update sequence number and timers (400)
@ -496,10 +492,9 @@ TCP_send:
mov [eax + TCP_SOCKET.timer_retransmission], dx mov [eax + TCP_SOCKET.timer_retransmission], dx
cmp [eax + TCP_SOCKET.timer_persist], 0 cmp [eax + TCP_SOCKET.timer_persist], 0
jne @f jne .retransmit_set
mov [eax + TCP_SOCKET.timer_persist], 0 mov [eax + TCP_SOCKET.timer_persist], 0
mov [eax + TCP_SOCKET.t_rxtshift], 0 mov [eax + TCP_SOCKET.t_rxtshift], 0
@@:
.retransmit_set: .retransmit_set:
@ -511,18 +506,32 @@ TCP_send:
TCP_checksum (eax + IP_SOCKET.LocalIP), (eax + IP_SOCKET.RemoteIP) TCP_checksum (eax + IP_SOCKET.LocalIP), (eax + IP_SOCKET.RemoteIP)
mov [esi + TCP_header.Checksum], dx mov [esi + TCP_header.Checksum], dx
; unlock socket
pusha
lea ecx, [eax + SOCKET.mutex]
call mutex_unlock
popa
;---------------- ;----------------
; Send the packet ; Send the packet
DEBUGF 1,"Sending TCP Packet to device %x\n", ebx DEBUGF 1,"Sending TCP Packet to device %x\n", ebx
call [ebx + NET_DEVICE.transmit] call [ebx + NET_DEVICE.transmit]
jnz .send_error
pop eax
inc [TCP_segments_tx] ; FIXME: correct interface?
;;; TODO: (485)
push [eax + TCP_SOCKET.RCV_NXT]
pop [eax + TCP_SOCKET.last_ack_sent]
and [eax + TCP_SOCKET.t_flags], not (TF_ACKNOW + TF_DELACK)
cmp [eax + TCP_SOCKET.sendalot], 0
jne TCP_output.again
; unlock socket
lea ecx, [eax + SOCKET.mutex]
call mutex_unlock
DEBUGF 1,"TCP_output: success!\n"
xor eax, eax
ret ret
@ -530,19 +539,29 @@ TCP_send:
pop ecx pop ecx
add esp, ecx add esp, ecx
pop eax pop eax
add esp, 8
mov [eax + TCP_SOCKET.timer_retransmission], TCP_time_re_min mov [eax + TCP_SOCKET.timer_retransmission], TCP_time_re_min
pusha ; unlock socket
lea ecx, [eax + SOCKET.mutex] lea ecx, [eax + SOCKET.mutex]
call mutex_unlock call mutex_unlock
popa
DEBUGF 1,"TCP_output: IP error\n" DEBUGF 1,"TCP_output: IP error\n"
or eax, -1
ret
.send_error:
pop eax
; unlock socket
lea ecx, [eax + SOCKET.mutex]
call mutex_unlock
DEBUGF 1,"TCP_output: sending failed\n"
or eax, -2
ret ret

View File

@ -201,7 +201,7 @@ TCP_close:
align 4 align 4
TCP_disconnect: TCP_disconnect:
DEBUGF 1,"TCP_disconnect\n" DEBUGF 1,"TCP_disconnect socket=%x\n", eax
cmp [eax + TCP_SOCKET.t_state], TCPS_ESTABLISHED cmp [eax + TCP_SOCKET.t_state], TCPS_ESTABLISHED
jb TCP_close jb TCP_close
@ -227,6 +227,8 @@ TCP_disconnect:
align 4 align 4
TCP_usrclosed: TCP_usrclosed:
DEBUGF 1,"TCP_usrclosed socket=%x\n", eax
push ebx push ebx
mov ebx, [eax + TCP_SOCKET.t_state] mov ebx, [eax + TCP_SOCKET.t_state]
mov ebx, dword [.switch + ebx*4] mov ebx, dword [.switch + ebx*4]
@ -297,9 +299,9 @@ TCP_outflags:
db TH_SYN + TH_ACK ; TCPS_SYN_RECEIVED db TH_SYN + TH_ACK ; TCPS_SYN_RECEIVED
db TH_ACK ; TCPS_ESTABLISHED db TH_ACK ; TCPS_ESTABLISHED
db TH_ACK ; TCPS_CLOSE_WAIT db TH_ACK ; TCPS_CLOSE_WAIT
db TH_SYN + TH_ACK ; TCPS_FIN_WAIT_1 db TH_FIN + TH_ACK ; TCPS_FIN_WAIT_1
db TH_SYN + TH_ACK ; TCPS_CLOSING db TH_FIN + TH_ACK ; TCPS_CLOSING
db TH_SYN + TH_ACK ; TCPS_LAST_ACK db TH_FIN + TH_ACK ; TCPS_LAST_ACK
db TH_ACK ; TCPS_FIN_WAIT_2 db TH_ACK ; TCPS_FIN_WAIT_2
db TH_ACK ; TCPS_TIMED_WAIT db TH_ACK ; TCPS_TIMED_WAIT

View File

@ -235,7 +235,7 @@ UDP_output:
DEBUGF 1,"UDP_output: socket:%x, bytes: %u, data ptr: %x\n", eax, ecx, esi DEBUGF 1,"UDP_output: socket:%x, bytes: %u, data ptr: %x\n", eax, ecx, esi
mov dx, [eax + UDP_SOCKET.RemotePort] mov dx, [eax + UDP_SOCKET.RemotePort]
DEBUGF 1,"remote port: %u\n", dx DEBUGF 1,"UDP_output: remote port: %u, ", dx
rol dx, 8 rol dx, 8
rol edx, 16 rol edx, 16
mov dx, [eax + UDP_SOCKET.LocalPort] mov dx, [eax + UDP_SOCKET.LocalPort]
@ -273,11 +273,11 @@ UDP_output:
; Checksum ; Checksum
mov esi, edi mov esi, edi
mov [edi + UDP_header.Checksum], 0 mov [edi + UDP_header.Checksum], 0
UDP_checksum (edi-4), (edi-8) ; TODO: fix this, IPv4 packet could have options.. UDP_checksum (edi-4), (edi-8) ; FIXME: IPv4 packet could have options..
inc [UDP_PACKETS_TX] inc [UDP_PACKETS_TX] ; FIXME: correct device?
DEBUGF 1,"Sending UDP Packet to device %x\n", ebx DEBUGF 1,"UDP_output: sending to device %x\n", ebx
call [ebx + NET_DEVICE.transmit] call [ebx + NET_DEVICE.transmit]
ret ret