Skip to contentSkip to conversation

sandbox: Add tap based networking

RFC PATCH New Matthias Weisser 4 participants 12 messages Nov 29, 2011 – Jan 8, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 sandbox: Add tap based networking

This patch adds a network driver for sandbox using tap.

---
This patch adds support for networking to sandbox architecture using tap. A tap device "tap0" has to be created e.g. using openvpn

$ openvpn --mktun --dev tap0

u-boot should then be able to detect the network device on startup. To test the network related commands I used the following commands to create an ethernet bridge to my local network connection

$ brctl addbr br0
$ ifconfig eth0 0.0.0.0 promisc
$ ifconfig tap0 0.0.0.0
$ brctl addif br0 eth0
$ brctl addif br0 tap0
$ ifconfig br0 up
$ pump -i br0

After this setup I was able to successfully execute the ping and tftp command.

To get timeouts working this patch also needs my timer patch for sandbox
http://patchwork.ozlabs.org/patch/128279/

Note:
As sandbox is build using the native compiler, which is in my case x86_64, ulong is 64 bit in size. This caused non-working IP stuff as IPaddr_t is typedefed to ulong. I changed this typedef to u32 which helped but is quite invasive to all network related stuff. This is the main reason why this patched is marked as RFC.

 arch/sandbox/cpu/cpu.c    |    9 +++
 arch/sandbox/cpu/os.c     |   39 ++++++++++++++
 arch/sandbox/lib/board.c  |    5 ++
 drivers/net/Makefile      |    1 +
 drivers/net/tap.c         |  125 +++++++++++++++++++++++++++++++++++++++++++++
 include/configs/sandbox.h |    9 ++--
 include/net.h             |    2 +-
 include/os.h              |    8 +++
 8 files changed, 193 insertions(+), 5 deletions(-)
 create mode 100644 drivers/net/tap.c
arch/sandbox/cpu/cpu.c +9 -0
index d7684d3..53e58bd 100644
@@ -60,3 +60,12 @@ void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
 void flush_dcache_range(unsigned long start, unsigned long stop)
 {
 }
+
+int cpu_eth_init(bd_t *bis)
+{
+#if defined(CONFIG_DRIVER_TAP)
+	return tap_initialize(bis);
+#else
+	return 0;
+#endif
+}
arch/sandbox/cpu/os.c +39 -0
index 6d55b5c..9985b33 100644
@@ -21,14 +21,20 @@
 
 #include <fcntl.h>
 #include <stdlib.h>
+#include <stdio.h>
 #include <termios.h>
 #include <unistd.h>
+#include <string.h>
 #include <time.h>
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/mman.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
 #include <linux/types.h>
+#include <linux/if.h>
+#include <linux/if_tun.h>
 
 #include <os.h>
 
@@ -121,3 +127,36 @@ u64 os_get_nsec(void)
 	return tv.tv_sec * 1000000000ULL + tv.tv_usec * 1000;
 #endif
 }
+
+int os_tap_open(char *dev)
+{
+	struct ifreq ifr;
+	int fd, err;
+
+	fd = open("/dev/net/tun", O_RDWR | O_NONBLOCK);
+	if (fd < 0) {
+		perror("could not open /dev/net/tun");
+		return -1;
+	}
+
+	memset(&ifr, 0, sizeof(ifr));
+
+	/* Flags: IFF_TUN   - TUN device (no Ethernet headers)
+	 *        IFF_TAP   - TAP device
+	 *
+	 *        IFF_NO_PI - Do not provide packet information
+	 */
+	ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
+	if (*dev)
+		strncpy(ifr.ifr_name, dev, IFNAMSIZ);
+
+	err = ioctl(fd, TUNSETIFF, (void *)&ifr);
+	if (err < 0) {
+		perror("could not get tap device");
+		close(fd);
+		return err;
+	}
+
+	strcpy(dev, ifr.ifr_name);
+	return fd;
+}
arch/sandbox/lib/board.c +5 -0
index b7997e9..d02f6ca 100644
@@ -257,6 +257,11 @@ void board_init_r(gd_t *id, ulong dest_addr)
 	board_late_init();
 #endif
 
+#if defined(CONFIG_CMD_NET)
+	puts("Net:   ");
+	eth_initialize(gd->bd);
+#endif
+
 #ifdef CONFIG_POST
 	post_run(NULL, POST_RAM | post_bootmode_get(0));
 #endif
drivers/net/Makefile +1 -0
index d3df82e..1686405 100644
@@ -69,6 +69,7 @@ COBJS-$(CONFIG_SH_ETHER) += sh_eth.o
 COBJS-$(CONFIG_SMC91111) += smc91111.o
 COBJS-$(CONFIG_SMC911X) += smc911x.o
 COBJS-$(CONFIG_DRIVER_TI_EMAC) += davinci_emac.o
+COBJS-$(CONFIG_DRIVER_TAP) += tap.o
 COBJS-$(CONFIG_TSEC_ENET) += tsec.o fsl_mdio.o
 COBJS-$(CONFIG_FMAN_ENET) += fsl_mdio.o
 COBJS-$(CONFIG_TSI108_ETH) += tsi108_eth.o
drivers/net/tap.c new file +125 -0

125 lines not on this page · raw message

include/configs/sandbox.h +5 -4
index 10565e6..1ca27e5 100644
@@ -69,12 +69,13 @@
 
 #define CONFIG_SYS_NO_FLASH
 
+/* Network support */
+#define CONFIG_DRIVER_TAP
+
 /* include default commands */
 #include <config_cmd_default.h>
-
-/* We don't have networking support yet */
-#undef CONFIG_CMD_NET
-#undef CONFIG_CMD_NFS
+#define CONFIG_CMD_DHCP
+#define CONFIG_CMD_PING
 
 #define CONFIG_BOOTARGS ""
 
include/net.h +1 -1
index ad9afbf..9d878e5 100644
@@ -33,7 +33,7 @@
 
 #define PKTALIGN	32
 
-typedef ulong		IPaddr_t;
+typedef u32		IPaddr_t;
 
 
 /**
include/os.h +8 -0
index f3af4f0..ba76419 100644
@@ -98,3 +98,11 @@ void os_usleep(unsigned long usec);
  * \return A monotonic increasing time scaled in nano seconds
  */
 u64 os_get_nsec(void);
+
+/**
+ * Opens a TAP device for network emulation
+ *
+ * \param dev Device name to be opened
+ * \return File descriptor of the device
+ */
+int os_tap_open(char *dev);
Signature · 1 line
1.7.5.4
#1 lore raw

RFC PATCH 1/1 sandbox: Add tap based networking

Quoted 3 lines · On Tuesday 29 November 2011 09:09:03 Matthias Weisser wrote:

This patch adds support for networking to sandbox architecture using tap. A tap device "tap0" has to be created e.g. using openvpn
....

this info should be in the changelog as it's useful

Quoted 5 lines

As sandbox is build using the native compiler, which is in my case x86_64, ulong is 64 bit in size. This caused non-working IP stuff as IPaddr_t is typedefed to ulong. I changed this typedef to u32 which helped but is quite invasive to all network related stuff. This is the main reason why this patched is marked as RFC.

could you elaborate on "non-working IP stuff" ?

arch/sandbox/cpu/cpu.c

Quoted 4 lines
arch/sandbox/cpu/cpu.c +1 -0
 
+#if defined(CONFIG_DRIVER_TAP)

i think Wolfgang NAK-ed the idea of using "DRIVER" in the config name. so let's use something like CONFIG_NET_TAP.

arch/sandbox/cpu/os.c line 37

Quoted 7 lines
arch/sandbox/cpu/os.c +4 -0
 
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <linux/if.h>
+#include <linux/if_tun.h>

these should be behind the new CONFIG name, as should the func itself

Quoted 1 line

+int os_tap_open(char *dev)

const char *dev

arch/sandbox/cpu/os.c u64 os_get_nsec(void) · line 151

Quoted 2 lines
arch/sandbox/cpu/os.c +2 -0
+	if (*dev)
+		strncpy(ifr.ifr_name, dev, IFNAMSIZ);

let's just make it required

drivers/net/tap.c line 52

Quoted 6 lines
drivers/net/tap.c new file +2 -0
 
+static int tap_send(struct eth_device *dev, void *packet, int length)
...
+	os_write(priv->fd, (void *)packet, length);

packet is already void*, so no need to cast

drivers/net/tap.c line 59

Quoted 4 lines
drivers/net/tap.c new file +4 -0
+static int tap_recv(struct eth_device *dev)
+{
+	struct tap_priv *priv = dev->priv;
+	uchar buf[PKTSIZE];

there are already common network buffers for you to use: NetRxPackets[0]

drivers/net/tap.c line 62

Quoted 3 lines
drivers/net/tap.c new file +3 -0
+	int length;
+
+	length = os_read(priv->fd, buf, PKTSIZE);

os_read returns ssize_t, not int

drivers/net/tap.c line 74

Quoted 5 lines
drivers/net/tap.c new file +5 -0
+static int tap_set_hwaddr(struct eth_device *dev)
+{
+	/* Nothing to be done here */
+	return 0;
+}

isn't there an ioctl that lets you control this ?

drivers/net/tap.c line 78

Quoted 3 lines
drivers/net/tap.c new file +2 -0
+int tap_initialize(bd_t *bd)
...
+	struct eth_device *edev;

this should be named "dev" to stay consistent

drivers/net/tap.c line 90

Quoted 2 lines
drivers/net/tap.c new file +2 -0
+	edev = (struct eth_device *)malloc(sizeof(struct eth_device));
+	tap = (struct tap_priv *)malloc(sizeof(struct tap_priv));

no need for the casts

drivers/net/tap.c line 95

Quoted 11 lines
drivers/net/tap.c new file +11 -0
+	if (!edev) {
+		puts("tap: not enough malloc memory for eth_device\n");
+		res = -ENOMEM;
+		goto err1;
+	}
+
+	if (!tap) {
+		puts("tap: not enough malloc memory for tap_priv\n");
+		res = -ENOMEM;
+		goto err2;
+	}

drop the puts(), and return 0, not -ENOMEM

drivers/net/tap.c line 100

Quoted 1 line
drivers/net/tap.c new file +1 -0
+	strncpy(tap->dev, "tap0", sizeof(tap->dev));

no reason we couldn't support more than one tap, is there ? make the device name an argument to tap_initialize(), and then the board caller can do:

	tap_initialize("tap0");
	tap_initialize("tap1");
	tap_initialize("fooiefoofoo");

drivers/net/tap.c line 105

Quoted 5 lines
drivers/net/tap.c new file +5 -0
+	tap->fd = os_tap_open(tap->dev);
+	if (tap->fd < 0) {
+		res = -EIO;
+		goto err3;
+	}

this should return -1

drivers/net/tap.c line 114

Quoted 1 line
drivers/net/tap.c new file +1 -0
+	sprintf(edev->name, "TAP");

use the same name as tap->dev. in fact, i'd just chuck tap->dev and only use dev->name.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20111129/fee5b043/attachment.pgp>

#2 lore raw

RFC PATCH 1/1 sandbox: Add tap based networking

Am 29.11.2011 16:24, schrieb Mike Frysinger:

Quoted 6 lines · On Tuesday 29 November 2011 09:09:03 Matthias Weisser wrote:
Quoted 3 lines

This patch adds support for networking to sandbox architecture using tap. A tap device "tap0" has to be created e.g. using openvpn
....

this info should be in the changelog as it's useful

Will do

Quoted 7 lines
Quoted 5 lines

As sandbox is build using the native compiler, which is in my case x86_64, ulong is 64 bit in size. This caused non-working IP stuff as IPaddr_t is typedefed to ulong. I changed this typedef to u32 which helped but is quite invasive to all network related stuff. This is the main reason why this patched is marked as RFC.

could you elaborate on "non-working IP stuff" ?

Nothing worked. e.g. ARP wasn't working due to the memcpy in function NetReadIP in net.h which uses sizeof(IPaddr_t) to copy the IP address out of the network packet. sizeof(IPaddr_t) yields 8 on x86_64. After changing the typedef to a type having 32 bits everything worked. So this is one of the zillion problems fixed which we will see if u-boot is ported to real 64 bit hardware :-)

Quoted 7 lines

arch/sandbox/cpu/cpu.c

Quoted 4 lines
arch/sandbox/cpu/cpu.c +1 -0
 
+#if defined(CONFIG_DRIVER_TAP)

i think Wolfgang NAK-ed the idea of using "DRIVER" in the config name. so let's use something like CONFIG_NET_TAP.

Done.

Quoted 9 lines

arch/sandbox/cpu/os.c line 37

Quoted 7 lines
arch/sandbox/cpu/os.c +4 -0
 
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <linux/if.h>
+#include <linux/if_tun.h>

these should be behind the new CONFIG name, as should the func itself

Done

Quoted 8 lines
Quoted 1 line

+int os_tap_open(char *dev)

const char *dev

arch/sandbox/cpu/os.c u64 os_get_nsec(void) · line 151

Quoted 2 lines
arch/sandbox/cpu/os.c +2 -0
+	if (*dev)
+		strncpy(ifr.ifr_name, dev, IFNAMSIZ);

let's just make it required

Done

Quoted 8 lines

drivers/net/tap.c line 52

Quoted 6 lines
drivers/net/tap.c new file +2 -0
 
+static int tap_send(struct eth_device *dev, void *packet, int length)
...
+	os_write(priv->fd, (void *)packet, length);

packet is already void*, so no need to cast

packet of tap_send need to be volatile. So added volatile there and let the cast there.

Quoted 6 lines

drivers/net/tap.c line 59

Quoted 4 lines
drivers/net/tap.c new file +4 -0
+static int tap_recv(struct eth_device *dev)
+{
+	struct tap_priv *priv = dev->priv;
+	uchar buf[PKTSIZE];

there are already common network buffers for you to use: NetRxPackets[0]

Will use them

Quoted 5 lines

drivers/net/tap.c line 62

Quoted 3 lines
drivers/net/tap.c new file +3 -0
+	int length;
+
+	length = os_read(priv->fd, buf, PKTSIZE);

os_read returns ssize_t, not int

NetReceive needs an int later on. I added an explicit cast.

Quoted 7 lines

drivers/net/tap.c line 74

Quoted 5 lines
drivers/net/tap.c new file +5 -0
+static int tap_set_hwaddr(struct eth_device *dev)
+{
+	/* Nothing to be done here */
+	return 0;
+}

isn't there an ioctl that lets you control this ?

Sure. But if I read the the docs correct it is an privileged operation and I don't think we wan't to run u-boot as super user all the time. How is the situation handled on real hardware when the MAC is programmed to an EEPROM on the NIC. Can the MAC be read from the NIC and set to u-boot? This would be the best solution as linux should take care about MAC address assignment.

Quoted 5 lines

drivers/net/tap.c line 78

Quoted 3 lines
drivers/net/tap.c new file +2 -0
+int tap_initialize(bd_t *bd)
...
+	struct eth_device *edev;

this should be named "dev" to stay consistent

Done.

Quoted 4 lines

drivers/net/tap.c line 90

Quoted 2 lines
drivers/net/tap.c new file +2 -0
+	edev = (struct eth_device *)malloc(sizeof(struct eth_device));
+	tap = (struct tap_priv *)malloc(sizeof(struct tap_priv));

no need for the casts

Right

Quoted 5 lines
Quoted 5 lines
drivers/net/tap.c new file +5 -0
+	if (!edev) {
+		puts("tap: not enough malloc memory for eth_device\n");
+		res = -ENOMEM;
+		goto err1;
+	}
Quoted 8 lines

drivers/net/tap.c line 95

Quoted 6 lines
drivers/net/tap.c new file +6 -0
+
+	if (!tap) {
+		puts("tap: not enough malloc memory for tap_priv\n");
+		res = -ENOMEM;
+		goto err2;
+	}

drop the puts(), and return 0, not -ENOMEM

I don't understand why, but done. We are in a PC environment where the puts shouldn't hurt in code size and may help in debugging.

Quoted 7 lines

drivers/net/tap.c line 100

Quoted 1 line
drivers/net/tap.c new file +1 -0
+	strncpy(tap->dev, "tap0", sizeof(tap->dev));

no reason we couldn't support more than one tap, is there ? make the device name an argument to tap_initialize(), and then the board caller can do:

	tap_initialize("tap0");
	tap_initialize("tap1");
	tap_initialize("fooiefoofoo");

Done.

Quoted 7 lines

drivers/net/tap.c line 105

Quoted 5 lines
drivers/net/tap.c new file +5 -0
+	tap->fd = os_tap_open(tap->dev);
+	if (tap->fd < 0) {
+		res = -EIO;
+		goto err3;
+	}

this should return -1

Done.

Quoted 4 lines

drivers/net/tap.c line 114

Quoted 1 line
drivers/net/tap.c new file +1 -0
+	sprintf(edev->name, "TAP");

use the same name as tap->dev. in fact, i'd just chuck tap->dev and only use dev->name.

Done

Thanks for the review. Will wait for some additional comments and send a new version then.

Signature · 1 line
Matthias
#3 lore raw

RFC PATCH 1/1 sandbox: Add tap based networking

Quoted 8 lines · On Tuesday 29 November 2011 13:21:38 Matthias Weisser wrote:

Am 29.11.2011 16:24, schrieb Mike Frysinger:

Quoted 7 lines · On Tuesday 29 November 2011 09:09:03 Matthias Weisser wrote:
Quoted 5 lines

As sandbox is build using the native compiler, which is in my case x86_64, ulong is 64 bit in size. This caused non-working IP stuff as IPaddr_t is typedefed to ulong. I changed this typedef to u32 which helped but is quite invasive to all network related stuff. This is the main reason why this patched is marked as RFC.

Quoted 8 lines
Quoted 1 line

could you elaborate on "non-working IP stuff" ?

Nothing worked. e.g. ARP wasn't working due to the memcpy in function NetReadIP in net.h which uses sizeof(IPaddr_t) to copy the IP address out of the network packet. sizeof(IPaddr_t) yields 8 on x86_64. After changing the typedef to a type having 32 bits everything worked. So this is one of the zillion problems fixed which we will see if u-boot is ported to real 64 bit hardware :-)

ok, so IPaddr_t is holding the exact contents of the IP address and gets read/written directly to the network packets. and being an IPv4 address, it needs to be 32bits exactly.

please split that one line change out into a dedicated patch.

Quoted 8 lines
Quoted 7 lines

drivers/net/tap.c line 74

Quoted 5 lines
drivers/net/tap.c new file +5 -0
+static int tap_set_hwaddr(struct eth_device *dev)
+{
+	/* Nothing to be done here */
+	return 0;
+}

isn't there an ioctl that lets you control this ?

Quoted 6 lines

Sure. But if I read the the docs correct it is an privileged operation and I don't think we wan't to run u-boot as super user all the time. How is the situation handled on real hardware when the MAC is programmed to an EEPROM on the NIC. Can the MAC be read from the NIC and set to u-boot? This would be the best solution as linux should take care about MAC address assignment.

the tap_initialize() func should read the current MAC address assigned to the tap device and write that to dev->enetaddr

then when tap_set_hwaddr() gets called, if the MAC is different, it will attempt to set the MAC to what the user requested. if they don't have permission, then the code can yell at them. but if they do, this should work imo. this gets us the best of all worlds i think.

Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/tap.c new file +5 -0
+	if (!edev) {
+		puts("tap: not enough malloc memory for eth_device\n");
+		res = -ENOMEM;
+		goto err1;
+	}
Quoted 8 lines

drivers/net/tap.c line 95

Quoted 6 lines
drivers/net/tap.c new file +6 -0
+
+	if (!tap) {
+		puts("tap: not enough malloc memory for tap_priv\n");
+		res = -ENOMEM;
+		goto err2;
+	}

drop the puts(), and return 0, not -ENOMEM

Quoted 2 lines

I don't understand why, but done. We are in a PC environment where the puts shouldn't hurt in code size and may help in debugging.

while true, i'm thinking in terms of standard u-boot network driver style here rather than "let's be as helpful as possible to the user". i'd still prefer we drop the puts(), but i understand what you mean ...

also, please keep replies on list :)
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20111129/c1c4dfae/attachment.pgp>

#4 lore raw

RFC PATCH 1/1 sandbox: Add tap based networking

Am 29.11.2011 19:39, schrieb Mike Frysinger:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

+static int tap_set_hwaddr(struct eth_device *dev)

Quoted 6 lines
Quoted 4 lines

drivers/net/tap.c line 41

Quoted 4 lines
drivers/net/tap.c new file +4 -0
+{
+	/* Nothing to be done here */
+	return 0;
+}

isn't there an ioctl that lets you control this ?

Quoted 8 lines
Quoted 6 lines
Quoted 6 lines

Sure. But if I read the the docs correct it is an privileged operation and I don't think we wan't to run u-boot as super user all the time. How is the situation handled on real hardware when the MAC is programmed to an EEPROM on the NIC. Can the MAC be read from the NIC and set to u-boot? This would be the best solution as linux should take care about MAC address assignment.

the tap_initialize() func should read the current MAC address assigned to the tap device and write that to dev->enetaddr

Done.

Quoted 4 lines

then when tap_set_hwaddr() gets called, if the MAC is different, it will attempt to set the MAC to what the user requested. if they don't have permission, then the code can yell at them. but if they do, this should work imo. this gets us the best of all worlds i think.

I looked into that. It seems that you have to shut down the interface, change the MAC and up the interface again. I tried now to do this using some ioctls but didn't got it working as user or as root. So I give up at this point. Should I submit the V2 patch without setting MAC function anyway or will it not be applied then?

If someone has an idea: Here is the (simplified) code to set the MAC of a tap interface.

void os_tap_set_hw_addr(int fd, unsigned char *hwaddr)

{
	struct ifreq ifr;
	
	memset(&ifr, 0, sizeof(ifr));
	strncpy(ifr.ifr_name, "tap0", IFNAMSIZ);
	
	/* Get the interface flags */
	if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
		perror("Could not get interface flags");
	}
	/* Shut down the interface */
	ifr.ifr_flags &= ~(IFF_UP);
	if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) {
		perror("Could not down the interface");
	}

	/* Set the new hw address */
	ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
        memcpy(&ifr.ifr_hwaddr.sa_data, hwaddr, ETH_ALEN);

        if (ioctl(fd, SIOCSIFHWADDR, &ifr) < 0) {
                perror("ioctl(SIOCSIFHWADDR)");
        }

        /* Get the interface flags */
	if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
		perror("Could not get interface flags");
	}
	/* Shut down the interface */
	ifr.ifr_flags |= IFF_UP;
	if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) {
		perror("Could not up the interface");
	}
}

The SIOC{G,S}IFFLAGS ioctl calls fail with "Invalid argument" and the SIOCSIFHWADDR fails with "Device or resource busy".

Signature · 1 line
Matthias
#5 lore raw

RFC PATCH 1/1 sandbox: Add tap based networking

Quoted 11 lines · On Saturday 03 December 2011 10:06:58 Matthias Weisser wrote:

Am 29.11.2011 19:39, schrieb Mike Frysinger:

Quoted 4 lines

then when tap_set_hwaddr() gets called, if the MAC is different, it will attempt to set the MAC to what the user requested. if they don't have permission, then the code can yell at them. but if they do, this should work imo. this gets us the best of all worlds i think.

I looked into that. It seems that you have to shut down the interface, change the MAC and up the interface again. I tried now to do this using some ioctls but didn't got it working as user or as root. So I give up at this point. Should I submit the V2 patch without setting MAC function anyway or will it not be applied then?

add a comment to the set_hwaddr that you tried XXX but couldn't get it to work, so for now it's disabled until someone can post a working solution -mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20111203/81175aad/attachment.pgp>

#6 lore raw

PATCH 1/1 sandbox: Add tap based networking

In reply to Matthias Weisser

This patch adds support for networking to sandbox architecture using tap. A tap device "tap0" has to be created e.g. using openvpn

$ openvpn --mktun --dev tap0

u-boot should then be able to detect the network device on startup. To test the network related commands the following commands can be used to create an ethernet bridge to local network connection.

$ brctl addbr br0
$ ifconfig eth0 0.0.0.0 promisc
$ ifconfig tap0 0.0.0.0
$ brctl addif br0 eth0
$ brctl addif br0 tap0
$ ifconfig br0 up
$ pump -i br0

---
This patch also needs these patches to work
http://patchwork.ozlabs.org/patch/128279/
http://patchwork.ozlabs.org/patch/129084/

Changes from RFC:
Multiple tap interfaces possible now
Minor cleanups due to comments from Mike Frysinger

 arch/sandbox/cpu/cpu.c    |    8 +++
 arch/sandbox/cpu/os.c     |  101 ++++++++++++++++++++++++++++++++++++++
 arch/sandbox/lib/board.c  |    5 ++
 drivers/net/Makefile      |    1 +
 drivers/net/tap.c         |  118 +++++++++++++++++++++++++++++++++++++++++++++
 include/configs/sandbox.h |    9 ++--
 include/netdev.h          |    1 +
 include/os.h              |   18 +++++++
 8 files changed, 257 insertions(+), 4 deletions(-)
 create mode 100644 drivers/net/tap.c
arch/sandbox/cpu/cpu.c +8 -0
index d7684d3..2fb3bae 100644
@@ -21,6 +21,7 @@
 
 #include <common.h>
 #include <os.h>
+#include <netdev.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -60,3 +61,10 @@ void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
 void flush_dcache_range(unsigned long start, unsigned long stop)
 {
 }
+
+#ifdef CONFIG_NET_TAP
+int cpu_eth_init(bd_t *bis)
+{
+	return tap_initialize(bis, "tap0");
+}
+#endif
arch/sandbox/cpu/os.c +101 -0

116 lines not on this page · raw message

arch/sandbox/lib/board.c +5 -0
index b7997e9..d02f6ca 100644
@@ -257,6 +257,11 @@ void board_init_r(gd_t *id, ulong dest_addr)
 	board_late_init();
 #endif
 
+#if defined(CONFIG_CMD_NET)
+	puts("Net:   ");
+	eth_initialize(gd->bd);
+#endif
+
 #ifdef CONFIG_POST
 	post_run(NULL, POST_RAM | post_bootmode_get(0));
 #endif
drivers/net/Makefile +1 -0
index d3df82e..914b1b7 100644
@@ -69,6 +69,7 @@ COBJS-$(CONFIG_SH_ETHER) += sh_eth.o
 COBJS-$(CONFIG_SMC91111) += smc91111.o
 COBJS-$(CONFIG_SMC911X) += smc911x.o
 COBJS-$(CONFIG_DRIVER_TI_EMAC) += davinci_emac.o
+COBJS-$(CONFIG_NET_TAP) += tap.o
 COBJS-$(CONFIG_TSEC_ENET) += tsec.o fsl_mdio.o
 COBJS-$(CONFIG_FMAN_ENET) += fsl_mdio.o
 COBJS-$(CONFIG_TSI108_ETH) += tsi108_eth.o
drivers/net/tap.c new file +118 -0

118 lines not on this page · raw message

include/configs/sandbox.h +5 -4
index 10565e6..33b1a19 100644
@@ -69,12 +69,13 @@
 
 #define CONFIG_SYS_NO_FLASH
 
+/* Network support */
+#define CONFIG_NET_TAP
+
 /* include default commands */
 #include <config_cmd_default.h>
-
-/* We don't have networking support yet */
-#undef CONFIG_CMD_NET
-#undef CONFIG_CMD_NFS
+#define CONFIG_CMD_DHCP
+#define CONFIG_CMD_PING
 
 #define CONFIG_BOOTARGS ""
 
include/netdev.h +1 -0
index 04d9f75..25173a8 100644
@@ -100,6 +100,7 @@ int xilinx_axiemac_initialize(bd_t *bis, unsigned long base_addr,
 							unsigned long dma_addr);
 int xilinx_emaclite_initialize(bd_t *bis, unsigned long base_addr,
 							int txpp, int rxpp);
+int tap_initialize(bd_t *bd, char * dname);
 
 /* Boards with PCI network controllers can call this from their board_eth_init()
  * function to initialize whatever's on board.
include/os.h +18 -0
index f3af4f0..3b0c629 100644
@@ -98,3 +98,21 @@ void os_usleep(unsigned long usec);
  * \return A monotonic increasing time scaled in nano seconds
  */
 u64 os_get_nsec(void);
+
+/**
+ * Opens a TAP device for network emulation
+ *
+ * \param dev Device name to be opened
+ * \param hwaddr Ethernet address of interface is copied here (6 byte)
+ * \return File descriptor of the device
+ */
+int os_tap_open(const char *dev, unsigned char *hwaddr);
+
+/**
+ * Sets the hw address of a open tap interface
+ *
+ * \param fd The fd of the tap interface
+ * \param hwaddr The address to be set (6 byte)
+ * \return -1 if the hwaddr couldn't be set
+ */
+int os_tap_set_hw_addr(int fd, unsigned char *hwaddr);
Signature · 1 line
1.7.5.4
#7 lore raw

PATCH 1/1 sandbox: Add tap based networking

Hi Matthias,

Quoted 17 lines · Matthias Weisser

This patch adds support for networking to sandbox architecture using tap. A tap device "tap0" has to be created e.g. using openvpn

$ openvpn --mktun --dev tap0

u-boot should then be able to detect the network device on startup. To test the network related commands the following commands can be used to create an ethernet bridge to local network connection.

$ brctl addbr br0
$ ifconfig eth0 0.0.0.0 promisc
$ ifconfig tap0 0.0.0.0
$ brctl addif br0 eth0
$ brctl addif br0 tap0
$ ifconfig br0 up
$ pump -i br0
Quoted 1 line

Unfortunately I was unable to test this easily and then ran out of time. But it looks good, with a few comments.

Quoted 59 lines

---
This patch also needs these patches to work
http://patchwork.ozlabs.org/patch/128279/
http://patchwork.ozlabs.org/patch/129084/

Changes from RFC:
?Multiple tap interfaces possible now ?Minor cleanups due to comments from Mike Frysinger

?arch/sandbox/cpu/cpu.c ? ?| ? ?8 +++
?arch/sandbox/cpu/os.c ? ? | ?101 ++++++++++++++++++++++++++++++++++++++
?arch/sandbox/lib/board.c ?| ? ?5 ++
?drivers/net/Makefile ? ? ?| ? ?1 +
?drivers/net/tap.c ? ? ? ? | ?118 +++++++++++++++++++++++++++++++++++++++++++++
?include/configs/sandbox.h | ? ?9 ++--
?include/netdev.h ? ? ? ? ?| ? ?1 +
?include/os.h ? ? ? ? ? ? ?| ? 18 +++++++

?8 files changed, 257 insertions(+), 4 deletions(-) ?create mode 100644 drivers/net/tap.c

arch/sandbox/cpu/cpu.c +0 -0
index d7684d3..2fb3bae 100644
@@ -21,6 +21,7 @@
 

?#include <common.h>
?#include <os.h>
+#include <netdev.h>

?DECLARE_GLOBAL_DATA_PTR;

arch/sandbox/cpu/cpu.c +7 -0
@@ -60,3 +61,10 @@ void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
 ?void flush_dcache_range(unsigned long start, unsigned long stop)
 ?{
 ?}
+
+#ifdef CONFIG_NET_TAP
+int cpu_eth_init(bd_t *bis)
+{
+ ? ? ? return tap_initialize(bis, "tap0");
+}
+#endif
arch/sandbox/cpu/os.c +0 -0
index 6d55b5c..0c8cc82 100644
@@ -19,6 +19,7 @@

?* MA 02111-1307 USA
?*/

+#include <config.h>
?#include <fcntl.h>
?#include <stdlib.h>
?#include <termios.h>

arch/sandbox/cpu/os.c +0 -0
@@ -30,6 +31,19 @@

?#include <sys/mman.h>
?#include <linux/types.h>

Quoted 1 line

+#ifdef CONFIG_NET_TAP

I don't think we need this #ifdef

Quoted 19 lines
arch/sandbox/cpu/os.c +12 -0
+#include <string.h>
+#include <stdio.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <linux/socket.h>
+#include <linux/if.h>
+#include <linux/if_tun.h>
+#include <linux/if_arp.h>
+#include <linux/if_ether.h>
+
+#endif
+

?#include <os.h>

?/* Operating System Interface */

arch/sandbox/cpu/os.c +0 -0
@@ -121,3 +135,90 @@ u64 os_get_nsec(void)
 ? ? ? ?return tv.tv_sec * 1000000000ULL + tv.tv_usec * 1000;

?#endif
?}

arch/sandbox/cpu/os.c

Quoted 2 lines
arch/sandbox/cpu/os.c +2 -0
+
+#ifdef CONFIG_NET_TAP

Is there a reason for not always enabling this function?

Quoted 4 lines
arch/sandbox/cpu/os.c +4 -0
+int os_tap_open(const char *dev, unsigned char *hwaddr)
+{
+ ? ? ? struct ifreq ifr;
+ ? ? ? int fd, err;

arch/sandbox/cpu/os.c

Quoted 10 lines
arch/sandbox/cpu/os.c +10 -0
+
+ ? ? ? fd = open("/dev/net/tun", O_RDWR | O_NONBLOCK);
+ ? ? ? if (fd < 0) {
+ ? ? ? ? ? ? ? perror("could not open /dev/net/tun");
+ ? ? ? ? ? ? ? return -1;
+ ? ? ? }
+
+ ? ? ? memset(&ifr, 0, sizeof(ifr));
+
+ ? ? ? /* Flags: IFF_TUN ? - TUN device (no Ethernet headers)

Comment style:

/*
* Flags:

Quoted 146 lines

+ ? ? ? ?* ? ? ? ?IFF_TAP ? - TAP device
+ ? ? ? ?*
+ ? ? ? ?* ? ? ? ?IFF_NO_PI - Do not provide packet information
+ ? ? ? ?*/
+ ? ? ? ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
+ ? ? ? strncpy(ifr.ifr_name, dev, IFNAMSIZ);

arch/sandbox/cpu/os.c +65 -0
+
+ ? ? ? err = ioctl(fd, TUNSETIFF, (void *)&ifr);
+ ? ? ? if (err < 0) {
+ ? ? ? ? ? ? ? perror("could not get tap device");
+ ? ? ? ? ? ? ? close(fd);
+ ? ? ? ? ? ? ? return err;
+ ? ? ? }
+
+ ? ? ? if (ioctl(fd, SIOCGIFHWADDR, (void *)&ifr) >= 0)
+ ? ? ? ? ? ? ? memcpy(hwaddr, &ifr.ifr_hwaddr.sa_data, ETH_ALEN);
+
+ ? ? ? return fd;
+}
+
+int os_tap_set_hw_addr(int fd, unsigned char *hwaddr)
+{
+ ? ? ? /*
+ ? ? ? ?* The following code should be able to change the MAC of a TAP
+ ? ? ? ?* interface but doesn't work on my box. So leave it disabled
+ ? ? ? ?* here as a reference if someone is going to pick that up in
+ ? ? ? ?* the future.
+ ? ? ? ?*/
+#if 0
+ ? ? ? struct ifreq ifr;
+
+ ? ? ? memset(&ifr, 0, sizeof(ifr));
+ ? ? ? strncpy(ifr.ifr_name, "tap0", IFNAMSIZ);
+
+ ? ? ? /* Get the interface flags */
+ ? ? ? if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
+ ? ? ? ? ? ? ? perror("Could not get interface flags");
+ ? ? ? ? ? ? ? return -1;
+ ? ? ? }
+ ? ? ? /* Shut down the interface */
+ ? ? ? ifr.ifr_flags &= ~(IFF_UP);
+ ? ? ? if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) {
+ ? ? ? ? ? ? ? perror("Could not down the interface");
+ ? ? ? ? ? ? ? return -1;
+ ? ? ? }
+
+ ? ? ? /* Set the new hw address */
+ ? ? ? ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
+ ? ? ? memcpy(&ifr.ifr_hwaddr.sa_data, hwaddr, ETH_ALEN);
+
+ ? ? ? if (ioctl(fd, SIOCSIFHWADDR, &ifr) < 0) {
+ ? ? ? ? ? ? ? perror("ioctl(SIOCSIFHWADDR)");
+ ? ? ? ? ? ? ? return -1;
+ ? ? ? }
+
+ ? ? ? /* Get the interface flags */
+ ? ? ? if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
+ ? ? ? ? ? ? ? perror("Could not get interface flags");
+ ? ? ? ? ? ? ? return -1;
+ ? ? ? }
+ ? ? ? /* Shut down the interface */
+ ? ? ? ifr.ifr_flags |= IFF_UP;
+ ? ? ? if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) {
+ ? ? ? ? ? ? ? perror("Could not up the interface");
+ ? ? ? ? ? ? ? return -1;
+ ? ? ? }
+ ? ? ? return 0;
+#endif
+ ? ? ? return -1;
+}
+#endif
arch/sandbox/lib/board.c +0 -0
index b7997e9..d02f6ca 100644
@@ -257,6 +257,11 @@ void board_init_r(gd_t *id, ulong dest_addr)
 ? ? ? ?board_late_init();

?#endif

arch/sandbox/lib/board.c +5 -0
+#if defined(CONFIG_CMD_NET)
+ ? ? ? puts("Net: ? ");
+ ? ? ? eth_initialize(gd->bd);
+#endif
+

?#ifdef CONFIG_POST
? ? ? ?post_run(NULL, POST_RAM | post_bootmode_get(0)); ?#endif

drivers/net/Makefile +0 -0
index d3df82e..914b1b7 100644
@@ -69,6 +69,7 @@ COBJS-$(CONFIG_SH_ETHER) += sh_eth.o

?COBJS-$(CONFIG_SMC91111) += smc91111.o
?COBJS-$(CONFIG_SMC911X) += smc911x.o
?COBJS-$(CONFIG_DRIVER_TI_EMAC) += davinci_emac.o
+COBJS-$(CONFIG_NET_TAP) += tap.o
?COBJS-$(CONFIG_TSEC_ENET) += tsec.o fsl_mdio.o
?COBJS-$(CONFIG_FMAN_ENET) += fsl_mdio.o
?COBJS-$(CONFIG_TSI108_ETH) += tsi108_eth.o

drivers/net/tap.c new file +41 -0
new file mode 100644
index 0000000..c02bb1b
@@ -0,0 +1,118 @@
+/*
+ * tap.c - A tap ethernet driver for u-boot
+ *
+ * Copyright (c) 2011 Matthias Wei?er <[email protected]>
+ *
+ * Based on fec_mxc.c and tap.c from barebox:
+ * Copyright (c) 2007 Sascha Hauer <[email protected]>, Pengutronix
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ?See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA ?02111-1307 ?USA
+ */
+
+#include <common.h>
+#include <malloc.h>
+#include <errno.h>
+#include <net.h>
+#include <os.h>
+
+struct tap_priv {
+ ? ? ? int fd; /* file descriptor */
+};
+
+static int tap_init(struct eth_device *dev, bd_t* bd)
+{
+ ? ? ? /* Nothing to be done here */
+ ? ? ? return 0;
+}
+

drivers/net/tap.c line 51

Quoted 10 lines
drivers/net/tap.c new file +10 -0
+static void tap_halt(struct eth_device *dev)
+{
+ ? ? ? /* Nothing to be done here */
+}
+
+static int tap_send(struct eth_device *dev, volatile void *packet, int length)
+{
+ ? ? ? struct tap_priv *tap = dev->priv;
+
+ ? ? ? os_write(tap->fd, (void *)packet, length);

check for os_write() failure?

drivers/net/tap.c

Quoted 7 lines
drivers/net/tap.c new file +7 -0
+ ? ? ? return 0;
+}
+
+static int tap_recv(struct eth_device *dev)
+{
+ ? ? ? struct tap_priv *tap = dev->priv;
+ ? ? ? int length;

Use ssize_t here?

Quoted 11 lines
drivers/net/tap.c new file +11 -0
+
+ ? ? ? length = (int)os_read(tap->fd, (void *)NetRxPackets[0], PKTSIZE);
+
+ ? ? ? if (length > 0)
+ ? ? ? ? ? ? ? NetReceive(NetRxPackets[0], length);
+
+ ? ? ? return 0;
+}
+
+static int tap_set_hwaddr(struct eth_device *dev)
+{

drivers/net/tap.c

Quoted 10 lines
drivers/net/tap.c new file +10 -0
+ ? ? ? struct tap_priv *tap = dev->priv;
+
+ ? ? ? return os_tap_set_hw_addr(tap->fd, dev->enetaddr);
+}
+
+int tap_initialize(bd_t *bd, char * dname)
+{
+ ? ? ? struct eth_device *dev;
+ ? ? ? struct tap_priv *tap;
+ ? ? ? int res = 0;

Perhaps set this to -1 until you get to the success path? Otherwise you see success with err1 and err2 below.

Quoted 66 lines
drivers/net/tap.c new file +39 -0
+
+ ? ? ? /* create and fill edev struct */
+ ? ? ? dev = malloc(sizeof(struct eth_device));
+ ? ? ? if (!dev)
+ ? ? ? ? ? ? ? goto err1;
+
+ ? ? ? tap = malloc(sizeof(struct tap_priv));
+ ? ? ? if (!tap)
+ ? ? ? ? ? ? ? goto err2;
+
+ ? ? ? memset(dev, 0, sizeof(*dev));
+ ? ? ? memset(tap, 0, sizeof(*tap));
+
+ ? ? ? strncpy(dev->name, dname, sizeof(dev->name));
+ ? ? ? tap->fd = os_tap_open(dev->name, dev->enetaddr);
+ ? ? ? if (tap->fd < 0) {
+ ? ? ? ? ? ? ? res = -1;
+ ? ? ? ? ? ? ? goto err3;
+ ? ? ? }
+
+ ? ? ? dev->priv = tap;
+ ? ? ? dev->init = tap_init;
+ ? ? ? dev->send = tap_send;
+ ? ? ? dev->recv = tap_recv;
+ ? ? ? dev->halt = tap_halt;
+ ? ? ? dev->write_hwaddr = tap_set_hwaddr;
+
+ ? ? ? strncpy(dev->name, dname, sizeof(dev->name));
+ ? ? ? eth_register(dev);
+
+ ? ? ? return res;
+
+err3:
+ ? ? ? free(tap);
+err2:
+ ? ? ? free(dev);
+err1:
+ ? ? ? return res;
+}
include/configs/sandbox.h +0 -0
index 10565e6..33b1a19 100644
@@ -69,12 +69,13 @@
 

?#define CONFIG_SYS_NO_FLASH

include/configs/sandbox.h +3 -0
+/* Network support */
+#define CONFIG_NET_TAP
+

?/* include default commands */
?#include <config_cmd_default.h>

include/configs/sandbox.h +2 -4
-
-/* We don't have networking support yet */
-#undef CONFIG_CMD_NET
-#undef CONFIG_CMD_NFS
+#define CONFIG_CMD_DHCP
+#define CONFIG_CMD_PING

?#define CONFIG_BOOTARGS ""

include/netdev.h +0 -0
index 04d9f75..25173a8 100644

include/netdev.h int xilinx_axiemac_initialize(bd_t *bis, unsigned long base_addr, · line 103

Quoted 4 lines
include/netdev.h +1 -0
@@ -100,6 +100,7 @@ int xilinx_axiemac_initialize(bd_t *bis, unsigned long base_addr,
 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?unsigned long dma_addr);
 ?int xilinx_emaclite_initialize(bd_t *bis, unsigned long base_addr,
 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?int txpp, int rxpp);
+int tap_initialize(bd_t *bd, char * dname);

Can we please have arg/return comments on this new function?

Quoted 11 lines
include/netdev.h +0 -0
 ?/* Boards with PCI network controllers can call this from their board_eth_init()

?* function to initialize whatever's on board.

include/os.h +0 -0
index f3af4f0..3b0c629 100644
@@ -98,3 +98,21 @@ void os_usleep(unsigned long usec);

?* \return A monotonic increasing time scaled in nano seconds ?*/
?u64 os_get_nsec(void);

include/os.h void os_usleep(unsigned long usec); · line 107

Quoted 7 lines
include/os.h +7 -0
+
+/**
+ * Opens a TAP device for network emulation
+ *
+ * \param dev Device name to be opened
+ * \param hwaddr Ethernet address of interface is copied here (6 byte)
+ * \return File descriptor of the device

While I'm fine with \ I think U-Boot tends to use @.

include/os.h void os_usleep(unsigned long usec); · line 116

Quoted 9 lines

+ */

include/os.h +8 -0
+int os_tap_open(const char *dev, unsigned char *hwaddr);
+
+/**
+ * Sets the hw address of a open tap interface
+ *
+ * \param fd The fd of the tap interface
+ * \param hwaddr The address to be set (6 byte)
+ * \return -1 if the hwaddr couldn't be set

or 0 on success?

Quoted 5 lines

+ */
+int os_tap_set_hw_addr(int fd, unsigned char *hwaddr); --
1.7.5.4

Regards,
Simon

#8 lore raw

PATCH 1/1 sandbox: Add tap based networking

Quoted 15 lines · On Tuesday 13 December 2011 18:54:59 Simon Glass wrote:
Quoted 14 lines · Matthias Weisser
arch/sandbox/cpu/os.c +1 -0
@@ -19,6 +19,7 @@
 * MA 02111-1307 USA
 */
 
+#include <config.h>
 #include <fcntl.h>
 #include <stdlib.h>
 #include <termios.h>
@@ -30,6 +31,19 @@
 #include <sys/mman.h>
 #include <linux/types.h>
 
Quoted 3 lines

arch/sandbox/cpu/os.c line 34

Quoted 1 line
arch/sandbox/cpu/os.c +1 -0
+#ifdef CONFIG_NET_TAP

I don't think we need this #ifdef

i think it's fine. the current code isn't too tied to Linux, but adding NET_TAP unconditionally would make it completely Linux specific ...
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20111213/3e952547/attachment.pgp>

#9 lore raw

PATCH 1/1 sandbox: Add tap based networking

Hi Mike,

Quoted 16 lines · Mike Frysinger
Quoted 15 lines · On Tuesday 13 December 2011 18:54:59 Simon Glass wrote:
Quoted 14 lines · Matthias Weisser
arch/sandbox/cpu/os.c +0 -0
@@ -19,6 +19,7 @@

?* MA 02111-1307 USA
?*/

+#include <config.h>
?#include <fcntl.h>
?#include <stdlib.h>
?#include <termios.h>

arch/sandbox/cpu/os.c +0 -0
@@ -30,6 +31,19 @@

?#include <sys/mman.h>
?#include <linux/types.h>

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

+#ifdef CONFIG_NET_TAP

I don't think we need this #ifdef

i think it's fine. ?the current code isn't too tied to Linux, but adding NET_TAP unconditionally would make it completely Linux specific ... -mike

OK that's fine.

Regards,
Simon

#10 lore raw

PATCH 1/1 sandbox: Add tap based networking

In reply to Matthias Weisser

Dear Matthias Weisser,

Quoted 18 lines · In message <[email protected]> you wrote:

This patch adds support for networking to sandbox architecture using tap. A tap device "tap0" has to be created e.g. using openvpn

$ openvpn --mktun --dev tap0

u-boot should then be able to detect the network device on startup. To test the network related commands the following commands can be used to create an ethernet bridge to local network connection.

$ brctl addbr br0
$ ifconfig eth0 0.0.0.0 promisc
$ ifconfig tap0 0.0.0.0
$ brctl addif br0 eth0
$ brctl addif br0 tap0
$ ifconfig br0 up
$ pump -i br0

...

Quoted 38 lines
arch/sandbox/cpu/os.c +38 -0
+int os_tap_set_hw_addr(int fd, unsigned char *hwaddr)
+{
+	/*
+	 * The following code should be able to change the MAC of a TAP
+	 * interface but doesn't work on my box. So leave it disabled
+	 * here as a reference if someone is going to pick that up in
+	 * the future.
+	 */
+#if 0
+	struct ifreq ifr;
+
+	memset(&ifr, 0, sizeof(ifr));
+	strncpy(ifr.ifr_name, "tap0", IFNAMSIZ);
+
+	/* Get the interface flags */
+	if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
+		perror("Could not get interface flags");
+		return -1;
+	}
+	/* Shut down the interface */
+	ifr.ifr_flags &= ~(IFF_UP);
+	if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) {
+		perror("Could not down the interface");
+		return -1;
+	}
+
+	/* Set the new hw address */
+	ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
+	memcpy(&ifr.ifr_hwaddr.sa_data, hwaddr, ETH_ALEN);
+
+	if (ioctl(fd, SIOCSIFHWADDR, &ifr) < 0) {
+		perror("ioctl(SIOCSIFHWADDR)");
+		return -1;
+	}
+
+	/* Get the interface flags */
+	if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
+		perror("Could not get interface flags");

arch/sandbox/cpu/os.c u64 os_get_nsec(void) · line 221

Quoted 10 lines
arch/sandbox/cpu/os.c +10 -0
+		return -1;
+	}
+	/* Shut down the interface */
+	ifr.ifr_flags |= IFF_UP;
+	if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) {
+		perror("Could not up the interface");
+		return -1;
+	}
+	return 0;
+#endif

Please do not add dead code.

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Even historians fail to learn from history -- they repeat the same
mistakes.
	-- John Gill, "Patterns of Force", stardate 2534.7