From patchwork Sun Mar 12 23:01:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Frederic Sowa X-Patchwork-Id: 737922 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3vhGkW0NjSz9s78 for ; Mon, 13 Mar 2017 10:03:15 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=stressinduktion.org header.i=@stressinduktion.org header.b="DjMa3cXC"; dkim=pass (1024-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="gruKSteY"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935758AbdCLXDO (ORCPT ); Sun, 12 Mar 2017 19:03:14 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:32835 "EHLO out1-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935589AbdCLXCQ (ORCPT ); Sun, 12 Mar 2017 19:02:16 -0400 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 4E66A2060A for ; Sun, 12 Mar 2017 19:02:09 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute7.internal (MEProxy); Sun, 12 Mar 2017 19:02:09 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= stressinduktion.org; h=date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=bw/W2vz5x8+59GjOr1ehkxcUiRo=; b=DjMa3c XCLj6ERR9sjD9h8R/DUpxqjPspdC8N1gGJYQm9QUothufkFxOesMIN9fumSDYFxv aq94bw3wol+tcoeAB+GZQNzhVjgG9+PFkx6JFPvv7NQUw2njorq0vPaRViLSb57s rD6Ssp53BH9WRP99AQZBOB+tWmX+jx/0t/Xmo= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=smtpout; bh=bw/W2vz5x8+59GjOr1ehkxcUiRo=; b=gruKS teYwVOLgGdyapgIfGBjq98eWhJ5xAi/UfjUuwkKTIeCdNuA68LtMD17yvT/S1wk/ x0g0mvj1SoOKHkjk1HDXLwZ0Ro1QSYEDimBhK8TsvjQeSALP/bqQPfcG0ru8p4BT sHFiphH0fMZ5keFJ6KAKpAfWboAx8zFiDb8flw= X-ME-Sender: X-Sasl-enc: Kgj9t2OMu+900ckfM2Rw2pADYWS9PMevctebj0lVEzbn 1489359728 Received: from m.localhost.localhost (unknown [213.55.211.72]) by mail.messagingengine.com (Postfix) with ESMTPA id 69E0F2423E for ; Sun, 12 Mar 2017 19:02:08 -0400 (EDT) From: Hannes Frederic Sowa To: netdev@vger.kernel.org Subject: [PATCH net-next RFC v1 17/27] afnetns: introduce __inet_select_addr Date: Mon, 13 Mar 2017 00:01:41 +0100 Message-Id: <20170312230151.5185-18-hannes@stressinduktion.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170312230151.5185-1-hannes@stressinduktion.org> References: <20170312230151.5185-1-hannes@stressinduktion.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Signed-off-by: Hannes Frederic Sowa --- include/linux/inetdevice.h | 2 ++ net/ipv4/devinet.c | 27 ++++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/include/linux/inetdevice.h b/include/linux/inetdevice.h index 01cbcfe93383b7..a41bfce099e0a1 100644 --- a/include/linux/inetdevice.h +++ b/include/linux/inetdevice.h @@ -170,6 +170,8 @@ int inet_addr_onlink(struct in_device *in_dev, __be32 a, __be32 b); int devinet_ioctl(struct net *net, unsigned int cmd, void __user *); void devinet_init(void); struct in_device *inetdev_by_index(struct net *, int); +__be32 __inet_select_addr(const struct net_device *dev, __be32 dst, int scope, + struct afnetns *afnetns); __be32 inet_select_addr(const struct net_device *dev, __be32 dst, int scope); __be32 inet_confirm_addr(struct net *net, struct in_device *in_dev, __be32 dst, __be32 local, int scope); diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index cc15afefa1df0a..0844d917aa8d7d 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c @@ -1224,7 +1224,17 @@ static int inet_gifconf(struct net_device *dev, char __user *buf, int len) return done; } -__be32 inet_select_addr(const struct net_device *dev, __be32 dst, int scope) +static struct afnetns *ifa_afnetns(struct in_ifaddr *ifa) +{ +#if IS_ENABLED(CONFIG_AFNETNS) + return ifa->afnetns; +#else + return NULL; +#endif +} + +__be32 __inet_select_addr(const struct net_device *dev, __be32 dst, + int scope, struct afnetns *afnetns) { __be32 addr = 0; struct in_device *in_dev; @@ -1237,6 +1247,8 @@ __be32 inet_select_addr(const struct net_device *dev, __be32 dst, int scope) goto no_in_dev; for_primary_ifa(in_dev) { + if (afnetns && afnetns != ifa_afnetns(ifa)) + continue; if (ifa->ifa_scope > scope) continue; if (!dst || inet_ifa_match(dst, ifa)) { @@ -1262,7 +1274,8 @@ __be32 inet_select_addr(const struct net_device *dev, __be32 dst, int scope) (in_dev = __in_dev_get_rcu(dev))) { for_primary_ifa(in_dev) { if (ifa->ifa_scope != RT_SCOPE_LINK && - ifa->ifa_scope <= scope) { + ifa->ifa_scope <= scope && + (!afnetns || afnetns == ifa_afnetns(ifa))) { addr = ifa->ifa_local; goto out_unlock; } @@ -1283,7 +1296,8 @@ __be32 inet_select_addr(const struct net_device *dev, __be32 dst, int scope) for_primary_ifa(in_dev) { if (ifa->ifa_scope != RT_SCOPE_LINK && - ifa->ifa_scope <= scope) { + ifa->ifa_scope <= scope && + (!afnetns || afnetns == ifa_afnetns(ifa))) { addr = ifa->ifa_local; goto out_unlock; } @@ -1293,6 +1307,13 @@ __be32 inet_select_addr(const struct net_device *dev, __be32 dst, int scope) rcu_read_unlock(); return addr; } +EXPORT_SYMBOL(__inet_select_addr); + +__be32 inet_select_addr(const struct net_device *dev, __be32 dst, + int scope) +{ + return __inet_select_addr(dev, dst, scope, NULL); +} EXPORT_SYMBOL(inet_select_addr); static __be32 confirm_addr_indev(struct in_device *in_dev, __be32 dst,