]> git.proxmox.com Git - mirror_lxc.git/commitdiff
Merge pull request #3069 from brauner/2019-07-01/network_creation
authorStéphane Graber <stgraber@ubuntu.com>
Tue, 2 Jul 2019 15:46:55 +0000 (11:46 -0400)
committerGitHub <noreply@github.com>
Tue, 2 Jul 2019 15:46:55 +0000 (11:46 -0400)
start: unify network creation

1  2 
src/lxc/start.c

diff --combined src/lxc/start.c
index 0842dc35429805ffb30de8fb25ae3dcb51fa8ad5,ad6e1f67094dd79601322bda4862c5a83f6ce287..9e28d3dcdfd65df3abf8607e2a563c4cf6e2d697
@@@ -1132,6 -1132,7 +1132,6 @@@ static int do_start(void *data
        ATTR_UNUSED __do_close_prot_errno int data_sock0 = handler->data_sock[0],
                                              data_sock1 = handler->data_sock[1];
        int ret;
 -      char path[PATH_MAX];
        uid_t new_uid;
        gid_t new_gid;
        struct lxc_list *iterator;
        if (ret < 0)
                goto out_error;
  
-       ret = lxc_network_recv_veth_names_from_parent(handler);
-       if (ret < 0) {
-               ERROR("Failed to receive veth names from parent");
-               goto out_warn_father;
+       if (handler->ns_clone_flags & CLONE_NEWNET) {
+               ret = lxc_network_recv_veth_names_from_parent(handler);
+               if (ret < 0) {
+                       ERROR("Failed to receive veth names from parent");
+                       goto out_warn_father;
+               }
        }
  
        /* If we are in a new user namespace, become root there to have
                goto out_warn_father;
        }
  
 -      ret = snprintf(path, sizeof(path), "%s/dev/null",
 -                     handler->conf->rootfs.mount);
 -      if (ret < 0 || ret >= sizeof(path))
 -              goto out_warn_father;
 -
        /* In order to checkpoint restore, we need to have everything in the
         * same mount namespace. However, some containers may not have a
         * reasonable /dev (in particular, they may not have /dev/null), so we
         * where it isn't wanted.
         */
        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();
@@@ -1695,31 -1696,6 +1697,6 @@@ static int lxc_spawn(struct lxc_handle
        if (ret < 0)
                goto out_sync_fini;
  
-       if (handler->ns_clone_flags & CLONE_NEWNET) {
-               if (!lxc_list_empty(&conf->network)) {
-                       /* Find gateway addresses from the link device, which is
-                        * no longer accessible inside the container. Do this
-                        * before creating network interfaces, since goto
-                        * out_delete_net does not work before lxc_clone.
-                        */
-                       ret = lxc_find_gateway_addresses(handler);
-                       if (ret < 0) {
-                               ERROR("Failed to find gateway addresses");
-                               goto out_sync_fini;
-                       }
-                       /* That should be done before the clone because we will
-                        * fill the netdev index and use them in the child.
-                        */
-                       ret = lxc_create_network_priv(handler);
-                       if (ret < 0) {
-                               ERROR("Failed to create the network");
-                               goto out_delete_net;
-                       }
-               }
-       }
        if (!cgroup_ops->payload_create(cgroup_ops, handler)) {
                ERROR("Failed creating cgroups");
                goto out_delete_net;
                        goto out_delete_net;
        }
  
+       ret = snprintf(pidstr, 20, "%d", handler->pid);
+       if (ret < 0 || ret >= 20)
+               goto out_delete_net;
+       ret = setenv("LXC_PID", pidstr, 1);
+       if (ret < 0)
+               SYSERROR("Failed to set environment variable: LXC_PID=%s", pidstr);
        for (i = 0; i < LXC_NS_MAX; i++)
                if (handler->ns_on_clone_flags & ns_info[i].clone_flag)
                        INFO("Cloned %s", ns_info[i].flag_name);
  
        /* Create the network configuration. */
        if (handler->ns_clone_flags & CLONE_NEWNET) {
-               ret = lxc_network_move_created_netdev_priv(handler->lxcpath,
-                                                          handler->name,
-                                                          &conf->network,
-                                                          handler->pid);
+               ret = lxc_create_network(handler);
                if (ret < 0) {
-                       ERROR("Failed to create the configured network");
+                       ERROR("Failed to create the network");
                        goto out_delete_net;
                }
  
-               ret = lxc_create_network_unpriv(handler->lxcpath, handler->name,
-                                               &conf->network, handler->pid, conf->hooks_version);
+               ret = lxc_network_send_veth_names_to_child(handler);
                if (ret < 0) {
-                       ERROR("Failed to create the configured network");
+                       ERROR("Failed to send veth names to child");
                        goto out_delete_net;
                }
        }
  
-       ret = lxc_network_send_veth_names_to_child(handler);
-       if (ret < 0) {
-               ERROR("Failed to send veth names to child");
-               goto out_delete_net;
-       }
        if (!lxc_list_empty(&conf->procs)) {
                ret = setup_proc_filesystem(&conf->procs, handler->pid);
                if (ret < 0)
                }
        }
  
-       ret = snprintf(pidstr, 20, "%d", handler->pid);
-       if (ret < 0 || ret >= 20)
-               goto out_delete_net;
-       ret = setenv("LXC_PID", pidstr, 1);
-       if (ret < 0)
-               SYSERROR("Failed to set environment variable: LXC_PID=%s", pidstr);
        /* Run any host-side start hooks */
        ret = run_lxc_hooks(name, "start-host", conf, NULL);
        if (ret < 0) {
        if (ret < 0)
                goto out_delete_net;
  
-       ret = lxc_network_recv_name_and_ifindex_from_child(handler);
-       if (ret < 0) {
-               ERROR("Failed to receive names and ifindices for network "
-                     "devices from child");
-               goto out_delete_net;
+       if (handler->ns_clone_flags & CLONE_NEWNET) {
+               ret = lxc_network_recv_name_and_ifindex_from_child(handler);
+               if (ret < 0) {
+                       ERROR("Failed to receive names and ifindices for network devices from child");
+                       goto out_delete_net;
+               }
        }
  
        /* Now all networks are created, network devices are moved into place,