diff --git a/New/Shorewall/Hosts.pm b/New/Shorewall/Hosts.pm index 42e859838..ba58bd257 100644 --- a/New/Shorewall/Hosts.pm +++ b/New/Shorewall/Hosts.pm @@ -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; diff --git a/New/Shorewall/Interfaces.pm b/New/Shorewall/Interfaces.pm index 3ffb9747a..8317c0a7d 100644 --- a/New/Shorewall/Interfaces.pm +++ b/New/Shorewall/Interfaces.pm @@ -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; diff --git a/New/compiler.pl b/New/compiler.pl index eae50e9a5..1fbd618ea 100755 --- a/New/compiler.pl +++ b/New/compiler.pl @@ -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];