Article View: linux.kernel.netdev
Article #12126Re: [PATCH RFC iproute2-next 2/2] ip: add "ip vsock" to move the guest vsock device to a netns
From: Stephen Hemminger
Date: Fri, 06 Nov 2026 09:36
Date: Fri, 06 Nov 2026 09:36
135 lines
16102 bytes
16102 bytes
On Thu, 5 Nov 2026 11:30:36 -0800
Bobby Eshleman <bobbyeshleman@meta.com> wrote:
> The guest's vsock device is not a netdev, so rtnetlink cannot move it
> between network namespaces. Add an "ip vsock" object that goes through
> the "vsock" generic netlink family instead:
>
> ip vsock set netns { PID | NETNSNAME | NETNSFILE }
> ip vsock show
>
> "set" issues VSOCK_CMD_DEV_NETNS_SET from inside the target namespace,
> since the kernel moves the device to the namespace the request was sent
> from. "show" issues VSOCK_CMD_DEV_NETNS_GET and prints where the device
> is, relative to the current namespace.
>
> Link: https://lore.kernel.org/all/20261103-vsock-guest-ns-v5-0-48179b9b66b8@meta.com/
> Signed-off-by: Bobby Eshleman <bobbyeshleman@meta.com>
> ---
Semi-automated review using review-prompts for iproute2
On Thu, 5 Nov 2026 11:30:36 -0800, Bobby Eshleman wrote:
Thanks, this is mostly in good shape. A few things to fix before it
goes beyond RFC.
> +#include <linux/vsock_netlink.h>
This depends on a uapi header (and kernel series) that is not yet
merged. iproute2-next can only take this once the kernel side is in
net-next; the header update should then come from the normal uapi
sync rather than a hand-added copy in patch 1/2.
> +static int vsock_talk(__u8 cmd, struct nlmsghdr **answer)
> +{
> + GENL_REQUEST(req, 128, 0, 0, VSOCK_FAMILY_VERSION, cmd, NLM_F_REQUEST);
> + struct rtnl_handle grth = { .fd = -1 };
> + int family = -1;
> + int ret;
> +
> + if (genl_init_handle(&grth, VSOCK_FAMILY_NAME, &family)) {
> + fprintf(stderr,
> + "Cannot resolve the \"%s\" netlink family, the kernel may not support moving the vsock device.\n",
> + VSOCK_FAMILY_NAME);
> + return -1;
> + }
genl_init_handle() leaves the socket open when genl_resolve_family()
fails, so this leaks grth.fd. Harmless today since ip exits, but not
under "ip -batch". Add rtnl_close(&grth) on this path.
Also genl_resolve_family() already prints "Error talking to the kernel"
on failure, so the user gets two messages. Not a big deal, just be aware.
> +static void vsock_print_netnsid(int id)
> +{
> + char *name;
> +
> + if (is_json_context()) {
> + print_int(PRINT_JSON, "netnsid", NULL, id);
> + return;
> + }
This copies the IFLA_LINK_NETNSID pattern from ipaddress.c, which is
fine for consistency, but note that JSON users never get the netns
name and get -1 for "unknown". Consider also emitting
print_string(PRINT_JSON, "netns", NULL, name) when a name exists.
> +int do_ipvsock(int argc, char **argv)
> +{
> + if (argc < 1)
> + return vsock_dev_netns_show();
> +
> + if (matches(*argv, "show") == 0 ||
> + matches(*argv, "list") == 0) {
...
> + if (matches(*argv, "set") == 0)
...
> + if (matches(*argv, "help") == 0)
> + usage();
and in vsock_set():
> + } else if (matches(*argv, "help") == 0) {
New code must use strcmp(), not matches(). Abbreviation matching has
caused repeated breakage when keywords are added later (e.g. "s" here
already matches both "show" and "set"; order decides which wins).
Please convert all of these to strcmp().
> + ret = rtnl_talk(&grth, &req.n, answer);
> + rtnl_close(&grth);
> +
> + return ret < 0 ? -2 : 0;
The -2 propagates out as the exit status of ip (254). Other ip
subcommands return -1/1 on failure; either is fine but please be
consistent with vsock_dev_netns_set() which returns -1 for its own
errors and -2 for a kernel error.
> + "Usage: ip vsock set netns { PID | NETNSNAME | NETNSFILE }\n"
> + " ip vsock show\n");
Literal tabs in the usage string; the rest of ip uses spaces for
alignment here ("Usage: ip vsock ...\n ip vsock show\n").
Also "ip vsock help" should be listed.
> +static int vsock_dev_netns_set(const char *netns)
> +{
...
> + if (setns(netns_fd, CLONE_NEWNET) < 0) {
Design note, more for the kernel side than this patch: because
VSOCK_CMD_DEV_NETNS_SET has no target attribute, userspace has to do a
setns() dance, and "ip -n foo vsock set netns bar" ends up depending on
which namespace the genl socket was opened in. rtnetlink and devlink
both take an explicit NETNS_FD / NETNS_PID / NETNS_ID attribute for
this; doing the same for vsock would make the tool trivial and avoid
needing setns() (and the privileges to enter the target ns) at all.
Since this is RFC on both sides it seems worth reconsidering now.
If the kernel API stays as is, the setns/restore logic looks correct.
> +ip vsock set netns 1
> +.RS 4
> +Move the device back to the initial network namespace, undoing the assignment.
That only holds if ip is run in the initial pid namespace; "1" is a
PID, not "the initial netns". Maybe say so, or use /proc/1/ns/net.
Minor: the man page says "Nothing follows vsock when the device is in
the current namespace" -- worth also showing an example of the
"netnsid unknown" output so users know what it means.
Technical Details
Message-ID:
<20261106103646.41a0f13a@stephen-xps.local>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-357884-linux-kernel-netdev=dewy.ruReferences:
<20261105-vsock-guest-ns-v1-0-b1c11b3b69c7@meta.com> <20261105-vsock-guest-ns-v1-2-b1c11b3b69c7@meta.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-357884-linux-kernel-netdev=dewy.ru
From: stephen@networkplumber.org (Stephen Hemminger)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH RFC iproute2-next 2/2] ip: add "ip vsock" to move the
guest vsock device to a netns
Date: Fri, 6 Nov 2026 10:36:46 +0100
Organization: Usenet Network
Message-ID: <20261106103646.41a0f13a@stephen-xps.local>
References: <20261105-vsock-guest-ns-v1-0-b1c11b3b69c7@meta.com>
<20261105-vsock-guest-ns-v1-2-b1c11b3b69c7@meta.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
logging-data="3842618"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:9nwutvKQ7SQw4dU1dj7v1ynBf/0= sha256:AmtvRl5DOZIlibb3nD8e9WoUd7cGxrDbcbMVrLrPvZ0=
sha1:ZxqGNtF/DymvrzmOjf9kil/cxXc= sha256:dMzSFprUJuMYyDNRfodI6UbEbP6gRyo8oXhKX/8KYQs=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id 35FA81131ED; Fri, 6 Nov 2026 13:05:15 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.951
X-Spam-Status: No, score=-2.951 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1,
RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=networkplumber-org.20260707.gappssmtp.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id PD1BumOr7NhP;
Fri, 6 Nov 2026 13:05:04 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-357884-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=quarantine dis=none) header.from=networkplumber.org
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
by mail.dewy.ru (Postfix) with ESMTPS id 914701131EA; Fri, 6 Nov 2026 13:04:55 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by tor.lore.kernel.org (Postfix) with ESMTP id 2F72E2E3D2; Fri, 6 Nov 2026 09:40:36 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1793957812;
b=xD7bsYQL/uzNjtMiL39aiwfiDHjX/mpVxC6zwdcEHJb8/8NaAErknkiRQ/e5RiDRzTLf
SAb8+vRDSDTfm7Xs8MgAXQ3EqmQhhNjyunvuOtcMWZRJBeUBn89CtUHfZGqpBZJAH1jEK
m3ROL8RqK56kzHCr0kdW/b9lgo/0iPBKti/pVTbINm91b5FJWC5kFjLhVhzuZWys3fj9c
96qnCJYlrVGlfvlgqDZOEQ45aWturbOLexJJUXuTz4ytOGebduLECgGqwCKsQ0IxVzEiS
H+2FgFxsfWJrXfnf19X2e4zj6zqlDL/TQTiCfMbnFhK2DrTM3du9BSoikxBRjeq2BCA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793957812;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
Received:Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References:
X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type:
Content-Transfer-Encoding;
bh=S9LGaEXB1E1wvy0Af1RCtMcyHpRCTnV7LkNTlfEWfg4=;
b=C2LV8+k+a9ORu2FYRop3j+RfKsruQvbtgDEj2tU6iNx6ebsC/c9SRY555xoV61QwXS6X
acR6zoXYAJ0+5J9Ms4OrloADwpTI1KHWV4Ol84g6VYxyh5c5cxAtipkeWg84MpopCZmNn
Y/lJUKG42Of5R9I0m/eqpnKScAwYu9W7e/Vl9x6KyJh9UysxnDVtkgyUV2vI+4vcjnl+U
tG2HSpzPXf9c0mF2bqR8nrP7710UQFM34IEZyoCYbDiO2H8qdoW3kN1M+LBdl81VZ96z0
roDliZmB4eaQgaugQsKXCHTaS0DcAiLG8027taQ0uem8WAkK87HHUsbzlgmii7vXAmw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=networkplumber-org.20260707.gappssmtp.com header.i=@networkplumber-org.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=JIayTWax;
dmarc=pass header.from=networkplumber.org;
spf=pass smtp.mailfrom=networkplumber.org;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id DB89C606A338;
Fri, 6 Nov 2026 09:36:51 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key, unprotected) header.d=networkplumber-org.20260707.gappssmtp.com header.i=@networkplumber-org.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=JIayTWax
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.208.45
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1793957811;
b=EKIWsNjomuP++0CjOwRtF7SEUrcrx8USG/2VwT2EWh2fuVLSlz/EX0HAvjm1n0TDVprk
bJvUTpKmI1SpDJX3UvQ0dSE/opbpkB70tPfV6KbIoOGMiMabsLTdJttMO/CSNwxqpQCIl
4hzsMFx7zJJhN5grcWZJC7QNEF9CXpVgEQB4vjwcwqbLUrHXUKtpRZvN8xdwyQB8FutFI
U+Ui18VfeFcbQs9xT2xYaxsac+I2TNONVaDChLuvLd6exseQ2+aCt7ebvLkhEOOkjKiVw
mjsby+iMXodKJMRRXqsKRR/4GlmjwPu0syflf46BnihqoqdNwEeBy2com2K9+LOcK+A==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793957811;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Date:From:To:Cc:
Subject:Message-ID:In-Reply-To:References:MIME-Version:Content-Type:
Content-Transfer-Encoding;
bh=S9LGaEXB1E1wvy0Af1RCtMcyHpRCTnV7LkNTlfEWfg4=;
b=g/e78qUb6/iDsV+8hFhEzmB39yRZyLUf4MiZXB0BHwdP3iawYPTt/XUGBFmmgdj1dmuX
CVHsMjJ7FpoYit1aMGqOErdGrYHnjFD1TTBCVT3cFmiUog1lCb5xCwSh22wquPGQ7OiuW
98BRcj3VsOteGwE0iuWIiDiO7Q5pf5W0gr16aJ+2VonsZiMv5m1fjbfwzztoYgXHW3mbS
RuE5eygrcZBQY15s+C9XnwnxAknigXTKiWlyZQrpm/5YX2MP2G81msZ2DtG2j9D3NbgT3
htvQzvC32dFKotFUxWf9PXKWZLSnKM/zHOCrC1S3j+UycN+IepXRfp2+RnpyosRGv1w==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=networkplumber.org;
spf=pass smtp.mailfrom=networkplumber.org;
dkim=pass header.d=networkplumber-org.20260707.gappssmtp.com header.i=@networkplumber-org.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=JIayTWax;
arc=none smtp.remote-ip=209.85.208.45
X-Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 99C8A606C3FA
for <netdev@vger.kernel.org>; Fri, 6 Nov 2026 09:36:50 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 99C8A606C3FA
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=networkplumber.org
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=networkplumber.org
X-Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-6b596569640so642465a12.1
for <netdev@vger.kernel.org>; Fri, 06 Nov 2026 01:36:50 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=networkplumber-org.20260707.gappssmtp.com; s=20260707; t=1793957809; x=1794562609; darn=vger.kernel.org;
h=content-transfer-encoding:content-type:mime-version:references
:in-reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject
:date:message-id:reply-to:content-type;
bh=S9LGaEXB1E1wvy0Af1RCtMcyHpRCTnV7LkNTlfEWfg4=;
b=JIayTWaxp2ytSTWPaIY6LO9yPsbjTs0kZxLTxn3inu0yeGhmu0yciWY1nbphfxnkU2
Som7MY8RIwdSxC69B2JzvMXw0aRXC1uUGW/HGPcfP4BM5tlp05yekHtfe0EmxLIlfFfw
8Rq3y3hGojW4ToTct9lVzPzCpvmmMr32VJ51oPVny/RvV5Oq6kWz5Ie3xfqS8iGsWkvN
ciDqEfwsta+BxSRaW4V2MUExt7EMPxo+Si84KMTZCa6wWKM1SMCUO8FhcFifSUC7VPkw
Zwlj5aCbo0a1hfgNFg/cYBldyznyK0rH2+wki7bM+BNnhtDannIz3zriJi4icxf8eFbD
lsBQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1793957809; x=1794562609;
h=content-transfer-encoding:content-type:mime-version:references
:in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to
:content-type;
bh=S9LGaEXB1E1wvy0Af1RCtMcyHpRCTnV7LkNTlfEWfg4=;
b=jAVzgrO2WnmYYnDyMQuG/wmgmzugo/MPsghGLJfTQhBCkhqX2Q/zYB6QpF8o78xsQz
s+cmK62DBVv4hYdNGurN+3Sm6vwHTmHernL9lzoIhf7YE64a9YOVLewZG2ED1PwwDVjR
jN5cNPk+7h5plxFVM0i3luv7hHznQIAZ679WGiDZKn5FPKQ+hAzq9q4AhM+sQbIqf9pn
0N7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957808889;
Fri, 06 Nov 2026 01:36:48 -0800 (PST)
X-Received: from stephen-xps.local (93.224-78-194.adsl-static.isp.belgacom.be. [194.78.224.93])
by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6b65d6b3a1csm523809a12.2.2026.11.06.01.36.48
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Fri, 06 Nov 2026 01:36:48 -0800 (PST)
X-Cc: <netdev@vger.kernel.org>, David Ahern <dsahern@kernel.org>, Stefano
Garzarella <sgarzare@redhat.com>, <virtualization@lists.linux.dev>, Bobby
Eshleman <bobbyeshleman@gmail.com>
X-In-Reply-To: <20261105-vsock-guest-ns-v1-2-b1c11b3b69c7@meta.com>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list