41 #include <dns/result.h> 51 extern int asprintf(
char **strp,
const char *fmt, ...);
82 #define ASSERT_STATE(state_is, state_shouldbe) {} 85 static const char copyright[] =
"Copyright 2004-2017 Internet Systems Consortium.";
86 static const char arr [] =
"All rights reserved.";
87 static const char message [] =
"Internet Systems Consortium DHCP Client";
88 static const char url [] =
"For info, please visit https://www.isc.org/software/dhcp/";
93 #if defined(DHCPv6) && defined(DHCP4o6) 94 int dhcp4o6_state = -1;
120 static isc_result_t write_duid(
struct data_string *duid);
123 static int check_domain_name(
const char *ptr,
size_t len,
int dots);
124 static int check_domain_name_list(
const char *ptr,
size_t len,
int dots);
126 const char *ptr,
size_t len);
147 #if defined(DHCPv6) && defined(DHCP4o6) 148 static void dhcp4o6_poll(
void *dummy);
149 static void dhcp4o6_resume(
void);
150 static void recv_dhcpv4_response(
struct data_string *raw);
151 static int send_dhcpv4_query(
struct client_state *client,
int broadcast);
153 static void dhcp4o6_stop(
void);
154 static void forw_dhcpv4_response(
struct packet *
packet);
155 static void forw_dhcpv4_query(
struct data_string *raw);
162 static const char use_noarg[] =
"No argument for command: %s";
164 static const char use_v6command[] =
"Command not used for DHCPv4: %s";
170 usage(
const char *sfmt,
const char *sarg)
178 #ifdef PRINT_SPECIFIC_CL_ERRORS 186 "[-4|-6] [-SNTPRI1dvrxi] [-nw] -4o6 <port>] [-p <port>]\n" 187 " [-D LL|LLT] [--dad-wait-time seconds]\n" 189 "[-4|-6] [-SNTPRI1dvrxi] [-nw] [-p <port>]\n" 190 " [-D LL|LLT] [--dad-wait-time seconds]\n" 193 "[-I1dvrxi] [-nw] [-p <port>] [-D LL|LLT] \n" 195 " [-s server-addr] [-cf config-file]\n" 196 " [-df duid-file] [-lf lease-file]\n" 197 " [-pf pid-file] [--no-pid] [-e VAR=val]\n" 198 " [-sf script-file] [interface]*\n" 199 " [-C <dhcp-client-identifier>] [-B]\n" 200 " [-H <host-name> | -F <fqdn.fqdn>] [--timeout <timeout>]\n" 201 " [-V <vendor-class-identifier>]\n" 202 " [--request-options <request option list>]",
216 int release_mode = 0;
221 int no_dhclient_conf = 0;
222 int no_dhclient_db = 0;
223 int no_dhclient_pid = 0;
224 int no_dhclient_script = 0;
226 int local_family_set = 0;
228 u_int16_t dhcp4o6_port = 0;
239 char *dhcp_client_identifier_arg = NULL;
240 char *dhcp_host_name_arg = NULL;
241 char *dhcp_fqdn_arg = NULL;
242 char *dhcp_vendor_class_identifier_arg = NULL;
243 char *dhclient_request_options = NULL;
246 char *arg_conf = NULL;
247 int arg_conf_len = 0;
248 #ifdef HAVE_LIBCAP_NG 249 int keep_capabilities = 0;
258 fd = open(
"/dev/null", O_RDWR | O_CLOEXEC);
260 fd = open(
"/dev/null", O_RDWR | O_CLOEXEC);
262 fd = open(
"/dev/null", O_RDWR | O_CLOEXEC);
270 #if !(defined(DEBUG) || defined(__CYGWIN32__)) 271 setlogmask(LOG_UPTO(LOG_INFO));
277 if (status != ISC_R_SUCCESS)
278 log_fatal(
"Can't initialize context: %s",
279 isc_result_totext(status));
283 if (status != ISC_R_SUCCESS)
285 isc_result_totext(status));
295 for (i = 1; i < argc; i++) {
296 if (!strcmp(argv[i],
"-r")) {
300 }
else if (!strcmp(argv[i],
"-4")) {
302 log_fatal(
"Client can only do v4 or v6, not " 304 local_family_set = 1;
306 }
else if (!strcmp(argv[i],
"-6")) {
308 log_fatal(
"Client can only do v4 or v6, not " 310 local_family_set = 1;
313 }
else if (!strcmp(argv[i],
"-4o6")) {
315 usage(use_noarg, argv[i-1]);
318 log_debug(
"DHCPv4 over DHCPv6 over ::1 port %d and %d",
320 ntohs(dhcp4o6_port) + 1);
324 }
else if (!strcmp(argv[i],
"-x")) {
328 }
else if (!strcmp(argv[i],
"-p")) {
330 usage(use_noarg, argv[i-1]);
332 log_debug(
"binding to user-specified port %d",
334 }
else if (!strcmp(argv[i],
"-d")) {
337 }
else if (!strcmp(argv[i],
"-pf")) {
339 usage(use_noarg, argv[i-1]);
342 }
else if (!strcmp(argv[i],
"--no-pid")) {
344 }
else if (!strcmp(argv[i],
"-cf")) {
346 usage(use_noarg, argv[i-1]);
348 no_dhclient_conf = 1;
349 }
else if (!strcmp(argv[i],
"-df")) {
351 usage(use_noarg, argv[i-1]);
353 }
else if (!strcmp(argv[i],
"-lf")) {
355 usage(use_noarg, argv[i-1]);
358 }
else if (!strcmp(argv[i],
"-sf")) {
360 usage(use_noarg, argv[i-1]);
362 no_dhclient_script = 1;
363 }
else if (!strcmp(argv[i],
"-1")) {
365 }
else if (!strcmp(argv[i],
"-q")) {
367 }
else if (!strcmp(argv[i],
"-s")) {
369 usage(use_noarg, argv[i-1]);
371 }
else if (!strcmp(argv[i],
"-g")) {
373 usage(use_noarg, argv[i-1]);
375 }
else if (!strcmp(argv[i],
"-nw")) {
377 }
else if (!strcmp(argv[i],
"-n")) {
380 }
else if (!strcmp(argv[i],
"-w")) {
383 }
else if (!strcmp(argv[i],
"-e")) {
386 usage(use_noarg, argv[i-1]);
387 tmp =
dmalloc(strlen(argv[i]) +
sizeof *tmp,
MDL);
390 strcpy(tmp->
string, argv[i]);
395 }
else if (!strcmp(argv[i],
"-S")) {
397 usage(use_v6command, argv[i]);
399 local_family_set = 1;
403 }
else if (!strcmp(argv[i],
"-N")) {
405 usage(use_v6command, argv[i]);
407 local_family_set = 1;
413 }
else if (!strcmp(argv[i],
"-T")) {
415 usage(use_v6command, argv[i]);
417 local_family_set = 1;
423 }
else if (!strcmp(argv[i],
"-P")) {
425 usage(use_v6command, argv[i]);
427 local_family_set = 1;
433 }
else if (!strcmp(argv[i],
"-R")) {
435 usage(use_v6command, argv[i]);
437 local_family_set = 1;
440 }
else if (!strcmp(argv[i],
"--dad-wait-time")) {
442 usage(use_noarg, argv[i-1]);
446 usage(
"Invalid value for --dad-wait-time: %s", argv[i]);
450 }
else if (!strcmp(argv[i],
"-D")) {
453 usage(use_noarg, argv[i-1]);
454 if (!strcasecmp(argv[i],
"LL")) {
456 }
else if (!strcasecmp(argv[i],
"LLT")) {
459 usage(
"Unknown argument to -D: %s", argv[i]);
461 }
else if (!strcmp(argv[i],
"-i")) {
464 }
else if (!strcmp(argv[i],
"-I")) {
467 }
else if (!strcmp(argv[i],
"-v")) {
469 }
else if (!strcmp(argv[i],
"--version")) {
470 const char vstring[] =
"isc-dhclient-";
478 }
else if (!strcmp(argv[i],
"-C")) {
479 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
480 usage(use_noarg, argv[i-1]);
489 dhcp_client_identifier_arg = argv[i];
490 }
else if (!strcmp(argv[i],
"-B")) {
492 }
else if (!strcmp(argv[i],
"-H")) {
493 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
494 usage(use_noarg, argv[i-1]);
503 if (dhcp_host_name_arg != NULL) {
504 log_error(
"The -H <host-name> and -F <fqdn> arguments are mutually exclusive");
508 dhcp_host_name_arg = argv[i];
509 }
else if (!strcmp(argv[i],
"-F")) {
510 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
511 usage(use_noarg, argv[i-1]);
520 if (dhcp_fqdn_arg != NULL) {
521 log_error(
"Only one -F <fqdn> argument can be specified");
525 if (dhcp_host_name_arg != NULL) {
526 log_error(
"The -F <fqdn> and -H <host-name> arguments are mutually exclusive");
530 dhcp_fqdn_arg = argv[i];
531 }
else if (!strcmp(argv[i],
"--timeout")) {
532 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
533 usage(use_noarg, argv[i-1]);
537 if ((timeout_arg = atoi(argv[i])) <= 0) {
538 log_error(
"timeout option must be > 0 - bad value: %s",argv[i]);
541 }
else if (!strcmp(argv[i],
"-V")) {
542 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
543 usage(use_noarg, argv[i-1]);
552 dhcp_vendor_class_identifier_arg = argv[i];
553 }
else if (!strcmp(argv[i],
"--request-options")) {
554 if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])==
'\0')) {
555 usage(use_noarg, argv[i-1]);
559 dhclient_request_options = argv[i];
560 }
else if (!strcmp(argv[i],
"-nc")) {
561 #ifdef HAVE_LIBCAP_NG 562 keep_capabilities = 1;
564 }
else if (argv[i][0] ==
'-') {
565 usage(
"Unknown command: %s", argv[i]);
567 usage(
"No interfaces comamnd -n and " 568 " requested interface %s", argv[i]);
572 status = interface_allocate(&tmp,
MDL);
573 if (status != ISC_R_SUCCESS)
574 log_fatal(
"Can't record interface %s:%s",
575 argv[i], isc_result_totext(status));
576 if (strlen(argv[i]) >=
sizeof(tmp->
name))
577 log_fatal(
"%s: interface name too long (is %ld)",
578 argv[i], (
long)strlen(argv[i]));
579 strcpy(tmp->
name, argv[i]);
581 interface_reference(&tmp->
next,
597 usage(
"PD %s only supports one requested interface",
"-P");
600 #if defined(DHCPv6) && defined(DHCP4o6) 602 (exit_mode || release_mode))
603 log_error(
"Can't relay DHCPv4-over-DHCPv6 " 604 "without a persistent DHCPv6 client");
607 log_fatal(
"DHCPv4-over-DHCPv6 requires an explicit " 608 "interface on which to be applied");
611 if (!no_dhclient_conf && (s = getenv(
"PATH_DHCLIENT_CONF"))) {
614 if (!no_dhclient_db && (s = getenv(
"PATH_DHCLIENT_DB"))) {
617 if (!no_dhclient_pid && (s = getenv(
"PATH_DHCLIENT_PID"))) {
620 if (!no_dhclient_script && (s = getenv(
"PATH_DHCLIENT_SCRIPT"))) {
624 #ifdef HAVE_LIBCAP_NG 626 if (!keep_capabilities) {
627 capng_clear(CAPNG_SELECT_CAPS);
628 capng_update(CAPNG_ADD, CAPNG_EFFECTIVE|CAPNG_PERMITTED,
630 capng_updatev(CAPNG_ADD, CAPNG_EFFECTIVE|CAPNG_PERMITTED,
631 CAP_NET_ADMIN, CAP_NET_RAW,
632 CAP_NET_BIND_SERVICE, CAP_SYS_ADMIN, -1);
633 capng_apply(CAPNG_SELECT_CAPS);
658 log_fatal(
"Failed to get realpath for %s: %s", old_path, strerror(errno));
665 log_fatal(
"Failed to get realpath for %s: %s", old_path, strerror(errno));
674 if ((release_mode || exit_mode) && (
no_pid_file == ISC_FALSE)) {
681 e = fscanf(pidfd,
"%ld\n", &temp);
682 oldpid = (pid_t)temp;
684 if (e != 0 && e != EOF && oldpid) {
685 if (kill(oldpid, SIGTERM) == 0) {
686 log_info(
"Killed old client process");
696 }
else if (errno == ESRCH) {
710 char *new_path_dhclient_pid;
729 int n_len = strlen(ip->
name);
731 new_path_dhclient_pid = (
char*) malloc(pfx + n_len + 6);
733 sprintf(new_path_dhclient_pid + pfx,
"-%s.pid", ip->
name);
735 if ((pidfd = fopen(new_path_dhclient_pid,
"re")) != NULL) {
736 e = fscanf(pidfd,
"%ld\n", &temp);
737 oldpid = (pid_t)temp;
739 if (e != 0 && e != EOF) {
741 if (kill(oldpid, SIGTERM) == 0)
749 free(new_path_dhclient_pid);
758 char procfn[256] =
"";
761 if ((fscanf(pidfp,
"%ld", &temp)==1) && ((dhcpid=(pid_t)temp) > 0)) {
762 snprintf(procfn,256,
"/proc/%u",dhcpid);
763 dhc_running = (access(procfn, F_OK) == 0);
770 log_fatal(
"dhclient(%u) is already running - exiting. ", dhcpid);
795 memcpy(&
giaddr, he->h_addr_list[0],
804 gettimeofday(&
cur_tv, NULL);
811 he = gethostbyname(server);
837 usage(
"Stateless commnad: %s incompatibile with " 838 "other commands",
"-S");
840 #if defined(DHCPv6) && defined(DHCP4o6) 849 if ((dhcp_client_identifier_arg != NULL) && (*dhcp_client_identifier_arg !=
'\0')) {
850 arg_conf_len =
asprintf(&arg_conf,
"send dhcp-client-identifier \"%s\";", dhcp_client_identifier_arg);
852 if ((arg_conf == 0) || (arg_conf_len <= 0))
853 log_fatal(
"Unable to send -C option dhcp-client-identifier");
856 if ((dhcp_host_name_arg != NULL) && (*dhcp_host_name_arg !=
'\0')) {
858 arg_conf_len =
asprintf(&arg_conf,
"send host-name \"%s\";", dhcp_host_name_arg);
860 if ((arg_conf == 0) || (arg_conf_len <= 0))
861 log_fatal(
"Unable to send -H option host-name");
863 char *last_arg_conf = arg_conf;
865 arg_conf_len =
asprintf(&arg_conf,
"%s\nsend host-name \"%s\";", last_arg_conf, dhcp_host_name_arg);
867 if ((arg_conf == 0) || (arg_conf_len <= 0))
868 log_fatal(
"Unable to send -H option host-name");
874 if ((dhcp_fqdn_arg != NULL) && (*dhcp_fqdn_arg !=
'\0')) {
876 arg_conf_len =
asprintf(&arg_conf,
"send fqdn.fqdn \"%s\";", dhcp_fqdn_arg);
878 if ((arg_conf == 0) || (arg_conf_len <= 0))
879 log_fatal(
"Unable to send -F option fqdn.fqdn");
881 char *last_arg_conf = arg_conf;
883 arg_conf_len =
asprintf(&arg_conf,
"%s\nsend fqdn.fqdn \"%s\";", last_arg_conf, dhcp_fqdn_arg);
885 if ((arg_conf == 0) || (arg_conf_len <= 0))
886 log_fatal(
"Unable to send -F option fqdn.fqdn");
894 arg_conf_len =
asprintf(&arg_conf,
"timeout %d;", timeout_arg);
896 if ((arg_conf == 0) || (arg_conf_len <= 0))
897 log_fatal(
"Unable to process --timeout timeout argument");
899 char *last_arg_conf = arg_conf;
901 arg_conf_len =
asprintf(&arg_conf,
"%s\ntimeout %d;", last_arg_conf, timeout_arg);
903 if ((arg_conf == 0) || (arg_conf_len == 0))
904 log_fatal(
"Unable to process --timeout timeout argument");
910 if ((dhcp_vendor_class_identifier_arg != NULL) && (*dhcp_vendor_class_identifier_arg !=
'\0')) {
912 arg_conf_len =
asprintf(&arg_conf,
"send vendor-class-identifier \"%s\";", dhcp_vendor_class_identifier_arg);
914 if ((arg_conf == 0) || (arg_conf_len <= 0))
915 log_fatal(
"Unable to send -V option vendor-class-identifier");
917 char *last_arg_conf = arg_conf;
919 arg_conf_len =
asprintf(&arg_conf,
"%s\nsend vendor-class-identifier \"%s\";", last_arg_conf, dhcp_vendor_class_identifier_arg);
921 if ((arg_conf == 0) || (arg_conf_len <= 0))
922 log_fatal(
"Unable to send -V option vendor-class-identifier");
928 if (dhclient_request_options != NULL) {
930 arg_conf_len =
asprintf(&arg_conf,
"request %s;", dhclient_request_options);
932 if ((arg_conf == 0) || (arg_conf_len <= 0))
933 log_fatal(
"Unable to parse --request-options <request options list> argument");
935 char *last_arg_conf = arg_conf;
937 arg_conf_len =
asprintf(&arg_conf,
"%s\nrequest %s;", last_arg_conf, dhclient_request_options);
939 if ((arg_conf == 0) || (arg_conf_len <= 0))
940 log_fatal(
"Unable to parse --request-options <request options list> argument");
947 if (arg_conf_len == 0)
948 if ((arg_conf_len = strlen(arg_conf)) == 0)
950 log_fatal(
"Unable to process -C/-H/-F/--timeout/-V/--request-options configuration arguments");
955 const char *val = NULL;
958 status =
new_parse(&cfile, -1, arg_conf, arg_conf_len,
"extra dhclient -C/-H/-F/--timeout/-V/--request-options configuration arguments", 0);
961 log_fatal(
"Cannot parse -C/-H/-F/--timeout/-V/--request-options configuration arguments !");
965 token =
peek_token(&val, (
unsigned *)0, cfile);
973 log_fatal(
"Cannot parse -C/-H/-F/--timeout/-V/--request-options configuration arguments !");
1030 log_info(
"No broadcast interfaces found - exiting.");
1033 }
else if (!release_mode && !exit_mode) {
1067 unsigned backup_seed = 0;
1070 if ( ip -> hw_address.hlen <=
sizeof seed )
1073 &ip -> hw_address.hbuf [ip -> hw_address.hlen -
1074 sizeof seed],
sizeof seed);
1096 if ( ip -> hw_address.hlen <=
sizeof seed )
1100 sizeof seed],
sizeof seed);
1104 if ( seed_flag == 0 ) {
1105 if ( backup_seed != 0 ) {
1107 log_info (
"xid: rand init seed (0x%x) built using all" 1108 " available interfaces",seed);
1111 seed =
cur_time^((unsigned) gethostid()) ;
1112 log_info (
"xid: warning: no netdev with useable HWADDR found" 1113 " for seed's uniqueness enforcement");
1114 log_info (
"xid: rand init seed (0x%x) built using gethostid",
1119 srandom(seed + ((
unsigned)(
cur_tv.tv_usec * 1000000)) + (
unsigned)getpid());
1122 srandom(seed + ((
unsigned)(
cur_tv.tv_usec * 1000000)) + (
unsigned)getpid());
1128 setup_ib_interface(ip);
1147 #if defined(DHCPv6) && defined(DHCP4o6) 1149 dhcp4o6_setup(dhcp4o6_port);
1156 for (client = ip->
client ; client != NULL ;
1157 client = client->
next) {
1161 }
else if (exit_mode) {
1181 for (client = ip->
client ; client ;
1182 client = client->
next) {
1199 tv.tv_usec = random()
1234 if (result != ISC_R_SUCCESS)
1235 log_fatal(
"Can't allocate new generic object: %s\n",
1236 isc_result_totext(result));
1241 if (result != ISC_R_SUCCESS)
1242 log_fatal(
"Can't start OMAPI protocol: %s",
1243 isc_result_totext (result));
1252 #if defined(DEBUG_MEMORY_LEAKAGE) || defined(DEBUG_MALLOC_POOL) || \ 1253 defined(DEBUG_MEMORY_LEAKAGE_ON_EXIT) 1254 dmalloc_cutoff_generation = dmalloc_generation;
1255 dmalloc_longterm = dmalloc_outstanding;
1256 dmalloc_outstanding = 0;
1259 #if defined(ENABLE_GENTLE_SHUTDOWN) 1296 isc_result_t result;
1305 usage(
"No interfaces available for stateless command: %s",
"-S");
1348 dhcp4o6_setup(port);
1354 client = client->
next) {
1368 if (result != ISC_R_SUCCESS)
1369 log_fatal(
"Can't allocate new generic object: %s\n",
1370 isc_result_totext(result));
1375 if (result != ISC_R_SUCCESS)
1376 log_fatal(
"Can't start OMAPI protocol: %s",
1377 isc_result_totext(result));
1383 #if defined(DEBUG_MEMORY_LEAKAGE) || defined(DEBUG_MALLOC_POOL) || \ 1384 defined(DEBUG_MEMORY_LEAKAGE_ON_EXIT) 1385 dmalloc_cutoff_generation = dmalloc_generation;
1386 dmalloc_longterm = dmalloc_outstanding;
1387 dmalloc_outstanding = 0;
1409 const char *s,
const char *
file,
int line)
1423 struct packet *packet;
1429 struct lease *lease;
1453 "dhcp-client-identifier") == 0)) {
1496 #if defined(DHCPv6) && defined(DHCP4o6) 1498 if (dhcp4o6_state < 0)
1509 client ->
active -> is_bootp ||
1523 client ->
xid = random ();
1556 client -> xid = client -> packet.xid;
1559 client -> first_sending =
cur_time;
1560 client -> interval = client -> config -> initial_interval;
1603 for (lp = client -> offered_leases; lp; lp =
next) {
1612 picked -> next = NULL;
1617 client -> offered_leases = NULL;
1624 client -> state =
S_INIT;
1631 client ->
new = picked;
1649 client -> first_sending =
cur_time;
1650 client -> interval = client -> config -> initial_interval;
1654 client -> xid = client -> packet.xid;
1667 struct packet *packet;
1677 for (client = ip -> client; client; client = client -> next) {
1678 if (client -> xid == packet -> raw -> xid)
1682 (packet -> interface -> hw_address.hlen - 1 !=
1683 packet -> raw -> hlen) ||
1684 (memcmp (&packet -> interface -> hw_address.hbuf [1],
1685 packet -> raw -> chaddr, packet -> raw -> hlen))) {
1687 log_debug (
"DHCPACK in wrong transaction.");
1702 log_info (
"DHCPACK from %s (xid=0x%x)",
piaddr (packet -> client_addr), ntohl(client -> xid));
1706 log_info (
"packet_to_lease failed.");
1710 client ->
new = lease;
1718 memset (&ds, 0,
sizeof ds);
1721 packet -> options, client ->
new -> options,
1726 client ->
new -> expiry = 0;
1729 client ->
new -> expiry = 0;
1734 log_error (
"no expiry time on offered lease.");
1740 tv.tv_sec =
cur_tv.tv_sec;
1741 tv.tv_usec =
cur_tv.tv_usec + 500000;
1743 if (tv.tv_usec >= 1000000) {
1745 tv.tv_usec -= 1000000;
1764 packet -> options, client ->
new -> options,
1769 client ->
new -> renewal = 0;
1772 client ->
new -> renewal = 0;
1775 if (!client ->
new -> renewal)
1776 client ->
new -> renewal = client ->
new -> expiry / 2 + 1;
1778 if (client ->
new -> renewal <= 0)
1779 client ->
new -> renewal =
TIME_MAX;
1784 (((random() % client->
new->
renewal) + 3) / 4);
1791 packet -> options, client ->
new -> options,
1796 client ->
new -> rebind = 0;
1799 client ->
new -> rebind = 0;
1801 if (client ->
new -> rebind <= 0) {
1802 if (client ->
new -> expiry <=
TIME_MAX / 7)
1803 client ->
new -> rebind =
1804 client ->
new -> expiry * 7 / 8;
1806 client ->
new -> rebind =
1807 client ->
new -> expiry / 8 * 7;
1812 if (client ->
new -> renewal > client ->
new -> rebind) {
1813 if (client ->
new -> rebind <=
TIME_MAX / 3)
1814 client ->
new -> renewal =
1815 client ->
new -> rebind * 3 / 4;
1817 client ->
new -> renewal =
1818 client ->
new -> rebind / 4 * 3;
1821 client ->
new -> expiry +=
cur_time;
1823 if (client ->
new -> expiry <
cur_time)
1824 client ->
new -> expiry =
TIME_MAX;
1825 client ->
new -> renewal +=
cur_time;
1826 if (client ->
new -> renewal <
cur_time)
1827 client ->
new -> renewal =
TIME_MAX;
1828 client ->
new -> rebind +=
cur_time;
1829 if (client ->
new -> rebind <
cur_time)
1830 client ->
new -> rebind =
TIME_MAX;
1866 log_info(
"Unable to obtain a lease on first " 1867 "try (declined). Exiting.");
1870 #if defined (CALL_SCRIPT_ON_ONETRY_FAIL) 1897 random() % 1000000 :
cur_tv.tv_usec;
1900 log_info(
"bound to %s -- renewal in %ld seconds.",
1906 #if defined (NSUPDATE) 1928 client -> xid = client -> packet.xid;
1930 memset (&ds, 0,
sizeof ds);
1936 client -> active -> options,
1939 memcpy (client -> destination.iabuf, ds.
data, 4);
1940 client -> destination.len = 4;
1948 client -> first_sending =
cur_time;
1949 client -> interval = client -> config -> initial_interval;
1989 struct lease *lease;
2006 struct packet *packet;
2017 for (ap = packet -> interface -> client -> config -> reject_list;
2018 ap; ap = ap ->
next) {
2027 log_info(
"BOOTREPLY from %s rejected by rule %s " 2039 struct packet *packet;
2042 void (*handler) (
struct packet *);
2069 for (ap = packet ->
interface -> client -> config -> reject_list;
2070 ap; ap = ap -> next) {
2079 log_info(
"%s from %s rejected by rule %s mask %s.",
2085 (*handler) (packet);
2090 dhcpv6(
struct packet *packet) {
2093 char addrbuf[
sizeof(
"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")];
2101 ap ; ap = ap->
next) {
2104 log_info(
"%s from %s rejected by rule %s",
2117 log_info(
"RCV: %s message on %s from %s.",
2121 forw_dhcpv4_response(packet);
2131 log_info(
"RCV: %s message on %s from %s.",
2142 client = client->
next) {
2151 log_info(
"Packet received, but nothing done with it.");
2167 static void forw_dhcpv4_response(
struct packet *packet)
2177 if (dhcp4o6_state == -1) {
2178 log_info(
"forw_dhcpv4_response: not ready.");
2183 log_error(
"forw_dhcpv4_response: bad address");
2192 log_info(
"DHCPv4-response from %s missing " 2193 "DHCPv4 Message option.",
2198 memset(&enc_opt_data, 0,
sizeof(enc_opt_data));
2201 log_error(
"forw_dhcpv4_response: error evaluating " 2209 "no memory for encapsulated packet.");
2217 memset(&ds, 0,
sizeof(ds));
2219 log_error(
"forw_dhcpv4_response: no memory buffer.");
2224 ds.
len = enc_opt_data.
len + 16;
2233 cc = send(dhcp4o6_fd, ds.
data, ds.
len, 0);
2235 log_error(
"forw_dhcpv4_response: send(): %m");
2249 static void recv_dhcpv4_response(
struct data_string *raw)
2251 struct packet *packet;
2255 log_error(
"recv_dhcpv4_response: no interfaces.");
2267 log_error(
"recv_dhcpv4_response: no memory for packet.");
2279 log_error(
"recv_dhcpv4_response: no memory for options.");
2300 memset(&dp, 0,
sizeof dp);
2326 struct packet *packet;
2334 const char *
name = packet -> packet_type ?
"DHCPOFFER" :
"BOOTREPLY";
2343 for (client = ip -> client; client; client = client -> next)
2344 if (client -> xid == packet -> raw -> xid)
2351 (packet -> interface -> hw_address.hlen - 1 !=
2352 packet -> raw -> hlen) ||
2353 (memcmp (&packet -> interface -> hw_address.hbuf [1],
2354 packet -> raw -> chaddr, packet -> raw -> hlen))) {
2356 log_debug (
"%s in wrong transaction.", name);
2361 sprintf (obuf,
"%s from %s", name,
piaddr (packet -> client_addr));
2369 for (i = 0 ; req[i] != NULL ; i++) {
2376 option_code_hash_lookup(&option,
2381 log_info(
"%s: no %s option.", obuf,
2384 log_info(
"%s: no unknown-%u option.",
2395 for (lease = client -> offered_leases; lease; lease = lease -> next) {
2396 if (lease -> address.len ==
sizeof packet -> raw -> yiaddr &&
2397 !memcmp (lease -> address.iabuf,
2398 &packet -> raw -> yiaddr, lease -> address.len)) {
2406 log_info (
"%s: packet_to_lease failed.", obuf);
2412 if (!packet -> options_valid || !packet -> packet_type)
2413 lease -> is_bootp = 1;
2416 lease -> medium = client -> medium;
2419 stop_selecting = (client -> first_sending +
2420 client -> config -> select_interval);
2424 if (lease -> address.len == client -> requested_address.len &&
2425 !memcmp (lease -> address.iabuf,
2426 client -> requested_address.iabuf,
2427 client -> requested_address.len)) {
2428 lease -> next = client -> offered_leases;
2429 client -> offered_leases = lease;
2433 if (!client -> offered_leases)
2434 client -> offered_leases = lease;
2436 for (lp = client -> offered_leases; lp ->
next;
2446 if (stop_selecting <=
cur_tv.tv_sec)
2449 tv.tv_sec = stop_selecting;
2450 tv.tv_usec =
cur_tv.tv_usec;
2461 struct packet *packet;
2473 log_error(
"packet_to_lease: no memory to record lease.\n");
2477 memset(lease, 0,
sizeof(*lease));
2482 lease->address.len =
sizeof(packet->
raw->
yiaddr);
2483 memcpy(lease->address.iabuf, &packet->
raw->
yiaddr,
2484 lease->address.len);
2486 lease->next_srv_addr.len =
sizeof(packet->
raw->
siaddr);
2487 memcpy(lease->next_srv_addr.iabuf, &packet->
raw->
siaddr,
2488 lease->next_srv_addr.len);
2490 memset(&data, 0,
sizeof(data));
2492 if (client -> config -> vendor_space_name) {
2498 client -> config -> vendor_space_name &&
2500 (
struct lease *)0, client,
2504 if (!option_code_hash_lookup(&option,
2508 "option (%s:%d).",
MDL);
2512 client -> config -> vendor_space_name
2538 if (!(i & 2) && packet -> raw -> sname [0]) {
2542 if (!packet -> raw -> sname [len])
2546 log_error (
"dhcpoffer: no memory for server name.\n");
2551 packet -> raw -> sname, len);
2557 if (!(i & 1) && packet -> raw ->
file [0]) {
2561 if (!packet -> raw ->
file [len])
2565 log_error (
"dhcpoffer: no memory for filename.\n");
2570 packet -> raw ->
file, len);
2576 client, lease->options, lease->options,
2584 struct packet *packet;
2590 for (client = ip -> client; client; client = client ->
next)
2591 if (client ->
xid == packet -> raw ->
xid)
2597 (packet ->
interface -> hw_address.hlen - 1 !=
2598 packet -> raw -> hlen) ||
2599 (memcmp (&packet ->
interface -> hw_address.hbuf [1],
2600 packet -> raw -> chaddr, packet -> raw -> hlen))) {
2602 log_debug (
"DHCPNAK in wrong transaction.");
2617 log_info (
"DHCPNAK from %s (xid=0x%x)",
piaddr (packet -> client_addr), ntohl(client ->
xid));
2621 log_info (
"DHCPNAK with no active lease.\n");
2654 client -> state =
S_INIT;
2673 interval =
cur_time - client -> first_sending;
2677 if (interval > client -> config ->
timeout) {
2685 if (!client -> offered_leases &&
2686 client -> config -> media) {
2689 if (client -> medium) {
2690 client -> medium = client -> medium -> next;
2693 if (!client -> medium) {
2695 log_fatal (
"No valid media types for %s!",
2696 client -> interface -> name);
2698 client -> config -> media;
2702 log_info (
"Trying medium \"%s\" %d",
2703 client -> medium ->
string, increase);
2731 if (
cur_time + client -> interval >
2732 client -> first_sending + client -> config ->
timeout)
2733 client -> interval =
2734 (client -> first_sending +
2738 if (interval < 65536)
2739 client -> packet.secs = htons (interval);
2741 client -> packet.secs = htons (65535);
2742 client -> secs = client -> packet.secs;
2744 #if defined(DHCPv6) && defined(DHCP4o6) 2746 log_info (
"DHCPDISCOVER interval %ld",
2747 (
long)(client -> interval));
2750 log_info (
"DHCPDISCOVER on %s to %s port %d interval %ld (xid=0x%x)",
2751 client -> name ? client -> name : client -> interface -> name,
2753 ntohs (
sockaddr_broadcast.sin_port), (
long)(client -> interval), ntohl(client -> xid));
2756 #if defined(DHCPv6) && defined(DHCP4o6) 2758 result = send_dhcpv4_query(client, 1);
2765 #if defined(DHCPv6) && defined(DHCP4o6) 2767 log_error(
"%s:%d: Failed to send %d byte long packet.",
2771 log_error(
"%s:%d: Failed to send %d byte long packet over %s " 2783 tv.tv_usec = client->
interval > 1 ? random() % 1000000 :
cur_tv.tv_usec;
2800 loop = lp = client -> active;
2802 log_info (
"No DHCPOFFERS received.");
2806 if (!client -> active && client -> leases)
2810 while (client -> active) {
2811 if (client -> active -> expiry >
cur_time) {
2812 log_info (
"Trying recorded lease %s",
2813 piaddr (client -> active -> address));
2817 client -> active -> medium);
2820 if (client -> alias)
2828 if (cur_time < client -> active -> renewal) {
2830 log_info (
"bound: renewal in %ld %s.",
2831 (
long)(client -> active -> renewal -
2836 random() % 1000000 :
2841 log_info (
"bound: immediate renewal.");
2851 if (!client -> leases) {
2852 client -> leases = client -> active;
2860 for (lp = client -> leases; lp ->
next; lp = lp ->
next)
2862 lp ->
next = client -> active;
2866 client -> active = client -> leases;
2867 client -> leases = client -> leases ->
next;
2872 if (client -> active == loop)
2875 loop = client -> active;
2883 log_info (
"Unable to obtain a lease on first try.%s",
2887 #if defined (CALL_SCRIPT_ON_ONETRY_FAIL) 2895 log_info (
"No working leases in persistent database - sleeping.");
2897 if (client -> alias)
2900 client -> state =
S_INIT;
2903 tv.tv_usec = ((tv.tv_sec -
cur_tv.tv_sec) > 1) ?
2904 random() % 1000000 :
cur_tv.tv_usec;
2916 struct sockaddr_in destination;
2917 struct in_addr from;
2921 interval =
cur_time - client -> first_sending;
2935 interval > client -> config -> reboot_timeout) {
2937 client -> state =
S_INIT;
2946 !client -> medium &&
2947 client -> active -> medium ) {
2948 script_init(client,
"MEDIUM", client -> active -> medium);
2955 client -> medium = client -> active -> medium;
2961 cur_time > client -> active -> expiry) {
2966 if (client -> alias)
2974 if (client -> alias)
2979 client -> state =
S_INIT;
2985 if (!client -> interval)
2986 client -> interval = client -> config -> initial_interval;
2988 client -> interval += ((random () >> 2) %
2989 (2 * client -> interval));
2993 if (client -> interval >
2994 client -> config -> backoff_cutoff)
2995 client -> interval =
2996 ((client -> config -> backoff_cutoff / 2)
2997 + ((random () >> 2) %
2998 client -> config -> backoff_cutoff));
3003 cur_time + client -> interval > client -> active -> expiry)
3004 client -> interval =
3005 client -> active -> expiry -
cur_time + 1;
3011 cur_time > client -> active -> rebind)
3014 memcpy (&destination.sin_addr.s_addr,
3015 client -> destination.iabuf,
3016 sizeof destination.sin_addr.s_addr);
3018 destination.sin_family = AF_INET;
3020 destination.sin_len =
sizeof destination;
3025 memcpy (&from, client -> active -> address.iabuf,
3028 from.s_addr = INADDR_ANY;
3032 client -> packet.secs = client -> secs;
3034 if (interval < 65536)
3035 client -> packet.secs = htons (interval);
3037 client -> packet.secs = htons (65535);
3040 #if defined(DHCPv6) && defined(DHCP4o6) 3045 log_info (
"DHCPREQUEST on %s to %s port %d (xid=0x%x)",
3046 client -> name ? client -> name : client -> interface -> name,
3047 inet_ntoa (destination.sin_addr),
3048 ntohs (destination.sin_port), ntohl(client -> xid));
3050 #if defined(DHCPv6) && defined(DHCP4o6) 3053 if (destination.sin_addr.s_addr == INADDR_BROADCAST)
3055 result = send_dhcpv4_query(client, broadcast);
3057 log_error(
"%s:%d: Failed to send %d byte long packet.",
3062 if (destination.sin_addr.s_addr != INADDR_BROADCAST &&
3064 #if defined(SO_BINDTODEVICE) 3068 log_error(
"%s:%d: Failed to bind fallback interface" 3076 log_error(
"%s:%d: Failed to send %d byte long packet " 3077 "over %s interface.",
MDL,
3081 #if defined(SO_BINDTODEVICE) 3083 SO_BINDTODEVICE, NULL, 0) < 0) {
3084 log_fatal(
"%s:%d: Failed to unbind fallback interface:" 3095 log_error(
"%s:%d: Failed to send %d byte long packet" 3096 " over %s interface.",
MDL,
3103 tv.tv_usec = ((tv.tv_sec -
cur_tv.tv_sec) > 1) ?
3104 random() % 1000000 :
cur_tv.tv_usec;
3115 #if defined(DHCPv6) && defined(DHCP4o6) 3120 log_info (
"DHCPDECLINE on %s to %s port %d (xid=0x%x)",
3126 #if defined(DHCPv6) && defined(DHCP4o6) 3128 result = send_dhcpv4_query(client, 1);
3135 #if defined(DHCPv6) && defined(DHCP4o6) 3137 log_error(
"%s:%d: Failed to send %d byte long packet.",
3141 log_error(
"%s:%d: Failed to send %d byte long packet over %s" 3153 struct sockaddr_in destination;
3154 struct in_addr from;
3156 memcpy (&from, client -> active -> address.iabuf,
3158 memcpy (&destination.sin_addr.s_addr,
3159 client -> destination.iabuf,
3160 sizeof destination.sin_addr.s_addr);
3162 destination.sin_family = AF_INET;
3164 destination.sin_len =
sizeof destination;
3169 client -> active -> expiry =
3170 client -> active -> renewal =
3171 client -> active -> rebind =
cur_time;
3173 log_error (
"Can't release lease: lease write failed.");
3177 #if defined(DHCPv6) && defined(DHCP4o6) 3182 log_info (
"DHCPRELEASE on %s to %s port %d (xid=0x%x)",
3183 client -> name ? client -> name : client -> interface -> name,
3184 inet_ntoa (destination.sin_addr),
3185 ntohs (destination.sin_port), ntohl(client -> xid));
3187 #if defined(DHCPv6) && defined(DHCP4o6) 3190 if (destination.sin_addr.s_addr == INADDR_BROADCAST)
3192 result = send_dhcpv4_query(client, broadcast);
3194 log_error(
"%s:%d: Failed to send %d byte long packet.",
3200 #if defined(SO_BINDTODEVICE) 3204 log_error(
"%s:%d: Failed to bind fallback interface" 3212 log_error(
"%s:%d: Failed to send %d byte long packet" 3213 " over %s interface.",
MDL,
3217 #if defined(SO_BINDTODEVICE) 3219 SO_BINDTODEVICE, NULL, 0) < 0) {
3220 log_fatal(
"%s:%d: Failed to unbind fallback interface:" 3230 log_error (
"%s:%d: Failed to send %d byte long packet" 3231 " over %s interface.",
MDL,
3239 #if defined(DHCPv6) && defined(DHCP4o6) 3251 static int send_dhcpv4_query(
struct client_state *client,
int broadcast) {
3256 if (dhcp4o6_state <= 0) {
3257 log_info(
"send_dhcpv4_query: not ready.");
3267 memset(&ds, 0,
sizeof(ds));
3269 log_error(
"Unable to allocate memory for DHCPv4-query.");
3297 cc = send(dhcp4o6_fd, ds.
data, ds.
len, 0);
3299 log_error(
"send_dhcpv4_query: send(): %m");
3312 static void forw_dhcpv4_query(
struct data_string *raw) {
3318 struct sockaddr_in6 sin6;
3319 int i, send_ret, attempt, success;
3321 attempt = success = 0;
3322 memset(&sin6, 0,
sizeof(sin6));
3323 sin6.sin6_family = AF_INET6;
3326 sin6.sin6_len =
sizeof(sin6);
3328 memset(&addrs, 0,
sizeof(addrs));
3330 for (client = ip->
client; client != NULL;
3331 client = client->
next) {
3337 if ((lease == NULL) || lease->
released)
3346 ((addrs.
len %
sizeof(sin6.sin6_addr)) != 0)) {
3350 if (addrs.
len == 0) {
3358 if (send_ret == raw->
len)
3362 for (i = 0; i < addrs.
len;
3363 i +=
sizeof(sin6.sin6_addr)) {
3364 memcpy(&sin6.sin6_addr, addrs.
data + i,
3365 sizeof(sin6.sin6_addr));
3369 if (send_ret == raw->
len)
3376 log_info(
"forw_dhcpv4_query: sent(%d): %d/%d",
3377 raw->
len, success, attempt);
3393 struct buffer *bp = NULL;
3416 log_error (
"can't make requested address cache.");
3442 for (i = 0 ; prl[i] != NULL ; i++)
3447 log_error(
"can't make parameter list buffer.");
3452 for (i = 0 ; prl[i] != NULL ; i++)
3456 if (!(option_code_hash_lookup(&option,
3481 memset(&client_identifier, 0,
sizeof(client_identifier));
3484 client_identifier.
len,
MDL))
3485 log_fatal(
"no memory for default DUID!");
3503 memcpy(&client_identifier.
buffer->
data + 5 - hw_len,
3508 memcpy(&client_identifier.
buffer->
data+(1+4),
3515 (u_int8_t *)client_identifier.
data,
3516 client_identifier.
len,
3518 log_error (
"can't make requested client id cache..");
3529 (lease ? lease->
options : NULL),
3542 memset (&client -> packet, 0,
sizeof (client -> packet));
3546 lease ? &lease -> address : (
struct iaddr *)0,
3547 client -> config -> requested_options,
3551 client -> packet_length =
3553 (
struct lease *)0, client,
3562 client -> config -> vendor_space_name);
3569 client -> packet.htype = client ->
interface -> hw_address.hbuf [0];
3571 client -> packet.hlen = client ->
interface -> hw_address.hlen - 1;
3572 client -> packet.hops = 0;
3573 client -> packet.xid = random ();
3574 client -> packet.secs = 0;
3578 client -> packet.flags = 0;
3582 memset (&(client -> packet.ciaddr),
3583 0,
sizeof client -> packet.ciaddr);
3584 memset (&(client -> packet.yiaddr),
3585 0,
sizeof client -> packet.yiaddr);
3586 memset (&(client -> packet.siaddr),
3587 0,
sizeof client -> packet.siaddr);
3588 client -> packet.giaddr =
giaddr;
3589 if (client -> interface -> hw_address.hlen > 0)
3590 memcpy (client -> packet.chaddr,
3591 &client -> interface -> hw_address.hbuf [1],
3592 (
unsigned)(client -> interface -> hw_address.hlen - 1));
3595 dump_raw ((
unsigned char *)&client -> packet, client -> packet_length);
3607 memset (&client -> packet, 0,
sizeof (client -> packet));
3615 if (client -> sent_options)
3622 : (
struct iaddr *)0),
3623 client -> config -> requested_options,
3624 &client -> sent_options);
3627 client -> packet_length =
3629 (
struct lease *)0, client,
3632 client -> sent_options,
3638 client -> config -> vendor_space_name);
3644 client -> packet.htype = client ->
interface -> hw_address.hbuf [0];
3646 client -> packet.hlen = client ->
interface -> hw_address.hlen - 1;
3647 client -> packet.hops = 0;
3648 client -> packet.xid = client -> xid;
3649 client -> packet.secs = 0;
3653 if (client -> state ==
S_BOUND ||
3656 memcpy (&client -> packet.ciaddr,
3657 lease -> address.iabuf, lease -> address.len);
3658 client -> packet.flags = 0;
3660 memset (&client -> packet.ciaddr, 0,
3661 sizeof client -> packet.ciaddr);
3663 client ->config->bootp_broadcast_always)) &&
3665 client -> packet.flags = 0;
3670 memset (&client -> packet.yiaddr, 0,
3671 sizeof client -> packet.yiaddr);
3672 memset (&client -> packet.siaddr, 0,
3673 sizeof client -> packet.siaddr);
3674 if (client -> state !=
S_BOUND &&
3676 client -> packet.giaddr =
giaddr;
3678 memset (&client -> packet.giaddr, 0,
3679 sizeof client -> packet.giaddr);
3680 if (client -> interface -> hw_address.hlen > 0)
3681 memcpy (client -> packet.chaddr,
3682 &client -> interface -> hw_address.hbuf [1],
3683 (
unsigned)(client -> interface -> hw_address.hlen - 1));
3686 dump_raw ((
unsigned char *)&client -> packet, client -> packet_length);
3706 memset (&client -> packet, 0,
sizeof (client -> packet));
3707 client -> packet_length =
3709 (
struct lease *)0, client, 0,
3712 client -> config -> vendor_space_name);
3721 client -> packet.htype = client ->
interface -> hw_address.hbuf [0];
3723 client -> packet.hlen = client ->
interface -> hw_address.hlen - 1;
3724 client -> packet.hops = 0;
3725 client -> packet.xid = client -> xid;
3726 client -> packet.secs = 0;
3729 client -> packet.flags = 0;
3734 memset (&client -> packet.ciaddr, 0,
3735 sizeof client -> packet.ciaddr);
3736 memset (&client -> packet.yiaddr, 0,
3737 sizeof client -> packet.yiaddr);
3738 memset (&client -> packet.siaddr, 0,
3739 sizeof client -> packet.siaddr);
3740 client -> packet.giaddr =
giaddr;
3741 memcpy (client -> packet.chaddr,
3742 &client -> interface -> hw_address.hbuf [1],
3743 client -> interface -> hw_address.hlen);
3746 dump_raw ((
unsigned char *)&client -> packet, client -> packet_length);
3759 memset (&client -> packet, 0,
sizeof (client -> packet));
3766 client -> packet_length =
3768 (
struct lease *)0, client,
3777 client -> config -> vendor_space_name);
3784 client -> packet.htype = client ->
interface -> hw_address.hbuf [0];
3786 client -> packet.hlen = client ->
interface -> hw_address.hlen - 1;
3787 client -> packet.hops = 0;
3788 client -> packet.xid = random ();
3789 client -> packet.secs = 0;
3790 client -> packet.flags = 0;
3791 memcpy (&client -> packet.ciaddr,
3792 lease -> address.iabuf, lease -> address.len);
3793 memset (&client -> packet.yiaddr, 0,
3794 sizeof client -> packet.yiaddr);
3795 memset (&client -> packet.siaddr, 0,
3796 sizeof client -> packet.siaddr);
3797 client -> packet.giaddr =
giaddr;
3798 memcpy (client -> packet.chaddr,
3799 &client -> interface -> hw_address.hbuf [1],
3800 client -> interface -> hw_address.hlen);
3803 dump_raw ((
unsigned char *)&client -> packet, client -> packet_length);
3827 if (leaseFile != NULL)
3830 if (leaseFile == NULL) {
3842 for (client = ip -> client; client; client = client ->
next) {
3843 for (lp = client -> leases; lp; lp = lp ->
next) {
3846 if (client -> active)
3848 client -> active, 1, 0);
3863 for (client = ip -> client; client; client = client ->
next) {
3864 for (lp = client -> leases; lp; lp = lp ->
next) {
3867 if (client -> active)
3869 client -> active, 1, 0);
3884 struct packet *packet,
struct lease *lease,
3891 const char *name, *dot;
3893 char *preamble = stuff;
3895 memset (&ds, 0,
sizeof ds);
3905 in_options, cfg_options, scope, oc,
MDL)) {
3907 fprintf(leaseFile,
"%soption %s%s%s", preamble,
3913 fprintf(leaseFile,
" %s",
3919 fprintf(leaseFile,
";\n");
3928 const char *preamble)
3941 if (c >=
'0' && c <=
'9')
3944 if (c >=
'a' && c <=
'f')
3945 return c -
'a' + 10;
3947 if (c >=
'A' && c <=
'F')
3948 return c -
'A' + 10;
3955 const char *id_fname =
"/etc/machine-id";
3958 FILE *
file = fopen( id_fname ,
"r");
3961 return ISC_R_IOERROR;
3963 nread = fread(
id, 1,
sizeof id, file);
3967 log_debug(
"Not enough data in %s", id_fname);
3968 return ISC_R_IOERROR;
3971 for (
int j = 0; j < 16; j++) {
3977 if (a < 0 || b < 0) {
3978 log_debug(
"Wrong data in %s", id_fname);
3979 return ISC_R_IOERROR;
3981 uuid[j] = a << 4 | b;
3985 uuid[6] = (uuid[6] & 0x0F) | 0x40;
3987 uuid[8] = (uuid[8] & 0x3F) | 0x80;
3989 return ISC_R_SUCCESS;
4022 log_debug(
"Cannot form default DUID from interface %s.", ip->
name);
4026 return ISC_R_UNEXPECTED;
4031 log_fatal(
"Impossible hardware address length at %s:%d.",
MDL);
4041 len = 2 +
sizeof (uuid);
4055 log_fatal(
"no memory for default DUID!");
4061 memcpy(duid->
buffer->
data + 2, uuid,
sizeof(uuid));
4081 log_info(
"form_duid: Couldn't allocate memory to log duid!");
4087 return ISC_R_SUCCESS;
4097 if ((duid == NULL) || (duid->
len <= 2))
4100 if (leaseFile == NULL) {
4102 if (leaseFile == NULL) {
4104 return ISC_R_IOERROR;
4112 return ISC_R_NOMEMORY;
4114 stat = fprintf(leaseFile,
"default-duid %s;\n", str);
4117 return ISC_R_IOERROR;
4119 if (fflush(leaseFile) != 0)
4120 return ISC_R_IOERROR;
4122 return ISC_R_SUCCESS;
4128 int rewrite,
int sync)
4136 if (!rewrite && (leases_written++ > 20)) {
4139 return ISC_R_SUCCESS;
4142 if (client == NULL || lease == NULL)
4145 if (leaseFile == NULL) {
4147 if (leaseFile == NULL) {
4149 return ISC_R_IOERROR;
4153 stat = fprintf(leaseFile,
"lease6 {\n");
4155 return ISC_R_IOERROR;
4157 stat = fprintf(leaseFile,
" interface \"%s\";\n",
4160 return ISC_R_IOERROR;
4162 for (ia = lease->
bindings ; ia != NULL ; ia = ia->
next) {
4183 (
const unsigned char *) &ia->
iaid, 4,
4188 return ISC_R_IOERROR;
4191 stat = fprintf(leaseFile,
" %s %s {\n",
4199 stat = fprintf(leaseFile,
" %s %s {\n", ianame,
4205 return ISC_R_IOERROR;
4208 stat = fprintf(leaseFile,
" starts %d;\n" 4213 stat = fprintf(leaseFile,
" starts %d;\n",
4216 return ISC_R_IOERROR;
4218 for (addr = ia->
addrs ; addr != NULL ; addr = addr->
next) {
4220 stat = fprintf(leaseFile,
4224 stat = fprintf(leaseFile,
4225 " iaprefix %s/%d {\n",
4229 return ISC_R_IOERROR;
4231 stat = fprintf(leaseFile,
" starts %d;\n" 4232 " preferred-life %u;\n" 4237 return ISC_R_IOERROR;
4240 write_options(client, addr->
options,
" ");
4242 stat = fprintf(leaseFile,
" }\n");
4244 return ISC_R_IOERROR;
4248 write_options(client, ia->
options,
" ");
4250 stat = fprintf(leaseFile,
" }\n");
4252 return ISC_R_IOERROR;
4256 stat = fprintf(leaseFile,
" released;\n");
4258 return ISC_R_IOERROR;
4262 write_options(client, lease->
options,
" ");
4264 stat = fprintf(leaseFile,
"}\n");
4266 return ISC_R_IOERROR;
4268 if (fflush(leaseFile) != 0)
4269 return ISC_R_IOERROR;
4272 if (fsync(fileno(leaseFile)) < 0) {
4273 log_error(
"write_client_lease: fsync(): %m");
4274 return ISC_R_IOERROR;
4278 return ISC_R_SUCCESS;
4293 if (leases_written++ > 20) {
4301 if (lease -> is_static)
4304 if (leaseFile == NULL) {
4306 if (leaseFile == NULL) {
4313 fprintf (leaseFile,
"lease {\n");
4314 if (lease -> is_bootp) {
4315 fprintf (leaseFile,
" bootp;\n");
4321 fprintf (leaseFile,
" interface \"%s\";\n",
4322 client -> interface -> name);
4327 if (client -> name) {
4328 fprintf (leaseFile,
" name \"%s\";\n", client -> name);
4334 fprintf (leaseFile,
" fixed-address %s;\n",
4335 piaddr (lease -> address));
4340 if (lease -> filename) {
4343 fprintf (leaseFile,
" filename \"%s\";\n", s);
4356 fprintf(leaseFile,
" server-name \"%s\";\n", s);
4365 if (lease -> medium) {
4368 fprintf (leaseFile,
" medium \"%s\";\n", s);
4382 memset (&ds, 0,
sizeof ds);
4384 write_options(client, lease->
options,
" ");
4388 fprintf(leaseFile,
" renew %s\n", tval) < 0)
4393 fprintf(leaseFile,
" rebind %s\n", tval) < 0)
4398 fprintf(leaseFile,
" expire %s\n", tval) < 0)
4401 if (fprintf(leaseFile,
"}\n") < 0)
4404 if (fflush(leaseFile) != 0)
4409 if (!errors && makesure) {
4410 if (fsync (fileno (leaseFile)) < 0) {
4411 log_info (
"write_client_lease: %m");
4416 return errors ? 0 : 1;
4443 for (sl = client -> env; sl; sl =
next) {
4450 if (client -> interface) {
4452 client -> interface -> name);
4456 "",
"client",
"%s", client -> name);
4459 "",
"medium",
"%s", medium ->
string);
4462 client_envadd (client,
"",
"pid",
"%ld", (
long int)getpid ());
4469 struct packet *packet,
struct lease *lease,
4478 memset (&data, 0,
sizeof data);
4481 in_options, cfg_options, scope, oc,
MDL)) {
4491 length = strlen(value);
4495 value, length) == 0) {
4500 "option - discarded",
4540 prefix,
"ip_address",
"%s",
piaddr (lease -> address));
4556 memset (&data, 0,
sizeof data);
4559 (
struct lease *)0, client,
4564 struct iaddr netmask, subnet, broadcast;
4587 (&data, (
struct packet *)0,
4588 (
struct lease *)0, client,
4593 if (broadcast.
len) {
4595 prefix,
"broadcast_address",
4596 "%s",
piaddr (broadcast));
4612 "option - discarded",
4625 "option - discarded",
4639 (
unsigned long)(lease -> expiry));
4661 for (i = 0 ; req[i] != NULL ; i++) {
4686 char reason [] =
"REASON=NBI";
4687 static char client_path [] = CLIENT_PATH;
4690 int pid, wpid, wstatus;
4693 scriptName = client -> config -> script_name;
4697 envp =
dmalloc (((client ? client -> envc : 2) +
4700 log_error (
"No memory for client script environment.");
4706 for (sp = client_env; sp; sp = sp ->
next) {
4707 envp [i++] = sp ->
string;
4711 for (sp = client -> env; sp; sp = sp ->
next) {
4712 envp [i++] = sp ->
string;
4715 envp [i++] = reason;
4718 envp [i++] = client_path;
4719 envp [i] = (
char *)0;
4722 argv [1] = (
char *)0;
4730 wpid = wait (&wstatus);
4731 }
while (wpid != pid && wpid > 0);
4740 if (leaseFile != NULL)
4742 execve (scriptName, argv, envp);
4743 log_error (
"execve (%s, ...): %m", scriptName);
4748 for (sp = client -> env; sp; sp =
next) {
4756 gettimeofday(&
cur_tv, NULL);
4757 return (WIFEXITED (wstatus) ?
4758 WEXITSTATUS (wstatus) : -WTERMSIG (wstatus));
4762 const char *prefix,
const char *name,
const char *fmt, ...)
4770 va_start (list, fmt);
4771 len = vsnprintf (spbuf,
sizeof spbuf, fmt, list);
4774 val =
dmalloc (strlen (prefix) + strlen (name) + 1 +
4775 len +
sizeof *val,
MDL);
4777 log_error (
"client_envadd: cannot allocate space for variable");
4786 if (len >=
sizeof spbuf) {
4787 va_start (list, fmt);
4788 vsnprintf (s, len + 1, fmt, list);
4794 val ->
next = client -> env;
4795 client -> env = val;
4818 if (j + 1 == buflen)
4828 if (j + 1 == buflen)
4841 static int state = 0;
4859 if ((pid = fork ()) < 0)
4872 (void) open(
"/dev/null", O_RDWR | O_CLOEXEC);
4873 (void) open(
"/dev/null", O_RDWR | O_CLOEXEC);
4874 (void) open(
"/dev/null", O_RDWR | O_CLOEXEC);
4891 pfdesc = open (
path_dhclient_pid, O_CREAT | O_TRUNC | O_WRONLY | O_CLOEXEC, 0644);
4898 pf = fdopen (pfdesc,
"we");
4903 fprintf (pf,
"%ld\n", (
long)getpid ());
4914 for (client = ip -> client; client; client = client ->
next) {
4915 switch (client ->
state) {
4948 #if defined(DHCPv6) && defined(DHCP4o6) 4950 if (dhcp4o6_state < 0)
4958 client -> xid = random ();
4961 if (client -> active) {
4966 memset (&ds, 0,
sizeof ds);
4968 client -> active -> options,
4972 (
struct lease *)0, client,
4974 client -> active -> options,
4977 memcpy (client -> destination.iabuf,
4979 client -> destination.len = 4;
4986 client -> first_sending =
cur_time;
4987 client -> interval = client -> config -> initial_interval;
4998 if (client -> alias)
5014 #if defined(DHCPv6) && defined(DHCP4o6) 5033 if (!strcmp (ip ->
name, tmp ->
name)) {
5037 interface_reference (&ip, last ->
next,
MDL);
5038 interface_dereference (&last ->
next,
MDL);
5040 interface_reference (&last ->
next,
5042 interface_dereference (&ip ->
next,
5047 interface_reference (&ip,
5053 interface_dereference (&ip ->
next,
5059 tmp -> client = ip ->
client;
5060 tmp -> client ->
interface = tmp;
5062 interface_dereference (&ip,
MDL);
5097 if (ip -> client ->
alias)
5099 ip -> client ->
alias);
5111 for (client = ip->
client ; client ; client = client->
next) {
5116 return ISC_R_SUCCESS;
5123 struct packet *packet;
5142 static void shutdown_exit (
void *foo)
5150 #if defined (NSUPDATE) 5167 isc_result_t eresult)
5170 isc_result_t result;
5172 if ((eresult == ISC_R_SUCCESS) &&
5178 if (result == ISC_R_SUCCESS) {
5184 dhclient_ddns_cb_free(ddns_cb,
MDL);
5193 isc_result_t result;
5196 if (client->
ddns_cb != NULL) {
5202 if (ddns_cb != NULL) {
5208 ddns_cb->
cur_func = client_dns_remove_action;
5212 if (result != ISC_R_TIMEDOUT) {
5213 dhclient_ddns_cb_free(ddns_cb,
MDL);
5229 return ISC_R_SUCCESS;
5233 log_info(
"Received signal %d, initiating shutdown.",
5242 for (client = ip -> client; client; client = client -> next) {
5245 return ISC_R_SUCCESS;
5248 return ISC_R_SUCCESS;
5251 if (client -> active &&
5252 client -> active -> expiry >
cur_time) {
5253 #if defined (NSUPDATE) 5275 tv.tv_sec =
cur_tv.tv_sec;
5276 tv.tv_usec =
cur_tv.tv_usec + 1;
5279 return ISC_R_SUCCESS;
5282 #if defined (NSUPDATE) 5293 isc_result_t status = ISC_R_FAILURE;
5295 if ((client != NULL) &&
5296 ((client->
active != NULL) ||
5309 if (status != ISC_R_TIMEDOUT) {
5310 dhclient_ddns_cb_free(ddns_cb,
MDL);
5345 isc_result_t eresult)
5347 isc_result_t result;
5364 ddns_cb->
cur_func = client_dns_update_action;
5367 if (result == ISC_R_SUCCESS) {
5373 case ISC_R_TIMEDOUT:
5381 if (ddns_cb->
zone != NULL) {
5387 ddns_cb->
cur_func = client_dns_update_action;
5393 tv.tv_usec =
cur_tv.tv_usec;
5395 ddns_cb, NULL, NULL);
5399 dhclient_ddns_cb_free(ddns_cb,
MDL);
5417 if (!client -> sent_options)
5418 return ISC_R_SUCCESS;
5422 return ISC_R_SUCCESS;
5428 (
struct lease *)0, client,
5429 client -> sent_options,
5432 return ISC_R_SUCCESS;
5439 (
struct lease *)0, client,
5440 client -> sent_options,
5443 return ISC_R_SUCCESS;
5449 (
struct lease *)0, client,
5450 client -> sent_options,
5453 return ISC_R_SUCCESS;
5465 memset(&client_identifier, 0,
sizeof(client_identifier));
5489 client_identifier.
data,
5490 client_identifier.
len);
5508 (client_identifier.
data[0] == 255)) {
5513 if (client_identifier.
len <= 5)
5514 log_fatal(
"Impossible condition at %s:%d.",
5517 client_identifier.
data + 5,
5518 client_identifier.
len - 5);
5520 result =
get_dhcid(ddns_cb, ddns_v4_type,
5521 client_identifier.
data,
5522 client_identifier.
len);
5532 return ISC_R_SUCCESS;
5541 rcode = ISC_R_FAILURE;
5547 if (rcode == ISC_R_SUCCESS) {
5548 rcode = ISC_R_TIMEDOUT;
5571 if (client->
ddns_cb != NULL) {
5578 if (ddns_cb != NULL) {
5579 ddns_cb->
lease = (
void *)client;
5592 ddns_cb->
cur_func = client_dns_update_action;
5596 tv.tv_sec =
cur_tv.tv_sec + offset;
5597 tv.tv_usec =
cur_tv.tv_usec;
5599 ddns_cb, NULL, NULL);
5601 log_error(
"Unable to allocate dns update state for %s",
5610 struct servent *ent;
5624 ent = getservbyname(
"dhcpc",
"udp");
5626 ent = getservbyname(
"bootpc",
"udp");
5631 #ifndef __CYGWIN32__ 5655 static int check_domain_name(
const char *ptr,
size_t len,
int dots)
5660 if ((len == 0) || (len > 256))
5665 for (p=ptr; (*p != 0) && (len-- > 0); p++) {
5666 if ((*p ==
'-') || (*p ==
'_')) {
5668 if (((p - ptr) == 0) || (len == 0) || (p[1] ==
'.'))
5670 }
else if (*p ==
'.') {
5674 if ((d <= 0) || (d >= 64))
5677 if ((dots > 0) && (len > 0))
5679 }
else if (isalnum((
unsigned char)*p) == 0) {
5684 return(dots ? -1 : 0);
5687 static int check_domain_name_list(
const char *ptr,
size_t len,
int dots)
5692 if ((ptr == NULL) || (len == 0))
5695 for (p=ptr; (*p != 0) && (len > 0); p++, len--) {
5699 if (check_domain_name(ptr, p - ptr, dots) != 0)
5706 return(check_domain_name(ptr, p - ptr, dots));
5723 #ifdef ACCEPT_LIST_IN_DOMAIN_NAME 5724 return check_domain_name_list(ptr, len, 0);
5726 return check_domain_name(ptr, len, 0);
5731 return check_domain_name(ptr, len, 0);
5734 return check_domain_name_list(ptr, len, 0);
5739 for (; (*ptr != 0) && (len-- > 0); ptr++) {
5740 if(!(isalnum((
unsigned char)*ptr) ||
5741 *ptr ==
'#' || *ptr ==
'%' ||
5742 *ptr ==
'+' || *ptr ==
'-' ||
5743 *ptr ==
'_' || *ptr ==
':' ||
5744 *ptr ==
'.' || *ptr ==
',' ||
5745 *ptr ==
'@' || *ptr ==
'~' ||
5746 *ptr ==
'\\' || *ptr ==
'/' ||
5747 *ptr ==
'[' || *ptr ==
']' ||
5748 *ptr ==
'=' || *ptr ==
' '))
5763 return check_domain_name_list(ptr, len, 0);
5773 add_reject(
struct packet *packet) {
5778 log_fatal (
"no memory for reject list!");
5797 log_info(
"Server added to list of rejected servers.");
5806 if (client != NULL) {
5814 #if defined(DHCPv6) && defined(DHCP4o6) 5833 char start_msg[5] = {
'S',
'T',
'A',
'R',
'T' };
5834 char stop_msg[4] = {
'S',
'T',
'O',
'P' };
5835 char poll_msg[4] = {
'P',
'O',
'L',
'L' };
5839 if (h->type != dhcp4o6_type)
5842 cc = recv(dhcp4o6_fd, buf,
sizeof(buf), 0);
5844 return ISC_R_UNEXPECTED;
5848 (memcmp(buf, poll_msg,
sizeof(poll_msg)) == 0)) {
5850 if (dhcp4o6_state < 0)
5851 cc = send(dhcp4o6_fd, stop_msg,
5852 sizeof(stop_msg), 0);
5854 cc = send(dhcp4o6_fd, start_msg,
5855 sizeof(start_msg), 0);
5857 log_error(
"dhcpv4o6_handler: send(): %m");
5858 return ISC_R_IOERROR;
5862 return ISC_R_UNEXPECTED;
5863 memset(&raw, 0,
sizeof(raw));
5866 "no memory buffer.");
5867 return ISC_R_NOMEMORY;
5873 forw_dhcpv4_query(&raw);
5879 (memcmp(buf, stop_msg,
sizeof(stop_msg)) == 0)) {
5881 if (dhcp4o6_state > 0) {
5885 }
else if ((cc == 5) &&
5886 (memcmp(buf, start_msg,
sizeof(start_msg)) == 0)) {
5888 if (dhcp4o6_state == 0)
5894 return ISC_R_UNEXPECTED;
5895 memset(&raw, 0,
sizeof(raw));
5898 "no memory buffer.");
5899 return ISC_R_NOMEMORY;
5905 recv_dhcpv4_response(&raw);
5911 return ISC_R_SUCCESS;
5922 static void dhcp4o6_poll(
void *dummy) {
5923 char msg[4] = {
'P',
'O',
'L',
'L' };
5929 if (dhcp4o6_state < 0)
5934 cc = send(dhcp4o6_fd, msg,
sizeof(msg), 0);
5939 tv.tv_usec = random() % 1000000;
5951 static void dhcp4o6_resume() {
5956 for (client = ip->
client; client != NULL;
5957 client = client->
next) {
5980 char msg[5] = {
'S',
'T',
'A',
'R',
'T' };
5983 memset(&addrs, 0,
sizeof(addrs));
5985 for (client = ip->
client; client != NULL;
5986 client = client->
next) {
5992 if ((lease == NULL) || lease->
released)
6002 if ((addrs.
len % 16) != 0) {
6015 if (dhcp4o6_state == 1)
6017 log_info(
"dhcp4o6_start: go to UP");
6020 cc = send(dhcp4o6_fd, msg,
sizeof(msg), 0);
6022 log_info(
"dhcp4o6_start: send(): %m");
6032 static void dhcp4o6_stop() {
6033 char msg[4] = {
'S',
'T',
'O',
'P' };
6036 if (dhcp4o6_state == -1)
6039 log_info(
"dhcp4o6_stop: go to DOWN");
6042 cc = send(dhcp4o6_fd, msg,
sizeof(msg), 0);
void do_packet6(struct interface_info *, const char *, int, int, const struct iaddr *, isc_boolean_t)
void state_selecting(void *cpp)
#define DHCP_FIXED_NON_UDP
#define _PATH_DHCLIENT_CONF
void(* dhcpv6_packet_handler)(struct interface_info *, const char *, int, int, const struct iaddr *, isc_boolean_t)
void send_discover(void *cpp)
void unbill_class(struct lease *lease)
struct client_lease * alias
int parse_encapsulated_suboptions(struct option_state *options, struct option *eopt, const unsigned char *buffer, unsigned len, struct universe *eu, const char *uname)
isc_result_t omapi_protocol_listen(omapi_object_t *, unsigned, int)
struct binding_scope * global_scope
#define _PATH_DHCLIENT_PID
struct universe * universe
void make_client_options(struct client_state *client, struct client_lease *lease, u_int8_t *type, struct option_cache *sid, struct iaddr *rip, struct option **prl, struct option_state **op)
struct group * on_receipt
unsigned char dhcpv6_transaction_id[3]
#define _PATH_DHCLIENT_SCRIPT
void save_option(struct universe *universe, struct option_state *options, struct option_cache *oc)
struct client_lease * new
void do_release(struct client_state *client)
const char * piaddr(const struct iaddr addr)
void rewrite_client_leases()
#define FQDN_NO_CLIENT_UPDATE
#define DHO_DOMAIN_SEARCH
#define DDNS_STATE_ADD_FW_NXDOMAIN
void dhcpoffer(struct packet *packet)
unsigned char dhcpv6_transaction_id[3]
int make_const_option_cache(struct option_cache **oc, struct buffer **buffer, u_int8_t *data, unsigned len, struct option *option, const char *file, int line)
void dhcpnak(struct packet *packet)
int get_dhcid(dhcp_ddns_cb_t *, int, const u_int8_t *, unsigned)
isc_result_t end_parse(struct parse **cfile)
const char * path_dhclient_db
void(* bootp_packet_handler)(struct interface_info *, struct dhcp_packet *, unsigned, unsigned int, struct iaddr, struct hardware *)
#define All_DHCP_Relay_Agents_and_Servers
void start_release6(struct client_state *client)
char * piaddrmask(struct iaddr *addr, struct iaddr *mask)
struct iaddr next_srv_addr
int option_cache_dereference(struct option_cache **ptr, const char *file, int line)
void start_info_request6(struct client_state *client)
void send_decline(void *cpp)
void client_dns_update_timeout(void *cp)
void cancel_timeout(void(*)(void *) where, void *what)
#define print_hex_1(len, data, limit)
#define DHO_DHCP_PARAMETER_REQUEST_LIST
int dhcp_max_agent_option_packet_length
struct client_lease * packet_to_lease(struct packet *packet, struct client_state *client)
#define DHCP_R_INVALIDARG
struct group * on_transmission
#define DISCOVER_REQUESTED
int script_go(struct client_state *client)
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
struct dhc6_ia * bindings
const char * path_dhclient_duid
enum dhcp_token peek_token(const char **rval, unsigned *rlen, struct parse *cfile)
struct data_string fwd_name
void write_client_pid_file()
void state_panic(void *cpp)
void forget_zone(struct dns_zone **)
struct data_string default_duid
struct option_state * options
void ddns_cb_free(dhcp_ddns_cb_t *ddns_cb, const char *file, int line)
void do_packet(struct interface_info *interface, struct dhcp_packet *packet, unsigned len, unsigned int from_port, struct iaddr from, struct hardware *hfrom)
#define D6O_NIS_DOMAIN_NAME
unsigned char dhcpv6_msg_type
#define DHO_DHCP_SERVER_IDENTIFIER
void log_fatal(const char *,...) __attribute__((__format__(__printf__
void(* v6_handler)(struct packet *, struct client_state *)
#define DHCP_CONTEXT_POST_DB
enum dhcp_pending pending
isc_result_t form_duid(struct data_string *duid, const char *file, int line)
struct executable_statement * statements
void state_init(void *cpp)
#define INTERFACE_AUTOMATIC
int option_state_reference(struct option_state **ptr, struct option_state *bp, const char *file, int line)
const char * print_time(TIME t)
struct option * default_requested_options[]
void read_client_leases()
struct option_state * options
struct iaddr subnet_number(struct iaddr addr, struct iaddr mask)
u_int16_t validate_port(char *port)
void dhcp_signal_handler(int signal)
int find_subnet(struct subnet **sp, struct iaddr addr, const char *file, int line)
void execute_statements_in_scope(struct binding_value **result, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *out_options, struct binding_scope **scope, struct group *group, struct group *limiting_group, struct on_star *on_star)
void make_request(struct client_state *client, struct client_lease *lease)
struct interface_info * fallback_interface
isc_result_t dhclient_interface_startup_hook(struct interface_info *interface)
int option_state_allocate(struct option_state **ptr, const char *file, int line)
const char * path_dhclient_pid
struct iaddrmatchlist * next
void client_option_envadd(struct option_cache *oc, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, struct universe *u, void *stuff)
isc_result_t dhcp_context_create(int flags, struct in_addr *local4, struct in6_addr *local6)
int evaluate_option_cache(struct data_string *result, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, struct option_cache *oc, const char *file, int line)
#define DHCPV6_DHCPV4_RESPONSE
int write_host(struct host_decl *host)
struct option_state * options
struct option ** requested_options
void classify(struct packet *packet, struct class *class)
void script_init(struct client_state *client, const char *reason, struct string_list *medium)
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