Not my area of expertise (yet) but I think most the network stack stuff is in the kernel. Download the
kernel sources and look in the net directory. You can find directories for ipv4, mac80211, netfilter, and all kinds of other stuff. You will have to recompile and reinstall your kernel (or modules) to see your changes.
Kernel programming is no walk in the park though. You have to be very good with C and learn a lot about the kernel structures and memory locking techniques and so forth. I've got a book I'm going through right now, Essential Linux Device Drivers from Prentice Hall, which is very detailed.