Commit 8ac974b34e for frr

commit 8ac974b34ebb1ab9968a7b5276e1fc25601bce7a
Author: Vincent Jardin <vjardin@free.fr>
Date:   Wed Nov 11 10:48:35 2026 +0100

    zebra: do not delete an interface that is set down on macOS

    Without RTM_IFANNOUNCE, ifm_read() cannot tell an interface that
    is set down is to be removed.

    macOS has no RTM_IFANNOUNCE, and the RTM_IFINFO sent when the
    interface is set up again has no sockaddr_dl to create it from, so the
    interface is lost until zebra restarts:

      ifam_read: no interface for ifname en0, index 6
      Interface index 6 (new) missing ifname

    For the same reason, interfaces that are down when zebra reads the
    interface list are ignored.

    Workaround: on macOS, only delete an interface when if_indextoname() no
    longer knows its index, and do not skip the interfaces that are down.

    Signed-off-by: Vincent Jardin <vjardin@free.fr>

diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c
index 9f21d834ed..a90ddc5fca 100644
--- a/zebra/kernel_socket.c
+++ b/zebra/kernel_socket.c
@@ -456,6 +456,24 @@ static int ifan_read(struct if_announcemsghdr *ifan)
 }
 #endif /* RTM_IFANNOUNCE */

+#ifndef RTM_IFANNOUNCE
+/*
+ * Without RTM_IFANNOUNCE, an interface that goes down may have been deleted.
+ * macOS sets interfaces down without deleting them: it is gone only once its
+ * index is.
+ */
+static bool kernel_if_gone(const struct if_msghdr *ifm)
+{
+#ifdef __APPLE__
+	char name[IFNAMSIZ];
+
+	return if_indextoname(ifm->ifm_index, name) == NULL;
+#else
+	return true;
+#endif /* __APPLE__ */
+}
+#endif /* RTM_IFANNOUNCE */
+
 #ifdef HAVE_BSD_IFI_LINK_STATE
 /* BSD link detect translation */
 static void bsd_linkdetect_translate(struct if_msghdr *ifm)
@@ -606,13 +624,13 @@ int ifm_read(struct if_msghdr *ifm)
 			return -1;
 		}

-#ifndef RTM_IFANNOUNCE
+#if !defined(RTM_IFANNOUNCE) && !defined(__APPLE__)
 		/* Down->Down interface should be ignored here.
 		 * See further comment below.
 		 */
 		if (!CHECK_FLAG(ifm->ifm_flags, IFF_UP))
 			return 0;
-#endif /* !RTM_IFANNOUNCE */
+#endif /* !RTM_IFANNOUNCE && !__APPLE__ */

 		if (ifp == NULL) {
 			/* Interface that zebra was not previously aware of, so
@@ -714,7 +732,8 @@ int ifm_read(struct if_msghdr *ifm)
 			 * will still behave correctly if run on a platform
 			 * without
 			 */
-			if_delete_update(&ifp);
+			if (kernel_if_gone(ifm))
+				if_delete_update(&ifp);
 		}
 #endif /* RTM_IFANNOUNCE */
 		if (ifp && if_is_up(ifp)) {