From: Tully Gray <tullygray@arc.net.au>
To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net>
Subject: [9fans] tun/tap support for 9vx
Date: Sat, 8 May 2010 03:54:26 +1000 [thread overview]
Message-ID: <20100507175426.GA24219@diamond.realm.of.chaos> (raw)
[-- 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",
next reply other threads:[~2010-05-07 17:54 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-07 17:54 Tully Gray [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100507175426.GA24219@diamond.realm.of.chaos \
--to=tullygray@arc.net.au \
--cc=9fans@9fans.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).