[klibc] PATCH: ipconfig may accept DHCPOFFER as DHCPACK
Άλκης Γεωργόπουλος
alkisg at gmail.com
Fri Jun 13 17:45:34 PDT 2008
I'm resending everything, with the signed-off paragraph included.
Thanks, and again, excuse my ignorance.
I found a bug in ipconfig and I'm sending a proposed patch for it.
I've only seen it happen in 2 dhcp-server environments. Scenario:
ipconfig sends a DHCP_DISCOVER,
server A answers with a DHCP_OFFER,
server B answers with a DHCP_OFFER,
ipconfig sends a DHCP_REQUEST for server A,
ipconfig accepts the DHCP_OFFER from server B instead of DHCP_ACK from
server A. <== BUG
The reason for this was that in dhcp_parse(), DHCPOFFER and DHCPACK
returned the same value (=1). So I had to modify the return values,
and I thought it would be better to return the constants DHCPOFFER,
DHCPACK etc instead of 1,2,3... I tried to keep the changes as minimal
as possible.
By making a contribution to this project, I certify that:
(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or
(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or
(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.
(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.
Signed-off-by: Άλκης Γεωργόπουλος <alkisg at gmail.com>
diff -ur ../ipconfig.old/dhcp_proto.c ./dhcp_proto.c
--- ../ipconfig.old/dhcp_proto.c 2008-06-14 01:52:11.000000000 +0300
+++ ./dhcp_proto.c 2008-06-14 02:28:32.000000000 +0300
@@ -71,6 +71,11 @@
/*
* Parse a DHCP response packet
+ * Returns:
+ * 0 = Not handled
+ * 2 = DHCPOFFER (from dhcp_proto.h)
+ * 5 = DHCPACK
+ * 6 = DHCPNACK
*/
static int
dhcp_parse(struct netdev *dev, struct bootp_hdr *hdr, uint8_t * exts,
int extlen)
@@ -101,19 +106,19 @@
switch (type) {
case DHCPOFFER:
- ret = bootp_parse(dev, hdr, exts, extlen);
- if (ret == 1 && serverid != INADDR_NONE)
+ ret = bootp_parse(dev, hdr, exts, extlen) ? DHCPOFFER : 0;
+ if (ret == DHCPOFFER && serverid != INADDR_NONE)
dev->serverid = serverid;
DEBUG(("\n dhcp offer\n"));
break;
case DHCPACK:
- ret = bootp_parse(dev, hdr, exts, extlen);
+ ret = bootp_parse(dev, hdr, exts, extlen) ? DHCPACK : 0;
DEBUG(("\n dhcp ack\n"));
break;
case DHCPNAK:
- ret = 2;
+ ret = DHCPNAK;
DEBUG(("\n dhcp nak\n"));
break;
}
@@ -122,6 +127,12 @@
/*
* Receive and parse a DHCP packet
+ * Returns:
+ *-1 = Error in packet_recv
+ * 0 = Not handled
+ * 2 = DHCPOFFER (from dhcp_proto.h)
+ * 5 = DHCPACK
+ * 6 = DHCPNACK
*/
static int dhcp_recv(struct netdev *dev)
{
diff -ur ../ipconfig.old/main.c ./main.c
--- ../ipconfig.old/main.c 2008-06-14 01:52:11.000000000 +0300
+++ ./main.c 2008-06-14 02:30:45.000000000 +0300
@@ -192,7 +192,7 @@
case -1:
s->state = DEVST_ERROR;
break;
- case 1: /* Offer received */
+ case DHCPOFFER: /* Offer received */
s->state = DEVST_DHCPREQ;
dhcp_send_request(s->dev);
break;
@@ -205,10 +205,10 @@
case -1: /* error */
s->state = DEVST_ERROR;
break;
- case 1: /* ACK received */
+ case DHCPACK: /* ACK received */
s->state = DEVST_COMPLETE;
break;
- case 2: /* NAK received */
+ case DHCPNAK: /* NAK received */
s->state = DEVST_DHCPDISC;
break;
}
More information about the klibc
mailing list