From 1148ebfdcdff3acd5ec401eeb3dd3797a4bed624 Mon Sep 17 00:00:00 2001 From: Naredula Janardhana Reddy Date: Wed, 9 Nov 2011 16:24:42 +0530 Subject: [PATCH] bug 11590: reviewed-by: Abhi Summary of Changes: while adding a primary address to the domR interface, previous primaray addresses(ip) are removed and added as with 32-bit netmask. This is to avoid two same ip's with different netmask attached to the interface. --- .../systemvm/debian/config/root/ipassoc.sh | 43 +++++++++++++++++++ .../VirtualNetworkApplianceManagerImpl.java | 7 ++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/patches/systemvm/debian/config/root/ipassoc.sh b/patches/systemvm/debian/config/root/ipassoc.sh index b825bc4eef9..17278a3fd9b 100644 --- a/patches/systemvm/debian/config/root/ipassoc.sh +++ b/patches/systemvm/debian/config/root/ipassoc.sh @@ -103,13 +103,56 @@ del_vpn_chain_for_ip () { logger -t cloud "$(basename $0): vpn chain did not exist for $pubIp, cleaned up" } +convert_primary_to_32() { + local existingIpMask=$(sudo ip addr show dev $ethDev | grep "inet " | awk '{print $2}') + local primary=$(echo $1 | awk -F'/' '{print $1}') +# add 32 mask to the existing primary + for ipMask in $existingIpMask + do + local ipNoMask=$(echo $ipMask | awk -F'/' '{print $1}') + local mask=$(echo $ipMask | awk -F'/' '{print $2}') + if [ "$ipNoMask" == "$primary" ] + then + continue + fi + if [ "$mask" != "32" ] + then + sudo ip addr add dev $ethDev $ipNoMask/32 + fi + done +#delete primaries + for ipMask in $existingIpMask + do + local ipNoMask=$(echo $ipMask | awk -F'/' '{print $1}') + local mask=$(echo $ipMask | awk -F'/' '{print $2}') + if [ "$ipNoMask" == "$primary" ] + then + continue + fi + if [ "$mask" != "32" ] + then + # this would have erase all primaries and secondaries in the previous loop, so we need to eat up the error. + sudo ip addr del dev $ethDev $ipNoMask/$mask > /dev/null + fi + done +} + + add_nat_entry() { local pubIp=$1 logger -t cloud "$(basename $0):Adding nat entry for ip $pubIp on interface $ethDev" local ipNoMask=$(echo $1 | awk -F'/' '{print $1}') + local mask=$(echo $1 | awk -F'/' '{print $2}') sudo ip link show $ethDev | grep "state DOWN" > /dev/null local old_state=$? + + convert_primary_to_32 $pubIp sudo ip addr add dev $ethDev $pubIp + if [ "$mask" != "32" ] && [ "$mask" != "" ] + then + # remove if duplicat ip with 32 mask, this happens when we are promting the ip to primary + sudo ip addr del dev $ethDev $ipNoMask/32 > /dev/null + fi sudo iptables -D FORWARD -i $ethDev -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT sudo iptables -D FORWARD -i eth0 -o $ethDev -j ACCEPT sudo iptables -t nat -D POSTROUTING -j SNAT -o $ethDev --to-source $ipNoMask ; diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 6eb5e063a7a..2c030be9b7a 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -2194,7 +2194,12 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian ip.setTrafficType(network.getTrafficType()); ip.setNetworkTags(network.getTags()); ipsToSend[i++] = ip; - firstIP = false; + /* send the firstIP = true for the first Add, this is to create primary on interface*/ + if (!firstIP || add) { + firstIP = false; + } + + } IpAssocCommand cmd = new IpAssocCommand(ipsToSend); cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, router.getPrivateIpAddress());