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

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).