Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp473366ybx; Tue, 5 Nov 2019 00:12:48 -0800 (PST) X-Google-Smtp-Source: APXvYqxL0i4HTCfVyUpyLsjX2ohoF+N1Xz5O4xozMeFh7O+Hyn8jjBNHRdZ4R+9bWfUJQY7m/Uu3 X-Received: by 2002:aa7:c716:: with SMTP id i22mr7778218edq.237.1572941568597; Tue, 05 Nov 2019 00:12:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572941568; cv=none; d=google.com; s=arc-20160816; b=OZds/BnhlA9Iyi00StUlxaLgmvE1H3uEvRcD6SEOE0S9DuiS0E6bO20HHhrPobBGHa TD4MYXxRBmZtI6GwkIYh2rECzsZqBPROgLZd3TjPnWFPxSq/MGW/TJK7kRneVE84NtLh M9S0iGK9DFNiFCKz9NzIYchDTLM+rpeIds/zYzO027MSOPDe7gKaPV04Ufzcci6bNGAr mQBK+3dZ1lrceLt18t9MX+98XR2iP2g+quqKRTR6cge0K0zJArJ61iHTTh14RvDTTedC EcayqZkPOkq6njQzvMDHCFCkFbzGtmaMWc4L7c2+K+3eQSIesyWXB0qU3305tP8XPQY0 wRrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=O8fWg+Ma5bc8RsOBhTOll0AqdVjJK6jvagus6dMpmcQ=; b=JvKaIQmqV4RCAP1Uo6H4ionOjVWg16xodcfXSrYPm/taBej1ZOyob3bGWWc4JQPvb/ bGkfFadaDp+Ehv+UDuk5sm86z/uUw4SpR/b+bxHBfC+dkbO5OunjVTMnGYqHnGAU5aHR 5VgpvzfuRBfxKp0x0e3GoBSKU+E6oZp/2hrtXJgZrp8MsbleHNDkLG7NnVjv2n7kLR6/ vq/DkTdSfB1REBCU6YglVE9kv1qa++Bry3RVQmcYNGXQhRw3vYI6T5eh9FKbK7I8puFG zj33vaA0Wx+uNXnvFMOlqpfUpkPDTthaceUF/ZB4njtB7XO4n5vnUZ+38qDw37lfw8jn GYRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@norrbonn-se.20150623.gappssmtp.com header.s=20150623 header.b="Zcf4/SyW"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d13si12678775ejj.317.2019.11.05.00.12.25; Tue, 05 Nov 2019 00:12:48 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@norrbonn-se.20150623.gappssmtp.com header.s=20150623 header.b="Zcf4/SyW"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388282AbfKEILf (ORCPT + 99 others); Tue, 5 Nov 2019 03:11:35 -0500 Received: from mail-lf1-f67.google.com ([209.85.167.67]:43678 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388209AbfKEILc (ORCPT ); Tue, 5 Nov 2019 03:11:32 -0500 Received: by mail-lf1-f67.google.com with SMTP id j5so14361142lfh.10 for ; Tue, 05 Nov 2019 00:11:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=norrbonn-se.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=O8fWg+Ma5bc8RsOBhTOll0AqdVjJK6jvagus6dMpmcQ=; b=Zcf4/SyWe5TJNkVp+0Og7VVNUrzIJk62VtAw908Cq926vhBECbqpi87sK3UifO9toC VyvSu7cfKgtaSDEGhdF+Q/G7vi+qbj+G53TTnhRGxdrRmmjOsFvJf94JM//cgMrEivhn wyrdIC+bVhEGxoPogeHAngMH3EG+TZjkAiwQAw+tmblPDlMeRpQ+G3fskeG9SuNRN/B+ 0dD2gy2AcvjxViWGaRHzIxhfvs/8lyymdw3t1yVn3HWjAKO4f5XO8sf+SgAJl1SQBKqj +Bk6zcBR8pOyZ6pVDd+vm5v+hoHHue1uH2U9RslWBvdyu25XFAHrlM9mju58d2CG/HAM cTbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=O8fWg+Ma5bc8RsOBhTOll0AqdVjJK6jvagus6dMpmcQ=; b=mzdCWQEMB9VgjtRYfkpUiK9jzvDFIgM4aYeof8qOMB5f49qt/QJoD5xuqArM5d7q6L eClMd5jIrIy+QYO7O/rjNZJ2isCIBzdu0aRCaBjflIQ94Oy5KF8uhdl0nxtbLkPAatjD FYw6WjqkCYq+KgBnDiUdjcf40q7c1YpIOOHVEwhFJkyGfzhya1Zrsge1/pulyUhqqR15 Qi0Eqs+eqb0OWqcKDV2JZabv07/oiKIXCTPwlxaeJClOYNhxZ82ZgVnpftjnD0xcEBvS xP5AlW00jjM3kmPlqTcN9gYo5tFxWfJAs8O/B+CuPQ7XomfJr/Sd/6VcN4OzwuB5F+wL sKnw== X-Gm-Message-State: APjAAAWwL4Dpa6plEmaj2gPF3AO08bv5ymoASN6QAbElaPMJh8BHdhP9 PE1qcQoUmLXSN5/puxVP1+ViVA== X-Received: by 2002:a19:614b:: with SMTP id m11mr832939lfk.157.1572941490745; Tue, 05 Nov 2019 00:11:30 -0800 (PST) Received: from mimer.lulea.netrounds.lan ([195.22.87.57]) by smtp.gmail.com with ESMTPSA id m7sm7275986lfp.22.2019.11.05.00.11.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2019 00:11:30 -0800 (PST) From: Jonas Bonn To: nicolas.dichtel@6wind.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: davem@davemloft.net, Jonas Bonn Subject: [PATCH 5/5] net: namespace: allow setting NSIDs outside current namespace Date: Tue, 5 Nov 2019 09:11:12 +0100 Message-Id: <20191105081112.16656-6-jonas@norrbonn.se> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191105081112.16656-1-jonas@norrbonn.se> References: <20191105081112.16656-1-jonas@norrbonn.se> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently it is only possible to move an interface to a new namespace if the destination namespace has an ID in the interface's current namespace. If the interface already resides outside of the current namespace, then we may need to assign the destination namespace an ID in the interface's namespace in order to effect the move. This patch allows namespace ID's to be created outside of the current namespace. With this, the following is possible: i) Our namespace is 'A'. ii) The interface resides in namespace 'B' iii) We can assign an ID for NS 'A' in NS 'B' iv) We can then move the interface into our own namespace. and i) Our namespace is 'A'; namespaces 'B' and 'C' also exist ii) We can assign an ID for namespace 'C' in namespace 'B' iii) We can then create a VETH interface directly in namespace 'B' with the other end in 'C', all without ever leaving namespace 'A' Signed-off-by: Jonas Bonn --- net/core/net_namespace.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c index 6d3e4821b02d..0071f395098d 100644 --- a/net/core/net_namespace.c +++ b/net/core/net_namespace.c @@ -724,6 +724,7 @@ static int rtnl_net_newid(struct sk_buff *skb, struct nlmsghdr *nlh, struct nlattr *tb[NETNSA_MAX + 1]; struct nlattr *nla; struct net *peer; + struct net *target = NULL; int nsid, err; err = nlmsg_parse_deprecated(nlh, sizeof(struct rtgenmsg), tb, @@ -752,6 +753,21 @@ static int rtnl_net_newid(struct sk_buff *skb, struct nlmsghdr *nlh, return PTR_ERR(peer); } + if (tb[NETNSA_TARGET_NSID]) { + int id = nla_get_s32(tb[NETNSA_TARGET_NSID]); + + target = rtnl_get_net_ns_capable(NETLINK_CB(skb).sk, id); + if (IS_ERR(target)) { + NL_SET_BAD_ATTR(extack, tb[NETNSA_TARGET_NSID]); + NL_SET_ERR_MSG(extack, + "Target netns reference is invalid"); + err = PTR_ERR(target); + goto out; + } + + net = target; + } + spin_lock_bh(&net->nsid_lock); if (__peernet2id(net, peer) >= 0) { spin_unlock_bh(&net->nsid_lock); @@ -773,6 +789,9 @@ static int rtnl_net_newid(struct sk_buff *skb, struct nlmsghdr *nlh, NL_SET_BAD_ATTR(extack, tb[NETNSA_NSID]); NL_SET_ERR_MSG(extack, "The specified nsid is already used"); } + + if (target) + put_net(target); out: put_net(peer); return err; -- 2.20.1