2001-06-13 21:52:19 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1996 - 2001 Brian Somers <brian@Awfulhak.org>
|
|
|
|
* based on work by Toshiharu OHNO <tony-o@iij.ad.jp>
|
|
|
|
* Internet Initiative Japan, Inc (IIJ)
|
|
|
|
* All rights reserved.
|
1995-01-31 06:29:58 +00:00
|
|
|
*
|
2001-06-13 21:52:19 +00:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
1995-01-31 06:29:58 +00:00
|
|
|
*
|
2001-06-13 21:52:19 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
1995-01-31 06:29:58 +00:00
|
|
|
*
|
1999-08-28 01:35:59 +00:00
|
|
|
* $FreeBSD$
|
1995-01-31 06:29:58 +00:00
|
|
|
*/
|
2001-06-13 21:52:19 +00:00
|
|
|
|
1999-01-28 01:56:34 +00:00
|
|
|
#include <sys/param.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
#include <netinet/in.h>
|
1995-01-31 06:29:58 +00:00
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/ip.h>
|
2001-08-14 16:05:52 +00:00
|
|
|
#include <sys/socket.h>
|
1998-04-28 01:25:46 +00:00
|
|
|
#include <sys/un.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
|
1997-11-09 06:22:49 +00:00
|
|
|
#include <stdio.h>
|
1999-08-06 20:04:08 +00:00
|
|
|
#include <string.h> /* strlen/memcpy */
|
1999-05-08 11:07:56 +00:00
|
|
|
#include <termios.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
|
1999-05-08 11:07:56 +00:00
|
|
|
#include "layer.h"
|
1997-10-26 01:04:02 +00:00
|
|
|
#include "mbuf.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "timer.h"
|
|
|
|
#include "fsm.h"
|
1999-05-08 11:07:56 +00:00
|
|
|
#include "proto.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
#include "slcompress.h"
|
1998-03-13 00:44:26 +00:00
|
|
|
#include "lqr.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
#include "hdlc.h"
|
1998-01-29 23:11:44 +00:00
|
|
|
#include "defs.h"
|
|
|
|
#include "iplist.h"
|
|
|
|
#include "throughput.h"
|
2001-08-14 16:05:52 +00:00
|
|
|
#include "ncpaddr.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
#include "ipcp.h"
|
1998-02-23 00:38:44 +00:00
|
|
|
#include "lcp.h"
|
|
|
|
#include "ccp.h"
|
|
|
|
#include "link.h"
|
1998-03-16 22:52:54 +00:00
|
|
|
#include "filter.h"
|
1998-03-20 19:48:28 +00:00
|
|
|
#include "descriptor.h"
|
1998-04-03 19:21:56 +00:00
|
|
|
#include "mp.h"
|
1999-01-28 01:56:34 +00:00
|
|
|
#ifndef NORADIUS
|
|
|
|
#include "radius.h"
|
|
|
|
#endif
|
2001-08-14 16:05:52 +00:00
|
|
|
#include "ipv6cp.h"
|
|
|
|
#include "ncp.h"
|
1998-02-23 00:38:44 +00:00
|
|
|
#include "bundle.h"
|
1997-10-26 01:04:02 +00:00
|
|
|
#include "vjcomp.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1997-08-25 00:29:32 +00:00
|
|
|
#define MAX_VJHEADER 16 /* Maximum size of compressed header */
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1999-05-08 11:07:56 +00:00
|
|
|
static struct mbuf *
|
2004-09-05 01:46:52 +00:00
|
|
|
vj_LayerPush(struct bundle *bundle, struct link *l __unused, struct mbuf *bp,
|
|
|
|
int pri __unused, u_short *proto)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
int type;
|
1999-03-29 08:21:28 +00:00
|
|
|
struct ip *pip;
|
1998-03-13 21:07:46 +00:00
|
|
|
u_short cproto = bundle->ncp.ipcp.peer_compproto >> 16;
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1999-12-20 20:29:47 +00:00
|
|
|
bp = m_pullup(bp);
|
1999-03-29 08:21:28 +00:00
|
|
|
pip = (struct ip *)MBUF_CTOP(bp);
|
1999-05-08 11:07:56 +00:00
|
|
|
if (*proto == PROTO_IP && pip->ip_p == IPPROTO_TCP &&
|
|
|
|
cproto == PROTO_VJCOMP) {
|
1999-03-29 08:21:28 +00:00
|
|
|
type = sl_compress_tcp(bp, pip, &bundle->ncp.ipcp.vj.cslc,
|
1998-03-16 22:54:35 +00:00
|
|
|
&bundle->ncp.ipcp.vj.slstat,
|
1998-03-13 21:07:46 +00:00
|
|
|
bundle->ncp.ipcp.peer_compproto & 0xff);
|
1999-05-08 11:07:56 +00:00
|
|
|
log_Printf(LogDEBUG, "vj_LayerWrite: type = %x\n", type);
|
1995-01-31 06:29:58 +00:00
|
|
|
switch (type) {
|
|
|
|
case TYPE_IP:
|
|
|
|
break;
|
1999-05-08 11:07:56 +00:00
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
case TYPE_UNCOMPRESSED_TCP:
|
1999-05-08 11:07:56 +00:00
|
|
|
*proto = PROTO_VJUNCOMP;
|
1999-05-12 09:49:12 +00:00
|
|
|
log_Printf(LogDEBUG, "vj_LayerPush: PROTO_IP -> PROTO_VJUNCOMP\n");
|
1999-12-20 20:29:47 +00:00
|
|
|
m_settype(bp, MB_VJOUT);
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
1999-05-08 11:07:56 +00:00
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
case TYPE_COMPRESSED_TCP:
|
1999-05-08 11:07:56 +00:00
|
|
|
*proto = PROTO_VJCOMP;
|
1999-05-12 09:49:12 +00:00
|
|
|
log_Printf(LogDEBUG, "vj_LayerPush: PROTO_IP -> PROTO_VJUNCOMP\n");
|
1999-12-20 20:29:47 +00:00
|
|
|
m_settype(bp, MB_VJOUT);
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
1999-05-08 11:07:56 +00:00
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
default:
|
1999-05-12 09:49:12 +00:00
|
|
|
log_Printf(LogERROR, "vj_LayerPush: Unknown frame type %x\n", type);
|
1999-12-20 20:29:47 +00:00
|
|
|
m_freem(bp);
|
1999-05-08 11:07:56 +00:00
|
|
|
return NULL;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1999-05-08 11:07:56 +00:00
|
|
|
}
|
1998-02-23 00:38:44 +00:00
|
|
|
|
1999-05-08 11:07:56 +00:00
|
|
|
return bp;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct mbuf *
|
1999-05-09 20:02:29 +00:00
|
|
|
VjUncompressTcp(struct ipcp *ipcp, struct mbuf *bp, u_char type)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
u_char *bufp;
|
|
|
|
int len, olen, rlen;
|
1997-08-25 00:29:32 +00:00
|
|
|
u_char work[MAX_HDR + MAX_VJHEADER]; /* enough to hold TCP/IP header */
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1999-12-20 20:29:47 +00:00
|
|
|
bp = m_pullup(bp);
|
|
|
|
olen = len = m_length(bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
if (type == TYPE_UNCOMPRESSED_TCP) {
|
|
|
|
/*
|
1997-08-25 00:29:32 +00:00
|
|
|
* Uncompressed packet does NOT change its size, so that we can use mbuf
|
|
|
|
* space for uncompression job.
|
1995-01-31 06:29:58 +00:00
|
|
|
*/
|
|
|
|
bufp = MBUF_CTOP(bp);
|
1998-06-14 00:56:13 +00:00
|
|
|
len = sl_uncompress_tcp(&bufp, len, type, &ipcp->vj.cslc, &ipcp->vj.slstat,
|
|
|
|
(ipcp->my_compproto >> 8) & 255);
|
1995-02-26 12:18:08 +00:00
|
|
|
if (len <= 0) {
|
1999-12-20 20:29:47 +00:00
|
|
|
m_freem(bp);
|
1998-01-21 02:15:33 +00:00
|
|
|
bp = NULL;
|
1999-06-02 15:59:09 +00:00
|
|
|
} else
|
1999-12-20 20:29:47 +00:00
|
|
|
m_settype(bp, MB_VJIN);
|
1999-05-08 11:07:56 +00:00
|
|
|
return bp;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1997-08-25 00:29:32 +00:00
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
/*
|
2011-12-30 10:58:14 +00:00
|
|
|
* Handle compressed packet. 1) Read up to MAX_VJHEADER bytes into work
|
2002-03-31 01:57:06 +00:00
|
|
|
* space. 2) Try to uncompress it. 3) Compute amount of necessary space. 4)
|
1997-08-25 00:29:32 +00:00
|
|
|
* Copy unread data info there.
|
1995-01-31 06:29:58 +00:00
|
|
|
*/
|
1997-08-25 00:29:32 +00:00
|
|
|
if (len > MAX_VJHEADER)
|
|
|
|
len = MAX_VJHEADER;
|
1995-01-31 06:29:58 +00:00
|
|
|
rlen = len;
|
|
|
|
bufp = work + MAX_HDR;
|
1998-05-01 19:26:12 +00:00
|
|
|
bp = mbuf_Read(bp, bufp, rlen);
|
1998-06-14 00:56:13 +00:00
|
|
|
len = sl_uncompress_tcp(&bufp, olen, type, &ipcp->vj.cslc, &ipcp->vj.slstat,
|
|
|
|
(ipcp->my_compproto >> 8) & 255);
|
1995-02-26 12:18:08 +00:00
|
|
|
if (len <= 0) {
|
1999-12-20 20:29:47 +00:00
|
|
|
m_freem(bp);
|
1998-01-21 02:15:33 +00:00
|
|
|
return NULL;
|
1995-02-26 12:18:08 +00:00
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
len -= olen;
|
|
|
|
len += rlen;
|
1999-12-20 20:29:51 +00:00
|
|
|
|
|
|
|
bp = m_prepend(bp, bufp, len, 0);
|
1999-12-20 20:29:47 +00:00
|
|
|
m_settype(bp, MB_VJIN);
|
1999-12-20 20:29:51 +00:00
|
|
|
|
|
|
|
return bp;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1999-05-08 11:07:56 +00:00
|
|
|
static struct mbuf *
|
2004-09-05 01:46:52 +00:00
|
|
|
vj_LayerPull(struct bundle *bundle, struct link *l __unused, struct mbuf *bp,
|
1999-05-08 11:07:56 +00:00
|
|
|
u_short *proto)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
u_char type;
|
|
|
|
|
1999-05-08 11:07:56 +00:00
|
|
|
switch (*proto) {
|
1995-01-31 06:29:58 +00:00
|
|
|
case PROTO_VJCOMP:
|
|
|
|
type = TYPE_COMPRESSED_TCP;
|
1999-05-12 09:49:12 +00:00
|
|
|
log_Printf(LogDEBUG, "vj_LayerPull: PROTO_VJCOMP -> PROTO_IP\n");
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
case PROTO_VJUNCOMP:
|
|
|
|
type = TYPE_UNCOMPRESSED_TCP;
|
1999-05-12 09:49:12 +00:00
|
|
|
log_Printf(LogDEBUG, "vj_LayerPull: PROTO_VJUNCOMP -> PROTO_IP\n");
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
default:
|
1999-05-08 11:07:56 +00:00
|
|
|
return bp;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1999-05-08 11:07:56 +00:00
|
|
|
|
|
|
|
*proto = PROTO_IP;
|
|
|
|
return VjUncompressTcp(&bundle->ncp.ipcp, bp, type);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1997-12-03 10:23:54 +00:00
|
|
|
|
|
|
|
const char *
|
1998-01-11 17:50:49 +00:00
|
|
|
vj2asc(u_int32_t val)
|
1997-12-03 10:23:54 +00:00
|
|
|
{
|
1998-06-15 19:06:58 +00:00
|
|
|
static char asc[50]; /* The return value is used immediately */
|
1997-12-03 10:23:54 +00:00
|
|
|
|
1998-04-16 00:26:21 +00:00
|
|
|
if (val)
|
1999-05-08 11:07:56 +00:00
|
|
|
snprintf(asc, sizeof asc, "%d VJ slots with%s slot compression",
|
|
|
|
(int)((val>>8)&15)+1, val & 1 ? "" : "out");
|
1998-04-16 00:26:21 +00:00
|
|
|
else
|
|
|
|
strcpy(asc, "VJ disabled");
|
1997-12-03 10:23:54 +00:00
|
|
|
return asc;
|
|
|
|
}
|
1999-05-08 11:07:56 +00:00
|
|
|
|
|
|
|
struct layer vjlayer = { LAYER_VJ, "vj", vj_LayerPush, vj_LayerPull };
|