40 #include <dns/result.h>
50 extern int asprintf(
char **strp,
const char *fmt, ...);
81 #define ASSERT_STATE(state_is, state_shouldbe) {}
83 static const char copyright[] =
"Copyright 2004-2014 Internet Systems Consortium.";
84 static const char arr [] =
"All rights reserved.";
85 static const char message [] =
"Internet Systems Consortium DHCP Client";
86 static const char url [] =
"For info, please visit https://www.isc.org/software/dhcp/";
107 static void usage(
void);
109 static isc_result_t write_duid(
struct data_string *duid);
112 static int check_domain_name(
const char *ptr,
size_t len,
int dots);
113 static int check_domain_name_list(
const char *ptr,
size_t len,
int dots);
115 const char *ptr,
size_t len);
130 int release_mode = 0;
135 int no_dhclient_conf = 0;
136 int no_dhclient_db = 0;
137 int no_dhclient_pid = 0;
138 int no_dhclient_script = 0;
140 int local_family_set = 0;
143 char *dhcp_client_identifier_arg = NULL;
144 char *dhcp_host_name_arg = NULL;
145 char *dhcp_fqdn_arg = NULL;
146 char *dhcp_vendor_class_identifier_arg = NULL;
147 char *dhclient_request_options = NULL;
150 char *arg_conf = NULL;
151 int arg_conf_len = 0;
152 #ifdef HAVE_LIBCAP_NG
153 int keep_capabilities = 0;
162 fd = open(
"/dev/null", O_RDWR | O_CLOEXEC);
164 fd = open(
"/dev/null", O_RDWR | O_CLOEXEC);
166 fd = open(
"/dev/null", O_RDWR | O_CLOEXEC);
174 #if !(defined(DEBUG) || defined(__CYGWIN32__))
175 setlogmask(LOG_UPTO(LOG_INFO));
181 if (status != ISC_R_SUCCESS)
182 log_fatal(
"Can't initialize context: %s",
183 isc_result_totext(status));
187 if (status != ISC_R_SUCCESS)
189 isc_result_totext(status));
199 for (i = 1; i < argc; i++) {
200 if (!strcmp(argv[i],
"-r")) {
204 }
else if (!strcmp(argv[i],
"-4")) {
206 log_fatal(
"Client can only do v4 or v6, not "
208 local_family_set = 1;
210 }
else if (!strcmp(argv[i],
"-6")) {
212 log_fatal(
"Client can only do v4 or v6, not "
214 local_family_set = 1;
217 }
else if (!strcmp(argv[i],
"-x")) {
221 }
else if (!strcmp(argv[i],
"-p")) {
225 log_debug(
"binding to user-specified port %d",
227 }
else if (!strcmp(argv[i],
"-d")) {
230 }
else if (!strcmp(argv[i],
"-pf")) {
235 }
else if (!strcmp(argv[i],
"--no-pid")) {
237 }
else if (!strcmp(argv[i],
"-cf")) {
241 no_dhclient_conf = 1;
242 }
else if (!strcmp(argv[i],
"-df")) {
246 }
else if (!strcmp(argv[i],
"-lf")) {
251 }
else if (!strcmp(argv[i],
"-sf")) {
255 no_dhclient_script = 1;
256 }
else if (!strcmp(argv[i],
"-1")) {
258 }
else if (!strcmp(argv[i],
"-q")) {
260 }
else if (!strcmp(argv[i],
"-s")) {
264 }
else if (!strcmp(argv[i],
"-g")) {
268 }
else if (!strcmp(argv[i],
"-nw")) {
270 }
else if (!strcmp(argv[i],
"-n")) {
273 }
else if (!strcmp(argv[i],
"-w")) {
276 }
else if (!strcmp(argv[i],
"-e")) {
280 tmp =
dmalloc(strlen(argv[i]) +
sizeof *tmp,
MDL);
283 strcpy(tmp->
string, argv[i]);
288 }
else if (!strcmp(argv[i],
"-S")) {
292 local_family_set = 1;
296 }
else if (!strcmp(argv[i],
"-N")) {
300 local_family_set = 1;
306 }
else if (!strcmp(argv[i],
"-T")) {
310 local_family_set = 1;
316 }
else if (!strcmp(argv[i],
"-P")) {
320 local_family_set = 1;
327 }
else if (!strcmp(argv[i],
"-D")) {
331 if (!strcasecmp(argv[i],
"LL")) {
333 }
else if (!strcasecmp(argv[i],
"LLT")) {
338 }
else if (!strcmp(argv[i],
"-i")) {
341 }
else if (!strcmp(argv[i],
"-I")) {
344 }
else if (!strcmp(argv[i],
"-v")) {
346 }
else if (!strcmp(argv[i],
"--version")) {
347 const char vstring[] =
"isc-dhclient-";
355 }
else if (!strcmp(argv[i],
"-C")) {
356 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
366 dhcp_client_identifier_arg = argv[i];
367 }
else if (!strcmp(argv[i],
"-B")) {
369 }
else if (!strcmp(argv[i],
"-H")) {
370 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
380 if (dhcp_host_name_arg != NULL) {
381 log_error(
"The -H <host-name> and -F <fqdn> arguments are mutually exclusive");
385 dhcp_host_name_arg = argv[i];
386 }
else if (!strcmp(argv[i],
"-F")) {
387 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
397 if (dhcp_fqdn_arg != NULL) {
398 log_error(
"Only one -F <fqdn> argument can be specified");
402 if (dhcp_host_name_arg != NULL) {
403 log_error(
"The -F <fqdn> and -H <host-name> arguments are mutually exclusive");
407 dhcp_fqdn_arg = argv[i];
408 }
else if (!strcmp(argv[i],
"-timeout")) {
409 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
414 if ((timeout_arg = atoi(argv[i])) <= 0) {
415 log_error(
"timeout option must be > 0 - bad value: %s",argv[i]);
418 }
else if (!strcmp(argv[i],
"-V")) {
419 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
429 dhcp_vendor_class_identifier_arg = argv[i];
430 }
else if (!strcmp(argv[i],
"-R")) {
431 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
436 dhclient_request_options = argv[i];
437 }
else if (!strcmp(argv[i],
"-nc")) {
438 #ifdef HAVE_LIBCAP_NG
439 keep_capabilities = 1;
441 }
else if (argv[i][0] ==
'-') {
448 status = interface_allocate(&tmp,
MDL);
449 if (status != ISC_R_SUCCESS)
450 log_fatal(
"Can't record interface %s:%s",
451 argv[i], isc_result_totext(status));
452 if (strlen(argv[i]) >=
sizeof(tmp->
name))
453 log_fatal(
"%s: interface name too long (is %ld)",
454 argv[i], (
long)strlen(argv[i]));
455 strcpy(tmp->
name, argv[i]);
457 interface_reference(&tmp->
next,
476 if (!no_dhclient_conf && (s = getenv(
"PATH_DHCLIENT_CONF"))) {
479 if (!no_dhclient_db && (s = getenv(
"PATH_DHCLIENT_DB"))) {
482 if (!no_dhclient_pid && (s = getenv(
"PATH_DHCLIENT_PID"))) {
485 if (!no_dhclient_script && (s = getenv(
"PATH_DHCLIENT_SCRIPT"))) {
489 #ifdef HAVE_LIBCAP_NG
491 if (!keep_capabilities) {
492 capng_clear(CAPNG_SELECT_CAPS);
493 capng_update(CAPNG_ADD, CAPNG_EFFECTIVE|CAPNG_PERMITTED,
495 capng_updatev(CAPNG_ADD, CAPNG_EFFECTIVE|CAPNG_PERMITTED,
496 CAP_NET_ADMIN, CAP_NET_RAW,
497 CAP_NET_BIND_SERVICE, CAP_SYS_ADMIN, -1);
498 capng_apply(CAPNG_SELECT_CAPS);
523 log_fatal(
"Failed to get realpath for %s: %s", old_path, strerror(errno));
530 log_fatal(
"Failed to get realpath for %s: %s", old_path, strerror(errno));
539 if ((release_mode || exit_mode) && (
no_pid_file == ISC_FALSE)) {
546 e = fscanf(pidfd,
"%ld\n", &temp);
547 oldpid = (pid_t)temp;
549 if (e != 0 && e != EOF && oldpid) {
550 if (kill(oldpid, SIGTERM) == 0) {
551 log_info(
"Killed old client process");
561 }
else if (errno == ESRCH) {
575 char *new_path_dhclient_pid;
594 int n_len = strlen(ip->
name);
596 new_path_dhclient_pid = (
char*) malloc(pfx + n_len + 6);
598 sprintf(new_path_dhclient_pid + pfx,
"-%s.pid", ip->
name);
600 if ((pidfd = fopen(new_path_dhclient_pid,
"re")) != NULL) {
601 e = fscanf(pidfd,
"%ld\n", &temp);
602 oldpid = (pid_t)temp;
604 if (e != 0 && e != EOF) {
606 if (kill(oldpid, SIGTERM) == 0)
614 free(new_path_dhclient_pid);
623 char procfn[256] =
"";
626 if ((fscanf(pidfp,
"%ld", &temp)==1) && ((dhcpid=(pid_t)temp) > 0)) {
627 snprintf(procfn,256,
"/proc/%u",dhcpid);
628 dhc_running = (access(procfn, F_OK) == 0);
635 log_fatal(
"dhclient(%u) is already running - exiting. ", dhcpid);
660 memcpy(&
giaddr, he->h_addr_list[0],
669 gettimeofday(&
cur_tv, NULL);
676 he = gethostbyname(server);
709 if ((dhcp_client_identifier_arg != NULL) && (*dhcp_client_identifier_arg !=
'\0')) {
710 arg_conf_len =
asprintf(&arg_conf,
"send dhcp-client-identifier \"%s\";", dhcp_client_identifier_arg);
712 if ((arg_conf == 0) || (arg_conf_len <= 0))
713 log_fatal(
"Unable to send -C option dhcp-client-identifier");
716 if ((dhcp_host_name_arg != NULL) && (*dhcp_host_name_arg !=
'\0')) {
718 arg_conf_len =
asprintf(&arg_conf,
"send host-name \"%s\";", dhcp_host_name_arg);
720 if ((arg_conf == 0) || (arg_conf_len <= 0))
721 log_fatal(
"Unable to send -H option host-name");
723 char *last_arg_conf = arg_conf;
725 arg_conf_len =
asprintf(&arg_conf,
"%s\nsend host-name \"%s\";", last_arg_conf, dhcp_host_name_arg);
727 if ((arg_conf == 0) || (arg_conf_len <= 0))
728 log_fatal(
"Unable to send -H option host-name");
734 if ((dhcp_fqdn_arg != NULL) && (*dhcp_fqdn_arg !=
'\0')) {
736 arg_conf_len =
asprintf(&arg_conf,
"send fqdn.fqdn \"%s\";", dhcp_fqdn_arg);
738 if ((arg_conf == 0) || (arg_conf_len <= 0))
739 log_fatal(
"Unable to send -F option fqdn.fqdn");
741 char *last_arg_conf = arg_conf;
743 arg_conf_len =
asprintf(&arg_conf,
"%s\nsend fqdn.fqdn \"%s\";", last_arg_conf, dhcp_fqdn_arg);
745 if ((arg_conf == 0) || (arg_conf_len <= 0))
746 log_fatal(
"Unable to send -F option fqdn.fqdn");
754 arg_conf_len =
asprintf(&arg_conf,
"timeout %d;", timeout_arg);
756 if ((arg_conf == 0) || (arg_conf_len <= 0))
757 log_fatal(
"Unable to process -timeout timeout argument");
759 char *last_arg_conf = arg_conf;
761 arg_conf_len =
asprintf(&arg_conf,
"%s\ntimeout %d;", last_arg_conf, timeout_arg);
763 if ((arg_conf == 0) || (arg_conf_len == 0))
764 log_fatal(
"Unable to process -timeout timeout argument");
770 if ((dhcp_vendor_class_identifier_arg != NULL) && (*dhcp_vendor_class_identifier_arg !=
'\0')) {
772 arg_conf_len =
asprintf(&arg_conf,
"send vendor-class-identifier \"%s\";", dhcp_vendor_class_identifier_arg);
774 if ((arg_conf == 0) || (arg_conf_len <= 0))
775 log_fatal(
"Unable to send -V option vendor-class-identifier");
777 char *last_arg_conf = arg_conf;
779 arg_conf_len =
asprintf(&arg_conf,
"%s\nsend vendor-class-identifier \"%s\";", last_arg_conf, dhcp_vendor_class_identifier_arg);
781 if ((arg_conf == 0) || (arg_conf_len <= 0))
782 log_fatal(
"Unable to send -V option vendor-class-identifier");
788 if (dhclient_request_options != NULL) {
790 arg_conf_len =
asprintf(&arg_conf,
"request %s;", dhclient_request_options);
792 if ((arg_conf == 0) || (arg_conf_len <= 0))
793 log_fatal(
"Unable to parse -R <request options list> argument");
795 char *last_arg_conf = arg_conf;
797 arg_conf_len =
asprintf(&arg_conf,
"%s\nrequest %s;", last_arg_conf, dhclient_request_options);
799 if ((arg_conf == 0) || (arg_conf_len <= 0))
800 log_fatal(
"Unable to parse -R <request options list> argument");
807 if (arg_conf_len == 0)
808 if ((arg_conf_len = strlen(arg_conf)) == 0)
810 log_fatal(
"Unable to process -C/-H/-F/-timeout/-V/-R configuration arguments");
815 const char *val = NULL;
818 status =
new_parse(&cfile, -1, arg_conf, arg_conf_len,
"extra dhclient -C/-H/-F/-timeout/-V/-R configuration arguments", 0);
821 log_fatal(
"Cannot parse -C/-H/-F/-timeout/-V/-R configuration arguments !");
825 token =
peek_token(&val, (
unsigned *)0, cfile);
833 log_fatal(
"Cannot parse -C/-H/-F/-timeout/-V/-R configuration arguments !");
890 log_info(
"No broadcast interfaces found - exiting.");
893 }
else if (!release_mode && !exit_mode) {
927 unsigned backup_seed = 0;
930 if ( ip -> hw_address.hlen <=
sizeof seed )
933 &ip -> hw_address.hbuf [ip -> hw_address.hlen -
934 sizeof seed],
sizeof seed);
956 if ( ip -> hw_address.hlen <=
sizeof seed )
960 sizeof seed],
sizeof seed);
964 if ( seed_flag == 0 ) {
965 if ( backup_seed != 0 ) {
967 log_info (
"xid: rand init seed (0x%x) built using all"
968 " available interfaces",seed);
971 seed =
cur_time^((unsigned) gethostid()) ;
972 log_info (
"xid: warning: no netdev with useable HWADDR found"
973 " for seed's uniqueness enforcement");
974 log_info (
"xid: rand init seed (0x%x) built using gethostid",
982 srandom(seed +
cur_time + (
unsigned)getpid());
988 setup_ib_interface(ip);
1011 for (client = ip->
client ; client != NULL ;
1012 client = client->
next) {
1016 }
else if (exit_mode) {
1036 for (client = ip->
client ; client ;
1037 client = client->
next) {
1040 else if (release_mode)
1054 tv.tv_usec = random()
1089 if (result != ISC_R_SUCCESS)
1090 log_fatal(
"Can't allocate new generic object: %s\n",
1091 isc_result_totext(result));
1096 if (result != ISC_R_SUCCESS)
1097 log_fatal(
"Can't start OMAPI protocol: %s",
1098 isc_result_totext (result));
1107 #if defined(DEBUG_MEMORY_LEAKAGE) || defined(DEBUG_MALLOC_POOL) || \
1108 defined(DEBUG_MEMORY_LEAKAGE_ON_EXIT)
1109 dmalloc_cutoff_generation = dmalloc_generation;
1110 dmalloc_longterm = dmalloc_outstanding;
1111 dmalloc_outstanding = 0;
1114 #if defined(ENABLE_GENTLE_SHUTDOWN)
1149 "[-4|-6] [-SNTPI1dvrxi] [-nw] [-p <port>] [-D LL|LLT] \n"
1151 "[-I1dvrxi] [-nw] [-p <port>] [-D LL|LLT] \n"
1153 " [-s server-addr] [-cf config-file]\n"
1154 " [-df duid-file] [-lf lease-file]\n"
1155 " [-pf pid-file] [--no-pid] [-e VAR=val]\n"
1156 " [-C <dhcp-client-identifier>] [-B]\n"
1157 " [-H <host-name> | -F <fqdn.fqdn>] [-timeout <timeout>]\n"
1158 " [-V <vendor-class-identifier>]\n"
1159 " [-R <request option list>]\n"
1160 " [-sf script-file] [interface]");
1168 isc_result_t result;
1198 client = client->
next) {
1212 if (result != ISC_R_SUCCESS)
1213 log_fatal(
"Can't allocate new generic object: %s\n",
1214 isc_result_totext(result));
1219 if (result != ISC_R_SUCCESS)
1220 log_fatal(
"Can't start OMAPI protocol: %s",
1221 isc_result_totext(result));
1227 #if defined(DEBUG_MEMORY_LEAKAGE) || defined(DEBUG_MALLOC_POOL) || \
1228 defined(DEBUG_MEMORY_LEAKAGE_ON_EXIT)
1229 dmalloc_cutoff_generation = dmalloc_generation;
1230 dmalloc_longterm = dmalloc_outstanding;
1231 dmalloc_outstanding = 0;
1252 const char *s,
const char *
file,
int line)
1298 "dhcp-client-identifier") == 0)) {
1343 client ->
active -> is_bootp ||
1357 client ->
xid = random ();
1390 client -> xid = client ->
packet.xid;
1393 client -> first_sending =
cur_time;
1394 client -> interval = client -> config -> initial_interval;
1437 for (lp = client -> offered_leases; lp; lp =
next) {
1446 picked -> next = NULL;
1451 client -> offered_leases = NULL;
1458 client -> state =
S_INIT;
1465 client ->
new = picked;
1483 client -> first_sending =
cur_time;
1484 client -> interval = client -> config -> initial_interval;
1488 client -> xid = client ->
packet.xid;
1511 for (client = ip -> client; client; client = client -> next) {
1512 if (client -> xid == packet -> raw -> xid)
1516 (packet -> interface -> hw_address.hlen - 1 !=
1517 packet -> raw -> hlen) ||
1518 (memcmp (&packet -> interface -> hw_address.hbuf [1],
1519 packet -> raw -> chaddr, packet -> raw -> hlen))) {
1521 log_debug (
"DHCPACK in wrong transaction.");
1536 log_info (
"DHCPACK from %s (xid=0x%x)",
piaddr (packet -> client_addr), client -> xid);
1540 log_info (
"packet_to_lease failed.");
1544 client ->
new = lease;
1552 memset (&ds, 0,
sizeof ds);
1555 packet -> options, client ->
new -> options,
1560 client ->
new -> expiry = 0;
1563 client ->
new -> expiry = 0;
1568 log_error (
"no expiry time on offered lease.");
1574 tv.tv_sec =
cur_tv.tv_sec;
1575 tv.tv_usec =
cur_tv.tv_usec + 500000;
1577 if (tv.tv_usec >= 1000000) {
1579 tv.tv_usec -= 1000000;
1598 packet -> options, client ->
new -> options,
1603 client ->
new -> renewal = 0;
1606 client ->
new -> renewal = 0;
1609 if (!client ->
new -> renewal)
1610 client ->
new -> renewal = client ->
new -> expiry / 2 + 1;
1612 if (client ->
new -> renewal <= 0)
1613 client ->
new -> renewal =
TIME_MAX;
1618 (((random() % client->
new->
renewal) + 3) / 4);
1625 packet -> options, client ->
new -> options,
1630 client ->
new -> rebind = 0;
1633 client ->
new -> rebind = 0;
1635 if (client ->
new -> rebind <= 0) {
1636 if (client ->
new -> expiry <=
TIME_MAX / 7)
1637 client ->
new -> rebind =
1638 client ->
new -> expiry * 7 / 8;
1640 client ->
new -> rebind =
1641 client ->
new -> expiry / 8 * 7;
1646 if (client ->
new -> renewal > client ->
new -> rebind) {
1647 if (client ->
new -> rebind <=
TIME_MAX / 3)
1648 client ->
new -> renewal =
1649 client ->
new -> rebind * 3 / 4;
1651 client ->
new -> renewal =
1652 client ->
new -> rebind / 4 * 3;
1655 client ->
new -> expiry +=
cur_time;
1657 if (client ->
new -> expiry <
cur_time)
1658 client ->
new -> expiry =
TIME_MAX;
1659 client ->
new -> renewal +=
cur_time;
1660 if (client ->
new -> renewal <
cur_time)
1661 client ->
new -> renewal =
TIME_MAX;
1662 client ->
new -> rebind +=
cur_time;
1663 if (client ->
new -> rebind <
cur_time)
1664 client ->
new -> rebind =
TIME_MAX;
1682 client->new->medium);
1683 if (client->active && client->state !=
S_REBOOTING)
1700 log_info(
"Unable to obtain a lease on first "
1701 "try (declined). Exiting.");
1711 if (!client->last_write ||
1718 client->active = client->new;
1722 tv.tv_sec = client->active->renewal;
1723 tv.tv_usec = ((client->active->renewal -
cur_tv.tv_sec) > 1) ?
1724 random() % 1000000 :
cur_tv.tv_usec;
1727 log_info(
"bound to %s -- renewal in %ld seconds.",
1728 piaddr(client->active->address),
1729 (
long)(client->active->renewal -
cur_time));
1733 #if defined (NSUPDATE)
1734 if (client->config->do_forward_update)
1755 client -> xid = client ->
packet.xid;
1757 memset (&ds, 0,
sizeof ds);
1763 client -> active -> options,
1766 memcpy (client -> destination.iabuf, ds.
data, 4);
1767 client -> destination.len = 4;
1775 client -> first_sending =
cur_time;
1776 client -> interval = client -> config -> initial_interval;
1837 for (ap = packet -> interface -> client -> config -> reject_list;
1838 ap; ap = ap ->
next) {
1847 log_info(
"BOOTREPLY from %s rejected by rule %s "
1848 "mask %s.",
piaddr(packet->client_addr),
1862 void (*handler) (
struct packet *);
1889 for (ap = packet ->
interface -> client -> config -> reject_list;
1890 ap; ap = ap -> next) {
1899 log_info(
"%s from %s rejected by rule %s mask %s.",
1900 type,
piaddr(packet->client_addr),
1905 (*handler) (packet);
1913 char addrbuf[
sizeof(
"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")];
1921 ap ; ap = ap->
next) {
1924 log_info(
"%s from %s rejected by rule %s",
1940 log_info(
"RCV: %s message on %s from %s.",
1951 client = client->
next) {
1960 log_info(
"Packet received, but nothing done with it.");
1965 struct packet *packet;
1973 const char *
name = packet -> packet_type ?
"DHCPOFFER" :
"BOOTREPLY";
1982 for (client = ip -> client; client; client = client -> next)
1983 if (client -> xid == packet -> raw -> xid)
1990 (packet -> interface -> hw_address.hlen - 1 !=
1991 packet -> raw -> hlen) ||
1992 (memcmp (&packet -> interface -> hw_address.hbuf [1],
1993 packet -> raw -> chaddr, packet -> raw -> hlen))) {
1995 log_debug (
"%s in wrong transaction.", name);
2000 sprintf (obuf,
"%s from %s", name,
piaddr (packet -> client_addr));
2008 for (i = 0 ; req[i] != NULL ; i++) {
2015 option_code_hash_lookup(&option,
2020 log_info(
"%s: no %s option.", obuf,
2023 log_info(
"%s: no unknown-%u option.",
2034 for (lease = client -> offered_leases; lease; lease = lease -> next) {
2035 if (lease -> address.len ==
sizeof packet -> raw -> yiaddr &&
2036 !memcmp (lease -> address.iabuf,
2037 &packet -> raw -> yiaddr, lease -> address.len)) {
2045 log_info (
"%s: packet_to_lease failed.", obuf);
2051 if (!packet -> options_valid || !packet -> packet_type)
2052 lease -> is_bootp = 1;
2055 lease -> medium = client -> medium;
2058 stop_selecting = (client -> first_sending +
2059 client -> config -> select_interval);
2063 if (lease -> address.len == client -> requested_address.len &&
2064 !memcmp (lease -> address.iabuf,
2065 client -> requested_address.iabuf,
2066 client -> requested_address.len)) {
2067 lease -> next = client -> offered_leases;
2068 client -> offered_leases = lease;
2072 if (!client -> offered_leases)
2073 client -> offered_leases = lease;
2075 for (lp = client -> offered_leases; lp ->
next;
2085 if (stop_selecting <=
cur_tv.tv_sec)
2088 tv.tv_sec = stop_selecting;
2089 tv.tv_usec =
cur_tv.tv_usec;
2100 struct packet *packet;
2112 log_error(
"packet_to_lease: no memory to record lease.\n");
2116 memset(lease, 0,
sizeof(*lease));
2121 lease->address.len =
sizeof(packet->raw->yiaddr);
2122 memcpy(lease->address.iabuf, &packet->raw->yiaddr,
2123 lease->address.len);
2125 lease->next_srv_addr.len =
sizeof(packet->raw->siaddr);
2126 memcpy(lease->next_srv_addr.iabuf, &packet->raw->siaddr,
2127 lease->next_srv_addr.len);
2129 memset(&data, 0,
sizeof(data));
2131 if (client -> config -> vendor_space_name) {
2137 client -> config -> vendor_space_name &&
2139 (
struct lease *)0, client,
2143 if (!option_code_hash_lookup(&option,
2147 "option (%s:%d).",
MDL);
2151 client -> config -> vendor_space_name
2177 if (!(i & 2) && packet -> raw -> sname [0]) {
2181 if (!packet -> raw -> sname [len])
2185 log_error (
"dhcpoffer: no memory for server name.\n");
2190 packet -> raw -> sname, len);
2196 if (!(i & 1) && packet -> raw ->
file [0]) {
2200 if (!packet -> raw ->
file [len])
2204 log_error (
"dhcpoffer: no memory for filename.\n");
2209 packet -> raw ->
file, len);
2215 client, lease->options, lease->options,
2223 struct packet *packet;
2229 for (client = ip -> client; client; client = client ->
next)
2230 if (client ->
xid == packet -> raw ->
xid)
2236 (packet ->
interface -> hw_address.hlen - 1 !=
2237 packet -> raw -> hlen) ||
2238 (memcmp (&packet ->
interface -> hw_address.hbuf [1],
2239 packet -> raw -> chaddr, packet -> raw -> hlen))) {
2241 log_debug (
"DHCPNAK in wrong transaction.");
2256 log_info (
"DHCPNAK from %s (xid=0x%x)",
piaddr (packet -> client_addr), client ->
xid);
2260 log_info (
"DHCPNAK with no active lease.\n");
2293 client -> state =
S_INIT;
2312 interval =
cur_time - client -> first_sending;
2316 if (interval > client -> config ->
timeout) {
2324 if (!client -> offered_leases &&
2325 client -> config -> media) {
2328 if (client -> medium) {
2329 client -> medium = client -> medium -> next;
2332 if (!client -> medium) {
2334 log_fatal (
"No valid media types for %s!",
2335 client -> interface -> name);
2337 client -> config -> media;
2341 log_info (
"Trying medium \"%s\" %d",
2342 client -> medium ->
string, increase);
2370 if (
cur_time + client -> interval >
2371 client -> first_sending + client -> config ->
timeout)
2372 client -> interval =
2373 (client -> first_sending +
2377 if (interval < 65536)
2378 client -> packet.secs = htons (interval);
2380 client -> packet.secs = htons (65535);
2381 client -> secs = client -> packet.secs;
2383 log_info (
"DHCPDISCOVER on %s to %s port %d interval %ld (xid=0x%x)",
2384 client -> name ? client -> name : client -> interface -> name,
2393 log_error(
"%s:%d: Failed to send %d byte long packet over %s "
2405 tv.tv_usec = client->
interval > 1 ? random() % 1000000 :
cur_tv.tv_usec;
2422 loop = lp = client -> active;
2424 log_info (
"No DHCPOFFERS received.");
2428 if (!client -> active && client -> leases)
2432 while (client -> active) {
2433 if (client -> active -> expiry >
cur_time) {
2434 log_info (
"Trying recorded lease %s",
2435 piaddr (client -> active -> address));
2439 client -> active -> medium);
2442 if (client -> alias)
2450 if (cur_time < client -> active -> renewal) {
2452 log_info (
"bound: renewal in %ld %s.",
2453 (
long)(client -> active -> renewal -
2458 random() % 1000000 :
2463 log_info (
"bound: immediate renewal.");
2473 if (!client -> leases) {
2474 client -> leases = client -> active;
2482 for (lp = client -> leases; lp ->
next; lp = lp ->
next)
2484 lp ->
next = client -> active;
2488 client -> active = client -> leases;
2489 client -> leases = client -> leases ->
next;
2494 if (client -> active == loop)
2497 loop = client -> active;
2505 log_info (
"Unable to obtain a lease on first try.%s",
2510 log_info (
"No working leases in persistent database - sleeping.");
2512 if (client -> alias)
2515 client -> state =
S_INIT;
2518 tv.tv_usec = ((tv.tv_sec -
cur_tv.tv_sec) > 1) ?
2519 random() % 1000000 :
cur_tv.tv_usec;
2531 struct sockaddr_in destination;
2532 struct in_addr from;
2536 interval =
cur_time - client -> first_sending;
2550 interval > client -> config -> reboot_timeout) {
2552 client -> state =
S_INIT;
2561 !client -> medium &&
2562 client -> active -> medium ) {
2563 script_init (client,
"MEDIUM", client -> active -> medium);
2570 client -> medium = client -> active -> medium;
2576 cur_time > client -> active -> expiry) {
2581 if (client -> alias)
2589 if (client -> alias)
2594 client -> state =
S_INIT;
2600 if (!client -> interval)
2601 client -> interval = client -> config -> initial_interval;
2603 client -> interval += ((random () >> 2) %
2604 (2 * client -> interval));
2608 if (client -> interval >
2609 client -> config -> backoff_cutoff)
2610 client -> interval =
2611 ((client -> config -> backoff_cutoff / 2)
2612 + ((random () >> 2) %
2613 client -> config -> backoff_cutoff));
2618 cur_time + client -> interval > client -> active -> expiry)
2619 client -> interval =
2620 client -> active -> expiry -
cur_time + 1;
2626 cur_time > client -> active -> rebind)
2629 memcpy (&destination.sin_addr.s_addr,
2630 client -> destination.iabuf,
2631 sizeof destination.sin_addr.s_addr);
2633 destination.sin_family = AF_INET;
2635 destination.sin_len =
sizeof destination;
2640 memcpy (&from, client -> active -> address.iabuf,
2643 from.s_addr = INADDR_ANY;
2647 client -> packet.secs = client -> secs;
2649 if (interval < 65536)
2650 client -> packet.secs = htons (interval);
2652 client -> packet.secs = htons (65535);
2655 log_info (
"DHCPREQUEST on %s to %s port %d (xid=0x%x)",
2656 client -> name ? client -> name : client -> interface -> name,
2657 inet_ntoa (destination.sin_addr),
2658 ntohs (destination.sin_port), client -> xid);
2660 if (destination.sin_addr.s_addr != INADDR_BROADCAST &&
2666 log_error(
"%s:%d: Failed to send %d byte long packet "
2667 "over %s interface.",
MDL,
2678 log_error(
"%s:%d: Failed to send %d byte long packet"
2679 " over %s interface.",
MDL,
2686 tv.tv_usec = ((tv.tv_sec -
cur_tv.tv_sec) > 1) ?
2687 random() % 1000000 :
cur_tv.tv_usec;
2698 log_info (
"DHCPDECLINE on %s to %s port %d (xid=0x%x)",
2708 log_error(
"%s:%d: Failed to send %d byte long packet over %s"
2720 struct sockaddr_in destination;
2721 struct in_addr from;
2723 memcpy (&from, client -> active -> address.iabuf,
2725 memcpy (&destination.sin_addr.s_addr,
2726 client -> destination.iabuf,
2727 sizeof destination.sin_addr.s_addr);
2729 destination.sin_family = AF_INET;
2731 destination.sin_len =
sizeof destination;
2736 client -> active -> expiry =
2737 client -> active -> renewal =
2738 client -> active -> rebind =
cur_time;
2740 log_error (
"Can't release lease: lease write failed.");
2744 log_info (
"DHCPRELEASE on %s to %s port %d (xid=0x%x)",
2745 client -> name ? client -> name : client -> interface -> name,
2746 inet_ntoa (destination.sin_addr),
2747 ntohs (destination.sin_port), client -> xid);
2754 log_error(
"%s:%d: Failed to send %d byte long packet"
2755 " over %s interface.",
MDL,
2765 log_error (
"%s:%d: Failed to send %d byte long packet"
2766 " over %s interface.",
MDL,
2783 struct buffer *bp = NULL;
2806 log_error (
"can't make requested address cache.");
2832 for (i = 0 ; prl[i] != NULL ; i++)
2837 log_error(
"can't make parameter list buffer.");
2842 for (i = 0 ; prl[i] != NULL ; i++)
2846 if (!(option_code_hash_lookup(&option,
2871 memset(&client_identifier, 0,
sizeof(client_identifier));
2874 client_identifier.
len,
MDL))
2875 log_fatal(
"no memory for default DUID!");
2893 memcpy(&client_identifier.
buffer->
data + 5 - hw_len,
2898 memcpy(&client_identifier.
buffer->
data+(1+4),
2905 (u_int8_t *)client_identifier.
data,
2906 client_identifier.
len,
2908 log_error (
"can't make requested client id cache..");
2919 (lease ? lease->
options : NULL),
2932 memset (&client -> packet, 0,
sizeof (client -> packet));
2936 lease ? &lease -> address : (
struct iaddr *)0,
2937 client -> config -> requested_options,
2941 client -> packet_length =
2943 (
struct lease *)0, client,
2952 client -> config -> vendor_space_name);
2959 client -> packet.htype = client ->
interface -> hw_address.hbuf [0];
2960 client -> packet.hlen = client ->
interface -> hw_address.hlen - 1;
2961 client -> packet.hops = 0;
2962 client -> packet.xid = random ();
2963 client -> packet.secs = 0;
2967 client -> packet.flags = 0;
2971 memset (&(client -> packet.ciaddr),
2972 0,
sizeof client -> packet.ciaddr);
2973 memset (&(client -> packet.yiaddr),
2974 0,
sizeof client -> packet.yiaddr);
2975 memset (&(client -> packet.siaddr),
2976 0,
sizeof client -> packet.siaddr);
2977 client -> packet.giaddr =
giaddr;
2978 if (client -> interface -> hw_address.hlen > 0)
2979 memcpy (client -> packet.chaddr,
2980 &client -> interface -> hw_address.hbuf [1],
2981 (
unsigned)(client -> interface -> hw_address.hlen - 1));
2984 dump_raw ((
unsigned char *)&client -> packet, client -> packet_length);
2996 memset (&client -> packet, 0,
sizeof (client -> packet));
3004 if (client -> sent_options)
3011 : (
struct iaddr *)0),
3012 client -> config -> requested_options,
3013 &client -> sent_options);
3016 client -> packet_length =
3018 (
struct lease *)0, client,
3021 client -> sent_options,
3027 client -> config -> vendor_space_name);
3033 client -> packet.htype = client ->
interface -> hw_address.hbuf [0];
3034 client -> packet.hlen = client ->
interface -> hw_address.hlen - 1;
3035 client -> packet.hops = 0;
3036 client -> packet.xid = client -> xid;
3037 client -> packet.secs = 0;
3041 if (client -> state ==
S_BOUND ||
3044 memcpy (&client -> packet.ciaddr,
3045 lease -> address.iabuf, lease -> address.len);
3046 client -> packet.flags = 0;
3048 memset (&client -> packet.ciaddr, 0,
3049 sizeof client -> packet.ciaddr);
3051 client ->config->bootp_broadcast_always)) &&
3053 client -> packet.flags = 0;
3058 memset (&client -> packet.yiaddr, 0,
3059 sizeof client -> packet.yiaddr);
3060 memset (&client -> packet.siaddr, 0,
3061 sizeof client -> packet.siaddr);
3062 if (client -> state !=
S_BOUND &&
3064 client -> packet.giaddr =
giaddr;
3066 memset (&client -> packet.giaddr, 0,
3067 sizeof client -> packet.giaddr);
3068 if (client -> interface -> hw_address.hlen > 0)
3069 memcpy (client -> packet.chaddr,
3070 &client -> interface -> hw_address.hbuf [1],
3071 (
unsigned)(client -> interface -> hw_address.hlen - 1));
3074 dump_raw ((
unsigned char *)&client -> packet, client -> packet_length);
3094 memset (&client -> packet, 0,
sizeof (client -> packet));
3095 client -> packet_length =
3097 (
struct lease *)0, client, 0,
3100 client -> config -> vendor_space_name);
3109 client -> packet.htype = client ->
interface -> hw_address.hbuf [0];
3110 client -> packet.hlen = client ->
interface -> hw_address.hlen - 1;
3111 client -> packet.hops = 0;
3112 client -> packet.xid = client -> xid;
3113 client -> packet.secs = 0;
3116 client -> packet.flags = 0;
3121 memset (&client -> packet.ciaddr, 0,
3122 sizeof client -> packet.ciaddr);
3123 memset (&client -> packet.yiaddr, 0,
3124 sizeof client -> packet.yiaddr);
3125 memset (&client -> packet.siaddr, 0,
3126 sizeof client -> packet.siaddr);
3127 client -> packet.giaddr =
giaddr;
3128 memcpy (client -> packet.chaddr,
3129 &client -> interface -> hw_address.hbuf [1],
3130 client -> interface -> hw_address.hlen);
3133 dump_raw ((
unsigned char *)&client -> packet, client -> packet_length);
3146 memset (&client -> packet, 0,
sizeof (client -> packet));
3153 client -> packet_length =
3155 (
struct lease *)0, client,
3164 client -> config -> vendor_space_name);
3171 client -> packet.htype = client ->
interface -> hw_address.hbuf [0];
3172 client -> packet.hlen = client ->
interface -> hw_address.hlen - 1;
3173 client -> packet.hops = 0;
3174 client -> packet.xid = random ();
3175 client -> packet.secs = 0;
3176 client -> packet.flags = 0;
3177 memcpy (&client -> packet.ciaddr,
3178 lease -> address.iabuf, lease -> address.len);
3179 memset (&client -> packet.yiaddr, 0,
3180 sizeof client -> packet.yiaddr);
3181 memset (&client -> packet.siaddr, 0,
3182 sizeof client -> packet.siaddr);
3183 client -> packet.giaddr =
giaddr;
3184 memcpy (client -> packet.chaddr,
3185 &client -> interface -> hw_address.hbuf [1],
3186 client -> interface -> hw_address.hlen);
3189 dump_raw ((
unsigned char *)&client -> packet, client -> packet_length);
3196 if (lease -> server_name)
3198 if (lease -> filename)
3213 if (leaseFile != NULL)
3216 if (leaseFile == NULL) {
3228 for (client = ip -> client; client; client = client ->
next) {
3229 for (lp = client -> leases; lp; lp = lp ->
next) {
3232 if (client -> active)
3234 client -> active, 1, 0);
3249 for (client = ip -> client; client; client = client ->
next) {
3250 for (lp = client -> leases; lp; lp = lp ->
next) {
3253 if (client -> active)
3255 client -> active, 1, 0);
3277 const char *name, *dot;
3279 char *preamble = stuff;
3281 memset (&ds, 0,
sizeof ds);
3291 in_options, cfg_options, scope, oc,
MDL)) {
3293 fprintf(leaseFile,
"%soption %s%s%s", preamble,
3299 fprintf(leaseFile,
" %s",
3305 fprintf(leaseFile,
";\n");
3314 const char *preamble)
3355 log_debug(
"Cannot form default DUID from interface %s.", ip->
name);
3359 return ISC_R_UNEXPECTED;
3364 log_fatal(
"Impossible hardware address length at %s:%d.",
MDL);
3381 len = 4 + (hlen - 1);
3385 log_fatal(
"no memory for default DUID!");
3411 return ISC_R_SUCCESS;
3421 if ((duid == NULL) || (duid->
len <= 2))
3424 if (leaseFile == NULL) {
3426 if (leaseFile == NULL) {
3428 return ISC_R_IOERROR;
3439 return ISC_R_NOMEMORY;
3441 stat = fprintf(leaseFile,
"default-duid \"%s\";\n", str);
3444 return ISC_R_IOERROR;
3446 if (fflush(leaseFile) != 0)
3447 return ISC_R_IOERROR;
3449 return ISC_R_SUCCESS;
3455 int rewrite,
int sync)
3463 if (!rewrite && (leases_written++ > 20)) {
3466 return ISC_R_SUCCESS;
3469 if (client == NULL || lease == NULL)
3472 if (leaseFile == NULL) {
3474 if (leaseFile == NULL) {
3476 return ISC_R_IOERROR;
3480 stat = fprintf(leaseFile,
"lease6 {\n");
3482 return ISC_R_IOERROR;
3484 stat = fprintf(leaseFile,
" interface \"%s\";\n",
3487 return ISC_R_IOERROR;
3489 for (ia = lease->
bindings ; ia != NULL ; ia = ia->
next) {
3502 stat = fprintf(leaseFile,
" %s %s {\n",
3505 return ISC_R_IOERROR;
3508 stat = fprintf(leaseFile,
" starts %d;\n"
3513 stat = fprintf(leaseFile,
" starts %d;\n",
3516 return ISC_R_IOERROR;
3518 for (addr = ia->
addrs ; addr != NULL ; addr = addr->
next) {
3520 stat = fprintf(leaseFile,
3524 stat = fprintf(leaseFile,
3525 " iaprefix %s/%d {\n",
3529 return ISC_R_IOERROR;
3531 stat = fprintf(leaseFile,
" starts %d;\n"
3532 " preferred-life %u;\n"
3537 return ISC_R_IOERROR;
3540 write_options(client, addr->
options,
" ");
3542 stat = fprintf(leaseFile,
" }\n");
3544 return ISC_R_IOERROR;
3548 write_options(client, ia->
options,
" ");
3550 stat = fprintf(leaseFile,
" }\n");
3552 return ISC_R_IOERROR;
3556 stat = fprintf(leaseFile,
" released;\n");
3558 return ISC_R_IOERROR;
3562 write_options(client, lease->
options,
" ");
3564 stat = fprintf(leaseFile,
"}\n");
3566 return ISC_R_IOERROR;
3568 if (fflush(leaseFile) != 0)
3569 return ISC_R_IOERROR;
3572 if (fsync(fileno(leaseFile)) < 0) {
3573 log_error(
"write_client_lease: fsync(): %m");
3574 return ISC_R_IOERROR;
3578 return ISC_R_SUCCESS;
3593 if (leases_written++ > 20) {
3601 if (lease -> is_static)
3604 if (leaseFile == NULL) {
3606 if (leaseFile == NULL) {
3613 fprintf (leaseFile,
"lease {\n");
3614 if (lease -> is_bootp) {
3615 fprintf (leaseFile,
" bootp;\n");
3621 fprintf (leaseFile,
" interface \"%s\";\n",
3622 client -> interface -> name);
3627 if (client -> name) {
3628 fprintf (leaseFile,
" name \"%s\";\n", client -> name);
3634 fprintf (leaseFile,
" fixed-address %s;\n",
3635 piaddr (lease -> address));
3640 if (lease -> filename) {
3643 fprintf (leaseFile,
" filename \"%s\";\n", s);
3656 fprintf(leaseFile,
" server-name \"%s\";\n", s);
3665 if (lease -> medium) {
3668 fprintf (leaseFile,
" medium \"%s\";\n", s);
3682 memset (&ds, 0,
sizeof ds);
3684 write_options(client, lease->
options,
" ");
3688 fprintf(leaseFile,
" renew %s\n", tval) < 0)
3693 fprintf(leaseFile,
" rebind %s\n", tval) < 0)
3698 fprintf(leaseFile,
" expire %s\n", tval) < 0)
3701 if (fprintf(leaseFile,
"}\n") < 0)
3704 if (fflush(leaseFile) != 0)
3709 if (!errors && makesure) {
3710 if (fsync (fileno (leaseFile)) < 0) {
3711 log_info (
"write_client_lease: %m");
3716 return errors ? 0 : 1;
3733 for (sl = client -> env; sl; sl =
next) {
3740 if (client -> interface) {
3742 client -> interface -> name);
3746 "",
"client",
"%s", client -> name);
3749 "",
"medium",
"%s", medium ->
string);
3752 client_envadd (client,
"",
"pid",
"%ld", (
long int)getpid ());
3766 memset (&data, 0,
sizeof data);
3769 in_options, cfg_options, scope, oc,
MDL)) {
3779 length = strlen(value);
3783 value, length) == 0) {
3788 "option - discarded",
3811 prefix,
"ip_address",
"%s",
piaddr (lease -> address));
3827 memset (&data, 0,
sizeof data);
3830 (
struct lease *)0, client,
3835 struct iaddr netmask, subnet, broadcast;
3858 (&data, (
struct packet *)0,
3859 (
struct lease *)0, client,
3864 if (broadcast.
len) {
3866 prefix,
"broadcast_address",
3867 "%s",
piaddr (broadcast));
3883 "option - discarded",
3896 "option - discarded",
3908 client_envadd (client, prefix,
"expiry",
"%d", (
int)(lease -> expiry));
3923 req = client->config->requested_options;
3928 for (i = 0 ; req[i] != NULL ; i++) {
3942 char reason [] =
"REASON=NBI";
3943 static char client_path [] = CLIENT_PATH;
3946 int pid, wpid, wstatus;
3949 scriptName = client -> config -> script_name;
3953 envp =
dmalloc (((client ? client -> envc : 2) +
3956 log_error (
"No memory for client script environment.");
3962 for (sp = client_env; sp; sp = sp ->
next) {
3963 envp [i++] = sp ->
string;
3967 for (sp = client -> env; sp; sp = sp ->
next) {
3968 envp [i++] = sp ->
string;
3971 envp [i++] = reason;
3974 envp [i++] = client_path;
3975 envp [i] = (
char *)0;
3978 argv [1] = (
char *)0;
3986 wpid = wait (&wstatus);
3987 }
while (wpid != pid && wpid > 0);
3996 if (leaseFile != NULL)
3998 execve (scriptName, argv, envp);
3999 log_error (
"execve (%s, ...): %m", scriptName);
4004 for (sp = client -> env; sp; sp =
next) {
4012 gettimeofday(&
cur_tv, NULL);
4013 return (WIFEXITED (wstatus) ?
4014 WEXITSTATUS (wstatus) : -WTERMSIG (wstatus));
4018 const char *prefix,
const char *name,
const char *fmt, ...)
4026 va_start (list, fmt);
4027 len = vsnprintf (spbuf,
sizeof spbuf, fmt, list);
4030 val =
dmalloc (strlen (prefix) + strlen (name) + 1 +
4031 len +
sizeof *val,
MDL);
4039 if (len >=
sizeof spbuf) {
4040 va_start (list, fmt);
4041 vsnprintf (s, len + 1, fmt, list);
4045 val ->
next = client -> env;
4046 client -> env = val;
4069 if (j + 1 == buflen)
4079 if (j + 1 == buflen)
4092 static int state = 0;
4110 if ((pid = fork ()) < 0)
4123 (void) open(
"/dev/null", O_RDWR | O_CLOEXEC);
4124 (void) open(
"/dev/null", O_RDWR | O_CLOEXEC);
4125 (void) open(
"/dev/null", O_RDWR | O_CLOEXEC);
4142 pfdesc = open (
path_dhclient_pid, O_CREAT | O_TRUNC | O_WRONLY | O_CLOEXEC, 0644);
4149 pf = fdopen (pfdesc,
"we");
4154 fprintf (pf,
"%ld\n", (
long)getpid ());
4165 for (client = ip -> client; client; client = client ->
next) {
4166 switch (client ->
state) {
4200 client -> xid = random ();
4203 if (client -> active) {
4208 memset (&ds, 0,
sizeof ds);
4210 client -> active -> options,
4214 (
struct lease *)0, client,
4216 client -> active -> options,
4219 memcpy (client -> destination.iabuf,
4221 client -> destination.len = 4;
4228 client -> first_sending =
cur_time;
4229 client -> interval = client -> config -> initial_interval;
4240 if (client -> alias)
4270 if (!strcmp (ip ->
name, tmp ->
name)) {
4274 interface_reference (&ip, last ->
next,
MDL);
4275 interface_dereference (&last ->
next,
MDL);
4277 interface_reference (&last ->
next,
4279 interface_dereference (&ip ->
next,
4284 interface_reference (&ip,
4290 interface_dereference (&ip ->
next,
4296 tmp -> client = ip ->
client;
4297 tmp -> client ->
interface = tmp;
4299 interface_dereference (&ip,
MDL);
4334 if (ip -> client ->
alias)
4336 ip -> client ->
alias);
4348 for (client = ip->
client ; client ; client = client->
next) {
4353 return ISC_R_SUCCESS;
4360 struct packet *packet;
4379 static void shutdown_exit (
void *foo)
4387 #if defined (NSUPDATE)
4404 isc_result_t eresult)
4407 isc_result_t result;
4409 if ((eresult == ISC_R_SUCCESS) &&
4415 if (result == ISC_R_SUCCESS) {
4430 isc_result_t result;
4433 if (client->
ddns_cb != NULL) {
4439 if (ddns_cb != NULL) {
4445 ddns_cb->
cur_func = client_dns_remove_action;
4449 if (result != ISC_R_TIMEDOUT) {
4466 return ISC_R_SUCCESS;
4470 log_info(
"Received signal %d, initiating shutdown.",
4479 for (client = ip -> client; client; client = client -> next) {
4482 return ISC_R_SUCCESS;
4485 return ISC_R_SUCCESS;
4488 if (client -> active &&
4489 client -> active -> expiry >
cur_time) {
4490 #if defined (NSUPDATE)
4512 tv.tv_sec =
cur_tv.tv_sec;
4513 tv.tv_usec =
cur_tv.tv_usec + 1;
4516 return ISC_R_SUCCESS;
4519 #if defined (NSUPDATE)
4530 isc_result_t status = ISC_R_FAILURE;
4532 if ((client != NULL) &&
4533 ((client->
active != NULL) ||
4546 if (status != ISC_R_TIMEDOUT) {
4547 if (client != NULL) {
4585 isc_result_t eresult)
4587 isc_result_t result;
4604 ddns_cb->
cur_func = client_dns_update_action;
4607 if (result == ISC_R_SUCCESS) {
4613 case ISC_R_TIMEDOUT:
4621 if (ddns_cb->
zone != NULL) {
4627 ddns_cb->
cur_func = client_dns_update_action;
4633 tv.tv_usec =
cur_tv.tv_usec;
4635 ddns_cb, NULL, NULL);
4657 if (!client -> sent_options)
4658 return ISC_R_SUCCESS;
4662 return ISC_R_SUCCESS;
4668 (
struct lease *)0, client,
4669 client -> sent_options,
4672 return ISC_R_SUCCESS;
4679 (
struct lease *)0, client,
4680 client -> sent_options,
4683 return ISC_R_SUCCESS;
4689 (
struct lease *)0, client,
4690 client -> sent_options,
4693 return ISC_R_SUCCESS;
4705 memset(&client_identifier, 0,
sizeof(client_identifier));
4729 client_identifier.data,
4730 client_identifier.len);
4748 (client_identifier.data[0] == 255)) {
4753 if (client_identifier.len <= 5)
4754 log_fatal(
"Impossible condition at %s:%d.",
4757 client_identifier.data + 5,
4758 client_identifier.len - 5);
4760 result =
get_dhcid(ddns_cb, ddns_v4_type,
4761 client_identifier.data,
4762 client_identifier.len);
4772 return ISC_R_SUCCESS;
4781 rcode = ISC_R_FAILURE;
4787 if (rcode == ISC_R_SUCCESS) {
4788 rcode = ISC_R_TIMEDOUT;
4811 if (client->
ddns_cb != NULL) {
4818 if (ddns_cb != NULL) {
4819 ddns_cb->
lease = (
void *)client;
4832 ddns_cb->
cur_func = client_dns_update_action;
4837 tv.tv_sec =
cur_tv.tv_sec + offset;
4838 tv.tv_usec =
cur_tv.tv_usec;
4840 ddns_cb, NULL, NULL);
4842 log_error(
"Unable to allocate dns update state for %s",
4851 struct servent *ent;
4865 ent = getservbyname(
"dhcpc",
"udp");
4867 ent = getservbyname(
"bootpc",
"udp");
4872 #ifndef __CYGWIN32__
4896 static int check_domain_name(
const char *ptr,
size_t len,
int dots)
4901 if ((len == 0) || (len > 256))
4906 for (p=ptr; (*p != 0) && (len-- > 0); p++) {
4907 if ((*p ==
'-') || (*p ==
'_')) {
4909 if (((p - ptr) == 0) || (len == 0) || (p[1] ==
'.'))
4911 }
else if (*p ==
'.') {
4915 if ((d <= 0) || (d >= 64))
4918 if ((dots > 0) && (len > 0))
4920 }
else if (isalnum((
unsigned char)*p) == 0) {
4925 return(dots ? -1 : 0);
4928 static int check_domain_name_list(
const char *ptr,
size_t len,
int dots)
4933 if ((ptr == NULL) || (len == 0))
4936 for (p=ptr; (*p != 0) && (len > 0); p++, len--) {
4940 if (check_domain_name(ptr, p - ptr, dots) != 0)
4947 return(check_domain_name(ptr, p - ptr, dots));
4964 #ifdef ACCEPT_LIST_IN_DOMAIN_NAME
4965 return check_domain_name_list(ptr, len, 0);
4967 return check_domain_name(ptr, len, 0);
4972 return check_domain_name(ptr, len, 0);
4975 return check_domain_name_list(ptr, len, 0);
4980 for (; (*ptr != 0) && (len-- > 0); ptr++) {
4981 if(!(isalnum((
unsigned char)*ptr) ||
4982 *ptr ==
'#' || *ptr ==
'%' ||
4983 *ptr ==
'+' || *ptr ==
'-' ||
4984 *ptr ==
'_' || *ptr ==
':' ||
4985 *ptr ==
'.' || *ptr ==
',' ||
4986 *ptr ==
'@' || *ptr ==
'~' ||
4987 *ptr ==
'\\' || *ptr ==
'/' ||
4988 *ptr ==
'[' || *ptr ==
']' ||
4989 *ptr ==
'=' || *ptr ==
' '))
5004 return check_domain_name_list(ptr, len, 0);
5014 add_reject(
struct packet *packet) {
5019 log_fatal (
"no memory for reject list!");
5038 log_info(
"Server added to list of rejected servers.");
void do_packet6(struct interface_info *, const char *, int, int, const struct iaddr *, isc_boolean_t)
void state_selecting(void *cpp)
#define _PATH_DHCLIENT_CONF
void send_discover(void *cpp)
struct client_lease * alias
int parse_encapsulated_suboptions(struct option_state *options, struct option *eopt, const unsigned char *buffer, unsigned len, struct universe *eu, const char *uname)
isc_result_t omapi_protocol_listen(omapi_object_t *, unsigned, int)
struct binding_scope * global_scope
#define _PATH_DHCLIENT_PID
struct universe * universe
void(* dhcpv6_packet_handler)(struct interface_info *, const char *, int, int, const struct iaddr *, isc_boolean_t)
void make_client_options(struct client_state *client, struct client_lease *lease, u_int8_t *type, struct option_cache *sid, struct iaddr *rip, struct option **prl, struct option_state **op)
struct group * on_receipt
unsigned char dhcpv6_transaction_id[3]
#define _PATH_DHCLIENT_SCRIPT
void save_option(struct universe *universe, struct option_state *options, struct option_cache *oc)
char * quotify_buf(const unsigned char *s, unsigned len, const char *file, int line)
struct client_lease * new
void do_release(struct client_state *client)
const char * piaddr(const struct iaddr addr)
void rewrite_client_leases()
#define FQDN_NO_CLIENT_UPDATE
#define DHO_DOMAIN_SEARCH
#define DDNS_STATE_ADD_FW_NXDOMAIN
void dhcpoffer(struct packet *packet)
unsigned char dhcpv6_transaction_id[3]
int make_const_option_cache(struct option_cache **oc, struct buffer **buffer, u_int8_t *data, unsigned len, struct option *option, const char *file, int line)
void dhcpnak(struct packet *packet)
int get_dhcid(dhcp_ddns_cb_t *, int, const u_int8_t *, unsigned)
isc_result_t end_parse(struct parse **cfile)
const char * path_dhclient_db
isc_result_t(* dhcp_interface_startup_hook)(struct interface_info *)
int unbill_class(struct lease *lease, struct class *class)
void start_release6(struct client_state *client)
void * dmalloc(unsigned, const char *, int)
char * piaddrmask(struct iaddr *addr, struct iaddr *mask)
struct iaddr next_srv_addr
int option_cache_dereference(struct option_cache **ptr, const char *file, int line)
void start_info_request6(struct client_state *client)
void send_decline(void *cpp)
void client_dns_update_timeout(void *cp)
void cancel_timeout(void(*)(void *) where, void *what)
#define print_hex_1(len, data, limit)
#define DHO_DHCP_PARAMETER_REQUEST_LIST
int dhcp_max_agent_option_packet_length
struct client_lease * packet_to_lease(struct packet *packet, struct client_state *client)
#define DHCP_R_INVALIDARG
struct group * on_transmission
#define DISCOVER_REQUESTED
int script_go(struct client_state *client)
struct iaddr requested_address
const char * dhcpv6_type_names[]
int int int log_debug(const char *,...) __attribute__((__format__(__printf__
int write_client_lease(struct client_state *client, struct client_lease *lease, int rewrite, int makesure)
struct client_state * client
int can_receive_unicast_unconfigured(struct interface_info *)
struct iaddr iaddr_broadcast
void reinitialize_interfaces()
#define DHCPV6_RECONFIGURE
struct client_state * next
#define DHCP_CONTEXT_PRE_DB
#define DHO_DHCP_LEASE_TIME
void dhcpack(struct packet *packet)
unsigned cons_agent_information_options(struct option_state *cfg_options, struct dhcp_packet *outpacket, unsigned agentix, unsigned length)
struct universe dhcp_universe
struct option_state * options
dhcp_ddns_cb_t * ddns_cb_alloc(const char *file, int line)
void data_string_forget(struct data_string *data, const char *file, int line)
void bootp(struct packet *packet)
const char * pretty_print_option(struct option *option, const unsigned char *data, unsigned len, int emit_commas, int emit_quotes)
#define INTERFACE_RUNNING
void send_release(void *cpp)
int log_error(const char *,...) __attribute__((__format__(__printf__
struct string_list * client_env
#define DDNS_INCLUDE_RRSET
void client_envadd(struct client_state *client, const char *prefix, const char *name, const char *fmt,...)
void add_timeout(struct timeval *when, void(*)(void *) where, void *what, tvref_t ref, tvunref_t unref)
void dump_packet(struct packet *)
#define DDNS_STATE_REM_FW_YXDHCID
#define DHO_DHCP_REBINDING_TIME
#define DHO_NETBIOS_SCOPE
struct dhc6_ia * bindings
const char * path_dhclient_duid
enum dhcp_token peek_token(const char **rval, unsigned *rlen, struct parse *cfile)
int(* dhcp_interface_shutdown_hook)(struct interface_info *)
struct data_string fwd_name
void write_client_pid_file()
void state_panic(void *cpp)
void forget_zone(struct dns_zone **)
struct data_string default_duid
void ddns_cb_free(dhcp_ddns_cb_t *ddns_cb, const char *file, int line)
void do_packet(struct interface_info *interface, struct dhcp_packet *packet, unsigned len, unsigned int from_port, struct iaddr from, struct hardware *hfrom)
#define D6O_NIS_DOMAIN_NAME
unsigned char dhcpv6_msg_type
#define DHO_DHCP_SERVER_IDENTIFIER
void log_fatal(const char *,...) __attribute__((__format__(__printf__
#define DHCP_CONTEXT_POST_DB
isc_result_t form_duid(struct data_string *duid, const char *file, int line)
struct executable_statement * statements
void state_init(void *cpp)
#define INTERFACE_AUTOMATIC
int option_state_reference(struct option_state **ptr, struct option_state *bp, const char *file, int line)
const char * print_time(TIME t)
void read_client_leases()
struct option_state * options
struct iaddr subnet_number(struct iaddr addr, struct iaddr mask)
u_int16_t validate_port(char *port)
void dhcp_signal_handler(int signal)
int find_subnet(struct subnet **sp, struct iaddr addr, const char *file, int line)
void execute_statements_in_scope(struct binding_value **result, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *out_options, struct binding_scope **scope, struct group *group, struct group *limiting_group, struct on_star *on_star)
void make_request(struct client_state *client, struct client_lease *lease)
struct interface_info * fallback_interface
isc_result_t dhclient_interface_startup_hook(struct interface_info *interface)
int option_state_allocate(struct option_state **ptr, const char *file, int line)
const char * path_dhclient_pid
struct iaddrmatchlist * next
void client_option_envadd(struct option_cache *oc, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, struct universe *u, void *stuff)
isc_result_t dhcp_context_create(int flags, struct in_addr *local4, struct in6_addr *local6)
int evaluate_option_cache(struct data_string *result, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, struct option_cache *oc, const char *file, int line)
int write_host(struct host_decl *host)
struct option_state * options
struct option ** requested_options
void classify(struct packet *packet, struct class *class)
void script_init(struct client_state *client, const char *reason, struct string_list *medium)
#define DHCP_MAX_OPTION_LEN
int main(int argc, char **argv)
dns_rdataclass_t dhcid_class
void make_decline(struct client_state *client, struct client_lease *lease)
void bind_lease(struct client_state *client)
int buffer_allocate(struct buffer **ptr, unsigned len, const char *file, int line)
#define DHO_BROADCAST_ADDRESS
struct option_cache * option
struct interface_info * interface
int write_lease(struct lease *lease)
void putULong(unsigned char *, u_int32_t)
void(* bootp_packet_handler)(struct interface_info *, struct dhcp_packet *, unsigned, unsigned int, struct iaddr, struct hardware *)
void run_stateless(int exit_mode)
int(* dhcp_interface_discovery_hook)(struct interface_info *)
void send_request(void *cpp)
isc_result_t omapi_generic_new(omapi_object_t **, const char *, int)
#define D6O_DOMAIN_SEARCH
ssize_t send_packet(struct interface_info *, struct packet *, struct dhcp_packet *, size_t, struct in_addr, struct sockaddr_in *, struct hardware *)
int cons_options(struct packet *inpacket, struct dhcp_packet *outpacket, struct lease *lease, struct client_state *client_state, int mms, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, int overload_avail, int terminate, int bootpp, struct data_string *prl, const char *vuname)
void start_confirm6(struct client_state *client)
void dfree(void *, const char *, int)
isc_boolean_t no_pid_file
struct client_lease * next
void ddns_cancel(dhcp_ddns_cb_t *ddns_cb, const char *file, int line)
struct option_state * sent_options
const char * path_dhclient_conf
struct hardware hw_address
struct option_cache * lookup_option(struct universe *universe, struct option_state *options, unsigned code)
int dhclient_interface_discovery_hook(struct interface_info *tmp)
struct client_state * client
struct option_state * options
int asprintf(char **strp, const char *fmt,...)
int int log_info(const char *,...) __attribute__((__format__(__printf__
int bootp_broadcast_always
struct interface_info * interfaces
void free_client_lease(struct client_lease *lease, const char *file, int line)
#define _PATH_DHCLIENT_DB
u_int32_t getULong(const unsigned char *)
struct client_config top_level_config
struct iaddr broadcast_addr(struct iaddr subnet, struct iaddr mask)
struct option ** required_options
union executable_statement::@7 data
void state_reboot(void *cpp)
int check_collection(struct packet *packet, struct lease *lease, struct collection *collection)
void destroy_client_lease(struct client_lease *lease)
int parse_agent_information_option(struct packet *packet, int len, u_int8_t *data)
#define ASSERT_STATE(state_is, state_shouldbe)
char * path_dhclient_script
void parse_client_statement(struct parse *cfile, struct interface_info *ip, struct client_config *config)
struct universe ** universes
int quiet_interface_discovery
#define DISCOVER_UNCONFIGURED
struct client_lease * active
isc_result_t client_dns_update(struct client_state *client, dhcp_ddns_cb_t *ddns_cb)
int option_state_dereference(struct option_state **ptr, const char *file, int line)
void start_init6(struct client_state *client)
void option_space_foreach(struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, struct universe *u, void *stuff, void(*func)(struct option_cache *, struct packet *, struct lease *, struct client_state *, struct option_state *, struct option_state *, struct binding_scope **, struct universe *, void *))
void(* v6_handler)(struct packet *, struct client_state *)
void initialize_common_option_spaces()
void make_discover(struct client_state *client, struct client_lease *lease)
void dhcpv6(struct packet *)
void unconfigure6(struct client_state *client, const char *reason)
void client_dns_remove(struct client_state *client, struct iaddr *addr)
const int dhcpv6_type_name_max
int addr_match(struct iaddr *addr, struct iaddrmatch *match)
struct dhcp_packet packet
void state_bound(void *cpp)
struct interface_info * next
struct universe dhcpv6_universe
int evaluate_boolean_option_cache(int *ignorep, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, struct option_cache *oc, const char *file, int line)
void make_release(struct client_state *client, struct client_lease *lease)
struct string_list * next
isc_result_t read_client_conf()
struct interface_info * dummy_interfaces
isc_result_t find_class(struct class **c, const char *s, const char *file, int line)
void script_write_requested(struct client_state *client)
#define FQDN_SERVER_UPDATE
struct client_lease * new_client_lease(char *file, int line) const
#define DDNS_STATE_ADD_FW_YXDHCID
void dhcpv4_client_assignments(void)
void dump_raw(unsigned char *buf, unsigned len) const
void dhcpv6_client_assignments(void)
u_int8_t hbuf[HARDWARE_ADDR_LEN+1]
struct iaddrmatchlist * reject_list
struct string_list * medium
struct client_config * config
#define D6O_SIP_SERVERS_DNS
struct sockaddr_in sockaddr_broadcast
void dhclient_schedule_updates(struct client_state *client, struct iaddr *addr, int offset)
int dhcp_option_ev_name(char *buf, size_t buflen, struct option *option)
struct in_addr inaddr_any
struct universe fqdn_universe
void dhcp(struct packet *packet)
#define DHO_DHCP_OPTION_OVERLOAD
#define D6O_NISP_DOMAIN_NAME
option_code_hash_t * code_hash
#define DHO_DHCP_RENEWAL_TIME
struct string_list * medium
#define DHO_DHCP_CLIENT_IDENTIFIER
struct dhcp_ddns_cb * ddns_cb
void putUShort(unsigned char *, u_int32_t)
isc_result_t dhcp_set_control_state(control_object_state_t oldstate, control_object_state_t newstate)
char * quotify_string(const char *s, const char *file, int line)
const unsigned char * data
struct interface_info * interface
#define DHO_DHCP_MESSAGE_TYPE
void dhcp_common_objects_setup(void)
void write_lease_option(struct option_cache *oc, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, struct universe *u, void *stuff)
#define DDNS_STATE_REM_FW_NXRR
u_int32_t default_requested_options[]
void discover_interfaces(int state)
isc_result_t new_parse(struct parse **cfile, int file, char *inbuf, unsigned buflen, const char *name, int eolp)
struct dhc6_lease * active_lease
#define INTERFACE_REQUESTED
int dhclient_interface_shutdown_hook(struct interface_info *interface)
void script_write_params(struct client_state *client, const char *prefix, struct client_lease *lease)
int option_dereference(struct option **dest, const char *file, int line)
#define DHO_VENDOR_ENCAPSULATED_OPTIONS
void client_location_changed()
void state_stop(void *cpp)
isc_result_t omapi_init(void)
#define DHO_DHCP_REQUESTED_ADDRESS
int buffer_dereference(struct buffer **ptr, const char *file, int line)
isc_result_t ddns_modify_fwd(dhcp_ddns_cb_t *ddns_cb, const char *file, int line)
isc_result_t write_client6_lease(struct client_state *client, struct dhc6_lease *lease, int rewrite, int sync)
int bootp_broadcast_always