This is the mail archive of the ecos-patches@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: RedBoot DHCP -- scan for DHCP Message Type tag


David Vrabel wrote:

Some DHCP/BOOTP servers don't place the DHCP Message Type tag as the first tag. This patch makes RedBoot scan through the tags looking for it.

Here it is again minus the bit that's already checked in.


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.).

David Vrabel
--
David Vrabel, Design Engineer

Arcom, Clifton Road           Tel: +44 (0)1223 411200 ext. 3233
Cambridge CB1 7EA, UK         Web: http://www.arcom.com/


_____________________________________________________________________ The message in this transmission is sent in confidence for the attention of the addressee only and should not be disclosed to any other party. Unauthorised recipients are requested to preserve this confidentiality. Please advise the sender if the addressee is not resident at the receiving end.

This message has been checked for all viruses by MessageLabs Virus Control Centre.
Index: include/net/bootp.h
===================================================================
RCS file: /var/cvs/ecos/packages/redboot/current/include/net/bootp.h,v
retrieving revision 1.1.1.1
diff -u -B -p -r1.1.1.1 bootp.h
--- include/net/bootp.h	29 May 2003 10:55:49 -0000	1.1.1.1
+++ include/net/bootp.h	21 Nov 2003 15:24:15 -0000
@@ -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.
Index: src/net/bootp.c
===================================================================
RCS file: /var/cvs/ecos/packages/redboot/current/src/net/bootp.c,v
retrieving revision 1.3
diff -u -B -p -r1.3 bootp.c
--- src/net/bootp.c	20 Nov 2003 13:04:12 -0000	1.3
+++ src/net/bootp.c	21 Nov 2003 15:24:15 -0000
@@ -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!

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]