
Hi Joe,
On 3 March 2015 at 19:41, Joe Hershberger joe.hershberger@ni.com wrote:
Implement a bridge between u-boot's network stack and Linux's raw packet API allowing the sandbox to send and receive packets using the host machine's network interface.
This raw Ethernet API requires elevated privileges. You can either run as root, or you can add the capability needed like so:
sudo /sbin/setcap "CAP_NET_RAW+ep" u-boot
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
Reviewed-by: Simon Glass sjg@chromium.org
Nits below.
Changes in v5: -Added fallback for setting promiscuous mode -Added help to Kconfig -Added more details and examples in the README -Check for NULL when reading fdt for host interface -Check for malloc failure -Remove cast of pointer passed to free -Remove the empty sb_eth_raw_remove function -Return -errno in from send and recv -Return errno from recv -Set the socket to non-blocking -Use net_rx_packets instead of a stack buffer
Changes in v4: -Add comments to priv struct definition -Added comments to README.sandbox -Clean up the interface to sandbox's eth-raw-os by passing priv to raw-os -Cleanup var definition order -Fixed the MAC address limitation (now all traffic uses MAC address from env) -Move os file to arch -Moved config to Kconfig -Use accessors for platdata and priv
Changes in v3: -Made the os raw packet support for sandbox eth build and work.
Changes in v2: -Added the raw packet proof-of-concept patch.
arch/sandbox/Kconfig | 3 + arch/sandbox/cpu/Makefile | 10 +++ arch/sandbox/cpu/eth-raw-os.c | 140 ++++++++++++++++++++++++++++++++++ arch/sandbox/dts/sandbox.dts | 6 ++ arch/sandbox/include/asm/eth-raw-os.h | 32 ++++++++ board/sandbox/README.sandbox | 52 +++++++++++++ drivers/net/Kconfig | 10 +++ drivers/net/Makefile | 1 + drivers/net/sandbox-raw.c | 98 ++++++++++++++++++++++++ 9 files changed, 352 insertions(+) create mode 100644 arch/sandbox/cpu/eth-raw-os.c create mode 100644 arch/sandbox/include/asm/eth-raw-os.h create mode 100644 drivers/net/sandbox-raw.c
diff --git a/board/sandbox/README.sandbox b/board/sandbox/README.sandbox index c1f5f7e..aedf05a 100644 --- a/board/sandbox/README.sandbox +++ b/board/sandbox/README.sandbox @@ -190,6 +190,58 @@ Also sandbox uses generic board (CONFIG_SYS_GENERIC_BOARD) and supports driver model (CONFIG_DM) and associated commands.
+Linux RAW Networking Bridge +---------------------------
+The sandbox_eth_raw driver bridges traffic between the bottom of the network +stack and the RAW sockets API in Linux. This allows much of the u-boot network
s/u-boot/U-Boot/g
(there's one in the Kconfig also)
+functionality to be tested in sandbox against real network traffic.
+For Ethernet network adapters, the bridge utilizes the RAW AF_PACKET API. This +is needed to get access to the lowest level of the network stack in Linux. This +means that all of the Ethernet frame is included. This allows the u-boot network +stack to be fully used. In other words, nothing about the Linux network stack is +involved in forming the packets that end up on the wire. To receive the +responses to packets sent from U-Boot the network interface has to be set to +promiscuous mode so that the network card won't filter out packets not destined +for its configured (on Linux) MAC address.
+The RAW sockets Ethernet API requires elevated privileges in Linux. You can +either run as root, or you can add the capability needed like so:
+sudo /sbin/setcap "CAP_NET_RAW+ep" u-boot
I think the last param is the filename, is that right? Would be good to clarify if this is a full path, etc.
+The default device tree for sandbox includes an entry for eth0 on the sandbox +host machine whose alias is "eth1". The following are a few examples of network +operations being tested on the eth0 interface.
+sudo u-boot -d u-boot.dtb
or sudo u-boot -D
+DHCP +....
+set autoload no +set ethact eth1 +dhcp
+PING +....
+set autoload no +set ethact eth1 +dhcp +ping $gatewayip
+TFTP +....
+set autoload no +set ethact eth1 +dhcp +set serverip WWW.XXX.YYY.ZZZ +tftpboot u-boot.bin
SPI Emulation
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig index e46e57b..601366f 100644 --- a/drivers/net/Kconfig +++ b/drivers/net/Kconfig @@ -29,4 +29,14 @@ config ETH_SANDBOX
This driver is particularly useful in the test/dm/eth.c tests
+config ETH_SANDBOX_RAW
depends on DM_ETH && SANDBOX
default y
bool "Sandbox: Bridge to Linux Raw Sockets"
help
This driver is a bridge from the bottom of the network stack
in u-boot to the RAW AF_PACKET API in Linux. This allows real
network traffic to be tested from within sandbox. See
board/sandbox/README.sandbox for more details.
endif # NETDEVICES
Regards, Simon