forked from extern/shorewall_code
Add BALANCE_TABLE.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
This commit is contained in:
parent
a5010ec9a6
commit
668926c2a6
@ -40,11 +40,12 @@ our @EXPORT = qw( process_providers
|
|||||||
handle_stickiness
|
handle_stickiness
|
||||||
handle_optional_interfaces );
|
handle_optional_interfaces );
|
||||||
our @EXPORT_OK = qw( initialize lookup_provider );
|
our @EXPORT_OK = qw( initialize lookup_provider );
|
||||||
our $VERSION = 'MODULEVERSION';
|
our $VERSION = '4.4_24';
|
||||||
|
|
||||||
use constant { LOCAL_TABLE => 255,
|
use constant { LOCAL_TABLE => 255,
|
||||||
MAIN_TABLE => 254,
|
MAIN_TABLE => 254,
|
||||||
DEFAULT_TABLE => 253,
|
DEFAULT_TABLE => 253,
|
||||||
|
BALANCE_TABLE => 250,
|
||||||
UNSPEC_TABLE => 0
|
UNSPEC_TABLE => 0
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -93,6 +94,7 @@ sub initialize( $ ) {
|
|||||||
%providers = ( local => { number => LOCAL_TABLE , mark => 0 , optional => 0 ,routes => [], rules => [] } ,
|
%providers = ( local => { number => LOCAL_TABLE , mark => 0 , optional => 0 ,routes => [], rules => [] } ,
|
||||||
main => { number => MAIN_TABLE , mark => 0 , optional => 0 ,routes => [], rules => [] } ,
|
main => { number => MAIN_TABLE , mark => 0 , optional => 0 ,routes => [], rules => [] } ,
|
||||||
default => { number => DEFAULT_TABLE , mark => 0 , optional => 0 ,routes => [], rules => [] } ,
|
default => { number => DEFAULT_TABLE , mark => 0 , optional => 0 ,routes => [], rules => [] } ,
|
||||||
|
balance => { number => BALANCE_TABLE , mark => 0 , optional => 0 ,routes => [], rules => [] } ,
|
||||||
unspec => { number => UNSPEC_TABLE , mark => 0 , optional => 0 ,routes => [], rules => [] } );
|
unspec => { number => UNSPEC_TABLE , mark => 0 , optional => 0 ,routes => [], rules => [] } );
|
||||||
@providers = ();
|
@providers = ();
|
||||||
}
|
}
|
||||||
@ -347,23 +349,17 @@ sub process_a_provider() {
|
|||||||
$mtu = "mtu $1 ";
|
$mtu = "mtu $1 ";
|
||||||
} elsif ( $option =~ /^fallback=(\d+)$/ ) {
|
} elsif ( $option =~ /^fallback=(\d+)$/ ) {
|
||||||
fatal_error q('fallback' is not available in IPv6) if $family == F_IPV6;
|
fatal_error q('fallback' is not available in IPv6) if $family == F_IPV6;
|
||||||
if ( $config{USE_DEFAULT_RT} ) {
|
$default = $1;
|
||||||
warning_message "'fallback' is ignored when USE_DEFAULT_RT=Yes";
|
$default_balance = 0;
|
||||||
} else {
|
fatal_error 'fallback must be non-zero' unless $default;
|
||||||
$default = $1;
|
|
||||||
fatal_error 'fallback must be non-zero' unless $default;
|
|
||||||
}
|
|
||||||
} elsif ( $option eq 'fallback' ) {
|
} elsif ( $option eq 'fallback' ) {
|
||||||
fatal_error q('fallback' is not available in IPv6) if $family == F_IPV6;
|
fatal_error q('fallback' is not available in IPv6) if $family == F_IPV6;
|
||||||
if ( $config{USE_DEFAULT_RT} ) {
|
$default = -1;
|
||||||
warning_message "'fallback' is ignored when USE_DEFAULT_RT=Yes";
|
$default_balance = 0;
|
||||||
} else {
|
|
||||||
$default = -1;
|
|
||||||
}
|
|
||||||
} elsif ( $option eq 'local' ) {
|
} elsif ( $option eq 'local' ) {
|
||||||
$local = 1;
|
$local = 1;
|
||||||
$track = 0 if $config{TRACK_PROVIDERS};
|
$track = 0 if $config{TRACK_PROVIDERS};
|
||||||
$default_balance = 0 if$config{USE_DEFAULT_RT};
|
$default_balance = 0 if $config{USE_DEFAULT_RT};
|
||||||
} else {
|
} else {
|
||||||
fatal_error "Invalid option ($option)";
|
fatal_error "Invalid option ($option)";
|
||||||
}
|
}
|
||||||
@ -563,14 +559,15 @@ sub add_a_provider( $$ ) {
|
|||||||
emit "run_ip route add default via $gateway src $address dev $physical ${mtu}table $number $realm";
|
emit "run_ip route add default via $gateway src $address dev $physical ${mtu}table $number $realm";
|
||||||
}
|
}
|
||||||
|
|
||||||
balance_default_route( $balance , $gateway, $physical, $realm ) if $balance;
|
if ( $balance ) {
|
||||||
|
balance_default_route( $balance , $gateway, $physical, $realm );
|
||||||
if ( $default > 0 ) {
|
} elsif ( $default > 0 ) {
|
||||||
balance_fallback_route( $default , $gateway, $physical, $realm );
|
balance_fallback_route( $default , $gateway, $physical, $realm );
|
||||||
} elsif ( $default ) {
|
} elsif ( $default ) {
|
||||||
emit '';
|
emit '';
|
||||||
if ( $gateway ) {
|
if ( $gateway ) {
|
||||||
if ( $family == F_IPV4 ) {
|
if ( $family == F_IPV4 ) {
|
||||||
|
emit qq(run_ip route replace $gateway dev $physical table ) . DEFAULT_TABLE;
|
||||||
emit qq(run_ip route replace default via $gateway src $address dev $physical table ) . DEFAULT_TABLE . qq( metric $number);
|
emit qq(run_ip route replace default via $gateway src $address dev $physical table ) . DEFAULT_TABLE . qq( metric $number);
|
||||||
} else {
|
} else {
|
||||||
emit qq(qt \$IP -6 route del default via $gateway src $address dev $physical table ) . DEFAULT_TABLE . qq( metric $number);
|
emit qq(qt \$IP -6 route del default via $gateway src $address dev $physical table ) . DEFAULT_TABLE . qq( metric $number);
|
||||||
@ -582,7 +579,7 @@ sub add_a_provider( $$ ) {
|
|||||||
emit qq(echo "qt \$IP -$family route del default dev $physical table ) . DEFAULT_TABLE . qq(" >> \${VARDIR}/undo_${table}_routing);
|
emit qq(echo "qt \$IP -$family route del default dev $physical table ) . DEFAULT_TABLE . qq(" >> \${VARDIR}/undo_${table}_routing);
|
||||||
}
|
}
|
||||||
|
|
||||||
$default = 1;
|
$fallback = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
unless ( $local ) {
|
unless ( $local ) {
|
||||||
@ -631,8 +628,8 @@ sub add_a_provider( $$ ) {
|
|||||||
|
|
||||||
push_indent;
|
push_indent;
|
||||||
|
|
||||||
if ( $balance || $default ) {
|
if ( $balance || $default > 0 ) {
|
||||||
$tbl = $default || $config{USE_DEFAULT_RT} ? DEFAULT_TABLE : MAIN_TABLE;
|
$tbl = $default ? DEFAULT_TABLE : $config{USE_DEFAULT_RT} ? BALANCE_TABLE : MAIN_TABLE;
|
||||||
$weight = $balance ? $balance : $default;
|
$weight = $balance ? $balance : $default;
|
||||||
|
|
||||||
if ( $gateway ) {
|
if ( $gateway ) {
|
||||||
@ -699,30 +696,40 @@ sub add_a_provider( $$ ) {
|
|||||||
|
|
||||||
my $undo = "\${VARDIR}/undo_${table}_routing";
|
my $undo = "\${VARDIR}/undo_${table}_routing";
|
||||||
|
|
||||||
emit( "if [ -f $undo ]; then",
|
emit( "if [ -f $undo ]; then" );
|
||||||
" . $undo",
|
|
||||||
" > $undo" );
|
|
||||||
|
|
||||||
if ( $balance || $default ) {
|
push_indent;
|
||||||
$tbl = $fallback || ( $config{USE_DEFAULT_RT} ? DEFAULT_TABLE : MAIN_TABLE );
|
|
||||||
|
if ( $balance || $default > 0 ) {
|
||||||
|
$tbl = $default ? DEFAULT_TABLE : $config{USE_DEFAULT_RT} ? BALANCE_TABLE : MAIN_TABLE;
|
||||||
$weight = $balance ? $balance : $default;
|
$weight = $balance ? $balance : $default;
|
||||||
|
|
||||||
my $via = 'via';
|
my $via;
|
||||||
|
|
||||||
$via .= " $gateway" if $gateway;
|
if ( $gateway ) {
|
||||||
$via .= " dev $physical";
|
$via = "via $gateway dev $physical";
|
||||||
$via .= " weight $weight";
|
} else {
|
||||||
|
$via = "dev $physical";
|
||||||
|
}
|
||||||
|
|
||||||
|
$via .= " weight $weight" unless $weight < 0;
|
||||||
$via .= " $realm" if $realm;
|
$via .= " $realm" if $realm;
|
||||||
|
|
||||||
emit( qq( delete_gateway "$via" $tbl $physical) );
|
emit( qq(delete_gateway "$via" $tbl $physical) );
|
||||||
}
|
}
|
||||||
|
|
||||||
emit( '',
|
emit (". $undo",
|
||||||
" qt \$TC qdisc del dev $physical root",
|
"> $undo" );
|
||||||
" qt \$TC qdisc del dev $physical ingress\n" ) if $tcdevices->{$interface};
|
|
||||||
|
|
||||||
emit( " progress_message2 \"Provider $table stopped\"",
|
emit( '',
|
||||||
'else',
|
"qt \$TC qdisc del dev $physical root",
|
||||||
|
"qt \$TC qdisc del dev $physical ingress\n" ) if $tcdevices->{$interface};
|
||||||
|
|
||||||
|
emit( "progress_message2 \"Provider $table stopped\"" );
|
||||||
|
|
||||||
|
pop_indent;
|
||||||
|
|
||||||
|
emit( 'else',
|
||||||
" startup_error \"$undo does not exist\"",
|
" startup_error \"$undo does not exist\"",
|
||||||
'fi'
|
'fi'
|
||||||
);
|
);
|
||||||
@ -916,12 +923,14 @@ sub finish_providers() {
|
|||||||
my $table = MAIN_TABLE;
|
my $table = MAIN_TABLE;
|
||||||
|
|
||||||
if ( $config{USE_DEFAULT_RT} ) {
|
if ( $config{USE_DEFAULT_RT} ) {
|
||||||
emit ( 'run_ip rule add from ' . ALLIP . ' table ' . MAIN_TABLE . ' pref 999',
|
emit ( 'run_ip rule add from ' . ALLIP . ' table ' . MAIN_TABLE . ' pref 999',
|
||||||
|
'run_ip rule add from ' . ALLIP . ' table ' . BALANCE_TABLE . ' pref 32765',
|
||||||
"\$IP -$family rule del from " . ALLIP . ' table ' . MAIN_TABLE . ' pref 32766',
|
"\$IP -$family rule del from " . ALLIP . ' table ' . MAIN_TABLE . ' pref 32766',
|
||||||
qq(echo "qt \$IP -$family rule add from ) . ALLIP . ' table ' . MAIN_TABLE . ' pref 32766" >> ${VARDIR}/undo_main_routing',
|
qq(echo "qt \$IP -$family rule add from ) . ALLIP . ' table ' . MAIN_TABLE . ' pref 32766" >> ${VARDIR}/undo_main_routing',
|
||||||
qq(echo "qt \$IP -$family rule del from ) . ALLIP . ' table ' . MAIN_TABLE . ' pref 999" >> ${VARDIR}/undo_main_routing',
|
qq(echo "qt \$IP -$family rule del from ) . ALLIP . ' table ' . MAIN_TABLE . ' pref 999" >> ${VARDIR}/undo_main_routing',
|
||||||
|
qq(echo "qt \$IP -$family rule del from ) . ALLIP . ' table ' . BALANCE_TABLE . ' pref 32765" >> ${VARDIR}/undo_balance_routing',
|
||||||
'' );
|
'' );
|
||||||
$table = DEFAULT_TABLE;
|
$table = BALANCE_TABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
emit ( 'if [ -n "$DEFAULT_ROUTE" ]; then' );
|
emit ( 'if [ -n "$DEFAULT_ROUTE" ]; then' );
|
||||||
@ -972,6 +981,8 @@ sub finish_providers() {
|
|||||||
emit( " progress_message \"Fallback route '\$(echo \$FALLBACK_ROUTE | sed 's/\$\\s*//')' Added\"",
|
emit( " progress_message \"Fallback route '\$(echo \$FALLBACK_ROUTE | sed 's/\$\\s*//')' Added\"",
|
||||||
'fi',
|
'fi',
|
||||||
'' );
|
'' );
|
||||||
|
} elsif ( $config{USE_DEFAULT_RT} ) {
|
||||||
|
emit "qt \$IP -$family route del default table " . DEFAULT_TABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
unless ( $config{KEEP_RT_TABLES} ) {
|
unless ( $config{KEEP_RT_TABLES} ) {
|
||||||
@ -984,7 +995,7 @@ sub finish_providers() {
|
|||||||
'#',
|
'#',
|
||||||
LOCAL_TABLE . "\tlocal",
|
LOCAL_TABLE . "\tlocal",
|
||||||
MAIN_TABLE . "\tmain",
|
MAIN_TABLE . "\tmain",
|
||||||
DEFAULT_TABLE . "\tdefault",
|
$config{USE_DEFAULT_RT} ? ( DEFAULT_TABLE . "\tdefault\n" . BALANCE_TABLE . "\tbalance" ) : DEFAULT_TABLE . "\tdefault",
|
||||||
"0\tunspec",
|
"0\tunspec",
|
||||||
'#',
|
'#',
|
||||||
'# local',
|
'# local',
|
||||||
|
@ -535,8 +535,10 @@
|
|||||||
is given without a <replaceable>weight</replaceable>, a
|
is given without a <replaceable>weight</replaceable>, a
|
||||||
separate default route is added through the provider's
|
separate default route is added through the provider's
|
||||||
gateway; the route has a metric equal to the provider's
|
gateway; the route has a metric equal to the provider's
|
||||||
NUMBER. The option is ignored with a warning message if
|
NUMBER.</para>
|
||||||
USE_DEFAULT_RT=Yes in
|
|
||||||
|
<para>Prior to Shorewall 4.4.24, the option is ignored with
|
||||||
|
a warning message if USE_DEFAULT_RT=Yes in
|
||||||
<filename>shorewall.conf</filename>.</para>
|
<filename>shorewall.conf</filename>.</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
@ -263,8 +263,10 @@
|
|||||||
specified <replaceable>weight</replaceable>. If the option is
|
specified <replaceable>weight</replaceable>. If the option is
|
||||||
given without a <replaceable>weight</replaceable>, an separate
|
given without a <replaceable>weight</replaceable>, an separate
|
||||||
default route is added through the provider's gateway; the
|
default route is added through the provider's gateway; the
|
||||||
route has a metric equal to the provider's NUMBER. The option
|
route has a metric equal to the provider's NUMBER.</para>
|
||||||
is ignored with a warning message if USE_DEFAULT_RT=Yes in
|
|
||||||
|
<para>Prior to Shorewall 4.4.24, the option is ignored with a
|
||||||
|
warning message if USE_DEFAULT_RT=Yes in
|
||||||
<filename>shorewall.conf</filename>.</para>
|
<filename>shorewall.conf</filename>.</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
Loading…
Reference in New Issue
Block a user