Skip to content

Commit

Permalink
sandbox: eth-raw: Allow interface to be specified by index
Browse files Browse the repository at this point in the history
With systemd stable interface names, eth0 will almost never exist.
Instead of using that name in the sandbox.dts, use an index.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
  • Loading branch information
jhershbe committed Jul 26, 2018
1 parent ac13270 commit c9e2caf
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions arch/sandbox/cpu/eth-raw-os.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ int sandbox_eth_raw_os_is_local(const char *ifname)
return ret;
}

int sandbox_eth_raw_os_idx_to_name(struct eth_sandbox_raw_priv *priv)
{
if (!if_indextoname(priv->host_ifindex, priv->host_ifname))
return -errno;
return 0;
}

static int _raw_packet_start(struct eth_sandbox_raw_priv *priv,
unsigned char *ethmac)
{
Expand Down
9 changes: 9 additions & 0 deletions arch/sandbox/include/asm/eth-raw-os.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ struct eth_sandbox_raw_priv {
*/
int sandbox_eth_raw_os_is_local(const char *ifname);

/*
* Look up the name of the interface based on the ifindex populated in priv.
*
* Overwrite the host_ifname member in priv based on looking up host_ifindex
*
* returns - 0 if success, negative if error
*/
int sandbox_eth_raw_os_idx_to_name(struct eth_sandbox_raw_priv *priv);

int sandbox_eth_raw_os_start(struct eth_sandbox_raw_priv *priv,
unsigned char *ethmac);
int sandbox_eth_raw_os_send(void *packet, int length,
Expand Down
11 changes: 11 additions & 0 deletions drivers/net/sandbox-raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ static int sb_eth_raw_ofdata_to_platdata(struct udevice *dev)
struct eth_sandbox_raw_priv *priv = dev_get_priv(dev);
const char *ifname;
u32 local;
int ret;

pdata->iobase = dev_read_addr(dev);

Expand All @@ -151,6 +152,16 @@ static int sb_eth_raw_ofdata_to_platdata(struct udevice *dev)
strncpy(priv->host_ifname, ifname, IFNAMSIZ);
printf(": Using %s from DT\n", priv->host_ifname);
}
if (dev_read_u32(dev, "host-raw-interface-idx",
&priv->host_ifindex) < 0) {
priv->host_ifindex = 0;
} else {
ret = sandbox_eth_raw_os_idx_to_name(priv);
if (ret < 0)
return ret;
printf(": Using interface index %d from DT (%s)\n",
priv->host_ifindex, priv->host_ifname);
}

local = sandbox_eth_raw_os_is_local(priv->host_ifname);
if (local < 0)
Expand Down

0 comments on commit c9e2caf

Please sign in to comment.