{
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);
}
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)
* 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
#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
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) {
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;
}
if (NetLoop(SNTP) < 0) {
printf("SNTP failed: host %pI4 not responding\n",
- &NetNtpServerIP);
+ &net_ntp_server);
return CMD_RET_FAILURE;
}
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 */
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);
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 */
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 */
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)
/* 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) {
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)
}
}
-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;
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);
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);
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)
{
* 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;
}
/* 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 */
*/
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;
};
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);
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;
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);
/* 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));
}
#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.
* @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);
/**
* @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.
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
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 */
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 */
*
* Note:
*
- * All variables of type IPaddr_t are stored in NETWORK byte order
+ * All variables of type struct in_addr are stored in NETWORK byte order
* (big endian).
*/
/* net.c */
/** BOOTP EXTENTIONS **/
-extern IPaddr_t NetOurGatewayIP; /* Our gateway IP address */
-extern IPaddr_t NetOurSubnetMask; /* Our subnet mask (0 = unknown) */
-extern IPaddr_t NetOurDNSIP; /* Our Domain Name Server (0 = unknown) */
+extern struct in_addr net_gateway; /* Our gateway IP address */
+extern struct in_addr net_netmask; /* Our subnet mask (0 = unknown) */
+/* Our Domain Name Server (0 = unknown) */
+extern struct in_addr net_dns_server;
#if defined(CONFIG_BOOTP_DNS2)
-extern IPaddr_t NetOurDNS2IP; /* Our 2nd Domain Name Server (0 = unknown) */
+/* Our 2nd Domain Name Server (0 = unknown) */
+extern struct in_addr net_dns_server2;
#endif
extern char NetOurNISDomain[32]; /* Our NIS domain */
extern char NetOurHostName[32]; /* Our hostname */
extern 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 */
#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)
#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 */
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);
/**
* @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
#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
* 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;
}
/* 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 */
}
/* 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);
#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;
}
# 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;
{
/* 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;
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);
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;
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)) {
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
/*
* 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);
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);
NetSendPacket(NetTxPacket, NetArpWaitTxPacketSize);
/* no arp request pending now */
- NetArpWaitPacketIP = 0;
+ net_arp_wait_packet_ip.s_addr = 0;
NetArpWaitTxPacketSize = 0;
NetArpWaitPacketMAC = NULL;
#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;
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);
#if defined(CONFIG_CMD_DHCP)
static dhcp_state_t dhcp_state = INIT;
static unsigned long dhcp_leasetime;
-static IPaddr_t NetDHCPServerIP;
-static void DhcpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
- unsigned len);
+static struct in_addr dhcp_server_ip;
+static void dhcp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
+ unsigned src, unsigned len);
/* For Debug */
#if 0
static void BootpCopyNetParams(struct Bootp_t *bp)
{
#if !defined(CONFIG_BOOTP_SERVERIP)
- IPaddr_t tmp_ip;
+ struct in_addr tmp_ip;
- NetCopyIP(&tmp_ip, &bp->bp_siaddr);
- if (tmp_ip != 0)
- NetCopyIP(&NetServerIP, &bp->bp_siaddr);
+ net_copy_ip(&tmp_ip, &bp->bp_siaddr);
+ if (tmp_ip.s_addr != 0)
+ net_copy_ip(&net_server_ip, &bp->bp_siaddr);
memcpy(NetServerEther, ((struct ethernet_hdr *)NetRxPacket)->et_src, 6);
if (strlen(bp->bp_file) > 0)
copy_filename(BootFile, bp->bp_file, sizeof(BootFile));
if (*BootFile)
setenv("bootfile", BootFile);
#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)
switch (*ext) {
/* Fixed length fields */
case 1: /* Subnet mask */
- if (NetOurSubnetMask == 0)
- NetCopyIP(&NetOurSubnetMask, (IPaddr_t *) (ext + 2));
+ if (net_netmask.s_addr == 0)
+ net_copy_ip(&net_netmask, (struct in_addr *)(ext + 2));
break;
case 2: /* Time offset - Not yet supported */
break;
/* Variable length fields */
case 3: /* Gateways list */
- if (NetOurGatewayIP == 0)
- NetCopyIP(&NetOurGatewayIP, (IPaddr_t *) (ext + 2));
+ if (net_gateway.s_addr == 0)
+ net_copy_ip(&net_gateway, (struct in_addr *)(ext + 2));
break;
case 4: /* Time server - Not yet supported */
break;
case 5: /* IEN-116 name server - Not yet supported */
break;
case 6:
- if (NetOurDNSIP == 0)
- NetCopyIP(&NetOurDNSIP, (IPaddr_t *) (ext + 2));
+ if (net_dns_server.s_addr == 0)
+ net_copy_ip(&net_dns_server,
+ (struct in_addr *)(ext + 2));
#if defined(CONFIG_BOOTP_DNS2)
- if ((NetOurDNS2IP == 0) && (size > 4))
- NetCopyIP(&NetOurDNS2IP, (IPaddr_t *) (ext + 2 + 4));
+ if ((net_dns_server2.s_addr == 0) && (size > 4))
+ net_copy_ip(&net_dns_server2,
+ (struct in_addr *)(ext + 2 + 4));
#endif
break;
case 7: /* Log server - Not yet supported */
break;
#if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER)
case 42: /* NTP server IP */
- NetCopyIP(&NetNtpServerIP, (IPaddr_t *) (ext + 2));
+ net_copy_ip(&net_ntp_server, (struct in_addr *)(ext + 2));
break;
#endif
/* Application layer fields */
}
debug("[BOOTP] Received fields:\n");
- if (NetOurSubnetMask)
- debug("NetOurSubnetMask : %pI4\n", &NetOurSubnetMask);
+ if (net_netmask.s_addr)
+ debug("net_netmask : %pI4\n", &net_netmask);
- if (NetOurGatewayIP)
- debug("NetOurGatewayIP : %pI4", &NetOurGatewayIP);
+ if (net_gateway.s_addr)
+ debug("net_gateway : %pI4", &net_gateway);
if (NetBootFileSize)
debug("NetBootFileSize : %d\n", NetBootFileSize);
debug("NetBootFileSize: %d\n", NetBootFileSize);
#if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER)
- if (NetNtpServerIP)
- debug("NetNtpServerIP : %pI4\n", &NetNtpServerIP);
+ if (net_ntp_server)
+ debug("net_ntp_server : %pI4\n", &net_ntp_server);
#endif
}
/*
* Handle a BOOTP received packet.
*/
-static void
-BootpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
- unsigned len)
+static void bootp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
+ unsigned src, unsigned len)
{
struct Bootp_t *bp;
* Initialize BOOTP extension fields in the request.
*/
#if defined(CONFIG_CMD_DHCP)
-static int DhcpExtended(u8 *e, int message_type, IPaddr_t ServerID,
- IPaddr_t RequestedIP)
+static int dhcp_extended(u8 *e, int message_type, struct in_addr server_ip,
+ struct in_addr requested_ip)
{
u8 *start = e;
u8 *cnt;
*e++ = (576 - 312 + OPT_FIELD_SIZE) >> 8;
*e++ = (576 - 312 + OPT_FIELD_SIZE) & 0xff;
- if (ServerID) {
- int tmp = ntohl(ServerID);
+ if (server_ip.s_addr) {
+ int tmp = ntohl(server_ip.s_addr);
*e++ = 54; /* ServerID */
*e++ = 4;
*e++ = tmp & 0xff;
}
- if (RequestedIP) {
- int tmp = ntohl(RequestedIP);
+ if (requested_ip.s_addr) {
+ int tmp = ntohl(requested_ip.s_addr);
*e++ = 50; /* Requested IP */
*e++ = 4;
/*
* 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;
ulong rand_ms;
#endif
ulong BootpID;
+ struct in_addr zero_ip;
+ struct in_addr bcast_ip;
bootstage_mark_name(BOOTSTAGE_ID_BOOTP_START, "bootp_start");
#if defined(CONFIG_CMD_DHCP)
bp->bp_hlen = HWL_ETHER;
bp->bp_hops = 0;
bp->bp_secs = htons(get_timer(0) / 1000);
- NetWriteIP(&bp->bp_ciaddr, 0);
- NetWriteIP(&bp->bp_yiaddr, 0);
- NetWriteIP(&bp->bp_siaddr, 0);
- NetWriteIP(&bp->bp_giaddr, 0);
+ zero_ip.s_addr = 0;
+ net_write_ip(&bp->bp_ciaddr, zero_ip);
+ net_write_ip(&bp->bp_yiaddr, zero_ip);
+ net_write_ip(&bp->bp_siaddr, zero_ip);
+ net_write_ip(&bp->bp_giaddr, zero_ip);
memcpy(bp->bp_chaddr, NetOurEther, 6);
copy_filename(bp->bp_file, BootFile, sizeof(bp->bp_file));
/* Request additional information from the BOOTP/DHCP server */
#if defined(CONFIG_CMD_DHCP)
- extlen = DhcpExtended((u8 *)bp->bp_vend, DHCP_DISCOVER, 0, 0);
+ extlen = dhcp_extended((u8 *)bp->bp_vend, DHCP_DISCOVER, zero_ip,
+ zero_ip);
#else
- extlen = BootpExtended((u8 *)bp->bp_vend);
+ extlen = bootp_extended((u8 *)bp->bp_vend);
#endif
/*
*/
iplen = BOOTP_HDR_SIZE - OPT_FIELD_SIZE + extlen;
pktlen = eth_hdr_size + IP_UDP_HDR_SIZE + iplen;
- net_set_udp_header(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen);
+ bcast_ip.s_addr = 0xFFFFFFFFL;
+ net_set_udp_header(iphdr, bcast_ip, PORT_BOOTPS, PORT_BOOTPC, iplen);
NetSetTimeout(bootp_timeout, BootpTimeout);
#if defined(CONFIG_CMD_DHCP)
dhcp_state = SELECTING;
- net_set_udp_handler(DhcpHandler);
+ net_set_udp_handler(dhcp_handler);
#else
- net_set_udp_handler(BootpHandler);
+ net_set_udp_handler(bootp_handler);
#endif
NetSendPacket(NetTxPacket, pktlen);
}
oplen = *(popt + 1);
switch (*popt) {
case 1:
- NetCopyIP(&NetOurSubnetMask, (popt + 2));
+ net_copy_ip(&net_netmask, (popt + 2));
break;
#if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_TIMEOFFSET)
case 2: /* Time offset */
break;
#endif
case 3:
- NetCopyIP(&NetOurGatewayIP, (popt + 2));
+ net_copy_ip(&net_gateway, (popt + 2));
break;
case 6:
- NetCopyIP(&NetOurDNSIP, (popt + 2));
+ net_copy_ip(&net_dns_server, (popt + 2));
#if defined(CONFIG_BOOTP_DNS2)
if (*(popt + 1) > 4)
- NetCopyIP(&NetOurDNS2IP, (popt + 2 + 4));
+ net_copy_ip(&net_dns_server2, (popt + 2 + 4));
#endif
break;
case 12:
break;
#if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER)
case 42: /* NTP server IP */
- NetCopyIP(&NetNtpServerIP, (popt + 2));
+ net_copy_ip(&net_ntp_server, (popt + 2));
break;
#endif
case 51:
case 53: /* Ignore Message Type Option */
break;
case 54:
- NetCopyIP(&NetDHCPServerIP, (popt + 2));
+ net_copy_ip(&dhcp_server_ip, (popt + 2));
break;
case 58: /* Ignore Renewal Time Option */
break;
struct Bootp_t *bp;
int pktlen, iplen, extlen;
int eth_hdr_size;
- IPaddr_t OfferedIP;
+ struct in_addr offered_ip;
+ struct in_addr zero_ip;
+ struct in_addr bcast_ip;
debug("DhcpSendRequestPkt: Sending DHCPREQUEST\n");
pkt = NetTxPacket;
* RFC3046 requires Relay Agents to discard packets with
* nonzero and offered giaddr
*/
- NetWriteIP(&bp->bp_giaddr, 0);
+ zero_ip.s_addr = 0;
+ net_write_ip(&bp->bp_giaddr, zero_ip);
memcpy(bp->bp_chaddr, NetOurEther, 6);
*/
/* Copy offered IP into the parameters request list */
- NetCopyIP(&OfferedIP, &bp_offer->bp_yiaddr);
- extlen = DhcpExtended((u8 *)bp->bp_vend, DHCP_REQUEST,
- NetDHCPServerIP, OfferedIP);
+ net_copy_ip(&offered_ip, &bp_offer->bp_yiaddr);
+ extlen = dhcp_extended((u8 *)bp->bp_vend, DHCP_REQUEST,
+ dhcp_server_ip, offered_ip);
iplen = BOOTP_HDR_SIZE - OPT_FIELD_SIZE + extlen;
pktlen = eth_hdr_size + IP_UDP_HDR_SIZE + iplen;
- net_set_udp_header(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen);
+ bcast_ip.s_addr = 0xFFFFFFFFL;
+ net_set_udp_header(iphdr, bcast_ip, PORT_BOOTPS, PORT_BOOTPC, iplen);
#ifdef CONFIG_BOOTP_DHCP_REQUEST_DELAY
udelay(CONFIG_BOOTP_DHCP_REQUEST_DELAY);
/*
* Handle DHCP received packets.
*/
-static void
-DhcpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
- unsigned len)
+static void dhcp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
+ unsigned src, unsigned len)
{
struct Bootp_t *bp = (struct Bootp_t *)pkt;
BootpCopyNetParams(bp);
dhcp_state = BOUND;
printf("DHCP client bound to address %pI4 (%lu ms)\n",
- &NetOurIP, get_timer(bootp_start));
+ &net_ip, get_timer(bootp_start));
bootstage_mark_name(BOOTSTAGE_ID_BOOTP_STOP,
"bootp_stop");
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 */
* Copyright (c) 2009 Robin Getz <rgetz@blackfin.uclinux.org>
*
* This is a simple DNS implementation for U-Boot. It will use the first IP
- * in the DNS response as NetServerIP. This can then be used for any other
+ * in the DNS response as net_server_ip. This can then be used for any other
* network related activities.
*
* The packet handling is partly based on TADNS, original copyrights
DnsOurPort = random_port();
- NetSendUDPPacket(NetServerEther, NetOurDNSIP, DNS_SERVICE_PORT,
- DnsOurPort, n);
+ NetSendUDPPacket(NetServerEther, net_dns_server, DNS_SERVICE_PORT,
+ DnsOurPort, n);
debug("DNS packet sent\n");
}
net_set_state(NETLOOP_FAIL);
}
-static void
-DnsHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, unsigned len)
+static void dns_handler(uchar *pkt, unsigned dest, struct in_addr sip,
+ unsigned src, unsigned len)
{
struct header *header;
const unsigned char *p, *e, *s;
u16 type, i;
int found, stop, dlen;
char IPStr[22];
- IPaddr_t IPAddress;
+ struct in_addr ip_addr;
debug("%s\n", __func__);
dlen = get_unaligned_be16(p+10);
p += 12;
- memcpy(&IPAddress, p, 4);
+ memcpy(&ip_addr, p, 4);
if (p + dlen <= e) {
- ip_to_string(IPAddress, IPStr);
+ ip_to_string(ip_addr, IPStr);
printf("%s\n", IPStr);
if (NetDNSenvvar)
setenv(NetDNSenvvar, IPStr);
debug("%s\n", __func__);
NetSetTimeout(DNS_TIMEOUT, DnsTimeout);
- net_set_udp_handler(DnsHandler);
+ net_set_udp_handler(dns_handler);
/* Clear a previous MAC address, the server IP might have changed. */
memset(NetServerEther, 0, sizeof(NetServerEther));
* mcast_addr: multicast ipaddr from which multicast Mac is made
* join: 1=join, 0=leave.
*/
-int eth_mcast_join(IPaddr_t mcast_ip, int join)
+int eth_mcast_join(struct in_addr mcast_ip, int join)
{
u8 mcast_mac[6];
if (!eth_current || !eth_current->mcast)
return -1;
- mcast_mac[5] = htonl(mcast_ip) & 0xff;
- mcast_mac[4] = (htonl(mcast_ip)>>8) & 0xff;
- mcast_mac[3] = (htonl(mcast_ip)>>16) & 0x7f;
+ mcast_mac[5] = htonl(mcast_ip.s_addr) & 0xff;
+ mcast_mac[4] = (htonl(mcast_ip.s_addr)>>8) & 0xff;
+ mcast_mac[3] = (htonl(mcast_ip.s_addr)>>16) & 0x7f;
mcast_mac[2] = 0x5e;
mcast_mac[1] = 0x0;
mcast_mac[0] = 0x1;
DISABLED
} state = DISABLED;
-static IPaddr_t ip;
+static struct in_addr ip;
static int timeout_ms = -1;
static unsigned deadline_ms;
static unsigned conflicts;
* Pick a random link local IP address on 169.254/16, except that
* the first and last 256 addresses are reserved.
*/
-static IPaddr_t pick(void)
+static struct in_addr pick(void)
{
unsigned tmp;
+ struct in_addr ip;
do {
tmp = rand_r(&seed) & IN_CLASSB_HOST;
} while (tmp > (IN_CLASSB_HOST - 0x0200));
- return (IPaddr_t) htonl((LINKLOCAL_ADDR + 0x0100) + tmp);
+ ip.s_addr = htonl((LINKLOCAL_ADDR + 0x0100) + tmp);
+ return ip;
}
/**
void link_local_start(void)
{
- ip = getenv_IPaddr("llipaddr");
- if (ip != 0 && (ntohl(ip) & IN_CLASSB_NET) != LINKLOCAL_ADDR) {
+ ip = getenv_ip("llipaddr");
+ if (ip.s_addr != 0 &&
+ (ntohl(ip.s_addr) & IN_CLASSB_NET) != LINKLOCAL_ADDR) {
puts("invalid link address");
net_set_state(NETLOOP_FAIL);
return;
}
- NetOurSubnetMask = IN_CLASSB_NET;
+ net_netmask.s_addr = IN_CLASSB_NET;
seed = seed_mac();
- if (ip == 0)
+ if (ip.s_addr == 0)
ip = pick();
state = PROBE;
/* timeouts in the PROBE state mean no conflicting ARP packets
have been received, so we can progress through the states */
if (nprobes < PROBE_NUM) {
+ struct in_addr zero_ip = {.s_addr = 0};
+
nprobes++;
debug_cond(DEBUG_LL_STATE, "probe/%u %s@%pI4\n",
nprobes, eth_get_name(), &ip);
- arp_raw_request(0, NetEtherNullAddr, ip);
+ arp_raw_request(zero_ip, NetEtherNullAddr, ip);
timeout_ms = PROBE_MIN * 1000;
timeout_ms += random_delay_ms(PROBE_MAX - PROBE_MIN);
} else {
/* Switch to monitor state */
state = MONITOR;
printf("Successfully assigned %pI4\n", &ip);
- NetCopyIP(&NetOurIP, &ip);
+ net_copy_ip(&net_ip, &ip);
ready = 1;
conflicts = 0;
timeout_ms = -1;
{
int source_ip_conflict;
int target_ip_conflict;
- IPaddr_t null_ip = 0;
+ struct in_addr null_ip = {.s_addr = 0};
if (state == DISABLED)
return;
state = PROBE;
debug("defend conflict -- starting over\n");
ready = 0;
- NetOurIP = 0;
+ net_ip.s_addr = 0;
/* restart the whole protocol */
ip = pick();
/** BOOTP EXTENTIONS **/
/* Our subnet mask (0=unknown) */
-IPaddr_t NetOurSubnetMask;
+struct in_addr net_netmask;
/* Our gateways IP address */
-IPaddr_t NetOurGatewayIP;
+struct in_addr net_gateway;
/* Our DNS IP address */
-IPaddr_t NetOurDNSIP;
+struct in_addr net_dns_server;
#if defined(CONFIG_BOOTP_DNS2)
/* Our 2nd DNS IP address */
-IPaddr_t NetOurDNS2IP;
+struct in_addr net_dns_server2;
#endif
/* Our NIS domain */
char NetOurNISDomain[32] = {0,};
ushort NetBootFileSize;
#ifdef CONFIG_MCAST_TFTP /* Multicast TFTP */
-IPaddr_t Mcast_addr;
+struct in_addr net_mcast_addr;
#endif
/** END OF BOOTP EXTENTIONS **/
/* Boot server enet address */
uchar NetServerEther[6];
/* Our IP addr (0 = unknown) */
-IPaddr_t NetOurIP;
+struct in_addr net_ip;
/* Server IP addr (0 = unknown) */
-IPaddr_t NetServerIP;
+struct in_addr net_server_ip;
/* Current receive packet */
uchar *NetRxPacket;
/* Current rx packet length */
#if defined(CONFIG_CMD_SNTP)
/* NTP server IP address */
-IPaddr_t NetNtpServerIP;
+struct in_addr net_ntp_server;
/* offset time from UTC */
int NetTimeOffset;
#endif
/* update only when the environment has changed */
if (env_changed_id != env_id) {
- NetOurIP = getenv_IPaddr("ipaddr");
- NetOurGatewayIP = getenv_IPaddr("gatewayip");
- NetOurSubnetMask = getenv_IPaddr("netmask");
- NetServerIP = getenv_IPaddr("serverip");
+ net_ip = getenv_ip("ipaddr");
+ net_gateway = getenv_ip("gatewayip");
+ net_netmask = getenv_ip("netmask");
+ net_server_ip = getenv_ip("serverip");
NetOurNativeVLAN = getenv_VLAN("nvlan");
NetOurVLAN = getenv_VLAN("vlan");
#if defined(CONFIG_CMD_DNS)
- NetOurDNSIP = getenv_IPaddr("dnsip");
+ net_dns_server = getenv_ip("dnsip");
#endif
env_changed_id = env_id;
}
#if defined(CONFIG_CMD_DHCP)
case DHCP:
BootpReset();
- NetOurIP = 0;
+ net_ip.s_addr = 0;
DhcpRequest(); /* Basically same as BOOTP */
break;
#endif
case BOOTP:
BootpReset();
- NetOurIP = 0;
+ net_ip.s_addr = 0;
BootpRequest();
break;
#if defined(CONFIG_CMD_RARP)
case RARP:
RarpTry = 0;
- NetOurIP = 0;
+ net_ip.s_addr = 0;
RarpRequest();
break;
#endif
*/
if (ctrlc()) {
/* cancel any ARP that may not have completed */
- NetArpWaitPacketIP = 0;
+ net_arp_wait_packet_ip.s_addr = 0;
net_cleanup_loop();
eth_halt();
*/
static void dummy_handler(uchar *pkt, unsigned dport,
- IPaddr_t sip, unsigned sport,
+ struct in_addr sip, unsigned sport,
unsigned len)
{
}
}
}
-int NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport,
+int NetSendUDPPacket(uchar *ether, struct in_addr dest, int dport, int sport,
int payload_len)
{
uchar *pkt;
return -1;
/* convert to new style broadcast */
- if (dest == 0)
- dest = 0xFFFFFFFF;
+ if (dest.s_addr == 0)
+ dest.s_addr = 0xFFFFFFFF;
/* if broadcast, make the ether address a broadcast and don't do ARP */
- if (dest == 0xFFFFFFFF)
+ if (dest.s_addr == 0xFFFFFFFF)
ether = NetBcastAddr;
pkt = (uchar *)NetTxPacket;
debug_cond(DEBUG_DEV_PKT, "sending ARP for %pI4\n", &dest);
/* save the ip and eth addr for the packet to send after arp */
- NetArpWaitPacketIP = dest;
+ net_arp_wait_packet_ip = dest;
NetArpWaitPacketMAC = ether;
/* size of the waiting packet */
* @parma ip IP packet containing the ICMP
*/
static void receive_icmp(struct ip_udp_hdr *ip, int len,
- IPaddr_t src_ip, struct ethernet_hdr *et)
+ struct in_addr src_ip, struct ethernet_hdr *et)
{
struct icmp_hdr *icmph = (struct icmp_hdr *)&ip->udp_src;
{
struct ethernet_hdr *et;
struct ip_udp_hdr *ip;
- IPaddr_t dst_ip;
- IPaddr_t src_ip;
+ struct in_addr dst_ip;
+ struct in_addr src_ip;
int eth_proto;
#if defined(CONFIG_CMD_CDP)
int iscdp;
return;
}
/* If it is not for us, ignore it */
- dst_ip = NetReadIP(&ip->ip_dst);
- if (NetOurIP && dst_ip != NetOurIP && dst_ip != 0xFFFFFFFF) {
+ dst_ip = net_read_ip(&ip->ip_dst);
+ if (net_ip.s_addr && dst_ip.s_addr != net_ip.s_addr &&
+ dst_ip.s_addr != 0xFFFFFFFF) {
#ifdef CONFIG_MCAST_TFTP
- if (Mcast_addr != dst_ip)
+ if (net_mcast_addr != dst_ip)
#endif
return;
}
/* Read source IP address for later use */
- src_ip = NetReadIP(&ip->ip_src);
+ src_ip = net_read_ip(&ip->ip_src);
/*
* The function returns the unchanged packet if it's not
* a fragment, and either the complete packet or NULL if
xsum = ip->ip_p;
xsum += (ntohs(ip->udp_len));
- xsum += (ntohl(ip->ip_src) >> 16) & 0x0000ffff;
- xsum += (ntohl(ip->ip_src) >> 0) & 0x0000ffff;
- xsum += (ntohl(ip->ip_dst) >> 16) & 0x0000ffff;
- xsum += (ntohl(ip->ip_dst) >> 0) & 0x0000ffff;
+ xsum += (ntohl(ip->ip_src.s_addr) >> 16) & 0x0000ffff;
+ xsum += (ntohl(ip->ip_src.s_addr) >> 0) & 0x0000ffff;
+ xsum += (ntohl(ip->ip_dst.s_addr) >> 16) & 0x0000ffff;
+ xsum += (ntohl(ip->ip_dst.s_addr) >> 0) & 0x0000ffff;
sumlen = ntohs(ip->udp_len);
sumptr = (ushort *) &(ip->udp_src);
/* Fall through */
#if defined(CONFIG_CMD_PING)
case PING:
- if (NetPingIP == 0) {
+ if (net_ping_ip.s_addr == 0) {
puts("*** ERROR: ping address not given\n");
return 1;
}
#endif
#if defined(CONFIG_CMD_SNTP)
case SNTP:
- if (NetNtpServerIP == 0) {
+ if (net_ntp_server.s_addr == 0) {
puts("*** ERROR: NTP server address not given\n");
return 1;
}
#endif
#if defined(CONFIG_CMD_DNS)
case DNS:
- if (NetOurDNSIP == 0) {
+ if (net_dns_server.s_addr == 0) {
puts("*** ERROR: DNS server address not given\n");
return 1;
}
#endif
case TFTPGET:
case TFTPPUT:
- if (NetServerIP == 0) {
+ if (net_server_ip.s_addr == 0) {
puts("*** ERROR: `serverip' not set\n");
return 1;
}
case NETCONS:
case TFTPSRV:
- if (NetOurIP == 0) {
+ if (net_ip.s_addr == 0) {
puts("*** ERROR: `ipaddr' not set\n");
return 1;
}
}
}
-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;
ip->ip_ttl = 255;
ip->ip_sum = 0;
/* already in network byte order */
- NetCopyIP((void *)&ip->ip_src, &source);
+ net_copy_ip((void *)&ip->ip_src, &source);
/* already in network byte order */
- NetCopyIP((void *)&ip->ip_dst, &dest);
+ net_copy_ip((void *)&ip->ip_dst, &dest);
}
-void net_set_udp_header(uchar *pkt, IPaddr_t dest, int dport, int sport,
+void net_set_udp_header(uchar *pkt, struct in_addr dest, int dport, int sport,
int len)
{
struct ip_udp_hdr *ip = (struct ip_udp_hdr *)pkt;
if (len & 1)
pkt[IP_UDP_HDR_SIZE + len] = 0;
- net_set_ip_header(pkt, dest, NetOurIP);
+ net_set_ip_header(pkt, dest, net_ip);
ip->ip_len = htons(IP_UDP_HDR_SIZE + len);
ip->ip_p = IPPROTO_UDP;
ip->ip_sum = compute_ip_checksum(ip, IP_HDR_SIZE);
}
#endif
-void ip_to_string(IPaddr_t x, char *s)
+void ip_to_string(struct in_addr x, char *s)
{
- x = ntohl(x);
+ x.s_addr = ntohl(x.s_addr);
sprintf(s, "%d.%d.%d.%d",
- (int) ((x >> 24) & 0xff),
- (int) ((x >> 16) & 0xff),
- (int) ((x >> 8) & 0xff), (int) ((x >> 0) & 0xff)
+ (int) ((x.s_addr >> 24) & 0xff),
+ (int) ((x.s_addr >> 16) & 0xff),
+ (int) ((x.s_addr >> 8) & 0xff),
+ (int) ((x.s_addr >> 0) & 0xff)
);
}
static char filefh[NFS_FHSIZE]; /* file handle of kernel image */
static enum net_loop_state nfs_download_state;
-static IPaddr_t NfsServerIP;
+static struct in_addr nfs_server_ip;
static int NfsSrvMountPort;
static int NfsSrvNfsPort;
static int NfsOurPort;
else
sport = NfsSrvNfsPort;
- NetSendUDPPacket(NetServerEther, NfsServerIP, sport, NfsOurPort,
- pktlen);
+ NetSendUDPPacket(NetServerEther, nfs_server_ip, sport, NfsOurPort,
+ pktlen);
}
/**************************************************************************
}
}
-static void
-NfsHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, unsigned len)
+static void nfs_handler(uchar *pkt, unsigned dest, struct in_addr sip,
+ unsigned src, unsigned len)
{
int rlen;
int reply;
debug("%s\n", __func__);
nfs_download_state = NETLOOP_FAIL;
- NfsServerIP = NetServerIP;
+ nfs_server_ip = net_server_ip;
nfs_path = (char *)nfs_path_buff;
if (nfs_path == NULL) {
if (BootFile[0] == '\0') {
sprintf(default_filename, "/nfsroot/%02X%02X%02X%02X.img",
- NetOurIP & 0xFF,
- (NetOurIP >> 8) & 0xFF,
- (NetOurIP >> 16) & 0xFF,
- (NetOurIP >> 24) & 0xFF);
+ net_ip.s_addr & 0xFF,
+ (net_ip.s_addr >> 8) & 0xFF,
+ (net_ip.s_addr >> 16) & 0xFF,
+ (net_ip.s_addr >> 24) & 0xFF);
strcpy(nfs_path, default_filename);
printf("*** Warning: no boot file name; using '%s'\n",
p = strchr(p, ':');
if (p != NULL) {
- NfsServerIP = string_to_ip(BootFile);
+ nfs_server_ip = string_to_ip(BootFile);
++p;
strcpy(nfs_path, p);
} else {
printf("Using %s device\n", eth_get_name());
- printf("File transfer via NFS from server %pI4"
- "; our IP address is %pI4", &NfsServerIP, &NetOurIP);
+ printf("File transfer via NFS from server %pI4; our IP address is %pI4",
+ &nfs_server_ip, &net_ip);
/* Check if we need to send across this subnet */
- if (NetOurGatewayIP && NetOurSubnetMask) {
- IPaddr_t OurNet = NetOurIP & NetOurSubnetMask;
- IPaddr_t ServerNet = NetServerIP & NetOurSubnetMask;
+ if (net_gateway.s_addr && net_netmask.s_addr) {
+ struct in_addr our_net;
+ struct in_addr server_net;
- if (OurNet != ServerNet)
+ our_net.s_addr = net_ip.s_addr & net_netmask.s_addr;
+ server_net.s_addr = net_server_ip.s_addr & net_netmask.s_addr;
+ if (our_net.s_addr != server_net.s_addr)
printf("; sending through gateway %pI4",
- &NetOurGatewayIP);
+ &net_gateway);
}
printf("\nFilename '%s/%s'.", nfs_path, nfs_filename);
"Loading: *\b", load_addr);
NetSetTimeout(nfs_timeout, NfsTimeout);
- net_set_udp_handler(NfsHandler);
+ net_set_udp_handler(nfs_handler);
NfsTimeoutCount = 0;
NfsState = STATE_PRCLOOKUP_PROG_MOUNT_REQ;
static ushort PingSeqNo;
/* The ip address to ping */
-IPaddr_t NetPingIP;
+struct in_addr net_ping_ip;
-static void set_icmp_header(uchar *pkt, IPaddr_t dest)
+static void set_icmp_header(uchar *pkt, struct in_addr dest)
{
/*
* Construct an IP and ICMP header.
struct ip_hdr *ip = (struct ip_hdr *)pkt;
struct icmp_hdr *icmp = (struct icmp_hdr *)(pkt + IP_HDR_SIZE);
- net_set_ip_header(pkt, dest, NetOurIP);
+ net_set_ip_header(pkt, dest, net_ip);
ip->ip_len = htons(IP_ICMP_HDR_SIZE);
ip->ip_p = IPPROTO_ICMP;
/* XXX always send arp request */
- debug_cond(DEBUG_DEV_PKT, "sending ARP for %pI4\n", &NetPingIP);
+ debug_cond(DEBUG_DEV_PKT, "sending ARP for %pI4\n", &net_ping_ip);
- NetArpWaitPacketIP = NetPingIP;
+ net_arp_wait_packet_ip = net_ping_ip;
eth_hdr_size = NetSetEther(NetTxPacket, NetEtherNullAddr, PROT_IP);
pkt = (uchar *)NetTxPacket + eth_hdr_size;
- set_icmp_header(pkt, NetPingIP);
+ set_icmp_header(pkt, net_ping_ip);
/* size of the waiting packet */
NetArpWaitTxPacketSize = eth_hdr_size + IP_ICMP_HDR_SIZE;
void ping_receive(struct ethernet_hdr *et, struct ip_udp_hdr *ip, int len)
{
struct icmp_hdr *icmph = (struct icmp_hdr *)&ip->udp_src;
- IPaddr_t src_ip;
+ struct in_addr src_ip;
int eth_hdr_size;
switch (icmph->type) {
case ICMP_ECHO_REPLY:
- src_ip = NetReadIP((void *)&ip->ip_src);
- if (src_ip == NetPingIP)
+ src_ip = net_read_ip((void *)&ip->ip_src);
+ if (src_ip.s_addr == net_ping_ip.s_addr)
net_set_state(NETLOOP_SUCCESS);
return;
case ICMP_ECHO_REQUEST:
ip->ip_sum = 0;
ip->ip_off = 0;
- NetCopyIP((void *)&ip->ip_dst, &ip->ip_src);
- NetCopyIP((void *)&ip->ip_src, &NetOurIP);
+ net_copy_ip((void *)&ip->ip_dst, &ip->ip_src);
+ net_copy_ip((void *)&ip->ip_src, &net_ip);
ip->ip_sum = compute_ip_checksum(ip, IP_HDR_SIZE);
icmph->type = ICMP_ECHO_REPLY;
puts("invalid RARP header\n");
} else {
- NetCopyIP(&NetOurIP, &arp->ar_data[16]);
- if (NetServerIP == 0)
- NetCopyIP(&NetServerIP, &arp->ar_data[6]);
+ net_copy_ip(&net_ip, &arp->ar_data[16]);
+ if (net_server_ip.s_addr == 0)
+ net_copy_ip(&net_server_ip, &arp->ar_data[6]);
memcpy(NetServerEther, &arp->ar_data[0], 6);
debug_cond(DEBUG_DEV_PKT, "Got good RARP\n");
net_auto_load();
rarp->ar_pln = 4;
rarp->ar_op = htons(RARPOP_REQUEST);
memcpy(&rarp->ar_data[0], NetOurEther, 6); /* source ET addr */
- memcpy(&rarp->ar_data[6], &NetOurIP, 4); /* source IP addr */
+ memcpy(&rarp->ar_data[6], &net_ip, 4); /* source IP addr */
/* dest ET addr = source ET addr ??*/
memcpy(&rarp->ar_data[10], NetOurEther, 6);
/* dest IP addr set to broadcast */
SntpOurPort = 10000 + (get_timer(0) % 4096);
sport = NTP_SERVICE_PORT;
- NetSendUDPPacket(NetServerEther, NetNtpServerIP, sport, SntpOurPort,
- pktlen);
+ NetSendUDPPacket(NetServerEther, net_ntp_server, sport, SntpOurPort,
+ pktlen);
}
static void
return;
}
-static void
-SntpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
- unsigned len)
+static void sntp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
+ unsigned src, unsigned len)
{
struct sntp_pkt_t *rpktp = (struct sntp_pkt_t *)pkt;
struct rtc_time tm;
debug("%s\n", __func__);
NetSetTimeout(SNTP_TIMEOUT, SntpTimeout);
- net_set_udp_handler(SntpHandler);
+ net_set_udp_handler(sntp_handler);
memset(NetServerEther, 0, sizeof(NetServerEther));
SntpSend();
TFTP_ERR_FILE_ALREADY_EXISTS = 6,
};
-static IPaddr_t TftpRemoteIP;
+static struct in_addr tftp_remote_ip;
/* The UDP port at their end */
static int TftpRemotePort;
/* The UDP port at our end */
static void
mcast_cleanup(void)
{
- if (Mcast_addr)
- eth_mcast_join(Mcast_addr, 0);
+ if (net_mcast_addr)
+ eth_mcast_join(net_mcast_addr, 0);
if (Bitmap)
free(Bitmap);
Bitmap = NULL;
- Mcast_addr = Multicast = Mcast_port = 0;
+ net_mcast_addr.s_addr = 0;
+ Multicast = 0;
+ Mcast_port = 0;
TftpEndingBlock = -1;
}
break;
}
- NetSendUDPPacket(NetServerEther, TftpRemoteIP, TftpRemotePort,
+ NetSendUDPPacket(NetServerEther, tftp_remote_ip, TftpRemotePort,
TftpOurPort, len);
}
#ifdef CONFIG_CMD_TFTPPUT
static void icmp_handler(unsigned type, unsigned code, unsigned dest,
- IPaddr_t sip, unsigned src, uchar *pkt, unsigned len)
+ struct in_addr sip, unsigned src, uchar *pkt,
+ unsigned len)
{
if (type == ICMP_NOT_REACH && code == ICMP_NOT_REACH_PORT) {
/* Oh dear the other end has gone away */
}
#endif
-static void
-TftpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
- unsigned len)
+static void tftp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
+ unsigned src, unsigned len)
{
__be16 proto;
__be16 *s;
#ifdef CONFIG_CMD_TFTPSRV
case TFTP_WRQ:
debug("Got WRQ\n");
- TftpRemoteIP = sip;
+ tftp_remote_ip = sip;
TftpRemotePort = src;
TftpOurPort = 1024 + (get_timer(0) % 3072);
new_transfer();
debug("TFTP blocksize = %i, timeout = %ld ms\n",
TftpBlkSizeOption, TftpTimeoutMSecs);
- TftpRemoteIP = NetServerIP;
+ tftp_remote_ip = net_server_ip;
if (BootFile[0] == '\0') {
sprintf(default_filename, "%02X%02X%02X%02X.img",
- NetOurIP & 0xFF,
- (NetOurIP >> 8) & 0xFF,
- (NetOurIP >> 16) & 0xFF,
- (NetOurIP >> 24) & 0xFF);
+ net_ip.s_addr & 0xFF,
+ (net_ip.s_addr >> 8) & 0xFF,
+ (net_ip.s_addr >> 16) & 0xFF,
+ (net_ip.s_addr >> 24) & 0xFF);
strncpy(tftp_filename, default_filename, MAX_LEN);
tftp_filename[MAX_LEN-1] = 0;
strncpy(tftp_filename, BootFile, MAX_LEN);
tftp_filename[MAX_LEN-1] = 0;
} else {
- TftpRemoteIP = string_to_ip(BootFile);
+ tftp_remote_ip = string_to_ip(BootFile);
strncpy(tftp_filename, p + 1, MAX_LEN);
tftp_filename[MAX_LEN-1] = 0;
}
#else
"from",
#endif
- &TftpRemoteIP, &NetOurIP);
+ &tftp_remote_ip, &net_ip);
/* Check if we need to send across this subnet */
- if (NetOurGatewayIP && NetOurSubnetMask) {
- IPaddr_t OurNet = NetOurIP & NetOurSubnetMask;
- IPaddr_t RemoteNet = TftpRemoteIP & NetOurSubnetMask;
-
- if (OurNet != RemoteNet)
- printf("; sending through gateway %pI4",
- &NetOurGatewayIP);
+ if (net_gateway.s_addr && net_netmask.s_addr) {
+ struct in_addr our_net;
+ struct in_addr remote_net;
+
+ our_net.s_addr = net_ip.s_addr & net_netmask.s_addr;
+ remote_net.s_addr = tftp_remote_ip.s_addr & net_netmask.s_addr;
+ if (our_net.s_addr != remote_net.s_addr)
+ printf("; sending through gateway %pI4", &net_gateway);
}
putc('\n');
TftpTimeoutCountMax = TftpRRQTimeoutCountMax;
NetSetTimeout(TftpTimeoutMSecs, TftpTimeout);
- net_set_udp_handler(TftpHandler);
+ net_set_udp_handler(tftp_handler);
#ifdef CONFIG_CMD_TFTPPUT
net_set_icmp_handler(icmp_handler);
#endif
tftp_filename[0] = 0;
printf("Using %s device\n", eth_get_name());
- printf("Listening for TFTP transfer on %pI4\n", &NetOurIP);
+ printf("Listening for TFTP transfer on %pI4\n", &net_ip);
printf("Load address: 0x%lx\n", load_addr);
puts("Loading: *\b");
#endif
TftpState = STATE_RECV_WRQ;
- net_set_udp_handler(TftpHandler);
+ net_set_udp_handler(tftp_handler);
/* zero out server ether in case the server ip has changed */
memset(NetServerEther, 0, 6);
static void parse_multicast_oack(char *pkt, int len)
{
int i;
- IPaddr_t addr;
+ struct in_addr addr;
char *mc_adr, *port, *mc;
mc_adr = port = mc = NULL;
Multicast = 1;
}
addr = string_to_ip(mc_adr);
- if (Mcast_addr != addr) {
- if (Mcast_addr)
- eth_mcast_join(Mcast_addr, 0);
- Mcast_addr = addr;
- if (eth_mcast_join(Mcast_addr, 1)) {
+ if (net_mcast_addr.s_addr != addr.s_addr) {
+ if (net_mcast_addr.s_addr)
+ eth_mcast_join(net_mcast_addr, 0);
+ net_mcast_addr = addr;
+ if (eth_mcast_join(net_mcast_addr, 1)) {
printf("Fail to set mcast, revert to TFTP\n");
ProhibitMcast = 1;
mcast_cleanup();
static int dm_test_eth(struct dm_test_state *dms)
{
- NetPingIP = string_to_ip("1.1.2.2");
+ net_ping_ip = string_to_ip("1.1.2.2");
setenv("ethact", "eth@10002000");
ut_assertok(NetLoop(PING));
static int dm_test_eth_alias(struct dm_test_state *dms)
{
- NetPingIP = string_to_ip("1.1.2.2");
+ net_ping_ip = string_to_ip("1.1.2.2");
setenv("ethact", "eth0");
ut_assertok(NetLoop(PING));
ut_asserteq_str("eth@10002000", getenv("ethact"));
static int dm_test_eth_prime(struct dm_test_state *dms)
{
- NetPingIP = string_to_ip("1.1.2.2");
+ net_ping_ip = string_to_ip("1.1.2.2");
/* Expected to be "eth@10003000" because of ethprime variable */
setenv("ethact", NULL);
char ethaddr[18];
/* Invalidate eth1's MAC address */
- NetPingIP = string_to_ip("1.1.2.2");
+ net_ping_ip = string_to_ip("1.1.2.2");
strcpy(ethaddr, getenv("eth1addr"));
setenv("eth1addr", NULL);
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