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-2015 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);
133 int release_mode = 0;
138 int no_dhclient_conf = 0;
139 int no_dhclient_db = 0;
140 int no_dhclient_pid = 0;
141 int no_dhclient_script = 0;
143 int local_family_set = 0;
146 char *dhcp_client_identifier_arg = NULL;
147 char *dhcp_host_name_arg = NULL;
148 char *dhcp_fqdn_arg = NULL;
149 char *dhcp_vendor_class_identifier_arg = NULL;
150 char *dhclient_request_options = NULL;
153 char *arg_conf = NULL;
154 int arg_conf_len = 0;
155 #ifdef HAVE_LIBCAP_NG
156 int keep_capabilities = 0;
165 fd = open(
"/dev/null", O_RDWR | O_CLOEXEC);
167 fd = open(
"/dev/null", O_RDWR | O_CLOEXEC);
169 fd = open(
"/dev/null", O_RDWR | O_CLOEXEC);
177 #if !(defined(DEBUG) || defined(__CYGWIN32__))
178 setlogmask(LOG_UPTO(LOG_INFO));
184 if (status != ISC_R_SUCCESS)
185 log_fatal(
"Can't initialize context: %s",
186 isc_result_totext(status));
190 if (status != ISC_R_SUCCESS)
192 isc_result_totext(status));
202 for (i = 1; i < argc; i++) {
203 if (!strcmp(argv[i],
"-r")) {
207 }
else if (!strcmp(argv[i],
"-4")) {
209 log_fatal(
"Client can only do v4 or v6, not "
211 local_family_set = 1;
213 }
else if (!strcmp(argv[i],
"-6")) {
215 log_fatal(
"Client can only do v4 or v6, not "
217 local_family_set = 1;
220 }
else if (!strcmp(argv[i],
"-x")) {
224 }
else if (!strcmp(argv[i],
"-p")) {
228 log_debug(
"binding to user-specified port %d",
230 }
else if (!strcmp(argv[i],
"-d")) {
233 }
else if (!strcmp(argv[i],
"-pf")) {
238 }
else if (!strcmp(argv[i],
"--no-pid")) {
240 }
else if (!strcmp(argv[i],
"-cf")) {
244 no_dhclient_conf = 1;
245 }
else if (!strcmp(argv[i],
"-df")) {
249 }
else if (!strcmp(argv[i],
"-lf")) {
254 }
else if (!strcmp(argv[i],
"-sf")) {
258 no_dhclient_script = 1;
259 }
else if (!strcmp(argv[i],
"-1")) {
261 }
else if (!strcmp(argv[i],
"-q")) {
263 }
else if (!strcmp(argv[i],
"-s")) {
267 }
else if (!strcmp(argv[i],
"-g")) {
271 }
else if (!strcmp(argv[i],
"-nw")) {
273 }
else if (!strcmp(argv[i],
"-n")) {
276 }
else if (!strcmp(argv[i],
"-w")) {
279 }
else if (!strcmp(argv[i],
"-e")) {
283 tmp =
dmalloc(strlen(argv[i]) +
sizeof *tmp,
MDL);
286 strcpy(tmp->
string, argv[i]);
291 }
else if (!strcmp(argv[i],
"-S")) {
295 local_family_set = 1;
299 }
else if (!strcmp(argv[i],
"-N")) {
303 local_family_set = 1;
309 }
else if (!strcmp(argv[i],
"-T")) {
313 local_family_set = 1;
319 }
else if (!strcmp(argv[i],
"-P")) {
323 local_family_set = 1;
330 }
else if (!strcmp(argv[i],
"-D")) {
334 if (!strcasecmp(argv[i],
"LL")) {
336 }
else if (!strcasecmp(argv[i],
"LLT")) {
341 }
else if (!strcmp(argv[i],
"-i")) {
344 }
else if (!strcmp(argv[i],
"-I")) {
347 }
else if (!strcmp(argv[i],
"-v")) {
349 }
else if (!strcmp(argv[i],
"--version")) {
350 const char vstring[] =
"isc-dhclient-";
358 }
else if (!strcmp(argv[i],
"-C")) {
359 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
369 dhcp_client_identifier_arg = argv[i];
370 }
else if (!strcmp(argv[i],
"-B")) {
372 }
else if (!strcmp(argv[i],
"-H")) {
373 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
383 if (dhcp_host_name_arg != NULL) {
384 log_error(
"The -H <host-name> and -F <fqdn> arguments are mutually exclusive");
388 dhcp_host_name_arg = argv[i];
389 }
else if (!strcmp(argv[i],
"-F")) {
390 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
400 if (dhcp_fqdn_arg != NULL) {
401 log_error(
"Only one -F <fqdn> argument can be specified");
405 if (dhcp_host_name_arg != NULL) {
406 log_error(
"The -F <fqdn> and -H <host-name> arguments are mutually exclusive");
410 dhcp_fqdn_arg = argv[i];
411 }
else if (!strcmp(argv[i],
"-timeout")) {
412 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
417 if ((timeout_arg = atoi(argv[i])) <= 0) {
418 log_error(
"timeout option must be > 0 - bad value: %s",argv[i]);
421 }
else if (!strcmp(argv[i],
"-V")) {
422 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
432 dhcp_vendor_class_identifier_arg = argv[i];
433 }
else if (!strcmp(argv[i],
"-R")) {
434 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
439 dhclient_request_options = argv[i];
440 }
else if (!strcmp(argv[i],
"-nc")) {
441 #ifdef HAVE_LIBCAP_NG
442 keep_capabilities = 1;
444 }
else if (argv[i][0] ==
'-') {
451 status = interface_allocate(&tmp,
MDL);
452 if (status != ISC_R_SUCCESS)
453 log_fatal(
"Can't record interface %s:%s",
454 argv[i], isc_result_totext(status));
455 if (strlen(argv[i]) >=
sizeof(tmp->
name))
456 log_fatal(
"%s: interface name too long (is %ld)",
457 argv[i], (
long)strlen(argv[i]));
458 strcpy(tmp->
name, argv[i]);
460 interface_reference(&tmp->
next,
479 if (!no_dhclient_conf && (s = getenv(
"PATH_DHCLIENT_CONF"))) {
482 if (!no_dhclient_db && (s = getenv(
"PATH_DHCLIENT_DB"))) {
485 if (!no_dhclient_pid && (s = getenv(
"PATH_DHCLIENT_PID"))) {
488 if (!no_dhclient_script && (s = getenv(
"PATH_DHCLIENT_SCRIPT"))) {
492 #ifdef HAVE_LIBCAP_NG
494 if (!keep_capabilities) {
495 capng_clear(CAPNG_SELECT_CAPS);
496 capng_update(CAPNG_ADD, CAPNG_EFFECTIVE|CAPNG_PERMITTED,
498 capng_updatev(CAPNG_ADD, CAPNG_EFFECTIVE|CAPNG_PERMITTED,
499 CAP_NET_ADMIN, CAP_NET_RAW,
500 CAP_NET_BIND_SERVICE, CAP_SYS_ADMIN, -1);
501 capng_apply(CAPNG_SELECT_CAPS);
526 log_fatal(
"Failed to get realpath for %s: %s", old_path, strerror(errno));
533 log_fatal(
"Failed to get realpath for %s: %s", old_path, strerror(errno));
542 if ((release_mode || exit_mode) && (
no_pid_file == ISC_FALSE)) {
549 e = fscanf(pidfd,
"%ld\n", &temp);
550 oldpid = (pid_t)temp;
552 if (e != 0 && e != EOF && oldpid) {
553 if (kill(oldpid, SIGTERM) == 0) {
554 log_info(
"Killed old client process");
564 }
else if (errno == ESRCH) {
578 char *new_path_dhclient_pid;
597 int n_len = strlen(ip->
name);
599 new_path_dhclient_pid = (
char*) malloc(pfx + n_len + 6);
601 sprintf(new_path_dhclient_pid + pfx,
"-%s.pid", ip->
name);
603 if ((pidfd = fopen(new_path_dhclient_pid,
"re")) != NULL) {
604 e = fscanf(pidfd,
"%ld\n", &temp);
605 oldpid = (pid_t)temp;
607 if (e != 0 && e != EOF) {
609 if (kill(oldpid, SIGTERM) == 0)
617 free(new_path_dhclient_pid);
626 char procfn[256] =
"";
629 if ((fscanf(pidfp,
"%ld", &temp)==1) && ((dhcpid=(pid_t)temp) > 0)) {
630 snprintf(procfn,256,
"/proc/%u",dhcpid);
631 dhc_running = (access(procfn, F_OK) == 0);
638 log_fatal(
"dhclient(%u) is already running - exiting. ", dhcpid);
663 memcpy(&
giaddr, he->h_addr_list[0],
672 gettimeofday(&
cur_tv, NULL);
679 he = gethostbyname(server);
712 if ((dhcp_client_identifier_arg != NULL) && (*dhcp_client_identifier_arg !=
'\0')) {
713 arg_conf_len =
asprintf(&arg_conf,
"send dhcp-client-identifier \"%s\";", dhcp_client_identifier_arg);
715 if ((arg_conf == 0) || (arg_conf_len <= 0))
716 log_fatal(
"Unable to send -C option dhcp-client-identifier");
719 if ((dhcp_host_name_arg != NULL) && (*dhcp_host_name_arg !=
'\0')) {
721 arg_conf_len =
asprintf(&arg_conf,
"send host-name \"%s\";", dhcp_host_name_arg);
723 if ((arg_conf == 0) || (arg_conf_len <= 0))
724 log_fatal(
"Unable to send -H option host-name");
726 char *last_arg_conf = arg_conf;
728 arg_conf_len =
asprintf(&arg_conf,
"%s\nsend host-name \"%s\";", last_arg_conf, dhcp_host_name_arg);
730 if ((arg_conf == 0) || (arg_conf_len <= 0))
731 log_fatal(
"Unable to send -H option host-name");
737 if ((dhcp_fqdn_arg != NULL) && (*dhcp_fqdn_arg !=
'\0')) {
739 arg_conf_len =
asprintf(&arg_conf,
"send fqdn.fqdn \"%s\";", dhcp_fqdn_arg);
741 if ((arg_conf == 0) || (arg_conf_len <= 0))
742 log_fatal(
"Unable to send -F option fqdn.fqdn");
744 char *last_arg_conf = arg_conf;
746 arg_conf_len =
asprintf(&arg_conf,
"%s\nsend fqdn.fqdn \"%s\";", last_arg_conf, dhcp_fqdn_arg);
748 if ((arg_conf == 0) || (arg_conf_len <= 0))
749 log_fatal(
"Unable to send -F option fqdn.fqdn");
757 arg_conf_len =
asprintf(&arg_conf,
"timeout %d;", timeout_arg);
759 if ((arg_conf == 0) || (arg_conf_len <= 0))
760 log_fatal(
"Unable to process -timeout timeout argument");
762 char *last_arg_conf = arg_conf;
764 arg_conf_len =
asprintf(&arg_conf,
"%s\ntimeout %d;", last_arg_conf, timeout_arg);
766 if ((arg_conf == 0) || (arg_conf_len == 0))
767 log_fatal(
"Unable to process -timeout timeout argument");
773 if ((dhcp_vendor_class_identifier_arg != NULL) && (*dhcp_vendor_class_identifier_arg !=
'\0')) {
775 arg_conf_len =
asprintf(&arg_conf,
"send vendor-class-identifier \"%s\";", dhcp_vendor_class_identifier_arg);
777 if ((arg_conf == 0) || (arg_conf_len <= 0))
778 log_fatal(
"Unable to send -V option vendor-class-identifier");
780 char *last_arg_conf = arg_conf;
782 arg_conf_len =
asprintf(&arg_conf,
"%s\nsend vendor-class-identifier \"%s\";", last_arg_conf, dhcp_vendor_class_identifier_arg);
784 if ((arg_conf == 0) || (arg_conf_len <= 0))
785 log_fatal(
"Unable to send -V option vendor-class-identifier");
791 if (dhclient_request_options != NULL) {
793 arg_conf_len =
asprintf(&arg_conf,
"request %s;", dhclient_request_options);
795 if ((arg_conf == 0) || (arg_conf_len <= 0))
796 log_fatal(
"Unable to parse -R <request options list> argument");
798 char *last_arg_conf = arg_conf;
800 arg_conf_len =
asprintf(&arg_conf,
"%s\nrequest %s;", last_arg_conf, dhclient_request_options);
802 if ((arg_conf == 0) || (arg_conf_len <= 0))
803 log_fatal(
"Unable to parse -R <request options list> argument");
810 if (arg_conf_len == 0)
811 if ((arg_conf_len = strlen(arg_conf)) == 0)
813 log_fatal(
"Unable to process -C/-H/-F/-timeout/-V/-R configuration arguments");
818 const char *val = NULL;
821 status =
new_parse(&cfile, -1, arg_conf, arg_conf_len,
"extra dhclient -C/-H/-F/-timeout/-V/-R configuration arguments", 0);
824 log_fatal(
"Cannot parse -C/-H/-F/-timeout/-V/-R configuration arguments !");
828 token =
peek_token(&val, (
unsigned *)0, cfile);
836 log_fatal(
"Cannot parse -C/-H/-F/-timeout/-V/-R configuration arguments !");
893 log_info(
"No broadcast interfaces found - exiting.");
896 }
else if (!release_mode && !exit_mode) {
930 unsigned backup_seed = 0;
933 if ( ip -> hw_address.hlen <=
sizeof seed )
936 &ip -> hw_address.hbuf [ip -> hw_address.hlen -
937 sizeof seed],
sizeof seed);
959 if ( ip -> hw_address.hlen <=
sizeof seed )
963 sizeof seed],
sizeof seed);
967 if ( seed_flag == 0 ) {
968 if ( backup_seed != 0 ) {
970 log_info (
"xid: rand init seed (0x%x) built using all"
971 " available interfaces",seed);
974 seed =
cur_time^((unsigned) gethostid()) ;
975 log_info (
"xid: warning: no netdev with useable HWADDR found"
976 " for seed's uniqueness enforcement");
977 log_info (
"xid: rand init seed (0x%x) built using gethostid",
982 srandom(seed + ((
unsigned)(
cur_tv.tv_usec * 1000000)) + (
unsigned)getpid());
985 srandom(seed + ((
unsigned)(
cur_tv.tv_usec * 1000000)) + (
unsigned)getpid());
991 setup_ib_interface(ip);
1014 for (client = ip->
client ; client != NULL ;
1015 client = client->
next) {
1019 }
else if (exit_mode) {
1039 for (client = ip->
client ; client ;
1040 client = client->
next) {
1043 else if (release_mode)
1057 tv.tv_usec = random()
1092 if (result != ISC_R_SUCCESS)
1093 log_fatal(
"Can't allocate new generic object: %s\n",
1094 isc_result_totext(result));
1099 if (result != ISC_R_SUCCESS)
1100 log_fatal(
"Can't start OMAPI protocol: %s",
1101 isc_result_totext (result));
1110 #if defined(DEBUG_MEMORY_LEAKAGE) || defined(DEBUG_MALLOC_POOL) || \
1111 defined(DEBUG_MEMORY_LEAKAGE_ON_EXIT)
1112 dmalloc_cutoff_generation = dmalloc_generation;
1113 dmalloc_longterm = dmalloc_outstanding;
1114 dmalloc_outstanding = 0;
1117 #if defined(ENABLE_GENTLE_SHUTDOWN)
1152 "[-4|-6] [-SNTPI1dvrxi] [-nw] [-p <port>] [-D LL|LLT] \n"
1154 "[-I1dvrxi] [-nw] [-p <port>] [-D LL|LLT] \n"
1156 " [-s server-addr] [-cf config-file]\n"
1157 " [-df duid-file] [-lf lease-file]\n"
1158 " [-pf pid-file] [--no-pid] [-e VAR=val]\n"
1159 " [-C <dhcp-client-identifier>] [-B]\n"
1160 " [-H <host-name> | -F <fqdn.fqdn>] [-timeout <timeout>]\n"
1161 " [-V <vendor-class-identifier>]\n"
1162 " [-R <request option list>]\n"
1163 " [-sf script-file] [interface]");
1171 isc_result_t result;
1203 client = client->
next) {
1217 if (result != ISC_R_SUCCESS)
1218 log_fatal(
"Can't allocate new generic object: %s\n",
1219 isc_result_totext(result));
1224 if (result != ISC_R_SUCCESS)
1225 log_fatal(
"Can't start OMAPI protocol: %s",
1226 isc_result_totext(result));
1232 #if defined(DEBUG_MEMORY_LEAKAGE) || defined(DEBUG_MALLOC_POOL) || \
1233 defined(DEBUG_MEMORY_LEAKAGE_ON_EXIT)
1234 dmalloc_cutoff_generation = dmalloc_generation;
1235 dmalloc_longterm = dmalloc_outstanding;
1236 dmalloc_outstanding = 0;
1257 const char *s,
const char *
file,
int line)
1301 "dhcp-client-identifier") == 0)) {
1346 client ->
active -> is_bootp ||
1360 client ->
xid = random ();
1393 client -> xid = client ->
packet.xid;
1396 client -> first_sending =
cur_time;
1397 client -> interval = client -> config -> initial_interval;
1440 for (lp = client -> offered_leases; lp; lp =
next) {
1449 picked -> next = NULL;
1454 client -> offered_leases = NULL;
1461 client -> state =
S_INIT;
1468 client ->
new = picked;
1486 client -> first_sending =
cur_time;
1487 client -> interval = client -> config -> initial_interval;
1491 client -> xid = client ->
packet.xid;
1514 for (client = ip -> client; client; client = client -> next) {
1515 if (client -> xid == packet -> raw -> xid)
1519 (packet -> interface -> hw_address.hlen - 1 !=
1520 packet -> raw -> hlen) ||
1521 (memcmp (&packet -> interface -> hw_address.hbuf [1],
1522 packet -> raw -> chaddr, packet -> raw -> hlen))) {
1524 log_debug (
"DHCPACK in wrong transaction.");
1539 log_info (
"DHCPACK from %s (xid=0x%x)",
piaddr (packet -> client_addr), ntohl(client -> xid));
1543 log_info (
"packet_to_lease failed.");
1547 client ->
new = lease;
1555 memset (&ds, 0,
sizeof ds);
1558 packet -> options, client ->
new -> options,
1563 client ->
new -> expiry = 0;
1566 client ->
new -> expiry = 0;
1571 log_error (
"no expiry time on offered lease.");
1577 tv.tv_sec =
cur_tv.tv_sec;
1578 tv.tv_usec =
cur_tv.tv_usec + 500000;
1580 if (tv.tv_usec >= 1000000) {
1582 tv.tv_usec -= 1000000;
1601 packet -> options, client ->
new -> options,
1606 client ->
new -> renewal = 0;
1609 client ->
new -> renewal = 0;
1612 if (!client ->
new -> renewal)
1613 client ->
new -> renewal = client ->
new -> expiry / 2 + 1;
1615 if (client ->
new -> renewal <= 0)
1616 client ->
new -> renewal =
TIME_MAX;
1621 (((random() % client->
new->
renewal) + 3) / 4);
1628 packet -> options, client ->
new -> options,
1633 client ->
new -> rebind = 0;
1636 client ->
new -> rebind = 0;
1638 if (client ->
new -> rebind <= 0) {
1639 if (client ->
new -> expiry <=
TIME_MAX / 7)
1640 client ->
new -> rebind =
1641 client ->
new -> expiry * 7 / 8;
1643 client ->
new -> rebind =
1644 client ->
new -> expiry / 8 * 7;
1649 if (client ->
new -> renewal > client ->
new -> rebind) {
1650 if (client ->
new -> rebind <=
TIME_MAX / 3)
1651 client ->
new -> renewal =
1652 client ->
new -> rebind * 3 / 4;
1654 client ->
new -> renewal =
1655 client ->
new -> rebind / 4 * 3;
1658 client ->
new -> expiry +=
cur_time;
1660 if (client ->
new -> expiry <
cur_time)
1661 client ->
new -> expiry =
TIME_MAX;
1662 client ->
new -> renewal +=
cur_time;
1663 if (client ->
new -> renewal <
cur_time)
1664 client ->
new -> renewal =
TIME_MAX;
1665 client ->
new -> rebind +=
cur_time;
1666 if (client ->
new -> rebind <
cur_time)
1667 client ->
new -> rebind =
TIME_MAX;
1685 client->new->medium);
1686 if (client->active && client->state !=
S_REBOOTING)
1703 log_info(
"Unable to obtain a lease on first "
1704 "try (declined). Exiting.");
1714 if (!client->last_write ||
1721 client->active = client->new;
1725 tv.tv_sec = client->active->renewal;
1726 tv.tv_usec = ((client->active->renewal -
cur_tv.tv_sec) > 1) ?
1727 random() % 1000000 :
cur_tv.tv_usec;
1730 log_info(
"bound to %s -- renewal in %ld seconds.",
1731 piaddr(client->active->address),
1732 (
long)(client->active->renewal -
cur_time));
1736 #if defined (NSUPDATE)
1737 if (client->config->do_forward_update)
1758 client -> xid = client ->
packet.xid;
1760 memset (&ds, 0,
sizeof ds);
1766 client -> active -> options,
1769 memcpy (client -> destination.iabuf, ds.
data, 4);
1770 client -> destination.len = 4;
1778 client -> first_sending =
cur_time;
1779 client -> interval = client -> config -> initial_interval;
1845 for (ap = packet -> interface -> client -> config -> reject_list;
1846 ap; ap = ap ->
next) {
1855 log_info(
"BOOTREPLY from %s rejected by rule %s "
1856 "mask %s.",
piaddr(packet->client_addr),
1870 void (*handler) (
struct packet *);
1897 for (ap = packet ->
interface -> client -> config -> reject_list;
1898 ap; ap = ap -> next) {
1907 log_info(
"%s from %s rejected by rule %s mask %s.",
1908 type,
piaddr(packet->client_addr),
1913 (*handler) (packet);
1921 char addrbuf[
sizeof(
"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")];
1929 ap ; ap = ap->
next) {
1932 log_info(
"%s from %s rejected by rule %s",
1948 log_info(
"RCV: %s message on %s from %s.",
1959 client = client->
next) {
1968 log_info(
"Packet received, but nothing done with it.");
1973 struct packet *packet;
1981 const char *
name = packet -> packet_type ?
"DHCPOFFER" :
"BOOTREPLY";
1990 for (client = ip -> client; client; client = client -> next)
1991 if (client -> xid == packet -> raw -> xid)
1998 (packet -> interface -> hw_address.hlen - 1 !=
1999 packet -> raw -> hlen) ||
2000 (memcmp (&packet -> interface -> hw_address.hbuf [1],
2001 packet -> raw -> chaddr, packet -> raw -> hlen))) {
2003 log_debug (
"%s in wrong transaction.", name);
2008 sprintf (obuf,
"%s from %s", name,
piaddr (packet -> client_addr));
2016 for (i = 0 ; req[i] != NULL ; i++) {
2023 option_code_hash_lookup(&option,
2028 log_info(
"%s: no %s option.", obuf,
2031 log_info(
"%s: no unknown-%u option.",
2042 for (lease = client -> offered_leases; lease; lease = lease -> next) {
2043 if (lease -> address.len ==
sizeof packet -> raw -> yiaddr &&
2044 !memcmp (lease -> address.iabuf,
2045 &packet -> raw -> yiaddr, lease -> address.len)) {
2053 log_info (
"%s: packet_to_lease failed.", obuf);
2059 if (!packet -> options_valid || !packet -> packet_type)
2060 lease -> is_bootp = 1;
2063 lease -> medium = client -> medium;
2066 stop_selecting = (client -> first_sending +
2067 client -> config -> select_interval);
2071 if (lease -> address.len == client -> requested_address.len &&
2072 !memcmp (lease -> address.iabuf,
2073 client -> requested_address.iabuf,
2074 client -> requested_address.len)) {
2075 lease -> next = client -> offered_leases;
2076 client -> offered_leases = lease;
2080 if (!client -> offered_leases)
2081 client -> offered_leases = lease;
2083 for (lp = client -> offered_leases; lp ->
next;
2093 if (stop_selecting <=
cur_tv.tv_sec)
2096 tv.tv_sec = stop_selecting;
2097 tv.tv_usec =
cur_tv.tv_usec;
2108 struct packet *packet;
2120 log_error(
"packet_to_lease: no memory to record lease.\n");
2124 memset(lease, 0,
sizeof(*lease));
2129 lease->address.len =
sizeof(packet->raw->yiaddr);
2130 memcpy(lease->address.iabuf, &packet->raw->yiaddr,
2131 lease->address.len);
2133 lease->next_srv_addr.len =
sizeof(packet->raw->siaddr);
2134 memcpy(lease->next_srv_addr.iabuf, &packet->raw->siaddr,
2135 lease->next_srv_addr.len);
2137 memset(&data, 0,
sizeof(data));
2139 if (client -> config -> vendor_space_name) {
2145 client -> config -> vendor_space_name &&
2147 (
struct lease *)0, client,
2151 if (!option_code_hash_lookup(&option,
2155 "option (%s:%d).",
MDL);
2159 client -> config -> vendor_space_name
2185 if (!(i & 2) && packet -> raw -> sname [0]) {
2189 if (!packet -> raw -> sname [len])
2193 log_error (
"dhcpoffer: no memory for server name.\n");
2198 packet -> raw -> sname, len);
2204 if (!(i & 1) && packet -> raw ->
file [0]) {
2208 if (!packet -> raw ->
file [len])
2212 log_error (
"dhcpoffer: no memory for filename.\n");
2217 packet -> raw ->
file, len);
2223 client, lease->options, lease->options,
2231 struct packet *packet;
2237 for (client = ip -> client; client; client = client ->
next)
2238 if (client ->
xid == packet -> raw ->
xid)
2244 (packet ->
interface -> hw_address.hlen - 1 !=
2245 packet -> raw -> hlen) ||
2246 (memcmp (&packet ->
interface -> hw_address.hbuf [1],
2247 packet -> raw -> chaddr, packet -> raw -> hlen))) {
2249 log_debug (
"DHCPNAK in wrong transaction.");
2264 log_info (
"DHCPNAK from %s (xid=0x%x)",
piaddr (packet -> client_addr), ntohl(client ->
xid));
2268 log_info (
"DHCPNAK with no active lease.\n");
2301 client -> state =
S_INIT;
2320 interval =
cur_time - client -> first_sending;
2324 if (interval > client -> config ->
timeout) {
2332 if (!client -> offered_leases &&
2333 client -> config -> media) {
2336 if (client -> medium) {
2337 client -> medium = client -> medium -> next;
2340 if (!client -> medium) {
2342 log_fatal (
"No valid media types for %s!",
2343 client -> interface -> name);
2345 client -> config -> media;
2349 log_info (
"Trying medium \"%s\" %d",
2350 client -> medium ->
string, increase);
2378 if (
cur_time + client -> interval >
2379 client -> first_sending + client -> config ->
timeout)
2380 client -> interval =
2381 (client -> first_sending +
2385 if (interval < 65536)
2386 client -> packet.secs = htons (interval);
2388 client -> packet.secs = htons (65535);
2389 client -> secs = client -> packet.secs;
2391 log_info (
"DHCPDISCOVER on %s to %s port %d interval %ld (xid=0x%x)",
2392 client -> name ? client -> name : client -> interface -> name,
2394 ntohs (
sockaddr_broadcast.sin_port), (
long)(client -> interval), ntohl(client -> xid));
2401 log_error(
"%s:%d: Failed to send %d byte long packet over %s "
2413 tv.tv_usec = client->
interval > 1 ? random() % 1000000 :
cur_tv.tv_usec;
2430 loop = lp = client -> active;
2432 log_info (
"No DHCPOFFERS received.");
2436 if (!client -> active && client -> leases)
2440 while (client -> active) {
2441 if (client -> active -> expiry >
cur_time) {
2442 log_info (
"Trying recorded lease %s",
2443 piaddr (client -> active -> address));
2447 client -> active -> medium);
2450 if (client -> alias)
2458 if (cur_time < client -> active -> renewal) {
2460 log_info (
"bound: renewal in %ld %s.",
2461 (
long)(client -> active -> renewal -
2466 random() % 1000000 :
2471 log_info (
"bound: immediate renewal.");
2481 if (!client -> leases) {
2482 client -> leases = client -> active;
2490 for (lp = client -> leases; lp ->
next; lp = lp ->
next)
2492 lp ->
next = client -> active;
2496 client -> active = client -> leases;
2497 client -> leases = client -> leases ->
next;
2502 if (client -> active == loop)
2505 loop = client -> active;
2513 log_info (
"Unable to obtain a lease on first try.%s",
2518 log_info (
"No working leases in persistent database - sleeping.");
2520 if (client -> alias)
2523 client -> state =
S_INIT;
2526 tv.tv_usec = ((tv.tv_sec -
cur_tv.tv_sec) > 1) ?
2527 random() % 1000000 :
cur_tv.tv_usec;
2539 struct sockaddr_in destination;
2540 struct in_addr from;
2544 interval =
cur_time - client -> first_sending;
2558 interval > client -> config -> reboot_timeout) {
2560 client -> state =
S_INIT;
2569 !client -> medium &&
2570 client -> active -> medium ) {
2571 script_init (client,
"MEDIUM", client -> active -> medium);
2578 client -> medium = client -> active -> medium;
2584 cur_time > client -> active -> expiry) {
2589 if (client -> alias)
2597 if (client -> alias)
2602 client -> state =
S_INIT;
2608 if (!client -> interval)
2609 client -> interval = client -> config -> initial_interval;
2611 client -> interval += ((random () >> 2) %
2612 (2 * client -> interval));
2616 if (client -> interval >
2617 client -> config -> backoff_cutoff)
2618 client -> interval =
2619 ((client -> config -> backoff_cutoff / 2)
2620 + ((random () >> 2) %
2621 client -> config -> backoff_cutoff));
2626 cur_time + client -> interval > client -> active -> expiry)
2627 client -> interval =
2628 client -> active -> expiry -
cur_time + 1;
2634 cur_time > client -> active -> rebind)
2637 memcpy (&destination.sin_addr.s_addr,
2638 client -> destination.iabuf,
2639 sizeof destination.sin_addr.s_addr);
2641 destination.sin_family = AF_INET;
2643 destination.sin_len =
sizeof destination;
2648 memcpy (&from, client -> active -> address.iabuf,
2651 from.s_addr = INADDR_ANY;
2655 client -> packet.secs = client -> secs;
2657 if (interval < 65536)
2658 client -> packet.secs = htons (interval);
2660 client -> packet.secs = htons (65535);
2663 log_info (
"DHCPREQUEST on %s to %s port %d (xid=0x%x)",
2664 client -> name ? client -> name : client -> interface -> name,
2665 inet_ntoa (destination.sin_addr),
2666 ntohs (destination.sin_port), ntohl(client -> xid));
2668 if (destination.sin_addr.s_addr != INADDR_BROADCAST &&
2670 #if defined(SO_BINDTODEVICE)
2674 log_error(
"%s:%d: Failed to bind fallback interface"
2682 log_error(
"%s:%d: Failed to send %d byte long packet "
2683 "over %s interface.",
MDL,
2687 #if defined(SO_BINDTODEVICE)
2689 SO_BINDTODEVICE, NULL, 0) < 0) {
2690 log_fatal(
"%s:%d: Failed to unbind fallback interface:"
2701 log_error(
"%s:%d: Failed to send %d byte long packet"
2702 " over %s interface.",
MDL,
2709 tv.tv_usec = ((tv.tv_sec -
cur_tv.tv_sec) > 1) ?
2710 random() % 1000000 :
cur_tv.tv_usec;
2721 log_info (
"DHCPDECLINE on %s to %s port %d (xid=0x%x)",
2731 log_error(
"%s:%d: Failed to send %d byte long packet over %s"
2743 struct sockaddr_in destination;
2744 struct in_addr from;
2746 memcpy (&from, client -> active -> address.iabuf,
2748 memcpy (&destination.sin_addr.s_addr,
2749 client -> destination.iabuf,
2750 sizeof destination.sin_addr.s_addr);
2752 destination.sin_family = AF_INET;
2754 destination.sin_len =
sizeof destination;
2759 client -> active -> expiry =
2760 client -> active -> renewal =
2761 client -> active -> rebind =
cur_time;
2763 log_error (
"Can't release lease: lease write failed.");
2767 log_info (
"DHCPRELEASE on %s to %s port %d (xid=0x%x)",
2768 client -> name ? client -> name : client -> interface -> name,
2769 inet_ntoa (destination.sin_addr),
2770 ntohs (destination.sin_port), ntohl(client -> xid));
2773 #if defined(SO_BINDTODEVICE)
2777 log_error(
"%s:%d: Failed to bind fallback interface"
2785 log_error(
"%s:%d: Failed to send %d byte long packet"
2786 " over %s interface.",
MDL,
2790 #if defined(SO_BINDTODEVICE)
2792 SO_BINDTODEVICE, NULL, 0) < 0) {
2793 log_fatal(
"%s:%d: Failed to unbind fallback interface:"
2803 log_error (
"%s:%d: Failed to send %d byte long packet"
2804 " over %s interface.",
MDL,
2821 struct buffer *bp = NULL;
2844 log_error (
"can't make requested address cache.");
2870 for (i = 0 ; prl[i] != NULL ; i++)
2875 log_error(
"can't make parameter list buffer.");
2880 for (i = 0 ; prl[i] != NULL ; i++)
2884 if (!(option_code_hash_lookup(&option,
2909 memset(&client_identifier, 0,
sizeof(client_identifier));
2912 client_identifier.
len,
MDL))
2913 log_fatal(
"no memory for default DUID!");
2931 memcpy(&client_identifier.
buffer->
data + 5 - hw_len,
2936 memcpy(&client_identifier.
buffer->
data+(1+4),
2943 (u_int8_t *)client_identifier.
data,
2944 client_identifier.
len,
2946 log_error (
"can't make requested client id cache..");
2957 (lease ? lease->
options : NULL),
2970 memset (&client -> packet, 0,
sizeof (client -> packet));
2974 lease ? &lease -> address : (
struct iaddr *)0,
2975 client -> config -> requested_options,
2979 client -> packet_length =
2981 (
struct lease *)0, client,
2990 client -> config -> vendor_space_name);
2997 client -> packet.htype = client ->
interface -> hw_address.hbuf [0];
2998 client -> packet.hlen = client ->
interface -> hw_address.hlen - 1;
2999 client -> packet.hops = 0;
3000 client -> packet.xid = random ();
3001 client -> packet.secs = 0;
3005 client -> packet.flags = 0;
3009 memset (&(client -> packet.ciaddr),
3010 0,
sizeof client -> packet.ciaddr);
3011 memset (&(client -> packet.yiaddr),
3012 0,
sizeof client -> packet.yiaddr);
3013 memset (&(client -> packet.siaddr),
3014 0,
sizeof client -> packet.siaddr);
3015 client -> packet.giaddr =
giaddr;
3016 if (client -> interface -> hw_address.hlen > 0)
3017 memcpy (client -> packet.chaddr,
3018 &client -> interface -> hw_address.hbuf [1],
3019 (
unsigned)(client -> interface -> hw_address.hlen - 1));
3022 dump_raw ((
unsigned char *)&client -> packet, client -> packet_length);
3034 memset (&client -> packet, 0,
sizeof (client -> packet));
3042 if (client -> sent_options)
3049 : (
struct iaddr *)0),
3050 client -> config -> requested_options,
3051 &client -> sent_options);
3054 client -> packet_length =
3056 (
struct lease *)0, client,
3059 client -> sent_options,
3065 client -> config -> vendor_space_name);
3071 client -> packet.htype = client ->
interface -> hw_address.hbuf [0];
3072 client -> packet.hlen = client ->
interface -> hw_address.hlen - 1;
3073 client -> packet.hops = 0;
3074 client -> packet.xid = client -> xid;
3075 client -> packet.secs = 0;
3079 if (client -> state ==
S_BOUND ||
3082 memcpy (&client -> packet.ciaddr,
3083 lease -> address.iabuf, lease -> address.len);
3084 client -> packet.flags = 0;
3086 memset (&client -> packet.ciaddr, 0,
3087 sizeof client -> packet.ciaddr);
3089 client ->config->bootp_broadcast_always)) &&
3091 client -> packet.flags = 0;
3096 memset (&client -> packet.yiaddr, 0,
3097 sizeof client -> packet.yiaddr);
3098 memset (&client -> packet.siaddr, 0,
3099 sizeof client -> packet.siaddr);
3100 if (client -> state !=
S_BOUND &&
3102 client -> packet.giaddr =
giaddr;
3104 memset (&client -> packet.giaddr, 0,
3105 sizeof client -> packet.giaddr);
3106 if (client -> interface -> hw_address.hlen > 0)
3107 memcpy (client -> packet.chaddr,
3108 &client -> interface -> hw_address.hbuf [1],
3109 (
unsigned)(client -> interface -> hw_address.hlen - 1));
3112 dump_raw ((
unsigned char *)&client -> packet, client -> packet_length);
3132 memset (&client -> packet, 0,
sizeof (client -> packet));
3133 client -> packet_length =
3135 (
struct lease *)0, client, 0,
3138 client -> config -> vendor_space_name);
3147 client -> packet.htype = client ->
interface -> hw_address.hbuf [0];
3148 client -> packet.hlen = client ->
interface -> hw_address.hlen - 1;
3149 client -> packet.hops = 0;
3150 client -> packet.xid = client -> xid;
3151 client -> packet.secs = 0;
3154 client -> packet.flags = 0;
3159 memset (&client -> packet.ciaddr, 0,
3160 sizeof client -> packet.ciaddr);
3161 memset (&client -> packet.yiaddr, 0,
3162 sizeof client -> packet.yiaddr);
3163 memset (&client -> packet.siaddr, 0,
3164 sizeof client -> packet.siaddr);
3165 client -> packet.giaddr =
giaddr;
3166 memcpy (client -> packet.chaddr,
3167 &client -> interface -> hw_address.hbuf [1],
3168 client -> interface -> hw_address.hlen);
3171 dump_raw ((
unsigned char *)&client -> packet, client -> packet_length);
3184 memset (&client -> packet, 0,
sizeof (client -> packet));
3191 client -> packet_length =
3193 (
struct lease *)0, client,
3202 client -> config -> vendor_space_name);
3209 client -> packet.htype = client ->
interface -> hw_address.hbuf [0];
3210 client -> packet.hlen = client ->
interface -> hw_address.hlen - 1;
3211 client -> packet.hops = 0;
3212 client -> packet.xid = random ();
3213 client -> packet.secs = 0;
3214 client -> packet.flags = 0;
3215 memcpy (&client -> packet.ciaddr,
3216 lease -> address.iabuf, lease -> address.len);
3217 memset (&client -> packet.yiaddr, 0,
3218 sizeof client -> packet.yiaddr);
3219 memset (&client -> packet.siaddr, 0,
3220 sizeof client -> packet.siaddr);
3221 client -> packet.giaddr =
giaddr;
3222 memcpy (client -> packet.chaddr,
3223 &client -> interface -> hw_address.hbuf [1],
3224 client -> interface -> hw_address.hlen);
3227 dump_raw ((
unsigned char *)&client -> packet, client -> packet_length);
3234 if (lease -> server_name)
3236 if (lease -> filename)
3251 if (leaseFile != NULL)
3254 if (leaseFile == NULL) {
3266 for (client = ip -> client; client; client = client ->
next) {
3267 for (lp = client -> leases; lp; lp = lp ->
next) {
3270 if (client -> active)
3272 client -> active, 1, 0);
3287 for (client = ip -> client; client; client = client ->
next) {
3288 for (lp = client -> leases; lp; lp = lp ->
next) {
3291 if (client -> active)
3293 client -> active, 1, 0);
3315 const char *name, *dot;
3317 char *preamble = stuff;
3319 memset (&ds, 0,
sizeof ds);
3329 in_options, cfg_options, scope, oc,
MDL)) {
3331 fprintf(leaseFile,
"%soption %s%s%s", preamble,
3337 fprintf(leaseFile,
" %s",
3343 fprintf(leaseFile,
";\n");
3352 const char *preamble)
3392 log_debug(
"Cannot form default DUID from interface %s.", ip->
name);
3396 return ISC_R_UNEXPECTED;
3401 log_fatal(
"Impossible hardware address length at %s:%d.",
MDL);
3417 log_fatal(
"no memory for default DUID!");
3443 return ISC_R_SUCCESS;
3453 if ((duid == NULL) || (duid->
len <= 2))
3456 if (leaseFile == NULL) {
3458 if (leaseFile == NULL) {
3460 return ISC_R_IOERROR;
3471 return ISC_R_NOMEMORY;
3473 stat = fprintf(leaseFile,
"default-duid \"%s\";\n", str);
3476 return ISC_R_IOERROR;
3478 if (fflush(leaseFile) != 0)
3479 return ISC_R_IOERROR;
3481 return ISC_R_SUCCESS;
3487 int rewrite,
int sync)
3495 if (!rewrite && (leases_written++ > 20)) {
3498 return ISC_R_SUCCESS;
3501 if (client == NULL || lease == NULL)
3504 if (leaseFile == NULL) {
3506 if (leaseFile == NULL) {
3508 return ISC_R_IOERROR;
3512 stat = fprintf(leaseFile,
"lease6 {\n");
3514 return ISC_R_IOERROR;
3516 stat = fprintf(leaseFile,
" interface \"%s\";\n",
3519 return ISC_R_IOERROR;
3521 for (ia = lease->
bindings ; ia != NULL ; ia = ia->
next) {
3534 stat = fprintf(leaseFile,
" %s %s {\n",
3537 return ISC_R_IOERROR;
3540 stat = fprintf(leaseFile,
" starts %d;\n"
3545 stat = fprintf(leaseFile,
" starts %d;\n",
3548 return ISC_R_IOERROR;
3550 for (addr = ia->
addrs ; addr != NULL ; addr = addr->
next) {
3552 stat = fprintf(leaseFile,
3556 stat = fprintf(leaseFile,
3557 " iaprefix %s/%d {\n",
3561 return ISC_R_IOERROR;
3563 stat = fprintf(leaseFile,
" starts %d;\n"
3564 " preferred-life %u;\n"
3569 return ISC_R_IOERROR;
3572 write_options(client, addr->
options,
" ");
3574 stat = fprintf(leaseFile,
" }\n");
3576 return ISC_R_IOERROR;
3580 write_options(client, ia->
options,
" ");
3582 stat = fprintf(leaseFile,
" }\n");
3584 return ISC_R_IOERROR;
3588 stat = fprintf(leaseFile,
" released;\n");
3590 return ISC_R_IOERROR;
3594 write_options(client, lease->
options,
" ");
3596 stat = fprintf(leaseFile,
"}\n");
3598 return ISC_R_IOERROR;
3600 if (fflush(leaseFile) != 0)
3601 return ISC_R_IOERROR;
3604 if (fsync(fileno(leaseFile)) < 0) {
3605 log_error(
"write_client_lease: fsync(): %m");
3606 return ISC_R_IOERROR;
3610 return ISC_R_SUCCESS;
3625 if (leases_written++ > 20) {
3633 if (lease -> is_static)
3636 if (leaseFile == NULL) {
3638 if (leaseFile == NULL) {
3645 fprintf (leaseFile,
"lease {\n");
3646 if (lease -> is_bootp) {
3647 fprintf (leaseFile,
" bootp;\n");
3653 fprintf (leaseFile,
" interface \"%s\";\n",
3654 client -> interface -> name);
3659 if (client -> name) {
3660 fprintf (leaseFile,
" name \"%s\";\n", client -> name);
3666 fprintf (leaseFile,
" fixed-address %s;\n",
3667 piaddr (lease -> address));
3672 if (lease -> filename) {
3675 fprintf (leaseFile,
" filename \"%s\";\n", s);
3688 fprintf(leaseFile,
" server-name \"%s\";\n", s);
3697 if (lease -> medium) {
3700 fprintf (leaseFile,
" medium \"%s\";\n", s);
3714 memset (&ds, 0,
sizeof ds);
3716 write_options(client, lease->
options,
" ");
3720 fprintf(leaseFile,
" renew %s\n", tval) < 0)
3725 fprintf(leaseFile,
" rebind %s\n", tval) < 0)
3730 fprintf(leaseFile,
" expire %s\n", tval) < 0)
3733 if (fprintf(leaseFile,
"}\n") < 0)
3736 if (fflush(leaseFile) != 0)
3741 if (!errors && makesure) {
3742 if (fsync (fileno (leaseFile)) < 0) {
3743 log_info (
"write_client_lease: %m");
3748 return errors ? 0 : 1;
3765 for (sl = client -> env; sl; sl =
next) {
3772 if (client -> interface) {
3774 client -> interface -> name);
3778 "",
"client",
"%s", client -> name);
3781 "",
"medium",
"%s", medium ->
string);
3784 client_envadd (client,
"",
"pid",
"%ld", (
long int)getpid ());
3798 memset (&data, 0,
sizeof data);
3801 in_options, cfg_options, scope, oc,
MDL)) {
3811 length = strlen(value);
3815 value, length) == 0) {
3820 "option - discarded",
3843 prefix,
"ip_address",
"%s",
piaddr (lease -> address));
3859 memset (&data, 0,
sizeof data);
3862 (
struct lease *)0, client,
3867 struct iaddr netmask, subnet, broadcast;
3890 (&data, (
struct packet *)0,
3891 (
struct lease *)0, client,
3896 if (broadcast.
len) {
3898 prefix,
"broadcast_address",
3899 "%s",
piaddr (broadcast));
3915 "option - discarded",
3928 "option - discarded",
3940 client_envadd (client, prefix,
"expiry",
"%d", (
int)(lease -> expiry));
3955 req = client->config->requested_options;
3960 for (i = 0 ; req[i] != NULL ; i++) {
3974 char reason [] =
"REASON=NBI";
3975 static char client_path [] = CLIENT_PATH;
3978 int pid, wpid, wstatus;
3981 scriptName = client -> config -> script_name;
3985 envp =
dmalloc (((client ? client -> envc : 2) +
3988 log_error (
"No memory for client script environment.");
3994 for (sp = client_env; sp; sp = sp ->
next) {
3995 envp [i++] = sp ->
string;
3999 for (sp = client -> env; sp; sp = sp ->
next) {
4000 envp [i++] = sp ->
string;
4003 envp [i++] = reason;
4006 envp [i++] = client_path;
4007 envp [i] = (
char *)0;
4010 argv [1] = (
char *)0;
4018 wpid = wait (&wstatus);
4019 }
while (wpid != pid && wpid > 0);
4028 if (leaseFile != NULL)
4030 execve (scriptName, argv, envp);
4031 log_error (
"execve (%s, ...): %m", scriptName);
4036 for (sp = client -> env; sp; sp =
next) {
4044 gettimeofday(&
cur_tv, NULL);
4045 return (WIFEXITED (wstatus) ?
4046 WEXITSTATUS (wstatus) : -WTERMSIG (wstatus));
4050 const char *prefix,
const char *name,
const char *fmt, ...)
4058 va_start (list, fmt);
4059 len = vsnprintf (spbuf,
sizeof spbuf, fmt, list);
4062 val =
dmalloc (strlen (prefix) + strlen (name) + 1 +
4063 len +
sizeof *val,
MDL);
4071 if (len >=
sizeof spbuf) {
4072 va_start (list, fmt);
4073 vsnprintf (s, len + 1, fmt, list);
4077 val ->
next = client -> env;
4078 client -> env = val;
4101 if (j + 1 == buflen)
4111 if (j + 1 == buflen)
4124 static int state = 0;
4142 if ((pid = fork ()) < 0)
4155 (void) open(
"/dev/null", O_RDWR | O_CLOEXEC);
4156 (void) open(
"/dev/null", O_RDWR | O_CLOEXEC);
4157 (void) open(
"/dev/null", O_RDWR | O_CLOEXEC);
4174 pfdesc = open (
path_dhclient_pid, O_CREAT | O_TRUNC | O_WRONLY | O_CLOEXEC, 0644);
4181 pf = fdopen (pfdesc,
"we");
4186 fprintf (pf,
"%ld\n", (
long)getpid ());
4197 for (client = ip -> client; client; client = client ->
next) {
4198 switch (client ->
state) {
4232 client -> xid = random ();
4235 if (client -> active) {
4240 memset (&ds, 0,
sizeof ds);
4242 client -> active -> options,
4246 (
struct lease *)0, client,
4248 client -> active -> options,
4251 memcpy (client -> destination.iabuf,
4253 client -> destination.len = 4;
4260 client -> first_sending =
cur_time;
4261 client -> interval = client -> config -> initial_interval;
4272 if (client -> alias)
4302 if (!strcmp (ip ->
name, tmp ->
name)) {
4306 interface_reference (&ip, last ->
next,
MDL);
4307 interface_dereference (&last ->
next,
MDL);
4309 interface_reference (&last ->
next,
4311 interface_dereference (&ip ->
next,
4316 interface_reference (&ip,
4322 interface_dereference (&ip ->
next,
4328 tmp -> client = ip ->
client;
4329 tmp -> client ->
interface = tmp;
4331 interface_dereference (&ip,
MDL);
4366 if (ip -> client ->
alias)
4368 ip -> client ->
alias);
4380 for (client = ip->
client ; client ; client = client->
next) {
4385 return ISC_R_SUCCESS;
4392 struct packet *packet;
4411 static void shutdown_exit (
void *foo)
4419 #if defined (NSUPDATE)
4436 isc_result_t eresult)
4439 isc_result_t result;
4441 if ((eresult == ISC_R_SUCCESS) &&
4447 if (result == ISC_R_SUCCESS) {
4453 dhclient_ddns_cb_free(ddns_cb,
MDL);
4462 isc_result_t result;
4465 if (client->
ddns_cb != NULL) {
4471 if (ddns_cb != NULL) {
4477 ddns_cb->
cur_func = client_dns_remove_action;
4481 if (result != ISC_R_TIMEDOUT) {
4482 dhclient_ddns_cb_free(ddns_cb,
MDL);
4498 return ISC_R_SUCCESS;
4502 log_info(
"Received signal %d, initiating shutdown.",
4511 for (client = ip -> client; client; client = client -> next) {
4514 return ISC_R_SUCCESS;
4517 return ISC_R_SUCCESS;
4520 if (client -> active &&
4521 client -> active -> expiry >
cur_time) {
4522 #if defined (NSUPDATE)
4544 tv.tv_sec =
cur_tv.tv_sec;
4545 tv.tv_usec =
cur_tv.tv_usec + 1;
4548 return ISC_R_SUCCESS;
4551 #if defined (NSUPDATE)
4562 isc_result_t status = ISC_R_FAILURE;
4564 if ((client != NULL) &&
4565 ((client->
active != NULL) ||
4578 if (status != ISC_R_TIMEDOUT) {
4579 dhclient_ddns_cb_free(ddns_cb,
MDL);
4614 isc_result_t eresult)
4616 isc_result_t result;
4633 ddns_cb->
cur_func = client_dns_update_action;
4636 if (result == ISC_R_SUCCESS) {
4642 case ISC_R_TIMEDOUT:
4650 if (ddns_cb->
zone != NULL) {
4656 ddns_cb->
cur_func = client_dns_update_action;
4662 tv.tv_usec =
cur_tv.tv_usec;
4664 ddns_cb, NULL, NULL);
4668 dhclient_ddns_cb_free(ddns_cb,
MDL);
4686 if (!client -> sent_options)
4687 return ISC_R_SUCCESS;
4691 return ISC_R_SUCCESS;
4697 (
struct lease *)0, client,
4698 client -> sent_options,
4701 return ISC_R_SUCCESS;
4708 (
struct lease *)0, client,
4709 client -> sent_options,
4712 return ISC_R_SUCCESS;
4718 (
struct lease *)0, client,
4719 client -> sent_options,
4722 return ISC_R_SUCCESS;
4734 memset(&client_identifier, 0,
sizeof(client_identifier));
4758 client_identifier.data,
4759 client_identifier.len);
4777 (client_identifier.data[0] == 255)) {
4782 if (client_identifier.len <= 5)
4783 log_fatal(
"Impossible condition at %s:%d.",
4786 client_identifier.data + 5,
4787 client_identifier.len - 5);
4789 result =
get_dhcid(ddns_cb, ddns_v4_type,
4790 client_identifier.data,
4791 client_identifier.len);
4801 return ISC_R_SUCCESS;
4810 rcode = ISC_R_FAILURE;
4816 if (rcode == ISC_R_SUCCESS) {
4817 rcode = ISC_R_TIMEDOUT;
4840 if (client->
ddns_cb != NULL) {
4847 if (ddns_cb != NULL) {
4848 ddns_cb->
lease = (
void *)client;
4861 ddns_cb->
cur_func = client_dns_update_action;
4865 tv.tv_sec =
cur_tv.tv_sec + offset;
4866 tv.tv_usec =
cur_tv.tv_usec;
4868 ddns_cb, NULL, NULL);
4870 log_error(
"Unable to allocate dns update state for %s",
4879 struct servent *ent;
4893 ent = getservbyname(
"dhcpc",
"udp");
4895 ent = getservbyname(
"bootpc",
"udp");
4900 #ifndef __CYGWIN32__
4924 static int check_domain_name(
const char *ptr,
size_t len,
int dots)
4929 if ((len == 0) || (len > 256))
4934 for (p=ptr; (*p != 0) && (len-- > 0); p++) {
4935 if ((*p ==
'-') || (*p ==
'_')) {
4937 if (((p - ptr) == 0) || (len == 0) || (p[1] ==
'.'))
4939 }
else if (*p ==
'.') {
4943 if ((d <= 0) || (d >= 64))
4946 if ((dots > 0) && (len > 0))
4948 }
else if (isalnum((
unsigned char)*p) == 0) {
4953 return(dots ? -1 : 0);
4956 static int check_domain_name_list(
const char *ptr,
size_t len,
int dots)
4961 if ((ptr == NULL) || (len == 0))
4964 for (p=ptr; (*p != 0) && (len > 0); p++, len--) {
4968 if (check_domain_name(ptr, p - ptr, dots) != 0)
4975 return(check_domain_name(ptr, p - ptr, dots));
4992 #ifdef ACCEPT_LIST_IN_DOMAIN_NAME
4993 return check_domain_name_list(ptr, len, 0);
4995 return check_domain_name(ptr, len, 0);
5000 return check_domain_name(ptr, len, 0);
5003 return check_domain_name_list(ptr, len, 0);
5008 for (; (*ptr != 0) && (len-- > 0); ptr++) {
5009 if(!(isalnum((
unsigned char)*ptr) ||
5010 *ptr ==
'#' || *ptr ==
'%' ||
5011 *ptr ==
'+' || *ptr ==
'-' ||
5012 *ptr ==
'_' || *ptr ==
':' ||
5013 *ptr ==
'.' || *ptr ==
',' ||
5014 *ptr ==
'@' || *ptr ==
'~' ||
5015 *ptr ==
'\\' || *ptr ==
'/' ||
5016 *ptr ==
'[' || *ptr ==
']' ||
5017 *ptr ==
'=' || *ptr ==
' '))
5032 return check_domain_name_list(ptr, len, 0);
5042 add_reject(
struct packet *packet) {
5047 log_fatal (
"no memory for reject list!");
5066 log_info(
"Server added to list of rejected servers.");
5075 if (client != NULL) {
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(* dhcpv6_packet_handler)(struct interface_info *, const char *, int, int, const struct iaddr *, isc_boolean_t)
void send_discover(void *cpp)
void unbill_class(struct lease *lease)
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 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
void(* bootp_packet_handler)(struct interface_info *, struct dhcp_packet *, unsigned, unsigned int, struct iaddr, struct hardware *)
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)
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__
void(* v6_handler)(struct packet *, struct client_state *)
#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)
struct option * default_requested_options[]
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 run_stateless(int exit_mode)
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)
void db_startup(int testp)
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
isc_result_t(* dhcp_interface_startup_hook)(struct interface_info *)
#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 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)
int(* dhcp_interface_discovery_hook)(struct interface_info *)
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
int(* dhcp_interface_shutdown_hook)(struct interface_info *)
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