Compare commits

..

11 Commits

Author SHA1 Message Date
Tom Eastep
3b6b89336e Eliminate superfluous test
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2016-10-24 11:57:56 -07:00
Tom Eastep
fc0ad7cd2e Be sure that the 'restriction' member exists for the FORWARD chain
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2016-10-24 11:37:40 -07:00
Tom Eastep
c9b1b7684c Correct handling of dest IPSET.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2016-10-24 09:06:05 -07:00
Tom Eastep
b8ec460a1a Correct grammar in the ipset creation message
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2016-10-24 08:49:51 -07:00
Tom Eastep
46b8e2e957 Avoid exception when validating 'occurs' in TC
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2016-10-24 08:14:12 -07:00
Tom Eastep
0ed813972b Auto-create ipsets used in tcfilters
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2016-10-23 16:44:07 -07:00
Tom Eastep
f9cfde91e5 Correctly handle ipset in tcfilter DEST
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2016-10-23 16:43:49 -07:00
Tom Eastep
3df488e710 Correct handling of ipsets in tcfilters
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2016-10-23 16:28:36 -07:00
Tom Eastep
0efc7a4899 Correct restriction and chain number handling in the mangle files
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2016-10-23 15:36:04 -07:00
Tom Eastep
e0203bca87 Correct nill address check in handling of 'origdest=detect'
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2016-10-23 08:34:24 -07:00
Tom Eastep
34f2aeacea Correct 'sed' command
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2016-10-22 09:59:30 -07:00
4 changed files with 30 additions and 21 deletions

View File

@@ -3566,7 +3566,7 @@ blacklist_command() {
if [ $VERBOSITY -gt 1 ]; then if [ $VERBOSITY -gt 1 ]; then
echo "$message" | awk '/have been deleted/ { sub( /^.*: /, "" ); sub( / /, " src " ); }; { print; }' echo "$message" | awk '/have been deleted/ { sub( /^.*: /, "" ); sub( / /, " src " ); }; { print; }'
else else
echo "$message" | head -n1 | sed '/^.*: //; s/ / src /' echo "$message" | head -n1 | sed 's/^.*: //; s/ / src /'
fi fi
fi fi
@@ -3576,7 +3576,7 @@ blacklist_command() {
if [ $VERBOSITY -gt 1 ]; then if [ $VERBOSITY -gt 1 ]; then
echo "$message" | awk '/have been deleted/ { sub( /^.*: /, "" ); sub( / /, " dst " ); }; { print; }' echo "$message" | awk '/have been deleted/ { sub( /^.*: /, "" ); sub( / /, " dst " ); }; { print; }'
else else
echo "$message" | head -n1 | sed '/^.*: //; s/ / dst /' echo "$message" | head -n1 | sed 's/^.*: //; s/ / dst /'
fi fi
fi fi
fi fi

View File

@@ -2747,11 +2747,13 @@ sub accounting_chainrefs() {
grep $_->{accounting} , values %$filter_table; grep $_->{accounting} , values %$filter_table;
} }
sub ensure_mangle_chain($) { sub ensure_mangle_chain($;$$) {
my $chain = $_[0]; my ( $chain, $number, $restriction ) = @_;
my $chainref = ensure_chain 'mangle', $chain; my $chainref = ensure_chain 'mangle', $chain;
$chainref->{referenced} = 1; $chainref->{referenced} = 1;
$chainref->{chainnumber} = $number if $number;
$chainref->{restriction} = $restriction if $restriction;
$chainref; $chainref;
} }
@@ -7273,6 +7275,7 @@ sub isolate_dest_interface( $$$$ ) {
my ( $diface, $dnets ); my ( $diface, $dnets );
if ( ( $restriction & PREROUTE_RESTRICT ) && $dest =~ /^detect:(.*)$/ ) { if ( ( $restriction & PREROUTE_RESTRICT ) && $dest =~ /^detect:(.*)$/ ) {
my $niladdr = NILIP;
# #
# DETECT_DNAT_IPADDRS=Yes and we're generating the nat rule # DETECT_DNAT_IPADDRS=Yes and we're generating the nat rule
# #
@@ -7289,14 +7292,14 @@ sub isolate_dest_interface( $$$$ ) {
push_command( $chainref , "for address in $list; do" , 'done' ); push_command( $chainref , "for address in $list; do" , 'done' );
push_command( $chainref , 'if [ $address != 0.0.0.0 ]; then' , 'fi' ) if $optional; push_command( $chainref , "if [ \$address != $niladdr ]; then" , 'fi' ) if $optional;
$rule .= '-d $address '; $rule .= '-d $address ';
} else { } else {
my $interface = $interfaces[0]; my $interface = $interfaces[0];
my $variable = get_interface_address( $interface ); my $variable = get_interface_address( $interface );
push_command( $chainref , "if [ $variable != 0.0.0.0 ]; then" , 'fi') if interface_is_optional( $interface ); push_command( $chainref , "if [ $variable != $niladdr ]; then" , 'fi') if interface_is_optional( $interface );
$rule .= "-d $variable "; $rule .= "-d $variable ";
} }
@@ -8304,18 +8307,18 @@ sub ensure_ipsets( @ ) {
if ( $family == F_IPV4 ) { if ( $family == F_IPV4 ) {
if ( have_capability 'IPSET_V5' ) { if ( have_capability 'IPSET_V5' ) {
emit ( qq( if ! qt \$IPSET list $set -n; then) , emit ( qq( if ! qt \$IPSET list $set -n; then) ,
qq( error_message "WARNING: ipset $set does not exist; creating it as an hash:net set") , qq( error_message "WARNING: ipset $set does not exist; creating it as a hash:net set") ,
qq( \$IPSET create $set hash:net family inet timeout 0${counters}) , qq( \$IPSET create $set hash:net family inet timeout 0${counters}) ,
qq( fi) ); qq( fi) );
} else { } else {
emit ( qq( if ! qt \$IPSET -L $set -n; then) , emit ( qq( if ! qt \$IPSET -L $set -n; then) ,
qq( error_message "WARNING: ipset $set does not exist; creating it as an iphash set") , qq( error_message "WARNING: ipset $set does not exist; creating it as a iphash set") ,
qq( \$IPSET -N $set iphash) , qq( \$IPSET -N $set iphash) ,
qq( fi) ); qq( fi) );
} }
} else { } else {
emit ( qq( if ! qt \$IPSET list $set -n; then) , emit ( qq( if ! qt \$IPSET list $set -n; then) ,
qq( error_message "WARNING: ipset $set does not exist; creating it as an hash:net set") , qq( error_message "WARNING: ipset $set does not exist; creating it as a hash:net set") ,
qq( \$IPSET create $set hash:net family inet6 timeout 0${counters}) , qq( \$IPSET create $set hash:net family inet6 timeout 0${counters}) ,
qq( fi) ); qq( fi) );
} }

View File

@@ -4098,11 +4098,13 @@ sub process_mangle_rule1( $$$$$$$$$$$$$$$$$$ ) {
my $chainref = ensure_chain( 'mangle', $chain = $chainnames{$chain} ); my $chainref = ensure_chain( 'mangle', $chain = $chainnames{$chain} );
$restriction |= $chainref->{restriction};
for ( my $packet = 0; $packet < $marks; $packet++, $markval += $increment ) { for ( my $packet = 0; $packet < $marks; $packet++, $markval += $increment ) {
my $match = "-m statistic --mode nth --every $marks --packet $packet "; my $match = "-m statistic --mode nth --every $marks --packet $packet ";
expand_rule( $chainref, expand_rule( $chainref,
$restrictions{$chain} | $restriction, $restriction,
$prerule , $prerule ,
$match . $match .
do_user( $user ) . do_user( $user ) .
@@ -4845,8 +4847,10 @@ sub process_mangle_rule1( $$$$$$$$$$$$$$$$$$ ) {
$chainref = ensure_chain( 'mangle', $chainnames{$chain} ); $chainref = ensure_chain( 'mangle', $chainnames{$chain} );
} }
$restriction |= $chainref->{restriction};
if ( ( my $result = expand_rule( $chainref , if ( ( my $result = expand_rule( $chainref ,
( $restrictions{$chain} || 0 ) | $restriction, $restriction,
$prerule, $prerule,
do_proto( $proto, $ports, $sports) . $matches . do_proto( $proto, $ports, $sports) . $matches .
do_user( $user ) . do_user( $user ) .

View File

@@ -827,7 +827,7 @@ sub validate_tc_class( ) {
fatal_error "Invalid 'occurs' ($val)" unless defined $occurs && $occurs > 1 && $occurs <= 256; fatal_error "Invalid 'occurs' ($val)" unless defined $occurs && $occurs > 1 && $occurs <= 256;
fatal_error "Invalid 'occurs' ($val)" if $occurs > $globals{TC_MAX}; fatal_error "Invalid 'occurs' ($val)" if $occurs > $globals{TC_MAX};
fatal_error q(Duplicate 'occurs') if $tcref->{occurs} > 1; fatal_error q(Duplicate 'occurs') if $tcref->{occurs} > 1;
fatal_error q(The 'occurs' option is not valid with 'default') if $devref->{default} == $classnumber; fatal_error q(The 'occurs' option is not valid with 'default') if defined($devref->{default}) && $devref->{default} == $classnumber;
fatal_error q(The 'occurs' option is not valid with 'tos') if @{$tcref->{tos}}; fatal_error q(The 'occurs' option is not valid with 'tos') if @{$tcref->{tos}};
warning_message "MARK ($mark) is ignored on an occurring class" if $mark ne '-'; warning_message "MARK ($mark) is ignored on an occurring class" if $mark ne '-';
@@ -1308,6 +1308,8 @@ sub handle_ematch( $$ ) {
$setname =~ s/\+//; $setname =~ s/\+//;
add_ipset($setname);
return "ipset\\($setname $options\\)"; return "ipset\\($setname $options\\)";
} }
@@ -1518,7 +1520,7 @@ sub process_tc_filter2( $$$$$$$$$ ) {
$rule .= ' and' if $have_rule; $rule .= ' and' if $have_rule;
if ( $source =~ /^\+/ ) { if ( $source =~ /^\+/ ) {
$rule = join( '', "\\\n ", handle_ematch( $source, 'src' ) ); $rule .= join( '', "\\\n ", handle_ematch( $source, 'src' ) );
} else { } else {
my @parts = decompose_net_u32( $source ); my @parts = decompose_net_u32( $source );
@@ -1557,10 +1559,10 @@ sub process_tc_filter2( $$$$$$$$$ ) {
$rule .= ' and' if @parts; $rule .= ' and' if @parts;
} }
} }
}
$have_rule = 1; $have_rule = 1;
} }
}
if ( $have_rule ) { if ( $have_rule ) {
push @$filtersref, ( "\nrun_tc $rule\\" , push @$filtersref, ( "\nrun_tc $rule\\" ,
@@ -2276,13 +2278,13 @@ sub setup_tc( $ ) {
$convert = $_[0]; $convert = $_[0];
if ( $config{MANGLE_ENABLED} ) { if ( $config{MANGLE_ENABLED} ) {
ensure_mangle_chain 'tcpre'; ensure_mangle_chain( 'tcpre', PREROUTING, PREROUTE_RESTRICT );
ensure_mangle_chain 'tcout'; ensure_mangle_chain( 'tcout', OUTPUT , OUTPUT_RESTRICT );
if ( have_capability( 'MANGLE_FORWARD' ) ) { if ( have_capability( 'MANGLE_FORWARD' ) ) {
ensure_mangle_chain 'tcfor'; ensure_mangle_chain( 'tcfor', FORWARD , NO_RESTRICT );
ensure_mangle_chain 'tcpost'; ensure_mangle_chain( 'tcpost', POSTROUTING, POSTROUTE_RESTRICT );
ensure_mangle_chain 'tcin'; ensure_mangle_chain( 'tcin', INPUT , INPUT_RESTRICT );
} }
my @mark_part; my @mark_part;