summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels Provos <provos@cvs.openbsd.org>2000-06-14 16:51:56 +0000
committerNiels Provos <provos@cvs.openbsd.org>2000-06-14 16:51:56 +0000
commitcb991a905a45bb827b43f71bab3833e3b9648f85 (patch)
tree8adce6d58f1e36b9208a97a2f2df40ccd0f0c6e3
parent3bc35fe51227abbf3c8d9e587d1c899d0b0ab712 (diff)
put in own ctl level for swapencrypt.
-rw-r--r--sys/uvm/uvm_meter.c36
-rw-r--r--sys/uvm/uvm_swap_encrypt.c43
-rw-r--r--sys/uvm/uvm_swap_encrypt.h14
-rw-r--r--sys/vm/vm_param.h6
4 files changed, 73 insertions, 26 deletions
diff --git a/sys/uvm/uvm_meter.c b/sys/uvm/uvm_meter.c
index da160cf64e3..29e4739fca9 100644
--- a/sys/uvm/uvm_meter.c
+++ b/sys/uvm/uvm_meter.c
@@ -132,9 +132,20 @@ uvm_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
struct vmtotal vmtotals;
struct _ps_strings _ps = { PS_STRINGS };
- /* all sysctl names at this level are terminal */
- if (namelen != 1)
- return (ENOTDIR); /* overloaded */
+ switch (name[0]) {
+ case VM_SWAPENCRYPT:
+#ifdef UVM_SWAP_ENCRYPT
+ return (swap_encrypt_ctl(name + 1, namelen - 1, oldp, oldlenp,
+ newp, newlen, p));
+#else
+ return (EOPNOTSUPP);
+#endif
+ default:
+ /* all sysctl names at this level are terminal */
+ if (namelen != 1)
+ return (ENOTDIR); /* overloaded */
+ break;
+ }
switch (name[0]) {
case VM_LOADAVG:
@@ -153,25 +164,6 @@ uvm_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
case VM_PSSTRINGS:
return (sysctl_rdstruct(oldp, oldlenp, newp, &_ps,
sizeof(_ps)));
-#ifdef UVM_SWAP_ENCRYPT
- case VM_SWAPENCRYPT: {
- int doencrypt = uvm_doswapencrypt;
- int result;
-
- result = sysctl_int(oldp, oldlenp, newp, newlen, &doencrypt);
- if (result)
- return result;
-
- /* Swap Encryption has been turned on, we need to
- * initalize state for swap devices that have been
- * added
- */
- if (doencrypt)
- uvm_swap_initcrypt_all();
- uvm_doswapencrypt = doencrypt;
- return (0);
- }
-#endif
default:
return (EOPNOTSUPP);
}
diff --git a/sys/uvm/uvm_swap_encrypt.c b/sys/uvm/uvm_swap_encrypt.c
index 97fefd244f2..64f50ca6346 100644
--- a/sys/uvm/uvm_swap_encrypt.c
+++ b/sys/uvm/uvm_swap_encrypt.c
@@ -32,6 +32,7 @@
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
+#include <sys/sysctl.h>
#include <sys/time.h>
#include <dev/rndvar.h>
#include <crypto/rijndael.h>
@@ -50,6 +51,48 @@ u_int uvm_swpkeysdeleted = 0;
int swap_encrypt_initalized = 0;
+int
+swap_encrypt_ctl(name, namelen, oldp, oldlenp, newp, newlen, p)
+ int *name;
+ u_int namelen;
+ void *oldp;
+ size_t *oldlenp;
+ void *newp;
+ size_t newlen;
+ struct proc *p;
+{
+ /* all sysctl names at this level are terminal */
+ if (namelen != 1)
+ return (ENOTDIR); /* overloaded */
+
+ switch (name[0]) {
+ case SWPENC_ENABLE: {
+ int doencrypt = uvm_doswapencrypt;
+ int result;
+
+ result = sysctl_int(oldp, oldlenp, newp, newlen, &doencrypt);
+ if (result)
+ return result;
+
+ /* Swap Encryption has been turned on, we need to
+ * initalize state for swap devices that have been
+ * added
+ */
+ if (doencrypt)
+ uvm_swap_initcrypt_all();
+ uvm_doswapencrypt = doencrypt;
+ return (0);
+ }
+ case SWPENC_CREATED:
+ return (sysctl_rdint(oldp, oldlenp, newp, uvm_swpkeyscreated));
+ case SWPENC_DELETED:
+ return (sysctl_rdint(oldp, oldlenp, newp, uvm_swpkeysdeleted));
+ default:
+ return (EOPNOTSUPP);
+ }
+ /* NOTREACHED */
+}
+
void
swap_key_create(struct swap_key *key)
{
diff --git a/sys/uvm/uvm_swap_encrypt.h b/sys/uvm/uvm_swap_encrypt.h
index 842cfa5b381..dc12c71c4f4 100644
--- a/sys/uvm/uvm_swap_encrypt.h
+++ b/sys/uvm/uvm_swap_encrypt.h
@@ -31,6 +31,17 @@
#ifndef _UVM_SWAP_ENCRYPT_H
#define _UVM_SWAP_ENCRYPT_H
+#define SWPENC_ENABLE 0
+#define SWPENC_CREATED 1
+#define SWPENC_DELETED 2
+#define SWPENC_MAXID 3
+
+#define CTL_SWPENC_NAMES { \
+ { "enable", CTLTYPE_INT }, \
+ { "keyscreated", CTLTYPE_INT }, \
+ { "keysdeleted", CTLTYPE_INT }, \
+}
+
#define SWAP_KEY_EXPIRE (120 /*60 * 60*/) /* time after that keys expire */
#define SWAP_KEY_SIZE 4 /* 128-bit keys */
@@ -39,6 +50,9 @@ struct swap_key {
u_int16_t refcount; /* pages that still need it */
};
+int swap_encrypt_ctl __P((int *, u_int, void *, size_t *, void *, size_t,
+ struct proc *));
+
void swap_encrypt __P((struct swap_key *,caddr_t, caddr_t, u_int64_t, size_t));
void swap_decrypt __P((struct swap_key *,caddr_t, caddr_t, u_int64_t, size_t));
diff --git a/sys/vm/vm_param.h b/sys/vm/vm_param.h
index b987b40838e..60882c1ae67 100644
--- a/sys/vm/vm_param.h
+++ b/sys/vm/vm_param.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: vm_param.h,v 1.19 2000/03/15 14:17:48 art Exp $ */
+/* $OpenBSD: vm_param.h,v 1.20 2000/06/14 16:51:55 provos Exp $ */
/* $NetBSD: vm_param.h,v 1.12 1995/03/26 20:39:16 jtc Exp $ */
/*
@@ -150,12 +150,10 @@ extern int page_shift;
{ "loadavg", CTLTYPE_STRUCT }, \
{ "psstrings", CTLTYPE_STRUCT }, \
{ "uvmexp", CTLTYPE_STRUCT }, \
- { "swapencrypt", CTLTYPE_INT }, \
+ { "swapencrypt", CTLTYPE_NODE }, \
}
-
#endif
-
struct _ps_strings {
void *val;
};