Re: [U-Boot] [PATCH] sandbox: Add tap based networking

2012-01-08 Thread Mike Frysinger
were you going to post an updated version ?
-mike


signature.asc
Description: This is a digitally signed message part.
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH] sandbox: Add tap based networking

2011-12-17 Thread Wolfgang Denk
Dear Matthias Weisser,

In message <1323021425-7854-1-git-send-email-weiss...@arcor.de> 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
> 
> Signed-off-by: Matthias Weisser 
...
> +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

Please do not add dead code.

Best regards,

Wolfgang Denk

-- 
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: w...@denx.de
Even historians fail to learn from history -- they repeat the same
mistakes.
-- John Gill, "Patterns of Force", stardate 2534.7
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH] sandbox: Add tap based networking

2011-12-15 Thread Simon Glass
Hi Mike,

On Tue, Dec 13, 2011 at 7:35 PM, Mike Frysinger  wrote:
> On Tuesday 13 December 2011 18:54:59 Simon Glass wrote:
>> On Sun, Dec 4, 2011 at 9:57 AM, Matthias Weisser wrote:
>> > --- a/arch/sandbox/cpu/os.c
>> > +++ b/arch/sandbox/cpu/os.c
>> > @@ -19,6 +19,7 @@
>> >  * MA 02111-1307 USA
>> >  */
>> >
>> > +#include 
>> >  #include 
>> >  #include 
>> >  #include 
>> > @@ -30,6 +31,19 @@
>> >  #include 
>> >  #include 
>> >
>> > +#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
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH] sandbox: Add tap based networking

2011-12-13 Thread Mike Frysinger
On Tuesday 13 December 2011 18:54:59 Simon Glass wrote:
> On Sun, Dec 4, 2011 at 9:57 AM, Matthias Weisser wrote:
> > --- a/arch/sandbox/cpu/os.c
> > +++ b/arch/sandbox/cpu/os.c
> > @@ -19,6 +19,7 @@
> >  * MA 02111-1307 USA
> >  */
> > 
> > +#include 
> >  #include 
> >  #include 
> >  #include 
> > @@ -30,6 +31,19 @@
> >  #include 
> >  #include 
> > 
> > +#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


signature.asc
Description: This is a digitally signed message part.
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH] sandbox: Add tap based networking

2011-12-13 Thread Simon Glass
Hi Matthias,

On Sun, Dec 4, 2011 at 9:57 AM, 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
>
> $ 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
>
> Signed-off-by: Matthias Weisser 

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

> ---
> 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
>
> diff --git a/arch/sandbox/cpu/cpu.c b/arch/sandbox/cpu/cpu.c
> index d7684d3..2fb3bae 100644
> --- a/arch/sandbox/cpu/cpu.c
> +++ b/arch/sandbox/cpu/cpu.c
> @@ -21,6 +21,7 @@
>
>  #include 
>  #include 
> +#include 
>
>  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
> diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
> index 6d55b5c..0c8cc82 100644
> --- a/arch/sandbox/cpu/os.c
> +++ b/arch/sandbox/cpu/os.c
> @@ -19,6 +19,7 @@
>  * MA 02111-1307 USA
>  */
>
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -30,6 +31,19 @@
>  #include 
>  #include 
>
> +#ifdef CONFIG_NET_TAP

I don't think we need this #ifdef

> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#endif
> +
>  #include 
>
>  /* Operating System Interface */
> @@ -121,3 +135,90 @@ u64 os_get_nsec(void)
>        return tv.tv_sec * 10ULL + tv.tv_usec * 1000;
>  #endif
>  }
> +
> +#ifdef CONFIG_NET_TAP

Is there a reason for not always enabling this function?

> +int os_tap_open(const char *dev, unsigned char *hwaddr)
> +{
> +       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)

Comment style:

/*
 * Flags:

> +        *        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);
> +
> +       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) {
> +               

[U-Boot] [PATCH] sandbox: Add tap based networking

2011-12-04 Thread 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

Signed-off-by: Matthias Weisser 
---
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

diff --git a/arch/sandbox/cpu/cpu.c b/arch/sandbox/cpu/cpu.c
index d7684d3..2fb3bae 100644
--- a/arch/sandbox/cpu/cpu.c
+++ b/arch/sandbox/cpu/cpu.c
@@ -21,6 +21,7 @@
 
 #include 
 #include 
+#include 
 
 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
diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
index 6d55b5c..0c8cc82 100644
--- a/arch/sandbox/cpu/os.c
+++ b/arch/sandbox/cpu/os.c
@@ -19,6 +19,7 @@
  * MA 02111-1307 USA
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -30,6 +31,19 @@
 #include 
 #include 
 
+#ifdef CONFIG_NET_TAP
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#endif
+
 #include 
 
 /* Operating System Interface */
@@ -121,3 +135,90 @@ u64 os_get_nsec(void)
return tv.tv_sec * 10ULL + tv.tv_usec * 1000;
 #endif
 }
+
+#ifdef CONFIG_NET_TAP
+int os_tap_open(const char *dev, unsigned char *hwaddr)
+{
+   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;
+   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;
+   }
+
+   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
diff --git a/arch/sandbox/lib/board.c b/arch/sandbox/lib/board.c
index b7997e9..d02f6ca 100644
--- a/arc