Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp975736ybx; Thu, 7 Nov 2019 05:30:46 -0800 (PST) X-Google-Smtp-Source: APXvYqzbKTKf8mcp5WXjirkKk58z69awPG/RPOjDt6bXLg8+qO817Q/HMyCQYolAoEYvwACElfsJ X-Received: by 2002:a05:6402:2029:: with SMTP id ay9mr3600321edb.47.1573133446247; Thu, 07 Nov 2019 05:30:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573133446; cv=none; d=google.com; s=arc-20160816; b=vXHWX1oW0PWHGavZNv4rq+jah4oODDxL3wR1flKElZxs8xomUVKQZ6yqjWrzeu3WmT Ukz6eVyjlE1l6/mMe25aWzSNUjZLnosO3wJEo17UtM4JumXOApGSU4RvnWNiZ8OWV2p4 +DFHqgt7AXSJDHJ0+3+VeJp9mcbqIOHoorXP1d0seQIlabScV5OUTOr1Fx4LExxNPz+6 K+mGjNM9mzWIIsQ+K0VY/6i8gF7pCByoDBtNkCeUNObfr8dRF1bpGOGQI3Lian0c9RMA ctSbpctJ/pn00v+AAQ2d0ndJWHzgqn2TgTd24HiMENQnhcPg3lYmuh2eyy5pktTlHyKU Yh7Q== 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=wRJUigE76AyzxKPdwIXmFrxCAtwRa7ubQV/YC/3pAas=; b=P5LxDjQBc7muqEDpQ8EaTMtuBn3WTdpwx7XhlG68t7/Pd7iGeSdZJgv6Dry5ONgGB3 mQ/cJDa3nWdl6/xmG4HGnuv5PZIKtNL4puraVylzUHUSHoivnt8SLsTU6Yyuj5jZWzIB RcKLZU6UY2AN5n1wqpePIjPQ+umvrhZLT6WxNyz/9MF/Gs/GXWu3CuHCz/pnvFVRg0yx 7da/gMjLzNw/vpdly9GPSvDqVyNl90zPQov85OHTKr4FsNzdmg2IdSGXfM6p5p88JZGw fXLkcOXxdVLWh0wSdmi2UbDxP2ct5VfRD75aGNTXCukIjsAq6f6cNTEhiZaw3fJHrn47 KbsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@norrbonn-se.20150623.gappssmtp.com header.s=20150623 header.b=eHPgKGH9; 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 w8si1461847ejq.57.2019.11.07.05.30.22; Thu, 07 Nov 2019 05:30:46 -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=eHPgKGH9; 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 S2389089AbfKGN2J (ORCPT + 99 others); Thu, 7 Nov 2019 08:28:09 -0500 Received: from mail-lf1-f68.google.com ([209.85.167.68]:35973 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389055AbfKGN2I (ORCPT ); Thu, 7 Nov 2019 08:28:08 -0500 Received: by mail-lf1-f68.google.com with SMTP id m6so1611922lfl.3 for ; Thu, 07 Nov 2019 05:28:06 -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=wRJUigE76AyzxKPdwIXmFrxCAtwRa7ubQV/YC/3pAas=; b=eHPgKGH9xEN9hvukhqJLmmua/oS1+CUUAE74DWq5vPa7giYMlc+U3F+6XIkpMpMJVj yin0QkebMhmVmf+VmXaYUXtv1lH9PwEf7IXHiothg1gQpqQ6/sqRR6yPdH/GXhXfWHqj gd+Wi3sPvg6Rg2+d+nOcd8qxtDwZC76OERewVj7MtTcFXQoKPag2+MX55GLfjLA39hQn TrIW0RqReLaUcqK2gJQlX4pL+XSiUd5UWzqvpYJS/YpixQ2tjA3Nj7AJiVKNNAHmrx2F 2UzWWOmR2J3UfXttJ46kdPIIMd26uPHCpD1zyhsLDgwAbOg8PqTlCAUpiiR86l37VagS 8ojw== 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=wRJUigE76AyzxKPdwIXmFrxCAtwRa7ubQV/YC/3pAas=; b=fotqAHJwU3UJ3pPde/JP8RC1wqlaIRni9wpO/Tb3zAELAJDJPPtGIECZW1rUDjxdb2 h8MTKu0aSRt2/lSBJb0WBfJKSCJZ4J4mxaWwYU4gWXY3go8lPFuVQ1rvzctzr1x3+bHD RfoRhqjBqIfu8Bh6Z5zpjWvAbZH6bexFfke+TmgnpMoOcuURIICumBudop0rVued7hCi cVYZofBZ3lDOFpGZC00zxnl8Llbj0Ffu9qlfnmCGsgb7EQ9j0TJxixsiB87YOspARSEP +quoADKaLrrPkVQaURLUlQsXOJGBC1up1ZkBF/dZdr8GMXen6NroUEgqLnLmERhJLk6r NxnQ== X-Gm-Message-State: APjAAAVjg1oQrPRHquz2AxIAcDP5sS17HZj+Fe1C53ISzlEzUcf5UG8h EE8DhXqCHDi4YlxOUbOSvHtcQg== X-Received: by 2002:ac2:5deb:: with SMTP id z11mr2563233lfq.35.1573133285907; Thu, 07 Nov 2019 05:28:05 -0800 (PST) Received: from mimer.lan (h-137-65.A159.priv.bahnhof.se. [81.170.137.65]) by smtp.gmail.com with ESMTPSA id y20sm3151507ljd.99.2019.11.07.05.28.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2019 05:28:05 -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 v3 6/6] net: ipv6: allow setting address on interface outside current namespace Date: Thu, 7 Nov 2019 14:27:55 +0100 Message-Id: <20191107132755.8517-7-jonas@norrbonn.se> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191107132755.8517-1-jonas@norrbonn.se> References: <20191107132755.8517-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 This patch allows an interface outside of the current namespace to be selected when setting a new IPv6 address for a device. This uses the IFA_TARGET_NETNSID attribute to select the namespace in which to search for the interface to act upon. Signed-off-by: Jonas Bonn --- net/ipv6/addrconf.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 34ccef18b40e..06a49670fe62 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -4721,6 +4721,7 @@ inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, struct netlink_ext_ack *extack) { struct net *net = sock_net(skb->sk); + struct net *tgt_net; struct ifaddrmsg *ifm; struct nlattr *tb[IFA_MAX+1]; struct in6_addr *peer_pfx; @@ -4758,6 +4759,18 @@ inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, cfg.preferred_lft = ci->ifa_prefered; } + if (tb[IFA_TARGET_NETNSID]) { + s32 netnsid = nla_get_s32(tb[IFA_TARGET_NETNSID]); + + tgt_net = rtnl_get_net_ns_capable(NETLINK_CB(skb).sk, netnsid); + if (IS_ERR(tgt_net)) { + NL_SET_ERR_MSG(extack, + "ipv6: Invalid target network namespace id"); + return PTR_ERR(tgt_net); + } + net = tgt_net; + } + dev = __dev_get_by_index(net, ifm->ifa_index); if (!dev) return -ENODEV; -- 2.20.1