2011-01-24 23:01:54 +01:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
|
|
|
;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;;
|
|
|
|
;; 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 ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
$Revision$
|
|
|
|
|
2011-01-08 15:59:21 +01:00
|
|
|
;-----------------------------------------------------------------
|
|
|
|
;
|
|
|
|
; TCP_output
|
|
|
|
;
|
|
|
|
; IN: eax = socket pointer
|
|
|
|
;
|
|
|
|
; OUT: /
|
|
|
|
;
|
|
|
|
;-----------------------------------------------------------------
|
|
|
|
align 4
|
|
|
|
TCP_output:
|
|
|
|
|
|
|
|
DEBUGF 1,"TCP_output, socket: %x\n", eax
|
|
|
|
|
|
|
|
|
|
|
|
; 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
|
|
|
|
; Otherwise, investigate further
|
|
|
|
|
|
|
|
mov ebx, [eax + TCP_SOCKET.SND_MAX]
|
|
|
|
cmp ebx, [eax + TCP_SOCKET.SND_UNA]
|
|
|
|
jne .not_idle
|
|
|
|
|
|
|
|
mov ebx, [eax + TCP_SOCKET.t_idle]
|
|
|
|
cmp ebx, [eax + TCP_SOCKET.t_rxtcur]
|
|
|
|
jle .not_idle
|
|
|
|
|
|
|
|
; 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.
|
|
|
|
|
|
|
|
mov ebx, [eax + TCP_SOCKET.t_maxseg]
|
|
|
|
mov [eax + TCP_SOCKET.SND_CWND], ebx
|
|
|
|
|
|
|
|
.not_idle:
|
|
|
|
.again:
|
2011-01-20 23:29:47 +01:00
|
|
|
mov ebx, [eax + TCP_SOCKET.SND_NXT] ; calculate offset (71)
|
2011-01-08 15:59:21 +01:00
|
|
|
sub ebx, [eax + TCP_SOCKET.SND_UNA] ;
|
|
|
|
|
|
|
|
mov ecx, [eax + TCP_SOCKET.SND_WND] ; determine window
|
|
|
|
cmp ecx, [eax + TCP_SOCKET.SND_CWND] ;
|
|
|
|
jl @f ;
|
|
|
|
mov ecx, [eax + TCP_SOCKET.SND_CWND] ;
|
|
|
|
@@: ;
|
|
|
|
|
2011-01-20 23:29:47 +01:00
|
|
|
call TCP_outflags ; flags in dl
|
|
|
|
|
|
|
|
;------------------------
|
|
|
|
; data being forced out ?
|
2011-01-08 15:59:21 +01:00
|
|
|
|
|
|
|
; If in persist timeout with window of 0, send 1 byte.
|
|
|
|
; Otherwise, if window is small but nonzero, and timer expired,
|
|
|
|
; we will send what we can and go to transmit state
|
|
|
|
|
|
|
|
test [eax + TCP_SOCKET.t_force], -1
|
2011-01-20 23:29:47 +01:00
|
|
|
jz .no_force
|
2011-01-08 15:59:21 +01:00
|
|
|
|
|
|
|
test ecx, ecx
|
|
|
|
jnz .no_zero_window
|
|
|
|
|
|
|
|
cmp ebx, [eax + STREAM_SOCKET.snd + RING_BUFFER.size]
|
|
|
|
jge @f
|
|
|
|
|
|
|
|
and dl, not (TH_FIN) ; clear the FIN flag ??? how can it be set before?
|
|
|
|
|
|
|
|
@@:
|
|
|
|
inc ecx
|
2011-01-20 23:29:47 +01:00
|
|
|
jmp .no_force
|
2011-01-08 15:59:21 +01:00
|
|
|
|
|
|
|
.no_zero_window:
|
|
|
|
mov [eax + TCP_SOCKET.timer_persist], 0
|
|
|
|
mov [eax + TCP_SOCKET.t_rxtshift], 0
|
|
|
|
|
2011-01-20 23:29:47 +01:00
|
|
|
.no_force:
|
2011-01-08 15:59:21 +01:00
|
|
|
|
2011-01-20 23:29:47 +01:00
|
|
|
;--------------------------------
|
|
|
|
; Calculate how much data to send (106)
|
2011-01-08 15:59:21 +01:00
|
|
|
|
|
|
|
mov esi, [eax + STREAM_SOCKET.snd + RING_BUFFER.size]
|
|
|
|
cmp esi, ecx
|
|
|
|
jl @f
|
|
|
|
mov esi, ecx
|
|
|
|
@@:
|
|
|
|
sub esi, ebx
|
|
|
|
|
2011-01-20 23:29:47 +01:00
|
|
|
;------------------------
|
|
|
|
; check for window shrink (107)
|
2011-01-08 15:59:21 +01:00
|
|
|
|
2011-01-20 23:29:47 +01:00
|
|
|
; If FIN has been set, but not ACKed, but we havent been called to retransmit, esi will be -1
|
2011-01-08 15:59:21 +01:00
|
|
|
; Otherwise, window shrank after we sent into it.
|
|
|
|
|
2011-01-24 00:56:32 +01:00
|
|
|
jns .not_negative
|
2011-01-20 23:29:47 +01:00
|
|
|
|
|
|
|
; enter persist state
|
2011-01-08 15:59:21 +01:00
|
|
|
xor esi, esi
|
|
|
|
|
2011-01-20 23:29:47 +01:00
|
|
|
; If window shrank to 0
|
2011-01-08 15:59:21 +01:00
|
|
|
test ecx, ecx
|
|
|
|
jnz @f
|
|
|
|
|
2011-01-20 23:29:47 +01:00
|
|
|
; cancel pending retransmit
|
|
|
|
mov [eax + TCP_SOCKET.timer_retransmission], 0
|
2011-01-08 15:59:21 +01:00
|
|
|
|
2011-01-20 23:29:47 +01:00
|
|
|
; pull SND_NXT back to (closed) window, We will enter persist state below.
|
2011-01-08 15:59:21 +01:00
|
|
|
push [eax + TCP_SOCKET.SND_UNA]
|
|
|
|
pop [eax + TCP_SOCKET.SND_NXT]
|
2011-01-20 23:29:47 +01:00
|
|
|
|
2011-01-08 15:59:21 +01:00
|
|
|
@@:
|
|
|
|
|
2011-01-20 23:29:47 +01:00
|
|
|
; If window didn't close completely, just wait for an ACK
|
|
|
|
|
2011-01-24 00:56:32 +01:00
|
|
|
.not_negative:
|
2011-01-08 15:59:21 +01:00
|
|
|
|
2011-01-20 23:29:47 +01:00
|
|
|
;---------------------------
|
|
|
|
; Send one segment at a time (124)
|
2011-01-08 15:59:21 +01:00
|
|
|
|
|
|
|
cmp esi, [eax + TCP_SOCKET.t_maxseg]
|
|
|
|
jle @f
|
|
|
|
|
|
|
|
mov esi, [eax + TCP_SOCKET.t_maxseg]
|
2011-01-20 23:29:47 +01:00
|
|
|
|
|
|
|
;;; sendalot = 1
|
2011-01-08 15:59:21 +01:00
|
|
|
|
|
|
|
@@:
|
|
|
|
|
2011-01-20 23:29:47 +01:00
|
|
|
;--------------------------------------------
|
|
|
|
; Turn of FIN flag if send buffer not emptied (128)
|
2011-01-08 15:59:21 +01:00
|
|
|
|
|
|
|
mov edi, [eax + TCP_SOCKET.SND_NXT]
|
2011-01-20 23:29:47 +01:00
|
|
|
add edi, esi
|
2011-01-08 15:59:21 +01:00
|
|
|
sub edi, [eax + TCP_SOCKET.SND_UNA]
|
2011-01-20 23:29:47 +01:00
|
|
|
sub edi, [eax + STREAM_SOCKET.snd + RING_BUFFER.size]
|
2011-01-24 00:56:32 +01:00
|
|
|
jns @f
|
2011-01-08 15:59:21 +01:00
|
|
|
|
2011-01-20 23:29:47 +01:00
|
|
|
and dl, not (TH_FIN)
|
2011-01-08 15:59:21 +01:00
|
|
|
|
|
|
|
@@:
|
|
|
|
|
2011-01-20 23:29:47 +01:00
|
|
|
;-------------------------------
|
|
|
|
; calculate window advertisement (130)
|
2011-01-08 15:59:21 +01:00
|
|
|
|
|
|
|
mov ecx, SOCKET_MAXDATA
|
|
|
|
sub ecx, [eax + STREAM_SOCKET.rcv + RING_BUFFER.size]
|
|
|
|
|
|
|
|
;------------------------------
|
2011-01-20 23:29:47 +01:00
|
|
|
; Sender silly window avoidance (131)
|
2011-01-08 15:59:21 +01:00
|
|
|
|
2011-01-20 23:29:47 +01:00
|
|
|
test esi, esi
|
|
|
|
jz .len_zero
|
|
|
|
|
|
|
|
cmp esi, [eax + TCP_SOCKET.t_maxseg]
|
2011-01-08 15:59:21 +01:00
|
|
|
je .send
|
|
|
|
|
2011-01-20 23:29:47 +01:00
|
|
|
;;; if (idle or TF_NODELAY) && (esi + ebx >= so_snd.sb_cc), send
|
2011-01-08 15:59:21 +01:00
|
|
|
|
2011-01-20 23:29:47 +01:00
|
|
|
test [eax + TCP_SOCKET.t_force], -1 ;;;
|
2011-01-08 15:59:21 +01:00
|
|
|
jnz .send
|
|
|
|
|
|
|
|
mov ebx, [eax + TCP_SOCKET.max_sndwnd]
|
|
|
|
shr ebx, 1
|
2011-01-20 23:29:47 +01:00
|
|
|
cmp esi, ebx
|
2011-01-08 15:59:21 +01:00
|
|
|
jge .send
|
|
|
|
|
|
|
|
mov ebx, [eax + TCP_SOCKET.SND_NXT]
|
|
|
|
cmp ebx, [eax + TCP_SOCKET.SND_MAX]
|
|
|
|
jl .send
|
|
|
|
|
2011-01-20 23:29:47 +01:00
|
|
|
.len_zero:
|
|
|
|
|
2011-01-08 15:59:21 +01:00
|
|
|
;----------------------------------------
|
2011-01-20 23:29:47 +01:00
|
|
|
; Check if a window update should be sent (154)
|
2011-01-08 15:59:21 +01:00
|
|
|
|
2011-01-20 23:29:47 +01:00
|
|
|
test ecx, ecx
|
2011-01-08 15:59:21 +01:00
|
|
|
jz .no_window
|
|
|
|
|
2011-01-20 23:29:47 +01:00
|
|
|
;;; TODO 167-172
|
2011-01-08 15:59:21 +01:00
|
|
|
|
|
|
|
.no_window:
|
|
|
|
|
|
|
|
;--------------------------
|
2011-01-20 23:29:47 +01:00
|
|
|
; Should a segment be sent? (174)
|
2011-01-08 15:59:21 +01:00
|
|
|
|
2011-01-20 23:29:47 +01:00
|
|
|
test [eax + TCP_SOCKET.t_flags], TF_ACKNOW ; we need to ACK
|
2011-01-08 15:59:21 +01:00
|
|
|
jnz .send
|
|
|
|
|
2011-01-20 23:29:47 +01:00
|
|
|
test dl, TH_SYN + TH_RST ; we need to send a SYN or RST
|
2011-01-08 15:59:21 +01:00
|
|
|
jnz .send
|
|
|
|
|
2011-01-20 23:29:47 +01:00
|
|
|
mov ebx, [eax + TCP_SOCKET.SND_UP] ; when urgent pointer is beyond start of send bufer
|
2011-01-08 15:59:21 +01:00
|
|
|
cmp ebx, [eax + TCP_SOCKET.SND_UNA]
|
|
|
|
jg .send
|
|
|
|
|
|
|
|
test dl, TH_FIN
|
2011-01-20 23:29:47 +01:00
|
|
|
jz .enter_persist ; no reason to send, enter persist state
|
|
|
|
|
|
|
|
; FIN was set, only send if not already sent, or on retransmit
|
2011-01-08 15:59:21 +01:00
|
|
|
|
|
|
|
test [eax + TCP_SOCKET.t_flags], TF_SENTFIN
|
|
|
|
jnz .send
|
|
|
|
|
|
|
|
mov ebx, [eax + TCP_SOCKET.SND_NXT]
|
|
|
|
cmp ebx, [eax + TCP_SOCKET.SND_UNA]
|
|
|
|
je .send
|
|
|
|
|
|
|
|
;--------------------
|
2011-01-20 23:29:47 +01:00
|
|
|
; Enter persist state (191)
|
2011-01-08 15:59:21 +01:00
|
|
|
|
|
|
|
.enter_persist:
|
|
|
|
|
|
|
|
DEBUGF 1,"Entering persist state\n"
|
|
|
|
|
2011-01-20 23:29:47 +01:00
|
|
|
|
|
|
|
;;; 213 - 217
|
|
|
|
|
|
|
|
;----------------------------
|
|
|
|
; No reason to send a segment (219)
|
2011-01-08 15:59:21 +01:00
|
|
|
|
|
|
|
DEBUGF 1,"No reason to send a segment\n"
|
|
|
|
|
2011-01-20 23:29:47 +01:00
|
|
|
mov [eax + SOCKET.lock], 0
|
2011-01-08 15:59:21 +01:00
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
2011-01-20 23:29:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-01-08 15:59:21 +01:00
|
|
|
;-----------------------------------------------
|
|
|
|
;
|
2011-01-20 23:29:47 +01:00
|
|
|
; Send a segment (222)
|
2011-01-08 15:59:21 +01:00
|
|
|
;
|
|
|
|
; eax = socket pointer
|
2011-01-20 23:29:47 +01:00
|
|
|
; esi = data len
|
2011-01-08 15:59:21 +01:00
|
|
|
; dl = flags
|
|
|
|
;
|
|
|
|
;-----------------------------------------------
|
|
|
|
|
|
|
|
.send:
|
|
|
|
|
|
|
|
DEBUGF 1,"Preparing to send a segment\n"
|
|
|
|
|
|
|
|
mov edi, TCP_segment.Data ; edi will contain headersize
|
|
|
|
|
|
|
|
sub esp, 8 ; create some space on stack
|
2011-01-20 23:29:47 +01:00
|
|
|
push eax ; save socket pointer
|
2011-01-08 15:59:21 +01:00
|
|
|
|
|
|
|
;------------------------------------
|
|
|
|
; Send options with first SYN segment
|
|
|
|
|
|
|
|
test dl, TH_SYN
|
2011-01-20 23:29:47 +01:00
|
|
|
jz .options_done
|
2011-01-08 15:59:21 +01:00
|
|
|
|
|
|
|
push [eax + TCP_SOCKET.ISS]
|
|
|
|
pop [eax + TCP_SOCKET.SND_NXT]
|
|
|
|
|
|
|
|
test [eax + TCP_SOCKET.t_flags], TF_NOOPT
|
2011-01-20 23:29:47 +01:00
|
|
|
jnz .options_done
|
2011-01-08 15:59:21 +01:00
|
|
|
|
|
|
|
mov ecx, 1460
|
|
|
|
or ecx, TCP_OPT_MAXSEG shl 24 + 4 shl 16
|
|
|
|
bswap ecx
|
|
|
|
push ecx
|
|
|
|
add di, 4
|
|
|
|
|
|
|
|
test [eax + TCP_SOCKET.t_flags], TF_REQ_SCALE
|
|
|
|
jz .no_syn
|
|
|
|
|
|
|
|
test dl, TH_ACK
|
|
|
|
jnz .scale_opt
|
|
|
|
|
|
|
|
test [eax + TCP_SOCKET.t_flags], TF_RCVD_SCALE
|
|
|
|
jz .no_syn
|
|
|
|
|
|
|
|
.scale_opt:
|
|
|
|
movzx ecx, byte [eax + TCP_SOCKET.request_r_scale]
|
|
|
|
or ecx, TCP_OPT_WINDOW shl 24 + 4 shl 16 + TCP_OPT_NOP shl 8
|
|
|
|
bswap ecx
|
|
|
|
pushd ecx
|
|
|
|
add di, 4
|
|
|
|
|
|
|
|
.no_syn:
|
|
|
|
|
|
|
|
;------------------------------------
|
|
|
|
; Make the timestamp option if needed
|
|
|
|
|
|
|
|
test [eax + TCP_SOCKET.t_flags], TF_REQ_TSTMP
|
|
|
|
jz .no_timestamp
|
|
|
|
|
|
|
|
test dl, TH_RST
|
|
|
|
jnz .no_timestamp
|
|
|
|
|
|
|
|
test dl, TH_ACK
|
|
|
|
jz .timestamp
|
|
|
|
|
|
|
|
test [eax + TCP_SOCKET.t_flags], TF_RCVD_TSTMP
|
|
|
|
jz .no_timestamp
|
|
|
|
|
|
|
|
.timestamp:
|
2011-01-20 23:29:47 +01:00
|
|
|
mov ebx, [timer_ticks]
|
|
|
|
bswap ebx
|
|
|
|
push ebx
|
2011-01-08 15:59:21 +01:00
|
|
|
pushw 0
|
|
|
|
pushd TCP_OPT_TIMESTAMP + 10 shl 8 + TCP_OPT_NOP shl 16 + TCP_OPT_NOP shl 24
|
|
|
|
add di, 10
|
|
|
|
|
|
|
|
.no_timestamp:
|
|
|
|
|
2011-01-20 23:29:47 +01:00
|
|
|
; <Add additional options here>
|
|
|
|
|
|
|
|
|
2011-01-08 15:59:21 +01:00
|
|
|
|
|
|
|
|
2011-01-20 23:29:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.options_done:
|
|
|
|
|
|
|
|
; eax = socket ptr
|
|
|
|
; edx = flags
|
|
|
|
; edi = header size
|
|
|
|
; esi = data len
|
|
|
|
|
|
|
|
;---------------------------------------------
|
|
|
|
; check if we dont exceed the max segment size (270)
|
|
|
|
|
|
|
|
add esi, edi ; total TCP segment size
|
|
|
|
cmp esi, [eax + TCP_SOCKET.t_maxseg]
|
|
|
|
jle .no_overflow
|
|
|
|
|
|
|
|
mov esi, [eax + TCP_SOCKET.t_maxseg]
|
|
|
|
|
|
|
|
;;; sendalot = 1
|
|
|
|
|
|
|
|
.no_overflow:
|
|
|
|
|
|
|
|
;-----------------------------------------------------------------
|
2011-01-08 15:59:21 +01:00
|
|
|
; Start by pushing all TCP header values in reverse order on stack
|
2011-01-20 23:29:47 +01:00
|
|
|
; (essentially, creating the tcp header on the stack!)
|
2011-01-08 15:59:21 +01:00
|
|
|
|
|
|
|
pushw 0 ; .UrgentPointer dw ?
|
|
|
|
pushw 0 ; .Checksum dw ?
|
2011-02-01 17:14:18 +01:00
|
|
|
pushw 0x00a0 ; .Window dw ? ;;;;;;; FIXME
|
2011-01-08 15:59:21 +01:00
|
|
|
shl edi, 2 ; .DataOffset db ? only 4 left-most bits
|
|
|
|
shl dx, 8
|
|
|
|
or dx, di ; .Flags db ?
|
|
|
|
pushw dx
|
|
|
|
shr edi, 2 ; .DataOffset db ? ;;;;
|
|
|
|
|
|
|
|
push [eax + TCP_SOCKET.RCV_NXT] ; .AckNumber dd ?
|
|
|
|
ntohd [esp]
|
|
|
|
|
|
|
|
push [eax + TCP_SOCKET.SND_NXT] ; .SequenceNumber dd ?
|
|
|
|
ntohd [esp]
|
|
|
|
|
|
|
|
push [eax + TCP_SOCKET.RemotePort] ; .DestinationPort dw ?
|
|
|
|
ntohw [esp]
|
|
|
|
|
|
|
|
push [eax + TCP_SOCKET.LocalPort] ; .SourcePort dw ?
|
|
|
|
ntohw [esp]
|
|
|
|
|
|
|
|
push edi ; header size
|
|
|
|
|
2011-01-20 23:29:47 +01:00
|
|
|
;---------------------
|
2011-01-08 15:59:21 +01:00
|
|
|
; Create the IP packet
|
2011-01-20 23:29:47 +01:00
|
|
|
|
|
|
|
mov ecx, esi
|
|
|
|
|
2011-01-08 15:59:21 +01:00
|
|
|
mov ebx, [eax + IP_SOCKET.LocalIP] ; source ip
|
|
|
|
mov eax, [eax + IP_SOCKET.RemoteIP] ; dest ip
|
|
|
|
mov di, IP_PROTO_TCP shl 8 + 128
|
|
|
|
call IPv4_output
|
|
|
|
jz .fail
|
|
|
|
|
|
|
|
;-----------------------------------------
|
|
|
|
; Move TCP header from stack to TCP packet
|
|
|
|
|
|
|
|
push ecx
|
|
|
|
mov ecx, [esp+4]
|
|
|
|
lea esi, [esp+4+4]
|
|
|
|
shr ecx, 2
|
|
|
|
rep movsd
|
|
|
|
pop ecx ; full TCP packet size
|
|
|
|
|
|
|
|
pop esi ; headersize
|
|
|
|
add esp, esi
|
|
|
|
|
|
|
|
mov [esp + 4], eax ; packet ptr
|
|
|
|
mov [esp + 4+4], edx ; packet size
|
|
|
|
|
|
|
|
mov edx, edi ; begin of data
|
|
|
|
sub edx, esi ; begin of packet (edi = begin of data)
|
|
|
|
push ecx
|
|
|
|
sub ecx, esi ; data size
|
|
|
|
|
|
|
|
;--------------
|
|
|
|
; Copy the data
|
|
|
|
|
|
|
|
; eax = ptr to ring struct
|
|
|
|
; ecx = buffer size
|
|
|
|
; edi = ptr to buffer
|
|
|
|
|
2011-01-20 23:29:47 +01:00
|
|
|
mov eax, [esp+4] ; get socket ptr
|
|
|
|
|
|
|
|
add [eax + TCP_SOCKET.SND_NXT], ecx ; update sequence number
|
|
|
|
|
2011-01-08 15:59:21 +01:00
|
|
|
add eax, STREAM_SOCKET.snd
|
|
|
|
push edx
|
|
|
|
call SOCKET_ring_read
|
2011-01-20 23:29:47 +01:00
|
|
|
pop esi ; begin of data
|
|
|
|
pop ecx ; full packet size
|
|
|
|
pop eax ; socket ptr
|
|
|
|
|
|
|
|
;----------------------------------
|
|
|
|
; update sequence number and timers (400)
|
2011-01-08 15:59:21 +01:00
|
|
|
|
|
|
|
test [esi + TCP_segment.Flags], TH_SYN + TH_FIN
|
|
|
|
jz @f
|
2011-01-20 23:29:47 +01:00
|
|
|
inc [eax + TCP_SOCKET.SND_NXT] ; syn and fin take a sequence number
|
|
|
|
test [esi + TCP_segment.Flags], TH_FIN
|
|
|
|
jz @f
|
|
|
|
or [eax + TCP_SOCKET.t_flags], TF_SENTFIN ; if we sent a fin, set the sentfin flag
|
2011-01-08 15:59:21 +01:00
|
|
|
@@:
|
|
|
|
|
|
|
|
mov edx, [eax + TCP_SOCKET.SND_NXT]
|
|
|
|
cmp edx, [eax + TCP_SOCKET.SND_MAX]
|
|
|
|
jle @f
|
|
|
|
mov [eax + TCP_SOCKET.SND_MAX], edx
|
|
|
|
|
|
|
|
;;;; TODO: time transmission (420)
|
2011-01-20 23:29:47 +01:00
|
|
|
|
2011-01-08 15:59:21 +01:00
|
|
|
@@:
|
|
|
|
|
2011-01-20 23:29:47 +01:00
|
|
|
; set retransmission timer if not already set, and not doing an ACK or keepalive probe
|
|
|
|
|
|
|
|
cmp [eax + TCP_SOCKET.timer_retransmission], 1000 ;;;;
|
|
|
|
jl .retransmit_set
|
|
|
|
|
|
|
|
cmp edx, [eax + TCP_SOCKET.SND_UNA] ; edx = [eax + TCP_SOCKET.SND_NXT]
|
|
|
|
je .retransmit_set
|
|
|
|
|
|
|
|
mov edx, [eax + TCP_SOCKET.t_rxtcur]
|
|
|
|
mov [eax + TCP_SOCKET.timer_retransmission], dx
|
|
|
|
|
|
|
|
mov [eax + TCP_SOCKET.timer_persist], 0
|
|
|
|
mov [eax + TCP_SOCKET.t_rxtshift], 0 ;;; TODO: only do this if timer_persist was set
|
|
|
|
|
|
|
|
|
|
|
|
.retransmit_set:
|
2011-01-08 15:59:21 +01:00
|
|
|
|
|
|
|
;--------------------
|
|
|
|
; Create the checksum
|
|
|
|
|
|
|
|
DEBUGF 1,"checksum: ptr=%x size=%u\n", esi, ecx
|
|
|
|
|
|
|
|
TCP_checksum (eax + IP_SOCKET.LocalIP), (eax + IP_SOCKET.RemoteIP)
|
|
|
|
mov [esi+TCP_segment.Checksum], dx
|
|
|
|
|
2011-01-20 23:29:47 +01:00
|
|
|
; unlock socket
|
|
|
|
|
|
|
|
mov [eax + SOCKET.lock], 0
|
|
|
|
|
2011-01-08 15:59:21 +01:00
|
|
|
;----------------
|
|
|
|
; Send the packet
|
|
|
|
|
|
|
|
DEBUGF 1,"Sending TCP Packet to device %x\n", ebx
|
|
|
|
call [ebx + NET_DEVICE.transmit]
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
.fail:
|
|
|
|
pop ecx
|
|
|
|
add esp, ecx
|
2011-02-03 22:35:16 +01:00
|
|
|
pop eax
|
|
|
|
add esp, 8
|
2011-01-20 23:29:47 +01:00
|
|
|
mov [eax + SOCKET.lock], 0
|
2011-01-08 15:59:21 +01:00
|
|
|
DEBUGF 1,"TCP_output: failed\n"
|
|
|
|
ret
|
|
|
|
|
|
|
|
|