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
This commit is contained in:
hidnplayr 2009-09-28 19:48:32 +00:00
parent f7ddce1888
commit d0d8c7f17c
5 changed files with 136 additions and 70 deletions

View File

@ -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: ; ARP_Handler:

View File

@ -100,7 +100,7 @@ ETH_init:
align 4 align 4
ETH_Add_Device: ETH_Add_Device:
DEBUGF 1,"ETH_Add_Device: %x\n", ebx DEBUGF 1,"ETH_Add_Device: %x ", ebx
mov eax, [ETH_RUNNING] mov eax, [ETH_RUNNING]
cmp eax, MAX_ETH_DEVICES cmp eax, MAX_ETH_DEVICES
@ -134,23 +134,8 @@ ETH_Add_Device:
mov eax, edi ; edx = 4*device num mov eax, edi ; edx = 4*device num
shr eax, 2 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 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 DEBUGF 1,"- succes: %u\n",eax
ret ret

View File

@ -103,6 +103,8 @@ uglobal
ICMP_PACKETS_RX rd MAX_IP ICMP_PACKETS_RX rd MAX_IP
endg endg
;----------------------------------------------------------------- ;-----------------------------------------------------------------
; ;
; ICMP_init ; ICMP_init
@ -127,12 +129,6 @@ ICMP_init:
;-------------------------------- ;--------------------------------
; ;
; ICMP_Handler: ; ICMP_Handler:
@ -153,7 +149,7 @@ align 4
ICMP_Handler: ;TODO: works only on pure ethernet right now ! ICMP_Handler: ;TODO: works only on pure ethernet right now !
DEBUGF 1,"ICMP_Handler - start\n" 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 jne .check_sockets
mov byte [edx + ICMP_Packet.Type], ICMP_ECHOREPLY ; Change Packet type to reply 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 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]
; 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

View File

@ -110,7 +110,7 @@ sys_socket:
dec bl dec bl
jz socket_recv ; 7 jz socket_recv ; 7
.error: s_error:
mov dword [esp+32],-1 mov dword [esp+32],-1
ret ret
@ -135,7 +135,7 @@ socket_open:
call net_socket_alloc call net_socket_alloc
or eax, eax or eax, eax
jz error jz s_error
mov [eax + SOCKET.Domain], ecx mov [eax + SOCKET.Domain], ecx
mov [eax + SOCKET.Type], edx mov [eax + SOCKET.Type], edx
@ -168,20 +168,20 @@ socket_bind:
stdcall net_socket_num_to_addr, ecx stdcall net_socket_num_to_addr, ecx
cmp eax, -1 cmp eax, -1
jz error jz s_error
cmp esi, 2 cmp esi, 2
jl error jl s_error
cmp word [edx], AF_INET4 cmp word [edx], AF_INET4
je .af_inet4 je .af_inet4
jmp error jmp s_error
.af_inet4: .af_inet4:
cmp esi, 6 cmp esi, 6
jl error jl s_error
mov bx, word [edx + 2] mov bx, word [edx + 2]
DEBUGF 1,"local port: %u ",bx DEBUGF 1,"local port: %u ",bx
@ -209,13 +209,13 @@ socket_bind:
jne .next_udp_socket jne .next_udp_socket
cmp word [edx + 2], 0 cmp word [edx + 2], 0
jne error jne s_error
cmp bx, MAX_EPHEMERAL_PORT cmp bx, MAX_EPHEMERAL_PORT
jle .find_port_loop jle .find_port_loop
mov [last_UDP_port], MIN_EPHEMERAL_PORT mov [last_UDP_port], MIN_EPHEMERAL_PORT
jmp error jmp s_error
.udp_port_ok: .udp_port_ok:
mov word [eax + SOCKET.LocalPort], bx mov word [eax + SOCKET.LocalPort], bx
@ -251,20 +251,20 @@ socket_connect:
stdcall net_socket_num_to_addr, ecx stdcall net_socket_num_to_addr, ecx
cmp eax, -1 cmp eax, -1
jz error jz s_error
cmp esi, 2 cmp esi, 2
jl error jl s_error
cmp word [edx], AF_INET4 cmp word [edx], AF_INET4
je .af_inet4 je .af_inet4
jmp error jmp s_error
.af_inet4: .af_inet4:
cmp esi, 8 cmp esi, 8
jl error jl s_error
cmp [eax + SOCKET.Type], IP_PROTO_UDP cmp [eax + SOCKET.Type], IP_PROTO_UDP
je .udp je .udp
@ -275,7 +275,7 @@ socket_connect:
; cmp [eax + SOCKET.Type], IP_PROTO_TCP ; cmp [eax + SOCKET.Type], IP_PROTO_TCP
; je .tcp ; je .tcp
jmp error jmp s_error
.udp: .udp:
@ -399,7 +399,7 @@ socket_listen:
stdcall net_socket_num_to_addr, ecx stdcall net_socket_num_to_addr, ecx
cmp eax, -1 cmp eax, -1
jz error jz s_error
cmp edx, MAX_backlog cmp edx, MAX_backlog
jl .ok jl .ok
@ -437,15 +437,15 @@ socket_accept:
stdcall net_socket_num_to_addr, ecx stdcall net_socket_num_to_addr, ecx
or eax, eax or eax, eax
jz error jz s_error
mov esi, eax mov esi, eax
cmp [esi + SOCKET.backlog], 0 cmp [esi + SOCKET.backlog], 0
jz error jz s_error
call net_socket_alloc call net_socket_alloc
or eax, eax or eax, eax
jz error jz s_error
mov edi, eax mov edi, eax
dec [esi + SOCKET.backlog] dec [esi + SOCKET.backlog]
@ -483,7 +483,7 @@ socket_close:
stdcall net_socket_num_to_addr, ecx stdcall net_socket_num_to_addr, ecx
or eax, eax or eax, eax
jz error jz s_error
cmp [eax + SOCKET.Type], IP_PROTO_UDP cmp [eax + SOCKET.Type], IP_PROTO_UDP
@ -495,7 +495,7 @@ socket_close:
; cmp [eax + SOCKET.Type], IP_PROTO_TCP ; cmp [eax + SOCKET.Type], IP_PROTO_TCP
; je .tcp ; je .tcp
jmp error jmp s_error
.udp: .udp:
@ -633,7 +633,7 @@ socket_recv:
stdcall net_socket_num_to_addr, ecx ; get real socket address stdcall net_socket_num_to_addr, ecx ; get real socket address
or eax, eax or eax, eax
jz error jz s_error
DEBUGF 1,"real socket address:%x\n", eax 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 stdcall net_socket_num_to_addr, ecx ; get real socket address
or eax, eax or eax, eax
jz error jz s_error
DEBUGF 1,"Socket type:%u\n", [eax + SOCKET.Type]:4 DEBUGF 1,"Socket type:%u\n", [eax + SOCKET.Type]:4
@ -726,7 +726,7 @@ socket_send:
; cmp [eax + SOCKET.Type], IP_PROTO_TCP ; cmp [eax + SOCKET.Type], IP_PROTO_TCP
; je .tcp ; je .tcp
jmp error jmp s_error
.udp: .udp:

View File

@ -19,18 +19,6 @@
$Revision: 983 $ $Revision: 983 $
;*******************************************************************
; Interface
; The interfaces defined in ETHERNET.INC plus:
; stack_init
; stack_handler
; app_stack_handler
; app_socket_handler
; checksum
;
;*******************************************************************
uglobal uglobal
last_1sTick db ? last_1sTick db ?
last_1hsTick dd ? last_1hsTick dd ?
@ -38,9 +26,11 @@ endg
MAX_NET_DEVICES equ 16 MAX_NET_DEVICES equ 16
; TCP opening modes MIN_EPHEMERAL_PORT equ 49152
SOCKET_PASSIVE equ 0 MAX_EPHEMERAL_PORT equ 61000
SOCKET_ACTIVE equ 1
ETHER equ 1337
ETHER_ARP equ 0x0608
;AF_UNSPEC equ 0 ;AF_UNSPEC equ 0
;AF_UNIX equ 1 ;AF_UNIX equ 1
@ -60,17 +50,18 @@ IP_PROTO_ICMP equ 1
IP_PROTO_TCP equ 6 IP_PROTO_TCP equ 6
IP_PROTO_UDP equ 17 IP_PROTO_UDP equ 17
MIN_EPHEMERAL_PORT equ 49152 ; TCP opening modes
MAX_EPHEMERAL_PORT equ 61000 SOCKET_PASSIVE equ 0
SOCKET_ACTIVE equ 1
include "queue.inc" include "queue.inc"
include "ARP.inc" include "arp.inc"
include "IPv4.inc" include "ipv4.inc"
include "ethernet.inc" include "ethernet.inc"
include "socket.inc" include "socket.inc"
;include "TCP.inc" ;include "tcp.inc"
include "UDP.inc" include "udp.inc"
include "ICMP.inc" include "icmp.inc"
;----------------------------------------------- ;-----------------------------------------------
; ;
@ -125,7 +116,7 @@ stack_handler:
; Test for 10ms tick, call tcp timer ; Test for 10ms tick, call tcp timer
mov eax, [timer_ticks] mov eax, [timer_ticks]
cmp eax, [last_1hsTick] cmp eax, [last_1hsTick]
je .sec_tick je .exit
mov [last_1hsTick], eax mov [last_1hsTick], eax
; call tcp_tx_handler ; call tcp_tx_handler
@ -141,7 +132,7 @@ stack_handler:
mov [last_1sTick], al mov [last_1sTick], al
stdcall arp_table_manager, ARP_TABLE_TIMER, 0, 0 ; call ARP_decrease_entry_ttls
call IPv4_decrease_fragment_ttls call IPv4_decrease_fragment_ttls
; call tcp_tcb_handler ; call tcp_tcb_handler
@ -275,7 +266,7 @@ sys_protocols:
cmp ax , ETHER_ARP cmp ax , ETHER_ARP
je ARP_API je ARP_API
cmp ax , 1337 cmp ax , ETHER
je ETH_API je ETH_API
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