From owner-freebsd-net@FreeBSD.ORG Sat Mar 28 20:38:43 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 8C8CA106566B for ; Sat, 28 Mar 2009 20:38:43 +0000 (UTC) (envelope-from ermal.luci@gmail.com) Received: from fg-out-1718.google.com (fg-out-1718.google.com [72.14.220.159]) by mx1.freebsd.org (Postfix) with ESMTP id 129DB8FC17 for ; Sat, 28 Mar 2009 20:38:42 +0000 (UTC) (envelope-from ermal.luci@gmail.com) Received: by fg-out-1718.google.com with SMTP id 13so448841fge.12 for ; Sat, 28 Mar 2009 13:38:42 -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=ZJBBJAdHhDkrjmFJhgD8JZ+f03azz8k9h0bn+wYIZD4=; b=tLBbBuEJNhRB5PLK7iInHLK+++QMnRAutwngZl3gGq9xg4s09pwFu+NrdyUOzix2kY kA8M2ib5pyhWNIHO0XS4KkNdcZoAusrxc2V76jYBJqH2+olN55wMQkpOyn5C41ZZsJFW /A8TqBDDRbynTqg/y6C4DdRViOVBt4BBTp1po= 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=JsQ/RrVmGolf8e95WG7p1O1aAjEen2dwJFChrOxYxovO9Th6SsYIilDuKT72SRPC5y O5fCWAN53xDG5lzmAqWlroEl1Vz9NdD5avFvOrOd7cylQJi38oXDmrqn3RuvqgmXMUMz rYHQooDDhW4D9foOYvjyuZnIFCkA5qAhpzhLQ= MIME-Version: 1.0 Sender: ermal.luci@gmail.com Received: by 10.86.61.13 with SMTP id j13mr1369792fga.48.1238272721994; Sat, 28 Mar 2009 13:38:41 -0700 (PDT) In-Reply-To: <9a542da30903281210v1b4ce5a6w148bb60a8a6bc90c@mail.gmail.com> References: <6CBA0923-DAF1-4FD5-A670-F5888BCA47B1@aeria.net> <49C11E56.7090809@elischer.org> <9a542da30903281210v1b4ce5a6w148bb60a8a6bc90c@mail.gmail.com> Date: Sat, 28 Mar 2009 21:38:41 +0100 X-Google-Sender-Auth: 0d57b23b2ff12404 Message-ID: <9a542da30903281338h269030e3wbc4d5cbcb66d8e59@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 20:38:44 -0000 On Sat, Mar 28, 2009 at 8:10 PM, Ermal Lu=E7i wrote: > On Wed, Mar 18, 2009 at 5:16 PM, Julian Elischer wr= ote: >> Ash Gokhale wrote: >>> >>> =A0I'm developing a kernel module that will be doing inspection and nee= ded >>> access to raw network frames, >>> =A0so I turned to netgraph =A0as the solution.However it seems that net= graph >>> will not permit a module >>> =A0to unload once it's participated in a mkpeer/connect operation. Rebo= oting >>> to remove a module is >>> =A0angrymaking (not like mtx/sleep crashes). >>> >>> =A0 =A0This going into the kernel because my bpf based userland stuff i= s >>> 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 fou= nd? >>> >>> >>> I've observed the trouble in 7.0 release, and tonight's =A07_RELENG, wi= th >>> GENERIC + WITNESS/INVARIANTS >>> >>> The module code =A0( cobbled together from netgraph/ng_sample.c / ng_ec= ho.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 = 1500 >> =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 = 1500 >> =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: 00000= 005 =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: 000= 00006 =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: 00000= 005 =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: 00000= 005 =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.k= o) >> =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 t= oo >> 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 unti= l >> =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 nod= es. >> =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: actually ngctl msg $if: disconnect > kldunload ng_ether > > This brings the question that should ng_ether be taught about ifnet > events(arrival/departure)?! > > -- > Ermal > --=20 Ermal