Improved loopback device, separate ARP tables for every interface, added arpstat functionality to netstat, preparing zeroconf to work on multiple interfaces, improved API (fn 76, fn 74), fixed some bugs.

git-svn-id: svn://kolibrios.org@3601 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2013-06-05 00:21:20 +00:00
parent c2bc66096c
commit c0fe9dddf7
19 changed files with 420 additions and 431 deletions

View File

@ -187,7 +187,6 @@ FASM_PROGRAMS:=\
media/midamp:MEDIA/MIDAMP:$(PROGS)/media/midamp/trunk/midamp.asm \ media/midamp:MEDIA/MIDAMP:$(PROGS)/media/midamp/trunk/midamp.asm \
media/palitra:MEDIA/PALITRA:$(PROGS)/media/palitra/trunk/palitra.asm \ media/palitra:MEDIA/PALITRA:$(PROGS)/media/palitra/trunk/palitra.asm \
media/startmus:MEDIA/STARTMUS:$(PROGS)/media/startmus/trunk/STARTMUS.ASM \ media/startmus:MEDIA/STARTMUS:$(PROGS)/media/startmus/trunk/STARTMUS.ASM \
network/arpcfg:NETWORK/ARPCFG:$(PROGS)/network/arpcfg/arpcfg.asm \
network/ping:NETWORK/PING:$(PROGS)/network/icmp/ping.asm \ network/ping:NETWORK/PING:$(PROGS)/network/icmp/ping.asm \
network/netcfg:NETWORK/NETCFG:$(PROGS)/network/netcfg/netcfg.asm \ network/netcfg:NETWORK/NETCFG:$(PROGS)/network/netcfg/netcfg.asm \
network/netstat:NETWORK/NETSTAT:$(PROGS)/network/netstat/netstat.asm \ network/netstat:NETWORK/NETSTAT:$(PROGS)/network/netstat/netstat.asm \

View File

@ -131,7 +131,6 @@ Clients > /@17
Zero-Config /sys/network/zeroconf Zero-Config /sys/network/zeroconf
Network Config /sys/network/netcfg Network Config /sys/network/netcfg
Network status /sys/network/netstat Network status /sys/network/netstat
ARP status /sys/network/arpcfg
#16 **** SERVERS **** #16 **** SERVERS ****
FTP daemon /sys/network/ftpd FTP daemon /sys/network/ftpd
#17 **** CLIENTS **** #17 **** CLIENTS ****

View File

@ -187,7 +187,6 @@ FASM_PROGRAMS:=\
media/midamp:MEDIA/MIDAMP:$(PROGS)/media/midamp/trunk/midamp.asm \ media/midamp:MEDIA/MIDAMP:$(PROGS)/media/midamp/trunk/midamp.asm \
media/palitra:MEDIA/PALITRA:$(PROGS)/media/palitra/trunk/palitra.asm \ media/palitra:MEDIA/PALITRA:$(PROGS)/media/palitra/trunk/palitra.asm \
media/startmus:MEDIA/STARTMUS:$(PROGS)/media/startmus/trunk/STARTMUS.ASM \ media/startmus:MEDIA/STARTMUS:$(PROGS)/media/startmus/trunk/STARTMUS.ASM \
network/arpcfg:NETWORK/ARPCFG:$(PROGS)/network/arpcfg/arpcfg.asm \
network/ping:NETWORK/PING:$(PROGS)/network/icmp/ping.asm \ network/ping:NETWORK/PING:$(PROGS)/network/icmp/ping.asm \
network/netcfg:NETWORK/NETCFG:$(PROGS)/network/netcfg/netcfg.asm \ network/netcfg:NETWORK/NETCFG:$(PROGS)/network/netcfg/netcfg.asm \
network/netstat:NETWORK/NETSTAT:$(PROGS)/network/netstat/netstat.asm \ network/netstat:NETWORK/NETSTAT:$(PROGS)/network/netstat/netstat.asm \

View File

@ -130,7 +130,6 @@ Clients > /@17
Zero-Config /sys/network/zeroconf Zero-Config /sys/network/zeroconf
Network Config /sys/network/netcfg Network Config /sys/network/netcfg
Network status /sys/network/netstat Network status /sys/network/netstat
ARP status /sys/network/arpcfg
#16 **** SERVERS **** #16 **** SERVERS ****
FTP daemon /sys/network/ftpd FTP daemon /sys/network/ftpd
#17 **** CLIENTS **** #17 **** CLIENTS ****

View File

@ -187,7 +187,6 @@ FASM_PROGRAMS:=\
media/midamp:MEDIA/MIDAMP:$(PROGS)/media/midamp/trunk/midamp.asm \ media/midamp:MEDIA/MIDAMP:$(PROGS)/media/midamp/trunk/midamp.asm \
media/palitra:MEDIA/PALITRA:$(PROGS)/media/palitra/trunk/palitra.asm \ media/palitra:MEDIA/PALITRA:$(PROGS)/media/palitra/trunk/palitra.asm \
media/startmus:MEDIA/STARTMUS:$(PROGS)/media/startmus/trunk/STARTMUS.ASM \ media/startmus:MEDIA/STARTMUS:$(PROGS)/media/startmus/trunk/STARTMUS.ASM \
network/arpcfg:NETWORK/ARPCFG:$(PROGS)/network/arpcfg/arpcfg.asm \
network/ping:NETWORK/PING:$(PROGS)/network/icmp/ping.asm \ network/ping:NETWORK/PING:$(PROGS)/network/icmp/ping.asm \
network/netcfg:NETWORK/NETCFG:$(PROGS)/network/netcfg/netcfg.asm \ network/netcfg:NETWORK/NETCFG:$(PROGS)/network/netcfg/netcfg.asm \
network/netstat:NETWORK/NETSTAT:$(PROGS)/network/netstat/netstat.asm \ network/netstat:NETWORK/NETSTAT:$(PROGS)/network/netstat/netstat.asm \

View File

@ -136,8 +136,7 @@ HEX-।
Zero-Config /sys/network/zeroconf Zero-Config /sys/network/zeroconf
Network Config /sys/network/netcfg Network Config /sys/network/netcfg
Network status /sys/network/netstat Network status /sys/network/netstat
ARP status /sys/network/arpcfg #16 **** SERVERS ****
#16 **** SERVERS ****
FTP daemon /sys/network/ftpd FTP daemon /sys/network/ftpd
#17 **** CLIENTS **** #17 **** CLIENTS ****
IRC client /sys/network/ircc IRC client /sys/network/ircc

View File

@ -187,7 +187,6 @@ FASM_PROGRAMS:=\
media/midamp:MEDIA/MIDAMP:$(PROGS)/media/midamp/trunk/midamp.asm \ media/midamp:MEDIA/MIDAMP:$(PROGS)/media/midamp/trunk/midamp.asm \
media/palitra:MEDIA/PALITRA:$(PROGS)/media/palitra/trunk/palitra.asm \ media/palitra:MEDIA/PALITRA:$(PROGS)/media/palitra/trunk/palitra.asm \
media/startmus:MEDIA/STARTMUS:$(PROGS)/media/startmus/trunk/STARTMUS.ASM \ media/startmus:MEDIA/STARTMUS:$(PROGS)/media/startmus/trunk/STARTMUS.ASM \
network/arpcfg:NETWORK/ARPCFG:$(PROGS)/network/arpcfg/arpcfg.asm \
network/ping:NETWORK/PING:$(PROGS)/network/icmp/ping.asm \ network/ping:NETWORK/PING:$(PROGS)/network/icmp/ping.asm \
network/netcfg:NETWORK/NETCFG:$(PROGS)/network/netcfg/netcfg.asm \ network/netcfg:NETWORK/NETCFG:$(PROGS)/network/netcfg/netcfg.asm \
network/netstat:NETWORK/NETSTAT:$(PROGS)/network/netstat/netstat.asm \ network/netstat:NETWORK/NETSTAT:$(PROGS)/network/netstat/netstat.asm \

View File

@ -131,7 +131,6 @@ Clientes > /@17
Zero-Config /sys/network/zeroconf Zero-Config /sys/network/zeroconf
Network Config /sys/network/netcfg Network Config /sys/network/netcfg
Network status /sys/network/netstat Network status /sys/network/netstat
ARP status /sys/network/arpcfg
#16 **** SERVIDORES **** #16 **** SERVIDORES ****
FTP daemon /sys/network/ftpd FTP daemon /sys/network/ftpd
#17 **** CLIENTES **** #17 **** CLIENTES ****

View File

@ -32,36 +32,36 @@ ARP_REP_OPCODE = 0x0200 ; reply
ARP_TABLE_SIZE = 20 ; Size of table ARP_TABLE_SIZE = 20 ; Size of table
struct ARP_entry struct ARP_entry
IP dd ? IP dd ?
MAC dp ? MAC dp ?
Status dw ? Status dw ?
TTL dw ? TTL dw ?
ends ends
struct ARP_header struct ARP_header
HardwareType dw ? HardwareType dw ?
ProtocolType dw ? ProtocolType dw ?
HardwareSize db ? HardwareSize db ?
ProtocolSize db ? ProtocolSize db ?
Opcode dw ? Opcode dw ?
SenderMAC dp ? SenderMAC dp ?
SenderIP dd ? SenderIP dd ?
TargetMAC dp ? TargetMAC dp ?
TargetIP dd ? TargetIP dd ?
ends ends
align 4 align 4
uglobal uglobal
NumARP dd ?
ARP_table rb ARP_TABLE_SIZE * sizeof.ARP_entry ; TODO: separate ARP table and stats per interface ARP_table rb NET_DEVICES_MAX*(ARP_TABLE_SIZE * sizeof.ARP_entry)
ARP_entries_num rd NET_DEVICES_MAX
ARP_PACKETS_TX rd NET_DEVICES_MAX ARP_PACKETS_TX rd NET_DEVICES_MAX
ARP_PACKETS_RX rd NET_DEVICES_MAX ARP_PACKETS_RX rd NET_DEVICES_MAX
ARP_CONFLICTS rd NET_DEVICES_MAX ARP_CONFLICTS rd NET_DEVICES_MAX
@ -81,10 +81,8 @@ endg
macro ARP_init { macro ARP_init {
xor eax, eax xor eax, eax
mov [NumARP], eax mov edi, ARP_entries_num
mov ecx, 4*NET_DEVICES_MAX
mov edi, ARP_PACKETS_TX
mov ecx, 3*NET_DEVICES_MAX
rep stosd rep stosd
} }
@ -111,11 +109,15 @@ local .exit
; The last status value is provided to allow the network layer to delete ; The last status value is provided to allow the network layer to delete
; a packet that is queued awaiting an ARP response ; a packet that is queued awaiting an ARP response
mov ecx, [NumARP] xor edi, edi
.loop_outer:
mov ecx, [ARP_entries_num + 4*edi]
test ecx, ecx test ecx, ecx
jz .exit jz .exit
mov esi, ARP_table mov esi, (ARP_TABLE_SIZE * sizeof.ARP_entry)
imul esi, edi
add esi, ARP_table
.loop: .loop:
cmp [esi + ARP_entry.TTL], ARP_STATIC_ENTRY cmp [esi + ARP_entry.TTL], ARP_STATIC_ENTRY
je .next je .next
@ -133,9 +135,9 @@ local .exit
cmp [esi + ARP_entry.Status], ARP_AWAITING_RESPONSE cmp [esi + ARP_entry.Status], ARP_AWAITING_RESPONSE
je .response_timeout je .response_timeout
push esi ecx push esi edi ecx
call ARP_del_entry call ARP_del_entry
pop ecx esi pop ecx edi esi
jmp .next jmp .next
@ -146,6 +148,9 @@ local .exit
jmp .next jmp .next
.exit: .exit:
inc edi
cmp edi, NET_DEVICES_MAX
jb .loop_outer
} }
@ -196,11 +201,13 @@ ARP_input:
DEBUGF DEBUG_NETWORK_VERBOSE, "ARP_input: It's a reply\n" DEBUGF DEBUG_NETWORK_VERBOSE, "ARP_input: It's a reply\n"
mov ecx, [NumARP] mov ecx, [ARP_entries_num + 4*edi]
test ecx, ecx test ecx, ecx
jz .exit jz .exit
mov esi, ARP_table mov esi, (ARP_TABLE_SIZE * sizeof.ARP_entry)
imul esi, edi
add esi, ARP_table
.loop: .loop:
cmp [esi + ARP_entry.IP], eax cmp [esi + ARP_entry.IP], eax
je .gotit je .gotit
@ -298,22 +305,19 @@ ARP_input:
; ;
; ARP_output_request ; ARP_output_request
; ;
; IN: ip in eax ; IN: ebx = device ptr
; device in edi ; eax = IP
; OUT: / ; OUT: /
; scratched: probably everything
; ;
;--------------------------------------------------------------------------- ;---------------------------------------------------------------------------
align 4 align 4
ARP_output_request: ARP_output_request:
push eax ; DestIP push eax
pushd [IP_LIST + edi] ; SenderIP
inc [ARP_PACKETS_TX + edi] ; assume we will succeed
DEBUGF DEBUG_NETWORK_VERBOSE, "ARP_output_request: ip=%u.%u.%u.%u\n",\ DEBUGF DEBUG_NETWORK_VERBOSE, "ARP_output_request: ip=%u.%u.%u.%u device=0x%x\n",\
[esp + 4]:1, [esp + 5]:1, [esp + 6]:1, [esp + 7]:1 [esp]:1, [esp + 1]:1, [esp + 2]:1, [esp + 3]:1, ebx
mov ebx, [NET_DRV_LIST + edi] ; device ptr
lea eax, [ebx + ETH_DEVICE.mac] ; local device mac lea eax, [ebx + ETH_DEVICE.mac] ; local device mac
mov edx, ETH_BROADCAST ; broadcast mac mov edx, ETH_BROADCAST ; broadcast mac
@ -322,8 +326,6 @@ ARP_output_request:
call ETH_output call ETH_output
jz .exit jz .exit
mov ecx, eax
mov [edi + ARP_header.HardwareType], 0x0100 ; Ethernet mov [edi + ARP_header.HardwareType], 0x0100 ; Ethernet
mov [edi + ARP_header.ProtocolType], 0x0008 ; IP mov [edi + ARP_header.ProtocolType], 0x0008 ; IP
mov [edi + ARP_header.HardwareSize], 6 ; MAC-addr length mov [edi + ARP_header.HardwareSize], 6 ; MAC-addr length
@ -331,29 +333,29 @@ ARP_output_request:
mov [edi + ARP_header.Opcode], ARP_REQ_OPCODE ; Request mov [edi + ARP_header.Opcode], ARP_REQ_OPCODE ; Request
add edi, ARP_header.SenderMAC add edi, ARP_header.SenderMAC
lea esi, [ebx + ETH_DEVICE.mac] ; SenderMac lea esi, [ebx + ETH_DEVICE.mac] ; SenderMac
movsw ; movsw ;
movsd ; movsd ;
pop eax ; SenderIP
stosd ;
mov eax, -1 ; DestMac ; mov esi, [ebx + NET_DEVICE.number]
stosd ; xor esi, esi ;;;; FIXME
stosw ; inc esi ;;;;;;;;;
pop eax ; DestIP inc [ARP_PACKETS_TX + 4*esi] ; assume we will succeed
stosd ; lea esi, [IP_LIST + 4*esi] ; SenderIP
movsd
DEBUGF DEBUG_NETWORK_VERBOSE, "ARP_output_request: device=%x\n", ebx mov esi, ETH_BROADCAST ; DestMac
movsw ;
movsd ;
popd [edi] ; DestIP
push edx ecx push edx eax
call [ebx + NET_DEVICE.transmit] call [ebx + NET_DEVICE.transmit]
ret ret
.exit: .exit:
add esp, 4 + 4 add esp, 4
DEBUGF DEBUG_NETWORK_VERBOSE, "ARP_output_request: failed\n" DEBUGF DEBUG_NETWORK_ERROR, "ARP_output_request: send failed\n"
sub eax, eax
ret ret
@ -362,50 +364,65 @@ ARP_output_request:
; ARP_add_entry (or update) ; ARP_add_entry (or update)
; ;
; IN: esi = ptr to entry (can easily be made on the stack) ; IN: esi = ptr to entry (can easily be made on the stack)
; edi = device num
; OUT: eax = entry #, -1 on error ; OUT: eax = entry #, -1 on error
; edi = ptr to newly created entry ; esi = ptr to newly created entry
; ;
;----------------------------------------------------------------- ; TODO: use a mutex ;----------------------------------------------------------------- ; TODO: use a mutex
align 4 align 4
ARP_add_entry: ARP_add_entry:
DEBUGF DEBUG_NETWORK_VERBOSE, "ARP_add_entry: " DEBUGF DEBUG_NETWORK_VERBOSE, "ARP_add_entry: device=%u\n", edi
mov ecx, [NumARP] mov ecx, [ARP_entries_num + 4*edi]
cmp ecx, ARP_TABLE_SIZE ; list full ? cmp ecx, ARP_TABLE_SIZE ; list full ?
jae .error jae .full
xor eax, eax
mov edi, ARP_table ; From this point on, we can only fail if IP has a static entry, or if table is corrupt.
mov ecx, [esi + ARP_entry.IP]
inc [ARP_entries_num + 4*edi] ; assume we will succeed
push edi
xor ecx, ecx
imul edi, ARP_TABLE_SIZE*sizeof.ARP_entry
add edi, ARP_table
mov eax, [edi + ARP_entry.IP]
.loop: .loop:
cmp [edi + ARP_entry.Status], ARP_NO_ENTRY ; is this slot empty? cmp [edi + ARP_entry.Status], ARP_NO_ENTRY ; is this slot empty?
je .add je .add
cmp [edi + ARP_entry.IP], ecx ; if not, check if it doesnt collide cmp [edi + ARP_entry.IP], eax ; if not, check if it doesnt collide
jne .maybe_next jne .maybe_next
cmp [edi + ARP_entry.TTL], ARP_STATIC_ENTRY ; ok, its the same IP, update it if not static cmp [edi + ARP_entry.TTL], ARP_STATIC_ENTRY ; ok, its the same IP, update it if not static
jne .add jne .add
DEBUGF DEBUG_NETWORK_ERROR, "ARP_add_entry: failed, IP already has a static entry\n"
jmp .error
.maybe_next: ; try the next slot .maybe_next: ; try the next slot
add edi, sizeof.ARP_entry add edi, sizeof.ARP_entry
inc eax inc ecx
cmp eax, ARP_TABLE_SIZE cmp ecx, ARP_TABLE_SIZE
jae .error jb .loop
jmp .loop
.add: .add:
push ecx
mov ecx, sizeof.ARP_entry/2 mov ecx, sizeof.ARP_entry/2
rep movsw rep movsw
inc [NumARP] pop ecx
sub edi, sizeof.ARP_entry lea esi, [edi - sizeof.ARP_entry]
DEBUGF DEBUG_NETWORK_VERBOSE, "entry=%u\n", eax pop edi
DEBUGF DEBUG_NETWORK_VERBOSE, "ARP_add_entry: entry=%u\n", ecx
ret ret
.error: .error:
DEBUGF DEBUG_NETWORK_VERBOSE, "failed\n" pop edi
dec [ARP_entries_num + 4*edi]
DEBUGF DEBUG_NETWORK_ERROR, "ARP_add_entry_failed\n"
.full:
mov eax, -1 mov eax, -1
ret ret
@ -414,30 +431,36 @@ ARP_add_entry:
; ;
; ARP_del_entry ; ARP_del_entry
; ;
; IN: esi = ptr to arp entry ; IN: esi = ptr to arp entry
; OUT: / ; edi = device number
; OUT: /
; ;
;----------------------------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
ARP_del_entry: ARP_del_entry:
DEBUGF DEBUG_NETWORK_VERBOSE, "ARP_del_entry: entry=%x entrys=%u\n", esi, [NumARP] DEBUGF DEBUG_NETWORK_VERBOSE, "ARP_del_entry: entry=%x entrys=%u\n", esi, [ARP_entries_num + 4*edi]
DEBUGF DEBUG_NETWORK_VERBOSE, "ARP_del_entry: IP=%u.%u.%u.%u\n", \ DEBUGF DEBUG_NETWORK_VERBOSE, "ARP_del_entry: IP=%u.%u.%u.%u\n", \
[esi + ARP_entry.IP]:1, [esi + ARP_entry.IP + 1]:1, [esi + ARP_entry.IP + 2]:1, [esi + ARP_entry.IP + 3]:1 [esi + ARP_entry.IP]:1, [esi + ARP_entry.IP + 1]:1, [esi + ARP_entry.IP + 2]:1, [esi + ARP_entry.IP + 3]:1
mov ecx, ARP_table + (ARP_TABLE_SIZE - 1) * sizeof.ARP_entry push edi
imul edi, (ARP_TABLE_SIZE) * sizeof.ARP_entry
lea ecx, [ARP_table + (ARP_TABLE_SIZE - 1) * sizeof.ARP_entry + edi]
sub ecx, esi sub ecx, esi
shr ecx, 1 shr ecx, 1
; move all trailing entries, sizeof.ARP_entry bytes to left.
mov edi, esi mov edi, esi
add esi, sizeof.ARP_entry add esi, sizeof.ARP_entry
rep movsw rep movsw
; now add an empty entry to the end (erasing previous one)
xor eax, eax xor eax, eax
mov ecx, sizeof.ARP_entry/2 mov ecx, sizeof.ARP_entry/2
rep stosw rep stosw
dec [NumARP] pop edi
dec [ARP_entries_num + 4*edi]
DEBUGF DEBUG_NETWORK_VERBOSE, "ARP_del_entry: success\n" DEBUGF DEBUG_NETWORK_VERBOSE, "ARP_del_entry: success\n"
ret ret
@ -465,7 +488,7 @@ ARP_IP_to_MAC:
DEBUGF DEBUG_NETWORK_VERBOSE, "ARP_IP_to_MAC: %u.%u", al, ah DEBUGF DEBUG_NETWORK_VERBOSE, "ARP_IP_to_MAC: %u.%u", al, ah
rol eax, 16 rol eax, 16
DEBUGF DEBUG_NETWORK_VERBOSE, ".%u.%u\n", al, ah DEBUGF DEBUG_NETWORK_VERBOSE, ".%u.%u device: %u\n", al, ah, edi
rol eax, 16 rol eax, 16
cmp eax, 0xffffffff cmp eax, 0xffffffff
@ -474,7 +497,7 @@ ARP_IP_to_MAC:
;-------------------------------- ;--------------------------------
; Try to find the IP in ARP_table ; Try to find the IP in ARP_table
mov ecx, [NumARP] mov ecx, [ARP_entries_num + 4*edi]
test ecx, ecx test ecx, ecx
jz .not_in_list jz .not_in_list
mov esi, ARP_table + ARP_entry.IP mov esi, ARP_table + ARP_entry.IP
@ -482,38 +505,41 @@ ARP_IP_to_MAC:
cmp [esi], eax cmp [esi], eax
je .found_it je .found_it
add esi, sizeof.ARP_entry add esi, sizeof.ARP_entry
loop .scan_loop dec ecx
jnz .scan_loop
.not_in_list: .not_in_list:
DEBUGF DEBUG_NETWORK_VERBOSE, "ARP_IP_to_MAC: preparing for ARP request\n" DEBUGF DEBUG_NETWORK_VERBOSE, "ARP_IP_to_MAC: preparing for ARP request\n"
;--------------------
; Send an ARP request
push eax edi ; save IP for ARP_output_request push eax edi ; save IP for ARP_output_request
; Now craft the ARP entry on the stack
; Now create the ARP entry
pushw ARP_REQUEST_TTL ; TTL pushw ARP_REQUEST_TTL ; TTL
pushw ARP_AWAITING_RESPONSE ; status pushw ARP_AWAITING_RESPONSE ; status
pushd 0 ; mac pushd 0 ; mac
pushw 0 pushw 0
pushd eax ; ip pushd eax ; ip
mov esi, esp mov esi, esp
; Add it to the list
call ARP_add_entry call ARP_add_entry
; Delete the temporary entry
add esp, sizeof.ARP_entry ; clear the entry from stack add esp, sizeof.ARP_entry ; clear the entry from stack
; If we could not add it to the list, give up
cmp eax, -1 ; did ARP_add_entry fail? cmp eax, -1 ; did ARP_add_entry fail?
je .full je .full
mov esi, edi
pop edi eax ; IP in eax, device number in edi, for ARP_output_request
push esi edi
call ARP_output_request ; And send a request
pop edi esi
;----------------------------------------------- ;-----------------------------------------------
; At this point, we got an ARP entry in the list ; At this point, we got an ARP entry in the list
; Now send a request packet on the network
pop edi eax ; IP in eax, device number in ebx, for ARP_output_request
push esi edi
mov ebx, [NET_DRV_LIST + 4*edi]
call ARP_output_request
pop edi esi
.found_it: .found_it:
cmp [esi + ARP_entry.Status], ARP_VALID_MAPPING ; Does it have a MAC assigned? cmp [esi + ARP_entry.Status], ARP_VALID_MAPPING ; Does it have a MAC assigned?
je .valid je .valid
@ -522,10 +548,10 @@ if ARP_BLOCK
cmp [esi + ARP_entry.Status], ARP_AWAITING_RESPONSE ; Are we waiting for reply from remote end? cmp [esi + ARP_entry.Status], ARP_AWAITING_RESPONSE ; Are we waiting for reply from remote end?
jne .give_up jne .give_up
push esi push esi edi
mov esi, 10 ; wait 10 ms mov esi, 10 ; wait 10 ms
call delay_ms call delay_ms
pop esi pop edi esi
jmp .found_it ; now check again jmp .found_it ; now check again
else else
@ -536,8 +562,8 @@ end if
.valid: .valid:
DEBUGF DEBUG_NETWORK_VERBOSE, "ARP_IP_to_MAC: found MAC\n" DEBUGF DEBUG_NETWORK_VERBOSE, "ARP_IP_to_MAC: found MAC\n"
movzx eax, word[esi + ARP_entry.MAC] movzx eax, word[edi + ARP_entry.MAC]
mov ebx, dword[esi + ARP_entry.MAC + 2] mov ebx, dword[edi + ARP_entry.MAC + 2]
ret ret
.full: .full:
@ -606,17 +632,19 @@ ARP_api:
ret ret
.entries: .entries:
mov eax, [NumARP] mov eax, [ARP_entries_num + eax]
ret ret
.read: .read:
cmp ecx, [NumARP] cmp ecx, [ARP_entries_num + eax]
jae .error jae .error
shr eax, 2
imul eax, sizeof.ARP_entry*ARP_TABLE_SIZE
add eax, ARP_table
; edi = pointer to buffer ; edi = pointer to buffer
; ecx = # entry ; ecx = # entry
imul ecx, sizeof.ARP_entry imul ecx, sizeof.ARP_entry
add ecx, ARP_table lea esi, [eax + ecx]
mov esi, ecx
mov ecx, sizeof.ARP_entry/2 mov ecx, sizeof.ARP_entry/2
rep movsw rep movsw
@ -625,20 +653,24 @@ ARP_api:
.write: .write:
; esi = pointer to buffer ; esi = pointer to buffer
mov edi, eax
shr edi, 2
call ARP_add_entry ; out: eax = entry number, -1 on error call ARP_add_entry ; out: eax = entry number, -1 on error
ret ret
.remove: .remove:
; ecx = # entry ; ecx = # entry
cmp ecx, [NumARP] cmp ecx, [ARP_entries_num + eax]
jae .error jae .error
imul ecx, sizeof.ARP_entry imul ecx, sizeof.ARP_entry
lea esi, [ARP_table + ecx] lea esi, [ARP_table + ecx]
mov edi, eax
shr edi, 2
call ARP_del_entry call ARP_del_entry
ret ret
.send_announce: .send_announce:
mov edi, eax mov ebx, [NET_DRV_LIST + eax]
mov eax, [IP_LIST + eax] mov eax, [IP_LIST + eax]
call ARP_output_request ; now send a gratuitous ARP call ARP_output_request ; now send a gratuitous ARP
ret ret

View File

@ -568,7 +568,7 @@ IPv4_find_fragment_slot:
align 4 align 4
IPv4_output: IPv4_output:
DEBUGF DEBUG_NETWORK_VERBOSE, "IPv4_output: size=%u\n", ecx DEBUGF DEBUG_NETWORK_VERBOSE, "IPv4_output: size=%u ip=0x%x\n", ecx, eax
cmp ecx, 65500 ; Max IPv4 packet size cmp ecx, 65500 ; Max IPv4 packet size
ja .too_large ja .too_large
@ -585,9 +585,9 @@ IPv4_output:
push ebx ; push the mac onto the stack push ebx ; push the mac onto the stack
push ax push ax
inc [IP_packets_tx + edi] ; update stats inc [IP_packets_tx + 4*edi] ; update stats
mov ebx, [NET_DRV_LIST + edi] mov ebx, [NET_DRV_LIST + 4*edi]
lea eax, [ebx + ETH_DEVICE.mac] lea eax, [ebx + ETH_DEVICE.mac]
mov edx, esp mov edx, esp
mov ecx, [esp + 10 + 6] mov ecx, [esp + 10 + 6]
@ -675,8 +675,8 @@ IPv4_output_raw:
push ebx ; push the mac push ebx ; push the mac
push ax push ax
inc [IP_packets_tx + edi] inc [IP_packets_tx + 4*edi]
mov ebx, [NET_DRV_LIST + edi] mov ebx, [NET_DRV_LIST + 4*edi]
lea eax, [ebx + ETH_DEVICE.mac] lea eax, [ebx + ETH_DEVICE.mac]
mov edx, esp mov edx, esp
mov ecx, [esp + 6 + 4] mov ecx, [esp + 6 + 4]
@ -855,7 +855,7 @@ IPv4_fragment:
; IPv4_route ; IPv4_route
; ;
; IN: eax = Destination IP ; IN: eax = Destination IP
; OUT: edi = device id * 4 ; OUT: edi = device number
; eax = ip of gateway if nescessary, unchanged otherwise ; eax = ip of gateway if nescessary, unchanged otherwise
; ;
;--------------------------------------------------------------------------- ;---------------------------------------------------------------------------
@ -882,15 +882,17 @@ IPv4_route:
jnz .loop jnz .loop
.invalid: .invalid:
xor edi, edi ; if none found, use device 0 as default xor edi, edi ; if none found, use device 1 as default ;;; FIXME
mov eax, [GATEWAY_LIST] inc di
mov eax, [GATEWAY_LIST+4]
.found_it: .found_it:
DEBUGF DEBUG_NETWORK_VERBOSE, "IPv4_route: %u\n", edi DEBUGF DEBUG_NETWORK_VERBOSE, "IPv4_route: %u\n", edi
ret ret
.broadcast: .broadcast:
xor edi, edi xor edi, edi ;;;; FIXME
inc di
ret ret
@ -973,7 +975,8 @@ IPv4_api:
or ebx, ecx or ebx, ecx
mov [BROADCAST_LIST + eax], ebx mov [BROADCAST_LIST + eax], ebx
mov eax, ecx mov ebx, [NET_DRV_LIST + eax]
mov eax, [IP_LIST + eax]
call ARP_output_request ; now send a gratuitous ARP call ARP_output_request ; now send a gratuitous ARP
call NET_send_event call NET_send_event

View File

@ -67,10 +67,10 @@ ETH_input:
cmp ax, ETHER_PROTO_IPv4 cmp ax, ETHER_PROTO_IPv4
je IPv4_input je IPv4_input
cmp ax, ETHER_PROTO_IPv4 cmp ax, ETHER_PROTO_ARP
je ARP_input je ARP_input
cmp ax, ETHER_PROTO_IPv4 cmp ax, ETHER_PROTO_IPv6
je IPv6_input je IPv6_input
cmp ax, ETHER_PROTO_PPP_DISCOVERY cmp ax, ETHER_PROTO_PPP_DISCOVERY
@ -162,7 +162,7 @@ ETH_output:
; ;
; ETH_API ; ETH_API
; ;
; This function is called by system function 75 ; This function is called by system function 76
; ;
; IN: subfunction number in bl ; IN: subfunction number in bl
; device number in bh ; device number in bh
@ -187,39 +187,13 @@ ETH_api:
jmp dword [.table + 4*ebx] jmp dword [.table + 4*ebx]
.table: .table:
dd .packets_tx ; 0 dd .read_mac ; 0
dd .packets_rx ; 1
dd .bytes_tx ; 2
dd .bytes_rx ; 3
dd .read_mac ; 4
dd .state ; 5
.number = ($ - .table) / 4 - 1 .number = ($ - .table) / 4 - 1
.error: .error:
or eax, -1 or eax, -1
ret ret
.packets_tx:
mov eax, [eax + NET_DEVICE.packets_tx]
ret
.packets_rx:
mov eax, [eax + NET_DEVICE.packets_rx]
ret
.bytes_tx:
mov ebx, dword [eax + NET_DEVICE.bytes_tx + 4]
mov eax, dword [eax + NET_DEVICE.bytes_tx]
mov [esp+20+4], ebx ; TODO: fix this ugly code
ret
.bytes_rx:
mov ebx, dword [eax + NET_DEVICE.bytes_rx + 4]
mov eax, dword [eax + NET_DEVICE.bytes_rx]
mov [esp+20+4], ebx ; TODO: fix this ugly code
ret
.read_mac: .read_mac:
movzx ebx, word [eax + ETH_DEVICE.mac] movzx ebx, word [eax + ETH_DEVICE.mac]
@ -227,7 +201,4 @@ ETH_api:
mov [esp+20+4], ebx ; TODO: fix this ugly code mov [esp+20+4], ebx ; TODO: fix this ugly code
ret ret
.state:
mov eax, [eax + NET_DEVICE.link_state]
ret

View File

@ -16,7 +16,6 @@
;; ;; ;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$Revision: 2924 $ $Revision: 2924 $
; ICMP types & codes ; ICMP types & codes
@ -168,16 +167,18 @@ ICMP_input:
mov esi, [esp] ; Start of buffer mov esi, [esp] ; Start of buffer
cmp dword[edi + 4], 1 shl 24 + 127
je .loopback
; Update stats (and validate device ptr) ; Update stats (and validate device ptr)
call NET_ptr_to_num call NET_ptr_to_num
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] inc [ICMP_PACKETS_TX + 4*edi]
cmp ebx, LOOPBACK_DEVICE
je .loopback
; FIXME: dont assume device is an ethernet device!
; 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
push dword [esi + ETH_header.DstMAC] push dword [esi + ETH_header.DstMAC]
@ -188,10 +189,10 @@ ICMP_input:
push word [esi + ETH_header.SrcMAC + 4] push word [esi + ETH_header.SrcMAC + 4]
pop word [esi + ETH_header.DstMAC + 4] pop word [esi + ETH_header.DstMAC + 4]
pop word [esi + ETH_header.SrcMAC + 4] pop word [esi + ETH_header.SrcMAC + 4]
add esi, sizeof.ETH_header-2 add esi, sizeof.ETH_header-4
.loopback: .loopback:
add esi, 2 add esi, 4
push [esi + IPv4_header.SourceAddress] push [esi + IPv4_header.SourceAddress]
push [esi + IPv4_header.DestinationAddress] push [esi + IPv4_header.DestinationAddress]
pop [esi + IPv4_header.SourceAddress] pop [esi + IPv4_header.SourceAddress]

View File

@ -20,26 +20,46 @@ iglobal
LOOPBACK_DEVICE: LOOPBACK_DEVICE:
.device_type dd NET_DEVICE_LOOPBACK .device_type dd NET_DEVICE_LOOPBACK
.mtu dd 4096 .mtu dd 4096
.name dd .namestr .name dd .namestr
.unload dd .dummy_fn .unload dd .dummy_fn
.reset dd .dummy_fn .reset dd .dummy_fn
.transmit dd LOOP_input .transmit dd LOOP_input
.bytes_tx dq 0 .bytes_tx dq 0
.bytes_rx dq 0 .bytes_rx dq 0
.packets_tx dd 0 .packets_tx dd 0
.packets_rx dd 0 .packets_rx dd 0
.namestr db 'loopback', 0 .link_state dd -1
.hwacc dd 0
.namestr db 'loopback', 0
.dummy_fn: .dummy_fn:
ret ret
endg endg
macro LOOP_init {
local .fail
mov ebx, LOOPBACK_DEVICE
call NET_add_device
cmp eax, -1
je .fail
mov [IP_LIST], 127 + 1 shl 24
mov [SUBNET_LIST], 255
mov [BROADCAST_LIST], 0xffffff00 + 127
.fail:
}
;----------------------------------------------------------------- ;-----------------------------------------------------------------
; ;
; LOOP_input ; LOOP_input

View File

@ -433,11 +433,10 @@ SOCKET_bind:
.tcp: .tcp:
.udp: .udp:
mov ebx, [edx + 4] ; First, fill in the IP cmp ebx, [edx + 4] ; First, fill in the IP
test ebx, ebx ; If IP is 0, use default test ebx, ebx ; If IP is 0, use default
jnz @f jnz @f
mov ebx, [NET_DEFAULT] mov ebx, [IP_LIST + 4] ;;;;; FIXME !i!i!i
mov ebx, [IP_LIST + 4*ebx]
@@: @@:
mov [eax + IP_SOCKET.LocalIP], ebx mov [eax + IP_SOCKET.LocalIP], ebx
@ -484,7 +483,7 @@ SOCKET_connect:
.af_inet4: .af_inet4:
cmp [eax + IP_SOCKET.LocalIP], 0 cmp [eax + IP_SOCKET.LocalIP], 0
jne @f jne @f
push [IP_LIST] ; FIXME push [IP_LIST + 4] ; FIXME !i!i!i!
pop [eax + IP_SOCKET.LocalIP] pop [eax + IP_SOCKET.LocalIP]
@@: @@:
@ -515,6 +514,8 @@ align 4
pushd [edx + 4] pushd [edx + 4]
pop [eax + IP_SOCKET.RemoteIP] pop [eax + IP_SOCKET.RemoteIP]
DEBUGF 1, "Connecting to 0x%x\n", [eax + IP_SOCKET.RemoteIP]
cmp [eax + UDP_SOCKET.LocalPort], 0 cmp [eax + UDP_SOCKET.LocalPort], 0
jne @f jne @f
call SOCKET_find_port call SOCKET_find_port
@ -633,7 +634,7 @@ SOCKET_listen:
cmp [eax + IP_SOCKET.LocalIP], 0 cmp [eax + IP_SOCKET.LocalIP], 0
jne @f jne @f
push [IP_LIST] push [IP_LIST + 4] ;;; fixme!!!!
pop [eax + IP_SOCKET.LocalIP] pop [eax + IP_SOCKET.LocalIP]
@@: @@:

View File

@ -217,7 +217,6 @@ align 4
uglobal uglobal
NET_RUNNING dd ? NET_RUNNING dd ?
NET_DEFAULT dd ?
NET_DRV_LIST rd NET_DEVICES_MAX NET_DRV_LIST rd NET_DEVICES_MAX
endg endg
@ -254,6 +253,8 @@ stack_init:
SOCKET_init SOCKET_init
LOOP_init
mov [net_tmr_count], 0 mov [net_tmr_count], 0
ret ret
@ -312,7 +313,7 @@ stack_handler:
align 4 align 4
NET_link_changed: NET_link_changed:
DEBUGF DEBUG_NETWORK_VERBOSE, "NET_link_changed device=0x%x status=0x%x\n", ebx, [ebx + NET_DEVICE.state] DEBUGF DEBUG_NETWORK_VERBOSE, "NET_link_changed device=0x%x status=0x%x\n", ebx, [ebx + NET_DEVICE.link_state]
align 4 align 4
NET_send_event: NET_send_event:
@ -398,7 +399,7 @@ NET_add_device:
; ;
; NET_Remove_Device: ; NET_Remove_Device:
; ;
; This function is called by etwork drivers, ; This function is called by network drivers,
; to unregister network devices from the kernel ; to unregister network devices from the kernel
; ;
; IN: Pointer to device structure in ebx ; IN: Pointer to device structure in ebx
@ -411,28 +412,12 @@ NET_remove_device:
cmp [NET_RUNNING], 0 cmp [NET_RUNNING], 0
je .error je .error
cmp [NET_DRV_LIST], ebx
jne @f
mov [NET_DRV_LIST], 0
cmp [NET_RUNNING], 1
je @f
; there are still active devices, find one and make it default
xor eax, eax
mov ecx, NET_DEVICES_MAX
mov edi, NET_DRV_LIST
repe scasd
je @f
shr edi, 2
dec edi
mov [NET_DEFAULT], edi
@@:
;---------------------------- ;----------------------------
; Find the driver in the list ; Find the driver in the list
mov eax, ebx mov eax, ebx
mov ecx, NET_DEVICES_MAX mov ecx, NET_DEVICES_MAX
mov edi, NET_DRV_LIST+4 mov edi, NET_DRV_LIST
repne scasd repne scasd
jnz .error jnz .error
@ -442,10 +427,11 @@ NET_remove_device:
xor eax, eax xor eax, eax
mov dword [edi-4], eax mov dword [edi-4], eax
dec [NET_RUNNING]
call NET_send_event call NET_send_event
dec [NET_RUNNING] xor eax, eax
ret ret
.error: .error:
@ -610,17 +596,18 @@ checksum_2:
;---------------------------------------------------------------- ;----------------------------------------------------------------
; ;
; System function to work with network devices (75) ; System function to work with network devices (74)
; ;
;---------------------------------------------------------------- ;----------------------------------------------------------------
align 4 align 4
sys_network: ; FIXME: make default device easily accessible sys_network:
cmp ebx, -1 cmp ebx, -1
jne @f jne @f
mov eax, [NET_RUNNING] mov eax, [NET_RUNNING]
jmp .return mov [esp+32], eax
ret
@@: @@:
cmp bh, NET_DEVICES_MAX ; Check if device number exists cmp bh, NET_DEVICES_MAX ; Check if device number exists
@ -647,16 +634,20 @@ sys_network: ; FIXME: make default device easily accessible
dd .stop ; 3 dd .stop ; 3
dd .get_ptr ; 4 dd .get_ptr ; 4
dd .get_drv_name ; 5 dd .get_drv_name ; 5
dd .packets_tx ; 6
dd .packets_rx ; 7
dd .bytes_tx ; 8
dd .bytes_rx ; 9
dd .state ; 10
.number = ($ - .table) / 4 - 1 .number = ($ - .table) / 4 - 1
.get_type: ; 0 = Get device type (ethernet/token ring/...) .get_type:
mov eax, [eax + NET_DEVICE.device_type] mov eax, [eax + NET_DEVICE.device_type]
jmp .return mov [esp+32], eax
ret
.get_dev_name: ; 1 = Get device name
.get_dev_name:
mov esi, [eax + NET_DEVICE.name] mov esi, [eax + NET_DEVICE.name]
mov edi, ecx mov edi, ecx
@ -664,38 +655,66 @@ sys_network: ; FIXME: make default device easily accessible
rep movsd rep movsd
xor eax, eax xor eax, eax
jmp .return mov [esp+32], eax
ret
.reset: ; 2 = Reset the device
.reset:
call [eax + NET_DEVICE.reset] call [eax + NET_DEVICE.reset]
jmp .return mov [esp+32], eax
ret
.stop: ; 3 = Stop driver for this device
.stop:
call [eax + NET_DEVICE.unload] call [eax + NET_DEVICE.unload]
jmp .return mov [esp+32], eax
ret
.get_ptr: ; 4 = Get driver pointer .get_ptr:
mov [esp+32], eax
jmp .return ret
.get_drv_name: ; 5 = Get driver name .get_drv_name:
xor eax, eax xor eax, eax
jmp .return mov [esp+32], eax
ret
.packets_tx:
mov eax, [eax + NET_DEVICE.packets_tx]
mov [esp+32], eax
ret
.packets_rx:
mov eax, [eax + NET_DEVICE.packets_rx]
mov [esp+32], eax
ret
.bytes_tx:
mov ebx, dword [eax + NET_DEVICE.bytes_tx + 4]
mov [esp+20], ebx
mov eax, dword [eax + NET_DEVICE.bytes_tx]
mov [esp+32], eax
ret
.bytes_rx:
mov ebx, dword [eax + NET_DEVICE.bytes_rx + 4]
mov [esp+20], ebx
mov eax, dword [eax + NET_DEVICE.bytes_rx]
mov [esp+32], eax
ret
.state:
mov eax, [eax + NET_DEVICE.link_state]
mov [esp+32], eax
ret
.doesnt_exist: .doesnt_exist:
mov eax, -1 mov dword[esp+32], -1
.return:
mov [esp+32], eax
ret ret
;---------------------------------------------------------------- ;----------------------------------------------------------------
; ;
; System function to work with protocols (76) ; System function to work with protocols (76)

View File

@ -675,7 +675,7 @@ lock xadd [DNSrequestID], eax ; atomically increment ID, get old value
mov eax, 0x01000100 mov eax, 0x01000100
stosd stosd
; 7. Get DNS server address. ; 7. Get DNS server address.
mcall 76, API_IPv4 + 4 ; protocol IP=0, device number=0, function=get DNS address mcall 76, API_IPv4 + (1 shl 8) + 4 ; protocol IP=0, device number=0, function=get DNS address
cmp eax, -1 cmp eax, -1
je .ret.dnserr je .ret.dnserr
mov esi, eax ; put server address to esi mov esi, eax ; put server address to esi

View File

@ -1,156 +0,0 @@
;
; ARPmanager for KolibriOS
;
; hidnplayr@gmail.com
;
format binary as ""
use32
org 0x0
db 'MENUET01' ; 8 byte id
dd 0x01 ; header version
dd START ; start of code
dd IM_END ; size of image
dd (I_END+0x100) ; memory for app
dd (I_END+0x100) ; esp
dd 0x0 , 0x0 ; I_Param , I_Icon
include '../macros.inc'
purge mov, add, sub
include '../struct.inc'
include '../network.inc'
START:
redraw:
mcall 12, 1
mcall 0, 100 shl 16 + 520, 100 shl 16 + 240, 0x34bcbcbc, , str_name
mcall 4, 25 shl 16 + 31, 0x80000000, str_legend
mcall 12, 2
draw_stats:
mov edx, 50 shl 16 + 50
mov [last], 0
.loop:
mcall 76, API_ARP + 3, [last],,, arp_buf
cmp eax, -1
je mainloop
mcall 4, edx, 0x80000000, str_entry
mov edx, ebx
mov eax, 47
mov ebx, 0x00030000
mov esi, 0x40000000
mov edi, 0x00bcbcbc
xor ecx, ecx
mov cl, byte[arp_buf.IP+0]
mcall
mov cl, byte[arp_buf.IP+1]
add edx, 24 shl 16
mcall
mov cl, byte[arp_buf.IP+2]
add edx, 24 shl 16
mcall
mov cl, byte[arp_buf.IP+3]
add edx, 24 shl 16
mcall
mov ebx, 0x00020100
mov cl, byte[arp_buf.MAC+0]
add edx, 36 shl 16
mcall
mov cl, byte[arp_buf.MAC+1]
add edx, 18 shl 16
mcall
mov cl, byte[arp_buf.MAC+2]
add edx, 18 shl 16
mcall
mov cl, byte[arp_buf.MAC+3]
add edx, 18 shl 16
mcall
mov cl, byte[arp_buf.MAC+4]
add edx, 18 shl 16
mcall
mov cl, byte[arp_buf.MAC+5]
add edx, 18 shl 16
mcall
mov ebx, 0x00040000
mov cx, [arp_buf.status]
add edx, 30 shl 16
mcall
mov cx, [arp_buf.TTL]
add edx, 60 shl 16
mcall
add dx, 20
rol edx, 16
mov dx, 50
rol edx, 16
inc [last]
jmp .loop
mainloop:
mcall 23,50 ; wait for event with timeout (0,5 s)
cmp eax, 1
je redraw
cmp eax, 2
je key
cmp eax, 3
je button
jmp draw_stats
key:
mcall 2
jmp mainloop
button: ; button
mcall 17 ; get id
cmp ah, 1
je exit
jmp redraw
exit:
mcall -1
; DATA AREA
str_name db 'ARP manager', 0
str_legend db '# IP-address MAC-address Status TTL', 0
str_entry db ' . . . - - - - - s', 0
IM_END:
last dd ?
arp_buf ARP_entry
I_END:

View File

@ -18,13 +18,13 @@ use32
org 0x0 org 0x0
db 'MENUET01' ; 8 byte id db 'MENUET01' ; 8 byte id
dd 0x01 ; header version dd 0x01 ; header version
dd START ; start of code dd START ; start of code
dd I_END ; size of image dd I_END ; size of image
dd (I_END+0x100) ; memory for app dd (I_END+0x1000) ; memory for app
dd (I_END+0x100) ; esp dd (I_END+0x1000) ; esp
dd I_PARAM , 0x0 ; I_Param , I_Icon dd 0, 0 ; I_Param , I_Path
include '..\macros.inc' include '..\macros.inc'
include '..\network.inc' include '..\network.inc'
@ -38,17 +38,21 @@ redraw:
call draw_interfaces call draw_interfaces
xor ebx, ebx
mov bh, [device]
mcall 74
mov [device_type], eax
mov edx, 101 mov edx, 101
mov esi, 0x00aaaaff mov esi, 0x00aaaaff
mov edi, 0x00aaffff mov edi, 0x00aaffff
cmp dl, [mode] cmp dl, [mode]
cmove esi, edi cmove esi, edi
mcall 8, 25 shl 16 + 65, 25 shl 16 + 20 mcall 8, 5 shl 16 + 55, 5 shl 16 + 20
.morebuttons: .morebuttons:
inc edx inc edx
add ebx, 75 shl 16 add ebx, 60 shl 16
mov esi, 0x00aaaaff mov esi, 0x00aaaaff
cmp dl, [mode] cmp dl, [mode]
@ -58,12 +62,12 @@ redraw:
cmp edx, 105 cmp edx, 105
jle .morebuttons jle .morebuttons
mcall 4, 28 shl 16 + 31, 0x80000000, modes mcall 4, 8 shl 16 + 11, 0x80000000, modes
cmp [mode], 101 cmp [mode], 101
jne .no_eth jne .no_eth
mcall 4, 20 shl 16 + 75, 0x80000000, str_packets_tx mcall 4, 8 shl 16 + 35, 0x80000000, str_packets_tx
add ebx, 18 add ebx, 18
mov edx, str_packets_rx mov edx, str_packets_rx
mcall mcall
@ -74,19 +78,23 @@ redraw:
mov edx, str_bytes_rx mov edx, str_bytes_rx
mcall mcall
add ebx, 18 add ebx, 18
mov edx, str_MAC
mcall
add ebx, 18
mov edx, str_link mov edx, str_link
mcall mcall
mov ebx, API_ETH + 4 cmp [device_type], 1
jne end_of_draw
add ebx, 18
mov edx, str_MAC
mcall
mov ebx, API_ETH
mov bh, [device] mov bh, [device]
mcall 76 mcall 76
push eax push eax
push bx push bx
mov edx, 135 shl 16 + 75 + 4*18 mov edx, 135 shl 16 + 35 + 5*18
call draw_mac call draw_mac
jmp end_of_draw jmp end_of_draw
@ -95,7 +103,7 @@ redraw:
cmp [mode], 102 cmp [mode], 102
jne .no_ip jne .no_ip
mcall 4, 20 shl 16 + 75, 0x80000000, str_packets_tx mcall 4, 8 shl 16 + 35, 0x80000000, str_packets_tx
add ebx, 18 add ebx, 18
mov edx, str_packets_rx mov edx, str_packets_rx
mcall mcall
@ -133,7 +141,7 @@ redraw:
mcall 76 mcall 76
push eax push eax
mov edx, 135 shl 16 + 75 + 2*18 mov edx, 135 shl 16 + 35 + 2*18
call draw_ip call draw_ip
add edx, 18 add edx, 18
@ -152,7 +160,7 @@ redraw:
cmp [mode], 103 cmp [mode], 103
jne .no_arp jne .no_arp
mcall 4, 20 shl 16 + 75, 0x80000000, str_packets_tx mcall 4, 8 shl 16 + 35, 0x80000000, str_packets_tx
add ebx, 18 add ebx, 18
mov edx, str_packets_rx mov edx, str_packets_rx
mcall mcall
@ -163,11 +171,13 @@ redraw:
mov edx, str_conflicts mov edx, str_conflicts
mcall mcall
mcall 4, 8 shl 16 + 130, 0x80000000, str_ARP_legend
jmp end_of_draw jmp end_of_draw
.no_arp: .no_arp:
mcall 4, 20 shl 16 + 75, 0x80000000, str_packets_tx mcall 4, 8 shl 16 + 35, 0x80000000, str_packets_tx
add ebx, 18 add ebx, 18
mov edx, str_packets_rx mov edx, str_packets_rx
@ -196,26 +206,24 @@ draw_stats:
mov ebx, API_ETH mov ebx, API_ETH
mov bh, [device] mov bh, [device]
mov bl, 6
@@: @@:
push ebx push ebx
mcall 76 mcall 74
pop ebx pop ebx
push eax push eax
inc bl inc bl
cmp bl, 3 cmp bl, 10
jbe @r jbe @r
inc bl
mcall 76
push eax
mov ebx, 0x000a0000 mov ebx, 0x000a0000
pop ecx pop ecx
mov edx, 135 shl 16 + 75 + 5*18 mov edx, 135 shl 16 + 35 + 4*18
mov esi, 0x40000000 mov esi, 0x40000000
mov edi, 0x00bcbcbc mov edi, 0x00bcbcbc
mcall 47 mcall 47
sub edx, 18*2 sub edx, 18
pop ecx pop ecx
mcall mcall
@ -255,7 +263,7 @@ not_101:
mov ebx, 0x000a0000 mov ebx, 0x000a0000
pop ecx pop ecx
mov edx, 135 shl 16 + 75 + 18 mov edx, 135 shl 16 + 35 + 18
mov esi, 0x40000000 mov esi, 0x40000000
mov edi, 0x00bcbcbc mov edi, 0x00bcbcbc
mcall 47 mcall 47
@ -299,7 +307,7 @@ not_102:
mov ebx, 0x000a0000 mov ebx, 0x000a0000
pop ecx pop ecx
mov edx, 135 shl 16 + 75 + 3*18 mov edx, 135 shl 16 + 35 + 3*18
mov esi, 0x40000000 mov esi, 0x40000000
mov edi, 0x00bcbcbc mov edi, 0x00bcbcbc
mcall 47 mcall 47
@ -316,7 +324,84 @@ not_102:
pop ecx pop ecx
mcall mcall
jmp mainloop
mov edx, 50 shl 16 + 150
mov [last], 0
.arp_loop:
mov ebx, API_ARP + 3
mov bh, [device]
mcall 76, , [last],,, arp_buf
cmp eax, -1
je mainloop
mcall 4, 20 shl 16 + 140, 0x80000000, str_ARP_entry
mov edx, ebx
mov eax, 47
mov ebx, 0x00030000
mov esi, 0x40000000
mov edi, 0x00bcbcbc
xor ecx, ecx
mov cl, byte[arp_buf.IP+0]
mcall
mov cl, byte[arp_buf.IP+1]
add edx, 24 shl 16
mcall
mov cl, byte[arp_buf.IP+2]
add edx, 24 shl 16
mcall
mov cl, byte[arp_buf.IP+3]
add edx, 24 shl 16
mcall
mov ebx, 0x00020100
mov cl, byte[arp_buf.MAC+0]
add edx, 36 shl 16
mcall
mov cl, byte[arp_buf.MAC+1]
add edx, 18 shl 16
mcall
mov cl, byte[arp_buf.MAC+2]
add edx, 18 shl 16
mcall
mov cl, byte[arp_buf.MAC+3]
add edx, 18 shl 16
mcall
mov cl, byte[arp_buf.MAC+4]
add edx, 18 shl 16
mcall
mov cl, byte[arp_buf.MAC+5]
add edx, 18 shl 16
mcall
mov ebx, 0x00040000
mov cx, [arp_buf.status]
add edx, 30 shl 16
mcall
mov cx, [arp_buf.TTL]
add edx, 60 shl 16
mcall
add dx, 18
rol edx, 16
mov dx, 8
rol edx, 16
inc [last]
jmp .arp_loop
not_103: not_103:
@ -338,7 +423,7 @@ not_103:
mov ebx, 0x000a0000 mov ebx, 0x000a0000
pop ecx pop ecx
mov edx, 135 shl 16 + 75 + 18 mov edx, 135 shl 16 + 35 + 18
mov esi, 0x40000000 mov esi, 0x40000000
mov edi, 0x00bcbcbc mov edi, 0x00bcbcbc
mcall 47 mcall 47
@ -369,7 +454,7 @@ not_104:
mov ebx, 0x000a0000 mov ebx, 0x000a0000
pop ecx pop ecx
mov edx, 135 shl 16 + 75 + 18 mov edx, 135 shl 16 + 35 + 18
mov esi, 0x40000000 mov esi, 0x40000000
mov edi, 0x00bcbcbc mov edi, 0x00bcbcbc
mcall 47 mcall 47
@ -412,7 +497,7 @@ not_105:
mov ebx, 0x000a0000 mov ebx, 0x000a0000
pop ecx pop ecx
mov edx, 135 shl 16 + 75 + 18*3 mov edx, 135 shl 16 + 35 + 18*3
mov esi, 0x40000000 mov esi, 0x40000000
mov edi, 0x00bcbcbc mov edi, 0x00bcbcbc
mcall 47 mcall 47
@ -530,8 +615,8 @@ draw_ip:
draw_interfaces: draw_interfaces:
mov [.btnpos], 8 shl 16 + 20 mov [.btnpos], 5 shl 16 + 20
mov [.txtpos], 490 shl 16 + 15 mov [.txtpos], 455 shl 16 + 12
mcall 74, -1 ; get number of active network devices mcall 74, -1 ; get number of active network devices
mov ecx, eax mov ecx, eax
@ -539,8 +624,8 @@ draw_interfaces:
xor ebx, ebx ; get device type xor ebx, ebx ; get device type
.loop: .loop:
mcall 74 mcall 74
cmp eax, 1 ; ethernet? cmp eax, 1 ; loopback or ethernet?
je .hit jbe .hit
inc bh inc bh
jb .loop ; tried all 256? jb .loop ; tried all 256?
ret ret
@ -553,17 +638,17 @@ draw_interfaces:
mov esi, 0x00aaaaff mov esi, 0x00aaaaff
cmp bh, [device] cmp bh, [device]
cmove esi, 0x00aaffff cmove esi, 0x00aaffff
mcall 8, 485 shl 16 + 100, [.btnpos] mcall 8, 450 shl 16 + 135, [.btnpos]
mov ebx, [esp] mov ebx, [esp]
inc bl inc bl
mov ecx, namebuf mov ecx, namebuf
mov edx, namebuf mov edx, namebuf
mcall 74 ; get device name mcall 74 ; get device name
cmp eax, -1 cmp eax, -1
jne @f jne @f
mov edx, str_unknown mov edx, str_unknown
@@: @@:
mcall 4, [.txtpos], 0x80000000 ; print the name mcall 4, [.txtpos], 0x80000000 ; print the name
pop ebx ecx pop ebx ecx
inc bh inc bh
@ -587,7 +672,9 @@ draw_interfaces:
name db 'Netstat', 0 name db 'Netstat', 0
mode db 101 mode db 101
device db 0 device db 0
modes db 'Ethernet IPv4 ARP ICMP UDP TCP', 0 device_type dd 0
last dd 0
modes db 'Physical IPv4 ARP ICMP UDP TCP', 0
str_packets_tx db 'Packets sent:', 0 str_packets_tx db 'Packets sent:', 0
str_packets_rx db 'Packets received:', 0 str_packets_rx db 'Packets received:', 0
@ -605,9 +692,11 @@ str_missed db 'Packets missed:',0
str_dumped db 'Packets dumped:',0 str_dumped db 'Packets dumped:',0
str_link db 'Link state:',0 str_link db 'Link state:',0
namebuf rb 64 str_ARP_legend db 'IP-address MAC-address Status TTL', 0
str_ARP_entry db ' . . . - - - - - s', 0
I_PARAM rb 1024 namebuf rb 64
arp_buf ARP_entry
I_END: I_END:

View File

@ -141,7 +141,9 @@ START:
DEBUGF 1,">Zero-config service loaded\n" DEBUGF 1,">Zero-config service loaded\n"
.wait: .wait:
mcall 76, API_ETH + 4 ; get MAC of ethernet interface 0 mov ebx, API_ETH + 0
mov bh, [device]
mcall 76 ; get MAC of ethernet interface 1
cmp eax, -1 cmp eax, -1
jne .start jne .start
@ -342,10 +344,15 @@ request:
call dhcp_end call dhcp_end
mcall 76, API_IPv4 + 3, [dhcp.ip] ; ip mov ebx, API_IPv4 + 3
mcall 76, API_IPv4 + 5, [dhcp.dns] ; dns mov bh, [device]
mcall 76, API_IPv4 + 7, [dhcp.subnet] ; subnet mcall 76, , [dhcp.ip] ; ip
mcall 76, API_IPv4 + 9, [dhcp.gateway] ; gateway mov bl, 5
mcall 76, , [dhcp.dns] ; dns
mov bl, 7
mcall 76, , [dhcp.subnet] ; subnet
mov bl, 9
mcall 76, , [dhcp.gateway] ; gateway
jmp exit jmp exit
@ -479,11 +486,16 @@ link_local:
mov cx, ax mov cx, ax
shl ecx, 16 shl ecx, 16
mov cx, 0xfea9 ; IP 169.254.0.0 link local net, see RFC3927 mov cx, 0xfea9 ; IP 169.254.0.0 link local net, see RFC3927
mcall 76, API_IPv4 + 3, ecx ; mask is 255.255.0.0 mov ebx, API_IPv4 + 3
mov bh, [device]
mcall 76, , ecx ; mask is 255.255.0.0
DEBUGF 1,"Link Local IP assinged: 169.254.%u.%u\n", [generator+0]:1, [generator+1]:1 DEBUGF 1,"Link Local IP assinged: 169.254.%u.%u\n", [generator+0]:1, [generator+1]:1
mcall 76, API_IPv4 + 7, 0xffff mov bl, 7
mcall 76, API_IPv4 + 9, 0x0 mcall 76, , 0xffff
mcall 76, API_IPv4 + 5, 0x0 mov bl, 9
mcall 76, , 0x0
mov bl, 5
mcall 76, , 0x0
mcall 5, PROBE_WAIT*100 mcall 5, PROBE_WAIT*100
@ -506,7 +518,9 @@ link_local:
mcall 5 mcall 5
DEBUGF 1,"Sending Probe\n" DEBUGF 1,"Sending Probe\n"
mcall 76, API_ARP + 6 mov ebx, API_ARP + 6
mov bh, [device]
mcall 76
inc esi inc esi
cmp esi, PROBE_NUM cmp esi, PROBE_NUM
@ -521,7 +535,9 @@ link_local:
announce_loop: announce_loop:
DEBUGF 1,"Sending Announce\n" DEBUGF 1,"Sending Announce\n"
mcall 76, API_ARP + 6 mov ebx, API_ARP + 6
mov bh, [device]
mcall 76
inc esi inc esi
cmp esi,ANNOUNCE_NUM cmp esi,ANNOUNCE_NUM
@ -594,6 +610,7 @@ path db '/sys/network.ini'
IM_END: IM_END:
device db 1
inibuf rb 16 inibuf rb 16
dhcpMsgType db ? dhcpMsgType db ?