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), ntohl(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), ntohl(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,
2386 ntohs (
sockaddr_broadcast.sin_port), (
long)(client -> interval), ntohl(client -> xid));
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), ntohl(client -> xid));
2660 if (destination.sin_addr.s_addr != INADDR_BROADCAST &&
2662 #if defined(SO_BINDTODEVICE)
2666 log_error(
"%s:%d: Failed to bind fallback interface"
2674 log_error(
"%s:%d: Failed to send %d byte long packet "
2675 "over %s interface.",
MDL,
2679 #if defined(SO_BINDTODEVICE)
2681 SO_BINDTODEVICE, NULL, 0) < 0) {
2682 log_fatal(
"%s:%d: Failed to unbind fallback interface:"
2693 log_error(
"%s:%d: Failed to send %d byte long packet"
2694 " over %s interface.",
MDL,
2701 tv.tv_usec = ((tv.tv_sec -
cur_tv.tv_sec) > 1) ?
2702 random() % 1000000 :
cur_tv.tv_usec;
2713 log_info (
"DHCPDECLINE on %s to %s port %d (xid=0x%x)",
2723 log_error(
"%s:%d: Failed to send %d byte long packet over %s"
2735 struct sockaddr_in destination;
2736 struct in_addr from;
2738 memcpy (&from, client -> active -> address.iabuf,
2740 memcpy (&destination.sin_addr.s_addr,
2741 client -> destination.iabuf,
2742 sizeof destination.sin_addr.s_addr);
2744 destination.sin_family = AF_INET;
2746 destination.sin_len =
sizeof destination;
2751 client -> active -> expiry =
2752 client -> active -> renewal =
2753 client -> active -> rebind =
cur_time;
2755 log_error (
"Can't release lease: lease write failed.");
2759 log_info (
"DHCPRELEASE on %s to %s port %d (xid=0x%x)",
2760 client -> name ? client -> name : client -> interface -> name,
2761 inet_ntoa (destination.sin_addr),
2762 ntohs (destination.sin_port), ntohl(client -> xid));
2765 #if defined(SO_BINDTODEVICE)
2769 log_error(
"%s:%d: Failed to bind fallback interface"
2777 log_error(
"%s:%d: Failed to send %d byte long packet"
2778 " over %s interface.",
MDL,
2782 #if defined(SO_BINDTODEVICE)
2784 SO_BINDTODEVICE, NULL, 0) < 0) {
2785 log_fatal(
"%s:%d: Failed to unbind fallback interface:"
2795 log_error (
"%s:%d: Failed to send %d byte long packet"
2796 " over %s interface.",
MDL,
2813 struct buffer *bp = NULL;
2836 log_error (
"can't make requested address cache.");
2862 for (i = 0 ; prl[i] != NULL ; i++)
2867 log_error(
"can't make parameter list buffer.");
2872 for (i = 0 ; prl[i] != NULL ; i++)
2876 if (!(option_code_hash_lookup(&option,
2901 memset(&client_identifier, 0,
sizeof(client_identifier));
2904 client_identifier.
len,
MDL))
2905 log_fatal(
"no memory for default DUID!");
2923 memcpy(&client_identifier.
buffer->
data + 5 - hw_len,
2928 memcpy(&client_identifier.
buffer->
data+(1+4),
2935 (u_int8_t *)client_identifier.
data,
2936 client_identifier.
len,
2938 log_error (
"can't make requested client id cache..");
2949 (lease ? lease->
options : NULL),
2962 memset (&client -> packet, 0,
sizeof (client -> packet));
2966 lease ? &lease -> address : (
struct iaddr *)0,
2967 client -> config -> requested_options,
2971 client -> packet_length =
2973 (
struct lease *)0, client,
2982 client -> config -> vendor_space_name);
2989 client -> packet.htype = client ->
interface -> hw_address.hbuf [0];
2990 client -> packet.hlen = client ->
interface -> hw_address.hlen - 1;
2991 client -> packet.hops = 0;
2992 client -> packet.xid = random ();
2993 client -> packet.secs = 0;
2997 client -> packet.flags = 0;
3001 memset (&(client -> packet.ciaddr),
3002 0,
sizeof client -> packet.ciaddr);
3003 memset (&(client -> packet.yiaddr),
3004 0,
sizeof client -> packet.yiaddr);
3005 memset (&(client -> packet.siaddr),
3006 0,
sizeof client -> packet.siaddr);
3007 client -> packet.giaddr =
giaddr;
3008 if (client -> interface -> hw_address.hlen > 0)
3009 memcpy (client -> packet.chaddr,
3010 &client -> interface -> hw_address.hbuf [1],
3011 (
unsigned)(client -> interface -> hw_address.hlen - 1));
3014 dump_raw ((
unsigned char *)&client -> packet, client -> packet_length);
3026 memset (&client -> packet, 0,
sizeof (client -> packet));
3034 if (client -> sent_options)
3041 : (
struct iaddr *)0),
3042 client -> config -> requested_options,
3043 &client -> sent_options);
3046 client -> packet_length =
3048 (
struct lease *)0, client,
3051 client -> sent_options,
3057 client -> config -> vendor_space_name);
3063 client -> packet.htype = client ->
interface -> hw_address.hbuf [0];
3064 client -> packet.hlen = client ->
interface -> hw_address.hlen - 1;
3065 client -> packet.hops = 0;
3066 client -> packet.xid = client -> xid;
3067 client -> packet.secs = 0;
3071 if (client -> state ==
S_BOUND ||
3074 memcpy (&client -> packet.ciaddr,
3075 lease -> address.iabuf, lease -> address.len);
3076 client -> packet.flags = 0;
3078 memset (&client -> packet.ciaddr, 0,
3079 sizeof client -> packet.ciaddr);
3081 client ->config->bootp_broadcast_always)) &&
3083 client -> packet.flags = 0;
3088 memset (&client -> packet.yiaddr, 0,
3089 sizeof client -> packet.yiaddr);
3090 memset (&client -> packet.siaddr, 0,
3091 sizeof client -> packet.siaddr);
3092 if (client -> state !=
S_BOUND &&
3094 client -> packet.giaddr =
giaddr;
3096 memset (&client -> packet.giaddr, 0,
3097 sizeof client -> packet.giaddr);
3098 if (client -> interface -> hw_address.hlen > 0)
3099 memcpy (client -> packet.chaddr,
3100 &client -> interface -> hw_address.hbuf [1],
3101 (
unsigned)(client -> interface -> hw_address.hlen - 1));
3104 dump_raw ((
unsigned char *)&client -> packet, client -> packet_length);
3124 memset (&client -> packet, 0,
sizeof (client -> packet));
3125 client -> packet_length =
3127 (
struct lease *)0, client, 0,
3130 client -> config -> vendor_space_name);
3139 client -> packet.htype = client ->
interface -> hw_address.hbuf [0];
3140 client -> packet.hlen = client ->
interface -> hw_address.hlen - 1;
3141 client -> packet.hops = 0;
3142 client -> packet.xid = client -> xid;
3143 client -> packet.secs = 0;
3146 client -> packet.flags = 0;
3151 memset (&client -> packet.ciaddr, 0,
3152 sizeof client -> packet.ciaddr);
3153 memset (&client -> packet.yiaddr, 0,
3154 sizeof client -> packet.yiaddr);
3155 memset (&client -> packet.siaddr, 0,
3156 sizeof client -> packet.siaddr);
3157 client -> packet.giaddr =
giaddr;
3158 memcpy (client -> packet.chaddr,
3159 &client -> interface -> hw_address.hbuf [1],
3160 client -> interface -> hw_address.hlen);
3163 dump_raw ((
unsigned char *)&client -> packet, client -> packet_length);
3176 memset (&client -> packet, 0,
sizeof (client -> packet));
3183 client -> packet_length =
3185 (
struct lease *)0, client,
3194 client -> config -> vendor_space_name);
3201 client -> packet.htype = client ->
interface -> hw_address.hbuf [0];
3202 client -> packet.hlen = client ->
interface -> hw_address.hlen - 1;
3203 client -> packet.hops = 0;
3204 client -> packet.xid = random ();
3205 client -> packet.secs = 0;
3206 client -> packet.flags = 0;
3207 memcpy (&client -> packet.ciaddr,
3208 lease -> address.iabuf, lease -> address.len);
3209 memset (&client -> packet.yiaddr, 0,
3210 sizeof client -> packet.yiaddr);
3211 memset (&client -> packet.siaddr, 0,
3212 sizeof client -> packet.siaddr);
3213 client -> packet.giaddr =
giaddr;
3214 memcpy (client -> packet.chaddr,
3215 &client -> interface -> hw_address.hbuf [1],
3216 client -> interface -> hw_address.hlen);
3219 dump_raw ((
unsigned char *)&client -> packet, client -> packet_length);
3226 if (lease -> server_name)
3228 if (lease -> filename)
3243 if (leaseFile != NULL)
3246 if (leaseFile == NULL) {
3258 for (client = ip -> client; client; client = client ->
next) {
3259 for (lp = client -> leases; lp; lp = lp ->
next) {
3262 if (client -> active)
3264 client -> active, 1, 0);
3279 for (client = ip -> client; client; client = client ->
next) {
3280 for (lp = client -> leases; lp; lp = lp ->
next) {
3283 if (client -> active)
3285 client -> active, 1, 0);
3307 const char *name, *dot;
3309 char *preamble = stuff;
3311 memset (&ds, 0,
sizeof ds);
3321 in_options, cfg_options, scope, oc,
MDL)) {
3323 fprintf(leaseFile,
"%soption %s%s%s", preamble,
3329 fprintf(leaseFile,
" %s",
3335 fprintf(leaseFile,
";\n");
3344 const char *preamble)
3385 log_debug(
"Cannot form default DUID from interface %s.", ip->
name);
3389 return ISC_R_UNEXPECTED;
3394 log_fatal(
"Impossible hardware address length at %s:%d.",
MDL);
3411 len = 4 + (hlen - 1);
3415 log_fatal(
"no memory for default DUID!");
3441 return ISC_R_SUCCESS;
3451 if ((duid == NULL) || (duid->
len <= 2))
3454 if (leaseFile == NULL) {
3456 if (leaseFile == NULL) {
3458 return ISC_R_IOERROR;
3469 return ISC_R_NOMEMORY;
3471 stat = fprintf(leaseFile,
"default-duid \"%s\";\n", str);
3474 return ISC_R_IOERROR;
3476 if (fflush(leaseFile) != 0)
3477 return ISC_R_IOERROR;
3479 return ISC_R_SUCCESS;
3485 int rewrite,
int sync)
3493 if (!rewrite && (leases_written++ > 20)) {
3496 return ISC_R_SUCCESS;
3499 if (client == NULL || lease == NULL)
3502 if (leaseFile == NULL) {
3504 if (leaseFile == NULL) {
3506 return ISC_R_IOERROR;
3510 stat = fprintf(leaseFile,
"lease6 {\n");
3512 return ISC_R_IOERROR;
3514 stat = fprintf(leaseFile,
" interface \"%s\";\n",
3517 return ISC_R_IOERROR;
3519 for (ia = lease->
bindings ; ia != NULL ; ia = ia->
next) {
3532 stat = fprintf(leaseFile,
" %s %s {\n",
3535 return ISC_R_IOERROR;
3538 stat = fprintf(leaseFile,
" starts %d;\n"
3543 stat = fprintf(leaseFile,
" starts %d;\n",
3546 return ISC_R_IOERROR;
3548 for (addr = ia->
addrs ; addr != NULL ; addr = addr->
next) {
3550 stat = fprintf(leaseFile,
3554 stat = fprintf(leaseFile,
3555 " iaprefix %s/%d {\n",
3559 return ISC_R_IOERROR;
3561 stat = fprintf(leaseFile,
" starts %d;\n"
3562 " preferred-life %u;\n"
3567 return ISC_R_IOERROR;
3570 write_options(client, addr->
options,
" ");
3572 stat = fprintf(leaseFile,
" }\n");
3574 return ISC_R_IOERROR;
3578 write_options(client, ia->
options,
" ");
3580 stat = fprintf(leaseFile,
" }\n");
3582 return ISC_R_IOERROR;
3586 stat = fprintf(leaseFile,
" released;\n");
3588 return ISC_R_IOERROR;
3592 write_options(client, lease->
options,
" ");
3594 stat = fprintf(leaseFile,
"}\n");
3596 return ISC_R_IOERROR;
3598 if (fflush(leaseFile) != 0)
3599 return ISC_R_IOERROR;
3602 if (fsync(fileno(leaseFile)) < 0) {
3603 log_error(
"write_client_lease: fsync(): %m");
3604 return ISC_R_IOERROR;
3608 return ISC_R_SUCCESS;
3623 if (leases_written++ > 20) {
3631 if (lease -> is_static)
3634 if (leaseFile == NULL) {
3636 if (leaseFile == NULL) {
3643 fprintf (leaseFile,
"lease {\n");
3644 if (lease -> is_bootp) {
3645 fprintf (leaseFile,
" bootp;\n");
3651 fprintf (leaseFile,
" interface \"%s\";\n",
3652 client -> interface -> name);
3657 if (client -> name) {
3658 fprintf (leaseFile,
" name \"%s\";\n", client -> name);
3664 fprintf (leaseFile,
" fixed-address %s;\n",
3665 piaddr (lease -> address));
3670 if (lease -> filename) {
3673 fprintf (leaseFile,
" filename \"%s\";\n", s);
3686 fprintf(leaseFile,
" server-name \"%s\";\n", s);
3695 if (lease -> medium) {
3698 fprintf (leaseFile,
" medium \"%s\";\n", s);
3712 memset (&ds, 0,
sizeof ds);
3714 write_options(client, lease->
options,
" ");
3718 fprintf(leaseFile,
" renew %s\n", tval) < 0)
3723 fprintf(leaseFile,
" rebind %s\n", tval) < 0)
3728 fprintf(leaseFile,
" expire %s\n", tval) < 0)
3731 if (fprintf(leaseFile,
"}\n") < 0)
3734 if (fflush(leaseFile) != 0)
3739 if (!errors && makesure) {
3740 if (fsync (fileno (leaseFile)) < 0) {
3741 log_info (
"write_client_lease: %m");
3746 return errors ? 0 : 1;
3763 for (sl = client -> env; sl; sl =
next) {
3770 if (client -> interface) {
3772 client -> interface -> name);
3776 "",
"client",
"%s", client -> name);
3779 "",
"medium",
"%s", medium ->
string);
3782 client_envadd (client,
"",
"pid",
"%ld", (
long int)getpid ());
3796 memset (&data, 0,
sizeof data);
3799 in_options, cfg_options, scope, oc,
MDL)) {
3809 length = strlen(value);
3813 value, length) == 0) {
3818 "option - discarded",
3841 prefix,
"ip_address",
"%s",
piaddr (lease -> address));
3857 memset (&data, 0,
sizeof data);
3860 (
struct lease *)0, client,
3865 struct iaddr netmask, subnet, broadcast;
3888 (&data, (
struct packet *)0,
3889 (
struct lease *)0, client,
3894 if (broadcast.
len) {
3896 prefix,
"broadcast_address",
3897 "%s",
piaddr (broadcast));
3913 "option - discarded",
3926 "option - discarded",
3938 client_envadd (client, prefix,
"expiry",
"%d", (
int)(lease -> expiry));
3953 req = client->config->requested_options;
3958 for (i = 0 ; req[i] != NULL ; i++) {
3972 char reason [] =
"REASON=NBI";
3973 static char client_path [] = CLIENT_PATH;
3976 int pid, wpid, wstatus;
3979 scriptName = client -> config -> script_name;
3983 envp =
dmalloc (((client ? client -> envc : 2) +
3986 log_error (
"No memory for client script environment.");
3992 for (sp = client_env; sp; sp = sp ->
next) {
3993 envp [i++] = sp ->
string;
3997 for (sp = client -> env; sp; sp = sp ->
next) {
3998 envp [i++] = sp ->
string;
4001 envp [i++] = reason;
4004 envp [i++] = client_path;
4005 envp [i] = (
char *)0;
4008 argv [1] = (
char *)0;
4016 wpid = wait (&wstatus);
4017 }
while (wpid != pid && wpid > 0);
4026 if (leaseFile != NULL)
4028 execve (scriptName, argv, envp);
4029 log_error (
"execve (%s, ...): %m", scriptName);
4034 for (sp = client -> env; sp; sp =
next) {
4042 gettimeofday(&
cur_tv, NULL);
4043 return (WIFEXITED (wstatus) ?
4044 WEXITSTATUS (wstatus) : -WTERMSIG (wstatus));
4048 const char *prefix,
const char *name,
const char *fmt, ...)
4056 va_start (list, fmt);
4057 len = vsnprintf (spbuf,
sizeof spbuf, fmt, list);
4060 val =
dmalloc (strlen (prefix) + strlen (name) + 1 +
4061 len +
sizeof *val,
MDL);
4069 if (len >=
sizeof spbuf) {
4070 va_start (list, fmt);
4071 vsnprintf (s, len + 1, fmt, list);
4075 val ->
next = client -> env;
4076 client -> env = val;
4099 if (j + 1 == buflen)
4109 if (j + 1 == buflen)
4122 static int state = 0;
4140 if ((pid = fork ()) < 0)
4153 (void) open(
"/dev/null", O_RDWR | O_CLOEXEC);
4154 (void) open(
"/dev/null", O_RDWR | O_CLOEXEC);
4155 (void) open(
"/dev/null", O_RDWR | O_CLOEXEC);
4172 pfdesc = open (
path_dhclient_pid, O_CREAT | O_TRUNC | O_WRONLY | O_CLOEXEC, 0644);
4179 pf = fdopen (pfdesc,
"we");
4184 fprintf (pf,
"%ld\n", (
long)getpid ());
4195 for (client = ip -> client; client; client = client ->
next) {
4196 switch (client ->
state) {
4230 client -> xid = random ();
4233 if (client -> active) {
4238 memset (&ds, 0,
sizeof ds);
4240 client -> active -> options,
4244 (
struct lease *)0, client,
4246 client -> active -> options,
4249 memcpy (client -> destination.iabuf,
4251 client -> destination.len = 4;
4258 client -> first_sending =
cur_time;
4259 client -> interval = client -> config -> initial_interval;
4270 if (client -> alias)
4300 if (!strcmp (ip ->
name, tmp ->
name)) {
4304 interface_reference (&ip, last ->
next,
MDL);
4305 interface_dereference (&last ->
next,
MDL);
4307 interface_reference (&last ->
next,
4309 interface_dereference (&ip ->
next,
4314 interface_reference (&ip,
4320 interface_dereference (&ip ->
next,
4326 tmp -> client = ip ->
client;
4327 tmp -> client ->
interface = tmp;
4329 interface_dereference (&ip,
MDL);
4364 if (ip -> client ->
alias)
4366 ip -> client ->
alias);
4378 for (client = ip->
client ; client ; client = client->
next) {
4383 return ISC_R_SUCCESS;
4390 struct packet *packet;
4409 static void shutdown_exit (
void *foo)
4417 #if defined (NSUPDATE)
4434 isc_result_t eresult)
4437 isc_result_t result;
4439 if ((eresult == ISC_R_SUCCESS) &&
4445 if (result == ISC_R_SUCCESS) {
4460 isc_result_t result;
4463 if (client->
ddns_cb != NULL) {
4469 if (ddns_cb != NULL) {
4475 ddns_cb->
cur_func = client_dns_remove_action;
4479 if (result != ISC_R_TIMEDOUT) {
4496 return ISC_R_SUCCESS;
4500 log_info(
"Received signal %d, initiating shutdown.",
4509 for (client = ip -> client; client; client = client -> next) {
4512 return ISC_R_SUCCESS;
4515 return ISC_R_SUCCESS;
4518 if (client -> active &&
4519 client -> active -> expiry >
cur_time) {
4520 #if defined (NSUPDATE)
4542 tv.tv_sec =
cur_tv.tv_sec;
4543 tv.tv_usec =
cur_tv.tv_usec + 1;
4546 return ISC_R_SUCCESS;
4549 #if defined (NSUPDATE)
4560 isc_result_t status = ISC_R_FAILURE;
4562 if ((client != NULL) &&
4563 ((client->
active != NULL) ||
4576 if (status != ISC_R_TIMEDOUT) {
4577 if (client != NULL) {
4615 isc_result_t eresult)
4617 isc_result_t result;
4634 ddns_cb->
cur_func = client_dns_update_action;
4637 if (result == ISC_R_SUCCESS) {
4643 case ISC_R_TIMEDOUT:
4651 if (ddns_cb->
zone != NULL) {
4657 ddns_cb->
cur_func = client_dns_update_action;
4663 tv.tv_usec =
cur_tv.tv_usec;
4665 ddns_cb, NULL, NULL);
4687 if (!client -> sent_options)
4688 return ISC_R_SUCCESS;
4692 return ISC_R_SUCCESS;
4698 (
struct lease *)0, client,
4699 client -> sent_options,
4702 return ISC_R_SUCCESS;
4709 (
struct lease *)0, client,
4710 client -> sent_options,
4713 return ISC_R_SUCCESS;
4719 (
struct lease *)0, client,
4720 client -> sent_options,
4723 return ISC_R_SUCCESS;
4735 memset(&client_identifier, 0,
sizeof(client_identifier));
4759 client_identifier.data,
4760 client_identifier.len);
4778 (client_identifier.data[0] == 255)) {
4783 if (client_identifier.len <= 5)
4784 log_fatal(
"Impossible condition at %s:%d.",
4787 client_identifier.data + 5,
4788 client_identifier.len - 5);
4790 result =
get_dhcid(ddns_cb, ddns_v4_type,
4791 client_identifier.data,
4792 client_identifier.len);
4802 return ISC_R_SUCCESS;
4811 rcode = ISC_R_FAILURE;
4817 if (rcode == ISC_R_SUCCESS) {
4818 rcode = ISC_R_TIMEDOUT;
4841 if (client->
ddns_cb != NULL) {
4848 if (ddns_cb != NULL) {
4849 ddns_cb->
lease = (
void *)client;
4862 ddns_cb->
cur_func = client_dns_update_action;
4867 tv.tv_sec =
cur_tv.tv_sec + offset;
4868 tv.tv_usec =
cur_tv.tv_usec;
4870 ddns_cb, NULL, NULL);
4872 log_error(
"Unable to allocate dns update state for %s",
4881 struct servent *ent;
4895 ent = getservbyname(
"dhcpc",
"udp");
4897 ent = getservbyname(
"bootpc",
"udp");
4902 #ifndef __CYGWIN32__
4926 static int check_domain_name(
const char *ptr,
size_t len,
int dots)
4931 if ((len == 0) || (len > 256))
4936 for (p=ptr; (*p != 0) && (len-- > 0); p++) {
4937 if ((*p ==
'-') || (*p ==
'_')) {
4939 if (((p - ptr) == 0) || (len == 0) || (p[1] ==
'.'))
4941 }
else if (*p ==
'.') {
4945 if ((d <= 0) || (d >= 64))
4948 if ((dots > 0) && (len > 0))
4950 }
else if (isalnum((
unsigned char)*p) == 0) {
4955 return(dots ? -1 : 0);
4958 static int check_domain_name_list(
const char *ptr,
size_t len,
int dots)
4963 if ((ptr == NULL) || (len == 0))
4966 for (p=ptr; (*p != 0) && (len > 0); p++, len--) {
4970 if (check_domain_name(ptr, p - ptr, dots) != 0)
4977 return(check_domain_name(ptr, p - ptr, dots));
4994 #ifdef ACCEPT_LIST_IN_DOMAIN_NAME
4995 return check_domain_name_list(ptr, len, 0);
4997 return check_domain_name(ptr, len, 0);
5002 return check_domain_name(ptr, len, 0);
5005 return check_domain_name_list(ptr, len, 0);
5010 for (; (*ptr != 0) && (len-- > 0); ptr++) {
5011 if(!(isalnum((
unsigned char)*ptr) ||
5012 *ptr ==
'#' || *ptr ==
'%' ||
5013 *ptr ==
'+' || *ptr ==
'-' ||
5014 *ptr ==
'_' || *ptr ==
':' ||
5015 *ptr ==
'.' || *ptr ==
',' ||
5016 *ptr ==
'@' || *ptr ==
'~' ||
5017 *ptr ==
'\\' || *ptr ==
'/' ||
5018 *ptr ==
'[' || *ptr ==
']' ||
5019 *ptr ==
'=' || *ptr ==
' '))
5034 return check_domain_name_list(ptr, len, 0);
5044 add_reject(
struct packet *packet) {
5049 log_fatal (
"no memory for reject list!");
5068 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