[Dnsmasq-discuss] Dnsmasq goes trendy - git and Lua
Simon Kelley
simon at thekelleys.org.uk
Sat Jan 7 15:08:47 GMT 2012
In an positive orgy of displacement activity designed to keep me away
from hacking DHCPv6 I've done a couple of significant bits of work on
dnsmasq.
The first is a git repository for the codebase. Dnsmasq has
traditionally been developed with the benefit of any SCM, but even I
have started to see the advantages as I've been juggling DHCPv6 code
around day-to-day maintenance.
The public repo resides on thekelleys.org.uk and contains every release
of dnsmasq version 2, the first of which was in 2004. It also contains
commits for ongoing work, starting with a dump of everything done up to
2.60test6 and then the last couple of days work as fine-grained commits.
I plan to keep working this way, making tagged x.ytestz releases as
required which are automatically made available as tarballs in the usual
place. (This has been first-class displacement activity, hacking
git-hooks and everything!).
The repo is browseable using gitweb at
http://www.thekelleys.org.uk/gitweb/?p=dnsmasq.git;a=summary
and available by the git protocol:
git clone git://thekelleys.org.uk/dnsmasq.git
will get you your very own copy.
Second, J P Mens and I have added Lua scripting (as an
alternative/addition to the dhcp-script shell script).
This adds very little code to dnsmasq, (but it does link the Lua
interpreter as a library, obviously), and it looks to me like a
significantly better programming environment for doing complex stuff. A
Lua function is invoked for each lease-change in the same way (and with
the same available parameters) as the shell script. The interpreter is
persistent between calls, so static variables retain their values, and
there are optional init and finalise function called when dnsmasq starts
and shuts down, to take advantage of this.
There's no documentation yet, but the switch to give dnsmasq a file
containing lua is
--dhcp-luascript=<luascript>
and the test luascript I've been using is
---------------------------------------------------------------------
counter = 0
file = nil
function init()
file = assert(io.open("/tmp/lua-leases", "a"))
print("starting...")
end
function shutdown()
file:close()
print("ending.....")
end
function lease(action , lease_desc)
counter = counter + 1
local line = "Lua: " .. action .. " " .. counter
for k,v in pairs(lease_desc) do line = line .. "\n" .. k .. " " .. v end
file:write(line .. "\n")
print(line)
end
------------------------------------------------------------------------
which gives the important information needed to get started.
At the moment there's no Lua equivalent of the shell-script's ability to
feed the lease database into dnsmasq at startup, so a Lua script can't
be used to replace the lease file in the way that a shell script can.
I'm not sure of removing that limitation of easily possible.
I'm no Lua programmer, but this looks to me like a facility worth
having. I'm interested in others' opinions.
get Lua-enabled code at
http://thekelleys.org.uk/dnsmasq/test-releases/dnsmasq-2.60test7.tar.gz
(or from git!) and build it with
make COPTS=-DHAVE_LUASCRIPT
All feedback gratefully received.
Cheers,
Simon.
More information about the Dnsmasq-discuss
mailing list