9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] tun/tap support for 9vx
@ 2010-05-07 17:54 Tully Gray
  2010-05-07 18:00 ` Devon H. O'Dell
  2010-05-07 18:57 ` Bakul Shah
  0 siblings, 2 replies; 7+ messages in thread
From: Tully Gray @ 2010-05-07 17:54 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 331 bytes --]

Hi,

I have modified Erik Quanstrom's raw socket ethernet driver
for 9vx so that it uses the Linux kernel's "tap" device.
It seems to work just fine. I create the tap device first
using "tunctl" which comes with the Usermode Linux toolkit
but I don't think this is necessary.

Tully Gray.

ps: I am shadowdaemon on IRC.

[-- Attachment #2: tuntap.diff --]
[-- Type: text/plain, Size: 1076 bytes --]

12a13
> #include <linux/if_tun.h>
38d38
< 	int fd;
40a41
> 	int fd;
42c43
< 	if((fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) < 0)
---
> 	if((fd = open("/dev/net/tun", O_RDWR)) < 0){
43a45,46
> 	}
>
45a49
> 		ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
47,55c51
< 		if(ioctl(fd, SIOCGIFINDEX, &ifr) < 0){
< 			close(fd);
< 			return -1;
< 		}
< 		memset(&sa, 0, sizeof sa);
< 		sa.sll_family = AF_PACKET;
< 		sa.sll_protocol = htons(ETH_P_ALL);
< 		sa.sll_ifindex = ifr.ifr_ifindex;
< 		if(bind(fd, (struct sockaddr*)&sa, sizeof sa) < 0){
---
> 		if(ioctl(fd, TUNSETIFF, &ifr) < 0){
61,71d56
< 	memset(&ifr, 0, sizeof ifr);
< 	strncpy(ifr.ifr_name, dev, sizeof ifr.ifr_name);
< 	if(ioctl(fd, SIOCGIFFLAGS, &ifr) < 0){
< 		close(fd);
< 		return -1;
< 	}
< 	ifr.ifr_flags |= IFF_PROMISC;
< 	if(ioctl(fd, SIOCSIFFLAGS, &ifr) < 0){
< 		close(fd);
< 		return -1;
< 	}
149c134
< 	0x00, 0x48, 0x01, 0x23, 0x45, 0x61,
---
> //	0x00, 0x48, 0x01, 0x23, 0x45, 0x61,
158c143
< 	"eth1", "eth0", "eth2", "eth3", "eth4", "eth5",
---
> 	"tap0",

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [9fans] tun/tap support for 9vx
  2010-05-07 17:54 [9fans] tun/tap support for 9vx Tully Gray
@ 2010-05-07 18:00 ` Devon H. O'Dell
  2010-05-07 18:04   ` erik quanstrom
  2010-05-07 18:57 ` Bakul Shah
  1 sibling, 1 reply; 7+ messages in thread
From: Devon H. O'Dell @ 2010-05-07 18:00 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

2010/5/7 Tully Gray <tullygray@arc.net.au>:
> Hi,
>
> I have modified Erik Quanstrom's raw socket ethernet driver
> for 9vx so that it uses the Linux kernel's "tap" device.
> It seems to work just fine. I create the tap device first
> using "tunctl" which comes with the Usermode Linux toolkit
> but I don't think this is necessary.

Thanks for this. My summer of code student will be working on wrapping
up some of this so that it's a bit nicer and more portable, and this
is a good start.

--Devon

> Tully Gray.
>
> ps: I am shadowdaemon on IRC.
>



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [9fans] tun/tap support for 9vx
  2010-05-07 18:00 ` Devon H. O'Dell
@ 2010-05-07 18:04   ` erik quanstrom
  2010-05-07 18:08     ` erik quanstrom
  2010-05-07 18:47     ` Tully Gray
  0 siblings, 2 replies; 7+ messages in thread
From: erik quanstrom @ 2010-05-07 18:04 UTC (permalink / raw)
  To: 9fans

> 2010/5/7 Tully Gray <tullygray@arc.net.au>:
> > Hi,
> >
> > I have modified Erik Quanstrom's raw socket ethernet driver
> > for 9vx so that it uses the Linux kernel's "tap" device.
> > It seems to work just fine. I create the tap device first
> > using "tunctl" which comes with the Usermode Linux toolkit
> > but I don't think this is necessary.
>
> Thanks for this. My summer of code student will be working on wrapping
> up some of this so that it's a bit nicer and more portable, and this
> is a good start.

interesting.  what's the advantage of the tap device?
is the code available online?

- erik



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [9fans] tun/tap support for 9vx
  2010-05-07 18:04   ` erik quanstrom
@ 2010-05-07 18:08     ` erik quanstrom
  2010-05-07 18:14       ` Devon H. O'Dell
  2010-05-07 18:47     ` Tully Gray
  1 sibling, 1 reply; 7+ messages in thread
From: erik quanstrom @ 2010-05-07 18:08 UTC (permalink / raw)
  To: 9fans

> interesting.  what's the advantage of the tap device?
> is the code available online?

duh.  sorry.  missed the attachment.  having peeked
at the code, do you think that the tap devices is a
complete replacement for the raw socket?

- erik



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [9fans] tun/tap support for 9vx
  2010-05-07 18:08     ` erik quanstrom
@ 2010-05-07 18:14       ` Devon H. O'Dell
  0 siblings, 0 replies; 7+ messages in thread
From: Devon H. O'Dell @ 2010-05-07 18:14 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

2010/5/7 erik quanstrom <quanstro@quanstro.net>:
>> interesting.  what's the advantage of the tap device?
>> is the code available online?
>
> duh.  sorry.  missed the attachment.  having peeked
> at the code, do you think that the tap devices is a
> complete replacement for the raw socket?

Yes. The tap(4) interface allows you to clone an existing ethernet
device on the system, and it's what most virtualization platforms use.
I had an ethertap.c in there, but never finished it up. It'll be
something that gets done for GSoC this year anyway.

--dho

> - erik
>
>



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [9fans] tun/tap support for 9vx
  2010-05-07 18:04   ` erik quanstrom
  2010-05-07 18:08     ` erik quanstrom
@ 2010-05-07 18:47     ` Tully Gray
  1 sibling, 0 replies; 7+ messages in thread
From: Tully Gray @ 2010-05-07 18:47 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Fri, May 07, 2010 at 02:04:47PM -0400, erik quanstrom wrote:
> > 2010/5/7 Tully Gray <tullygray@arc.net.au>:
> > > Hi,
> > >
> > > I have modified Erik Quanstrom's raw socket ethernet driver
> > > for 9vx so that it uses the Linux kernel's "tap" device.
> > > It seems to work just fine. I create the tap device first
> > > using "tunctl" which comes with the Usermode Linux toolkit
> > > but I don't think this is necessary.
> >
> > Thanks for this. My summer of code student will be working on wrapping
> > up some of this so that it's a bit nicer and more portable, and this
> > is a good start.
>
> interesting.  what's the advantage of the tap device?
> is the code available online?
>
> - erik

Hi,

originally I was using your driver and attaching it to either
eth0 or the bridge I have, br0. I was getting problems with
ARP, 9vx could see the traffic but the host could not see the
guest. Also 9vx would eventually crash due to freeing memory
that was in use. Is the raw socket driver meant to be attached
to a unused device? Both eth0 and br0 were being used by the
host system.

Tully Gray.

ps: I got the code to setup the tap device from http://vtun.sourceforge.net/



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [9fans] tun/tap support for 9vx
  2010-05-07 17:54 [9fans] tun/tap support for 9vx Tully Gray
  2010-05-07 18:00 ` Devon H. O'Dell
@ 2010-05-07 18:57 ` Bakul Shah
  1 sibling, 0 replies; 7+ messages in thread
From: Bakul Shah @ 2010-05-07 18:57 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Sat, 08 May 2010 03:54:26 +1000 Tully Gray <tullygray@arc.net.au>  wrote:
>
> I have modified Erik Quanstrom's raw socket ethernet driver
> for 9vx so that it uses the Linux kernel's "tap" device.

Neat!

> < 	if((fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) < 0)
> ---
> > 	if((fd = open("/dev/net/tun", O_RDWR)) < 0){

On *BSD tun is for IP frames, tap is for ethernet frames
so there you'd use /dev/tap.  You may wish to see how Qemu
handles tap differences & multiple tap interfaces on various
platforms.

On Fri, 07 May 2010 19:14:58 BST "Devon H. O'Dell" <devon.odell@gmail.com>  wrot
e:
>
> Yes. The tap(4) interface allows you to clone an existing ethernet
> device on the system, and it's what most virtualization platforms use.

Sorry for nitpicking!  "tap" appears as a completely separate
virtual ethernet interface to the host.  The "other end" of
tap is a device, to be open()ed by a program.  One can bridge
the host side interface to existing physical ethernet
interfaces but you don't have to.



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2010-05-07 18:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-07 17:54 [9fans] tun/tap support for 9vx Tully Gray
2010-05-07 18:00 ` Devon H. O'Dell
2010-05-07 18:04   ` erik quanstrom
2010-05-07 18:08     ` erik quanstrom
2010-05-07 18:14       ` Devon H. O'Dell
2010-05-07 18:47     ` Tully Gray
2010-05-07 18:57 ` Bakul Shah

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).