mbuf.c revision 641bf847576fdcb22f110d9c8e4fbe99a5947f1b
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Copyright (c) 1995 Danny Gasparovski
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Please read the file COPYRIGHT for the
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * terms and conditions of the copyright.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * mbuf's in SLiRP are much simpler than the real mbufs in
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * FreeBSD. They are fixed size, determined by the MTU,
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * so that one whole packet can fit. Mbuf's cannot be
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * chained together. If there's more data than the mbuf
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * could hold, an external malloced buffer is pointed to
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * by m_ext (and the data pointers) and M_EXT is set in
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * the flags
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync uint8_t *zone = RTMemAlloc(msize * MBUF_ZONE_SIZE);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync for (i = 0; i < MBUF_ZONE_SIZE; ++i)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync m->m_hdr.mh_id = pData->mbuf_zone_count * MBUF_ZONE_SIZE + i;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync LIST_INSERT_HEAD(&pData->mbuf_zone_head, mzone, list);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync pData->mbuf_water_line_limit = pData->mbuf_zone_count * MBUF_ZONE_SIZE;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync for (i = 0; i < MBUF_ZONE_SIZE; ++i)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync m_freelist.m_next = m_freelist.m_prev = &m_freelist;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync m_usedlist.m_next = m_usedlist.m_prev = &m_usedlist;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Find a nice value for msize
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync + sizeof(struct m_hdr) + sizeof(void *) /*pointer to the backstore*/
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Get an mbuf from the free list, if there are none
struct mbuf *
register struct mbuf *m;
int flags = 0;
int rc = 0;
if (rc == 0)
goto recheck_zone;
return NULL;
if (m == NULL)
goto end_error;
mbuf_alloced++;
mbuf_alloced++;
m->m_len = 0;
m->m_nextpkt = 0;
m->m_prevpkt = 0;
int rc;
mbuf_alloced--;
RTMemFree(m);
mbuf_alloced--;
#include "mbuf.h"
int datasize;
void *pvNew;
if (pvNew)
char *dat;
if (!dat)
if (m == NULL)
if (len >= 0)
struct mbuf *
struct mbuf *m;
return (struct mbuf *)0;
#ifndef VBOX_WITH_SLIRP_BSD_MBUF
* Interface that DrvNAT.cpp uses for allocating a buffer.
return NULL;
return NULL;