]> www.infradead.org Git - users/rw/ppcboot.git/commitdiff
DHCP still has serious problems.
authorwdenk <wdenk>
Wed, 30 May 2001 17:44:52 +0000 (17:44 +0000)
committerwdenk <wdenk>
Wed, 30 May 2001 17:44:52 +0000 (17:44 +0000)
include/config_lwmon.h
net/bootp.c
net/bootp.h

index 27253c61f248e3e28e1ab5a35f5bd41ba8fcaeee..44d068067c42fff6564221dd61dc1bfc93e22c0c 100644 (file)
                                CFG_CMD_BSP     )
 #else
 #define CONFIG_COMMANDS              ( CONFIG_CMD_DFL  | \
-                               CFG_CMD_DHCP    | \
                                CFG_CMD_EEPROM  | \
                                CFG_CMD_DATE    | \
                                CFG_CMD_IDE     | \
                                CFG_CMD_BSP     )
+/* CFG_CMD_DHCP        */
 #endif
 #define CONFIG_MAC_PARTITION
 #define CONFIG_DOS_PARTITION
index 8bfab2c969e1ddc6d2c28da4c041090e11889d38..de4cbc205a09b7f54e8bde838d5b7f7496030ce4 100644 (file)
@@ -7,7 +7,10 @@
  *     Copyright 2000 Paolo Scaffardi
  */
 
-/* #define DEBUG_BOOTP_EXT     1       / * Debug received vendor fields        */
+#if 0
+#define        DEBUG           1       /* general debug */
+#define DEBUG_BOOTP_EXT        1       /* Debug received vendor fields */
+#endif
 
 #include <ppcboot.h>
 #include <command.h>
@@ -64,9 +67,9 @@ static int BootpCheckPkt(uchar *pkt, unsigned dest, unsigned src, unsigned len)
                retval = -1;
        if (len < sizeof (Bootp_t) - OPT_SIZE)
                retval = -2;
-       if (bp->bp_op != OP_BOOTREQUEST && 
-           bp->bp_op != OP_BOOTREPLY && 
-           bp->bp_op != DHCP_OFFER && 
+       if (bp->bp_op != OP_BOOTREQUEST &&
+           bp->bp_op != OP_BOOTREPLY &&
+           bp->bp_op != DHCP_OFFER &&
            bp->bp_op != DHCP_ACK &&
            bp->bp_op != DHCP_NAK ) {
                retval = -3;
@@ -78,11 +81,13 @@ static int BootpCheckPkt(uchar *pkt, unsigned dest, unsigned src, unsigned len)
        if (bp->bp_id != BootpID)
                retval = -6;
 
-       // printf("Filtering pkt = %d\n", retval);
+#ifdef DEBUG
+       printf("Filtering pkt = %d\n", retval);
+#endif
        return retval;
 }
 
-/* 
+/*
  * Copy parameters of interest from BOOTP_REPLY/DHCP_OFFER packet
  */
 void BootpCopyNetParams(Bootp_t *bp)
@@ -585,13 +590,23 @@ void DhcpOptionsProcess(char *popt)
        while ( popt < end && *popt != 0xff ) {
                oplen = *(popt + 1);
                switch(*popt) {
-                       case 1: NetOurSubnetMask = *(IPaddr_t *)(popt + 2); break;
-                       case 3: NetOurGatewayIP = *(IPaddr_t *)(popt + 2); break;
-                       case 53: break;         /* Ignore Message Type Option */
-                       case 54: NetServerIP = *(IPaddr_t *)(popt+2); break;
-                       case 51: dhcp_leasetime = *(unsigned int *)(popt + 2); break;
+                       case  1:
+                               NetOurSubnetMask = *(IPaddr_t *)(popt + 2);
+                               break;
+                       case  3:
+                               NetOurGatewayIP = *(IPaddr_t *)(popt + 2);
+                               break;
+                       case 53:
+                               break;          /* Ignore Message Type Option */
+                       case 54:
+                               NetServerIP = *(IPaddr_t *)(popt+2);
+                               break;
+                       case 51:
+                               dhcp_leasetime = *(unsigned int *)(popt + 2);
+                               break;
                        default:
-                               printf("******* Unhandled DHCP Option present in OFFER/ACK: %d\n", *popt);
+                               printf("*** Unhandled DHCP Option in OFFER/ACK: %d\n",
+                                       *popt);
                                break;
                }
                popt += oplen + 2;      /* Process next option */
@@ -612,32 +627,15 @@ static int DhcpMessageType(unsigned char *popt)
        return -1;
 }
 
-/*
- * Scan string for filename str within fname
- */
-static int strfind(char *fname, char *str)
-{
-       int lf = strlen(fname);
-       int ls = strlen(str);
-       char *p = fname;
-       if ( ls > lf ) 
-               return -1;
-
-       while ( p - fname < lf ) {
-               if ( strncmp(p, str, ls) == 0 )
-                       return 0;
-               p++;
-       }
-       return -1;
-}
-
 void DhcpSendRequestPkt(Bootp_t *bp_offer)
 {
        volatile uchar *pkt, *iphdr;
        Bootp_t *bp;
        int pktlen, iplen, extlen;
 
+#ifdef DEBUG
        printf("DhcpSendRequestPkt: Sending DHCPREQUEST\n");
+#endif
        pkt = NetTxPacket;
        memset ((void*)pkt, 0, PKTSIZE);
 
@@ -685,12 +683,12 @@ static void
 DhcpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
 {
        Bootp_t *bp = (Bootp_t *)pkt;
-       if ( BootpCheckPkt(pkt, dest, src, len) )       /* Filter out pkts we don't want */
+       if (BootpCheckPkt(pkt, dest, src, len)) /* Filter out pkts we don't want */
                return;
 
 #ifdef DEBUG
-       printf("DHCPHandler: got DHCP packet: (src=%d, dst=%d, len=%d)\n",
-               src, dest, len);
+       printf("DHCPHandler: got DHCP packet: (src=%d, dst=%d, len=%d) state: %d\n",
+               src, dest, len, dhcp_state);
 #endif /* DEBUG */
 
        switch (dhcp_state) {
@@ -701,21 +699,36 @@ DhcpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
                 * If filename is in format we recognize, assume it is a valid
                 * OFFER from a server we want.
                 */
-               if ( strfind(bp->bp_file, BOOT_FILE_PREFIX) == 0 ) {
+#ifdef DEBUG
+               printf("DHCP: state=SELECTING bp_file: \"%s\"\n", bp->bp_file);
+#endif
+#ifdef CFG_BOOTFILE_PREFIX
+               if (strncmp(bp->bp_file,
+                           CFG_BOOTFILE_PREFIX,
+                           strlen(CFG_BOOTFILE_PREFIX)) == 0 ) {
+#endif /* CFG_BOOTFILE_PREFIX */
+
+#ifdef DEBUG
                        printf("TRANSITIONING TO REQUESTING STATE\n");
+#endif
                        dhcp_state = REQUESTING;
                        if ((*(uint *)bp->bp_vend) == BOOTP_VENDOR_MAGIC)
                                DhcpOptionsProcess(&bp->bp_vend[4]);
-                       
-                       BootpCopyNetParams(bp);         /* Store net params from reply */
-               
+
+                       BootpCopyNetParams(bp); /* Store net params from reply */
+
                        NetSetTimeout(TIMEOUT * CFG_HZ, BootpTimeout);
                        DhcpSendRequestPkt(bp);
+#ifdef CFG_BOOTFILE_PREFIX
                }
+#endif /* CFG_BOOTFILE_PREFIX */
+
                return;
                break;
        case REQUESTING:
+#ifdef DEBUG
                printf("DHCP State: REQUESTING\n");
+#endif
                if ( DhcpMessageType(bp->bp_vend) == DHCP_ACK ) {
                        dhcp_state = BOUND;
                        printf("DhcpHandler: Client BOUND to address ");
index 7ea757f38a1ad8fb7e88be56a2cf9e2772a77092..4e24b53bc3682363106864690605a2ffd65cad21 100644 (file)
@@ -89,7 +89,6 @@ typedef enum { INIT,
 #define DHCP_RELEASE  7
 
 #define SELECT_TIMEOUT 3       /* Seconds to wait for offers */
-#define BOOT_FILE_PREFIX "image-"
 
 /**********************************************************************/