From owner-freebsd-net@FreeBSD.ORG Thu Jul 10 11:10:18 2003 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0ADD137B401 for ; Thu, 10 Jul 2003 11:10:18 -0700 (PDT) Received: from ecserv7.uwaterloo.ca (ecserv7.uwaterloo.ca [129.97.50.127]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2F8B543F3F for ; Thu, 10 Jul 2003 11:10:17 -0700 (PDT) (envelope-from kw3wong@engmail.uwaterloo.ca) Received: from ecserv7.uwaterloo.ca (localhost.uwaterloo.ca [127.0.0.1]) h6AIAGWa004243; Thu, 10 Jul 2003 14:10:16 -0400 (EDT) (envelope-from kw3wong@engmail.uwaterloo.ca) Received: (from www@localhost) by ecserv7.uwaterloo.ca (8.12.6p2/8.12.6/Submit) id h6AIAFP8004242; Thu, 10 Jul 2003 14:10:15 -0400 (EDT) (envelope-from kw3wong@engmail.uwaterloo.ca) X-Authentication-Warning: ecserv7.uwaterloo.ca: www set sender to kw3wong@engmail.uwaterloo.ca using -f Received: from 129.97.106.24 ( [129.97.106.24])with HTTP; Thu, 10 Jul 2003 14:10:15 -0400 Message-ID: <1057860615.3f0dac07e1418@www.nexusmail.uwaterloo.ca> Date: Thu, 10 Jul 2003 14:10:15 -0400 From: kw3wong@engmail.uwaterloo.ca To: Luigi Rizzo References: <1057778632.3f0c6bc8af474@www.nexusmail.uwaterloo.ca> <20030709195455.A24039@xorpc.icir.org> In-Reply-To: <20030709195455.A24039@xorpc.icir.org> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit User-Agent: Internet Messaging Program (IMP) 3.1 / FreeBSD-4.6.2 X-Originating-IP: 129.97.106.24 cc: freebsd-net@freebsd.org cc: dsze@engmail.uwaterloo.ca Subject: Re: Question about bridging code X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Jul 2003 18:10:18 -0000 Hi Luigi, Thanks for response, the vmnet/tap stuff sounds like neat stuff. After reading the description of tap (from the vtun site), the system seems to make a lot of sense. However, I'm not sure how vmnet comes into play here - what purpose does it serve, shouldn't I just be able to read from the /dev/tap0 and bridge between tap0 and fxp0? I tried writing a simple program to use tap. Basically, I have the bridge setup as such net.link.ether.bridge_cfg: fxp0:0,tap0:0 tap1:1 bge0:1 And I ran this quick test program that I wrote: #include // ssize_t #include // ::socket #include // n_long #include // IPPROTO_DIVERT, struct sockaddr_in #include // IP_MAXPACKET #include // struct tcphdr #include // ::fcntl #include // ::err #include // errno #include // ::printf #include // ::bcopy #include // ::close #define MAX(a, b) (((a) > (b)) ? (a) : (b)) /** main */ int main() { int nFDRight; int nFDLeft; unsigned char kpucInPacket[IP_MAXPACKET]; nFDRight = open("/dev/tap0", O_RDWR); if (nFDRight < 0) ::err(errno, "open"); nFDLeft = open("/dev/tap1", O_RDWR); if (nFDLeft < 0) ::err(errno, "open"); fd_set masterReadSocks; fd_set currentReadSocks; FD_ZERO(&masterReadSocks); FD_SET(nFDRight,&masterReadSocks); FD_SET(nFDLeft, &masterReadSocks); int nMaxFD = MAX(nFDRight, nFDLeft); while (true) { ::bcopy(&masterReadSocks, ¤tReadSocks, sizeof(fd_set)); int nSelectValue = select(nMaxFD + 1, ¤tReadSocks, NULL, NULL, NULL); printf("Unblocked on select\n"); if (nSelectValue == -1) { /* Signal interrupted, just continue */ if (errno == EINTR) continue; ::err(errno, "select"); } if (FD_ISSET(nFDRight, ¤tReadSocks)) { int nReadSize = read(nFDRight, kpucInPacket, sizeof(kpucInPacket)); if (nReadSize < 0) err(errno, "read"); if (write(nFDLeft, kpucInPacket, nReadSize) < 0) err(errno, "write"); } if (FD_ISSET(nFDLeft, ¤tReadSocks)) { int nReadSize = read(nFDLeft, kpucInPacket, sizeof(kpucInPacket)); if (nReadSize < 0) err(errno, "read"); if (write(nFDRight, kpucInPacket, nReadSize) < 0) err(errno, "write"); } } close(nFDLeft); close(nFDRight); } Unfortunately, it doesn't work, it only gets a read event when I make changes to the tap interface via ifconfig. I guess I don't fully understand how the /dev/tapN interface works, can you (or anybody who also know) point out what I'm doing wrong? Thanks again! Bernie ---------------------------------------- This mail sent through www.mywaterloo.ca