From nobody Fri Oct 13 18:13:57 2023 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 4S6ZQS5xQMz4wb5W; Fri, 13 Oct 2023 18:14:08 +0000 (UTC) (envelope-from zlei@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [IPv6:2610:1c1:1:606c::24b:4]) (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 "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4S6ZQS5Ppzz4Q7N; Fri, 13 Oct 2023 18:14:08 +0000 (UTC) (envelope-from zlei@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697220848; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jItv3mzLQNyeJtDZmmUQbVhZmTd1JFz/iSKvzxJNstk=; b=R+ZNxpLu0/O/8/oFmovBgPUEFxlRlkibwFAeupMPllvkH35WIetPWQtgEHadTOACWnBrBA qfbDu5YYJV5idhchcTKMixhljE39PcpUi68MNREk+HOUTIqlMekyA1hJcit0xc9biCHC0/ fAv3VKuw0zqww/hyQuBvLZqUqxKspUg/81DZsZwU/1ObGJp/GFRSDhgyIYFKITW6XLh+9A FZP4ITuRtR156PxHRQSMaJ9VYcMZfoP4GypOr/eTgHUoKI5D+2rIGNIz5He4xWeTTbML7t KoLtk1KYGu0dTjlciFzcUCd+i3ENsimEBCWa3h4aM/EnoWw2YAB1ENmlI4+s2g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1697220848; a=rsa-sha256; cv=none; b=ZJv07FYmOTmZuDI5CAJLdgyfQdFci5NeT/117TMXzwMufg2CB2RLhBUYE+wisykNkm2fq1 6fEnSP+qq7u63RNLpNiMHaYRnisDTfb+aVYpBHEbGGCzA2kbwtzUeirqW8dedBWTnAYMEU XDmQVw4YMDEg7oys+CT1GkBHoPwCeD1vWgvyrDYxToUz2+66NZcuyOCjwb0TLZlb4aBma1 kj5Ab00KFHh4M1FPuHT0b9eJCC75a9je5D9cEKrOxe7pOsFIZ5iNqFmQsiLR/1HTYFW7Gq qNfCKzCCcfc5M7eI7sFVQ4F/QUR1GuZA+UZP4gfqxzAhztQYRZu5MIy3HZjdZw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697220848; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jItv3mzLQNyeJtDZmmUQbVhZmTd1JFz/iSKvzxJNstk=; b=iTPTNjM0+w6nLMYzrfYZequ8mjpgVDOeWJrTZ9UvJgTGHy5/KqS4LYx/cJ9zkg/QwZzd0m 5IqWRVmyXu/ROsHM2irLvz/dZoGY67gRq9a/P880jSu/LLDc1P/jCVjdY0rF+hS1003pFu K3aLgTj48FcuAanbJKPJpDzjiYxzjjHeuKl1mieHq0OdBinfeP6eq8lvJfmr/2aa3UyaJ+ KWE/n64Rz3ME8Aqm/fhrHCnXnS9VlpELp9NjlmlOsY4MeDAM1nnEBApTnqqs4ea8cNYaid WqHQ6bsRhffvNNSAaN2Zon6CIMEpdVQSPt/OarKpD23N/OulD8yzTBfi4gvLrw== Received: from smtpclient.apple (unknown [IPv6:2001:19f0:6001:9db:98f0:9fe0:3545:10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) (Authenticated sender: zlei/mail) by smtp.freebsd.org (Postfix) with ESMTPSA id 4S6ZQR104pz1NM9; Fri, 13 Oct 2023 18:14:06 +0000 (UTC) (envelope-from zlei@FreeBSD.org) Content-Type: text/plain; charset=us-ascii 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: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.4\)) Subject: Re: git: c81dd8e5fe72 - main - bpf: Add IfAPI analogue for bpf_peers_present() From: Zhenlei Huang In-Reply-To: <202310131722.39DHM2b6077203@gitrepo.freebsd.org> Date: Sat, 14 Oct 2023 02:13:57 +0800 Cc: "src-committers@freebsd.org" , "dev-commits-src-all@freebsd.org" , "dev-commits-src-main@freebsd.org" Content-Transfer-Encoding: quoted-printable Message-Id: References: <202310131722.39DHM2b6077203@gitrepo.freebsd.org> To: Justin Hibbits X-Mailer: Apple Mail (2.3696.120.41.1.4) > On Oct 14, 2023, at 1:22 AM, Justin Hibbits = wrote: >=20 > The branch main has been updated by jhibbits: >=20 > URL: = https://cgit.FreeBSD.org/src/commit/?id=3Dc81dd8e5fe72d0c7ec055c8621bb2da3= a3627abf >=20 > commit c81dd8e5fe72d0c7ec055c8621bb2da3a3627abf > Author: Justin Hibbits > AuthorDate: 2023-10-04 20:56:52 +0000 > Commit: Justin Hibbits > CommitDate: 2023-10-13 17:12:44 +0000 >=20 > bpf: Add IfAPI analogue for bpf_peers_present() >=20 > An interface's bpf could feasibly not exist, in which case > bpf_peers_present() would panic from a NULL pointer dereference. = Solve > this by adding a new IfAPI that includes a NULL check. Since this = API The initial version DOES have NULL check. But that is redundant and = removed from the committed version. > is used in only a handful of locations, it reduces the the NULL = check > scope over inserting the check into bpf_peers_present(). >=20 > Sponsored by: Juniper Networks, Inc. > MFC after: 1 week > --- > sys/dev/firewire/if_fwip.c | 4 ++-- > sys/dev/hyperv/netvsc/if_hn.c | 4 ++-- > sys/dev/my/if_my.c | 2 +- > sys/dev/usb/usb_pf.c | 4 +--- > sys/net/bpf.c | 14 ++++++++++++++ > sys/net/bpf.h | 1 + > 6 files changed, 21 insertions(+), 8 deletions(-) >=20 > diff --git a/sys/dev/firewire/if_fwip.c b/sys/dev/firewire/if_fwip.c > index 5237c555d999..b698db6c9620 100644 > --- a/sys/dev/firewire/if_fwip.c > +++ b/sys/dev/firewire/if_fwip.c > @@ -780,7 +780,7 @@ fwip_stream_input(struct fw_xferq *xferq) > * Record the sender ID for possible BPF usage. > */ > src =3D ntohl(p[1]) >> 16; > - if (bpf_peers_present(if_getbpf(ifp))) { > + if (bpf_peers_present_if(ifp)) { > mtag =3D m_tag_alloc(MTAG_FIREWIRE, > MTAG_FIREWIRE_SENDER_EUID, > 2*sizeof(uint32_t), M_NOWAIT); > @@ -880,7 +880,7 @@ fwip_unicast_input(struct fw_xfer *xfer) > goto done; > } >=20 > - if (bpf_peers_present(if_getbpf(ifp))) { > + if (bpf_peers_present_if(ifp)) { > /* > * Record the sender ID for possible BPF usage. > */ > diff --git a/sys/dev/hyperv/netvsc/if_hn.c = b/sys/dev/hyperv/netvsc/if_hn.c > index 7d8e1914163e..f6f885873a79 100644 > --- a/sys/dev/hyperv/netvsc/if_hn.c > +++ b/sys/dev/hyperv/netvsc/if_hn.c > @@ -3262,7 +3262,7 @@ hn_txpkt(if_t ifp, struct hn_tx_ring *txr, = struct hn_txdesc *txd) > int error, send_failed =3D 0, has_bpf; >=20 > again: > - has_bpf =3D bpf_peers_present(if_getbpf(ifp)); > + has_bpf =3D bpf_peers_present_if(ifp); > if (has_bpf) { > /* > * Make sure that this txd and any aggregated txds are = not > @@ -5972,7 +5972,7 @@ hn_transmit(if_t ifp, struct mbuf *m) > omcast =3D (m->m_flags & M_MCAST) !=3D 0; >=20 > if (sc->hn_xvf_flags & HN_XVFFLAG_ACCBPF) { > - if (bpf_peers_present(if_getbpf(ifp))) { > + if (bpf_peers_present_if(ifp)) { > m_bpf =3D m_copypacket(m, = M_NOWAIT); > if (m_bpf =3D=3D NULL) { > /* > diff --git a/sys/dev/my/if_my.c b/sys/dev/my/if_my.c > index 2bf4573d337b..631c38df9dca 100644 > --- a/sys/dev/my/if_my.c > +++ b/sys/dev/my/if_my.c > @@ -1152,7 +1152,7 @@ my_rxeof(struct my_softc * sc) > * broadcast packet, multicast packet, matches our = ethernet > * address or the interface is in promiscuous mode. > */ > - if (bpf_peers_present(if_getbpf(ifp))) { > + if (bpf_peers_present_if(ifp)) { > bpf_mtap_if(ifp, m); > if (if_getflags(ifp) & IFF_PROMISC && > (bcmp(eh->ether_dhost, = if_getlladdr(sc->my_ifp), > diff --git a/sys/dev/usb/usb_pf.c b/sys/dev/usb/usb_pf.c > index 43e819684857..4da59419a7c6 100644 > --- a/sys/dev/usb/usb_pf.c > +++ b/sys/dev/usb/usb_pf.c > @@ -408,9 +408,7 @@ usbpf_xfertap(struct usb_xfer *xfer, int type) > bus =3D xfer->xroot->bus; >=20 > /* sanity checks */ > - if (bus->ifp =3D=3D NULL || if_getbpf(bus->ifp) =3D=3D NULL) > - return; > - if (!bpf_peers_present(if_getbpf(bus->ifp))) > + if (bus->ifp =3D=3D NULL || !bpf_peers_present_if(bus->ifp)) > return; >=20 > totlen =3D usbpf_xfer_precompute_size(xfer, type); > diff --git a/sys/net/bpf.c b/sys/net/bpf.c > index 8ca6e941e646..96420b709911 100644 > --- a/sys/net/bpf.c > +++ b/sys/net/bpf.c > @@ -2879,6 +2879,14 @@ bpfdetach(struct ifnet *ifp) > BPF_UNLOCK(); > } >=20 > +bool > +bpf_peers_present_if(struct ifnet *ifp) > +{ > + struct bpf_if *bp =3D ifp->if_bpf; > + > + return (bpf_peers_present(bp) > 0); > +} > + > /* > * Get a list of available data link type of the interface. > */ > @@ -3162,6 +3170,12 @@ bpfdetach(struct ifnet *ifp) > { > } >=20 > +bool > +bpf_peers_present_if(struct ifnet *ifp) > +{ > + return (false); > +} > + > u_int > bpf_filter(const struct bpf_insn *pc, u_char *p, u_int wirelen, u_int = buflen) > { > diff --git a/sys/net/bpf.h b/sys/net/bpf.h > index 924dea5fc9f4..31968445aac1 100644 > --- a/sys/net/bpf.h > +++ b/sys/net/bpf.h > @@ -428,6 +428,7 @@ void bpf_mtap2_if(struct ifnet *, void *, = u_int, struct mbuf *); > void bpfattach(struct ifnet *, u_int, u_int); > void bpfattach2(struct ifnet *, u_int, u_int, struct bpf_if **); > void bpfdetach(struct ifnet *); > +bool bpf_peers_present_if(struct ifnet *); > #ifdef VIMAGE > int bpf_get_bp_params(struct bpf_if *, u_int *, u_int *); > #endif