Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 7677 → Rev 7678

/kernel/trunk/network/IPv4.inc
1,6 → 1,6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2004-2016. All rights reserved. ;;
;; Copyright (C) KolibriOS team 2004-2019. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; ;;
;; IPv4.INC ;;
61,33 → 61,32
; Ip header begins here (we will need the IP header to re-construct the complete packet)
ends
 
struct IPv4_ROUTE
;struct IPv4_ROUTE
;
; Destination dd ?
; Gateway dd ?
; Flags dd ?
; Use dd ?
; Interface dd ?
;
;ends
 
Destination dd ?
Gateway dd ?
Flags dd ?
Use dd ?
Interface dd ?
 
ends
 
 
uglobal
align 4
 
IP_LIST rd NET_DEVICES_MAX
SUBNET_LIST rd NET_DEVICES_MAX
DNS_LIST rd NET_DEVICES_MAX
GATEWAY_LIST rd NET_DEVICES_MAX
BROADCAST_LIST rd NET_DEVICES_MAX
IPv4_address rd NET_DEVICES_MAX
IPv4_subnet rd NET_DEVICES_MAX
IPv4_nameserver rd NET_DEVICES_MAX
IPv4_gateway rd NET_DEVICES_MAX
IPv4_broadcast rd NET_DEVICES_MAX
 
IPv4_packets_tx rd NET_DEVICES_MAX
IPv4_packets_rx rd NET_DEVICES_MAX
IPv4_packets_dumped rd NET_DEVICES_MAX
 
IPv4_FRAGMENT_LIST rb IPv4_MAX_FRAGMENTS * sizeof.IPv4_FRAGMENT_slot
IPv4_fragments rb IPv4_MAX_FRAGMENTS * sizeof.IPv4_FRAGMENT_slot
 
IPv4_ROUTES rd IPv4_MAX_ROUTES * sizeof.IPv4_ROUTE
; IPv4_routes rd IPv4_MAX_ROUTES * sizeof.IPv4_ROUTE
 
endg
 
100,7 → 99,7
macro ipv4_init {
 
xor eax, eax
mov edi, IP_LIST
mov edi, IPv4_address
mov ecx, 7*NET_DEVICES_MAX + (sizeof.IPv4_FRAGMENT_slot*IPv4_MAX_FRAGMENTS)/4
rep stosd
 
116,7 → 115,7
 
local .loop, .next
 
mov esi, IPv4_FRAGMENT_LIST
mov esi, IPv4_fragments
mov ecx, IPv4_MAX_FRAGMENTS
.loop:
cmp [esi + IPv4_FRAGMENT_slot.ttl], 0
244,11 → 243,11
 
; local ip (Using RFC1122 strong end system model)
mov eax, [edx + IPv4_header.DestinationAddress]
cmp eax, [IP_LIST + edi]
cmp eax, [IPv4_address + edi]
je .ip_ok
 
; network layer broadcast
cmp eax, [BROADCAST_LIST + edi]
cmp eax, [IPv4_broadcast + edi]
je .ip_ok
 
; physical layer broadcast (255.255.255.255)
261,7 → 260,7
je .ip_ok
 
; maybe we just dont have an IP yet and should accept everything on the IP level
cmp [IP_LIST + edi], 0
cmp [IPv4_address + edi], 0
je .ip_ok
 
; or it's just not meant for us.. :(
419,7 → 418,7
DEBUGF DEBUG_NETWORK_VERBOSE, "IPv4_input: First fragment packet received!\n"
; try to locate a free slot..
mov ecx, IPv4_MAX_FRAGMENTS
mov esi, IPv4_FRAGMENT_LIST
mov esi, IPv4_fragments
.find_free_slot:
cmp word [esi + IPv4_FRAGMENT_slot.ttl], 0
je .found_free_slot
584,7 → 583,7
push eax ebx ecx edx
mov ax, [edx + IPv4_header.Identification]
mov ecx, IPv4_MAX_FRAGMENTS
mov esi, IPv4_FRAGMENT_LIST
mov esi, IPv4_fragments
mov ebx, [edx + IPv4_header.SourceAddress]
mov edx, [edx + IPv4_header.DestinationAddress]
.find_slot:
649,7 → 648,7
inc [IPv4_packets_tx + edi] ; update stats
 
mov ax, ETHER_PROTO_IPv4
mov ebx, [NET_DRV_LIST + edi]
mov ebx, [net_drv_list + edi]
mov ecx, [esp + 6 + 8 + 2]
add ecx, sizeof.IPv4_header
mov edx, esp
706,6 → 705,8
ret
 
.loopback:
inc [IPv4_packets_tx + edi] ; update stats
 
mov dword [esp], eax ; set source IP to dest IP
mov ecx, [esp + 10]
add ecx, sizeof.IPv4_header
746,7 → 747,7
 
inc [IPv4_packets_tx + 4*edi]
mov ax, ETHER_PROTO_IPv4
mov ebx, [NET_DRV_LIST + 4*edi]
mov ebx, [net_drv_list + 4*edi]
mov ecx, [esp + 6 + 4]
add ecx, sizeof.IPv4_header
mov edx, esp
945,11 → 946,11
 
xor edi, edi
.loop:
mov ebx, [IP_LIST + edi]
and ebx, [SUBNET_LIST + edi]
mov ebx, [IPv4_address + edi]
and ebx, [IPv4_subnet + edi]
jz .next
mov ecx, eax
and ecx, [SUBNET_LIST + edi]
and ecx, [IPv4_subnet + edi]
cmp ebx, ecx
je .got_it
.next:
957,7 → 958,7
cmp edi, 4*NET_DEVICES_MAX
jb .loop
 
mov eax, [GATEWAY_LIST + 4] ; TODO: let user (or a user space daemon) configure default route
mov eax, [IPv4_gateway + 4] ; TODO: let user (or a user space daemon) configure default route
.broadcast:
mov edi, 4 ; TODO: same as above
.got_it:
964,7 → 965,7
DEBUGF DEBUG_NETWORK_VERBOSE, "IPv4_route: %u\n", edi
test edx, edx
jnz @f
mov edx, [IP_LIST + edi]
mov edx, [IPv4_address + edi]
@@:
 
ret
975,7 → 976,7
cmp edi, -1
je .fail
 
mov edx, [IP_LIST + edi] ; Source IP
mov edx, [IPv4_address + edi] ; Source IP
 
; Broadcast does not need gateway
cmp eax, 0xffffffff
982,13 → 983,13
je @f
 
; Check if we should route to gateway or not
mov ebx, [IP_LIST + edi]
and ebx, [SUBNET_LIST + edi]
mov ebx, [IPv4_address + edi]
and ebx, [IPv4_subnet + edi]
mov ecx, eax
and ecx, [SUBNET_LIST + edi]
and ecx, [IPv4_subnet + edi]
cmp ecx, ebx
je @f
mov eax, [GATEWAY_LIST + edi]
mov eax, [IPv4_gateway + edi]
@@:
DEBUGF DEBUG_NETWORK_VERBOSE, "IPv4_route: %u\n", edi
ret
1038,7 → 1039,7
; Fill in local IP
cmp [eax + IP_SOCKET.LocalIP], 0
jne @f
push [IP_LIST + 4] ; FIXME: use correct local IP
push [IPv4_address + 4] ; FIXME: use correct local IP
pop [eax + IP_SOCKET.LocalIP]
 
; Fill in remote IP
1100,21 → 1101,21
ret
 
.read_ip:
mov eax, [IP_LIST + eax]
mov eax, [IPv4_address + eax]
ret
 
.write_ip:
mov [IP_LIST + eax], ecx
mov [IPv4_address + eax], ecx
mov edi, eax ; device number, we'll need it for ARP
 
; pre-calculate the local broadcast address
mov ebx, [SUBNET_LIST + eax]
mov ebx, [IPv4_subnet + eax]
not ebx
or ebx, ecx
mov [BROADCAST_LIST + eax], ebx
mov [IPv4_broadcast + eax], ebx
 
mov ebx, [NET_DRV_LIST + eax]
mov eax, [IP_LIST + eax]
mov ebx, [net_drv_list + eax]
mov eax, [IPv4_address + eax]
call arp_output_request ; now send a gratuitous ARP
 
call net_send_event
1122,27 → 1123,27
ret
 
.read_dns:
mov eax, [DNS_LIST + eax]
mov eax, [IPv4_nameserver + eax]
ret
 
.write_dns:
mov [DNS_LIST + eax], ecx
mov [IPv4_nameserver + eax], ecx
call net_send_event
xor eax, eax
ret
 
.read_subnet:
mov eax, [SUBNET_LIST + eax]
mov eax, [IPv4_subnet + eax]
ret
 
.write_subnet:
mov [SUBNET_LIST + eax], ecx
mov [IPv4_subnet + eax], ecx
 
; pre-calculate the local broadcast address
mov ebx, [IP_LIST + eax]
mov ebx, [IPv4_address + eax]
not ecx
or ecx, ebx
mov [BROADCAST_LIST + eax], ecx
mov [IPv4_broadcast + eax], ecx
 
call net_send_event
xor eax, eax
1149,11 → 1150,11
ret
 
.read_gateway:
mov eax, [GATEWAY_LIST + eax]
mov eax, [IPv4_gateway + eax]
ret
 
.write_gateway:
mov [GATEWAY_LIST + eax], ecx
mov [IPv4_gateway + eax], ecx
 
call net_send_event
xor eax, eax