From: Christian Brauner Date: Wed, 3 Jul 2019 21:17:05 +0000 (+0200) Subject: network: send names for all non-trivial network types X-Git-Tag: lxc-3.2.0~14^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3c09b97cd578b8ab28b9d10797a6896f3a9ca0fd;p=thirdparty%2Flxc.git network: send names for all non-trivial network types Signed-off-by: Christian Brauner --- diff --git a/src/lxc/network.c b/src/lxc/network.c index 38c7a75ba..ca74b1e62 100644 --- a/src/lxc/network.c +++ b/src/lxc/network.c @@ -3174,6 +3174,17 @@ int lxc_network_move_created_netdev_priv(struct lxc_handler *handler) return 0; } +static int network_requires_advanced_setup(int type) +{ + if (type == LXC_NET_EMPTY) + return false; + + if (type == LXC_NET_NONE) + return false; + + return true; +} + static int lxc_create_network_unpriv(struct lxc_handler *handler) { int hooks_version = handler->conf->hooks_version; @@ -3186,10 +3197,7 @@ static int lxc_create_network_unpriv(struct lxc_handler *handler) lxc_list_for_each(iterator, network) { struct lxc_netdev *netdev = iterator->elem; - if (netdev->type == LXC_NET_EMPTY) - continue; - - if (netdev->type == LXC_NET_NONE) + if (!network_requires_advanced_setup(netdev->type)) continue; if (netdev->type != LXC_NET_VETH) { @@ -3528,7 +3536,7 @@ static int lxc_setup_netdev_in_child_namespaces(struct lxc_netdev *netdev) netdev->ifindex = if_nametoindex(netdev->created_name); if (!netdev->ifindex) SYSERROR("Failed to retrieve ifindex for network device with name %s", - netdev->name ?: "(null)"); + netdev->created_name ?: "(null)"); } /* get the new ifindex in case of physical netdev */ @@ -3763,7 +3771,7 @@ int lxc_setup_network_in_child_namespaces(const struct lxc_conf *conf, return 0; } -int lxc_network_send_veth_names_to_child(struct lxc_handler *handler) +int lxc_network_send_to_child(struct lxc_handler *handler) { struct lxc_list *iterator; struct lxc_list *network = &handler->conf->network; @@ -3773,7 +3781,7 @@ int lxc_network_send_veth_names_to_child(struct lxc_handler *handler) int ret; struct lxc_netdev *netdev = iterator->elem; - if (netdev->type != LXC_NET_VETH) + if (!network_requires_advanced_setup(netdev->type)) continue; ret = lxc_send_nointr(data_sock, netdev->name, IFNAMSIZ, MSG_NOSIGNAL); @@ -3790,7 +3798,7 @@ int lxc_network_send_veth_names_to_child(struct lxc_handler *handler) return 0; } -int lxc_network_recv_veth_names_from_parent(struct lxc_handler *handler) +int lxc_network_recv_from_parent(struct lxc_handler *handler) { struct lxc_list *iterator; struct lxc_list *network = &handler->conf->network; @@ -3800,7 +3808,7 @@ int lxc_network_recv_veth_names_from_parent(struct lxc_handler *handler) int ret; struct lxc_netdev *netdev = iterator->elem; - if (netdev->type != LXC_NET_VETH) + if (!network_requires_advanced_setup(netdev->type)) continue; ret = lxc_recv_nointr(data_sock, netdev->name, IFNAMSIZ, 0); diff --git a/src/lxc/network.h b/src/lxc/network.h index 9a79cb870..483fbb8cd 100644 --- a/src/lxc/network.h +++ b/src/lxc/network.h @@ -278,8 +278,8 @@ extern int lxc_requests_empty_network(struct lxc_handler *handler); extern int lxc_restore_phys_nics_to_netns(struct lxc_handler *handler); extern int lxc_setup_network_in_child_namespaces(const struct lxc_conf *conf, struct lxc_list *network); -extern int lxc_network_send_veth_names_to_child(struct lxc_handler *handler); -extern int lxc_network_recv_veth_names_from_parent(struct lxc_handler *handler); +extern int lxc_network_send_to_child(struct lxc_handler *handler); +extern int lxc_network_recv_from_parent(struct lxc_handler *handler); extern int lxc_network_send_name_and_ifindex_to_parent(struct lxc_handler *handler); extern int lxc_network_recv_name_and_ifindex_from_child(struct lxc_handler *handler); extern int lxc_netns_set_nsid(int netns_fd); diff --git a/src/lxc/start.c b/src/lxc/start.c index 9e28d3dcd..1e559f887 100644 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@ -1194,7 +1194,7 @@ static int do_start(void *data) goto out_error; if (handler->ns_clone_flags & CLONE_NEWNET) { - ret = lxc_network_recv_veth_names_from_parent(handler); + ret = lxc_network_recv_from_parent(handler); if (ret < 0) { ERROR("Failed to receive veth names from parent"); goto out_warn_father; @@ -1252,12 +1252,12 @@ static int do_start(void *data) */ if (handler->daemonize && !handler->conf->autodev) { char path[PATH_MAX]; - + ret = snprintf(path, sizeof(path), "%s/dev/null", handler->conf->rootfs.mount); if (ret < 0 || ret >= sizeof(path)) goto out_warn_father; - + ret = access(path, F_OK); if (ret != 0) { devnull_fd = open_devnull(); @@ -1839,7 +1839,7 @@ static int lxc_spawn(struct lxc_handler *handler) goto out_delete_net; } - ret = lxc_network_send_veth_names_to_child(handler); + ret = lxc_network_send_to_child(handler); if (ret < 0) { ERROR("Failed to send veth names to child"); goto out_delete_net;