ReactOS 0.4.17-dev-573-g8315b8c
dhclient.c
Go to the documentation of this file.
1/* $OpenBSD: dhclient.c,v 1.62 2004/12/05 18:35:51 deraadt Exp $ */
2
3/*
4 * Copyright 2004 Henning Brauer <henning@openbsd.org>
5 * Copyright (c) 1995, 1996, 1997, 1998, 1999
6 * The Internet Software Consortium. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of The Internet Software Consortium nor the names
18 * of its contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND
22 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 * DISCLAIMED. IN NO EVENT SHALL THE INTERNET SOFTWARE CONSORTIUM OR
26 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
29 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 * This software has been written for the Internet Software Consortium
36 * by Ted Lemon <mellon@fugue.com> in cooperation with Vixie
37 * Enterprises. To learn more about the Internet Software Consortium,
38 * see ``http://www.vix.com/isc''. To learn more about Vixie
39 * Enterprises, see ``http://www.vix.com''.
40 *
41 * This client was substantially modified and enhanced by Elliot Poger
42 * for use on Linux while he was working on the MosquitoNet project at
43 * Stanford.
44 *
45 * The current version owes much to Elliot's Linux enhancements, but
46 * was substantially reorganized and partially rewritten by Ted Lemon
47 * so as to use the same networking framework that the Internet Software
48 * Consortium DHCP server uses. Much system-specific configuration code
49 * was moved into a shell script so that as support for more operating
50 * systems is added, it will not be necessary to port and maintain
51 * system-specific configuration code to these operating systems - instead,
52 * the shell script can invoke the native tools to accomplish the same
53 * purpose.
54 */
55
56#include <rosdhcp.h>
57
58#define PERIOD 0x2e
59#define hyphenchar(c) ((c) == 0x2d)
60#define bslashchar(c) ((c) == 0x5c)
61#define periodchar(c) ((c) == PERIOD)
62#define asterchar(c) ((c) == 0x2a)
63#define alphachar(c) (((c) >= 0x41 && (c) <= 0x5a) || \
64 ((c) >= 0x61 && (c) <= 0x7a))
65#define digitchar(c) ((c) >= 0x30 && (c) <= 0x39)
66
67#define borderchar(c) (alphachar(c) || digitchar(c))
68#define middlechar(c) (borderchar(c) || hyphenchar(c))
69#define domainchar(c) ((c) > 0x20 && (c) < 0x7f)
70
71unsigned long debug_trace_level = 0; /* DEBUG_ULTRA */
72
75
76int log_perror = 1;
78//int nullfd = -1;
79
80struct iaddr iaddr_broadcast = { 4, { 255, 255, 255, 255 } };
83
84/*
85 * ASSERT_STATE() does nothing now; it used to be
86 * assert (state_is == state_shouldbe).
87 */
88#define ASSERT_STATE(state_is, state_shouldbe) {}
89
90#define TIME_MAX 2147483647
91
94int unknown_ok = 1;
96
97void usage(void);
98int check_option(struct client_lease *l, int option);
99int ipv4addrs(char * buf);
100int res_hnok(const char *dn);
101char *option_as_string(unsigned int code, unsigned char *data, int len);
102int fork_privchld(int, int);
103int check_arp( struct interface_info *ip, struct client_lease *lp );
104
105#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
106
108
109
110int
112{
113 ApiInit();
114 AdapterInit();
115
116 tzset();
117
119 sockaddr_broadcast.sin_family = AF_INET;
121 sockaddr_broadcast.sin_addr.s_addr = INADDR_BROADCAST;
122 inaddr_any.s_addr = INADDR_ANY;
124
125 return 1; // TRUE
126}
127
128void
130{
131 // AdapterStop();
132 // ApiFree();
133 /* FIXME: Close pipe and kill pipe thread */
134}
135
136/* XXX Implement me */
137int check_arp( struct interface_info *ip, struct client_lease *lp ) {
138 return 1;
139}
140
141/*
142 * Individual States:
143 *
144 * Each routine is called from the dhclient_state_machine() in one of
145 * these conditions:
146 * -> entering INIT state
147 * -> recvpacket_flag == 0: timeout in this state
148 * -> otherwise: received a packet in this state
149 *
150 * Return conditions as handled by dhclient_state_machine():
151 * Returns 1, sendpacket_flag = 1: send packet, reset timer.
152 * Returns 1, sendpacket_flag = 0: just reset the timer (wait for a milestone).
153 * Returns 0: finish the nap which was interrupted for no good reason.
154 *
155 * Several per-interface variables are used to keep track of the process:
156 * active_lease: the lease that is being used on the interface
157 * (null pointer if not configured yet).
158 * offered_leases: leases corresponding to DHCPOFFER messages that have
159 * been sent to us by DHCP servers.
160 * acked_leases: leases corresponding to DHCPACK messages that have been
161 * sent to us by DHCP servers.
162 * sendpacket: DHCP packet we're trying to send.
163 * destination: IP address to send sendpacket to
164 * In addition, there are several relevant per-lease variables.
165 * T1_expiry, T2_expiry, lease_expiry: lease milestones
166 * In the active lease, these control the process of renewing the lease;
167 * In leases on the acked_leases list, this simply determines when we
168 * can no longer legitimately use the lease.
169 */
170
171void
172state_reboot(void *ipp)
173{
174 struct interface_info *ip = ipp;
176
177 /* If we don't remember an active lease, go straight to INIT. */
178 if (!ip->client->active || ip->client->active->is_bootp) {
179 state_init(ip);
180 return;
181 }
182
183 /* We are in the rebooting state. */
184 ip->client->state = S_REBOOTING;
185
186 /* make_request doesn't initialize xid because it normally comes
187 from the DHCPDISCOVER, but we haven't sent a DHCPDISCOVER,
188 so pick an xid now. */
189 ip->client->xid = RtlRandom(&foo);
190
191 /* Make a DHCPREQUEST packet, and set appropriate per-interface
192 flags. */
193 make_request(ip, ip->client->active);
194 ip->client->destination = iaddr_broadcast;
195 time(&ip->client->first_sending);
196 ip->client->interval = ip->client->config->initial_interval;
197
198 /* Zap the medium list... */
199 ip->client->medium = NULL;
200
201 /* Send out the first DHCPREQUEST packet. */
203}
204
205/*
206 * Called when a lease has completely expired and we've
207 * been unable to renew it.
208 */
209void
210state_init(void *ipp)
211{
212 struct interface_info *ip = ipp;
213
215
216 /* Make a DHCPDISCOVER packet, and set appropriate per-interface
217 flags. */
218 make_discover(ip, ip->client->active);
219 ip->client->xid = ip->client->packet.xid;
220 ip->client->destination = iaddr_broadcast;
221 ip->client->state = S_SELECTING;
222 time(&ip->client->first_sending);
223 ip->client->interval = ip->client->config->initial_interval;
224
225 /* Add an immediate timeout to cause the first DHCPDISCOVER packet
226 to go out. */
228}
229
230void
232{
233 struct interface_info *ip = ipp;
235
237
238 /* Make a DHCPRELEASE packet, and set appropriate per-interface
239 flags. */
240 make_release(ip, ip->client->active);
241
242 /* make_request doesn't initialize xid because it normally comes
243 from the DHCPDISCOVER, but we haven't sent a DHCPDISCOVER,
244 so pick an xid now. */
245 ip->client->xid = RtlRandom(&foo);
247
248 ip->client->state = S_RELEASED;
250}
251
252/*
253 * state_selecting is called when one or more DHCPOFFER packets
254 * have been received and a configurable period of time has passed.
255 */
256void
258{
259 struct interface_info *ip = ipp;
260 struct client_lease *lp, *next, *picked;
262
264
265 time(&cur_time);
266
267 /* Cancel state_selecting and send_discover timeouts, since either
268 one could have got us here. */
271
272 /* We have received one or more DHCPOFFER packets. Currently,
273 the only criterion by which we judge leases is whether or
274 not we get a response when we arp for them. */
275 picked = NULL;
276 for (lp = ip->client->offered_leases; lp; lp = next) {
277 next = lp->next;
278
279 /* Check to see if we got an ARPREPLY for the address
280 in this particular lease. */
281 if (!picked) {
282 if( !check_arp(ip,lp) ) goto freeit;
283 picked = lp;
284 picked->next = NULL;
285 } else {
286freeit:
288 }
289 }
290 ip->client->offered_leases = NULL;
291
292 /* If we just tossed all the leases we were offered, go back
293 to square one. */
294 if (!picked) {
295 ip->client->state = S_INIT;
296 state_init(ip);
297 return;
298 }
299
300 /* If it was a BOOTREPLY, we can just take the address right now. */
301 if (!picked->options[DHO_DHCP_MESSAGE_TYPE].len) {
302 ip->client->new = picked;
303
304 /* Make up some lease expiry times
305 XXX these should be configurable. */
306 ip->client->new->expiry = cur_time + 12000;
307 ip->client->new->renewal += cur_time + 8000;
308 ip->client->new->rebind += cur_time + 10000;
309
310 ip->client->state = S_REQUESTING;
311
312 /* Bind to the address we received. */
313 bind_lease(ip);
314 return;
315 }
316
317 /* Go to the REQUESTING state. */
318 ip->client->destination = iaddr_broadcast;
319 ip->client->state = S_REQUESTING;
320 ip->client->first_sending = cur_time;
321 ip->client->interval = ip->client->config->initial_interval;
322
323 /* Make a DHCPREQUEST packet from the lease we picked. */
324 make_request(ip, picked);
325 ip->client->xid = ip->client->packet.xid;
326
327 /* Toss the lease we picked - we'll get it back in a DHCPACK. */
328 free_client_lease(picked);
329
330 /* Add an immediate timeout to send the first DHCPREQUEST packet. */
332}
333
334/* state_requesting is called when we receive a DHCPACK message after
335 having sent out one or more DHCPREQUEST packets. */
336
337void
339{
341 struct client_lease *lease;
343
344 time(&cur_time);
345
346 /* If we're not receptive to an offer right now, or if the offer
347 has an unrecognizable transaction id, then just drop it. */
348 if (packet->interface->client->xid != packet->raw->xid ||
349 (packet->interface->hw_address.hlen != packet->raw->hlen) ||
350 (memcmp(packet->interface->hw_address.haddr,
351 packet->raw->chaddr, packet->raw->hlen)))
352 return;
353
354 if (ip->client->state != S_REBOOTING &&
355 ip->client->state != S_REQUESTING &&
356 ip->client->state != S_RENEWING &&
357 ip->client->state != S_REBINDING)
358 return;
359
360 note("DHCPACK from %s", piaddr(packet->client_addr));
361
362 lease = packet_to_lease(packet);
363 if (!lease) {
364 note("packet_to_lease failed.");
365 return;
366 }
367
368 ip->client->new = lease;
369
370 /* Stop resending DHCPREQUEST. */
372
373 /* Figure out the lease time. */
374 if (ip->client->new->options[DHO_DHCP_LEASE_TIME].data)
375 ip->client->new->expiry = getULong(
376 ip->client->new->options[DHO_DHCP_LEASE_TIME].data);
377 else
378 ip->client->new->expiry = DHCP_DEFAULT_LEASE_TIME;
379 /* A number that looks negative here is really just very large,
380 because the lease expiry offset is unsigned. */
381 if (ip->client->new->expiry < 0)
382 ip->client->new->expiry = TIME_MAX;
383 /* XXX should be fixed by resetting the client state */
384 if (ip->client->new->expiry < 60)
385 ip->client->new->expiry = 60;
386
387 /* Take the server-provided renewal time if there is one;
388 otherwise figure it out according to the spec. */
389 if (ip->client->new->options[DHO_DHCP_RENEWAL_TIME].len)
390 ip->client->new->renewal = getULong(
391 ip->client->new->options[DHO_DHCP_RENEWAL_TIME].data);
392 else
393 ip->client->new->renewal = ip->client->new->expiry / 2;
394
395 /* Same deal with the rebind time. */
396 if (ip->client->new->options[DHO_DHCP_REBINDING_TIME].len)
397 ip->client->new->rebind = getULong(
398 ip->client->new->options[DHO_DHCP_REBINDING_TIME].data);
399 else
400 ip->client->new->rebind = ip->client->new->renewal +
401 ip->client->new->renewal / 2 + ip->client->new->renewal / 4;
402
403#ifdef __REACTOS__
404 ip->client->new->lease = ip->client->new->expiry;
405 ip->client->new->obtained = cur_time;
406#endif
407 ip->client->new->expiry += cur_time;
408 /* Lease lengths can never be negative. */
409 if (ip->client->new->expiry < cur_time)
410 ip->client->new->expiry = TIME_MAX;
411 ip->client->new->renewal += cur_time;
412 if (ip->client->new->renewal < cur_time)
413 ip->client->new->renewal = TIME_MAX;
414 ip->client->new->rebind += cur_time;
415 if (ip->client->new->rebind < cur_time)
416 ip->client->new->rebind = TIME_MAX;
417
418 bind_lease(ip);
419}
420
421void set_name_servers( PDHCP_ADAPTER Adapter, struct client_lease *new_lease ) {
422 CHAR Buffer[200] = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\";
423 HKEY RegKey;
424
425 strcat(Buffer, Adapter->DhclientInfo.name);
427 return;
428
429
430 if( new_lease->options[DHO_DOMAIN_NAME_SERVERS].len ) {
431
432 struct iaddr nameserver;
433 char *nsbuf;
434 int i, addrs =
435 new_lease->options[DHO_DOMAIN_NAME_SERVERS].len / sizeof(ULONG);
436
437 nsbuf = malloc( addrs * sizeof(IP_ADDRESS_STRING) );
438
439 if( nsbuf) {
440 nsbuf[0] = 0;
441 for( i = 0; i < addrs; i++ ) {
442 nameserver.len = sizeof(ULONG);
443 memcpy( nameserver.iabuf,
444 new_lease->options[DHO_DOMAIN_NAME_SERVERS].data +
445 (i * sizeof(ULONG)), sizeof(ULONG) );
446 strcat( nsbuf, piaddr(nameserver) );
447 if( i != addrs-1 ) strcat( nsbuf, "," );
448 }
449
450 DH_DbgPrint(MID_TRACE,("Setting DhcpNameserver: %s\n", nsbuf));
451
452 RegSetValueExA( RegKey, "DhcpNameServer", 0, REG_SZ,
453 (LPBYTE)nsbuf, strlen(nsbuf) + 1 );
454 free( nsbuf );
455 }
456
457 } else {
458 RegDeleteValueW( RegKey, L"DhcpNameServer" );
459 }
460
461 RegCloseKey( RegKey );
462
463}
464
465void
467 PDHCP_ADAPTER Adapter)
468{
469 CHAR Buffer[200] = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\";
470 HKEY RegKey;
471
472 strcat(Buffer, Adapter->DhclientInfo.name);
474 return;
475
476 RegDeleteValueW( RegKey, L"DhcpNameServer" );
477
478 RegCloseKey( RegKey );
479}
480
481
482void
484 struct client_lease *new_lease)
485{
486 CHAR Buffer1[MAX_PATH] = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\";
487 CHAR Buffer2[MAX_PATH] = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters";
488 HKEY RegKey1, RegKey2;
489
490 strcat(Buffer1, Adapter->DhclientInfo.name);
491
492 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, Buffer1, 0, KEY_WRITE, &RegKey1 ) != ERROR_SUCCESS)
493 {
494 return;
495 }
496
497 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, Buffer2, 0, KEY_WRITE, &RegKey2 ) != ERROR_SUCCESS)
498 {
499 RegCloseKey(RegKey1);
500 return;
501 }
502
503 if (new_lease->options[DHO_DOMAIN_NAME].len)
504 {
505 DH_DbgPrint(MID_TRACE, ("Setting DhcpDomain: %s\n", new_lease->options[DHO_DOMAIN_NAME].data));
506
507 RegSetValueExA(RegKey1,
508 "DhcpDomain",
509 0,
510 REG_SZ,
511 (LPBYTE)new_lease->options[DHO_DOMAIN_NAME].data,
512 new_lease->options[DHO_DOMAIN_NAME].len);
513
514 RegSetValueExA(RegKey2,
515 "DhcpDomain",
516 0,
517 REG_SZ,
518 (LPBYTE)new_lease->options[DHO_DOMAIN_NAME].data,
519 new_lease->options[DHO_DOMAIN_NAME].len);
520 }
521 else
522 {
523 RegDeleteValueW(RegKey1, L"DhcpDomain");
524 RegDeleteValueW(RegKey2, L"DhcpDomain");
525 }
526
527 RegCloseKey(RegKey1);
528 RegCloseKey(RegKey2);
529
530}
531
532void
534 PDHCP_ADAPTER Adapter)
535{
536 CHAR Buffer1[MAX_PATH] = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\";
537 CHAR Buffer2[MAX_PATH] = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters";
538 HKEY RegKey1, RegKey2;
539
540 strcat(Buffer1, Adapter->DhclientInfo.name);
541
542 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, Buffer1, 0, KEY_WRITE, &RegKey1 ) != ERROR_SUCCESS)
543 {
544 return;
545 }
546
547 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, Buffer2, 0, KEY_WRITE, &RegKey2 ) != ERROR_SUCCESS)
548 {
549 RegCloseKey(RegKey1);
550 return;
551 }
552
553 RegDeleteValueW(RegKey1, L"DhcpDomain");
554 RegDeleteValueW(RegKey2, L"DhcpDomain");
555
556 RegCloseKey(RegKey1);
557 RegCloseKey(RegKey2);
558}
559
560
561void setup_adapter( PDHCP_ADAPTER Adapter, struct client_lease *new_lease ) {
562 CHAR Buffer[200] = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\";
563 CHAR AddressBuffer[32];
564 struct in_addr addr;
565 HKEY hkey;
566
567 strcat(Buffer, Adapter->DhclientInfo.name);
569 hkey = NULL;
570
571
572 if( Adapter->NteContext )
573 {
574 DeleteIPAddress( Adapter->NteContext );
575 Adapter->NteContext = 0;
576 }
577
578 /* Set up our default router if we got one from the DHCP server */
579 if( new_lease->options[DHO_SUBNET_MASK].len == (int)sizeof(ULONG) ) {
580 DWORD err;
581
583 ( *((ULONG*)new_lease->address.iabuf),
584 *((ULONG*)new_lease->options[DHO_SUBNET_MASK].data),
585 Adapter->IfMib.dwIndex,
586 &Adapter->NteContext,
587 &Adapter->NteInstance );
588 if (hkey && err == NO_ERROR) {
589 RegSetValueExA(hkey, "DhcpIPAddress", 0, REG_SZ, (LPBYTE)piaddr(new_lease->address), strlen(piaddr(new_lease->address))+1);
590 addr.S_un.S_addr = *((ULONG*)new_lease->options[DHO_SUBNET_MASK].data);
591 RtlIpv4AddressToStringA(&addr, AddressBuffer);
592 RegSetValueExA(hkey, "DhcpSubnetMask", 0, REG_SZ, (LPBYTE)AddressBuffer, strlen(AddressBuffer)+1);
593 RegSetValueExA(hkey, "DhcpServer", 0, REG_SZ, (LPBYTE)piaddr(new_lease->serveraddress), strlen(piaddr(new_lease->serveraddress))+1);
594
595 RegSetValueExA(hkey, "Lease", 0, REG_DWORD, (LPBYTE)&new_lease->lease, sizeof(DWORD));
596 RegSetValueExA(hkey, "LeaseObtainedTime", 0, REG_DWORD, (LPBYTE)&new_lease->obtained, sizeof(DWORD));
597 RegSetValueExA(hkey, "LeaseTerminatesTime", 0, REG_DWORD, (LPBYTE)&new_lease->expiry, sizeof(DWORD));
598 RegSetValueExA(hkey, "T1", 0, REG_DWORD, (LPBYTE)&new_lease->renewal, sizeof(DWORD));
599 RegSetValueExA(hkey, "T2", 0, REG_DWORD, (LPBYTE)&new_lease->rebind, sizeof(DWORD));
600 DWORD dwAddressType = 0;
601 RegSetValueExA(hkey, "AddressType", 0, REG_DWORD, (LPBYTE)&dwAddressType, sizeof(DWORD));
602 }
603
604 if( err != NO_ERROR )
605 warning("AddIPAddress: %d\n", err);
606 }
607 else if( new_lease->options[DHO_SUBNET_MASK].len ) {
608 warning("Invalid subnet mask option length: %d\n", new_lease->options[DHO_SUBNET_MASK].len);
609 }
610
611 if( new_lease->options[DHO_ROUTERS].len > (int)0 && new_lease->options[DHO_ROUTERS].len % (int)sizeof(ULONG) == 0 ) {
612 DWORD err;
613
614 Adapter->RouterMib.dwForwardDest = 0; /* Default route */
615 Adapter->RouterMib.dwForwardMask = 0;
616 Adapter->RouterMib.dwForwardMetric1 = 1;
617 Adapter->RouterMib.dwForwardIfIndex = Adapter->IfMib.dwIndex;
618
619 if( Adapter->RouterMib.dwForwardNextHop ) {
620 /* If we set a default route before, delete it before continuing */
621 DeleteIpForwardEntry( &Adapter->RouterMib );
622 }
623
624 Adapter->RouterMib.dwForwardNextHop =
625 *((ULONG*)new_lease->options[DHO_ROUTERS].data);
626
627 err = CreateIpForwardEntry( &Adapter->RouterMib );
628
629 if( err != NO_ERROR )
630 warning("CreateIpForwardEntry: %d\n", err);
631
632 if (hkey && err == NO_ERROR) {
633 addr.S_un.S_addr = *((ULONG*)new_lease->options[DHO_ROUTERS].data);
634 RtlIpv4AddressToStringA(&addr, AddressBuffer);
635 RegSetValueExA(hkey, "DhcpDefaultGateway", 0, REG_SZ, (LPBYTE)AddressBuffer, strlen(AddressBuffer)+1);
636 }
637 }
638 else if( new_lease->options[DHO_ROUTERS].len ) {
639 warning("Invalid routers option length: %d\n", new_lease->options[DHO_ROUTERS].len);
640 }
641
642 if (hkey)
643 RegCloseKey(hkey);
644}
645
646void
648 CHAR Buffer[200] = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\";
649 CHAR IpAddress[] = "0.0.0.0";
650 CHAR SubnetMask[] = "255.0.0.0";
651 CHAR Server[] = "255.255.255.255";
652 HKEY hkey;
653 DWORD lease;
654 time_t cur_time, new_time;
655
656 time(&cur_time);
657
658 strcat(Buffer, Adapter->DhclientInfo.name);
660 hkey = NULL;
661
662 if( Adapter->NteContext )
663 {
664 DeleteIPAddress( Adapter->NteContext );
665 Adapter->NteContext = 0;
666 }
667
668 if (hkey) {
669 RegSetValueExA(hkey, "DhcpIPAddress", 0, REG_SZ, (LPBYTE)IpAddress, strlen(IpAddress)+1);
670 RegSetValueExA(hkey, "DhcpSubnetMask", 0, REG_SZ, (LPBYTE)SubnetMask, strlen(SubnetMask)+1);
671 RegSetValueExA(hkey, "DhcpServer", 0, REG_SZ, (LPBYTE)Server, strlen(Server)+1);
672
673 lease = 3600;
674 RegSetValueExA(hkey, "Lease", 0, REG_DWORD, (LPBYTE)&lease, sizeof(DWORD));
675 RegSetValueExA(hkey, "LeaseObtainedTime", 0, REG_DWORD, (LPBYTE)&cur_time, sizeof(DWORD));
676 new_time = cur_time + lease;
677 RegSetValueExA(hkey, "LeaseTerminatesTime", 0, REG_DWORD, (LPBYTE)&new_time, sizeof(DWORD));
678 new_time = cur_time + (lease / 2);
679 RegSetValueExA(hkey, "T1", 0, REG_DWORD, (LPBYTE)&new_time, sizeof(DWORD));
680 new_time = cur_time + lease - (lease / 8);
681 RegSetValueExA(hkey, "T2", 0, REG_DWORD, (LPBYTE)&new_time, sizeof(DWORD));
682 DWORD dwAddressType = 0;
683 RegSetValueExA(hkey, "AddressType", 0, REG_DWORD, (LPBYTE)&dwAddressType, sizeof(DWORD));
684 }
685
686 if( Adapter->RouterMib.dwForwardNextHop ) {
687 DeleteIpForwardEntry( &Adapter->RouterMib );
688 }
689
690 if (hkey) {
691 RegDeleteValueA(hkey, "DhcpDefaultGateway");
692 }
693
694 if (hkey)
695 RegCloseKey(hkey);
696}
697
698
699void
701{
702 PDHCP_ADAPTER Adapter;
703 struct client_lease *new_lease = ip->client->new;
705
706 time(&cur_time);
707
708 /* Remember the medium. */
709 ip->client->new->medium = ip->client->medium;
710
711 /* Replace the old active lease with the new one. */
712 if (ip->client->active)
713 free_client_lease(ip->client->active);
714 ip->client->active = ip->client->new;
715 ip->client->new = NULL;
716
717 /* Set up a timeout to start the renewal process. */
718 /* Timeout of zero means no timeout (some implementations seem to use
719 * one day).
720 */
721 if( ip->client->active->renewal - cur_time )
722 add_timeout(ip->client->active->renewal, state_bound, ip);
723
724 note("bound to %s -- renewal in %ld seconds.",
725 piaddr(ip->client->active->address),
726 (long int)(ip->client->active->renewal - cur_time));
727
728 ip->client->state = S_BOUND;
729
730 Adapter = AdapterFindInfo( ip );
731
732 if( Adapter ) setup_adapter( Adapter, new_lease );
733 else {
734 warning("Could not find adapter for info %p\n", ip);
735 return;
736 }
737 set_name_servers( Adapter, new_lease );
738 set_domain( Adapter, new_lease );
739}
740
741void
743{
744 PDHCP_ADAPTER Adapter;
745
746 if (ip->client->active) {
747 free_client_lease(ip->client->active);
748 ip->client->active = NULL;
749 }
750
751 Adapter = AdapterFindInfo( ip );
752 if (Adapter) {
753 reset_adapter(Adapter);
754 unset_name_servers(Adapter);
755 unset_domain(Adapter);
756 }
757 else {
758 warning("Could not find adapter for info %p\n", ip);
759 return;
760 }
761}
762
763/*
764 * state_bound is called when we've successfully bound to a particular
765 * lease, but the renewal time on that lease has expired. We are
766 * expected to unicast a DHCPREQUEST to the server that gave us our
767 * original lease.
768 */
769void
770state_bound(void *ipp)
771{
772 struct interface_info *ip = ipp;
773
775
776 /* T1 has expired. */
777 make_request(ip, ip->client->active);
778 ip->client->xid = ip->client->packet.xid;
779
780 if (ip->client->active->options[DHO_DHCP_SERVER_IDENTIFIER].len == 4) {
781 memcpy(ip->client->destination.iabuf, ip->client->active->
783 ip->client->destination.len = 4;
784 } else
785 ip->client->destination = iaddr_broadcast;
786
787 time(&ip->client->first_sending);
788 ip->client->interval = ip->client->config->initial_interval;
789 ip->client->state = S_RENEWING;
790
791 /* Send the first packet immediately. */
793}
794
795void
797{
798 struct iaddrlist *ap;
799
800 if (packet->raw->op != BOOTREPLY)
801 return;
802
803 /* If there's a reject list, make sure this packet's sender isn't
804 on it. */
805 for (ap = packet->interface->client->config->reject_list;
806 ap; ap = ap->next) {
807 if (addr_eq(packet->client_addr, ap->addr)) {
808 note("BOOTREPLY from %s rejected.", piaddr(ap->addr));
809 return;
810 }
811 }
813}
814
815void
817{
818 struct iaddrlist *ap;
819 void (*handler)(struct packet *);
820 char *type;
821
822 switch (packet->packet_type) {
823 case DHCPOFFER:
825 type = "DHCPOFFER";
826 break;
827 case DHCPNAK:
829 type = "DHCPNACK";
830 break;
831 case DHCPACK:
833 type = "DHCPACK";
834 break;
835 default:
836 return;
837 }
838
839 /* If there's a reject list, make sure this packet's sender isn't
840 on it. */
841 for (ap = packet->interface->client->config->reject_list;
842 ap; ap = ap->next) {
843 if (addr_eq(packet->client_addr, ap->addr)) {
844 note("%s from %s rejected.", type, piaddr(ap->addr));
845 return;
846 }
847 }
848 (*handler)(packet);
849}
850
851void
853{
855 struct client_lease *lease, *lp;
856 int i;
857 int arp_timeout_needed = 0;
858 time_t stop_selecting;
860 "DHCPOFFER" : "BOOTREPLY";
862
863 time(&cur_time);
864
865 /* If we're not receptive to an offer right now, or if the offer
866 has an unrecognizable transaction id, then just drop it. */
867 if (ip->client->state != S_SELECTING ||
868 packet->interface->client->xid != packet->raw->xid ||
869 (packet->interface->hw_address.hlen != packet->raw->hlen) ||
870 (memcmp(packet->interface->hw_address.haddr,
871 packet->raw->chaddr, packet->raw->hlen)))
872 return;
873
874 note("%s from %s", name, piaddr(packet->client_addr));
875
876
877 /* If this lease doesn't supply the minimum required parameters,
878 blow it off. */
879 for (i = 0; ip->client->config->required_options[i]; i++) {
880 if (!packet->options[ip->client->config->
881 required_options[i]].len) {
882 note("%s isn't satisfactory.", name);
883 return;
884 }
885 }
886
887 /* If we've already seen this lease, don't record it again. */
888 for (lease = ip->client->offered_leases;
889 lease; lease = lease->next) {
890 if (lease->address.len == sizeof(packet->raw->yiaddr) &&
891 !memcmp(lease->address.iabuf,
892 &packet->raw->yiaddr, lease->address.len)) {
893 debug("%s already seen.", name);
894 return;
895 }
896 }
897
898 lease = packet_to_lease(packet);
899 if (!lease) {
900 note("packet_to_lease failed.");
901 return;
902 }
903
904 /* If this lease was acquired through a BOOTREPLY, record that
905 fact. */
907 lease->is_bootp = 1;
908
909 /* Record the medium under which this lease was offered. */
910 lease->medium = ip->client->medium;
911
912 /* Send out an ARP Request for the offered IP address. */
913 if( !check_arp( ip, lease ) ) {
914 note("Arp check failed\n");
915 return;
916 }
917
918 /* Figure out when we're supposed to stop selecting. */
919 stop_selecting =
920 ip->client->first_sending + ip->client->config->select_interval;
921
922 /* If this is the lease we asked for, put it at the head of the
923 list, and don't mess with the arp request timeout. */
924 if (lease->address.len == ip->client->requested_address.len &&
925 !memcmp(lease->address.iabuf,
926 ip->client->requested_address.iabuf,
927 ip->client->requested_address.len)) {
928 lease->next = ip->client->offered_leases;
929 ip->client->offered_leases = lease;
930 } else {
931 /* If we already have an offer, and arping for this
932 offer would take us past the selection timeout,
933 then don't extend the timeout - just hope for the
934 best. */
935 if (ip->client->offered_leases &&
936 (cur_time + arp_timeout_needed) > stop_selecting)
937 arp_timeout_needed = 0;
938
939 /* Put the lease at the end of the list. */
940 lease->next = NULL;
941 if (!ip->client->offered_leases)
942 ip->client->offered_leases = lease;
943 else {
944 for (lp = ip->client->offered_leases; lp->next;
945 lp = lp->next)
946 ; /* nothing */
947 lp->next = lease;
948 }
949 }
950
951 /* If we're supposed to stop selecting before we've had time
952 to wait for the ARPREPLY, add some delay to wait for
953 the ARPREPLY. */
954 if (stop_selecting - cur_time < arp_timeout_needed)
955 stop_selecting = cur_time + arp_timeout_needed;
956
957 /* If the selecting interval has expired, go immediately to
958 state_selecting(). Otherwise, time out into
959 state_selecting at the select interval. */
960 if (stop_selecting <= 0)
962 else {
963 add_timeout(stop_selecting, state_selecting, ip);
965 }
966}
967
968/* Allocate a client_lease structure and initialize it from the parameters
969 in the specified packet. */
970
971struct client_lease *
973{
974 struct client_lease *lease;
975 int i;
976
977 lease = malloc(sizeof(struct client_lease));
978
979 if (!lease) {
980 warning("dhcpoffer: no memory to record lease.");
981 return (NULL);
982 }
983
984 memset(lease, 0, sizeof(*lease));
985
986 /* Copy the lease options. */
987 for (i = 0; i < 256; i++) {
988 if (packet->options[i].len) {
989 lease->options[i].data =
990 malloc(packet->options[i].len + 1);
991 if (!lease->options[i].data) {
992 warning("dhcpoffer: no memory for option %d", i);
993 free_client_lease(lease);
994 return (NULL);
995 } else {
996 memcpy(lease->options[i].data,
997 packet->options[i].data,
998 packet->options[i].len);
999 lease->options[i].len =
1000 packet->options[i].len;
1001 lease->options[i].data[lease->options[i].len] =
1002 0;
1003 }
1004 if (!check_option(lease,i)) {
1005 /* ignore a bogus lease offer */
1006 warning("Invalid lease option - ignoring offer");
1007 free_client_lease(lease);
1008 return (NULL);
1009 }
1010 }
1011 }
1012
1013 lease->address.len = sizeof(packet->raw->yiaddr);
1014 memcpy(lease->address.iabuf, &packet->raw->yiaddr, lease->address.len);
1015#ifdef __REACTOS__
1016 if (packet->raw->siaddr.S_un.S_addr == 0)
1017 {
1018 lease->serveraddress.len = packet->client_addr.len;
1019 memcpy(lease->serveraddress.iabuf, &packet->client_addr.iabuf, packet->client_addr.len);
1020 }
1021 else
1022 {
1023 lease->serveraddress.len = sizeof(packet->raw->siaddr);
1024 memcpy(lease->serveraddress.iabuf, &packet->raw->siaddr, lease->serveraddress.len);
1025 }
1026#endif
1027
1028 /* If the server name was filled out, copy it. */
1030 !(packet->options[DHO_DHCP_OPTION_OVERLOAD].data[0] & 2)) &&
1031 packet->raw->sname[0]) {
1032 lease->server_name = malloc(DHCP_SNAME_LEN + 1);
1033 if (!lease->server_name) {
1034 warning("dhcpoffer: no memory for server name.");
1035 free_client_lease(lease);
1036 return (NULL);
1037 }
1038 memcpy(lease->server_name, packet->raw->sname, DHCP_SNAME_LEN);
1039 lease->server_name[DHCP_SNAME_LEN]='\0';
1040 if (!res_hnok(lease->server_name) ) {
1041 warning("Bogus server name %s", lease->server_name );
1042 free_client_lease(lease);
1043 return (NULL);
1044 }
1045
1046 }
1047
1048 /* Ditto for the filename. */
1050 !(packet->options[DHO_DHCP_OPTION_OVERLOAD].data[0] & 1)) &&
1051 packet->raw->file[0]) {
1052 /* Don't count on the NUL terminator. */
1053 lease->filename = malloc(DHCP_FILE_LEN + 1);
1054 if (!lease->filename) {
1055 warning("dhcpoffer: no memory for filename.");
1056 free_client_lease(lease);
1057 return (NULL);
1058 }
1059 memcpy(lease->filename, packet->raw->file, DHCP_FILE_LEN);
1060 lease->filename[DHCP_FILE_LEN]='\0';
1061 }
1062 return lease;
1063}
1064
1065void
1067{
1068 struct interface_info *ip = packet->interface;
1069
1070 /* If we're not receptive to an offer right now, or if the offer
1071 has an unrecognizable transaction id, then just drop it. */
1072 if (packet->interface->client->xid != packet->raw->xid ||
1073 (packet->interface->hw_address.hlen != packet->raw->hlen) ||
1074 (memcmp(packet->interface->hw_address.haddr,
1075 packet->raw->chaddr, packet->raw->hlen)))
1076 return;
1077
1078 if (ip->client->state != S_REBOOTING &&
1079 ip->client->state != S_REQUESTING &&
1080 ip->client->state != S_RENEWING &&
1081 ip->client->state != S_REBINDING)
1082 return;
1083
1084 note("DHCPNAK from %s", piaddr(packet->client_addr));
1085
1086 if (!ip->client->active) {
1087 note("DHCPNAK with no active lease.\n");
1088 return;
1089 }
1090
1091 free_client_lease(ip->client->active);
1092 ip->client->active = NULL;
1093
1094 /* Stop sending DHCPREQUEST packets... */
1096
1097 ip->client->state = S_INIT;
1098 state_init(ip);
1099}
1100
1101/* Send out a DHCPDISCOVER packet, and set a timeout to send out another
1102 one after the right interval has expired. If we don't get an offer by
1103 the time we reach the panic interval, call the panic function. */
1104
1105void
1107{
1108 struct interface_info *ip = ipp;
1109 int interval, increase = 1;
1111
1112 DH_DbgPrint(MID_TRACE,("Doing discover on interface %p\n",ip));
1113
1114 time(&cur_time);
1115
1116 /* Figure out how long it's been since we started transmitting. */
1117 interval = cur_time - ip->client->first_sending;
1118
1119 /* If we're past the panic timeout, call the script and tell it
1120 we haven't found anything for this interface yet. */
1121 if (interval > ip->client->config->timeout) {
1122 state_panic(ip);
1123 ip->client->first_sending = cur_time;
1124 }
1125
1126 /* If we're selecting media, try the whole list before doing
1127 the exponential backoff, but if we've already received an
1128 offer, stop looping, because we obviously have it right. */
1129 if (!ip->client->offered_leases &&
1130 ip->client->config->media) {
1131 int fail = 0;
1132
1133 if (ip->client->medium) {
1134 ip->client->medium = ip->client->medium->next;
1135 increase = 0;
1136 }
1137 if (!ip->client->medium) {
1138 if (fail)
1139 error("No valid media types for %s!", ip->name);
1140 ip->client->medium = ip->client->config->media;
1141 increase = 1;
1142 }
1143
1144 note("Trying medium \"%s\" %d", ip->client->medium->string,
1145 increase);
1146 /* XXX Support other media types eventually */
1147 }
1148
1149 /*
1150 * If we're supposed to increase the interval, do so. If it's
1151 * currently zero (i.e., we haven't sent any packets yet), set
1152 * it to one; otherwise, add to it a random number between zero
1153 * and two times itself. On average, this means that it will
1154 * double with every transmission.
1155 */
1156 if (increase) {
1157 if (!ip->client->interval)
1158 ip->client->interval =
1159 ip->client->config->initial_interval;
1160 else {
1161 ip->client->interval += (rand() >> 2) %
1162 (2 * ip->client->interval);
1163 }
1164
1165 /* Don't backoff past cutoff. */
1166 if (ip->client->interval >
1167 ip->client->config->backoff_cutoff)
1168 ip->client->interval =
1169 ((ip->client->config->backoff_cutoff / 2)
1170 + ((rand() >> 2) %
1171 ip->client->config->backoff_cutoff));
1172 } else if (!ip->client->interval)
1173 ip->client->interval =
1174 ip->client->config->initial_interval;
1175
1176 /* If the backoff would take us to the panic timeout, just use that
1177 as the interval. */
1178 if (cur_time + ip->client->interval >
1179 ip->client->first_sending + ip->client->config->timeout)
1180 ip->client->interval =
1181 (ip->client->first_sending +
1182 ip->client->config->timeout) - cur_time + 1;
1183
1184 /* Record the number of seconds since we started sending. */
1185 if (interval < 65536)
1186 ip->client->packet.secs = htons(interval);
1187 else
1188 ip->client->packet.secs = htons(65535);
1189 ip->client->secs = ip->client->packet.secs;
1190
1191 note("DHCPDISCOVER on %s to %s port %d interval %ld",
1192 ip->name, inet_ntoa(sockaddr_broadcast.sin_addr),
1193 ntohs(sockaddr_broadcast.sin_port), (long int)ip->client->interval);
1194
1195 /* Send out a packet. */
1196 (void)send_packet(ip, &ip->client->packet, ip->client->packet_length,
1198
1199 DH_DbgPrint(MID_TRACE,("discover timeout: now %x -> then %x\n",
1200 cur_time, cur_time + ip->client->interval));
1201
1202 add_timeout(cur_time + ip->client->interval, send_discover, ip);
1203}
1204
1205/*
1206 * state_panic gets called if we haven't received any offers in a preset
1207 * amount of time. When this happens, we try to use existing leases
1208 * that haven't yet expired, and failing that, we call the client script
1209 * and hope it can do something.
1210 */
1211void
1212state_panic(void *ipp)
1213{
1214 CHAR szKeyNameBuffer[200] = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\";
1215 CHAR Server[] = "255.255.255.255";
1216 CHAR SubnetMask[] = "255.255.0.0";
1217 CHAR AddressBuffer[32];
1218 struct interface_info *ip = ipp;
1219 uint16_t address_low;
1220 int i;
1221 IPAddr IpAddress;
1222 ULONG Buffer[20];
1224 DWORD ret;
1225 HKEY hKey = NULL;
1226 PDHCP_ADAPTER Adapter = AdapterFindInfo(ip);
1228 DWORD lease = 0;
1229 time_t cur_time, never_time = 0x7FFFFFFF;
1230 struct in_addr addr;
1231 DWORD dwAddressType = 0;
1232
1233 note("No DHCPOFFERS received.");
1234
1235 time(&cur_time);
1236
1237 strcat(szKeyNameBuffer, Adapter->DhclientInfo.name);
1238 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, szKeyNameBuffer, 0, KEY_WRITE, &hKey) != ERROR_SUCCESS)
1239 hKey = NULL;
1240
1241 if (Adapter && !Adapter->NteContext)
1242 {
1243 DH_DbgPrint(MID_TRACE,("DHCPCSVC: Failed to receive a response from a DHCP server\n"));
1244 if ((Adapter->AlternateConfiguration != NULL) &&
1245 (Adapter->AlternateConfiguration->IpAddress != 0))
1246 {
1247 /* Use the alternate configuration */
1248 DH_DbgPrint(MID_TRACE,("DHCPCSVC: The alternate configuration will be used.\n"));
1249
1250 /* IPAddress & SubnetMask */
1253 Adapter->IfMib.dwIndex,
1254 &Adapter->NteContext,
1255 &Adapter->NteInstance);
1256 if (!NT_SUCCESS(Status))
1257 DH_DbgPrint(MID_TRACE,("AddIPAddress: %lx\n", Status));
1258
1259 /* DefaultGateway */
1260 if (Adapter->AlternateConfiguration->DefaultGateway != 0)
1261 {
1262 Adapter->RouterMib.dwForwardDest = 0; /* Default route */
1263 Adapter->RouterMib.dwForwardMask = 0;
1264 Adapter->RouterMib.dwForwardMetric1 = 1;
1265 Adapter->RouterMib.dwForwardIfIndex = Adapter->IfMib.dwIndex;
1266
1267 if (Adapter->RouterMib.dwForwardNextHop)
1268 {
1269 /* If we set a default route before, delete it before continuing */
1271 }
1272
1274
1276 if (!NT_SUCCESS(Status))
1277 DH_DbgPrint(MID_TRACE,("CreateIpForwardEntry: %lx\n", Status));
1278 }
1279
1280 if (hKey)
1281 {
1282 addr.S_un.S_addr = htonl(Adapter->AlternateConfiguration->IpAddress);
1283 RtlIpv4AddressToStringA(&addr, AddressBuffer);
1284 RegSetValueExA(hKey, "DhcpIPAddress", 0, REG_SZ, (LPBYTE)AddressBuffer, strlen(AddressBuffer) + 1);
1285 addr.S_un.S_addr = htonl(Adapter->AlternateConfiguration->SubnetMask);
1286 RtlIpv4AddressToStringA(&addr, AddressBuffer);
1287 RegSetValueExA(hKey, "DhcpSubnetMask", 0, REG_SZ, (LPBYTE)AddressBuffer, strlen(AddressBuffer) + 1);
1288 if (Adapter->AlternateConfiguration->DefaultGateway != 0)
1289 {
1290 addr.S_un.S_addr = htonl(Adapter->AlternateConfiguration->DefaultGateway);
1291 RtlIpv4AddressToStringA(&addr, AddressBuffer);
1292 RegSetValueExA(hKey, "DhcpDefaultGateway", 0, REG_SZ, (LPBYTE)AddressBuffer, strlen(AddressBuffer) + 1);
1293 }
1294 else
1295 {
1296 RegDeleteValueA(hKey, "DhcpDefaultGateway");
1297 }
1298 RegSetValueExA(hKey, "DhcpServer", 0, REG_SZ, (LPBYTE)Server, strlen(Server) + 1);
1299 RegDeleteValueA(hKey, "DhcpDomain");
1300
1301 if (Adapter->AlternateConfiguration->DnsServer1 != 0)
1302 {
1303 char *pPtr;
1304 addr.S_un.S_addr = htonl(Adapter->AlternateConfiguration->DnsServer1);
1305 pPtr = RtlIpv4AddressToStringA(&addr, AddressBuffer);
1306 if (Adapter->AlternateConfiguration->DnsServer2 != 0)
1307 {
1308 *pPtr = ' ';
1309 pPtr++;
1310 addr.S_un.S_addr = htonl(Adapter->AlternateConfiguration->DnsServer2);
1312 }
1313
1314 RegSetValueExA(hKey, "DhcpNameServer", 0, REG_SZ, (LPBYTE)AddressBuffer, strlen(AddressBuffer) + 1);
1315 }
1316 else
1317 {
1318 RegDeleteValueA(hKey, "DhcpNameServer");
1319 }
1320
1321 RegDeleteValueA(hKey, "IPAutoconfigurationAddress");
1322 RegDeleteValueA(hKey, "IPAutoconfigurationMask");
1323
1324 RegSetValueExA(hKey, "Lease", 0, REG_DWORD, (LPBYTE)&lease, sizeof(DWORD));
1325 RegSetValueExA(hKey, "LeaseObtainedTime", 0, REG_DWORD, (LPBYTE)&cur_time, sizeof(DWORD));
1326 RegSetValueExA(hKey, "LeaseTerminatesTime", 0, REG_DWORD, (LPBYTE)&never_time, sizeof(DWORD));
1327 RegSetValueExA(hKey, "T1", 0, REG_DWORD, (LPBYTE)&cur_time, sizeof(DWORD));
1328 RegSetValueExA(hKey, "T2", 0, REG_DWORD, (LPBYTE)&cur_time, sizeof(DWORD));
1329 RegSetValueExA(hKey, "AddressType", 0, REG_DWORD, (LPBYTE)&dwAddressType, sizeof(DWORD));
1330 }
1331 }
1332 else
1333 {
1334 /* Generate an automatic private address */
1335 DH_DbgPrint(MID_TRACE,("DHCPCSVC: An automatic private address will be assigned.\n"));
1336
1337 /* FIXME: The address generation code sucks */
1338 srand(0);
1339
1340 for (;;)
1341 {
1342 address_low = rand();
1343 for (i = 0; i < ip->hw_address.hlen; i++)
1344 address_low += ip->hw_address.haddr[i];
1345
1346 IpAddress = htonl(0xA9FE0000 | address_low); // 169.254.X.X
1347
1348 /* Send an ARP request to check if the IP address is already in use */
1349 BufferSize = sizeof(Buffer);
1350 ret = SendARP(IpAddress,
1351 IpAddress,
1352 Buffer,
1353 &BufferSize);
1354 DH_DbgPrint(MID_TRACE,("DHCPCSVC: SendARP returned %lu\n", ret));
1355 if (ret != 0)
1356 {
1357 /* The IP address is not in use */
1358 DH_DbgPrint(MID_TRACE,("DHCPCSVC: Using automatic private address\n"));
1359 Status = AddIPAddress(IpAddress,
1360 htonl(0xFFFF0000), // 255.255.0.0
1361 Adapter->IfMib.dwIndex,
1362 &Adapter->NteContext,
1363 &Adapter->NteInstance);
1364 if (!NT_SUCCESS(Status))
1365 DH_DbgPrint(MID_TRACE,("AddIPAddress: %lx\n", Status));
1366
1367 if (hKey)
1368 {
1369 addr.S_un.S_addr = IpAddress;
1370 RtlIpv4AddressToStringA(&addr, AddressBuffer);
1371 RegSetValueExA(hKey, "DhcpIPAddress", 0, REG_SZ, (LPBYTE)AddressBuffer, strlen(AddressBuffer) + 1);
1372 RegSetValueExA(hKey, "DhcpSubnetMask", 0, REG_SZ, (LPBYTE)SubnetMask, strlen(SubnetMask) + 1);
1373 RegSetValueExA(hKey, "DhcpServer", 0, REG_SZ, (LPBYTE)Server, strlen(Server) + 1);
1374 RegDeleteValueA(hKey, "DhcpDefaultGateway");
1375 RegDeleteValueA(hKey, "DhcpDomain");
1376 RegDeleteValueA(hKey, "DhcpNameServer");
1377
1378 RegSetValueExA(hKey, "IPAutoconfigurationAddress", 0, REG_SZ, (LPBYTE)AddressBuffer, strlen(AddressBuffer) + 1);
1379 RegSetValueExA(hKey, "IPAutoconfigurationMask", 0, REG_SZ, (LPBYTE)SubnetMask, strlen(SubnetMask) + 1);
1380
1381 RegSetValueExA(hKey, "Lease", 0, REG_DWORD, (LPBYTE)&lease, sizeof(DWORD));
1382 RegSetValueExA(hKey, "LeaseObtainedTime", 0, REG_DWORD, (LPBYTE)&cur_time, sizeof(DWORD));
1383 RegSetValueExA(hKey, "LeaseTerminatesTime", 0, REG_DWORD, (LPBYTE)&never_time, sizeof(DWORD));
1384 RegSetValueExA(hKey, "T1", 0, REG_DWORD, (LPBYTE)&cur_time, sizeof(DWORD));
1385 RegSetValueExA(hKey, "T2", 0, REG_DWORD, (LPBYTE)&cur_time, sizeof(DWORD));
1386 dwAddressType = 1;
1387 RegSetValueExA(hKey, "AddressType", 0, REG_DWORD, (LPBYTE)&dwAddressType, sizeof(DWORD));
1388 }
1389
1390 goto done;
1391 }
1392 }
1393 }
1394 }
1395
1396done:
1397 if (hKey)
1399}
1400
1401void
1403{
1404 struct interface_info *ip = ipp;
1405 struct sockaddr_in destination;
1406 struct in_addr from;
1407 int interval;
1409
1410 time(&cur_time);
1411
1412 /* Figure out how long it's been since we started transmitting. */
1413 interval = cur_time - ip->client->first_sending;
1414
1415 /* If we're in the INIT-REBOOT or REQUESTING state and we're
1416 past the reboot timeout, go to INIT and see if we can
1417 DISCOVER an address... */
1418 /* XXX In the INIT-REBOOT state, if we don't get an ACK, it
1419 means either that we're on a network with no DHCP server,
1420 or that our server is down. In the latter case, assuming
1421 that there is a backup DHCP server, DHCPDISCOVER will get
1422 us a new address, but we could also have successfully
1423 reused our old address. In the former case, we're hosed
1424 anyway. This is not a win-prone situation. */
1425 if ((ip->client->state == S_REBOOTING ||
1426 ip->client->state == S_REQUESTING) &&
1427 interval > ip->client->config->reboot_timeout) {
1428 ip->client->state = S_INIT;
1430 state_init(ip);
1431 return;
1432 }
1433
1434 /* If we're in the reboot state, make sure the media is set up
1435 correctly. */
1436 if (ip->client->state == S_REBOOTING &&
1437 !ip->client->medium &&
1438 ip->client->active->medium ) {
1439 /* If the medium we chose won't fly, go to INIT state. */
1440 /* XXX Nothing for now */
1441
1442 /* Record the medium. */
1443 ip->client->medium = ip->client->active->medium;
1444 }
1445
1446 /* If the lease has expired, relinquish the address and go back
1447 to the INIT state. */
1448 if (ip->client->state != S_REQUESTING &&
1449 cur_time > ip->client->active->expiry) {
1450 PDHCP_ADAPTER Adapter = AdapterFindInfo( ip );
1451 /* Run the client script with the new parameters. */
1452 /* No script actions necessary in the expiry case */
1453 /* Now do a preinit on the interface so that we can
1454 discover a new address. */
1455
1456 if( Adapter )
1457 {
1458 DeleteIPAddress( Adapter->NteContext );
1459 Adapter->NteContext = 0;
1460 }
1461
1462 ip->client->state = S_INIT;
1463 state_init(ip);
1464 return;
1465 }
1466
1467 /* Do the exponential backoff... */
1468 if (!ip->client->interval)
1469 ip->client->interval = ip->client->config->initial_interval;
1470 else
1471 ip->client->interval += ((rand() >> 2) %
1472 (2 * ip->client->interval));
1473
1474 /* Don't backoff past cutoff. */
1475 if (ip->client->interval >
1476 ip->client->config->backoff_cutoff)
1477 ip->client->interval =
1478 ((ip->client->config->backoff_cutoff / 2) +
1479 ((rand() >> 2) % ip->client->interval));
1480
1481 /* If the backoff would take us to the expiry time, just set the
1482 timeout to the expiry time. */
1483 if (ip->client->state != S_REQUESTING &&
1484 cur_time + ip->client->interval >
1485 ip->client->active->expiry)
1486 ip->client->interval =
1487 ip->client->active->expiry - cur_time + 1;
1488
1489 /* If the lease T2 time has elapsed, or if we're not yet bound,
1490 broadcast the DHCPREQUEST rather than unicasting. */
1491 memset(&destination, 0, sizeof(destination));
1492 if (ip->client->state == S_REQUESTING ||
1493 ip->client->state == S_REBOOTING ||
1494 cur_time > ip->client->active->rebind)
1495 destination.sin_addr.s_addr = INADDR_BROADCAST;
1496 else
1497 memcpy(&destination.sin_addr.s_addr,
1498 ip->client->destination.iabuf,
1499 sizeof(destination.sin_addr.s_addr));
1500 destination.sin_port = htons(REMOTE_PORT);
1501 destination.sin_family = AF_INET;
1502// destination.sin_len = sizeof(destination);
1503
1504 if (ip->client->state != S_REQUESTING)
1505 memcpy(&from, ip->client->active->address.iabuf,
1506 sizeof(from));
1507 else
1508 from.s_addr = INADDR_ANY;
1509
1510 /* Record the number of seconds since we started sending. */
1511 if (ip->client->state == S_REQUESTING)
1512 ip->client->packet.secs = ip->client->secs;
1513 else {
1514 if (interval < 65536)
1515 ip->client->packet.secs = htons(interval);
1516 else
1517 ip->client->packet.secs = htons(65535);
1518 }
1519
1520 note("DHCPREQUEST on %s to %s port %d", ip->name,
1521 inet_ntoa(destination.sin_addr), ntohs(destination.sin_port));
1522
1523 /* Send out a packet. */
1524 (void) send_packet(ip, &ip->client->packet, ip->client->packet_length,
1525 from, &destination, NULL);
1526
1527 add_timeout(cur_time + ip->client->interval, send_request, ip);
1528}
1529
1530void
1532{
1533 struct interface_info *ip = ipp;
1534
1535 note("DHCPDECLINE on %s to %s port %d", ip->name,
1536 inet_ntoa(sockaddr_broadcast.sin_addr),
1537 ntohs(sockaddr_broadcast.sin_port));
1538
1539 /* Send out a packet. */
1540 (void) send_packet(ip, &ip->client->packet, ip->client->packet_length,
1542}
1543
1544void
1546{
1547 struct interface_info *ip = ipp;
1548 struct sockaddr_in destination;
1549 struct in_addr from;
1550
1551 memset(&destination, 0, sizeof(destination));
1552 memcpy(&destination.sin_addr.s_addr,
1553 ip->client->destination.iabuf,
1554 sizeof(destination.sin_addr.s_addr));
1555 destination.sin_port = htons(REMOTE_PORT);
1556 destination.sin_family = AF_INET;
1557
1558 memcpy(&from, ip->client->active->address.iabuf,
1559 sizeof(from));
1560
1561 note("DHCPRELEASE on %s to %s port %d", ip->name,
1562 inet_ntoa(destination.sin_addr), ntohs(destination.sin_port));
1563
1564 /* Send out a packet. */
1565 (void) send_packet(ip, &ip->client->packet, ip->client->packet_length,
1566 from, &destination, NULL);
1567}
1568
1569void
1571{
1572 unsigned char discover = DHCPDISCOVER;
1573 struct tree_cache *options[256];
1574 struct tree_cache option_elements[256];
1575 int i;
1577
1578 memset(option_elements, 0, sizeof(option_elements));
1579 memset(options, 0, sizeof(options));
1580 memset(&ip->client->packet, 0, sizeof(ip->client->packet));
1581
1582 /* Set DHCP_MESSAGE_TYPE to DHCPDISCOVER */
1584 options[i] = &option_elements[i];
1585 options[i]->value = &discover;
1586 options[i]->len = sizeof(discover);
1587 options[i]->buf_size = sizeof(discover);
1588 options[i]->timeout = 0xFFFFFFFF;
1589
1590 /* Request the options we want */
1592 options[i] = &option_elements[i];
1593 options[i]->value = ip->client->config->requested_options;
1594 options[i]->len = ip->client->config->requested_option_count;
1595 options[i]->buf_size =
1596 ip->client->config->requested_option_count;
1597 options[i]->timeout = 0xFFFFFFFF;
1598
1599 /* If we had an address, try to get it again. */
1600 if (lease) {
1601 ip->client->requested_address = lease->address;
1603 options[i] = &option_elements[i];
1604 options[i]->value = lease->address.iabuf;
1605 options[i]->len = lease->address.len;
1606 options[i]->buf_size = lease->address.len;
1607 options[i]->timeout = 0xFFFFFFFF;
1608 } else
1609 ip->client->requested_address.len = 0;
1610
1611 /* Send any options requested in the config file. */
1612 for (i = 0; i < 256; i++)
1613 if (!options[i] &&
1614 ip->client->config->send_options[i].data) {
1615 options[i] = &option_elements[i];
1616 options[i]->value =
1617 ip->client->config->send_options[i].data;
1618 options[i]->len =
1619 ip->client->config->send_options[i].len;
1620 options[i]->buf_size =
1621 ip->client->config->send_options[i].len;
1622 options[i]->timeout = 0xFFFFFFFF;
1623 }
1624
1625 /* Set up the option buffer... */
1626 ip->client->packet_length = cons_options(NULL, &ip->client->packet, 0,
1627 options);
1628 if (ip->client->packet_length < BOOTP_MIN_LEN)
1629 ip->client->packet_length = BOOTP_MIN_LEN;
1630
1631 ip->client->packet.op = BOOTREQUEST;
1632 ip->client->packet.htype = ip->hw_address.htype;
1633 ip->client->packet.hlen = ip->hw_address.hlen;
1634 ip->client->packet.hops = 0;
1635 ip->client->packet.xid = RtlRandom(&foo);
1636 ip->client->packet.secs = 0; /* filled in by send_discover. */
1637 ip->client->packet.flags = 0;
1638
1639 memset(&(ip->client->packet.ciaddr),
1640 0, sizeof(ip->client->packet.ciaddr));
1641 memset(&(ip->client->packet.yiaddr),
1642 0, sizeof(ip->client->packet.yiaddr));
1643 memset(&(ip->client->packet.siaddr),
1644 0, sizeof(ip->client->packet.siaddr));
1645 memset(&(ip->client->packet.giaddr),
1646 0, sizeof(ip->client->packet.giaddr));
1647 memcpy(ip->client->packet.chaddr,
1648 ip->hw_address.haddr, ip->hw_address.hlen);
1649}
1650
1651
1652void
1654{
1655 unsigned char request = DHCPREQUEST;
1656 struct tree_cache *options[256];
1657 struct tree_cache option_elements[256];
1658 int i;
1659
1660 memset(options, 0, sizeof(options));
1661 memset(&ip->client->packet, 0, sizeof(ip->client->packet));
1662
1663 /* Set DHCP_MESSAGE_TYPE to DHCPREQUEST */
1665 options[i] = &option_elements[i];
1666 options[i]->value = &request;
1667 options[i]->len = sizeof(request);
1668 options[i]->buf_size = sizeof(request);
1669 options[i]->timeout = 0xFFFFFFFF;
1670
1671 /* Request the options we want */
1673 options[i] = &option_elements[i];
1674 options[i]->value = ip->client->config->requested_options;
1675 options[i]->len = ip->client->config->requested_option_count;
1676 options[i]->buf_size =
1677 ip->client->config->requested_option_count;
1678 options[i]->timeout = 0xFFFFFFFF;
1679
1680 /* If we are requesting an address that hasn't yet been assigned
1681 to us, use the DHCP Requested Address option. */
1682 if (ip->client->state == S_REQUESTING) {
1683 /* Send back the server identifier... */
1685 options[i] = &option_elements[i];
1686 options[i]->value = lease->options[i].data;
1687 options[i]->len = lease->options[i].len;
1688 options[i]->buf_size = lease->options[i].len;
1689 options[i]->timeout = 0xFFFFFFFF;
1690 }
1691 if (ip->client->state == S_REQUESTING ||
1692 ip->client->state == S_REBOOTING) {
1693 ip->client->requested_address = lease->address;
1695 options[i] = &option_elements[i];
1696 options[i]->value = lease->address.iabuf;
1697 options[i]->len = lease->address.len;
1698 options[i]->buf_size = lease->address.len;
1699 options[i]->timeout = 0xFFFFFFFF;
1700 } else
1701 ip->client->requested_address.len = 0;
1702
1703 /* Send any options requested in the config file. */
1704 for (i = 0; i < 256; i++)
1705 if (!options[i] &&
1706 ip->client->config->send_options[i].data) {
1707 options[i] = &option_elements[i];
1708 options[i]->value =
1709 ip->client->config->send_options[i].data;
1710 options[i]->len =
1711 ip->client->config->send_options[i].len;
1712 options[i]->buf_size =
1713 ip->client->config->send_options[i].len;
1714 options[i]->timeout = 0xFFFFFFFF;
1715 }
1716
1717 /* Set up the option buffer... */
1718 ip->client->packet_length = cons_options(NULL, &ip->client->packet, 0,
1719 options);
1720 if (ip->client->packet_length < BOOTP_MIN_LEN)
1721 ip->client->packet_length = BOOTP_MIN_LEN;
1722
1723 ip->client->packet.op = BOOTREQUEST;
1724 ip->client->packet.htype = ip->hw_address.htype;
1725 ip->client->packet.hlen = ip->hw_address.hlen;
1726 ip->client->packet.hops = 0;
1727 ip->client->packet.xid = ip->client->xid;
1728 ip->client->packet.secs = 0; /* Filled in by send_request. */
1729
1730 /* If we own the address we're requesting, put it in ciaddr;
1731 otherwise set ciaddr to zero. */
1732 if (ip->client->state == S_BOUND ||
1733 ip->client->state == S_RENEWING ||
1734 ip->client->state == S_REBINDING) {
1735 memcpy(&ip->client->packet.ciaddr,
1736 lease->address.iabuf, lease->address.len);
1737 ip->client->packet.flags = 0;
1738 } else {
1739 memset(&ip->client->packet.ciaddr, 0,
1740 sizeof(ip->client->packet.ciaddr));
1741 ip->client->packet.flags = 0;
1742 }
1743
1744 memset(&ip->client->packet.yiaddr, 0,
1745 sizeof(ip->client->packet.yiaddr));
1746 memset(&ip->client->packet.siaddr, 0,
1747 sizeof(ip->client->packet.siaddr));
1748 memset(&ip->client->packet.giaddr, 0,
1749 sizeof(ip->client->packet.giaddr));
1750 memcpy(ip->client->packet.chaddr,
1751 ip->hw_address.haddr, ip->hw_address.hlen);
1752}
1753
1754void
1756{
1757 struct tree_cache *options[256], message_type_tree;
1758 struct tree_cache requested_address_tree;
1759 struct tree_cache server_id_tree, client_id_tree;
1760 unsigned char decline = DHCPDECLINE;
1761 int i;
1762
1763 memset(options, 0, sizeof(options));
1764 memset(&ip->client->packet, 0, sizeof(ip->client->packet));
1765
1766 /* Set DHCP_MESSAGE_TYPE to DHCPDECLINE */
1768 options[i] = &message_type_tree;
1769 options[i]->value = &decline;
1770 options[i]->len = sizeof(decline);
1771 options[i]->buf_size = sizeof(decline);
1772 options[i]->timeout = 0xFFFFFFFF;
1773
1774 /* Send back the server identifier... */
1776 options[i] = &server_id_tree;
1777 options[i]->value = lease->options[i].data;
1778 options[i]->len = lease->options[i].len;
1779 options[i]->buf_size = lease->options[i].len;
1780 options[i]->timeout = 0xFFFFFFFF;
1781
1782 /* Send back the address we're declining. */
1784 options[i] = &requested_address_tree;
1785 options[i]->value = lease->address.iabuf;
1786 options[i]->len = lease->address.len;
1787 options[i]->buf_size = lease->address.len;
1788 options[i]->timeout = 0xFFFFFFFF;
1789
1790 /* Send the uid if the user supplied one. */
1792 if (ip->client->config->send_options[i].len) {
1793 options[i] = &client_id_tree;
1794 options[i]->value = ip->client->config->send_options[i].data;
1795 options[i]->len = ip->client->config->send_options[i].len;
1796 options[i]->buf_size = ip->client->config->send_options[i].len;
1797 options[i]->timeout = 0xFFFFFFFF;
1798 }
1799
1800
1801 /* Set up the option buffer... */
1802 ip->client->packet_length = cons_options(NULL, &ip->client->packet, 0,
1803 options);
1804 if (ip->client->packet_length < BOOTP_MIN_LEN)
1805 ip->client->packet_length = BOOTP_MIN_LEN;
1806
1807 ip->client->packet.op = BOOTREQUEST;
1808 ip->client->packet.htype = ip->hw_address.htype;
1809 ip->client->packet.hlen = ip->hw_address.hlen;
1810 ip->client->packet.hops = 0;
1811 ip->client->packet.xid = ip->client->xid;
1812 ip->client->packet.secs = 0; /* Filled in by send_request. */
1813 ip->client->packet.flags = 0;
1814
1815 /* ciaddr must always be zero. */
1816 memset(&ip->client->packet.ciaddr, 0,
1817 sizeof(ip->client->packet.ciaddr));
1818 memset(&ip->client->packet.yiaddr, 0,
1819 sizeof(ip->client->packet.yiaddr));
1820 memset(&ip->client->packet.siaddr, 0,
1821 sizeof(ip->client->packet.siaddr));
1822 memset(&ip->client->packet.giaddr, 0,
1823 sizeof(ip->client->packet.giaddr));
1824 memcpy(ip->client->packet.chaddr,
1825 ip->hw_address.haddr, ip->hw_address.hlen);
1826}
1827
1828void
1830{
1831 struct tree_cache *options[256], message_type_tree;
1832 struct tree_cache server_id_tree, client_id_tree;
1833 unsigned char release = DHCPRELEASE;
1834 int i;
1835
1836 memset(options, 0, sizeof(options));
1837 memset(&ip->client->packet, 0, sizeof(ip->client->packet));
1838
1839 /* Set DHCP_MESSAGE_TYPE to DHCPRELEASE */
1841 options[i] = &message_type_tree;
1842 options[i]->value = &release;
1843 options[i]->len = sizeof(release);
1844 options[i]->buf_size = sizeof(release);
1845 options[i]->timeout = 0xFFFFFFFF;
1846
1847 /* Send back the server identifier... */
1849 options[i] = &server_id_tree;
1850 options[i]->value = lease->options[i].data;
1851 options[i]->len = lease->options[i].len;
1852 options[i]->buf_size = lease->options[i].len;
1853 options[i]->timeout = 0xFFFFFFFF;
1854
1855 /* Send the uid if the user supplied one. */
1857 if (ip->client->config->send_options[i].len)
1858 {
1859 options[i] = &client_id_tree;
1860 options[i]->value = ip->client->config->send_options[i].data;
1861 options[i]->len = ip->client->config->send_options[i].len;
1862 options[i]->buf_size = ip->client->config->send_options[i].len;
1863 options[i]->timeout = 0xFFFFFFFF;
1864 }
1865
1866 /* Set up the option buffer... */
1867 ip->client->packet_length = cons_options(NULL, &ip->client->packet, 0, options);
1868 if (ip->client->packet_length < BOOTP_MIN_LEN)
1869 ip->client->packet_length = BOOTP_MIN_LEN;
1870
1871 ip->client->packet.op = BOOTREQUEST;
1872 ip->client->packet.htype = ip->hw_address.htype;
1873 ip->client->packet.hlen = ip->hw_address.hlen;
1874 ip->client->packet.hops = 0;
1875 ip->client->packet.xid = 0;
1876 ip->client->packet.secs = 0;
1877 ip->client->packet.flags = 0;
1878
1879 /* ciaddr is the address to be released */
1880 memcpy(&ip->client->packet.ciaddr,
1881 lease->address.iabuf, lease->address.len);
1882 memset(&ip->client->packet.yiaddr, 0,
1883 sizeof(ip->client->packet.yiaddr));
1884 memset(&ip->client->packet.siaddr, 0,
1885 sizeof(ip->client->packet.siaddr));
1886 memset(&ip->client->packet.giaddr, 0,
1887 sizeof(ip->client->packet.giaddr));
1888 memcpy(ip->client->packet.chaddr,
1889 ip->hw_address.haddr, ip->hw_address.hlen);
1890}
1891
1892void
1894{
1895 int i;
1896
1897 if (lease->server_name)
1898 free(lease->server_name);
1899 if (lease->filename)
1900 free(lease->filename);
1901 for (i = 0; i < 256; i++) {
1902 if (lease->options[i].len)
1903 free(lease->options[i].data);
1904 }
1905 free(lease);
1906}
1907
1909
1910void
1912{
1913 struct client_lease *lp;
1914
1915 if (!leaseFile) {
1917 if (!leaseFile)
1918 error("can't create %s", path_dhclient_db);
1919 } else {
1922 }
1923
1924 for (lp = ifi->client->leases; lp; lp = lp->next)
1925 write_client_lease(ifi, lp, 1);
1926 if (ifi->client->active)
1927 write_client_lease(ifi, ifi->client->active, 1);
1928
1930}
1931
1932void
1934 int rewrite)
1935{
1936 static int leases_written;
1937 struct tm *t;
1938 int i;
1939
1940 if (!rewrite) {
1941 if (leases_written++ > 20) {
1943 leases_written = 0;
1944 }
1945 }
1946
1947 /* If the lease came from the config file, we don't need to stash
1948 a copy in the lease database. */
1949 if (lease->is_static)
1950 return;
1951
1952 if (!leaseFile) { /* XXX */
1954 if (!leaseFile) {
1955 error("can't create %s", path_dhclient_db);
1956 return;
1957 }
1958 }
1959
1960 fprintf(leaseFile, "lease {\n");
1961 if (lease->is_bootp)
1962 fprintf(leaseFile, " bootp;\n");
1963 fprintf(leaseFile, " interface \"%s\";\n", ip->name);
1964 fprintf(leaseFile, " fixed-address %s;\n", piaddr(lease->address));
1965 if (lease->filename)
1966 fprintf(leaseFile, " filename \"%s\";\n", lease->filename);
1967 if (lease->server_name)
1968 fprintf(leaseFile, " server-name \"%s\";\n",
1969 lease->server_name);
1970 if (lease->medium)
1971 fprintf(leaseFile, " medium \"%s\";\n", lease->medium->string);
1972 for (i = 0; i < 256; i++)
1973 if (lease->options[i].len)
1974 fprintf(leaseFile, " option %s %s;\n",
1976 pretty_print_option(i, lease->options[i].data,
1977 lease->options[i].len, 1, 1));
1978
1979 t = gmtime(&lease->renewal);
1980 if (t)
1981 fprintf(leaseFile, " renew %d %d/%d/%d %02d:%02d:%02d;\n",
1982 t->tm_wday, t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
1983 t->tm_hour, t->tm_min, t->tm_sec);
1984 t = gmtime(&lease->rebind);
1985 if (t)
1986 fprintf(leaseFile, " rebind %d %d/%d/%d %02d:%02d:%02d;\n",
1987 t->tm_wday, t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
1988 t->tm_hour, t->tm_min, t->tm_sec);
1989 t = gmtime(&lease->expiry);
1990 if (t)
1991 fprintf(leaseFile, " expire %d %d/%d/%d %02d:%02d:%02d;\n",
1992 t->tm_wday, t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
1993 t->tm_hour, t->tm_min, t->tm_sec);
1994 fprintf(leaseFile, "}\n");
1996}
1997
1998void
1999priv_script_init(struct interface_info *ip, char *reason, char *medium)
2000{
2001 if (ip) {
2002 // XXX Do we need to do anything?
2003 }
2004}
2005
2006void
2008{
2009 u_int8_t dbuf[1500];
2010 int i, len = 0;
2011
2012#if 0
2013 script_set_env(ip->client, prefix, "ip_address",
2014 piaddr(lease->address));
2015#endif
2016
2017 if (lease->options[DHO_SUBNET_MASK].len &&
2018 (lease->options[DHO_SUBNET_MASK].len <
2019 sizeof(lease->address.iabuf))) {
2020 struct iaddr netmask, subnet, broadcast;
2021
2022 memcpy(netmask.iabuf, lease->options[DHO_SUBNET_MASK].data,
2023 lease->options[DHO_SUBNET_MASK].len);
2024 netmask.len = lease->options[DHO_SUBNET_MASK].len;
2025
2026 subnet = subnet_number(lease->address, netmask);
2027 if (subnet.len) {
2028#if 0
2029 script_set_env(ip->client, prefix, "network_number",
2030 piaddr(subnet));
2031#endif
2032 if (!lease->options[DHO_BROADCAST_ADDRESS].len) {
2033 broadcast = broadcast_addr(subnet, netmask);
2034 if (broadcast.len)
2035#if 0
2036 script_set_env(ip->client, prefix,
2037 "broadcast_address",
2038 piaddr(broadcast));
2039#else
2040 ;
2041#endif
2042 }
2043 }
2044 }
2045
2046#if 0
2047 if (lease->filename)
2048 script_set_env(ip->client, prefix, "filename", lease->filename);
2049 if (lease->server_name)
2050 script_set_env(ip->client, prefix, "server_name",
2051 lease->server_name);
2052#endif
2053
2054 for (i = 0; i < 256; i++) {
2055 u_int8_t *dp = NULL;
2056
2057 if (ip->client->config->defaults[i].len) {
2058 if (lease->options[i].len) {
2059 switch (
2060 ip->client->config->default_actions[i]) {
2061 case ACTION_DEFAULT:
2062 dp = lease->options[i].data;
2063 len = lease->options[i].len;
2064 break;
2065 case ACTION_SUPERSEDE:
2066supersede:
2067 dp = ip->client->
2068 config->defaults[i].data;
2069 len = ip->client->
2070 config->defaults[i].len;
2071 break;
2072 case ACTION_PREPEND:
2073 len = ip->client->
2074 config->defaults[i].len +
2075 lease->options[i].len;
2076 if (len >= sizeof(dbuf)) {
2077 warning("no space to %s %s",
2078 "prepend option",
2080 goto supersede;
2081 }
2082 dp = dbuf;
2083 memcpy(dp,
2084 ip->client->
2085 config->defaults[i].data,
2086 ip->client->
2087 config->defaults[i].len);
2088 memcpy(dp + ip->client->
2089 config->defaults[i].len,
2090 lease->options[i].data,
2091 lease->options[i].len);
2092 dp[len] = '\0';
2093 break;
2094 case ACTION_APPEND:
2095 len = ip->client->
2096 config->defaults[i].len +
2097 lease->options[i].len + 1;
2098 if (len > sizeof(dbuf)) {
2099 warning("no space to %s %s",
2100 "append option",
2102 goto supersede;
2103 }
2104 dp = dbuf;
2105 memcpy(dp,
2106 lease->options[i].data,
2107 lease->options[i].len);
2108 memcpy(dp + lease->options[i].len,
2109 ip->client->
2110 config->defaults[i].data,
2111 ip->client->
2112 config->defaults[i].len);
2113 dp[len-1] = '\0';
2114 }
2115 } else {
2116 dp = ip->client->
2117 config->defaults[i].data;
2118 len = ip->client->
2119 config->defaults[i].len;
2120 }
2121 } else if (lease->options[i].len) {
2122 len = lease->options[i].len;
2123 dp = lease->options[i].data;
2124 } else {
2125 len = 0;
2126 }
2127#if 0
2128 if (len) {
2129 char name[256];
2130
2131 if (dhcp_option_ev_name(name, sizeof(name),
2132 &dhcp_options[i]))
2133 script_set_env(ip->client, prefix, name,
2134 pretty_print_option(i, dp, len, 0, 0));
2135 }
2136#endif
2137 }
2138#if 0
2139 snprintf(tbuf, sizeof(tbuf), "%d", (int)lease->expiry);
2140 script_set_env(ip->client, prefix, "expiry", tbuf);
2141#endif
2142}
2143
2144int
2145dhcp_option_ev_name(char *buf, size_t buflen, struct dhcp_option *option)
2146{
2147 int i;
2148
2149 for (i = 0; option->name[i]; i++) {
2150 if (i + 1 == buflen)
2151 return 0;
2152 if (option->name[i] == '-')
2153 buf[i] = '_';
2154 else
2155 buf[i] = option->name[i];
2156 }
2157
2158 buf[i] = 0;
2159 return 1;
2160}
2161
2162#if 0
2163void
2164go_daemon(void)
2165{
2166 static int state = 0;
2167
2168 if (no_daemon || state)
2169 return;
2170
2171 state = 1;
2172
2173 /* Stop logging to stderr... */
2174 log_perror = 0;
2175
2176 if (daemon(1, 0) == -1)
2177 error("daemon");
2178
2179 /* we are chrooted, daemon(3) fails to open /dev/null */
2180 if (nullfd != -1) {
2181 dup2(nullfd, STDIN_FILENO);
2182 dup2(nullfd, STDOUT_FILENO);
2183 dup2(nullfd, STDERR_FILENO);
2184 close(nullfd);
2185 nullfd = -1;
2186 }
2187}
2188#endif
2189
2190int
2192{
2193 char *opbuf;
2194 char *sbuf;
2195
2196 /* we use this, since this is what gets passed to dhclient-script */
2197
2198 opbuf = pretty_print_option(option, l->options[option].data,
2199 l->options[option].len, 0, 0);
2200
2201 sbuf = option_as_string(option, l->options[option].data,
2202 l->options[option].len);
2203
2204 switch (option) {
2205 case DHO_SUBNET_MASK:
2206 if (l->options[option].len != (int)sizeof(ULONG))
2207 {
2208 warning("Invalid IP address length in option(%d): %d", option, l->options[option].len);
2209 return (0);
2210 }
2211 if (!ipv4addrs(opbuf))
2212 {
2213 warning("Invalid IP address in option(%d): %s", option, opbuf);
2214 return (0);
2215 }
2216 return (1);
2217 case DHO_ROUTERS:
2218 if (l->options[option].len % (int)sizeof(ULONG))
2219 {
2220 warning("Invalid IP address list length in option(%d): %d", option, l->options[option].len);
2221 return (0);
2222 }
2223 if (!ipv4addrs(opbuf))
2224 {
2225 warning("Invalid IP address in option(%d): %s", option, opbuf);
2226 return (0);
2227 }
2228 return (1);
2229 case DHO_TIME_SERVERS:
2230 case DHO_NAME_SERVERS:
2232 case DHO_LOG_SERVERS:
2233 case DHO_COOKIE_SERVERS:
2234 case DHO_LPR_SERVERS:
2237 case DHO_SWAP_SERVER:
2239 case DHO_NIS_SERVERS:
2240 case DHO_NTP_SERVERS:
2243 case DHO_FONT_SERVERS:
2245 if (!ipv4addrs(opbuf)) {
2246 warning("Invalid IP address in option(%d): %s", option, opbuf);
2247 return (0);
2248 }
2249 return (1) ;
2250 case DHO_HOST_NAME:
2251 case DHO_DOMAIN_NAME:
2252 case DHO_NIS_DOMAIN:
2253 if (!res_hnok(sbuf))
2254 warning("Bogus Host Name option %d: %s (%s)", option,
2255 sbuf, opbuf);
2256 return (1);
2257 case DHO_PAD:
2258 case DHO_TIME_OFFSET:
2259 case DHO_BOOT_SIZE:
2260 case DHO_MERIT_DUMP:
2261 case DHO_ROOT_PATH:
2263 case DHO_IP_FORWARDING:
2265 case DHO_POLICY_FILTER:
2267 case DHO_DEFAULT_IP_TTL:
2270 case DHO_INTERFACE_MTU:
2273 case DHO_MASK_SUPPLIER:
2276 case DHO_STATIC_ROUTES:
2285 case DHO_NETBIOS_SCOPE:
2292 case DHO_DHCP_MESSAGE:
2299 case DHO_END:
2300 return (1);
2301 default:
2302 warning("unknown dhcp option value 0x%x", option);
2303 return (unknown_ok);
2304 }
2305}
2306
2307int
2308res_hnok(const char *dn)
2309{
2310 int pch = PERIOD, ch = *dn++;
2311
2312 while (ch != '\0') {
2313 int nch = *dn++;
2314
2315 if (periodchar(ch)) {
2316 ;
2317 } else if (periodchar(pch)) {
2318 if (!borderchar(ch))
2319 return (0);
2320 } else if (periodchar(nch) || nch == '\0') {
2321 if (!borderchar(ch))
2322 return (0);
2323 } else {
2324 if (!middlechar(ch))
2325 return (0);
2326 }
2327 pch = ch, ch = nch;
2328 }
2329 return (1);
2330}
2331
2332/* Does buf consist only of dotted decimal ipv4 addrs?
2333 * return how many if so,
2334 * otherwise, return 0
2335 */
2336int
2338{
2339 char *tmp;
2340 struct in_addr jnk;
2341 int i = 0;
2342
2343 note("Input: %s", buf);
2344
2345 do {
2346 tmp = strtok(buf, " ");
2347 note("got %s", tmp);
2348 if( tmp && inet_aton(tmp, &jnk) ) i++;
2349 buf = NULL;
2350 } while( tmp );
2351
2352 return (i);
2353}
2354
2355
2356char *
2357option_as_string(unsigned int code, unsigned char *data, int len)
2358{
2359 static char optbuf[32768]; /* XXX */
2360 char *op = optbuf;
2361 int opleft = sizeof(optbuf);
2362 unsigned char *dp = data;
2363
2364 if (code > 255)
2365 error("option_as_string: bad code %d", code);
2366
2367 for (; dp < data + len; dp++) {
2368 if (!isascii(*dp) || !isprint(*dp)) {
2369 if (dp + 1 != data + len || *dp != 0) {
2370 _snprintf(op, opleft, "\\%03o", *dp);
2371 op += 4;
2372 opleft -= 4;
2373 }
2374 } else if (*dp == '"' || *dp == '\'' || *dp == '$' ||
2375 *dp == '`' || *dp == '\\') {
2376 *op++ = '\\';
2377 *op++ = *dp;
2378 opleft -= 2;
2379 } else {
2380 *op++ = *dp;
2381 opleft--;
2382 }
2383 }
2384 if (opleft < 1)
2385 goto toobig;
2386 *op = 0;
2387 return optbuf;
2388toobig:
2389 warning("dhcp option too large");
2390 return "<error>";
2391}
2392
#define isprint(c)
Definition: acclib.h:73
#define close
Definition: acwin.h:99
CHAR FAR *WSAAPI inet_ntoa(IN IN_ADDR in)
Definition: addrconv.c:71
#define inet_aton(ap, inp)
Definition: adns_win32.h:161
static int state
Definition: maze.c:121
LONG NTSTATUS
Definition: precomp.h:26
void AdapterInit()
Definition: adapter.c:289
PDHCP_ADAPTER AdapterFindInfo(struct interface_info *ip)
Definition: adapter.c:638
VOID ApiInit()
Definition: api.c:18
void cancel_timeout(void(*where)(void *), void *what)
Definition: dispatch.c:316
void add_timeout(time_t when, void(*where)(void *), void *what)
Definition: dispatch.c:253
void(* bootp_packet_handler)(struct interface_info *, struct dhcp_packet *, int, unsigned int, struct iaddr, struct hardware *)
Definition: dispatch.c:59
char * pretty_print_option(unsigned int code, unsigned char *data, int len, int emit_commas, int emit_quotes)
Definition: options.c:396
int cons_options(struct packet *inpacket, struct dhcp_packet *outpacket, int mms, struct tree_cache **options)
Definition: options.c:199
void do_packet(struct interface_info *interface, struct dhcp_packet *packet, int len, unsigned int from_port, struct iaddr from, struct hardware *hfrom)
Definition: options.c:635
struct dhcp_option dhcp_options[256]
Definition: tables.c:68
int note(char *format,...)
Definition: util.c:12
int addr_eq(struct iaddr a, struct iaddr b)
Definition: util.c:100
struct iaddr broadcast_addr(struct iaddr addr, struct iaddr mask)
Definition: util.c:178
char * piaddr(struct iaddr addr)
Definition: util.c:6
u_int32_t getULong(unsigned char *data)
Definition: util.c:96
struct iaddr subnet_number(struct iaddr addr, struct iaddr mask)
Definition: util.c:183
#define MID_TRACE
Definition: debug.h:15
#define DH_DbgPrint(_t_, _x_)
Definition: debug.h:49
#define DHO_DHCP_MESSAGE
Definition: dhcp.h:152
#define DHO_MASK_SUPPLIER
Definition: dhcp.h:126
#define DHCPREQUEST
Definition: dhcp.h:164
#define DHO_TCP_KEEPALIVE_GARBAGE
Definition: dhcp.h:135
#define DHO_DHCP_MAX_MESSAGE_SIZE
Definition: dhcp.h:153
#define DHO_ROUTER_DISCOVERY
Definition: dhcp.h:127
#define DHO_NAME_SERVERS
Definition: dhcp.h:101
#define DHO_VENDOR_ENCAPSULATED_OPTIONS
Definition: dhcp.h:139
#define DHO_PERFORM_MASK_DISCOVERY
Definition: dhcp.h:125
#define DHO_NIS_SERVERS
Definition: dhcp.h:137
#define BOOTP_MIN_LEN
Definition: dhcp.h:54
#define DHO_NON_LOCAL_SOURCE_ROUTING
Definition: dhcp.h:116
#define DHCPRELEASE
Definition: dhcp.h:168
#define DHO_NTP_SERVERS
Definition: dhcp.h:138
#define DHO_MERIT_DUMP
Definition: dhcp.h:110
#define DHO_NETBIOS_NAME_SERVERS
Definition: dhcp.h:140
#define DHO_DHCP_PARAMETER_REQUEST_LIST
Definition: dhcp.h:151
#define DHO_FONT_SERVERS
Definition: dhcp.h:144
#define DHO_NETBIOS_SCOPE
Definition: dhcp.h:143
#define DHCPNAK
Definition: dhcp.h:167
#define DHCP_SNAME_LEN
Definition: dhcp.h:46
#define DHO_LOG_SERVERS
Definition: dhcp.h:103
#define DHCPACK
Definition: dhcp.h:166
#define DHCP_FILE_LEN
Definition: dhcp.h:47
#define DHO_NETBIOS_NODE_TYPE
Definition: dhcp.h:142
#define DHO_NIS_DOMAIN
Definition: dhcp.h:136
#define BOOTREPLY
Definition: dhcp.h:79
#define DHO_PAD
Definition: dhcp.h:96
#define DHO_HOST_NAME
Definition: dhcp.h:108
#define DHO_TCP_KEEPALIVE_INTERVAL
Definition: dhcp.h:134
#define DHO_BROADCAST_ADDRESS
Definition: dhcp.h:124
#define DHO_TIME_SERVERS
Definition: dhcp.h:100
#define DHO_NETBIOS_DD_SERVER
Definition: dhcp.h:141
#define DHO_IP_FORWARDING
Definition: dhcp.h:115
#define DHO_IMPRESS_SERVERS
Definition: dhcp.h:106
#define DHO_TRAILER_ENCAPSULATION
Definition: dhcp.h:130
#define DHO_PATH_MTU_PLATEAU_TABLE
Definition: dhcp.h:121
#define DHO_DHCP_USER_CLASS_ID
Definition: dhcp.h:158
#define DHO_EXTENSIONS_PATH
Definition: dhcp.h:114
#define DHO_DHCP_CLIENT_IDENTIFIER
Definition: dhcp.h:157
#define DHO_TIME_OFFSET
Definition: dhcp.h:98
#define DHO_DEFAULT_TCP_TTL
Definition: dhcp.h:133
#define DHO_DHCP_MESSAGE_TYPE
Definition: dhcp.h:149
#define DHO_INTERFACE_MTU
Definition: dhcp.h:122
#define DHO_X_DISPLAY_MANAGER
Definition: dhcp.h:145
#define DHO_POLICY_FILTER
Definition: dhcp.h:117
#define DHO_ALL_SUBNETS_LOCAL
Definition: dhcp.h:123
#define DHO_MAX_DGRAM_REASSEMBLY
Definition: dhcp.h:118
#define BOOTREQUEST
Definition: dhcp.h:78
#define DHCPDISCOVER
Definition: dhcp.h:162
#define DHO_END
Definition: dhcp.h:159
#define DHO_COOKIE_SERVERS
Definition: dhcp.h:104
#define DHO_DOMAIN_NAME
Definition: dhcp.h:111
#define DHO_DHCP_RENEWAL_TIME
Definition: dhcp.h:154
#define DHCPOFFER
Definition: dhcp.h:163
#define DHO_SWAP_SERVER
Definition: dhcp.h:112
#define DHO_DOMAIN_NAME_SERVERS
Definition: dhcp.h:102
#define DHO_DEFAULT_IP_TTL
Definition: dhcp.h:119
#define DHO_BOOT_SIZE
Definition: dhcp.h:109
#define DHO_DHCP_REBINDING_TIME
Definition: dhcp.h:155
#define DHO_DHCP_OPTION_OVERLOAD
Definition: dhcp.h:148
#define DHO_DHCP_SERVER_IDENTIFIER
Definition: dhcp.h:150
#define DHO_ROOT_PATH
Definition: dhcp.h:113
#define DHO_ARP_CACHE_TIMEOUT
Definition: dhcp.h:131
#define DHO_ROUTERS
Definition: dhcp.h:99
#define DHO_IEEE802_3_ENCAPSULATION
Definition: dhcp.h:132
#define DHO_DHCP_REQUESTED_ADDRESS
Definition: dhcp.h:146
#define DHO_DHCP_LEASE_TIME
Definition: dhcp.h:147
#define DHO_STATIC_ROUTES
Definition: dhcp.h:129
#define DHO_SUBNET_MASK
Definition: dhcp.h:97
#define DHO_DHCP_CLASS_IDENTIFIER
Definition: dhcp.h:156
#define DHO_LPR_SERVERS
Definition: dhcp.h:105
#define DHO_ROUTER_SOLICITATION_ADDRESS
Definition: dhcp.h:128
#define DHCPDECLINE
Definition: dhcp.h:165
#define DHO_PATH_MTU_AGING_TIMEOUT
Definition: dhcp.h:120
#define DHO_RESOURCE_LOCATION_SERVERS
Definition: dhcp.h:107
#define RegCloseKey(hKey)
Definition: registry.h:49
r l[0]
Definition: byte_order.h:168
Definition: bufpool.h:45
#define NO_ERROR
Definition: dderror.h:5
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define BufferSize
Definition: mmc.h:75
#define ERROR_SUCCESS
Definition: deptool.c:10
void make_request(struct interface_info *ip, struct client_lease *lease)
Definition: dhclient.c:1653
void unset_domain(PDHCP_ADAPTER Adapter)
Definition: dhclient.c:533
#define TIME_MAX
Definition: dhclient.c:90
int init_client(void)
Definition: dhclient.c:111
struct client_lease * packet_to_lease(struct packet *packet)
Definition: dhclient.c:972
void make_release(struct interface_info *ip, struct client_lease *lease)
Definition: dhclient.c:1829
void bootp(struct packet *packet)
Definition: dhclient.c:796
int unknown_ok
Definition: dhclient.c:94
void bind_lease(struct interface_info *ip)
Definition: dhclient.c:700
void dhcp(struct packet *packet)
Definition: dhclient.c:816
#define middlechar(c)
Definition: dhclient.c:68
char * path_dhclient_db
Definition: dhclient.c:74
int privfd
Definition: dhclient.c:77
void send_discover(void *ipp)
Definition: dhclient.c:1106
void free_client_lease(struct client_lease *lease)
Definition: dhclient.c:1893
void dhcpnak(struct packet *packet)
Definition: dhclient.c:1066
int dhcp_option_ev_name(char *buf, size_t buflen, struct dhcp_option *option)
Definition: dhclient.c:2145
struct iaddr iaddr_broadcast
Definition: dhclient.c:80
void write_client_lease(struct interface_info *ip, struct client_lease *lease, int rewrite)
Definition: dhclient.c:1933
struct in_addr inaddr_any
Definition: dhclient.c:81
int check_option(struct client_lease *l, int option)
Definition: dhclient.c:2191
void unset_name_servers(PDHCP_ADAPTER Adapter)
Definition: dhclient.c:466
void state_bound(void *ipp)
Definition: dhclient.c:770
int ipv4addrs(char *buf)
Definition: dhclient.c:2337
void send_release(void *ipp)
Definition: dhclient.c:1545
char * path_dhclient_conf
Definition: dhclient.c:73
void setup_adapter(PDHCP_ADAPTER Adapter, struct client_lease *new_lease)
Definition: dhclient.c:561
int fork_privchld(int, int)
void make_decline(struct interface_info *ip, struct client_lease *lease)
Definition: dhclient.c:1755
#define periodchar(c)
Definition: dhclient.c:61
struct sockaddr_in sockaddr_broadcast
Definition: dhclient.c:82
int no_daemon
Definition: dhclient.c:93
void state_selecting(void *ipp)
Definition: dhclient.c:257
void send_decline(void *ipp)
Definition: dhclient.c:1531
void state_release(void *ipp)
Definition: dhclient.c:231
int check_arp(struct interface_info *ip, struct client_lease *lp)
Definition: dhclient.c:137
void state_reboot(void *ipp)
Definition: dhclient.c:172
void set_domain(PDHCP_ADAPTER Adapter, struct client_lease *new_lease)
Definition: dhclient.c:483
void dhcpack(struct packet *packet)
Definition: dhclient.c:338
void state_panic(void *ipp)
Definition: dhclient.c:1212
void unbind_lease(struct interface_info *ip)
Definition: dhclient.c:742
void stop_client(void)
Definition: dhclient.c:129
#define borderchar(c)
Definition: dhclient.c:67
FILE * leaseFile
Definition: dhclient.c:1908
char * option_as_string(unsigned int code, unsigned char *data, int len)
Definition: dhclient.c:2357
int log_perror
Definition: dhclient.c:76
void reset_adapter(PDHCP_ADAPTER Adapter)
Definition: dhclient.c:647
void priv_script_init(struct interface_info *ip, char *reason, char *medium)
Definition: dhclient.c:1999
void priv_script_write_params(struct interface_info *ip, char *prefix, struct client_lease *lease)
Definition: dhclient.c:2007
time_t scripttime
Definition: dhclient.c:107
void state_init(void *ipp)
Definition: dhclient.c:210
int routefd
Definition: dhclient.c:95
int res_hnok(const char *dn)
Definition: dhclient.c:2308
int log_priority
Definition: dhclient.c:92
#define ASSERT_STATE(state_is, state_shouldbe)
Definition: dhclient.c:88
void set_name_servers(PDHCP_ADAPTER Adapter, struct client_lease *new_lease)
Definition: dhclient.c:421
void rewrite_client_leases(struct interface_info *ifi)
Definition: dhclient.c:1911
void usage(void)
void dhcpoffer(struct packet *packet)
Definition: dhclient.c:852
unsigned long debug_trace_level
Definition: dhclient.c:71
#define PERIOD
Definition: dhclient.c:58
void make_discover(struct interface_info *ip, struct client_lease *lease)
Definition: dhclient.c:1570
void go_daemon(void)
time_t cur_time
@ S_RELEASED
Definition: dhcpd.h:180
@ S_REBOOTING
Definition: dhcpd.h:172
@ S_BOUND
Definition: dhcpd.h:176
@ S_RENEWING
Definition: dhcpd.h:177
@ S_REBINDING
Definition: dhcpd.h:178
@ S_SELECTING
Definition: dhcpd.h:174
@ S_REQUESTING
Definition: dhcpd.h:175
@ S_INIT
Definition: dhcpd.h:173
#define REMOTE_PORT
Definition: dhcpd.h:113
#define _PATH_DHCLIENT_CONF
Definition: dhcpd.h:277
void script_set_env(struct client_state *, const char *, const char *, const char *)
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
UINT op
Definition: effect.c:236
LONG WINAPI RegSetValueExA(HKEY hKey, LPCSTR lpValueName, DWORD Reserved, DWORD dwType, CONST BYTE *lpData, DWORD cbData)
Definition: reg.c:4799
LONG WINAPI RegOpenKeyExA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey, _In_ DWORD ulOptions, _In_ REGSAM samDesired, _Out_ PHKEY phkResult)
Definition: reg.c:3298
LONG WINAPI RegDeleteValueA(HKEY hKey, LPCSTR lpValueName)
Definition: reg.c:2287
LONG WINAPI RegDeleteValueW(HKEY hKey, LPCWSTR lpValueName)
Definition: reg.c:2330
static WCHAR reason[MAX_STRING_RESOURCE_LEN]
Definition: object.c:1971
#define MAX_PATH
Definition: compat.h:34
ULONG WINAPI DECLSPEC_HOTPATCH GetTickCount(void)
Definition: sync.c:182
UINT(* handler)(MSIPACKAGE *)
Definition: action.c:7512
unsigned char ch[4][2]
Definition: console.c:118
int WINAPIV fprintf(FILE *file, const char *format,...)
Definition: file.c:5549
FILE *CDECL fopen(const char *path, const char *mode)
Definition: file.c:4310
void CDECL rewind(FILE *file)
Definition: file.c:1712
int CDECL fflush(FILE *file)
Definition: file.c:1182
__time32_t time_t
Definition: corecrt.h:228
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2807
static int dup2(int od, int nd)
Definition: io.h:20
unsigned short uint16_t
Definition: stdint.h:35
static int __cdecl _snprintf(char *buffer, size_t size, const char *format,...) __WINE_CRT_PRINTF_ATTR(3
Definition: stdio.h:507
#define STDOUT_FILENO
Definition: stdio.h:25
#define STDERR_FILENO
Definition: stdio.h:26
#define STDIN_FILENO
Definition: stdio.h:24
_ACRTIMP int __cdecl rand(void)
Definition: misc.c:59
_ACRTIMP void __cdecl srand(unsigned int)
Definition: misc.c:50
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1597
_ACRTIMP char *__cdecl strtok(char *, const char *)
Definition: string.c:290
static struct tm * gmtime(const time_t *t)
Definition: time.h:120
int nch
Definition: scanf.h:201
return ret
Definition: mutex.c:146
#define L(x)
Definition: resources.c:13
#define AF_INET
Definition: tcpip.h:117
unsigned long DWORD
Definition: ntddk_ex.h:95
static void increase(int &a_)
FxAutoRegKey hKey
Status
Definition: gdiplustypes.h:24
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLdouble GLdouble t
Definition: gl.h:2047
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum const GLvoid * addr
Definition: glext.h:9621
GLenum GLsizei len
Definition: glext.h:6722
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
DWORD WINAPI AddIPAddress(IPAddr Address, IPMask Netmask, DWORD IfIndex, PULONG NteContext, PULONG NteInstance)
Definition: iphlpapi_main.c:67
DWORD WINAPI DeleteIpForwardEntry(PMIB_IPFORWARDROW pRoute)
DWORD WINAPI CreateIpForwardEntry(PMIB_IPFORWARDROW pRoute)
DWORD WINAPI DeleteIPAddress(ULONG NTEContext)
DWORD WINAPI SendARP(IPAddr DestIP, IPAddr SrcIP, PULONG pMacAddr, PULONG PhyAddrLen)
#define debug(msg)
Definition: key_call.c:71
#define REG_SZ
Definition: layer.c:22
#define INADDR_BROADCAST
Definition: inet.h:82
#define INADDR_ANY
Definition: inet.h:80
__u16 time
Definition: mkdosfs.c:8
#define error(str)
Definition: mkdosfs.c:1605
#define pch(ap)
Definition: match.c:418
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define htons(x)
Definition: module.h:215
#define ntohs(x)
Definition: module.h:210
#define htonl(x)
Definition: module.h:214
NTSYSAPI ULONG NTAPI RtlRandom(_Inout_ PULONG Seed)
#define KEY_WRITE
Definition: nt_native.h:1034
char CHAR
Definition: pedump.c:57
ULONG IPAddr
Definition: pfhook.h:35
static unsigned __int64 next
Definition: rand_nt.c:6
#define err(...)
unsigned char u_int8_t
Definition: rosdhcp.h:37
#define DHCP_DEFAULT_LEASE_TIME
Definition: rosdhcp.h:34
#define REG_DWORD
Definition: sdbapi.c:615
#define isascii
Definition: ctype.h:742
_CRTIMP void __cdecl tzset(void)
#define warning(s)
Definition: debug.h:83
strcat
Definition: string.h:92
#define memset(x, y, z)
Definition: compat.h:39
ssize_t send_packet(struct interface_info *ip, struct dhcp_packet *p, size_t size, struct in_addr addr, struct sockaddr_in *broadcast, struct hardware *hardware)
Definition: socket.c:9
CardRegion * from
Definition: spigame.cpp:19
static void Server(int port)
Definition: srltest.c:69
ULONG NteContext
Definition: rosdhcp.h:85
ULONG NteInstance
Definition: rosdhcp.h:85
MIB_IPFORWARDROW RouterMib
Definition: rosdhcp.h:82
PALTERNATE_CONFIGURATION AlternateConfiguration
Definition: rosdhcp.h:80
struct interface_info DhclientInfo
Definition: rosdhcp.h:86
MIB_IFROW IfMib
Definition: rosdhcp.h:81
DWORD dwIndex
Definition: ifmib.h:38
DWORD dwForwardNextHop
Definition: ipmib.h:74
DWORD dwForwardMetric1
Definition: ipmib.h:88
IF_INDEX dwForwardIfIndex
Definition: ipmib.h:75
DWORD dwForwardDest
Definition: ipmib.h:71
DWORD dwForwardMask
Definition: ipmib.h:72
unsigned int is_static
Definition: dhcpd.h:165
struct string_list * medium
Definition: dhcpd.h:164
struct option_data options[256]
Definition: dhcpd.h:167
struct iaddr address
Definition: dhcpd.h:156
char * filename
Definition: dhcpd.h:163
char * server_name
Definition: dhcpd.h:157
unsigned int is_bootp
Definition: dhcpd.h:166
struct client_lease * next
Definition: dhcpd.h:154
time_t renewal
Definition: dhcpd.h:155
time_t rebind
Definition: dhcpd.h:155
time_t expiry
Definition: dhcpd.h:155
Definition: inflate.c:139
Definition: dhcpd.h:125
int len
Definition: dhcpd.h:126
unsigned char iabuf[16]
Definition: dhcpd.h:127
Definition: tcpip.h:126
struct client_state * client
Definition: dhcpd.h:241
Definition: dhcpd.h:62
Definition: name.c:39
Definition: getopt.h:109
WCHAR * name
Definition: getopt.h:110
Definition: dhcpd.h:135
struct dhcp_packet * raw
Definition: dhcpd.h:136
struct interface_info * interface
Definition: dhcpd.h:142
struct option_data options[256]
Definition: dhcpd.h:144
int packet_type
Definition: dhcpd.h:138
struct iaddr client_addr
Definition: dhcpd.h:141
Definition: tftpd.h:86
struct in_addr sin_addr
Definition: winsock.h:506
short sin_family
Definition: winsock.h:504
u_short sin_port
Definition: winsock.h:505
NTSYSAPI PSTR NTAPI RtlIpv4AddressToStringA(_In_ const struct in_addr *Addr, _Out_writes_(16) PSTR S)
Character const *const prefix
Definition: tempnam.cpp:195
static const u8_t broadcast[6]
Definition: test_dhcp.c:23
unsigned char * LPBYTE
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254
void int int ULONGLONG int va_list * ap
Definition: winesup.h:36
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define snprintf
Definition: wintirpc.h:48