forked from extern/shorewall_code
Replace discrete tests with fatal_error() calls with assert() calls.
Signed-off-by: Tom Eastep <teastep@shorewall.net> git-svn-id: https://shorewall.svn.sourceforge.net/svnroot/shorewall/trunk@9672 fbd18981-670d-0410-9b5c-8dc0c1a9a2bb
This commit is contained in:
parent
8dfd9e5ccd
commit
b987ea4940
@ -712,7 +712,7 @@ sub process_action3( $$$$$ ) {
|
||||
if ( $action2type & ACTION ) {
|
||||
$target2 = (find_logactionchain ( $target = $target2 ))->{name};
|
||||
} else {
|
||||
fatal_error "Internal Error" unless $action2type & ( MACRO | LOGRULE | NFQ | CHAIN );
|
||||
assert( $action2type & ( MACRO | LOGRULE | NFQ | CHAIN ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -387,7 +387,7 @@ sub incr_cmd_level( $ ) {
|
||||
}
|
||||
|
||||
sub decr_cmd_level( $ ) {
|
||||
fatal_error "Internal error in decr_cmd_level()" if --$_[0]->{cmdlevel} < 0;
|
||||
assert( --$_[0]->{cmdlevel} >= 0);
|
||||
}
|
||||
|
||||
#
|
||||
@ -535,7 +535,7 @@ sub add_rule($$;$)
|
||||
{
|
||||
my ($chainref, $rule, $expandports) = @_;
|
||||
|
||||
fatal_error 'Internal Error in add_rule()' if reftype $rule;
|
||||
assert( ! reftype $rule );
|
||||
|
||||
$iprangematch = 0;
|
||||
#
|
||||
@ -627,7 +627,7 @@ sub insert_rule1($$$)
|
||||
{
|
||||
my ($chainref, $number, $rule) = @_;
|
||||
|
||||
fatal_error 'Internal Error in insert_rule()' if $chainref->{cmdlevel};
|
||||
assert( ! $chainref->{cmdlevel});
|
||||
|
||||
$rule .= "-m comment --comment \"$comment\"" if $comment;
|
||||
|
||||
@ -670,7 +670,7 @@ sub move_rules( $$ ) {
|
||||
my @rules = @{$chain1->{rules}};
|
||||
|
||||
for ( @rules ) {
|
||||
fatal_error "Internal Error in move_rules()" unless /^-A/;
|
||||
assert( /^-A/ );
|
||||
}
|
||||
|
||||
splice @{$chain2->{rules}}, 0, 0, @rules;
|
||||
@ -903,7 +903,7 @@ sub new_chain($$)
|
||||
{
|
||||
my ($table, $chain) = @_;
|
||||
|
||||
fatal_error "Internal error in new_chain()" if $chain_table{$table}{$chain} || $builtin_target{ $chain };
|
||||
assert( ! $chain_table{$table}{$chain} && ! $builtin_target{ $chain } );
|
||||
|
||||
$chain_table{$table}{$chain} = { name => $chain,
|
||||
rules => [],
|
||||
@ -920,7 +920,7 @@ sub ensure_chain($$)
|
||||
{
|
||||
my ($table, $chain) = @_;
|
||||
|
||||
fatal_error 'Internal Error in ensure_chain' unless $table && $chain;
|
||||
assert( $table && $chain );
|
||||
|
||||
my $ref = $chain_table{$table}{$chain};
|
||||
|
||||
@ -2774,7 +2774,7 @@ sub create_netfilter_load( $ ) {
|
||||
for my $chain ( @builtins ) {
|
||||
my $chainref = $chain_table{$table}{$chain};
|
||||
if ( $chainref ) {
|
||||
fatal_error "Internal error in create_netfilter_load()" if $chainref->{cmdlevel};
|
||||
assert( $chainref->{cmdlevel} == 0 );
|
||||
emit_unindented ":$chain $chainref->{policy} [0:0]";
|
||||
push @chains, $chainref;
|
||||
}
|
||||
@ -2785,7 +2785,7 @@ sub create_netfilter_load( $ ) {
|
||||
for my $chain ( grep $chain_table{$table}{$_}->{referenced} , ( sort keys %{$chain_table{$table}} ) ) {
|
||||
my $chainref = $chain_table{$table}{$chain};
|
||||
unless ( $chainref->{builtin} ) {
|
||||
fatal_error "Internal error in create_netfilter_load()" if $chainref->{cmdlevel};
|
||||
assert( $chainref->{cmdlevel} == 0 );
|
||||
emit_unindented ":$chainref->{name} - [0:0]";
|
||||
push @chains, $chainref;
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ our @ISA = qw(Exporter);
|
||||
our @EXPORT = qw(
|
||||
warning_message
|
||||
fatal_error
|
||||
assert
|
||||
progress_message
|
||||
progress_message_nocompress
|
||||
progress_message2
|
||||
@ -702,6 +703,14 @@ sub fatal_error1 {
|
||||
die " ERROR: @_\n";
|
||||
}
|
||||
|
||||
sub assert( $ ) {
|
||||
unless ( $_[0] ) {
|
||||
my @caller = caller 1;
|
||||
|
||||
fatal_error "Internal error in $caller[0]::$caller[3]";
|
||||
}
|
||||
}
|
||||
|
||||
#
|
||||
# Convert value to decimal number
|
||||
#
|
||||
@ -746,7 +755,7 @@ sub in_hex8( $ ) {
|
||||
# Replaces leading spaces with tabs as appropriate and suppresses consecutive blank lines.
|
||||
#
|
||||
sub emit {
|
||||
fatal_error 'Internal Error in emit' unless $object_enabled;
|
||||
assert ( $object_enabled );
|
||||
|
||||
if ( $object ) {
|
||||
#
|
||||
@ -772,7 +781,7 @@ sub emit {
|
||||
# Write passed message to the object with newline but no indentation.
|
||||
#
|
||||
sub emit_unindented( $ ) {
|
||||
fatal_error 'Internal Error in emit_unindented' unless $object_enabled;
|
||||
assert( $object_enabled );
|
||||
print $object "$_[0]\n" if $object;
|
||||
}
|
||||
|
||||
@ -964,7 +973,7 @@ sub pop_indent() {
|
||||
# Functions for copying files into the object
|
||||
#
|
||||
sub copy( $ ) {
|
||||
fatal_error 'Internal Error in copy' unless $object_enabled;
|
||||
assert( $object_enabled );
|
||||
|
||||
if ( $object ) {
|
||||
my $file = $_[0];
|
||||
@ -996,7 +1005,7 @@ sub copy( $ ) {
|
||||
# This one handles line continuation and 'here documents'
|
||||
|
||||
sub copy1( $ ) {
|
||||
fatal_error 'Internal Error in copy1' unless $object_enabled;
|
||||
assert( $object_enabled );
|
||||
|
||||
if ( $object ) {
|
||||
my $file = $_[0];
|
||||
@ -1274,7 +1283,7 @@ sub do_open_file( $ ) {
|
||||
sub open_file( $ ) {
|
||||
my $fname = find_file $_[0];
|
||||
|
||||
fatal_error 'Internal Error in open_file()' if defined $currentfile;
|
||||
assert( ! defined $currentfile );
|
||||
|
||||
-f $fname && -s _ ? do_open_file $fname : '';
|
||||
}
|
||||
@ -1448,7 +1457,7 @@ sub embedded_perl( $ ) {
|
||||
if ( $scriptfile ) {
|
||||
fatal_error "INCLUDEs nested too deeply" if @includestack >= 4;
|
||||
|
||||
close $scriptfile or fatal_error "Internal Error in embedded_perl()";
|
||||
close $scriptfile or assert(0);
|
||||
|
||||
$scriptfile = undef;
|
||||
|
||||
|
@ -202,7 +202,7 @@ sub validate_4net( $$ ) {
|
||||
}
|
||||
|
||||
if ( defined wantarray ) {
|
||||
fatal_error "Internal Error in validate_net()" if $allow_name;
|
||||
assert ( ! $allow_name );
|
||||
if ( wantarray ) {
|
||||
( decodeaddr( $net ) , $vlsm );
|
||||
} else {
|
||||
|
@ -372,7 +372,7 @@ sub default_policy( $$$ ) {
|
||||
my $policy = $policyref->{policy};
|
||||
my $loglevel = $policyref->{loglevel};
|
||||
|
||||
fatal_error "Internal error in default_policy()" unless $policyref;
|
||||
assert( $policyref );
|
||||
|
||||
if ( $chainref eq $policyref ) {
|
||||
policy_rules $chainref , $policy, $loglevel , $default, $config{MULTICAST};
|
||||
|
@ -71,7 +71,7 @@ sub setup_arp_filtering() {
|
||||
my $file = "/proc/sys/net/ipv4/conf/$interface/arp_ignore";
|
||||
my $value = get_interface_option $interface, 'arp_ignore';
|
||||
|
||||
fatal_error "Internal Error in setup_arp_filtering()" unless defined $value;
|
||||
assert( defined $value );
|
||||
|
||||
emit ( "if [ -f $file ]; then",
|
||||
" echo $value > $file");
|
||||
|
@ -1643,7 +1643,7 @@ sub generate_matrix() {
|
||||
return $chain if $chainref && $chainref->{referenced};
|
||||
return 'ACCEPT' if $zone eq $zone1;
|
||||
|
||||
fatal_error "Internal Error in rules_target()" unless $chainref;
|
||||
assert( $chainref );
|
||||
|
||||
if ( $chainref->{policy} ne 'CONTINUE' ) {
|
||||
my $policyref = $filter_table->{$chainref->{policychain}};
|
||||
|
@ -495,7 +495,7 @@ sub dev_by_number( $ ) {
|
||||
$dev = $devnums[ $devnum ];
|
||||
fatal_error "Undefined INTERFACE number ($_[0])" unless defined $dev;
|
||||
$devref = $tcdevices{$dev};
|
||||
fatal_error "Internal Error in dev_by_number()" unless $devref;
|
||||
assert( $devref );
|
||||
} else {
|
||||
$devref = $tcdevices{$dev};
|
||||
fatal_error "Unknown INTERFACE ($dev)" unless $devref;
|
||||
|
@ -344,7 +344,7 @@ sub determine_zones()
|
||||
}
|
||||
}
|
||||
|
||||
fatal_error "Internal error in determine_zones()" unless scalar @zones == scalar @z;
|
||||
assert( scalar @zones == scalar @z );
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user