From: wdenk Date: Wed, 30 May 2001 17:44:52 +0000 (+0000) Subject: DHCP still has serious problems. X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=a5a282cf9b31e494a224e052cb41a2e469367b68;p=users%2Frw%2Fppcboot.git DHCP still has serious problems. --- diff --git a/include/config_lwmon.h b/include/config_lwmon.h index 27253c6..44d0680 100644 --- a/include/config_lwmon.h +++ b/include/config_lwmon.h @@ -80,11 +80,11 @@ 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 diff --git a/net/bootp.c b/net/bootp.c index 8bfab2c..de4cbc2 100644 --- a/net/bootp.c +++ b/net/bootp.c @@ -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 #include @@ -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 "); diff --git a/net/bootp.h b/net/bootp.h index 7ea757f..4e24b53 100644 --- a/net/bootp.h +++ b/net/bootp.h @@ -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-" /**********************************************************************/