[klibc] [klibc:master] ipconfig: Append padding if DHCP packet length < 300 octets

klibc-bot for KUMAAN 9maaan at gmail.com
Tue May 22 02:00:03 PDT 2012


Commit-ID:  f41c1d74c6a8e3d463e7e4291b112b367eb8b097
Gitweb:     http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=f41c1d74c6a8e3d463e7e4291b112b367eb8b097
Author:     KUMAAN <9maaan at gmail.com>
AuthorDate: Tue, 23 Aug 2011 14:59:19 +0900
Committer:  maximilian attems <max at stro.at>
CommitDate: Tue, 22 May 2012 10:55:16 +0200

[klibc] ipconfig: Append padding if DHCP packet length < 300 octets

This patch appends padding to DHCP packet for its length to be 300 octets,
if its length is shorter than 300 octets.

dhclient in ISC DHCP 4.1.1-P1 also does so. Some bad DHCP servers ignore
short DHCP packet which dhclient doesn't send.

Signed-off-by: KUMAAN <9maaan at gmail.com>
Acked-by: H. Peter Anvin <hpa at zytor.com>
Signed-off-by: maximilian attems <max at stro.at>

---
 usr/kinit/ipconfig/bootp_packet.h |    3 +++
 usr/kinit/ipconfig/dhcp_proto.c   |   18 +++++++++++++++++-
 2 files changed, 20 insertions(+), 1 deletions(-)

diff --git a/usr/kinit/ipconfig/bootp_packet.h b/usr/kinit/ipconfig/bootp_packet.h
index 1ef505e..1d5bd0d 100644
--- a/usr/kinit/ipconfig/bootp_packet.h
+++ b/usr/kinit/ipconfig/bootp_packet.h
@@ -38,4 +38,7 @@ struct bootp_hdr {
 /* larger size for backward compatibility of ipconfig */
 #define BOOTP_EXTS_SIZE	1500
 
+/* minimum length of BOOTP/DHCP packet on sending */
+#define BOOTP_MIN_LEN	300
+
 #endif /* BOOTP_PACKET_H */
diff --git a/usr/kinit/ipconfig/dhcp_proto.c b/usr/kinit/ipconfig/dhcp_proto.c
index 0c907e9..ebf79cc 100644
--- a/usr/kinit/ipconfig/dhcp_proto.c
+++ b/usr/kinit/ipconfig/dhcp_proto.c
@@ -50,7 +50,7 @@ static uint8_t dhcp_end[] = {
 
 /* Both iovecs below have to have the same structure, since dhcp_send()
    pokes at the internals */
-#define DHCP_IOV_LEN 7
+#define DHCP_IOV_LEN 8
 
 static struct iovec dhcp_discover_iov[DHCP_IOV_LEN] = {
 	/* [0] = ip + udp header */
@@ -60,6 +60,7 @@ static struct iovec dhcp_discover_iov[DHCP_IOV_LEN] = {
 	/* [4] = optional vendor class */
 	/* [5] = optional hostname */
 	/* [6] = {dhcp_end, sizeof(dhcp_end)} */
+	/* [7] = optional padding */
 };
 
 static struct iovec dhcp_request_iov[DHCP_IOV_LEN] = {
@@ -70,6 +71,7 @@ static struct iovec dhcp_request_iov[DHCP_IOV_LEN] = {
 	/* [4] = optional vendor class */
 	/* [5] = optional hostname */
 	/* [6] = {dhcp_end, sizeof(dhcp_end)} */
+	/* [7] = optional padding */
 };
 
 /*
@@ -187,7 +189,10 @@ static int dhcp_send(struct netdev *dev, struct iovec *vec)
 {
 	struct bootp_hdr bootp;
 	char dhcp_hostname[SYS_NMLN+2];
+	uint8_t padding[BOOTP_MIN_LEN - sizeof(struct bootp_hdr)];
+	int padding_len;
 	int i = 4;
+	int j;
 
 	memset(&bootp, 0, sizeof(struct bootp_hdr));
 
@@ -232,6 +237,17 @@ static int dhcp_send(struct netdev *dev, struct iovec *vec)
 	vec[i].iov_base = dhcp_end;
 	vec[i].iov_len  = sizeof(dhcp_end);
 
+	/* Append padding if DHCP packet length is shorter than BOOTP_MIN_LEN */
+	padding_len = sizeof(padding);
+	for (j = 2; j <= i; j++)
+		padding_len -= vec[j].iov_len;
+	if (padding_len > 0) {
+		memset(padding, 0, padding_len);
+		i++;
+		vec[i].iov_base = padding;
+		vec[i].iov_len  = padding_len;
+	}
+
 	return packet_send(dev, vec, i + 1);
 }
 


More information about the klibc mailing list