aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustin chi <chigang@huawei.com>2015-09-17 11:03:33 +0000
committerGerrit Code Review <gerrit@172.30.200.206>2015-09-17 11:03:33 +0000
commite784578ee4f155f195506b10cf32f781b39be56c (patch)
treeebf09a5cce12b65bf8491396d3dcf69d025c38af
parent9ea235214f7206398877314b5bb289dbbb952254 (diff)
parent1f600070d9489783b426a67e71fcfa4837db4fe7 (diff)
Merge "lack broadcast parameter when move ips from nic to br_install and lead to the broadcast add is 0.0.0.0"
-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
}