1 | 1 | simandl | #!/usr/bin/env perl |
2 | | | use warnings; |
3 | | | use diagnostics; |
4 | | | |
5 | | | use lib "../../lib"; |
6 | | | use HotSaNICparser; |
7 | | | |
8 | | | # read global settings |
9 | | | # |
10 | | | $MODNAME=HotSaNICparser::get_module_name(); |
11 | | | |
12 | | | # read module-specific settings |
13 | | | # |
14 | | | |
15 | | | foreach (HotSaNICparser::read_settings(".")) { |
16 | | | ($var,$value)=HotSaNICparser::parse_line($_); |
17 | | | if ($var eq "INTIF") { $INTIF=$value; } |
18 | | | if ($var eq "IPTABLES") { $IPTABLES=$value; } |
19 | | | if ($var eq "EXTIF") { $EXTIF=$value; } |
20 | | | if ($var eq "DEVEXT") { |
21 | | | ($dev,$maxin,$maxout,$descr)=split(/,/,$value); |
22 | | | push @WORLDDEST,$dev; |
23 | | | } |
24 | | | if ($var eq "DEVINT") { |
25 | | | ($dev,$maxin,$maxout,$descr)=split(/,/,$value); |
26 | | | push @LOCALDEST,$dev; |
27 | | | } |
28 | | | } |
29 | | | |
30 | | | if ( ! defined $IPTABLES) { die time," ",$MODNAME,": IPTABLES not configured in module settings...\n"; } |
31 | | | |
32 | 5 | simandl | print "\nclearing old and setting up new accounting chains\n"; |
33 | 6 | simandl | foreach $prt ("tcp","udp","other") { |
34 | 5 | simandl | system("$IPTABLES -F acct_ext_$prt > /dev/null"); |
35 | | | system("$IPTABLES -X acct_ext_$prt > /dev/null"); |
36 | | | system("$IPTABLES -F acct_int_$prt > /dev/null "); |
37 | | | system("$IPTABLES -X acct_int_$prt > /dev/null"); |
38 | | | system("$IPTABLES -N acct_ext_$prt > /dev/null"); |
39 | | | system("$IPTABLES -N acct_int_$prt > /dev/null"); |
40 | 1 | simandl | } |
41 | | | |
42 | | | # |
43 | | | # set up Accounting for unique IPs in subnet... |
44 | | | # |
45 | | | |
46 | | | print "\naccounting for local targets\n"; |
47 | | | |
48 | | | foreach $host (@LOCALDEST) { |
49 | | | print " ",$host,"\n"; |
50 | 6 | simandl | foreach $prt ("tcp","udp") { |
51 | 5 | simandl | system("$IPTABLES -A acct_int_$prt -s $host"); |
52 | | | system("$IPTABLES -A acct_int_$prt -d $host"); |
53 | 1 | simandl | } |
54 | 6 | simandl | system("$IPTABLES -A acct_int_other -s $host"); |
55 | | | system("$IPTABLES -A acct_int_other -d $host"); |
56 | 1 | simandl | } |
57 | 6 | simandl | #this will kick out all tcp and udp from other accounting chain |
58 | | | system("$IPTABLES -I acct_int_other -p tcp -j RETURN"); |
59 | | | system("$IPTABLES -I acct_int_other -p udp -j RETURN"); |
60 | 1 | simandl | |
61 | | | # |
62 | 5 | simandl | # set up accounting for dedicated networks to local subnet |
63 | 1 | simandl | # |
64 | | | |
65 | | | print "\naccounting for externel targets\n"; |
66 | | | |
67 | | | foreach $host (@WORLDDEST) { |
68 | | | print " ",$host,"\n"; |
69 | 6 | simandl | foreach $prt ("tcp","udp") { |
70 | 5 | simandl | system("$IPTABLES -A acct_ext_$prt -s $host"); |
71 | | | system("$IPTABLES -A acct_ext_$prt -d $host"); |
72 | 1 | simandl | } |
73 | 6 | simandl | system("$IPTABLES -A acct_ext_other -s $host"); |
74 | | | system("$IPTABLES -A acct_ext_other -d $host"); |
75 | 1 | simandl | } |
76 | 6 | simandl | #this will kick out all tcp and udp from other accounting chain |
77 | | | system("$IPTABLES -I acct_ext_other -p tcp -j RETURN"); |
78 | | | system("$IPTABLES -I acct_ext_other -p udp -j RETURN"); |
79 | 1 | simandl | |
80 | | | print "\nlinking accounting chains to INPUT/OUTPUT chain\n"; |
81 | | | foreach $dev (split(/,/,$EXTIF)) { |
82 | | | if ($IPTABLES =~ /ipchains/) { |
83 | | | system("$IPTABLES -I input -i $dev -j acct_ext > /dev/null"); |
84 | | | system("$IPTABLES -I output -i $dev -j acct_ext > /dev/null"); |
85 | | | } |
86 | | | else { |
87 | 6 | simandl | #this will sent ALL to other chain |
88 | | | system("$IPTABLES -I INPUT -i $dev -p all -j acct_ext_other > /dev/null"); |
89 | | | system("$IPTABLES -I OUTPUT -o $dev -p all -j acct_ext_other > /dev/null"); |
90 | | | system("$IPTABLES -I FORWARD -i $dev -p all -j acct_ext_other > /dev/null"); |
91 | | | system("$IPTABLES -I FORWARD -o $dev -p all -j acct_ext_other > /dev/null"); |
92 | | | foreach $prt ("tcp","udp") { |
93 | 5 | simandl | system("$IPTABLES -I INPUT -i $dev -p $prt -j acct_ext_$prt > /dev/null"); |
94 | | | system("$IPTABLES -I OUTPUT -o $dev -p $prt -j acct_ext_$prt > /dev/null"); |
95 | | | system("$IPTABLES -I FORWARD -i $dev -p $prt -j acct_ext_$prt > /dev/null"); |
96 | | | system("$IPTABLES -I FORWARD -o $dev -p $prt -j acct_ext_$prt > /dev/null"); |
97 | | | } |
98 | 1 | simandl | } |
99 | | | } |
100 | 5 | simandl | |
101 | 1 | simandl | foreach $dev (split(/,/,$INTIF)) { |
102 | | | if ($IPTABLES =~ /ipchains/) { |
103 | | | system("$IPTABLES -I input -i $dev -j acct_int > /dev/null"); |
104 | | | system("$IPTABLES -I output -i $dev -j acct_int > /dev/null"); |
105 | | | } |
106 | | | else { |
107 | 6 | simandl | #this will sent ALL to other chain |
108 | | | system("$IPTABLES -I INPUT -i $dev -p all -j acct_int_other > /dev/null"); |
109 | | | system("$IPTABLES -I OUTPUT -o $dev -p all -j acct_int_other > /dev/null"); |
110 | | | system("$IPTABLES -I FORWARD -i $dev -p all -j acct_int_other > /dev/null"); |
111 | | | system("$IPTABLES -I FORWARD -o $dev -p all -j acct_int_other > /dev/null"); |
112 | | | foreach $prt ("tcp","udp") { |
113 | 5 | simandl | system("$IPTABLES -I INPUT -i $dev -p $prt -j acct_int_$prt > /dev/null"); |
114 | | | system("$IPTABLES -I OUTPUT -o $dev -p $prt -j acct_int_$prt > /dev/null"); |
115 | | | system("$IPTABLES -I FORWARD -i $dev -p $prt -j acct_int_$prt > /dev/null"); |
116 | | | system("$IPTABLES -I FORWARD -o $dev -p $prt -j acct_int_$prt > /dev/null"); |
117 | | | } |
118 | 1 | simandl | } |
119 | | | } |
120 | | | print "\n\nAll done! - accounting should be running now!\n"; |
121 | | | |