From owner-freebsd-net@FreeBSD.ORG Sun Oct 31 09:44:59 2004 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 9D0A916A4CE for ; Sun, 31 Oct 2004 09:44:59 +0000 (GMT) Received: from fledge.watson.org (fledge.watson.org [204.156.12.50]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4432E43D2F for ; Sun, 31 Oct 2004 09:44:59 +0000 (GMT) (envelope-from robert@fledge.watson.org) Received: from fledge.watson.org (localhost [127.0.0.1]) by fledge.watson.org (8.13.1/8.13.1) with ESMTP id i9V9iHH5048255; Sun, 31 Oct 2004 04:44:17 -0500 (EST) (envelope-from robert@fledge.watson.org) Received: from localhost (robert@localhost)i9V9iHkX048252; Sun, 31 Oct 2004 09:44:17 GMT (envelope-from robert@fledge.watson.org) Date: Sun, 31 Oct 2004 09:44:17 +0000 (GMT) From: Robert Watson X-Sender: robert@fledge.watson.org To: kamal kc In-Reply-To: <20041031082704.30632.qmail@web13009.mail.yahoo.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: freebsd-net@freebsd.org Subject: Re: Bridge--using Packet Capture Library(libpcap.a) -- efficiency ????? 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: Sun, 31 Oct 2004 09:44:59 -0000 On Sun, 31 Oct 2004, kamal kc wrote: > I have made a bridge using the Packet Capture Library I set the two nics > to promiscous mode and transfer packet between the two packet capture > handles A piece of the code I use for initializing the packet capture Copying every packet into and out of user space along with the at least two system calls to do each packet will necessarily be expensive. However, 3ms sounds far to high to me, do you have other processes running (such as tcpdump) that might result in additional context switches? I have used BPF to do bridging previously with a lot of success; I have some sample code bridging over a tap interface and a TCP socket -- the source (functional but not pretty) is at: http://www.watson.org/~robert/freebsd/netbridge/ The only complicated bit is walking through the BPF buffer, where sample code is invaluable. Everything else is very straight forward. If you're doing a bridge, you probably want to set the BPF flag so you don't loop any packets. Robert N M Watson FreeBSD Core Team, TrustedBSD Projects robert@fledge.watson.org Principal Research Scientist, McAfee Research