Partial update from FreeBSD.

This commit is contained in:
Ralf Corsepius
2005-05-09 12:47:45 +00:00
parent 00a578ad6b
commit 558e177e53

View File

@@ -10,10 +10,6 @@
* 2. Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors * 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software * may be used to endorse or promote products derived from this software
* without specific prior written permission. * without specific prior written permission.
@@ -165,27 +161,25 @@ m_getclr(nowait, type)
} }
struct mbuf * struct mbuf *
m_free(m) m_free(struct mbuf *m)
struct mbuf *m;
{ {
register struct mbuf *n; struct mbuf *n;
MFREE(m, n); MFREE(m, n);
return (n); return (n);
} }
void void
m_freem(m) m_freem(struct mbuf *mb)
register struct mbuf *m;
{ {
register struct mbuf *n; struct mbuf *n;
if (m == NULL) if (mb == NULL)
return; return;
do { do {
MFREE(m, n); MFREE(mb, n);
m = n; mb = n;
} while (m); } while (mb);
} }
/* /*
@@ -198,9 +192,7 @@ m_freem(m)
* copy junk along. * copy junk along.
*/ */
struct mbuf * struct mbuf *
m_prepend(m, len, how) m_prepend(struct mbuf *m, int len, int how)
register struct mbuf *m;
int len, how;
{ {
struct mbuf *mn; struct mbuf *mn;
@@ -229,13 +221,10 @@ m_prepend(m, len, how)
static int MCFail; static int MCFail;
struct mbuf * struct mbuf *
m_copym(m, off0, len, wait) m_copym(struct mbuf *m, int off0, int len, int wait)
register struct mbuf *m;
int off0, wait;
register int len;
{ {
register struct mbuf *n, **np; struct mbuf *n, **np;
register int off = off0; int off = off0;
struct mbuf *top; struct mbuf *top;
int copyhdr = 0; int copyhdr = 0;
@@ -244,7 +233,7 @@ m_copym(m, off0, len, wait)
if (off == 0 && m->m_flags & M_PKTHDR) if (off == 0 && m->m_flags & M_PKTHDR)
copyhdr = 1; copyhdr = 1;
while (off > 0) { while (off > 0) {
if (m == 0) if (m == NULL)
panic("m_copym"); panic("m_copym");
if (off < m->m_len) if (off < m->m_len)
break; break;
@@ -254,14 +243,14 @@ m_copym(m, off0, len, wait)
np = &top; np = &top;
top = 0; top = 0;
while (len > 0) { while (len > 0) {
if (m == 0) { if (m == NULL) {
if (len != M_COPYALL) if (len != M_COPYALL)
panic("m_copym"); panic("m_copym");
break; break;
} }
MGET(n, wait, m->m_type); MGET(n, wait, m->m_type);
*np = n; *np = n;
if (n == 0) if (n == NULL)
goto nospace; goto nospace;
if (copyhdr) { if (copyhdr) {
M_COPY_PKTHDR(n, m); M_COPY_PKTHDR(n, m);
@@ -290,13 +279,13 @@ m_copym(m, off0, len, wait)
m = m->m_next; m = m->m_next;
np = &n->m_next; np = &n->m_next;
} }
if (top == 0) if (top == NULL)
MCFail++; MCFail++;
return (top); return (top);
nospace: nospace:
m_freem(top); m_freem(top);
MCFail++; MCFail++;
return (0); return (NULL);
} }
/* /*
@@ -304,9 +293,7 @@ nospace:
* An optimization of the common case `m_copym(m, 0, M_COPYALL, how)'. * An optimization of the common case `m_copym(m, 0, M_COPYALL, how)'.
*/ */
struct mbuf * struct mbuf *
m_copypacket(m, how) m_copypacket(struct mbuf *m, int how)
struct mbuf *m;
int how;
{ {
struct mbuf *top, *n, *o; struct mbuf *top, *n, *o;
@@ -360,14 +347,9 @@ nospace:
* size is bigger than available * size is bigger than available
*/ */
int int
m_copydata(m, off, len, cp) m_copydata(const struct mbuf *m, int off, int len, caddr_t cp)
register struct mbuf *m;
register int off;
register int len;
caddr_t cp;
{ {
register unsigned count; u_int count;
/* struct mbuf *m0 = m; */
if (off < 0 || len < 0) if (off < 0 || len < 0)
panic("m_copydata"); panic("m_copydata");
@@ -413,8 +395,7 @@ m_copydata(m, off, len, cp)
* Any m_pkthdr is not updated. * Any m_pkthdr is not updated.
*/ */
void void
m_cat(m, n) m_cat(struct mbuf *m, struct mbuf *n)
register struct mbuf *m, *n;
{ {
while (m->m_next) while (m->m_next)
m = m->m_next; m = m->m_next;
@@ -434,13 +415,11 @@ m_cat(m, n)
} }
void void
m_adj(mp, req_len) m_adj(struct mbuf *mp, int req_len)
struct mbuf *mp;
int req_len;
{ {
register int len = req_len; int len = req_len;
register struct mbuf *m; struct mbuf *m;
register int count; int count;
if ((m = mp) == NULL) if ((m = mp) == NULL)
return; return;
@@ -518,12 +497,10 @@ m_adj(mp, req_len)
static int MPFail; static int MPFail;
struct mbuf * struct mbuf *
m_pullup(n, len) m_pullup(struct mbuf *n, int len)
register struct mbuf *n;
int len;
{ {
register struct mbuf *m; struct mbuf *m;
register int count; int count;
int space; int space;
/* /*
@@ -542,7 +519,7 @@ m_pullup(n, len)
if (len > MHLEN) if (len > MHLEN)
goto bad; goto bad;
MGET(m, M_DONTWAIT, n->m_type); MGET(m, M_DONTWAIT, n->m_type);
if (m == 0) if (m == NULL)
goto bad; goto bad;
m->m_len = 0; m->m_len = 0;
if (n->m_flags & M_PKTHDR) { if (n->m_flags & M_PKTHDR) {
@@ -570,10 +547,10 @@ m_pullup(n, len)
} }
m->m_next = n; m->m_next = n;
return (m); return (m);
bad: bad:
m_freem(n); m_freem(n);
MPFail++; MPFail++;
return (0); return (NULL);
} }
/* /*
@@ -582,22 +559,20 @@ bad:
* attempts to restore the chain to its original state. * attempts to restore the chain to its original state.
*/ */
struct mbuf * struct mbuf *
m_split(m0, len0, wait) m_split(struct mbuf *m0, int len0, int wait)
register struct mbuf *m0;
int len0, wait;
{ {
register struct mbuf *m, *n; struct mbuf *m, *n;
unsigned len = len0, remain; u_int len = len0, remain;
for (m = m0; m && len > m->m_len; m = m->m_next) for (m = m0; m && len > m->m_len; m = m->m_next)
len -= m->m_len; len -= m->m_len;
if (m == 0) if (m == NULL)
return (0); return (NULL);
remain = m->m_len - len; remain = m->m_len - len;
if (m0->m_flags & M_PKTHDR) { if (m0->m_flags & M_PKTHDR) {
MGETHDR(n, wait, m0->m_type); MGETHDR(n, wait, m0->m_type);
if (n == 0) if (n == NULL)
return (0); return (NULL);
n->m_pkthdr.rcvif = m0->m_pkthdr.rcvif; n->m_pkthdr.rcvif = m0->m_pkthdr.rcvif;
n->m_pkthdr.len = m0->m_pkthdr.len - len0; n->m_pkthdr.len = m0->m_pkthdr.len - len0;
m0->m_pkthdr.len = len0; m0->m_pkthdr.len = len0;
@@ -616,7 +591,7 @@ m_split(m0, len0, wait)
MH_ALIGN(n, remain); MH_ALIGN(n, remain);
} else if (remain == 0) { } else if (remain == 0) {
n = m->m_next; n = m->m_next;
m->m_next = 0; m->m_next = NULL;
return (n); return (n);
} else { } else {
MGET(n, wait, m->m_type); MGET(n, wait, m->m_type);
@@ -641,23 +616,21 @@ extpacket:
n->m_len = remain; n->m_len = remain;
m->m_len = len; m->m_len = len;
n->m_next = m->m_next; n->m_next = m->m_next;
m->m_next = 0; m->m_next = NULL;
return (n); return (n);
} }
/* /*
* Routine to copy from device local memory into mbufs. * Routine to copy from device local memory into mbufs.
*/ */
struct mbuf * struct mbuf *
m_devget(buf, totlen, off0, ifp, copy) m_devget(char *buf, int totlen, int off0, struct ifnet *ifp,
char *buf; void (*copy)(char *from, caddr_t to, u_int len))
int totlen, off0;
struct ifnet *ifp;
void (*copy) __P((char *from, caddr_t to, u_int len));
{ {
register struct mbuf *m; struct mbuf *m;
struct mbuf *top = 0, **mp = &top; struct mbuf *top = NULL, **mp = &top;
register int off = off0, len; int len;
register char *cp; int off = off0;
char *cp;
char *epkt; char *epkt;
cp = buf; cp = buf;
@@ -701,9 +674,9 @@ m_devget(buf, totlen, off0, ifp, copy)
len = m->m_len; len = m->m_len;
} }
if (copy) if (copy)
copy(cp, mtod(m, caddr_t), (unsigned)len); copy(cp, mtod(m, caddr_t), (u_int)len);
else else
bcopy(cp, mtod(m, caddr_t), (unsigned)len); bcopy(cp, mtod(m, caddr_t), (u_int)len);
cp += len; cp += len;
*mp = m; *mp = m;
mp = &m->m_next; mp = &m->m_next;
@@ -726,18 +699,18 @@ m_copyback(m0, off, len, cp)
register int len; register int len;
caddr_t cp; caddr_t cp;
{ {
register int mlen; int mlen;
register struct mbuf *m = m0, *n; struct mbuf *m = m0, *n;
int totlen = 0; int totlen = 0;
if (m0 == 0) if (m0 == NULL)
return 0; return 0;
while (off > (mlen = m->m_len)) { while (off > (mlen = m->m_len)) {
off -= mlen; off -= mlen;
totlen += mlen; totlen += mlen;
if (m->m_next == 0) { if (m->m_next == NULL) {
n = m_getclr(M_DONTWAIT, m->m_type); n = m_getclr(M_DONTWAIT, m->m_type);
if (n == 0) { if (n == NULL) {
/*panic("m_copyback() : malformed chain\n");*/ /*panic("m_copyback() : malformed chain\n");*/
return -1; return -1;
} }
@@ -748,7 +721,7 @@ m_copyback(m0, off, len, cp)
} }
while (len > 0) { while (len > 0) {
mlen = min (m->m_len - off, len); mlen = min (m->m_len - off, len);
bcopy(cp, off + mtod(m, caddr_t), (unsigned)mlen); bcopy(cp, off + mtod(m, caddr_t), (u_int)mlen);
cp += mlen; cp += mlen;
len -= mlen; len -= mlen;
mlen += off; mlen += off;
@@ -758,7 +731,7 @@ m_copyback(m0, off, len, cp)
/* m->m_len = mlen; */ /* m->m_len = mlen; */
break; break;
} }
if (m->m_next == 0) { if (m->m_next == NULL) {
n = m_get(M_DONTWAIT, m->m_type); n = m_get(M_DONTWAIT, m->m_type);
if (n == 0) { if (n == 0) {
/*panic("m_copyback() : malformed chain 2\n");*/ /*panic("m_copyback() : malformed chain 2\n");*/