Remove netmask from network_map
authorMartin Schwenke <martin@meltin.net>
Mon, 24 Nov 2014 10:01:37 +0000 (21:01 +1100)
committerMartin Schwenke <martin@meltin.net>
Tue, 25 Nov 2014 00:24:56 +0000 (11:24 +1100)
This removes the /24 assumption, embeds the prefix into the ip field
and calculates netmask in the only place it is needed.

Signed-off-by: Martin Schwenke <martin@meltin.net>
autocluster
config.d/00base.defconf
host_setup/setup_networks.sh
templates/basic-postinstall.sh

index 3e9d88e99782313244614645497b4f0942e0def3..0eb26f5076a603a723c60c5d69e4ef1260d109b9 100755 (executable)
@@ -350,15 +350,14 @@ make_network_map ()
        local net="${ip_bits%/*}"
        local netname="acnet_${net//./_}"
 
-       local ip="${net%.*}.${IPNUM}"
-       local mask="255.255.255.0"
+       local ip="${net%.*}.${IPNUM}/${ip_bits#*/}"
 
        # This can be used to override the variables in the echo
        # statement below.  The hook can use any other variables
        # available in this function.
        run_hooks hack_network_map_hooks
 
-       echo "${netname} ${dev} ${ip} ${mask} ${mac} ${opts}"
+       echo "${netname} ${dev} ${ip} ${mac} ${opts}"
        count=$(($count + 1))
     done >"$network_map"
 }
@@ -719,8 +718,8 @@ guess_install_network ()
     # specified then use the IP address associated with it.
     INSTALL_IP=""
     INSTALL_GW=""
-    local netname dev ip mask mac opts
-    while read netname dev ip mask mac opts; do
+    local netname dev ip mac opts
+    while read netname dev ip mac opts; do
        local o
        for o in $opts ; do
            case "$o" in
@@ -1008,11 +1007,11 @@ setup_network()
     diskimage rm_rf "/etc/udev/rules.d/70-persistent-net.rules"
 
     echo "Setting up network interfaces: "
-    local netname dev ip mask mac opts
-    while read netname dev ip mask mac opts; do
+    local netname dev ip mac opts
+    while read netname dev ip mac opts; do
        echo "  $dev"
 
-       local o gw
+       local o gw addr mask
        gw=""
        for o in $opts ; do
            case "$o" in
@@ -1021,12 +1020,15 @@ setup_network()
            esac
        done
 
+       addr=${ip%/*}
+       mask=$(ipv4_prefix_to_netmask ${ip#*/})
+
        cat <<EOF | \
            diskimage put - "/etc/sysconfig/network-scripts/ifcfg-${dev}"
 DEVICE=$dev
 ONBOOT=yes
 TYPE=Ethernet
-IPADDR=$ip
+IPADDR=$addr
 NETMASK=$mask
 HWADDR=$mac
 ${gw:+GATEWAY=}${gw}
index e141e51ea18b685ebb68bd7de287a305a2b627b1..f366f1ee42625b5f21c775cff656a7a8357d966e 100644 (file)
@@ -225,8 +225,6 @@ defconf DNSSEARCH "$DOMAIN" \
 # * First network is private and contains the CTDB node addresses.
 # * Items look like: net/bits,dev[,nat|bridge=host_iface][,gw=gateway_ip]
 
-# * Right now autocluster only supports 24 bit networks.  This will
-#   be improved in the future.
 defconf NETWORKS "10.0.0.0/24,eth0,gw=10.0.0.1 10.0.1.0/24,eth1 10.0.2.0/24,eth2" \
        "<list>" "description of IP networks"
 
@@ -263,15 +261,6 @@ make_public_addresses()
 
 networks_post_config_hook ()
 {
-    local n
-    for n in $NETWORKS ; do
-       local ip_mask="${n%%,*}"
-       local mask="${ip_mask#*/}"
-
-       [ "$mask" = "24" ] || \
-           die "Network maskbits other than 24 unsupported in \"$n\""
-    done
-
     [ -z "$IPBASE" -a -z "$IPNET0" -a -z "$IPNET1" -a -z "$IPNET2" ] || \
        die "Configuration variables IPBASE, IPNET0/1/2 unsupported - please use NETWORKS"
 
@@ -290,8 +279,8 @@ defconf NETWORK_TEMPLATE "|network_template" \
 
 network_template ()
 {
-    local netname dev ip mask mac opts
-    while read netname dev ip mask mac opts ; do
+    local netname dev ip mac opts
+    while read netname dev ip mac opts ; do
        cat <<EOF
     <interface type='network'>
       <mac address='${mac}'/>
index c2663b4603ef20e21764d285bfe4f9518d556884..e1758637d2ea3d4e30fa1b4d30b99fa466cfa0aa 100755 (executable)
@@ -20,8 +20,7 @@ gen_xml ()
 {
     local netname="$1"
     local ip="$2"
-    local mask="$3"
-    local opts="$4"
+    local opts="$3"
 
     local uuid=$(uuidgen)
 
@@ -52,10 +51,12 @@ EOF
 EOF
     fi
 
+    ip_addr=${ip%/*}
+    ip_mask=${ip#*/}
+
     cat <<EOF
   <bridge name='${netname}' stp='on' forwardDelay='0' />
-  <ip address='${ip}' netmask='${mask}'>
-  </ip>
+  <ip address='${ip_addr}' prefix='${ip_mask}' />
 </network>
 EOF
 }
@@ -76,10 +77,10 @@ if [ $? -ne 0 -o -z "$network_map" ]; then
 fi
 
 
-while read netname dev ip mask mac opts ; do
+while read netname dev ip mac opts ; do
     echo "Setting up network \"${netname}\""
     t=$(mktemp)
-    gen_xml "$netname" "$ip" "$mask" "$opts" >"$t"
+    gen_xml "$netname" "$ip" "$opts" >"$t"
     if $dry_run ; then
        cat "$t"
     else
index d81b3c1593beb2c4c2c09405f199c6ba372f1395..f630b70618004cf4f3675410576a939fa9a5eb9c 100644 (file)
@@ -21,7 +21,7 @@ dev=$(ip link show |
 echo "Forcing up network interface \"$dev\""
 
 ip link set $dev up
-ip addr add @@INSTALL_IP@@/24 dev $dev
+ip addr add @@INSTALL_IP@@ dev $dev
 if [ -n "@@INSTALL_GW@@" ] ; then
     ip route add default via @@INSTALL_GW@@
 fi