Deal with the fact that as we now mbuf_Read the fsm

header in fsm_Input() we often end up with a NULL mbuf.

Deal with a possible NULL mbuf being passed into
mbuf_Prepend().

Adjust some spacing to make things more consistent.
This commit is contained in:
Brian Somers 1999-05-09 20:02:29 +00:00
parent 71a0942aca
commit 3377c28cd9
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=46828
15 changed files with 98 additions and 96 deletions

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: ccp.c,v 1.46 1999/05/02 14:33:39 brian Exp $
* $Id: ccp.c,v 1.47 1999/05/08 11:06:12 brian Exp $
*
* TODO:
* o Support other compression protocols
@ -363,9 +363,7 @@ CcpLayerFinish(struct fsm *fp)
log_Printf(LogCCP, "%s: LayerFinish.\n", fp->link->name);
}
/*
* Called when CCP has reached the OPEN state
*/
/* Called when CCP has reached the OPEN state */
static int
CcpLayerUp(struct fsm *fp)
{

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: fsm.c,v 1.41 1999/03/29 08:21:26 brian Exp $
* $Id: fsm.c,v 1.42 1999/05/08 11:06:35 brian Exp $
*
* TODO:
*/
@ -156,7 +156,7 @@ fsm_Init(struct fsm *fp, const char *name, u_short proto, int mincode,
}
static void
NewState(struct fsm * fp, int new)
NewState(struct fsm *fp, int new)
{
log_Printf(fp->LogLevel, "%s: State change %s --> %s\n",
fp->link->name, State2Nam(fp->state), State2Nam(new));
@ -237,7 +237,7 @@ FsmOpenNow(void *v)
}
void
fsm_Open(struct fsm * fp)
fsm_Open(struct fsm *fp)
{
switch (fp->state) {
case ST_INITIAL:
@ -275,7 +275,7 @@ fsm_Open(struct fsm * fp)
}
void
fsm_Up(struct fsm * fp)
fsm_Up(struct fsm *fp)
{
switch (fp->state) {
case ST_INITIAL:
@ -363,7 +363,7 @@ fsm_Close(struct fsm *fp)
* Send functions
*/
static void
FsmSendConfigReq(struct fsm * fp)
FsmSendConfigReq(struct fsm *fp)
{
if (fp->more.reqs-- > 0 && fp->restart-- > 0) {
(*fp->fn->SendConfigReq)(fp);
@ -442,7 +442,7 @@ FsmInitRestartCounter(struct fsm *fp, int what)
}
/*
* Actions when receive packets
* Actions when receive packets
*/
static void
FsmRecvConfigReq(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
@ -461,17 +461,13 @@ FsmRecvConfigReq(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
return;
}
/*
* Check and process easy case
*/
/* Check and process easy case */
switch (fp->state) {
case ST_INITIAL:
if (fp->proto == PROTO_CCP && fp->link->lcp.fsm.state == ST_OPENED) {
/*
* ccp_SetOpenMode() leaves us in initial if we're disabling
* & denying everything.
*
* this is a bit smelly... we know that bp has a leading fsmheader.
*/
bp = mbuf_Prepend(bp, lhp, sizeof *lhp, 2);
bp = proto_Prepend(bp, fp->proto, 0, 0);
@ -503,7 +499,6 @@ FsmRecvConfigReq(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
}
bp = mbuf_Contiguous(bp);
dec.ackend = dec.ack;
dec.nakend = dec.nak;
dec.rejend = dec.rej;
@ -662,6 +657,7 @@ FsmRecvConfigNak(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
return;
}
bp = mbuf_Contiguous(bp);
dec.ackend = dec.ack;
dec.nakend = dec.nak;
dec.rejend = dec.rej;
@ -727,7 +723,7 @@ FsmRecvTermReq(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
}
static void
FsmRecvTermAck(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
FsmRecvTermAck(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
/* RTA */
{
switch (fp->state) {
@ -789,6 +785,7 @@ FsmRecvConfigRej(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
return;
}
bp = mbuf_Contiguous(bp);
dec.ackend = dec.ack;
dec.nakend = dec.nak;
dec.rejend = dec.rej;
@ -826,11 +823,14 @@ static void
FsmRecvProtoRej(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
{
struct physical *p = link2physical(fp->link);
u_short *sp, proto;
u_short proto;
bp = mbuf_Contiguous(bp);
sp = (u_short *)MBUF_CTOP(bp);
proto = ntohs(*sp);
if (mbuf_Length(bp) < 2) {
mbuf_Free(bp);
return;
}
bp = mbuf_Read(bp, &proto, 2);
proto = ntohs(proto);
log_Printf(fp->LogLevel, "%s: -- Protocol 0x%04x (%s) was rejected!\n",
fp->link->name, proto, hdlc_Protocol2Nam(proto));
@ -881,7 +881,7 @@ FsmRecvEchoReq(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
u_char *cp;
u_int32_t magic;
if (lcp) {
if (lcp && mbuf_Length(bp) >= 4) {
cp = MBUF_CTOP(bp);
ua_ntohl(cp, &magic);
if (magic != lcp->his_magic) {
@ -903,37 +903,37 @@ FsmRecvEchoRep(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
struct lcp *lcp = fsm2lcp(fp);
u_int32_t magic;
if (lcp) {
ua_ntohl(MBUF_CTOP(bp), &magic);
if (lcp && mbuf_Length(bp) >= 4) {
mbuf_Read(bp, &magic, 4);
magic = ntohl(magic);
/* Tolerate echo replies with either magic number */
if (magic != 0 && magic != lcp->his_magic && magic != lcp->want_magic) {
log_Printf(LogWARN,
"%s: RecvEchoRep: Bad magic: expected 0x%08x, got: 0x%08x\n",
fp->link->name, lcp->his_magic, magic);
log_Printf(LogWARN, "%s: RecvEchoRep: Bad magic: expected 0x%08x,"
" got 0x%08x\n", fp->link->name, lcp->his_magic, magic);
/*
* XXX: We should send terminate request. But poor implementations may
* die as a result.
*/
}
lqr_RecvEcho(fp, bp);
bp = lqr_RecvEcho(fp, bp);
}
mbuf_Free(bp);
}
static void
FsmRecvDiscReq(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
FsmRecvDiscReq(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
{
mbuf_Free(bp);
}
static void
FsmRecvIdent(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
FsmRecvIdent(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
{
mbuf_Free(bp);
}
static void
FsmRecvTimeRemain(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
FsmRecvTimeRemain(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
{
mbuf_Free(bp);
}

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: ip.c,v 1.58 1999/05/01 11:31:29 brian Exp $
* $Id: ip.c,v 1.59 1999/05/08 11:06:42 brian Exp $
*
* TODO:
* o Return ICMP message for filterd packet
@ -232,7 +232,7 @@ FilterCheck(struct ip *pip, struct filter *filter)
#ifdef notdef
static void
IcmpError(struct ip * pip, int code)
IcmpError(struct ip *pip, int code)
{
struct mbuf *bp;

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: ipcp.c,v 1.75 1999/04/26 08:54:34 brian Exp $
* $Id: ipcp.c,v 1.76 1999/05/08 11:06:45 brian Exp $
*
* TODO:
* o Support IPADDRS properly
@ -795,7 +795,7 @@ AcceptableAddr(const struct in_range *prange, struct in_addr ipaddr)
}
static void
IpcpDecodeConfig(struct fsm *fp, u_char * cp, int plen, int mode_type,
IpcpDecodeConfig(struct fsm *fp, u_char *cp, int plen, int mode_type,
struct fsm_decode *dec)
{
/* Deal with incoming PROTO_IPCP */

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: lcp.c,v 1.72 1999/04/11 08:51:04 brian Exp $
* $Id: lcp.c,v 1.73 1999/05/08 11:06:51 brian Exp $
*
*/
@ -874,9 +874,7 @@ LcpDecodeConfig(struct fsm *fp, u_char *cp, int plen, int mode_type,
dec->ackend += 2;
} else {
#ifdef OLDMST
/*
* MorningStar before v1.3 needs NAK
*/
/* MorningStar before v1.3 needs NAK */
memcpy(dec->nakend, cp, 2);
dec->nakend += 2;
#else
@ -902,9 +900,7 @@ LcpDecodeConfig(struct fsm *fp, u_char *cp, int plen, int mode_type,
dec->ackend += 2;
} else {
#ifdef OLDMST
/*
* MorningStar before v1.3 needs NAK
*/
/* MorningStar before v1.3 needs NAK */
memcpy(dec->nakend, cp, 2);
dec->nakend += 2;
#else

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: log.c,v 1.35 1998/08/21 18:10:14 brian Exp $
* $Id: log.c,v 1.36 1999/03/07 11:54:41 brian Exp $
*/
#include <sys/types.h>
@ -364,7 +364,7 @@ log_DumpBp(int lev, const char *hdr, const struct mbuf *bp)
}
void
log_DumpBuff(int lev, const char *hdr, const u_char * ptr, int n)
log_DumpBuff(int lev, const char *hdr, const u_char *ptr, int n)
{
if (log_IsKept(lev)) {
char buf[50];

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: lqr.c,v 1.32 1999/03/29 08:21:28 brian Exp $
* $Id: lqr.c,v 1.33 1999/05/08 11:07:02 brian Exp $
*
* o LQR based on RFC1333
*
@ -78,17 +78,17 @@ SendEchoReq(struct lcp *lcp)
(u_char *)&echo, sizeof echo);
}
void
lqr_RecvEcho(struct fsm *fp, struct mbuf * bp)
struct mbuf *
lqr_RecvEcho(struct fsm *fp, struct mbuf *bp)
{
struct hdlc *hdlc = &link2physical(fp->link)->hdlc;
struct echolqr *lqr;
struct echolqr lqr;
u_int32_t seq;
if (mbuf_Length(bp) == sizeof(struct echolqr)) {
lqr = (struct echolqr *) MBUF_CTOP(bp);
if (ntohl(lqr->signature) == SIGNATURE) {
seq = ntohl(lqr->sequence);
if (mbuf_Length(bp) == sizeof lqr) {
mbuf_Read(bp, &lqr, sizeof lqr);
if (ntohl(lqr.signature) == SIGNATURE) {
seq = ntohl(lqr.sequence);
/* careful not to update lqm.echo.seq_recv with older values */
if ((hdlc->lqm.echo.seq_recv > (u_int32_t)0 - 5 && seq < 5) ||
(hdlc->lqm.echo.seq_recv <= (u_int32_t)0 - 5 &&
@ -96,14 +96,15 @@ lqr_RecvEcho(struct fsm *fp, struct mbuf * bp)
hdlc->lqm.echo.seq_recv = seq;
} else
log_Printf(LogWARN, "lqr_RecvEcho: Got sig 0x%08lx, not 0x%08lx !\n",
(u_long)ntohl(lqr->signature), (u_long)SIGNATURE);
(u_long)ntohl(lqr.signature), (u_long)SIGNATURE);
} else
log_Printf(LogWARN, "lqr_RecvEcho: Got packet size %d, expecting %ld !\n",
mbuf_Length(bp), (long)sizeof(struct echolqr));
return bp;
}
void
lqr_ChangeOrder(struct lqrdata * src, struct lqrdata * dst)
lqr_ChangeOrder(struct lqrdata *src, struct lqrdata *dst)
{
u_int32_t *sp, *dp;
int n;

View File

@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: lqr.h,v 1.13 1998/05/21 21:46:36 brian Exp $
* $Id: lqr.h,v 1.14 1999/05/08 11:07:04 brian Exp $
*
* TODO:
*/
@ -57,7 +57,7 @@ extern void lqr_Start(struct lcp *);
extern void lqr_reStart(struct lcp *);
extern void lqr_Stop(struct physical *, int);
extern void lqr_StopTimer(struct physical *);
extern void lqr_RecvEcho(struct fsm *, struct mbuf *);
extern struct mbuf *lqr_RecvEcho(struct fsm *, struct mbuf *);
extern struct mbuf *lqr_Input(struct bundle *, struct link *, struct mbuf *);
extern struct layer lqrlayer;

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: mbuf.c,v 1.24 1999/03/29 08:21:28 brian Exp $
* $Id: mbuf.c,v 1.25 1999/05/08 11:07:07 brian Exp $
*
*/
#include <sys/types.h>
@ -45,13 +45,13 @@ static int totalalloced;
static unsigned long long mbuf_Mallocs, mbuf_Frees;
int
mbuf_Length(struct mbuf * bp)
mbuf_Length(struct mbuf *bp)
{
int len;
for (len = 0; bp; bp = bp->next)
len += bp->cnt;
return (len);
return len;
}
struct mbuf *
@ -155,7 +155,7 @@ mbuf_Prepend(struct mbuf *bp, const void *ptr, size_t len, size_t extra)
{
struct mbuf *head;
if (bp->offset) {
if (bp && bp->offset) {
if (bp->offset >= len) {
bp->offset -= len;
bp->cnt += len;
@ -168,7 +168,7 @@ mbuf_Prepend(struct mbuf *bp, const void *ptr, size_t len, size_t extra)
bp->offset = 0;
}
head = mbuf_Alloc(len + extra, bp->type);
head = mbuf_Alloc(len + extra, bp ? bp->type : MB_FSM);
head->offset = extra;
head->cnt -= extra;
memcpy(MBUF_CTOP(head), ptr, len);
@ -274,13 +274,15 @@ mbuf_Dequeue(struct mqueue *q)
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);
if (bp != NULL) {
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);
}
}
struct mbuf *
@ -288,24 +290,26 @@ mbuf_Contiguous(struct mbuf *bp)
{
/* Put it all in one contigous (aligned) mbuf */
if (bp->next != NULL) {
struct mbuf *nbp;
u_char *cp;
if (bp != NULL) {
if (bp->next != NULL) {
struct mbuf *nbp;
u_char *cp;
nbp = mbuf_Alloc(mbuf_Length(bp), bp->type);
nbp = mbuf_Alloc(mbuf_Length(bp), bp->type);
for (cp = MBUF_CTOP(nbp); bp; bp = mbuf_FreeSeg(bp)) {
memcpy(cp, MBUF_CTOP(bp), bp->cnt);
cp += bp->cnt;
for (cp = MBUF_CTOP(nbp); bp; bp = mbuf_FreeSeg(bp)) {
memcpy(cp, MBUF_CTOP(bp), bp->cnt);
cp += bp->cnt;
}
bp = nbp;
}
bp = nbp;
}
#ifndef __i386__ /* Do any other archs not care about alignment ? */
else if ((bp->offset & 0x03) != 0) {
bcopy(MBUF_CTOP(bp), bp + 1, bp->cnt);
bp->offset = 0;
}
else if ((bp->offset & 0x03) != 0) {
bcopy(MBUF_CTOP(bp), bp + 1, bp->cnt);
bp->offset = 0;
}
#endif
}
return bp;
}

View File

@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: mbuf.h,v 1.15 1999/03/29 08:21:28 brian Exp $
* $Id: mbuf.h,v 1.16 1999/05/08 11:07:09 brian Exp $
*
* TODO:
*/
@ -36,8 +36,11 @@ struct mqueue {
int qlen;
};
#define MBUF_CTOP(bp) ((u_char *)((bp)+1) + (bp)->offset)
#define CONST_MBUF_CTOP(bp) ((const u_char *)((bp)+1) + (bp)->offset)
#define MBUF_CTOP(bp) \
((bp) ? (u_char *)((bp)+1) + (bp)->offset : NULL)
#define CONST_MBUF_CTOP(bp) \
((bp) ? (const u_char *)((bp)+1) + (bp)->offset : NULL)
#define MB_ASYNC 1
#define MB_FSM 2

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: pred.c,v 1.24 1999/03/16 01:24:23 brian Exp $
* $Id: pred.c,v 1.25 1999/05/08 11:07:28 brian Exp $
*/
#include <sys/types.h>
@ -287,7 +287,7 @@ Pred1Input(void *v, struct ccp *ccp, u_short *proto, struct mbuf *bp)
}
static void
Pred1DictSetup(void *v, struct ccp *ccp, u_short proto, struct mbuf * bp)
Pred1DictSetup(void *v, struct ccp *ccp, u_short proto, struct mbuf *bp)
{
}

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: slcompress.c,v 1.24 1999/03/31 13:44:07 brian Exp $
* $Id: slcompress.c,v 1.25 1999/05/08 11:07:38 brian Exp $
*
* Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989:
* - Initial distribution.
@ -60,7 +60,7 @@
#include "bundle.h"
void
sl_compress_init(struct slcompress * comp, int max_state)
sl_compress_init(struct slcompress *comp, int max_state)
{
register u_int i;
register struct cstate *tstate = comp->tstate;

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: systems.c,v 1.42 1999/03/09 20:39:03 brian Exp $
* $Id: systems.c,v 1.43 1999/05/08 11:07:43 brian Exp $
*
* TODO:
*/
@ -53,7 +53,7 @@ OpenSecret(const char *file)
}
void
CloseSecret(FILE * fp)
CloseSecret(FILE *fp)
{
fclose(fp);
}

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: timer.c,v 1.31 1998/06/27 14:18:11 brian Exp $
* $Id: timer.c,v 1.32 1998/12/14 19:24:29 brian Exp $
*
* TODO:
*/
@ -49,7 +49,7 @@ tState2Nam(u_int state)
}
void
timer_Stop(struct pppTimer * tp)
timer_Stop(struct pppTimer *tp)
{
int omask;
@ -59,7 +59,7 @@ timer_Stop(struct pppTimer * tp)
}
void
timer_Start(struct pppTimer * tp)
timer_Start(struct pppTimer *tp)
{
struct pppTimer *t, *pt;
u_long ticks = 0;
@ -107,7 +107,7 @@ timer_Start(struct pppTimer * tp)
}
static void
StopTimerNoBlock(struct pppTimer * tp)
StopTimerNoBlock(struct pppTimer *tp)
{
struct pppTimer *t, *pt;

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: vjcomp.c,v 1.27 1999/03/31 14:21:46 brian Exp $
* $Id: vjcomp.c,v 1.28 1999/05/08 11:07:55 brian Exp $
*
* TODO:
*/
@ -99,7 +99,7 @@ vj_LayerPush(struct bundle *bundle, struct link *l, struct mbuf *bp, int pri,
}
static struct mbuf *
VjUncompressTcp(struct ipcp *ipcp, struct mbuf * bp, u_char type)
VjUncompressTcp(struct ipcp *ipcp, struct mbuf *bp, u_char type)
{
u_char *bufp;
int len, olen, rlen;