From d0d8c7f17c831ec627ca47c20a6c8818519866f5 Mon Sep 17 00:00:00 2001 From: hidnplayr Date: Mon, 28 Sep 2009 19:48:32 +0000 Subject: [PATCH] More fixes to make net brach compile on unix + some general bugfixes and updates git-svn-id: svn://kolibrios.org@1185 a494cfbc-eb01-0410-851d-a64ba20cac60 --- kernel/branches/net/network/ARP.inc | 93 ++++++++++++++++++++++++ kernel/branches/net/network/ethernet.inc | 17 +---- kernel/branches/net/network/icmp.inc | 11 +-- kernel/branches/net/network/socket.inc | 44 +++++------ kernel/branches/net/network/stack.inc | 41 ++++------- 5 files changed, 136 insertions(+), 70 deletions(-) diff --git a/kernel/branches/net/network/ARP.inc b/kernel/branches/net/network/ARP.inc index d6789ff6cd..d0458a9467 100644 --- a/kernel/branches/net/network/ARP.inc +++ b/kernel/branches/net/network/ARP.inc @@ -567,6 +567,99 @@ endp +;--------------------------------------------------------------------------- +; +; ARP_decrease_entry_ttls +; +; IN: / +; OUT: / +; +;--------------------------------------------------------------------------- + +align 4 +ARP_decrease_entry_ttls: + + mov ecx, [NumARP] + test ecx, ecx + jz .exit + + mov ebx, ARPTable + +.timer_loop: + + movsx esi, word [ebx + ARP_ENTRY.TTL] + cmp esi, 0xFFFFFFFF + je .timer_loop_end ;if TTL==0xFFFF then it's static entry + + test esi, esi + jnz .timer_loop_end_with_dec ;if TTL!=0 + + ; Ok, TTL is 0 + ;if Status==AWAITING_RESPONSE and TTL==0 + ;then we have to change it to ARP_RESPONSE_TIMEOUT + cmp word [ebx + ARP_ENTRY.Status], ARP_AWAITING_RESPONSE + jne @f + + mov word [ebx + ARP_ENTRY.Status], ARP_RESPONSE_TIMEOUT + mov word [ebx + ARP_ENTRY.TTL], word 0x000A ;10 sec + jmp .timer_loop_end + + @@: + ;if TTL==0 and Status==VALID_MAPPING, we have to delete it + ;if TTL==0 and Status==RESPONSE_TIMEOUT, delete too + mov esi, dword[NumARP] + sub esi, ecx ;esi=index of entry, will be deleted + + call ARP_del_entry + + jmp .timer_loop_end + + +.timer_loop_end_with_dec: + + dec word [ebx + ARP_ENTRY.TTL] ;decrease TTL + +.timer_loop_end: + + add ebx, ARP_ENTRY.size + loop .timer_loop + +.exit: + + ret + + +;--------------------------------------------------------------------------- +; +; ARP_del_entry +; +; IN: entry # in esi +; OUT: / +; +;--------------------------------------------------------------------------- + +align 4 +ARP_del_entry: + + imul esi, ARP_ENTRY.size + + mov ecx, (ARP_TABLE_SIZE - 1) * ARP_ENTRY.size + sub ecx, esi + + lea edi, [ebx + esi] ;edi=ptr to entry that should be deleted + lea esi, [edi + ARP_ENTRY.size] ;esi=ptr to next entry + + shr ecx,1 ;ecx/2 => ARP_ENTRY_SIZE MUST BE EVEN NUMBER! + cld + rep movsw + + dec dword[NumARP] ;decrease arp-entries counter + ret + + + + + ;----------------------------------------------------- ; ; ARP_Handler: diff --git a/kernel/branches/net/network/ethernet.inc b/kernel/branches/net/network/ethernet.inc index 59ee22f7cd..ed2e56f422 100644 --- a/kernel/branches/net/network/ethernet.inc +++ b/kernel/branches/net/network/ethernet.inc @@ -100,7 +100,7 @@ ETH_init: align 4 ETH_Add_Device: - DEBUGF 1,"ETH_Add_Device: %x\n", ebx + DEBUGF 1,"ETH_Add_Device: %x ", ebx mov eax, [ETH_RUNNING] cmp eax, MAX_ETH_DEVICES @@ -134,23 +134,8 @@ ETH_Add_Device: mov eax, edi ; edx = 4*device num shr eax, 2 -; shr eax, 1 ; edx = 2*device num -; add edi, eax ; edi = 6*device_num Meanwhile, calculate MAC offset in edi -; shr eax, 1 ; edx = device num -; add edi, MAC_LIST ; edi = MAC_LIST+6*device_num -; push eax - -; push edi -; call [ebx+ETH_DEVICE.get_MAC] ; Get MAC address from driver -; pop edi -; -; stosd ; Write MAC address to the MAC list -; mov ax, bx ; -; stosw ; - inc [ETH_RUNNING] ; Indicate that one more ethernet device is up and running -; pop eax ; Output device num in eax DEBUGF 1,"- succes: %u\n",eax ret diff --git a/kernel/branches/net/network/icmp.inc b/kernel/branches/net/network/icmp.inc index 7b368aede8..2f1b8a7843 100644 --- a/kernel/branches/net/network/icmp.inc +++ b/kernel/branches/net/network/icmp.inc @@ -103,6 +103,8 @@ uglobal ICMP_PACKETS_RX rd MAX_IP endg + + ;----------------------------------------------------------------- ; ; ICMP_init @@ -123,12 +125,6 @@ ICMP_init: rep stosd ret - - - - - - @@ -153,7 +149,7 @@ align 4 ICMP_Handler: ;TODO: works only on pure ethernet right now ! DEBUGF 1,"ICMP_Handler - start\n" - cmp byte [edx + ICMP_Packet.Type], ICMP_ECHO ; Is this an echo request? discard if not + cmp byte [edx + ICMP_Packet.Type], ICMP_ECHO ; Is this an echo request? jne .check_sockets mov byte [edx + ICMP_Packet.Type], ICMP_ECHOREPLY ; Change Packet type to reply @@ -163,6 +159,7 @@ ICMP_Handler: ;TODO: works only on pure ethernet right now ! cmp edi,-1 je .dump 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 diff --git a/kernel/branches/net/network/socket.inc b/kernel/branches/net/network/socket.inc index d4ee035eb9..494cb41b20 100644 --- a/kernel/branches/net/network/socket.inc +++ b/kernel/branches/net/network/socket.inc @@ -110,7 +110,7 @@ sys_socket: dec bl jz socket_recv ; 7 -.error: +s_error: mov dword [esp+32],-1 ret @@ -135,7 +135,7 @@ socket_open: call net_socket_alloc or eax, eax - jz error + jz s_error mov [eax + SOCKET.Domain], ecx mov [eax + SOCKET.Type], edx @@ -168,20 +168,20 @@ socket_bind: stdcall net_socket_num_to_addr, ecx cmp eax, -1 - jz error + jz s_error cmp esi, 2 - jl error + jl s_error cmp word [edx], AF_INET4 je .af_inet4 - jmp error + jmp s_error .af_inet4: cmp esi, 6 - jl error + jl s_error mov bx, word [edx + 2] DEBUGF 1,"local port: %u ",bx @@ -209,13 +209,13 @@ socket_bind: jne .next_udp_socket cmp word [edx + 2], 0 - jne error + jne s_error cmp bx, MAX_EPHEMERAL_PORT jle .find_port_loop mov [last_UDP_port], MIN_EPHEMERAL_PORT - jmp error + jmp s_error .udp_port_ok: mov word [eax + SOCKET.LocalPort], bx @@ -251,20 +251,20 @@ socket_connect: stdcall net_socket_num_to_addr, ecx cmp eax, -1 - jz error + jz s_error cmp esi, 2 - jl error + jl s_error cmp word [edx], AF_INET4 je .af_inet4 - jmp error + jmp s_error .af_inet4: cmp esi, 8 - jl error + jl s_error cmp [eax + SOCKET.Type], IP_PROTO_UDP je .udp @@ -275,7 +275,7 @@ socket_connect: ; cmp [eax + SOCKET.Type], IP_PROTO_TCP ; je .tcp - jmp error + jmp s_error .udp: @@ -399,7 +399,7 @@ socket_listen: stdcall net_socket_num_to_addr, ecx cmp eax, -1 - jz error + jz s_error cmp edx, MAX_backlog jl .ok @@ -437,15 +437,15 @@ socket_accept: stdcall net_socket_num_to_addr, ecx or eax, eax - jz error + jz s_error mov esi, eax cmp [esi + SOCKET.backlog], 0 - jz error + jz s_error call net_socket_alloc or eax, eax - jz error + jz s_error mov edi, eax dec [esi + SOCKET.backlog] @@ -483,7 +483,7 @@ socket_close: stdcall net_socket_num_to_addr, ecx or eax, eax - jz error + jz s_error cmp [eax + SOCKET.Type], IP_PROTO_UDP @@ -495,7 +495,7 @@ socket_close: ; cmp [eax + SOCKET.Type], IP_PROTO_TCP ; je .tcp - jmp error + jmp s_error .udp: @@ -633,7 +633,7 @@ socket_recv: stdcall net_socket_num_to_addr, ecx ; get real socket address or eax, eax - jz error + jz s_error DEBUGF 1,"real socket address:%x\n", eax @@ -713,7 +713,7 @@ socket_send: stdcall net_socket_num_to_addr, ecx ; get real socket address or eax, eax - jz error + jz s_error DEBUGF 1,"Socket type:%u\n", [eax + SOCKET.Type]:4 @@ -726,7 +726,7 @@ socket_send: ; cmp [eax + SOCKET.Type], IP_PROTO_TCP ; je .tcp - jmp error + jmp s_error .udp: diff --git a/kernel/branches/net/network/stack.inc b/kernel/branches/net/network/stack.inc index 7dd353bdc2..56debe666c 100644 --- a/kernel/branches/net/network/stack.inc +++ b/kernel/branches/net/network/stack.inc @@ -19,18 +19,6 @@ $Revision: 983 $ - -;******************************************************************* -; Interface -; The interfaces defined in ETHERNET.INC plus: -; stack_init -; stack_handler -; app_stack_handler -; app_socket_handler -; checksum -; -;******************************************************************* - uglobal last_1sTick db ? last_1hsTick dd ? @@ -38,9 +26,11 @@ endg MAX_NET_DEVICES equ 16 -; TCP opening modes -SOCKET_PASSIVE equ 0 -SOCKET_ACTIVE equ 1 +MIN_EPHEMERAL_PORT equ 49152 +MAX_EPHEMERAL_PORT equ 61000 + +ETHER equ 1337 +ETHER_ARP equ 0x0608 ;AF_UNSPEC equ 0 ;AF_UNIX equ 1 @@ -60,17 +50,18 @@ IP_PROTO_ICMP equ 1 IP_PROTO_TCP equ 6 IP_PROTO_UDP equ 17 -MIN_EPHEMERAL_PORT equ 49152 -MAX_EPHEMERAL_PORT equ 61000 +; TCP opening modes +SOCKET_PASSIVE equ 0 +SOCKET_ACTIVE equ 1 include "queue.inc" -include "ARP.inc" -include "IPv4.inc" +include "arp.inc" +include "ipv4.inc" include "ethernet.inc" include "socket.inc" -;include "TCP.inc" -include "UDP.inc" -include "ICMP.inc" +;include "tcp.inc" +include "udp.inc" +include "icmp.inc" ;----------------------------------------------- ; @@ -125,7 +116,7 @@ stack_handler: ; Test for 10ms tick, call tcp timer mov eax, [timer_ticks] cmp eax, [last_1hsTick] - je .sec_tick + je .exit mov [last_1hsTick], eax ; call tcp_tx_handler @@ -141,7 +132,7 @@ stack_handler: mov [last_1sTick], al - stdcall arp_table_manager, ARP_TABLE_TIMER, 0, 0 +; call ARP_decrease_entry_ttls call IPv4_decrease_fragment_ttls ; call tcp_tcb_handler @@ -275,7 +266,7 @@ sys_protocols: cmp ax , ETHER_ARP je ARP_API - cmp ax , 1337 + cmp ax , ETHER je ETH_API add esp, 4 ; if we reached here, no function was called, so we need to balance stack