

Years ago I wrote bits of low-level IP networking code in Common Lisp that never took the shape of a finished program. I don't expect to finish this off so now I'm pushing the unpolished code out in the hope that someone will have fun with it. (An older version of some of this exists on Sourceforge.) slitch and netkit are the two darcs repos. Slitch started out as an ethernet switch in Common Lisp (my therapy after hacking Linux) and later grew some other random bits from my experiments. netkit started as an attempt to rewrite Slitch without the cruft but ended up having different features. The code is written for CMUCL on Linux. I hope it isn't too hard to port. Here are some highlights from Slitch: tuntap.lisp is an FFI interface to Linux tun/tap virtual network interfaces. This is good for communicating with the TCP/IP stack on the host machine.

packet-socket.lisp is an FFI interface to Linux PF_PACKET sockets. This is good to communicate with the ethernet port directly (bypassing the host).

netlib-structures.lisp contains protocol header definitions based on Frode Vatvedt Fjeld's binary-types package.

binary-rw-gen.lisp is a macro-based compiler for binary-types encoders and decoders.

switch.lisp is a working ethernet switch in a page and a half of code.

root.lisp is a library for conveniently switching between normal-user/super-user mode on Linux.

tcpip.lisp is a partial TCP/IP stack that can answer pings, send ICMP, talk to telnet, etc. Lacks important features like TCP retransmission. Here's a "screenshot" of Slitch: * (netstat) lisp0 UP Type:TAP HWaddr 00:FF:C5:50:B6:E4 Inet addr:192.168.43.10/255.255.255.0 Bcast:192.168.43.255 RX bytes:196325 (196.3KiB) TX bytes:190508 (190.5KiB)> lisp1 DOWN Type:TAP HWaddr 00:FF:6B:5D:36:60 Inet addr:0.0.0.0/0.0.0.0 Bcast:0.0.0.0 RX bytes:0 (0 b) TX bytes:0 (0 b)> * (show-tcp-connections) TCP Stream 192.168.43.10:80 / 192.168.43.1:33398: ESTABLISHED TCP Stream 192.168.43.10:80 / 192.168.43.1:33400: ESTABLISHED * (routes) Destination Gateway Netmask Interface 192.168.128.43 0.0.0.0 255.255.255.255 lisp0 192.168.43.0 0.0.0.0 255.255.255.0 lisp0 192.168.128.0 192.168.43.1 255.255.255.0 lisp0 And here's some stuff in netkit: packet.lisp is a stand-alone encoder and decoder for TCP/IP protocol headers. This time I wrote it in straight Lisp without binary-types. It's a semi-literate pbook program that you can print from packet.pdf to read on the bus.

pcap.lisp is a decoder for the capture files produced by tcpdump.

clim.lisp is a CLIM interface for manipulating pcap files. (This file seems to have syntax errors, I hope they're simple.) The image above is a screenshot. This was all following on from related work in Erlang with Martin Björklund and Tony Rogvall, some of which exists in the Jungerl. These days I've switched to hacking this stuff in Squeak. I was reminded of this code by ILC conversations: some with the Dylan Hackers who've written something more polished in Dylan and some others about memory management. My own interest in memory management comes from writing Slitch with complete disregard for efficiency and then out of curiosity checking out its throughput and latency characteristics. There I discovered the large constant factors of CMUCL's garbage collector (scavenging static space and zeroing oldspace) and began to ponder what it all means.