Bart De Schuymer | 865444d | 2005-06-14 19:17:48 +0000 | [diff] [blame] | 1 | #!/usr/bin/perl -w |
| 2 | # |
| 3 | # |
| 4 | # A script that generates text output of the ebtables rules. |
| 5 | # Similar to iptables-save. |
| 6 | # |
| 7 | # It can be used to store active configuration to /etc/sysconfig/ebtables |
| 8 | |
| 9 | use strict; |
| 10 | my $table; |
| 11 | |
| 12 | # ======================================================== |
| 13 | # Process filter table |
| 14 | # ======================================================== |
| 15 | sub process_table { |
| 16 | my $chain = ""; |
| 17 | my $rules = ""; |
| 18 | my $chains = ""; |
| 19 | my $line = ""; |
| 20 | |
| 21 | foreach $line (split("\n",$_[0])) { |
| 22 | if ($line =~ m/Bridge table: (.*)/) { |
| 23 | print "*$1\n"; |
| 24 | next; |
| 25 | } |
| 26 | if ($line =~ m/Bridge chain: (.*?), entries:.* policy: (.*)/) { |
| 27 | $chains = $chains . ":$1 $2\n"; |
| 28 | $chain = $1; |
| 29 | next; |
| 30 | } |
| 31 | if ($line =~ m/^$/) { |
| 32 | next; |
| 33 | } |
| 34 | $rules = $rules . "-A $chain $line\n"; |
| 35 | } |
| 36 | |
| 37 | print $chains; |
| 38 | print $rules; |
| 39 | print "\n"; |
| 40 | } |
| 41 | # ======================================================== |
| 42 | |
| 43 | unless (-x "/sbin/ebtables") { exit -1 }; |
| 44 | $table =`/sbin/ebtables -t filter -L`; |
| 45 | unless ($? == 0) { print $table; exit -1 }; |
| 46 | &process_table($table); |
| 47 | $table =`/sbin/ebtables -t nat -L`; |
| 48 | unless ($? == 0) { print $table; exit -1 }; |
| 49 | &process_table($table); |
| 50 | $table =`/sbin/ebtables -t broute -L`; |
| 51 | unless ($? == 0) { print $table; exit -1 }; |
| 52 | &process_table($table); |
| 53 | |