From c37e41ee9cd5c52fd31468a9e1d88dc0857c78b2 Mon Sep 17 00:00:00 2001 From: Tom Eastep Date: Sun, 6 Mar 2016 15:48:33 -0800 Subject: [PATCH] Avoid duplicate route rules from 'disable' Signed-off-by: Tom Eastep --- Shorewall/Perl/Shorewall/Providers.pm | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/Shorewall/Perl/Shorewall/Providers.pm b/Shorewall/Perl/Shorewall/Providers.pm index 967326c0d..f5e1e5fbe 100644 --- a/Shorewall/Perl/Shorewall/Providers.pm +++ b/Shorewall/Perl/Shorewall/Providers.pm @@ -828,12 +828,12 @@ sub add_a_provider( $$ ) { if ( ! $noautosrc ) { if ( $shared ) { - emit "qt \$IP -$family rule del from $address" if $config{DELETE_THEN_ADD}; + emit "qt \$IP -$family rule del from $address"; emit( "run_ip rule add from $address pref 20000 table $id" , "echo \"\$IP -$family rule del from $address pref 20000> /dev/null 2>&1\" >> \${VARDIR}/undo_${table}_routing" ); } else { emit ( "find_interface_addresses $physical | while read address; do" ); - emit ( " qt \$IP -$family rule del from \$address" ) if $config{DELETE_THEN_ADD}; + emit ( " qt \$IP -$family rule del from \$address" ); emit ( " run_ip rule add from \$address pref 20000 table $id", " echo \"\$IP -$family rule del from \$address pref 20000 > /dev/null 2>&1\" >> \${VARDIR}/undo_${table}_routing", ' rulenum=$(($rulenum + 1))', @@ -993,12 +993,19 @@ CEOF } } elsif ( ! $noautosrc ) { if ( $shared ) { - emit "qt \$IP -$family rule del from $address" if $config{DELETE_THEN_ADD}; - emit( "run_ip rule add from $address pref 20000 table $id" , - "echo \"\$IP -$family rule del from $address pref 20000> /dev/null 2>&1\" >> \${VARDIR}/undo_${table}_routing" ); + if ( $persistent ) { + emit( qq(if ! egrep -q "^2000:[[:space:]]+from $address lookup $id"; then), + qq( run_ip rule add from $address pref 20000 table $id), + qq( echo "\$IP -$family rule del from $address pref 20000> /dev/null 2>&1" >> \${VARDIR}/undo_${table}_routing ), + qq(fi) ); + } else { + emit "qt \$IP -$family rule del from $address" if $config{DELETE_THEN_ADD}; + emit( "run_ip rule add from $address pref 20000 table $id" , + "echo \"\$IP -$family rule del from $address pref 20000> /dev/null 2>&1\" >> \${VARDIR}/undo_${table}_routing" ); + } } elsif ( ! $pseudo ) { emit ( "find_interface_addresses $physical | while read address; do" ); - emit ( " qt \$IP -$family rule del from \$address" ) if $config{DELETE_THEN_ADD}; + emit ( " qt \$IP -$family rule del from \$address" ) if $persistent || $config{DELETE_THEN_ADD}; emit ( " run_ip rule add from \$address pref 20000 table $id", " echo \"\$IP -$family rule del from \$address pref 20000 > /dev/null 2>&1\" >> \${VARDIR}/undo_${table}_routing", ' rulenum=$(($rulenum + 1))', @@ -1283,7 +1290,7 @@ sub add_an_rtrule1( $$$$$ ) { push @{$providerref->{rules}}, "run_ip rule add $source ${dest}${mark} $priority table $id"; if ( $persistent ) { - push @{$providerref->{persistent_rules}}, "qt \$IP -$family rule del $source ${dest}${mark} $priority" if $config{DELETE_THEN_ADD}; + push @{$providerref->{persistent_rules}}, "qt \$IP -$family rule del $source ${dest}${mark} $priority"; push @{$providerref->{persistent_rules}}, "run_ip rule add $source ${dest}${mark} $priority table $id"; }