summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorbrian <brian@cvs.openbsd.org>1999-03-29 08:20:34 +0000
committerbrian <brian@cvs.openbsd.org>1999-03-29 08:20:34 +0000
commit34382abd3dd4a8ca1873c8d819619d0b0b166a6c (patch)
treebe82fe16c72adaf028d356365e3390d18d006cac /usr.sbin
parentc88e14f2546ce3d5ed6cd2890cd74273fd79c0b2 (diff)
Ensure that the thing we're casting to struct ip
is aligned for non-i386 architectures.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/ppp/ppp/cbcp.c3
-rw-r--r--usr.sbin/ppp/ppp/fsm.c3
-rw-r--r--usr.sbin/ppp/ppp/hdlc.c10
-rw-r--r--usr.sbin/ppp/ppp/ip.c4
-rw-r--r--usr.sbin/ppp/ppp/lqr.c5
-rw-r--r--usr.sbin/ppp/ppp/mbuf.c38
-rw-r--r--usr.sbin/ppp/ppp/mbuf.h3
-rw-r--r--usr.sbin/ppp/ppp/vjcomp.c12
8 files changed, 53 insertions, 25 deletions
diff --git a/usr.sbin/ppp/ppp/cbcp.c b/usr.sbin/ppp/ppp/cbcp.c
index 6913d34a075..c6a608231e0 100644
--- a/usr.sbin/ppp/ppp/cbcp.c
+++ b/usr.sbin/ppp/ppp/cbcp.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: cbcp.c,v 1.6 1999/02/26 21:28:19 brian Exp $
+ * $Id: cbcp.c,v 1.7 1999/03/29 08:20:32 brian Exp $
*/
#include <sys/param.h>
@@ -608,6 +608,7 @@ cbcp_Input(struct physical *p, struct mbuf *bp)
struct cbcp *cbcp = &p->dl->cbcp;
int len;
+ bp = mbuf_Contiguous(bp);
len = mbuf_Length(bp);
if (len < sizeof(struct cbcp_header)) {
mbuf_Free(bp);
diff --git a/usr.sbin/ppp/ppp/fsm.c b/usr.sbin/ppp/ppp/fsm.c
index 5df2fb146e5..73fd93ffd78 100644
--- a/usr.sbin/ppp/ppp/fsm.c
+++ b/usr.sbin/ppp/ppp/fsm.c
@@ -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.5 1999/03/01 02:52:19 brian Exp $
+ * $Id: fsm.c,v 1.6 1999/03/29 08:20:32 brian Exp $
*
* TODO:
*/
@@ -826,6 +826,7 @@ FsmRecvProtoRej(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
struct physical *p = link2physical(fp->link);
u_short *sp, proto;
+ bp = mbuf_Contiguous(bp);
sp = (u_short *)MBUF_CTOP(bp);
proto = ntohs(*sp);
log_Printf(fp->LogLevel, "%s: -- Protocol 0x%04x (%s) was rejected!\n",
diff --git a/usr.sbin/ppp/ppp/hdlc.c b/usr.sbin/ppp/ppp/hdlc.c
index 7118e0aeeb1..0b3fe0ebbd4 100644
--- a/usr.sbin/ppp/ppp/hdlc.c
+++ b/usr.sbin/ppp/ppp/hdlc.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: hdlc.c,v 1.3 1999/02/11 10:14:50 brian Exp $
+ * $Id: hdlc.c,v 1.4 1999/03/29 08:20:32 brian Exp $
*
* TODO:
*/
@@ -174,7 +174,7 @@ hdlc_Output(struct link *l, int pri, u_short proto, struct mbuf *bp)
mhp->cnt += 2;
}
- mhp->next = bp;
+ mhp->next = bp = mbuf_Contiguous(bp);
if (!p) {
/*
@@ -188,11 +188,7 @@ hdlc_Output(struct link *l, int pri, u_short proto, struct mbuf *bp)
return;
}
- /* Tack mfcs onto the end, then set bp back to the start of the data */
- while (bp->next != NULL)
- bp = bp->next;
- bp->next = mfcs;
- bp = mhp->next;
+ bp->next = mfcs; /* Tack mfcs onto the end */
p->hdlc.lqm.OutOctets += mbuf_Length(mhp) + 1;
p->hdlc.lqm.OutPackets++;
diff --git a/usr.sbin/ppp/ppp/ip.c b/usr.sbin/ppp/ppp/ip.c
index 3c2298301fe..75aabb2c016 100644
--- a/usr.sbin/ppp/ppp/ip.c
+++ b/usr.sbin/ppp/ppp/ip.c
@@ -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.4 1999/02/06 03:22:38 brian Exp $
+ * $Id: ip.c,v 1.5 1999/03/29 08:20:32 brian Exp $
*
* TODO:
* o Return ICMP message for filterd packet
@@ -553,7 +553,7 @@ ip_FlushPacket(struct link *l, struct bundle *bundle)
for (queue = &ipcp->Queue[PRI_FAST]; queue >= ipcp->Queue; queue--)
if (queue->top) {
- bp = mbuf_Dequeue(queue);
+ bp = mbuf_Contiguous(mbuf_Dequeue(queue));
if (bp) {
struct ip *pip = (struct ip *)MBUF_CTOP(bp);
diff --git a/usr.sbin/ppp/ppp/lqr.c b/usr.sbin/ppp/ppp/lqr.c
index c0c1a9ed49b..d86818aaa1a 100644
--- a/usr.sbin/ppp/ppp/lqr.c
+++ b/usr.sbin/ppp/ppp/lqr.c
@@ -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.2 1999/02/06 03:22:41 brian Exp $
+ * $Id: lqr.c,v 1.3 1999/03/29 08:20:32 brian Exp $
*
* o LQR based on RFC1333
*
@@ -171,7 +171,7 @@ lqr_Input(struct physical *physical, struct mbuf *bp)
len, (long)sizeof(struct lqrdata));
else if (!IsAccepted(physical->link.lcp.cfg.lqr) &&
!(physical->hdlc.lqm.method & LQM_LQR)) {
- bp->offset -= 2;
+ bp->offset -= 2; /* XXX: We have a bit too much knowledge here ! */
bp->cnt += 2;
lcp_SendProtoRej(physical->hdlc.lqm.owner, MBUF_CTOP(bp), bp->cnt);
} else {
@@ -179,6 +179,7 @@ lqr_Input(struct physical *physical, struct mbuf *bp)
struct lcp *lcp;
u_int32_t lastLQR;
+ bp = mbuf_Contiguous(bp);
lqr = (struct lqrdata *)MBUF_CTOP(bp);
lcp = physical->hdlc.lqm.owner;
if (ntohl(lqr->MagicNumber) != physical->hdlc.lqm.owner->his_magic)
diff --git a/usr.sbin/ppp/ppp/mbuf.c b/usr.sbin/ppp/ppp/mbuf.c
index 7ef4bb23f27..32ed0623bb8 100644
--- a/usr.sbin/ppp/ppp/mbuf.c
+++ b/usr.sbin/ppp/ppp/mbuf.c
@@ -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.2 1999/02/06 03:22:42 brian Exp $
+ * $Id: mbuf.c,v 1.3 1999/03/29 08:20:32 brian Exp $
*
*/
#include <sys/types.h>
@@ -72,8 +72,7 @@ mbuf_Alloc(int cnt, int type)
totalalloced += cnt;
bp->size = bp->cnt = cnt;
bp->type = type;
- bp->pnext = NULL;
- return (bp);
+ return bp;
}
struct mbuf *
@@ -87,9 +86,10 @@ mbuf_FreeSeg(struct mbuf * bp)
MemMap[bp->type].octets -= bp->size;
totalalloced -= bp->size;
free(bp);
- return (nbp);
+ bp = nbp;
}
- return (bp);
+
+ return bp;
}
void
@@ -192,7 +192,6 @@ mbuf_Dequeue(struct mqueue *q)
return bp;
}
-
void
mbuf_Enqueue(struct mqueue *queue, struct mbuf *bp)
{
@@ -204,3 +203,30 @@ mbuf_Enqueue(struct mqueue *queue, struct mbuf *bp)
queue->qlen++;
log_Printf(LogDEBUG, "mbuf_Enqueue: len = %d\n", queue->qlen);
}
+
+struct mbuf *
+mbuf_Contiguous(struct mbuf *bp)
+{
+ /* Put it all in one contigous (aligned) mbuf */
+
+ if (bp->next != NULL) {
+ struct mbuf *nbp;
+ u_char *cp;
+
+ 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;
+ }
+ 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;
+ }
+#endif
+
+ return bp;
+}
diff --git a/usr.sbin/ppp/ppp/mbuf.h b/usr.sbin/ppp/ppp/mbuf.h
index 1b987439387..beca223fc5b 100644
--- a/usr.sbin/ppp/ppp/mbuf.h
+++ b/usr.sbin/ppp/ppp/mbuf.h
@@ -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.2 1999/02/06 03:22:42 brian Exp $
+ * $Id: mbuf.h,v 1.3 1999/03/29 08:20:33 brian Exp $
*
* TODO:
*/
@@ -64,3 +64,4 @@ extern void mbuf_Log(void);
extern int mbuf_Show(struct cmdargs const *);
extern void mbuf_Enqueue(struct mqueue *, struct mbuf *);
extern struct mbuf *mbuf_Dequeue(struct mqueue *);
+extern struct mbuf *mbuf_Contiguous(struct mbuf *);
diff --git a/usr.sbin/ppp/ppp/vjcomp.c b/usr.sbin/ppp/ppp/vjcomp.c
index b93a08b3b8d..31627face6e 100644
--- a/usr.sbin/ppp/ppp/vjcomp.c
+++ b/usr.sbin/ppp/ppp/vjcomp.c
@@ -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.2 1999/02/06 03:22:49 brian Exp $
+ * $Id: vjcomp.c,v 1.3 1999/03/29 08:20:33 brian Exp $
*
* TODO:
*/
@@ -60,14 +60,15 @@ vj_SendFrame(struct link *l, struct mbuf * bp, struct bundle *bundle)
{
int type;
u_short proto;
+ struct ip *pip;
u_short cproto = bundle->ncp.ipcp.peer_compproto >> 16;
log_Printf(LogDEBUG, "vj_SendFrame: COMPPROTO = %x\n",
bundle->ncp.ipcp.peer_compproto);
- if (((struct ip *) MBUF_CTOP(bp))->ip_p == IPPROTO_TCP
- && cproto == PROTO_VJCOMP) {
- type = sl_compress_tcp(bp, (struct ip *)MBUF_CTOP(bp),
- &bundle->ncp.ipcp.vj.cslc,
+ bp = mbuf_Contiguous(bp);
+ pip = (struct ip *)MBUF_CTOP(bp);
+ if (pip->ip_p == IPPROTO_TCP && cproto == PROTO_VJCOMP) {
+ type = sl_compress_tcp(bp, pip, &bundle->ncp.ipcp.vj.cslc,
&bundle->ncp.ipcp.vj.slstat,
bundle->ncp.ipcp.peer_compproto & 0xff);
log_Printf(LogDEBUG, "vj_SendFrame: type = %x\n", type);
@@ -101,6 +102,7 @@ VjUncompressTcp(struct ipcp *ipcp, struct mbuf * bp, u_char type)
struct mbuf *nbp;
u_char work[MAX_HDR + MAX_VJHEADER]; /* enough to hold TCP/IP header */
+ bp = mbuf_Contiguous(bp);
olen = len = mbuf_Length(bp);
if (type == TYPE_UNCOMPRESSED_TCP) {