From owner-freebsd-net@FreeBSD.ORG Sun Nov 2 02:14:33 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 1A4301065670 for ; Sun, 2 Nov 2008 02:14:33 +0000 (UTC) (envelope-from prvs=julian=185d67ddd@elischer.org) Received: from smtp-outbound.ironport.com (smtp-outbound.ironport.com [63.251.108.112]) by mx1.freebsd.org (Postfix) with ESMTP id F20AE8FC0A for ; Sun, 2 Nov 2008 02:14:32 +0000 (UTC) (envelope-from prvs=julian=185d67ddd@elischer.org) Received: from unknown (HELO julian-mac.elischer.org) ([10.251.60.58]) by smtp-outbound.ironport.com with ESMTP; 01 Nov 2008 19:14:21 -0700 Message-ID: <490D0CFB.5040102@elischer.org> Date: Sat, 01 Nov 2008 19:14:19 -0700 From: Julian Elischer User-Agent: Thunderbird 2.0.0.17 (Macintosh/20080914) MIME-Version: 1.0 To: Joe Pellegrino References: <490CEF11.4010007@elischer.org> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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 02:14:33 -0000 Joe Pellegrino wrote: > 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? have you done man 3 netgraph to look at the netgraph management library? for example programs, see: /usr/src/usr.sbin/nghook /usr/src/usr.sbin/ngctl /usr/ports/net/mpd (you'll need to download the sources with "make") > >>> 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