From owner-freebsd-ipfw@FreeBSD.ORG Mon Apr 21 15:35:29 2014 Return-Path: Delivered-To: freebsd-ipfw@freebsd.org Received: from mx2.freebsd.org (mx2.freebsd.org [IPv6:2001:1900:2254:206a::19:2]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 4976439F for ; Mon, 21 Apr 2014 15:35:29 +0000 (UTC) Received: from butcher-nb.yandex.net (hub.freebsd.org [IPv6:2001:1900:2254:206c::16:88]) by mx2.freebsd.org (Postfix) with ESMTP id 933CF1DDF; Mon, 21 Apr 2014 15:35:28 +0000 (UTC) Message-ID: <53553A74.4000405@FreeBSD.org> Date: Mon, 21 Apr 2014 19:34:12 +0400 From: "Andrey V. Elsukov" User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 MIME-Version: 1.0 To: bycn82 Subject: Re: how does it pass in the rule sets References: <5352298C.2090902@gmail.com> <53552C83.7060008@FreeBSD.org> <535535C7.1050707@gmail.com> In-Reply-To: <535535C7.1050707@gmail.com> X-Enigmail-Version: 1.6 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: freebsd-ipfw@freebsd.org X-BeenThere: freebsd-ipfw@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: IPFW Technical Discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Apr 2014 15:35:29 -0000 On 21.04.2014 19:14, bycn82 wrote: > On 4/21/14 22:34, Andrey V. Elsukov wrote: >> On 19.04.2014 11:45, bycn82 wrote: >>> Hi, >>> can someone help to explain how does the user land command `ipfw` pass >>> the rule set into the hook function in the kernel? I assume that it must >>> be hardcoded in somewhere, but I did not find it yet. >> ipfw(8) uses raw socket and setsockopt(2)/getsockopt(2) functions to >> interact with kernel. In particular, do_cmd() function from ipfw2.c does it. >> > Thanks very much, > Actually I saw the source already, the ipfw_ctl() method. I would like > to call it as "an event handler" > But why it will triggered? where are the code to register this method > as listener? > Sorry for using Java terminologies ;) You need to improve your grep-fu :) When you load ipfw.ko kernel module, vnet_ipfw_init() initializes V_ip_fw_ctl_ptr = ipfw_ctl. When you call setsockopt() for raw socket, it invokes ctloutput method for RAW IP - rip_ctloutput() (netinet/raw_ip.c). It calls ipfw_ctl() via V_ip_fw_ctl_ptr pointer. -- WBR, Andrey V. Elsukov