LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 10-19-2010, 02:24 PM   #1
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,681
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
iptables-restore


Anyone know if the iptables-restore command operates atomically? I want to make sure that the entirety of in-kernel iptables are switched over to those specified in the input to iptables-restore, all at once, with no intervening emptiness, incompleteness, or mixing with prior table. The man page doesn't say about this.
 
Old 10-19-2010, 05:31 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by Skaperen View Post
Anyone know if the iptables-restore command operates atomically?
You could test it for your self: build an elaborate list of ingress and egress rules across two tables of choice. Create a shell script that flushes each table, creates each chain and then loads up the the rules. Time script execution. Run 'iptables-save' on the ruleset. (Clean out the firewall and) then time 'iptables-restore'.


Quote:
Originally Posted by Skaperen View Post
I want to make sure that the entirety of in-kernel iptables are switched over to those specified in the input to iptables-restore, all at once, with no intervening emptiness, incompleteness, or mixing with prior table. The man page doesn't say about this.
The only lead you've got on that is in 'man iptables-restore' the "--noflush" switch: "If not specified, iptables-restore flushes (deletes) all previous contents of the respective IP Table." which means it cleans out the previous rule set so no mixing. I can't say anything about your specific requirements of "intervening emptiness, incompleteness". If you're loading large rulesets, dynamically need to change rules and in general need more scalability than iptables can offer you might be "better" off using ipset (http://ipset.netfilter.org/features.html). For a performance comparison see http://people.netfilter.org/kadlec/nftest.pdf.
 
Old 10-20-2010, 01:13 PM   #3
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,681

Original Poster
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
I don't see how the time it takes would tell me if it is atomic. What I want is for there to be no time frame in which a packet would be tested against the iptables in any state other than entirely before I start, or entirely after I finish. For example, when flushing, it if builds up the chain with individual rules one by one, what happens if a packet arrives in the middle of this?

What would give me confidence would be design where the entire iptables state could be pre-constructed in a temporary location, then by merely switching some internal pointer, start using the new one. Then the old one can be purged (free memory in the kernel as applicable).

The legacy way, of running multiple iptables commands from a script, certainly won't do it, since lots of stuff can happen in between those commands. But there's some gimmer of hope that iptables-restore can possibly do this, if the interface into the kernel allows constructing a temporary set of chains as described above, or if the entire state can be passed in a single syscall.

Consider this method of updating a file. You have a few places within the file to change. The changes do not change size or shift anything in position. If done as a few write-in-place operations, something could read the file between these operations and see the file in a "partly updated" state. Alternatively, you can make a copy of the file with changes done while copying, to a temporary file on the same filesystem. Then move the new file into the desired name. Any process with the old file open reads only the old file unmodified (with the only link to the file being its open link). Any process with the new file open reads only the new modified file. Nothing gets any in between state.
 
Old 10-21-2010, 01:14 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by Skaperen View Post
there's some gimmer of hope that iptables-restore can possibly do this, if the interface into the kernel allows constructing a temporary set of chains as described above, or if the entire state can be passed in a single syscall.
It was a rather crude attempt to show that if an operation takes *that* little time to complete it could be concluded it must be (near-)atomic. Maybe instead I should have suggested you read in iptables.restore.c how in main() input is parsed per line and written?.. If iptables-restore works while denying any packet traversing the firewall you could test if you have two asymmetric hosts of which you bombard and try to overload the least capable one while restoring a rule set on it.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Restore iptables Rules that have been saved with iptables-save tiuz Linux - Security 4 08-14-2010 05:50 PM
iptables-restore ubuntu server does not restore at boot R03L Ubuntu 4 02-09-2010 08:14 PM
iptables-restore is not restoring? ApachePadowan Linux - Newbie 1 04-10-2009 10:04 PM
iptables-save, iptables-restore, how to set up them in some script sarajevo Linux - Networking 1 03-24-2008 11:39 PM
Restore iptables file RH AS 5 AQG Linux - Security 4 10-10-2007 01:49 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 09:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration