From owner-freebsd-hackers@FreeBSD.ORG Wed Jun 2 02:26:30 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6588516A4CF for ; Wed, 2 Jun 2004 02:26:30 -0700 (PDT) Received: from mailtoaster1.pipeline.ch (mailtoaster1.pipeline.ch [62.48.0.70]) by mx1.FreeBSD.org (Postfix) with ESMTP id 86C1743D3F for ; Wed, 2 Jun 2004 02:26:29 -0700 (PDT) (envelope-from andre@freebsd.org) Received: (qmail 77616 invoked from network); 2 Jun 2004 09:26:27 -0000 Received: from unknown (HELO [62.48.0.47]) ([62.48.0.47]) (envelope-sender ) by mailtoaster1.pipeline.ch (qmail-ldap-1.03) with SMTP for ; 2 Jun 2004 09:26:27 -0000 Message-ID: <40BD9D3F.7090100@freebsd.org> Date: Wed, 02 Jun 2004 11:26:23 +0200 From: Andre Oppermann User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7) Gecko/20040514 X-Accept-Language: en-us, en MIME-Version: 1.0 To: "Christian S.J. Peron" References: <20040602043537.GA42327@freefall.freebsd.org> In-Reply-To: <20040602043537.GA42327@freefall.freebsd.org> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit cc: hackers@freebsd.org cc: ipfw@freebsd.org Subject: Re: ipfw cached ucred patch X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Jun 2004 09:26:30 -0000 Christian S.J. Peron wrote: > All, > > Currently, when you have any rules which contain UID/GID > constraints, ipfw will lock the pcb hash and do a lookup > to find the pcb associated with that packet -- > One for each constraint. > > I have written a patch in attempt to minimize the impact > of PCB related lookups for these type of firewall rules. > > This patch will have the following effects on firewalls which > contain UID/GID constraints: > > o Greatly reduce the locking contention associated > with PCB lookups. > > o Increase the performance of firewall in general by making > PCB lookups O(1) rather than O(n) (where n represents > number of UID/GID constraints in the ruleset) > > It would be greatly appriciated if people who are running ipfw > rules sets containing UID/GID constraints tested this patch > and reported any success or failures. > > The patch can be downloaded from: > > http://people.freebsd.org/~csjp/ip_fw2_cached_ucred.patch You can optimize it even further by directly copying the uid/gid from the ucred while you hold the INP_LOCK. There is no need to hold on to the entire ucred. It should be sufficient to do the ucred lookup only once per packet in the ipfw code. If you don't find an INPCB for the packet you'll do a negative lookup for every uid/gid rule. > It also appears that ip_output passes a reference to the PCB. > Perhaps we can hold a reference to the ucred stored in that > entry and do away with lookups on outgoing packets all-together? Yes, that would be possible but that weaves ipfw even tighter with ip_output and I'm currently converting it to go through the pfil_hooks mechanism. Pfil_hooks does not allow such additional information to be passed along directly. What you could do is to pass a m_tag with the numerical uid/gid along with locally generated packets to get the same effect. Here it would be good to co-ordinate with pf/ipfilter guys so that they can use this m_tag too. However for a first step just redo the lookup once per packet if neccessary. -- Andre