This file is indexed.

/etc/vz/dists/scripts/etcnet-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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/bash
#  Copyright (C) 2006-2007 Dmitry V. Levin <ldv@altlinux.org>
#
#  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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
#
#
# Adds IP address(es) in a container running a etcnet-based systems.

HOSTFILE=/etc/hosts
IFACE_DIR=/etc/net/ifaces
NETFILE=/etc/sysconfig/network
VENET_DEV=venet0

# Function to quote argument for sed regexp.
quote_sed_regexp()
{
	local out="$*"
	if [ -z "${out##*[\[\].^\$\\/]*}" ]; then
		out="$(printf %s "$out" |sed 's/[].^$[\/]/\\&/g')" ||
			return 1
	fi
	printf %s "$out"
}

create_venet_config()
{
	local dir="$1"; shift

	rm -rf "$dir" && mkdir -p "$dir" ||
		error "Cannot create $dir" ${VZ_FS_NO_DISK_SPACE}
	echo >"$dir/ipv4address" ||
		error "Cannot create $dir/ipv4address" ${VZ_FS_NO_DISK_SPACE}
	echo "default dev $dir" >"$dir/ipv4route" ||
		error "Cannot create $dir/ipv4route" ${VZ_FS_NO_DISK_SPACE}
	echo 'BOOTPROTO=static
ONBOOT=yes
TYPE=lo' >"$dir/options" ||
		error "Cannot create $dir/options" ${VZ_FS_NO_DISK_SPACE}
}

destroy_venet_config()
{
	local dir="$1"; shift

	rm -rf "$dir" ||
		error "Cannot destroy $dir" ${VZ_FS_NO_DISK_SPACE}
}

del_ipv6_conf()
{
	local dir="$1"; shift

	if [ -f "$dir/ipv6address" ]; then
		rm -f "$dir/ipv6address" ||
			error "Cannot remove $dir/ipv6address" ${VZ_FS_NO_DISK_SPACE}
	fi

	if [ -f "$dir/ipv6route" ]; then
		rm -f "$dir/ipv6route" ||
			error "Cannot remove $dir/ipv6route" ${VZ_FS_NO_DISK_SPACE}
	fi

	del_param ".tmp/$VENET_DEV/options" "CONFIG_IPV6=yes"

}

setup_network()
{
	# Purge old venet0 interface settings
	destroy_venet_config "$VENET_DEV"

	# Set up venet0 main interface
	[ $# -eq 0 ] || create_venet_config "$VENET_DEV"

	# Set /etc/sysconfig/network
	put_param "$NETFILE" NETWORKING yes

	# Set up /etc/hosts if necessary
	[ -s "$HOSTFILE" ] ||
		echo '127.0.0.1	localhost.localdomain localhost' >"$HOSTFILE"
}

create_alias()
{
	local ip="$1"; shift
	local mask="$1"; shift
	local ifnum="$1"; shift

	echo "$ip/$mask label $VENET_DEV:$ifnum" >>".tmp/$VENET_DEV/ipv4address" ||
		error "Cannot create .tmp/$VENET_DEV/ipv4address" ${VZ_FS_NO_DISK_SPACE}
}

add_ip6() {
	local ip="$1"; shift
	local mask="$1"; shift

	[ "${IPV6}" != "yes" ] && return 0

	if ! grep -qw "$ip" ".tmp/$VENET_DEV/ipv6address" 2>/dev/null; then
		echo "2000::/3 dev $VENET_DEV" > ".tmp/$VENET_DEV/ipv6route" ||
			error "Cannot create .tmp/$VENET_DEV/ipv6route" ${VZ_FS_NO_DISK_SPACE}

		echo "$ip/$mask" >> ".tmp/$VENET_DEV/ipv6address" ||
			error "Cannot create .tmp/$VENET_DEV/ipv6address" ${VZ_FS_NO_DISK_SPACE}

		put_param ".tmp/$VENET_DEV/options" "CONFIG_IPV6" "yes"
	fi
}

backup_configs()
{
	rm -rf .tmp && mkdir -p .tmp ||
		error "Cannot create $VENET_DEV" ${VZ_FS_NO_DISK_SPACE}
	[ -d "$VENET_DEV" ] ||
		create_venet_config "$VENET_DEV"
	cp -a "$VENET_DEV" .tmp/ ||
		error "Unable to backup interface config files" ${VZ_FS_NO_DISK_SPACE}
}

move_configs()
{
	rm -rf "$VENET_DEV.orig" &&
	mv "$VENET_DEV" "$VENET_DEV.orig" &&
	mv ".tmp/$VENET_DEV" "$VENET_DEV" &&
	rm -rf "$VENET_DEV.orig" .tmp
}

find_unused_alias()
{
	local i="$1"; shift
	while grep -qs "label $VENET_DEV:$i\$" ".tmp/$VENET_DEV/ipv4address"; do
		i="$(($i+1))"
	done
	echo "$i"
}

add_ip()
{
	set -- ${IP_ADDR}

	if [ "$VE_STATE" = 'starting' ]; then
		setup_network "$@"
	fi

	if [ $# -gt 0 ]; then
		backup_configs

		local i=0 ipm
		for ipm; do
			ip_conv $ipm
			if [ -z "$_IPV6ADDR" ]; then
				i="$(find_unused_alias "$(($i+1))")"
				create_alias "$_IP" "$_MASK" "$i"
			else
				if [ "$IPDELALL" = "yes" ]; then
				     del_ipv6_conf "$VENET_DEV"
				fi
				add_ip6 "${_IP}" "${_MASK}"
			fi
		done

		move_configs
	fi

	if [ "$VE_STATE" = 'running' ]; then
		# synchronyze config files & interfaces
		ifdown "$VENET_DEV"
		if [ $# -gt 0 ]; then
			ifup "$VENET_DEV"
		else
			destroy_venet_config "$VENET_DEV"
		fi
	fi

	if [ $# -gt 0 -a -d /etc/hooks/add_ip.d ] &&
	   type run-parts >/dev/null 2>&1; then
		run-parts /etc/hooks/add_ip.d "$@"
	fi
}

[ -d "$IFACE_DIR" ] &&
cd "$IFACE_DIR" &&
add_ip
exit 0