Commit c8d8090bec for frr

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

    zebra: handle address cases that macOS does not notify

    zebra marks an address that it installed as real, and announces it to
    the daemons, once the kernel notifies it, and withdraws it once the
    kernel notifies its deletion.

    XNU emits RTM_NEWADDR and RTM_DELADDR for an IPv4 address only when it
    adds or deletes the subnet route of the address: nothing for a 2nd
    address in a subnet that the interface already has, nor for an address
    that another interface already has.

    So on macOS, process the result of every install and uninstall request
    of an address of a broadcast interface, once the kernel accepted it.
    When XNU notifies the address too, whichever comes second finds the
    same address and changes nothing. The dplane results and the routing
    socket are read separately: ignore a result that is not current
    anymore, an address that zebra does not want anymore or that the
    kernel already removed.

    The handling is in interface.c and not in kernel_socket.c: like
    zebra_if_dplane_result(), it runs from rib_process_dplane_results(),
    in the main zebra pthread that owns the interfaces and their connected
    addresses. It is built only on macOS: on other systems the results of
    the address requests are still ignored, Linux netlink notifies every
    address change.

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

diff --git a/zebra/interface.c b/zebra/interface.c
index 21b7f4d73a..f6d0d10e49 100644
--- a/zebra/interface.c
+++ b/zebra/interface.c
@@ -1399,6 +1399,49 @@ static void zebra_if_addr_update_ctx(struct zebra_dplane_ctx *ctx,
 		rib_update(RIB_UPDATE_KERNEL_LAST_IPV4_ADDRESS_DELETED, ZEBRA_ROUTE_ALL);
 }

+#ifdef __APPLE__
+void zebra_if_addr_result(struct zebra_dplane_ctx *ctx)
+{
+	const struct prefix *addr = dplane_ctx_get_intf_addr(ctx);
+	struct connected *ifc;
+	struct interface *ifp;
+
+	if (dplane_ctx_get_status(ctx) != ZEBRA_DPLANE_REQUEST_SUCCESS)
+		return;
+
+	ifp = if_lookup_by_index_per_nsid(dplane_ctx_get_ns_id(ctx), dplane_ctx_get_ifindex(ctx));
+	/* point-to-point addresses are left to RTM_NEWADDR, which gives their peer */
+	if (!ifp || if_is_pointopoint(ifp))
+		return;
+
+	ifc = connected_check(ifp, addr);
+
+	if (dplane_ctx_get_op(ctx) == DPLANE_OP_ADDR_INSTALL) {
+		/* removed since: by an uninstall request, or by a RTM_DELADDR */
+		if (!ifc || !CHECK_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED) ||
+		    !CHECK_FLAG(ifc->conf, ZEBRA_IFC_QUEUED))
+			return;
+
+		if (addr->family == AF_INET)
+			connected_add_ipv4(ifp, 0, &addr->u.prefix4, addr->prefixlen, NULL, NULL,
+					   METRIC_MAX);
+		else if (addr->family == AF_INET6)
+			connected_add_ipv6(ifp, 0, &addr->u.prefix6, NULL, addr->prefixlen, NULL,
+					   METRIC_MAX);
+		return;
+	}
+
+	/* already gone, or installed again since */
+	if (!ifc || CHECK_FLAG(ifc->conf, ZEBRA_IFC_QUEUED))
+		return;
+
+	if (addr->family == AF_INET)
+		connected_delete_ipv4(ifp, 0, &addr->u.prefix4, addr->prefixlen, NULL);
+	else if (addr->family == AF_INET6)
+		connected_delete_ipv6(ifp, &addr->u.prefix6, NULL, addr->prefixlen);
+}
+#endif /* __APPLE__ */
+
 static void zebra_if_update_ctx(struct zebra_dplane_ctx *ctx,
 				struct interface *ifp)
 {
diff --git a/zebra/interface.h b/zebra/interface.h
index e3e08e9e65..ff40c63b82 100644
--- a/zebra/interface.h
+++ b/zebra/interface.h
@@ -343,6 +343,9 @@ extern void zebra_l2_unmap_slave_from_bond(struct zebra_if *zif);
 extern const char *zebra_protodown_rc_str(uint32_t protodown_rc, char *pd_buf,
 					  uint32_t pd_buf_len);
 void zebra_if_dplane_result(struct zebra_dplane_ctx *ctx);
+#ifdef __APPLE__
+void zebra_if_addr_result(struct zebra_dplane_ctx *ctx);
+#endif

 #ifdef HAVE_PROC_NET_DEV
 extern void ifstat_update_proc(void);
diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c
index 4796443efd..80d00aa1fa 100644
--- a/zebra/zebra_rib.c
+++ b/zebra/zebra_rib.c
@@ -5666,9 +5666,14 @@ static void rib_process_dplane_results(struct event *event)
 				zebra_tc_qdisc_handle_notify(ctx);
 				break;

-			/* Some op codes not handled here */
 			case DPLANE_OP_ADDR_INSTALL:
 			case DPLANE_OP_ADDR_UNINSTALL:
+#ifdef __APPLE__
+				zebra_if_addr_result(ctx);
+#endif
+				break;
+
+			/* Some op codes not handled here */
 			case DPLANE_OP_VTEP_ADD:
 			case DPLANE_OP_VTEP_DELETE:
 			case DPLANE_OP_BR_PORT_UPDATE: