Persisting conntrack table to MySQL on OpenWRT

I needed a way to persist the conntrack table on an OpenWRT based router, so I made this quick & dirty script.

This uses the included library to get the conntrack table and LuaSQL (MySQL in this instance) to persist.

The table structure has primary keys on nearly all the fields, except namely packets and bytes. If a duplicate key is detected on INSERT, it’ll update those 2 fields instead.

Figured I’d put this on Gist in case anyone else needed it.
Never made anything in Lua before, so I’m sure there are better ways to do certain things.

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>