summaryrefslogtreecommitdiffstats
path: root/drivers/net/sandbox-raw.c
diff options
context:
space:
mode:
authorJoe Hershberger <joe.hershberger@ni.com>2015-03-22 17:09:23 -0500
committerSimon Glass <sjg@chromium.org>2015-04-18 11:11:14 -0600
commit22f68524f84c3a0d620e787c51d5f244ef8e0aca (patch)
treeeac8ed04673bcc41b6f9f2c9771c38b38961b2b5 /drivers/net/sandbox-raw.c
parentf3e0c3744a6a0a01fcf3a34b582c2f9c84ba56cd (diff)
downloadtalos-obmc-uboot-22f68524f84c3a0d620e787c51d5f244ef8e0aca.tar.gz
talos-obmc-uboot-22f68524f84c3a0d620e787c51d5f244ef8e0aca.zip
sandbox: eth: Add support for using the 'lo' interface
The 'lo' interface on Linux doesn't support thinks like ARP or link-layer access like we use to talk to a normal network interface. A higher-level network API must be used to access localhost. As written, this interface is limited to not supporting ICMP since the API doesn't allow the socket to be opened for all IP traffic and be able to receive at the same time. UDP is far more useful to test with, so it was selected over ICMP. Ping won't work, but things like TFTP should work. Signed-off-by: Joe Hershberger <joe.hershberger@ni.com> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers/net/sandbox-raw.c')
-rw-r--r--drivers/net/sandbox-raw.c71
1 files changed, 69 insertions, 2 deletions
diff --git a/drivers/net/sandbox-raw.c b/drivers/net/sandbox-raw.c
index 435b8745c3..91da5f55ca 100644
--- a/drivers/net/sandbox-raw.c
+++ b/drivers/net/sandbox-raw.c
@@ -15,6 +15,8 @@
DECLARE_GLOBAL_DATA_PTR;
+static int reply_arp;
+static IPaddr_t arp_ip;
static int sb_eth_raw_start(struct udevice *dev)
{
@@ -29,6 +31,11 @@ static int sb_eth_raw_start(struct udevice *dev)
if (interface == NULL)
return -EINVAL;
+ if (strcmp(interface, "lo") == 0) {
+ priv->local = 1;
+ setenv("ipaddr", "127.0.0.1");
+ setenv("serverip", "127.0.0.1");
+ }
return sandbox_eth_raw_os_start(interface, pdata->enetaddr, priv);
}
@@ -38,18 +45,78 @@ static int sb_eth_raw_send(struct udevice *dev, void *packet, int length)
debug("eth_sandbox_raw: Send packet %d\n", length);
+ if (priv->local) {
+ struct ethernet_hdr *eth = packet;
+
+ if (ntohs(eth->et_protlen) == PROT_ARP) {
+ struct arp_hdr *arp = packet + ETHER_HDR_SIZE;
+
+ /**
+ * localhost works on a higher-level API in Linux than
+ * ARP packets, so fake it
+ */
+ arp_ip = NetReadIP(&arp->ar_tpa);
+ reply_arp = 1;
+ return 0;
+ }
+ packet += ETHER_HDR_SIZE;
+ length -= ETHER_HDR_SIZE;
+ }
return sandbox_eth_raw_os_send(packet, length, priv);
}
static int sb_eth_raw_recv(struct udevice *dev, uchar **packetp)
{
+ struct eth_pdata *pdata = dev_get_platdata(dev);
struct eth_sandbox_raw_priv *priv = dev_get_priv(dev);
- int retval;
+ int retval = 0;
int length;
- retval = sandbox_eth_raw_os_recv(net_rx_packets[0], &length, priv);
+ if (reply_arp) {
+ struct arp_hdr *arp = (void *)net_rx_packets[0] +
+ ETHER_HDR_SIZE;
+
+ /*
+ * Fake an ARP response. The u-boot network stack is sending an
+ * ARP request (to find the MAC address to address the actual
+ * packet to) and requires an ARP response to continue. Since
+ * this is the localhost interface, there is no Etherent level
+ * traffic at all, so there is no way to send an ARP request or
+ * to get a response. For this reason we fake the response to
+ * make the u-boot network stack happy.
+ */
+ arp->ar_hrd = htons(ARP_ETHER);
+ arp->ar_pro = htons(PROT_IP);
+ arp->ar_hln = ARP_HLEN;
+ arp->ar_pln = ARP_PLEN;
+ arp->ar_op = htons(ARPOP_REPLY);
+ /* 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);
+ memcpy(&arp->ar_tha, pdata->enetaddr, ARP_HLEN);
+ NetWriteIP(&arp->ar_tpa, NetOurIP);
+ length = ARP_HDR_SIZE;
+ } else {
+ /* If local, the Ethernet header won't be included; skip it */
+ uchar *pktptr = priv->local ?
+ net_rx_packets[0] + ETHER_HDR_SIZE : net_rx_packets[0];
+
+ retval = sandbox_eth_raw_os_recv(pktptr, &length, priv);
+ }
if (!retval && length) {
+ if (priv->local) {
+ struct ethernet_hdr *eth = (void *)net_rx_packets[0];
+
+ /* Fill in enough of the missing Ethernet header */
+ memcpy(eth->et_dest, pdata->enetaddr, ARP_HLEN);
+ memset(eth->et_src, 0x01, ARP_HLEN);
+ eth->et_protlen = htons(reply_arp ? PROT_ARP : PROT_IP);
+ reply_arp = 0;
+ length += ETHER_HDR_SIZE;
+ }
+
debug("eth_sandbox_raw: received packet %d\n",
length);
*packetp = net_rx_packets[0];
OpenPOWER on IntegriCloud