summaryrefslogtreecommitdiffstats
path: root/userspace/ebtables2/ebtables-restore
diff options
context:
space:
mode:
authorBart De Schuymer <bdschuym@pandora.be>2005-06-14 19:17:48 +0000
committerBart De Schuymer <bdschuym@pandora.be>2005-06-14 19:17:48 +0000
commit2aae5c00bc261150e7d3583ecd2447e7934daccc (patch)
tree81a3836016cc9f59ce9b1b1b51e2c55272c1982d /userspace/ebtables2/ebtables-restore
parent90f4fca5a26014cf0b86837b673e5dceb0c71ebe (diff)
Rok Papez <rok.papez_at_ames.si>
Diffstat (limited to 'userspace/ebtables2/ebtables-restore')
-rw-r--r--userspace/ebtables2/ebtables-restore62
1 files changed, 62 insertions, 0 deletions
diff --git a/userspace/ebtables2/ebtables-restore b/userspace/ebtables2/ebtables-restore
new file mode 100644
index 0000000..171a80c
--- /dev/null
+++ b/userspace/ebtables2/ebtables-restore
@@ -0,0 +1,62 @@
+#!/usr/bin/perl -w
+#
+#
+# A script that imports text ebtables rules. Similar to iptables-restore.
+# It can be used to restore configuration from /etc/sysconfig/ebtables.
+#
+
+use strict;
+my $ebtables = "/sbin/ebtables";
+my $table;
+my $rc;
+my $line;
+
+# ==============================
+# Check table
+# Creates user chains.
+# ==============================
+sub check_chain {
+ if ($table eq "filter") {
+ if ($_[1] eq "INPUT") { return; }
+ if ($_[1] eq "FORWARD") { return; }
+ if ($_[1] eq "OUTPUT") { return; }
+ }
+ if ($table eq "nat") {
+ if ($_[1] eq "PREROUTING") { return; }
+ if ($_[1] eq "POSTROUTING") { return; }
+ if ($_[1] eq "OUTPUT") { return; }
+ }
+ if ($table eq "broute") {
+ if ($_[1] eq "BROUTING") { return; }
+ }
+ $rc = `$ebtables -t $_[0] -N $_[1]`;
+ unless($? == 0) {print "ERROR: $rc\n"; exit -1};
+}
+# ==============================
+
+unless (-x $ebtables) { print "ERROR: $ebtables isn't executable\n"; exit -1; };
+$rc = `$ebtables -t filter --init-table`;
+unless($? == 0) { print "ERROR: $rc\n"; exit -1 };
+$rc = `$ebtables -t nat --init-table`;
+unless($? == 0) { print "ERROR: $rc\n"; exit -1 };
+$rc = `$ebtables -t broute --init-table`;
+unless($? == 0) { print "ERROR: $rc\n"; exit -1 };
+
+$line = 0;
+while(<>) {
+ $line++;
+ if(m/^#/) { next; };
+ if(m/^$/) { next; };
+ if(m/^\*(.*)/) {
+ $table = $1;
+ next;
+ }
+ if(m/^\:(.*?)\s(.*)/) {
+ &check_chain($table,$1);
+ $rc = `$ebtables -t $table -P $1 $2`;
+ unless($? == 0) {print "ERROR(line $line): $rc\n"; exit -1};
+ next;
+ }
+ $rc = `$ebtables -t $table $_`;
+ unless($? == 0) {print "ERROR(line $line): $rc\n"; exit -1};
+}