Better debug info for network, lots of improvements in TCP code

git-svn-id: svn://kolibrios.org@2891 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2012-07-26 23:21:35 +00:00
parent 0287f5c75b
commit 83c26b2500
10 changed files with 303 additions and 336 deletions

View File

@ -163,7 +163,6 @@ local .exit
align 4 align 4
ARP_input: ARP_input:
DEBUGF 1,"ARP_input - start\n"
cmp ecx, sizeof.ARP_header cmp ecx, sizeof.ARP_header
jb .exit jb .exit
@ -173,9 +172,9 @@ ARP_input:
cmp [edx + ARP_header.Opcode], ARP_REP_OPCODE cmp [edx + ARP_header.Opcode], ARP_REP_OPCODE
jne .maybe_request jne .maybe_request
DEBUGF 1,"ARP_input - it's a reply packet from %u.%u.%u.%u\n",\ DEBUGF 1,"ARP_input: got reply packet from %u.%u.%u.%u\n",\
[edx + ARP_header.SenderIP]:1, [edx + ARP_header.SenderIP+1]:1,\ [edx + ARP_header.SenderIP]:1, [edx + ARP_header.SenderIP + 1]:1,\
[edx + ARP_header.SenderIP+2]:1, [edx + ARP_header.SenderIP+3]:1 [edx + ARP_header.SenderIP + 2]:1, [edx + ARP_header.SenderIP + 3]:1
mov ecx, [NumARP] mov ecx, [NumARP]
test ecx, ecx test ecx, ecx
@ -194,20 +193,20 @@ ARP_input:
jmp .exit jmp .exit
.gotit: .gotit:
DEBUGF 1,"ARP_input - found matching entry\n" DEBUGF 1,"ARP_input: found matching entry\n"
cmp [esi + ARP_entry.TTL], ARP_STATIC_ENTRY ; if it is a static entry, dont touch it cmp [esi + ARP_entry.TTL], ARP_STATIC_ENTRY ; if it is a static entry, dont touch it
je .exit je .exit
DEBUGF 1,"ARP_input - updating entry\n" DEBUGF 1,"ARP_input: updating entry\n"
mov [esi + ARP_entry.Status], ARP_VALID_MAPPING mov [esi + ARP_entry.Status], ARP_VALID_MAPPING
mov [esi + ARP_entry.TTL], ARP_ENTRY_TTL mov [esi + ARP_entry.TTL], ARP_ENTRY_TTL
mov eax, dword [edx + ARP_header.SenderMAC] mov eax, dword [edx + ARP_header.SenderMAC]
mov dword [esi+ARP_entry.MAC], eax mov dword [esi + ARP_entry.MAC], eax
mov cx, word [edx + ARP_header.SenderMAC + 4] mov cx, word [edx + ARP_header.SenderMAC + 4]
mov word [esi+ARP_entry.MAC+4], cx mov word [esi + ARP_entry.MAC + 4], cx
jmp .exit jmp .exit
@ -222,10 +221,10 @@ ARP_input:
call NET_ptr_to_num call NET_ptr_to_num
cmp edi, -1 cmp edi, -1
jz .exit jz .exit
DEBUGF 1,"ARP Request packet through device: %u\n", edi DEBUGF 1,"ARP_input: got request packet through device: %u\n", edi
inc [ARP_PACKETS_RX+4*edi] inc [ARP_PACKETS_RX + 4*edi]
mov eax, [IP_LIST+4*edi] mov eax, [IP_LIST + 4*edi]
cmp eax, [edx + ARP_header.TargetIP] ; Is it looking for my IP address? cmp eax, [edx + ARP_header.TargetIP] ; Is it looking for my IP address?
jne .exit jne .exit
@ -264,7 +263,7 @@ ARP_input:
; mov ax , ETHER_ARP ; It's already there, I'm sure of it! ; mov ax , ETHER_ARP ; It's already there, I'm sure of it!
; stosw ; stosw
DEBUGF 1,"ARP_input - Sending reply \n" DEBUGF 1,"ARP_input: Sending reply\n"
call [ebx + NET_DEVICE.transmit] call [ebx + NET_DEVICE.transmit]
ret ret
@ -273,7 +272,7 @@ ARP_input:
call kernel_free call kernel_free
add esp, 4 ; pop (balance stack) add esp, 4 ; pop (balance stack)
DEBUGF 1,"ARP_input - exiting\n" DEBUGF 1,"ARP_input: exiting\n"
ret ret
@ -289,12 +288,13 @@ ARP_input:
align 4 align 4
ARP_output_request: ARP_output_request:
DEBUGF 1,"Create ARP Packet\n"
push eax ; DestIP push eax ; DestIP
pushd [IP_LIST+edi] ; SenderIP pushd [IP_LIST + edi] ; SenderIP
mov ebx, [NET_DRV_LIST+edi] ; device ptr DEBUGF 1,"ARP_output_request: ip=%u.%u.%u.%u\n",\
[esp]:1, [esp + 1]:1, [esp + 2]:1, [esp + 3]:1
mov ebx, [NET_DRV_LIST + edi] ; device ptr
lea eax, [ebx + ETH_DEVICE.mac] ; local device mac lea eax, [ebx + ETH_DEVICE.mac] ; local device mac
mov edx, ETH_BROADCAST ; broadcast mac mov edx, ETH_BROADCAST ; broadcast mac
@ -325,15 +325,15 @@ ARP_output_request:
pop eax ; DestIP pop eax ; DestIP
stosd ; stosd ;
DEBUGF 1,"ARP Packet for device %x created successfully\n", ebx DEBUGF 1,"ARP_output_request: device=%x\n", ebx
push edx ecx push edx ecx
call [ebx + NET_DEVICE.transmit] call [ebx + NET_DEVICE.transmit]
ret ret
.exit: .exit:
add esp, 4+4 add esp, 4 + 4
DEBUGF 1,"Create ARP Packet - failed\n" DEBUGF 1,"ARP_output_request: failed\n"
sub eax, eax sub eax, eax
ret ret
@ -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,12 @@ 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,"entry %u created\n", eax DEBUGF 1,"entry=%u\n", eax
.exit:
DEBUGF 1,"exiting\n"
ret ret
.error: .error:
DEBUGF 1,"error!\n" DEBUGF 1,"failed\n"
mov eax, -1 mov eax, -1
ret ret
@ -415,7 +413,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: entry=%u 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 +424,7 @@ ARP_del_entry:
rep movsw rep movsw
dec [NumARP] dec [NumARP]
DEBUGF 1,"ARP_del_entry: done!\n" DEBUGF 1,"ARP_del_entry: success\n"
ret ret

View File

@ -219,7 +219,7 @@ IPv4_input: ; TODO: add IPv4
IPv4_checksum edx IPv4_checksum edx
jnz .dump ; if checksum isn't valid then dump packet jnz .dump ; if checksum isn't valid then dump packet
DEBUGF 1,"IPv4 Checksum is correct\n" DEBUGF 1,"IPv4_input: Checksum ok\n"
;----------------------------------- ;-----------------------------------
; Check if destination IP is correct ; Check if destination IP is correct
@ -257,7 +257,7 @@ IPv4_input: ; TODO: add IPv4
; or it's just not meant for us.. :( ; or it's just not meant for us.. :(
DEBUGF 2,"IPv4_input - Destination address does not match!\n" DEBUGF 2,"IPv4_input: Destination address does not match!\n"
jmp .dump jmp .dump
;------------------------ ;------------------------
@ -301,11 +301,11 @@ IPv4_input: ; TODO: add IPv4
cmp al, IP_PROTO_ICMP cmp al, IP_PROTO_ICMP
je ICMP_input je ICMP_input
DEBUGF 2,"IPv4_input - unknown protocol: %u\n", al DEBUGF 2,"IPv4_input: unknown protocol %u\n", al
.dump: .dump:
DEBUGF 2,"IPv4_input - dumping\n" DEBUGF 2,"IPv4_input: dumping\n"
; inc [dumped_rx_count] ; inc [dumped_rx_count] ;;; TODO
call kernel_free call kernel_free
add esp, 4 ; pop (balance stack) add esp, 4 ; pop (balance stack)
ret ret
@ -320,7 +320,7 @@ IPv4_input: ; TODO: add IPv4
xchg al , ah xchg al , ah
shl ax , 3 shl ax , 3
DEBUGF 1,"Fragmented packet, offset:%u, id:%x\n", ax, [edx + IPv4_header.Identification]:4 DEBUGF 1,"IPv4_input: fragmented packet offset=%u id=%x\n", ax, [edx + IPv4_header.Identification]:4
test ax , ax ; Is this the first packet of the fragment? test ax , ax ; Is this the first packet of the fragment?
jz .is_first_fragment jz .is_first_fragment
@ -329,7 +329,7 @@ IPv4_input: ; TODO: add IPv4
;------------------------------------------------------- ;-------------------------------------------------------
; We have a fragmented IP packet, but it's not the first ; We have a fragmented IP packet, but it's not the first
DEBUGF 1,"Middle fragmented packet received!\n" DEBUGF 1,"IPv4_input: Middle fragment packet received!\n"
call IPv4_find_fragment_slot call IPv4_find_fragment_slot
cmp esi, -1 cmp esi, -1
@ -362,7 +362,7 @@ IPv4_input: ; TODO: add IPv4
; We have received the first fragment ; We have received the first fragment
.is_first_fragment: .is_first_fragment:
DEBUGF 1,"First fragmented packet received!\n" DEBUGF 1,"IPv4_input: First fragment packet received!\n"
; try to locate a free slot.. ; try to locate a free slot..
mov ecx, MAX_FRAGMENTS mov ecx, MAX_FRAGMENTS
mov esi, FRAGMENT_LIST mov esi, FRAGMENT_LIST
@ -396,7 +396,7 @@ IPv4_input: ; TODO: add IPv4
; We have received the last fragment ; We have received the last fragment
.is_last_fragment: .is_last_fragment:
DEBUGF 1,"Last fragmented packet received!\n" DEBUGF 1,"IPv4_input: Last fragment packet received!\n"
call IPv4_find_fragment_slot call IPv4_find_fragment_slot
cmp esi, -1 cmp esi, -1
@ -412,12 +412,12 @@ IPv4_input: ; TODO: add IPv4
jne .destroy_slot_pop ; Damn, something screwed up, remove the whole slot (and free buffers too if possible!) jne .destroy_slot_pop ; Damn, something screwed up, remove the whole slot (and free buffers too if possible!)
mov cx, [esi + sizeof.FRAGMENT_entry + IPv4_header.TotalLength] ; Add total length mov cx, [esi + sizeof.FRAGMENT_entry + IPv4_header.TotalLength] ; Add total length
xchg cl, ch xchg cl, ch
DEBUGF 1,"Packet size: %u\n", cx DEBUGF 1,"IPv4_input: Packet size=%u\n", cx
add ax, cx add ax, cx
movzx cx, [esi + sizeof.FRAGMENT_entry + IPv4_header.VersionAndIHL] ; Sub Header length movzx cx, [esi + sizeof.FRAGMENT_entry + IPv4_header.VersionAndIHL] ; Sub Header length
and cx, 0x000F and cx, 0x000F
shl cx, 2 shl cx, 2
DEBUGF 1,"Header size: %u\n", cx DEBUGF 1,"IPv4_input: Header size=%u\n", cx
sub ax, cx sub ax, cx
mov edi, esi mov edi, esi
mov esi, [esi + FRAGMENT_entry.NextPtr] mov esi, [esi + FRAGMENT_entry.NextPtr]
@ -432,9 +432,9 @@ IPv4_input: ; TODO: add IPv4
mov cx, [edx + IPv4_header.TotalLength] ; Note: This time we dont substract Header length mov cx, [edx + IPv4_header.TotalLength] ; Note: This time we dont substract Header length
xchg cl , ch xchg cl , ch
DEBUGF 1,"Packet size: %u\n", cx DEBUGF 1,"IPv4_input: Packet size=%u\n", cx
add ax , cx add ax , cx
DEBUGF 1,"Total Received data size: %u\n", eax DEBUGF 1,"IPv4_input: Total Received data size=%u\n", eax
push eax push eax
mov ax , [edx + IPv4_header.FlagsAndFragmentOffset] mov ax , [edx + IPv4_header.FlagsAndFragmentOffset]
@ -442,7 +442,7 @@ IPv4_input: ; TODO: add IPv4
shl ax , 3 shl ax , 3
add cx , ax add cx , ax
pop eax pop eax
DEBUGF 1,"Total Fragment size: %u\n", ecx DEBUGF 1,"IPv4_input: Total Fragment size=%u\n", ecx
cmp ax, cx cmp ax, cx
jne .destroy_slot_pop jne .destroy_slot_pop
@ -458,7 +458,7 @@ IPv4_input: ; TODO: add IPv4
movzx ecx, [edx + sizeof.FRAGMENT_entry + IPv4_header.FlagsAndFragmentOffset] ; Calculate the fragment offset movzx ecx, [edx + sizeof.FRAGMENT_entry + IPv4_header.FlagsAndFragmentOffset] ; Calculate the fragment offset
xchg cl , ch ; intel byte order xchg cl , ch ; intel byte order
shl cx , 3 ; multiply by 8 and clear first 3 bits shl cx , 3 ; multiply by 8 and clear first 3 bits
DEBUGF 1,"Fragment offset: %u\n", cx DEBUGF 1,"IPv4_input: Fragment offset=%u\n", cx
lea edi, [eax + ecx] ; Notice that edi will be equal to eax for first fragment lea edi, [eax + ecx] ; Notice that edi will be equal to eax for first fragment
movzx ebx, [edx + sizeof.FRAGMENT_entry + IPv4_header.VersionAndIHL] ; Find header size (in ebx) of fragment movzx ebx, [edx + sizeof.FRAGMENT_entry + IPv4_header.VersionAndIHL] ; Find header size (in ebx) of fragment
@ -505,7 +505,7 @@ IPv4_input: ; TODO: add IPv4
.destroy_slot_pop: .destroy_slot_pop:
add esp, 4 add esp, 4
.destroy_slot: .destroy_slot:
DEBUGF 1,"Destroy fragment slot!\n" DEBUGF 1,"IPv4_input: Destroy fragment slot!\n"
; TODO! ; TODO!
jmp .dump jmp .dump
@ -613,7 +613,7 @@ IPv4_output:
IPv4_checksum edi IPv4_checksum edi
add edi, sizeof.IPv4_header add edi, sizeof.IPv4_header
DEBUGF 1,"IPv4 Packet for device %x created successfully\n", ebx DEBUGF 1,"IPv4_output: success!\n"
ret ret
.eth_error: .eth_error:
@ -623,13 +623,13 @@ IPv4_output:
ret ret
.arp_error: .arp_error:
DEBUGF 1,"IPv4_output: ARP error (0x%x)\n", eax DEBUGF 1,"IPv4_output: ARP error=%x\n", eax
add esp, 3*4+2 add esp, 3*4+2
xor edi, edi xor edi, edi
ret ret
.too_large: .too_large:
DEBUGF 1,"IPv4_output: error: Packet too large!\n" DEBUGF 1,"IPv4_output: Packet too large!\n"
xor edi, edi xor edi, edi
ret ret
@ -706,7 +706,7 @@ IPv4_output_raw:
IPv4_checksum edi ;;;; todo: checksum for IP packet with options! IPv4_checksum edi ;;;; todo: checksum for IP packet with options!
add edi, sizeof.IPv4_header add edi, sizeof.IPv4_header
DEBUGF 1,"IPv4 Packet for device %x created successfully\n", ebx DEBUGF 1,"IPv4_output_raw: device=%x\n", ebx
call [ebx + NET_DEVICE.transmit] call [ebx + NET_DEVICE.transmit]
ret ret
@ -763,7 +763,7 @@ IPv4_fragment:
push dword 0 ; offset push dword 0 ; offset
.new_fragment: .new_fragment:
DEBUGF 1,"Ipv4_fragment - new_fragmentn" DEBUGF 1,"Ipv4_fragment: new fragment"
mov eax, [esp + 3*4] mov eax, [esp + 3*4]
@ -785,7 +785,7 @@ IPv4_fragment:
add esi, [esp] ; offset add esi, [esp] ; offset
mov ecx, [esp + 1*4] mov ecx, [esp + 1*4]
DEBUGF 1,"IPv4_fragment - copying data (%u bytes)\n", ecx DEBUGF 1,"IPv4_fragment: copying %u bytes\n", ecx
rep movsb rep movsb
; now, correct header ; now, correct header
@ -822,7 +822,7 @@ IPv4_fragment:
sub ecx, [esp+2*4] ; ptr to ip header sub ecx, [esp+2*4] ; ptr to ip header
add ecx, [esp] ; offset add ecx, [esp] ; offset
DEBUGF 1,"Ipv4_fragment - bytes remaining: %u\n", ecx DEBUGF 1,"Ipv4_fragment: %u bytes remaining\n", ecx
cmp ecx, [esp+1*4] cmp ecx, [esp+1*4]
jae .new_fragment jae .new_fragment
@ -831,11 +831,11 @@ IPv4_fragment:
jmp .new_fragment jmp .new_fragment
.err: .err:
DEBUGF 1,"Ipv4_fragment - failed\n" DEBUGF 1,"Ipv4_fragment: failed\n"
.done: .done:
add esp, 12 + 4 + 6 add esp, 12 + 4 + 6
.err2: .err2:
DEBUGF 1,"Ipv4_fragment - dumping\n" DEBUGF 1,"Ipv4_fragment: dumping\n"
call kernel_free call kernel_free
add esp, 4 add esp, 4

View File

@ -63,7 +63,7 @@ ETH_input:
mov eax, [esp] mov eax, [esp]
mov ecx, [esp+4] mov ecx, [esp+4]
DEBUGF 1,"ETH_input - size: %u\n", ecx DEBUGF 1,"ETH_input: size=%u\n", ecx
cmp ecx, ETH_FRAME_MINIMUM cmp ecx, ETH_FRAME_MINIMUM
jb .dump jb .dump
sub ecx, sizeof.ETH_header sub ecx, sizeof.ETH_header
@ -86,10 +86,10 @@ ETH_input:
; cmp ax, ETHER_PPP_SESSION ; cmp ax, ETHER_PPP_SESSION
; je PPPoE_session_input ; je PPPoE_session_input
DEBUGF 2,"Unknown ethernet packet type %x\n", ax DEBUGF 2,"ETH_input: Unknown packet type=%x\n", ax
.dump: .dump:
DEBUGF 2,"ETH_input - dumping\n" DEBUGF 2,"ETH_input: dumping\n"
call kernel_free call kernel_free
add esp, 4 add esp, 4
ret ret
@ -114,7 +114,7 @@ ETH_input:
align 4 align 4
ETH_output: ETH_output:
DEBUGF 1,"ETH_output: size=%u device:%x\n", ecx, ebx DEBUGF 1,"ETH_output: size=%u device=%x\n", ecx, ebx
cmp ecx, [ebx + NET_DEVICE.mtu] cmp ecx, [ebx + NET_DEVICE.mtu]
ja .exit ja .exit
@ -144,7 +144,7 @@ ETH_output:
cmp edx, ETH_FRAME_MINIMUM cmp edx, ETH_FRAME_MINIMUM
jbe .adjust_size jbe .adjust_size
.done: .done:
DEBUGF 1,"ETH_output: done: %x total size: %u\n", eax, edx DEBUGF 1,"ETH_output: ptr=%x size=%u\n", eax, edx
ret ret
.adjust_size: .adjust_size:
@ -153,7 +153,7 @@ ETH_output:
jmp .done jmp .done
.out_of_ram: .out_of_ram:
DEBUGF 2,"ETH_output: Out of ram space!!\n" DEBUGF 2,"ETH_output: Out of ram!\n"
add esp, 4+4+2+4 add esp, 4+4+2+4
sub edi, edi sub edi, edi
ret ret
@ -203,7 +203,6 @@ ETH_api:
.number = ($ - .table) / 4 - 1 .number = ($ - .table) / 4 - 1
.error: .error:
DEBUGF 2,"Device is not ethernet type\n"
or eax, -1 or eax, -1
ret ret

View File

@ -142,7 +142,7 @@ macro ICMP_init {
align 4 align 4
ICMP_input: ICMP_input:
DEBUGF 1,"ICMP_input - start\n" DEBUGF 1,"ICMP_input:\n"
; First, check the checksum (altough some implementations ignore it) ; First, check the checksum (altough some implementations ignore it)
@ -163,15 +163,15 @@ ICMP_input:
; We well re-use the packet so we can create the response as fast as possible ; We well re-use the packet so we can create the response as fast as possible
; Notice: this only works on pure ethernet ; Notice: this only works on pure ethernet
DEBUGF 1,"ICMP_input - echo request\n" DEBUGF 1,"got echo request\n"
mov [edx + ICMP_header.Type], ICMP_ECHOREPLY ; Change Packet type to reply mov [edx + ICMP_header.Type], ICMP_ECHOREPLY ; Change Packet type to reply
; Update stats (and validate device ptr) ; Update stats (and validate device ptr)
call NET_ptr_to_num call NET_ptr_to_num
cmp edi,-1 cmp edi,-1
je .dump je .dump
inc [ICMP_PACKETS_RX+4*edi] inc [ICMP_PACKETS_RX + 4*edi]
inc [ICMP_PACKETS_TX+4*edi] inc [ICMP_PACKETS_TX + 4*edi]
; exchange dest and source address in IP header ; exchange dest and source address in IP header
; exchange dest and source MAC in ETH header ; exchange dest and source MAC in ETH header
@ -252,7 +252,7 @@ ICMP_input:
; je .dump ; je .dump
; inc [ICMP_PACKETS_RX+edi] ; inc [ICMP_PACKETS_RX+edi]
DEBUGF 1,"Found valid ICMP packet for socket %x\n", eax DEBUGF 1,"socket=%x\n", eax
pusha pusha
lea ecx, [eax + SOCKET.mutex] lea ecx, [eax + SOCKET.mutex]
@ -264,10 +264,10 @@ ICMP_input:
.checksum_mismatch: .checksum_mismatch:
DEBUGF 1,"ICMP_Handler - checksum mismatch\n" DEBUGF 1,"checksum mismatch\n"
.dump: .dump:
DEBUGF 1,"ICMP_Handler - dumping\n" DEBUGF 1,"ICMP_input: dumping\n"
call kernel_free call kernel_free
add esp, 4 ; pop (balance stack) add esp, 4 ; pop (balance stack)
@ -332,7 +332,7 @@ ICMP_output:
ret ret
.exit: .exit:
DEBUGF 1,"Creating ICMP Packet failed\n" DEBUGF 1,"Creating ICMP Packet failed\n"
add esp,2*4+2 add esp, 2*4 + 2
ret ret

View File

@ -132,7 +132,7 @@ struct TCP_SOCKET IP_SOCKET
; extra ; extra
sendalot db ? sendalot db ? ; also used as 'need output'
ends ends
@ -272,7 +272,7 @@ s_error:
align 4 align 4
SOCKET_open: SOCKET_open:
DEBUGF 1,"SOCKET_open: domain: %u, type: %u protocol: %x\n", ecx, edx, esi DEBUGF 1,"SOCKET_open: domain=%u type=%u protocol=%x\n", ecx, edx, esi
push ecx edx esi push ecx edx esi
call SOCKET_alloc call SOCKET_alloc
@ -361,7 +361,7 @@ align 4
align 4 align 4
SOCKET_bind: SOCKET_bind:
DEBUGF 1,"socket_bind: socknum: %u sockaddr: %x, length: %u\n", ecx, edx, esi DEBUGF 1,"SOCKET_bind: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi
call SOCKET_num_to_ptr call SOCKET_num_to_ptr
jz s_error jz s_error
@ -385,8 +385,6 @@ SOCKET_bind:
.af_inet4: .af_inet4:
DEBUGF 1,"af_inet4\n"
cmp esi, 6 cmp esi, 6
jb s_error jb s_error
@ -413,7 +411,7 @@ SOCKET_bind:
call SOCKET_check_port call SOCKET_check_port
jz s_error ; ZF is set by socket_check_port, on error jz s_error ; ZF is set by socket_check_port, on error
DEBUGF 1,"local ip: %u.%u.%u.%u\n",\ DEBUGF 1,"SOCKET_bind: local ip=%u.%u.%u.%u\n",\
[eax + IP_SOCKET.LocalIP + 0]:1,[eax + IP_SOCKET.LocalIP + 1]:1,\ [eax + IP_SOCKET.LocalIP + 0]:1,[eax + IP_SOCKET.LocalIP + 1]:1,\
[eax + IP_SOCKET.LocalIP + 2]:1,[eax + IP_SOCKET.LocalIP + 3]:1 [eax + IP_SOCKET.LocalIP + 2]:1,[eax + IP_SOCKET.LocalIP + 3]:1
@ -436,7 +434,7 @@ SOCKET_bind:
align 4 align 4
SOCKET_connect: SOCKET_connect:
DEBUGF 1,"SOCKET_connect: socknum: %u sockaddr: %x, length: %u\n", ecx, edx, esi DEBUGF 1,"SOCKET_connect: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi
call SOCKET_num_to_ptr call SOCKET_num_to_ptr
jz s_error jz s_error
@ -583,7 +581,7 @@ align 4
align 4 align 4
SOCKET_listen: SOCKET_listen:
DEBUGF 1,"SOCKET_listen: socknum: %u backlog: %u\n", ecx, edx DEBUGF 1,"SOCKET_listen: socknum=%u backlog=%u\n", ecx, edx
call SOCKET_num_to_ptr call SOCKET_num_to_ptr
jz s_error jz s_error
@ -635,7 +633,7 @@ SOCKET_listen:
align 4 align 4
SOCKET_accept: SOCKET_accept:
DEBUGF 1,"SOCKET_accept: socknum: %u sockaddr: %x, length: %u\n", ecx, edx, esi DEBUGF 1,"SOCKET_accept: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi
call SOCKET_num_to_ptr call SOCKET_num_to_ptr
jz s_error jz s_error
@ -674,7 +672,7 @@ SOCKET_accept:
align 4 align 4
SOCKET_close: SOCKET_close:
DEBUGF 1,"SOCKET_close: socknum: %u\n", ecx DEBUGF 1,"SOCKET_close: %u\n", ecx
call SOCKET_num_to_ptr call SOCKET_num_to_ptr
jz s_error jz s_error
@ -701,6 +699,7 @@ SOCKET_close:
jb .free jb .free
call TCP_usrclosed call TCP_usrclosed
call TCP_output ;;;; Fixme: is this nescessary??
mov dword [esp+32], 0 mov dword [esp+32], 0
ret ret
@ -726,7 +725,7 @@ SOCKET_close:
align 4 align 4
SOCKET_receive: SOCKET_receive:
DEBUGF 1,"SOCKET_receive: socknum: %u bufaddr: %x, buflength: %u, flags: %x, ", ecx, edx, esi, edi DEBUGF 1,"SOCKET_receive: socknum=%u bufaddr=%x buflength=%u flags=%x\n", ecx, edx, esi, edi
call SOCKET_num_to_ptr call SOCKET_num_to_ptr
jz s_error jz s_error
@ -745,14 +744,14 @@ SOCKET_receive_dgram:
get_from_queue (eax + SOCKET_QUEUE_LOCATION), SOCKET_QUEUE_SIZE, sizeof.socket_queue_entry, s_error ; destroys esi and ecx get_from_queue (eax + SOCKET_QUEUE_LOCATION), SOCKET_QUEUE_SIZE, sizeof.socket_queue_entry, s_error ; destroys esi and ecx
mov ecx, [esi + socket_queue_entry.data_size] mov ecx, [esi + socket_queue_entry.data_size]
DEBUGF 1,"Got %u bytes of data\n", ecx DEBUGF 1,"SOCKET_receive: %u bytes data\n", ecx
cmp ecx, ebx cmp ecx, ebx
ja .too_small ja .too_small
push [esi + socket_queue_entry.buf_ptr] ; save the buffer addr so we can clear it later push [esi + socket_queue_entry.buf_ptr] ; save the buffer addr so we can clear it later
mov esi, [esi + socket_queue_entry.data_ptr] mov esi, [esi + socket_queue_entry.data_ptr]
DEBUGF 1,"Source buffer: %x, real addr: %x\n", [esp], esi DEBUGF 1,"SOCKET_receive: Source buffer=%x real addr=%x\n", [esp], esi
mov [esp+32+4], ecx ; return number of bytes copied mov [esp+32+4], ecx ; return number of bytes copied
; copy the data ; copy the data
@ -774,7 +773,7 @@ SOCKET_receive_dgram:
.too_small: .too_small:
DEBUGF 1,"Buffer too small...\n" DEBUGF 1,"SOCKET_receive: Buffer too small\n"
jmp s_error jmp s_error
align 4 align 4
@ -808,7 +807,7 @@ SOCKET_receive_tcp:
align 4 align 4
SOCKET_send: SOCKET_send:
DEBUGF 1,"SOCKET_send: socknum: %u data ptr: %x, length: %u, flags: %x, ", ecx, edx, esi, edi DEBUGF 1,"SOCKET_send: socknum=%u data ptr=%x length=%u flags=%x\n", ecx, edx, esi, edi
call SOCKET_num_to_ptr call SOCKET_num_to_ptr
jz s_error jz s_error
@ -850,7 +849,7 @@ SOCKET_send_tcp:
align 4 align 4
SOCKET_send_ip: SOCKET_send_ip:
DEBUGF 1,"type: IP\n" DEBUGF 1,"SOCKET_send: IPv4\n"
mov [esp+32], ecx mov [esp+32], ecx
call IPv4_output_raw call IPv4_output_raw
@ -966,7 +965,7 @@ SOCKET_set_opt:
jz s_error jz s_error
mov [eax + SOCKET.device], edx mov [eax + SOCKET.device], edx
DEBUGF 1,"Bound socket %x to device %x\n",eax, edx DEBUGF 1,"SOCKET_set_opt: Bound socket %x to device %x\n",eax, edx
mov dword [esp+32], 0 ; success! mov dword [esp+32], 0 ; success!
ret ret
@ -993,7 +992,7 @@ SOCKET_set_opt:
align 4 align 4
SOCKET_debug: SOCKET_debug:
DEBUGF 1,"socket_debug\n" DEBUGF 1,"SOCKET_debug\n"
call SOCKET_num_to_ptr call SOCKET_num_to_ptr
jz s_error jz s_error
@ -1084,7 +1083,7 @@ SOCKET_find_port:
align 4 align 4
SOCKET_check_port: SOCKET_check_port:
DEBUGF 1,"SOCKET_check_port\n" DEBUGF 1,"SOCKET_check_port: "
mov ecx, [eax + SOCKET.Protocol] mov ecx, [eax + SOCKET.Protocol]
mov edx, [eax + IP_SOCKET.LocalIP] mov edx, [eax + IP_SOCKET.LocalIP]
@ -1108,6 +1107,7 @@ SOCKET_check_port:
ret ret
.port_ok: .port_ok:
DEBUGF 1,"local port %u is free\n", bx
mov [eax + UDP_SOCKET.LocalPort], bx mov [eax + UDP_SOCKET.LocalPort], bx
or bx, bx ; set the zero-flag or bx, bx ; set the zero-flag
@ -1636,7 +1636,7 @@ SOCKET_fork:
align 4 align 4
SOCKET_num_to_ptr: SOCKET_num_to_ptr:
DEBUGF 1,"SOCKET_num_to_ptr: %u ", ecx DEBUGF 1,"SOCKET_num_to_ptr: num=%u ", ecx
mov eax, net_sockets mov eax, net_sockets
@ -1649,8 +1649,11 @@ SOCKET_num_to_ptr:
test eax, eax test eax, eax
DEBUGF 1,"(%x)\n", eax DEBUGF 1,"ptr=%x\n", eax
ret
.error: .error:
DEBUGF 1,"not found\n", eax
ret ret
@ -1668,16 +1671,18 @@ SOCKET_num_to_ptr:
align 4 align 4
SOCKET_ptr_to_num: SOCKET_ptr_to_num:
DEBUGF 1,"SOCKET_ptr_to_num: %x ", eax DEBUGF 1,"SOCKET_ptr_to_num: ptr=%x ", eax
call SOCKET_check call SOCKET_check
jz .error jz .error
mov eax, [eax + SOCKET.Number] mov eax, [eax + SOCKET.Number]
DEBUGF 1,"(%u)\n", eax DEBUGF 1,"num=%u\n", eax
ret
.error: .error:
DEBUGF 1,"not found\n", eax
ret ret
@ -1771,7 +1776,7 @@ SOCKET_process_end:
cmp [ebx + SOCKET.PID], edx cmp [ebx + SOCKET.PID], edx
jne .next_socket jne .next_socket
DEBUGF 1,"killing socket %x\n", ebx DEBUGF 1,"SOCKET_process_end: killing socket %x\n", ebx
mov [ebx + SOCKET.PID], 0 mov [ebx + SOCKET.PID], 0
@ -1812,6 +1817,7 @@ SOCKET_process_end:
align 4 align 4
SOCKET_is_connecting: SOCKET_is_connecting:
DEBUGF 1,"SOCKET_is_connecting: %x\n", eax
and [eax + SOCKET.options], not (SS_ISCONNECTED + SS_ISDISCONNECTING + SS_ISCONFIRMING) and [eax + SOCKET.options], not (SS_ISCONNECTED + SS_ISDISCONNECTING + SS_ISCONFIRMING)
or [eax + SOCKET.options], SS_ISCONNECTING or [eax + SOCKET.options], SS_ISCONNECTING
@ -1832,6 +1838,7 @@ SOCKET_is_connecting:
align 4 align 4
SOCKET_is_connected: SOCKET_is_connected:
DEBUGF 1,"SOCKET_is_connected: %x\n", eax
and [eax + SOCKET.options], not (SS_ISCONNECTING + SS_ISDISCONNECTING + SS_ISCONFIRMING) and [eax + SOCKET.options], not (SS_ISCONNECTING + SS_ISDISCONNECTING + SS_ISCONFIRMING)
or [eax + SOCKET.options], SS_ISCONNECTED or [eax + SOCKET.options], SS_ISCONNECTED
@ -1853,6 +1860,8 @@ SOCKET_is_connected:
align 4 align 4
SOCKET_is_disconnecting: SOCKET_is_disconnecting:
DEBUGF 1,"SOCKET_is_disconnecting: %x\n", eax
and [eax + SOCKET.options], not (SS_ISCONNECTING) and [eax + SOCKET.options], not (SS_ISCONNECTING)
or [eax + SOCKET.options], SS_ISDISCONNECTING + SS_CANTRCVMORE + SS_CANTSENDMORE or [eax + SOCKET.options], SS_ISDISCONNECTING + SS_CANTRCVMORE + SS_CANTSENDMORE
@ -1872,6 +1881,8 @@ SOCKET_is_disconnecting:
align 4 align 4
SOCKET_is_disconnected: SOCKET_is_disconnected:
DEBUGF 1,"SOCKET_is_disconnected: %x\n", eax
and [eax + SOCKET.options], not (SS_ISCONNECTING + SS_ISCONNECTED + SS_ISDISCONNECTING) and [eax + SOCKET.options], not (SS_ISCONNECTING + SS_ISCONNECTED + SS_ISDISCONNECTING)
or [eax + SOCKET.options], SS_CANTRCVMORE + SS_CANTSENDMORE or [eax + SOCKET.options], SS_CANTRCVMORE + SS_CANTSENDMORE
@ -1890,6 +1901,8 @@ SOCKET_is_disconnected:
align 4 align 4
SOCKET_cant_recv_more: SOCKET_cant_recv_more:
DEBUGF 1,"SOCKET_cant_recv_more: %x\n", eax
or [eax + SOCKET.options], SS_CANTRCVMORE or [eax + SOCKET.options], SS_CANTRCVMORE
ret ret
@ -1908,6 +1921,8 @@ SOCKET_cant_recv_more:
align 4 align 4
SOCKET_cant_send_more: SOCKET_cant_send_more:
DEBUGF 1,"SOCKET_cant_send_more: %x\n", eax
or [eax + SOCKET.options], SS_CANTSENDMORE or [eax + SOCKET.options], SS_CANTSENDMORE
ret ret

View File

@ -346,7 +346,7 @@ NET_add_device:
align 4 align 4
NET_set_default: NET_set_default:
DEBUGF 1,"NET_set_default %x\n", eax DEBUGF 1,"NET_set_default: device=%x\n", eax
cmp eax, MAX_NET_DEVICES cmp eax, MAX_NET_DEVICES
jae .error jae .error
@ -356,12 +356,12 @@ NET_set_default:
mov [NET_DEFAULT], eax mov [NET_DEFAULT], eax
DEBUGF 1,"Device number %u is now default!\n", eax DEBUGF 1,"NET_set_default: succes\n"
ret ret
.error: .error:
or eax, -1 or eax, -1
DEBUGF 2,"Setting default network device failed\n" DEBUGF 1,"NET_set_default: failed\n"
ret ret
@ -371,7 +371,7 @@ NET_set_default:
; ;
; This function is called by etwork drivers, ; This function is called by etwork drivers,
; to unregister network devices from the kernel ; to unregister network devices from the kernel
; d ;
; IN: Pointer to device structure in ebx ; IN: Pointer to device structure in ebx
; OUT: eax: -1 on error ; OUT: eax: -1 on error
; ;
@ -664,7 +664,6 @@ sys_network: ; FIXME: make default device easily accessible
jmp .return jmp .return
.doesnt_exist: .doesnt_exist:
DEBUGF 1,"sys_network: invalid device/function specified!\n"
mov eax, -1 mov eax, -1
.return: .return:
@ -717,7 +716,6 @@ sys_protocols:
add esp, 4 ; if we reached here, no function was called, so we need to balance stack add esp, 4 ; if we reached here, no function was called, so we need to balance stack
.doesnt_exist: .doesnt_exist:
DEBUGF 1,"sys_protocols: protocol %u doesnt exist on device %u!\n", ax, bh
mov eax, -1 mov eax, -1
.return: .return:

View File

@ -34,7 +34,7 @@ $Revision$
align 4 align 4
TCP_input: TCP_input:
DEBUGF 1,"TCP_input size=%u\n", ecx DEBUGF 1,"TCP_input: size=%u\n", ecx
; First, re-calculate the checksum ; First, re-calculate the checksum
@ -47,7 +47,7 @@ TCP_input:
pop edx ecx pop edx ecx
jne .drop_no_socket jne .drop_no_socket
DEBUGF 1,"Checksum ok\n" DEBUGF 1,"TCP_input: Checksum ok\n"
and [edx + TCP_header.DataOffset], 0xf0 ; Calculate TCP segment header size (throwing away unused reserved bits in TCP header) and [edx + TCP_header.DataOffset], 0xf0 ; Calculate TCP segment header size (throwing away unused reserved bits in TCP header)
shr [edx + TCP_header.DataOffset], 2 shr [edx + TCP_header.DataOffset], 2
@ -57,7 +57,7 @@ TCP_input:
movzx eax, [edx + TCP_header.DataOffset] movzx eax, [edx + TCP_header.DataOffset]
sub ecx, eax ; substract TCP header size from total segment size sub ecx, eax ; substract TCP header size from total segment size
jb .drop_no_socket ; If total segment size is less then the advertised header size, drop packet jb .drop_no_socket ; If total segment size is less then the advertised header size, drop packet
DEBUGF 1,"we got %u bytes of data\n", ecx DEBUGF 1,"TCP_input: %u bytes of data\n", ecx
;----------------------------------------------------------------------------------------- ;-----------------------------------------------------------------------------------------
; Check if this packet has a timestamp option (We do it here so we can process it quickly) ; Check if this packet has a timestamp option (We do it here so we can process it quickly)
@ -76,7 +76,7 @@ TCP_input:
cmp dword [edx + sizeof.TCP_header], 0x0101080a ; Timestamp header cmp dword [edx + sizeof.TCP_header], 0x0101080a ; Timestamp header
jne .no_timestamp jne .no_timestamp
DEBUGF 1,"timestamp ok\n" DEBUGF 1,"TCP_input: timestamp ok\n"
; TODO: Parse the option ; TODO: Parse the option
; TODO: Set a Bit in the TCP to tell all options are parsed ; TODO: Set a Bit in the TCP to tell all options are parsed
@ -131,7 +131,7 @@ TCP_input:
test ax, ax test ax, ax
jnz .socket_loop jnz .socket_loop
.found_socket: ; ebx now contains the socketpointer .found_socket: ; ebx now contains the socketpointer
DEBUGF 1,"Socket ptr: %x\n", ebx DEBUGF 1,"TCP_input: socket ptr=%x state=%u flags=%x\n", ebx, [ebx + TCP_SOCKET.t_state], [edx + TCP_header.Flags]:2
; update stats ; update stats
inc [TCP_segments_rx] ; FIXME: correct interface? inc [TCP_segments_rx] ; FIXME: correct interface?
@ -146,11 +146,19 @@ TCP_input:
; Lock the socket ; Lock the socket
pusha pusha
pushf
cli
lea ecx, [ebx + SOCKET.mutex] lea ecx, [ebx + SOCKET.mutex]
call mutex_lock call mutex_lock
popf
popa popa
DEBUGF 1,"Socket locked\n" DEBUGF 1,"TCP_input: socket locked\n"
;----------------------
; set need_output to 0
mov [ebx + TCP_SOCKET.sendalot], 0
;--------------------------------------- ;---------------------------------------
; unscale the window into a 32 bit value ; unscale the window into a 32 bit value
@ -168,7 +176,7 @@ TCP_input:
test [ebx + SOCKET.options], SO_ACCEPTCON test [ebx + SOCKET.options], SO_ACCEPTCON
jz .no_listening_socket jz .no_listening_socket
DEBUGF 1,"Accepting new connection\n" DEBUGF 1,"TCP_input: Accepting new connection\n"
pusha pusha
lea ecx, [ebx + SOCKET.mutex] lea ecx, [ebx + SOCKET.mutex]
@ -208,7 +216,7 @@ TCP_input:
cmp eax, sizeof.TCP_header ; Does header contain any options? cmp eax, sizeof.TCP_header ; Does header contain any options?
je .no_options je .no_options
DEBUGF 1,"Segment has options\n" DEBUGF 1,"TCP_input: Segment has options\n"
cmp [ebx + TCP_SOCKET.t_state], TCPS_LISTEN ; no options when in listen state cmp [ebx + TCP_SOCKET.t_state], TCPS_LISTEN ; no options when in listen state
jz .not_uni_xfer ; also no header prediction jz .not_uni_xfer ; also no header prediction
@ -250,7 +258,7 @@ TCP_input:
movzx eax, word[esi+2] movzx eax, word[esi+2]
rol ax, 8 rol ax, 8
DEBUGF 1,"Maxseg: %u\n", ax DEBUGF 1,"TCP_input: Maxseg=%u\n", ax
mov [ebx + TCP_SOCKET.t_maxseg], eax mov [ebx + TCP_SOCKET.t_maxseg], eax
@ -266,7 +274,7 @@ TCP_input:
test [edx + TCP_header.Flags], TH_SYN test [edx + TCP_header.Flags], TH_SYN
jz @f jz @f
DEBUGF 1,"Got window option\n" DEBUGF 1,"TCP_input: Got window option\n"
;;;;; ;;;;;
@@: @@:
@ -278,7 +286,7 @@ TCP_input:
cmp byte [esi+1], 10 cmp byte [esi+1], 10
jne .no_options jne .no_options
DEBUGF 1,"Got timestamp option\n" DEBUGF 1,"TCP_input: Got timestamp option\n"
;;;;; ;;;;;
@ -287,11 +295,6 @@ TCP_input:
.no_options: .no_options:
;----------------------------------------------------------------------- ;-----------------------------------------------------------------------
; Time to do some header prediction (Original Principle by Van Jacobson) ; Time to do some header prediction (Original Principle by Van Jacobson)
@ -352,7 +355,7 @@ TCP_input:
sub eax, [ebx + TCP_SOCKET.SND_UNA] sub eax, [ebx + TCP_SOCKET.SND_UNA]
jbe .not_uni_xfer jbe .not_uni_xfer
DEBUGF 1,"Header prediction: we are sender\n" DEBUGF 1,"TCP_input: Header prediction: we are sender\n"
;--------------------------------- ;---------------------------------
; Packet is a pure ACK, process it ; Packet is a pure ACK, process it
@ -408,7 +411,7 @@ TCP_input:
; Complete processing of received data ; Complete processing of received data
DEBUGF 1,"header prediction: we are receiver\nreceiving %u bytes of data\n", ecx DEBUGF 1,"TCP_input: Header prediction: we are receiving %u bytes\n", ecx
add [ebx + TCP_SOCKET.RCV_NXT], ecx ; Update sequence number with number of bytes we have copied add [ebx + TCP_SOCKET.RCV_NXT], ecx ; Update sequence number with number of bytes we have copied
@ -434,7 +437,7 @@ TCP_input:
.not_uni_xfer: .not_uni_xfer:
DEBUGF 1,"Header prediction failed\n" DEBUGF 1,"TCP_input: Header prediction failed\n"
; Calculate receive window size ; Calculate receive window size
@ -464,7 +467,7 @@ TCP_input:
align 4 align 4
.LISTEN: .LISTEN:
DEBUGF 1,"TCP state: listen\n" DEBUGF 1,"TCP_input: state=listen\n"
test [edx + TCP_header.Flags], TH_RST ;;; TODO: kill new socket on error test [edx + TCP_header.Flags], TH_RST ;;; TODO: kill new socket on error
jnz .drop jnz .drop
@ -525,7 +528,7 @@ align 4
align 4 align 4
.SYN_SENT: .SYN_SENT:
DEBUGF 1,"TCP state: syn_sent\n" DEBUGF 1,"TCP_input: state=syn_sent\n"
test [edx + TCP_header.Flags], TH_ACK test [edx + TCP_header.Flags], TH_ACK
jz @f jz @f
@ -586,7 +589,7 @@ align 4
test [edx + TCP_header.Flags], TH_ACK test [edx + TCP_header.Flags], TH_ACK
jz .simultaneous_open jz .simultaneous_open
DEBUGF 1,"TCP: active open\n" DEBUGF 1,"TCP_input: active open\n"
;;; TODO: update stats ;;; TODO: update stats
@ -603,7 +606,7 @@ align 4
.simultaneous_open: .simultaneous_open:
DEBUGF 1,"TCP: simultaneous open\n" DEBUGF 1,"TCP_input: simultaneous open\n"
; We have received a syn but no ACK, so we are having a simultaneous open.. ; We have received a syn but no ACK, so we are having a simultaneous open..
mov [ebx + TCP_SOCKET.t_state], TCPS_SYN_RECEIVED mov [ebx + TCP_SOCKET.t_state], TCPS_SYN_RECEIVED
@ -638,7 +641,7 @@ align 4
.NOT_LISTEN_OR_SYN_SENT: .NOT_LISTEN_OR_SYN_SENT:
DEBUGF 1,"Slow TCP input: not listen or syn_sent state\n" DEBUGF 1,"TCP_input: state is not listen or syn_sent\n"
;-------------------------------------------- ;--------------------------------------------
; Protection Against Wrapped Sequence Numbers ; Protection Against Wrapped Sequence Numbers
@ -667,7 +670,7 @@ align 4
sub eax, [edx + TCP_header.SequenceNumber] sub eax, [edx + TCP_header.SequenceNumber]
jbe .no_duplicate jbe .no_duplicate
DEBUGF 1,"Uh oh.. %u bytes of duplicate data!\n", eax DEBUGF 1,"TCP_input: %u bytes duplicate data!\n", eax
test [edx + TCP_header.Flags], TH_SYN test [edx + TCP_header.Flags], TH_SYN
jz .no_dup_syn jz .no_dup_syn
@ -694,27 +697,29 @@ align 4
cmp eax, ecx cmp eax, ecx
jae .duplicate jae .duplicate
DEBUGF 1,"Going to drop %u out of %u bytes\n", eax, ecx DEBUGF 1,"TCP_input: Going to drop %u out of %u bytes\n", eax, ecx
;;; TODO: apply figure 28.30 ;;; TODO: apply figure 28.30
; Check for duplicate FIN ; Check for duplicate FIN
test [edx + TCP_header.Flags], TH_FIN test [edx + TCP_header.Flags], TH_FIN
jz @f jz .no_fin2
inc ecx inc ecx
cmp eax, ecx cmp eax, ecx
dec ecx
jne @f jne @f
mov eax, ecx mov eax, ecx
and [edx + TCP_header.Flags], not TH_FIN and [edx + TCP_header.Flags], not TH_FIN
or [ebx + TCP_SOCKET.t_flags], TF_ACKNOW or [ebx + TCP_SOCKET.t_flags], TF_ACKNOW
dec ecx
jmp .no_duplicate jmp .no_duplicate
@@: @@:
dec ecx
.no_fin2:
; Handle the case when a bound socket connects to itself ; Handle the case when a bound socket connects to itself
; Allow packets with a SYN and an ACKto continue with the processing ; Allow packets with a SYN and an ACK to continue with the processing
;------------------------------------- ;-------------------------------------
; Generate duplicate ACK if nescessary ; Generate duplicate ACK if nescessary
@ -729,7 +734,7 @@ align 4
.duplicate: .duplicate:
DEBUGF 1,"Duplicate received\n" DEBUGF 1,"TCP_input: Duplicate received\n"
;---------------------------------------- ;----------------------------------------
; Update statistics for duplicate packets ; Update statistics for duplicate packets
@ -744,8 +749,7 @@ align 4
; Remove duplicate data and update urgent offset ; Remove duplicate data and update urgent offset
add [edx + TCP_header.SequenceNumber], eax add [edx + TCP_header.SequenceNumber], eax
sub ecx, eax ;;;;;;;; Checkme
;;; TODO
sub [edx + TCP_header.UrgentPointer], ax sub [edx + TCP_header.UrgentPointer], ax
ja @f ja @f
@ -795,60 +799,50 @@ align 4
.no_excess_data: .no_excess_data:
;----------------- ;-----------------
; Record timestamp ; Record timestamp
;;; TODO 737-746 ;;; TODO 737-746
;------------------ ;------------------
; Process RST flags ; Process RST flags
test [edx + TCP_header.Flags], TH_RST test [edx + TCP_header.Flags], TH_RST
jz .rst_skip jz .no_rst
DEBUGF 1,"Got an RST flag\n" DEBUGF 1,"TCP_input: Got an RST flag\n"
mov eax, [ebx + TCP_SOCKET.t_state] mov eax, [ebx + TCP_SOCKET.t_state]
shl eax, 2 shl eax, 2
jmp dword [eax + .rst_sw_list] jmp dword [eax + .rst_sw_list]
.rst_sw_list: .rst_sw_list:
dd .rst_skip ;TCPS_CLOSED dd .no_rst ; TCPS_CLOSED
dd .rst_skip ;TCPS_LISTEN dd .no_rst ; TCPS_LISTEN
dd .rst_skip ;TCPS_SYN_SENT dd .no_rst ; TCPS_SYN_SENT
dd .econnrefused ;TCPS_SYN_RECEIVED dd .econnrefused ; TCPS_SYN_RECEIVED
dd .econnreset ;TCPS_ESTABLISHED dd .econnreset ; TCPS_ESTABLISHED
dd .econnreset ;TCPS_CLOSE_WAIT dd .econnreset ; TCPS_CLOSE_WAIT
dd .econnreset ;TCPS_FIN_WAIT_1 dd .econnreset ; TCPS_FIN_WAIT_1
dd .rst_close ;TCPS_CLOSING dd .rst_close ; TCPS_CLOSING
dd .rst_close ;TCPS_LAST_ACK dd .rst_close ; TCPS_LAST_ACK
dd .econnreset ;TCPS_FIN_WAIT_2 dd .econnreset ; TCPS_FIN_WAIT_2
dd .rst_close ;TCPS_TIMED_WAIT dd .rst_close ; TCPS_TIMED_WAIT
.econnrefused: .econnrefused:
DEBUGF 1,"Connection refused\n" DEBUGF 1,"TCP_input: Connection refused\n"
mov [ebx + SOCKET.errorcode], ECONNREFUSED mov [ebx + SOCKET.errorcode], ECONNREFUSED
jmp .close jmp .close
.econnreset: .econnreset:
DEBUGF 1,"Connection reset\n" DEBUGF 1,"TCP_input: Connection reset\n"
mov [ebx + SOCKET.errorcode], ECONNRESET mov [ebx + SOCKET.errorcode], ECONNRESET
.close: .close:
DEBUGF 1,"Closing connection\n" DEBUGF 1,"TCP_input: Closing connection\n"
mov [ebx + TCP_SOCKET.t_state], TCPS_CLOSED mov [ebx + TCP_SOCKET.t_state], TCPS_CLOSED
;;; TODO: update stats (tcp drops) ;;; TODO: update stats (tcp drops)
@ -857,19 +851,13 @@ align 4
jmp .drop jmp .drop
.rst_close: .rst_close:
DEBUGF 1,"Closing with reset\n" DEBUGF 1,"TCP_input: Closing with reset\n"
mov eax, ebx mov eax, ebx
call TCP_close call TCP_close
jmp .drop jmp .drop
.no_rst:
.rst_skip:
;-------------------------------------- ;--------------------------------------
@ -882,24 +870,18 @@ align 4
mov ebx, ECONNRESET mov ebx, ECONNRESET
call TCP_drop call TCP_drop
jmp .drop_with_reset jmp .drop_with_reset
test [edx + TCP_header.Flags], TH_ACK
jz .drop
@@: @@:
;--------------- ;---------------
; ACK processing ; ACK processing
test [edx + TCP_header.Flags], TH_ACK
jz .drop
cmp [ebx + TCP_SOCKET.t_state], TCPS_SYN_RECEIVED cmp [ebx + TCP_SOCKET.t_state], TCPS_SYN_RECEIVED
jnz .no_syn_rcv jnz .no_syn_rcv
DEBUGF 1,"TCP state = syn received\n" DEBUGF 1,"TCP_input: state=syn_received\n"
mov eax, [edx + TCP_header.AckNumber] mov eax, [edx + TCP_header.AckNumber]
cmp [ebx + TCP_SOCKET.SND_UNA], eax cmp [ebx + TCP_SOCKET.SND_UNA], eax
@ -924,12 +906,11 @@ align 4
pop word [ebx + TCP_SOCKET.SND_SCALE] pop word [ebx + TCP_SOCKET.SND_SCALE]
@@: @@:
;;; TODO: copy the data (if any) into the socket ;;; TODO: call TCP_reassemble
mov eax, [edx + TCP_header.SequenceNumber] mov eax, [edx + TCP_header.SequenceNumber]
dec eax dec eax
mov [ebx + TCP_SOCKET.SND_WL1], eax mov [ebx + TCP_SOCKET.SND_WL1], eax
jmp .not_dup_ack
.no_syn_rcv: .no_syn_rcv:
@ -946,7 +927,7 @@ align 4
cmp eax, [ebx + TCP_SOCKET.SND_WND] cmp eax, [ebx + TCP_SOCKET.SND_WND]
jne .reset_dupacks jne .reset_dupacks
DEBUGF 1,"Processing a duplicate ACK..\n" DEBUGF 1,"TCP_input: Processing duplicate ACK\n"
cmp [ebx + TCP_SOCKET.timer_retransmission], 10000 ;;;; FIXME cmp [ebx + TCP_SOCKET.timer_retransmission], 10000 ;;;; FIXME
ja @f ja @f
@ -1011,7 +992,7 @@ align 4
.no_re_xmit: .no_re_xmit:
jbe .not_dup_ack jbe .not_dup_ack
DEBUGF 1,"Increasing congestion window\n" DEBUGF 1,"TCP_input: Increasing congestion window\n"
mov eax, [ebx + TCP_SOCKET.t_maxseg] mov eax, [ebx + TCP_SOCKET.t_maxseg]
add [ebx + TCP_SOCKET.SND_CWND], eax add [ebx + TCP_SOCKET.SND_CWND], eax
@ -1022,10 +1003,6 @@ align 4
jmp .drop jmp .drop
.not_dup_ack: .not_dup_ack:
;------------------------------------------------- ;-------------------------------------------------
@ -1057,12 +1034,7 @@ align 4
;;; TODO: update stats ;;; TODO: update stats
DEBUGF 1,"We have an acceptable ACK of %u bytes\n", edi DEBUGF 1,"TCP_input: acceptable ACK for %u bytes\n", edi
;------------------------------------------ ;------------------------------------------
; RTT measurements and retransmission timer ; RTT measurements and retransmission timer
@ -1075,13 +1047,9 @@ align 4
cmp eax, [edx + TCP_header.AckNumber] cmp eax, [edx + TCP_header.AckNumber]
je .all_outstanding je .all_outstanding
mov [ebx + TCP_SOCKET.timer_retransmission], 120 ;;;; TODO: correct this value (use a macro for it) mov [ebx + TCP_SOCKET.timer_retransmission], 120 ;;;; TODO: correct this value (use a macro for it)
.all_outstanding: .all_outstanding:
inc [ebx + TCP_SOCKET.sendalot] ; need output
;------------------------------------------- ;-------------------------------------------
; Open congestion window in response to ACKs ; Open congestion window in response to ACKs
@ -1113,15 +1081,26 @@ align 4
cmova esi, eax cmova esi, eax
mov [ebx + TCP_SOCKET.SND_CWND], esi mov [ebx + TCP_SOCKET.SND_CWND], esi
;------------------------------------------ ;------------------------------------------
; Remove acknowledged data from send buffer ; Remove acknowledged data from send buffer
cmp edi, [ebx + STREAM_SOCKET.snd.size]
jbe .finiacked
push ecx edx ebx
mov ecx, [ebx + STREAM_SOCKET.snd.size]
lea eax, [ebx + STREAM_SOCKET.snd]
sub [ebx + TCP_SOCKET.SND_WND], ecx
call SOCKET_ring_free
pop ebx edx ecx
DEBUGF 1,"TCP_input: our FIN is acked\n"
stc
jmp .wakeup
.finiacked:
push ecx edx ebx push ecx edx ebx
mov ecx, edi mov ecx, edi
lea eax, [ebx + STREAM_SOCKET.snd] lea eax, [ebx + STREAM_SOCKET.snd]
@ -1130,8 +1109,15 @@ align 4
sub [ebx + TCP_SOCKET.SND_WND], ecx sub [ebx + TCP_SOCKET.SND_WND], ecx
pop edx ecx pop edx ecx
DEBUGF 1,"TCP_input: our FIN is not acked\n"
clc
;----------------------------------------
; Wake up process waiting on send buffer ; Wake up process waiting on send buffer
.wakeup:
pushf
mov eax, ebx mov eax, ebx
call SOCKET_notify_owner call SOCKET_notify_owner
@ -1139,17 +1125,12 @@ align 4
mov eax, [edx + TCP_header.AckNumber] mov eax, [edx + TCP_header.AckNumber]
mov [ebx + TCP_SOCKET.SND_UNA], eax mov [ebx + TCP_SOCKET.SND_UNA], eax
cmp eax, [ebx + TCP_SOCKET.SND_NXT] cmp eax, [ebx + TCP_SOCKET.SND_NXT]
jb @f jb @f
mov [ebx + TCP_SOCKET.SND_NXT], eax mov [ebx + TCP_SOCKET.SND_NXT], eax
@@: @@:
popf
;; TODO: use zero flag as 'ourfinisacked'
; General ACK handling complete ; General ACK handling complete
; Now do the state-specific ones ; Now do the state-specific ones
@ -1158,27 +1139,27 @@ align 4
jmp dword [eax*4 + .ACK_sw_list] jmp dword [eax*4 + .ACK_sw_list]
.ACK_sw_list: .ACK_sw_list:
dd .ack_processed ;TCPS_CLOSED dd .ack_processed ; TCPS_CLOSED
dd .ack_processed ;TCPS_LISTEN dd .ack_processed ; TCPS_LISTEN
dd .ack_processed ;TCPS_SYN_SENT dd .ack_processed ; TCPS_SYN_SENT
dd .ack_processed ;TCPS_SYN_RECEIVED dd .ack_processed ; TCPS_SYN_RECEIVED
dd .ack_processed ;TCPS_ESTABLISHED dd .ack_processed ; TCPS_ESTABLISHED
dd .ack_processed ;TCPS_CLOSE_WAIT dd .ack_processed ; TCPS_CLOSE_WAIT
dd .ack_fw1 ;TCPS_FIN_WAIT_1 dd .ack_fw1 ; TCPS_FIN_WAIT_1
dd .ack_c ;TCPS_CLOSING dd .ack_c ; TCPS_CLOSING
dd .ack_la ;TCPS_LAST_ACK dd .ack_la ; TCPS_LAST_ACK
dd .ack_processed ;TCPS_FIN_WAIT_2 dd .ack_processed ; TCPS_FIN_WAIT_2
dd .ack_tw ;TCPS_TIMED_WAIT dd .ack_tw ; TCPS_TIMED_WAIT
.ack_fw1: .ack_fw1:
jz .ack_processed jnc .ack_processed
test [ebx + SOCKET.state], SS_CANTRCVMORE test [ebx + SOCKET.state], SS_CANTRCVMORE
jnz @f jnz @f
mov eax, ebx mov eax, ebx
call SOCKET_is_disconnected call SOCKET_is_disconnected
;;; mov [ebx + TCP_SOCKET.timer_timed_wait], TCP_time_max_idle ;;; mov [ebx + TCP_SOCKET.timer_timed_wait], TCP_time_max_idle ; FIXME
@@: @@:
mov [ebx + TCP_SOCKET.t_state], TCPS_FIN_WAIT_2 mov [ebx + TCP_SOCKET.t_state], TCPS_FIN_WAIT_2
@ -1186,7 +1167,7 @@ align 4
.ack_c: .ack_c:
jz .ack_processed jnc .ack_processed
mov [ebx + TCP_SOCKET.t_state], TCPS_TIMED_WAIT mov [ebx + TCP_SOCKET.t_state], TCPS_TIMED_WAIT
mov eax, ebx mov eax, ebx
@ -1198,7 +1179,7 @@ align 4
.ack_la: .ack_la:
jz .ack_processed jnc .ack_processed
mov eax, ebx mov eax, ebx
@ -1212,17 +1193,13 @@ align 4
.reset_dupacks: ; We got a new ACK, reset duplicate ACK counter .reset_dupacks: ; We got a new ACK, reset duplicate ACK counter
mov [ebx + TCP_SOCKET.t_dupacks], 0 mov [ebx + TCP_SOCKET.t_dupacks], 0
.ack_processed: ; (step 6) .ack_processed: ; (step 6)
DEBUGF 1,"ACK processed\n" DEBUGF 1,"TCP_input: ACK processed\n"
;---------------------------------------------- ;----------------------------------------------
; check if we need to update window information ; check if we need to update window information
@ -1260,7 +1237,7 @@ align 4
@@: @@:
mov [ebx + TCP_SOCKET.SND_WND], eax mov [ebx + TCP_SOCKET.SND_WND], eax
DEBUGF 1,"Updating window to %d\n", eax DEBUGF 1,"TCP_input: Updating window to %u\n", eax
push [edx + TCP_header.SequenceNumber] push [edx + TCP_header.SequenceNumber]
pop [ebx + TCP_SOCKET.SND_WL1] pop [ebx + TCP_SOCKET.SND_WL1]
@ -1268,7 +1245,7 @@ align 4
push [edx + TCP_header.AckNumber] push [edx + TCP_header.AckNumber]
pop [ebx + TCP_SOCKET.SND_WL2] pop [ebx + TCP_SOCKET.SND_WL2]
;;; needoutput = 1 inc [ebx + TCP_SOCKET.sendalot]
.no_window_update: .no_window_update:
@ -1310,70 +1287,35 @@ align 4
;;; TODO (1051-1093) ;;; TODO (1051-1093)
;---------------------------------------
; process the data in the segment (1094)
;--------------------------------
; process the data in the segment
.do_data: .do_data:
DEBUGF 1,"TCP: do data (%u)\n", ecx cmp [ebx + TCP_SOCKET.t_state], TCPS_TIMED_WAIT
jae .final_processing
test [edx + TCP_header.Flags], TH_FIN test [edx + TCP_header.Flags], TH_FIN
jnz .process_fin jnz @f
cmp [ebx + TCP_SOCKET.t_state], TCPS_FIN_WAIT_1
jae .dont_do_data
test ecx, ecx test ecx, ecx
jz .final_processing jnz .final_processing
@@:
DEBUGF 1,"Processing data in segment\n"
;; TODO: check if data is in sequence !
movzx esi, [edx + TCP_header.DataOffset]
add esi, edx
or [ebx + TCP_SOCKET.t_flags], TF_DELACK
add [ebx + TCP_SOCKET.RCV_NXT], ecx
lea eax, [ebx + STREAM_SOCKET.rcv]
call SOCKET_ring_write
mov eax, ebx
call SOCKET_notify_owner
jmp .final_processing
.dont_do_data:
; call TCP_reassemble ;;; TODO
;--------------- ;---------------
; FIN processing ; FIN processing
.process_fin: test [edx + TCP_header.Flags], TH_FIN
jz .no_fin
DEBUGF 1,"Processing FIN\n" DEBUGF 1,"TCP_input: Processing FIN\n"
cmp [ebx + TCP_SOCKET.t_state], TCPS_CLOSE_WAIT cmp [ebx + TCP_SOCKET.t_state], TCPS_TIMED_WAIT
je .not_first_fin jae .not_first_fin
cmp [ebx + TCP_SOCKET.t_state], TCPS_CLOSING
je .not_first_fin
cmp [ebx + TCP_SOCKET.t_state], TCPS_FIN_WAIT_2
je .not_first_fin
DEBUGF 1,"First FIN for this connection\n" DEBUGF 1,"TCP_input: First FIN for this connection\n"
mov eax, ebx mov eax, ebx
call SOCKET_cant_recv_more call SOCKET_cant_recv_more
@ -1387,17 +1329,17 @@ align 4
jmp dword [eax + .FIN_sw_list] jmp dword [eax + .FIN_sw_list]
.FIN_sw_list: .FIN_sw_list:
dd .no_fin ;TCPS_CLOSED dd .no_fin ; TCPS_CLOSED
dd .no_fin ;TCPS_LISTEN dd .no_fin ; TCPS_LISTEN
dd .no_fin ;TCPS_SYN_SENT dd .no_fin ; TCPS_SYN_SENT
dd .fin_syn_est ;TCPS_SYN_RECEIVED dd .fin_syn_est ; TCPS_SYN_RECEIVED
dd .fin_syn_est ;TCPS_ESTABLISHED dd .fin_syn_est ; TCPS_ESTABLISHED
dd .no_fin ;TCPS_CLOSE_WAIT dd .no_fin ; TCPS_CLOSE_WAIT
dd .fin_wait1 ;TCPS_FIN_WAIT_1 dd .fin_wait1 ; TCPS_FIN_WAIT_1
dd .no_fin ;TCPS_CLOSING dd .no_fin ; TCPS_CLOSING
dd .no_fin ;TCPS_LAST_ACK dd .no_fin ; TCPS_LAST_ACK
dd .fin_wait2 ;TCPS_FIN_WAIT_2 dd .fin_wait2 ; TCPS_FIN_WAIT_2
dd .fin_timed ;TCPS_TIMED_WAIT dd .fin_timed ; TCPS_TIMED_WAIT
.fin_syn_est: .fin_syn_est:
@ -1427,34 +1369,41 @@ align 4
;----------------- ;-----------------
; Final processing ; Final processing
.final_processing: .final_processing:
DEBUGF 1,"Final processing\n" DEBUGF 1,"TCP_input: Final processing\n"
;;; if debug enabled, output packet cmp [ebx + TCP_SOCKET.sendalot], 0
jne .need_output
;test needoutput, needoutput
;jz .dumpit
test [ebx + TCP_SOCKET.t_flags], TF_ACKNOW test [ebx + TCP_SOCKET.t_flags], TF_ACKNOW
jz .dumpit jz .dumpit
DEBUGF 1,"ACK now!\n" DEBUGF 1,"TCP_input: ACK now!\n"
.need_output:
pusha
lea ecx, [ebx + SOCKET.mutex]
call mutex_unlock
popa
push ebx push ebx
mov eax, ebx mov eax, ebx
call TCP_output call TCP_output
pop ebx pop ebx
call kernel_free
add esp, 4
ret
.dumpit: .dumpit:
DEBUGF 1,"TCP_input: dumping\n"
pusha pusha
lea ecx, [ebx + SOCKET.mutex] lea ecx, [ebx + SOCKET.mutex]
call mutex_unlock call mutex_unlock
@ -1476,7 +1425,7 @@ align 4
align 4 align 4
.drop_after_ack: .drop_after_ack:
DEBUGF 1,"Drop after ACK\n" DEBUGF 1,"TCP_input: Drop after ACK\n"
test [edx + TCP_header.Flags], TH_RST test [edx + TCP_header.Flags], TH_RST
jnz .drop jnz .drop
@ -1512,7 +1461,7 @@ align 4
align 4 align 4
.drop_with_reset: .drop_with_reset:
DEBUGF 1,"Drop with reset\n" DEBUGF 1,"TCP_input: Drop with reset\n"
pusha pusha
lea ecx, [ebx + SOCKET.mutex] lea ecx, [ebx + SOCKET.mutex]
@ -1568,7 +1517,7 @@ align 4
.drop_not_locked: .drop_not_locked:
DEBUGF 1,"Dropping packet\n" DEBUGF 1,"TCP_input: Dropping packet\n"
;;;; If debugging options are enabled, output the packet somwhere ;;;; If debugging options are enabled, output the packet somwhere
@ -1585,7 +1534,7 @@ align 4
.drop_with_reset_no_socket: .drop_with_reset_no_socket:
DEBUGF 1,"Drop with reset (no socket)\n" DEBUGF 1,"TCP_input: Drop with reset (no socket)\n"
test [edx + TCP_header.Flags], TH_RST test [edx + TCP_header.Flags], TH_RST
jnz .drop_no_socket jnz .drop_no_socket
@ -1600,7 +1549,7 @@ align 4
.drop_no_socket: .drop_no_socket:
DEBUGF 1,"Drop (no socket)\n" DEBUGF 1,"TCP_input: Drop (no socket)\n"
call kernel_free call kernel_free
add esp, 4 add esp, 4

View File

@ -28,7 +28,15 @@ $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
pushf
cli
pusha
lea ecx, [eax + SOCKET.mutex]
call mutex_lock
popa
; 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
@ -255,7 +263,7 @@ TCP_output:
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,"TCP_output: 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
@ -264,12 +272,13 @@ TCP_output:
;---------------------------- ;----------------------------
; 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,"TCP_output: No reason to send a segment\n"
pusha pusha
lea ecx, [eax + SOCKET.mutex] lea ecx, [eax + SOCKET.mutex]
call mutex_unlock call mutex_unlock
popa popa
popf
ret ret
@ -293,7 +302,7 @@ TCP_output:
align 4 align 4
TCP_send: TCP_send:
DEBUGF 1,"TCP_send socket=%x length=%u flags=%x\n", eax, esi, dl DEBUGF 1,"TCP_send: socket=%x length=%u flags=%x\n", eax, esi, dl
push eax ; save socket ptr push eax ; save socket ptr
mov edi, sizeof.TCP_header ; edi will contain headersize mov edi, sizeof.TCP_header ; edi will contain headersize
@ -501,15 +510,13 @@ TCP_send:
;-------------------- ;--------------------
; Create the checksum ; Create the checksum
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
;---------------- ;----------------
; Send the packet ; Send the packet
DEBUGF 1,"Sending TCP Packet to device %x\n", ebx DEBUGF 1,"TCP_send: Sending with device %x\n", ebx
call [ebx + NET_DEVICE.transmit] call [ebx + NET_DEVICE.transmit]
jnz .send_error jnz .send_error
pop eax pop eax
@ -529,7 +536,8 @@ TCP_send:
; unlock socket ; unlock socket
lea ecx, [eax + SOCKET.mutex] lea ecx, [eax + SOCKET.mutex]
call mutex_unlock call mutex_unlock
DEBUGF 1,"TCP_output: success!\n" popf
DEBUGF 1,"TCP_send: success!\n"
xor eax, eax xor eax, eax
ret ret
@ -545,7 +553,8 @@ TCP_send:
; unlock socket ; unlock socket
lea ecx, [eax + SOCKET.mutex] lea ecx, [eax + SOCKET.mutex]
call mutex_unlock call mutex_unlock
DEBUGF 1,"TCP_output: IP error\n" popf
DEBUGF 1,"TCP_send: IP error\n"
or eax, -1 or eax, -1
ret ret
@ -555,7 +564,8 @@ TCP_send:
; unlock socket ; unlock socket
lea ecx, [eax + SOCKET.mutex] lea ecx, [eax + SOCKET.mutex]
call mutex_unlock call mutex_unlock
DEBUGF 1,"TCP_output: sending failed\n" popf
DEBUGF 1,"TCP_send: sending failed\n"
or eax, -2 or eax, -2
ret ret

View File

@ -140,7 +140,7 @@ TCP_pull_out_of_band:
align 4 align 4
TCP_drop: TCP_drop:
DEBUGF 1,"TCP_drop\n" DEBUGF 1,"TCP_drop: %x\n", eax
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
@ -201,7 +201,7 @@ TCP_close:
align 4 align 4
TCP_disconnect: TCP_disconnect:
DEBUGF 1,"TCP_disconnect socket=%x\n", eax DEBUGF 1,"TCP_disconnect: %x\n", eax
cmp [eax + TCP_SOCKET.t_state], TCPS_ESTABLISHED cmp [eax + TCP_SOCKET.t_state], TCPS_ESTABLISHED
jb TCP_close jb TCP_close
@ -227,7 +227,7 @@ TCP_disconnect:
align 4 align 4
TCP_usrclosed: TCP_usrclosed:
DEBUGF 1,"TCP_usrclosed socket=%x\n", eax DEBUGF 1,"TCP_usrclosed: %x\n", eax
push ebx push ebx
mov ebx, [eax + TCP_SOCKET.t_state] mov ebx, [eax + TCP_SOCKET.t_state]
@ -287,7 +287,7 @@ 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
@ -323,7 +323,7 @@ TCP_outflags:
align 4 align 4
TCP_respond_socket: TCP_respond_socket:
DEBUGF 1,"TCP_respond_socket\n" DEBUGF 1,"TCP_respond_socket: socket=%x flags=%x\n", ebx, cl
;--------------------- ;---------------------
; Create the IP packet ; Create the IP packet
@ -382,8 +382,8 @@ TCP_respond_socket:
ret ret
.error: .error:
DEBUGF 1,"TCP_respond failed\n" DEBUGF 1,"TCP_respond_socket: failed\n"
add esp, 2+4 add esp, 2 + 4
ret ret
@ -404,7 +404,7 @@ TCP_respond_socket:
align 4 align 4
TCP_respond_segment: TCP_respond_segment:
DEBUGF 1,"TCP_respond_segment\n" DEBUGF 1,"TCP_respond_segment: frame=%x flags=%c\n", edx, cl
;--------------------- ;---------------------
; Create the IP packet ; Create the IP packet
@ -461,7 +461,7 @@ TCP_respond_segment:
ret ret
.error: .error:
DEBUGF 1,"TCP_respond failed\n" DEBUGF 1,"TCP_respond_segment: failed\n"
add esp, 2+4 add esp, 2+4
ret ret

View File

@ -116,7 +116,7 @@ macro UDP_checksum IP1, IP2 { ; esi = ptr to udp packet, ecx = packet size
align 4 align 4
UDP_input: UDP_input:
DEBUGF 1,"UDP_input, size:%u\n", ecx DEBUGF 1,"UDP_input: size=%u\n", ecx
; First validate, checksum ; First validate, checksum
@ -129,7 +129,7 @@ UDP_input:
jnz .checksum_mismatch jnz .checksum_mismatch
.no_checksum: .no_checksum:
DEBUGF 1,"UDP Checksum is correct\n" DEBUGF 1,"UDP_input: checksum ok\n"
; Convert port numbers to intel format ; Convert port numbers to intel format
@ -160,7 +160,7 @@ UDP_input:
cmp [eax + UDP_SOCKET.LocalPort], dx cmp [eax + UDP_SOCKET.LocalPort], dx
jne .next_socket jne .next_socket
DEBUGF 1,"using socket: %x\n", eax DEBUGF 1,"UDP_input: socket=%x\n", eax
;;; TODO: when packet is processed, check more sockets! ;;; TODO: when packet is processed, check more sockets!
@ -184,8 +184,8 @@ UDP_input:
popa popa
.updatesock: .updatesock:
inc [UDP_PACKETS_RX] inc [UDP_PACKETS_RX] ; Fixme: correct interface?
DEBUGF 1,"Found valid UDP packet for socket %x\n", eax
movzx ecx, [esi + UDP_header.Length] movzx ecx, [esi + UDP_header.Length]
sub ecx, sizeof.UDP_header sub ecx, sizeof.UDP_header
add esi, sizeof.UDP_header add esi, sizeof.UDP_header
@ -198,7 +198,7 @@ UDP_input:
call mutex_lock call mutex_lock
popa popa
DEBUGF 1,"Changing remote port to: %u\n", cx DEBUGF 1,"UDP_input: new remote port=%u\n", cx
mov [eax + UDP_SOCKET.RemotePort], cx mov [eax + UDP_SOCKET.RemotePort], cx
inc [eax + UDP_SOCKET.firstpacket] inc [eax + UDP_SOCKET.firstpacket]
@ -206,13 +206,12 @@ UDP_input:
.checksum_mismatch: .checksum_mismatch:
DEBUGF 2,"UDP_input: checksum mismatch\n"
DEBUGF 2,"UDP_Handler - checksum mismatch\n"
.dump: .dump:
call kernel_free call kernel_free
add esp, 4 ; pop (balance stack) add esp, 4 ; pop (balance stack)
DEBUGF 2,"UDP_Handler - dumping\n" DEBUGF 2,"UDP_input: dumping\n"
ret ret
@ -232,14 +231,14 @@ UDP_input:
align 4 align 4
UDP_output: UDP_output:
DEBUGF 1,"UDP_output: socket:%x, bytes: %u, data ptr: %x\n", eax, ecx, esi DEBUGF 1,"UDP_output: socket=%x bytes=%u data_ptr=%x\n", eax, ecx, esi
mov dx, [eax + UDP_SOCKET.RemotePort] mov dx, [eax + UDP_SOCKET.RemotePort]
DEBUGF 1,"UDP_output: remote port: %u, ", dx DEBUGF 1,"UDP_output: remote port=%u, ", dx
rol dx, 8 rol dx, 8
rol edx, 16 rol edx, 16
mov dx, [eax + UDP_SOCKET.LocalPort] mov dx, [eax + UDP_SOCKET.LocalPort]
DEBUGF 1,"local port: %u\n", dx DEBUGF 1,"local port=%u\n", dx
rol dx, 8 rol dx, 8
sub esp, 8 ; Data ptr and data size will be placed here sub esp, 8 ; Data ptr and data size will be placed here
@ -277,8 +276,7 @@ UDP_output:
inc [UDP_PACKETS_TX] ; FIXME: correct device? inc [UDP_PACKETS_TX] ; FIXME: correct device?
DEBUGF 1,"UDP_output: sending to device %x\n", ebx DEBUGF 1,"UDP_output: sending with device %x\n", ebx
call [ebx + NET_DEVICE.transmit] call [ebx + NET_DEVICE.transmit]
ret ret