I need to query existing rules, as well as being able to easily add and delete rules. I haven't found any APIs for doing this, is there something that I'm missing?
The closest I've come to a solution is using iptables-save | iptables-xml
for querying, and manually calling the iptables command itself to add/delete rules. Another solution I've considered is simply regenerating the entire ruleset out of my application's database and flushing the whole chain, then applying it again - I want to avoid this as I don't want to drop any packets (unless there's a way to atomically do this?). I'm wondering if there's a better way.
An API in C would be great, however as I'm planning to build this into a stand-alone suid program, libraries that do this in ANY language are fine too.