From nobody Thu Jun 01 11:51:51 2023 X-Original-To: dev-commits-src-all@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 4QX4HD3Dvlz4YMj7; Thu, 1 Jun 2023 11:51:52 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QX4HC3mYHz4Ch2; Thu, 1 Jun 2023 11:51:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685620311; 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=tZ121k0XZnk2ulh88irUfB7zWZNLxMmZpo0qaqX91/E=; b=sAMLSqLqMpav2RVJJzyTFS4SESu2Iepsv3C2eL5wBw7SgCpSdfpGrkIxNJZh6guFodyRFT F38GWF/WAezvrL6VhNXjFJ9jz/bxAZbHr/pVgjYQX/C/20YExFiwjD2q5XdSREmZbO6thm cJfzRBS3ZYEEezuT82uFyRUKkz6PaqIrySsCC8F4MvjaojKmvO5rZrF38Q/Ba0ZqJNtc0Y Hk4rXSvsDiVg93s8SxV+r4CVrCo6pHY8yOmn+rilfefLWEsd3Us0spUdj8mIQkAERIQBCX twZYzbfHVFrX7a742nHQSspN2ivcNibk4DEiLNllmlwvGwFX7GMdUyF9nfhNaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685620311; 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=tZ121k0XZnk2ulh88irUfB7zWZNLxMmZpo0qaqX91/E=; b=Bv8A+CKWOGBCQrkcJvL0oItYOjKaZrYZf2wRX5zPYsvBdRXrGORzAXFoK2ty+fr5466z6N 6TauNnYxKsXAid2S/S0Orh+CJpoAcFQs3qpbeZNIV0UU6o/gppfgDRfu6oZ2VypM3xIc7P rhBP/6x/Jn6OG9N08Pq9L0PwLdUl54wr1iOpKdafT0K8rH44TYBzk5h9aUUpNG8JxmDaa4 t6dHmB3r662SOlz8T3fDYge5DgKSvBSQq8vCml+6musXXRzbZGUFiWaUutjuhONhElIJje 0YMuN/ZmkGK7c66vfO+rOwyCalIrEH3g7n8W+KpCXqw76Dw1FsGD+CtAvMkUew== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1685620311; a=rsa-sha256; cv=none; b=KJxzMxFcE1sHoRPQgVcFNmoeypMZdOBVRAfEiX2OJE4eDMEI5PeMkEaezraU9gRztzqpsI 6BZ7Z+X+RNtaayG11UtwvuS6sDyN1v3F7UENo0x5zRswzjrdkJBVs2CUOjs3VBzKkxITKe bdInMsWuP3ImGvPMWbRuBH6D2uBp6hmvAMFdaGiBQIfwdN1GMuN+JxLoHgutxZv6Dwqlpm aHsTY17Nijv4PFPTVpXaU+F9LGBBSQtAVUNqnYTt2rVTC+5vTpXqWexYbfQY2pH/3u+uO2 fveLZIOYHaPdBARxUC3BwT0NAp4Wm8mabxj8v128Qx/xg2g6MRY6KIqaMxUn5A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4QX4HC2s8VzGNT; Thu, 1 Jun 2023 11:51:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 351Bppq6053824; Thu, 1 Jun 2023 11:51:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 351Bpp8c053823; Thu, 1 Jun 2023 11:51:51 GMT (envelope-from git) Date: Thu, 1 Jun 2023 11:51:51 GMT Message-Id: <202306011151.351Bpp8c053823@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Alexander V. Chernikov" Subject: git: a77facd27368 - main - ifnet: consistently call hooks when the interface gets up. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: melifaro X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a77facd27368f618520d25391cfce11149879a41 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=a77facd27368f618520d25391cfce11149879a41 commit a77facd27368f618520d25391cfce11149879a41 Author: Alexander V. Chernikov AuthorDate: 2023-06-01 11:44:15 +0000 Commit: Alexander V. Chernikov CommitDate: 2023-06-01 11:44:19 +0000 ifnet: consistently call hooks when the interface gets up. Some context on the current IPv6 interface setup & address management: There are two data path for IPv6 initialisation in context of assigning LL addresses: 1) Userland explicitly requests IFF_UP for the interface w/o any addresses. if_up() then calls in6_if_up(), which calls in6_ifattach(). The latter sets up some initial ND/IN6 state and disables IPv6 for the interface if it’s not loopback. If the interface is loopback, then it adds ::1/128 and LL addresses via in6_ifattach_loopback(). Then, devd notification is generated (if the VNET is the default one), which triggers rc.network ifconfig_up(), causing ifdisabled to be removed via SIOCSIFINFO_IN6 from ifconfig. The kernel SIOCSIFINFO_IN6 handler calls in6_if_up() once again and it assigns the interface link-local address. 2) Userland adds IPv4 or IPv6 address to the interface. SIOCAIFADDR[_IN6] kernel handler calls IPv4/IPv6 protocol handler to add the address. Both then call if_ioctl() with SIOCSIFADDR. Ethernet/loopback ioctl handlers silently sets IFF_UP for the interface. Finally, if.c:ifioctl() wrapper code compares old and new interface flags and, if IFF_UP is added, it explicitly calls in6_if_up(), which adds link-local address if either the original address is IPv6 or the interface is loopback. In the latter case, “formal” interface-up notifications are missing. The kernel does not trigger event handler event, does not call carp hook and does not provide any userland notification. This diff unifies the event handling in both scenarios, providing the necessary notifications to the kernel and userland. Reviewed By: kp Differential Revision: https://reviews.freebsd.org/D40332 MFC after: 2 weeks --- sys/net/if.c | 36 +++++++----------------------------- sys/netinet6/in6.c | 14 ++++++++++++++ sys/netlink/route/iface.c | 4 +--- 3 files changed, 22 insertions(+), 32 deletions(-) diff --git a/sys/net/if.c b/sys/net/if.c index af9758a39324..975f4498073e 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -278,7 +278,6 @@ static void if_attachdomain1(struct ifnet *); static int ifconf(u_long, caddr_t); static void if_input_default(struct ifnet *, struct mbuf *); static int if_requestencap_default(struct ifnet *, struct if_encap_req *); -static void if_route(struct ifnet *, int flag, int fam); static int if_setflag(struct ifnet *, int, int, int *, int); static int if_transmit_default(struct ifnet *ifp, struct mbuf *m); static void if_unroute(struct ifnet *, int flag, int fam); @@ -2141,26 +2140,6 @@ if_unroute(struct ifnet *ifp, int flag, int fam) rt_ifmsg(ifp, IFF_UP); } -/* - * Mark an interface up and notify protocols of - * the transition. - */ -static void -if_route(struct ifnet *ifp, int flag, int fam) -{ - - KASSERT(flag == IFF_UP, ("if_route: flag != IFF_UP")); - - ifp->if_flags |= flag; - getmicrotime(&ifp->if_lastchange); - if (ifp->if_carp) - (*carp_linkstate_p)(ifp); - rt_ifmsg(ifp, IFF_UP); -#ifdef INET6 - in6_if_up(ifp); -#endif -} - void (*vlan_link_state_p)(struct ifnet *); /* XXX: private from if_vlan */ void (*vlan_trunk_cap_p)(struct ifnet *); /* XXX: private from if_vlan */ struct ifnet *(*vlan_trunkdev_p)(struct ifnet *); @@ -2246,7 +2225,11 @@ void if_up(struct ifnet *ifp) { - if_route(ifp, IFF_UP, AF_UNSPEC); + ifp->if_flags |= IFF_UP; + getmicrotime(&ifp->if_lastchange); + if (ifp->if_carp) + (*carp_linkstate_p)(ifp); + rt_ifmsg(ifp, IFF_UP); EVENTHANDLER_INVOKE(ifnet_event, ifp, IFNET_EVENT_UP); } @@ -3109,13 +3092,8 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct thread *td) cmd != SIOCSIFDSTADDR && cmd != SIOCSIFNETMASK) error = (*ifp->if_ioctl)(ifp, cmd, data); - if ((oif_flags ^ ifp->if_flags) & IFF_UP) { -#ifdef INET6 - if (ifp->if_flags & IFF_UP) - in6_if_up(ifp); -#endif - } - + if (!(oif_flags & IFF_UP) && (ifp->if_flags & IFF_UP)) + if_up(ifp); out_ref: if_rele(ifp); out_noref: diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c index 3d967e9a40c7..0ef640c5c4bf 100644 --- a/sys/netinet6/in6.c +++ b/sys/netinet6/in6.c @@ -2049,6 +2049,20 @@ in6_if_up(struct ifnet *ifp) in6_ifattach(ifp, NULL); } +static void +in6_ifevent(void *arg __unused, struct ifnet *ifp, int event) +{ + if (event == IFNET_EVENT_UP) + in6_if_up(ifp); +} + +static void +in6_init(void *arg __unused) +{ + EVENTHANDLER_REGISTER(ifnet_event, in6_ifevent, NULL, EVENTHANDLER_PRI_ANY); +} +SYSINIT(in6_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, in6_init, NULL); + int in6if_do_dad(struct ifnet *ifp) { diff --git a/sys/netlink/route/iface.c b/sys/netlink/route/iface.c index 2f70325ce9ef..5e0295e7fe52 100644 --- a/sys/netlink/route/iface.c +++ b/sys/netlink/route/iface.c @@ -1312,10 +1312,8 @@ rtnl_handle_addr(struct nlmsghdr *hdr, struct nlpcb *nlp, struct nl_pstate *npt) error = EAFNOSUPPORT; } -#ifdef INET6 if (error == 0 && !(if_flags & IFF_UP) && (if_getflags(ifp) & IFF_UP)) - in6_if_up(ifp); -#endif + if_up(ifp); if_rele(ifp);