]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - src/patches/dhcp/dhcp-dhclient-options.patch
Merge remote-tracking branch 'mfischer/slang' into next
[people/pmueller/ipfire-2.x.git] / src / patches / dhcp / dhcp-dhclient-options.patch
CommitLineData
c1e9ba67
MF
1diff -up dhcp-4.3.1b1/client/clparse.c.fLPqYB dhcp-4.3.1b1/client/clparse.c
2--- dhcp-4.3.1b1/client/clparse.c.fLPqYB 2014-07-02 19:58:38.000000000 +0200
3+++ dhcp-4.3.1b1/client/clparse.c 2014-07-10 17:38:26.938599402 +0200
4@@ -148,6 +148,7 @@ isc_result_t read_client_conf ()
78ab9b04
MT
5 /* Requested lease time, used by DHCPv6 (DHCPv4 uses the option cache)
6 */
7 top_level_config.requested_lease = 7200;
8+ top_level_config.bootp_broadcast_always = 0;
9
10 group_allocate (&top_level_config.on_receipt, MDL);
11 if (!top_level_config.on_receipt)
c1e9ba67 12@@ -353,7 +354,8 @@ void read_client_leases ()
78ab9b04
MT
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 */
19
20 void parse_client_statement (cfile, ip, config)
21 struct parse *cfile;
c1e9ba67 22@@ -771,6 +773,12 @@ void parse_client_statement (cfile, ip,
78ab9b04
MT
23 parse_reject_statement (cfile, config);
24 return;
25
26+ case BOOTP_BROADCAST_ALWAYS:
27+ token = next_token(&val, (unsigned*)0, cfile);
28+ config -> bootp_broadcast_always = 1;
29+ parse_semi (cfile);
30+ return;
31+
32 default:
33 lose = 0;
34 stmt = (struct executable_statement *)0;
c1e9ba67
MF
35diff -up dhcp-4.3.1b1/client/dhclient.8.fLPqYB dhcp-4.3.1b1/client/dhclient.8
36--- dhcp-4.3.1b1/client/dhclient.8.fLPqYB 2014-07-02 19:58:38.000000000 +0200
37+++ dhcp-4.3.1b1/client/dhclient.8 2014-07-10 17:38:26.938599402 +0200
38@@ -128,6 +128,33 @@ dhclient - Dynamic Host Configuration Pr
39 .B -w
40 ]
41 [
42+.B -B
43+]
44+[
45+.B -C
46+.I dhcp-client-identifier
47+]
48+[
49+.B -H
50+.I host-name
51+]
52+[
53+.B -F
54+.I fqdn.fqdn
55+]
56+[
57+.B -V
58+.I vendor-class-identifier
59+]
60+[
61+.B -R
62+.I request-option-list
63+]
64+[
65+.B -timeout
66+.I timeout
67+]
68+[
69 .B -v
70 ]
71 [
72@@ -275,6 +302,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.
76+
77+.TP
78+.BI \-B
79+Set the BOOTP broadcast flag in request packets so servers will always
80+broadcast replies.
81+
82+.TP
83+.BI \-C\ <dhcp-client-identifier>
84+Specify the dhcp-client-identifier option to send to the DHCP server.
85+
86+.TP
87+.BI \-H\ <host-name>
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
92+.B -H
93+option cannot be used with the
94+.B -F
95+option.
96+
97+.TP
98+.BI \-F\ <fqdn.fqdn>
99+Specify the fqdn.fqdn option to send to the DHCP server. This option cannot
100+be used with the
101+.B -H
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.
104+
105+.TP
106+.BI \-V\ <vendor-class-identifier>
107+Specify the vendor-class-identifier option to send to the DHCP server.
108+
109+.TP
110+.BI \-R\ <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
114+list is:
115+
116+.BR
117+ subnet-mask, broadcast-address, time-offset, routers,
118+.BR
119+ domain-search, domain-name, domain-name-servers, host-name,
120+.BR
121+ nis-domain, nis-servers, ntp-servers, interface-mtu
122+
123+.TP
124+.B -R
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 -R
130+parameter.
131+
132+.TP
133+.BI \-timeout\ <timeout>
134+Specify the time after which
135+.B dhclient
136+will decide that no DHCP servers can be contacted when no responses have been
137+received.
138+
139 .TP
140 .BI \-n
141 Do not configure any interfaces. This is most likely to be useful in
142diff -up dhcp-4.3.1b1/client/dhclient.c.fLPqYB dhcp-4.3.1b1/client/dhclient.c
143--- dhcp-4.3.1b1/client/dhclient.c.fLPqYB 2014-07-02 19:58:38.000000000 +0200
144+++ dhcp-4.3.1b1/client/dhclient.c 2014-07-10 17:38:44.520350055 +0200
78ab9b04
MT
145@@ -39,6 +39,12 @@
146 #include <limits.h>
147 #include <dns/result.h>
148
149+/*
150+ * Defined in stdio.h when _GNU_SOURCE is set, but we don't want to define
151+ * that when building ISC code.
152+ */
153+extern int asprintf(char **strp, const char *fmt, ...);
154+
155 TIME default_lease_time = 43200; /* 12 hours... */
156 TIME max_lease_time = 86400; /* 24 hours... */
157
c1e9ba67 158@@ -88,6 +94,9 @@ int wanted_ia_na = -1; /* the absolute
78ab9b04
MT
159 int wanted_ia_ta = 0;
160 int wanted_ia_pd = 0;
161 char *mockup_relay = NULL;
162+int bootp_broadcast_always = 0;
163+
c1e9ba67 164+extern struct option *default_requested_options[];
78ab9b04
MT
165
166 void run_stateless(int exit_mode);
167
c1e9ba67 168@@ -125,6 +134,15 @@ main(int argc, char **argv) {
78ab9b04
MT
169 int local_family_set = 0;
170 #endif /* DHCPv6 */
171 char *s;
172+ char *dhcp_client_identifier_arg = NULL;
173+ char *dhcp_host_name_arg = NULL;
174+ char *dhcp_fqdn_arg = NULL;
175+ char *dhcp_vendor_class_identifier_arg = NULL;
176+ char *dhclient_request_options = NULL;
177+
178+ int timeout_arg = 0;
179+ char *arg_conf = NULL;
180+ int arg_conf_len = 0;
181
182 /* Initialize client globals. */
183 memset(&default_duid, 0, sizeof(default_duid));
c1e9ba67
MF
184@@ -325,6 +343,88 @@ main(int argc, char **argv) {
185 strlen(PACKAGE_VERSION)));
186 IGNORE_RET(write(STDERR_FILENO, "\n", 1));
78ab9b04 187 exit(0);
c1e9ba67 188+ } else if (!strcmp(argv[i], "-C")) {
78ab9b04
MT
189+ if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
190+ usage();
191+ exit(1);
192+ }
193+
194+ if (strlen(argv[i]) >= DHCP_MAX_OPTION_LEN) {
c1e9ba67 195+ log_error("-C option dhcp-client-identifier string \"%s\" is too long - maximum length is: %d", argv[i], DHCP_MAX_OPTION_LEN-1);
78ab9b04
MT
196+ exit(1);
197+ }
198+
199+ dhcp_client_identifier_arg = argv[i];
200+ } else if (!strcmp(argv[i], "-B")) {
201+ bootp_broadcast_always = 1;
202+ } else if (!strcmp(argv[i], "-H")) {
203+ if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
204+ usage();
205+ exit(1);
206+ }
207+
208+ if (strlen(argv[i]) >= DHCP_MAX_OPTION_LEN) {
209+ log_error("-H option host-name string \"%s\" is too long - maximum length is: %d", argv[i], DHCP_MAX_OPTION_LEN-1);
210+ exit(1);
211+ }
212+
213+ if (dhcp_host_name_arg != NULL) {
214+ log_error("The -H <host-name> and -F <fqdn> arguments are mutually exclusive");
215+ exit(1);
216+ }
217+
218+ dhcp_host_name_arg = argv[i];
219+ } else if (!strcmp(argv[i], "-F")) {
220+ if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
221+ usage();
222+ exit(1);
223+ }
224+
225+ if (strlen(argv[i]) >= DHCP_MAX_OPTION_LEN) {
226+ log_error("-F option fqdn.fqdn string \"%s\" is too long - maximum length is: %d", argv[i], DHCP_MAX_OPTION_LEN-1);
227+ exit(1);
228+ }
229+
230+ if (dhcp_fqdn_arg != NULL) {
231+ log_error("Only one -F <fqdn> argument can be specified");
232+ exit(1);
233+ }
234+
235+ if (dhcp_host_name_arg != NULL) {
236+ log_error("The -F <fqdn> and -H <host-name> arguments are mutually exclusive");
237+ exit(1);
238+ }
239+
240+ dhcp_fqdn_arg = argv[i];
241+ } else if (!strcmp(argv[i], "-timeout")) {
242+ if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
243+ usage();
244+ exit(1);
245+ }
246+
247+ if ((timeout_arg = atoi(argv[i])) <= 0) {
c1e9ba67 248+ log_error("timeout option must be > 0 - bad value: %s",argv[i]);
78ab9b04
MT
249+ exit(1);
250+ }
251+ } else if (!strcmp(argv[i], "-V")) {
252+ if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
253+ usage();
254+ exit(1);
255+ }
256+
257+ if (strlen(argv[i]) >= DHCP_MAX_OPTION_LEN) {
258+ log_error("-V option vendor-class-identifier string \"%s\" is too long - maximum length is: %d", argv[i], DHCP_MAX_OPTION_LEN-1);
259+ exit(1);
260+ }
261+
262+ dhcp_vendor_class_identifier_arg = argv[i];
263+ } else if (!strcmp(argv[i], "-R")) {
264+ if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
265+ usage();
266+ exit(1);
267+ }
268+
269+ dhclient_request_options = argv[i];
270 } else if (argv[i][0] == '-') {
271 usage();
272 } else if (interfaces_requested < 0) {
c1e9ba67 273@@ -507,6 +607,156 @@ main(int argc, char **argv) {
78ab9b04
MT
274 /* Parse the dhclient.conf file. */
275 read_client_conf();
276
277+ /* Parse any extra command line configuration arguments: */
278+ if ((dhcp_client_identifier_arg != NULL) && (*dhcp_client_identifier_arg != '\0')) {
279+ arg_conf_len = asprintf(&arg_conf, "send dhcp-client-identifier \"%s\";", dhcp_client_identifier_arg);
280+
281+ if ((arg_conf == 0) || (arg_conf_len <= 0))
c1e9ba67 282+ log_fatal("Unable to send -C option dhcp-client-identifier");
78ab9b04
MT
283+ }
284+
285+ if ((dhcp_host_name_arg != NULL) && (*dhcp_host_name_arg != '\0')) {
286+ if (arg_conf == 0) {
287+ arg_conf_len = asprintf(&arg_conf, "send host-name \"%s\";", dhcp_host_name_arg);
288+
289+ if ((arg_conf == 0) || (arg_conf_len <= 0))
290+ log_fatal("Unable to send -H option host-name");
291+ } else {
292+ char *last_arg_conf = arg_conf;
293+ arg_conf = NULL;
294+ arg_conf_len = asprintf(&arg_conf, "%s\nsend host-name \"%s\";", last_arg_conf, dhcp_host_name_arg);
295+
296+ if ((arg_conf == 0) || (arg_conf_len <= 0))
297+ log_fatal("Unable to send -H option host-name");
298+
299+ free(last_arg_conf);
300+ }
301+ }
302+
303+ if ((dhcp_fqdn_arg != NULL) && (*dhcp_fqdn_arg != '\0')) {
304+ if (arg_conf == 0) {
305+ arg_conf_len = asprintf(&arg_conf, "send fqdn.fqdn \"%s\";", dhcp_fqdn_arg);
306+
307+ if ((arg_conf == 0) || (arg_conf_len <= 0))
308+ log_fatal("Unable to send -F option fqdn.fqdn");
309+ } else {
310+ char *last_arg_conf = arg_conf;
311+ arg_conf = NULL;
312+ arg_conf_len = asprintf(&arg_conf, "%s\nsend fqdn.fqdn \"%s\";", last_arg_conf, dhcp_fqdn_arg);
313+
314+ if ((arg_conf == 0) || (arg_conf_len <= 0))
315+ log_fatal("Unable to send -F option fqdn.fqdn");
316+
317+ free(last_arg_conf);
318+ }
319+ }
320+
321+ if (timeout_arg) {
322+ if (arg_conf == 0) {
323+ arg_conf_len = asprintf(&arg_conf, "timeout %d;", timeout_arg);
324+
325+ if ((arg_conf == 0) || (arg_conf_len <= 0))
326+ log_fatal("Unable to process -timeout timeout argument");
327+ } else {
328+ char *last_arg_conf = arg_conf;
329+ arg_conf = NULL;
330+ arg_conf_len = asprintf(&arg_conf, "%s\ntimeout %d;", last_arg_conf, timeout_arg);
331+
332+ if ((arg_conf == 0) || (arg_conf_len == 0))
333+ log_fatal("Unable to process -timeout timeout argument");
334+
335+ free(last_arg_conf);
336+ }
337+ }
338+
339+ if ((dhcp_vendor_class_identifier_arg != NULL) && (*dhcp_vendor_class_identifier_arg != '\0')) {
340+ if (arg_conf == 0) {
341+ arg_conf_len = asprintf(&arg_conf, "send vendor-class-identifier \"%s\";", dhcp_vendor_class_identifier_arg);
342+
343+ if ((arg_conf == 0) || (arg_conf_len <= 0))
344+ log_fatal("Unable to send -V option vendor-class-identifier");
345+ } else {
346+ char *last_arg_conf = arg_conf;
347+ arg_conf = NULL;
348+ arg_conf_len = asprintf(&arg_conf, "%s\nsend vendor-class-identifier \"%s\";", last_arg_conf, dhcp_vendor_class_identifier_arg);
349+
350+ if ((arg_conf == 0) || (arg_conf_len <= 0))
351+ log_fatal("Unable to send -V option vendor-class-identifier");
352+
353+ free(last_arg_conf);
354+ }
355+ }
356+
357+ if (dhclient_request_options != NULL) {
358+ if (arg_conf == 0) {
359+ arg_conf_len = asprintf(&arg_conf, "request %s;", dhclient_request_options);
360+
361+ if ((arg_conf == 0) || (arg_conf_len <= 0))
362+ log_fatal("Unable to parse -R <request options list> argument");
363+ } else {
364+ char *last_arg_conf = arg_conf;
365+ arg_conf = NULL;
366+ arg_conf_len = asprintf(&arg_conf, "%s\nrequest %s;", last_arg_conf, dhclient_request_options);
367+
368+ if ((arg_conf == 0) || (arg_conf_len <= 0))
369+ log_fatal("Unable to parse -R <request options list> argument");
370+
371+ free(last_arg_conf);
372+ }
373+ }
374+
375+ if (arg_conf) {
376+ if (arg_conf_len == 0)
377+ if ((arg_conf_len = strlen(arg_conf)) == 0)
378+ /* huh ? cannot happen ! */
c1e9ba67 379+ log_fatal("Unable to process -C/-H/-F/-timeout/-V/-R configuration arguments");
78ab9b04
MT
380+
381+ /* parse the extra dhclient.conf configuration arguments
382+ * into top level config: */
383+ struct parse *cfile = (struct parse *)0;
384+ const char *val = NULL;
385+ int token;
386+
c1e9ba67 387+ status = new_parse(&cfile, -1, arg_conf, arg_conf_len, "extra dhclient -C/-H/-F/-timeout/-V/-R configuration arguments", 0);
78ab9b04
MT
388+
389+ if ((status != ISC_R_SUCCESS) || (cfile -> warnings_occurred))
c1e9ba67 390+ log_fatal("Cannot parse -C/-H/-F/-timeout/-V/-R configuration arguments !");
78ab9b04
MT
391+ /* more detailed parse failures will be logged */
392+
393+ do {
394+ token = peek_token(&val, (unsigned *)0, cfile);
395+ if (token == END_OF_FILE)
396+ break;
397+
398+ parse_client_statement(cfile, (struct interface_info *)0, &top_level_config);
399+ } while (1);
400+
401+ if (cfile -> warnings_occurred)
c1e9ba67 402+ log_fatal("Cannot parse -C/-H/-F/-timeout/-V/-R configuration arguments !");
78ab9b04
MT
403+ end_parse(&cfile);
404+
405+ if (timeout_arg) {
406+ /* we just set the toplevel timeout, but per-client
c1e9ba67 407+ * timeouts may still be at defaults.
78ab9b04 408+ */
78ab9b04
MT
409+ for (ip=interfaces; ip; ip = ip->next) {
410+ if (ip->client->config->timeout == 60)
411+ ip->client->config->timeout = timeout_arg;
78ab9b04
MT
412+ }
413+ }
414+
415+ if ((dhclient_request_options != 0) && (top_level_config.requested_options != default_requested_options)) {
416+ for (ip=interfaces; ip; ip = ip->next) {
417+ if (ip->client->config->requested_options == default_requested_options)
418+ ip->client->config->requested_options = top_level_config.requested_options;
419+ }
420+ }
421+
422+ free(arg_conf);
423+ arg_conf = NULL;
424+ arg_conf_len = 0;
425+ }
426+
427 /* Parse the lease database. */
428 read_client_leases();
429
c1e9ba67
MF
430@@ -756,6 +1006,10 @@ static void usage()
431 " [-s server-addr] [-cf config-file]\n"
432 " [-df duid-file] [-lf lease-file]\n"
433 " [-pf pid-file] [--no-pid] [-e VAR=val]\n"
434+ " [-C <dhcp-client-identifier>] [-B]\n"
435+ " [-H <host-name> | -F <fqdn.fqdn>] [-timeout <timeout>]\n"
436+ " [-V <vendor-class-identifier>]\n"
437+ " [-R <request option list>]\n"
438 " [-sf script-file] [interface]");
439 }
440
441@@ -2531,7 +2785,8 @@ void make_discover (client, lease)
78ab9b04
MT
442 client -> packet.xid = random ();
443 client -> packet.secs = 0; /* filled in by send_discover. */
444
445- if (can_receive_unicast_unconfigured (client -> interface))
446+ if ((!(bootp_broadcast_always || client->config->bootp_broadcast_always))
447+ && can_receive_unicast_unconfigured(client->interface))
448 client -> packet.flags = 0;
449 else
450 client -> packet.flags = htons (BOOTP_BROADCAST);
c1e9ba67 451@@ -2615,7 +2870,9 @@ void make_request (client, lease)
78ab9b04
MT
452 } else {
453 memset (&client -> packet.ciaddr, 0,
454 sizeof client -> packet.ciaddr);
455- if (can_receive_unicast_unconfigured (client -> interface))
456+ if ((!(bootp_broadcast_always ||
457+ client ->config->bootp_broadcast_always)) &&
458+ can_receive_unicast_unconfigured (client -> interface))
459 client -> packet.flags = 0;
460 else
461 client -> packet.flags = htons (BOOTP_BROADCAST);
c1e9ba67 462@@ -2677,7 +2934,8 @@ void make_decline (client, lease)
78ab9b04
MT
463 client -> packet.hops = 0;
464 client -> packet.xid = client -> xid;
465 client -> packet.secs = 0; /* Filled in by send_request. */
466- if (can_receive_unicast_unconfigured (client -> interface))
467+ if ((!(bootp_broadcast_always || client->config-> bootp_broadcast_always))
468+ && can_receive_unicast_unconfigured (client->interface))
469 client -> packet.flags = 0;
470 else
471 client -> packet.flags = htons (BOOTP_BROADCAST);
c1e9ba67
MF
472diff -up dhcp-4.3.1b1/common/conflex.c.fLPqYB dhcp-4.3.1b1/common/conflex.c
473--- dhcp-4.3.1b1/common/conflex.c.fLPqYB 2014-07-02 19:58:38.000000000 +0200
474+++ dhcp-4.3.1b1/common/conflex.c 2014-07-10 17:38:26.940599374 +0200
475@@ -811,6 +811,8 @@ intern(char *atom, enum dhcp_token dfv)
78ab9b04
MT
476 return BALANCE;
477 if (!strcasecmp (atom + 1, "ound"))
478 return BOUND;
479+ if (!strcasecmp (atom + 1, "ootp-broadcast-always"))
480+ return BOOTP_BROADCAST_ALWAYS;
481 break;
482 case 'c':
483 if (!strcasecmp(atom + 1, "ase"))
c1e9ba67
MF
484diff -up dhcp-4.3.1b1/includes/dhcpd.h.fLPqYB dhcp-4.3.1b1/includes/dhcpd.h
485--- dhcp-4.3.1b1/includes/dhcpd.h.fLPqYB 2014-07-02 19:58:39.000000000 +0200
486+++ dhcp-4.3.1b1/includes/dhcpd.h 2014-07-10 17:38:26.941599360 +0200
487@@ -1152,6 +1152,9 @@ struct client_config {
78ab9b04
MT
488 int do_forward_update; /* If nonzero, and if we have the
489 information we need, update the
490 A record for the address we get. */
491+
492+ int bootp_broadcast_always; /* If nonzero, always set the BOOTP_BROADCAST
493+ flag in requests */
494 };
495
496 /* Per-interface state used in the dhcp client... */
c1e9ba67
MF
497diff -up dhcp-4.3.1b1/includes/dhctoken.h.fLPqYB dhcp-4.3.1b1/includes/dhctoken.h
498--- dhcp-4.3.1b1/includes/dhctoken.h.fLPqYB 2014-07-02 19:58:39.000000000 +0200
499+++ dhcp-4.3.1b1/includes/dhctoken.h 2014-07-10 17:38:26.942599346 +0200
500@@ -367,7 +367,8 @@ enum dhcp_token {
501 TOKEN_INFINIBAND = 668,
502 POOL6 = 669,
503 V6RELAY = 670,
504- V6RELOPT = 671
505+ V6RELOPT = 671,
506+ BOOTP_BROADCAST_ALWAYS = 672
78ab9b04
MT
507 };
508
509 #define is_identifier(x) ((x) >= FIRST_TOKEN && \