diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2011-07-06 14:49:31 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2011-07-06 14:49:31 +0000 |
commit | 553ecec87d3691559c4520022538b9fcb0380f49 (patch) | |
tree | 1cc0975be555b9ab9149bf315bad9b7407d93465 | |
parent | 0a080daeefebfbc57004984aae043425a1173074 (diff) |
Add a new kqfilter for random which returns ARC4_MAIN_MAX_BYTES for read
and POOLBYTES for write.
looks right to deraadt
-rw-r--r-- | sys/dev/rnd.c | 54 | ||||
-rw-r--r-- | sys/sys/conf.h | 4 |
2 files changed, 52 insertions, 6 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) { diff --git a/sys/sys/conf.h b/sys/sys/conf.h index e0e34f91342..388215ddc89 100644 --- a/sys/sys/conf.h +++ b/sys/sys/conf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: conf.h,v 1.114 2011/07/04 22:53:53 tedu Exp $ */ +/* $OpenBSD: conf.h,v 1.115 2011/07/06 14:49:30 nicm Exp $ */ /* $NetBSD: conf.h,v 1.33 1996/05/03 20:03:32 christos Exp $ */ /*- @@ -383,7 +383,7 @@ extern struct cdevsw cdevsw[]; dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \ 0, seltrue, (dev_type_mmap((*))) enodev, \ - 0, 0, seltrue_kqfilter } + 0, 0, dev_init(c,n,kqfilter) } /* open, close, ioctl, poll, nokqfilter */ #define cdev_usb_init(c,n) { \ |