Markup changes in net branch + updates in TCP_output

git-svn-id: svn://kolibrios.org@2362 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2012-02-21 08:44:51 +00:00
parent 8fd9581723
commit f156bb294d
5 changed files with 1652 additions and 1598 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;; ;; ;;
;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;; ;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;; ;; Distributed under terms of the GNU General Public License ;;
;; ;; ;; ;;
;; Part of the tcp/ip network stack for KolibriOS ;; ;; Part of the tcp/ip network stack for KolibriOS ;;
@ -93,8 +93,8 @@ ends
align 4 align 4
uglobal uglobal
TCP_headers_tx rd IP_MAX_INTERFACES TCP_headers_tx rd IP_MAX_INTERFACES
TCP_headers_rx rd IP_MAX_INTERFACES TCP_headers_rx rd IP_MAX_INTERFACES
TCP_bytes_rx rq IP_MAX_INTERFACES TCP_bytes_rx rq IP_MAX_INTERFACES
TCP_bytes_tx rq IP_MAX_INTERFACES TCP_bytes_tx rq IP_MAX_INTERFACES
TCP_sequence_num dd ? TCP_sequence_num dd ?

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;; ;; ;;
;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;; ;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;; ;; Distributed under terms of the GNU General Public License ;;
;; ;; ;; ;;
;; Part of the tcp/ip network stack for KolibriOS ;; ;; Part of the tcp/ip network stack for KolibriOS ;;
@ -75,7 +75,7 @@ TCP_output:
test ecx, ecx test ecx, ecx
jnz .no_zero_window jnz .no_zero_window
cmp ebx, [eax + STREAM_SOCKET.snd + RING_BUFFER.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?
@ -93,7 +93,7 @@ TCP_output:
;-------------------------------- ;--------------------------------
; Calculate how much data to send (106) ; Calculate how much data to send (106)
mov esi, [eax + STREAM_SOCKET.snd + RING_BUFFER.size] mov esi, [eax + STREAM_SOCKET.snd.size]
cmp esi, ecx cmp esi, ecx
jb @f jb @f
mov esi, ecx mov esi, ecx
@ -146,7 +146,7 @@ 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 + RING_BUFFER.size] sub edi, [eax + STREAM_SOCKET.snd.size]
jns @f jns @f
and dl, not (TH_FIN) and dl, not (TH_FIN)
@ -157,7 +157,7 @@ TCP_output:
; calculate window advertisement (130) ; calculate window advertisement (130)
mov ecx, SOCKET_MAXDATA mov ecx, SOCKET_MAXDATA
sub ecx, [eax + STREAM_SOCKET.rcv + RING_BUFFER.size] sub ecx, [eax + STREAM_SOCKET.rcv.size]
;------------------------------ ;------------------------------
; Sender silly window avoidance (131) ; Sender silly window avoidance (131)
@ -168,7 +168,13 @@ TCP_output:
cmp esi, [eax + TCP_SOCKET.t_maxseg] cmp esi, [eax + TCP_SOCKET.t_maxseg]
je .send je .send
;;; if (idle or TF_NODELAY) && (esi + ebx >= so_snd.sb_cc), send test [eax + TCP_SOCKET.t_flags], TF_NODELAY
jnz @f
; TODO: if not 'idle', skip to next codeblock
@@:
add ebx, esi
cmp ebx, [eax + STREAM_SOCKET.snd.size]
jae .send
test [eax + TCP_SOCKET.t_force], -1 ;;; test [eax + TCP_SOCKET.t_force], -1 ;;;
jnz .send jnz .send
@ -190,7 +196,23 @@ TCP_output:
test ecx, ecx test ecx, ecx
jz .no_window jz .no_window
;;; TODO 167-172 push ecx
mov cl, [eax + TCP_SOCKET.RCV_SCALE]
inc cl ; we want it *2
mov ebx, TCP_max_win
shl ebx, cl
pop ecx
cmp ebx, ecx
cmovb ebx, ecx
; now ebx is TWICE the amount we can increase the window
; (with TCP_max_win shl rcv_scale as the maximum)
cmp ebx, [eax + TCP_SOCKET.t_maxseg]
jae .send
;;; cmp ebx, [eax + ] ;;; TODO: check receive buffer high water mark
;;; jae .send
.no_window: .no_window:
@ -224,10 +246,18 @@ TCP_output:
.enter_persist: .enter_persist:
cmp [eax + STREAM_SOCKET.snd.size], 0 ; Data ready to send?
jne @f
cmp [eax + TCP_SOCKET.timer_retransmission], 0
jne @f
cmp [eax + TCP_SOCKET.timer_persist], 0 ; Persist timer already expired?
jne @f
DEBUGF 1,"Entering persist state\n" DEBUGF 1,"Entering persist state\n"
mov [eax + TCP_SOCKET.t_rxtshift], 0
;;; 213 - 217 TCP_set_persist eax
@@:
;---------------------------- ;----------------------------
; No reason to send a segment (219) ; No reason to send a segment (219)
@ -260,7 +290,7 @@ TCP_output:
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
@ -463,9 +493,11 @@ TCP_output:
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
jne @f
mov [eax + TCP_SOCKET.timer_persist], 0 mov [eax + TCP_SOCKET.timer_persist], 0
mov [eax + TCP_SOCKET.t_rxtshift], 0 ;;; TODO: only do this if timer_persist was set mov [eax + TCP_SOCKET.t_rxtshift], 0
@@:
.retransmit_set: .retransmit_set:

View File

@ -1,6 +1,6 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;; ;; ;;
;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;; ;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;; ;; Distributed under terms of the GNU General Public License ;;
;; ;; ;; ;;
;; Part of the tcp/ip network stack for KolibriOS ;; ;; Part of the tcp/ip network stack for KolibriOS ;;
@ -16,65 +16,65 @@
$Revision$ $Revision$
macro TCP_checksum IP1, IP2 { macro TCP_checksum IP1, IP2 {
;------------- ;-------------
; Pseudoheader ; Pseudoheader
; protocol type ; protocol type
mov edx, IP_PROTO_TCP mov edx, IP_PROTO_TCP
; source address ; source address
add dl, byte [IP1+1] add dl, byte [IP1+1]
adc dh, byte [IP1+0] adc dh, byte [IP1+0]
adc dl, byte [IP1+3] adc dl, byte [IP1+3]
adc dh, byte [IP1+2] adc dh, byte [IP1+2]
; destination address ; destination address
adc dl, byte [IP2+1] adc dl, byte [IP2+1]
adc dh, byte [IP2+0] adc dh, byte [IP2+0]
adc dl, byte [IP2+3] adc dl, byte [IP2+3]
adc dh, byte [IP2+2] adc dh, byte [IP2+2]
; size ; size
adc dl, cl adc dl, cl
adc dh, ch adc dh, ch
;--------------------- ;---------------------
; Real header and data ; Real header and data
push esi push esi
call checksum_1 call checksum_1
call checksum_2 call checksum_2
pop esi pop esi
} ; returns in dx only } ; returns in dx only
macro TCP_sendseqinit ptr { macro TCP_sendseqinit ptr {
push edi ;;;; i dont like this static use of edi push edi ;;;; i dont like this static use of edi
mov edi, [ptr + TCP_SOCKET.ISS] mov edi, [ptr + TCP_SOCKET.ISS]
mov [ptr + TCP_SOCKET.SND_UP], edi mov [ptr + TCP_SOCKET.SND_UP], edi
mov [ptr + TCP_SOCKET.SND_MAX], edi mov [ptr + TCP_SOCKET.SND_MAX], edi
mov [ptr + TCP_SOCKET.SND_NXT], edi mov [ptr + TCP_SOCKET.SND_NXT], edi
mov [ptr + TCP_SOCKET.SND_UNA], edi mov [ptr + TCP_SOCKET.SND_UNA], edi
pop edi pop edi
} }
macro TCP_rcvseqinit ptr { macro TCP_rcvseqinit ptr {
push edi push edi
mov edi, [ptr + TCP_SOCKET.IRS] mov edi, [ptr + TCP_SOCKET.IRS]
inc edi inc edi
mov [ptr + TCP_SOCKET.RCV_NXT], edi mov [ptr + TCP_SOCKET.RCV_NXT], edi
mov [ptr + TCP_SOCKET.RCV_ADV], edi mov [ptr + TCP_SOCKET.RCV_ADV], edi
pop edi pop edi
} }
@ -102,11 +102,11 @@ macro TCP_rcvseqinit ptr {
align 4 align 4
TCP_pull_out_of_band: TCP_pull_out_of_band:
DEBUGF 1,"TCP_pull_out_of_band\n" DEBUGF 1,"TCP_pull_out_of_band\n"
;;;; 1282-1305 ;;;; 1282-1305
ret ret
@ -128,18 +128,18 @@ TCP_pull_out_of_band:
align 4 align 4
TCP_drop: TCP_drop:
DEBUGF 1,"TCP_drop\n" DEBUGF 1,"TCP_drop\n"
cmp [eax + TCP_SOCKET.t_state], TCPS_SYN_RECEIVED cmp [eax + TCP_SOCKET.t_state], TCPS_SYN_RECEIVED
jb .no_syn_received jb .no_syn_received
mov [eax + TCP_SOCKET.t_state], TCPS_CLOSED mov [eax + TCP_SOCKET.t_state], TCPS_CLOSED
call TCP_output call TCP_output
;;; TODO: update stats ;;; TODO: update stats
jmp TCP_close jmp TCP_close
.no_syn_received: .no_syn_received:
@ -147,7 +147,7 @@ TCP_drop:
;;; TODO: check if error code is "Connection timed out' and handle accordingly ;;; TODO: check if error code is "Connection timed out' and handle accordingly
mov [eax + SOCKET.errorcode], ebx mov [eax + SOCKET.errorcode], ebx
@ -167,15 +167,15 @@ TCP_drop:
align 4 align 4
TCP_close: TCP_close:
DEBUGF 1,"TCP_close\n" DEBUGF 1,"TCP_close\n"
;;; TODO: update RTT and mean deviation ;;; TODO: update RTT and mean deviation
;;; TODO: update slow start threshold ;;; TODO: update slow start threshold
;;; TODO: release connection resources ;;; TODO: release connection resources
call SOCKET_is_disconnected call SOCKET_is_disconnected
ret ret
@ -198,26 +198,26 @@ TCP_close:
align 4 align 4
TCP_outflags: TCP_outflags:
mov edx, [eax + TCP_SOCKET.t_state] mov edx, [eax + TCP_SOCKET.t_state]
movzx edx, byte [edx + .flaglist] movzx edx, byte [edx + .flaglist]
DEBUGF 1,"TCP_outflags, socket: %x, flags: %x\n", eax, dl DEBUGF 1,"TCP_outflags, socket: %x, flags: %x\n", eax, dl
ret ret
.flaglist: .flaglist:
db TH_RST + TH_ACK ; TCPS_CLOSED db TH_RST + TH_ACK ; TCPS_CLOSED
db 0 ; TCPS_LISTEN db 0 ; TCPS_LISTEN
db TH_SYN ; TCPS_SYN_SENT db TH_SYN ; TCPS_SYN_SENT
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_SYN + TH_ACK ; TCPS_FIN_WAIT_1
db TH_SYN + TH_ACK ; TCPS_CLOSING db TH_SYN + TH_ACK ; TCPS_CLOSING
db TH_SYN + TH_ACK ; TCPS_LAST_ACK db TH_SYN + 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
@ -237,69 +237,69 @@ TCP_outflags:
align 4 align 4
TCP_respond_socket: TCP_respond_socket:
DEBUGF 1,"TCP_respond_socket\n" DEBUGF 1,"TCP_respond_socket\n"
;--------------------- ;---------------------
; Create the IP packet ; Create the IP packet
push cx ebx push cx ebx
mov eax, [ebx + IP_SOCKET.RemoteIP] mov eax, [ebx + IP_SOCKET.RemoteIP]
mov ebx, [ebx + IP_SOCKET.LocalIP] mov ebx, [ebx + IP_SOCKET.LocalIP]
mov ecx, sizeof.TCP_header mov ecx, sizeof.TCP_header
mov di , IP_PROTO_TCP shl 8 + 128 mov di , IP_PROTO_TCP shl 8 + 128
call IPv4_output call IPv4_output
test edi, edi test edi, edi
jz .error jz .error
pop esi cx pop esi cx
push edx eax push edx eax
;----------------------------------------------- ;-----------------------------------------------
; Fill in the TCP header by using the socket ptr ; Fill in the TCP header by using the socket ptr
mov ax, [esi + TCP_SOCKET.LocalPort] mov ax, [esi + TCP_SOCKET.LocalPort]
rol ax, 8 rol ax, 8
stosw stosw
mov ax, [esi + TCP_SOCKET.RemotePort] mov ax, [esi + TCP_SOCKET.RemotePort]
rol ax, 8 rol ax, 8
stosw stosw
mov eax, [esi + TCP_SOCKET.SND_NXT] mov eax, [esi + TCP_SOCKET.SND_NXT]
bswap eax bswap eax
stosd stosd
mov eax, [esi + TCP_SOCKET.RCV_NXT] mov eax, [esi + TCP_SOCKET.RCV_NXT]
bswap eax bswap eax
stosd stosd
mov al, 0x50 ; Dataoffset: 20 bytes (TCP_header.DataOffset) mov al, 0x50 ; Dataoffset: 20 bytes (TCP_header.DataOffset)
stosb stosb
mov al, cl mov al, cl
stosb stosb
; mov ax, [esi + TCP_SOCKET.RCV_WND] ; mov ax, [esi + TCP_SOCKET.RCV_WND]
; rol ax, 8 ; rol ax, 8
mov ax, 0x00a0 ;;;;;;; FIXME mov ax, 0x00a0 ;;;;;;; FIXME
stosw ; window stosw ; window
xor eax, eax xor eax, eax
stosd ; checksum + urgentpointer stosd ; checksum + urgentpointer
;--------------------- ;---------------------
; Fill in the checksum ; Fill in the checksum
.checksum: .checksum:
sub edi, sizeof.TCP_header sub edi, sizeof.TCP_header
mov ecx, sizeof.TCP_header mov ecx, sizeof.TCP_header
xchg esi, edi xchg esi, edi
TCP_checksum (edi + IP_SOCKET.LocalIP), (edi + IP_SOCKET.RemoteIP) TCP_checksum (edi + IP_SOCKET.LocalIP), (edi + IP_SOCKET.RemoteIP)
mov [esi+TCP_header.Checksum], dx mov [esi+TCP_header.Checksum], dx
;-------------------- ;--------------------
; And send the segment ; And send the segment
call [ebx + NET_DEVICE.transmit] call [ebx + NET_DEVICE.transmit]
ret ret
.error: .error:
DEBUGF 1,"TCP_respond failed\n" DEBUGF 1,"TCP_respond failed\n"
add esp, 2+4 add esp, 2+4
ret ret
@ -319,64 +319,86 @@ TCP_respond_socket:
align 4 align 4
TCP_respond_segment: TCP_respond_segment:
DEBUGF 1,"TCP_respond_segment\n" DEBUGF 1,"TCP_respond_segment\n"
;--------------------- ;---------------------
; Create the IP packet ; Create the IP packet
push cx edx ebx push cx edx ebx
mov ebx, [edi + 4] mov ebx, [edi + 4]
mov eax, [edi] mov eax, [edi]
mov ecx, sizeof.TCP_header mov ecx, sizeof.TCP_header
mov di , IP_PROTO_TCP shl 8 + 128 mov di , IP_PROTO_TCP shl 8 + 128
call IPv4_output call IPv4_output
jz .error jz .error
pop ebx esi cx pop ebx esi cx
push edx eax push edx eax
;--------------------------------------------------- ;---------------------------------------------------
; Fill in the TCP header by using a received segment ; Fill in the TCP header by using a received segment
mov ax, [esi + TCP_header.DestinationPort] mov ax, [esi + TCP_header.DestinationPort]
rol ax, 8 rol ax, 8
stosw stosw
mov ax, [esi + TCP_header.SourcePort] mov ax, [esi + TCP_header.SourcePort]
rol ax, 8 rol ax, 8
stosw stosw
mov eax, [esi + TCP_header.AckNumber] mov eax, [esi + TCP_header.AckNumber]
bswap eax bswap eax
stosd stosd
xor eax, eax xor eax, eax
stosd stosd
mov al, 0x50 ; Dataoffset: 20 bytes (sizeof.TCP_header) mov al, 0x50 ; Dataoffset: 20 bytes (sizeof.TCP_header)
stosb stosb
mov al, cl mov al, cl
stosb stosb
mov ax, 1280 mov ax, 1280
rol ax, 8 rol ax, 8
stosw ; window stosw ; window
xor eax, eax xor eax, eax
stosd ; checksum + urgentpointer stosd ; checksum + urgentpointer
;--------------------- ;---------------------
; Fill in the checksum ; Fill in the checksum
.checksum: .checksum:
lea esi, [edi - sizeof.TCP_header] lea esi, [edi - sizeof.TCP_header]
mov ecx, sizeof.TCP_header mov ecx, sizeof.TCP_header
TCP_checksum (esi - sizeof.IPv4_header + IPv4_header.DestinationAddress),\ ; FIXME TCP_checksum (esi - sizeof.IPv4_header + IPv4_header.DestinationAddress),\ ; FIXME
(esi - sizeof.IPv4_header + IPv4_header.SourceAddress) (esi - sizeof.IPv4_header + IPv4_header.SourceAddress)
mov [esi+TCP_header.Checksum], dx mov [esi+TCP_header.Checksum], dx
;-------------------- ;--------------------
; And send the segment ; And send the segment
call [ebx + NET_DEVICE.transmit] call [ebx + NET_DEVICE.transmit]
ret ret
.error: .error:
DEBUGF 1,"TCP_respond failed\n" DEBUGF 1,"TCP_respond failed\n"
add esp, 2+4 add esp, 2+4
ret ret
macro TCP_set_persist socket {
;int t = ((tp->t_srtt >> 2) + tp->t_rttvar) >> 1;
;int tt;
;
;tp->t_flags &= ~TF_PREVVALID;
;
;if (tcp_timer_active(tp, TT_REXMT))
; panic("tcp_setpersist: retransmit pending");
;
;; Start/restart persistance timer.
;
;TCPT_RANGESET(tt, t * tcp_backoff[tp->t_rxtshift], TCPTV_PERSMIN, TCPTV_PERSMAX);
;tcp_timer_activate(tp, TT_PERSIST, tt);
;
;if (tp->t_rxtshift < TCP_MAXRXTSHIFT)
; tp->t_rxtshift++;
}