summaryrefslogtreecommitdiff
path: root/sbin/dhclient
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2011-05-11 14:38:37 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2011-05-11 14:38:37 +0000
commit2738e3bb29bd9e8a6234dc538b2cb1e5d824e2d7 (patch)
treea3654bd5d15b75c5a9357e02f10427fcf284067c /sbin/dhclient
parent244b931de87cae31e725020f4da297be6d32637c (diff)
Make dhclient more friendly to sequential option processing by
always starting DHCP packet options with DHO_DHCP_MESSAGE_TYPE. Now DHCP-specific options always come after the option identifying the packet as DHCP rather than BOOTP. Makes at least Nortel NetIP DHCP server happier. Clean up some code and parameter passing. Closes PR#6543, as confirmed by original submitter and patch tester Len Zaifman. Thanks! ok matthew@ (who hates the ISC-like code)
Diffstat (limited to 'sbin/dhclient')
-rw-r--r--sbin/dhclient/dhclient.c11
-rw-r--r--sbin/dhclient/dhcp.h5
-rw-r--r--sbin/dhclient/dhcpd.h4
-rw-r--r--sbin/dhclient/options.c18
4 files changed, 21 insertions, 17 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c
index 84c1b874f22..54323f96008 100644
--- a/sbin/dhclient/dhclient.c
+++ b/sbin/dhclient/dhclient.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhclient.c,v 1.140 2011/04/17 20:06:08 phessler Exp $ */
+/* $OpenBSD: dhclient.c,v 1.141 2011/05/11 14:38:36 krw Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -1195,8 +1195,7 @@ make_discover(struct client_lease *lease)
}
/* Set up the option buffer to fit in a minimal UDP packet. */
- i = cons_options(client->packet.options, 576 - DHCP_FIXED_LEN,
- options);
+ i = cons_options(options);
if (i == -1 || client->packet.options[i] != DHO_END)
error("options do not fit in DHCPDISCOVER packet.");
client->packet_length = DHCP_FIXED_NON_UDP+i+1;
@@ -1264,8 +1263,7 @@ make_request(struct client_lease * lease)
}
/* Set up the option buffer to fit in a minimal UDP packet. */
- i = cons_options(client->packet.options, 576 - DHCP_FIXED_LEN,
- options);
+ i = cons_options(options);
if (i == -1 || client->packet.options[i] != DHO_END)
error("options do not fit in DHCPREQUEST packet.");
client->packet_length = DHCP_FIXED_NON_UDP+i+1;
@@ -1332,8 +1330,7 @@ make_decline(struct client_lease *lease)
}
/* Set up the option buffer to fit in a minimal UDP packet. */
- i = cons_options(client->packet.options, 576 - DHCP_FIXED_LEN,
- options);
+ i = cons_options(options);
if (i == -1 || client->packet.options[i] != DHO_END)
error("options do not fit in DHCPDECLINE packet.");
client->packet_length = DHCP_FIXED_NON_UDP+i+1;
diff --git a/sbin/dhclient/dhcp.h b/sbin/dhclient/dhcp.h
index e1394283972..d81de4a075a 100644
--- a/sbin/dhclient/dhcp.h
+++ b/sbin/dhclient/dhcp.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhcp.h,v 1.8 2010/10/15 09:51:15 jsg Exp $ */
+/* $OpenBSD: dhcp.h,v 1.9 2011/05/11 14:38:36 krw Exp $ */
/* Protocol structures... */
@@ -86,7 +86,8 @@ struct dhcp_packet {
/* Magic cookie validating dhcp options field (and bootp vendor
extensions field). */
-#define DHCP_OPTIONS_COOKIE "\143\202\123\143"
+#define DHCP_OPTIONS_COOKIE "\143\202\123\143"
+#define DHCP_OPTIONS_MESSAGE_TYPE "\065\001\000"
/* DHCP Option codes: */
diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h
index 1c686ade33b..fffb63d1f1b 100644
--- a/sbin/dhclient/dhcpd.h
+++ b/sbin/dhclient/dhcpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhcpd.h,v 1.72 2011/04/04 11:14:52 krw Exp $ */
+/* $OpenBSD: dhcpd.h,v 1.73 2011/05/11 14:38:36 krw Exp $ */
/*
* Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
@@ -207,7 +207,7 @@ extern struct client_state *client;
extern struct client_config *config;
/* options.c */
-int cons_options(unsigned char *, const int, struct option_data *);
+int cons_options(struct option_data *);
char *pretty_print_option(unsigned int, unsigned char *, int, int, int);
void do_packet(int, unsigned int, struct iaddr, struct hardware *);
diff --git a/sbin/dhclient/options.c b/sbin/dhclient/options.c
index c4007fe57a1..052aa8975de 100644
--- a/sbin/dhclient/options.c
+++ b/sbin/dhclient/options.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: options.c,v 1.38 2011/04/17 19:57:23 phessler Exp $ */
+/* $OpenBSD: options.c,v 1.39 2011/05/11 14:38:36 krw Exp $ */
/* DHCP options parsing and reassembly. */
@@ -131,18 +131,24 @@ parse_option_buffer(struct option_data *options, unsigned char *buffer,
* to see if it's DHO_END to decide if all the options were copied.
*/
int
-cons_options(unsigned char *buf, const int buflen, struct option_data *options)
+cons_options(struct option_data *options)
{
+ unsigned char *buf = client->packet.options;
+ int buflen = 576 - DHCP_FIXED_LEN;
int ix, incr, length, bufix, code, lastopt = -1;
bzero(buf, buflen);
- if (buflen > 3)
- memcpy(buf, DHCP_OPTIONS_COOKIE, 4);
- bufix = 4;
+ memcpy(buf, DHCP_OPTIONS_COOKIE, 4);
+ if (options[DHO_DHCP_MESSAGE_TYPE].data) {
+ memcpy(&buf[4], DHCP_OPTIONS_MESSAGE_TYPE, 3);
+ buf[6] = options[DHO_DHCP_MESSAGE_TYPE].data[0];
+ bufix = 7;
+ } else
+ bufix = 4;
for (code = DHO_SUBNET_MASK; code < DHO_END; code++) {
- if (!options[code].data)
+ if (!options[code].data || code == DHO_DHCP_MESSAGE_TYPE)
continue;
length = options[code].len;