From: Sergey Popovich <popovich_sergei@mail.ru>
To: netdev@vger.kernel.org
Subject: [PATCH 4/4 v3] ipv4: mark nexthop as dead when it's subnet becomes unreachable
Date: Fri, 24 Jan 2014 12:25:17 +0200 [thread overview]
Message-ID: <1521507.ObZglEaf1D@tuxracer> (raw)
In-Reply-To: <2039386.VZO3kUlZdW@tuxracer>
Removing ip address and it's subnet route using fib_del_ifaddr() does
not purge routes with nexthop in such subnet.
This could be easily reproduced with the following config:
ip link add dev dummy1 type dummy
ip link set up dev dummy1
ip -4 addr add 10.0.10.1/24 dev dummy1
ip -4 addr add 10.0.20.1/24 dev dummy1
ip -4 route add 172.16.0.0/12 proto static via 10.0.10.5
ip -4 route show exact 172.16.0.0/12
172.16.0.0/12 via 10.0.10.5 dev dummy1 proto static
ip -4 addr del 10.0.10.1/24 dev dummy1
ip -4 route show exact 172.16.0.0/12
172.16.0.0/12 via 10.0.10.5 dev dummy1 proto static
Add interface address (ifa) parameter to fib_sync_down_dev()
and use it to match nexthop against it's subnet.
Use fib_sync_down_dev() in fib_del_ifaddr() among with fib_sync_down_addr()
to mark as dead routes with nexthop in ifa.
v3. Fix NH marking as dead when NH gateway subnet is still on
interface (e.g. 10.0.10.1/24 and 10.0.30.1/16 and NH is 10.0.10.5).
Thanks to Julian Anastasov.
v2. Fix NH marking as dead when NH created with onlink option.
Signed-off-by: Sergey Popovich <popovich_sergei@mail.ru>
---
include/net/ip_fib.h | 3 ++-
net/ipv4/fib_frontend.c | 5 +++--
net/ipv4/fib_semantics.c | 29 +++++++++++++++++++++++++++--
3 files changed, 32 insertions(+), 5 deletions(-)
diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
index 9922093..0405fc9 100644
--- a/include/net/ip_fib.h
+++ b/include/net/ip_fib.h
@@ -287,8 +287,9 @@ static inline int fib_num_tclassid_users(struct net *net)
#endif
/* Exported by fib_semantics.c */
+struct in_ifaddr;
int ip_fib_check_default(__be32 gw, struct net_device *dev);
-int fib_sync_down_dev(struct net_device *dev, int force);
+int fib_sync_down_dev(struct net_device *dev, struct in_ifaddr *ifa, int force);
int fib_sync_down_addr(struct net *net, __be32 local);
int fib_sync_up(struct net_device *dev);
void fib_select_multipath(struct fib_result *res);
diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
index ae5f35f..fd3445e 100644
--- a/net/ipv4/fib_frontend.c
+++ b/net/ipv4/fib_frontend.c
@@ -907,7 +907,8 @@ void fib_del_ifaddr(struct in_ifaddr *ifa, struct in_ifaddr *iprim)
* First of all, we scan fib_info list searching
* for stray nexthop entries, then ignite fib_flush.
*/
- if (fib_sync_down_addr(dev_net(dev), ifa->ifa_local))
+ if (fib_sync_down_addr(dev_net(dev), ifa->ifa_local) +
+ fib_sync_down_dev(dev, ifa, 0))
fib_flush(dev_net(dev));
}
}
@@ -997,7 +998,7 @@ static void nl_fib_lookup_exit(struct net *net)
static void fib_disable_ip(struct net_device *dev, int force)
{
- if (fib_sync_down_dev(dev, force))
+ if (fib_sync_down_dev(dev, NULL, force))
fib_flush(dev_net(dev));
rt_cache_flush(dev_net(dev));
arp_ifdown(dev);
diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
index 9d43468..fbebba5 100644
--- a/net/ipv4/fib_semantics.c
+++ b/net/ipv4/fib_semantics.c
@@ -1112,7 +1112,29 @@ int fib_sync_down_addr(struct net *net, __be32 local)
return ret;
}
-int fib_sync_down_dev(struct net_device *dev, int force)
+static inline bool fib_sync_down_gw(struct fib_nh *nh,
+ struct in_ifaddr *ifr)
+{
+ if (!ifr)
+ return true;
+
+ if (nh->nh_flags & RTNH_F_ONLINK)
+ return false;
+
+ if (!inet_ifa_match(nh->nh_gw, ifr))
+ return false;
+
+ for_ifa(ifr->ifa_dev) {
+ if (unlikely(ifa == ifr))
+ continue;
+ if (inet_ifa_match(nh->nh_gw, ifa))
+ return false;
+ } endfor_ifa(ifr->ifa_dev);
+
+ return true;
+}
+
+int fib_sync_down_dev(struct net_device *dev, struct in_ifaddr *ifa, int force)
{
int ret = 0;
int scope = RT_SCOPE_NOWHERE;
@@ -1124,6 +1146,8 @@ int fib_sync_down_dev(struct net_device *dev, int force)
if (force)
scope = -1;
+ BUG_ON(ifa && ifa->ifa_dev->dev != dev);
+
hlist_for_each_entry(nh, head, nh_hash) {
struct fib_info *fi = nh->nh_parent;
int dead;
@@ -1137,7 +1161,8 @@ int fib_sync_down_dev(struct net_device *dev, int force)
if (nexthop_nh->nh_flags & RTNH_F_DEAD)
dead++;
else if (nexthop_nh->nh_dev == dev &&
- nexthop_nh->nh_scope != scope) {
+ nexthop_nh->nh_scope != scope &&
+ fib_sync_down_gw(nexthop_nh, ifa)) {
nexthop_nh->nh_flags |= RTNH_F_DEAD;
#ifdef CONFIG_IP_ROUTE_MULTIPATH
spin_lock_bh(&fib_multipath_lock);
--
1.8.3.4
next prev parent reply other threads:[~2014-01-24 10:25 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-21 11:48 [PATCH 0/4] ipv4: small set of fixes Sergey Popovich
2014-01-21 11:48 ` [PATCH 1/4] ipv4: don't disable interface if last ipv4 address is removed Sergey Popovich
2014-01-23 1:52 ` David Miller
2014-01-21 11:48 ` [PATCH 2/4] ipv4: fib_semantics: increment fib_info_cnt after fib_info allocation Sergey Popovich
2014-01-21 11:48 ` [PATCH 3/4] ipv4: use SNMP macro assuming softirq context in ip_forward() Sergey Popovich
2014-01-23 1:52 ` David Miller
2014-01-21 11:48 ` [PATCH 4/4] ipv4: mark nexthop as dead when it's subnet becomes unreachable Sergey Popovich
2014-01-23 1:53 ` David Miller
2014-01-23 10:06 ` Julian Anastasov
2014-01-23 15:05 ` Sergey Popovich
2014-01-23 21:58 ` Julian Anastasov
2014-01-24 10:12 ` Sergey Popovich
2014-01-24 10:25 ` Sergey Popovich [this message]
2014-01-24 21:49 ` [PATCH 4/4 v3] " Julian Anastasov
2014-01-24 10:15 ` [PATCH 4/4 v3] ipv4: mark nexthop as dead when it's subnet becomes Sergey Popovich
2014-01-24 10:26 ` Sergey Popovich
2014-01-23 1:54 ` [PATCH 0/4] ipv4: small set of fixes 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=1521507.ObZglEaf1D@tuxracer \
--to=popovich_sergei@mail.ru \
--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