forked from KolibriOS/kolibrios
network code cleanup, implemented TCP_sendalot
git-svn-id: svn://kolibrios.org@2888 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
c95986da86
commit
e19d06cb9f
@ -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 ;;
|
;; Distributed under terms of the GNU General Public License ;;
|
||||||
;; ;;
|
;; ;;
|
||||||
;; ARP.INC ;;
|
;; ARP.INC ;;
|
||||||
@ -349,7 +349,7 @@ ARP_output_request:
|
|||||||
align 4
|
align 4
|
||||||
ARP_add_entry:
|
ARP_add_entry:
|
||||||
|
|
||||||
DEBUGF 1,"ARP add entry: "
|
DEBUGF 1,"ARP_add_entry: "
|
||||||
|
|
||||||
mov ecx, [NumARP]
|
mov ecx, [NumARP]
|
||||||
test ecx, ecx ; first entry?
|
test ecx, ecx ; first entry?
|
||||||
@ -392,14 +392,14 @@ ARP_add_entry:
|
|||||||
lea esi, [edi - sizeof.ARP_entry]
|
lea esi, [edi - sizeof.ARP_entry]
|
||||||
inc [NumARP]
|
inc [NumARP]
|
||||||
pop eax
|
pop eax
|
||||||
DEBUGF 1,"New entry created: %u\n", eax
|
DEBUGF 1,"entry %u created\n", eax
|
||||||
|
|
||||||
.exit:
|
.exit:
|
||||||
DEBUGF 1,"Exiting\n"
|
DEBUGF 1,"exiting\n"
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.error:
|
.error:
|
||||||
DEBUGF 1,"error! \n"
|
DEBUGF 1,"error!\n"
|
||||||
mov eax, -1
|
mov eax, -1
|
||||||
ret
|
ret
|
||||||
|
|
||||||
@ -415,7 +415,7 @@ ARP_add_entry:
|
|||||||
align 4
|
align 4
|
||||||
ARP_del_entry:
|
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
|
mov ecx, ARP_table + (ARP_TABLE_SIZE - 1) * sizeof.ARP_entry
|
||||||
sub ecx, esi
|
sub ecx, esi
|
||||||
@ -426,7 +426,7 @@ ARP_del_entry:
|
|||||||
rep movsw
|
rep movsw
|
||||||
|
|
||||||
dec [NumARP]
|
dec [NumARP]
|
||||||
DEBUGF 1,"ARP entry deleted\n"
|
DEBUGF 1,"ARP_del_entry: done!\n"
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
@ -473,7 +473,7 @@ ARP_IP_to_MAC:
|
|||||||
loop .scan_loop
|
loop .scan_loop
|
||||||
|
|
||||||
.not_in_list:
|
.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
|
; Send an ARP request
|
||||||
@ -502,7 +502,7 @@ ARP_IP_to_MAC:
|
|||||||
ret
|
ret
|
||||||
|
|
||||||
.found_it:
|
.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
|
cmp [esi + ARP_entry.Status], ARP_VALID_MAPPING
|
||||||
jne .invalid
|
jne .invalid
|
||||||
|
|
||||||
@ -511,12 +511,12 @@ ARP_IP_to_MAC:
|
|||||||
ret
|
ret
|
||||||
|
|
||||||
.invalid:
|
.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
|
mov eax, -1
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.full:
|
.full:
|
||||||
DEBUGF 1,"ARP table is full!\n"
|
DEBUGF 1,"ARP_IP_to_MAC: table is full!\n"
|
||||||
add esp, 8
|
add esp, 8
|
||||||
mov eax, -1
|
mov eax, -1
|
||||||
ret
|
ret
|
||||||
|
@ -3,7 +3,9 @@
|
|||||||
;; Copyright (C) KolibriOS team 2004-2012. 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 ;;
|
||||||
;; ;;
|
;; ;;
|
||||||
;; Written by hidnplayr@kolibrios.org, ;;
|
;; Part of the tcp/ip network stack for KolibriOS ;;
|
||||||
|
;; ;;
|
||||||
|
;; Written by hidnplayr@kolibrios.org, ;;
|
||||||
;; and Clevermouse. ;;
|
;; and Clevermouse. ;;
|
||||||
;; ;;
|
;; ;;
|
||||||
;; Based on code by mike.dld ;;
|
;; Based on code by mike.dld ;;
|
||||||
@ -1181,7 +1183,7 @@ SOCKET_ring_create:
|
|||||||
mov [esi + RING_BUFFER.write_ptr], eax
|
mov [esi + RING_BUFFER.write_ptr], eax
|
||||||
mov [esi + RING_BUFFER.read_ptr], eax
|
mov [esi + RING_BUFFER.read_ptr], eax
|
||||||
mov [esi + RING_BUFFER.size], 0
|
mov [esi + RING_BUFFER.size], 0
|
||||||
add eax, SOCKET_MAXDATA
|
add eax, SOCKET_MAXDATA
|
||||||
mov [esi + RING_BUFFER.end_ptr], eax
|
mov [esi + RING_BUFFER.end_ptr], eax
|
||||||
mov eax, esi
|
mov eax, esi
|
||||||
pop esi
|
pop esi
|
||||||
@ -1307,10 +1309,14 @@ SOCKET_ring_read:
|
|||||||
|
|
||||||
.less_data:
|
.less_data:
|
||||||
mov ecx, [eax + RING_BUFFER.size]
|
mov ecx, [eax + RING_BUFFER.size]
|
||||||
; test ecx, ecx
|
cmp ecx, 0
|
||||||
; jz .no_data_at_all
|
jb .error
|
||||||
jmp .copy
|
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
|
DEBUGF 1,"SOCKET_ring_free: %u bytes from ring %x\n", ecx, eax
|
||||||
|
|
||||||
sub [eax + RING_BUFFER.size], ecx
|
sub [eax + RING_BUFFER.size], ecx
|
||||||
jb .sumthinwong
|
jb .error
|
||||||
add [eax + RING_BUFFER.read_ptr], ecx
|
add [eax + RING_BUFFER.read_ptr], ecx
|
||||||
|
|
||||||
mov edx, [eax + RING_BUFFER.end_ptr]
|
mov edx, [eax + RING_BUFFER.end_ptr]
|
||||||
@ -1340,7 +1346,8 @@ SOCKET_ring_free:
|
|||||||
@@:
|
@@:
|
||||||
ret
|
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
|
add [eax + RING_BUFFER.size], ecx
|
||||||
xor ecx, ecx
|
xor ecx, ecx
|
||||||
ret
|
ret
|
||||||
|
@ -1055,7 +1055,7 @@ align 4
|
|||||||
;;; TODO: update stats
|
;;; 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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,6 +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
|
||||||
@ -122,7 +126,6 @@ TCP_output:
|
|||||||
; 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]
|
||||||
|
|
||||||
@@:
|
@@:
|
||||||
|
|
||||||
; If window didn't close completely, just wait for an ACK
|
; If window didn't close completely, just wait for an ACK
|
||||||
@ -136,9 +139,8 @@ TCP_output:
|
|||||||
jbe @f
|
jbe @f
|
||||||
|
|
||||||
mov esi, [eax + TCP_SOCKET.t_maxseg]
|
mov esi, [eax + TCP_SOCKET.t_maxseg]
|
||||||
|
push eax
|
||||||
;;; sendalot = 1
|
push dword TCP_sendalot
|
||||||
|
|
||||||
@@:
|
@@:
|
||||||
|
|
||||||
;--------------------------------------------
|
;--------------------------------------------
|
||||||
@ -167,7 +169,7 @@ TCP_output:
|
|||||||
jz .len_zero
|
jz .len_zero
|
||||||
|
|
||||||
cmp esi, [eax + TCP_SOCKET.t_maxseg]
|
cmp esi, [eax + TCP_SOCKET.t_maxseg]
|
||||||
je .send
|
je TCP_send
|
||||||
|
|
||||||
test [eax + TCP_SOCKET.t_flags], TF_NODELAY
|
test [eax + TCP_SOCKET.t_flags], TF_NODELAY
|
||||||
jnz @f
|
jnz @f
|
||||||
@ -175,19 +177,19 @@ TCP_output:
|
|||||||
@@:
|
@@:
|
||||||
add ebx, esi
|
add ebx, esi
|
||||||
cmp ebx, [eax + STREAM_SOCKET.snd.size]
|
cmp ebx, [eax + STREAM_SOCKET.snd.size]
|
||||||
jae .send
|
jae TCP_send
|
||||||
|
|
||||||
test [eax + TCP_SOCKET.t_force], -1 ;;;
|
test [eax + TCP_SOCKET.t_force], -1 ;;;
|
||||||
jnz .send
|
jnz TCP_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 TCP_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 TCP_send
|
||||||
|
|
||||||
.len_zero:
|
.len_zero:
|
||||||
|
|
||||||
@ -210,10 +212,10 @@ TCP_output:
|
|||||||
; (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 TCP_send
|
||||||
|
|
||||||
;;; cmp ebx, [eax + ] ;;; TODO: check receive buffer high water mark
|
cmp ebx, 8192 ;[eax + TCP_SOCKET.] ;;; FIXME: check with receive buffer high water mark
|
||||||
;;; jae .send
|
jae TCP_send
|
||||||
|
|
||||||
.no_window:
|
.no_window:
|
||||||
|
|
||||||
@ -221,14 +223,14 @@ 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 TCP_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 TCP_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 TCP_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
|
||||||
@ -236,11 +238,11 @@ 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 .send
|
jnz 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]
|
||||||
je .send
|
je TCP_send
|
||||||
|
|
||||||
;--------------------
|
;--------------------
|
||||||
; Enter persist state (191)
|
; Enter persist state (191)
|
||||||
@ -289,10 +291,10 @@ TCP_output:
|
|||||||
; dl = flags
|
; dl = flags
|
||||||
;
|
;
|
||||||
;-----------------------------------------------
|
;-----------------------------------------------
|
||||||
|
align 4
|
||||||
|
TCP_send:
|
||||||
|
|
||||||
.send:
|
DEBUGF 1,"TCP_send socket=%x length=%u flags=%x\n", eax, esi, dl
|
||||||
|
|
||||||
DEBUGF 1,"Preparing to send a segment socket: %x length: %u flags: %x\n", eax, esi, dl
|
|
||||||
|
|
||||||
mov edi, sizeof.TCP_header ; edi will contain headersize
|
mov edi, sizeof.TCP_header ; edi will contain headersize
|
||||||
|
|
||||||
@ -362,13 +364,6 @@ TCP_output:
|
|||||||
|
|
||||||
; <Add additional options here>
|
; <Add additional options here>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
.options_done:
|
.options_done:
|
||||||
|
|
||||||
; eax = socket ptr
|
; eax = socket ptr
|
||||||
@ -384,8 +379,8 @@ TCP_output:
|
|||||||
jbe .no_overflow
|
jbe .no_overflow
|
||||||
|
|
||||||
mov esi, [eax + TCP_SOCKET.t_maxseg]
|
mov esi, [eax + TCP_SOCKET.t_maxseg]
|
||||||
|
;; push eax
|
||||||
;;; sendalot = 1
|
;; push dword TCP_sendalot
|
||||||
|
|
||||||
.no_overflow:
|
.no_overflow:
|
||||||
|
|
||||||
@ -395,12 +390,12 @@ TCP_output:
|
|||||||
|
|
||||||
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 (370)
|
||||||
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]
|
||||||
@ -456,13 +451,15 @@ 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
|
|
||||||
push edx
|
push edx
|
||||||
|
test ecx, ecx
|
||||||
|
jz .nodata
|
||||||
|
add eax, STREAM_SOCKET.snd
|
||||||
call SOCKET_ring_read
|
call SOCKET_ring_read
|
||||||
|
.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
|
pop eax ; socket ptr
|
||||||
@ -546,3 +543,6 @@ TCP_output:
|
|||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user