Date: Sat, 01 Nov 2008 19:14:19 -0700 From: Julian Elischer <julian@elischer.org> To: Joe Pellegrino <jdp@elvis.rowan.edu> Cc: freebsd-net@freebsd.org Subject: Re: A netgraph question. Message-ID: <490D0CFB.5040102@elischer.org> In-Reply-To: <Pine.GSO.4.64.0811012107200.7887@elvis.rowan.edu> References: <Pine.GSO.4.64.0811011759200.4676@elvis.rowan.edu> <490CEF11.4010007@elischer.org> <Pine.GSO.4.64.0811012107200.7887@elvis.rowan.edu>
next in thread | previous in thread | raw e-mail | index | archive | help
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 <netgraph/ng_socket.h> > > 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?490D0CFB.5040102>