summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2014-11-24 20:49:46 +1100
committerMartin Schwenke <martin@meltin.net>2014-11-24 20:49:46 +1100
commit85628a2ba97f28cdb21a3efade73c38304f28416 (patch)
treecd82d8e646b24be0bbc2a38eb223a68138b18ce5
parent393c054b1dc3b6f1eccd2614755c424573a8dc0e (diff)
downloadautocluster-85628a2ba97f28cdb21a3efade73c38304f28416.tar.gz
autocluster-85628a2ba97f28cdb21a3efade73c38304f28416.tar.xz
autocluster-85628a2ba97f28cdb21a3efade73c38304f28416.zip
New function ipv4_prefix_to_netmask()
Allows calculation of netmask from prefix. Signed-off-by: Martin Schwenke <martin@meltin.net>
-rwxr-xr-xautocluster25
1 files changed, 25 insertions, 0 deletions
diff --git a/autocluster b/autocluster
index 62cbdfd..3e9d88e 100755
--- a/autocluster
+++ b/autocluster
@@ -951,6 +951,31 @@ setup_base()
run_hooks setup_base_hooks
}
+ipv4_prefix_to_netmask ()
+{
+ local prefix="$1"
+
+ local div=$(($prefix / 8))
+ local mod=$(($prefix % 8))
+
+ local octet
+ for octet in 1 2 3 4 ; do
+ if [ $octet -le $div ] ; then
+ echo -n "255"
+ elif [ $mod -ne 0 -a $octet -eq $(($div + 1)) ] ; then
+ local shift=$((8 - $mod))
+ echo -n $(( (255 >> $shift << $shift) ))
+ else
+ echo -n 0
+ fi
+ if [ $octet -lt 4 ] ; then
+ echo -n '.'
+ fi
+ done
+
+ echo
+}
+
# setup various networking components
setup_network()
{