From 061e9e3bd8b149c283e76e67dc9b2a73a50d8363 Mon Sep 17 00:00:00 2001 From: hidnplayr Date: Mon, 20 Jul 2015 14:05:04 +0000 Subject: [PATCH] Zeroconfig: Support for multiple network devices. Allow static DNS when using DHCP. Netstat: New window for IP configuration. network.ini: New format that allows configuring more then one network device. git-svn-id: svn://kolibrios.org@5586 a494cfbc-eb01-0410-851d-a64ba20cac60 --- data/eng/settings/network.ini | 20 +- data/et/settings/network.ini | 20 +- data/it/settings/network.ini | 20 +- data/rus/settings/network.ini | 20 +- data/sp/settings/network.ini | 20 +- programs/network/netstat/ipcfg.inc | 397 +++++++++++ programs/network/netstat/netstat.asm | 144 +++- programs/network/zeroconf/dhcp.inc | 284 ++++---- programs/network/zeroconf/zeroconf.asm | 900 +++++++++++++------------ 9 files changed, 1200 insertions(+), 625 deletions(-) create mode 100644 programs/network/netstat/ipcfg.inc diff --git a/data/eng/settings/network.ini b/data/eng/settings/network.ini index c2c74d1b4..048f6848b 100644 --- a/data/eng/settings/network.ini +++ b/data/eng/settings/network.ini @@ -1,12 +1,18 @@ -[ipconfig] -; type should be static or zeroconf -; zeroconf means the service first tries to contact a DHCP server -; If dhcp is not available, it switches to link-local -type = zeroconf +; General configuration for otherwise unlisted devices. +[ip?] +; type should be dhcp, auto or disabled. +ip_type = auto +dns_type= auto + +; Specific configuration for network device 1. +[ip1] +; type can be dhcp, auto, static or disabled. +ip_type = auto ip = 192.168.1.150 -gateway = 192.168.1.1 -dns = 192.168.1.1 subnet = 255.255.255.0 +gateway = 192.168.1.1 +dns_type= auto +dns = 192.168.1.1 [proxy] ; If Internet connection requires HTTP proxy, set it here diff --git a/data/et/settings/network.ini b/data/et/settings/network.ini index c2c74d1b4..048f6848b 100644 --- a/data/et/settings/network.ini +++ b/data/et/settings/network.ini @@ -1,12 +1,18 @@ -[ipconfig] -; type should be static or zeroconf -; zeroconf means the service first tries to contact a DHCP server -; If dhcp is not available, it switches to link-local -type = zeroconf +; General configuration for otherwise unlisted devices. +[ip?] +; type should be dhcp, auto or disabled. +ip_type = auto +dns_type= auto + +; Specific configuration for network device 1. +[ip1] +; type can be dhcp, auto, static or disabled. +ip_type = auto ip = 192.168.1.150 -gateway = 192.168.1.1 -dns = 192.168.1.1 subnet = 255.255.255.0 +gateway = 192.168.1.1 +dns_type= auto +dns = 192.168.1.1 [proxy] ; If Internet connection requires HTTP proxy, set it here diff --git a/data/it/settings/network.ini b/data/it/settings/network.ini index c2c74d1b4..048f6848b 100644 --- a/data/it/settings/network.ini +++ b/data/it/settings/network.ini @@ -1,12 +1,18 @@ -[ipconfig] -; type should be static or zeroconf -; zeroconf means the service first tries to contact a DHCP server -; If dhcp is not available, it switches to link-local -type = zeroconf +; General configuration for otherwise unlisted devices. +[ip?] +; type should be dhcp, auto or disabled. +ip_type = auto +dns_type= auto + +; Specific configuration for network device 1. +[ip1] +; type can be dhcp, auto, static or disabled. +ip_type = auto ip = 192.168.1.150 -gateway = 192.168.1.1 -dns = 192.168.1.1 subnet = 255.255.255.0 +gateway = 192.168.1.1 +dns_type= auto +dns = 192.168.1.1 [proxy] ; If Internet connection requires HTTP proxy, set it here diff --git a/data/rus/settings/network.ini b/data/rus/settings/network.ini index c2c74d1b4..048f6848b 100644 --- a/data/rus/settings/network.ini +++ b/data/rus/settings/network.ini @@ -1,12 +1,18 @@ -[ipconfig] -; type should be static or zeroconf -; zeroconf means the service first tries to contact a DHCP server -; If dhcp is not available, it switches to link-local -type = zeroconf +; General configuration for otherwise unlisted devices. +[ip?] +; type should be dhcp, auto or disabled. +ip_type = auto +dns_type= auto + +; Specific configuration for network device 1. +[ip1] +; type can be dhcp, auto, static or disabled. +ip_type = auto ip = 192.168.1.150 -gateway = 192.168.1.1 -dns = 192.168.1.1 subnet = 255.255.255.0 +gateway = 192.168.1.1 +dns_type= auto +dns = 192.168.1.1 [proxy] ; If Internet connection requires HTTP proxy, set it here diff --git a/data/sp/settings/network.ini b/data/sp/settings/network.ini index c2c74d1b4..048f6848b 100644 --- a/data/sp/settings/network.ini +++ b/data/sp/settings/network.ini @@ -1,12 +1,18 @@ -[ipconfig] -; type should be static or zeroconf -; zeroconf means the service first tries to contact a DHCP server -; If dhcp is not available, it switches to link-local -type = zeroconf +; General configuration for otherwise unlisted devices. +[ip?] +; type should be dhcp, auto or disabled. +ip_type = auto +dns_type= auto + +; Specific configuration for network device 1. +[ip1] +; type can be dhcp, auto, static or disabled. +ip_type = auto ip = 192.168.1.150 -gateway = 192.168.1.1 -dns = 192.168.1.1 subnet = 255.255.255.0 +gateway = 192.168.1.1 +dns_type= auto +dns = 192.168.1.1 [proxy] ; If Internet connection requires HTTP proxy, set it here diff --git a/programs/network/netstat/ipcfg.inc b/programs/network/netstat/ipcfg.inc new file mode 100644 index 000000000..0182ef4ea --- /dev/null +++ b/programs/network/netstat/ipcfg.inc @@ -0,0 +1,397 @@ +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; ;; +;; Copyright (C) KolibriOS team 2010-2015. All rights reserved. ;; +;; Distributed under terms of the GNU General Public License ;; +;; ;; +;; Written by hidnplayr@kolibrios.org ;; +;; ;; +;; GNU GENERAL PUBLIC LICENSE ;; +;; Version 2, June 1991 ;; +;; ;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +enum_callback: + +ipcfg: + + mcall 40, EVM_MOUSE + EVM_MOUSE_FILTER + EVM_REDRAW + EVM_BUTTON + EVM_KEY + EVM_STACK + +; Create the 'ip..' string with correct device number + call create_str_ini_int + +; Try to read settings from .ini file + invoke ini.get_str, net_ini, str_ini_int, str_ini_ip_type, ini_buf, 16, sz_0 + test eax, eax + jz @f +; If settings not found, use default settings from 'ip?' section + mov dword[str_ini_int], 'ip?' + @@: + +; Read ip/subnet/gateway type + mov [option_ip], op_ip_static + invoke ini.get_str, net_ini, str_ini_int, str_ini_ip_type, ini_buf, 16, sz_0 +; test eax, eax +; jz .disabled + cmp dword[ini_buf], 'dhcp' + jne @f + mov [option_ip], op_ip_auto + @@: + +; Read DNS type + mov [option_dns], op_dns_static + invoke ini.get_str, net_ini, str_ini_int, str_ini_dns_type, ini_buf, 16, sz_0 + cmp dword[ini_buf], 'dhcp' + jne @f + mov [option_dns], op_dns_auto + @@: + +; Read all IP addresses + mov [str_edit_ip], 0 + mov [str_edit_subnet], 0 + mov [str_edit_gateway], 0 + mov [str_edit_dns], 0 + + invoke ini.get_str, net_ini, str_ini_int, str_ini_ip, str_edit_ip, 16, sz_0 + invoke ini.get_str, net_ini, str_ini_int, str_ini_subnet, str_edit_subnet, 16, sz_0 + invoke ini.get_str, net_ini, str_ini_int, str_ini_gateway, str_edit_gateway, 16, sz_0 + invoke ini.get_str, net_ini, str_ini_int, str_ini_dns, str_edit_dns, 16, sz_0 + + invoke edit_set_text, edit_ip, str_edit_ip + invoke edit_set_text, edit_subnet, str_edit_subnet + invoke edit_set_text, edit_gateway, str_edit_gateway + invoke edit_set_text, edit_dns, str_edit_dns + + .parse_settings: + call toggle_editboxes + + .draw: +; get system colors + mcall 48, 3, sc, 40 + + mcall 12, 1 + + mov edx, [sc.work] + or edx, 0x34000000 + xor esi, esi + mov edi, str_title + mcall 0, 50 shl 16 + 200, 30 shl 16 + 200 + + mov ecx, 0x80000000 + or ecx, [sc.work_text] +; mov ebx, 47 shl 16 + 10 +; mov edx, str_mode +; mcall + mov ebx, 59 shl 16 + 35 + mov edx, sz_ip + mcall 4 + mov ebx, 5 shl 16 + 55 + mov edx, sz_subnet + mcall + mov ebx, 29 shl 16 + 75 + mov edx, sz_gateway + mcall +; mov ebx, 47 shl 16 + 80 +; mov edx, str_mode +; mcall + mov ebx, 53 shl 16 + 120 + mov edx, sz_dns + mcall + + invoke edit_box_draw, edit_ip + invoke edit_box_draw, edit_subnet + invoke edit_box_draw, edit_gateway + invoke edit_box_draw, edit_dns + + invoke option_box_draw, Option_boxs1 + invoke option_box_draw, Option_boxs2 + + mcall 8, 80 shl 16 + 100, 150 shl 16 + 16, 2, [sc.work_button] + + mov ecx, 0x80000000 + or ecx, [sc.work_button_text] + mov ebx, 112 shl 16 + 155 + mov edx, sz_apply + mcall 4 + + mcall 12, 2 + + .loop: + mcall 10 + dec eax + jz .draw + dec eax + jz .key + dec eax + jz .btn + + cmp [edit_ip.color], 0xcacaca + je @f + invoke edit_box_mouse, edit_ip + invoke edit_box_mouse, edit_subnet + invoke edit_box_mouse, edit_gateway + @@: + + cmp [edit_dns.color], 0xcacaca + je @f + invoke edit_box_mouse, edit_dns + @@: + + push [option_ip] [option_dns] + invoke option_box_mouse, Option_boxs1 + invoke option_box_mouse, Option_boxs2 + pop ebx eax + cmp eax, [option_ip] + jne @f + cmp ebx, [option_dns] + je .loop + @@: + call toggle_editboxes + jmp .draw + + .btn: + mcall 17 + + test ah , ah + jz .loop + + cmp ah, 2 ; apply + jne .exit + +; Apply settings! + .apply: + xor edi, edi + + cmp [edit_ip.color], 0xcacaca + je .skip_ip + mov [edit_ip.color], 0xffffff + mov esi, str_edit_ip + call validate_ip + test eax, eax + jz @f + mov [edit_ip.color], 0xff4444 + inc edi + @@: + + mov [edit_subnet.color], 0xffffff + mov esi, str_edit_subnet + call validate_ip + test eax, eax + jz @f + mov [edit_subnet.color], 0xff4444 + inc edi + @@: + + mov [edit_gateway.color], 0xffffff + mov esi, str_edit_gateway + call validate_ip + test eax, eax + jz @f + mov [edit_gateway.color], 0xff4444 + inc edi + @@: + .skip_ip: + + cmp [edit_dns.color], 0xcacaca + je .skip_dns + mov [edit_dns.color], 0xffffff + mov esi, str_edit_dns + call validate_ip + test eax, eax + jz @f + mov [edit_dns.color], 0xff4444 + inc edi + @@: + .skip_dns: + + test edi, edi + jnz .draw + +; Settings look valid, save them to the ini file +; Re-create 'ip..' string, we dont want to save to 'ip?' section. + call create_str_ini_int + + cmp [option_ip], op_ip_auto + jne .ip_static + invoke ini.set_str, net_ini, str_ini_int, str_ini_ip_type, sz_dhcp, 4 + jmp @f + .ip_static: + invoke ini.set_str, net_ini, str_ini_int, str_ini_ip_type, sz_static2, 6 + @@: + + cmp [option_dns], op_dns_auto + invoke ini.set_str, net_ini, str_ini_int, str_ini_dns_type, sz_dhcp, 4 + jmp @f + .dns_static: + invoke ini.set_str, net_ini, str_ini_int, str_ini_dns_type, sz_static2, 6 + @@: + + invoke ini.set_str, net_ini, str_ini_int, str_ini_ip, str_edit_ip, [edit_ip.size] + invoke ini.set_str, net_ini, str_ini_int, str_ini_subnet, str_edit_subnet, [edit_subnet.size] + invoke ini.set_str, net_ini, str_ini_int, str_ini_gateway, str_edit_gateway, [edit_gateway.size] + invoke ini.set_str, net_ini, str_ini_int, str_ini_dns, str_edit_dns, [edit_dns.size] + + .exit: + mcall -1 + + .key: + mcall 2 + +; Stupid editbox doesnt allow us to disable edit boxes nor filter input decently, so we do it here. + cmp ah, 13 + je .apply + cmp ah, 8 + je @f + cmp ah, '.' + je @f + cmp ah, '0' + jb .loop + cmp ah, '9' + ja .loop + @@: + cmp [edit_ip.color], 0xffffff + jne @f + invoke edit_box_key, edit_ip + invoke edit_box_key, edit_subnet + invoke edit_box_key, edit_gateway + @@: + + cmp [edit_dns.color], 0xffffff + jne @f + invoke edit_box_key, edit_dns + @@: + + jmp .loop + +toggle_editboxes: + + mov [edit_ip.color], 0xffffff + mov [edit_subnet.color], 0xffffff + mov [edit_gateway.color], 0xffffff + cmp [option_ip], op_ip_static + je @f + mov [edit_ip.color], 0xcacaca + mov [edit_subnet.color], 0xcacaca + mov [edit_gateway.color], 0xcacaca + @@: + + mov [edit_dns.color], 0xffffff + cmp [option_dns], op_dns_static + je @f + mov [edit_dns.color], 0xcacaca + @@: + + ret + + +; in: esi = ptr to ascii ip +; out: eax = 0 - ok / -1 - error +validate_ip: + xor ecx, ecx ; octet count + .outer_loop: + xor ebx, ebx ; current number + inc ecx + .inner_loop: + lodsb ; load one character from ascii string + test al, al + je .finish + cmp al, '.' + je .outer_loop + ; Convert current digit from ascii to bin, if valid + sub al, '0' + jb .invalid + cmp al, 9 + ja .invalid + ; multiply current number by 10 + add bl, bl + jc .invalid + lea ebx, [ebx + 4 * ebx] + test ebx, 0xffffff00 + jnz .invalid + ; add current digit to current number + add bl, al + jc .invalid + jmp .inner_loop + .finish: + cmp cl, 4 + jne .invalid + xor eax, eax + ret + + .invalid: + or eax, -1 + ret + +create_str_ini_int: + movzx eax, [device] + mov ebx, 10 + xor edx, edx + push 0 + @@: + div ebx + add dl, '0' + push edx + test eax, eax + jnz @r + @@: + mov edi, str_ini_int+2 + @@: + pop eax + stosb + test eax, eax + jnz @r + + ret + + +;------------------------- +; DATA + +edit_ip edit_box 100, 80, 30, 0xffffff, 0x6f9480, 0, 0, 0, 15, str_edit_ip, mouse_dd, 0, 0, 1 +edit_subnet edit_box 100, 80, 50, 0xffffff, 0x6f9480, 0, 0, 0, 15, str_edit_subnet, mouse_dd, 0, 0, 1 +edit_gateway edit_box 100, 80, 70, 0xffffff, 0x6f9480, 0, 0, 0, 15, str_edit_gateway, mouse_dd, 0, 0, 1 + +edit_dns edit_box 100, 80, 115, 0xffffff, 0x6f9480, 0, 0, 0, 15, str_edit_dns, mouse_dd, 0, 0, 1 + +op_ip_auto option_box option_ip, 15, 10, 6, 12, 0xffffff, 0, 0, sz_auto, 5 +op_ip_static option_box option_ip, 80, 10, 6, 12, 0xffffff, 0, 0, sz_static, 7 + +op_dns_auto option_box option_dns, 15, 95, 6, 12, 0xffffff, 0, 0, sz_auto, 5 +op_dns_static option_box option_dns, 80, 95, 6, 12, 0xffffff, 0, 0, sz_static, 7 + +option_ip dd op_ip_auto +option_dns dd op_dns_auto +Option_boxs1 dd op_ip_auto, op_ip_static, 0 +Option_boxs2 dd op_dns_auto, op_dns_static, 0 + +net_ini db '/sys/settings/network.ini', 0 + +str_ini_int db 'ip1', 0 + rb 10 +str_ini_ip db 'ip', 0 +str_ini_subnet db 'subnet', 0 +str_ini_gateway db 'gateway', 0 +str_ini_dns db 'dns1', 0 +str_ini_ip_type db 'ip_type', 0 +str_ini_dns_type db 'dns_type', 0 + +sz_0 db 0 +sz_dhcp db 'dhcp', 0 +sz_static2 db 'static', 0 + +str_title db 'IP settings', 0 +sz_ip db 'IP:', 0 +sz_subnet db 'Subnet mask:', 0 +sz_gateway db 'Gateway:', 0 +sz_dns db 'DNS:', 0 +sz_auto db 'Auto', 0 +sz_static db 'Static', 0 +sz_apply db 'Apply', 0 + +str_edit_ip rb 16 +str_edit_subnet rb 16 +str_edit_gateway rb 16 +str_edit_dns rb 16 + +ini_buf rb 16 + +mouse_dd dd ? \ No newline at end of file diff --git a/programs/network/netstat/netstat.asm b/programs/network/netstat/netstat.asm index 078bf5446..57b98ef88 100644 --- a/programs/network/netstat/netstat.asm +++ b/programs/network/netstat/netstat.asm @@ -1,6 +1,6 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; -;; Copyright (C) KolibriOS team 2010-2014. All rights reserved. ;; +;; Copyright (C) KolibriOS team 2010-2015. All rights reserved. ;; ;; Distributed under terms of the GNU General Public License ;; ;; ;; ;; netstat.asm - Network Status Tool for KolibriOS ;; @@ -29,13 +29,30 @@ use32 dd (I_END+0x1000) ; esp dd 0, 0 ; I_Param, I_Path +include '../../proc32.inc' include '../../macros.inc' +include '../../dll.inc' +include '../../develop/libraries/box_lib/trunk/box_lib.mac' + include '../../network.inc' +include 'ipcfg.inc' + START: + + mcall 68, 11 + + stdcall dll.Load, @IMPORT + or eax, eax + jnz exit + mcall 40, EVM_REDRAW + EVM_BUTTON + EVM_STACK2 + EVM_KEY window_redraw: + +; get system colors + mcall 48, 3, sc, 40 + ; Notify kernel of start of window draw mcall 12, 1 @@ -134,6 +151,12 @@ redraw: mov edx, str_bytes_rx mcall add ebx, 18 + mov edx, str_speed_tx + mcall + add ebx, 18 + mov edx, str_speed_rx + mcall + add ebx, 18 mov edx, str_link mcall @@ -150,7 +173,7 @@ redraw: push eax push bx - mov edx, 134 shl 16 + 35 + 5*18 + mov edx, 134 shl 16 + 35 + 7*18 call draw_mac jmp end_of_draw @@ -209,6 +232,12 @@ redraw: add edx, 18 call draw_ip + cmp [device], 0 + je end_of_draw + + mcall 8, 128 shl 16 + 100, 150 shl 16 + 20, 2, [sc.work_button] + mcall 4, 150 shl 16 + 157, [sc.work_button_text], str_ip_cfg, str_ip_cfg.len + jmp end_of_draw .no_ip: @@ -275,38 +304,65 @@ draw_stats: cmp bl, 10 jbe @r - pop eax - test al, al + pop ecx + + push [time] + pop [delta_time] + mcall 26, 9 + mov [time], eax + sub eax, [delta_time] + jnz @f + inc eax ; Zero time units? Lets make it at least one. + @@: + mov [delta_time], eax + + mov eax, [esp+4] ; bytes received + push eax + sub eax, [prev_rx] + pop [prev_rx] + xor edx, edx + div [delta_time] + push eax + + mov eax, [esp+4] ; bytes sent + push eax + sub eax, [prev_tx] + pop [prev_tx] + xor edx, edx + div [delta_time] + push eax + + test cl, cl jnz @f mov edx, str_down jmp .print_link @@: - cmp al, 100b + cmp cl, 100b jnz @f mov edx, str_10m jmp .print_link @@: - cmp al, 110b + cmp cl, 110b jnz @f mov edx, str_10mfd jmp .print_link @@: - cmp al, 1000b + cmp cl, 1000b jnz @f mov edx, str_100m jmp .print_link @@: - cmp al, 1010b + cmp cl, 1010b jnz @f mov edx, str_100mfd jmp .print_link @@: - cmp al, 1100b + cmp cl, 1100b jnz @f mov edx, str_1g jmp .print_link @@: - cmp al, 1110b + cmp cl, 1110b jnz @f mov edx, str_1gfd jmp .print_link @@ -314,25 +370,39 @@ draw_stats: mov edx, str_unknown .print_link: - mov ebx, 134 shl 16 + 35 + 4*18 + mov ebx, 134 shl 16 + 35 + 6*18 mov ecx, 0xc0000000 mov edi, 0x00f3f3f3 mcall 4 +; speed tx mov ebx, 0x000a0000 pop ecx - mov edx, 134 shl 16 + 35 + 3*18 + mov edx, 134 shl 16 + 35 + 5*18 mov esi, 0x40000000 mcall 47 +; speed rx sub edx, 18 pop ecx mcall +; bytes received sub edx, 18 pop ecx mcall +; bytes sent + sub edx, 18 + pop ecx + mcall + +; packets received + sub edx, 18 + pop ecx + mcall + +; packets sent sub edx, 18 pop ecx mcall @@ -646,12 +716,18 @@ button: ; button mcall 17 ; get id cmp ah, 1 je exit + cmp ah, 2 + je .ipcfg cmp ah, 0 je .interface shr ax, 8 mov [mode], ax jmp redraw + .ipcfg: + mcall 51, 1, ipcfg, I_END+0x1000 + jmp mainloop + .interface: shr eax, 16 mov [device], al @@ -818,6 +894,31 @@ draw_interfaces: ; DATA AREA +align 16 +@IMPORT: + +library box_lib , 'box_lib.obj', \ + libini , 'libini.obj' + +import libini, \ + ini.get_str , 'ini_get_str' ,\ + ini.set_str , 'ini_set_str' ,\ + ini.enum_sections, 'ini_enum_sections' + +import box_lib ,\ + edit_box_draw , 'edit_box' ,\ + edit_box_key , 'edit_box_key' ,\ + edit_box_mouse , 'edit_box_mouse' ,\ + edit_set_text , 'edit_box_set_text' ,\ + version_ed , 'version_ed' ,\ + init_checkbox , 'init_checkbox2' ,\ + check_box_draw , 'check_box_draw2' ,\ + check_box_mouse , 'check_box_mouse2' ,\ + version_ch , 'version_ch2' ,\ + option_box_draw , 'option_box_draw' ,\ + option_box_mouse, 'option_box_mouse' ,\ + version_op , 'version_op' + name db 'Network status', 0 mode dw 101 ; currently selected protocol device db 1 ; currently selected device @@ -837,10 +938,14 @@ str_subnet db 'Subnet mask: . . .', 0 str_gateway db 'Standard gateway: . . .', 0 str_arp db 'ARP entrys:', 0 str_conflicts db 'ARP conflicts:', 0 -str_missed db 'Packets missed:',0 -str_dumped db 'Packets dumped:',0 -str_queued db 'Packets queued:',0 -str_link db 'Link state:',0 +str_missed db 'Packets missed:', 0 +str_dumped db 'Packets dumped:', 0 +str_queued db 'Packets queued:', 0 +str_link db 'Link state:', 0 +str_speed_tx db 'Upload (kb/s):', 0 +str_speed_rx db 'Download (kb/s):', 0 +str_ip_cfg db 'Configure' +.len = $ - str_ip_cfg str_down db 'disconnected ', 0 str_unknown db 'unknown ', 0 @@ -854,7 +959,14 @@ str_1gfd db '1 Gbit Full duplex ', 0 str_ARP_legend db 'IP-address MAC-address Status TTL', 0 str_ARP_entry db ' . . . - - - - -', 0 +prev_rx dd ? +prev_tx dd ? +time dd ? +delta_time dd ? + namebuf rb 64 arp_buf ARP_entry +sc system_colors + I_END: \ No newline at end of file diff --git a/programs/network/zeroconf/dhcp.inc b/programs/network/zeroconf/dhcp.inc index afe6c8fba..867b029d7 100644 --- a/programs/network/zeroconf/dhcp.inc +++ b/programs/network/zeroconf/dhcp.inc @@ -1,126 +1,126 @@ ;Name Number Length Meaning -dhcp_pad_option equ 0 ; 0 None -dhcp_end_option equ 255 ; 0 None -dhcp_subnet_mask equ 1 ; 4 Subnet Mask Value -dhcp_time_offset equ 2 ; 4 Time Offset in Seconds from UTC -dhcp_router equ 3 ; N×4 Router addresses -dhcp_time_server equ 4 ; N×4 Timeserver addresses -dhcp_name_server equ 5 ; N×4 IEN-116 Server addresses -dhcp_domain_server equ 6 ; N×4 DNS Server addresses -dhcp_log_server equ 7 ; N×4 Logging Server addresses -dhcp_quotes_server equ 8 ; N×4 Quotes Server addresses -dhcp_lpr_server equ 9 ; N×4 Printer Server addresses -dhcp_impress_server equ 10 ; N×4 Impress Server addresses -dhcp_rlp_server equ 11 ; N×4 N RLP Server addresses -dhcp_hostname equ 12 ; N Hostname string -dhcp_boot_file_size equ 13 ; 2 Size of boot file in 512-octet blocks -dhcp_merit_dump_file equ 14 ; N Client to dump and name the file to dump it to -dhcp_domain_name equ 15 ; N The DNS domain name of the client -dhcp_swap_server equ 16 ; 4 Swap Server address -dhcp_root_path equ 17 ; N Path name for root disk -dhcp_extension_file equ 18 ; N Path name for more BOOTP info +dhcp_pad_option = 0 ; 0 None +dhcp_end_option = 255 ; 0 None +dhcp_subnet_mask = 1 ; 4 Subnet Mask Value +dhcp_time_offset = 2 ; 4 Time Offset in Seconds from UTC +dhcp_router = 3 ; N×4 Router addresses +dhcp_time_server = 4 ; N×4 Timeserver addresses +dhcp_name_server = 5 ; N×4 IEN-116 Server addresses +dhcp_domain_server = 6 ; N×4 DNS Server addresses +dhcp_log_server = 7 ; N×4 Logging Server addresses +dhcp_quotes_server = 8 ; N×4 Quotes Server addresses +dhcp_lpr_server = 9 ; N×4 Printer Server addresses +dhcp_impress_server = 10 ; N×4 Impress Server addresses +dhcp_rlp_server = 11 ; N×4 N RLP Server addresses +dhcp_hostname = 12 ; N Hostname string +dhcp_boot_file_size = 13 ; 2 Size of boot file in 512-octet blocks +dhcp_merit_dump_file = 14 ; N Client to dump and name the file to dump it to +dhcp_domain_name = 15 ; N The DNS domain name of the client +dhcp_swap_server = 16 ; 4 Swap Server address +dhcp_root_path = 17 ; N Path name for root disk +dhcp_extension_file = 18 ; N Path name for more BOOTP info ;IP Layer Parameters per Host -dhcp_forward equ 19 ; 1 Enable/Disable IP Forwarding -dhcp_srcrte equ 20 ; 1 Enable/Disable Non-Local Source Routing -dhcp_policy equ 21 ; N×8 Non-Local Source Routing Policy Filters -dhcp_mag_dg_assembly equ 22 ; 2 Max Datagram Reassembly Size -dhcp_default_ip_tll equ 23 ; 1 Default IP Time to Live -dhcp_mtu_timeout equ 24 ; 4 Path MTU Aging Timeout -dhcp_mtu_plateau equ 25 ; N×2 Path MTU Plateau Table +dhcp_forward = 19 ; 1 Enable/Disable IP Forwarding +dhcp_srcrte = 20 ; 1 Enable/Disable Non-Local Source Routing +dhcp_policy = 21 ; N×8 Non-Local Source Routing Policy Filters +dhcp_mag_dg_assembly = 22 ; 2 Max Datagram Reassembly Size +dhcp_default_ip_tll = 23 ; 1 Default IP Time to Live +dhcp_mtu_timeout = 24 ; 4 Path MTU Aging Timeout +dhcp_mtu_plateau = 25 ; N×2 Path MTU Plateau Table ;IP Layer Parameters per Interface -dhcp_mtu_interface equ 26 ; 2 Interface MTU Size -dhcp_mtu_subnet equ 27 ; 1 All Subnets are Local -dhcp_broadcast_address equ 28 ; 4 Broadcast Address -dhcp_mask_discovery equ 29 ; 1 Perform Mask Discovery -dhcp_mask_supplier equ 30 ; 1 Provide Mask to Others -dhcp_router_discovery equ 31 ; 1 Perform Router Discovery -dhcp_router_request equ 32 ; 4 Router Solicitation Address -dhcp_static_route equ 33 ; N×8 Static Routing Table +dhcp_mtu_interface = 26 ; 2 Interface MTU Size +dhcp_mtu_subnet = 27 ; 1 All Subnets are Local +dhcp_broadcast_address = 28 ; 4 Broadcast Address +dhcp_mask_discovery = 29 ; 1 Perform Mask Discovery +dhcp_mask_supplier = 30 ; 1 Provide Mask to Others +dhcp_router_discovery = 31 ; 1 Perform Router Discovery +dhcp_router_request = 32 ; 4 Router Solicitation Address +dhcp_static_route = 33 ; N×8 Static Routing Table ;Link Layer Parameters per Interface -dhcp_trailers equ 34 ; 1 Trailer Encapsulation -dhcp_arp_timeout equ 35 ; 4 ARP Cache Timeout -dhcp_ethernet equ 36 ; 1 Ethernet Encapsulation +dhcp_trailers = 34 ; 1 Trailer Encapsulation +dhcp_arp_timeout = 35 ; 4 ARP Cache Timeout +dhcp_ethernet = 36 ; 1 Ethernet Encapsulation ;TCP Parameters -dhcp_default_tcp_tll equ 37 ; 1 Default TCP Time to Live -dhcp_keepalive_time equ 38 ; 4 TCP Keepalive Interval -dhcp_keepalive_data equ 39 ; 1 TCP Keepalive Garbage +dhcp_default_tcp_tll = 37 ; 1 Default TCP Time to Live +dhcp_keepalive_time = 38 ; 4 TCP Keepalive Interval +dhcp_keepalive_data = 39 ; 1 TCP Keepalive Garbage ;Application and Service Parameters -dhcp_nis_domain equ 40 ; N NIS Domain Name -dhcp_nis_servers equ 41 ; N×4 NIS Server Addresses -dhcp_ntp_servers equ 42 ; N×4 NTP Server Addresses -dhcp_vendor_specific equ 43 ; N Vendor Specific Information -dhcp_netbios_name_srv equ 44 ; N×4 NETBIOS Name Servers -dhcp_netbios_dist_srv equ 45 ; N×4 NETBIOS Datagram Distribution -dhcp_netbios_node_type equ 46 ; 1 NETBIOS Node Type -dhcp_netbios_scope equ 47 ; N NETBIOS Scope -dhcp_x_window_font equ 48 ; N×4 X Window Font Server -dhcp_x_window_manager equ 49 ; N×4 X Window Display Manager -dhcp_nis_domain_name equ 64 ; N NIS+ v3 Client Domain Name -dhcp_nis_server_addr equ 65 ; N×4 NIS+ v3 Server Addresses -dhcp_home_agent_addrs equ 68 ; N×4 Mobile IP Home Agent Addresses -dhcp_smtp_server equ 69 ; N×4 Simple Mail Server Addresses -dhcp_pop3_server equ 70 ; N×4 Post Office Server Addresses -dhcp_nntp_server equ 71 ; N×4 Network News Server Addresses -dhcp_www_server equ 72 ; N×4 WWW Server Addresses -dhcp_finger_server equ 73 ; N×4 Finger Server Addresses -dhcp_irc_server equ 74 ; N×4 Chat Server Addresses -dhcp_streettalk_server equ 75 ; N×4 StreetTalk Server Addresses -dhcp_stda_server equ 76 ; N×4 ST Directory Assist. Addresses +dhcp_nis_domain = 40 ; N NIS Domain Name +dhcp_nis_servers = 41 ; N×4 NIS Server Addresses +dhcp_ntp_servers = 42 ; N×4 NTP Server Addresses +dhcp_vendor_specific = 43 ; N Vendor Specific Information +dhcp_netbios_name_srv = 44 ; N×4 NETBIOS Name Servers +dhcp_netbios_dist_srv = 45 ; N×4 NETBIOS Datagram Distribution +dhcp_netbios_node_type = 46 ; 1 NETBIOS Node Type +dhcp_netbios_scope = 47 ; N NETBIOS Scope +dhcp_x_window_font = 48 ; N×4 X Window Font Server +dhcp_x_window_manager = 49 ; N×4 X Window Display Manager +dhcp_nis_domain_name = 64 ; N NIS+ v3 Client Domain Name +dhcp_nis_server_addr = 65 ; N×4 NIS+ v3 Server Addresses +dhcp_home_agent_addrs = 68 ; N×4 Mobile IP Home Agent Addresses +dhcp_smtp_server = 69 ; N×4 Simple Mail Server Addresses +dhcp_pop3_server = 70 ; N×4 Post Office Server Addresses +dhcp_nntp_server = 71 ; N×4 Network News Server Addresses +dhcp_www_server = 72 ; N×4 WWW Server Addresses +dhcp_finger_server = 73 ; N×4 Finger Server Addresses +dhcp_irc_server = 74 ; N×4 Chat Server Addresses +dhcp_streettalk_server = 75 ; N×4 StreetTalk Server Addresses +dhcp_stda_server = 76 ; N×4 ST Directory Assist. Addresses ;DHCP Extensions -dhcp_address_request equ 50 ; 4 Requested IP Address -dhcp_address_time equ 51 ; 4 IP Address Lease Time -dhcp_option_overload equ 52 ; 1 Overload "sname" or "file" -dhcp_msg_type equ 53 ; 1 DHCP Message Type -dhcp_dhcp_server_id equ 54 ; 4 DHCP Server Identification -dhcp_parameter_list equ 55 ; N Parameter Request List -dhcp_dhcp_message equ 56 ; N DHCP Error Message -dhcp_dhcp_max_msg_size equ 57 ; 2 DHCP Maximum Message Size -dhcp_renewal_time equ 58 ; 4 DHCP Renewal (T1) Time -dhcp_rebinding_time equ 59 ; 4 DHCP Rebinding (T2) Time -dhcp_class_id equ 60 ; N Vendor Class Identifier -dhcp_client_id equ 61 ; N Client Identifier -dhcp_server_name equ 66 ; N TFTP Server Name -dhcp_bootfile_name equ 67 ; N Boot File Name +dhcp_address_request = 50 ; 4 Requested IP Address +dhcp_address_time = 51 ; 4 IP Address Lease Time +dhcp_option_overload = 52 ; 1 Overload "sname" or "file" +dhcp_msg_type = 53 ; 1 DHCP Message Type +dhcp_dhcp_server_id = 54 ; 4 DHCP Server Identification +dhcp_parameter_list = 55 ; N Parameter Request List +dhcp_dhcp_message = 56 ; N DHCP Error Message +dhcp_dhcp_max_msg_size = 57 ; 2 DHCP Maximum Message Size +dhcp_renewal_time = 58 ; 4 DHCP Renewal (T1) Time +dhcp_rebinding_time = 59 ; 4 DHCP Rebinding (T2) Time +dhcp_class_id = 60 ; N Vendor Class Identifier +dhcp_client_id = 61 ; N Client Identifier +dhcp_server_name = 66 ; N TFTP Server Name +dhcp_bootfile_name = 67 ; N Boot File Name ;Newer extensions -dhcp_netware_ip_domain equ 62 ; N Netware/IP Domain Name -dhcp_netware_ip_option equ 63 ; N Netware/IP sub Options -dhcp_user_class equ 77 ; N User Class Information -dhcp_directory_agent equ 78 ; N directory agent information -dhcp_service_scope equ 79 ; N service location agent scope -dhcp_rapid_commit equ 80 ; 0 Rapid Commit -dhcp_client_fqdn equ 81 ; N Fully Qualified Domain Name -dhcp_relay_agent_info equ 82 ; N Relay Agent Information, RFC 3046 -dhcp_isns equ 83 ; N Internet Storage Name Service +dhcp_netware_ip_domain = 62 ; N Netware/IP Domain Name +dhcp_netware_ip_option = 63 ; N Netware/IP sub Options +dhcp_user_class = 77 ; N User Class Information +dhcp_directory_agent = 78 ; N directory agent information +dhcp_service_scope = 79 ; N service location agent scope +dhcp_rapid_commit = 80 ; 0 Rapid Commit +dhcp_client_fqdn = 81 ; N Fully Qualified Domain Name +dhcp_relay_agent_info = 82 ; N Relay Agent Information, RFC 3046 +dhcp_isns = 83 ; N Internet Storage Name Service ; 84 REMOVED/Unassigned -dhcp_nds_servers equ 85 ; N Novell Directory Services -dhcp_nds_tree_name equ 86 ; N Novell Directory Services -dhcp_nds_conext equ 87 ; N Novell Directory Services -dhcp_bcmcs equ 88 ; Controller Domain Name list -dhcp_bcmcs equ 89 ; Controller IPv4 address option -dhcp_authentication equ 90 ; N Authentication +dhcp_nds_servers = 85 ; N Novell Directory Services +dhcp_nds_tree_name = 86 ; N Novell Directory Services +dhcp_nds_conext = 87 ; N Novell Directory Services +dhcp_bcmcs = 88 ; Controller Domain Name list +dhcp_bcmcs = 89 ; Controller IPv4 address option +dhcp_authentication = 90 ; N Authentication ; 91 REMOVED/Unassigned ; 92 REMOVED/Unassigned -dhcp_client_system equ 93 ; N Client System Architecture -dhcp_client_ndi equ 94 ; N Client Network Device Interface -dhcp_ldap equ 95 ; N Lightweight Directory Access Protocol +dhcp_client_system = 93 ; N Client System Architecture +dhcp_client_ndi = 94 ; N Client Network Device Interface +dhcp_ldap = 95 ; N Lightweight Directory Access Protocol ; 96 REMOVED/Unassigned -dhcp_uuid_guid equ 97 ; N UUID/GUID-based Client Identifier -dchp_user_auth equ 98 ; N Open Group's User Authentication +dhcp_uuid_guid = 97 ; N UUID/GUID-based Client Identifier +dchp_user_auth = 98 ; N Open Group's User Authentication ; 99 REMOVED/Unassigned ; 100 REMOVED/Unassigned ; 101 REMOVED/Unassigned @@ -134,42 +134,42 @@ dchp_user_auth equ 98 ; N Open Group's User Authentication ; 109 REMOVED/Unassigned ; 110 REMOVED/Unassigned ; 111 REMOVED/Unassigned -dhcp_netinfo_address equ 112 ; N NetInfo Parent Server Address -dhcp_netinfo_tag equ 113 ; N NetInfo Parent Server Tag -dhcp_url equ 114 ; N URL +dhcp_netinfo_address = 112 ; N NetInfo Parent Server Address +dhcp_netinfo_tag = 113 ; N NetInfo Parent Server Tag +dhcp_url = 114 ; N URL ; 115 REMOVED/Unassigned -dhcp_auto_config equ 116 ; N DHCP Auto-Configuration -dhcp_ns_search equ 117 ; N Name Service Search -dhcp_subnet_selection equ 118 ; 4 Subnet Selection Option -dhcp_domain_search equ 119 ; N DNS domain search list -dhcp_sip_servers equ 120 ; N SIP Servers DHCP Option -dhcp_cl_static_route equ 121 ; N Classless Static Route Option -dhcp_ccc equ 122 ; N CableLabs Client Configuration -dhcp_geoconf equ 123 ; 16 GeoConf Option -dhcp_v_i_vendor_class equ 124 ; Vendor-Identifying Vendor Class -dhcp_v_i_vendor_spec equ 125 ; Vendor-Identifying Vendor-Specific +dhcp_auto_config = 116 ; N DHCP Auto-Configuration +dhcp_ns_search = 117 ; N Name Service Search +dhcp_subnet_selection = 118 ; 4 Subnet Selection Option +dhcp_domain_search = 119 ; N DNS domain search list +dhcp_sip_servers = 120 ; N SIP Servers DHCP Option +dhcp_cl_static_route = 121 ; N Classless Static Route Option +dhcp_ccc = 122 ; N CableLabs Client Configuration +dhcp_geoconf = 123 ; 16 GeoConf Option +dhcp_v_i_vendor_class = 124 ; Vendor-Identifying Vendor Class +dhcp_v_i_vendor_spec = 125 ; Vendor-Identifying Vendor-Specific ; 126 REMOVED/Unassigned ; 127 REMOVED/Unassigned -dhcp_pxe equ 128 ; PXE - undefined (vendor specific) (Tentatively Assigned - 23 June 2005) -dhcp_etherboot_sign equ 128 ; Etherboot signature. 6 bytes: E4:45:74:68:00:00 -dhcp_docsis equ 128 ; DOCSIS "full security" server IP address -dhcp_tftp_server_ip equ 128 ; TFTP Server IP address (for IP Phone software load) -dhcp_pxe equ 129 ; PXE - undefined (vendor specific) (Tentatively Assigned - 23 June 2005) -dhcp_kernel_options equ 129 ; Kernel options. Variable length string -dhcp_call_server_ip equ 129 ; Call Server IP address -dhcp_pxe equ 130 ; PXE - undefined (vendor specific) (Tentatively Assigned - 23 June 2005) -dhcp_ethernet_interface equ 130 ; Ethernet interface. Variable length string. -dhcp_siscrimination equ 130 ; Discrimination string (to identify vendor) -dhcp_pxe equ 131 ; PXE - undefined (vendor specific) (Tentatively Assigned - 23 June 2005) -dhcp_remote_stat_server equ 131 ; Remote statistics server IP address -dhcp_pxe equ 132 ; PXE - undefined (vendor specific) (Tentatively Assigned - 23 June 2005) -dhcp_802.1p equ 132 ; 802.1P VLAN ID -dhcp_pxe equ 133 ; PXE - undefined (vendor specific) (Tentatively Assigned - 23 June 2005) -dhcp_802.1q equ 133 ; 802.1Q L2 Priority -dhcp_pxe equ 134 ; PXE - undefined (vendor specific) (Tentatively Assigned - 23 June 2005) -dhcp_diffserv equ 134 ; Diffserv Code Point -dhcp_pxe equ 135 ; PXE - undefined (vendor specific) (Tentatively Assigned - 23 June 2005) -dhcp_http_proxy_psa equ 135 ; HTTP Proxy for phone-specific applications +dhcp_pxe = 128 ; PXE - undefined (vendor specific) (Tentatively Assigned - 23 June 2005) +dhcp_etherboot_sign = 128 ; Etherboot signature. 6 bytes: E4:45:74:68:00:00 +dhcp_docsis = 128 ; DOCSIS "full security" server IP address +dhcp_tftp_server_ip = 128 ; TFTP Server IP address (for IP Phone software load) +dhcp_pxe = 129 ; PXE - undefined (vendor specific) (Tentatively Assigned - 23 June 2005) +dhcp_kernel_options = 129 ; Kernel options. Variable length string +dhcp_call_server_ip = 129 ; Call Server IP address +dhcp_pxe = 130 ; PXE - undefined (vendor specific) (Tentatively Assigned - 23 June 2005) +dhcp_ethernet_interface = 130 ; Ethernet interface. Variable length string. +dhcp_siscrimination = 130 ; Discrimination string (to identify vendor) +dhcp_pxe = 131 ; PXE - undefined (vendor specific) (Tentatively Assigned - 23 June 2005) +dhcp_remote_stat_server = 131 ; Remote statistics server IP address +dhcp_pxe = 132 ; PXE - undefined (vendor specific) (Tentatively Assigned - 23 June 2005) +dhcp_802.1p = 132 ; 802.1P VLAN ID +dhcp_pxe = 133 ; PXE - undefined (vendor specific) (Tentatively Assigned - 23 June 2005) +dhcp_802.1q = 133 ; 802.1Q L2 Priority +dhcp_pxe = 134 ; PXE - undefined (vendor specific) (Tentatively Assigned - 23 June 2005) +dhcp_diffserv = 134 ; Diffserv Code Point +dhcp_pxe = 135 ; PXE - undefined (vendor specific) (Tentatively Assigned - 23 June 2005) +dhcp_http_proxy_psa = 135 ; HTTP Proxy for phone-specific applications ; 136 REMOVED/Unassigned ; 137 REMOVED/Unassigned ; 138 REMOVED/Unassigned @@ -184,9 +184,9 @@ dhcp_http_proxy_psa equ 135 ; HTTP Proxy for phone-specific application ; 147 REMOVED/Unassigned ; 148 REMOVED/Unassigned ; 149 REMOVED/Unassigned -dhcp_tftp_server_addr equ 150 ; TFTP server address (Tentatively Assigned - 23 June 2005) -dhcp_etherboot equ 150 ; Etherboot -dhcp_grub_conf_path equ 150 ; GRUB configuration path name +dhcp_tftp_server_addr = 150 ; TFTP server address (Tentatively Assigned - 23 June 2005) +dhcp_etherboot = 150 ; Etherboot +dhcp_grub_conf_path = 150 ; GRUB configuration path name ; 151 REMOVED/Unassigned ; 152 REMOVED/Unassigned ; 153 REMOVED/Unassigned @@ -211,10 +211,10 @@ dhcp_grub_conf_path equ 150 ; GRUB configuration path name ; 172 REMOVED/Unassigned ; 173 REMOVED/Unassigned ; 174 REMOVED/Unassigned -dhcp_etherboot equ 175 ; Etherboot (Tentatively Assigned - 23 June 2005) -dhcp_ip_telephone equ 176 ; IP Telephone (Tentatively Assigned - 23 June 2005) -dhcp_etherboot equ 177 ; Etherboot (Tentatively Assigned - 23 June 2005) -dhcp_packetcable equ 177 ; PacketCable and CableHome (replaced by 122) +dhcp_etherboot = 175 ; Etherboot (Tentatively Assigned - 23 June 2005) +dhcp_ip_telephone = 176 ; IP Telephone (Tentatively Assigned - 23 June 2005) +dhcp_etherboot = 177 ; Etherboot (Tentatively Assigned - 23 June 2005) +dhcp_packetcable = 177 ; PacketCable and CableHome (replaced by 122) ; 178 REMOVED/Unassigned ; 179 REMOVED/Unassigned ; 180 REMOVED/Unassigned @@ -245,10 +245,10 @@ dhcp_packetcable equ 177 ; PacketCable and CableHome (replaced by 122) ; 205 REMOVED/Unassigned ; 206 REMOVED/Unassigned ; 207 REMOVED/Unassigned -dhcp_pxelinux.magic equ 208 ; pxelinux.magic (string) = F1:00:74:7E (241.0.116.126) (Tentatively Assigned - 23 June 2005) -dhcp_pxelinux.conffile equ 209 ; pxelinux.configfile (text) (Tentatively Assigned - 23 June 2005) -dhcp_pxelinux.path equ 210 ; pxelinux.pathprefix (text) (Tentatively Assigned - 23 June 2005) -dhcp_pxelinux.reboot equ 211 ; pxelinux.reboottime (unsigned integer 32 bits) (Tentatively Assigned - 23 June 2005) +dhcp_pxelinux.magic = 208 ; pxelinux.magic (string) = F1:00:74:7E (241.0.116.126) (Tentatively Assigned - 23 June 2005) +dhcp_pxelinux.conffile = 209 ; pxelinux.configfile (text) (Tentatively Assigned - 23 June 2005) +dhcp_pxelinux.path = 210 ; pxelinux.pathprefix (text) (Tentatively Assigned - 23 June 2005) +dhcp_pxelinux.reboot = 211 ; pxelinux.reboottime (unsigned integer 32 bits) (Tentatively Assigned - 23 June 2005) ; 212 REMOVED/Unassigned ; 213 REMOVED/Unassigned ; 214 REMOVED/Unassigned @@ -257,7 +257,7 @@ dhcp_pxelinux.reboot equ 211 ; pxelinux.reboottime (unsigned integer ; 217 REMOVED/Unassigned ; 218 REMOVED/Unassigned ; 219 REMOVED/Unassigned -dhcp_subnet_aloc equ 220 ; Subnet Allocation Option (Tentatively Assigned - 23 June 2005) -dhcp_virtual_subnet equ 221 ; Virtual Subnet Selection Option (Tentatively Assigned - 23 June 2005) +dhcp_subnet_aloc = 220 ; Subnet Allocation Option (Tentatively Assigned - 23 June 2005) +dhcp_virtual_subnet = 221 ; Virtual Subnet Selection Option (Tentatively Assigned - 23 June 2005) ; 222 REMOVED/Unassigned ; 223 REMOVED/Unassigned diff --git a/programs/network/zeroconf/zeroconf.asm b/programs/network/zeroconf/zeroconf.asm index a80c99dfd..d1966efb6 100644 --- a/programs/network/zeroconf/zeroconf.asm +++ b/programs/network/zeroconf/zeroconf.asm @@ -43,6 +43,8 @@ RATE_LIMIT_INTERVAL = 60 ; seconds (delay between successive atte DEFEND_INTERVAL = 10 ; seconds (min. wait between defensive ARPs) +MAX_INTERFACES = 8 + use32 org 0x0 @@ -62,246 +64,366 @@ include '../../network.inc' include 'dhcp.inc' include '../../dll.inc' +struct dhcp_msg + op db ? ; Operation Code + htype db ? ; Hardware type + hlen db ? ; Hardware address length + hops db ? + xid dd ? ; Transaction Identifier + secs dw ? ; Seconds since boot + flags dw ? + ciaddr dd ? ; Client IP address + yiaddr dd ? ; "Your" IP address + siaddr dd ? ; Server IP address + giaddr dd ? ; Gateway IP address + chaddr rb 16 ; Client hardware address + sname rb 64 ; Server name + file rb 128 ; boot filename + cookie dd ? ; Magic cookie (0x63538263) + options rb 512 +ends + +struct interface + number dd ? + state dd ? ; 0 - disconnected, 1 - connected + mode dd ? ; 0 - static, 1 - dhcp, 2 - auto (zero config) + tries dd ? + lease dd ? + ServerIP dd ? + ip dd ? + subnet dd ? + dns dd ? + gateway dd ? + socketNum dd ? + timeout dd ? + ip_conflicts dd ? +ends + START: - mcall 68, 11 + mcall 68, 11 ; init heap - stdcall dll.Load,@IMPORT + stdcall dll.Load, @IMPORT ; load libraries or eax, eax - jnz fail + jnz exit_immediately - DEBUGF 2,"Zero-config service loaded\n" + DEBUGF 2, "Zero-config service loaded\n" - mcall 40, EVM_STACK2 + mcall 40, EVM_STACK2 ; We only want low-level network events -wait_for_link_up: - mov bh, [device] - mov bl, 0 ; Get device type - mcall 74 - cmp eax, 1 ; Ethernet - jne .wait +; Set up interface list + mov edi, device_list + xor ebx, ebx + @@: + inc ebx + mov eax, ebx + stosd + mov ecx, sizeof.interface/4-1 + xor eax,eax + rep stosd + cmp ebx, MAX_INTERFACES + jb @b - mov bl, 10 ; Get Link status - mcall 74 - test eax, eax - jnz .go + mov ebp, device_list +mainloop: + cmp [ebp + interface.state], 0 + je .link_up? + jmp .maintain_link + + .next: + cmp [ebp + interface.number], MAX_INTERFACES + je .wait + add ebp, sizeof.interface + jmp mainloop .wait: - mcall 10 - jmp wait_for_link_up + mcall 10 ; Wait for event + mov ebp, device_list + jmp mainloop - .go: - mov ebx, API_ETH + 0 - mov bh, [device] - mcall 76 ; get MAC of the ethernet interface - mov word[MAC], bx - mov dword[MAC+2], eax - DEBUGF 1,"MAC: %x-%x-%x-%x-%x-%x\n", [MAC+0]:2, [MAC+1]:2, [MAC+2]:2, [MAC+3]:2, [MAC+4]:2, [MAC+5]:2 - - invoke ini.get_str, path, str_ipconfig, str_type, inibuf, 16, 0 - - cmp dword[inibuf], 'stat' - je static - jmp try_dhcp - -wait_for_link_down: -; TODO: detect ARP conflicts - - mcall 40, EVM_STACK2 - .loop: - mcall 10 - mov bh, [device] - mov bl, 0 ; Get device type + .link_up?: + mov bh, byte[ebp + interface.number] + mov bl, 0 ; Get device type mcall 74 - cmp eax, 0 ; No device - je .down + cmp eax, 1 ; Ethernet + jne mainloop.next - mov bl, 10 ; Get Link status + mov bl, 10 ; Get Link status mcall 74 test eax, eax - jnz .loop + jz mainloop.next - .down: + mov [ebp + interface.state], 1 + + call create_str_ini_int + +; Try to read settings from .ini file + invoke ini.get_str, ini_path, str_ini_int, str_ip_type, inibuf, 16, str_null + test eax, eax + jz @f +; If settings not found, use default settings from 'ip?' section + mov dword[str_ini_int], 'ip?' + @@: + + mov ebx, API_ETH + 0 + mov bh, byte[ebp + interface.number] + mcall 76 ; get MAC of the ethernet interface + mov word[tx_msg.chaddr], bx + mov dword[tx_msg.chaddr+2], eax + DEBUGF 1, "MAC: %x-%x-%x-%x-%x-%x\n", \ + [tx_msg.chaddr+0]:2, [tx_msg.chaddr+1]:2, [tx_msg.chaddr+2]:2, \ + [tx_msg.chaddr+3]:2, [tx_msg.chaddr+4]:2, [tx_msg.chaddr+5]:2 + + invoke ini.get_str, ini_path, str_ini_int, str_ip_type, inibuf, 16, str_null + test eax, eax + jnz .fail + mov eax, dword[inibuf] + or eax, 0x20202020 + mov [ebp + interface.mode], 0 + cmp eax, 'stat' + je static + mov [ebp + interface.mode], 1 + cmp eax, 'dhcp' + je dhcp + mov [ebp + interface.mode], 2 + cmp eax, 'auto' + je dhcp + + .fail: + DEBUGF 2, "Invalid network.ini settings\n" + mcall -1 ; Give up + + .maintain_link: + +; Check for IP conflicts + mov ebx, API_ARP + mov bh, byte[ebp + interface.number] + mov bl, 7 + mcall 76 ; Number of IP conflicts + cmp eax, [ebp + interface.ip_conflicts] + je @f + mov [ebp + interface.ip_conflicts], eax + DEBUGF 2, "IP address conflict on interface %u\n", [ebp + interface.number] + ; Notify user of the IP address conflict + mov [notify_struct.msg], str_conflict + mcall 70, notify_struct + @@: + +; Check if device is still there + mov bh, byte[ebp + interface.number] + mov bl, 0 ; Get device type + mcall 74 + test eax, eax ; No device + jz .link_down + +; Check if link is still there + mov bl, 10 ; Get Link status + mcall 74 + test eax, eax + jnz .next + + .link_down: + mov [ebp + interface.state], 0 + +; Notify user that the link is down + mov [notify_struct.msg], str_disconnected + mcall 70, notify_struct + +; CHECKME: should we do this in kernel instead? Should we even do this at all? xor ecx, ecx mov ebx, API_IPv4 + 3 - mov bh, [device] - mcall 76 ; ip + mov bh, byte[ebp + interface.number] + mcall 76 ; ip mov bl, 5 - mcall 76 ; dns + mcall 76 ; dns mov bl, 7 - mcall 76 ; subnet + mcall 76 ; subnet mov bl, 9 - mcall 76 ; gateway + mcall 76 ; gateway - jmp wait_for_link_up + jmp .next -static: - DEBUGF 1,"Applying Static IP settings\n" +link_up: - invoke ini.get_str, path, str_ipconfig, str_ip, inibuf, 16, 0 - mov edx, inibuf - call ip_str_to_dword - mov ecx, edx - mov ebx, API_IPv4 + 3 ; set IP - mov bh, [device] - mcall 76 - - invoke ini.get_str, path, str_ipconfig, str_gateway, inibuf, 16, 0 - mov edx, inibuf - call ip_str_to_dword - mov ecx, edx - mov ebx, API_IPv4 + 9 ; set gateway - mov bh, [device] - mcall 76 - - invoke ini.get_str, path, str_ipconfig, str_dns, inibuf, 16, 0 - mov edx, inibuf - call ip_str_to_dword - mov ecx, edx - mov ebx, API_IPv4 + 5 ; set DNS - mov bh, [device] - mcall 76 - - invoke ini.get_str, path, str_ipconfig, str_subnet, inibuf, 16, 0 - mov edx, inibuf - call ip_str_to_dword - mov ecx, edx - mov ebx, API_IPv4 + 7 ; set subnet - mov bh, [device] +; Read number of previous IP conflicts + mov ebx, API_ARP + mov bh, byte[ebp + interface.number] + mov bl, 7 mcall 76 + mov [ebp + interface.ip_conflicts], eax +; Notify user that the link is up and running mov [notify_struct.msg], str_connected mcall 70, notify_struct - jmp wait_for_link_down + + .fail: + mcall 40, EVM_STACK2 + jmp mainloop.next + +static: + DEBUGF 1, "Applying Static IP settings\n" + + invoke ini.get_str, ini_path, str_ini_int, str_ip, inibuf, 16, str_null + mov esi, inibuf + call ip_str_to_dword + mov ebx, API_IPv4 + 3 ; set IP + mov bh, byte[ebp + interface.number] + mcall 76 + + invoke ini.get_str, ini_path, str_ini_int, str_subnet, inibuf, 16, str_null + mov esi, inibuf + call ip_str_to_dword + mov ebx, API_IPv4 + 7 ; set subnet + mov bh, byte[ebp + interface.number] + mcall 76 + + invoke ini.get_str, ini_path, str_ini_int, str_gateway, inibuf, 16, str_null + mov esi, inibuf + call ip_str_to_dword + mov ebx, API_IPv4 + 9 ; set gateway + mov bh, byte[ebp + interface.number] + mcall 76 + + .dns: + invoke ini.get_str, ini_path, str_ini_int, str_dns, inibuf, 16, str_null + mov esi, inibuf + call ip_str_to_dword + mov ebx, API_IPv4 + 5 ; set DNS + mov bh, byte[ebp + interface.number] + mcall 76 + + jmp link_up -try_dhcp: +dhcp: - DEBUGF 2,"Trying to contact DHCP server\n" + DEBUGF 2, "Trying to contact DHCP server\n" mcall 40, EVM_STACK - mcall 75, 0, AF_INET4, SOCK_DGRAM, 0 ; open socket (parameters: domain, type, reserved) + mcall 75, 0, AF_INET4, SOCK_DGRAM, 0 ; open socket (parameters: domain, type, reserved) cmp eax, -1 - je socket_error - mov [socketNum], eax + je dhcp_error + mov [ebp + interface.socketNum], eax - DEBUGF 1,"Socket %x opened\n", eax + DEBUGF 1, "Socket %x opened\n", eax - mcall 75, 2, [socketNum], sockaddr1, 18 ; bind socket to local port 68 + mcall 75, 2, [ebp + interface.socketNum], sock_local, 18 ; bind socket to local port 68 cmp eax, -1 je socket_error - DEBUGF 1,"Socket Bound to local port 68\n" + DEBUGF 1, "Socket Bound to local port 68\n" - mcall 75, 4, [socketNum], sockaddr2, 18 ; connect to 255.255.255.255 on port 67 + pushd [ebp + interface.number] + pushd 4 ; length of option + pushd 1 shl 9 ; SO_BINDTODEVICE + pushd 0 ; SOL_SOCKET + mcall 75, 8, [ebp + interface.socketNum], esp + add esp, 16 cmp eax, -1 je socket_error - DEBUGF 1,"Connected to 255.255.255.255 on port 67\n" + DEBUGF 1, "Socket Bound to local interface %u\n", [ebp + interface.number] - mov [dhcpMsgType_tx], 0x01 ; DHCP discover - mov [dhcpLease], esi ; esi is still -1 (-1 = forever) + mcall 75, 4, [ebp + interface.socketNum], sock_remote, 18 ; connect to 255.255.255.255 on port 67 + cmp eax, -1 + je socket_error + + DEBUGF 1, "Connected to 255.255.255.255 on port 67\n" + + ; Read preferred IP address from settings file + invoke ini.get_str, ini_path, str_ini_int, str_ip, inibuf, 16, str_null + mov esi, inibuf + call ip_str_to_dword + mov [ebp + interface.ip], ecx call random - mov [dhcpXID], eax + mov [tx_msg.xid], eax ; randomize session ID + mov [tx_msg_type], 1 ; DHCP discover -build_request: ; Creates a DHCP request packet. +build_dhcp_packet: - DEBUGF 1,"Building request\n" + DEBUGF 1, "Building DHCP packet\n" - mcall 26, 9 ; Get system time - imul eax, 100 - mov [currTime], eax - - mov [tries], DHCP_TRIES - - stdcall mem.Alloc, BUFFER - test eax, eax - jz dhcp_fail2 - mov [dhcpMsg], eax - - ; Fill buffer with zeros - mov edi, eax - mov ecx, BUFFER - xor eax, eax - rep stosb - - mov edx, [dhcpMsg] + mov [ebp + interface.tries], DHCP_TRIES ; Boot protocol legacy - mov [edx], byte 0x01 ; Boot request - mov [edx+1], byte 0x01 ; Ethernet - mov [edx+2], byte 0x06 ; Ethernet h/w len - mov eax, [dhcpXID] - mov [edx+4], eax ; xid - mov eax, [currTime] - mov [edx+8], eax ; secs, our uptime - mov [edx+10], byte 0x80 ; broadcast flag set - mov eax, dword [MAC] ; first 4 bytes of MAC - mov [edx+28],dword eax - mov ax, word [MAC+4] ; last 2 bytes of MAC - mov [edx+32],word ax + mov [tx_msg.op], 1 ; Boot request + mov [tx_msg.htype], 1 ; Ethernet + mov [tx_msg.hlen], 6 ; Ethernet address h/w len + mov [tx_msg.hops], 0 + mcall 26, 9 ; Time since boot + xor edx, edx + mov ebx, 100 + div ebx ; Divide by 100 to get number of seconds + mov [tx_msg.secs], ax + mov [tx_msg.flags], 0 ; DHCP extension - mov [edx+236], dword 0x63538263 ; magic cookie - mov [edx+240], word 0x0135 ; option DHCP msg type - mov al, [dhcpMsgType_tx] - mov [edx+240+2], al - mov [edx+240+3], word 0x0433 ; option Lease time = infinity - mov eax, [dhcpLease] - mov [edx+240+5], eax - mov [edx+240+9], word 0x0432 ; option requested IP address - mov eax, [dhcp.ip] - mov [edx+240+11], eax - mov [edx+240+15], word 0x0437 ; option request list - mov [edx+240+17], dword 0x0f060301 + mov [tx_msg.cookie], 0x63538263 ; magic cookie - cmp [dhcpMsgType_tx], 0x01 ; Check which msg we are sending - jne .options + mov word[tx_msg+240], 0x0135 ; option DHCP msg type + mov al,[tx_msg_type] + mov [tx_msg+240+2], al - mov [edx+240+21], byte 0xff ; end of options marker + mov word[tx_msg+240+3], 0x0433 ; option Lease time + mov dword[tx_msg+240+5], -1 ; infinite - mov [dhcpMsgLen], 262 ; length - jmp send_dhcpmsg + mov word[tx_msg+240+9], 0x0432 ; option requested IP address + mov eax,[ebp + interface.ip] + mov [tx_msg+240+11], eax - .options: - mov [edx+240+21], word 0x0436 ; server IP - mov eax, [dhcpServerIP] - mov [edx+240+23], eax + mov word[tx_msg+240+15], 0x0437 ; option request list + mov dword[tx_msg+240+17], 0x0f060301 - mov [edx+240+27], byte 0xff ; end of options marker + cmp [tx_msg_type], 1 ; Check which msg we are sending + jne .request - mov [dhcpMsgLen], 268 ; length + mov byte[tx_msg+240+21], 0xff ; end of options marker -send_dhcpmsg: - DEBUGF 1,"Sending DHCP discover/request\n" - mcall 75, 6, [socketNum], [dhcpMsg], [dhcpMsgLen] ; write to socket (send broadcast request) + mov [tx_msg_len], 262 ; length + jmp send_dhcp_packet -; Wait for data + .request: + mov word[tx_msg+240+21], 0x0436 ; server IP + mov eax,[ebp + interface.ServerIP] + mov [tx_msg+240+23], eax + + mov byte[tx_msg+240+27], 0xff ; end of options marker + + mov [tx_msg_len], 268 ; length + + +send_dhcp_packet: + DEBUGF 1, "Sending DHCP packet\n" + lea edx, [tx_msg] + mcall 75, 6, [ebp + interface.socketNum], , [tx_msg_len] + +; Wait for reply mcall 26, 9 add eax, TIMEOUT*100 - mov [timeout], eax + mov [ebp + interface.timeout], eax + mov ebx, TIMEOUT*100 .wait: - mcall 23, TIMEOUT - -read_data: ; we have data - this will be the response - mcall 75, 7, [socketNum], [dhcpMsg], BUFFER, MSG_DONTWAIT ; read data from socket + mcall 23 ; Wait for event with timeout +read_packet: ; we have data - this will be the response + lea edx, [rx_msg] + mcall 75, 7, [ebp + interface.socketNum], , BUFFER, MSG_DONTWAIT ; read data from socket cmp eax, -1 jne .got_data mcall 26, 9 - cmp eax, [timeout] - jb send_dhcpmsg.wait + mov ebx, eax + sub ebx, [ebp + interface.timeout] + ja send_dhcp_packet.wait - DEBUGF 2,"No answer from DHCP server\n" - dec [tries] - jnz send_dhcpmsg ; try again - stdcall mem.Free, [dhcpMsg] + DEBUGF 2, "No answer from DHCP server\n" + dec [ebp + interface.tries] + jnz send_dhcp_packet jmp dhcp_fail .got_data: - DEBUGF 1,"%d bytes received\n", eax - mov [dhcpMsgLen], eax + DEBUGF 1, "%d bytes received\n", eax + mov [rx_msg_len], eax ; depending on which msg we sent, handle the response ; accordingly. @@ -313,120 +435,101 @@ read_data: ; we hav ; 1) If the response is DHCP ACK then ; 1.1) extract the DNS & subnet fields. Set them in the stack - cmp [dhcpMsgType_tx], 0x01 ; did we send a discover? + cmp [tx_msg_type], 1 ; did we send a discover? je discover_sent - - cmp [dhcpMsgType_tx], 0x03 ; did we send a request? + cmp [tx_msg_type], 3 ; did we send a request? je request_sent - - ; we should never reach here ;) - stdcall mem.Free, [dhcpMsg] - jmp fail + jmp exit_immediately discover_sent: - call parse_response - cmp [dhcpMsgType_rx], 0x02 ; Was the response an offer? - jne read_data + call parse_dhcp_reply + cmp [rx_msg_type], 2 ; Was the response an offer? + jne read_packet DEBUGF 1, "Got offer, making request\n" - mov [dhcpMsgType_tx], 0x03 ; make it a request - jmp build_request + mov [tx_msg_type], 3 ; make it a request + jmp build_dhcp_packet request_sent: - call parse_response - cmp [dhcpMsgType_rx], 0x05 ; Was the response an ACK? It should be - jne read_data ; NO - read next packets + call parse_dhcp_reply + cmp [rx_msg_type], 5 ; Was the response an ACK? It should be + jne read_packet ; NO - read next packets DEBUGF 2, "IP assigned by DHCP server successfully\n" - mov [notify_struct.msg], str_connected - mcall 70, notify_struct - - mcall close, [socketNum] + mcall close, [ebp + interface.socketNum] mov ebx, API_IPv4 + 3 - mov bh, [device] - mcall 76, , [dhcp.ip] ; ip + mov bh, byte[ebp + interface.number] + mcall 76, , [ebp + interface.ip] ; ip mov bl, 5 - mcall 76, , [dhcp.dns] ; dns - mov bl, 7 - mcall 76, , [dhcp.subnet] ; subnet + mcall 76, , [ebp + interface.subnet] ; subnet mov bl, 9 - mcall 76, , [dhcp.gateway] ; gateway + mcall 76, , [ebp + interface.gateway] ; gateway - jmp wait_for_link_down + invoke ini.get_str, ini_path, str_ini_int, str_dns_type, inibuf, 16, str_null + test eax, eax + jnz @f + mov eax, dword[inibuf] + or eax, 0x202020 + cmp eax, 'stat' + je static.dns + @@: + mcall 76, , [ebp + interface.dns] ; dns + mov bl, 7 + + jmp link_up -;*************************************************************************** -; Function -; parseResponse -; -; Description -; extracts the fields ( client IP address and options ) from -; a DHCP response -; The values go into -; dhcpMsgType,dhcpLease,dhcpClientIP,dhcpServerIP, -; dhcpDNSIP, dhcpSubnet -; The message is stored in dhcpMsg -; -;*************************************************************************** -parse_response: +parse_dhcp_reply: - DEBUGF 1,"Parsing response\n" - mov edx, [dhcpMsg] - mov [dhcpMsgType_rx], 0 + DEBUGF 1, "Parsing response\n" + mov [rx_msg_type], 0 ; Verify if session ID matches - mov eax, [dhcpXID] - cmp dword[edx+4], eax + mov eax, [tx_msg.xid] + cmp [rx_msg.xid], eax jne .done - push dword [edx+16] - pop [dhcp.ip] - DEBUGF 1,"Client: %u.%u.%u.%u\n", [edx+16]:1, [edx+17]:1, [edx+18]:1, [edx+19]:1 + pushd [rx_msg.yiaddr] + pop [ebp + interface.ip] + DEBUGF 1, "Client: %u.%u.%u.%u\n", \ + [rx_msg.yiaddr]:1, [rx_msg.yiaddr+1]:1, [rx_msg.yiaddr+2]:1, [rx_msg.yiaddr+3]:1 -; TODO: check if there really are options - - mov al, 240 ; Point to first option - movzx ecx, al +; Verify magic cookie + cmp [rx_msg.cookie], 0x63538263 + jne .done +; Parse the DHCP options + lea esi, [rx_msg] + mov ecx, 240 ; point to the first option .next_option: - add edx, ecx +; TODO: check if we still are inside the buffer! + add esi, ecx - mov al, [edx] ; get message identifier - - cmp al, 0xff ; End of options? + lodsb ; get message identifier + mov bl, al + cmp bl, 0xff ; End of options? je .done + test bl, bl + jz .pad - cmp al, 0 - je .pad - -; TODO: check if we still are inside the buffer - - inc edx - movzx ecx, byte [edx] ; get data length - inc edx ; point to data - - cmp al, dhcp_msg_type ; Msg type is a single byte option + lodsb ; load data length + movzx ecx, al + cmp bl, dhcp_msg_type ; Msg type is a single byte option je .msgtype - - cmp al, dhcp_dhcp_server_id + cmp bl, dhcp_dhcp_server_id je .server - - cmp al, dhcp_address_time + cmp bl, dhcp_address_time je .lease - - cmp al, dhcp_subnet_mask + cmp bl, dhcp_subnet_mask je .subnet - - cmp al, dhcp_router + cmp bl, dhcp_router je .router - - cmp al, dhcp_domain_server + cmp bl, dhcp_domain_server je .dns - DEBUGF 1,"Unsupported DHCP option: %u\n", al - + DEBUGF 1, "Unsupported DHCP option: %u\n", bl jmp .next_option .pad: @@ -435,67 +538,75 @@ parse_response: jmp .next_option .msgtype: - mov al, [edx] - mov [dhcpMsgType_rx], al + mov al, [esi] + mov [rx_msg_type], al - DEBUGF 1,"DHCP Msg type: %u\n", al + DEBUGF 1, "DHCP Msg type: %u\n", al jmp .next_option ; Get next option .server: - mov eax, [edx] - mov [dhcpServerIP], eax - DEBUGF 1,"Server: %u.%u.%u.%u\n",[edx]:1,[edx+1]:1,[edx+2]:1,[edx+3]:1 + pushd [esi] + pop [ebp + interface.ServerIP] + DEBUGF 1, "Server: %u.%u.%u.%u\n", [esi]:1, [esi+1]:1, [esi+2]:1, [esi+3]:1 jmp .next_option .lease: pusha - mov eax,[edx] + mov eax,[esi] bswap eax - mov [dhcpLease],eax - DEBUGF 1,"Lease: %d\n",eax + mov [ebp + interface.lease], eax + DEBUGF 1, "Lease: %d\n", eax popa jmp .next_option .subnet: - push dword [edx] - pop [dhcp.subnet] - DEBUGF 1,"Subnet: %u.%u.%u.%u\n",[edx]:1,[edx+1]:1,[edx+2]:1,[edx+3]:1 + pushd [esi] + pop [ebp + interface.subnet] + DEBUGF 1, "Subnet: %u.%u.%u.%u\n", [esi]:1, [esi+1]:1, [esi+2]:1, [esi+3]:1 jmp .next_option .router: - push dword [edx] - pop [dhcp.gateway] - DEBUGF 1,"Gateway: %u.%u.%u.%u\n",[edx]:1,[edx+1]:1,[edx+2]:1,[edx+3]:1 + pushd [esi] + pop [ebp + interface.gateway] + DEBUGF 1, "Gateway: %u.%u.%u.%u\n", [esi]:1, [esi+1]:1, [esi+2]:1, [esi+3]:1 jmp .next_option .dns: - push dword [edx] - pop [dhcp.dns] - DEBUGF 1,"DNS: %u.%u.%u.%u\n",[edx]:1,[edx+1]:1,[edx+2]:1,[edx+3]:1 + pushd [esi] + pop [ebp + interface.dns] + DEBUGF 1, "DNS: %u.%u.%u.%u\n", [esi]:1, [esi+1]:1, [esi+2]:1, [esi+3]:1 jmp .next_option .done: - stdcall mem.Free, [dhcpMsg] ret +exit_immediately: + DEBUGF 2, "Zeroconf failed!\n" + mcall -1 + +socket_error: + DEBUGF 2, "Socket error!\n" dhcp_fail: + mcall close, [ebp + interface.socketNum] - mcall close, [socketNum] - -dhcp_fail2: - DEBUGF 1,"DHCP failed\n" - +dhcp_error: + DEBUGF 1, "DHCP failed\n" + cmp [ebp + interface.mode], 2 ; zero config mode? + jne link_up link_local: + +; TODO: send ARP probes before setting the IP address in stack! + call random mov cx, ax shl ecx, 16 mov cx, 0xfea9 ; IP 169.254.0.0 link local net, see RFC3927 mov ebx, API_IPv4 + 3 - mov bh, [device] + mov bh, byte[ebp + interface.number] mcall 76, , ecx ; mask is 255.255.0.0 - DEBUGF 2,"Link Local IP assigned: 169.254.%u.%u\n", [generator+0]:1, [generator+1]:1 + DEBUGF 2, "Link Local IP assigned: 169.254.%u.%u\n", [generator+0]:1, [generator+1]:1 mov bl, 7 mcall 76, , 0xffff mov bl, 9 @@ -503,148 +614,85 @@ link_local: mov bl, 5 mcall 76, , 0x0 - mcall 5, PROBE_WAIT*100 - - xor esi, esi - probe_loop: - call random ; create a pseudo random number in eax (seeded by MAC) - - cmp al, PROBE_MIN*100 ; check if al is bigger then PROBE_MIN - jae @f ; all ok - add al, (PROBE_MAX-PROBE_MIN)*100 ; al is too small - @@: - - cmp al, PROBE_MAX*100 - jbe @f - sub al, (PROBE_MAX-PROBE_MIN)*100 - @@: - - movzx ebx,al - DEBUGF 1,"Waiting %u0ms\n",ebx - mcall 5 - - DEBUGF 1,"Sending Probe\n" - mov ebx, API_ARP + 6 - mov bh, [device] - mcall 76 - inc esi - - cmp esi, PROBE_NUM - jb probe_loop - -; now we wait further ANNOUNCE_WAIT seconds and send ANNOUNCE_NUM ARP announces. If any other host has assingned -; IP within this time, we should create another adress, that have to be done later - - DEBUGF 1,"Waiting %us\n", ANNOUNCE_WAIT - mcall 5, ANNOUNCE_WAIT*100 - xor esi, esi - announce_loop: - - DEBUGF 1,"Sending Announce\n" - mov ebx, API_ARP + 6 - mov bh, [device] - mcall 76 - - inc esi - cmp esi,ANNOUNCE_NUM - je @f - - DEBUGF 1,"Waiting %us\n", ANNOUNCE_INTERVAL - mcall 5, ANNOUNCE_INTERVAL*100 - jmp announce_loop - @@: - jmp wait_for_link_down - - -socket_error: - DEBUGF 2,"Socket error\n" -fail: - DEBUGF 2,"Zeroconf failed!\n" - mcall -1 + jmp link_up random: ; Pseudo random actually - mov eax, [generator] + mov eax,[generator] add eax, -43ab45b5h ror eax, 1 bswap eax - xor eax, dword[MAC] + xor eax, dword[tx_msg.chaddr] ror eax, 1 - xor eax, dword[MAC+2] + xor eax, dword[tx_msg.chaddr+2] mov [generator], eax ret +create_str_ini_int: + mov eax, [ebp + interface.number] + mov ebx, 10 + xor edx, edx + push 0 + @@: + div ebx + add dl, '0' + push edx + test eax, eax + jnz @r + @@: + mov edi, str_ini_int+2 + @@: + pop eax + stosb + test eax, eax + jnz @r + + ret + + + +; In: esi = ptr to ASCIIZ IP address +; Out: ecx = IP (0 on error) + ip_str_to_dword: - push edx - ; This code validates if the query is an IP containing 4 numbers and 3 dots - - xor al, al ; make al (dot count) zero - - @@: - cmp byte[edx],'0' ; check if this byte is a number, if not jump to no_IP - jl no_IP ; - cmp byte[edx],'9' ; - jg no_IP ; - - inc edx ; the byte was a number, so lets check the next byte - - cmp byte[edx],0 ; is this byte zero? (have we reached end of query?) - jz @f ; jump to next @@ then - cmp byte[edx],':' - jz @f - - cmp byte[edx],'.' ; is this byte a dot? - jne @r ; if not, jump to previous @@ - - inc al ; the byte was a dot so increment al(dot count) - inc edx ; next byte - jmp @r ; lets check for numbers again (jump to previous @@) - - @@: ; we reach this when end of query reached - cmp al,3 ; check if there where 3 dots - jnz no_IP ; if not, jump to no_IP - - ; The following code will convert this IP into a dword and output it in eax - ; If there is also a port number specified, this will be returned in ebx, otherwise ebx is -1 - - pop esi ; edx (query address) was pushed onto stack and is now popped in esi - - xor edx, edx ; result - xor eax, eax ; current character - xor ebx, ebx ; current byte - - .outer_loop: - shl edx, 8 - add edx, ebx - xor ebx, ebx - .inner_loop: - lodsb - test eax, eax - jz .finish - cmp al, '.' - jz .outer_loop - sub eax, '0' - imul ebx, 10 - add ebx, eax - jmp .inner_loop + xor ecx, ecx ; end result + .charloop: + lodsb + test al, al + jz .finish + cmp al, '.' + je .dot + sub al, '0' + jb .fail + cmp al, 9 + ja .fail + mov dl, cl + shl cl, 2 + jc .fail + add cl, dl + jc .fail + add cl, cl + jc .fail + add cl, al + jc .fail + jmp .charloop + .dot: + shl ecx, 8 + jc .fail + xor cl, cl + jmp .charloop .finish: - shl edx, 8 - add edx, ebx + bswap ecx ; we want little endian order + ret - bswap edx ; we want little endian order - - ret - -no_IP: - pop edx - xor edx, edx - - ret + .fail: + xor ecx, ecx + ret ; DATA AREA @@ -652,10 +700,11 @@ align 16 @IMPORT: library \ - libini,'libini.obj' + libini, 'libini.obj' import libini, \ - ini.get_str,'ini_get_str' + ini.get_str, 'ini_get_str',\ + ini.set_str, 'ini_set_str' include_debug_strings @@ -663,25 +712,26 @@ str_ip db 'ip', 0 str_subnet db 'subnet', 0 str_gateway db 'gateway', 0 str_dns db 'dns', 0 -str_ipconfig db 'ipconfig', 0 -str_type db 'type', 0 +str_ip_type db 'ip_type', 0 +str_dns_type db 'dns_type', 0 -sockaddr1: +str_ini_int db 'ip1', 0 + rb 10 +str_null db 0 + +sock_local: dw AF_INET4 dw 68 shl 8 ; local port dd 0 ; local IP - rb 10 -sockaddr2: - +sock_remote: dw AF_INET4 dw 67 shl 8 ; destination port dd -1 ; destination IP - rb 10 notify_struct: @@ -692,39 +742,25 @@ notify_struct: dd 0 db '/sys/@notify', 0 -str_connected db '"You are now connected to the network." -N', 0 +str_connected db '"You are now connected to the network." -N', 0 +str_disconnected db '"You are now disconnected from the network." -N', 0 +str_conflict db '"An IP address conflict has been detected on the network." -W', 0 -path db '/sys/settings/network.ini',0 +ini_path db '/sys/settings/network.ini',0 IM_END: -device db 1 -inibuf rb 16 -tries db ? - -dhcpMsgType_tx db ? ; sent -dhcpMsgType_rx db ? ; received -dhcpXID dd ? -dhcpLease dd ? -dhcpServerIP dd ? - -dhcp: -.ip dd ? -.subnet dd ? -.dns dd ? -.gateway dd ? - - -dhcpMsgLen dd ? -socketNum dd ? - -MAC dp ? - -currTime dd ? generator dd ? -dhcpMsg dd ? +inibuf rb 16 -timeout dd ? +tx_msg_len dd ? +rx_msg_len dd ? +tx_msg_type db ? +rx_msg_type db ? +tx_msg dhcp_msg +rx_msg dhcp_msg + +device_list rd MAX_INTERFACES*sizeof.interface I_END: \ No newline at end of file