Deleted Added
full compact
mbuf.c (46686) mbuf.c (46828)
1/*
2 * PPP Memory handling module
3 *
4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
5 *
6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
7 *
8 * Redistribution and use in source and binary forms are permitted
9 * provided that the above copyright notice and this paragraph are
10 * duplicated in all such forms and that any documentation,
11 * advertising materials, and other materials related to such
12 * distribution and use acknowledge that the software was developed
13 * by the Internet Initiative Japan, Inc. The name of the
14 * IIJ may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 *
1/*
2 * PPP Memory handling module
3 *
4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
5 *
6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
7 *
8 * Redistribution and use in source and binary forms are permitted
9 * provided that the above copyright notice and this paragraph are
10 * duplicated in all such forms and that any documentation,
11 * advertising materials, and other materials related to such
12 * distribution and use acknowledge that the software was developed
13 * by the Internet Initiative Japan, Inc. The name of the
14 * IIJ may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 *
20 * $Id: mbuf.c,v 1.24 1999/03/29 08:21:28 brian Exp $
20 * $Id: mbuf.c,v 1.25 1999/05/08 11:07:07 brian Exp $
21 *
22 */
23#include <sys/types.h>
24
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28#include <sysexits.h>

--- 11 unchanged lines hidden (view full) ---

40 struct mbuf *queue;
41 int fragments, octets;
42} MemMap[MB_MAX + 2];
43
44static int totalalloced;
45static unsigned long long mbuf_Mallocs, mbuf_Frees;
46
47int
21 *
22 */
23#include <sys/types.h>
24
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28#include <sysexits.h>

--- 11 unchanged lines hidden (view full) ---

40 struct mbuf *queue;
41 int fragments, octets;
42} MemMap[MB_MAX + 2];
43
44static int totalalloced;
45static unsigned long long mbuf_Mallocs, mbuf_Frees;
46
47int
48mbuf_Length(struct mbuf * bp)
48mbuf_Length(struct mbuf *bp)
49{
50 int len;
51
52 for (len = 0; bp; bp = bp->next)
53 len += bp->cnt;
49{
50 int len;
51
52 for (len = 0; bp; bp = bp->next)
53 len += bp->cnt;
54 return (len);
54 return len;
55}
56
57struct mbuf *
58mbuf_Alloc(int cnt, int type)
59{
60 struct mbuf *bp;
61
62 if (type > MB_MAX)

--- 87 unchanged lines hidden (view full) ---

150 return len - l;
151}
152
153struct mbuf *
154mbuf_Prepend(struct mbuf *bp, const void *ptr, size_t len, size_t extra)
155{
156 struct mbuf *head;
157
55}
56
57struct mbuf *
58mbuf_Alloc(int cnt, int type)
59{
60 struct mbuf *bp;
61
62 if (type > MB_MAX)

--- 87 unchanged lines hidden (view full) ---

150 return len - l;
151}
152
153struct mbuf *
154mbuf_Prepend(struct mbuf *bp, const void *ptr, size_t len, size_t extra)
155{
156 struct mbuf *head;
157
158 if (bp->offset) {
158 if (bp && bp->offset) {
159 if (bp->offset >= len) {
160 bp->offset -= len;
161 bp->cnt += len;
162 memcpy(MBUF_CTOP(bp), ptr, len);
163 return bp;
164 }
165 len -= bp->offset;
166 memcpy(bp + sizeof *bp, (const char *)ptr + len, bp->offset);
167 bp->cnt += bp->offset;
168 bp->offset = 0;
169 }
170
159 if (bp->offset >= len) {
160 bp->offset -= len;
161 bp->cnt += len;
162 memcpy(MBUF_CTOP(bp), ptr, len);
163 return bp;
164 }
165 len -= bp->offset;
166 memcpy(bp + sizeof *bp, (const char *)ptr + len, bp->offset);
167 bp->cnt += bp->offset;
168 bp->offset = 0;
169 }
170
171 head = mbuf_Alloc(len + extra, bp->type);
171 head = mbuf_Alloc(len + extra, bp ? bp->type : MB_FSM);
172 head->offset = extra;
173 head->cnt -= extra;
174 memcpy(MBUF_CTOP(head), ptr, len);
175 head->next = bp;
176
177 return head;
178}
179

--- 89 unchanged lines hidden (view full) ---

269 }
270
271 return bp;
272}
273
274void
275mbuf_Enqueue(struct mqueue *queue, struct mbuf *bp)
276{
172 head->offset = extra;
173 head->cnt -= extra;
174 memcpy(MBUF_CTOP(head), ptr, len);
175 head->next = bp;
176
177 return head;
178}
179

--- 89 unchanged lines hidden (view full) ---

269 }
270
271 return bp;
272}
273
274void
275mbuf_Enqueue(struct mqueue *queue, struct mbuf *bp)
276{
277 if (queue->last) {
278 queue->last->pnext = bp;
279 queue->last = bp;
280 } else
281 queue->last = queue->top = bp;
282 queue->qlen++;
283 log_Printf(LogDEBUG, "mbuf_Enqueue: len = %d\n", queue->qlen);
277 if (bp != NULL) {
278 if (queue->last) {
279 queue->last->pnext = bp;
280 queue->last = bp;
281 } else
282 queue->last = queue->top = bp;
283 queue->qlen++;
284 log_Printf(LogDEBUG, "mbuf_Enqueue: len = %d\n", queue->qlen);
285 }
284}
285
286struct mbuf *
287mbuf_Contiguous(struct mbuf *bp)
288{
289 /* Put it all in one contigous (aligned) mbuf */
290
286}
287
288struct mbuf *
289mbuf_Contiguous(struct mbuf *bp)
290{
291 /* Put it all in one contigous (aligned) mbuf */
292
291 if (bp->next != NULL) {
292 struct mbuf *nbp;
293 u_char *cp;
293 if (bp != NULL) {
294 if (bp->next != NULL) {
295 struct mbuf *nbp;
296 u_char *cp;
294
297
295 nbp = mbuf_Alloc(mbuf_Length(bp), bp->type);
298 nbp = mbuf_Alloc(mbuf_Length(bp), bp->type);
296
299
297 for (cp = MBUF_CTOP(nbp); bp; bp = mbuf_FreeSeg(bp)) {
298 memcpy(cp, MBUF_CTOP(bp), bp->cnt);
299 cp += bp->cnt;
300 for (cp = MBUF_CTOP(nbp); bp; bp = mbuf_FreeSeg(bp)) {
301 memcpy(cp, MBUF_CTOP(bp), bp->cnt);
302 cp += bp->cnt;
303 }
304 bp = nbp;
300 }
305 }
301 bp = nbp;
302 }
303#ifndef __i386__ /* Do any other archs not care about alignment ? */
306#ifndef __i386__ /* Do any other archs not care about alignment ? */
304 else if ((bp->offset & 0x03) != 0) {
305 bcopy(MBUF_CTOP(bp), bp + 1, bp->cnt);
306 bp->offset = 0;
307 }
307 else if ((bp->offset & 0x03) != 0) {
308 bcopy(MBUF_CTOP(bp), bp + 1, bp->cnt);
309 bp->offset = 0;
310 }
308#endif
311#endif
312 }
309
310 return bp;
311}
313
314 return bp;
315}