Skip to contentSkip to conversation

ip(6)tables-save: Allow chain selection

PATCH New Richard Weinberger 2 participants 5 messages Oct 1, 2011 netfilter

lore
Share & tools
lore
#0 lore raw

This patch set adds a switch to iptables-save to select a specific chain to be saved.

Sometimes it's useful to save only one chain.
E.g. When some rules are added dynamically by daemons like OpenVPN or strongSwan and the base rule set is generated by a bash script.

Consider this trivial script:
---8<---
#!/bin/sh

# save only the DYN_OVPN chain
iptables-save -t filter -C DYN_OVPN > /tmp/dyn-rules

iptables -F
iptables -X

iptables -A INPUT -s 1.2.3.4 -j ACCEPT

# much more rules...
iptables -A INPUT ... -j ACCEPT

# OpenVPN can insert here rules which get not lost in case

# the base rule set gets modified and reloaded.
iptables -N DYN_OVPN
iptables -A INPUT -i tun+ -j DYN_OVPN
# restore DYN_OVPN chain
iptables-restore -n < /tmp/dyn-rules
rm -f /tmp/dyn-rules
--->8---

[PATCH 1/2] iptables-save: Allow chain selection [PATCH 2/2] ip6tables-save: Allow chain selection

#1 lore raw

PATCH 1/2 iptables-save: Allow chain selection

This patch allows an user to select the chain he wants to save.

---
 iptables/iptables-save.8 |    4 ++
 iptables/iptables-save.c |   76 ++++++++++++++++++++++++++++-----------------
 2 files changed, 51 insertions(+), 29 deletions(-)
iptables/iptables-save.8 +4 -0
index c2e0a94..f7140d1 100644
@@ -39,6 +39,10 @@ include the current values of all packet and byte counters in the output
 \fB\-t\fR, \fB\-\-table\fR \fItablename\fP
 restrict output to only one table. If not specified, output includes all
 available tables.
+.TP
+\fB\-C\fR, \fB\-\-chain\fR \fIchainname\fP
+restrict output to only one chain. If not specified, output includes all
+available chains.
 .SH BUGS
 None known as of iptables-1.2.1 release
 .SH AUTHOR
iptables/iptables-save.c +47 -29

111 lines not on this page · raw message

Signature · 1 line
1.7.6.4
#2 lore raw

PATCH 2/2 ip6tables-save: Allow chain selection

In reply to Richard Weinberger

This patch allows an user to select the chain he wants to save.

---
 iptables/ip6tables-save.8 |    4 ++
 iptables/ip6tables-save.c |   75 +++++++++++++++++++++++++++-----------------
 2 files changed, 50 insertions(+), 29 deletions(-)
iptables/ip6tables-save.8 +4 -0
index 457be82..420b10d 100644
@@ -39,6 +39,10 @@ include the current values of all packet and byte counters in the output
 \fB\-t\fR, \fB\-\-table\fR \fItablename\fP
 restrict output to only one table. If not specified, output includes all
 available tables.
+.TP
+\fB\-C\fR, \fB\-\-chain\fR \fIchainname\fP
+restrict output to only one chain. If not specified, output includes all
+available chains.
 .SH BUGS
 None known as of iptables-1.2.1 release
 .SH AUTHORS
iptables/ip6tables-save.c +46 -29

110 lines not on this page · raw message

Signature · 1 line
1.7.6.4
#3 lore raw
In reply to Richard Weinberger
Quoted 9 lines · Richard Weinberger

This patch set adds a switch to iptables-save to select a specific chain to be saved.

Sometimes it's useful to save only one chain.
E.g. When some rules are added dynamically by daemons like OpenVPN or strongSwan and the base rule set is generated by a bash script.

iptables-save -t filter -C DYN_OVPN > /tmp/dyn-rules

iptables -S can already select chains and even single rules. We are getting to the point where things are implemented redundantly.. hm.

#4 lore raw

Am 01.10.2011 21:13, schrieb Jan Engelhardt:

Quoted 10 lines · Richard Weinberger
Quoted 9 lines

This patch set adds a switch to iptables-save to select a specific chain to be saved.

Sometimes it's useful to save only one chain.
E.g. When some rules are added dynamically by daemons like OpenVPN or strongSwan and the base rule set is generated by a bash script.

Quoted 4 lines
Quoted 1 line

iptables-save -t filter -C DYN_OVPN > /tmp/dyn-rules

iptables -S can already select chains and even single rules. We are getting to the point where things are implemented redundantly.. hm.

Hmm, good point.
Maybe it's time to drop iptables-save...

Thanks,
//richard