2
# Copyright (C) 2010-2011, Parallels, Inc. 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
18
# This script configures IP alias(es) inside Funtoo-based CT with
19
# OpenRC used as services/startup/shutdown system.
21
# Parameters are passed in environment variables.
22
# Required parameters:
23
# IP_ADDR - IP address(es) to add
24
# (several addresses should be divided by space)
25
# Optional parameters:
26
# VE_STATE - state of CT; could be one of:
27
# starting | stopping | running | stopped
28
# IPDELALL - delete all old interfaces
30
# Note that modern versions of vzctl runs this script even if there
31
# are not venet IPs to add to the CT, which resulted in netif.venet0
32
# being created even when venet wasn't enabled for this container.
33
# This could indicate an upstream bug.
36
IFCFG=/etc/conf.d/netif.${VENET_DEV}
37
SCRIPT=/etc/runlevels/default/netif.${VENET_DEV}
41
function comment_line_regex()
43
cp -pf ${IFCFG} ${IFCFG}.$$ ||
44
error "Failed to comment ${1}: unable to copy ${IFCFG}" ${VZ_FS_NO_DISK_SPACE}
45
sed -e "s/${1}/#${1}/" < ${IFCFG} > ${IFCFG}.$$ &&
46
mv -f ${IFCFG}.$$ ${IFCFG} 2>/dev/null
48
rm -f ${IFCFG}.$$ 2>/dev/null
49
error "Failed to comment ${1}: unable to create ${IFCFG}" ${VZ_FS_NO_DISK_SPACE}
55
[ -f "${SCRIPT}" ] && return 0
56
ln -sf netif.tmpl /etc/init.d/netif.${VENET_DEV}
57
rc-update add netif.${VENET_DEV} default &>/dev/null
62
# used for disabling venet if we are using veth and no IPs are specified
63
rc-update del netif.${VENET_DEV} default &>/dev/null
64
rm -f /etc/init.d/netif.${VENET_DEV}
65
rm -f /etc/conf.d/netif.${VENET_DEV}
66
ip link set ${VENET_DEV} down > /dev/null 2>&1
69
function init_netconfig()
71
if [ "$IP_ADDR" != "" ]
78
if [ ! -f ${HOSTFILE} ]; then
79
echo "127.0.0.1 localhost.localdomain localhost" > $HOSTFILE
86
if [ "x${VE_STATE}" = "xstarting" -o "x${IPDELALL}" = "xyes" ]; then
88
if [ "x${IPDELALL}" = "xyes" ]; then
89
/etc/init.d/netif.${VENET_DEV} stop >/dev/null 2>&1
95
if [ "${VENET_DEV}" = "venet0" ]
98
put_param "${IFCFG}" "route" "default dev venet0"
100
for ipm in ${IP_ADDR}; do
102
ips="$ips $_IP/$_MASK"
104
put_param "${IFCFG}" "template" "interface"
105
put_param "${IFCFG}" "ipaddrs" "$ips"
107
if [ "x${VE_STATE}" = "xrunning" ]; then
108
# synchronize config files & interfaces
109
/etc/init.d/netif.${VENET_DEV} restart >/dev/null 2>&1