+++ /dev/null
-/* From: NetBSD: bpf.h,v 1.12 1995/09/27 18:30:40 thorpej Exp */
-
-/*
- * Copyright (c) 1990, 1991, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from the Stanford/CMU enet packet filter,
- * (net/enet.c) distributed as part of 4.3BSD, and code contributed
- * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
- * Berkeley Laboratory.
- *
- * 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.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
- *
- * @(#)bpf.h 8.1 (Berkeley) 6/10/93
- */
-
-#ifndef _NET_BPF_H_
-#define _NET_BPF_H_
-
-/*
- * Alignment macros. BPF_WORDALIGN rounds up to the next
- * even multiple of BPF_ALIGNMENT.
- */
-#define BPF_ALIGNMENT sizeof(long)
-#define BPF_WORDALIGN(x) (((x)+(BPF_ALIGNMENT-1))&~(BPF_ALIGNMENT-1))
-
-#define BPF_MAXINSNS 512
-#define BPF_MAXBUFSIZE 0x8000
-#define BPF_MINBUFSIZE 32
-
-/*
- * Structure for BIOCSETF.
- */
-struct bpf_program {
- unsigned int bf_len;
- struct bpf_insn *bf_insns;
-};
-
-/*
- * The instruction encondings.
- */
-/* instruction classes */
-#define BPF_CLASS(code) ((code) & 0x07)
-#define BPF_LD 0x00
-#define BPF_LDX 0x01
-#define BPF_ST 0x02
-#define BPF_STX 0x03
-#define BPF_ALU 0x04
-#define BPF_JMP 0x05
-#define BPF_RET 0x06
-#define BPF_MISC 0x07
-
-/* ld/ldx fields */
-#define BPF_SIZE(code) ((code) & 0x18)
-#define BPF_W 0x00
-#define BPF_H 0x08
-#define BPF_B 0x10
-#define BPF_MODE(code) ((code) & 0xe0)
-#define BPF_IMM 0x00
-#define BPF_ABS 0x20
-#define BPF_IND 0x40
-#define BPF_MEM 0x60
-#define BPF_LEN 0x80
-#define BPF_MSH 0xa0
-
-/* alu/jmp fields */
-#define BPF_OP(code) ((code) & 0xf0)
-#define BPF_ADD 0x00
-#define BPF_SUB 0x10
-#define BPF_MUL 0x20
-#define BPF_DIV 0x30
-#define BPF_OR 0x40
-#define BPF_AND 0x50
-#define BPF_LSH 0x60
-#define BPF_RSH 0x70
-#define BPF_NEG 0x80
-#define BPF_JA 0x00
-#define BPF_JEQ 0x10
-#define BPF_JGT 0x20
-#define BPF_JGE 0x30
-#define BPF_JSET 0x40
-#define BPF_SRC(code) ((code) & 0x08)
-#define BPF_K 0x00
-#define BPF_X 0x08
-
-/* ret - BPF_K and BPF_X also apply */
-#define BPF_RVAL(code) ((code) & 0x18)
-#define BPF_A 0x10
-
-/* misc */
-#define BPF_MISCOP(code) ((code) & 0xf8)
-#define BPF_TAX 0x00
-#define BPF_TXA 0x80
-
-/*
- * The instruction data structure.
- */
-struct bpf_insn {
- unsigned short code;
- unsigned char jt;
- unsigned char jf;
- int k;
-};
-
-/*
- * Macros for insn array initializers.
- */
-#define BPF_STMT(code, k) { (unsigned short)(code), 0, 0, k }
-#define BPF_JUMP(code, k, jt, jf) { (unsigned short)(code), jt, jf, k }
-
-#ifdef _KERNEL
-int bpf_validate __P((struct bpf_insn *, int));
-u_int bpf_filter __P((struct bpf_insn *, u_char *, u_int, u_int));
-#endif
-
-/*
- * Number of scratch memory words (for BPF_LD|BPF_MEM and BPF_ST).
- */
-#define BPF_MEMWORDS 16
-
-#endif /* _NET_BPF_H_ */
+++ /dev/null
-/*
- ppp_str.h - streams version include file
-
- Copyright (C) 1990 Brad K. Clements, All Rights Reserved,
- See copyright statement in NOTES
-*/
-
-/*
- * Packet sizes
- */
-#define PPP_MTU 1500 /* Default MTU (size of Info field) */
-#define PPP_MAXMRU 65000 /* Largest MRU we allow */
-
-/*
- * Definitions for ioctls.
- */
-struct npioctl {
- int protocol; /* PPP procotol, e.g. PPP_IP */
- enum NPmode mode;
-};
-
-/* Structure describing a CCP configuration option, for SIOCSCOMPRESS */
-#define MAX_PPP_OPTION 32
-struct ppp_option_data {
- u_int length;
- int transmit;
- u_char opt_data[MAX_PPP_OPTION];
-};
-
-struct ifpppstatsreq {
- char ifr_name[IFNAMSIZ];
- struct ppp_stats stats;
-};
-
-struct ifpppcstatsreq {
- char ifr_name[IFNAMSIZ];
- struct ppp_comp_stats stats;
-};
-
-/*
- * Ioctl definitions.
- */
-
-#if defined(__STDC__) || defined(__osf__)
-#define SIOCSIFCOMPAC _IOW('p', 130, char)
-#define SIOCSIFCOMPPROT _IOW('p', 131, char)
-#define SIOCSIFMRU _IOW('p', 132, int) /* set max receive unit */
-#define SIOCGIFMRU _IOR('p', 133, int) /* get max receive unit */
-#define SIOCGIFASYNCMAP _IOR('p', 134, u_int32_t) /* get transmit async map */
-#define SIOCSIFASYNCMAP _IOW('p', 135, u_int32_t) /* set transmit async map */
-#define SIOCGETU _IOR('p', 136, int) /* get unit number */
-#define SIOCSIFVJCOMP _IOW('p', 137, char) /* enable/disable VJ comp */
-#define SIOCGIFDEBUG _IOR('p', 138, int) /* get debug flags */
-#define SIOCSIFDEBUG _IOW('p', 139, int) /* set debug flags */
-#define SIOCGIFRASYNCMAP _IOR('p', 140, u_int32_t) /* get receive async map */
-#define SIOCSIFRASYNCMAP _IOW('p', 141, u_int32_t) /* set receive async map */
-#define SIOCGIFXASYNCMAP _IOR('p', 142, ext_accm) /* get extended xmit map */
-#define SIOCSIFXASYNCMAP _IOW('p', 143, ext_accm) /* set extended xmit map */
-#define SIOCSETU _IOW('p', 144, int) /* set unit number */
-#define SIOCSETNPMODE _IOW('p', 145, struct npioctl) /* set NP mode */
-#define SIOCGETNPMODE _IOWR('p', 146, struct npioctl) /* get NP mode */
-#define SIOCGIFCOMP _IOR('p', 148, int) /* get CCP kernel flags */
-#define SIOCSIFCOMP _IOW('p', 149, int) /* set CCP closed/open/up */
-#define SIOCSCOMPRESS _IOW('p', 150, struct ppp_option_data)
-
-#define SIOCGPPPSTATS _IOWR('i', 123, struct ifpppstatsreq)
-#define SIOCGPPPCSTATS _IOWR('i', 124, struct ifpppcstatsreq)
-
-#else
-/* traditional C compiler */
-#define SIOCSIFCOMPAC _IOW(p, 130, char)
-#define SIOCSIFCOMPPROT _IOW(p, 131, char)
-#define SIOCSIFMRU _IOW(p, 132, int) /* set max receive unit */
-#define SIOCGIFMRU _IOR(p, 133, int) /* get max receive unit */
-#define SIOCGIFASYNCMAP _IOR(p, 134, u_int32_t) /* get transmit async map */
-#define SIOCSIFASYNCMAP _IOW(p, 135, u_int32_t) /* set transmit async map */
-#define SIOCGETU _IOR(p, 136, int) /* get unit number */
-#define SIOCSIFVJCOMP _IOW(p, 137, char) /* enable/disable VJ comp */
-#define SIOCGIFDEBUG _IOR(p, 138, int) /* get debug flags */
-#define SIOCSIFDEBUG _IOW(p, 139, int) /* set debug flags */
-#define SIOCGIFRASYNCMAP _IOR(p, 140, u_int32_t) /* get receive async map */
-#define SIOCSIFRASYNCMAP _IOW(p, 141, u_int32_t) /* set receive async map */
-#define SIOCGIFXASYNCMAP _IOR(p, 142, ext_accm) /* get extended xmit map */
-#define SIOCSIFXASYNCMAP _IOW(p, 143, ext_accm) /* set extended xmit map */
-#define SIOCSETU _IOW(p, 144, int) /* set unit number */
-#define SIOCSETNPMODE _IOW(p, 145, struct npioctl) /* set NP mode */
-#define SIOCGETNPMODE _IOWR(p, 146, struct npioctl) /* get NP mode */
-#define SIOCGIFCOMP _IOR(p, 148, int) /* get CCP kernel flags */
-#define SIOCSIFCOMP _IOW(p, 149, int) /* set CCP closed/open/up */
-#define SIOCSCOMPRESS _IOW(p, 150, struct ppp_option_data)
-
-#define SIOCGPPPSTATS _IOWR(i, 123, struct ifpppstatsreq)
-#define SIOCGPPPCSTATS _IOWR(i, 124, struct ifpppcstatsreq)
-#endif
-
-/*
- * Note on SIOCSIFVJCOMP: the parameter is now encoded as follows.
- * Bit 0 = overall VJ enable, bit 1 = don't compress connection ID,
- * bit 2 = receiver rejects VJ compression,
- * bits 4--7 = maximum slot ID (0 => use default (15)).
- */
-
-/* Bits for SIOCGIFDEBUG */
-#define PAI_FLAGS_B7_0 0x100
-#define PAI_FLAGS_B7_1 0x200
-#define PAI_FLAGS_PAR_EVEN 0x400
-#define PAI_FLAGS_PAR_ODD 0x800
-#define PAI_FLAGS_HIBITS 0xF00
-
-/* Bit definitions for SIOC[GS]IFCOMP. */
-#define CCP_ISOPEN 1
-#define CCP_ISUP 2
-#define CCP_COMP_RUN 4
-#define CCP_DECOMP_RUN 8
-#define CCP_ERROR 0x10
-#define CCP_FATALERROR 0x20
-
-/* defines for streams modules */
-#define IF_INPUT_ERROR 0xe1
-#define IF_OUTPUT_ERROR 0xe2
-#define IF_GET_CSTATS 0xe3
-#define IF_CSTATS 0xe4
+++ /dev/null
-/*
- ppp_async.c - Streams async functions Also does FCS
-
- Copyright (C) 1990 Brad K. Clements, All Rights Reserved
- fcstab and some ideas nicked from if_ppp.c from cmu.
- See copyright notice in if_ppp.h and NOTES
-
- $Id: ppp_async.c,v 1.1 1995/12/18 23:45:07 paulus Exp $
-*/
-
-/*
- * This file is used under SunOS 4.x, and OSF/1 on DEC Alpha.
- *
- * Beware that under OSF/1, the ioctl constants (SIOC*) end up
- * as 64-bit (long) values, so an ioctl constant should be cast to
- * int (32 bits) before being compared with the ioc_cmd field of
- * an iocblk structure.
- */
-
-#include <sys/types.h>
-
-#ifndef PPP_VD
-#include "ppp.h"
-#endif
-
-#if NPPP > 0
-
-#define STREAMS 1
-#define DEBUGS 1
-#include <sys/param.h>
-#include <sys/stream.h>
-#include <sys/stropts.h>
-#include <sys/dir.h>
-#include <sys/signal.h>
-#include <sys/user.h>
-#include <sys/mbuf.h>
-#include <sys/socket.h>
-#include <net/if.h>
-#include <netinet/in.h>
-
-#ifdef __osf__
-#include <sys/proc.h>
-#define NOTSUSER (suser(u.u_procp->p_rcred, &u.u_acflag))
-#else
-#define NOTSUSER (!suser())
-#endif
-
-#include <net/ppp_defs.h>
-#include <net/ppp_str.h>
-
-/* how big of a buffer block to allocate for each chunk of the input chain */
-#define ALLOCBSIZE 64
-
-#ifdef DEBUGS
-#include <sys/syslog.h>
-#define DLOG(s,a) if (p->pai_flags&PAI_FLAGS_DEBUG) log(LOG_DEBUG, s, a)
-
-int ppp_async_max_dump_bytes = 28;
-#define MAX_DUMP_BYTES 1504
-
-static void ppp_dump_frame();
-
-#else
-#define DLOG(s) {}
-#endif
-
-static int ppp_async_open(), ppp_async_close(), ppp_async_rput(),
- ppp_async_wput(), ppp_async_wsrv(), ppp_async_rsrv();
-
-static struct module_info minfo ={
- 0xabcd,"ppp_async",0, INFPSZ, 16384, 4096
-};
-
-static struct qinit r_init = {
- ppp_async_rput, ppp_async_rsrv, ppp_async_open, ppp_async_close,
- NULL, &minfo, NULL
-};
-static struct qinit w_init = {
- ppp_async_wput, ppp_async_wsrv, ppp_async_open, ppp_async_close,
- NULL, &minfo, NULL
-};
-struct streamtab ppp_asyncinfo = {
- &r_init, &w_init, NULL, NULL,
-};
-
-/*
- * FCS lookup table as calculated by genfcstab.
- */
-static u_short fcstab[256] = {
- 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
- 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
- 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
- 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
- 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
- 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
- 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
- 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
- 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
- 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
- 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
- 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
- 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
- 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
- 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
- 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
- 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
- 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
- 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
- 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
- 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
- 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
- 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
- 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
- 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
- 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
- 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
- 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
- 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
- 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
- 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
- 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
-};
-
-
-struct ppp_async_info {
- u_int pai_flags;
- int pai_buffsize; /* how big of an input buffer to alloc */
- int pai_buffcount; /* how many chars currently in input buffer */
- u_short pai_fcs; /* the current fcs */
- mblk_t *pai_buffer; /* pointer to the current buffer list */
- mblk_t *pai_bufftail; /* pointer to the current input block */
- ext_accm pai_asyncmap; /* current outgoing asyncmap */
- u_int32_t pai_rasyncmap; /* current receive asyncmap */
-};
-
-/* Values for pai_flags */
-#define PAI_FLAGS_INUSE 0x1
-#define PAI_FLAGS_FLUSH 0x2
-#define PAI_FLAGS_ESCAPED 0x4
-#define PAI_FLAGS_COMPPROT 0x8
-#define PAI_FLAGS_COMPAC 0x10
-#define PAI_FLAGS_RCV_COMPPROT 0x20
-#define PAI_FLAGS_RCV_COMPAC 0x40
-
-#define PAI_FLAGS_DEBUG 0x1000
-#define PAI_FLAGS_LOG_INPKT 0x2000
-#define PAI_FLAGS_LOG_OUTPKT 0x4000
-#define PAI_FLAGS_ALL_DEBUG 0x7000
-
-typedef struct ppp_async_info PAI;
-
-static PAI pai[NPPP*2]; /* our private cache of async ctrl structs */
-
-/* open might fail if we don't have any more pai elements left free */
-static int
-ppp_async_open(q, dev, flag, sflag)
- queue_t *q;
- dev_t dev;
- int flag;
- int sflag;
-{
- register PAI *p;
- register int x;
- int s;
-
- /* only let the superuser or setuid root ppl open this module */
- if (NOTSUSER) {
- u.u_error = EPERM;
- return (OPENFAIL);
- }
-
- s = splstr();
- if (!q->q_ptr) {
- for (x=0; x < NPPP; x++) /* search for an empty PAI */
- if (!(pai[x].pai_flags & PAI_FLAGS_INUSE))
- break;
- if (x == NPPP) { /* all buffers in use */
- splx(s); /* restore processor state */
- u.u_error = ENOBUFS;
- return (OPENFAIL);
- }
- p = &pai[x];
- DLOG("ppp_async%d: opening\n",x);
-
- /* initialize the unit to default values */
- WR(q)->q_ptr = q->q_ptr = (caddr_t) p;
- bzero(p, sizeof(*p));
- p->pai_flags = PAI_FLAGS_INUSE | PAI_FLAGS_RCV_COMPAC
- | PAI_FLAGS_RCV_COMPPROT;
- p->pai_asyncmap[0] = 0xffffffff; /* default async map */
- p->pai_asyncmap[3] = 0x60000000; /* escape 7d, 7e */
- p->pai_buffsize = PPP_MTU + PPP_HDRLEN + PPP_FCSLEN;
- }
- else {
- p = (PAI *) q->q_ptr;
- DLOG("ppp_async%d: reopen\n", p - pai);
- }
-
- splx(s);
- return(0);
-}
-
-static int
-ppp_async_close(q)
- queue_t *q; /* queue info */
-{
- int s;
- register PAI *p;
-
- s = splstr();
- if ((p = (PAI *) q->q_ptr) != NULL) {
- p->pai_flags = 0; /* clear all flags */
- if (p->pai_buffer) {
- /* currently receiving some chars, discard the buffer */
- freemsg(p->pai_buffer);
- p->pai_buffer = NULL;
- }
- DLOG("ppp_async%d: closing\n", p - pai);
- }
- splx(s);
- return(0);
-}
-
-
-/* M_IOCTL processing is performed at this level. There is some
- weirdness here, but I couldn't think of an easier way to handle it.
-
- SIOC{G,S}IF{,R,X}ASYNCMAP are handled here.
-
- SIOCSIFCOMPAC and SIOCSIFCOMPPROT are both handled here.
-
- SIOCSIFMRU and SIOCGIFMRU (Max Receive Unit) are both handled here.
- Rather than using the MTU to set the MRU, we have a seperate IOCTL for it.
-*/
-
-static int
-ppp_async_wput(q, mp)
- queue_t *q;
- register mblk_t *mp;
-{
- register struct iocblk *i;
- register PAI *p;
- int x, flags;
-
- switch (mp->b_datap->db_type) {
-
- case M_CTL:
- switch (*(u_char *)mp->b_rptr) {
- case IF_GET_CSTATS:
- /* trap this and remove it */
- freemsg(mp);
- break;
- default:
- putnext(q, mp);
- }
- break;
-
- case M_FLUSH :
- if (*mp->b_rptr & FLUSHW)
- flushq(q, FLUSHDATA);
- putnext(q, mp); /* send it along too */
- break;
-
- case M_DATA :
- putq(q, mp); /* queue it for my service routine */
- break;
-
- case M_IOCTL :
- i = (struct iocblk *) mp->b_rptr;
- p = (PAI *) q->q_ptr;
- switch (i->ioc_cmd) {
-
- case SIOCSIFCOMPAC : /* enable or disable AC compression */
- if (i->ioc_count != sizeof(u_char)) {
- i->ioc_error = EINVAL;
- goto iocnak;
- }
- x = *(u_char *) mp->b_cont->b_rptr;
- DLOG("ppp_async: SIFCOMPAC %d\n", x);
- flags = (x & 2)? PAI_FLAGS_RCV_COMPAC: PAI_FLAGS_COMPAC;
- if (x & 1)
- p->pai_flags |= flags;
- else
- p->pai_flags &= ~flags;
- i->ioc_count = 0;
- goto iocack;
-
- case SIOCSIFCOMPPROT: /* enable or disable PROT compression */
- if (i->ioc_count != sizeof(u_char)) {
- i->ioc_error = EINVAL;
- goto iocnak;
- }
- x = *(u_char *) mp->b_cont->b_rptr;
- DLOG("ppp_async: SIFCOMPPROT %d\n", x);
- flags = (x & 2)? PAI_FLAGS_RCV_COMPPROT: PAI_FLAGS_COMPPROT;
- if (x & 1)
- p->pai_flags |= flags;
- else
- p->pai_flags &= ~flags;
- i->ioc_count = 0;
- goto iocack;
-
-
- case SIOCSIFMRU :
- if (i->ioc_count != sizeof(int)) {
- i->ioc_error = EINVAL;
- goto iocnak;
- }
- x = *(int *) mp->b_cont->b_rptr;
- if (x < PPP_MTU)
- x = PPP_MTU;
- x += PPP_HDRLEN + PPP_FCSLEN;
- if (x > 4096) { /* couldn't allocb something this big */
- i->ioc_error = EINVAL;
- goto iocnak;
- }
- p->pai_buffsize = x;
- i->ioc_count = 0;
- goto iocack;
-
- case SIOCGIFMRU :
- if ((mp->b_cont = allocb(sizeof(int), BPRI_MED)) != NULL) {
- *(int *) mp->b_cont->b_wptr =
- p->pai_buffsize - (PPP_HDRLEN + PPP_FCSLEN);
- mp->b_cont->b_wptr += i->ioc_count = sizeof(int);
- goto iocack;
- }
- i->ioc_error = ENOSR;
- goto iocnak;
-
- case SIOCGIFASYNCMAP :
- if ((mp->b_cont = allocb(sizeof(u_int32_t), BPRI_MED)) != NULL) {
- *(u_int32_t *) mp->b_cont->b_wptr = p->pai_asyncmap[0];
- mp->b_cont->b_wptr += i->ioc_count = sizeof(u_int32_t);
- goto iocack;
- }
- i->ioc_error = ENOSR;
- goto iocnak;
-
- case SIOCSIFASYNCMAP :
- if (i->ioc_count != sizeof(u_int32_t)) {
- i->ioc_error = EINVAL;
- goto iocnak; /* ugh, goto */
- }
- p->pai_asyncmap[0] = *(u_int32_t *) mp->b_cont->b_rptr;
- DLOG("ppp_async: SIFASYNCMAP %lx\n", p->pai_asyncmap[0]);
- i->ioc_count = 0;
- goto iocack;
-
- case SIOCGIFRASYNCMAP :
- if ((mp->b_cont = allocb(sizeof(u_int32_t), BPRI_MED)) != NULL) {
- *(u_int32_t *) mp->b_cont->b_wptr = p->pai_rasyncmap;
- mp->b_cont->b_wptr += i->ioc_count = sizeof(u_int32_t);
- goto iocack;
- }
- i->ioc_error = ENOSR;
- goto iocnak;
-
- case SIOCSIFRASYNCMAP :
- if (i->ioc_count != sizeof(u_int32_t)) {
- i->ioc_error = EINVAL;
- goto iocnak; /* ugh, goto */
- }
- p->pai_rasyncmap = *(u_int32_t *) mp->b_cont->b_rptr;
- DLOG("ppp_async: SIFRASYNCMAP %lx\n", p->pai_rasyncmap);
- i->ioc_count = 0;
- goto iocack;
-
- case SIOCGIFXASYNCMAP :
- if ((mp->b_cont = allocb(sizeof(ext_accm), BPRI_MED)) != NULL) {
- bcopy(p->pai_asyncmap, mp->b_cont->b_wptr, sizeof(ext_accm));
- mp->b_cont->b_wptr += i->ioc_count = sizeof(ext_accm);
- goto iocack;
- }
- i->ioc_error = ENOSR;
- goto iocnak;
-
- case SIOCSIFXASYNCMAP :
- if (i->ioc_count != sizeof(ext_accm)) {
- i->ioc_error = EINVAL;
- goto iocnak; /* ugh, goto */
- }
- bcopy(mp->b_cont->b_rptr, p->pai_asyncmap, sizeof(ext_accm));
- p->pai_asyncmap[1] = 0; /* can't escape 20-3f */
- p->pai_asyncmap[2] &= ~0x40000000; /* can't escape 5e */
- p->pai_asyncmap[3] |= 0x60000000; /* must escape 7d, 7e */
- i->ioc_count = 0;
- goto iocack;
-
- case SIOCGIFDEBUG :
- if ((mp->b_cont = allocb(sizeof(int), BPRI_MED)) != NULL) {
- *(int *)mp->b_cont->b_wptr =
- (unsigned)(p->pai_flags & PAI_FLAGS_ALL_DEBUG)
- / PAI_FLAGS_DEBUG |
- (p->pai_flags & PAI_FLAGS_HIBITS);
- mp->b_cont->b_wptr += i->ioc_count = sizeof(int);
- goto iocack;
- }
- i->ioc_error = ENOSR;
- goto iocnak;
-
- case SIOCSIFDEBUG :
- if(i->ioc_count != sizeof(int)) {
- i->ioc_error = EINVAL;
- goto iocnak; /* ugh, goto */
- }
- flags = *(int *)mp->b_cont->b_rptr;
- DLOG("ppp_async: SIFIFDEBUG %x\n", flags);
- p->pai_flags &= ~PAI_FLAGS_ALL_DEBUG | PAI_FLAGS_HIBITS;
- p->pai_flags |= ((unsigned) flags * PAI_FLAGS_DEBUG)
- & PAI_FLAGS_ALL_DEBUG;
- i->ioc_count = 0;
- goto iocack;
-
- iocack:;
- mp->b_datap->db_type = M_IOCACK;
- qreply(q,mp);
- break;
- iocnak:;
- i->ioc_count = 0;
- mp->b_datap->db_type = M_IOCNAK;
- qreply(q, mp);
- break;
- default: /* unknown IOCTL call */
- putnext(q,mp); /* pass it along */
- }
- break;
-
- default:
- putnext(q, mp); /* don't know what to do with this, so send it along*/
- }
-}
-
-static int
-ppp_async_wsrv(q)
- queue_t *q;
-{
- register u_char *cp, *wp;
- register PAI *p;
- register u_short fcs;
- register mblk_t *mp, *m0;
- mblk_t *cop, *outgoing;
- int proto, len, olen, c;
-
- p = (PAI *) q->q_ptr;
-
- while ((mp = getq(q)) != NULL) {
- /*
- * we can only get M_DATA types into our Queue,
- * due to our Put function
- */
- if (!canput(q->q_next)) {
- putbq(q, mp);
- return;
- }
-
- /* at least a header required */
- len = msgdsize(mp);
- if (len < PPP_HDRLEN
- || (mp->b_wptr - mp->b_rptr < PPP_HDRLEN
- && !pullupmsg(mp, PPP_HDRLEN))) {
- freemsg(mp); /* discard the message */
- DLOG("ppp_async: short message (%d)\n", len);
- /* indicate output err */
- putctl1(OTHERQ(q), M_CTL, IF_OUTPUT_ERROR);
- continue;
- }
-
- /* Do address/control and protocol compression */
- proto = (mp->b_rptr[2] << 8) + mp->b_rptr[3];
- if (p->pai_flags & PAI_FLAGS_COMPAC && proto != PPP_LCP
- && mp->b_rptr[0] == PPP_ALLSTATIONS && mp->b_rptr[1] == PPP_UI) {
- mp->b_rptr += 2;
- if (p->pai_flags & PAI_FLAGS_COMPPROT && proto < 0xff)
- ++mp->b_rptr;
- } else if (p->pai_flags & PAI_FLAGS_COMPPROT && proto < 0xff) {
- mp->b_rptr[2] = mp->b_rptr[1];
- mp->b_rptr[1] = mp->b_rptr[0];
- ++mp->b_rptr;
- }
-
- m0 = mp; /* remember first message block */
- fcs = PPP_INITFCS;
-
- /*
- * Estimate the required buffer length as 1.25 * message length
- * to allow for escaped characters. If this isn't enough, we
- * allocate another buffer later.
- */
- olen = len + (len >> 2) + 5;
- if (olen < 32)
- olen = 32;
- else if (olen > 2048)
- olen = 2048;
- outgoing = cop = allocb(olen, BPRI_MED);
- if (outgoing == NULL) {
- DLOG("allocb(%d) failed!\n", olen);
- /* should do something tricky here */
- goto nobuffs;
- }
- wp = cop->b_wptr;
-
- /* Put the initial flag in (we'll take it out later if we don't
- need it). */
- *wp++ = PPP_FLAG;
- --olen;
-
-#define SPECIAL(p, c) (p->pai_asyncmap[(c) >> 5] & (1 << ((c) & 0x1F)))
-
- /*
- * Copy the message to the output block, escaping characters
- * as needed.
- */
- while (mp) {
- for (cp = mp->b_rptr; cp < mp->b_wptr; ) {
- c = *cp++;
- if (olen < 2) {
- /* grab another message block and put it on the end */
- cop->b_wptr = wp;
- olen = 256;
- cop = allocb(olen, BPRI_MED);
- if (cop == NULL)
- goto nobuffs;
- linkb(outgoing, cop);
- wp = cop->b_wptr;
- }
- if (SPECIAL(p, c)) {
- *wp++ = PPP_ESCAPE;
- *wp++ = c ^ PPP_TRANS;
- olen -= 2;
- } else {
- *wp++ = c;
- --olen;
- }
- fcs = PPP_FCS(fcs, c);
- }
- mp = mp->b_cont; /* look at the next block */
- } /* end while(mp) */
-
- /*
- * Add the FCS and the trailing flag.
- */
- if (olen < 5) {
- /* grab another message block for FCS and trailing flag */
- cop->b_wptr = wp;
- cop = allocb(5, BPRI_MED);
- if (cop == NULL)
- goto nobuffs;
- linkb(outgoing, cop);
- wp = cop->b_wptr;
- }
- fcs ^= 0xffff; /* XOR the resulting FCS */
- c = fcs & 0xff;
- if (SPECIAL(p, c)) {
- *wp++ = PPP_ESCAPE;
- *wp++ = c ^ PPP_TRANS;
- } else
- *wp++ = c;
- c = fcs >> 8;
- if (SPECIAL(p, c)) {
- *wp++ = PPP_ESCAPE;
- *wp++ = c ^ PPP_TRANS;
- } else
- *wp++ = c;
- *wp++ = PPP_FLAG; /* add trailing PPP_FLAG */
-
- cop->b_wptr = wp;
- freemsg(m0);
-
- /*
- * now we check to see if the lower queue has entries, if so,
- * we assume that we don't need a leading PPP_FLAG because
- * these packets will be sent back to back.
- */
- if (qsize(q->q_next) > 0) {
- /* entries in next queue, remove the leading PPP_FLAG */
- ++outgoing->b_rptr;
- }
-
-#if DEBUGS
- if (p->pai_flags & PAI_FLAGS_LOG_OUTPKT)
- ppp_dump_frame(p, outgoing, " sent output");
-#endif
- putnext(q, outgoing);
- continue;
-
- nobuffs: /* well, we ran out of memory somewhere */
- if (outgoing)
- freemsg(outgoing); /* throw away what we have already */
- putbq(q, m0); /* put back the original message */
- putctl1(OTHERQ(q), M_CTL, IF_OUTPUT_ERROR);
- qenable(q); /* reschedule ourselves for later */
- return;
- } /* end while(getq()) */
-} /* end function */
-
-static int
-ppp_async_rput(q, mp)
- queue_t *q;
- register mblk_t *mp;
-{
- switch (mp->b_datap->db_type) {
-
- case M_FLUSH:
- if(*mp->b_rptr & FLUSHR)
- flushq(q, FLUSHDATA);
- putnext(q, mp); /* send it along too */
- break;
-
- case M_DATA:
- putq(q, mp); /* queue it for my service routine */
- break;
-
- default:
- putnext(q,mp); /* don't know what to do with this, so send it along */
- }
-}
-
-static u_int32_t paritytab[8] = {
- 0x96696996, 0x69969669, 0x69969669, 0x96696996,
- 0x69969669, 0x96696996, 0x96696996, 0x69969669,
-};
-
-static int
-ppp_async_rsrv(q)
- queue_t *q;
-{
- register mblk_t *mp, *bp;
- register PAI *p;
- register u_char *cp,c;
- mblk_t *m0;
- register u_char *wptr;
- int bcount;
-
- p = (PAI *) q->q_ptr;
-
-#define INPUT_ERROR(q) putctl1(q, M_CTL, IF_INPUT_ERROR)
-#define STUFF_CHAR(p,c) (*wptr++ = (c), (p)->pai_buffcount++)
-#define FLUSHEM(q, p) (INPUT_ERROR(q), (p)->pai_flags |= PAI_FLAGS_FLUSH)
-
- while ((mp = getq(q)) != NULL) {
- /* we can only get M_DATA types into our Queue,
- due to our Put function */
- if (!canput(q->q_next)) {
- putbq(q, mp);
- return;
- }
- m0 = mp; /* remember first message block */
- for (; mp != NULL; mp = mp->b_cont) { /* for each message block */
- cp = mp->b_rptr;
- while (cp < mp->b_wptr) {
- c = *cp++;
-
- /* Accumulate info to help with detecting
- non 8-bit clean links. */
- if (c & 0x80)
- p->pai_flags |= PAI_FLAGS_B7_1;
- else
- p->pai_flags |= PAI_FLAGS_B7_0;
- if (paritytab[c >> 5] & (1 << (c & 0x1F)))
- p->pai_flags |= PAI_FLAGS_PAR_ODD;
- else
- p->pai_flags |= PAI_FLAGS_PAR_EVEN;
-
- /* Throw out chars in the receive asyncmap. */
- if (c < 0x20 && (p->pai_rasyncmap & (1 << c)))
- continue;
-
- /* A flag marks the end of a frame. */
- if (c == PPP_FLAG) {
- bp = p->pai_buffer;
- bcount = p->pai_buffcount;
- p->pai_buffer = NULL;
- p->pai_buffcount = 0;
-
- /* if the escape indicator is set, then we have
- seen the packet abort sequence "}~". */
- if (p->pai_flags & (PAI_FLAGS_ESCAPED | PAI_FLAGS_FLUSH)) {
- if ((p->pai_flags & PAI_FLAGS_FLUSH) == 0)
- DLOG("ppp_async: packet abort\n", 0);
- p->pai_flags &= ~(PAI_FLAGS_ESCAPED | PAI_FLAGS_FLUSH);
- if (bp)
- freemsg(bp);
- continue;
- }
-
- if (bcount > PPP_FCSLEN) { /* discard FCS */
- adjmsg(bp, -PPP_FCSLEN);
- bcount -= PPP_FCSLEN;
- }
-
- if (bcount < PPP_HDRLEN) {
- if (bcount) {
- INPUT_ERROR(q);
- DLOG("ppp_async: short input packet (%d)\n",
- bcount);
- }
- if (bp)
- freemsg(bp);
- continue;
- }
-
- if (bp) {
- if (p->pai_fcs == PPP_GOODFCS) {
-#if DEBUGS
- if (p->pai_flags & PAI_FLAGS_LOG_INPKT)
- ppp_dump_frame(p, bp, " got input");
-#endif /*DEBUGS*/
- putnext(q, bp);
- }
- else {
- INPUT_ERROR(q);
- freemsg(bp);
- DLOG("ppp_async: FCS Error\n", 0);
- }
- }
- continue;
- }
-
- /* here c != PPP_FLAG */
- if (p->pai_flags & PAI_FLAGS_FLUSH) {
- while (cp < mp->b_wptr && *cp != PPP_FLAG)
- ++cp;
- continue;
- }
-
- if (p->pai_flags & PAI_FLAGS_ESCAPED) {
- p->pai_flags &= ~PAI_FLAGS_ESCAPED; /* clear esc flag */
- c ^= PPP_TRANS;
- } else if (c == PPP_ESCAPE) {
- if (cp >= mp->b_wptr || (c = *cp) == PPP_FLAG
- || c < 0x20 && (p->pai_rasyncmap & (1 << c))) {
- p->pai_flags |= PAI_FLAGS_ESCAPED;
- continue;
- }
- c ^= PPP_TRANS;
- ++cp;
- }
-
- /* here we check to see if we have a buffer.
- If we don't, we assume that this is the first char
- for the buffer, and we allocb one */
-
- if (!p->pai_buffer) {
- /* we allocate buffer chains in blocks of ALLOCBSIZE */
-
- if (!(p->pai_buffer = allocb(ALLOCBSIZE, BPRI_MED))) {
- FLUSHEM(q, p);
- continue;
- /* if we don't get a buffer, is there some way
- to recover and requeue later? rather than flushing
- the current packet... ? */
- }
- p->pai_bufftail = p->pai_buffer;
- }
- wptr = p->pai_bufftail->b_wptr;
-
- if (!p->pai_buffcount) {
- p->pai_fcs = PPP_INITFCS;
- if (c != PPP_ALLSTATIONS) {
- if (p->pai_flags & PAI_FLAGS_RCV_COMPAC) {
- STUFF_CHAR(p, PPP_ALLSTATIONS);
- STUFF_CHAR(p, PPP_UI);
- }
- else {
- DLOG("ppp_async: missed ALLSTATIONS (0xff), got 0x%x\n", c);
- FLUSHEM(q, p);
- continue;
- }
- }
- } /* end if !p->pai_buffcount */
-
- if (p->pai_buffcount == 1 && c != PPP_UI) {
- DLOG("ppp_async: missed UI (0x3), got 0x%x\n", c);
- FLUSHEM(q,p);
- continue;
- }
-
- if (p->pai_buffcount == 2 && (c & 1) == 1) {
- if (p->pai_flags & PAI_FLAGS_RCV_COMPPROT)
- STUFF_CHAR(p, 0);
- else {
- DLOG("ppp_async: bad protocol high byte %x\n", c);
- FLUSHEM(q, p);
- continue;
- }
- }
-
- if (p->pai_buffcount == 3 && (c & 1) == 0) {
- DLOG("ppp_async: bad protocol low byte %x\n", c);
- FLUSHEM(q, p);
- continue;
- }
-
- if (p->pai_buffcount >= p->pai_buffsize) { /* overrun */
- DLOG("ppp_async: too many chars in input buffer %d\n",
- p->pai_buffcount);
- FLUSHEM(q, p);
- continue;
- }
-
- /* determine if we have enough space in the buffer */
- if (wptr >= p->pai_bufftail->b_datap->db_lim) {
- p->pai_bufftail->b_wptr = wptr;
- if (!(p->pai_bufftail = allocb(ALLOCBSIZE, BPRI_MED))) {
- DLOG("ppp_async: couldn't get buffer for tail\n", 0);
- FLUSHEM(q, p); /* discard all of it */
- continue;
- }
- linkb(p->pai_buffer, p->pai_bufftail);
- wptr = p->pai_bufftail->b_wptr;
- }
-
- STUFF_CHAR(p, c);
- p->pai_fcs = PPP_FCS(p->pai_fcs, c);
-
- if (p->pai_buffcount >= PPP_HDRLEN) {
- while (cp < mp->b_wptr
- && wptr < p->pai_bufftail->b_datap->db_lim
- && (c = *cp) != PPP_FLAG && c != PPP_ESCAPE) {
- if (c >= 0x20 || (p->pai_rasyncmap & (1 << c)) == 0) {
- STUFF_CHAR(p, c);
- p->pai_fcs = PPP_FCS(p->pai_fcs, c);
- }
- ++cp;
- }
- }
-
- p->pai_bufftail->b_wptr = wptr;
-
- } /* end while cp < wptr */
- } /* end for each block */
- /* discard this message now */
- freemsg(m0);
- } /* end while getq */
-
-}
-
-#if DEBUGS
-/*
- * here is where we will dump out a frame in hex using the log()
- * function if ppp_async_input_debug is non-zero. As this function is
- * a pig, we only print up to the number of bytes specified by the value of
- * the ppp_async_max_dump_bytes variable so as to not cause too many
- * timeouts. <gmc@quotron.com>
- */
-
-static void
-ppp_dump_frame(p, mptr, msg)
- register PAI *p;
- register mblk_t *mptr;
- char *msg;
-{
- register u_char *rptr;
- register u_int i, mlen, frame_length;
- char buf[2*MAX_DUMP_BYTES+4]; /* tmp buffer */
- char *bp = buf;
- static char digits[] = "0123456789abcdef";
-
- frame_length = i = msgdsize(mptr);
- log(LOG_INFO, "ppp_async%d:%s frame of %d bytes\n", p - pai,
- msg, frame_length);
- rptr = mptr->b_rptr; /* get pointer to beginning */
- mlen = mptr->b_wptr - rptr; /* get length of this dblock */
-
- /* only dump up to MAX_DUMP_BYTES */
- if (i > ppp_async_max_dump_bytes)
- i = ppp_async_max_dump_bytes;
-
- while (i--) { /* convert to ascii hex */
- while (mlen == 0) { /* get next dblock */
- mptr = mptr->b_cont;
- if (mptr) { /* are we done? */
- rptr = mptr->b_rptr; /* nope, get next dblock */
- mlen = mptr->b_wptr - rptr;
- }
- else { /* no more dblocks */
- if (i != 0)
- log(LOG_ERR, "ppp_async: ran out of data! (this shouldn't happen\n");
- break;
- }
- }
- --mlen;
- *bp++ = digits[*rptr >> 4]; /* convert byte to ascii hex */
- *bp++ = digits[*rptr++ & 0xf];
- }
-
- /* add a '>' to show that frame was truncated*/
- if (ppp_async_max_dump_bytes < frame_length)
- *bp++ = '>';
- *bp = 0;
- log(LOG_INFO,"ppp_async: %s\n", buf);
-}
-#endif /* DEBUGS */
-
-#endif /* NPPP > 0 */
+++ /dev/null
-/*
- * ppp_comp.c - STREAMS module for kernel-level CCP support.
- *
- * 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.c,v 1.1 1995/12/18 23:45:09 paulus Exp $
- */
-
-/*
- * This file is used under SunOS 4.x, and OSF/1 on DEC Alpha.
- *
- * Beware that under OSF/1, the ioctl constants (SIOC*) end up
- * as 64-bit (long) values, so an ioctl constant should be cast to
- * int (32 bits) before being compared with the ioc_cmd field of
- * an iocblk structure.
- */
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/errno.h>
-#include <sys/user.h>
-#include <sys/stream.h>
-#include <sys/stropts.h>
-#include <sys/syslog.h>
-#include <sys/socket.h>
-#include <net/if.h>
-#include <net/ppp_defs.h>
-#include <net/ppp_str.h>
-
-#ifdef __osf__
-#include <kern/kalloc.h>
-#ifdef FREE
-#undef FREE
-#endif
-#define ALLOCATE(n) kalloc((n))
-#define FREE(p, n) kfree((p), (n))
-#endif
-
-#ifdef sun
-#include <sys/kmem_alloc.h>
-#define ALLOCATE(n) kmem_alloc((n), KMEM_NOSLEEP)
-#define FREE(p, n) kmem_free((p), (n))
-#endif
-
-#define PACKETPTR mblk_t *
-#include <net/ppp-comp.h>
-
-static int ppp_comp_open(), ppp_comp_close();
-static int ppp_comp_rput(), ppp_comp_wput();
-static void ppp_comp_ccp();
-
-static struct module_info minfo = {
- 0xbadf, "ppp_compress", 0, INFPSZ, 16384, 4096,
-};
-
-static struct qinit r_init = {
- ppp_comp_rput, NULL, ppp_comp_open, ppp_comp_close,
- NULL, &minfo, NULL
-};
-
-static struct qinit w_init = {
- ppp_comp_wput, NULL, NULL, NULL, NULL, &minfo, NULL
-};
-
-struct streamtab ppp_compinfo = {
- &r_init, &w_init, NULL, NULL
-};
-
-struct ppp_comp_state {
- int ccp_state;
- int debug;
- int mru;
- struct compressor *xcomp;
- void *xstate;
- struct compressor *rcomp;
- void *rstate;
-};
-
-/* Bits in ccp_state are as defined in ppp_str.h. */
-#define CCP_ERR (CCP_ERROR | CCP_FATALERROR)
-
-/*
- * List of compressors we know about.
- */
-
-extern struct compressor ppp_bsd_compress;
-
-struct compressor *ppp_compressors[] = {
-#if DO_BSD_COMPRESS
- &ppp_bsd_compress,
-#endif
- NULL
-};
-
-static int
-ppp_comp_open(q, dev, flag, sflag)
- queue_t *q;
- dev_t dev;
- int flag;
- int sflag;
-{
- struct ppp_comp_state *cp;
-
- if (q->q_ptr == NULL) {
- cp = (struct ppp_comp_state *) ALLOCATE(sizeof(struct ppp_comp_state));
- if (cp == NULL) {
- u.u_error = ENOSR;
- return OPENFAIL;
- }
- OTHERQ(q)->q_ptr = q->q_ptr = (caddr_t) cp;
- cp->ccp_state = 0;
- cp->debug = 0;
- cp->mru = PPP_MRU;
- cp->xstate = NULL;
- cp->rstate = NULL;
- }
- return 0;
-}
-
-static int
-ppp_comp_close(q)
- queue_t *q;
-{
- struct ppp_comp_state *cp;
-
- cp = (struct ppp_comp_state *) q->q_ptr;
- if (cp != NULL) {
- if (cp->xstate != NULL)
- (*cp->xcomp->comp_free)(cp->xstate);
- if (cp->rstate != NULL)
- (*cp->rcomp->decomp_free)(cp->rstate);
- FREE(cp, sizeof(struct ppp_comp_state));
- q->q_ptr = NULL;
- OTHERQ(q)->q_ptr = NULL;
- }
- return 0;
-}
-
-static int
-ppp_comp_wput(q, mp)
- queue_t *q;
- mblk_t *mp;
-{
- struct iocblk *iop;
- struct ppp_comp_state *cp;
- mblk_t *cmp = NULL;
- int error, len, proto, state;
- struct ppp_option_data *odp;
- struct compressor **comp;
- struct ppp_comp_stats *pcp;
-
- cp = (struct ppp_comp_state *) q->q_ptr;
- switch (mp->b_datap->db_type) {
-
- case M_CTL:
- switch (*(u_char *) mp->b_rptr) {
- case IF_GET_CSTATS:
- freemsg(mp);
- mp = allocb(sizeof(struct ppp_comp_stats) + sizeof(u_long),
- BPRI_HI);
- if (mp != NULL) {
- mp->b_datap->db_type = M_CTL;
- *(u_char *) mp->b_wptr = IF_CSTATS;
- mp->b_wptr += sizeof(u_long); /* should be enough alignment */
- pcp = (struct ppp_comp_stats *) mp->b_wptr;
- mp->b_wptr += sizeof(struct ppp_comp_stats);
- bzero(pcp, sizeof(struct ppp_comp_stats));
- if (cp->xstate != NULL)
- (*cp->xcomp->comp_stat)(cp->xstate, &pcp->c);
- if (cp->rstate != NULL)
- (*cp->rcomp->decomp_stat)(cp->rstate, &pcp->d);
- qreply(q, mp);
- }
- break;
- default:
- putnext(q, mp);
- }
- break;
-
- case M_DATA:
- /* first find out what the protocol is */
- if (mp->b_wptr - mp->b_rptr >= PPP_HDRLEN
- || pullupmsg(mp, PPP_HDRLEN)) {
- proto = PPP_PROTOCOL(mp->b_rptr);
- if (proto == PPP_CCP)
- ppp_comp_ccp(q, mp, 0);
- else if (proto != PPP_LCP && (cp->ccp_state & CCP_COMP_RUN)
- && cp->xstate != NULL) {
- len = msgdsize(mp);
- (*cp->xcomp->compress)(cp->xstate, &cmp, mp, len,
- (cp->ccp_state & CCP_ISUP? len: 0));
- /* XXX we really want the MTU here, not len */
- if (cmp != NULL) {
- freemsg(mp);
- mp = cmp;
- }
- }
- }
- putnext(q, mp);
- break;
-
- case M_IOCTL:
- iop = (struct iocblk *) mp->b_rptr;
- error = -1;
- switch (iop->ioc_cmd) {
-
- case SIOCSIFCOMP:
- /* set CCP state */
- if (iop->ioc_count != sizeof(int)) {
- error = EINVAL;
- break;
- }
- state = (*(int *) mp->b_cont->b_rptr) & (CCP_ISUP | CCP_ISOPEN);
- if ((state & CCP_ISOPEN) == 0) {
- if (cp->xstate != NULL) {
- (*cp->xcomp->comp_free)(cp->xstate);
- cp->xstate = NULL;
- }
- if (cp->rstate != NULL) {
- (*cp->rcomp->decomp_free)(cp->rstate);
- cp->rstate = NULL;
- }
- cp->ccp_state = 0;
- } else {
- cp->ccp_state = (cp->ccp_state & ~CCP_ISUP) | state;
- }
- if (cp->debug)
- log(LOG_DEBUG, "SIOCSIFCOMP %x, state = %x\n",
- *(int *) mp->b_cont->b_rptr, cp->ccp_state);
- error = 0;
- iop->ioc_count = 0;
- break;
-
- case SIOCGIFCOMP:
- if ((mp->b_cont = allocb(sizeof(int), BPRI_MED)) == NULL) {
- error = ENOSR;
- break;
- }
- *(int *)mp->b_cont->b_wptr = cp->ccp_state;
- mp->b_cont->b_wptr += iop->ioc_count = sizeof(int);
- error = 0;
- break;
-
- case SIOCSCOMPRESS:
- error = EINVAL;
- if (iop->ioc_count != sizeof(struct ppp_option_data))
- break;
- odp = (struct ppp_option_data *) mp->b_cont->b_rptr;
- len = mp->b_cont->b_wptr - (unsigned char *) odp->opt_data;
- if (len > odp->length)
- len = odp->length;
- if (odp->opt_data[1] < 2 || odp->opt_data[1] > len)
- break;
- for (comp = ppp_compressors; *comp != NULL; ++comp)
- if ((*comp)->compress_proto == odp->opt_data[0]) {
- /* here's the handler! */
- error = 0;
- if (odp->transmit) {
- if (cp->xstate != NULL)
- (*cp->xcomp->comp_free)(cp->xstate);
- cp->xcomp = *comp;
- cp->xstate = (*comp)->comp_alloc(odp->opt_data, len);
- if (cp->xstate == NULL)
- error = ENOSR;
- } else {
- if (cp->rstate != NULL)
- (*cp->rcomp->decomp_free)(cp->rstate);
- cp->rcomp = *comp;
- cp->rstate = (*comp)->decomp_alloc(odp->opt_data, len);
- if (cp->rstate == NULL)
- error = ENOSR;
- }
- if (cp->debug)
- log(LOG_DEBUG, "SIOCSCOMPRESS %s len=%d\n",
- odp->transmit? "xmit": "recv", len);
- break;
- }
- iop->ioc_count = 0;
- break;
-
- case SIOCSIFDEBUG:
- /* set our debug flag from this */
- if (iop->ioc_count == sizeof(int)) {
- cp->debug = *(int *) mp->b_cont->b_rptr & 1;
- }
- break;
-
- case SIOCSIFMRU:
- /* remember this value */
- if (iop->ioc_count == sizeof(int)) {
- cp->mru = *(int *) mp->b_cont->b_rptr;
- }
- break;
-
- }
-
- if (error < 0)
- putnext(q, mp);
- else if (error == 0) {
- mp->b_datap->db_type = M_IOCACK;
- qreply(q, mp);
- } else {
- mp->b_datap->db_type = M_IOCNAK;
- iop->ioc_count = 0;
- qreply(q, mp);
- }
- break;
-
- default:
- putnext(q, mp);
- }
-}
-
-static int
-ppp_comp_rput(q, mp)
- queue_t *q;
- mblk_t *mp;
-{
- int proto, rv;
- mblk_t *dmp = NULL;
- struct ppp_comp_state *cp;
-
- cp = (struct ppp_comp_state *) q->q_ptr;
- switch (mp->b_datap->db_type) {
-
- case M_DATA:
- /* possibly a compressed packet to decompress,
- or a CCP packet to take notice of. */
- if (mp->b_wptr - mp->b_rptr >= PPP_HDRLEN
- || pullupmsg(mp, PPP_HDRLEN)) {
- proto = PPP_PROTOCOL(mp->b_rptr);
- if (proto == PPP_CCP)
- ppp_comp_ccp(q, mp, 1);
- else if (proto == PPP_COMP) {
- if ((cp->ccp_state & CCP_ISUP)
- && (cp->ccp_state & CCP_DECOMP_RUN) && cp->rstate
- && (cp->ccp_state & CCP_ERR) == 0) {
- rv = (*cp->rcomp->decompress)(cp->rstate, mp, &dmp);
- switch (rv) {
- case DECOMP_OK:
- freemsg(mp);
- mp = dmp;
- /* if mp is now NULL, then there was no error,
- but no packet returned either. */
- break;
- case DECOMP_ERROR:
- cp->ccp_state |= CCP_ERROR;
- break;
- case DECOMP_FATALERROR:
- cp->ccp_state |= CCP_FATALERROR;
- break;
- }
- }
- } else if (cp->rstate && (cp->ccp_state & CCP_DECOMP_RUN)) {
- (*cp->rcomp->incomp)(cp->rstate, mp);
- }
- }
- if (mp != NULL)
- putnext(q, mp);
- break;
-
- default:
- putnext(q, mp);
- }
-}
-
-static void
-ppp_comp_ccp(q, mp, rcvd)
- queue_t *q;
- mblk_t *mp;
- int rcvd;
-{
- int len, clen;
- struct ppp_comp_state *cp;
- unsigned char *dp;
-
- len = msgdsize(mp);
- if (len < PPP_HDRLEN + CCP_HDRLEN || !pullupmsg(mp, len))
- return;
- cp = (struct ppp_comp_state *) q->q_ptr;
- dp = mp->b_rptr + PPP_HDRLEN;
- len -= PPP_HDRLEN;
- clen = CCP_LENGTH(dp);
- if (clen > len)
- return;
- if (cp->debug)
- log(LOG_DEBUG, "CCP %s: code=%x len=%d\n", rcvd? "rcvd": "sent",
- CCP_CODE(dp), clen);
-
- switch (CCP_CODE(dp)) {
- case CCP_CONFREQ:
- case CCP_TERMREQ:
- case CCP_TERMACK:
- cp->ccp_state &= ~CCP_ISUP;
- break;
-
- case CCP_CONFACK:
- if ((cp->ccp_state & (CCP_ISOPEN | CCP_ISUP)) == CCP_ISOPEN
- && clen >= CCP_HDRLEN + CCP_OPT_MINLEN
- && clen >= CCP_HDRLEN + CCP_OPT_LENGTH(dp + CCP_HDRLEN)) {
- if (!rcvd) {
- if (cp->xstate != NULL
- && (*cp->xcomp->comp_init)
- (cp->xstate, dp + CCP_HDRLEN, clen - CCP_HDRLEN,
- 0, /* XXX: should be unit */ 0,
- cp->debug))
- cp->ccp_state |= CCP_COMP_RUN;
- } else {
- if (cp->rstate != NULL
- && (*cp->rcomp->decomp_init)
- (cp->rstate, dp + CCP_HDRLEN, clen - CCP_HDRLEN,
- 0/* unit */, 0, cp->mru, cp->debug))
- cp->ccp_state = (cp->ccp_state & ~CCP_ERR)
- | CCP_DECOMP_RUN;
- }
- }
- break;
-
- case CCP_RESETACK:
- if (cp->ccp_state & CCP_ISUP) {
- if (!rcvd) {
- if (cp->xstate && (cp->ccp_state & CCP_COMP_RUN))
- (*cp->xcomp->comp_reset)(cp->xstate);
- } else {
- if (cp->rstate && (cp->ccp_state & CCP_DECOMP_RUN)) {
- (*cp->rcomp->decomp_reset)(cp->rstate);
- cp->ccp_state &= ~CCP_ERROR;
- }
- }
- }
- break;
- }
-
- if (cp->debug)
- log(LOG_DEBUG, "ccp_state = %x\n", cp->ccp_state);
-}
+++ /dev/null
-/*
- ppp_if.c - Streams PPP interface module
-
- top level module handles if_ and packetizing PPP packets.
-
- Copyright (C) 1990 Brad K. Clements, All Rights Reserved
- See copyright notice in NOTES
-
- $Id: ppp_if.c,v 1.1 1995/12/18 23:45:11 paulus Exp $
-*/
-
-/*
- * This file is used under SunOS 4.x, and OSF/1 on DEC Alpha.
- *
- * Beware that under OSF/1, the ioctl constants (SIOC*) end up
- * as 64-bit (long) values, so an ioctl constant should be cast to
- * int (32 bits) before being compared with the ioc_cmd field of
- * an iocblk structure.
- */
-
-#define VJC 1
-#include <sys/types.h>
-
-#ifndef PPP_VD
-#include "ppp.h"
-#endif
-
-#if NPPP > 0
-
-#define PPP_STATS 1 /* keep statistics */
-#define DEBUGS 1 /* include debug code */
-
-#ifdef __osf__
-#include <sys/proc.h>
-#define NOTSUSER (suser(u.u_procp->p_rcred, &u.u_acflag))
-#define IFA_ADDR(ifa) (*(ifa)->ifa_addr)
-#define ifr_mtu ifr_metric
-#define SIOCSIFMTU SIOCSIPMTU
-#define SIOCGIFMTU SIOCRIPMTU
-#endif
-
-#ifdef sun
-#define PPP_SNIT 1 /* support Streams Network Interface Tap */
-#define NOTSUSER (!suser())
-#define MHLEN MLEN
-#define MGETHDR MGET
-#define m_data m_off /* well almost */
-#define IFA_ADDR(ifa) ((ifa)->ifa_addr)
-#endif
-
-#include <sys/param.h>
-#include <sys/stream.h>
-#include <sys/stropts.h>
-
-#include <sys/user.h>
-#include <sys/systm.h>
-#include <sys/mbuf.h>
-#include <sys/socket.h>
-#include <sys/errno.h>
-#include <sys/ioctl.h>
-#include <sys/file.h>
-#include <sys/uio.h>
-#include <net/if.h>
-#include <net/route.h>
-#include <net/netisr.h>
-#include <netinet/in.h>
-#include <netinet/in_systm.h>
-#include <netinet/in_var.h>
-#include <netinet/ip.h>
-
-#include <net/ppp_defs.h>
-#include <net/ppp_str.h>
-
-#ifdef VJC
-#include <net/vjcompress.h>
-#endif
-
-#ifdef PPP_STATS
-#define INCR(comp) ++p->pii_stats.comp
-#else
-#define INCR(comp)
-#endif
-
-#define MAX_PKTSIZE 4096 /* max packet size including framing */
-#define PPP_FRAMING 6 /* 4-byte header + 2-byte FCS */
-#define MAX_IPHDR 128 /* max TCP/IP header size */
-#define MAX_VJHDR 20 /* max VJ compressed header size (?) */
-
-/*
- * Network protocols we support.
- */
-#define NP_IP 0
-#define NUM_NP 1 /* # protocols supported */
-
-/*
- * Structure used within the ppp_if streams module.
- */
-struct ppp_if_info {
- int pii_flags;
- struct ifnet pii_ifnet;
- queue_t *pii_writeq; /* used by ppp_output */
- enum NPmode pii_npmode[NUM_NP];
- mblk_t *pii_npq; /* list of packets queued up */
- mblk_t **pii_npq_tail;
-#ifdef VJC
- struct vjcompress pii_sc_comp; /* vjc control buffer */
-#endif
-#ifdef PPP_STATS
- struct pppstat pii_stats;
-#endif
- struct ppp_comp_stats pii_cstats;
-};
-
-/*
- * Values for pii_flags.
- */
-#define PII_FLAGS_INUSE 0x1 /* in use by a stream */
-#define PII_FLAGS_ATTACHED 0x8 /* already if_attached */
-#define PII_FLAGS_VJC_ON 0x10 /* VJ TCP header compression enabled */
-#define PII_FLAGS_VJC_NOCCID 0x20 /* VJ: don't compress conn. id */
-#define PII_FLAGS_VJC_REJ 0x40 /* receive: reject VJ comp */
-#define PII_FLAGS_DEBUG 0x80 /* enable debug printout */
-
-#ifdef DEBUGS
-#include <sys/syslog.h>
-#define DLOG(s,a) if (p->pii_flags&PII_FLAGS_DEBUG) log(LOG_DEBUG, s, a)
-#else
-#define DLOG(s) {}
-#endif
-
-#ifdef PPP_SNIT
-#include <net/nit_if.h>
-#include <netinet/if_ether.h>
-/* Use a fake link level header to make etherfind and tcpdump happy. */
-static struct ether_header header = {{1}, {2}, ETHERTYPE_IP};
-static struct nit_if nif = {(caddr_t)&header, sizeof(header), 0, 0};
-#endif
-
-static int ppp_if_open(), ppp_if_close(), ppp_if_rput(), ppp_if_wput(),
- ppp_if_wsrv(), ppp_if_rsrv();
-
-static struct module_info minfo ={
- 0xbad,"ppp_if",0, INFPSZ, 16384, 4096
-};
-
-static struct qinit r_init = {
- ppp_if_rput, ppp_if_rsrv, ppp_if_open, ppp_if_close, NULL, &minfo, NULL
-};
-static struct qinit w_init = {
- ppp_if_wput, ppp_if_wsrv, ppp_if_open, ppp_if_close, NULL, &minfo, NULL
-};
-struct streamtab ppp_ifinfo = {
- &r_init, &w_init, NULL, NULL,
-};
-
-typedef struct ppp_if_info PII;
-
-PII pii[NPPP];
-
-int ppp_output(), ppp_ioctl();
-static void if_release_addrs(), if_delete_route();
-
-int
-ppp_attach()
-{
- int unit;
- register struct ifnet *ifp;
-
- for (unit = 0; unit < NPPP; ++unit) {
- if (pii[unit].pii_flags & PII_FLAGS_ATTACHED)
- continue;
- ifp = &pii[unit].pii_ifnet;
-
- ifp->if_name = "ppp";
- ifp->if_mtu = PPP_MTU;
- ifp->if_flags = IFF_POINTOPOINT;
- ifp->if_unit = unit;
- ifp->if_ioctl = ppp_ioctl;
- ifp->if_output = ppp_output;
-#ifdef __osf__
- ifp->if_version = "2.2";
- ifp->if_mediamtu = PPP_MTU;
- ifp->if_start = NULL;
- ifp->if_done = NULL;
- ifp->if_type = 0x1d; /* IFT_PPP snagged from BSD -- is this ok? */
- ifp->if_hdrlen = PPP_HDRLEN;
-#endif
- ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;
- if_attach(ifp);
- pii[unit].pii_flags |= PII_FLAGS_ATTACHED;
- }
-}
-
-
-int
-ppp_unattach()
-{
- int unit;
- register struct ifnet *ifp;
- register struct ifnet **p;
- int s;
-
- for (unit = 0; unit < NPPP; ++unit) {
- if (!(pii[unit].pii_flags & PII_FLAGS_ATTACHED))
- continue;
- ifp = &pii[unit].pii_ifnet;
-
- /* remove interface from interface list */
- s = splimp();
- for (p = &ifnet; *p; p = &((*p)->if_next)) {
- if (*p == ifp) {
- *p = (*p)->if_next;
-
- /* mark it down and flush it's que */
- if_down(ifp);
-
- /* free any addresses hanging off the intf */
- if_release_addrs(ifp);
-
- pii[unit].pii_flags &= ~PII_FLAGS_ATTACHED;
-
- break;
- }
- }
- (void)splx(s);
- }
-}
-
-
-static void
-if_release_addrs(ifp)
-register struct ifnet *ifp;
-{
- register struct in_ifaddr **addr;
- register struct ifaddr *ifa, *ifanxt;
- register int s;
-
- if_delete_route(ifp);
-
- for (addr = &in_ifaddr; *addr; ) {
- if ((*addr)->ia_ifp == ifp)
- *addr = (*addr)->ia_next;
- else
- addr = &((*addr)->ia_next);
- }
-
- /*
- * Free all mbufs holding down this interface's address(es).
- */
- for (ifa = ifp->if_addrlist; ifa; ifa = ifanxt) {
- ifanxt = ifa->ifa_next;
- m_free(dtom(ifa));
- }
- ifp->if_addrlist = 0;
-}
-
-/*
- * Delete routes to the specified interface.
- * Hacked from rtrequest().
- */
-static void
-if_delete_route(ifp)
-struct ifnet *ifp;
-{
- extern int rttrash; /* routes not in table but not freed */
- register struct mbuf **mprev, *m;
- register struct rtentry *route;
- register int i;
-
- /* search host rt tbl */
- for (i = 0; i < RTHASHSIZ; i++) {
- mprev = &rthost[i];
- while (m = *mprev) {
- route = mtod(m, struct rtentry *);
- if (route->rt_ifp == ifp) {
- *mprev = m->m_next;
- if (route->rt_refcnt > 0) {
- route->rt_flags &= ~RTF_UP;
- rttrash++;
- m->m_next = 0;
- } else {
- m_free(m);
- }
- } else
- mprev = &m->m_next;
- }
- }
-
- /* search net rt tbl */
- for (i = 0; i < RTHASHSIZ; i++) {
- mprev = &rtnet[i];
- while (m = *mprev) {
- route = mtod(m, struct rtentry *);
- if (route->rt_ifp == ifp) {
- *mprev = m->m_next;
- if (route->rt_refcnt > 0) {
- route->rt_flags &= ~RTF_UP;
- rttrash++;
- m->m_next = 0;
- } else {
- m_free(m);
- }
- } else
- mprev = &m->m_next;
- }
- }
-}
-
-int
-ppp_busy()
-{
- int x;
-
- for (x = 0; x < NPPP; x++) {
- if (pii[x].pii_flags & PII_FLAGS_INUSE)
- return 1;
- }
- return 0;
-}
-
-static PII *
-ppp_if_alloc()
-{
- int s, x;
- PII *p;
-
- s = splstr();
- for (x = 0; x < NPPP; x++)
- if (!(pii[x].pii_flags & PII_FLAGS_INUSE))
- break;
- if (x == NPPP) { /* all buffers in use */
- splx(s); /* restore processor state */
- return NULL;
- }
- p = &pii[x];
- p->pii_flags |= PII_FLAGS_INUSE;
- splx(s);
- return p;
-}
-
-static void
-ppp_if_init(q, p)
- queue_t *q;
- PII *p;
-{
- int s, n;
-
- s = splstr();
-
-#ifdef VJC
- vj_compress_init(&p->pii_sc_comp, -1);
-#endif
-#ifdef PPP_STATS
- bzero(&p->pii_stats, sizeof(p->pii_stats));
-#endif
- if (!(p->pii_flags & PII_FLAGS_ATTACHED))
- ppp_attach(); /* attach it */
- else
- p->pii_ifnet.if_mtu = PPP_MTU;
- p->pii_writeq = WR(q);
- /* set write Q and read Q to point here */
- WR(q)->q_ptr = q->q_ptr = (caddr_t) p;
- p->pii_ifnet.if_flags |= IFF_RUNNING;
- p->pii_flags &= PII_FLAGS_INUSE | PII_FLAGS_ATTACHED | PII_FLAGS_DEBUG;
- for (n = 0; n < NUM_NP; ++n)
- p->pii_npmode[n] = NPMODE_ERROR;
- p->pii_npmode[NP_IP] = NPMODE_PASS; /* for backwards compatibility */
- p->pii_npq = NULL;
- p->pii_npq_tail = &p->pii_npq;
-
- splx(s);
- DLOG("ppp_if%d: init\n", p - pii);
-}
-
-static int
-ppp_if_open(q, dev, flag, sflag)
- queue_t *q;
- dev_t dev;
- int flag, sflag;
-
-{
- if (NOTSUSER) {
- u.u_error = EPERM;
- return (OPENFAIL);
- }
-
- return (0);
-}
-
-static int
-ppp_if_close(q)
- queue_t *q; /* queue info */
-{
- PII *p = (PII *) q->q_ptr;
- int s, n;
- mblk_t *mp, *mq;
-
- if (p != NULL) {
- s = splimp();
- if_down(&p->pii_ifnet);
- p->pii_ifnet.if_flags &= ~IFF_RUNNING;
- p->pii_flags &= ~PII_FLAGS_INUSE;
- q->q_ptr = NULL;
- splx(s);
- for (mp = p->pii_npq; mp != NULL; mp = mq) {
- mq = mp->b_next;
- freemsg(mp);
- }
- p->pii_npq = NULL;
- p->pii_npq_tail = &p->pii_npq;
- p->pii_writeq = NULL;
- DLOG("ppp_if%d: closed\n", p - pii);
- }
- return(0); /* no work to be done */
-}
-
-
-static int
-ppp_if_wput(q, mp)
- queue_t *q;
- register mblk_t *mp;
-{
- register struct iocblk *i;
- register PII *p;
- int bits, flags, error, unit, s;
- queue_t *oq;
- int npix;
- struct npioctl *npi;
- mblk_t *mq, **mqnext;
- struct ppp_stats *psp;
-
- switch (mp->b_datap->db_type) {
-
- case M_FLUSH:
- if (*mp->b_rptr & FLUSHW)
- flushq(q, FLUSHDATA);
- putnext(q, mp); /* send it along too */
- break;
-
- case M_DATA:
- putq(q, mp); /* queue it for my service routine */
- break;
-
- case M_IOCTL:
- i = (struct iocblk *) mp->b_rptr;
- p = (PII *) q->q_ptr;
- switch (i->ioc_cmd) {
-
- case SIOCSIFVJCOMP: /* enable or disable VJ compression */
-#ifdef VJC
- if (i->ioc_count == sizeof(u_char) && p != NULL) {
- bits = *(u_char *) mp->b_cont->b_rptr;
- DLOG("ppp_if: SIFVJCOMP %d\n", bits);
- if (bits & 1)
- p->pii_flags |= PII_FLAGS_VJC_ON;
- else
- p->pii_flags &= ~PII_FLAGS_VJC_ON;
- if (bits & 2)
- p->pii_flags |= PII_FLAGS_VJC_NOCCID;
- else
- p->pii_flags &= ~PII_FLAGS_VJC_NOCCID;
- if (bits & 4)
- p->pii_flags |= PII_FLAGS_VJC_REJ;
- else
- p->pii_flags &= ~PII_FLAGS_VJC_REJ;
- bits >>= 4; /* now max conn id. */
- if (bits)
- vj_compress_init(&p->pii_sc_comp, bits);
- mp->b_datap->db_type = M_IOCACK;
- i->ioc_count = 0;
- qreply(q, mp);
- break;
- }
-#endif
- putnext(q, mp);
- break;
-
- case SIOCGETU: /* get unit number */
- /*
- * Allocate a unit if we don't already have one.
- */
- error = 0;
- if (p == NULL) {
- p = ppp_if_alloc();
- if (p == NULL)
- error = ENOBUFS;
- else
- ppp_if_init(RD(q), p);
- }
- if (error == 0
- && (mp->b_cont = allocb(sizeof(int), BPRI_MED)) == NULL)
- error = ENOSR;
- if (error == 0) {
- *(int *) mp->b_cont->b_wptr = p->pii_ifnet.if_unit;
- mp->b_cont->b_wptr += i->ioc_count = sizeof(int);
- mp->b_datap->db_type = M_IOCACK;
- } else {
- i->ioc_error = error;
- i->ioc_count = 0;
- mp->b_datap->db_type = M_IOCNAK;
- }
- qreply(q,mp);
- break;
-
- case SIOCSETU: /* set unit number */
- if (i->ioc_count == sizeof(int)) {
- unit = *(int *)mp->b_cont->b_rptr;
- if (p != NULL || (unsigned) unit > NPPP) {
- mp->b_datap->db_type = M_IOCNAK;
- i->ioc_error = EINVAL;
- i->ioc_count = 0;
- error = EINVAL;
- } else {
- p = &pii[unit];
- if (p->pii_flags & PII_FLAGS_INUSE) {
- oq = p->pii_writeq;
- oq->q_ptr = RD(oq)->q_ptr = NULL;
- q->q_ptr = RD(q)->q_ptr = (caddr_t) p;
- p->pii_writeq = q;
- } else {
- ppp_if_init(RD(q), p);
- }
- mp->b_datap->db_type = M_IOCACK;
- }
- qreply(q, mp);
- break;
- }
- putnext(q, mp);
- break;
-
- case SIOCSIFDEBUG :
- /* catch it on the way past to set our debug flag as well */
- if (i->ioc_count == sizeof(int)) {
- flags = *(int *)mp->b_cont->b_rptr;
- if (flags & 1)
- p->pii_flags |= PII_FLAGS_DEBUG;
- else
- p->pii_flags &= ~PII_FLAGS_DEBUG;
- }
- putnext(q, mp);
- break;
-
- case SIOCGETNPMODE:
- case SIOCSETNPMODE:
- if (i->ioc_count == sizeof(struct npioctl) && p != NULL) {
- npi = (struct npioctl *) mp->b_cont->b_rptr;
- switch (npi->protocol) {
- case PPP_IP:
- npix = NP_IP;
- break;
- default:
- npix = -1;
- }
- if (npix < 0) {
- i->ioc_error = EAFNOSUPPORT;
- i->ioc_count = 0;
- mp->b_datap->db_type = M_IOCNAK;
- qreply(q, mp);
- break;
- }
- if (i->ioc_cmd == (int) SIOCSETNPMODE) {
- if (p->pii_npmode[npix] == NPMODE_QUEUE
- && npi->mode != NPMODE_QUEUE) {
- for (mqnext = &p->pii_npq; (mq = *mqnext) != NULL; ) {
- if (PPP_PROTOCOL(mq->b_rptr) != npi->protocol){
- mqnext = &mq->b_next;
- continue;
- }
- *mqnext = mq->b_next;
- if (npi->mode == NPMODE_PASS) {
- putq(q, mq); /* q it for service routine */
- } else {
- freemsg(mq);
- }
- }
- p->pii_npq_tail = mqnext;
- }
- p->pii_npmode[npix] = npi->mode;
- i->ioc_count = 0;
- } else
- npi->mode = p->pii_npmode[npix];
- mp->b_datap->db_type = M_IOCACK;
- qreply(q, mp);
- break;
- }
- putnext(q, mp);
- break;
-
- default: /* unknown IOCTL call */
- putnext(q, mp); /* pass it along */
- }
- break;
-
- default:
- putnext(q, mp); /* don't know what to do with this, so send it along*/
- }
-}
-
-static int
-ppp_if_wsrv(q)
- queue_t *q;
-{
- register mblk_t *mp;
- register PII *p;
-
- p = (PII *) q->q_ptr;
-
- while ((mp = getq(q)) != NULL) {
- /*
- * we can only get M_DATA types into our Queue,
- * due to our Put function
- */
- if (!canput(q->q_next)) {
- putbq(q, mp);
- return;
- }
-
- /* increment count of outgoing packets */
- if (p != NULL)
- INCR(ppp_opackets);
-
- /* just pass it along, nothing to do in this direction */
- putnext(q, mp);
- } /* end while */
-}
-
-
-static int
-ppp_if_rput(q, mp)
- queue_t *q;
- register mblk_t *mp;
-{
- register PII *p;
-
- switch (mp->b_datap->db_type) {
-
- case M_FLUSH:
- if (*mp->b_rptr & FLUSHR)
- flushq(q, FLUSHDATA);
- putnext(q, mp); /* send it along too */
- break;
-
- case M_DATA:
- putq(q, mp); /* queue it for my service routine */
- break;
-
- case M_CTL:
- p = (PII *) q->q_ptr;
- if (p != NULL) {
- switch (*(u_char *) mp->b_rptr) {
- case IF_INPUT_ERROR:
- p->pii_ifnet.if_ierrors++;
- INCR(ppp_ierrors);
- DLOG("ppp_if: input error inc to %d\n",
- p->pii_ifnet.if_ierrors);
- putnext(q, mp);
- break;
- case IF_OUTPUT_ERROR:
- p->pii_ifnet.if_oerrors++;
- INCR(ppp_oerrors);
- DLOG("ppp_if: output error inc to %d\n",
- p->pii_ifnet.if_oerrors);
- putnext(q, mp);
- break;
- case IF_CSTATS:
- bcopy(mp->b_rptr + sizeof(u_long), &p->pii_cstats,
- sizeof(struct ppp_comp_stats));
- freemsg(mp);
- break;
- default:
- putnext(q, mp); /* send it up to pppd */
- break;
- }
- }
- break;
-
- default:
- putnext(q, mp); /* send along other message types */
- }
-}
-
-static int
-ppp_if_rsrv(q)
- queue_t *q;
-{
- register mblk_t *mp,*m0;
-#ifdef VJC
- register mblk_t *mvjc;
- unsigned char *cp, *iphdr;
- u_int hlen;
-#endif
- register PII *p;
- struct mbuf *mb1, *mb2, *mbtail;
- int len, xlen, count, s;
- u_char *rptr;
- int address, control;
- int dlen;
-
- p = (PII *) q->q_ptr;
-
- while ((mp = getq(q)) != NULL) {
- /*
- * we can only get M_DATA types into our Queue,
- * due to our Put function
- */
-
- if (p == NULL) {
- if (!canput(q->q_next)) {
- putbq(q, mp);
- return;
- }
- putnext(q, mp);
- continue;
- }
-
- len = msgdsize(mp);
- dlen = len - PPP_HDRLEN;
-#ifdef PPP_STATS
- p->pii_stats.ppp_ibytes += len;
-#endif
-
- /* make sure ppp_header is completely in first block */
- if (mp->b_wptr - mp->b_rptr < PPP_HDRLEN
- && !pullupmsg(mp, PPP_HDRLEN)) {
- DLOG("pullupmsg failed!\n", 0);
- freemsg(mp);
- p->pii_ifnet.if_ierrors++;
- continue;
- }
- m0 = mp; /* remember first message block */
-
-#ifdef VJC
- switch (PPP_PROTOCOL(mp->b_rptr)) {
- case PPP_VJC_COMP :
- if ((p->pii_flags & PII_FLAGS_VJC_REJ)
- || p->pii_npmode[NP_IP] != NPMODE_PASS) {
- DLOG("VJC rejected\n", 0);
- freemsg(mp);
- continue;
- }
- address = PPP_ADDRESS(mp->b_rptr);
- control = PPP_CONTROL(mp->b_rptr);
- mp->b_rptr += PPP_HDRLEN;
- len -= PPP_HDRLEN;
-
- /*
- * Make sure the VJ header is in one message block.
- */
- xlen = MIN(len, MAX_VJHDR);
- if (mp->b_rptr + xlen > mp->b_wptr && !pullupmsg(mp, xlen)) {
- DLOG("pullupmsg vjc %d failed\n", xlen);
- freemsg(mp);
- continue;
- }
-
- /*
- * Decompress it, then get a buffer and put the
- * decompressed header in it.
- */
- xlen = vj_uncompress_tcp(mp->b_rptr, mp->b_wptr - mp->b_rptr,
- len, &p->pii_sc_comp, &iphdr, &hlen);
- if (xlen < 0) {
- DLOG("ppp: vj_uncompress failed on type Compressed\n", 0);
- freemsg(mp);
- continue;
- }
- if (!(mvjc = allocb(hlen + PPP_HDRLEN, BPRI_MED))) {
- DLOG("allocb mvjc failed (%d)\n", hlen + PPP_HDRLEN);
- freemsg(mp);
- continue;
- }
- dlen = len - xlen + hlen;
- cp = mvjc->b_rptr;
- cp[0] = address;
- cp[1] = control;
- cp[2] = 0;
- cp[3] = PPP_IP;
- bcopy(iphdr, cp + PPP_HDRLEN, hlen);
- mvjc->b_wptr = cp + PPP_HDRLEN + hlen;
- mvjc->b_cont = mp;
- mp->b_rptr += xlen;
- m0 = mp = mvjc;
- break;
-
- case PPP_VJC_UNCOMP :
- if ((p->pii_flags & PII_FLAGS_VJC_REJ)
- || p->pii_npmode[NP_IP] != NPMODE_PASS) {
- DLOG("VJU rejected\n", 0);
- freemsg(mp);
- continue;
- }
-
- /*
- * Make sure the IP header is in one message block.
- */
- xlen = MIN(len, MAX_IPHDR + PPP_HDRLEN);
- if (mp->b_rptr + xlen > mp->b_wptr && !pullupmsg(mp, xlen)) {
- DLOG("pullupmsg vju %d failed\n", xlen);
- freemsg(mp);
- continue;
- }
-
- /*
- * "Uncompress" it. Basically this just copies information
- * into p->pii_sc_comp and restores the protocol field of
- * the IP header.
- */
- if (!vj_uncompress_uncomp(mp->b_rptr + PPP_HDRLEN,
- &p->pii_sc_comp)) {
- DLOG("ppp: vj_uncompress failed on type Uncompresed\n", 0);
- freemsg(mp);
- continue;
- }
- mp->b_rptr[3] = PPP_IP;
- break;
- }
-#endif
-
- switch (PPP_PROTOCOL(mp->b_rptr)) {
- default:
- if (!canput(q->q_next)) {
- putbq(q, mp);
- return;
- }
- INCR(ppp_ipackets);
- p->pii_ifnet.if_ipackets++;
- putnext(q, mp);
- continue;
-
- case PPP_IP:
- /*
- * Don't let packets through until IPCP is up.
- */
- INCR(ppp_ipackets);
- p->pii_ifnet.if_ipackets++;
-
- if (!(p->pii_ifnet.if_flags & IFF_UP)
- || p->pii_npmode[NP_IP] != NPMODE_PASS) {
- DLOG("pkt ignored - IP down\n", 0);
- freemsg(mp);
- continue;
- }
-
- /*
- * Get the first mbuf and put the struct ifnet * in.
- */
- MGETHDR(mb1, M_DONTWAIT, MT_DATA);
- if (mb1 == NULL) {
- p->pii_ifnet.if_ierrors++;
- freemsg(m0);
- continue;
- }
-#ifdef __osf__
- mb1->m_pkthdr.rcvif = &(p->pii_ifnet);
- mb1->m_pkthdr.len = dlen;
- len = MHLEN;
- mb1->m_len = 0;
-#else
- *mtod(mb1, struct ifnet **) = &p->pii_ifnet;
- len = MLEN - sizeof(struct ifnet *);
- mb1->m_len = sizeof(struct ifnet *);
-#endif
- mbtail = mb2 = mb1;
-
- rptr = mp->b_rptr + PPP_HDRLEN;
- xlen = mp->b_wptr - rptr;
- for(;;) {
- if (xlen == 0) { /* move to the next mblk */
- mp = mp->b_cont;
- if (mp == NULL)
- break;
- xlen = mp->b_wptr - (rptr = mp->b_rptr);
- continue;
- }
- if (len == 0) {
- MGET(mb2, M_DONTWAIT, MT_DATA);
- if (!mb2) {
- /* if we couldn't get a buffer, drop the packet */
- p->pii_ifnet.if_ierrors++;
- m_freem(mb1); /* discard what we've used already */
- mb1 = NULL;
- break;
- }
- len = MLEN;
- mb2->m_len = 0;
- mbtail->m_next = mb2;
- mbtail = mb2;
- }
- count = MIN(xlen, len);
- bcopy((char *) rptr, mtod(mb2, char *) + mb2->m_len, count);
- rptr += count;
- len -= count;
- xlen -= count;
- mb2->m_len += count;
- }
-
- freemsg(m0);
- if (mb1 == NULL)
- continue;
-
-#ifdef PPP_SNIT
- if (p->pii_ifnet.if_flags & IFF_PROMISC) {
- struct mbuf *m = mb1;
-
- len = 0;
- do {
- len += m->m_len;
- } while (m = m->m_next);
- nif.nif_bodylen = len - sizeof(struct ifnet *);
- mb1->m_off += sizeof(struct ifnet *);
- snit_intr(&p->pii_ifnet, mb1, &nif);
- mb1->m_off -= sizeof(struct ifnet *);
- }
-#endif
- s = splimp();
- if (IF_QFULL(&ipintrq)) {
- IF_DROP(&ipintrq);
- p->pii_ifnet.if_ierrors++;
- m_freem(mb1);
- }
- else {
- IF_ENQUEUE(&ipintrq, mb1);
- schednetisr(NETISR_IP);
- }
- splx(s);
- }
- } /* end while */
-}
-
-/* ifp output procedure */
-int
-ppp_output(ifp, m0, dst)
- struct ifnet *ifp;
- struct mbuf *m0;
- struct sockaddr *dst;
-{
- register PII *p = &pii[ifp->if_unit];
- struct mbuf *m1;
- int error, s, len;
- u_short protocol;
-#ifdef VJC
- int type;
- u_char *vjhdr;
-#endif
- mblk_t *mp;
- enum NPmode npmode;
-
- error = 0;
- if (!(ifp->if_flags & IFF_UP)) {
- error = ENETDOWN;
- goto getout;
- }
-
- switch (dst->sa_family) {
-#ifdef INET
- case AF_INET:
-#ifdef PPP_SNIT
- if (ifp->if_flags & IFF_PROMISC) {
- struct mbuf *m = m0;
-
- len = 0;
- do {
- len += m->m_len;
- } while (m = m->m_next);
- nif.nif_bodylen = len;
- snit_intr(ifp, m0, &nif);
- }
-#endif
- protocol = PPP_IP;
- npmode = p->pii_npmode[NP_IP];
- break;
-#endif
-
- default:
- DLOG("ppp: af%d not supported\n", dst->sa_family);
- error = EAFNOSUPPORT;
- goto getout;
- }
-
- if (!p->pii_writeq) {
- DLOG("ppp_if%d: no queue\n", p - pii);
- error = EHOSTUNREACH;
- goto getout;
- }
-
- switch (npmode) {
- case NPMODE_DROP:
- goto getout;
- case NPMODE_ERROR:
- error = ENETDOWN;
- goto getout;
- }
-
-#ifdef VJC
- if ((protocol == PPP_IP) && (p->pii_flags & PII_FLAGS_VJC_ON)) {
- register struct ip *ip;
- ip = mtod(m0, struct ip *);
- if (ip->ip_p == IPPROTO_TCP) {
- type = vj_compress_tcp(ip, m0->m_len, &p->pii_sc_comp,
- !(p->pii_flags & PII_FLAGS_VJC_NOCCID),
- &vjhdr);
- switch (type) {
- case TYPE_UNCOMPRESSED_TCP :
- protocol = PPP_VJC_UNCOMP;
- break;
- case TYPE_COMPRESSED_TCP :
- protocol = PPP_VJC_COMP;
- len = vjhdr - (u_char *) ip;
- m0->m_data += len;
- m0->m_len -= len;
- break;
- }
- }
- }
-#endif
-
- len = PPP_HDRLEN;
- for (m1 = m0; m1; m1 = m1->m_next)
- len += m1->m_len;
-
- if (!(mp = allocb(len, BPRI_MED))) {
- DLOG("ppp_if%d: allocb failed\n", p - pii);
- error = ENOBUFS;
- goto getout;
- }
-
-#ifdef PPP_STATS
- p->pii_stats.ppp_obytes += len;
-#endif
-
- *mp->b_wptr++ = PPP_ALLSTATIONS;
- *mp->b_wptr++ = PPP_UI;
- *mp->b_wptr++ = 0;
- *mp->b_wptr++ = protocol;
- for (m1 = m0; m1; m1 = m1->m_next) { /* copy all data */
- bcopy(mtod(m1, char *), (char *) mp->b_wptr, m1->m_len);
- mp->b_wptr += m1->m_len;
- }
-
- s = splstr();
- p->pii_ifnet.if_opackets++;
- if (npmode == NPMODE_PASS) {
- putq(p->pii_writeq, mp);
- } else {
- mp->b_next = NULL;
- *p->pii_npq_tail = mp;
- p->pii_npq_tail = ∓
- }
- splx(s);
-
- getout:
- m_freem(m0);
- if (error) {
- INCR(ppp_oerrors);
- p->pii_ifnet.if_oerrors++;
- }
- return (error);
-}
-
-/*
- * if_ ioctl requests
-*/
-ppp_ioctl(ifp, cmd, data)
- register struct ifnet *ifp;
- int cmd;
- caddr_t data;
-{
- register struct ifaddr *ifa = (struct ifaddr *) data;
- register struct ifreq *ifr = (struct ifreq *) data;
- struct ppp_stats *psp;
- struct ppp_comp_stats *pcp;
- PII *p;
- queue_t *q;
- int s = splimp(), error = 0;
-
- switch (cmd) {
- case SIOCSIFFLAGS :
- /* This happens every time IFF_PROMISC has been changed. */
- if (!ifr)
- break;
- if (NOTSUSER) {
- error = EPERM;
- break;
- }
-
- /* clear the flags that can be cleared */
- ifp->if_flags &= (IFF_CANTCHANGE);
- /* or in the flags that can be changed */
- ifp->if_flags |= (ifr->ifr_flags & ~IFF_CANTCHANGE);
- break;
-
- case SIOCGIFFLAGS :
- ifr->ifr_flags = ifp->if_flags;
- break;
-
- case SIOCSIFADDR :
- if (IFA_ADDR(ifa).sa_family != AF_INET)
- error = EAFNOSUPPORT;
- break;
-
- case SIOCSIFDSTADDR :
- if (IFA_ADDR(ifa).sa_family != AF_INET)
- error = EAFNOSUPPORT;
- break;
-
- case SIOCSIFMTU :
- if (NOTSUSER) {
- error = EPERM;
- break;
- }
- if (ifr->ifr_mtu > MAX_PKTSIZE - PPP_FRAMING) {
- error = EINVAL;
- break;
- }
- ifp->if_mtu = ifr->ifr_mtu;
- break;
-
- case SIOCGIFMTU :
- ifr->ifr_mtu = ifp->if_mtu;
- break;
-
- case SIOCGPPPSTATS:
- p = &pii[ifp->if_unit];
- psp = (struct ppp_stats *) &((struct ifpppstatsreq *)data)->stats;
- bzero(psp, sizeof(struct ppp_stats));
-#ifdef PPP_STATS
- psp->p = p->pii_stats;
-#endif
-#if defined(VJC) && !defined(VJ_NO_STATS)
- psp->vj = p->pii_sc_comp.stats;
-#endif
- break;
-
- case SIOCGPPPCSTATS:
- p = &pii[ifp->if_unit];
- bzero(&p->pii_cstats, sizeof(struct ppp_comp_stats));
-
- /* Make a message to send on the interface's write stream */
- s = splstr();
- q = p->pii_writeq;
- if (q != NULL) {
- putctl1(q, M_CTL, IF_GET_CSTATS);
- /*
- * We assume the message gets passed along immediately, so
- * by the time the putctl1 returns, the request has been
- * processed, the values returned and p->pii_cstats has
- * been updated. If not, we just get zeroes.
- */
- }
- splx(s);
-
- pcp = (struct ppp_comp_stats *)&((struct ifpppcstatsreq *)data)->stats;
- bcopy(&p->pii_cstats, pcp, sizeof(struct ppp_comp_stats));
- break;
-
- default:
- error = EINVAL;
- break;
- }
- splx(s);
- return(error);
-}
-
-#endif