From nobody Thu Aug 11 16:20:10 2022 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 4M3X8W04Snz4YqC7; Thu, 11 Aug 2022 16:20:11 +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 4M3X8V6hJ5z3l7B; Thu, 11 Aug 2022 16:20:10 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660234810; 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=DJWDBY9Jbf827xh7USSoNWWh7pZmAqndsnUXiRJYLSE=; b=c1fxc0tunVU2UEsefLi8S5UKq7tJNYsEv/u3iieF8DuAzMS50IFD1PL2KD3kiQcrQWd92r 25V/kXJnxBhFcDX0raPguOxLyus9AN/Ita7gn+FtxH+PYazBMeAfUtS4eEF91HHya61uov twtNGT1VpE+oAylGZ57B9j6Nj59WcirdfreMkYbmJcDBbAV9tGKBa36GWChL3ub4BmWHF1 Ud32IEpAcUF4Xm8PyoQZ27aDMF8/bHdZMnZQSmnFevxKxhBgATDrYrZYEIYoTyQgKeCy3u SBbsrO0mprV3wdiiCLOizglx20cbVIssF+LOEYlpf4Kax1G5p3CWwUeZ8BG5zw== 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 4M3X8V5m3KzxZM; Thu, 11 Aug 2022 16:20:10 +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 27BGKAiS045175; Thu, 11 Aug 2022 16:20:10 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 27BGKAJW045171; Thu, 11 Aug 2022 16:20:10 GMT (envelope-from git) Date: Thu, 11 Aug 2022 16:20:10 GMT Message-Id: <202208111620.27BGKAJW045171@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: b8103ca76de0 - main - netinet: get interface event notifications directly via EVENTHANDLER(9) 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: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b8103ca76de09414775aa2eaca7b0e1bca59136c Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660234810; 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=DJWDBY9Jbf827xh7USSoNWWh7pZmAqndsnUXiRJYLSE=; b=P4ZOZB0Ixn7fZ3RSK8+7Y+m5eaDdcgu3PtzI5TsNBPF6HpBQogv1ZXaLdM2XYkUTl+9Dq/ U4vUBttmfxwhcgFCYY5RiXUqDY25laL+P8LBKYZjei9sV8sXzMl+QaYKz9xemo5/UHr0s7 sJl8oK79uW8FfG3lphYZwlwabtDAknfXLtZuWyaXDoPBMvwgydwkOogQFvU2X3sH3RBzQS b+2OameWmohMigWjfj1RNRi062k26D0FrMTK4rXt4yLdAMYzcu1MbIZ9uOgqiZLmt6vGCW 8HEAKm4JkP+xGjv9jucvOcVaqB/G2iZ8pueqLXxGvnCxAfi/GDeIQNSPca94Lg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1660234810; a=rsa-sha256; cv=none; b=s8LjEPd0xMWgWPnAEyBrcECNvHff3pfBTJ8TijnMR435ANZRohJDEywY4MGz1thEAPagMi Jqs1LTu/IKOEg4Acmz2qpR0qMwWOMVUN5mhDlKjKY4+zSv+d6C8miay++HYT/kUidsIX4j g36mTX3V3uvQZG/MM5wYjisRM2CnUKaaacmg+HbDD3zXBf2YonQkkyHunxMdNKt5lw6sym QLh/vogT1FPrGJq8bP1HkLTIuqxfV6VJXVIl1gLlkR5pn8ToeBcowH+zikaRkgMjqJIgKb HaD16rxNuUS8xulc7KJeRuSECd6V8awaaQYBLcTk+BVMqw1VhcrE02Gv9rey3A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=b8103ca76de09414775aa2eaca7b0e1bca59136c commit b8103ca76de09414775aa2eaca7b0e1bca59136c Author: Gleb Smirnoff AuthorDate: 2022-08-11 16:19:36 +0000 Commit: Gleb Smirnoff CommitDate: 2022-08-11 16:19:36 +0000 netinet: get interface event notifications directly via EVENTHANDLER(9) The old mechanism of getting them via domains/protocols control input is a relict from the previous century, when nothing like EVENTHANDLER(9) existed yet. Retire PRC_IFDOWN/PRC_IFUP as netinet was the only one to use them. Reviewed by: melifaro Differential revision: https://reviews.freebsd.org/D36116 --- sys/net/if.c | 14 ------------- sys/netinet/in.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++- sys/netinet/in_var.h | 1 - sys/netinet/raw_ip.c | 53 ------------------------------------------------ sys/sys/protosw.h | 2 -- 5 files changed, 56 insertions(+), 71 deletions(-) diff --git a/sys/net/if.c b/sys/net/if.c index 24a97329d232..906f2256dd54 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -2132,18 +2132,11 @@ link_init_sdl(struct ifnet *ifp, struct sockaddr *paddr, u_char iftype) static void if_unroute(struct ifnet *ifp, int flag, int fam) { - struct ifaddr *ifa; - struct epoch_tracker et; KASSERT(flag == IFF_UP, ("if_unroute: flag != IFF_UP")); ifp->if_flags &= ~flag; getmicrotime(&ifp->if_lastchange); - NET_EPOCH_ENTER(et); - CK_STAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) - if (fam == PF_UNSPEC || (fam == ifa->ifa_addr->sa_family)) - pfctlinput(PRC_IFDOWN, ifa->ifa_addr); - NET_EPOCH_EXIT(et); ifp->if_qflush(ifp); if (ifp->if_carp) @@ -2158,18 +2151,11 @@ if_unroute(struct ifnet *ifp, int flag, int fam) static void if_route(struct ifnet *ifp, int flag, int fam) { - struct ifaddr *ifa; - struct epoch_tracker et; KASSERT(flag == IFF_UP, ("if_route: flag != IFF_UP")); ifp->if_flags |= flag; getmicrotime(&ifp->if_lastchange); - NET_EPOCH_ENTER(et); - CK_STAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) - if (fam == PF_UNSPEC || (fam == ifa->ifa_addr->sa_family)) - pfctlinput(PRC_IFUP, ifa->ifa_addr); - NET_EPOCH_EXIT(et); if (ifp->if_carp) (*carp_linkstate_p)(ifp); rt_ifmsg(ifp); diff --git a/sys/netinet/in.c b/sys/netinet/in.c index 1c44623bdec1..e394af68ac23 100644 --- a/sys/netinet/in.c +++ b/sys/netinet/in.c @@ -954,7 +954,7 @@ ia_getrtprefix(const struct in_ifaddr *ia, struct in_addr *prefix, struct in_add * Adds or delete interface "prefix" route corresponding to @ifa. * Returns 0 on success or errno. */ -int +static int in_handle_ifaddr_route(int cmd, struct in_ifaddr *ia) { struct ifaddr *ifa = &ia->ia_ifa; @@ -1303,6 +1303,61 @@ in_ifdetach(struct ifnet *ifp) inm_release_wait(NULL); } +static void +in_ifnet_event(void *arg __unused, struct ifnet *ifp, int event) +{ + struct epoch_tracker et; + struct ifaddr *ifa; + struct in_ifaddr *ia; + int error; + + NET_EPOCH_ENTER(et); + switch (event) { + case IFNET_EVENT_DOWN: + CK_STAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { + if (ifa->ifa_addr->sa_family != AF_INET) + continue; + ia = (struct in_ifaddr *)ifa; + if ((ia->ia_flags & IFA_ROUTE) == 0) + continue; + ifa_ref(ifa); + /* + * in_scrubprefix() kills the interface route. + */ + in_scrubprefix(ia, 0); + /* + * in_ifadown gets rid of all the rest of the + * routes. This is not quite the right thing + * to do, but at least if we are running a + * routing process they will come back. + */ + in_ifadown(ifa, 0); + ifa_free(ifa); + } + break; + + case IFNET_EVENT_UP: + CK_STAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { + if (ifa->ifa_addr->sa_family != AF_INET) + continue; + ia = (struct in_ifaddr *)ifa; + if (ia->ia_flags & IFA_ROUTE) + continue; + ifa_ref(ifa); + error = ifa_del_loopback_route(ifa, ifa->ifa_addr); + rt_addrmsg(RTM_ADD, ifa, ifa->ifa_ifp->if_fib); + error = in_handle_ifaddr_route(RTM_ADD, ia); + if (error == 0) + ia->ia_flags |= IFA_ROUTE; + error = ifa_add_loopback_route(ifa, ifa->ifa_addr); + ifa_free(ifa); + } + break; + } + NET_EPOCH_EXIT(et); +} +EVENTHANDLER_DEFINE(ifnet_event, in_ifnet_event, NULL, EVENTHANDLER_PRI_ANY); + /* * Delete all IPv4 multicast address records, and associated link-layer * multicast address records, associated with ifp. diff --git a/sys/netinet/in_var.h b/sys/netinet/in_var.h index a6902159e739..c3f936b444dc 100644 --- a/sys/netinet/in_var.h +++ b/sys/netinet/in_var.h @@ -449,7 +449,6 @@ int in_control(struct socket *, u_long, caddr_t, struct ifnet *, int in_addprefix(struct in_ifaddr *); int in_scrubprefix(struct in_ifaddr *, u_int); void in_ifscrub_all(void); -int in_handle_ifaddr_route(int, struct in_ifaddr *); void ip_input(struct mbuf *); void ip_direct_input(struct mbuf *); void in_ifadown(struct ifaddr *ifa, int); diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c index 1f631e108a49..0bd874c717e6 100644 --- a/sys/netinet/raw_ip.c +++ b/sys/netinet/raw_ip.c @@ -769,64 +769,11 @@ rip_ctloutput(struct socket *so, struct sockopt *sopt) return (error); } -/* - * This function exists solely to receive the PRC_IFDOWN messages which are - * sent by if_down(). It looks for an ifaddr whose ifa_addr is sa, and calls - * in_ifadown() to remove all routes corresponding to that address. It also - * receives the PRC_IFUP messages from if_up() and reinstalls the interface - * routes. - */ void rip_ctlinput(int cmd, struct sockaddr *sa, void *vip) { - struct in_ifaddr *ia; - int err; - - NET_EPOCH_ASSERT(); switch (cmd) { - case PRC_IFDOWN: - CK_STAILQ_FOREACH(ia, &V_in_ifaddrhead, ia_link) { - if (ia->ia_ifa.ifa_addr == sa - && (ia->ia_flags & IFA_ROUTE)) { - ifa_ref(&ia->ia_ifa); - /* - * in_scrubprefix() kills the interface route. - */ - in_scrubprefix(ia, 0); - /* - * in_ifadown gets rid of all the rest of the - * routes. This is not quite the right thing - * to do, but at least if we are running a - * routing process they will come back. - */ - in_ifadown(&ia->ia_ifa, 0); - ifa_free(&ia->ia_ifa); - break; - } - } - break; - - case PRC_IFUP: - CK_STAILQ_FOREACH(ia, &V_in_ifaddrhead, ia_link) { - if (ia->ia_ifa.ifa_addr == sa) - break; - } - if (ia == NULL || (ia->ia_flags & IFA_ROUTE)) - return; - ifa_ref(&ia->ia_ifa); - - err = ifa_del_loopback_route((struct ifaddr *)ia, sa); - - rt_addrmsg(RTM_ADD, &ia->ia_ifa, ia->ia_ifp->if_fib); - err = in_handle_ifaddr_route(RTM_ADD, ia); - if (err == 0) - ia->ia_flags |= IFA_ROUTE; - - err = ifa_add_loopback_route((struct ifaddr *)ia, sa); - - ifa_free(&ia->ia_ifa); - break; #if defined(IPSEC) || defined(IPSEC_SUPPORT) case PRC_MSGSIZE: if (IPSEC_ENABLED(ipv4)) diff --git a/sys/sys/protosw.h b/sys/sys/protosw.h index 26cd1bc3fc16..85761583c30a 100644 --- a/sys/sys/protosw.h +++ b/sys/sys/protosw.h @@ -282,9 +282,7 @@ int pru_sopoll_notsupp(struct socket *so, int events, struct ucred *cred, * where cmd is one of the commands below, sa is a pointer to a sockaddr, * and arg is a `void *' argument used within a protocol family. */ -#define PRC_IFDOWN 0 /* interface transition */ #define PRC_ROUTEDEAD 1 /* select new route if possible ??? */ -#define PRC_IFUP 2 /* interface has come back up */ /* was PRC_QUENCH2 3 DEC congestion bit says slow down */ /* was PRC_QUENCH 4 Deprecated by RFC 6633 */ #define PRC_MSGSIZE 5 /* message size forced drop */