CS-14784 support multiple subnets

resolved fixed
This commit is contained in:
anthony 2012-05-16 16:25:01 -07:00
parent 2e2e5ee59d
commit 297996e907
4 changed files with 21 additions and 81 deletions

View File

@ -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);

View File

@ -751,18 +751,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();

View File

@ -1699,10 +1699,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) {
@ -1732,19 +1728,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);

View File

@ -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