From: Rod Grimes Date: Fri, 27 Aug 1993 02:10:40 +0000 (+0000) Subject: Kernel support for ppp 1.3 + fixes X-Git-Tag: FreeBSD-release/1.1~1921 X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/commitdiff_plain/8b3438a61b11c2f237773d267af97ea0c58f17ab Kernel support for ppp 1.3 + fixes --- diff --git a/sys/conf/files b/sys/conf/files index a912888067..1350564059 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -89,6 +89,7 @@ net/bpf_filter.c optional bpfilter net/if.c standard net/if_ethersubr.c optional ether net/if_loop.c optional loop +net/if_ppp.c optional ppp net/if_sl.c optional sl net/if_tun.c optional tun device-driver net/radix.c standard @@ -97,6 +98,7 @@ net/raw_usrreq.c standard net/route.c standard net/rtsock.c standard net/slcompress.c optional sl +net/slcompress.c optional ppp netccitt/ccitt_proto.c optional ccitt netccitt/hd_debug.c optional ccitt netccitt/hd_input.c optional ccitt diff --git a/sys/i386/conf/LINT b/sys/i386/conf/LINT index 131c275144..3d5bc30fbb 100644 --- a/sys/i386/conf/LINT +++ b/sys/i386/conf/LINT @@ -4,7 +4,7 @@ # # This kernel is NOT MEANT to be runnable! # -# $Id: LINT,v 1.1 1993/08/22 02:59:49 rgrimes Exp $ +# $Id: LINT,v 1.2 1993/08/26 17:55:58 rgrimes Exp $ # machine "i386" @@ -51,6 +51,7 @@ options MFS #Memroy File System options NFS #Network File System #options NS #Xerox NS communications protocols options PCFS #PC (MSDOS) File System +pseudo-device ppp 2 pseudo-device pty 4 options QUOTA #enable disk quotas controller scbus0 diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c index b6165d830c..f12d2f4157 100644 --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -40,7 +40,7 @@ * 26 May 93 Holger Veit Remove hard coded escapes * Rodney W. Grimes Added two more \n to clean up output */ -static char rcsid[] = "$Header: /a/cvs/386BSD/src/sys/kern/init_main.c,v 1.1.1.1 1993/06/12 14:57:34 rgrimes Exp $"; +static char rcsid[] = "$Header: /a/cvs/386BSD/src/sys/kern/init_main.c,v 1.2 1993/08/06 09:53:06 rgrimes Exp $"; #include "param.h" #include "filedesc.h" @@ -229,6 +229,10 @@ main() #if NSL > 0 slattach(); /* XXX */ #endif +#include "ppp.h" +#if NPPP > 0 + pppattach(); /* XXX */ +#endif #include "loop.h" #if NLOOP > 0 loattach(); /* XXX */ diff --git a/sys/kern/tty_conf.c b/sys/kern/tty_conf.c index 2745f43a53..63519c7f30 100644 --- a/sys/kern/tty_conf.c +++ b/sys/kern/tty_conf.c @@ -55,6 +55,11 @@ int tbopen(),tbclose(),tbread(),tbinput(),tbioctl(); #if NSL > 0 int slopen(),slclose(),slinput(),sltioctl(),slstart(); #endif +#include "ppp.h" +#if NPPP > 0 +int pppopen(),pppclose(),pppread(),pppwrite(),pppinput(); +int ppptioctl(),pppstart(),pppselect(); +#endif struct linesw linesw[] = @@ -81,6 +86,13 @@ struct linesw linesw[] = enodev, enodev, enodev, enodev, enodev, enodev, enodev, enodev, enodev, enodev, #endif +#if NPPP > 0 + pppopen, pppclose, pppread, pppwrite, ppptioctl, + pppinput, enodev, nullop, pppstart, ttymodem, /* 5- PPPDISC */ +#else + enodev, enodev, enodev, enodev, enodev, + enodev, enodev, enodev, enodev, enodev, +#endif }; int nldisp = sizeof (linesw) / sizeof (linesw[0]); diff --git a/sys/kern/tty_pty.c b/sys/kern/tty_pty.c index 1000c56d27..057c9bf7eb 100644 --- a/sys/kern/tty_pty.c +++ b/sys/kern/tty_pty.c @@ -47,7 +47,7 @@ * 27 Feb 93 Charles Hannum Proper return values for ptsclose() * and ptcclose() */ -static char rcsid[] = "$Header: /a/cvs/386BSD/src/sys/kern/tty_pty.c,v 1.1.1.1 1993/06/12 14:57:31 rgrimes Exp $"; +static char rcsid[] = "$Header: /a/cvs/386BSD/src/sys/kern/tty_pty.c,v 1.2 1993/08/15 06:11:22 alm Exp $"; /* * Pseudo-teletype Driver @@ -655,8 +655,9 @@ ptyioctl(dev, cmd, data, flag) return(0); } error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag); - if (error < 0) - error = ttioctl(tp, cmd, data, flag); + if (error >= 0) + return (error); + error = ttioctl(tp, cmd, data, flag); /* * Since we use the tty queues internally, * pty's can't be switched to disciplines which overwrite diff --git a/sys/net/if.c b/sys/net/if.c index dc395f5522..349dcff4ba 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -484,6 +484,15 @@ ifioctl(so, cmd, data, p) ifp->if_metric = ifr->ifr_metric; break; + case SIOCSIFMTU: + case SIOCGIFMTU: + case SIOCSIFASYNCMAP: + case SIOCGIFASYNCMAP: + if (!ifp->if_ioctl) + return (EOPNOTSUPP); + return ((*ifp->if_ioctl)(ifp, cmd, data)); + break; + default: if (so->so_proto == 0) return (EOPNOTSUPP); diff --git a/sys/net/if_ppp.c b/sys/net/if_ppp.c new file mode 100644 index 0000000000..2b5be3c0dc --- /dev/null +++ b/sys/net/if_ppp.c @@ -0,0 +1,1262 @@ +/* + * if_ppp.c - Point-to-Point Protocol (PPP) Asynchronous driver. + * + * Copyright (c) 1989 Carnegie Mellon University. + * All rights reserved. + * + * Redistribution and use in source and binary forms are permitted + * provided that the above copyright notice and this paragraph are + * duplicated in all such forms and that any documentation, + * advertising materials, and other materials related to such + * distribution and use acknowledge that the software was developed + * by Carnegie Mellon University. The name of the + * University may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Drew D. Perkins + * Carnegie Mellon University + * 4910 Forbes Ave. + * Pittsburgh, PA 15213 + * (412) 268-8576 + * ddp@andrew.cmu.edu + * + * Based on: + * @(#)if_sl.c 7.6.1.2 (Berkeley) 2/15/89 + * + * Copyright (c) 1987 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms are permitted + * provided that the above copyright notice and this paragraph are + * duplicated in all such forms and that any documentation, + * advertising materials, and other materials related to such + * distribution and use acknowledge that the software was developed + * by the University of California, Berkeley. The name of the + * University may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Serial Line interface + * + * Rick Adams + * Center for Seismic Studies + * 1300 N 17th Street, Suite 1450 + * Arlington, Virginia 22209 + * (703)276-7900 + * rick@seismo.ARPA + * seismo!rick + * + * Pounded on heavily by Chris Torek (chris@mimsy.umd.edu, umcp-cs!chris). + * Converted to 4.3BSD Beta by Chris Torek. + * Other changes made at Berkeley, based in part on code by Kirk Smith. + * + * Converted to 4.3BSD+ 386BSD by Brad Parker (brad@cayman.com) + * Added VJ tcp header compression; more unified ioctls + * + * Extensively modified by Paul Mackerras (paulus@cs.anu.edu.au). + * Cleaned up a lot of the mbuf-related code to fix bugs that + * caused system crashes and packet corruption. Changed pppstart + * so that it doesn't just give up with a collision if the whole + * packet doesn't fit in the output ring buffer. + */ + +/* + * $Id$ + * From: if_ppp.c,v 1.20 1993/08/16 02:13:13 paulus Exp + * From: if_sl.c,v 1.11 84/10/04 12:54:47 rick Exp + */ + +#include "ppp.h" +#if NPPP > 0 + +#define VJC + +#include "param.h" +#include "systm.h" +#include "proc.h" +#include "mbuf.h" +#include "buf.h" +#include "dkstat.h" +#include "socket.h" +#include "ioctl.h" +#include "file.h" +#include "tty.h" +#include "kernel.h" +#include "conf.h" + +#include "if.h" +#include "if_types.h" +#include "netisr.h" +#include "route.h" +#if INET +#include "../netinet/in.h" +#include "../netinet/in_systm.h" +#include "../netinet/in_var.h" +#include "../netinet/ip.h" +#endif + +/* + * Here we try to tell whether we are in a 386BSD kernel, or + * in a NetBSD/Net-2/4.3-Reno kernel. + */ +#ifndef RB_LEN +/* NetBSD, 4.3-Reno or similar */ +#define CCOUNT(q) ((q)->c_cc) + +#else +/* 386BSD, Jolitz-style ring buffers */ +#define t_outq t_out +#define t_rawq t_raw +#define t_canq t_can +#define CCOUNT(q) (RB_LEN(q)) +#endif + +#ifdef VJC +#include "slcompress.h" +#define HDROFF MAX_HDR +/* HDROFF should really be 128, but other parts of the system will + panic on TCP+IP headers bigger than MAX_HDR = MHLEN (100). */ + +#else +#define HDROFF (0) +#endif + +#include "if_ppp.h" +#include "machine/mtpr.h" + +struct ppp_softc ppp_softc[NPPP]; +int ppp_async_out_debug = 0; +int ppp_async_in_debug = 0; +int ppp_debug = 0; + +void pppattach __P((void)); +int pppopen __P((dev_t dev, struct tty *tp)); +void pppclose __P((struct tty *tp, int flag)); +int pppread __P((struct tty *tp, struct uio *uio, int flag)); +int pppwrite __P((struct tty *tp, struct uio *uio, int flag)); +int ppptioctl __P((struct tty *tp, int cmd, caddr_t data, int flag)); +int pppoutput __P((struct ifnet *ifp, struct mbuf *m0, + struct sockaddr *dst)); +void pppstart __P((struct tty *tp)); +void pppinput __P((int c, struct tty *tp)); +int pppioctl __P((struct ifnet *ifp, int cmd, caddr_t data)); + +static u_short pppfcs __P((u_short fcs, u_char *cp, int len)); +static int pppinit __P((struct ppp_softc *sc)); +static struct mbuf *ppp_btom __P((struct ppp_softc *sc)); +static void pppdumpm __P((struct mbuf *m0, int pktlen)); +static void pppdumpb __P((u_char *b, int l)); + +/* + * Some useful mbuf macros not in mbuf.h. + */ +#define M_DATASTART(m) \ + ((m)->m_flags & M_EXT ? (m)->m_ext.ext_buf : \ + (m)->m_flags & M_PKTHDR ? (m)->m_pktdat : (m)->m_dat) + +#define M_DATASIZE(m) \ + ((m)->m_flags & M_EXT ? (m)->m_ext.ext_size : \ + (m)->m_flags & M_PKTHDR ? MHLEN: MLEN) + +/* + * Called from boot code to establish ppp interfaces. + */ +void +pppattach() +{ + register struct ppp_softc *sc; + register int i = 0; + + for (sc = ppp_softc; i < NPPP; sc++) { + sc->sc_if.if_name = "ppp"; + sc->sc_if.if_unit = i++; + sc->sc_if.if_mtu = PPP_MTU; + sc->sc_if.if_flags = IFF_POINTOPOINT; + sc->sc_if.if_type = IFT_PPP; + sc->sc_if.if_hdrlen = sizeof(struct ppp_header); + sc->sc_if.if_ioctl = pppioctl; + sc->sc_if.if_output = pppoutput; + sc->sc_if.if_snd.ifq_maxlen = IFQ_MAXLEN; + sc->sc_inq.ifq_maxlen = IFQ_MAXLEN; + if_attach(&sc->sc_if); + } +} + +/* + * Line specific open routine. + * Attach the given tty to the first available ppp unit. + */ +/* ARGSUSED */ +int +pppopen(dev, tp) + dev_t dev; + register struct tty *tp; +{ + struct proc *p = curproc; /* XXX */ + register struct ppp_softc *sc; + register int nppp; + int error, s; + + if (error = suser(p->p_ucred, &p->p_acflag)) + return (error); + + if (tp->t_line == PPPDISC) + return (0); + + for (nppp = 0, sc = ppp_softc; nppp < NPPP; nppp++, sc++) + if (sc->sc_ttyp == NULL) { + sc->sc_flags = 0; + sc->sc_ilen = 0; + sc->sc_asyncmap = 0xffffffff; +#ifdef VJC + sl_compress_init(&sc->sc_comp); +#endif + if (pppinit(sc) == 0) { + sc->sc_if.if_flags &= ~(IFF_UP|IFF_RUNNING); + return (ENOBUFS); + } + tp->t_sc = (caddr_t)sc; + sc->sc_ttyp = tp; + sc->sc_outm = NULL; + ttyflush(tp, FREAD | FWRITE); + sc->sc_if.if_flags |= IFF_RUNNING; + +#ifdef PPP_OUTQ_SIZE + /* N.B. this code is designed *only* for use in NetBSD */ + s = spltty(); + /* get rid of the default outq clist buffer */ + clfree(&tp->t_outq); + /* and get a new one, without quoting support, much larger */ + clalloc(&tp->t_outq, PPP_OUTQ_SIZE, 0); + splx (s); +#endif /* PPP_OUTQ_SIZE */ + + return (0); + } + + return (ENXIO); +} + +/* + * Line specific close routine. + * Detach the tty from the ppp unit. + * Mimics part of ttyclose(). + */ +void +pppclose(tp, flag) + struct tty *tp; + int flag; +{ + register struct ppp_softc *sc; + struct mbuf *m; + int s; + + ttywflush(tp); + s = splimp(); /* paranoid; splnet probably ok */ + tp->t_line = 0; + sc = (struct ppp_softc *)tp->t_sc; + if (sc != NULL) { + if_down(&sc->sc_if); + sc->sc_ttyp = NULL; + tp->t_sc = NULL; + m_freem(sc->sc_outm); + sc->sc_outm = NULL; + m_freem(sc->sc_m); + sc->sc_m = NULL; + for (;;) { + IF_DEQUEUE(&sc->sc_inq, m); + if (m == NULL) + break; + m_freem(m); + } + sc->sc_if.if_flags &= ~(IFF_UP|IFF_RUNNING); + +#ifdef PPP_OUTQ_SIZE + /* reinstall default clist-buffer for outq + XXXX should really remember old value and restore that!! */ + clfree(&tp->t_outq); + clalloc(&tp->t_outq, 1024, 0); +#endif /* PPP_OUTQ_SIZE */ + + } + splx(s); +} + +/* + * Line specific (tty) read routine. + */ +int +pppread(tp, uio, flag) + register struct tty *tp; + struct uio *uio; + int flag; +{ + register struct ppp_softc *sc = (struct ppp_softc *)tp->t_sc; + struct mbuf *m, *m0; + register int s; + int error; + + if ((tp->t_state & TS_CARR_ON)==0) + return (EIO); + s = splimp(); + while (sc->sc_inq.ifq_head == NULL && tp->t_line == PPPDISC) { + if (tp->t_state & TS_ASYNC) { + splx(s); + return (EWOULDBLOCK); + } + error = ttysleep(tp, (caddr_t)&tp->t_rawq, TTIPRI|PCATCH, ttyin, 0); + if (error) + return error; + } + if (tp->t_line != PPPDISC) { + splx(s); + return (-1); + } + + /* Pull place-holder byte out of canonical queue */ + getc(&tp->t_canq); + + /* Get the packet from the input queue */ + IF_DEQUEUE(&sc->sc_inq, m0); + splx(s); + + for (m = m0; m && uio->uio_resid; m = m->m_next) + if (error = uiomove(mtod(m, u_char *), m->m_len, uio)) + break; + m_freem(m0); + return (error); +} + +/* + * Line specific (tty) write routine. + */ +int +pppwrite(tp, uio, flag) + register struct tty *tp; + struct uio *uio; + int flag; +{ + register struct ppp_softc *sc = (struct ppp_softc *)tp->t_sc; + struct mbuf *m, *m0, **mp; + struct sockaddr dst; + struct ppp_header *ph1, *ph2; + int len, error; + + if ((tp->t_state & TS_CARR_ON)==0) + return (EIO); + if (tp->t_line != PPPDISC) + return (EINVAL); + if (uio->uio_resid > sc->sc_if.if_mtu + sizeof (struct ppp_header) || + uio->uio_resid < sizeof (struct ppp_header)) + return (EMSGSIZE); + for (mp = &m0; uio->uio_resid; mp = &m->m_next) { + MGET(m, M_WAIT, MT_DATA); + if ((*mp = m) == NULL) { + m_freem(m0); + return (ENOBUFS); + } + if (uio->uio_resid >= MCLBYTES / 2) + MCLGET(m, M_DONTWAIT); + len = MIN(M_TRAILINGSPACE(m), uio->uio_resid); + if (error = uiomove(mtod(m, u_char *), len, uio)) { + m_freem(m0); + return (error); + } + m->m_len = len; + } + dst.sa_family = AF_UNSPEC; + ph1 = (struct ppp_header *) &dst.sa_data; + ph2 = mtod(m0, struct ppp_header *); + *ph1 = *ph2; + m0->m_data += sizeof (struct ppp_header); + m0->m_len -= sizeof (struct ppp_header); + return (pppoutput(&sc->sc_if, m0, &dst)); +} + +/* + * Line specific (tty) ioctl routine. + * Provide a way to get the ppp unit number. + * This discipline requires that tty device drivers call + * the line specific l_ioctl routine from their ioctl routines. + */ +/* ARGSUSED */ +int +ppptioctl(tp, cmd, data, flag) + struct tty *tp; + caddr_t data; + int cmd, flag; +{ + register struct ppp_softc *sc = (struct ppp_softc *)tp->t_sc; + struct proc *p = curproc; /* XXX */ + int s, error; + + switch (cmd) { +#if 0 /* this is handled (properly) by ttioctl */ + case TIOCGETD: + *(int *)data = sc->sc_if.if_unit; + break; +#endif + case FIONREAD: + *(int *)data = sc->sc_inq.ifq_len; + break; + + case PPPIOCGUNIT: + *(int *)data = sc->sc_if.if_unit; + break; + + case PPPIOCGFLAGS: + *(u_int *)data = sc->sc_flags; + break; + + case PPPIOCSFLAGS: + if (error = suser(p->p_ucred, &p->p_acflag)) + return (error); +#define SC_MASK 0xffff + s = splimp(); + sc->sc_flags = + (sc->sc_flags & ~SC_MASK) | ((*(int *)data) & SC_MASK); + splx(s); + break; + + case PPPIOCSASYNCMAP: + if (error = suser(p->p_ucred, &p->p_acflag)) + return (error); + sc->sc_asyncmap = *(u_int *)data; + break; + + case PPPIOCGASYNCMAP: + *(u_int *)data = sc->sc_asyncmap; + break; + + default: + return (-1); + } + return (0); +} + +/* + * FCS lookup table as calculated by genfcstab. + */ +static u_short fcstab[256] = { + 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, + 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7, + 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e, + 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876, + 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd, + 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5, + 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c, + 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974, + 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb, + 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3, + 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a, + 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72, + 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9, + 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1, + 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738, + 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70, + 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7, + 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff, + 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036, + 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e, + 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5, + 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd, + 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134, + 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c, + 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3, + 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb, + 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232, + 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a, + 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1, + 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9, + 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330, + 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78 +}; + +/* + * Calculate a new FCS given the current FCS and the new data. + */ +static u_short +pppfcs(fcs, cp, len) + register u_short fcs; + register u_char *cp; + register int len; +{ + while (len--) + fcs = PPP_FCS(fcs, *cp++); + return (fcs); +} + +/* + * Queue a packet. Start transmission if not active. + * Packet is placed in Information field of PPP frame. + */ +int +pppoutput(ifp, m0, dst) + struct ifnet *ifp; + struct mbuf *m0; + struct sockaddr *dst; +{ + register struct ppp_softc *sc = &ppp_softc[ifp->if_unit]; + struct mbuf *m, *m1; + struct ppp_header *ph; + u_short protocol, fcs; + u_char address, control, *cp; + int s, error, compac, compprot; + + if (sc->sc_ttyp == NULL || (ifp->if_flags & IFF_RUNNING) == 0 + || (ifp->if_flags & IFF_UP) == 0 && dst->sa_family != AF_UNSPEC) { + error = ENETDOWN; /* sort of */ + goto bad; + } + if ((sc->sc_ttyp->t_state & TS_CARR_ON) == 0) { + error = EHOSTUNREACH; + goto bad; + } + + /* + * Compute PPP header. + */ + address = PPP_ALLSTATIONS; + control = PPP_UI; + switch (dst->sa_family) { +#ifdef INET + case AF_INET: + protocol = PPP_IP; +#ifdef VJC + if (sc->sc_flags & SC_COMP_TCP) { + register struct ip *ip; + + if ((ip = mtod(m0, struct ip *))->ip_p == IPPROTO_TCP) { + int type = sl_compress_tcp(m0, ip, &sc->sc_comp, 1); + switch (type) { + case TYPE_UNCOMPRESSED_TCP: + protocol = PPP_VJC_UNCOMP; + break; + case TYPE_COMPRESSED_TCP: + protocol = PPP_VJC_COMP; + break; + } + } + } +#endif + break; +#endif +#ifdef NS + case AF_NS: + protocol = PPP_XNS; + break; +#endif + case AF_UNSPEC: + ph = (struct ppp_header *) dst->sa_data; + address = ph->ph_address; + control = ph->ph_control; + protocol = ntohs(ph->ph_protocol); + break; + default: + printf("ppp%d: af%d not supported\n", ifp->if_unit, dst->sa_family); + error = EAFNOSUPPORT; + goto bad; + } + compac = sc->sc_flags & SC_COMP_AC && address == PPP_ALLSTATIONS && + control == PPP_UI && protocol != PPP_ALLSTATIONS && + protocol != PPP_LCP; + compprot = sc->sc_flags & SC_COMP_PROT && protocol < 0x100; + + /* + * Add PPP header. If no space in first mbuf, allocate another. + */ + if (M_LEADINGSPACE(m0) < sizeof(struct ppp_header)) { + m0 = m_prepend(m0, sizeof(struct ppp_header), M_DONTWAIT); + if (m0 == 0) { + error = ENOBUFS; + goto bad; + } + m0->m_len = 0; + } else + m0->m_data -= (compac ? 0 : 2) + (compprot ? 1 : 2); + + cp = mtod(m0, u_char *); + if (!compac) { + *cp++ = address; + *cp++ = control; + m0->m_len += 2; + } + if (!compprot) { + *cp++ = protocol >> 8; + m0->m_len++; + } + *cp++ = protocol & 0xff; + m0->m_len++; + + /* + * Add PPP trailer. Compute one's complement of FCS over frame + * and attach to mbuf chain least significant byte first. + */ + fcs = PPP_INITFCS; + for (m = m0; m; m = m->m_next) { + fcs = pppfcs(fcs, mtod(m, u_char *), m->m_len); + m1 = m; + } + fcs ^= 0xffff; + + /* + * If the last mbuf is a cluster, we can't just store the + * FCS in it (other mbufs might point to the same cluster). + */ + if (M_TRAILINGSPACE(m1) < sizeof(short) || m1->m_flags & M_EXT) { + MGET(m, M_DONTWAIT, MT_HEADER); + if (m == 0) { + error = ENOBUFS; + goto bad; + } + m->m_next = NULL; + m->m_len = 0; + m1->m_next = m; + m1 = m; + } + cp = mtod(m1, u_char *) + m1->m_len; + + *cp++ = fcs & 0xff; + *cp++ = fcs >> 8; + m1->m_len += 2; + + if (ppp_async_out_debug) { + printf("ppp%d output: ", ifp->if_unit); + pppdumpm(m0, -1); + } + + s = splimp(); + if (IF_QFULL(&ifp->if_snd)) { + IF_DROP(&ifp->if_snd); + splx(s); + sc->sc_if.if_oerrors++; + error = ENOBUFS; + goto bad; + } + IF_ENQUEUE(&ifp->if_snd, m0); + if (CCOUNT(&sc->sc_ttyp->t_outq) == 0) + pppstart(sc->sc_ttyp); + splx(s); + return (0); + +bad: + m_freem(m0); + return (error); +} + +/* + * Start output on interface. Get another datagram + * to send from the interface queue and map it to + * the interface before starting output. + */ +void +pppstart(tp) + register struct tty *tp; +{ + register struct ppp_softc *sc = (struct ppp_softc *)tp->t_sc; + register struct mbuf *m; + register int len; + register u_char *start, *stop, *cp; + int n, s, ndone; + struct mbuf *m2; + + for (;;) { + /* + * If there is more in the output queue, just send it now. + * We are being called in lieu of ttstart and must do what + * it would. + */ + if (CCOUNT(&tp->t_outq) != 0 && tp->t_oproc != NULL) { + (*tp->t_oproc)(tp); + if (CCOUNT(&tp->t_outq) > PPP_HIWAT) + return; + } + /* + * This happens briefly when the line shuts down. + */ + if (sc == NULL) + return; + + /* + * See if we have an existing packet partly sent. + * If not, get a new packet and start sending it. + */ + m = sc->sc_outm; + if (m == NULL) { + s = splimp(); + IF_DEQUEUE(&sc->sc_if.if_snd, m); + splx(s); + if (m == NULL) + return; + + /* + * The extra PPP_FLAG will start up a new packet, and thus + * will flush any accumulated garbage. We do this whenever + * the line may have been idle for some time. + */ + if (CCOUNT(&tp->t_outq) == 0) { + ++sc->sc_bytessent; + (void) putc(PPP_FLAG, &tp->t_outq); + } + } + + do { + start = mtod(m, u_char *); + len = m->m_len; + stop = start + len; + while (len > 0) { + /* + * Find out how many bytes in the string we can + * handle without doing something special. + */ + for (cp = start; cp < stop; cp++) + if ((*cp == PPP_FLAG) || (*cp == PPP_ESCAPE) || + (*cp < 0x20 && (sc->sc_asyncmap & (1 << *cp)))) + break; + n = cp - start; + if (n) { +#ifndef RB_LEN + /* NetBSD (0.9 or later), 4.3-Reno or similar. */ + ndone = n - b_to_q(start, n, &tp->t_outq); +#else +#ifdef NetBSD + /* NetBSD, 0.8 or earlier */ + ndone = rb_cwrite(&tp->t_out, start, n); +#else + /* 386BSD */ + int cc, nleft; + for (nleft = n; nleft > 0; nleft -= cc) { + if ((cc = RB_CONTIGPUT(&tp->t_out)) == 0) + break; + cc = min (cc, nleft); + bcopy((char *)start, tp->t_out.rb_tl, cc); + tp->t_out.rb_tl = RB_ROLLOVER(&tp->t_out, + tp->t_out.rb_tl + cc); + } + ndone = n - nleft; +#endif /* NetBSD */ +#endif /* RB_LEN */ + len -= ndone; + start += ndone; + sc->sc_bytessent += ndone; + + if (ndone < n) + break; /* packet doesn't fit */ + } + /* + * If there are characters left in the mbuf, + * the first one must be special.. + * Put it out in a different form. + */ + if (len) { + if (putc(PPP_ESCAPE, &tp->t_outq)) + break; + if (putc(*start ^ PPP_TRANS, &tp->t_outq)) { + (void) unputc(&tp->t_outq); + break; + } + sc->sc_bytessent += 2; + start++; + len--; + } + } + /* + * If we didn't empty this mbuf, remember where we're up to. + * If we emptied the last mbuf, try to add the closing flag, + * and if we can't, leave sc_outm pointing to m, but with + * m->m_len == 0, to remind us to output the flag later. + */ + if (len > 0 || m->m_next == NULL && putc(PPP_FLAG, &tp->t_outq)) { + m->m_data = start; + m->m_len = len; + sc->sc_outm = m; + if (tp->t_oproc != NULL) + (*tp->t_oproc)(tp); + return; /* can't do any more at the moment */ + } + + /* Finished with this mbuf; free it and move on. */ + MFREE(m, m2); + m = m2; + } while (m); + + /* Finished a packet */ + sc->sc_outm = NULL; + sc->sc_bytessent++; /* account for closing flag */ + sc->sc_if.if_opackets++; + sc->sc_if.if_obytes = sc->sc_bytessent; + } +} + +/* + * Allocate enough mbuf to handle current MTU. + */ +static int +pppinit(sc) + register struct ppp_softc *sc; +{ + struct mbuf *m, **mp; + int len = HDROFF + MAX(sc->sc_if.if_mtu, PPP_MRU) + + sizeof (struct ppp_header) + sizeof (u_short); + int s; + + s = splimp(); + for (mp = &sc->sc_m; (m = *mp) != NULL; mp = &m->m_next) + if ((len -= M_DATASIZE(m)) <= 0) { + splx(s); + return (1); + } + + for (;; mp = &m->m_next) { + MGETHDR(m, M_DONTWAIT, MT_DATA); + if (m == 0) { + m_freem(sc->sc_m); + sc->sc_m = NULL; + splx(s); + printf("ppp%d: can't allocate mbuf\n", sc - ppp_softc); + return (0); + } + *mp = m; + MCLGET(m, M_DONTWAIT); + if ((len -= M_DATASIZE(m)) <= 0) { + splx(s); + return (1); + } + } +} + +/* + * Copy mbuf chain. Would like to use m_copy(), but we need a real copy + * of the data, not just copies of pointers to the data. + */ +static struct mbuf * +ppp_btom(sc) + struct ppp_softc *sc; +{ + register struct mbuf *m, **mp; + struct mbuf *top = sc->sc_m; + + /* + * First check current mbuf. If we have more than a small mbuf, + * return the whole cluster and set beginning of buffer to the + * next mbuf. + * Else, copy the current bytes into a small mbuf, attach the new + * mbuf to the end of the chain and set beginning of buffer to the + * current mbuf. + */ + + if (sc->sc_mc->m_len > MHLEN) { + sc->sc_m = sc->sc_mc->m_next; + sc->sc_mc->m_next = NULL; + } + else { + /* rather than waste a whole cluster on <= MHLEN bytes, + alloc a small mbuf and copy to it */ + MGETHDR(m, M_DONTWAIT, MT_DATA); + if (m == NULL) + return (NULL); + + bcopy(mtod(sc->sc_mc, caddr_t), mtod(m, caddr_t), + sc->sc_mc->m_len); + m->m_len = sc->sc_mc->m_len; + for (mp = ⊤ *mp != sc->sc_mc; mp = &(*mp)->m_next) + ; + *mp = m; + sc->sc_m = sc->sc_mc; + } + + /* + * Try to allocate enough extra mbufs to handle the next packet. + */ + if (pppinit(sc) == 0) { + m_freem(top); + if (pppinit(sc) == 0) + sc->sc_if.if_flags &= ~IFF_UP; + return (NULL); + } + + return (top); +} + +/* + * tty interface receiver interrupt. + */ +#define COMPTYPE(proto) ((proto) == PPP_VJC_COMP? TYPE_COMPRESSED_TCP: \ + TYPE_UNCOMPRESSED_TCP) + +void +pppinput(c, tp) + int c; + register struct tty *tp; +{ + register struct ppp_softc *sc; + struct mbuf *m; + struct ifqueue *inq; + int s, ilen, xlen, proto; + char *pkttype; + + tk_nin++; + sc = (struct ppp_softc *)tp->t_sc; + if (sc == NULL) + return; + + ++sc->sc_if.if_ibytes; + + if (c & TTY_FE) + /* framing error or overrun on this char - abort packet */ + goto flush; + + c &= 0xff; + if (c == PPP_FLAG) { + ilen = sc->sc_ilen; + sc->sc_ilen = 0; + + if (sc->sc_flags & SC_FLUSH + || ilen > 0 && sc->sc_fcs != PPP_GOODFCS) { +#ifdef VJC + /* + * If we've missed a packet, we must toss subsequent compressed + * packets which don't have an explicit connection ID. + */ + sl_uncompress_tcp(NULL, 0, TYPE_ERROR, &sc->sc_comp); +#endif + if ((sc->sc_flags & SC_FLUSH) == 0){ + if (ppp_debug) + printf("ppp: bad fcs\n"); + sc->sc_if.if_ierrors++; + } else + sc->sc_flags &= ~SC_FLUSH; + return; + } + + if (ilen < sizeof (struct ppp_header) + 2) { + if (ilen) { + if (ppp_debug) + printf("ppp: too short (%d)\n", ilen); + sc->sc_if.if_ierrors++; + } + return; + } + + /* + * Remove FCS trailer. Somewhat painful... + */ + ilen -= 2; + if (--sc->sc_mc->m_len == 0) { + for (m = sc->sc_m; m->m_next != sc->sc_mc; m = m->m_next) + ; + sc->sc_mc = m; + } + sc->sc_mc->m_len--; + + sc->sc_if.if_ipackets++; + m = sc->sc_m; + + if (ppp_async_in_debug) { + printf("ppp%d: got %d bytes\n", sc - ppp_softc, ilen); + pppdumpm(m, ilen); + } + + proto = ntohs(mtod(m, struct ppp_header *)->ph_protocol); + switch (proto) { +#ifdef INET + case PPP_IP: + ilen -= sizeof (struct ppp_header); + m->m_data += sizeof (struct ppp_header); + m->m_len -= sizeof (struct ppp_header); + break; + +#ifdef VJC + case PPP_VJC_COMP: + case PPP_VJC_UNCOMP: + pkttype = proto == PPP_VJC_COMP? "": "un"; + if (sc->sc_flags & SC_COMP_TCP) { + + m->m_data += sizeof (struct ppp_header); + m->m_len -= sizeof (struct ppp_header); + ilen -= sizeof(struct ppp_header); + + xlen = sl_uncompress_tcp_part((u_char **)(&m->m_data), + m->m_len, ilen, + COMPTYPE(proto), &sc->sc_comp); + + if (xlen) { + /* adjust the first mbuf by the decompressed amt */ + m->m_len += xlen - ilen; + ilen = xlen; + proto = PPP_IP; + break; + } + + if (ppp_debug) + printf("ppp%d: sl_uncompress failed on type %scomp\n", + sc->sc_if.if_unit, pkttype); + + } else { + if (ppp_debug) + printf("ppp%d: %scomp pkt w/o compression; flags 0x%x\n", + sc->sc_if.if_unit, pkttype, sc->sc_flags); + } + if (ppp_debug) + printf("ppp: packet rejected, protocol 0x%x\n", proto); + sc->sc_if.if_ierrors++; + return; +#endif +#endif + } + + /* get this packet as an mbuf chain */ + if ((m = ppp_btom(sc)) == NULL) { + sc->sc_if.if_ierrors++; + return; + } + m->m_pkthdr.len = ilen; + m->m_pkthdr.rcvif = &sc->sc_if; + + if (proto == PPP_IP) { + /* IP packet - pass it up to IP */ + if ((sc->sc_if.if_flags & IFF_UP) == 0) { + /* interface is down - drop the packet. */ + m_freem(m); + sc->sc_if.if_ierrors++; + return; + } + schednetisr(NETISR_IP); + inq = &ipintrq; + + } else { + /* some other protocol - place on input queue for read() */ + /* Put a placeholder byte in canq for ttselect()/ttnread() */ + putc(0, &tp->t_canq); + ttwakeup(tp); + inq = &sc->sc_inq; + } + + s = splimp(); + if (IF_QFULL(inq)) { + IF_DROP(inq); + if (ppp_debug) + printf("ppp: queue full\n"); + sc->sc_if.if_ierrors++; + sc->sc_if.if_iqdrops++; + m_freem(m); + } else + IF_ENQUEUE(inq, m); + + splx(s); + return; + } + if (sc->sc_flags & SC_FLUSH) + return; + if (c == PPP_ESCAPE) { + sc->sc_flags |= SC_ESCAPED; + return; + } + + if (sc->sc_flags & SC_ESCAPED) { + sc->sc_flags &= ~SC_ESCAPED; + c ^= PPP_TRANS; + } + + /* + * Initialize buffer on first octet received. + * First octet could be address or protocol (when compressing + * address/control). + * Second octet is control. + * Third octet is first or second (when compressing protocol) + * octet of protocol. + * Fourth octet is second octet of protocol. + */ + if (sc->sc_ilen == 0) { + /* reset the first input mbuf */ + m = sc->sc_m; + m->m_len = 0; + m->m_data = M_DATASTART(sc->sc_m) + HDROFF; + sc->sc_mc = m; + sc->sc_mp = mtod(m, char *); + sc->sc_fcs = PPP_INITFCS; + if (c != PPP_ALLSTATIONS) { + if ((sc->sc_flags & SC_COMP_AC) == 0) { + if (ppp_debug) + printf("ppp: missing ALLSTATIONS, got 0x%x; flags %x\n", + c, sc->sc_flags); + goto flush; + } + *sc->sc_mp++ = PPP_ALLSTATIONS; + *sc->sc_mp++ = PPP_UI; + sc->sc_ilen += 2; + m->m_len += 2; + } + } + if (sc->sc_ilen == 1 && c != PPP_UI) { + if (ppp_debug) + printf("ppp: missing UI, got 0x%x\n", c); + goto flush; + } + if (sc->sc_ilen == 2 && (c & 1) == 1) { + if ((sc->sc_flags & SC_COMP_PROT) == 0) { + if (ppp_debug) + printf("ppp: compressed protocol %x, but compression off\n", + c); + goto flush; + } + *sc->sc_mp++ = 0; + sc->sc_ilen++; + sc->sc_mc->m_len++; + } + if (sc->sc_ilen == 3 && (c & 1) == 0) { + if (ppp_debug) + printf("ppp: bad protocol %x\n", c); + goto flush; + } + + /* packet beyond configured mtu? */ + if (++sc->sc_ilen > MAX(sc->sc_if.if_mtu, PPP_MRU) + + sizeof (struct ppp_header) + sizeof (u_short)) { + if (ppp_debug) + printf("ppp: packet too big\n"); + goto flush; + } + + /* is this mbuf full? */ + m = sc->sc_mc; + if (M_TRAILINGSPACE(m) <= 0) { + sc->sc_mc = m = m->m_next; + if (m == NULL) { + printf("ppp%d: too few input mbufs!\n"); + goto flush; + } + m->m_len = 0; + m->m_data = M_DATASTART(m); + sc->sc_mp = mtod(m, char *); + } + + ++m->m_len; + *sc->sc_mp++ = c; + sc->sc_fcs = PPP_FCS(sc->sc_fcs, c); + return; + + flush: + sc->sc_if.if_ierrors++; + sc->sc_flags |= SC_FLUSH; +} + +/* + * Process an ioctl request to interface. + */ +pppioctl(ifp, cmd, data) + register struct ifnet *ifp; + int cmd; + caddr_t data; +{ + struct proc *p = curproc; /* XXX */ + register struct ppp_softc *sc = &ppp_softc[ifp->if_unit]; + register struct ifaddr *ifa = (struct ifaddr *)data; + register struct ifreq *ifr = (struct ifreq *)data; + int s = splimp(), error = 0; + + + switch (cmd) { + case SIOCSIFFLAGS: + if ((ifp->if_flags & IFF_RUNNING) == 0) + ifp->if_flags &= ~IFF_UP; + break; + + case SIOCSIFADDR: + if (ifa->ifa_addr->sa_family != AF_INET) + error = EAFNOSUPPORT; + break; + + case SIOCSIFDSTADDR: + if (ifa->ifa_addr->sa_family != AF_INET) + error = EAFNOSUPPORT; + break; + + case SIOCSIFMTU: + if (error = suser(p->p_ucred, &p->p_acflag)) + return (error); + sc->sc_if.if_mtu = ifr->ifr_mtu; + if (pppinit(sc) == 0) + error = ENOBUFS; + break; + + case SIOCGIFMTU: + ifr->ifr_mtu = sc->sc_if.if_mtu; + break; + + default: + error = EINVAL; + } + splx(s); + return (error); +} + +#define MAX_DUMP_BYTES 128 + +static void +pppdumpm(m0, pktlen) + struct mbuf *m0; + int pktlen; +{ + char buf[2*MAX_DUMP_BYTES+4]; + char *bp = buf; + struct mbuf *m; + static char digits[] = "0123456789abcdef"; + + for (m = m0; m && pktlen; m = m->m_next) { + int l = m->m_len; + u_char *rptr = (u_char *)m->m_data; + + if (pktlen > 0) { + l = min(l, pktlen); + pktlen -= l; + } + while (l--) { + if (bp > buf + sizeof(buf) - 4) + goto done; + *bp++ = digits[*rptr >> 4]; /* convert byte to ascii hex */ + *bp++ = digits[*rptr++ & 0xf]; + } + + if (m->m_next) { + if (bp > buf + sizeof(buf) - 3) + goto done; + *bp++ = '|'; + } + } +done: + if (m && pktlen) + *bp++ = '>'; + *bp = 0; + printf("%s\n", buf); +} + +static void +pppdumpb(b, l) + u_char *b; + int l; +{ + char buf[2*MAX_DUMP_BYTES+4]; + char *bp = buf; + static char digits[] = "0123456789abcdef"; + + while (l--) { + *bp++ = digits[*b >> 4]; /* convert byte to ascii hex */ + *bp++ = digits[*b++ & 0xf]; + if (bp >= buf + sizeof(buf) - 2) { + *bp++ = '>'; + break; + } + } + + *bp = 0; + printf("%s\n", buf); +} + + +#endif /* NPPP > 0 */ diff --git a/sys/net/if_ppp.h b/sys/net/if_ppp.h new file mode 100644 index 0000000000..a3e2cd104a --- /dev/null +++ b/sys/net/if_ppp.h @@ -0,0 +1,100 @@ +/* + * if_ppp.h - Point-to-Point Protocol definitions. + * + * Copyright (c) 1989 Carnegie Mellon University. + * All rights reserved. + * + * Redistribution and use in source and binary forms are permitted + * provided that the above copyright notice and this paragraph are + * duplicated in all such forms and that any documentation, + * advertising materials, and other materials related to such + * distribution and use acknowledge that the software was developed + * by Carnegie Mellon University. The name of the + * University may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Modified by Paul Mackerras (paulus@cs.anu.edu.au) + * PPP_MRU added, PPP_MTU changed to 296 (default only), added sc_outm. + * + * $Id$ + * From: if_ppp.h,v 1.3 1993/08/09 02:37:32 paulus Exp + */ + +/* + * 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_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 types. + */ +#define PPP_IP 0x21 /* Internet Protocol */ +#define PPP_XNS 0x25 /* Xerox NS */ +#define PPP_VJC_COMP 0x2d /* VJ compressed TCP */ +#define PPP_VJC_UNCOMP 0x2f /* VJ uncompressed TCP */ +#define PPP_LCP 0xc021 /* Link 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]) + +#define PPP_MTU 296 /* Default MTU (size of Info field) */ +#define PPP_MRU 1500 /* Default MRU (max receive unit) */ +#define PPP_HIWAT 400 /* Don't start a new packet if HIWAT on que */ + +struct ppp_softc { + struct ifnet sc_if; /* network-visible interface */ + u_int sc_flags; /* see below */ + struct tty *sc_ttyp; /* pointer to tty structure */ + 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 */ + u_long sc_asyncmap; /* async control character map */ + struct ifqueue sc_inq; /* TTY side input queue */ +#ifdef VJC + struct slcompress sc_comp; /* vjc control buffer */ +#endif + u_int sc_bytessent; + u_int sc_bytesrcvd; +}; + +/* flags */ +#define SC_ESCAPED 0x00010000 /* saw a PPP_ESCAPE */ +#define SC_FLUSH 0x00020000 /* flush input until next PPP_FLAG */ +#define SC_COMP_PROT 0x00000001 /* protocol compression */ +#define SC_COMP_AC 0x00000002 /* header compression */ +#define SC_COMP_TCP 0x00000004 /* TCP traffic (VJ) compression */ + +#define t_sc T_LINEP + +/* 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 */ +#define PPPIOCSASYNCMAP _IOW('t', 87, int) /* set async map */ +#define PPPIOCGUNIT _IOR('t', 86, int) /* get ppp unit number */ + +/* old copies of PPP may have defined this */ +#if !defined(ifr_mtu) +#define ifr_mtu ifr_metric +#endif + diff --git a/sys/net/if_types.h b/sys/net/if_types.h index 70b81957cf..d3123d165a 100644 --- a/sys/net/if_types.h +++ b/sys/net/if_types.h @@ -62,3 +62,4 @@ #define IFT_XETHER 0x1a /* obsolete 3MB experimental ethernet */ #define IFT_NSIP 0x1b /* XNS over IP */ #define IFT_SLIP 0x1c /* IP over generic TTY */ +#define IFT_PPP 0x1d /* PPP over generic TTY */ diff --git a/sys/net/ppp.h b/sys/net/ppp.h new file mode 100644 index 0000000000..ed389e8773 --- /dev/null +++ b/sys/net/ppp.h @@ -0,0 +1,38 @@ +/* + * ppp.h - PPP global declarations. + * + * Copyright (c) 1989 Carnegie Mellon University. + * All rights reserved. + * + * Redistribution and use in source and binary forms are permitted + * provided that the above copyright notice and this paragraph are + * duplicated in all such forms and that any documentation, + * advertising materials, and other materials related to such + * distribution and use acknowledge that the software was developed + * by Carnegie Mellon University. The name of the + * University may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +#ifndef __PPP_H__ +#define __PPP_H__ + +#define NPPP 1 /* One PPP interface supported (per process) */ + +/* + * Data Link Layer header = Address, Control, Protocol. + */ +#define ALLSTATIONS 0xff /* All-Stations Address */ +#define UI 0x03 /* Unnumbered Information */ +#define LCP 0xc021 /* Link Control Protocol */ +#define IPCP 0x8021 /* IP Control Protocol */ +#define UPAP 0xc023 /* User/Password Authentication Protocol */ +#define CHAP 0xc223 /* Crytpographic Handshake Protocol */ +#define IP_VJ_COMP 0x002d /* VJ TCP compressed IP packet */ +#define DLLHEADERLEN (sizeof (u_char) + sizeof (u_char) + sizeof (u_short)) +#define MTU 1500 /* Default MTU */ + +#endif /* __PPP_H__ */ diff --git a/sys/net/slcompress.c b/sys/net/slcompress.c index 475affc4d4..2b8143384a 100644 --- a/sys/net/slcompress.c +++ b/sys/net/slcompress.c @@ -20,21 +20,24 @@ * Van Jacobson (van@ee.lbl.gov), Dec 31, 1989: * - Initial distribution. * - * PATCHES MAGIC LEVEL PATCH THAT GOT US HERE - * -------------------- ----- ---------------------- - * CURRENT PATCH LEVEL: 1 00112 - * -------------------- ----- ---------------------- + * Modified March 14, 1993 by David Greenman, upgraded to slcompress.c + * from tcpdump 2.2.1. * - * 14 Mar 93 David Greenman Upgrade bpf to match tcpdump 2.2.1 + * Modified June 1993 by Paul Mackerras, paulus@cs.anu.edu.au, + * so that the entire packet being decompressed doesn't have + * to be in contiguous memory (just the compressed header). + * + * $Id$ + * From: slcompress.c,v 1.22 92/05/24 11:48:20 van Exp $ (LBL) */ #ifndef lint static char rcsid[] = - "@(#) $Header: /a/cvs/386BSD/src/sys.386bsd/net/slcompress.c,v 1.1.1.1 1993/06/12 14:57:51 rgrimes Exp $ (LBL)"; + "$Id$"; #endif #include #include -#include "systm.h" +#include #include #include #include @@ -392,6 +395,23 @@ sl_uncompress_tcp(bufp, len, type, comp) int len; u_int type; struct slcompress *comp; +{ + return sl_uncompress_tcp_part(bufp, len, len, type, comp); +} + + +/* + * Uncompress a packet of total length total_len. The first buflen + * bytes are at *bufp; this must include the entire (compressed or + * uncompressed) TCP/IP header. In addition, there must be enough + * clear space before *bufp to build a full-length TCP/IP header. + */ +int +sl_uncompress_tcp_part(bufp, buflen, total_len, type, comp) + u_char **bufp; + int buflen, total_len; + u_int type; + struct slcompress *comp; { register u_char *cp; register u_int hlen, changes; @@ -415,7 +435,7 @@ sl_uncompress_tcp(bufp, len, type, comp) cs->cs_ip.ip_sum = 0; cs->cs_hlen = hlen; INCR(sls_uncompressedin) - return (len); + return (total_len); default: goto bad; @@ -496,20 +516,21 @@ sl_uncompress_tcp(bufp, len, type, comp) * prepend 128 bytes of header). Adjust the length to account for * the new header & fill in the IP total length. */ - len -= (cp - *bufp); - if (len < 0) + buflen -= (cp - *bufp); + total_len -= (cp - *bufp); + if (buflen < 0) /* we must have dropped some characters (crc should detect * this but the old slip framing won't) */ goto bad; if ((int)cp & 3) { - if (len > 0) - (void) ovbcopy(cp, (caddr_t)((int)cp &~ 3), len); + if (buflen > 0) + (void) ovbcopy(cp, (caddr_t)((int)cp &~ 3), buflen); cp = (u_char *)((int)cp &~ 3); } cp -= cs->cs_hlen; - len += cs->cs_hlen; - cs->cs_ip.ip_len = htons(len); + total_len += cs->cs_hlen; + cs->cs_ip.ip_len = htons(total_len); BCOPY(&cs->cs_ip, cp, cs->cs_hlen); *bufp = cp; @@ -522,7 +543,7 @@ sl_uncompress_tcp(bufp, len, type, comp) changes = (changes & 0xffff) + (changes >> 16); ((struct ip *)cp)->ip_sum = ~ changes; } - return (len); + return (total_len); bad: comp->flags |= SLF_TOSS; INCR(sls_errorin) diff --git a/sys/net/slcompress.h b/sys/net/slcompress.h index f799706fa1..4554d12eb9 100644 --- a/sys/net/slcompress.h +++ b/sys/net/slcompress.h @@ -2,7 +2,9 @@ /* * Definitions for tcp compression routines. * - * $Header: slcompress.h,v 1.10 89/12/31 08:53:02 van Exp $ + * $Id$ + * From: slcompress.h,v 1.13 1993/08/09 02:37:32 paulus Exp + * From: slcompress.h,v 1.10 89/12/31 08:53:02 van Exp * * Copyright (c) 1989 Regents of the University of California. * All rights reserved. @@ -37,6 +39,9 @@ * * Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989: * - Initial distribution. + * + * Paul Mackerras (paulus@cs.anu.edu.au), June 1993: + * - added sl_uncompress_tcp_part. */ #define MAX_STATES 16 /* must be > 2 and < 256 */ @@ -151,7 +156,11 @@ struct slcompress { /* flag values */ #define SLF_TOSS 1 /* tossing rcvd frames because of input err */ -extern void sl_compress_init(/* struct slcompress * */); -extern u_char sl_compress_tcp(/* struct mbuf *, struct ip *, - struct slcompress *, int compress_cid_flag */); -extern int sl_uncompress_tcp(/* u_char **, int, u_char, struct slcompress * */); +extern void sl_compress_init __P((struct slcompress *)); +extern u_char sl_compress_tcp __P((struct mbuf *m, struct ip *ip, + struct slcompress *, int comp_cid_flag)); +extern int sl_uncompress_tcp __P((u_char **bufp, int len, u_int type, + struct slcompress *)); +extern int sl_uncompress_tcp_part __P((u_char **bufp, int buflen, + int total_len, u_int type, + struct slcompress *)); diff --git a/sys/sys/ioctl.h b/sys/sys/ioctl.h index 633a274b7f..2b1ce1c46b 100644 --- a/sys/sys/ioctl.h +++ b/sys/sys/ioctl.h @@ -160,6 +160,7 @@ struct ttysize { #define TTYDISC 0 /* termios tty line discipline */ #define TABLDISC 3 /* tablet discipline */ #define SLIPDISC 4 /* serial IP discipline */ +#define PPPDISC 5 /* PPP discipline */ #define FIOCLEX _IO('f', 1) /* set close on exec on fd */ @@ -208,6 +209,11 @@ struct ttysize { #define SIOCGARP _IOWR('i',38, struct arpreq) /* get arp entry */ #define SIOCDARP _IOW('i', 32, struct arpreq) /* delete arp entry */ +#define SIOCSIFMTU _IOW('i', 127, struct ifreq) /* set ifnet mtu */ +#define SIOCGIFMTU _IOWR('i',126, struct ifreq) /* get ifnet mtu */ +#define SIOCSIFASYNCMAP _IOW('i', 125, struct ifreq) /* set ppp asyncmap */ +#define SIOCGIFASYNCMAP _IOWR('i',124, struct ifreq) /* get ppp asyncmap */ + #ifndef KERNEL #include