41 #include <dns/result.h> 51 extern int asprintf(
char **strp,
const char *fmt, ...);
82 #define ASSERT_STATE(state_is, state_shouldbe) {} 85 static const char copyright[] =
"Copyright 2004-2016 Internet Systems Consortium.";
86 static const char arr [] =
"All rights reserved.";
87 static const char message [] =
"Internet Systems Consortium DHCP Client";
88 static const char url [] =
"For info, please visit https://www.isc.org/software/dhcp/";
93 #if defined(DHCPv6) && defined(DHCP4o6) 94 int dhcp4o6_state = -1;
119 static isc_result_t write_duid(
struct data_string *duid);
122 static int check_domain_name(
const char *ptr,
size_t len,
int dots);
123 static int check_domain_name_list(
const char *ptr,
size_t len,
int dots);
125 const char *ptr,
size_t len);
146 #if defined(DHCPv6) && defined(DHCP4o6) 147 static void dhcp4o6_poll(
void *dummy);
148 static void dhcp4o6_resume(
void);
149 static void recv_dhcpv4_response(
struct data_string *raw);
150 static int send_dhcpv4_query(
struct client_state *client,
int broadcast);
152 static void dhcp4o6_stop(
void);
153 static void forw_dhcpv4_response(
struct packet *
packet);
154 static void forw_dhcpv4_query(
struct data_string *raw);
161 static const char use_noarg[] =
"No argument for command: %s";
163 static const char use_v6command[] =
"Command not used for DHCPv4: %s";
169 usage(
const char *sfmt,
const char *sarg)
177 #ifdef PRINT_SPECIFIC_CL_ERRORS 185 "[-4|-6] [-SNTPRI1dvrxi] [-nw] -4o6 <port>]\n" 186 " [-p <port>] [-D LL|LLT] \n" 188 "[-4|-6] [-SNTPRI1dvrxi] [-nw] [-p <port>] [-D LL|LLT] \n" 191 "[-I1dvrxi] [-nw] [-p <port>] [-D LL|LLT] \n" 193 " [-s server-addr] [-cf config-file]\n" 194 " [-df duid-file] [-lf lease-file]\n" 195 " [-pf pid-file] [--no-pid] [-e VAR=val]\n" 196 " [-sf script-file] [interface]*\n" 197 " [-C <dhcp-client-identifier>] [-B]\n" 198 " [-H <host-name> | -F <fqdn.fqdn>] [--timeout <timeout>]\n" 199 " [-V <vendor-class-identifier>]\n" 200 " [--request-options <request option list>]",
214 int release_mode = 0;
219 int no_dhclient_conf = 0;
220 int no_dhclient_db = 0;
221 int no_dhclient_pid = 0;
222 int no_dhclient_script = 0;
224 int local_family_set = 0;
226 u_int16_t dhcp4o6_port = 0;
237 char *dhcp_client_identifier_arg = NULL;
238 char *dhcp_host_name_arg = NULL;
239 char *dhcp_fqdn_arg = NULL;
240 char *dhcp_vendor_class_identifier_arg = NULL;
241 char *dhclient_request_options = NULL;
244 char *arg_conf = NULL;
245 int arg_conf_len = 0;
246 #ifdef HAVE_LIBCAP_NG 247 int keep_capabilities = 0;
256 fd = open(
"/dev/null", O_RDWR | O_CLOEXEC);
258 fd = open(
"/dev/null", O_RDWR | O_CLOEXEC);
260 fd = open(
"/dev/null", O_RDWR | O_CLOEXEC);
268 #if !(defined(DEBUG) || defined(__CYGWIN32__)) 269 setlogmask(LOG_UPTO(LOG_INFO));
275 if (status != ISC_R_SUCCESS)
276 log_fatal(
"Can't initialize context: %s",
277 isc_result_totext(status));
281 if (status != ISC_R_SUCCESS)
283 isc_result_totext(status));
293 for (i = 1; i < argc; i++) {
294 if (!strcmp(argv[i],
"-r")) {
298 }
else if (!strcmp(argv[i],
"-4")) {
300 log_fatal(
"Client can only do v4 or v6, not " 302 local_family_set = 1;
304 }
else if (!strcmp(argv[i],
"-6")) {
306 log_fatal(
"Client can only do v4 or v6, not " 308 local_family_set = 1;
311 }
else if (!strcmp(argv[i],
"-4o6")) {
313 usage(use_noarg, argv[i-1]);
316 log_debug(
"DHCPv4 over DHCPv6 over ::1 port %d and %d",
318 ntohs(dhcp4o6_port) + 1);
322 }
else if (!strcmp(argv[i],
"-x")) {
326 }
else if (!strcmp(argv[i],
"-p")) {
328 usage(use_noarg, argv[i-1]);
330 log_debug(
"binding to user-specified port %d",
332 }
else if (!strcmp(argv[i],
"-d")) {
335 }
else if (!strcmp(argv[i],
"-pf")) {
337 usage(use_noarg, argv[i-1]);
340 }
else if (!strcmp(argv[i],
"--no-pid")) {
342 }
else if (!strcmp(argv[i],
"-cf")) {
344 usage(use_noarg, argv[i-1]);
346 no_dhclient_conf = 1;
347 }
else if (!strcmp(argv[i],
"-df")) {
349 usage(use_noarg, argv[i-1]);
351 }
else if (!strcmp(argv[i],
"-lf")) {
353 usage(use_noarg, argv[i-1]);
356 }
else if (!strcmp(argv[i],
"-sf")) {
358 usage(use_noarg, argv[i-1]);
360 no_dhclient_script = 1;
361 }
else if (!strcmp(argv[i],
"-1")) {
363 }
else if (!strcmp(argv[i],
"-q")) {
365 }
else if (!strcmp(argv[i],
"-s")) {
367 usage(use_noarg, argv[i-1]);
369 }
else if (!strcmp(argv[i],
"-g")) {
371 usage(use_noarg, argv[i-1]);
373 }
else if (!strcmp(argv[i],
"-nw")) {
375 }
else if (!strcmp(argv[i],
"-n")) {
378 }
else if (!strcmp(argv[i],
"-w")) {
381 }
else if (!strcmp(argv[i],
"-e")) {
384 usage(use_noarg, argv[i-1]);
385 tmp =
dmalloc(strlen(argv[i]) +
sizeof *tmp,
MDL);
388 strcpy(tmp->
string, argv[i]);
393 }
else if (!strcmp(argv[i],
"-S")) {
395 usage(use_v6command, argv[i]);
397 local_family_set = 1;
401 }
else if (!strcmp(argv[i],
"-N")) {
403 usage(use_v6command, argv[i]);
405 local_family_set = 1;
411 }
else if (!strcmp(argv[i],
"-T")) {
413 usage(use_v6command, argv[i]);
415 local_family_set = 1;
421 }
else if (!strcmp(argv[i],
"-P")) {
423 usage(use_v6command, argv[i]);
425 local_family_set = 1;
431 }
else if (!strcmp(argv[i],
"-R")) {
433 usage(use_v6command, argv[i]);
435 local_family_set = 1;
439 }
else if (!strcmp(argv[i],
"-D")) {
442 usage(use_noarg, argv[i-1]);
443 if (!strcasecmp(argv[i],
"LL")) {
445 }
else if (!strcasecmp(argv[i],
"LLT")) {
448 usage(
"Unknown argument to -D: %s", argv[i]);
450 }
else if (!strcmp(argv[i],
"-i")) {
453 }
else if (!strcmp(argv[i],
"-I")) {
456 }
else if (!strcmp(argv[i],
"-v")) {
458 }
else if (!strcmp(argv[i],
"--version")) {
459 const char vstring[] =
"isc-dhclient-";
467 }
else if (!strcmp(argv[i],
"-C")) {
468 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
469 usage(use_noarg, argv[i-1]);
478 dhcp_client_identifier_arg = argv[i];
479 }
else if (!strcmp(argv[i],
"-B")) {
481 }
else if (!strcmp(argv[i],
"-H")) {
482 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
483 usage(use_noarg, argv[i-1]);
492 if (dhcp_host_name_arg != NULL) {
493 log_error(
"The -H <host-name> and -F <fqdn> arguments are mutually exclusive");
497 dhcp_host_name_arg = argv[i];
498 }
else if (!strcmp(argv[i],
"-F")) {
499 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
500 usage(use_noarg, argv[i-1]);
509 if (dhcp_fqdn_arg != NULL) {
510 log_error(
"Only one -F <fqdn> argument can be specified");
514 if (dhcp_host_name_arg != NULL) {
515 log_error(
"The -F <fqdn> and -H <host-name> arguments are mutually exclusive");
519 dhcp_fqdn_arg = argv[i];
520 }
else if (!strcmp(argv[i],
"--timeout")) {
521 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
522 usage(use_noarg, argv[i-1]);
526 if ((timeout_arg = atoi(argv[i])) <= 0) {
527 log_error(
"timeout option must be > 0 - bad value: %s",argv[i]);
530 }
else if (!strcmp(argv[i],
"-V")) {
531 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
532 usage(use_noarg, argv[i-1]);
541 dhcp_vendor_class_identifier_arg = argv[i];
542 }
else if (!strcmp(argv[i],
"--request-options")) {
543 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
544 usage(use_noarg, argv[i-1]);
548 dhclient_request_options = argv[i];
549 }
else if (!strcmp(argv[i],
"-nc")) {
550 #ifdef HAVE_LIBCAP_NG 551 keep_capabilities = 1;
553 }
else if (argv[i][0] ==
'-') {
554 usage(
"Unknown command: %s", argv[i]);
556 usage(
"No interfaces comamnd -n and " 557 " requested interface %s", argv[i]);
561 status = interface_allocate(&tmp,
MDL);
562 if (status != ISC_R_SUCCESS)
563 log_fatal(
"Can't record interface %s:%s",
564 argv[i], isc_result_totext(status));
565 if (strlen(argv[i]) >=
sizeof(tmp->
name))
566 log_fatal(
"%s: interface name too long (is %ld)",
567 argv[i], (
long)strlen(argv[i]));
568 strcpy(tmp->
name, argv[i]);
570 interface_reference(&tmp->
next,
586 usage(
"PD %s only supports one requested interface",
"-P");
589 #if defined(DHCPv6) && defined(DHCP4o6) 591 (exit_mode || release_mode))
592 log_error(
"Can't relay DHCPv4-over-DHCPv6 " 593 "without a persistent DHCPv6 client");
596 log_fatal(
"DHCPv4-over-DHCPv6 requires an explicit " 597 "interface on which to be applied");
600 if (!no_dhclient_conf && (s = getenv(
"PATH_DHCLIENT_CONF"))) {
603 if (!no_dhclient_db && (s = getenv(
"PATH_DHCLIENT_DB"))) {
606 if (!no_dhclient_pid && (s = getenv(
"PATH_DHCLIENT_PID"))) {
609 if (!no_dhclient_script && (s = getenv(
"PATH_DHCLIENT_SCRIPT"))) {
613 #ifdef HAVE_LIBCAP_NG 615 if (!keep_capabilities) {
616 capng_clear(CAPNG_SELECT_CAPS);
617 capng_update(CAPNG_ADD, CAPNG_EFFECTIVE|CAPNG_PERMITTED,
619 capng_updatev(CAPNG_ADD, CAPNG_EFFECTIVE|CAPNG_PERMITTED,
620 CAP_NET_ADMIN, CAP_NET_RAW,
621 CAP_NET_BIND_SERVICE, CAP_SYS_ADMIN, -1);
622 capng_apply(CAPNG_SELECT_CAPS);
647 log_fatal(
"Failed to get realpath for %s: %s", old_path, strerror(errno));
654 log_fatal(
"Failed to get realpath for %s: %s", old_path, strerror(errno));
663 if ((release_mode || exit_mode) && (
no_pid_file == ISC_FALSE)) {
670 e = fscanf(pidfd,
"%ld\n", &temp);
671 oldpid = (pid_t)temp;
673 if (e != 0 && e != EOF && oldpid) {
674 if (kill(oldpid, SIGTERM) == 0) {
675 log_info(
"Killed old client process");
685 }
else if (errno == ESRCH) {
699 char *new_path_dhclient_pid;
718 int n_len = strlen(ip->
name);
720 new_path_dhclient_pid = (
char*) malloc(pfx + n_len + 6);
722 sprintf(new_path_dhclient_pid + pfx,
"-%s.pid", ip->
name);
724 if ((pidfd = fopen(new_path_dhclient_pid,
"re")) != NULL) {
725 e = fscanf(pidfd,
"%ld\n", &temp);
726 oldpid = (pid_t)temp;
728 if (e != 0 && e != EOF) {
730 if (kill(oldpid, SIGTERM) == 0)
738 free(new_path_dhclient_pid);
747 char procfn[256] =
"";
750 if ((fscanf(pidfp,
"%ld", &temp)==1) && ((dhcpid=(pid_t)temp) > 0)) {
751 snprintf(procfn,256,
"/proc/%u",dhcpid);
752 dhc_running = (access(procfn, F_OK) == 0);
759 log_fatal(
"dhclient(%u) is already running - exiting. ", dhcpid);
784 memcpy(&
giaddr, he->h_addr_list[0],
793 gettimeofday(&
cur_tv, NULL);
800 he = gethostbyname(server);
826 usage(
"Stateless commnad: %s incompatibile with " 827 "other commands",
"-S");
829 #if defined(DHCPv6) && defined(DHCP4o6) 838 if ((dhcp_client_identifier_arg != NULL) && (*dhcp_client_identifier_arg !=
'\0')) {
839 arg_conf_len =
asprintf(&arg_conf,
"send dhcp-client-identifier \"%s\";", dhcp_client_identifier_arg);
841 if ((arg_conf == 0) || (arg_conf_len <= 0))
842 log_fatal(
"Unable to send -C option dhcp-client-identifier");
845 if ((dhcp_host_name_arg != NULL) && (*dhcp_host_name_arg !=
'\0')) {
847 arg_conf_len =
asprintf(&arg_conf,
"send host-name \"%s\";", dhcp_host_name_arg);
849 if ((arg_conf == 0) || (arg_conf_len <= 0))
850 log_fatal(
"Unable to send -H option host-name");
852 char *last_arg_conf = arg_conf;
854 arg_conf_len =
asprintf(&arg_conf,
"%s\nsend host-name \"%s\";", last_arg_conf, dhcp_host_name_arg);
856 if ((arg_conf == 0) || (arg_conf_len <= 0))
857 log_fatal(
"Unable to send -H option host-name");
863 if ((dhcp_fqdn_arg != NULL) && (*dhcp_fqdn_arg !=
'\0')) {
865 arg_conf_len =
asprintf(&arg_conf,
"send fqdn.fqdn \"%s\";", dhcp_fqdn_arg);
867 if ((arg_conf == 0) || (arg_conf_len <= 0))
868 log_fatal(
"Unable to send -F option fqdn.fqdn");
870 char *last_arg_conf = arg_conf;
872 arg_conf_len =
asprintf(&arg_conf,
"%s\nsend fqdn.fqdn \"%s\";", last_arg_conf, dhcp_fqdn_arg);
874 if ((arg_conf == 0) || (arg_conf_len <= 0))
875 log_fatal(
"Unable to send -F option fqdn.fqdn");
883 arg_conf_len =
asprintf(&arg_conf,
"timeout %d;", timeout_arg);
885 if ((arg_conf == 0) || (arg_conf_len <= 0))
886 log_fatal(
"Unable to process --timeout timeout argument");
888 char *last_arg_conf = arg_conf;
890 arg_conf_len =
asprintf(&arg_conf,
"%s\ntimeout %d;", last_arg_conf, timeout_arg);
892 if ((arg_conf == 0) || (arg_conf_len == 0))
893 log_fatal(
"Unable to process --timeout timeout argument");
899 if ((dhcp_vendor_class_identifier_arg != NULL) && (*dhcp_vendor_class_identifier_arg !=
'\0')) {
901 arg_conf_len =
asprintf(&arg_conf,
"send vendor-class-identifier \"%s\";", dhcp_vendor_class_identifier_arg);
903 if ((arg_conf == 0) || (arg_conf_len <= 0))
904 log_fatal(
"Unable to send -V option vendor-class-identifier");
906 char *last_arg_conf = arg_conf;
908 arg_conf_len =
asprintf(&arg_conf,
"%s\nsend vendor-class-identifier \"%s\";", last_arg_conf, dhcp_vendor_class_identifier_arg);
910 if ((arg_conf == 0) || (arg_conf_len <= 0))
911 log_fatal(
"Unable to send -V option vendor-class-identifier");
917 if (dhclient_request_options != NULL) {
919 arg_conf_len =
asprintf(&arg_conf,
"request %s;", dhclient_request_options);
921 if ((arg_conf == 0) || (arg_conf_len <= 0))
922 log_fatal(
"Unable to parse --request-options <request options list> argument");
924 char *last_arg_conf = arg_conf;
926 arg_conf_len =
asprintf(&arg_conf,
"%s\nrequest %s;", last_arg_conf, dhclient_request_options);
928 if ((arg_conf == 0) || (arg_conf_len <= 0))
929 log_fatal(
"Unable to parse --request-options <request options list> argument");
936 if (arg_conf_len == 0)
937 if ((arg_conf_len = strlen(arg_conf)) == 0)
939 log_fatal(
"Unable to process -C/-H/-F/--timeout/-V/--request-options configuration arguments");
944 const char *val = NULL;
947 status =
new_parse(&cfile, -1, arg_conf, arg_conf_len,
"extra dhclient -C/-H/-F/--timeout/-V/--request-options configuration arguments", 0);
950 log_fatal(
"Cannot parse -C/-H/-F/--timeout/-V/--request-options configuration arguments !");
954 token =
peek_token(&val, (
unsigned *)0, cfile);
962 log_fatal(
"Cannot parse -C/-H/-F/--timeout/-V/--request-options configuration arguments !");
1019 log_info(
"No broadcast interfaces found - exiting.");
1022 }
else if (!release_mode && !exit_mode) {
1056 unsigned backup_seed = 0;
1059 if ( ip -> hw_address.hlen <=
sizeof seed )
1062 &ip -> hw_address.hbuf [ip -> hw_address.hlen -
1063 sizeof seed],
sizeof seed);
1085 if ( ip -> hw_address.hlen <=
sizeof seed )
1089 sizeof seed],
sizeof seed);
1093 if ( seed_flag == 0 ) {
1094 if ( backup_seed != 0 ) {
1096 log_info (
"xid: rand init seed (0x%x) built using all" 1097 " available interfaces",seed);
1100 seed =
cur_time^((unsigned) gethostid()) ;
1101 log_info (
"xid: warning: no netdev with useable HWADDR found" 1102 " for seed's uniqueness enforcement");
1103 log_info (
"xid: rand init seed (0x%x) built using gethostid",
1108 srandom(seed + ((
unsigned)(
cur_tv.tv_usec * 1000000)) + (
unsigned)getpid());
1111 srandom(seed + ((
unsigned)(
cur_tv.tv_usec * 1000000)) + (
unsigned)getpid());
1117 setup_ib_interface(ip);
1136 #if defined(DHCPv6) && defined(DHCP4o6) 1138 dhcp4o6_setup(dhcp4o6_port);
1145 for (client = ip->
client ; client != NULL ;
1146 client = client->
next) {
1150 }
else if (exit_mode) {
1170 for (client = ip->
client ; client ;
1171 client = client->
next) {
1188 tv.tv_usec = random()
1223 if (result != ISC_R_SUCCESS)
1224 log_fatal(
"Can't allocate new generic object: %s\n",
1225 isc_result_totext(result));
1230 if (result != ISC_R_SUCCESS)
1231 log_fatal(
"Can't start OMAPI protocol: %s",
1232 isc_result_totext (result));
1241 #if defined(DEBUG_MEMORY_LEAKAGE) || defined(DEBUG_MALLOC_POOL) || \ 1242 defined(DEBUG_MEMORY_LEAKAGE_ON_EXIT) 1243 dmalloc_cutoff_generation = dmalloc_generation;
1244 dmalloc_longterm = dmalloc_outstanding;
1245 dmalloc_outstanding = 0;
1248 #if defined(ENABLE_GENTLE_SHUTDOWN) 1285 isc_result_t result;
1294 usage(
"No interfaces available for stateless command: %s",
"-S");
1337 dhcp4o6_setup(port);
1343 client = client->
next) {
1357 if (result != ISC_R_SUCCESS)
1358 log_fatal(
"Can't allocate new generic object: %s\n",
1359 isc_result_totext(result));
1364 if (result != ISC_R_SUCCESS)
1365 log_fatal(
"Can't start OMAPI protocol: %s",
1366 isc_result_totext(result));
1372 #if defined(DEBUG_MEMORY_LEAKAGE) || defined(DEBUG_MALLOC_POOL) || \ 1373 defined(DEBUG_MEMORY_LEAKAGE_ON_EXIT) 1374 dmalloc_cutoff_generation = dmalloc_generation;
1375 dmalloc_longterm = dmalloc_outstanding;
1376 dmalloc_outstanding = 0;
1398 const char *s,
const char *
file,
int line)
1412 struct packet *packet;
1418 struct lease *lease;
1442 "dhcp-client-identifier") == 0)) {
1485 #if defined(DHCPv6) && defined(DHCP4o6) 1487 if (dhcp4o6_state < 0)
1498 client ->
active -> is_bootp ||
1512 client ->
xid = random ();
1545 client -> xid = client -> packet.xid;
1548 client -> first_sending =
cur_time;
1549 client -> interval = client -> config -> initial_interval;
1592 for (lp = client -> offered_leases; lp; lp =
next) {
1601 picked -> next = NULL;
1606 client -> offered_leases = NULL;
1613 client -> state =
S_INIT;
1620 client ->
new = picked;
1638 client -> first_sending =
cur_time;
1639 client -> interval = client -> config -> initial_interval;
1643 client -> xid = client -> packet.xid;
1656 struct packet *packet;
1666 for (client = ip -> client; client; client = client -> next) {
1667 if (client -> xid == packet -> raw -> xid)
1671 (packet -> interface -> hw_address.hlen - 1 !=
1672 packet -> raw -> hlen) ||
1673 (memcmp (&packet -> interface -> hw_address.hbuf [1],
1674 packet -> raw -> chaddr, packet -> raw -> hlen))) {
1676 log_debug (
"DHCPACK in wrong transaction.");
1691 log_info (
"DHCPACK from %s (xid=0x%x)",
piaddr (packet -> client_addr), ntohl(client -> xid));
1695 log_info (
"packet_to_lease failed.");
1699 client ->
new = lease;
1707 memset (&ds, 0,
sizeof ds);
1710 packet -> options, client ->
new -> options,
1715 client ->
new -> expiry = 0;
1718 client ->
new -> expiry = 0;
1723 log_error (
"no expiry time on offered lease.");
1729 tv.tv_sec =
cur_tv.tv_sec;
1730 tv.tv_usec =
cur_tv.tv_usec + 500000;
1732 if (tv.tv_usec >= 1000000) {
1734 tv.tv_usec -= 1000000;
1753 packet -> options, client ->
new -> options,
1758 client ->
new -> renewal = 0;
1761 client ->
new -> renewal = 0;
1764 if (!client ->
new -> renewal)
1765 client ->
new -> renewal = client ->
new -> expiry / 2 + 1;
1767 if (client ->
new -> renewal <= 0)
1768 client ->
new -> renewal =
TIME_MAX;
1773 (((random() % client->
new->
renewal) + 3) / 4);
1780 packet -> options, client ->
new -> options,
1785 client ->
new -> rebind = 0;
1788 client ->
new -> rebind = 0;
1790 if (client ->
new -> rebind <= 0) {
1791 if (client ->
new -> expiry <=
TIME_MAX / 7)
1792 client ->
new -> rebind =
1793 client ->
new -> expiry * 7 / 8;
1795 client ->
new -> rebind =
1796 client ->
new -> expiry / 8 * 7;
1801 if (client ->
new -> renewal > client ->
new -> rebind) {
1802 if (client ->
new -> rebind <=
TIME_MAX / 3)
1803 client ->
new -> renewal =
1804 client ->
new -> rebind * 3 / 4;
1806 client ->
new -> renewal =
1807 client ->
new -> rebind / 4 * 3;
1810 client ->
new -> expiry +=
cur_time;
1812 if (client ->
new -> expiry <
cur_time)
1813 client ->
new -> expiry =
TIME_MAX;
1814 client ->
new -> renewal +=
cur_time;
1815 if (client ->
new -> renewal <
cur_time)
1816 client ->
new -> renewal =
TIME_MAX;
1817 client ->
new -> rebind +=
cur_time;
1818 if (client ->
new -> rebind <
cur_time)
1819 client ->
new -> rebind =
TIME_MAX;
1855 log_info(
"Unable to obtain a lease on first " 1856 "try (declined). Exiting.");
1879 random() % 1000000 :
cur_tv.tv_usec;
1882 log_info(
"bound to %s -- renewal in %ld seconds.",
1888 #if defined (NSUPDATE) 1910 client -> xid = client -> packet.xid;
1912 memset (&ds, 0,
sizeof ds);
1918 client -> active -> options,
1921 memcpy (client -> destination.iabuf, ds.
data, 4);
1922 client -> destination.len = 4;
1930 client -> first_sending =
cur_time;
1931 client -> interval = client -> config -> initial_interval;
1971 struct lease *lease;
1988 struct packet *packet;
1999 for (ap = packet -> interface -> client -> config -> reject_list;
2000 ap; ap = ap ->
next) {
2009 log_info(
"BOOTREPLY from %s rejected by rule %s " 2021 struct packet *packet;
2024 void (*handler) (
struct packet *);
2051 for (ap = packet ->
interface -> client -> config -> reject_list;
2052 ap; ap = ap -> next) {
2061 log_info(
"%s from %s rejected by rule %s mask %s.",
2067 (*handler) (packet);
2072 dhcpv6(
struct packet *packet) {
2075 char addrbuf[
sizeof(
"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")];
2083 ap ; ap = ap->
next) {
2086 log_info(
"%s from %s rejected by rule %s",
2099 log_info(
"RCV: %s message on %s from %s.",
2103 forw_dhcpv4_response(packet);
2113 log_info(
"RCV: %s message on %s from %s.",
2124 client = client->
next) {
2133 log_info(
"Packet received, but nothing done with it.");
2149 static void forw_dhcpv4_response(
struct packet *packet)
2159 if (dhcp4o6_state == -1) {
2160 log_info(
"forw_dhcpv4_response: not ready.");
2165 log_error(
"forw_dhcpv4_response: bad address");
2174 log_info(
"DHCPv4-response from %s missing " 2175 "DHCPv4 Message option.",
2180 memset(&enc_opt_data, 0,
sizeof(enc_opt_data));
2183 log_error(
"forw_dhcpv4_response: error evaluating " 2191 "no memory for encapsulated packet.");
2199 memset(&ds, 0,
sizeof(ds));
2201 log_error(
"forw_dhcpv4_response: no memory buffer.");
2206 ds.
len = enc_opt_data.
len + 16;
2215 cc = send(dhcp4o6_fd, ds.
data, ds.
len, 0);
2217 log_error(
"forw_dhcpv4_response: send(): %m");
2231 static void recv_dhcpv4_response(
struct data_string *raw)
2233 struct packet *packet;
2237 log_error(
"recv_dhcpv4_response: no interfaces.");
2249 log_error(
"recv_dhcpv4_response: no memory for packet.");
2261 log_error(
"recv_dhcpv4_response: no memory for options.");
2282 memset(&dp, 0,
sizeof dp);
2308 struct packet *packet;
2316 const char *
name = packet -> packet_type ?
"DHCPOFFER" :
"BOOTREPLY";
2325 for (client = ip -> client; client; client = client -> next)
2326 if (client -> xid == packet -> raw -> xid)
2333 (packet -> interface -> hw_address.hlen - 1 !=
2334 packet -> raw -> hlen) ||
2335 (memcmp (&packet -> interface -> hw_address.hbuf [1],
2336 packet -> raw -> chaddr, packet -> raw -> hlen))) {
2338 log_debug (
"%s in wrong transaction.", name);
2343 sprintf (obuf,
"%s from %s", name,
piaddr (packet -> client_addr));
2351 for (i = 0 ; req[i] != NULL ; i++) {
2358 option_code_hash_lookup(&option,
2363 log_info(
"%s: no %s option.", obuf,
2366 log_info(
"%s: no unknown-%u option.",
2377 for (lease = client -> offered_leases; lease; lease = lease -> next) {
2378 if (lease -> address.len ==
sizeof packet -> raw -> yiaddr &&
2379 !memcmp (lease -> address.iabuf,
2380 &packet -> raw -> yiaddr, lease -> address.len)) {
2388 log_info (
"%s: packet_to_lease failed.", obuf);
2394 if (!packet -> options_valid || !packet -> packet_type)
2395 lease -> is_bootp = 1;
2398 lease -> medium = client -> medium;
2401 stop_selecting = (client -> first_sending +
2402 client -> config -> select_interval);
2406 if (lease -> address.len == client -> requested_address.len &&
2407 !memcmp (lease -> address.iabuf,
2408 client -> requested_address.iabuf,
2409 client -> requested_address.len)) {
2410 lease -> next = client -> offered_leases;
2411 client -> offered_leases = lease;
2415 if (!client -> offered_leases)
2416 client -> offered_leases = lease;
2418 for (lp = client -> offered_leases; lp ->
next;
2428 if (stop_selecting <=
cur_tv.tv_sec)
2431 tv.tv_sec = stop_selecting;
2432 tv.tv_usec =
cur_tv.tv_usec;
2443 struct packet *packet;
2455 log_error(
"packet_to_lease: no memory to record lease.\n");
2459 memset(lease, 0,
sizeof(*lease));
2464 lease->address.len =
sizeof(packet->
raw->
yiaddr);
2465 memcpy(lease->address.iabuf, &packet->
raw->
yiaddr,
2466 lease->address.len);
2468 lease->next_srv_addr.len =
sizeof(packet->
raw->
siaddr);
2469 memcpy(lease->next_srv_addr.iabuf, &packet->
raw->
siaddr,
2470 lease->next_srv_addr.len);
2472 memset(&data, 0,
sizeof(data));
2474 if (client -> config -> vendor_space_name) {
2480 client -> config -> vendor_space_name &&
2482 (
struct lease *)0, client,
2486 if (!option_code_hash_lookup(&option,
2490 "option (%s:%d).",
MDL);
2494 client -> config -> vendor_space_name
2520 if (!(i & 2) && packet -> raw -> sname [0]) {
2524 if (!packet -> raw -> sname [len])
2528 log_error (
"dhcpoffer: no memory for server name.\n");
2533 packet -> raw -> sname, len);
2539 if (!(i & 1) && packet -> raw ->
file [0]) {
2543 if (!packet -> raw ->
file [len])
2547 log_error (
"dhcpoffer: no memory for filename.\n");
2552 packet -> raw ->
file, len);
2558 client, lease->options, lease->options,
2566 struct packet *packet;
2572 for (client = ip -> client; client; client = client ->
next)
2573 if (client ->
xid == packet -> raw ->
xid)
2579 (packet ->
interface -> hw_address.hlen - 1 !=
2580 packet -> raw -> hlen) ||
2581 (memcmp (&packet ->
interface -> hw_address.hbuf [1],
2582 packet -> raw -> chaddr, packet -> raw -> hlen))) {
2584 log_debug (
"DHCPNAK in wrong transaction.");
2599 log_info (
"DHCPNAK from %s (xid=0x%x)",
piaddr (packet -> client_addr), ntohl(client ->
xid));
2603 log_info (
"DHCPNAK with no active lease.\n");
2636 client -> state =
S_INIT;
2655 interval =
cur_time - client -> first_sending;
2659 if (interval > client -> config ->
timeout) {
2667 if (!client -> offered_leases &&
2668 client -> config -> media) {
2671 if (client -> medium) {
2672 client -> medium = client -> medium -> next;
2675 if (!client -> medium) {
2677 log_fatal (
"No valid media types for %s!",
2678 client -> interface -> name);
2680 client -> config -> media;
2684 log_info (
"Trying medium \"%s\" %d",
2685 client -> medium ->
string, increase);
2713 if (
cur_time + client -> interval >
2714 client -> first_sending + client -> config ->
timeout)
2715 client -> interval =
2716 (client -> first_sending +
2720 if (interval < 65536)
2721 client -> packet.secs = htons (interval);
2723 client -> packet.secs = htons (65535);
2724 client -> secs = client -> packet.secs;
2726 #if defined(DHCPv6) && defined(DHCP4o6) 2728 log_info (
"DHCPDISCOVER interval %ld",
2729 (
long)(client -> interval));
2732 log_info (
"DHCPDISCOVER on %s to %s port %d interval %ld (xid=0x%x)",
2733 client -> name ? client -> name : client -> interface -> name,
2735 ntohs (
sockaddr_broadcast.sin_port), (
long)(client -> interval), ntohl(client -> xid));
2738 #if defined(DHCPv6) && defined(DHCP4o6) 2740 result = send_dhcpv4_query(client, 1);
2747 #if defined(DHCPv6) && defined(DHCP4o6) 2749 log_error(
"%s:%d: Failed to send %d byte long packet.",
2753 log_error(
"%s:%d: Failed to send %d byte long packet over %s " 2765 tv.tv_usec = client->
interval > 1 ? random() % 1000000 :
cur_tv.tv_usec;
2782 loop = lp = client -> active;
2784 log_info (
"No DHCPOFFERS received.");
2788 if (!client -> active && client -> leases)
2792 while (client -> active) {
2793 if (client -> active -> expiry >
cur_time) {
2794 log_info (
"Trying recorded lease %s",
2795 piaddr (client -> active -> address));
2799 client -> active -> medium);
2802 if (client -> alias)
2810 if (cur_time < client -> active -> renewal) {
2812 log_info (
"bound: renewal in %ld %s.",
2813 (
long)(client -> active -> renewal -
2818 random() % 1000000 :
2823 log_info (
"bound: immediate renewal.");
2833 if (!client -> leases) {
2834 client -> leases = client -> active;
2842 for (lp = client -> leases; lp ->
next; lp = lp ->
next)
2844 lp ->
next = client -> active;
2848 client -> active = client -> leases;
2849 client -> leases = client -> leases ->
next;
2854 if (client -> active == loop)
2857 loop = client -> active;
2865 log_info (
"Unable to obtain a lease on first try.%s",
2870 log_info (
"No working leases in persistent database - sleeping.");
2872 if (client -> alias)
2875 client -> state =
S_INIT;
2878 tv.tv_usec = ((tv.tv_sec -
cur_tv.tv_sec) > 1) ?
2879 random() % 1000000 :
cur_tv.tv_usec;
2891 struct sockaddr_in destination;
2892 struct in_addr from;
2896 interval =
cur_time - client -> first_sending;
2910 interval > client -> config -> reboot_timeout) {
2912 client -> state =
S_INIT;
2921 !client -> medium &&
2922 client -> active -> medium ) {
2923 script_init (client,
"MEDIUM", client -> active -> medium);
2930 client -> medium = client -> active -> medium;
2936 cur_time > client -> active -> expiry) {
2941 if (client -> alias)
2949 if (client -> alias)
2954 client -> state =
S_INIT;
2960 if (!client -> interval)
2961 client -> interval = client -> config -> initial_interval;
2963 client -> interval += ((random () >> 2) %
2964 (2 * client -> interval));
2968 if (client -> interval >
2969 client -> config -> backoff_cutoff)
2970 client -> interval =
2971 ((client -> config -> backoff_cutoff / 2)
2972 + ((random () >> 2) %
2973 client -> config -> backoff_cutoff));
2978 cur_time + client -> interval > client -> active -> expiry)
2979 client -> interval =
2980 client -> active -> expiry -
cur_time + 1;
2986 cur_time > client -> active -> rebind)
2989 memcpy (&destination.sin_addr.s_addr,
2990 client -> destination.iabuf,
2991 sizeof destination.sin_addr.s_addr);
2993 destination.sin_family = AF_INET;
2995 destination.sin_len =
sizeof destination;
3000 memcpy (&from, client -> active -> address.iabuf,
3003 from.s_addr = INADDR_ANY;
3007 client -> packet.secs = client -> secs;
3009 if (interval < 65536)
3010 client -> packet.secs = htons (interval);
3012 client -> packet.secs = htons (65535);
3015 #if defined(DHCPv6) && defined(DHCP4o6) 3020 log_info (
"DHCPREQUEST on %s to %s port %d (xid=0x%x)",
3021 client -> name ? client -> name : client -> interface -> name,
3022 inet_ntoa (destination.sin_addr),
3023 ntohs (destination.sin_port), ntohl(client -> xid));
3025 #if defined(DHCPv6) && defined(DHCP4o6) 3028 if (destination.sin_addr.s_addr == INADDR_BROADCAST)
3030 result = send_dhcpv4_query(client, broadcast);
3032 log_error(
"%s:%d: Failed to send %d byte long packet.",
3037 if (destination.sin_addr.s_addr != INADDR_BROADCAST &&
3039 #if defined(SO_BINDTODEVICE) 3043 log_error(
"%s:%d: Failed to bind fallback interface" 3051 log_error(
"%s:%d: Failed to send %d byte long packet " 3052 "over %s interface.",
MDL,
3056 #if defined(SO_BINDTODEVICE) 3058 SO_BINDTODEVICE, NULL, 0) < 0) {
3059 log_fatal(
"%s:%d: Failed to unbind fallback interface:" 3070 log_error(
"%s:%d: Failed to send %d byte long packet" 3071 " over %s interface.",
MDL,
3078 tv.tv_usec = ((tv.tv_sec -
cur_tv.tv_sec) > 1) ?
3079 random() % 1000000 :
cur_tv.tv_usec;
3090 #if defined(DHCPv6) && defined(DHCP4o6) 3095 log_info (
"DHCPDECLINE on %s to %s port %d (xid=0x%x)",
3101 #if defined(DHCPv6) && defined(DHCP4o6) 3103 result = send_dhcpv4_query(client, 1);
3110 #if defined(DHCPv6) && defined(DHCP4o6) 3112 log_error(
"%s:%d: Failed to send %d byte long packet.",
3116 log_error(
"%s:%d: Failed to send %d byte long packet over %s" 3128 struct sockaddr_in destination;
3129 struct in_addr from;
3131 memcpy (&from, client -> active -> address.iabuf,
3133 memcpy (&destination.sin_addr.s_addr,
3134 client -> destination.iabuf,
3135 sizeof destination.sin_addr.s_addr);
3137 destination.sin_family = AF_INET;
3139 destination.sin_len =
sizeof destination;
3144 client -> active -> expiry =
3145 client -> active -> renewal =
3146 client -> active -> rebind =
cur_time;
3148 log_error (
"Can't release lease: lease write failed.");
3152 #if defined(DHCPv6) && defined(DHCP4o6) 3157 log_info (
"DHCPRELEASE on %s to %s port %d (xid=0x%x)",
3158 client -> name ? client -> name : client -> interface -> name,
3159 inet_ntoa (destination.sin_addr),
3160 ntohs (destination.sin_port), ntohl(client -> xid));
3162 #if defined(DHCPv6) && defined(DHCP4o6) 3165 if (destination.sin_addr.s_addr == INADDR_BROADCAST)
3167 result = send_dhcpv4_query(client, broadcast);
3169 log_error(
"%s:%d: Failed to send %d byte long packet.",
3175 #if defined(SO_BINDTODEVICE) 3179 log_error(
"%s:%d: Failed to bind fallback interface" 3187 log_error(
"%s:%d: Failed to send %d byte long packet" 3188 " over %s interface.",
MDL,
3192 #if defined(SO_BINDTODEVICE) 3194 SO_BINDTODEVICE, NULL, 0) < 0) {
3195 log_fatal(
"%s:%d: Failed to unbind fallback interface:" 3205 log_error (
"%s:%d: Failed to send %d byte long packet" 3206 " over %s interface.",
MDL,
3214 #if defined(DHCPv6) && defined(DHCP4o6) 3226 static int send_dhcpv4_query(
struct client_state *client,
int broadcast) {
3231 if (dhcp4o6_state <= 0) {
3232 log_info(
"send_dhcpv4_query: not ready.");
3242 memset(&ds, 0,
sizeof(ds));
3244 log_error(
"Unable to allocate memory for DHCPv4-query.");
3272 cc = send(dhcp4o6_fd, ds.
data, ds.
len, 0);
3274 log_error(
"send_dhcpv4_query: send(): %m");
3287 static void forw_dhcpv4_query(
struct data_string *raw) {
3293 struct sockaddr_in6 sin6;
3294 int i, send_ret, attempt, success;
3296 attempt = success = 0;
3297 memset(&sin6, 0,
sizeof(sin6));
3298 sin6.sin6_family = AF_INET6;
3301 sin6.sin6_len =
sizeof(sin6);
3303 memset(&addrs, 0,
sizeof(addrs));
3305 for (client = ip->
client; client != NULL;
3306 client = client->
next) {
3312 if ((lease == NULL) || lease->
released)
3321 ((addrs.
len %
sizeof(sin6.sin6_addr)) != 0)) {
3325 if (addrs.
len == 0) {
3333 if (send_ret == raw->
len)
3337 for (i = 0; i < addrs.
len;
3338 i +=
sizeof(sin6.sin6_addr)) {
3339 memcpy(&sin6.sin6_addr, addrs.
data + i,
3340 sizeof(sin6.sin6_addr));
3344 if (send_ret == raw->
len)
3351 log_info(
"forw_dhcpv4_query: sent(%d): %d/%d",
3352 raw->
len, success, attempt);
3368 struct buffer *bp = NULL;
3391 log_error (
"can't make requested address cache.");
3417 for (i = 0 ; prl[i] != NULL ; i++)
3422 log_error(
"can't make parameter list buffer.");
3427 for (i = 0 ; prl[i] != NULL ; i++)
3431 if (!(option_code_hash_lookup(&option,
3456 memset(&client_identifier, 0,
sizeof(client_identifier));
3459 client_identifier.
len,
MDL))
3460 log_fatal(
"no memory for default DUID!");
3478 memcpy(&client_identifier.
buffer->
data + 5 - hw_len,
3483 memcpy(&client_identifier.
buffer->
data+(1+4),
3490 (u_int8_t *)client_identifier.
data,
3491 client_identifier.
len,
3493 log_error (
"can't make requested client id cache..");
3504 (lease ? lease->
options : NULL),
3517 memset (&client -> packet, 0,
sizeof (client -> packet));
3521 lease ? &lease -> address : (
struct iaddr *)0,
3522 client -> config -> requested_options,
3526 client -> packet_length =
3528 (
struct lease *)0, client,
3537 client -> config -> vendor_space_name);
3544 client -> packet.htype = client ->
interface -> hw_address.hbuf [0];
3546 client -> packet.hlen = client ->
interface -> hw_address.hlen - 1;
3547 client -> packet.hops = 0;
3548 client -> packet.xid = random ();
3549 client -> packet.secs = 0;
3553 client -> packet.flags = 0;
3557 memset (&(client -> packet.ciaddr),
3558 0,
sizeof client -> packet.ciaddr);
3559 memset (&(client -> packet.yiaddr),
3560 0,
sizeof client -> packet.yiaddr);
3561 memset (&(client -> packet.siaddr),
3562 0,
sizeof client -> packet.siaddr);
3563 client -> packet.giaddr =
giaddr;
3564 if (client -> interface -> hw_address.hlen > 0)
3565 memcpy (client -> packet.chaddr,
3566 &client -> interface -> hw_address.hbuf [1],
3567 (
unsigned)(client -> interface -> hw_address.hlen - 1));
3570 dump_raw ((
unsigned char *)&client -> packet, client -> packet_length);
3582 memset (&client -> packet, 0,
sizeof (client -> packet));
3590 if (client -> sent_options)
3597 : (
struct iaddr *)0),
3598 client -> config -> requested_options,
3599 &client -> sent_options);
3602 client -> packet_length =
3604 (
struct lease *)0, client,
3607 client -> sent_options,
3613 client -> config -> vendor_space_name);
3619 client -> packet.htype = client ->
interface -> hw_address.hbuf [0];
3621 client -> packet.hlen = client ->
interface -> hw_address.hlen - 1;
3622 client -> packet.hops = 0;
3623 client -> packet.xid = client -> xid;
3624 client -> packet.secs = 0;
3628 if (client -> state ==
S_BOUND ||
3631 memcpy (&client -> packet.ciaddr,
3632 lease -> address.iabuf, lease -> address.len);
3633 client -> packet.flags = 0;
3635 memset (&client -> packet.ciaddr, 0,
3636 sizeof client -> packet.ciaddr);
3638 client ->config->bootp_broadcast_always)) &&
3640 client -> packet.flags = 0;
3645 memset (&client -> packet.yiaddr, 0,
3646 sizeof client -> packet.yiaddr);
3647 memset (&client -> packet.siaddr, 0,
3648 sizeof client -> packet.siaddr);
3649 if (client -> state !=
S_BOUND &&
3651 client -> packet.giaddr =
giaddr;
3653 memset (&client -> packet.giaddr, 0,
3654 sizeof client -> packet.giaddr);
3655 if (client -> interface -> hw_address.hlen > 0)
3656 memcpy (client -> packet.chaddr,
3657 &client -> interface -> hw_address.hbuf [1],
3658 (
unsigned)(client -> interface -> hw_address.hlen - 1));
3661 dump_raw ((
unsigned char *)&client -> packet, client -> packet_length);
3681 memset (&client -> packet, 0,
sizeof (client -> packet));
3682 client -> packet_length =
3684 (
struct lease *)0, client, 0,
3687 client -> config -> vendor_space_name);
3696 client -> packet.htype = client ->
interface -> hw_address.hbuf [0];
3698 client -> packet.hlen = client ->
interface -> hw_address.hlen - 1;
3699 client -> packet.hops = 0;
3700 client -> packet.xid = client -> xid;
3701 client -> packet.secs = 0;
3704 client -> packet.flags = 0;
3709 memset (&client -> packet.ciaddr, 0,
3710 sizeof client -> packet.ciaddr);
3711 memset (&client -> packet.yiaddr, 0,
3712 sizeof client -> packet.yiaddr);
3713 memset (&client -> packet.siaddr, 0,
3714 sizeof client -> packet.siaddr);
3715 client -> packet.giaddr =
giaddr;
3716 memcpy (client -> packet.chaddr,
3717 &client -> interface -> hw_address.hbuf [1],
3718 client -> interface -> hw_address.hlen);
3721 dump_raw ((
unsigned char *)&client -> packet, client -> packet_length);
3734 memset (&client -> packet, 0,
sizeof (client -> packet));
3741 client -> packet_length =
3743 (
struct lease *)0, client,
3752 client -> config -> vendor_space_name);
3759 client -> packet.htype = client ->
interface -> hw_address.hbuf [0];
3761 client -> packet.hlen = client ->
interface -> hw_address.hlen - 1;
3762 client -> packet.hops = 0;
3763 client -> packet.xid = random ();
3764 client -> packet.secs = 0;
3765 client -> packet.flags = 0;
3766 memcpy (&client -> packet.ciaddr,
3767 lease -> address.iabuf, lease -> address.len);
3768 memset (&client -> packet.yiaddr, 0,
3769 sizeof client -> packet.yiaddr);
3770 memset (&client -> packet.siaddr, 0,
3771 sizeof client -> packet.siaddr);
3772 client -> packet.giaddr =
giaddr;
3773 memcpy (client -> packet.chaddr,
3774 &client -> interface -> hw_address.hbuf [1],
3775 client -> interface -> hw_address.hlen);
3778 dump_raw ((
unsigned char *)&client -> packet, client -> packet_length);
3802 if (leaseFile != NULL)
3805 if (leaseFile == NULL) {
3817 for (client = ip -> client; client; client = client ->
next) {
3818 for (lp = client -> leases; lp; lp = lp ->
next) {
3821 if (client -> active)
3823 client -> active, 1, 0);
3838 for (client = ip -> client; client; client = client ->
next) {
3839 for (lp = client -> leases; lp; lp = lp ->
next) {
3842 if (client -> active)
3844 client -> active, 1, 0);
3859 struct packet *packet,
struct lease *lease,
3866 const char *name, *dot;
3868 char *preamble = stuff;
3870 memset (&ds, 0,
sizeof ds);
3880 in_options, cfg_options, scope, oc,
MDL)) {
3882 fprintf(leaseFile,
"%soption %s%s%s", preamble,
3888 fprintf(leaseFile,
" %s",
3894 fprintf(leaseFile,
";\n");
3903 const char *preamble)
3916 if (c >=
'0' && c <=
'9')
3919 if (c >=
'a' && c <=
'f')
3920 return c -
'a' + 10;
3922 if (c >=
'A' && c <=
'F')
3923 return c -
'A' + 10;
3930 const char *id_fname =
"/etc/machine-id";
3933 FILE *
file = fopen( id_fname ,
"r");
3936 return ISC_R_IOERROR;
3938 nread = fread(
id, 1,
sizeof id, file);
3942 log_debug(
"Not enough data in %s", id_fname);
3943 return ISC_R_IOERROR;
3946 for (
int j = 0; j < 16; j++) {
3952 if (a < 0 || b < 0) {
3953 log_debug(
"Wrong data in %s", id_fname);
3954 return ISC_R_IOERROR;
3956 uuid[j] = a << 4 | b;
3960 uuid[6] = (uuid[6] & 0x0F) | 0x40;
3962 uuid[8] = (uuid[8] & 0x3F) | 0x80;
3964 return ISC_R_SUCCESS;
3997 log_debug(
"Cannot form default DUID from interface %s.", ip->
name);
4001 return ISC_R_UNEXPECTED;
4006 log_fatal(
"Impossible hardware address length at %s:%d.",
MDL);
4016 len = 2 +
sizeof (uuid);
4030 log_fatal(
"no memory for default DUID!");
4036 memcpy(duid->
buffer->
data + 2, uuid,
sizeof(uuid));
4056 log_info(
"form_duid: Couldn't allocate memory to log duid!");
4062 return ISC_R_SUCCESS;
4072 if ((duid == NULL) || (duid->
len <= 2))
4075 if (leaseFile == NULL) {
4077 if (leaseFile == NULL) {
4079 return ISC_R_IOERROR;
4087 return ISC_R_NOMEMORY;
4089 stat = fprintf(leaseFile,
"default-duid %s;\n", str);
4092 return ISC_R_IOERROR;
4094 if (fflush(leaseFile) != 0)
4095 return ISC_R_IOERROR;
4097 return ISC_R_SUCCESS;
4103 int rewrite,
int sync)
4111 if (!rewrite && (leases_written++ > 20)) {
4114 return ISC_R_SUCCESS;
4117 if (client == NULL || lease == NULL)
4120 if (leaseFile == NULL) {
4122 if (leaseFile == NULL) {
4124 return ISC_R_IOERROR;
4128 stat = fprintf(leaseFile,
"lease6 {\n");
4130 return ISC_R_IOERROR;
4132 stat = fprintf(leaseFile,
" interface \"%s\";\n",
4135 return ISC_R_IOERROR;
4137 for (ia = lease->
bindings ; ia != NULL ; ia = ia->
next) {
4158 (
const unsigned char *) &ia->
iaid, 4,
4163 return ISC_R_IOERROR;
4166 stat = fprintf(leaseFile,
" %s %s {\n",
4174 stat = fprintf(leaseFile,
" %s %s {\n", ianame,
4180 return ISC_R_IOERROR;
4183 stat = fprintf(leaseFile,
" starts %d;\n" 4188 stat = fprintf(leaseFile,
" starts %d;\n",
4191 return ISC_R_IOERROR;
4193 for (addr = ia->
addrs ; addr != NULL ; addr = addr->
next) {
4195 stat = fprintf(leaseFile,
4199 stat = fprintf(leaseFile,
4200 " iaprefix %s/%d {\n",
4204 return ISC_R_IOERROR;
4206 stat = fprintf(leaseFile,
" starts %d;\n" 4207 " preferred-life %u;\n" 4212 return ISC_R_IOERROR;
4215 write_options(client, addr->
options,
" ");
4217 stat = fprintf(leaseFile,
" }\n");
4219 return ISC_R_IOERROR;
4223 write_options(client, ia->
options,
" ");
4225 stat = fprintf(leaseFile,
" }\n");
4227 return ISC_R_IOERROR;
4231 stat = fprintf(leaseFile,
" released;\n");
4233 return ISC_R_IOERROR;
4237 write_options(client, lease->
options,
" ");
4239 stat = fprintf(leaseFile,
"}\n");
4241 return ISC_R_IOERROR;
4243 if (fflush(leaseFile) != 0)
4244 return ISC_R_IOERROR;
4247 if (fsync(fileno(leaseFile)) < 0) {
4248 log_error(
"write_client_lease: fsync(): %m");
4249 return ISC_R_IOERROR;
4253 return ISC_R_SUCCESS;
4268 if (leases_written++ > 20) {
4276 if (lease -> is_static)
4279 if (leaseFile == NULL) {
4281 if (leaseFile == NULL) {
4288 fprintf (leaseFile,
"lease {\n");
4289 if (lease -> is_bootp) {
4290 fprintf (leaseFile,
" bootp;\n");
4296 fprintf (leaseFile,
" interface \"%s\";\n",
4297 client -> interface -> name);
4302 if (client -> name) {
4303 fprintf (leaseFile,
" name \"%s\";\n", client -> name);
4309 fprintf (leaseFile,
" fixed-address %s;\n",
4310 piaddr (lease -> address));
4315 if (lease -> filename) {
4318 fprintf (leaseFile,
" filename \"%s\";\n", s);
4331 fprintf(leaseFile,
" server-name \"%s\";\n", s);
4340 if (lease -> medium) {
4343 fprintf (leaseFile,
" medium \"%s\";\n", s);
4357 memset (&ds, 0,
sizeof ds);
4359 write_options(client, lease->
options,
" ");
4363 fprintf(leaseFile,
" renew %s\n", tval) < 0)
4368 fprintf(leaseFile,
" rebind %s\n", tval) < 0)
4373 fprintf(leaseFile,
" expire %s\n", tval) < 0)
4376 if (fprintf(leaseFile,
"}\n") < 0)
4379 if (fflush(leaseFile) != 0)
4384 if (!errors && makesure) {
4385 if (fsync (fileno (leaseFile)) < 0) {
4386 log_info (
"write_client_lease: %m");
4391 return errors ? 0 : 1;
4408 for (sl = client -> env; sl; sl =
next) {
4415 if (client -> interface) {
4417 client -> interface -> name);
4421 "",
"client",
"%s", client -> name);
4424 "",
"medium",
"%s", medium ->
string);
4427 client_envadd (client,
"",
"pid",
"%ld", (
long int)getpid ());
4432 struct packet *packet,
struct lease *lease,
4441 memset (&data, 0,
sizeof data);
4444 in_options, cfg_options, scope, oc,
MDL)) {
4454 length = strlen(value);
4458 value, length) == 0) {
4463 "option - discarded",
4486 prefix,
"ip_address",
"%s",
piaddr (lease -> address));
4502 memset (&data, 0,
sizeof data);
4505 (
struct lease *)0, client,
4510 struct iaddr netmask, subnet, broadcast;
4533 (&data, (
struct packet *)0,
4534 (
struct lease *)0, client,
4539 if (broadcast.
len) {
4541 prefix,
"broadcast_address",
4542 "%s",
piaddr (broadcast));
4558 "option - discarded",
4571 "option - discarded",
4583 client_envadd (client, prefix,
"expiry",
"%d", (
int)(lease -> expiry));
4603 for (i = 0 ; req[i] != NULL ; i++) {
4617 char reason [] =
"REASON=NBI";
4618 static char client_path [] = CLIENT_PATH;
4621 int pid, wpid, wstatus;
4624 scriptName = client -> config -> script_name;
4628 envp =
dmalloc (((client ? client -> envc : 2) +
4631 log_error (
"No memory for client script environment.");
4637 for (sp = client_env; sp; sp = sp ->
next) {
4638 envp [i++] = sp ->
string;
4642 for (sp = client -> env; sp; sp = sp ->
next) {
4643 envp [i++] = sp ->
string;
4646 envp [i++] = reason;
4649 envp [i++] = client_path;
4650 envp [i] = (
char *)0;
4653 argv [1] = (
char *)0;
4661 wpid = wait (&wstatus);
4662 }
while (wpid != pid && wpid > 0);
4671 if (leaseFile != NULL)
4673 execve (scriptName, argv, envp);
4674 log_error (
"execve (%s, ...): %m", scriptName);
4679 for (sp = client -> env; sp; sp =
next) {
4687 gettimeofday(&
cur_tv, NULL);
4688 return (WIFEXITED (wstatus) ?
4689 WEXITSTATUS (wstatus) : -WTERMSIG (wstatus));
4693 const char *prefix,
const char *name,
const char *fmt, ...)
4701 va_start (list, fmt);
4702 len = vsnprintf (spbuf,
sizeof spbuf, fmt, list);
4705 val =
dmalloc (strlen (prefix) + strlen (name) + 1 +
4706 len +
sizeof *val,
MDL);
4714 if (len >=
sizeof spbuf) {
4715 va_start (list, fmt);
4716 vsnprintf (s, len + 1, fmt, list);
4720 val ->
next = client -> env;
4721 client -> env = val;
4744 if (j + 1 == buflen)
4754 if (j + 1 == buflen)
4767 static int state = 0;
4785 if ((pid = fork ()) < 0)
4798 (void) open(
"/dev/null", O_RDWR | O_CLOEXEC);
4799 (void) open(
"/dev/null", O_RDWR | O_CLOEXEC);
4800 (void) open(
"/dev/null", O_RDWR | O_CLOEXEC);
4817 pfdesc = open (
path_dhclient_pid, O_CREAT | O_TRUNC | O_WRONLY | O_CLOEXEC, 0644);
4824 pf = fdopen (pfdesc,
"we");
4829 fprintf (pf,
"%ld\n", (
long)getpid ());
4840 for (client = ip -> client; client; client = client ->
next) {
4841 switch (client ->
state) {
4874 #if defined(DHCPv6) && defined(DHCP4o6) 4876 if (dhcp4o6_state < 0)
4884 client -> xid = random ();
4887 if (client -> active) {
4892 memset (&ds, 0,
sizeof ds);
4894 client -> active -> options,
4898 (
struct lease *)0, client,
4900 client -> active -> options,
4903 memcpy (client -> destination.iabuf,
4905 client -> destination.len = 4;
4912 client -> first_sending =
cur_time;
4913 client -> interval = client -> config -> initial_interval;
4924 if (client -> alias)
4940 #if defined(DHCPv6) && defined(DHCP4o6) 4959 if (!strcmp (ip ->
name, tmp ->
name)) {
4963 interface_reference (&ip, last ->
next,
MDL);
4964 interface_dereference (&last ->
next,
MDL);
4966 interface_reference (&last ->
next,
4968 interface_dereference (&ip ->
next,
4973 interface_reference (&ip,
4979 interface_dereference (&ip ->
next,
4985 tmp -> client = ip ->
client;
4986 tmp -> client ->
interface = tmp;
4988 interface_dereference (&ip,
MDL);
5023 if (ip -> client ->
alias)
5025 ip -> client ->
alias);
5037 for (client = ip->
client ; client ; client = client->
next) {
5042 return ISC_R_SUCCESS;
5049 struct packet *packet;
5068 static void shutdown_exit (
void *foo)
5076 #if defined (NSUPDATE) 5093 isc_result_t eresult)
5096 isc_result_t result;
5098 if ((eresult == ISC_R_SUCCESS) &&
5104 if (result == ISC_R_SUCCESS) {
5110 dhclient_ddns_cb_free(ddns_cb,
MDL);
5119 isc_result_t result;
5122 if (client->
ddns_cb != NULL) {
5128 if (ddns_cb != NULL) {
5134 ddns_cb->
cur_func = client_dns_remove_action;
5138 if (result != ISC_R_TIMEDOUT) {
5139 dhclient_ddns_cb_free(ddns_cb,
MDL);
5155 return ISC_R_SUCCESS;
5159 log_info(
"Received signal %d, initiating shutdown.",
5168 for (client = ip -> client; client; client = client -> next) {
5171 return ISC_R_SUCCESS;
5174 return ISC_R_SUCCESS;
5177 if (client -> active &&
5178 client -> active -> expiry >
cur_time) {
5179 #if defined (NSUPDATE) 5201 tv.tv_sec =
cur_tv.tv_sec;
5202 tv.tv_usec =
cur_tv.tv_usec + 1;
5205 return ISC_R_SUCCESS;
5208 #if defined (NSUPDATE) 5219 isc_result_t status = ISC_R_FAILURE;
5221 if ((client != NULL) &&
5222 ((client->
active != NULL) ||
5235 if (status != ISC_R_TIMEDOUT) {
5236 dhclient_ddns_cb_free(ddns_cb,
MDL);
5271 isc_result_t eresult)
5273 isc_result_t result;
5290 ddns_cb->
cur_func = client_dns_update_action;
5293 if (result == ISC_R_SUCCESS) {
5299 case ISC_R_TIMEDOUT:
5307 if (ddns_cb->
zone != NULL) {
5313 ddns_cb->
cur_func = client_dns_update_action;
5319 tv.tv_usec =
cur_tv.tv_usec;
5321 ddns_cb, NULL, NULL);
5325 dhclient_ddns_cb_free(ddns_cb,
MDL);
5343 if (!client -> sent_options)
5344 return ISC_R_SUCCESS;
5348 return ISC_R_SUCCESS;
5354 (
struct lease *)0, client,
5355 client -> sent_options,
5358 return ISC_R_SUCCESS;
5365 (
struct lease *)0, client,
5366 client -> sent_options,
5369 return ISC_R_SUCCESS;
5375 (
struct lease *)0, client,
5376 client -> sent_options,
5379 return ISC_R_SUCCESS;
5391 memset(&client_identifier, 0,
sizeof(client_identifier));
5415 client_identifier.
data,
5416 client_identifier.
len);
5434 (client_identifier.
data[0] == 255)) {
5439 if (client_identifier.
len <= 5)
5440 log_fatal(
"Impossible condition at %s:%d.",
5443 client_identifier.
data + 5,
5444 client_identifier.
len - 5);
5446 result =
get_dhcid(ddns_cb, ddns_v4_type,
5447 client_identifier.
data,
5448 client_identifier.
len);
5458 return ISC_R_SUCCESS;
5467 rcode = ISC_R_FAILURE;
5473 if (rcode == ISC_R_SUCCESS) {
5474 rcode = ISC_R_TIMEDOUT;
5497 if (client->
ddns_cb != NULL) {
5504 if (ddns_cb != NULL) {
5505 ddns_cb->
lease = (
void *)client;
5518 ddns_cb->
cur_func = client_dns_update_action;
5522 tv.tv_sec =
cur_tv.tv_sec + offset;
5523 tv.tv_usec =
cur_tv.tv_usec;
5525 ddns_cb, NULL, NULL);
5527 log_error(
"Unable to allocate dns update state for %s",
5536 struct servent *ent;
5550 ent = getservbyname(
"dhcpc",
"udp");
5552 ent = getservbyname(
"bootpc",
"udp");
5557 #ifndef __CYGWIN32__ 5581 static int check_domain_name(
const char *ptr,
size_t len,
int dots)
5586 if ((len == 0) || (len > 256))
5591 for (p=ptr; (*p != 0) && (len-- > 0); p++) {
5592 if ((*p ==
'-') || (*p ==
'_')) {
5594 if (((p - ptr) == 0) || (len == 0) || (p[1] ==
'.'))
5596 }
else if (*p ==
'.') {
5600 if ((d <= 0) || (d >= 64))
5603 if ((dots > 0) && (len > 0))
5605 }
else if (isalnum((
unsigned char)*p) == 0) {
5610 return(dots ? -1 : 0);
5613 static int check_domain_name_list(
const char *ptr,
size_t len,
int dots)
5618 if ((ptr == NULL) || (len == 0))
5621 for (p=ptr; (*p != 0) && (len > 0); p++, len--) {
5625 if (check_domain_name(ptr, p - ptr, dots) != 0)
5632 return(check_domain_name(ptr, p - ptr, dots));
5649 #ifdef ACCEPT_LIST_IN_DOMAIN_NAME 5650 return check_domain_name_list(ptr, len, 0);
5652 return check_domain_name(ptr, len, 0);
5657 return check_domain_name(ptr, len, 0);
5660 return check_domain_name_list(ptr, len, 0);
5665 for (; (*ptr != 0) && (len-- > 0); ptr++) {
5666 if(!(isalnum((
unsigned char)*ptr) ||
5667 *ptr ==
'#' || *ptr ==
'%' ||
5668 *ptr ==
'+' || *ptr ==
'-' ||
5669 *ptr ==
'_' || *ptr ==
':' ||
5670 *ptr ==
'.' || *ptr ==
',' ||
5671 *ptr ==
'@' || *ptr ==
'~' ||
5672 *ptr ==
'\\' || *ptr ==
'/' ||
5673 *ptr ==
'[' || *ptr ==
']' ||
5674 *ptr ==
'=' || *ptr ==
' '))
5689 return check_domain_name_list(ptr, len, 0);
5699 add_reject(
struct packet *packet) {
5704 log_fatal (
"no memory for reject list!");
5723 log_info(
"Server added to list of rejected servers.");
5732 if (client != NULL) {
5740 #if defined(DHCPv6) && defined(DHCP4o6) 5759 char start_msg[5] = {
'S',
'T',
'A',
'R',
'T' };
5760 char stop_msg[4] = {
'S',
'T',
'O',
'P' };
5761 char poll_msg[4] = {
'P',
'O',
'L',
'L' };
5765 if (h->type != dhcp4o6_type)
5768 cc = recv(dhcp4o6_fd, buf,
sizeof(buf), 0);
5770 return ISC_R_UNEXPECTED;
5774 (memcmp(buf, poll_msg,
sizeof(poll_msg)) == 0)) {
5776 if (dhcp4o6_state < 0)
5777 cc = send(dhcp4o6_fd, stop_msg,
5778 sizeof(stop_msg), 0);
5780 cc = send(dhcp4o6_fd, start_msg,
5781 sizeof(start_msg), 0);
5783 log_error(
"dhcpv4o6_handler: send(): %m");
5784 return ISC_R_IOERROR;
5788 return ISC_R_UNEXPECTED;
5789 memset(&raw, 0,
sizeof(raw));
5792 "no memory buffer.");
5793 return ISC_R_NOMEMORY;
5799 forw_dhcpv4_query(&raw);
5805 (memcmp(buf, stop_msg,
sizeof(stop_msg)) == 0)) {
5807 if (dhcp4o6_state > 0) {
5811 }
else if ((cc == 5) &&
5812 (memcmp(buf, start_msg,
sizeof(start_msg)) == 0)) {
5814 if (dhcp4o6_state == 0)
5820 return ISC_R_UNEXPECTED;
5821 memset(&raw, 0,
sizeof(raw));
5824 "no memory buffer.");
5825 return ISC_R_NOMEMORY;
5831 recv_dhcpv4_response(&raw);
5837 return ISC_R_SUCCESS;
5848 static void dhcp4o6_poll(
void *dummy) {
5849 char msg[4] = {
'P',
'O',
'L',
'L' };
5855 if (dhcp4o6_state < 0)
5860 cc = send(dhcp4o6_fd, msg,
sizeof(msg), 0);
5865 tv.tv_usec = random() % 1000000;
5877 static void dhcp4o6_resume() {
5882 for (client = ip->
client; client != NULL;
5883 client = client->
next) {
5906 char msg[5] = {
'S',
'T',
'A',
'R',
'T' };
5909 memset(&addrs, 0,
sizeof(addrs));
5911 for (client = ip->
client; client != NULL;
5912 client = client->
next) {
5918 if ((lease == NULL) || lease->
released)
5928 if ((addrs.
len % 16) != 0) {
5941 if (dhcp4o6_state == 1)
5943 log_info(
"dhcp4o6_start: go to UP");
5946 cc = send(dhcp4o6_fd, msg,
sizeof(msg), 0);
5948 log_info(
"dhcp4o6_start: send(): %m");
5958 static void dhcp4o6_stop() {
5959 char msg[4] = {
'S',
'T',
'O',
'P' };
5962 if (dhcp4o6_state == -1)
5965 log_info(
"dhcp4o6_stop: go to DOWN");
5968 cc = send(dhcp4o6_fd, msg,
sizeof(msg), 0);
void do_packet6(struct interface_info *, const char *, int, int, const struct iaddr *, isc_boolean_t)
void state_selecting(void *cpp)
#define DHCP_FIXED_NON_UDP
#define _PATH_DHCLIENT_CONF
void(* dhcpv6_packet_handler)(struct interface_info *, const char *, int, int, const struct iaddr *, isc_boolean_t)
void send_discover(void *cpp)
void unbill_class(struct lease *lease)
struct client_lease * alias
int parse_encapsulated_suboptions(struct option_state *options, struct option *eopt, const unsigned char *buffer, unsigned len, struct universe *eu, const char *uname)
isc_result_t omapi_protocol_listen(omapi_object_t *, unsigned, int)
struct binding_scope * global_scope
#define _PATH_DHCLIENT_PID
struct universe * universe
void make_client_options(struct client_state *client, struct client_lease *lease, u_int8_t *type, struct option_cache *sid, struct iaddr *rip, struct option **prl, struct option_state **op)
struct group * on_receipt
unsigned char dhcpv6_transaction_id[3]
#define _PATH_DHCLIENT_SCRIPT
void save_option(struct universe *universe, struct option_state *options, struct option_cache *oc)
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 *)
#define All_DHCP_Relay_Agents_and_Servers
void start_release6(struct client_state *client)
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
#define DHCPV6_DHCPV4_QUERY
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
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
enum dhcp_pending pending
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)
#define DHCPV6_DHCPV4_RESPONSE
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)
void(* store_length)(unsigned char *, u_int32_t)
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
isc_result_t read_uuid(u_int8_t *uuid)
ssize_t send_packet6(struct interface_info *, const unsigned char *, size_t, struct sockaddr_in6 *)
int write_lease(struct lease *lease)
void putULong(unsigned char *, u_int32_t)
void run_stateless(int exit_mode, u_int16_t port)
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
u_int16_t validate_port_pair(char *port)
void * dmalloc(size_t, const char *, int)
int parse_options(struct packet *packet)
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 *)
int validate_packet(struct packet *packet)
struct client_config top_level_config
struct iaddr broadcast_addr(struct iaddr subnet, struct iaddr mask)
struct option ** required_options
union executable_statement::@7 data
void state_reboot(void *cpp)
int check_collection(struct packet *packet, struct lease *lease, struct collection *collection)
void destroy_client_lease(struct client_lease *lease)
void db_startup(int testp)
int parse_agent_information_option(struct packet *packet, int len, u_int8_t *data)
#define ASSERT_STATE(state_is, state_shouldbe)
char * path_dhclient_script
void parse_client_statement(struct parse *cfile, struct interface_info *ip, struct client_config *config)
struct universe ** universes
char * format_lease_id(const unsigned char *s, unsigned len, int format, const char *file, int line)
#define DHCP4O6_QUERY_UNICAST
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)
int packet_dereference(struct packet **ptr, const char *file, int line)
int packet_allocate(struct packet **ptr, 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
#define D6O_DHCP4_O_DHCP6_SERVER
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)
unsigned char options[FLEXIBLE_ARRAY_MEMBER]
const unsigned char * data
struct interface_info * interface
#define DHO_DHCP_MESSAGE_TYPE
void dhcp_common_objects_setup(void)
void(* store_tag)(unsigned char *, u_int32_t)
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