mirror of
https://github.com/ApfelTeeSaft/reactos.git
synced 2026-09-01 19:26:16 +00:00
tcpmisc.h:
- Correct wrongly sized struct IPAddrEntry. dhcp: dhclient.c and dispatch.c - remove lots of #if 0 - remove instances of script_go and associated stuff - write stub check_arp pending ARP api functions being implemented - introduced S_STATIC state for adapters dhcp: api.c: - Do add_protocol and send_discover when telling an adapter to lease. - Do remove_protocol when we make an adapter static. dhcp: adapter.c: - Add infrastructure for finding the adapter key in the registry - Check for IP address settings and apply as static if set, otherwise dynamic tcpip: *info and lan: - Set info types to DEBUG_INFO and DEBUG_DATALINK everywhere tcpip: lan: - Remove kernel IP configuration. bootdata: - Added dhcp service and make it start. - Removed static IP address settings from the default configuration - Removed old JS bootcode svn path=/trunk/; revision=14737
This commit is contained in:
@@ -725,8 +725,8 @@ HKLM,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\New Zealand Standa
|
||||
0x00,0x00,0x0a,0x00,0x00,0x00,0x01,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00
|
||||
|
||||
|
||||
;HKLM,"SOFTWARE\ReactOS\Windows NT\CurrentVersion\Winlogon","Shell",0x00020000,"%SystemRoot%\system32\cmd.exe"
|
||||
HKLM,"SOFTWARE\ReactOS\Windows NT\CurrentVersion\Winlogon","Shell",0x00020000,"%SystemRoot%\explorer.exe"
|
||||
HKLM,"SOFTWARE\ReactOS\Windows NT\CurrentVersion\Winlogon","Shell",0x00020000,"%SystemRoot%\system32\cmd.exe"
|
||||
;HKLM,"SOFTWARE\ReactOS\Windows NT\CurrentVersion\Winlogon","Shell",0x00020000,"%SystemRoot%\explorer.exe"
|
||||
HKLM,"SOFTWARE\ReactOS\Windows NT\CurrentVersion\Winlogon","StartServices",0x00010001,0x00000001
|
||||
HKLM,"SOFTWARE\ReactOS\Windows NT\CurrentVersion\Winlogon","StartGUI",0x00010001,0x00000000
|
||||
HKLM,"SOFTWARE\ReactOS\Windows NT\CurrentVersion\Winlogon","Userinit",0x00020000,"%SystemRoot%\system32\userinit.exe"
|
||||
|
||||
+16
-105
@@ -293,9 +293,9 @@ HKLM,"SYSTEM\CurrentControlSet\Services\3c90x1\Linkage","Export",0x00010000,"\De
|
||||
HKLM,"SYSTEM\CurrentControlSet\Services\3c90x1\Linkage","Route",0x00010000,"3c90x1"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Services\3c90x1\Parameters","SlotNumber",0x00000000,"10"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Services\3c90x1\Parameters","BusNumber",0x00000000,"0"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Services\3c90x1\Parameters\Tcpip","DefaultGateway",0x00010000,"10.0.0.1"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Services\3c90x1\Parameters\Tcpip","IPAddress",0x00010000,"10.0.0.100"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Services\3c90x1\Parameters\Tcpip","SubnetMask",0x00010000,"255.255.255.0"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Services\3c90x1\Parameters\Tcpip","DefaultGateway",0x00010000,"0.0.0.0"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Services\3c90x1\Parameters\Tcpip","IPAddress",0x00010000,"0.0.0.0"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Services\3c90x1\Parameters\Tcpip","SubnetMask",0x00010000,"0.0.0.0"
|
||||
|
||||
; Afd driver
|
||||
HKLM,"SYSTEM\CurrentControlSet\Services\Afd","ErrorControl",0x00010001,0x00000001
|
||||
@@ -446,6 +446,13 @@ HKLM,"SYSTEM\CurrentControlSet\Services\EventLog","ImagePath",0x00020000,"%Syste
|
||||
HKLM,"SYSTEM\CurrentControlSet\Services\EventLog","Start",0x00010001,0x00000002
|
||||
HKLM,"SYSTEM\CurrentControlSet\Services\EventLog","Type",0x00010001,0x00000010
|
||||
|
||||
; DHCP client service
|
||||
HKLM,"SYSTEM\CurrentControlSet\Services\DHCP","ErrorControl",0x00010001,0x00000000
|
||||
HKLM,"SYSTEM\CurrentControlSet\Services\DHCP","Group",0x00000000,"Network"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Services\DHCP","ImagePath",0x00020000,"%SystemRoot%\system32\dhcp.exe"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Services\DHCP","Start",0x00010001,0x00000002
|
||||
HKLM,"SYSTEM\CurrentControlSet\Services\DHCP","Type",0x00010001,0x00000010
|
||||
|
||||
; Floppy driver
|
||||
HKLM,"SYSTEM\CurrentControlSet\Services\Floppy","ErrorControl",0x00010001,0x00000000
|
||||
HKLM,"SYSTEM\CurrentControlSet\Services\Floppy","Group",0x00000000,"Primary Disk"
|
||||
@@ -572,9 +579,9 @@ HKLM,"SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE103
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0001","Port",0x00000000,"280"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0001","Irq",0x00000000,"9"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0001","NetworkAddress",0x00000000,"001122334455"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Services\Ne20001\Parameters\Tcpip","DefaultGateway",0x00010000,"10.0.0.1"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Services\Ne20001\Parameters\Tcpip","IPAddress",0x00010000,"10.0.0.100"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Services\Ne20001\Parameters\Tcpip","SubnetMask",0x00010000,"255.255.255.0"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Services\Ne20001\Parameters\Tcpip","DefaultGateway",0x00010000,"0.0.0.0"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Services\Ne20001\Parameters\Tcpip","IPAddress",0x00010000,"0.0.0.0"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Services\Ne20001\Parameters\Tcpip","SubnetMask",0x00010000,"0.0.0.0"
|
||||
|
||||
; one day this will happen automatically; until then we need this since ndis5 drivers
|
||||
; rely on the fact that their resources are handed to them by ndis, so we have to find
|
||||
@@ -663,9 +670,9 @@ HKLM,"SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE103
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0000","BusNumber",0x00000000,"0"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\{RANDOMCFGGUIDFOR_PCNET1}",,0x00000000,"Network Adapters"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\{RANDOMCFGGUIDFOR_PCNET1}\Connection","Name",0x00000000,"AMD PCNet (static Registry entry)"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Services\PCNet1\Parameters\Tcpip","DefaultGateway",0x00010000,"10.0.0.1"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Services\PCNet1\Parameters\Tcpip","IPAddress",0x00010000,"10.0.0.100"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Services\PCNet1\Parameters\Tcpip","SubnetMask",0x00010000,"255.255.255.0"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Services\PCNet1\Parameters\Tcpip","DefaultGateway",0x00010000,"0.0.0.0"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Services\PCNet1\Parameters\Tcpip","IPAddress",0x00010000,"0.0.0.0"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Services\PCNet1\Parameters\Tcpip","SubnetMask",0x00010000,"0.0.0.0"
|
||||
|
||||
; Named Pipe filesystem driver
|
||||
HKLM,"SYSTEM\CurrentControlSet\Services\Npfs","ErrorControl",0x00010001,0x00000000
|
||||
@@ -867,100 +874,4 @@ HKLM,"SYSTEM\Setup","OsLoaderPath",0x00000000,"\"
|
||||
HKLM,"SYSTEM\Setup","SetupType",0x00010001,0x00000001
|
||||
HKLM,"SYSTEM\Setup","SystemPartition",0x00000000,"\Device\Harddisk0\Partition1"
|
||||
HKLM,"SYSTEM\Setup","SystemSetupInProgress",0x00010001,0x00000000
|
||||
|
||||
; ----------------------------- KJS Init ----------------------------
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","kjsinit",0x00010000,\
|
||||
"function init(v) { var rk = '\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Kdb'; eval(System.regread(rk,v)); } for( i = 1; i <= 45; i++ ) { init((new Number(i)).toString()); }"
|
||||
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","1",0x00010000,\
|
||||
"function write(x) { System.print(x); }"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","2",0x00010000,\
|
||||
"function regs(n) { return System.regs(n); }"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","3",0x00010000,\
|
||||
"function debugebp() { return regs(0); }"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","4",0x00010000,\
|
||||
"function debugeip() { return regs(1); }"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","5",0x00010000,\
|
||||
"function tf_argmark() { return regs(2); }"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","6",0x00010000,\
|
||||
"function tf_pointer() { return regs(3); }"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","7",0x00010000,\
|
||||
"function tf_tempcs() { return regs(4); } "
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","8",0x00010000,\
|
||||
"function tf_tempeip() { return regs(5); } "
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","9",0x00010000,\
|
||||
"function dr0() { return regs(6); } "
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","10",0x00010000,\
|
||||
"function dr1() { return regs(7); } "
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","11",0x00010000,\
|
||||
"function dr2() { return regs(8); } "
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","12",0x00010000,\
|
||||
"function dr3() { return regs(9); } "
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","13",0x00010000,\
|
||||
"function dr6() { return regs(10); } "
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","14",0x00010000,\
|
||||
"function dr7() { return regs(11); } "
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","15",0x00010000,\
|
||||
"function gs() { return regs(12) & 0xffff; }"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","16",0x00010000,\
|
||||
"function es() { return regs(13) & 0xffff; }"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","17",0x00010000,\
|
||||
"function ds() { return regs(14) & 0xffff; }"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","18",0x00010000,\
|
||||
"function edx() { return regs(15); }"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","19",0x00010000,\
|
||||
"function ecx() { return regs(16); }"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","20",0x00010000,\
|
||||
"function eax() { return regs(17); }"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","21",0x00010000,\
|
||||
"function tf_pmode() { return regs(18); }"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","22",0x00010000,\
|
||||
"function tf_exl() { return regs(19); }"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","23",0x00010000,\
|
||||
"function fs() { return regs(20) & 0xffff; }"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","24",0x00010000,\
|
||||
"function edi() { return regs(21); }"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","25",0x00010000,\
|
||||
"function esi() { return regs(22); }"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","26",0x00010000,\
|
||||
"function ebx() { return regs(23); }"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","27",0x00010000,\
|
||||
"function ebp() { return regs(24); }"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","28",0x00010000,\
|
||||
"function error_code() { return regs(25); }"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","29",0x00010000,\
|
||||
"function eip() { return regs(26); }"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","30",0x00010000,\
|
||||
"function cs() { return regs(27) & 0xffff; }"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","31",0x00010000,\
|
||||
"function eflags() { return regs(28); }"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","32",0x00010000,\
|
||||
"function esp() { return regs(29); }"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","33",0x00010000,\
|
||||
"function ss() { return regs(30) & 0xffff; }"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","34",0x00010000,\
|
||||
"function v86_es() { return regs(31) & 0xffff; }"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","35",0x00010000,\
|
||||
"function v86_ds() { return regs(32) & 0xffff; }"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","36",0x00010000,\
|
||||
"function v86_fs() { return regs(33) & 0xffff; }"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","37",0x00010000,\
|
||||
"function v86_gs() { return regs(34) & 0xffff; }"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","38",0x00010000,\
|
||||
"function peekl(a) { return System.mread(4,a); }"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","39",0x00010000,\
|
||||
"function pokel(a,b) { return System.mwrite(4,a,b); }"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","40",0x00010000,\
|
||||
"function peekw(a) { return System.mread(2,a); }"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","41",0x00010000,\
|
||||
"function pokew(a,b) { return System.mwrite(2,a,b); }"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","42",0x00010000,\
|
||||
"function peek(a) { return System.mread(1,a); }"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","43",0x00010000,\
|
||||
"function poke(a,b) { return System.mwrite(1,a,b); }"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","44",0x00010000,\
|
||||
"function regread(x,y) { return System.regread(x,y); }"
|
||||
HKLM,"SYSTEM\CurrentControlSet\Control\Kdb","45",0x00010000,\
|
||||
"write('JS Registry Init Complete. Welcome to ReactOS kernel scripting');"
|
||||
|
||||
; EOF
|
||||
|
||||
@@ -167,6 +167,7 @@ subsys\system\userinit\userinit.exe 1
|
||||
subsys\system\vmwinst\vmwinst.exe 1
|
||||
subsys\system\winlogon\winlogon.exe 1
|
||||
subsys\system\winefile\winefile.exe 1
|
||||
subsys\system\dhcp\dhcp.exe 1
|
||||
services\eventlog\eventlog.exe 1
|
||||
services\rpcss\rpcss.exe 1
|
||||
services\umpnpmgr\umpnpmgr.exe 1
|
||||
|
||||
@@ -189,6 +189,10 @@ NDIS_STATUS LoopRegisterAdapter(
|
||||
|
||||
Loopback = IPCreateInterface(&BindInfo);
|
||||
|
||||
Loopback->Name.Buffer = L"Loopback";
|
||||
Loopback->Name.MaximumLength = Loopback->Name.Length =
|
||||
wcslen(Loopback->Name.Buffer) * sizeof(WCHAR);
|
||||
|
||||
AddrInitIPv4(&Loopback->Unicast, LOOPBACK_ADDRESS_IPv4);
|
||||
AddrInitIPv4(&Loopback->Netmask, LOOPBACK_ADDRMASK_IPv4);
|
||||
|
||||
|
||||
@@ -366,6 +366,8 @@ VOID LanSubmitReceiveWork(
|
||||
PLAN_ADAPTER Adapter = (PLAN_ADAPTER)BindingContext;
|
||||
KIRQL OldIrql;
|
||||
|
||||
TI_DbgPrint(DEBUG_DATALINK,("called\n"));
|
||||
|
||||
TcpipAcquireSpinLock( &LanWorkLock, &OldIrql );
|
||||
|
||||
WQItem = ExAllocatePool( NonPagedPool, sizeof(LAN_WQ_ITEM) );
|
||||
@@ -408,6 +410,8 @@ VOID STDCALL ProtocolTransferDataComplete(
|
||||
{
|
||||
ASSERT(KeGetCurrentIrql() == DISPATCH_LEVEL);
|
||||
|
||||
TI_DbgPrint(DEBUG_DATALINK,("called\n"));
|
||||
|
||||
TransferDataCompleteCalled++;
|
||||
ASSERT(TransferDataCompleteCalled <= TransferDataCalled);
|
||||
|
||||
@@ -736,59 +740,6 @@ OpenRegistryKey( PNDIS_STRING RegistryPath, PHANDLE RegHandle ) {
|
||||
return Status;
|
||||
}
|
||||
|
||||
static NTSTATUS ReadIPAddressFromRegistry( HANDLE RegHandle,
|
||||
PWCHAR RegistryValue,
|
||||
PIP_ADDRESS Address ) {
|
||||
UNICODE_STRING ValueName;
|
||||
UNICODE_STRING UnicodeAddress;
|
||||
NTSTATUS Status;
|
||||
ULONG ResultLength;
|
||||
UCHAR buf[1024];
|
||||
PKEY_VALUE_PARTIAL_INFORMATION Information = (PKEY_VALUE_PARTIAL_INFORMATION)buf;
|
||||
ANSI_STRING AnsiAddress;
|
||||
ULONG AnsiLen;
|
||||
|
||||
RtlInitUnicodeString(&ValueName, RegistryValue);
|
||||
Status =
|
||||
ZwQueryValueKey(RegHandle,
|
||||
&ValueName,
|
||||
KeyValuePartialInformation,
|
||||
Information,
|
||||
sizeof(buf),
|
||||
&ResultLength);
|
||||
|
||||
if (!NT_SUCCESS(Status))
|
||||
return Status;
|
||||
/* IP address is stored as a REG_MULTI_SZ - we only pay attention to the first one though */
|
||||
TI_DbgPrint(MIN_TRACE, ("Information DataLength: 0x%x\n", Information->DataLength));
|
||||
|
||||
UnicodeAddress.Buffer = (PWCHAR)&Information->Data;
|
||||
UnicodeAddress.Length = Information->DataLength;
|
||||
UnicodeAddress.MaximumLength = Information->DataLength;
|
||||
|
||||
AnsiLen = RtlUnicodeStringToAnsiSize(&UnicodeAddress);
|
||||
if(!AnsiLen)
|
||||
return STATUS_NO_MEMORY;
|
||||
|
||||
AnsiAddress.Buffer = exAllocatePoolWithTag(PagedPool, AnsiLen, 0x01020304);
|
||||
if(!AnsiAddress.Buffer)
|
||||
return STATUS_NO_MEMORY;
|
||||
|
||||
AnsiAddress.Length = AnsiLen;
|
||||
AnsiAddress.MaximumLength = AnsiLen;
|
||||
|
||||
Status = RtlUnicodeStringToAnsiString(&AnsiAddress, &UnicodeAddress, FALSE);
|
||||
if (!NT_SUCCESS(Status)) {
|
||||
exFreePool(AnsiAddress.Buffer);
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
}
|
||||
|
||||
AnsiAddress.Buffer[AnsiAddress.Length] = 0;
|
||||
AddrInitIPv4(Address, inet_addr(AnsiAddress.Buffer));
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static NTSTATUS ReadStringFromRegistry( HANDLE RegHandle,
|
||||
PWCHAR RegistryValue,
|
||||
PUNICODE_STRING String ) {
|
||||
@@ -1001,7 +952,7 @@ VOID BindAdapter(
|
||||
PIP_INTERFACE IF;
|
||||
NDIS_STATUS NdisStatus;
|
||||
LLIP_BIND_INFO BindInfo;
|
||||
IP_ADDRESS DefaultGateway, DefaultMask = { 0 };
|
||||
IP_ADDRESS DefaultMask = { 0 };
|
||||
ULONG Lookahead = LOOKAHEAD_SIZE;
|
||||
NTSTATUS Status;
|
||||
HANDLE RegHandle = 0;
|
||||
@@ -1055,20 +1006,10 @@ VOID BindAdapter(
|
||||
TI_DbgPrint(DEBUG_DATALINK,("Adapter Name: %wZ\n", &IF->Name));
|
||||
}
|
||||
|
||||
if(NT_SUCCESS(Status))
|
||||
Status = ReadIPAddressFromRegistry( RegHandle, L"DefaultGateway",
|
||||
&DefaultGateway );
|
||||
if(!NT_SUCCESS(Status)) {
|
||||
Status = STATUS_SUCCESS;
|
||||
RtlZeroMemory( &DefaultGateway, sizeof(DefaultGateway) );
|
||||
}
|
||||
DefaultMask.Type = IP_ADDRESS_V4;
|
||||
|
||||
if(NT_SUCCESS(Status))
|
||||
Status = ReadIPAddressFromRegistry( RegHandle, L"IPAddress",
|
||||
&IF->Unicast );
|
||||
if(NT_SUCCESS(Status))
|
||||
Status = ReadIPAddressFromRegistry( RegHandle, L"SubnetMask",
|
||||
&IF->Netmask );
|
||||
IF->Unicast = DefaultMask;
|
||||
IF->Netmask = DefaultMask;
|
||||
|
||||
IF->Broadcast.Type = IP_ADDRESS_V4;
|
||||
IF->Broadcast.Address.IPv4Address =
|
||||
@@ -1077,33 +1018,6 @@ VOID BindAdapter(
|
||||
|
||||
TI_DbgPrint(DEBUG_DATALINK,("BCAST(IF) %s\n", A2S(&IF->Broadcast)));
|
||||
|
||||
if(NT_SUCCESS(Status)) {
|
||||
/* It's ok to fail some of the above. We'll just use DHCP. */
|
||||
TI_DbgPrint
|
||||
(DEBUG_DATALINK,
|
||||
("--> Our IP address on this interface: '%s'\n",
|
||||
A2S(&IF->Unicast)));
|
||||
|
||||
TI_DbgPrint
|
||||
(DEBUG_DATALINK,
|
||||
("--> Our net mask on this interface: '%s'\n",
|
||||
A2S(&IF->Netmask)));
|
||||
|
||||
if( DefaultGateway.Address.IPv4Address ) {
|
||||
TI_DbgPrint
|
||||
(DEBUG_DATALINK,
|
||||
("--> Our gateway is: '%s'\n",
|
||||
A2S(&DefaultGateway)));
|
||||
|
||||
/* Create a default route */
|
||||
RouterCreateRoute( &DefaultMask, /* Zero */
|
||||
&DefaultMask, /* Zero */
|
||||
&DefaultGateway,
|
||||
IF,
|
||||
1 );
|
||||
}
|
||||
}
|
||||
|
||||
/* Get maximum link speed */
|
||||
NdisStatus = NDISCall(Adapter,
|
||||
NdisRequestQueryInformation,
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#define DEBUG_NCACHE 0x00400000
|
||||
#define DEBUG_CPOINT 0x00800000
|
||||
#define DEBUG_LOCK 0x01000000
|
||||
#define DEBUG_INFO 0x02000000
|
||||
#define DEBUG_ULTRA 0xFFFFFFFF
|
||||
|
||||
#ifdef DBG
|
||||
|
||||
@@ -21,7 +21,7 @@ TDI_STATUS InfoTdiQueryGetInterfaceMIB(TDIEntityID *ID,
|
||||
ULONG Size;
|
||||
UINT DescrLenMax = MAX_IFDESCR_LEN - 1;
|
||||
|
||||
TI_DbgPrint(MAX_TRACE,
|
||||
TI_DbgPrint(DEBUG_INFO,
|
||||
("Getting IFEntry MIB (IF %08x LA %08x) (%04x:%d)\n",
|
||||
Interface, IF, ID->tei_entity, ID->tei_instance));
|
||||
|
||||
@@ -38,7 +38,7 @@ TDI_STATUS InfoTdiQueryGetInterfaceMIB(TDIEntityID *ID,
|
||||
OutData->Type = Interface ==
|
||||
Loopback ? MIB_IF_TYPE_LOOPBACK : MIB_IF_TYPE_ETHERNET;
|
||||
OutData->Mtu = Interface->MTU;
|
||||
TI_DbgPrint(MAX_TRACE,
|
||||
TI_DbgPrint(DEBUG_INFO,
|
||||
("Getting interface speed\n"));
|
||||
OutData->PhysAddrLen = Interface->AddressLength;
|
||||
OutData->AdminStatus = MIB_IF_ADMIN_STATUS_UP;
|
||||
@@ -53,27 +53,28 @@ TDI_STATUS InfoTdiQueryGetInterfaceMIB(TDIEntityID *ID,
|
||||
|
||||
if( IF ) {
|
||||
GetInterfaceSpeed( Interface, (PUINT)&OutData->Speed );
|
||||
TI_DbgPrint(MAX_TRACE,
|
||||
TI_DbgPrint(DEBUG_INFO,
|
||||
("IF Speed = %d * 100bps\n", OutData->Speed));
|
||||
memcpy(OutData->PhysAddr,Interface->Address,Interface->AddressLength);
|
||||
TI_DbgPrint(MAX_TRACE, ("Got HWAddr\n"));
|
||||
GetInterfaceName( Interface, IFDescr, MAX_IFDESCR_LEN - 1 );
|
||||
DescrLenMax = strlen( IFDescr ) + 1;
|
||||
TI_DbgPrint(DEBUG_INFO, ("Got HWAddr\n"));
|
||||
}
|
||||
|
||||
IFDescr[DescrLenMax] = 0; /* Terminate ifdescr string */
|
||||
GetInterfaceName( Interface, IFDescr, MAX_IFDESCR_LEN - 1 );
|
||||
DescrLenMax = strlen( IFDescr ) + 1;
|
||||
|
||||
TI_DbgPrint(MAX_TRACE, ("Copied in name %s\n", IFDescr));
|
||||
TI_DbgPrint(DEBUG_INFO, ("Copied in name %s\n", IFDescr));
|
||||
OutData->DescrLen = DescrLenMax;
|
||||
IFDescr += DescrLenMax;
|
||||
Size = IFDescr - (PCHAR)OutData + 1;
|
||||
|
||||
TI_DbgPrint(MAX_TRACE, ("Finished IFEntry MIB (%04x:%d) size %d\n",
|
||||
TI_DbgPrint(DEBUG_INFO, ("Finished IFEntry MIB (%04x:%d) size %d\n",
|
||||
ID->tei_entity, ID->tei_instance, Size));
|
||||
|
||||
Status = InfoCopyOut( (PCHAR)OutData, Size, Buffer, BufferSize );
|
||||
ExFreePool( OutData );
|
||||
|
||||
TI_DbgPrint(DEBUG_INFO,("Returning %x\n", Status));
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
@@ -104,7 +105,7 @@ TDI_STATUS InfoInterfaceTdiSetEx( UINT InfoClass,
|
||||
TDIEntityID *id,
|
||||
PCHAR Buffer,
|
||||
UINT BufferSize ) {
|
||||
TI_DbgPrint(MAX_TRACE, ("Got Request: Class %x Type %x Id %x, EntityID %x:%x\n",
|
||||
TI_DbgPrint(DEBUG_INFO, ("Got Request: Class %x Type %x Id %x, EntityID %x:%x\n",
|
||||
InfoClass, InfoId, id->tei_entity, id->tei_instance));
|
||||
return TDI_INVALID_REQUEST;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ VOID InsertTDIInterfaceEntity( PIP_INTERFACE Interface ) {
|
||||
KIRQL OldIrql;
|
||||
UINT Count = 0, i;
|
||||
|
||||
TI_DbgPrint(MAX_TRACE,
|
||||
TI_DbgPrint(DEBUG_INFO,
|
||||
("Inserting interface %08x (%d entities already)\n",
|
||||
Interface, EntityCount));
|
||||
|
||||
@@ -38,7 +38,7 @@ VOID InsertTDIInterfaceEntity( PIP_INTERFACE Interface ) {
|
||||
for( i = 0; i < EntityCount; i++ )
|
||||
if( EntityList[i].tei_entity == IF_ENTITY ) {
|
||||
Count++;
|
||||
TI_DbgPrint(MAX_TRACE, ("Entity %d is an IF. Found %d\n",
|
||||
TI_DbgPrint(DEBUG_INFO, ("Entity %d is an IF. Found %d\n",
|
||||
i, Count));
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ TDI_STATUS InfoTdiQueryListEntities(PNDIS_BUFFER Buffer,
|
||||
UINT Count, Size, BufSize = *BufferSize;
|
||||
KIRQL OldIrql;
|
||||
|
||||
TI_DbgPrint(MAX_TRACE,("About to copy %d TDIEntityIDs to user\n",
|
||||
TI_DbgPrint(DEBUG_INFO,("About to copy %d TDIEntityIDs to user\n",
|
||||
EntityCount));
|
||||
|
||||
TcpipAcquireSpinLock(&EntityListLock, &OldIrql);
|
||||
@@ -134,7 +134,7 @@ TDI_STATUS InfoTdiQueryInformationEx(
|
||||
BOOL FoundEntity = FALSE;
|
||||
InfoRequest_f InfoRequest = NULL;
|
||||
|
||||
TI_DbgPrint(MAX_TRACE,
|
||||
TI_DbgPrint(DEBUG_INFO,
|
||||
("InfoEx Req: %x %x %x!%04x:%d\n",
|
||||
ID->toi_class,
|
||||
ID->toi_type,
|
||||
@@ -148,7 +148,7 @@ TDI_STATUS InfoTdiQueryInformationEx(
|
||||
if ((ID->toi_class != INFO_CLASS_GENERIC) ||
|
||||
(ID->toi_type != INFO_TYPE_PROVIDER) ||
|
||||
(ID->toi_id != ENTITY_LIST_ID)) {
|
||||
TI_DbgPrint(MAX_TRACE,("Invalid parameter\n"));
|
||||
TI_DbgPrint(DEBUG_INFO,("Invalid parameter\n"));
|
||||
Status = TDI_INVALID_PARAMETER;
|
||||
} else
|
||||
Status = InfoTdiQueryListEntities(Buffer, BufferSize);
|
||||
@@ -168,7 +168,7 @@ TDI_STATUS InfoTdiQueryInformationEx(
|
||||
TcpipReleaseSpinLock( &EntityListLock, OldIrql );
|
||||
|
||||
if( FoundEntity ) {
|
||||
TI_DbgPrint(MAX_TRACE,
|
||||
TI_DbgPrint(DEBUG_INFO,
|
||||
("Calling Entity %d (%04x:%d) InfoEx (%x,%x,%x)\n",
|
||||
i, ID->toi_entity.tei_entity,
|
||||
ID->toi_entity.tei_instance,
|
||||
@@ -183,7 +183,7 @@ TDI_STATUS InfoTdiQueryInformationEx(
|
||||
}
|
||||
}
|
||||
|
||||
TI_DbgPrint(MAX_TRACE,("Status: %08x\n", Status));
|
||||
TI_DbgPrint(DEBUG_INFO,("Status: %08x\n", Status));
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ TDI_STATUS InfoTdiQueryGetAddrTable( PNDIS_BUFFER Buffer,
|
||||
ExAllocatePool( NonPagedPool, sizeof( IPADDR_ENTRY ) * IfCount );
|
||||
PIPADDR_ENTRY IpCurrent = IpAddress;
|
||||
|
||||
TI_DbgPrint(MAX_TRACE, ("Called.\n"));
|
||||
TI_DbgPrint(DEBUG_INFO, ("Called.\n"));
|
||||
|
||||
TcpipAcquireSpinLock(&InterfaceListLock, &OldIrql);
|
||||
|
||||
@@ -56,7 +56,7 @@ TDI_STATUS InfoTdiQueryGetAddrTable( PNDIS_BUFFER Buffer,
|
||||
|
||||
ExFreePool( IpAddress );
|
||||
|
||||
TI_DbgPrint(MAX_TRACE, ("Returning %08x\n", Status));
|
||||
TI_DbgPrint(DEBUG_INFO, ("Returning %08x\n", Status));
|
||||
|
||||
return Status;
|
||||
}
|
||||
@@ -73,7 +73,7 @@ TDI_STATUS InfoTdiQueryGetRouteTable( PNDIS_BUFFER Buffer, PUINT BufferSize ) {
|
||||
PIPROUTE_ENTRY RouteEntries = ExAllocatePool( NonPagedPool, Size ),
|
||||
RtCurrent = RouteEntries;
|
||||
|
||||
TI_DbgPrint(MAX_TRACE, ("Called, routes = %d, RCache = %08x\n",
|
||||
TI_DbgPrint(DEBUG_INFO, ("Called, routes = %d, RCache = %08x\n",
|
||||
RtCount, RCache));
|
||||
|
||||
if( !RCache || !RouteEntries ) {
|
||||
@@ -106,7 +106,7 @@ TDI_STATUS InfoTdiQueryGetRouteTable( PNDIS_BUFFER Buffer, PUINT BufferSize ) {
|
||||
RtCurrent->Type = TDI_ADDRESS_TYPE_IP;
|
||||
|
||||
TI_DbgPrint
|
||||
(MAX_TRACE,
|
||||
(DEBUG_INFO,
|
||||
("%d: NA %08x NM %08x GW %08x MT %x\n",
|
||||
RtCurrent - RouteEntries,
|
||||
RtCurrent->Dest,
|
||||
@@ -132,7 +132,7 @@ TDI_STATUS InfoTdiQueryGetRouteTable( PNDIS_BUFFER Buffer, PUINT BufferSize ) {
|
||||
ExFreePool( RouteEntries );
|
||||
ExFreePool( RCache );
|
||||
|
||||
TI_DbgPrint(MAX_TRACE, ("Returning %08x\n", Status));
|
||||
TI_DbgPrint(DEBUG_INFO, ("Returning %08x\n", Status));
|
||||
|
||||
return Status;
|
||||
}
|
||||
@@ -144,7 +144,7 @@ TDI_STATUS InfoTdiQueryGetIPSnmpInfo( PNDIS_BUFFER Buffer,
|
||||
UINT RouteCount = CountFIBs( NULL );
|
||||
TDI_STATUS Status = TDI_INVALID_REQUEST;
|
||||
|
||||
TI_DbgPrint(MAX_TRACE, ("Called.\n"));
|
||||
TI_DbgPrint(DEBUG_INFO, ("Called.\n"));
|
||||
|
||||
RtlZeroMemory(&SnmpInfo, sizeof(IPSNMP_INFO));
|
||||
|
||||
@@ -155,7 +155,7 @@ TDI_STATUS InfoTdiQueryGetIPSnmpInfo( PNDIS_BUFFER Buffer,
|
||||
Status = InfoCopyOut( (PCHAR)&SnmpInfo, sizeof(SnmpInfo),
|
||||
Buffer, BufferSize );
|
||||
|
||||
TI_DbgPrint(MAX_TRACE, ("Returning %08x\n", Status));
|
||||
TI_DbgPrint(DEBUG_INFO, ("Returning %08x\n", Status));
|
||||
|
||||
return Status;
|
||||
}
|
||||
@@ -169,7 +169,7 @@ TDI_STATUS InfoNetworkLayerTdiQueryEx( UINT InfoClass,
|
||||
PUINT BufferSize ) {
|
||||
TDI_STATUS Status = TDI_INVALID_REQUEST;
|
||||
|
||||
TI_DbgPrint(MAX_TRACE, ("Called.\n"));
|
||||
TI_DbgPrint(DEBUG_INFO, ("Called.\n"));
|
||||
|
||||
switch( InfoClass ) {
|
||||
case INFO_CLASS_GENERIC:
|
||||
@@ -200,7 +200,7 @@ TDI_STATUS InfoNetworkLayerTdiQueryEx( UINT InfoClass,
|
||||
}
|
||||
}
|
||||
|
||||
TI_DbgPrint(MAX_TRACE, ("Returning %08x\n", Status));
|
||||
TI_DbgPrint(DEBUG_INFO, ("Returning %08x\n", Status));
|
||||
|
||||
return Status;
|
||||
}
|
||||
@@ -218,7 +218,7 @@ TDI_STATUS InfoNetworkLayerTdiSetEx( UINT InfoClass,
|
||||
IP_ADDRESS Router;
|
||||
PNEIGHBOR_CACHE_ENTRY NCE;
|
||||
|
||||
TI_DbgPrint(MID_TRACE,("Called\n"));
|
||||
TI_DbgPrint(DEBUG_INFO,("Called\n"));
|
||||
|
||||
OskitDumpBuffer( (OSK_PCHAR)Buffer, BufferSize );
|
||||
|
||||
@@ -232,7 +232,7 @@ TDI_STATUS InfoNetworkLayerTdiSetEx( UINT InfoClass,
|
||||
AddrInitIPv4( &Router, Route->Gw );
|
||||
|
||||
if( Route->Type == IP_ROUTE_TYPE_ADD ) { /* Add the route */
|
||||
TI_DbgPrint(MID_TRACE,("Adding route (%s)\n", A2S(&Address)));
|
||||
TI_DbgPrint(DEBUG_INFO,("Adding route (%s)\n", A2S(&Address)));
|
||||
/* Find the existing route this belongs to */
|
||||
NCE = RouterGetRoute( &Router );
|
||||
/* Really add the route */
|
||||
@@ -243,12 +243,12 @@ TDI_STATUS InfoNetworkLayerTdiSetEx( UINT InfoClass,
|
||||
else
|
||||
Status = STATUS_UNSUCCESSFUL;
|
||||
} else if( Route->Type == IP_ROUTE_TYPE_DEL ) {
|
||||
TI_DbgPrint(MID_TRACE,("Removing route (%s)\n", A2S(&Address)));
|
||||
TI_DbgPrint(DEBUG_INFO,("Removing route (%s)\n", A2S(&Address)));
|
||||
Status = RouterRemoveRoute( &Address, &Router );
|
||||
} else Status = TDI_INVALID_REQUEST;
|
||||
}
|
||||
|
||||
TI_DbgPrint(MID_TRACE,("Returning %x\n", Status));
|
||||
TI_DbgPrint(DEBUG_INFO,("Returning %x\n", Status));
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ TARGET_OBJECTS = adapter.o alloc.o api.o compat.o dhclient.o dispatch.o \
|
||||
|
||||
TARGET_SDKLIBS = iphlpapi.a ws2_32.a ntdll.a
|
||||
|
||||
TARGET_INSTALLDIR = system32
|
||||
|
||||
TARGET_RC_SRCS = dhcp.rc
|
||||
|
||||
TARGET_RC_BINSRC =
|
||||
|
||||
@@ -5,34 +5,212 @@ static LIST_ENTRY AdapterList;
|
||||
static WSADATA wsd;
|
||||
extern struct interface_info *ifi;
|
||||
|
||||
DWORD GetAddress( PDHCP_ADAPTER Adapter ) {
|
||||
PMIB_IPADDRTABLE AddressTable = NULL;
|
||||
ULONG i, Size = 0, NumAddressRows;
|
||||
DWORD Error = GetIpAddrTable( AddressTable, &Size, FALSE );
|
||||
PCHAR *GetSubkeyNames( PCHAR MainKeyName, PCHAR Append ) {
|
||||
int i = 0;
|
||||
DWORD Error;
|
||||
HKEY MainKey;
|
||||
PCHAR *Out, OutKeyName;
|
||||
DWORD CharTotal = 0, ThisKey, AppendLen = 1 + strlen(Append);
|
||||
DWORD MaxSubKeyLen = 0, MaxSubKeys = 0;
|
||||
|
||||
while( Error == ERROR_INSUFFICIENT_BUFFER ) {
|
||||
free( AddressTable );
|
||||
AddressTable = malloc( Size );
|
||||
if( AddressTable )
|
||||
Error = GetIpAddrTable( AddressTable, &Size, FALSE );
|
||||
}
|
||||
if( Error != ERROR_SUCCESS ) {
|
||||
free( AddressTable );
|
||||
return Error;
|
||||
Error = RegOpenKey( HKEY_LOCAL_MACHINE, MainKeyName, &MainKey );
|
||||
|
||||
if( Error ) return NULL;
|
||||
|
||||
Error = RegQueryInfoKey
|
||||
( MainKey,
|
||||
NULL, NULL, NULL,
|
||||
&MaxSubKeys, &MaxSubKeyLen,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL );
|
||||
|
||||
DH_DbgPrint(MID_TRACE,("MaxSubKeys: %d, MaxSubKeyLen %d\n",
|
||||
MaxSubKeys, MaxSubKeyLen));
|
||||
|
||||
CharTotal = (sizeof(PCHAR) + MaxSubKeyLen + AppendLen) * (MaxSubKeys + 1);
|
||||
|
||||
DH_DbgPrint(MID_TRACE,("AppendLen: %d, CharTotal: %d\n",
|
||||
AppendLen, CharTotal));
|
||||
|
||||
Out = malloc( CharTotal );
|
||||
OutKeyName = ((PCHAR)&Out[MaxSubKeys+1]);
|
||||
|
||||
if( !Out ) { RegCloseKey( MainKey ); return NULL; }
|
||||
|
||||
i = 0;
|
||||
do {
|
||||
Out[i] = OutKeyName;
|
||||
Error = RegEnumKey( MainKey, i, OutKeyName, MaxSubKeyLen );
|
||||
if( !Error ) {
|
||||
strcat( OutKeyName, Append );
|
||||
DH_DbgPrint(MID_TRACE,("[%d]: %s\n", i, OutKeyName));
|
||||
OutKeyName += strlen(OutKeyName) + 1;
|
||||
i++;
|
||||
} else Out[i] = 0;
|
||||
} while( Error == ERROR_SUCCESS );
|
||||
|
||||
RegCloseKey( MainKey );
|
||||
|
||||
return Out;
|
||||
}
|
||||
|
||||
PCHAR RegReadString( HKEY Root, PCHAR Subkey, PCHAR Value ) {
|
||||
PCHAR SubOut = NULL;
|
||||
DWORD SubOutLen = 0, Error = 0;
|
||||
HKEY ValueKey = NULL;
|
||||
|
||||
DH_DbgPrint(MID_TRACE,("Looking in %x:%s:%s\n", Root, Subkey, Value ));
|
||||
|
||||
if( Subkey && strlen(Subkey) ) {
|
||||
if( RegOpenKey( Root, Subkey, &ValueKey ) != ERROR_SUCCESS )
|
||||
goto regerror;
|
||||
} else ValueKey = Root;
|
||||
|
||||
DH_DbgPrint(MID_TRACE,("Got Key %x\n", ValueKey));
|
||||
|
||||
if( (Error = RegQueryValueEx( ValueKey, Value, NULL, NULL,
|
||||
SubOut, &SubOutLen )) != ERROR_SUCCESS )
|
||||
goto regerror;
|
||||
|
||||
DH_DbgPrint(MID_TRACE,("Value %s has size %d\n", Value, SubOutLen));
|
||||
|
||||
if( !(SubOut = malloc(SubOutLen)) )
|
||||
goto regerror;
|
||||
|
||||
if( (Error = RegQueryValueEx( ValueKey, Value, NULL, NULL,
|
||||
SubOut, &SubOutLen )) != ERROR_SUCCESS )
|
||||
goto regerror;
|
||||
|
||||
DH_DbgPrint(MID_TRACE,("Value %s is %s\n", Value, SubOut));
|
||||
|
||||
goto cleanup;
|
||||
|
||||
regerror:
|
||||
if( SubOut ) free( SubOut );
|
||||
cleanup:
|
||||
if( ValueKey && ValueKey != Root ) {
|
||||
DH_DbgPrint(MID_TRACE,("Closing key %x\n", ValueKey));
|
||||
RegCloseKey( ValueKey );
|
||||
}
|
||||
|
||||
NumAddressRows = Size / sizeof(MIB_IPADDRTABLE);
|
||||
for( i = 0; i < AddressTable->dwNumEntries; i++ ) {
|
||||
DH_DbgPrint(MID_TRACE,
|
||||
("Finding address for adapter %d: (%d -> %x)\n",
|
||||
Adapter->IfMib.dwIndex,
|
||||
AddressTable->table[i].dwIndex,
|
||||
AddressTable->table[i].dwAddr));
|
||||
if( Adapter->IfMib.dwIndex == AddressTable->table[i].dwIndex ) {
|
||||
memcpy( &Adapter->IfAddr, &AddressTable->table[i],
|
||||
sizeof( MIB_IPADDRROW ) );
|
||||
DH_DbgPrint(MID_TRACE,("Returning %x with error %d\n", SubOut, Error));
|
||||
|
||||
return SubOut;
|
||||
}
|
||||
|
||||
HKEY FindAdapterKey( PDHCP_ADAPTER Adapter ) {
|
||||
int i = 0;
|
||||
PCHAR EnumKeyName =
|
||||
"SYSTEM\\CurrentControlSet\\Control\\Class\\"
|
||||
"{4D36E972-E325-11CE-BFC1-08002BE10318}";
|
||||
PCHAR TargetKeyNameStart =
|
||||
"SYSTEM\\CurrentControlSet\\Services\\";
|
||||
PCHAR TargetKeyNameEnd = "\\Parameters\\Tcpip";
|
||||
PCHAR TargetKeyName = NULL;
|
||||
PCHAR *EnumKeysLinkage = GetSubkeyNames( EnumKeyName, "\\Linkage" );
|
||||
PCHAR *EnumKeysTop = GetSubkeyNames( EnumKeyName, "" );
|
||||
PCHAR RootDevice = NULL, DriverDesc = NULL;
|
||||
HKEY EnumKey, OutKey = NULL;
|
||||
DWORD Error = ERROR_SUCCESS;
|
||||
|
||||
if( !EnumKeysLinkage || !EnumKeysTop ) goto cleanup;
|
||||
|
||||
Error = RegOpenKey( HKEY_LOCAL_MACHINE, EnumKeyName, &EnumKey );
|
||||
|
||||
if( Error ) goto cleanup;
|
||||
|
||||
for( i = 0; EnumKeysLinkage[i]; i++ ) {
|
||||
RootDevice = RegReadString
|
||||
( EnumKey, EnumKeysLinkage[i], "RootDevice" );
|
||||
DriverDesc = RegReadString
|
||||
( EnumKey, EnumKeysTop[i], "DriverDesc" );
|
||||
|
||||
if( DriverDesc &&
|
||||
!strcmp( DriverDesc, Adapter->DhclientInfo.name ) ) {
|
||||
TargetKeyName =
|
||||
malloc( strlen( TargetKeyNameStart ) +
|
||||
strlen( RootDevice ) +
|
||||
strlen( TargetKeyNameEnd ) + 1 );
|
||||
if( !TargetKeyName ) goto cleanup;
|
||||
sprintf( TargetKeyName, "%s%s%s",
|
||||
TargetKeyNameStart, RootDevice, TargetKeyNameEnd );
|
||||
Error = RegOpenKey( HKEY_LOCAL_MACHINE, TargetKeyName, &OutKey );
|
||||
break;
|
||||
} else {
|
||||
free( RootDevice ); RootDevice = 0;
|
||||
free( DriverDesc ); DriverDesc = 0;
|
||||
}
|
||||
}
|
||||
|
||||
cleanup:
|
||||
if( RootDevice ) free( RootDevice );
|
||||
if( DriverDesc ) free( DriverDesc );
|
||||
if( EnumKeysLinkage ) free( EnumKeysLinkage );
|
||||
if( EnumKeysTop ) free( EnumKeysTop );
|
||||
if( TargetKeyName ) free( TargetKeyName );
|
||||
|
||||
return OutKey;
|
||||
}
|
||||
|
||||
BOOL PrepareAdapterForService( PDHCP_ADAPTER Adapter ) {
|
||||
HKEY AdapterKey = NULL;
|
||||
PCHAR IPAddress = NULL, Netmask = NULL, DefaultGateway = NULL;
|
||||
NTSTATUS Status = STATUS_SUCCESS;
|
||||
DWORD Error = ERROR_SUCCESS;
|
||||
MIB_IPFORWARDROW DefGatewayRow;
|
||||
|
||||
Adapter->DhclientState.config = &Adapter->DhclientConfig;
|
||||
strncpy(Adapter->DhclientInfo.name, Adapter->IfMib.bDescr,
|
||||
sizeof(Adapter->DhclientInfo.name));
|
||||
|
||||
AdapterKey = FindAdapterKey( Adapter );
|
||||
if( AdapterKey )
|
||||
IPAddress = RegReadString( AdapterKey, NULL, "IPAddress" );
|
||||
|
||||
if( IPAddress && strcmp( IPAddress, "0.0.0.0" ) ) {
|
||||
/* Non-automatic case */
|
||||
DH_DbgPrint
|
||||
(MID_TRACE,("Adapter Name: [%s] (Bind Status %x) (static %s)\n",
|
||||
Adapter->DhclientInfo.name,
|
||||
Adapter->BindStatus,
|
||||
IPAddress));
|
||||
|
||||
Adapter->DhclientState.state = S_STATIC;
|
||||
|
||||
Netmask = RegReadString( AdapterKey, NULL, "Subnetmask" );
|
||||
if( !Netmask ) Netmask = "255.255.255.0";
|
||||
|
||||
Status = AddIPAddress( inet_addr( IPAddress ),
|
||||
inet_addr( Netmask ),
|
||||
Adapter->IfMib.dwIndex,
|
||||
&Adapter->NteContext,
|
||||
&Adapter->NteInstance );
|
||||
|
||||
DefaultGateway = RegReadString( AdapterKey, NULL, "DefaultGateway" );
|
||||
|
||||
if( DefaultGateway ) {
|
||||
DefGatewayRow.dwForwardDest = 0;
|
||||
DefGatewayRow.dwForwardMask = 0;
|
||||
DefGatewayRow.dwForwardMetric1 = 1;
|
||||
DefGatewayRow.dwForwardNextHop = inet_addr(DefaultGateway);
|
||||
Error = CreateIpForwardEntry( &DefGatewayRow );
|
||||
if( Error )
|
||||
warning("Failed to set default gateway %s: %d\n",
|
||||
DefaultGateway, Error);
|
||||
}
|
||||
|
||||
if( DefaultGateway ) free( DefaultGateway );
|
||||
if( Netmask ) free( Netmask );
|
||||
} else {
|
||||
/* Automatic case */
|
||||
DH_DbgPrint
|
||||
(MID_TRACE,("Adapter Name: [%s] (Bind Status %x) (dynamic)\n",
|
||||
Adapter->DhclientInfo.name,
|
||||
Adapter->BindStatus));
|
||||
}
|
||||
|
||||
if( IPAddress ) free( IPAddress );
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -66,20 +244,23 @@ void AdapterInit() {
|
||||
Table->table[i].dwIndex));
|
||||
Adapter = calloc( sizeof( DHCP_ADAPTER ) + Table->table[i].dwMtu, 1 );
|
||||
|
||||
if( Adapter && Table->table[i].dwType ) {
|
||||
if( Adapter && Table->table[i].dwType == MIB_IF_TYPE_ETHERNET ) {
|
||||
memcpy( &Adapter->IfMib, &Table->table[i],
|
||||
sizeof(Adapter->IfMib) );
|
||||
GetAddress( Adapter );
|
||||
InsertTailList( &AdapterList, &Adapter->ListEntry );
|
||||
Adapter->DhclientInfo.next = ifi;
|
||||
Adapter->DhclientInfo.client = &Adapter->DhclientState;
|
||||
Adapter->DhclientInfo.rbuf = Adapter->recv_buf;
|
||||
Adapter->DhclientInfo.rbuf_max = Table->table[i].dwMtu;
|
||||
Adapter->DhclientInfo.rbuf_len =
|
||||
Adapter->DhclientInfo.rbuf_offset = 0;
|
||||
memcpy(Adapter->DhclientInfo.hw_address.haddr,
|
||||
Adapter->IfMib.bPhysAddr,
|
||||
Adapter->IfMib.dwPhysAddrLen);
|
||||
Adapter->DhclientInfo.hw_address.hlen =
|
||||
Adapter->IfMib.dwPhysAddrLen;
|
||||
|
||||
if( DhcpSocket == INVALID_SOCKET ) {
|
||||
DhcpSocket =
|
||||
Adapter->DhclientInfo.rfdesc =
|
||||
Adapter->DhclientInfo.rfdesc =
|
||||
Adapter->DhclientInfo.wfdesc =
|
||||
socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
|
||||
Adapter->ListenAddr.sin_family = AF_INET;
|
||||
@@ -93,7 +274,7 @@ void AdapterInit() {
|
||||
Adapter->DhclientInfo.rfdesc =
|
||||
Adapter->DhclientInfo.wfdesc = DhcpSocket;
|
||||
}
|
||||
Adapter->DhclientState.config = &Adapter->DhclientConfig;
|
||||
|
||||
Adapter->DhclientConfig.timeout = DHCP_PANIC_TIMEOUT;
|
||||
Adapter->DhclientConfig.initial_interval = DHCP_DISCOVER_INTERVAL;
|
||||
Adapter->DhclientConfig.retry_interval = DHCP_DISCOVER_INTERVAL;
|
||||
@@ -102,13 +283,17 @@ void AdapterInit() {
|
||||
Adapter->DhclientConfig.backoff_cutoff = DHCP_BACKOFF_MAX;
|
||||
Adapter->DhclientState.interval =
|
||||
Adapter->DhclientConfig.retry_interval;
|
||||
strncpy(Adapter->DhclientInfo.name, Adapter->IfMib.bDescr,
|
||||
sizeof(Adapter->DhclientInfo.name));
|
||||
DH_DbgPrint(MID_TRACE,("Adapter Name: [%s] (Bind Status %x)\n",
|
||||
Adapter->DhclientInfo.name,
|
||||
Adapter->BindStatus));
|
||||
ifi = &Adapter->DhclientInfo;
|
||||
}
|
||||
|
||||
if( PrepareAdapterForService( Adapter ) ) {
|
||||
Adapter->DhclientInfo.next = ifi;
|
||||
ifi = &Adapter->DhclientInfo;
|
||||
InsertTailList( &AdapterList, &Adapter->ListEntry );
|
||||
} else { free( Adapter ); Adapter = 0; }
|
||||
} else { free( Adapter ); Adapter = 0; }
|
||||
|
||||
if( !Adapter )
|
||||
DH_DbgPrint(MID_TRACE,("Adapter %d was rejected\n",
|
||||
Table->table[i].dwIndex));
|
||||
}
|
||||
|
||||
DH_DbgPrint(MID_TRACE,("done with AdapterInit\n"));
|
||||
|
||||
@@ -38,8 +38,11 @@ DWORD DSLeaseIpAddress( PipeSendFunc Send, COMM_DHCP_REQ *Req ) {
|
||||
Reply.Reply = Adapter ? 1 : 0;
|
||||
|
||||
if( Adapter ) {
|
||||
Adapter->DhclientState.state = S_REBOOTING;
|
||||
send_discover( &Adapter->DhclientInfo );
|
||||
add_protocol( Adapter->DhclientInfo.name,
|
||||
Adapter->DhclientInfo.rfdesc, got_one,
|
||||
&Adapter->DhclientInfo );
|
||||
Adapter->DhclientInfo.client->state = S_INIT;
|
||||
state_reboot(&Adapter->DhclientInfo);
|
||||
}
|
||||
|
||||
ApiUnlock();
|
||||
@@ -77,6 +80,7 @@ DWORD DSReleaseIpAddressLease( PipeSendFunc Send, COMM_DHCP_REQ *Req ) {
|
||||
|
||||
if( Adapter ) {
|
||||
DeleteIPAddress( Adapter->NteContext );
|
||||
remove_protocol( find_protocol_by_adapter( &Adapter->DhclientInfo ) );
|
||||
}
|
||||
|
||||
ApiUnlock();
|
||||
@@ -101,6 +105,7 @@ DWORD DSRenewIpAddressLease( PipeSendFunc Send, COMM_DHCP_REQ *Req ) {
|
||||
|
||||
Adapter->DhclientState.state = S_BOUND;
|
||||
|
||||
send_discover( &Adapter->DhclientInfo );
|
||||
state_bound( &Adapter->DhclientInfo );
|
||||
|
||||
ApiUnlock();
|
||||
@@ -121,7 +126,8 @@ DWORD DSStaticRefreshParams( PipeSendFunc Send, COMM_DHCP_REQ *Req ) {
|
||||
|
||||
if( Adapter ) {
|
||||
DeleteIPAddress( Adapter->NteContext );
|
||||
Adapter->DhclientState.state = S_BOUND;
|
||||
Adapter->DhclientState.state = S_STATIC;
|
||||
remove_protocol( find_protocol_by_adapter( &Adapter->DhclientInfo ) );
|
||||
Status = AddIPAddress( Req->Body.StaticRefreshParams.IPAddress,
|
||||
Req->Body.StaticRefreshParams.Netmask,
|
||||
Req->AdapterIndex,
|
||||
|
||||
@@ -108,6 +108,7 @@ int ipv4addrs(char * buf);
|
||||
int res_hnok(const char *dn);
|
||||
char *option_as_string(unsigned int code, unsigned char *data, int len);
|
||||
int fork_privchld(int, int);
|
||||
int check_arp( struct interface_info *ip, struct client_lease *lp );
|
||||
|
||||
#define ROUNDUP(a) \
|
||||
((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
|
||||
@@ -115,143 +116,11 @@ int fork_privchld(int, int);
|
||||
|
||||
time_t scripttime;
|
||||
|
||||
#if 0
|
||||
|
||||
int
|
||||
findproto(char *cp, int n)
|
||||
{
|
||||
struct sockaddr *sa;
|
||||
int i;
|
||||
|
||||
if (n == 0)
|
||||
return -1;
|
||||
for (i = 1; i; i <<= 1) {
|
||||
if (i & n) {
|
||||
sa = (struct sockaddr *)cp;
|
||||
switch (i) {
|
||||
case RTA_IFA:
|
||||
case RTA_DST:
|
||||
case RTA_GATEWAY:
|
||||
case RTA_NETMASK:
|
||||
if (sa->sa_family == AF_INET)
|
||||
return AF_INET;
|
||||
if (sa->sa_family == AF_INET6)
|
||||
return AF_INET6;
|
||||
break;
|
||||
case RTA_IFP:
|
||||
break;
|
||||
}
|
||||
ADVANCE(cp, sa);
|
||||
}
|
||||
}
|
||||
return (-1);
|
||||
/* XXX Implement me */
|
||||
int check_arp( struct interface_info *ip, struct client_lease *lp ) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
struct sockaddr *
|
||||
get_ifa(char *cp, int n)
|
||||
{
|
||||
struct sockaddr *sa;
|
||||
int i;
|
||||
|
||||
if (n == 0)
|
||||
return (NULL);
|
||||
for (i = 1; i; i <<= 1)
|
||||
if (i & n) {
|
||||
sa = (struct sockaddr *)cp;
|
||||
if (i == RTA_IFA)
|
||||
return (sa);
|
||||
ADVANCE(cp, sa);
|
||||
}
|
||||
|
||||
return (NULL);
|
||||
}
|
||||
struct iaddr defaddr = { 4 };
|
||||
|
||||
/* ARGSUSED */
|
||||
void
|
||||
routehandler(struct protocol *p)
|
||||
{
|
||||
char msg[2048];
|
||||
struct rt_msghdr *rtm;
|
||||
struct if_msghdr *ifm;
|
||||
struct ifa_msghdr *ifam;
|
||||
struct if_announcemsghdr *ifan;
|
||||
struct client_lease *l;
|
||||
time_t t = time(NULL);
|
||||
struct sockaddr *sa;
|
||||
struct iaddr a;
|
||||
ssize_t n;
|
||||
|
||||
n = read(routefd, &msg, sizeof(msg));
|
||||
rtm = (struct rt_msghdr *)msg;
|
||||
if (n < sizeof(rtm->rtm_msglen) || n < rtm->rtm_msglen ||
|
||||
rtm->rtm_version != RTM_VERSION)
|
||||
return;
|
||||
|
||||
switch (rtm->rtm_type) {
|
||||
case RTM_NEWADDR:
|
||||
ifam = (struct ifa_msghdr *)rtm;
|
||||
if (ifam->ifam_index != ifi->index)
|
||||
break;
|
||||
if (findproto((char *)(ifam + 1), ifam->ifam_addrs) != AF_INET)
|
||||
break;
|
||||
if (ifi == NULL)
|
||||
goto die;
|
||||
sa = get_ifa((char *)(ifam + 1), ifam->ifam_addrs);
|
||||
if (sa == NULL)
|
||||
goto die;
|
||||
|
||||
if ((a.len = sizeof(struct in_addr)) > sizeof(a.iabuf))
|
||||
error("king bula sez: len mismatch");
|
||||
memcpy(a.iabuf, &((struct sockaddr_in *)sa)->sin_addr, a.len);
|
||||
if (addr_eq(a, defaddr))
|
||||
break;
|
||||
|
||||
for (l = ifi->client->active; l != NULL; l = l->next)
|
||||
if (addr_eq(a, l->address))
|
||||
break;
|
||||
|
||||
if (l != NULL) /* new addr is the one we set */
|
||||
break;
|
||||
|
||||
goto die;
|
||||
case RTM_DELADDR:
|
||||
ifam = (struct ifa_msghdr *)rtm;
|
||||
if (ifam->ifam_index != ifi->index)
|
||||
break;
|
||||
if (findproto((char *)(ifam + 1), ifam->ifam_addrs) != AF_INET)
|
||||
break;
|
||||
if (scripttime == 0 || t < scripttime + 10)
|
||||
break;
|
||||
goto die;
|
||||
case RTM_IFINFO:
|
||||
ifm = (struct if_msghdr *)rtm;
|
||||
if (ifm->ifm_index != ifi->index)
|
||||
break;
|
||||
if ((rtm->rtm_flags & RTF_UP) == 0)
|
||||
goto die;
|
||||
break;
|
||||
case RTM_IFANNOUNCE:
|
||||
ifan = (struct if_announcemsghdr *)rtm;
|
||||
if (ifan->ifan_what == IFAN_DEPARTURE &&
|
||||
ifan->ifan_index == ifi->index)
|
||||
goto die;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return;
|
||||
|
||||
die:
|
||||
script_init("FAIL", NULL);
|
||||
if (ifi->client->alias)
|
||||
script_write_params("alias_", ifi->client->alias);
|
||||
script_go();
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
@@ -299,9 +168,6 @@ main(int argc, char *argv[])
|
||||
(MID_TRACE,
|
||||
("Setting init state and restarting interface %p\n",ifi));
|
||||
|
||||
ifi->client->state = S_INIT;
|
||||
state_reboot(ifi);
|
||||
|
||||
bootp_packet_handler = do_packet;
|
||||
|
||||
DH_DbgPrint(MID_TRACE,("Going into dispatch()\n"));
|
||||
@@ -438,20 +304,7 @@ state_selecting(void *ipp)
|
||||
/* Check to see if we got an ARPREPLY for the address
|
||||
in this particular lease. */
|
||||
if (!picked) {
|
||||
script_init("ARPCHECK", lp->medium);
|
||||
script_write_params("check_", lp);
|
||||
|
||||
/* If the ARPCHECK code detects another
|
||||
machine using the offered address, it exits
|
||||
nonzero. We need to send a DHCPDECLINE and
|
||||
toss the lease. */
|
||||
#if 0 /* XXX Later check ARP. For now, trust leases */
|
||||
if (script_go()) {
|
||||
make_decline(ip, lp);
|
||||
send_decline(ip);
|
||||
goto freeit;
|
||||
}
|
||||
#endif
|
||||
if( !check_arp(ip,lp) ) goto freeit;
|
||||
picked = lp;
|
||||
picked->next = NULL;
|
||||
} else {
|
||||
@@ -805,8 +658,8 @@ dhcpoffer(struct packet *packet)
|
||||
/* If we're not receptive to an offer right now, or if the offer
|
||||
has an unrecognizable transaction id, then just drop it. */
|
||||
if (ip->client->state != S_SELECTING ||
|
||||
packet->interface->client->xid != packet->raw->xid ||
|
||||
(packet->interface->hw_address.hlen != packet->raw->hlen) ||
|
||||
packet->interface->client->xid != packet->raw->xid ||
|
||||
(packet->interface->hw_address.hlen != packet->raw->hlen) ||
|
||||
(memcmp(packet->interface->hw_address.haddr,
|
||||
packet->raw->chaddr, packet->raw->hlen)))
|
||||
return;
|
||||
@@ -850,14 +703,10 @@ dhcpoffer(struct packet *packet)
|
||||
lease->medium = ip->client->medium;
|
||||
|
||||
/* Send out an ARP Request for the offered IP address. */
|
||||
script_init("ARPSEND", lease->medium);
|
||||
script_write_params("check_", lease);
|
||||
/* If the script can't send an ARP request without waiting,
|
||||
we'll be waiting when we do the ARPCHECK, so don't wait now. */
|
||||
if (script_go())
|
||||
arp_timeout_needed = 0;
|
||||
else
|
||||
arp_timeout_needed = 2;
|
||||
if( !check_arp( ip, lease ) ) {
|
||||
note("Arp check failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Figure out when we're supposed to stop selecting. */
|
||||
stop_selecting =
|
||||
@@ -1072,9 +921,7 @@ again:
|
||||
|
||||
note("Trying medium \"%s\" %d", ip->client->medium->string,
|
||||
increase);
|
||||
script_init("MEDIUM", ip->client->medium);
|
||||
if (script_go())
|
||||
goto again;
|
||||
/* XXX Support other media types eventually */
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1170,25 +1017,22 @@ state_panic(void *ipp)
|
||||
/* If the old lease is still good and doesn't
|
||||
yet need renewal, go into BOUND state and
|
||||
timeout at the renewal time. */
|
||||
if (!script_go()) {
|
||||
if (cur_time <
|
||||
ip->client->active->renewal) {
|
||||
ip->client->state = S_BOUND;
|
||||
note("bound: renewal in %d seconds.",
|
||||
ip->client->active->renewal -
|
||||
cur_time);
|
||||
add_timeout(
|
||||
ip->client->active->renewal,
|
||||
state_bound, ip);
|
||||
} else {
|
||||
ip->client->state = S_BOUND;
|
||||
note("bound: immediate renewal.");
|
||||
state_bound(ip);
|
||||
}
|
||||
reinitialize_interfaces();
|
||||
//go_daemon();
|
||||
return;
|
||||
}
|
||||
if (cur_time <
|
||||
ip->client->active->renewal) {
|
||||
ip->client->state = S_BOUND;
|
||||
note("bound: renewal in %d seconds.",
|
||||
ip->client->active->renewal -
|
||||
cur_time);
|
||||
add_timeout(
|
||||
ip->client->active->renewal,
|
||||
state_bound, ip);
|
||||
} else {
|
||||
ip->client->state = S_BOUND;
|
||||
note("bound: immediate renewal.");
|
||||
state_bound(ip);
|
||||
}
|
||||
reinitialize_interfaces();
|
||||
return;
|
||||
}
|
||||
|
||||
/* If there are no other leases, give up. */
|
||||
@@ -1222,14 +1066,10 @@ activate_next:
|
||||
tell the shell script that we failed to allocate an address,
|
||||
and try again later. */
|
||||
note("No working leases in persistent database - sleeping.\n");
|
||||
script_init("FAIL", NULL);
|
||||
if (ip->client->alias)
|
||||
script_write_params("alias_", ip->client->alias);
|
||||
script_go();
|
||||
ip->client->state = S_INIT;
|
||||
add_timeout(cur_time + ip->client->config->retry_interval, state_init,
|
||||
ip);
|
||||
// go_daemon();
|
||||
/* XXX Take any failure actions necessary */
|
||||
}
|
||||
|
||||
void
|
||||
@@ -1271,8 +1111,7 @@ cancel:
|
||||
script_init("MEDIUM", ip->client->active->medium);
|
||||
|
||||
/* If the medium we chose won't fly, go to INIT state. */
|
||||
if (script_go())
|
||||
goto cancel;
|
||||
/* XXX Nothing for now */
|
||||
|
||||
/* Record the medium. */
|
||||
ip->client->medium = ip->client->active->medium;
|
||||
@@ -1282,23 +1121,18 @@ cancel:
|
||||
to the INIT state. */
|
||||
if (ip->client->state != S_REQUESTING &&
|
||||
cur_time > ip->client->active->expiry) {
|
||||
/* Run the client script with the new parameters. */
|
||||
script_init("EXPIRE", NULL);
|
||||
script_write_params("old_", ip->client->active);
|
||||
if (ip->client->alias)
|
||||
script_write_params("alias_", ip->client->alias);
|
||||
script_go();
|
||||
PDHCP_ADAPTER Adapter = AdapterFindInfo( ip );
|
||||
/* Run the client script with the new parameters. */
|
||||
/* No script actions necessary in the expiry case */
|
||||
/* Now do a preinit on the interface so that we can
|
||||
discover a new address. */
|
||||
|
||||
/* Now do a preinit on the interface so that we can
|
||||
discover a new address. */
|
||||
script_init("PREINIT", NULL);
|
||||
if (ip->client->alias)
|
||||
script_write_params("alias_", ip->client->alias);
|
||||
script_go();
|
||||
|
||||
ip->client->state = S_INIT;
|
||||
state_init(ip);
|
||||
return;
|
||||
if( Adapter )
|
||||
DeleteIPAddress( Adapter->NteContext );
|
||||
|
||||
ip->client->state = S_INIT;
|
||||
state_init(ip);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Do the exponential backoff... */
|
||||
@@ -1974,158 +1808,6 @@ script_write_params(char *prefix, struct client_lease *lease)
|
||||
error("buf_close: %m");
|
||||
}
|
||||
|
||||
int
|
||||
script_go(void)
|
||||
{
|
||||
struct imsg_hdr hdr;
|
||||
struct buf *buf;
|
||||
int ret;
|
||||
|
||||
scripttime = time(NULL);
|
||||
|
||||
hdr.code = IMSG_SCRIPT_GO;
|
||||
hdr.len = sizeof(struct imsg_hdr);
|
||||
|
||||
if ((buf = buf_open(hdr.len)) == NULL)
|
||||
error("buf_open: %m");
|
||||
|
||||
if (buf_add(buf, &hdr, sizeof(hdr)))
|
||||
error("buf_add: %m");
|
||||
|
||||
if (buf_close(privfd, buf) == -1)
|
||||
error("buf_close: %m");
|
||||
|
||||
memset(&hdr, 0, sizeof(hdr));
|
||||
//bzero(&hdr, sizeof(hdr));
|
||||
buf_read(privfd, &hdr, sizeof(hdr));
|
||||
if (hdr.code != IMSG_SCRIPT_GO_RET)
|
||||
error("unexpected msg type %u", hdr.code);
|
||||
if (hdr.len != sizeof(hdr) + sizeof(int))
|
||||
error("received corrupted message");
|
||||
buf_read(privfd, &ret, sizeof(ret));
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
#if 0
|
||||
int
|
||||
priv_script_go(void)
|
||||
{
|
||||
char *scriptName, *argv[2], **envp, *epp[3], reason[] = "REASON=NBI";
|
||||
static char client_path[] = CLIENT_PATH;
|
||||
struct interface_info *ip = ifi;
|
||||
int pid, wpid, wstatus;
|
||||
|
||||
scripttime = time(NULL);
|
||||
|
||||
if (ip) {
|
||||
scriptName = ip->client->config->script_name;
|
||||
envp = ip->client->scriptEnv;
|
||||
} else {
|
||||
scriptName = top_level_config.script_name;
|
||||
epp[0] = reason;
|
||||
epp[1] = client_path;
|
||||
epp[2] = NULL;
|
||||
envp = epp;
|
||||
}
|
||||
|
||||
argv[0] = scriptName;
|
||||
argv[1] = NULL;
|
||||
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
error("fork: %m");
|
||||
wstatus = 0;
|
||||
} else if (pid) {
|
||||
do {
|
||||
wpid = wait(&wstatus);
|
||||
} while (wpid != pid && wpid > 0);
|
||||
if (wpid < 0) {
|
||||
error("wait: %m");
|
||||
wstatus = 0;
|
||||
}
|
||||
} else {
|
||||
execve(scriptName, argv, envp);
|
||||
error("execve (%s, ...): %m", scriptName);
|
||||
}
|
||||
|
||||
if (ip)
|
||||
script_flush_env(ip->client);
|
||||
|
||||
return (wstatus & 0xff);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
void
|
||||
script_set_env(struct client_state *client, const char *prefix,
|
||||
const char *name, const char *value)
|
||||
{
|
||||
int i, j, namelen;
|
||||
|
||||
namelen = strlen(name);
|
||||
|
||||
for (i = 0; client->scriptEnv[i]; i++)
|
||||
if (strncmp(client->scriptEnv[i], name, namelen) == 0 &&
|
||||
client->scriptEnv[i][namelen] == '=')
|
||||
break;
|
||||
|
||||
if (client->scriptEnv[i])
|
||||
/* Reuse the slot. */
|
||||
free(client->scriptEnv[i]);
|
||||
else {
|
||||
/* New variable. Expand if necessary. */
|
||||
if (i >= client->scriptEnvsize - 1) {
|
||||
char **newscriptEnv;
|
||||
int newscriptEnvsize = client->scriptEnvsize + 50;
|
||||
|
||||
newscriptEnv = realloc(client->scriptEnv,
|
||||
newscriptEnvsize);
|
||||
if (newscriptEnv == NULL) {
|
||||
free(client->scriptEnv);
|
||||
client->scriptEnv = NULL;
|
||||
client->scriptEnvsize = 0;
|
||||
error("script_set_env: no memory for variable");
|
||||
}
|
||||
client->scriptEnv = newscriptEnv;
|
||||
client->scriptEnvsize = newscriptEnvsize;
|
||||
}
|
||||
/* need to set the NULL pointer at end of array beyond
|
||||
the new slot. */
|
||||
client->scriptEnv[i + 1] = NULL;
|
||||
}
|
||||
/* Allocate space and format the variable in the appropriate slot. */
|
||||
client->scriptEnv[i] = malloc(strlen(prefix) + strlen(name) + 1 +
|
||||
strlen(value) + 1);
|
||||
if (client->scriptEnv[i] == NULL)
|
||||
error("script_set_env: no memory for variable assignment");
|
||||
|
||||
/* No `` or $() command substitution allowed in environment values! */
|
||||
for (j=0; j < strlen(value); j++)
|
||||
switch (value[j]) {
|
||||
case '`':
|
||||
case '$':
|
||||
error("illegal character (%c) in value '%s'", value[j],
|
||||
value);
|
||||
/* not reached */
|
||||
}
|
||||
snprintf(client->scriptEnv[i], strlen(prefix) + strlen(name) +
|
||||
1 + strlen(value) + 1, "%s%s=%s", prefix, name, value);
|
||||
}
|
||||
|
||||
void
|
||||
script_flush_env(struct client_state *client)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; client->scriptEnv[i]; i++) {
|
||||
free(client->scriptEnv[i]);
|
||||
client->scriptEnv[i] = NULL;
|
||||
}
|
||||
client->scriptEnvsize = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
dhcp_option_ev_name(char *buf, size_t buflen, struct dhcp_option *option)
|
||||
{
|
||||
|
||||
@@ -63,120 +63,21 @@ static int interface_status(struct interface_info *ifinfo);
|
||||
* register that interface with the network I/O software, figure out
|
||||
* what subnet it's on, and add it to the list of interfaces.
|
||||
*/
|
||||
#if 0
|
||||
void
|
||||
discover_interfaces(struct interface_info *iface)
|
||||
{
|
||||
struct ifaddrs *ifap, *ifa;
|
||||
struct sockaddr_in foo;
|
||||
struct ifreq *tif;
|
||||
|
||||
if (getifaddrs(&ifap) != 0)
|
||||
error("getifaddrs failed");
|
||||
|
||||
for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) {
|
||||
if ((ifa->ifa_flags & IFF_LOOPBACK) ||
|
||||
(ifa->ifa_flags & IFF_POINTOPOINT) ||
|
||||
(!(ifa->ifa_flags & IFF_UP)))
|
||||
continue;
|
||||
|
||||
|
||||
if (strcmp(iface->name, ifa->ifa_name))
|
||||
continue;
|
||||
|
||||
/*
|
||||
* If we have the capability, extract link information
|
||||
* and record it in a linked list.
|
||||
*/
|
||||
if (ifa->ifa_addr->sa_family == AF_LINK) {
|
||||
struct sockaddr_dl *foo =
|
||||
(struct sockaddr_dl *)ifa->ifa_addr;
|
||||
|
||||
iface->index = foo->sdl_index;
|
||||
iface->hw_address.hlen = foo->sdl_alen;
|
||||
iface->hw_address.htype = HTYPE_ETHER; /* XXX */
|
||||
memcpy(iface->hw_address.haddr,
|
||||
LLADDR(foo), foo->sdl_alen);
|
||||
} else if (ifa->ifa_addr->sa_family == AF_INET) {
|
||||
struct iaddr addr;
|
||||
|
||||
memcpy(&foo, ifa->ifa_addr, sizeof(foo));
|
||||
if (foo.sin_addr.s_addr == htonl(INADDR_LOOPBACK))
|
||||
continue;
|
||||
if (!iface->ifp) {
|
||||
int len = IFNAMSIZ + ifa->ifa_addr->sa_len;
|
||||
if ((tif = malloc(len)) == NULL)
|
||||
error("no space to remember ifp");
|
||||
strlcpy(tif->ifr_name, ifa->ifa_name, IFNAMSIZ);
|
||||
memcpy(&tif->ifr_addr, ifa->ifa_addr,
|
||||
ifa->ifa_addr->sa_len);
|
||||
iface->ifp = tif;
|
||||
iface->primary_address = foo.sin_addr;
|
||||
}
|
||||
addr.len = 4;
|
||||
memcpy(addr.iabuf, &foo.sin_addr.s_addr, addr.len);
|
||||
}
|
||||
}
|
||||
|
||||
if (!iface->ifp)
|
||||
error("%s: not found", iface->name);
|
||||
|
||||
/* Register the interface... */
|
||||
if_register_receive(iface);
|
||||
if_register_send(iface);
|
||||
add_protocol(iface->name, iface->rfdesc, got_one, iface);
|
||||
freeifaddrs(ifap);
|
||||
}
|
||||
#else
|
||||
void
|
||||
discover_interfaces(struct interface_info *iface)
|
||||
{
|
||||
NTSTATUS Status;
|
||||
ULONG dim;
|
||||
char TmpName [IFNAMSIZ];
|
||||
PDHCP_ADAPTER Adapter = AdapterFindInfo( iface );
|
||||
|
||||
PIP_ADAPTER_INFO pAdapterInfo;
|
||||
PIP_ADAPTER_INFO pAdapter = NULL;
|
||||
if_register_receive(iface);
|
||||
if_register_send(iface);
|
||||
|
||||
pAdapterInfo = malloc(sizeof(IP_ADAPTER_INFO));
|
||||
dim = sizeof(IP_ADAPTER_INFO);
|
||||
|
||||
if (GetAdaptersInfo( pAdapterInfo, &dim) != ERROR_SUCCESS) {
|
||||
free(pAdapterInfo);
|
||||
pAdapterInfo = (IP_ADAPTER_INFO *) malloc (dim);
|
||||
}
|
||||
|
||||
if ((Status = GetAdaptersInfo( pAdapterInfo, &dim)) != NO_ERROR) {
|
||||
note("Error %x", Status);
|
||||
free (pAdapterInfo);
|
||||
return;
|
||||
}
|
||||
|
||||
for (pAdapter = pAdapterInfo; pAdapter; pAdapter = pAdapter->Next) {
|
||||
/* we only do ethernet */
|
||||
note("found: %s %x\n", pAdapter->AdapterName, pAdapter->Address);
|
||||
if (pAdapter->Type != MIB_IF_TYPE_ETHERNET) {
|
||||
continue;
|
||||
}
|
||||
note ("found ethernet\n");
|
||||
|
||||
iface->hw_address.hlen = pAdapter->AddressLength;
|
||||
iface->hw_address.htype = HTYPE_ETHER;
|
||||
memcpy (&iface->hw_address.haddr[0],
|
||||
pAdapter->Address, iface->hw_address.hlen);
|
||||
|
||||
if (pAdapter->IpAddressList.IpAddress.String)
|
||||
iface->primary_address.S_un.S_addr = inet_addr(pAdapter->IpAddressList.IpAddress.String);
|
||||
|
||||
}
|
||||
if (iface) {
|
||||
if_register_receive(iface);
|
||||
if_register_send(iface);
|
||||
if( Adapter->DhclientState.state != S_STATIC ) {
|
||||
add_protocol(iface->name, iface->rfdesc, got_one, iface);
|
||||
iface->client->state = S_INIT;
|
||||
state_reboot(iface);
|
||||
}
|
||||
free (pAdapterInfo);
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
reinitialize_interfaces(void)
|
||||
@@ -247,12 +148,16 @@ dispatch(void)
|
||||
}
|
||||
}
|
||||
|
||||
if (i == 0)
|
||||
error("No live interfaces to poll on - exiting.");
|
||||
|
||||
/* Wait for a packet or a timeout... XXX */
|
||||
timeval.tv_sec = to_msec / 1000;
|
||||
timeval.tv_usec = (to_msec % 1000) * 1000;
|
||||
if (i == 0) {
|
||||
/* No interfaces for now, set the select timeout reasonably so
|
||||
* we can recover from that condition later. */
|
||||
timeval.tv_sec = 5;
|
||||
timeval.tv_usec = 0;
|
||||
} else {
|
||||
/* Wait for a packet or a timeout... XXX */
|
||||
timeval.tv_sec = to_msec / 1000;
|
||||
timeval.tv_usec = (to_msec % 1000) * 1000;
|
||||
}
|
||||
|
||||
ApiUnlock();
|
||||
|
||||
@@ -547,6 +452,18 @@ remove_protocol(struct protocol *proto)
|
||||
}
|
||||
}
|
||||
|
||||
struct protocol *
|
||||
find_protocol_by_adapter(struct interface_info *info)
|
||||
{
|
||||
struct protocol *p;
|
||||
|
||||
for( p = protocols; p; p = p->next ) {
|
||||
if( p->local == (void *)info ) return p;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
interface_link_status(char *ifname)
|
||||
{
|
||||
|
||||
@@ -171,7 +171,8 @@ enum dhcp_state {
|
||||
S_REQUESTING,
|
||||
S_BOUND,
|
||||
S_RENEWING,
|
||||
S_REBINDING
|
||||
S_REBINDING,
|
||||
S_STATIC
|
||||
};
|
||||
|
||||
struct client_config {
|
||||
@@ -342,6 +343,7 @@ void add_timeout(time_t, void (*)(void *), void *);
|
||||
void cancel_timeout(void (*)(void *), void *);
|
||||
void add_protocol(char *, int, void (*)(struct protocol *), void *);
|
||||
void remove_protocol(struct protocol *);
|
||||
struct protocol *find_protocol_by_adapter( struct interface_info * );
|
||||
int interface_link_status(char *);
|
||||
|
||||
/* hash.c */
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#define DHCP_PANIC_TIMEOUT DHCP_REBOOT_TIMEOUT * 3
|
||||
#define DHCP_BACKOFF_MAX 300
|
||||
#define _PATH_DHCLIENT_PID "\\systemroot\\system32\\drivers\\etc\\dhclient.pid"
|
||||
|
||||
#define RRF_RT_REG_SZ 2
|
||||
typedef void *VOIDPTR;
|
||||
|
||||
#define NTOS_MODE_USER
|
||||
|
||||
Reference in New Issue
Block a user