forked from extern/shorewall_code
Named arguments to Shorewall::Compiler::compiler()
git-svn-id: https://shorewall.svn.sourceforge.net/svnroot/shorewall/trunk@7826 fbd18981-670d-0410-9b5c-8dc0c1a9a2bb
This commit is contained in:
parent
dea79aa763
commit
20bedd04d7
@ -95,6 +95,36 @@ Other changes in Shorewall 4.1.2.
|
|||||||
The --log option is ignored when --log_verbosity is not supplied or
|
The --log option is ignored when --log_verbosity is not supplied or
|
||||||
is supplied with value -1.
|
is supplied with value -1.
|
||||||
|
|
||||||
|
To avoid a proliferation of parameters to
|
||||||
|
Shorewall::Compiler::compile(), that function has been changed to
|
||||||
|
use named parameters. Parameter names are:
|
||||||
|
|
||||||
|
object Object file. If omitted or '', the
|
||||||
|
configuration is syntax checked.
|
||||||
|
directory Directory. If omitted or '', configuration
|
||||||
|
files are located using
|
||||||
|
CONFIG_PATH. Otherwise, the directory named by
|
||||||
|
this parameter is searched first.
|
||||||
|
verbosity Verbosity; range -1 to 2
|
||||||
|
timestamp 0|1 -- timestamp messages.
|
||||||
|
debug 0|1 -- include stack trace in warning/error
|
||||||
|
messages.
|
||||||
|
export 0|1 -- compile for export.
|
||||||
|
chains List of chains to be reloaded by 'refresh'.
|
||||||
|
log File to log compiler messages to.
|
||||||
|
log_verbosity Log Verbosity; range -1 to 2.
|
||||||
|
|
||||||
|
Those parameters that are supplied must have defined values.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
use lib '/usr/share/shorewall-perl/';
|
||||||
|
use Shorewall::Compiler;
|
||||||
|
|
||||||
|
compiler( object => '/root/firewall',
|
||||||
|
log => '/root/compile.log',
|
||||||
|
log_verbosity => 2 );
|
||||||
|
|
||||||
2) Previously, when HIGH_ROUTE_MARKS=Yes, Shorewall allowed non-zero
|
2) Previously, when HIGH_ROUTE_MARKS=Yes, Shorewall allowed non-zero
|
||||||
mark values < 256 to be assigned in the OUTPUT chain. This has been
|
mark values < 256 to be assigned in the OUTPUT chain. This has been
|
||||||
changed so that only high mark values may be assigned
|
changed so that only high mark values may be assigned
|
||||||
|
@ -701,12 +701,44 @@ EOF
|
|||||||
# If the first argument is non-null, it names the script file to generate.
|
# If the first argument is non-null, it names the script file to generate.
|
||||||
# Otherwise, this is a 'check' command and no script is produced.
|
# Otherwise, this is a 'check' command and no script is produced.
|
||||||
#
|
#
|
||||||
sub compiler( $$$$$$$ ) {
|
sub compiler {
|
||||||
|
|
||||||
my ( $objectfile, $directory, $verbosity, $options , $chains , $log , $log_verbosity ) = @_;
|
my ( $objectfile, $directory, $verbosity, $timestamp , $debug, $chains , $log , $log_verbosity ) =
|
||||||
|
( '', '', -1, '', 0, '', '', -1 );
|
||||||
|
|
||||||
$export = 0;
|
$export = 0;
|
||||||
|
|
||||||
|
sub edit_boolean( $ ) {
|
||||||
|
my $val = numeric_value1( shift );
|
||||||
|
defined $val && $val >= 0 && $val < 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub edit_verbosity( $ ) {
|
||||||
|
my $val = numeric_value1( shift );
|
||||||
|
defined $val && $val >= -1 && $val < 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
my %elbat = ( object => { store => \$objectfile },
|
||||||
|
directory => { store => \$directory },
|
||||||
|
verbosity => { store => \$verbosity , edit => \&edit_verbosity } ,
|
||||||
|
timestamp => { store => \$timestamp, edit => \&edit_boolean } ,
|
||||||
|
debug => { store => \$debug, edit => \&edit_boolean } ,
|
||||||
|
export => { store => \$export , edit => \&edit_boolean } ,
|
||||||
|
chains => { store => \$chains },
|
||||||
|
log => { store => \$log },
|
||||||
|
log_verbosity => { store => \$log_verbosity, edit => \&edit_verbosity } ,
|
||||||
|
);
|
||||||
|
|
||||||
|
while ( defined ( my $name = shift ) ) {
|
||||||
|
fatal_error "Unknown parameter ($name)" unless my $ref = $elbat{$name};
|
||||||
|
fatal_error "Undefined value supplied for parameter $name" unless defined ( my $val = shift ) ;
|
||||||
|
if ( $ref->{edit} ) {
|
||||||
|
fatal_error "Invalid value ( $val ) supplied for parameter $name" unless $ref->{edit}->($val);
|
||||||
|
}
|
||||||
|
|
||||||
|
${$ref->{store}} = $val;
|
||||||
|
}
|
||||||
|
|
||||||
reinitialize if $reused++;
|
reinitialize if $reused++;
|
||||||
|
|
||||||
if ( $directory ne '' ) {
|
if ( $directory ne '' ) {
|
||||||
@ -714,11 +746,10 @@ sub compiler( $$$$$$$ ) {
|
|||||||
set_shorewall_dir( $directory );
|
set_shorewall_dir( $directory );
|
||||||
}
|
}
|
||||||
|
|
||||||
set_verbose( $verbosity ) unless $verbosity eq '';
|
set_verbose( $verbosity );
|
||||||
set_log($log, $log_verbosity) if $log;
|
set_log($log, $log_verbosity) if $log;
|
||||||
$export = 1 if $options & EXPORT;
|
set_timestamp( $timestamp );
|
||||||
set_timestamp( 1 ) if $options & TIMESTAMP;
|
set_debug( $debug );
|
||||||
set_debug( 1 ) if $options & DEBUG;
|
|
||||||
#
|
#
|
||||||
# Get shorewall.conf and capabilities.
|
# Get shorewall.conf and capabilities.
|
||||||
#
|
#
|
||||||
|
@ -55,6 +55,7 @@ our @EXPORT_OK = qw( $shorewall_dir initialize read_a_line1 set_config_path shor
|
|||||||
our %EXPORT_TAGS = ( internal => [ qw( create_temp_object
|
our %EXPORT_TAGS = ( internal => [ qw( create_temp_object
|
||||||
finalize_object
|
finalize_object
|
||||||
numeric_value
|
numeric_value
|
||||||
|
numeric_value1
|
||||||
emit
|
emit
|
||||||
emit_unindented
|
emit_unindented
|
||||||
save_progress_message
|
save_progress_message
|
||||||
@ -510,6 +511,12 @@ sub numeric_value ( $ ) {
|
|||||||
$mark =~ /^0/ ? oct $mark : $mark;
|
$mark =~ /^0/ ? oct $mark : $mark;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub numeric_value1 ( $ ) {
|
||||||
|
my $mark = lc $_[0];
|
||||||
|
return undef unless $mark =~ /^-?(0x[a-f0-9]+|0[0-7]*|[1-9]\d*)$/;
|
||||||
|
$mark =~ /^0/ ? oct $mark : $mark;
|
||||||
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# Write the arguments to the object file (if any) with the current indentation.
|
# Write the arguments to the object file (if any) with the current indentation.
|
||||||
#
|
#
|
||||||
|
@ -42,7 +42,7 @@ use lib "$FindBin::Bin";
|
|||||||
use Shorewall::Compiler;
|
use Shorewall::Compiler;
|
||||||
use Getopt::Long;
|
use Getopt::Long;
|
||||||
|
|
||||||
sub usage() {
|
sub usage( $ ) {
|
||||||
print STDERR 'usage: compiler.pl [ <option> ... ] <filename> ]
|
print STDERR 'usage: compiler.pl [ <option> ... ] <filename> ]
|
||||||
|
|
||||||
options are:
|
options are:
|
||||||
@ -55,7 +55,7 @@ sub usage() {
|
|||||||
[ --log=<filename> ]
|
[ --log=<filename> ]
|
||||||
[ --log-verbose={-1|0-2} ]
|
[ --log-verbose={-1|0-2} ]
|
||||||
';
|
';
|
||||||
exit 1;
|
exit shift @_;
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -64,15 +64,18 @@ sub usage() {
|
|||||||
my $export = 0;
|
my $export = 0;
|
||||||
my $shorewall_dir = '';
|
my $shorewall_dir = '';
|
||||||
my $verbose = 0;
|
my $verbose = 0;
|
||||||
my $timestamp = '';
|
my $timestamp = 0;
|
||||||
my $debug = 0;
|
my $debug = 0;
|
||||||
my $chains = '';
|
my $chains = '';
|
||||||
my $log = '';
|
my $log = '';
|
||||||
my $log_verbose = 0;
|
my $log_verbose = 0;
|
||||||
|
my $help = 0;
|
||||||
|
|
||||||
Getopt::Long::Configure ('bundling');
|
Getopt::Long::Configure ('bundling');
|
||||||
|
|
||||||
my $result = GetOptions('export' => \$export,
|
my $result = GetOptions('h' => \$help,
|
||||||
|
'--help' => \$help,
|
||||||
|
'export' => \$export,
|
||||||
'e' => \$export,
|
'e' => \$export,
|
||||||
'directory=s' => \$shorewall_dir,
|
'directory=s' => \$shorewall_dir,
|
||||||
'd=s' => \$shorewall_dir,
|
'd=s' => \$shorewall_dir,
|
||||||
@ -88,12 +91,15 @@ my $result = GetOptions('export' => \$export,
|
|||||||
'log_verbosity=i' => \$log_verbose,
|
'log_verbosity=i' => \$log_verbose,
|
||||||
);
|
);
|
||||||
|
|
||||||
usage unless $result && @ARGV < 2;
|
usage(1) unless $result && @ARGV < 2;
|
||||||
|
usage(0) if $help;
|
||||||
|
|
||||||
my $options = 0;
|
compiler( object => defined $ARGV[0] ? $ARGV[0] : '',
|
||||||
|
directory => $shorewall_dir,
|
||||||
$options |= EXPORT if $export;
|
verbosity => $verbose,
|
||||||
$options |= TIMESTAMP if $timestamp;
|
timestamp => $timestamp,
|
||||||
$options |= DEBUG if $debug;
|
debug => $debug,
|
||||||
|
export => $export,
|
||||||
compiler $ARGV[0], $shorewall_dir, $verbose, $options, $chains, $log , $log_verbose;
|
chains => $chains,
|
||||||
|
log => $log,
|
||||||
|
log_verbosity => $log_verbose );
|
||||||
|
Loading…
Reference in New Issue
Block a user