Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 1184 → Rev 1185

/kernel/branches/net/network/ARP.inc
567,6 → 567,99
 
 
 
;---------------------------------------------------------------------------
;
; 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:
/kernel/branches/net/network/ethernet.inc
100,7 → 100,7
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
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
 
/kernel/branches/net/network/icmp.inc
103,6 → 103,8
ICMP_PACKETS_RX rd MAX_IP
endg
 
 
 
;-----------------------------------------------------------------
;
; ICMP_init
127,12 → 129,6
 
 
 
 
 
 
;--------------------------------
;
; ICMP_Handler:
153,7 → 149,7
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
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
/kernel/branches/net/network/socket.inc
110,7 → 110,7
dec bl
jz socket_recv ; 7
 
.error:
s_error:
mov dword [esp+32],-1
 
ret
135,7 → 135,7
 
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
 
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
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
 
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
; cmp [eax + SOCKET.Type], IP_PROTO_TCP
; je .tcp
 
jmp error
jmp s_error
 
.udp:
 
399,7 → 399,7
 
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
 
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
 
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
; cmp [eax + SOCKET.Type], IP_PROTO_TCP
; je .tcp
 
jmp error
jmp s_error
 
.udp:
 
633,7 → 633,7
 
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
 
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
; cmp [eax + SOCKET.Type], IP_PROTO_TCP
; je .tcp
 
jmp error
jmp s_error
 
.udp:
 
/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,10 → 26,12
 
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
AF_INET4 equ 2
60,17 → 50,18
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
; 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
 
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
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