From nobody Wed Oct 13 07:54:50 2021 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 5242517FD368; Wed, 13 Oct 2021 07:54:51 +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 4HTlDq19wcz4S6Z; Wed, 13 Oct 2021 07:54:51 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 EE10223BF1; Wed, 13 Oct 2021 07:54:50 +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 19D7soiR049457; Wed, 13 Oct 2021 07:54:50 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 19D7so0V049456; Wed, 13 Oct 2021 07:54:50 GMT (envelope-from git) Date: Wed, 13 Oct 2021 07:54:50 GMT Message-Id: <202110130754.19D7so0V049456@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Hartmut Brandt Subject: git: ded77e0237a8 - main - Allow the BPF to be select for write. This is needed for boost:asio which otherwise fails to handle BPFs. Reviewed by: ae Differential Revision: https://reviews.freebsd.org/D31967 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 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: harti X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ded77e0237a8534230746031f373d8a8ae80cdaa Auto-Submitted: auto-generated X-Spam: Yes X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by harti: URL: https://cgit.FreeBSD.org/src/commit/?id=ded77e0237a8534230746031f373d8a8ae80cdaa commit ded77e0237a8534230746031f373d8a8ae80cdaa Author: Hartmut Brandt AuthorDate: 2021-10-10 15:03:51 +0000 Commit: Hartmut Brandt CommitDate: 2021-10-10 15:03:51 +0000 Allow the BPF to be select for write. This is needed for boost:asio which otherwise fails to handle BPFs. Reviewed by: ae Differential Revision: https://reviews.freebsd.org/D31967 --- lib/libc/sys/kqueue.2 | 9 +++++++-- sys/net/bpf.c | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/lib/libc/sys/kqueue.2 b/lib/libc/sys/kqueue.2 index f80c89f75d78..68929e973dc0 100644 --- a/lib/libc/sys/kqueue.2 +++ b/lib/libc/sys/kqueue.2 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd September 30, 2021 +.Dd October 12, 2021 .Dt KQUEUE 2 .Os .Sh NAME @@ -378,7 +378,7 @@ The filter will set .Dv EV_EOF when the reader disconnects, and for the fifo case, this will be cleared when a new reader connects. -Note that this filter is not supported for vnodes or BPF devices. +Note that this filter is not supported for vnodes. .Pp For sockets, the low water mark and socket error handling is identical to the @@ -389,6 +389,11 @@ For eventfds, .Va data will contain the maximum value that can be added to the counter without blocking. +.Pp +For BPF devices, the filter always indicates that it is possible to +write and +.Va data +will contain the MTU size of the underlying interface. .It Dv EVFILT_EMPTY Takes a descriptor as the identifier, and returns whenever there is no remaining data in the write buffer. diff --git a/sys/net/bpf.c b/sys/net/bpf.c index 77c85cc91aae..ce7aba5a9bcd 100644 --- a/sys/net/bpf.c +++ b/sys/net/bpf.c @@ -213,6 +213,7 @@ static int bpf_getdltlist(struct bpf_d *, struct bpf_dltlist *); static int bpf_setdlt(struct bpf_d *, u_int); static void filt_bpfdetach(struct knote *); static int filt_bpfread(struct knote *, long); +static int filt_bpfwrite(struct knote *, long); static void bpf_drvinit(void *); static int bpf_stats_sysctl(SYSCTL_HANDLER_ARGS); @@ -257,6 +258,12 @@ static struct filterops bpfread_filtops = { .f_event = filt_bpfread, }; +static struct filterops bpfwrite_filtops = { + .f_isfd = 1, + .f_detach = filt_bpfdetach, + .f_event = filt_bpfwrite, +}; + /* * LOCKING MODEL USED BY BPF * @@ -2158,16 +2165,27 @@ bpfkqfilter(struct cdev *dev, struct knote *kn) { struct bpf_d *d; - if (devfs_get_cdevpriv((void **)&d) != 0 || - kn->kn_filter != EVFILT_READ) + if (devfs_get_cdevpriv((void **)&d) != 0) return (1); + switch (kn->kn_filter) { + case EVFILT_READ: + kn->kn_fop = &bpfread_filtops; + break; + + case EVFILT_WRITE: + kn->kn_fop = &bpfwrite_filtops; + break; + + default: + return (1); + } + /* * Refresh PID associated with this descriptor. */ BPFD_LOCK(d); BPF_PID_REFRESH_CUR(d); - kn->kn_fop = &bpfread_filtops; kn->kn_hook = d; knlist_add(&d->bd_sel.si_note, kn, 1); BPFD_UNLOCK(d); @@ -2207,6 +2225,17 @@ filt_bpfread(struct knote *kn, long hint) return (ready); } +static int +filt_bpfwrite(struct knote *kn, long hint) +{ + struct bpf_d *d = (struct bpf_d *)kn->kn_hook; + BPFD_LOCK_ASSERT(d); + + kn->kn_data = d->bd_bif->bif_ifp->if_mtu; + + return (1); +} + #define BPF_TSTAMP_NONE 0 #define BPF_TSTAMP_FAST 1 #define BPF_TSTAMP_NORMAL 2