Commit 018ef520 by Daniel Lezcano

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: 's avatarDaniel Lezcano <dlezcano@fr.ibm.com>
parent f8af8e23
...@@ -1260,13 +1260,22 @@ static int setup_network_cb(const char *name, const char *directory, ...@@ -1260,13 +1260,22 @@ static int setup_network_cb(const char *name, const char *directory,
return -1; return -1;
} }
if (!read_info(path, "name", newname, sizeof(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)) { if (lxc_device_rename(ifname, newname)) {
ERROR("failed to rename %s->%s", ERROR("failed to rename %s->%s", ifname, current_ifname);
ifname, newname);
return -1; return -1;
} }
current_ifname = newname;
/* 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))) { if (!read_info(path, "hwaddr", hwaddr, sizeof(hwaddr))) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment