40 #include <dns/result.h> 50 extern int asprintf(
char **strp,
const char *fmt, ...);
80 #define ASSERT_STATE(state_is, state_shouldbe) {} 82 static const char copyright[] =
"Copyright 2004-2014 Internet Systems Consortium.";
83 static const char arr [] =
"All rights reserved.";
84 static const char message [] =
"Internet Systems Consortium DHCP Client";
85 static const char url [] =
"For info, please visit https://www.isc.org/software/dhcp/";
106 static void usage(
void);
108 static isc_result_t write_duid(
struct data_string *duid);
111 static int check_domain_name(
const char *ptr,
size_t len,
int dots);
112 static int check_domain_name_list(
const char *ptr,
size_t len,
int dots);
114 const char *ptr,
size_t len);
128 int release_mode = 0;
133 int no_dhclient_conf = 0;
134 int no_dhclient_db = 0;
135 int no_dhclient_pid = 0;
136 int no_dhclient_script = 0;
138 int local_family_set = 0;
141 char *dhcp_client_identifier_arg = NULL;
142 char *dhcp_host_name_arg = NULL;
143 char *dhcp_fqdn_arg = NULL;
144 char *dhcp_vendor_class_identifier_arg = NULL;
145 char *dhclient_request_options = NULL;
148 char *arg_conf = NULL;
149 int arg_conf_len = 0;
150 #ifdef HAVE_LIBCAP_NG 151 int keep_capabilities = 0;
160 fd = open(
"/dev/null", O_RDWR | O_CLOEXEC);
162 fd = open(
"/dev/null", O_RDWR | O_CLOEXEC);
164 fd = open(
"/dev/null", O_RDWR | O_CLOEXEC);
170 openlog(
"dhclient", LOG_NDELAY | LOG_PID, LOG_DAEMON);
172 #if !(defined(DEBUG) || defined(__CYGWIN32__)) 173 setlogmask(LOG_UPTO(LOG_INFO));
179 if (status != ISC_R_SUCCESS)
180 log_fatal(
"Can't initialize context: %s",
181 isc_result_totext(status));
185 if (status != ISC_R_SUCCESS)
187 isc_result_totext(status));
197 for (i = 1; i < argc; i++) {
198 if (!strcmp(argv[i],
"-r")) {
202 }
else if (!strcmp(argv[i],
"-4")) {
204 log_fatal(
"Client can only do v4 or v6, not " 206 local_family_set = 1;
208 }
else if (!strcmp(argv[i],
"-6")) {
210 log_fatal(
"Client can only do v4 or v6, not " 212 local_family_set = 1;
215 }
else if (!strcmp(argv[i],
"-x")) {
219 }
else if (!strcmp(argv[i],
"-p")) {
223 log_debug(
"binding to user-specified port %d",
225 }
else if (!strcmp(argv[i],
"-d")) {
228 }
else if (!strcmp(argv[i],
"-pf")) {
233 }
else if (!strcmp(argv[i],
"--no-pid")) {
235 }
else if (!strcmp(argv[i],
"-cf")) {
239 no_dhclient_conf = 1;
240 }
else if (!strcmp(argv[i],
"-lf")) {
245 }
else if (!strcmp(argv[i],
"-sf")) {
249 no_dhclient_script = 1;
250 }
else if (!strcmp(argv[i],
"-1")) {
252 }
else if (!strcmp(argv[i],
"-q")) {
254 }
else if (!strcmp(argv[i],
"-s")) {
258 }
else if (!strcmp(argv[i],
"-g")) {
262 }
else if (!strcmp(argv[i],
"-nw")) {
264 }
else if (!strcmp(argv[i],
"-n")) {
267 }
else if (!strcmp(argv[i],
"-w")) {
270 }
else if (!strcmp(argv[i],
"-e")) {
274 tmp =
dmalloc(strlen(argv[i]) +
sizeof *tmp,
MDL);
277 strcpy(tmp->
string, argv[i]);
282 }
else if (!strcmp(argv[i],
"-S")) {
286 local_family_set = 1;
290 }
else if (!strcmp(argv[i],
"-N")) {
294 local_family_set = 1;
300 }
else if (!strcmp(argv[i],
"-T")) {
304 local_family_set = 1;
310 }
else if (!strcmp(argv[i],
"-P")) {
314 local_family_set = 1;
321 }
else if (!strcmp(argv[i],
"-D")) {
325 if (!strcasecmp(argv[i],
"LL")) {
327 }
else if (!strcasecmp(argv[i],
"LLT")) {
332 }
else if (!strcmp(argv[i],
"-i")) {
335 }
else if (!strcmp(argv[i],
"-I")) {
338 }
else if (!strcmp(argv[i],
"-v")) {
340 }
else if (!strcmp(argv[i],
"--version")) {
343 }
else if (!strcmp(argv[i],
"-C")) {
344 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
354 dhcp_client_identifier_arg = argv[i];
355 }
else if (!strcmp(argv[i],
"-B")) {
357 }
else if (!strcmp(argv[i],
"-H")) {
358 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
368 if (dhcp_host_name_arg != NULL) {
369 log_error(
"The -H <host-name> and -F <fqdn> arguments are mutually exclusive");
373 dhcp_host_name_arg = argv[i];
374 }
else if (!strcmp(argv[i],
"-F")) {
375 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
385 if (dhcp_fqdn_arg != NULL) {
386 log_error(
"Only one -F <fqdn> argument can be specified");
390 if (dhcp_host_name_arg != NULL) {
391 log_error(
"The -F <fqdn> and -H <host-name> arguments are mutually exclusive");
395 dhcp_fqdn_arg = argv[i];
396 }
else if (!strcmp(argv[i],
"-timeout")) {
397 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
402 if ((timeout_arg = atoi(argv[i])) <= 0) {
403 log_error(
"timeout option must be > 0 - bad value: %s",argv[i]);
406 }
else if (!strcmp(argv[i],
"-V")) {
407 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
417 dhcp_vendor_class_identifier_arg = argv[i];
418 }
else if (!strcmp(argv[i],
"-R")) {
419 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
424 dhclient_request_options = argv[i];
425 }
else if (!strcmp(argv[i],
"-nc")) {
426 #ifdef HAVE_LIBCAP_NG 427 keep_capabilities = 1;
429 }
else if (argv[i][0] ==
'-') {
436 status = interface_allocate(&tmp,
MDL);
437 if (status != ISC_R_SUCCESS)
438 log_fatal(
"Can't record interface %s:%s",
439 argv[i], isc_result_totext(status));
440 if (strlen(argv[i]) >=
sizeof(tmp->
name))
441 log_fatal(
"%s: interface name too long (is %ld)",
442 argv[i], (
long)strlen(argv[i]));
443 strcpy(tmp->
name, argv[i]);
445 interface_reference(&tmp->
next,
464 if (!no_dhclient_conf && (s = getenv(
"PATH_DHCLIENT_CONF"))) {
467 if (!no_dhclient_db && (s = getenv(
"PATH_DHCLIENT_DB"))) {
470 if (!no_dhclient_pid && (s = getenv(
"PATH_DHCLIENT_PID"))) {
473 if (!no_dhclient_script && (s = getenv(
"PATH_DHCLIENT_SCRIPT"))) {
477 #ifdef HAVE_LIBCAP_NG 479 if (!keep_capabilities) {
480 capng_clear(CAPNG_SELECT_CAPS);
481 capng_update(CAPNG_ADD, CAPNG_EFFECTIVE|CAPNG_PERMITTED,
483 capng_updatev(CAPNG_ADD, CAPNG_EFFECTIVE|CAPNG_PERMITTED,
484 CAP_NET_ADMIN, CAP_NET_RAW,
485 CAP_NET_BIND_SERVICE, CAP_SYS_ADMIN, -1);
486 capng_apply(CAPNG_SELECT_CAPS);
511 log_fatal(
"Failed to get realpath for %s: %s", old_path, strerror(errno));
518 log_fatal(
"Failed to get realpath for %s: %s", old_path, strerror(errno));
527 if ((release_mode || exit_mode) && (
no_pid_file == ISC_FALSE)) {
534 e = fscanf(pidfd,
"%ld\n", &temp);
535 oldpid = (pid_t)temp;
537 if (e != 0 && e != EOF) {
538 if (oldpid && (kill(oldpid, SIGTERM) == 0)) {
558 char *new_path_dhclient_pid;
577 int n_len = strlen(ip->
name);
579 new_path_dhclient_pid = (
char*) malloc(pfx + n_len + 6);
581 sprintf(new_path_dhclient_pid + pfx,
"-%s.pid", ip->
name);
583 if ((pidfd = fopen(new_path_dhclient_pid,
"re")) != NULL) {
584 e = fscanf(pidfd,
"%ld\n", &temp);
585 oldpid = (pid_t)temp;
587 if (e != 0 && e != EOF) {
589 if (kill(oldpid, SIGTERM) == 0)
597 free(new_path_dhclient_pid);
606 char procfn[256] =
"";
609 if ((fscanf(pidfp,
"%ld", &temp)==1) && ((dhcpid=(pid_t)temp) > 0)) {
610 snprintf(procfn,256,
"/proc/%u",dhcpid);
611 dhc_running = (access(procfn, F_OK) == 0);
618 log_fatal(
"dhclient(%u) is already running - exiting. ", dhcpid);
643 memcpy(&
giaddr, he->h_addr_list[0],
652 gettimeofday(&
cur_tv, NULL);
659 he = gethostbyname(server);
692 if ((dhcp_client_identifier_arg != NULL) && (*dhcp_client_identifier_arg !=
'\0')) {
693 arg_conf_len =
asprintf(&arg_conf,
"send dhcp-client-identifier \"%s\";", dhcp_client_identifier_arg);
695 if ((arg_conf == 0) || (arg_conf_len <= 0))
696 log_fatal(
"Unable to send -C option dhcp-client-identifier");
699 if ((dhcp_host_name_arg != NULL) && (*dhcp_host_name_arg !=
'\0')) {
701 arg_conf_len =
asprintf(&arg_conf,
"send host-name \"%s\";", dhcp_host_name_arg);
703 if ((arg_conf == 0) || (arg_conf_len <= 0))
704 log_fatal(
"Unable to send -H option host-name");
706 char *last_arg_conf = arg_conf;
708 arg_conf_len =
asprintf(&arg_conf,
"%s\nsend host-name \"%s\";", last_arg_conf, dhcp_host_name_arg);
710 if ((arg_conf == 0) || (arg_conf_len <= 0))
711 log_fatal(
"Unable to send -H option host-name");
717 if ((dhcp_fqdn_arg != NULL) && (*dhcp_fqdn_arg !=
'\0')) {
719 arg_conf_len =
asprintf(&arg_conf,
"send fqdn.fqdn \"%s\";", dhcp_fqdn_arg);
721 if ((arg_conf == 0) || (arg_conf_len <= 0))
722 log_fatal(
"Unable to send -F option fqdn.fqdn");
724 char *last_arg_conf = arg_conf;
726 arg_conf_len =
asprintf(&arg_conf,
"%s\nsend fqdn.fqdn \"%s\";", last_arg_conf, dhcp_fqdn_arg);
728 if ((arg_conf == 0) || (arg_conf_len <= 0))
729 log_fatal(
"Unable to send -F option fqdn.fqdn");
737 arg_conf_len =
asprintf(&arg_conf,
"timeout %d;", timeout_arg);
739 if ((arg_conf == 0) || (arg_conf_len <= 0))
740 log_fatal(
"Unable to process -timeout timeout argument");
742 char *last_arg_conf = arg_conf;
744 arg_conf_len =
asprintf(&arg_conf,
"%s\ntimeout %d;", last_arg_conf, timeout_arg);
746 if ((arg_conf == 0) || (arg_conf_len == 0))
747 log_fatal(
"Unable to process -timeout timeout argument");
753 if ((dhcp_vendor_class_identifier_arg != NULL) && (*dhcp_vendor_class_identifier_arg !=
'\0')) {
755 arg_conf_len =
asprintf(&arg_conf,
"send vendor-class-identifier \"%s\";", dhcp_vendor_class_identifier_arg);
757 if ((arg_conf == 0) || (arg_conf_len <= 0))
758 log_fatal(
"Unable to send -V option vendor-class-identifier");
760 char *last_arg_conf = arg_conf;
762 arg_conf_len =
asprintf(&arg_conf,
"%s\nsend vendor-class-identifier \"%s\";", last_arg_conf, dhcp_vendor_class_identifier_arg);
764 if ((arg_conf == 0) || (arg_conf_len <= 0))
765 log_fatal(
"Unable to send -V option vendor-class-identifier");
771 if (dhclient_request_options != NULL) {
773 arg_conf_len =
asprintf(&arg_conf,
"request %s;", dhclient_request_options);
775 if ((arg_conf == 0) || (arg_conf_len <= 0))
776 log_fatal(
"Unable to parse -R <request options list> argument");
778 char *last_arg_conf = arg_conf;
780 arg_conf_len =
asprintf(&arg_conf,
"%s\nrequest %s;", last_arg_conf, dhclient_request_options);
782 if ((arg_conf == 0) || (arg_conf_len <= 0))
783 log_fatal(
"Unable to parse -R <request options list> argument");
790 if (arg_conf_len == 0)
791 if ((arg_conf_len = strlen(arg_conf)) == 0)
793 log_fatal(
"Unable to process -C/-H/-F/-timeout/-V/-R configuration arguments");
798 const char *val = NULL;
801 status =
new_parse(&cfile, -1, arg_conf, arg_conf_len,
"extra dhclient -C/-H/-F/-timeout/-V/-R configuration arguments", 0);
804 log_fatal(
"Cannot parse -C/-H/-F/-timeout/-V/-R configuration arguments !");
808 token =
peek_token(&val, (
unsigned *)0, cfile);
816 log_fatal(
"Cannot parse -C/-H/-F/-timeout/-V/-R configuration arguments !");
868 log_info(
"No broadcast interfaces found - exiting.");
871 }
else if (!release_mode && !exit_mode) {
905 unsigned backup_seed = 0;
908 if ( ip -> hw_address.hlen <=
sizeof seed )
911 &ip -> hw_address.hbuf [ip -> hw_address.hlen -
912 sizeof seed],
sizeof seed);
934 if ( ip -> hw_address.hlen <=
sizeof seed )
938 sizeof seed],
sizeof seed);
942 if ( seed_flag == 0 ) {
943 if ( backup_seed != 0 ) {
945 log_info (
"xid: rand init seed (0x%x) built using all" 946 " available interfaces",seed);
949 seed =
cur_time^((unsigned) gethostid()) ;
950 log_info (
"xid: warning: no netdev with useable HWADDR found" 951 " for seed's uniqueness enforcement");
952 log_info (
"xid: rand init seed (0x%x) built using gethostid",
960 srandom(seed +
cur_time + (
unsigned)getpid());
966 setup_ib_interface(ip);
989 for (client = ip->
client ; client != NULL ;
990 client = client->
next) {
994 }
else if (exit_mode) {
1014 for (client = ip->
client ; client ;
1015 client = client->
next) {
1018 else if (release_mode)
1032 tv.tv_usec = random()
1067 if (result != ISC_R_SUCCESS)
1068 log_fatal(
"Can't allocate new generic object: %s\n",
1069 isc_result_totext(result));
1074 if (result != ISC_R_SUCCESS)
1075 log_fatal(
"Can't start OMAPI protocol: %s",
1076 isc_result_totext (result));
1085 #if defined(DEBUG_MEMORY_LEAKAGE) || defined(DEBUG_MALLOC_POOL) || \ 1086 defined(DEBUG_MEMORY_LEAKAGE_ON_EXIT) 1087 dmalloc_cutoff_generation = dmalloc_generation;
1088 dmalloc_longterm = dmalloc_outstanding;
1089 dmalloc_outstanding = 0;
1123 "[-4|-6] [-SNTPI1dvrxi] [-nw] [-p <port>] [-D LL|LLT] \n" 1125 "[-I1dvrxi] [-nw] [-p <port>] [-D LL|LLT] \n" 1127 " [-s server-addr] [-cf config-file] " 1128 "[-lf lease-file]\n" 1129 " [-pf pid-file] [--no-pid] [-e VAR=val]\n" 1130 " [-C <dhcp-client-identifier>] [-B]\n" 1131 " [-H <host-name> | -F <fqdn.fqdn>] [-timeout <timeout>]\n" 1132 " [-V <vendor-class-identifier>]\n" 1133 " [-R <request option list>]\n" 1134 " [-sf script-file] [interface]");
1142 isc_result_t result;
1167 client = client->
next) {
1181 if (result != ISC_R_SUCCESS)
1182 log_fatal(
"Can't allocate new generic object: %s\n",
1183 isc_result_totext(result));
1188 if (result != ISC_R_SUCCESS)
1189 log_fatal(
"Can't start OMAPI protocol: %s",
1190 isc_result_totext(result));
1196 #if defined(DEBUG_MEMORY_LEAKAGE) || defined(DEBUG_MALLOC_POOL) || \ 1197 defined(DEBUG_MEMORY_LEAKAGE_ON_EXIT) 1198 dmalloc_cutoff_generation = dmalloc_generation;
1199 dmalloc_longterm = dmalloc_outstanding;
1200 dmalloc_outstanding = 0;
1221 const char *s,
const char *
file,
int line)
1235 struct packet *packet;
1241 struct lease *lease;
1267 "dhcp-client-identifier") == 0)) {
1312 client ->
active -> is_bootp ||
1326 client ->
xid = random ();
1359 client -> xid = client -> packet.xid;
1362 client -> first_sending =
cur_time;
1363 client -> interval = client -> config -> initial_interval;
1406 for (lp = client -> offered_leases; lp; lp =
next) {
1415 picked -> next = NULL;
1420 client -> offered_leases = NULL;
1427 client -> state =
S_INIT;
1434 client ->
new = picked;
1452 client -> first_sending =
cur_time;
1453 client -> interval = client -> config -> initial_interval;
1457 client -> xid = client -> packet.xid;
1470 struct packet *packet;
1480 for (client = ip -> client; client; client = client -> next) {
1481 if (client -> xid == packet -> raw -> xid)
1485 (packet -> interface -> hw_address.hlen - 1 !=
1486 packet -> raw -> hlen) ||
1487 (memcmp (&packet -> interface -> hw_address.hbuf [1],
1488 packet -> raw -> chaddr, packet -> raw -> hlen))) {
1490 log_debug (
"DHCPACK in wrong transaction.");
1505 log_info (
"DHCPACK from %s (xid=0x%x)",
piaddr (packet -> client_addr), client -> xid);
1509 log_info (
"packet_to_lease failed.");
1513 client ->
new = lease;
1521 memset (&ds, 0,
sizeof ds);
1524 packet -> options, client ->
new -> options,
1529 client ->
new -> expiry = 0;
1532 client ->
new -> expiry = 0;
1537 log_error (
"no expiry time on offered lease.");
1543 tv.tv_sec =
cur_tv.tv_sec;
1544 tv.tv_usec =
cur_tv.tv_usec + 500000;
1546 if (tv.tv_usec >= 1000000) {
1548 tv.tv_usec -= 1000000;
1567 packet -> options, client ->
new -> options,
1572 client ->
new -> renewal = 0;
1575 client ->
new -> renewal = 0;
1578 if (!client ->
new -> renewal)
1579 client ->
new -> renewal = client ->
new -> expiry / 2 + 1;
1581 if (client ->
new -> renewal <= 0)
1582 client ->
new -> renewal =
TIME_MAX;
1587 (((random() % client->
new->
renewal) + 3) / 4);
1594 packet -> options, client ->
new -> options,
1599 client ->
new -> rebind = 0;
1602 client ->
new -> rebind = 0;
1604 if (client ->
new -> rebind <= 0) {
1605 if (client ->
new -> expiry <=
TIME_MAX / 7)
1606 client ->
new -> rebind =
1607 client ->
new -> expiry * 7 / 8;
1609 client ->
new -> rebind =
1610 client ->
new -> expiry / 8 * 7;
1615 if (client ->
new -> renewal > client ->
new -> rebind) {
1616 if (client ->
new -> rebind <=
TIME_MAX / 3)
1617 client ->
new -> renewal =
1618 client ->
new -> rebind * 3 / 4;
1620 client ->
new -> renewal =
1621 client ->
new -> rebind / 4 * 3;
1624 client ->
new -> expiry +=
cur_time;
1626 if (client ->
new -> expiry <
cur_time)
1627 client ->
new -> expiry =
TIME_MAX;
1628 client ->
new -> renewal +=
cur_time;
1629 if (client ->
new -> renewal <
cur_time)
1630 client ->
new -> renewal =
TIME_MAX;
1631 client ->
new -> rebind +=
cur_time;
1632 if (client ->
new -> rebind <
cur_time)
1633 client ->
new -> rebind =
TIME_MAX;
1635 bind_lease (client, &packet -> raw -> siaddr);
1640 struct in_addr *siaddr;
1645 client ->
new -> medium = client -> medium;
1653 ?
"REBOOT" :
"REBIND"))),
1654 client ->
new -> medium);
1655 if (client -> active && client -> state !=
S_REBOOTING)
1659 if (client -> alias)
1663 char buf[INET_ADDRSTRLEN];
1665 if (inet_ntop (AF_INET, (
void *) siaddr, buf,
sizeof (buf)))
1677 log_info (
"Unable to obtain a lease on first try.%s",
1695 if (client -> active)
1697 client -> active = client ->
new;
1703 random() % 1000000 :
cur_tv.tv_usec;
1706 log_info (
"bound to %s -- renewal in %ld seconds.",
1712 #if defined (NSUPDATE) 1734 client -> xid = client -> packet.xid;
1736 memset (&ds, 0,
sizeof ds);
1742 client -> active -> options,
1745 memcpy (client -> destination.iabuf, ds.
data, 4);
1746 client -> destination.len = 4;
1754 client -> first_sending =
cur_time;
1755 client -> interval = client -> config -> initial_interval;
1793 struct lease *lease;
1805 struct packet *packet;
1816 for (ap = packet -> interface -> client -> config -> reject_list;
1817 ap; ap = ap ->
next) {
1826 log_info(
"BOOTREPLY from %s rejected by rule %s " 1838 struct packet *packet;
1841 void (*handler) (
struct packet *);
1868 for (ap = packet ->
interface -> client -> config -> reject_list;
1869 ap; ap = ap -> next) {
1878 log_info(
"%s from %s rejected by rule %s mask %s.",
1884 (*handler) (packet);
1889 dhcpv6(
struct packet *packet) {
1892 char addrbuf[
sizeof(
"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")];
1900 ap ; ap = ap->
next) {
1903 log_info(
"%s from %s rejected by rule %s",
1919 log_info(
"RCV: %s message on %s from %s.",
1930 client = client->
next) {
1939 log_info(
"Packet received, but nothing done with it.");
1944 struct packet *packet;
1952 const char *
name = packet -> packet_type ?
"DHCPOFFER" :
"BOOTREPLY";
1961 for (client = ip -> client; client; client = client -> next)
1962 if (client -> xid == packet -> raw -> xid)
1969 (packet -> interface -> hw_address.hlen - 1 !=
1970 packet -> raw -> hlen) ||
1971 (memcmp (&packet -> interface -> hw_address.hbuf [1],
1972 packet -> raw -> chaddr, packet -> raw -> hlen))) {
1974 log_debug (
"%s in wrong transaction.", name);
1979 sprintf (obuf,
"%s from %s", name,
piaddr (packet -> client_addr));
1987 for (i = 0 ; req[i] != NULL ; i++) {
1994 option_code_hash_lookup(&option,
1999 log_info(
"%s: no %s option.", obuf,
2002 log_info(
"%s: no unknown-%u option.",
2013 for (lease = client -> offered_leases; lease; lease = lease -> next) {
2014 if (lease -> address.len ==
sizeof packet -> raw -> yiaddr &&
2015 !memcmp (lease -> address.iabuf,
2016 &packet -> raw -> yiaddr, lease -> address.len)) {
2024 log_info (
"%s: packet_to_lease failed.", obuf);
2030 if (!packet -> options_valid || !packet -> packet_type)
2031 lease -> is_bootp = 1;
2034 lease -> medium = client -> medium;
2037 stop_selecting = (client -> first_sending +
2038 client -> config -> select_interval);
2042 if (lease -> address.len == client -> requested_address.len &&
2043 !memcmp (lease -> address.iabuf,
2044 client -> requested_address.iabuf,
2045 client -> requested_address.len)) {
2046 lease -> next = client -> offered_leases;
2047 client -> offered_leases = lease;
2051 if (!client -> offered_leases)
2052 client -> offered_leases = lease;
2054 for (lp = client -> offered_leases; lp ->
next;
2064 if (stop_selecting <=
cur_tv.tv_sec)
2067 tv.tv_sec = stop_selecting;
2068 tv.tv_usec =
cur_tv.tv_usec;
2079 struct packet *packet;
2091 log_error (
"packet_to_lease: no memory to record lease.\n");
2095 memset (lease, 0,
sizeof *lease);
2100 lease ->
address.
len =
sizeof (packet -> raw -> yiaddr);
2101 memcpy (lease ->
address.
iabuf, &packet -> raw -> yiaddr,
2104 memset (&data, 0,
sizeof data);
2106 if (client -> config -> vendor_space_name) {
2112 client -> config -> vendor_space_name &&
2114 (
struct lease *)0, client,
2118 if (!option_code_hash_lookup(&option,
2122 "option (%s:%d).",
MDL);
2126 client -> config -> vendor_space_name
2152 if (!(i & 2) && packet -> raw -> sname [0]) {
2156 if (!packet -> raw -> sname [len])
2160 log_error (
"dhcpoffer: no memory for server name.\n");
2165 packet -> raw -> sname, len);
2171 if (!(i & 1) && packet -> raw ->
file [0]) {
2175 if (!packet -> raw ->
file [len])
2179 log_error (
"dhcpoffer: no memory for filename.\n");
2184 packet -> raw ->
file, len);
2190 client, lease->options, lease->options,
2198 struct packet *packet;
2204 for (client = ip -> client; client; client = client ->
next)
2205 if (client ->
xid == packet -> raw ->
xid)
2211 (packet ->
interface -> hw_address.hlen - 1 !=
2212 packet -> raw -> hlen) ||
2213 (memcmp (&packet ->
interface -> hw_address.hbuf [1],
2214 packet -> raw -> chaddr, packet -> raw -> hlen))) {
2216 log_debug (
"DHCPNAK in wrong transaction.");
2231 log_info (
"DHCPNAK from %s (xid=0x%x)",
piaddr (packet -> client_addr), client ->
xid);
2235 log_info (
"DHCPNAK with no active lease.\n");
2268 client -> state =
S_INIT;
2287 interval =
cur_time - client -> first_sending;
2291 if (interval > client -> config ->
timeout) {
2299 if (!client -> offered_leases &&
2300 client -> config -> media) {
2303 if (client -> medium) {
2304 client -> medium = client -> medium -> next;
2307 if (!client -> medium) {
2309 log_fatal (
"No valid media types for %s!",
2310 client -> interface -> name);
2312 client -> config -> media;
2316 log_info (
"Trying medium \"%s\" %d",
2317 client -> medium ->
string, increase);
2345 if (
cur_time + client -> interval >
2346 client -> first_sending + client -> config ->
timeout)
2347 client -> interval =
2348 (client -> first_sending +
2352 if (interval < 65536)
2353 client -> packet.secs = htons (interval);
2355 client -> packet.secs = htons (65535);
2356 client -> secs = client -> packet.secs;
2358 log_info (
"DHCPDISCOVER on %s to %s port %d interval %ld (xid=0x%x)",
2359 client -> name ? client -> name : client -> interface -> name,
2368 log_error(
"%s:%d: Failed to send %d byte long packet over %s " 2380 tv.tv_usec = client->
interval > 1 ? random() % 1000000 :
cur_tv.tv_usec;
2397 loop = lp = client -> active;
2399 log_info (
"No DHCPOFFERS received.");
2403 if (!client -> active && client -> leases)
2407 while (client -> active) {
2408 if (client -> active -> expiry >
cur_time) {
2409 log_info (
"Trying recorded lease %s",
2410 piaddr (client -> active -> address));
2414 client -> active -> medium);
2417 if (client -> alias)
2425 if (cur_time < client -> active -> renewal) {
2427 log_info (
"bound: renewal in %ld %s.",
2428 (
long)(client -> active -> renewal -
2433 random() % 1000000 :
2438 log_info (
"bound: immediate renewal.");
2448 if (!client -> leases) {
2449 client -> leases = client -> active;
2457 for (lp = client -> leases; lp ->
next; lp = lp ->
next)
2459 lp ->
next = client -> active;
2463 client -> active = client -> leases;
2464 client -> leases = client -> leases ->
next;
2469 if (client -> active == loop)
2472 loop = client -> active;
2480 log_info (
"Unable to obtain a lease on first try.%s",
2485 log_info (
"No working leases in persistent database - sleeping.");
2487 if (client -> alias)
2490 client -> state =
S_INIT;
2493 tv.tv_usec = ((tv.tv_sec -
cur_tv.tv_sec) > 1) ?
2494 random() % 1000000 :
cur_tv.tv_usec;
2506 struct sockaddr_in destination;
2507 struct in_addr from;
2511 interval =
cur_time - client -> first_sending;
2525 interval > client -> config -> reboot_timeout) {
2527 client -> state =
S_INIT;
2536 !client -> medium &&
2537 client -> active -> medium ) {
2538 script_init (client,
"MEDIUM", client -> active -> medium);
2545 client -> medium = client -> active -> medium;
2551 cur_time > client -> active -> expiry) {
2556 if (client -> alias)
2564 if (client -> alias)
2569 client -> state =
S_INIT;
2575 if (!client -> interval)
2576 client -> interval = client -> config -> initial_interval;
2578 client -> interval += ((random () >> 2) %
2579 (2 * client -> interval));
2583 if (client -> interval >
2584 client -> config -> backoff_cutoff)
2585 client -> interval =
2586 ((client -> config -> backoff_cutoff / 2)
2587 + ((random () >> 2) %
2588 client -> config -> backoff_cutoff));
2593 cur_time + client -> interval > client -> active -> expiry)
2594 client -> interval =
2595 client -> active -> expiry -
cur_time + 1;
2601 cur_time > client -> active -> rebind)
2604 memcpy (&destination.sin_addr.s_addr,
2605 client -> destination.iabuf,
2606 sizeof destination.sin_addr.s_addr);
2608 destination.sin_family = AF_INET;
2610 destination.sin_len =
sizeof destination;
2615 memcpy (&from, client -> active -> address.iabuf,
2618 from.s_addr = INADDR_ANY;
2622 client -> packet.secs = client -> secs;
2624 if (interval < 65536)
2625 client -> packet.secs = htons (interval);
2627 client -> packet.secs = htons (65535);
2630 log_info (
"DHCPREQUEST on %s to %s port %d (xid=0x%x)",
2631 client -> name ? client -> name : client -> interface -> name,
2632 inet_ntoa (destination.sin_addr),
2633 ntohs (destination.sin_port), client -> xid);
2635 if (destination.sin_addr.s_addr != INADDR_BROADCAST &&
2641 log_error(
"%s:%d: Failed to send %d byte long packet " 2642 "over %s interface.",
MDL,
2653 log_error(
"%s:%d: Failed to send %d byte long packet" 2654 " over %s interface.",
MDL,
2661 tv.tv_usec = ((tv.tv_sec -
cur_tv.tv_sec) > 1) ?
2662 random() % 1000000 :
cur_tv.tv_usec;
2673 log_info (
"DHCPDECLINE on %s to %s port %d (xid=0x%x)",
2683 log_error(
"%s:%d: Failed to send %d byte long packet over %s" 2695 struct sockaddr_in destination;
2696 struct in_addr from;
2698 memcpy (&from, client -> active -> address.iabuf,
2700 memcpy (&destination.sin_addr.s_addr,
2701 client -> destination.iabuf,
2702 sizeof destination.sin_addr.s_addr);
2704 destination.sin_family = AF_INET;
2706 destination.sin_len =
sizeof destination;
2711 client -> active -> expiry =
2712 client -> active -> renewal =
2713 client -> active -> rebind =
cur_time;
2715 log_error (
"Can't release lease: lease write failed.");
2719 log_info (
"DHCPRELEASE on %s to %s port %d (xid=0x%x)",
2720 client -> name ? client -> name : client -> interface -> name,
2721 inet_ntoa (destination.sin_addr),
2722 ntohs (destination.sin_port), client -> xid);
2729 log_error(
"%s:%d: Failed to send %d byte long packet" 2730 " over %s interface.",
MDL,
2740 log_error (
"%s:%d: Failed to send %d byte long packet" 2741 " over %s interface.",
MDL,
2758 struct buffer *bp = NULL;
2781 log_error (
"can't make requested address cache.");
2807 for (i = 0 ; prl[i] != NULL ; i++)
2812 log_error(
"can't make parameter list buffer.");
2817 for (i = 0 ; prl[i] != NULL ; i++)
2821 if (!(option_code_hash_lookup(&option,
2844 memset(&client_identifier, 0,
sizeof(client_identifier));
2847 client_identifier.
len,
MDL))
2848 log_fatal(
"no memory for default DUID!");
2866 memcpy(&client_identifier.
buffer->
data + 5 - hw_len,
2871 memcpy(&client_identifier.
buffer->
data+(1+4),
2878 (u_int8_t *)client_identifier.
data,
2879 client_identifier.
len,
2881 log_error (
"can't make requested client id cache..");
2892 (lease ? lease->
options : NULL),
2905 memset (&client -> packet, 0,
sizeof (client -> packet));
2909 lease ? &lease -> address : (
struct iaddr *)0,
2910 client -> config -> requested_options,
2914 client -> packet_length =
2916 (
struct lease *)0, client,
2925 client -> config -> vendor_space_name);
2932 client -> packet.htype = client ->
interface -> hw_address.hbuf [0];
2933 client -> packet.hlen = client ->
interface -> hw_address.hlen - 1;
2934 client -> packet.hops = 0;
2935 client -> packet.xid = random ();
2936 client -> packet.secs = 0;
2940 client -> packet.flags = 0;
2944 memset (&(client -> packet.ciaddr),
2945 0,
sizeof client -> packet.ciaddr);
2946 memset (&(client -> packet.yiaddr),
2947 0,
sizeof client -> packet.yiaddr);
2948 memset (&(client -> packet.siaddr),
2949 0,
sizeof client -> packet.siaddr);
2950 client -> packet.giaddr =
giaddr;
2951 if (client -> interface -> hw_address.hlen > 0)
2952 memcpy (client -> packet.chaddr,
2953 &client -> interface -> hw_address.hbuf [1],
2954 (
unsigned)(client -> interface -> hw_address.hlen - 1));
2957 dump_raw ((
unsigned char *)&client -> packet, client -> packet_length);
2969 memset (&client -> packet, 0,
sizeof (client -> packet));
2977 if (client -> sent_options)
2984 : (
struct iaddr *)0),
2985 client -> config -> requested_options,
2986 &client -> sent_options);
2989 client -> packet_length =
2991 (
struct lease *)0, client,
2994 client -> sent_options,
3000 client -> config -> vendor_space_name);
3006 client -> packet.htype = client ->
interface -> hw_address.hbuf [0];
3007 client -> packet.hlen = client ->
interface -> hw_address.hlen - 1;
3008 client -> packet.hops = 0;
3009 client -> packet.xid = client -> xid;
3010 client -> packet.secs = 0;
3014 if (client -> state ==
S_BOUND ||
3017 memcpy (&client -> packet.ciaddr,
3018 lease -> address.iabuf, lease -> address.len);
3019 client -> packet.flags = 0;
3021 memset (&client -> packet.ciaddr, 0,
3022 sizeof client -> packet.ciaddr);
3024 client ->config->bootp_broadcast_always)) &&
3026 client -> packet.flags = 0;
3031 memset (&client -> packet.yiaddr, 0,
3032 sizeof client -> packet.yiaddr);
3033 memset (&client -> packet.siaddr, 0,
3034 sizeof client -> packet.siaddr);
3035 if (client -> state !=
S_BOUND &&
3037 client -> packet.giaddr =
giaddr;
3039 memset (&client -> packet.giaddr, 0,
3040 sizeof client -> packet.giaddr);
3041 if (client -> interface -> hw_address.hlen > 0)
3042 memcpy (client -> packet.chaddr,
3043 &client -> interface -> hw_address.hbuf [1],
3044 (
unsigned)(client -> interface -> hw_address.hlen - 1));
3047 dump_raw ((
unsigned char *)&client -> packet, client -> packet_length);
3067 memset (&client -> packet, 0,
sizeof (client -> packet));
3068 client -> packet_length =
3070 (
struct lease *)0, client, 0,
3073 client -> config -> vendor_space_name);
3082 client -> packet.htype = client ->
interface -> hw_address.hbuf [0];
3083 client -> packet.hlen = client ->
interface -> hw_address.hlen - 1;
3084 client -> packet.hops = 0;
3085 client -> packet.xid = client -> xid;
3086 client -> packet.secs = 0;
3089 client -> packet.flags = 0;
3094 memset (&client -> packet.ciaddr, 0,
3095 sizeof client -> packet.ciaddr);
3096 memset (&client -> packet.yiaddr, 0,
3097 sizeof client -> packet.yiaddr);
3098 memset (&client -> packet.siaddr, 0,
3099 sizeof client -> packet.siaddr);
3100 client -> packet.giaddr =
giaddr;
3101 memcpy (client -> packet.chaddr,
3102 &client -> interface -> hw_address.hbuf [1],
3103 client -> interface -> hw_address.hlen);
3106 dump_raw ((
unsigned char *)&client -> packet, client -> packet_length);
3119 memset (&client -> packet, 0,
sizeof (client -> packet));
3126 client -> packet_length =
3128 (
struct lease *)0, client,
3137 client -> config -> vendor_space_name);
3144 client -> packet.htype = client ->
interface -> hw_address.hbuf [0];
3145 client -> packet.hlen = client ->
interface -> hw_address.hlen - 1;
3146 client -> packet.hops = 0;
3147 client -> packet.xid = random ();
3148 client -> packet.secs = 0;
3149 client -> packet.flags = 0;
3150 memcpy (&client -> packet.ciaddr,
3151 lease -> address.iabuf, lease -> address.len);
3152 memset (&client -> packet.yiaddr, 0,
3153 sizeof client -> packet.yiaddr);
3154 memset (&client -> packet.siaddr, 0,
3155 sizeof client -> packet.siaddr);
3156 client -> packet.giaddr =
giaddr;
3157 memcpy (client -> packet.chaddr,
3158 &client -> interface -> hw_address.hbuf [1],
3159 client -> interface -> hw_address.hlen);
3162 dump_raw ((
unsigned char *)&client -> packet, client -> packet_length);
3201 for (client = ip -> client; client; client = client ->
next) {
3202 for (lp = client -> leases; lp; lp = lp ->
next) {
3205 if (client -> active)
3207 client -> active, 1, 0);
3222 for (client = ip -> client; client; client = client ->
next) {
3223 for (lp = client -> leases; lp; lp = lp ->
next) {
3226 if (client -> active)
3228 client -> active, 1, 0);
3243 struct packet *packet,
struct lease *lease,
3250 const char *name, *dot;
3252 char *preamble = stuff;
3254 memset (&ds, 0,
sizeof ds);
3264 in_options, cfg_options, scope, oc,
MDL)) {
3266 fprintf(
leaseFile,
"%soption %s%s%s", preamble,
3287 const char *preamble)
3327 log_debug(
"Cannot form default DUID from interface %s.", ip->
name);
3331 return ISC_R_UNEXPECTED;
3336 log_fatal(
"Impossible hardware address length at %s:%d.",
MDL);
3353 len = 4 + (hlen - 1);
3357 log_fatal(
"no memory for default DUID!");
3375 return ISC_R_SUCCESS;
3385 if ((duid == NULL) || (duid->
len <= 2))
3392 return ISC_R_IOERROR;
3403 return ISC_R_NOMEMORY;
3405 stat = fprintf(
leaseFile,
"default-duid \"%s\";\n", str);
3408 return ISC_R_IOERROR;
3411 return ISC_R_IOERROR;
3413 return ISC_R_SUCCESS;
3419 int rewrite,
int sync)
3430 return ISC_R_SUCCESS;
3433 if (client == NULL || lease == NULL)
3440 return ISC_R_IOERROR;
3444 stat = fprintf(
leaseFile,
"lease6 {\n");
3446 return ISC_R_IOERROR;
3448 stat = fprintf(
leaseFile,
" interface \"%s\";\n",
3451 return ISC_R_IOERROR;
3453 for (ia = lease->
bindings ; ia != NULL ; ia = ia->
next) {
3469 return ISC_R_IOERROR;
3472 stat = fprintf(
leaseFile,
" starts %d;\n" 3477 stat = fprintf(
leaseFile,
" starts %d;\n",
3480 return ISC_R_IOERROR;
3482 for (addr = ia->
addrs ; addr != NULL ; addr = addr->
next) {
3489 " iaprefix %s/%d {\n",
3493 return ISC_R_IOERROR;
3495 stat = fprintf(
leaseFile,
" starts %d;\n" 3496 " preferred-life %u;\n" 3501 return ISC_R_IOERROR;
3504 write_options(client, addr->
options,
" ");
3508 return ISC_R_IOERROR;
3512 write_options(client, ia->
options,
" ");
3516 return ISC_R_IOERROR;
3520 stat = fprintf(
leaseFile,
" released;\n");
3522 return ISC_R_IOERROR;
3526 write_options(client, lease->
options,
" ");
3530 return ISC_R_IOERROR;
3533 return ISC_R_IOERROR;
3537 log_error(
"write_client_lease: fsync(): %m");
3538 return ISC_R_IOERROR;
3542 return ISC_R_SUCCESS;
3565 if (lease -> is_static)
3578 if (lease -> is_bootp) {
3585 fprintf (
leaseFile,
" interface \"%s\";\n",
3586 client -> interface -> name);
3591 if (client -> name) {
3592 fprintf (
leaseFile,
" name \"%s\";\n", client -> name);
3598 fprintf (
leaseFile,
" fixed-address %s;\n",
3599 piaddr (lease -> address));
3604 if (lease -> filename) {
3607 fprintf (
leaseFile,
" filename \"%s\";\n", s);
3620 fprintf(
leaseFile,
" server-name \"%s\";\n", s);
3629 if (lease -> medium) {
3632 fprintf (
leaseFile,
" medium \"%s\";\n", s);
3646 memset (&ds, 0,
sizeof ds);
3648 write_options(client, lease->
options,
" ");
3652 fprintf(
leaseFile,
" renew %s\n", tval) < 0)
3657 fprintf(
leaseFile,
" rebind %s\n", tval) < 0)
3662 fprintf(
leaseFile,
" expire %s\n", tval) < 0)
3673 if (!errors && makesure) {
3675 log_info (
"write_client_lease: %m");
3680 return errors ? 0 : 1;
3697 for (sl = client -> env; sl; sl =
next) {
3704 if (client -> interface) {
3706 client -> interface -> name);
3710 "",
"client",
"%s", client -> name);
3713 "",
"medium",
"%s", medium ->
string);
3716 client_envadd (client,
"",
"pid",
"%ld", (
long int)getpid ());
3721 struct packet *packet,
struct lease *lease,
3730 memset (&data, 0,
sizeof data);
3733 in_options, cfg_options, scope, oc,
MDL)) {
3743 length = strlen(value);
3747 value, length) == 0) {
3752 "option - discarded",
3775 prefix,
"ip_address",
"%s",
piaddr (lease -> address));
3784 memset (&data, 0,
sizeof data);
3787 (
struct lease *)0, client,
3792 struct iaddr netmask, subnet, broadcast;
3815 (&data, (
struct packet *)0,
3816 (
struct lease *)0, client,
3821 if (broadcast.
len) {
3823 prefix,
"broadcast_address",
3824 "%s",
piaddr (broadcast));
3840 "option - discarded",
3853 "option - discarded",
3865 client_envadd (client, prefix,
"expiry",
"%d", (
int)(lease -> expiry));
3885 for (i = 0 ; req[i] != NULL ; i++) {
3899 char reason [] =
"REASON=NBI";
3900 static char client_path [] = CLIENT_PATH;
3903 int pid, wpid, wstatus;
3906 scriptName = client -> config -> script_name;
3910 envp =
dmalloc (((client ? client -> envc : 2) +
3913 log_error (
"No memory for client script environment.");
3919 for (sp = client_env; sp; sp = sp ->
next) {
3920 envp [i++] = sp ->
string;
3924 for (sp = client -> env; sp; sp = sp ->
next) {
3925 envp [i++] = sp ->
string;
3928 envp [i++] = reason;
3931 envp [i++] = client_path;
3932 envp [i] = (
char *)0;
3935 argv [1] = (
char *)0;
3943 wpid = wait (&wstatus);
3944 }
while (wpid != pid && wpid > 0);
3955 execve (scriptName, argv, envp);
3956 log_error (
"execve (%s, ...): %m", scriptName);
3961 for (sp = client -> env; sp; sp =
next) {
3969 gettimeofday(&
cur_tv, NULL);
3970 return (WIFEXITED (wstatus) ?
3971 WEXITSTATUS (wstatus) : -WTERMSIG (wstatus));
3975 const char *prefix,
const char *name,
const char *fmt, ...)
3983 va_start (list, fmt);
3984 len = vsnprintf (spbuf,
sizeof spbuf, fmt, list);
3987 val =
dmalloc (strlen (prefix) + strlen (name) + 1 +
3988 len +
sizeof *val,
MDL);
3996 if (len >=
sizeof spbuf) {
3997 va_start (list, fmt);
3998 vsnprintf (s, len + 1, fmt, list);
4002 val ->
next = client -> env;
4003 client -> env = val;
4026 if (j + 1 == buflen)
4036 if (j + 1 == buflen)
4049 static int state = 0;
4067 if ((pid = fork ()) < 0)
4080 (void) open(
"/dev/null", O_RDWR | O_CLOEXEC);
4081 (void) open(
"/dev/null", O_RDWR | O_CLOEXEC);
4082 (void) open(
"/dev/null", O_RDWR | O_CLOEXEC);
4099 pfdesc = open (
path_dhclient_pid, O_CREAT | O_TRUNC | O_WRONLY | O_CLOEXEC, 0644);
4106 pf = fdopen (pfdesc,
"we");
4111 fprintf (pf,
"%ld\n", (
long)getpid ());
4122 for (client = ip -> client; client; client = client ->
next) {
4123 switch (client ->
state) {
4157 client -> xid = random ();
4160 if (client -> active) {
4165 memset (&ds, 0,
sizeof ds);
4167 client -> active -> options,
4171 (
struct lease *)0, client,
4173 client -> active -> options,
4176 memcpy (client -> destination.iabuf,
4178 client -> destination.len = 4;
4185 client -> first_sending =
cur_time;
4186 client -> interval = client -> config -> initial_interval;
4197 if (client -> alias)
4227 if (!strcmp (ip ->
name, tmp ->
name)) {
4231 interface_reference (&ip, last ->
next,
MDL);
4232 interface_dereference (&last ->
next,
MDL);
4234 interface_reference (&last ->
next,
4236 interface_dereference (&ip ->
next,
4241 interface_reference (&ip,
4247 interface_dereference (&ip ->
next,
4253 tmp -> client = ip ->
client;
4254 tmp -> client ->
interface = tmp;
4256 interface_dereference (&ip,
MDL);
4291 if (ip -> client ->
alias)
4293 ip -> client ->
alias);
4305 for (client = ip->
client ; client ; client = client->
next) {
4310 return ISC_R_SUCCESS;
4317 struct packet *packet;
4336 static void shutdown_exit (
void *foo)
4341 #if defined (NSUPDATE) 4358 isc_result_t eresult)
4361 isc_result_t result;
4363 if ((eresult == ISC_R_SUCCESS) &&
4369 if (result == ISC_R_SUCCESS) {
4384 isc_result_t result;
4387 if (client->
ddns_cb != NULL) {
4393 if (ddns_cb != NULL) {
4399 ddns_cb->
cur_func = client_dns_remove_action;
4403 if (result != ISC_R_TIMEDOUT) {
4420 return ISC_R_SUCCESS;
4424 log_info(
"Received signal %d, initiating shutdown.",
4433 for (client = ip -> client; client; client = client -> next) {
4436 return ISC_R_SUCCESS;
4439 return ISC_R_SUCCESS;
4442 if (client -> active &&
4443 client -> active -> expiry >
cur_time) {
4444 #if defined (NSUPDATE) 4466 tv.tv_sec =
cur_tv.tv_sec;
4467 tv.tv_usec =
cur_tv.tv_usec + 1;
4470 return ISC_R_SUCCESS;
4473 #if defined (NSUPDATE) 4484 isc_result_t status = ISC_R_FAILURE;
4486 if ((client != NULL) &&
4487 ((client->
active != NULL) ||
4500 if (status != ISC_R_TIMEDOUT) {
4501 if (client != NULL) {
4539 isc_result_t eresult)
4541 isc_result_t result;
4558 ddns_cb->
cur_func = client_dns_update_action;
4561 if (result == ISC_R_SUCCESS) {
4567 case ISC_R_TIMEDOUT:
4575 if (ddns_cb->
zone != NULL) {
4581 ddns_cb->
cur_func = client_dns_update_action;
4587 tv.tv_usec =
cur_tv.tv_usec;
4589 ddns_cb, NULL, NULL);
4611 if (!client -> sent_options)
4612 return ISC_R_SUCCESS;
4616 return ISC_R_SUCCESS;
4622 (
struct lease *)0, client,
4623 client -> sent_options,
4626 return ISC_R_SUCCESS;
4633 (
struct lease *)0, client,
4634 client -> sent_options,
4637 return ISC_R_SUCCESS;
4643 (
struct lease *)0, client,
4644 client -> sent_options,
4647 return ISC_R_SUCCESS;
4659 memset(&client_identifier, 0,
sizeof(client_identifier));
4683 client_identifier.
data,
4684 client_identifier.
len);
4702 (client_identifier.
data[0] == 255)) {
4707 if (client_identifier.
len <= 5)
4708 log_fatal(
"Impossible condition at %s:%d.",
4711 client_identifier.
data + 5,
4712 client_identifier.
len - 5);
4714 result =
get_dhcid(ddns_cb, ddns_v4_type,
4715 client_identifier.
data,
4716 client_identifier.
len);
4726 return ISC_R_SUCCESS;
4735 rcode = ISC_R_FAILURE;
4741 if (rcode == ISC_R_SUCCESS) {
4742 rcode = ISC_R_TIMEDOUT;
4765 if (client->
ddns_cb != NULL) {
4772 if (ddns_cb != NULL) {
4773 ddns_cb->
lease = (
void *)client;
4786 ddns_cb->
cur_func = client_dns_update_action;
4791 tv.tv_sec =
cur_tv.tv_sec + offset;
4792 tv.tv_usec =
cur_tv.tv_usec;
4794 ddns_cb, NULL, NULL);
4796 log_error(
"Unable to allocate dns update state for %s",
4805 struct servent *ent;
4819 ent = getservbyname (
"dhcpc",
"udp");
4824 #ifndef __CYGWIN32__ 4848 static int check_domain_name(
const char *ptr,
size_t len,
int dots)
4853 if ((len == 0) || (len > 256))
4858 for (p=ptr; (*p != 0) && (len-- > 0); p++) {
4859 if ((*p ==
'-') || (*p ==
'_')) {
4861 if (((p - ptr) == 0) || (len == 0) || (p[1] ==
'.'))
4863 }
else if (*p ==
'.') {
4867 if ((d <= 0) || (d >= 64))
4870 if ((dots > 0) && (len > 0))
4872 }
else if (isalnum((
unsigned char)*p) == 0) {
4877 return(dots ? -1 : 0);
4880 static int check_domain_name_list(
const char *ptr,
size_t len,
int dots)
4885 if ((ptr == NULL) || (len == 0))
4888 for (p=ptr; (*p != 0) && (len > 0); p++, len--) {
4892 if (check_domain_name(ptr, p - ptr, dots) != 0)
4899 return(check_domain_name(ptr, p - ptr, dots));
4916 #ifdef ACCEPT_LIST_IN_DOMAIN_NAME 4917 return check_domain_name_list(ptr, len, 0);
4919 return check_domain_name(ptr, len, 0);
4924 return check_domain_name(ptr, len, 0);
4927 return check_domain_name_list(ptr, len, 0);
4932 for (; (*ptr != 0) && (len-- > 0); ptr++) {
4933 if(!(isalnum((
unsigned char)*ptr) ||
4934 *ptr ==
'#' || *ptr ==
'%' ||
4935 *ptr ==
'+' || *ptr ==
'-' ||
4936 *ptr ==
'_' || *ptr ==
':' ||
4937 *ptr ==
'.' || *ptr ==
',' ||
4938 *ptr ==
'@' || *ptr ==
'~' ||
4939 *ptr ==
'\\' || *ptr ==
'/' ||
4940 *ptr ==
'[' || *ptr ==
']' ||
4941 *ptr ==
'=' || *ptr ==
' '))
4956 return check_domain_name_list(ptr, len, 0);
4966 add_reject(
struct packet *packet) {
4971 log_fatal (
"no memory for reject list!");
4990 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)
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
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
struct option_state * options
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)
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)
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
void bind_lease(struct client_state *client, struct in_addr *siaddr)
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 *)
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
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