diff options
author | Phil Oester <kernel@linuxace.com> | 2013-05-31 09:07:04 -0400 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2013-06-11 12:54:30 +0200 |
commit | 93587a04d0f2511e108bbc4d87a8b9d28a5c5dd8 (patch) | |
tree | dcaf19625096fac37cddcc80a0ff1aff673c2579 /iptables/xshared.h | |
parent | 34844da8f53ec80b34ad094f2fca2519a7079ec2 (diff) | |
download | platform_external_iptables-93587a04d0f2511e108bbc4d87a8b9d28a5c5dd8.tar.gz platform_external_iptables-93587a04d0f2511e108bbc4d87a8b9d28a5c5dd8.tar.bz2 platform_external_iptables-93587a04d0f2511e108bbc4d87a8b9d28a5c5dd8.zip |
ip[6]tables: Add locking to prevent concurrent instances
There have been numerous complaints and bug reports over the years when admins
attempt to run more than one instance of iptables simultaneously. Currently
open bug reports which are related:
325: Parallel execution of the iptables is impossible
758: Retry iptables command on transient failure
764: Doing -Z twice in parallel breaks counters
822: iptables shows negative or other bad packet/byte counts
As Patrick notes in 325: "Since this has been a problem people keep running
into, I'd suggest to simply add some locking to iptables to catch the most
common case."
I started looking into alternatives to add locking, and of course the most
common/obvious solution is to use a pidfile. But this has various downsides,
such as if the application is terminated abnormally and the pidfile isn't
cleaned up. And this also requires a writable filesystem. Using a UNIX domain
socket file (e.g. in /var/run) has similar issues.
Starting in 2.2, Linux added support for abstract sockets. These sockets
require no filesystem, and automatically disappear once the application
terminates. This is the locking solution I chose to implement in ip[6]tables.
As an added bonus, since each network namespace has its own socket pool, an
ip[6]tables instance running in one namespace will not lock out an ip[6]tables
instance running in another namespace. A filesystem approach would have
to recognize and handle multiple network namespaces.
Signed-off-by: Phil Oester <kernel@linuxace.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'iptables/xshared.h')
-rw-r--r-- | iptables/xshared.h | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/iptables/xshared.h b/iptables/xshared.h index b804aafe..1e2b9b8e 100644 --- a/iptables/xshared.h +++ b/iptables/xshared.h @@ -2,6 +2,7 @@ #define IPTABLES_XSHARED_H 1 #include <limits.h> +#include <stdbool.h> #include <stdint.h> #include <netinet/in.h> #include <net/if.h> @@ -83,6 +84,7 @@ extern struct xtables_match *load_proto(struct iptables_command_state *); extern int subcmd_main(int, char **, const struct subcommand *); extern void xs_init_target(struct xtables_target *); extern void xs_init_match(struct xtables_match *); +extern bool xtables_lock(bool wait); extern const struct xtables_afinfo *afinfo; |