network code cleanup, implemented TCP_sendalot

git-svn-id: svn://kolibrios.org@2888 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2012-07-24 20:29:46 +00:00
parent c95986da86
commit e19d06cb9f
4 changed files with 59 additions and 52 deletions

View File

@ -1,6 +1,6 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2004-2010. All rights reserved. ;;
;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; ;;
;; ARP.INC ;;
@ -349,7 +349,7 @@ ARP_output_request:
align 4
ARP_add_entry:
DEBUGF 1,"ARP add entry: "
DEBUGF 1,"ARP_add_entry: "
mov ecx, [NumARP]
test ecx, ecx ; first entry?
@ -392,10 +392,10 @@ ARP_add_entry:
lea esi, [edi - sizeof.ARP_entry]
inc [NumARP]
pop eax
DEBUGF 1,"New entry created: %u\n", eax
DEBUGF 1,"entry %u created\n", eax
.exit:
DEBUGF 1,"Exiting\n"
DEBUGF 1,"exiting\n"
ret
.error:
@ -415,7 +415,7 @@ ARP_add_entry:
align 4
ARP_del_entry:
DEBUGF 1,"ARP del entry %x, total entrys: %u\n", esi, [NumARP]
DEBUGF 1,"ARP_del_entry %x, total entrys: %u\n", esi, [NumARP]
mov ecx, ARP_table + (ARP_TABLE_SIZE - 1) * sizeof.ARP_entry
sub ecx, esi
@ -426,7 +426,7 @@ ARP_del_entry:
rep movsw
dec [NumARP]
DEBUGF 1,"ARP entry deleted\n"
DEBUGF 1,"ARP_del_entry: done!\n"
ret
@ -473,7 +473,7 @@ ARP_IP_to_MAC:
loop .scan_loop
.not_in_list:
DEBUGF 1,"IP not found on list, preparing for ARP request\n"
DEBUGF 1,"ARP_IP_to_MAC: preparing for ARP request\n"
;--------------------
; Send an ARP request
@ -502,7 +502,7 @@ ARP_IP_to_MAC:
ret
.found_it:
DEBUGF 1,"found IP in ARPTable\n"
DEBUGF 1,"ARP_IP_to_MAC: found IP\n"
cmp [esi + ARP_entry.Status], ARP_VALID_MAPPING
jne .invalid
@ -511,12 +511,12 @@ ARP_IP_to_MAC:
ret
.invalid:
DEBUGF 1,"ARP entry has no valid mapping!\n"
DEBUGF 1,"ARP_IP_to_MAC: entry has no valid mapping!\n"
mov eax, -1
ret
.full:
DEBUGF 1,"ARP table is full!\n"
DEBUGF 1,"ARP_IP_to_MAC: table is full!\n"
add esp, 8
mov eax, -1
ret

View File

@ -3,6 +3,8 @@
;; Copyright (C) KolibriOS team 2004-2012. 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, ;;
;; and Clevermouse. ;;
;; ;;
@ -1307,10 +1309,14 @@ SOCKET_ring_read:
.less_data:
mov ecx, [eax + RING_BUFFER.size]
; test ecx, ecx
; jz .no_data_at_all
cmp ecx, 0
jb .error
jmp .copy
.error:
DEBUGF 1,"SOCKET_ring_read: ringbuff=%x error!", eax
xor ecx, ecx
ret
;-----------------------------------------------------------------
;
@ -1330,7 +1336,7 @@ SOCKET_ring_free:
DEBUGF 1,"SOCKET_ring_free: %u bytes from ring %x\n", ecx, eax
sub [eax + RING_BUFFER.size], ecx
jb .sumthinwong
jb .error
add [eax + RING_BUFFER.read_ptr], ecx
mov edx, [eax + RING_BUFFER.end_ptr]
@ -1340,7 +1346,8 @@ SOCKET_ring_free:
@@:
ret
.sumthinwong: ; we could free all available bytes, but that would be stupid, i guess..
.error: ; we could free all available bytes, but that would be stupid, i guess..
DEBUGF 1,"SOCKET_ring_free: buffer=%x error!\n", eax
add [eax + RING_BUFFER.size], ecx
xor ecx, ecx
ret

View File

@ -1055,7 +1055,7 @@ align 4
;;; TODO: update stats
DEBUGF 1,"We have an acceptable ACK of %x bytes\n", esi
DEBUGF 1,"We have an acceptable ACK of %x bytes\n", edi

View File

@ -26,6 +26,10 @@ $Revision$
;
;-----------------------------------------------------------------
align 4
TCP_sendalot:
DEBUGF 1,"TCP_sendalot\n"
pop eax
;align 4
TCP_output:
DEBUGF 1,"TCP_output, socket: %x\n", eax
@ -122,7 +126,6 @@ TCP_output:
; pull SND_NXT back to (closed) window, We will enter persist state below.
push [eax + TCP_SOCKET.SND_UNA]
pop [eax + TCP_SOCKET.SND_NXT]
@@:
; If window didn't close completely, just wait for an ACK
@ -136,9 +139,8 @@ TCP_output:
jbe @f
mov esi, [eax + TCP_SOCKET.t_maxseg]
;;; sendalot = 1
push eax
push dword TCP_sendalot
@@:
;--------------------------------------------
@ -167,7 +169,7 @@ TCP_output:
jz .len_zero
cmp esi, [eax + TCP_SOCKET.t_maxseg]
je .send
je TCP_send
test [eax + TCP_SOCKET.t_flags], TF_NODELAY
jnz @f
@ -175,19 +177,19 @@ TCP_output:
@@:
add ebx, esi
cmp ebx, [eax + STREAM_SOCKET.snd.size]
jae .send
jae TCP_send
test [eax + TCP_SOCKET.t_force], -1 ;;;
jnz .send
jnz TCP_send
mov ebx, [eax + TCP_SOCKET.max_sndwnd]
shr ebx, 1
cmp esi, ebx
jae .send
jae TCP_send
mov ebx, [eax + TCP_SOCKET.SND_NXT]
cmp ebx, [eax + TCP_SOCKET.SND_MAX]
jb .send
jb TCP_send
.len_zero:
@ -210,10 +212,10 @@ TCP_output:
; (with TCP_max_win shl rcv_scale as the maximum)
cmp ebx, [eax + TCP_SOCKET.t_maxseg]
jae .send
jae TCP_send
;;; cmp ebx, [eax + ] ;;; TODO: check receive buffer high water mark
;;; jae .send
cmp ebx, 8192 ;[eax + TCP_SOCKET.] ;;; FIXME: check with receive buffer high water mark
jae TCP_send
.no_window:
@ -221,14 +223,14 @@ TCP_output:
; Should a segment be sent? (174)
test [eax + TCP_SOCKET.t_flags], TF_ACKNOW ; we need to ACK
jnz .send
jnz TCP_send
test dl, TH_SYN + TH_RST ; we need to send a SYN or RST
jnz .send
jnz TCP_send
mov ebx, [eax + TCP_SOCKET.SND_UP] ; when urgent pointer is beyond start of send bufer
cmp ebx, [eax + TCP_SOCKET.SND_UNA]
ja .send
ja TCP_send
test dl, TH_FIN
jz .enter_persist ; no reason to send, enter persist state
@ -236,11 +238,11 @@ TCP_output:
; FIN was set, only send if not already sent, or on retransmit
test [eax + TCP_SOCKET.t_flags], TF_SENTFIN
jnz .send
jnz TCP_send
mov ebx, [eax + TCP_SOCKET.SND_NXT]
cmp ebx, [eax + TCP_SOCKET.SND_UNA]
je .send
je TCP_send
;--------------------
; Enter persist state (191)
@ -289,10 +291,10 @@ TCP_output:
; dl = flags
;
;-----------------------------------------------
align 4
TCP_send:
.send:
DEBUGF 1,"Preparing to send a segment socket: %x length: %u flags: %x\n", eax, esi, dl
DEBUGF 1,"TCP_send socket=%x length=%u flags=%x\n", eax, esi, dl
mov edi, sizeof.TCP_header ; edi will contain headersize
@ -362,13 +364,6 @@ TCP_output:
; <Add additional options here>
.options_done:
; eax = socket ptr
@ -384,8 +379,8 @@ TCP_output:
jbe .no_overflow
mov esi, [eax + TCP_SOCKET.t_maxseg]
;;; sendalot = 1
;; push eax
;; push dword TCP_sendalot
.no_overflow:
@ -395,12 +390,12 @@ TCP_output:
pushw 0 ; .UrgentPointer dw ?
pushw 0 ; .Checksum dw ?
pushw 0x00a0 ; .Window dw ? ;;;;;;; FIXME
pushw 0x00a0 ; .Window dw ? ;;;;;;; FIXME (370)
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 ? ;;;;
shr edi, 2 ; .DataOffset db ?
push [eax + TCP_SOCKET.RCV_NXT] ; .AckNumber dd ?
ntohd [esp]
@ -457,12 +452,14 @@ TCP_output:
; edi = ptr to buffer
mov eax, [esp + 4] ; get socket ptr
add [eax + TCP_SOCKET.SND_NXT], ecx ; update sequence number
add eax, STREAM_SOCKET.snd
push edx
test ecx, ecx
jz .nodata
add eax, STREAM_SOCKET.snd
call SOCKET_ring_read
.nodata:
pop esi ; begin of data
pop ecx ; full packet size
pop eax ; socket ptr
@ -546,3 +543,6 @@ TCP_output:
ret