From owner-freebsd-net@FreeBSD.ORG Wed Aug 30 12:31:13 2006 Return-Path: X-Original-To: freebsd-net@freebsd.org Delivered-To: freebsd-net@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D94E616A4DE for ; Wed, 30 Aug 2006 12:31:13 +0000 (UTC) (envelope-from rajkumars@gmail.com) Received: from nz-out-0102.google.com (nz-out-0102.google.com [64.233.162.201]) by mx1.FreeBSD.org (Postfix) with ESMTP id 64C5D43D5E for ; Wed, 30 Aug 2006 12:31:11 +0000 (GMT) (envelope-from rajkumars@gmail.com) Received: by nz-out-0102.google.com with SMTP id 13so94252nzn for ; Wed, 30 Aug 2006 05:31:10 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=c3EtpJKfug+k07kpshWZGujr0QH8Ra8ODw+sFotGP68m0FN4FVsBS2e06SmnUx77UdhuW2UE/H3Ve1hl73A3REdNMDKwC2FBfdwlMTC83MfaQX7HhyS8qP4AbcTEJ6ifebBlx1aMAR7aKtqIijbhBDm2w9xhZOc0nL83A7hh/PA= Received: by 10.64.184.14 with SMTP id h14mr546750qbf; Wed, 30 Aug 2006 05:31:10 -0700 (PDT) Received: by 10.65.248.1 with HTTP; Wed, 30 Aug 2006 05:31:10 -0700 (PDT) Message-ID: <64de5c8b0608300531y7ab06ea5ibde5c96aaaa6374e@mail.gmail.com> Date: Wed, 30 Aug 2006 18:01:10 +0530 From: "Rajkumar S" To: freebsd-net@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Subject: sending NGM_BPF_SET_PROGRAM message to a bpf node from a program 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, 30 Aug 2006 12:31:13 -0000 Hi, I am trying to write a program to create a bpf node and assign a bpf filter to that node. I am able to create the node and attch the node to 3 other nodes, but not settng up a bpf filter to the node. I am initialising the ng_bpf_hookprog struct using the following code: struct ng_bpf_hookprog *bpf_hookprog; bpf_hookprog = calloc (1, sizeof (struct ng_bpf_hookprog) + fp.bf_len * sizeof (struct bpf_insn)); bpf_hookprog->bpf_prog_len = fp.bf_len; printf ("fp.bf_len is %d\n", fp.bf_len); insn = fp.bf_insns; for (k=0; k < fp.bf_len; ++k,++insn){ memcpy ((bpf_hookprog->bpf_prog + k), insn, sizeof(insn)); printf ("code=%d\n", bpf_hookprog->bpf_prog[k].code); } strlcpy (bpf_hookprog->thisHook, "from_lower", sizeof (bpf_hookprog->thisHook)); strlcpy (bpf_hookprog->ifNotMatch, "discard", sizeof (bpf_hookprog->ifNotMatch)); strlcpy (bpf_hookprog->ifMatch, "to_upper", sizeof (bpf_hookprog->ifMatch)); and messaging the bpf: using the following code fragment. if (NgSendMsg(cfd, "bpf:", NGM_GENERIC_COOKIE, NGM_BPF_SET_PROGRAM, bpf_hookprog, (sizeof (struct ng_bpf_hookprog) + fp.bf_len * sizeof (struct bpf_insn))) < 0) { perror ("Setup bpf program"); return (-1); } The full souce is available at http://pastebin.ca/154537 While running the code, just before sending the setprogram message, the ngctl list shows: + list There are 6 total nodes: Name: sink Type: hole ID: 00000082 Num hooks: 1 Name: bpf Type: bpf ID: 00000081 Num hooks: 3 Name: test_socket Type: socket ID: 00000080 Num hooks: 0 Name: ngctl5868 Type: socket ID: 0000003f Num hooks: 0 Name: vr0 Type: ether ID: 00000002 Num hooks: 0 Name: rl0 Type: ether ID: 00000001 Num hooks: 2 but once the setprogram message has been sent, it becomes: + list There are 4 total nodes: Name: test_socket Type: socket ID: 00000080 Num hooks: 0 Name: ngctl5868 Type: socket ID: 0000003f Num hooks: 0 Name: vr0 Type: ether ID: 00000002 Num hooks: 0 Name: rl0 Type: ether ID: 00000001 Num hooks: 0 Since the argument for setprogram involves flexible array, I have tried my best to make sure that there are no issues with the argument passing, but even in that case zapping the already running bpf node is bit strange, or is this a case of me being stupid? with warm regards, raj