mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-08-16 09:01:09 +00:00
update hwaddr to fill in xx at create time
Commit 67702c21
regressed the case where lxc-create use a config
file with 'xx:xx' in lxc.network.hwaddr, so that the 'xx' were
preserved in the container's configuration file. Expand those
in the unexpanded_config file whenever we are reading a
config file which is not coming from a 'lxc.include'.
The config file will have \n-terminated lines, so update
rand_complete_hwaddr to also stop on \n.
Add a test case to make sure xx gets expanded at lxc-create.
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
This commit is contained in:
parent
af242ace3e
commit
e6744e9b39
@ -551,7 +551,7 @@ static int rand_complete_hwaddr(char *hwaddr)
|
|||||||
#else
|
#else
|
||||||
unsigned int seed=randseed(false);
|
unsigned int seed=randseed(false);
|
||||||
#endif
|
#endif
|
||||||
while (*curs != '\0')
|
while (*curs != '\0' && *curs != '\n')
|
||||||
{
|
{
|
||||||
if ( *curs == 'x' || *curs == 'X' ) {
|
if ( *curs == 'x' || *curs == 'X' ) {
|
||||||
if (curs - hwaddr == 1) {
|
if (curs - hwaddr == 1) {
|
||||||
@ -1642,10 +1642,41 @@ static int config_console_logfile(const char *key, const char *value,
|
|||||||
return config_path_item(&lxc_conf->console.log_path, value);
|
return config_path_item(&lxc_conf->console.log_path, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If we find a lxc.network.hwaddr in the original config file,
|
||||||
|
* we expand it in the unexpanded_config, so that after a save_config
|
||||||
|
* we store the hwaddr for re-use.
|
||||||
|
* This is only called when reading the config file, not when executing
|
||||||
|
* a lxc.include.
|
||||||
|
* 'x' and 'X' are substituted in-place.
|
||||||
|
*/
|
||||||
|
static void update_hwaddr(const char *line)
|
||||||
|
{
|
||||||
|
char *p;
|
||||||
|
|
||||||
|
line += lxc_char_left_gc(line, strlen(line));
|
||||||
|
if (line[0] == '#')
|
||||||
|
return;
|
||||||
|
if (strncmp(line, "lxc.network.hwaddr", 18) != 0)
|
||||||
|
return;
|
||||||
|
p = strchr(line, '=');
|
||||||
|
if (!p)
|
||||||
|
return; // let config_network_hwaddr raise the error
|
||||||
|
p++;
|
||||||
|
while (isblank(*p))
|
||||||
|
p++;
|
||||||
|
if (!*p)
|
||||||
|
return;
|
||||||
|
|
||||||
|
rand_complete_hwaddr(p);
|
||||||
|
}
|
||||||
|
|
||||||
int append_unexp_config_line(const char *line, struct lxc_conf *conf)
|
int append_unexp_config_line(const char *line, struct lxc_conf *conf)
|
||||||
{
|
{
|
||||||
size_t len = conf->unexpanded_len, linelen = strlen(line);
|
size_t len = conf->unexpanded_len, linelen = strlen(line);
|
||||||
|
|
||||||
|
update_hwaddr(line);
|
||||||
|
|
||||||
while (conf->unexpanded_alloced <= len + linelen + 2) {
|
while (conf->unexpanded_alloced <= len + linelen + 2) {
|
||||||
char *tmp = realloc(conf->unexpanded_config, conf->unexpanded_alloced + 1024);
|
char *tmp = realloc(conf->unexpanded_config, conf->unexpanded_alloced + 1024);
|
||||||
if (!tmp)
|
if (!tmp)
|
||||||
|
@ -48,7 +48,7 @@ bin_PROGRAMS = lxc-test-containertests lxc-test-locktests lxc-test-startone \
|
|||||||
lxc-test-reboot lxc-test-list lxc-test-attach lxc-test-device-add-remove \
|
lxc-test-reboot lxc-test-list lxc-test-attach lxc-test-device-add-remove \
|
||||||
lxc-test-apparmor
|
lxc-test-apparmor
|
||||||
|
|
||||||
bin_SCRIPTS = lxc-test-autostart lxc-test-cloneconfig
|
bin_SCRIPTS = lxc-test-autostart lxc-test-cloneconfig lxc-test-createconfig
|
||||||
|
|
||||||
if DISTRO_UBUNTU
|
if DISTRO_UBUNTU
|
||||||
bin_SCRIPTS += \
|
bin_SCRIPTS += \
|
||||||
@ -79,6 +79,7 @@ EXTRA_DIST = \
|
|||||||
lxc-test-apparmor-mount \
|
lxc-test-apparmor-mount \
|
||||||
lxc-test-checkpoint-restore \
|
lxc-test-checkpoint-restore \
|
||||||
lxc-test-cloneconfig \
|
lxc-test-cloneconfig \
|
||||||
|
lxc-test-createconfig \
|
||||||
lxc-test-ubuntu \
|
lxc-test-ubuntu \
|
||||||
lxc-test-unpriv \
|
lxc-test-unpriv \
|
||||||
may_control.c \
|
may_control.c \
|
||||||
|
42
src/tests/lxc-test-createconfig
Normal file
42
src/tests/lxc-test-createconfig
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# lxc: linux Container library
|
||||||
|
|
||||||
|
# Authors:
|
||||||
|
# Serge Hallyn <serge.hallyn@ubuntu.com>
|
||||||
|
#
|
||||||
|
# This is a test script for the lxc-user-nic program
|
||||||
|
|
||||||
|
# This library is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
|
# License as published by the Free Software Foundation; either
|
||||||
|
# version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
# This library 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
|
||||||
|
# Lesser General Public License for more details.
|
||||||
|
|
||||||
|
# You should have received a copy of the GNU Lesser General Public
|
||||||
|
# License along with this library; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
s=`mktemp -d /tmp/lxctest-XXXXXX`
|
||||||
|
f="$s/in.conf"
|
||||||
|
|
||||||
|
cleanup() {
|
||||||
|
lxc-destroy -n lxctestc || true
|
||||||
|
rm -rf $s
|
||||||
|
}
|
||||||
|
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
|
cat > $f << EOF
|
||||||
|
lxc.network.type = veth
|
||||||
|
lxc.network.hwaddr = 00:16:3e:xx:xx:xx
|
||||||
|
EOF
|
||||||
|
lxc-create -t busybox -f $f -n lxctestc
|
||||||
|
grep -q "xx:xx" /var/lib/lxc/lxctestc/config && { echo "hwaddr not expanded"; exit 1; }
|
||||||
|
echo "Success"
|
Loading…
Reference in New Issue
Block a user