2
# Copyright (C) 2000-2006 SWsoft. All rights reserved.
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
# Common stuff for vzctl helper scripts
20
# get the name of the script
21
SELFNAME=`basename $0`
27
VZ_INVALID_PARAMETER_SYNTAX=20
28
VZ_FS_NO_DISK_SPACE=46
36
VE_STATE_DIR="/var/lib/vzctl/veip/"
37
CONF_DIR="/etc/vz/conf/"
39
ARPSEND_CMD="arpsend -c 1 -w 1"
42
# Prints error message and exits
47
# vzerror "Fatal error" 1
50
# print errors to stdout too
52
echo "$SELFNAME ERROR: $1"
56
# Prints warning message
60
# vzwarning Invalid user
63
echo "$SELFNAME WARNING: $*"
66
# Prints debug message
70
# vzdebug Trying to start ls
76
# Checks if environment variable exists,
77
# and exits with exit code 1 if not
81
# vzcheckvar VEID IP_ADDR
85
if eval test "\"x\$$VAR\"" = "x"; then
86
vzerror "Missing parameter: $VAR" $VZ_INVALID_PARAMETER_SYNTAX
91
# This function fills $NETDEVICES with all network interfaces
92
# You should always call it before calling vzarp
93
function vzgetnetdev()
95
# Get a list of interfaces, excluding ones with LOOPBACK NOARP or SLAVE flags
96
NETDEVICES=`${IP_CMD} link list | egrep -v -E "LOOPBACK|NOARP|SLAVE" | \
97
awk "/^[0-9].*:/&&/UP/ {print \\$2}" | sed -e "s/:\$//"`
100
# Adds/deletes public ARP records for given IP for all interfaces
102
# $1 - should be either "add" or "del"
104
# $NETDEVICES - Network devices used to take MAC addresses from
109
[ -z "${NETDEVICES}" ] && vzwarning "Device list is empty"
110
for DEV in $NETDEVICES; do
111
if [ $(cat /proc/sys/net/ipv4/conf/$DEV/proxy_arp) == 0 ] ; then
112
vzwarning "Function proxy_arp for $DEV is set to 0. Enable with 'sysctl -w net.ipv4.conf.$DEV.proxy_arp=1'. See /usr/share/doc/vzctl/README.Debian."
114
${IP_CMD} neigh $1 proxy $2 dev $DEV > /dev/null 2>&1
118
# Send ARP request to detect that somebody already have this IP
119
function vzarpipdetect()
125
[ -z "${1}" ] && return
126
[ "${SKIP_ARPDETECT}" = "yes" ] && return
132
for DEV in $NETDEVICES; do
133
${ARPSEND_CMD} -D ${cmd} $DEV || vzwarning "${ARPSEND_CMD} -D ${cmd} $DEV FAILED"
137
# Send ARP request to update neighbour ARP caches
138
function vzarpipset()
144
[ -z "${1}" ] && return
146
for dev in $NETDEVICES; do
148
opt="-i ${ip} -e ${ip}"
149
${ARPSEND_CMD} -U ${opt} ${dev} || vzwarning "${ARPSEND_CMD} -U ${opt} ${dev} FAILED"
154
# Sets VE0 source routing for given IP
157
function vzaddrouting()
161
if ! ${IP_CMD} route list $1 | grep "$1 dev venet0" > /dev/null 2>&1;
163
if [ -n "${VE_ROUTE_SRC_DEV}" ]; then
164
device="dev ${VE_ROUTE_SRC_DEV}"
166
src_addr=`ip route list table local ${device} | grep '^local'|\
167
cut -d' ' -f2 | grep -v '^127\.' | head -n 1`
168
if [ -z "${src_addr}" ]; then
169
vzerror "Unable to get source ip [${device}]" $VZ_CANT_ADDIP
171
${IP_CMD} route add $1 dev venet0 src ${src_addr} || \
172
vzerror "Unable to add route ${IP_CMD} route add $1 dev venet0 src ${src_addr}" $VZ_CANT_ADDIP
176
# Deletes VE0 source routing for given IP
179
function vzdelrouting()
181
if ${IP_CMD} route list $1 | grep "$1 dev venet0" >/dev/null 2>&1; then
182
${IP_CMD} route del $1 dev venet0 || \
183
vzwarning "Unable to del route ${IP_CMD} route del $1 dev venet0"