git: d62b2d8f3a47 - stable/14 - Fix failure to add an interface prefix route when route with the same prefix is already presented in the routing table.

From: Eugene Grosbein <eugen_at_FreeBSD.org>
Date: Sat, 11 Jan 2025 12:27:47 UTC
The branch stable/14 has been updated by eugen:

URL: https://cgit.FreeBSD.org/src/commit/?id=d62b2d8f3a4711724d984102daa0bd0a5351f8b9

commit d62b2d8f3a4711724d984102daa0bd0a5351f8b9
Author:     Alexander V. Chernikov <melifaro@FreeBSD.org>
AuthorDate: 2024-11-12 23:36:50 +0000
Commit:     Eugene Grosbein <eugen@FreeBSD.org>
CommitDate: 2025-01-11 12:25:16 +0000

    Fix failure to add an interface prefix route
    when route with the same prefix is already presented
    in the routing table.
    
    PR:             277125
    Reported by:    Oleksandr Ignatyev <alex@i.org.ua>
    Reviewed by:    ae, jlduran
    Tested by:      jlduran
    Differential Revision: https://reviews.freebsd.org/D47534
    
    (cherry picked from commit 1da4954c92ea7585b352ba830d3ee64ca69ada52)
---
 sys/net/route/route_ctl.c | 13 ++++++++-----
 sys/net/route/route_ctl.h | 10 +++++-----
 2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/sys/net/route/route_ctl.c b/sys/net/route/route_ctl.c
index a07a58737c1c..d7756f2a0eb6 100644
--- a/sys/net/route/route_ctl.c
+++ b/sys/net/route/route_ctl.c
@@ -772,12 +772,15 @@ add_route_byinfo(struct rib_head *rnh, struct rt_addrinfo *info,
 	rnd_add.rnd_weight = get_info_weight(info, RT_DEFAULT_WEIGHT);
 
 	int op_flags = RTM_F_CREATE;
-	if (get_prio_from_info(info) == NH_PRIORITY_HIGH)
-		op_flags |= RTM_F_FORCE;
-	else
-		op_flags |= RTM_F_APPEND;
-	return (add_route_flags(rnh, rt, &rnd_add, op_flags, rc));
 
+	/*
+	 * Set the desired action when the route already exists:
+	 * If RTF_PINNED is present, assume the direct kernel routes that cannot be multipath.
+	 * Otherwise, append the path.
+	 */
+	op_flags |= (info->rti_flags & RTF_PINNED) ? RTM_F_REPLACE : RTM_F_APPEND;
+
+	return (add_route_flags(rnh, rt, &rnd_add, op_flags, rc));
 }
 
 static int
diff --git a/sys/net/route/route_ctl.h b/sys/net/route/route_ctl.h
index 140f14aa9e4f..845df8ce1fbe 100644
--- a/sys/net/route/route_ctl.h
+++ b/sys/net/route/route_ctl.h
@@ -61,11 +61,11 @@ int rib_del_route_px_gw(uint32_t fibnum, struct sockaddr *dst, int plen,
     const struct sockaddr *gw, int op_flags, struct rib_cmd_info *rc);
 
 /* operation flags */
-#define	RTM_F_CREATE	0x01
-#define	RTM_F_EXCL	0x02
-#define	RTM_F_REPLACE	0x04
-#define	RTM_F_APPEND	0x08
-#define	RTM_F_FORCE	0x10
+#define	RTM_F_CREATE	0x01	/* Create object if not exists */
+#define	RTM_F_EXCL	0x02	/* (Deprecated) Do not replace or append if exists */
+#define	RTM_F_REPLACE	0x04	/* Replace if route (even multipath) if exists */
+#define	RTM_F_APPEND	0x08	/* Append path to the route */
+#define	RTM_F_FORCE	0x10	/* Bump operation priority to highest */
 
 int rib_add_route(uint32_t fibnum, struct rt_addrinfo *info,
   struct rib_cmd_info *rc);