From 2c1dc421c236d9f22cf192d399073aed62333a1f Mon Sep 17 00:00:00 2001 From: anthony Date: Wed, 16 May 2012 16:41:45 -0700 Subject: [PATCH] CS-14784 support multiple subnets resolved fixed --- .../VirtualRoutingResource.java | 9 ++- .../vmware/resource/VmwareResource.java | 13 ++-- .../xen/resource/CitrixResourceBase.java | 17 ++--- .../systemvm/debian/config/root/ipassoc.sh | 66 ++----------------- 4 files changed, 22 insertions(+), 83 deletions(-) diff --git a/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java b/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java index 4527404e7aa..d4ae4fa86ac 100755 --- a/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java +++ b/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java @@ -617,17 +617,16 @@ public class VirtualRoutingResource implements Manager { } else { command.add("-D"); } - String cidrSize = Long.toString(NetUtils.getCidrSize(vlanNetmask)); + if (sourceNat) { command.add("-s"); } if (firstIP) { command.add( "-f"); - command.add( "-l", publicIpAddress + "/" + cidrSize); - } else { - command.add("-l", publicIpAddress); - } + } + String cidrSize = Long.toString(NetUtils.getCidrSize(vlanNetmask)); + command.add( "-l", publicIpAddress + "/" + cidrSize); String publicNic = "eth" + nicNum; command.add("-c", publicNic); diff --git a/core/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/core/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java index 0718db16818..dc2a9fc3ec2 100755 --- a/core/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java +++ b/core/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java @@ -755,19 +755,16 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa } else { args = " -D "; } - String cidrSize = Long.toString(NetUtils.getCidrSize(vlanNetmask)); if (sourceNat) { args += " -s "; } if (firstIP) { args += " -f "; - args += " -l "; - args += publicIpAddress + "/" + cidrSize; - } else { - args += " -l "; - args += publicIpAddress; - } - + } + + String cidrSize = Long.toString(NetUtils.getCidrSize(vlanNetmask)); + args += " -l "; + args += publicIpAddress + "/" + cidrSize; args += " -c "; args += "eth" + publicNicInfo.first(); diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index 9208b2d88f4..4b8146b3be2 100644 --- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -1695,10 +1695,6 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe boolean removeVif = false; if (add && correctVif == null) { addVif = true; - } else if (!add && firstIP) { - /* FIXME: This is incorrect. Because you can only tell if it's the first IP in this bundle of ip address which send to the router, - * but don't know if it's the only IP left in the router - because we didn't send all the related vlan's IPs to the router now. */ - removeVif = true; } if (addVif) { @@ -1728,19 +1724,18 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } else { args += " -D "; } - String cidrSize = Long.toString(NetUtils.getCidrSize(vlanNetmask)); + if (sourceNat) { args += " -s"; - } + } if (firstIP) { args += " -f"; - args += " -l "; - args += publicIpAddress + "/" + cidrSize; - } else { - args += " -l "; - args += publicIpAddress; } + String cidrSize = Long.toString(NetUtils.getCidrSize(vlanNetmask)); + args += " -l "; + args += publicIpAddress + "/" + cidrSize; + args += " -c "; args += "eth" + correctVif.getDevice(conn); diff --git a/patches/systemvm/debian/config/root/ipassoc.sh b/patches/systemvm/debian/config/root/ipassoc.sh index e9d75caa3d6..7087e7f4dae 100644 --- a/patches/systemvm/debian/config/root/ipassoc.sh +++ b/patches/systemvm/debian/config/root/ipassoc.sh @@ -96,40 +96,6 @@ 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 - ip_addr_add $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 -} - remove_routing() { local pubIp=$1 logger -t cloud "$(basename $0):Remove routing $pubIp on interface $ethDev" @@ -169,8 +135,13 @@ copy_routes_from_main() { ip_addr_add() { local dev="$1" local ip="$2" + local ipNoMask=$(echo $ip | awk -F'/' '{print $1}') + local mask=$(echo $ip | awk -F'/' '{print $2}') + local subnet=`TERM=linux ipcalc $ip | grep Network | awk -F' ' '{print $2}' | awk -F'/' '{print $1}'` local brd=`TERM=linux ipcalc $ip|grep Broadcast|awk -F' ' '{print $2}'` - sudo ip addr add dev $dev $ip broadcast $brd + sudo ip addr add dev $dev $subnet/$mask broadcast $brd > /dev/null + sudo ip addr add dev $dev $ipNoMask/32 + } add_routing() { @@ -241,13 +212,7 @@ add_first_ip() { sudo ip link show $ethDev | grep "state DOWN" > /dev/null local old_state=$? - convert_primary_to_32 $pubIp ip_addr_add $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 @@ -326,24 +291,7 @@ remove_an_ip () { local existingIpMask=$(sudo ip addr show dev $ethDev | grep inet | awk '{print $2}' | grep -w $ipNoMask) [ "$existingIpMask" == "" ] && return 0 remove_snat $1 - local existingMask=$(echo $existingIpMask | awk -F'/' '{print $2}') - if [ "$existingMask" == "32" ] - then - sudo ip addr del dev $ethDev $existingIpMask - result=$? - fi - - if [ "$existingMask" != "32" ] - then - replaceIpMask=`sudo ip addr show dev $ethDev | grep inet | grep -v $existingIpMask | awk '{print $2}' | sort -t/ -k2 -n|tail -1` - sudo ip addr del dev $ethDev $existingIpMask; - if [ -n "$replaceIpMask" ]; then - sudo ip addr del dev $ethDev $replaceIpMask; - replaceIp=`echo $replaceIpMask | awk -F/ '{print $1}'`; - ip_addr_add $ethDev $replaceIp/$existingMask - fi - result=$? - fi + sudo ip addr del dev $ethDev $existingIpMask if [ $result -gt 0 -a $result -ne 2 ] then