Coding Style cleanup; update CHANGELOG.
[platform/kernel/u-boot.git] / net / net.c
index b8648bd..641c37c 100644 (file)
--- a/net/net.c
+++ b/net/net.c
@@ -92,6 +92,9 @@
 #if defined(CONFIG_CDP_VERSION)
 #include <timestamp.h>
 #endif
+#if defined(CONFIG_CMD_DNS)
+#include "dns.h"
+#endif
 
 #if defined(CONFIG_CMD_NET)
 
@@ -139,8 +142,8 @@ uchar               NetServerEther[6] =     /* Boot server enet address             */
                        { 0, 0, 0, 0, 0, 0 };
 IPaddr_t       NetOurIP;               /* Our IP addr (0 = unknown)            */
 IPaddr_t       NetServerIP;            /* Server IP addr (0 = unknown)         */
-volatile uchar *NetRxPkt;              /* Current receive packet               */
-int            NetRxPktLen;            /* Current rx packet length             */
+volatile uchar *NetRxPacket;           /* Current receive packet               */
+int            NetRxPacketLen;         /* Current rx packet length             */
 unsigned       NetIPID;                /* IP packet ID                         */
 uchar          NetBcastAddr[6] =       /* Ethernet bcast address               */
                        { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
@@ -209,8 +212,6 @@ uchar               NetArpWaitPacketBuf[PKTSIZE_ALIGN + PKTALIGN];
 ulong          NetArpWaitTimerStart;
 int            NetArpWaitTry;
 
-int            env_changed_id = 0;
-
 void ArpRequest (void)
 {
        int i;
@@ -278,9 +279,10 @@ void ArpTimeoutCheck(void)
        }
 }
 
-int
+static void
 NetInitLoop(proto_t protocol)
 {
+       static int env_changed_id = 0;
        bd_t *bd = gd->bd;
        int env_id = get_env_id ();
 
@@ -292,10 +294,13 @@ NetInitLoop(proto_t protocol)
                NetServerIP = getenv_IPaddr ("serverip");
                NetOurNativeVLAN = getenv_VLAN("nvlan");
                NetOurVLAN = getenv_VLAN("vlan");
+#if defined(CONFIG_CMD_DNS)
+               NetOurDNSIP = getenv_IPaddr("dnsip");
+#endif
                env_changed_id = env_id;
        }
 
-       return 0;
+       return;
 }
 
 /**********************************************************************/
@@ -389,17 +394,20 @@ restart:
 #if defined(CONFIG_CMD_DHCP)
                case DHCP:
                        BootpTry = 0;
+                       NetOurIP = 0;
                        DhcpRequest();          /* Basically same as BOOTP */
                        break;
 #endif
 
                case BOOTP:
                        BootpTry = 0;
+                       NetOurIP = 0;
                        BootpRequest ();
                        break;
 
                case RARP:
                        RarpTry = 0;
+                       NetOurIP = 0;
                        RarpRequest ();
                        break;
 #if defined(CONFIG_CMD_PING)
@@ -427,6 +435,11 @@ restart:
                        SntpStart();
                        break;
 #endif
+#if defined(CONFIG_CMD_DNS)
+               case DNS:
+                       DnsStart();
+                       break;
+#endif
                default:
                        break;
                }
@@ -1123,8 +1136,8 @@ NetReceive(volatile uchar * inpkt, int len)
        printf("packet received\n");
 #endif
 
-       NetRxPkt = inpkt;
-       NetRxPktLen = len;
+       NetRxPacket = inpkt;
+       NetRxPacketLen = len;
        et = (Ethernet_t *)inpkt;
 
        /* too small packet? */
@@ -1274,6 +1287,15 @@ NetReceive(volatile uchar * inpkt, int len)
                        /* are we waiting for a reply */
                        if (!NetArpWaitPacketIP || !NetArpWaitPacketMAC)
                                break;
+
+#ifdef CONFIG_KEEP_SERVERADDR
+                       if (NetServerIP == NetArpWaitPacketIP) {
+                               char buf[20];
+                               sprintf(buf, "%pM", arp->ar_data);
+                               setenv("serveraddr", buf);
+                       }
+#endif
+
 #ifdef ET_DEBUG
                        printf("Got ARP REPLY, set server/gtwy eth addr (%pM)\n",
                                arp->ar_data);
@@ -1519,6 +1541,14 @@ static int net_check_prereq (proto_t protocol)
                }
                goto common;
 #endif
+#if defined(CONFIG_CMD_DNS)
+       case DNS:
+               if (NetOurDNSIP == 0) {
+                       puts("*** ERROR: DNS server address not given\n");
+                       return 1;
+               }
+               goto common;
+#endif
 #if defined(CONFIG_CMD_NFS)
        case NFS:
 #endif
@@ -1682,6 +1712,16 @@ void copy_filename (char *dst, char *src, int size)
 
 #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
+ */
+unsigned int random_port(void)
+{
+       return 1024 + (get_timer(0) % 0x8000);;
+}
+#endif
+
 void ip_to_string (IPaddr_t x, char *s)
 {
        x = ntohl (x);