ReactOS 0.4.16-dev-1247-g7d8d8a6
api.c File Reference
#include <rosdhcp.h>
#include <reactos/debug.h>
Include dependency graph for api.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID ApiInit ()
 
VOID ApiLock ()
 
VOID ApiUnlock ()
 
VOID ApiFree ()
 
DWORD DSAcquireParams (_In_ PipeSendFunc Send, _In_ HANDLE CommPipe, _Out_ COMM_DHCP_REQ *Req)
 
DWORD DSReleaseParams (_In_ PipeSendFunc Send, _In_ HANDLE CommPipe, _Out_ COMM_DHCP_REQ *Req)
 
DWORD DSLeaseIpAddress (PipeSendFunc Send, HANDLE CommPipe, COMM_DHCP_REQ *Req)
 
DWORD DSQueryHWInfo (PipeSendFunc Send, HANDLE CommPipe, COMM_DHCP_REQ *Req)
 
DWORD DSReleaseIpAddressLease (PipeSendFunc Send, HANDLE CommPipe, COMM_DHCP_REQ *Req)
 
DWORD DSRenewIpAddressLease (PipeSendFunc Send, HANDLE CommPipe, COMM_DHCP_REQ *Req)
 
DWORD DSStaticRefreshParams (PipeSendFunc Send, HANDLE CommPipe, COMM_DHCP_REQ *Req)
 

Variables

static CRITICAL_SECTION ApiCriticalSection
 
HANDLE hAdapterStateChangedEvent
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 11 of file api.c.

Function Documentation

◆ ApiFree()

VOID ApiFree ( )

Definition at line 30 of file api.c.

30 {
32}
static CRITICAL_SECTION ApiCriticalSection
Definition: api.c:14
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)

◆ ApiInit()

VOID ApiInit ( )

Definition at line 18 of file api.c.

18 {
20}
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751

Referenced by init_client().

◆ ApiLock()

◆ ApiUnlock()

◆ DSAcquireParams()

DWORD DSAcquireParams ( _In_ PipeSendFunc  Send,
_In_ HANDLE  CommPipe,
_Out_ COMM_DHCP_REQ Req 
)

Definition at line 37 of file api.c.

41{
42 COMM_DHCP_REPLY Reply;
43 PDHCP_ADAPTER Adapter;
44 struct protocol* proto;
45
46 DPRINT1("DSAcquireParams()\n");
47
48 ApiLock();
49
50 Adapter = AdapterFindName(Req->Body.AcquireParams.AdapterName);
51 DPRINT1("Adapter: %p\n", Adapter);
52
53 if (Adapter == NULL || Adapter->DhclientState.state == S_STATIC)
54 {
55 Reply.Reply = 0;
56 ApiUnlock();
57 return Send(CommPipe, &Reply);
58 }
59
60 Reply.Reply = 1;
61
63 if (proto)
65
66 add_protocol(Adapter->DhclientInfo.name,
67 Adapter->DhclientInfo.rfdesc, got_one,
68 &Adapter->DhclientInfo);
69
70 Adapter->DhclientInfo.client->state = S_INIT;
71 state_reboot(&Adapter->DhclientInfo);
72
75
76 ApiUnlock();
77
78 return Send(CommPipe, &Reply);
79}
#define DPRINT1
Definition: precomp.h:8
PDHCP_ADAPTER AdapterFindName(const CHAR *name)
Definition: adapter.c:512
HANDLE hAdapterStateChangedEvent
Definition: dhcpcsvc.c:20
VOID ApiLock()
Definition: api.c:22
VOID ApiUnlock()
Definition: api.c:26
void add_protocol(char *name, int fd, void(*handler)(struct protocol *), void *local)
Definition: dispatch.c:342
void remove_protocol(struct protocol *proto)
Definition: dispatch.c:359
void got_one(struct protocol *l)
Definition: dispatch.c:194
struct protocol * find_protocol_by_adapter(struct interface_info *info)
Definition: dispatch.c:412
void state_reboot(void *ipp)
Definition: dhclient.c:172
@ S_INIT
Definition: dhcpd.h:172
@ S_STATIC
Definition: dhcpd.h:178
#define NULL
Definition: types.h:112
struct interface_info DhclientInfo
Definition: rosdhcp.h:71
struct client_state DhclientState
Definition: rosdhcp.h:72
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733

Referenced by PipeThreadProc().

◆ DSLeaseIpAddress()

DWORD DSLeaseIpAddress ( PipeSendFunc  Send,
HANDLE  CommPipe,
COMM_DHCP_REQ Req 
)

Definition at line 131 of file api.c.

131 {
132 COMM_DHCP_REPLY Reply;
133 PDHCP_ADAPTER Adapter;
134 struct protocol* proto;
135
136 ApiLock();
137
138 Adapter = AdapterFindIndex( Req->AdapterIndex );
139
140 Reply.Reply = Adapter ? 1 : 0;
141
142 if( Adapter ) {
144 if (proto)
146
147 add_protocol( Adapter->DhclientInfo.name,
148 Adapter->DhclientInfo.rfdesc, got_one,
149 &Adapter->DhclientInfo );
150
151 Adapter->DhclientInfo.client->state = S_INIT;
152 state_reboot(&Adapter->DhclientInfo);
153
156 }
157
158 ApiUnlock();
159
160 return Send(CommPipe, &Reply );
161}
PDHCP_ADAPTER AdapterFindIndex(unsigned int indx)
Definition: adapter.c:498
DWORD AdapterIndex
Definition: rosdhcp_pipe.h:16

Referenced by PipeThreadProc().

◆ DSQueryHWInfo()

DWORD DSQueryHWInfo ( PipeSendFunc  Send,
HANDLE  CommPipe,
COMM_DHCP_REQ Req 
)

Definition at line 163 of file api.c.

163 {
164 COMM_DHCP_REPLY Reply;
165 PDHCP_ADAPTER Adapter;
166
167 ApiLock();
168
169 Adapter = AdapterFindIndex( Req->AdapterIndex );
170
171 Reply.Reply = Adapter ? 1 : 0;
172
173 if (Adapter) {
174 Reply.QueryHWInfo.AdapterIndex = Req->AdapterIndex;
175 Reply.QueryHWInfo.MediaType = Adapter->IfMib.dwType;
176 Reply.QueryHWInfo.Mtu = Adapter->IfMib.dwMtu;
177 Reply.QueryHWInfo.Speed = Adapter->IfMib.dwSpeed;
178 }
179
180 ApiUnlock();
181
182 return Send(CommPipe, &Reply );
183}
MIB_IFROW IfMib
Definition: rosdhcp.h:66
DWORD dwSpeed
Definition: ifmib.h:41
DWORD dwMtu
Definition: ifmib.h:40
DWORD dwType
Definition: ifmib.h:39
struct _COMM_DHCP_REPLY::@52 QueryHWInfo

Referenced by PipeThreadProc().

◆ DSReleaseIpAddressLease()

DWORD DSReleaseIpAddressLease ( PipeSendFunc  Send,
HANDLE  CommPipe,
COMM_DHCP_REQ Req 
)

Definition at line 185 of file api.c.

185 {
186 COMM_DHCP_REPLY Reply;
187 PDHCP_ADAPTER Adapter;
188 struct protocol* proto;
189
190 ApiLock();
191
192 Adapter = AdapterFindIndex( Req->AdapterIndex );
193
194 Reply.Reply = Adapter ? 1 : 0;
195
196 if( Adapter ) {
197 if (Adapter->NteContext)
198 {
199 DeleteIPAddress( Adapter->NteContext );
200 Adapter->NteContext = 0;
201 }
202 if (Adapter->RouterMib.dwForwardNextHop)
203 {
204 DeleteIpForwardEntry( &Adapter->RouterMib );
205 Adapter->RouterMib.dwForwardNextHop = 0;
206 }
207
209 if (proto)
211
212 Adapter->DhclientInfo.client->active = NULL;
213 Adapter->DhclientInfo.client->state = S_INIT;
214
217 }
218
219 ApiUnlock();
220
221 return Send(CommPipe, &Reply );
222}
DWORD WINAPI DeleteIpForwardEntry(PMIB_IPFORWARDROW pRoute)
DWORD WINAPI DeleteIPAddress(ULONG NTEContext)
ULONG NteContext
Definition: rosdhcp.h:70
MIB_IPFORWARDROW RouterMib
Definition: rosdhcp.h:67
DWORD dwForwardNextHop
Definition: ipmib.h:74

Referenced by PipeThreadProc().

◆ DSReleaseParams()

DWORD DSReleaseParams ( _In_ PipeSendFunc  Send,
_In_ HANDLE  CommPipe,
_Out_ COMM_DHCP_REQ Req 
)

Definition at line 83 of file api.c.

87{
88 COMM_DHCP_REPLY Reply;
89 PDHCP_ADAPTER Adapter;
90 struct protocol* proto;
91
92 DPRINT1("DSReleaseParams()\n");
93
94 ApiLock();
95
96 Adapter = AdapterFindName(Req->Body.AcquireParams.AdapterName);
97 DPRINT1("Adapter: %p\n", Adapter);
98
99 Reply.Reply = Adapter ? 1 : 0;
100
101 if (Adapter)
102 {
103 if (Adapter->NteContext)
104 {
105 DeleteIPAddress(Adapter->NteContext);
106 Adapter->NteContext = 0;
107 }
108 if (Adapter->RouterMib.dwForwardNextHop)
109 {
111 Adapter->RouterMib.dwForwardNextHop = 0;
112 }
113
115 if (proto)
117
118 Adapter->DhclientInfo.client->active = NULL;
119 Adapter->DhclientInfo.client->state = S_INIT;
120
123 }
124
125 ApiUnlock();
126
127 return Send(CommPipe, &Reply);
128}

Referenced by PipeThreadProc().

◆ DSRenewIpAddressLease()

DWORD DSRenewIpAddressLease ( PipeSendFunc  Send,
HANDLE  CommPipe,
COMM_DHCP_REQ Req 
)

Definition at line 224 of file api.c.

224 {
225 COMM_DHCP_REPLY Reply;
226 PDHCP_ADAPTER Adapter;
227 struct protocol* proto;
228
229 ApiLock();
230
231 Adapter = AdapterFindIndex( Req->AdapterIndex );
232
233 if( !Adapter || Adapter->DhclientState.state == S_STATIC ) {
234 Reply.Reply = 0;
235 ApiUnlock();
236 return Send(CommPipe, &Reply );
237 }
238
239 Reply.Reply = 1;
240
242 if (proto)
244
245 add_protocol( Adapter->DhclientInfo.name,
246 Adapter->DhclientInfo.rfdesc, got_one,
247 &Adapter->DhclientInfo );
248
249 Adapter->DhclientInfo.client->state = S_INIT;
250 state_reboot(&Adapter->DhclientInfo);
251
254
255 ApiUnlock();
256
257 return Send(CommPipe, &Reply );
258}

Referenced by PipeThreadProc().

◆ DSStaticRefreshParams()

DWORD DSStaticRefreshParams ( PipeSendFunc  Send,
HANDLE  CommPipe,
COMM_DHCP_REQ Req 
)

Definition at line 260 of file api.c.

260 {
262 COMM_DHCP_REPLY Reply;
263 PDHCP_ADAPTER Adapter;
264 struct protocol* proto;
265
266 ApiLock();
267
268 Adapter = AdapterFindIndex( Req->AdapterIndex );
269
270 Reply.Reply = Adapter ? 1 : 0;
271
272 if( Adapter ) {
273 if (Adapter->NteContext)
274 {
275 DeleteIPAddress( Adapter->NteContext );
276 Adapter->NteContext = 0;
277 }
278 if (Adapter->RouterMib.dwForwardNextHop)
279 {
280 DeleteIpForwardEntry( &Adapter->RouterMib );
281 Adapter->RouterMib.dwForwardNextHop = 0;
282 }
283
284 Adapter->DhclientState.state = S_STATIC;
286 if (proto)
289 Req->Body.StaticRefreshParams.Netmask,
290 Req->AdapterIndex,
291 &Adapter->NteContext,
292 &Adapter->NteInstance );
293 Reply.Reply = NT_SUCCESS(Status);
294
297 }
298
299 ApiUnlock();
300
301 return Send(CommPipe, &Reply );
302}
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
Status
Definition: gdiplustypes.h:25
DWORD WINAPI AddIPAddress(IPAddr Address, IPMask Netmask, DWORD IfIndex, PULONG NteContext, PULONG NteInstance)
Definition: iphlpapi_main.c:67
struct _COMM_DHCP_REQ::@46::@51 StaticRefreshParams
union _COMM_DHCP_REQ::@46 Body
ULONG NteInstance
Definition: rosdhcp.h:70

Referenced by PipeThreadProc().

Variable Documentation

◆ ApiCriticalSection

CRITICAL_SECTION ApiCriticalSection
static

Definition at line 14 of file api.c.

Referenced by ApiFree(), ApiInit(), ApiLock(), and ApiUnlock().

◆ hAdapterStateChangedEvent

HANDLE hAdapterStateChangedEvent
extern