netgraph hook for iface node

Khoa To takhoa at rice.edu
Thu Jun 5 16:05:27 PDT 2003


Hello,

I need to implement a routing protocol on top of IP (i.e. the packet is
encapsulated within an IP packet).  I'm new to network programming, and from
searching the web, it looks like netgraph can help me a lot.  But I have
some problems with applying netgraph to my implementation, and I am
wondering if someone can help me or give me some pointers.  (I would like to
implement the code in user space as much as possible)

I think I should use an iface node if I want to get an IP packet.  I tried
and successfully get IP packets printed out on the console when I:
- Configure the iface node with the command "ifconfig ng0 1.1.1.1 2.2.2.2"
- Used "nghook -a ng0: inet" to connect to the inet hook from the user space
- Ping 2.2.2.2

But how do I connect this iface node to the regular ethernet interface so
that I can capture IP packets coming from the wire to my regular ethernet
card?  I can get raw ethernet packets by hooking to the "lower" hook of
eth0, but I want the Ethernet codes to do the parsing for me and give me a
clean IP packet.  I tried to connect the upper hook of eth0 to the inet hook
(it probably the wrong way to do it anyway), but I couldn't because I
already connected the inet hook to my user level program via nghook.

Also, on the way down (i.e. from the application layer), after I assemble my
protocol-specific packet, is there a hook in netgraph that I can pass the
packet to that would do all the IP encapsulation and generate checksums,
etc. and send it down to the network interface for transmission?  (Or what
type of node that I should create that would allow me to do that?)

I really appreciate any hints/help that you guys can provide.

Thank you very much,
Khoa.



More information about the freebsd-net mailing list