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>
#else
unsigned int seed=randseed(false);
#endif
- while (*curs != '\0')
+ while (*curs != '\0' && *curs != '\n')
{
if ( *curs == 'x' || *curs == 'X' ) {
if (curs - hwaddr == 1) {
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)
{
size_t len = conf->unexpanded_len, linelen = strlen(line);
+ update_hwaddr(line);
+
while (conf->unexpanded_alloced <= len + linelen + 2) {
char *tmp = realloc(conf->unexpanded_config, conf->unexpanded_alloced + 1024);
if (!tmp)
lxc-test-reboot lxc-test-list lxc-test-attach lxc-test-device-add-remove \
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
bin_SCRIPTS += \
lxc-test-apparmor-mount \
lxc-test-checkpoint-restore \
lxc-test-cloneconfig \
+ lxc-test-createconfig \
lxc-test-ubuntu \
lxc-test-unpriv \
may_control.c \
--- /dev/null
+#!/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"