Index: sys/net/bpf.c =================================================================== --- sys/net/bpf.c +++ sys/net/bpf.c @@ -213,6 +213,7 @@ 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 @@ .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,19 +2165,37 @@ { 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); - /* - * 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); + switch (kn->kn_filter) { + case EVFILT_READ: + /* + * 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); + break; + + case EVFILT_WRITE: + /* + * Refresh PID associated with this descriptor. + */ + BPFD_LOCK(d); + BPF_PID_REFRESH_CUR(d); + kn->kn_fop = &bpfwrite_filtops; + kn->kn_hook = d; + knlist_add(&d->bd_sel.si_note, kn, 1); + BPFD_UNLOCK(d); + break; + + default: + return (1); + } return (0); } @@ -2207,6 +2232,17 @@ 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