ReactOS  0.4.12-dev-43-g63b00d8
adapter.c File Reference
#include <rosdhcp.h>
Include dependency graph for adapter.c:

Go to the source code of this file.

Functions

PCHARGetSubkeyNames (PCHAR MainKeyName, PCHAR Append)
 
PCHAR RegReadString (HKEY Root, PCHAR Subkey, PCHAR Value)
 
HKEY FindAdapterKey (PDHCP_ADAPTER Adapter)
 
BOOL PrepareAdapterForService (PDHCP_ADAPTER Adapter)
 
void AdapterInit ()
 
int InterfaceConnected (const MIB_IFROW *IfEntry)
 
BOOL IsReconnectHackNeeded (PDHCP_ADAPTER Adapter, const MIB_IFROW *IfEntry)
 
DWORD WINAPI AdapterDiscoveryThread (LPVOID Context)
 
HANDLE StartAdapterDiscovery (VOID)
 
void AdapterStop ()
 
PDHCP_ADAPTER AdapterFindIndex (unsigned int indx)
 
PDHCP_ADAPTER AdapterFindName (const WCHAR *name)
 
PDHCP_ADAPTER AdapterFindInfo (struct interface_info *ip)
 
PDHCP_ADAPTER AdapterFindByHardwareAddress (u_int8_t haddr[16], u_int8_t hlen)
 
PDHCP_ADAPTER AdapterGetFirst ()
 
PDHCP_ADAPTER AdapterGetNext (PDHCP_ADAPTER This)
 
void if_register_send (struct interface_info *ip)
 
void if_register_receive (struct interface_info *ip)
 

Variables

SOCKET DhcpSocket = INVALID_SOCKET
 
static LIST_ENTRY AdapterList
 
static WSADATA wsd
 

Function Documentation

◆ AdapterDiscoveryThread()

DWORD WINAPI AdapterDiscoveryThread ( LPVOID  Context)

Definition at line 286 of file adapter.c.

Referenced by StartAdapterDiscovery().

286  {
288  DWORD Error, Size = sizeof(MIB_IFTABLE);
289  PDHCP_ADAPTER Adapter = NULL;
291  struct interface_info *ifi = NULL;
292  struct protocol *proto;
293  int i, AdapterCount = 0, Broadcast;
294 
295  /* FIXME: Kill this thread when the service is stopped */
296 
297  do {
298  DH_DbgPrint(MID_TRACE,("Getting Adapter List...\n"));
299 
300  while( (Error = GetIfTable(Table, &Size, 0 )) ==
302  DH_DbgPrint(MID_TRACE,("Error %d, New Buffer Size: %d\n", Error, Size));
303  free( Table );
304  Table = (PMIB_IFTABLE) malloc( Size );
305  }
306 
307  if( Error != NO_ERROR )
308  {
309  /* HACK: We are waiting until TCP/IP starts */
310  Sleep(2000);
311  continue;
312  }
313 
314  DH_DbgPrint(MID_TRACE,("Got Adapter List (%d entries)\n", Table->dwNumEntries));
315 
316  for( i = Table->dwNumEntries - 1; i >= 0; i-- ) {
317  DH_DbgPrint(MID_TRACE,("Getting adapter %d attributes\n",
318  Table->table[i].dwIndex));
319 
320  ApiLock();
321 
322  if ((Adapter = AdapterFindByHardwareAddress(Table->table[i].bPhysAddr, Table->table[i].dwPhysAddrLen)))
323  {
324  proto = find_protocol_by_adapter(&Adapter->DhclientInfo);
325 
326  /* This is an existing adapter */
327  if (InterfaceConnected(&Table->table[i])) {
328  /* We're still active so we stay in the list */
329  ifi = &Adapter->DhclientInfo;
330 
331  /* This is a hack because IP helper API sucks */
332  if (IsReconnectHackNeeded(Adapter, &Table->table[i]))
333  {
334  /* This handles a disconnect/reconnect */
335 
336  if (proto)
337  remove_protocol(proto);
338  Adapter->DhclientInfo.client->state = S_INIT;
339 
340  /* These are already invalid since the media state change */
341  Adapter->RouterMib.dwForwardNextHop = 0;
342  Adapter->NteContext = 0;
343 
344  add_protocol(Adapter->DhclientInfo.name,
345  Adapter->DhclientInfo.rfdesc,
346  got_one, &Adapter->DhclientInfo);
347  state_init(&Adapter->DhclientInfo);
348 
349  SetEvent(AdapterStateChangedEvent);
350  }
351 
352  } else {
353  if (proto)
354  remove_protocol(proto);
355 
356  /* We've lost our link so out we go */
357  RemoveEntryList(&Adapter->ListEntry);
358  free(Adapter);
359  }
360 
361  ApiUnlock();
362 
363  continue;
364  }
365 
366  ApiUnlock();
367 
368  Adapter = (DHCP_ADAPTER*) calloc( sizeof( DHCP_ADAPTER ) + Table->table[i].dwMtu, 1 );
369 
370  if( Adapter && Table->table[i].dwType == MIB_IF_TYPE_ETHERNET && InterfaceConnected(&Table->table[i])) {
371  memcpy( &Adapter->IfMib, &Table->table[i],
372  sizeof(Adapter->IfMib) );
373  Adapter->DhclientInfo.client = &Adapter->DhclientState;
374  Adapter->DhclientInfo.rbuf = Adapter->recv_buf;
375  Adapter->DhclientInfo.rbuf_max = Table->table[i].dwMtu;
376  Adapter->DhclientInfo.rbuf_len =
377  Adapter->DhclientInfo.rbuf_offset = 0;
378  memcpy(Adapter->DhclientInfo.hw_address.haddr,
379  Adapter->IfMib.bPhysAddr,
380  Adapter->IfMib.dwPhysAddrLen);
381  Adapter->DhclientInfo.hw_address.hlen = Adapter->IfMib.dwPhysAddrLen;
382 
383  /* I'm not sure where else to set this, but
384  some DHCP servers won't take a zero.
385  We checked the hardware type earlier in
386  the if statement. */
387  Adapter->DhclientInfo.hw_address.htype = HTYPE_ETHER;
388 
389  if( DhcpSocket == INVALID_SOCKET ) {
390  DhcpSocket =
391  Adapter->DhclientInfo.rfdesc =
392  Adapter->DhclientInfo.wfdesc =
394 
395  if (DhcpSocket != INVALID_SOCKET) {
396 
397  /* Allow broadcast on this socket */
398  Broadcast = 1;
400  SOL_SOCKET,
401  SO_BROADCAST,
402  (const char *)&Broadcast,
403  sizeof(Broadcast));
404 
405  Adapter->ListenAddr.sin_family = AF_INET;
406  Adapter->ListenAddr.sin_port = htons(LOCAL_PORT);
407  Adapter->BindStatus =
408  (bind( Adapter->DhclientInfo.rfdesc,
409  (struct sockaddr *)&Adapter->ListenAddr,
410  sizeof(Adapter->ListenAddr) ) == 0) ?
411  0 : WSAGetLastError();
412  } else {
413  error("socket() failed: %d\n", WSAGetLastError());
414  }
415  } else {
416  Adapter->DhclientInfo.rfdesc =
417  Adapter->DhclientInfo.wfdesc = DhcpSocket;
418  }
419 
420  Adapter->DhclientConfig.timeout = DHCP_PANIC_TIMEOUT;
421  Adapter->DhclientConfig.initial_interval = DHCP_DISCOVER_INTERVAL;
422  Adapter->DhclientConfig.retry_interval = DHCP_DISCOVER_INTERVAL;
423  Adapter->DhclientConfig.select_interval = 1;
424  Adapter->DhclientConfig.reboot_timeout = DHCP_REBOOT_TIMEOUT;
425  Adapter->DhclientConfig.backoff_cutoff = DHCP_BACKOFF_MAX;
426  Adapter->DhclientState.interval =
427  Adapter->DhclientConfig.retry_interval;
428 
429  if( PrepareAdapterForService( Adapter ) ) {
430  Adapter->DhclientInfo.next = ifi;
431  ifi = &Adapter->DhclientInfo;
432 
433  read_client_conf(&Adapter->DhclientInfo);
434 
435  if (Adapter->DhclientInfo.client->state == S_INIT)
436  {
437  add_protocol(Adapter->DhclientInfo.name,
438  Adapter->DhclientInfo.rfdesc,
439  got_one, &Adapter->DhclientInfo);
440 
441  state_init(&Adapter->DhclientInfo);
442  }
443 
444  ApiLock();
445  InsertTailList( &AdapterList, &Adapter->ListEntry );
446  AdapterCount++;
447  SetEvent(AdapterStateChangedEvent);
448  ApiUnlock();
449  } else { free( Adapter ); Adapter = 0; }
450  } else { free( Adapter ); Adapter = 0; }
451 
452  if( !Adapter )
453  DH_DbgPrint(MID_TRACE,("Adapter %d was rejected\n",
454  Table->table[i].dwIndex));
455  }
456 #if 0
457  Error = NotifyAddrChange(NULL, NULL);
458  if (Error != NO_ERROR)
459  break;
460 #else
461  Sleep(3000);
462 #endif
463  } while (TRUE);
464 
465  DbgPrint("DHCPCSVC: Adapter discovery thread is terminating! (Error: %d)\n", Error);
466 
467  if( Table ) free( Table );
468  return Error;
469 }
unsigned int BindStatus
Definition: rosdhcp.h:75
MIB_IFROW table[1]
Definition: ifmib.h:66
static LIST_ENTRY AdapterList
Definition: adapter.c:4
ASMGENDATA Table[]
Definition: genincdata.c:61
#define TRUE
Definition: types.h:120
MIB_IFROW IfMib
Definition: rosdhcp.h:66
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:736
#define MID_TRACE
Definition: debug.h:15
#define HTYPE_ETHER
Definition: dhcp.h:85
SOCKET WSAAPI socket(IN INT af, IN INT type, IN INT protocol)
Definition: socklife.c:143
#define error(str)
Definition: mkdosfs.c:1605
DWORD dwType
Definition: ifmib.h:39
ULONG NteContext
Definition: rosdhcp.h:70
int read_client_conf(struct interface_info *ifi)
Definition: util.c:106
#define DbgPrint
Definition: loader.c:25
INT WSAAPI bind(IN SOCKET s, IN CONST struct sockaddr *name, IN INT namelen)
Definition: socklife.c:36
#define free
Definition: debug_ros.c:5
Definition: dhcpd.h:172
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:679
void got_one(struct protocol *l)
Definition: dispatch.c:195
#define DHCP_PANIC_TIMEOUT
Definition: rosdhcp.h:28
#define SOL_SOCKET
Definition: winsock.h:398
#define InsertTailList(ListHead, Entry)
#define NO_ERROR
Definition: dderror.h:5
#define DHCP_DISCOVER_INTERVAL
Definition: rosdhcp.h:26
void remove_protocol(struct protocol *proto)
Definition: dispatch.c:360
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
DWORD WINAPI GetIfTable(PMIB_IFTABLE pIfTable, PULONG pdwSize, BOOL bOrder)
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define SO_BROADCAST
Definition: winsock.h:183
INT WSAAPI setsockopt(IN SOCKET s, IN INT level, IN INT optname, IN CONST CHAR FAR *optval, IN INT optlen)
Definition: sockctrl.c:421
smooth NULL
Definition: ftsmooth.c:416
#define DH_DbgPrint(_t_, _x_)
Definition: debug.h:49
#define DHCP_REBOOT_TIMEOUT
Definition: rosdhcp.h:27
MIB_IPFORWARDROW RouterMib
Definition: rosdhcp.h:67
struct client_config DhclientConfig
Definition: rosdhcp.h:73
struct protocol * find_protocol_by_adapter(struct interface_info *info)
Definition: dispatch.c:413
INT WSAAPI WSAGetLastError(VOID)
Definition: dllmain.c:112
DWORD dwForwardNextHop
Definition: ipmib.h:74
#define INVALID_SOCKET
Definition: winsock.h:332
void add_protocol(char *name, int fd, void(*handler)(struct protocol *), void *local)
Definition: dispatch.c:343
UCHAR bPhysAddr[MAXLEN_PHYSADDR]
Definition: ifmib.h:43
SOCKET DhcpSocket
Definition: adapter.c:3
struct _MIB_IFTABLE MIB_IFTABLE
#define MIB_IF_TYPE_ETHERNET
Definition: ipifcons.h:223
PVOID HANDLE
Definition: typedefs.h:71
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL Error
Definition: chkdsk.c:66
int InterfaceConnected(const MIB_IFROW *IfEntry)
Definition: adapter.c:194
struct interface_info DhclientInfo
Definition: rosdhcp.h:71
DWORD dwPhysAddrLen
Definition: ifmib.h:42
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
struct client_state DhclientState
Definition: rosdhcp.h:72
DWORD WINAPI NotifyAddrChange(PHANDLE Handle, LPOVERLAPPED overlapped)
struct _MIB_IFTABLE * PMIB_IFTABLE
PDHCP_ADAPTER AdapterFindByHardwareAddress(u_int8_t haddr[16], u_int8_t hlen)
Definition: adapter.c:555
LIST_ENTRY ListEntry
Definition: rosdhcp.h:65
DWORD dwNumEntries
Definition: ifmib.h:65
#define DHCP_BACKOFF_MAX
Definition: rosdhcp.h:29
#define calloc
Definition: rosglue.h:14
void state_init(void *ipp)
Definition: dhclient.c:218
#define AF_INET
Definition: tcpip.h:117
#define malloc
Definition: debug_ros.c:4
VOID ApiUnlock()
Definition: api.c:26
DWORD dwIndex
Definition: ifmib.h:38
HANDLE AdapterStateChangedEvent
Definition: dispatch.c:51
BOOL PrepareAdapterForService(PDHCP_ADAPTER Adapter)
Definition: adapter.c:148
#define htons(x)
Definition: module.h:213
#define SOCK_DGRAM
Definition: winsock.h:336
DWORD dwMtu
Definition: ifmib.h:40
VOID ApiLock()
Definition: api.c:22
struct sockaddr_in ListenAddr
Definition: rosdhcp.h:74
BOOL IsReconnectHackNeeded(PDHCP_ADAPTER Adapter, const MIB_IFROW *IfEntry)
Definition: adapter.c:205
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
unsigned char recv_buf[1]
Definition: rosdhcp.h:76

◆ AdapterFindByHardwareAddress()

PDHCP_ADAPTER AdapterFindByHardwareAddress ( u_int8_t  haddr[16],
u_int8_t  hlen 
)

Definition at line 555 of file adapter.c.

Referenced by AdapterDiscoveryThread(), and got_one().

555  {
556  PDHCP_ADAPTER Adapter;
557  PLIST_ENTRY ListEntry;
558 
559  for(ListEntry = AdapterList.Flink;
560  ListEntry != &AdapterList;
561  ListEntry = ListEntry->Flink) {
562  Adapter = CONTAINING_RECORD( ListEntry, DHCP_ADAPTER, ListEntry );
563  if (Adapter->DhclientInfo.hw_address.hlen == hlen &&
564  !memcmp(Adapter->DhclientInfo.hw_address.haddr,
565  haddr,
566  hlen)) return Adapter;
567  }
568 
569  return NULL;
570 }
static LIST_ENTRY AdapterList
Definition: adapter.c:4
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
struct interface_info DhclientInfo
Definition: rosdhcp.h:71
Definition: typedefs.h:117

◆ AdapterFindIndex()

PDHCP_ADAPTER AdapterFindIndex ( unsigned int  indx)

Definition at line 513 of file adapter.c.

Referenced by DSGetAdapterInfo(), DSLeaseIpAddress(), DSQueryHWInfo(), DSReleaseIpAddressLease(), DSRenewIpAddressLease(), and DSStaticRefreshParams().

513  {
514  PDHCP_ADAPTER Adapter;
515  PLIST_ENTRY ListEntry;
516 
517  for( ListEntry = AdapterList.Flink;
518  ListEntry != &AdapterList;
519  ListEntry = ListEntry->Flink ) {
520  Adapter = CONTAINING_RECORD( ListEntry, DHCP_ADAPTER, ListEntry );
521  if( Adapter->IfMib.dwIndex == indx ) return Adapter;
522  }
523 
524  return NULL;
525 }
static LIST_ENTRY AdapterList
Definition: adapter.c:4
MIB_IFROW IfMib
Definition: rosdhcp.h:66
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
Definition: typedefs.h:117
DWORD dwIndex
Definition: ifmib.h:38

◆ AdapterFindInfo()

PDHCP_ADAPTER AdapterFindInfo ( struct interface_info ip)

Definition at line 541 of file adapter.c.

Referenced by bind_lease(), got_one(), send_request(), and state_panic().

541  {
542  PDHCP_ADAPTER Adapter;
543  PLIST_ENTRY ListEntry;
544 
545  for( ListEntry = AdapterList.Flink;
546  ListEntry != &AdapterList;
547  ListEntry = ListEntry->Flink ) {
548  Adapter = CONTAINING_RECORD( ListEntry, DHCP_ADAPTER, ListEntry );
549  if( ip == &Adapter->DhclientInfo ) return Adapter;
550  }
551 
552  return NULL;
553 }
static LIST_ENTRY AdapterList
Definition: adapter.c:4
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
struct interface_info DhclientInfo
Definition: rosdhcp.h:71
Definition: typedefs.h:117

◆ AdapterFindName()

PDHCP_ADAPTER AdapterFindName ( const WCHAR name)

Definition at line 527 of file adapter.c.

527  {
528  PDHCP_ADAPTER Adapter;
529  PLIST_ENTRY ListEntry;
530 
531  for( ListEntry = AdapterList.Flink;
532  ListEntry != &AdapterList;
533  ListEntry = ListEntry->Flink ) {
534  Adapter = CONTAINING_RECORD( ListEntry, DHCP_ADAPTER, ListEntry );
535  if( !wcsicmp( Adapter->IfMib.wszName, name ) ) return Adapter;
536  }
537 
538  return NULL;
539 }
static LIST_ENTRY AdapterList
Definition: adapter.c:4
WCHAR wszName[MAX_INTERFACE_NAME_LEN]
Definition: ifmib.h:37
MIB_IFROW IfMib
Definition: rosdhcp.h:66
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
Definition: typedefs.h:117
#define wcsicmp
Definition: string.h:1152
Definition: name.c:36

◆ AdapterGetFirst()

PDHCP_ADAPTER AdapterGetFirst ( )

Definition at line 572 of file adapter.c.

572  {
573  if( IsListEmpty( &AdapterList ) ) return NULL; else {
574  return CONTAINING_RECORD
575  ( AdapterList.Flink, DHCP_ADAPTER, ListEntry );
576  }
577 }
static LIST_ENTRY AdapterList
Definition: adapter.c:4
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119

◆ AdapterGetNext()

PDHCP_ADAPTER AdapterGetNext ( PDHCP_ADAPTER  This)

Definition at line 579 of file adapter.c.

580 {
581  if( This->ListEntry.Flink == &AdapterList ) return NULL;
582  return CONTAINING_RECORD
583  ( This->ListEntry.Flink, DHCP_ADAPTER, ListEntry );
584 }
static LIST_ENTRY AdapterList
Definition: adapter.c:4
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
LIST_ENTRY ListEntry
Definition: rosdhcp.h:65

◆ AdapterInit()

void AdapterInit ( )

Definition at line 187 of file adapter.c.

Referenced by init_client().

187  {
188  WSAStartup(0x0101,&wsd);
189 
191 }
static LIST_ENTRY AdapterList
Definition: adapter.c:4
INT WINAPI WSAStartup(IN WORD wVersionRequested, OUT LPWSADATA lpWSAData)
Definition: startup.c:113
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
static WSADATA wsd
Definition: adapter.c:5

◆ AdapterStop()

void AdapterStop ( )

Definition at line 500 of file adapter.c.

Referenced by init_client().

500  {
501  PLIST_ENTRY ListEntry;
502  PDHCP_ADAPTER Adapter;
503  ApiLock();
504  while( !IsListEmpty( &AdapterList ) ) {
505  ListEntry = (PLIST_ENTRY)RemoveHeadList( &AdapterList );
506  Adapter = CONTAINING_RECORD( ListEntry, DHCP_ADAPTER, ListEntry );
507  free( Adapter );
508  }
509  ApiUnlock();
510  WSACleanup();
511 }
struct _LIST_ENTRY * PLIST_ENTRY
static LIST_ENTRY AdapterList
Definition: adapter.c:4
#define free
Definition: debug_ros.c:5
INT WSAAPI WSACleanup(VOID)
Definition: startup.c:60
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
Definition: typedefs.h:117
VOID ApiUnlock()
Definition: api.c:26
VOID ApiLock()
Definition: api.c:22

◆ FindAdapterKey()

HKEY FindAdapterKey ( PDHCP_ADAPTER  Adapter)

Definition at line 100 of file adapter.c.

Referenced by PrepareAdapterForService().

100  {
101  int i = 0;
102  PCHAR EnumKeyName =
103  "SYSTEM\\CurrentControlSet\\Control\\Class\\"
104  "{4D36E972-E325-11CE-BFC1-08002BE10318}";
105  PCHAR TargetKeyNameStart =
106  "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\";
107  PCHAR TargetKeyName = NULL;
108  PCHAR *EnumKeysLinkage = GetSubkeyNames( EnumKeyName, "\\Linkage" );
109  PCHAR *EnumKeysTop = GetSubkeyNames( EnumKeyName, "" );
110  PCHAR RootDevice = NULL;
111  HKEY EnumKey, OutKey = NULL;
113 
114  if( !EnumKeysLinkage || !EnumKeysTop ) goto cleanup;
115 
116  Error = RegOpenKey( HKEY_LOCAL_MACHINE, EnumKeyName, &EnumKey );
117 
118  if( Error ) goto cleanup;
119 
120  for( i = 0; EnumKeysLinkage[i]; i++ ) {
121  RootDevice = RegReadString
122  ( EnumKey, EnumKeysLinkage[i], "RootDevice" );
123 
124  if( RootDevice &&
125  !strcmp( RootDevice, Adapter->DhclientInfo.name ) ) {
126  TargetKeyName =
127  (CHAR*) malloc( strlen( TargetKeyNameStart ) +
128  strlen( RootDevice ) + 1);
129  if( !TargetKeyName ) goto cleanup;
130  sprintf( TargetKeyName, "%s%s",
131  TargetKeyNameStart, RootDevice );
132  Error = RegCreateKeyExA( HKEY_LOCAL_MACHINE, TargetKeyName, 0, NULL, 0, KEY_READ, NULL, &OutKey, NULL );
133  break;
134  } else {
135  free( RootDevice ); RootDevice = 0;
136  }
137  }
138 
139 cleanup:
140  if( RootDevice ) free( RootDevice );
141  if( EnumKeysLinkage ) free( EnumKeysLinkage );
142  if( EnumKeysTop ) free( EnumKeysTop );
143  if( TargetKeyName ) free( TargetKeyName );
144 
145  return OutKey;
146 }
signed char * PCHAR
Definition: retypes.h:7
#define ERROR_SUCCESS
Definition: deptool.c:10
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define KEY_READ
Definition: nt_native.h:1023
char CHAR
Definition: xmlstorage.h:175
#define free
Definition: debug_ros.c:5
PCHAR RegReadString(HKEY Root, PCHAR Subkey, PCHAR Value)
Definition: adapter.c:56
#define sprintf(buf, format,...)
Definition: sprintf.c:55
GLenum GLclampf GLint i
Definition: glfuncs.h:14
smooth NULL
Definition: ftsmooth.c:416
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL Error
Definition: chkdsk.c:66
PCHAR * GetSubkeyNames(PCHAR MainKeyName, PCHAR Append)
Definition: adapter.c:7
struct interface_info DhclientInfo
Definition: rosdhcp.h:71
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
char * cleanup(char *str)
Definition: wpickclick.c:99
#define malloc
Definition: debug_ros.c:4
LONG WINAPI RegCreateKeyExA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey, _In_ DWORD Reserved, _In_ LPSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_ LPDWORD lpdwDisposition)
Definition: reg.c:1032
#define RegOpenKey
Definition: winreg.h:519
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

◆ GetSubkeyNames()

PCHAR* GetSubkeyNames ( PCHAR  MainKeyName,
PCHAR  Append 
)

Definition at line 7 of file adapter.c.

Referenced by FindAdapterKey().

7  {
8  int i = 0;
9  DWORD Error;
10  HKEY MainKey;
11  PCHAR *Out, OutKeyName;
12  DWORD CharTotal = 0, AppendLen = 1 + strlen(Append);
13  DWORD MaxSubKeyLen = 0, MaxSubKeys = 0;
14 
15  Error = RegOpenKey( HKEY_LOCAL_MACHINE, MainKeyName, &MainKey );
16 
17  if( Error ) return NULL;
18 
19  Error = RegQueryInfoKey
20  ( MainKey,
21  NULL, NULL, NULL,
22  &MaxSubKeys, &MaxSubKeyLen,
23  NULL, NULL, NULL, NULL, NULL, NULL );
24 
25  MaxSubKeyLen++;
26  DH_DbgPrint(MID_TRACE,("MaxSubKeys: %d, MaxSubKeyLen %d\n",
27  MaxSubKeys, MaxSubKeyLen));
28 
29  CharTotal = (sizeof(PCHAR) + MaxSubKeyLen + AppendLen) * (MaxSubKeys + 1);
30 
31  DH_DbgPrint(MID_TRACE,("AppendLen: %d, CharTotal: %d\n",
32  AppendLen, CharTotal));
33 
34  Out = (CHAR**) malloc( CharTotal );
35  OutKeyName = ((PCHAR)&Out[MaxSubKeys+1]);
36 
37  if( !Out ) { RegCloseKey( MainKey ); return NULL; }
38 
39  i = 0;
40  do {
41  Out[i] = OutKeyName;
42  Error = RegEnumKey( MainKey, i, OutKeyName, MaxSubKeyLen );
43  if( !Error ) {
44  strcat( OutKeyName, Append );
45  DH_DbgPrint(MID_TRACE,("[%d]: %s\n", i, OutKeyName));
46  OutKeyName += strlen(OutKeyName) + 1;
47  i++;
48  } else Out[i] = 0;
49  } while( Error == ERROR_SUCCESS );
50 
51  RegCloseKey( MainKey );
52 
53  return Out;
54 }
signed char * PCHAR
Definition: retypes.h:7
#define MID_TRACE
Definition: debug.h:15
#define RegQueryInfoKey
Definition: winreg.h:521
#define ERROR_SUCCESS
Definition: deptool.c:10
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char CHAR
Definition: xmlstorage.h:175
static BOOL Append(LPWSTR *ppszText, DWORD *pdwTextLen, LPCWSTR pszAppendText, DWORD dwAppendLen)
Definition: text.c:25
GLenum GLclampf GLint i
Definition: glfuncs.h:14
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
smooth NULL
Definition: ftsmooth.c:416
#define DH_DbgPrint(_t_, _x_)
Definition: debug.h:49
#define PCHAR
Definition: match.c:90
#define RegEnumKey
Definition: winreg.h:509
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL Error
Definition: chkdsk.c:66
#define malloc
Definition: debug_ros.c:4
#define RegOpenKey
Definition: winreg.h:519
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

◆ if_register_receive()

void if_register_receive ( struct interface_info ip)

Definition at line 590 of file adapter.c.

590  {
591 }

◆ if_register_send()

void if_register_send ( struct interface_info ip)

Definition at line 586 of file adapter.c.

586  {
587 
588 }

◆ InterfaceConnected()

int InterfaceConnected ( const MIB_IFROW IfEntry)

Definition at line 194 of file adapter.c.

Referenced by AdapterDiscoveryThread().

195 {
196  if (IfEntry->dwOperStatus == IF_OPER_STATUS_CONNECTED ||
198  return 1;
199 
200  DH_DbgPrint(MID_TRACE,("Interface %d is down\n", IfEntry->dwIndex));
201  return 0;
202 }
#define MID_TRACE
Definition: debug.h:15
#define DH_DbgPrint(_t_, _x_)
Definition: debug.h:49
DWORD dwIndex
Definition: ifmib.h:38
INTERNAL_IF_OPER_STATUS dwOperStatus
Definition: ifmib.h:45

◆ IsReconnectHackNeeded()

BOOL IsReconnectHackNeeded ( PDHCP_ADAPTER  Adapter,
const MIB_IFROW IfEntry 
)

Definition at line 205 of file adapter.c.

Referenced by AdapterDiscoveryThread().

206 {
207  struct protocol *proto;
208  PIP_ADAPTER_INFO AdapterInfo, Orig;
209  DWORD Size, Ret;
210  char *ZeroAddress = "0.0.0.0";
211 
212  proto = find_protocol_by_adapter(&Adapter->DhclientInfo);
213 
214  if (Adapter->DhclientInfo.client->state == S_BOUND && !proto)
215  return FALSE;
216 
217  if (Adapter->DhclientInfo.client->state != S_BOUND &&
218  Adapter->DhclientInfo.client->state != S_STATIC)
219  return FALSE;
220 
221  ApiUnlock();
222 
223  Orig = AdapterInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(IP_ADAPTER_INFO));
224  Size = sizeof(IP_ADAPTER_INFO);
225  if (!AdapterInfo)
226  {
227  ApiLock();
228  return FALSE;
229  }
230 
231  Ret = GetAdaptersInfo(AdapterInfo, &Size);
232  if (Ret == ERROR_BUFFER_OVERFLOW)
233  {
234  HeapFree(GetProcessHeap(), 0, AdapterInfo);
235  AdapterInfo = HeapAlloc(GetProcessHeap(), 0, Size);
236  if (!AdapterInfo)
237  {
238  ApiLock();
239  return FALSE;
240  }
241 
242  if (GetAdaptersInfo(AdapterInfo, &Size) != NO_ERROR)
243  {
244  ApiLock();
245  return FALSE;
246  }
247 
248  Orig = AdapterInfo;
249  for (; AdapterInfo != NULL; AdapterInfo = AdapterInfo->Next)
250  {
251  if (AdapterInfo->Index == IfEntry->dwIndex)
252  break;
253  }
254 
255  if (AdapterInfo == NULL)
256  {
257  HeapFree(GetProcessHeap(), 0, Orig);
258  ApiLock();
259  return FALSE;
260  }
261  }
262  else if (Ret != NO_ERROR)
263  {
264  HeapFree(GetProcessHeap(), 0, Orig);
265  ApiLock();
266  return FALSE;
267  }
268 
269  if (!strcmp(AdapterInfo->IpAddressList.IpAddress.String, ZeroAddress))
270  {
271  HeapFree(GetProcessHeap(), 0, Orig);
272  ApiLock();
273  return TRUE;
274  }
275  else
276  {
277  HeapFree(GetProcessHeap(), 0, Orig);
278  ApiLock();
279  return FALSE;
280  }
281 }
Definition: dhcpd.h:175
#define TRUE
Definition: types.h:120
#define ERROR_BUFFER_OVERFLOW
Definition: winerror.h:185
IP_ADDRESS_STRING IpAddress
Definition: iptypes.h:47
char String[4 *4]
Definition: iptypes.h:42
#define NO_ERROR
Definition: dderror.h:5
struct _IP_ADAPTER_INFO IP_ADAPTER_INFO
smooth NULL
Definition: ftsmooth.c:416
struct protocol * find_protocol_by_adapter(struct interface_info *info)
Definition: dispatch.c:413
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
unsigned long DWORD
Definition: ntddk_ex.h:95
struct interface_info DhclientInfo
Definition: rosdhcp.h:71
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
DWORD WINAPI GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen)
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
VOID ApiUnlock()
Definition: api.c:26
DWORD dwIndex
Definition: ifmib.h:38
#define HeapFree(x, y, z)
Definition: compat.h:394
struct _IP_ADAPTER_INFO * Next
Definition: iptypes.h:53
VOID ApiLock()
Definition: api.c:22
IP_ADDR_STRING IpAddressList
Definition: iptypes.h:63

◆ PrepareAdapterForService()

BOOL PrepareAdapterForService ( PDHCP_ADAPTER  Adapter)

Definition at line 148 of file adapter.c.

Referenced by AdapterDiscoveryThread().

148  {
149  HKEY AdapterKey;
150  DWORD Error = ERROR_SUCCESS, DhcpEnabled, Length = sizeof(DWORD);
151 
152  Adapter->DhclientState.config = &Adapter->DhclientConfig;
153  strncpy(Adapter->DhclientInfo.name, (char*)Adapter->IfMib.bDescr,
154  sizeof(Adapter->DhclientInfo.name));
155 
156  AdapterKey = FindAdapterKey( Adapter );
157  if( AdapterKey )
158  {
159  Error = RegQueryValueEx(AdapterKey, "EnableDHCP", NULL, NULL, (LPBYTE)&DhcpEnabled, &Length);
160 
161  if (Error != ERROR_SUCCESS || Length != sizeof(DWORD))
162  DhcpEnabled = 1;
163 
164  CloseHandle(AdapterKey);
165  }
166  else
167  {
168  /* DHCP enabled by default */
169  DhcpEnabled = 1;
170  }
171 
172  if( !DhcpEnabled ) {
173  /* Non-automatic case */
174  DbgPrint("DHCPCSVC: Adapter Name: [%s] (static)\n", Adapter->DhclientInfo.name);
175 
176  Adapter->DhclientState.state = S_STATIC;
177  } else {
178  /* Automatic case */
179  DbgPrint("DHCPCSVC: Adapter Name: [%s] (dynamic)\n", Adapter->DhclientInfo.name);
180 
181  Adapter->DhclientInfo.client->state = S_INIT;
182  }
183 
184  return TRUE;
185 }
#define RegQueryValueEx
Definition: winreg.h:524
#define TRUE
Definition: types.h:120
MIB_IFROW IfMib
Definition: rosdhcp.h:66
#define CloseHandle
Definition: compat.h:398
#define ERROR_SUCCESS
Definition: deptool.c:10
#define DbgPrint
Definition: loader.c:25
#define DWORD
Definition: msvc.h:34
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
Definition: dhcpd.h:172
unsigned char * LPBYTE
Definition: typedefs.h:52
smooth NULL
Definition: ftsmooth.c:416
struct client_config DhclientConfig
Definition: rosdhcp.h:73
HKEY FindAdapterKey(PDHCP_ADAPTER Adapter)
Definition: adapter.c:100
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL Error
Definition: chkdsk.c:66
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
BYTE bDescr[MAXLEN_IFDESCR]
Definition: ifmib.h:60
struct interface_info DhclientInfo
Definition: rosdhcp.h:71
struct client_state DhclientState
Definition: rosdhcp.h:72

◆ RegReadString()

PCHAR RegReadString ( HKEY  Root,
PCHAR  Subkey,
PCHAR  Value 
)

Definition at line 56 of file adapter.c.

Referenced by FindAdapterKey().

56  {
57  PCHAR SubOut = NULL;
58  DWORD SubOutLen = 0, Error = 0;
59  HKEY ValueKey = NULL;
60 
61  DH_DbgPrint(MID_TRACE,("Looking in %x:%s:%s\n", Root, Subkey, Value ));
62 
63  if( Subkey && strlen(Subkey) ) {
64  if( RegOpenKey( Root, Subkey, &ValueKey ) != ERROR_SUCCESS )
65  goto regerror;
66  } else ValueKey = Root;
67 
68  DH_DbgPrint(MID_TRACE,("Got Key %x\n", ValueKey));
69 
70  if( (Error = RegQueryValueEx( ValueKey, Value, NULL, NULL,
71  (LPBYTE)SubOut, &SubOutLen )) != ERROR_SUCCESS )
72  goto regerror;
73 
74  DH_DbgPrint(MID_TRACE,("Value %s has size %d\n", Value, SubOutLen));
75 
76  if( !(SubOut = (CHAR*) malloc(SubOutLen)) )
77  goto regerror;
78 
79  if( (Error = RegQueryValueEx( ValueKey, Value, NULL, NULL,
80  (LPBYTE)SubOut, &SubOutLen )) != ERROR_SUCCESS )
81  goto regerror;
82 
83  DH_DbgPrint(MID_TRACE,("Value %s is %s\n", Value, SubOut));
84 
85  goto cleanup;
86 
87 regerror:
88  if( SubOut ) { free( SubOut ); SubOut = NULL; }
89 cleanup:
90  if( ValueKey && ValueKey != Root ) {
91  DH_DbgPrint(MID_TRACE,("Closing key %x\n", ValueKey));
92  RegCloseKey( ValueKey );
93  }
94 
95  DH_DbgPrint(MID_TRACE,("Returning %x with error %d\n", SubOut, Error));
96 
97  return SubOut;
98 }
#define RegQueryValueEx
Definition: winreg.h:524
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2327
signed char * PCHAR
Definition: retypes.h:7
#define MID_TRACE
Definition: debug.h:15
#define ERROR_SUCCESS
Definition: deptool.c:10
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char CHAR
Definition: xmlstorage.h:175
#define free
Definition: debug_ros.c:5
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
smooth NULL
Definition: ftsmooth.c:416
#define DH_DbgPrint(_t_, _x_)
Definition: debug.h:49
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL Error
Definition: chkdsk.c:66
Definition: cmtypes.h:239
char * cleanup(char *str)
Definition: wpickclick.c:99
#define malloc
Definition: debug_ros.c:4
#define RegOpenKey
Definition: winreg.h:519

◆ StartAdapterDiscovery()

HANDLE StartAdapterDiscovery ( VOID  )

Definition at line 471 of file adapter.c.

Referenced by dispatch().

471  {
472  HANDLE ThreadHandle, EventHandle;
473 
474  EventHandle = CreateEvent(NULL,
475  FALSE,
476  FALSE,
477  NULL);
478 
479  if (EventHandle == NULL)
480  return NULL;
481 
482  ThreadHandle = CreateThread(NULL,
483  0,
485  (LPVOID)EventHandle,
486  0,
487  NULL);
488 
489  if (ThreadHandle == NULL)
490  {
491  CloseHandle(EventHandle);
492  return NULL;
493  }
494 
495  CloseHandle(ThreadHandle);
496 
497  return EventHandle;
498 }
#define CreateEvent
Definition: winbase.h:3562
#define CloseHandle
Definition: compat.h:398
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:112
smooth NULL
Definition: ftsmooth.c:416
DWORD WINAPI AdapterDiscoveryThread(LPVOID Context)
Definition: adapter.c:286
_Out_ PHANDLE EventHandle
Definition: iofuncs.h:855

Variable Documentation

◆ AdapterList

LIST_ENTRY AdapterList
static

Definition at line 4 of file adapter.c.

◆ DhcpSocket

SOCKET DhcpSocket = INVALID_SOCKET

Definition at line 3 of file adapter.c.

Referenced by AdapterDiscoveryThread(), and dispatch().

◆ wsd

WSADATA wsd
static

Definition at line 5 of file adapter.c.

Referenced by openlog(), and wmain().