Blame SOURCES/dhcp-dhclient-options.patch

324fcf
diff --git a/client/clparse.c b/client/clparse.c
324fcf
index 03190c3..2033427 100644
324fcf
--- a/client/clparse.c
324fcf
+++ b/client/clparse.c
324fcf
@@ -189,6 +189,7 @@ isc_result_t read_client_conf ()
324fcf
 	/* Requested lease time, used by DHCPv6 (DHCPv4 uses the option cache)
324fcf
 	 */
324fcf
 	top_level_config.requested_lease = 7200;
324fcf
+	top_level_config.bootp_broadcast_always = 0;
324fcf
 
324fcf
 	group_allocate (&top_level_config.on_receipt, MDL);
324fcf
 	if (!top_level_config.on_receipt)
324fcf
@@ -394,7 +395,8 @@ void read_client_leases ()
324fcf
 	interface-declaration |
324fcf
 	LEASE client-lease-statement |
324fcf
 	ALIAS client-lease-statement |
324fcf
-	KEY key-definition */
324fcf
+	KEY key-definition |
324fcf
+	BOOTP_BROADCAST_ALWAYS */
324fcf
 
324fcf
 void parse_client_statement (cfile, ip, config)
324fcf
 	struct parse *cfile;
324fcf
@@ -817,6 +819,12 @@ void parse_client_statement (cfile, ip, config)
324fcf
 		parse_lease_id_format(cfile);
324fcf
 		break;
324fcf
 
324fcf
+	      case BOOTP_BROADCAST_ALWAYS:
324fcf
+		token = next_token(&val, (unsigned*)0, cfile);
324fcf
+		config -> bootp_broadcast_always = 1;
324fcf
+		parse_semi (cfile);
324fcf
+		return;
324fcf
+
324fcf
 
324fcf
 	      default:
324fcf
 		lose = 0;
324fcf
diff --git a/client/dhclient.8 b/client/dhclient.8
324fcf
index 24f8f12..aa2238d 100644
324fcf
--- a/client/dhclient.8
324fcf
+++ b/client/dhclient.8
324fcf
@@ -134,6 +134,33 @@ dhclient - Dynamic Host Configuration Protocol Client
324fcf
 .B -w
324fcf
 ]
324fcf
 [
324fcf
+.B -B
324fcf
+]
324fcf
+[
324fcf
+.B -C
324fcf
+.I dhcp-client-identifier
324fcf
+]
324fcf
+[
324fcf
+.B -H
324fcf
+.I host-name
324fcf
+]
324fcf
+[
324fcf
+.B -F
324fcf
+.I fqdn.fqdn
324fcf
+]
324fcf
+[
324fcf
+.B -V
324fcf
+.I vendor-class-identifier
324fcf
+]
324fcf
+[
324fcf
+.B --request-options
324fcf
+.I request-option-list
324fcf
+]
324fcf
+[
324fcf
+.B --timeout
324fcf
+.I timeout
324fcf
+]
324fcf
+[
324fcf
 .B --dad-wait-time
324fcf
 .I seconds
324fcf
 ]
324fcf
diff --git a/client/dhclient.c b/client/dhclient.c
324fcf
index dcf3f1a..270a960 100644
324fcf
--- a/client/dhclient.c
324fcf
+++ b/client/dhclient.c
324fcf
@@ -40,6 +40,12 @@
324fcf
 #include <isc/file.h>
324fcf
 #include <dns/result.h>
324fcf
 
324fcf
+/*
324fcf
+ * Defined in stdio.h when _GNU_SOURCE is set, but we don't want to define
324fcf
+ * that when building ISC code.
324fcf
+ */
324fcf
+extern int asprintf(char **strp, const char *fmt, ...);
324fcf
+
324fcf
 TIME default_lease_time = 43200; /* 12 hours... */
324fcf
 TIME max_lease_time = 86400; /* 24 hours... */
324fcf
 
324fcf
@@ -101,6 +107,10 @@ char *mockup_relay = NULL;
324fcf
 
324fcf
 char *progname = NULL;
324fcf
 
324fcf
+int bootp_broadcast_always = 0;
324fcf
+
324fcf
+extern struct option *default_requested_options[];
324fcf
+
324fcf
 void run_stateless(int exit_mode, u_int16_t port);
324fcf
 
324fcf
 static isc_result_t write_duid(struct data_string *duid);
324fcf
@@ -179,7 +189,11 @@ usage(const char *sfmt, const char *sarg)
324fcf
 		  "                [-s server-addr] [-cf config-file]\n"
324fcf
 		  "                [-df duid-file] [-lf lease-file]\n"
324fcf
 		  "                [-pf pid-file] [--no-pid] [-e VAR=val]\n"
324fcf
-		  "                [-sf script-file] [interface]*",
324fcf
+		  "                [-sf script-file] [interface]*\n"
324fcf
+		  "                [-C <dhcp-client-identifier>] [-B]\n"
324fcf
+		  "                [-H <host-name> | -F <fqdn.fqdn>] [--timeout <timeout>]\n"
324fcf
+		  "                [-V <vendor-class-identifier>]\n"
324fcf
+		  "                [--request-options <request option list>]",
324fcf
 		  isc_file_basename(progname));
324fcf
 }
324fcf
 
324fcf
@@ -216,6 +230,16 @@ main(int argc, char **argv) {
324fcf
 	progname = argv[0];
324fcf
 #endif
324fcf
 
324fcf
+	char *dhcp_client_identifier_arg = NULL;
324fcf
+	char *dhcp_host_name_arg = NULL;
324fcf
+	char *dhcp_fqdn_arg = NULL;
324fcf
+	char *dhcp_vendor_class_identifier_arg = NULL;
324fcf
+	char *dhclient_request_options = NULL;
324fcf
+
324fcf
+	int timeout_arg = 0;
324fcf
+	char *arg_conf = NULL;
324fcf
+	int arg_conf_len = 0;
324fcf
+
324fcf
 	/* Initialize client globals. */
324fcf
 	memset(&default_duid, 0, sizeof(default_duid));
324fcf
 
324fcf
@@ -442,6 +466,88 @@ main(int argc, char **argv) {
324fcf
 					 strlen(PACKAGE_VERSION)));
324fcf
 			IGNORE_RET(write(STDERR_FILENO, "\n", 1));
324fcf
 			exit(0);
324fcf
+		} else if (!strcmp(argv[i], "-C")) {
324fcf
+			if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
324fcf
+				usage(use_noarg, argv[i-1]);
324fcf
+				exit(1);
324fcf
+			}
324fcf
+
324fcf
+			if (strlen(argv[i]) >= DHCP_MAX_OPTION_LEN) {
324fcf
+				log_error("-C option dhcp-client-identifier string \"%s\" is too long - maximum length is: %d", argv[i], DHCP_MAX_OPTION_LEN-1);
324fcf
+				exit(1);
324fcf
+			}
324fcf
+
324fcf
+			dhcp_client_identifier_arg = argv[i];
324fcf
+		} else if (!strcmp(argv[i], "-B")) {
324fcf
+			bootp_broadcast_always = 1;
324fcf
+		} else if (!strcmp(argv[i], "-H")) {
324fcf
+			if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
324fcf
+				usage(use_noarg, argv[i-1]);
324fcf
+				exit(1);
324fcf
+			}
324fcf
+
324fcf
+			if (strlen(argv[i]) >= DHCP_MAX_OPTION_LEN) {
324fcf
+				log_error("-H option host-name string \"%s\" is too long - maximum length is: %d", argv[i], DHCP_MAX_OPTION_LEN-1);
324fcf
+				exit(1);
324fcf
+			}
324fcf
+
324fcf
+			if (dhcp_host_name_arg != NULL) {
324fcf
+				log_error("The -H <host-name> and -F <fqdn> arguments are mutually exclusive");
324fcf
+				exit(1);
324fcf
+			}
324fcf
+
324fcf
+			dhcp_host_name_arg = argv[i];
324fcf
+		} else if (!strcmp(argv[i], "-F")) {
324fcf
+			if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
324fcf
+				usage(use_noarg, argv[i-1]);
324fcf
+				exit(1);
324fcf
+			}
324fcf
+
324fcf
+			if (strlen(argv[i]) >= DHCP_MAX_OPTION_LEN) {
324fcf
+				log_error("-F option fqdn.fqdn string \"%s\" is too long - maximum length is: %d", argv[i], DHCP_MAX_OPTION_LEN-1);
324fcf
+				exit(1);
324fcf
+			}
324fcf
+
324fcf
+			if (dhcp_fqdn_arg != NULL) {
324fcf
+				log_error("Only one -F <fqdn> argument can be specified");
324fcf
+				exit(1);
324fcf
+			}
324fcf
+
324fcf
+			if (dhcp_host_name_arg != NULL) {
324fcf
+				log_error("The -F <fqdn> and -H <host-name> arguments are mutually exclusive");
324fcf
+				exit(1);
324fcf
+			}
324fcf
+
324fcf
+			dhcp_fqdn_arg = argv[i];
324fcf
+		} else if (!strcmp(argv[i], "--timeout")) {
324fcf
+			if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
324fcf
+				usage(use_noarg, argv[i-1]);
324fcf
+				exit(1);
324fcf
+			}
324fcf
+
324fcf
+			if ((timeout_arg = atoi(argv[i])) <= 0) {
324fcf
+				log_error("timeout option must be > 0 - bad value: %s",argv[i]);
324fcf
+				exit(1);
324fcf
+			}
324fcf
+		} else if (!strcmp(argv[i], "-V")) {
324fcf
+			if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
324fcf
+				usage(use_noarg, argv[i-1]);
324fcf
+				exit(1);
324fcf
+			}
324fcf
+
324fcf
+			if (strlen(argv[i]) >= DHCP_MAX_OPTION_LEN) {
324fcf
+				log_error("-V option vendor-class-identifier string \"%s\" is too long - maximum length is: %d", argv[i], DHCP_MAX_OPTION_LEN-1);
324fcf
+				exit(1);
324fcf
+			}
324fcf
+
324fcf
+			dhcp_vendor_class_identifier_arg = argv[i];
324fcf
+		} else if (!strcmp(argv[i], "--request-options")) {
324fcf
+			if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
324fcf
+				usage(use_noarg, argv[i-1]);
324fcf
+				exit(1);
324fcf
+			}
324fcf
+
324fcf
+			dhclient_request_options = argv[i];
324fcf
 		} else if (argv[i][0] == '-') {
324fcf
 			usage("Unknown command: %s", argv[i]);
324fcf
 		} else if (interfaces_requested < 0) {
324fcf
@@ -641,6 +747,156 @@ main(int argc, char **argv) {
324fcf
 	/* Parse the dhclient.conf file. */
324fcf
 	read_client_conf();
324fcf
 
324fcf
+	/* Parse any extra command line configuration arguments: */
324fcf
+	if ((dhcp_client_identifier_arg != NULL) && (*dhcp_client_identifier_arg != '\0')) {
324fcf
+		arg_conf_len = asprintf(&arg_conf, "send dhcp-client-identifier \"%s\";", dhcp_client_identifier_arg);
324fcf
+
324fcf
+		if ((arg_conf == 0) || (arg_conf_len <= 0))
324fcf
+			log_fatal("Unable to send -C option dhcp-client-identifier");
324fcf
+	}
324fcf
+
324fcf
+	if ((dhcp_host_name_arg != NULL) && (*dhcp_host_name_arg != '\0')) {
324fcf
+		if (arg_conf == 0) {
324fcf
+			arg_conf_len = asprintf(&arg_conf, "send host-name \"%s\";", dhcp_host_name_arg);
324fcf
+
324fcf
+			if ((arg_conf == 0) || (arg_conf_len <= 0))
324fcf
+				log_fatal("Unable to send -H option host-name");
324fcf
+		} else {
324fcf
+			char *last_arg_conf = arg_conf;
324fcf
+			arg_conf = NULL;
324fcf
+			arg_conf_len = asprintf(&arg_conf, "%s\nsend host-name \"%s\";", last_arg_conf, dhcp_host_name_arg);
324fcf
+
324fcf
+			if ((arg_conf == 0) || (arg_conf_len <= 0))
324fcf
+				log_fatal("Unable to send -H option host-name");
324fcf
+
324fcf
+			free(last_arg_conf);
324fcf
+		}
324fcf
+	}
324fcf
+
324fcf
+	if ((dhcp_fqdn_arg != NULL) && (*dhcp_fqdn_arg != '\0')) {
324fcf
+		if (arg_conf == 0) {
324fcf
+			arg_conf_len = asprintf(&arg_conf,  "send fqdn.fqdn \"%s\";", dhcp_fqdn_arg);
324fcf
+
324fcf
+			if ((arg_conf == 0) || (arg_conf_len <= 0))
324fcf
+				log_fatal("Unable to send -F option fqdn.fqdn");
324fcf
+		} else {
324fcf
+			char *last_arg_conf = arg_conf;
324fcf
+			arg_conf = NULL;
324fcf
+			arg_conf_len = asprintf(&arg_conf, "%s\nsend fqdn.fqdn \"%s\";", last_arg_conf, dhcp_fqdn_arg);
324fcf
+
324fcf
+			if ((arg_conf == 0)  || (arg_conf_len <= 0))
324fcf
+				log_fatal("Unable to send -F option fqdn.fqdn");
324fcf
+
324fcf
+			free(last_arg_conf);
324fcf
+		}
324fcf
+	}
324fcf
+
324fcf
+	if (timeout_arg) {
324fcf
+		if (arg_conf == 0) {
324fcf
+			arg_conf_len = asprintf(&arg_conf,  "timeout %d;", timeout_arg);
324fcf
+
324fcf
+			if ((arg_conf == 0) || (arg_conf_len <= 0))
324fcf
+				log_fatal("Unable to process --timeout timeout argument");
324fcf
+		} else {
324fcf
+			char *last_arg_conf = arg_conf;
324fcf
+			arg_conf = NULL;
324fcf
+			arg_conf_len = asprintf(&arg_conf, "%s\ntimeout %d;", last_arg_conf, timeout_arg);
324fcf
+
324fcf
+			if ((arg_conf == 0) || (arg_conf_len == 0))
324fcf
+				log_fatal("Unable to process --timeout timeout argument");
324fcf
+
324fcf
+			free(last_arg_conf);
324fcf
+		}
324fcf
+	}
324fcf
+
324fcf
+	if ((dhcp_vendor_class_identifier_arg != NULL) && (*dhcp_vendor_class_identifier_arg != '\0')) {
324fcf
+		if (arg_conf == 0) {
324fcf
+			arg_conf_len = asprintf(&arg_conf,  "send vendor-class-identifier \"%s\";", dhcp_vendor_class_identifier_arg);
324fcf
+
324fcf
+			if ((arg_conf == 0) || (arg_conf_len <= 0))
324fcf
+				log_fatal("Unable to send -V option vendor-class-identifier");
324fcf
+		} else {
324fcf
+			char *last_arg_conf = arg_conf;
324fcf
+			arg_conf = NULL;
324fcf
+			arg_conf_len = asprintf(&arg_conf, "%s\nsend vendor-class-identifier \"%s\";", last_arg_conf, dhcp_vendor_class_identifier_arg);
324fcf
+
324fcf
+			if ((arg_conf == 0) || (arg_conf_len <= 0))
324fcf
+				log_fatal("Unable to send -V option vendor-class-identifier");
324fcf
+
324fcf
+			free(last_arg_conf);
324fcf
+		}
324fcf
+	}
324fcf
+
324fcf
+	if (dhclient_request_options != NULL) {
324fcf
+		if (arg_conf == 0) {
324fcf
+			arg_conf_len = asprintf(&arg_conf,  "request %s;", dhclient_request_options);
324fcf
+
324fcf
+			if ((arg_conf == 0) || (arg_conf_len <= 0))
324fcf
+				log_fatal("Unable to parse --request-options <request options list> argument");
324fcf
+		} else {
324fcf
+			char *last_arg_conf = arg_conf;
324fcf
+			arg_conf = NULL;
324fcf
+			arg_conf_len = asprintf(&arg_conf, "%s\nrequest %s;", last_arg_conf, dhclient_request_options);
324fcf
+
324fcf
+			if ((arg_conf == 0)  || (arg_conf_len <= 0))
324fcf
+				log_fatal("Unable to parse --request-options <request options list> argument");
324fcf
+
324fcf
+			free(last_arg_conf);
324fcf
+		}
324fcf
+	}
324fcf
+
324fcf
+	if (arg_conf) {
324fcf
+		if (arg_conf_len == 0)
324fcf
+			if ((arg_conf_len = strlen(arg_conf)) == 0)
324fcf
+				/* huh ? cannot happen ! */
324fcf
+				log_fatal("Unable to process -C/-H/-F/--timeout/-V/--request-options configuration arguments");
324fcf
+
324fcf
+		/* parse the extra dhclient.conf configuration arguments
324fcf
+		 * into top level config: */
324fcf
+		struct parse *cfile = (struct parse *)0;
324fcf
+		const char *val = NULL;
324fcf
+		int token;
324fcf
+
324fcf
+		status = new_parse(&cfile, -1, arg_conf, arg_conf_len, "extra dhclient -C/-H/-F/--timeout/-V/--request-options configuration arguments", 0);
324fcf
+
324fcf
+		if ((status != ISC_R_SUCCESS) || (cfile -> warnings_occurred))
324fcf
+			log_fatal("Cannot parse -C/-H/-F/--timeout/-V/--request-options configuration arguments !");
324fcf
+		/* more detailed parse failures will be logged */
324fcf
+
324fcf
+		do {
324fcf
+			token = peek_token(&val, (unsigned *)0, cfile);
324fcf
+			if (token == END_OF_FILE)
324fcf
+				break;
324fcf
+
324fcf
+			parse_client_statement(cfile, (struct interface_info *)0, &top_level_config);
324fcf
+		} while (1);
324fcf
+
324fcf
+		if (cfile -> warnings_occurred)
324fcf
+			log_fatal("Cannot parse -C/-H/-F/--timeout/-V/--request-options configuration arguments !");
324fcf
+		end_parse(&cfile);
324fcf
+
324fcf
+		if (timeout_arg) {
324fcf
+			/* we just set the toplevel timeout, but per-client
324fcf
+			 * timeouts may still be at defaults.
324fcf
+			 */
324fcf
+			for (ip=interfaces; ip; ip = ip->next) {
324fcf
+				if (ip->client->config->timeout == 60)
324fcf
+					ip->client->config->timeout = timeout_arg;
324fcf
+			}
324fcf
+		}
324fcf
+
324fcf
+		if ((dhclient_request_options != 0) && (top_level_config.requested_options != default_requested_options)) {
324fcf
+			for (ip=interfaces; ip; ip = ip->next) {
324fcf
+				if (ip->client->config->requested_options == default_requested_options)
324fcf
+					ip->client->config->requested_options = top_level_config.requested_options;
324fcf
+			}
324fcf
+		}
324fcf
+
324fcf
+		free(arg_conf);
324fcf
+		arg_conf = NULL;
324fcf
+		arg_conf_len = 0;
324fcf
+	}
324fcf
+
324fcf
 	/* Parse the lease database. */
324fcf
 	read_client_leases();
324fcf
 
324fcf
@@ -3092,7 +3348,8 @@ void make_discover (client, lease)
324fcf
 	client -> packet.xid = random ();
324fcf
 	client -> packet.secs = 0; /* filled in by send_discover. */
324fcf
 
324fcf
-	if (can_receive_unicast_unconfigured (client -> interface))
324fcf
+	if ((!(bootp_broadcast_always || client->config->bootp_broadcast_always))
324fcf
+	    && can_receive_unicast_unconfigured(client->interface))
324fcf
 		client -> packet.flags = 0;
324fcf
 	else
324fcf
 		client -> packet.flags = htons (BOOTP_BROADCAST);
324fcf
@@ -3177,7 +3434,9 @@ void make_request (client, lease)
324fcf
 	} else {
324fcf
 		memset (&client -> packet.ciaddr, 0,
324fcf
 			sizeof client -> packet.ciaddr);
324fcf
-		if (can_receive_unicast_unconfigured (client -> interface))
324fcf
+		if ((!(bootp_broadcast_always ||
324fcf
+		    client ->config->bootp_broadcast_always)) &&
324fcf
+		    can_receive_unicast_unconfigured (client -> interface))
324fcf
 			client -> packet.flags = 0;
324fcf
 		else
324fcf
 			client -> packet.flags = htons (BOOTP_BROADCAST);
324fcf
@@ -3240,7 +3499,8 @@ void make_decline (client, lease)
324fcf
 	client -> packet.hops = 0;
324fcf
 	client -> packet.xid = client -> xid;
324fcf
 	client -> packet.secs = 0; /* Filled in by send_request. */
324fcf
-	if (can_receive_unicast_unconfigured (client -> interface))
324fcf
+	if ((!(bootp_broadcast_always || client->config-> bootp_broadcast_always))
324fcf
+	    && can_receive_unicast_unconfigured (client->interface))
324fcf
 		client -> packet.flags = 0;
324fcf
 	else
324fcf
 		client -> packet.flags = htons (BOOTP_BROADCAST);
324fcf
diff --git a/common/conflex.c b/common/conflex.c
324fcf
index fe994ac..bdb4a52 100644
324fcf
--- a/common/conflex.c
324fcf
+++ b/common/conflex.c
324fcf
@@ -832,6 +832,8 @@ intern(char *atom, enum dhcp_token dfv) {
324fcf
 		if (!strcasecmp(atom+1, "ig-endian")) {
324fcf
 			return TOKEN_BIG_ENDIAN;
324fcf
 		}
324fcf
+		if (!strcasecmp (atom + 1, "ootp-broadcast-always"))
324fcf
+			return BOOTP_BROADCAST_ALWAYS;
324fcf
 		break;
324fcf
 	      case 'c':
324fcf
 		if (!strcasecmp(atom + 1, "ase"))
324fcf
diff --git a/includes/dhcpd.h b/includes/dhcpd.h
324fcf
index eab09a6..cfdac23 100644
324fcf
--- a/includes/dhcpd.h
324fcf
+++ b/includes/dhcpd.h
324fcf
@@ -1251,6 +1251,9 @@ struct client_config {
324fcf
 
324fcf
 	int lease_id_format;		/* format for IDs in lease file,
324fcf
 					   TOKEN_OCTAL or TOKEN_HEX */
324fcf
+
324fcf
+	int bootp_broadcast_always;	/* If nonzero, always set the BOOTP_BROADCAST
324fcf
+					   flag in requests */
324fcf
 };
324fcf
 
324fcf
 /* Per-interface state used in the dhcp client... */
324fcf
diff --git a/includes/dhctoken.h b/includes/dhctoken.h
324fcf
index 15bbd1c..b312e7a 100644
324fcf
--- a/includes/dhctoken.h
324fcf
+++ b/includes/dhctoken.h
324fcf
@@ -373,7 +373,8 @@ enum dhcp_token {
324fcf
 	TOKEN_BIG_ENDIAN = 675,
324fcf
 	LEASE_ID_FORMAT = 676,
324fcf
 	TOKEN_HEX = 677,
324fcf
-	TOKEN_OCTAL = 678
324fcf
+	TOKEN_OCTAL = 678,
324fcf
+	BOOTP_BROADCAST_ALWAYS = 679
324fcf
 };
324fcf
 
324fcf
 #define is_identifier(x)	((x) >= FIRST_TOKEN &&	\