VPC : fixes for static nat

This commit is contained in:
anthony 2012-06-27 11:20:19 -07:00
parent e2fd2f7515
commit 9775675d97
4 changed files with 41 additions and 8 deletions

View File

@ -7449,6 +7449,6 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
private SetStaticRouteAnswer execute(SetStaticRouteCommand cmd) {
// TODO Auto-generated method stub
return null;
return new SetStaticRouteAnswer(cmd, true, null);
}
}

View File

@ -0,0 +1,30 @@
#!/usr/bin/env bash
# Copyright 2012 Citrix Systems, Inc. Licensed under the
# Apache License, Version 2.0 (the "License"); you may not use this
# file except in compliance with the License. Citrix Systems, Inc.
# reserves all rights not expressly granted by the License.
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Automatically generated by addcopyright.py at 04/03/2012
# @VERSION@
getEthByIp (){
local ip=$1
for dev in `ls -1 /sys/class/net | grep eth`
do
sudo ip addr show dev $dev | grep $ip > /dev/null
if [ $? -eq 0 ]
then
echo $dev
return 0
fi
done
return 1
}

View File

@ -65,7 +65,7 @@ add_an_ip () {
sudo arping -c 3 -I $ethDev -A -U -s $pubIp $pubIp
fi
local tableNo=${ethDev:3}
sudo iptables-save -t mangle | grep "PREROUTING -i $ethDev -m state --state NEW -j CONNMARK --set-mark" 2>/dev/null
sudo iptables-save -t mangle | grep "PREROUTING -i $ethDev -m state --state NEW -j CONNMARK --set-xmark" 2>/dev/null
if [ $? -gt 0 ]
then
sudo iptables -t mangle -A PREROUTING -i $ethDev -m state --state NEW -j CONNMARK --set-mark $tableNo 2>/dev/null

View File

@ -14,7 +14,7 @@
# @VERSION@
source /root/func.sh
source /opt/cloud/bin/vpc_func.sh
lock="biglock"
locked=$(getLockFile $lock)
if [ "$locked" != "1" ]
@ -51,7 +51,7 @@ static_nat() {
# add mark to force the package go out through the eth the public IP is on
(sudo iptables -t mangle $op PREROUTING -s $instIp -j MARK \
--set-mark $tableNo &> $OUTFILE || [ "$op" == "-D" ]) &&
(sudo iptables -t nat $op2 POSTROUTING -i $ethDev -s $instIp -j SNAT \
(sudo iptables -t nat $op2 POSTROUTING -o $ethDev -s $instIp -j SNAT \
--to-source $publicIp &>> $OUTFILE )
result=$?
logger -t cloud "$(basename $0): done static nat entry public ip=$publicIp op=$op result=$result"
@ -68,7 +68,7 @@ rflag=
lflag=
dflag=
op=""
while getopts 'ADr:l:d:' OPTION
while getopts 'ADr:l:' OPTION
do
case $OPTION in
@ -82,15 +82,18 @@ do
l) lflag=1
publicIp="$OPTARG"
;;
d) dflag=1
ethDev="$OPTARG"
;;
?) usage
unlock_exit 2 $lock $locked
;;
esac
done
ethDev=$(getEthByIp $publicIp)
result=$?
if [ $result -gt 0 ]
then
unlock_exit $result $lock $locked
fi
OUTFILE=$(mktemp)
static_nat $op $publicIp $instanceIp