diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2020-01-02 16:23:02 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2020-01-02 16:23:02 +0000 |
commit | e7eb307b556cdf00895356f6d84d1a25ff39fdb7 (patch) | |
tree | efe23501a08e579237a566def9f767abb129b866 | |
parent | 37c5ba331bb1ba8def6c6502f0670dfa2dbc3656 (diff) |
Switch bpf to use pgsigio(9) and sigio_init(9) instead of handrolling
something with csignal().
OK visa@
-rw-r--r-- | sys/net/bpf.c | 25 | ||||
-rw-r--r-- | sys/net/bpfdesc.h | 9 |
2 files changed, 18 insertions, 16 deletions
diff --git a/sys/net/bpf.c b/sys/net/bpf.c index 6c23b4581b7..01ddec71af8 100644 --- a/sys/net/bpf.c +++ b/sys/net/bpf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bpf.c,v 1.183 2019/12/31 13:48:32 visa Exp $ */ +/* $OpenBSD: bpf.c,v 1.184 2020/01/02 16:23:01 claudio Exp $ */ /* $NetBSD: bpf.c,v 1.33 1997/02/21 23:59:35 thorpej Exp $ */ /* @@ -58,6 +58,7 @@ #include <sys/smr.h> #include <sys/specdev.h> #include <sys/selinfo.h> +#include <sys/sigio.h> #include <sys/task.h> #include <net/if.h> @@ -376,6 +377,7 @@ bpfopen(dev_t dev, int flag, int mode, struct proc *p) mtx_init(&bd->bd_mtx, IPL_NET); task_set(&bd->bd_wake_task, bpf_wakeup_cb, bd); smr_init(&bd->bd_smr); + sigio_init(&bd->bd_sigio); if (flag & FNONBLOCK) bd->bd_rtout = -1; @@ -556,7 +558,7 @@ bpf_wakeup(struct bpf_d *d) MUTEX_ASSERT_LOCKED(&d->bd_mtx); /* - * As long as csignal() and selwakeup() need to be protected + * As long as pgsigio() and selwakeup() need to be protected * by the KERNEL_LOCK() we have to delay the wakeup to * another context to keep the hot path KERNEL_LOCK()-free. */ @@ -574,7 +576,7 @@ bpf_wakeup_cb(void *xd) wakeup(d); if (d->bd_async && d->bd_sig) - csignal(d->bd_pgid, d->bd_sig, d->bd_siguid, d->bd_sigeuid); + pgsigio(&d->bd_sigio, d->bd_sig, 0); selwakeup(&d->bd_sel); bpf_put(d); @@ -972,19 +974,19 @@ bpfioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p) /* * N.B. ioctl (FIOSETOWN) and fcntl (F_SETOWN) both end up doing * the equivalent of a TIOCSPGRP and hence end up here. *However* - * TIOCSPGRP's arg is a process group if it's positive and a process - * id if it's negative. This is exactly the opposite of what the - * other two functions want! Therefore there is code in ioctl and - * fcntl to negate the arg before calling here. + * TIOCSPGRP's arg is a process group. Therefore there is code in + * ioctl and fcntl to negate the arg before calling here. */ case TIOCSPGRP: /* Process or group to send signals to */ - d->bd_pgid = *(int *)addr; - d->bd_siguid = p->p_ucred->cr_ruid; - d->bd_sigeuid = p->p_ucred->cr_uid; + if (*(int *)addr < 0) { + error = EINVAL; + break; + } + error = sigio_setown(&d->bd_sigio, -*(int *)addr); break; case TIOCGPGRP: - *(int *)addr = d->bd_pgid; + *(int *)addr = -sigio_getown(&d->bd_sigio); break; case BIOCSRSIG: /* Set receive signal */ @@ -1587,6 +1589,7 @@ bpf_d_smr(void *smr) { struct bpf_d *bd = smr; + sigio_free(&bd->bd_sigio); free(bd->bd_sbuf, M_DEVBUF, bd->bd_bufsize); free(bd->bd_hbuf, M_DEVBUF, bd->bd_bufsize); free(bd->bd_fbuf, M_DEVBUF, bd->bd_bufsize); diff --git a/sys/net/bpfdesc.h b/sys/net/bpfdesc.h index ab0b743341d..41b65116b41 100644 --- a/sys/net/bpfdesc.h +++ b/sys/net/bpfdesc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bpfdesc.h,v 1.39 2019/10/21 23:02:05 sashan Exp $ */ +/* $OpenBSD: bpfdesc.h,v 1.40 2020/01/02 16:23:01 claudio Exp $ */ /* $NetBSD: bpfdesc.h,v 1.11 1995/09/27 18:30:42 thorpej Exp $ */ /* @@ -90,15 +90,14 @@ struct bpf_d { int bd_hdrcmplt; /* false to fill in src lladdr automatically */ int bd_async; /* non-zero if packet reception should generate signal */ int bd_sig; /* signal to send upon packet reception */ - pid_t bd_pgid; /* process or group id for signal */ - uid_t bd_siguid; /* uid for process that set pgid */ - uid_t bd_sigeuid; /* euid for process that set pgid */ + struct sigio_ref + bd_sigio; /* async I/O registration */ u_int bd_ref; /* reference count */ struct selinfo bd_sel; /* bsd select info */ int bd_unit; /* logical unit number */ LIST_ENTRY(bpf_d) bd_list; /* descriptor list */ - struct task bd_wake_task; /* delay csignal() and selwakeup() */ + struct task bd_wake_task; /* delay pgsigio() and selwakeup() */ struct smr_entry bd_smr; |