Correct PPTP server firewall rules chain.
[tomato/davidwu.git] / release / src / router / ebtables / ebtables-save
blob49d733b7adf5e083bdabcf51a92f670358105fda
1 #!/usr/bin/perl -w
4 # A script that generates text output of the ebtables rules.
5 # Similar to iptables-save.
7 # It can be used to store active configuration to /etc/sysconfig/ebtables
9 use strict;
10 my $table;
11 my $ebtables = "__EXEC_PATH__/ebtables";
12 my $cnt = "";
13 my $version = "1.0";
14 my $table_name;
16 # ========================================================
17 # Process filter table
18 # ========================================================
19 sub process_table {
20 my $chain = "";
21 my $rules = "";
22 my $chains = "";
23 my $line = "";
25 foreach $line (split("\n",$_[0])) {
26 if ($line =~ m/Bridge table: (.*)/) {
27 print "*$1\n";
28 next;
30 if ($line =~ m/Bridge chain: (.*?), entries:.* policy: (.*)/) {
31 $chains = $chains . ":$1 $2\n";
32 $chain = $1;
33 next;
35 if ($line =~ m/^$/) {
36 next;
38 if ($cnt eq "--Lc") {
39 $line =~ s/, pcnt = (.*) -- bcnt = (.*)/-c $1 $2/;
40 } else {
41 $line =~ s/ $//;
43 $rules = $rules . "-A $chain $line\n";
46 print $chains;
47 print $rules;
48 print "\n";
50 # ========================================================
52 unless (-x $ebtables) { exit -1 };
53 print "# Generated by ebtables-save v$version on " . `date`;
54 if (defined($ENV{'EBTABLES_SAVE_COUNTER'}) && $ENV{'EBTABLES_SAVE_COUNTER'} eq "yes") {
55 $cnt = "--Lc";
57 foreach $table_name (split("\n", `grep -E '^ebtable_' /proc/modules | cut -f1 -d' ' | sed s/ebtable_//`)) {
58 $table =`$ebtables -t $table_name -L $cnt`;
59 unless ($? == 0) { print $table; exit -1 };
60 &process_table($table);