diff options
Diffstat (limited to 'net-scripts/net/bridge.sh')
-rw-r--r-- | net-scripts/net/bridge.sh | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/net-scripts/net/bridge.sh b/net-scripts/net/bridge.sh index 67af002..2d4e6f5 100644 --- a/net-scripts/net/bridge.sh +++ b/net-scripts/net/bridge.sh @@ -36,29 +36,33 @@ bridge_check_installed() { # Returns the interfaces added to the given bridge bridge_get_ports() { brctl show 2>/dev/null \ - | sed -n -e '/^'"$1"'/,/^\S/ { /^\('"$1"'\|\t\)/s/^.*\t//p }' + | sed -n -e '/^'"$1"'[[:space:]]/,/^\S/ { /^\('"$1"'[[:space:]]\|\t\)/s/^.*\t//p }' } # char* bridge_get_bridge(char *interface) # # Returns the bridge interface of the given interface bridge_get_bridge() { - local x="$( brctl show 2>/dev/null \ - | sed -e '1 {d}; /^[^ ]/ { N }; /.*'"$1"'.*/ {s/^\([^ \t]\+\).*/\1/p}; d')" - - local -a a=( ${x} ) - if [[ ${#a[@]} == "1" ]] ; then - echo "${x}" - elif [[ $1 == "${a[3]}" ]] ; then - echo "${a[0]}" - fi + local myiface="$1" + local bridge= idx= stp= iface= x= + while read bridge idx stp iface x ; do + if [[ -z ${iface} ]] ; then + iface="${stp}" + stp="${idx}" + idx="${bridge}" + fi + if [[ ${iface} == "${myiface}" ]] ; then + echo "${bridge}" + return 0 + fi + done < <(brctl show 2>/dev/null) } # bool bridge_exists(char *interface) # # Returns 0 if the bridge exists, otherwise 1 bridge_exists() { - brctl show 2>/dev/null | grep -q "^$1" + brctl show 2>/dev/null | grep -q "^$1[[:space:]]" } # bool bridge_create(char *interface) |