]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
net: cosmetic: Change IPaddr_t to struct in_addr
authorJoe Hershberger <joe.hershberger@ni.com>
Wed, 8 Apr 2015 06:41:01 +0000 (01:41 -0500)
committerLothar Waßmann <LW@KARO-electronics.de>
Tue, 8 Sep 2015 20:05:47 +0000 (22:05 +0200)
This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
25 files changed:
common/cmd_bootce.c
common/cmd_net.c
common/cmd_pxe.c
drivers/net/netconsole.c
drivers/net/sandbox-raw.c
drivers/net/sandbox.c
include/common.h
include/net.h
include/wince.h
lib/net_utils.c
net/arp.c
net/arp.h
net/bootme.c
net/bootp.c
net/bootp.h
net/dns.c
net/eth.c
net/link_local.c
net/net.c
net/nfs.c
net/ping.c
net/rarp.c
net/sntp.c
net/tftp.c
test/dm/eth.c

index a95f163d479a2f92ce66dde8ad63ba25a5958048..556b01b5c8e55214bbe4636cbbb0555da7e8cde4 100644 (file)
@@ -52,7 +52,7 @@ DECLARE_GLOBAL_DATA_PTR;
 
 static ce_bin __attribute__ ((aligned (32))) g_bin;
 static ce_net __attribute__ ((aligned (32))) g_net;
-static IPaddr_t server_ip;
+static struct in_addr server_ip;
 
 static void ce_init_bin(ce_bin *bin, unsigned char *dataBuffer)
 {
@@ -133,7 +133,7 @@ static void ce_setup_std_drv_globals(ce_std_driver_globals *std_drv_glb)
        snprintf(std_drv_glb->deviceId, sizeof(std_drv_glb->deviceId),
                "Triton%02X", eth_get_dev()->enetaddr[5]);
 
-       NetCopyIP(&std_drv_glb->kitl.ipAddress, &NetOurIP);
+       net_copy_ip(&std_drv_glb->kitl.ipAddress, &net_ip);
        std_drv_glb->kitl.ipMask = getenv_IPaddr("netmask");
        std_drv_glb->kitl.ipRoute = getenv_IPaddr("gatewayip");
 
@@ -617,9 +617,9 @@ static enum bootme_state ce_process_download(ce_net *net, ce_bin *bin)
                                        // Some diag output
                                        if (net->verbose) {
                                                printf("Locked Down download link, IP: %pI4\n",
-                                                       &NetServerIP);
+                                                       &net_server_ip);
                                                printf("Sending BOOTME request [%d] to %pI4\n",
-                                                       net->seqNum, &NetServerIP);
+                                                       net->seqNum, &net_server_ip);
                                        }
 
                                        // Lock down EShell download link
@@ -705,7 +705,7 @@ static enum bootme_state ce_process_edbg(ce_net *net, ce_bin *bin)
                /* Some diag output */
                if (net->verbose) {
                        printf("Locked Down EDBG service link, IP: %pI4\n",
-                               &NetServerIP);
+                               &net_server_ip);
                }
 
                /* Lock down EDBG link */
@@ -837,7 +837,7 @@ static int ce_send_bootme(ce_net *net)
        }
 
        /* IP address from active config */
-       NetCopyIP(&data->ipAddr, &NetOurIP);
+       net_copy_ip(&data->ipAddr, &net_ip);
 
        // Device name string (NULL terminated). Should include
        // platform and number based on Ether address (e.g. Odo42, CEPCLS2346, etc)
@@ -966,7 +966,7 @@ static int do_ceconnect(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]
        int ret = 1;
        int i;
 
-       server_ip = 0;
+       server_ip.s_addr = 0;
 
        for (i = 1; i < argc; i++){
                if (*argv[i] != '-')
index 3f52edc805d23219a2d261a18d1fff6afd28ade6..d75718ce5019235b761c4f7fec4fa162bfe3f928 100644 (file)
@@ -114,13 +114,13 @@ static void netboot_update_env(void)
 {
        char tmp[22];
 
-       if (NetOurGatewayIP) {
-               ip_to_string(NetOurGatewayIP, tmp);
+       if (net_gateway.s_addr) {
+               ip_to_string(net_gateway, tmp);
                setenv("gatewayip", tmp);
        }
 
-       if (NetOurSubnetMask) {
-               ip_to_string(NetOurSubnetMask, tmp);
+       if (net_netmask.s_addr) {
+               ip_to_string(net_netmask, tmp);
                setenv("netmask", tmp);
        }
 
@@ -130,8 +130,8 @@ static void netboot_update_env(void)
        if (NetOurRootPath[0])
                setenv("rootpath", NetOurRootPath);
 
-       if (NetOurIP) {
-               ip_to_string(NetOurIP, tmp);
+       if (net_ip.s_addr) {
+               ip_to_string(net_ip, tmp);
                setenv("ipaddr", tmp);
        }
 #if !defined(CONFIG_BOOTP_SERVERIP)
@@ -139,18 +139,18 @@ static void netboot_update_env(void)
         * Only attempt to change serverip if net/bootp.c:BootpCopyNetParams()
         * could have set it
         */
-       if (NetServerIP) {
-               ip_to_string(NetServerIP, tmp);
+       if (net_server_ip.s_addr) {
+               ip_to_string(net_server_ip, tmp);
                setenv("serverip", tmp);
        }
 #endif
-       if (NetOurDNSIP) {
-               ip_to_string(NetOurDNSIP, tmp);
+       if (net_dns_server.s_addr) {
+               ip_to_string(net_dns_server, tmp);
                setenv("dnsip", tmp);
        }
 #if defined(CONFIG_BOOTP_DNS2)
-       if (NetOurDNS2IP) {
-               ip_to_string(NetOurDNS2IP, tmp);
+       if (net_dns_server2.s_addr) {
+               ip_to_string(net_dns_server2, tmp);
                setenv("dnsip2", tmp);
        }
 #endif
@@ -166,8 +166,8 @@ static void netboot_update_env(void)
 #endif
 #if defined(CONFIG_CMD_SNTP) \
     && defined(CONFIG_BOOTP_NTPSERVER)
-       if (NetNtpServerIP) {
-               ip_to_string(NetNtpServerIP, tmp);
+       if (net_ntp_server.s_addr) {
+               ip_to_string(net_ntp_server, tmp);
                setenv("ntpserverip", tmp);
        }
 #endif
@@ -201,11 +201,13 @@ static int netboot_common(enum proto_t proto, cmd_tbl_t *cmdtp, int argc,
                if (end == (argv[1] + strlen(argv[1])))
                        load_addr = addr;
                else
-                       copy_filename(BootFile, argv[1], sizeof(BootFile));
+                       copy_filename(net_boot_file_name, argv[1],
+                                     sizeof(net_boot_file_name));
                break;
 
        case 3: load_addr = simple_strtoul(argv[1], NULL, 16);
-               copy_filename(BootFile, argv[2], sizeof(BootFile));
+               copy_filename(net_boot_file_name, argv[2],
+                             sizeof(net_boot_file_name));
 
                break;
 
@@ -216,7 +218,8 @@ static int netboot_common(enum proto_t proto, cmd_tbl_t *cmdtp, int argc,
                        printf("Invalid address/size\n");
                        return CMD_RET_USAGE;
                }
-               copy_filename(BootFile, argv[3], sizeof(BootFile));
+               copy_filename(net_boot_file_name, argv[3],
+                             sizeof(net_boot_file_name));
                break;
 #endif
        default:
@@ -260,8 +263,8 @@ static int do_ping(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
        if (argc < 2)
                return CMD_RET_USAGE;
 
-       NetPingIP = string_to_ip(argv[1]);
-       if (NetPingIP == 0)
+       net_ping_ip = string_to_ip(argv[1]);
+       if (net_ping_ip.s_addr == 0)
                return CMD_RET_USAGE;
 
        if (NetLoop(PING) < 0) {
@@ -331,14 +334,14 @@ int do_sntp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
        char *toff;
 
        if (argc < 2) {
-               NetNtpServerIP = getenv_IPaddr("ntpserverip");
-               if (NetNtpServerIP == 0) {
+               net_ntp_server = getenv_ip("ntpserverip");
+               if (net_ntp_server.s_addr == 0) {
                        printf("ntpserverip not set\n");
                        return CMD_RET_FAILURE;
                }
        } else {
-               NetNtpServerIP = string_to_ip(argv[1]);
-               if (NetNtpServerIP == 0) {
+               net_ntp_server = string_to_ip(argv[1]);
+               if (net_ntp_server.s_addr == 0) {
                        printf("Bad NTP server IP address\n");
                        return CMD_RET_FAILURE;
                }
@@ -352,7 +355,7 @@ int do_sntp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
        if (NetLoop(SNTP) < 0) {
                printf("SNTP failed: host %pI4 not responding\n",
-                       &NetNtpServerIP);
+                       &net_ntp_server);
                return CMD_RET_FAILURE;
        }
 
@@ -421,14 +424,14 @@ static int do_link_local(cmd_tbl_t *cmdtp, int flag, int argc,
        if (NetLoop(LINKLOCAL) < 0)
                return CMD_RET_FAILURE;
 
-       NetOurGatewayIP = 0;
-       ip_to_string(NetOurGatewayIP, tmp);
+       net_gateway.s_addr = 0;
+       ip_to_string(net_gateway, tmp);
        setenv("gatewayip", tmp);
 
-       ip_to_string(NetOurSubnetMask, tmp);
+       ip_to_string(net_netmask, tmp);
        setenv("netmask", tmp);
 
-       ip_to_string(NetOurIP, tmp);
+       ip_to_string(net_ip, tmp);
        setenv("ipaddr", tmp);
        setenv("llipaddr", tmp); /* store this for next time */
 
index 96f963ddd77606d9fe9a23dd8853e198c059d07f..5cde5b6258ccee2e39c14874daa333323f39352c 100644 (file)
@@ -331,7 +331,7 @@ static int pxe_ipaddr_paths(cmd_tbl_t *cmdtp, void *pxefile_addr_r)
        char ip_addr[9];
        int mask_pos, err;
 
-       sprintf(ip_addr, "%08X", ntohl(NetOurIP));
+       sprintf(ip_addr, "%08X", ntohl(net_ip.s_addr));
 
        for (mask_pos = 7; mask_pos >= 0;  mask_pos--) {
                err = get_pxelinux_path(cmdtp, ip_addr, pxefile_addr_r);
@@ -1568,7 +1568,7 @@ do_pxe_boot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
        destroy_pxe_menu(cfg);
 
-       copy_filename(BootFile, "", sizeof(BootFile));
+       copy_filename(net_boot_file_name, "", sizeof(net_boot_file_name));
 
        return 0;
 }
index 87cea7a93209b7fad0fa074c0668dd53ea2d053a..55f383f13391b51bfcceee65a1fe469aff5eb4da 100644 (file)
@@ -23,7 +23,7 @@ static int input_recursion;
 static int output_recursion;
 static int net_timeout;
 static uchar nc_ether[6]; /* server enet address */
-static IPaddr_t nc_ip; /* server ip */
+static struct in_addr nc_ip; /* server ip */
 static short nc_out_port; /* target output port */
 static short nc_in_port; /* source input port */
 static const char *output_packet; /* used by first send udp */
@@ -35,14 +35,14 @@ static int output_packet_len;
 enum proto_t net_loop_last_protocol = BOOTP;
 
 static void nc_wait_arp_handler(uchar *pkt, unsigned dest,
-                                IPaddr_t sip, unsigned src,
+                                struct in_addr sip, unsigned src,
                                 unsigned len)
 {
        net_set_state(NETLOOP_SUCCESS); /* got arp reply - quit net loop */
 }
 
-static void nc_handler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
-                       unsigned len)
+static void nc_handler(uchar *pkt, unsigned dest, struct in_addr sip,
+                      unsigned src, unsigned len)
 {
        if (input_size)
                net_set_state(NETLOOP_SUCCESS); /* got input - quit net loop */
@@ -53,24 +53,25 @@ static void nc_timeout(void)
        net_set_state(NETLOOP_SUCCESS);
 }
 
-static int is_broadcast(IPaddr_t ip)
+static int is_broadcast(struct in_addr ip)
 {
-       static IPaddr_t netmask;
-       static IPaddr_t our_ip;
+       static struct in_addr netmask;
+       static struct in_addr our_ip;
        static int env_changed_id;
        int env_id = get_env_id();
 
        /* update only when the environment has changed */
        if (env_changed_id != env_id) {
-               netmask = getenv_IPaddr("netmask");
-               our_ip = getenv_IPaddr("ipaddr");
+               netmask = getenv_ip("netmask");
+               our_ip = getenv_ip("ipaddr");
 
                env_changed_id = env_id;
        }
 
-       return (ip == ~0 ||                             /* 255.255.255.255 */
-           ((netmask & our_ip) == (netmask & ip) &&    /* on the same net */
-           (netmask | ip) == ~0));             /* broadcast to our net */
+       return (ip.s_addr == ~0 || /* 255.255.255.255 (global bcast) */
+               ((netmask.s_addr & our_ip.s_addr) ==
+                (netmask.s_addr & ip.s_addr) && /* on the same net and */
+                (netmask.s_addr | ip.s_addr) == ~0)); /* bcast to our net */
 }
 
 static int refresh_settings_from_env(void)
@@ -82,8 +83,8 @@ static int refresh_settings_from_env(void)
        /* update only when the environment has changed */
        if (env_changed_id != env_id) {
                if (getenv("ncip")) {
-                       nc_ip = getenv_IPaddr("ncip");
-                       if (!nc_ip)
+                       nc_ip = getenv_ip("ncip");
+                       if (!nc_ip.s_addr)
                                return -1;      /* ncip is 0.0.0.0 */
                        p = strchr(getenv("ncip"), ':');
                        if (p != NULL) {
@@ -91,7 +92,7 @@ static int refresh_settings_from_env(void)
                                nc_in_port = nc_out_port;
                        }
                } else
-                       nc_ip = ~0; /* ncip is not set, so broadcast */
+                       nc_ip.s_addr = ~0; /* ncip is not set, so broadcast */
 
                p = getenv("ncoutport");
                if (p != NULL)
@@ -131,7 +132,7 @@ void NcStart(void)
        }
 }
 
-int nc_input_packet(uchar *pkt, IPaddr_t src_ip, unsigned dest_port,
+int nc_input_packet(uchar *pkt, struct in_addr src_ip, unsigned dest_port,
        unsigned src_port, unsigned len)
 {
        int end, chunk;
@@ -139,7 +140,7 @@ int nc_input_packet(uchar *pkt, IPaddr_t src_ip, unsigned dest_port,
        if (dest_port != nc_in_port || !len)
                return 0; /* not for us */
 
-       if (src_ip != nc_ip && !is_broadcast(nc_ip))
+       if (src_ip.s_addr != nc_ip.s_addr && !is_broadcast(nc_ip))
                return 0; /* not from our client */
 
        debug_cond(DEBUG_DEV_PKT, "input: \"%*.*s\"\n", len, len, pkt);
@@ -171,7 +172,7 @@ static void nc_send_packet(const char *buf, int len)
        int inited = 0;
        uchar *pkt;
        uchar *ether;
-       IPaddr_t ip;
+       struct in_addr ip;
 
        debug_cond(DEBUG_DEV_PKT, "output: \"%*.*s\"\n", len, len, buf);
 
index 91da5f55ca8013adde211fc930cbdf33eec3fb1c..45c3b18bdf33ccfe8d4f224e5d6e10f6c2e385ab 100644 (file)
@@ -16,7 +16,7 @@
 DECLARE_GLOBAL_DATA_PTR;
 
 static int reply_arp;
-static IPaddr_t arp_ip;
+static struct in_addr arp_ip;
 
 static int sb_eth_raw_start(struct udevice *dev)
 {
@@ -55,7 +55,7 @@ static int sb_eth_raw_send(struct udevice *dev, void *packet, int length)
                         * localhost works on a higher-level API in Linux than
                         * ARP packets, so fake it
                         */
-                       arp_ip = NetReadIP(&arp->ar_tpa);
+                       arp_ip = net_read_ip(&arp->ar_tpa);
                        reply_arp = 1;
                        return 0;
                }
@@ -93,9 +93,9 @@ static int sb_eth_raw_recv(struct udevice *dev, uchar **packetp)
                /* Any non-zero MAC address will work */
                memset(&arp->ar_sha, 0x01, ARP_HLEN);
                /* Use whatever IP we were looking for (always 127.0.0.1?) */
-               NetWriteIP(&arp->ar_spa, arp_ip);
+               net_write_ip(&arp->ar_spa, arp_ip);
                memcpy(&arp->ar_tha, pdata->enetaddr, ARP_HLEN);
-               NetWriteIP(&arp->ar_tpa, NetOurIP);
+               net_write_ip(&arp->ar_tpa, net_ip);
                length = ARP_HDR_SIZE;
        } else {
                /* If local, the Ethernet header won't be included; skip it */
index db115d0339f8223e91db0a76c812fec0c944878b..e239ff44479d07cbd04d3906c46646bae2f3c9c1 100644 (file)
@@ -24,7 +24,7 @@ DECLARE_GLOBAL_DATA_PTR;
  */
 struct eth_sandbox_priv {
        uchar fake_host_hwaddr[ARP_HLEN];
-       IPaddr_t fake_host_ipaddr;
+       struct in_addr fake_host_ipaddr;
        uchar *recv_packet_buffer;
        int recv_packet_length;
 };
@@ -73,7 +73,7 @@ static int sb_eth_send(struct udevice *dev, void *packet, int length)
                        struct arp_hdr *arp_recv;
 
                        /* store this as the assumed IP of the fake host */
-                       priv->fake_host_ipaddr = NetReadIP(&arp->ar_tpa);
+                       priv->fake_host_ipaddr = net_read_ip(&arp->ar_tpa);
                        /* Formulate a fake response */
                        eth_recv = (void *)priv->recv_packet_buffer;
                        memcpy(eth_recv->et_dest, eth->et_src, ARP_HLEN);
@@ -90,9 +90,9 @@ static int sb_eth_send(struct udevice *dev, void *packet, int length)
                        arp_recv->ar_op = htons(ARPOP_REPLY);
                        memcpy(&arp_recv->ar_sha, priv->fake_host_hwaddr,
                               ARP_HLEN);
-                       NetWriteIP(&arp_recv->ar_spa, priv->fake_host_ipaddr);
+                       net_write_ip(&arp_recv->ar_spa, priv->fake_host_ipaddr);
                        memcpy(&arp_recv->ar_tha, &arp->ar_sha, ARP_HLEN);
-                       NetCopyIP(&arp_recv->ar_tpa, &arp->ar_spa);
+                       net_copy_ip(&arp_recv->ar_tpa, &arp->ar_spa);
 
                        priv->recv_packet_length = ETHER_HDR_SIZE +
                                ARP_HDR_SIZE;
@@ -121,9 +121,9 @@ static int sb_eth_send(struct udevice *dev, void *packet, int length)
                                       ARP_HLEN);
                                ipr->ip_sum = 0;
                                ipr->ip_off = 0;
-                               NetCopyIP((void *)&ipr->ip_dst, &ip->ip_src);
-                               NetWriteIP((void *)&ipr->ip_src,
-                                          priv->fake_host_ipaddr);
+                               net_copy_ip((void *)&ipr->ip_dst, &ip->ip_src);
+                               net_write_ip((void *)&ipr->ip_src,
+                                            priv->fake_host_ipaddr);
                                ipr->ip_sum = compute_ip_checksum(ipr,
                                        IP_HDR_SIZE);
 
index fb5c4845992a302fcaaba5d0d8234b696bfd758c..f1dad4b2aae8388c1e162f2c0d14bb77e6d9df7d 100644 (file)
@@ -865,7 +865,7 @@ int zzip(void *dst, unsigned long *lenp, unsigned char *src,
 
 /* lib/net_utils.c */
 #include <net.h>
-static inline IPaddr_t getenv_IPaddr(char *var)
+static inline struct in_addr getenv_ip(char *var)
 {
        return string_to_ip(getenv(var));
 }
index ef9de3cad14bce2844b4f4647e0b665ab832665d..088ad8dadb07c14e19ec694cf5738ff345250a54 100644 (file)
@@ -39,8 +39,9 @@
 #define PKTALIGN       ARCH_DMA_MINALIGN
 
 /* IPv4 addresses are always 32 bits in size */
-typedef __be32         IPaddr_t;
-
+struct in_addr {
+       __be32 s_addr;
+};
 
 /**
  * An incoming packet handler.
@@ -51,7 +52,7 @@ typedef __be32                IPaddr_t;
  * @param len    packet length
  */
 typedef void rxhand_f(uchar *pkt, unsigned dport,
-                     IPaddr_t sip, unsigned sport,
+                     struct in_addr sip, unsigned sport,
                      unsigned len);
 
 /**
@@ -65,7 +66,7 @@ typedef void rxhand_f(uchar *pkt, unsigned dport,
  * @param len  packet length
  */
 typedef void rxhand_icmp_f(unsigned type, unsigned code, unsigned dport,
-               IPaddr_t sip, unsigned sport, uchar *pkt, unsigned len);
+               struct in_addr sip, unsigned sport, uchar *pkt, unsigned len);
 
 /*
  *     A timeout handler.  Called after time interval has expired.
@@ -243,7 +244,7 @@ void eth_halt(void);                        /* stop SCC */
 const char *eth_get_name(void);                /* get name of current device */
 
 #ifdef CONFIG_MCAST_TFTP
-int eth_mcast_join(IPaddr_t mcast_addr, int join);
+int eth_mcast_join(struct in_addr mcast_addr, int join);
 u32 ether_crc(size_t len, unsigned char const *p);
 #endif
 
@@ -318,8 +319,8 @@ struct ip_hdr {
        uchar           ip_ttl;         /* time to live                 */
        uchar           ip_p;           /* protocol                     */
        ushort          ip_sum;         /* checksum                     */
-       IPaddr_t        ip_src;         /* Source IP address            */
-       IPaddr_t        ip_dst;         /* Destination IP address       */
+       struct in_addr  ip_src;         /* Source IP address            */
+       struct in_addr  ip_dst;         /* Destination IP address       */
 };
 
 #define IP_OFFS                0x1fff /* ip offset *= 8 */
@@ -342,8 +343,8 @@ struct ip_udp_hdr {
        uchar           ip_ttl;         /* time to live                 */
        uchar           ip_p;           /* protocol                     */
        ushort          ip_sum;         /* checksum                     */
-       IPaddr_t        ip_src;         /* Source IP address            */
-       IPaddr_t        ip_dst;         /* Destination IP address       */
+       struct in_addr  ip_src;         /* Source IP address            */
+       struct in_addr  ip_dst;         /* Destination IP address       */
        ushort          udp_src;        /* UDP source port              */
        ushort          udp_dst;        /* UDP destination port         */
        ushort          udp_len;        /* Length of UDP packet         */
@@ -458,28 +459,28 @@ struct icmp_hdr {
  *
  * Note:
  *
- * All variables of type IPaddr_t are stored in NETWORK byte order
+ * All variables of type struct in_addr are stored in NETWORK byte order
  * (big endian).
  */
 
 /* net.c */
 /** BOOTP EXTENTIONS **/
-extern IPaddr_t NetOurGatewayIP;       /* Our gateway IP address */
-extern IPaddr_t NetOurSubnetMask;      /* Our subnet mask (0 = unknown) */
-extern IPaddr_t NetOurDNSIP;   /* Our Domain Name Server (0 = unknown) */
+extern struct in_addr net_gateway;     /* Our gateway IP address */
+extern struct in_addr net_netmask;     /* Our subnet mask (0 = unknown) */
+/* Our Domain Name Server (0 = unknown) */
+extern struct in_addr net_dns_server;
 #if defined(CONFIG_BOOTP_DNS2)
-extern IPaddr_t NetOurDNS2IP;  /* Our 2nd Domain Name Server (0 = unknown) */
+/* Our 2nd Domain Name Server (0 = unknown) */
+extern struct in_addr net_dns_server2;
 #endif
 extern char    NetOurNISDomain[32];    /* Our NIS domain */
 extern char    NetOurHostName[32];     /* Our hostname */
 extern char    NetOurRootPath[64];     /* Our root path */
-extern ushort  NetBootFileSize;        /* Our boot file size in blocks */
 /** END OF BOOTP EXTENTIONS **/
-extern ulong           NetBootFileXferSize;    /* size of bootfile in bytes */
 extern uchar           NetOurEther[6];         /* Our ethernet address */
 extern uchar           NetServerEther[6];      /* Boot server enet address */
-extern IPaddr_t                NetOurIP;       /* Our    IP addr (0 = unknown) */
-extern IPaddr_t                NetServerIP;    /* Server IP addr (0 = unknown) */
+extern struct in_addr  net_ip;         /* Our    IP addr (0 = unknown) */
+extern struct in_addr  net_server_ip;  /* Server IP addr (0 = unknown) */
 extern uchar           *NetTxPacket;           /* THE transmit packet */
 #ifdef CONFIG_DM_ETH
 extern uchar           *net_rx_packets[PKTBUFSRX]; /* Receive packets */
@@ -504,8 +505,11 @@ enum proto_t {
        TFTPSRV, TFTPPUT, LINKLOCAL, BOOTME
 };
 
-/* from net/net.c */
-extern char    BootFile[128];                  /* Boot File name */
+extern char    net_boot_file_name[128];/* Boot File name */
+/* The actual transferred size of the bootfile (in bytes) */
+extern u32     net_boot_file_size;
+/* Boot file size in blocks as reported by the DHCP server */
+extern u32     net_boot_file_expected_size_in_blocks;
 
 #if defined(CONFIG_CMD_DNS)
 extern char *NetDNSResolve;            /* The host to resolve  */
@@ -513,7 +517,7 @@ extern char *NetDNSenvvar;          /* the env var to put the ip into */
 #endif
 
 #if defined(CONFIG_CMD_PING)
-extern IPaddr_t        NetPingIP;                      /* the ip address to ping */
+extern struct in_addr net_ping_ip;     /* the ip address to ping */
 #endif
 
 #if defined(CONFIG_CMD_CDP)
@@ -533,12 +537,12 @@ static inline int is_cdp_packet(const uchar *et_addr)
 #endif
 
 #if defined(CONFIG_CMD_SNTP)
-extern IPaddr_t        NetNtpServerIP;                 /* the ip address to NTP */
+extern struct in_addr  net_ntp_server;         /* the ip address to NTP */
 extern int NetTimeOffset;                      /* offset time from UTC */
 #endif
 
 #if defined(CONFIG_MCAST_TFTP)
-extern IPaddr_t Mcast_addr;
+extern struct in_addr net_mcast_addr;
 #endif
 
 /* Initialize the network adapter */
@@ -559,8 +563,8 @@ int NetSetEther(uchar *, uchar *, uint);
 int net_update_ether(struct ethernet_hdr *et, uchar *addr, uint prot);
 
 /* Set IP header */
-void net_set_ip_header(uchar *pkt, IPaddr_t dest, IPaddr_t source);
-void net_set_udp_header(uchar *pkt, IPaddr_t dest, int dport,
+void net_set_ip_header(uchar *pkt, struct in_addr dest, struct in_addr source);
+void net_set_udp_header(uchar *pkt, struct in_addr dest, int dport,
                                int sport, int len);
 
 /**
@@ -633,7 +637,7 @@ static inline void NetSendPacket(uchar *pkt, int len)
  * @param sport Source UDP port
  * @param payload_len Length of data after the UDP header
  */
-int NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport,
+int NetSendUDPPacket(uchar *ether, struct in_addr dest, int dport,
                        int sport, int payload_len);
 
 #ifndef CONFIG_DM_ETH
@@ -644,7 +648,7 @@ void net_process_received_packet(uchar *in_packet, int len);
 
 #ifdef CONFIG_NETCONSOLE
 void NcStart(void);
-int nc_input_packet(uchar *pkt, IPaddr_t src_ip, unsigned dest_port,
+int nc_input_packet(uchar *pkt, struct in_addr src_ip, unsigned dest_port,
        unsigned src_port, unsigned len);
 #endif
 
@@ -685,9 +689,9 @@ void net_auto_load(void);
  * footprint in our tests.
  */
 /* return IP *in network byteorder* */
-static inline IPaddr_t NetReadIP(void *from)
+static inline struct in_addr net_read_ip(void *from)
 {
-       IPaddr_t ip;
+       struct in_addr ip;
 
        memcpy((void *)&ip, (void *)from, sizeof(ip));
        return ip;
@@ -703,15 +707,15 @@ static inline ulong NetReadLong(ulong *from)
 }
 
 /* write IP *in network byteorder* */
-static inline void NetWriteIP(void *to, IPaddr_t ip)
+static inline void net_write_ip(void *to, struct in_addr ip)
 {
        memcpy(to, (void *)&ip, sizeof(ip));
 }
 
 /* copy IP */
-static inline void NetCopyIP(void *to, void *from)
+static inline void net_copy_ip(void *to, void *from)
 {
-       memcpy((void *)to, from, sizeof(IPaddr_t));
+       memcpy((void *)to, from, sizeof(struct in_addr));
 }
 
 /* copy ulong */
@@ -791,10 +795,10 @@ static inline void eth_random_addr(uchar *addr)
 }
 
 /* Convert an IP address to a string */
-void ip_to_string(IPaddr_t x, char *s);
+void ip_to_string(struct in_addr x, char *s);
 
 /* Convert a string to ip address */
-IPaddr_t string_to_ip(const char *s);
+struct in_addr string_to_ip(const char *s);
 
 /* Convert a VLAN id to a string */
 void VLAN_to_string(ushort x, char *s);
index 68f480d7ebb84497fb21cfdebea389a5a26335e5..72d42f998a164e61b0d0c06d916bd65269dd58ab 100644 (file)
@@ -275,7 +275,7 @@ typedef struct {
 
 /* Socket/connection information */
 struct sockaddr_in {
-       IPaddr_t sin_addr;
+       struct in_addr sin_addr;
        unsigned short sin_port;
        unsigned short sin_family;
        short          sin_len;
@@ -304,7 +304,7 @@ typedef struct {
        struct sockaddr_in srvAddrSend;
        struct sockaddr_in srvAddrRecv;
 #else
-       IPaddr_t server_ip;
+       struct in_addr server_ip;
 #endif
        int gotJumpingRequest;
        int dataLen;
@@ -441,8 +441,8 @@ typedef enum bootme_state bootme_hand_f(const void *pkt, size_t len);
 
 int bootme_recv_frame(void *buf, size_t len, int timeout);
 int bootme_send_frame(const void *buf, size_t len);
-//void bootme_init(IPaddr_t server_ip);
-int BootMeRequest(IPaddr_t server_ip, const void *buf, size_t len, int timeout);
+//void bootme_init(struct in_addr server_ip);
+int BootMeRequest(struct in_addr server_ip, const void *buf, size_t len, int timeout);
 //int ce_download_handler(const void *buf, size_t len);
 int BootMeDownload(bootme_hand_f *pkt_handler);
 int BootMeDebugStart(bootme_hand_f *pkt_handler);
index 8d66163159c60d706b80c9f37d2594878d456a52..cfae842752414ebb7a24d3ed5229245a114e02da 100644 (file)
 
 #include <common.h>
 
-IPaddr_t string_to_ip(const char *s)
+struct in_addr string_to_ip(const char *s)
 {
-       IPaddr_t addr;
+       struct in_addr addr;
        char *e;
        int i;
 
+       addr.s_addr = 0;
        if (s == NULL)
-               return(0);
+               return addr;
 
-       for (addr=0, i=0; i<4; ++i) {
+       for (addr.s_addr = 0, i = 0; i < 4; ++i) {
                ulong val = s ? simple_strtoul(s, &e, 10) : 0;
-               addr <<= 8;
-               addr |= (val & 0xFF);
+               addr.s_addr <<= 8;
+               addr.s_addr |= (val & 0xFF);
                if (s) {
                        s = (*e) ? e+1 : e;
                }
        }
 
-       return (htonl(addr));
+       addr.s_addr = htonl(addr.s_addr);
+       return addr;
 }
index 21ed31bf742dd3582add21aed5bf1333591d3c0e..4971a53612f2fdb0f42f915eb8b8ee070aac59f1 100644 (file)
--- a/net/arp.c
+++ b/net/arp.c
@@ -27,8 +27,8 @@
 # define ARP_TIMEOUT_COUNT     CONFIG_NET_RETRY_COUNT
 #endif
 
-IPaddr_t       NetArpWaitPacketIP;
-static IPaddr_t        NetArpWaitReplyIP;
+struct in_addr net_arp_wait_packet_ip;
+static struct in_addr net_arp_wait_reply_ip;
 /* MAC address of waiting packet's destination */
 uchar         *NetArpWaitPacketMAC;
 int            NetArpWaitTxPacketSize;
@@ -42,15 +42,15 @@ void ArpInit(void)
 {
        /* XXX problem with bss workaround */
        NetArpWaitPacketMAC = NULL;
-       NetArpWaitPacketIP = 0;
-       NetArpWaitReplyIP = 0;
+       net_arp_wait_packet_ip.s_addr = 0;
+       net_arp_wait_reply_ip.s_addr = 0;
        NetArpWaitTxPacketSize = 0;
        NetArpTxPacket = &NetArpPacketBuf[0] + (PKTALIGN - 1);
        NetArpTxPacket -= (ulong)NetArpTxPacket % PKTALIGN;
 }
 
-void arp_raw_request(IPaddr_t sourceIP, const uchar *targetEther,
-       IPaddr_t targetIP)
+void arp_raw_request(struct in_addr source_ip, const uchar *targetEther,
+       struct in_addr target_ip)
 {
        uchar *pkt;
        struct arp_hdr *arp;
@@ -72,35 +72,35 @@ void arp_raw_request(IPaddr_t sourceIP, const uchar *targetEther,
        arp->ar_op = htons(ARPOP_REQUEST);
 
        memcpy(&arp->ar_sha, NetOurEther, ARP_HLEN);    /* source ET addr */
-       NetWriteIP(&arp->ar_spa, sourceIP);             /* source IP addr */
+       net_write_ip(&arp->ar_spa, source_ip);          /* source IP addr */
        memcpy(&arp->ar_tha, targetEther, ARP_HLEN);    /* target ET addr */
-       NetWriteIP(&arp->ar_tpa, targetIP);             /* target IP addr */
+       net_write_ip(&arp->ar_tpa, target_ip);          /* target IP addr */
 
        NetSendPacket(NetArpTxPacket, eth_hdr_size + ARP_HDR_SIZE);
 }
 
 void ArpRequest(void)
 {
-       if ((NetArpWaitPacketIP & NetOurSubnetMask) !=
-           (NetOurIP & NetOurSubnetMask)) {
-               if (NetOurGatewayIP == 0) {
+       if ((net_arp_wait_packet_ip.s_addr & net_netmask.s_addr) !=
+           (net_ip.s_addr & net_netmask.s_addr)) {
+               if (net_gateway.s_addr == 0) {
                        puts("## Warning: gatewayip needed but not set\n");
-                       NetArpWaitReplyIP = NetArpWaitPacketIP;
+                       net_arp_wait_reply_ip = net_arp_wait_packet_ip;
                } else {
-                       NetArpWaitReplyIP = NetOurGatewayIP;
+                       net_arp_wait_reply_ip = net_gateway;
                }
        } else {
-               NetArpWaitReplyIP = NetArpWaitPacketIP;
+               net_arp_wait_reply_ip = net_arp_wait_packet_ip;
        }
 
-       arp_raw_request(NetOurIP, NetEtherNullAddr, NetArpWaitReplyIP);
+       arp_raw_request(net_ip, NetEtherNullAddr, net_arp_wait_reply_ip);
 }
 
 void ArpTimeoutCheck(void)
 {
        ulong t;
 
-       if (!NetArpWaitPacketIP)
+       if (!net_arp_wait_packet_ip.s_addr)
                return;
 
        t = get_timer(0);
@@ -123,7 +123,7 @@ void ArpTimeoutCheck(void)
 void ArpReceive(struct ethernet_hdr *et, struct ip_udp_hdr *ip, int len)
 {
        struct arp_hdr *arp;
-       IPaddr_t reply_ip_addr;
+       struct in_addr reply_ip_addr;
        uchar *pkt;
        int eth_hdr_size;
 
@@ -152,10 +152,10 @@ void ArpReceive(struct ethernet_hdr *et, struct ip_udp_hdr *ip, int len)
        if (arp->ar_pln != ARP_PLEN)
                return;
 
-       if (NetOurIP == 0)
+       if (net_ip.s_addr == 0)
                return;
 
-       if (NetReadIP(&arp->ar_tpa) != NetOurIP)
+       if (net_read_ip(&arp->ar_tpa).s_addr != net_ip.s_addr)
                return;
 
        switch (ntohs(arp->ar_op)) {
@@ -167,9 +167,9 @@ void ArpReceive(struct ethernet_hdr *et, struct ip_udp_hdr *ip, int len)
                pkt += eth_hdr_size;
                arp->ar_op = htons(ARPOP_REPLY);
                memcpy(&arp->ar_tha, &arp->ar_sha, ARP_HLEN);
-               NetCopyIP(&arp->ar_tpa, &arp->ar_spa);
+               net_copy_ip(&arp->ar_tpa, &arp->ar_spa);
                memcpy(&arp->ar_sha, NetOurEther, ARP_HLEN);
-               NetCopyIP(&arp->ar_spa, &NetOurIP);
+               net_copy_ip(&arp->ar_spa, &net_ip);
 
 #ifdef CONFIG_CMD_LINK_LOCAL
                /*
@@ -180,8 +180,8 @@ void ArpReceive(struct ethernet_hdr *et, struct ip_udp_hdr *ip, int len)
                 *   reply to ARP request so that our reply will overwrite
                 *   the arp-proxy's instead of the other way around.
                 */
-               if ((NetReadIP(&arp->ar_tpa) & NetOurSubnetMask) !=
-                   (NetReadIP(&arp->ar_spa) & NetOurSubnetMask))
+               if ((net_read_ip(&arp->ar_tpa).s_addr & net_netmask.s_addr) !=
+                   (net_read_ip(&arp->ar_spa).s_addr & net_netmask.s_addr))
                        udelay(5000);
 #endif
                NetSendPacket((uchar *)et, eth_hdr_size + ARP_HDR_SIZE);
@@ -189,21 +189,21 @@ void ArpReceive(struct ethernet_hdr *et, struct ip_udp_hdr *ip, int len)
 
        case ARPOP_REPLY:               /* arp reply */
                /* are we waiting for a reply */
-               if (!NetArpWaitPacketIP)
+               if (!net_arp_wait_packet_ip.s_addr)
                        break;
 
 #ifdef CONFIG_KEEP_SERVERADDR
-               if (NetServerIP == NetArpWaitPacketIP) {
+               if (net_server_ip.s_addr == net_arp_wait_packet_ip.s_addr) {
                        char buf[20];
                        sprintf(buf, "%pM", &arp->ar_sha);
                        setenv("serveraddr", buf);
                }
 #endif
 
-               reply_ip_addr = NetReadIP(&arp->ar_spa);
+               reply_ip_addr = net_read_ip(&arp->ar_spa);
 
                /* matched waiting packet's address */
-               if (reply_ip_addr == NetArpWaitReplyIP) {
+               if (reply_ip_addr.s_addr == net_arp_wait_reply_ip.s_addr) {
                        debug_cond(DEBUG_DEV_PKT,
                                "Got ARP REPLY, set eth addr (%pM)\n",
                                arp->ar_data);
@@ -223,7 +223,7 @@ void ArpReceive(struct ethernet_hdr *et, struct ip_udp_hdr *ip, int len)
                        NetSendPacket(NetTxPacket, NetArpWaitTxPacketSize);
 
                        /* no arp request pending now */
-                       NetArpWaitPacketIP = 0;
+                       net_arp_wait_packet_ip.s_addr = 0;
                        NetArpWaitTxPacketSize = 0;
                        NetArpWaitPacketMAC = NULL;
 
index 3a0a13a3720afaf3fd2df112b7235fa8f6dad9ee..718342bcf02b19009aeb138d753a22e8d6f611b1 100644 (file)
--- a/net/arp.h
+++ b/net/arp.h
@@ -14,7 +14,7 @@
 
 #include <common.h>
 
-extern IPaddr_t        NetArpWaitPacketIP;
+extern struct in_addr net_arp_wait_packet_ip;
 /* MAC address of waiting packet's destination */
 extern uchar *NetArpWaitPacketMAC;
 extern int NetArpWaitTxPacketSize;
@@ -23,8 +23,8 @@ extern int NetArpWaitTry;
 
 void ArpInit(void);
 void ArpRequest(void);
-void arp_raw_request(IPaddr_t sourceIP, const uchar *targetEther,
-       IPaddr_t targetIP);
+void arp_raw_request(struct in_addr source_ip, const uchar *targetEther,
+       struct in_addr target_ip);
 void ArpTimeoutCheck(void);
 void ArpReceive(struct ethernet_hdr *et, struct ip_udp_hdr *ip, int len);
 
index 448727201cae94e9f0ad332311ed58c79f43de32..29f86d3ddea91845b35555c2fefadc28c4d539d7 100644 (file)
@@ -33,7 +33,7 @@ static enum bootme_state bootme_state;
 static int bootme_src_port = 0xdeadface;
 static int bootme_dst_port = 0xdeadbeef;
 static uchar bootme_ether[ETH_ALEN];
-static IPaddr_t bootme_ip;
+static struct in_addr bootme_ip;
 static int bootme_timed_out;
 static const char *output_packet; /* used by first send udp */
 static int output_packet_len;
@@ -93,10 +93,10 @@ static inline int env_changed(int *id)
 
 static int env_id;
 
-static int is_broadcast(IPaddr_t ip)
+static int is_broadcast(struct in_addr ip)
 {
-       static IPaddr_t netmask;
-       static IPaddr_t our_ip;
+       static struct in_addr netmask;
+       static struct in_addr our_ip;
 
        return (ip == ~0 ||                             /* 255.255.255.255 */
            ((netmask & our_ip) == (netmask & ip) &&    /* on the same net */
@@ -141,13 +141,13 @@ static int check_net_config(void)
                        memset(bootme_ether, 0, sizeof(bootme_ether));
 
                net_init();
-               NetServerIP = bootme_ip;
+               net_copy_ip(&net_server_ip, &bootme_ip);
        }
        return 0;
 }
 
 static void bootme_wait_arp_handler(uchar *pkt, unsigned dest,
-                               IPaddr_t sip, unsigned src,
+                               struct in_addr sip, unsigned src,
                                unsigned len)
 {
        net_set_state(NETLOOP_SUCCESS); /* got arp reply - quit net loop */
@@ -168,7 +168,7 @@ static inline char next_cursor(char c)
        return 0;
 }
 
-static void bootme_handler(uchar *pkt, unsigned dest_port, IPaddr_t src_ip,
+static void bootme_handler(uchar *pkt, unsigned dest_port, struct in_addr src_ip,
                        unsigned src_port, unsigned len)
 {
        uchar *eth_pkt = pkt;
@@ -202,7 +202,7 @@ static void bootme_handler(uchar *pkt, unsigned dest_port, IPaddr_t src_ip,
                printf("Target MAC address set to %pM\n", bootme_ether);
 
                if (is_broadcast(bootme_ip)) {
-                       NetCopyIP(&bootme_ip, &src_ip);
+                       net_copy_ip(&bootme_ip, &src_ip);
                }
        }
        if (bootme_state == BOOTME_INIT) {
@@ -327,12 +327,12 @@ int bootme_send_frame(const void *buf, size_t len)
        return ret;
 }
 
-static void bootme_init(IPaddr_t server_ip)
+static void bootme_init(struct in_addr server_ip)
 {
        debug("%s@%d: bootme_state: %d -> %d\n", __func__, __LINE__,
                bootme_state, BOOTME_INIT);
        bootme_state = BOOTME_INIT;
-       bootme_ip = server_ip;
+       net_copy_ip(&bootme_ip, &server_ip);
        /* force reconfiguration in check_net_config() */
        env_id = 0;
 }
@@ -374,7 +374,7 @@ int BootMeDebugStart(bootme_hand_f *handler)
        return bootme_state;
 }
 
-int BootMeRequest(IPaddr_t server_ip, const void *buf, size_t len, int timeout)
+int BootMeRequest(struct in_addr server_ip, const void *buf, size_t len, int timeout)
 {
        bootme_init(server_ip);
        bootme_timeout = timeout * 1000;
index 5e835a31ad786ada52102b23907777d662046f3f..fe143201c0f3f509b59219cc67e68e6f50dd3ec8 100644 (file)
@@ -60,9 +60,9 @@ ulong         bootp_timeout;
 #if defined(CONFIG_CMD_DHCP)
 static dhcp_state_t dhcp_state = INIT;
 static unsigned long dhcp_leasetime;
-static IPaddr_t NetDHCPServerIP;
-static void DhcpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
-                       unsigned len);
+static struct in_addr dhcp_server_ip;
+static void dhcp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
+                       unsigned src, unsigned len);
 
 /* For Debug */
 #if 0
@@ -139,25 +139,26 @@ static int BootpCheckPkt(uchar *pkt, unsigned dest, unsigned src, unsigned len)
 static void BootpCopyNetParams(struct Bootp_t *bp)
 {
 #if !defined(CONFIG_BOOTP_SERVERIP)
-       IPaddr_t tmp_ip;
+       struct in_addr tmp_ip;
 
-       NetCopyIP(&tmp_ip, &bp->bp_siaddr);
-       if (tmp_ip != 0)
-               NetCopyIP(&NetServerIP, &bp->bp_siaddr);
+       net_copy_ip(&tmp_ip, &bp->bp_siaddr);
+       if (tmp_ip.s_addr != 0)
+               net_copy_ip(&net_server_ip, &bp->bp_siaddr);
        memcpy(NetServerEther, ((struct ethernet_hdr *)NetRxPacket)->et_src, 6);
        if (strlen(bp->bp_file) > 0)
-               copy_filename(BootFile, bp->bp_file, sizeof(BootFile));
+               copy_filename(net_boot_file_name, bp->bp_file,
+                             sizeof(net_boot_file_name));
 
-       debug("Bootfile: %s\n", BootFile);
+       debug("net_boot_file_name: %s\n", net_boot_file_name);
 
        /* Propagate to environment:
         * don't delete exising entry when BOOTP / DHCP reply does
         * not contain a new value
         */
-       if (*BootFile)
-               setenv("bootfile", BootFile);
+       if (*net_boot_file_name)
+               setenv("bootfile", net_boot_file_name);
 #endif
-       NetCopyIP(&NetOurIP, &bp->bp_yiaddr);
+       net_copy_ip(&net_ip, &bp->bp_yiaddr);
 }
 
 static int truncate_sz(const char *name, int maxlen, int curlen)
@@ -179,31 +180,33 @@ static void BootpVendorFieldProcess(u8 *ext)
        debug("[BOOTP] Processing extension %d... (%d bytes)\n", *ext,
                *(ext + 1));
 
-       NetBootFileSize = 0;
+       net_boot_file_expected_size_in_blocks = 0;
 
        switch (*ext) {
                /* Fixed length fields */
        case 1:                 /* Subnet mask */
-               if (NetOurSubnetMask == 0)
-                       NetCopyIP(&NetOurSubnetMask, (IPaddr_t *) (ext + 2));
+               if (net_netmask.s_addr == 0)
+                       net_copy_ip(&net_netmask, (struct in_addr *)(ext + 2));
                break;
        case 2:                 /* Time offset - Not yet supported */
                break;
                /* Variable length fields */
        case 3:                 /* Gateways list */
-               if (NetOurGatewayIP == 0)
-                       NetCopyIP(&NetOurGatewayIP, (IPaddr_t *) (ext + 2));
+               if (net_gateway.s_addr == 0)
+                       net_copy_ip(&net_gateway, (struct in_addr *)(ext + 2));
                break;
        case 4:                 /* Time server - Not yet supported */
                break;
        case 5:                 /* IEN-116 name server - Not yet supported */
                break;
        case 6:
-               if (NetOurDNSIP == 0)
-                       NetCopyIP(&NetOurDNSIP, (IPaddr_t *) (ext + 2));
+               if (net_dns_server.s_addr == 0)
+                       net_copy_ip(&net_dns_server,
+                                   (struct in_addr *)(ext + 2));
 #if defined(CONFIG_BOOTP_DNS2)
-               if ((NetOurDNS2IP == 0) && (size > 4))
-                       NetCopyIP(&NetOurDNS2IP, (IPaddr_t *) (ext + 2 + 4));
+               if ((net_dns_server2.s_addr == 0) && (size > 4))
+                       net_copy_ip(&net_dns_server2,
+                                   (struct in_addr *)(ext + 2 + 4));
 #endif
                break;
        case 7:                 /* Log server - Not yet supported */
@@ -226,9 +229,11 @@ static void BootpVendorFieldProcess(u8 *ext)
                break;
        case 13:                /* Boot file size */
                if (size == 2)
-                       NetBootFileSize = ntohs(*(ushort *) (ext + 2));
+                       net_boot_file_expected_size_in_blocks =
+                               ntohs(*(ushort *)(ext + 2));
                else if (size == 4)
-                       NetBootFileSize = ntohl(*(ulong *) (ext + 2));
+                       net_boot_file_expected_size_in_blocks =
+                               ntohl(*(ulong *)(ext + 2));
                break;
        case 14:                /* Merit dump file - Not yet supported */
                break;
@@ -262,7 +267,7 @@ static void BootpVendorFieldProcess(u8 *ext)
                break;
 #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER)
        case 42:        /* NTP server IP */
-               NetCopyIP(&NetNtpServerIP, (IPaddr_t *) (ext + 2));
+               net_copy_ip(&net_ntp_server, (struct in_addr *)(ext + 2));
                break;
 #endif
                /* Application layer fields */
@@ -295,14 +300,15 @@ static void BootpVendorProcess(u8 *ext, int size)
        }
 
        debug("[BOOTP] Received fields:\n");
-       if (NetOurSubnetMask)
-               debug("NetOurSubnetMask : %pI4\n", &NetOurSubnetMask);
+       if (net_netmask.s_addr)
+               debug("net_netmask : %pI4\n", &net_netmask);
 
-       if (NetOurGatewayIP)
-               debug("NetOurGatewayIP  : %pI4", &NetOurGatewayIP);
+       if (net_gateway.s_addr)
+               debug("net_gateway      : %pI4", &net_gateway);
 
-       if (NetBootFileSize)
-               debug("NetBootFileSize : %d\n", NetBootFileSize);
+       if (net_boot_file_expected_size_in_blocks)
+               debug("net_boot_file_expected_size_in_blocks : %d\n",
+                     net_boot_file_expected_size_in_blocks);
 
        if (NetOurHostName[0])
                debug("NetOurHostName  : %s\n", NetOurHostName);
@@ -313,21 +319,17 @@ static void BootpVendorProcess(u8 *ext, int size)
        if (NetOurNISDomain[0])
                debug("NetOurNISDomain : %s\n", NetOurNISDomain);
 
-       if (NetBootFileSize)
-               debug("NetBootFileSize: %d\n", NetBootFileSize);
-
 #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER)
-       if (NetNtpServerIP)
-               debug("NetNtpServerIP : %pI4\n", &NetNtpServerIP);
+       if (net_ntp_server)
+               debug("net_ntp_server : %pI4\n", &net_ntp_server);
 #endif
 }
 
 /*
  *     Handle a BOOTP received packet.
  */
-static void
-BootpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
-            unsigned len)
+static void bootp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
+                         unsigned src, unsigned len)
 {
        struct Bootp_t *bp;
 
@@ -400,8 +402,8 @@ BootpTimeout(void)
  *     Initialize BOOTP extension fields in the request.
  */
 #if defined(CONFIG_CMD_DHCP)
-static int DhcpExtended(u8 *e, int message_type, IPaddr_t ServerID,
-                       IPaddr_t RequestedIP)
+static int dhcp_extended(u8 *e, int message_type, struct in_addr server_ip,
+                       struct in_addr requested_ip)
 {
        u8 *start = e;
        u8 *cnt;
@@ -431,8 +433,8 @@ static int DhcpExtended(u8 *e, int message_type, IPaddr_t ServerID,
        *e++ = (576 - 312 + OPT_FIELD_SIZE) >> 8;
        *e++ = (576 - 312 + OPT_FIELD_SIZE) & 0xff;
 
-       if (ServerID) {
-               int tmp = ntohl(ServerID);
+       if (server_ip.s_addr) {
+               int tmp = ntohl(server_ip.s_addr);
 
                *e++ = 54;      /* ServerID */
                *e++ = 4;
@@ -442,8 +444,8 @@ static int DhcpExtended(u8 *e, int message_type, IPaddr_t ServerID,
                *e++ = tmp & 0xff;
        }
 
-       if (RequestedIP) {
-               int tmp = ntohl(RequestedIP);
+       if (requested_ip.s_addr) {
+               int tmp = ntohl(requested_ip.s_addr);
 
                *e++ = 50;      /* Requested IP */
                *e++ = 4;
@@ -561,7 +563,7 @@ static int DhcpExtended(u8 *e, int message_type, IPaddr_t ServerID,
 /*
  * Warning: no field size check - change CONFIG_BOOTP_* at your own risk!
  */
-static int BootpExtended(u8 *e)
+static int bootp_extended(u8 *e)
 {
        u8 *start = e;
 
@@ -662,6 +664,8 @@ BootpRequest(void)
        ulong rand_ms;
 #endif
        ulong BootpID;
+       struct in_addr zero_ip;
+       struct in_addr bcast_ip;
 
        bootstage_mark_name(BOOTSTAGE_ID_BOOTP_START, "bootp_start");
 #if defined(CONFIG_CMD_DHCP)
@@ -707,18 +711,20 @@ BootpRequest(void)
        bp->bp_hlen = HWL_ETHER;
        bp->bp_hops = 0;
        bp->bp_secs = htons(get_timer(0) / 1000);
-       NetWriteIP(&bp->bp_ciaddr, 0);
-       NetWriteIP(&bp->bp_yiaddr, 0);
-       NetWriteIP(&bp->bp_siaddr, 0);
-       NetWriteIP(&bp->bp_giaddr, 0);
+       zero_ip.s_addr = 0;
+       net_write_ip(&bp->bp_ciaddr, zero_ip);
+       net_write_ip(&bp->bp_yiaddr, zero_ip);
+       net_write_ip(&bp->bp_siaddr, zero_ip);
+       net_write_ip(&bp->bp_giaddr, zero_ip);
        memcpy(bp->bp_chaddr, NetOurEther, 6);
-       copy_filename(bp->bp_file, BootFile, sizeof(bp->bp_file));
+       copy_filename(bp->bp_file, net_boot_file_name, sizeof(bp->bp_file));
 
        /* Request additional information from the BOOTP/DHCP server */
 #if defined(CONFIG_CMD_DHCP)
-       extlen = DhcpExtended((u8 *)bp->bp_vend, DHCP_DISCOVER, 0, 0);
+       extlen = dhcp_extended((u8 *)bp->bp_vend, DHCP_DISCOVER, zero_ip,
+                              zero_ip);
 #else
-       extlen = BootpExtended((u8 *)bp->bp_vend);
+       extlen = bootp_extended((u8 *)bp->bp_vend);
 #endif
 
        /*
@@ -744,14 +750,15 @@ BootpRequest(void)
         */
        iplen = BOOTP_HDR_SIZE - OPT_FIELD_SIZE + extlen;
        pktlen = eth_hdr_size + IP_UDP_HDR_SIZE + iplen;
-       net_set_udp_header(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen);
+       bcast_ip.s_addr = 0xFFFFFFFFL;
+       net_set_udp_header(iphdr, bcast_ip, PORT_BOOTPS, PORT_BOOTPC, iplen);
        NetSetTimeout(bootp_timeout, BootpTimeout);
 
 #if defined(CONFIG_CMD_DHCP)
        dhcp_state = SELECTING;
-       net_set_udp_handler(DhcpHandler);
+       net_set_udp_handler(dhcp_handler);
 #else
-       net_set_udp_handler(BootpHandler);
+       net_set_udp_handler(bootp_handler);
 #endif
        NetSendPacket(NetTxPacket, pktlen);
 }
@@ -769,7 +776,7 @@ static void DhcpOptionsProcess(uchar *popt, struct Bootp_t *bp)
                oplen = *(popt + 1);
                switch (*popt) {
                case 1:
-                       NetCopyIP(&NetOurSubnetMask, (popt + 2));
+                       net_copy_ip(&net_netmask, (popt + 2));
                        break;
 #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_TIMEOFFSET)
                case 2:         /* Time offset  */
@@ -779,13 +786,13 @@ static void DhcpOptionsProcess(uchar *popt, struct Bootp_t *bp)
                        break;
 #endif
                case 3:
-                       NetCopyIP(&NetOurGatewayIP, (popt + 2));
+                       net_copy_ip(&net_gateway, (popt + 2));
                        break;
                case 6:
-                       NetCopyIP(&NetOurDNSIP, (popt + 2));
+                       net_copy_ip(&net_dns_server, (popt + 2));
 #if defined(CONFIG_BOOTP_DNS2)
                        if (*(popt + 1) > 4)
-                               NetCopyIP(&NetOurDNS2IP, (popt + 2 + 4));
+                               net_copy_ip(&net_dns_server2, (popt + 2 + 4));
 #endif
                        break;
                case 12:
@@ -806,7 +813,7 @@ static void DhcpOptionsProcess(uchar *popt, struct Bootp_t *bp)
                        break;
 #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER)
                case 42:        /* NTP server IP */
-                       NetCopyIP(&NetNtpServerIP, (popt + 2));
+                       net_copy_ip(&net_ntp_server, (popt + 2));
                        break;
 #endif
                case 51:
@@ -815,7 +822,7 @@ static void DhcpOptionsProcess(uchar *popt, struct Bootp_t *bp)
                case 53:        /* Ignore Message Type Option */
                        break;
                case 54:
-                       NetCopyIP(&NetDHCPServerIP, (popt + 2));
+                       net_copy_ip(&dhcp_server_ip, (popt + 2));
                        break;
                case 58:        /* Ignore Renewal Time Option */
                        break;
@@ -882,7 +889,9 @@ static void DhcpSendRequestPkt(struct Bootp_t *bp_offer)
        struct Bootp_t *bp;
        int pktlen, iplen, extlen;
        int eth_hdr_size;
-       IPaddr_t OfferedIP;
+       struct in_addr offered_ip;
+       struct in_addr zero_ip;
+       struct in_addr bcast_ip;
 
        debug("DhcpSendRequestPkt: Sending DHCPREQUEST\n");
        pkt = NetTxPacket;
@@ -907,7 +916,8 @@ static void DhcpSendRequestPkt(struct Bootp_t *bp_offer)
         * RFC3046 requires Relay Agents to discard packets with
         * nonzero and offered giaddr
         */
-       NetWriteIP(&bp->bp_giaddr, 0);
+       zero_ip.s_addr = 0;
+       net_write_ip(&bp->bp_giaddr, zero_ip);
 
        memcpy(bp->bp_chaddr, NetOurEther, 6);
 
@@ -922,13 +932,14 @@ static void DhcpSendRequestPkt(struct Bootp_t *bp_offer)
         */
 
        /* Copy offered IP into the parameters request list */
-       NetCopyIP(&OfferedIP, &bp_offer->bp_yiaddr);
-       extlen = DhcpExtended((u8 *)bp->bp_vend, DHCP_REQUEST,
-               NetDHCPServerIP, OfferedIP);
+       net_copy_ip(&offered_ip, &bp_offer->bp_yiaddr);
+       extlen = dhcp_extended((u8 *)bp->bp_vend, DHCP_REQUEST,
+               dhcp_server_ip, offered_ip);
 
        iplen = BOOTP_HDR_SIZE - OPT_FIELD_SIZE + extlen;
        pktlen = eth_hdr_size + IP_UDP_HDR_SIZE + iplen;
-       net_set_udp_header(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen);
+       bcast_ip.s_addr = 0xFFFFFFFFL;
+       net_set_udp_header(iphdr, bcast_ip, PORT_BOOTPS, PORT_BOOTPC, iplen);
 
 #ifdef CONFIG_BOOTP_DHCP_REQUEST_DELAY
        udelay(CONFIG_BOOTP_DHCP_REQUEST_DELAY);
@@ -940,9 +951,8 @@ static void DhcpSendRequestPkt(struct Bootp_t *bp_offer)
 /*
  *     Handle DHCP received packets.
  */
-static void
-DhcpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
-           unsigned len)
+static void dhcp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
+                        unsigned src, unsigned len)
 {
        struct Bootp_t *bp = (struct Bootp_t *)pkt;
 
@@ -997,7 +1007,7 @@ DhcpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
                        BootpCopyNetParams(bp);
                        dhcp_state = BOUND;
                        printf("DHCP client bound to address %pI4 (%lu ms)\n",
-                               &NetOurIP, get_timer(bootp_start));
+                               &net_ip, get_timer(bootp_start));
                        bootstage_mark_name(BOOTSTAGE_ID_BOOTP_STOP,
                                "bootp_stop");
 
index 3ffbc51db3b1588855324de3dcd735ad903f3bee..8c591a6d5ba3705c0eedcd39caa2b407d703bf76 100644 (file)
@@ -41,10 +41,10 @@ struct Bootp_t {
        ulong           bp_id;          /* Transaction ID               */
        ushort          bp_secs;        /* Seconds since boot           */
        ushort          bp_spare1;      /* Alignment                    */
-       IPaddr_t        bp_ciaddr;      /* Client IP address            */
-       IPaddr_t        bp_yiaddr;      /* Your (client) IP address     */
-       IPaddr_t        bp_siaddr;      /* Server IP address            */
-       IPaddr_t        bp_giaddr;      /* Gateway IP address           */
+       struct in_addr  bp_ciaddr;      /* Client IP address            */
+       struct in_addr  bp_yiaddr;      /* Your (client) IP address     */
+       struct in_addr  bp_siaddr;      /* Server IP address            */
+       struct in_addr  bp_giaddr;      /* Gateway IP address           */
        uchar           bp_chaddr[16];  /* Client hardware address      */
        char            bp_sname[64];   /* Server host name             */
        char            bp_file[128];   /* Boot file name               */
@@ -59,7 +59,7 @@ struct Bootp_t {
  */
 
 /* bootp.c */
-extern char    BootFile[128];          /* Boot file name               */
+extern ulong   BootpID;                /* ID of cur BOOTP request      */
 extern int     BootpTry;
 
 
index dd45320150452299e2d2adcdfcd96eb84d06c7f7..6f8b1f2596cdbd1bf858be5acbdb4870400438f7 100644 (file)
--- a/net/dns.c
+++ b/net/dns.c
@@ -5,7 +5,7 @@
  * Copyright (c) 2009 Robin Getz <rgetz@blackfin.uclinux.org>
  *
  * This is a simple DNS implementation for U-Boot. It will use the first IP
- * in the DNS response as NetServerIP. This can then be used for any other
+ * in the DNS response as net_server_ip. This can then be used for any other
  * network related activities.
  *
  * The packet handling is partly based on TADNS, original copyrights
@@ -89,8 +89,8 @@ DnsSend(void)
 
        DnsOurPort = random_port();
 
-       NetSendUDPPacket(NetServerEther, NetOurDNSIP, DNS_SERVICE_PORT,
-               DnsOurPort, n);
+       NetSendUDPPacket(NetServerEther, net_dns_server, DNS_SERVICE_PORT,
+                        DnsOurPort, n);
        debug("DNS packet sent\n");
 }
 
@@ -101,15 +101,15 @@ DnsTimeout(void)
        net_set_state(NETLOOP_FAIL);
 }
 
-static void
-DnsHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, unsigned len)
+static void dns_handler(uchar *pkt, unsigned dest, struct in_addr sip,
+                       unsigned src, unsigned len)
 {
        struct header *header;
        const unsigned char *p, *e, *s;
        u16 type, i;
        int found, stop, dlen;
        char IPStr[22];
-       IPaddr_t IPAddress;
+       struct in_addr ip_addr;
 
 
        debug("%s\n", __func__);
@@ -180,10 +180,10 @@ DnsHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, unsigned len)
 
                dlen = get_unaligned_be16(p+10);
                p += 12;
-               memcpy(&IPAddress, p, 4);
+               memcpy(&ip_addr, p, 4);
 
                if (p + dlen <= e) {
-                       ip_to_string(IPAddress, IPStr);
+                       ip_to_string(ip_addr, IPStr);
                        printf("%s\n", IPStr);
                        if (NetDNSenvvar)
                                setenv(NetDNSenvvar, IPStr);
@@ -200,7 +200,7 @@ DnsStart(void)
        debug("%s\n", __func__);
 
        NetSetTimeout(DNS_TIMEOUT, DnsTimeout);
-       net_set_udp_handler(DnsHandler);
+       net_set_udp_handler(dns_handler);
 
        /* Clear a previous MAC address, the server IP might have changed. */
        memset(NetServerEther, 0, sizeof(NetServerEther));
index 05411f1cec5ee72bddd0caa0c8364146bdaa6739..f06fdb27439ce2903ca9fb4f25c74b7d9aea7d69 100644 (file)
--- a/net/eth.c
+++ b/net/eth.c
@@ -66,7 +66,8 @@ static void eth_env_init(void)
 
        s = getenv("bootfile");
        if (s != NULL)
-               copy_filename(BootFile, s, sizeof(BootFile));
+               copy_filename(net_boot_file_name, s,
+                             sizeof(net_boot_file_name));
 }
 
 static int eth_mac_skip(int index)
@@ -768,14 +769,14 @@ int eth_initialize(void)
  * mcast_addr: multicast ipaddr from which multicast Mac is made
  * join: 1=join, 0=leave.
  */
-int eth_mcast_join(IPaddr_t mcast_ip, int join)
+int eth_mcast_join(struct in_addr mcast_ip, int join)
 {
        u8 mcast_mac[6];
        if (!eth_current || !eth_current->mcast)
                return -1;
-       mcast_mac[5] = htonl(mcast_ip) & 0xff;
-       mcast_mac[4] = (htonl(mcast_ip)>>8) & 0xff;
-       mcast_mac[3] = (htonl(mcast_ip)>>16) & 0x7f;
+       mcast_mac[5] = htonl(mcast_ip.s_addr) & 0xff;
+       mcast_mac[4] = (htonl(mcast_ip.s_addr)>>8) & 0xff;
+       mcast_mac[3] = (htonl(mcast_ip.s_addr)>>16) & 0x7f;
        mcast_mac[2] = 0x5e;
        mcast_mac[1] = 0x0;
        mcast_mac[0] = 0x1;
index 4152fae5bacba34c051bf2f877a11d435630325e..6d92c555fb0fa96f5a2409e11277de9ceb220660 100644 (file)
@@ -49,7 +49,7 @@ static enum ll_state_t {
        DISABLED
 } state = DISABLED;
 
-static IPaddr_t ip;
+static struct in_addr ip;
 static int timeout_ms = -1;
 static unsigned deadline_ms;
 static unsigned conflicts;
@@ -64,14 +64,16 @@ static void link_local_timeout(void);
  * Pick a random link local IP address on 169.254/16, except that
  * the first and last 256 addresses are reserved.
  */
-static IPaddr_t pick(void)
+static struct in_addr pick(void)
 {
        unsigned tmp;
+       struct in_addr ip;
 
        do {
                tmp = rand_r(&seed) & IN_CLASSB_HOST;
        } while (tmp > (IN_CLASSB_HOST - 0x0200));
-       return (IPaddr_t) htonl((LINKLOCAL_ADDR + 0x0100) + tmp);
+       ip.s_addr = htonl((LINKLOCAL_ADDR + 0x0100) + tmp);
+       return ip;
 }
 
 /**
@@ -102,16 +104,17 @@ static void configure_wait(void)
 
 void link_local_start(void)
 {
-       ip = getenv_IPaddr("llipaddr");
-       if (ip != 0 && (ntohl(ip) & IN_CLASSB_NET) != LINKLOCAL_ADDR) {
+       ip = getenv_ip("llipaddr");
+       if (ip.s_addr != 0 &&
+           (ntohl(ip.s_addr) & IN_CLASSB_NET) != LINKLOCAL_ADDR) {
                puts("invalid link address");
                net_set_state(NETLOOP_FAIL);
                return;
        }
-       NetOurSubnetMask = IN_CLASSB_NET;
+       net_netmask.s_addr = IN_CLASSB_NET;
 
        seed = seed_mac();
-       if (ip == 0)
+       if (ip.s_addr == 0)
                ip = pick();
 
        state = PROBE;
@@ -131,10 +134,12 @@ static void link_local_timeout(void)
                /* timeouts in the PROBE state mean no conflicting ARP packets
                   have been received, so we can progress through the states */
                if (nprobes < PROBE_NUM) {
+                       struct in_addr zero_ip = {.s_addr = 0};
+
                        nprobes++;
                        debug_cond(DEBUG_LL_STATE, "probe/%u %s@%pI4\n",
                                        nprobes, eth_get_name(), &ip);
-                       arp_raw_request(0, NetEtherNullAddr, ip);
+                       arp_raw_request(zero_ip, NetEtherNullAddr, ip);
                        timeout_ms = PROBE_MIN * 1000;
                        timeout_ms += random_delay_ms(PROBE_MAX - PROBE_MIN);
                } else {
@@ -172,7 +177,7 @@ static void link_local_timeout(void)
                        /* Switch to monitor state */
                        state = MONITOR;
                        printf("Successfully assigned %pI4\n", &ip);
-                       NetCopyIP(&NetOurIP, &ip);
+                       net_copy_ip(&net_ip, &ip);
                        ready = 1;
                        conflicts = 0;
                        timeout_ms = -1;
@@ -206,7 +211,7 @@ void link_local_receive_arp(struct arp_hdr *arp, int len)
 {
        int source_ip_conflict;
        int target_ip_conflict;
-       IPaddr_t null_ip = 0;
+       struct in_addr null_ip = {.s_addr = 0};
 
        if (state == DISABLED)
                return;
@@ -322,7 +327,7 @@ void link_local_receive_arp(struct arp_hdr *arp, int len)
                        state = PROBE;
                        debug("defend conflict -- starting over\n");
                        ready = 0;
-                       NetOurIP = 0;
+                       net_ip.s_addr = 0;
 
                        /* restart the whole protocol */
                        ip = pick();
index 153d52ebdb0d65f48ec6c20d2236e67240d52ab7..fcab1ef9a3c2e1088e00ae59c1de27ce50d94439 100644 (file)
--- a/net/net.c
+++ b/net/net.c
@@ -112,14 +112,14 @@ DECLARE_GLOBAL_DATA_PTR;
 /** BOOTP EXTENTIONS **/
 
 /* Our subnet mask (0=unknown) */
-IPaddr_t       NetOurSubnetMask;
+struct in_addr net_netmask;
 /* Our gateways IP address */
-IPaddr_t       NetOurGatewayIP;
+struct in_addr net_gateway;
 /* Our DNS IP address */
-IPaddr_t       NetOurDNSIP;
+struct in_addr net_dns_server;
 #if defined(CONFIG_BOOTP_DNS2)
 /* Our 2nd DNS IP address */
-IPaddr_t       NetOurDNS2IP;
+struct in_addr net_dns_server2;
 #endif
 /* Our NIS domain */
 char           NetOurNISDomain[32] = {0,};
@@ -127,25 +127,21 @@ char              NetOurNISDomain[32] = {0,};
 char           NetOurHostName[32] = {0,};
 /* Our bootpath */
 char           NetOurRootPath[64] = {0,};
-/* Our bootfile size in blocks */
-ushort         NetBootFileSize;
 
 #ifdef CONFIG_MCAST_TFTP       /* Multicast TFTP */
-IPaddr_t Mcast_addr;
+struct in_addr net_mcast_addr;
 #endif
 
 /** END OF BOOTP EXTENTIONS **/
 
-/* The actual transferred size of the bootfile (in bytes) */
-ulong          NetBootFileXferSize;
 /* Our ethernet address */
 uchar          NetOurEther[6];
 /* Boot server enet address */
 uchar          NetServerEther[6];
 /* Our IP addr (0 = unknown) */
-IPaddr_t       NetOurIP;
+struct in_addr net_ip;
 /* Server IP addr (0 = unknown) */
-IPaddr_t       NetServerIP;
+struct in_addr net_server_ip;
 /* Current receive packet */
 uchar *NetRxPacket;
 /* Current rx packet length */
@@ -174,11 +170,15 @@ ushort            NetOurVLAN = 0xFFFF;
 ushort         NetOurNativeVLAN = 0xFFFF;
 
 /* Boot File name */
-char           BootFile[128];
+char net_boot_file_name[128];
+/* The actual transferred size of the bootfile (in bytes) */
+u32 net_boot_file_size;
+/* Boot file size in blocks as reported by the DHCP server */
+u32 net_boot_file_expected_size_in_blocks;
 
 #if defined(CONFIG_CMD_SNTP)
 /* NTP server IP address */
-IPaddr_t       NetNtpServerIP;
+struct in_addr net_ntp_server;
 /* offset time from UTC */
 int            NetTimeOffset;
 #endif
@@ -222,7 +222,8 @@ static int on_bootfile(const char *name, const char *value, enum env_op op,
        switch (op) {
        case env_op_create:
        case env_op_overwrite:
-               copy_filename(BootFile, value, sizeof(BootFile));
+               copy_filename(net_boot_file_name, value,
+                             sizeof(net_boot_file_name));
                break;
        default:
                break;
@@ -267,14 +268,14 @@ static void NetInitLoop(void)
 
        /* update only when the environment has changed */
        if (env_changed_id != env_id) {
-               NetOurIP = getenv_IPaddr("ipaddr");
-               NetOurGatewayIP = getenv_IPaddr("gatewayip");
-               NetOurSubnetMask = getenv_IPaddr("netmask");
-               NetServerIP = getenv_IPaddr("serverip");
+               net_ip = getenv_ip("ipaddr");
+               net_gateway = getenv_ip("gatewayip");
+               net_netmask = getenv_ip("netmask");
+               net_server_ip = getenv_ip("serverip");
                NetOurNativeVLAN = getenv_VLAN("nvlan");
                NetOurVLAN = getenv_VLAN("vlan");
 #if defined(CONFIG_CMD_DNS)
-               NetOurDNSIP = getenv_IPaddr("dnsip");
+               net_dns_server = getenv_ip("dnsip");
 #endif
                env_changed_id = env_id;
        }
@@ -380,7 +381,7 @@ restart:
 
        case 0:
                NetDevExists = 1;
-               NetBootFileXferSize = 0;
+               net_boot_file_size = 0;
                switch (protocol) {
                case TFTPGET:
 #ifdef CONFIG_CMD_TFTPPUT
@@ -397,21 +398,21 @@ restart:
 #if defined(CONFIG_CMD_DHCP)
                case DHCP:
                        BootpReset();
-                       NetOurIP = 0;
+                       net_ip.s_addr = 0;
                        DhcpRequest();          /* Basically same as BOOTP */
                        break;
 #endif
 
                case BOOTP:
                        BootpReset();
-                       NetOurIP = 0;
+                       net_ip.s_addr = 0;
                        BootpRequest();
                        break;
 
 #if defined(CONFIG_CMD_RARP)
                case RARP:
                        RarpTry = 0;
-                       NetOurIP = 0;
+                       net_ip.s_addr = 0;
                        RarpRequest();
                        break;
 #endif
@@ -501,7 +502,7 @@ restart:
                 */
                if (ctrlc()) {
                        /* cancel any ARP that may not have completed */
-                       NetArpWaitPacketIP = 0;
+                       net_arp_wait_packet_ip.s_addr = 0;
 
                        net_cleanup_loop();
                        eth_halt();
@@ -556,11 +557,10 @@ restart:
 
                case NETLOOP_SUCCESS:
                        net_cleanup_loop();
-                       if (NetBootFileXferSize > 0) {
-                               printf("Bytes transferred = %ld (%lx hex)\n",
-                                       NetBootFileXferSize,
-                                       NetBootFileXferSize);
-                               setenv_hex("filesize", NetBootFileXferSize);
+                       if (net_boot_file_size > 0) {
+                               printf("Bytes transferred = %d (%x hex)\n",
+                                      net_boot_file_size, net_boot_file_size);
+                               setenv_hex("filesize", net_boot_file_size);
                                setenv_hex("fileaddr", load_addr);
                        }
                        if (protocol != NETCONS) {
@@ -571,7 +571,7 @@ restart:
 
                        eth_set_last_protocol(protocol);
 
-                       ret = NetBootFileXferSize;
+                       ret = net_boot_file_size;
                        debug_cond(DEBUG_INT_STATE, "--- NetLoop Success!\n");
                        goto done;
 
@@ -666,7 +666,7 @@ int NetStartAgain(void)
  */
 
 static void dummy_handler(uchar *pkt, unsigned dport,
-                       IPaddr_t sip, unsigned sport,
+                       struct in_addr sip, unsigned sport,
                        unsigned len)
 {
 }
@@ -722,7 +722,7 @@ NetSetTimeout(ulong iv, thand_f *f)
        }
 }
 
-int NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport,
+int NetSendUDPPacket(uchar *ether, struct in_addr dest, int dport, int sport,
                int payload_len)
 {
        uchar *pkt;
@@ -735,11 +735,11 @@ int NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport,
                return -1;
 
        /* convert to new style broadcast */
-       if (dest == 0)
-               dest = 0xFFFFFFFF;
+       if (dest.s_addr == 0)
+               dest.s_addr = 0xFFFFFFFF;
 
        /* if broadcast, make the ether address a broadcast and don't do ARP */
-       if (dest == 0xFFFFFFFF)
+       if (dest.s_addr == 0xFFFFFFFF)
                ether = NetBcastAddr;
 
        pkt = (uchar *)NetTxPacket;
@@ -754,7 +754,7 @@ int NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport,
                debug_cond(DEBUG_DEV_PKT, "sending ARP for %pI4\n", &dest);
 
                /* save the ip and eth addr for the packet to send after arp */
-               NetArpWaitPacketIP = dest;
+               net_arp_wait_packet_ip = dest;
                NetArpWaitPacketMAC = ether;
 
                /* size of the waiting packet */
@@ -952,7 +952,7 @@ static inline struct ip_udp_hdr *NetDefragment(struct ip_udp_hdr *ip, int *lenp)
  * @parma ip   IP packet containing the ICMP
  */
 static void receive_icmp(struct ip_udp_hdr *ip, int len,
-                       IPaddr_t src_ip, struct ethernet_hdr *et)
+                       struct in_addr src_ip, struct ethernet_hdr *et)
 {
        struct icmp_hdr *icmph = (struct icmp_hdr *)&ip->udp_src;
 
@@ -981,8 +981,8 @@ void net_process_received_packet(uchar *in_packet, int len)
 {
        struct ethernet_hdr *et;
        struct ip_udp_hdr *ip;
-       IPaddr_t dst_ip;
-       IPaddr_t src_ip;
+       struct in_addr dst_ip;
+       struct in_addr src_ip;
        int eth_proto;
 #if defined(CONFIG_CMD_CDP)
        int iscdp;
@@ -1118,15 +1118,16 @@ void net_process_received_packet(uchar *in_packet, int len)
                        return;
                }
                /* If it is not for us, ignore it */
-               dst_ip = NetReadIP(&ip->ip_dst);
-               if (NetOurIP && dst_ip != NetOurIP && dst_ip != 0xFFFFFFFF) {
+               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 (Mcast_addr != dst_ip)
+                       if (net_mcast_addr != dst_ip)
 #endif
                                return;
                }
                /* Read source IP address for later use */
-               src_ip = NetReadIP(&ip->ip_src);
+               src_ip = net_read_ip(&ip->ip_src);
                /*
                 * The function returns the unchanged packet if it's not
                 * a fragment, and either the complete packet or NULL if
@@ -1175,10 +1176,10 @@ void net_process_received_packet(uchar *in_packet, int len)
 
                        xsum  = ip->ip_p;
                        xsum += (ntohs(ip->udp_len));
-                       xsum += (ntohl(ip->ip_src) >> 16) & 0x0000ffff;
-                       xsum += (ntohl(ip->ip_src) >>  0) & 0x0000ffff;
-                       xsum += (ntohl(ip->ip_dst) >> 16) & 0x0000ffff;
-                       xsum += (ntohl(ip->ip_dst) >>  0) & 0x0000ffff;
+                       xsum += (ntohl(ip->ip_src.s_addr) >> 16) & 0x0000ffff;
+                       xsum += (ntohl(ip->ip_src.s_addr) >>  0) & 0x0000ffff;
+                       xsum += (ntohl(ip->ip_dst.s_addr) >> 16) & 0x0000ffff;
+                       xsum += (ntohl(ip->ip_dst.s_addr) >>  0) & 0x0000ffff;
 
                        sumlen = ntohs(ip->udp_len);
                        sumptr = (ushort *) &(ip->udp_src);
@@ -1237,7 +1238,7 @@ static int net_check_prereq(enum proto_t protocol)
        switch (protocol) {
 #if defined(CONFIG_CMD_PING)
        case PING:
-               if (NetPingIP == 0) {
+               if (net_ping_ip.s_addr == 0) {
                        puts("*** ERROR: ping address not given\n");
                        return 1;
                }
@@ -1245,7 +1246,7 @@ static int net_check_prereq(enum proto_t protocol)
 #endif
 #if defined(CONFIG_CMD_SNTP)
        case SNTP:
-               if (NetNtpServerIP == 0) {
+               if (net_ntp_server.s_addr == 0) {
                        puts("*** ERROR: NTP server address not given\n");
                        return 1;
                }
@@ -1253,7 +1254,7 @@ static int net_check_prereq(enum proto_t protocol)
 #endif
 #if defined(CONFIG_CMD_DNS)
        case DNS:
-               if (NetOurDNSIP == 0) {
+               if (net_dns_server.s_addr == 0) {
                        puts("*** ERROR: DNS server address not given\n");
                        return 1;
                }
@@ -1264,7 +1265,7 @@ static int net_check_prereq(enum proto_t protocol)
 #endif
        case TFTPGET:
        case TFTPPUT:
-               if (NetServerIP == 0) {
+               if (net_server_ip.s_addr == 0) {
                        puts("*** ERROR: `serverip' not set\n");
                        return 1;
                }
@@ -1277,7 +1278,7 @@ common:
        case BOOTME:
        case NETCONS:
        case TFTPSRV:
-               if (NetOurIP == 0) {
+               if (net_ip.s_addr == 0) {
                        puts("*** ERROR: `ipaddr' not set\n");
                        return 1;
                }
@@ -1379,7 +1380,7 @@ int net_update_ether(struct ethernet_hdr *et, uchar *addr, uint prot)
        }
 }
 
-void net_set_ip_header(uchar *pkt, IPaddr_t dest, IPaddr_t source)
+void net_set_ip_header(uchar *pkt, struct in_addr dest, struct in_addr source)
 {
        struct ip_udp_hdr *ip = (struct ip_udp_hdr *)pkt;
 
@@ -1395,12 +1396,12 @@ void net_set_ip_header(uchar *pkt, IPaddr_t dest, IPaddr_t source)
        ip->ip_ttl   = 255;
        ip->ip_sum   = 0;
        /* already in network byte order */
-       NetCopyIP((void *)&ip->ip_src, &source);
+       net_copy_ip((void *)&ip->ip_src, &source);
        /* already in network byte order */
-       NetCopyIP((void *)&ip->ip_dst, &dest);
+       net_copy_ip((void *)&ip->ip_dst, &dest);
 }
 
-void net_set_udp_header(uchar *pkt, IPaddr_t dest, int dport, int sport,
+void net_set_udp_header(uchar *pkt, struct in_addr dest, int dport, int sport,
                        int len)
 {
        struct ip_udp_hdr *ip = (struct ip_udp_hdr *)pkt;
@@ -1413,7 +1414,7 @@ void net_set_udp_header(uchar *pkt, IPaddr_t dest, int dport, int sport,
        if (len & 1)
                pkt[IP_UDP_HDR_SIZE + len] = 0;
 
-       net_set_ip_header(pkt, dest, NetOurIP);
+       net_set_ip_header(pkt, dest, net_ip);
        ip->ip_len   = htons(IP_UDP_HDR_SIZE + len);
        ip->ip_p     = IPPROTO_UDP;
        ip->ip_sum   = compute_ip_checksum(ip, IP_HDR_SIZE);
@@ -1450,13 +1451,14 @@ unsigned int random_port(void)
 }
 #endif
 
-void ip_to_string(IPaddr_t x, char *s)
+void ip_to_string(struct in_addr x, char *s)
 {
-       x = ntohl(x);
+       x.s_addr = ntohl(x.s_addr);
        sprintf(s, "%d.%d.%d.%d",
-               (int) ((x >> 24) & 0xff),
-               (int) ((x >> 16) & 0xff),
-               (int) ((x >> 8) & 0xff), (int) ((x >> 0) & 0xff)
+               (int) ((x.s_addr >> 24) & 0xff),
+               (int) ((x.s_addr >> 16) & 0xff),
+               (int) ((x.s_addr >> 8) & 0xff),
+               (int) ((x.s_addr >> 0) & 0xff)
        );
 }
 
index 8e05ae57cd883cc8ac23cd8b1dabb0a1db86d725..1e5c1c350ad25ffc7948d66a505d0f4026734293 100644 (file)
--- a/net/nfs.c
+++ b/net/nfs.c
@@ -51,7 +51,7 @@ static char dirfh[NFS_FHSIZE];        /* file handle of directory */
 static char filefh[NFS_FHSIZE]; /* file handle of kernel image */
 
 static enum net_loop_state nfs_download_state;
-static IPaddr_t NfsServerIP;
+static struct in_addr nfs_server_ip;
 static int     NfsSrvMountPort;
 static int     NfsSrvNfsPort;
 static int     NfsOurPort;
@@ -100,8 +100,8 @@ store_block(uchar *src, unsigned offset, unsigned len)
                unmap_sysmem(ptr);
        }
 
-       if (NetBootFileXferSize < (offset+len))
-               NetBootFileXferSize = newsize;
+       if (net_boot_file_size < (offset + len))
+               net_boot_file_size = newsize;
        return 0;
 }
 
@@ -211,8 +211,8 @@ rpc_req(int rpc_prog, int rpc_proc, uint32_t *data, int datalen)
        else
                sport = NfsSrvNfsPort;
 
-       NetSendUDPPacket(NetServerEther, NfsServerIP, sport, NfsOurPort,
-               pktlen);
+       NetSendUDPPacket(NetServerEther, nfs_server_ip, sport, NfsOurPort,
+                        pktlen);
 }
 
 /**************************************************************************
@@ -600,8 +600,8 @@ NfsTimeout(void)
        }
 }
 
-static void
-NfsHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, unsigned len)
+static void nfs_handler(uchar *pkt, unsigned dest, struct in_addr sip,
+                       unsigned src, unsigned len)
 {
        int rlen;
        int reply;
@@ -715,7 +715,7 @@ NfsStart(void)
        debug("%s\n", __func__);
        nfs_download_state = NETLOOP_FAIL;
 
-       NfsServerIP = NetServerIP;
+       nfs_server_ip = net_server_ip;
        nfs_path = (char *)nfs_path_buff;
 
        if (nfs_path == NULL) {
@@ -724,27 +724,27 @@ NfsStart(void)
                return;
        }
 
-       if (BootFile[0] == '\0') {
+       if (net_boot_file_name[0] == '\0') {
                sprintf(default_filename, "/nfsroot/%02X%02X%02X%02X.img",
-                       NetOurIP & 0xFF,
-                       (NetOurIP >>  8) & 0xFF,
-                       (NetOurIP >> 16) & 0xFF,
-                       (NetOurIP >> 24) & 0xFF);
+                       net_ip.s_addr & 0xFF,
+                       (net_ip.s_addr >>  8) & 0xFF,
+                       (net_ip.s_addr >> 16) & 0xFF,
+                       (net_ip.s_addr >> 24) & 0xFF);
                strcpy(nfs_path, default_filename);
 
                printf("*** Warning: no boot file name; using '%s'\n",
                        nfs_path);
        } else {
-               char *p = BootFile;
+               char *p = net_boot_file_name;
 
                p = strchr(p, ':');
 
                if (p != NULL) {
-                       NfsServerIP = string_to_ip(BootFile);
+                       nfs_server_ip = string_to_ip(net_boot_file_name);
                        ++p;
                        strcpy(nfs_path, p);
                } else {
-                       strcpy(nfs_path, BootFile);
+                       strcpy(nfs_path, net_boot_file_name);
                }
        }
 
@@ -753,29 +753,32 @@ NfsStart(void)
 
        printf("Using %s device\n", eth_get_name());
 
-       printf("File transfer via NFS from server %pI4"
-               "; our IP address is %pI4", &NfsServerIP, &NetOurIP);
+       printf("File transfer via NFS from server %pI4; our IP address is %pI4",
+              &nfs_server_ip, &net_ip);
 
        /* Check if we need to send across this subnet */
-       if (NetOurGatewayIP && NetOurSubnetMask) {
-               IPaddr_t OurNet     = NetOurIP    & NetOurSubnetMask;
-               IPaddr_t ServerNet  = NetServerIP & NetOurSubnetMask;
+       if (net_gateway.s_addr && net_netmask.s_addr) {
+               struct in_addr our_net;
+               struct in_addr server_net;
 
-               if (OurNet != ServerNet)
+               our_net.s_addr = net_ip.s_addr & net_netmask.s_addr;
+               server_net.s_addr = net_server_ip.s_addr & net_netmask.s_addr;
+               if (our_net.s_addr != server_net.s_addr)
                        printf("; sending through gateway %pI4",
-                               &NetOurGatewayIP);
+                               &net_gateway);
        }
        printf("\nFilename '%s/%s'.", nfs_path, nfs_filename);
 
-       if (NetBootFileSize) {
-               printf(" Size is 0x%x Bytes = ", NetBootFileSize<<9);
-               print_size(NetBootFileSize<<9, "");
+       if (net_boot_file_expected_size_in_blocks) {
+               printf(" Size is 0x%x Bytes = ",
+                      net_boot_file_expected_size_in_blocks << 9);
+               print_size(net_boot_file_expected_size_in_blocks << 9, "");
        }
        printf("\nLoad address: 0x%lx\n"
                "Loading: *\b", load_addr);
 
        NetSetTimeout(nfs_timeout, NfsTimeout);
-       net_set_udp_handler(NfsHandler);
+       net_set_udp_handler(nfs_handler);
 
        NfsTimeoutCount = 0;
        NfsState = STATE_PRCLOOKUP_PROG_MOUNT_REQ;
index 366f51825f9ecbff62354eeae1aeb2c49b4aa25b..4918a1cb36d3e2ebc7c888545ee9c0fc3d6c5c98 100644 (file)
@@ -15,9 +15,9 @@
 static ushort PingSeqNo;
 
 /* The ip address to ping */
-IPaddr_t NetPingIP;
+struct in_addr net_ping_ip;
 
-static void set_icmp_header(uchar *pkt, IPaddr_t dest)
+static void set_icmp_header(uchar *pkt, struct in_addr dest)
 {
        /*
         *      Construct an IP and ICMP header.
@@ -25,7 +25,7 @@ static void set_icmp_header(uchar *pkt, IPaddr_t dest)
        struct ip_hdr *ip = (struct ip_hdr *)pkt;
        struct icmp_hdr *icmp = (struct icmp_hdr *)(pkt + IP_HDR_SIZE);
 
-       net_set_ip_header(pkt, dest, NetOurIP);
+       net_set_ip_header(pkt, dest, net_ip);
 
        ip->ip_len   = htons(IP_ICMP_HDR_SIZE);
        ip->ip_p     = IPPROTO_ICMP;
@@ -46,14 +46,14 @@ static int ping_send(void)
 
        /* XXX always send arp request */
 
-       debug_cond(DEBUG_DEV_PKT, "sending ARP for %pI4\n", &NetPingIP);
+       debug_cond(DEBUG_DEV_PKT, "sending ARP for %pI4\n", &net_ping_ip);
 
-       NetArpWaitPacketIP = NetPingIP;
+       net_arp_wait_packet_ip = net_ping_ip;
 
        eth_hdr_size = NetSetEther(NetTxPacket, NetEtherNullAddr, PROT_IP);
        pkt = (uchar *)NetTxPacket + eth_hdr_size;
 
-       set_icmp_header(pkt, NetPingIP);
+       set_icmp_header(pkt, net_ping_ip);
 
        /* size of the waiting packet */
        NetArpWaitTxPacketSize = eth_hdr_size + IP_ICMP_HDR_SIZE;
@@ -82,13 +82,13 @@ void ping_start(void)
 void ping_receive(struct ethernet_hdr *et, struct ip_udp_hdr *ip, int len)
 {
        struct icmp_hdr *icmph = (struct icmp_hdr *)&ip->udp_src;
-       IPaddr_t src_ip;
+       struct in_addr src_ip;
        int eth_hdr_size;
 
        switch (icmph->type) {
        case ICMP_ECHO_REPLY:
-               src_ip = NetReadIP((void *)&ip->ip_src);
-               if (src_ip == NetPingIP)
+               src_ip = net_read_ip((void *)&ip->ip_src);
+               if (src_ip.s_addr == net_ping_ip.s_addr)
                        net_set_state(NETLOOP_SUCCESS);
                return;
        case ICMP_ECHO_REQUEST:
@@ -99,8 +99,8 @@ void ping_receive(struct ethernet_hdr *et, struct ip_udp_hdr *ip, int len)
 
                ip->ip_sum = 0;
                ip->ip_off = 0;
-               NetCopyIP((void *)&ip->ip_dst, &ip->ip_src);
-               NetCopyIP((void *)&ip->ip_src, &NetOurIP);
+               net_copy_ip((void *)&ip->ip_dst, &ip->ip_src);
+               net_copy_ip((void *)&ip->ip_src, &net_ip);
                ip->ip_sum = compute_ip_checksum(ip, IP_HDR_SIZE);
 
                icmph->type = ICMP_ECHO_REPLY;
index a8e085126d4fa27c9837323e5ea3c2e81ac6cdaa..3e1c74cdcc5ee90a433fe9858529e2e7e8849b16 100644 (file)
@@ -43,9 +43,9 @@ void rarp_receive(struct ip_udp_hdr *ip, unsigned len)
 
                puts("invalid RARP header\n");
        } else {
-               NetCopyIP(&NetOurIP, &arp->ar_data[16]);
-               if (NetServerIP == 0)
-                       NetCopyIP(&NetServerIP, &arp->ar_data[6]);
+               net_copy_ip(&net_ip, &arp->ar_data[16]);
+               if (net_server_ip.s_addr == 0)
+                       net_copy_ip(&net_server_ip, &arp->ar_data[6]);
                memcpy(NetServerEther, &arp->ar_data[0], 6);
                debug_cond(DEBUG_DEV_PKT, "Got good RARP\n");
                net_auto_load();
@@ -88,7 +88,7 @@ void RarpRequest(void)
        rarp->ar_pln = 4;
        rarp->ar_op  = htons(RARPOP_REQUEST);
        memcpy(&rarp->ar_data[0],  NetOurEther, 6);     /* source ET addr */
-       memcpy(&rarp->ar_data[6],  &NetOurIP,   4);     /* source IP addr */
+       memcpy(&rarp->ar_data[6],  &net_ip,   4);       /* source IP addr */
        /* dest ET addr = source ET addr ??*/
        memcpy(&rarp->ar_data[10], NetOurEther, 6);
        /* dest IP addr set to broadcast */
index 5de19526e6394b213cd2204d594026d6201a5175..3e45a8342a36ba8e259607e701bc9870a86d6bdd 100644 (file)
@@ -37,8 +37,8 @@ SntpSend(void)
        SntpOurPort = 10000 + (get_timer(0) % 4096);
        sport = NTP_SERVICE_PORT;
 
-       NetSendUDPPacket(NetServerEther, NetNtpServerIP, sport, SntpOurPort,
-               pktlen);
+       NetSendUDPPacket(NetServerEther, net_ntp_server, sport, SntpOurPort,
+                        pktlen);
 }
 
 static void
@@ -49,9 +49,8 @@ SntpTimeout(void)
        return;
 }
 
-static void
-SntpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
-           unsigned len)
+static void sntp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
+                        unsigned src, unsigned len)
 {
        struct sntp_pkt_t *rpktp = (struct sntp_pkt_t *)pkt;
        struct rtc_time tm;
@@ -85,7 +84,7 @@ SntpStart(void)
        debug("%s\n", __func__);
 
        NetSetTimeout(SNTP_TIMEOUT, SntpTimeout);
-       net_set_udp_handler(SntpHandler);
+       net_set_udp_handler(sntp_handler);
        memset(NetServerEther, 0, sizeof(NetServerEther));
 
        SntpSend();
index 51c67be952222200df6a0ab04ef8a08089641d27..bafc35458ef876697e0bbe267b94500c00ca7c76 100644 (file)
@@ -65,7 +65,7 @@ enum {
        TFTP_ERR_FILE_ALREADY_EXISTS = 6,
 };
 
-static IPaddr_t TftpRemoteIP;
+static struct in_addr tftp_remote_ip;
 /* The UDP port at their end */
 static int     TftpRemotePort;
 /* The UDP port at our end */
@@ -146,12 +146,14 @@ static void parse_multicast_oack(char *pkt, int len);
 static void
 mcast_cleanup(void)
 {
-       if (Mcast_addr)
-               eth_mcast_join(Mcast_addr, 0);
+       if (net_mcast_addr)
+               eth_mcast_join(net_mcast_addr, 0);
        if (Bitmap)
                free(Bitmap);
        Bitmap = NULL;
-       Mcast_addr = Multicast = Mcast_port = 0;
+       net_mcast_addr.s_addr = 0;
+       Multicast = 0;
+       Mcast_port = 0;
        TftpEndingBlock = -1;
 }
 
@@ -195,8 +197,8 @@ store_block(int block, uchar *src, unsigned len)
                ext2_set_bit(block, Bitmap);
 #endif
 
-       if (NetBootFileXferSize < newsize)
-               NetBootFileXferSize = newsize;
+       if (net_boot_file_size < newsize)
+               net_boot_file_size = newsize;
 }
 
 /* Clear our state ready for a new transfer */
@@ -225,7 +227,7 @@ static int load_block(unsigned block, uchar *dst, unsigned len)
        ulong offset = ((int)block - 1) * len + TftpBlockWrapOffset;
        ulong tosend = len;
 
-       tosend = min(NetBootFileXferSize - offset, tosend);
+       tosend = min(net_boot_file_size - offset, tosend);
        (void)memcpy(dst, (void *)(save_addr + offset), tosend);
        debug("%s: block=%d, offset=%ld, len=%d, tosend=%ld\n", __func__,
                block, offset, len, tosend);
@@ -309,7 +311,7 @@ static void tftp_complete(void)
        time_start = get_timer(time_start);
        if (time_start > 0) {
                puts("\n\t ");  /* Line up with "Loading: " */
-               print_size(NetBootFileXferSize /
+               print_size(net_boot_file_size /
                        time_start * 1000, "/s");
        }
        puts("\ndone\n");
@@ -359,8 +361,8 @@ TftpSend(void)
                debug("send option \"timeout %s\"\n", (char *)pkt);
                pkt += strlen((char *)pkt) + 1;
 #ifdef CONFIG_TFTP_TSIZE
-               pkt += sprintf((char *)pkt, "tsize%c%lu%c",
-                               0, NetBootFileXferSize, 0);
+               pkt += sprintf((char *)pkt, "tsize%c%u%c",
+                               0, net_boot_file_size, 0);
 #endif
                /* try for more effic. blk size */
                pkt += sprintf((char *)pkt, "blksize%c%d%c",
@@ -433,13 +435,14 @@ TftpSend(void)
                break;
        }
 
-       NetSendUDPPacket(NetServerEther, TftpRemoteIP, TftpRemotePort,
+       NetSendUDPPacket(NetServerEther, tftp_remote_ip, TftpRemotePort,
                         TftpOurPort, len);
 }
 
 #ifdef CONFIG_CMD_TFTPPUT
 static void icmp_handler(unsigned type, unsigned code, unsigned dest,
-                        IPaddr_t sip, unsigned src, uchar *pkt, unsigned len)
+                        struct in_addr sip, unsigned src, uchar *pkt,
+                        unsigned len)
 {
        if (type == ICMP_NOT_REACH && code == ICMP_NOT_REACH_PORT) {
                /* Oh dear the other end has gone away */
@@ -448,9 +451,8 @@ static void icmp_handler(unsigned type, unsigned code, unsigned dest,
 }
 #endif
 
-static void
-TftpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
-           unsigned len)
+static void tftp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
+                        unsigned src, unsigned len)
 {
        __be16 proto;
        __be16 *s;
@@ -507,7 +509,7 @@ TftpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
 #ifdef CONFIG_CMD_TFTPSRV
        case TFTP_WRQ:
                debug("Got WRQ\n");
-               TftpRemoteIP = sip;
+               tftp_remote_ip = sip;
                TftpRemotePort = src;
                TftpOurPort = 1024 + (get_timer(0) % 3072);
                new_transfer();
@@ -717,13 +719,13 @@ void TftpStart(enum proto_t protocol)
        debug("TFTP blocksize = %i, timeout = %ld ms\n",
                TftpBlkSizeOption, TftpTimeoutMSecs);
 
-       TftpRemoteIP = NetServerIP;
-       if (BootFile[0] == '\0') {
+       tftp_remote_ip = net_server_ip;
+       if (net_boot_file_name[0] == '\0') {
                sprintf(default_filename, "%02X%02X%02X%02X.img",
-                       NetOurIP & 0xFF,
-                       (NetOurIP >>  8) & 0xFF,
-                       (NetOurIP >> 16) & 0xFF,
-                       (NetOurIP >> 24) & 0xFF);
+                       net_ip.s_addr & 0xFF,
+                       (net_ip.s_addr >>  8) & 0xFF,
+                       (net_ip.s_addr >> 16) & 0xFF,
+                       (net_ip.s_addr >> 24) & 0xFF);
 
                strncpy(tftp_filename, default_filename, MAX_LEN);
                tftp_filename[MAX_LEN-1] = 0;
@@ -731,13 +733,13 @@ void TftpStart(enum proto_t protocol)
                printf("*** Warning: no boot file name; using '%s'\n",
                        tftp_filename);
        } else {
-               char *p = strchr(BootFile, ':');
+               char *p = strchr(net_boot_file_name, ':');
 
                if (p == NULL) {
-                       strncpy(tftp_filename, BootFile, MAX_LEN);
+                       strncpy(tftp_filename, net_boot_file_name, MAX_LEN);
                        tftp_filename[MAX_LEN-1] = 0;
                } else {
-                       TftpRemoteIP = string_to_ip(BootFile);
+                       tftp_remote_ip = string_to_ip(net_boot_file_name);
                        strncpy(tftp_filename, p + 1, MAX_LEN);
                        tftp_filename[MAX_LEN-1] = 0;
                }
@@ -750,24 +752,26 @@ void TftpStart(enum proto_t protocol)
 #else
                "from",
 #endif
-               &TftpRemoteIP, &NetOurIP);
+               &tftp_remote_ip, &net_ip);
 
        /* Check if we need to send across this subnet */
-       if (NetOurGatewayIP && NetOurSubnetMask) {
-               IPaddr_t OurNet = NetOurIP    & NetOurSubnetMask;
-               IPaddr_t RemoteNet      = TftpRemoteIP & NetOurSubnetMask;
-
-               if (OurNet != RemoteNet)
-                       printf("; sending through gateway %pI4",
-                              &NetOurGatewayIP);
+       if (net_gateway.s_addr && net_netmask.s_addr) {
+               struct in_addr our_net;
+               struct in_addr remote_net;
+
+               our_net.s_addr = net_ip.s_addr & net_netmask.s_addr;
+               remote_net.s_addr = tftp_remote_ip.s_addr & net_netmask.s_addr;
+               if (our_net.s_addr != remote_net.s_addr)
+                       printf("; sending through gateway %pI4", &net_gateway);
        }
        putc('\n');
 
        printf("Filename '%s'.", tftp_filename);
 
-       if (NetBootFileSize) {
-               printf(" Size is 0x%x Bytes = ", NetBootFileSize<<9);
-               print_size(NetBootFileSize<<9, "");
+       if (net_boot_file_expected_size_in_blocks) {
+               printf(" Size is 0x%x Bytes = ",
+                      net_boot_file_expected_size_in_blocks << 9);
+               print_size(net_boot_file_expected_size_in_blocks << 9, "");
        }
 
        putc('\n');
@@ -776,7 +780,7 @@ void TftpStart(enum proto_t protocol)
        if (TftpWriting) {
                printf("Save address: 0x%lx\n", save_addr);
                printf("Save size:    0x%lx\n", save_size);
-               NetBootFileXferSize = save_size;
+               net_boot_file_size = save_size;
                puts("Saving: *\b");
                TftpState = STATE_SEND_WRQ;
                new_transfer();
@@ -792,7 +796,7 @@ void TftpStart(enum proto_t protocol)
        TftpTimeoutCountMax = TftpRRQTimeoutCountMax;
 
        NetSetTimeout(TftpTimeoutMSecs, TftpTimeout);
-       net_set_udp_handler(TftpHandler);
+       net_set_udp_handler(tftp_handler);
 #ifdef CONFIG_CMD_TFTPPUT
        net_set_icmp_handler(icmp_handler);
 #endif
@@ -833,7 +837,7 @@ TftpStartServer(void)
        tftp_filename[0] = 0;
 
        printf("Using %s device\n", eth_get_name());
-       printf("Listening for TFTP transfer on %pI4\n", &NetOurIP);
+       printf("Listening for TFTP transfer on %pI4\n", &net_ip);
        printf("Load address: 0x%lx\n", load_addr);
 
        puts("Loading: *\b");
@@ -854,7 +858,7 @@ TftpStartServer(void)
 #endif
 
        TftpState = STATE_RECV_WRQ;
-       net_set_udp_handler(TftpHandler);
+       net_set_udp_handler(tftp_handler);
 
        /* zero out server ether in case the server ip has changed */
        memset(NetServerEther, 0, 6);
@@ -880,7 +884,7 @@ TftpStartServer(void)
 static void parse_multicast_oack(char *pkt, int len)
 {
        int i;
-       IPaddr_t addr;
+       struct in_addr addr;
        char *mc_adr, *port,  *mc;
 
        mc_adr = port = mc = NULL;
@@ -935,11 +939,11 @@ static void parse_multicast_oack(char *pkt, int len)
                Multicast = 1;
        }
        addr = string_to_ip(mc_adr);
-       if (Mcast_addr != addr) {
-               if (Mcast_addr)
-                       eth_mcast_join(Mcast_addr, 0);
-               Mcast_addr = addr;
-               if (eth_mcast_join(Mcast_addr, 1)) {
+       if (net_mcast_addr.s_addr != addr.s_addr) {
+               if (net_mcast_addr.s_addr)
+                       eth_mcast_join(net_mcast_addr, 0);
+               net_mcast_addr = addr;
+               if (eth_mcast_join(net_mcast_addr, 1)) {
                        printf("Fail to set mcast, revert to TFTP\n");
                        ProhibitMcast = 1;
                        mcast_cleanup();
index 19236705e28c561d6082dc3bbb1f8aa47e7233dd..22fd26e5040ab52bda500cbafd03cc96ed08214c 100644 (file)
@@ -20,7 +20,7 @@ DECLARE_GLOBAL_DATA_PTR;
 
 static int dm_test_eth(struct dm_test_state *dms)
 {
-       NetPingIP = string_to_ip("1.1.2.2");
+       net_ping_ip = string_to_ip("1.1.2.2");
 
        setenv("ethact", "eth@10002000");
        ut_assertok(NetLoop(PING));
@@ -40,7 +40,7 @@ DM_TEST(dm_test_eth, DM_TESTF_SCAN_FDT);
 
 static int dm_test_eth_alias(struct dm_test_state *dms)
 {
-       NetPingIP = string_to_ip("1.1.2.2");
+       net_ping_ip = string_to_ip("1.1.2.2");
        setenv("ethact", "eth0");
        ut_assertok(NetLoop(PING));
        ut_asserteq_str("eth@10002000", getenv("ethact"));
@@ -64,7 +64,7 @@ DM_TEST(dm_test_eth_alias, DM_TESTF_SCAN_FDT);
 
 static int dm_test_eth_prime(struct dm_test_state *dms)
 {
-       NetPingIP = string_to_ip("1.1.2.2");
+       net_ping_ip = string_to_ip("1.1.2.2");
 
        /* Expected to be "eth@10003000" because of ethprime variable */
        setenv("ethact", NULL);
@@ -87,7 +87,7 @@ static int dm_test_eth_rotate(struct dm_test_state *dms)
        char ethaddr[18];
 
        /* Invalidate eth1's MAC address */
-       NetPingIP = string_to_ip("1.1.2.2");
+       net_ping_ip = string_to_ip("1.1.2.2");
        strcpy(ethaddr, getenv("eth1addr"));
        setenv("eth1addr", NULL);
 
@@ -126,7 +126,7 @@ DM_TEST(dm_test_eth_rotate, DM_TESTF_SCAN_FDT);
 
 static int dm_test_net_retry(struct dm_test_state *dms)
 {
-       NetPingIP = string_to_ip("1.1.2.2");
+       net_ping_ip = string_to_ip("1.1.2.2");
 
        /*
         * eth1 is disabled and netretry is yes, so the ping should succeed and