On Mon, Feb 14, 2022 at 08:34:42AM +0000, Visa Hankala wrote:
> This makes bpf(4) use knote_modify_fn() and knote_process_fn().
> 
> Since the code has only one event function, it makes sense to use it
> directly instead of going through struct filterops f_event pointer.
> 
> OK?

ok.

> 
> Index: net/bpf.c
> ===================================================================
> RCS file: src/sys/net/bpf.c,v
> retrieving revision 1.214
> diff -u -p -r1.214 bpf.c
> --- net/bpf.c 13 Feb 2022 23:11:10 -0000      1.214
> +++ net/bpf.c 14 Feb 2022 08:08:07 -0000
> @@ -1229,8 +1229,13 @@ filt_bpfrdetach(struct knote *kn)
>  }
>  
>  int
> -filt_bpfread_common(struct knote *kn, struct bpf_d *d)
> +filt_bpfread(struct knote *kn, long hint)
>  {
> +     struct bpf_d *d = kn->kn_hook;
> +
> +     if (hint == NOTE_SUBMIT) /* ignore activation from selwakeup */
> +             return (0);
> +
>       MUTEX_ASSERT_LOCKED(&d->bd_mtx);
>  
>       kn->kn_data = d->bd_hlen;
> @@ -1241,25 +1246,13 @@ filt_bpfread_common(struct knote *kn, st
>  }
>  
>  int
> -filt_bpfread(struct knote *kn, long hint)
> -{
> -     struct bpf_d *d = kn->kn_hook;
> -
> -     if (hint == NOTE_SUBMIT) /* ignore activation from selwakeup */
> -             return (0);
> -
> -     return (filt_bpfread_common(kn, d));
> -}
> -
> -int
>  filt_bpfreadmodify(struct kevent *kev, struct knote *kn)
>  {
>       struct bpf_d *d = kn->kn_hook;
>       int active;
>  
>       mtx_enter(&d->bd_mtx);
> -     knote_assign(kev, kn);
> -     active = filt_bpfread_common(kn, d);
> +     active = knote_modify_fn(kev, kn, filt_bpfread);
>       mtx_leave(&d->bd_mtx);
>  
>       return (active);
> @@ -1272,12 +1265,7 @@ filt_bpfreadprocess(struct knote *kn, st
>       int active;
>  
>       mtx_enter(&d->bd_mtx);
> -     if (kev != NULL && (kn->kn_flags & EV_ONESHOT))
> -             active = 1;
> -     else
> -             active = filt_bpfread_common(kn, d);
> -     if (active)
> -             knote_submit(kn, kev);
> +     active = knote_process_fn(kn, kev, filt_bpfread);
>       mtx_leave(&d->bd_mtx);
>  
>       return (active);
> 

Reply via email to