summaryrefslogtreecommitdiffstats
path: root/usr.sbin/ppp/mbuf.c
diff options
context:
space:
mode:
authorbrian <brian@FreeBSD.org>1998-05-21 21:49:08 +0000
committerbrian <brian@FreeBSD.org>1998-05-21 21:49:08 +0000
commit56df88b778aee0e60678672b107a48a8ea05cb48 (patch)
tree13b88ca17b38e787c84b0cd242677b3c3c0b93c3 /usr.sbin/ppp/mbuf.c
parente077fa331b8a428923ded3a95d0b8d47084cf670 (diff)
downloadFreeBSD-src-56df88b778aee0e60678672b107a48a8ea05cb48.zip
FreeBSD-src-56df88b778aee0e60678672b107a48a8ea05cb48.tar.gz
MFMP: Make ppp multilink capable.
See the file README.changes, and re-read the man page.
Diffstat (limited to 'usr.sbin/ppp/mbuf.c')
-rw-r--r--usr.sbin/ppp/mbuf.c105
1 files changed, 71 insertions, 34 deletions
diff --git a/usr.sbin/ppp/mbuf.c b/usr.sbin/ppp/mbuf.c
index 0b1c2df..fc30aeb 100644
--- a/usr.sbin/ppp/mbuf.c
+++ b/usr.sbin/ppp/mbuf.c
@@ -17,33 +17,33 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: mbuf.c,v 1.12 1997/12/28 02:56:42 brian Exp $
+ * $Id: mbuf.c,v 1.13.2.11 1998/05/01 19:25:19 brian Exp $
*
*/
-#include <sys/param.h>
-#include <netinet/in.h>
+#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sysexits.h>
+#include <termios.h>
#include "command.h"
#include "mbuf.h"
#include "log.h"
-#include "defs.h"
-#include "loadalias.h"
-#include "vars.h"
-#include "server.h"
+#include "descriptor.h"
+#include "prompt.h"
+#include "main.h"
static struct memmap {
struct mbuf *queue;
int count;
-} MemMap[MB_MAX + 2];
+} MemMap[MB_MAX + 2];
static int totalalloced;
int
-plength(struct mbuf * bp)
+mbuf_Length(struct mbuf * bp)
{
int len;
@@ -53,25 +53,23 @@ plength(struct mbuf * bp)
}
struct mbuf *
-mballoc(int cnt, int type)
+mbuf_Alloc(int cnt, int type)
{
u_char *p;
struct mbuf *bp;
if (type > MB_MAX)
- LogPrintf(LogERROR, "Bad mbuf type %d\n", type);
+ log_Printf(LogERROR, "Bad mbuf type %d\n", type);
bp = (struct mbuf *) malloc(sizeof(struct mbuf));
if (bp == NULL) {
- LogPrintf(LogALERT, "failed to allocate memory: %u\n", sizeof(struct mbuf));
- ServerClose();
- exit(1);
+ log_Printf(LogALERT, "failed to allocate memory: %u\n", sizeof(struct mbuf));
+ AbortProgram(EX_OSERR);
}
memset(bp, '\0', sizeof(struct mbuf));
p = (u_char *) malloc(cnt);
if (p == NULL) {
- LogPrintf(LogALERT, "failed to allocate memory: %d\n", cnt);
- ServerClose();
- exit(1);
+ log_Printf(LogALERT, "failed to allocate memory: %d\n", cnt);
+ AbortProgram(EX_OSERR);
}
MemMap[type].count += cnt;
totalalloced += cnt;
@@ -83,7 +81,7 @@ mballoc(int cnt, int type)
}
struct mbuf *
-mbfree(struct mbuf * bp)
+mbuf_FreeSeg(struct mbuf * bp)
{
struct mbuf *nbp;
@@ -99,14 +97,14 @@ mbfree(struct mbuf * bp)
}
void
-pfree(struct mbuf * bp)
+mbuf_Free(struct mbuf * bp)
{
while (bp)
- bp = mbfree(bp);
+ bp = mbuf_FreeSeg(bp);
}
struct mbuf *
-mbread(struct mbuf * bp, u_char * ptr, int len)
+mbuf_Read(struct mbuf * bp, u_char * ptr, int len)
{
int nb;
@@ -124,7 +122,7 @@ mbread(struct mbuf * bp, u_char * ptr, int len)
#ifdef notdef
bp = bp->next;
#else
- bp = mbfree(bp);
+ bp = mbuf_FreeSeg(bp);
#endif
}
}
@@ -132,12 +130,12 @@ mbread(struct mbuf * bp, u_char * ptr, int len)
}
void
-mbwrite(struct mbuf * bp, u_char * ptr, int cnt)
+mbuf_Write(struct mbuf * bp, u_char * ptr, int cnt)
{
int plen;
int nb;
- plen = plength(bp);
+ plen = mbuf_Length(bp);
if (plen < cnt)
cnt = plen;
@@ -150,26 +148,65 @@ mbwrite(struct mbuf * bp, u_char * ptr, int cnt)
}
int
-ShowMemMap(struct cmdargs const *arg)
+mbuf_Show(struct cmdargs const *arg)
{
+ /* Watch it - ~m calls us with arg == NULL */
int i;
+ static const char *mbuftype[] = {
+ "async", "fsm", "hdlcout", "ipin", "echo", "lqr", "link", "vjcomp",
+ "ipq", "mp" };
- if (!VarTerm)
- return 1;
+ for (i = 1; i < MB_MAX; i += 2)
+ prompt_Printf(arg->prompt, "%10.10s: %04d\t%10.10s: %04d\n",
+ mbuftype[i-1], MemMap[i].count, mbuftype[i], MemMap[i+1].count);
- for (i = 0; i <= MB_MAX; i += 2)
- fprintf(VarTerm, "%d: %d %d: %d\n",
- i, MemMap[i].count, i + 1, MemMap[i + 1].count);
+ if (i == MB_MAX)
+ prompt_Printf(arg->prompt, "%10.10s: %04d\n",
+ mbuftype[i-1], MemMap[i].count);
return 0;
}
void
-LogMemory()
+mbuf_Log()
{
- LogPrintf(LogDEBUG, "LogMemory: mem alloced: %d\n", totalalloced);
- LogPrintf(LogDEBUG, "LogMemory: 1: %d 2: %d 3: %d 4: %d\n",
+ log_Printf(LogDEBUG, "mbuf_Log: mem alloced: %d\n", totalalloced);
+ log_Printf(LogDEBUG, "mbuf_Log: 1: %d 2: %d 3: %d 4: %d\n",
MemMap[1].count, MemMap[2].count, MemMap[3].count, MemMap[4].count);
- LogPrintf(LogDEBUG, "LogMemory: 5: %d 6: %d 7: %d 8: %d\n",
+ log_Printf(LogDEBUG, "mbuf_Log: 5: %d 6: %d 7: %d 8: %d\n",
MemMap[5].count, MemMap[6].count, MemMap[7].count, MemMap[8].count);
+ log_Printf(LogDEBUG, "mbuf_Log: 9: %d 10: %d\n",
+ MemMap[9].count, MemMap[10].count);
+}
+
+struct mbuf *
+mbuf_Dequeue(struct mqueue *q)
+{
+ struct mbuf *bp;
+
+ log_Printf(LogDEBUG, "mbuf_Dequeue: queue len = %d\n", q->qlen);
+ bp = q->top;
+ if (bp) {
+ q->top = q->top->pnext;
+ q->qlen--;
+ if (q->top == NULL) {
+ q->last = q->top;
+ if (q->qlen)
+ log_Printf(LogERROR, "mbuf_Dequeue: Not zero (%d)!!!\n", q->qlen);
+ }
+ }
+
+ return bp;
+}
+
+void
+mbuf_Enqueue(struct mqueue *queue, struct mbuf *bp)
+{
+ if (queue->last) {
+ queue->last->pnext = bp;
+ queue->last = bp;
+ } else
+ queue->last = queue->top = bp;
+ queue->qlen++;
+ log_Printf(LogDEBUG, "mbuf_Enqueue: len = %d\n", queue->qlen);
}
OpenPOWER on IntegriCloud