1 diff -up dhcp-4.2.2b1/client/clparse.c.options dhcp-4.2.2b1/client/clparse.c
2 --- dhcp-4.2.2b1/client/clparse.c.options 2011-04-21 16:08:14.000000000 +0200
3 +++ dhcp-4.2.2b1/client/clparse.c 2011-07-01 13:51:52.935755570 +0200
4 @@ -146,6 +146,7 @@ isc_result_t read_client_conf ()
5 /* Requested lease time, used by DHCPv6 (DHCPv4 uses the option cache)
7 top_level_config.requested_lease = 7200;
8 + top_level_config.bootp_broadcast_always = 0;
10 group_allocate (&top_level_config.on_receipt, MDL);
11 if (!top_level_config.on_receipt)
12 @@ -313,7 +314,8 @@ void read_client_leases ()
13 interface-declaration |
14 LEASE client-lease-statement |
15 ALIAS client-lease-statement |
16 - KEY key-definition */
17 + KEY key-definition |
18 + BOOTP_BROADCAST_ALWAYS */
20 void parse_client_statement (cfile, ip, config)
22 @@ -732,6 +734,12 @@ void parse_client_statement (cfile, ip,
23 parse_reject_statement (cfile, config);
26 + case BOOTP_BROADCAST_ALWAYS:
27 + token = next_token(&val, (unsigned*)0, cfile);
28 + config -> bootp_broadcast_always = 1;
34 stmt = (struct executable_statement *)0;
35 diff -up dhcp-4.2.2b1/client/dhclient.c.options dhcp-4.2.2b1/client/dhclient.c
36 --- dhcp-4.2.2b1/client/dhclient.c.options 2011-05-11 16:20:59.000000000 +0200
37 +++ dhcp-4.2.2b1/client/dhclient.c 2011-07-01 13:51:52.936755545 +0200
40 #include <dns/result.h>
43 + * Defined in stdio.h when _GNU_SOURCE is set, but we don't want to define
44 + * that when building ISC code.
46 +extern int asprintf(char **strp, const char *fmt, ...);
48 TIME default_lease_time = 43200; /* 12 hours... */
49 TIME max_lease_time = 86400; /* 24 hours... */
51 @@ -87,6 +93,9 @@ int wanted_ia_na = -1; /* the absolute
54 char *mockup_relay = NULL;
55 +int bootp_broadcast_always = 0;
57 +extern u_int32_t default_requested_options[];
59 void run_stateless(int exit_mode);
61 @@ -123,6 +132,15 @@ main(int argc, char **argv) {
62 int local_family_set = 0;
65 + char *dhcp_client_identifier_arg = NULL;
66 + char *dhcp_host_name_arg = NULL;
67 + char *dhcp_fqdn_arg = NULL;
68 + char *dhcp_vendor_class_identifier_arg = NULL;
69 + char *dhclient_request_options = NULL;
71 + int timeout_arg = 0;
72 + char *arg_conf = NULL;
73 + int arg_conf_len = 0;
75 /* Initialize client globals. */
76 memset(&default_duid, 0, sizeof(default_duid));
77 @@ -310,6 +328,88 @@ main(int argc, char **argv) {
78 } else if (!strcmp(argv[i], "--version")) {
79 log_info("isc-dhclient-%s", PACKAGE_VERSION);
81 + } else if (!strcmp(argv[i], "-I")) {
82 + if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
87 + if (strlen(argv[i]) >= DHCP_MAX_OPTION_LEN) {
88 + log_error("-I option dhcp-client-identifier string \"%s\" is too long - maximum length is: %d", argv[i], DHCP_MAX_OPTION_LEN-1);
92 + dhcp_client_identifier_arg = argv[i];
93 + } else if (!strcmp(argv[i], "-B")) {
94 + bootp_broadcast_always = 1;
95 + } else if (!strcmp(argv[i], "-H")) {
96 + if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
101 + if (strlen(argv[i]) >= DHCP_MAX_OPTION_LEN) {
102 + log_error("-H option host-name string \"%s\" is too long - maximum length is: %d", argv[i], DHCP_MAX_OPTION_LEN-1);
106 + if (dhcp_host_name_arg != NULL) {
107 + log_error("The -H <host-name> and -F <fqdn> arguments are mutually exclusive");
111 + dhcp_host_name_arg = argv[i];
112 + } else if (!strcmp(argv[i], "-F")) {
113 + if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
118 + if (strlen(argv[i]) >= DHCP_MAX_OPTION_LEN) {
119 + log_error("-F option fqdn.fqdn string \"%s\" is too long - maximum length is: %d", argv[i], DHCP_MAX_OPTION_LEN-1);
123 + if (dhcp_fqdn_arg != NULL) {
124 + log_error("Only one -F <fqdn> argument can be specified");
128 + if (dhcp_host_name_arg != NULL) {
129 + log_error("The -F <fqdn> and -H <host-name> arguments are mutually exclusive");
133 + dhcp_fqdn_arg = argv[i];
134 + } else if (!strcmp(argv[i], "-timeout")) {
135 + if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
140 + if ((timeout_arg = atoi(argv[i])) <= 0) {
141 + log_error("-T timeout option must be > 0 - bad value: %s",argv[i]);
144 + } else if (!strcmp(argv[i], "-V")) {
145 + if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
150 + if (strlen(argv[i]) >= DHCP_MAX_OPTION_LEN) {
151 + log_error("-V option vendor-class-identifier string \"%s\" is too long - maximum length is: %d", argv[i], DHCP_MAX_OPTION_LEN-1);
155 + dhcp_vendor_class_identifier_arg = argv[i];
156 + } else if (!strcmp(argv[i], "-R")) {
157 + if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
162 + dhclient_request_options = argv[i];
163 } else if (argv[i][0] == '-') {
165 } else if (interfaces_requested < 0) {
166 @@ -484,6 +584,166 @@ main(int argc, char **argv) {
167 /* Parse the dhclient.conf file. */
170 + /* Parse any extra command line configuration arguments: */
171 + if ((dhcp_client_identifier_arg != NULL) && (*dhcp_client_identifier_arg != '\0')) {
172 + arg_conf_len = asprintf(&arg_conf, "send dhcp-client-identifier \"%s\";", dhcp_client_identifier_arg);
174 + if ((arg_conf == 0) || (arg_conf_len <= 0))
175 + log_fatal("Unable to send -I option dhcp-client-identifier");
178 + if ((dhcp_host_name_arg != NULL) && (*dhcp_host_name_arg != '\0')) {
179 + if (arg_conf == 0) {
180 + arg_conf_len = asprintf(&arg_conf, "send host-name \"%s\";", dhcp_host_name_arg);
182 + if ((arg_conf == 0) || (arg_conf_len <= 0))
183 + log_fatal("Unable to send -H option host-name");
185 + char *last_arg_conf = arg_conf;
187 + arg_conf_len = asprintf(&arg_conf, "%s\nsend host-name \"%s\";", last_arg_conf, dhcp_host_name_arg);
189 + if ((arg_conf == 0) || (arg_conf_len <= 0))
190 + log_fatal("Unable to send -H option host-name");
192 + free(last_arg_conf);
196 + if ((dhcp_fqdn_arg != NULL) && (*dhcp_fqdn_arg != '\0')) {
197 + if (arg_conf == 0) {
198 + arg_conf_len = asprintf(&arg_conf, "send fqdn.fqdn \"%s\";", dhcp_fqdn_arg);
200 + if ((arg_conf == 0) || (arg_conf_len <= 0))
201 + log_fatal("Unable to send -F option fqdn.fqdn");
203 + char *last_arg_conf = arg_conf;
205 + arg_conf_len = asprintf(&arg_conf, "%s\nsend fqdn.fqdn \"%s\";", last_arg_conf, dhcp_fqdn_arg);
207 + if ((arg_conf == 0) || (arg_conf_len <= 0))
208 + log_fatal("Unable to send -F option fqdn.fqdn");
210 + free(last_arg_conf);
215 + if (arg_conf == 0) {
216 + arg_conf_len = asprintf(&arg_conf, "timeout %d;", timeout_arg);
218 + if ((arg_conf == 0) || (arg_conf_len <= 0))
219 + log_fatal("Unable to process -timeout timeout argument");
221 + char *last_arg_conf = arg_conf;
223 + arg_conf_len = asprintf(&arg_conf, "%s\ntimeout %d;", last_arg_conf, timeout_arg);
225 + if ((arg_conf == 0) || (arg_conf_len == 0))
226 + log_fatal("Unable to process -timeout timeout argument");
228 + free(last_arg_conf);
232 + if ((dhcp_vendor_class_identifier_arg != NULL) && (*dhcp_vendor_class_identifier_arg != '\0')) {
233 + if (arg_conf == 0) {
234 + arg_conf_len = asprintf(&arg_conf, "send vendor-class-identifier \"%s\";", dhcp_vendor_class_identifier_arg);
236 + if ((arg_conf == 0) || (arg_conf_len <= 0))
237 + log_fatal("Unable to send -V option vendor-class-identifier");
239 + char *last_arg_conf = arg_conf;
241 + arg_conf_len = asprintf(&arg_conf, "%s\nsend vendor-class-identifier \"%s\";", last_arg_conf, dhcp_vendor_class_identifier_arg);
243 + if ((arg_conf == 0) || (arg_conf_len <= 0))
244 + log_fatal("Unable to send -V option vendor-class-identifier");
246 + free(last_arg_conf);
250 + if (dhclient_request_options != NULL) {
251 + if (arg_conf == 0) {
252 + arg_conf_len = asprintf(&arg_conf, "request %s;", dhclient_request_options);
254 + if ((arg_conf == 0) || (arg_conf_len <= 0))
255 + log_fatal("Unable to parse -R <request options list> argument");
257 + char *last_arg_conf = arg_conf;
259 + arg_conf_len = asprintf(&arg_conf, "%s\nrequest %s;", last_arg_conf, dhclient_request_options);
261 + if ((arg_conf == 0) || (arg_conf_len <= 0))
262 + log_fatal("Unable to parse -R <request options list> argument");
264 + free(last_arg_conf);
269 + if (arg_conf_len == 0)
270 + if ((arg_conf_len = strlen(arg_conf)) == 0)
271 + /* huh ? cannot happen ! */
272 + log_fatal("Unable to process -I/-H/-F/-timeout/-V/-R configuration arguments");
274 + /* parse the extra dhclient.conf configuration arguments
275 + * into top level config: */
276 + struct parse *cfile = (struct parse *)0;
277 + const char *val = NULL;
280 + status = new_parse(&cfile, -1, arg_conf, arg_conf_len, "extra dhclient -I/-H/-F/-timeout/-V/-R configuration arguments", 0);
282 + if ((status != ISC_R_SUCCESS) || (cfile -> warnings_occurred))
283 + log_fatal("Cannot parse -I/-H/-F/-timeout/-V/-R configuration arguments !");
284 + /* more detailed parse failures will be logged */
287 + token = peek_token(&val, (unsigned *)0, cfile);
288 + if (token == END_OF_FILE)
291 + parse_client_statement(cfile, (struct interface_info *)0, &top_level_config);
294 + if (cfile -> warnings_occurred)
295 + log_fatal("Cannot parse -I/-H/-F/-timeout/-V/-R configuration arguments !");
299 + /* we just set the toplevel timeout, but per-client
300 + * timeouts may still be at defaults. Also, it makes no
301 + * sense having the reboot_timeout or backoff_cutoff
302 + * greater than the timeout:
304 + if ((top_level_config.backoff_cutoff == 15) && (top_level_config.backoff_cutoff > (timeout_arg / 2)))
305 + top_level_config.backoff_cutoff = (((unsigned long)(timeout_arg / 2)) == 0) ? timeout_arg : (unsigned long)(timeout_arg / 2);
307 + for (ip=interfaces; ip; ip = ip->next) {
308 + if (ip->client->config->timeout == 60)
309 + ip->client->config->timeout = timeout_arg;
311 + if ((ip->client->config->reboot_timeout == 10) && (ip->client->config->reboot_timeout > ip->client->config->timeout))
312 + ip->client->config->reboot_timeout = ip->client->config->timeout;
313 + if ((ip->client->config->backoff_cutoff == 15) && (ip->client->config->backoff_cutoff > top_level_config.backoff_cutoff))
314 + ip->client->config->backoff_cutoff = top_level_config.backoff_cutoff;
318 + if ((dhclient_request_options != 0) && (top_level_config.requested_options != default_requested_options)) {
319 + for (ip=interfaces; ip; ip = ip->next) {
320 + if (ip->client->config->requested_options == default_requested_options)
321 + ip->client->config->requested_options = top_level_config.requested_options;
330 /* Parse the lease database. */
331 read_client_leases();
333 @@ -2397,7 +2657,8 @@ void make_discover (client, lease)
334 client -> packet.xid = random ();
335 client -> packet.secs = 0; /* filled in by send_discover. */
337 - if (can_receive_unicast_unconfigured (client -> interface))
338 + if ((!(bootp_broadcast_always || client->config->bootp_broadcast_always))
339 + && can_receive_unicast_unconfigured(client->interface))
340 client -> packet.flags = 0;
342 client -> packet.flags = htons (BOOTP_BROADCAST);
343 @@ -2481,7 +2742,9 @@ void make_request (client, lease)
345 memset (&client -> packet.ciaddr, 0,
346 sizeof client -> packet.ciaddr);
347 - if (can_receive_unicast_unconfigured (client -> interface))
348 + if ((!(bootp_broadcast_always ||
349 + client ->config->bootp_broadcast_always)) &&
350 + can_receive_unicast_unconfigured (client -> interface))
351 client -> packet.flags = 0;
353 client -> packet.flags = htons (BOOTP_BROADCAST);
354 @@ -2543,7 +2806,8 @@ void make_decline (client, lease)
355 client -> packet.hops = 0;
356 client -> packet.xid = client -> xid;
357 client -> packet.secs = 0; /* Filled in by send_request. */
358 - if (can_receive_unicast_unconfigured (client -> interface))
359 + if ((!(bootp_broadcast_always || client->config-> bootp_broadcast_always))
360 + && can_receive_unicast_unconfigured (client->interface))
361 client -> packet.flags = 0;
363 client -> packet.flags = htons (BOOTP_BROADCAST);
364 diff -up dhcp-4.2.2b1/common/conflex.c.options dhcp-4.2.2b1/common/conflex.c
365 --- dhcp-4.2.2b1/common/conflex.c.options 2011-05-11 16:20:59.000000000 +0200
366 +++ dhcp-4.2.2b1/common/conflex.c 2011-07-01 13:51:52.938755494 +0200
367 @@ -808,6 +808,8 @@ intern(char *atom, enum dhcp_token dfv)
369 if (!strcasecmp (atom + 1, "ound"))
371 + if (!strcasecmp (atom + 1, "ootp-broadcast-always"))
372 + return BOOTP_BROADCAST_ALWAYS;
375 if (!strcasecmp(atom + 1, "ase"))
376 diff -up dhcp-4.2.2b1/includes/dhcpd.h.options dhcp-4.2.2b1/includes/dhcpd.h
377 --- dhcp-4.2.2b1/includes/dhcpd.h.options 2011-05-20 16:21:11.000000000 +0200
378 +++ dhcp-4.2.2b1/includes/dhcpd.h 2011-07-01 13:51:52.940755442 +0200
379 @@ -1147,6 +1147,9 @@ struct client_config {
380 int do_forward_update; /* If nonzero, and if we have the
381 information we need, update the
382 A record for the address we get. */
384 + int bootp_broadcast_always; /* If nonzero, always set the BOOTP_BROADCAST
385 + flag in requests */
388 /* Per-interface state used in the dhcp client... */
389 diff -up dhcp-4.2.2b1/includes/dhctoken.h.options dhcp-4.2.2b1/includes/dhctoken.h
390 --- dhcp-4.2.2b1/includes/dhctoken.h.options 2011-05-12 14:02:47.000000000 +0200
391 +++ dhcp-4.2.2b1/includes/dhctoken.h 2011-07-01 13:53:43.316861637 +0200
392 @@ -361,7 +361,8 @@ enum dhcp_token {
396 - GETHOSTBYNAME = 665
397 + GETHOSTBYNAME = 665,
398 + BOOTP_BROADCAST_ALWAYS = 666
401 #define is_identifier(x) ((x) >= FIRST_TOKEN && \