git: b9b2184322da - main - netlink: clear IPv6 embedded scope when dumping route gateways.

From: Alexander V. Chernikov <melifaro_at_FreeBSD.org>
Date: Tue, 21 Feb 2023 12:27:48 UTC
The branch main has been updated by melifaro:

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

commit b9b2184322da85e1f4d52e3b0a6322dd214210ec
Author:     Alexander V. Chernikov <melifaro@FreeBSD.org>
AuthorDate: 2023-02-21 12:25:58 +0000
Commit:     Alexander V. Chernikov <melifaro@FreeBSD.org>
CommitDate: 2023-02-21 12:27:26 +0000

    netlink: clear IPv6 embedded scope when dumping route gateways.
    
    Reported by:    zarychtam@plan-b.pwste.edu.pl
    MFC after:      3 days
---
 sys/netlink/route/rt.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/sys/netlink/route/rt.c b/sys/netlink/route/rt.c
index 534186447b4d..dabdaea3e03b 100644
--- a/sys/netlink/route/rt.c
+++ b/sys/netlink/route/rt.c
@@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$");
 #include <net/route/nhop.h>
 #include <net/route/route_ctl.h>
 #include <net/route/route_var.h>
+#include <netinet6/scope6_var.h>
 #include <netlink/netlink.h>
 #include <netlink/netlink_ctl.h>
 #include <netlink/netlink_route.h>
@@ -123,7 +124,9 @@ rc_get_nhop(const struct rib_cmd_info *rc)
 static void
 dump_rc_nhop_gw(struct nl_writer *nw, const struct nhop_object *nh)
 {
+#ifdef INET6
 	int upper_family;
+#endif
 
 	switch (nhop_get_neigh_family(nh)) {
 	case AF_LINK:
@@ -132,19 +135,27 @@ dump_rc_nhop_gw(struct nl_writer *nw, const struct nhop_object *nh)
 	case AF_INET:
 		nlattr_add(nw, NL_RTA_GATEWAY, 4, &nh->gw4_sa.sin_addr);
 		break;
+#ifdef INET6
 	case AF_INET6:
 		upper_family = nhop_get_upper_family(nh);
 		if (upper_family == AF_INET6) {
-			nlattr_add(nw, NL_RTA_GATEWAY, 16, &nh->gw6_sa.sin6_addr);
+			struct in6_addr gw6 = nh->gw6_sa.sin6_addr;
+			in6_clearscope(&gw6);
+
+			nlattr_add(nw, NL_RTA_GATEWAY, 16, &gw6);
 		} else if (upper_family == AF_INET) {
 			/* IPv4 over IPv6 */
+			struct in6_addr gw6 = nh->gw6_sa.sin6_addr;
+			in6_clearscope(&gw6);
+
 			char buf[20];
 			struct rtvia *via = (struct rtvia *)&buf[0];
 			via->rtvia_family = AF_INET6;
-			memcpy(via->rtvia_addr, &nh->gw6_sa.sin6_addr, 16);
+			memcpy(via->rtvia_addr, &gw6, 16);
 			nlattr_add(nw, NL_RTA_VIA, 17, via);
 		}
 		break;
+#endif
 	}
 }