forked from extern/shorewall_code
Optimize wildcard resolution.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
This commit is contained in:
parent
ebbf381e27
commit
7061997324
@ -164,6 +164,7 @@ our %reservedName = ( all => 1,
|
|||||||
#
|
#
|
||||||
our @interfaces;
|
our @interfaces;
|
||||||
our %interfaces;
|
our %interfaces;
|
||||||
|
our %roots;
|
||||||
our @bport_zones;
|
our @bport_zones;
|
||||||
our %ipsets;
|
our %ipsets;
|
||||||
our %physical;
|
our %physical;
|
||||||
@ -221,6 +222,7 @@ sub initialize( $ ) {
|
|||||||
$have_ipsec = undef;
|
$have_ipsec = undef;
|
||||||
|
|
||||||
@interfaces = ();
|
@interfaces = ();
|
||||||
|
%roots = ();
|
||||||
%interfaces = ();
|
%interfaces = ();
|
||||||
@bport_zones = ();
|
@bport_zones = ();
|
||||||
%ipsets = ();
|
%ipsets = ();
|
||||||
@ -907,6 +909,7 @@ sub process_interface( $$ ) {
|
|||||||
if ( $interface =~ /\+$/ ) {
|
if ( $interface =~ /\+$/ ) {
|
||||||
$wildcard = 1;
|
$wildcard = 1;
|
||||||
$root = substr( $interface, 0, -1 );
|
$root = substr( $interface, 0, -1 );
|
||||||
|
$roots{$root} = $interface;
|
||||||
} else {
|
} else {
|
||||||
$root = $interface;
|
$root = $interface;
|
||||||
}
|
}
|
||||||
@ -1184,25 +1187,30 @@ sub map_physical( $$ ) {
|
|||||||
#
|
#
|
||||||
# Returns true if passed interface matches an entry in /etc/shorewall/interfaces
|
# Returns true if passed interface matches an entry in /etc/shorewall/interfaces
|
||||||
#
|
#
|
||||||
# If the passed name matches a wildcard and 'cache' is true, an entry for the name is added in
|
# If the passed name matches a wildcard, an entry for the name is added to %interfaces.
|
||||||
# %interfaces.
|
|
||||||
#
|
#
|
||||||
sub known_interface($)
|
sub known_interface($)
|
||||||
{
|
{
|
||||||
my ( $interface, $cache ) = @_;
|
my $interface = shift;
|
||||||
my $interfaceref = $interfaces{$interface};
|
my $interfaceref = $interfaces{$interface};
|
||||||
|
|
||||||
return $interfaceref if $interfaceref;
|
return $interfaceref if $interfaceref;
|
||||||
|
|
||||||
fatal_error "Invalid interface ($interface)" if $interface =~ /\*/;
|
fatal_error "Invalid interface ($interface)" if $interface =~ /\*/;
|
||||||
|
|
||||||
for my $i ( @interfaces ) {
|
my $iface = $interface;
|
||||||
$interfaceref = $interfaces{$i};
|
|
||||||
my $root = $interfaceref->{root};
|
while ( 1 ) {
|
||||||
if ( $i ne $root && $interface ne $root && substr( $interface, 0, length $root ) eq $root ) {
|
chop $iface;
|
||||||
|
|
||||||
|
return 0 if $iface eq '';
|
||||||
|
|
||||||
|
if ( my $i = $roots{$iface} ) {
|
||||||
|
$interfaceref = $interfaces{$i};
|
||||||
|
|
||||||
my $physical = map_physical( $interface, $interfaceref );
|
my $physical = map_physical( $interface, $interfaceref );
|
||||||
|
|
||||||
return $interfaces{$interface} = { options => $interfaceref->{options},
|
return $interfaces{$interface} = { options => $interfaceref->{options} ,
|
||||||
bridge => $interfaceref->{bridge} ,
|
bridge => $interfaceref->{bridge} ,
|
||||||
name => $i ,
|
name => $i ,
|
||||||
number => $interfaceref->{number} ,
|
number => $interfaceref->{number} ,
|
||||||
|
Loading…
Reference in New Issue
Block a user