Kernel now automatically sends one gratuitous ARP once IP address has been set.

Also, fixed ARP stats.

git-svn-id: svn://kolibrios.org@3159 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2013-01-11 10:52:01 +00:00
parent 43ea83d5a4
commit 72dc4ba124
2 changed files with 24 additions and 9 deletions

View File

@ -1,6 +1,6 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;; ;; ;;
;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;; ;; Copyright (C) KolibriOS team 2004-2013. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;; ;; Distributed under terms of the GNU General Public License ;;
;; ;; ;; ;;
;; ARP.INC ;; ;; ARP.INC ;;
@ -157,17 +157,22 @@ local .exit
; size of buffer in [esp+4] ; size of buffer in [esp+4]
; packet size (without ethernet header) in ecx ; packet size (without ethernet header) in ecx
; packet ptr in edx ; packet ptr in edx
; device ptr in ebx
; OUT: / ; OUT: /
; ;
;----------------------------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
ARP_input: ARP_input:
call NET_ptr_to_num
cmp edi, -1
jz .exit
cmp ecx, sizeof.ARP_header cmp ecx, sizeof.ARP_header
jb .exit jb .exit
;--------------------- ;---------------------
; Handle Reply packets ; Handle reply packets
cmp [edx + ARP_header.Opcode], ARP_REP_OPCODE cmp [edx + ARP_header.Opcode], ARP_REP_OPCODE
jne .maybe_request jne .maybe_request
@ -176,11 +181,15 @@ ARP_input:
[edx + ARP_header.SenderIP]:1, [edx + ARP_header.SenderIP + 1]:1,\ [edx + ARP_header.SenderIP]:1, [edx + ARP_header.SenderIP + 1]:1,\
[edx + ARP_header.SenderIP + 2]:1, [edx + ARP_header.SenderIP + 3]:1 [edx + ARP_header.SenderIP + 2]:1, [edx + ARP_header.SenderIP + 3]:1
inc [ARP_PACKETS_RX + 4*edi]
mov ecx, [NumARP] mov ecx, [NumARP]
test ecx, ecx test ecx, ecx
jz .exit jz .exit
mov eax, [edx + ARP_header.SenderIP] mov eax, [edx + ARP_header.SenderIP]
cmp eax, [IP_LIST + 4*edi] ; check for IP collision
je .collision
mov esi, ARP_table mov esi, ARP_table
.loop: .loop:
cmp [esi + ARP_entry.IP], eax cmp [esi + ARP_entry.IP], eax
@ -210,17 +219,18 @@ ARP_input:
jmp .exit jmp .exit
.collision:
DEBUGF 1,"ARP_input: IP address conflict detected!\n"
jmp .exit
;----------------------- ;-----------------------
; Handle Request packets ; Handle request packets
.maybe_request: .maybe_request:
cmp [edx + ARP_header.Opcode], ARP_REQ_OPCODE cmp [edx + ARP_header.Opcode], ARP_REQ_OPCODE
jne .exit jne .exit
call NET_ptr_to_num
cmp edi, -1
jz .exit
DEBUGF 1,"ARP_input: got request packet through device: %u\n", edi DEBUGF 1,"ARP_input: got request packet through device: %u\n", edi
inc [ARP_PACKETS_RX + 4*edi] inc [ARP_PACKETS_RX + 4*edi]
@ -290,6 +300,7 @@ ARP_output_request:
push eax ; DestIP push eax ; DestIP
pushd [IP_LIST + edi] ; SenderIP pushd [IP_LIST + edi] ; SenderIP
inc [ARP_PACKETS_TX + edi] ; assume we will succeed
DEBUGF 1,"ARP_output_request: ip=%u.%u.%u.%u\n",\ DEBUGF 1,"ARP_output_request: ip=%u.%u.%u.%u\n",\
[esp]:1, [esp + 1]:1, [esp + 2]:1, [esp + 3]:1 [esp]:1, [esp + 1]:1, [esp + 2]:1, [esp + 3]:1
@ -469,7 +480,7 @@ ARP_IP_to_MAC:
;-------------------- ;--------------------
; Send an ARP request ; Send an ARP request
push eax edi ; save IP for ARP_output_request push eax edi ; save IP for ARP_output_request
; Now create the ARP entry ; Now create the ARP entry
pushw ARP_REQUEST_TTL ; TTL pushw ARP_REQUEST_TTL ; TTL

View File

@ -964,12 +964,16 @@ IPv4_api:
.write_ip: .write_ip:
mov [IP_LIST + eax], ecx mov [IP_LIST + eax], ecx
mov edi, eax ; device number, we'll need it for ARP
; pre-calculate the local broadcast address ; pre-calculate the local broadcast address
mov ebx, [SUBNET_LIST + eax] mov ebx, [SUBNET_LIST + eax]
not ebx not ebx
or ecx, ebx or ebx, ecx
mov [BROADCAST_LIST + eax], ecx mov [BROADCAST_LIST + eax], ebx
mov eax, ecx
call ARP_output_request ; now send a gratuitous ARP
xor eax, eax xor eax, eax
ret ret