File: arptables-save

package info (click to toggle)
arptables 0.0.4+snapshot20181021-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 352 kB
  • sloc: ansic: 4,453; perl: 81; makefile: 64; sh: 29
file content (50 lines) | stat: -rw-r--r-- 1,252 bytes parent folder | download
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
#!/usr/bin/perl -w
#
#
# A script that generates text output of the arptables rules.
# Similar to iptables-save.

use strict;
my $table;
my $tool = "__EXEC_PATH__/arptables";

# ========================================================
# Process filter table
# ========================================================
sub process_table {
    my $chain = "";
    my $rules = "";
    my $chains = "";
    my $custom_chains = "";
    my $line = "";

    foreach $line (split("\n",$_[0])) {
        if ($line =~ m/Chain\s(.*?)\s\(policy\s(.*?)\)/) {
            $chains = $chains . ":$1 $2\n";
            $chain = $1;
            next;
        }
        if ($line =~ m/Chain\s(.*?)\s\(/) {
            $custom_chains = $custom_chains . ":$1 -\n";
            $chain = $1;
            next;
        }
        if ($line =~ m/^$/) {
            next;
        }
        $rules = $rules . "-A $chain $line\n";
    }

    print "*filter\n";
    print $chains;
    print $custom_chains;
    print $rules;
    print "\n";
}
# ========================================================

unless (-x "$tool") { print "ERROR: Tool $tool isn't executable"; exit -1; };
$table =`$tool -t filter -L -n`;
unless ($? == 0) { print $table; exit -1 };
&process_table($table);