Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp1008066ybx; Thu, 7 Nov 2019 06:00:04 -0800 (PST) X-Google-Smtp-Source: APXvYqxXPR3wg3o1rIvapZe1JjTSMdRsDRslLMs87BaizYZTs4snNQVOiWNX0zZawk8EIh7TN5l5 X-Received: by 2002:a50:c191:: with SMTP id m17mr3687333edf.259.1573135204189; Thu, 07 Nov 2019 06:00:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573135204; cv=none; d=google.com; s=arc-20160816; b=Zz75hBBHF8ttAbdMhKztwxu/dKXA0kgpv7cXq/Ri4b4Yn2jadHmH/Cm+5kJmQuT8Kk hrToETO5rC/6nQg22d2/viAnJIpqwt57fmePWP9dJyX8FRL6gV5lfBzMy8wkNjQhec+a OZl4+Zr100jXZc72FWIy7zypXGjiqmI44fEGzfgCTkUiVEljLeZmRRFWkmLmtTbfFHAX 7aarIUrTxxphQ8InJfzvcp8mXskiAIBBi9fjusN6aPRP8QxuQnu4P1k3JJyfpmFGmhX1 I6pSPbJ7zKOSytIPrhyZaTZ7GQv+I+oerS/MiJXRDdayjQMq26ZnNjI+iRezsBcSxMoR eB+A== 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=1TX8xaGatMSdm2p99RnjVc360czbsJGz8WZJSaymf6M=; b=RvPv2Jth9ur67l+NnvT3r53wCaion+WanJ6JKT1s8B1JlWmYQi5Iu+nBHh9OwsvNj7 LxCj8++PTAOrT8NfpTPf487lTVg3VGE8Wgz1nFT3rC9/L+GSrYkKpB7ZtsVyEqPfJpFN 11M+uz8+M8S5u9KTXKIRouqGNs+KbugOPGlZK0aCRA+Kd0E2iuqEch75KSGwueC0jBWl liuafJEoEBP2w+vXSC/lFOzCp4GwnEF73tIE3+juv1shHwQSWX8mTWhgh4ftn6u4bfVe mlCK8fSvdtEKPEjWzlgJmNqXDvA8TA7MFLKaos60OO0cXkFPWhjLFsX3xOT5KNlMaOIy RJ5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@norrbonn-se.20150623.gappssmtp.com header.s=20150623 header.b=O8zbOeVr; 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 oq2si1437205ejb.402.2019.11.07.05.59.40; Thu, 07 Nov 2019 06:00:04 -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=O8zbOeVr; 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 S2389004AbfKGN46 (ORCPT + 99 others); Thu, 7 Nov 2019 08:56:58 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:46184 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730980AbfKGN46 (ORCPT ); Thu, 7 Nov 2019 08:56:58 -0500 Received: by mail-lj1-f195.google.com with SMTP id e9so2337478ljp.13 for ; Thu, 07 Nov 2019 05:56:57 -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=1TX8xaGatMSdm2p99RnjVc360czbsJGz8WZJSaymf6M=; b=O8zbOeVrfelqXQlVZ2eNw0YwlQmFt60dOpoM90BkVxQyTr1f3PwwWOzMfp0wKsaIKh uWDM1Ug5Dj8FV9k7EVgZ+ii7+cI4M6eDav8lGkSuLUgqKiUI8gAAn96cdKA2Wc17Fa1K Tqfmt1Nc8yBcIH2iTGK3/rEyLVB3FffRAsW/SIXC/MQGznKxluoPqZYHnA7R3+xlWbbZ WsuNEFnlaGquzh3rDdMtLQHVXsr6HmqrxDbuolCI+aN2VRbHL7DkjlrgR6Eg5UENanWq RZQehUOEkOZ74/wLWBOmlkVLYCL/VJ4S9hmpdkPMKKpRRLuvCejLgbSSu0QH+xkr7Ful ioLA== 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=1TX8xaGatMSdm2p99RnjVc360czbsJGz8WZJSaymf6M=; b=TcG0f6kLH+YwuaRUnQcekzFKvp1pLl2Cch/7hBu8R7/HGeQYmK+Q+cqdBQBxbKmHRZ kqtKAhru3F0zehRWwJgUBTILJI0cWSENmrjRz6MiMlAA8O2J+59/m8AJR3GVSUxgLe3o fe7eJNrq44p+XQAlca7WiSfrfSo5u5KuIuJvSOUw9Leksr/XvyXZKWipdUEqRUK/ZL+/ qIwS5HoqcN9pIFD6yKboUL6doRSEEFT8f+iaM3Bp4if1/6EDJmd36mg5F4AWlvzVX5+7 I+ltMrZoK0qAw5zTxTy+p61NIjAihdABsR2InAWxhrca8UyOd3PzouDqPmGbUJlSoEn8 wmeQ== X-Gm-Message-State: APjAAAVOt4Gkdu6qh9nVdEYEZTHlYUCk58lP5aM/dM1xGb9Aq+6j9h6C cc9o9FTogERWaLaWc8/DKb77xw== X-Received: by 2002:a2e:88c9:: with SMTP id a9mr2393868ljk.30.1573135016509; Thu, 07 Nov 2019 05:56:56 -0800 (PST) Received: from mimer.lan (h-137-65.A159.priv.bahnhof.se. [81.170.137.65]) by smtp.gmail.com with ESMTPSA id v6sm1067697ljd.15.2019.11.07.05.56.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2019 05:56:55 -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 1/1] net: ipv6: allow setting address on interface outside current namespace Date: Thu, 7 Nov 2019 14:56:52 +0100 Message-Id: <20191107135652.19629-1-jonas@norrbonn.se> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191107132755.8517-7-jonas@norrbonn.se> References: <20191107132755.8517-7-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 --- I messed up this patch and the cleanup code path wasn't included. It should look like this. Sorry for the noise. /Jonas net/ipv6/addrconf.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 34ccef18b40e..8ef8297db150 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 = NULL; struct ifaddrmsg *ifm; struct nlattr *tb[IFA_MAX+1]; struct in6_addr *peer_pfx; @@ -4758,9 +4759,23 @@ 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; + if (!dev) { + err = -ENODEV; + goto out; + } if (tb[IFA_FLAGS]) cfg.ifa_flags = nla_get_u32(tb[IFA_FLAGS]); @@ -4773,8 +4788,10 @@ inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, IFA_F_MCAUTOJOIN | IFA_F_OPTIMISTIC; idev = ipv6_find_idev(dev); - if (IS_ERR(idev)) - return PTR_ERR(idev); + if (IS_ERR(idev)) { + err = PTR_ERR(idev); + goto out; + } if (!ipv6_allow_optimistic_dad(net, idev)) cfg.ifa_flags &= ~IFA_F_OPTIMISTIC; @@ -4782,7 +4799,8 @@ inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, if (cfg.ifa_flags & IFA_F_NODAD && cfg.ifa_flags & IFA_F_OPTIMISTIC) { NL_SET_ERR_MSG(extack, "IFA_F_NODAD and IFA_F_OPTIMISTIC are mutually exclusive"); - return -EINVAL; + err = -EINVAL; + goto out; } ifa = ipv6_get_ifaddr(net, cfg.pfx, dev, 1); @@ -4791,7 +4809,8 @@ inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, * It would be best to check for !NLM_F_CREATE here but * userspace already relies on not having to provide this. */ - return inet6_addr_add(net, ifm->ifa_index, &cfg, extack); + err = inet6_addr_add(net, ifm->ifa_index, &cfg, extack); + goto out; } if (nlh->nlmsg_flags & NLM_F_EXCL || @@ -4802,6 +4821,9 @@ inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, in6_ifa_put(ifa); +out: + if (tgt_net) + put_net(tgt_net); return err; } -- 2.20.1