mirror of https://github.com/apache/cloudstack.git
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.
This commit is contained in:
parent
657edb1a56
commit
1148ebfdcd
|
|
@ -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 ;
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
Loading…
Reference in New Issue