Skip to contentSkip to conversation

send notify when delete source address routes

PATCH Superseded Hangbin Liu 4 participants 9 messages Aug 9, 2023 – Sep 13, 2023

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover send notify when delete source address routes

After deleting an interface address, the relate perfer source address routes are also deleted. But there is no notify for the route deleting, which makes route daemons like NetworkManager keep a wrong cache. Fix this by sending notify when delete src routes.

Run fib_tests.sh and all passed.

Tests passed: 203
Tests failed: 0

v2: Add a bit in fib_info to mark the deleted src route.

Hangbin Liu (2):
fib: convert fib_nh_is_v6 and nh_updated to use a single bit ipv4/fib: send notify when delete source address routes

 include/net/ip_fib.h     | 5 +++--
 net/ipv4/fib_semantics.c | 3 ++-
 net/ipv4/fib_trie.c      | 4 ++++
 net/ipv4/nexthop.c       | 4 ++--
 4 files changed, 11 insertions(+), 5 deletions(-)
Signature · 1 line
2.38.1
#1 lore raw

PATCH v2 1/2 fib: convert fib_nh_is_v6 and nh_updated to use a single bit

The FIB info structure currently looks like this:

struct fib_info {
        struct hlist_node          fib_hash;             /*     0    16 */
        [...]
        u32                        fib_priority;         /*    80     4 */

        /* XXX 4 bytes hole, try to pack */

        struct dst_metrics *       fib_metrics;          /*    88     8 */
        int                        fib_nhs;              /*    96     4 */
        bool                       fib_nh_is_v6;         /*   100     1 */
        bool                       nh_updated;           /*   101     1 */

        /* XXX 2 bytes hole, try to pack */

        struct nexthop *           nh;                   /*   104     8 */
        struct callback_head       rcu __attribute__((__aligned__(8))); /*   112    16 */
        /* --- cacheline 2 boundary (128 bytes) --- */
        struct fib_nh              fib_nh[];             /*   128     0 */

        /* size: 128, cachelines: 2, members: 21 */
        /* sum members: 122, holes: 2, sum holes: 6 */
        /* forced alignments: 1 */
} __attribute__((__aligned__(8)));

Let's convert fib_nh_is_v6 and nh_updated to use a single bit, so that we can add other functional bits in later patch.

---
 include/net/ip_fib.h     | 4 ++--
 net/ipv4/fib_semantics.c | 2 +-
 net/ipv4/nexthop.c       | 4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)
include/net/ip_fib.h +2 -2
index a378eff827c7..a91f8a28689a 100644
@@ -152,8 +152,8 @@ struct fib_info {
 #define fib_rtt fib_metrics->metrics[RTAX_RTT-1]
 #define fib_advmss fib_metrics->metrics[RTAX_ADVMSS-1]
 	int			fib_nhs;
-	bool			fib_nh_is_v6;
-	bool			nh_updated;
+	u8			fib_nh_is_v6:1,
+				nh_updated:1;
 	struct nexthop		*nh;
 	struct rcu_head		rcu;
 	struct fib_nh		fib_nh[];
net/ipv4/fib_semantics.c +1 -1
index 65ba18a91865..ce1c10e408cf 100644
@@ -1572,7 +1572,7 @@ struct fib_info *fib_create_info(struct fib_config *cfg,
 			fib_info_update_nhc_saddr(net, &nexthop_nh->nh_common,
 						  fi->fib_scope);
 			if (nexthop_nh->fib_nh_gw_family == AF_INET6)
-				fi->fib_nh_is_v6 = true;
+				fi->fib_nh_is_v6 = 1;
 		} endfor_nexthops(fi)
 
 		fib_rebalance(fi);
net/ipv4/nexthop.c +2 -2
index 93f14d39fef6..5243bb80bade 100644
@@ -2213,12 +2213,12 @@ static void __nexthop_replace_notify(struct net *net, struct nexthop *nh,
 		 * and then walk the fib tables once
 		 */
 		list_for_each_entry(fi, &nh->fi_list, nh_list)
-			fi->nh_updated = true;
+			fi->nh_updated = 1;
 
 		fib_info_notify_update(net, info);
 
 		list_for_each_entry(fi, &nh->fi_list, nh_list)
-			fi->nh_updated = false;
+			fi->nh_updated = 0;
 	}
 
 	list_for_each_entry(f6i, &nh->f6i_list, nh_list)
Signature · 1 line
2.38.1
#2 lore raw

PATCH v2 2/2 ipv4/fib: send notify when delete source address routes

In reply to Hangbin Liu

After deleting an interface address in fib_del_ifaddr(), the function scans the fib_info list for stray entries and calls fib_flush() and fib_table_flush(). Then the stray entries will be deleted silently and no RTM_DELROUTE notification will be sent.

This lack of notification can make routing daemons like NetworkManager, miss the routing changes. e.g.

+ ip link add dummy1 type dummy
+ ip link add dummy2 type dummy
+ ip link set dummy1 up
+ ip link set dummy2 up
+ ip addr add 192.168.5.5/24 dev dummy1
+ ip route add 7.7.7.0/24 dev dummy2 src 192.168.5.5
+ ip -4 route
7.7.7.0/24 dev dummy2 scope link src 192.168.5.5
192.168.5.0/24 dev dummy1 proto kernel scope link src 192.168.5.5
+ ip monitor route
+ ip addr del 192.168.5.5/24 dev dummy1
Deleted 192.168.5.0/24 dev dummy1 proto kernel scope link src 192.168.5.5 Deleted broadcast 192.168.5.255 dev dummy1 table local proto kernel scope link src 192.168.5.5 Deleted local 192.168.5.5 dev dummy1 table local proto kernel scope host src 192.168.5.5

As Ido reminded, fib_table_flush() isn't only called when an address is deleted, but also when an interface is deleted or put down. The lack of notification in these cases is deliberate. And commit 7c6bb7d2faaf ("net/ipv6: Add knob to skip DELROUTE message on device down") introduced a sysctl to make IPv6 behave like IPv4 in this regard. So we can't send the route delete notify blindly in fib_table_flush().

To fix this issue, let's add a new bit in "struct fib_info" to track the deleted prefer source address routes, and only send notify for them.

After update:
+ ip monitor route
+ ip addr del 192.168.5.5/24 dev dummy1
Deleted 192.168.5.0/24 dev dummy1 proto kernel scope link src 192.168.5.5 Deleted broadcast 192.168.5.255 dev dummy1 table local proto kernel scope link src 192.168.5.5 Deleted local 192.168.5.5 dev dummy1 table local proto kernel scope host src 192.168.5.5 Deleted 7.7.7.0/24 dev dummy2 scope link src 192.168.5.5

---
v2: Add a bit in fib_info to mark the deleted src route.

---
 include/net/ip_fib.h     | 3 ++-
 net/ipv4/fib_semantics.c | 1 +
 net/ipv4/fib_trie.c      | 4 ++++
 3 files changed, 7 insertions(+), 1 deletion(-)
include/net/ip_fib.h +2 -1
index a91f8a28689a..12dedfa4c9fd 100644
@@ -153,7 +153,8 @@ struct fib_info {
 #define fib_advmss fib_metrics->metrics[RTAX_ADVMSS-1]
 	int			fib_nhs;
 	u8			fib_nh_is_v6:1,
-				nh_updated:1;
+				nh_updated:1,
+				pfsrc_removed:1;
 	struct nexthop		*nh;
 	struct rcu_head		rcu;
 	struct fib_nh		fib_nh[];
net/ipv4/fib_semantics.c +1 -0
index ce1c10e408cf..6cd919b442a7 100644
@@ -1884,6 +1884,7 @@ int fib_sync_down_addr(struct net_device *dev, __be32 local)
 			continue;
 		if (fi->fib_prefsrc == local) {
 			fi->fib_flags |= RTNH_F_DEAD;
+			fi->pfsrc_removed = 1;
 			ret++;
 		}
 	}
net/ipv4/fib_trie.c +4 -0
index 74d403dbd2b4..9cadeeaaa93a 100644
@@ -2026,6 +2026,7 @@ void fib_table_flush_external(struct fib_table *tb)
 int fib_table_flush(struct net *net, struct fib_table *tb, bool flush_all)
 {
 	struct trie *t = (struct trie *)tb->tb_data;
+	struct nl_info info = { .nl_net = net };
 	struct key_vector *pn = t->kv;
 	unsigned long cindex = 1;
 	struct hlist_node *tmp;
@@ -2088,6 +2089,9 @@ int fib_table_flush(struct net *net, struct fib_table *tb, bool flush_all)
 
 			fib_notify_alias_delete(net, n->key, &n->leaf, fa,
 						NULL);
+			if (fi->pfsrc_removed)
+				rtmsg_fib(RTM_DELROUTE, htonl(n->key), fa,
+					  KEYLENGTH - fa->fa_slen, tb->tb_id, &info, 0);
 			hlist_del_rcu(&fa->fa_list);
 			fib_release_info(fa->fa_info);
 			alias_free_mem_rcu(fa);
Signature · 1 line
2.38.1
#3 lore raw

Re: [PATCHv2 net-next 2/2] ipv4/fib: send notify when delete source address routes

Quoted 7 lines · Hangbin Liu

After deleting an interface address in fib_del_ifaddr(), the function scans the fib_info list for stray entries and calls fib_flush() and fib_table_flush(). Then the stray entries will be deleted silently and no RTM_DELROUTE notification will be sent.

This lack of notification can make routing daemons like NetworkManager, miss the routing changes. e.g.

[...]

Quoted 2 lines

To fix this issue, let's add a new bit in "struct fib_info" to track the deleted prefer source address routes, and only send notify for them.

In the other thread Thomas mentioned that NM already requests a route dump following address deletion [1]. If so, can Thomas or you please explain how this patch is going to help NM? Is the intention to optimize things and avoid the dump request (which can only work on new kernels)?

[1] https://lore.kernel.org/netdev/[email protected]/

#4 lore raw

Re: [PATCHv2 net-next 2/2] ipv4/fib: send notify when delete source address routes

Quoted 14 lines · Ido Schimmel
Quoted 7 lines · Hangbin Liu

After deleting an interface address in fib_del_ifaddr(), the function scans the fib_info list for stray entries and calls fib_flush() and fib_table_flush(). Then the stray entries will be deleted silently and no RTM_DELROUTE notification will be sent.

This lack of notification can make routing daemons like NetworkManager, miss the routing changes. e.g.

[...]

Quoted 2 lines

To fix this issue, let's add a new bit in "struct fib_info" to track the deleted prefer source address routes, and only send notify for them.

Quoted 6 lines

In the other thread Thomas mentioned that NM already requests a route dump following address deletion [1]. If so, can Thomas or you please explain how this patch is going to help NM? Is the intention to optimize things and avoid the dump request (which can only work on new kernels)?

[1] https://lore.kernel.org/netdev/[email protected]/

In my understanding, After deleting an address, deal with the delete notify is more efficient to maintain the route cache than dump all the routes.

Hi Thomas ,do you have any comments?

Thanks
Hangbin

#5 lore raw

Re: [PATCHv2 net-next 2/2] ipv4/fib: send notify when delete source address routes

Hi Thomas,

Any comments?

Thanks
Hangbin

Quoted 29 lines · Hangbin Liu
Quoted 14 lines · Ido Schimmel
Quoted 7 lines · Hangbin Liu

After deleting an interface address in fib_del_ifaddr(), the function scans the fib_info list for stray entries and calls fib_flush() and fib_table_flush(). Then the stray entries will be deleted silently and no RTM_DELROUTE notification will be sent.

This lack of notification can make routing daemons like NetworkManager, miss the routing changes. e.g.

[...]

Quoted 2 lines

To fix this issue, let's add a new bit in "struct fib_info" to track the deleted prefer source address routes, and only send notify for them.

Quoted 6 lines

In the other thread Thomas mentioned that NM already requests a route dump following address deletion [1]. If so, can Thomas or you please explain how this patch is going to help NM? Is the intention to optimize things and avoid the dump request (which can only work on new kernels)?

[1] https://lore.kernel.org/netdev/[email protected]/

In my understanding, After deleting an address, deal with the delete notify is more efficient to maintain the route cache than dump all the routes.

Hi Thomas ,do you have any comments?

Thanks
Hangbin

#6 lore raw

Re: [PATCHv2 net-next 2/2] ipv4/fib: send notify when delete source address routes

Quoted 10 lines · Hangbin Liu
Quoted 10 lines
Quoted 10 lines

In the other thread Thomas mentioned that NM already requests a route
dump following address deletion [1]. If so, can Thomas or you please
explain how this patch is going to help NM? Is the intention to optimize
things and avoid the dump request (which can only work on new kernels)?

Quoted 7 lines
Quoted 7 lines
Quoted 2 lines

[1]
https://lore.kernel.org/netdev/[email protected]/

In my understanding, After deleting an address, deal with the delete notify is
more efficient to maintain the route cache than dump all the routes.

Hi,

NetworkManager does so out of necessity, as there is no notification. Overall, it seems a pretty bad thing to do, because it's expensive if you have many routes/addresses.

Unfortunately, it's hard to ever drop a workaround, because we never know when the workaround can be dropped.

Also, it's simply a notification missing, and not tied to NetworkManager or to maintaining a cache. If you run ip route monitor, you also don't see the notification that kernel drops a route? The effort that NetworkManager takes to maintain correct information is not something that most programs would do.

Thomas

#7 lore raw

Re: [PATCHv2 net-next 2/2] ipv4/fib: send notify when delete source address routes

Hi Ido,

Do you think if I should modify the patch description and re-post it?

Thanks
Hangbin

Quoted 39 lines · Thomas Haller
Quoted 10 lines · Hangbin Liu
Quoted 10 lines
Quoted 10 lines

In the other thread Thomas mentioned that NM already requests a route
dump following address deletion [1]. If so, can Thomas or you please
explain how this patch is going to help NM? Is the intention to optimize
things and avoid the dump request (which can only work on new kernels)?

Quoted 7 lines
Quoted 7 lines
Quoted 2 lines

[1]
https://lore.kernel.org/netdev/[email protected]/

In my understanding, After deleting an address, deal with the delete notify is
more efficient to maintain the route cache than dump all the routes.

Hi,

NetworkManager does so out of necessity, as there is no notification. Overall, it seems a pretty bad thing to do, because it's expensive if you have many routes/addresses.

Unfortunately, it's hard to ever drop a workaround, because we never know when the workaround can be dropped.

Also, it's simply a notification missing, and not tied to NetworkManager or to maintaining a cache. If you run ip route monitor, you also don't see the notification that kernel drops a route? The effort that NetworkManager takes to maintain correct information is not something that most programs would do.

Thomas

#8 lore raw

Re: [PATCHv2 net-next 2/2] ipv4/fib: send notify when delete source address routes

Le 12/09/2023 à 04:30, Hangbin Liu a écrit :

Quoted 3 lines

Hi Ido,

Do you think if I should modify the patch description and re-post it?

At least, this patch seems to be targeted for net, not for net-next.

Regards,
Nicolas