Debian Codegraph @

arptables-save

raw
1 #!/usr/bin/perl -w
2 #
3 #
4 # A script that generates text output of the arptables rules.
5 # Similar to iptables-save.
6
7 use strict;
8 my $table;
9 my $tool = "__EXEC_PATH__/arptables";
10
11 # ========================================================
12 # Process filter table
13 # ========================================================
14 sub process_table {
15 my $chain = "";
16 my $rules = "";
17 my $chains = "";
18 my $custom_chains = "";
19 my $line = "";
20
21 foreach $line (split("\n",$_[0])) {
22 if ($line =~ m/Chain\s(.*?)\s\(policy\s(.*?)\)/) {
23 $chains = $chains . ":$1 $2\n";
24 $chain = $1;
25 next;
26 }
27 if ($line =~ m/Chain\s(.*?)\s\(/) {
28 $custom_chains = $custom_chains . ":$1 -\n";
29 $chain = $1;
30 next;
31 }
32 if ($line =~ m/^$/) {
33 next;
34 }
35 $rules = $rules . "-A $chain $line\n";
36 }
37
38 print "*filter\n";
39 print $chains;
40 print $custom_chains;
41 print $rules;
42 print "\n";
43 }
44 # ========================================================
45
46 unless (-x "$tool") { print "ERROR: Tool $tool isn't executable"; exit -1; };
47 $table =`$tool -t filter -L -n`;
48 unless ($? == 0) { print $table; exit -1 };
49 &process_table($table);
50