summaryrefslogtreecommitdiffstats
path: root/iptables/xshared.h
diff options
context:
space:
mode:
authorLorenzo Colitti <lorenzo@google.com>2017-05-19 16:08:59 +0900
committerPablo Neira Ayuso <pablo@netfilter.org>2017-05-29 13:42:20 +0200
commit80d8bfaac9e2430d710084a10ec78e68bd61e6ec (patch)
treecc15d1b7b3a68774db0335003a1f639d2e72fcae /iptables/xshared.h
parentc29d99c83d95ca063fd378bd0b7f798eb66163fb (diff)
iptables: insist that the lock is held.
Currently, iptables programs will exit with an error if the iptables lock cannot be acquired, but will silently continue if the lock cannot be opened at all. This can cause unexpected failures (with unhelpful error messages) in the presence of concurrent updates, which can be very difficult to find in a complex or multi-administrator system. Instead, refuse to do anything if the lock cannot be acquired. The behaviour is not affected by command-line flags because: 1. In order to reliably avoid concurrent modification, all invocations of iptables commands must follow this behaviour. 2. Whether or not the lock can be opened is typically not a run-time condition but is likely to be a configuration error. Existing systems that depended on things working mostly correctly even if there was no lock might be affected by this change. However, that is arguably a configuration error, and now that the iptables lock is configurable, it is trivial to provide a lock file that is always accessible: if nothing else, the iptables binary itself can be used. The lock does not have to be writable, only readable. Tested by configuring the system to use an xtables.lock file in a non-existent directory and observing that all commands failed. Signed-off-by: Lorenzo Colitti <lorenzo@google.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'iptables/xshared.h')
-rw-r--r--iptables/xshared.h7
1 files changed, 3 insertions, 4 deletions
diff --git a/iptables/xshared.h b/iptables/xshared.h
index 539e6c24..7e6d0859 100644
--- a/iptables/xshared.h
+++ b/iptables/xshared.h
@@ -92,8 +92,7 @@ extern void xs_init_match(struct xtables_match *);
*
* A value >= 0 indicates the lock filedescriptor. Other values are:
*
- * XT_LOCK_UNSUPPORTED : The system does not support locking, execution will
- * proceed lockless.
+ * XT_LOCK_FAILED : The lock could not be acquired.
*
* XT_LOCK_BUSY : The lock was held by another process. xtables_lock only
* returns this value when |wait| == false. If |wait| == true, xtables_lock
@@ -103,11 +102,11 @@ extern void xs_init_match(struct xtables_match *);
*/
enum {
XT_LOCK_BUSY = -1,
- XT_LOCK_UNSUPPORTED = -2,
+ XT_LOCK_FAILED = -2,
XT_LOCK_NOT_ACQUIRED = -3,
};
-extern int xtables_lock(int wait, struct timeval *tv);
extern void xtables_unlock(int lock);
+extern int xtables_lock_or_exit(int wait, struct timeval *tv);
int parse_wait_time(int argc, char *argv[]);
void parse_wait_interval(int argc, char *argv[], struct timeval *wait_interval);