]> git.ozlabs.org Git - ppp.git/blob - freebsd-2.0/if_ppp.c
Some mods from Bruce Evans
[ppp.git] / freebsd-2.0 / if_ppp.c
1 /*
2  * if_ppp.c - Point-to-Point Protocol (PPP) Asynchronous driver.
3  *
4  * Copyright (c) 1989 Carnegie Mellon University.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms are permitted
8  * provided that the above copyright notice and this paragraph are
9  * duplicated in all such forms and that any documentation,
10  * advertising materials, and other materials related to such
11  * distribution and use acknowledge that the software was developed
12  * by Carnegie Mellon University.  The name of the
13  * University may not be used to endorse or promote products derived
14  * from this software without specific prior written permission.
15  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18  *
19  * Drew D. Perkins
20  * Carnegie Mellon University
21  * 4910 Forbes Ave.
22  * Pittsburgh, PA 15213
23  * (412) 268-8576
24  * ddp@andrew.cmu.edu
25  *
26  * Based on:
27  *      @(#)if_sl.c     7.6.1.2 (Berkeley) 2/15/89
28  *
29  * Copyright (c) 1987 Regents of the University of California.
30  * All rights reserved.
31  *
32  * Redistribution and use in source and binary forms are permitted
33  * provided that the above copyright notice and this paragraph are
34  * duplicated in all such forms and that any documentation,
35  * advertising materials, and other materials related to such
36  * distribution and use acknowledge that the software was developed
37  * by the University of California, Berkeley.  The name of the
38  * University may not be used to endorse or promote products derived
39  * from this software without specific prior written permission.
40  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
41  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
42  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
43  *
44  * Serial Line interface
45  *
46  * Rick Adams
47  * Center for Seismic Studies
48  * 1300 N 17th Street, Suite 1450
49  * Arlington, Virginia 22209
50  * (703)276-7900
51  * rick@seismo.ARPA
52  * seismo!rick
53  *
54  * Pounded on heavily by Chris Torek (chris@mimsy.umd.edu, umcp-cs!chris).
55  * Converted to 4.3BSD Beta by Chris Torek.
56  * Other changes made at Berkeley, based in part on code by Kirk Smith.
57  *
58  * Converted to 4.3BSD+ 386BSD by Brad Parker (brad@cayman.com)
59  * Added VJ tcp header compression; more unified ioctls
60  *
61  * Extensively modified by Paul Mackerras (paulus@cs.anu.edu.au).
62  * Cleaned up a lot of the mbuf-related code to fix bugs that
63  * caused system crashes and packet corruption.  Changed pppstart
64  * so that it doesn't just give up with a collision if the whole
65  * packet doesn't fit in the output ring buffer.
66  *
67  * Added priority queueing for interactive IP packets, following
68  * the model of if_sl.c, plus hooks for bpf.
69  * Paul Mackerras (paulus@cs.anu.edu.au).
70  */
71
72 /* $Id: if_ppp.c,v 1.5 1995/08/16 01:36:38 paulus Exp $ */
73 /* from if_sl.c,v 1.11 84/10/04 12:54:47 rick Exp */
74
75 #include "ppp.h"
76 #if NPPP > 0
77
78 #define VJC
79 #define PPP_COMPRESS
80
81 #include <sys/param.h>
82 #include <sys/systm.h>
83 #include <sys/proc.h>
84 #include <sys/mbuf.h>
85 #include <sys/socket.h>
86 #include <sys/ioctl.h>
87 #include <sys/kernel.h>
88
89 #include <net/if.h>
90 #include <net/if_types.h>
91 #include <net/netisr.h>
92 #include <net/route.h>
93
94 #if INET
95 #include <netinet/in.h>
96 #include <netinet/in_systm.h>
97 #include <netinet/in_var.h>
98 #include <netinet/ip.h>
99 #endif
100
101 #include "bpfilter.h"
102 #if NBPFILTER > 0
103 #include <sys/time.h>
104 #include <net/bpf.h>
105 #endif
106
107 #ifdef VJC
108 #include <net/pppcompress.h>
109 #endif
110
111 #include <net/ppp_defs.h>
112 #include <net/if_ppp.h>
113 #include <net/if_pppvar.h>
114 #include <machine/cpu.h>
115
116 #ifndef NETISR_PPP
117 /* This definition should be moved to net/netisr.h */
118 #define NETISR_PPP      26      /* PPP software interrupt */
119 #endif
120
121 #ifdef PPP_COMPRESS
122 #define PACKETPTR       struct mbuf *
123 #include <net/ppp-comp.h>
124 #endif
125
126 void    pppattach __P((void));
127 int     pppioctl __P((struct ppp_softc *sc, int cmd, caddr_t data, int flag,
128                       struct proc *));
129 int     pppoutput __P((struct ifnet *ifp, struct mbuf *m0,
130                        struct sockaddr *dst, struct rtentry *rtp));
131 int     pppsioctl __P((struct ifnet *ifp, int cmd, caddr_t data));
132 void    pppintr __P((void));
133
134 static void     ppp_requeue __P((struct ppp_softc *));
135 static void     ppp_outpkt __P((struct ppp_softc *));
136 static int      ppp_ccp __P((struct ppp_softc *, struct mbuf *m, int rcvd));
137 static void     ppp_ccp_closed __P((struct ppp_softc *));
138 static void     ppp_inproc __P((struct ppp_softc *, struct mbuf *));
139 static void     pppdumpm __P((struct mbuf *m0));
140
141 /*
142  * Some useful mbuf macros not in mbuf.h.
143  */
144 #define M_IS_CLUSTER(m) ((m)->m_flags & M_EXT)
145
146 #define M_DATASTART(m)  \
147         (M_IS_CLUSTER(m) ? (m)->m_ext.ext_buf : \
148             (m)->m_flags & M_PKTHDR ? (m)->m_pktdat : (m)->m_dat)
149
150 #define M_DATASIZE(m)   \
151         (M_IS_CLUSTER(m) ? (m)->m_ext.ext_size : \
152             (m)->m_flags & M_PKTHDR ? MHLEN: MLEN)
153
154 /*
155  * We steal two bits in the mbuf m_flags, to mark high-priority packets
156  * for output, and received packets following lost/corrupted packets.
157  */
158 #define M_HIGHPRI       0x2000  /* output packet for sc_fastq */
159 #define M_ERRMARK       0x4000  /* steal a bit in mbuf m_flags */
160
161
162 #ifdef PPP_COMPRESS
163 /*
164  * List of compressors we know about.
165  * We leave some space so maybe we can modload compressors.
166  */
167
168 extern struct compressor ppp_bsd_compress;
169
170 struct compressor *ppp_compressors[8] = {
171 #if DO_BSD_COMPRESS
172     &ppp_bsd_compress,
173 #endif
174     NULL
175 };
176 #endif /* PPP_COMPRESS */
177
178 TEXT_SET(pseudo_set, pppattach);
179
180 /*
181  * Called from boot code to establish ppp interfaces.
182  */
183 void
184 pppattach()
185 {
186     register struct ppp_softc *sc;
187     register int i = 0;
188     extern void (*netisrs[])__P((void));
189
190     for (sc = ppp_softc; i < NPPP; sc++) {
191         sc->sc_if.if_name = "ppp";
192         sc->sc_if.if_unit = i++;
193         sc->sc_if.if_mtu = PPP_MTU;
194         sc->sc_if.if_flags = IFF_POINTOPOINT | IFF_MULTICAST;
195         sc->sc_if.if_type = IFT_PPP;
196         sc->sc_if.if_hdrlen = PPP_HDRLEN;
197         sc->sc_if.if_ioctl = pppsioctl;
198         sc->sc_if.if_output = pppoutput;
199         sc->sc_if.if_snd.ifq_maxlen = IFQ_MAXLEN;
200         sc->sc_inq.ifq_maxlen = IFQ_MAXLEN;
201         sc->sc_fastq.ifq_maxlen = IFQ_MAXLEN;
202         sc->sc_rawq.ifq_maxlen = IFQ_MAXLEN;
203         if_attach(&sc->sc_if);
204 #if NBPFILTER > 0
205         bpfattach(&sc->sc_bpf, &sc->sc_if, DLT_PPP, PPP_HDRLEN);
206 #endif
207     }
208     netisrs[NETISR_PPP] = ppp_intr;
209 }
210
211 /*
212  * Allocate a ppp interface unit and initialize it.
213  */
214 struct ppp_softc *
215 pppalloc(pid)
216     pid_t pid;
217 {
218     int nppp, i;
219     struct ppp_softc *sc;
220
221     for (nppp = 0, sc = ppp_softc; nppp < NPPP; nppp++, sc++)
222         if (sc->sc_xfer == pid) {
223             sc->sc_xfer = 0;
224             return sc;
225         }
226     for (nppp = 0, sc = ppp_softc; nppp < NPPP; nppp++, sc++)
227         if (sc->sc_devp == NULL)
228             break;
229     if (nppp >= NPPP)
230         return NULL;
231
232     sc->sc_flags = 0;
233     sc->sc_mru = PPP_MRU;
234     sc->sc_relinq = NULL;
235 #ifdef VJC
236     vj_compress_init(&sc->sc_comp, -1);
237 #endif
238 #ifdef PPP_COMPRESS
239     sc->sc_xc_state = NULL;
240     sc->sc_rc_state = NULL;
241 #endif /* PPP_COMPRESS */
242     for (i = 0; i < NUM_NP; ++i)
243         sc->sc_npmode[i] = NPMODE_ERROR;
244     sc->sc_npqueue = NULL;
245     sc->sc_npqtail = &sc->sc_npqueue;
246     sc->sc_last_sent = sc->sc_last_recv = time.tv_sec;
247
248     return sc;
249 }
250
251 /*
252  * Deallocate a ppp unit.  Must be called at splnet or higher.
253  */
254 void
255 pppdealloc(sc)
256     struct ppp_softc *sc;
257 {
258     struct mbuf *m;
259
260     if_down(&sc->sc_if);
261     sc->sc_if.if_flags &= ~(IFF_UP|IFF_RUNNING);
262     sc->sc_devp = NULL;
263     sc->sc_xfer = 0;
264     for (;;) {
265         IF_DEQUEUE(&sc->sc_rawq, m);
266         if (m == NULL)
267             break;
268         m_freem(m);
269     }
270     for (;;) {
271         IF_DEQUEUE(&sc->sc_inq, m);
272         if (m == NULL)
273             break;
274         m_freem(m);
275     }
276     for (;;) {
277         IF_DEQUEUE(&sc->sc_fastq, m);
278         if (m == NULL)
279             break;
280         m_freem(m);
281     }
282     while ((m = sc->sc_npqueue) != NULL) {
283         sc->sc_npqueue = m->m_nextpkt;
284         m_freem(m);
285     }
286     if (sc->sc_togo != NULL) {
287         m_freem(sc->sc_togo);
288         sc->sc_togo = NULL;
289     }
290 #ifdef PPP_COMPRESS
291     ppp_ccp_closed(sc);
292     sc->sc_xc_state = NULL;
293     sc->sc_rc_state = NULL;
294 #endif /* PPP_COMPRESS */
295 }
296
297 /*
298  * Ioctl routine for generic ppp devices.
299  */
300 int
301 pppioctl(sc, cmd, data, flag, p)
302     struct ppp_softc *sc;
303     caddr_t data;
304     int cmd, flag;
305     struct proc *p;
306 {
307     int s, error, flags, mru, nb, npx;
308     struct ppp_option_data *odp;
309     struct compressor **cp;
310     struct npioctl *npi;
311     time_t t;
312 #ifdef  PPP_COMPRESS
313     u_char ccp_option[CCP_MAX_OPTION_LENGTH];
314 #endif
315
316     switch (cmd) {
317     case FIONREAD:
318         *(int *)data = sc->sc_inq.ifq_len;
319         break;
320
321     case PPPIOCGUNIT:
322         *(int *)data = sc->sc_if.if_unit;
323         break;
324
325     case PPPIOCGFLAGS:
326         *(u_int *)data = sc->sc_flags;
327         break;
328
329     case PPPIOCSFLAGS:
330         if (error = suser(p->p_ucred, &p->p_acflag))
331             return (error);
332         flags = *(int *)data & SC_MASK;
333         s = splnet();
334 #ifdef PPP_COMPRESS
335         if (sc->sc_flags & SC_CCP_OPEN && !(flags & SC_CCP_OPEN))
336             ppp_ccp_closed(sc);
337 #endif
338         splimp();
339         sc->sc_flags = (sc->sc_flags & ~SC_MASK) | flags;
340         splx(s);
341         break;
342
343     case PPPIOCSMRU:
344         if (error = suser(p->p_ucred, &p->p_acflag))
345             return (error);
346         mru = *(int *)data;
347         if (mru >= PPP_MRU && mru <= PPP_MAXMRU)
348             sc->sc_mru = mru;
349         break;
350
351     case PPPIOCGMRU:
352         *(int *)data = sc->sc_mru;
353         break;
354
355 #ifdef VJC
356     case PPPIOCSMAXCID:
357         if (error = suser(p->p_ucred, &p->p_acflag))
358             return (error);
359         s = splnet();
360         vj_compress_init(&sc->sc_comp, *(int *)data);
361         splx(s);
362         break;
363 #endif
364
365     case PPPIOCXFERUNIT:
366         if (error = suser(p->p_ucred, &p->p_acflag))
367             return (error);
368         sc->sc_xfer = p->p_pid;
369         break;
370
371 #ifdef PPP_COMPRESS
372     case PPPIOCSCOMPRESS:
373         if (error = suser(p->p_ucred, &p->p_acflag))
374             return (error);
375         odp = (struct ppp_option_data *) data;
376         nb = odp->length;
377         if (nb > sizeof(ccp_option))
378             nb = sizeof(ccp_option);
379         if (error = copyin(odp->ptr, ccp_option, nb))
380             return (error);
381         if (ccp_option[1] < 2)  /* preliminary check on the length byte */
382             return (EINVAL);
383         for (cp = ppp_compressors; *cp != NULL; ++cp)
384             if ((*cp)->compress_proto == ccp_option[0]) {
385                 /*
386                  * Found a handler for the protocol - try to allocate
387                  * a compressor or decompressor.
388                  */
389                 error = 0;
390                 s = splnet();
391                 if (odp->transmit) {
392                     if (sc->sc_xc_state != NULL)
393                         (*sc->sc_xcomp->comp_free)(sc->sc_xc_state);
394                     sc->sc_xcomp = *cp;
395                     sc->sc_xc_state = (*cp)->comp_alloc(ccp_option, nb);
396                     if (sc->sc_xc_state == NULL) {
397                         if (sc->sc_flags & SC_DEBUG)
398                             printf("ppp%d: comp_alloc failed\n",
399                                sc->sc_if.if_unit);
400                         error = ENOBUFS;
401                     }
402                     splimp();
403                     sc->sc_flags &= ~SC_COMP_RUN;
404                 } else {
405                     if (sc->sc_rc_state != NULL)
406                         (*sc->sc_rcomp->decomp_free)(sc->sc_rc_state);
407                     sc->sc_rcomp = *cp;
408                     sc->sc_rc_state = (*cp)->decomp_alloc(ccp_option, nb);
409                     if (sc->sc_rc_state == NULL) {
410                         if (sc->sc_flags & SC_DEBUG)
411                             printf("ppp%d: decomp_alloc failed\n",
412                                sc->sc_if.if_unit);
413                         error = ENOBUFS;
414                     }
415                     splimp();
416                     sc->sc_flags &= ~SC_DECOMP_RUN;
417                 }
418                 splx(s);
419                 return (error);
420             }
421         if (sc->sc_flags & SC_DEBUG)
422             printf("ppp%d: no compressor for [%x %x %x], %x\n",
423                    sc->sc_if.if_unit, ccp_option[0], ccp_option[1],
424                    ccp_option[2], nb);
425         return (EINVAL);        /* no handler found */
426 #endif /* PPP_COMPRESS */
427
428     case PPPIOCGNPMODE:
429     case PPPIOCSNPMODE:
430         npi = (struct npioctl *) data;
431         switch (npi->protocol) {
432         case PPP_IP:
433             npx = NP_IP;
434             break;
435         default:
436             return EINVAL;
437         }
438         if (cmd == PPPIOCGNPMODE) {
439             npi->mode = sc->sc_npmode[npx];
440         } else {
441             if (error = suser(p->p_ucred, &p->p_acflag))
442                 return (error);
443             if (npi->mode != sc->sc_npmode[npx]) {
444                 s = splimp();
445                 sc->sc_npmode[npx] = npi->mode;
446                 if (npi->mode != NPMODE_QUEUE) {
447                     ppp_requeue(sc);
448                     (*sc->sc_start)(sc);
449                 }
450                 splx(s);
451             }
452         }
453         break;
454
455     case PPPIOCGIDLE:
456         s = splimp();
457         t = time.tv_sec;
458         ((struct ppp_idle *)data)->xmit_idle = t - sc->sc_last_sent;
459         ((struct ppp_idle *)data)->recv_idle = t - sc->sc_last_recv;
460         splx(s);
461         break;
462
463     default:
464         return (-1);
465     }
466     return (0);
467 }
468
469 /*
470  * Process an ioctl request to the ppp network interface.
471  */
472 int
473 pppsioctl(ifp, cmd, data)
474     register struct ifnet *ifp;
475     int cmd;
476     caddr_t data;
477 {
478     struct proc *p = curproc;   /* XXX */
479     register struct ppp_softc *sc = &ppp_softc[ifp->if_unit];
480     register struct ifaddr *ifa = (struct ifaddr *)data;
481     register struct ifreq *ifr = (struct ifreq *)data;
482     struct ppp_stats *psp;
483 #ifdef  PPP_COMPRESS
484     struct ppp_comp_stats *pcp;
485 #endif
486     int s = splimp(), error = 0;
487
488     switch (cmd) {
489     case SIOCSIFFLAGS:
490         if ((ifp->if_flags & IFF_RUNNING) == 0)
491             ifp->if_flags &= ~IFF_UP;
492         break;
493
494     case SIOCSIFADDR:
495         if (ifa->ifa_addr->sa_family != AF_INET)
496             error = EAFNOSUPPORT;
497         break;
498
499     case SIOCSIFDSTADDR:
500         if (ifa->ifa_addr->sa_family != AF_INET)
501             error = EAFNOSUPPORT;
502         break;
503
504     case SIOCSIFMTU:
505         if (error = suser(p->p_ucred, &p->p_acflag))
506             break;
507         sc->sc_if.if_mtu = ifr->ifr_mtu;
508         break;
509
510     case SIOCGIFMTU:
511         ifr->ifr_mtu = sc->sc_if.if_mtu;
512         break;
513
514     case SIOCADDMULTI:
515     case SIOCDELMULTI:
516         switch(ifr->ifr_addr.sa_family) {
517 #ifdef INET
518         case AF_INET:
519             break;
520 #endif
521         default:
522             error = EAFNOSUPPORT;
523             break;
524         }
525         break;
526
527     case SIOCGPPPSTATS:
528         psp = &((struct ifpppstatsreq *) data)->stats;
529         bzero(psp, sizeof(*psp));
530         psp->p.ppp_ibytes = sc->sc_bytesrcvd;
531         psp->p.ppp_ipackets = ifp->if_ipackets;
532         psp->p.ppp_ierrors = ifp->if_ierrors;
533         psp->p.ppp_obytes = sc->sc_bytessent;
534         psp->p.ppp_opackets = ifp->if_opackets;
535         psp->p.ppp_oerrors = ifp->if_oerrors;
536 #ifdef VJC
537         psp->vj.vjs_packets = sc->sc_comp.sls_packets;
538         psp->vj.vjs_compressed = sc->sc_comp.sls_compressed;
539         psp->vj.vjs_searches = sc->sc_comp.sls_searches;
540         psp->vj.vjs_misses = sc->sc_comp.sls_misses;
541         psp->vj.vjs_uncompressedin = sc->sc_comp.sls_uncompressedin;
542         psp->vj.vjs_compressedin = sc->sc_comp.sls_compressedin;
543         psp->vj.vjs_errorin = sc->sc_comp.sls_errorin;
544         psp->vj.vjs_tossed = sc->sc_comp.sls_tossed;
545 #endif /* VJC */
546         break;
547
548 #ifdef PPP_COMPRESS
549     case SIOCGPPPCSTATS:
550         pcp = &((struct ifpppcstatsreq *) data)->stats;
551         bzero(pcp, sizeof(*pcp));
552         if (sc->sc_xc_state != NULL)
553             (*sc->sc_xcomp->comp_stat)(sc->sc_xc_state, &pcp->c);
554         if (sc->sc_rc_state != NULL)
555             (*sc->sc_rcomp->decomp_stat)(sc->sc_rc_state, &pcp->d);
556         break;
557 #endif /* PPP_COMPRESS */
558
559     default:
560         error = EINVAL;
561     }
562     splx(s);
563     return (error);
564 }
565
566 /*
567  * Queue a packet.  Start transmission if not active.
568  * Packet is placed in Information field of PPP frame.
569  */
570 int
571 pppoutput(ifp, m0, dst, rtp)
572     struct ifnet *ifp;
573     struct mbuf *m0;
574     struct sockaddr *dst;
575     struct rtentry *rtp;
576 {
577     register struct ppp_softc *sc = &ppp_softc[ifp->if_unit];
578     struct ppp_header *ph;
579     int protocol, address, control;
580     u_char *cp;
581     int s, error;
582     struct ip *ip;
583     struct ifqueue *ifq;
584     enum NPmode mode;
585
586     if (sc->sc_devp == NULL || (ifp->if_flags & IFF_RUNNING) == 0
587         || (ifp->if_flags & IFF_UP) == 0 && dst->sa_family != AF_UNSPEC) {
588         error = ENETDOWN;       /* sort of */
589         goto bad;
590     }
591
592     /*
593      * Compute PPP header.
594      */
595     m0->m_flags &= ~M_HIGHPRI;
596     switch (dst->sa_family) {
597 #ifdef INET
598     case AF_INET:
599         address = PPP_ALLSTATIONS;
600         control = PPP_UI;
601         protocol = PPP_IP;
602         mode = sc->sc_npmode[NP_IP];
603
604         /*
605          * If this packet has the "low delay" bit set in the IP header,
606          * put it on the fastq instead.
607          */
608         ip = mtod(m0, struct ip *);
609         if (ip->ip_tos & IPTOS_LOWDELAY)
610             m0->m_flags |= M_HIGHPRI;
611         break;
612 #endif
613     case AF_UNSPEC:
614         address = PPP_ADDRESS(dst->sa_data);
615         control = PPP_CONTROL(dst->sa_data);
616         protocol = PPP_PROTOCOL(dst->sa_data);
617         mode = NPMODE_PASS;
618         break;
619     default:
620         printf("ppp%d: af%d not supported\n", ifp->if_unit, dst->sa_family);
621         error = EAFNOSUPPORT;
622         goto bad;
623     }
624
625     /*
626      * Drop this packet, or return an error, if necessary.
627      */
628     if (mode == NPMODE_ERROR) {
629         error = ENETDOWN;
630         goto bad;
631     }
632     if (mode == NPMODE_DROP) {
633         error = 0;
634         goto bad;
635     }
636
637     /*
638      * Add PPP header.  If no space in first mbuf, allocate another.
639      * (This assumes M_LEADINGSPACE is always 0 for a cluster mbuf.)
640      */
641     if (M_LEADINGSPACE(m0) < PPP_HDRLEN) {
642         m0 = m_prepend(m0, PPP_HDRLEN, M_DONTWAIT);
643         if (m0 == 0) {
644             error = ENOBUFS;
645             goto bad;
646         }
647         m0->m_len = 0;
648     } else
649         m0->m_data -= PPP_HDRLEN;
650
651     cp = mtod(m0, u_char *);
652     *cp++ = address;
653     *cp++ = control;
654     *cp++ = protocol >> 8;
655     *cp++ = protocol & 0xff;
656     m0->m_len += PPP_HDRLEN;
657
658     if (sc->sc_flags & SC_LOG_OUTPKT) {
659         printf("ppp%d output: ", ifp->if_unit);
660         pppdumpm(m0);
661     }
662
663 #if NBPFILTER > 0
664     /*
665      * See if bpf wants to look at the packet.
666      */
667     if (sc->sc_bpf)
668         bpf_mtap(sc->sc_bpf, m0);
669 #endif
670
671     /*
672      * Put the packet on the appropriate queue.
673      */
674     s = splimp();               /* splnet should be OK now */
675     if (mode == NPMODE_QUEUE) {
676         /* XXX we should limit the number of packets on this queue */
677         *sc->sc_npqtail = m0;
678         m0->m_nextpkt = NULL;
679         sc->sc_npqtail = &m0->m_nextpkt;
680     } else {
681         ifq = (m0->m_flags & M_HIGHPRI)? &sc->sc_fastq: &ifp->if_snd;
682         if (IF_QFULL(ifq)) {
683             IF_DROP(ifq);
684             splx(s);
685             sc->sc_if.if_oerrors++;
686             error = ENOBUFS;
687             goto bad;
688         }
689         IF_ENQUEUE(ifq, m0);
690         (*sc->sc_start)(sc);
691     }
692
693     splx(s);
694     return (0);
695
696 bad:
697     m_freem(m0);
698     return (error);
699 }
700
701 /*
702  * After a change in the NPmode for some NP, move packets from the
703  * npqueue to the send queue or the fast queue as appropriate.
704  * Should be called at splimp (actually splnet would probably suffice).
705  */
706 static void
707 ppp_requeue(sc)
708     struct ppp_softc *sc;
709 {
710     struct mbuf *m, **mpp;
711     struct ifqueue *ifq;
712     enum NPmode mode;
713
714     for (mpp = &sc->sc_npqueue; (m = *mpp) != NULL; ) {
715         switch (PPP_PROTOCOL(mtod(m, u_char *))) {
716         case PPP_IP:
717             mode = sc->sc_npmode[NP_IP];
718             break;
719         default:
720             mode = NPMODE_PASS;
721         }
722
723         switch (mode) {
724         case NPMODE_PASS:
725             /*
726              * This packet can now go on one of the queues to be sent.
727              */
728             *mpp = m->m_nextpkt;
729             m->m_nextpkt = NULL;
730             ifq = (m->m_flags & M_HIGHPRI)? &sc->sc_fastq: &sc->sc_if.if_snd;
731             if (IF_QFULL(ifq)) {
732                 IF_DROP(ifq);
733                 sc->sc_if.if_oerrors++;
734             } else
735                 IF_ENQUEUE(ifq, m);
736             break;
737
738         case NPMODE_DROP:
739         case NPMODE_ERROR:
740             *mpp = m->m_nextpkt;
741             m_freem(m);
742             break;
743
744         case NPMODE_QUEUE:
745             mpp = &m->m_nextpkt;
746             break;
747         }
748     }
749     sc->sc_npqtail = mpp;
750 }
751
752 /*
753  * Get a packet to send.  This procedure is intended to be called
754  * at spltty()/splimp(), so it takes little time.  If there isn't
755  * a packet waiting to go out, it schedules a software interrupt
756  * to prepare a new packet; the device start routine gets called
757  * again when a packet is ready.
758  */
759 struct mbuf *
760 ppp_dequeue(sc)
761     struct ppp_softc *sc;
762 {
763     struct mbuf *m;
764     int s = splimp();
765
766     m = sc->sc_togo;
767     if (m) {
768         /*
769          * Had a packet waiting - send it.
770          */
771         sc->sc_togo = NULL;
772         sc->sc_flags |= SC_TBUSY;
773         splx(s);
774         return m;
775     }
776     /*
777      * Remember we wanted a packet and schedule a software interrupt.
778      */
779     sc->sc_flags &= ~SC_TBUSY;
780     schednetisr(NETISR_PPP);
781     splx(s);
782     return NULL;
783 }
784
785 /*
786  * Software interrupt routine, called at splnet().
787  */
788 void
789 pppintr()
790 {
791     struct ppp_softc *sc;
792     int i, s;
793     struct mbuf *m;
794
795     s = splnet();
796     sc = ppp_softc;
797     for (i = 0; i < NPPP; ++i, ++sc) {
798         if (!(sc->sc_flags & SC_TBUSY) && sc->sc_togo == NULL
799             && (sc->sc_if.if_snd.ifq_head || sc->sc_fastq.ifq_head))
800             ppp_outpkt(sc);
801         for (;;) {
802             IF_DEQUEUE(&sc->sc_rawq, m);
803             if (m == NULL)
804                 break;
805             ppp_inproc(sc, m);
806         }
807     }
808     splx(s);
809 }
810
811 /*
812  * Grab another packet off a queue and apply VJ compression,
813  * packet compression, address/control and/or protocol compression
814  * if enabled.  Should be called at splnet.
815  */
816 static void
817 ppp_outpkt(sc)
818     struct ppp_softc *sc;
819 {
820     int s;
821     struct mbuf *m, *mp;
822     u_char *cp;
823     int address, control, protocol;
824     enum NPmode mode;
825
826     /*
827      * Grab a packet to send: first try the fast queue, then the
828      * normal queue.
829      */
830     IF_DEQUEUE(&sc->sc_fastq, m);
831     if (m == NULL)
832         IF_DEQUEUE(&sc->sc_if.if_snd, m);
833     if (m == NULL)
834         return;
835
836     /*
837      * Extract the ppp header of the new packet.
838      * The ppp header will be in one mbuf.
839      */
840     cp = mtod(m, u_char *);
841     address = PPP_ADDRESS(cp);
842     control = PPP_CONTROL(cp);
843     protocol = PPP_PROTOCOL(cp);
844
845     switch (protocol) {
846     case PPP_IP:
847         /*
848          * Update the time we sent the most recent packet.
849          */
850         sc->sc_last_sent = time.tv_sec;
851
852 #ifdef VJC
853         /*
854          * If the packet is a TCP/IP packet, see if we can compress it.
855          */
856         if (sc->sc_flags & SC_COMP_TCP) {
857             struct ip *ip;
858             int type;
859
860             mp = m;
861             ip = (struct ip *) (cp + PPP_HDRLEN);
862             if (mp->m_len <= PPP_HDRLEN) {
863                 mp = mp->m_next;
864                 if (mp == NULL)
865                     break;
866                 ip = mtod(mp, struct ip *);
867             }
868             /* this code assumes the IP/TCP header is in one non-shared mbuf */
869             if (ip->ip_p == IPPROTO_TCP) {
870                 type = vj_compress_tcp(mp, ip, &sc->sc_comp,
871                                        !(sc->sc_flags & SC_NO_TCP_CCID));
872                 switch (type) {
873                 case TYPE_UNCOMPRESSED_TCP:
874                     protocol = PPP_VJC_UNCOMP;
875                     break;
876                 case TYPE_COMPRESSED_TCP:
877                     protocol = PPP_VJC_COMP;
878                     cp = mtod(m, u_char *);
879                     cp[0] = address;    /* header has moved */
880                     cp[1] = control;
881                     cp[2] = 0;
882                     break;
883                 }
884                 cp[3] = protocol;       /* update protocol in PPP header */
885             }
886         }
887 #endif  /* VJC */
888         break;
889
890 #ifdef PPP_COMPRESS
891     case PPP_CCP:
892         ppp_ccp(sc, m, 0);
893         break;
894 #endif  /* PPP_COMPRESS */
895     }
896
897 #ifdef PPP_COMPRESS
898     if (protocol != PPP_LCP && protocol != PPP_CCP
899         && sc->sc_xc_state && (sc->sc_flags & SC_COMP_RUN)) {
900         struct mbuf *mcomp = NULL;
901         int slen, clen;
902
903         slen = 0;
904         for (mp = m; mp != NULL; mp = mp->m_next)
905             slen += mp->m_len;
906         clen = (*sc->sc_xcomp->compress)
907             (sc->sc_xc_state, &mcomp, m, slen,
908              (sc->sc_flags & SC_CCP_UP? sc->sc_if.if_mtu: 0));
909         if (mcomp != NULL) {
910             m_freem(m);
911             m = mcomp;
912             cp = mtod(m, u_char *);
913             protocol = cp[3];
914         }
915     }
916 #endif  /* PPP_COMPRESS */
917
918     /*
919      * Compress the address/control and protocol, if possible.
920      */
921     if (sc->sc_flags & SC_COMP_AC && address == PPP_ALLSTATIONS &&
922         control == PPP_UI && protocol != PPP_ALLSTATIONS &&
923         protocol != PPP_LCP) {
924         /* can compress address/control */
925         m->m_data += 2;
926         m->m_len -= 2;
927     }
928     if (sc->sc_flags & SC_COMP_PROT && protocol < 0xFF) {
929         /* can compress protocol */
930         if (mtod(m, u_char *) == cp) {
931             cp[2] = cp[1];      /* move address/control up */
932             cp[1] = cp[0];
933         }
934         ++m->m_data;
935         --m->m_len;
936     }
937
938     s = splimp();
939     sc->sc_togo = m;
940     (*sc->sc_start)(sc);
941     splx(s);
942 }
943
944 #ifdef PPP_COMPRESS
945 /*
946  * Handle a CCP packet.  `rcvd' is 1 if the packet was received,
947  * 0 if it is about to be transmitted.
948  */
949 static int
950 ppp_ccp(sc, m, rcvd)
951     struct ppp_softc *sc;
952     struct mbuf *m;
953     int rcvd;
954 {
955     u_char *dp, *ep;
956     struct mbuf *mp;
957     int slen, s;
958
959     /*
960      * Get a pointer to the data after the PPP header.
961      */
962     if (m->m_len <= PPP_HDRLEN) {
963         mp = m->m_next;
964         if (mp == NULL)
965             return;
966         dp = (mp != NULL)? mtod(mp, u_char *): NULL;
967     } else {
968         mp = m;
969         dp = mtod(mp, u_char *) + PPP_HDRLEN;
970     }
971
972     ep = mtod(mp, u_char *) + mp->m_len;
973     if (dp + CCP_HDRLEN > ep)
974         return;
975     slen = CCP_LENGTH(dp);
976     if (dp + slen > ep) {
977         if (sc->sc_flags & SC_DEBUG)
978             printf("if_ppp/ccp: not enough data in mbuf (%x+%x > %x+%x)\n",
979                    dp, slen, mtod(mp, u_char *), mp->m_len);
980         return;
981     }
982
983     switch (CCP_CODE(dp)) {
984     case CCP_CONFREQ:
985     case CCP_TERMREQ:
986     case CCP_TERMACK:
987         /* CCP must be going down - disable compression */
988         if (sc->sc_flags & SC_CCP_UP) {
989             s = splimp();
990             sc->sc_flags &= ~(SC_CCP_UP | SC_COMP_RUN | SC_DECOMP_RUN);
991             splx(s);
992         }
993         break;
994
995     case CCP_CONFACK:
996         if (sc->sc_flags & SC_CCP_OPEN && !(sc->sc_flags & SC_CCP_UP)
997             && slen >= CCP_HDRLEN + CCP_OPT_MINLEN
998             && slen >= CCP_OPT_LENGTH(dp + CCP_HDRLEN) + CCP_HDRLEN) {
999             if (!rcvd) {
1000                 /* we're agreeing to send compressed packets. */
1001                 if (sc->sc_xc_state != NULL
1002                     && (*sc->sc_xcomp->comp_init)
1003                         (sc->sc_xc_state, dp + CCP_HDRLEN, slen - CCP_HDRLEN,
1004                          sc->sc_if.if_unit, 0, sc->sc_flags & SC_DEBUG)) {
1005                     s = splimp();
1006                     sc->sc_flags |= SC_COMP_RUN;
1007                     splx(s);
1008                 }
1009             } else {
1010                 /* peer is agreeing to send compressed packets. */
1011                 if (sc->sc_rc_state != NULL
1012                     && (*sc->sc_rcomp->decomp_init)
1013                         (sc->sc_rc_state, dp + CCP_HDRLEN, slen - CCP_HDRLEN,
1014                          sc->sc_if.if_unit, 0, sc->sc_mru,
1015                          sc->sc_flags & SC_DEBUG)) {
1016                     s = splimp();
1017                     sc->sc_flags |= SC_DECOMP_RUN;
1018                     sc->sc_flags &= ~(SC_DC_ERROR | SC_DC_FERROR);
1019                     splx(s);
1020                 }
1021             }
1022         }
1023         break;
1024
1025     case CCP_RESETACK:
1026         if (sc->sc_flags & SC_CCP_UP) {
1027             if (!rcvd) {
1028                 if (sc->sc_xc_state && (sc->sc_flags & SC_COMP_RUN))
1029                     (*sc->sc_xcomp->comp_reset)(sc->sc_xc_state);
1030             } else {
1031                 if (sc->sc_rc_state && (sc->sc_flags & SC_DECOMP_RUN)) {
1032                     (*sc->sc_rcomp->decomp_reset)(sc->sc_rc_state);
1033                     s = splimp();
1034                     sc->sc_flags &= ~SC_DC_ERROR;
1035                     splx(s);
1036                 }
1037             }
1038         }
1039         break;
1040     }
1041 }
1042
1043 /*
1044  * CCP is down; free (de)compressor state if necessary.
1045  */
1046 static void
1047 ppp_ccp_closed(sc)
1048     struct ppp_softc *sc;
1049 {
1050     if (sc->sc_xc_state) {
1051         (*sc->sc_xcomp->comp_free)(sc->sc_xc_state);
1052         sc->sc_xc_state = NULL;
1053     }
1054     if (sc->sc_rc_state) {
1055         (*sc->sc_rcomp->decomp_free)(sc->sc_rc_state);
1056         sc->sc_rc_state = NULL;
1057     }
1058 }
1059 #endif /* PPP_COMPRESS */
1060
1061 /*
1062  * PPP packet input routine.
1063  * The caller has checked and removed the FCS and has inserted
1064  * the address/control bytes and the protocol high byte if they
1065  * were omitted.
1066  */
1067 void
1068 ppppktin(sc, m, lost)
1069     struct ppp_softc *sc;
1070     struct mbuf *m;
1071     int lost;
1072 {
1073     int s = splimp();
1074
1075     if (lost)
1076         m->m_flags |= M_ERRMARK;
1077     IF_ENQUEUE(&sc->sc_rawq, m);
1078     schednetisr(NETISR_PPP);
1079     splx(s);
1080 }
1081
1082 /*
1083  * Process a received PPP packet, doing decompression as necessary.
1084  */
1085 #define COMPTYPE(proto) ((proto) == PPP_VJC_COMP? TYPE_COMPRESSED_TCP: \
1086                          TYPE_UNCOMPRESSED_TCP)
1087
1088 static void
1089 ppp_inproc(sc, m)
1090     struct ppp_softc *sc;
1091     struct mbuf *m;
1092 {
1093     struct ifqueue *inq;
1094     int s, ilen, xlen, proto, rv;
1095     u_char *cp, adrs, ctrl;
1096     struct mbuf *mp, *dmp = NULL;
1097     u_char *iphdr;
1098     u_int hlen;
1099
1100     sc->sc_if.if_ipackets++;
1101
1102     if (sc->sc_flags & SC_LOG_INPKT) {
1103         printf("ppp%d: got %d bytes\n", sc->sc_if.if_unit, ilen);
1104         pppdumpm(m);
1105     }
1106
1107     cp = mtod(m, u_char *);
1108     adrs = PPP_ADDRESS(cp);
1109     ctrl = PPP_CONTROL(cp);
1110     proto = PPP_PROTOCOL(cp);
1111
1112     if (m->m_flags & M_ERRMARK) {
1113         m->m_flags &= ~M_ERRMARK;
1114         s = splimp();
1115         sc->sc_flags |= SC_VJ_RESET;
1116         splx(s);
1117     }
1118
1119 #ifdef PPP_COMPRESS
1120     /*
1121      * Decompress this packet if necessary, update the receiver's
1122      * dictionary, or take appropriate action on a CCP packet.
1123      */
1124     if (proto == PPP_COMP && sc->sc_rc_state && (sc->sc_flags & SC_DECOMP_RUN)
1125         && !(sc->sc_flags & SC_DC_ERROR) && !(sc->sc_flags & SC_DC_FERROR)) {
1126         /* decompress this packet */
1127         rv = (*sc->sc_rcomp->decompress)(sc->sc_rc_state, m, &dmp);
1128         if (rv == DECOMP_OK) {
1129             m_freem(m);
1130             if (dmp == NULL) {
1131                 /* no error, but no decompressed packet produced */
1132                 return;
1133             }
1134             m = dmp;
1135             cp = mtod(m, u_char *);
1136             proto = PPP_PROTOCOL(cp);
1137
1138         } else {
1139             /*
1140              * An error has occurred in decompression.
1141              * Pass the compressed packet up to pppd, which may take
1142              * CCP down or issue a Reset-Req.
1143              */
1144             if (sc->sc_flags & SC_DEBUG)
1145                 printf("ppp%d: decompress failed %d\n", sc->sc_if.if_unit, rv);
1146             s = splimp();
1147             sc->sc_flags |= SC_VJ_RESET;
1148             if (rv == DECOMP_ERROR)
1149                 sc->sc_flags |= SC_DC_ERROR;
1150             else
1151                 sc->sc_flags |= SC_DC_FERROR;
1152             splx(s);
1153         }
1154
1155     } else {
1156         if (sc->sc_rc_state && (sc->sc_flags & SC_DECOMP_RUN)) {
1157             (*sc->sc_rcomp->incomp)(sc->sc_rc_state, m);
1158         }
1159         if (proto == PPP_CCP) {
1160             ppp_ccp(sc, m, 1);
1161         }
1162     }
1163 #endif
1164
1165     ilen = 0;
1166     for (mp = m; mp != NULL; mp = mp->m_next)
1167         ilen += mp->m_len;
1168
1169 #ifdef VJC
1170     if (sc->sc_flags & SC_VJ_RESET) {
1171         /*
1172          * If we've missed a packet, we must toss subsequent compressed
1173          * packets which don't have an explicit connection ID.
1174          */
1175         vj_uncompress_tcp(NULL, 0, TYPE_ERROR, &sc->sc_comp);
1176         s = splimp();
1177         sc->sc_flags &= ~SC_VJ_RESET;
1178         splx(s);
1179     }
1180
1181     /*
1182      * See if we have a VJ-compressed packet to uncompress.
1183      */
1184     if (proto == PPP_VJC_COMP) {
1185         if (sc->sc_flags & SC_REJ_COMP_TCP)
1186             goto bad;
1187
1188         xlen = vj_uncompress_tcp_core(cp + PPP_HDRLEN, m->m_len - PPP_HDRLEN,
1189                                       ilen - PPP_HDRLEN, TYPE_COMPRESSED_TCP,
1190                                       &sc->sc_comp, &iphdr, &hlen);
1191
1192         if (xlen <= 0) {
1193             if (sc->sc_flags & SC_DEBUG)
1194                 printf("ppp%d: VJ uncompress failed on type comp\n",
1195                         sc->sc_if.if_unit);
1196             goto bad;
1197         }
1198
1199         /* Copy the PPP and IP headers into a new mbuf. */
1200         MGETHDR(mp, M_DONTWAIT, MT_DATA);
1201         if (mp == NULL)
1202             goto bad;
1203         mp->m_len = 0;
1204         mp->m_next = NULL;
1205         if (hlen + PPP_HDRLEN > MHLEN) {
1206             MCLGET(mp, M_DONTWAIT);
1207             if (M_TRAILINGSPACE(mp) < hlen + PPP_HDRLEN) {
1208                 m_freem(mp);
1209                 goto bad;       /* lose if big headers and no clusters */
1210             }
1211         }
1212         cp = mtod(mp, u_char *);
1213         cp[0] = adrs;
1214         cp[1] = ctrl;
1215         cp[2] = 0;
1216         cp[3] = PPP_IP;
1217         proto = PPP_IP;
1218         bcopy(iphdr, cp + PPP_HDRLEN, hlen);
1219         mp->m_len = hlen + PPP_HDRLEN;
1220
1221         /*
1222          * Trim the PPP and VJ headers off the old mbuf
1223          * and stick the new and old mbufs together.
1224          */
1225         m->m_data += PPP_HDRLEN + xlen;
1226         m->m_len -= PPP_HDRLEN + xlen;
1227         if (m->m_len <= M_TRAILINGSPACE(mp)) {
1228             bcopy(mtod(m, u_char *), mtod(mp, u_char *) + mp->m_len, m->m_len);
1229             mp->m_len += m->m_len;
1230             MFREE(m, mp->m_next);
1231         } else
1232             mp->m_next = m;
1233         m = mp;
1234         ilen += hlen - xlen;
1235
1236     } else if (proto == PPP_VJC_UNCOMP) {
1237         if (sc->sc_flags & SC_REJ_COMP_TCP)
1238             goto bad;
1239
1240         xlen = vj_uncompress_tcp_core(cp + PPP_HDRLEN, m->m_len - PPP_HDRLEN,
1241                                       ilen - PPP_HDRLEN, TYPE_UNCOMPRESSED_TCP,
1242                                       &sc->sc_comp, &iphdr, &hlen);
1243
1244         if (xlen < 0) {
1245             if (sc->sc_flags & SC_DEBUG)
1246                 printf("ppp%d: VJ uncompress failed on type uncomp\n",
1247                         sc->sc_if.if_unit);
1248             goto bad;
1249         }
1250
1251         proto = PPP_IP;
1252         cp[3] = PPP_IP;
1253     }
1254 #endif /* VJC */
1255
1256     /*
1257      * If the packet will fit in a header mbuf, don't waste a
1258      * whole cluster on it.
1259      */
1260     if (ilen <= MHLEN && M_IS_CLUSTER(m)) {
1261         MGETHDR(mp, M_DONTWAIT, MT_DATA);
1262         if (mp != NULL) {
1263             m_copydata(m, 0, ilen, mtod(mp, caddr_t));
1264             m_freem(m);
1265             m = mp;
1266             m->m_len = ilen;
1267         }
1268     }
1269     m->m_pkthdr.len = ilen;
1270     m->m_pkthdr.rcvif = &sc->sc_if;
1271
1272 #if NBPFILTER > 0
1273     /* See if bpf wants to look at the packet. */
1274     if (sc->sc_bpf)
1275         bpf_mtap(sc->sc_bpf, m);
1276 #endif
1277
1278     rv = 0;
1279     switch (proto) {
1280 #ifdef INET
1281     case PPP_IP:
1282         /*
1283          * IP packet - take off the ppp header and pass it up to IP.
1284          */
1285         if ((sc->sc_if.if_flags & IFF_UP) == 0
1286             || sc->sc_npmode[NP_IP] != NPMODE_PASS) {
1287             /* interface is down - drop the packet. */
1288             m_freem(m);
1289             return;
1290         }
1291         m->m_pkthdr.len -= PPP_HDRLEN;
1292         m->m_data += PPP_HDRLEN;
1293         m->m_len -= PPP_HDRLEN;
1294         schednetisr(NETISR_IP);
1295         inq = &ipintrq;
1296         sc->sc_last_recv = time.tv_sec; /* update time of last pkt rcvd */
1297         break;
1298 #endif
1299
1300     default:
1301         /*
1302          * Some other protocol - place on input queue for read().
1303          */
1304         inq = &sc->sc_inq;
1305         rv = 1;
1306         break;
1307     }
1308
1309     /*
1310      * Put the packet on the appropriate input queue.
1311      */
1312     s = splimp();
1313     if (IF_QFULL(inq)) {
1314         IF_DROP(inq);
1315         splx(s);
1316         if (sc->sc_flags & SC_DEBUG)
1317             printf("ppp%d: input queue full\n", sc->sc_if.if_unit);
1318         sc->sc_if.if_iqdrops++;
1319         goto bad;
1320     }
1321     IF_ENQUEUE(inq, m);
1322     splx(s);
1323
1324     if (rv)
1325         (*sc->sc_ctlp)(sc);
1326
1327     return;
1328
1329  bad:
1330     m_freem(m);
1331     sc->sc_if.if_ierrors++;
1332 }
1333
1334 #define MAX_DUMP_BYTES  128
1335
1336 static void
1337 pppdumpm(m0)
1338     struct mbuf *m0;
1339 {
1340     char buf[3*MAX_DUMP_BYTES+4];
1341     char *bp = buf;
1342     struct mbuf *m;
1343     static char digits[] = "0123456789abcdef";
1344
1345     for (m = m0; m; m = m->m_next) {
1346         int l = m->m_len;
1347         u_char *rptr = (u_char *)m->m_data;
1348
1349         while (l--) {
1350             if (bp > buf + sizeof(buf) - 4)
1351                 goto done;
1352             *bp++ = digits[*rptr >> 4]; /* convert byte to ascii hex */
1353             *bp++ = digits[*rptr++ & 0xf];
1354         }
1355
1356         if (m->m_next) {
1357             if (bp > buf + sizeof(buf) - 3)
1358                 goto done;
1359             *bp++ = '|';
1360         } else
1361             *bp++ = ' ';
1362     }
1363 done:
1364     if (m)
1365         *bp++ = '>';
1366     *bp = 0;
1367     printf("%s\n", buf);
1368 }
1369
1370 #endif  /* NPPP > 0 */