From 9869420106927a2466b250f8126d98bd1912d85e Mon Sep 17 00:00:00 2001 From: Tom Eastep Date: Sun, 3 Jun 2012 08:43:48 -0700 Subject: [PATCH 1/3] Check for conditional directives prior to continuation Signed-off-by: Tom Eastep --- Shorewall/Perl/Shorewall/Config.pm | 42 +++++++++++++++++------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/Shorewall/Perl/Shorewall/Config.pm b/Shorewall/Perl/Shorewall/Config.pm index b0bf81323..8e5e68b7c 100644 --- a/Shorewall/Perl/Shorewall/Config.pm +++ b/Shorewall/Perl/Shorewall/Config.pm @@ -1652,8 +1652,14 @@ sub have_capability( $ ); sub process_conditional( $$$ ) { my ( $omitting, $line, $linenumber ) = @_; + # + # Save/set $currentlinenumber so that fatal_error will report correct line number + # + my $save_currentlinenumber = $currentlinenumber; - print "CD===> $currentline\n" if $debug; + $currentlinenumber = $linenumber; + + print "CD===> $line\n" if $debug; fatal_error "Invalid compiler directive ($line)" unless $line =~ /^\s*\?(IF\s+|ELSE|ENDIF)(.*)$/; @@ -1705,6 +1711,10 @@ sub process_conditional( $$$ ) { $omitting = $prioromit; pop @ifstack; } + # + # Restore $currentlinenumber + # + $currentlinenumber = $save_currentlinenumber; $omitting; } @@ -2264,10 +2274,21 @@ sub read_a_line($) { $currentlinenumber = 0; while ( <$currentfile> ) { + chomp; + # + # Handle conditionals + # + if ( /^\s*\?(?:IF|ELSE|ENDIF)/ ) { + $omitting = process_conditional( $omitting, $_, $. ); + next; + } + + if ( $omitting ) { + print "OMIT=> $_\n" if $debug; + next; + } $currentlinenumber = $. unless $currentlinenumber; - - chomp; # # Suppress leading whitespace in certain continuation lines # @@ -2282,21 +2303,6 @@ sub read_a_line($) { # chop $currentline, next if ($currentline .= $_) =~ /\\$/; # - # Handle conditionals - # - if ( $currentline =~ /^\s*\?(?:IF|ELSE|ENDIF)/ ) { - $omitting = process_conditional( $omitting, $currentline, $currentlinenumber ); - $currentline=''; - next; - } - - if ( $omitting ) { - print "OMIT=> $currentline\n" if $debug; - $currentline=''; - $currentlinenumber = 0; - next; - } - # # Must check for shell/perl before doing variable expansion # if ( $options & EMBEDDED_ENABLED ) { From 69387b9099977f123ce09ef1baa26627fcd3d629 Mon Sep 17 00:00:00 2001 From: Tom Eastep Date: Sun, 3 Jun 2012 15:15:11 -0700 Subject: [PATCH 2/3] Make 'check -r' work like 'compile' WRT optimization Signed-off-by: Tom Eastep --- Shorewall/Perl/Shorewall/Chains.pm | 2 ++ Shorewall/Perl/Shorewall/Compiler.pm | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Shorewall/Perl/Shorewall/Chains.pm b/Shorewall/Perl/Shorewall/Chains.pm index a4aab8ebe..c7f70b150 100644 --- a/Shorewall/Perl/Shorewall/Chains.pm +++ b/Shorewall/Perl/Shorewall/Chains.pm @@ -112,6 +112,7 @@ our %EXPORT_TAGS = ( ALL_COMMANDS NOT_RESTORE OPTIMIZE_POLICY_MASK + OPTIMIZE_POLICY_MASK1 OPTIMIZE_RULESET_MASK OPTIMIZE_MASK @@ -368,6 +369,7 @@ use constant { ALL_COMMANDS => 1, NOT_RESTORE => 2 }; # use constant { OPTIMIZE_POLICY_MASK => 0x02 , # Call optimize_policy_chains() + OPTIMIZE_POLICY_MASK1 => 0x06 , OPTIMIZE_RULESET_MASK => 0x1C , # Call optimize_ruleset() }; diff --git a/Shorewall/Perl/Shorewall/Compiler.pm b/Shorewall/Perl/Shorewall/Compiler.pm index 47cc71648..7c9ea2cd2 100644 --- a/Shorewall/Perl/Shorewall/Compiler.pm +++ b/Shorewall/Perl/Shorewall/Compiler.pm @@ -817,11 +817,11 @@ sub compiler { # # Optimize Policy Chains # - optimize_policy_chains if $optimize & 6 == 2; # Level 2 but not 4 + optimize_policy_chains if ( $optimize & OPTIMIZE_POLICY_MASK1 ) == OPTIMIZE_POLICY_MASK; # Level 2 but not 4 # # More Optimization # - optimize_ruleset if $config{OPTIMIZE} & 0x1C; + optimize_ruleset if $config{OPTIIMIZE} & OPTIMIZE_RULESET_MASK; } enable_script; @@ -877,16 +877,16 @@ sub compiler { optimize_level0; - if ( $config{OPTIMIZE} & OPTIMIZE_MASK ) { + if ( ( my $optimize = $config{OPTIMIZE} & OPTIMIZE_MASK ) ) { progress_message2 'Optimizing Ruleset...'; # # Optimize Policy Chains # - optimize_policy_chains if $config{OPTIMIZE} & OPTIMIZE_POLICY_MASK; + optimize_policy_chains if ( $optimize & OPTIMIZE_POLICY_MASK1 ) == OPTIMIZE_POLICY_MASK; # Level 2 but not 4 # # Ruleset Optimization # - optimize_ruleset if $config{OPTIMIZE} & OPTIMIZE_RULESET_MASK; + optimize_ruleset if $optimize & OPTIMIZE_RULESET_MASK; } enable_script if $debug; From 040f693583e72fc444030a6e85ff157ab1920477 Mon Sep 17 00:00:00 2001 From: Tom Eastep Date: Sun, 3 Jun 2012 17:50:34 -0700 Subject: [PATCH 3/3] Cosmetic changes in code from when I was still learning Perl Signed-off-by: Tom Eastep --- Shorewall/Perl/Shorewall/Zones.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Shorewall/Perl/Shorewall/Zones.pm b/Shorewall/Perl/Shorewall/Zones.pm index c260d3679..a5493a28f 100644 --- a/Shorewall/Perl/Shorewall/Zones.pm +++ b/Shorewall/Perl/Shorewall/Zones.pm @@ -567,6 +567,7 @@ sub determine_zones() for ( @{$zones{$zone}{children}} ) { next ZONE unless $ordered{$_}; } + $ordered{$zone} = 1; push @zones, $zone; redo PUSHED; @@ -574,7 +575,7 @@ sub determine_zones() } } - assert( scalar @zones == scalar @z ); + assert( @zones == @z ); }