mbuf.c revision e2f547a1107946f41f895b0717e8602435203fd8
/*
* Copyright (c) 1995 Danny Gasparovski
*
* Please read the file COPYRIGHT for the
* terms and conditions of the copyright.
*/
/*
* mbuf's in SLiRP are much simpler than the real mbufs in
* FreeBSD. They are fixed size, determined by the MTU,
* so that one whole packet can fit. Mbuf's cannot be
* chained together. If there's more data than the mbuf
* could hold, an external malloced buffer is pointed to
* by m_ext (and the data pointers) and M_EXT is set in
* the flags
*/
#include <slirp.h>
void
{
mbuf_alloced = 0;
}
void
{
/*
* Find a nice value for msize
* XXX if_maxlinkhdr already in mtu
*/
}
/*
* Get an mbuf from the free list, if there are none
* malloc one
*
* Because fragmentation can occur if we alloc new mbufs and
* free old mbufs, we mark all mbufs above mbuf_thresh as M_DOFREE,
* which tells m_free to actually free() it
*/
struct mbuf *
{
register struct mbuf *m;
int flags = 0;
DEBUG_CALL("m_get");
{
if (m == NULL)
goto end_error;
mbuf_alloced++;
if (mbuf_alloced > mbuf_thresh)
if (mbuf_alloced > mbuf_max)
}
else
{
m = m_freelist.m_next;
}
/* Insert it in the used list */
/* Initialise it */
m->m_len = 0;
m->m_nextpkt = 0;
m->m_prevpkt = 0;
DEBUG_ARG("m = %lx", (long )m);
return m;
}
void
{
DEBUG_CALL("m_free");
DEBUG_ARG("m = %lx", (long )m);
if(m)
{
/* Remove from m_usedlist */
if (m->m_flags & M_USEDLIST)
/* If it's M_EXT, free() it */
/*
* Either free() it or put it on the free list
*/
{
free(m);
mbuf_alloced--;
}
else if ((m->m_flags & M_FREELIST) == 0)
{
}
} /* if(m) */
}
/*
* Copy data from one mbuf to the end of
* the other.. if result is too big for one mbuf, malloc()
* an M_EXT data segment
*/
void
{
/*
* If there's no room, realloc
*/
if (M_FREEROOM(m) < n->m_len)
}
/* make m size bytes large */
void
{
int datasize;
/* some compiles throw up on gotos. This one we can fake. */
return;
{
#if 0
#endif
}
else
{
char *dat;
#if 0
#endif
}
}
void
{
if (m == NULL)
return;
if (len >= 0)
{
/* Trim from head */
}
else
{
/* Trim from tail */
}
}
/*
* Copy len bytes from m, starting off bytes into n
*/
int
{
if (len > M_FREEROOM(n))
return -1;
return 0;
}
/*
* Given a pointer into an mbuf, return the mbuf
* XXX This is a kludge, I should eliminate the need for it
* Fortunately, it's not used often
*/
struct mbuf *
{
struct mbuf *m;
DEBUG_CALL("dtom");
/* bug corrected for M_EXT buffers */
{
{
return m;
}
else
{
return m;
}
}
return (struct mbuf *)0;
}