Date: Sat, 28 Mar 2009 20:10:35 +0100 From: =?ISO-8859-1?Q?Ermal_Lu=E7i?= <eri@freebsd.org> To: Julian Elischer <julian@elischer.org> Cc: freebsd-net@freebsd.org, Ash Gokhale <ash@aeria.net> Subject: Re: netgraph modules won't unload after use Message-ID: <9a542da30903281210v1b4ce5a6w148bb60a8a6bc90c@mail.gmail.com> In-Reply-To: <49C11E56.7090809@elischer.org> References: <6CBA0923-DAF1-4FD5-A670-F5888BCA47B1@aeria.net> <49C11E56.7090809@elischer.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Mar 18, 2009 at 5:16 PM, Julian Elischer <julian@elischer.org> 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<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1= 500 > =A0 =A0 =A0 =A0options=3D9b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HW= CSUM> > =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 <full-duplex>) > =A0 =A0 =A0 =A0status: active > bge1: flags=3D8802<BROADCAST,SIMPLEX,MULTICAST> metric 0 mtu 1500 > =A0 =A0 =A0 =A0options=3D9b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HW= CSUM> > =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<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1= 500 > =A0 =A0 =A0 =A0options=3Db<RXCSUM,TXCSUM,VLAN_MTU> > =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 <full-duplex>) > =A0 =A0 =A0 =A0status: active > lo0: flags=3D8049<UP,LOOPBACK,RUNNING,MULTICAST> 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: <unnamed> =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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?9a542da30903281210v1b4ce5a6w148bb60a8a6bc90c>