From 018ef5201be79a5f8cd2c4e1ddf0da0519268a03 Mon Sep 17 00:00:00 2001 From: Daniel Lezcano Date: Thu, 28 May 2009 12:10:51 +0200 Subject: [PATCH] choose a default network interface name When no name is specified in the configuration file for an interface, let the system to choose one nice name like "eth". Signed-off-by: Daniel Lezcano --- src/lxc/conf.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/lxc/conf.c b/src/lxc/conf.c index a19e25e4d..9b593f3f7 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -1260,13 +1260,22 @@ static int setup_network_cb(const char *name, const char *directory, return -1; } - if (!read_info(path, "name", newname, sizeof(newname))) { - if (lxc_device_rename(ifname, newname)) { - ERROR("failed to rename %s->%s", - ifname, newname); - return -1; - } - current_ifname = newname; + /* default: let the system to choose one interface name */ + if (read_info(path, "name", newname, sizeof(newname))) + strcpy(newname, "eth%d"); + + if (lxc_device_rename(ifname, newname)) { + ERROR("failed to rename %s->%s", ifname, current_ifname); + return -1; + } + + /* Re-read the name of the interface because its name has changed + * and would be automatically allocated by the system + */ + if (!if_indextoname(ifindex, current_ifname)) { + ERROR("no interface corresponding to index '%d'", + ifindex); + return -1; } if (!read_info(path, "hwaddr", hwaddr, sizeof(hwaddr))) { -- 2.47.2