Move a couple more functions to modules

git-svn-id: https://shorewall.svn.sourceforge.net/svnroot/shorewall/trunk@5531 fbd18981-670d-0410-9b5c-8dc0c1a9a2bb
This commit is contained in:
teastep 2007-03-15 00:42:37 +00:00
parent 119587d501
commit 721008f156
3 changed files with 58 additions and 55 deletions

View File

@ -8,7 +8,7 @@ use Shorewall::Interfaces;
use strict;
our @ISA = qw(Exporter);
our @EXPORT = qw( validate_hosts_file );
our @EXPORT = qw( validate_hosts_file find_hosts_by_option );
our @EXPORT_OK = ();
our @VERSION = 1.00;
@ -85,3 +85,36 @@ sub validate_hosts_file()
close HOSTS;
}
#
# Returns a reference to a array of host entries. Each entry is a
# reference to an array containing ( interface , group type {ipsec|none} , network );
#
sub find_hosts_by_option( $ ) {
my $option = $_[0];
my @hosts;
for my $zone ( grep $zones{$_}{type} ne 'firewall' , @zones ) {
while ( my ($type, $interfaceref) = each %{$zones{$zone}{hosts}} ) {
while ( my ( $interface, $arrayref) = ( each %{$interfaceref} ) ) {
for my $host ( @{$arrayref} ) {
if ( $host->{$option} ) {
for my $net ( @{$host->{hosts}} ) {
push @hosts, [ $interface, $type eq 'ipsec4' ? 'ipsec' : 'none' , $net ];
}
}
}
}
}
}
for my $interface ( @interfaces ) {
my $optionsref = $interfaces{$interface}{options};
if ( $optionsref && $optionsref->{$option} ) {
push @hosts, [ $interface, 'none', ALLIPv4 ];
}
}
\@hosts;
}
1;

View File

@ -7,7 +7,13 @@ use Shorewall::Zones;
use strict;
our @ISA = qw(Exporter);
our @EXPORT = qw( add_group_to_zone validate_interfaces_file dump_interface_info known_interface @interfaces );
our @EXPORT = qw( add_group_to_zone
validate_interfaces_file
dump_interface_info
known_interface
find_interfaces_by_option
@interfaces );
our @EXPORT_OK = ();
our @VERSION = 1.00;
@ -242,4 +248,21 @@ sub known_interface($)
0;
}
#
# Returns reference to array of interfaces with the passed option
#
sub find_interfaces_by_option( $ ) {
my $option = $_[0];
my @ints = ();
for my $interface ( @interfaces ) {
my $optionsref = $interfaces{$interface}{options};
if ( $optionsref && $optionsref->{$option} ) {
push @ints , $interface;
}
}
\@ints;
}
1;

View File

@ -1,8 +1,6 @@
#! /usr/bin/perl -w
use strict;
use File::Basename;
use File::Temp qw/ tempfile tempdir /;
use lib "$ENV{HOME}/shorewall/trunk/New";
use Shorewall::Common;
use Shorewall::Config;
@ -13,8 +11,6 @@ use Shorewall::Hosts;
my ( $command, $doing, $done ) = qw/ compile Compiling Compiled/; #describe the current command, it's present progressive, and it's completion.
my $tempfile = ''; # Temporary object file name
#
# Set to one if we find a SECTION
#
@ -805,55 +801,6 @@ sub add_rule_pair( $$$$ ) {
add_rule $chainref , "${predicate}-j $target";
}
#
# Returns reference to array of interfaces with the passed option
#
sub find_interfaces_by_option( $ ) {
my $option = $_[0];
my @ints = ();
for my $interface ( @interfaces ) {
my $optionsref = $interfaces{$interface}{options};
if ( $optionsref && $optionsref->{$option} ) {
push @ints , $interface;
}
}
\@ints;
}
#
# Returns a reference to a array of host entries. Each entry is a
# reference to an array containing ( interface , group type {ipsec|none} , network );
#
sub find_hosts_by_option( $ ) {
my $option = $_[0];
my @hosts;
for my $zone ( grep $zones{$_}{type} ne 'firewall' , @zones ) {
while ( my ($type, $interfaceref) = each %{$zones{$zone}{hosts}} ) {
while ( my ( $interface, $arrayref) = ( each %{$interfaceref} ) ) {
for my $host ( @{$arrayref} ) {
if ( $host->{$option} ) {
for my $net ( @{$host->{hosts}} ) {
push @hosts, [ $interface, $type eq 'ipsec4' ? 'ipsec' : 'none' , $net ];
}
}
}
}
}
}
for my $interface ( @interfaces ) {
my $optionsref = $interfaces{$interface}{options};
if ( $optionsref && $optionsref->{$option} ) {
push @hosts, [ $interface, 'none', ALLIPv4 ];
}
}
\@hosts;
}
sub setup_rfc1918_filteration( $ ) {
my $listref = $_[0];