2 * ppp.c - STREAMS multiplexing pseudo-device driver for PPP.
4 * Copyright (c) 1994 The Australian National University.
7 * Permission to use, copy, modify, and distribute this software and its
8 * documentation is hereby granted, provided that the above copyright
9 * notice appears in all copies. This software is provided without any
10 * warranty, express or implied. The Australian National University
11 * makes no representations about the suitability of this software for
14 * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
15 * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
16 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
17 * THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY
20 * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
21 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22 * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
23 * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
24 * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
27 * $Id: ppp.c,v 1.6 1995/06/30 00:54:51 paulus Exp $
31 * This file is used under Solaris 2.
34 #include <sys/types.h>
35 #include <sys/param.h>
37 #include <sys/stream.h>
38 #include <sys/stropts.h>
39 #include <sys/errno.h>
40 #include <sys/cmn_err.h>
43 #include <sys/ioccom.h>
47 #include <sys/modctl.h>
48 #include <sys/kstat.h>
49 #include <sys/sunddi.h>
51 #include <net/ppp_defs.h>
52 #include <net/pppio.h>
61 * The IP module uses this SAP value for IP packets.
64 #define ETHERTYPE_IP 0x800
68 #define PPP_MAXMTU 65535
72 * Private information; one per upper stream.
74 typedef struct upperstr {
75 minor_t mn; /* minor device number */
76 struct upperstr *nextmn; /* next minor device */
77 queue_t *q; /* read q associated with this upper stream */
78 int flags; /* flag bits, see below */
79 int state; /* current DLPI state */
80 int sap; /* service access point */
81 int req_sap; /* which SAP the DLPI client requested */
82 struct upperstr *ppa; /* control stream for our ppa */
83 struct upperstr *next; /* next stream for this ppa */
84 uint ioc_id; /* last ioctl ID for this stream */
86 * There is exactly one control stream for each PPA.
87 * The following fields are only used for control streams.
90 queue_t *lowerq; /* write queue attached below this PPA */
91 struct upperstr *nextppa; /* next control stream */
94 struct pppstat stats; /* statistics */
96 kstat_t *kstats; /* stats for netstat */
100 /* Values for flags */
101 #define US_PRIV 1 /* stream was opened by superuser */
102 #define US_CONTROL 2 /* stream is a control stream */
103 #define US_BLOCKED 4 /* flow ctrl has blocked lower write stream */
104 #define US_LASTMOD 8 /* no PPP modules below us */
106 static upperstr_t *minor_devs = NULL;
107 static upperstr_t *ppas = NULL;
110 static int ppp_identify __P((dev_info_t *));
111 static int ppp_attach __P((dev_info_t *, ddi_attach_cmd_t));
112 static int ppp_detach __P((dev_info_t *, ddi_detach_cmd_t));
113 static int ppp_devinfo __P((dev_info_t *, ddi_info_cmd_t, void *, void **));
115 static int pppopen __P((queue_t *, dev_t *, int, int, cred_t *));
116 static int pppclose __P((queue_t *, int, cred_t *));
117 static int pppuwput __P((queue_t *, mblk_t *));
118 static int pppursrv __P((queue_t *));
119 static int pppuwsrv __P((queue_t *));
120 static int ppplrput __P((queue_t *, mblk_t *));
121 static int ppplwput __P((queue_t *, mblk_t *));
122 static int ppplrsrv __P((queue_t *));
123 static int ppplwsrv __P((queue_t *));
124 static void dlpi_request __P((queue_t *, mblk_t *, upperstr_t *));
125 static void dlpi_error __P((queue_t *, int, int, int));
126 static void dlpi_ok __P((queue_t *, int));
127 static int send_data __P((mblk_t *, upperstr_t *));
128 static void new_ppa __P((queue_t *, mblk_t *));
129 static void attach_ppa __P((queue_t *, mblk_t *));
130 static void detach_ppa __P((queue_t *, mblk_t *));
131 static void debug_dump __P((queue_t *, mblk_t *));
132 static upperstr_t *find_dest __P((upperstr_t *, int));
133 static int putctl2 __P((queue_t *, int, int, int));
134 static int putctl4 __P((queue_t *, int, int, int));
136 static struct module_info ppp_info = {
137 0xb1a6, "ppp", 0, 512, 512, 128
140 static struct qinit pppurint = {
141 NULL, pppursrv, pppopen, pppclose, NULL, &ppp_info, NULL
144 static struct qinit pppuwint = {
145 pppuwput, pppuwsrv, NULL, NULL, NULL, &ppp_info, NULL
148 static struct qinit ppplrint = {
149 ppplrput, ppplrsrv, NULL, NULL, NULL, &ppp_info, NULL
152 static struct qinit ppplwint = {
153 ppplwput, ppplwsrv, NULL, NULL, NULL, &ppp_info, NULL
156 static struct streamtab pppinfo = {
157 &pppurint, &pppuwint,
162 static dev_info_t *ppp_dip;
164 static struct cb_ops cb_ppp_ops = {
165 nulldev, nulldev, nodev, nodev, /* cb_open, ... */
166 nodev, nodev, nodev, nodev, /* cb_dump, ... */
167 nodev, nodev, nodev, nochpoll, /* cb_devmap, ... */
168 ddi_prop_op, /* cb_prop_op */
169 &pppinfo, /* cb_stream */
170 D_NEW|D_MP|D_MTQPAIR|D_MTOUTPERIM|D_MTOCEXCL /* cb_flag */
173 static struct dev_ops ppp_ops = {
174 DEVO_REV, /* devo_rev */
176 ppp_devinfo, /* devo_getinfo */
177 ppp_identify, /* devo_identify */
178 nulldev, /* devo_probe */
179 ppp_attach, /* devo_attach */
180 ppp_detach, /* devo_detach */
181 nodev, /* devo_reset */
182 &cb_ppp_ops, /* devo_cb_ops */
183 NULL /* devo_bus_ops */
187 * Module linkage information
190 static struct modldrv modldrv = {
191 &mod_driverops, /* says this is a pseudo driver */
192 "PPP-2.2 multiplexing driver",
193 &ppp_ops /* driver ops */
196 static struct modlinkage modlinkage = {
205 return mod_install(&modlinkage);
211 return mod_remove(&modlinkage);
218 return mod_info(&modlinkage, mip);
225 return strcmp(ddi_get_name(dip), "ppp") == 0? DDI_IDENTIFIED:
232 ddi_attach_cmd_t cmd;
235 if (cmd != DDI_ATTACH)
237 if (ddi_create_minor_node(dip, "ppp", S_IFCHR, 0, DDI_PSEUDO, CLONE_DEV)
239 ddi_remove_minor_node(dip, NULL);
248 ddi_detach_cmd_t cmd;
250 ddi_remove_minor_node(dip, NULL);
255 ppp_devinfo(dip, cmd, arg, result)
265 case DDI_INFO_DEVT2DEVINFO:
269 *result = (void *) ppp_dip;
271 case DDI_INFO_DEVT2INSTANCE:
283 # define qprocsoff(q)
284 # define canputnext(q) canput((q)->q_next)
285 # define qwriter(q, mp, func, scope) (func)((q), (mp))
289 pppopen(q, devp, oflag, sflag, credp)
300 return 0; /* device is already open */
302 if (sflag == CLONEOPEN) {
304 for (prevp = &minor_devs; (up = *prevp) != 0; prevp = &up->nextmn) {
310 mn = getminor(*devp);
311 for (prevp = &minor_devs; (up = *prevp) != 0; prevp = &up->nextmn) {
316 /* this can't happen */
317 q->q_ptr = WR(q)->q_ptr = up;
323 * Construct a new minor node.
325 up = (upperstr_t *) kmem_zalloc(sizeof(upperstr_t), KM_SLEEP);
327 cmn_err(CE_CONT, "pppopen: out of kernel memory\n");
333 *devp = makedevice(getmajor(*devp), mn);
335 if (drv_priv(credp) == 0)
336 up->flags |= US_PRIV;
337 up->state = DL_UNATTACHED;
348 pppclose(q, flag, credp)
353 upperstr_t *up, **upp;
354 upperstr_t *as, *asnext;
359 up = (upperstr_t *) q->q_ptr;
362 if (up->flags & US_CONTROL) {
364 * This stream represents a PPA:
365 * For all streams attached to the PPA, clear their
366 * references to this PPA.
367 * Then remove this PPA from the list of PPAs.
369 for (as = up->next; as != 0; as = asnext) {
373 if (as->flags & US_BLOCKED) {
374 as->flags &= ~US_BLOCKED;
375 flushq(WR(as->q), FLUSHDATA);
378 for (upp = &ppas; *upp != 0; upp = &(*upp)->nextppa)
386 * If this stream is attached to a PPA,
387 * remove it from the PPA's list.
389 if ((as = up->ppa) != 0) {
390 for (; as->next != 0; as = as->next)
391 if (as->next == up) {
400 kstat_delete(up->kstats);
406 for (prevp = &minor_devs; *prevp != 0; prevp = &(*prevp)->nextmn) {
412 kmem_free(up, sizeof(upperstr_t));
418 * A message from on high. We do one of three things:
420 * - put the message on the lower write stream
421 * - queue it for our service routine
428 upperstr_t *us, *usnext, *ppa;
435 us = (upperstr_t *) q->q_ptr;
436 switch (mp->b_datap->db_type) {
439 dlpi_request(q, mp, us);
443 if ((us->flags & US_CONTROL) == 0
444 || msgdsize(mp) > us->mtu + PPP_HDRLEN) {
446 cmn_err(CE_CONT, "pppuwput: junk data len=%d\n", msgdsize(mp));
451 if (!send_data(mp, us))
456 iop = (struct iocblk *) mp->b_rptr;
458 switch (iop->ioc_cmd) {
460 if ((us->flags & US_CONTROL) == 0 || us->lowerq != 0)
462 lb = (struct linkblk *) mp->b_cont->b_rptr;
463 us->lowerq = lq = lb->l_qbot;
469 us->flags &= ~US_LASTMOD;
470 /* Unblock upper streams which now feed this lower stream. */
472 /* Send useful information down to the modules which
473 are now linked below us. */
474 putctl2(lq, M_CTL, PPPCTL_UNIT, us->ppa_id);
475 putctl4(lq, M_CTL, PPPCTL_MRU, us->mru);
476 putctl4(lq, M_CTL, PPPCTL_MTU, us->mtu);
480 lb = (struct linkblk *) mp->b_cont->b_rptr;
482 if (us->lowerq != lb->l_qbot)
483 cmn_err(CE_CONT, "ppp unlink: lowerq=%x qbot=%x\n",
484 us->lowerq, lb->l_qbot);
489 /* Unblock streams which now feed back up the control stream. */
494 if (us->flags & US_CONTROL)
496 if ((us->flags & US_PRIV) == 0) {
500 /* Arrange to return an int */
501 if ((mq = mp->b_cont) == 0
502 || mq->b_datap->db_lim - mq->b_rptr < sizeof(int)) {
503 mq = allocb(sizeof(int), BPRI_HI);
513 iop->ioc_count = sizeof(int);
514 mq->b_wptr = mq->b_rptr + sizeof(int);
515 qwriter(q, mp, new_ppa, PERIM_OUTER);
520 /* like dlpi_attach, for programs which can't write to
521 the stream (like pppstats) */
522 if (iop->ioc_count != sizeof(int) || us->ppa != 0)
524 n = *(int *)mp->b_cont->b_rptr;
525 for (ppa = ppas; ppa != 0; ppa = ppa->nextppa)
526 if (ppa->ppa_id == n)
532 qwriter(q, mp, attach_ppa, PERIM_OUTER);
537 if (iop->ioc_count != sizeof(int) || (us->flags & US_CONTROL) == 0)
539 n = *(int *)mp->b_cont->b_rptr;
540 if (n <= 0 || n > PPP_MAXMTU)
546 putctl4(us->lowerq, M_CTL, PPPCTL_MRU, n);
552 if (iop->ioc_count != sizeof(int) || (us->flags & US_CONTROL) == 0)
554 n = *(int *)mp->b_cont->b_rptr;
555 if (n <= 0 || n > PPP_MAXMTU)
561 putctl4(us->lowerq, M_CTL, PPPCTL_MTU, n);
567 us->flags |= US_LASTMOD;
572 if (iop->ioc_count != sizeof(int))
574 n = *(int *)mp->b_cont->b_rptr;
575 if (n == PPPDBG_DUMP + PPPDBG_DRIVER) {
576 qwriter(q, NULL, debug_dump, PERIM_OUTER);
580 if (us->ppa == 0 || us->ppa->lowerq == 0)
582 putnext(us->ppa->lowerq, mp);
588 if (us->ppa == 0 || us->ppa->lowerq == 0)
590 us->ioc_id = iop->ioc_id;
592 switch (iop->ioc_cmd) {
595 if (us->flags & US_LASTMOD) {
599 putnext(us->ppa->lowerq, mp);
602 if (us->flags & US_PRIV)
603 putnext(us->ppa->lowerq, mp);
606 cmn_err(CE_CONT, "ppp ioctl %x rejected\n", iop->ioc_cmd);
616 iop->ioc_error = error;
617 mp->b_datap->db_type = M_IOCNAK;
619 } else if (error == 0) {
620 mp->b_datap->db_type = M_IOCACK;
626 if (*mp->b_rptr & FLUSHW)
627 flushq(q, FLUSHDATA);
628 if (*mp->b_rptr & FLUSHR) {
629 *mp->b_rptr &= ~FLUSHW;
643 dlpi_request(q, mp, us)
648 union DL_primitives *d = (union DL_primitives *) mp->b_rptr;
649 int size = mp->b_wptr - mp->b_rptr;
651 upperstr_t *ppa, *os;
656 switch (d->dl_primitive) {
658 if (size < sizeof(dl_info_req_t))
660 if ((reply = allocb(sizeof(dl_info_ack_t), BPRI_HI)) == 0)
661 break; /* should do bufcall */
662 reply->b_datap->db_type = M_PCPROTO;
663 info = (dl_info_ack_t *) reply->b_wptr;
664 reply->b_wptr += sizeof(dl_info_ack_t);
665 bzero((caddr_t) info, sizeof(dl_info_ack_t));
666 info->dl_primitive = DL_INFO_ACK;
667 info->dl_max_sdu = PPP_MAXMTU;
668 info->dl_min_sdu = 1;
669 info->dl_addr_length = sizeof(ulong);
671 info->dl_mac_type = DL_OTHER;
673 info->dl_mac_type = DL_HDLC; /* a lie */
675 info->dl_current_state = us->state;
676 info->dl_service_mode = DL_CLDLS;
677 info->dl_provider_style = DL_STYLE2;
678 #if DL_CURRENT_VERSION >= 2
679 info->dl_sap_length = sizeof(ulong);
680 info->dl_version = DL_CURRENT_VERSION;
686 if (size < sizeof(dl_attach_req_t))
688 if (us->state != DL_UNATTACHED || us->ppa != 0) {
689 dlpi_error(q, DL_ATTACH_REQ, DL_OUTSTATE, 0);
692 for (ppa = ppas; ppa != 0; ppa = ppa->nextppa)
693 if (ppa->ppa_id == d->attach_req.dl_ppa)
696 dlpi_error(q, DL_ATTACH_REQ, DL_BADPPA, 0);
700 qwriter(q, mp, attach_ppa, PERIM_OUTER);
704 if (size < sizeof(dl_detach_req_t))
706 if (us->state != DL_UNBOUND || us->ppa == 0) {
707 dlpi_error(q, DL_DETACH_REQ, DL_OUTSTATE, 0);
710 qwriter(q, mp, detach_ppa, PERIM_OUTER);
714 if (size < sizeof(dl_bind_req_t))
716 if (us->state != DL_UNBOUND || us->ppa == 0) {
717 dlpi_error(q, DL_BIND_REQ, DL_OUTSTATE, 0);
720 if (d->bind_req.dl_service_mode != DL_CLDLS) {
721 dlpi_error(q, DL_BIND_REQ, DL_UNSUPPORTED, 0);
725 /* saps must be valid PPP network protocol numbers,
726 except that we accept ETHERTYPE_IP in place of PPP_IP. */
727 sap = d->bind_req.dl_sap;
730 cmn_err(CE_CONT, "ppp bind %x\n", sap);
732 if (sap == ETHERTYPE_IP)
734 if (sap < 0x21 || sap > 0x3fff || (sap & 0x101) != 1) {
735 dlpi_error(q, DL_BIND_REQ, DL_BADADDR, 0);
739 /* check that no other stream is bound to this sap already. */
740 for (os = us->ppa; os != 0; os = os->next)
744 dlpi_error(q, DL_BIND_REQ, DL_NOADDR, 0);
751 if ((reply = allocb(sizeof(dl_bind_ack_t) + sizeof(ulong),
753 break; /* should do bufcall */
754 ackp = (dl_bind_ack_t *) reply->b_wptr;
755 reply->b_wptr += sizeof(dl_bind_ack_t) + sizeof(ulong);
756 reply->b_datap->db_type = M_PCPROTO;
757 bzero((caddr_t) ackp, sizeof(dl_bind_ack_t));
758 ackp->dl_primitive = DL_BIND_ACK;
760 ackp->dl_addr_length = sizeof(ulong);
761 ackp->dl_addr_offset = sizeof(dl_bind_ack_t);
762 *(ulong *)(ackp+1) = sap;
767 if (size < sizeof(dl_unbind_req_t))
769 if (us->state != DL_IDLE) {
770 dlpi_error(q, DL_UNBIND_REQ, DL_OUTSTATE, 0);
774 us->state = DL_UNBOUND;
775 dlpi_ok(q, DL_UNBIND_REQ);
778 case DL_UNITDATA_REQ:
779 if (size < sizeof(dl_unitdata_req_t))
781 if (us->state != DL_IDLE) {
782 dlpi_error(q, DL_UNITDATA_REQ, DL_OUTSTATE, 0);
786 cmn_err(CE_CONT, "ppp: in state dl_idle but ppa == 0?\n");
789 len = mp->b_cont == 0? 0: msgdsize(mp->b_cont);
790 if (len > us->ppa->mtu) {
792 cmn_err(CE_CONT, "dlpi data too large (%d > %d)\n", len, us->mtu);
796 /* this assumes PPP_HDRLEN <= sizeof(dl_unitdata_req_t) */
797 if (mp->b_datap->db_ref > 1) {
798 np = allocb(PPP_HDRLEN, BPRI_HI);
801 np->b_cont = mp->b_cont;
806 mp->b_datap->db_type = M_DATA;
807 /* XXX should use dl_dest_addr_offset/length here,
808 but we would have to translate ETHERTYPE_IP -> PPP_IP */
809 mp->b_wptr = mp->b_rptr + PPP_HDRLEN;
810 mp->b_rptr[0] = PPP_ALLSTATIONS;
811 mp->b_rptr[1] = PPP_UI;
812 mp->b_rptr[2] = us->sap >> 8;
813 mp->b_rptr[3] = us->sap;
814 if (!send_data(mp, us))
818 #if DL_CURRENT_VERSION >= 2
819 case DL_SUBS_BIND_REQ:
820 case DL_SUBS_UNBIND_REQ:
821 case DL_ENABMULTI_REQ:
822 case DL_DISABMULTI_REQ:
823 case DL_PROMISCON_REQ:
824 case DL_PROMISCOFF_REQ:
825 case DL_PHYS_ADDR_REQ:
826 case DL_SET_PHYS_ADDR_REQ:
829 case DL_REPLY_UPDATE_REQ:
831 case DL_DATA_ACK_REQ:
835 dlpi_error(q, d->dl_primitive, DL_NOTSUPPORTED, 0);
839 case DL_DISCONNECT_REQ:
842 dlpi_error(q, d->dl_primitive, DL_OUTSTATE, 0);
846 dlpi_error(q, d->dl_primitive, DL_BADQOSTYPE, 0);
849 #if DL_CURRENT_VERSION >= 2
856 cmn_err(CE_CONT, "ppp: unknown dlpi prim 0x%x\n", d->dl_primitive);
859 dlpi_error(q, d->dl_primitive, DL_BADPRIM, 0);
866 dlpi_error(q, prim, err, uerr)
871 dl_error_ack_t *errp;
873 reply = allocb(sizeof(dl_error_ack_t), BPRI_HI);
875 return; /* XXX should do bufcall */
876 reply->b_datap->db_type = M_PCPROTO;
877 errp = (dl_error_ack_t *) reply->b_wptr;
878 reply->b_wptr += sizeof(dl_error_ack_t);
879 errp->dl_primitive = DL_ERROR_ACK;
880 errp->dl_error_primitive = prim;
881 errp->dl_errno = err;
882 errp->dl_unix_errno = uerr;
894 reply = allocb(sizeof(dl_ok_ack_t), BPRI_HI);
896 return; /* XXX should do bufcall */
897 reply->b_datap->db_type = M_PCPROTO;
898 okp = (dl_ok_ack_t *) reply->b_wptr;
899 reply->b_wptr += sizeof(dl_ok_ack_t);
900 okp->dl_primitive = DL_OK_ACK;
901 okp->dl_correct_primitive = prim;
913 if (us->flags & US_BLOCKED)
920 if ((q = ppa->lowerq) == 0) {
921 /* try to send it up the control stream */
922 if (canputnext(ppa->q)) {
927 if (canputnext(ppa->lowerq)) {
929 * The lower write queue's put procedure just updates counters
930 * and does a putnext. We call it in order to enter the lower
931 * queues' perimeter so that the counter updates are serialized.
933 put(ppa->lowerq, mp);
937 us->flags |= US_BLOCKED;
942 * Allocate a new PPA id and link this stream into the list of PPAs.
943 * This procedure is called with an exclusive lock on all queues in
951 upperstr_t *us, **usp;
956 while ((us = *usp) != 0 && ppa_id == us->ppa_id) {
960 us = (upperstr_t *) q->q_ptr;
966 us->flags |= US_CONTROL;
972 if (us->kstats == 0) {
975 sprintf(unit, "ppp%d", us->ppa->ppa_id);
976 us->kstats = kstat_create("ppp", us->ppa->ppa_id, unit,
977 "net", KSTAT_TYPE_NAMED, 4, 0);
978 if (us->kstats != 0) {
979 kstat_named_t *kn = KSTAT_NAMED_PTR(us->kstats);
981 strcpy(kn[0].name, "ipackets");
982 kn[0].data_type = KSTAT_DATA_ULONG;
983 strcpy(kn[1].name, "ierrors");
984 kn[1].data_type = KSTAT_DATA_ULONG;
985 strcpy(kn[2].name, "opackets");
986 kn[2].data_type = KSTAT_DATA_ULONG;
987 strcpy(kn[3].name, "oerrors");
988 kn[3].data_type = KSTAT_DATA_ULONG;
989 kstat_install(us->kstats);
994 *(int *)mp->b_cont->b_rptr = ppa_id;
995 mp->b_datap->db_type = M_IOCACK;
1006 us = (upperstr_t *) q->q_ptr;
1007 us->state = DL_UNBOUND;
1008 for (t = us->ppa; t->next != 0; t = t->next)
1012 if (mp->b_datap->db_type == M_IOCTL) {
1013 mp->b_datap->db_type = M_IOCACK;
1016 dlpi_ok(q, DL_ATTACH_REQ);
1027 us = (upperstr_t *) q->q_ptr;
1028 for (t = us->ppa; t->next != 0; t = t->next)
1029 if (t->next == us) {
1035 us->state = DL_UNATTACHED;
1036 dlpi_ok(q, DL_DETACH_REQ);
1044 struct lowerstr *ls;
1048 us = (upperstr_t *) q->q_ptr;
1049 us->flags &= ~US_BLOCKED;
1050 while ((mp = getq(q)) != 0) {
1051 if (!send_data(mp, us)) {
1067 if (ppa != 0) { /* why wouldn't it? */
1068 ppa->stats.ppp_opackets++;
1069 ppa->stats.ppp_obytes += msgdsize(mp);
1071 if (ppa->kstats != 0)
1072 KSTAT_NAMED_PTR(ppa->kstats)[2].value.ul++;
1086 * Flow control has back-enabled this stream:
1087 * enable the write service procedures of all upper
1088 * streams feeding this lower stream.
1090 for (us = (upperstr_t *) q->q_ptr; us != NULL; us = us->next)
1091 if (us->flags & US_BLOCKED)
1100 upperstr_t *us, *as;
1102 dl_unitdata_ind_t *ud;
1105 us = (upperstr_t *) q->q_ptr;
1106 if (us->flags & US_CONTROL) {
1109 * If there is no lower queue attached, run the write service
1110 * routines of other upper streams attached to this PPA.
1112 if (us->lowerq == 0) {
1115 if (as->flags & US_BLOCKED)
1122 * A network protocol stream. Put a DLPI header on each
1123 * packet and send it on.
1124 * (Actually, it seems that the IP module will happily
1125 * accept M_DATA messages without the DL_UNITDATA_IND header.)
1127 while ((mp = getq(q)) != 0) {
1128 if (!canputnext(q)) {
1132 proto = PPP_PROTOCOL(mp->b_rptr);
1133 mp->b_rptr += PPP_HDRLEN;
1134 hdr = allocb(sizeof(dl_unitdata_ind_t) + 2 * sizeof(ulong),
1137 /* XXX should put it back and use bufcall */
1141 hdr->b_datap->db_type = M_PROTO;
1142 ud = (dl_unitdata_ind_t *) hdr->b_wptr;
1143 hdr->b_wptr += sizeof(dl_unitdata_ind_t) + 2 * sizeof(ulong);
1145 ud->dl_primitive = DL_UNITDATA_IND;
1146 ud->dl_dest_addr_length = sizeof(ulong);
1147 ud->dl_dest_addr_offset = sizeof(dl_unitdata_ind_t);
1148 ud->dl_src_addr_length = sizeof(ulong);
1149 ud->dl_src_addr_offset = ud->dl_dest_addr_offset + sizeof(ulong);
1150 #if DL_CURRENT_VERSION >= 2
1151 ud->dl_group_address = 0;
1153 /* Send the DLPI client the data with the SAP they requested,
1154 (e.g. ETHERTYPE_IP) rather than the PPP protocol number
1156 ((ulong *)(ud + 1))[0] = us->req_sap; /* dest SAP */
1157 ((ulong *)(ud + 1))[1] = us->req_sap; /* src SAP */
1163 * If this stream is attached to a PPA with a lower queue pair,
1164 * enable the read queue's service routine if it has data queued.
1165 * XXX there is a possibility that packets could get out of order
1166 * if ppplrput now runs before ppplrsrv.
1168 if (us->ppa != 0 && us->ppa->lowerq != 0)
1169 qenable(RD(us->ppa->lowerq));
1175 find_dest(ppa, proto)
1181 for (us = ppa->next; us != 0; us = us->next)
1182 if (proto == us->sap)
1192 upperstr_t *ppa, *us;
1198 ppa = (upperstr_t *) q->q_ptr;
1201 cmn_err(CE_CONT, "ppplrput: q = %x, ppa = 0??\n", q);
1206 switch (mp->b_datap->db_type) {
1208 if (*mp->b_rptr & FLUSHW) {
1209 *mp->b_rptr &= ~FLUSHR;
1216 switch (*mp->b_rptr) {
1219 if (ppa->kstats != 0) {
1220 KSTAT_NAMED_PTR(ppa->kstats)[1].value.ul++;
1223 ppa->stats.ppp_ierrors++;
1227 if (ppa->kstats != 0) {
1228 KSTAT_NAMED_PTR(ppa->kstats)[3].value.ul++;
1231 ppa->stats.ppp_oerrors++;
1240 * Attempt to match up the response with the stream
1241 * that the request came from.
1243 iop = (struct iocblk *) mp->b_rptr;
1244 for (us = ppa; us != 0; us = us->next)
1245 if (us->ioc_id == iop->ioc_id)
1254 if (mp->b_datap->db_type == M_DATA) {
1256 if (mp->b_wptr - mp->b_rptr < PPP_HDRLEN) {
1257 np = msgpullup(mp, PPP_HDRLEN);
1261 cmn_err(CE_CONT, "ppp_lrput: msgpullup failed (len=%d)\n",
1268 ppa->stats.ppp_ipackets++;
1269 ppa->stats.ppp_ibytes += len;
1271 if (ppa->kstats != 0) {
1272 KSTAT_NAMED_PTR(ppa->kstats)[0].value.ul++;
1275 proto = PPP_PROTOCOL(mp->b_rptr);
1276 if (proto < 0x8000 && (us = find_dest(ppa, proto)) != 0) {
1278 * A data packet for some network protocol.
1279 * Queue it on the upper stream for that protocol.
1289 * A control frame, a frame for an unknown protocol,
1290 * or some other message type.
1291 * Send it up to pppd via the control stream.
1293 if (queclass(mp) == QPCTL || canputnext(ppa->q))
1294 putnext(ppa->q, mp);
1308 upperstr_t *ppa, *us;
1312 * Packets only get queued here for flow control reasons.
1314 ppa = (upperstr_t *) q->q_ptr;
1315 while ((mp = getq(q)) != 0) {
1316 if (mp->b_datap->db_type == M_DATA
1317 && (proto = PPP_PROTOCOL(mp->b_rptr)) < 0x8000
1318 && (us = find_dest(ppa, proto)) != 0) {
1326 if (canputnext(ppa->q))
1327 putnext(ppa->q, mp);
1338 putctl2(q, type, code, val)
1340 int type, code, val;
1344 mp = allocb(2, BPRI_HI);
1347 mp->b_datap->db_type = type;
1348 mp->b_wptr[0] = code;
1349 mp->b_wptr[1] = val;
1356 putctl4(q, type, code, val)
1358 int type, code, val;
1362 mp = allocb(4, BPRI_HI);
1365 mp->b_datap->db_type = type;
1366 mp->b_wptr[0] = code;
1367 ((short *)mp->b_wptr)[1] = val;
1375 queue_t *q; /* not used */
1376 mblk_t *mp; /* not used either */
1381 cmn_err(CE_CONT, "ppp upper streams:\n");
1382 for (us = minor_devs; us != 0; us = us->nextmn) {
1384 cmn_err(CE_CONT, " %d: q=%x rlev=%d wlev=%d flags=0x%b",
1385 us->mn, uq, (uq? qsize(uq): 0), (uq? qsize(WR(uq)): 0),
1386 us->flags, "\020\1priv\2control\3blocked\4last");
1387 cmn_err(CE_CONT, " state=%x sap=%x req_sap=%x", us->state, us->sap,
1390 cmn_err(CE_CONT, " ppa=?\n");
1392 cmn_err(CE_CONT, " ppa=%d\n", us->ppa->ppa_id);
1393 if (us->flags & US_CONTROL) {
1395 cmn_err(CE_CONT, " control for %d lq=%x rlev=%d wlev=%d",
1396 us->ppa_id, lq, (lq? qsize(RD(lq)): 0),
1397 (lq? qsize(lq): 0));
1398 cmn_err(CE_CONT, " mru=%d mtu=%d\n", us->mru, us->mtu);