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);
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;
1200 client = client->
next) {
1214 if (result != ISC_R_SUCCESS)
1215 log_fatal(
"Can't allocate new generic object: %s\n",
1216 isc_result_totext(result));
1221 if (result != ISC_R_SUCCESS)
1222 log_fatal(
"Can't start OMAPI protocol: %s",
1223 isc_result_totext(result));
1229 #if defined(DEBUG_MEMORY_LEAKAGE) || defined(DEBUG_MALLOC_POOL) || \
1230 defined(DEBUG_MEMORY_LEAKAGE_ON_EXIT)
1231 dmalloc_cutoff_generation = dmalloc_generation;
1232 dmalloc_longterm = dmalloc_outstanding;
1233 dmalloc_outstanding = 0;
1254 const char *s,
const char *
file,
int line)
1300 "dhcp-client-identifier") == 0)) {
1345 client ->
active -> is_bootp ||
1359 client ->
xid = random ();
1392 client -> xid = client ->
packet.xid;
1395 client -> first_sending =
cur_time;
1396 client -> interval = client -> config -> initial_interval;
1439 for (lp = client -> offered_leases; lp; lp =
next) {
1448 picked -> next = NULL;
1453 client -> offered_leases = NULL;
1460 client -> state =
S_INIT;
1467 client ->
new = picked;
1485 client -> first_sending =
cur_time;
1486 client -> interval = client -> config -> initial_interval;
1490 client -> xid = client ->
packet.xid;
1513 for (client = ip -> client; client; client = client -> next) {
1514 if (client -> xid == packet -> raw -> xid)
1518 (packet -> interface -> hw_address.hlen - 1 !=
1519 packet -> raw -> hlen) ||
1520 (memcmp (&packet -> interface -> hw_address.hbuf [1],
1521 packet -> raw -> chaddr, packet -> raw -> hlen))) {
1523 log_debug (
"DHCPACK in wrong transaction.");
1538 log_info (
"DHCPACK from %s (xid=0x%x)",
piaddr (packet -> client_addr), ntohl(client -> xid));
1542 log_info (
"packet_to_lease failed.");
1546 client ->
new = lease;
1554 memset (&ds, 0,
sizeof ds);
1557 packet -> options, client ->
new -> options,
1562 client ->
new -> expiry = 0;
1565 client ->
new -> expiry = 0;
1570 log_error (
"no expiry time on offered lease.");
1576 tv.tv_sec =
cur_tv.tv_sec;
1577 tv.tv_usec =
cur_tv.tv_usec + 500000;
1579 if (tv.tv_usec >= 1000000) {
1581 tv.tv_usec -= 1000000;
1600 packet -> options, client ->
new -> options,
1605 client ->
new -> renewal = 0;
1608 client ->
new -> renewal = 0;
1611 if (!client ->
new -> renewal)
1612 client ->
new -> renewal = client ->
new -> expiry / 2 + 1;
1614 if (client ->
new -> renewal <= 0)
1615 client ->
new -> renewal =
TIME_MAX;
1620 (((random() % client->
new->
renewal) + 3) / 4);
1627 packet -> options, client ->
new -> options,
1632 client ->
new -> rebind = 0;
1635 client ->
new -> rebind = 0;
1637 if (client ->
new -> rebind <= 0) {
1638 if (client ->
new -> expiry <=
TIME_MAX / 7)
1639 client ->
new -> rebind =
1640 client ->
new -> expiry * 7 / 8;
1642 client ->
new -> rebind =
1643 client ->
new -> expiry / 8 * 7;
1648 if (client ->
new -> renewal > client ->
new -> rebind) {
1649 if (client ->
new -> rebind <=
TIME_MAX / 3)
1650 client ->
new -> renewal =
1651 client ->
new -> rebind * 3 / 4;
1653 client ->
new -> renewal =
1654 client ->
new -> rebind / 4 * 3;
1657 client ->
new -> expiry +=
cur_time;
1659 if (client ->
new -> expiry <
cur_time)
1660 client ->
new -> expiry =
TIME_MAX;
1661 client ->
new -> renewal +=
cur_time;
1662 if (client ->
new -> renewal <
cur_time)
1663 client ->
new -> renewal =
TIME_MAX;
1664 client ->
new -> rebind +=
cur_time;
1665 if (client ->
new -> rebind <
cur_time)
1666 client ->
new -> rebind =
TIME_MAX;
1684 client->new->medium);
1685 if (client->active && client->state !=
S_REBOOTING)
1702 log_info(
"Unable to obtain a lease on first "
1703 "try (declined). Exiting.");
1713 if (!client->last_write ||
1720 client->active = client->new;
1724 tv.tv_sec = client->active->renewal;
1725 tv.tv_usec = ((client->active->renewal -
cur_tv.tv_sec) > 1) ?
1726 random() % 1000000 :
cur_tv.tv_usec;
1729 log_info(
"bound to %s -- renewal in %ld seconds.",
1730 piaddr(client->active->address),
1731 (
long)(client->active->renewal -
cur_time));
1735 #if defined (NSUPDATE)
1736 if (client->config->do_forward_update)
1757 client -> xid = client ->
packet.xid;
1759 memset (&ds, 0,
sizeof ds);
1765 client -> active -> options,
1768 memcpy (client -> destination.iabuf, ds.
data, 4);
1769 client -> destination.len = 4;
1777 client -> first_sending =
cur_time;
1778 client -> interval = client -> config -> initial_interval;
1839 for (ap = packet -> interface -> client -> config -> reject_list;
1840 ap; ap = ap ->
next) {
1849 log_info(
"BOOTREPLY from %s rejected by rule %s "
1850 "mask %s.",
piaddr(packet->client_addr),
1864 void (*handler) (
struct packet *);
1891 for (ap = packet ->
interface -> client -> config -> reject_list;
1892 ap; ap = ap -> next) {
1901 log_info(
"%s from %s rejected by rule %s mask %s.",
1902 type,
piaddr(packet->client_addr),
1907 (*handler) (packet);
1915 char addrbuf[
sizeof(
"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")];
1923 ap ; ap = ap->
next) {
1926 log_info(
"%s from %s rejected by rule %s",
1942 log_info(
"RCV: %s message on %s from %s.",
1953 client = client->
next) {
1962 log_info(
"Packet received, but nothing done with it.");
1967 struct packet *packet;
1975 const char *
name = packet -> packet_type ?
"DHCPOFFER" :
"BOOTREPLY";
1984 for (client = ip -> client; client; client = client -> next)
1985 if (client -> xid == packet -> raw -> xid)
1992 (packet -> interface -> hw_address.hlen - 1 !=
1993 packet -> raw -> hlen) ||
1994 (memcmp (&packet -> interface -> hw_address.hbuf [1],
1995 packet -> raw -> chaddr, packet -> raw -> hlen))) {
1997 log_debug (
"%s in wrong transaction.", name);
2002 sprintf (obuf,
"%s from %s", name,
piaddr (packet -> client_addr));
2010 for (i = 0 ; req[i] != NULL ; i++) {
2017 option_code_hash_lookup(&option,
2022 log_info(
"%s: no %s option.", obuf,
2025 log_info(
"%s: no unknown-%u option.",
2036 for (lease = client -> offered_leases; lease; lease = lease -> next) {
2037 if (lease -> address.len ==
sizeof packet -> raw -> yiaddr &&
2038 !memcmp (lease -> address.iabuf,
2039 &packet -> raw -> yiaddr, lease -> address.len)) {
2047 log_info (
"%s: packet_to_lease failed.", obuf);
2053 if (!packet -> options_valid || !packet -> packet_type)
2054 lease -> is_bootp = 1;
2057 lease -> medium = client -> medium;
2060 stop_selecting = (client -> first_sending +
2061 client -> config -> select_interval);
2065 if (lease -> address.len == client -> requested_address.len &&
2066 !memcmp (lease -> address.iabuf,
2067 client -> requested_address.iabuf,
2068 client -> requested_address.len)) {
2069 lease -> next = client -> offered_leases;
2070 client -> offered_leases = lease;
2074 if (!client -> offered_leases)
2075 client -> offered_leases = lease;
2077 for (lp = client -> offered_leases; lp ->
next;
2087 if (stop_selecting <=
cur_tv.tv_sec)
2090 tv.tv_sec = stop_selecting;
2091 tv.tv_usec =
cur_tv.tv_usec;
2102 struct packet *packet;
2114 log_error(
"packet_to_lease: no memory to record lease.\n");
2118 memset(lease, 0,
sizeof(*lease));
2123 lease->address.len =
sizeof(packet->raw->yiaddr);
2124 memcpy(lease->address.iabuf, &packet->raw->yiaddr,
2125 lease->address.len);
2127 lease->next_srv_addr.len =
sizeof(packet->raw->siaddr);
2128 memcpy(lease->next_srv_addr.iabuf, &packet->raw->siaddr,
2129 lease->next_srv_addr.len);
2131 memset(&data, 0,
sizeof(data));
2133 if (client -> config -> vendor_space_name) {
2139 client -> config -> vendor_space_name &&
2141 (
struct lease *)0, client,
2145 if (!option_code_hash_lookup(&option,
2149 "option (%s:%d).",
MDL);
2153 client -> config -> vendor_space_name
2179 if (!(i & 2) && packet -> raw -> sname [0]) {
2183 if (!packet -> raw -> sname [len])
2187 log_error (
"dhcpoffer: no memory for server name.\n");
2192 packet -> raw -> sname, len);
2198 if (!(i & 1) && packet -> raw ->
file [0]) {
2202 if (!packet -> raw ->
file [len])
2206 log_error (
"dhcpoffer: no memory for filename.\n");
2211 packet -> raw ->
file, len);
2217 client, lease->options, lease->options,
2225 struct packet *packet;
2231 for (client = ip -> client; client; client = client ->
next)
2232 if (client ->
xid == packet -> raw ->
xid)
2238 (packet ->
interface -> hw_address.hlen - 1 !=
2239 packet -> raw -> hlen) ||
2240 (memcmp (&packet ->
interface -> hw_address.hbuf [1],
2241 packet -> raw -> chaddr, packet -> raw -> hlen))) {
2243 log_debug (
"DHCPNAK in wrong transaction.");
2258 log_info (
"DHCPNAK from %s (xid=0x%x)",
piaddr (packet -> client_addr), ntohl(client ->
xid));
2262 log_info (
"DHCPNAK with no active lease.\n");
2295 client -> state =
S_INIT;
2314 interval =
cur_time - client -> first_sending;
2318 if (interval > client -> config ->
timeout) {
2326 if (!client -> offered_leases &&
2327 client -> config -> media) {
2330 if (client -> medium) {
2331 client -> medium = client -> medium -> next;
2334 if (!client -> medium) {
2336 log_fatal (
"No valid media types for %s!",
2337 client -> interface -> name);
2339 client -> config -> media;
2343 log_info (
"Trying medium \"%s\" %d",
2344 client -> medium ->
string, increase);
2372 if (
cur_time + client -> interval >
2373 client -> first_sending + client -> config ->
timeout)
2374 client -> interval =
2375 (client -> first_sending +
2379 if (interval < 65536)
2380 client -> packet.secs = htons (interval);
2382 client -> packet.secs = htons (65535);
2383 client -> secs = client -> packet.secs;
2385 log_info (
"DHCPDISCOVER on %s to %s port %d interval %ld (xid=0x%x)",
2386 client -> name ? client -> name : client -> interface -> name,
2388 ntohs (
sockaddr_broadcast.sin_port), (
long)(client -> interval), ntohl(client -> xid));
2395 log_error(
"%s:%d: Failed to send %d byte long packet over %s "
2407 tv.tv_usec = client->
interval > 1 ? random() % 1000000 :
cur_tv.tv_usec;
2424 loop = lp = client -> active;
2426 log_info (
"No DHCPOFFERS received.");
2430 if (!client -> active && client -> leases)
2434 while (client -> active) {
2435 if (client -> active -> expiry >
cur_time) {
2436 log_info (
"Trying recorded lease %s",
2437 piaddr (client -> active -> address));
2441 client -> active -> medium);
2444 if (client -> alias)
2452 if (cur_time < client -> active -> renewal) {
2454 log_info (
"bound: renewal in %ld %s.",
2455 (
long)(client -> active -> renewal -
2460 random() % 1000000 :
2465 log_info (
"bound: immediate renewal.");
2475 if (!client -> leases) {
2476 client -> leases = client -> active;
2484 for (lp = client -> leases; lp ->
next; lp = lp ->
next)
2486 lp ->
next = client -> active;
2490 client -> active = client -> leases;
2491 client -> leases = client -> leases ->
next;
2496 if (client -> active == loop)
2499 loop = client -> active;
2507 log_info (
"Unable to obtain a lease on first try.%s",
2512 log_info (
"No working leases in persistent database - sleeping.");
2514 if (client -> alias)
2517 client -> state =
S_INIT;
2520 tv.tv_usec = ((tv.tv_sec -
cur_tv.tv_sec) > 1) ?
2521 random() % 1000000 :
cur_tv.tv_usec;
2533 struct sockaddr_in destination;
2534 struct in_addr from;
2538 interval =
cur_time - client -> first_sending;
2552 interval > client -> config -> reboot_timeout) {
2554 client -> state =
S_INIT;
2563 !client -> medium &&
2564 client -> active -> medium ) {
2565 script_init (client,
"MEDIUM", client -> active -> medium);
2572 client -> medium = client -> active -> medium;
2578 cur_time > client -> active -> expiry) {
2583 if (client -> alias)
2591 if (client -> alias)
2596 client -> state =
S_INIT;
2602 if (!client -> interval)
2603 client -> interval = client -> config -> initial_interval;
2605 client -> interval += ((random () >> 2) %
2606 (2 * client -> interval));
2610 if (client -> interval >
2611 client -> config -> backoff_cutoff)
2612 client -> interval =
2613 ((client -> config -> backoff_cutoff / 2)
2614 + ((random () >> 2) %
2615 client -> config -> backoff_cutoff));
2620 cur_time + client -> interval > client -> active -> expiry)
2621 client -> interval =
2622 client -> active -> expiry -
cur_time + 1;
2628 cur_time > client -> active -> rebind)
2631 memcpy (&destination.sin_addr.s_addr,
2632 client -> destination.iabuf,
2633 sizeof destination.sin_addr.s_addr);
2635 destination.sin_family = AF_INET;
2637 destination.sin_len =
sizeof destination;
2642 memcpy (&from, client -> active -> address.iabuf,
2645 from.s_addr = INADDR_ANY;
2649 client -> packet.secs = client -> secs;
2651 if (interval < 65536)
2652 client -> packet.secs = htons (interval);
2654 client -> packet.secs = htons (65535);
2657 log_info (
"DHCPREQUEST on %s to %s port %d (xid=0x%x)",
2658 client -> name ? client -> name : client -> interface -> name,
2659 inet_ntoa (destination.sin_addr),
2660 ntohs (destination.sin_port), ntohl(client -> xid));
2662 if (destination.sin_addr.s_addr != INADDR_BROADCAST &&
2664 #if defined(SO_BINDTODEVICE)
2668 log_error(
"%s:%d: Failed to bind fallback interface"
2676 log_error(
"%s:%d: Failed to send %d byte long packet "
2677 "over %s interface.",
MDL,
2681 #if defined(SO_BINDTODEVICE)
2683 SO_BINDTODEVICE, NULL, 0) < 0) {
2684 log_fatal(
"%s:%d: Failed to unbind fallback interface:"
2695 log_error(
"%s:%d: Failed to send %d byte long packet"
2696 " over %s interface.",
MDL,
2703 tv.tv_usec = ((tv.tv_sec -
cur_tv.tv_sec) > 1) ?
2704 random() % 1000000 :
cur_tv.tv_usec;
2715 log_info (
"DHCPDECLINE on %s to %s port %d (xid=0x%x)",
2725 log_error(
"%s:%d: Failed to send %d byte long packet over %s"
2737 struct sockaddr_in destination;
2738 struct in_addr from;
2740 memcpy (&from, client -> active -> address.iabuf,
2742 memcpy (&destination.sin_addr.s_addr,
2743 client -> destination.iabuf,
2744 sizeof destination.sin_addr.s_addr);
2746 destination.sin_family = AF_INET;
2748 destination.sin_len =
sizeof destination;
2753 client -> active -> expiry =
2754 client -> active -> renewal =
2755 client -> active -> rebind =
cur_time;
2757 log_error (
"Can't release lease: lease write failed.");
2761 log_info (
"DHCPRELEASE on %s to %s port %d (xid=0x%x)",
2762 client -> name ? client -> name : client -> interface -> name,
2763 inet_ntoa (destination.sin_addr),
2764 ntohs (destination.sin_port), ntohl(client -> xid));
2767 #if defined(SO_BINDTODEVICE)
2771 log_error(
"%s:%d: Failed to bind fallback interface"
2779 log_error(
"%s:%d: Failed to send %d byte long packet"
2780 " over %s interface.",
MDL,
2784 #if defined(SO_BINDTODEVICE)
2786 SO_BINDTODEVICE, NULL, 0) < 0) {
2787 log_fatal(
"%s:%d: Failed to unbind fallback interface:"
2797 log_error (
"%s:%d: Failed to send %d byte long packet"
2798 " over %s interface.",
MDL,
2815 struct buffer *bp = NULL;
2838 log_error (
"can't make requested address cache.");
2864 for (i = 0 ; prl[i] != NULL ; i++)
2869 log_error(
"can't make parameter list buffer.");
2874 for (i = 0 ; prl[i] != NULL ; i++)
2878 if (!(option_code_hash_lookup(&option,
2903 memset(&client_identifier, 0,
sizeof(client_identifier));
2906 client_identifier.
len,
MDL))
2907 log_fatal(
"no memory for default DUID!");
2925 memcpy(&client_identifier.
buffer->
data + 5 - hw_len,
2930 memcpy(&client_identifier.
buffer->
data+(1+4),
2937 (u_int8_t *)client_identifier.
data,
2938 client_identifier.
len,
2940 log_error (
"can't make requested client id cache..");
2951 (lease ? lease->
options : NULL),
2964 memset (&client -> packet, 0,
sizeof (client -> packet));
2968 lease ? &lease -> address : (
struct iaddr *)0,
2969 client -> config -> requested_options,
2973 client -> packet_length =
2975 (
struct lease *)0, client,
2984 client -> config -> vendor_space_name);
2991 client -> packet.htype = client ->
interface -> hw_address.hbuf [0];
2992 client -> packet.hlen = client ->
interface -> hw_address.hlen - 1;
2993 client -> packet.hops = 0;
2994 client -> packet.xid = random ();
2995 client -> packet.secs = 0;
2999 client -> packet.flags = 0;
3003 memset (&(client -> packet.ciaddr),
3004 0,
sizeof client -> packet.ciaddr);
3005 memset (&(client -> packet.yiaddr),
3006 0,
sizeof client -> packet.yiaddr);
3007 memset (&(client -> packet.siaddr),
3008 0,
sizeof client -> packet.siaddr);
3009 client -> packet.giaddr =
giaddr;
3010 if (client -> interface -> hw_address.hlen > 0)
3011 memcpy (client -> packet.chaddr,
3012 &client -> interface -> hw_address.hbuf [1],
3013 (
unsigned)(client -> interface -> hw_address.hlen - 1));
3016 dump_raw ((
unsigned char *)&client -> packet, client -> packet_length);
3028 memset (&client -> packet, 0,
sizeof (client -> packet));
3036 if (client -> sent_options)
3043 : (
struct iaddr *)0),
3044 client -> config -> requested_options,
3045 &client -> sent_options);
3048 client -> packet_length =
3050 (
struct lease *)0, client,
3053 client -> sent_options,
3059 client -> config -> vendor_space_name);
3065 client -> packet.htype = client ->
interface -> hw_address.hbuf [0];
3066 client -> packet.hlen = client ->
interface -> hw_address.hlen - 1;
3067 client -> packet.hops = 0;
3068 client -> packet.xid = client -> xid;
3069 client -> packet.secs = 0;
3073 if (client -> state ==
S_BOUND ||
3076 memcpy (&client -> packet.ciaddr,
3077 lease -> address.iabuf, lease -> address.len);
3078 client -> packet.flags = 0;
3080 memset (&client -> packet.ciaddr, 0,
3081 sizeof client -> packet.ciaddr);
3083 client ->config->bootp_broadcast_always)) &&
3085 client -> packet.flags = 0;
3090 memset (&client -> packet.yiaddr, 0,
3091 sizeof client -> packet.yiaddr);
3092 memset (&client -> packet.siaddr, 0,
3093 sizeof client -> packet.siaddr);
3094 if (client -> state !=
S_BOUND &&
3096 client -> packet.giaddr =
giaddr;
3098 memset (&client -> packet.giaddr, 0,
3099 sizeof client -> packet.giaddr);
3100 if (client -> interface -> hw_address.hlen > 0)
3101 memcpy (client -> packet.chaddr,
3102 &client -> interface -> hw_address.hbuf [1],
3103 (
unsigned)(client -> interface -> hw_address.hlen - 1));
3106 dump_raw ((
unsigned char *)&client -> packet, client -> packet_length);
3126 memset (&client -> packet, 0,
sizeof (client -> packet));
3127 client -> packet_length =
3129 (
struct lease *)0, client, 0,
3132 client -> config -> vendor_space_name);
3141 client -> packet.htype = client ->
interface -> hw_address.hbuf [0];
3142 client -> packet.hlen = client ->
interface -> hw_address.hlen - 1;
3143 client -> packet.hops = 0;
3144 client -> packet.xid = client -> xid;
3145 client -> packet.secs = 0;
3148 client -> packet.flags = 0;
3153 memset (&client -> packet.ciaddr, 0,
3154 sizeof client -> packet.ciaddr);
3155 memset (&client -> packet.yiaddr, 0,
3156 sizeof client -> packet.yiaddr);
3157 memset (&client -> packet.siaddr, 0,
3158 sizeof client -> packet.siaddr);
3159 client -> packet.giaddr =
giaddr;
3160 memcpy (client -> packet.chaddr,
3161 &client -> interface -> hw_address.hbuf [1],
3162 client -> interface -> hw_address.hlen);
3165 dump_raw ((
unsigned char *)&client -> packet, client -> packet_length);
3178 memset (&client -> packet, 0,
sizeof (client -> packet));
3185 client -> packet_length =
3187 (
struct lease *)0, client,
3196 client -> config -> vendor_space_name);
3203 client -> packet.htype = client ->
interface -> hw_address.hbuf [0];
3204 client -> packet.hlen = client ->
interface -> hw_address.hlen - 1;
3205 client -> packet.hops = 0;
3206 client -> packet.xid = random ();
3207 client -> packet.secs = 0;
3208 client -> packet.flags = 0;
3209 memcpy (&client -> packet.ciaddr,
3210 lease -> address.iabuf, lease -> address.len);
3211 memset (&client -> packet.yiaddr, 0,
3212 sizeof client -> packet.yiaddr);
3213 memset (&client -> packet.siaddr, 0,
3214 sizeof client -> packet.siaddr);
3215 client -> packet.giaddr =
giaddr;
3216 memcpy (client -> packet.chaddr,
3217 &client -> interface -> hw_address.hbuf [1],
3218 client -> interface -> hw_address.hlen);
3221 dump_raw ((
unsigned char *)&client -> packet, client -> packet_length);
3228 if (lease -> server_name)
3230 if (lease -> filename)
3245 if (leaseFile != NULL)
3248 if (leaseFile == NULL) {
3260 for (client = ip -> client; client; client = client ->
next) {
3261 for (lp = client -> leases; lp; lp = lp ->
next) {
3264 if (client -> active)
3266 client -> active, 1, 0);
3281 for (client = ip -> client; client; client = client ->
next) {
3282 for (lp = client -> leases; lp; lp = lp ->
next) {
3285 if (client -> active)
3287 client -> active, 1, 0);
3309 const char *name, *dot;
3311 char *preamble = stuff;
3313 memset (&ds, 0,
sizeof ds);
3323 in_options, cfg_options, scope, oc,
MDL)) {
3325 fprintf(leaseFile,
"%soption %s%s%s", preamble,
3331 fprintf(leaseFile,
" %s",
3337 fprintf(leaseFile,
";\n");
3346 const char *preamble)
3386 log_debug(
"Cannot form default DUID from interface %s.", ip->
name);
3390 return ISC_R_UNEXPECTED;
3395 log_fatal(
"Impossible hardware address length at %s:%d.",
MDL);
3411 log_fatal(
"no memory for default DUID!");
3437 return ISC_R_SUCCESS;
3447 if ((duid == NULL) || (duid->
len <= 2))
3450 if (leaseFile == NULL) {
3452 if (leaseFile == NULL) {
3454 return ISC_R_IOERROR;
3465 return ISC_R_NOMEMORY;
3467 stat = fprintf(leaseFile,
"default-duid \"%s\";\n", str);
3470 return ISC_R_IOERROR;
3472 if (fflush(leaseFile) != 0)
3473 return ISC_R_IOERROR;
3475 return ISC_R_SUCCESS;
3481 int rewrite,
int sync)
3489 if (!rewrite && (leases_written++ > 20)) {
3492 return ISC_R_SUCCESS;
3495 if (client == NULL || lease == NULL)
3498 if (leaseFile == NULL) {
3500 if (leaseFile == NULL) {
3502 return ISC_R_IOERROR;
3506 stat = fprintf(leaseFile,
"lease6 {\n");
3508 return ISC_R_IOERROR;
3510 stat = fprintf(leaseFile,
" interface \"%s\";\n",
3513 return ISC_R_IOERROR;
3515 for (ia = lease->
bindings ; ia != NULL ; ia = ia->
next) {
3528 stat = fprintf(leaseFile,
" %s %s {\n",
3531 return ISC_R_IOERROR;
3534 stat = fprintf(leaseFile,
" starts %d;\n"
3539 stat = fprintf(leaseFile,
" starts %d;\n",
3542 return ISC_R_IOERROR;
3544 for (addr = ia->
addrs ; addr != NULL ; addr = addr->
next) {
3546 stat = fprintf(leaseFile,
3550 stat = fprintf(leaseFile,
3551 " iaprefix %s/%d {\n",
3555 return ISC_R_IOERROR;
3557 stat = fprintf(leaseFile,
" starts %d;\n"
3558 " preferred-life %u;\n"
3563 return ISC_R_IOERROR;
3566 write_options(client, addr->
options,
" ");
3568 stat = fprintf(leaseFile,
" }\n");
3570 return ISC_R_IOERROR;
3574 write_options(client, ia->
options,
" ");
3576 stat = fprintf(leaseFile,
" }\n");
3578 return ISC_R_IOERROR;
3582 stat = fprintf(leaseFile,
" released;\n");
3584 return ISC_R_IOERROR;
3588 write_options(client, lease->
options,
" ");
3590 stat = fprintf(leaseFile,
"}\n");
3592 return ISC_R_IOERROR;
3594 if (fflush(leaseFile) != 0)
3595 return ISC_R_IOERROR;
3598 if (fsync(fileno(leaseFile)) < 0) {
3599 log_error(
"write_client_lease: fsync(): %m");
3600 return ISC_R_IOERROR;
3604 return ISC_R_SUCCESS;
3619 if (leases_written++ > 20) {
3627 if (lease -> is_static)
3630 if (leaseFile == NULL) {
3632 if (leaseFile == NULL) {
3639 fprintf (leaseFile,
"lease {\n");
3640 if (lease -> is_bootp) {
3641 fprintf (leaseFile,
" bootp;\n");
3647 fprintf (leaseFile,
" interface \"%s\";\n",
3648 client -> interface -> name);
3653 if (client -> name) {
3654 fprintf (leaseFile,
" name \"%s\";\n", client -> name);
3660 fprintf (leaseFile,
" fixed-address %s;\n",
3661 piaddr (lease -> address));
3666 if (lease -> filename) {
3669 fprintf (leaseFile,
" filename \"%s\";\n", s);
3682 fprintf(leaseFile,
" server-name \"%s\";\n", s);
3691 if (lease -> medium) {
3694 fprintf (leaseFile,
" medium \"%s\";\n", s);
3708 memset (&ds, 0,
sizeof ds);
3710 write_options(client, lease->
options,
" ");
3714 fprintf(leaseFile,
" renew %s\n", tval) < 0)
3719 fprintf(leaseFile,
" rebind %s\n", tval) < 0)
3724 fprintf(leaseFile,
" expire %s\n", tval) < 0)
3727 if (fprintf(leaseFile,
"}\n") < 0)
3730 if (fflush(leaseFile) != 0)
3735 if (!errors && makesure) {
3736 if (fsync (fileno (leaseFile)) < 0) {
3737 log_info (
"write_client_lease: %m");
3742 return errors ? 0 : 1;
3759 for (sl = client -> env; sl; sl =
next) {
3766 if (client -> interface) {
3768 client -> interface -> name);
3772 "",
"client",
"%s", client -> name);
3775 "",
"medium",
"%s", medium ->
string);
3778 client_envadd (client,
"",
"pid",
"%ld", (
long int)getpid ());
3792 memset (&data, 0,
sizeof data);
3795 in_options, cfg_options, scope, oc,
MDL)) {
3805 length = strlen(value);
3809 value, length) == 0) {
3814 "option - discarded",
3837 prefix,
"ip_address",
"%s",
piaddr (lease -> address));
3853 memset (&data, 0,
sizeof data);
3856 (
struct lease *)0, client,
3861 struct iaddr netmask, subnet, broadcast;
3884 (&data, (
struct packet *)0,
3885 (
struct lease *)0, client,
3890 if (broadcast.
len) {
3892 prefix,
"broadcast_address",
3893 "%s",
piaddr (broadcast));
3909 "option - discarded",
3922 "option - discarded",
3934 client_envadd (client, prefix,
"expiry",
"%d", (
int)(lease -> expiry));
3949 req = client->config->requested_options;
3954 for (i = 0 ; req[i] != NULL ; i++) {
3968 char reason [] =
"REASON=NBI";
3969 static char client_path [] = CLIENT_PATH;
3972 int pid, wpid, wstatus;
3975 scriptName = client -> config -> script_name;
3979 envp =
dmalloc (((client ? client -> envc : 2) +
3982 log_error (
"No memory for client script environment.");
3988 for (sp = client_env; sp; sp = sp ->
next) {
3989 envp [i++] = sp ->
string;
3993 for (sp = client -> env; sp; sp = sp ->
next) {
3994 envp [i++] = sp ->
string;
3997 envp [i++] = reason;
4000 envp [i++] = client_path;
4001 envp [i] = (
char *)0;
4004 argv [1] = (
char *)0;
4012 wpid = wait (&wstatus);
4013 }
while (wpid != pid && wpid > 0);
4022 if (leaseFile != NULL)
4024 execve (scriptName, argv, envp);
4025 log_error (
"execve (%s, ...): %m", scriptName);
4030 for (sp = client -> env; sp; sp =
next) {
4038 gettimeofday(&
cur_tv, NULL);
4039 return (WIFEXITED (wstatus) ?
4040 WEXITSTATUS (wstatus) : -WTERMSIG (wstatus));
4044 const char *prefix,
const char *name,
const char *fmt, ...)
4052 va_start (list, fmt);
4053 len = vsnprintf (spbuf,
sizeof spbuf, fmt, list);
4056 val =
dmalloc (strlen (prefix) + strlen (name) + 1 +
4057 len +
sizeof *val,
MDL);
4065 if (len >=
sizeof spbuf) {
4066 va_start (list, fmt);
4067 vsnprintf (s, len + 1, fmt, list);
4071 val ->
next = client -> env;
4072 client -> env = val;
4095 if (j + 1 == buflen)
4105 if (j + 1 == buflen)
4118 static int state = 0;
4136 if ((pid = fork ()) < 0)
4149 (void) open(
"/dev/null", O_RDWR | O_CLOEXEC);
4150 (void) open(
"/dev/null", O_RDWR | O_CLOEXEC);
4151 (void) open(
"/dev/null", O_RDWR | O_CLOEXEC);
4168 pfdesc = open (
path_dhclient_pid, O_CREAT | O_TRUNC | O_WRONLY | O_CLOEXEC, 0644);
4175 pf = fdopen (pfdesc,
"we");
4180 fprintf (pf,
"%ld\n", (
long)getpid ());
4191 for (client = ip -> client; client; client = client ->
next) {
4192 switch (client ->
state) {
4226 client -> xid = random ();
4229 if (client -> active) {
4234 memset (&ds, 0,
sizeof ds);
4236 client -> active -> options,
4240 (
struct lease *)0, client,
4242 client -> active -> options,
4245 memcpy (client -> destination.iabuf,
4247 client -> destination.len = 4;
4254 client -> first_sending =
cur_time;
4255 client -> interval = client -> config -> initial_interval;
4266 if (client -> alias)
4296 if (!strcmp (ip ->
name, tmp ->
name)) {
4300 interface_reference (&ip, last ->
next,
MDL);
4301 interface_dereference (&last ->
next,
MDL);
4303 interface_reference (&last ->
next,
4305 interface_dereference (&ip ->
next,
4310 interface_reference (&ip,
4316 interface_dereference (&ip ->
next,
4322 tmp -> client = ip ->
client;
4323 tmp -> client ->
interface = tmp;
4325 interface_dereference (&ip,
MDL);
4360 if (ip -> client ->
alias)
4362 ip -> client ->
alias);
4374 for (client = ip->
client ; client ; client = client->
next) {
4379 return ISC_R_SUCCESS;
4386 struct packet *packet;
4405 static void shutdown_exit (
void *foo)
4413 #if defined (NSUPDATE)
4430 isc_result_t eresult)
4433 isc_result_t result;
4435 if ((eresult == ISC_R_SUCCESS) &&
4441 if (result == ISC_R_SUCCESS) {
4456 isc_result_t result;
4459 if (client->
ddns_cb != NULL) {
4465 if (ddns_cb != NULL) {
4471 ddns_cb->
cur_func = client_dns_remove_action;
4475 if (result != ISC_R_TIMEDOUT) {
4492 return ISC_R_SUCCESS;
4496 log_info(
"Received signal %d, initiating shutdown.",
4505 for (client = ip -> client; client; client = client -> next) {
4508 return ISC_R_SUCCESS;
4511 return ISC_R_SUCCESS;
4514 if (client -> active &&
4515 client -> active -> expiry >
cur_time) {
4516 #if defined (NSUPDATE)
4538 tv.tv_sec =
cur_tv.tv_sec;
4539 tv.tv_usec =
cur_tv.tv_usec + 1;
4542 return ISC_R_SUCCESS;
4545 #if defined (NSUPDATE)
4556 isc_result_t status = ISC_R_FAILURE;
4558 if ((client != NULL) &&
4559 ((client->
active != NULL) ||
4572 if (status != ISC_R_TIMEDOUT) {
4573 if (client != NULL) {
4611 isc_result_t eresult)
4613 isc_result_t result;
4630 ddns_cb->
cur_func = client_dns_update_action;
4633 if (result == ISC_R_SUCCESS) {
4639 case ISC_R_TIMEDOUT:
4647 if (ddns_cb->
zone != NULL) {
4653 ddns_cb->
cur_func = client_dns_update_action;
4659 tv.tv_usec =
cur_tv.tv_usec;
4661 ddns_cb, NULL, NULL);
4683 if (!client -> sent_options)
4684 return ISC_R_SUCCESS;
4688 return ISC_R_SUCCESS;
4694 (
struct lease *)0, client,
4695 client -> sent_options,
4698 return ISC_R_SUCCESS;
4705 (
struct lease *)0, client,
4706 client -> sent_options,
4709 return ISC_R_SUCCESS;
4715 (
struct lease *)0, client,
4716 client -> sent_options,
4719 return ISC_R_SUCCESS;
4731 memset(&client_identifier, 0,
sizeof(client_identifier));
4755 client_identifier.data,
4756 client_identifier.len);
4774 (client_identifier.data[0] == 255)) {
4779 if (client_identifier.len <= 5)
4780 log_fatal(
"Impossible condition at %s:%d.",
4783 client_identifier.data + 5,
4784 client_identifier.len - 5);
4786 result =
get_dhcid(ddns_cb, ddns_v4_type,
4787 client_identifier.data,
4788 client_identifier.len);
4798 return ISC_R_SUCCESS;
4807 rcode = ISC_R_FAILURE;
4813 if (rcode == ISC_R_SUCCESS) {
4814 rcode = ISC_R_TIMEDOUT;
4837 if (client->
ddns_cb != NULL) {
4844 if (ddns_cb != NULL) {
4845 ddns_cb->
lease = (
void *)client;
4858 ddns_cb->
cur_func = client_dns_update_action;
4863 tv.tv_sec =
cur_tv.tv_sec + offset;
4864 tv.tv_usec =
cur_tv.tv_usec;
4866 ddns_cb, NULL, NULL);
4868 log_error(
"Unable to allocate dns update state for %s",
4877 struct servent *ent;
4891 ent = getservbyname(
"dhcpc",
"udp");
4893 ent = getservbyname(
"bootpc",
"udp");
4898 #ifndef __CYGWIN32__
4922 static int check_domain_name(
const char *ptr,
size_t len,
int dots)
4927 if ((len == 0) || (len > 256))
4932 for (p=ptr; (*p != 0) && (len-- > 0); p++) {
4933 if ((*p ==
'-') || (*p ==
'_')) {
4935 if (((p - ptr) == 0) || (len == 0) || (p[1] ==
'.'))
4937 }
else if (*p ==
'.') {
4941 if ((d <= 0) || (d >= 64))
4944 if ((dots > 0) && (len > 0))
4946 }
else if (isalnum((
unsigned char)*p) == 0) {
4951 return(dots ? -1 : 0);
4954 static int check_domain_name_list(
const char *ptr,
size_t len,
int dots)
4959 if ((ptr == NULL) || (len == 0))
4962 for (p=ptr; (*p != 0) && (len > 0); p++, len--) {
4966 if (check_domain_name(ptr, p - ptr, dots) != 0)
4973 return(check_domain_name(ptr, p - ptr, dots));
4990 #ifdef ACCEPT_LIST_IN_DOMAIN_NAME
4991 return check_domain_name_list(ptr, len, 0);
4993 return check_domain_name(ptr, len, 0);
4998 return check_domain_name(ptr, len, 0);
5001 return check_domain_name_list(ptr, len, 0);
5006 for (; (*ptr != 0) && (len-- > 0); ptr++) {
5007 if(!(isalnum((
unsigned char)*ptr) ||
5008 *ptr ==
'#' || *ptr ==
'%' ||
5009 *ptr ==
'+' || *ptr ==
'-' ||
5010 *ptr ==
'_' || *ptr ==
':' ||
5011 *ptr ==
'.' || *ptr ==
',' ||
5012 *ptr ==
'@' || *ptr ==
'~' ||
5013 *ptr ==
'\\' || *ptr ==
'/' ||
5014 *ptr ==
'[' || *ptr ==
']' ||
5015 *ptr ==
'=' || *ptr ==
' '))
5030 return check_domain_name_list(ptr, len, 0);
5040 add_reject(
struct packet *packet) {
5045 log_fatal (
"no memory for reject list!");
5064 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(* dhcpv6_packet_handler)(struct interface_info *, const char *, int, int, const struct iaddr *, isc_boolean_t)
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 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 *)
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)
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)
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