[CRIU] [PATCH 07/10] net: set a proper network namespace to create a socket

Pavel Emelyanov xemul at virtuozzo.com
Mon Feb 13 05:15:45 PST 2017


> @@ -740,3 +743,37 @@ int collect_sockets(struct ns_id *ns)
>  
>  	return err;
>  }
> +
> +static uint32_t last_ns_id = 0;
> +
> +int set_netns(uint32_t ns_id)
> +{
> +	struct ns_id *ns;
> +	int nsfd;
> +
> +	if (!(root_ns_mask & CLONE_NEWNET))
> +		return 0;
> +
> +	if (ns_id == last_ns_id)
> +		return 0;
> +
> +	ns = lookup_ns_by_id(ns_id, &net_ns_desc);
> +	if (ns == NULL) {
> +		pr_err("Unable to find a network namespace");
> +		return -1;
> +	}
> +	nsfd = open_proc(root_item->pid->ns[0].virt, "fd/%d", ns->net.ns_fd);

There's no such thing as ns->net.ns_fd. Patch #5 that used to introduce one
now messes with nsfd_id and fdstore.

> +	if (nsfd < 0)
> +		return -1;
> +	if (setns(nsfd, CLONE_NEWNET)) {
> +		pr_perror("Unable to switch a network namespace");
> +		close(nsfd);
> +		return -1;
> +	}
> +	last_ns_id = ns_id;
> +	close(nsfd);
> +
> +	close_pid_proc();
> +
> +	return 0;
> +}
> 



More information about the CRIU mailing list