From nobody Tue Sep 24 04:32:06 2024 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 4XCRlq11zNz5XGY5; Tue, 24 Sep 2024 04:32:07 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XCRlq0Twmz4RbQ; Tue, 24 Sep 2024 04:32:07 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1727152327; 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=QOa2M6qmSjEf1s8ZwC7zCk7nnCIEEaieM4BgC9/tZJg=; b=w013aVGXWQECcdFSzkwVhKvNpyleNuLWtvwBS+/ekdXyQpsB9HuMQA5U+mlWCAsphs6rAD mmxhfd+lwltV15AenYWRcf35Kw422MPuMmeUOusqGI1l9SK31O99IRnTZL7ae/3yfEBzn6 4AwfklpqU0OCjLyC3mhGD+rIxi2fX9Luprbu6JX108FrfJEJALwI/XwPaA7dlFwEYQiZ/f jSJ0dZpRgAYxq7YVUGoLHqhWl1Xnn4k9gTX69yZJ8HMDY9jlTIEXDfVAaMigVUhifHyfOc iSeZ5qLc0wkf5Hq06ISdYkaCCTc4PFCZo7ZhXjUCgjth+WkAffHFQFweiTcMkw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1727152327; a=rsa-sha256; cv=none; b=qFebwmkgZoj2sAwZ+dSRrOBegvPBYAQon4sxgiCz0eM4dO/EmIzm31+YutHodtHzpWhpCA StVIOnrT4KYfXglQUcUI6dM9jb8WSP0JMuQKTRt6x8AH/YGi6WEEfxkRWdai7XnJy8VzQd gw6MM+R5buZe/bmPP/nKtMRrdgMjG2YEiSHsYAkOM54bVSOlJnoNHXMr6kz+kJYp0Ll/yy +QZ+7B0px/R97ew/vxOpfkkWwkNOm4vgfcR7TzEIFfpfflG3e7LhMJs5tFqQayhfgTqw3x DGhBmh4+4+BwNqjSGgTg4y1SmoKqWVFqcKkwQ3tsb+FXuweJFJnAB2GXt7AbiA== 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=1727152327; 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=QOa2M6qmSjEf1s8ZwC7zCk7nnCIEEaieM4BgC9/tZJg=; b=IHX6I6EmOw4GPfXn7+38AGBfaykpvL6BgnX1PCB9WKkOrTz7rL2hVYiLyti6CqoIyudkOK UpnBxxzc+/NCL7MLqB/CVlnbOiQaZHOh9IT8l+xGI7RNrPy0d3IpXXnfXshjBTbVUl5xo+ XuZ5ffVq17aH7YMMJfNqL/exxoFzTiEIDf9ycRwTsL0Lx6O1LzQRrBvfknWeOnAWji4bI5 D9h5csaOoX6P+OSEaWxHvA78CxF4rmI68pDj6dp/rzCYTS4O9WHKZebtUXrnxB1pSPccVp BvlL3i7ZvvgepzJZj41mtHBFxRlIpjsAQGC3lGGeNW7IhwbuUT3whkU1BEcVqQ== 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 4XCRlq05L2zF5G; Tue, 24 Sep 2024 04:32:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 48O4W6wW091849; Tue, 24 Sep 2024 04:32:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 48O4W6wt091846; Tue, 24 Sep 2024 04:32:06 GMT (envelope-from git) Date: Tue, 24 Sep 2024 04:32:06 GMT Message-Id: <202409240432.48O4W6wt091846@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Zhenlei Huang Subject: git: 6c2430c72b4c - stable/14 - bpf: Add IfAPI analogue for bpf_peers_present() 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: zlei X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 6c2430c72b4c3516752b7541b100847522ab2225 Auto-Submitted: auto-generated The branch stable/14 has been updated by zlei: URL: https://cgit.FreeBSD.org/src/commit/?id=6c2430c72b4c3516752b7541b100847522ab2225 commit 6c2430c72b4c3516752b7541b100847522ab2225 Author: Justin Hibbits AuthorDate: 2023-10-04 20:56:52 +0000 Commit: Zhenlei Huang CommitDate: 2024-09-24 04:30:48 +0000 bpf: Add IfAPI analogue for bpf_peers_present() 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 could deal with a NULL bpf, if such could occur in the network stack. Reviewed by: zlei Sponsored by: Juniper Networks, Inc. MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D42082 (cherry picked from commit 8f31b879ecaf9e738dba631df4606742ee404e8e) bpf: Prefer the boolean form when calling bpf_peers_present() Reviewed by: markj, kp, #network MFC with: 8f31b879ecaf Differential Revision: https://reviews.freebsd.org/D45509 (cherry picked from commit 89204d9dcbe28558fae65936a0e93f44d926b88f) --- 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 | 12 ++++++++++++ sys/net/bpf.h | 1 + 6 files changed, 19 insertions(+), 8 deletions(-) diff --git a/sys/dev/firewire/if_fwip.c b/sys/dev/firewire/if_fwip.c index 91a27800f308..6350ec9cb56e 100644 --- a/sys/dev/firewire/if_fwip.c +++ b/sys/dev/firewire/if_fwip.c @@ -778,7 +778,7 @@ fwip_stream_input(struct fw_xferq *xferq) * Record the sender ID for possible BPF usage. */ src = ntohl(p[1]) >> 16; - if (bpf_peers_present(if_getbpf(ifp))) { + if (bpf_peers_present_if(ifp)) { mtag = m_tag_alloc(MTAG_FIREWIRE, MTAG_FIREWIRE_SENDER_EUID, 2*sizeof(uint32_t), M_NOWAIT); @@ -878,7 +878,7 @@ fwip_unicast_input(struct fw_xfer *xfer) goto done; } - 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 41be4226e592..9f51f5b32199 100644 --- a/sys/dev/hyperv/netvsc/if_hn.c +++ b/sys/dev/hyperv/netvsc/if_hn.c @@ -3263,7 +3263,7 @@ hn_txpkt(if_t ifp, struct hn_tx_ring *txr, struct hn_txdesc *txd) int error, send_failed = 0, has_bpf; again: - has_bpf = bpf_peers_present(if_getbpf(ifp)); + has_bpf = bpf_peers_present_if(ifp); if (has_bpf) { /* * Make sure that this txd and any aggregated txds are not @@ -5973,7 +5973,7 @@ hn_transmit(if_t ifp, struct mbuf *m) omcast = (m->m_flags & M_MCAST) != 0; if (sc->hn_xvf_flags & HN_XVFFLAG_ACCBPF) { - if (bpf_peers_present(if_getbpf(ifp))) { + if (bpf_peers_present_if(ifp)) { m_bpf = m_copypacket(m, M_NOWAIT); if (m_bpf == NULL) { /* diff --git a/sys/dev/my/if_my.c b/sys/dev/my/if_my.c index 3de394f424a2..6064c9de46c3 100644 --- a/sys/dev/my/if_my.c +++ b/sys/dev/my/if_my.c @@ -1146,7 +1146,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 3b03e80db489..0e7a75d04d6a 100644 --- a/sys/dev/usb/usb_pf.c +++ b/sys/dev/usb/usb_pf.c @@ -402,9 +402,7 @@ usbpf_xfertap(struct usb_xfer *xfer, int type) bus = xfer->xroot->bus; /* sanity checks */ - if (bus->ifp == NULL || if_getbpf(bus->ifp) == NULL) - return; - if (!bpf_peers_present(if_getbpf(bus->ifp))) + if (bus->ifp == NULL || !bpf_peers_present_if(bus->ifp)) return; totlen = usbpf_xfer_precompute_size(xfer, type); diff --git a/sys/net/bpf.c b/sys/net/bpf.c index 61eb674a7c0a..e65d890f891b 100644 --- a/sys/net/bpf.c +++ b/sys/net/bpf.c @@ -2879,6 +2879,12 @@ bpfdetach(struct ifnet *ifp) BPF_UNLOCK(); } +bool +bpf_peers_present_if(struct ifnet *ifp) +{ + return (bpf_peers_present(ifp->if_bpf)); +} + /* * Get a list of available data link type of the interface. */ @@ -3162,6 +3168,12 @@ bpfdetach(struct ifnet *ifp) { } +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 7b76129aec94..ed3239971db5 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