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
This commit is contained in:
parent
ffe99567dd
commit
1e79e01304
@ -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
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user