OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [libnetworking/] [pppd/] [modem_example/] [ppp.c] - Diff between revs 30 and 173

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 30 Rev 173
/*
/*
 * if_ppp.c - Point-to-Point Protocol (PPP) Asynchronous driver.
 * if_ppp.c - Point-to-Point Protocol (PPP) Asynchronous driver.
 *
 *
 * Copyright (c) 1989 Carnegie Mellon University.
 * Copyright (c) 1989 Carnegie Mellon University.
 * All rights reserved.
 * All rights reserved.
 *
 *
 * Redistribution and use in source and binary forms are permitted
 * Redistribution and use in source and binary forms are permitted
 * provided that the above copyright notice and this paragraph are
 * provided that the above copyright notice and this paragraph are
 * duplicated in all such forms and that any documentation,
 * duplicated in all such forms and that any documentation,
 * advertising materials, and other materials related to such
 * advertising materials, and other materials related to such
 * distribution and use acknowledge that the software was developed
 * distribution and use acknowledge that the software was developed
 * by Carnegie Mellon University.  The name of the
 * by Carnegie Mellon University.  The name of the
 * University may not be used to endorse or promote products derived
 * University may not be used to endorse or promote products derived
 * from this software without specific prior written permission.
 * from this software without specific prior written permission.
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 *
 * Drew D. Perkins
 * Drew D. Perkins
 * Carnegie Mellon University
 * Carnegie Mellon University
 * 4910 Forbes Ave.
 * 4910 Forbes Ave.
 * Pittsburgh, PA 15213
 * Pittsburgh, PA 15213
 * (412) 268-8576
 * (412) 268-8576
 * ddp@andrew.cmu.edu
 * ddp@andrew.cmu.edu
 *
 *
 * Based on:
 * Based on:
 *      @(#)if_sl.c     7.6.1.2 (Berkeley) 2/15/89
 *      @(#)if_sl.c     7.6.1.2 (Berkeley) 2/15/89
 *
 *
 * Copyright (c) 1987 Regents of the University of California.
 * Copyright (c) 1987 Regents of the University of California.
 * All rights reserved.
 * All rights reserved.
 *
 *
 * Redistribution and use in source and binary forms are permitted
 * Redistribution and use in source and binary forms are permitted
 * provided that the above copyright notice and this paragraph are
 * provided that the above copyright notice and this paragraph are
 * duplicated in all such forms and that any documentation,
 * duplicated in all such forms and that any documentation,
 * advertising materials, and other materials related to such
 * advertising materials, and other materials related to such
 * distribution and use acknowledge that the software was developed
 * distribution and use acknowledge that the software was developed
 * by the University of California, Berkeley.  The name of the
 * by the University of California, Berkeley.  The name of the
 * University may not be used to endorse or promote products derived
 * University may not be used to endorse or promote products derived
 * from this software without specific prior written permission.
 * from this software without specific prior written permission.
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 *
 * Serial Line interface
 * Serial Line interface
 *
 *
 * Rick Adams
 * Rick Adams
 * Center for Seismic Studies
 * Center for Seismic Studies
 * 1300 N 17th Street, Suite 1450
 * 1300 N 17th Street, Suite 1450
 * Arlington, Virginia 22209
 * Arlington, Virginia 22209
 * (703)276-7900
 * (703)276-7900
 * rick@seismo.ARPA
 * rick@seismo.ARPA
 * seismo!rick
 * seismo!rick
 *
 *
 * Pounded on heavily by Chris Torek (chris@mimsy.umd.edu, umcp-cs!chris).
 * Pounded on heavily by Chris Torek (chris@mimsy.umd.edu, umcp-cs!chris).
 * Converted to 4.3BSD Beta by Chris Torek.
 * Converted to 4.3BSD Beta by Chris Torek.
 * Other changes made at Berkeley, based in part on code by Kirk Smith.
 * Other changes made at Berkeley, based in part on code by Kirk Smith.
 *
 *
 * Converted to 4.3BSD+ 386BSD by Brad Parker (brad@cayman.com)
 * Converted to 4.3BSD+ 386BSD by Brad Parker (brad@cayman.com)
 * Added VJ tcp header compression; more unified ioctls
 * Added VJ tcp header compression; more unified ioctls
 *
 *
 * Extensively modified by Paul Mackerras (paulus@cs.anu.edu.au).
 * Extensively modified by Paul Mackerras (paulus@cs.anu.edu.au).
 * Cleaned up a lot of the mbuf-related code to fix bugs that
 * Cleaned up a lot of the mbuf-related code to fix bugs that
 * caused system crashes and packet corruption.  Changed pppstart
 * caused system crashes and packet corruption.  Changed pppstart
 * so that it doesn't just give up with a collision if the whole
 * so that it doesn't just give up with a collision if the whole
 * packet doesn't fit in the output ring buffer.
 * packet doesn't fit in the output ring buffer.
 *
 *
 * Added priority queueing for interactive IP packets, following
 * Added priority queueing for interactive IP packets, following
 * the model of if_sl.c, plus hooks for bpf.
 * the model of if_sl.c, plus hooks for bpf.
 * Paul Mackerras (paulus@cs.anu.edu.au).
 * Paul Mackerras (paulus@cs.anu.edu.au).
 */
 */
 
 
/* $Id: ppp.c,v 1.2 2001-09-27 12:01:57 chris Exp $ */
/* $Id: ppp.c,v 1.2 2001-09-27 12:01:57 chris Exp $ */
/* from if_sl.c,v 1.11 84/10/04 12:54:47 rick Exp */
/* from if_sl.c,v 1.11 84/10/04 12:54:47 rick Exp */
/* from NetBSD: if_ppp.c,v 1.15.2.2 1994/07/28 05:17:58 cgd Exp */
/* from NetBSD: if_ppp.c,v 1.15.2.2 1994/07/28 05:17:58 cgd Exp */
 
 
#include "ppp.h"
#include "ppp.h"
#if NPPP > 0
#if NPPP > 0
/* na razie wylaczmy kompresje*/
/* na razie wylaczmy kompresje*/
 
 
#include <sys/param.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/systm.h>
#include <sys/proc.h>
#include <sys/proc.h>
#include <sys/mbuf.h>
#include <sys/mbuf.h>
#include <sys/socket.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/ioctl.h>
#include <sys/kernel.h>
#include <sys/kernel.h>
#include <sys/time.h>
#include <sys/time.h>
#include <sys/malloc.h>
#include <sys/malloc.h>
 
 
#include <rtems/rtems_bsdnet.h>
#include <rtems/rtems_bsdnet.h>
#include <net/if.h>
#include <net/if.h>
#include <sys/errno.h>
#include <sys/errno.h>
#include <net/if_types.h>
#include <net/if_types.h>
#include <net/netisr.h>
#include <net/netisr.h>
#include <net/route.h>
#include <net/route.h>
#ifdef PPP_FILTER
#ifdef PPP_FILTER
#include <net/bpf.h>
#include <net/bpf.h>
#endif
#endif
 
 
#ifdef INET
#ifdef INET
#include <netinet/in.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/in_systm.h>
#include <netinet/in_var.h>
#include <netinet/in_var.h>
#include <netinet/ip.h>
#include <netinet/ip.h>
#endif
#endif
 
 
#include <bpfilter.h>
#include <bpfilter.h>
#if NBPFILTER > 0
#if NBPFILTER > 0
#include <net/bpf.h>
#include <net/bpf.h>
#endif
#endif
 
 
#ifdef VJC
#ifdef VJC
#include <net/pppcompress.h>
#include <net/pppcompress.h>
#endif
#endif
 
 
#include <net/ppp_defs.h>
#include <net/ppp_defs.h>
#include <net/if_ppp.h>
#include <net/if_ppp.h>
#include <net/if_pppvar.h>
#include <net/if_pppvar.h>
#include <machine/cpu.h>
#include <machine/cpu.h>
 
 
#define splsoftnet      splnet
#define splsoftnet      splnet
 
 
#ifndef NETISR_PPP
#ifndef NETISR_PPP
/* This definition should be moved to net/netisr.h */
/* This definition should be moved to net/netisr.h */
#define NETISR_PPP      26      /* PPP software interrupt */
#define NETISR_PPP      26      /* PPP software interrupt */
#endif
#endif
 
 
#ifdef PPP_COMPRESS
#ifdef PPP_COMPRESS
#define PACKETPTR       struct mbuf *
#define PACKETPTR       struct mbuf *
#include <net/ppp-comp.h>
#include <net/ppp-comp.h>
#endif
#endif
extern struct   ifqueue ipintrq;
extern struct   ifqueue ipintrq;
static int      pppsioctl __P((struct ifnet *, int, caddr_t));
static int      pppsioctl __P((struct ifnet *, int, caddr_t));
static void     ppp_requeue __P((struct ppp_softc *));
static void     ppp_requeue __P((struct ppp_softc *));
static void     ppp_ccp __P((struct ppp_softc *, struct mbuf *m, int rcvd));
static void     ppp_ccp __P((struct ppp_softc *, struct mbuf *m, int rcvd));
static void     ppp_ccp_closed __P((struct ppp_softc *));
static void     ppp_ccp_closed __P((struct ppp_softc *));
static void     ppp_inproc __P((struct ppp_softc *, struct mbuf *));
static void     ppp_inproc __P((struct ppp_softc *, struct mbuf *));
static void     pppdumpm __P((struct mbuf *m0));
static void     pppdumpm __P((struct mbuf *m0));
 
 
/*
/*
 * Some useful mbuf macros not in mbuf.h.
 * Some useful mbuf macros not in mbuf.h.
 */
 */
#define M_IS_CLUSTER(m) ((m)->m_flags & M_EXT)
#define M_IS_CLUSTER(m) ((m)->m_flags & M_EXT)
 
 
#define M_DATASTART(m)  \
#define M_DATASTART(m)  \
        (M_IS_CLUSTER(m) ? (m)->m_ext.ext_buf : \
        (M_IS_CLUSTER(m) ? (m)->m_ext.ext_buf : \
            (m)->m_flags & M_PKTHDR ? (m)->m_pktdat : (m)->m_dat)
            (m)->m_flags & M_PKTHDR ? (m)->m_pktdat : (m)->m_dat)
 
 
#define M_DATASIZE(m)   \
#define M_DATASIZE(m)   \
        (M_IS_CLUSTER(m) ? (m)->m_ext.ext_size : \
        (M_IS_CLUSTER(m) ? (m)->m_ext.ext_size : \
            (m)->m_flags & M_PKTHDR ? MHLEN: MLEN)
            (m)->m_flags & M_PKTHDR ? MHLEN: MLEN)
 
 
/*
/*
 * We steal two bits in the mbuf m_flags, to mark high-priority packets
 * We steal two bits in the mbuf m_flags, to mark high-priority packets
 * for output, and received packets following lost/corrupted packets.
 * for output, and received packets following lost/corrupted packets.
 */
 */
#define M_HIGHPRI       0x2000  /* output packet for sc_fastq */
#define M_HIGHPRI       0x2000  /* output packet for sc_fastq */
#define M_ERRMARK       0x4000  /* steal a bit in mbuf m_flags */
#define M_ERRMARK       0x4000  /* steal a bit in mbuf m_flags */
 
 
 
 
#ifdef PPP_COMPRESS
#ifdef PPP_COMPRESS
/*
/*
 * List of compressors we know about.
 * List of compressors we know about.
 * We leave some space so maybe we can modload compressors.
 * We leave some space so maybe we can modload compressors.
 */
 */
 
 
extern struct compressor ppp_bsd_compress;
extern struct compressor ppp_bsd_compress;
extern struct compressor ppp_deflate, ppp_deflate_draft;
extern struct compressor ppp_deflate, ppp_deflate_draft;
 
 
 
 
struct compressor *ppp_compressors[8] = {
struct compressor *ppp_compressors[8] = {
#if DO_BSD_COMPRESS
#if DO_BSD_COMPRESS
    &ppp_bsd_compress,
    &ppp_bsd_compress,
#endif
#endif
#if DO_DEFLATE
#if DO_DEFLATE
    &ppp_deflate,
    &ppp_deflate,
    &ppp_deflate_draft,
    &ppp_deflate_draft,
#endif
#endif
    NULL
    NULL
};
};
#endif /* PPP_COMPRESS */
#endif /* PPP_COMPRESS */
static struct timeval ppp_time;
static struct timeval ppp_time;
 
 
TEXT_SET(pseudo_set, pppattach);
TEXT_SET(pseudo_set, pppattach);
 
 
/*
/*
 * Called from boot code to establish ppp interfaces.
 * Called from boot code to establish ppp interfaces.
 */
 */
int rtems_ppp_driver_attach (struct rtems_bsdnet_ifconfig *config)
int rtems_ppp_driver_attach (struct rtems_bsdnet_ifconfig *config)
{
{
    register struct ppp_softc *sc;
    register struct ppp_softc *sc;
    register int i = 0;
    register int i = 0;
    extern void (*netisrs[])__P((void));
    extern void (*netisrs[])__P((void));
 
 
    for (sc = ppp_softc; i < NPPP; sc++) {
    for (sc = ppp_softc; i < NPPP; sc++) {
        sc->sc_if.if_name = "ppp";
        sc->sc_if.if_name = "ppp";
        sc->sc_if.if_unit = i++;
        sc->sc_if.if_unit = i++;
        sc->sc_if.if_mtu = PPP_MTU;
        sc->sc_if.if_mtu = PPP_MTU;
        sc->sc_if.if_flags = IFF_POINTOPOINT | IFF_MULTICAST;
        sc->sc_if.if_flags = IFF_POINTOPOINT | IFF_MULTICAST;
        sc->sc_if.if_type = IFT_PPP;
        sc->sc_if.if_type = IFT_PPP;
        sc->sc_if.if_hdrlen = PPP_HDRLEN;
        sc->sc_if.if_hdrlen = PPP_HDRLEN;
        sc->sc_if.if_ioctl = pppsioctl;
        sc->sc_if.if_ioctl = pppsioctl;
        sc->sc_if.if_output = pppoutput;
        sc->sc_if.if_output = pppoutput;
        sc->sc_if.if_snd.ifq_maxlen = IFQ_MAXLEN;
        sc->sc_if.if_snd.ifq_maxlen = IFQ_MAXLEN;
        sc->sc_inq.ifq_maxlen = IFQ_MAXLEN;
        sc->sc_inq.ifq_maxlen = IFQ_MAXLEN;
        sc->sc_fastq.ifq_maxlen = IFQ_MAXLEN;
        sc->sc_fastq.ifq_maxlen = IFQ_MAXLEN;
        sc->sc_rawq.ifq_maxlen = IFQ_MAXLEN;
        sc->sc_rawq.ifq_maxlen = IFQ_MAXLEN;
        if_attach(&sc->sc_if);
        if_attach(&sc->sc_if);
#if NBPFILTER > 0
#if NBPFILTER > 0
        bpfattach(&sc->sc_bpf, &sc->sc_if, DLT_PPP, PPP_HDRLEN);
        bpfattach(&sc->sc_bpf, &sc->sc_if, DLT_PPP, PPP_HDRLEN);
#endif
#endif
    }
    }
/* wpisane na twardo do rtems_glue.c
/* wpisane na twardo do rtems_glue.c
    netisrs[NETISR_PPP] = pppintr; */
    netisrs[NETISR_PPP] = pppintr; */
        return 1;
        return 1;
}
}
 
 
/*
/*
 * Allocate a ppp interface unit and initialize it.
 * Allocate a ppp interface unit and initialize it.
 */
 */
struct ppp_softc *
struct ppp_softc *
pppalloc(pid)
pppalloc(pid)
    pid_t pid;
    pid_t pid;
{
{
    int nppp, i;
    int nppp, i;
    struct ppp_softc *sc;
    struct ppp_softc *sc;
    for (nppp = 0, sc = ppp_softc; nppp < NPPP; nppp++, sc++)
    for (nppp = 0, sc = ppp_softc; nppp < NPPP; nppp++, sc++)
        if (sc->sc_xfer == pid) {
        if (sc->sc_xfer == pid) {
            sc->sc_xfer = 0;
            sc->sc_xfer = 0;
            return sc;
            return sc;
        }
        }
    for (nppp = 0, sc = ppp_softc; nppp < NPPP; nppp++, sc++)
    for (nppp = 0, sc = ppp_softc; nppp < NPPP; nppp++, sc++)
        if (sc->sc_devp == NULL)
        if (sc->sc_devp == NULL)
            break;
            break;
    if (nppp >= NPPP)
    if (nppp >= NPPP)
        return NULL;
        return NULL;
 
 
    sc->sc_flags = 0;
    sc->sc_flags = 0;
    sc->sc_mru = PPP_MRU;
    sc->sc_mru = PPP_MRU;
    sc->sc_relinq = NULL;
    sc->sc_relinq = NULL;
    bzero((char *)&sc->sc_stats, sizeof(sc->sc_stats));
    bzero((char *)&sc->sc_stats, sizeof(sc->sc_stats));
#ifdef VJC
#ifdef VJC
    sc->sc_comp=malloc(sizeof(struct vjcompress),M_DEVBUF, M_NOWAIT);
    sc->sc_comp=malloc(sizeof(struct vjcompress),M_DEVBUF, M_NOWAIT);
    if (sc->sc_comp)
    if (sc->sc_comp)
        vj_compress_init(sc->sc_comp, -1);
        vj_compress_init(sc->sc_comp, -1);
#endif
#endif
#ifdef PPP_COMPRESS
#ifdef PPP_COMPRESS
    sc->sc_xc_state = NULL;
    sc->sc_xc_state = NULL;
    sc->sc_rc_state = NULL;
    sc->sc_rc_state = NULL;
#endif /* PPP_COMPRESS */
#endif /* PPP_COMPRESS */
    for (i = 0; i < NUM_NP; ++i)
    for (i = 0; i < NUM_NP; ++i)
        sc->sc_npmode[i] = NPMODE_ERROR;
        sc->sc_npmode[i] = NPMODE_ERROR;
    sc->sc_npqueue = NULL;
    sc->sc_npqueue = NULL;
    sc->sc_npqtail = &sc->sc_npqueue;
    sc->sc_npqtail = &sc->sc_npqueue;
         microtime(&ppp_time);
         microtime(&ppp_time);
    sc->sc_last_sent = sc->sc_last_recv = ppp_time.tv_sec;
    sc->sc_last_sent = sc->sc_last_recv = ppp_time.tv_sec;
 
 
    return sc;
    return sc;
}
}
 
 
/*
/*
 * Deallocate a ppp unit.  Must be called at splsoftnet or higher.
 * Deallocate a ppp unit.  Must be called at splsoftnet or higher.
 */
 */
void
void
pppdealloc(sc)
pppdealloc(sc)
    struct ppp_softc *sc;
    struct ppp_softc *sc;
{
{
    struct mbuf *m;
    struct mbuf *m;
 
 
    if_down(&sc->sc_if);
    if_down(&sc->sc_if);
    sc->sc_if.if_flags &= ~(IFF_UP|IFF_RUNNING);
    sc->sc_if.if_flags &= ~(IFF_UP|IFF_RUNNING);
    sc->sc_devp = NULL;
    sc->sc_devp = NULL;
    sc->sc_xfer = 0;
    sc->sc_xfer = 0;
    for (;;) {
    for (;;) {
        IF_DEQUEUE(&sc->sc_rawq, m);
        IF_DEQUEUE(&sc->sc_rawq, m);
        if (m == NULL)
        if (m == NULL)
            break;
            break;
        m_freem(m);
        m_freem(m);
    }
    }
    for (;;) {
    for (;;) {
        IF_DEQUEUE(&sc->sc_inq, m);
        IF_DEQUEUE(&sc->sc_inq, m);
        if (m == NULL)
        if (m == NULL)
            break;
            break;
        m_freem(m);
        m_freem(m);
    }
    }
    for (;;) {
    for (;;) {
        IF_DEQUEUE(&sc->sc_fastq, m);
        IF_DEQUEUE(&sc->sc_fastq, m);
        if (m == NULL)
        if (m == NULL)
            break;
            break;
        m_freem(m);
        m_freem(m);
    }
    }
    while ((m = sc->sc_npqueue) != NULL) {
    while ((m = sc->sc_npqueue) != NULL) {
        sc->sc_npqueue = m->m_nextpkt;
        sc->sc_npqueue = m->m_nextpkt;
        m_freem(m);
        m_freem(m);
    }
    }
    if (sc->sc_togo != NULL) {
    if (sc->sc_togo != NULL) {
        m_freem(sc->sc_togo);
        m_freem(sc->sc_togo);
        sc->sc_togo = NULL;
        sc->sc_togo = NULL;
    }
    }
#ifdef PPP_COMPRESS
#ifdef PPP_COMPRESS
    ppp_ccp_closed(sc);
    ppp_ccp_closed(sc);
    sc->sc_xc_state = NULL;
    sc->sc_xc_state = NULL;
    sc->sc_rc_state = NULL;
    sc->sc_rc_state = NULL;
#endif /* PPP_COMPRESS */
#endif /* PPP_COMPRESS */
#ifdef PPP_FILTER
#ifdef PPP_FILTER
    if (sc->sc_pass_filt.bf_insns != 0) {
    if (sc->sc_pass_filt.bf_insns != 0) {
        free(sc->sc_pass_filt.bf_insns, M_DEVBUF);
        free(sc->sc_pass_filt.bf_insns, M_DEVBUF);
        sc->sc_pass_filt.bf_insns = 0;
        sc->sc_pass_filt.bf_insns = 0;
        sc->sc_pass_filt.bf_len = 0;
        sc->sc_pass_filt.bf_len = 0;
    }
    }
    if (sc->sc_active_filt.bf_insns != 0) {
    if (sc->sc_active_filt.bf_insns != 0) {
        free(sc->sc_active_filt.bf_insns, M_DEVBUF);
        free(sc->sc_active_filt.bf_insns, M_DEVBUF);
        sc->sc_active_filt.bf_insns = 0;
        sc->sc_active_filt.bf_insns = 0;
        sc->sc_active_filt.bf_len = 0;
        sc->sc_active_filt.bf_len = 0;
    }
    }
#endif /* PPP_FILTER */
#endif /* PPP_FILTER */
#ifdef VJC
#ifdef VJC
    if (sc->sc_comp != 0) {
    if (sc->sc_comp != 0) {
        free(sc->sc_comp, M_DEVBUF);
        free(sc->sc_comp, M_DEVBUF);
        sc->sc_comp = 0;
        sc->sc_comp = 0;
    }
    }
#endif
#endif
}
}
 
 
/*
/*
 * Ioctl routine for generic ppp devices.
 * Ioctl routine for generic ppp devices.
 */
 */
int
int
pppioctl(sc, cmd, data, flag, p)
pppioctl(sc, cmd, data, flag, p)
    struct ppp_softc *sc;
    struct ppp_softc *sc;
    int cmd;
    int cmd;
    caddr_t data;
    caddr_t data;
    int flag;
    int flag;
    struct proc *p;
    struct proc *p;
{
{
    int s, error, flags, mru, nb, npx;
    int s, error, flags, mru, nb, npx;
    struct ppp_option_data *odp;
    struct ppp_option_data *odp;
    struct compressor **cp;
    struct compressor **cp;
    struct npioctl *npi;
    struct npioctl *npi;
    time_t t;
    time_t t;
#ifdef PPP_FILTER
#ifdef PPP_FILTER
    struct bpf_program *bp, *nbp;
    struct bpf_program *bp, *nbp;
    struct bpf_insn *newcode, *oldcode;
    struct bpf_insn *newcode, *oldcode;
    int newcodelen;
    int newcodelen;
#endif /* PPP_FILTER */
#endif /* PPP_FILTER */
#ifdef  PPP_COMPRESS
#ifdef  PPP_COMPRESS
    u_char ccp_option[CCP_MAX_OPTION_LENGTH];
    u_char ccp_option[CCP_MAX_OPTION_LENGTH];
#endif
#endif
 
 
    switch (cmd) {
    switch (cmd) {
    case FIONREAD:
    case FIONREAD:
        *(int *)data = sc->sc_inq.ifq_len;
        *(int *)data = sc->sc_inq.ifq_len;
        break;
        break;
 
 
    case PPPIOCGUNIT:
    case PPPIOCGUNIT:
        *(int *)data = sc->sc_if.if_unit;
        *(int *)data = sc->sc_if.if_unit;
        break;
        break;
 
 
    case PPPIOCGFLAGS:
    case PPPIOCGFLAGS:
        *(u_int *)data = sc->sc_flags;
        *(u_int *)data = sc->sc_flags;
        break;
        break;
 
 
    case PPPIOCSFLAGS:
    case PPPIOCSFLAGS:
        flags = *(int *)data & SC_MASK;
        flags = *(int *)data & SC_MASK;
        s = splsoftnet();
        s = splsoftnet();
#ifdef PPP_COMPRESS
#ifdef PPP_COMPRESS
        if (sc->sc_flags & SC_CCP_OPEN && !(flags & SC_CCP_OPEN))
        if (sc->sc_flags & SC_CCP_OPEN && !(flags & SC_CCP_OPEN))
            ppp_ccp_closed(sc);
            ppp_ccp_closed(sc);
#endif
#endif
        splimp();
        splimp();
        sc->sc_flags = (sc->sc_flags & ~SC_MASK) | flags;
        sc->sc_flags = (sc->sc_flags & ~SC_MASK) | flags;
        splx(s);
        splx(s);
        break;
        break;
 
 
    case PPPIOCSMRU:
    case PPPIOCSMRU:
        mru = *(int *)data;
        mru = *(int *)data;
        if (mru >= PPP_MRU && mru <= PPP_MAXMRU)
        if (mru >= PPP_MRU && mru <= PPP_MAXMRU)
            sc->sc_mru = mru;
            sc->sc_mru = mru;
        break;
        break;
 
 
    case PPPIOCGMRU:
    case PPPIOCGMRU:
        *(int *)data = sc->sc_mru;
        *(int *)data = sc->sc_mru;
        break;
        break;
 
 
#ifdef VJC
#ifdef VJC
    case PPPIOCSMAXCID:
    case PPPIOCSMAXCID:
        if (sc->sc_comp) {
        if (sc->sc_comp) {
            s = splsoftnet();
            s = splsoftnet();
            vj_compress_init(sc->sc_comp, *(int *)data);
            vj_compress_init(sc->sc_comp, *(int *)data);
            splx(s);
            splx(s);
        }
        }
        break;
        break;
#endif
#endif
 
 
    case PPPIOCXFERUNIT:
    case PPPIOCXFERUNIT:
        sc->sc_xfer = 0; /* Always root p->p_pid;*/
        sc->sc_xfer = 0; /* Always root p->p_pid;*/
        break;
        break;
 
 
#ifdef PPP_COMPRESS
#ifdef PPP_COMPRESS
    case PPPIOCSCOMPRESS:
    case PPPIOCSCOMPRESS:
        odp = (struct ppp_option_data *) data;
        odp = (struct ppp_option_data *) data;
        nb = odp->length;
        nb = odp->length;
        if (nb > sizeof(ccp_option))
        if (nb > sizeof(ccp_option))
            nb = sizeof(ccp_option);
            nb = sizeof(ccp_option);
        if ((error = copyin(odp->ptr, ccp_option, nb)) != 0)
        if ((error = copyin(odp->ptr, ccp_option, nb)) != 0)
            return (error);
            return (error);
        if (ccp_option[1] < 2)  /* preliminary check on the length byte */
        if (ccp_option[1] < 2)  /* preliminary check on the length byte */
            return (EINVAL);
            return (EINVAL);
        for (cp = ppp_compressors; *cp != NULL; ++cp)
        for (cp = ppp_compressors; *cp != NULL; ++cp)
            if ((*cp)->compress_proto == ccp_option[0]) {
            if ((*cp)->compress_proto == ccp_option[0]) {
                /*
                /*
                 * Found a handler for the protocol - try to allocate
                 * Found a handler for the protocol - try to allocate
                 * a compressor or decompressor.
                 * a compressor or decompressor.
                 */
                 */
                error = 0;
                error = 0;
                if (odp->transmit) {
                if (odp->transmit) {
                    s = splsoftnet();
                    s = splsoftnet();
                    if (sc->sc_xc_state != NULL)
                    if (sc->sc_xc_state != NULL)
                        (*sc->sc_xcomp->comp_free)(sc->sc_xc_state);
                        (*sc->sc_xcomp->comp_free)(sc->sc_xc_state);
                    sc->sc_xcomp = *cp;
                    sc->sc_xcomp = *cp;
                    sc->sc_xc_state = (*cp)->comp_alloc(ccp_option, nb);
                    sc->sc_xc_state = (*cp)->comp_alloc(ccp_option, nb);
                    if (sc->sc_xc_state == NULL) {
                    if (sc->sc_xc_state == NULL) {
                        if (sc->sc_flags & SC_DEBUG)
                        if (sc->sc_flags & SC_DEBUG)
                            printf("ppp%d: comp_alloc failed\n",
                            printf("ppp%d: comp_alloc failed\n",
                               sc->sc_if.if_unit);
                               sc->sc_if.if_unit);
                        error = ENOBUFS;
                        error = ENOBUFS;
                    }
                    }
                    splimp();
                    splimp();
                    sc->sc_flags &= ~SC_COMP_RUN;
                    sc->sc_flags &= ~SC_COMP_RUN;
                    splx(s);
                    splx(s);
                } else {
                } else {
                    s = splsoftnet();
                    s = splsoftnet();
                    if (sc->sc_rc_state != NULL)
                    if (sc->sc_rc_state != NULL)
                        (*sc->sc_rcomp->decomp_free)(sc->sc_rc_state);
                        (*sc->sc_rcomp->decomp_free)(sc->sc_rc_state);
                    sc->sc_rcomp = *cp;
                    sc->sc_rcomp = *cp;
                    sc->sc_rc_state = (*cp)->decomp_alloc(ccp_option, nb);
                    sc->sc_rc_state = (*cp)->decomp_alloc(ccp_option, nb);
                    if (sc->sc_rc_state == NULL) {
                    if (sc->sc_rc_state == NULL) {
                        if (sc->sc_flags & SC_DEBUG)
                        if (sc->sc_flags & SC_DEBUG)
                            printf("ppp%d: decomp_alloc failed\n",
                            printf("ppp%d: decomp_alloc failed\n",
                               sc->sc_if.if_unit);
                               sc->sc_if.if_unit);
                        error = ENOBUFS;
                        error = ENOBUFS;
                    }
                    }
                    splimp();
                    splimp();
                    sc->sc_flags &= ~SC_DECOMP_RUN;
                    sc->sc_flags &= ~SC_DECOMP_RUN;
                    splx(s);
                    splx(s);
                }
                }
                return (error);
                return (error);
            }
            }
        if (sc->sc_flags & SC_DEBUG)
        if (sc->sc_flags & SC_DEBUG)
            printf("ppp%d: no compressor for [%x %x %x], %x\n",
            printf("ppp%d: no compressor for [%x %x %x], %x\n",
                   sc->sc_if.if_unit, ccp_option[0], ccp_option[1],
                   sc->sc_if.if_unit, ccp_option[0], ccp_option[1],
                   ccp_option[2], nb);
                   ccp_option[2], nb);
        return (EINVAL);        /* no handler found */
        return (EINVAL);        /* no handler found */
#endif /* PPP_COMPRESS */
#endif /* PPP_COMPRESS */
 
 
    case PPPIOCGNPMODE:
    case PPPIOCGNPMODE:
    case PPPIOCSNPMODE:
    case PPPIOCSNPMODE:
        npi = (struct npioctl *) data;
        npi = (struct npioctl *) data;
        switch (npi->protocol) {
        switch (npi->protocol) {
        case PPP_IP:
        case PPP_IP:
            npx = NP_IP;
            npx = NP_IP;
            break;
            break;
        default:
        default:
            return EINVAL;
            return EINVAL;
        }
        }
        if (cmd == PPPIOCGNPMODE) {
        if (cmd == PPPIOCGNPMODE) {
            npi->mode = sc->sc_npmode[npx];
            npi->mode = sc->sc_npmode[npx];
        } else {
        } else {
            if (npi->mode != sc->sc_npmode[npx]) {
            if (npi->mode != sc->sc_npmode[npx]) {
                s = splsoftnet();
                s = splsoftnet();
                sc->sc_npmode[npx] = npi->mode;
                sc->sc_npmode[npx] = npi->mode;
                if (npi->mode != NPMODE_QUEUE) {
                if (npi->mode != NPMODE_QUEUE) {
                    ppp_requeue(sc);
                    ppp_requeue(sc);
                    (*sc->sc_start)(sc);
                    (*sc->sc_start)(sc);
                }
                }
                splx(s);
                splx(s);
            }
            }
        }
        }
        break;
        break;
 
 
    case PPPIOCGIDLE:
    case PPPIOCGIDLE:
        s = splsoftnet();
        s = splsoftnet();
        microtime(&ppp_time);
        microtime(&ppp_time);
        t = ppp_time.tv_sec;
        t = ppp_time.tv_sec;
        ((struct ppp_idle *)data)->xmit_idle = t - sc->sc_last_sent;
        ((struct ppp_idle *)data)->xmit_idle = t - sc->sc_last_sent;
        ((struct ppp_idle *)data)->recv_idle = t - sc->sc_last_recv;
        ((struct ppp_idle *)data)->recv_idle = t - sc->sc_last_recv;
        splx(s);
        splx(s);
        break;
        break;
 
 
#ifdef PPP_FILTER
#ifdef PPP_FILTER
    case PPPIOCSPASS:
    case PPPIOCSPASS:
    case PPPIOCSACTIVE:
    case PPPIOCSACTIVE:
        nbp = (struct bpf_program *) data;
        nbp = (struct bpf_program *) data;
        if ((unsigned) nbp->bf_len > BPF_MAXINSNS)
        if ((unsigned) nbp->bf_len > BPF_MAXINSNS)
            return EINVAL;
            return EINVAL;
        newcodelen = nbp->bf_len * sizeof(struct bpf_insn);
        newcodelen = nbp->bf_len * sizeof(struct bpf_insn);
        if (newcodelen != 0) {
        if (newcodelen != 0) {
            newcode=(struct bpf_insn *) malloc (newcodelen, M_DEVBUF, M_WAITOK);
            newcode=(struct bpf_insn *) malloc (newcodelen, M_DEVBUF, M_WAITOK);
            if (newcode == 0) {
            if (newcode == 0) {
                return EINVAL;          /* or sumpin */
                return EINVAL;          /* or sumpin */
            }
            }
            if ((error = copyin((caddr_t)nbp->bf_insns, (caddr_t)newcode,
            if ((error = copyin((caddr_t)nbp->bf_insns, (caddr_t)newcode,
                               newcodelen)) != 0) {
                               newcodelen)) != 0) {
                free(newcode, M_DEVBUF);
                free(newcode, M_DEVBUF);
                return error;
                return error;
            }
            }
            if (!bpf_validate(newcode, nbp->bf_len)) {
            if (!bpf_validate(newcode, nbp->bf_len)) {
                free(newcode, M_DEVBUF);
                free(newcode, M_DEVBUF);
                return EINVAL;
                return EINVAL;
            }
            }
        } else
        } else
            newcode = 0;
            newcode = 0;
        bp = (cmd == PPPIOCSPASS)? &sc->sc_pass_filt: &sc->sc_active_filt;
        bp = (cmd == PPPIOCSPASS)? &sc->sc_pass_filt: &sc->sc_active_filt;
        oldcode = bp->bf_insns;
        oldcode = bp->bf_insns;
        s = splimp();
        s = splimp();
        bp->bf_len = nbp->bf_len;
        bp->bf_len = nbp->bf_len;
        bp->bf_insns = newcode;
        bp->bf_insns = newcode;
        splx(s);
        splx(s);
        if (oldcode != 0)
        if (oldcode != 0)
            free(oldcode, M_DEVBUF);
            free(oldcode, M_DEVBUF);
        break;
        break;
#endif
#endif
 
 
    default:
    default:
        return (-1);
        return (-1);
    }
    }
    return (0);
    return (0);
}
}
 
 
/*
/*
 * Process an ioctl request to the ppp network interface.
 * Process an ioctl request to the ppp network interface.
 */
 */
static int
static int
pppsioctl(ifp, cmd, data)
pppsioctl(ifp, cmd, data)
    register struct ifnet *ifp;
    register struct ifnet *ifp;
    int cmd;
    int cmd;
    caddr_t data;
    caddr_t data;
{
{
/*    struct proc *p = curproc; *//* XXX */
/*    struct proc *p = curproc; *//* XXX */
    register struct ppp_softc *sc = &ppp_softc[ifp->if_unit];
    register struct ppp_softc *sc = &ppp_softc[ifp->if_unit];
    register struct ifaddr *ifa = (struct ifaddr *)data;
    register struct ifaddr *ifa = (struct ifaddr *)data;
    register struct ifreq *ifr = (struct ifreq *)data;
    register struct ifreq *ifr = (struct ifreq *)data;
    struct ppp_stats *psp;
    struct ppp_stats *psp;
#ifdef  PPP_COMPRESS
#ifdef  PPP_COMPRESS
    struct ppp_comp_stats *pcp;
    struct ppp_comp_stats *pcp;
#endif
#endif
    int s = splimp(), error = 0;
    int s = splimp(), error = 0;
 
 
    switch (cmd) {
    switch (cmd) {
    case SIOCSIFFLAGS:
    case SIOCSIFFLAGS:
        if ((ifp->if_flags & IFF_RUNNING) == 0)
        if ((ifp->if_flags & IFF_RUNNING) == 0)
            ifp->if_flags &= ~IFF_UP;
            ifp->if_flags &= ~IFF_UP;
        break;
        break;
 
 
    case SIOCSIFADDR:
    case SIOCSIFADDR:
        if (ifa->ifa_addr->sa_family != AF_INET)
        if (ifa->ifa_addr->sa_family != AF_INET)
            error = EAFNOSUPPORT;
            error = EAFNOSUPPORT;
        break;
        break;
 
 
    case SIOCSIFDSTADDR:
    case SIOCSIFDSTADDR:
        if (ifa->ifa_addr->sa_family != AF_INET)
        if (ifa->ifa_addr->sa_family != AF_INET)
            error = EAFNOSUPPORT;
            error = EAFNOSUPPORT;
        break;
        break;
 
 
    case SIOCSIFMTU:
    case SIOCSIFMTU:
        sc->sc_if.if_mtu = ifr->ifr_mtu;
        sc->sc_if.if_mtu = ifr->ifr_mtu;
        break;
        break;
 
 
    case SIOCGIFMTU:
    case SIOCGIFMTU:
        ifr->ifr_mtu = sc->sc_if.if_mtu;
        ifr->ifr_mtu = sc->sc_if.if_mtu;
        break;
        break;
 
 
    case SIOCADDMULTI:
    case SIOCADDMULTI:
    case SIOCDELMULTI:
    case SIOCDELMULTI:
        if (ifr == 0) {
        if (ifr == 0) {
            error = EAFNOSUPPORT;
            error = EAFNOSUPPORT;
            break;
            break;
        }
        }
        switch(ifr->ifr_addr.sa_family) {
        switch(ifr->ifr_addr.sa_family) {
#ifdef INET
#ifdef INET
        case AF_INET:
        case AF_INET:
            break;
            break;
#endif
#endif
        default:
        default:
            error = EAFNOSUPPORT;
            error = EAFNOSUPPORT;
            break;
            break;
        }
        }
        break;
        break;
        case SIO_RTEMS_SHOW_STATS:
        case SIO_RTEMS_SHOW_STATS:
  printf ("              MRU:%-8lu", sc->sc_mru);
  printf ("              MRU:%-8lu", sc->sc_mru);
  printf ("   Bytes received:%-8lu", sc->sc_stats.ppp_ibytes);
  printf ("   Bytes received:%-8lu", sc->sc_stats.ppp_ibytes);
  printf (" Packets received:%-8lu", sc->sc_stats.ppp_ipackets);
  printf (" Packets received:%-8lu", sc->sc_stats.ppp_ipackets);
  printf ("   Receive errors:%-8lu\n", sc->sc_stats.ppp_ierrors);
  printf ("   Receive errors:%-8lu\n", sc->sc_stats.ppp_ierrors);
  printf ("       Bytes sent:%-8lu", sc->sc_stats.ppp_obytes);
  printf ("       Bytes sent:%-8lu", sc->sc_stats.ppp_obytes);
  printf ("     Packets sent:%-8lu", sc->sc_stats.ppp_opackets);
  printf ("     Packets sent:%-8lu", sc->sc_stats.ppp_opackets);
  printf ("  Transmit errors:%-8lu\n", sc->sc_stats.ppp_oerrors);
  printf ("  Transmit errors:%-8lu\n", sc->sc_stats.ppp_oerrors);
 
 
        break;
        break;
 
 
 
 
    case SIOCGPPPSTATS:
    case SIOCGPPPSTATS:
        psp = &((struct ifpppstatsreq *) data)->stats;
        psp = &((struct ifpppstatsreq *) data)->stats;
        bzero(psp, sizeof(*psp));
        bzero(psp, sizeof(*psp));
        psp->p = sc->sc_stats;
        psp->p = sc->sc_stats;
#if defined(VJC) && !defined(SL_NO_STATS)
#if defined(VJC) && !defined(SL_NO_STATS)
        if (sc->sc_comp) {
        if (sc->sc_comp) {
            psp->vj.vjs_packets = sc->sc_comp->sls_packets;
            psp->vj.vjs_packets = sc->sc_comp->sls_packets;
            psp->vj.vjs_compressed = sc->sc_comp->sls_compressed;
            psp->vj.vjs_compressed = sc->sc_comp->sls_compressed;
            psp->vj.vjs_searches = sc->sc_comp->sls_searches;
            psp->vj.vjs_searches = sc->sc_comp->sls_searches;
            psp->vj.vjs_misses = sc->sc_comp->sls_misses;
            psp->vj.vjs_misses = sc->sc_comp->sls_misses;
            psp->vj.vjs_uncompressedin = sc->sc_comp->sls_uncompressedin;
            psp->vj.vjs_uncompressedin = sc->sc_comp->sls_uncompressedin;
            psp->vj.vjs_compressedin = sc->sc_comp->sls_compressedin;
            psp->vj.vjs_compressedin = sc->sc_comp->sls_compressedin;
            psp->vj.vjs_errorin = sc->sc_comp->sls_errorin;
            psp->vj.vjs_errorin = sc->sc_comp->sls_errorin;
            psp->vj.vjs_tossed = sc->sc_comp->sls_tossed;
            psp->vj.vjs_tossed = sc->sc_comp->sls_tossed;
        }
        }
#endif /* VJC */
#endif /* VJC */
        break;
        break;
 
 
#ifdef PPP_COMPRESS
#ifdef PPP_COMPRESS
    case SIOCGPPPCSTATS:
    case SIOCGPPPCSTATS:
        pcp = &((struct ifpppcstatsreq *) data)->stats;
        pcp = &((struct ifpppcstatsreq *) data)->stats;
        bzero(pcp, sizeof(*pcp));
        bzero(pcp, sizeof(*pcp));
        if (sc->sc_xc_state != NULL)
        if (sc->sc_xc_state != NULL)
            (*sc->sc_xcomp->comp_stat)(sc->sc_xc_state, &pcp->c);
            (*sc->sc_xcomp->comp_stat)(sc->sc_xc_state, &pcp->c);
        if (sc->sc_rc_state != NULL)
        if (sc->sc_rc_state != NULL)
            (*sc->sc_rcomp->decomp_stat)(sc->sc_rc_state, &pcp->d);
            (*sc->sc_rcomp->decomp_stat)(sc->sc_rc_state, &pcp->d);
        break;
        break;
#endif /* PPP_COMPRESS */
#endif /* PPP_COMPRESS */
 
 
    default:
    default:
        error = EINVAL;
        error = EINVAL;
    }
    }
    splx(s);
    splx(s);
    return (error);
    return (error);
}
}
 
 
/*
/*
 * Queue a packet.  Start transmission if not active.
 * Queue a packet.  Start transmission if not active.
 * Packet is placed in Information field of PPP frame.
 * Packet is placed in Information field of PPP frame.
 */
 */
int
int
pppoutput(ifp, m0, dst, rtp)
pppoutput(ifp, m0, dst, rtp)
    struct ifnet *ifp;
    struct ifnet *ifp;
    struct mbuf *m0;
    struct mbuf *m0;
    struct sockaddr *dst;
    struct sockaddr *dst;
    struct rtentry *rtp;
    struct rtentry *rtp;
{
{
    register struct ppp_softc *sc = &ppp_softc[ifp->if_unit];
    register struct ppp_softc *sc = &ppp_softc[ifp->if_unit];
    int protocol, address, control;
    int protocol, address, control;
    u_char *cp;
    u_char *cp;
    int s, error;
    int s, error;
    struct ip *ip;
    struct ip *ip;
    struct ifqueue *ifq;
    struct ifqueue *ifq;
    enum NPmode mode;
    enum NPmode mode;
    int len;
    int len;
    struct mbuf *m;
    struct mbuf *m;
    if (sc->sc_devp == NULL || (ifp->if_flags & IFF_RUNNING) == 0
    if (sc->sc_devp == NULL || (ifp->if_flags & IFF_RUNNING) == 0
        || ((ifp->if_flags & IFF_UP) == 0 && dst->sa_family != AF_UNSPEC)) {
        || ((ifp->if_flags & IFF_UP) == 0 && dst->sa_family != AF_UNSPEC)) {
        error = ENETDOWN;       /* sort of */
        error = ENETDOWN;       /* sort of */
        goto bad;
        goto bad;
    }
    }
 
 
    /*
    /*
     * Compute PPP header.
     * Compute PPP header.
     */
     */
    m0->m_flags &= ~M_HIGHPRI;
    m0->m_flags &= ~M_HIGHPRI;
    switch (dst->sa_family) {
    switch (dst->sa_family) {
#ifdef INET
#ifdef INET
    case AF_INET:
    case AF_INET:
        address = PPP_ALLSTATIONS;
        address = PPP_ALLSTATIONS;
        control = PPP_UI;
        control = PPP_UI;
        protocol = PPP_IP;
        protocol = PPP_IP;
        mode = sc->sc_npmode[NP_IP];
        mode = sc->sc_npmode[NP_IP];
 
 
        /*
        /*
         * If this packet has the "low delay" bit set in the IP header,
         * If this packet has the "low delay" bit set in the IP header,
         * put it on the fastq instead.
         * put it on the fastq instead.
         */
         */
        ip = mtod(m0, struct ip *);
        ip = mtod(m0, struct ip *);
        if (ip->ip_tos & IPTOS_LOWDELAY)
        if (ip->ip_tos & IPTOS_LOWDELAY)
            m0->m_flags |= M_HIGHPRI;
            m0->m_flags |= M_HIGHPRI;
        break;
        break;
#endif
#endif
    case AF_UNSPEC:
    case AF_UNSPEC:
        address = PPP_ADDRESS(dst->sa_data);
        address = PPP_ADDRESS(dst->sa_data);
        control = PPP_CONTROL(dst->sa_data);
        control = PPP_CONTROL(dst->sa_data);
        protocol = PPP_PROTOCOL(dst->sa_data);
        protocol = PPP_PROTOCOL(dst->sa_data);
        mode = NPMODE_PASS;
        mode = NPMODE_PASS;
        break;
        break;
    default:
    default:
        printf("ppp%d: af%d not supported\n", ifp->if_unit, dst->sa_family);
        printf("ppp%d: af%d not supported\n", ifp->if_unit, dst->sa_family);
        error = EAFNOSUPPORT;
        error = EAFNOSUPPORT;
        goto bad;
        goto bad;
    }
    }
 
 
    /*
    /*
     * Drop this packet, or return an error, if necessary.
     * Drop this packet, or return an error, if necessary.
     */
     */
    if (mode == NPMODE_ERROR) {
    if (mode == NPMODE_ERROR) {
        error = ENETDOWN;
        error = ENETDOWN;
        goto bad;
        goto bad;
    }
    }
    if (mode == NPMODE_DROP) {
    if (mode == NPMODE_DROP) {
        error = 0;
        error = 0;
        goto bad;
        goto bad;
    }
    }
 
 
    /*
    /*
     * Add PPP header.  If no space in first mbuf, allocate another.
     * Add PPP header.  If no space in first mbuf, allocate another.
     * (This assumes M_LEADINGSPACE is always 0 for a cluster mbuf.)
     * (This assumes M_LEADINGSPACE is always 0 for a cluster mbuf.)
     */
     */
    if (M_LEADINGSPACE(m0) < PPP_HDRLEN) {
    if (M_LEADINGSPACE(m0) < PPP_HDRLEN) {
        m0 = m_prepend(m0, PPP_HDRLEN, M_DONTWAIT);
        m0 = m_prepend(m0, PPP_HDRLEN, M_DONTWAIT);
        if (m0 == 0) {
        if (m0 == 0) {
            error = ENOBUFS;
            error = ENOBUFS;
            goto bad;
            goto bad;
        }
        }
        m0->m_len = 0;
        m0->m_len = 0;
    } else
    } else
        m0->m_data -= PPP_HDRLEN;
        m0->m_data -= PPP_HDRLEN;
 
 
    cp = mtod(m0, u_char *);
    cp = mtod(m0, u_char *);
    *cp++ = address;
    *cp++ = address;
    *cp++ = control;
    *cp++ = control;
    *cp++ = protocol >> 8;
    *cp++ = protocol >> 8;
    *cp++ = protocol & 0xff;
    *cp++ = protocol & 0xff;
    m0->m_len += PPP_HDRLEN;
    m0->m_len += PPP_HDRLEN;
 
 
    len = 0;
    len = 0;
    for (m = m0; m != 0; m = m->m_next)
    for (m = m0; m != 0; m = m->m_next)
        len += m->m_len;
        len += m->m_len;
 
 
    if (sc->sc_flags & SC_LOG_OUTPKT) {
    if (sc->sc_flags & SC_LOG_OUTPKT) {
        printf("ppp%d output: ", ifp->if_unit);
        printf("ppp%d output: ", ifp->if_unit);
        pppdumpm(m0);
        pppdumpm(m0);
    }
    }
 
 
    if ((protocol & 0x8000) == 0) {
    if ((protocol & 0x8000) == 0) {
#ifdef PPP_FILTER
#ifdef PPP_FILTER
        /*
        /*
         * Apply the pass and active filters to the packet,
         * Apply the pass and active filters to the packet,
         * but only if it is a data packet.
         * but only if it is a data packet.
         */
         */
        *mtod(m0, u_char *) = 1;        /* indicates outbound */
        *mtod(m0, u_char *) = 1;        /* indicates outbound */
        if (sc->sc_pass_filt.bf_insns != 0
        if (sc->sc_pass_filt.bf_insns != 0
            && bpf_filter(sc->sc_pass_filt.bf_insns, (u_char *) m0,
            && bpf_filter(sc->sc_pass_filt.bf_insns, (u_char *) m0,
                          len, 0) == 0) {
                          len, 0) == 0) {
            error = 0;           /* drop this packet */
            error = 0;           /* drop this packet */
            goto bad;
            goto bad;
        }
        }
 
 
        /*
        /*
         * Update the time we sent the most recent packet.
         * Update the time we sent the most recent packet.
         */
         */
        if (sc->sc_active_filt.bf_insns == 0
        if (sc->sc_active_filt.bf_insns == 0
            || bpf_filter(sc->sc_active_filt.bf_insns, (u_char *) m0, len, 0))
            || bpf_filter(sc->sc_active_filt.bf_insns, (u_char *) m0, len, 0))
            {
            {
                microtime(&ppp_time);
                microtime(&ppp_time);
                sc->sc_last_sent = ppp_time.tv_sec;
                sc->sc_last_sent = ppp_time.tv_sec;
            }
            }
 
 
        *mtod(m0, u_char *) = address;
        *mtod(m0, u_char *) = address;
#else
#else
        /*
        /*
         * Update the time we sent the most recent data packet.
         * Update the time we sent the most recent data packet.
         */
         */
        microtime(&ppp_time);
        microtime(&ppp_time);
        sc->sc_last_sent = ppp_time.tv_sec;
        sc->sc_last_sent = ppp_time.tv_sec;
#endif /* PPP_FILTER */
#endif /* PPP_FILTER */
    }
    }
 
 
#if NBPFILTER > 0
#if NBPFILTER > 0
    /*
    /*
     * See if bpf wants to look at the packet.
     * See if bpf wants to look at the packet.
     */
     */
    if (sc->sc_bpf)
    if (sc->sc_bpf)
        bpf_mtap(sc->sc_bpf, m0);
        bpf_mtap(sc->sc_bpf, m0);
#endif
#endif
 
 
    /*
    /*
     * Put the packet on the appropriate queue.
     * Put the packet on the appropriate queue.
     */
     */
    if (mode == NPMODE_QUEUE) {
    if (mode == NPMODE_QUEUE) {
        /* XXX we should limit the number of packets on this queue */
        /* XXX we should limit the number of packets on this queue */
        *sc->sc_npqtail = m0;
        *sc->sc_npqtail = m0;
        m0->m_nextpkt = NULL;
        m0->m_nextpkt = NULL;
        sc->sc_npqtail = &m0->m_nextpkt;
        sc->sc_npqtail = &m0->m_nextpkt;
    } else {
    } else {
        ifq = (m0->m_flags & M_HIGHPRI)? &sc->sc_fastq: &ifp->if_snd;
        ifq = (m0->m_flags & M_HIGHPRI)? &sc->sc_fastq: &ifp->if_snd;
        if (IF_QFULL(ifq) && dst->sa_family != AF_UNSPEC) {
        if (IF_QFULL(ifq) && dst->sa_family != AF_UNSPEC) {
            IF_DROP(ifq);
            IF_DROP(ifq);
            splx(s);
            splx(s);
            sc->sc_if.if_oerrors++;
            sc->sc_if.if_oerrors++;
            sc->sc_stats.ppp_oerrors++;
            sc->sc_stats.ppp_oerrors++;
            error = ENOBUFS;
            error = ENOBUFS;
            goto bad;
            goto bad;
        }
        }
        IF_ENQUEUE(ifq, m0);
        IF_ENQUEUE(ifq, m0);
        (*sc->sc_start)(sc);
        (*sc->sc_start)(sc);
    }
    }
        microtime(&ppp_time);
        microtime(&ppp_time);
    ifp->if_lastchange = ppp_time;
    ifp->if_lastchange = ppp_time;
    ifp->if_opackets++;
    ifp->if_opackets++;
    ifp->if_obytes += len;
    ifp->if_obytes += len;
 
 
    return (0);
    return (0);
 
 
bad:
bad:
    m_freem(m0);
    m_freem(m0);
    return (error);
    return (error);
}
}
 
 
/*
/*
 * After a change in the NPmode for some NP, move packets from the
 * After a change in the NPmode for some NP, move packets from the
 * npqueue to the send queue or the fast queue as appropriate.
 * npqueue to the send queue or the fast queue as appropriate.
 * Should be called at splsoftnet.
 * Should be called at splsoftnet.
 */
 */
static void
static void
ppp_requeue(sc)
ppp_requeue(sc)
    struct ppp_softc *sc;
    struct ppp_softc *sc;
{
{
    struct mbuf *m, **mpp;
    struct mbuf *m, **mpp;
    struct ifqueue *ifq;
    struct ifqueue *ifq;
    enum NPmode mode;
    enum NPmode mode;
 
 
    for (mpp = &sc->sc_npqueue; (m = *mpp) != NULL; ) {
    for (mpp = &sc->sc_npqueue; (m = *mpp) != NULL; ) {
        switch (PPP_PROTOCOL(mtod(m, u_char *))) {
        switch (PPP_PROTOCOL(mtod(m, u_char *))) {
        case PPP_IP:
        case PPP_IP:
            mode = sc->sc_npmode[NP_IP];
            mode = sc->sc_npmode[NP_IP];
            break;
            break;
        default:
        default:
            mode = NPMODE_PASS;
            mode = NPMODE_PASS;
        }
        }
 
 
        switch (mode) {
        switch (mode) {
        case NPMODE_PASS:
        case NPMODE_PASS:
            /*
            /*
             * This packet can now go on one of the queues to be sent.
             * This packet can now go on one of the queues to be sent.
             */
             */
            *mpp = m->m_nextpkt;
            *mpp = m->m_nextpkt;
            m->m_nextpkt = NULL;
            m->m_nextpkt = NULL;
            ifq = (m->m_flags & M_HIGHPRI)? &sc->sc_fastq: &sc->sc_if.if_snd;
            ifq = (m->m_flags & M_HIGHPRI)? &sc->sc_fastq: &sc->sc_if.if_snd;
            if (IF_QFULL(ifq)) {
            if (IF_QFULL(ifq)) {
                IF_DROP(ifq);
                IF_DROP(ifq);
                sc->sc_if.if_oerrors++;
                sc->sc_if.if_oerrors++;
                sc->sc_stats.ppp_oerrors++;
                sc->sc_stats.ppp_oerrors++;
            } else
            } else
                IF_ENQUEUE(ifq, m);
                IF_ENQUEUE(ifq, m);
            break;
            break;
 
 
        case NPMODE_DROP:
        case NPMODE_DROP:
        case NPMODE_ERROR:
        case NPMODE_ERROR:
            *mpp = m->m_nextpkt;
            *mpp = m->m_nextpkt;
            m_freem(m);
            m_freem(m);
            break;
            break;
 
 
        case NPMODE_QUEUE:
        case NPMODE_QUEUE:
            mpp = &m->m_nextpkt;
            mpp = &m->m_nextpkt;
            break;
            break;
        }
        }
    }
    }
    sc->sc_npqtail = mpp;
    sc->sc_npqtail = mpp;
}
}
 
 
/*
/*
 * Transmitter has finished outputting some stuff;
 * Transmitter has finished outputting some stuff;
 * remember to call sc->sc_start later at splsoftnet.
 * remember to call sc->sc_start later at splsoftnet.
 */
 */
void
void
ppp_restart(sc)
ppp_restart(sc)
    struct ppp_softc *sc;
    struct ppp_softc *sc;
{
{
 
 
    sc->sc_flags &= ~SC_TBUSY;
    sc->sc_flags &= ~SC_TBUSY;
/*    schednetisr(NETISR_PPP);
/*    schednetisr(NETISR_PPP);
*/}
*/}
 
 
/*
/*
 * Get a packet to send.  This procedure is intended to be called at
 * Get a packet to send.  This procedure is intended to be called at
 * splsoftnet, since it may involve time-consuming operations such as
 * splsoftnet, since it may involve time-consuming operations such as
 * applying VJ compression, packet compression, address/control and/or
 * applying VJ compression, packet compression, address/control and/or
 * protocol field compression to the packet.
 * protocol field compression to the packet.
 */
 */
struct mbuf *
struct mbuf *
ppp_dequeue(sc)
ppp_dequeue(sc)
    struct ppp_softc *sc;
    struct ppp_softc *sc;
{
{
    struct mbuf *m, *mp;
    struct mbuf *m, *mp;
    u_char *cp;
    u_char *cp;
    int address, control, protocol;
    int address, control, protocol;
 
 
    /*
    /*
     * Grab a packet to send: first try the fast queue, then the
     * Grab a packet to send: first try the fast queue, then the
     * normal queue.
     * normal queue.
     */
     */
    IF_DEQUEUE(&sc->sc_fastq, m);
    IF_DEQUEUE(&sc->sc_fastq, m);
    if (m == NULL)
    if (m == NULL)
        IF_DEQUEUE(&sc->sc_if.if_snd, m);
        IF_DEQUEUE(&sc->sc_if.if_snd, m);
    if (m == NULL)
    if (m == NULL)
        return NULL;
        return NULL;
 
 
    ++sc->sc_stats.ppp_opackets;
    ++sc->sc_stats.ppp_opackets;
 
 
    /*
    /*
     * Extract the ppp header of the new packet.
     * Extract the ppp header of the new packet.
     * The ppp header will be in one mbuf.
     * The ppp header will be in one mbuf.
     */
     */
    cp = mtod(m, u_char *);
    cp = mtod(m, u_char *);
    address = PPP_ADDRESS(cp);
    address = PPP_ADDRESS(cp);
    control = PPP_CONTROL(cp);
    control = PPP_CONTROL(cp);
    protocol = PPP_PROTOCOL(cp);
    protocol = PPP_PROTOCOL(cp);
 
 
    switch (protocol) {
    switch (protocol) {
    case PPP_IP:
    case PPP_IP:
#ifdef VJC
#ifdef VJC
        /*
        /*
         * If the packet is a TCP/IP packet, see if we can compress it.
         * If the packet is a TCP/IP packet, see if we can compress it.
         */
         */
        if ((sc->sc_flags & SC_COMP_TCP) && sc->sc_comp != NULL) {
        if ((sc->sc_flags & SC_COMP_TCP) && sc->sc_comp != NULL) {
            struct ip *ip;
            struct ip *ip;
            int type;
            int type;
 
 
            mp = m;
            mp = m;
            ip = (struct ip *) (cp + PPP_HDRLEN);
            ip = (struct ip *) (cp + PPP_HDRLEN);
            if (mp->m_len <= PPP_HDRLEN) {
            if (mp->m_len <= PPP_HDRLEN) {
                mp = mp->m_next;
                mp = mp->m_next;
                if (mp == NULL)
                if (mp == NULL)
                    break;
                    break;
                ip = mtod(mp, struct ip *);
                ip = mtod(mp, struct ip *);
            }
            }
            /* this code assumes the IP/TCP header is in one non-shared mbuf */
            /* this code assumes the IP/TCP header is in one non-shared mbuf */
            if (ip->ip_p == IPPROTO_TCP) {
            if (ip->ip_p == IPPROTO_TCP) {
                type = vj_compress_tcp(mp, ip, sc->sc_comp,
                type = vj_compress_tcp(mp, ip, sc->sc_comp,
                                       !(sc->sc_flags & SC_NO_TCP_CCID));
                                       !(sc->sc_flags & SC_NO_TCP_CCID));
                switch (type) {
                switch (type) {
                case TYPE_UNCOMPRESSED_TCP:
                case TYPE_UNCOMPRESSED_TCP:
                    protocol = PPP_VJC_UNCOMP;
                    protocol = PPP_VJC_UNCOMP;
                    break;
                    break;
                case TYPE_COMPRESSED_TCP:
                case TYPE_COMPRESSED_TCP:
                    protocol = PPP_VJC_COMP;
                    protocol = PPP_VJC_COMP;
                    cp = mtod(m, u_char *);
                    cp = mtod(m, u_char *);
                    cp[0] = address;     /* header has moved */
                    cp[0] = address;     /* header has moved */
                    cp[1] = control;
                    cp[1] = control;
                    cp[2] = 0;
                    cp[2] = 0;
                    break;
                    break;
                }
                }
                cp[3] = protocol;       /* update protocol in PPP header */
                cp[3] = protocol;       /* update protocol in PPP header */
            }
            }
        }
        }
#endif  /* VJC */
#endif  /* VJC */
        break;
        break;
 
 
#ifdef PPP_COMPRESS
#ifdef PPP_COMPRESS
    case PPP_CCP:
    case PPP_CCP:
        ppp_ccp(sc, m, 0);
        ppp_ccp(sc, m, 0);
        break;
        break;
#endif  /* PPP_COMPRESS */
#endif  /* PPP_COMPRESS */
    }
    }
 
 
#ifdef PPP_COMPRESS
#ifdef PPP_COMPRESS
    if (protocol != PPP_LCP && protocol != PPP_CCP
    if (protocol != PPP_LCP && protocol != PPP_CCP
        && sc->sc_xc_state && (sc->sc_flags & SC_COMP_RUN)) {
        && sc->sc_xc_state && (sc->sc_flags & SC_COMP_RUN)) {
        struct mbuf *mcomp = NULL;
        struct mbuf *mcomp = NULL;
        int slen, clen;
        int slen, clen;
 
 
        slen = 0;
        slen = 0;
        for (mp = m; mp != NULL; mp = mp->m_next)
        for (mp = m; mp != NULL; mp = mp->m_next)
            slen += mp->m_len;
            slen += mp->m_len;
        clen = (*sc->sc_xcomp->compress)
        clen = (*sc->sc_xcomp->compress)
            (sc->sc_xc_state, &mcomp, m, slen, sc->sc_if.if_mtu + PPP_HDRLEN);
            (sc->sc_xc_state, &mcomp, m, slen, sc->sc_if.if_mtu + PPP_HDRLEN);
        if (mcomp != NULL) {
        if (mcomp != NULL) {
            if (sc->sc_flags & SC_CCP_UP) {
            if (sc->sc_flags & SC_CCP_UP) {
                /* Send the compressed packet instead of the original. */
                /* Send the compressed packet instead of the original. */
                m_freem(m);
                m_freem(m);
                m = mcomp;
                m = mcomp;
                cp = mtod(m, u_char *);
                cp = mtod(m, u_char *);
                protocol = cp[3];
                protocol = cp[3];
            } else {
            } else {
                /* Can't transmit compressed packets until CCP is up. */
                /* Can't transmit compressed packets until CCP is up. */
                m_freem(mcomp);
                m_freem(mcomp);
            }
            }
        }
        }
    }
    }
#endif  /* PPP_COMPRESS */
#endif  /* PPP_COMPRESS */
 
 
    /*
    /*
     * Compress the address/control and protocol, if possible.
     * Compress the address/control and protocol, if possible.
     */
     */
    if (sc->sc_flags & SC_COMP_AC && address == PPP_ALLSTATIONS &&
    if (sc->sc_flags & SC_COMP_AC && address == PPP_ALLSTATIONS &&
        control == PPP_UI && protocol != PPP_ALLSTATIONS &&
        control == PPP_UI && protocol != PPP_ALLSTATIONS &&
        protocol != PPP_LCP) {
        protocol != PPP_LCP) {
        /* can compress address/control */
        /* can compress address/control */
        m->m_data += 2;
        m->m_data += 2;
        m->m_len -= 2;
        m->m_len -= 2;
    }
    }
    if (sc->sc_flags & SC_COMP_PROT && protocol < 0xFF) {
    if (sc->sc_flags & SC_COMP_PROT && protocol < 0xFF) {
        /* can compress protocol */
        /* can compress protocol */
        if (mtod(m, u_char *) == cp) {
        if (mtod(m, u_char *) == cp) {
            cp[2] = cp[1];      /* move address/control up */
            cp[2] = cp[1];      /* move address/control up */
            cp[1] = cp[0];
            cp[1] = cp[0];
        }
        }
        ++m->m_data;
        ++m->m_data;
        --m->m_len;
        --m->m_len;
    }
    }
 
 
    return m;
    return m;
}
}
 
 
/*
/*
 * Software interrupt routine, called at splsoftnet.
 * Software interrupt routine, called at splsoftnet.
 */
 */
void
void
pppintr()
pppintr()
{
{
    struct ppp_softc *sc;
    struct ppp_softc *sc;
    int i, s, s2;
    int i, s, s2;
    struct mbuf *m;
    struct mbuf *m;
 
 
    sc = ppp_softc;
    sc = ppp_softc;
    for (i = 0; i < NPPP; ++i, ++sc) {
    for (i = 0; i < NPPP; ++i, ++sc) {
        if (!(sc->sc_flags & SC_TBUSY)
        if (!(sc->sc_flags & SC_TBUSY)
            && (sc->sc_if.if_snd.ifq_head || sc->sc_fastq.ifq_head)) {
            && (sc->sc_if.if_snd.ifq_head || sc->sc_fastq.ifq_head)) {
            s2 = splimp();
            s2 = splimp();
            sc->sc_flags |= SC_TBUSY;
            sc->sc_flags |= SC_TBUSY;
            splx(s2);
            splx(s2);
            (*sc->sc_start)(sc);
            (*sc->sc_start)(sc);
        }
        }
        for (;;) {
        for (;;) {
            IF_DEQUEUE(&sc->sc_rawq, m);
            IF_DEQUEUE(&sc->sc_rawq, m);
            if (m == NULL)
            if (m == NULL)
                break;
                break;
            ppp_inproc(sc, m);
            ppp_inproc(sc, m);
        }
        }
    }
    }
}
}
 
 
#ifdef PPP_COMPRESS
#ifdef PPP_COMPRESS
/*
/*
 * Handle a CCP packet.  `rcvd' is 1 if the packet was received,
 * Handle a CCP packet.  `rcvd' is 1 if the packet was received,
 * 0 if it is about to be transmitted.
 * 0 if it is about to be transmitted.
 */
 */
static void
static void
ppp_ccp(sc, m, rcvd)
ppp_ccp(sc, m, rcvd)
    struct ppp_softc *sc;
    struct ppp_softc *sc;
    struct mbuf *m;
    struct mbuf *m;
    int rcvd;
    int rcvd;
{
{
    u_char *dp, *ep;
    u_char *dp, *ep;
    struct mbuf *mp;
    struct mbuf *mp;
    int slen, s;
    int slen, s;
 
 
    /*
    /*
     * Get a pointer to the data after the PPP header.
     * Get a pointer to the data after the PPP header.
     */
     */
    if (m->m_len <= PPP_HDRLEN) {
    if (m->m_len <= PPP_HDRLEN) {
        mp = m->m_next;
        mp = m->m_next;
        if (mp == NULL)
        if (mp == NULL)
            return;
            return;
        dp = (mp != NULL)? mtod(mp, u_char *): NULL;
        dp = (mp != NULL)? mtod(mp, u_char *): NULL;
    } else {
    } else {
        mp = m;
        mp = m;
        dp = mtod(mp, u_char *) + PPP_HDRLEN;
        dp = mtod(mp, u_char *) + PPP_HDRLEN;
    }
    }
 
 
    ep = mtod(mp, u_char *) + mp->m_len;
    ep = mtod(mp, u_char *) + mp->m_len;
    if (dp + CCP_HDRLEN > ep)
    if (dp + CCP_HDRLEN > ep)
        return;
        return;
    slen = CCP_LENGTH(dp);
    slen = CCP_LENGTH(dp);
    if (dp + slen > ep) {
    if (dp + slen > ep) {
        if (sc->sc_flags & SC_DEBUG)
        if (sc->sc_flags & SC_DEBUG)
            printf("if_ppp/ccp: not enough data in mbuf (%p+%x > %p+%x)\n",
            printf("if_ppp/ccp: not enough data in mbuf (%p+%x > %p+%x)\n",
                   dp, slen, mtod(mp, u_char *), mp->m_len);
                   dp, slen, mtod(mp, u_char *), mp->m_len);
        return;
        return;
    }
    }
 
 
    switch (CCP_CODE(dp)) {
    switch (CCP_CODE(dp)) {
    case CCP_CONFREQ:
    case CCP_CONFREQ:
    case CCP_TERMREQ:
    case CCP_TERMREQ:
    case CCP_TERMACK:
    case CCP_TERMACK:
        /* CCP must be going down - disable compression */
        /* CCP must be going down - disable compression */
        if (sc->sc_flags & SC_CCP_UP) {
        if (sc->sc_flags & SC_CCP_UP) {
            s = splimp();
            s = splimp();
            sc->sc_flags &= ~(SC_CCP_UP | SC_COMP_RUN | SC_DECOMP_RUN);
            sc->sc_flags &= ~(SC_CCP_UP | SC_COMP_RUN | SC_DECOMP_RUN);
            splx(s);
            splx(s);
        }
        }
        break;
        break;
 
 
    case CCP_CONFACK:
    case CCP_CONFACK:
        if (sc->sc_flags & SC_CCP_OPEN && !(sc->sc_flags & SC_CCP_UP)
        if (sc->sc_flags & SC_CCP_OPEN && !(sc->sc_flags & SC_CCP_UP)
            && slen >= CCP_HDRLEN + CCP_OPT_MINLEN
            && slen >= CCP_HDRLEN + CCP_OPT_MINLEN
            && slen >= CCP_OPT_LENGTH(dp + CCP_HDRLEN) + CCP_HDRLEN) {
            && slen >= CCP_OPT_LENGTH(dp + CCP_HDRLEN) + CCP_HDRLEN) {
            if (!rcvd) {
            if (!rcvd) {
                /* we're agreeing to send compressed packets. */
                /* we're agreeing to send compressed packets. */
                if (sc->sc_xc_state != NULL
                if (sc->sc_xc_state != NULL
                    && (*sc->sc_xcomp->comp_init)
                    && (*sc->sc_xcomp->comp_init)
                        (sc->sc_xc_state, dp + CCP_HDRLEN, slen - CCP_HDRLEN,
                        (sc->sc_xc_state, dp + CCP_HDRLEN, slen - CCP_HDRLEN,
                         sc->sc_if.if_unit, 0, sc->sc_flags & SC_DEBUG)) {
                         sc->sc_if.if_unit, 0, sc->sc_flags & SC_DEBUG)) {
                    s = splimp();
                    s = splimp();
                    sc->sc_flags |= SC_COMP_RUN;
                    sc->sc_flags |= SC_COMP_RUN;
                    splx(s);
                    splx(s);
                }
                }
            } else {
            } else {
                /* peer is agreeing to send compressed packets. */
                /* peer is agreeing to send compressed packets. */
                if (sc->sc_rc_state != NULL
                if (sc->sc_rc_state != NULL
                    && (*sc->sc_rcomp->decomp_init)
                    && (*sc->sc_rcomp->decomp_init)
                        (sc->sc_rc_state, dp + CCP_HDRLEN, slen - CCP_HDRLEN,
                        (sc->sc_rc_state, dp + CCP_HDRLEN, slen - CCP_HDRLEN,
                         sc->sc_if.if_unit, 0, sc->sc_mru,
                         sc->sc_if.if_unit, 0, sc->sc_mru,
                         sc->sc_flags & SC_DEBUG)) {
                         sc->sc_flags & SC_DEBUG)) {
                    s = splimp();
                    s = splimp();
                    sc->sc_flags |= SC_DECOMP_RUN;
                    sc->sc_flags |= SC_DECOMP_RUN;
                    sc->sc_flags &= ~(SC_DC_ERROR | SC_DC_FERROR);
                    sc->sc_flags &= ~(SC_DC_ERROR | SC_DC_FERROR);
                    splx(s);
                    splx(s);
                }
                }
            }
            }
        }
        }
        break;
        break;
 
 
    case CCP_RESETACK:
    case CCP_RESETACK:
        if (sc->sc_flags & SC_CCP_UP) {
        if (sc->sc_flags & SC_CCP_UP) {
            if (!rcvd) {
            if (!rcvd) {
                if (sc->sc_xc_state && (sc->sc_flags & SC_COMP_RUN))
                if (sc->sc_xc_state && (sc->sc_flags & SC_COMP_RUN))
                    (*sc->sc_xcomp->comp_reset)(sc->sc_xc_state);
                    (*sc->sc_xcomp->comp_reset)(sc->sc_xc_state);
            } else {
            } else {
                if (sc->sc_rc_state && (sc->sc_flags & SC_DECOMP_RUN)) {
                if (sc->sc_rc_state && (sc->sc_flags & SC_DECOMP_RUN)) {
                    (*sc->sc_rcomp->decomp_reset)(sc->sc_rc_state);
                    (*sc->sc_rcomp->decomp_reset)(sc->sc_rc_state);
                    s = splimp();
                    s = splimp();
                    sc->sc_flags &= ~SC_DC_ERROR;
                    sc->sc_flags &= ~SC_DC_ERROR;
                    splx(s);
                    splx(s);
                }
                }
            }
            }
        }
        }
        break;
        break;
    }
    }
}
}
 
 
/*
/*
 * CCP is down; free (de)compressor state if necessary.
 * CCP is down; free (de)compressor state if necessary.
 */
 */
static void
static void
ppp_ccp_closed(sc)
ppp_ccp_closed(sc)
    struct ppp_softc *sc;
    struct ppp_softc *sc;
{
{
    if (sc->sc_xc_state) {
    if (sc->sc_xc_state) {
        (*sc->sc_xcomp->comp_free)(sc->sc_xc_state);
        (*sc->sc_xcomp->comp_free)(sc->sc_xc_state);
        sc->sc_xc_state = NULL;
        sc->sc_xc_state = NULL;
    }
    }
    if (sc->sc_rc_state) {
    if (sc->sc_rc_state) {
        (*sc->sc_rcomp->decomp_free)(sc->sc_rc_state);
        (*sc->sc_rcomp->decomp_free)(sc->sc_rc_state);
        sc->sc_rc_state = NULL;
        sc->sc_rc_state = NULL;
    }
    }
}
}
#endif /* PPP_COMPRESS */
#endif /* PPP_COMPRESS */
 
 
/*
/*
 * PPP packet input routine.
 * PPP packet input routine.
 * The caller has checked and removed the FCS and has inserted
 * The caller has checked and removed the FCS and has inserted
 * the address/control bytes and the protocol high byte if they
 * the address/control bytes and the protocol high byte if they
 * were omitted.
 * were omitted.
 */
 */
void
void
ppppktin(sc, m, lost)
ppppktin(sc, m, lost)
    struct ppp_softc *sc;
    struct ppp_softc *sc;
    struct mbuf *m;
    struct mbuf *m;
    int lost;
    int lost;
{
{
 
 
    if (lost)
    if (lost)
        m->m_flags |= M_ERRMARK;
        m->m_flags |= M_ERRMARK;
    IF_ENQUEUE(&sc->sc_rawq, m);
    IF_ENQUEUE(&sc->sc_rawq, m);
    pppintr();
    pppintr();
}
}
 
 
/*
/*
 * Process a received PPP packet, doing decompression as necessary.
 * Process a received PPP packet, doing decompression as necessary.
 * Should be called at splsoftnet.
 * Should be called at splsoftnet.
 */
 */
#define COMPTYPE(proto) ((proto) == PPP_VJC_COMP? TYPE_COMPRESSED_TCP: \
#define COMPTYPE(proto) ((proto) == PPP_VJC_COMP? TYPE_COMPRESSED_TCP: \
                         TYPE_UNCOMPRESSED_TCP)
                         TYPE_UNCOMPRESSED_TCP)
 
 
static void
static void
ppp_inproc(sc, m)
ppp_inproc(sc, m)
    struct ppp_softc *sc;
    struct ppp_softc *sc;
    struct mbuf *m;
    struct mbuf *m;
{
{
    struct ifnet *ifp = &sc->sc_if;
    struct ifnet *ifp = &sc->sc_if;
    struct ifqueue *inq;
    struct ifqueue *inq;
    int s, ilen, xlen, proto, rv;
    int s, ilen, xlen, proto, rv;
    u_char *cp, adrs, ctrl;
    u_char *cp, adrs, ctrl;
    struct mbuf *mp, *dmp = NULL;
    struct mbuf *mp, *dmp = NULL;
    u_char *iphdr;
    u_char *iphdr;
    u_int hlen;
    u_int hlen;
 
 
    sc->sc_stats.ppp_ipackets++;
    sc->sc_stats.ppp_ipackets++;
 
 
    if (sc->sc_flags & SC_LOG_INPKT) {
    if (sc->sc_flags & SC_LOG_INPKT) {
        ilen = 0;
        ilen = 0;
        for (mp = m; mp != NULL; mp = mp->m_next)
        for (mp = m; mp != NULL; mp = mp->m_next)
            ilen += mp->m_len;
            ilen += mp->m_len;
        printf("ppp%d: got %d bytes\n", ifp->if_unit, ilen);
        printf("ppp%d: got %d bytes\n", ifp->if_unit, ilen);
        pppdumpm(m);
        pppdumpm(m);
    }
    }
 
 
    cp = mtod(m, u_char *);
    cp = mtod(m, u_char *);
    adrs = PPP_ADDRESS(cp);
    adrs = PPP_ADDRESS(cp);
    ctrl = PPP_CONTROL(cp);
    ctrl = PPP_CONTROL(cp);
    proto = PPP_PROTOCOL(cp);
    proto = PPP_PROTOCOL(cp);
 
 
    if (m->m_flags & M_ERRMARK) {
    if (m->m_flags & M_ERRMARK) {
        m->m_flags &= ~M_ERRMARK;
        m->m_flags &= ~M_ERRMARK;
        s = splimp();
        s = splimp();
        sc->sc_flags |= SC_VJ_RESET;
        sc->sc_flags |= SC_VJ_RESET;
        splx(s);
        splx(s);
    }
    }
 
 
#ifdef PPP_COMPRESS
#ifdef PPP_COMPRESS
    /*
    /*
     * Decompress this packet if necessary, update the receiver's
     * Decompress this packet if necessary, update the receiver's
     * dictionary, or take appropriate action on a CCP packet.
     * dictionary, or take appropriate action on a CCP packet.
     */
     */
    if (proto == PPP_COMP && sc->sc_rc_state && (sc->sc_flags & SC_DECOMP_RUN)
    if (proto == PPP_COMP && sc->sc_rc_state && (sc->sc_flags & SC_DECOMP_RUN)
        && !(sc->sc_flags & SC_DC_ERROR) && !(sc->sc_flags & SC_DC_FERROR)) {
        && !(sc->sc_flags & SC_DC_ERROR) && !(sc->sc_flags & SC_DC_FERROR)) {
        /* decompress this packet */
        /* decompress this packet */
        rv = (*sc->sc_rcomp->decompress)(sc->sc_rc_state, m, &dmp);
        rv = (*sc->sc_rcomp->decompress)(sc->sc_rc_state, m, &dmp);
        if (rv == DECOMP_OK) {
        if (rv == DECOMP_OK) {
            m_freem(m);
            m_freem(m);
            if (dmp == NULL) {
            if (dmp == NULL) {
                /* no error, but no decompressed packet produced */
                /* no error, but no decompressed packet produced */
                return;
                return;
            }
            }
            m = dmp;
            m = dmp;
            cp = mtod(m, u_char *);
            cp = mtod(m, u_char *);
            proto = PPP_PROTOCOL(cp);
            proto = PPP_PROTOCOL(cp);
 
 
        } else {
        } else {
            /*
            /*
             * An error has occurred in decompression.
             * An error has occurred in decompression.
             * Pass the compressed packet up to pppd, which may take
             * Pass the compressed packet up to pppd, which may take
             * CCP down or issue a Reset-Req.
             * CCP down or issue a Reset-Req.
             */
             */
            if (sc->sc_flags & SC_DEBUG)
            if (sc->sc_flags & SC_DEBUG)
                printf("ppp%d: decompress failed %d\n", ifp->if_unit, rv);
                printf("ppp%d: decompress failed %d\n", ifp->if_unit, rv);
            s = splimp();
            s = splimp();
            sc->sc_flags |= SC_VJ_RESET;
            sc->sc_flags |= SC_VJ_RESET;
            if (rv == DECOMP_ERROR)
            if (rv == DECOMP_ERROR)
                sc->sc_flags |= SC_DC_ERROR;
                sc->sc_flags |= SC_DC_ERROR;
            else
            else
                sc->sc_flags |= SC_DC_FERROR;
                sc->sc_flags |= SC_DC_FERROR;
            splx(s);
            splx(s);
        }
        }
 
 
    } else {
    } else {
        if (sc->sc_rc_state && (sc->sc_flags & SC_DECOMP_RUN)) {
        if (sc->sc_rc_state && (sc->sc_flags & SC_DECOMP_RUN)) {
            (*sc->sc_rcomp->incomp)(sc->sc_rc_state, m);
            (*sc->sc_rcomp->incomp)(sc->sc_rc_state, m);
        }
        }
        if (proto == PPP_CCP) {
        if (proto == PPP_CCP) {
            ppp_ccp(sc, m, 1);
            ppp_ccp(sc, m, 1);
        }
        }
    }
    }
#endif
#endif
 
 
    ilen = 0;
    ilen = 0;
    for (mp = m; mp != NULL; mp = mp->m_next)
    for (mp = m; mp != NULL; mp = mp->m_next)
        ilen += mp->m_len;
        ilen += mp->m_len;
 
 
#ifdef VJC
#ifdef VJC
    if (sc->sc_flags & SC_VJ_RESET) {
    if (sc->sc_flags & SC_VJ_RESET) {
        /*
        /*
         * If we've missed a packet, we must toss subsequent compressed
         * If we've missed a packet, we must toss subsequent compressed
         * packets which don't have an explicit connection ID.
         * packets which don't have an explicit connection ID.
         */
         */
        if (sc->sc_comp)
        if (sc->sc_comp)
            vj_uncompress_tcp(NULL, 0, TYPE_ERROR, sc->sc_comp);
            vj_uncompress_tcp(NULL, 0, TYPE_ERROR, sc->sc_comp);
        s = splimp();
        s = splimp();
        sc->sc_flags &= ~SC_VJ_RESET;
        sc->sc_flags &= ~SC_VJ_RESET;
        splx(s);
        splx(s);
    }
    }
 
 
    /*
    /*
     * See if we have a VJ-compressed packet to uncompress.
     * See if we have a VJ-compressed packet to uncompress.
     */
     */
    if (proto == PPP_VJC_COMP) {
    if (proto == PPP_VJC_COMP) {
        if ((sc->sc_flags & SC_REJ_COMP_TCP) || sc->sc_comp == 0)
        if ((sc->sc_flags & SC_REJ_COMP_TCP) || sc->sc_comp == 0)
            goto bad;
            goto bad;
 
 
        xlen = vj_uncompress_tcp_core(cp + PPP_HDRLEN, m->m_len - PPP_HDRLEN,
        xlen = vj_uncompress_tcp_core(cp + PPP_HDRLEN, m->m_len - PPP_HDRLEN,
                                      ilen - PPP_HDRLEN, TYPE_COMPRESSED_TCP,
                                      ilen - PPP_HDRLEN, TYPE_COMPRESSED_TCP,
                                      sc->sc_comp, &iphdr, &hlen);
                                      sc->sc_comp, &iphdr, &hlen);
 
 
        if (xlen <= 0) {
        if (xlen <= 0) {
            if (sc->sc_flags & SC_DEBUG)
            if (sc->sc_flags & SC_DEBUG)
                printf("ppp%d: VJ uncompress failed on type comp\n",
                printf("ppp%d: VJ uncompress failed on type comp\n",
                        ifp->if_unit);
                        ifp->if_unit);
            goto bad;
            goto bad;
        }
        }
 
 
        /* Copy the PPP and IP headers into a new mbuf. */
        /* Copy the PPP and IP headers into a new mbuf. */
        MGETHDR(mp, M_DONTWAIT, MT_DATA);
        MGETHDR(mp, M_DONTWAIT, MT_DATA);
        if (mp == NULL)
        if (mp == NULL)
            goto bad;
            goto bad;
        mp->m_len = 0;
        mp->m_len = 0;
        mp->m_next = NULL;
        mp->m_next = NULL;
        if (hlen + PPP_HDRLEN > MHLEN) {
        if (hlen + PPP_HDRLEN > MHLEN) {
            MCLGET(mp, M_DONTWAIT);
            MCLGET(mp, M_DONTWAIT);
            if (M_TRAILINGSPACE(mp) < hlen + PPP_HDRLEN) {
            if (M_TRAILINGSPACE(mp) < hlen + PPP_HDRLEN) {
                m_freem(mp);
                m_freem(mp);
                goto bad;       /* lose if big headers and no clusters */
                goto bad;       /* lose if big headers and no clusters */
            }
            }
        }
        }
        cp = mtod(mp, u_char *);
        cp = mtod(mp, u_char *);
        cp[0] = adrs;
        cp[0] = adrs;
        cp[1] = ctrl;
        cp[1] = ctrl;
        cp[2] = 0;
        cp[2] = 0;
        cp[3] = PPP_IP;
        cp[3] = PPP_IP;
        proto = PPP_IP;
        proto = PPP_IP;
        bcopy(iphdr, cp + PPP_HDRLEN, hlen);
        bcopy(iphdr, cp + PPP_HDRLEN, hlen);
        mp->m_len = hlen + PPP_HDRLEN;
        mp->m_len = hlen + PPP_HDRLEN;
 
 
        /*
        /*
         * Trim the PPP and VJ headers off the old mbuf
         * Trim the PPP and VJ headers off the old mbuf
         * and stick the new and old mbufs together.
         * and stick the new and old mbufs together.
         */
         */
        m->m_data += PPP_HDRLEN + xlen;
        m->m_data += PPP_HDRLEN + xlen;
        m->m_len -= PPP_HDRLEN + xlen;
        m->m_len -= PPP_HDRLEN + xlen;
        if (m->m_len <= M_TRAILINGSPACE(mp)) {
        if (m->m_len <= M_TRAILINGSPACE(mp)) {
            bcopy(mtod(m, u_char *), mtod(mp, u_char *) + mp->m_len, m->m_len);
            bcopy(mtod(m, u_char *), mtod(mp, u_char *) + mp->m_len, m->m_len);
            mp->m_len += m->m_len;
            mp->m_len += m->m_len;
            MFREE(m, mp->m_next);
            MFREE(m, mp->m_next);
        } else
        } else
            mp->m_next = m;
            mp->m_next = m;
        m = mp;
        m = mp;
        ilen += hlen - xlen;
        ilen += hlen - xlen;
 
 
    } else if (proto == PPP_VJC_UNCOMP) {
    } else if (proto == PPP_VJC_UNCOMP) {
        if ((sc->sc_flags & SC_REJ_COMP_TCP) || sc->sc_comp == 0)
        if ((sc->sc_flags & SC_REJ_COMP_TCP) || sc->sc_comp == 0)
            goto bad;
            goto bad;
 
 
        xlen = vj_uncompress_tcp_core(cp + PPP_HDRLEN, m->m_len - PPP_HDRLEN,
        xlen = vj_uncompress_tcp_core(cp + PPP_HDRLEN, m->m_len - PPP_HDRLEN,
                                      ilen - PPP_HDRLEN, TYPE_UNCOMPRESSED_TCP,
                                      ilen - PPP_HDRLEN, TYPE_UNCOMPRESSED_TCP,
                                      sc->sc_comp, &iphdr, &hlen);
                                      sc->sc_comp, &iphdr, &hlen);
 
 
        if (xlen < 0) {
        if (xlen < 0) {
            if (sc->sc_flags & SC_DEBUG)
            if (sc->sc_flags & SC_DEBUG)
                printf("ppp%d: VJ uncompress failed on type uncomp\n",
                printf("ppp%d: VJ uncompress failed on type uncomp\n",
                        ifp->if_unit);
                        ifp->if_unit);
            goto bad;
            goto bad;
        }
        }
 
 
        proto = PPP_IP;
        proto = PPP_IP;
        cp[3] = PPP_IP;
        cp[3] = PPP_IP;
    }
    }
#endif /* VJC */
#endif /* VJC */
 
 
    /*
    /*
     * If the packet will fit in a header mbuf, don't waste a
     * If the packet will fit in a header mbuf, don't waste a
     * whole cluster on it.
     * whole cluster on it.
     */
     */
    if (ilen <= MHLEN && M_IS_CLUSTER(m)) {
    if (ilen <= MHLEN && M_IS_CLUSTER(m)) {
        MGETHDR(mp, M_DONTWAIT, MT_DATA);
        MGETHDR(mp, M_DONTWAIT, MT_DATA);
        if (mp != NULL) {
        if (mp != NULL) {
            m_copydata(m, 0, ilen, mtod(mp, caddr_t));
            m_copydata(m, 0, ilen, mtod(mp, caddr_t));
            m_freem(m);
            m_freem(m);
            m = mp;
            m = mp;
            m->m_len = ilen;
            m->m_len = ilen;
        }
        }
    }
    }
    m->m_pkthdr.len = ilen;
    m->m_pkthdr.len = ilen;
    m->m_pkthdr.rcvif = ifp;
    m->m_pkthdr.rcvif = ifp;
 
 
    if ((proto & 0x8000) == 0) {
    if ((proto & 0x8000) == 0) {
#ifdef PPP_FILTER
#ifdef PPP_FILTER
        /*
        /*
         * See whether we want to pass this packet, and
         * See whether we want to pass this packet, and
         * if it counts as link activity.
         * if it counts as link activity.
         */
         */
        adrs = *mtod(m, u_char *);      /* save address field */
        adrs = *mtod(m, u_char *);      /* save address field */
        *mtod(m, u_char *) = 0;          /* indicate inbound */
        *mtod(m, u_char *) = 0;          /* indicate inbound */
        if (sc->sc_pass_filt.bf_insns != 0
        if (sc->sc_pass_filt.bf_insns != 0
            && bpf_filter(sc->sc_pass_filt.bf_insns, (u_char *) m,
            && bpf_filter(sc->sc_pass_filt.bf_insns, (u_char *) m,
                          ilen, 0) == 0) {
                          ilen, 0) == 0) {
            /* drop this packet */
            /* drop this packet */
            m_freem(m);
            m_freem(m);
            return;
            return;
        }
        }
        if (sc->sc_active_filt.bf_insns == 0
        if (sc->sc_active_filt.bf_insns == 0
            || bpf_filter(sc->sc_active_filt.bf_insns, (u_char *) m, ilen, 0))
            || bpf_filter(sc->sc_active_filt.bf_insns, (u_char *) m, ilen, 0))
            {
            {
                microtime(&ppp_time);
                microtime(&ppp_time);
 
 
                sc->sc_last_recv = ppp_time.tv_sec;
                sc->sc_last_recv = ppp_time.tv_sec;
            }
            }
 
 
        *mtod(m, u_char *) = adrs;
        *mtod(m, u_char *) = adrs;
#else
#else
        /*
        /*
         * Record the time that we received this packet.
         * Record the time that we received this packet.
         */
         */
        microtime(&ppp_time);
        microtime(&ppp_time);
        sc->sc_last_recv = ppp_time.tv_sec;
        sc->sc_last_recv = ppp_time.tv_sec;
#endif /* PPP_FILTER */
#endif /* PPP_FILTER */
    }
    }
 
 
#if NBPFILTER > 0
#if NBPFILTER > 0
    /* See if bpf wants to look at the packet. */
    /* See if bpf wants to look at the packet. */
    if (sc->sc_bpf)
    if (sc->sc_bpf)
        bpf_mtap(sc->sc_bpf, m);
        bpf_mtap(sc->sc_bpf, m);
#endif
#endif
 
 
    rv = 0;
    rv = 0;
    switch (proto) {
    switch (proto) {
#ifdef INET
#ifdef INET
    case PPP_IP:
    case PPP_IP:
        /*
        /*
         * IP packet - take off the ppp header and pass it up to IP.
         * IP packet - take off the ppp header and pass it up to IP.
         */
         */
        if ((ifp->if_flags & IFF_UP) == 0
        if ((ifp->if_flags & IFF_UP) == 0
            || sc->sc_npmode[NP_IP] != NPMODE_PASS) {
            || sc->sc_npmode[NP_IP] != NPMODE_PASS) {
            /* interface is down - drop the packet. */
            /* interface is down - drop the packet. */
            m_freem(m);
            m_freem(m);
            return;
            return;
        }
        }
        m->m_pkthdr.len -= PPP_HDRLEN;
        m->m_pkthdr.len -= PPP_HDRLEN;
        m->m_data += PPP_HDRLEN;
        m->m_data += PPP_HDRLEN;
        m->m_len -= PPP_HDRLEN;
        m->m_len -= PPP_HDRLEN;
        schednetisr(NETISR_IP);
        schednetisr(NETISR_IP);
        inq = &ipintrq;
        inq = &ipintrq;
        break;
        break;
#endif
#endif
 
 
    default:
    default:
        /*
        /*
         * Some other protocol - place on input queue for read().
         * Some other protocol - place on input queue for read().
         */
         */
        inq = &sc->sc_inq;
        inq = &sc->sc_inq;
        rv = 1;
        rv = 1;
        break;
        break;
    }
    }
 
 
    /*
    /*
     * Put the packet on the appropriate input queue.
     * Put the packet on the appropriate input queue.
     */
     */
    s = splimp();
    s = splimp();
    if (IF_QFULL(inq)) {
    if (IF_QFULL(inq)) {
        IF_DROP(inq);
        IF_DROP(inq);
        splx(s);
        splx(s);
        if (sc->sc_flags & SC_DEBUG)
        if (sc->sc_flags & SC_DEBUG)
            printf("ppp%d: input queue full\n", ifp->if_unit);
            printf("ppp%d: input queue full\n", ifp->if_unit);
        ifp->if_iqdrops++;
        ifp->if_iqdrops++;
        goto bad;
        goto bad;
    }
    }
    IF_ENQUEUE(inq, m);
    IF_ENQUEUE(inq, m);
    splx(s);
    splx(s);
    ifp->if_ipackets++;
    ifp->if_ipackets++;
    ifp->if_ibytes += ilen;
    ifp->if_ibytes += ilen;
        microtime(&ppp_time);
        microtime(&ppp_time);
    ifp->if_lastchange = ppp_time;
    ifp->if_lastchange = ppp_time;
 
 
    if (rv)
    if (rv)
        (*sc->sc_ctlp)(sc);
        (*sc->sc_ctlp)(sc);
 
 
    return;
    return;
 
 
 bad:
 bad:
    m_freem(m);
    m_freem(m);
    sc->sc_if.if_ierrors++;
    sc->sc_if.if_ierrors++;
    sc->sc_stats.ppp_ierrors++;
    sc->sc_stats.ppp_ierrors++;
}
}
 
 
#define MAX_DUMP_BYTES  128
#define MAX_DUMP_BYTES  128
 
 
static void
static void
pppdumpm(m0)
pppdumpm(m0)
    struct mbuf *m0;
    struct mbuf *m0;
{
{
    char buf[3*MAX_DUMP_BYTES+4];
    char buf[3*MAX_DUMP_BYTES+4];
    char *bp = buf;
    char *bp = buf;
    struct mbuf *m;
    struct mbuf *m;
    static char digits[] = "0123456789abcdef";
    static char digits[] = "0123456789abcdef";
 
 
    for (m = m0; m; m = m->m_next) {
    for (m = m0; m; m = m->m_next) {
        int l = m->m_len;
        int l = m->m_len;
        u_char *rptr = (u_char *)m->m_data;
        u_char *rptr = (u_char *)m->m_data;
 
 
        while (l--) {
        while (l--) {
            if (bp > buf + sizeof(buf) - 4)
            if (bp > buf + sizeof(buf) - 4)
                goto done;
                goto done;
            *bp++ = digits[*rptr >> 4]; /* convert byte to ascii hex */
            *bp++ = digits[*rptr >> 4]; /* convert byte to ascii hex */
            *bp++ = digits[*rptr++ & 0xf];
            *bp++ = digits[*rptr++ & 0xf];
        }
        }
 
 
        if (m->m_next) {
        if (m->m_next) {
            if (bp > buf + sizeof(buf) - 3)
            if (bp > buf + sizeof(buf) - 3)
                goto done;
                goto done;
            *bp++ = '|';
            *bp++ = '|';
        } else
        } else
            *bp++ = ' ';
            *bp++ = ' ';
    }
    }
done:
done:
    if (m)
    if (m)
        *bp++ = '>';
        *bp++ = '>';
    *bp = 0;
    *bp = 0;
    printf("%s\n", buf);
    printf("%s\n", buf);
}
}
 
 
#endif  /* NPPP > 0 */
#endif  /* NPPP > 0 */
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.