net: nfs: Only link in NFS code outside of SPL builds
[oweals/u-boot.git] / net / net.c
index a5a216c3eeec04ca984e2b73ff2e6aa71f15ef4b..5114364edd8b544886ab356efe8d4185cdbc9ce8 100644 (file)
--- a/net/net.c
+++ b/net/net.c
 #include <common.h>
 #include <command.h>
 #include <console.h>
-#include <environment.h>
+#include <env.h>
+#include <env_internal.h>
 #include <errno.h>
 #include <net.h>
 #include <net/fastboot.h>
 #include <net/tftp.h>
+#if defined(CONFIG_CMD_PCAP)
+#include <net/pcap.h>
+#endif
 #if defined(CONFIG_LED_STATUS)
 #include <miiphy.h>
 #include <status_led.h>
@@ -131,10 +135,6 @@ struct in_addr net_dns_server;
 struct in_addr net_dns_server2;
 #endif
 
-#ifdef CONFIG_MCAST_TFTP       /* Multicast TFTP */
-struct in_addr net_mcast_addr;
-#endif
-
 /** END OF BOOTP EXTENTIONS **/
 
 /* Our ethernet address */
@@ -308,7 +308,7 @@ U_BOOT_ENV_CALLBACK(dnsip, on_dnsip);
  */
 void net_auto_load(void)
 {
-#if defined(CONFIG_CMD_NFS)
+#if defined(CONFIG_CMD_NFS) && !defined(CONFIG_SPL_BUILD)
        const char *s = env_get("autoload");
 
        if (s != NULL && strcmp(s, "NFS") == 0) {
@@ -496,7 +496,7 @@ restart:
                        ping_start();
                        break;
 #endif
-#if defined(CONFIG_CMD_NFS)
+#if defined(CONFIG_CMD_NFS) && !defined(CONFIG_SPL_BUILD)
                case NFS:
                        nfs_start();
                        break;
@@ -561,9 +561,6 @@ restart:
         */
        for (;;) {
                WATCHDOG_RESET();
-#ifdef CONFIG_SHOW_ACTIVITY
-               show_activity(1);
-#endif
                if (arp_timeout_check() > 0)
                        time_start = get_timer(0);
 
@@ -657,6 +654,7 @@ restart:
                        /* Invalidate the last protocol */
                        eth_set_last_protocol(BOOTP);
                        debug_cond(DEBUG_INT_STATE, "--- net_loop Fail!\n");
+                       ret = -ENONET;
                        goto done;
 
                case NETLOOP_CONTINUE:
@@ -674,6 +672,11 @@ done:
        net_set_icmp_handler(NULL);
 #endif
        net_set_state(prev_net_state);
+
+#if defined(CONFIG_CMD_PCAP)
+       if (pcap_active())
+               pcap_print_status();
+#endif
        return ret;
 }
 
@@ -1086,6 +1089,9 @@ void net_process_received_packet(uchar *in_packet, int len)
 
        debug_cond(DEBUG_NET_PKT, "packet received\n");
 
+#if defined(CONFIG_CMD_PCAP)
+       pcap_post(in_packet, len, false);
+#endif
        net_rx_packet = in_packet;
        net_rx_packet_len = len;
        et = (struct ethernet_hdr *)in_packet;
@@ -1215,9 +1221,6 @@ void net_process_received_packet(uchar *in_packet, int len)
                dst_ip = net_read_ip(&ip->ip_dst);
                if (net_ip.s_addr && dst_ip.s_addr != net_ip.s_addr &&
                    dst_ip.s_addr != 0xFFFFFFFF) {
-#ifdef CONFIG_MCAST_TFTP
-                       if (net_mcast_addr != dst_ip)
-#endif
                                return;
                }
                /* Read source IP address for later use */
@@ -1258,6 +1261,9 @@ void net_process_received_packet(uchar *in_packet, int len)
                        return;
                }
 
+               if (ntohs(ip->udp_len) < UDP_HDR_SIZE || ntohs(ip->udp_len) > ntohs(ip->ip_len))
+                       return;
+
                debug_cond(DEBUG_DEV_PKT,
                           "received UDP (to=%pI4, from=%pI4, len=%d)\n",
                           &dst_ip, &src_ip, len);