Log in

slitch & netkit - Luke's Weblog [entries|archive|friends|userinfo]
Luke Gorrie

[ website | My Website ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

slitch & netkit [Apr. 13th, 2007|06:40 pm]
Luke Gorrie
[Tags|, ]

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:  Bcast:
         RX bytes:196325 (196.3KiB)  TX bytes:190508 (190.5KiB)>
  lisp1  DOWN  Type:TAP  HWaddr 00:FF:6B:5D:36:60
         Inet addr:  Bcast:
         RX bytes:0 (0 b)  TX bytes:0 (0 b)>
  * (show-tcp-connections)
  * (routes)
  Destination      Gateway          Netmask          Interface  lisp0    lisp0    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.

From: (Anonymous)
2007-04-18 06:24 am (UTC)
He he, you've got a good memory.
Recently I've spent a lot of time with Javascript
(http://tpl.tornkvist.org:8383/) but if I'm not
mistaken, you wrote a Lisp interpreter in Javascript
years ago... :-)

(Reply) (Parent) (Thread)
[User Picture]From: lukego
2007-04-18 06:35 am (UTC)
And it still works! I was showing it off to Patrik Winroth last week :-) http://fresh.homeunix.net/~luke/jscm/repl.html

and in the Luke/Patrik/Tony "that's nothing, on the Atari I used to.." discussions I also found that the first commercial program I ever wrote is still in production use: Araknoid! http://www.eyeone.com/e1gc_no/uk/main/games/araknoid/game_intro.jsp :-)
(Reply) (Parent) (Thread)