Refactor ALL_ACASTS code

Signed-off-by: Tom Eastep <teastep@shorewall.net>
This commit is contained in:
Tom Eastep 2020-09-11 15:07:38 -07:00
parent b253be8a69
commit 8d4e79650e
No known key found for this signature in database
GPG Key ID: 96E6B3F2423A4D10
3 changed files with 20 additions and 11 deletions

View File

@ -7478,9 +7478,9 @@ sub have_address_variables() {
# #
# Generate setting of run-time global shell variables # Generate setting of run-time global shell variables
# #
sub set_global_variables( $$ ) { sub set_global_variables( $$$ ) {
my ( $setall, $conditional ) = @_; my ( $setall, $conditional, $call_generate_all_acasts ) = @_;
if ( $conditional ) { if ( $conditional ) {
my ( $interface, @interfaces ); my ( $interface, @interfaces );
@ -7523,7 +7523,7 @@ sub set_global_variables( $$ ) {
emit 'ALL_BCASTS="$(get_all_bcasts) 255.255.255.255"'; emit 'ALL_BCASTS="$(get_all_bcasts) 255.255.255.255"';
emit $interfacebcasts{$_} for sortkeysiftest %interfacebcasts; emit $interfacebcasts{$_} for sortkeysiftest %interfacebcasts;
} else { } else {
generate_all_acasts; emit $call_generate_all_acasts;
emit $interfaceacasts{$_} for sortkeysiftest %interfaceacasts; emit $interfaceacasts{$_} for sortkeysiftest %interfaceacasts;
} }
} }

View File

@ -276,6 +276,11 @@ sub generate_script_2() {
emit "}\n"; # End of initialize() emit "}\n"; # End of initialize()
#
# Conditionally emit the 'generate_all_acasts() function
#
my $call_generate_all_acasts = $family == F_IPV6 && ! have_capability( 'ADDRTYPE' ) && generate_all_acasts;
emit( '' , emit( '' ,
'#' , '#' ,
'# Set global variables holding detected IP information' , '# Set global variables holding detected IP information' ,
@ -297,8 +302,6 @@ sub generate_script_2() {
); );
} }
emit( 'local iface', '' ) if $family == F_IPV6;
map_provider_to_interface if have_providers; map_provider_to_interface if have_providers;
if ( $global_variables ) { if ( $global_variables ) {
@ -315,7 +318,7 @@ sub generate_script_2() {
if ( $global_variables == ( ALL_COMMANDS | NOT_RESTORE ) ) { if ( $global_variables == ( ALL_COMMANDS | NOT_RESTORE ) ) {
verify_required_interfaces(0); verify_required_interfaces(0);
set_global_variables($family == F_IPV6, 0); set_global_variables( $family == F_IPV6, 0, $call_generate_all_acasts );
handle_optional_interfaces; handle_optional_interfaces;
} }
@ -329,7 +332,7 @@ sub generate_script_2() {
} }
verify_required_interfaces(1); verify_required_interfaces(1);
set_global_variables(1,1); set_global_variables(1, 1, $call_generate_all_acasts );
handle_optional_interfaces; handle_optional_interfaces;
if ( $global_variables & NOT_RESTORE ) { if ( $global_variables & NOT_RESTORE ) {

View File

@ -2430,13 +2430,15 @@ sub generate_all_acasts() {
} }
} }
unless( @noacasts || @wildnoacasts ) { return 'ALL_ACASTS="$(get_all_acasts)"' unless @noacasts || @wildnoacasts;
emit( 'ALL_ACASTS="$(get_all_acasts)"' );
return;
}
@wildacasts = '*' unless @wildacasts; @wildacasts = '*' unless @wildacasts;
emit( "#\n# Populate the ALL_ACASTS variable\n#",
'generate_all_acasts()',
'{' );
push_indent;
emit( 'ALL_ACASTS=', emit( 'ALL_ACASTS=',
'', '',
'for iface in $(find_all_interfaces1); do' ); 'for iface in $(find_all_interfaces1); do' );
@ -2489,6 +2491,10 @@ sub generate_all_acasts() {
emit( 'esac'); emit( 'esac');
pop_indent; pop_indent;
emit( 'done'); emit( 'done');
pop_indent;
emit( "}\n" );
return 'generate_all_acasts';
} }
1; 1;