diff --git a/Shorewall-core/lib.cli b/Shorewall-core/lib.cli index b54b33209..626c803c7 100644 --- a/Shorewall-core/lib.cli +++ b/Shorewall-core/lib.cli @@ -582,7 +582,7 @@ show_routing() { determine_ipset_version() { local setname - if [ -z "$IPSET" -o $IPSET = ipset ]; then + if [ -z "$IPSET" -o "$IPSET" = "ipset" ]; then IPSET=$(mywhich ipset) [ -n "$IPSET" ] || fatal_error "The ipset utility cannot be located" fi @@ -3506,6 +3506,8 @@ shorewall_cli() { g_conditional= g_file= g_doing="Compiling" + g_directives= + g_inline= VERBOSE= VERBOSITY=1 diff --git a/Shorewall/Perl/Shorewall/ARP.pm b/Shorewall/Perl/Shorewall/ARP.pm index 77f6457e3..58015b9ad 100644 --- a/Shorewall/Perl/Shorewall/ARP.pm +++ b/Shorewall/Perl/Shorewall/ARP.pm @@ -82,7 +82,8 @@ sub match_arp_net( $$$ ) { # Process a rule in the arprules file # sub process_arprule() { - my ( $originalaction, $source, $dest, $opcode ) = split_line( 'arprules file entry', {action => 0, source => 1, dest => 2, opcode => 3 } ); + my ( $originalaction, $source, $dest, $opcode ) = split_line( 'arprules file entry', + {action => 0, source => 1, dest => 2, opcode => 3 } ); my $chainref; my $iifaceref; diff --git a/Shorewall/Perl/Shorewall/Accounting.pm b/Shorewall/Perl/Shorewall/Accounting.pm index d12ffca60..c06b1ce06 100644 --- a/Shorewall/Perl/Shorewall/Accounting.pm +++ b/Shorewall/Perl/Shorewall/Accounting.pm @@ -243,7 +243,7 @@ sub process_accounting_rule1( $$$$$$$$$$$ ) { } } } elsif ( $action eq 'INLINE' ) { - $rule .= get_inline_matches; + $rule .= get_inline_matches(1); } else { ( $action, my $cmd ) = split /:/, $action; @@ -424,8 +424,11 @@ sub process_accounting_rule1( $$$$$$$$$$$ ) { sub process_accounting_rule( ) { my ($action, $chain, $source, $dest, $protos, $ports, $sports, $user, $mark, $ipsec, $headers ) = - split_line1 'Accounting File', { action => 0, chain => 1, source => 2, dest => 3, proto => 4, dport => 5, sport => 6, user => 7, mark => 8, ipsec => 9, headers => 10 }; - + split_line2( 'Accounting File', + { action => 0, chain => 1, source => 2, dest => 3, proto => 4, dport => 5, sport => 6, user => 7, mark => 8, ipsec => 9, headers => 10 }, + {}, #nopad + undef, #Max columns + 1 ); my $nonempty = 0; for my $proto ( split_list $protos, 'Protocol' ) { diff --git a/Shorewall/Perl/Shorewall/Chains.pm b/Shorewall/Perl/Shorewall/Chains.pm index 2ffb66278..0206f9100 100644 --- a/Shorewall/Perl/Shorewall/Chains.pm +++ b/Shorewall/Perl/Shorewall/Chains.pm @@ -80,6 +80,10 @@ our @EXPORT = ( qw( add_interface_options state_match state_imatch + split_action + get_target_param + get_inline_matches + handle_inline STANDARD NATRULE @@ -8397,4 +8401,71 @@ sub initialize_switches() { } } +# +# Return ( action, level[:tag] ) from passed full action +# +sub split_action ( $ ) { + my $action = $_[0]; + + my @list = split_list2( $action, 'ACTION' ); + + fatal_error "Invalid ACTION ($action)" if @list > 3; + + ( shift @list, join( ':', @list ) ); +} + +# +# Get inline matches and conditionally verify the absense of -j +# +sub get_inline_matches( $ ) { + if ( $_[0] ) { + fetch_inline_matches; + } else { + my $inline_matches = fetch_inline_matches; + + fatal_error "-j is only allowed when the ACTION is INLINE with no parameter" if $inline_matches =~ /\s-j\s/; + + $inline_matches; + } +} + +# +# Split the passed target into the basic target and parameter (previously duplicated in this file) +# +sub get_target_param( $ ) { + my ( $target, $param ) = split '/', $_[0]; + + unless ( defined $param ) { + ( $target, $param ) = ( $1, $2 ) if $target =~ /^(.*?)[(](.*)[)]$/; + } + + ( $target, $param ); +} + +sub handle_inline( $$$$ ) { + my ( $action, $basictarget, $param, $loglevel ) = @_; + my $inline_matches = get_inline_matches(1); + my $raw_matches = ''; + + if ( $inline_matches =~ /^(.*\s+)?-j\s+(.+) $/ ) { + $raw_matches .= $1 if supplied $1; + $action = $2; + my ( $target ) = split ' ', $action; + fatal_error "Unknown jump target ($action)" unless $targets{$target} || $target eq 'MARK'; + fatal_error "INLINE may not have a parameter when '-j' is specified in the free-form area" if $param ne ''; + } else { + $raw_matches .= $inline_matches; + + if ( $param eq '' ) { + $action = $loglevel ? 'LOG' : ''; + } else { + ( $action, $loglevel ) = split_action $param; + ( $basictarget, $param ) = get_target_param $action; + $param = '' unless defined $param; + } + } + + return ( $action, $basictarget, $param, $loglevel, $raw_matches ); +} + 1; diff --git a/Shorewall/Perl/Shorewall/Compiler.pm b/Shorewall/Perl/Shorewall/Compiler.pm index a6ff12195..1002fffe2 100644 --- a/Shorewall/Perl/Shorewall/Compiler.pm +++ b/Shorewall/Perl/Shorewall/Compiler.pm @@ -581,8 +581,8 @@ EOF # sub compiler { - my ( $scriptfilename, $directory, $verbosity, $timestamp , $debug, $chains , $log , $log_verbosity, $preview, $confess , $update , $annotate , $convert, $config_path, $shorewallrc , $shorewallrc1 , $directives ) = - ( '', '', -1, '', 0, '', '', -1, 0, 0, 0, 0, , 0 , '' , '/usr/share/shorewall/shorewallrc', '' , 0 ); + my ( $scriptfilename, $directory, $verbosity, $timestamp , $debug, $chains , $log , $log_verbosity, $preview, $confess , $update , $annotate , $convert, $config_path, $shorewallrc , $shorewallrc1 , $directives, $inline ) = + ( '', '', -1, '', 0, '', '', -1, 0, 0, 0, 0, , 0 , '' , '/usr/share/shorewall/shorewallrc', '' , 0 , 0 ); $export = 0; $test = 0; @@ -620,6 +620,7 @@ sub compiler { update => { store => \$update, validate=> \&validate_boolean } , convert => { store => \$convert, validate=> \&validate_boolean } , annotate => { store => \$annotate, validate=> \&validate_boolean } , + inline => { store => \$inline, validate=> \&validate_boolean } , directives => { store => \$directives, validate=> \&validate_boolean } , config_path => { store => \$config_path } , shorewallrc => { store => \$shorewallrc } , @@ -659,7 +660,7 @@ sub compiler { # # S H O R E W A L L . C O N F A N D C A P A B I L I T I E S # - get_configuration( $export , $update , $annotate , $directives ); + get_configuration( $export , $update , $annotate , $directives , $inline ); # # Create a temp file to hold the script # diff --git a/Shorewall/Perl/Shorewall/Config.pm b/Shorewall/Perl/Shorewall/Config.pm index fafe964dd..5e09e4b19 100644 --- a/Shorewall/Perl/Shorewall/Config.pm +++ b/Shorewall/Perl/Shorewall/Config.pm @@ -70,7 +70,7 @@ our @EXPORT = qw( get_action_disposition set_action_disposition set_action_param - get_inline_matches + fetch_inline_matches set_inline_matches set_comment @@ -125,6 +125,7 @@ our %EXPORT_TAGS = ( internal => [ qw( create_temp_script split_list2 split_line split_line1 + split_line2 first_entry open_file close_file @@ -226,7 +227,7 @@ our %EXPORT_TAGS = ( internal => [ qw( create_temp_script Exporter::export_ok_tags('internal'); -our $VERSION = '4.5.20-Beta1'; +our $VERSION = '4.6.0-Beta1'; # # describe the current command, it's present progressive, and it's completion. @@ -553,6 +554,7 @@ our $warningcount; # Used to suppress duplicate warnings about missing our $warningcount1; # Used to suppress duplicate warnings about COMMENT being deprecated our $warningcount2; # Used to suppress duplicate warnings about FORMAT being deprecated our $warningcount3; # Used to suppress duplicate warnings about SECTION being deprecated +our $checkinline; # The -i option to check/compile/etc. our $shorewall_dir; # Shorewall Directory; if non-empty, search here first for files. @@ -833,6 +835,7 @@ sub initialize( $;$$) { CHAIN_SCRIPTS => undef, TRACK_RULES => undef, REJECT_ACTION => undef, + INLINE_MATCHES => undef, # # Packet Disposition # @@ -1982,6 +1985,57 @@ sub split_list3( $$ ) { @list2; } +sub split_columns( $ ) { + my ($list) = @_; + + return split ' ', $list unless $list =~ /\(/; + + my @list1 = split ' ', $list; + my @list2; + my $element = ''; + my $opencount = 0; + + for ( @list1 ) { + my $count; + + if ( ( $count = tr/(/(/ ) > 0 ) { + $opencount += $count; + if ( $element eq '' ) { + $element = $_; + } else { + $element = join( ',', $element, $_ ); + } + + if ( ( $count = tr/)/)/ ) > 0 ) { + if ( ! ( $opencount -= $count ) ) { + push @list2 , $element; + $element = ''; + } else { + fatal_error "Mismatched parentheses ($_)" if $opencount < 0; + } + } + } elsif ( ( $count = tr/)/)/ ) > 0 ) { + $element = join (',', $element, $_ ); + if ( ! ( $opencount -= $count ) ) { + push @list2 , $element; + $element = ''; + } else { + fatal_error "Mismatched parentheses ($_)" if $opencount < 0; + } + } elsif ( $element eq '' ) { + push @list2 , $_; + } else { + $element = join ',', $element , $_; + } + } + + unless ( $opencount == 0 ) { + fatal_error "Mismatched parentheses ($list)"; + } + + @list2; +} + # # Determine if a value has been supplied # @@ -1999,8 +2053,10 @@ sub supplied( $ ) { # Handles all of the supported forms of column/pair specification # Handles segragating raw iptables input in INLINE rules # -sub split_line1( $$;$$ ) { - my ( $description, $columnsref, $nopad, $maxcolumns ) = @_; +sub split_line2( $$;$$$ ) { + my ( $description, $columnsref, $nopad, $maxcolumns, $inline ) = @_; + + my $inlinematches = $config{INLINE_MATCHES}; unless ( defined $maxcolumns ) { my @maxcolumns = ( keys %$columnsref ); @@ -2019,7 +2075,9 @@ sub split_line1( $$;$$ ) { # fatal_error "Only one semicolon (';') allowed on a line" if defined $rest; - if ( $currentline =~ /^\s*INLINE(?:\(.*\)|:.*)?\s/) { + if ( $inlinematches ) { + fatal_error "The $description does not support inline matches (INLINE_MATCHES=Yes)" unless $inline; + $inline_matches = $pairs; if ( $columns =~ /^(\s*|.*[^&@%]){(.*)}\s*$/ ) { @@ -2031,6 +2089,26 @@ sub split_line1( $$;$$ ) { } else { $pairs = ''; } + } elsif ( $inline ) { + # + # This file supports INLINE + # + if ( $currentline =~ /^\s*INLINE(?:\(.*\)|:.*)?\s/) { + $inline_matches = $pairs; + + if ( $columns =~ /^(\s*|.*[^&@%]){(.*)}\s*$/ ) { + # + # Pairs are enclosed in curly brackets. + # + $columns = $1; + $pairs = $2; + } else { + warning_message "This entry needs to be changed before INLINE_MATCHES can be set to Yes" if $checkinline; + $pairs = ''; + } + } + } elsif ( $checkinline ) { + warning_message "This entry needs to be changed before INLINE_MATCHES can be set to Yes"; } } elsif ( $currentline =~ /^(\s*|.*[^&@%]){(.*)}$/ ) { # @@ -2045,7 +2123,7 @@ sub split_line1( $$;$$ ) { fatal_error "Shorewall Configuration file entries may not contain double quotes, single back quotes or backslashes" if $columns =~ /["`\\]/; fatal_error "Non-ASCII gunk in file" if $columns =~ /[^\s[:print:]]/; - my @line = split( ' ', $columns ); + my @line = split_columns( $columns ); $nopad = {} unless $nopad; @@ -2089,6 +2167,10 @@ sub split_line1( $$;$$ ) { @line; } +sub split_line1( $$;$$ ) { + &split_line2( @_, undef ); +} + sub split_line($$) { &split_line1( @_, {} ); } @@ -2989,7 +3071,7 @@ sub embedded_perl( $ ) { # # Return inline matches # -sub get_inline_matches() { +sub fetch_inline_matches() { "$inline_matches "; } @@ -5115,12 +5197,13 @@ sub convert_to_directives() { # writeable regular file # my $result = system << "EOF"; -perl -pi.bak -e '/^\\s*FORMAT\\s*/ && s/FORMAT/?FORMAT/; - if ( /^\\s*COMMENT\\s+/ ) { - s/COMMENT/?COMMENT/; - } elsif ( /^\\s*COMMENT\\s*\$/ ) { - s/COMMENT/?COMMENT/; - }' $file + perl -pi.bak -e '/^\\s*FORMAT\\s+/ && s/FORMAT/?FORMAT/; + /^\\s*SECTION\\s+/ && s/SECTION/?SECTION/; + if ( /^\\s*COMMENT\\s+/ ) { + s/COMMENT/?COMMENT/; + } elsif ( /^\\s*COMMENT\\s*\$/ ) { + s/COMMENT/?COMMENT/; + }' $file EOF if ( $result == 0 ) { if ( system( "diff -q $file ${file}.bak > /dev/null" ) ) { @@ -5131,7 +5214,7 @@ EOF warning message "Unable to rename ${file}.bak to $file:$!"; } } else { - warning_message ("Unable to update file ${file}.bak:$!" ); + warning_message ("Unable to update file $file" ); } } else { warning_message( "$file skipped (not writeable)" ) unless -d _; @@ -5151,9 +5234,9 @@ EOF # - Read the capabilities file, if any # - establish global hashes %params, %config , %globals and %capabilities # -sub get_configuration( $$$$ ) { +sub get_configuration( $$$$$ ) { - my ( $export, $update, $annotate, $directives ) = @_; + ( my ( $export, $update, $annotate, $directives ) , $checkinline ) = @_; $globals{EXPORT} = $export; @@ -5471,6 +5554,7 @@ sub get_configuration( $$$$ ) { default_yes_no 'MARK_IN_FORWARD_CHAIN' , ''; default_yes_no 'CHAIN_SCRIPTS' , 'Yes'; default_yes_no 'TRACK_RULES' , ''; + default_yes_no 'INLINE_MATCHES' , ''; if ( $val = $config{REJECT_ACTION} ) { fatal_error "Invalid Reject Action Name ($val)" unless $val =~ /^[a-zA-Z][\w-]*$/; diff --git a/Shorewall/Perl/Shorewall/Misc.pm b/Shorewall/Perl/Shorewall/Misc.pm index c64369b1d..501353e99 100644 --- a/Shorewall/Perl/Shorewall/Misc.pm +++ b/Shorewall/Perl/Shorewall/Misc.pm @@ -82,7 +82,9 @@ sub process_tos() { while ( read_a_line( NORMAL_READ ) ) { - my ($src, $dst, $proto, $ports, $sports , $tos, $mark ) = split_line 'tos file entry', { source => 0, dest => 1, proto => 2, dport => 3, sport => 4, tos => 5, mark => 6 } ; + my ($src, $dst, $proto, $ports, $sports , $tos, $mark ) = + split_line( 'tos file entry', + { source => 0, dest => 1, proto => 2, dport => 3, sport => 4, tos => 5, mark => 6 } ); $first_entry = 0; @@ -153,7 +155,10 @@ sub setup_ecn() while ( read_a_line( NORMAL_READ ) ) { - my ($interface, $hosts ) = split_line1 'ecn file entry', { interface => 0, host => 1, hosts => 1 }, {}, 2; + my ($interface, $hosts ) = split_line1( 'ecn file entry', + { interface => 0, host => 1, hosts => 1 }, + {}, + 2 ); fatal_error 'INTERFACE must be specified' if $interface eq '-'; fatal_error "Unknown interface ($interface)" unless known_interface $interface; @@ -240,7 +245,8 @@ sub setup_blacklist() { $first_entry = 0; } - my ( $networks, $protocol, $ports, $options ) = split_line 'blacklist file', { networks => 0, proto => 1, port => 2, options => 3 }; + my ( $networks, $protocol, $ports, $options ) = split_line( 'blacklist file', + { networks => 0, proto => 1, port => 2, options => 3 } ); if ( $options eq '-' ) { $options = 'src'; @@ -400,7 +406,9 @@ sub convert_blacklist() { first_entry "Converting $fn..."; while ( read_a_line( NORMAL_READ ) ) { - my ( $networks, $protocol, $ports, $options ) = split_line 'blacklist file', { networks => 0, proto => 1, port => 2, options => 3 }; + my ( $networks, $protocol, $ports, $options ) = + split_line( 'blacklist file', + { networks => 0, proto => 1, port => 2, options => 3 } ); if ( $options eq '-' ) { $options = 'src'; @@ -560,7 +568,8 @@ sub process_routestopped() { while ( read_a_line ( NORMAL_READ ) ) { my ($interface, $hosts, $options , $proto, $ports, $sports ) = - split_line 'routestopped file', { interface => 0, hosts => 1, options => 2, proto => 3, dport => 4, sport => 5 }; + split_line( 'routestopped file', + { interface => 0, hosts => 1, options => 2, proto => 3, dport => 4, sport => 5 } ); my $interfaceref; @@ -686,7 +695,8 @@ sub process_stoppedrules() { $result = 1; my ( $target, $source, $dest, $protos, $ports, $sports ) = - split_line1 'stoppedrules file', { target => 0, source => 1, dest => 2, proto => 3, dport => 4, sport => 5 }; + split_line1( 'stoppedrules file', + { target => 0, source => 1, dest => 2, proto => 3, dport => 4, sport => 5 } ); fatal_error( "Invalid TARGET ($target)" ) unless $target =~ /^(?:ACCEPT|NOTRACK)$/; @@ -1220,7 +1230,9 @@ sub setup_mac_lists( $ ) { while ( read_a_line( NORMAL_READ ) ) { - my ( $original_disposition, $interface, $mac, $addresses ) = split_line1 'maclist file', { disposition => 0, interface => 1, mac => 2, addresses => 3 }; + my ( $original_disposition, $interface, $mac, $addresses ) = + split_line1( 'maclist file', + { disposition => 0, interface => 1, mac => 2, addresses => 3 } ); my ( $disposition, $level, $remainder) = split( /:/, $original_disposition, 3 ); diff --git a/Shorewall/Perl/Shorewall/Nat.pm b/Shorewall/Perl/Shorewall/Nat.pm index c88c2efbe..2c85d3d0d 100644 --- a/Shorewall/Perl/Shorewall/Nat.pm +++ b/Shorewall/Perl/Shorewall/Nat.pm @@ -66,12 +66,22 @@ sub process_one_masq1( $$$$$$$$$$ ) my $add_snat_aliases = $family == F_IPV4 && $config{ADD_SNAT_ALIASES}; my $destnets = ''; my $baserule = ''; + my $inlinematches = ''; # # Leading '+' # $pre_nat = 1 if $interfacelist =~ s/^\+//; # + # Check for INLINE + # + if ( $interfacelist =~ /^INLINE\((.+)\)$/ ) { + $interfacelist = $1; + $inlinematches = get_inline_matches(0); + } elsif ( $config{INLINE_MATCHES} ) { + $inlinematches = get_inline_matches(0); + } + # # Parse the remaining part of the INTERFACE column # if ( $family == F_IPV4 ) { @@ -325,7 +335,7 @@ sub process_one_masq1( $$$$$$$$$$ ) expand_rule( $chainref , POSTROUTE_RESTRICT , '' , - $baserule . $rule , + $baserule . $inlinematches . $rule , $networks , $destnets , $origdest , @@ -366,7 +376,11 @@ sub process_one_masq1( $$$$$$$$$$ ) sub process_one_masq( ) { my ($interfacelist, $networks, $addresses, $protos, $ports, $ipsec, $mark, $user, $condition, $origdest ) = - split_line1 'masq file', { interface => 0, source => 1, address => 2, proto => 3, port => 4, ipsec => 5, mark => 6, user => 7, switch => 8, origdest => 9 }; + split_line2( 'masq file', + { interface => 0, source => 1, address => 2, proto => 3, port => 4, ipsec => 5, mark => 6, user => 7, switch => 8, origdest => 9 }, + {}, #Nopad + undef, #Columns + 1 ); #Allow inline matches fatal_error 'INTERFACE must be specified' if $interfacelist eq '-'; @@ -481,7 +495,9 @@ sub setup_nat() { while ( read_a_line( NORMAL_READ ) ) { - my ( $external, $interfacelist, $internal, $allints, $localnat ) = split_line1 'nat file', { external => 0, interface => 1, internal => 2, allints => 3, local => 4 }; + my ( $external, $interfacelist, $internal, $allints, $localnat ) = + split_line1( 'nat file', + { external => 0, interface => 1, internal => 2, allints => 3, local => 4 } ); ( $interfacelist, my $digit ) = split /:/, $interfacelist; @@ -511,7 +527,9 @@ sub setup_netmap() { while ( read_a_line( NORMAL_READ ) ) { - my ( $type, $net1, $interfacelist, $net2, $net3, $proto, $dport, $sport ) = split_line 'netmap file', { type => 0, net1 => 1, interface => 2, net2 => 3, net3 => 4, proto => 5, dport => 6, sport => 7 }; + my ( $type, $net1, $interfacelist, $net2, $net3, $proto, $dport, $sport ) = + split_line( 'netmap file', + { type => 0, net1 => 1, interface => 2, net2 => 3, net3 => 4, proto => 5, dport => 6, sport => 7 } ); $net3 = ALLIP if $net3 eq '-'; diff --git a/Shorewall/Perl/Shorewall/Providers.pm b/Shorewall/Perl/Shorewall/Providers.pm index ce172f346..dd12d1ced 100644 --- a/Shorewall/Perl/Shorewall/Providers.pm +++ b/Shorewall/Perl/Shorewall/Providers.pm @@ -416,7 +416,8 @@ sub process_a_provider( $ ) { my $pseudo = $_[0]; # When true, this is an optional interface that we are treating somewhat like a provider. my ($table, $number, $mark, $duplicate, $interface, $gateway, $options, $copy ) = - split_line 'providers file', { table => 0, number => 1, mark => 2, duplicate => 3, interface => 4, gateway => 5, options => 6, copy => 7 }; + split_line('providers file', + { table => 0, number => 1, mark => 2, duplicate => 3, interface => 4, gateway => 5, options => 6, copy => 7 } ); fatal_error "Duplicate provider ($table)" if $providers{$table}; @@ -1047,7 +1048,9 @@ CEOF } sub add_an_rtrule( ) { - my ( $source, $dest, $provider, $priority, $originalmark ) = split_line 'rtrules file', { source => 0, dest => 1, provider => 2, priority => 3 , mark => 4 }; + my ( $source, $dest, $provider, $priority, $originalmark ) = + split_line( 'rtrules file', + { source => 0, dest => 1, provider => 2, priority => 3 , mark => 4 } ); our $current_if; @@ -1137,7 +1140,9 @@ sub add_an_rtrule( ) { } sub add_a_route( ) { - my ( $provider, $dest, $gateway, $device ) = split_line 'routes file', { provider => 0, dest => 1, gateway => 2, device => 3 }; + my ( $provider, $dest, $gateway, $device ) = + split_line( 'routes file', + { provider => 0, dest => 1, gateway => 2, device => 3 } ); our $current_if; diff --git a/Shorewall/Perl/Shorewall/Proxyarp.pm b/Shorewall/Perl/Shorewall/Proxyarp.pm index 2f7d9a4f3..02ab531f7 100644 --- a/Shorewall/Perl/Shorewall/Proxyarp.pm +++ b/Shorewall/Perl/Shorewall/Proxyarp.pm @@ -123,7 +123,9 @@ sub setup_proxy_arp() { while ( read_a_line( NORMAL_READ ) ) { my ( $address, $interface, $external, $haveroute, $persistent ) = - split_line $file_opt . 'file ', { address => 0, interface => 1, external => 2, haveroute => 3, persistent => 4 }; + split_line( $file_opt . + 'file ', + { address => 0, interface => 1, external => 2, haveroute => 3, persistent => 4 } ); if ( $first_entry ) { progress_message2 "$doing $fn..."; diff --git a/Shorewall/Perl/Shorewall/Raw.pm b/Shorewall/Perl/Shorewall/Raw.pm index 20de9dec2..e867d10ef 100644 --- a/Shorewall/Perl/Shorewall/Raw.pm +++ b/Shorewall/Perl/Shorewall/Raw.pm @@ -240,7 +240,9 @@ sub setup_conntrack() { my ( $source, $dest, $protos, $ports, $sports, $user, $switch ); if ( $file_format == 1 ) { - ( $source, $dest, $protos, $ports, $sports, $user, $switch ) = split_line1 'Conntrack File', { source => 0, dest => 1, proto => 2, dport => 3, sport => 4, user => 5, switch => 6 }; + ( $source, $dest, $protos, $ports, $sports, $user, $switch ) = + split_line1( 'Conntrack File', + { source => 0, dest => 1, proto => 2, dport => 3, sport => 4, user => 5, switch => 6 } ); $action = 'NOTRACK'; } else { ( $action, $source, $dest, $protos, $ports, $sports, $user, $switch ) = split_line1 'Conntrack File', { action => 0, source => 1, dest => 2, proto => 3, dport => 4, sport => 5, user => 6, switch => 7 }; diff --git a/Shorewall/Perl/Shorewall/Rules.pm b/Shorewall/Perl/Shorewall/Rules.pm index 2c6805307..39bcb56cd 100644 --- a/Shorewall/Perl/Shorewall/Rules.pm +++ b/Shorewall/Perl/Shorewall/Rules.pm @@ -299,19 +299,6 @@ sub new_rules_chain( $ ) { ############################################################################### # Functions moved from the former Policy Module ############################################################################### -# -# Split the passed target into the basic target and parameter (previously duplicated in this file) -# -sub get_target_param( $ ) { - my ( $target, $param ) = split '/', $_[0]; - - unless ( defined $param ) { - ( $target, $param ) = ( $1, $2 ) if $target =~ /^(.*?)[(](.*)[)]$/; - } - - ( $target, $param ); -} - # # Convert a chain into a policy chain. # @@ -1104,19 +1091,6 @@ sub finish_section ( $ ) { ################################################################################ # Functions moved from the Actions module in 4.4.16 ################################################################################ -# -# Return ( action, level[:tag] ) from passed full action -# -sub split_action ( $ ) { - my $action = $_[0]; - - my @list = split_list2( $action, 'ACTION' ); - - fatal_error "Invalid ACTION ($action)" if @list > 3; - - ( shift @list, join( ':', @list ) ); -} - # # Create a normalized action name from the passed pieces. # @@ -1675,11 +1649,16 @@ sub process_action($$) { if ( $file_format == 1 ) { ($target, $source, $dest, $proto, $ports, $sports, $rate, $user, $mark ) = - split_line1 'action file', { target => 0, source => 1, dest => 2, proto => 3, dport => 4, sport => 5, rate => 6, user => 7, mark => 8 }, $rule_commands; + split_line1( + 'action file', + { target => 0, source => 1, dest => 2, proto => 3, dport => 4, sport => 5, rate => 6, user => 7, mark => 8 }, + $rule_commands ); $origdest = $connlimit = $time = $headers = $condition = $helper = '-'; } else { ($target, $source, $dest, $proto, $ports, $sports, $origdest, $rate, $user, $mark, $connlimit, $time, $headers, $condition, $helper ) - = split_line1 'action file', \%rulecolumns, $action_commands; + = split_line1( 'action file', + \%rulecolumns, + $action_commands ); } fatal_error 'TARGET must be specified' if $target eq '-'; @@ -1746,7 +1725,11 @@ sub process_actions() { open_file( $file, 2 ); while ( read_a_line( NORMAL_READ ) ) { - my ( $action, $options ) = split_line 'action file' , { action => 0, options => 1 }; + my ( $action, $options ) = split_line2( 'action file', + { action => 0, options => 1 }, + {}, #Nopad + undef, #Columns + 1 ); #Allow inline matches my $type = ( $action eq $config{REJECT_ACTION} ? INLINE : ACTION ); my $noinline = 0; @@ -1889,7 +1872,12 @@ sub process_macro ($$$$$$$$$$$$$$$$$$$$) { my ( $mtarget, $msource, $mdest, $mproto, $mports, $msports, $morigdest, $mrate, $muser, $mmark, $mconnlimit, $mtime, $mheaders, $mcondition, $mhelper); if ( $file_format == 1 ) { - ( $mtarget, $msource, $mdest, $mproto, $mports, $msports, $mrate, $muser ) = split_line1 'macro file', \%rulecolumns, $rule_commands; + ( $mtarget, $msource, $mdest, $mproto, $mports, $msports, $mrate, $muser ) = + split_line2( 'macro file', + \%rulecolumns, + $rule_commands, + undef, #Columns + 1 ); #Allow inline matches ( $morigdest, $mmark, $mconnlimit, $mtime, $mheaders, $mcondition, $mhelper ) = qw/- - - - - - -/; } else { ( $mtarget, @@ -1906,7 +1894,11 @@ sub process_macro ($$$$$$$$$$$$$$$$$$$$) { $mtime, $mheaders, $mcondition, - $mhelper ) = split_line1 'macro file', \%rulecolumns, $rule_commands; + $mhelper ) = split_line2( 'macro file', + \%rulecolumns, + $rule_commands, + undef, #Columns + 1 ); #Allow inline matches } fatal_error 'TARGET must be specified' if $mtarget eq '-'; @@ -2031,7 +2023,12 @@ sub process_inline ($$$$$$$$$$$$$$$$$$$$$) { $mtime, $mheaders, $mcondition, - $mhelper ) = split_line1 'inline action file', \%rulecolumns, $rule_commands; + $mhelper ) = split_line2( 'inline action file', + \%rulecolumns, + $rule_commands, + undef, #Columns + 1 ); #Allow inline matches + fatal_error 'TARGET must be specified' if $mtarget eq '-'; @@ -2156,7 +2153,7 @@ sub process_rule ( $$$$$$$$$$$$$$$$$$$ ) { my ( $basictarget, $param ) = get_target_param $action; my $optimize = $wildcard ? ( $basictarget =~ /!$/ ? 0 : $config{OPTIMIZE} & 5 ) : 0; my $actiontype; - my $inaction = ''; # Set to true when we are process rules in an action file + my $inaction = ''; # Set to true when we are processing rules in an action file my $inchain = ''; # Set to true when a chain reference is passed. my $normalized_target; my $normalized_action; @@ -2171,25 +2168,9 @@ sub process_rule ( $$$$$$$$$$$$$$$$$$$ ) { $param = '' unless defined $param; if ( $basictarget eq 'INLINE' ) { - my $inline_matches = get_inline_matches; - - if ( $inline_matches =~ /^(.*\s+)?-j\s+(.+) $/ ) { - $raw_matches .= $1 if supplied $1; - $action = $2; - my ( $target ) = split ' ', $action; - fatal_error "Unknown jump target ($action)" unless $targets{$target} || $target eq 'MARK'; - fatal_error "INLINE may not have a parameter when '-j' is specified in the free-form area" if $param ne ''; - } else { - $raw_matches .= $inline_matches; - - if ( $param eq '' ) { - $action = $loglevel ? 'LOG' : ''; - } else { - ( $action, $loglevel ) = split_action $param; - ( $basictarget, $param ) = get_target_param $action; - $param = '' unless defined $param; - } - } + ( $action, $basictarget, $param, $loglevel, $raw_matches ) = handle_inline( $action, $basictarget, $param, $loglevel ); + } elsif ( $config{INLINE_MATCHES} ) { + $raw_matches = get_inline_matches(0); } # # Determine the validity of the action @@ -3116,7 +3097,12 @@ sub build_zone_list( $$$\$\$ ) { # sub process_raw_rule ( ) { my ( $target, $source, $dest, $protos, $ports, $sports, $origdest, $ratelimit, $users, $mark, $connlimit, $time, $headers, $condition, $helper ) - = split_line1 'rules file', \%rulecolumns, $rule_commands; + = split_line2( 'rules file', + \%rulecolumns, + $rule_commands, + undef, #Columns + 1 ); #Allow inline matches + fatal_error 'ACTION must be specified' if $target eq '-'; diff --git a/Shorewall/Perl/Shorewall/Tc.pm b/Shorewall/Perl/Shorewall/Tc.pm index 433d5add9..99db00408 100644 --- a/Shorewall/Perl/Shorewall/Tc.pm +++ b/Shorewall/Perl/Shorewall/Tc.pm @@ -207,7 +207,7 @@ sub initialize( $ ) { sub process_tc_rule1( $$$$$$$$$$$$$$$$ ) { my ( $originalmark, $source, $dest, $proto, $ports, $sports, $user, $testval, $length, $tos , $connbytes, $helper, $headers, $probability , $dscp , $state ) = @_; -our %tccmd; + our %tccmd; unless ( %tccmd ) { %tccmd = ( SAVE => { match => sub ( $ ) { $_[0] eq 'SAVE' } , @@ -316,6 +316,16 @@ our %tccmd; fatal_error 'MARK must be specified' if $originalmark eq '-'; + my $raw = ''; + + if ( $originalmark =~ /^INLINE\((.+)\)(:.*)?$/ ) { + $originalmark = $1; + $originalmark .= $2 if $2; + $raw = get_inline_matches(0); + } elsif ( $config{INLINE_MATCHES} ) { + $raw = get_inline_matches(0); + } + my ( $mark, $designator, $remainder ) = split( /:/, $originalmark, 3 ); fatal_error "Invalid MARK ($originalmark)" unless supplied $mark; @@ -555,11 +565,14 @@ our %tccmd; INLINE => sub() { assert ( $cmd eq 'INLINE' ); - $matches = get_inline_matches; + $matches = get_inline_matches(1); - if ( $matches =~ /^(.*\s+)-j\s+(.+) $/ ) { - $matches = $1; - $target = $2; + if ( $matches =~ /^(.*\s+)-j\s+(.+)$/ ) { + $matches = $1; + $target = $2; + my $action = $target; + $action = $1 if $action =~ /^(.+?)\s/; + fatal_error "Unknown target ($action)" unless $targets{$action} || $builtin_target{$action}; } else { $target = ''; } @@ -816,11 +829,19 @@ sub process_tc_rule( ) { my ( $originalmark, $source, $dest, $protos, $ports, $sports, $user, $testval, $length, $tos , $connbytes, $helper, $headers, $probability , $dscp , $state ); if ( $family == F_IPV4 ) { ( $originalmark, $source, $dest, $protos, $ports, $sports, $user, $testval, $length, $tos , $connbytes, $helper, $probability, $dscp, $state ) = - split_line1 'tcrules file', { mark => 0, action => 0, source => 1, dest => 2, proto => 3, dport => 4, sport => 5, user => 6, test => 7, length => 8, tos => 9, connbytes => 10, helper => 11, probability => 12 , dscp => 13, state => 14 }, {}, 15; + split_line2( 'tcrules file', + { mark => 0, action => 0, source => 1, dest => 2, proto => 3, dport => 4, sport => 5, user => 6, test => 7, length => 8, tos => 9, connbytes => 10, helper => 11, probability => 12 , dscp => 13, state => 14 }, + {}, + 15, + 1 ); $headers = '-'; } else { ( $originalmark, $source, $dest, $protos, $ports, $sports, $user, $testval, $length, $tos , $connbytes, $helper, $headers, $probability, $dscp, $state ) = - split_line1 'tcrules file', { mark => 0, action => 0, source => 1, dest => 2, proto => 3, dport => 4, sport => 5, user => 6, test => 7, length => 8, tos => 9, connbytes => 10, helper => 11, headers => 12, probability => 13 , dscp => 14 , state => 15 }, {}, 16; + split_line2( 'tcrules file', + { mark => 0, action => 0, source => 1, dest => 2, proto => 3, dport => 4, sport => 5, user => 6, test => 7, length => 8, tos => 9, connbytes => 10, helper => 11, headers => 12, probability => 13 , dscp => 14 , state => 15 }, + {}, + 16, + 1 ); } for my $proto (split_list( $protos, 'Protocol' ) ) { @@ -947,7 +968,9 @@ sub process_flow($) { } sub process_simple_device() { - my ( $device , $type , $in_rate , $out_part ) = split_line 'tcinterfaces', { interface => 0, type => 1, in_bandwidth => 2, out_bandwidth => 3 }; + my ( $device , $type , $in_rate , $out_part ) = + split_line( 'tcinterfaces', + { interface => 0, type => 1, in_bandwidth => 2, out_bandwidth => 3 } ); fatal_error 'INTERFACE must be specified' if $device eq '-'; fatal_error "Duplicate INTERFACE ($device)" if $tcdevices{$device}; @@ -1076,7 +1099,9 @@ sub process_simple_device() { my %validlinklayer = ( ethernet => 1, atm => 1, adsl => 1 ); sub validate_tc_device( ) { - my ( $device, $inband, $outband , $options , $redirected ) = split_line 'tcdevices', { interface => 0, in_bandwidth => 1, out_bandwidth => 2, options => 3, redirect => 4 }; + my ( $device, $inband, $outband , $options , $redirected ) = + split_line( 'tcdevices', + { interface => 0, in_bandwidth => 1, out_bandwidth => 2, options => 3, redirect => 4 } ); fatal_error 'INTERFACE must be specified' if $device eq '-'; fatal_error "Invalid tcdevices entry" if $outband eq '-'; @@ -1287,7 +1312,8 @@ sub validate_filter_priority( $$ ) { sub validate_tc_class( ) { my ( $devclass, $mark, $rate, $ceil, $prio, $options ) = - split_line 'tcclasses file', { interface => 0, mark => 1, rate => 2, ceil => 3, prio => 4, options => 5 }; + split_line( 'tcclasses file', + { interface => 0, mark => 1, rate => 2, ceil => 3, prio => 4, options => 5 } ); my $classnumber = 0; my $devref; my $device = $devclass; @@ -1950,7 +1976,8 @@ sub process_tc_filter1( $$$$$$$$$ ) { sub process_tc_filter() { my ( $devclass, $source, $dest , $protos, $portlist , $sportlist, $tos, $length, $priority ) - = split_line 'tcfilters file', { class => 0, source => 1, dest => 2, proto => 3, dport => 4, sport => 5, tos => 6, length => 7 , priority => 8 }; + = split_line( 'tcfilters file', + { class => 0, source => 1, dest => 2, proto => 3, dport => 4, sport => 5, tos => 6, length => 7 , priority => 8 } ); fatal_error 'CLASS must be specified' if $devclass eq '-'; @@ -2049,7 +2076,9 @@ sub process_tc_priority1( $$$$$$ ) { } sub process_tc_priority() { - my ( $band, $protos, $ports , $address, $interface, $helper ) = split_line1 'tcpri', { band => 0, proto => 1, port => 2, address => 3, interface => 4, helper => 5 }; + my ( $band, $protos, $ports , $address, $interface, $helper ) = + split_line1( 'tcpri', + { band => 0, proto => 1, port => 2, address => 3, interface => 4, helper => 5 } ); fatal_error 'BAND must be specified' if $band eq '-'; @@ -2493,7 +2522,8 @@ sub process_secmark_rule1( $$$$$$$$$ ) { # sub process_secmark_rule() { my ( $secmark, $chainin, $source, $dest, $protos, $dport, $sport, $user, $mark ) = - split_line1( 'Secmarks file' , { secmark => 0, chain => 1, source => 2, dest => 3, proto => 4, dport => 5, sport => 6, user => 7, mark => 8 } ); + split_line1( 'Secmarks file' , + { secmark => 0, chain => 1, source => 2, dest => 3, proto => 4, dport => 5, sport => 6, user => 7, mark => 8 } ); fatal_error 'SECMARK must be specified' if $secmark eq '-'; diff --git a/Shorewall/Perl/Shorewall/Tunnels.pm b/Shorewall/Perl/Shorewall/Tunnels.pm index 35c2a0083..2900bddab 100644 --- a/Shorewall/Perl/Shorewall/Tunnels.pm +++ b/Shorewall/Perl/Shorewall/Tunnels.pm @@ -291,7 +291,11 @@ sub setup_tunnels() { while ( read_a_line( NORMAL_READ ) ) { - my ( $kind, $zone, $gateway, $gatewayzones ) = split_line1 'tunnels file', { type => 0, zone => 1, gateway => 2, gateways => 2, gateway_zone => 3 , gateway_zones => 3 }, {}, 4; + my ( $kind, $zone, $gateway, $gatewayzones ) = + split_line1( 'tunnels file', + { type => 0, zone => 1, gateway => 2, gateways => 2, gateway_zone => 3 , gateway_zones => 3 }, + {}, + 4 ); fatal_error 'TYPE must be specified' if $kind eq '-'; diff --git a/Shorewall/Perl/Shorewall/Zones.pm b/Shorewall/Perl/Shorewall/Zones.pm index d5a43a2aa..d96e4d0dd 100644 --- a/Shorewall/Perl/Shorewall/Zones.pm +++ b/Shorewall/Perl/Shorewall/Zones.pm @@ -503,7 +503,8 @@ sub process_zone( \$ ) { my @parents; my ($zone, $type, $options, $in_options, $out_options ) = - split_line 'zones file', { zone => 0, type => 1, options => 2, in_options => 3, out_options => 4 }; + split_line( 'zones file', + { zone => 0, type => 1, options => 2, in_options => 3, out_options => 4 } ); fatal_error 'ZONE must be specified' if $zone eq '-'; @@ -1079,9 +1080,12 @@ sub process_interface( $$ ) { my $bridge = ''; if ( $file_format == 1 ) { - ($zone, $originalinterface, $bcasts, $options ) = split_line1 'interfaces file', { zone => 0, interface => 1, broadcast => 2, options => 3 }; + ($zone, $originalinterface, $bcasts, $options ) = + split_line1( 'interfaces file', + { zone => 0, interface => 1, broadcast => 2, options => 3 } ); } else { - ($zone, $originalinterface, $options ) = split_line1 'interfaces file', { zone => 0, interface => 1, options => 2 }; + ($zone, $originalinterface, $options ) = split_line1( 'interfaces file', + { zone => 0, interface => 1, options => 2 } ); $bcasts = '-'; } @@ -1939,7 +1943,10 @@ sub verify_required_interfaces( $ ) { # sub process_host( ) { my $ipsec = 0; - my ($zone, $hosts, $options ) = split_line1 'hosts file', { zone => 0, host => 1, hosts => 1, options => 2 }, {}, 3; + my ($zone, $hosts, $options ) = split_line1( 'hosts file', + { zone => 0, host => 1, hosts => 1, options => 2 }, + {}, + 3 ); fatal_error 'ZONE must be specified' if $zone eq '-'; fatal_error 'HOSTS must be specified' if $hosts eq '-'; diff --git a/Shorewall/Perl/compiler.pl b/Shorewall/Perl/compiler.pl index 3e614e6f5..1541c0b74 100755 --- a/Shorewall/Perl/compiler.pl +++ b/Shorewall/Perl/compiler.pl @@ -40,6 +40,7 @@ # --shorewallrc= # Path to global shorewallrc file. # --shorewallrc1= # Path to export shorewallrc file. # --config_path= # Search path for config files +# --inline # Update alternative column specifications # use strict; use FindBin; @@ -73,10 +74,10 @@ usage: compiler.pl [