A high level language for low level code

Fosdem 2013

Justin Cormack

A high level language for low level code

Origins

When I started using Linux many years ago I soon started poking around to find out how it worked.

I started with /etc/inittab and worked on from there.

You could start to understand it as much was shell scripts.

Requirements

I was also using Linux containers to isolate processes

The assumption was that you would run a whole Linux distro for each container

Was there a simpler way?

Dumb idea!

Why not just build the stuff you need to boot Linux into a scripting language, and then write simple scripts to boot your system or VM?

After all how much do you need to build to run a simple application with some networking?

How much work could it be?

Building it

LuaJIT

LuaJIT is being used for other low level projects eg Snabb Switch

Structure

Example system calls

local s = S.socket("inet", "stream, nonblock")
s:setsockopt("socket", "reuseaddr", true)
local sa = S.t.sockaddr_in(8000, "127.0.0.1")
s:bind(sa)
s:listen(128)
local ep = S.epoll_create()
ep:epoll_ctl("add", s, "in")

Example netlink

nl.create_interface {name = "dummy0", type = "dummy"}
local i = nl.interfaces()
i.dummy0:up()
i.dummy0:setmac("46:9d:c9:06:dd:dd")
i.dummy0:address("10.10.10.1/24")
i.dummy0:down()
i.dummy0:delete()

Difficulties

Comprehensive test suite helped a lot in finding errors. Tests every system call and interface.

What is it good for?

Prototyping

Network programs

Learning about Linux

Simple Linux containers and systems

Roadmap

Roadmap

You could port to another language, only Go seems to have a good interface.

A high level language for low level code

Justin Cormack

LuaJIT: luajit.org

Fork me on Github