From nobody Thu Dec 18 19:16:02 2025 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4dXL431zlVz6LZX7 for ; Thu, 18 Dec 2025 19:16:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4dXL423H9Wz4P9d for ; Thu, 18 Dec 2025 19:16:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1766085362; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=hxmj1/j4pvk84N3GnUKo6pc1onXllK3LtMtK6s8J7jc=; b=PSxgDqGDL2Lc9lpefh383VHUq4xA2LGLcHxLUmpND5e4ODIVyPhjjHtuwdAMVjwyIXBAEu d0MvhYU3vGDpwAS0b1iEXSnpkctEsgLsYnd6WfRYu5F4kzmIXXkC6nnA0ADCeD4z2ZNY9n 7+djtcWm3fLiHvJN2Ld1Z6lgLywTImiPI9ApeBW1YPIkCJPy6smZUFZw4FQupfSzveA/CO GDkUxW3zLSkB7HJs2ZrK/MY7/FRTMJO9M9slrbnL8XXDdgkeZ1nfntoRHvg0zNJ1FdQAXU rUYHB5D8Ig5rcwst6cbOiMALZlp1xZ1MuGzS/2HvpN1gqhEQwZNKAf6BMLKQKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1766085362; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=hxmj1/j4pvk84N3GnUKo6pc1onXllK3LtMtK6s8J7jc=; b=EeuFLPviDcFzAA4C2nkOiAAwW7fwn4zKgWd8nPYxRRzI1rGjLin8nQyfa+hRMBZLK66URR ZlDv3A0OLFaRaUgg2TIy6WudzwpgD/XdIrW0ZDB1ytf9rgrowPrfUsnO45UkTANHfwH3nD vk2/H+duc8Xs9oY6VOC7bC0h8aqONxxJJ01TtHpu9QCt7GvpiG2UVQpTBD+NQr53ESjunt QGLzyONh/Ujvvb7koU5jI9BlbrUXajSPitmi+QzkaaDNZTALBQ+XHP8nlJOnkfjuDhJCdS 5XpfsVNNk8LkxzwuuTa+QzITx8mOhn77R6Eq6ol0j7JUbuwz4f8C545sa59Z0A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1766085362; a=rsa-sha256; cv=none; b=OwrQc+nj2ZX55xDrJadG2hSON/FxQzYHXjqKZ6PGhn6xbD5i77XEF4qZIaQNC1bbaHxzLm W+xJtNwM8kFJ6tL82eroGPSRIf5U79fSfnvNg7sAuNnr0zDuIy0l3vZltvP6TykCT+7qrM kSjhj8rAgz5LtpPFVMICL/lqGKwhay432mWEl8dAQ2na4Y21gCiq8jEFGbZh73Kpp69G8L vPHOV5QWyra1c6NGZt3D/MiA0xGfQ4oJ7d3rXGIyJWyM6PcpQVH4hapjY4K/w6sVS982PU s8qT30Z4Z6hD5ydZmzY0yFE7u0qe7BdmUeIQ2YrL3NVmUj03V8Rs1Jkxt2QC0Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4dXL422qRJzrXN for ; Thu, 18 Dec 2025 19:16:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 346f3 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 18 Dec 2025 19:16:02 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: 713b57c414b7 - main - net: split ifnet_arrival_event into two events List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 713b57c414b789fd6c3eb2ce7ecb682b6cb4ba30 Auto-Submitted: auto-generated Date: Thu, 18 Dec 2025 19:16:02 +0000 Message-Id: <694452f2.346f3.4214bebb@gitrepo.freebsd.org> The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=713b57c414b789fd6c3eb2ce7ecb682b6cb4ba30 commit 713b57c414b789fd6c3eb2ce7ecb682b6cb4ba30 Author: Gleb Smirnoff AuthorDate: 2025-12-18 16:47:31 +0000 Commit: Gleb Smirnoff CommitDate: 2025-12-18 19:15:53 +0000 net: split ifnet_arrival_event into two events Run the original ifnet_arrival_event before linking the interface. Otherwise there is a race window when interface is already visible, but not all of the protocols have completed their attach. Provide a new event handler ifnet_attached_event, that is executed when the inteface is fully visible. Use it in route(4) socket and netlink(4) to announce new interface to the userland. Properly document the ifnet events in if_var.h. Reviewed by: zlei, melifaro Differential Revision: https://reviews.freebsd.org/D54085 --- sys/net/if.c | 5 ++--- sys/net/if_var.h | 23 +++++++++++++++++------ sys/net/rtsock.c | 4 ++-- sys/netlink/route/iface.c | 2 +- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/sys/net/if.c b/sys/net/if.c index d7c6b22821e2..b603c72bd106 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -932,10 +932,9 @@ if_attach_internal(struct ifnet *ifp, bool vmove) if (domain_init_status >= 2) if_attachdomain1(ifp); - - if_link_ifnet(ifp); - EVENTHANDLER_INVOKE(ifnet_arrival_event, ifp); + if_link_ifnet(ifp); + EVENTHANDLER_INVOKE(ifnet_attached_event, ifp); if (IS_DEFAULT_VNET(curvnet)) devctl_notify("IFNET", ifp->if_xname, "ATTACH", NULL); } diff --git a/sys/net/if_var.h b/sys/net/if_var.h index b717e879815b..cbc4969918ba 100644 --- a/sys/net/if_var.h +++ b/sys/net/if_var.h @@ -358,12 +358,23 @@ typedef void (*ifaddr_event_ext_handler_t)(void *, if_t, struct ifaddr *, int); EVENTHANDLER_DECLARE(ifaddr_event_ext, ifaddr_event_ext_handler_t); #define IFADDR_EVENT_ADD 0 #define IFADDR_EVENT_DEL 1 -/* new interface arrival event */ -typedef void (*ifnet_arrival_event_handler_t)(void *, if_t); -EVENTHANDLER_DECLARE(ifnet_arrival_event, ifnet_arrival_event_handler_t); -/* interface departure event */ -typedef void (*ifnet_departure_event_handler_t)(void *, if_t); -EVENTHANDLER_DECLARE(ifnet_departure_event, ifnet_departure_event_handler_t); + +/* + * Interface arrival & departure events. + * The ifnet_arrival_event is executed before the is yet globally visible. + * Protocols shall use this event to attach themselves. Protocols shall not + * expect other protocols to be fully attached. + * The ifnet_attached_event is executed after the interface is attached to all + * protocols, is globally visible and fully functional. + * The ifnet_departure_event is complementary to ifnet_arrival_event. The + * interface is no longer globally visible, protocols may detach. + * XXXGL: immediate memory reclamation may not be safe in ifnet_departure_event. + */ +typedef void (*ifnet_event_handler_t)(void *, if_t); +EVENTHANDLER_DECLARE(ifnet_arrival_event, ifnet_event_handler_t); +EVENTHANDLER_DECLARE(ifnet_attached_event, ifnet_event_handler_t); +EVENTHANDLER_DECLARE(ifnet_departure_event, ifnet_event_handler_t); + /* Interface link state change event */ typedef void (*ifnet_link_event_handler_t)(void *, if_t, int); EVENTHANDLER_DECLARE(ifnet_link_event, ifnet_link_event_handler_t); diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c index be858428bb3e..82af92545b79 100644 --- a/sys/net/rtsock.c +++ b/sys/net/rtsock.c @@ -317,11 +317,11 @@ rtsock_init(void *dummy __unused) SYSINIT(rtsock_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, rtsock_init, NULL); static void -rts_handle_ifnet_arrival(void *arg __unused, struct ifnet *ifp) +rts_ifnet_attached(void *arg __unused, struct ifnet *ifp) { rt_ifannouncemsg(ifp, IFAN_ARRIVAL); } -EVENTHANDLER_DEFINE(ifnet_arrival_event, rts_handle_ifnet_arrival, NULL, 0); +EVENTHANDLER_DEFINE(ifnet_attached_event, rts_ifnet_attached, NULL, 0); static void rts_handle_ifnet_departure(void *arg __unused, struct ifnet *ifp) diff --git a/sys/netlink/route/iface.c b/sys/netlink/route/iface.c index 70ec5e688c57..29a9a89fd20c 100644 --- a/sys/netlink/route/iface.c +++ b/sys/netlink/route/iface.c @@ -1508,7 +1508,7 @@ void rtnl_ifaces_init(void) { ifattach_event = EVENTHANDLER_REGISTER( - ifnet_arrival_event, rtnl_handle_ifattach, NULL, + ifnet_attached_event, rtnl_handle_ifattach, NULL, EVENTHANDLER_PRI_ANY); ifdetach_event = EVENTHANDLER_REGISTER( ifnet_departure_event, rtnl_handle_ifdetach, NULL,