]> git.pld-linux.org Git - packages/dhcp.git/blob - dhcp-options.patch
- up to 4.3.5
[packages/dhcp.git] / dhcp-options.patch
1 diff -up dhcp-4.3.4/client/clparse.c.options dhcp-4.3.4/client/clparse.c
2 --- dhcp-4.3.4/client/clparse.c.options 2016-03-22 14:16:51.000000000 +0100
3 +++ dhcp-4.3.4/client/clparse.c 2016-04-29 12:06:13.485470579 +0200
4 @@ -189,6 +189,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 @@ -394,7 +395,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 @@ -817,6 +819,12 @@ void parse_client_statement (cfile, ip,
23                 parse_lease_id_format(cfile);
24                 break;
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  
33               default:
34                 lose = 0;
35 diff -up dhcp-4.3.4/client/dhclient.8.options dhcp-4.3.4/client/dhclient.8
36 --- dhcp-4.3.4/client/dhclient.8.options        2016-03-22 14:16:51.000000000 +0100
37 +++ dhcp-4.3.4/client/dhclient.8        2016-04-29 11:59:50.446590077 +0200
38 @@ -134,6 +134,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 --request-options
62 +.I request-option-list
63 +]
64 +[
65 +.B --timeout
66 +.I timeout
67 +]
68 +[
69  .B -v
70  ]
71  [
72 @@ -289,6 +316,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 \--request-options\ <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 --request-options
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 --request-options
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
142 diff -up dhcp-4.3.4/client/dhclient.c.options dhcp-4.3.4/client/dhclient.c
143 --- dhcp-4.3.4/client/dhclient.c.options        2016-03-22 14:16:51.000000000 +0100
144 +++ dhcp-4.3.4/client/dhclient.c        2016-04-29 12:12:14.182364093 +0200
145 @@ -40,6 +40,12 @@
146  #include <isc/file.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 @@ -100,6 +106,10 @@ char *mockup_relay = NULL;
159  
160  char *progname = NULL;
161  
162 +int bootp_broadcast_always = 0;
163 +
164 +extern struct option *default_requested_options[];
165 +
166  void run_stateless(int exit_mode, u_int16_t port);
167  
168  static isc_result_t write_duid(struct data_string *duid);
169 @@ -177,7 +187,11 @@ usage(const char *sfmt, const char *sarg
170                   "                [-s server-addr] [-cf config-file]\n"
171                   "                [-df duid-file] [-lf lease-file]\n"
172                   "                [-pf pid-file] [--no-pid] [-e VAR=val]\n"
173 -                 "                [-sf script-file] [interface]*",
174 +                 "                [-sf script-file] [interface]*\n"
175 +                 "                [-C <dhcp-client-identifier>] [-B]\n"
176 +                 "                [-H <host-name> | -F <fqdn.fqdn>] [--timeout <timeout>]\n"
177 +                 "                [-V <vendor-class-identifier>]\n"
178 +                 "                [--request-options <request option list>]",
179                   isc_file_basename(progname));
180  }
181  
182 @@ -214,6 +228,16 @@ main(int argc, char **argv) {
183         progname = argv[0];
184  #endif
185  
186 +       char *dhcp_client_identifier_arg = NULL;
187 +       char *dhcp_host_name_arg = NULL;
188 +       char *dhcp_fqdn_arg = NULL;
189 +       char *dhcp_vendor_class_identifier_arg = NULL;
190 +       char *dhclient_request_options = NULL;
191 +
192 +       int timeout_arg = 0;
193 +       char *arg_conf = NULL;
194 +       int arg_conf_len = 0;
195 +
196         /* Initialize client globals. */
197         memset(&default_duid, 0, sizeof(default_duid));
198  
199 @@ -431,6 +455,88 @@ main(int argc, char **argv) {
200                                          strlen(PACKAGE_VERSION)));
201                         IGNORE_RET(write(STDERR_FILENO, "\n", 1));
202                         exit(0);
203 +               } else if (!strcmp(argv[i], "-C")) {
204 +                       if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
205 +                               usage(use_noarg, argv[i-1]);
206 +                               exit(1);
207 +                       }
208 +
209 +                       if (strlen(argv[i]) >= DHCP_MAX_OPTION_LEN) {
210 +                               log_error("-C option dhcp-client-identifier string \"%s\" is too long - maximum length is: %d", argv[i], DHCP_MAX_OPTION_LEN-1);
211 +                               exit(1);
212 +                       }
213 +
214 +                       dhcp_client_identifier_arg = argv[i];
215 +               } else if (!strcmp(argv[i], "-B")) {
216 +                       bootp_broadcast_always = 1;
217 +               } else if (!strcmp(argv[i], "-H")) {
218 +                       if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
219 +                               usage(use_noarg, argv[i-1]);
220 +                               exit(1);
221 +                       }
222 +
223 +                       if (strlen(argv[i]) >= DHCP_MAX_OPTION_LEN) {
224 +                               log_error("-H option host-name string \"%s\" is too long - maximum length is: %d", argv[i], DHCP_MAX_OPTION_LEN-1);
225 +                               exit(1);
226 +                       }
227 +
228 +                       if (dhcp_host_name_arg != NULL) {
229 +                               log_error("The -H <host-name> and -F <fqdn> arguments are mutually exclusive");
230 +                               exit(1);
231 +                       }
232 +
233 +                       dhcp_host_name_arg = argv[i];
234 +               } else if (!strcmp(argv[i], "-F")) {
235 +                       if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
236 +                               usage(use_noarg, argv[i-1]);
237 +                               exit(1);
238 +                       }
239 +
240 +                       if (strlen(argv[i]) >= DHCP_MAX_OPTION_LEN) {
241 +                               log_error("-F option fqdn.fqdn string \"%s\" is too long - maximum length is: %d", argv[i], DHCP_MAX_OPTION_LEN-1);
242 +                               exit(1);
243 +                       }
244 +
245 +                       if (dhcp_fqdn_arg != NULL) {
246 +                               log_error("Only one -F <fqdn> argument can be specified");
247 +                               exit(1);
248 +                       }
249 +
250 +                       if (dhcp_host_name_arg != NULL) {
251 +                               log_error("The -F <fqdn> and -H <host-name> arguments are mutually exclusive");
252 +                               exit(1);
253 +                       }
254 +
255 +                       dhcp_fqdn_arg = argv[i];
256 +               } else if (!strcmp(argv[i], "--timeout")) {
257 +                       if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
258 +                               usage(use_noarg, argv[i-1]);
259 +                               exit(1);
260 +                       }
261 +
262 +                       if ((timeout_arg = atoi(argv[i])) <= 0) {
263 +                               log_error("timeout option must be > 0 - bad value: %s",argv[i]);
264 +                               exit(1);
265 +                       }
266 +               } else if (!strcmp(argv[i], "-V")) {
267 +                       if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
268 +                               usage(use_noarg, argv[i-1]);
269 +                               exit(1);
270 +                       }
271 +
272 +                       if (strlen(argv[i]) >= DHCP_MAX_OPTION_LEN) {
273 +                               log_error("-V option vendor-class-identifier string \"%s\" is too long - maximum length is: %d", argv[i], DHCP_MAX_OPTION_LEN-1);
274 +                               exit(1);
275 +                       }
276 +
277 +                       dhcp_vendor_class_identifier_arg = argv[i];
278 +               } else if (!strcmp(argv[i], "--request-options")) {
279 +                       if ((++i == argc) || (argv[i] == NULL) || (*(argv[i])=='\0')) {
280 +                               usage(use_noarg, argv[i-1]);
281 +                               exit(1);
282 +                       }
283 +
284 +                       dhclient_request_options = argv[i];
285                 } else if (argv[i][0] == '-') {
286                         usage("Unknown command: %s", argv[i]);
287                 } else if (interfaces_requested < 0) {
288 @@ -630,6 +736,156 @@ main(int argc, char **argv) {
289         /* Parse the dhclient.conf file. */
290         read_client_conf();
291  
292 +       /* Parse any extra command line configuration arguments: */
293 +       if ((dhcp_client_identifier_arg != NULL) && (*dhcp_client_identifier_arg != '\0')) {
294 +               arg_conf_len = asprintf(&arg_conf, "send dhcp-client-identifier \"%s\";", dhcp_client_identifier_arg);
295 +
296 +               if ((arg_conf == 0) || (arg_conf_len <= 0))
297 +                       log_fatal("Unable to send -C option dhcp-client-identifier");
298 +       }
299 +
300 +       if ((dhcp_host_name_arg != NULL) && (*dhcp_host_name_arg != '\0')) {
301 +               if (arg_conf == 0) {
302 +                       arg_conf_len = asprintf(&arg_conf, "send host-name \"%s\";", dhcp_host_name_arg);
303 +
304 +                       if ((arg_conf == 0) || (arg_conf_len <= 0))
305 +                               log_fatal("Unable to send -H option host-name");
306 +               } else {
307 +                       char *last_arg_conf = arg_conf;
308 +                       arg_conf = NULL;
309 +                       arg_conf_len = asprintf(&arg_conf, "%s\nsend host-name \"%s\";", last_arg_conf, dhcp_host_name_arg);
310 +
311 +                       if ((arg_conf == 0) || (arg_conf_len <= 0))
312 +                               log_fatal("Unable to send -H option host-name");
313 +
314 +                       free(last_arg_conf);
315 +               }
316 +       }
317 +
318 +       if ((dhcp_fqdn_arg != NULL) && (*dhcp_fqdn_arg != '\0')) {
319 +               if (arg_conf == 0) {
320 +                       arg_conf_len = asprintf(&arg_conf,  "send fqdn.fqdn \"%s\";", dhcp_fqdn_arg);
321 +
322 +                       if ((arg_conf == 0) || (arg_conf_len <= 0))
323 +                               log_fatal("Unable to send -F option fqdn.fqdn");
324 +               } else {
325 +                       char *last_arg_conf = arg_conf;
326 +                       arg_conf = NULL;
327 +                       arg_conf_len = asprintf(&arg_conf, "%s\nsend fqdn.fqdn \"%s\";", last_arg_conf, dhcp_fqdn_arg);
328 +
329 +                       if ((arg_conf == 0)  || (arg_conf_len <= 0))
330 +                               log_fatal("Unable to send -F option fqdn.fqdn");
331 +
332 +                       free(last_arg_conf);
333 +               }
334 +       }
335 +
336 +       if (timeout_arg) {
337 +               if (arg_conf == 0) {
338 +                       arg_conf_len = asprintf(&arg_conf,  "timeout %d;", timeout_arg);
339 +
340 +                       if ((arg_conf == 0) || (arg_conf_len <= 0))
341 +                               log_fatal("Unable to process --timeout timeout argument");
342 +               } else {
343 +                       char *last_arg_conf = arg_conf;
344 +                       arg_conf = NULL;
345 +                       arg_conf_len = asprintf(&arg_conf, "%s\ntimeout %d;", last_arg_conf, timeout_arg);
346 +
347 +                       if ((arg_conf == 0) || (arg_conf_len == 0))
348 +                               log_fatal("Unable to process --timeout timeout argument");
349 +
350 +                       free(last_arg_conf);
351 +               }
352 +       }
353 +
354 +       if ((dhcp_vendor_class_identifier_arg != NULL) && (*dhcp_vendor_class_identifier_arg != '\0')) {
355 +               if (arg_conf == 0) {
356 +                       arg_conf_len = asprintf(&arg_conf,  "send vendor-class-identifier \"%s\";", dhcp_vendor_class_identifier_arg);
357 +
358 +                       if ((arg_conf == 0) || (arg_conf_len <= 0))
359 +                               log_fatal("Unable to send -V option vendor-class-identifier");
360 +               } else {
361 +                       char *last_arg_conf = arg_conf;
362 +                       arg_conf = NULL;
363 +                       arg_conf_len = asprintf(&arg_conf, "%s\nsend vendor-class-identifier \"%s\";", last_arg_conf, dhcp_vendor_class_identifier_arg);
364 +
365 +                       if ((arg_conf == 0) || (arg_conf_len <= 0))
366 +                               log_fatal("Unable to send -V option vendor-class-identifier");
367 +
368 +                       free(last_arg_conf);
369 +               }
370 +       }
371 +
372 +       if (dhclient_request_options != NULL) {
373 +               if (arg_conf == 0) {
374 +                       arg_conf_len = asprintf(&arg_conf,  "request %s;", dhclient_request_options);
375 +
376 +                       if ((arg_conf == 0) || (arg_conf_len <= 0))
377 +                               log_fatal("Unable to parse --request-options <request options list> argument");
378 +               } else {
379 +                       char *last_arg_conf = arg_conf;
380 +                       arg_conf = NULL;
381 +                       arg_conf_len = asprintf(&arg_conf, "%s\nrequest %s;", last_arg_conf, dhclient_request_options);
382 +
383 +                       if ((arg_conf == 0)  || (arg_conf_len <= 0))
384 +                               log_fatal("Unable to parse --request-options <request options list> argument");
385 +
386 +                       free(last_arg_conf);
387 +               }
388 +       }
389 +
390 +       if (arg_conf) {
391 +               if (arg_conf_len == 0)
392 +                       if ((arg_conf_len = strlen(arg_conf)) == 0)
393 +                               /* huh ? cannot happen ! */
394 +                               log_fatal("Unable to process -C/-H/-F/--timeout/-V/--request-options configuration arguments");
395 +
396 +               /* parse the extra dhclient.conf configuration arguments
397 +                * into top level config: */
398 +               struct parse *cfile = (struct parse *)0;
399 +               const char *val = NULL;
400 +               int token;
401 +
402 +               status = new_parse(&cfile, -1, arg_conf, arg_conf_len, "extra dhclient -C/-H/-F/--timeout/-V/--request-options configuration arguments", 0);
403 +
404 +               if ((status != ISC_R_SUCCESS) || (cfile -> warnings_occurred))
405 +                       log_fatal("Cannot parse -C/-H/-F/--timeout/-V/--request-options configuration arguments !");
406 +               /* more detailed parse failures will be logged */
407 +
408 +               do {
409 +                       token = peek_token(&val, (unsigned *)0, cfile);
410 +                       if (token == END_OF_FILE)
411 +                               break;
412 +
413 +                       parse_client_statement(cfile, (struct interface_info *)0, &top_level_config);
414 +               } while (1);
415 +
416 +               if (cfile -> warnings_occurred)
417 +                       log_fatal("Cannot parse -C/-H/-F/--timeout/-V/--request-options configuration arguments !");
418 +               end_parse(&cfile);
419 +
420 +               if (timeout_arg) {
421 +                       /* we just set the toplevel timeout, but per-client
422 +                        * timeouts may still be at defaults.
423 +                        */
424 +                       for (ip=interfaces; ip; ip = ip->next) {
425 +                               if (ip->client->config->timeout == 60)
426 +                                       ip->client->config->timeout = timeout_arg;
427 +                       }
428 +               }
429 +
430 +               if ((dhclient_request_options != 0) && (top_level_config.requested_options != default_requested_options)) {
431 +                       for (ip=interfaces; ip; ip = ip->next) {
432 +                               if (ip->client->config->requested_options == default_requested_options)
433 +                                       ip->client->config->requested_options = top_level_config.requested_options;
434 +                       }
435 +               }
436 +
437 +               free(arg_conf);
438 +               arg_conf = NULL;
439 +               arg_conf_len = 0;
440 +       }
441 +
442         /* Parse the lease database. */
443         read_client_leases();
444  
445 @@ -3067,7 +3323,8 @@ void make_discover (client, lease)
446         client -> packet.xid = random ();
447         client -> packet.secs = 0; /* filled in by send_discover. */
448  
449 -       if (can_receive_unicast_unconfigured (client -> interface))
450 +       if ((!(bootp_broadcast_always || client->config->bootp_broadcast_always))
451 +           && can_receive_unicast_unconfigured(client->interface))
452                 client -> packet.flags = 0;
453         else
454                 client -> packet.flags = htons (BOOTP_BROADCAST);
455 @@ -3152,7 +3409,9 @@ void make_request (client, lease)
456         } else {
457                 memset (&client -> packet.ciaddr, 0,
458                         sizeof client -> packet.ciaddr);
459 -               if (can_receive_unicast_unconfigured (client -> interface))
460 +               if ((!(bootp_broadcast_always ||
461 +                   client ->config->bootp_broadcast_always)) &&
462 +                   can_receive_unicast_unconfigured (client -> interface))
463                         client -> packet.flags = 0;
464                 else
465                         client -> packet.flags = htons (BOOTP_BROADCAST);
466 @@ -3215,7 +3474,8 @@ void make_decline (client, lease)
467         client -> packet.hops = 0;
468         client -> packet.xid = client -> xid;
469         client -> packet.secs = 0; /* Filled in by send_request. */
470 -       if (can_receive_unicast_unconfigured (client -> interface))
471 +       if ((!(bootp_broadcast_always || client->config-> bootp_broadcast_always))
472 +           && can_receive_unicast_unconfigured (client->interface))
473                 client -> packet.flags = 0;
474         else
475                 client -> packet.flags = htons (BOOTP_BROADCAST);
476 diff -up dhcp-4.3.4/common/conflex.c.options dhcp-4.3.4/common/conflex.c
477 --- dhcp-4.3.4/common/conflex.c.options 2016-04-29 11:59:50.448590077 +0200
478 +++ dhcp-4.3.4/common/conflex.c 2016-04-29 12:13:23.637342420 +0200
479 @@ -832,6 +832,8 @@ intern(char *atom, enum dhcp_token dfv)
480                 if (!strcasecmp(atom+1, "ig-endian")) {
481                         return TOKEN_BIG_ENDIAN;
482                 }
483 +               if (!strcasecmp (atom + 1, "ootp-broadcast-always"))
484 +                       return BOOTP_BROADCAST_ALWAYS;
485                 break;
486               case 'c':
487                 if (!strcasecmp(atom + 1, "ase"))
488 diff -up dhcp-4.3.4/includes/dhcpd.h.options dhcp-4.3.4/includes/dhcpd.h
489 --- dhcp-4.3.4/includes/dhcpd.h.options 2016-04-29 11:59:50.448590077 +0200
490 +++ dhcp-4.3.4/includes/dhcpd.h 2016-04-29 12:14:05.361329401 +0200
491 @@ -1246,6 +1246,9 @@ struct client_config {
492  
493         int lease_id_format;            /* format for IDs in lease file,
494                                            TOKEN_OCTAL or TOKEN_HEX */
495 +
496 +       int bootp_broadcast_always;     /* If nonzero, always set the BOOTP_BROADCAST
497 +                                          flag in requests */
498  };
499  
500  /* Per-interface state used in the dhcp client... */
501 diff -up dhcp-4.3.4/includes/dhctoken.h.options dhcp-4.3.4/includes/dhctoken.h
502 --- dhcp-4.3.4/includes/dhctoken.h.options      2016-04-29 11:59:50.449590076 +0200
503 +++ dhcp-4.3.4/includes/dhctoken.h      2016-04-29 12:15:03.073300846 +0200
504 @@ -373,7 +373,8 @@ enum dhcp_token {
505         TOKEN_BIG_ENDIAN = 675,
506         LEASE_ID_FORMAT = 676,
507         TOKEN_HEX = 677,
508 -       TOKEN_OCTAL = 678
509 +       TOKEN_OCTAL = 678,
510 +       BOOTP_BROADCAST_ALWAYS = 679
511  };
512  
513  #define is_identifier(x)       ((x) >= FIRST_TOKEN &&  \
This page took 0.067801 seconds and 4 git commands to generate.