diff --git a/Shorewall/Perl/Shorewall/Rules.pm b/Shorewall/Perl/Shorewall/Rules.pm index 232a7ea52..4601f66e6 100644 --- a/Shorewall/Perl/Shorewall/Rules.pm +++ b/Shorewall/Perl/Shorewall/Rules.pm @@ -4773,91 +4773,4 @@ sub process_mangle_rule( $ ) { process_mangle_rule1( $chainref, $originalmark, $source, $dest, $proto, $ports, $sports, $user, $testval, $length, $tos , $connbytes, $helper, $headers, $probability , $dscp , $state, $time ); } } - -sub convert_tos($$) { - my ( $mangle, $fn1 ) = @_; - - my $have_tos = 0; - - sub unlink_tos( $ ) { - my $fn = shift; - - if ( unlink $fn ) { - warning_message "Empty tos file ($fn) removed"; - } else { - warning_message "Unable to remove empty tos file $fn: $!"; - } - } - - if ( my $fn = open_file 'tos' ) { - first_entry( - sub { - my $date = localtime; - progress_message2 "Converting $fn..."; - print( $mangle - "#\n" , - "# Rules generated from tos file $fn by Shorewall $globals{VERSION} - $date\n" , - "#\n" ); - } - ); - - while ( read_a_line( NORMAL_READ ) ) { - - $have_tos = 1; - - 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 $chain_designator = 'P'; - - decode_tos($tos, 1); - - my ( $srczone , $source , $remainder ); - - if ( $family == F_IPV4 ) { - ( $srczone , $source , $remainder ) = split( /:/, $src, 3 ); - fatal_error 'Invalid SOURCE' if defined $remainder; - } elsif ( $src =~ /^(.+?):<(.*)>\s*$/ || $src =~ /^(.+?):\[(.*)\]\s*$/ ) { - $srczone = $1; - $source = $2; - } else { - $srczone = $src; - } - - if ( $srczone eq firewall_zone ) { - $chain_designator = 'O'; - $src = $source || '-'; - } else { - $src =~ s/^all:?//; - } - - $dst =~ s/^all:?//; - - $src = '-' unless supplied $src; - $dst = '-' unless supplied $dst; - $proto = '-' unless supplied $proto; - $ports = '-' unless supplied $ports; - $sports = '-' unless supplied $sports; - $mark = '-' unless supplied $mark; - - print $mangle "TOS($tos):$chain_designator\t$src\t$dst\t$proto\t$ports\t$sports\t-\t$mark\n" - - } - - if ( $have_tos ) { - progress_message2 "Converted $fn to $fn1"; - if ( rename $fn, "$fn.bak" ) { - progress_message2 "$fn renamed $fn.bak"; - } else { - fatal_error "Cannot Rename $fn to $fn.bak: $!"; - } - } else { - unlink_tos( $fn ); - } - } elsif ( -f ( $fn = find_file( 'tos' ) ) ) { - unlink_tos( $fn ); - } -} - 1; diff --git a/Shorewall/Perl/Shorewall/Tc.pm b/Shorewall/Perl/Shorewall/Tc.pm index 0e73adeba..ca282570b 100644 --- a/Shorewall/Perl/Shorewall/Tc.pm +++ b/Shorewall/Perl/Shorewall/Tc.pm @@ -2140,6 +2140,93 @@ sub process_secmark_rule() { } } + +sub convert_tos($$) { + my ( $mangle, $fn1 ) = @_; + + my $have_tos = 0; + + sub unlink_tos( $ ) { + my $fn = shift; + + if ( unlink $fn ) { + warning_message "Empty tos file ($fn) removed"; + } else { + warning_message "Unable to remove empty tos file $fn: $!"; + } + } + + if ( my $fn = open_file 'tos' ) { + first_entry( + sub { + my $date = localtime; + progress_message2 "Converting $fn..."; + print( $mangle + "#\n" , + "# Rules generated from tos file $fn by Shorewall $globals{VERSION} - $date\n" , + "#\n" ); + } + ); + + while ( read_a_line( NORMAL_READ ) ) { + + $have_tos = 1; + + 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 $chain_designator = 'P'; + + decode_tos($tos, 1); + + my ( $srczone , $source , $remainder ); + + if ( $family == F_IPV4 ) { + ( $srczone , $source , $remainder ) = split( /:/, $src, 3 ); + fatal_error 'Invalid SOURCE' if defined $remainder; + } elsif ( $src =~ /^(.+?):<(.*)>\s*$/ || $src =~ /^(.+?):\[(.*)\]\s*$/ ) { + $srczone = $1; + $source = $2; + } else { + $srczone = $src; + } + + if ( $srczone eq firewall_zone ) { + $chain_designator = 'O'; + $src = $source || '-'; + } else { + $src =~ s/^all:?//; + } + + $dst =~ s/^all:?//; + + $src = '-' unless supplied $src; + $dst = '-' unless supplied $dst; + $proto = '-' unless supplied $proto; + $ports = '-' unless supplied $ports; + $sports = '-' unless supplied $sports; + $mark = '-' unless supplied $mark; + + print $mangle "TOS($tos):$chain_designator\t$src\t$dst\t$proto\t$ports\t$sports\t-\t$mark\n" + + } + + if ( $have_tos ) { + progress_message2 "Converted $fn to $fn1"; + if ( rename $fn, "$fn.bak" ) { + progress_message2 "$fn renamed $fn.bak"; + } else { + fatal_error "Cannot Rename $fn to $fn.bak: $!"; + } + } else { + unlink_tos( $fn ); + } + } elsif ( -f ( $fn = find_file( 'tos' ) ) ) { + unlink_tos( $fn ); + } +} + sub open_mangle_for_output() { my ( $mangle, $fn1 );