summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbms <bms@FreeBSD.org>2003-12-15 21:49:41 +0000
committerbms <bms@FreeBSD.org>2003-12-15 21:49:41 +0000
commit3eb53d90efa64e513846ead8455355cb3da6d7e4 (patch)
tree4a56d35c92a140a3a9a8c550bd3f95c338a48449
parenta1979e4f7e164437f89f892976c3a660e1ffcfc4 (diff)
downloadFreeBSD-src-3eb53d90efa64e513846ead8455355cb3da6d7e4.zip
FreeBSD-src-3eb53d90efa64e513846ead8455355cb3da6d7e4.tar.gz
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
-rw-r--r--sys/conf/files1
-rw-r--r--sys/kern/uipc_mbuf.c67
-rw-r--r--sys/modules/crypto/Makefile2
-rw-r--r--sys/netipsec/ipsec_mbuf.c2
-rw-r--r--sys/opencrypto/cryptodev.h3
-rw-r--r--sys/opencrypto/cryptosoft.c9
-rw-r--r--sys/sys/mbuf.h3
7 files changed, 72 insertions, 15 deletions
diff --git a/sys/conf/files b/sys/conf/files
index 831861e..4b96cc5 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 3dfee69..52b6bb1 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 37541b0..0d2168e 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 7d7496d..f44ff7a 100644
--- a/sys/netipsec/ipsec_mbuf.c
+++ b/sys/netipsec/ipsec_mbuf.c
@@ -42,8 +42,6 @@
#include <netipsec/ipsec.h>
-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 d281dd5..ec166e8 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 6fa156e..3225620 100644
--- a/sys/opencrypto/cryptosoft.c
+++ b/sys/opencrypto/cryptosoft.c
@@ -88,13 +88,6 @@ 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.
*/
static int
@@ -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 0b84e1f..18422f1 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);
OpenPOWER on IntegriCloud