In a project I happen to need to adjust iptables rules programatically. After some research (involving this and that), I have concluded that it would be suitable to generate a iptables-save compatible output and import it using iptables-restore. Fine so far.
However I would very much like to make use of ipsets, because they greatly simplify the result chains. So at the time of update I need to atomically flush all the iptables & ipset data and put a new set of entries in. How can I do that?
The only solution I can think of is to create new ipsets first (not atomically while they are not being used yet), then atomically flush iptables with references to the old ipsets and then import the new chains with references to the new ipsets. (In one atomic swipe). After that I can non-atomically delete old ipsets as they are no longer referenced and used.
However, such proposed solution seems quite complicated and overheady..
Does anyone know, how this could be done in any better way?