From 9ea233d55f2c55eceae6fa7b73de520981b3b5bd Mon Sep 17 00:00:00 2001 From: Tom Eastep Date: Sun, 13 May 2012 15:53:02 -0700 Subject: [PATCH] Split a couple of functions with address-family dependent logic. Signed-off-by: Tom Eastep --- Shorewall/lib.core | 92 ++++++++++++++++++++++++++-------------------- 1 file changed, 53 insertions(+), 39 deletions(-) diff --git a/Shorewall/lib.core b/Shorewall/lib.core index 1ce4f8fe1..5cc160d91 100644 --- a/Shorewall/lib.core +++ b/Shorewall/lib.core @@ -171,44 +171,6 @@ interface_is_up() { [ -n "$($IP -$g_family link list dev $1 2> /dev/null | grep -e '[<,]UP[,>]')" ] } -# -# Determine if interface is usable from a Netfilter perspective -# -interface_is_usable() # $1 = interface -{ - local status; - status=0 - - if [ "$1" != lo -a "$COMMAND" != enable ]; then - if [ $g_family -eq 4 ]; then - if interface_is_up $1 && [ "$(find_first_interface_address_if_any $1)" != 0.0.0.0 ]; then - run_isusable_exit $1 - status=$? - fi - else - if interface_is_up $1 && [ "$(find_first_interface_address_if_any $1)" != :: ]; then - run_isusable_exit $1 - status=$? - fi - fi - fi - - return $status -} - -# -# Find interface addresses--returns the set of addresses assigned to the passed -# device -# -find_interface_addresses() # $1 = interface -{ - if [ $g_family -eq 4 ]; then - $IP -f inet addr show $1 2> /dev/null | grep inet\ | sed 's/\s*inet //;s/\/.*//;s/ peer.*//' - else - $IP -f inet6 addr show $1 2> /dev/null | grep 'inet6 2' | sed 's/\s*inet6 //;s/\/.*//;s/ peer.*//' - fi -} - # # echo the list of networks routed out of a given interface # @@ -659,9 +621,35 @@ EOF ################################################################################# # IPv4-specific Functions ################################################################################# +# +# Determine if interface is usable from a Netfilter perspective +# +interface_is_usable() # $1 = interface +{ + local status; + status=0 + + if [ "$1" != lo -a "$COMMAND" != enable ]; then + if interface_is_up $1 && [ "$(find_first_interface_address_if_any $1)" != 0.0.0.0 ]; then + run_isusable_exit $1 + status=$? + fi + fi + + return $status +} + +# +# Find interface addresses--returns the set of addresses assigned to the passed device +# +find_interface_addresses() # $1 = interface +{ + $IP -f inet addr show $1 2> /dev/null | grep inet\ | sed 's/\s*inet //;s/\/.*//;s/ peer.*//' +} + +# # Find the value 'weight' in the passed arguments then echo the next value # - find_weight() { while [ $# -gt 1 ]; do [ "x$1" = xweight ] && echo $2 && return @@ -1032,6 +1020,32 @@ get_all_bcasts() ################################################################################# # IPv6-specific Functions ################################################################################# +# +# Determine if interface is usable from a Netfilter perspective +# +interface_is_usable() # $1 = interface +{ + local status; + status=0 + + if [ "$1" != lo -a "$COMMAND" != enable ]; then + if interface_is_up $1 && [ "$(find_first_interface_address_if_any $1)" != :: ]; then + run_isusable_exit $1 + status=$? + fi + fi + + return $status +} + +# +# Find interface addresses--returns the set of addresses assigned to the passed device +# +find_interface_addresses() # $1 = interface +{ + $IP -f inet6 addr show $1 2> /dev/null | grep 'inet6 2' | sed 's/\s*inet6 //;s/\/.*//;s/ peer.*//' +} + # # Get all interface addresses with VLSMs #