]>
Commit | Line | Data |
---|---|---|
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) | |
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) | |
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 */ | |
19 | ||
20 | void parse_client_statement (cfile, ip, config) | |
21 | struct parse *cfile; | |
22 | @@ -732,6 +734,12 @@ void parse_client_statement (cfile, ip, | |
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; | |
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 | |
38 | @@ -39,6 +39,12 @@ | |
39 | #include <limits.h> | |
40 | #include <dns/result.h> | |
41 | ||
42 | +/* | |
43 | + * Defined in stdio.h when _GNU_SOURCE is set, but we don't want to define | |
44 | + * that when building ISC code. | |
45 | + */ | |
46 | +extern int asprintf(char **strp, const char *fmt, ...); | |
47 | + | |
48 | TIME default_lease_time = 43200; /* 12 hours... */ | |
49 | TIME max_lease_time = 86400; /* 24 hours... */ | |
50 | ||
51 | @@ -87,6 +93,9 @@ int wanted_ia_na = -1; /* the absolute | |
52 | int wanted_ia_ta = 0; | |
53 | int wanted_ia_pd = 0; | |
54 | char *mockup_relay = NULL; | |
55 | +int bootp_broadcast_always = 0; | |
56 | + | |
57 | +extern u_int32_t default_requested_options[]; | |
58 | ||
59 | void run_stateless(int exit_mode); | |
60 | ||
61 | @@ -123,6 +132,15 @@ main(int argc, char **argv) { | |
62 | int local_family_set = 0; | |
63 | #endif /* DHCPv6 */ | |
64 | char *s; | |
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; | |
70 | + | |
71 | + int timeout_arg = 0; | |
72 | + char *arg_conf = NULL; | |
73 | + int arg_conf_len = 0; | |
74 | ||
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); | |
80 | exit(0); | |
81 | + } else if (!strcmp(argv[i], "-I")) { | |
82 | + if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) { | |
83 | + usage(); | |
84 | + exit(1); | |
85 | + } | |
86 | + | |
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); | |
89 | + exit(1); | |
90 | + } | |
91 | + | |
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')) { | |
97 | + usage(); | |
98 | + exit(1); | |
99 | + } | |
100 | + | |
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); | |
103 | + exit(1); | |
104 | + } | |
105 | + | |
106 | + if (dhcp_host_name_arg != NULL) { | |
107 | + log_error("The -H <host-name> and -F <fqdn> arguments are mutually exclusive"); | |
108 | + exit(1); | |
109 | + } | |
110 | + | |
111 | + dhcp_host_name_arg = argv[i]; | |
112 | + } else if (!strcmp(argv[i], "-F")) { | |
113 | + if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) { | |
114 | + usage(); | |
115 | + exit(1); | |
116 | + } | |
117 | + | |
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); | |
120 | + exit(1); | |
121 | + } | |
122 | + | |
123 | + if (dhcp_fqdn_arg != NULL) { | |
124 | + log_error("Only one -F <fqdn> argument can be specified"); | |
125 | + exit(1); | |
126 | + } | |
127 | + | |
128 | + if (dhcp_host_name_arg != NULL) { | |
129 | + log_error("The -F <fqdn> and -H <host-name> arguments are mutually exclusive"); | |
130 | + exit(1); | |
131 | + } | |
132 | + | |
133 | + dhcp_fqdn_arg = argv[i]; | |
134 | + } else if (!strcmp(argv[i], "-timeout")) { | |
135 | + if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) { | |
136 | + usage(); | |
137 | + exit(1); | |
138 | + } | |
139 | + | |
140 | + if ((timeout_arg = atoi(argv[i])) <= 0) { | |
141 | + log_error("-T timeout option must be > 0 - bad value: %s",argv[i]); | |
142 | + exit(1); | |
143 | + } | |
144 | + } else if (!strcmp(argv[i], "-V")) { | |
145 | + if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) { | |
146 | + usage(); | |
147 | + exit(1); | |
148 | + } | |
149 | + | |
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); | |
152 | + exit(1); | |
153 | + } | |
154 | + | |
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')) { | |
158 | + usage(); | |
159 | + exit(1); | |
160 | + } | |
161 | + | |
162 | + dhclient_request_options = argv[i]; | |
163 | } else if (argv[i][0] == '-') { | |
164 | usage(); | |
165 | } else if (interfaces_requested < 0) { | |
166 | @@ -484,6 +584,166 @@ main(int argc, char **argv) { | |
167 | /* Parse the dhclient.conf file. */ | |
168 | read_client_conf(); | |
169 | ||
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); | |
173 | + | |
174 | + if ((arg_conf == 0) || (arg_conf_len <= 0)) | |
175 | + log_fatal("Unable to send -I option dhcp-client-identifier"); | |
176 | + } | |
177 | + | |
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); | |
181 | + | |
182 | + if ((arg_conf == 0) || (arg_conf_len <= 0)) | |
183 | + log_fatal("Unable to send -H option host-name"); | |
184 | + } else { | |
185 | + char *last_arg_conf = arg_conf; | |
186 | + arg_conf = NULL; | |
187 | + arg_conf_len = asprintf(&arg_conf, "%s\nsend host-name \"%s\";", last_arg_conf, dhcp_host_name_arg); | |
188 | + | |
189 | + if ((arg_conf == 0) || (arg_conf_len <= 0)) | |
190 | + log_fatal("Unable to send -H option host-name"); | |
191 | + | |
192 | + free(last_arg_conf); | |
193 | + } | |
194 | + } | |
195 | + | |
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); | |
199 | + | |
200 | + if ((arg_conf == 0) || (arg_conf_len <= 0)) | |
201 | + log_fatal("Unable to send -F option fqdn.fqdn"); | |
202 | + } else { | |
203 | + char *last_arg_conf = arg_conf; | |
204 | + arg_conf = NULL; | |
205 | + arg_conf_len = asprintf(&arg_conf, "%s\nsend fqdn.fqdn \"%s\";", last_arg_conf, dhcp_fqdn_arg); | |
206 | + | |
207 | + if ((arg_conf == 0) || (arg_conf_len <= 0)) | |
208 | + log_fatal("Unable to send -F option fqdn.fqdn"); | |
209 | + | |
210 | + free(last_arg_conf); | |
211 | + } | |
212 | + } | |
213 | + | |
214 | + if (timeout_arg) { | |
215 | + if (arg_conf == 0) { | |
216 | + arg_conf_len = asprintf(&arg_conf, "timeout %d;", timeout_arg); | |
217 | + | |
218 | + if ((arg_conf == 0) || (arg_conf_len <= 0)) | |
219 | + log_fatal("Unable to process -timeout timeout argument"); | |
220 | + } else { | |
221 | + char *last_arg_conf = arg_conf; | |
222 | + arg_conf = NULL; | |
223 | + arg_conf_len = asprintf(&arg_conf, "%s\ntimeout %d;", last_arg_conf, timeout_arg); | |
224 | + | |
225 | + if ((arg_conf == 0) || (arg_conf_len == 0)) | |
226 | + log_fatal("Unable to process -timeout timeout argument"); | |
227 | + | |
228 | + free(last_arg_conf); | |
229 | + } | |
230 | + } | |
231 | + | |
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); | |
235 | + | |
236 | + if ((arg_conf == 0) || (arg_conf_len <= 0)) | |
237 | + log_fatal("Unable to send -V option vendor-class-identifier"); | |
238 | + } else { | |
239 | + char *last_arg_conf = arg_conf; | |
240 | + arg_conf = NULL; | |
241 | + arg_conf_len = asprintf(&arg_conf, "%s\nsend vendor-class-identifier \"%s\";", last_arg_conf, dhcp_vendor_class_identifier_arg); | |
242 | + | |
243 | + if ((arg_conf == 0) || (arg_conf_len <= 0)) | |
244 | + log_fatal("Unable to send -V option vendor-class-identifier"); | |
245 | + | |
246 | + free(last_arg_conf); | |
247 | + } | |
248 | + } | |
249 | + | |
250 | + if (dhclient_request_options != NULL) { | |
251 | + if (arg_conf == 0) { | |
252 | + arg_conf_len = asprintf(&arg_conf, "request %s;", dhclient_request_options); | |
253 | + | |
254 | + if ((arg_conf == 0) || (arg_conf_len <= 0)) | |
255 | + log_fatal("Unable to parse -R <request options list> argument"); | |
256 | + } else { | |
257 | + char *last_arg_conf = arg_conf; | |
258 | + arg_conf = NULL; | |
259 | + arg_conf_len = asprintf(&arg_conf, "%s\nrequest %s;", last_arg_conf, dhclient_request_options); | |
260 | + | |
261 | + if ((arg_conf == 0) || (arg_conf_len <= 0)) | |
262 | + log_fatal("Unable to parse -R <request options list> argument"); | |
263 | + | |
264 | + free(last_arg_conf); | |
265 | + } | |
266 | + } | |
267 | + | |
268 | + if (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"); | |
273 | + | |
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; | |
278 | + int token; | |
279 | + | |
280 | + status = new_parse(&cfile, -1, arg_conf, arg_conf_len, "extra dhclient -I/-H/-F/-timeout/-V/-R configuration arguments", 0); | |
281 | + | |
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 */ | |
285 | + | |
286 | + do { | |
287 | + token = peek_token(&val, (unsigned *)0, cfile); | |
288 | + if (token == END_OF_FILE) | |
289 | + break; | |
290 | + | |
291 | + parse_client_statement(cfile, (struct interface_info *)0, &top_level_config); | |
292 | + } while (1); | |
293 | + | |
294 | + if (cfile -> warnings_occurred) | |
295 | + log_fatal("Cannot parse -I/-H/-F/-timeout/-V/-R configuration arguments !"); | |
296 | + end_parse(&cfile); | |
297 | + | |
298 | + if (timeout_arg) { | |
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: | |
303 | + */ | |
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); | |
306 | + | |
307 | + for (ip=interfaces; ip; ip = ip->next) { | |
308 | + if (ip->client->config->timeout == 60) | |
309 | + ip->client->config->timeout = timeout_arg; | |
310 | + | |
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; | |
315 | + } | |
316 | + } | |
317 | + | |
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; | |
322 | + } | |
323 | + } | |
324 | + | |
325 | + free(arg_conf); | |
326 | + arg_conf = NULL; | |
327 | + arg_conf_len = 0; | |
328 | + } | |
329 | + | |
330 | /* Parse the lease database. */ | |
331 | read_client_leases(); | |
332 | ||
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. */ | |
336 | ||
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; | |
341 | else | |
342 | client -> packet.flags = htons (BOOTP_BROADCAST); | |
343 | @@ -2481,7 +2742,9 @@ void make_request (client, lease) | |
344 | } else { | |
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; | |
352 | else | |
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; | |
362 | else | |
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) | |
368 | return BALANCE; | |
369 | if (!strcasecmp (atom + 1, "ound")) | |
370 | return BOUND; | |
371 | + if (!strcasecmp (atom + 1, "ootp-broadcast-always")) | |
372 | + return BOOTP_BROADCAST_ALWAYS; | |
373 | break; | |
374 | case 'c': | |
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. */ | |
383 | + | |
384 | + int bootp_broadcast_always; /* If nonzero, always set the BOOTP_BROADCAST | |
385 | + flag in requests */ | |
386 | }; | |
387 | ||
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 { | |
393 | GETHOSTNAME = 662, | |
394 | REWIND = 663, | |
395 | INITIAL_DELAY = 664, | |
396 | - GETHOSTBYNAME = 665 | |
397 | + GETHOSTBYNAME = 665, | |
398 | + BOOTP_BROADCAST_ALWAYS = 666 | |
399 | }; | |
400 | ||
401 | #define is_identifier(x) ((x) >= FIRST_TOKEN && \ |