mirror of
https://gitlab.com/shorewall/code.git
synced 2025-06-26 04:32:01 +02:00
Implement BALANCE table
Signed-off-by: Tom Eastep <teastep@shorewall.net>
This commit is contained in:
parent
8ec8056268
commit
e6b120a805
@ -45,6 +45,7 @@ our $VERSION = 'MODULEVERSION';
|
|||||||
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)";
|
||||||
}
|
}
|
||||||
@ -559,18 +555,19 @@ sub add_a_provider( $$ ) {
|
|||||||
emit "qt \$IP -6 route del $gateway src $address dev $physical ${mtu}table $number $realm";
|
emit "qt \$IP -6 route del $gateway src $address dev $physical ${mtu}table $number $realm";
|
||||||
emit "run_ip route add $gateway src $address dev $physical ${mtu}table $number $realm";
|
emit "run_ip route add $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";
|
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);
|
||||||
@ -581,6 +578,8 @@ sub add_a_provider( $$ ) {
|
|||||||
emit qq(run_ip route add default table ) . DEFAULT_TABLE . qq( dev $physical metric $number);
|
emit qq(run_ip route add default table ) . DEFAULT_TABLE . qq( dev $physical metric $number);
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
unless ( $local ) {
|
unless ( $local ) {
|
||||||
@ -630,7 +629,7 @@ sub add_a_provider( $$ ) {
|
|||||||
push_indent;
|
push_indent;
|
||||||
|
|
||||||
if ( $balance || $default ) {
|
if ( $balance || $default ) {
|
||||||
$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 ) {
|
||||||
@ -702,7 +701,7 @@ sub add_a_provider( $$ ) {
|
|||||||
" > $undo" );
|
" > $undo" );
|
||||||
|
|
||||||
if ( $balance || $default ) {
|
if ( $balance || $default ) {
|
||||||
$tbl = $fallback || ( $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;
|
||||||
|
|
||||||
my $via = 'via';
|
my $via = 'via';
|
||||||
@ -914,12 +913,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' );
|
||||||
@ -970,6 +971,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} ) {
|
||||||
@ -982,7 +985,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',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user