git: b224af946a17 - main - netlink: Don't directly access ifnet members

From: Justin Hibbits <jhibbits_at_FreeBSD.org>
Date: Wed, 13 Nov 2024 19:29:34 UTC
The branch main has been updated by jhibbits:

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

commit b224af946a17b8e7a7b4942157556b5bc86dd6fb
Author:     Justin Hibbits <jhibbits@FreeBSD.org>
AuthorDate: 2024-10-31 15:09:48 +0000
Commit:     Justin Hibbits <jhibbits@FreeBSD.org>
CommitDate: 2024-11-13 19:30:58 +0000

    netlink: Don't directly access ifnet members
    
    Summary:
    Remove the final direct access of struct ifnet members from netlink.
    Since only the first address is used, create the iterator and then free,
    without fully iterating.
    
    Reviewed By:    kp
    Sponsored by:   Juniper Networks, Inc.
    Differential Revision: https://reviews.freebsd.org/D42972
---
 sys/netlink/route/iface.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/sys/netlink/route/iface.c b/sys/netlink/route/iface.c
index 7d33c89a396a..48fdab6a8475 100644
--- a/sys/netlink/route/iface.c
+++ b/sys/netlink/route/iface.c
@@ -322,11 +322,13 @@ dump_iface(struct nl_writer *nw, if_t ifp, const struct nlmsghdr *hdr,
 */
 	if (if_getaddrlen(ifp) != 0) {
 		struct ifaddr *ifa;
+		struct ifa_iter it;
 
 		NET_EPOCH_ENTER(et);
-		ifa = CK_STAILQ_FIRST(&ifp->if_addrhead);
+		ifa = ifa_iter_start(ifp, &it);
 		if (ifa != NULL)
 			dump_sa(nw, IFLA_ADDRESS, ifa->ifa_addr);
+		ifa_iter_finish(&it);
 		NET_EPOCH_EXIT(et);
 	}