A netgraph question.

Joe Pellegrino jdp at elvis.rowan.edu
Sun Nov 2 14:38:05 PST 2008

On Sat, 1 Nov 2008, Julian Elischer wrote:

> Joe Pellegrino wrote:
>> On Sat, 1 Nov 2008, Julian Elischer wrote:
> have you done man 3 netgraph to look at the netgraph management library?

Looked at that today and I might be able to get something going. I tried 
to use the ng_echo node in a module. The code looked something like this:
#include <sys/param.h>
#include <sys/module.h>
#include <sys/kernel.h>
#include <sys/systm.h>
#include <sys/mbuf.h>

#include <netgraph/ng_message.h>
#include <netgraph/netgraph.h>
#include <netgraph/ng_echo.h>

extern struct ng_type typestruct;

static int event_handler(struct module *module, int event, void *arg) {
         int e = 0; /* Error, 0 for normal return status */
         switch (event) {
         case MOD_LOAD:
                 uprintf("Hello Free Software Magazine Readers! \n");
         case MOD_UNLOAD:
                 uprintf("Bye Bye FSM reader, be sure to check 
emagazine.com !\n");
                 e = EOPNOTSUPP; /* Error, Operation Not Supported */


/* The second argument of DECLARE_MODULE. */
static moduledata_t hello_conf = {
     "hello_fsm",    /* module name */
      event_handler,  /* event handler */
      NULL            /* extra data */


However, trying to load this module results in:

# kldload ./hello_fsm.ko
kldload: can't load ./hello_fsm.ko: No such file or directory

So to start, how can I use ng_echo in a module? According to the man 4 of 
netgraph the ng_newtype should construct a new node right? And I presume 
once I get that module running and an ng_echo module loaded, I'll try to 
communicate with it from userspace but what about the above is incorrect? 
Thanks. :)


> 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")

More information about the freebsd-net mailing list