From 1aa5bf4c3c30c474c081bcb8d89a4f06fd3e6e86 Mon Sep 17 00:00:00 2001 From: Lassulus Date: Fri, 28 Dec 2012 01:56:08 +0100 Subject: fixed netmask magic --- retiolum/scripts/tinc_setup/new_install.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'retiolum') diff --git a/retiolum/scripts/tinc_setup/new_install.sh b/retiolum/scripts/tinc_setup/new_install.sh index 579ebff9..82878673 100755 --- a/retiolum/scripts/tinc_setup/new_install.sh +++ b/retiolum/scripts/tinc_setup/new_install.sh @@ -17,6 +17,7 @@ HOSTN=${HOSTN:-$SYSHOSTN} NETNAME=${NETNAME:-retiolum} MASK4=${MASK4:-16} MASK6=${MASK6:-16} +RMASK=${RMASK:-255.255.0.0} URL=${URL:-http://euer.krebsco.de/retiolum/hosts.tar.gz} SURL=${SURL:-http://euer.krebsco.de/retiolum/supernodes.tar.gz} @@ -60,14 +61,13 @@ EOF host2subnet() { NEEDDOTSINSUB=$(expr 3 - $( echo $SUBNET4 | tr -C -d . | wc -c)) - FULLSUBNET=$(echo $SUBNET4$(eval "printf '.0'%.0s {1..${#NEEDDOTSINSUB}}"s)) - result=$(($(($((1 << $1)) - 1)) << $((32 - $1)))) - byte="" - for i in {0..2}; do - byte=.$(($result % 256))$byte - result=$(($result / 256)) - done - RETARDEDMASK=$result$byte + case $NEEDDOTSINSUB in + 3) FULLSUBNET=$SUBNET4.0.0.0 ;; + 2) FULLSUBNET=$SUBNET4.0.0 ;; + 1) FULLSUBNET=$SUBNET4.0 ;; + 0) FULLSUBNET=$SUBNET4 ;; + *) echo "cannot read subnet" && exit 1;; + esac } #check if ip is valid ipv4 function @@ -370,7 +370,7 @@ else echo '' >> tinc-up echo "addr4=\$(sed -n \"s|^ *Subnet *= *\\($SUBNET4[.][^ ]*\\) *$|\\1|p\" \$host)" >> tinc-up echo 'ifconfig $INTERFACE $addr4' >> tinc-up - echo "route add -net $FULLSUBNET netmask $RETARDEDMASK dev \$INTERFACE " >> tinc-up + echo "route add -net $FULLSUBNET netmask $RMASK dev \$INTERFACE " >> tinc-up fi #fix permissions -- cgit v1.2.3