36 #include <dns/result.h> 52 extern int asprintf(
char **strp,
const char *fmt, ...);
85 #define ASSERT_STATE(state_is, state_shouldbe) {} 88 static const char copyright[] =
"Copyright 2004-2018 Internet Systems Consortium.";
89 static const char arr [] =
"All rights reserved.";
90 static const char message [] =
"Internet Systems Consortium DHCP Client";
91 static const char url [] =
"For info, please visit https://www.isc.org/software/dhcp/";
96 #if defined(DHCPv6) && defined(DHCP4o6) 97 int dhcp4o6_state = -1;
114 int dad_wait_time = 0;
115 int prefix_len_hint = 0;
129 static isc_result_t write_duid(
struct data_string *duid);
132 static int check_domain_name(
const char *ptr,
size_t len,
int dots);
133 static int check_domain_name_list(
const char *ptr,
size_t len,
int dots);
135 const char *ptr,
size_t len);
156 #if defined(DHCPv6) && defined(DHCP4o6) 157 static void dhcp4o6_poll(
void *dummy);
158 static void dhcp4o6_resume(
void);
159 static void recv_dhcpv4_response(
struct data_string *raw);
160 static int send_dhcpv4_query(
struct client_state *client,
int broadcast);
162 static void dhcp4o6_stop(
void);
163 static void forw_dhcpv4_response(
struct packet *
packet);
164 static void forw_dhcpv4_query(
struct data_string *raw);
171 static const char use_noarg[] =
"No argument for command: %s";
173 static const char use_v6command[] =
"Command not used for DHCPv4: %s";
178 #define DHCLIENT_USAGE0 \ 179 "[-4|-6] [-SNTPRI1dvrxi] [-nw] -4o6 <port>] [-p <port>] [-D LL|LLT]\n" \ 180 " [--dad-wait-time <seconds>] [--prefix-len-hint <length>]\n" \ 181 " [--decline-wait-time <seconds>]\n" \ 182 " [--address-prefix-len <length>]\n" 184 #define DHCLIENT_USAGE0 \ 185 "[-4|-6] [-SNTPRI1dvrxi] [-nw] [-p <port>] [-D LL|LLT]\n" \ 186 " [--dad-wait-time <seconds>] [--prefix-len-hint <length>]\n" \ 187 " [--decline-wait-time <seconds>]\n" \ 188 " [--address-prefix-len <length>]\n" 191 #define DHCLIENT_USAGE0 \ 192 "[-I1dvrxi] [-nw] [-p <port>] [-D LL|LLT] \n" \ 193 " [--decline-wait-time <seconds>]\n" 196 #define DHCLIENT_USAGEC \ 197 " [-s server-addr] [-cf config-file]\n" \ 198 " [-df duid-file] [-lf lease-file]\n" \ 199 " [-pf pid-file] [--no-pid] [-e VAR=val]\n" \ 200 " [-sf script-file] [interface]*\n" \ 201 " [-C <dhcp-client-identifier>] [-B]\n" \ 202 " [-H <host-name> | -F <fqdn.fqdn>] [--timeout <timeout>]\n" \ 203 " [-V <vendor-class-identifier>]\n" \ 204 " [--request-options <request option list>]" 206 #define DHCLIENT_USAGEH "{--version|--help|-h}" 211 usage(
const char *sfmt,
const char *sarg)
219 #ifdef PRINT_SPECIFIC_CL_ERRORS 244 int release_mode = 0;
249 int no_dhclient_conf = 0;
250 int no_dhclient_db = 0;
251 int no_dhclient_pid = 0;
252 int no_dhclient_script = 0;
254 int local_family_set = 0;
256 u_int16_t dhcp4o6_port = 0;
266 char *dhcp_client_identifier_arg = NULL;
267 char *dhcp_host_name_arg = NULL;
268 char *dhcp_fqdn_arg = NULL;
269 char *dhcp_vendor_class_identifier_arg = NULL;
270 char *dhclient_request_options = NULL;
273 char *arg_conf = NULL;
274 int arg_conf_len = 0;
275 #ifdef HAVE_LIBCAP_NG 276 int keep_capabilities = 0;
285 fd = open(
"/dev/null", O_RDWR | O_CLOEXEC);
287 fd = open(
"/dev/null", O_RDWR | O_CLOEXEC);
289 fd = open(
"/dev/null", O_RDWR | O_CLOEXEC);
297 #if !(defined(DEBUG) || defined(__CYGWIN32__)) 298 setlogmask(LOG_UPTO(LOG_INFO));
302 for (i = 1; i < argc; i++) {
303 if (!strcmp(argv[i],
"-r")) {
305 }
else if (!strcmp(argv[i],
"-x")) {
307 }
else if (!strcmp(argv[i],
"-d")) {
309 }
else if (!strcmp(argv[i],
"--version")) {
310 const char vstring[] =
"isc-dhclient-";
318 }
else if (!strcmp(argv[i],
"-C")) {
319 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
320 usage(use_noarg, argv[i-1]);
329 dhcp_client_identifier_arg = argv[i];
330 }
else if (!strcmp(argv[i],
"-B")) {
332 }
else if (!strcmp(argv[i],
"-H")) {
333 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
334 usage(use_noarg, argv[i-1]);
343 if (dhcp_host_name_arg != NULL) {
344 log_error(
"The -H <host-name> and -F <fqdn> arguments are mutually exclusive");
348 dhcp_host_name_arg = argv[i];
349 }
else if (!strcmp(argv[i],
"-F")) {
350 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
351 usage(use_noarg, argv[i-1]);
360 if (dhcp_fqdn_arg != NULL) {
361 log_error(
"Only one -F <fqdn> argument can be specified");
365 if (dhcp_host_name_arg != NULL) {
366 log_error(
"The -F <fqdn> and -H <host-name> arguments are mutually exclusive");
370 dhcp_fqdn_arg = argv[i];
371 }
else if (!strcmp(argv[i],
"--timeout")) {
372 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
373 usage(use_noarg, argv[i-1]);
377 if ((timeout_arg = atoi(argv[i])) <= 0) {
378 log_error(
"timeout option must be > 0 - bad value: %s",argv[i]);
381 }
else if (!strcmp(argv[i],
"-V")) {
382 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
383 usage(use_noarg, argv[i-1]);
392 dhcp_vendor_class_identifier_arg = argv[i];
393 }
else if (!strcmp(argv[i],
"--request-options")) {
394 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
395 usage(use_noarg, argv[i-1]);
399 dhclient_request_options = argv[i];
400 }
else if (!strcmp(argv[i],
"-nc")) {
401 #ifdef HAVE_LIBCAP_NG 402 keep_capabilities = 1;
404 }
else if (!strcmp(argv[i],
"--help") ||
405 !strcmp(argv[i],
"-h")) {
406 const char *pname = isc_file_basename(
progname);
430 if ((pid = fork ()) < 0)
436 (void) close(
dfd[1]);
440 n = read(
dfd[0], &buf, 1);
443 }
while (n == -1 && errno == EINTR);
447 (void) close(
dfd[0]);
453 if (status != ISC_R_SUCCESS)
454 log_fatal(
"Can't initialize context: %s",
455 isc_result_totext(status));
459 if (status != ISC_R_SUCCESS)
461 isc_result_totext(status));
471 for (i = 1; i < argc; i++) {
472 if (!strcmp(argv[i],
"-r")) {
476 }
else if (!strcmp(argv[i],
"-4")) {
478 log_fatal(
"Client can only do v4 or v6, not " 480 local_family_set = 1;
482 }
else if (!strcmp(argv[i],
"-6")) {
484 log_fatal(
"Client can only do v4 or v6, not " 486 local_family_set = 1;
489 }
else if (!strcmp(argv[i],
"-4o6")) {
491 usage(use_noarg, argv[i-1]);
494 log_debug(
"DHCPv4 over DHCPv6 over ::1 port %d and %d",
496 ntohs(dhcp4o6_port) + 1);
500 }
else if (!strcmp(argv[i],
"-x")) {
504 }
else if (!strcmp(argv[i],
"-p")) {
506 usage(use_noarg, argv[i-1]);
508 log_debug(
"binding to user-specified port %d",
510 }
else if (!strcmp(argv[i],
"-d")) {
513 }
else if (!strcmp(argv[i],
"-pf")) {
515 usage(use_noarg, argv[i-1]);
518 }
else if (!strcmp(argv[i],
"--no-pid")) {
520 }
else if (!strcmp(argv[i],
"-cf")) {
522 usage(use_noarg, argv[i-1]);
524 no_dhclient_conf = 1;
525 }
else if (!strcmp(argv[i],
"-df")) {
527 usage(use_noarg, argv[i-1]);
529 }
else if (!strcmp(argv[i],
"-lf")) {
531 usage(use_noarg, argv[i-1]);
534 }
else if (!strcmp(argv[i],
"-sf")) {
536 usage(use_noarg, argv[i-1]);
538 no_dhclient_script = 1;
539 }
else if (!strcmp(argv[i],
"-1")) {
541 }
else if (!strcmp(argv[i],
"-q")) {
543 }
else if (!strcmp(argv[i],
"-s")) {
545 usage(use_noarg, argv[i-1]);
547 }
else if (!strcmp(argv[i],
"-g")) {
549 usage(use_noarg, argv[i-1]);
551 }
else if (!strcmp(argv[i],
"-nw")) {
553 }
else if (!strcmp(argv[i],
"-n")) {
556 }
else if (!strcmp(argv[i],
"-w")) {
559 }
else if (!strcmp(argv[i],
"-e")) {
562 usage(use_noarg, argv[i-1]);
563 tmp =
dmalloc(strlen(argv[i]) +
sizeof *tmp,
MDL);
566 strcpy(tmp->
string, argv[i]);
571 }
else if (!strcmp(argv[i],
"-S")) {
573 usage(use_v6command, argv[i]);
575 local_family_set = 1;
579 }
else if (!strcmp(argv[i],
"-N")) {
581 usage(use_v6command, argv[i]);
583 local_family_set = 1;
589 }
else if (!strcmp(argv[i],
"-T")) {
591 usage(use_v6command, argv[i]);
593 local_family_set = 1;
599 }
else if (!strcmp(argv[i],
"-P")) {
601 usage(use_v6command, argv[i]);
603 local_family_set = 1;
609 }
else if (!strcmp(argv[i],
"-R")) {
611 usage(use_v6command, argv[i]);
613 local_family_set = 1;
616 }
else if (!strcmp(argv[i],
"--dad-wait-time")) {
618 usage(use_noarg, argv[i-1]);
621 dad_wait_time = (
int)strtol(argv[i], &s, 10);
622 if (errno || (*s !=
'\0') || (dad_wait_time < 0)) {
623 usage(
"Invalid value for --dad-wait-time: %s",
626 }
else if (!strcmp(argv[i],
"--prefix-len-hint")) {
628 usage(use_noarg, argv[i-1]);
632 prefix_len_hint = (
int)strtol(argv[i], &s, 10);
633 if (errno || (*s !=
'\0') || (prefix_len_hint < 0)) {
634 usage(
"Invalid value for --prefix-len-hint: %s",
637 }
else if (!strcmp(argv[i],
"--address-prefix-len")) {
639 usage(use_noarg, argv[i-1]);
643 if (errno || (*s !=
'\0') ||
645 usage(
"Invalid value for" 646 " --address-prefix-len: %s", argv[i]);
649 }
else if (!strcmp(argv[i],
"--decline-wait-time")) {
651 usage(use_noarg, argv[i-1]);
656 if (errno || (*s !=
'\0') ||
658 usage(
"Invalid value for " 659 "--decline-wait-time: %s", argv[i]);
661 }
else if (!strcmp(argv[i],
"-D")) {
664 usage(use_noarg, argv[i-1]);
665 if (!strcasecmp(argv[i],
"LL")) {
667 }
else if (!strcasecmp(argv[i],
"LLT")) {
670 usage(
"Unknown argument to -D: %s", argv[i]);
672 }
else if (!strcmp(argv[i],
"-i")) {
675 }
else if (!strcmp(argv[i],
"-I")) {
678 }
else if (!strcmp(argv[i],
"-v")) {
680 }
else if (argv[i][0] ==
'-') {
681 usage(
"Unknown command: %s", argv[i]);
683 usage(
"No interfaces comamnd -n and " 684 " requested interface %s", argv[i]);
688 status = interface_allocate(&tmp,
MDL);
689 if (status != ISC_R_SUCCESS)
690 log_fatal(
"Can't record interface %s:%s",
691 argv[i], isc_result_totext(status));
692 if (strlen(argv[i]) >=
sizeof(tmp->
name))
693 log_fatal(
"%s: interface name too long (is %ld)",
694 argv[i], (
long)strlen(argv[i]));
695 strcpy(tmp->
name, argv[i]);
697 interface_reference(&tmp->
next,
713 usage(
"PD %s only supports one requested interface",
"-P");
716 #if defined(DHCPv6) && defined(DHCP4o6) 718 (exit_mode || release_mode))
719 log_error(
"Can't relay DHCPv4-over-DHCPv6 " 720 "without a persistent DHCPv6 client");
723 log_fatal(
"DHCPv4-over-DHCPv6 requires an explicit " 724 "interface on which to be applied");
727 if (!no_dhclient_conf && (s = getenv(
"PATH_DHCLIENT_CONF"))) {
730 if (!no_dhclient_db && (s = getenv(
"PATH_DHCLIENT_DB"))) {
733 if (!no_dhclient_pid && (s = getenv(
"PATH_DHCLIENT_PID"))) {
736 if (!no_dhclient_script && (s = getenv(
"PATH_DHCLIENT_SCRIPT"))) {
740 #ifdef HAVE_LIBCAP_NG 742 if (!keep_capabilities) {
743 capng_clear(CAPNG_SELECT_CAPS);
744 capng_update(CAPNG_ADD, CAPNG_EFFECTIVE|CAPNG_PERMITTED,
746 capng_updatev(CAPNG_ADD, CAPNG_EFFECTIVE|CAPNG_PERMITTED,
747 CAP_NET_ADMIN, CAP_NET_RAW,
748 CAP_NET_BIND_SERVICE, CAP_SYS_ADMIN, -1);
749 capng_apply(CAPNG_SELECT_CAPS);
787 if ((release_mode || exit_mode) && (
no_pid_file == ISC_FALSE)) {
794 e = fscanf(pidfd,
"%ld\n", &temp);
795 oldpid = (pid_t)temp;
797 if (e != 0 && e != EOF && oldpid) {
798 if (kill(oldpid, SIGTERM) == 0) {
799 log_info(
"Killed old client process");
809 }
else if (errno == ESRCH) {
823 char *new_path_dhclient_pid;
842 int n_len = strlen(
ip->name);
844 new_path_dhclient_pid = (
char*) malloc(pfx + n_len + 6);
846 sprintf(new_path_dhclient_pid + pfx,
"-%s.pid",
ip->name);
848 if ((pidfd = fopen(new_path_dhclient_pid,
"re")) != NULL) {
849 e = fscanf(pidfd,
"%ld\n", &temp);
850 oldpid = (pid_t)temp;
852 if (e != 0 && e != EOF) {
854 if (kill(oldpid, SIGTERM) == 0)
862 free(new_path_dhclient_pid);
871 char procfn[256] =
"";
874 if ((fscanf(pidfp,
"%ld", &temp)==1) && ((dhcpid=(pid_t)temp) > 0)) {
875 snprintf(procfn,256,
"/proc/%u",dhcpid);
876 dhc_running = (access(procfn, F_OK) == 0);
883 log_fatal(
"dhclient(%u) is already running - exiting. ", dhcpid);
908 memcpy(&
giaddr, he->h_addr_list[0],
917 gettimeofday(&
cur_tv, NULL);
924 he = gethostbyname(server);
944 usage(
"Stateless command: %s incompatibile with " 945 "other commands",
"-S");
947 #if defined(DHCPv6) && defined(DHCP4o6) 962 if ((dhcp_client_identifier_arg != NULL) && (*dhcp_client_identifier_arg !=
'\0')) {
963 arg_conf_len =
asprintf(&arg_conf,
"send dhcp-client-identifier \"%s\";", dhcp_client_identifier_arg);
965 if ((arg_conf == 0) || (arg_conf_len <= 0))
966 log_fatal(
"Unable to send -C option dhcp-client-identifier");
969 if ((dhcp_host_name_arg != NULL) && (*dhcp_host_name_arg !=
'\0')) {
971 arg_conf_len =
asprintf(&arg_conf,
"send host-name \"%s\";", dhcp_host_name_arg);
973 if ((arg_conf == 0) || (arg_conf_len <= 0))
974 log_fatal(
"Unable to send -H option host-name");
976 char *last_arg_conf = arg_conf;
978 arg_conf_len =
asprintf(&arg_conf,
"%s\nsend host-name \"%s\";", last_arg_conf, dhcp_host_name_arg);
980 if ((arg_conf == 0) || (arg_conf_len <= 0))
981 log_fatal(
"Unable to send -H option host-name");
987 if ((dhcp_fqdn_arg != NULL) && (*dhcp_fqdn_arg !=
'\0')) {
989 arg_conf_len =
asprintf(&arg_conf,
"send fqdn.fqdn \"%s\";", dhcp_fqdn_arg);
991 if ((arg_conf == 0) || (arg_conf_len <= 0))
992 log_fatal(
"Unable to send -F option fqdn.fqdn");
994 char *last_arg_conf = arg_conf;
996 arg_conf_len =
asprintf(&arg_conf,
"%s\nsend fqdn.fqdn \"%s\";", last_arg_conf, dhcp_fqdn_arg);
998 if ((arg_conf == 0) || (arg_conf_len <= 0))
999 log_fatal(
"Unable to send -F option fqdn.fqdn");
1001 free(last_arg_conf);
1006 if (arg_conf == 0) {
1007 arg_conf_len =
asprintf(&arg_conf,
"timeout %d;", timeout_arg);
1009 if ((arg_conf == 0) || (arg_conf_len <= 0))
1010 log_fatal(
"Unable to process --timeout timeout argument");
1012 char *last_arg_conf = arg_conf;
1014 arg_conf_len =
asprintf(&arg_conf,
"%s\ntimeout %d;", last_arg_conf, timeout_arg);
1016 if ((arg_conf == 0) || (arg_conf_len == 0))
1017 log_fatal(
"Unable to process --timeout timeout argument");
1019 free(last_arg_conf);
1023 if ((dhcp_vendor_class_identifier_arg != NULL) && (*dhcp_vendor_class_identifier_arg !=
'\0')) {
1024 if (arg_conf == 0) {
1025 arg_conf_len =
asprintf(&arg_conf,
"send vendor-class-identifier \"%s\";", dhcp_vendor_class_identifier_arg);
1027 if ((arg_conf == 0) || (arg_conf_len <= 0))
1028 log_fatal(
"Unable to send -V option vendor-class-identifier");
1030 char *last_arg_conf = arg_conf;
1032 arg_conf_len =
asprintf(&arg_conf,
"%s\nsend vendor-class-identifier \"%s\";", last_arg_conf, dhcp_vendor_class_identifier_arg);
1034 if ((arg_conf == 0) || (arg_conf_len <= 0))
1035 log_fatal(
"Unable to send -V option vendor-class-identifier");
1037 free(last_arg_conf);
1041 if (dhclient_request_options != NULL) {
1042 if (arg_conf == 0) {
1043 arg_conf_len =
asprintf(&arg_conf,
"request %s;", dhclient_request_options);
1045 if ((arg_conf == 0) || (arg_conf_len <= 0))
1046 log_fatal(
"Unable to parse --request-options <request options list> argument");
1048 char *last_arg_conf = arg_conf;
1050 arg_conf_len =
asprintf(&arg_conf,
"%s\nrequest %s;", last_arg_conf, dhclient_request_options);
1052 if ((arg_conf == 0) || (arg_conf_len <= 0))
1053 log_fatal(
"Unable to parse --request-options <request options list> argument");
1055 free(last_arg_conf);
1060 if (arg_conf_len == 0)
1061 if ((arg_conf_len = strlen(arg_conf)) == 0)
1063 log_fatal(
"Unable to process -C/-H/-F/--timeout/-V/--request-options configuration arguments");
1068 const char *val = NULL;
1071 status =
new_parse(&cfile, -1, arg_conf, arg_conf_len,
"extra dhclient -C/-H/-F/--timeout/-V/--request-options configuration arguments", 0);
1074 log_fatal(
"Cannot parse -C/-H/-F/--timeout/-V/--request-options configuration arguments !");
1086 log_fatal(
"Cannot parse -C/-H/-F/--timeout/-V/--request-options configuration arguments !");
1094 if (
ip->client->config->timeout == 60)
1095 ip->client->config->timeout = timeout_arg;
1143 log_info(
"No broadcast interfaces found - exiting.");
1146 }
else if (!release_mode && !exit_mode) {
1163 if (
ip->client->alias != NULL)
1180 unsigned backup_seed = 0;
1183 if (
ip -> hw_address.hlen <=
sizeof seed )
1186 &
ip -> hw_address.hbuf [
ip -> hw_address.hlen -
1187 sizeof seed],
sizeof seed);
1209 if (
ip -> hw_address.hlen <=
sizeof seed )
1212 &
ip->hw_address.hbuf[
ip->hw_address.hlen -
1213 sizeof seed],
sizeof seed);
1217 if ( seed_flag == 0 ) {
1218 if ( backup_seed != 0 ) {
1220 log_info (
"xid: rand init seed (0x%x) built using all" 1221 " available interfaces",seed);
1224 seed =
cur_time^((unsigned) gethostid()) ;
1225 log_info (
"xid: warning: no netdev with useable HWADDR found" 1226 " for seed's uniqueness enforcement");
1227 log_info (
"xid: rand init seed (0x%x) built using gethostid",
1232 srandom(seed + ((
unsigned)(
cur_tv.tv_usec * 1000000)) + (
unsigned)getpid());
1235 srandom(seed + ((
unsigned)(
cur_tv.tv_usec * 1000000)) + (
unsigned)getpid());
1241 setup_ib_interface(
ip);
1260 #if defined(DHCPv6) && defined(DHCP4o6) 1262 dhcp4o6_setup(dhcp4o6_port);
1269 for (client =
ip->client ; client != NULL ;
1270 client = client->
next) {
1274 }
else if (exit_mode) {
1294 for (client =
ip->client ; client ;
1295 client = client->
next) {
1312 tv.tv_usec = random()
1347 if (result != ISC_R_SUCCESS)
1348 log_fatal(
"Can't allocate new generic object: %s\n",
1349 isc_result_totext(result));
1354 if (result != ISC_R_SUCCESS)
1355 log_fatal(
"Can't start OMAPI protocol: %s",
1356 isc_result_totext (result));
1365 #if defined(DEBUG_MEMORY_LEAKAGE) || defined(DEBUG_MALLOC_POOL) || \ 1366 defined(DEBUG_MEMORY_LEAKAGE_ON_EXIT) 1367 dmalloc_cutoff_generation = dmalloc_generation;
1368 dmalloc_longterm = dmalloc_outstanding;
1369 dmalloc_outstanding = 0;
1372 #if defined(ENABLE_GENTLE_SHUTDOWN) 1409 isc_result_t result;
1419 usage(
"No interfaces available for stateless command: %s",
"-S");
1451 dhcp4o6_setup(port);
1457 client = client->
next) {
1471 if (result != ISC_R_SUCCESS)
1472 log_fatal(
"Can't allocate new generic object: %s\n",
1473 isc_result_totext(result));
1478 if (result != ISC_R_SUCCESS)
1479 log_fatal(
"Can't start OMAPI protocol: %s",
1480 isc_result_totext(result));
1486 #if defined(DEBUG_MEMORY_LEAKAGE) || defined(DEBUG_MALLOC_POOL) || \ 1487 defined(DEBUG_MEMORY_LEAKAGE_ON_EXIT) 1488 dmalloc_cutoff_generation = dmalloc_generation;
1489 dmalloc_longterm = dmalloc_outstanding;
1490 dmalloc_outstanding = 0;
1512 const char *s,
const char *
file,
int line)
1547 ip->client->config->bootp_broadcast_always = 1;
1553 for (g =
ip->client->config->on_transmission; g != NULL; g = g->
next) {
1556 "dhcp-client-identifier") == 0)) {
1562 log_fatal(
"dhcp-client-identifier must be specified for InfiniBand");
1599 #if defined(DHCPv6) && defined(DHCP4o6) 1601 if (dhcp4o6_state < 0)
1612 client ->
active -> is_bootp ||
1626 client ->
xid = random ();
1695 for (lp = client -> offered_leases; lp; lp =
next) {
1704 picked ->
next = NULL;
1709 client -> offered_leases = NULL;
1716 client -> state =
S_INIT;
1723 client ->
new = picked;
1741 client -> first_sending =
cur_time;
1742 client -> interval = client -> config -> initial_interval;
1746 client -> xid = client ->
packet.xid;
1769 for (client =
ip -> client; client; client = client -> next) {
1770 if (client -> xid ==
packet -> raw -> xid)
1774 (
packet -> interface -> hw_address.hlen - 1 !=
1775 packet -> raw -> hlen) ||
1776 (memcmp (&
packet -> interface -> hw_address.hbuf [1],
1779 log_debug (
"DHCPACK in wrong transaction.");
1793 log_info (
"DHCPACK of %s from %s (xid=0x%x)",
1796 ntohl(client -> xid));
1800 log_info (
"packet_to_lease failed.");
1804 client ->
new =
lease;
1812 memset (&ds, 0,
sizeof ds);
1815 packet -> options, client ->
new -> options,
1820 client ->
new -> expiry = 0;
1823 client ->
new -> expiry = 0;
1828 log_error (
"no expiry time on offered lease.");
1834 tv.tv_sec =
cur_tv.tv_sec;
1835 tv.tv_usec =
cur_tv.tv_usec + 500000;
1837 if (tv.tv_usec >= 1000000) {
1839 tv.tv_usec -= 1000000;
1858 packet -> options, client ->
new -> options,
1863 client ->
new -> renewal = 0;
1866 client ->
new -> renewal = 0;
1869 if (!client ->
new -> renewal)
1870 client ->
new -> renewal = client ->
new -> expiry / 2 + 1;
1872 if (client ->
new -> renewal <= 0)
1873 client ->
new -> renewal =
TIME_MAX;
1878 (((random() % client->
new->
renewal) + 3) / 4);
1885 packet -> options, client ->
new -> options,
1890 client ->
new -> rebind = 0;
1893 client ->
new -> rebind = 0;
1895 if (client ->
new -> rebind <= 0) {
1896 if (client ->
new -> expiry <=
TIME_MAX / 7)
1897 client ->
new -> rebind =
1898 client ->
new -> expiry * 7 / 8;
1900 client ->
new -> rebind =
1901 client ->
new -> expiry / 8 * 7;
1906 if (client ->
new -> renewal > client ->
new -> rebind) {
1907 if (client ->
new -> rebind <=
TIME_MAX / 3)
1908 client ->
new -> renewal =
1909 client ->
new -> rebind * 3 / 4;
1911 client ->
new -> renewal =
1912 client ->
new -> rebind / 4 * 3;
1915 client ->
new -> expiry +=
cur_time;
1917 if (client ->
new -> expiry <
cur_time)
1918 client ->
new -> expiry =
TIME_MAX;
1919 client ->
new -> renewal +=
cur_time;
1920 if (client ->
new -> renewal <
cur_time)
1921 client ->
new -> renewal =
TIME_MAX;
1922 client ->
new -> rebind +=
cur_time;
1923 if (client ->
new -> rebind <
cur_time)
1924 client ->
new -> rebind =
TIME_MAX;
1960 log_info(
"Unable to obtain a lease on first " 1961 "try (declined). Exiting.");
1964 #if defined (CALL_SCRIPT_ON_ONETRY_FAIL) 1973 tv.tv_usec =
cur_tv.tv_usec;
1993 random() % 1000000 :
cur_tv.tv_usec;
1996 log_info(
"bound to %s -- renewal in %ld seconds.",
2002 #if defined (NSUPDATE) 2024 client -> xid = client ->
packet.xid;
2026 memset (&ds, 0,
sizeof ds);
2032 client -> active -> options,
2035 memcpy (client -> destination.iabuf, ds.
data, 4);
2036 client -> destination.len = 4;
2044 client -> first_sending =
cur_time;
2045 client -> interval = client -> config -> initial_interval;
2113 for (ap =
packet -> interface -> client -> config -> reject_list;
2114 ap; ap = ap ->
next) {
2123 log_info(
"BOOTREPLY from %s rejected by rule %s " 2138 void (*handler) (
struct packet *);
2166 ap; ap = ap -> next) {
2175 log_info(
"%s from %s rejected by rule %s mask %s.",
2189 char addrbuf[
sizeof(
"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")];
2197 ap ; ap = ap->
next) {
2200 log_info(
"%s from %s rejected by rule %s",
2213 log_info(
"RCV: %s message on %s from %s.",
2217 forw_dhcpv4_response(
packet);
2227 log_info(
"RCV: %s message on %s from %s.",
2238 client = client->
next) {
2247 log_info(
"Packet received, but nothing done with it.");
2263 static void forw_dhcpv4_response(
struct packet *
packet)
2273 if (dhcp4o6_state == -1) {
2274 log_info(
"forw_dhcpv4_response: not ready.");
2279 log_error(
"forw_dhcpv4_response: bad address");
2288 log_info(
"DHCPv4-response from %s missing " 2289 "DHCPv4 Message option.",
2294 memset(&enc_opt_data, 0,
sizeof(enc_opt_data));
2297 log_error(
"forw_dhcpv4_response: error evaluating " 2305 "no memory for encapsulated packet.");
2313 memset(&ds, 0,
sizeof(ds));
2315 log_error(
"forw_dhcpv4_response: no memory buffer.");
2319 ds.data = ds.buffer->data;
2320 ds.len = enc_opt_data.len + 16;
2321 memcpy(ds.buffer->data, enc_opt_data.data, enc_opt_data.len);
2322 memcpy(ds.buffer->data + enc_opt_data.len,
2329 cc = send(dhcp4o6_fd, ds.data, ds.len, 0);
2331 log_error(
"forw_dhcpv4_response: send(): %m");
2345 static void recv_dhcpv4_response(
struct data_string *raw)
2351 log_error(
"recv_dhcpv4_response: no interfaces.");
2356 memcpy(from.iabuf, raw->
data + (raw->
len - 16), 16);
2363 log_error(
"recv_dhcpv4_response: no memory for packet.");
2375 log_error(
"recv_dhcpv4_response: no memory for options.");
2396 memset(&dp, 0,
sizeof dp);
2430 const char *
name =
packet -> packet_type ?
"DHCPOFFER" :
"BOOTREPLY";
2439 for (client =
ip -> client; client; client = client -> next)
2440 if (client -> xid ==
packet -> raw -> xid)
2447 (
packet -> interface -> hw_address.hlen - 1 !=
2448 packet -> raw -> hlen) ||
2449 (memcmp (&
packet -> interface -> hw_address.hbuf [1],
2452 log_debug (
"%s in wrong transaction.", name);
2457 sprintf (obuf,
"%s of %s from %s", name,
2466 for (i = 0 ; req[i] != NULL ; i++) {
2473 option_code_hash_lookup(&
option,
2478 log_info(
"%s: no %s option.", obuf,
2481 log_info(
"%s: no unknown-%u option.",
2493 if (
lease -> address.len ==
sizeof packet -> raw -> yiaddr &&
2494 !memcmp (
lease -> address.iabuf,
2495 &
packet -> raw -> yiaddr,
lease -> address.len)) {
2503 log_info (
"%s: packet_to_lease failed.", obuf);
2512 if (!
packet -> options_valid || !
packet -> packet_type)
2513 lease -> is_bootp = 1;
2516 lease -> medium = client -> medium;
2519 stop_selecting = (client -> first_sending +
2520 client -> config -> select_interval);
2524 if (
lease -> address.len == client -> requested_address.len &&
2525 !memcmp (
lease -> address.iabuf,
2526 client -> requested_address.iabuf,
2527 client -> requested_address.len)) {
2528 lease -> next = client -> offered_leases;
2529 client -> offered_leases =
lease;
2533 if (!client -> offered_leases)
2534 client -> offered_leases =
lease;
2536 for (lp = client -> offered_leases; lp ->
next;
2546 if (stop_selecting <=
cur_tv.tv_sec)
2549 tv.tv_sec = stop_selecting;
2550 tv.tv_usec =
cur_tv.tv_usec;
2572 log_error(
"packet_to_lease: no memory to record lease.\n");
2583 lease->address.len);
2587 lease->next_srv_addr.len);
2589 memset(&data, 0,
sizeof(data));
2591 if (client -> config -> vendor_space_name) {
2597 client -> config -> vendor_space_name &&
2599 (
struct lease *)0, client,
2603 if (!option_code_hash_lookup(&
option,
2607 "option (%s:%d).",
MDL);
2611 client -> config -> vendor_space_name
2637 if (!(i & 2) &&
packet -> raw -> sname [0]) {
2641 if (!
packet -> raw -> sname [len])
2645 log_error (
"dhcpoffer: no memory for server name.\n");
2650 packet -> raw -> sname, len);
2664 log_error (
"dhcpoffer: no memory for filename.\n");
2689 for (client =
ip -> client; client; client = client ->
next)
2697 packet -> raw -> hlen) ||
2701 log_debug (
"DHCPNAK in wrong transaction.");
2720 log_info (
"DHCPNAK with no active lease.\n");
2753 client -> state =
S_INIT;
2772 interval =
cur_time - client -> first_sending;
2776 if (interval > client -> config ->
timeout) {
2784 if (!client -> offered_leases &&
2785 client -> config -> media) {
2788 if (client -> medium) {
2789 client -> medium = client -> medium -> next;
2792 if (!client -> medium) {
2794 log_fatal (
"No valid media types for %s!",
2795 client -> interface -> name);
2797 client -> config -> media;
2801 log_info (
"Trying medium \"%s\" %d",
2802 client -> medium ->
string, increase);
2830 if (
cur_time + client -> interval >
2831 client -> first_sending + client -> config ->
timeout)
2832 client -> interval =
2833 (client -> first_sending +
2837 if (interval < 65536)
2838 client ->
packet.secs = htons (interval);
2840 client ->
packet.secs = htons (65535);
2841 client -> secs = client ->
packet.secs;
2843 #if defined(DHCPv6) && defined(DHCP4o6) 2845 log_info (
"DHCPDISCOVER interval %ld",
2846 (
long)(client -> interval));
2849 log_info (
"DHCPDISCOVER on %s to %s port %d interval %ld (xid=0x%x)",
2850 client -> name ? client -> name : client -> interface -> name,
2852 ntohs (
sockaddr_broadcast.sin_port), (
long)(client -> interval), ntohl(client -> xid));
2855 #if defined(DHCPv6) && defined(DHCP4o6) 2857 result = send_dhcpv4_query(client, 1);
2864 #if defined(DHCPv6) && defined(DHCP4o6) 2866 log_error(
"%s:%d: Failed to send %d byte long packet.",
2870 log_error(
"%s:%d: Failed to send %d byte long packet over %s " 2882 tv.tv_usec = client->
interval > 1 ? random() % 1000000 :
cur_tv.tv_usec;
2899 loop = lp = client -> active;
2901 log_info (
"No DHCPOFFERS received.");
2905 if (!client -> active && client -> leases)
2909 while (client -> active) {
2910 if (client -> active -> expiry >
cur_time) {
2911 log_info (
"Trying recorded lease %s",
2912 piaddr (client -> active -> address));
2916 client -> active -> medium);
2919 if (client -> alias)
2927 if (cur_time < client -> active -> renewal) {
2929 log_info (
"bound: renewal in %ld %s.",
2930 (
long)(client -> active -> renewal -
2935 random() % 1000000 :
2940 log_info (
"bound: immediate renewal.");
2950 if (!client -> leases) {
2951 client -> leases = client -> active;
2959 for (lp = client -> leases; lp ->
next; lp = lp ->
next)
2961 lp ->
next = client -> active;
2965 client -> active = client -> leases;
2966 client -> leases = client -> leases ->
next;
2971 if (client -> active == loop)
2974 loop = client -> active;
2982 log_info (
"Unable to obtain a lease on first try.%s",
2986 #if defined (CALL_SCRIPT_ON_ONETRY_FAIL) 2994 log_info (
"No working leases in persistent database - sleeping.");
2996 if (client -> alias)
2999 client -> state =
S_INIT;
3002 tv.tv_usec = ((tv.tv_sec -
cur_tv.tv_sec) > 1) ?
3003 random() % 1000000 :
cur_tv.tv_usec;
3015 struct sockaddr_in destination;
3016 struct in_addr from;
3019 const char* rip_str =
"";
3022 interval =
cur_time - client -> first_sending;
3036 interval > client -> config -> reboot_timeout) {
3038 client -> state =
S_INIT;
3047 !client -> medium &&
3048 client -> active -> medium ) {
3049 script_init(client,
"MEDIUM", client -> active -> medium);
3056 client -> medium = client -> active -> medium;
3062 cur_time > client -> active -> expiry) {
3067 if (client -> alias)
3075 if (client -> alias)
3080 client -> state =
S_INIT;
3086 if (!client -> interval)
3087 client -> interval = client -> config -> initial_interval;
3089 client -> interval += ((random () >> 2) %
3090 (2 * client -> interval));
3094 if (client -> interval >
3095 client -> config -> backoff_cutoff)
3096 client -> interval =
3097 ((client -> config -> backoff_cutoff / 2)
3098 + ((random () >> 2) %
3099 client -> config -> backoff_cutoff));
3104 cur_time + client -> interval > client -> active -> expiry)
3105 client -> interval =
3106 client -> active -> expiry -
cur_time + 1;
3112 cur_time > client -> active -> rebind)
3115 memcpy (&destination.sin_addr.s_addr,
3116 client -> destination.iabuf,
3117 sizeof destination.sin_addr.s_addr);
3119 destination.sin_family = AF_INET;
3121 destination.sin_len =
sizeof destination;
3126 memcpy (&from, client -> active -> address.iabuf,
3129 from.s_addr = INADDR_ANY;
3133 client ->
packet.secs = client -> secs;
3135 if (interval < 65536)
3136 client ->
packet.secs = htons (interval);
3138 client ->
packet.secs = htons (65535);
3141 #if defined(DHCPv6) && defined(DHCP4o6) 3146 memset(rip_buf, 0x0,
sizeof(rip_buf));
3154 strncpy(rip_buf, rip_str,
sizeof(rip_buf)-1);
3155 log_info (
"DHCPREQUEST for %s on %s to %s port %d (xid=0x%x)",
3158 inet_ntoa(destination.sin_addr),
3159 ntohs (destination.sin_port),
3160 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.",
3174 if (destination.sin_addr.s_addr != INADDR_BROADCAST &&
3176 #if defined(SO_BINDTODEVICE) 3180 log_error(
"%s:%d: Failed to bind fallback interface" 3188 log_error(
"%s:%d: Failed to send %d byte long packet " 3189 "over %s interface.",
MDL,
3193 #if defined(SO_BINDTODEVICE) 3195 SO_BINDTODEVICE, NULL, 0) < 0) {
3196 log_fatal(
"%s:%d: Failed to unbind fallback interface:" 3207 log_error(
"%s:%d: Failed to send %d byte long packet" 3208 " over %s interface.",
MDL,
3215 tv.tv_usec = ((tv.tv_sec -
cur_tv.tv_sec) > 1) ?
3216 random() % 1000000 :
cur_tv.tv_usec;
3227 #if defined(DHCPv6) && defined(DHCP4o6) 3232 log_info (
"DHCPDECLINE of %s on %s to %s port %d (xid=0x%x)",
3237 ntohl(client ->
xid));
3241 #if defined(DHCPv6) && defined(DHCP4o6) 3243 result = send_dhcpv4_query(client, 1);
3250 #if defined(DHCPv6) && defined(DHCP4o6) 3252 log_error(
"%s:%d: Failed to send %d byte long packet.",
3256 log_error(
"%s:%d: Failed to send %d byte long packet over %s" 3268 struct sockaddr_in destination;
3269 struct in_addr from;
3271 memcpy (&from, client -> active -> address.iabuf,
3273 memcpy (&destination.sin_addr.s_addr,
3274 client -> destination.iabuf,
3275 sizeof destination.sin_addr.s_addr);
3277 destination.sin_family = AF_INET;
3279 destination.sin_len =
sizeof destination;
3284 client -> active -> expiry =
3285 client -> active -> renewal =
3286 client -> active -> rebind =
cur_time;
3288 log_error (
"Can't release lease: lease write failed.");
3292 #if defined(DHCPv6) && defined(DHCP4o6) 3297 log_info (
"DHCPRELEASE of %s on %s to %s port %d (xid=0x%x)",
3300 inet_ntoa (destination.sin_addr),
3301 ntohs (destination.sin_port),
3302 ntohl(client -> xid));
3304 #if defined(DHCPv6) && defined(DHCP4o6) 3307 if (destination.sin_addr.s_addr == INADDR_BROADCAST)
3309 result = send_dhcpv4_query(client, broadcast);
3311 log_error(
"%s:%d: Failed to send %d byte long packet.",
3317 #if defined(SO_BINDTODEVICE) 3321 log_error(
"%s:%d: Failed to bind fallback interface" 3329 log_error(
"%s:%d: Failed to send %d byte long packet" 3330 " over %s interface.",
MDL,
3334 #if defined(SO_BINDTODEVICE) 3336 SO_BINDTODEVICE, NULL, 0) < 0) {
3337 log_fatal(
"%s:%d: Failed to unbind fallback interface:" 3347 log_error (
"%s:%d: Failed to send %d byte long packet" 3348 " over %s interface.",
MDL,
3356 #if defined(DHCPv6) && defined(DHCP4o6) 3368 static int send_dhcpv4_query(
struct client_state *client,
int broadcast) {
3373 if (dhcp4o6_state <= 0) {
3374 log_info(
"send_dhcpv4_query: not ready.");
3384 memset(&ds, 0,
sizeof(ds));
3386 log_error(
"Unable to allocate memory for DHCPv4-query.");
3389 ds.data = ds.buffer->data;
3414 cc = send(dhcp4o6_fd, ds.data, ds.len, 0);
3416 log_error(
"send_dhcpv4_query: send(): %m");
3429 static void forw_dhcpv4_query(
struct data_string *raw) {
3435 struct sockaddr_in6 sin6;
3436 int i, send_ret, attempt, success;
3438 attempt = success = 0;
3439 memset(&sin6, 0,
sizeof(sin6));
3440 sin6.sin6_family = AF_INET6;
3443 sin6.sin6_len =
sizeof(sin6);
3445 memset(&addrs, 0,
sizeof(addrs));
3447 for (client =
ip->client; client != NULL;
3448 client = client->
next) {
3461 lease->options, NULL,
3463 ((addrs.len %
sizeof(sin6.sin6_addr)) != 0)) {
3467 if (addrs.len == 0) {
3475 if (send_ret == raw->
len)
3479 for (i = 0; i < addrs.len;
3480 i +=
sizeof(sin6.sin6_addr)) {
3481 memcpy(&sin6.sin6_addr, addrs.data + i,
3482 sizeof(sin6.sin6_addr));
3486 if (send_ret == raw->
len)
3493 log_info(
"forw_dhcpv4_query: sent(%d): %d/%d",
3494 raw->
len, success, attempt);
3510 struct buffer *bp = NULL;
3533 log_error (
"can't make requested address cache.");
3559 for (i = 0 ; prl[i] != NULL ; i++)
3564 log_error(
"can't make parameter list buffer.");
3569 for (i = 0 ; prl[i] != NULL ; i++)
3573 if (!(option_code_hash_lookup(&
option,
3598 memset(&client_identifier, 0,
sizeof(client_identifier));
3601 client_identifier.
len,
MDL))
3602 log_fatal(
"no memory for default DUID!");
3620 memcpy(&client_identifier.
buffer->
data + 5 - hw_len,
3625 memcpy(&client_identifier.
buffer->
data+(1+4),
3632 (u_int8_t *)client_identifier.
data,
3633 client_identifier.
len,
3635 log_error (
"can't make requested client id cache..");
3659 memset (&client ->
packet, 0,
sizeof (client ->
packet));
3664 client -> config -> requested_options,
3668 client -> packet_length =
3670 (
struct lease *)0, client,
3679 client -> config -> vendor_space_name);
3686 client ->
packet.htype = client ->
interface -> hw_address.hbuf [0];
3688 client ->
packet.hlen = client ->
interface -> hw_address.hlen - 1;
3689 client ->
packet.hops = 0;
3690 client ->
packet.xid = random ();
3691 client ->
packet.secs = 0;
3695 client ->
packet.flags = 0;
3699 memset (&(client ->
packet.ciaddr),
3700 0,
sizeof client ->
packet.ciaddr);
3701 memset (&(client ->
packet.yiaddr),
3702 0,
sizeof client ->
packet.yiaddr);
3703 memset (&(client ->
packet.siaddr),
3704 0,
sizeof client ->
packet.siaddr);
3706 if (client -> interface -> hw_address.hlen > 0)
3707 memcpy (client ->
packet.chaddr,
3708 &client -> interface -> hw_address.hbuf [1],
3709 (
unsigned)(client -> interface -> hw_address.hlen - 1));
3712 dump_raw ((
unsigned char *)&client ->
packet, client -> packet_length);
3724 memset (&client ->
packet, 0,
sizeof (client ->
packet));
3732 if (client -> sent_options)
3739 : (
struct iaddr *)0),
3740 client -> config -> requested_options,
3741 &client -> sent_options);
3744 client -> packet_length =
3746 (
struct lease *)0, client,
3749 client -> sent_options,
3755 client -> config -> vendor_space_name);
3761 client ->
packet.htype = client ->
interface -> hw_address.hbuf [0];
3763 client ->
packet.hlen = client ->
interface -> hw_address.hlen - 1;
3764 client ->
packet.hops = 0;
3765 client ->
packet.xid = client -> xid;
3766 client ->
packet.secs = 0;
3770 if (client -> state ==
S_BOUND ||
3773 memcpy (&client ->
packet.ciaddr,
3774 lease -> address.iabuf,
lease -> address.len);
3775 client ->
packet.flags = 0;
3777 memset (&client ->
packet.ciaddr, 0,
3778 sizeof client ->
packet.ciaddr);
3780 client ->config->bootp_broadcast_always)) &&
3782 client ->
packet.flags = 0;
3787 memset (&client ->
packet.yiaddr, 0,
3788 sizeof client ->
packet.yiaddr);
3789 memset (&client ->
packet.siaddr, 0,
3790 sizeof client ->
packet.siaddr);
3791 if (client -> state !=
S_BOUND &&
3795 memset (&client ->
packet.giaddr, 0,
3796 sizeof client ->
packet.giaddr);
3797 if (client -> interface -> hw_address.hlen > 0)
3798 memcpy (client ->
packet.chaddr,
3799 &client -> interface -> hw_address.hbuf [1],
3800 (
unsigned)(client -> interface -> hw_address.hlen - 1));
3803 dump_raw ((
unsigned char *)&client ->
packet, client -> packet_length);
3823 memset (&client ->
packet, 0,
sizeof (client ->
packet));
3824 client -> packet_length =
3826 (
struct lease *)0, client, 0,
3829 client -> config -> vendor_space_name);
3838 client ->
packet.htype = client ->
interface -> hw_address.hbuf [0];
3840 client ->
packet.hlen = client ->
interface -> hw_address.hlen - 1;
3841 client ->
packet.hops = 0;
3842 client ->
packet.xid = client -> xid;
3843 client ->
packet.secs = 0;
3846 client ->
packet.flags = 0;
3851 memset (&client ->
packet.ciaddr, 0,
3852 sizeof client ->
packet.ciaddr);
3853 memset (&client ->
packet.yiaddr, 0,
3854 sizeof client ->
packet.yiaddr);
3855 memset (&client ->
packet.siaddr, 0,
3856 sizeof client ->
packet.siaddr);
3858 memcpy (client ->
packet.chaddr,
3859 &client -> interface -> hw_address.hbuf [1],
3860 client -> interface -> hw_address.hlen);
3863 dump_raw ((
unsigned char *)&client ->
packet, client -> packet_length);
3876 memset (&client ->
packet, 0,
sizeof (client ->
packet));
3883 client -> packet_length =
3885 (
struct lease *)0, client,
3894 client -> config -> vendor_space_name);
3901 client ->
packet.htype = client ->
interface -> hw_address.hbuf [0];
3903 client ->
packet.hlen = client ->
interface -> hw_address.hlen - 1;
3904 client ->
packet.hops = 0;
3905 client ->
packet.xid = random ();
3906 client ->
packet.secs = 0;
3907 client ->
packet.flags = 0;
3908 memcpy (&client ->
packet.ciaddr,
3909 lease -> address.iabuf,
lease -> address.len);
3910 memset (&client ->
packet.yiaddr, 0,
3911 sizeof client ->
packet.yiaddr);
3912 memset (&client ->
packet.siaddr, 0,
3913 sizeof client ->
packet.siaddr);
3915 memcpy (client ->
packet.chaddr,
3916 &client -> interface -> hw_address.hbuf [1],
3917 client -> interface -> hw_address.hlen);
3920 dump_raw ((
unsigned char *)&client ->
packet, client -> packet_length);
3959 for (client =
ip -> client; client; client = client ->
next) {
3960 for (lp = client -> leases; lp; lp = lp ->
next) {
3963 if (client -> active)
3965 client -> active, 1, 0);
3980 for (client =
ip -> client; client; client = client ->
next) {
3981 for (lp = client -> leases; lp; lp = lp ->
next) {
3984 if (client -> active)
3986 client -> active, 1, 0);
4008 const char *name, *dot;
4010 char *preamble = stuff;
4012 memset (&ds, 0,
sizeof ds);
4022 in_options, cfg_options, scope, oc,
MDL)) {
4024 fprintf(
leaseFile,
"%soption %s%s%s", preamble,
4045 const char *preamble)
4058 if (c >=
'0' && c <=
'9')
4061 if (c >=
'a' && c <=
'f')
4062 return c -
'a' + 10;
4064 if (c >=
'A' && c <=
'F')
4065 return c -
'A' + 10;
4072 const char *id_fname =
"/etc/machine-id";
4075 FILE *
file = fopen( id_fname ,
"r");
4078 return ISC_R_IOERROR;
4080 nread = fread(
id, 1,
sizeof id,
file);
4084 log_debug(
"Not enough data in %s", id_fname);
4085 return ISC_R_IOERROR;
4088 for (j = 0; j < 16; j++) {
4094 if (a < 0 || b < 0) {
4095 log_debug(
"Wrong data in %s", id_fname);
4096 return ISC_R_IOERROR;
4098 uuid[j] = a << 4 | b;
4102 uuid[6] = (uuid[6] & 0x0F) | 0x40;
4104 uuid[8] = (uuid[8] & 0x3F) | 0x80;
4106 return ISC_R_SUCCESS;
4139 log_debug(
"Cannot form default DUID from interface %s.",
ip->name);
4143 return ISC_R_UNEXPECTED;
4146 if ((
ip->hw_address.hlen == 0) ||
4147 (
ip->hw_address.hlen >
sizeof(
ip->hw_address.hbuf)))
4148 log_fatal(
"Impossible hardware address length at %s:%d.",
MDL);
4158 len = 2 +
sizeof (uuid);
4167 len = 4 + (
ip->hw_address.hlen - 1);
4172 log_fatal(
"no memory for default DUID!");
4178 memcpy(duid->
buffer->
data + 2, uuid,
sizeof(uuid));
4185 memcpy(duid->
buffer->
data + 8,
ip->hw_address.hbuf + 1,
4186 ip->hw_address.hlen - 1);
4190 memcpy(duid->
buffer->
data + 4,
ip->hw_address.hbuf + 1,
4191 ip->hw_address.hlen - 1);
4198 log_info(
"form_duid: Couldn't allocate memory to log duid!");
4204 return ISC_R_SUCCESS;
4214 if ((duid == NULL) || (duid->
len <= 2))
4221 return ISC_R_IOERROR;
4229 return ISC_R_NOMEMORY;
4231 stat = fprintf(
leaseFile,
"default-duid %s;\n", str);
4234 return ISC_R_IOERROR;
4237 return ISC_R_IOERROR;
4239 return ISC_R_SUCCESS;
4245 int rewrite,
int sync)
4256 return ISC_R_SUCCESS;
4259 if (client == NULL ||
lease == NULL)
4266 return ISC_R_IOERROR;
4270 stat = fprintf(
leaseFile,
"lease6 {\n");
4272 return ISC_R_IOERROR;
4274 stat = fprintf(
leaseFile,
" interface \"%s\";\n",
4277 return ISC_R_IOERROR;
4279 for (ia =
lease->bindings ; ia != NULL ; ia = ia->
next) {
4300 (
const unsigned char *) &ia->
iaid, 4,
4305 return ISC_R_IOERROR;
4316 stat = fprintf(
leaseFile,
" %s %s {\n", ianame,
4322 return ISC_R_IOERROR;
4325 stat = fprintf(
leaseFile,
" starts %d;\n" 4330 stat = fprintf(
leaseFile,
" starts %d;\n",
4333 return ISC_R_IOERROR;
4335 for (addr = ia->
addrs ; addr != NULL ; addr = addr->
next) {
4342 " iaprefix %s/%d {\n",
4346 return ISC_R_IOERROR;
4348 stat = fprintf(
leaseFile,
" starts %d;\n" 4349 " preferred-life %u;\n" 4354 return ISC_R_IOERROR;
4357 write_options(client, addr->
options,
" ");
4361 return ISC_R_IOERROR;
4365 write_options(client, ia->
options,
" ");
4369 return ISC_R_IOERROR;
4372 if (
lease->released) {
4373 stat = fprintf(
leaseFile,
" released;\n");
4375 return ISC_R_IOERROR;
4378 if (
lease->options != NULL)
4379 write_options(client,
lease->options,
" ");
4383 return ISC_R_IOERROR;
4386 return ISC_R_IOERROR;
4390 log_error(
"write_client_lease: fsync(): %m");
4391 return ISC_R_IOERROR;
4395 return ISC_R_SUCCESS;
4418 if (
lease -> is_static)
4431 if (
lease -> is_bootp) {
4438 fprintf (
leaseFile,
" interface \"%s\";\n",
4439 client -> interface -> name);
4444 if (client -> name) {
4445 fprintf (
leaseFile,
" name \"%s\";\n", client -> name);
4451 fprintf (
leaseFile,
" fixed-address %s;\n",
4457 if (
lease -> filename) {
4460 fprintf (
leaseFile,
" filename \"%s\";\n", s);
4470 if (
lease->server_name != NULL) {
4473 fprintf(
leaseFile,
" server-name \"%s\";\n", s);
4482 if (
lease -> medium) {
4485 fprintf (
leaseFile,
" medium \"%s\";\n", s);
4499 memset (&ds, 0,
sizeof ds);
4501 write_options(client,
lease->options,
" ");
4505 fprintf(
leaseFile,
" renew %s\n", tval) < 0)
4510 fprintf(
leaseFile,
" rebind %s\n", tval) < 0)
4515 fprintf(
leaseFile,
" expire %s\n", tval) < 0)
4526 if (!errors && makesure) {
4528 log_info (
"write_client_lease: %m");
4533 return errors ? 0 : 1;
4560 for (sl = client -> env; sl; sl =
next) {
4567 if (client -> interface) {
4569 client -> interface -> name);
4573 "",
"client",
"%s", client -> name);
4576 "",
"medium",
"%s", medium ->
string);
4579 client_envadd (client,
"",
"pid",
"%ld", (
long int)getpid ());
4582 (
long int)dad_wait_time);
4600 in_options, cfg_options, scope, oc,
MDL)) {
4610 length = strlen(value);
4614 value, length) == 0) {
4619 "option - discarded",
4663 if (
lease->next_srv_addr.len != 0) {
4675 memset (&data, 0,
sizeof data);
4706 (&data, (
struct packet *)0,
4707 (
struct lease *)0, client,
4712 if (broadcast.
len) {
4714 prefix,
"broadcast_address",
4715 "%s",
piaddr (broadcast));
4723 if (
lease->filename) {
4726 strlen(
lease->filename)) == 0) {
4728 "%s",
lease->filename);
4731 "option - discarded",
4736 if (
lease->server_name) {
4739 strlen(
lease->server_name)) == 0 ) {
4741 "%s",
lease->server_name);
4744 "option - discarded",
4745 lease->server_name);
4758 (
unsigned long)(
lease -> expiry));
4780 for (i = 0 ; req[i] != NULL ; i++) {
4805 char reason [] =
"REASON=NBI";
4806 static char client_path [] = CLIENT_PATH;
4809 int pid, wpid, wstatus;
4812 scriptName = client -> config -> script_name;
4816 envp =
dmalloc (((client ? client -> envc : 2) +
4819 log_error (
"No memory for client script environment.");
4826 envp [i++] = sp ->
string;
4830 for (sp = client -> env; sp; sp = sp ->
next) {
4831 envp [i++] = sp ->
string;
4834 envp [i++] = reason;
4837 envp [i++] = client_path;
4838 envp [i] = (
char *)0;
4841 argv [1] = (
char *)0;
4849 wpid = wait (&wstatus);
4850 }
while (wpid != pid && wpid > 0);
4867 for (sp = client -> env; sp; sp =
next) {
4875 gettimeofday(&
cur_tv, NULL);
4876 return (WIFEXITED (wstatus) ?
4877 WEXITSTATUS (wstatus) : -WTERMSIG (wstatus));
4881 const char *prefix,
const char *name,
const char *fmt, ...)
4889 va_start (list, fmt);
4890 len = vsnprintf (spbuf,
sizeof spbuf, fmt, list);
4893 val =
dmalloc (strlen (prefix) + strlen (name) + 1 +
4894 len +
sizeof *val,
MDL);
4896 log_error (
"client_envadd: cannot allocate space for variable");
4905 if (len >=
sizeof spbuf) {
4906 va_start (list, fmt);
4907 vsnprintf (s, len + 1, fmt, list);
4913 val ->
next = client -> env;
4914 client -> env = val;
4937 if (j + 1 == buflen)
4947 if (j + 1 == buflen)
4962 if (write(
dfd[1], &ret, 1) != 1)
4964 (void) close(
dfd[1]);
4980 if (
dfd[0] == -1 ||
dfd[1] == -1)
4984 if (write(
dfd[1], &buf, 1) != 1)
4986 (void) close(
dfd[1]);
5001 (void) open(
"/dev/null", O_RDWR | O_CLOEXEC);
5002 (void) open(
"/dev/null", O_RDWR | O_CLOEXEC);
5003 (void) open(
"/dev/null", O_RDWR | O_CLOEXEC);
5021 pfdesc = open (
path_dhclient_pid, O_CREAT | O_TRUNC | O_WRONLY | O_CLOEXEC, 0644);
5028 pf = fdopen (pfdesc,
"we");
5033 fprintf (pf,
"%ld\n", (
long)getpid ());
5044 for (client =
ip -> client; client; client = client ->
next) {
5045 switch (client ->
state) {
5078 #if defined(DHCPv6) && defined(DHCP4o6) 5080 if (dhcp4o6_state < 0)
5088 client -> xid = random ();
5091 if (client -> active) {
5096 memset (&ds, 0,
sizeof ds);
5098 client -> active -> options,
5102 (
struct lease *)0, client,
5104 client -> active -> options,
5107 memcpy (client -> destination.iabuf,
5109 client -> destination.len = 4;
5116 client -> first_sending =
cur_time;
5117 client -> interval = client -> config -> initial_interval;
5128 if (client -> alias)
5144 #if defined(DHCPv6) && defined(DHCP4o6) 5167 interface_reference (&
ip, last ->
next,
MDL);
5168 interface_dereference (&last ->
next,
MDL);
5170 interface_reference (&last ->
next,
5172 interface_dereference (&
ip ->
next,
5177 interface_reference (&
ip,
5183 interface_dereference (&
ip ->
next,
5190 tmp ->
client ->
interface = tmp;
5192 interface_dereference (&
ip,
MDL);
5241 for (client =
ip->client ; client ; client = client->
next) {
5246 return ISC_R_SUCCESS;
5272 static void shutdown_exit (
void *foo)
5280 #if defined (NSUPDATE) 5297 isc_result_t eresult)
5300 isc_result_t result;
5302 if ((eresult == ISC_R_SUCCESS) &&
5308 if (result == ISC_R_SUCCESS) {
5314 dhclient_ddns_cb_free(ddns_cb,
MDL);
5323 isc_result_t result;
5326 if (client->
ddns_cb != NULL) {
5332 if (ddns_cb != NULL) {
5338 ddns_cb->
cur_func = client_dns_remove_action;
5342 if (result != ISC_R_TIMEDOUT) {
5343 dhclient_ddns_cb_free(ddns_cb,
MDL);
5359 return ISC_R_SUCCESS;
5363 log_info(
"Received signal %d, initiating shutdown.",
5372 for (client =
ip -> client; client; client = client -> next) {
5375 return ISC_R_SUCCESS;
5378 return ISC_R_SUCCESS;
5381 if (client -> active &&
5382 client -> active -> expiry >
cur_time) {
5383 #if defined (NSUPDATE) 5405 tv.tv_sec =
cur_tv.tv_sec;
5406 tv.tv_usec =
cur_tv.tv_usec + 1;
5409 return ISC_R_SUCCESS;
5412 #if defined (NSUPDATE) 5423 isc_result_t status = ISC_R_FAILURE;
5425 if ((client != NULL) &&
5426 ((client->
active != NULL) ||
5439 if (status != ISC_R_TIMEDOUT) {
5475 isc_result_t eresult)
5477 isc_result_t result;
5494 ddns_cb->
cur_func = client_dns_update_action;
5497 if (result == ISC_R_SUCCESS) {
5503 case ISC_R_TIMEDOUT:
5511 if (ddns_cb->
zone != NULL) {
5517 ddns_cb->
cur_func = client_dns_update_action;
5523 tv.tv_usec =
cur_tv.tv_usec;
5525 ddns_cb, NULL, NULL);
5529 dhclient_ddns_cb_free(ddns_cb,
MDL);
5547 if (!client -> sent_options)
5548 return ISC_R_SUCCESS;
5552 return ISC_R_SUCCESS;
5558 (
struct lease *)0, client,
5559 client -> sent_options,
5562 return ISC_R_SUCCESS;
5569 (
struct lease *)0, client,
5570 client -> sent_options,
5573 return ISC_R_SUCCESS;
5579 (
struct lease *)0, client,
5580 client -> sent_options,
5583 return ISC_R_SUCCESS;
5595 memset(&client_identifier, 0,
sizeof(client_identifier));
5619 client_identifier.data,
5620 client_identifier.len);
5638 (client_identifier.data[0] == 255)) {
5643 if (client_identifier.len <= 5)
5644 log_fatal(
"Impossible condition at %s:%d.",
5647 client_identifier.data + 5,
5648 client_identifier.len - 5);
5650 result =
get_dhcid(ddns_cb, ddns_v4_type,
5651 client_identifier.data,
5652 client_identifier.len);
5662 return ISC_R_SUCCESS;
5671 rcode = ISC_R_FAILURE;
5677 if (rcode == ISC_R_SUCCESS) {
5678 rcode = ISC_R_TIMEDOUT;
5701 if (client->
ddns_cb != NULL) {
5708 if (ddns_cb != NULL) {
5709 ddns_cb->
lease = (
void *)client;
5722 ddns_cb->
cur_func = client_dns_update_action;
5726 tv.tv_sec =
cur_tv.tv_sec + offset;
5727 tv.tv_usec =
cur_tv.tv_usec;
5729 ddns_cb, NULL, NULL);
5731 log_error(
"Unable to allocate dns update state for %s",
5740 struct servent *ent;
5754 ent = getservbyname(
"dhcpc",
"udp");
5756 ent = getservbyname(
"bootpc",
"udp");
5761 #ifndef __CYGWIN32__ 5785 static int check_domain_name(
const char *ptr,
size_t len,
int dots)
5790 if ((len == 0) || (len > 256))
5795 for (p=ptr; (*p != 0) && (len-- > 0); p++) {
5796 if ((*p ==
'-') || (*p ==
'_')) {
5798 if (((p - ptr) == 0) || (len == 0) || (p[1] ==
'.'))
5800 }
else if (*p ==
'.') {
5804 if ((d <= 0) || (d >= 64))
5807 if ((dots > 0) && (len > 0))
5809 }
else if (isalnum((
unsigned char)*p) == 0) {
5814 return(dots ? -1 : 0);
5817 static int check_domain_name_list(
const char *ptr,
size_t len,
int dots)
5822 if ((ptr == NULL) || (len == 0))
5825 for (p=ptr; (*p != 0) && (len > 0); p++, len--) {
5829 if (check_domain_name(ptr, p - ptr, dots) != 0)
5836 return(check_domain_name(ptr, p - ptr, dots));
5853 #ifdef ACCEPT_LIST_IN_DOMAIN_NAME 5854 return check_domain_name_list(ptr, len, 0);
5856 return check_domain_name(ptr, len, 0);
5861 return check_domain_name(ptr, len, 0);
5864 return check_domain_name_list(ptr, len, 0);
5869 for (; (*ptr != 0) && (len-- > 0); ptr++) {
5870 if(!(isalnum((
unsigned char)*ptr) ||
5871 *ptr ==
'#' || *ptr ==
'%' ||
5872 *ptr ==
'+' || *ptr ==
'-' ||
5873 *ptr ==
'_' || *ptr ==
':' ||
5874 *ptr ==
'.' || *ptr ==
',' ||
5875 *ptr ==
'@' || *ptr ==
'~' ||
5876 *ptr ==
'\\' || *ptr ==
'/' ||
5877 *ptr ==
'[' || *ptr ==
']' ||
5878 *ptr ==
'=' || *ptr ==
' '))
5893 return check_domain_name_list(ptr, len, 0);
5908 log_fatal (
"no memory for reject list!");
5927 log_info(
"Server added to list of rejected servers.");
5936 if (client != NULL) {
5944 #if defined(DHCPv6) && defined(DHCP4o6) 5963 char start_msg[5] = {
'S',
'T',
'A',
'R',
'T' };
5964 char stop_msg[4] = {
'S',
'T',
'O',
'P' };
5965 char poll_msg[4] = {
'P',
'O',
'L',
'L' };
5969 if (h->type != dhcp4o6_type)
5972 cc = recv(dhcp4o6_fd, buf,
sizeof(buf), 0);
5974 return ISC_R_UNEXPECTED;
5978 (memcmp(buf, poll_msg,
sizeof(poll_msg)) == 0)) {
5980 if (dhcp4o6_state < 0)
5981 cc = send(dhcp4o6_fd, stop_msg,
5982 sizeof(stop_msg), 0);
5984 cc = send(dhcp4o6_fd, start_msg,
5985 sizeof(start_msg), 0);
5987 log_error(
"dhcpv4o6_handler: send(): %m");
5988 return ISC_R_IOERROR;
5992 return ISC_R_UNEXPECTED;
5993 memset(&raw, 0,
sizeof(raw));
5996 "no memory buffer.");
5997 return ISC_R_NOMEMORY;
6003 forw_dhcpv4_query(&raw);
6009 (memcmp(buf, stop_msg,
sizeof(stop_msg)) == 0)) {
6011 if (dhcp4o6_state > 0) {
6015 }
else if ((cc == 5) &&
6016 (memcmp(buf, start_msg,
sizeof(start_msg)) == 0)) {
6018 if (dhcp4o6_state == 0)
6024 return ISC_R_UNEXPECTED;
6025 memset(&raw, 0,
sizeof(raw));
6028 "no memory buffer.");
6029 return ISC_R_NOMEMORY;
6035 recv_dhcpv4_response(&raw);
6041 return ISC_R_SUCCESS;
6052 static void dhcp4o6_poll(
void *dummy) {
6053 char msg[4] = {
'P',
'O',
'L',
'L' };
6059 if (dhcp4o6_state < 0)
6064 cc = send(dhcp4o6_fd, msg,
sizeof(msg), 0);
6069 tv.tv_usec = random() % 1000000;
6081 static void dhcp4o6_resume() {
6086 for (client =
ip->client; client != NULL;
6087 client = client->
next) {
6110 char msg[5] = {
'S',
'T',
'A',
'R',
'T' };
6113 memset(&addrs, 0,
sizeof(addrs));
6115 for (client =
ip->client; client != NULL;
6116 client = client->
next) {
6129 lease->options, NULL,
6132 if ((addrs.len % 16) != 0) {
6145 if (dhcp4o6_state == 1)
6147 log_info(
"dhcp4o6_start: go to UP");
6150 cc = send(dhcp4o6_fd, msg,
sizeof(msg), 0);
6152 log_info(
"dhcp4o6_start: send(): %m");
6162 static void dhcp4o6_stop() {
6163 char msg[4] = {
'S',
'T',
'O',
'P' };
6166 if (dhcp4o6_state == -1)
6169 log_info(
"dhcp4o6_stop: go to DOWN");
6172 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)
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)
Calls external script.
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 initialize_client_option_spaces()
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
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 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)
Initializes basic variables for a script.
#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)
#define DHCP_DNS_CLIENT_LAZY_INIT
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)
#define DHCLIENT_DEFAULT_PREFIX_LEN
char * absolute_path(const char *orgpath)
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)
Write out the environent variable the client requested. Write out the environment variables for the o...
#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)
Adds parameters to environment variables for a script.
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