From owner-freebsd-net@FreeBSD.ORG Sat Mar 28 19:38:21 2009 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B95FC1065672 for ; Sat, 28 Mar 2009 19:38:21 +0000 (UTC) (envelope-from ermal.luci@gmail.com) Received: from mail-fx0-f167.google.com (mail-fx0-f167.google.com [209.85.220.167]) by mx1.freebsd.org (Postfix) with ESMTP id 122C38FC1B for ; Sat, 28 Mar 2009 19:38:20 +0000 (UTC) (envelope-from ermal.luci@gmail.com) Received: by fxm11 with SMTP id 11so1372093fxm.43 for ; Sat, 28 Mar 2009 12:38:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to:cc :content-type:content-transfer-encoding; bh=i+JLF3iJ/txCRMpNjbMlXVwtR3X2r9Sx2/ihHF38USs=; b=jFay9ty/CbGJE0cnKwL34PL0V9nKODhHR0JjJ7xY1RtOYl3lhYulpClyHQz4FPons+ a1032mZ5Y5vufIQvhb/mTwtXh2UfZs9tqrSYk5fAoNvIIQTREibUHWqc7HHTvEe9yDb+ 0FDWanawWf32aTDMm4/FaUBOefhPdpM0mRptw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=pz/N7y5tNsjNsB8gV/mIRzt83naytNt6PcPY7hDl/MdZKUQsWxmVmD1YAKrGG0OZRl UPg6acfbvyGNq9i2OSR0txl4ruH56U2GN+TxBfwsjPaqSqubcSWSiJ/r+ydsoCUYtE8B cP3qIB/BG+ijw4gurIilPBY4VzvLRN+OfzFkE= MIME-Version: 1.0 Sender: ermal.luci@gmail.com Received: by 10.86.95.20 with SMTP id s20mr3013909fgb.43.1238267435888; Sat, 28 Mar 2009 12:10:35 -0700 (PDT) In-Reply-To: <49C11E56.7090809@elischer.org> References: <6CBA0923-DAF1-4FD5-A670-F5888BCA47B1@aeria.net> <49C11E56.7090809@elischer.org> Date: Sat, 28 Mar 2009 20:10:35 +0100 X-Google-Sender-Auth: c9c4f57d1169328a Message-ID: <9a542da30903281210v1b4ce5a6w148bb60a8a6bc90c@mail.gmail.com> From: =?ISO-8859-1?Q?Ermal_Lu=E7i?= To: Julian Elischer Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: freebsd-net@freebsd.org, Ash Gokhale Subject: Re: netgraph modules won't unload after use X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 28 Mar 2009 19:38:22 -0000 On Wed, Mar 18, 2009 at 5:16 PM, Julian Elischer wrot= e: > Ash Gokhale wrote: >> >> =A0I'm developing a kernel module that will be doing inspection and need= ed >> access to raw network frames, >> =A0so I turned to netgraph =A0as the solution.However it seems that netg= raph >> will not permit a module >> =A0to unload once it's participated in a mkpeer/connect operation. Reboo= ting >> to remove a module is >> =A0angrymaking (not like mtx/sleep crashes). >> >> =A0 =A0This going into the kernel because my bpf based userland stuff is >> probably not going to hold up to the packet rate. >> >> Should I file a PR? Or is there magic in the documentation I havn't foun= d? >> >> >> I've observed the trouble in 7.0 release, and tonight's =A07_RELENG, wit= h >> GENERIC + WITNESS/INVARIANTS >> >> The module code =A0( cobbled together from netgraph/ng_sample.c / ng_ech= o.c) >> http://pastebin.com/m31b6ece6 >> >> The module loads and unloads fine until connected to a netgraph hook: > > hmm they are supposed to, and they did in the past.. > let me check... > > root@trafmon1:kldload ng_ether > root@trafmon1:ifconfig > bge0: flags=3D8843 metric 0 mtu 1= 500 > =A0 =A0 =A0 =A0options=3D9b > =A0 =A0 =A0 =A0ether 00:11:43:30:fb:8a > =A0 =A0 =A0 =A0inet 10.7.2.3 netmask 0xffffff00 broadcast 10.7.2.255 > =A0 =A0 =A0 =A0media: Ethernet autoselect (100baseTX ) > =A0 =A0 =A0 =A0status: active > bge1: flags=3D8802 metric 0 mtu 1500 > =A0 =A0 =A0 =A0options=3D9b > =A0 =A0 =A0 =A0ether 00:11:43:30:fb:8b > =A0 =A0 =A0 =A0media: Ethernet autoselect (none) > =A0 =A0 =A0 =A0status: no carrier > fxp0: flags=3D8843 metric 0 mtu 1= 500 > =A0 =A0 =A0 =A0options=3Db > =A0 =A0 =A0 =A0ether 00:0e:0c:62:aa:14 > =A0 =A0 =A0 =A0inet 10.7.0.101 netmask 0xffffff00 broadcast 10.7.0.255 > =A0 =A0 =A0 =A0media: Ethernet autoselect (100baseTX ) > =A0 =A0 =A0 =A0status: active > lo0: flags=3D8049 metric 0 mtu 16384 > =A0 =A0 =A0 =A0inet 127.0.0.1 netmask 0xff000000 > root@trafmon1:ngctl > + list > There are 4 total nodes: > =A0Name: bge0 =A0 =A0 =A0 =A0 =A0 =A0Type: ether =A0 =A0 =A0 =A0 =A0 ID: = 00000002 =A0 Num hooks: 0 > =A0Name: bge1 =A0 =A0 =A0 =A0 =A0 =A0Type: ether =A0 =A0 =A0 =A0 =A0 ID: = 00000003 =A0 Num hooks: 0 > =A0Name: ngctl4252 =A0 =A0 =A0 Type: socket =A0 =A0 =A0 =A0 =A0ID: 000000= 05 =A0 Num hooks: 0 > =A0Name: fxp0 =A0 =A0 =A0 =A0 =A0 =A0Type: ether =A0 =A0 =A0 =A0 =A0 ID: = 00000004 =A0 Num hooks: 0 > + mkpeer bge0: hole lower hook > + list > There are 5 total nodes: > =A0Name: =A0 =A0 =A0 Type: hole =A0 =A0 =A0 =A0 =A0 =A0ID: 0000= 0006 =A0 Num hooks: 1 > =A0Name: bge0 =A0 =A0 =A0 =A0 =A0 =A0Type: ether =A0 =A0 =A0 =A0 =A0 ID: = 00000002 =A0 Num hooks: 1 > =A0Name: bge1 =A0 =A0 =A0 =A0 =A0 =A0Type: ether =A0 =A0 =A0 =A0 =A0 ID: = 00000003 =A0 Num hooks: 0 > =A0Name: ngctl4252 =A0 =A0 =A0 Type: socket =A0 =A0 =A0 =A0 =A0ID: 000000= 05 =A0 Num hooks: 0 > =A0Name: fxp0 =A0 =A0 =A0 =A0 =A0 =A0Type: ether =A0 =A0 =A0 =A0 =A0 ID: = 00000004 =A0 Num hooks: 0 > + shutdown [6]: > + list > There are 4 total nodes: > =A0Name: bge0 =A0 =A0 =A0 =A0 =A0 =A0Type: ether =A0 =A0 =A0 =A0 =A0 ID: = 00000002 =A0 Num hooks: 0 > =A0Name: bge1 =A0 =A0 =A0 =A0 =A0 =A0Type: ether =A0 =A0 =A0 =A0 =A0 ID: = 00000003 =A0 Num hooks: 0 > =A0Name: ngctl4252 =A0 =A0 =A0 Type: socket =A0 =A0 =A0 =A0 =A0ID: 000000= 05 =A0 Num hooks: 0 > =A0Name: fxp0 =A0 =A0 =A0 =A0 =A0 =A0Type: ether =A0 =A0 =A0 =A0 =A0 ID: = 00000004 =A0 Num hooks: 0 > + quit > root@trafmon1:kldstat -v > Id Refs Address =A0 =A0Size =A0 =A0 Name > =A01 =A0 36 0xc0400000 6a9c28 =A0 kernel (/boot/kernel/kernel) > > [...] > > =A07 =A0 =A01 0xccb16000 4000 =A0 =A0 ng_ether.ko (/boot/kernel/ng_ether.= ko) > =A0 =A0 =A0 =A0Contains modules: > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Id Name > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0246 ng_ether > =A08 =A0 =A01 0xccb1b000 2000 =A0 =A0 ng_hole.ko (/boot/kernel/ng_hole.ko= ) > =A0 =A0 =A0 =A0Contains modules: > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Id Name > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0247 ng_hole > root@trafmon1:klunload ng_hole > klunload: Command not found. > root@trafmon1:kldunload ng_hole > root@trafmon1:kldunload ng_ether > kldunload: can't unload file: Device busy > root@trafmon1:kldstat -v > Id Refs Address =A0 =A0Size =A0 =A0 Name > =A01 =A0 36 0xc0400000 6a9c28 =A0 kernel (/boot/kernel/kernel) > > [...] > > =A07 =A0 =A01 0xccb16000 4000 =A0 =A0 ng_ether.ko (/boot/kernel/ng_ether.= ko) > =A0 =A0 =A0 =A0Contains modules: > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Id Name > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0246 ng_ether > root@trafmon1: > > > this is expected. =A0ng-ether is not unloadable as the connections are to= o > complicated to unwind easily.. one day.... > > root@trafmon1: > >>> Stop in /root/tmp/food.ko. >>> Exit 1 >>> #Mar 18 03:14:31 =A0kernel: quiesced >>> =A0:ro:~/tmp/food.ko:3:14:31:32 >>> Mar 18 03:14:31 =A0kernel: foodmod unloaded >> >> >> Seems that I can't unload some of the other netgraph types either ( it's >> not just me): >> >>> #kldunload ng_ether >>> :ro:~/tmp/food.ko:3:24:07:41 >>> kldunload: can't unload file: Device busy >>> Exit 1 > > try unloading a node that IS unloadable.. > > see the following comment in ng_ehter.c: > =A0 =A0 =A0 =A0 /* > =A0 =A0 =A0 =A0 =A0* Note that the base code won't try to unload us until > =A0 =A0 =A0 =A0 =A0* all nodes have been removed, and that can't happen > =A0 =A0 =A0 =A0 =A0* until all Ethernet interfaces are removed. In any > =A0 =A0 =A0 =A0 =A0* case, we know there are no nodes left if the action > =A0 =A0 =A0 =A0 =A0* is MOD_UNLOAD, so there's no need to detach any node= s. > =A0 =A0 =A0 =A0 =A0*/ > > so we can't run this unless you have removeable ethernet interfaces, and > have removed them. > > > Just saw the message. Actually ng_ether can be unloaded but this is left at your own risk and there is a comment in code about this. for each $if in `ifconfig -l` ngctl shutdown $if: kldunload ng_ether This brings the question that should ng_ether be taught about ifnet events(arrival/departure)?! --=20 Ermal