aboutsummaryrefslogtreecommitdiffstats
path: root/deploy/network.sh
diff options
context:
space:
mode:
Diffstat (limited to 'deploy/network.sh')
-rwxr-xr-xdeploy/network.sh74
1 files changed, 56 insertions, 18 deletions
diff --git a/deploy/network.sh b/deploy/network.sh
index 864ec011..a5344f58 100755
--- a/deploy/network.sh
+++ b/deploy/network.sh
@@ -8,27 +8,61 @@ function destroy_bridge()
{
bridge=$1
nic=$2
- ips=$(ip addr show $bridge | grep 'inet ' | awk -F' ' '{print $2}')
- routes=$(ip route show | grep $bridge)
+ install_gw="$3"
+
+ brige_info=$(ip addr show $bridge 2>/dev/null)
+ if [[ -z $brige_info ]]; then
+ return
+ fi
+ ips=`echo "$brige_info" | grep 'inet ' | grep -v $install_gw | sed "s/inet //g"`
+
+ routes=$(ip route show | grep $bridge | grep -v $install_gw)
ip link set $bridge down
brctl delbr $bridge
- for ip in $ips; do
- ip addr add $ip dev $nic
- done
+ if [[ -n $ips ]]; then
+ echo "$ips" | while read line; do
+ echo $line | sed "s/$bridge/dev $nic/g" | xargs ip addr add | true
+ done
+ fi
- echo "$routes" | while read line; do
- echo $line | sed "s/$bridge/$nic/g" | xargs ip route add | true
+ if [[ -n $routes ]]; then
+ echo "$routes" | while read line; do
+ echo $line | sed "s/$bridge/$nic/g" | xargs ip route add | true
+ done
+ fi
+}
+
+function get_broadcast_addr()
+{
+ ip=(${1//[!0-9]/ })
+ mask=(${2//[!0-9]/ })
+
+ for i in {0..3}; do
+ num=$((${ip[$i]} | $((${mask[$i]} ^ 255))))
+ if [[ -z $broadcast ]]; then
+ broadcast="$num"
+ else
+ broadcast="$broadcast.$num"
+ fi
done
+ echo ${broadcast}
+}
+
+function get_mask_len()
+{
+ mask=`echo $1 | awk -F'.' '{print ($1*(2^24)+$2*(2^16)+$3*(2^8)+$4)}'`
+ mask_len=`echo "obase=2;${mask}"|bc|awk -F'0' '{print length($1)}'`
+ echo $mask_len
}
function create_bridge()
{
bridge=$1
nic=$2
- ips=$(ip addr show $nic | grep 'inet ' | awk -F' ' '{print $2}')
+ ips=$(ip addr show $nic | grep 'inet ' | sed "s/inet //g")
routes=$(ip route show | grep $nic)
ip addr flush $nic
@@ -37,21 +71,25 @@ function create_bridge()
brctl addif $bridge $nic
ip link set $bridge up
- for ip in $ips; do
- ip addr add $ip dev $bridge
- done
+ if [[ -n $ips ]]; then
+ echo "$ips" | while read line; do
+ echo $line | sed -e "s/$nic/dev $bridge/g" | xargs ip addr add
+ done
+ fi
- mask=`echo $INSTALL_MASK | awk -F'.' '{print ($1*(2^24)+$2*(2^16)+$3*(2^8)+$4)}'`
- mask_len=`echo "obase=2;${mask}"|bc|awk -F'0' '{print length($1)}'`
- ip addr add $INSTALL_GW/$mask_len dev $bridge
+ mask_len=`get_mask_len $INSTALL_MASK`
+ broadcast=`get_broadcast_addr $INSTALL_GW $INSTALL_MASK`
+ ip addr add $INSTALL_GW/$mask_len brd $broadcast dev $bridge
- echo "$routes" | while read line; do
- echo $line | sed "s/$nic/$bridge/g" | xargs ip route add | true
- done
+ if [[ -n $routes ]]; then
+ echo "$routes" | while read line; do
+ echo $line | sed "s/$nic/$bridge/g" | xargs ip route add | true
+ done
+ fi
}
function setup_om_bridge() {
- destroy_bridge br_install $OM_NIC
+ destroy_bridge br_install $OM_NIC $INSTALL_GW
create_bridge br_install $OM_NIC
}