5a3797e
diff -up dhcp-4.2.0/client/clparse.c.options dhcp-4.2.0/client/clparse.c
5a3797e
--- dhcp-4.2.0/client/clparse.c.options	2009-11-20 02:48:58.000000000 +0100
5a3797e
+++ dhcp-4.2.0/client/clparse.c	2010-07-21 13:29:05.000000000 +0200
4bf24c8
@@ -136,6 +136,7 @@ isc_result_t read_client_conf ()
4bf24c8
 	/* Requested lease time, used by DHCPv6 (DHCPv4 uses the option cache)
4bf24c8
 	 */
4bf24c8
 	top_level_config.requested_lease = 7200;
4bf24c8
+	top_level_config.bootp_broadcast_always = 0;
203b45c
 
4bf24c8
 	group_allocate (&top_level_config.on_receipt, MDL);
4bf24c8
 	if (!top_level_config.on_receipt)
4bf24c8
@@ -303,7 +304,8 @@ void read_client_leases ()
4bf24c8
 	interface-declaration |
4bf24c8
 	LEASE client-lease-statement |
4bf24c8
 	ALIAS client-lease-statement |
4bf24c8
-	KEY key-definition */
4bf24c8
+	KEY key-definition |
4bf24c8
+	BOOTP_BROADCAST_ALWAYS */
203b45c
 
4bf24c8
 void parse_client_statement (cfile, ip, config)
4bf24c8
 	struct parse *cfile;
5a3797e
@@ -717,6 +719,12 @@ void parse_client_statement (cfile, ip, 
4bf24c8
 		parse_reject_statement (cfile, config);
4bf24c8
 		return;
4bf24c8
 
4bf24c8
+	      case BOOTP_BROADCAST_ALWAYS:
4bf24c8
+		token = next_token(&val, (unsigned*)0, cfile);
4bf24c8
+		config -> bootp_broadcast_always = 1;
4bf24c8
+		parse_semi (cfile);
4bf24c8
+		return;
4bf24c8
+
4bf24c8
 	      default:
4bf24c8
 		lose = 0;
4bf24c8
 		stmt = (struct executable_statement *)0;
5a3797e
diff -up dhcp-4.2.0/client/dhclient.c.options dhcp-4.2.0/client/dhclient.c
5a3797e
--- dhcp-4.2.0/client/dhclient.c.options	2010-02-17 21:33:55.000000000 +0100
5a3797e
+++ dhcp-4.2.0/client/dhclient.c	2010-07-21 13:30:10.000000000 +0200
5a3797e
@@ -39,6 +39,12 @@
82186fd
 #include <limits.h>
5a3797e
 #include <dns/result.h>
203b45c
 
203b45c
+/*
203b45c
+ * Defined in stdio.h when _GNU_SOURCE is set, but we don't want to define
203b45c
+ * that when building ISC code.
203b45c
+ */
203b45c
+extern int asprintf(char **strp, const char *fmt, ...);
203b45c
+
203b45c
 TIME default_lease_time = 43200; /* 12 hours... */
203b45c
 TIME max_lease_time = 86400; /* 24 hours... */
203b45c
 
9538db2
@@ -82,6 +88,9 @@ int wanted_ia_na = -1;		/* the absolute 
4bf24c8
 int wanted_ia_ta = 0;
4bf24c8
 int wanted_ia_pd = 0;
82186fd
 char *mockup_relay = NULL;
203b45c
+int bootp_broadcast_always = 0;
203b45c
+
203b45c
+extern u_int32_t default_requested_options[];
203b45c
 
4bf24c8
 void run_stateless(int exit_mode);
203b45c
 
9538db2
@@ -112,6 +121,15 @@ main(int argc, char **argv) {
82186fd
 	int local_family_set = 0;
4bf24c8
 #endif /* DHCPv6 */
203b45c
 	char *s;
203b45c
+	char *dhcp_client_identifier_arg = NULL;
203b45c
+	char *dhcp_host_name_arg = NULL;
203b45c
+	char *dhcp_fqdn_arg = NULL;
203b45c
+	char *dhcp_vendor_class_identifier_arg = NULL;
203b45c
+	char *dhclient_request_options = NULL;
203b45c
+
203b45c
+	int timeout_arg = 0;
203b45c
+	char *arg_conf = NULL;
203b45c
+	int arg_conf_len = 0;
203b45c
 
82186fd
 	/* Initialize client globals. */
82186fd
 	memset(&default_duid, 0, sizeof(default_duid));
5a3797e
@@ -297,6 +315,88 @@ main(int argc, char **argv) {
4bf24c8
 		} else if (!strcmp(argv[i], "--version")) {
4bf24c8
 			log_info("isc-dhclient-%s", PACKAGE_VERSION);
4bf24c8
 			exit(0);
4bf24c8
+		} else if (!strcmp(argv[i], "-I")) {
203b45c
+			if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
4bf24c8
+				usage();
4bf24c8
+				exit(1);
203b45c
+			}
203b45c
+
82186fd
+			if (strlen(argv[i]) >= DHCP_MAX_OPTION_LEN) {
4bf24c8
+				log_error("-I option dhcp-client-identifier string \"%s\" is too long - maximum length is: %d", argv[i], DHCP_MAX_OPTION_LEN-1);
203b45c
+				exit(1);
203b45c
+			}
203b45c
+
203b45c
+			dhcp_client_identifier_arg = argv[i];
4bf24c8
+		} else if (!strcmp(argv[i], "-B")) {
203b45c
+			bootp_broadcast_always = 1;
4bf24c8
+		} else if (!strcmp(argv[i], "-H")) {
203b45c
+			if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
4bf24c8
+				usage();
4bf24c8
+				exit(1);
203b45c
+			}
203b45c
+
82186fd
+			if (strlen(argv[i]) >= DHCP_MAX_OPTION_LEN) {
4bf24c8
+				log_error("-H option host-name string \"%s\" is too long - maximum length is: %d", argv[i], DHCP_MAX_OPTION_LEN-1);
203b45c
+				exit(1);
203b45c
+			}
203b45c
+
203b45c
+			if (dhcp_host_name_arg != NULL) {
203b45c
+				log_error("The -H <host-name> and -F <fqdn> arguments are mutually exclusive");
203b45c
+				exit(1);
203b45c
+			}
203b45c
+
203b45c
+			dhcp_host_name_arg = argv[i];
4bf24c8
+		} else if (!strcmp(argv[i], "-F")) {
203b45c
+			if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
4bf24c8
+				usage();
4bf24c8
+				exit(1);
203b45c
+			}
203b45c
+
82186fd
+			if (strlen(argv[i]) >= DHCP_MAX_OPTION_LEN) {
4bf24c8
+				log_error("-F option fqdn.fqdn string \"%s\" is too long - maximum length is: %d", argv[i], DHCP_MAX_OPTION_LEN-1);
203b45c
+				exit(1);
203b45c
+			}
203b45c
+
203b45c
+			if (dhcp_fqdn_arg != NULL) {
203b45c
+				log_error("Only one -F <fqdn> argument can be specified");
203b45c
+				exit(1);
203b45c
+			}
203b45c
+
203b45c
+			if (dhcp_host_name_arg != NULL) {
203b45c
+				log_error("The -F <fqdn> and -H <host-name> arguments are mutually exclusive");
203b45c
+				exit(1);
203b45c
+			}
203b45c
+
203b45c
+			dhcp_fqdn_arg = argv[i];
4bf24c8
+		} else if (!strcmp(argv[i], "-timeout")) {
203b45c
+			if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
4bf24c8
+				usage();
4bf24c8
+				exit(1);
203b45c
+			}
203b45c
+
203b45c
+			if ((timeout_arg = atoi(argv[i])) <= 0) {
203b45c
+				log_error("-T timeout option must be > 0 - bad value: %s",argv[i]);
203b45c
+				exit(1);
203b45c
+			}
4bf24c8
+		} else if (!strcmp(argv[i], "-V")) {
203b45c
+			if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
4bf24c8
+				usage();
4bf24c8
+				exit(1);
203b45c
+			}
203b45c
+
82186fd
+			if (strlen(argv[i]) >= DHCP_MAX_OPTION_LEN) {
4bf24c8
+				log_error("-V option vendor-class-identifier string \"%s\" is too long - maximum length is: %d", argv[i], DHCP_MAX_OPTION_LEN-1);
203b45c
+				exit(1);
203b45c
+			}
203b45c
+
203b45c
+			dhcp_vendor_class_identifier_arg = argv[i];
4bf24c8
+		} else if (!strcmp(argv[i], "-R")) {
203b45c
+			if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
4bf24c8
+				usage();
4bf24c8
+				exit(1);
203b45c
+			}
203b45c
+
4bf24c8
+			dhclient_request_options = argv[i];
4bf24c8
 		} else if (argv[i][0] == '-') {
4bf24c8
 		    usage();
4bf24c8
 		} else if (interfaces_requested < 0) {
5a3797e
@@ -466,6 +566,166 @@ main(int argc, char **argv) {
203b45c
 	/* Parse the dhclient.conf file. */
4bf24c8
 	read_client_conf();
203b45c
 
203b45c
+	/* Parse any extra command line configuration arguments: */
203b45c
+	if ((dhcp_client_identifier_arg != NULL) && (*dhcp_client_identifier_arg != '\0')) {
203b45c
+		arg_conf_len = asprintf(&arg_conf, "send dhcp-client-identifier \"%s\";", dhcp_client_identifier_arg);
203b45c
+
203b45c
+		if ((arg_conf == 0) || (arg_conf_len <= 0))
203b45c
+			log_fatal("Unable to send -I option dhcp-client-identifier");
203b45c
+	}
203b45c
+
203b45c
+	if ((dhcp_host_name_arg != NULL) && (*dhcp_host_name_arg != '\0')) {
203b45c
+		if (arg_conf == 0) {
203b45c
+			arg_conf_len = asprintf(&arg_conf, "send host-name \"%s\";", dhcp_host_name_arg);
203b45c
+
203b45c
+			if ((arg_conf == 0) || (arg_conf_len <= 0))
203b45c
+				log_fatal("Unable to send -H option host-name");
203b45c
+		} else {
203b45c
+			char *last_arg_conf = arg_conf;
203b45c
+			arg_conf = NULL;
4bf24c8
+			arg_conf_len = asprintf(&arg_conf, "%s\nsend host-name \"%s\";", last_arg_conf, dhcp_host_name_arg);
203b45c
+
203b45c
+			if ((arg_conf == 0) || (arg_conf_len <= 0))
203b45c
+				log_fatal("Unable to send -H option host-name");
203b45c
+
203b45c
+			free(last_arg_conf);
203b45c
+		}
203b45c
+	}
203b45c
+
203b45c
+	if ((dhcp_fqdn_arg != NULL) && (*dhcp_fqdn_arg != '\0')) {
203b45c
+		if (arg_conf == 0) {
203b45c
+			arg_conf_len = asprintf(&arg_conf,  "send fqdn.fqdn \"%s\";", dhcp_fqdn_arg);
203b45c
+
203b45c
+			if ((arg_conf == 0) || (arg_conf_len <= 0))
203b45c
+				log_fatal("Unable to send -F option fqdn.fqdn");
203b45c
+		} else {
203b45c
+			char *last_arg_conf = arg_conf;
203b45c
+			arg_conf = NULL;
4bf24c8
+			arg_conf_len = asprintf(&arg_conf, "%s\nsend fqdn.fqdn \"%s\";", last_arg_conf, dhcp_fqdn_arg);
203b45c
+
203b45c
+			if ((arg_conf == 0)  || (arg_conf_len <= 0))
203b45c
+				log_fatal("Unable to send -F option fqdn.fqdn");
203b45c
+
203b45c
+			free(last_arg_conf);
203b45c
+		}
203b45c
+	}
203b45c
+
203b45c
+	if (timeout_arg) {
203b45c
+		if (arg_conf == 0) {
203b45c
+			arg_conf_len = asprintf(&arg_conf,  "timeout %d;", timeout_arg);
203b45c
+
203b45c
+			if ((arg_conf == 0) || (arg_conf_len <= 0))
4bf24c8
+				log_fatal("Unable to process -timeout timeout argument");
203b45c
+		} else {
203b45c
+			char *last_arg_conf = arg_conf;
203b45c
+			arg_conf = NULL;
4bf24c8
+			arg_conf_len = asprintf(&arg_conf, "%s\ntimeout %d;", last_arg_conf, timeout_arg);
203b45c
+
203b45c
+			if ((arg_conf == 0) || (arg_conf_len == 0))
4bf24c8
+				log_fatal("Unable to process -timeout timeout argument");
203b45c
+
203b45c
+			free(last_arg_conf);
203b45c
+		}
203b45c
+	}
203b45c
+
203b45c
+	if ((dhcp_vendor_class_identifier_arg != NULL) && (*dhcp_vendor_class_identifier_arg != '\0')) {
203b45c
+		if (arg_conf == 0) {
203b45c
+			arg_conf_len = asprintf(&arg_conf,  "send vendor-class-identifier \"%s\";", dhcp_vendor_class_identifier_arg);
203b45c
+
203b45c
+			if ((arg_conf == 0) || (arg_conf_len <= 0))
203b45c
+				log_fatal("Unable to send -V option vendor-class-identifier");
203b45c
+		} else {
203b45c
+			char *last_arg_conf = arg_conf;
203b45c
+			arg_conf = NULL;
203b45c
+			arg_conf_len = asprintf(&arg_conf, "%s\nsend vendor-class-identifier \"%s\";", last_arg_conf, dhcp_vendor_class_identifier_arg);
203b45c
+
203b45c
+			if ((arg_conf == 0) || (arg_conf_len <= 0))
203b45c
+				log_fatal("Unable to send -V option vendor-class-identifier");
203b45c
+
203b45c
+			free(last_arg_conf);
203b45c
+		}
203b45c
+	}
203b45c
+
203b45c
+	if (dhclient_request_options != NULL) {
203b45c
+		if (arg_conf == 0) {
203b45c
+			arg_conf_len = asprintf(&arg_conf,  "request %s;", dhclient_request_options);
203b45c
+
203b45c
+			if ((arg_conf == 0) || (arg_conf_len <= 0))
203b45c
+				log_fatal("Unable to parse -R <request options list> argument");
203b45c
+		} else {
203b45c
+			char *last_arg_conf = arg_conf;
203b45c
+			arg_conf = NULL;
203b45c
+			arg_conf_len = asprintf(&arg_conf, "%s\nrequest %s;", last_arg_conf, dhclient_request_options);
203b45c
+
203b45c
+			if ((arg_conf == 0)  || (arg_conf_len <= 0))
203b45c
+				log_fatal("Unable to parse -R <request options list> argument");
203b45c
+
203b45c
+			free(last_arg_conf);
203b45c
+		}
203b45c
+	}
203b45c
+
203b45c
+	if (arg_conf) {
203b45c
+		if (arg_conf_len == 0)
203b45c
+			if ((arg_conf_len = strlen(arg_conf)) == 0)
203b45c
+				/* huh ? cannot happen ! */
4bf24c8
+				log_fatal("Unable to process -I/-H/-F/-timeout/-V/-R configuration arguments");
203b45c
+
203b45c
+		/* parse the extra dhclient.conf configuration arguments
203b45c
+		 * into top level config: */
203b45c
+		struct parse *cfile = (struct parse *)0;
203b45c
+		const char *val = NULL;
203b45c
+		int token;
203b45c
+
4bf24c8
+		status = new_parse(&cfile, -1, arg_conf, arg_conf_len, "extra dhclient -I/-H/-F/-timeout/-V/-R configuration arguments", 0);
203b45c
+
203b45c
+		if ((status != ISC_R_SUCCESS) || (cfile -> warnings_occurred))
4bf24c8
+			log_fatal("Cannot parse -I/-H/-F/-timeout/-V/-R configuration arguments !");
203b45c
+		/* more detailed parse failures will be logged */
203b45c
+
203b45c
+		do {
4bf24c8
+			token = peek_token(&val, (unsigned *)0, cfile);
203b45c
+			if (token == END_OF_FILE)
203b45c
+				break;
203b45c
+
4bf24c8
+			parse_client_statement(cfile, (struct interface_info *)0, &top_level_config);
203b45c
+		} while (1);
203b45c
+
203b45c
+		if (cfile -> warnings_occurred)
4bf24c8
+			log_fatal("Cannot parse -I/-H/-F/-timeout/-V/-R configuration arguments !");
4bf24c8
+		end_parse(&cfile);
203b45c
+
203b45c
+		if (timeout_arg) {
203b45c
+			/* we just set the toplevel timeout, but per-client
203b45c
+			 * timeouts may still be at defaults. Also, it makes no
203b45c
+			 * sense having the reboot_timeout or backoff_cutoff
203b45c
+			 * greater than the timeout:
203b45c
+			 */
203b45c
+			if ((top_level_config.backoff_cutoff == 15) && (top_level_config.backoff_cutoff > (timeout_arg / 2)))
203b45c
+				top_level_config.backoff_cutoff = (((unsigned long)(timeout_arg / 2)) == 0) ? timeout_arg : (unsigned long)(timeout_arg / 2);
203b45c
+
4bf24c8
+			for (ip=interfaces; ip; ip = ip->next) {
203b45c
+				if (ip->client->config->timeout == 60)
203b45c
+					ip->client->config->timeout = timeout_arg;
203b45c
+
203b45c
+				if ((ip->client->config->reboot_timeout == 10) && (ip->client->config->reboot_timeout > ip->client->config->timeout))
203b45c
+					ip->client->config->reboot_timeout = ip->client->config->timeout;
203b45c
+				if ((ip->client->config->backoff_cutoff == 15) && (ip->client->config->backoff_cutoff > top_level_config.backoff_cutoff))
203b45c
+					ip->client->config->backoff_cutoff = top_level_config.backoff_cutoff;
203b45c
+			}
203b45c
+		}
203b45c
+
203b45c
+		if ((dhclient_request_options != 0) && (top_level_config.requested_options != default_requested_options)) {
4bf24c8
+			for (ip=interfaces; ip; ip = ip->next) {
203b45c
+				if (ip->client->config->requested_options == default_requested_options)
203b45c
+					ip->client->config->requested_options = top_level_config.requested_options;
203b45c
+			}
203b45c
+		}
203b45c
+
203b45c
+		free(arg_conf);
203b45c
+		arg_conf = NULL;
203b45c
+		arg_conf_len = 0;
203b45c
+	}
203b45c
+
203b45c
 	/* Parse the lease database. */
4bf24c8
 	read_client_leases();
203b45c
 
5a3797e
@@ -2337,7 +2597,8 @@ void make_discover (client, lease)
203b45c
 	client -> packet.xid = random ();
203b45c
 	client -> packet.secs = 0; /* filled in by send_discover. */
203b45c
 
203b45c
-	if (can_receive_unicast_unconfigured (client -> interface))
203b45c
+	if ((!(bootp_broadcast_always || client->config->bootp_broadcast_always))
203b45c
+	    && can_receive_unicast_unconfigured(client->interface))
203b45c
 		client -> packet.flags = 0;
203b45c
 	else
203b45c
 		client -> packet.flags = htons (BOOTP_BROADCAST);
5a3797e
@@ -2421,7 +2682,9 @@ void make_request (client, lease)
203b45c
 	} else {
203b45c
 		memset (&client -> packet.ciaddr, 0,
203b45c
 			sizeof client -> packet.ciaddr);
203b45c
-		if (can_receive_unicast_unconfigured (client -> interface))
203b45c
+		if ((!(bootp_broadcast_always ||
203b45c
+		    client ->config->bootp_broadcast_always)) &&
203b45c
+		    can_receive_unicast_unconfigured (client -> interface))
203b45c
 			client -> packet.flags = 0;
203b45c
 		else
203b45c
 			client -> packet.flags = htons (BOOTP_BROADCAST);
5a3797e
@@ -2483,7 +2746,8 @@ void make_decline (client, lease)
203b45c
 	client -> packet.hops = 0;
203b45c
 	client -> packet.xid = client -> xid;
203b45c
 	client -> packet.secs = 0; /* Filled in by send_request. */
203b45c
-	if (can_receive_unicast_unconfigured (client -> interface))
203b45c
+	if ((!(bootp_broadcast_always || client->config-> bootp_broadcast_always))
203b45c
+	    && can_receive_unicast_unconfigured (client->interface))
203b45c
 		client -> packet.flags = 0;
203b45c
 	else
203b45c
 		client -> packet.flags = htons (BOOTP_BROADCAST);
5a3797e
diff -up dhcp-4.2.0/common/conflex.c.options dhcp-4.2.0/common/conflex.c
5a3797e
--- dhcp-4.2.0/common/conflex.c.options	2010-03-24 22:49:47.000000000 +0100
5a3797e
+++ dhcp-4.2.0/common/conflex.c	2010-07-21 13:29:05.000000000 +0200
5a3797e
@@ -803,6 +803,8 @@ intern(char *atom, enum dhcp_token dfv) 
4bf24c8
 			return BALANCE;
4bf24c8
 		if (!strcasecmp (atom + 1, "ound"))
4bf24c8
 			return BOUND;
4bf24c8
+		if (!strcasecmp (atom + 1, "ootp-broadcast-always"))
4bf24c8
+			return BOOTP_BROADCAST_ALWAYS;
4bf24c8
 		break;
4bf24c8
 	      case 'c':
9538db2
 		if (!strcasecmp(atom + 1, "ase"))
5a3797e
diff -up dhcp-4.2.0/includes/dhcpd.h.options dhcp-4.2.0/includes/dhcpd.h
5a3797e
--- dhcp-4.2.0/includes/dhcpd.h.options	2010-06-01 19:29:59.000000000 +0200
5a3797e
+++ dhcp-4.2.0/includes/dhcpd.h	2010-07-21 13:29:05.000000000 +0200
5a3797e
@@ -1119,6 +1119,9 @@ struct client_config {
4bf24c8
 	int do_forward_update;		/* If nonzero, and if we have the
4bf24c8
 					   information we need, update the
4bf24c8
 					   A record for the address we get. */
4bf24c8
+
4bf24c8
+	int bootp_broadcast_always;	/* If nonzero, always set the BOOTP_BROADCAST
4bf24c8
+					   flag in requests */
4bf24c8
 };
203b45c
 
4bf24c8
 /* Per-interface state used in the dhcp client... */
5a3797e
diff -up dhcp-4.2.0/includes/dhctoken.h.options dhcp-4.2.0/includes/dhctoken.h
5a3797e
--- dhcp-4.2.0/includes/dhctoken.h.options	2010-02-17 21:33:55.000000000 +0100
5a3797e
+++ dhcp-4.2.0/includes/dhctoken.h	2010-07-21 13:33:08.000000000 +0200
5a3797e
@@ -357,7 +357,8 @@ enum dhcp_token {
5a3797e
 	CONFLICT_DONE = 660,
5a3797e
 	AUTO_PARTNER_DOWN = 661,
5a3797e
 	GETHOSTNAME = 662,
5a3797e
-	REWIND = 663
5a3797e
+	REWIND = 663,
5a3797e
+	BOOTP_BROADCAST_ALWAYS = 664
4bf24c8
 };
203b45c
 
5a3797e
 #define is_identifier(x)	((x) >= FIRST_TOKEN &&	\