42 #include <dns/result.h> 52 extern int asprintf(
char **strp,
const char *fmt, ...);
83 #define ASSERT_STATE(state_is, state_shouldbe) {} 86 static const char copyright[] =
"Copyright 2004-2017 Internet Systems Consortium.";
87 static const char arr [] =
"All rights reserved.";
88 static const char message [] =
"Internet Systems Consortium DHCP Client";
89 static const char url [] =
"For info, please visit https://www.isc.org/software/dhcp/";
94 #if defined(DHCPv6) && defined(DHCP4o6) 95 int dhcp4o6_state = -1;
121 static isc_result_t write_duid(
struct data_string *duid);
124 static int check_domain_name(
const char *ptr,
size_t len,
int dots);
125 static int check_domain_name_list(
const char *ptr,
size_t len,
int dots);
127 const char *ptr,
size_t len);
148 #if defined(DHCPv6) && defined(DHCP4o6) 149 static void dhcp4o6_poll(
void *dummy);
150 static void dhcp4o6_resume(
void);
151 static void recv_dhcpv4_response(
struct data_string *raw);
152 static int send_dhcpv4_query(
struct client_state *client,
int broadcast);
154 static void dhcp4o6_stop(
void);
155 static void forw_dhcpv4_response(
struct packet *
packet);
156 static void forw_dhcpv4_query(
struct data_string *raw);
163 static const char use_noarg[] =
"No argument for command: %s";
165 static const char use_v6command[] =
"Command not used for DHCPv4: %s";
171 usage(
const char *sfmt,
const char *sarg)
179 #ifdef PRINT_SPECIFIC_CL_ERRORS 187 "[-4|-6] [-SNTPRI1dvrxi] [-nw] -4o6 <port>] [-p <port>]\n" 188 " [-D LL|LLT] [--dad-wait-time seconds]\n" 190 "[-4|-6] [-SNTPRI1dvrxi] [-nw] [-p <port>]\n" 191 " [-D LL|LLT] [--dad-wait-time seconds]\n" 194 "[-I1dvrxi] [-nw] [-p <port>] [-D LL|LLT] \n" 196 " [-s server-addr] [-cf config-file]\n" 197 " [-df duid-file] [-lf lease-file]\n" 198 " [-pf pid-file] [--no-pid] [-e VAR=val]\n" 199 " [-sf script-file] [interface]*\n" 200 " [-C <dhcp-client-identifier>] [-B]\n" 201 " [-H <host-name> | -F <fqdn.fqdn>] [--timeout <timeout>]\n" 202 " [-V <vendor-class-identifier>]\n" 203 " [--request-options <request option list>]",
217 int release_mode = 0;
222 int no_dhclient_conf = 0;
223 int no_dhclient_db = 0;
224 int no_dhclient_pid = 0;
225 int no_dhclient_script = 0;
227 int local_family_set = 0;
229 u_int16_t dhcp4o6_port = 0;
240 char *dhcp_client_identifier_arg = NULL;
241 char *dhcp_host_name_arg = NULL;
242 char *dhcp_fqdn_arg = NULL;
243 char *dhcp_vendor_class_identifier_arg = NULL;
244 char *dhclient_request_options = NULL;
247 char *arg_conf = NULL;
248 int arg_conf_len = 0;
249 #ifdef HAVE_LIBCAP_NG 250 int keep_capabilities = 0;
259 fd = open(
"/dev/null", O_RDWR | O_CLOEXEC);
261 fd = open(
"/dev/null", O_RDWR | O_CLOEXEC);
263 fd = open(
"/dev/null", O_RDWR | O_CLOEXEC);
271 #if !(defined(DEBUG) || defined(__CYGWIN32__)) 272 setlogmask(LOG_UPTO(LOG_INFO));
278 if (status != ISC_R_SUCCESS)
279 log_fatal(
"Can't initialize context: %s",
280 isc_result_totext(status));
284 if (status != ISC_R_SUCCESS)
286 isc_result_totext(status));
296 for (i = 1; i < argc; i++) {
297 if (!strcmp(argv[i],
"-r")) {
301 }
else if (!strcmp(argv[i],
"-4")) {
303 log_fatal(
"Client can only do v4 or v6, not " 305 local_family_set = 1;
307 }
else if (!strcmp(argv[i],
"-6")) {
309 log_fatal(
"Client can only do v4 or v6, not " 311 local_family_set = 1;
314 }
else if (!strcmp(argv[i],
"-4o6")) {
316 usage(use_noarg, argv[i-1]);
319 log_debug(
"DHCPv4 over DHCPv6 over ::1 port %d and %d",
321 ntohs(dhcp4o6_port) + 1);
325 }
else if (!strcmp(argv[i],
"-x")) {
329 }
else if (!strcmp(argv[i],
"-p")) {
331 usage(use_noarg, argv[i-1]);
333 log_debug(
"binding to user-specified port %d",
335 }
else if (!strcmp(argv[i],
"-d")) {
338 }
else if (!strcmp(argv[i],
"-pf")) {
340 usage(use_noarg, argv[i-1]);
343 }
else if (!strcmp(argv[i],
"--no-pid")) {
345 }
else if (!strcmp(argv[i],
"-cf")) {
347 usage(use_noarg, argv[i-1]);
349 no_dhclient_conf = 1;
350 }
else if (!strcmp(argv[i],
"-df")) {
352 usage(use_noarg, argv[i-1]);
354 }
else if (!strcmp(argv[i],
"-lf")) {
356 usage(use_noarg, argv[i-1]);
359 }
else if (!strcmp(argv[i],
"-sf")) {
361 usage(use_noarg, argv[i-1]);
363 no_dhclient_script = 1;
364 }
else if (!strcmp(argv[i],
"-1")) {
366 }
else if (!strcmp(argv[i],
"-q")) {
368 }
else if (!strcmp(argv[i],
"-s")) {
370 usage(use_noarg, argv[i-1]);
372 }
else if (!strcmp(argv[i],
"-g")) {
374 usage(use_noarg, argv[i-1]);
376 }
else if (!strcmp(argv[i],
"-nw")) {
378 }
else if (!strcmp(argv[i],
"-n")) {
381 }
else if (!strcmp(argv[i],
"-w")) {
384 }
else if (!strcmp(argv[i],
"-e")) {
387 usage(use_noarg, argv[i-1]);
388 tmp =
dmalloc(strlen(argv[i]) +
sizeof *tmp,
MDL);
391 strcpy(tmp->
string, argv[i]);
396 }
else if (!strcmp(argv[i],
"-S")) {
398 usage(use_v6command, argv[i]);
400 local_family_set = 1;
404 }
else if (!strcmp(argv[i],
"-N")) {
406 usage(use_v6command, argv[i]);
408 local_family_set = 1;
414 }
else if (!strcmp(argv[i],
"-T")) {
416 usage(use_v6command, argv[i]);
418 local_family_set = 1;
424 }
else if (!strcmp(argv[i],
"-P")) {
426 usage(use_v6command, argv[i]);
428 local_family_set = 1;
434 }
else if (!strcmp(argv[i],
"-R")) {
436 usage(use_v6command, argv[i]);
438 local_family_set = 1;
441 }
else if (!strcmp(argv[i],
"--dad-wait-time")) {
443 usage(use_noarg, argv[i-1]);
447 usage(
"Invalid value for --dad-wait-time: %s", argv[i]);
451 }
else if (!strcmp(argv[i],
"-D")) {
454 usage(use_noarg, argv[i-1]);
455 if (!strcasecmp(argv[i],
"LL")) {
457 }
else if (!strcasecmp(argv[i],
"LLT")) {
460 usage(
"Unknown argument to -D: %s", argv[i]);
462 }
else if (!strcmp(argv[i],
"-i")) {
465 }
else if (!strcmp(argv[i],
"-I")) {
468 }
else if (!strcmp(argv[i],
"-v")) {
470 }
else if (!strcmp(argv[i],
"--version")) {
471 const char vstring[] =
"isc-dhclient-";
479 }
else if (!strcmp(argv[i],
"-C")) {
480 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
481 usage(use_noarg, argv[i-1]);
490 dhcp_client_identifier_arg = argv[i];
491 }
else if (!strcmp(argv[i],
"-B")) {
493 }
else if (!strcmp(argv[i],
"-H")) {
494 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
495 usage(use_noarg, argv[i-1]);
504 if (dhcp_host_name_arg != NULL) {
505 log_error(
"The -H <host-name> and -F <fqdn> arguments are mutually exclusive");
509 dhcp_host_name_arg = argv[i];
510 }
else if (!strcmp(argv[i],
"-F")) {
511 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
512 usage(use_noarg, argv[i-1]);
521 if (dhcp_fqdn_arg != NULL) {
522 log_error(
"Only one -F <fqdn> argument can be specified");
526 if (dhcp_host_name_arg != NULL) {
527 log_error(
"The -F <fqdn> and -H <host-name> arguments are mutually exclusive");
531 dhcp_fqdn_arg = argv[i];
532 }
else if (!strcmp(argv[i],
"--timeout")) {
533 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
534 usage(use_noarg, argv[i-1]);
538 if ((timeout_arg = atoi(argv[i])) <= 0) {
539 log_error(
"timeout option must be > 0 - bad value: %s",argv[i]);
542 }
else if (!strcmp(argv[i],
"-V")) {
543 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
544 usage(use_noarg, argv[i-1]);
553 dhcp_vendor_class_identifier_arg = argv[i];
554 }
else if (!strcmp(argv[i],
"--request-options")) {
555 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
556 usage(use_noarg, argv[i-1]);
560 dhclient_request_options = argv[i];
561 }
else if (!strcmp(argv[i],
"-nc")) {
562 #ifdef HAVE_LIBCAP_NG 563 keep_capabilities = 1;
565 }
else if (argv[i][0] ==
'-') {
566 usage(
"Unknown command: %s", argv[i]);
568 usage(
"No interfaces comamnd -n and " 569 " requested interface %s", argv[i]);
573 status = interface_allocate(&tmp,
MDL);
574 if (status != ISC_R_SUCCESS)
575 log_fatal(
"Can't record interface %s:%s",
576 argv[i], isc_result_totext(status));
577 if (strlen(argv[i]) >=
sizeof(tmp->
name))
578 log_fatal(
"%s: interface name too long (is %ld)",
579 argv[i], (
long)strlen(argv[i]));
580 strcpy(tmp->
name, argv[i]);
582 interface_reference(&tmp->
next,
598 usage(
"PD %s only supports one requested interface",
"-P");
601 #if defined(DHCPv6) && defined(DHCP4o6) 603 (exit_mode || release_mode))
604 log_error(
"Can't relay DHCPv4-over-DHCPv6 " 605 "without a persistent DHCPv6 client");
608 log_fatal(
"DHCPv4-over-DHCPv6 requires an explicit " 609 "interface on which to be applied");
612 if (!no_dhclient_conf && (s = getenv(
"PATH_DHCLIENT_CONF"))) {
615 if (!no_dhclient_db && (s = getenv(
"PATH_DHCLIENT_DB"))) {
618 if (!no_dhclient_pid && (s = getenv(
"PATH_DHCLIENT_PID"))) {
621 if (!no_dhclient_script && (s = getenv(
"PATH_DHCLIENT_SCRIPT"))) {
625 #ifdef HAVE_LIBCAP_NG 627 if (!keep_capabilities) {
628 capng_clear(CAPNG_SELECT_CAPS);
629 capng_update(CAPNG_ADD, CAPNG_EFFECTIVE|CAPNG_PERMITTED,
631 capng_updatev(CAPNG_ADD, CAPNG_EFFECTIVE|CAPNG_PERMITTED,
632 CAP_NET_ADMIN, CAP_NET_RAW,
633 CAP_NET_BIND_SERVICE, CAP_SYS_ADMIN, -1);
634 capng_apply(CAPNG_SELECT_CAPS);
659 log_fatal(
"Failed to get realpath for %s: %s", old_path, strerror(errno));
666 log_fatal(
"Failed to get realpath for %s: %s", old_path, strerror(errno));
675 if ((release_mode || exit_mode) && (
no_pid_file == ISC_FALSE)) {
682 e = fscanf(pidfd,
"%ld\n", &temp);
683 oldpid = (pid_t)temp;
685 if (e != 0 && e != EOF && oldpid) {
686 if (kill(oldpid, SIGTERM) == 0) {
687 log_info(
"Killed old client process");
697 }
else if (errno == ESRCH) {
711 char *new_path_dhclient_pid;
730 int n_len = strlen(
ip->name);
732 new_path_dhclient_pid = (
char*) malloc(pfx + n_len + 6);
734 sprintf(new_path_dhclient_pid + pfx,
"-%s.pid",
ip->name);
736 if ((pidfd = fopen(new_path_dhclient_pid,
"re")) != NULL) {
737 e = fscanf(pidfd,
"%ld\n", &temp);
738 oldpid = (pid_t)temp;
740 if (e != 0 && e != EOF) {
742 if (kill(oldpid, SIGTERM) == 0)
750 free(new_path_dhclient_pid);
759 char procfn[256] =
"";
762 if ((fscanf(pidfp,
"%ld", &temp)==1) && ((dhcpid=(pid_t)temp) > 0)) {
763 snprintf(procfn,256,
"/proc/%u",dhcpid);
764 dhc_running = (access(procfn, F_OK) == 0);
771 log_fatal(
"dhclient(%u) is already running - exiting. ", dhcpid);
796 memcpy(&
giaddr, he->h_addr_list[0],
805 gettimeofday(&
cur_tv, NULL);
812 he = gethostbyname(server);
838 usage(
"Stateless commnad: %s incompatibile with " 839 "other commands",
"-S");
841 #if defined(DHCPv6) && defined(DHCP4o6) 850 if ((dhcp_client_identifier_arg != NULL) && (*dhcp_client_identifier_arg !=
'\0')) {
851 arg_conf_len =
asprintf(&arg_conf,
"send dhcp-client-identifier \"%s\";", dhcp_client_identifier_arg);
853 if ((arg_conf == 0) || (arg_conf_len <= 0))
854 log_fatal(
"Unable to send -C option dhcp-client-identifier");
857 if ((dhcp_host_name_arg != NULL) && (*dhcp_host_name_arg !=
'\0')) {
859 arg_conf_len =
asprintf(&arg_conf,
"send host-name \"%s\";", dhcp_host_name_arg);
861 if ((arg_conf == 0) || (arg_conf_len <= 0))
862 log_fatal(
"Unable to send -H option host-name");
864 char *last_arg_conf = arg_conf;
866 arg_conf_len =
asprintf(&arg_conf,
"%s\nsend host-name \"%s\";", last_arg_conf, dhcp_host_name_arg);
868 if ((arg_conf == 0) || (arg_conf_len <= 0))
869 log_fatal(
"Unable to send -H option host-name");
875 if ((dhcp_fqdn_arg != NULL) && (*dhcp_fqdn_arg !=
'\0')) {
877 arg_conf_len =
asprintf(&arg_conf,
"send fqdn.fqdn \"%s\";", dhcp_fqdn_arg);
879 if ((arg_conf == 0) || (arg_conf_len <= 0))
880 log_fatal(
"Unable to send -F option fqdn.fqdn");
882 char *last_arg_conf = arg_conf;
884 arg_conf_len =
asprintf(&arg_conf,
"%s\nsend fqdn.fqdn \"%s\";", last_arg_conf, dhcp_fqdn_arg);
886 if ((arg_conf == 0) || (arg_conf_len <= 0))
887 log_fatal(
"Unable to send -F option fqdn.fqdn");
895 arg_conf_len =
asprintf(&arg_conf,
"timeout %d;", timeout_arg);
897 if ((arg_conf == 0) || (arg_conf_len <= 0))
898 log_fatal(
"Unable to process --timeout timeout argument");
900 char *last_arg_conf = arg_conf;
902 arg_conf_len =
asprintf(&arg_conf,
"%s\ntimeout %d;", last_arg_conf, timeout_arg);
904 if ((arg_conf == 0) || (arg_conf_len == 0))
905 log_fatal(
"Unable to process --timeout timeout argument");
911 if ((dhcp_vendor_class_identifier_arg != NULL) && (*dhcp_vendor_class_identifier_arg !=
'\0')) {
913 arg_conf_len =
asprintf(&arg_conf,
"send vendor-class-identifier \"%s\";", dhcp_vendor_class_identifier_arg);
915 if ((arg_conf == 0) || (arg_conf_len <= 0))
916 log_fatal(
"Unable to send -V option vendor-class-identifier");
918 char *last_arg_conf = arg_conf;
920 arg_conf_len =
asprintf(&arg_conf,
"%s\nsend vendor-class-identifier \"%s\";", last_arg_conf, dhcp_vendor_class_identifier_arg);
922 if ((arg_conf == 0) || (arg_conf_len <= 0))
923 log_fatal(
"Unable to send -V option vendor-class-identifier");
929 if (dhclient_request_options != NULL) {
931 arg_conf_len =
asprintf(&arg_conf,
"request %s;", dhclient_request_options);
933 if ((arg_conf == 0) || (arg_conf_len <= 0))
934 log_fatal(
"Unable to parse --request-options <request options list> argument");
936 char *last_arg_conf = arg_conf;
938 arg_conf_len =
asprintf(&arg_conf,
"%s\nrequest %s;", last_arg_conf, dhclient_request_options);
940 if ((arg_conf == 0) || (arg_conf_len <= 0))
941 log_fatal(
"Unable to parse --request-options <request options list> argument");
948 if (arg_conf_len == 0)
949 if ((arg_conf_len = strlen(arg_conf)) == 0)
951 log_fatal(
"Unable to process -C/-H/-F/--timeout/-V/--request-options configuration arguments");
956 const char *val = NULL;
959 status =
new_parse(&cfile, -1, arg_conf, arg_conf_len,
"extra dhclient -C/-H/-F/--timeout/-V/--request-options configuration arguments", 0);
962 log_fatal(
"Cannot parse -C/-H/-F/--timeout/-V/--request-options configuration arguments !");
974 log_fatal(
"Cannot parse -C/-H/-F/--timeout/-V/--request-options configuration arguments !");
982 if (
ip->client->config->timeout == 60)
983 ip->client->config->timeout = timeout_arg;
1031 log_info(
"No broadcast interfaces found - exiting.");
1034 }
else if (!release_mode && !exit_mode) {
1051 if (
ip->client->alias != NULL)
1068 unsigned backup_seed = 0;
1071 if (
ip -> hw_address.hlen <=
sizeof seed )
1074 &
ip -> hw_address.hbuf [
ip -> hw_address.hlen -
1075 sizeof seed],
sizeof seed);
1097 if (
ip -> hw_address.hlen <=
sizeof seed )
1100 &
ip->hw_address.hbuf[
ip->hw_address.hlen -
1101 sizeof seed],
sizeof seed);
1105 if ( seed_flag == 0 ) {
1106 if ( backup_seed != 0 ) {
1108 log_info (
"xid: rand init seed (0x%x) built using all" 1109 " available interfaces",seed);
1112 seed =
cur_time^((unsigned) gethostid()) ;
1113 log_info (
"xid: warning: no netdev with useable HWADDR found" 1114 " for seed's uniqueness enforcement");
1115 log_info (
"xid: rand init seed (0x%x) built using gethostid",
1120 srandom(seed + ((
unsigned)(
cur_tv.tv_usec * 1000000)) + (
unsigned)getpid());
1123 srandom(seed + ((
unsigned)(
cur_tv.tv_usec * 1000000)) + (
unsigned)getpid());
1129 setup_ib_interface(
ip);
1148 #if defined(DHCPv6) && defined(DHCP4o6) 1150 dhcp4o6_setup(dhcp4o6_port);
1157 for (client =
ip->client ; client != NULL ;
1158 client = client->
next) {
1162 }
else if (exit_mode) {
1182 for (client =
ip->client ; client ;
1183 client = client->
next) {
1200 tv.tv_usec = random()
1235 if (result != ISC_R_SUCCESS)
1236 log_fatal(
"Can't allocate new generic object: %s\n",
1237 isc_result_totext(result));
1242 if (result != ISC_R_SUCCESS)
1243 log_fatal(
"Can't start OMAPI protocol: %s",
1244 isc_result_totext (result));
1253 #if defined(DEBUG_MEMORY_LEAKAGE) || defined(DEBUG_MALLOC_POOL) || \ 1254 defined(DEBUG_MEMORY_LEAKAGE_ON_EXIT) 1255 dmalloc_cutoff_generation = dmalloc_generation;
1256 dmalloc_longterm = dmalloc_outstanding;
1257 dmalloc_outstanding = 0;
1260 #if defined(ENABLE_GENTLE_SHUTDOWN) 1297 isc_result_t result;
1306 usage(
"No interfaces available for stateless command: %s",
"-S");
1349 dhcp4o6_setup(port);
1369 if (result != ISC_R_SUCCESS)
1370 log_fatal(
"Can't allocate new generic object: %s\n",
1371 isc_result_totext(result));
1376 if (result != ISC_R_SUCCESS)
1377 log_fatal(
"Can't start OMAPI protocol: %s",
1378 isc_result_totext(result));
1384 #if defined(DEBUG_MEMORY_LEAKAGE) || defined(DEBUG_MALLOC_POOL) || \ 1385 defined(DEBUG_MEMORY_LEAKAGE_ON_EXIT) 1386 dmalloc_cutoff_generation = dmalloc_generation;
1387 dmalloc_longterm = dmalloc_outstanding;
1388 dmalloc_outstanding = 0;
1410 const char *s,
const char *
file,
int line)
1445 ip->client->config->bootp_broadcast_always = 1;
1451 for (g =
ip->client->config->on_transmission; g != NULL; g = g->
next) {
1454 "dhcp-client-identifier") == 0)) {
1497 #if defined(DHCPv6) && defined(DHCP4o6) 1499 if (dhcp4o6_state < 0)
1510 client ->
active -> is_bootp ||
1524 client ->
xid = random ();
1557 client -> xid = client ->
packet.xid;
1560 client -> first_sending =
cur_time;
1561 client -> interval = client -> config -> initial_interval;
1604 for (lp = client -> offered_leases; lp; lp =
next) {
1613 picked ->
next = NULL;
1618 client -> offered_leases = NULL;
1625 client -> state =
S_INIT;
1632 client ->
new = picked;
1650 client -> first_sending =
cur_time;
1651 client -> interval = client -> config -> initial_interval;
1655 client -> xid = client ->
packet.xid;
1678 for (client =
ip -> client; client; client = client -> next) {
1679 if (client -> xid ==
packet -> raw -> xid)
1683 (
packet -> interface -> hw_address.hlen - 1 !=
1684 packet -> raw -> hlen) ||
1685 (memcmp (&
packet -> interface -> hw_address.hbuf [1],
1688 log_debug (
"DHCPACK in wrong transaction.");
1707 log_info (
"packet_to_lease failed.");
1711 client ->
new =
lease;
1719 memset (&ds, 0,
sizeof ds);
1722 packet -> options, client ->
new -> options,
1727 client ->
new -> expiry = 0;
1730 client ->
new -> expiry = 0;
1735 log_error (
"no expiry time on offered lease.");
1741 tv.tv_sec =
cur_tv.tv_sec;
1742 tv.tv_usec =
cur_tv.tv_usec + 500000;
1744 if (tv.tv_usec >= 1000000) {
1746 tv.tv_usec -= 1000000;
1765 packet -> options, client ->
new -> options,
1770 client ->
new -> renewal = 0;
1773 client ->
new -> renewal = 0;
1781 if (!client ->
new -> renewal ||
1782 client ->
new -> renewal > client ->
new -> expiry)
1783 client ->
new -> renewal = client ->
new -> expiry / 2 + 1;
1785 if (client ->
new -> renewal <= 0)
1786 client ->
new -> renewal =
TIME_MAX;
1791 (((random() % client->
new->
renewal) + 3) / 4);
1798 packet -> options, client ->
new -> options,
1803 client ->
new -> rebind = 0;
1806 client ->
new -> rebind = 0;
1809 if (client ->
new -> rebind <= 0 ||
1810 client ->
new -> rebind > client ->
new -> expiry) {
1811 if (client ->
new -> expiry <=
TIME_MAX / 7)
1812 client ->
new -> rebind =
1813 client ->
new -> expiry * 7 / 8;
1815 client ->
new -> rebind =
1816 client ->
new -> expiry / 8 * 7;
1821 if (client ->
new -> renewal > client ->
new -> rebind) {
1822 if (client ->
new -> rebind <=
TIME_MAX / 3)
1823 client ->
new -> renewal =
1824 client ->
new -> rebind * 3 / 4;
1826 client ->
new -> renewal =
1827 client ->
new -> rebind / 4 * 3;
1830 client ->
new -> expiry +=
cur_time;
1832 if (client ->
new -> expiry <
cur_time)
1833 client ->
new -> expiry =
TIME_MAX;
1834 client ->
new -> renewal +=
cur_time;
1835 if (client ->
new -> renewal <
cur_time)
1836 client ->
new -> renewal =
TIME_MAX;
1837 client ->
new -> rebind +=
cur_time;
1838 if (client ->
new -> rebind <
cur_time)
1839 client ->
new -> rebind =
TIME_MAX;
1875 log_info(
"Unable to obtain a lease on first " 1876 "try (declined). Exiting.");
1879 #if defined (CALL_SCRIPT_ON_ONETRY_FAIL) 1906 random() % 1000000 :
cur_tv.tv_usec;
1909 log_info(
"bound to %s -- renewal in %ld seconds.",
1915 #if defined (NSUPDATE) 1937 client -> xid = client ->
packet.xid;
1939 memset (&ds, 0,
sizeof ds);
1945 client -> active -> options,
1948 memcpy (client -> destination.iabuf, ds.
data, 4);
1949 client -> destination.len = 4;
1957 client -> first_sending =
cur_time;
1958 client -> interval = client -> config -> initial_interval;
2026 for (ap =
packet -> interface -> client -> config -> reject_list;
2027 ap; ap = ap ->
next) {
2036 log_info(
"BOOTREPLY from %s rejected by rule %s " 2051 void (*handler) (
struct packet *);
2079 ap; ap = ap -> next) {
2088 log_info(
"%s from %s rejected by rule %s mask %s.",
2102 char addrbuf[
sizeof(
"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")];
2110 ap ; ap = ap->
next) {
2113 log_info(
"%s from %s rejected by rule %s",
2126 log_info(
"RCV: %s message on %s from %s.",
2130 forw_dhcpv4_response(
packet);
2140 log_info(
"RCV: %s message on %s from %s.",
2151 client = client->
next) {
2160 log_info(
"Packet received, but nothing done with it.");
2176 static void forw_dhcpv4_response(
struct packet *
packet)
2186 if (dhcp4o6_state == -1) {
2187 log_info(
"forw_dhcpv4_response: not ready.");
2192 log_error(
"forw_dhcpv4_response: bad address");
2201 log_info(
"DHCPv4-response from %s missing " 2202 "DHCPv4 Message option.",
2207 memset(&enc_opt_data, 0,
sizeof(enc_opt_data));
2210 log_error(
"forw_dhcpv4_response: error evaluating " 2218 "no memory for encapsulated packet.");
2226 memset(&ds, 0,
sizeof(ds));
2228 log_error(
"forw_dhcpv4_response: no memory buffer.");
2232 ds.data = ds.buffer->data;
2233 ds.len = enc_opt_data.len + 16;
2234 memcpy(ds.buffer->data, enc_opt_data.data, enc_opt_data.len);
2235 memcpy(ds.buffer->data + enc_opt_data.len,
2242 cc = send(dhcp4o6_fd, ds.data, ds.len, 0);
2244 log_error(
"forw_dhcpv4_response: send(): %m");
2258 static void recv_dhcpv4_response(
struct data_string *raw)
2264 log_error(
"recv_dhcpv4_response: no interfaces.");
2269 memcpy(from.iabuf, raw->
data + (raw->
len - 16), 16);
2276 log_error(
"recv_dhcpv4_response: no memory for packet.");
2288 log_error(
"recv_dhcpv4_response: no memory for options.");
2309 memset(&dp, 0,
sizeof dp);
2343 const char *
name =
packet -> packet_type ?
"DHCPOFFER" :
"BOOTREPLY";
2352 for (client =
ip -> client; client; client = client -> next)
2353 if (client -> xid ==
packet -> raw -> xid)
2360 (
packet -> interface -> hw_address.hlen - 1 !=
2361 packet -> raw -> hlen) ||
2362 (memcmp (&
packet -> interface -> hw_address.hbuf [1],
2365 log_debug (
"%s in wrong transaction.", name);
2370 sprintf (obuf,
"%s from %s", name,
piaddr (
packet -> client_addr));
2378 for (i = 0 ; req[i] != NULL ; i++) {
2385 option_code_hash_lookup(&
option,
2390 log_info(
"%s: no %s option.", obuf,
2393 log_info(
"%s: no unknown-%u option.",
2405 if (
lease -> address.len ==
sizeof packet -> raw -> yiaddr &&
2406 !memcmp (
lease -> address.iabuf,
2407 &
packet -> raw -> yiaddr,
lease -> address.len)) {
2415 log_info (
"%s: packet_to_lease failed.", obuf);
2421 if (!
packet -> options_valid || !
packet -> packet_type)
2422 lease -> is_bootp = 1;
2425 lease -> medium = client -> medium;
2428 stop_selecting = (client -> first_sending +
2429 client -> config -> select_interval);
2433 if (
lease -> address.len == client -> requested_address.len &&
2434 !memcmp (
lease -> address.iabuf,
2435 client -> requested_address.iabuf,
2436 client -> requested_address.len)) {
2437 lease -> next = client -> offered_leases;
2438 client -> offered_leases =
lease;
2442 if (!client -> offered_leases)
2443 client -> offered_leases =
lease;
2445 for (lp = client -> offered_leases; lp ->
next;
2455 if (stop_selecting <=
cur_tv.tv_sec)
2458 tv.tv_sec = stop_selecting;
2459 tv.tv_usec =
cur_tv.tv_usec;
2482 log_error(
"packet_to_lease: no memory to record lease.\n");
2493 lease->address.len);
2497 lease->next_srv_addr.len);
2499 memset(&data, 0,
sizeof(data));
2501 if (client -> config -> vendor_space_name) {
2507 client -> config -> vendor_space_name &&
2509 (
struct lease *)0, client,
2513 if (!option_code_hash_lookup(&
option,
2517 "option (%s:%d).",
MDL);
2521 client -> config -> vendor_space_name
2547 if (!(i & 2) &&
packet -> raw -> sname [0]) {
2551 if (!
packet -> raw -> sname [len])
2555 log_error (
"dhcpoffer: no memory for server name.\n");
2560 packet -> raw -> sname, len);
2574 log_error (
"dhcpoffer: no memory for filename.\n");
2599 for (client =
ip -> client; client; client = client ->
next)
2607 packet -> raw -> hlen) ||
2611 log_debug (
"DHCPNAK in wrong transaction.");
2630 log_info (
"DHCPNAK with no active lease.\n");
2663 client -> state =
S_INIT;
2682 interval =
cur_time - client -> first_sending;
2686 if (interval > client -> config ->
timeout) {
2694 if (!client -> offered_leases &&
2695 client -> config -> media) {
2698 if (client -> medium) {
2699 client -> medium = client -> medium -> next;
2702 if (!client -> medium) {
2704 log_fatal (
"No valid media types for %s!",
2705 client -> interface -> name);
2707 client -> config -> media;
2711 log_info (
"Trying medium \"%s\" %d",
2712 client -> medium ->
string, increase);
2740 if (
cur_time + client -> interval >
2741 client -> first_sending + client -> config ->
timeout)
2742 client -> interval =
2743 (client -> first_sending +
2747 if (interval < 65536)
2748 client ->
packet.secs = htons (interval);
2750 client ->
packet.secs = htons (65535);
2751 client -> secs = client ->
packet.secs;
2753 #if defined(DHCPv6) && defined(DHCP4o6) 2755 log_info (
"DHCPDISCOVER interval %ld",
2756 (
long)(client -> interval));
2759 log_info (
"DHCPDISCOVER on %s to %s port %d interval %ld (xid=0x%x)",
2760 client -> name ? client -> name : client -> interface -> name,
2762 ntohs (
sockaddr_broadcast.sin_port), (
long)(client -> interval), ntohl(client -> xid));
2765 #if defined(DHCPv6) && defined(DHCP4o6) 2767 result = send_dhcpv4_query(client, 1);
2774 #if defined(DHCPv6) && defined(DHCP4o6) 2776 log_error(
"%s:%d: Failed to send %d byte long packet.",
2780 log_error(
"%s:%d: Failed to send %d byte long packet over %s " 2792 tv.tv_usec = client->
interval > 1 ? random() % 1000000 :
cur_tv.tv_usec;
2809 loop = lp = client -> active;
2811 log_info (
"No DHCPOFFERS received.");
2815 if (!client -> active && client -> leases)
2819 while (client -> active) {
2820 if (client -> active -> expiry >
cur_time) {
2821 log_info (
"Trying recorded lease %s",
2822 piaddr (client -> active -> address));
2826 client -> active -> medium);
2829 if (client -> alias)
2837 if (cur_time < client -> active -> renewal) {
2839 log_info (
"bound: renewal in %ld %s.",
2840 (
long)(client -> active -> renewal -
2845 random() % 1000000 :
2850 log_info (
"bound: immediate renewal.");
2860 if (!client -> leases) {
2861 client -> leases = client -> active;
2869 for (lp = client -> leases; lp ->
next; lp = lp ->
next)
2871 lp ->
next = client -> active;
2875 client -> active = client -> leases;
2876 client -> leases = client -> leases ->
next;
2881 if (client -> active == loop)
2884 loop = client -> active;
2892 log_info (
"Unable to obtain a lease on first try.%s",
2896 #if defined (CALL_SCRIPT_ON_ONETRY_FAIL) 2904 log_info (
"No working leases in persistent database - sleeping.");
2906 if (client -> alias)
2909 client -> state =
S_INIT;
2912 tv.tv_usec = ((tv.tv_sec -
cur_tv.tv_sec) > 1) ?
2913 random() % 1000000 :
cur_tv.tv_usec;
2925 struct sockaddr_in destination;
2926 struct in_addr from;
2930 interval =
cur_time - client -> first_sending;
2944 interval > client -> config -> reboot_timeout) {
2946 client -> state =
S_INIT;
2955 !client -> medium &&
2956 client -> active -> medium ) {
2957 script_init(client,
"MEDIUM", client -> active -> medium);
2964 client -> medium = client -> active -> medium;
2970 cur_time > client -> active -> expiry) {
2975 if (client -> alias)
2983 if (client -> alias)
2988 client -> state =
S_INIT;
2994 if (!client -> interval)
2995 client -> interval = client -> config -> initial_interval;
2997 client -> interval += ((random () >> 2) %
2998 (2 * client -> interval));
3002 if (client -> interval >
3003 client -> config -> backoff_cutoff)
3004 client -> interval =
3005 ((client -> config -> backoff_cutoff / 2)
3006 + ((random () >> 2) %
3007 client -> config -> backoff_cutoff));
3012 cur_time + client -> interval > client -> active -> expiry)
3013 client -> interval =
3014 client -> active -> expiry -
cur_time + 1;
3020 cur_time > client -> active -> rebind)
3023 memcpy (&destination.sin_addr.s_addr,
3024 client -> destination.iabuf,
3025 sizeof destination.sin_addr.s_addr);
3027 destination.sin_family = AF_INET;
3029 destination.sin_len =
sizeof destination;
3034 memcpy (&from, client -> active -> address.iabuf,
3037 from.s_addr = INADDR_ANY;
3041 client ->
packet.secs = client -> secs;
3043 if (interval < 65536)
3044 client ->
packet.secs = htons (interval);
3046 client ->
packet.secs = htons (65535);
3049 #if defined(DHCPv6) && defined(DHCP4o6) 3054 log_info (
"DHCPREQUEST on %s to %s port %d (xid=0x%x)",
3055 client -> name ? client -> name : client -> interface -> name,
3056 inet_ntoa (destination.sin_addr),
3057 ntohs (destination.sin_port), ntohl(client -> xid));
3059 #if defined(DHCPv6) && defined(DHCP4o6) 3062 if (destination.sin_addr.s_addr == INADDR_BROADCAST)
3064 result = send_dhcpv4_query(client, broadcast);
3066 log_error(
"%s:%d: Failed to send %d byte long packet.",
3071 if (destination.sin_addr.s_addr != INADDR_BROADCAST &&
3073 #if defined(SO_BINDTODEVICE) 3077 log_error(
"%s:%d: Failed to bind fallback interface" 3085 log_error(
"%s:%d: Failed to send %d byte long packet " 3086 "over %s interface.",
MDL,
3090 #if defined(SO_BINDTODEVICE) 3092 SO_BINDTODEVICE, NULL, 0) < 0) {
3093 log_fatal(
"%s:%d: Failed to unbind fallback interface:" 3104 log_error(
"%s:%d: Failed to send %d byte long packet" 3105 " over %s interface.",
MDL,
3112 tv.tv_usec = ((tv.tv_sec -
cur_tv.tv_sec) > 1) ?
3113 random() % 1000000 :
cur_tv.tv_usec;
3124 #if defined(DHCPv6) && defined(DHCP4o6) 3129 log_info (
"DHCPDECLINE on %s to %s port %d (xid=0x%x)",
3135 #if defined(DHCPv6) && defined(DHCP4o6) 3137 result = send_dhcpv4_query(client, 1);
3144 #if defined(DHCPv6) && defined(DHCP4o6) 3146 log_error(
"%s:%d: Failed to send %d byte long packet.",
3150 log_error(
"%s:%d: Failed to send %d byte long packet over %s" 3162 struct sockaddr_in destination;
3163 struct in_addr from;
3165 memcpy (&from, client -> active -> address.iabuf,
3167 memcpy (&destination.sin_addr.s_addr,
3168 client -> destination.iabuf,
3169 sizeof destination.sin_addr.s_addr);
3171 destination.sin_family = AF_INET;
3173 destination.sin_len =
sizeof destination;
3178 client -> active -> expiry =
3179 client -> active -> renewal =
3180 client -> active -> rebind =
cur_time;
3182 log_error (
"Can't release lease: lease write failed.");
3186 #if defined(DHCPv6) && defined(DHCP4o6) 3191 log_info (
"DHCPRELEASE on %s to %s port %d (xid=0x%x)",
3192 client -> name ? client -> name : client -> interface -> name,
3193 inet_ntoa (destination.sin_addr),
3194 ntohs (destination.sin_port), ntohl(client -> xid));
3196 #if defined(DHCPv6) && defined(DHCP4o6) 3199 if (destination.sin_addr.s_addr == INADDR_BROADCAST)
3201 result = send_dhcpv4_query(client, broadcast);
3203 log_error(
"%s:%d: Failed to send %d byte long packet.",
3209 #if defined(SO_BINDTODEVICE) 3213 log_error(
"%s:%d: Failed to bind fallback interface" 3221 log_error(
"%s:%d: Failed to send %d byte long packet" 3222 " over %s interface.",
MDL,
3226 #if defined(SO_BINDTODEVICE) 3228 SO_BINDTODEVICE, NULL, 0) < 0) {
3229 log_fatal(
"%s:%d: Failed to unbind fallback interface:" 3239 log_error (
"%s:%d: Failed to send %d byte long packet" 3240 " over %s interface.",
MDL,
3248 #if defined(DHCPv6) && defined(DHCP4o6) 3260 static int send_dhcpv4_query(
struct client_state *client,
int broadcast) {
3265 if (dhcp4o6_state <= 0) {
3266 log_info(
"send_dhcpv4_query: not ready.");
3276 memset(&ds, 0,
sizeof(ds));
3278 log_error(
"Unable to allocate memory for DHCPv4-query.");
3281 ds.data = ds.buffer->data;
3306 cc = send(dhcp4o6_fd, ds.data, ds.len, 0);
3308 log_error(
"send_dhcpv4_query: send(): %m");
3321 static void forw_dhcpv4_query(
struct data_string *raw) {
3327 struct sockaddr_in6 sin6;
3328 int i, send_ret, attempt, success;
3330 attempt = success = 0;
3331 memset(&sin6, 0,
sizeof(sin6));
3332 sin6.sin6_family = AF_INET6;
3335 sin6.sin6_len =
sizeof(sin6);
3337 memset(&addrs, 0,
sizeof(addrs));
3339 for (client =
ip->client; client != NULL;
3340 client = client->
next) {
3353 lease->options, NULL,
3355 ((addrs.len %
sizeof(sin6.sin6_addr)) != 0)) {
3359 if (addrs.len == 0) {
3367 if (send_ret == raw->
len)
3371 for (i = 0; i < addrs.len;
3372 i +=
sizeof(sin6.sin6_addr)) {
3373 memcpy(&sin6.sin6_addr, addrs.data + i,
3374 sizeof(sin6.sin6_addr));
3378 if (send_ret == raw->
len)
3385 log_info(
"forw_dhcpv4_query: sent(%d): %d/%d",
3386 raw->
len, success, attempt);
3402 struct buffer *bp = NULL;
3425 log_error (
"can't make requested address cache.");
3451 for (i = 0 ; prl[i] != NULL ; i++)
3456 log_error(
"can't make parameter list buffer.");
3461 for (i = 0 ; prl[i] != NULL ; i++)
3465 if (!(option_code_hash_lookup(&
option,
3490 memset(&client_identifier, 0,
sizeof(client_identifier));
3493 client_identifier.
len,
MDL))
3494 log_fatal(
"no memory for default DUID!");
3512 memcpy(&client_identifier.
buffer->
data + 5 - hw_len,
3517 memcpy(&client_identifier.
buffer->
data+(1+4),
3524 (u_int8_t *)client_identifier.
data,
3525 client_identifier.
len,
3527 log_error (
"can't make requested client id cache..");
3551 memset (&client ->
packet, 0,
sizeof (client ->
packet));
3556 client -> config -> requested_options,
3560 client -> packet_length =
3562 (
struct lease *)0, client,
3571 client -> config -> vendor_space_name);
3578 client ->
packet.htype = client ->
interface -> hw_address.hbuf [0];
3580 client ->
packet.hlen = client ->
interface -> hw_address.hlen - 1;
3581 client ->
packet.hops = 0;
3582 client ->
packet.xid = random ();
3583 client ->
packet.secs = 0;
3587 client ->
packet.flags = 0;
3591 memset (&(client ->
packet.ciaddr),
3592 0,
sizeof client ->
packet.ciaddr);
3593 memset (&(client ->
packet.yiaddr),
3594 0,
sizeof client ->
packet.yiaddr);
3595 memset (&(client ->
packet.siaddr),
3596 0,
sizeof client ->
packet.siaddr);
3598 if (client -> interface -> hw_address.hlen > 0)
3599 memcpy (client ->
packet.chaddr,
3600 &client -> interface -> hw_address.hbuf [1],
3601 (
unsigned)(client -> interface -> hw_address.hlen - 1));
3604 dump_raw ((
unsigned char *)&client ->
packet, client -> packet_length);
3616 memset (&client ->
packet, 0,
sizeof (client ->
packet));
3624 if (client -> sent_options)
3631 : (
struct iaddr *)0),
3632 client -> config -> requested_options,
3633 &client -> sent_options);
3636 client -> packet_length =
3638 (
struct lease *)0, client,
3641 client -> sent_options,
3647 client -> config -> vendor_space_name);
3653 client ->
packet.htype = client ->
interface -> hw_address.hbuf [0];
3655 client ->
packet.hlen = client ->
interface -> hw_address.hlen - 1;
3656 client ->
packet.hops = 0;
3657 client ->
packet.xid = client -> xid;
3658 client ->
packet.secs = 0;
3662 if (client -> state ==
S_BOUND ||
3665 memcpy (&client ->
packet.ciaddr,
3666 lease -> address.iabuf,
lease -> address.len);
3667 client ->
packet.flags = 0;
3669 memset (&client ->
packet.ciaddr, 0,
3670 sizeof client ->
packet.ciaddr);
3672 client ->config->bootp_broadcast_always)) &&
3674 client ->
packet.flags = 0;
3679 memset (&client ->
packet.yiaddr, 0,
3680 sizeof client ->
packet.yiaddr);
3681 memset (&client ->
packet.siaddr, 0,
3682 sizeof client ->
packet.siaddr);
3683 if (client -> state !=
S_BOUND &&
3687 memset (&client ->
packet.giaddr, 0,
3688 sizeof client ->
packet.giaddr);
3689 if (client -> interface -> hw_address.hlen > 0)
3690 memcpy (client ->
packet.chaddr,
3691 &client -> interface -> hw_address.hbuf [1],
3692 (
unsigned)(client -> interface -> hw_address.hlen - 1));
3695 dump_raw ((
unsigned char *)&client ->
packet, client -> packet_length);
3715 memset (&client ->
packet, 0,
sizeof (client ->
packet));
3716 client -> packet_length =
3718 (
struct lease *)0, client, 0,
3721 client -> config -> vendor_space_name);
3730 client ->
packet.htype = client ->
interface -> hw_address.hbuf [0];
3732 client ->
packet.hlen = client ->
interface -> hw_address.hlen - 1;
3733 client ->
packet.hops = 0;
3734 client ->
packet.xid = client -> xid;
3735 client ->
packet.secs = 0;
3738 client ->
packet.flags = 0;
3743 memset (&client ->
packet.ciaddr, 0,
3744 sizeof client ->
packet.ciaddr);
3745 memset (&client ->
packet.yiaddr, 0,
3746 sizeof client ->
packet.yiaddr);
3747 memset (&client ->
packet.siaddr, 0,
3748 sizeof client ->
packet.siaddr);
3750 memcpy (client ->
packet.chaddr,
3751 &client -> interface -> hw_address.hbuf [1],
3752 client -> interface -> hw_address.hlen);
3755 dump_raw ((
unsigned char *)&client ->
packet, client -> packet_length);
3768 memset (&client ->
packet, 0,
sizeof (client ->
packet));
3775 client -> packet_length =
3777 (
struct lease *)0, client,
3786 client -> config -> vendor_space_name);
3793 client ->
packet.htype = client ->
interface -> hw_address.hbuf [0];
3795 client ->
packet.hlen = client ->
interface -> hw_address.hlen - 1;
3796 client ->
packet.hops = 0;
3797 client ->
packet.xid = random ();
3798 client ->
packet.secs = 0;
3799 client ->
packet.flags = 0;
3800 memcpy (&client ->
packet.ciaddr,
3801 lease -> address.iabuf,
lease -> address.len);
3802 memset (&client ->
packet.yiaddr, 0,
3803 sizeof client ->
packet.yiaddr);
3804 memset (&client ->
packet.siaddr, 0,
3805 sizeof client ->
packet.siaddr);
3807 memcpy (client ->
packet.chaddr,
3808 &client -> interface -> hw_address.hbuf [1],
3809 client -> interface -> hw_address.hlen);
3812 dump_raw ((
unsigned char *)&client ->
packet, client -> packet_length);
3851 for (client =
ip -> client; client; client = client ->
next) {
3852 for (lp = client -> leases; lp; lp = lp ->
next) {
3855 if (client -> active)
3857 client -> active, 1, 0);
3872 for (client =
ip -> client; client; client = client ->
next) {
3873 for (lp = client -> leases; lp; lp = lp ->
next) {
3876 if (client -> active)
3878 client -> active, 1, 0);
3900 const char *name, *dot;
3902 char *preamble = stuff;
3904 memset (&ds, 0,
sizeof ds);
3914 in_options, cfg_options, scope, oc,
MDL)) {
3916 fprintf(
leaseFile,
"%soption %s%s%s", preamble,
3937 const char *preamble)
3950 if (c >=
'0' && c <=
'9')
3953 if (c >=
'a' && c <=
'f')
3954 return c -
'a' + 10;
3956 if (c >=
'A' && c <=
'F')
3957 return c -
'A' + 10;
3964 const char *id_fname =
"/etc/machine-id";
3967 FILE *
file = fopen( id_fname ,
"r");
3970 return ISC_R_IOERROR;
3972 nread = fread(
id, 1,
sizeof id,
file);
3976 log_debug(
"Not enough data in %s", id_fname);
3977 return ISC_R_IOERROR;
3980 for (j = 0; j < 16; j++) {
3986 if (a < 0 || b < 0) {
3987 log_debug(
"Wrong data in %s", id_fname);
3988 return ISC_R_IOERROR;
3990 uuid[j] = a << 4 | b;
3994 uuid[6] = (uuid[6] & 0x0F) | 0x40;
3996 uuid[8] = (uuid[8] & 0x3F) | 0x80;
3998 return ISC_R_SUCCESS;
4031 log_debug(
"Cannot form default DUID from interface %s.",
ip->name);
4035 return ISC_R_UNEXPECTED;
4038 if ((
ip->hw_address.hlen == 0) ||
4039 (
ip->hw_address.hlen >
sizeof(
ip->hw_address.hbuf)))
4040 log_fatal(
"Impossible hardware address length at %s:%d.",
MDL);
4050 len = 2 +
sizeof (uuid);
4059 len = 4 + (
ip->hw_address.hlen - 1);
4064 log_fatal(
"no memory for default DUID!");
4070 memcpy(duid->
buffer->
data + 2, uuid,
sizeof(uuid));
4077 memcpy(duid->
buffer->
data + 8,
ip->hw_address.hbuf + 1,
4078 ip->hw_address.hlen - 1);
4082 memcpy(duid->
buffer->
data + 4,
ip->hw_address.hbuf + 1,
4083 ip->hw_address.hlen - 1);
4090 log_info(
"form_duid: Couldn't allocate memory to log duid!");
4096 return ISC_R_SUCCESS;
4106 if ((duid == NULL) || (duid->
len <= 2))
4113 return ISC_R_IOERROR;
4121 return ISC_R_NOMEMORY;
4123 stat = fprintf(
leaseFile,
"default-duid %s;\n", str);
4126 return ISC_R_IOERROR;
4129 return ISC_R_IOERROR;
4131 return ISC_R_SUCCESS;
4137 int rewrite,
int sync)
4148 return ISC_R_SUCCESS;
4151 if (client == NULL ||
lease == NULL)
4158 return ISC_R_IOERROR;
4162 stat = fprintf(
leaseFile,
"lease6 {\n");
4164 return ISC_R_IOERROR;
4166 stat = fprintf(
leaseFile,
" interface \"%s\";\n",
4169 return ISC_R_IOERROR;
4171 for (ia =
lease->bindings ; ia != NULL ; ia = ia->
next) {
4192 (
const unsigned char *) &ia->
iaid, 4,
4197 return ISC_R_IOERROR;
4208 stat = fprintf(
leaseFile,
" %s %s {\n", ianame,
4214 return ISC_R_IOERROR;
4217 stat = fprintf(
leaseFile,
" starts %d;\n" 4222 stat = fprintf(
leaseFile,
" starts %d;\n",
4225 return ISC_R_IOERROR;
4227 for (addr = ia->
addrs ; addr != NULL ; addr = addr->
next) {
4234 " iaprefix %s/%d {\n",
4238 return ISC_R_IOERROR;
4240 stat = fprintf(
leaseFile,
" starts %d;\n" 4241 " preferred-life %u;\n" 4246 return ISC_R_IOERROR;
4249 write_options(client, addr->
options,
" ");
4253 return ISC_R_IOERROR;
4257 write_options(client, ia->
options,
" ");
4261 return ISC_R_IOERROR;
4264 if (
lease->released) {
4265 stat = fprintf(
leaseFile,
" released;\n");
4267 return ISC_R_IOERROR;
4270 if (
lease->options != NULL)
4271 write_options(client,
lease->options,
" ");
4275 return ISC_R_IOERROR;
4278 return ISC_R_IOERROR;
4282 log_error(
"write_client_lease: fsync(): %m");
4283 return ISC_R_IOERROR;
4287 return ISC_R_SUCCESS;
4310 if (
lease -> is_static)
4323 if (
lease -> is_bootp) {
4330 fprintf (
leaseFile,
" interface \"%s\";\n",
4331 client -> interface -> name);
4336 if (client -> name) {
4337 fprintf (
leaseFile,
" name \"%s\";\n", client -> name);
4343 fprintf (
leaseFile,
" fixed-address %s;\n",
4349 if (
lease -> filename) {
4352 fprintf (
leaseFile,
" filename \"%s\";\n", s);
4362 if (
lease->server_name != NULL) {
4365 fprintf(
leaseFile,
" server-name \"%s\";\n", s);
4374 if (
lease -> medium) {
4377 fprintf (
leaseFile,
" medium \"%s\";\n", s);
4391 memset (&ds, 0,
sizeof ds);
4393 write_options(client,
lease->options,
" ");
4397 fprintf(
leaseFile,
" renew %s\n", tval) < 0)
4402 fprintf(
leaseFile,
" rebind %s\n", tval) < 0)
4407 fprintf(
leaseFile,
" expire %s\n", tval) < 0)
4418 if (!errors && makesure) {
4420 log_info (
"write_client_lease: %m");
4425 return errors ? 0 : 1;
4452 for (sl = client -> env; sl; sl =
next) {
4459 if (client -> interface) {
4461 client -> interface -> name);
4465 "",
"client",
"%s", client -> name);
4468 "",
"medium",
"%s", medium ->
string);
4471 client_envadd (client,
"",
"pid",
"%ld", (
long int)getpid ());
4490 in_options, cfg_options, scope, oc,
MDL)) {
4500 length = strlen(value);
4504 value, length) == 0) {
4509 "option - discarded",
4553 if (
lease->next_srv_addr.len != 0) {
4565 memset (&data, 0,
sizeof data);
4596 (&data, (
struct packet *)0,
4597 (
struct lease *)0, client,
4602 if (broadcast.
len) {
4604 prefix,
"broadcast_address",
4605 "%s",
piaddr (broadcast));
4613 if (
lease->filename) {
4616 strlen(
lease->filename)) == 0) {
4618 "%s",
lease->filename);
4621 "option - discarded",
4626 if (
lease->server_name) {
4629 strlen(
lease->server_name)) == 0 ) {
4631 "%s",
lease->server_name);
4634 "option - discarded",
4635 lease->server_name);
4648 (
unsigned long)(
lease -> expiry));
4670 for (i = 0 ; req[i] != NULL ; i++) {
4695 char reason [] =
"REASON=NBI";
4696 static char client_path [] = CLIENT_PATH;
4699 int pid, wpid, wstatus;
4702 scriptName = client -> config -> script_name;
4706 envp =
dmalloc (((client ? client -> envc : 2) +
4709 log_error (
"No memory for client script environment.");
4716 envp [i++] = sp ->
string;
4720 for (sp = client -> env; sp; sp = sp ->
next) {
4721 envp [i++] = sp ->
string;
4724 envp [i++] = reason;
4727 envp [i++] = client_path;
4728 envp [i] = (
char *)0;
4731 argv [1] = (
char *)0;
4739 wpid = wait (&wstatus);
4740 }
while (wpid != pid && wpid > 0);
4757 for (sp = client -> env; sp; sp =
next) {
4765 gettimeofday(&
cur_tv, NULL);
4766 return (WIFEXITED (wstatus) ?
4767 WEXITSTATUS (wstatus) : -WTERMSIG (wstatus));
4771 const char *prefix,
const char *name,
const char *fmt, ...)
4779 va_start (list, fmt);
4780 len = vsnprintf (spbuf,
sizeof spbuf, fmt, list);
4783 val =
dmalloc (strlen (prefix) + strlen (name) + 1 +
4784 len +
sizeof *val,
MDL);
4786 log_error (
"client_envadd: cannot allocate space for variable");
4795 if (len >=
sizeof spbuf) {
4796 va_start (list, fmt);
4797 vsnprintf (s, len + 1, fmt, list);
4803 val ->
next = client -> env;
4804 client -> env = val;
4827 if (j + 1 == buflen)
4837 if (j + 1 == buflen)
4850 static int state = 0;
4868 if ((pid = fork ()) < 0)
4881 (void) open(
"/dev/null", O_RDWR | O_CLOEXEC);
4882 (void) open(
"/dev/null", O_RDWR | O_CLOEXEC);
4883 (void) open(
"/dev/null", O_RDWR | O_CLOEXEC);
4900 pfdesc = open (
path_dhclient_pid, O_CREAT | O_TRUNC | O_WRONLY | O_CLOEXEC, 0644);
4907 pf = fdopen (pfdesc,
"we");
4912 fprintf (pf,
"%ld\n", (
long)getpid ());
4923 for (client =
ip -> client; client; client = client ->
next) {
4924 switch (client ->
state) {
4957 #if defined(DHCPv6) && defined(DHCP4o6) 4959 if (dhcp4o6_state < 0)
4967 client -> xid = random ();
4970 if (client -> active) {
4975 memset (&ds, 0,
sizeof ds);
4977 client -> active -> options,
4981 (
struct lease *)0, client,
4983 client -> active -> options,
4986 memcpy (client -> destination.iabuf,
4988 client -> destination.len = 4;
4995 client -> first_sending =
cur_time;
4996 client -> interval = client -> config -> initial_interval;
5007 if (client -> alias)
5023 #if defined(DHCPv6) && defined(DHCP4o6) 5046 interface_reference (&
ip, last ->
next,
MDL);
5047 interface_dereference (&last ->
next,
MDL);
5049 interface_reference (&last ->
next,
5051 interface_dereference (&
ip ->
next,
5056 interface_reference (&
ip,
5062 interface_dereference (&
ip ->
next,
5069 tmp ->
client ->
interface = tmp;
5071 interface_dereference (&
ip,
MDL);
5120 for (client =
ip->client ; client ; client = client->
next) {
5125 return ISC_R_SUCCESS;
5151 static void shutdown_exit (
void *foo)
5159 #if defined (NSUPDATE) 5176 isc_result_t eresult)
5179 isc_result_t result;
5181 if ((eresult == ISC_R_SUCCESS) &&
5187 if (result == ISC_R_SUCCESS) {
5193 dhclient_ddns_cb_free(ddns_cb,
MDL);
5202 isc_result_t result;
5205 if (client->
ddns_cb != NULL) {
5211 if (ddns_cb != NULL) {
5217 ddns_cb->
cur_func = client_dns_remove_action;
5221 if (result != ISC_R_TIMEDOUT) {
5222 dhclient_ddns_cb_free(ddns_cb,
MDL);
5238 return ISC_R_SUCCESS;
5242 log_info(
"Received signal %d, initiating shutdown.",
5251 for (client =
ip -> client; client; client = client -> next) {
5254 return ISC_R_SUCCESS;
5257 return ISC_R_SUCCESS;
5260 if (client -> active &&
5261 client -> active -> expiry >
cur_time) {
5262 #if defined (NSUPDATE) 5284 tv.tv_sec =
cur_tv.tv_sec;
5285 tv.tv_usec =
cur_tv.tv_usec + 1;
5288 return ISC_R_SUCCESS;
5291 #if defined (NSUPDATE) 5302 isc_result_t status = ISC_R_FAILURE;
5304 if ((client != NULL) &&
5305 ((client->
active != NULL) ||
5318 if (status != ISC_R_TIMEDOUT) {
5354 isc_result_t eresult)
5356 isc_result_t result;
5373 ddns_cb->
cur_func = client_dns_update_action;
5376 if (result == ISC_R_SUCCESS) {
5382 case ISC_R_TIMEDOUT:
5390 if (ddns_cb->
zone != NULL) {
5396 ddns_cb->
cur_func = client_dns_update_action;
5402 tv.tv_usec =
cur_tv.tv_usec;
5404 ddns_cb, NULL, NULL);
5408 dhclient_ddns_cb_free(ddns_cb,
MDL);
5426 if (!client -> sent_options)
5427 return ISC_R_SUCCESS;
5431 return ISC_R_SUCCESS;
5437 (
struct lease *)0, client,
5438 client -> sent_options,
5441 return ISC_R_SUCCESS;
5448 (
struct lease *)0, client,
5449 client -> sent_options,
5452 return ISC_R_SUCCESS;
5458 (
struct lease *)0, client,
5459 client -> sent_options,
5462 return ISC_R_SUCCESS;
5474 memset(&client_identifier, 0,
sizeof(client_identifier));
5498 client_identifier.data,
5499 client_identifier.len);
5517 (client_identifier.data[0] == 255)) {
5522 if (client_identifier.len <= 5)
5523 log_fatal(
"Impossible condition at %s:%d.",
5526 client_identifier.data + 5,
5527 client_identifier.len - 5);
5529 result =
get_dhcid(ddns_cb, ddns_v4_type,
5530 client_identifier.data,
5531 client_identifier.len);
5541 return ISC_R_SUCCESS;
5550 rcode = ISC_R_FAILURE;
5556 if (rcode == ISC_R_SUCCESS) {
5557 rcode = ISC_R_TIMEDOUT;
5580 if (client->
ddns_cb != NULL) {
5587 if (ddns_cb != NULL) {
5588 ddns_cb->
lease = (
void *)client;
5601 ddns_cb->
cur_func = client_dns_update_action;
5605 tv.tv_sec =
cur_tv.tv_sec + offset;
5606 tv.tv_usec =
cur_tv.tv_usec;
5608 ddns_cb, NULL, NULL);
5610 log_error(
"Unable to allocate dns update state for %s",
5619 struct servent *ent;
5633 ent = getservbyname(
"dhcpc",
"udp");
5635 ent = getservbyname(
"bootpc",
"udp");
5640 #ifndef __CYGWIN32__ 5664 static int check_domain_name(
const char *ptr,
size_t len,
int dots)
5669 if ((len == 0) || (len > 256))
5674 for (p=ptr; (*p != 0) && (len-- > 0); p++) {
5675 if ((*p ==
'-') || (*p ==
'_')) {
5677 if (((p - ptr) == 0) || (len == 0) || (p[1] ==
'.'))
5679 }
else if (*p ==
'.') {
5683 if ((d <= 0) || (d >= 64))
5686 if ((dots > 0) && (len > 0))
5688 }
else if (isalnum((
unsigned char)*p) == 0) {
5693 return(dots ? -1 : 0);
5696 static int check_domain_name_list(
const char *ptr,
size_t len,
int dots)
5701 if ((ptr == NULL) || (len == 0))
5704 for (p=ptr; (*p != 0) && (len > 0); p++, len--) {
5708 if (check_domain_name(ptr, p - ptr, dots) != 0)
5715 return(check_domain_name(ptr, p - ptr, dots));
5732 #ifdef ACCEPT_LIST_IN_DOMAIN_NAME 5733 return check_domain_name_list(ptr, len, 0);
5735 return check_domain_name(ptr, len, 0);
5740 return check_domain_name(ptr, len, 0);
5743 return check_domain_name_list(ptr, len, 0);
5748 for (; (*ptr != 0) && (len-- > 0); ptr++) {
5749 if(!(isalnum((
unsigned char)*ptr) ||
5750 *ptr ==
'#' || *ptr ==
'%' ||
5751 *ptr ==
'+' || *ptr ==
'-' ||
5752 *ptr ==
'_' || *ptr ==
':' ||
5753 *ptr ==
'.' || *ptr ==
',' ||
5754 *ptr ==
'@' || *ptr ==
'~' ||
5755 *ptr ==
'\\' || *ptr ==
'/' ||
5756 *ptr ==
'[' || *ptr ==
']' ||
5757 *ptr ==
'=' || *ptr ==
' '))
5772 return check_domain_name_list(ptr, len, 0);
5787 log_fatal (
"no memory for reject list!");
5806 log_info(
"Server added to list of rejected servers.");
5815 if (client != NULL) {
5823 #if defined(DHCPv6) && defined(DHCP4o6) 5842 char start_msg[5] = {
'S',
'T',
'A',
'R',
'T' };
5843 char stop_msg[4] = {
'S',
'T',
'O',
'P' };
5844 char poll_msg[4] = {
'P',
'O',
'L',
'L' };
5848 if (h->type != dhcp4o6_type)
5851 cc = recv(dhcp4o6_fd, buf,
sizeof(buf), 0);
5853 return ISC_R_UNEXPECTED;
5857 (memcmp(buf, poll_msg,
sizeof(poll_msg)) == 0)) {
5859 if (dhcp4o6_state < 0)
5860 cc = send(dhcp4o6_fd, stop_msg,
5861 sizeof(stop_msg), 0);
5863 cc = send(dhcp4o6_fd, start_msg,
5864 sizeof(start_msg), 0);
5866 log_error(
"dhcpv4o6_handler: send(): %m");
5867 return ISC_R_IOERROR;
5871 return ISC_R_UNEXPECTED;
5872 memset(&raw, 0,
sizeof(raw));
5875 "no memory buffer.");
5876 return ISC_R_NOMEMORY;
5882 forw_dhcpv4_query(&raw);
5888 (memcmp(buf, stop_msg,
sizeof(stop_msg)) == 0)) {
5890 if (dhcp4o6_state > 0) {
5894 }
else if ((cc == 5) &&
5895 (memcmp(buf, start_msg,
sizeof(start_msg)) == 0)) {
5897 if (dhcp4o6_state == 0)
5903 return ISC_R_UNEXPECTED;
5904 memset(&raw, 0,
sizeof(raw));
5907 "no memory buffer.");
5908 return ISC_R_NOMEMORY;
5914 recv_dhcpv4_response(&raw);
5920 return ISC_R_SUCCESS;
5931 static void dhcp4o6_poll(
void *dummy) {
5932 char msg[4] = {
'P',
'O',
'L',
'L' };
5938 if (dhcp4o6_state < 0)
5943 cc = send(dhcp4o6_fd, msg,
sizeof(msg), 0);
5948 tv.tv_usec = random() % 1000000;
5960 static void dhcp4o6_resume() {
5965 for (client =
ip->client; client != NULL;
5966 client = client->
next) {
5989 char msg[5] = {
'S',
'T',
'A',
'R',
'T' };
5992 memset(&addrs, 0,
sizeof(addrs));
5994 for (client =
ip->client; client != NULL;
5995 client = client->
next) {
6008 lease->options, NULL,
6011 if ((addrs.len % 16) != 0) {
6024 if (dhcp4o6_state == 1)
6026 log_info(
"dhcp4o6_start: go to UP");
6029 cc = send(dhcp4o6_fd, msg,
sizeof(msg), 0);
6031 log_info(
"dhcp4o6_start: send(): %m");
6041 static void dhcp4o6_stop() {
6042 char msg[4] = {
'S',
'T',
'O',
'P' };
6045 if (dhcp4o6_state == -1)
6048 log_info(
"dhcp4o6_stop: go to DOWN");
6051 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 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)
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