summaryrefslogtreecommitdiff
path: root/sys/dev/rnd.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2011-07-06 14:49:31 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2011-07-06 14:49:31 +0000
commit553ecec87d3691559c4520022538b9fcb0380f49 (patch)
tree1cc0975be555b9ab9149bf315bad9b7407d93465 /sys/dev/rnd.c
parent0a080daeefebfbc57004984aae043425a1173074 (diff)
Add a new kqfilter for random which returns ARC4_MAIN_MAX_BYTES for read
and POOLBYTES for write. looks right to deraadt
Diffstat (limited to 'sys/dev/rnd.c')
-rw-r--r--sys/dev/rnd.c54
1 files changed, 50 insertions, 4 deletions
diff --git a/sys/dev/rnd.c b/sys/dev/rnd.c
index 0c6ff53540a..9beb232b963 100644
--- a/sys/dev/rnd.c
+++ b/sys/dev/rnd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rnd.c,v 1.139 2011/01/11 06:15:03 djm Exp $ */
+/* $OpenBSD: rnd.c,v 1.140 2011/07/06 14:49:30 nicm Exp $ */
/*
* Copyright (c) 2011 Theo de Raadt.
@@ -112,6 +112,7 @@
#include <sys/systm.h>
#include <sys/conf.h>
#include <sys/disk.h>
+#include <sys/event.h>
#include <sys/limits.h>
#include <sys/time.h>
#include <sys/ioctl.h>
@@ -224,9 +225,18 @@ u_int32_t entropy_pool[POOLWORDS];
u_int entropy_add_ptr;
u_char entropy_input_rotate;
-void dequeue_randomness(void *);
-void add_entropy_words(const u_int32_t *, u_int);
-void extract_entropy(u_int8_t *buf, int nbytes);
+void dequeue_randomness(void *);
+void add_entropy_words(const u_int32_t *, u_int);
+void extract_entropy(u_int8_t *, int);
+
+int filt_randomread(struct knote *, long);
+void filt_randomdetach(struct knote *);
+int filt_randomwrite(struct knote *, long);
+
+struct filterops randomread_filtops =
+ { 1, NULL, filt_randomdetach, filt_randomread };
+struct filterops randomwrite_filtops =
+ { 1, NULL, filt_randomdetach, filt_randomwrite };
static __inline struct rand_event *
rnd_get(void)
@@ -783,6 +793,42 @@ randomwrite(dev_t dev, struct uio *uio, int flags)
}
int
+randomkqfilter(dev_t dev, struct knote *kn)
+{
+ switch (kn->kn_filter) {
+ case EVFILT_READ:
+ kn->kn_fop = &randomread_filtops;
+ break;
+ case EVFILT_WRITE:
+ kn->kn_fop = &randomwrite_filtops;
+ break;
+ default:
+ return (EINVAL);
+ }
+
+ return (0);
+}
+
+void
+filt_randomdetach(struct knote *kn)
+{
+}
+
+int
+filt_randomread(struct knote *kn, long hint)
+{
+ kn->kn_data = ARC4_MAIN_MAX_BYTES;
+ return (1);
+}
+
+int
+filt_randomwrite(struct knote *kn, long hint)
+{
+ kn->kn_data = POOLBYTES;
+ return (1);
+}
+
+int
randomioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
{
switch (cmd) {