From owner-freebsd-net@FreeBSD.ORG Wed Mar 18 03:44:44 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 4B1D7106564A for ; Wed, 18 Mar 2009 03:44:44 +0000 (UTC) (envelope-from ash@aeria.net) Received: from aeria.net (aeria.net [205.134.176.42]) by mx1.freebsd.org (Postfix) with ESMTP id 0B20E8FC17 for ; Wed, 18 Mar 2009 03:44:43 +0000 (UTC) (envelope-from ash@aeria.net) Received: from [IPv6:::1] (aeria.net [205.134.176.42]) by aeria.net (Postfix) with ESMTP id C6B5B47B41 for ; Wed, 18 Mar 2009 03:33:39 +0000 (UTC) Message-Id: <6CBA0923-DAF1-4FD5-A670-F5888BCA47B1@aeria.net> From: Ash Gokhale To: freebsd-net@freebsd.org Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v930.3) Date: Tue, 17 Mar 2009 23:29:40 -0400 X-Mailer: Apple Mail (2.930.3) Subject: 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: Wed, 18 Mar 2009 03:44:44 -0000 I'm developing a kernel module that will be doing inspection and needed access to raw network frames, so I turned to netgraph as the solution.However it seems that netgraph will not permit a module to unload once it's participated in a mkpeer/connect operation. Rebooting to remove a module is angrymaking (not like mtx/sleep crashes). This 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 found? I've observed the trouble in 7.0 release, and tonight's 7_RELENG, with GENERIC + WITNESS/INVARIANTS The module code ( cobbled together from netgraph/ng_sample.c / ng_echo.c) http://pastebin.com/m31b6ece6 The module loads and unloads fine until connected to a netgraph hook: > #make load :ro:~/tmp/ > food.ko:3:06:42:20 > /sbin/kldload -v /root/tmp/food.ko/food.ko > Loaded /root/tmp/food.ko/food.ko, id=3 > #Mar 18 03:06:44 kernel: foodmod loaded :ro:~/tmp/ > food.ko:3:06:44:21 > #make unload :ro:~/tmp/ > food.ko:3:10:16:21 > /sbin/kldunload -v food.ko > Unloading food.ko, id=3 > #Mar 18 03:10:19 kernel: quiesced :ro:~/tmp/ > food.ko:3:10:19:22 > Mar 18 03:10:19 kernel: foodmod unloaded Fine.. so let's connect it: > #make ath :ro:~/tmp/ > food.ko:3:10:59:23 > kldload ng_ether > ifconfig ath0 ssid ')(allmightytallest' > ifconfig ath0 promisc >> > #Mar 18 03:11:04 kernel: ath0: permanently promiscuous mode > enabledo:3:11:04:24 > make connect > #make load :ro:~/tmp/ > food.ko:3:11:13:26 > /sbin/kldload -v /root/tmp/food.ko/food.ko > Loaded /root/tmp/food.ko/food.ko, id=7 > #Mar 18 03:12:05 kernel: foodmod loaded > make connect > ngctl mkpeer ath0: food lower fredhook > ngctl name ath0:lower eater > sleep 1 > Mar 18 03:12:15 kernel: ngconstruct > ifconfig ath0 down > ifconfig ath0 up > #Mar 18 03:12:18 kernel: not our messageunrecognized command/ > food.ko:3:12:16:28 > Mar 18 03:12:18 kernel: ath0: link state changed to UP > # :ro:~/tmp/ > food.ko:3:12:18:28 > #Mar 18 03:12:21 kernel: .... Fine; we get packets to the ng_rx_data procedure .. now we pull the plug on the netgraph > #make discon :ro:~/tmp/ > food.ko:3:12:35:28 > ngctl shutdown eater: > #Mar 18 03:12:37 kernel: discondiconnecting last ng > nodengshutdownko:3:12:36:29 > > #ngctl list :ro:~/tmp/ > food.ko:3:12:39:29 > There are 3 total nodes: > Name: bge0 Type: ether ID: 00000001 Num > hooks: 0 > Name: ngctl1058 Type: socket ID: 00000008 Num > hooks: 0 > Name: ath0 Type: ether ID: 00000002 Num > hooks: 0 > But the module will never unload: ( but the UNLOAD and QUIESE event handlers are invoked) > #make unload :ro:~/tmp/ > food.ko:3:14:28:31 > /sbin/kldunload -vf food.ko > Unloading food.ko, id=7 > kldunload: can't unload file: Device busy > *** Error code 1 > > Stop in /root/tmp/food.ko. > Exit 1 > #Mar 18 03:14:31 kernel: quiesced :ro:~/tmp/ > food.ko:3:14:31:32 > Mar 18 03:14:31 kernel: 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