Latest version of PPP stuff, with packet compression and other

improvements.  The PPP kernel code is now split into if_ppp.c,
containing generic PPP support, and ppp_tty.c, which specifically
supports PPP on async tty devices (as a line discipline).  This is
so that other devices can be supported without making them look
like ttys.
This commit is contained in:
paulus 1995-07-04 06:28:17 +00:00
parent e476de387b
commit 7f06ab8b0b
9 changed files with 3465 additions and 1107 deletions

1116
sys/net/bsd-comp.c Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_ppp.h,v 1.8 1995/03/08 02:57:02 cgd Exp $ */
/* $NetBSD: if_ppp.h,v 1.9 1995/07/04 06:28:22 paulus Exp $ */
/*
* if_ppp.h - Point-to-Point Protocol definitions.
@ -22,125 +22,109 @@
#ifndef _IF_PPP_H_
#define _IF_PPP_H_
/*
* Standard PPP header.
*/
struct ppp_header {
u_int8_t ph_address; /* Address Field */
u_int8_t ph_control; /* Control Field */
u_int16_t ph_protocol; /* Protocol Field */
};
#define PPP_HDRLEN 4 /* sizeof(struct ppp_header) must be 4 */
#define PPP_FCSLEN 2 /* octets for FCS */
#define PPP_ALLSTATIONS 0xff /* All-Stations broadcast address */
#define PPP_UI 0x03 /* Unnumbered Information */
#define PPP_FLAG 0x7e /* Flag Sequence */
#define PPP_ESCAPE 0x7d /* Asynchronous Control Escape */
#define PPP_TRANS 0x20 /* Asynchronous transparency modifier */
/*
* Protocol field values.
*/
#define PPP_IP 0x21 /* Internet Protocol */
#define PPP_XNS 0x25 /* Xerox NS */
#define PPP_VJC_COMP 0x2d /* VJ compressed TCP */
#define PPP_VJC_UNCOMP 0x2f /* VJ uncompressed TCP */
#define PPP_COMP 0xfd /* compressed packet */
#define PPP_LCP 0xc021 /* Link Control Protocol */
#define PPP_CCP 0x80fd /* Compression Control Protocol */
/*
* Important FCS values.
*/
#define PPP_INITFCS 0xffff /* Initial FCS value */
#define PPP_GOODFCS 0xf0b8 /* Good final FCS value */
#define PPP_FCS(fcs, c) (((fcs) >> 8) ^ fcstab[((fcs) ^ (c)) & 0xff])
/*
* Packet sizes
*/
#define PPP_MTU 1500 /* Default MTU (size of Info field) */
#define PPP_MRU 1500 /* Default MRU (max receive unit) */
#define PPP_MAXMRU 65000 /* Largest MRU we allow */
/* Extended asyncmap - allows any character to be escaped. */
typedef u_int32_t ext_accm[8];
/*
* Structure describing each ppp unit.
* Bit definitions for flags.
*/
struct ppp_softc {
struct ifnet sc_if; /* network-visible interface */
u_int sc_flags; /* see below */
void *sc_devp; /* pointer to device-dependent structure */
int (*sc_start) __P((struct ppp_softc *)); /* start routine */
short sc_mru; /* max receive unit */
pid_t sc_xfer; /* used in xferring unit to another dev */
struct ifqueue sc_inq; /* TTY side input queue */
struct ifqueue sc_fastq; /* IP interactive output packet queue */
#ifdef VJC
struct slcompress sc_comp; /* vjc control buffer */
#endif
u_int sc_bytessent; /* count of octets sent */
u_int sc_bytesrcvd; /* count of octets received */
caddr_t sc_bpf; /* hook for BPF */
/* Device-dependent part for async lines. */
ext_accm sc_asyncmap; /* async control character map */
u_int32_t sc_rasyncmap; /* receive async control char map */
struct mbuf *sc_outm; /* mbuf chain being output currently */
struct mbuf *sc_m; /* pointer to input mbuf chain */
struct mbuf *sc_mc; /* pointer to current input mbuf */
char *sc_mp; /* pointer to next char in input mbuf */
short sc_ilen; /* length of input-packet-so-far */
u_short sc_fcs; /* FCS so far (input) */
u_short sc_outfcs; /* FCS so far for output packet */
u_char sc_rawin[16]; /* chars as received */
int sc_rawin_count; /* # in sc_rawin */
};
/* flags */
#define SC_COMP_PROT 0x00000001 /* protocol compression (output) */
#define SC_COMP_AC 0x00000002 /* header compression (output) */
#define SC_COMP_TCP 0x00000004 /* TCP (VJ) compression (output) */
#define SC_NO_TCP_CCID 0x00000008 /* disable VJ connection-id comp. */
#define SC_REJ_COMP_AC 0x00000010 /* reject adrs/ctrl comp. on input */
#define SC_REJ_COMP_TCP 0x00000020 /* reject TCP (VJ) comp. on input */
#define SC_ENABLE_IP 0x00000100 /* IP packets may be exchanged */
#define SC_CCP_OPEN 0x00000040 /* Look at CCP packets */
#define SC_CCP_UP 0x00000080 /* May send/recv compressed packets */
#define SC_DEBUG 0x00010000 /* enable debug messages */
#define SC_LOG_INPKT 0x00020000 /* log contents of good pkts recvd */
#define SC_LOG_OUTPKT 0x00040000 /* log contents of pkts sent */
#define SC_LOG_RAWIN 0x00080000 /* log all chars received */
#define SC_LOG_FLUSH 0x00100000 /* log all chars flushed */
#define SC_MASK 0x0fffffff /* bits that user can change */
/* state bits */
#define SC_ESCAPED 0x80000000 /* saw a PPP_ESCAPE */
#define SC_FLUSH 0x40000000 /* flush input until next PPP_FLAG */
#define SC_RCV_B7_0 0x01000000 /* have rcvd char with bit 7 = 0 */
#define SC_RCV_B7_1 0x02000000 /* have rcvd char with bit 7 = 0 */
#define SC_RCV_B7_1 0x02000000 /* have rcvd char with bit 7 = 1 */
#define SC_RCV_EVNP 0x04000000 /* have rcvd char with even parity */
#define SC_RCV_ODDP 0x08000000 /* have rcvd char with odd parity */
#define SC_MASK 0x0fff00ff /* bits that user can change */
/*
* State bits in sc_flags, not changeable by user.
*/
#define SC_TIMEOUT 0x00000400 /* timeout is currently pending */
#define SC_VJ_RESET 0x00000800 /* need to reset VJ decomp */
#define SC_COMP_RUN 0x00001000 /* compressor has been inited */
#define SC_DECOMP_RUN 0x00002000 /* decompressor has been inited */
#define SC_DC_ERROR 0x00004000 /* non-fatal decomp error detected */
#define SC_DC_FERROR 0x00008000 /* fatal decomp error detected */
#define SC_TBUSY 0x10000000 /* xmitter doesn't need a packet yet */
#define SC_PKTLOST 0x20000000 /* have lost or dropped a packet */
#define SC_FLUSH 0x40000000 /* flush input until next PPP_FLAG */
#define SC_ESCAPED 0x80000000 /* saw a PPP_ESCAPE */
/*
* Ioctl definitions.
*/
struct npioctl {
int protocol; /* PPP procotol, e.g. PPP_IP */
enum NPmode mode;
};
/* Structure describing a CCP configuration option, for PPPIOCSCOMPRESS */
struct ppp_option_data {
u_char *ptr;
u_int length;
int transmit;
};
struct ifpppstatsreq {
char ifr_name[IFNAMSIZ];
struct ppp_stats stats;
};
struct ifpppcstatsreq {
char ifr_name[IFNAMSIZ];
struct ppp_comp_stats stats;
};
/*
* Ioctl definitions.
*/
/* this stuff doesn't belong here... */
#define PPPIOCGFLAGS _IOR('t', 90, int) /* get configuration flags */
#define PPPIOCSFLAGS _IOW('t', 89, int) /* set configuration flags */
#define PPPIOCGASYNCMAP _IOR('t', 88, int32_t) /* get async map */
#define PPPIOCSASYNCMAP _IOW('t', 87, int32_t) /* set async map */
#define PPPIOCGASYNCMAP _IOR('t', 88, int) /* get async map */
#define PPPIOCSASYNCMAP _IOW('t', 87, int) /* set async map */
#define PPPIOCGUNIT _IOR('t', 86, int) /* get ppp unit number */
#define PPPIOCGRASYNCMAP _IOR('t', 85, int32_t) /* get receive async map */
#define PPPIOCSRASYNCMAP _IOW('t', 84, int32_t) /* set receive async map */
#define PPPIOCGRASYNCMAP _IOR('t', 85, int) /* get receive async map */
#define PPPIOCSRASYNCMAP _IOW('t', 84, int) /* set receive async map */
#define PPPIOCGMRU _IOR('t', 83, int) /* get max receive unit */
#define PPPIOCSMRU _IOW('t', 82, int) /* set max receive unit */
#define PPPIOCSMAXCID _IOW('t', 81, int) /* set VJ max slot ID */
#define PPPIOCGXASYNCMAP _IOR('t', 80, ext_accm) /* get extended ACCM */
#define PPPIOCSXASYNCMAP _IOW('t', 79, ext_accm) /* set extended ACCM */
#define PPPIOCXFERUNIT _IO('t', 78) /* transfer PPP unit */
#define PPPIOCSCOMPRESS _IOW('t', 77, struct ppp_option_data)
#define PPPIOCGNPMODE _IOWR('t', 76, struct npioctl) /* get NP mode */
#define PPPIOCSNPMODE _IOW('t', 75, struct npioctl) /* set NP mode */
#define PPPIOCGIDLE _IOR('t', 74, struct ppp_idle) /* get idle time */
/* PPPIOC[GS]MTU are alternatives to SIOC[GS]IFMTU, used under Ultrix */
#define PPPIOCGMTU _IOR('t', 73, int) /* get interface MTU */
#define PPPIOCSMTU _IOW('t', 72, int) /* set interface MTU */
/*
* These two are interface ioctls so that pppstats can do them on
* a socket without having to open the serial device.
*/
#define SIOCGPPPSTATS _IOWR('i', 123, struct ifpppstatsreq)
#define SIOCGPPPCSTATS _IOWR('i', 122, struct ifpppcstatsreq)
#if !defined(ifr_mtu)
#define ifr_mtu ifr_metric
#define ifr_mtu ifr_ifru.ifru_metric
#endif
#endif /* _IF_PPP_H_ */

104
sys/net/if_pppvar.h Normal file
View File

@ -0,0 +1,104 @@
/* $NetBSD: if_pppvar.h,v 1.1 1995/07/04 06:28:24 paulus Exp $ */
/*
* if_pppvar.h - private structures and declarations for PPP.
*
* Copyright (c) 1994 The Australian National University.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, provided that the above copyright
* notice appears in all copies. This software is provided without any
* warranty, express or implied. The Australian National University
* makes no representations about the suitability of this software for
* any purpose.
*
* IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
* PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
* THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
* OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
* OR MODIFICATIONS.
*
* Copyright (c) 1989 Carnegie Mellon University.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by Carnegie Mellon University. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/*
* Supported network protocols. These values are used for
* indexing sc_npmode.
*/
#define NP_IP 0 /* Internet Protocol */
#define NUM_NP 1 /* Number of NPs. */
/*
* Structure describing each ppp unit.
*/
struct ppp_softc {
struct ifnet sc_if; /* network-visible interface */
u_int sc_flags; /* control/status bits; see if_ppp.h */
void *sc_devp; /* pointer to device-dep structure */
void (*sc_start) __P((struct ppp_softc *)); /* start output proc */
void (*sc_ctlp) __P((struct ppp_softc *)); /* rcvd control pkt */
void (*sc_relinq) __P((struct ppp_softc *)); /* relinquish ifunit */
u_int16_t sc_mru; /* max receive unit */
pid_t sc_xfer; /* used in transferring unit */
struct ifqueue sc_rawq; /* received packets */
struct ifqueue sc_inq; /* queue of input packets for daemon */
struct ifqueue sc_fastq; /* interactive output packet q */
struct mbuf *sc_togo; /* output packet ready to go */
struct mbuf *sc_npqueue; /* output packets not to be sent yet */
struct mbuf **sc_npqtail; /* ptr to last next ptr in npqueue */
#ifdef VJC
struct slcompress sc_comp; /* vjc control buffer */
#endif
u_int sc_bytessent; /* count of octets sent */
u_int sc_bytesrcvd; /* count of octets received */
caddr_t sc_bpf; /* hook for BPF */
enum NPmode sc_npmode[NUM_NP]; /* what to do with each NP */
struct compressor *sc_xcomp; /* transmit compressor */
void *sc_xc_state; /* transmit compressor state */
struct compressor *sc_rcomp; /* receive decompressor */
void *sc_rc_state; /* receive decompressor state */
time_t sc_last_sent; /* time (secs) last NP pkt sent */
time_t sc_last_recv; /* time (secs) last NP pkt rcvd */
/* Device-dependent part for async lines. */
ext_accm sc_asyncmap; /* async control character map */
u_int32_t sc_rasyncmap; /* receive async control char map */
struct mbuf *sc_outm; /* mbuf chain currently being output */
struct mbuf *sc_m; /* pointer to input mbuf chain */
struct mbuf *sc_mc; /* pointer to current input mbuf */
char *sc_mp; /* ptr to next char in input mbuf */
u_int16_t sc_ilen; /* length of input packet so far */
u_int16_t sc_fcs; /* FCS so far (input) */
u_int16_t sc_outfcs; /* FCS so far for output packet */
u_char sc_rawin[16]; /* chars as received */
int sc_rawin_count; /* # in sc_rawin */
};
struct ppp_softc ppp_softc[NPPP];
struct ppp_softc *pppalloc __P((pid_t pid));
void pppdealloc __P((struct ppp_softc *sc));
int pppioctl __P((struct ppp_softc *sc, int cmd, caddr_t data,
int flag, struct proc *p));
void ppppktin __P((struct ppp_softc *sc, struct mbuf *m, int lost));
struct mbuf *ppp_dequeue __P((struct ppp_softc *sc));

138
sys/net/ppp-comp.h Normal file
View File

@ -0,0 +1,138 @@
/* $NetBSD: ppp-comp.h,v 1.1 1995/07/04 06:28:24 paulus Exp $ */
/*
* ppp-comp.h - Definitions for doing PPP packet compression.
*
* Copyright (c) 1994 The Australian National University.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, provided that the above copyright
* notice appears in all copies. This software is provided without any
* warranty, express or implied. The Australian National University
* makes no representations about the suitability of this software for
* any purpose.
*
* IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
* PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
* THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
* OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
* OR MODIFICATIONS.
*
* $Id: ppp-comp.h,v 1.1 1995/07/04 06:28:24 paulus Exp $
*/
#ifndef _NET_PPP_COMP_H
#define _NET_PPP_COMP_H
/*
* The following symbols control whether we include code for
* various compression methods.
*/
#ifndef DO_BSD_COMPRESS
#define DO_BSD_COMPRESS 1 /* by default, include BSD-Compress */
#endif
/*
* Structure giving methods for compression/decompression.
*/
#ifdef PACKETPTR
struct compressor {
int compress_proto; /* CCP compression protocol number */
/* Allocate space for a compressor (transmit side) */
void *(*comp_alloc) __P((u_char *options, int opt_len));
/* Free space used by a compressor */
void (*comp_free) __P((void *state));
/* Initialize a compressor */
int (*comp_init) __P((void *state, u_char *options, int opt_len,
int unit, int hdrlen, int debug));
/* Reset a compressor */
void (*comp_reset) __P((void *state));
/* Compress a packet */
int (*compress) __P((void *state, PACKETPTR *mret,
PACKETPTR mp, int orig_len, int max_len));
/* Return compression statistics */
void (*comp_stat) __P((void *state, struct compstat *stats));
/* Allocate space for a decompressor (receive side) */
void *(*decomp_alloc) __P((u_char *options, int opt_len));
/* Free space used by a decompressor */
void (*decomp_free) __P((void *state));
/* Initialize a decompressor */
int (*decomp_init) __P((void *state, u_char *options, int opt_len,
int unit, int hdrlen, int mru, int debug));
/* Reset a decompressor */
void (*decomp_reset) __P((void *state));
/* Decompress a packet. */
int (*decompress) __P((void *state, PACKETPTR mp,
PACKETPTR *dmpp));
/* Update state for an incompressible packet received */
void (*incomp) __P((void *state, PACKETPTR mp));
/* Return decompression statistics */
void (*decomp_stat) __P((void *state, struct compstat *stats));
};
#endif /* PACKETPTR */
/*
* Return values for decompress routine.
* We need to make these distinctions so that we can disable certain
* useful functionality, namely sending a CCP reset-request as a result
* of an error detected after decompression. This is to avoid infringing
* a patent held by Motorola.
* Don't you just lurve software patents.
*/
#define DECOMP_OK 0 /* everything went OK */
#define DECOMP_ERROR 1 /* error detected before decomp. */
#define DECOMP_FATALERROR 2 /* error detected after decomp. */
/*
* CCP codes.
*/
#define CCP_CONFREQ 1
#define CCP_CONFACK 2
#define CCP_TERMREQ 5
#define CCP_TERMACK 6
#define CCP_RESETREQ 14
#define CCP_RESETACK 15
/*
* Max # bytes for a CCP option
*/
#define CCP_MAX_OPTION_LENGTH 32
/*
* Parts of a CCP packet.
*/
#define CCP_CODE(dp) ((dp)[0])
#define CCP_ID(dp) ((dp)[1])
#define CCP_LENGTH(dp) (((dp)[2] << 8) + (dp)[3])
#define CCP_HDRLEN 4
#define CCP_OPT_CODE(dp) ((dp)[0])
#define CCP_OPT_LENGTH(dp) ((dp)[1])
#define CCP_OPT_MINLEN 2
/*
* Definitions for BSD-Compress.
*/
#define CI_BSD_COMPRESS 21 /* config. option for BSD-Compress */
#define CILEN_BSD_COMPRESS 3 /* length of config. option */
/* Macros for handling the 3rd byte of the BSD-Compress config option. */
#define BSD_NBITS(x) ((x) & 0x1F) /* number of bits requested */
#define BSD_VERSION(x) ((x) >> 5) /* version of option format */
#define BSD_CURRENT_VERSION 1 /* current version number */
#define BSD_MAKE_OPT(v, n) (((v) << 5) | (n))
#define BSD_MIN_BITS 9 /* smallest code size supported */
#define BSD_MAX_BITS 15 /* largest code size supported */
#endif /* _NET_PPP_COMP_H */

160
sys/net/ppp_defs.h Normal file
View File

@ -0,0 +1,160 @@
/* $NetBSD: ppp_defs.h,v 1.1 1995/07/04 06:28:26 paulus Exp $ */
/*
* ppp_defs.h - PPP definitions.
*
* Copyright (c) 1994 The Australian National University.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, provided that the above copyright
* notice appears in all copies. This software is provided without any
* warranty, express or implied. The Australian National University
* makes no representations about the suitability of this software for
* any purpose.
*
* IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
* PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
* THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
* OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
* OR MODIFICATIONS.
*/
#ifndef _PPP_DEFS_H_
#define _PPP_DEFS_H_
/*
* The basic PPP frame.
*/
#define PPP_HDRLEN 4 /* octets for standard ppp header */
#define PPP_FCSLEN 2 /* octets for FCS */
#define PPP_MRU 1500 /* default MRU = max length of info field */
#define PPP_ADDRESS(p) (((u_char *)(p))[0])
#define PPP_CONTROL(p) (((u_char *)(p))[1])
#define PPP_PROTOCOL(p) ((((u_char *)(p))[2] << 8) + ((u_char *)(p))[3])
/*
* Significant octet values.
*/
#define PPP_ALLSTATIONS 0xff /* All-Stations broadcast address */
#define PPP_UI 0x03 /* Unnumbered Information */
#define PPP_FLAG 0x7e /* Flag Sequence */
#define PPP_ESCAPE 0x7d /* Asynchronous Control Escape */
#define PPP_TRANS 0x20 /* Asynchronous transparency modifier */
/*
* Protocol field values.
*/
#define PPP_IP 0x21 /* Internet Protocol */
#define PPP_VJC_COMP 0x2d /* VJ compressed TCP */
#define PPP_VJC_UNCOMP 0x2f /* VJ uncompressed TCP */
#define PPP_COMP 0xfd /* compressed packet */
#define PPP_IPCP 0x8021 /* IP Control Protocol */
#define PPP_CCP 0x80fd /* Compression Control Protocol */
#define PPP_LCP 0xc021 /* Link Control Protocol */
#define PPP_PAP 0xc023 /* Password Authentication Protocol */
#define PPP_LQR 0xc025 /* Link Quality Report protocol */
#define PPP_CHAP 0xc223 /* Cryptographic Handshake Auth. Protocol */
/*
* Values for FCS calculations.
*/
#define PPP_INITFCS 0xffff /* Initial FCS value */
#define PPP_GOODFCS 0xf0b8 /* Good final FCS value */
#define PPP_FCS(fcs, c) (((fcs) >> 8) ^ fcstab[((fcs) ^ (c)) & 0xff])
/*
* A 32-bit unsigned integral type.
*/
#ifndef __BIT_TYPES_DEFINED__
#ifdef UINT32_T
typedef UINT32_T u_int32_t;
#else
typedef unsigned int u_int32_t;
#endif
#endif
/*
* Extended asyncmap - allows any character to be escaped.
*/
typedef u_int32_t ext_accm[8];
/*
* What to do with network protocol (NP) packets.
*/
enum NPmode {
NPMODE_PASS, /* pass the packet through */
NPMODE_DROP, /* silently drop the packet */
NPMODE_ERROR, /* return an error */
NPMODE_QUEUE /* save it up for later. */
};
/*
* Statistics.
*/
struct pppstat {
u_int ppp_ibytes; /* bytes received */
u_int ppp_ipackets; /* packets received */
u_int ppp_ierrors; /* receive errors */
u_int ppp_obytes; /* bytes sent */
u_int ppp_opackets; /* packets sent */
u_int ppp_oerrors; /* transmit errors */
};
struct vjstat {
u_int vjs_packets; /* outbound packets */
u_int vjs_compressed; /* outbound compressed packets */
u_int vjs_searches; /* searches for connection state */
u_int vjs_misses; /* times couldn't find conn. state */
u_int vjs_uncompressedin; /* inbound uncompressed packets */
u_int vjs_compressedin; /* inbound compressed packets */
u_int vjs_errorin; /* inbound unknown type packets */
u_int vjs_tossed; /* inbound packets tossed because of error */
};
struct ppp_stats {
struct pppstat p; /* basic PPP statistics */
struct vjstat vj; /* VJ header compression statistics */
};
struct compstat {
u_int unc_bytes; /* total uncompressed bytes */
u_int unc_packets; /* total uncompressed packets */
u_int comp_bytes; /* compressed bytes */
u_int comp_packets; /* compressed packets */
u_int inc_bytes; /* incompressible bytes */
u_int inc_packets; /* incompressible packets */
u_int ratio; /* recent compression ratio << 8 */
};
struct ppp_comp_stats {
struct compstat c; /* packet compression statistics */
struct compstat d; /* packet decompression statistics */
};
/*
* The following structure records the time in seconds since
* the last NP packet was sent or received.
*/
struct ppp_idle {
time_t xmit_idle; /* time since last NP packet sent */
time_t recv_idle; /* time since last NP packet received */
};
#ifndef __P
#ifdef __STDC__
#define __P(x) x
#else
#define __P(x) ()
#endif
#endif
#endif /* _PPP_DEFS_H_ */

1023
sys/net/ppp_tty.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
/* $NetBSD: slcompress.c,v 1.11 1995/03/28 20:01:15 jtc Exp $ */
/* $NetBSD: slcompress.c,v 1.12 1995/07/04 06:28:28 paulus Exp $ */
/*
* Copyright (c) 1989, 1993, 1994
@ -401,33 +401,68 @@ sl_uncompress_tcp(bufp, len, type, comp)
u_int type;
struct slcompress *comp;
{
u_char *hdr, *cp;
int hlen, vjlen;
return sl_uncompress_tcp_part(bufp, len, len, type, comp);
cp = bufp? *bufp: NULL;
vjlen = sl_uncompress_tcp_core(cp, len, len, type, comp, &hdr, &hlen);
if (vjlen < 0)
return (0); /* error */
if (vjlen == 0)
return (len); /* was uncompressed already */
cp += vjlen;
len -= vjlen;
/*
* At this point, cp points to the first byte of data in the
* packet. If we're not aligned on a 4-byte boundary, copy the
* data down so the ip & tcp headers will be aligned. Then back up
* cp by the tcp/ip header length to make room for the reconstructed
* header (we assume the packet we were handed has enough space to
* prepend 128 bytes of header).
*/
if ((int)cp & 3) {
if (len > 0)
(void) ovbcopy(cp, (caddr_t)((int)cp &~ 3), len);
cp = (u_char *)((int)cp &~ 3);
}
cp -= hlen;
len += hlen;
BCOPY(hdr, cp, hlen);
*bufp = cp;
return (len);
}
/*
* Uncompress a packet of total length total_len. The first buflen
* bytes are at *bufp; this must include the entire (compressed or
* uncompressed) TCP/IP header. In addition, there must be enough
* clear space before *bufp to build a full-length TCP/IP header.
* bytes are at buf; this must include the entire (compressed or
* uncompressed) TCP/IP header. This procedure returns the length
* of the VJ header, with a pointer to the uncompressed IP header
* in *hdrp and its length in *hlenp.
*/
int
sl_uncompress_tcp_part(bufp, buflen, total_len, type, comp)
u_char **bufp;
sl_uncompress_tcp_core(buf, buflen, total_len, type, comp, hdrp, hlenp)
u_char *buf;
int buflen, total_len;
u_int type;
struct slcompress *comp;
u_char **hdrp;
u_int *hlenp;
{
register u_char *cp;
register u_int hlen, changes;
register struct tcphdr *th;
register struct cstate *cs;
register struct ip *ip;
register u_int16_t *bp;
register u_int vjlen;
switch (type) {
case TYPE_UNCOMPRESSED_TCP:
ip = (struct ip *) *bufp;
ip = (struct ip *) buf;
if (ip->ip_p >= MAX_STATES)
goto bad;
cs = &comp->rstate[comp->last_recv = ip->ip_p];
@ -437,10 +472,11 @@ sl_uncompress_tcp_part(bufp, buflen, total_len, type, comp)
hlen += ((struct tcphdr *)&((int32_t *)ip)[hlen])->th_off;
hlen <<= 2;
BCOPY(ip, &cs->cs_ip, hlen);
cs->cs_ip.ip_sum = 0;
cs->cs_hlen = hlen;
INCR(sls_uncompressedin)
return (total_len);
*hdrp = (u_char *) &cs->cs_ip;
*hlenp = hlen;
return (0);
default:
goto bad;
@ -450,7 +486,7 @@ sl_uncompress_tcp_part(bufp, buflen, total_len, type, comp)
}
/* We've got a compressed packet. */
INCR(sls_compressedin)
cp = *bufp;
cp = buf;
changes = *cp++;
if (changes & NEW_C) {
/* Make sure the state index is in range, then grab the state.
@ -466,7 +502,7 @@ sl_uncompress_tcp_part(bufp, buflen, total_len, type, comp)
* explicit state index, we have to toss the packet. */
if (comp->flags & SLF_TOSS) {
INCR(sls_tossed)
return (0);
return (-1);
}
}
cs = &comp->rstate[comp->last_recv];
@ -514,43 +550,34 @@ sl_uncompress_tcp_part(bufp, buflen, total_len, type, comp)
/*
* At this point, cp points to the first byte of data in the
* packet. If we're not aligned on a 4-byte boundary, copy the
* data down so the ip & tcp headers will be aligned. Then back up
* cp by the tcp/ip header length to make room for the reconstructed
* header (we assume the packet we were handed has enough space to
* prepend 128 bytes of header). Adjust the length to account for
* the new header & fill in the IP total length.
* packet. Fill in the IP total length and update the IP
* header checksum.
*/
buflen -= (cp - *bufp);
total_len -= (cp - *bufp);
vjlen = cp - buf;
buflen -= vjlen;
if (buflen < 0)
/* we must have dropped some characters (crc should detect
* this but the old slip framing won't) */
goto bad;
if ((long)cp & 3) {
if (buflen > 0)
(void) ovbcopy(cp, (caddr_t)((long)cp &~ 3), buflen);
cp = (u_char *)((long)cp &~ 3);
}
cp -= cs->cs_hlen;
total_len += cs->cs_hlen;
total_len += cs->cs_hlen - vjlen;
cs->cs_ip.ip_len = htons(total_len);
BCOPY(&cs->cs_ip, cp, cs->cs_hlen);
*bufp = cp;
/* recompute the ip header checksum */
{
register u_int16_t *bp = (u_int16_t *)cp;
bp = (u_int16_t *) &cs->cs_ip;
cs->cs_ip.ip_sum = 0;
for (changes = 0; hlen > 0; hlen -= 2)
changes += *bp++;
changes = (changes & 0xffff) + (changes >> 16);
changes = (changes & 0xffff) + (changes >> 16);
((struct ip *)cp)->ip_sum = ~ changes;
}
return (total_len);
cs->cs_ip.ip_sum = ~ changes;
*hdrp = (u_char *) &cs->cs_ip;
*hlenp = cs->cs_hlen;
return vjlen;
bad:
comp->flags |= SLF_TOSS;
INCR(sls_errorin)
return (0);
return (-1);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: slcompress.h,v 1.8 1994/06/29 06:36:51 cgd Exp $ */
/* $NetBSD: slcompress.h,v 1.9 1995/07/04 06:28:29 paulus Exp $ */
/*
* Copyright (c) 1989, 1993
@ -118,7 +118,7 @@
*/
struct cstate {
struct cstate *cs_next; /* next most recently used cstate (xmit only) */
u_short cs_hlen; /* size of hdr (receive only) */
u_int16_t cs_hlen; /* size of hdr (receive only) */
u_char cs_id; /* connection # associated with this state */
u_char cs_filler;
union {
@ -137,7 +137,7 @@ struct slcompress {
struct cstate *last_cs; /* most recently used tstate */
u_char last_recv; /* last rcvd conn. id */
u_char last_xmit; /* last sent conn. id */
u_short flags;
u_int16_t flags;
#ifndef SL_NO_STATS
int sls_packets; /* outbound packets */
int sls_compressed; /* outbound compressed packets */
@ -158,5 +158,5 @@ void sl_compress_init __P((struct slcompress *, int));
u_int sl_compress_tcp __P((struct mbuf *,
struct ip *, struct slcompress *, int));
int sl_uncompress_tcp __P((u_char **, int, u_int, struct slcompress *));
int sl_uncompress_tcp_part __P((u_char **, int, int, u_int,
struct slcompress *));
int sl_uncompress_tcp_core __P((u_char *, int, int, u_int,
struct slcompress *, u_char **, u_int *));