After another hiatus, I've almost finished reading through the
Linux 1.0 kernel. Building on last time, I've now read everything but
tcp.[ch], which is probably a good time to take a break as tcp.c is
pretty near 4000 lines on its own, and the longest source file in the
tree.
- Network-related headers from include/linux. There appear to
be a bunch of structs that are borrowed from elsewhere, and never
referred to. It's clear the stack is under development, in a slightly
magpie-like way.
- arp.[ch] Pleasantly straightforward. It did take me a while
to realise "arp_q" is not a queue of ARP requests, but a queue
of packets that can't be sent until the ARP responses are in! I read
most of the way through the file before realising that the handling of
cache clearing is done by timers when sockets get closed, so that
logic is actually distributed else where.
- ip.[ch] So much to nit-pick! Lots of special values all
over the place (usually 0) to mean "not filled in" or "not
applicable". I'm loving languages with explicit Option types, but at
least give a named constant for this kind of thing! "ip_send" is
poorly named, filling in the MAC header but not sending. "ip_find" has
an unused "qplast" variable - it was clearly copied from some
list-mutating code. "ip_free"'s call to del_timer with the interrupts
on looks like a great race. The file has a horrific mix of tabs and
spaces. The IP fragment-collectiong code is very willing to run the
kernel out of memory, and is not programmed defensively. Generally,
though, it's easy-to-follow code. It's weird to see that there's
retransmit-handling code at the IP layer, despite this being a TCP
feature.
- raw.[ch] And then we're back into the world of using
complicated, overloaded structs. Due to the way that raw IP sockets
work, each socket opened dynamically inserts a new protocol into the
IP stack, in order to intercept all the packets that arrive. Pretty
heavy!
- icmp.[ch] Pleasantly readable and straightforward!
- udp.[ch] Slightly less readable than the ICMP code, but
still pretty unexciting.
Posted 2019-03-03.