From 658a7ab8f2d91da8b2da85980436fd500accaf92 Mon Sep 17 00:00:00 2001 From: markm Date: Wed, 16 Oct 2002 14:31:34 +0000 Subject: [PATCH] Module-ize the 'core' crypto stuff. This may still need to be compiled into the kernel by default (if required), but other modules can now depend() on this. Fix inter-module dependancy. Earlier version OK'ed by: sam --- sys/dev/hifn/hifn7751.c | 1 + sys/dev/ubsec/ubsec.c | 1 + sys/modules/Makefile | 7 ++++++- sys/modules/crypto/Makefile | 20 ++++++++++++++++++++ sys/opencrypto/crypto.c | 33 ++++++++++++++++++++++++++++++--- sys/opencrypto/cryptodev.c | 1 + 6 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 sys/modules/crypto/Makefile diff --git a/sys/dev/hifn/hifn7751.c b/sys/dev/hifn/hifn7751.c index c98b32607d29..1d00872e969d 100644 --- a/sys/dev/hifn/hifn7751.c +++ b/sys/dev/hifn/hifn7751.c @@ -108,6 +108,7 @@ static driver_t hifn_driver = { static devclass_t hifn_devclass; DRIVER_MODULE(hifn, pci, hifn_driver, hifn_devclass, 0, 0); +MODULE_DEPEND(hifn, crypto, 1, 1, 1); static void hifn_reset_board(struct hifn_softc *, int); static void hifn_reset_puc(struct hifn_softc *); diff --git a/sys/dev/ubsec/ubsec.c b/sys/dev/ubsec/ubsec.c index 90df6d37b3ed..507198903ce8 100644 --- a/sys/dev/ubsec/ubsec.c +++ b/sys/dev/ubsec/ubsec.c @@ -124,6 +124,7 @@ static driver_t ubsec_driver = { static devclass_t ubsec_devclass; DRIVER_MODULE(ubsec, pci, ubsec_driver, ubsec_devclass, 0, 0); +MODULE_DEPEND(ubsec, crypto, 1, 1, 1); static void ubsec_intr(void *); static int ubsec_newsession(void *, u_int32_t *, struct cryptoini *); diff --git a/sys/modules/Makefile b/sys/modules/Makefile index d3f6f6bf357b..a42eed3ec434 100644 --- a/sys/modules/Makefile +++ b/sys/modules/Makefile @@ -1,5 +1,9 @@ # $FreeBSD$ +.if exists(${.CURDIR}/../opencrypto) && !defined(NOCRYPT) +_crypto= crypto +_cryptodev= cryptodev +.endif .if exists(${.CURDIR}/../crypto) && !defined(NOCRYPT) _random= random .endif @@ -19,7 +23,8 @@ SUBDIR= 3dfx \ ccd \ cd9660 \ coda \ - cryptodev \ + ${_crypto} \ + ${_cryptodev} \ cue \ dc \ de \ diff --git a/sys/modules/crypto/Makefile b/sys/modules/crypto/Makefile new file mode 100644 index 000000000000..37541b06db10 --- /dev/null +++ b/sys/modules/crypto/Makefile @@ -0,0 +1,20 @@ +# $FreeBSD$ + +.PATH: ${.CURDIR}/../../opencrypto +.PATH: ${.CURDIR}/../../crypto +.PATH: ${.CURDIR}/../../crypto/blowfish +.PATH: ${.CURDIR}/../../crypto/des +.PATH: ${.CURDIR}/../../crypto/sha2 +.PATH: ${.CURDIR}/../../net + +KMOD = crypto +SRCS = crypto.c +SRCS += criov.c crmbuf.c cryptosoft.c xform.c +SRCS += cast.c deflate.c rmd160.c rijndael.c skipjack.c +SRCS += bf_enc.c bf_skey.c +SRCS += des_ecb.c des_enc.c des_setkey.c +SRCS += sha1.c sha2.c +SRCS += zlib.c +SRCS += opt_param.h + +.include diff --git a/sys/opencrypto/crypto.c b/sys/opencrypto/crypto.c index 9bd2e84c4827..a4e2f5e60d9a 100644 --- a/sys/opencrypto/crypto.c +++ b/sys/opencrypto/crypto.c @@ -123,7 +123,34 @@ crypto_init(void) TAILQ_INIT(&crp_ret_kq); mtx_init(&crypto_ret_q_mtx, "crypto return queues", NULL, MTX_DEF); } -SYSINIT(crypto_init, SI_SUB_DRIVERS, SI_ORDER_FIRST, crypto_init, NULL) + +/* + * Initialization code, both for static and dynamic loading. + */ +static int +crypto_modevent(module_t mod, int type, void *unused) +{ + switch (type) { + case MOD_LOAD: + crypto_init(); + if (bootverbose) + printf("crypto: \n"); + return 0; + case MOD_UNLOAD: + /*XXX disallow if active sessions */ + /*XXX kill kthreads */ + return 0; + } + return EINVAL; +} + +static moduledata_t crypto_mod = { + "crypto", + crypto_modevent, + 0 +}; +MODULE_VERSION(crypto, 1); +DECLARE_MODULE(crypto, crypto_mod, SI_SUB_PSEUDO, SI_ORDER_SECOND); /* * Create a new session. @@ -910,7 +937,7 @@ static struct kproc_desc crypto_kp = { crypto_proc, &cryptoproc }; -SYSINIT(crypto_proc, SI_SUB_KTHREAD_IDLE, SI_ORDER_ANY, +SYSINIT(crypto_proc, SI_SUB_KTHREAD_IDLE, SI_ORDER_THIRD, kproc_start, &crypto_kp) static struct proc *cryptoretproc; @@ -972,5 +999,5 @@ static struct kproc_desc crypto_ret_kp = { crypto_ret_proc, &cryptoretproc }; -SYSINIT(crypto_ret_proc, SI_SUB_KTHREAD_IDLE, SI_ORDER_ANY, +SYSINIT(crypto_ret_proc, SI_SUB_KTHREAD_IDLE, SI_ORDER_THIRD, kproc_start, &crypto_ret_kp) diff --git a/sys/opencrypto/cryptodev.c b/sys/opencrypto/cryptodev.c index 6612cef7136d..4967d1611fab 100644 --- a/sys/opencrypto/cryptodev.c +++ b/sys/opencrypto/cryptodev.c @@ -794,3 +794,4 @@ static moduledata_t cryptodev_mod = { }; MODULE_VERSION(cryptodev, 1); DECLARE_MODULE(cryptodev, cryptodev_mod, SI_SUB_PSEUDO, SI_ORDER_ANY); +MODULE_DEPEND(cryptodev, crypto, 1, 1, 1);