netdev->type = LXC_NET_PHYS;
} else if (strequal(value, "empty")) {
netdev->type = LXC_NET_EMPTY;
+ /* We don't support custom loopback device names. */
+ (void)strlcpy(netdev->name, "lo", IFNAMSIZ);
} else if (strequal(value, "none")) {
netdev->type = LXC_NET_NONE;
} else {
NULL,
};
- netdev->ifindex = 0;
+ /* The loopback device always has index 1. */
+ netdev->ifindex = 1;
+
+ if (!strequal(netdev->name, "lo"))
+ return syserror_set(-EINVAL, "Custom loopback device names not supported");
+
if (!netdev->upscript)
return 0;
return 0;
}
+static int netdev_requires_move(const struct lxc_netdev *netdev)
+{
+ if (IN_SET(netdev->type, LXC_NET_EMPTY, LXC_NET_NONE))
+ return false;
+
+ /*
+ * Veth devices are directly created in the container's network
+ * namespace so the device doesn't need to be moved into the
+ * container's network namespace. The transient name will
+ * already have been set above when we created the veth tunnel.
+ */
+ if (!netdev->ifindex)
+ return false;
+
+ return true;
+}
+
int lxc_network_move_created_netdev_priv(struct lxc_handler *handler)
{
pid_t pid = handler->pid;
int ret;
struct lxc_netdev *netdev = iterator->elem;
- /*
- * Veth devices are directly created in the container's network
- * namespace so the device doesn't need to be moved into the
- * container's network namespace. The transient name will
- * already have been set above when we created the veth tunnel.
- *
- * Other than this special case this also catches all
- * LXC_NET_EMPTY and LXC_NET_NONE devices.
- */
- if (!netdev->ifindex)
+ if (!netdev_requires_move(netdev))
continue;
ret = create_transient_name(netdev);
int err;
char bufinet4[INET_ADDRSTRLEN], bufinet6[INET6_ADDRSTRLEN];
- /* empty network namespace */
- if (!netdev->ifindex && netdev->flags & IFF_UP) {
- err = lxc_netdev_up("lo");
- if (err)
- return log_error_errno(-1, -err, "Failed to set the loopback network device up");
- }
-
/* set a mac address */
if (netdev->hwaddr && setup_hw_addr(netdev->hwaddr, netdev->name))
return log_error_errno(-1, errno, "Failed to setup hw address for network device \"%s\"", netdev->name);