1
0
Fork 0

net: cosmetic: Change IPaddr_t to struct in_addr

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>
utp
Joe Hershberger 2015-04-08 01:41:01 -05:00 committed by Simon Glass
parent 2ea4cfdef6
commit 049a95a775
22 changed files with 362 additions and 336 deletions

View File

@ -114,13 +114,13 @@ static void netboot_update_env(void)
{ {
char tmp[22]; char tmp[22];
if (NetOurGatewayIP) { if (net_gateway.s_addr) {
ip_to_string(NetOurGatewayIP, tmp); ip_to_string(net_gateway, tmp);
setenv("gatewayip", tmp); setenv("gatewayip", tmp);
} }
if (NetOurSubnetMask) { if (net_netmask.s_addr) {
ip_to_string(NetOurSubnetMask, tmp); ip_to_string(net_netmask, tmp);
setenv("netmask", tmp); setenv("netmask", tmp);
} }
@ -130,8 +130,8 @@ static void netboot_update_env(void)
if (NetOurRootPath[0]) if (NetOurRootPath[0])
setenv("rootpath", NetOurRootPath); setenv("rootpath", NetOurRootPath);
if (NetOurIP) { if (net_ip.s_addr) {
ip_to_string(NetOurIP, tmp); ip_to_string(net_ip, tmp);
setenv("ipaddr", tmp); setenv("ipaddr", tmp);
} }
#if !defined(CONFIG_BOOTP_SERVERIP) #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() * Only attempt to change serverip if net/bootp.c:BootpCopyNetParams()
* could have set it * could have set it
*/ */
if (NetServerIP) { if (net_server_ip.s_addr) {
ip_to_string(NetServerIP, tmp); ip_to_string(net_server_ip, tmp);
setenv("serverip", tmp); setenv("serverip", tmp);
} }
#endif #endif
if (NetOurDNSIP) { if (net_dns_server.s_addr) {
ip_to_string(NetOurDNSIP, tmp); ip_to_string(net_dns_server, tmp);
setenv("dnsip", tmp); setenv("dnsip", tmp);
} }
#if defined(CONFIG_BOOTP_DNS2) #if defined(CONFIG_BOOTP_DNS2)
if (NetOurDNS2IP) { if (net_dns_server2.s_addr) {
ip_to_string(NetOurDNS2IP, tmp); ip_to_string(net_dns_server2, tmp);
setenv("dnsip2", tmp); setenv("dnsip2", tmp);
} }
#endif #endif
@ -166,8 +166,8 @@ static void netboot_update_env(void)
#endif #endif
#if defined(CONFIG_CMD_SNTP) \ #if defined(CONFIG_CMD_SNTP) \
&& defined(CONFIG_BOOTP_NTPSERVER) && defined(CONFIG_BOOTP_NTPSERVER)
if (NetNtpServerIP) { if (net_ntp_server.s_addr) {
ip_to_string(NetNtpServerIP, tmp); ip_to_string(net_ntp_server, tmp);
setenv("ntpserverip", tmp); setenv("ntpserverip", tmp);
} }
#endif #endif
@ -260,8 +260,8 @@ static int do_ping(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
if (argc < 2) if (argc < 2)
return CMD_RET_USAGE; return CMD_RET_USAGE;
NetPingIP = string_to_ip(argv[1]); net_ping_ip = string_to_ip(argv[1]);
if (NetPingIP == 0) if (net_ping_ip.s_addr == 0)
return CMD_RET_USAGE; return CMD_RET_USAGE;
if (NetLoop(PING) < 0) { if (NetLoop(PING) < 0) {
@ -331,14 +331,14 @@ int do_sntp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
char *toff; char *toff;
if (argc < 2) { if (argc < 2) {
NetNtpServerIP = getenv_IPaddr("ntpserverip"); net_ntp_server = getenv_ip("ntpserverip");
if (NetNtpServerIP == 0) { if (net_ntp_server.s_addr == 0) {
printf("ntpserverip not set\n"); printf("ntpserverip not set\n");
return CMD_RET_FAILURE; return CMD_RET_FAILURE;
} }
} else { } else {
NetNtpServerIP = string_to_ip(argv[1]); net_ntp_server = string_to_ip(argv[1]);
if (NetNtpServerIP == 0) { if (net_ntp_server.s_addr == 0) {
printf("Bad NTP server IP address\n"); printf("Bad NTP server IP address\n");
return CMD_RET_FAILURE; return CMD_RET_FAILURE;
} }
@ -352,7 +352,7 @@ int do_sntp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
if (NetLoop(SNTP) < 0) { if (NetLoop(SNTP) < 0) {
printf("SNTP failed: host %pI4 not responding\n", printf("SNTP failed: host %pI4 not responding\n",
&NetNtpServerIP); &net_ntp_server);
return CMD_RET_FAILURE; return CMD_RET_FAILURE;
} }
@ -421,14 +421,14 @@ static int do_link_local(cmd_tbl_t *cmdtp, int flag, int argc,
if (NetLoop(LINKLOCAL) < 0) if (NetLoop(LINKLOCAL) < 0)
return CMD_RET_FAILURE; return CMD_RET_FAILURE;
NetOurGatewayIP = 0; net_gateway.s_addr = 0;
ip_to_string(NetOurGatewayIP, tmp); ip_to_string(net_gateway, tmp);
setenv("gatewayip", tmp); setenv("gatewayip", tmp);
ip_to_string(NetOurSubnetMask, tmp); ip_to_string(net_netmask, tmp);
setenv("netmask", tmp); setenv("netmask", tmp);
ip_to_string(NetOurIP, tmp); ip_to_string(net_ip, tmp);
setenv("ipaddr", tmp); setenv("ipaddr", tmp);
setenv("llipaddr", tmp); /* store this for next time */ setenv("llipaddr", tmp); /* store this for next time */

View File

@ -331,7 +331,7 @@ static int pxe_ipaddr_paths(cmd_tbl_t *cmdtp, void *pxefile_addr_r)
char ip_addr[9]; char ip_addr[9];
int mask_pos, err; 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--) { for (mask_pos = 7; mask_pos >= 0; mask_pos--) {
err = get_pxelinux_path(cmdtp, ip_addr, pxefile_addr_r); err = get_pxelinux_path(cmdtp, ip_addr, pxefile_addr_r);

View File

@ -23,7 +23,7 @@ static int input_recursion;
static int output_recursion; static int output_recursion;
static int net_timeout; static int net_timeout;
static uchar nc_ether[6]; /* server enet address */ 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_out_port; /* target output port */
static short nc_in_port; /* source input port */ static short nc_in_port; /* source input port */
static const char *output_packet; /* used by first send udp */ 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; enum proto_t net_loop_last_protocol = BOOTP;
static void nc_wait_arp_handler(uchar *pkt, unsigned dest, static void nc_wait_arp_handler(uchar *pkt, unsigned dest,
IPaddr_t sip, unsigned src, struct in_addr sip, unsigned src,
unsigned len) unsigned len)
{ {
net_set_state(NETLOOP_SUCCESS); /* got arp reply - quit net loop */ net_set_state(NETLOOP_SUCCESS); /* got arp reply - quit net loop */
} }
static void nc_handler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, static void nc_handler(uchar *pkt, unsigned dest, struct in_addr sip,
unsigned len) unsigned src, unsigned len)
{ {
if (input_size) if (input_size)
net_set_state(NETLOOP_SUCCESS); /* got input - quit net loop */ net_set_state(NETLOOP_SUCCESS); /* got input - quit net loop */
@ -53,24 +53,25 @@ static void nc_timeout(void)
net_set_state(NETLOOP_SUCCESS); 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 struct in_addr netmask;
static IPaddr_t our_ip; static struct in_addr our_ip;
static int env_changed_id; static int env_changed_id;
int env_id = get_env_id(); int env_id = get_env_id();
/* update only when the environment has changed */ /* update only when the environment has changed */
if (env_changed_id != env_id) { if (env_changed_id != env_id) {
netmask = getenv_IPaddr("netmask"); netmask = getenv_ip("netmask");
our_ip = getenv_IPaddr("ipaddr"); our_ip = getenv_ip("ipaddr");
env_changed_id = env_id; env_changed_id = env_id;
} }
return (ip == ~0 || /* 255.255.255.255 */ return (ip.s_addr == ~0 || /* 255.255.255.255 (global bcast) */
((netmask & our_ip) == (netmask & ip) && /* on the same net */ ((netmask.s_addr & our_ip.s_addr) ==
(netmask | ip) == ~0)); /* broadcast to our net */ (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) 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 */ /* update only when the environment has changed */
if (env_changed_id != env_id) { if (env_changed_id != env_id) {
if (getenv("ncip")) { if (getenv("ncip")) {
nc_ip = getenv_IPaddr("ncip"); nc_ip = getenv_ip("ncip");
if (!nc_ip) if (!nc_ip.s_addr)
return -1; /* ncip is 0.0.0.0 */ return -1; /* ncip is 0.0.0.0 */
p = strchr(getenv("ncip"), ':'); p = strchr(getenv("ncip"), ':');
if (p != NULL) { if (p != NULL) {
@ -91,7 +92,7 @@ static int refresh_settings_from_env(void)
nc_in_port = nc_out_port; nc_in_port = nc_out_port;
} }
} else } else
nc_ip = ~0; /* ncip is not set, so broadcast */ nc_ip.s_addr = ~0; /* ncip is not set, so broadcast */
p = getenv("ncoutport"); p = getenv("ncoutport");
if (p != NULL) 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) unsigned src_port, unsigned len)
{ {
int end, chunk; 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) if (dest_port != nc_in_port || !len)
return 0; /* not for us */ 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 */ return 0; /* not from our client */
debug_cond(DEBUG_DEV_PKT, "input: \"%*.*s\"\n", len, len, pkt); 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; int inited = 0;
uchar *pkt; uchar *pkt;
uchar *ether; uchar *ether;
IPaddr_t ip; struct in_addr ip;
debug_cond(DEBUG_DEV_PKT, "output: \"%*.*s\"\n", len, len, buf); debug_cond(DEBUG_DEV_PKT, "output: \"%*.*s\"\n", len, len, buf);

View File

@ -16,7 +16,7 @@
DECLARE_GLOBAL_DATA_PTR; DECLARE_GLOBAL_DATA_PTR;
static int reply_arp; static int reply_arp;
static IPaddr_t arp_ip; static struct in_addr arp_ip;
static int sb_eth_raw_start(struct udevice *dev) 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 * localhost works on a higher-level API in Linux than
* ARP packets, so fake it * ARP packets, so fake it
*/ */
arp_ip = NetReadIP(&arp->ar_tpa); arp_ip = net_read_ip(&arp->ar_tpa);
reply_arp = 1; reply_arp = 1;
return 0; return 0;
} }
@ -93,9 +93,9 @@ static int sb_eth_raw_recv(struct udevice *dev, uchar **packetp)
/* Any non-zero MAC address will work */ /* Any non-zero MAC address will work */
memset(&arp->ar_sha, 0x01, ARP_HLEN); memset(&arp->ar_sha, 0x01, ARP_HLEN);
/* Use whatever IP we were looking for (always 127.0.0.1?) */ /* 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); 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; length = ARP_HDR_SIZE;
} else { } else {
/* If local, the Ethernet header won't be included; skip it */ /* If local, the Ethernet header won't be included; skip it */

View File

@ -24,7 +24,7 @@ DECLARE_GLOBAL_DATA_PTR;
*/ */
struct eth_sandbox_priv { struct eth_sandbox_priv {
uchar fake_host_hwaddr[ARP_HLEN]; uchar fake_host_hwaddr[ARP_HLEN];
IPaddr_t fake_host_ipaddr; struct in_addr fake_host_ipaddr;
uchar *recv_packet_buffer; uchar *recv_packet_buffer;
int recv_packet_length; 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; struct arp_hdr *arp_recv;
/* store this as the assumed IP of the fake host */ /* 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 */ /* Formulate a fake response */
eth_recv = (void *)priv->recv_packet_buffer; eth_recv = (void *)priv->recv_packet_buffer;
memcpy(eth_recv->et_dest, eth->et_src, ARP_HLEN); 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); arp_recv->ar_op = htons(ARPOP_REPLY);
memcpy(&arp_recv->ar_sha, priv->fake_host_hwaddr, memcpy(&arp_recv->ar_sha, priv->fake_host_hwaddr,
ARP_HLEN); 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); 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 + priv->recv_packet_length = ETHER_HDR_SIZE +
ARP_HDR_SIZE; ARP_HDR_SIZE;
@ -121,9 +121,9 @@ static int sb_eth_send(struct udevice *dev, void *packet, int length)
ARP_HLEN); ARP_HLEN);
ipr->ip_sum = 0; ipr->ip_sum = 0;
ipr->ip_off = 0; ipr->ip_off = 0;
NetCopyIP((void *)&ipr->ip_dst, &ip->ip_src); net_copy_ip((void *)&ipr->ip_dst, &ip->ip_src);
NetWriteIP((void *)&ipr->ip_src, net_write_ip((void *)&ipr->ip_src,
priv->fake_host_ipaddr); priv->fake_host_ipaddr);
ipr->ip_sum = compute_ip_checksum(ipr, ipr->ip_sum = compute_ip_checksum(ipr,
IP_HDR_SIZE); IP_HDR_SIZE);

View File

@ -826,7 +826,7 @@ int zzip(void *dst, unsigned long *lenp, unsigned char *src,
/* lib/net_utils.c */ /* lib/net_utils.c */
#include <net.h> #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)); return string_to_ip(getenv(var));
} }

View File

@ -39,8 +39,9 @@
#define PKTALIGN ARCH_DMA_MINALIGN #define PKTALIGN ARCH_DMA_MINALIGN
/* IPv4 addresses are always 32 bits in size */ /* IPv4 addresses are always 32 bits in size */
typedef __be32 IPaddr_t; struct in_addr {
__be32 s_addr;
};
/** /**
* An incoming packet handler. * An incoming packet handler.
@ -51,7 +52,7 @@ typedef __be32 IPaddr_t;
* @param len packet length * @param len packet length
*/ */
typedef void rxhand_f(uchar *pkt, unsigned dport, typedef void rxhand_f(uchar *pkt, unsigned dport,
IPaddr_t sip, unsigned sport, struct in_addr sip, unsigned sport,
unsigned len); unsigned len);
/** /**
@ -65,7 +66,7 @@ typedef void rxhand_f(uchar *pkt, unsigned dport,
* @param len packet length * @param len packet length
*/ */
typedef void rxhand_icmp_f(unsigned type, unsigned code, unsigned dport, 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. * 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 */ const char *eth_get_name(void); /* get name of current device */
#ifdef CONFIG_MCAST_TFTP #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); u32 ether_crc(size_t len, unsigned char const *p);
#endif #endif
@ -318,8 +319,8 @@ struct ip_hdr {
uchar ip_ttl; /* time to live */ uchar ip_ttl; /* time to live */
uchar ip_p; /* protocol */ uchar ip_p; /* protocol */
ushort ip_sum; /* checksum */ ushort ip_sum; /* checksum */
IPaddr_t ip_src; /* Source IP address */ struct in_addr ip_src; /* Source IP address */
IPaddr_t ip_dst; /* Destination IP address */ struct in_addr ip_dst; /* Destination IP address */
}; };
#define IP_OFFS 0x1fff /* ip offset *= 8 */ #define IP_OFFS 0x1fff /* ip offset *= 8 */
@ -342,8 +343,8 @@ struct ip_udp_hdr {
uchar ip_ttl; /* time to live */ uchar ip_ttl; /* time to live */
uchar ip_p; /* protocol */ uchar ip_p; /* protocol */
ushort ip_sum; /* checksum */ ushort ip_sum; /* checksum */
IPaddr_t ip_src; /* Source IP address */ struct in_addr ip_src; /* Source IP address */
IPaddr_t ip_dst; /* Destination IP address */ struct in_addr ip_dst; /* Destination IP address */
ushort udp_src; /* UDP source port */ ushort udp_src; /* UDP source port */
ushort udp_dst; /* UDP destination port */ ushort udp_dst; /* UDP destination port */
ushort udp_len; /* Length of UDP packet */ ushort udp_len; /* Length of UDP packet */
@ -458,17 +459,19 @@ struct icmp_hdr {
* *
* Note: * 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). * (big endian).
*/ */
/* net.c */ /* net.c */
/** BOOTP EXTENTIONS **/ /** BOOTP EXTENTIONS **/
extern IPaddr_t NetOurGatewayIP; /* Our gateway IP address */ extern struct in_addr net_gateway; /* Our gateway IP address */
extern IPaddr_t NetOurSubnetMask; /* Our subnet mask (0 = unknown) */ extern struct in_addr net_netmask; /* Our subnet mask (0 = unknown) */
extern IPaddr_t NetOurDNSIP; /* Our Domain Name Server (0 = unknown) */ /* Our Domain Name Server (0 = unknown) */
extern struct in_addr net_dns_server;
#if defined(CONFIG_BOOTP_DNS2) #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 #endif
extern char NetOurNISDomain[32]; /* Our NIS domain */ extern char NetOurNISDomain[32]; /* Our NIS domain */
extern char NetOurHostName[32]; /* Our hostname */ extern char NetOurHostName[32]; /* Our hostname */
@ -478,8 +481,8 @@ extern ushort NetBootFileSize; /* Our boot file size in blocks */
extern ulong NetBootFileXferSize; /* size of bootfile in bytes */ extern ulong NetBootFileXferSize; /* size of bootfile in bytes */
extern uchar NetOurEther[6]; /* Our ethernet address */ extern uchar NetOurEther[6]; /* Our ethernet address */
extern uchar NetServerEther[6]; /* Boot server enet address */ extern uchar NetServerEther[6]; /* Boot server enet address */
extern IPaddr_t NetOurIP; /* Our IP addr (0 = unknown) */ extern struct in_addr net_ip; /* Our IP addr (0 = unknown) */
extern IPaddr_t NetServerIP; /* Server IP addr (0 = unknown) */ extern struct in_addr net_server_ip; /* Server IP addr (0 = unknown) */
extern uchar *NetTxPacket; /* THE transmit packet */ extern uchar *NetTxPacket; /* THE transmit packet */
#ifdef CONFIG_DM_ETH #ifdef CONFIG_DM_ETH
extern uchar *net_rx_packets[PKTBUFSRX]; /* Receive packets */ extern uchar *net_rx_packets[PKTBUFSRX]; /* Receive packets */
@ -513,7 +516,7 @@ extern char *NetDNSenvvar; /* the env var to put the ip into */
#endif #endif
#if defined(CONFIG_CMD_PING) #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 #endif
#if defined(CONFIG_CMD_CDP) #if defined(CONFIG_CMD_CDP)
@ -533,12 +536,12 @@ static inline int is_cdp_packet(const uchar *et_addr)
#endif #endif
#if defined(CONFIG_CMD_SNTP) #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 */ extern int NetTimeOffset; /* offset time from UTC */
#endif #endif
#if defined(CONFIG_MCAST_TFTP) #if defined(CONFIG_MCAST_TFTP)
extern IPaddr_t Mcast_addr; extern struct in_addr net_mcast_addr;
#endif #endif
/* Initialize the network adapter */ /* Initialize the network adapter */
@ -559,8 +562,8 @@ int NetSetEther(uchar *, uchar *, uint);
int net_update_ether(struct ethernet_hdr *et, uchar *addr, uint prot); int net_update_ether(struct ethernet_hdr *et, uchar *addr, uint prot);
/* Set IP header */ /* Set IP header */
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);
void net_set_udp_header(uchar *pkt, IPaddr_t dest, int dport, void net_set_udp_header(uchar *pkt, struct in_addr dest, int dport,
int sport, int len); int sport, int len);
/** /**
@ -633,7 +636,7 @@ static inline void NetSendPacket(uchar *pkt, int len)
* @param sport Source UDP port * @param sport Source UDP port
* @param payload_len Length of data after the UDP header * @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); int sport, int payload_len);
#ifndef CONFIG_DM_ETH #ifndef CONFIG_DM_ETH
@ -644,7 +647,7 @@ void net_process_received_packet(uchar *in_packet, int len);
#ifdef CONFIG_NETCONSOLE #ifdef CONFIG_NETCONSOLE
void NcStart(void); 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); unsigned src_port, unsigned len);
#endif #endif
@ -682,9 +685,9 @@ void net_auto_load(void);
* footprint in our tests. * footprint in our tests.
*/ */
/* return IP *in network byteorder* */ /* 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)); memcpy((void *)&ip, (void *)from, sizeof(ip));
return ip; return ip;
@ -700,15 +703,15 @@ static inline ulong NetReadLong(ulong *from)
} }
/* write IP *in network byteorder* */ /* 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)); memcpy(to, (void *)&ip, sizeof(ip));
} }
/* copy 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 */ /* copy ulong */
@ -788,10 +791,10 @@ static inline void eth_random_addr(uchar *addr)
} }
/* Convert an IP address to a string */ /* 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 */ /* 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 */ /* Convert a VLAN id to a string */
void VLAN_to_string(ushort x, char *s); void VLAN_to_string(ushort x, char *s);

View File

@ -12,23 +12,25 @@
#include <common.h> #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; char *e;
int i; int i;
addr.s_addr = 0;
if (s == NULL) 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; ulong val = s ? simple_strtoul(s, &e, 10) : 0;
addr <<= 8; addr.s_addr <<= 8;
addr |= (val & 0xFF); addr.s_addr |= (val & 0xFF);
if (s) { if (s) {
s = (*e) ? e+1 : e; s = (*e) ? e+1 : e;
} }
} }
return (htonl(addr)); addr.s_addr = htonl(addr.s_addr);
return addr;
} }

View File

@ -27,8 +27,8 @@
# define ARP_TIMEOUT_COUNT CONFIG_NET_RETRY_COUNT # define ARP_TIMEOUT_COUNT CONFIG_NET_RETRY_COUNT
#endif #endif
IPaddr_t NetArpWaitPacketIP; struct in_addr net_arp_wait_packet_ip;
static IPaddr_t NetArpWaitReplyIP; static struct in_addr net_arp_wait_reply_ip;
/* MAC address of waiting packet's destination */ /* MAC address of waiting packet's destination */
uchar *NetArpWaitPacketMAC; uchar *NetArpWaitPacketMAC;
int NetArpWaitTxPacketSize; int NetArpWaitTxPacketSize;
@ -42,15 +42,15 @@ void ArpInit(void)
{ {
/* XXX problem with bss workaround */ /* XXX problem with bss workaround */
NetArpWaitPacketMAC = NULL; NetArpWaitPacketMAC = NULL;
NetArpWaitPacketIP = 0; net_arp_wait_packet_ip.s_addr = 0;
NetArpWaitReplyIP = 0; net_arp_wait_reply_ip.s_addr = 0;
NetArpWaitTxPacketSize = 0; NetArpWaitTxPacketSize = 0;
NetArpTxPacket = &NetArpPacketBuf[0] + (PKTALIGN - 1); NetArpTxPacket = &NetArpPacketBuf[0] + (PKTALIGN - 1);
NetArpTxPacket -= (ulong)NetArpTxPacket % PKTALIGN; NetArpTxPacket -= (ulong)NetArpTxPacket % PKTALIGN;
} }
void arp_raw_request(IPaddr_t sourceIP, const uchar *targetEther, void arp_raw_request(struct in_addr source_ip, const uchar *targetEther,
IPaddr_t targetIP) struct in_addr target_ip)
{ {
uchar *pkt; uchar *pkt;
struct arp_hdr *arp; struct arp_hdr *arp;
@ -72,35 +72,35 @@ void arp_raw_request(IPaddr_t sourceIP, const uchar *targetEther,
arp->ar_op = htons(ARPOP_REQUEST); arp->ar_op = htons(ARPOP_REQUEST);
memcpy(&arp->ar_sha, NetOurEther, ARP_HLEN); /* source ET addr */ 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 */ 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); NetSendPacket(NetArpTxPacket, eth_hdr_size + ARP_HDR_SIZE);
} }
void ArpRequest(void) void ArpRequest(void)
{ {
if ((NetArpWaitPacketIP & NetOurSubnetMask) != if ((net_arp_wait_packet_ip.s_addr & net_netmask.s_addr) !=
(NetOurIP & NetOurSubnetMask)) { (net_ip.s_addr & net_netmask.s_addr)) {
if (NetOurGatewayIP == 0) { if (net_gateway.s_addr == 0) {
puts("## Warning: gatewayip needed but not set\n"); puts("## Warning: gatewayip needed but not set\n");
NetArpWaitReplyIP = NetArpWaitPacketIP; net_arp_wait_reply_ip = net_arp_wait_packet_ip;
} else { } else {
NetArpWaitReplyIP = NetOurGatewayIP; net_arp_wait_reply_ip = net_gateway;
} }
} else { } 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) void ArpTimeoutCheck(void)
{ {
ulong t; ulong t;
if (!NetArpWaitPacketIP) if (!net_arp_wait_packet_ip.s_addr)
return; return;
t = get_timer(0); t = get_timer(0);
@ -123,7 +123,7 @@ void ArpTimeoutCheck(void)
void ArpReceive(struct ethernet_hdr *et, struct ip_udp_hdr *ip, int len) void ArpReceive(struct ethernet_hdr *et, struct ip_udp_hdr *ip, int len)
{ {
struct arp_hdr *arp; struct arp_hdr *arp;
IPaddr_t reply_ip_addr; struct in_addr reply_ip_addr;
uchar *pkt; uchar *pkt;
int eth_hdr_size; 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) if (arp->ar_pln != ARP_PLEN)
return; return;
if (NetOurIP == 0) if (net_ip.s_addr == 0)
return; return;
if (NetReadIP(&arp->ar_tpa) != NetOurIP) if (net_read_ip(&arp->ar_tpa).s_addr != net_ip.s_addr)
return; return;
switch (ntohs(arp->ar_op)) { 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; pkt += eth_hdr_size;
arp->ar_op = htons(ARPOP_REPLY); arp->ar_op = htons(ARPOP_REPLY);
memcpy(&arp->ar_tha, &arp->ar_sha, ARP_HLEN); 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); 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 #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 * reply to ARP request so that our reply will overwrite
* the arp-proxy's instead of the other way around. * the arp-proxy's instead of the other way around.
*/ */
if ((NetReadIP(&arp->ar_tpa) & NetOurSubnetMask) != if ((net_read_ip(&arp->ar_tpa).s_addr & net_netmask.s_addr) !=
(NetReadIP(&arp->ar_spa) & NetOurSubnetMask)) (net_read_ip(&arp->ar_spa).s_addr & net_netmask.s_addr))
udelay(5000); udelay(5000);
#endif #endif
NetSendPacket((uchar *)et, eth_hdr_size + ARP_HDR_SIZE); 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 */ case ARPOP_REPLY: /* arp reply */
/* are we waiting for a reply */ /* are we waiting for a reply */
if (!NetArpWaitPacketIP) if (!net_arp_wait_packet_ip.s_addr)
break; break;
#ifdef CONFIG_KEEP_SERVERADDR #ifdef CONFIG_KEEP_SERVERADDR
if (NetServerIP == NetArpWaitPacketIP) { if (net_server_ip.s_addr == net_arp_wait_packet_ip.s_addr) {
char buf[20]; char buf[20];
sprintf(buf, "%pM", &arp->ar_sha); sprintf(buf, "%pM", &arp->ar_sha);
setenv("serveraddr", buf); setenv("serveraddr", buf);
} }
#endif #endif
reply_ip_addr = NetReadIP(&arp->ar_spa); reply_ip_addr = net_read_ip(&arp->ar_spa);
/* matched waiting packet's address */ /* 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, debug_cond(DEBUG_DEV_PKT,
"Got ARP REPLY, set eth addr (%pM)\n", "Got ARP REPLY, set eth addr (%pM)\n",
arp->ar_data); arp->ar_data);
@ -223,7 +223,7 @@ void ArpReceive(struct ethernet_hdr *et, struct ip_udp_hdr *ip, int len)
NetSendPacket(NetTxPacket, NetArpWaitTxPacketSize); NetSendPacket(NetTxPacket, NetArpWaitTxPacketSize);
/* no arp request pending now */ /* no arp request pending now */
NetArpWaitPacketIP = 0; net_arp_wait_packet_ip.s_addr = 0;
NetArpWaitTxPacketSize = 0; NetArpWaitTxPacketSize = 0;
NetArpWaitPacketMAC = NULL; NetArpWaitPacketMAC = NULL;

View File

@ -14,7 +14,7 @@
#include <common.h> #include <common.h>
extern IPaddr_t NetArpWaitPacketIP; extern struct in_addr net_arp_wait_packet_ip;
/* MAC address of waiting packet's destination */ /* MAC address of waiting packet's destination */
extern uchar *NetArpWaitPacketMAC; extern uchar *NetArpWaitPacketMAC;
extern int NetArpWaitTxPacketSize; extern int NetArpWaitTxPacketSize;
@ -23,8 +23,8 @@ extern int NetArpWaitTry;
void ArpInit(void); void ArpInit(void);
void ArpRequest(void); void ArpRequest(void);
void arp_raw_request(IPaddr_t sourceIP, const uchar *targetEther, void arp_raw_request(struct in_addr source_ip, const uchar *targetEther,
IPaddr_t targetIP); struct in_addr target_ip);
void ArpTimeoutCheck(void); void ArpTimeoutCheck(void);
void ArpReceive(struct ethernet_hdr *et, struct ip_udp_hdr *ip, int len); void ArpReceive(struct ethernet_hdr *et, struct ip_udp_hdr *ip, int len);

View File

@ -60,9 +60,9 @@ ulong bootp_timeout;
#if defined(CONFIG_CMD_DHCP) #if defined(CONFIG_CMD_DHCP)
static dhcp_state_t dhcp_state = INIT; static dhcp_state_t dhcp_state = INIT;
static unsigned long dhcp_leasetime; static unsigned long dhcp_leasetime;
static IPaddr_t NetDHCPServerIP; static struct in_addr dhcp_server_ip;
static void DhcpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, static void dhcp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
unsigned len); unsigned src, unsigned len);
/* For Debug */ /* For Debug */
#if 0 #if 0
@ -139,11 +139,11 @@ static int BootpCheckPkt(uchar *pkt, unsigned dest, unsigned src, unsigned len)
static void BootpCopyNetParams(struct Bootp_t *bp) static void BootpCopyNetParams(struct Bootp_t *bp)
{ {
#if !defined(CONFIG_BOOTP_SERVERIP) #if !defined(CONFIG_BOOTP_SERVERIP)
IPaddr_t tmp_ip; struct in_addr tmp_ip;
NetCopyIP(&tmp_ip, &bp->bp_siaddr); net_copy_ip(&tmp_ip, &bp->bp_siaddr);
if (tmp_ip != 0) if (tmp_ip.s_addr != 0)
NetCopyIP(&NetServerIP, &bp->bp_siaddr); net_copy_ip(&net_server_ip, &bp->bp_siaddr);
memcpy(NetServerEther, ((struct ethernet_hdr *)NetRxPacket)->et_src, 6); memcpy(NetServerEther, ((struct ethernet_hdr *)NetRxPacket)->et_src, 6);
if (strlen(bp->bp_file) > 0) if (strlen(bp->bp_file) > 0)
copy_filename(BootFile, bp->bp_file, sizeof(BootFile)); copy_filename(BootFile, bp->bp_file, sizeof(BootFile));
@ -157,7 +157,7 @@ static void BootpCopyNetParams(struct Bootp_t *bp)
if (*BootFile) if (*BootFile)
setenv("bootfile", BootFile); setenv("bootfile", BootFile);
#endif #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) static int truncate_sz(const char *name, int maxlen, int curlen)
@ -184,26 +184,28 @@ static void BootpVendorFieldProcess(u8 *ext)
switch (*ext) { switch (*ext) {
/* Fixed length fields */ /* Fixed length fields */
case 1: /* Subnet mask */ case 1: /* Subnet mask */
if (NetOurSubnetMask == 0) if (net_netmask.s_addr == 0)
NetCopyIP(&NetOurSubnetMask, (IPaddr_t *) (ext + 2)); net_copy_ip(&net_netmask, (struct in_addr *)(ext + 2));
break; break;
case 2: /* Time offset - Not yet supported */ case 2: /* Time offset - Not yet supported */
break; break;
/* Variable length fields */ /* Variable length fields */
case 3: /* Gateways list */ case 3: /* Gateways list */
if (NetOurGatewayIP == 0) if (net_gateway.s_addr == 0)
NetCopyIP(&NetOurGatewayIP, (IPaddr_t *) (ext + 2)); net_copy_ip(&net_gateway, (struct in_addr *)(ext + 2));
break; break;
case 4: /* Time server - Not yet supported */ case 4: /* Time server - Not yet supported */
break; break;
case 5: /* IEN-116 name server - Not yet supported */ case 5: /* IEN-116 name server - Not yet supported */
break; break;
case 6: case 6:
if (NetOurDNSIP == 0) if (net_dns_server.s_addr == 0)
NetCopyIP(&NetOurDNSIP, (IPaddr_t *) (ext + 2)); net_copy_ip(&net_dns_server,
(struct in_addr *)(ext + 2));
#if defined(CONFIG_BOOTP_DNS2) #if defined(CONFIG_BOOTP_DNS2)
if ((NetOurDNS2IP == 0) && (size > 4)) if ((net_dns_server2.s_addr == 0) && (size > 4))
NetCopyIP(&NetOurDNS2IP, (IPaddr_t *) (ext + 2 + 4)); net_copy_ip(&net_dns_server2,
(struct in_addr *)(ext + 2 + 4));
#endif #endif
break; break;
case 7: /* Log server - Not yet supported */ case 7: /* Log server - Not yet supported */
@ -262,7 +264,7 @@ static void BootpVendorFieldProcess(u8 *ext)
break; break;
#if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER) #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER)
case 42: /* NTP server IP */ case 42: /* NTP server IP */
NetCopyIP(&NetNtpServerIP, (IPaddr_t *) (ext + 2)); net_copy_ip(&net_ntp_server, (struct in_addr *)(ext + 2));
break; break;
#endif #endif
/* Application layer fields */ /* Application layer fields */
@ -295,11 +297,11 @@ static void BootpVendorProcess(u8 *ext, int size)
} }
debug("[BOOTP] Received fields:\n"); debug("[BOOTP] Received fields:\n");
if (NetOurSubnetMask) if (net_netmask.s_addr)
debug("NetOurSubnetMask : %pI4\n", &NetOurSubnetMask); debug("net_netmask : %pI4\n", &net_netmask);
if (NetOurGatewayIP) if (net_gateway.s_addr)
debug("NetOurGatewayIP : %pI4", &NetOurGatewayIP); debug("net_gateway : %pI4", &net_gateway);
if (NetBootFileSize) if (NetBootFileSize)
debug("NetBootFileSize : %d\n", NetBootFileSize); debug("NetBootFileSize : %d\n", NetBootFileSize);
@ -317,17 +319,16 @@ static void BootpVendorProcess(u8 *ext, int size)
debug("NetBootFileSize: %d\n", NetBootFileSize); debug("NetBootFileSize: %d\n", NetBootFileSize);
#if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER) #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER)
if (NetNtpServerIP) if (net_ntp_server)
debug("NetNtpServerIP : %pI4\n", &NetNtpServerIP); debug("net_ntp_server : %pI4\n", &net_ntp_server);
#endif #endif
} }
/* /*
* Handle a BOOTP received packet. * Handle a BOOTP received packet.
*/ */
static void static void bootp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
BootpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, unsigned src, unsigned len)
unsigned len)
{ {
struct Bootp_t *bp; struct Bootp_t *bp;
@ -400,8 +401,8 @@ BootpTimeout(void)
* Initialize BOOTP extension fields in the request. * Initialize BOOTP extension fields in the request.
*/ */
#if defined(CONFIG_CMD_DHCP) #if defined(CONFIG_CMD_DHCP)
static int DhcpExtended(u8 *e, int message_type, IPaddr_t ServerID, static int dhcp_extended(u8 *e, int message_type, struct in_addr server_ip,
IPaddr_t RequestedIP) struct in_addr requested_ip)
{ {
u8 *start = e; u8 *start = e;
u8 *cnt; u8 *cnt;
@ -431,8 +432,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) >> 8;
*e++ = (576 - 312 + OPT_FIELD_SIZE) & 0xff; *e++ = (576 - 312 + OPT_FIELD_SIZE) & 0xff;
if (ServerID) { if (server_ip.s_addr) {
int tmp = ntohl(ServerID); int tmp = ntohl(server_ip.s_addr);
*e++ = 54; /* ServerID */ *e++ = 54; /* ServerID */
*e++ = 4; *e++ = 4;
@ -442,8 +443,8 @@ static int DhcpExtended(u8 *e, int message_type, IPaddr_t ServerID,
*e++ = tmp & 0xff; *e++ = tmp & 0xff;
} }
if (RequestedIP) { if (requested_ip.s_addr) {
int tmp = ntohl(RequestedIP); int tmp = ntohl(requested_ip.s_addr);
*e++ = 50; /* Requested IP */ *e++ = 50; /* Requested IP */
*e++ = 4; *e++ = 4;
@ -561,7 +562,7 @@ static int DhcpExtended(u8 *e, int message_type, IPaddr_t ServerID,
/* /*
* Warning: no field size check - change CONFIG_BOOTP_* at your own risk! * 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; u8 *start = e;
@ -662,6 +663,8 @@ BootpRequest(void)
ulong rand_ms; ulong rand_ms;
#endif #endif
ulong BootpID; ulong BootpID;
struct in_addr zero_ip;
struct in_addr bcast_ip;
bootstage_mark_name(BOOTSTAGE_ID_BOOTP_START, "bootp_start"); bootstage_mark_name(BOOTSTAGE_ID_BOOTP_START, "bootp_start");
#if defined(CONFIG_CMD_DHCP) #if defined(CONFIG_CMD_DHCP)
@ -707,18 +710,20 @@ BootpRequest(void)
bp->bp_hlen = HWL_ETHER; bp->bp_hlen = HWL_ETHER;
bp->bp_hops = 0; bp->bp_hops = 0;
bp->bp_secs = htons(get_timer(0) / 1000); bp->bp_secs = htons(get_timer(0) / 1000);
NetWriteIP(&bp->bp_ciaddr, 0); zero_ip.s_addr = 0;
NetWriteIP(&bp->bp_yiaddr, 0); net_write_ip(&bp->bp_ciaddr, zero_ip);
NetWriteIP(&bp->bp_siaddr, 0); net_write_ip(&bp->bp_yiaddr, zero_ip);
NetWriteIP(&bp->bp_giaddr, 0); net_write_ip(&bp->bp_siaddr, zero_ip);
net_write_ip(&bp->bp_giaddr, zero_ip);
memcpy(bp->bp_chaddr, NetOurEther, 6); memcpy(bp->bp_chaddr, NetOurEther, 6);
copy_filename(bp->bp_file, BootFile, sizeof(bp->bp_file)); copy_filename(bp->bp_file, BootFile, sizeof(bp->bp_file));
/* Request additional information from the BOOTP/DHCP server */ /* Request additional information from the BOOTP/DHCP server */
#if defined(CONFIG_CMD_DHCP) #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 #else
extlen = BootpExtended((u8 *)bp->bp_vend); extlen = bootp_extended((u8 *)bp->bp_vend);
#endif #endif
/* /*
@ -740,14 +745,15 @@ BootpRequest(void)
*/ */
iplen = BOOTP_HDR_SIZE - OPT_FIELD_SIZE + extlen; iplen = BOOTP_HDR_SIZE - OPT_FIELD_SIZE + extlen;
pktlen = eth_hdr_size + IP_UDP_HDR_SIZE + iplen; 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); NetSetTimeout(bootp_timeout, BootpTimeout);
#if defined(CONFIG_CMD_DHCP) #if defined(CONFIG_CMD_DHCP)
dhcp_state = SELECTING; dhcp_state = SELECTING;
net_set_udp_handler(DhcpHandler); net_set_udp_handler(dhcp_handler);
#else #else
net_set_udp_handler(BootpHandler); net_set_udp_handler(bootp_handler);
#endif #endif
NetSendPacket(NetTxPacket, pktlen); NetSendPacket(NetTxPacket, pktlen);
} }
@ -765,7 +771,7 @@ static void DhcpOptionsProcess(uchar *popt, struct Bootp_t *bp)
oplen = *(popt + 1); oplen = *(popt + 1);
switch (*popt) { switch (*popt) {
case 1: case 1:
NetCopyIP(&NetOurSubnetMask, (popt + 2)); net_copy_ip(&net_netmask, (popt + 2));
break; break;
#if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_TIMEOFFSET) #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_TIMEOFFSET)
case 2: /* Time offset */ case 2: /* Time offset */
@ -775,13 +781,13 @@ static void DhcpOptionsProcess(uchar *popt, struct Bootp_t *bp)
break; break;
#endif #endif
case 3: case 3:
NetCopyIP(&NetOurGatewayIP, (popt + 2)); net_copy_ip(&net_gateway, (popt + 2));
break; break;
case 6: case 6:
NetCopyIP(&NetOurDNSIP, (popt + 2)); net_copy_ip(&net_dns_server, (popt + 2));
#if defined(CONFIG_BOOTP_DNS2) #if defined(CONFIG_BOOTP_DNS2)
if (*(popt + 1) > 4) if (*(popt + 1) > 4)
NetCopyIP(&NetOurDNS2IP, (popt + 2 + 4)); net_copy_ip(&net_dns_server2, (popt + 2 + 4));
#endif #endif
break; break;
case 12: case 12:
@ -802,7 +808,7 @@ static void DhcpOptionsProcess(uchar *popt, struct Bootp_t *bp)
break; break;
#if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER) #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER)
case 42: /* NTP server IP */ case 42: /* NTP server IP */
NetCopyIP(&NetNtpServerIP, (popt + 2)); net_copy_ip(&net_ntp_server, (popt + 2));
break; break;
#endif #endif
case 51: case 51:
@ -811,7 +817,7 @@ static void DhcpOptionsProcess(uchar *popt, struct Bootp_t *bp)
case 53: /* Ignore Message Type Option */ case 53: /* Ignore Message Type Option */
break; break;
case 54: case 54:
NetCopyIP(&NetDHCPServerIP, (popt + 2)); net_copy_ip(&dhcp_server_ip, (popt + 2));
break; break;
case 58: /* Ignore Renewal Time Option */ case 58: /* Ignore Renewal Time Option */
break; break;
@ -878,7 +884,9 @@ static void DhcpSendRequestPkt(struct Bootp_t *bp_offer)
struct Bootp_t *bp; struct Bootp_t *bp;
int pktlen, iplen, extlen; int pktlen, iplen, extlen;
int eth_hdr_size; 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"); debug("DhcpSendRequestPkt: Sending DHCPREQUEST\n");
pkt = NetTxPacket; pkt = NetTxPacket;
@ -903,7 +911,8 @@ static void DhcpSendRequestPkt(struct Bootp_t *bp_offer)
* RFC3046 requires Relay Agents to discard packets with * RFC3046 requires Relay Agents to discard packets with
* nonzero and offered giaddr * 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); memcpy(bp->bp_chaddr, NetOurEther, 6);
@ -918,13 +927,14 @@ static void DhcpSendRequestPkt(struct Bootp_t *bp_offer)
*/ */
/* Copy offered IP into the parameters request list */ /* Copy offered IP into the parameters request list */
NetCopyIP(&OfferedIP, &bp_offer->bp_yiaddr); net_copy_ip(&offered_ip, &bp_offer->bp_yiaddr);
extlen = DhcpExtended((u8 *)bp->bp_vend, DHCP_REQUEST, extlen = dhcp_extended((u8 *)bp->bp_vend, DHCP_REQUEST,
NetDHCPServerIP, OfferedIP); dhcp_server_ip, offered_ip);
iplen = BOOTP_HDR_SIZE - OPT_FIELD_SIZE + extlen; iplen = BOOTP_HDR_SIZE - OPT_FIELD_SIZE + extlen;
pktlen = eth_hdr_size + IP_UDP_HDR_SIZE + iplen; 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 #ifdef CONFIG_BOOTP_DHCP_REQUEST_DELAY
udelay(CONFIG_BOOTP_DHCP_REQUEST_DELAY); udelay(CONFIG_BOOTP_DHCP_REQUEST_DELAY);
@ -936,9 +946,8 @@ static void DhcpSendRequestPkt(struct Bootp_t *bp_offer)
/* /*
* Handle DHCP received packets. * Handle DHCP received packets.
*/ */
static void static void dhcp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
DhcpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, unsigned src, unsigned len)
unsigned len)
{ {
struct Bootp_t *bp = (struct Bootp_t *)pkt; struct Bootp_t *bp = (struct Bootp_t *)pkt;
@ -993,7 +1002,7 @@ DhcpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
BootpCopyNetParams(bp); BootpCopyNetParams(bp);
dhcp_state = BOUND; dhcp_state = BOUND;
printf("DHCP client bound to address %pI4 (%lu ms)\n", 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, bootstage_mark_name(BOOTSTAGE_ID_BOOTP_STOP,
"bootp_stop"); "bootp_stop");

View File

@ -41,10 +41,10 @@ struct Bootp_t {
ulong bp_id; /* Transaction ID */ ulong bp_id; /* Transaction ID */
ushort bp_secs; /* Seconds since boot */ ushort bp_secs; /* Seconds since boot */
ushort bp_spare1; /* Alignment */ ushort bp_spare1; /* Alignment */
IPaddr_t bp_ciaddr; /* Client IP address */ struct in_addr bp_ciaddr; /* Client IP address */
IPaddr_t bp_yiaddr; /* Your (client) IP address */ struct in_addr bp_yiaddr; /* Your (client) IP address */
IPaddr_t bp_siaddr; /* Server IP address */ struct in_addr bp_siaddr; /* Server IP address */
IPaddr_t bp_giaddr; /* Gateway IP address */ struct in_addr bp_giaddr; /* Gateway IP address */
uchar bp_chaddr[16]; /* Client hardware address */ uchar bp_chaddr[16]; /* Client hardware address */
char bp_sname[64]; /* Server host name */ char bp_sname[64]; /* Server host name */
char bp_file[128]; /* Boot file name */ char bp_file[128]; /* Boot file name */

View File

@ -5,7 +5,7 @@
* Copyright (c) 2009 Robin Getz <rgetz@blackfin.uclinux.org> * Copyright (c) 2009 Robin Getz <rgetz@blackfin.uclinux.org>
* *
* This is a simple DNS implementation for U-Boot. It will use the first IP * 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. * network related activities.
* *
* The packet handling is partly based on TADNS, original copyrights * The packet handling is partly based on TADNS, original copyrights
@ -89,8 +89,8 @@ DnsSend(void)
DnsOurPort = random_port(); DnsOurPort = random_port();
NetSendUDPPacket(NetServerEther, NetOurDNSIP, DNS_SERVICE_PORT, NetSendUDPPacket(NetServerEther, net_dns_server, DNS_SERVICE_PORT,
DnsOurPort, n); DnsOurPort, n);
debug("DNS packet sent\n"); debug("DNS packet sent\n");
} }
@ -101,15 +101,15 @@ DnsTimeout(void)
net_set_state(NETLOOP_FAIL); net_set_state(NETLOOP_FAIL);
} }
static void static void dns_handler(uchar *pkt, unsigned dest, struct in_addr sip,
DnsHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, unsigned len) unsigned src, unsigned len)
{ {
struct header *header; struct header *header;
const unsigned char *p, *e, *s; const unsigned char *p, *e, *s;
u16 type, i; u16 type, i;
int found, stop, dlen; int found, stop, dlen;
char IPStr[22]; char IPStr[22];
IPaddr_t IPAddress; struct in_addr ip_addr;
debug("%s\n", __func__); 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); dlen = get_unaligned_be16(p+10);
p += 12; p += 12;
memcpy(&IPAddress, p, 4); memcpy(&ip_addr, p, 4);
if (p + dlen <= e) { if (p + dlen <= e) {
ip_to_string(IPAddress, IPStr); ip_to_string(ip_addr, IPStr);
printf("%s\n", IPStr); printf("%s\n", IPStr);
if (NetDNSenvvar) if (NetDNSenvvar)
setenv(NetDNSenvvar, IPStr); setenv(NetDNSenvvar, IPStr);
@ -200,7 +200,7 @@ DnsStart(void)
debug("%s\n", __func__); debug("%s\n", __func__);
NetSetTimeout(DNS_TIMEOUT, DnsTimeout); 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. */ /* Clear a previous MAC address, the server IP might have changed. */
memset(NetServerEther, 0, sizeof(NetServerEther)); memset(NetServerEther, 0, sizeof(NetServerEther));

View File

@ -768,14 +768,14 @@ int eth_initialize(void)
* mcast_addr: multicast ipaddr from which multicast Mac is made * mcast_addr: multicast ipaddr from which multicast Mac is made
* join: 1=join, 0=leave. * 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]; u8 mcast_mac[6];
if (!eth_current || !eth_current->mcast) if (!eth_current || !eth_current->mcast)
return -1; return -1;
mcast_mac[5] = htonl(mcast_ip) & 0xff; mcast_mac[5] = htonl(mcast_ip.s_addr) & 0xff;
mcast_mac[4] = (htonl(mcast_ip)>>8) & 0xff; mcast_mac[4] = (htonl(mcast_ip.s_addr)>>8) & 0xff;
mcast_mac[3] = (htonl(mcast_ip)>>16) & 0x7f; mcast_mac[3] = (htonl(mcast_ip.s_addr)>>16) & 0x7f;
mcast_mac[2] = 0x5e; mcast_mac[2] = 0x5e;
mcast_mac[1] = 0x0; mcast_mac[1] = 0x0;
mcast_mac[0] = 0x1; mcast_mac[0] = 0x1;

View File

@ -49,7 +49,7 @@ static enum ll_state_t {
DISABLED DISABLED
} state = DISABLED; } state = DISABLED;
static IPaddr_t ip; static struct in_addr ip;
static int timeout_ms = -1; static int timeout_ms = -1;
static unsigned deadline_ms; static unsigned deadline_ms;
static unsigned conflicts; 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 * Pick a random link local IP address on 169.254/16, except that
* the first and last 256 addresses are reserved. * the first and last 256 addresses are reserved.
*/ */
static IPaddr_t pick(void) static struct in_addr pick(void)
{ {
unsigned tmp; unsigned tmp;
struct in_addr ip;
do { do {
tmp = rand_r(&seed) & IN_CLASSB_HOST; tmp = rand_r(&seed) & IN_CLASSB_HOST;
} while (tmp > (IN_CLASSB_HOST - 0x0200)); } 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) void link_local_start(void)
{ {
ip = getenv_IPaddr("llipaddr"); ip = getenv_ip("llipaddr");
if (ip != 0 && (ntohl(ip) & IN_CLASSB_NET) != LINKLOCAL_ADDR) { if (ip.s_addr != 0 &&
(ntohl(ip.s_addr) & IN_CLASSB_NET) != LINKLOCAL_ADDR) {
puts("invalid link address"); puts("invalid link address");
net_set_state(NETLOOP_FAIL); net_set_state(NETLOOP_FAIL);
return; return;
} }
NetOurSubnetMask = IN_CLASSB_NET; net_netmask.s_addr = IN_CLASSB_NET;
seed = seed_mac(); seed = seed_mac();
if (ip == 0) if (ip.s_addr == 0)
ip = pick(); ip = pick();
state = PROBE; state = PROBE;
@ -131,10 +134,12 @@ static void link_local_timeout(void)
/* timeouts in the PROBE state mean no conflicting ARP packets /* timeouts in the PROBE state mean no conflicting ARP packets
have been received, so we can progress through the states */ have been received, so we can progress through the states */
if (nprobes < PROBE_NUM) { if (nprobes < PROBE_NUM) {
struct in_addr zero_ip = {.s_addr = 0};
nprobes++; nprobes++;
debug_cond(DEBUG_LL_STATE, "probe/%u %s@%pI4\n", debug_cond(DEBUG_LL_STATE, "probe/%u %s@%pI4\n",
nprobes, eth_get_name(), &ip); 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 = PROBE_MIN * 1000;
timeout_ms += random_delay_ms(PROBE_MAX - PROBE_MIN); timeout_ms += random_delay_ms(PROBE_MAX - PROBE_MIN);
} else { } else {
@ -172,7 +177,7 @@ static void link_local_timeout(void)
/* Switch to monitor state */ /* Switch to monitor state */
state = MONITOR; state = MONITOR;
printf("Successfully assigned %pI4\n", &ip); printf("Successfully assigned %pI4\n", &ip);
NetCopyIP(&NetOurIP, &ip); net_copy_ip(&net_ip, &ip);
ready = 1; ready = 1;
conflicts = 0; conflicts = 0;
timeout_ms = -1; timeout_ms = -1;
@ -206,7 +211,7 @@ void link_local_receive_arp(struct arp_hdr *arp, int len)
{ {
int source_ip_conflict; int source_ip_conflict;
int target_ip_conflict; int target_ip_conflict;
IPaddr_t null_ip = 0; struct in_addr null_ip = {.s_addr = 0};
if (state == DISABLED) if (state == DISABLED)
return; return;
@ -322,7 +327,7 @@ void link_local_receive_arp(struct arp_hdr *arp, int len)
state = PROBE; state = PROBE;
debug("defend conflict -- starting over\n"); debug("defend conflict -- starting over\n");
ready = 0; ready = 0;
NetOurIP = 0; net_ip.s_addr = 0;
/* restart the whole protocol */ /* restart the whole protocol */
ip = pick(); ip = pick();

100
net/net.c
View File

@ -112,14 +112,14 @@ DECLARE_GLOBAL_DATA_PTR;
/** BOOTP EXTENTIONS **/ /** BOOTP EXTENTIONS **/
/* Our subnet mask (0=unknown) */ /* Our subnet mask (0=unknown) */
IPaddr_t NetOurSubnetMask; struct in_addr net_netmask;
/* Our gateways IP address */ /* Our gateways IP address */
IPaddr_t NetOurGatewayIP; struct in_addr net_gateway;
/* Our DNS IP address */ /* Our DNS IP address */
IPaddr_t NetOurDNSIP; struct in_addr net_dns_server;
#if defined(CONFIG_BOOTP_DNS2) #if defined(CONFIG_BOOTP_DNS2)
/* Our 2nd DNS IP address */ /* Our 2nd DNS IP address */
IPaddr_t NetOurDNS2IP; struct in_addr net_dns_server2;
#endif #endif
/* Our NIS domain */ /* Our NIS domain */
char NetOurNISDomain[32] = {0,}; char NetOurNISDomain[32] = {0,};
@ -131,7 +131,7 @@ char NetOurRootPath[64] = {0,};
ushort NetBootFileSize; ushort NetBootFileSize;
#ifdef CONFIG_MCAST_TFTP /* Multicast TFTP */ #ifdef CONFIG_MCAST_TFTP /* Multicast TFTP */
IPaddr_t Mcast_addr; struct in_addr net_mcast_addr;
#endif #endif
/** END OF BOOTP EXTENTIONS **/ /** END OF BOOTP EXTENTIONS **/
@ -143,9 +143,9 @@ uchar NetOurEther[6];
/* Boot server enet address */ /* Boot server enet address */
uchar NetServerEther[6]; uchar NetServerEther[6];
/* Our IP addr (0 = unknown) */ /* Our IP addr (0 = unknown) */
IPaddr_t NetOurIP; struct in_addr net_ip;
/* Server IP addr (0 = unknown) */ /* Server IP addr (0 = unknown) */
IPaddr_t NetServerIP; struct in_addr net_server_ip;
/* Current receive packet */ /* Current receive packet */
uchar *NetRxPacket; uchar *NetRxPacket;
/* Current rx packet length */ /* Current rx packet length */
@ -178,7 +178,7 @@ char BootFile[128];
#if defined(CONFIG_CMD_SNTP) #if defined(CONFIG_CMD_SNTP)
/* NTP server IP address */ /* NTP server IP address */
IPaddr_t NetNtpServerIP; struct in_addr net_ntp_server;
/* offset time from UTC */ /* offset time from UTC */
int NetTimeOffset; int NetTimeOffset;
#endif #endif
@ -267,14 +267,14 @@ static void NetInitLoop(void)
/* update only when the environment has changed */ /* update only when the environment has changed */
if (env_changed_id != env_id) { if (env_changed_id != env_id) {
NetOurIP = getenv_IPaddr("ipaddr"); net_ip = getenv_ip("ipaddr");
NetOurGatewayIP = getenv_IPaddr("gatewayip"); net_gateway = getenv_ip("gatewayip");
NetOurSubnetMask = getenv_IPaddr("netmask"); net_netmask = getenv_ip("netmask");
NetServerIP = getenv_IPaddr("serverip"); net_server_ip = getenv_ip("serverip");
NetOurNativeVLAN = getenv_VLAN("nvlan"); NetOurNativeVLAN = getenv_VLAN("nvlan");
NetOurVLAN = getenv_VLAN("vlan"); NetOurVLAN = getenv_VLAN("vlan");
#if defined(CONFIG_CMD_DNS) #if defined(CONFIG_CMD_DNS)
NetOurDNSIP = getenv_IPaddr("dnsip"); net_dns_server = getenv_ip("dnsip");
#endif #endif
env_changed_id = env_id; env_changed_id = env_id;
} }
@ -397,21 +397,21 @@ restart:
#if defined(CONFIG_CMD_DHCP) #if defined(CONFIG_CMD_DHCP)
case DHCP: case DHCP:
BootpReset(); BootpReset();
NetOurIP = 0; net_ip.s_addr = 0;
DhcpRequest(); /* Basically same as BOOTP */ DhcpRequest(); /* Basically same as BOOTP */
break; break;
#endif #endif
case BOOTP: case BOOTP:
BootpReset(); BootpReset();
NetOurIP = 0; net_ip.s_addr = 0;
BootpRequest(); BootpRequest();
break; break;
#if defined(CONFIG_CMD_RARP) #if defined(CONFIG_CMD_RARP)
case RARP: case RARP:
RarpTry = 0; RarpTry = 0;
NetOurIP = 0; net_ip.s_addr = 0;
RarpRequest(); RarpRequest();
break; break;
#endif #endif
@ -496,7 +496,7 @@ restart:
*/ */
if (ctrlc()) { if (ctrlc()) {
/* cancel any ARP that may not have completed */ /* cancel any ARP that may not have completed */
NetArpWaitPacketIP = 0; net_arp_wait_packet_ip.s_addr = 0;
net_cleanup_loop(); net_cleanup_loop();
eth_halt(); eth_halt();
@ -660,7 +660,7 @@ int NetStartAgain(void)
*/ */
static void dummy_handler(uchar *pkt, unsigned dport, static void dummy_handler(uchar *pkt, unsigned dport,
IPaddr_t sip, unsigned sport, struct in_addr sip, unsigned sport,
unsigned len) unsigned len)
{ {
} }
@ -716,7 +716,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) int payload_len)
{ {
uchar *pkt; uchar *pkt;
@ -729,11 +729,11 @@ int NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport,
return -1; return -1;
/* convert to new style broadcast */ /* convert to new style broadcast */
if (dest == 0) if (dest.s_addr == 0)
dest = 0xFFFFFFFF; dest.s_addr = 0xFFFFFFFF;
/* if broadcast, make the ether address a broadcast and don't do ARP */ /* if broadcast, make the ether address a broadcast and don't do ARP */
if (dest == 0xFFFFFFFF) if (dest.s_addr == 0xFFFFFFFF)
ether = NetBcastAddr; ether = NetBcastAddr;
pkt = (uchar *)NetTxPacket; pkt = (uchar *)NetTxPacket;
@ -748,7 +748,7 @@ int NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport,
debug_cond(DEBUG_DEV_PKT, "sending ARP for %pI4\n", &dest); debug_cond(DEBUG_DEV_PKT, "sending ARP for %pI4\n", &dest);
/* save the ip and eth addr for the packet to send after arp */ /* save the ip and eth addr for the packet to send after arp */
NetArpWaitPacketIP = dest; net_arp_wait_packet_ip = dest;
NetArpWaitPacketMAC = ether; NetArpWaitPacketMAC = ether;
/* size of the waiting packet */ /* size of the waiting packet */
@ -946,7 +946,7 @@ static inline struct ip_udp_hdr *NetDefragment(struct ip_udp_hdr *ip, int *lenp)
* @parma ip IP packet containing the ICMP * @parma ip IP packet containing the ICMP
*/ */
static void receive_icmp(struct ip_udp_hdr *ip, int len, 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; struct icmp_hdr *icmph = (struct icmp_hdr *)&ip->udp_src;
@ -975,8 +975,8 @@ void net_process_received_packet(uchar *in_packet, int len)
{ {
struct ethernet_hdr *et; struct ethernet_hdr *et;
struct ip_udp_hdr *ip; struct ip_udp_hdr *ip;
IPaddr_t dst_ip; struct in_addr dst_ip;
IPaddr_t src_ip; struct in_addr src_ip;
int eth_proto; int eth_proto;
#if defined(CONFIG_CMD_CDP) #if defined(CONFIG_CMD_CDP)
int iscdp; int iscdp;
@ -1112,15 +1112,16 @@ void net_process_received_packet(uchar *in_packet, int len)
return; return;
} }
/* If it is not for us, ignore it */ /* If it is not for us, ignore it */
dst_ip = NetReadIP(&ip->ip_dst); dst_ip = net_read_ip(&ip->ip_dst);
if (NetOurIP && dst_ip != NetOurIP && dst_ip != 0xFFFFFFFF) { if (net_ip.s_addr && dst_ip.s_addr != net_ip.s_addr &&
dst_ip.s_addr != 0xFFFFFFFF) {
#ifdef CONFIG_MCAST_TFTP #ifdef CONFIG_MCAST_TFTP
if (Mcast_addr != dst_ip) if (net_mcast_addr != dst_ip)
#endif #endif
return; return;
} }
/* Read source IP address for later use */ /* 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 * The function returns the unchanged packet if it's not
* a fragment, and either the complete packet or NULL if * a fragment, and either the complete packet or NULL if
@ -1169,10 +1170,10 @@ void net_process_received_packet(uchar *in_packet, int len)
xsum = ip->ip_p; xsum = ip->ip_p;
xsum += (ntohs(ip->udp_len)); xsum += (ntohs(ip->udp_len));
xsum += (ntohl(ip->ip_src) >> 16) & 0x0000ffff; xsum += (ntohl(ip->ip_src.s_addr) >> 16) & 0x0000ffff;
xsum += (ntohl(ip->ip_src) >> 0) & 0x0000ffff; xsum += (ntohl(ip->ip_src.s_addr) >> 0) & 0x0000ffff;
xsum += (ntohl(ip->ip_dst) >> 16) & 0x0000ffff; xsum += (ntohl(ip->ip_dst.s_addr) >> 16) & 0x0000ffff;
xsum += (ntohl(ip->ip_dst) >> 0) & 0x0000ffff; xsum += (ntohl(ip->ip_dst.s_addr) >> 0) & 0x0000ffff;
sumlen = ntohs(ip->udp_len); sumlen = ntohs(ip->udp_len);
sumptr = (ushort *) &(ip->udp_src); sumptr = (ushort *) &(ip->udp_src);
@ -1232,7 +1233,7 @@ static int net_check_prereq(enum proto_t protocol)
/* Fall through */ /* Fall through */
#if defined(CONFIG_CMD_PING) #if defined(CONFIG_CMD_PING)
case PING: case PING:
if (NetPingIP == 0) { if (net_ping_ip.s_addr == 0) {
puts("*** ERROR: ping address not given\n"); puts("*** ERROR: ping address not given\n");
return 1; return 1;
} }
@ -1240,7 +1241,7 @@ static int net_check_prereq(enum proto_t protocol)
#endif #endif
#if defined(CONFIG_CMD_SNTP) #if defined(CONFIG_CMD_SNTP)
case SNTP: case SNTP:
if (NetNtpServerIP == 0) { if (net_ntp_server.s_addr == 0) {
puts("*** ERROR: NTP server address not given\n"); puts("*** ERROR: NTP server address not given\n");
return 1; return 1;
} }
@ -1248,7 +1249,7 @@ static int net_check_prereq(enum proto_t protocol)
#endif #endif
#if defined(CONFIG_CMD_DNS) #if defined(CONFIG_CMD_DNS)
case DNS: case DNS:
if (NetOurDNSIP == 0) { if (net_dns_server.s_addr == 0) {
puts("*** ERROR: DNS server address not given\n"); puts("*** ERROR: DNS server address not given\n");
return 1; return 1;
} }
@ -1259,7 +1260,7 @@ static int net_check_prereq(enum proto_t protocol)
#endif #endif
case TFTPGET: case TFTPGET:
case TFTPPUT: case TFTPPUT:
if (NetServerIP == 0) { if (net_server_ip.s_addr == 0) {
puts("*** ERROR: `serverip' not set\n"); puts("*** ERROR: `serverip' not set\n");
return 1; return 1;
} }
@ -1271,7 +1272,7 @@ common:
case NETCONS: case NETCONS:
case TFTPSRV: case TFTPSRV:
if (NetOurIP == 0) { if (net_ip.s_addr == 0) {
puts("*** ERROR: `ipaddr' not set\n"); puts("*** ERROR: `ipaddr' not set\n");
return 1; return 1;
} }
@ -1373,7 +1374,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; struct ip_udp_hdr *ip = (struct ip_udp_hdr *)pkt;
@ -1389,12 +1390,12 @@ void net_set_ip_header(uchar *pkt, IPaddr_t dest, IPaddr_t source)
ip->ip_ttl = 255; ip->ip_ttl = 255;
ip->ip_sum = 0; ip->ip_sum = 0;
/* already in network byte order */ /* already in network byte order */
NetCopyIP((void *)&ip->ip_src, &source); net_copy_ip((void *)&ip->ip_src, &source);
/* already in network byte order */ /* 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) int len)
{ {
struct ip_udp_hdr *ip = (struct ip_udp_hdr *)pkt; struct ip_udp_hdr *ip = (struct ip_udp_hdr *)pkt;
@ -1407,7 +1408,7 @@ void net_set_udp_header(uchar *pkt, IPaddr_t dest, int dport, int sport,
if (len & 1) if (len & 1)
pkt[IP_UDP_HDR_SIZE + len] = 0; 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_len = htons(IP_UDP_HDR_SIZE + len);
ip->ip_p = IPPROTO_UDP; ip->ip_p = IPPROTO_UDP;
ip->ip_sum = compute_ip_checksum(ip, IP_HDR_SIZE); ip->ip_sum = compute_ip_checksum(ip, IP_HDR_SIZE);
@ -1444,13 +1445,14 @@ unsigned int random_port(void)
} }
#endif #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", sprintf(s, "%d.%d.%d.%d",
(int) ((x >> 24) & 0xff), (int) ((x.s_addr >> 24) & 0xff),
(int) ((x >> 16) & 0xff), (int) ((x.s_addr >> 16) & 0xff),
(int) ((x >> 8) & 0xff), (int) ((x >> 0) & 0xff) (int) ((x.s_addr >> 8) & 0xff),
(int) ((x.s_addr >> 0) & 0xff)
); );
} }

View File

@ -51,7 +51,7 @@ static char dirfh[NFS_FHSIZE]; /* file handle of directory */
static char filefh[NFS_FHSIZE]; /* file handle of kernel image */ static char filefh[NFS_FHSIZE]; /* file handle of kernel image */
static enum net_loop_state nfs_download_state; static enum net_loop_state nfs_download_state;
static IPaddr_t NfsServerIP; static struct in_addr nfs_server_ip;
static int NfsSrvMountPort; static int NfsSrvMountPort;
static int NfsSrvNfsPort; static int NfsSrvNfsPort;
static int NfsOurPort; static int NfsOurPort;
@ -211,8 +211,8 @@ rpc_req(int rpc_prog, int rpc_proc, uint32_t *data, int datalen)
else else
sport = NfsSrvNfsPort; sport = NfsSrvNfsPort;
NetSendUDPPacket(NetServerEther, NfsServerIP, sport, NfsOurPort, NetSendUDPPacket(NetServerEther, nfs_server_ip, sport, NfsOurPort,
pktlen); pktlen);
} }
/************************************************************************** /**************************************************************************
@ -600,8 +600,8 @@ NfsTimeout(void)
} }
} }
static void static void nfs_handler(uchar *pkt, unsigned dest, struct in_addr sip,
NfsHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, unsigned len) unsigned src, unsigned len)
{ {
int rlen; int rlen;
int reply; int reply;
@ -715,7 +715,7 @@ NfsStart(void)
debug("%s\n", __func__); debug("%s\n", __func__);
nfs_download_state = NETLOOP_FAIL; nfs_download_state = NETLOOP_FAIL;
NfsServerIP = NetServerIP; nfs_server_ip = net_server_ip;
nfs_path = (char *)nfs_path_buff; nfs_path = (char *)nfs_path_buff;
if (nfs_path == NULL) { if (nfs_path == NULL) {
@ -726,10 +726,10 @@ NfsStart(void)
if (BootFile[0] == '\0') { if (BootFile[0] == '\0') {
sprintf(default_filename, "/nfsroot/%02X%02X%02X%02X.img", sprintf(default_filename, "/nfsroot/%02X%02X%02X%02X.img",
NetOurIP & 0xFF, net_ip.s_addr & 0xFF,
(NetOurIP >> 8) & 0xFF, (net_ip.s_addr >> 8) & 0xFF,
(NetOurIP >> 16) & 0xFF, (net_ip.s_addr >> 16) & 0xFF,
(NetOurIP >> 24) & 0xFF); (net_ip.s_addr >> 24) & 0xFF);
strcpy(nfs_path, default_filename); strcpy(nfs_path, default_filename);
printf("*** Warning: no boot file name; using '%s'\n", printf("*** Warning: no boot file name; using '%s'\n",
@ -740,7 +740,7 @@ NfsStart(void)
p = strchr(p, ':'); p = strchr(p, ':');
if (p != NULL) { if (p != NULL) {
NfsServerIP = string_to_ip(BootFile); nfs_server_ip = string_to_ip(BootFile);
++p; ++p;
strcpy(nfs_path, p); strcpy(nfs_path, p);
} else { } else {
@ -753,17 +753,19 @@ NfsStart(void)
printf("Using %s device\n", eth_get_name()); printf("Using %s device\n", eth_get_name());
printf("File transfer via NFS from server %pI4" printf("File transfer via NFS from server %pI4; our IP address is %pI4",
"; our IP address is %pI4", &NfsServerIP, &NetOurIP); &nfs_server_ip, &net_ip);
/* Check if we need to send across this subnet */ /* Check if we need to send across this subnet */
if (NetOurGatewayIP && NetOurSubnetMask) { if (net_gateway.s_addr && net_netmask.s_addr) {
IPaddr_t OurNet = NetOurIP & NetOurSubnetMask; struct in_addr our_net;
IPaddr_t ServerNet = NetServerIP & NetOurSubnetMask; 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", printf("; sending through gateway %pI4",
&NetOurGatewayIP); &net_gateway);
} }
printf("\nFilename '%s/%s'.", nfs_path, nfs_filename); printf("\nFilename '%s/%s'.", nfs_path, nfs_filename);
@ -775,7 +777,7 @@ NfsStart(void)
"Loading: *\b", load_addr); "Loading: *\b", load_addr);
NetSetTimeout(nfs_timeout, NfsTimeout); NetSetTimeout(nfs_timeout, NfsTimeout);
net_set_udp_handler(NfsHandler); net_set_udp_handler(nfs_handler);
NfsTimeoutCount = 0; NfsTimeoutCount = 0;
NfsState = STATE_PRCLOOKUP_PROG_MOUNT_REQ; NfsState = STATE_PRCLOOKUP_PROG_MOUNT_REQ;

View File

@ -15,9 +15,9 @@
static ushort PingSeqNo; static ushort PingSeqNo;
/* The ip address to ping */ /* 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. * 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 ip_hdr *ip = (struct ip_hdr *)pkt;
struct icmp_hdr *icmp = (struct icmp_hdr *)(pkt + IP_HDR_SIZE); 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_len = htons(IP_ICMP_HDR_SIZE);
ip->ip_p = IPPROTO_ICMP; ip->ip_p = IPPROTO_ICMP;
@ -46,14 +46,14 @@ static int ping_send(void)
/* XXX always send arp request */ /* 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); eth_hdr_size = NetSetEther(NetTxPacket, NetEtherNullAddr, PROT_IP);
pkt = (uchar *)NetTxPacket + eth_hdr_size; pkt = (uchar *)NetTxPacket + eth_hdr_size;
set_icmp_header(pkt, NetPingIP); set_icmp_header(pkt, net_ping_ip);
/* size of the waiting packet */ /* size of the waiting packet */
NetArpWaitTxPacketSize = eth_hdr_size + IP_ICMP_HDR_SIZE; 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) void ping_receive(struct ethernet_hdr *et, struct ip_udp_hdr *ip, int len)
{ {
struct icmp_hdr *icmph = (struct icmp_hdr *)&ip->udp_src; struct icmp_hdr *icmph = (struct icmp_hdr *)&ip->udp_src;
IPaddr_t src_ip; struct in_addr src_ip;
int eth_hdr_size; int eth_hdr_size;
switch (icmph->type) { switch (icmph->type) {
case ICMP_ECHO_REPLY: case ICMP_ECHO_REPLY:
src_ip = NetReadIP((void *)&ip->ip_src); src_ip = net_read_ip((void *)&ip->ip_src);
if (src_ip == NetPingIP) if (src_ip.s_addr == net_ping_ip.s_addr)
net_set_state(NETLOOP_SUCCESS); net_set_state(NETLOOP_SUCCESS);
return; return;
case ICMP_ECHO_REQUEST: 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_sum = 0;
ip->ip_off = 0; ip->ip_off = 0;
NetCopyIP((void *)&ip->ip_dst, &ip->ip_src); net_copy_ip((void *)&ip->ip_dst, &ip->ip_src);
NetCopyIP((void *)&ip->ip_src, &NetOurIP); net_copy_ip((void *)&ip->ip_src, &net_ip);
ip->ip_sum = compute_ip_checksum(ip, IP_HDR_SIZE); ip->ip_sum = compute_ip_checksum(ip, IP_HDR_SIZE);
icmph->type = ICMP_ECHO_REPLY; icmph->type = ICMP_ECHO_REPLY;

View File

@ -43,9 +43,9 @@ void rarp_receive(struct ip_udp_hdr *ip, unsigned len)
puts("invalid RARP header\n"); puts("invalid RARP header\n");
} else { } else {
NetCopyIP(&NetOurIP, &arp->ar_data[16]); net_copy_ip(&net_ip, &arp->ar_data[16]);
if (NetServerIP == 0) if (net_server_ip.s_addr == 0)
NetCopyIP(&NetServerIP, &arp->ar_data[6]); net_copy_ip(&net_server_ip, &arp->ar_data[6]);
memcpy(NetServerEther, &arp->ar_data[0], 6); memcpy(NetServerEther, &arp->ar_data[0], 6);
debug_cond(DEBUG_DEV_PKT, "Got good RARP\n"); debug_cond(DEBUG_DEV_PKT, "Got good RARP\n");
net_auto_load(); net_auto_load();
@ -88,7 +88,7 @@ void RarpRequest(void)
rarp->ar_pln = 4; rarp->ar_pln = 4;
rarp->ar_op = htons(RARPOP_REQUEST); rarp->ar_op = htons(RARPOP_REQUEST);
memcpy(&rarp->ar_data[0], NetOurEther, 6); /* source ET addr */ 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 ??*/ /* dest ET addr = source ET addr ??*/
memcpy(&rarp->ar_data[10], NetOurEther, 6); memcpy(&rarp->ar_data[10], NetOurEther, 6);
/* dest IP addr set to broadcast */ /* dest IP addr set to broadcast */

View File

@ -37,8 +37,8 @@ SntpSend(void)
SntpOurPort = 10000 + (get_timer(0) % 4096); SntpOurPort = 10000 + (get_timer(0) % 4096);
sport = NTP_SERVICE_PORT; sport = NTP_SERVICE_PORT;
NetSendUDPPacket(NetServerEther, NetNtpServerIP, sport, SntpOurPort, NetSendUDPPacket(NetServerEther, net_ntp_server, sport, SntpOurPort,
pktlen); pktlen);
} }
static void static void
@ -49,9 +49,8 @@ SntpTimeout(void)
return; return;
} }
static void static void sntp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
SntpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, unsigned src, unsigned len)
unsigned len)
{ {
struct sntp_pkt_t *rpktp = (struct sntp_pkt_t *)pkt; struct sntp_pkt_t *rpktp = (struct sntp_pkt_t *)pkt;
struct rtc_time tm; struct rtc_time tm;
@ -85,7 +84,7 @@ SntpStart(void)
debug("%s\n", __func__); debug("%s\n", __func__);
NetSetTimeout(SNTP_TIMEOUT, SntpTimeout); NetSetTimeout(SNTP_TIMEOUT, SntpTimeout);
net_set_udp_handler(SntpHandler); net_set_udp_handler(sntp_handler);
memset(NetServerEther, 0, sizeof(NetServerEther)); memset(NetServerEther, 0, sizeof(NetServerEther));
SntpSend(); SntpSend();

View File

@ -65,7 +65,7 @@ enum {
TFTP_ERR_FILE_ALREADY_EXISTS = 6, TFTP_ERR_FILE_ALREADY_EXISTS = 6,
}; };
static IPaddr_t TftpRemoteIP; static struct in_addr tftp_remote_ip;
/* The UDP port at their end */ /* The UDP port at their end */
static int TftpRemotePort; static int TftpRemotePort;
/* The UDP port at our end */ /* The UDP port at our end */
@ -146,12 +146,14 @@ static void parse_multicast_oack(char *pkt, int len);
static void static void
mcast_cleanup(void) mcast_cleanup(void)
{ {
if (Mcast_addr) if (net_mcast_addr)
eth_mcast_join(Mcast_addr, 0); eth_mcast_join(net_mcast_addr, 0);
if (Bitmap) if (Bitmap)
free(Bitmap); free(Bitmap);
Bitmap = NULL; Bitmap = NULL;
Mcast_addr = Multicast = Mcast_port = 0; net_mcast_addr.s_addr = 0;
Multicast = 0;
Mcast_port = 0;
TftpEndingBlock = -1; TftpEndingBlock = -1;
} }
@ -433,13 +435,14 @@ TftpSend(void)
break; break;
} }
NetSendUDPPacket(NetServerEther, TftpRemoteIP, TftpRemotePort, NetSendUDPPacket(NetServerEther, tftp_remote_ip, TftpRemotePort,
TftpOurPort, len); TftpOurPort, len);
} }
#ifdef CONFIG_CMD_TFTPPUT #ifdef CONFIG_CMD_TFTPPUT
static void icmp_handler(unsigned type, unsigned code, unsigned dest, 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) { if (type == ICMP_NOT_REACH && code == ICMP_NOT_REACH_PORT) {
/* Oh dear the other end has gone away */ /* Oh dear the other end has gone away */
@ -448,9 +451,8 @@ static void icmp_handler(unsigned type, unsigned code, unsigned dest,
} }
#endif #endif
static void static void tftp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
TftpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, unsigned src, unsigned len)
unsigned len)
{ {
__be16 proto; __be16 proto;
__be16 *s; __be16 *s;
@ -507,7 +509,7 @@ TftpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
#ifdef CONFIG_CMD_TFTPSRV #ifdef CONFIG_CMD_TFTPSRV
case TFTP_WRQ: case TFTP_WRQ:
debug("Got WRQ\n"); debug("Got WRQ\n");
TftpRemoteIP = sip; tftp_remote_ip = sip;
TftpRemotePort = src; TftpRemotePort = src;
TftpOurPort = 1024 + (get_timer(0) % 3072); TftpOurPort = 1024 + (get_timer(0) % 3072);
new_transfer(); new_transfer();
@ -717,13 +719,13 @@ void TftpStart(enum proto_t protocol)
debug("TFTP blocksize = %i, timeout = %ld ms\n", debug("TFTP blocksize = %i, timeout = %ld ms\n",
TftpBlkSizeOption, TftpTimeoutMSecs); TftpBlkSizeOption, TftpTimeoutMSecs);
TftpRemoteIP = NetServerIP; tftp_remote_ip = net_server_ip;
if (BootFile[0] == '\0') { if (BootFile[0] == '\0') {
sprintf(default_filename, "%02X%02X%02X%02X.img", sprintf(default_filename, "%02X%02X%02X%02X.img",
NetOurIP & 0xFF, net_ip.s_addr & 0xFF,
(NetOurIP >> 8) & 0xFF, (net_ip.s_addr >> 8) & 0xFF,
(NetOurIP >> 16) & 0xFF, (net_ip.s_addr >> 16) & 0xFF,
(NetOurIP >> 24) & 0xFF); (net_ip.s_addr >> 24) & 0xFF);
strncpy(tftp_filename, default_filename, MAX_LEN); strncpy(tftp_filename, default_filename, MAX_LEN);
tftp_filename[MAX_LEN-1] = 0; tftp_filename[MAX_LEN-1] = 0;
@ -737,7 +739,7 @@ void TftpStart(enum proto_t protocol)
strncpy(tftp_filename, BootFile, MAX_LEN); strncpy(tftp_filename, BootFile, MAX_LEN);
tftp_filename[MAX_LEN-1] = 0; tftp_filename[MAX_LEN-1] = 0;
} else { } else {
TftpRemoteIP = string_to_ip(BootFile); tftp_remote_ip = string_to_ip(BootFile);
strncpy(tftp_filename, p + 1, MAX_LEN); strncpy(tftp_filename, p + 1, MAX_LEN);
tftp_filename[MAX_LEN-1] = 0; tftp_filename[MAX_LEN-1] = 0;
} }
@ -750,16 +752,17 @@ void TftpStart(enum proto_t protocol)
#else #else
"from", "from",
#endif #endif
&TftpRemoteIP, &NetOurIP); &tftp_remote_ip, &net_ip);
/* Check if we need to send across this subnet */ /* Check if we need to send across this subnet */
if (NetOurGatewayIP && NetOurSubnetMask) { if (net_gateway.s_addr && net_netmask.s_addr) {
IPaddr_t OurNet = NetOurIP & NetOurSubnetMask; struct in_addr our_net;
IPaddr_t RemoteNet = TftpRemoteIP & NetOurSubnetMask; struct in_addr remote_net;
if (OurNet != RemoteNet) our_net.s_addr = net_ip.s_addr & net_netmask.s_addr;
printf("; sending through gateway %pI4", remote_net.s_addr = tftp_remote_ip.s_addr & net_netmask.s_addr;
&NetOurGatewayIP); if (our_net.s_addr != remote_net.s_addr)
printf("; sending through gateway %pI4", &net_gateway);
} }
putc('\n'); putc('\n');
@ -792,7 +795,7 @@ void TftpStart(enum proto_t protocol)
TftpTimeoutCountMax = TftpRRQTimeoutCountMax; TftpTimeoutCountMax = TftpRRQTimeoutCountMax;
NetSetTimeout(TftpTimeoutMSecs, TftpTimeout); NetSetTimeout(TftpTimeoutMSecs, TftpTimeout);
net_set_udp_handler(TftpHandler); net_set_udp_handler(tftp_handler);
#ifdef CONFIG_CMD_TFTPPUT #ifdef CONFIG_CMD_TFTPPUT
net_set_icmp_handler(icmp_handler); net_set_icmp_handler(icmp_handler);
#endif #endif
@ -833,7 +836,7 @@ TftpStartServer(void)
tftp_filename[0] = 0; tftp_filename[0] = 0;
printf("Using %s device\n", eth_get_name()); 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); printf("Load address: 0x%lx\n", load_addr);
puts("Loading: *\b"); puts("Loading: *\b");
@ -854,7 +857,7 @@ TftpStartServer(void)
#endif #endif
TftpState = STATE_RECV_WRQ; 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 */ /* zero out server ether in case the server ip has changed */
memset(NetServerEther, 0, 6); memset(NetServerEther, 0, 6);
@ -880,7 +883,7 @@ TftpStartServer(void)
static void parse_multicast_oack(char *pkt, int len) static void parse_multicast_oack(char *pkt, int len)
{ {
int i; int i;
IPaddr_t addr; struct in_addr addr;
char *mc_adr, *port, *mc; char *mc_adr, *port, *mc;
mc_adr = port = mc = NULL; mc_adr = port = mc = NULL;
@ -935,11 +938,11 @@ static void parse_multicast_oack(char *pkt, int len)
Multicast = 1; Multicast = 1;
} }
addr = string_to_ip(mc_adr); addr = string_to_ip(mc_adr);
if (Mcast_addr != addr) { if (net_mcast_addr.s_addr != addr.s_addr) {
if (Mcast_addr) if (net_mcast_addr.s_addr)
eth_mcast_join(Mcast_addr, 0); eth_mcast_join(net_mcast_addr, 0);
Mcast_addr = addr; net_mcast_addr = addr;
if (eth_mcast_join(Mcast_addr, 1)) { if (eth_mcast_join(net_mcast_addr, 1)) {
printf("Fail to set mcast, revert to TFTP\n"); printf("Fail to set mcast, revert to TFTP\n");
ProhibitMcast = 1; ProhibitMcast = 1;
mcast_cleanup(); mcast_cleanup();

View File

@ -20,7 +20,7 @@ DECLARE_GLOBAL_DATA_PTR;
static int dm_test_eth(struct dm_test_state *dms) 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"); setenv("ethact", "eth@10002000");
ut_assertok(NetLoop(PING)); 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) 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"); setenv("ethact", "eth0");
ut_assertok(NetLoop(PING)); ut_assertok(NetLoop(PING));
ut_asserteq_str("eth@10002000", getenv("ethact")); 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) 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 */ /* Expected to be "eth@10003000" because of ethprime variable */
setenv("ethact", NULL); setenv("ethact", NULL);
@ -87,7 +87,7 @@ static int dm_test_eth_rotate(struct dm_test_state *dms)
char ethaddr[18]; char ethaddr[18];
/* Invalidate eth1's MAC address */ /* 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")); strcpy(ethaddr, getenv("eth1addr"));
setenv("eth1addr", NULL); 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) 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 * eth1 is disabled and netretry is yes, so the ping should succeed and