From 83c26b2500addbbe555b10903158172965097a9c Mon Sep 17 00:00:00 2001 From: hidnplayr Date: Thu, 26 Jul 2012 23:21:35 +0000 Subject: [PATCH] Better debug info for network, lots of improvements in TCP code git-svn-id: svn://kolibrios.org@2891 a494cfbc-eb01-0410-851d-a64ba20cac60 --- kernel/branches/net/network/ARP.inc | 52 ++- kernel/branches/net/network/IPv4.inc | 50 +-- kernel/branches/net/network/ethernet.inc | 13 +- kernel/branches/net/network/icmp.inc | 16 +- kernel/branches/net/network/socket.inc | 63 ++-- kernel/branches/net/network/stack.inc | 10 +- kernel/branches/net/network/tcp_input.inc | 361 +++++++++------------ kernel/branches/net/network/tcp_output.inc | 30 +- kernel/branches/net/network/tcp_subr.inc | 18 +- kernel/branches/net/network/udp.inc | 26 +- 10 files changed, 303 insertions(+), 336 deletions(-) diff --git a/kernel/branches/net/network/ARP.inc b/kernel/branches/net/network/ARP.inc index 56b62b606b..f9378c1be5 100644 --- a/kernel/branches/net/network/ARP.inc +++ b/kernel/branches/net/network/ARP.inc @@ -163,7 +163,6 @@ local .exit align 4 ARP_input: - DEBUGF 1,"ARP_input - start\n" cmp ecx, sizeof.ARP_header jb .exit @@ -173,9 +172,9 @@ ARP_input: cmp [edx + ARP_header.Opcode], ARP_REP_OPCODE jne .maybe_request - DEBUGF 1,"ARP_input - it's a reply packet from %u.%u.%u.%u\n",\ - [edx + ARP_header.SenderIP]:1, [edx + ARP_header.SenderIP+1]:1,\ - [edx + ARP_header.SenderIP+2]:1, [edx + ARP_header.SenderIP+3]:1 + 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 + 2]:1, [edx + ARP_header.SenderIP + 3]:1 mov ecx, [NumARP] test ecx, ecx @@ -194,20 +193,20 @@ ARP_input: jmp .exit .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 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.TTL], ARP_ENTRY_TTL 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 word [esi+ARP_entry.MAC+4], cx + mov word [esi + ARP_entry.MAC + 4], cx jmp .exit @@ -222,10 +221,10 @@ ARP_input: call NET_ptr_to_num cmp edi, -1 jz .exit - DEBUGF 1,"ARP Request packet through device: %u\n", edi - inc [ARP_PACKETS_RX+4*edi] + DEBUGF 1,"ARP_input: got request packet through device: %u\n", 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? jne .exit @@ -264,7 +263,7 @@ ARP_input: ; mov ax , ETHER_ARP ; It's already there, I'm sure of it! ; stosw - DEBUGF 1,"ARP_input - Sending reply \n" + DEBUGF 1,"ARP_input: Sending reply\n" call [ebx + NET_DEVICE.transmit] ret @@ -273,7 +272,7 @@ ARP_input: call kernel_free add esp, 4 ; pop (balance stack) - DEBUGF 1,"ARP_input - exiting\n" + DEBUGF 1,"ARP_input: exiting\n" ret @@ -289,12 +288,13 @@ ARP_input: align 4 ARP_output_request: - DEBUGF 1,"Create ARP Packet\n" - 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 mov edx, ETH_BROADCAST ; broadcast mac @@ -325,15 +325,15 @@ ARP_output_request: pop eax ; DestIP stosd ; - DEBUGF 1,"ARP Packet for device %x created successfully\n", ebx + DEBUGF 1,"ARP_output_request: device=%x\n", ebx push edx ecx call [ebx + NET_DEVICE.transmit] ret .exit: - add esp, 4+4 - DEBUGF 1,"Create ARP Packet - failed\n" + add esp, 4 + 4 + DEBUGF 1,"ARP_output_request: failed\n" sub eax, eax ret @@ -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,14 +392,12 @@ ARP_add_entry: lea esi, [edi - sizeof.ARP_entry] inc [NumARP] pop eax - DEBUGF 1,"entry %u created\n", eax + DEBUGF 1,"entry=%u\n", eax - .exit: - DEBUGF 1,"exiting\n" ret .error: - DEBUGF 1,"error!\n" + DEBUGF 1,"failed\n" mov eax, -1 ret @@ -415,7 +413,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: entry=%u entrys=%u\n", esi, [NumARP] mov ecx, ARP_table + (ARP_TABLE_SIZE - 1) * sizeof.ARP_entry sub ecx, esi @@ -426,7 +424,7 @@ ARP_del_entry: rep movsw dec [NumARP] - DEBUGF 1,"ARP_del_entry: done!\n" + DEBUGF 1,"ARP_del_entry: success\n" ret diff --git a/kernel/branches/net/network/IPv4.inc b/kernel/branches/net/network/IPv4.inc index 2bb2aa8eed..e37cbcc9e8 100644 --- a/kernel/branches/net/network/IPv4.inc +++ b/kernel/branches/net/network/IPv4.inc @@ -219,7 +219,7 @@ IPv4_input: ; TODO: add IPv4 IPv4_checksum edx 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 @@ -257,7 +257,7 @@ IPv4_input: ; TODO: add IPv4 ; 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 ;------------------------ @@ -301,11 +301,11 @@ IPv4_input: ; TODO: add IPv4 cmp al, IP_PROTO_ICMP je ICMP_input - DEBUGF 2,"IPv4_input - unknown protocol: %u\n", al + DEBUGF 2,"IPv4_input: unknown protocol %u\n", al .dump: - DEBUGF 2,"IPv4_input - dumping\n" -; inc [dumped_rx_count] + DEBUGF 2,"IPv4_input: dumping\n" +; inc [dumped_rx_count] ;;; TODO call kernel_free add esp, 4 ; pop (balance stack) ret @@ -320,7 +320,7 @@ IPv4_input: ; TODO: add IPv4 xchg al , ah 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? 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 - DEBUGF 1,"Middle fragmented packet received!\n" + DEBUGF 1,"IPv4_input: Middle fragment packet received!\n" call IPv4_find_fragment_slot cmp esi, -1 @@ -362,7 +362,7 @@ IPv4_input: ; TODO: add IPv4 ; We have received the 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.. mov ecx, MAX_FRAGMENTS mov esi, FRAGMENT_LIST @@ -396,7 +396,7 @@ IPv4_input: ; TODO: add IPv4 ; We have received the 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 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!) mov cx, [esi + sizeof.FRAGMENT_entry + IPv4_header.TotalLength] ; Add total length xchg cl, ch - DEBUGF 1,"Packet size: %u\n", cx + DEBUGF 1,"IPv4_input: Packet size=%u\n", cx add ax, cx movzx cx, [esi + sizeof.FRAGMENT_entry + IPv4_header.VersionAndIHL] ; Sub Header length and cx, 0x000F shl cx, 2 - DEBUGF 1,"Header size: %u\n", cx + DEBUGF 1,"IPv4_input: Header size=%u\n", cx sub ax, cx mov edi, esi 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 xchg cl , ch - DEBUGF 1,"Packet size: %u\n", cx + DEBUGF 1,"IPv4_input: Packet size=%u\n", 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 mov ax , [edx + IPv4_header.FlagsAndFragmentOffset] @@ -442,7 +442,7 @@ IPv4_input: ; TODO: add IPv4 shl ax , 3 add cx , ax pop eax - DEBUGF 1,"Total Fragment size: %u\n", ecx + DEBUGF 1,"IPv4_input: Total Fragment size=%u\n", ecx cmp ax, cx 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 xchg cl , ch ; intel byte order 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 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: add esp, 4 .destroy_slot: - DEBUGF 1,"Destroy fragment slot!\n" + DEBUGF 1,"IPv4_input: Destroy fragment slot!\n" ; TODO! jmp .dump @@ -613,7 +613,7 @@ IPv4_output: IPv4_checksum edi add edi, sizeof.IPv4_header - DEBUGF 1,"IPv4 Packet for device %x created successfully\n", ebx + DEBUGF 1,"IPv4_output: success!\n" ret .eth_error: @@ -623,13 +623,13 @@ IPv4_output: ret .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 xor edi, edi ret .too_large: - DEBUGF 1,"IPv4_output: error: Packet too large!\n" + DEBUGF 1,"IPv4_output: Packet too large!\n" xor edi, edi ret @@ -706,7 +706,7 @@ IPv4_output_raw: IPv4_checksum edi ;;;; todo: checksum for IP packet with options! 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] ret @@ -763,7 +763,7 @@ IPv4_fragment: push dword 0 ; offset .new_fragment: - DEBUGF 1,"Ipv4_fragment - new_fragmentn" + DEBUGF 1,"Ipv4_fragment: new fragment" mov eax, [esp + 3*4] @@ -785,7 +785,7 @@ IPv4_fragment: add esi, [esp] ; offset 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 ; now, correct header @@ -822,7 +822,7 @@ IPv4_fragment: sub ecx, [esp+2*4] ; ptr to ip header 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] jae .new_fragment @@ -831,11 +831,11 @@ IPv4_fragment: jmp .new_fragment .err: - DEBUGF 1,"Ipv4_fragment - failed\n" + DEBUGF 1,"Ipv4_fragment: failed\n" .done: add esp, 12 + 4 + 6 .err2: - DEBUGF 1,"Ipv4_fragment - dumping\n" + DEBUGF 1,"Ipv4_fragment: dumping\n" call kernel_free add esp, 4 diff --git a/kernel/branches/net/network/ethernet.inc b/kernel/branches/net/network/ethernet.inc index 40e3d342c1..9602e04b16 100644 --- a/kernel/branches/net/network/ethernet.inc +++ b/kernel/branches/net/network/ethernet.inc @@ -63,7 +63,7 @@ ETH_input: mov eax, [esp] 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 jb .dump sub ecx, sizeof.ETH_header @@ -86,10 +86,10 @@ ETH_input: ; cmp ax, ETHER_PPP_SESSION ; je PPPoE_session_input - DEBUGF 2,"Unknown ethernet packet type %x\n", ax + DEBUGF 2,"ETH_input: Unknown packet type=%x\n", ax .dump: - DEBUGF 2,"ETH_input - dumping\n" + DEBUGF 2,"ETH_input: dumping\n" call kernel_free add esp, 4 ret @@ -114,7 +114,7 @@ ETH_input: align 4 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] ja .exit @@ -144,7 +144,7 @@ ETH_output: cmp edx, ETH_FRAME_MINIMUM jbe .adjust_size .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 .adjust_size: @@ -153,7 +153,7 @@ ETH_output: jmp .done .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 sub edi, edi ret @@ -203,7 +203,6 @@ ETH_api: .number = ($ - .table) / 4 - 1 .error: - DEBUGF 2,"Device is not ethernet type\n" or eax, -1 ret diff --git a/kernel/branches/net/network/icmp.inc b/kernel/branches/net/network/icmp.inc index e21bec5105..a1b3d37417 100644 --- a/kernel/branches/net/network/icmp.inc +++ b/kernel/branches/net/network/icmp.inc @@ -142,7 +142,7 @@ macro ICMP_init { align 4 ICMP_input: - DEBUGF 1,"ICMP_input - start\n" + DEBUGF 1,"ICMP_input:\n" ; 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 ; 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 ; Update stats (and validate device ptr) call NET_ptr_to_num cmp edi,-1 je .dump - inc [ICMP_PACKETS_RX+4*edi] - inc [ICMP_PACKETS_TX+4*edi] + inc [ICMP_PACKETS_RX + 4*edi] + inc [ICMP_PACKETS_TX + 4*edi] ; exchange dest and source address in IP header ; exchange dest and source MAC in ETH header @@ -252,7 +252,7 @@ ICMP_input: ; je .dump ; inc [ICMP_PACKETS_RX+edi] - DEBUGF 1,"Found valid ICMP packet for socket %x\n", eax + DEBUGF 1,"socket=%x\n", eax pusha lea ecx, [eax + SOCKET.mutex] @@ -264,10 +264,10 @@ ICMP_input: .checksum_mismatch: - DEBUGF 1,"ICMP_Handler - checksum mismatch\n" + DEBUGF 1,"checksum mismatch\n" .dump: - DEBUGF 1,"ICMP_Handler - dumping\n" + DEBUGF 1,"ICMP_input: dumping\n" call kernel_free add esp, 4 ; pop (balance stack) @@ -332,7 +332,7 @@ ICMP_output: ret .exit: DEBUGF 1,"Creating ICMP Packet failed\n" - add esp,2*4+2 + add esp, 2*4 + 2 ret diff --git a/kernel/branches/net/network/socket.inc b/kernel/branches/net/network/socket.inc index a796825cef..f26f467fac 100644 --- a/kernel/branches/net/network/socket.inc +++ b/kernel/branches/net/network/socket.inc @@ -132,7 +132,7 @@ struct TCP_SOCKET IP_SOCKET ; extra - sendalot db ? + sendalot db ? ; also used as 'need output' ends @@ -272,7 +272,7 @@ s_error: align 4 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 call SOCKET_alloc @@ -361,7 +361,7 @@ align 4 align 4 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 jz s_error @@ -385,8 +385,6 @@ SOCKET_bind: .af_inet4: - DEBUGF 1,"af_inet4\n" - cmp esi, 6 jb s_error @@ -413,7 +411,7 @@ SOCKET_bind: call SOCKET_check_port 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 + 2]:1,[eax + IP_SOCKET.LocalIP + 3]:1 @@ -436,7 +434,7 @@ SOCKET_bind: align 4 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 jz s_error @@ -583,7 +581,7 @@ align 4 align 4 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 jz s_error @@ -635,7 +633,7 @@ SOCKET_listen: align 4 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 jz s_error @@ -674,7 +672,7 @@ SOCKET_accept: align 4 SOCKET_close: - DEBUGF 1,"SOCKET_close: socknum: %u\n", ecx + DEBUGF 1,"SOCKET_close: %u\n", ecx call SOCKET_num_to_ptr jz s_error @@ -701,6 +699,7 @@ SOCKET_close: jb .free call TCP_usrclosed + call TCP_output ;;;; Fixme: is this nescessary?? mov dword [esp+32], 0 ret @@ -726,7 +725,7 @@ SOCKET_close: align 4 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 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 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 ja .too_small 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] - 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 ; copy the data @@ -774,7 +773,7 @@ SOCKET_receive_dgram: .too_small: - DEBUGF 1,"Buffer too small...\n" + DEBUGF 1,"SOCKET_receive: Buffer too small\n" jmp s_error align 4 @@ -808,7 +807,7 @@ SOCKET_receive_tcp: align 4 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 jz s_error @@ -850,7 +849,7 @@ SOCKET_send_tcp: align 4 SOCKET_send_ip: - DEBUGF 1,"type: IP\n" + DEBUGF 1,"SOCKET_send: IPv4\n" mov [esp+32], ecx call IPv4_output_raw @@ -966,7 +965,7 @@ SOCKET_set_opt: jz s_error 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! ret @@ -993,7 +992,7 @@ SOCKET_set_opt: align 4 SOCKET_debug: - DEBUGF 1,"socket_debug\n" + DEBUGF 1,"SOCKET_debug\n" call SOCKET_num_to_ptr jz s_error @@ -1084,7 +1083,7 @@ SOCKET_find_port: align 4 SOCKET_check_port: - DEBUGF 1,"SOCKET_check_port\n" + DEBUGF 1,"SOCKET_check_port: " mov ecx, [eax + SOCKET.Protocol] mov edx, [eax + IP_SOCKET.LocalIP] @@ -1108,6 +1107,7 @@ SOCKET_check_port: ret .port_ok: + DEBUGF 1,"local port %u is free\n", bx mov [eax + UDP_SOCKET.LocalPort], bx or bx, bx ; set the zero-flag @@ -1636,7 +1636,7 @@ SOCKET_fork: align 4 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 @@ -1649,8 +1649,11 @@ SOCKET_num_to_ptr: test eax, eax - DEBUGF 1,"(%x)\n", eax + DEBUGF 1,"ptr=%x\n", eax + ret + .error: + DEBUGF 1,"not found\n", eax ret @@ -1668,16 +1671,18 @@ SOCKET_num_to_ptr: align 4 SOCKET_ptr_to_num: - DEBUGF 1,"SOCKET_ptr_to_num: %x ", eax + DEBUGF 1,"SOCKET_ptr_to_num: ptr=%x ", eax call SOCKET_check jz .error mov eax, [eax + SOCKET.Number] - DEBUGF 1,"(%u)\n", eax + DEBUGF 1,"num=%u\n", eax + ret .error: + DEBUGF 1,"not found\n", eax ret @@ -1771,7 +1776,7 @@ SOCKET_process_end: cmp [ebx + SOCKET.PID], edx 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 @@ -1812,6 +1817,7 @@ SOCKET_process_end: align 4 SOCKET_is_connecting: + DEBUGF 1,"SOCKET_is_connecting: %x\n", eax and [eax + SOCKET.options], not (SS_ISCONNECTED + SS_ISDISCONNECTING + SS_ISCONFIRMING) or [eax + SOCKET.options], SS_ISCONNECTING @@ -1832,6 +1838,7 @@ SOCKET_is_connecting: align 4 SOCKET_is_connected: + DEBUGF 1,"SOCKET_is_connected: %x\n", eax and [eax + SOCKET.options], not (SS_ISCONNECTING + SS_ISDISCONNECTING + SS_ISCONFIRMING) or [eax + SOCKET.options], SS_ISCONNECTED @@ -1853,6 +1860,8 @@ SOCKET_is_connected: align 4 SOCKET_is_disconnecting: + DEBUGF 1,"SOCKET_is_disconnecting: %x\n", eax + and [eax + SOCKET.options], not (SS_ISCONNECTING) or [eax + SOCKET.options], SS_ISDISCONNECTING + SS_CANTRCVMORE + SS_CANTSENDMORE @@ -1872,6 +1881,8 @@ SOCKET_is_disconnecting: align 4 SOCKET_is_disconnected: + DEBUGF 1,"SOCKET_is_disconnected: %x\n", eax + and [eax + SOCKET.options], not (SS_ISCONNECTING + SS_ISCONNECTED + SS_ISDISCONNECTING) or [eax + SOCKET.options], SS_CANTRCVMORE + SS_CANTSENDMORE @@ -1890,6 +1901,8 @@ SOCKET_is_disconnected: align 4 SOCKET_cant_recv_more: + DEBUGF 1,"SOCKET_cant_recv_more: %x\n", eax + or [eax + SOCKET.options], SS_CANTRCVMORE ret @@ -1908,6 +1921,8 @@ SOCKET_cant_recv_more: align 4 SOCKET_cant_send_more: + DEBUGF 1,"SOCKET_cant_send_more: %x\n", eax + or [eax + SOCKET.options], SS_CANTSENDMORE ret \ No newline at end of file diff --git a/kernel/branches/net/network/stack.inc b/kernel/branches/net/network/stack.inc index 95e19e2593..dfee0577f7 100644 --- a/kernel/branches/net/network/stack.inc +++ b/kernel/branches/net/network/stack.inc @@ -346,7 +346,7 @@ NET_add_device: align 4 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 jae .error @@ -356,12 +356,12 @@ NET_set_default: mov [NET_DEFAULT], eax - DEBUGF 1,"Device number %u is now default!\n", eax + DEBUGF 1,"NET_set_default: succes\n" ret .error: or eax, -1 - DEBUGF 2,"Setting default network device failed\n" + DEBUGF 1,"NET_set_default: failed\n" ret @@ -371,7 +371,7 @@ NET_set_default: ; ; This function is called by etwork drivers, ; to unregister network devices from the kernel -; d +; ; IN: Pointer to device structure in ebx ; OUT: eax: -1 on error ; @@ -664,7 +664,6 @@ sys_network: ; FIXME: make default device easily accessible jmp .return .doesnt_exist: - DEBUGF 1,"sys_network: invalid device/function specified!\n" mov eax, -1 .return: @@ -717,7 +716,6 @@ sys_protocols: add esp, 4 ; if we reached here, no function was called, so we need to balance stack .doesnt_exist: - DEBUGF 1,"sys_protocols: protocol %u doesnt exist on device %u!\n", ax, bh mov eax, -1 .return: diff --git a/kernel/branches/net/network/tcp_input.inc b/kernel/branches/net/network/tcp_input.inc index ee41418f52..9548d6317f 100644 --- a/kernel/branches/net/network/tcp_input.inc +++ b/kernel/branches/net/network/tcp_input.inc @@ -34,7 +34,7 @@ $Revision$ align 4 TCP_input: - DEBUGF 1,"TCP_input size=%u\n", ecx + DEBUGF 1,"TCP_input: size=%u\n", ecx ; First, re-calculate the checksum @@ -47,7 +47,7 @@ TCP_input: pop edx ecx 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) shr [edx + TCP_header.DataOffset], 2 @@ -57,7 +57,7 @@ TCP_input: movzx eax, [edx + TCP_header.DataOffset] 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 - 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) @@ -76,7 +76,7 @@ TCP_input: cmp dword [edx + sizeof.TCP_header], 0x0101080a ; Timestamp header jne .no_timestamp - DEBUGF 1,"timestamp ok\n" + DEBUGF 1,"TCP_input: timestamp ok\n" ; TODO: Parse the option ; TODO: Set a Bit in the TCP to tell all options are parsed @@ -131,7 +131,7 @@ TCP_input: test ax, ax jnz .socket_loop .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 inc [TCP_segments_rx] ; FIXME: correct interface? @@ -146,11 +146,19 @@ TCP_input: ; Lock the socket pusha + pushf + cli lea ecx, [ebx + SOCKET.mutex] call mutex_lock + popf 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 @@ -168,7 +176,7 @@ TCP_input: test [ebx + SOCKET.options], SO_ACCEPTCON jz .no_listening_socket - DEBUGF 1,"Accepting new connection\n" + DEBUGF 1,"TCP_input: Accepting new connection\n" pusha lea ecx, [ebx + SOCKET.mutex] @@ -208,7 +216,7 @@ TCP_input: cmp eax, sizeof.TCP_header ; Does header contain any 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 jz .not_uni_xfer ; also no header prediction @@ -250,7 +258,7 @@ TCP_input: movzx eax, word[esi+2] rol ax, 8 - DEBUGF 1,"Maxseg: %u\n", ax + DEBUGF 1,"TCP_input: Maxseg=%u\n", ax mov [ebx + TCP_SOCKET.t_maxseg], eax @@ -266,7 +274,7 @@ TCP_input: test [edx + TCP_header.Flags], TH_SYN 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 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: - - - - - ;----------------------------------------------------------------------- ; Time to do some header prediction (Original Principle by Van Jacobson) @@ -352,7 +355,7 @@ TCP_input: sub eax, [ebx + TCP_SOCKET.SND_UNA] 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 @@ -408,7 +411,7 @@ TCP_input: ; 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 @@ -434,7 +437,7 @@ TCP_input: .not_uni_xfer: - DEBUGF 1,"Header prediction failed\n" + DEBUGF 1,"TCP_input: Header prediction failed\n" ; Calculate receive window size @@ -464,7 +467,7 @@ TCP_input: align 4 .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 jnz .drop @@ -525,7 +528,7 @@ align 4 align 4 .SYN_SENT: - DEBUGF 1,"TCP state: syn_sent\n" + DEBUGF 1,"TCP_input: state=syn_sent\n" test [edx + TCP_header.Flags], TH_ACK jz @f @@ -586,7 +589,7 @@ align 4 test [edx + TCP_header.Flags], TH_ACK jz .simultaneous_open - DEBUGF 1,"TCP: active open\n" + DEBUGF 1,"TCP_input: active open\n" ;;; TODO: update stats @@ -603,7 +606,7 @@ align 4 .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.. mov [ebx + TCP_SOCKET.t_state], TCPS_SYN_RECEIVED @@ -638,7 +641,7 @@ align 4 .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 @@ -667,7 +670,7 @@ align 4 sub eax, [edx + TCP_header.SequenceNumber] 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 jz .no_dup_syn @@ -694,27 +697,29 @@ align 4 cmp eax, ecx 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 ; Check for duplicate FIN test [edx + TCP_header.Flags], TH_FIN - jz @f + jz .no_fin2 inc ecx cmp eax, ecx - dec ecx jne @f mov eax, ecx and [edx + TCP_header.Flags], not TH_FIN or [ebx + TCP_SOCKET.t_flags], TF_ACKNOW + dec ecx jmp .no_duplicate - @@: + @@: + dec ecx + .no_fin2: ; 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 @@ -729,7 +734,7 @@ align 4 .duplicate: - DEBUGF 1,"Duplicate received\n" + DEBUGF 1,"TCP_input: Duplicate received\n" ;---------------------------------------- ; Update statistics for duplicate packets @@ -744,8 +749,7 @@ align 4 ; Remove duplicate data and update urgent offset add [edx + TCP_header.SequenceNumber], eax - -;;; TODO + sub ecx, eax ;;;;;;;; Checkme sub [edx + TCP_header.UrgentPointer], ax ja @f @@ -795,60 +799,50 @@ align 4 .no_excess_data: - - - - - - - ;----------------- ; Record timestamp ;;; TODO 737-746 - - - ;------------------ ; Process RST flags 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] shl eax, 2 jmp dword [eax + .rst_sw_list] .rst_sw_list: - dd .rst_skip ;TCPS_CLOSED - dd .rst_skip ;TCPS_LISTEN - dd .rst_skip ;TCPS_SYN_SENT - dd .econnrefused ;TCPS_SYN_RECEIVED - dd .econnreset ;TCPS_ESTABLISHED - dd .econnreset ;TCPS_CLOSE_WAIT - dd .econnreset ;TCPS_FIN_WAIT_1 - dd .rst_close ;TCPS_CLOSING - dd .rst_close ;TCPS_LAST_ACK - dd .econnreset ;TCPS_FIN_WAIT_2 - dd .rst_close ;TCPS_TIMED_WAIT + dd .no_rst ; TCPS_CLOSED + dd .no_rst ; TCPS_LISTEN + dd .no_rst ; TCPS_SYN_SENT + dd .econnrefused ; TCPS_SYN_RECEIVED + dd .econnreset ; TCPS_ESTABLISHED + dd .econnreset ; TCPS_CLOSE_WAIT + dd .econnreset ; TCPS_FIN_WAIT_1 + dd .rst_close ; TCPS_CLOSING + dd .rst_close ; TCPS_LAST_ACK + dd .econnreset ; TCPS_FIN_WAIT_2 + dd .rst_close ; TCPS_TIMED_WAIT .econnrefused: - DEBUGF 1,"Connection refused\n" + DEBUGF 1,"TCP_input: Connection refused\n" mov [ebx + SOCKET.errorcode], ECONNREFUSED jmp .close .econnreset: - DEBUGF 1,"Connection reset\n" + DEBUGF 1,"TCP_input: Connection reset\n" mov [ebx + SOCKET.errorcode], ECONNRESET .close: - DEBUGF 1,"Closing connection\n" + DEBUGF 1,"TCP_input: Closing connection\n" mov [ebx + TCP_SOCKET.t_state], TCPS_CLOSED ;;; TODO: update stats (tcp drops) @@ -857,19 +851,13 @@ align 4 jmp .drop .rst_close: - DEBUGF 1,"Closing with reset\n" + DEBUGF 1,"TCP_input: Closing with reset\n" mov eax, ebx call TCP_close jmp .drop - - - - - - - .rst_skip: + .no_rst: ;-------------------------------------- @@ -882,24 +870,18 @@ align 4 mov ebx, ECONNRESET call TCP_drop jmp .drop_with_reset - - test [edx + TCP_header.Flags], TH_ACK - jz .drop @@: - - - - - - ;--------------- ; ACK processing + test [edx + TCP_header.Flags], TH_ACK + jz .drop + cmp [ebx + TCP_SOCKET.t_state], TCPS_SYN_RECEIVED 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] cmp [ebx + TCP_SOCKET.SND_UNA], eax @@ -924,12 +906,11 @@ align 4 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] dec eax mov [ebx + TCP_SOCKET.SND_WL1], eax - jmp .not_dup_ack .no_syn_rcv: @@ -946,7 +927,7 @@ align 4 cmp eax, [ebx + TCP_SOCKET.SND_WND] 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 ja @f @@ -1011,7 +992,7 @@ align 4 .no_re_xmit: 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] add [ebx + TCP_SOCKET.SND_CWND], eax @@ -1022,10 +1003,6 @@ align 4 jmp .drop - - - - .not_dup_ack: ;------------------------------------------------- @@ -1057,12 +1034,7 @@ align 4 ;;; 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 @@ -1075,13 +1047,9 @@ align 4 cmp eax, [edx + TCP_header.AckNumber] je .all_outstanding mov [ebx + TCP_SOCKET.timer_retransmission], 120 ;;;; TODO: correct this value (use a macro for it) + .all_outstanding: - - - - - - + inc [ebx + TCP_SOCKET.sendalot] ; need output ;------------------------------------------- ; Open congestion window in response to ACKs @@ -1113,15 +1081,26 @@ align 4 cmova esi, eax mov [ebx + TCP_SOCKET.SND_CWND], esi - - - - - - ;------------------------------------------ ; 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 mov ecx, edi lea eax, [ebx + STREAM_SOCKET.snd] @@ -1130,8 +1109,15 @@ align 4 sub [ebx + TCP_SOCKET.SND_WND], ecx pop edx ecx + DEBUGF 1,"TCP_input: our FIN is not acked\n" + clc + +;---------------------------------------- ; Wake up process waiting on send buffer + .wakeup: + + pushf mov eax, ebx call SOCKET_notify_owner @@ -1139,17 +1125,12 @@ align 4 mov eax, [edx + TCP_header.AckNumber] mov [ebx + TCP_SOCKET.SND_UNA], eax - cmp eax, [ebx + TCP_SOCKET.SND_NXT] jb @f mov [ebx + TCP_SOCKET.SND_NXT], eax @@: - - ;; TODO: use zero flag as 'ourfinisacked' - - - + popf ; General ACK handling complete ; Now do the state-specific ones @@ -1158,27 +1139,27 @@ align 4 jmp dword [eax*4 + .ACK_sw_list] .ACK_sw_list: - dd .ack_processed ;TCPS_CLOSED - dd .ack_processed ;TCPS_LISTEN - dd .ack_processed ;TCPS_SYN_SENT - dd .ack_processed ;TCPS_SYN_RECEIVED - dd .ack_processed ;TCPS_ESTABLISHED - dd .ack_processed ;TCPS_CLOSE_WAIT - dd .ack_fw1 ;TCPS_FIN_WAIT_1 - dd .ack_c ;TCPS_CLOSING - dd .ack_la ;TCPS_LAST_ACK - dd .ack_processed ;TCPS_FIN_WAIT_2 - dd .ack_tw ;TCPS_TIMED_WAIT + dd .ack_processed ; TCPS_CLOSED + dd .ack_processed ; TCPS_LISTEN + dd .ack_processed ; TCPS_SYN_SENT + dd .ack_processed ; TCPS_SYN_RECEIVED + dd .ack_processed ; TCPS_ESTABLISHED + dd .ack_processed ; TCPS_CLOSE_WAIT + dd .ack_fw1 ; TCPS_FIN_WAIT_1 + dd .ack_c ; TCPS_CLOSING + dd .ack_la ; TCPS_LAST_ACK + dd .ack_processed ; TCPS_FIN_WAIT_2 + dd .ack_tw ; TCPS_TIMED_WAIT .ack_fw1: - jz .ack_processed + jnc .ack_processed test [ebx + SOCKET.state], SS_CANTRCVMORE jnz @f mov eax, ebx 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 @@ -1186,7 +1167,7 @@ align 4 .ack_c: - jz .ack_processed + jnc .ack_processed mov [ebx + TCP_SOCKET.t_state], TCPS_TIMED_WAIT mov eax, ebx @@ -1198,7 +1179,7 @@ align 4 .ack_la: - jz .ack_processed + jnc .ack_processed mov eax, ebx @@ -1212,17 +1193,13 @@ align 4 - - - - .reset_dupacks: ; We got a new ACK, reset duplicate ACK counter mov [ebx + TCP_SOCKET.t_dupacks], 0 .ack_processed: ; (step 6) - DEBUGF 1,"ACK processed\n" + DEBUGF 1,"TCP_input: ACK processed\n" ;---------------------------------------------- ; check if we need to update window information @@ -1260,7 +1237,7 @@ align 4 @@: 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] pop [ebx + TCP_SOCKET.SND_WL1] @@ -1268,7 +1245,7 @@ align 4 push [edx + TCP_header.AckNumber] pop [ebx + TCP_SOCKET.SND_WL2] - ;;; needoutput = 1 + inc [ebx + TCP_SOCKET.sendalot] .no_window_update: @@ -1310,70 +1287,35 @@ align 4 ;;; TODO (1051-1093) - - - - - - -;-------------------------------- -; process the data in the segment +;--------------------------------------- +; process the data in the segment (1094) .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 - jnz .process_fin - - cmp [ebx + TCP_SOCKET.t_state], TCPS_FIN_WAIT_1 - jae .dont_do_data + jnz @f test ecx, ecx - jz .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: - - - - - + jnz .final_processing + @@: +; call TCP_reassemble ;;; TODO ;--------------- ; 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 - je .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 + cmp [ebx + TCP_SOCKET.t_state], TCPS_TIMED_WAIT + jae .not_first_fin - DEBUGF 1,"First FIN for this connection\n" + DEBUGF 1,"TCP_input: First FIN for this connection\n" mov eax, ebx call SOCKET_cant_recv_more @@ -1387,17 +1329,17 @@ align 4 jmp dword [eax + .FIN_sw_list] .FIN_sw_list: - dd .no_fin ;TCPS_CLOSED - dd .no_fin ;TCPS_LISTEN - dd .no_fin ;TCPS_SYN_SENT - dd .fin_syn_est ;TCPS_SYN_RECEIVED - dd .fin_syn_est ;TCPS_ESTABLISHED - dd .no_fin ;TCPS_CLOSE_WAIT - dd .fin_wait1 ;TCPS_FIN_WAIT_1 - dd .no_fin ;TCPS_CLOSING - dd .no_fin ;TCPS_LAST_ACK - dd .fin_wait2 ;TCPS_FIN_WAIT_2 - dd .fin_timed ;TCPS_TIMED_WAIT + dd .no_fin ; TCPS_CLOSED + dd .no_fin ; TCPS_LISTEN + dd .no_fin ; TCPS_SYN_SENT + dd .fin_syn_est ; TCPS_SYN_RECEIVED + dd .fin_syn_est ; TCPS_ESTABLISHED + dd .no_fin ; TCPS_CLOSE_WAIT + dd .fin_wait1 ; TCPS_FIN_WAIT_1 + dd .no_fin ; TCPS_CLOSING + dd .no_fin ; TCPS_LAST_ACK + dd .fin_wait2 ; TCPS_FIN_WAIT_2 + dd .fin_timed ; TCPS_TIMED_WAIT .fin_syn_est: @@ -1427,34 +1369,41 @@ align 4 - - - - ;----------------- ; Final processing .final_processing: - DEBUGF 1,"Final processing\n" + DEBUGF 1,"TCP_input: Final processing\n" - ;;; if debug enabled, output packet - - ;test needoutput, needoutput - ;jz .dumpit + cmp [ebx + TCP_SOCKET.sendalot], 0 + jne .need_output test [ebx + TCP_SOCKET.t_flags], TF_ACKNOW 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 mov eax, ebx call TCP_output pop ebx + call kernel_free + add esp, 4 + ret + .dumpit: + DEBUGF 1,"TCP_input: dumping\n" + pusha lea ecx, [ebx + SOCKET.mutex] call mutex_unlock @@ -1476,7 +1425,7 @@ align 4 align 4 .drop_after_ack: - DEBUGF 1,"Drop after ACK\n" + DEBUGF 1,"TCP_input: Drop after ACK\n" test [edx + TCP_header.Flags], TH_RST jnz .drop @@ -1512,7 +1461,7 @@ align 4 align 4 .drop_with_reset: - DEBUGF 1,"Drop with reset\n" + DEBUGF 1,"TCP_input: Drop with reset\n" pusha lea ecx, [ebx + SOCKET.mutex] @@ -1568,7 +1517,7 @@ align 4 .drop_not_locked: - DEBUGF 1,"Dropping packet\n" + DEBUGF 1,"TCP_input: Dropping packet\n" ;;;; If debugging options are enabled, output the packet somwhere @@ -1585,7 +1534,7 @@ align 4 .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 jnz .drop_no_socket @@ -1600,7 +1549,7 @@ align 4 .drop_no_socket: - DEBUGF 1,"Drop (no socket)\n" + DEBUGF 1,"TCP_input: Drop (no socket)\n" call kernel_free add esp, 4 diff --git a/kernel/branches/net/network/tcp_output.inc b/kernel/branches/net/network/tcp_output.inc index 2436317bc2..d2735327db 100644 --- a/kernel/branches/net/network/tcp_output.inc +++ b/kernel/branches/net/network/tcp_output.inc @@ -28,7 +28,15 @@ $Revision$ align 4 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 ; 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? jne @f - DEBUGF 1,"Entering persist state\n" + DEBUGF 1,"TCP_output: Entering persist state\n" mov [eax + TCP_SOCKET.t_rxtshift], 0 TCP_set_persist eax @@ -264,12 +272,13 @@ TCP_output: ;---------------------------- ; 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 lea ecx, [eax + SOCKET.mutex] call mutex_unlock popa + popf ret @@ -293,7 +302,7 @@ TCP_output: align 4 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 mov edi, sizeof.TCP_header ; edi will contain headersize @@ -501,15 +510,13 @@ TCP_send: ;-------------------- ; Create the checksum - DEBUGF 1,"checksum: ptr=%x size=%u\n", esi, ecx - TCP_checksum (eax + IP_SOCKET.LocalIP), (eax + IP_SOCKET.RemoteIP) mov [esi + TCP_header.Checksum], dx ;---------------- ; 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] jnz .send_error pop eax @@ -529,7 +536,8 @@ TCP_send: ; unlock socket lea ecx, [eax + SOCKET.mutex] call mutex_unlock - DEBUGF 1,"TCP_output: success!\n" + popf + DEBUGF 1,"TCP_send: success!\n" xor eax, eax ret @@ -545,7 +553,8 @@ TCP_send: ; unlock socket lea ecx, [eax + SOCKET.mutex] call mutex_unlock - DEBUGF 1,"TCP_output: IP error\n" + popf + DEBUGF 1,"TCP_send: IP error\n" or eax, -1 ret @@ -555,7 +564,8 @@ TCP_send: ; unlock socket lea ecx, [eax + SOCKET.mutex] call mutex_unlock - DEBUGF 1,"TCP_output: sending failed\n" + popf + DEBUGF 1,"TCP_send: sending failed\n" or eax, -2 ret diff --git a/kernel/branches/net/network/tcp_subr.inc b/kernel/branches/net/network/tcp_subr.inc index f5019e8af8..8710074a81 100644 --- a/kernel/branches/net/network/tcp_subr.inc +++ b/kernel/branches/net/network/tcp_subr.inc @@ -140,7 +140,7 @@ TCP_pull_out_of_band: align 4 TCP_drop: - DEBUGF 1,"TCP_drop\n" + DEBUGF 1,"TCP_drop: %x\n", eax cmp [eax + TCP_SOCKET.t_state], TCPS_SYN_RECEIVED jb .no_syn_received @@ -201,7 +201,7 @@ TCP_close: align 4 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 jb TCP_close @@ -227,7 +227,7 @@ TCP_disconnect: align 4 TCP_usrclosed: - DEBUGF 1,"TCP_usrclosed socket=%x\n", eax + DEBUGF 1,"TCP_usrclosed: %x\n", eax push ebx mov ebx, [eax + TCP_SOCKET.t_state] @@ -287,7 +287,7 @@ TCP_outflags: mov edx, [eax + TCP_SOCKET.t_state] 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 @@ -323,7 +323,7 @@ TCP_outflags: align 4 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 @@ -382,8 +382,8 @@ TCP_respond_socket: ret .error: - DEBUGF 1,"TCP_respond failed\n" - add esp, 2+4 + DEBUGF 1,"TCP_respond_socket: failed\n" + add esp, 2 + 4 ret @@ -404,7 +404,7 @@ TCP_respond_socket: align 4 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 @@ -461,7 +461,7 @@ TCP_respond_segment: ret .error: - DEBUGF 1,"TCP_respond failed\n" + DEBUGF 1,"TCP_respond_segment: failed\n" add esp, 2+4 ret diff --git a/kernel/branches/net/network/udp.inc b/kernel/branches/net/network/udp.inc index c069b6eb89..2cb0a1633d 100644 --- a/kernel/branches/net/network/udp.inc +++ b/kernel/branches/net/network/udp.inc @@ -116,7 +116,7 @@ macro UDP_checksum IP1, IP2 { ; esi = ptr to udp packet, ecx = packet size align 4 UDP_input: - DEBUGF 1,"UDP_input, size:%u\n", ecx + DEBUGF 1,"UDP_input: size=%u\n", ecx ; First validate, checksum @@ -129,7 +129,7 @@ UDP_input: jnz .checksum_mismatch .no_checksum: - DEBUGF 1,"UDP Checksum is correct\n" + DEBUGF 1,"UDP_input: checksum ok\n" ; Convert port numbers to intel format @@ -160,7 +160,7 @@ UDP_input: cmp [eax + UDP_SOCKET.LocalPort], dx 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! @@ -184,8 +184,8 @@ UDP_input: popa .updatesock: - inc [UDP_PACKETS_RX] - DEBUGF 1,"Found valid UDP packet for socket %x\n", eax + inc [UDP_PACKETS_RX] ; Fixme: correct interface? + movzx ecx, [esi + UDP_header.Length] sub ecx, sizeof.UDP_header add esi, sizeof.UDP_header @@ -198,7 +198,7 @@ UDP_input: call mutex_lock 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 inc [eax + UDP_SOCKET.firstpacket] @@ -206,13 +206,12 @@ UDP_input: .checksum_mismatch: - - DEBUGF 2,"UDP_Handler - checksum mismatch\n" + DEBUGF 2,"UDP_input: checksum mismatch\n" .dump: call kernel_free add esp, 4 ; pop (balance stack) - DEBUGF 2,"UDP_Handler - dumping\n" + DEBUGF 2,"UDP_input: dumping\n" ret @@ -232,14 +231,14 @@ UDP_input: align 4 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] - DEBUGF 1,"UDP_output: remote port: %u, ", dx + DEBUGF 1,"UDP_output: remote port=%u, ", dx rol dx, 8 rol edx, 16 mov dx, [eax + UDP_SOCKET.LocalPort] - DEBUGF 1,"local port: %u\n", dx + DEBUGF 1,"local port=%u\n", dx rol dx, 8 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? - 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] ret