Skip to contentSkip to conversation

net: ipv6: put host and anycast routes on device with address

PATCH Superseded David Ahern 2 participants 3 messages Aug 16, 2017 – Aug 17, 2017

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: ipv6: put host and anycast routes on device with address

One nagging difference between ipv4 and ipv6 is host routes for ipv6 addresses are installed using the loopback device or VRF / L3 Master device. e.g.,

2001:db8:1::/120 dev veth0 proto kernel metric 256 pref medium local 2001:db8:1::1 dev lo table local proto kernel metric 0 pref medium

Using the loopback device is convenient -- necessary for local tx, but has some nasty side effects, most notably setting the 'lo' device down causes all host routes for all local IPv6 address to be removed from the FIB and completely breaks IPv6 networking across all interfaces.

This patch puts FIB entries for IPv6 routes against the device. This simplifies the routes in the FIB, for example by making dst->dev and rt6i_idev->dev the same (a future patch can look at removing the device reference taken for rt6i_idev for FIB entries). For example:

    $ ip -6 r ls table all | grep veth1
    2001:db8:99::/120 dev veth1 proto kernel metric 256 pref medium
    anycast 2001:db8:99:: dev veth1 table local proto kernel metric 0 pref medium
    local 2001:db8:99::1 dev veth1 table local proto kernel metric 0 pref medium

When copies are made on FIB lookups, the cloned route has dst->dev set to loopback (or the L3 master device). This is needed for the local Tx of packets to local addresses.

With fib entries allocated against the real network device, the addrconf code that reinserts host routes on admin up of 'lo' is no longer needed.

---
 net/ipv6/addrconf.c | 42 ------------------------------------------
 net/ipv6/route.c    | 46 ++++++++++++++++++++++++++++++++++------------
 2 files changed, 34 insertions(+), 54 deletions(-)
net/ipv6/addrconf.c +0 -42
index 640792e1ecb7..45d0a24644de 100644
@@ -3030,9 +3030,6 @@ static void sit_add_v4_addrs(struct inet6_dev *idev)
 static void init_loopback(struct net_device *dev)
 {
 	struct inet6_dev  *idev;
-	struct net_device *sp_dev;
-	struct inet6_ifaddr *sp_ifa;
-	struct rt6_info *sp_rt;
 
 	/* ::1 */
 
@@ -3045,45 +3042,6 @@ static void init_loopback(struct net_device *dev)
 	}
 
 	add_addr(idev, &in6addr_loopback, 128, IFA_HOST);
-
-	/* Add routes to other interface's IPv6 addresses */
-	for_each_netdev(dev_net(dev), sp_dev) {
-		if (!strcmp(sp_dev->name, dev->name))
-			continue;
-
-		idev = __in6_dev_get(sp_dev);
-		if (!idev)
-			continue;
-
-		read_lock_bh(&idev->lock);
-		list_for_each_entry(sp_ifa, &idev->addr_list, if_list) {
-
-			if (sp_ifa->flags & (IFA_F_DADFAILED | IFA_F_TENTATIVE))
-				continue;
-
-			if (sp_ifa->rt) {
-				/* This dst has been added to garbage list when
-				 * lo device down, release this obsolete dst and
-				 * reallocate a new router for ifa.
-				 */
-				if (!sp_ifa->rt->rt6i_node) {
-					ip6_rt_put(sp_ifa->rt);
-					sp_ifa->rt = NULL;
-				} else {
-					continue;
-				}
-			}
-
-			sp_rt = addrconf_dst_alloc(idev, &sp_ifa->addr, false);
-
-			/* Failure cases are ignored */
-			if (!IS_ERR(sp_rt)) {
-				sp_ifa->rt = sp_rt;
-				ip6_ins_rt(sp_rt);
-			}
-		}
-		read_unlock_bh(&idev->lock);
-	}
 }
 
 void addrconf_add_linklocal(struct inet6_dev *idev,
net/ipv6/route.c +34 -12

78 lines not on this page · raw message

Signature · 1 line
2.1.4
#1 lore raw
Quoted 26 lines · David Ahern

One nagging difference between ipv4 and ipv6 is host routes for ipv6 addresses are installed using the loopback device or VRF / L3 Master device. e.g.,

2001:db8:1::/120 dev veth0 proto kernel metric 256 pref medium local 2001:db8:1::1 dev lo table local proto kernel metric 0 pref medium

Using the loopback device is convenient -- necessary for local tx, but has some nasty side effects, most notably setting the 'lo' device down causes all host routes for all local IPv6 address to be removed from the FIB and completely breaks IPv6 networking across all interfaces.

This patch puts FIB entries for IPv6 routes against the device. This simplifies the routes in the FIB, for example by making dst->dev and rt6i_idev->dev the same (a future patch can look at removing the device reference taken for rt6i_idev for FIB entries). For example:

    $ ip -6 r ls table all | grep veth1
    2001:db8:99::/120 dev veth1 proto kernel metric 256 pref medium
    anycast 2001:db8:99:: dev veth1 table local proto kernel metric 0 pref medium
    local 2001:db8:99::1 dev veth1 table local proto kernel metric 0 pref medium

When copies are made on FIB lookups, the cloned route has dst->dev set to loopback (or the L3 master device). This is needed for the local Tx of packets to local addresses.

Quoted 9 lines

With fib entries allocated against the real network device, the addrconf code that reinserts host routes on admin up of 'lo' is no longer needed.

---
 net/ipv6/addrconf.c | 42 ------------------------------------------
 net/ipv6/route.c    | 46 ++++++++++++++++++++++++++++++++++------------
 2 files changed, 34 insertions(+), 54 deletions(-)

DaveM: please drop this one. I found a use case that is failing: UDP packets to a local linklocal address with no server are not getting the ICMP unreachable. Will send a v2 when tests complete.

maintainer
#2 lore raw

From: David Ahern <[email protected]>
Date: Thu, 17 Aug 2017 10:56:54 -0600

Quoted 3 lines

DaveM: please drop this one. I found a use case that is failing: UDP packets to a local linklocal address with no server are not getting the ICMP unreachable. Will send a v2 when tests complete.

Ok.