From 37621fd5d93015b59e08fc1278cbabfbf393fa7b Mon Sep 17 00:00:00 2001 From: Bruce M Simpson Date: Mon, 15 Dec 2003 21:49:41 +0000 Subject: [PATCH] Push m_apply() and m_getptr() up into the colleciton of standard mbuf routines, and purge them from opencrypto. Reviewed by: sam Obtained from: NetBSD Sponsored by: spc.org --- sys/conf/files | 1 - sys/kern/uipc_mbuf.c | 67 +++++++++++++++++++++++++++++++++++++ sys/modules/crypto/Makefile | 2 +- sys/netipsec/ipsec_mbuf.c | 2 -- sys/opencrypto/cryptodev.h | 3 -- sys/opencrypto/cryptosoft.c | 9 +---- sys/sys/mbuf.h | 3 ++ 7 files changed, 72 insertions(+), 15 deletions(-) diff --git a/sys/conf/files b/sys/conf/files index 831861e6e1a6..4b96cc5933b9 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -1569,7 +1569,6 @@ nfsserver/nfs_syscalls.c optional nfsserver # crypto support opencrypto/cast.c optional crypto opencrypto/criov.c optional crypto -opencrypto/crmbuf.c optional crypto opencrypto/crypto.c optional crypto opencrypto/cryptodev.c optional cryptodev opencrypto/cryptosoft.c optional crypto diff --git a/sys/kern/uipc_mbuf.c b/sys/kern/uipc_mbuf.c index 3dfee6954a67..52b6bb1f7b9e 100644 --- a/sys/kern/uipc_mbuf.c +++ b/sys/kern/uipc_mbuf.c @@ -755,6 +755,73 @@ out: if (((m = m0)->m_flags & M_PKTHDR) && (m->m_pkthdr.len < totlen)) m->m_pkthdr.len = totlen; } +/* + * Apply function f to the data in an mbuf chain starting "off" bytes from + * the beginning, continuing for "len" bytes. + */ +int +m_apply(struct mbuf *m, int off, int len, + int (*f)(void *, caddr_t, unsigned int), void *arg) +{ + unsigned int count; + int rval; + + KASSERT(off >= 0, ("m_apply, negative off %d", off)); + KASSERT(len >= 0, ("m_apply, negative len %d", len)); + + while (off > 0) { + KASSERT(m != NULL, ("m_apply, offset > size of mbuf chain")); + if (off < m->m_len) + break; + off -= m->m_len; + m = m->m_next; + } + while (len > 0) { + KASSERT(m != NULL, ("m_apply, offset > size of mbuf chain")); + count = min(m->m_len - off, len); + + rval = (*f)(arg, mtod(m, caddr_t) + off, count); + if (rval) + return (rval); + + len -= count; + off = 0; + m = m->m_next; + } + + return (0); +} + +/* + * Return a pointer to mbuf/offset of location in mbuf chain. + */ +struct mbuf * +m_getptr(struct mbuf *m, int loc, int *off) +{ + + while (loc >= 0) { + /* Normal end of search */ + if (m->m_len > loc) { + *off = loc; + return (m); + } else { + loc -= m->m_len; + + if (m->m_next == NULL) { + if (loc == 0) { + /* Point at the end of valid data */ + *off = m->m_len; + return (m); + } else + return (NULL); + } else + m = m->m_next; + } + } + + return (NULL); +} + void m_print(const struct mbuf *m) { diff --git a/sys/modules/crypto/Makefile b/sys/modules/crypto/Makefile index 37541b06db10..0d2168e91345 100644 --- a/sys/modules/crypto/Makefile +++ b/sys/modules/crypto/Makefile @@ -9,7 +9,7 @@ KMOD = crypto SRCS = crypto.c -SRCS += criov.c crmbuf.c cryptosoft.c xform.c +SRCS += criov.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 diff --git a/sys/netipsec/ipsec_mbuf.c b/sys/netipsec/ipsec_mbuf.c index 7d7496de3715..f44ff7aba54b 100644 --- a/sys/netipsec/ipsec_mbuf.c +++ b/sys/netipsec/ipsec_mbuf.c @@ -42,8 +42,6 @@ #include -extern struct mbuf *m_getptr(struct mbuf *, int, int *); - /* * Create a writable copy of the mbuf chain. While doing this * we compact the chain with a goal of producing a chain with diff --git a/sys/opencrypto/cryptodev.h b/sys/opencrypto/cryptodev.h index d281dd50330e..ec166e81ce90 100644 --- a/sys/opencrypto/cryptodev.h +++ b/sys/opencrypto/cryptodev.h @@ -379,9 +379,6 @@ extern int crypto_devallowsoft; /* only use hardware crypto */ * XXX these don't really belong here; but for now they're * kept apart from the rest of the system. */ -struct mbuf; -struct mbuf *m_getptr(struct mbuf *, int, int *); - struct uio; extern void cuio_copydata(struct uio* uio, int off, int len, caddr_t cp); extern void cuio_copyback(struct uio* uio, int off, int len, caddr_t cp); diff --git a/sys/opencrypto/cryptosoft.c b/sys/opencrypto/cryptosoft.c index 6fa156e66c66..32256206ac4b 100644 --- a/sys/opencrypto/cryptosoft.c +++ b/sys/opencrypto/cryptosoft.c @@ -87,13 +87,6 @@ static int swcr_process(void *, struct cryptop *, int); static int swcr_newsession(void *, u_int32_t *, struct cryptoini *); static int swcr_freesession(void *, u_int64_t); -/* - * NB: These came over from openbsd and are kept private - * to the crypto code for now. - */ -extern int m_apply(struct mbuf *m, int off, int len, - int (*f)(caddr_t, caddr_t, unsigned int), caddr_t fstate); - /* * Apply a symmetric encryption/decryption algorithm. */ @@ -460,7 +453,7 @@ swcr_authcompute(struct cryptop *crp, struct cryptodesc *crd, break; case CRYPTO_BUF_MBUF: err = m_apply((struct mbuf *) buf, crd->crd_skip, crd->crd_len, - (int (*)(caddr_t, caddr_t, unsigned int)) axf->Update, + (int (*)(void *, caddr_t, unsigned int)) axf->Update, (caddr_t) &ctx); if (err) return err; diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h index 0b84e1f804e3..18422f1674ba 100644 --- a/sys/sys/mbuf.h +++ b/sys/sys/mbuf.h @@ -435,6 +435,8 @@ extern int nsfbufs; /* Number of sendfile(2) bufs */ void _mext_free(struct mbuf *); void m_adj(struct mbuf *, int); +int m_apply(struct mbuf *, int, int, + int (*)(void *, caddr_t, unsigned int), void *); void m_cat(struct mbuf *, struct mbuf *); void m_chtype(struct mbuf *, short); void m_clget(struct mbuf *, int); @@ -460,6 +462,7 @@ struct mbuf *m_getcl(int, short, int); struct mbuf *m_gethdr(int, short); struct mbuf *m_gethdr_clrd(int, short); struct mbuf *m_getm(struct mbuf *, int, int, short); +struct mbuf *m_getptr(struct mbuf *, int, int *); u_int m_length(struct mbuf *, struct mbuf **); void m_move_pkthdr(struct mbuf *, struct mbuf *); struct mbuf *m_prepend(struct mbuf *, int, int);