blob: 171a80c0c0d17526e56ae704532a96535629e672 [file] [log] [blame]
Bart De Schuymer865444d2005-06-14 19:17:48 +00001#!/usr/bin/perl -w
2#
3#
4# A script that imports text ebtables rules. Similar to iptables-restore.
5# It can be used to restore configuration from /etc/sysconfig/ebtables.
6#
7
8use strict;
9my $ebtables = "/sbin/ebtables";
10my $table;
11my $rc;
12my $line;
13
14# ==============================
15# Check table
16# Creates user chains.
17# ==============================
18sub check_chain {
19 if ($table eq "filter") {
20 if ($_[1] eq "INPUT") { return; }
21 if ($_[1] eq "FORWARD") { return; }
22 if ($_[1] eq "OUTPUT") { return; }
23 }
24 if ($table eq "nat") {
25 if ($_[1] eq "PREROUTING") { return; }
26 if ($_[1] eq "POSTROUTING") { return; }
27 if ($_[1] eq "OUTPUT") { return; }
28 }
29 if ($table eq "broute") {
30 if ($_[1] eq "BROUTING") { return; }
31 }
32 $rc = `$ebtables -t $_[0] -N $_[1]`;
33 unless($? == 0) {print "ERROR: $rc\n"; exit -1};
34}
35# ==============================
36
37unless (-x $ebtables) { print "ERROR: $ebtables isn't executable\n"; exit -1; };
38$rc = `$ebtables -t filter --init-table`;
39unless($? == 0) { print "ERROR: $rc\n"; exit -1 };
40$rc = `$ebtables -t nat --init-table`;
41unless($? == 0) { print "ERROR: $rc\n"; exit -1 };
42$rc = `$ebtables -t broute --init-table`;
43unless($? == 0) { print "ERROR: $rc\n"; exit -1 };
44
45$line = 0;
46while(<>) {
47 $line++;
48 if(m/^#/) { next; };
49 if(m/^$/) { next; };
50 if(m/^\*(.*)/) {
51 $table = $1;
52 next;
53 }
54 if(m/^\:(.*?)\s(.*)/) {
55 &check_chain($table,$1);
56 $rc = `$ebtables -t $table -P $1 $2`;
57 unless($? == 0) {print "ERROR(line $line): $rc\n"; exit -1};
58 next;
59 }
60 $rc = `$ebtables -t $table $_`;
61 unless($? == 0) {print "ERROR(line $line): $rc\n"; exit -1};
62}