From: David Ahern <dsa@cumulusnetworks.com>
To: netdev@vger.kernel.org
Cc: eric.dumazet@gmail.com, David Ahern <dsa@cumulusnetworks.com>
Subject: [PATCH net-next v2] net: Updates to netif_index_is_vrf
Date: Sun, 16 Aug 2015 07:49:20 -0600 [thread overview]
Message-ID: <1439732960-3302-1-git-send-email-dsa@cumulusnetworks.com> (raw)
As Eric noted netif_index_is_vrf is not called with rcu_read_lock held,
so wrap the dev_get_by_index_rcu in rcu_read_lock and unlock.
If VRF is not enabled or oif is 0 skip the device lookup. In both cases
index cannot be the VRF master.
Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
---
v2:
- per Florian's suggestion keep the dev_get_by_index_rcu and wrap with
rcu_read_lock/unlock versus moving to dev_get_by_index with dev_hold/put
include/linux/netdevice.h | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index f7a6ef2fae3a..2d3cd86c5618 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -3819,12 +3819,22 @@ static inline bool netif_is_vrf(const struct net_device *dev)
static inline bool netif_index_is_vrf(struct net *net, int ifindex)
{
- struct net_device *dev = dev_get_by_index_rcu(net, ifindex);
bool rc = false;
+#if IS_ENABLED(CONFIG_NET_VRF)
+ struct net_device *dev;
+
+ if (ifindex == 0)
+ return false;
+
+ rcu_read_lock();
+
+ dev = dev_get_by_index_rcu(net, ifindex);
if (dev)
rc = netif_is_vrf(dev);
+ rcu_read_unlock();
+#endif
return rc;
}
--
2.3.2 (Apple Git-55)
next reply other threads:[~2015-08-16 13:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-16 13:49 David Ahern [this message]
2015-08-17 22:56 ` [PATCH net-next v2] net: Updates to netif_index_is_vrf David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1439732960-3302-1-git-send-email-dsa@cumulusnetworks.com \
--to=dsa@cumulusnetworks.com \
--cc=eric.dumazet@gmail.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).