]> git.pld-linux.org Git - packages/dhcp.git/blame - dhcp-options.patch
- added try-restart and force-reload options
[packages/dhcp.git] / dhcp-options.patch
CommitLineData
c494ae74
PZ
1diff -up dhcp-3.1.0/common/conflex.c.options dhcp-3.1.0/common/conflex.c
2--- dhcp-3.1.0/common/conflex.c.options 2007-10-22 15:46:24.000000000 -0400
3+++ dhcp-3.1.0/common/conflex.c 2007-10-22 15:48:07.000000000 -0400
4@@ -599,6 +599,8 @@ static enum dhcp_token intern (atom, dfv
5 return BALANCE;
6 if (!strcasecmp (atom + 1, "ound"))
7 return BOUND;
8+ if (!strcasecmp (atom + 1, "ootp-broadcast-always"))
9+ return BOOTP_BROADCAST_ALWAYS;
10 break;
11 case 'c':
12 if (!strcasecmp (atom + 1, "ase"))
13diff -up dhcp-3.1.0/includes/dhcpd.h.options dhcp-3.1.0/includes/dhcpd.h
14--- dhcp-3.1.0/includes/dhcpd.h.options 2007-10-22 15:46:24.000000000 -0400
15+++ dhcp-3.1.0/includes/dhcpd.h 2007-10-22 15:48:21.000000000 -0400
16@@ -912,6 +912,9 @@ struct client_config {
17 int do_forward_update; /* If nonzero, and if we have the
18 information we need, update the
19 A record for the address we get. */
20+
21+ int bootp_broadcast_always; /* If nonzero, always set the BOOTP_BROADCAST
22+ flag in requests */
23 };
24
25 /* Per-interface state used in the dhcp client... */
26diff -up dhcp-3.1.0/includes/dhctoken.h.options dhcp-3.1.0/includes/dhctoken.h
27--- dhcp-3.1.0/includes/dhctoken.h.options 2006-07-31 18:19:51.000000000 -0400
28+++ dhcp-3.1.0/includes/dhctoken.h 2007-10-22 15:49:24.000000000 -0400
29@@ -325,7 +325,8 @@ enum dhcp_token {
30 MIN_BALANCE = 629,
31 DOMAIN_LIST = 630,
32 LEASEQUERY = 631,
33- EXECUTE = 632
34+ EXECUTE = 632,
35+ BOOTP_BROADCAST_ALWAYS = 633
36 };
37
38 #define is_identifier(x) ((x) >= FIRST_TOKEN && \
39diff -up dhcp-3.1.0/client/dhclient.c.options dhcp-3.1.0/client/dhclient.c
40--- dhcp-3.1.0/client/dhclient.c.options 2007-05-22 16:37:04.000000000 -0400
41+++ dhcp-3.1.0/client/dhclient.c 2007-10-22 15:47:51.000000000 -0400
42@@ -38,6 +38,12 @@ static char ocopyright[] =
43 #include "dhcpd.h"
44 #include "version.h"
45
46+/*
47+ * Defined in stdio.h when _GNU_SOURCE is set, but we don't want to define
48+ * that when building ISC code.
49+ */
50+extern int asprintf(char **strp, const char *fmt, ...);
51+
52 TIME default_lease_time = 43200; /* 12 hours... */
53 TIME max_lease_time = 86400; /* 24 hours... */
54
55@@ -74,6 +80,9 @@ int client_env_count=0;
56 int onetry=0;
57 int quiet=0;
58 int nowait=0;
59+int bootp_broadcast_always = 0;
60+
61+extern u_int32_t default_requested_options[];
62 #ifdef EXTENDED_NEW_OPTION_INFO
63 int extended_option_environment = 0;
64 #endif
65@@ -101,6 +110,15 @@ int main (argc, argv, envp)
66 int no_dhclient_pid = 0;
67 int no_dhclient_script = 0;
68 char *s;
69+ char *dhcp_client_identifier_arg = NULL;
70+ char *dhcp_host_name_arg = NULL;
71+ char *dhcp_fqdn_arg = NULL;
72+ char *dhcp_vendor_class_identifier_arg = NULL;
73+ char *dhclient_request_options = NULL;
74+
75+ int timeout_arg = 0;
76+ char *arg_conf = NULL;
77+ int arg_conf_len = 0;
78
79 /* Make sure that file descriptors 0 (stdin), 1, (stdout), and
80 2 (stderr) are open. To do this, we assume that when we
81@@ -211,6 +229,88 @@ int main (argc, argv, envp)
82 } else if (!strcmp (argv [i], "--version")) {
83 log_info ("isc-dhclient-%s", DHCP_VERSION);
84 exit (0);
85+ } else if (!strcmp (argv [i], "-I")) {
86+ if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
87+ usage ();
88+ return EXIT_FAILURE;
89+ }
90+
91+ if (strlen(argv[i]) >= DHCP_OPTION_LEN) {
92+ log_error("-I option dhcp-client-identifier string \"%s\" is too long - maximum length is: %d", argv[i], DHCP_OPTION_LEN-1);
93+ exit(1);
94+ }
95+
96+ dhcp_client_identifier_arg = argv[i];
97+ } else if (!strcmp (argv [i], "-B")) {
98+ bootp_broadcast_always = 1;
99+ } else if (!strcmp (argv [i], "-H")) {
100+ if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
101+ usage ();
102+ return EXIT_FAILURE;
103+ }
104+
105+ if (strlen(argv[i]) >= DHCP_OPTION_LEN) {
106+ log_error("-H option host-name string \"%s\" is too long - maximum length is: %d", argv[i], DHCP_OPTION_LEN-1);
107+ exit(1);
108+ }
109+
110+ if (dhcp_host_name_arg != NULL) {
111+ log_error("The -H <host-name> and -F <fqdn> arguments are mutually exclusive");
112+ exit(1);
113+ }
114+
115+ dhcp_host_name_arg = argv[i];
116+ } else if (!strcmp (argv [i], "-F")) {
117+ if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
118+ usage ();
119+ return EXIT_FAILURE;
120+ }
121+
122+ if (strlen(argv[i]) >= DHCP_OPTION_LEN) {
123+ log_error("-F option fqdn.fqdn string \"%s\" is too long - maximum length is: %d", argv[i], DHCP_OPTION_LEN-1);
124+ exit(1);
125+ }
126+
127+ if (dhcp_fqdn_arg != NULL) {
128+ log_error("Only one -F <fqdn> argument can be specified");
129+ exit(1);
130+ }
131+
132+ if (dhcp_host_name_arg != NULL) {
133+ log_error("The -F <fqdn> and -H <host-name> arguments are mutually exclusive");
134+ exit(1);
135+ }
136+
137+ dhcp_fqdn_arg = argv[i];
138+ } else if (!strcmp (argv [i], "-T")) {
139+ if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
140+ usage ();
141+ return EXIT_FAILURE;
142+ }
143+
144+ if ((timeout_arg = atoi(argv[i])) <= 0) {
145+ log_error("-T timeout option must be > 0 - bad value: %s",argv[i]);
146+ exit(1);
147+ }
148+ } else if (!strcmp (argv [i], "-V")) {
149+ if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
150+ usage ();
151+ return EXIT_FAILURE;
152+ }
153+
154+ if (strlen(argv[i]) >= DHCP_OPTION_LEN) {
155+ log_error("-V option vendor-class-identifier string \"%s\" is too long - maximum length is: %d", argv[i], DHCP_OPTION_LEN-1);
156+ exit(1);
157+ }
158+
159+ dhcp_vendor_class_identifier_arg = argv[i];
160+ } else if (!strcmp (argv [i], "-R")) {
161+ if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
162+ usage ();
163+ return EXIT_FAILURE;
164+ }
165+
166+ dhclient_request_options=argv[i];
167 #ifdef EXTENDED_NEW_OPTION_INFO
168 } else if (!strcmp (argv [i], "-y")) {
169 extended_option_environment = 1;
170@@ -347,6 +447,167 @@ int main (argc, argv, envp)
171 /* Parse the dhclient.conf file. */
172 read_client_conf ();
173
174+ /* Parse any extra command line configuration arguments: */
175+ if ((dhcp_client_identifier_arg != NULL) && (*dhcp_client_identifier_arg != '\0')) {
176+ arg_conf_len = asprintf(&arg_conf, "send dhcp-client-identifier \"%s\";", dhcp_client_identifier_arg);
177+
178+ if ((arg_conf == 0) || (arg_conf_len <= 0))
179+ log_fatal("Unable to send -I option dhcp-client-identifier");
180+ }
181+
182+ if ((dhcp_host_name_arg != NULL) && (*dhcp_host_name_arg != '\0')) {
183+ if (arg_conf == 0) {
184+ arg_conf_len = asprintf(&arg_conf, "send host-name \"%s\";", dhcp_host_name_arg);
185+
186+ if ((arg_conf == 0) || (arg_conf_len <= 0))
187+ log_fatal("Unable to send -H option host-name");
188+ } else {
189+ char *last_arg_conf = arg_conf;
190+ arg_conf = NULL;
191+ arg_conf_len = asprintf( &arg_conf, "%s\nsend host-name \"%s\";", last_arg_conf, dhcp_host_name_arg);
192+
193+ if ((arg_conf == 0) || (arg_conf_len <= 0))
194+ log_fatal("Unable to send -H option host-name");
195+
196+ free(last_arg_conf);
197+ }
198+ }
199+
200+ if ((dhcp_fqdn_arg != NULL) && (*dhcp_fqdn_arg != '\0')) {
201+ if (arg_conf == 0) {
202+ arg_conf_len = asprintf(&arg_conf, "send fqdn.fqdn \"%s\";", dhcp_fqdn_arg);
203+
204+ if ((arg_conf == 0) || (arg_conf_len <= 0))
205+ log_fatal("Unable to send -F option fqdn.fqdn");
206+ } else {
207+ char *last_arg_conf = arg_conf;
208+ arg_conf = NULL;
209+ arg_conf_len = asprintf( &arg_conf, "%s\nsend fqdn.fqdn \"%s\";", last_arg_conf, dhcp_fqdn_arg);
210+
211+ if ((arg_conf == 0) || (arg_conf_len <= 0))
212+ log_fatal("Unable to send -F option fqdn.fqdn");
213+
214+ free(last_arg_conf);
215+ }
216+ }
217+
218+ if (timeout_arg) {
219+ if (arg_conf == 0) {
220+ arg_conf_len = asprintf(&arg_conf, "timeout %d;", timeout_arg);
221+
222+ if ((arg_conf == 0) || (arg_conf_len <= 0))
223+ log_fatal("Unable to process -T timeout argument");
224+ } else {
225+ char *last_arg_conf = arg_conf;
226+ arg_conf = NULL;
227+ arg_conf_len = asprintf( &arg_conf, "%s\ntimeout %d;", last_arg_conf, timeout_arg);
228+
229+ if ((arg_conf == 0) || (arg_conf_len == 0))
230+ log_fatal("Unable to process -T timeout argument");
231+
232+ free(last_arg_conf);
233+ }
234+ }
235+
236+ if ((dhcp_vendor_class_identifier_arg != NULL) && (*dhcp_vendor_class_identifier_arg != '\0')) {
237+ if (arg_conf == 0) {
238+ arg_conf_len = asprintf(&arg_conf, "send vendor-class-identifier \"%s\";", dhcp_vendor_class_identifier_arg);
239+
240+ if ((arg_conf == 0) || (arg_conf_len <= 0))
241+ log_fatal("Unable to send -V option vendor-class-identifier");
242+ } else {
243+ char *last_arg_conf = arg_conf;
244+ arg_conf = NULL;
245+ arg_conf_len = asprintf(&arg_conf, "%s\nsend vendor-class-identifier \"%s\";", last_arg_conf, dhcp_vendor_class_identifier_arg);
246+
247+ if ((arg_conf == 0) || (arg_conf_len <= 0))
248+ log_fatal("Unable to send -V option vendor-class-identifier");
249+
250+ free(last_arg_conf);
251+ }
252+ }
253+
254+ if (dhclient_request_options != NULL) {
255+ if (arg_conf == 0) {
256+ arg_conf_len = asprintf(&arg_conf, "request %s;", dhclient_request_options);
257+
258+ if ((arg_conf == 0) || (arg_conf_len <= 0))
259+ log_fatal("Unable to parse -R <request options list> argument");
260+ } else {
261+ char *last_arg_conf = arg_conf;
262+ arg_conf = NULL;
263+ arg_conf_len = asprintf(&arg_conf, "%s\nrequest %s;", last_arg_conf, dhclient_request_options);
264+
265+ if ((arg_conf == 0) || (arg_conf_len <= 0))
266+ log_fatal("Unable to parse -R <request options list> argument");
267+
268+ free(last_arg_conf);
269+ }
270+ }
271+
272+ if (arg_conf) {
273+ if (arg_conf_len == 0)
274+ if ((arg_conf_len = strlen(arg_conf)) == 0)
275+ /* huh ? cannot happen ! */
276+ log_fatal("Unable to process -I/-H/-F/-T/-V/-R configuration arguments");
277+
278+ /* parse the extra dhclient.conf configuration arguments
279+ * into top level config: */
280+ struct parse *cfile = (struct parse *)0;
281+ const char *val = NULL;
282+ int token;
283+
284+ status = new_parse (&cfile, -1, arg_conf, arg_conf_len, "extra dhclient -I/-H/-F/-T/-V/-R configuration arguments", 0);
285+
286+ if ((status != ISC_R_SUCCESS) || (cfile -> warnings_occurred))
287+ log_fatal("Cannot parse -I/-H/-F/-T/-V/-R configuration arguments !");
288+ /* more detailed parse failures will be logged */
289+
290+ do {
291+ token = peek_token (&val, (unsigned *)0, cfile);
292+ if (token == END_OF_FILE)
293+ break;
294+
295+ parse_client_statement (cfile, (struct interface_info *)0, &top_level_config);
296+ } while (1);
297+
298+ if (cfile -> warnings_occurred)
299+ log_fatal ("Cannot parse -I/-H/-F/-T/-V/-R configuration arguments !");
300+ end_parse (&cfile);
301+
302+ if (timeout_arg) {
303+ /* we just set the toplevel timeout, but per-client
304+ * timeouts may still be at defaults. Also, it makes no
305+ * sense having the reboot_timeout or backoff_cutoff
306+ * greater than the timeout:
307+ */
308+ if ((top_level_config.backoff_cutoff == 15) && (top_level_config.backoff_cutoff > (timeout_arg / 2)))
309+ top_level_config.backoff_cutoff = (((unsigned long)(timeout_arg / 2)) == 0) ? timeout_arg : (unsigned long)(timeout_arg / 2);
310+
311+ for (ip = interfaces; ip; ip = ip -> next) {
312+ if (ip->client->config->timeout == 60)
313+ ip->client->config->timeout = timeout_arg;
314+
315+ if ((ip->client->config->reboot_timeout == 10) && (ip->client->config->reboot_timeout > ip->client->config->timeout))
316+ ip->client->config->reboot_timeout = ip->client->config->timeout;
317+
318+ if ((ip->client->config->backoff_cutoff == 15) && (ip->client->config->backoff_cutoff > top_level_config.backoff_cutoff))
319+ ip->client->config->backoff_cutoff = top_level_config.backoff_cutoff;
320+ }
321+ }
322+
323+ if ((dhclient_request_options != 0) && (top_level_config.requested_options != default_requested_options)) {
324+ for (ip = interfaces; ip; ip = ip -> next) {
325+ if (ip->client->config->requested_options == default_requested_options)
326+ ip->client->config->requested_options = top_level_config.requested_options;
327+ }
328+ }
329+
330+ free(arg_conf);
331+ arg_conf = NULL;
332+ arg_conf_len = 0;
333+ }
334+
335 /* Parse the lease database. */
336 read_client_leases ();
337
338@@ -1978,7 +2239,8 @@ void make_discover (client, lease)
339 client -> packet.xid = random ();
340 client -> packet.secs = 0; /* filled in by send_discover. */
341
342- if (can_receive_unicast_unconfigured (client -> interface))
343+ if ((!(bootp_broadcast_always || client->config->bootp_broadcast_always))
344+ && can_receive_unicast_unconfigured(client->interface))
345 client -> packet.flags = 0;
346 else
347 client -> packet.flags = htons (BOOTP_BROADCAST);
348@@ -2065,7 +2327,9 @@ void make_request (client, lease)
349 } else {
350 memset (&client -> packet.ciaddr, 0,
351 sizeof client -> packet.ciaddr);
352- if (can_receive_unicast_unconfigured (client -> interface))
353+ if ((!(bootp_broadcast_always ||
354+ client ->config->bootp_broadcast_always)) &&
355+ can_receive_unicast_unconfigured (client -> interface))
356 client -> packet.flags = 0;
357 else
358 client -> packet.flags = htons (BOOTP_BROADCAST);
359@@ -2125,7 +2389,8 @@ void make_decline (client, lease)
360 client -> packet.hops = 0;
361 client -> packet.xid = client -> xid;
362 client -> packet.secs = 0; /* Filled in by send_request. */
363- if (can_receive_unicast_unconfigured (client -> interface))
364+ if ((!(bootp_broadcast_always || client->config-> bootp_broadcast_always))
365+ && can_receive_unicast_unconfigured (client->interface))
366 client -> packet.flags = 0;
367 else
368 client -> packet.flags = htons (BOOTP_BROADCAST);
369diff -up dhcp-3.1.0/client/clparse.c.options dhcp-3.1.0/client/clparse.c
370--- dhcp-3.1.0/client/clparse.c.options 2007-02-14 17:41:22.000000000 -0500
371+++ dhcp-3.1.0/client/clparse.c 2007-10-22 15:47:12.000000000 -0400
372@@ -84,6 +84,7 @@ isc_result_t read_client_conf ()
373 top_level_config.requested_options = default_requested_options;
374 top_level_config.omapi_port = -1;
375 top_level_config.do_forward_update = 1;
376+ top_level_config.bootp_broadcast_always = 0;
377
378 group_allocate (&top_level_config.on_receipt, MDL);
379 if (!top_level_config.on_receipt)
380@@ -230,7 +231,8 @@ void read_client_leases ()
381 interface-declaration |
382 LEASE client-lease-statement |
383 ALIAS client-lease-statement |
384- KEY key-definition */
385+ KEY key-definition |
386+ BOOTP_BROADCAST_ALWAYS */
387
388 void parse_client_statement (cfile, ip, config)
389 struct parse *cfile;
390@@ -554,6 +556,12 @@ void parse_client_statement (cfile, ip,
391 parse_reject_statement (cfile, config);
392 return;
393
394+ case BOOTP_BROADCAST_ALWAYS:
395+ token = next_token(&val, (unsigned*)0, cfile);
396+ config -> bootp_broadcast_always = 1;
397+ parse_semi (cfile);
398+ return;
399+
400 default:
401 lose = 0;
402 stmt = (struct executable_statement *)0;
This page took 0.091057 seconds and 4 git commands to generate.