From owner-freebsd-net@FreeBSD.ORG Sun Nov 2 01:21:27 2008 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 1A365106568D for ; Sun, 2 Nov 2008 01:21:27 +0000 (UTC) (envelope-from jdp@elvis.rowan.edu) Received: from elvis.rowan.edu (elvis.rowan.edu [150.250.64.69]) by mx1.freebsd.org (Postfix) with ESMTP id B85748FC16 for ; Sun, 2 Nov 2008 01:21:26 +0000 (UTC) (envelope-from jdp@elvis.rowan.edu) Received: from elvis.rowan.edu (localhost [127.0.0.1]) by elvis.rowan.edu (8.13.8+Sun/8.13.8) with ESMTP id mA21LPjL016473; Sat, 1 Nov 2008 21:21:25 -0400 (EDT) Received: from localhost (jdp@localhost) by elvis.rowan.edu (8.13.8+Sun/8.13.8/Submit) with ESMTP id mA21LOfF016469; Sat, 1 Nov 2008 21:21:24 -0400 (EDT) Date: Sat, 1 Nov 2008 21:21:23 -0400 (EDT) From: Joe Pellegrino To: Julian Elischer In-Reply-To: <490CEF11.4010007@elischer.org> Message-ID: References: <490CEF11.4010007@elischer.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: freebsd-net@freebsd.org Subject: Re: A netgraph question. 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: Sun, 02 Nov 2008 01:21:27 -0000 On Sat, 1 Nov 2008, Julian Elischer wrote: > I'll try answer your questions.. > > Hooks are created on demand.. > you need to send a 'connect' or 'mkpeer' message to the node(s) > on which you want t script level, you just use the ngctl program > to do it for you. > > Hooks are always made in pairs. so you need two nodes to connect. > The mkpeer message does this for you, and creates a new node and connects > them together by two hooks of the names you specify. > > Have you looked at the sample netgraph scripts in > /usr/share/examples/netgraph? > Yep, I've looked at those but if I recall they are all scripts. I am looking for some C or C++ example. Basically on the userland side I have something like: #include <..> #include int main () { int s1 = socket (PF_NETGRAPH, SOCK_DGRAM, NG_CONTROL) int s2 = socket (PF_NETGRAPH, SOCK_DGRAM, NG_DATA) bind(...); } This gives me a node with a name, set with bind, of type socket and no hooks. The kernel module I don't have any netgraph code yet but I figure it will involve a set of calls similar to the userland program. So if I want to interact with the socket the userland program created, what kind of node do I create in the module? Another ng_socket or a ng_ksocket or something different. Then how do I go about connecting the two hooks? >> Of course I realize that I proabably need to create a node on the kernel >> side so which type of netgraph node would be suggested? How is it created >> and then hooked to the ng_socket? > > for fun you could use the ng_echo node type which would send everything you > want back to you.. > > Alternatively when you kldload the ng-ether node type, then all the ethernets > will grow nodes to match them so you can connect to them directly. > > You could connect an ng_bpf (packet filter) node to the ng_ether node > and pass specific packets only on to the socket. > I'll look into this for the other half of what I am playing with. I looked at bpf by itself and it seemed to me it made a copy of the packet, with the original continuing up the stack rather than diverting the packet. But I am getting ahead of myself. I'd like to get the userland <-> module part together first. :) And all the example code are scripts. Am I missing someting? >> pages and can't seem to find a lot of good documentation or example code so >> I am hoping to get some pointers here. BTW If this is the wrong list please >> directly to the right place to ask. Thanks in advance. > > not sure what netlink does.. > (will look on google :-) > Thanks for your help, there is a reasonable entry in the wiki about it. ---jdp