]> git.pld-linux.org Git - packages/dhcp.git/blame - dhcp-options.patch
- updated to 4.4.3-P1
[packages/dhcp.git] / dhcp-options.patch
CommitLineData
15c1a831
MK
1From af18c830fe55f6be0b89997a36b611d981e3c25d Mon Sep 17 00:00:00 2001
2From: Pavel Zhukov <pzhukov@redhat.com>
3Date: Thu, 21 Feb 2019 10:19:47 +0100
4Subject: [PATCH 02/28] additional dhclient options
5
6---
7 client/clparse.c | 10 +-
8 client/dhclient.8 | 27 +++++
9 client/dhclient.c | 271 +++++++++++++++++++++++++++++++++++++++++++-
10 common/conflex.c | 2 +
11 includes/dhcpd.h | 3 +
12 includes/dhctoken.h | 3 +-
13 6 files changed, 309 insertions(+), 7 deletions(-)
14
15diff --git a/client/clparse.c b/client/clparse.c
16index 74ca499..bb63825 100644
17--- a/client/clparse.c
18+++ b/client/clparse.c
19459f16 19@@ -192,6 +192,7 @@ isc_result_t read_client_conf ()
19507c9d
AM
20 /* Requested lease time, used by DHCPv6 (DHCPv4 uses the option cache)
21 */
22 top_level_config.requested_lease = 7200;
23+ top_level_config.bootp_broadcast_always = 0;
24
25 group_allocate (&top_level_config.on_receipt, MDL);
26 if (!top_level_config.on_receipt)
19459f16 27@@ -397,7 +398,8 @@ void read_client_leases ()
19507c9d
AM
28 interface-declaration |
29 LEASE client-lease-statement |
30 ALIAS client-lease-statement |
31- KEY key-definition */
32+ KEY key-definition |
33+ BOOTP_BROADCAST_ALWAYS */
34
35 void parse_client_statement (cfile, ip, config)
36 struct parse *cfile;
15c1a831 37@@ -820,6 +822,12 @@ void parse_client_statement (cfile, ip, config)
19507c9d
AM
38 parse_lease_id_format(cfile);
39 break;
40
41+ case BOOTP_BROADCAST_ALWAYS:
42+ token = next_token(&val, (unsigned*)0, cfile);
43+ config -> bootp_broadcast_always = 1;
44+ parse_semi (cfile);
45+ return;
46+
47
48 default:
49 lose = 0;
15c1a831
MK
50diff --git a/client/dhclient.8 b/client/dhclient.8
51index 861ff56..5029dac 100644
52--- a/client/dhclient.8
53+++ b/client/dhclient.8
54@@ -135,6 +135,33 @@ dhclient - Dynamic Host Configuration Protocol Client
55 .B -w
96d6b603
JR
56 ]
57 [
58+.B -B
59+]
60+[
19507c9d 61+.B -C
96d6b603
JR
62+.I dhcp-client-identifier
63+]
64+[
65+.B -H
66+.I host-name
67+]
68+[
69+.B -F
70+.I fqdn.fqdn
71+]
72+[
73+.B -V
74+.I vendor-class-identifier
75+]
76+[
19507c9d 77+.B --request-options
96d6b603
JR
78+.I request-option-list
79+]
80+[
19507c9d 81+.B --timeout
96d6b603
JR
82+.I timeout
83+]
84+[
15c1a831
MK
85 .B --dad-wait-time
86 .I seconds
96d6b603 87 ]
15c1a831
MK
88diff --git a/client/dhclient.c b/client/dhclient.c
89index 46dc3a7..6c1c09a 100644
90--- a/client/dhclient.c
91+++ b/client/dhclient.c
3ae1beff
PZ
92@@ -41,6 +41,12 @@
93 #include <sys/wait.h>
94 #include <limits.h>
c494ae74
PZ
95
96+/*
97+ * Defined in stdio.h when _GNU_SOURCE is set, but we don't want to define
98+ * that when building ISC code.
99+ */
100+extern int asprintf(char **strp, const char *fmt, ...);
101+
102 TIME default_lease_time = 43200; /* 12 hours... */
103 TIME max_lease_time = 86400; /* 24 hours... */
104
15c1a831 105@@ -113,6 +119,10 @@ char *mockup_relay = NULL;
19507c9d
AM
106
107 char *progname = NULL;
108
c494ae74
PZ
109+int bootp_broadcast_always = 0;
110+
19507c9d
AM
111+extern struct option *default_requested_options[];
112+
113 void run_stateless(int exit_mode, u_int16_t port);
114
115 static isc_result_t write_duid(struct data_string *duid);
15c1a831 116@@ -189,8 +199,12 @@ static const char use_v6command[] = "Command not used for DHCPv4: %s";
3ae1beff
PZ
117 " [-s server-addr] [-cf config-file]\n" \
118 " [-df duid-file] [-lf lease-file]\n" \
119 " [-pf pid-file] [--no-pid] [-e VAR=val]\n" \
120-" [-sf script-file] [interface]*"
15c1a831 121-
3ae1beff
PZ
122+" [-sf script-file] [interface]*\n" \
123+" [-C <dhcp-client-identifier>] [-B]\n" \
124+" [-H <host-name> | -F <fqdn.fqdn>] [--timeout <timeout>]\n" \
125+" [-V <vendor-class-identifier>]\n" \
126+" [--request-options <request option list>]"
15c1a831 127+
3ae1beff
PZ
128 #define DHCLIENT_USAGEH "{--version|--help|-h}"
129
15c1a831
MK
130 static void
131@@ -249,6 +263,16 @@ main(int argc, char **argv) {
132 #else
133 progname = argv[0];
134 #endif
135+ char *dhcp_client_identifier_arg = NULL;
136+ char *dhcp_host_name_arg = NULL;
c494ae74
PZ
137+ char *dhcp_fqdn_arg = NULL;
138+ char *dhcp_vendor_class_identifier_arg = NULL;
139+ char *dhclient_request_options = NULL;
140+
141+ int timeout_arg = 0;
142+ char *arg_conf = NULL;
143+ int arg_conf_len = 0;
19507c9d 144+
15c1a831
MK
145 /* Initialize client globals. */
146 memset(&default_duid, 0, sizeof(default_duid));
147
148@@ -564,6 +588,89 @@ main(int argc, char **argv) {
149 std_dhcid = 1;
150 } else if (!strcmp(argv[i], "-v")) {
151 quiet = 0;
19507c9d 152+ } else if (!strcmp(argv[i], "-C")) {
c494ae74 153+ if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
19507c9d 154+ usage(use_noarg, argv[i-1]);
96d6b603 155+ exit(1);
c494ae74
PZ
156+ }
157+
8f0e8db7 158+ if (strlen(argv[i]) >= DHCP_MAX_OPTION_LEN) {
19507c9d 159+ log_error("-C option dhcp-client-identifier string \"%s\" is too long - maximum length is: %d", argv[i], DHCP_MAX_OPTION_LEN-1);
c494ae74
PZ
160+ exit(1);
161+ }
162+
163+ dhcp_client_identifier_arg = argv[i];
96d6b603 164+ } else if (!strcmp(argv[i], "-B")) {
c494ae74 165+ bootp_broadcast_always = 1;
96d6b603 166+ } else if (!strcmp(argv[i], "-H")) {
c494ae74 167+ if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
19507c9d 168+ usage(use_noarg, argv[i-1]);
96d6b603 169+ exit(1);
c494ae74
PZ
170+ }
171+
8f0e8db7 172+ if (strlen(argv[i]) >= DHCP_MAX_OPTION_LEN) {
96d6b603 173+ log_error("-H option host-name string \"%s\" is too long - maximum length is: %d", argv[i], DHCP_MAX_OPTION_LEN-1);
c494ae74
PZ
174+ exit(1);
175+ }
176+
177+ if (dhcp_host_name_arg != NULL) {
178+ log_error("The -H <host-name> and -F <fqdn> arguments are mutually exclusive");
179+ exit(1);
180+ }
181+
182+ dhcp_host_name_arg = argv[i];
96d6b603 183+ } else if (!strcmp(argv[i], "-F")) {
c494ae74 184+ if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
19507c9d 185+ usage(use_noarg, argv[i-1]);
96d6b603 186+ exit(1);
c494ae74
PZ
187+ }
188+
8f0e8db7 189+ if (strlen(argv[i]) >= DHCP_MAX_OPTION_LEN) {
96d6b603 190+ log_error("-F option fqdn.fqdn string \"%s\" is too long - maximum length is: %d", argv[i], DHCP_MAX_OPTION_LEN-1);
c494ae74
PZ
191+ exit(1);
192+ }
193+
194+ if (dhcp_fqdn_arg != NULL) {
195+ log_error("Only one -F <fqdn> argument can be specified");
196+ exit(1);
197+ }
198+
199+ if (dhcp_host_name_arg != NULL) {
200+ log_error("The -F <fqdn> and -H <host-name> arguments are mutually exclusive");
201+ exit(1);
202+ }
203+
204+ dhcp_fqdn_arg = argv[i];
19507c9d 205+ } else if (!strcmp(argv[i], "--timeout")) {
c494ae74 206+ if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
19507c9d 207+ usage(use_noarg, argv[i-1]);
96d6b603 208+ exit(1);
c494ae74
PZ
209+ }
210+
211+ if ((timeout_arg = atoi(argv[i])) <= 0) {
96d6b603 212+ log_error("timeout option must be > 0 - bad value: %s",argv[i]);
c494ae74
PZ
213+ exit(1);
214+ }
96d6b603 215+ } else if (!strcmp(argv[i], "-V")) {
c494ae74 216+ if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
19507c9d 217+ usage(use_noarg, argv[i-1]);
96d6b603 218+ exit(1);
c494ae74
PZ
219+ }
220+
8f0e8db7 221+ if (strlen(argv[i]) >= DHCP_MAX_OPTION_LEN) {
96d6b603 222+ log_error("-V option vendor-class-identifier string \"%s\" is too long - maximum length is: %d", argv[i], DHCP_MAX_OPTION_LEN-1);
c494ae74
PZ
223+ exit(1);
224+ }
225+
226+ dhcp_vendor_class_identifier_arg = argv[i];
19507c9d 227+ } else if (!strcmp(argv[i], "--request-options")) {
c494ae74 228+ if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
19507c9d 229+ usage(use_noarg, argv[i-1]);
96d6b603 230+ exit(1);
c494ae74
PZ
231+ }
232+
96d6b603 233+ dhclient_request_options = argv[i];
3ae1beff 234+
15c1a831
MK
235 } else if (argv[i][0] == '-') {
236 usage("Unknown command: %s", argv[i]);
237 } else if (interfaces_requested < 0) {
238@@ -760,6 +867,156 @@ main(int argc, char **argv) {
c494ae74 239 /* Parse the dhclient.conf file. */
96d6b603 240 read_client_conf();
c494ae74
PZ
241
242+ /* Parse any extra command line configuration arguments: */
243+ if ((dhcp_client_identifier_arg != NULL) && (*dhcp_client_identifier_arg != '\0')) {
244+ arg_conf_len = asprintf(&arg_conf, "send dhcp-client-identifier \"%s\";", dhcp_client_identifier_arg);
245+
246+ if ((arg_conf == 0) || (arg_conf_len <= 0))
19507c9d 247+ log_fatal("Unable to send -C option dhcp-client-identifier");
c494ae74
PZ
248+ }
249+
250+ if ((dhcp_host_name_arg != NULL) && (*dhcp_host_name_arg != '\0')) {
251+ if (arg_conf == 0) {
252+ arg_conf_len = asprintf(&arg_conf, "send host-name \"%s\";", dhcp_host_name_arg);
253+
254+ if ((arg_conf == 0) || (arg_conf_len <= 0))
255+ log_fatal("Unable to send -H option host-name");
256+ } else {
257+ char *last_arg_conf = arg_conf;
258+ arg_conf = NULL;
96d6b603 259+ arg_conf_len = asprintf(&arg_conf, "%s\nsend host-name \"%s\";", last_arg_conf, dhcp_host_name_arg);
c494ae74
PZ
260+
261+ if ((arg_conf == 0) || (arg_conf_len <= 0))
262+ log_fatal("Unable to send -H option host-name");
263+
264+ free(last_arg_conf);
265+ }
266+ }
267+
268+ if ((dhcp_fqdn_arg != NULL) && (*dhcp_fqdn_arg != '\0')) {
269+ if (arg_conf == 0) {
270+ arg_conf_len = asprintf(&arg_conf, "send fqdn.fqdn \"%s\";", dhcp_fqdn_arg);
271+
272+ if ((arg_conf == 0) || (arg_conf_len <= 0))
273+ log_fatal("Unable to send -F option fqdn.fqdn");
274+ } else {
275+ char *last_arg_conf = arg_conf;
276+ arg_conf = NULL;
96d6b603 277+ arg_conf_len = asprintf(&arg_conf, "%s\nsend fqdn.fqdn \"%s\";", last_arg_conf, dhcp_fqdn_arg);
c494ae74
PZ
278+
279+ if ((arg_conf == 0) || (arg_conf_len <= 0))
280+ log_fatal("Unable to send -F option fqdn.fqdn");
281+
282+ free(last_arg_conf);
283+ }
284+ }
285+
286+ if (timeout_arg) {
287+ if (arg_conf == 0) {
288+ arg_conf_len = asprintf(&arg_conf, "timeout %d;", timeout_arg);
289+
290+ if ((arg_conf == 0) || (arg_conf_len <= 0))
19507c9d 291+ log_fatal("Unable to process --timeout timeout argument");
c494ae74
PZ
292+ } else {
293+ char *last_arg_conf = arg_conf;
294+ arg_conf = NULL;
96d6b603 295+ arg_conf_len = asprintf(&arg_conf, "%s\ntimeout %d;", last_arg_conf, timeout_arg);
c494ae74
PZ
296+
297+ if ((arg_conf == 0) || (arg_conf_len == 0))
19507c9d 298+ log_fatal("Unable to process --timeout timeout argument");
c494ae74
PZ
299+
300+ free(last_arg_conf);
301+ }
302+ }
303+
304+ if ((dhcp_vendor_class_identifier_arg != NULL) && (*dhcp_vendor_class_identifier_arg != '\0')) {
305+ if (arg_conf == 0) {
306+ arg_conf_len = asprintf(&arg_conf, "send vendor-class-identifier \"%s\";", dhcp_vendor_class_identifier_arg);
307+
308+ if ((arg_conf == 0) || (arg_conf_len <= 0))
309+ log_fatal("Unable to send -V option vendor-class-identifier");
310+ } else {
311+ char *last_arg_conf = arg_conf;
312+ arg_conf = NULL;
313+ arg_conf_len = asprintf(&arg_conf, "%s\nsend vendor-class-identifier \"%s\";", last_arg_conf, dhcp_vendor_class_identifier_arg);
314+
315+ if ((arg_conf == 0) || (arg_conf_len <= 0))
316+ log_fatal("Unable to send -V option vendor-class-identifier");
317+
318+ free(last_arg_conf);
319+ }
320+ }
321+
322+ if (dhclient_request_options != NULL) {
323+ if (arg_conf == 0) {
324+ arg_conf_len = asprintf(&arg_conf, "request %s;", dhclient_request_options);
325+
326+ if ((arg_conf == 0) || (arg_conf_len <= 0))
19507c9d 327+ log_fatal("Unable to parse --request-options <request options list> argument");
c494ae74
PZ
328+ } else {
329+ char *last_arg_conf = arg_conf;
330+ arg_conf = NULL;
331+ arg_conf_len = asprintf(&arg_conf, "%s\nrequest %s;", last_arg_conf, dhclient_request_options);
332+
333+ if ((arg_conf == 0) || (arg_conf_len <= 0))
19507c9d 334+ log_fatal("Unable to parse --request-options <request options list> argument");
c494ae74
PZ
335+
336+ free(last_arg_conf);
337+ }
338+ }
339+
340+ if (arg_conf) {
341+ if (arg_conf_len == 0)
342+ if ((arg_conf_len = strlen(arg_conf)) == 0)
343+ /* huh ? cannot happen ! */
19507c9d 344+ log_fatal("Unable to process -C/-H/-F/--timeout/-V/--request-options configuration arguments");
c494ae74
PZ
345+
346+ /* parse the extra dhclient.conf configuration arguments
347+ * into top level config: */
348+ struct parse *cfile = (struct parse *)0;
349+ const char *val = NULL;
350+ int token;
351+
19507c9d 352+ status = new_parse(&cfile, -1, arg_conf, arg_conf_len, "extra dhclient -C/-H/-F/--timeout/-V/--request-options configuration arguments", 0);
c494ae74
PZ
353+
354+ if ((status != ISC_R_SUCCESS) || (cfile -> warnings_occurred))
19507c9d 355+ log_fatal("Cannot parse -C/-H/-F/--timeout/-V/--request-options configuration arguments !");
c494ae74
PZ
356+ /* more detailed parse failures will be logged */
357+
358+ do {
96d6b603 359+ token = peek_token(&val, (unsigned *)0, cfile);
c494ae74
PZ
360+ if (token == END_OF_FILE)
361+ break;
362+
96d6b603 363+ parse_client_statement(cfile, (struct interface_info *)0, &top_level_config);
c494ae74
PZ
364+ } while (1);
365+
366+ if (cfile -> warnings_occurred)
19507c9d 367+ log_fatal("Cannot parse -C/-H/-F/--timeout/-V/--request-options configuration arguments !");
96d6b603 368+ end_parse(&cfile);
c494ae74
PZ
369+
370+ if (timeout_arg) {
371+ /* we just set the toplevel timeout, but per-client
96d6b603 372+ * timeouts may still be at defaults.
c494ae74 373+ */
96d6b603 374+ for (ip=interfaces; ip; ip = ip->next) {
c494ae74
PZ
375+ if (ip->client->config->timeout == 60)
376+ ip->client->config->timeout = timeout_arg;
c494ae74
PZ
377+ }
378+ }
379+
380+ if ((dhclient_request_options != 0) && (top_level_config.requested_options != default_requested_options)) {
96d6b603 381+ for (ip=interfaces; ip; ip = ip->next) {
c494ae74
PZ
382+ if (ip->client->config->requested_options == default_requested_options)
383+ ip->client->config->requested_options = top_level_config.requested_options;
384+ }
385+ }
386+
387+ free(arg_conf);
388+ arg_conf = NULL;
389+ arg_conf_len = 0;
390+ }
391+
392 /* Parse the lease database. */
96d6b603 393 read_client_leases();
c494ae74 394
15c1a831 395@@ -3472,7 +3729,8 @@ void make_discover (client, lease)
c494ae74
PZ
396 client -> packet.xid = random ();
397 client -> packet.secs = 0; /* filled in by send_discover. */
398
399- if (can_receive_unicast_unconfigured (client -> interface))
400+ if ((!(bootp_broadcast_always || client->config->bootp_broadcast_always))
401+ && can_receive_unicast_unconfigured(client->interface))
402 client -> packet.flags = 0;
403 else
404 client -> packet.flags = htons (BOOTP_BROADCAST);
15c1a831 405@@ -3557,7 +3815,9 @@ void make_request (client, lease)
c494ae74
PZ
406 } else {
407 memset (&client -> packet.ciaddr, 0,
408 sizeof client -> packet.ciaddr);
409- if (can_receive_unicast_unconfigured (client -> interface))
410+ if ((!(bootp_broadcast_always ||
411+ client ->config->bootp_broadcast_always)) &&
412+ can_receive_unicast_unconfigured (client -> interface))
413 client -> packet.flags = 0;
414 else
415 client -> packet.flags = htons (BOOTP_BROADCAST);
15c1a831 416@@ -3620,7 +3880,8 @@ void make_decline (client, lease)
c494ae74
PZ
417 client -> packet.hops = 0;
418 client -> packet.xid = client -> xid;
419 client -> packet.secs = 0; /* Filled in by send_request. */
420- if (can_receive_unicast_unconfigured (client -> interface))
421+ if ((!(bootp_broadcast_always || client->config-> bootp_broadcast_always))
422+ && can_receive_unicast_unconfigured (client->interface))
423 client -> packet.flags = 0;
424 else
425 client -> packet.flags = htons (BOOTP_BROADCAST);
15c1a831
MK
426diff --git a/common/conflex.c b/common/conflex.c
427index 8b01dfb..1fa2be3 100644
428--- a/common/conflex.c
429+++ b/common/conflex.c
430@@ -832,6 +832,8 @@ intern(char *atom, enum dhcp_token dfv) {
19507c9d
AM
431 if (!strcasecmp(atom+1, "ig-endian")) {
432 return TOKEN_BIG_ENDIAN;
433 }
96d6b603
JR
434+ if (!strcasecmp (atom + 1, "ootp-broadcast-always"))
435+ return BOOTP_BROADCAST_ALWAYS;
436 break;
437 case 'c':
438 if (!strcasecmp(atom + 1, "ase"))
15c1a831
MK
439diff --git a/includes/dhcpd.h b/includes/dhcpd.h
440index f68b228..3b2e2ca 100644
441--- a/includes/dhcpd.h
442+++ b/includes/dhcpd.h
443@@ -1284,6 +1284,9 @@ struct client_config {
19507c9d
AM
444
445 int lease_id_format; /* format for IDs in lease file,
446 TOKEN_OCTAL or TOKEN_HEX */
96d6b603
JR
447+
448+ int bootp_broadcast_always; /* If nonzero, always set the BOOTP_BROADCAST
449+ flag in requests */
450 };
c494ae74 451
96d6b603 452 /* Per-interface state used in the dhcp client... */
15c1a831
MK
453diff --git a/includes/dhctoken.h b/includes/dhctoken.h
454index e6d125f..6daa422 100644
455--- a/includes/dhctoken.h
456+++ b/includes/dhctoken.h
457@@ -377,7 +377,8 @@ enum dhcp_token {
19507c9d 458 TOKEN_HEX = 677,
3ae1beff 459 TOKEN_OCTAL = 678,
15c1a831
MK
460 KEY_ALGORITHM = 679,
461- DISCONNECT = 680
462+ BOOTP_BROADCAST_ALWAYS = 680,
463+ DISCONNECT = 681
96d6b603 464 };
c494ae74 465
19459f16 466 #define is_identifier(x) ((x) >= FIRST_TOKEN && \
15c1a831
MK
467--
4682.35.1
469
This page took 0.134857 seconds and 4 git commands to generate.