summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorguenther <guenther@openbsd.org>2015-07-18 15:00:01 +0000
committerguenther <guenther@openbsd.org>2015-07-18 15:00:01 +0000
commitb68e1112f3e95b25fea6aa101dadc8fd0d973f4f (patch)
treee80671107c5d25d2ae891e92e585fdf84879953a
parentCheck the return value of ASN1_STRING_set(), for it may fail to allocate (diff)
downloadwireguard-openbsd-b68e1112f3e95b25fea6aa101dadc8fd0d973f4f.tar.xz
wireguard-openbsd-b68e1112f3e95b25fea6aa101dadc8fd0d973f4f.zip
Change unp_scan() and its callbacks to pass the array of struct file **
and a count instead of calling the callback on each one, while also renders the 'dispose' argument superfluous. Move unp_*() prototypes from <sys/un.h> to <sys/unpcb.h> ok claudio@ mpi@
-rw-r--r--sys/kern/uipc_proto.c4
-rw-r--r--sys/kern/uipc_usrreq.c74
-rw-r--r--sys/miscfs/fifofs/fifo_vnops.c4
-rw-r--r--sys/sys/un.h24
-rw-r--r--sys/sys/unpcb.h22
5 files changed, 61 insertions, 67 deletions
diff --git a/sys/kern/uipc_proto.c b/sys/kern/uipc_proto.c
index 6e7529e8366..61a92a860fe 100644
--- a/sys/kern/uipc_proto.c
+++ b/sys/kern/uipc_proto.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_proto.c,v 1.7 2015/03/14 03:38:51 jsg Exp $ */
+/* $OpenBSD: uipc_proto.c,v 1.8 2015/07/18 15:00:01 guenther Exp $ */
/* $NetBSD: uipc_proto.c,v 1.8 1996/02/13 21:10:47 christos Exp $ */
/*-
@@ -37,7 +37,7 @@
#include <sys/protosw.h>
#include <sys/domain.h>
#include <sys/mbuf.h>
-#include <sys/un.h>
+#include <sys/unpcb.h>
#include <sys/socketvar.h>
#include <net/raw_cb.h>
diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c
index 17631ed75bd..6eed2562825 100644
--- a/sys/kern/uipc_usrreq.c
+++ b/sys/kern/uipc_usrreq.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_usrreq.c,v 1.81 2015/06/30 15:30:17 mpi Exp $ */
+/* $OpenBSD: uipc_usrreq.c,v 1.82 2015/07/18 15:00:01 guenther Exp $ */
/* $NetBSD: uipc_usrreq.c,v 1.18 1996/02/09 19:00:50 christos Exp $ */
/*
@@ -685,15 +685,7 @@ restart:
fdplock(p->p_fd);
if (error != 0) {
rp = ((struct file **)CMSG_DATA(cm));
- for (i = 0; i < nfds; i++) {
- fp = *rp;
- /*
- * zero the pointer before calling unp_discard,
- * since it may end up in unp_gc()..
- */
- *rp++ = NULL;
- unp_discard(fp);
- }
+ unp_discard(rp, nfds);
goto out;
}
@@ -909,7 +901,7 @@ unp_gc(void)
goto restart;
}
#endif
- unp_scan(so->so_rcv.sb_mb, unp_mark, 0);
+ unp_scan(so->so_rcv.sb_mb, unp_mark);
}
} while (unp_defer);
/*
@@ -979,16 +971,15 @@ unp_dispose(struct mbuf *m)
{
if (m)
- unp_scan(m, unp_discard, 1);
+ unp_scan(m, unp_discard);
}
void
-unp_scan(struct mbuf *m0, void (*op)(struct file *), int discard)
+unp_scan(struct mbuf *m0, void (*op)(struct file **, int))
{
struct mbuf *m;
- struct file **rp, *fp;
+ struct file **rp;
struct cmsghdr *cm;
- int i;
int qfds;
while (m0) {
@@ -1001,13 +992,9 @@ unp_scan(struct mbuf *m0, void (*op)(struct file *), int discard)
continue;
qfds = (cm->cmsg_len - CMSG_ALIGN(sizeof *cm))
/ sizeof(struct file *);
- rp = (struct file **)CMSG_DATA(cm);
- for (i = 0; i < qfds; i++) {
- fp = *rp;
- if (discard)
- *rp = 0;
- (*op)(fp);
- rp++;
+ if (qfds > 0) {
+ rp = (struct file **)CMSG_DATA(cm);
+ op(rp, qfds);
}
break; /* XXX, but saves time */
}
@@ -1017,30 +1004,39 @@ unp_scan(struct mbuf *m0, void (*op)(struct file *), int discard)
}
void
-unp_mark(struct file *fp)
+unp_mark(struct file **rp, int nfds)
{
- if (fp == NULL)
- return;
+ int i;
- if (fp->f_iflags & (FIF_MARK|FIF_DEFER))
- return;
+ for (i = 0; i < nfds; i++) {
+ if (rp[i] == NULL)
+ continue;
- if (fp->f_type == DTYPE_SOCKET) {
- unp_defer++;
- fp->f_iflags |= FIF_DEFER;
- } else {
- fp->f_iflags |= FIF_MARK;
+ if (rp[i]->f_iflags & (FIF_MARK|FIF_DEFER))
+ continue;
+
+ if (rp[i]->f_type == DTYPE_SOCKET) {
+ unp_defer++;
+ rp[i]->f_iflags |= FIF_DEFER;
+ } else {
+ rp[i]->f_iflags |= FIF_MARK;
+ }
}
}
void
-unp_discard(struct file *fp)
+unp_discard(struct file **rp, int nfds)
{
+ struct file *fp;
+ int i;
- if (fp == NULL)
- return;
- FREF(fp);
- fp->f_msgcount--;
- unp_rights--;
- (void) closef(fp, NULL);
+ for (i = 0; i < nfds; i++) {
+ if ((fp = rp[i]) == NULL)
+ continue;
+ rp[i] = NULL;
+ FREF(fp);
+ fp->f_msgcount--;
+ unp_rights--;
+ (void) closef(fp, NULL);
+ }
}
diff --git a/sys/miscfs/fifofs/fifo_vnops.c b/sys/miscfs/fifofs/fifo_vnops.c
index 4d6a0d7b9f3..70b1241409a 100644
--- a/sys/miscfs/fifofs/fifo_vnops.c
+++ b/sys/miscfs/fifofs/fifo_vnops.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fifo_vnops.c,v 1.47 2015/05/10 22:35:39 millert Exp $ */
+/* $OpenBSD: fifo_vnops.c,v 1.48 2015/07/18 15:00:01 guenther Exp $ */
/* $NetBSD: fifo_vnops.c,v 1.18 1996/03/16 23:52:42 christos Exp $ */
/*
@@ -48,7 +48,7 @@
#include <sys/errno.h>
#include <sys/malloc.h>
#include <sys/poll.h>
-#include <sys/un.h>
+#include <sys/unpcb.h>
#include <sys/unistd.h>
#include <miscfs/fifofs/fifo.h>
diff --git a/sys/sys/un.h b/sys/sys/un.h
index b2d30ad94c6..63619faa14b 100644
--- a/sys/sys/un.h
+++ b/sys/sys/un.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: un.h,v 1.13 2014/08/31 01:42:36 guenther Exp $ */
+/* $OpenBSD: un.h,v 1.14 2015/07/18 15:00:01 guenther Exp $ */
/* $NetBSD: un.h,v 1.11 1996/02/04 02:12:47 christos Exp $ */
/*
@@ -52,27 +52,7 @@ struct sockaddr_un {
char sun_path[104]; /* path name (gag) */
};
-#ifdef _KERNEL
-struct unpcb;
-struct socket;
-
-int unp_attach(struct socket *);
-int unp_bind(struct unpcb *, struct mbuf *, struct proc *);
-int unp_connect(struct socket *, struct mbuf *, struct proc *);
-int unp_connect2(struct socket *, struct socket *);
-void unp_detach(struct unpcb *);
-void unp_discard(struct file *);
-void unp_disconnect(struct unpcb *);
-void unp_drop(struct unpcb *, int);
-void unp_gc(void);
-void unp_mark(struct file *);
-void unp_scan(struct mbuf *, void (*)(struct file *), int);
-void unp_shutdown(struct unpcb *);
-int unp_externalize(struct mbuf *, socklen_t, int);
-int unp_internalize(struct mbuf *, struct proc *);
-void unp_dispose(struct mbuf *);
-#else /* !_KERNEL */
-
+#ifndef _KERNEL
#if __BSD_VISIBLE
/* actual length of an initialized sockaddr_un */
diff --git a/sys/sys/unpcb.h b/sys/sys/unpcb.h
index eb351bbff68..beeafc1e8b5 100644
--- a/sys/sys/unpcb.h
+++ b/sys/sys/unpcb.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: unpcb.h,v 1.9 2015/03/28 23:50:55 bluhm Exp $ */
+/* $OpenBSD: unpcb.h,v 1.10 2015/07/18 15:00:01 guenther Exp $ */
/* $NetBSD: unpcb.h,v 1.6 1994/06/29 06:46:08 cgd Exp $ */
/*
@@ -38,7 +38,7 @@
*
* A socket may be associated with an vnode in the
* file system. If so, the unp_vnode pointer holds
- * a reference count to this vnode, which should be irele'd
+ * a reference count to this vnode, which should be vrele'd
* when the socket goes away.
*
* A socket may be connected to another socket, in which
@@ -80,3 +80,21 @@ struct unpcb {
#define UNP_FEIDSBIND 2 /* unp_connid was set by a bind */
#define sotounpcb(so) ((struct unpcb *)((so)->so_pcb))
+
+#ifdef _KERNEL
+int unp_attach(struct socket *);
+int unp_bind(struct unpcb *, struct mbuf *, struct proc *);
+int unp_connect(struct socket *, struct mbuf *, struct proc *);
+int unp_connect2(struct socket *, struct socket *);
+void unp_detach(struct unpcb *);
+void unp_discard(struct file **, int);
+void unp_disconnect(struct unpcb *);
+void unp_drop(struct unpcb *, int);
+void unp_gc(void);
+void unp_mark(struct file **, int);
+void unp_scan(struct mbuf *, void (*)(struct file **, int));
+void unp_shutdown(struct unpcb *);
+int unp_externalize(struct mbuf *, socklen_t, int);
+int unp_internalize(struct mbuf *, struct proc *);
+void unp_dispose(struct mbuf *);
+#endif /* _KERNEL */