Commit 049a95a7 authored by Joe Hershberger's avatar Joe Hershberger Committed by Simon Glass

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: default avatarJoe Hershberger <joe.hershberger@ni.com>
Acked-by: default avatarSimon Glass <sjg@chromium.org>
parent 2ea4cfde
......@@ -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
......@@ -260,8 +260,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 +331,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 +352,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 +421,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 */
......
......@@ -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);
......
......@@ -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);
......
......@@ -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 */
......
......@@ -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);
......
......@@ -826,7 +826,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));
}
......
......@@ -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,17 +459,19 @@ 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 */
......@@ -478,8 +481,8 @@ extern ushort NetBootFileSize; /* Our boot file size in blocks */
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 */
......@@ -513,7 +516,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 +536,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 +562,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 +636,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 +647,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
......@@ -682,9 +685,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;
......@@ -700,15 +703,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 */
......@@ -788,10 +791,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);
......
......@@ -12,23 +12,25 @@
#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;
}
......@@ -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;
......
......@@ -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);
......
This diff is collapsed.
......@@ -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 */
......
......@@ -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.
* <