summaryrefslogtreecommitdiffstats
path: root/ebtables-restore
diff options
context:
space:
mode:
Diffstat (limited to 'ebtables-restore')
-rw-r--r--ebtables-restore53
1 files changed, 28 insertions, 25 deletions
diff --git a/ebtables-restore b/ebtables-restore
index 171a80c..abe049d 100644
--- a/ebtables-restore
+++ b/ebtables-restore
@@ -6,8 +6,8 @@
#
use strict;
-my $ebtables = "/sbin/ebtables";
-my $table;
+my $ebtables = "__EXEC_PATH__/ebtables";
+my $table = "";
my $rc;
my $line;
@@ -16,43 +16,42 @@ my $line;
# 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};
+ 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/^\*(.*)/) {
+ if (defined($ENV{'EBTABLES_SAVE_COUNTER'}) && !($ENV{'EBTABLES_SAVE_COUNTER'} eq "yes") && !($table eq "") ) {
+ $rc = `$ebtables -t $table -Z`;
+ unless($? == 0) {print "ERROR: $rc\n"; exit -1};
+ }
$table = $1;
+ $rc = `$ebtables -t filter --init-table`;
+ unless($? == 0) {print "ERROR: $rc\n"; exit -1};
next;
}
if(m/^\:(.*?)\s(.*)/) {
- &check_chain($table,$1);
+ &check_chain($table,$1);
$rc = `$ebtables -t $table -P $1 $2`;
unless($? == 0) {print "ERROR(line $line): $rc\n"; exit -1};
next;
@@ -60,3 +59,7 @@ while(<>) {
$rc = `$ebtables -t $table $_`;
unless($? == 0) {print "ERROR(line $line): $rc\n"; exit -1};
}
+if (defined($ENV{'EBTABLES_SAVE_COUNTER'}) && !($ENV{'EBTABLES_SAVE_COUNTER'} eq "yes") && !($table eq "")) {
+ $rc = `$ebtables -t $table -Z`;
+ unless($? == 0) {print "ERROR: '-t $table -Z' failed\n"; exit -1};
+}