ctdb-scripts: Add IPv6 addresses support in ip_maskbits_iface()
authorMartin Schwenke <martin@meltin.net>
Fri, 21 Nov 2014 03:37:54 +0000 (14:37 +1100)
committerKarolin Seeger <kseeger@samba.org>
Wed, 10 Dec 2014 19:56:09 +0000 (20:56 +0100)
It also prints a third word, the address family.  This is either
"inet" or "inet6".

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
(cherry picked from commit ed029ae0a1faa56bf882a71d10828e2a90ab0bc7)

ctdb/config/functions

index 05bcd3826823725bbf1bba1b6b1ecfdfe85771b1..eca767ea4996ca3010a3c0aada1a6f1fe2eaab10 100755 (executable)
@@ -864,8 +864,15 @@ ip_maskbits_iface ()
 {
     _addr="$1"
 
-    ip addr show to "${_addr}/32" 2>/dev/null | \
-       awk '$1 == "inet" { print gensub(".*/", "", 1, $2), $NF }'
+    case "$_addr" in
+       *:*) _family="inet6" ; _bits=128 ;;
+       *)   _family="inet"  ; _bits=32  ;;
+    esac
+
+    ip addr show to "${_addr}/${_bits}" 2>/dev/null | \
+       awk -v family="${_family}" \
+           'NR == 1 { iface = gensub(":$", "", 1, $2) } \
+             $1 ~ /inet/ { print gensub(".*/", "", 1, $2), iface, family }'
 }
 
 drop_ip ()