]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
choose a default network interface name
authorDaniel Lezcano <dlezcano@fr.ibm.com>
Thu, 28 May 2009 10:10:51 +0000 (12:10 +0200)
committerDaniel Lezcano <dlezcano@fr.ibm.com>
Thu, 28 May 2009 10:10:51 +0000 (12:10 +0200)
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 <dlezcano@fr.ibm.com>
src/lxc/conf.c

index a19e25e4d1af95f952fc71b938ae14cdb6cb4019..9b593f3f70c0074216b95af6cec8b0f999968fcb 100644 (file)
@@ -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))) {