From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Sat, 8 May 2010 03:54:26 +1000 From: Tully Gray To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Message-ID: <20100507175426.GA24219@diamond.realm.of.chaos> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="qMm9M+Fa2AknHoGS" Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Subject: [9fans] tun/tap support for 9vx Topicbox-Message-UUID: 1d8a15a0-ead6-11e9-9d60-3106f5b1d025 --qMm9M+Fa2AknHoGS Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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. --qMm9M+Fa2AknHoGS Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="tuntap.diff" 12a13 > #include 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", --qMm9M+Fa2AknHoGS--