aboutsummaryrefslogtreecommitdiff
path: root/arch/sandbox
diff options
context:
space:
mode:
authorJoe Hershberger2018-07-02 14:47:54 -0500
committerJoe Hershberger2018-07-26 14:08:19 -0500
commitf40a31e695638e0422fdce3c4c6eb39cd1f11f91 (patch)
treec31007bdb6512d4d75f182f0e0410a52cbd96727 /arch/sandbox
parentb96ced9cdb6bbba1ef4e0087eec799127a22afab (diff)
sandbox: eth-raw: Add a SIMPLE_BUS to enumerate host interfaces
Ask the OS for each of its interfaces and for each one, bind a U-Boot device and then probe it. This will allocate the priv data structure that is then populated. Signed-off-by: Joe Hershberger <joe.hershberger@ni.com> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'arch/sandbox')
-rw-r--r--arch/sandbox/cpu/eth-raw-os.c10
-rw-r--r--arch/sandbox/dts/sandbox.dts18
-rw-r--r--arch/sandbox/dts/sandbox64.dts18
-rw-r--r--arch/sandbox/include/asm/eth-raw-os.h11
4 files changed, 31 insertions, 26 deletions
diff --git a/arch/sandbox/cpu/eth-raw-os.c b/arch/sandbox/cpu/eth-raw-os.c
index df7acaa0bc8..75bfaa4c90a 100644
--- a/arch/sandbox/cpu/eth-raw-os.c
+++ b/arch/sandbox/cpu/eth-raw-os.c
@@ -23,6 +23,16 @@
#include <linux/if_ether.h>
#include <linux/if_packet.h>
+struct sandbox_eth_raw_if_nameindex *sandbox_eth_raw_if_nameindex(void)
+{
+ return (struct sandbox_eth_raw_if_nameindex *)if_nameindex();
+}
+
+void sandbox_eth_raw_if_freenameindex(struct sandbox_eth_raw_if_nameindex *ptr)
+{
+ if_freenameindex((struct if_nameindex *)ptr);
+}
+
int sandbox_eth_raw_os_is_local(const char *ifname)
{
int fd = socket(AF_INET, SOCK_DGRAM, 0);
diff --git a/arch/sandbox/dts/sandbox.dts b/arch/sandbox/dts/sandbox.dts
index 0ea2452742d..9f444c96a9e 100644
--- a/arch/sandbox/dts/sandbox.dts
+++ b/arch/sandbox/dts/sandbox.dts
@@ -8,7 +8,6 @@
model = "sandbox";
aliases {
- eth5 = "/eth@90000000";
i2c0 = &i2c_0;
pci0 = &pci;
rtc0 = &rtc_0;
@@ -47,24 +46,17 @@
};
};
+ ethrawbus {
+ compatible = "sandbox,eth-raw-bus";
+ skip-localhost = <0>;
+ };
+
eth@10002000 {
compatible = "sandbox,eth";
reg = <0x10002000 0x1000>;
fake-host-hwaddr = [00 00 66 44 22 00];
};
- eth@80000000 {
- compatible = "sandbox,eth-raw";
- reg = <0x80000000 0x1000>;
- host-raw-interface = "eth0";
- };
-
- eth@90000000 {
- compatible = "sandbox,eth-raw";
- reg = <0x90000000 0x1000>;
- host-raw-interface = "lo";
- };
-
gpio_a: gpios@0 {
gpio-controller;
compatible = "sandbox,gpio";
diff --git a/arch/sandbox/dts/sandbox64.dts b/arch/sandbox/dts/sandbox64.dts
index 48e420e721e..9e65d2fda3d 100644
--- a/arch/sandbox/dts/sandbox64.dts
+++ b/arch/sandbox/dts/sandbox64.dts
@@ -8,7 +8,6 @@
model = "sandbox";
aliases {
- eth5 = "/eth@90000000";
i2c0 = &i2c_0;
pci0 = &pci;
rtc0 = &rtc_0;
@@ -47,24 +46,17 @@
};
};
+ ethrawbus {
+ compatible = "sandbox,eth-raw-bus";
+ skip-localhost = <1>;
+ };
+
eth@10002000 {
compatible = "sandbox,eth";
reg = <0x0 0x10002000 0x0 0x1000>;
fake-host-hwaddr = [00 00 66 44 22 00];
};
- eth@80000000 {
- compatible = "sandbox,eth-raw";
- reg = <0x0 0x80000000 0x0 0x1000>;
- host-raw-interface = "eth0";
- };
-
- eth@90000000 {
- compatible = "sandbox,eth-raw";
- reg = <0x0 0x90000000 0x0 0x1000>;
- host-raw-interface = "lo";
- };
-
gpio_a: gpios@0 {
gpio-controller;
compatible = "sandbox,gpio";
diff --git a/arch/sandbox/include/asm/eth-raw-os.h b/arch/sandbox/include/asm/eth-raw-os.h
index 99f674e82e6..0b511db70c3 100644
--- a/arch/sandbox/include/asm/eth-raw-os.h
+++ b/arch/sandbox/include/asm/eth-raw-os.h
@@ -34,6 +34,17 @@ struct eth_sandbox_raw_priv {
unsigned short local_bind_udp_port;
};
+/* A struct to mimic if_nameindex but that does not depend on Linux headers */
+struct sandbox_eth_raw_if_nameindex {
+ unsigned int if_index; /* Index of interface (1, 2, ...) */
+ char *if_name; /* Null-terminated name ("eth0", etc.) */
+};
+
+/* Enumerate host network interfaces */
+struct sandbox_eth_raw_if_nameindex *sandbox_eth_raw_if_nameindex(void);
+/* Free the data structure of enumerated network interfaces */
+void sandbox_eth_raw_if_freenameindex(struct sandbox_eth_raw_if_nameindex *ptr);
+
/*
* Check if the interface named "ifname" is a localhost interface or not.
* ifname - the interface name on the host to check