3161ff3
diff -up dhcp-4.1.0/client/clparse.c.options dhcp-4.1.0/client/clparse.c
3161ff3
--- dhcp-4.1.0/client/clparse.c.options	2008-05-23 03:22:23.000000000 -1000
3161ff3
+++ dhcp-4.1.0/client/clparse.c	2009-01-06 07:59:14.000000000 -1000
3161ff3
@@ -136,6 +136,7 @@ isc_result_t read_client_conf ()
3161ff3
 	/* Requested lease time, used by DHCPv6 (DHCPv4 uses the option cache)
3161ff3
 	 */
3161ff3
 	top_level_config.requested_lease = 7200;
3161ff3
+	top_level_config.bootp_broadcast_always = 0;
9858513
 
3161ff3
 	group_allocate (&top_level_config.on_receipt, MDL);
3161ff3
 	if (!top_level_config.on_receipt)
3161ff3
@@ -303,7 +304,8 @@ void read_client_leases ()
3161ff3
 	interface-declaration |
3161ff3
 	LEASE client-lease-statement |
3161ff3
 	ALIAS client-lease-statement |
3161ff3
-	KEY key-definition */
3161ff3
+	KEY key-definition |
3161ff3
+	BOOTP_BROADCAST_ALWAYS */
9858513
 
3161ff3
 void parse_client_statement (cfile, ip, config)
3161ff3
 	struct parse *cfile;
3161ff3
@@ -693,6 +695,12 @@ void parse_client_statement (cfile, ip, 
3161ff3
 		parse_reject_statement (cfile, config);
3161ff3
 		return;
3161ff3
 
3161ff3
+	      case BOOTP_BROADCAST_ALWAYS:
3161ff3
+		token = next_token(&val, (unsigned*)0, cfile);
3161ff3
+		config -> bootp_broadcast_always = 1;
3161ff3
+		parse_semi (cfile);
3161ff3
+		return;
3161ff3
+
3161ff3
 	      default:
3161ff3
 		lose = 0;
3161ff3
 		stmt = (struct executable_statement *)0;
3161ff3
diff -up dhcp-4.1.0/client/dhclient.c.options dhcp-4.1.0/client/dhclient.c
3161ff3
--- dhcp-4.1.0/client/dhclient.c.options	2008-06-11 10:17:10.000000000 -1000
3161ff3
+++ dhcp-4.1.0/client/dhclient.c	2009-01-06 08:27:57.000000000 -1000
3161ff3
@@ -38,6 +38,12 @@
7ebed4a
 #include <sys/wait.h>
7ebed4a
 #include <limits.h>
9858513
 
9858513
+/*
9858513
+ * Defined in stdio.h when _GNU_SOURCE is set, but we don't want to define
9858513
+ * that when building ISC code.
9858513
+ */
9858513
+extern int asprintf(char **strp, const char *fmt, ...);
9858513
+
9858513
 TIME default_lease_time = 43200; /* 12 hours... */
9858513
 TIME max_lease_time = 86400; /* 24 hours... */
9858513
 
3161ff3
@@ -80,6 +86,9 @@ int wanted_ia_na = -1;		/* the absolute 
3161ff3
 int wanted_ia_ta = 0;
3161ff3
 int wanted_ia_pd = 0;
7ebed4a
 char *mockup_relay = NULL;
9858513
+int bootp_broadcast_always = 0;
9858513
+
9858513
+extern u_int32_t default_requested_options[];
9858513
 
3161ff3
 void run_stateless(int exit_mode);
9858513
 
3161ff3
@@ -110,6 +119,15 @@ main(int argc, char **argv) {
7ebed4a
 	int local_family_set = 0;
3161ff3
 #endif /* DHCPv6 */
9858513
 	char *s;
9858513
+	char *dhcp_client_identifier_arg = NULL;
9858513
+	char *dhcp_host_name_arg = NULL;
9858513
+	char *dhcp_fqdn_arg = NULL;
9858513
+	char *dhcp_vendor_class_identifier_arg = NULL;
9858513
+	char *dhclient_request_options = NULL;
9858513
+
9858513
+	int timeout_arg = 0;
9858513
+	char *arg_conf = NULL;
9858513
+	int arg_conf_len = 0;
9858513
 
7ebed4a
 	/* Initialize client globals. */
7ebed4a
 	memset(&default_duid, 0, sizeof(default_duid));
3161ff3
@@ -274,6 +292,88 @@ main(int argc, char **argv) {
3161ff3
 		} else if (!strcmp(argv[i], "--version")) {
3161ff3
 			log_info("isc-dhclient-%s", PACKAGE_VERSION);
3161ff3
 			exit(0);
3161ff3
+		} else if (!strcmp(argv[i], "-I")) {
9858513
+			if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
3161ff3
+				usage();
3161ff3
+				exit(1);
9858513
+			}
9858513
+
7ebed4a
+			if (strlen(argv[i]) >= DHCP_MAX_OPTION_LEN) {
3161ff3
+				log_error("-I option dhcp-client-identifier string \"%s\" is too long - maximum length is: %d", argv[i], DHCP_MAX_OPTION_LEN-1);
9858513
+				exit(1);
9858513
+			}
9858513
+
9858513
+			dhcp_client_identifier_arg = argv[i];
3161ff3
+		} else if (!strcmp(argv[i], "-B")) {
9858513
+			bootp_broadcast_always = 1;
3161ff3
+		} else if (!strcmp(argv[i], "-H")) {
9858513
+			if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
3161ff3
+				usage();
3161ff3
+				exit(1);
9858513
+			}
9858513
+
7ebed4a
+			if (strlen(argv[i]) >= DHCP_MAX_OPTION_LEN) {
3161ff3
+				log_error("-H option host-name string \"%s\" is too long - maximum length is: %d", argv[i], DHCP_MAX_OPTION_LEN-1);
9858513
+				exit(1);
9858513
+			}
9858513
+
9858513
+			if (dhcp_host_name_arg != NULL) {
9858513
+				log_error("The -H <host-name> and -F <fqdn> arguments are mutually exclusive");
9858513
+				exit(1);
9858513
+			}
9858513
+
9858513
+			dhcp_host_name_arg = argv[i];
3161ff3
+		} else if (!strcmp(argv[i], "-F")) {
9858513
+			if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
3161ff3
+				usage();
3161ff3
+				exit(1);
9858513
+			}
9858513
+
7ebed4a
+			if (strlen(argv[i]) >= DHCP_MAX_OPTION_LEN) {
3161ff3
+				log_error("-F option fqdn.fqdn string \"%s\" is too long - maximum length is: %d", argv[i], DHCP_MAX_OPTION_LEN-1);
9858513
+				exit(1);
9858513
+			}
9858513
+
9858513
+			if (dhcp_fqdn_arg != NULL) {
9858513
+				log_error("Only one -F <fqdn> argument can be specified");
9858513
+				exit(1);
9858513
+			}
9858513
+
9858513
+			if (dhcp_host_name_arg != NULL) {
9858513
+				log_error("The -F <fqdn> and -H <host-name> arguments are mutually exclusive");
9858513
+				exit(1);
9858513
+			}
9858513
+
9858513
+			dhcp_fqdn_arg = argv[i];
3161ff3
+		} else if (!strcmp(argv[i], "-timeout")) {
9858513
+			if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
3161ff3
+				usage();
3161ff3
+				exit(1);
9858513
+			}
9858513
+
9858513
+			if ((timeout_arg = atoi(argv[i])) <= 0) {
9858513
+				log_error("-T timeout option must be > 0 - bad value: %s",argv[i]);
9858513
+				exit(1);
9858513
+			}
3161ff3
+		} else if (!strcmp(argv[i], "-V")) {
9858513
+			if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
3161ff3
+				usage();
3161ff3
+				exit(1);
9858513
+			}
9858513
+
7ebed4a
+			if (strlen(argv[i]) >= DHCP_MAX_OPTION_LEN) {
3161ff3
+				log_error("-V option vendor-class-identifier string \"%s\" is too long - maximum length is: %d", argv[i], DHCP_MAX_OPTION_LEN-1);
9858513
+				exit(1);
9858513
+			}
9858513
+
9858513
+			dhcp_vendor_class_identifier_arg = argv[i];
3161ff3
+		} else if (!strcmp(argv[i], "-R")) {
9858513
+			if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
3161ff3
+				usage();
3161ff3
+				exit(1);
9858513
+			}
9858513
+
3161ff3
+			dhclient_request_options = argv[i];
3161ff3
 		} else if (argv[i][0] == '-') {
3161ff3
 		    usage();
3161ff3
 		} else if (interfaces_requested < 0) {
3161ff3
@@ -443,6 +543,166 @@ main(int argc, char **argv) {
9858513
 	/* Parse the dhclient.conf file. */
3161ff3
 	read_client_conf();
9858513
 
9858513
+	/* Parse any extra command line configuration arguments: */
9858513
+	if ((dhcp_client_identifier_arg != NULL) && (*dhcp_client_identifier_arg != '\0')) {
9858513
+		arg_conf_len = asprintf(&arg_conf, "send dhcp-client-identifier \"%s\";", dhcp_client_identifier_arg);
9858513
+
9858513
+		if ((arg_conf == 0) || (arg_conf_len <= 0))
9858513
+			log_fatal("Unable to send -I option dhcp-client-identifier");
9858513
+	}
9858513
+
9858513
+	if ((dhcp_host_name_arg != NULL) && (*dhcp_host_name_arg != '\0')) {
9858513
+		if (arg_conf == 0) {
9858513
+			arg_conf_len = asprintf(&arg_conf, "send host-name \"%s\";", dhcp_host_name_arg);
9858513
+
9858513
+			if ((arg_conf == 0) || (arg_conf_len <= 0))
9858513
+				log_fatal("Unable to send -H option host-name");
9858513
+		} else {
9858513
+			char *last_arg_conf = arg_conf;
9858513
+			arg_conf = NULL;
3161ff3
+			arg_conf_len = asprintf(&arg_conf, "%s\nsend host-name \"%s\";", last_arg_conf, dhcp_host_name_arg);
9858513
+
9858513
+			if ((arg_conf == 0) || (arg_conf_len <= 0))
9858513
+				log_fatal("Unable to send -H option host-name");
9858513
+
9858513
+			free(last_arg_conf);
9858513
+		}
9858513
+	}
9858513
+
9858513
+	if ((dhcp_fqdn_arg != NULL) && (*dhcp_fqdn_arg != '\0')) {
9858513
+		if (arg_conf == 0) {
9858513
+			arg_conf_len = asprintf(&arg_conf,  "send fqdn.fqdn \"%s\";", dhcp_fqdn_arg);
9858513
+
9858513
+			if ((arg_conf == 0) || (arg_conf_len <= 0))
9858513
+				log_fatal("Unable to send -F option fqdn.fqdn");
9858513
+		} else {
9858513
+			char *last_arg_conf = arg_conf;
9858513
+			arg_conf = NULL;
3161ff3
+			arg_conf_len = asprintf(&arg_conf, "%s\nsend fqdn.fqdn \"%s\";", last_arg_conf, dhcp_fqdn_arg);
9858513
+
9858513
+			if ((arg_conf == 0)  || (arg_conf_len <= 0))
9858513
+				log_fatal("Unable to send -F option fqdn.fqdn");
9858513
+
9858513
+			free(last_arg_conf);
9858513
+		}
9858513
+	}
9858513
+
9858513
+	if (timeout_arg) {
9858513
+		if (arg_conf == 0) {
9858513
+			arg_conf_len = asprintf(&arg_conf,  "timeout %d;", timeout_arg);
9858513
+
9858513
+			if ((arg_conf == 0) || (arg_conf_len <= 0))
3161ff3
+				log_fatal("Unable to process -timeout timeout argument");
9858513
+		} else {
9858513
+			char *last_arg_conf = arg_conf;
9858513
+			arg_conf = NULL;
3161ff3
+			arg_conf_len = asprintf(&arg_conf, "%s\ntimeout %d;", last_arg_conf, timeout_arg);
9858513
+
9858513
+			if ((arg_conf == 0) || (arg_conf_len == 0))
3161ff3
+				log_fatal("Unable to process -timeout timeout argument");
9858513
+
9858513
+			free(last_arg_conf);
9858513
+		}
9858513
+	}
9858513
+
9858513
+	if ((dhcp_vendor_class_identifier_arg != NULL) && (*dhcp_vendor_class_identifier_arg != '\0')) {
9858513
+		if (arg_conf == 0) {
9858513
+			arg_conf_len = asprintf(&arg_conf,  "send vendor-class-identifier \"%s\";", dhcp_vendor_class_identifier_arg);
9858513
+
9858513
+			if ((arg_conf == 0) || (arg_conf_len <= 0))
9858513
+				log_fatal("Unable to send -V option vendor-class-identifier");
9858513
+		} else {
9858513
+			char *last_arg_conf = arg_conf;
9858513
+			arg_conf = NULL;
9858513
+			arg_conf_len = asprintf(&arg_conf, "%s\nsend vendor-class-identifier \"%s\";", last_arg_conf, dhcp_vendor_class_identifier_arg);
9858513
+
9858513
+			if ((arg_conf == 0) || (arg_conf_len <= 0))
9858513
+				log_fatal("Unable to send -V option vendor-class-identifier");
9858513
+
9858513
+			free(last_arg_conf);
9858513
+		}
9858513
+	}
9858513
+
9858513
+	if (dhclient_request_options != NULL) {
9858513
+		if (arg_conf == 0) {
9858513
+			arg_conf_len = asprintf(&arg_conf,  "request %s;", dhclient_request_options);
9858513
+
9858513
+			if ((arg_conf == 0) || (arg_conf_len <= 0))
9858513
+				log_fatal("Unable to parse -R <request options list> argument");
9858513
+		} else {
9858513
+			char *last_arg_conf = arg_conf;
9858513
+			arg_conf = NULL;
9858513
+			arg_conf_len = asprintf(&arg_conf, "%s\nrequest %s;", last_arg_conf, dhclient_request_options);
9858513
+
9858513
+			if ((arg_conf == 0)  || (arg_conf_len <= 0))
9858513
+				log_fatal("Unable to parse -R <request options list> argument");
9858513
+
9858513
+			free(last_arg_conf);
9858513
+		}
9858513
+	}
9858513
+
9858513
+	if (arg_conf) {
9858513
+		if (arg_conf_len == 0)
9858513
+			if ((arg_conf_len = strlen(arg_conf)) == 0)
9858513
+				/* huh ? cannot happen ! */
3161ff3
+				log_fatal("Unable to process -I/-H/-F/-timeout/-V/-R configuration arguments");
9858513
+
9858513
+		/* parse the extra dhclient.conf configuration arguments
9858513
+		 * into top level config: */
9858513
+		struct parse *cfile = (struct parse *)0;
9858513
+		const char *val = NULL;
9858513
+		int token;
9858513
+
3161ff3
+		status = new_parse(&cfile, -1, arg_conf, arg_conf_len, "extra dhclient -I/-H/-F/-timeout/-V/-R configuration arguments", 0);
9858513
+
9858513
+		if ((status != ISC_R_SUCCESS) || (cfile -> warnings_occurred))
3161ff3
+			log_fatal("Cannot parse -I/-H/-F/-timeout/-V/-R configuration arguments !");
9858513
+		/* more detailed parse failures will be logged */
9858513
+
9858513
+		do {
3161ff3
+			token = peek_token(&val, (unsigned *)0, cfile);
9858513
+			if (token == END_OF_FILE)
9858513
+				break;
9858513
+
3161ff3
+			parse_client_statement(cfile, (struct interface_info *)0, &top_level_config);
9858513
+		} while (1);
9858513
+
9858513
+		if (cfile -> warnings_occurred)
3161ff3
+			log_fatal("Cannot parse -I/-H/-F/-timeout/-V/-R configuration arguments !");
3161ff3
+		end_parse(&cfile);
9858513
+
9858513
+		if (timeout_arg) {
9858513
+			/* we just set the toplevel timeout, but per-client
9858513
+			 * timeouts may still be at defaults. Also, it makes no
9858513
+			 * sense having the reboot_timeout or backoff_cutoff
9858513
+			 * greater than the timeout:
9858513
+			 */
9858513
+			if ((top_level_config.backoff_cutoff == 15) && (top_level_config.backoff_cutoff > (timeout_arg / 2)))
9858513
+				top_level_config.backoff_cutoff = (((unsigned long)(timeout_arg / 2)) == 0) ? timeout_arg : (unsigned long)(timeout_arg / 2);
9858513
+
3161ff3
+			for (ip=interfaces; ip; ip = ip->next) {
9858513
+				if (ip->client->config->timeout == 60)
9858513
+					ip->client->config->timeout = timeout_arg;
9858513
+
9858513
+				if ((ip->client->config->reboot_timeout == 10) && (ip->client->config->reboot_timeout > ip->client->config->timeout))
9858513
+					ip->client->config->reboot_timeout = ip->client->config->timeout;
9858513
+				if ((ip->client->config->backoff_cutoff == 15) && (ip->client->config->backoff_cutoff > top_level_config.backoff_cutoff))
9858513
+					ip->client->config->backoff_cutoff = top_level_config.backoff_cutoff;
9858513
+			}
9858513
+		}
9858513
+
9858513
+		if ((dhclient_request_options != 0) && (top_level_config.requested_options != default_requested_options)) {
3161ff3
+			for (ip=interfaces; ip; ip = ip->next) {
9858513
+				if (ip->client->config->requested_options == default_requested_options)
9858513
+					ip->client->config->requested_options = top_level_config.requested_options;
9858513
+			}
9858513
+		}
9858513
+
9858513
+		free(arg_conf);
9858513
+		arg_conf = NULL;
9858513
+		arg_conf_len = 0;
9858513
+	}
9858513
+
9858513
 	/* Parse the lease database. */
3161ff3
 	read_client_leases();
9858513
 
3161ff3
@@ -2313,7 +2573,8 @@ void make_discover (client, lease)
9858513
 	client -> packet.xid = random ();
9858513
 	client -> packet.secs = 0; /* filled in by send_discover. */
9858513
 
9858513
-	if (can_receive_unicast_unconfigured (client -> interface))
9858513
+	if ((!(bootp_broadcast_always || client->config->bootp_broadcast_always))
9858513
+	    && can_receive_unicast_unconfigured(client->interface))
9858513
 		client -> packet.flags = 0;
9858513
 	else
9858513
 		client -> packet.flags = htons (BOOTP_BROADCAST);
3161ff3
@@ -2397,7 +2658,9 @@ void make_request (client, lease)
9858513
 	} else {
9858513
 		memset (&client -> packet.ciaddr, 0,
9858513
 			sizeof client -> packet.ciaddr);
9858513
-		if (can_receive_unicast_unconfigured (client -> interface))
9858513
+		if ((!(bootp_broadcast_always ||
9858513
+		    client ->config->bootp_broadcast_always)) &&
9858513
+		    can_receive_unicast_unconfigured (client -> interface))
9858513
 			client -> packet.flags = 0;
9858513
 		else
9858513
 			client -> packet.flags = htons (BOOTP_BROADCAST);
3161ff3
@@ -2459,7 +2722,8 @@ void make_decline (client, lease)
9858513
 	client -> packet.hops = 0;
9858513
 	client -> packet.xid = client -> xid;
9858513
 	client -> packet.secs = 0; /* Filled in by send_request. */
9858513
-	if (can_receive_unicast_unconfigured (client -> interface))
9858513
+	if ((!(bootp_broadcast_always || client->config-> bootp_broadcast_always))
9858513
+	    && can_receive_unicast_unconfigured (client->interface))
9858513
 		client -> packet.flags = 0;
9858513
 	else
9858513
 		client -> packet.flags = htons (BOOTP_BROADCAST);
3161ff3
diff -up dhcp-4.1.0/common/conflex.c.options dhcp-4.1.0/common/conflex.c
3161ff3
--- dhcp-4.1.0/common/conflex.c.options	2009-01-06 07:59:13.000000000 -1000
3161ff3
+++ dhcp-4.1.0/common/conflex.c	2009-01-06 07:59:14.000000000 -1000
3161ff3
@@ -783,6 +783,8 @@ intern(char *atom, enum dhcp_token dfv) 
3161ff3
 			return BALANCE;
3161ff3
 		if (!strcasecmp (atom + 1, "ound"))
3161ff3
 			return BOUND;
3161ff3
+		if (!strcasecmp (atom + 1, "ootp-broadcast-always"))
3161ff3
+			return BOOTP_BROADCAST_ALWAYS;
3161ff3
 		break;
3161ff3
 	      case 'c':
3161ff3
 		if (!strcasecmp (atom + 1, "ase"))
3161ff3
diff -up dhcp-4.1.0/includes/dhcpd.h.options dhcp-4.1.0/includes/dhcpd.h
3161ff3
--- dhcp-4.1.0/includes/dhcpd.h.options	2009-01-06 07:59:13.000000000 -1000
3161ff3
+++ dhcp-4.1.0/includes/dhcpd.h	2009-01-06 07:59:14.000000000 -1000
3161ff3
@@ -1079,6 +1079,9 @@ struct client_config {
3161ff3
 	int do_forward_update;		/* If nonzero, and if we have the
3161ff3
 					   information we need, update the
3161ff3
 					   A record for the address we get. */
3161ff3
+
3161ff3
+	int bootp_broadcast_always;	/* If nonzero, always set the BOOTP_BROADCAST
3161ff3
+					   flag in requests */
3161ff3
 };
9858513
 
3161ff3
 /* Per-interface state used in the dhcp client... */
3161ff3
diff -up dhcp-4.1.0/includes/dhctoken.h.options dhcp-4.1.0/includes/dhctoken.h
3161ff3
--- dhcp-4.1.0/includes/dhctoken.h.options	2008-02-20 02:45:53.000000000 -1000
3161ff3
+++ dhcp-4.1.0/includes/dhctoken.h	2009-01-06 08:00:51.000000000 -1000
3161ff3
@@ -352,7 +352,8 @@ enum dhcp_token {
3161ff3
 	ZEROLEN = 655,
3161ff3
 	TEMPORARY = 656,
3161ff3
 	PREFIX6 = 657,
3161ff3
-	FIXED_PREFIX6 = 658
3161ff3
+	FIXED_PREFIX6 = 658,
3161ff3
+	BOOTP_BROADCAST_ALWAYS = 659
3161ff3
 };
9858513
 
3161ff3
 #define is_identifier(x)	((x) >= FIRST_TOKEN &&	\