From: David Ahern <dsahern@kernel.org>
To: davem@davemloft.net, netdev@vger.kernel.org
Cc: idosch@mellanox.com, jiri@mellanox.com, saeedm@mellanox.com,
David Ahern <dsahern@gmail.com>
Subject: [PATCH v2 net-next 02/13] ipv4: Move IN_DEV_IGNORE_ROUTES_WITH_LINKDOWN to helper
Date: Wed, 27 Mar 2019 11:23:18 -0700 [thread overview]
Message-ID: <20190327182329.18149-3-dsahern@kernel.org> (raw)
In-Reply-To: <20190327182329.18149-1-dsahern@kernel.org>
From: David Ahern <dsahern@gmail.com>
in_dev lookup followed by IN_DEV_IGNORE_ROUTES_WITH_LINKDOWN check
is called in several places, some with the rcu lock and others with the
rtnl held.
Move the check to a helper similar to what IPv6 has. Since the helper
can be invoked from either context use rcu_dereference_rtnl to
dereference ip_ptr.
Signed-off-by: David Ahern <dsahern@gmail.com>
Reviewed-by: Ido Schimmel <idosch@mellanox.com>
---
include/linux/inetdevice.h | 14 ++++++++++++++
net/ipv4/fib_semantics.c | 31 +++++++------------------------
net/ipv4/fib_trie.c | 4 +---
3 files changed, 22 insertions(+), 27 deletions(-)
diff --git a/include/linux/inetdevice.h b/include/linux/inetdevice.h
index a64f21a97369..367dc2a0f84a 100644
--- a/include/linux/inetdevice.h
+++ b/include/linux/inetdevice.h
@@ -237,6 +237,20 @@ static inline struct in_device *__in_dev_get_rtnl(const struct net_device *dev)
return rtnl_dereference(dev->ip_ptr);
}
+/* called with rcu_read_lock or rtnl held */
+static inline bool ip_ignore_linkdown(const struct net_device *dev)
+{
+ struct in_device *in_dev;
+ bool rc = false;
+
+ in_dev = rcu_dereference_rtnl(dev->ip_ptr);
+ if (in_dev &&
+ IN_DEV_IGNORE_ROUTES_WITH_LINKDOWN(in_dev))
+ rc = true;
+
+ return rc;
+}
+
static inline struct neigh_parms *__in_dev_arp_parms_get_rcu(const struct net_device *dev)
{
struct in_device *in_dev = __in_dev_get_rcu(dev);
diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
index b5dbbdfd1e49..78631eb255f7 100644
--- a/net/ipv4/fib_semantics.c
+++ b/net/ipv4/fib_semantics.c
@@ -558,7 +558,6 @@ static void fib_rebalance(struct fib_info *fi)
{
int total;
int w;
- struct in_device *in_dev;
if (fi->fib_nhs < 2)
return;
@@ -568,10 +567,7 @@ static void fib_rebalance(struct fib_info *fi)
if (nh->nh_flags & RTNH_F_DEAD)
continue;
- in_dev = __in_dev_get_rtnl(nh->nh_dev);
-
- if (in_dev &&
- IN_DEV_IGNORE_ROUTES_WITH_LINKDOWN(in_dev) &&
+ if (ip_ignore_linkdown(nh->nh_dev) &&
nh->nh_flags & RTNH_F_LINKDOWN)
continue;
@@ -582,12 +578,9 @@ static void fib_rebalance(struct fib_info *fi)
change_nexthops(fi) {
int upper_bound;
- in_dev = __in_dev_get_rtnl(nexthop_nh->nh_dev);
-
if (nexthop_nh->nh_flags & RTNH_F_DEAD) {
upper_bound = -1;
- } else if (in_dev &&
- IN_DEV_IGNORE_ROUTES_WITH_LINKDOWN(in_dev) &&
+ } else if (ip_ignore_linkdown(nexthop_nh->nh_dev) &&
nexthop_nh->nh_flags & RTNH_F_LINKDOWN) {
upper_bound = -1;
} else {
@@ -1325,12 +1318,8 @@ int fib_dump_info(struct sk_buff *skb, u32 portid, u32 seq, int event,
nla_put_u32(skb, RTA_OIF, fi->fib_nh->nh_oif))
goto nla_put_failure;
if (fi->fib_nh->nh_flags & RTNH_F_LINKDOWN) {
- struct in_device *in_dev;
-
rcu_read_lock();
- in_dev = __in_dev_get_rcu(fi->fib_nh->nh_dev);
- if (in_dev &&
- IN_DEV_IGNORE_ROUTES_WITH_LINKDOWN(in_dev))
+ if (ip_ignore_linkdown(fi->fib_nh->nh_dev))
rtm->rtm_flags |= RTNH_F_DEAD;
rcu_read_unlock();
}
@@ -1361,12 +1350,8 @@ int fib_dump_info(struct sk_buff *skb, u32 portid, u32 seq, int event,
rtnh->rtnh_flags = nh->nh_flags & 0xFF;
if (nh->nh_flags & RTNH_F_LINKDOWN) {
- struct in_device *in_dev;
-
rcu_read_lock();
- in_dev = __in_dev_get_rcu(nh->nh_dev);
- if (in_dev &&
- IN_DEV_IGNORE_ROUTES_WITH_LINKDOWN(in_dev))
+ if (ip_ignore_linkdown(nh->nh_dev))
rtnh->rtnh_flags |= RTNH_F_DEAD;
rcu_read_unlock();
}
@@ -1433,7 +1418,7 @@ int fib_sync_down_addr(struct net_device *dev, __be32 local)
static int call_fib_nh_notifiers(struct fib_nh *fib_nh,
enum fib_event_type event_type)
{
- struct in_device *in_dev = __in_dev_get_rtnl(fib_nh->nh_dev);
+ bool ignore_link_down = ip_ignore_linkdown(fib_nh->nh_dev);
struct fib_nh_notifier_info info = {
.fib_nh = fib_nh,
};
@@ -1442,14 +1427,12 @@ static int call_fib_nh_notifiers(struct fib_nh *fib_nh,
case FIB_EVENT_NH_ADD:
if (fib_nh->nh_flags & RTNH_F_DEAD)
break;
- if (IN_DEV_IGNORE_ROUTES_WITH_LINKDOWN(in_dev) &&
- fib_nh->nh_flags & RTNH_F_LINKDOWN)
+ if (ignore_link_down && fib_nh->nh_flags & RTNH_F_LINKDOWN)
break;
return call_fib4_notifiers(dev_net(fib_nh->nh_dev), event_type,
&info.info);
case FIB_EVENT_NH_DEL:
- if ((in_dev && IN_DEV_IGNORE_ROUTES_WITH_LINKDOWN(in_dev) &&
- fib_nh->nh_flags & RTNH_F_LINKDOWN) ||
+ if ((ignore_link_down && fib_nh->nh_flags & RTNH_F_LINKDOWN) ||
(fib_nh->nh_flags & RTNH_F_DEAD))
return call_fib4_notifiers(dev_net(fib_nh->nh_dev),
event_type, &info.info);
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index 1704f432de1f..656d3d19f112 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -1471,12 +1471,10 @@ int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp,
continue;
for (nhsel = 0; nhsel < fi->fib_nhs; nhsel++) {
const struct fib_nh *nh = &fi->fib_nh[nhsel];
- struct in_device *in_dev = __in_dev_get_rcu(nh->nh_dev);
if (nh->nh_flags & RTNH_F_DEAD)
continue;
- if (in_dev &&
- IN_DEV_IGNORE_ROUTES_WITH_LINKDOWN(in_dev) &&
+ if (ip_ignore_linkdown(nh->nh_dev) &&
nh->nh_flags & RTNH_F_LINKDOWN &&
!(fib_flags & FIB_LOOKUP_IGNORE_LINKSTATE))
continue;
--
2.11.0
next prev parent reply other threads:[~2019-03-27 18:38 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-27 18:23 [PATCH v2 net-next 00/13] net: Move fib_nh and fib6_nh to a common struct David Ahern
2019-03-27 18:23 ` [PATCH v2 net-next 01/13] ipv4: Define fib_get_nhs when CONFIG_IP_ROUTE_MULTIPATH is disabled David Ahern
2019-03-27 18:23 ` David Ahern [this message]
2019-03-27 18:23 ` [PATCH v2 net-next 03/13] ipv4: Create init helper for fib_nh David Ahern
2019-03-27 18:23 ` [PATCH v2 net-next 04/13] ipv4: Create cleanup " David Ahern
2019-03-27 18:23 ` [PATCH v2 net-next 05/13] ipv6: Create init helper for fib6_nh David Ahern
2019-03-27 22:52 ` Alexei Starovoitov
2019-03-28 0:47 ` David Ahern
2019-03-28 1:30 ` Alexei Starovoitov
2019-03-28 2:05 ` David Ahern
2019-03-28 2:29 ` Alexei Starovoitov
2019-03-28 2:50 ` David Ahern
2019-03-28 3:04 ` Alexei Starovoitov
2019-03-28 2:11 ` David Ahern
2019-03-27 18:23 ` [PATCH v2 net-next 06/13] ipv6: Create cleanup " David Ahern
2019-03-27 18:23 ` [PATCH v2 net-next 07/13] ipv6: Move gateway checks to a fib6_nh setting David Ahern
2019-03-27 18:23 ` [PATCH v2 net-next 08/13] ipv6: Refactor fib6_ignore_linkdown David Ahern
2019-03-27 18:23 ` [PATCH v2 net-next 09/13] ipv6: Change rt6_add_nexthop and rt6_nexthop_info to take fib6_nh David Ahern
2019-03-27 18:23 ` [PATCH v2 net-next 10/13] ipv4: Rename fib_nh entries David Ahern
2019-03-27 18:23 ` [PATCH v2 net-next 11/13] ipv6: Rename fib6_nh entries David Ahern
2019-03-27 18:23 ` [PATCH v2 net-next 12/13] net: Add fib_nh_common and update fib_nh and fib6_nh David Ahern
2019-03-27 18:23 ` [PATCH v2 net-next 13/13] net: Use common nexthop init and release helpers David Ahern
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=20190327182329.18149-3-dsahern@kernel.org \
--to=dsahern@kernel.org \
--cc=davem@davemloft.net \
--cc=dsahern@gmail.com \
--cc=idosch@mellanox.com \
--cc=jiri@mellanox.com \
--cc=netdev@vger.kernel.org \
--cc=saeedm@mellanox.com \
/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).