]> git.ipfire.org Git - people/ms/ipfire-3.x.git/blame - dhcp/patches/dhcp-4.2.4-options.patch
dhcp: Update to 4.2.4.
[people/ms/ipfire-3.x.git] / dhcp / patches / dhcp-4.2.4-options.patch
CommitLineData
444c1184
MT
1diff -up dhcp-4.2.4b1/client/clparse.c.options dhcp-4.2.4b1/client/clparse.c
2--- dhcp-4.2.4b1/client/clparse.c.options 2012-03-09 12:28:10.000000000 +0100
3+++ dhcp-4.2.4b1/client/clparse.c 2012-04-16 17:24:58.794047046 +0200
4@@ -154,6 +154,7 @@ isc_result_t read_client_conf ()
6df985df
SS
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)
444c1184 12@@ -320,7 +321,8 @@ void read_client_leases ()
6df985df
SS
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;
444c1184 22@@ -739,6 +741,12 @@ void parse_client_statement (cfile, ip,
6df985df
SS
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;
444c1184
MT
35diff -up dhcp-4.2.4b1/client/dhclient.c.options dhcp-4.2.4b1/client/dhclient.c
36--- dhcp-4.2.4b1/client/dhclient.c.options 2012-04-11 22:43:24.000000000 +0200
37+++ dhcp-4.2.4b1/client/dhclient.c 2012-04-16 17:24:58.795047032 +0200
6df985df
SS
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
444c1184 51@@ -87,6 +93,9 @@ int wanted_ia_na = -1; /* the absolute
6df985df
SS
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) {
444c1184 141+ log_error("timeout option must be > 0 - bad value: %s",argv[i]);
6df985df
SS
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) {
444c1184 166@@ -484,6 +584,156 @@ main(int argc, char **argv) {
6df985df
SS
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
444c1184 300+ * timeouts may still be at defaults.
6df985df 301+ */
6df985df
SS
302+ for (ip=interfaces; ip; ip = ip->next) {
303+ if (ip->client->config->timeout == 60)
304+ ip->client->config->timeout = timeout_arg;
6df985df
SS
305+ }
306+ }
307+
308+ if ((dhclient_request_options != 0) && (top_level_config.requested_options != default_requested_options)) {
309+ for (ip=interfaces; ip; ip = ip->next) {
310+ if (ip->client->config->requested_options == default_requested_options)
311+ ip->client->config->requested_options = top_level_config.requested_options;
312+ }
313+ }
314+
315+ free(arg_conf);
316+ arg_conf = NULL;
317+ arg_conf_len = 0;
318+ }
319+
320 /* Parse the lease database. */
321 read_client_leases();
322
444c1184 323@@ -2421,7 +2671,8 @@ void make_discover (client, lease)
6df985df
SS
324 client -> packet.xid = random ();
325 client -> packet.secs = 0; /* filled in by send_discover. */
326
327- if (can_receive_unicast_unconfigured (client -> interface))
328+ if ((!(bootp_broadcast_always || client->config->bootp_broadcast_always))
329+ && can_receive_unicast_unconfigured(client->interface))
330 client -> packet.flags = 0;
331 else
332 client -> packet.flags = htons (BOOTP_BROADCAST);
444c1184 333@@ -2505,7 +2756,9 @@ void make_request (client, lease)
6df985df
SS
334 } else {
335 memset (&client -> packet.ciaddr, 0,
336 sizeof client -> packet.ciaddr);
337- if (can_receive_unicast_unconfigured (client -> interface))
338+ if ((!(bootp_broadcast_always ||
339+ client ->config->bootp_broadcast_always)) &&
340+ can_receive_unicast_unconfigured (client -> interface))
341 client -> packet.flags = 0;
342 else
343 client -> packet.flags = htons (BOOTP_BROADCAST);
444c1184 344@@ -2567,7 +2820,8 @@ void make_decline (client, lease)
6df985df
SS
345 client -> packet.hops = 0;
346 client -> packet.xid = client -> xid;
347 client -> packet.secs = 0; /* Filled in by send_request. */
348- if (can_receive_unicast_unconfigured (client -> interface))
349+ if ((!(bootp_broadcast_always || 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);
444c1184
MT
354diff -up dhcp-4.2.4b1/common/conflex.c.options dhcp-4.2.4b1/common/conflex.c
355--- dhcp-4.2.4b1/common/conflex.c.options 2012-02-16 22:09:14.000000000 +0100
356+++ dhcp-4.2.4b1/common/conflex.c 2012-04-16 17:24:58.796047018 +0200
357@@ -808,6 +808,8 @@ intern(char *atom, enum dhcp_token dfv)
6df985df
SS
358 return BALANCE;
359 if (!strcasecmp (atom + 1, "ound"))
360 return BOUND;
361+ if (!strcasecmp (atom + 1, "ootp-broadcast-always"))
362+ return BOOTP_BROADCAST_ALWAYS;
363 break;
364 case 'c':
365 if (!strcasecmp(atom + 1, "ase"))
444c1184
MT
366diff -up dhcp-4.2.4b1/includes/dhcpd.h.options dhcp-4.2.4b1/includes/dhcpd.h
367--- dhcp-4.2.4b1/includes/dhcpd.h.options 2012-04-10 02:55:06.000000000 +0200
368+++ dhcp-4.2.4b1/includes/dhcpd.h 2012-04-16 17:24:58.797047004 +0200
6df985df
SS
369@@ -1147,6 +1147,9 @@ struct client_config {
370 int do_forward_update; /* If nonzero, and if we have the
371 information we need, update the
372 A record for the address we get. */
373+
374+ int bootp_broadcast_always; /* If nonzero, always set the BOOTP_BROADCAST
375+ flag in requests */
376 };
377
378 /* Per-interface state used in the dhcp client... */
444c1184
MT
379diff -up dhcp-4.2.4b1/includes/dhctoken.h.options dhcp-4.2.4b1/includes/dhctoken.h
380--- dhcp-4.2.4b1/includes/dhctoken.h.options 2012-02-16 22:09:15.000000000 +0100
381+++ dhcp-4.2.4b1/includes/dhctoken.h 2012-04-16 17:25:53.819276248 +0200
382@@ -364,7 +364,8 @@ enum dhcp_token {
383 GETHOSTBYNAME = 665,
384 PRIMARY6 = 666,
385 SECONDARY6 = 667,
386- TOKEN_INFINIBAND = 668
387+ TOKEN_INFINIBAND = 668,
388+ BOOTP_BROADCAST_ALWAYS = 669
6df985df
SS
389 };
390
391 #define is_identifier(x) ((x) >= FIRST_TOKEN && \