/etc/vz/dists/scripts/suse-add_ip.sh is in vzctl 4.9.4-5.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | #!/bin/bash
# Copyright (C) 2000-2015, Parallels, Inc. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#
# Adds IP address(es) in a container running SuSE.
VENET_DEV=venet0
IFCFG_DIR=/etc/sysconfig/network
IFCFG=${IFCFG_DIR}/ifcfg-${VENET_DEV}
ROUTES=${IFCFG_DIR}/ifroute-${VENET_DEV}
HOSTFILE=/etc/hosts
function get_aliases()
{
IFNUMLIST=
[ -f ${IFCFG} ] || return 0
IFNUMLIST=`grep -e "^LABEL_" ${IFCFG} | sed 's/^LABEL_\(.*\)=.*/\1/'`
}
function fix_wicked_route()
{
local wickedfile=/etc/wicked/extensions/netconfig
local venet_route_file=/etc/wicked/extensions/venet_route
local mark='# Set up venet routing v1'
[ ! -f ${wickedfile} ] && return 0
if ! grep -q 'venet_route' ${wickedfile}; then
sed -i -e "/info)/ a\
$venet_route_file \$ifname add
" -e "/remove)/ a\
$venet_route_file \$ifname del
" ${wickedfile}
fi
fgrep -q "$mark" $venet_route_file 2>/dev/null || \
cat > $venet_route_file << EOL
#!/bin/bash
$mark
DEVICE=\$1
ACTION=\$2
PROTO=""
VENET="venet0"
VENET_CONF="/etc/sysconfig/network/ifroute-\$VENET"
[ "x\$DEVICE" != "x\$VENET" ] && exit 0
[ "x\$ACTION" != "xadd" -a "x\$ACTION" != "xdel" ] && exit 0
fgrep -q "default - - \$VENET" \$VENET_CONF 2>/dev/null
[ \$? -eq 0 ] && PROTO="-4"
fgrep -q "default :: - \$VENET" \$VENET_CONF 2>/dev/null
[ \$? -eq 0 ] && PROTO="\$PROTO -6"
for proto in \$PROTO; do
ip \$proto route \$ACTION default dev \$VENET >/dev/null 2>&1
done
exit 0
EOL
chmod 0755 $venet_route_file
}
function fix_ifup_route()
{
local file=/etc/sysconfig/network/scripts/ifup-route
local str='run_iproute $ACTION to $TYPE $DEST via $GWAY $IFACE $IPOPTS'
is_wicked && fix_wicked_route
if [ -f ${file} ] && grep -q "$str" $file; then
sed -i -e "/$str/s/via \$GWAY/\${GWAY:+via \$GWAY}/" $file
fi
}
function init_config()
{
mkdir -p ${IFCFG_DIR}
echo "STARTMODE=onboot
BOOTPROTO=static
BROADCAST=0.0.0.0
NETMASK=255.255.255.255
IPADDR=127.0.0.1" > ${IFCFG} ||
error "Can't write to file ${IFCFG}" ${VZ_FS_NO_DISK_SPACE}
# Set up /etc/hosts
if [ ! -f ${HOSTFILE} ]; then
echo "127.0.0.1 localhost.localdomain localhost" > $HOSTFILE
fi
# Set default route to venet0 only if there are IPs
# and there is no other default route
rm -f ${ROUTES}
if [ -n "${IP_ADDR}" ] && ! grep -qw ^default ${IFCFG_DIR}/ifroute-* 2>/dev/null; then
cat << EOF > ${ROUTES}
default - - ${VENET_DEV}
default :: - ${VENET_DEV}
EOF
fi
fix_ifup_route
}
function create_config()
{
local ip=$1
local mask=$2
local ifnum=$3
echo "IPADDR_${ifnum}=${ip}
PREFIXLEN_${ifnum}=${mask}
LABEL_${ifnum}=${ifnum}" >> ${IFCFG} ||
error "Can't write to file ${IFCFG}" ${VZ_FS_NO_DISK_SPACE}
}
function add_ip()
{
local ipm
local ifnum=-1
local found
if [ "x${VE_STATE}" = "xstarting" ]; then
if [ -n "${IP_ADDR}" ]; then
init_config
elif [ -f ${IFCFG} ] && grep -q "^IPADDR_" ${IFCFG}; then
init_config
fi
elif [ "x${IPDELALL}" = "xyes" ]; then
init_config
elif [ ! -f "${IFCFG}" ]; then
init_config
fi
get_aliases
for ipm in ${IP_ADDR}; do
ip_conv $ipm
found=
if grep -q -w "${_IP}" ${IFCFG}; then
continue
fi
while test -z ${found}; do
let ifnum++
if ! echo "${IFNUMLIST}" | grep -w -q "${ifnum}"; then
found=1
fi
done
create_config "${_IP}" "${_MASK}" "${ifnum}"
done
if [ "x${VE_STATE}" = "xrunning" ]; then
ifdown $VENET_DEV >/dev/null 2>&1
ifup $VENET_DEV >/dev/null 2>&1
fi
}
add_ip
exit 0
# end of script
|