forked from KolibriOS/kolibrios
Usage of new mutexes in net branch.
git-svn-id: svn://kolibrios.org@2402 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
0478f45357
commit
815cb2a26f
@ -254,9 +254,10 @@ ICMP_input:
|
|||||||
|
|
||||||
DEBUGF 1,"Found valid ICMP packet for socket %x\n", ebx
|
DEBUGF 1,"Found valid ICMP packet for socket %x\n", ebx
|
||||||
|
|
||||||
mov eax, ebx
|
pusha
|
||||||
add ebx, SOCKET.lock
|
lea ecx, [eax + SOCKET.mutex]
|
||||||
call wait_mutex
|
call mutex_lock
|
||||||
|
popa
|
||||||
|
|
||||||
mov esi, edx
|
mov esi, edx
|
||||||
jmp SOCKET_input
|
jmp SOCKET_input
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -151,12 +151,6 @@ macro ntohw reg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
wait_mutex: ; stub
|
|
||||||
inc dword [ebx]
|
|
||||||
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
include "queue.inc"
|
include "queue.inc"
|
||||||
|
|
||||||
include "ethernet.inc"
|
include "ethernet.inc"
|
||||||
|
@ -143,13 +143,10 @@ TCP_input:
|
|||||||
;----------------
|
;----------------
|
||||||
; Lock the socket
|
; Lock the socket
|
||||||
|
|
||||||
cmp [ebx + SOCKET.lock], 0
|
pusha
|
||||||
jne .drop_not_locked ;;; HACK ! HACK ! dirty fucking HACK ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
lea ecx, [ebx + SOCKET.mutex]
|
||||||
|
call mutex_lock
|
||||||
add ebx, SOCKET.lock
|
popa
|
||||||
DEBUGF 1,"lock: %x\n", [ebx]
|
|
||||||
call wait_mutex
|
|
||||||
sub ebx, SOCKET.lock
|
|
||||||
|
|
||||||
DEBUGF 1,"Socket locked\n"
|
DEBUGF 1,"Socket locked\n"
|
||||||
|
|
||||||
@ -171,7 +168,11 @@ TCP_input:
|
|||||||
|
|
||||||
DEBUGF 1,"Accepting new connection\n"
|
DEBUGF 1,"Accepting new connection\n"
|
||||||
|
|
||||||
mov [ebx + SOCKET.lock], 0
|
pusha
|
||||||
|
lea ecx, [ebx + SOCKET.mutex]
|
||||||
|
call mutex_unlock
|
||||||
|
popa
|
||||||
|
|
||||||
push ecx edx esi edi ;;;
|
push ecx edx esi edi ;;;
|
||||||
call SOCKET_fork
|
call SOCKET_fork
|
||||||
pop edi esi edx ecx
|
pop edi esi edx ecx
|
||||||
@ -375,7 +376,11 @@ TCP_input:
|
|||||||
mov [ebx + TCP_SOCKET.timer_retransmission], 0
|
mov [ebx + TCP_SOCKET.timer_retransmission], 0
|
||||||
|
|
||||||
; Awaken waiting processes
|
; Awaken waiting processes
|
||||||
mov [ebx + SOCKET.lock], 0
|
pusha
|
||||||
|
lea ecx, [ebx + SOCKET.mutex]
|
||||||
|
call mutex_unlock
|
||||||
|
popa
|
||||||
|
|
||||||
mov eax, ebx
|
mov eax, ebx
|
||||||
call SOCKET_notify_owner
|
call SOCKET_notify_owner
|
||||||
|
|
||||||
@ -1465,7 +1470,10 @@ align 4
|
|||||||
|
|
||||||
.dumpit:
|
.dumpit:
|
||||||
|
|
||||||
mov [ebx + SOCKET.lock], 0
|
pusha
|
||||||
|
lea ecx, [ebx + SOCKET.mutex]
|
||||||
|
call mutex_unlock
|
||||||
|
popa
|
||||||
|
|
||||||
call kernel_free
|
call kernel_free
|
||||||
add esp, 4
|
add esp, 4
|
||||||
@ -1490,7 +1498,10 @@ align 4
|
|||||||
|
|
||||||
and [ebx + TCP_SOCKET.t_flags], TF_ACKNOW
|
and [ebx + TCP_SOCKET.t_flags], TF_ACKNOW
|
||||||
|
|
||||||
mov [ebx + SOCKET.lock], 0
|
pusha
|
||||||
|
lea ecx, [ebx + SOCKET.mutex]
|
||||||
|
call mutex_unlock
|
||||||
|
popa
|
||||||
|
|
||||||
push ebx
|
push ebx
|
||||||
; mov cl, TH_ACK
|
; mov cl, TH_ACK
|
||||||
@ -1516,7 +1527,10 @@ align 4
|
|||||||
align 4
|
align 4
|
||||||
.drop_with_reset:
|
.drop_with_reset:
|
||||||
|
|
||||||
mov [ebx + SOCKET.lock], 0
|
pusha
|
||||||
|
lea ecx, [ebx + SOCKET.mutex]
|
||||||
|
call mutex_unlock
|
||||||
|
popa
|
||||||
|
|
||||||
.drop_with_reset_not_locked:
|
.drop_with_reset_not_locked:
|
||||||
|
|
||||||
@ -1568,7 +1582,10 @@ align 4
|
|||||||
align 4
|
align 4
|
||||||
.drop:
|
.drop:
|
||||||
|
|
||||||
mov [ebx + SOCKET.lock], 0
|
pusha
|
||||||
|
lea ecx, [ebx + SOCKET.mutex]
|
||||||
|
call mutex_unlock
|
||||||
|
popa
|
||||||
|
|
||||||
.drop_not_locked:
|
.drop_not_locked:
|
||||||
|
|
||||||
|
@ -28,39 +28,39 @@ $Revision$
|
|||||||
align 4
|
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
|
||||||
|
|
||||||
mov ebx, [eax + TCP_SOCKET.SND_MAX]
|
mov ebx, [eax + TCP_SOCKET.SND_MAX]
|
||||||
cmp ebx, [eax + TCP_SOCKET.SND_UNA]
|
cmp ebx, [eax + TCP_SOCKET.SND_UNA]
|
||||||
jne .not_idle
|
jne .not_idle
|
||||||
|
|
||||||
mov ebx, [eax + TCP_SOCKET.t_idle]
|
mov ebx, [eax + TCP_SOCKET.t_idle]
|
||||||
cmp ebx, [eax + TCP_SOCKET.t_rxtcur]
|
cmp ebx, [eax + TCP_SOCKET.t_rxtcur]
|
||||||
jbe .not_idle
|
jbe .not_idle
|
||||||
|
|
||||||
; We have been idle for a while and no ACKS are expected to clock out any data we send..
|
; We have been idle for a while and no ACKS are expected to clock out any data we send..
|
||||||
; Slow start to get ack "clock" running again.
|
; Slow start to get ack "clock" running again.
|
||||||
|
|
||||||
mov ebx, [eax + TCP_SOCKET.t_maxseg]
|
mov ebx, [eax + TCP_SOCKET.t_maxseg]
|
||||||
mov [eax + TCP_SOCKET.SND_CWND], ebx
|
mov [eax + TCP_SOCKET.SND_CWND], ebx
|
||||||
|
|
||||||
.not_idle:
|
.not_idle:
|
||||||
.again:
|
.again:
|
||||||
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] ;
|
||||||
|
|
||||||
mov ecx, [eax + TCP_SOCKET.SND_WND] ; determine window
|
mov ecx, [eax + TCP_SOCKET.SND_WND] ; determine window
|
||||||
cmp ecx, [eax + TCP_SOCKET.SND_CWND] ;
|
cmp ecx, [eax + TCP_SOCKET.SND_CWND] ;
|
||||||
jb @f ;
|
jb @f ;
|
||||||
mov ecx, [eax + TCP_SOCKET.SND_CWND] ;
|
mov ecx, [eax + TCP_SOCKET.SND_CWND] ;
|
||||||
@@: ;
|
@@: ;
|
||||||
|
|
||||||
call TCP_outflags ; flags in dl
|
call TCP_outflags ; flags in dl
|
||||||
|
|
||||||
;------------------------
|
;------------------------
|
||||||
; data being forced out ?
|
; data being forced out ?
|
||||||
@ -69,36 +69,36 @@ TCP_output:
|
|||||||
; Otherwise, if window is small but nonzero, and timer expired,
|
; Otherwise, if window is small but nonzero, and timer expired,
|
||||||
; we will send what we can and go to transmit state
|
; we will send what we can and go to transmit state
|
||||||
|
|
||||||
test [eax + TCP_SOCKET.t_force], -1
|
test [eax + TCP_SOCKET.t_force], -1
|
||||||
jz .no_force
|
jz .no_force
|
||||||
|
|
||||||
test ecx, ecx
|
test ecx, ecx
|
||||||
jnz .no_zero_window
|
jnz .no_zero_window
|
||||||
|
|
||||||
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) ; clear the FIN flag ??? how can it be set before?
|
||||||
|
|
||||||
@@:
|
@@:
|
||||||
inc ecx
|
inc ecx
|
||||||
jmp .no_force
|
jmp .no_force
|
||||||
|
|
||||||
.no_zero_window:
|
.no_zero_window:
|
||||||
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
|
||||||
|
|
||||||
.no_force:
|
.no_force:
|
||||||
|
|
||||||
;--------------------------------
|
;--------------------------------
|
||||||
; Calculate how much data to send (106)
|
; Calculate how much data to send (106)
|
||||||
|
|
||||||
mov esi, [eax + STREAM_SOCKET.snd.size]
|
mov esi, [eax + STREAM_SOCKET.snd.size]
|
||||||
cmp esi, ecx
|
cmp esi, ecx
|
||||||
jb @f
|
jb @f
|
||||||
mov esi, ecx
|
mov esi, ecx
|
||||||
@@:
|
@@:
|
||||||
sub esi, ebx
|
sub esi, ebx
|
||||||
|
|
||||||
;------------------------
|
;------------------------
|
||||||
; check for window shrink (107)
|
; check for window shrink (107)
|
||||||
@ -106,21 +106,21 @@ TCP_output:
|
|||||||
; If FIN has been set, but not ACKed, but we havent been called to retransmit, esi will be -1
|
; If FIN has been set, but not ACKed, but we havent been called to retransmit, esi will be -1
|
||||||
; Otherwise, window shrank after we sent into it.
|
; Otherwise, window shrank after we sent into it.
|
||||||
|
|
||||||
jns .not_negative
|
jns .not_negative
|
||||||
|
|
||||||
; enter persist state
|
; enter persist state
|
||||||
xor esi, esi
|
xor esi, esi
|
||||||
|
|
||||||
; If window shrank to 0
|
; If window shrank to 0
|
||||||
test ecx, ecx
|
test ecx, ecx
|
||||||
jnz @f
|
jnz @f
|
||||||
|
|
||||||
; cancel pending retransmit
|
; cancel pending retransmit
|
||||||
mov [eax + TCP_SOCKET.timer_retransmission], 0
|
mov [eax + TCP_SOCKET.timer_retransmission], 0
|
||||||
|
|
||||||
; pull SND_NXT back to (closed) window, We will enter persist state below.
|
; pull SND_NXT back to (closed) window, We will enter persist state below.
|
||||||
push [eax + TCP_SOCKET.SND_UNA]
|
push [eax + TCP_SOCKET.SND_UNA]
|
||||||
pop [eax + TCP_SOCKET.SND_NXT]
|
pop [eax + TCP_SOCKET.SND_NXT]
|
||||||
|
|
||||||
@@:
|
@@:
|
||||||
|
|
||||||
@ -131,10 +131,10 @@ TCP_output:
|
|||||||
;---------------------------
|
;---------------------------
|
||||||
; Send one segment at a time (124)
|
; Send one segment at a time (124)
|
||||||
|
|
||||||
cmp esi, [eax + TCP_SOCKET.t_maxseg]
|
cmp esi, [eax + TCP_SOCKET.t_maxseg]
|
||||||
jbe @f
|
jbe @f
|
||||||
|
|
||||||
mov esi, [eax + TCP_SOCKET.t_maxseg]
|
mov esi, [eax + TCP_SOCKET.t_maxseg]
|
||||||
|
|
||||||
;;; sendalot = 1
|
;;; sendalot = 1
|
||||||
|
|
||||||
@ -143,73 +143,73 @@ TCP_output:
|
|||||||
;--------------------------------------------
|
;--------------------------------------------
|
||||||
; Turn of FIN flag if send buffer not emptied (128)
|
; Turn of FIN flag if send buffer not emptied (128)
|
||||||
|
|
||||||
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]
|
sub edi, [eax + STREAM_SOCKET.snd.size]
|
||||||
jns @f
|
jns @f
|
||||||
|
|
||||||
and dl, not (TH_FIN)
|
and dl, not (TH_FIN)
|
||||||
|
|
||||||
@@:
|
@@:
|
||||||
|
|
||||||
;-------------------------------
|
;-------------------------------
|
||||||
; calculate window advertisement (130)
|
; calculate window advertisement (130)
|
||||||
|
|
||||||
mov ecx, SOCKET_MAXDATA
|
mov ecx, SOCKET_MAXDATA
|
||||||
sub ecx, [eax + STREAM_SOCKET.rcv.size]
|
sub ecx, [eax + STREAM_SOCKET.rcv.size]
|
||||||
|
|
||||||
;------------------------------
|
;------------------------------
|
||||||
; Sender silly window avoidance (131)
|
; Sender silly window avoidance (131)
|
||||||
|
|
||||||
test esi, esi
|
test esi, esi
|
||||||
jz .len_zero
|
jz .len_zero
|
||||||
|
|
||||||
cmp esi, [eax + TCP_SOCKET.t_maxseg]
|
cmp esi, [eax + TCP_SOCKET.t_maxseg]
|
||||||
je .send
|
je .send
|
||||||
|
|
||||||
test [eax + TCP_SOCKET.t_flags], TF_NODELAY
|
test [eax + TCP_SOCKET.t_flags], TF_NODELAY
|
||||||
jnz @f
|
jnz @f
|
||||||
; TODO: if not 'idle', skip to next codeblock
|
; TODO: if not 'idle', skip to next codeblock
|
||||||
@@:
|
@@:
|
||||||
add ebx, esi
|
add ebx, esi
|
||||||
cmp ebx, [eax + STREAM_SOCKET.snd.size]
|
cmp ebx, [eax + STREAM_SOCKET.snd.size]
|
||||||
jae .send
|
jae .send
|
||||||
|
|
||||||
test [eax + TCP_SOCKET.t_force], -1 ;;;
|
test [eax + TCP_SOCKET.t_force], -1 ;;;
|
||||||
jnz .send
|
jnz .send
|
||||||
|
|
||||||
mov ebx, [eax + TCP_SOCKET.max_sndwnd]
|
mov ebx, [eax + TCP_SOCKET.max_sndwnd]
|
||||||
shr ebx, 1
|
shr ebx, 1
|
||||||
cmp esi, ebx
|
cmp esi, ebx
|
||||||
jae .send
|
jae .send
|
||||||
|
|
||||||
mov ebx, [eax + TCP_SOCKET.SND_NXT]
|
mov ebx, [eax + TCP_SOCKET.SND_NXT]
|
||||||
cmp ebx, [eax + TCP_SOCKET.SND_MAX]
|
cmp ebx, [eax + TCP_SOCKET.SND_MAX]
|
||||||
jb .send
|
jb .send
|
||||||
|
|
||||||
.len_zero:
|
.len_zero:
|
||||||
|
|
||||||
;----------------------------------------
|
;----------------------------------------
|
||||||
; Check if a window update should be sent (154)
|
; Check if a window update should be sent (154)
|
||||||
|
|
||||||
test ecx, ecx
|
test ecx, ecx
|
||||||
jz .no_window
|
jz .no_window
|
||||||
|
|
||||||
push ecx
|
push ecx
|
||||||
mov cl, [eax + TCP_SOCKET.RCV_SCALE]
|
mov cl, [eax + TCP_SOCKET.RCV_SCALE]
|
||||||
inc cl ; we want it *2
|
inc cl ; we want it *2
|
||||||
mov ebx, TCP_max_win
|
mov ebx, TCP_max_win
|
||||||
shl ebx, cl
|
shl ebx, cl
|
||||||
pop ecx
|
pop ecx
|
||||||
cmp ebx, ecx
|
cmp ebx, ecx
|
||||||
cmovb ebx, ecx
|
cmovb ebx, ecx
|
||||||
|
|
||||||
; now ebx is TWICE the amount we can increase the window
|
; now ebx is TWICE the amount we can increase the window
|
||||||
; (with TCP_max_win shl rcv_scale as the maximum)
|
; (with TCP_max_win shl rcv_scale as the maximum)
|
||||||
|
|
||||||
cmp ebx, [eax + TCP_SOCKET.t_maxseg]
|
cmp ebx, [eax + TCP_SOCKET.t_maxseg]
|
||||||
jae .send
|
jae .send
|
||||||
|
|
||||||
;;; cmp ebx, [eax + ] ;;; TODO: check receive buffer high water mark
|
;;; cmp ebx, [eax + ] ;;; TODO: check receive buffer high water mark
|
||||||
;;; jae .send
|
;;; jae .send
|
||||||
@ -219,54 +219,57 @@ TCP_output:
|
|||||||
;--------------------------
|
;--------------------------
|
||||||
; Should a segment be sent? (174)
|
; Should a segment be sent? (174)
|
||||||
|
|
||||||
test [eax + TCP_SOCKET.t_flags], TF_ACKNOW ; we need to ACK
|
test [eax + TCP_SOCKET.t_flags], TF_ACKNOW ; we need to ACK
|
||||||
jnz .send
|
jnz .send
|
||||||
|
|
||||||
test dl, TH_SYN + TH_RST ; we need to send a SYN or RST
|
test dl, TH_SYN + TH_RST ; we need to send a SYN or RST
|
||||||
jnz .send
|
jnz .send
|
||||||
|
|
||||||
mov ebx, [eax + TCP_SOCKET.SND_UP] ; when urgent pointer is beyond start of send bufer
|
mov ebx, [eax + TCP_SOCKET.SND_UP] ; when urgent pointer is beyond start of send bufer
|
||||||
cmp ebx, [eax + TCP_SOCKET.SND_UNA]
|
cmp ebx, [eax + TCP_SOCKET.SND_UNA]
|
||||||
ja .send
|
ja .send
|
||||||
|
|
||||||
test dl, TH_FIN
|
test dl, TH_FIN
|
||||||
jz .enter_persist ; no reason to send, enter persist state
|
jz .enter_persist ; no reason to send, enter persist state
|
||||||
|
|
||||||
; 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 .send
|
jnz .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]
|
||||||
je .send
|
je .send
|
||||||
|
|
||||||
;--------------------
|
;--------------------
|
||||||
; Enter persist state (191)
|
; Enter persist state (191)
|
||||||
|
|
||||||
.enter_persist:
|
.enter_persist:
|
||||||
|
|
||||||
cmp [eax + STREAM_SOCKET.snd.size], 0 ; Data ready to send?
|
cmp [eax + STREAM_SOCKET.snd.size], 0 ; Data ready to send?
|
||||||
jne @f
|
jne @f
|
||||||
cmp [eax + TCP_SOCKET.timer_retransmission], 0
|
cmp [eax + TCP_SOCKET.timer_retransmission], 0
|
||||||
jne @f
|
jne @f
|
||||||
cmp [eax + TCP_SOCKET.timer_persist], 0 ; Persist timer already expired?
|
cmp [eax + TCP_SOCKET.timer_persist], 0 ; Persist timer already expired?
|
||||||
jne @f
|
jne @f
|
||||||
|
|
||||||
DEBUGF 1,"Entering persist state\n"
|
DEBUGF 1,"Entering persist state\n"
|
||||||
|
|
||||||
mov [eax + TCP_SOCKET.t_rxtshift], 0
|
mov [eax + TCP_SOCKET.t_rxtshift], 0
|
||||||
TCP_set_persist eax
|
TCP_set_persist eax
|
||||||
@@:
|
@@:
|
||||||
|
|
||||||
;----------------------------
|
;----------------------------
|
||||||
; No reason to send a segment (219)
|
; No reason to send a segment (219)
|
||||||
|
|
||||||
DEBUGF 1,"No reason to send a segment\n"
|
DEBUGF 1,"No reason to send a segment\n"
|
||||||
|
|
||||||
mov [eax + SOCKET.lock], 0
|
pusha
|
||||||
|
lea ecx, [eax + SOCKET.mutex]
|
||||||
|
call mutex_unlock
|
||||||
|
popa
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -288,75 +291,75 @@ TCP_output:
|
|||||||
|
|
||||||
.send:
|
.send:
|
||||||
|
|
||||||
DEBUGF 1,"Preparing to send a segment\n"
|
DEBUGF 1,"Preparing to send a segment\n"
|
||||||
|
|
||||||
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
|
sub esp, 8 ; create some space on stack
|
||||||
push eax ; save socket pointer
|
push eax ; save socket pointer
|
||||||
|
|
||||||
;------------------------------------
|
;------------------------------------
|
||||||
; Send options with first SYN segment
|
; Send options with first SYN segment
|
||||||
|
|
||||||
test dl, TH_SYN
|
test dl, TH_SYN
|
||||||
jz .options_done
|
jz .options_done
|
||||||
|
|
||||||
push [eax + TCP_SOCKET.ISS]
|
push [eax + TCP_SOCKET.ISS]
|
||||||
pop [eax + TCP_SOCKET.SND_NXT]
|
pop [eax + TCP_SOCKET.SND_NXT]
|
||||||
|
|
||||||
test [eax + TCP_SOCKET.t_flags], TF_NOOPT
|
test [eax + TCP_SOCKET.t_flags], TF_NOOPT
|
||||||
jnz .options_done
|
jnz .options_done
|
||||||
|
|
||||||
mov ecx, 1460 ;;;; FIXME
|
mov ecx, 1460 ;;;; FIXME
|
||||||
or ecx, TCP_OPT_MAXSEG shl 24 + 4 shl 16
|
or ecx, TCP_OPT_MAXSEG shl 24 + 4 shl 16
|
||||||
bswap ecx
|
bswap ecx
|
||||||
push ecx
|
push ecx
|
||||||
add di, 4
|
add di, 4
|
||||||
|
|
||||||
test [eax + TCP_SOCKET.t_flags], TF_REQ_SCALE
|
test [eax + TCP_SOCKET.t_flags], TF_REQ_SCALE
|
||||||
jz .no_syn
|
jz .no_syn
|
||||||
|
|
||||||
test dl, TH_ACK
|
test dl, TH_ACK
|
||||||
jnz .scale_opt
|
jnz .scale_opt
|
||||||
|
|
||||||
test [eax + TCP_SOCKET.t_flags], TF_RCVD_SCALE
|
test [eax + TCP_SOCKET.t_flags], TF_RCVD_SCALE
|
||||||
jz .no_syn
|
jz .no_syn
|
||||||
|
|
||||||
.scale_opt:
|
.scale_opt:
|
||||||
movzx ecx, byte [eax + TCP_SOCKET.request_r_scale]
|
movzx ecx, byte [eax + TCP_SOCKET.request_r_scale]
|
||||||
or ecx, TCP_OPT_WINDOW shl 24 + 4 shl 16 + TCP_OPT_NOP shl 8
|
or ecx, TCP_OPT_WINDOW shl 24 + 4 shl 16 + TCP_OPT_NOP shl 8
|
||||||
bswap ecx
|
bswap ecx
|
||||||
pushd ecx
|
pushd ecx
|
||||||
add di, 4
|
add di, 4
|
||||||
|
|
||||||
.no_syn:
|
.no_syn:
|
||||||
|
|
||||||
;------------------------------------
|
;------------------------------------
|
||||||
; Make the timestamp option if needed
|
; Make the timestamp option if needed
|
||||||
|
|
||||||
test [eax + TCP_SOCKET.t_flags], TF_REQ_TSTMP
|
test [eax + TCP_SOCKET.t_flags], TF_REQ_TSTMP
|
||||||
jz .no_timestamp
|
jz .no_timestamp
|
||||||
|
|
||||||
test dl, TH_RST
|
test dl, TH_RST
|
||||||
jnz .no_timestamp
|
jnz .no_timestamp
|
||||||
|
|
||||||
test dl, TH_ACK
|
test dl, TH_ACK
|
||||||
jz .timestamp
|
jz .timestamp
|
||||||
|
|
||||||
test [eax + TCP_SOCKET.t_flags], TF_RCVD_TSTMP
|
test [eax + TCP_SOCKET.t_flags], TF_RCVD_TSTMP
|
||||||
jz .no_timestamp
|
jz .no_timestamp
|
||||||
|
|
||||||
.timestamp:
|
.timestamp:
|
||||||
mov ebx, [timer_ticks]
|
mov ebx, [timer_ticks]
|
||||||
bswap ebx
|
bswap ebx
|
||||||
push ebx
|
push ebx
|
||||||
pushw 0
|
pushw 0
|
||||||
pushd TCP_OPT_TIMESTAMP + 10 shl 8 + TCP_OPT_NOP shl 16 + TCP_OPT_NOP shl 24
|
pushd TCP_OPT_TIMESTAMP + 10 shl 8 + TCP_OPT_NOP shl 16 + TCP_OPT_NOP shl 24
|
||||||
add di, 10
|
add di, 10
|
||||||
|
|
||||||
.no_timestamp:
|
.no_timestamp:
|
||||||
|
|
||||||
; <Add additional options here>
|
; <Add additional options here>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -375,11 +378,11 @@ TCP_output:
|
|||||||
;---------------------------------------------
|
;---------------------------------------------
|
||||||
; check if we dont exceed the max segment size (270)
|
; check if we dont exceed the max segment size (270)
|
||||||
|
|
||||||
add esi, edi ; total TCP segment size
|
add esi, edi ; total TCP segment size
|
||||||
cmp esi, [eax + TCP_SOCKET.t_maxseg]
|
cmp esi, [eax + TCP_SOCKET.t_maxseg]
|
||||||
jbe .no_overflow
|
jbe .no_overflow
|
||||||
|
|
||||||
mov esi, [eax + TCP_SOCKET.t_maxseg]
|
mov esi, [eax + TCP_SOCKET.t_maxseg]
|
||||||
|
|
||||||
;;; sendalot = 1
|
;;; sendalot = 1
|
||||||
|
|
||||||
@ -389,60 +392,60 @@ TCP_output:
|
|||||||
; Start by pushing all TCP header values in reverse order on stack
|
; Start by pushing all TCP header values in reverse order on stack
|
||||||
; (essentially, creating the tcp header on the stack!)
|
; (essentially, creating the tcp header on the stack!)
|
||||||
|
|
||||||
pushw 0 ; .UrgentPointer dw ?
|
pushw 0 ; .UrgentPointer dw ?
|
||||||
pushw 0 ; .Checksum dw ?
|
pushw 0 ; .Checksum dw ?
|
||||||
pushw 0x00a0 ; .Window dw ? ;;;;;;; FIXME
|
pushw 0x00a0 ; .Window dw ? ;;;;;;; FIXME
|
||||||
shl edi, 2 ; .DataOffset db ? only 4 left-most bits
|
shl edi, 2 ; .DataOffset db ? only 4 left-most bits
|
||||||
shl dx, 8
|
shl dx, 8
|
||||||
or dx, di ; .Flags db ?
|
or dx, di ; .Flags db ?
|
||||||
pushw dx
|
pushw dx
|
||||||
shr edi, 2 ; .DataOffset db ? ;;;;
|
shr edi, 2 ; .DataOffset db ? ;;;;
|
||||||
|
|
||||||
push [eax + TCP_SOCKET.RCV_NXT] ; .AckNumber dd ?
|
push [eax + TCP_SOCKET.RCV_NXT] ; .AckNumber dd ?
|
||||||
ntohd [esp]
|
ntohd [esp]
|
||||||
|
|
||||||
push [eax + TCP_SOCKET.SND_NXT] ; .SequenceNumber dd ?
|
push [eax + TCP_SOCKET.SND_NXT] ; .SequenceNumber dd ?
|
||||||
ntohd [esp]
|
ntohd [esp]
|
||||||
|
|
||||||
push [eax + TCP_SOCKET.RemotePort] ; .DestinationPort dw ?
|
push [eax + TCP_SOCKET.RemotePort] ; .DestinationPort dw ?
|
||||||
ntohw [esp]
|
ntohw [esp]
|
||||||
|
|
||||||
push [eax + TCP_SOCKET.LocalPort] ; .SourcePort dw ?
|
push [eax + TCP_SOCKET.LocalPort] ; .SourcePort dw ?
|
||||||
ntohw [esp]
|
ntohw [esp]
|
||||||
|
|
||||||
push edi ; header size
|
push edi ; header size
|
||||||
|
|
||||||
;---------------------
|
;---------------------
|
||||||
; Create the IP packet
|
; Create the IP packet
|
||||||
|
|
||||||
mov ecx, esi
|
mov ecx, esi
|
||||||
|
|
||||||
mov ebx, [eax + IP_SOCKET.LocalIP] ; source ip
|
mov ebx, [eax + IP_SOCKET.LocalIP] ; source ip
|
||||||
mov eax, [eax + IP_SOCKET.RemoteIP] ; dest ip
|
mov eax, [eax + IP_SOCKET.RemoteIP] ; dest ip
|
||||||
mov di, IP_PROTO_TCP shl 8 + 128
|
mov di, IP_PROTO_TCP shl 8 + 128
|
||||||
call IPv4_output
|
call IPv4_output
|
||||||
jz .fail
|
jz .fail
|
||||||
|
|
||||||
;-----------------------------------------
|
;-----------------------------------------
|
||||||
; Move TCP header from stack to TCP packet
|
; Move TCP header from stack to TCP packet
|
||||||
|
|
||||||
push ecx
|
push ecx
|
||||||
mov ecx, [esp+4]
|
mov ecx, [esp+4]
|
||||||
lea esi, [esp+4+4]
|
lea esi, [esp+4+4]
|
||||||
shr ecx, 2
|
shr ecx, 2
|
||||||
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
|
||||||
|
|
||||||
mov [esp + 4], eax ; packet ptr
|
mov [esp + 4], eax ; packet ptr
|
||||||
mov [esp + 4+4], edx ; packet size
|
mov [esp + 4+4], edx ; packet size
|
||||||
|
|
||||||
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)
|
||||||
push ecx
|
push ecx
|
||||||
sub ecx, esi ; data size
|
sub ecx, esi ; data size
|
||||||
|
|
||||||
;--------------
|
;--------------
|
||||||
; Copy the data
|
; Copy the data
|
||||||
@ -451,52 +454,52 @@ TCP_output:
|
|||||||
; ecx = buffer size
|
; ecx = buffer size
|
||||||
; edi = ptr to buffer
|
; edi = ptr to buffer
|
||||||
|
|
||||||
mov eax, [esp+4] ; get socket ptr
|
mov eax, [esp+4] ; get socket ptr
|
||||||
|
|
||||||
add [eax + TCP_SOCKET.SND_NXT], ecx ; update sequence number
|
add [eax + TCP_SOCKET.SND_NXT], ecx ; update sequence number
|
||||||
|
|
||||||
add eax, STREAM_SOCKET.snd
|
add eax, STREAM_SOCKET.snd
|
||||||
push edx
|
push edx
|
||||||
call SOCKET_ring_read
|
call SOCKET_ring_read
|
||||||
pop esi ; begin of data
|
pop esi ; begin of data
|
||||||
pop ecx ; full packet size
|
pop ecx ; full packet size
|
||||||
pop eax ; socket ptr
|
pop eax ; socket ptr
|
||||||
|
|
||||||
;----------------------------------
|
;----------------------------------
|
||||||
; update sequence number and timers (400)
|
; update sequence number and timers (400)
|
||||||
|
|
||||||
test [esi + TCP_header.Flags], TH_SYN + TH_FIN
|
test [esi + TCP_header.Flags], TH_SYN + TH_FIN
|
||||||
jz @f
|
jz @f
|
||||||
inc [eax + TCP_SOCKET.SND_NXT] ; syn and fin take a sequence number
|
inc [eax + TCP_SOCKET.SND_NXT] ; syn and fin take a sequence number
|
||||||
test [esi + TCP_header.Flags], TH_FIN
|
test [esi + TCP_header.Flags], TH_FIN
|
||||||
jz @f
|
jz @f
|
||||||
or [eax + TCP_SOCKET.t_flags], TF_SENTFIN ; if we sent a fin, set the sentfin flag
|
or [eax + TCP_SOCKET.t_flags], TF_SENTFIN ; if we sent a fin, set the sentfin flag
|
||||||
@@:
|
@@:
|
||||||
|
|
||||||
mov edx, [eax + TCP_SOCKET.SND_NXT]
|
mov edx, [eax + TCP_SOCKET.SND_NXT]
|
||||||
cmp edx, [eax + TCP_SOCKET.SND_MAX]
|
cmp edx, [eax + TCP_SOCKET.SND_MAX]
|
||||||
jbe @f
|
jbe @f
|
||||||
mov [eax + TCP_SOCKET.SND_MAX], edx
|
mov [eax + TCP_SOCKET.SND_MAX], edx
|
||||||
|
|
||||||
;;;; TODO: time transmission (420)
|
;;;; TODO: time transmission (420)
|
||||||
|
|
||||||
@@:
|
@@:
|
||||||
|
|
||||||
; set retransmission timer if not already set, and not doing an ACK or keepalive probe
|
; set retransmission timer if not already set, and not doing an ACK or keepalive probe
|
||||||
|
|
||||||
cmp [eax + TCP_SOCKET.timer_retransmission], 1000 ;;;; FIXME
|
cmp [eax + TCP_SOCKET.timer_retransmission], 1000 ;;;; FIXME
|
||||||
jb .retransmit_set
|
jb .retransmit_set
|
||||||
|
|
||||||
cmp edx, [eax + TCP_SOCKET.SND_UNA] ; edx = [eax + TCP_SOCKET.SND_NXT]
|
cmp edx, [eax + TCP_SOCKET.SND_UNA] ; edx = [eax + TCP_SOCKET.SND_NXT]
|
||||||
je .retransmit_set
|
je .retransmit_set
|
||||||
|
|
||||||
mov edx, [eax + TCP_SOCKET.t_rxtcur]
|
mov edx, [eax + TCP_SOCKET.t_rxtcur]
|
||||||
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 @f
|
||||||
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:
|
||||||
@ -504,30 +507,38 @@ TCP_output:
|
|||||||
;--------------------
|
;--------------------
|
||||||
; Create the checksum
|
; Create the checksum
|
||||||
|
|
||||||
DEBUGF 1,"checksum: ptr=%x size=%u\n", esi, ecx
|
DEBUGF 1,"checksum: ptr=%x size=%u\n", esi, ecx
|
||||||
|
|
||||||
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
|
; unlock socket
|
||||||
|
|
||||||
mov [eax + SOCKET.lock], 0
|
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]
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
.fail:
|
.fail:
|
||||||
pop ecx
|
pop ecx
|
||||||
add esp, ecx
|
add esp, ecx
|
||||||
pop eax
|
pop eax
|
||||||
add esp, 8
|
add esp, 8
|
||||||
mov [eax + SOCKET.lock], 0
|
|
||||||
DEBUGF 1,"TCP_output: failed\n"
|
pusha
|
||||||
ret
|
lea ecx, [eax + SOCKET.mutex]
|
||||||
|
call mutex_unlock
|
||||||
|
popa
|
||||||
|
|
||||||
|
DEBUGF 1,"TCP_output: failed\n"
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
@ -178,10 +178,10 @@ UDP_input:
|
|||||||
cmp [eax + UDP_SOCKET.RemotePort], cx
|
cmp [eax + UDP_SOCKET.RemotePort], cx
|
||||||
jne .dump
|
jne .dump
|
||||||
|
|
||||||
push ebx
|
pusha
|
||||||
lea ebx, [eax + SOCKET.lock]
|
lea ecx, [eax + SOCKET.mutex]
|
||||||
call wait_mutex
|
call mutex_lock
|
||||||
pop ebx
|
popa
|
||||||
|
|
||||||
.updatesock:
|
.updatesock:
|
||||||
inc [UDP_PACKETS_RX]
|
inc [UDP_PACKETS_RX]
|
||||||
@ -193,10 +193,10 @@ UDP_input:
|
|||||||
jmp SOCKET_input
|
jmp SOCKET_input
|
||||||
|
|
||||||
.updateport:
|
.updateport:
|
||||||
push ebx
|
pusha
|
||||||
lea ebx, [eax + SOCKET.lock]
|
lea ecx, [eax + SOCKET.mutex]
|
||||||
call wait_mutex
|
call mutex_lock
|
||||||
pop ebx
|
popa
|
||||||
|
|
||||||
DEBUGF 1,"Changing remote port to: %u\n", cx
|
DEBUGF 1,"Changing remote port to: %u\n", cx
|
||||||
mov [eax + UDP_SOCKET.RemotePort], cx
|
mov [eax + UDP_SOCKET.RemotePort], cx
|
||||||
|
Loading…
Reference in New Issue
Block a user