net: Quietly ignore DHCP Option 28 (Broadcast Address)
[oweals/u-boot.git] / net / bootp.c
index 84ac8a027daf620687f14305000fcc6ac9978fa4..661e371063ac6273d0f3302ca0d85f12e1c4a1dd 100644 (file)
 #include <command.h>
 #include <net.h>
 #include "bootp.h"
-#include "net_rand.h"
 #include "tftp.h"
 #include "nfs.h"
 #ifdef CONFIG_STATUS_LED
 #include <status_led.h>
 #endif
-#include <linux/compiler.h>
+#ifdef CONFIG_BOOTP_RANDOM_DELAY
+#include "net_rand.h"
+#endif
 
 #define BOOTP_VENDOR_MAGIC     0x63825363      /* RFC1048 Magic Cookie */
 
@@ -96,15 +97,15 @@ static int BootpCheckPkt(uchar *pkt, unsigned dest, unsigned src, unsigned len)
  */
 static void BootpCopyNetParams(struct Bootp_t *bp)
 {
-       __maybe_unused IPaddr_t tmp_ip;
-
-       NetCopyIP(&NetOurIP, &bp->bp_yiaddr);
 #if !defined(CONFIG_BOOTP_SERVERIP)
+       IPaddr_t tmp_ip;
+
        NetCopyIP(&tmp_ip, &bp->bp_siaddr);
        if (tmp_ip != 0)
                NetCopyIP(&NetServerIP, &bp->bp_siaddr);
        memcpy(NetServerEther, ((struct ethernet_hdr *)NetRxPacket)->et_src, 6);
 #endif
+       NetCopyIP(&NetOurIP, &bp->bp_yiaddr);
        if (strlen(bp->bp_file) > 0)
                copy_filename(BootFile, bp->bp_file, sizeof(BootFile));
 
@@ -327,8 +328,13 @@ static void
 BootpTimeout(void)
 {
        if (BootpTry >= TIMEOUT_COUNT) {
+#ifdef CONFIG_BOOTP_MAY_FAIL
+               puts("\nRetry count exceeded\n");
+               net_set_state(NETLOOP_FAIL);
+#else
                puts("\nRetry count exceeded; starting again\n");
                NetStartAgain();
+#endif
        } else {
                NetSetTimeout(TIMEOUT, BootpTimeout);
                BootpRequest();
@@ -669,9 +675,9 @@ BootpRequest(void)
 
 #if defined(CONFIG_CMD_DHCP)
        dhcp_state = SELECTING;
-       NetSetHandler(DhcpHandler);
+       net_set_udp_handler(DhcpHandler);
 #else
-       NetSetHandler(BootpHandler);
+       net_set_udp_handler(BootpHandler);
 #endif
        NetSendPacket(NetTxPacket, pktlen);
 }
@@ -722,6 +728,8 @@ static void DhcpOptionsProcess(uchar *popt, struct Bootp_t *bp)
                        memcpy(&NetOurRootPath, popt + 2, size);
                        NetOurRootPath[size] = 0;
                        break;
+               case 28:        /* Ignore Broadcast Address Option */
+                       break;
 #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER)
                case 42:        /* NTP server IP */
                        NetCopyIP(&NetNtpServerIP, (popt + 2));
@@ -848,10 +856,10 @@ static void DhcpSendRequestPkt(struct Bootp_t *bp_offer)
        pktlen = eth_hdr_size + IP_UDP_HDR_SIZE + iplen;
        net_set_udp_header(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen);
 
-       debug("Transmitting DHCPREQUEST packet: len = %d\n", pktlen);
 #ifdef CONFIG_BOOTP_DHCP_REQUEST_DELAY
        udelay(CONFIG_BOOTP_DHCP_REQUEST_DELAY);
 #endif /* CONFIG_BOOTP_DHCP_REQUEST_DELAY */
+       debug("Transmitting DHCPREQUEST packet: len = %d\n", pktlen);
        NetSendPacket(NetTxPacket, pktlen);
 }