From f6092ee52dfaab3e359e26612f9d69bd43b08002 Mon Sep 17 00:00:00 2001 From: Tom Eastep Date: Sat, 1 Oct 2011 11:39:12 -0700 Subject: [PATCH] Eliminate the maxcolumns argument to the split_line functions Signed-off-by: Tom Eastep --- Shorewall/Perl/Shorewall/Accounting.pm | 2 +- Shorewall/Perl/Shorewall/Config.pm | 14 ++++++++++---- Shorewall/Perl/Shorewall/Misc.pm | 10 +++++----- Shorewall/Perl/Shorewall/Nat.pm | 6 +++--- Shorewall/Perl/Shorewall/Providers.pm | 6 +++--- Shorewall/Perl/Shorewall/Proxyarp.pm | 2 +- Shorewall/Perl/Shorewall/Raw.pm | 2 +- Shorewall/Perl/Shorewall/Rules.pm | 14 +++++++------- Shorewall/Perl/Shorewall/Tc.pm | 14 +++++++------- Shorewall/Perl/Shorewall/Tunnels.pm | 2 +- Shorewall/Perl/Shorewall/Zones.pm | 6 +++--- 11 files changed, 42 insertions(+), 36 deletions(-) diff --git a/Shorewall/Perl/Shorewall/Accounting.pm b/Shorewall/Perl/Shorewall/Accounting.pm index e15ee581d..df9e5a779 100644 --- a/Shorewall/Perl/Shorewall/Accounting.pm +++ b/Shorewall/Perl/Shorewall/Accounting.pm @@ -142,7 +142,7 @@ sub process_accounting_rule( ) { $jumpchainref = 0; my ($action, $chain, $source, $dest, $proto, $ports, $sports, $user, $mark, $ipsec, $headers ) = - split_line1 11, 'Accounting File', { action => 0, chain => 1, source => 2, dest => 3, proto => 4, dport => 5, sport => 6, user => 7, mark => 8, ipsec => 9, headers => 10 }, $accounting_commands; + 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 }, $accounting_commands; fatal_error 'ACTION must be specified' if $action eq '-'; diff --git a/Shorewall/Perl/Shorewall/Config.pm b/Shorewall/Perl/Shorewall/Config.pm index 1ded27aac..03f82f11a 100644 --- a/Shorewall/Perl/Shorewall/Config.pm +++ b/Shorewall/Perl/Shorewall/Config.pm @@ -1338,8 +1338,11 @@ sub supplied( $ ) { # ensure that it has an appropriate number of columns. # supply '-' in omitted trailing columns. # -sub split_line( $$$ ) { - my ( $maxcolumns, $description, $columnsref ) = @_; +sub split_line( $$ ) { + my ( $description, $columnsref ) = @_; + + my @maxcolumns = ( keys %$columnsref ); + my $maxcolumns = @maxcolumns; my ( $columns, $pairs, $rest ) = split( ';', $currentline ); @@ -1376,8 +1379,11 @@ sub split_line( $$$ ) { # # Version of 'split_line' used on files with exceptions # -sub split_line1( $$$;$ ) { - my ( $maxcolumns, $description, $columnsref, $nopad) = @_; +sub split_line1( $$;$ ) { + my ( $description, $columnsref, $nopad) = @_; + + my @maxcolumns = ( keys %$columnsref ); + my $maxcolumns = @maxcolumns; my ( $columns, $pairs, $rest ) = split( ';', $currentline ); diff --git a/Shorewall/Perl/Shorewall/Misc.pm b/Shorewall/Perl/Shorewall/Misc.pm index ab8685bed..b7dd639ce 100644 --- a/Shorewall/Perl/Shorewall/Misc.pm +++ b/Shorewall/Perl/Shorewall/Misc.pm @@ -82,7 +82,7 @@ sub process_tos() { while ( read_a_line ) { - my ($src, $dst, $proto, $ports, $sports , $tos, $mark ) = split_line 7, '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; @@ -159,7 +159,7 @@ sub setup_ecn() while ( read_a_line ) { - my ($interface, $hosts ) = split_line 2, 'ecn file entry', { interface => 0, hosts => 1 }; + my ($interface, $hosts ) = split_line 'ecn file entry', { interface => 0, hosts => 1 }; fatal_error 'INTERFACE must be specified' if $interface eq '-'; fatal_error "Unknown interface ($interface)" unless known_interface $interface; @@ -257,7 +257,7 @@ sub setup_blacklist() { $first_entry = 0; } - my ( $networks, $protocol, $ports, $options ) = split_line 4, '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'; @@ -360,7 +360,7 @@ sub process_routestopped() { while ( read_a_line ) { my ($interface, $hosts, $options , $proto, $ports, $sports ) = - split_line 6, 'routestopped file', { interface => 1, hosts => 2, options => 3, proto => 4, dport => 5, sport => 6 }; + split_line 'routestopped file', { interface => 1, hosts => 2, options => 3, proto => 4, dport => 5, sport => 6 }; my $interfaceref; @@ -900,7 +900,7 @@ sub setup_mac_lists( $ ) { while ( read_a_line ) { - my ( $original_disposition, $interface, $mac, $addresses ) = split_line1 4, '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 }; if ( $original_disposition eq 'COMMENT' ) { process_comment; diff --git a/Shorewall/Perl/Shorewall/Nat.pm b/Shorewall/Perl/Shorewall/Nat.pm index 99b28c92d..bec89ed9a 100644 --- a/Shorewall/Perl/Shorewall/Nat.pm +++ b/Shorewall/Perl/Shorewall/Nat.pm @@ -55,7 +55,7 @@ sub initialize() { sub process_one_masq( ) { my ($interfacelist, $networks, $addresses, $proto, $ports, $ipsec, $mark, $user ) = - split_line1 8, 'masq file', { interface => 0, source => 1, address => 2, proto => 3, port => 4, ipsec => 5, mark => 6, user => 7 }; + split_line1 'masq file', { interface => 0, source => 1, address => 2, proto => 3, port => 4, ipsec => 5, mark => 6, user => 7 }; if ( $interfacelist eq 'COMMENT' ) { process_comment; @@ -377,7 +377,7 @@ sub setup_nat() { while ( read_a_line ) { - my ( $external, $interfacelist, $internal, $allints, $localnat ) = split_line1 5, 'nat file', { external => 1, interface => 1, internal => 2, allints => 3, localnat => 4 }; + my ( $external, $interfacelist, $internal, $allints, $localnat ) = split_line1 'nat file', { external => 1, interface => 1, internal => 2, allints => 3, localnat => 4 }; if ( $external eq 'COMMENT' ) { process_comment; @@ -413,7 +413,7 @@ sub setup_netmap() { while ( read_a_line ) { - my ( $type, $net1, $interfacelist, $net2, $net3, $proto, $dport, $sport ) = split_line 8, 'netmap file', { type => 0, net1 => 1, interface => 2, net2 => 3, net3 => 4, proto => 4, dport => 5, sport => 6 }; + my ( $type, $net1, $interfacelist, $net2, $net3, $proto, $dport, $sport ) = split_line 'netmap file', { type => 0, net1 => 1, interface => 2, net2 => 3, net3 => 4, proto => 4, dport => 5, sport => 6 }; $net3 = ALLIP if $net3 eq '-'; diff --git a/Shorewall/Perl/Shorewall/Providers.pm b/Shorewall/Perl/Shorewall/Providers.pm index 07f622c81..f551b4746 100644 --- a/Shorewall/Perl/Shorewall/Providers.pm +++ b/Shorewall/Perl/Shorewall/Providers.pm @@ -268,7 +268,7 @@ sub start_provider( $$$ ) { sub process_a_provider() { my ($table, $number, $mark, $duplicate, $interface, $gateway, $options, $copy ) = - split_line 8, '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}; @@ -734,7 +734,7 @@ sub add_a_provider( $$ ) { } sub add_an_rtrule( ) { - my ( $source, $dest, $provider, $priority ) = split_line 4, 'route_rules file', { source => 0, dest => 1, provider => 2, priority => 3 }; + my ( $source, $dest, $provider, $priority ) = split_line 'route_rules file', { source => 0, dest => 1, provider => 2, priority => 3 }; our $current_if; @@ -809,7 +809,7 @@ sub add_an_rtrule( ) { } sub add_a_route( ) { - my ( $provider, $dest, $gateway, $device ) = split_line 4, '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 457fc3689..241bbd111 100644 --- a/Shorewall/Perl/Shorewall/Proxyarp.pm +++ b/Shorewall/Perl/Shorewall/Proxyarp.pm @@ -123,7 +123,7 @@ sub setup_proxy_arp() { while ( read_a_line ) { my ( $address, $interface, $external, $haveroute, $persistent ) = - split_line 5, { address => 0, interface => 1, external => 2, haveroute => 3, persistent => 4 }, $file_opt; + 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 a4b368091..e04401b66 100644 --- a/Shorewall/Perl/Shorewall/Raw.pm +++ b/Shorewall/Perl/Shorewall/Raw.pm @@ -84,7 +84,7 @@ sub setup_notrack() { while ( read_a_line ) { - my ( $source, $dest, $proto, $ports, $sports, $user ) = split_line1 6, 'Notrack File', { source => 0, dest => 1, proto => 2, dport => 3, sport => 4, user => 5 }; + my ( $source, $dest, $proto, $ports, $sports, $user ) = split_line1 'Notrack File', { source => 0, dest => 1, proto => 2, dport => 3, sport => 4, user => 5 }; if ( $source eq 'COMMENT' ) { process_comment; diff --git a/Shorewall/Perl/Shorewall/Rules.pm b/Shorewall/Perl/Shorewall/Rules.pm index c90d500ac..afcb260ef 100644 --- a/Shorewall/Perl/Shorewall/Rules.pm +++ b/Shorewall/Perl/Shorewall/Rules.pm @@ -313,7 +313,7 @@ sub process_a_policy() { our @zonelist; my ( $client, $server, $originalpolicy, $loglevel, $synparams, $connlimit ) = - split_line 6, 'policy file', { source => 0, dest => 1, policy => 2, loglevel => 3, limit => 4, connlimit => 5 } ; + split_line 'policy file', { source => 0, dest => 1, policy => 2, loglevel => 3, limit => 4, connlimit => 5 } ; $loglevel = '' if $loglevel eq '-'; $synparams = '' if $synparams eq '-'; @@ -1374,7 +1374,7 @@ sub process_actions() { open_file $file; while ( read_a_line ) { - my ( $action ) = split_line 1, 'action file' , { action => 0 }; + my ( $action ) = split_line 'action file' , { action => 0 }; if ( $action =~ /:/ ) { warning_message 'Default Actions are now specified in /etc/shorewall/shorewall.conf'; @@ -1438,11 +1438,11 @@ sub process_action( $) { my ($target, $source, $dest, $proto, $ports, $sports, $origdest, $rate, $user, $mark, $connlimit, $time, $headers, $condition ); if ( $format == 1 ) { - ($target, $source, $dest, $proto, $ports, $sports, $rate, $user, $mark ) = split_line1 9, 'action file', $rule_commands, {}; + ($target, $source, $dest, $proto, $ports, $sports, $rate, $user, $mark ) = split_line1 'action file', $rule_commands; $origdest = $connlimit = $time = $headers = $condition = '-'; } else { ($target, $source, $dest, $proto, $ports, $sports, $origdest, $rate, $user, $mark, $connlimit, $time, $headers, $condition ) - = split_line1 14, 'action file', \%rulecolumns, $action_commands; + = split_line1 'action file', \%rulecolumns, $action_commands; } fatal_error 'TARGET must be specified' if $target eq '-'; @@ -1530,10 +1530,10 @@ sub process_macro ( $$$$$$$$$$$$$$$$$$ ) { my ( $mtarget, $msource, $mdest, $mproto, $mports, $msports, $morigdest, $mrate, $muser, $mmark, $mconnlimit, $mtime, $mheaders, $mcondition ); if ( $format == 1 ) { - ( $mtarget, $msource, $mdest, $mproto, $mports, $msports, $mrate, $muser ) = split_line1 8, 'macro file', \%rulecolumns, $rule_commands; + ( $mtarget, $msource, $mdest, $mproto, $mports, $msports, $mrate, $muser ) = split_line1 'macro file', \%rulecolumns, $rule_commands; ( $morigdest, $mmark, $mconnlimit, $mtime, $mheaders, $mcondition ) = qw/- - - - - -/; } else { - ( $mtarget, $msource, $mdest, $mproto, $mports, $msports, $morigdest, $mrate, $muser, $mmark, $mconnlimit, $mtime, $mheaders, $mcondition ) = split_line1 14, 'macro file', \%rulecolumns, $rule_commands; + ( $mtarget, $msource, $mdest, $mproto, $mports, $msports, $morigdest, $mrate, $muser, $mmark, $mconnlimit, $mtime, $mheaders, $mcondition ) = split_line1 'macro file', \%rulecolumns, $rule_commands; } fatal_error 'TARGET must be specified' if $mtarget eq '-'; @@ -2346,7 +2346,7 @@ sub build_zone_list( $$$\$\$ ) { # sub process_rule ( ) { my ( $target, $source, $dest, $protos, $ports, $sports, $origdest, $ratelimit, $user, $mark, $connlimit, $time, $headers, $condition ) - = split_line1 14, 'rules file', \%rulecolumns, $rule_commands; + = split_line1 'rules file', \%rulecolumns, $rule_commands; fatal_error 'ACTION must be specified' if $target eq '-'; diff --git a/Shorewall/Perl/Shorewall/Tc.pm b/Shorewall/Perl/Shorewall/Tc.pm index 76dd729c6..0226fcf8e 100644 --- a/Shorewall/Perl/Shorewall/Tc.pm +++ b/Shorewall/Perl/Shorewall/Tc.pm @@ -192,7 +192,7 @@ sub initialize( $ ) { sub process_tc_rule( ) { my ( $originalmark, $source, $dest, $proto, $ports, $sports, $user, $testval, $length, $tos , $connbytes, $helper, $headers ) = - split_line1 13, 'tcrules file', { mark => 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 }; + split_line1 'tcrules file', { mark => 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 }; our @tccmd; @@ -513,7 +513,7 @@ sub process_flow($) { } sub process_simple_device() { - my ( $device , $type , $in_bandwidth , $out_part ) = split_line 4, 'tcinterfaces', { interface => 0, type => 1, in_bandwidth => 2, out_bandwidth => 3 }; + my ( $device , $type , $in_bandwidth , $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}; @@ -648,7 +648,7 @@ sub process_simple_device() { } sub validate_tc_device( ) { - my ( $device, $inband, $outband , $options , $redirected ) = split_line 5, '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 '-'; @@ -813,7 +813,7 @@ sub dev_by_number( $ ) { sub validate_tc_class( ) { my ( $devclass, $mark, $rate, $ceil, $prio, $options ) = - split_line 6, '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; @@ -1037,7 +1037,7 @@ my %validlengths = ( 32 => '0xffe0', 64 => '0xffc0', 128 => '0xff80', 256 => '0x # sub process_tc_filter() { - my ( $devclass, $source, $dest , $proto, $portlist , $sportlist, $tos, $length ) = split_line 8, 'tcfilters file', { interface => 0, source => 1, dest => 2, proto => 3, dport => 4, sport => 5, tos => 6, length => 7 }; + my ( $devclass, $source, $dest , $proto, $portlist , $sportlist, $tos, $length ) = split_line 'tcfilters file', { interface => 0, source => 1, dest => 2, proto => 3, dport => 4, sport => 5, tos => 6, length => 7 }; fatal_error 'CLASS must be specified' if $devclass eq '-'; @@ -1339,7 +1339,7 @@ sub process_tcfilters() { # Process a tcpri record # sub process_tc_priority() { - my ( $band, $proto, $ports , $address, $interface, $helper ) = split_line1 6, 'tcpri', { band => 0, proto => 1, port => 2, address => 3, interface => 4, helper => 5 }; + my ( $band, $proto, $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 '-'; @@ -1680,7 +1680,7 @@ sub setup_traffic_shaping() { # sub process_secmark_rule() { my ( $secmark, $chainin, $source, $dest, $proto, $dport, $sport, $user, $mark ) = - split_line1( 9 , '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 d53224d46..9e2ef9c12 100644 --- a/Shorewall/Perl/Shorewall/Tunnels.pm +++ b/Shorewall/Perl/Shorewall/Tunnels.pm @@ -284,7 +284,7 @@ sub setup_tunnels() { while ( read_a_line ) { - my ( $kind, $zone, $gateway, $gatewayzones ) = split_line1 4, 'tunnels file', { kind => 0, zone => 1, gateway => 2, gateway_zone => 3 }; + my ( $kind, $zone, $gateway, $gatewayzones ) = split_line1 'tunnels file', { kind => 0, zone => 1, gateway => 2, gateway_zone => 3 }; fatal_error 'TYPE must be specified' if $kind eq '-'; fatal_error 'ZONE must be specified' if $zone eq '-'; diff --git a/Shorewall/Perl/Shorewall/Zones.pm b/Shorewall/Perl/Shorewall/Zones.pm index 73dded5a7..332226846 100644 --- a/Shorewall/Perl/Shorewall/Zones.pm +++ b/Shorewall/Perl/Shorewall/Zones.pm @@ -403,7 +403,7 @@ sub process_zone( \$ ) { my @parents; my ($zone, $type, $options, $in_options, $out_options ) = - split_line 5, '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 '-'; @@ -874,7 +874,7 @@ sub process_interface( $$ ) { my ( $nextinum, $export ) = @_; my $netsref = ''; my $filterref = []; - my ($zone, $originalinterface, $bcasts, $options ) = split_line 4, 'interfaces file', { zone => 0, interface => 1, broadcast => 2, options => 3 }; + my ($zone, $originalinterface, $bcasts, $options ) = split_line 'interfaces file', { zone => 0, interface => 1, broadcast => 2, options => 3 }; my $zoneref; my $bridge = ''; @@ -1732,7 +1732,7 @@ sub compile_updown() { # sub process_host( ) { my $ipsec = 0; - my ($zone, $hosts, $options ) = split_line 3, 'hosts file', { zone => 0, hosts => 1, options => 2 }; + my ($zone, $hosts, $options ) = split_line 'hosts file', { zone => 0, hosts => 1, options => 2 }; fatal_error 'ZONE must be specified' if $zone eq '-'; fatal_error 'HOSTS must be specified' if $hosts eq '-';