diff --git a/patches/systemvm/debian/config/opt/cloud/bin/vpc_staticroute.sh b/patches/systemvm/debian/config/opt/cloud/bin/vpc_staticroute.sh new file mode 100755 index 00000000000..2a4593c7603 --- /dev/null +++ b/patches/systemvm/debian/config/opt/cloud/bin/vpc_staticroute.sh @@ -0,0 +1,93 @@ +#!/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@ + +source /root/func.sh +source /opt/cloud/bin/vpc_func.sh +lock="biglock" +locked=$(getLockFile $lock) +if [ "$locked" != "1" ] +then + exit 1 +fi + +usage() { + printf "Usage: %s: (-A|-D) -c < cidr > -l -g < gateway> \n" $(basename $0) >&2 +} + +#set -x + +static_route() { + local op=$1 + local publicIp=$2 + local gateway=$3 + local cidr=$4 + + logger -t cloud "$(basename $0): static route: public ip=$publicIp \ + gateway=$gateway cidr=$cidr op=$op" + #if adding, this might be a duplicate, so delete the old one first + [ "$op" == "add" ] && static_routet "del" $publicIp $gateway $cidr + + sudo ip route $op $cidr dev $ethDev via $gateway &>> $OUTFILE + result=$? + logger -t cloud "$(basename $0): done static route: public ip=$publicIp \ + gateway=$gateway cidr=$cidr op=$op" + + if [ "$op" == "del" ] + then + return 0 + fi + return $result +} + + + +gflag= +lflag= +cflag= +op="" +while getopts 'ADg:l:c:' OPTION + +do + case $OPTION in + A) op="add" + ;; + D) op="del" + ;; + g) gflag=1 + gateway="$OPTARG" + ;; + l) lflag=1 + publicIp="$OPTARG" + ;; + c) cflag=1 + cidr="$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_route $op $publicIp $gateway $cidr +result=$? +unlock_exit $result $lock $locked