Use a function to generate the list of interfaces with an L3 address

This commit is contained in:
Tom Eastep 2010-08-29 20:13:56 -07:00
parent 57c54af6ed
commit c18d206726
4 changed files with 29 additions and 17 deletions

View File

@ -859,17 +859,15 @@ sub handle_optional_interfaces( $ ) {
emit( join( '_', 'SW', uc chain_base( get_physical( $_ ) ) , 'IS_USABLE=' ) ) for @$interfaces; emit( join( '_', 'SW', uc chain_base( get_physical( $_ ) ) , 'IS_USABLE=' ) ) for @$interfaces;
if ( $wildcards ) { if ( $wildcards ) {
#
# We must consider all interfaces with an address in $family -- generate a list of such addresses.
#
emit( '', emit( '',
'interfaces=$($IP -' . $family . ' addr list | egrep \'^[[:digit:]]+\' | while read number interface rest; do echo ${interface%:}; done)', 'for interface in $(find_all_interfaces1); do',
'',
'for interface in $interfaces; do'
); );
push_indent; push_indent;
emit ( 'case "$interface" in' );
emit ( 'case "$interface" in'
);
push_indent; push_indent;
} else { } else {
emit ''; emit '';
@ -881,9 +879,7 @@ sub handle_optional_interfaces( $ ) {
my $base = uc chain_base( $physical ); my $base = uc chain_base( $physical );
my $providerref = $providers{$provider}; my $providerref = $providers{$provider};
emit( "$physical)" ) if $wildcards; emit( "$physical)" ), push_indent if $wildcards;
push_indent;
if ( $providerref->{gatewaycase} eq 'detect' ) { if ( $providerref->{gatewaycase} eq 'detect' ) {
emit qq(if interface_is_usable $physical && [ -n "$providerref->{gateway}" ]; then); emit qq(if interface_is_usable $physical && [ -n "$providerref->{gateway}" ]; then);
@ -908,7 +904,6 @@ sub handle_optional_interfaces( $ ) {
if ( $wildcards ) { if ( $wildcards ) {
emit( "$case)" ); emit( "$case)" );
push_indent; push_indent;
if ( $wild ) { if ( $wild ) {
emit( qq(if [ -z "\$SW_${base}_IS_USABLE" ]; then) ); emit( qq(if [ -z "\$SW_${base}_IS_USABLE" ]; then) );
@ -922,7 +917,6 @@ sub handle_optional_interfaces( $ ) {
} }
emit ( ' HAVE_INTERFACE=Yes' ) if $require; emit ( ' HAVE_INTERFACE=Yes' ) if $require;
emit ( " SW_${base}_IS_USABLE=Yes" , emit ( " SW_${base}_IS_USABLE=Yes" ,
'fi' ); 'fi' );
@ -934,6 +928,10 @@ sub handle_optional_interfaces( $ ) {
} }
if ( $wildcards ) { if ( $wildcards ) {
emit( '*)' ,
' ;;'
);
pop_indent;
emit( 'esac' ); emit( 'esac' );
pop_indent; pop_indent;
emit('done' ); emit('done' );

View File

@ -1429,16 +1429,16 @@ sub verify_required_interfaces( $ ) {
$physical =~ s/\+$/*/; $physical =~ s/\+$/*/;
emit( "${base}_IS_UP=\n", emit( "SW_${base}_IS_UP=\n",
'for interface in $(find_all_interfaces); do', 'for interface in $(find_all_interfaces); do',
' case $interface in', ' case $interface in',
" $physical)", " $physical)",
" interface_is_usable \$interface && ${base}_IS_UP=Yes && break", " interface_is_usable \$interface && SW_${base}_IS_UP=Yes && break",
' ;;', ' ;;',
' esac', ' esac',
'done', 'done',
'', '',
"if [ -z \"\$${base}_IS_UP\" ]; then", "if [ -z \"\$SW_${base}_IS_UP\" ]; then",
" startup_error \"None of the required interfaces $physical are available\"", " startup_error \"None of the required interfaces $physical are available\"",
"fi\n" "fi\n"
); );

View File

@ -124,7 +124,14 @@ deleteallchains() {
# Generate a list of all network interfaces on the system # Generate a list of all network interfaces on the system
# #
find_all_interfaces() { find_all_interfaces() {
${IP:-ip} link list | egrep '^[[:digit:]]+:' | cut -d ' ' -f2 | sed 's/:$//' ${IP:-ip} link list | egrep '^[[:digit:]]+:' | cut -d ' ' -f2 | sed -r 's/(@.*)?:$//'
}
#
# Generate a list of all network interfaces on the system that have an ipv4 address
#
find_all_interfaces1() {
${IP:-ip} -4 addr list | egrep '^[[:digit:]]+:' | cut -d ' ' -f2 | sed -r 's/(@.*)?:$//'
} }
# #

View File

@ -116,7 +116,14 @@ deleteallchains() {
# Generate a list of all network interfaces on the system # Generate a list of all network interfaces on the system
# #
find_all_interfaces() { find_all_interfaces() {
${IP:-ip} link list | egrep '^[[:digit:]]+:' | cut -d ' ' -f2 | sed 's/:$//' ${IP:-ip} link list | egrep '^[[:digit:]]+:' | cut -d ' ' -f2 | sed -r 's/(@.*)?:$//'
}
#
# Generate a list of all network interfaces on the system that have an ipv6 address
#
find_all_interfaces1() {
${IP:-ip} -6 addr list | egrep '^[[:digit:]]+:' | cut -d ' ' -f2 | sed -r 's/(@.*)?:$//'
} }
# #