1 diff -urNp -x '*.orig' dhcp-4.4.2.org/client/clparse.c dhcp-4.4.2/client/clparse.c
2 --- dhcp-4.4.2.org/client/clparse.c 2020-01-21 20:21:48.000000000 +0100
3 +++ dhcp-4.4.2/client/clparse.c 2021-05-15 22:10:03.054906758 +0200
4 @@ -192,6 +192,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 @@ -397,7 +398,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 @@ -820,6 +822,12 @@ void parse_client_statement (cfile, ip,
23 parse_lease_id_format(cfile);
26 + case BOOTP_BROADCAST_ALWAYS:
27 + token = next_token(&val, (unsigned*)0, cfile);
28 + config -> bootp_broadcast_always = 1;
35 diff -urNp -x '*.orig' dhcp-4.4.2.org/client/dhclient.8 dhcp-4.4.2/client/dhclient.8
36 --- dhcp-4.4.2.org/client/dhclient.8 2020-01-21 20:21:48.000000000 +0100
37 +++ dhcp-4.4.2/client/dhclient.8 2021-05-15 22:10:03.054906758 +0200
38 @@ -147,6 +147,33 @@ dhclient - Dynamic Host Configuration Pr
46 +.I dhcp-client-identifier
58 +.I vendor-class-identifier
62 +.I request-option-list
72 @@ -302,6 +329,69 @@ not to exit when it doesn't find any suc
73 program can then be used to notify the client when a network interface
74 has been added or removed, so that the client can attempt to configure an IP
75 address on that interface.
79 +Set the BOOTP broadcast flag in request packets so servers will always
83 +.BI \-C\ <dhcp-client-identifier>
84 +Specify the dhcp-client-identifier option to send to the DHCP server.
88 +Specify the host-name option to send to the DHCP server. The host-name
89 +string only contains the client's hostname prefix, to which the server will
90 +append the ddns-domainname or domain-name options, if any, to derive the
91 +fully qualified domain name of the client. The
93 +option cannot be used with the
99 +Specify the fqdn.fqdn option to send to the DHCP server. This option cannot
102 +option. The fqdn.fqdn option must specify the complete domain name of the
103 +client host, which the server may use for dynamic DNS updates.
106 +.BI \-V\ <vendor-class-identifier>
107 +Specify the vendor-class-identifier option to send to the DHCP server.
110 +.BI \--request-options\ <option>[,<option>...]
111 +Specify the list of options the client is to request from the server. The
112 +option list must be a single string consisting of option names separated
113 +by at least one command and optional space characters. The default option
117 + subnet-mask, broadcast-address, time-offset, routers,
119 + domain-search, domain-name, domain-name-servers, host-name,
121 + nis-domain, nis-servers, ntp-servers, interface-mtu
124 +.B --request-options
125 +option does not append options to the default request, it overrides the
126 +default request list. Keep this in mind if you want to request an
127 +additional option besides the default request list. You will have to
128 +specify all option names for the
129 +.B --request-options
133 +.BI \--timeout\ <timeout>
134 +Specify the time after which
136 +will decide that no DHCP servers can be contacted when no responses have been
141 Do not configure any interfaces. This is most likely to be useful in
142 diff -urNp -x '*.orig' dhcp-4.4.2.org/client/dhclient.c dhcp-4.4.2/client/dhclient.c
143 --- dhcp-4.4.2.org/client/dhclient.c 2021-05-15 22:10:02.951572212 +0200
144 +++ dhcp-4.4.2/client/dhclient.c 2021-05-15 22:10:03.054906758 +0200
146 #include <sys/wait.h>
150 + * Defined in stdio.h when _GNU_SOURCE is set, but we don't want to define
151 + * that when building ISC code.
153 +extern int asprintf(char **strp, const char *fmt, ...);
155 TIME default_lease_time = 43200; /* 12 hours... */
156 TIME max_lease_time = 86400; /* 24 hours... */
158 @@ -112,6 +118,10 @@ char *mockup_relay = NULL;
160 char *progname = NULL;
162 +int bootp_broadcast_always = 0;
164 +extern struct option *default_requested_options[];
166 void run_stateless(int exit_mode, u_int16_t port);
168 static isc_result_t write_duid(struct data_string *duid);
169 @@ -188,7 +198,11 @@ static const char use_v6command[] = "Com
170 " [-s server-addr] [-cf config-file]\n" \
171 " [-df duid-file] [-lf lease-file]\n" \
172 " [-pf pid-file] [--no-pid] [-e VAR=val]\n" \
173 -" [-sf script-file] [interface]*"
174 +" [-sf script-file] [interface]*\n" \
175 +" [-C <dhcp-client-identifier>] [-B]\n" \
176 +" [-H <host-name> | -F <fqdn.fqdn>] [--timeout <timeout>]\n" \
177 +" [-V <vendor-class-identifier>]\n" \
178 +" [--request-options <request option list>]"
180 #define DHCLIENT_USAGEH "{--version|--help|-h}"
182 @@ -251,6 +265,17 @@ main(int argc, char **argv) {
183 /* Initialize client globals. */
184 memset(&default_duid, 0, sizeof(default_duid));
186 + char *dhcp_client_identifier_arg = NULL;
187 + char *dhcp_host_name_arg = NULL;
188 + char *dhcp_fqdn_arg = NULL;
189 + char *dhcp_vendor_class_identifier_arg = NULL;
190 + char *dhclient_request_options = NULL;
192 + int timeout_arg = 0;
193 + char *arg_conf = NULL;
194 + int arg_conf_len = 0;
197 /* Make sure that file descriptors 0 (stdin), 1, (stdout), and
198 2 (stderr) are open. To do this, we assume that when we
199 open a file the lowest available file descriptor is used. */
200 @@ -305,6 +330,89 @@ main(int argc, char **argv) {
201 strlen(DHCLIENT_USAGEH)));
202 IGNORE_RET(write(STDERR_FILENO, "\n", 1));
204 + } else if (!strcmp(argv[i], "-C")) {
205 + if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
206 + usage(use_noarg, argv[i-1]);
210 + if (strlen(argv[i]) >= DHCP_MAX_OPTION_LEN) {
211 + log_error("-C option dhcp-client-identifier string \"%s\" is too long - maximum length is: %d", argv[i], DHCP_MAX_OPTION_LEN-1);
215 + dhcp_client_identifier_arg = argv[i];
216 + } else if (!strcmp(argv[i], "-B")) {
217 + bootp_broadcast_always = 1;
218 + } else if (!strcmp(argv[i], "-H")) {
219 + if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
220 + usage(use_noarg, argv[i-1]);
224 + if (strlen(argv[i]) >= DHCP_MAX_OPTION_LEN) {
225 + log_error("-H option host-name string \"%s\" is too long - maximum length is: %d", argv[i], DHCP_MAX_OPTION_LEN-1);
229 + if (dhcp_host_name_arg != NULL) {
230 + log_error("The -H <host-name> and -F <fqdn> arguments are mutually exclusive");
234 + dhcp_host_name_arg = argv[i];
235 + } else if (!strcmp(argv[i], "-F")) {
236 + if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
237 + usage(use_noarg, argv[i-1]);
241 + if (strlen(argv[i]) >= DHCP_MAX_OPTION_LEN) {
242 + log_error("-F option fqdn.fqdn string \"%s\" is too long - maximum length is: %d", argv[i], DHCP_MAX_OPTION_LEN-1);
246 + if (dhcp_fqdn_arg != NULL) {
247 + log_error("Only one -F <fqdn> argument can be specified");
251 + if (dhcp_host_name_arg != NULL) {
252 + log_error("The -F <fqdn> and -H <host-name> arguments are mutually exclusive");
256 + dhcp_fqdn_arg = argv[i];
257 + } else if (!strcmp(argv[i], "--timeout")) {
258 + if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
259 + usage(use_noarg, argv[i-1]);
263 + if ((timeout_arg = atoi(argv[i])) <= 0) {
264 + log_error("timeout option must be > 0 - bad value: %s",argv[i]);
267 + } else if (!strcmp(argv[i], "-V")) {
268 + if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
269 + usage(use_noarg, argv[i-1]);
273 + if (strlen(argv[i]) >= DHCP_MAX_OPTION_LEN) {
274 + log_error("-V option vendor-class-identifier string \"%s\" is too long - maximum length is: %d", argv[i], DHCP_MAX_OPTION_LEN-1);
278 + dhcp_vendor_class_identifier_arg = argv[i];
279 + } else if (!strcmp(argv[i], "--request-options")) {
280 + if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
281 + usage(use_noarg, argv[i-1]);
285 + dhclient_request_options = argv[i];
289 /* When not forbidden prepare to become a daemon */
290 @@ -831,6 +939,156 @@ main(int argc, char **argv) {
291 /* Parse the dhclient.conf file. */
294 + /* Parse any extra command line configuration arguments: */
295 + if ((dhcp_client_identifier_arg != NULL) && (*dhcp_client_identifier_arg != '\0')) {
296 + arg_conf_len = asprintf(&arg_conf, "send dhcp-client-identifier \"%s\";", dhcp_client_identifier_arg);
298 + if ((arg_conf == 0) || (arg_conf_len <= 0))
299 + log_fatal("Unable to send -C option dhcp-client-identifier");
302 + if ((dhcp_host_name_arg != NULL) && (*dhcp_host_name_arg != '\0')) {
303 + if (arg_conf == 0) {
304 + arg_conf_len = asprintf(&arg_conf, "send host-name \"%s\";", dhcp_host_name_arg);
306 + if ((arg_conf == 0) || (arg_conf_len <= 0))
307 + log_fatal("Unable to send -H option host-name");
309 + char *last_arg_conf = arg_conf;
311 + arg_conf_len = asprintf(&arg_conf, "%s\nsend host-name \"%s\";", last_arg_conf, dhcp_host_name_arg);
313 + if ((arg_conf == 0) || (arg_conf_len <= 0))
314 + log_fatal("Unable to send -H option host-name");
316 + free(last_arg_conf);
320 + if ((dhcp_fqdn_arg != NULL) && (*dhcp_fqdn_arg != '\0')) {
321 + if (arg_conf == 0) {
322 + arg_conf_len = asprintf(&arg_conf, "send fqdn.fqdn \"%s\";", dhcp_fqdn_arg);
324 + if ((arg_conf == 0) || (arg_conf_len <= 0))
325 + log_fatal("Unable to send -F option fqdn.fqdn");
327 + char *last_arg_conf = arg_conf;
329 + arg_conf_len = asprintf(&arg_conf, "%s\nsend fqdn.fqdn \"%s\";", last_arg_conf, dhcp_fqdn_arg);
331 + if ((arg_conf == 0) || (arg_conf_len <= 0))
332 + log_fatal("Unable to send -F option fqdn.fqdn");
334 + free(last_arg_conf);
339 + if (arg_conf == 0) {
340 + arg_conf_len = asprintf(&arg_conf, "timeout %d;", timeout_arg);
342 + if ((arg_conf == 0) || (arg_conf_len <= 0))
343 + log_fatal("Unable to process --timeout timeout argument");
345 + char *last_arg_conf = arg_conf;
347 + arg_conf_len = asprintf(&arg_conf, "%s\ntimeout %d;", last_arg_conf, timeout_arg);
349 + if ((arg_conf == 0) || (arg_conf_len == 0))
350 + log_fatal("Unable to process --timeout timeout argument");
352 + free(last_arg_conf);
356 + if ((dhcp_vendor_class_identifier_arg != NULL) && (*dhcp_vendor_class_identifier_arg != '\0')) {
357 + if (arg_conf == 0) {
358 + arg_conf_len = asprintf(&arg_conf, "send vendor-class-identifier \"%s\";", dhcp_vendor_class_identifier_arg);
360 + if ((arg_conf == 0) || (arg_conf_len <= 0))
361 + log_fatal("Unable to send -V option vendor-class-identifier");
363 + char *last_arg_conf = arg_conf;
365 + arg_conf_len = asprintf(&arg_conf, "%s\nsend vendor-class-identifier \"%s\";", last_arg_conf, dhcp_vendor_class_identifier_arg);
367 + if ((arg_conf == 0) || (arg_conf_len <= 0))
368 + log_fatal("Unable to send -V option vendor-class-identifier");
370 + free(last_arg_conf);
374 + if (dhclient_request_options != NULL) {
375 + if (arg_conf == 0) {
376 + arg_conf_len = asprintf(&arg_conf, "request %s;", dhclient_request_options);
378 + if ((arg_conf == 0) || (arg_conf_len <= 0))
379 + log_fatal("Unable to parse --request-options <request options list> argument");
381 + char *last_arg_conf = arg_conf;
383 + arg_conf_len = asprintf(&arg_conf, "%s\nrequest %s;", last_arg_conf, dhclient_request_options);
385 + if ((arg_conf == 0) || (arg_conf_len <= 0))
386 + log_fatal("Unable to parse --request-options <request options list> argument");
388 + free(last_arg_conf);
393 + if (arg_conf_len == 0)
394 + if ((arg_conf_len = strlen(arg_conf)) == 0)
395 + /* huh ? cannot happen ! */
396 + log_fatal("Unable to process -C/-H/-F/--timeout/-V/--request-options configuration arguments");
398 + /* parse the extra dhclient.conf configuration arguments
399 + * into top level config: */
400 + struct parse *cfile = (struct parse *)0;
401 + const char *val = NULL;
404 + status = new_parse(&cfile, -1, arg_conf, arg_conf_len, "extra dhclient -C/-H/-F/--timeout/-V/--request-options configuration arguments", 0);
406 + if ((status != ISC_R_SUCCESS) || (cfile -> warnings_occurred))
407 + log_fatal("Cannot parse -C/-H/-F/--timeout/-V/--request-options configuration arguments !");
408 + /* more detailed parse failures will be logged */
411 + token = peek_token(&val, (unsigned *)0, cfile);
412 + if (token == END_OF_FILE)
415 + parse_client_statement(cfile, (struct interface_info *)0, &top_level_config);
418 + if (cfile -> warnings_occurred)
419 + log_fatal("Cannot parse -C/-H/-F/--timeout/-V/--request-options configuration arguments !");
423 + /* we just set the toplevel timeout, but per-client
424 + * timeouts may still be at defaults.
426 + for (ip=interfaces; ip; ip = ip->next) {
427 + if (ip->client->config->timeout == 60)
428 + ip->client->config->timeout = timeout_arg;
432 + if ((dhclient_request_options != 0) && (top_level_config.requested_options != default_requested_options)) {
433 + for (ip=interfaces; ip; ip = ip->next) {
434 + if (ip->client->config->requested_options == default_requested_options)
435 + ip->client->config->requested_options = top_level_config.requested_options;
444 /* Parse the lease database. */
445 read_client_leases();
447 @@ -991,7 +1249,7 @@ main(int argc, char **argv) {
450 add_timeout(&tv, state_reboot,
454 state_reboot(client);
456 @@ -1771,11 +2029,11 @@ void bootp (packet)
457 ap; ap = ap -> next) {
458 if (addr_match(&packet->client_addr, &ap->match)) {
460 - /* piaddr() returns its result in a static
461 + /* piaddr() returns its result in a static
462 buffer sized 4*16 (see common/inet.c). */
464 - strcpy(addrbuf, piaddr(ap->match.addr));
465 - strcpy(maskbuf, piaddr(ap->match.mask));
466 + strcpy(addrbuf, piaddr(ap->match.addr));
467 + strcpy(maskbuf, piaddr(ap->match.mask));
469 log_info("BOOTREPLY from %s rejected by rule %s "
470 "mask %s.", piaddr(packet->client_addr),
471 @@ -1823,11 +2081,11 @@ void dhcp (packet)
472 ap; ap = ap -> next) {
473 if (addr_match(&packet->client_addr, &ap->match)) {
475 - /* piaddr() returns its result in a static
476 + /* piaddr() returns its result in a static
477 buffer sized 4*16 (see common/inet.c). */
479 - strcpy(addrbuf, piaddr(ap->match.addr));
480 - strcpy(maskbuf, piaddr(ap->match.mask));
481 + strcpy(addrbuf, piaddr(ap->match.addr));
482 + strcpy(maskbuf, piaddr(ap->match.mask));
484 log_info("%s from %s rejected by rule %s mask %s.",
485 type, piaddr(packet->client_addr),
486 @@ -3403,7 +3661,8 @@ void make_discover (client, lease)
487 client -> packet.xid = random ();
488 client -> packet.secs = 0; /* filled in by send_discover. */
490 - if (can_receive_unicast_unconfigured (client -> interface))
491 + if ((!(bootp_broadcast_always || client->config->bootp_broadcast_always))
492 + && can_receive_unicast_unconfigured(client->interface))
493 client -> packet.flags = 0;
495 client -> packet.flags = htons (BOOTP_BROADCAST);
496 @@ -3488,7 +3747,9 @@ void make_request (client, lease)
498 memset (&client -> packet.ciaddr, 0,
499 sizeof client -> packet.ciaddr);
500 - if (can_receive_unicast_unconfigured (client -> interface))
501 + if ((!(bootp_broadcast_always ||
502 + client ->config->bootp_broadcast_always)) &&
503 + can_receive_unicast_unconfigured (client -> interface))
504 client -> packet.flags = 0;
506 client -> packet.flags = htons (BOOTP_BROADCAST);
507 @@ -3551,7 +3812,8 @@ void make_decline (client, lease)
508 client -> packet.hops = 0;
509 client -> packet.xid = client -> xid;
510 client -> packet.secs = 0; /* Filled in by send_request. */
511 - if (can_receive_unicast_unconfigured (client -> interface))
512 + if ((!(bootp_broadcast_always || client->config-> bootp_broadcast_always))
513 + && can_receive_unicast_unconfigured (client->interface))
514 client -> packet.flags = 0;
516 client -> packet.flags = htons (BOOTP_BROADCAST);
517 diff -urNp -x '*.orig' dhcp-4.4.2.org/common/conflex.c dhcp-4.4.2/common/conflex.c
518 --- dhcp-4.4.2.org/common/conflex.c 2020-01-21 20:21:48.000000000 +0100
519 +++ dhcp-4.4.2/common/conflex.c 2021-05-15 22:10:03.054906758 +0200
520 @@ -832,6 +832,8 @@ intern(char *atom, enum dhcp_token dfv)
521 if (!strcasecmp(atom+1, "ig-endian")) {
522 return TOKEN_BIG_ENDIAN;
524 + if (!strcasecmp (atom + 1, "ootp-broadcast-always"))
525 + return BOOTP_BROADCAST_ALWAYS;
528 if (!strcasecmp(atom + 1, "ase"))
529 diff -urNp -x '*.orig' dhcp-4.4.2.org/includes/dhcpd.h dhcp-4.4.2/includes/dhcpd.h
530 --- dhcp-4.4.2.org/includes/dhcpd.h 2021-05-15 22:10:02.951572212 +0200
531 +++ dhcp-4.4.2/includes/dhcpd.h 2021-05-15 22:10:03.054906758 +0200
532 @@ -1279,6 +1279,9 @@ struct client_config {
534 int lease_id_format; /* format for IDs in lease file,
535 TOKEN_OCTAL or TOKEN_HEX */
537 + int bootp_broadcast_always; /* If nonzero, always set the BOOTP_BROADCAST
538 + flag in requests */
541 /* Per-interface state used in the dhcp client... */
542 diff -urNp -x '*.orig' dhcp-4.4.2.org/includes/dhctoken.h dhcp-4.4.2/includes/dhctoken.h
543 --- dhcp-4.4.2.org/includes/dhctoken.h 2020-01-21 20:21:48.000000000 +0100
544 +++ dhcp-4.4.2/includes/dhctoken.h 2021-05-15 22:10:03.054906758 +0200
545 @@ -376,7 +376,8 @@ enum dhcp_token {
546 LEASE_ID_FORMAT = 676,
549 - KEY_ALGORITHM = 679
550 + KEY_ALGORITHM = 679,
551 + BOOTP_BROADCAST_ALWAYS = 680
554 #define is_identifier(x) ((x) >= FIRST_TOKEN && \