1995-01-31 06:29:58 +00:00
|
|
|
/*
|
|
|
|
* PPP Memory handling module
|
|
|
|
*
|
|
|
|
* Written by Toshiharu OHNO (tony-o@iij.ad.jp)
|
|
|
|
*
|
|
|
|
* Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms are permitted
|
|
|
|
* provided that the above copyright notice and this paragraph are
|
|
|
|
* duplicated in all such forms and that any documentation,
|
|
|
|
* advertising materials, and other materials related to such
|
|
|
|
* distribution and use acknowledge that the software was developed
|
|
|
|
* by the Internet Initiative Japan, Inc. The name of the
|
|
|
|
* IIJ may not be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
*
|
1999-08-28 01:35:59 +00:00
|
|
|
* $FreeBSD$
|
1995-05-30 03:57:47 +00:00
|
|
|
*
|
1995-01-31 06:29:58 +00:00
|
|
|
*/
|
1998-04-07 00:54:26 +00:00
|
|
|
#include <sys/types.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1998-02-16 00:01:12 +00:00
|
|
|
#include <sysexits.h>
|
1998-02-10 03:23:50 +00:00
|
|
|
#include <termios.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
|
1998-06-15 19:06:25 +00:00
|
|
|
#include "defs.h"
|
1997-11-22 03:37:54 +00:00
|
|
|
#include "command.h"
|
1997-10-26 01:04:02 +00:00
|
|
|
#include "mbuf.h"
|
|
|
|
#include "log.h"
|
1998-02-10 03:23:50 +00:00
|
|
|
#include "descriptor.h"
|
|
|
|
#include "prompt.h"
|
1998-02-16 00:01:12 +00:00
|
|
|
#include "main.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1999-12-20 20:29:51 +00:00
|
|
|
#define BUCKET_CHUNK 20
|
|
|
|
#define BUCKET_HASH 256
|
|
|
|
|
|
|
|
struct mbucket;
|
|
|
|
|
|
|
|
struct mfree {
|
|
|
|
struct mbucket *next;
|
|
|
|
size_t count;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct mbucket {
|
|
|
|
union {
|
|
|
|
struct mbuf m;
|
|
|
|
struct mfree f;
|
|
|
|
} u;
|
|
|
|
} *bucket[(M_MAXLEN + sizeof(struct mbuf)) / BUCKET_HASH];
|
|
|
|
|
|
|
|
#define M_BINDEX(sz) (((sz) + sizeof(struct mbuf) - 1) / BUCKET_HASH)
|
|
|
|
#define M_BUCKET(sz) (bucket + M_BINDEX(sz))
|
|
|
|
#define M_ROUNDUP(sz) ((M_BINDEX(sz) + 1) * BUCKET_HASH)
|
|
|
|
|
1998-01-21 02:15:33 +00:00
|
|
|
static struct memmap {
|
1995-01-31 06:29:58 +00:00
|
|
|
struct mbuf *queue;
|
1999-12-20 20:29:47 +00:00
|
|
|
size_t fragments;
|
|
|
|
size_t octets;
|
1999-06-02 15:59:09 +00:00
|
|
|
} MemMap[MB_MAX + 1];
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1999-05-08 11:07:56 +00:00
|
|
|
static unsigned long long mbuf_Mallocs, mbuf_Frees;
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
int
|
1999-12-20 20:29:47 +00:00
|
|
|
m_length(struct mbuf *bp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
int len;
|
|
|
|
|
1999-12-20 20:29:47 +00:00
|
|
|
for (len = 0; bp; bp = bp->m_next)
|
|
|
|
len += bp->m_len;
|
1999-05-09 20:02:29 +00:00
|
|
|
return len;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct mbuf *
|
1999-12-20 20:29:47 +00:00
|
|
|
m_get(size_t m_len, int type)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1999-12-20 20:29:51 +00:00
|
|
|
struct mbucket **mb;
|
1995-01-31 06:29:58 +00:00
|
|
|
struct mbuf *bp;
|
1999-12-20 20:29:51 +00:00
|
|
|
size_t size;
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1999-06-02 15:59:09 +00:00
|
|
|
if (type > MB_MAX) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogERROR, "Bad mbuf type %d\n", type);
|
1999-06-02 15:59:09 +00:00
|
|
|
type = MB_UNKNOWN;
|
|
|
|
}
|
1999-12-20 20:29:51 +00:00
|
|
|
|
|
|
|
if (m_len > M_MAXLEN || m_len == 0) {
|
|
|
|
log_Printf(LogERROR, "Request for mbuf size %lu denied\n", (u_long)m_len);
|
1998-02-16 00:01:12 +00:00
|
|
|
AbortProgram(EX_OSERR);
|
1997-05-10 01:22:19 +00:00
|
|
|
}
|
1999-12-20 20:29:51 +00:00
|
|
|
|
|
|
|
mb = M_BUCKET(m_len);
|
|
|
|
size = M_ROUNDUP(m_len);
|
|
|
|
|
|
|
|
if (*mb) {
|
|
|
|
/* We've got some free blocks of the right size */
|
|
|
|
bp = &(*mb)->u.m;
|
|
|
|
if (--(*mb)->u.f.count == 0)
|
|
|
|
*mb = (*mb)->u.f.next;
|
|
|
|
else {
|
|
|
|
((struct mbucket *)((char *)*mb + size))->u.f.count = (*mb)->u.f.count;
|
|
|
|
*mb = (struct mbucket *)((char *)*mb + size);
|
|
|
|
(*mb)->u.f.next = NULL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Allocate another chunk of mbufs, use the first and put the rest on
|
|
|
|
* the free list
|
|
|
|
*/
|
|
|
|
*mb = (struct mbucket *)malloc(BUCKET_CHUNK * size);
|
|
|
|
if (*mb == NULL) {
|
2000-03-14 01:47:19 +00:00
|
|
|
log_Printf(LogALERT, "Failed to allocate memory (%lu)\n",
|
|
|
|
(unsigned long)BUCKET_CHUNK * size);
|
1999-12-20 20:29:51 +00:00
|
|
|
AbortProgram(EX_OSERR);
|
|
|
|
}
|
|
|
|
bp = &(*mb)->u.m;
|
|
|
|
*mb = (struct mbucket *)((char *)*mb + size);
|
|
|
|
(*mb)->u.f.count = BUCKET_CHUNK - 1;
|
|
|
|
(*mb)->u.f.next = NULL;
|
|
|
|
}
|
|
|
|
|
1999-05-08 11:07:56 +00:00
|
|
|
mbuf_Mallocs++;
|
1999-12-20 20:29:51 +00:00
|
|
|
|
1997-10-26 01:04:02 +00:00
|
|
|
memset(bp, '\0', sizeof(struct mbuf));
|
1999-12-20 20:29:51 +00:00
|
|
|
bp->m_size = size - sizeof *bp;
|
|
|
|
bp->m_len = m_len;
|
1999-12-20 20:29:47 +00:00
|
|
|
bp->m_type = type;
|
1999-12-20 20:29:51 +00:00
|
|
|
|
|
|
|
MemMap[type].fragments++;
|
|
|
|
MemMap[type].octets += bp->m_size;
|
|
|
|
|
1999-03-29 08:21:28 +00:00
|
|
|
return bp;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct mbuf *
|
1999-12-20 20:29:47 +00:00
|
|
|
m_free(struct mbuf *bp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1999-12-20 20:29:51 +00:00
|
|
|
struct mbucket **mb, *f;
|
1995-01-31 06:29:58 +00:00
|
|
|
struct mbuf *nbp;
|
|
|
|
|
1999-12-20 20:29:51 +00:00
|
|
|
if ((f = (struct mbucket *)bp) != NULL) {
|
1999-12-20 20:29:47 +00:00
|
|
|
MemMap[bp->m_type].fragments--;
|
|
|
|
MemMap[bp->m_type].octets -= bp->m_size;
|
1999-12-20 20:29:51 +00:00
|
|
|
|
|
|
|
nbp = bp->m_next;
|
|
|
|
mb = M_BUCKET(bp->m_size);
|
|
|
|
f->u.f.next = *mb;
|
|
|
|
f->u.f.count = 1;
|
|
|
|
*mb = f;
|
|
|
|
|
1999-05-08 11:07:56 +00:00
|
|
|
mbuf_Frees++;
|
1999-03-29 08:21:28 +00:00
|
|
|
bp = nbp;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1999-03-29 08:21:28 +00:00
|
|
|
|
|
|
|
return bp;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-12-20 20:29:47 +00:00
|
|
|
m_freem(struct mbuf *bp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
while (bp)
|
1999-12-20 20:29:47 +00:00
|
|
|
bp = m_free(bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct mbuf *
|
1999-05-08 11:07:56 +00:00
|
|
|
mbuf_Read(struct mbuf *bp, void *v, size_t len)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
int nb;
|
1999-05-08 11:07:56 +00:00
|
|
|
u_char *ptr = v;
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
while (bp && len > 0) {
|
1999-12-20 20:29:47 +00:00
|
|
|
if (len > bp->m_len)
|
|
|
|
nb = bp->m_len;
|
1995-01-31 06:29:58 +00:00
|
|
|
else
|
|
|
|
nb = len;
|
1999-05-08 11:07:56 +00:00
|
|
|
if (nb) {
|
|
|
|
memcpy(ptr, MBUF_CTOP(bp), nb);
|
|
|
|
ptr += nb;
|
1999-12-20 20:29:47 +00:00
|
|
|
bp->m_len -= nb;
|
1999-05-08 11:07:56 +00:00
|
|
|
len -= nb;
|
1999-12-20 20:29:47 +00:00
|
|
|
bp->m_offset += nb;
|
1999-05-08 11:07:56 +00:00
|
|
|
}
|
1999-12-20 20:29:47 +00:00
|
|
|
if (bp->m_len == 0)
|
|
|
|
bp = m_free(bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1999-05-08 11:07:56 +00:00
|
|
|
|
1999-12-20 20:29:47 +00:00
|
|
|
while (bp && bp->m_len == 0)
|
|
|
|
bp = m_free(bp);
|
1999-05-08 11:07:56 +00:00
|
|
|
|
|
|
|
return bp;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
mbuf_View(struct mbuf *bp, void *v, size_t len)
|
|
|
|
{
|
|
|
|
size_t nb, l = len;
|
|
|
|
u_char *ptr = v;
|
|
|
|
|
|
|
|
while (bp && l > 0) {
|
1999-12-20 20:29:47 +00:00
|
|
|
if (l > bp->m_len)
|
|
|
|
nb = bp->m_len;
|
1999-05-08 11:07:56 +00:00
|
|
|
else
|
|
|
|
nb = l;
|
|
|
|
memcpy(ptr, MBUF_CTOP(bp), nb);
|
|
|
|
ptr += nb;
|
|
|
|
l -= nb;
|
1999-12-20 20:29:47 +00:00
|
|
|
bp = bp->m_next;
|
1999-05-08 11:07:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return len - l;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct mbuf *
|
1999-12-20 20:29:47 +00:00
|
|
|
m_prepend(struct mbuf *bp, const void *ptr, size_t len, size_t extra)
|
1999-05-08 11:07:56 +00:00
|
|
|
{
|
|
|
|
struct mbuf *head;
|
|
|
|
|
1999-12-20 20:29:47 +00:00
|
|
|
if (bp && bp->m_offset) {
|
|
|
|
if (bp->m_offset >= len) {
|
|
|
|
bp->m_offset -= len;
|
|
|
|
bp->m_len += len;
|
1999-05-08 11:07:56 +00:00
|
|
|
memcpy(MBUF_CTOP(bp), ptr, len);
|
|
|
|
return bp;
|
|
|
|
}
|
1999-12-20 20:29:47 +00:00
|
|
|
len -= bp->m_offset;
|
|
|
|
memcpy(bp + 1, (const char *)ptr + len, bp->m_offset);
|
|
|
|
bp->m_len += bp->m_offset;
|
|
|
|
bp->m_offset = 0;
|
1999-05-08 11:07:56 +00:00
|
|
|
}
|
|
|
|
|
1999-12-20 20:29:47 +00:00
|
|
|
head = m_get(len + extra, bp ? bp->m_type : MB_UNKNOWN);
|
|
|
|
head->m_offset = extra;
|
|
|
|
head->m_len -= extra;
|
2000-01-03 20:09:23 +00:00
|
|
|
if (ptr)
|
|
|
|
memcpy(MBUF_CTOP(head), ptr, len);
|
1999-12-20 20:29:47 +00:00
|
|
|
head->m_next = bp;
|
1999-05-08 11:07:56 +00:00
|
|
|
|
|
|
|
return head;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct mbuf *
|
1999-12-20 20:29:47 +00:00
|
|
|
m_adj(struct mbuf *bp, ssize_t n)
|
1999-05-08 11:07:56 +00:00
|
|
|
{
|
1999-12-20 20:29:47 +00:00
|
|
|
if (n > 0) {
|
|
|
|
while (bp) {
|
|
|
|
if (n < bp->m_len) {
|
|
|
|
bp->m_len = n;
|
|
|
|
bp->m_offset += n;
|
|
|
|
return bp;
|
|
|
|
}
|
|
|
|
n -= bp->m_len;
|
|
|
|
bp = m_free(bp);
|
1999-05-08 11:07:56 +00:00
|
|
|
}
|
1999-12-20 20:29:47 +00:00
|
|
|
} else {
|
|
|
|
if ((n = m_length(bp) + n) <= 0) {
|
|
|
|
m_freem(bp);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
for (; bp; bp = bp->m_next, n -= bp->m_len)
|
|
|
|
if (n < bp->m_len) {
|
|
|
|
bp->m_len = n;
|
|
|
|
m_freem(bp->m_next);
|
|
|
|
bp->m_next = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1999-05-08 11:07:56 +00:00
|
|
|
|
|
|
|
return bp;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
void
|
1999-12-20 20:29:47 +00:00
|
|
|
mbuf_Write(struct mbuf *bp, const void *ptr, size_t m_len)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
int plen;
|
|
|
|
int nb;
|
|
|
|
|
1999-12-20 20:29:47 +00:00
|
|
|
plen = m_length(bp);
|
|
|
|
if (plen < m_len)
|
|
|
|
m_len = plen;
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1999-12-20 20:29:47 +00:00
|
|
|
while (m_len > 0) {
|
|
|
|
nb = (m_len < bp->m_len) ? m_len : bp->m_len;
|
1997-10-26 01:04:02 +00:00
|
|
|
memcpy(MBUF_CTOP(bp), ptr, nb);
|
1999-12-20 20:29:47 +00:00
|
|
|
m_len -= bp->m_len;
|
|
|
|
bp = bp->m_next;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1998-05-01 19:26:12 +00:00
|
|
|
mbuf_Show(struct cmdargs const *arg)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
int i;
|
1999-12-27 11:54:57 +00:00
|
|
|
static const char * const mbuftype[] = {
|
1999-08-19 18:15:52 +00:00
|
|
|
"ip in", "ip out", "nat in", "nat out", "mp in", "mp out",
|
1999-06-02 15:59:09 +00:00
|
|
|
"vj in", "vj out", "icompd in", "icompd out", "compd in", "compd out",
|
|
|
|
"lqr in", "lqr out", "echo in", "echo out", "proto in", "proto out",
|
|
|
|
"acf in", "acf out", "sync in", "sync out", "hdlc in", "hdlc out",
|
|
|
|
"async in", "async out", "cbcp in", "cbcp out", "chap in", "chap out",
|
|
|
|
"pap in", "pap out", "ccp in", "ccp out", "ipcp in", "ipcp out",
|
|
|
|
"lcp in", "lcp out", "unknown"
|
|
|
|
};
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1998-08-21 18:09:57 +00:00
|
|
|
prompt_Printf(arg->prompt, "Fragments (octets) in use:\n");
|
1999-06-02 15:59:09 +00:00
|
|
|
for (i = 0; i < MB_MAX; i += 2)
|
1999-12-20 20:29:47 +00:00
|
|
|
prompt_Printf(arg->prompt, "%10.10s: %04lu (%06lu)\t"
|
|
|
|
"%10.10s: %04lu (%06lu)\n",
|
|
|
|
mbuftype[i], (u_long)MemMap[i].fragments,
|
|
|
|
(u_long)MemMap[i].octets, mbuftype[i+1],
|
|
|
|
(u_long)MemMap[i+1].fragments, (u_long)MemMap[i+1].octets);
|
1997-06-09 03:27:43 +00:00
|
|
|
|
1998-04-07 01:29:44 +00:00
|
|
|
if (i == MB_MAX)
|
1999-12-20 20:29:47 +00:00
|
|
|
prompt_Printf(arg->prompt, "%10.10s: %04lu (%06lu)\n",
|
|
|
|
mbuftype[i], (u_long)MemMap[i].fragments,
|
|
|
|
(u_long)MemMap[i].octets);
|
1997-06-09 03:27:43 +00:00
|
|
|
|
1999-08-09 22:56:18 +00:00
|
|
|
prompt_Printf(arg->prompt, "Mallocs: %llu, Frees: %llu\n",
|
1999-05-08 11:07:56 +00:00
|
|
|
mbuf_Mallocs, mbuf_Frees);
|
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
return 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1998-01-30 19:46:07 +00:00
|
|
|
struct mbuf *
|
1999-12-20 20:29:47 +00:00
|
|
|
m_dequeue(struct mqueue *q)
|
1998-01-30 19:46:07 +00:00
|
|
|
{
|
|
|
|
struct mbuf *bp;
|
|
|
|
|
1999-12-20 20:29:47 +00:00
|
|
|
log_Printf(LogDEBUG, "m_dequeue: queue len = %lu\n", (u_long)q->len);
|
1998-01-30 19:46:07 +00:00
|
|
|
bp = q->top;
|
|
|
|
if (bp) {
|
1999-12-20 20:29:47 +00:00
|
|
|
q->top = q->top->m_nextpkt;
|
|
|
|
q->len--;
|
1998-01-30 19:46:07 +00:00
|
|
|
if (q->top == NULL) {
|
|
|
|
q->last = q->top;
|
1999-12-20 20:29:47 +00:00
|
|
|
if (q->len)
|
|
|
|
log_Printf(LogERROR, "m_dequeue: Not zero (%lu)!!!\n",
|
|
|
|
(u_long)q->len);
|
1998-01-30 19:46:07 +00:00
|
|
|
}
|
1999-12-20 20:29:47 +00:00
|
|
|
bp->m_nextpkt = NULL;
|
1998-01-30 19:46:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return bp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-12-20 20:29:47 +00:00
|
|
|
m_enqueue(struct mqueue *queue, struct mbuf *bp)
|
1998-01-30 19:46:07 +00:00
|
|
|
{
|
1999-05-09 20:02:29 +00:00
|
|
|
if (bp != NULL) {
|
|
|
|
if (queue->last) {
|
1999-12-20 20:29:47 +00:00
|
|
|
queue->last->m_nextpkt = bp;
|
1999-05-09 20:02:29 +00:00
|
|
|
queue->last = bp;
|
|
|
|
} else
|
|
|
|
queue->last = queue->top = bp;
|
1999-12-20 20:29:47 +00:00
|
|
|
queue->len++;
|
2000-03-14 01:47:19 +00:00
|
|
|
log_Printf(LogDEBUG, "m_enqueue: len = %lu\n", (unsigned long)queue->len);
|
1999-05-09 20:02:29 +00:00
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1999-03-29 08:21:28 +00:00
|
|
|
|
|
|
|
struct mbuf *
|
1999-12-20 20:29:47 +00:00
|
|
|
m_pullup(struct mbuf *bp)
|
1999-03-29 08:21:28 +00:00
|
|
|
{
|
|
|
|
/* Put it all in one contigous (aligned) mbuf */
|
|
|
|
|
1999-05-09 20:02:29 +00:00
|
|
|
if (bp != NULL) {
|
1999-12-20 20:29:47 +00:00
|
|
|
if (bp->m_next != NULL) {
|
1999-05-09 20:02:29 +00:00
|
|
|
struct mbuf *nbp;
|
|
|
|
u_char *cp;
|
1999-03-29 08:21:28 +00:00
|
|
|
|
1999-12-20 20:29:47 +00:00
|
|
|
nbp = m_get(m_length(bp), bp->m_type);
|
1999-03-29 08:21:28 +00:00
|
|
|
|
1999-12-20 20:29:47 +00:00
|
|
|
for (cp = MBUF_CTOP(nbp); bp; bp = m_free(bp)) {
|
|
|
|
memcpy(cp, MBUF_CTOP(bp), bp->m_len);
|
|
|
|
cp += bp->m_len;
|
1999-05-09 20:02:29 +00:00
|
|
|
}
|
|
|
|
bp = nbp;
|
1999-03-29 08:21:28 +00:00
|
|
|
}
|
|
|
|
#ifndef __i386__ /* Do any other archs not care about alignment ? */
|
1999-12-20 20:29:47 +00:00
|
|
|
else if ((bp->m_offset & (sizeof(long) - 1)) != 0) {
|
|
|
|
bcopy(MBUF_CTOP(bp), bp + 1, bp->m_len);
|
|
|
|
bp->m_offset = 0;
|
1999-05-09 20:02:29 +00:00
|
|
|
}
|
1999-03-29 08:21:28 +00:00
|
|
|
#endif
|
1999-05-09 20:02:29 +00:00
|
|
|
}
|
1999-03-29 08:21:28 +00:00
|
|
|
|
|
|
|
return bp;
|
|
|
|
}
|
1999-06-02 15:59:09 +00:00
|
|
|
|
|
|
|
void
|
1999-12-20 20:29:47 +00:00
|
|
|
m_settype(struct mbuf *bp, int type)
|
1999-06-02 15:59:09 +00:00
|
|
|
{
|
1999-12-20 20:29:47 +00:00
|
|
|
for (; bp; bp = bp->m_next)
|
|
|
|
if (type != bp->m_type) {
|
|
|
|
MemMap[bp->m_type].fragments--;
|
|
|
|
MemMap[bp->m_type].octets -= bp->m_size;
|
|
|
|
bp->m_type = type;
|
1999-06-02 15:59:09 +00:00
|
|
|
MemMap[type].fragments++;
|
1999-12-20 20:29:47 +00:00
|
|
|
MemMap[type].octets += bp->m_size;
|
1999-06-02 15:59:09 +00:00
|
|
|
}
|
|
|
|
}
|
2000-01-03 20:09:23 +00:00
|
|
|
|
|
|
|
struct mbuf *
|
2000-05-07 10:08:24 +00:00
|
|
|
m_append(struct mbuf *bp, const void *v, size_t sz)
|
2000-01-03 20:09:23 +00:00
|
|
|
{
|
2000-05-07 10:08:24 +00:00
|
|
|
struct mbuf *m = bp;
|
|
|
|
|
2000-01-03 20:09:23 +00:00
|
|
|
if (m) {
|
|
|
|
while (m->m_next)
|
|
|
|
m = m->m_next;
|
|
|
|
if (m->m_size - m->m_len > sz)
|
|
|
|
m->m_len += sz;
|
|
|
|
else
|
|
|
|
m->m_next = m_prepend(NULL, v, sz, 0);
|
|
|
|
} else
|
2000-05-07 10:08:24 +00:00
|
|
|
bp = m_prepend(NULL, v, sz, 0);
|
2000-01-03 20:09:23 +00:00
|
|
|
|
2000-05-07 10:08:24 +00:00
|
|
|
return bp;
|
2000-01-03 20:09:23 +00:00
|
|
|
}
|