From 9775675d9790fc4a38f27786f5f0be6659b7a416 Mon Sep 17 00:00:00 2001 From: anthony Date: Wed, 27 Jun 2012 11:20:19 -0700 Subject: [PATCH] VPC : fixes for static nat --- .../xen/resource/CitrixResourceBase.java | 2 +- .../debian/config/opt/cloud/bin/vpc_func.sh | 30 +++++++++++++++++++ .../config/opt/cloud/bin/vpc_ipassoc.sh | 2 +- .../config/opt/cloud/bin/vpc_staticnat.sh | 15 ++++++---- 4 files changed, 41 insertions(+), 8 deletions(-) create mode 100755 patches/systemvm/debian/config/opt/cloud/bin/vpc_func.sh diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index 5c0ca6051e6..72f71586a17 100644 --- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -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); } } diff --git a/patches/systemvm/debian/config/opt/cloud/bin/vpc_func.sh b/patches/systemvm/debian/config/opt/cloud/bin/vpc_func.sh new file mode 100755 index 00000000000..f7111747339 --- /dev/null +++ b/patches/systemvm/debian/config/opt/cloud/bin/vpc_func.sh @@ -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 +} + diff --git a/patches/systemvm/debian/config/opt/cloud/bin/vpc_ipassoc.sh b/patches/systemvm/debian/config/opt/cloud/bin/vpc_ipassoc.sh index 6eb83898ab1..40c1e4d996a 100755 --- a/patches/systemvm/debian/config/opt/cloud/bin/vpc_ipassoc.sh +++ b/patches/systemvm/debian/config/opt/cloud/bin/vpc_ipassoc.sh @@ -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 diff --git a/patches/systemvm/debian/config/opt/cloud/bin/vpc_staticnat.sh b/patches/systemvm/debian/config/opt/cloud/bin/vpc_staticnat.sh index bcf0c5a950f..f25dfd8b477 100755 --- a/patches/systemvm/debian/config/opt/cloud/bin/vpc_staticnat.sh +++ b/patches/systemvm/debian/config/opt/cloud/bin/vpc_staticnat.sh @@ -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