Mercurial > flash_v2
changeset 1412:7423c71e5c19
Improve scanning for DHCP options - from David Vrabel
| author | gthomas |
|---|---|
| date | Mon, 01 Dec 2003 18:33:38 +0000 |
| parents | 5e52f3febc7d |
| children | 1a7ba46a9ed9 |
| files | packages/redboot/current/ChangeLog packages/redboot/current/include/net/bootp.h packages/redboot/current/src/net/bootp.c |
| diffstat | 3 files changed, 33 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/packages/redboot/current/ChangeLog +++ b/packages/redboot/current/ChangeLog @@ -1,3 +1,11 @@ +2003-11-21 David Vrabel <dvrabel@arcom.com> + + * src/net/bootp.c (bootp_handler): Scan for DHCP Message Type tag + as it isn't always the first tag. + + * include/net/bootp.h: New #define's for DHCP message types + (DHCP_MESSAGE_TYPE_DISCOVER etc.). + 2003-11-25 John Dallaway <jld@ecoscentric.com> * src/fconfig.c (load_flash_config):
--- a/packages/redboot/current/include/net/bootp.h +++ b/packages/redboot/current/include/net/bootp.h @@ -284,6 +284,14 @@ typedef struct bootp { /* XXX - Add new tags here */ +/* DHCP Message Types */ +#define DHCP_MESS_TYPE_DISCOVER ((unsigned char) 1) +#define DHCP_MESS_TYPE_OFFER ((unsigned char) 2) +#define DHCP_MESS_TYPE_REQUEST ((unsigned char) 3) +#define DHCP_MESS_TYPE_DECLINE ((unsigned char) 4) +#define DHCP_MESS_TYPE_ACK ((unsigned char) 5) +#define DHCP_MESS_TYPE_NAK ((unsigned char) 6) +#define DHCP_MESS_TYPE_RELEASE ((unsigned char) 7) /* * "vendor" data permitted for CMU bootp clients.
--- a/packages/redboot/current/src/net/bootp.c +++ b/packages/redboot/current/src/net/bootp.c @@ -69,11 +69,8 @@ static bootp_header_t *bp_info; static const unsigned char dhcpCookie[] = {99,130,83,99}; static const unsigned char dhcpEnd[] = {255}; static const unsigned char dhcpDiscover[] = {53,1,1}; -static const unsigned char dhcpOffer[] = {53,1,2}; static const unsigned char dhcpRequest[] = {53,1,3}; static const unsigned char dhcpRequestIP[] = {50,4}; -static const unsigned char dhcpAck[] = {53,1,5}; -static const unsigned char dhcpNak[] = {53,1,6}; static const unsigned char dhcpParamRequestList[] = {55,3,1,3,6}; static enum { DHCP_NONE = 0, @@ -90,7 +87,7 @@ bootp_handler(udp_socket_t *skt, char *b { bootp_header_t *b; #ifdef CYGSEM_REDBOOT_NETWORKING_DHCP - unsigned char *p, *expected = 0; + unsigned char *p, expected = 0; #endif b = (bootp_header_t *)buf; @@ -114,24 +111,33 @@ bootp_handler(udp_socket_t *skt, char *b if (memcmp(p, dhcpCookie, sizeof(dhcpCookie))) return; p += 4; - + + // Find the DHCP Message Type tag + while (*p != TAG_DHCP_MESS_TYPE) { + p += p[1] + 2; + if (p >= (unsigned char*)b + sizeof(*bp_info)) + return; + } + + p += 2; + switch (dhcpState) { case DHCP_DISCOVER: // The discover message has been sent, only accept an offer reply - if (memcmp(p, dhcpOffer, sizeof(dhcpOffer)) == 0) { + if (*p == DHCP_MESS_TYPE_OFFER) { dhcpState = DHCP_OFFER; return; } else { - expected = (unsigned char *)dhcpOffer; + expected = DHCP_MESS_TYPE_OFFER; } break; case DHCP_REQUEST: // The request message has been sent, only accept an ack reply - if (memcmp(p, dhcpAck, sizeof(dhcpAck)) == 0) { + if (*p == DHCP_MESS_TYPE_ACK) { dhcpState = DHCP_ACK; return; } else { - expected = (unsigned char *)dhcpAck; + expected = DHCP_MESS_TYPE_ACK; } break; case DHCP_NONE: @@ -141,12 +147,11 @@ bootp_handler(udp_socket_t *skt, char *b return; } // See if we've been NAK'd - if so, give up and try again - if (memcmp(p, dhcpNak, sizeof(dhcpNak)) == 0) { + if (*p == DHCP_MESS_TYPE_NAK) { dhcpState = DHCP_NONE; return; } - diag_printf("DHCP reply: %d/%d/%d, not %d/%d/%d\n", - p[0], p[1], p[2], expected[0], expected[1], expected[2]); + diag_printf("DHCP reply: %d, not %d\n", (int)*p, (int)expected); return; #else // Simple BOOTP - this is all there is!
