Welcome, gentle reader.
This document is a journey; some parts are well-travelled, and in other areas you will find yourself almost alone. The best advice I can give you is to grab a large, cozy mug of coffee or hot chocolate, get into a comfortable chair, and absorb the contents before venturing out into the sometimes dangerous world of networking.
netfilter is a framework for packet mangling, outside the normal Berkeley socket interface. It has five parts. Firstly, each protocol defines "hooks" (IPv4 defines 6) which are well-defined points in a packet's traversal of that protocol stack. At each of these points, the protocol will call the netfilter framework with the packet and the hook number.
Secondly, parts of the kernel can register to listen to the different hooks for each protocol. So when a packet is passed to the netfilter framework, it checks to see if anyone has registered for that protocol and hook; if so, they each get a chance to examine (and possibly alter) the packet in order, and discard the packet, allow it to pass, or ask netfilter to queue the packet for userspace.
The third part is that packets which have been queued for userspace are collected (usually by the netfilter_dev driver) for sending to userspace; these packets are handled asynchronously.
The fourth part is that any packet dropped once inside the IP layer can be examined before it is actually dropped. For example, this allows modules to examine IP-spoofed packets (dropped by the routing code).
The final part consists of cool comments in the code and documentation. This is instrumental for any experimental project. The netfilter motto is (stolen shamelessly from Cort Dougan):
``So... how is this better than KDE?''
In addition to this raw framework, various modules have been written which provide functionality similar to previous (pre-netfilter) kernels, in particular, an extensible NAT system, and an extensible packet filtering system (iptables).
Interactions between packet filtering and masquerading make firewalling complex:
I'm the only one foolish enough to do this. As ipchains co-author and current Linux Kernel IP Firewall maintainer, I see many of the problems that people have with the current system, as well as getting exposure to what they are trying to do.
Woah! You should have seen it last week!
Because I'm not as great a programmer as we might all wish, and I certainly haven't tested all scenarios, because of lack of time, equipment and/or inspiration. I have two Intel laptops connected by PLIP and a NetWinder connected to one laptop via 10baseT. (Cort, are you listening? Where's my PowerPC box?)