blob: 171a80c0c0d17526e56ae704532a96535629e672 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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};
}
|