Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 16 Mar 2000 17:22:14 -0800
From:      Tom Pavel <pavel@NetworkPhysics.COM>
To:        freebsd-net@FreeBSD.ORG
Subject:   Netgraph weirdness
Message-ID:  <200003170122.RAA16225@gto.networkphysics.com>

next in thread | raw e-mail | index | archive | help

I've been experimenting with netgraph in 3.4 (and 3.4-STABLE) and have
run into some weird aspects related to KLD modules.  I've managed to
learn the workaround, but I think there is still an important problem
lurking here.

My test case is to do the simple example:
    nghook -a de3: divert

Since I want netgraph nodes for my ethernet interfaces, this requires
that I compile my kernel with the NETGRAPH option.  Figuring that any
other netgraph modules could be loaded dynamically, I did not include
any of the other NETGRAPH_xxx options in my kernel.

I discovered that when I do a:
    ngctl list
the 2 KLD modules ng_socket.ko and netgraph.ko get loaded
automagically.  Here is where my troubles start.  

It turns out that the netgraph.ko is a 2nd copy of the code from
/sys/netgraph/ng_base.c.  When the KLD module gets loaded, it calls
register_netisr() with the ngintr() routine from the KLD module (which
overwrites the previous ngintr() from the base kernel).  However, when
the ethernet interfaces call ether_input() and ngether_send(), the
packets get queued onto the ngqbase queue from the base kernel.
Needless to say, this does not work right...

So, it turns out that the fix is to compile in the NETGRAPH_SOCKET
option into the kernel.  But then, why have NETGRAPH_SOCKET as a
separable option if the system won't work without it compiled together
with the base netgraph code?  And when I go to write my own netgraph
node and kldload it in, will I return to the same situation with the
module unwittingly loading in netgraph.ko? 

Perhaps there is just a simple mistake preventing ng_socket.ko from
knowing that the equivalent code of netgraph.ko is statically linked
into the kernel.  I confess that I don't understand the KLD
infrastructure too well.  I see that ng_base.c has a

    DECLARE_MODULE(netgraph, netgraph_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
	      
declaration, which seems like it ought to be the right thing.  I have
seen that this declaration is sufficient to get the ngb_mod_event()
routine in the statically-linked ng_base.c code called at boot time
(this is how the ngintr() routine gets registered int netisrs for the
statically linked code).

Any wisdom out there?  I've traced through this code quite a bit over
the last couple days.  I'd like to turn up the actual bug and get it
fixed, but I don't know where to dig that last bit...


Tom Pavel

Network Physics
pavel@networkphysics.com / pavel@alum.mit.edu 


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-net" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200003170122.RAA16225>