From 1f600070d9489783b426a67e71fcfa4837db4fe7 Mon Sep 17 00:00:00 2001 From: baigk Date: Thu, 17 Sep 2015 09:55:48 +0800 Subject: lack broadcast parameter when move ips from nic to br_install and lead to the broadcast add is 0.0.0.0 JIRA: COMPASS-57 Change-Id: I7b5ff7dc4f6566d8b28b00bda417b4da98ac6c18 Signed-off-by: baigk --- deploy/network.sh | 74 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file 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 } -- cgit 1.2.3-korg