1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-10-19 02:29:40 +00:00

Merge/update ppp-2.2 kernel parts onto mainline.

Note that the old if_ppp.c has been split in half into if_ppp.c and
ppp_tty.c
This commit is contained in:
Peter Wemm 1995-10-31 20:24:14 +00:00
parent 8511566984
commit 45e829f5a5
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=11970
6 changed files with 1072 additions and 1231 deletions

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -1,4 +1,5 @@
/* $Id: if_pppvar.h,v 1.1 1994/12/15 22:28:09 paulus Exp $ */
/* from Id: if_pppvar.h,v 1.1 1994/12/15 22:28:09 paulus Exp */
/* $Id$ */
/*
* if_pppvar.h - private structures and declarations for PPP.
*
@ -53,21 +54,22 @@
*/
struct ppp_softc {
struct ifnet sc_if; /* network-visible interface */
u_int sc_flags; /* control/status bits; see if_ppp.h */
/*hi*/ u_int sc_flags; /* control/status bits; see if_ppp.h */
void *sc_devp; /* pointer to device-dep structure */
void (*sc_start) __P((struct ppp_softc *)); /* start output proc */
void (*sc_ctlp) __P((struct ppp_softc *)); /* rcvd control pkt */
void (*sc_relinq) __P((struct ppp_softc *)); /* relinquish ifunit */
void (*sc_setmtu) __P((struct ppp_softc *)); /* set mtu */
short sc_mru; /* max receive unit */
pid_t sc_xfer; /* used in transferring unit */
struct ifqueue sc_rawq; /* received packets */
struct ifqueue sc_inq; /* queue of input packets for daemon */
struct ifqueue sc_fastq; /* interactive output packet q */
/*hi*/ struct ifqueue sc_rawq; /* received packets */
/*net*/ struct ifqueue sc_inq; /* queue of input packets for daemon */
/*net*/ struct ifqueue sc_fastq; /* interactive output packet q */
struct mbuf *sc_togo; /* output packet ready to go */
struct mbuf *sc_npqueue; /* output packets not to be sent yet */
struct mbuf **sc_npqtail; /* ptr to last next ptr in npqueue */
#ifdef VJC
struct vjcompress sc_comp; /* vjc control buffer */
struct slcompress sc_comp; /* vjc control buffer */
#endif
u_int sc_bytessent; /* count of octets sent */
u_int sc_bytesrcvd; /* count of octets received */
@ -100,5 +102,7 @@ struct ppp_softc *pppalloc __P((pid_t pid));
void pppdealloc __P((struct ppp_softc *sc));
int pppioctl __P((struct ppp_softc *sc, int cmd, caddr_t data,
int flag, struct proc *p));
int pppoutput __P((struct ifnet *ifp, struct mbuf *m0,
struct sockaddr *dst, struct rtentry *rtp));
void ppppktin __P((struct ppp_softc *sc, struct mbuf *m, int lost));
struct mbuf *ppp_dequeue __P((struct ppp_softc *sc));

View File

@ -1,5 +1,5 @@
/*
* ppp-comp.h - Definitions for doing PPP packet compression.
* ppp_comp.h - Definitions for doing PPP packet compression.
*
* Copyright (c) 1994 The Australian National University.
* All rights reserved.
@ -24,7 +24,8 @@
* OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
* OR MODIFICATIONS.
*
* $Id: ppp-comp.h,v 1.7 1995/05/01 01:43:37 paulus Exp $
* From: Id: ppp-comp.h,v 1.7 1995/05/01 01:43:37 paulus Exp
* $Id$
*/
#ifndef _NET_PPP_COMP_H

View File

@ -1,4 +1,5 @@
/* $Id: ppp_defs.h,v 1.7 1995/08/10 06:49:35 paulus Exp $ */
/* from Id: ppp_defs.h,v 1.7 1995/08/10 06:49:35 paulus Exp */
/* $Id$ */
/*
* ppp_defs.h - PPP definitions.
@ -54,10 +55,13 @@
* Protocol field values.
*/
#define PPP_IP 0x21 /* Internet Protocol */
#define PPP_XNS 0x25 /* Xerox NS */
#define PPP_IPX 0x2b /* IPX Datagram (RFC1552) */
#define PPP_VJC_COMP 0x2d /* VJ compressed TCP */
#define PPP_VJC_UNCOMP 0x2f /* VJ uncompressed TCP */
#define PPP_COMP 0xfd /* compressed packet */
#define PPP_IPCP 0x8021 /* IP Control Protocol */
#define PPP_IPXCP 0x802b /* IPX Control Protocol (RFC1552) */
#define PPP_CCP 0x80fd /* Compression Control Protocol */
#define PPP_LCP 0xc021 /* Link Control Protocol */
#define PPP_PAP 0xc023 /* Password Authentication Protocol */
@ -74,7 +78,7 @@
/*
* A 32-bit unsigned integral type.
*/
#if !defined(__BIT_TYPES_DEFINED__) && !defined(_BITYPES)
#if !defined(__BIT_TYPES_DEFINED__) && !defined(_BITYPES) && !defined(__FreeBSD__)
#ifdef UINT32_T
typedef UINT32_T u_int32_t;
#else

View File

@ -70,7 +70,8 @@
* Paul Mackerras (paulus@cs.anu.edu.au).
*/
/* $Id: ppp_tty.c,v 1.3 1995/08/16 01:36:40 paulus Exp $ */
/* $Id$ */
/* from Id: ppp_tty.c,v 1.3 1995/08/16 01:36:40 paulus Exp */
/* from if_sl.c,v 1.11 84/10/04 12:54:47 rick Exp */
#include "ppp.h"
@ -90,7 +91,15 @@
#include <sys/tty.h>
#include <sys/kernel.h>
#include <sys/conf.h>
#include <sys/vnode.h>
#undef KERNEL /* so that vnode.h does not try to include vnode_if.h */
# include <sys/vnode.h>
#define KERNEL
#ifdef i386 /* fiddle with the spl locking */
# include <machine/spl.h>
# include <i386/isa/isa_device.h>
#endif
#include <net/if.h>
#include <net/if_types.h>
@ -99,14 +108,16 @@
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <net/pppcompress.h>
#include <net/slcompress.h>
#endif
#include <net/ppp_defs.h>
#include <net/if_ppp.h>
#include <net/if_pppvar.h>
void pppasyncattach __P((void));
void pppasyncattach __P((void *));
PSEUDO_SET(pppasyncattach, ppp_tty);
int pppopen __P((dev_t dev, struct tty *tp));
int pppclose __P((struct tty *tp, int flag));
int pppread __P((struct tty *tp, struct uio *uio, int flag));
@ -120,6 +131,7 @@ static u_short pppfcs __P((u_short fcs, u_char *cp, int len));
static void pppasyncstart __P((struct ppp_softc *));
static void pppasyncctlp __P((struct ppp_softc *));
static void pppasyncrelinq __P((struct ppp_softc *));
static void pppasyncsetmtu __P((struct ppp_softc *));
static void ppp_timeout __P((void *));
static void pppgetm __P((struct ppp_softc *sc));
static void pppdumpb __P((u_char *b, int l));
@ -147,7 +159,7 @@ static void ppplogchar __P((struct ppp_softc *, int));
* Procedures for using an async tty interface for PPP.
*/
/* This is a FreeBSD-2.0 kernel. */
/* This is a FreeBSD-2.X kernel. */
#define CCOUNT(q) ((q)->c_cc)
#define PPP_HIWAT 400 /* Don't start a new packet if HIWAT on que */
@ -161,16 +173,36 @@ static struct linesw pppdisc = {
};
void
pppasyncattach()
pppasyncattach(dummy)
void *dummy;
{
#ifdef i386
int s;
s = splhigh();
/*
* Make sure that the soft net "engine" cannot run while spltty code is
* active. The if_ppp.c code can walk down into b_to_q etc, and it is
* bad if the tty system was in the middle of another b_to_q...
*/
tty_imask |= SWI_NET_MASK; /* spltty() block spl[soft]net() */
net_imask |= SWI_TTY_MASK; /* splimp() block splsofttty() */
net_imask |= tty_imask; /* splimp() block spltty() */
update_intr_masks();
splx(s);
printf("new masks: bio %x, tty %x, net %x\n", bio_imask, tty_imask, net_imask);
#endif
/* register line discipline */
linesw[PPPDISC] = pppdisc;
}
TEXT_SET(pseudo_set, pppasyncattach);
/*
* Line specific open routine for async tty devices.
* Attach the given tty to the first available ppp unit.
* Called from device open routine or ttioctl() at >= splsofttty()
*/
/* ARGSUSED */
int
@ -185,19 +217,24 @@ pppopen(dev, tp)
if (error = suser(p->p_ucred, &p->p_acflag))
return (error);
s = spltty(); /* also netisr's, including NETISR_PPP */
if (tp->t_line == PPPDISC) {
sc = (struct ppp_softc *) tp->t_sc;
if (sc != NULL && sc->sc_devp == (void *) tp)
if (sc != NULL && sc->sc_devp == (void *) tp) {
splx(s);
return (0);
}
}
if ((sc = pppalloc(p->p_pid)) == NULL)
if ((sc = pppalloc(p->p_pid)) == NULL) {
splx(s);
return ENXIO;
}
if (sc->sc_relinq)
(*sc->sc_relinq)(sc); /* get previous owner to relinquish the unit */
s = splimp();
sc->sc_ilen = 0;
sc->sc_m = NULL;
bzero(sc->sc_asyncmap, sizeof(sc->sc_asyncmap));
@ -208,19 +245,33 @@ pppopen(dev, tp)
sc->sc_start = pppasyncstart;
sc->sc_ctlp = pppasyncctlp;
sc->sc_relinq = pppasyncrelinq;
sc->sc_setmtu = pppasyncsetmtu;
sc->sc_outm = NULL;
pppgetm(sc);
sc->sc_if.if_flags |= IFF_RUNNING;
sc->sc_if.if_baudrate = tp->t_ospeed;
tp->t_sc = (caddr_t) sc;
ttyflush(tp, FREAD | FWRITE);
/*
* Pre-allocate cblocks to the "just right" amount. The 1 byte t_canq
* allocation helps avoid the need for select and/or FIONREAD.
* We also pass 1 byte tokens through t_canq...
*/
clist_alloc_cblocks(&tp->t_canq, 1, 1);
clist_alloc_cblocks(&tp->t_outq, sc->sc_if.if_mtu + PPP_HIWAT,
sc->sc_if.if_mtu + PPP_HIWAT);
clist_alloc_cblocks(&tp->t_rawq, 0, 0);
splx(s);
return (0);
}
/*
* Line specific close routine.
* Line specific close routine, called from device close routine
* and from ttioctl at >= splsofttty().
* Detach the tty from the ppp unit.
* Mimics part of ttyclose().
*/
@ -233,8 +284,10 @@ pppclose(tp, flag)
struct mbuf *m;
int s;
ttywflush(tp);
s = splimp(); /* paranoid; splnet probably ok */
s = spltty(); /* also netisr's, including NETISR_PPP */
ttyflush(tp, FREAD | FWRITE);
clist_free_cblocks(&tp->t_canq);
clist_free_cblocks(&tp->t_outq);
tp->t_line = 0;
sc = (struct ppp_softc *) tp->t_sc;
if (sc != NULL) {
@ -257,7 +310,7 @@ pppasyncrelinq(sc)
{
int s;
s = splimp();
s = spltty(); /* also netisr's, including NETISR_PPP */
if (sc->sc_outm) {
m_freem(sc->sc_outm);
sc->sc_outm = NULL;
@ -273,8 +326,27 @@ pppasyncrelinq(sc)
splx(s);
}
/*
* This gets called from the upper layer to notify a mtu change
*/
static void
pppasyncsetmtu(sc)
register struct ppp_softc *sc;
{
register struct tty *tp = (struct tty *) sc->sc_devp;
int s;
s = spltty(); /* also netisr's, including NETISR_PPP */
if (tp != NULL)
clist_alloc_cblocks(&tp->t_outq, sc->sc_if.if_mtu + PPP_HIWAT,
sc->sc_if.if_mtu + PPP_HIWAT);
splx(s);
}
/*
* Line specific (tty) read routine.
* called at no spl from the device driver in the response to user-level
* reads on the tty file descriptor (ie: pppd).
*/
int
pppread(tp, uio, flag)
@ -293,7 +365,7 @@ pppread(tp, uio, flag)
* Loop waiting for input, checking that nothing disasterous
* happens in the meantime.
*/
s = splimp();
s = spltty(); /* also netisr's, including NETISR_PPP */
for (;;) {
if (tp != (struct tty *) sc->sc_devp || tp->t_line != PPPDISC) {
splx(s);
@ -301,7 +373,7 @@ pppread(tp, uio, flag)
}
if (sc->sc_inq.ifq_head != NULL)
break;
if ((tp->t_state & TS_CONNECTED) == 0 && (tp->t_state & TS_ISOPEN)) {
if ((tp->t_state & TS_CONNECTED) == 0) {
splx(s);
return 0; /* end of file */
}
@ -332,6 +404,8 @@ pppread(tp, uio, flag)
/*
* Line specific (tty) write routine.
* called at no spl from the device driver in the response to user-level
* writes on the tty file descriptor (ie: pppd).
*/
int
pppwrite(tp, uio, flag)
@ -342,7 +416,7 @@ pppwrite(tp, uio, flag)
register struct ppp_softc *sc = (struct ppp_softc *)tp->t_sc;
struct mbuf *m, *m0, **mp;
struct sockaddr dst;
int len, error;
int len, error, s;
if ((tp->t_state & TS_CONNECTED) == 0)
return 0; /* wrote 0 bytes */
@ -353,10 +427,13 @@ pppwrite(tp, uio, flag)
if (uio->uio_resid > sc->sc_if.if_mtu + PPP_HDRLEN ||
uio->uio_resid < PPP_HDRLEN)
return (EMSGSIZE);
s = spltty(); /* also netisr's, including NETISR_PPP */
for (mp = &m0; uio->uio_resid; mp = &m->m_next) {
MGET(m, M_WAIT, MT_DATA);
if ((*mp = m) == NULL) {
m_freem(m0);
splx(s);
return (ENOBUFS);
}
m->m_len = 0;
@ -367,6 +444,7 @@ pppwrite(tp, uio, flag)
len = uio->uio_resid;
if (error = uiomove(mtod(m, u_char *), len, uio)) {
m_freem(m0);
splx(s);
return (error);
}
m->m_len = len;
@ -375,7 +453,11 @@ pppwrite(tp, uio, flag)
bcopy(mtod(m0, u_char *), dst.sa_data, PPP_HDRLEN);
m0->m_data += PPP_HDRLEN;
m0->m_len -= PPP_HDRLEN;
return (pppoutput(&sc->sc_if, m0, &dst, (struct rtentry *)0));
/* call the upper layer to "transmit" it... */
error = pppoutput(&sc->sc_if, m0, &dst, (struct rtentry *)0);
splx(s);
return (error);
}
/*
@ -422,7 +504,7 @@ ppptioctl(tp, cmd, data, flag, p)
case PPPIOCSXASYNCMAP:
if (error = suser(p->p_ucred, &p->p_acflag))
break;
s = spltty();
s = spltty(); /* also netisr's, including NETISR_PPP */
bcopy(data, sc->sc_asyncmap, sizeof(sc->sc_asyncmap));
sc->sc_asyncmap[1] = 0; /* mustn't escape 0x20 - 0x3f */
sc->sc_asyncmap[2] &= ~0x40000000; /* mustn't escape 0x5e */
@ -506,30 +588,39 @@ pppasyncstart(sc)
register struct tty *tp = (struct tty *) sc->sc_devp;
int s;
s = splimp();
s = spltty(); /* raise from splnet to spltty */
pppstart(tp);
splx(s);
}
/*
* This gets called when a received packet is placed on
* the inq.
* the inq. The pppd daemon is to be woken up to do a read().
*/
static void
pppasyncctlp(sc)
struct ppp_softc *sc;
{
struct tty *tp;
int s;
/* Put a placeholder byte in canq for ttselect()/ttnread(). */
s = spltty(); /* raise from splnet to spltty */
tp = (struct tty *) sc->sc_devp;
putc(0, &tp->t_canq);
ttwakeup(tp);
splx(s);
}
/*
* Start output on async tty interface. Get another datagram
* to send from the interface queue and start sending it.
*
* Called from tty system at splsofttty() or spltty().
* Called from the upper half at softnet, raised to spltty via asyncstart.
*
* Harmless to be called while the upper netisr code is preempted, but we
* do not want to be preempted by it again.
*/
int
pppstart(tp)
@ -542,13 +633,15 @@ pppstart(tp)
int n, s, ndone, done, idle;
struct mbuf *m2;
if ((tp->t_state & TS_CONNECTED) == 0
|| sc == NULL || tp != (struct tty *) sc->sc_devp) {
if ((tp->t_state & TS_CONNECTED) == 0
|| sc == NULL || tp != (struct tty *) sc->sc_devp
|| tp->t_line != PPPDISC) {
if (tp->t_oproc != NULL)
(*tp->t_oproc)(tp);
return 0;
}
s = spltty(); /* in case.. do not want netisrs to preempt us */
idle = 0;
while (CCOUNT(&tp->t_outq) < PPP_HIWAT) {
/*
@ -578,6 +671,7 @@ pppstart(tp)
/* Calculate the FCS for the first mbuf's worth. */
sc->sc_outfcs = pppfcs(PPP_INITFCS, mtod(m, u_char *), m->m_len);
sc->sc_if.if_lastchange = time;
}
for (;;) {
@ -694,7 +788,7 @@ pppstart(tp)
}
/*
* Send anything that may be in the output queue.
* Call output process whether or not there is any output.
* We are being called in lieu of ttstart and must do what it would.
*/
if (tp->t_oproc != NULL)
@ -709,6 +803,7 @@ pppstart(tp)
timeout(ppp_timeout, (void *) sc, 1);
sc->sc_flags |= SC_TIMEOUT;
}
splx(s);
return 0;
}
@ -724,7 +819,7 @@ ppp_timeout(x)
struct tty *tp = (struct tty *) sc->sc_devp;
int s;
s = splimp();
s = spltty(); /* also netisr's, including NETISR_PPP */
sc->sc_flags &= ~SC_TIMEOUT;
pppstart(tp);
splx(s);
@ -741,7 +836,7 @@ pppgetm(sc)
int len;
int s;
s = splimp();
s = spltty(); /* also netisr's, including NETISR_PPP */
mp = &sc->sc_m;
for (len = sc->sc_mru + PPP_HDRLEN + PPP_FCSLEN; len > 0; ){
if ((m = *mp) == NULL) {
@ -765,6 +860,11 @@ static unsigned paritytab[8] = {
0x69969669, 0x96696996, 0x96696996, 0x69969669
};
/*
* Called when character is available from device driver.
* Only guaranteed to be at splsofttty() or spltty()
* This is safe to be called while the upper half's netisr is preempted.
*/
int
pppinput(c, tp)
int c;
@ -778,18 +878,25 @@ pppinput(c, tp)
if (sc == NULL || tp != (struct tty *) sc->sc_devp)
return 0;
s = spltty();
s = spltty(); /* also netisr's, including NETISR_PPP */
++tk_nin;
++sc->sc_bytesrcvd;
if (c & TTY_FE) {
/* framing error or overrun on this char - abort packet */
if ((tp->t_state & TS_CONNECTED) == 0) {
if (sc->sc_flags & SC_DEBUG)
printf("ppp%d: bad char %x\n", sc->sc_if.if_unit, c);
printf("ppp%d: no carrier\n", sc->sc_if.if_unit);
goto flush;
}
c &= 0xff;
if (c & TTY_ERRORMASK) {
/* framing error or overrun on this char - abort packet */
if (sc->sc_flags & SC_DEBUG)
printf("ppp%d: line error %x\n", sc->sc_if.if_unit,
c & TTY_ERRORMASK);
goto flush;
}
c &= TTY_CHARMASK;
if (c & 0x80)
sc->sc_flags |= SC_RCV_B7_1;