Eliminate shortlineinfo1()

Signed-off-by: Tom Eastep <teastep@shorewall.net>
This commit is contained in:
Tom Eastep 2016-01-27 10:21:08 -08:00
parent b4723da07c
commit f999acda63
4 changed files with 40 additions and 24 deletions

View File

@ -919,7 +919,7 @@ sub set_rule_option( $$$ ) {
sub transform_rule( $;\$ ) { sub transform_rule( $;\$ ) {
my ( $input, $completeref ) = @_; my ( $input, $completeref ) = @_;
my $ruleref = { mode => CAT_MODE, matches => [], target => '' , origin => shortlineinfo1( '' ) }; my $ruleref = { mode => CAT_MODE, matches => [], target => '' , origin => shortlineinfo( '' ) };
my $simple = 1; my $simple = 1;
my $target = ''; my $target = '';
my $jump = ''; my $jump = '';
@ -1243,6 +1243,19 @@ sub add_commands ( $$;@ ) {
$chainref->{optflags} |= ( DONT_OPTIMIZE | DONT_MOVE ); $chainref->{optflags} |= ( DONT_OPTIMIZE | DONT_MOVE );
} }
#
# Set the comment member of an irule
#
sub set_irule_comment( $$ ) {
my ( $chainref, $ruleref ) = @_;
if ( $config{TRACK_RULES} eq 'Yes' ) {
$ruleref->{comment} = shortlineinfo( $chainref->{origin} ) || $comment;
} else {
$ruleref->{comment} = $comment;
}
}
# #
# Transform the passed rule and add it to the end of the passed chain's rule list. # Transform the passed rule and add it to the end of the passed chain's rule list.
# #
@ -1254,7 +1267,8 @@ sub push_rule( $$ ) {
my $complete = 0; my $complete = 0;
my $ruleref = transform_rule( $_[1], $complete ); my $ruleref = transform_rule( $_[1], $complete );
$ruleref->{comment} = shortlineinfo($chainref->{origin}) || $comment; set_irule_comment( $chainref, $ruleref );
$ruleref->{mode} = CMD_MODE if $ruleref->{cmdlevel} = $chainref->{cmdlevel}; $ruleref->{mode} = CMD_MODE if $ruleref->{cmdlevel} = $chainref->{cmdlevel};
push @{$chainref->{rules}}, $ruleref; push @{$chainref->{rules}}, $ruleref;
@ -1475,7 +1489,7 @@ sub create_irule( $$$;@ ) {
( $target, my $targetopts ) = split ' ', $target, 2; ( $target, my $targetopts ) = split ' ', $target, 2;
my $ruleref = { matches => [] , origin => shortlineinfo1( '' ) }; my $ruleref = { matches => [] , origin => shortlineinfo( '' ) };
$ruleref->{mode} = ( $ruleref->{cmdlevel} = $chainref->{cmdlevel} ) ? CMD_MODE : CAT_MODE; $ruleref->{mode} = ( $ruleref->{cmdlevel} = $chainref->{cmdlevel} ) ? CMD_MODE : CAT_MODE;
@ -1488,7 +1502,7 @@ sub create_irule( $$$;@ ) {
$ruleref->{target} = ''; $ruleref->{target} = '';
} }
$ruleref->{comment} = shortlineinfo($chainref->{origin}) || $ruleref->{comment} || $comment; set_irule_comment( $chainref, $ruleref );
$iprangematch = 0; $iprangematch = 0;
@ -1644,7 +1658,7 @@ sub insert_rule1($$$)
my $ruleref = transform_rule( $rule ); my $ruleref = transform_rule( $rule );
$ruleref->{comment} = shortlineinfo($chainref->{origin}) || $comment; set_irule_comment( $chainref, $ruleref );
assert( ! ( $ruleref->{cmdlevel} = $chainref->{cmdlevel}) , $chainref->{name} ); assert( ! ( $ruleref->{cmdlevel} = $chainref->{cmdlevel}) , $chainref->{name} );
$ruleref->{mode} = CAT_MODE; $ruleref->{mode} = CAT_MODE;
@ -1670,7 +1684,7 @@ sub insert_irule( $$$$;@ ) {
my ( $chainref, $jump, $target, $number, @matches ) = @_; my ( $chainref, $jump, $target, $number, @matches ) = @_;
my $rulesref = $chainref->{rules}; my $rulesref = $chainref->{rules};
my $ruleref = { origin => shortlineinfo1( '' ) }; my $ruleref = { origin => shortlineinfo( '' ) };
$ruleref->{mode} = ( $ruleref->{cmdlevel} = $chainref->{cmdlevel} ) ? CMD_MODE : CAT_MODE; $ruleref->{mode} = ( $ruleref->{cmdlevel} = $chainref->{cmdlevel} ) ? CMD_MODE : CAT_MODE;
@ -1686,8 +1700,7 @@ sub insert_irule( $$$$;@ ) {
$chainref->{optflags} |= push_matches( $ruleref, @matches ); $chainref->{optflags} |= push_matches( $ruleref, @matches );
} }
set_irule_comment( $chainref, $ruleref );
$ruleref->{comment} = shortlineinfo( $chainref->{origin} ) || $ruleref->{comment} || $comment;
if ( $number >= @$rulesref ) { if ( $number >= @$rulesref ) {
# #
@ -2302,7 +2315,7 @@ sub new_chain($$)
references => {}, references => {},
filtered => 0, filtered => 0,
optflags => 0, optflags => 0,
origin => shortlineinfo1( '' ) || shortlineinfo( '' ), origin => shortlineinfo( '' ),
}; };
trace( $chainref, 'N', undef, '' ) if $debug; trace( $chainref, 'N', undef, '' ) if $debug;
@ -7931,7 +7944,7 @@ sub emitr( $$ ) {
# #
enter_cat_mode unless $mode == CAT_MODE; enter_cat_mode unless $mode == CAT_MODE;
if ( my $origin = $ruleref->{origin} ) { if ( ( my $origin = $ruleref->{origin} ) && $config{TRACK_RULES} eq 'File' ) {
emit_unindented '# ' . $origin; emit_unindented '# ' . $origin;
} }

View File

@ -52,7 +52,6 @@ our @EXPORT = qw(
assert assert
currentlineinfo currentlineinfo
shortlineinfo shortlineinfo
shortlineinfo1
shortlineinfo2 shortlineinfo2
clear_currentfilename clear_currentfilename
validate_level validate_level
@ -1210,23 +1209,25 @@ sub shortlineinfo2() {
} }
} }
sub shortlineinfo1( $ ) {
$config{TRACK_RULES} eq 'File' ? $currentfile ? shortlineinfo2 : $_[0] || '' : '';
}
sub shortlineinfo( $ ) { sub shortlineinfo( $ ) {
if ( $config{TRACK_RULES} eq 'Yes' ) { if ( my $track = $config{TRACK_RULES} ) {
if ( $currentfile ) { if ( $currentfile ) {
if ( $track eq 'Yes' ) {
my $comment = '@@@ '. join( ':', $currentfilename, $currentlinenumber ) . ' @@@'; my $comment = '@@@ '. join( ':', $currentfilename, $currentlinenumber ) . ' @@@';
$comment = '@@@ ' . join( ':' , basename($currentfilename), $currentlinenumber) . ' @@@' if length $comment > 255; $comment = '@@@ ' . join( ':' , basename($currentfilename), $currentlinenumber) . ' @@@' if length $comment > 255;
$comment = '@@@ Filename Too Long @@@' if length $comment > 255; $comment = '@@@ Filename Too Long @@@' if length $comment > 255;
$comment; $comment;
} else {
join( ':', $currentfilename, $currentlinenumber );
}
} else { } else {
# #
# Alternate lineinfo may have been passed # Alternate lineinfo may have been passed
# #
$_[0] || '' $_[0] || ''
} }
} else {
'';
} }
} }

View File

@ -107,13 +107,15 @@ sub setup_ecn()
fatal_error 'INTERFACE must be specified' if $interface eq '-'; fatal_error 'INTERFACE must be specified' if $interface eq '-';
fatal_error "Unknown interface ($interface)" unless known_interface $interface; fatal_error "Unknown interface ($interface)" unless known_interface $interface;
$interfaces{$interface} ||= shortlineinfo1( '' ); my $lineinfo = shortlineinfo( '' );
$interfaces{$interface} ||= $lineinfo;
$hosts = ALLIP if $hosts eq '-'; $hosts = ALLIP if $hosts eq '-';
for my $host( split_list $hosts, 'address' ) { for my $host( split_list $hosts, 'address' ) {
validate_host( $host , 1 ); validate_host( $host , 1 );
push @hosts, [ $interface, shortlineinfo1( '' ), $host ]; push @hosts, [ $interface, $lineinfo, $host ];
} }
} }

View File

@ -894,7 +894,7 @@ sub add_group_to_zone($$$$$$)
hosts => \@newnetworks, hosts => \@newnetworks,
ipsec => $type & IPSEC ? 'ipsec' : 'none' , ipsec => $type & IPSEC ? 'ipsec' : 'none' ,
exclusions => \@exclusions , exclusions => \@exclusions ,
origin => shortlineinfo1( '' ) , origin => shortlineinfo( '' ) ,
}; };
if ( $type != IPSEC ) { if ( $type != IPSEC ) {
@ -1397,7 +1397,7 @@ sub process_interface( $$ ) {
physical => $physical , physical => $physical ,
base => var_base( $physical ), base => var_base( $physical ),
zones => {}, zones => {},
origin => shortlineinfo1('') || shortlineinfo( '' ), origin => shortlineinfo( '' ),
wildcard => $wildcard, wildcard => $wildcard,
}; };