]> git.pld-linux.org Git - packages/dhcp.git/blob - dhcp-options.patch
- x32 rebuild
[packages/dhcp.git] / dhcp-options.patch
1 diff -up dhcp-4.2.1b1/client/dhclient.8.man dhcp-4.2.1b1/client/dhclient.8
2 --- dhcp-4.2.1b1/client/dhclient.8.man  2010-07-14 22:09:34.000000000 +0200
3 +++ dhcp-4.2.1b1/client/dhclient.8      2011-01-27 18:19:07.000000000 +0100
4 @@ -115,6 +115,33 @@ dhclient - Dynamic Host Configuration Pr
5  .B -w
6  ]
7  [
8 +.B -B
9 +]
10 +[
11 +.B -I
12 +.I dhcp-client-identifier
13 +]
14 +[
15 +.B -H
16 +.I host-name
17 +]
18 +[
19 +.B -F
20 +.I fqdn.fqdn
21 +]
22 +[
23 +.B -V
24 +.I vendor-class-identifier
25 +]
26 +[
27 +.B -R
28 +.I request-option-list
29 +]
30 +[
31 +.B -timeout
32 +.I timeout
33 +]
34 +[
35  .B -v
36  ]
37  [
38 @@ -264,6 +291,69 @@ not to exit when it doesn't find any suc
39  program can then be used to notify the client when a network interface
40  has been added or removed, so that the client can attempt to configure an IP
41  address on that interface.
42 +
43 +.TP
44 +.BI \-B
45 +Set the BOOTP broadcast flag in request packets so servers will always
46 +broadcast replies.
47 +
48 +.TP
49 +.BI \-I\ <dhcp-client-identifier>
50 +Specify the dhcp-client-identifier option to send to the DHCP server.
51 +
52 +.TP
53 +.BI \-H\ <host-name>
54 +Specify the host-name option to send to the DHCP server.  The host-name
55 +string only contains the client's hostname prefix, to which the server will
56 +append the ddns-domainname or domain-name options, if any, to derive the
57 +fully qualified domain name of the client.  The
58 +.B -H
59 +option cannot be used with the
60 +.B -F
61 +option.
62 +
63 +.TP
64 +.BI \-F\ <fqdn.fqdn>
65 +Specify the fqdn.fqdn option to send to the DHCP server.  This option cannot
66 +be used with the
67 +.B -H
68 +option.  The fqdn.fqdn option must specify the complete domain name of the
69 +client host, which the server may use for dynamic DNS updates.
70 +
71 +.TP
72 +.BI \-V\ <vendor-class-identifier>
73 +Specify the vendor-class-identifier option to send to the DHCP server.
74 +
75 +.TP
76 +.BI \-R\ <option>[,<option>...]
77 +Specify the list of options the client is to request from the server.  The
78 +option list must be a single string consisting of option names separated
79 +by at least one command and optional space characters.  The default option
80 +list is:
81 +
82 +.BR
83 +    subnet-mask, broadcast-address, time-offset, routers,
84 +.BR
85 +    domain-search, domain-name, domain-name-servers, host-name, 
86 +.BR
87 +    nis-domain, nis-servers, ntp-servers, interface-mtu
88 +
89 +.TP
90 +.B -R
91 +option does not append options to the default request, it overrides the
92 +default request list.  Keep this in mind if you want to request an
93 +additional option besides the default request list.  You will have to
94 +specify all option names for the
95 +.B -R
96 +parameter.
97 +
98 +.TP
99 +.BI \-timeout\ <timeout>
100 +Specify the time after which
101 +.B dhclient
102 +will decide that no DHCP servers can be contacted when no responses have been
103 +received.
104 +
105  .TP
106  .BI \-n
107  Do not configure any interfaces.  This is most likely to be useful in
108 diff -up dhcp-4.2.4-P2/client/clparse.c.options dhcp-4.2.4-P2/client/clparse.c
109 --- dhcp-4.2.4-P2/client/clparse.c.options      2012-08-24 21:11:21.000000000 +0200
110 +++ dhcp-4.2.4-P2/client/clparse.c      2012-09-26 10:34:27.140049896 +0200
111 @@ -154,6 +154,7 @@ isc_result_t read_client_conf ()
112         /* Requested lease time, used by DHCPv6 (DHCPv4 uses the option cache)
113          */
114         top_level_config.requested_lease = 7200;
115 +       top_level_config.bootp_broadcast_always = 0;
116  
117         group_allocate (&top_level_config.on_receipt, MDL);
118         if (!top_level_config.on_receipt)
119 @@ -320,7 +321,8 @@ void read_client_leases ()
120         interface-declaration |
121         LEASE client-lease-statement |
122         ALIAS client-lease-statement |
123 -       KEY key-definition */
124 +       KEY key-definition |
125 +       BOOTP_BROADCAST_ALWAYS */
126  
127  void parse_client_statement (cfile, ip, config)
128         struct parse *cfile;
129 @@ -739,6 +741,12 @@ void parse_client_statement (cfile, ip,
130                 parse_reject_statement (cfile, config);
131                 return;
132  
133 +             case BOOTP_BROADCAST_ALWAYS:
134 +               token = next_token(&val, (unsigned*)0, cfile);
135 +               config -> bootp_broadcast_always = 1;
136 +               parse_semi (cfile);
137 +               return;
138 +
139               default:
140                 lose = 0;
141                 stmt = (struct executable_statement *)0;
142 diff -up dhcp-4.2.4-P2/client/dhclient.c.options dhcp-4.2.4-P2/client/dhclient.c
143 --- dhcp-4.2.4-P2/client/dhclient.c.options     2012-08-28 04:13:03.000000000 +0200
144 +++ dhcp-4.2.4-P2/client/dhclient.c     2012-09-26 10:36:10.396967531 +0200
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  
158 @@ -87,6 +93,9 @@ int wanted_ia_na = -1;                /* the absolute
159  int wanted_ia_ta = 0;
160  int wanted_ia_pd = 0;
161  char *mockup_relay = NULL;
162 +int bootp_broadcast_always = 0;
163 +
164 +extern u_int32_t default_requested_options[];
165  
166  void run_stateless(int exit_mode);
167  
168 @@ -123,6 +132,15 @@ main(int argc, char **argv) {
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));
184 @@ -310,6 +328,88 @@ main(int argc, char **argv) {
185                 } else if (!strcmp(argv[i], "--version")) {
186                         log_info("isc-dhclient-%s", PACKAGE_VERSION);
187                         exit(0);
188 +               } else if (!strcmp(argv[i], "-I")) {
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) {
195 +                               log_error("-I option dhcp-client-identifier string \"%s\" is too long - maximum length is: %d", argv[i], DHCP_MAX_OPTION_LEN-1);
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) {
248 +                               log_error("timeout option must be > 0 - bad value: %s",argv[i]);
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) {
273 @@ -484,6 +584,156 @@ main(int argc, char **argv) {
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))
282 +                       log_fatal("Unable to send -I option dhcp-client-identifier");
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 ! */
379 +                               log_fatal("Unable to process -I/-H/-F/-timeout/-V/-R configuration arguments");
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 +
387 +               status = new_parse(&cfile, -1, arg_conf, arg_conf_len, "extra dhclient -I/-H/-F/-timeout/-V/-R configuration arguments", 0);
388 +
389 +               if ((status != ISC_R_SUCCESS) || (cfile -> warnings_occurred))
390 +                       log_fatal("Cannot parse -I/-H/-F/-timeout/-V/-R configuration arguments !");
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)
402 +                       log_fatal("Cannot parse -I/-H/-F/-timeout/-V/-R configuration arguments !");
403 +               end_parse(&cfile);
404 +
405 +               if (timeout_arg) {
406 +                       /* we just set the toplevel timeout, but per-client
407 +                        * timeouts may still be at defaults.
408 +                        */
409 +                       for (ip=interfaces; ip; ip = ip->next) {
410 +                               if (ip->client->config->timeout == 60)
411 +                                       ip->client->config->timeout = timeout_arg;
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  
430 @@ -715,6 +965,10 @@ static void usage()
431                   "                [-s server-addr] [-cf config-file] "
432                   "[-lf lease-file]\n"
433                   "                [-pf pid-file] [--no-pid] [-e VAR=val]\n"
434 +                 "                [-I <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 @@ -2421,7 +2675,8 @@ void make_discover (client, lease)
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);
451 @@ -2505,7 +2760,9 @@ void make_request (client, lease)
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);
462 @@ -2567,7 +2824,8 @@ void make_decline (client, lease)
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);
472 diff -up dhcp-4.2.4-P2/common/conflex.c.options dhcp-4.2.4-P2/common/conflex.c
473 --- dhcp-4.2.4-P2/common/conflex.c.options      2012-08-28 04:13:03.000000000 +0200
474 +++ dhcp-4.2.4-P2/common/conflex.c      2012-09-26 10:34:27.142049876 +0200
475 @@ -808,6 +808,8 @@ intern(char *atom, enum dhcp_token dfv)
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"))
484 diff -up dhcp-4.2.4-P2/includes/dhcpd.h.options dhcp-4.2.4-P2/includes/dhcpd.h
485 --- dhcp-4.2.4-P2/includes/dhcpd.h.options      2012-08-28 04:13:22.000000000 +0200
486 +++ dhcp-4.2.4-P2/includes/dhcpd.h      2012-09-26 10:34:27.143049865 +0200
487 @@ -1153,6 +1153,9 @@ struct client_config {
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... */
497 diff -up dhcp-4.2.4-P2/includes/dhctoken.h.options dhcp-4.2.4-P2/includes/dhctoken.h
498 --- dhcp-4.2.4-P2/includes/dhctoken.h.options   2012-08-28 04:13:03.000000000 +0200
499 +++ dhcp-4.2.4-P2/includes/dhctoken.h   2012-09-26 10:34:27.144049854 +0200
500 @@ -364,7 +364,8 @@ enum dhcp_token {
501         GETHOSTBYNAME = 665,
502         PRIMARY6 = 666,
503         SECONDARY6 = 667,
504 -       TOKEN_INFINIBAND = 668
505 +       TOKEN_INFINIBAND = 668,
506 +       BOOTP_BROADCAST_ALWAYS = 669
507  };
508  
509  #define is_identifier(x)       ((x) >= FIRST_TOKEN &&  \
This page took 0.060489 seconds and 3 git commands to generate.