2013-03-16 20:41:13 +00:00
|
|
|
/*
|
2010-05-21 19:30:13 +00:00
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS kernel
|
|
|
|
* FILE: subsys/system/dhcp/api.c
|
|
|
|
* PURPOSE: DHCP client api handlers
|
|
|
|
* PROGRAMMER: arty
|
|
|
|
*/
|
|
|
|
|
2013-01-24 23:00:42 +00:00
|
|
|
#include <rosdhcp.h>
|
2010-05-21 19:30:13 +00:00
|
|
|
|
|
|
|
#define NDEBUG
|
|
|
|
#include <reactos/debug.h>
|
|
|
|
|
|
|
|
static CRITICAL_SECTION ApiCriticalSection;
|
|
|
|
|
2012-01-12 03:12:49 +00:00
|
|
|
extern HANDLE AdapterStateChangedEvent;
|
|
|
|
|
2010-05-21 19:30:13 +00:00
|
|
|
VOID ApiInit() {
|
|
|
|
InitializeCriticalSection( &ApiCriticalSection );
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID ApiLock() {
|
|
|
|
EnterCriticalSection( &ApiCriticalSection );
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID ApiUnlock() {
|
|
|
|
LeaveCriticalSection( &ApiCriticalSection );
|
|
|
|
}
|
|
|
|
|
2010-05-21 20:14:56 +00:00
|
|
|
VOID ApiFree() {
|
|
|
|
DeleteCriticalSection( &ApiCriticalSection );
|
|
|
|
}
|
|
|
|
|
2010-05-21 19:30:13 +00:00
|
|
|
/* This represents the service portion of the DHCP client API */
|
|
|
|
|
|
|
|
DWORD DSLeaseIpAddress( PipeSendFunc Send, COMM_DHCP_REQ *Req ) {
|
|
|
|
COMM_DHCP_REPLY Reply;
|
|
|
|
PDHCP_ADAPTER Adapter;
|
2012-01-12 03:12:49 +00:00
|
|
|
struct protocol* proto;
|
2010-05-21 19:30:13 +00:00
|
|
|
|
|
|
|
ApiLock();
|
|
|
|
|
|
|
|
Adapter = AdapterFindIndex( Req->AdapterIndex );
|
|
|
|
|
|
|
|
Reply.Reply = Adapter ? 1 : 0;
|
|
|
|
|
|
|
|
if( Adapter ) {
|
2012-01-12 03:12:49 +00:00
|
|
|
proto = find_protocol_by_adapter( &Adapter->DhclientInfo );
|
|
|
|
if (proto)
|
|
|
|
remove_protocol(proto);
|
|
|
|
|
2010-05-21 19:30:13 +00:00
|
|
|
add_protocol( Adapter->DhclientInfo.name,
|
|
|
|
Adapter->DhclientInfo.rfdesc, got_one,
|
|
|
|
&Adapter->DhclientInfo );
|
2012-01-12 03:12:49 +00:00
|
|
|
|
|
|
|
Adapter->DhclientInfo.client->state = S_INIT;
|
|
|
|
state_reboot(&Adapter->DhclientInfo);
|
|
|
|
|
|
|
|
if (AdapterStateChangedEvent != NULL)
|
|
|
|
SetEvent(AdapterStateChangedEvent);
|
2010-05-21 19:30:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ApiUnlock();
|
|
|
|
|
|
|
|
return Send( &Reply );
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD DSQueryHWInfo( PipeSendFunc Send, COMM_DHCP_REQ *Req ) {
|
|
|
|
COMM_DHCP_REPLY Reply;
|
|
|
|
PDHCP_ADAPTER Adapter;
|
|
|
|
|
|
|
|
ApiLock();
|
|
|
|
|
|
|
|
Adapter = AdapterFindIndex( Req->AdapterIndex );
|
|
|
|
|
|
|
|
Reply.Reply = Adapter ? 1 : 0;
|
|
|
|
|
|
|
|
if (Adapter) {
|
|
|
|
Reply.QueryHWInfo.AdapterIndex = Req->AdapterIndex;
|
|
|
|
Reply.QueryHWInfo.MediaType = Adapter->IfMib.dwType;
|
|
|
|
Reply.QueryHWInfo.Mtu = Adapter->IfMib.dwMtu;
|
|
|
|
Reply.QueryHWInfo.Speed = Adapter->IfMib.dwSpeed;
|
|
|
|
}
|
|
|
|
|
|
|
|
ApiUnlock();
|
|
|
|
|
|
|
|
return Send( &Reply );
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD DSReleaseIpAddressLease( PipeSendFunc Send, COMM_DHCP_REQ *Req ) {
|
|
|
|
COMM_DHCP_REPLY Reply;
|
|
|
|
PDHCP_ADAPTER Adapter;
|
|
|
|
struct protocol* proto;
|
|
|
|
|
|
|
|
ApiLock();
|
|
|
|
|
|
|
|
Adapter = AdapterFindIndex( Req->AdapterIndex );
|
|
|
|
|
|
|
|
Reply.Reply = Adapter ? 1 : 0;
|
|
|
|
|
|
|
|
if( Adapter ) {
|
|
|
|
if (Adapter->NteContext)
|
- Merge 54929, 54930, 54932, 54933, 54934, 54939, 54941, 54942, 54944, 54945, 54946, and 54947
- The DHCP service now recognizes adapter configuration and media state changes without manual intervention
- Multiple bugs with a static IP configuration are fixed
- IpRenewAddress (ipconfig /renew) and IpReleaseAddress (ipconfig /release) no longer corrupt internal DHCP state
- Routes that cannot currently be resolved by ARP no longer become corrupted by the neighbor timeout
svn path=/trunk/; revision=54966
2012-01-14 19:42:58 +00:00
|
|
|
{
|
2010-05-21 19:30:13 +00:00
|
|
|
DeleteIPAddress( Adapter->NteContext );
|
- Merge 54929, 54930, 54932, 54933, 54934, 54939, 54941, 54942, 54944, 54945, 54946, and 54947
- The DHCP service now recognizes adapter configuration and media state changes without manual intervention
- Multiple bugs with a static IP configuration are fixed
- IpRenewAddress (ipconfig /renew) and IpReleaseAddress (ipconfig /release) no longer corrupt internal DHCP state
- Routes that cannot currently be resolved by ARP no longer become corrupted by the neighbor timeout
svn path=/trunk/; revision=54966
2012-01-14 19:42:58 +00:00
|
|
|
Adapter->NteContext = 0;
|
|
|
|
}
|
2012-01-12 03:12:49 +00:00
|
|
|
if (Adapter->RouterMib.dwForwardNextHop)
|
- Merge 54929, 54930, 54932, 54933, 54934, 54939, 54941, 54942, 54944, 54945, 54946, and 54947
- The DHCP service now recognizes adapter configuration and media state changes without manual intervention
- Multiple bugs with a static IP configuration are fixed
- IpRenewAddress (ipconfig /renew) and IpReleaseAddress (ipconfig /release) no longer corrupt internal DHCP state
- Routes that cannot currently be resolved by ARP no longer become corrupted by the neighbor timeout
svn path=/trunk/; revision=54966
2012-01-14 19:42:58 +00:00
|
|
|
{
|
2012-01-12 03:12:49 +00:00
|
|
|
DeleteIpForwardEntry( &Adapter->RouterMib );
|
- Merge 54929, 54930, 54932, 54933, 54934, 54939, 54941, 54942, 54944, 54945, 54946, and 54947
- The DHCP service now recognizes adapter configuration and media state changes without manual intervention
- Multiple bugs with a static IP configuration are fixed
- IpRenewAddress (ipconfig /renew) and IpReleaseAddress (ipconfig /release) no longer corrupt internal DHCP state
- Routes that cannot currently be resolved by ARP no longer become corrupted by the neighbor timeout
svn path=/trunk/; revision=54966
2012-01-14 19:42:58 +00:00
|
|
|
Adapter->RouterMib.dwForwardNextHop = 0;
|
|
|
|
}
|
2010-05-21 19:30:13 +00:00
|
|
|
|
|
|
|
proto = find_protocol_by_adapter( &Adapter->DhclientInfo );
|
|
|
|
if (proto)
|
|
|
|
remove_protocol(proto);
|
2012-01-12 03:12:49 +00:00
|
|
|
|
|
|
|
Adapter->DhclientInfo.client->active = NULL;
|
|
|
|
Adapter->DhclientInfo.client->state = S_INIT;
|
|
|
|
|
|
|
|
if (AdapterStateChangedEvent != NULL)
|
|
|
|
SetEvent(AdapterStateChangedEvent);
|
2010-05-21 19:30:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ApiUnlock();
|
|
|
|
|
|
|
|
return Send( &Reply );
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD DSRenewIpAddressLease( PipeSendFunc Send, COMM_DHCP_REQ *Req ) {
|
|
|
|
COMM_DHCP_REPLY Reply;
|
|
|
|
PDHCP_ADAPTER Adapter;
|
2012-01-12 03:12:49 +00:00
|
|
|
struct protocol* proto;
|
2010-05-21 19:30:13 +00:00
|
|
|
|
|
|
|
ApiLock();
|
|
|
|
|
|
|
|
Adapter = AdapterFindIndex( Req->AdapterIndex );
|
|
|
|
|
|
|
|
if( !Adapter || Adapter->DhclientState.state == S_STATIC ) {
|
|
|
|
Reply.Reply = 0;
|
|
|
|
ApiUnlock();
|
|
|
|
return Send( &Reply );
|
|
|
|
}
|
|
|
|
|
|
|
|
Reply.Reply = 1;
|
|
|
|
|
2012-01-12 03:12:49 +00:00
|
|
|
proto = find_protocol_by_adapter( &Adapter->DhclientInfo );
|
|
|
|
if (proto)
|
|
|
|
remove_protocol(proto);
|
|
|
|
|
2010-05-21 19:30:13 +00:00
|
|
|
add_protocol( Adapter->DhclientInfo.name,
|
|
|
|
Adapter->DhclientInfo.rfdesc, got_one,
|
|
|
|
&Adapter->DhclientInfo );
|
2012-01-12 03:12:49 +00:00
|
|
|
|
2010-05-21 19:30:13 +00:00
|
|
|
Adapter->DhclientInfo.client->state = S_INIT;
|
|
|
|
state_reboot(&Adapter->DhclientInfo);
|
|
|
|
|
2012-01-12 03:12:49 +00:00
|
|
|
if (AdapterStateChangedEvent != NULL)
|
|
|
|
SetEvent(AdapterStateChangedEvent);
|
|
|
|
|
2010-05-21 19:30:13 +00:00
|
|
|
ApiUnlock();
|
|
|
|
|
|
|
|
return Send( &Reply );
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD DSStaticRefreshParams( PipeSendFunc Send, COMM_DHCP_REQ *Req ) {
|
|
|
|
NTSTATUS Status;
|
|
|
|
COMM_DHCP_REPLY Reply;
|
|
|
|
PDHCP_ADAPTER Adapter;
|
|
|
|
struct protocol* proto;
|
|
|
|
|
|
|
|
ApiLock();
|
|
|
|
|
|
|
|
Adapter = AdapterFindIndex( Req->AdapterIndex );
|
|
|
|
|
|
|
|
Reply.Reply = Adapter ? 1 : 0;
|
|
|
|
|
|
|
|
if( Adapter ) {
|
|
|
|
if (Adapter->NteContext)
|
- Merge 54929, 54930, 54932, 54933, 54934, 54939, 54941, 54942, 54944, 54945, 54946, and 54947
- The DHCP service now recognizes adapter configuration and media state changes without manual intervention
- Multiple bugs with a static IP configuration are fixed
- IpRenewAddress (ipconfig /renew) and IpReleaseAddress (ipconfig /release) no longer corrupt internal DHCP state
- Routes that cannot currently be resolved by ARP no longer become corrupted by the neighbor timeout
svn path=/trunk/; revision=54966
2012-01-14 19:42:58 +00:00
|
|
|
{
|
2010-05-21 19:30:13 +00:00
|
|
|
DeleteIPAddress( Adapter->NteContext );
|
- Merge 54929, 54930, 54932, 54933, 54934, 54939, 54941, 54942, 54944, 54945, 54946, and 54947
- The DHCP service now recognizes adapter configuration and media state changes without manual intervention
- Multiple bugs with a static IP configuration are fixed
- IpRenewAddress (ipconfig /renew) and IpReleaseAddress (ipconfig /release) no longer corrupt internal DHCP state
- Routes that cannot currently be resolved by ARP no longer become corrupted by the neighbor timeout
svn path=/trunk/; revision=54966
2012-01-14 19:42:58 +00:00
|
|
|
Adapter->NteContext = 0;
|
|
|
|
}
|
2012-01-12 03:12:49 +00:00
|
|
|
if (Adapter->RouterMib.dwForwardNextHop)
|
- Merge 54929, 54930, 54932, 54933, 54934, 54939, 54941, 54942, 54944, 54945, 54946, and 54947
- The DHCP service now recognizes adapter configuration and media state changes without manual intervention
- Multiple bugs with a static IP configuration are fixed
- IpRenewAddress (ipconfig /renew) and IpReleaseAddress (ipconfig /release) no longer corrupt internal DHCP state
- Routes that cannot currently be resolved by ARP no longer become corrupted by the neighbor timeout
svn path=/trunk/; revision=54966
2012-01-14 19:42:58 +00:00
|
|
|
{
|
2012-01-12 03:12:49 +00:00
|
|
|
DeleteIpForwardEntry( &Adapter->RouterMib );
|
- Merge 54929, 54930, 54932, 54933, 54934, 54939, 54941, 54942, 54944, 54945, 54946, and 54947
- The DHCP service now recognizes adapter configuration and media state changes without manual intervention
- Multiple bugs with a static IP configuration are fixed
- IpRenewAddress (ipconfig /renew) and IpReleaseAddress (ipconfig /release) no longer corrupt internal DHCP state
- Routes that cannot currently be resolved by ARP no longer become corrupted by the neighbor timeout
svn path=/trunk/; revision=54966
2012-01-14 19:42:58 +00:00
|
|
|
Adapter->RouterMib.dwForwardNextHop = 0;
|
|
|
|
}
|
2012-01-12 03:12:49 +00:00
|
|
|
|
2010-05-21 19:30:13 +00:00
|
|
|
Adapter->DhclientState.state = S_STATIC;
|
|
|
|
proto = find_protocol_by_adapter( &Adapter->DhclientInfo );
|
|
|
|
if (proto)
|
|
|
|
remove_protocol(proto);
|
|
|
|
Status = AddIPAddress( Req->Body.StaticRefreshParams.IPAddress,
|
|
|
|
Req->Body.StaticRefreshParams.Netmask,
|
|
|
|
Req->AdapterIndex,
|
|
|
|
&Adapter->NteContext,
|
|
|
|
&Adapter->NteInstance );
|
|
|
|
Reply.Reply = NT_SUCCESS(Status);
|
2012-01-12 03:12:49 +00:00
|
|
|
|
|
|
|
if (AdapterStateChangedEvent != NULL)
|
|
|
|
SetEvent(AdapterStateChangedEvent);
|
2010-05-21 19:30:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ApiUnlock();
|
|
|
|
|
|
|
|
return Send( &Reply );
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD DSGetAdapterInfo( PipeSendFunc Send, COMM_DHCP_REQ *Req ) {
|
|
|
|
COMM_DHCP_REPLY Reply;
|
|
|
|
PDHCP_ADAPTER Adapter;
|
|
|
|
|
|
|
|
ApiLock();
|
|
|
|
|
|
|
|
Adapter = AdapterFindIndex( Req->AdapterIndex );
|
|
|
|
|
|
|
|
Reply.Reply = Adapter ? 1 : 0;
|
|
|
|
|
|
|
|
if( Adapter ) {
|
|
|
|
Reply.GetAdapterInfo.DhcpEnabled = (S_STATIC != Adapter->DhclientState.state);
|
|
|
|
if (S_BOUND == Adapter->DhclientState.state) {
|
|
|
|
if (sizeof(Reply.GetAdapterInfo.DhcpServer) ==
|
|
|
|
Adapter->DhclientState.active->serveraddress.len) {
|
|
|
|
memcpy(&Reply.GetAdapterInfo.DhcpServer,
|
|
|
|
Adapter->DhclientState.active->serveraddress.iabuf,
|
|
|
|
Adapter->DhclientState.active->serveraddress.len);
|
|
|
|
} else {
|
|
|
|
DPRINT1("Unexpected server address len %d\n",
|
|
|
|
Adapter->DhclientState.active->serveraddress.len);
|
|
|
|
Reply.GetAdapterInfo.DhcpServer = htonl(INADDR_NONE);
|
|
|
|
}
|
|
|
|
Reply.GetAdapterInfo.LeaseObtained = Adapter->DhclientState.active->obtained;
|
|
|
|
Reply.GetAdapterInfo.LeaseExpires = Adapter->DhclientState.active->expiry;
|
|
|
|
} else {
|
|
|
|
Reply.GetAdapterInfo.DhcpServer = htonl(INADDR_NONE);
|
|
|
|
Reply.GetAdapterInfo.LeaseObtained = 0;
|
|
|
|
Reply.GetAdapterInfo.LeaseExpires = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ApiUnlock();
|
|
|
|
|
|
|
|
return Send( &Reply );
|
|
|
|
}
|