]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
sandbox: eth-raw: Allow interface to be specified by index
authorJoe Hershberger <joe.hershberger@ni.com>
Mon, 2 Jul 2018 19:47:52 +0000 (14:47 -0500)
committerJoe Hershberger <joe.hershberger@ni.com>
Thu, 26 Jul 2018 19:08:18 +0000 (14:08 -0500)
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>
arch/sandbox/cpu/eth-raw-os.c
arch/sandbox/include/asm/eth-raw-os.h
drivers/net/sandbox-raw.c

index 12ddb345d92f843afa661cfffc256525a1a38e1b..df7acaa0bc8480ec01cad2a0b1d3543bbf3841f9 100644 (file)
@@ -44,6 +44,13 @@ out:
        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)
 {
index edd09d2e08403dc589465eb17bd7c5e5d4dd11e1..99f674e82e645f8110ab3f5cae623a128ea5c994 100644 (file)
@@ -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,
index c04b94c6e186fd4366a53a85ace526f8fc6ce221..0d1fd4d93110b569112323606a68812ebe873c6b 100644 (file)
@@ -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);
 
@@ -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)