]> git.sur5r.net Git - u-boot/blobdiff - net/net.c
net: ftmac100: remove unnecessary volatiles
[u-boot] / net / net.c
index fd13cd93f444394650c0a1953e2f33b5f6d2f405..a6096324126ada55e2f30afe023d376f6720ff16 100644 (file)
--- a/net/net.c
+++ b/net/net.c
@@ -80,7 +80,9 @@
 #include <net.h>
 #include "bootp.h"
 #include "tftp.h"
+#ifdef CONFIG_CMD_RARP
 #include "rarp.h"
+#endif
 #include "nfs.h"
 #ifdef CONFIG_STATUS_LED
 #include <status_led.h>
@@ -96,8 +98,6 @@
 #include "dns.h"
 #endif
 
-#if defined(CONFIG_CMD_NET)
-
 DECLARE_GLOBAL_DATA_PTR;
 
 #ifndef        CONFIG_ARP_TIMEOUT
@@ -403,11 +403,13 @@ restart:
                        BootpRequest ();
                        break;
 
+#if defined(CONFIG_CMD_RARP)
                case RARP:
                        RarpTry = 0;
                        NetOurIP = 0;
                        RarpRequest ();
                        break;
+#endif
 #if defined(CONFIG_CMD_PING)
                case PING:
                        PingStart();
@@ -1203,7 +1205,8 @@ static IP_t *__NetDefragment(IP_t *ip, int *lenp)
                h = payload + h->next_hole;
        }
 
-       if (offset8 + (len / 8) <= h - payload) {
+       /* last fragment may be 1..7 bytes, the "+7" forces acceptance */
+       if (offset8 + ((len + 7) / 8) <= h - payload) {
                /* no overlap with holes (dup fragment?) */
                return NULL;
        }
@@ -1493,6 +1496,7 @@ NetReceive(volatile uchar * inpkt, int len)
                }
                break;
 
+#ifdef CONFIG_CMD_RARP
        case PROT_RARP:
                debug("Got RARP\n");
                arp = (ARP_t *)ip;
@@ -1516,7 +1520,7 @@ NetReceive(volatile uchar * inpkt, int len)
                        (*packetHandler)(0,0,0,0);
                }
                break;
-
+#endif
        case PROT_IP:
                debug("Got IP\n");
                /* Before we start poking the header, make sure it is there */
@@ -1730,10 +1734,12 @@ static int net_check_prereq (proto_t protocol)
                }
                /* Fall through */
 
-       case DHCP:
+#ifdef CONFIG_CMD_RARP
        case RARP:
+#endif
        case BOOTP:
        case CDP:
+       case DHCP:
                if (memcmp (NetOurEther, "\0\0\0\0\0\0", 6) == 0) {
 #ifdef CONFIG_NET_MULTI
                        extern int eth_get_dev_index (void);
@@ -1859,7 +1865,7 @@ NetSetIP(volatile uchar * xip, IPaddr_t dest, int dport, int sport, int len)
        ip->ip_sum   = ~NetCksum((uchar *)ip, IP_HDR_SIZE_NO_UDP / 2);
 }
 
-void copy_filename (char *dst, char *src, int size)
+void copy_filename (char *dst, const char *src, int size)
 {
        if (*src && (*src == '"')) {
                ++src;
@@ -1872,15 +1878,15 @@ void copy_filename (char *dst, char *src, int size)
        *dst = '\0';
 }
 
-#endif
-
 #if defined(CONFIG_CMD_NFS) || defined(CONFIG_CMD_SNTP) || defined(CONFIG_CMD_DNS)
 /*
- * make port a little random, but use something trivial to compute
+ * make port a little random (1024-17407)
+ * This keeps the math somewhat trivial to compute, and seems to work with
+ * all supported protocols/clients/servers
  */
 unsigned int random_port(void)
 {
-       return 1024 + (get_timer(0) % 0x8000);;
+       return 1024 + (get_timer(0) % 0x4000);
 }
 #endif
 
@@ -1894,27 +1900,6 @@ void ip_to_string (IPaddr_t x, char *s)
        );
 }
 
-IPaddr_t string_to_ip(char *s)
-{
-       IPaddr_t addr;
-       char *e;
-       int i;
-
-       if (s == NULL)
-               return(0);
-
-       for (addr=0, i=0; i<4; ++i) {
-               ulong val = s ? simple_strtoul(s, &e, 10) : 0;
-               addr <<= 8;
-               addr |= (val & 0xFF);
-               if (s) {
-                       s = (*e) ? e+1 : e;
-               }
-       }
-
-       return (htonl(addr));
-}
-
 void VLAN_to_string(ushort x, char *s)
 {
        x = ntohs(x);
@@ -1928,7 +1913,7 @@ void VLAN_to_string(ushort x, char *s)
                sprintf(s, "%d", x & VLAN_IDMASK);
 }
 
-ushort string_to_VLAN(char *s)
+ushort string_to_VLAN(const char *s)
 {
        ushort id;
 
@@ -1943,11 +1928,6 @@ ushort string_to_VLAN(char *s)
        return htons(id);
 }
 
-IPaddr_t getenv_IPaddr (char *var)
-{
-       return (string_to_ip(getenv(var)));
-}
-
 ushort getenv_VLAN(char *var)
 {
        return (string_to_VLAN(getenv(var)));