From owner-freebsd-net@FreeBSD.ORG Fri May 14 02:38:19 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 7605716A4CE for ; Fri, 14 May 2004 02:38:19 -0700 (PDT) Received: from fbsd.lv (fbsd.lv [159.148.95.82]) by mx1.FreeBSD.org (Postfix) with ESMTP id D759D43D45 for ; Fri, 14 May 2004 02:38:18 -0700 (PDT) (envelope-from artis@fbsd.lv) Received: by fbsd.lv (Postfix, from userid 10000) id 44D71C129; Fri, 14 May 2004 12:38:17 +0300 (EEST) Date: Fri, 14 May 2004 12:38:17 +0300 From: Artis Caune To: freebsd-net@freebsd.org Message-ID: <20040514093817.GA54302@fbsd.lv> References: <200404291422.56670.max@love2party.net> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <200404291422.56670.max@love2party.net> Subject: Re: 'struct ifnet' question! 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: Fri, 14 May 2004 09:38:19 -0000 Thanks, event handlers looks very trivial to implement. My thoughts was: userland read rules and check if interface exist with: 'if_nametoindex(interface)' call. kernel stores rules without any knowledge about interface name or direction, because I use seperate decision tree for every interface + direction pair. When module got departure event, all rules are flushed from in/out decision tree: flush_rules(decision_tree[ifp->if_index]->out); flush_rules(decision_tree[ifp->if_index]->in); because if interface is gone, rules are not valid: # ifconfig vlan0 create if_findindex() returns index 6 # load rules with '... in on vlan0 ...' kernel store rules in 'decision_tree[6]->in' # ifconfig vlan0 destory here we must flush all vlan0 rules # ifconfig gif0 create gif0 got index 6 if we don't flush old rules, gif0 will use vlan0 rules because index is reused... And here is the problem: If i watch departure events, interface renaming feature will flush walid rules: case SIOCSIFNAME: ... EVENTHANDLER_INVOKE(ifnet_departure_event, ifp); ... change if_xname ... EVENTHANDLER_INVOKE(ifnet_arrival_event, ifp); how about another event? ;) EVENTHANDLER_INVOKE(ifnet_rename_event, ifp->ifx_name, new_name); strlcpy(ifp->if_xname, new_name, sizeof(ifp->if_xname)); > The other (big) problem in this field is, how to handle yet unknown interfaces > (e.g. USB/Cardbus/ppp/tun/...). What is about usb/cardbus/... interfaces? Don't they also call ether_ifattach()/if_attach()? -- Artis On Thu, Apr 29, 2004 at 02:22:47PM +0200, Max Laier wrote: > Yes there is, in -current you will find some eventhandlers (in if_var.h and > if_clone.h) which allow you to get a notification when an interface arrives > or leaves. Pf (from OpenBSD 3.5) will use them to do exactly what you are > planning, to have O(1) interface look-ups. > > Attached is my WIP version of the pf interface handling, which might be a bit > too complex for your purpose, but should give you the idea. > > -- > Best regards, | mlaier@freebsd.org > Max Laier | ICQ #67774661 > http://pf4freebsd.love2party.net/ | mlaier@EFnet