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.3 1995/05/29 06:59:36 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 */
85 * There is exactly one control stream for each PPA.
86 * The following fields are only used for control streams.
89 queue_t *lowerq; /* write queue attached below this PPA */
90 struct upperstr *nextppa; /* next control stream */
93 struct pppstat stats; /* statistics */
95 kstat_t *kstats; /* stats for netstat */
99 /* Values for flags */
100 #define US_PRIV 1 /* stream was opened by superuser */
101 #define US_CONTROL 2 /* stream is a control stream */
102 #define US_BLOCKED 4 /* flow ctrl has blocked lower write stream */
103 #define US_LASTMOD 8 /* no PPP modules below us */
105 static upperstr_t *minor_devs = NULL;
106 static upperstr_t *ppas = NULL;
109 static int ppp_identify __P((dev_info_t *));
110 static int ppp_attach __P((dev_info_t *, ddi_attach_cmd_t));
111 static int ppp_detach __P((dev_info_t *, ddi_detach_cmd_t));
112 static int ppp_devinfo __P((dev_info_t *, ddi_info_cmd_t, void *, void **));
114 static int pppopen __P((queue_t *, dev_t *, int, int, cred_t *));
115 static int pppclose __P((queue_t *, int, cred_t *));
116 static int pppuwput __P((queue_t *, mblk_t *));
117 static int pppursrv __P((queue_t *));
118 static int pppuwsrv __P((queue_t *));
119 static int ppplrput __P((queue_t *, mblk_t *));
120 static int ppplwput __P((queue_t *, mblk_t *));
121 static int ppplrsrv __P((queue_t *));
122 static int ppplwsrv __P((queue_t *));
123 static void dlpi_request __P((queue_t *, mblk_t *, upperstr_t *));
124 static void dlpi_error __P((queue_t *, int, int, int));
125 static void dlpi_ok __P((queue_t *, int));
126 static int send_data __P((mblk_t *, upperstr_t *));
127 static void new_ppa __P((queue_t *, mblk_t *));
128 static void attach_ppa __P((queue_t *, mblk_t *));
129 static void detach_ppa __P((queue_t *, mblk_t *));
130 static upperstr_t *find_dest __P((upperstr_t *, int));
131 static int putctl2 __P((queue_t *, int, int, int));
132 static int putctl4 __P((queue_t *, int, int, int));
134 static struct module_info ppp_info = {
135 0xb1a6, "ppp", 0, 512, 512, 128
138 static struct qinit pppurint = {
139 NULL, pppursrv, pppopen, pppclose, NULL, &ppp_info, NULL
142 static struct qinit pppuwint = {
143 pppuwput, pppuwsrv, NULL, NULL, NULL, &ppp_info, NULL
146 static struct qinit ppplrint = {
147 ppplrput, ppplrsrv, NULL, NULL, NULL, &ppp_info, NULL
150 static struct qinit ppplwint = {
151 ppplwput, ppplwsrv, NULL, NULL, NULL, &ppp_info, NULL
154 static struct streamtab pppinfo = {
155 &pppurint, &pppuwint,
160 static dev_info_t *ppp_dip;
162 static struct cb_ops cb_ppp_ops = {
163 nulldev, nulldev, nodev, nodev, /* cb_open, ... */
164 nodev, nodev, nodev, nodev, /* cb_dump, ... */
165 nodev, nodev, nodev, nochpoll, /* cb_devmap, ... */
166 ddi_prop_op, /* cb_prop_op */
167 &pppinfo, /* cb_stream */
168 D_NEW|D_MP|D_MTQPAIR|D_MTOUTPERIM|D_MTOCEXCL /* cb_flag */
171 static struct dev_ops ppp_ops = {
172 DEVO_REV, /* devo_rev */
174 ppp_devinfo, /* devo_getinfo */
175 ppp_identify, /* devo_identify */
176 nulldev, /* devo_probe */
177 ppp_attach, /* devo_attach */
178 ppp_detach, /* devo_detach */
179 nodev, /* devo_reset */
180 &cb_ppp_ops, /* devo_cb_ops */
181 NULL /* devo_bus_ops */
185 * Module linkage information
188 static struct modldrv modldrv = {
189 &mod_driverops, /* says this is a pseudo driver */
190 "PPP-2.2 multiplexing driver",
191 &ppp_ops /* driver ops */
194 static struct modlinkage modlinkage = {
203 return mod_install(&modlinkage);
209 return mod_remove(&modlinkage);
216 return mod_info(&modlinkage, mip);
223 return strcmp(ddi_get_name(dip), "ppp") == 0? DDI_IDENTIFIED:
230 ddi_attach_cmd_t cmd;
233 if (cmd != DDI_ATTACH)
235 if (ddi_create_minor_node(dip, "ppp", S_IFCHR, 0, DDI_PSEUDO, CLONE_DEV)
237 ddi_remove_minor_node(dip, NULL);
246 ddi_detach_cmd_t cmd;
248 ddi_remove_minor_node(dip, NULL);
253 ppp_devinfo(dip, cmd, arg, result)
263 case DDI_INFO_DEVT2DEVINFO:
267 *result = (void *) ppp_dip;
269 case DDI_INFO_DEVT2INSTANCE:
281 # define qprocsoff(q)
282 # define canputnext(q) canput((q)->q_next)
283 # define qwriter(q, mp, func, scope) (func)((q), (mp))
287 pppopen(q, devp, oflag, sflag, credp)
298 return 0; /* device is already open */
300 if (sflag == CLONEOPEN) {
302 for (prevp = &minor_devs; (up = *prevp) != 0; prevp = &up->nextmn) {
308 mn = getminor(*devp);
309 for (prevp = &minor_devs; (up = *prevp) != 0; prevp = &up->nextmn) {
314 /* this can't happen */
315 q->q_ptr = WR(q)->q_ptr = up;
321 * Construct a new minor node.
323 up = (upperstr_t *) kmem_zalloc(sizeof(upperstr_t), KM_SLEEP);
325 cmn_err(CE_CONT, "pppopen: out of kernel memory\n");
331 *devp = makedevice(getmajor(*devp), mn);
333 if (drv_priv(credp) == 0)
334 up->flags |= US_PRIV;
335 up->state = DL_UNATTACHED;
346 pppclose(q, flag, credp)
351 upperstr_t *up, **upp;
352 upperstr_t *as, *asnext;
357 up = (upperstr_t *) q->q_ptr;
358 if (up->flags & US_CONTROL) {
360 * This stream represents a PPA:
361 * For all streams attached to the PPA, clear their
362 * references to this PPA.
363 * Then remove this PPA from the list of PPAs.
365 for (as = up->next; as != 0; as = asnext) {
369 if (as->flags & US_BLOCKED) {
370 as->flags &= ~US_BLOCKED;
371 flushq(WR(as->q), FLUSHDATA);
374 for (upp = &ppas; *upp != 0; upp = &(*upp)->nextppa)
382 * If this stream is attached to a PPA,
383 * remove it from the PPA's list.
385 if ((as = up->ppa) != 0) {
386 for (; as->next != 0; as = as->next)
387 if (as->next == up) {
395 kstat_delete(up->kstats);
400 for (prevp = &minor_devs; *prevp != 0; prevp = &up->nextmn) {
406 kmem_free(up, sizeof(upperstr_t));
412 * A message from on high. We do one of three things:
414 * - put the message on the lower write stream
415 * - queue it for our service routine
422 upperstr_t *us, *usnext, *ppa;
429 us = (upperstr_t *) q->q_ptr;
430 switch (mp->b_datap->db_type) {
433 dlpi_request(q, mp, us);
437 if ((us->flags & US_CONTROL) == 0
438 || msgdsize(mp) > us->mtu + PPP_HDRLEN) {
440 cmn_err(CE_CONT, "pppuwput: junk data len=%d\n", msgdsize(mp));
445 if (!send_data(mp, us))
450 iop = (struct iocblk *) mp->b_rptr;
452 switch (iop->ioc_cmd) {
454 if ((us->flags & US_CONTROL) == 0 || us->lowerq != 0)
456 lb = (struct linkblk *) mp->b_cont->b_rptr;
457 us->lowerq = lq = lb->l_qbot;
462 us->flags &= ~US_LASTMOD;
463 /* Unblock upper streams which now feed this lower stream. */
465 /* Send useful information down to the modules which
466 are now linked below us. */
467 putctl2(lq, M_CTL, PPPCTL_UNIT, us->ppa_id);
468 putctl4(lq, M_CTL, PPPCTL_MRU, us->mru);
469 putctl4(lq, M_CTL, PPPCTL_MTU, us->mtu);
473 lb = (struct linkblk *) mp->b_cont->b_rptr;
475 if (us->lowerq != lb->l_qbot)
476 cmn_err(CE_CONT, "ppp unlink: lowerq=%x qbot=%x\n",
477 us->lowerq, lb->l_qbot);
482 /* Unblock streams which now feed back up the control stream. */
487 if (us->flags & US_CONTROL)
489 if ((us->flags & US_PRIV) == 0) {
493 /* Arrange to return an int */
494 if ((mq = mp->b_cont) == 0
495 || mq->b_datap->db_lim - mq->b_rptr < sizeof(int)) {
496 mq = allocb(sizeof(int), BPRI_HI);
506 iop->ioc_count = sizeof(int);
507 mq->b_wptr = mq->b_rptr + sizeof(int);
508 qwriter(q, mp, new_ppa, PERIM_OUTER);
513 /* like dlpi_attach, for programs which can't write to
514 the stream (like pppstats) */
515 if (iop->ioc_count != sizeof(int) || us->ppa != 0)
517 n = *(int *)mp->b_cont->b_rptr;
518 for (ppa = ppas; ppa != 0; ppa = ppa->nextppa)
519 if (ppa->ppa_id == n)
524 qwriter(q, NULL, attach_ppa, PERIM_OUTER);
528 if (iop->ioc_count != sizeof(int) || (us->flags & US_CONTROL) == 0)
530 n = *(int *)mp->b_cont->b_rptr;
531 if (n <= 0 || n > PPP_MAXMTU)
537 putctl4(us->lowerq, M_CTL, PPPCTL_MRU, n);
543 if (iop->ioc_count != sizeof(int) || (us->flags & US_CONTROL) == 0)
545 n = *(int *)mp->b_cont->b_rptr;
546 if (n <= 0 || n > PPP_MAXMTU)
552 putctl4(us->lowerq, M_CTL, PPPCTL_MTU, n);
558 us->flags |= US_LASTMOD;
563 if (us->ppa == 0 || us->ppa->lowerq == 0)
566 switch (iop->ioc_cmd) {
569 if (us->flags & US_LASTMOD) {
573 putnext(us->ppa->lowerq, mp);
576 if (us->flags & US_PRIV)
577 putnext(us->ppa->lowerq, mp);
580 cmn_err(CE_CONT, "ppp ioctl %x rejected\n", iop->ioc_cmd);
590 iop->ioc_error = error;
591 mp->b_datap->db_type = M_IOCNAK;
593 } else if (error == 0) {
594 mp->b_datap->db_type = M_IOCACK;
600 if (*mp->b_rptr & FLUSHW)
601 flushq(q, FLUSHDATA);
602 if (*mp->b_rptr & FLUSHR) {
603 *mp->b_rptr &= ~FLUSHW;
617 dlpi_request(q, mp, us)
622 union DL_primitives *d = (union DL_primitives *) mp->b_rptr;
623 int size = mp->b_wptr - mp->b_rptr;
625 upperstr_t *ppa, *os;
630 switch (d->dl_primitive) {
632 if (size < sizeof(dl_info_req_t))
634 if ((reply = allocb(sizeof(dl_info_ack_t), BPRI_HI)) == 0)
635 break; /* should do bufcall */
636 reply->b_datap->db_type = M_PCPROTO;
637 info = (dl_info_ack_t *) reply->b_wptr;
638 reply->b_wptr += sizeof(dl_info_ack_t);
639 bzero((caddr_t) info, sizeof(dl_info_ack_t));
640 info->dl_primitive = DL_INFO_ACK;
641 info->dl_max_sdu = PPP_MAXMTU;
642 info->dl_min_sdu = 1;
643 info->dl_addr_length = sizeof(ulong);
645 info->dl_mac_type = DL_OTHER;
647 info->dl_mac_type = DL_HDLC; /* a lie */
649 info->dl_current_state = us->state;
650 info->dl_service_mode = DL_CLDLS;
651 info->dl_provider_style = DL_STYLE2;
652 #if DL_CURRENT_VERSION >= 2
653 info->dl_sap_length = sizeof(ulong);
654 info->dl_version = DL_CURRENT_VERSION;
660 if (size < sizeof(dl_attach_req_t))
662 if (us->state != DL_UNATTACHED || us->ppa != 0) {
663 dlpi_error(q, DL_ATTACH_REQ, DL_OUTSTATE, 0);
666 for (ppa = ppas; ppa != 0; ppa = ppa->nextppa)
667 if (ppa->ppa_id == d->attach_req.dl_ppa)
670 dlpi_error(q, DL_ATTACH_REQ, DL_BADPPA, 0);
674 qwriter(q, mp, attach_ppa, PERIM_OUTER);
678 if (size < sizeof(dl_detach_req_t))
680 if (us->state != DL_UNBOUND || us->ppa == 0) {
681 dlpi_error(q, DL_DETACH_REQ, DL_OUTSTATE, 0);
684 qwriter(q, mp, detach_ppa, PERIM_OUTER);
688 if (size < sizeof(dl_bind_req_t))
690 if (us->state != DL_UNBOUND || us->ppa == 0) {
691 dlpi_error(q, DL_BIND_REQ, DL_OUTSTATE, 0);
694 if (d->bind_req.dl_service_mode != DL_CLDLS) {
695 dlpi_error(q, DL_BIND_REQ, DL_UNSUPPORTED, 0);
699 /* saps must be valid PPP network protocol numbers,
700 except that we accept ETHERTYPE_IP in place of PPP_IP. */
701 sap = d->bind_req.dl_sap;
704 cmn_err(CE_CONT, "ppp bind %x\n", sap);
706 if (sap == ETHERTYPE_IP)
708 if (sap < 0x21 || sap > 0x3fff || (sap & 0x101) != 1) {
709 dlpi_error(q, DL_BIND_REQ, DL_BADADDR, 0);
713 /* check that no other stream is bound to this sap already. */
714 for (os = us->ppa; os != 0; os = os->next)
718 dlpi_error(q, DL_BIND_REQ, DL_NOADDR, 0);
725 if ((reply = allocb(sizeof(dl_bind_ack_t) + sizeof(ulong),
727 break; /* should do bufcall */
728 ackp = (dl_bind_ack_t *) reply->b_wptr;
729 reply->b_wptr += sizeof(dl_bind_ack_t) + sizeof(ulong);
730 reply->b_datap->db_type = M_PCPROTO;
731 bzero((caddr_t) ackp, sizeof(dl_bind_ack_t));
732 ackp->dl_primitive = DL_BIND_ACK;
734 ackp->dl_addr_length = sizeof(ulong);
735 ackp->dl_addr_offset = sizeof(dl_bind_ack_t);
736 *(ulong *)(ackp+1) = sap;
741 if (size < sizeof(dl_unbind_req_t))
743 if (us->state != DL_IDLE) {
744 dlpi_error(q, DL_UNBIND_REQ, DL_OUTSTATE, 0);
748 us->state = DL_UNBOUND;
749 dlpi_ok(q, DL_UNBIND_REQ);
752 case DL_UNITDATA_REQ:
753 if (size < sizeof(dl_unitdata_req_t))
755 if (us->state != DL_IDLE) {
756 dlpi_error(q, DL_UNITDATA_REQ, DL_OUTSTATE, 0);
760 cmn_err(CE_CONT, "ppp: in state dl_idle but ppa == 0?\n");
763 len = mp->b_cont == 0? 0: msgdsize(mp->b_cont);
764 if (len > us->ppa->mtu) {
766 cmn_err(CE_CONT, "dlpi data too large (%d > %d)\n", len, us->mtu);
770 /* this assumes PPP_HDRLEN <= sizeof(dl_unitdata_req_t) */
771 if (mp->b_datap->db_ref > 1) {
772 np = allocb(PPP_HDRLEN, BPRI_HI);
775 np->b_cont = mp->b_cont;
780 mp->b_datap->db_type = M_DATA;
781 /* XXX should use dl_dest_addr_offset/length here,
782 but we would have to translate ETHERTYPE_IP -> PPP_IP */
783 mp->b_wptr = mp->b_rptr + PPP_HDRLEN;
784 mp->b_rptr[0] = PPP_ALLSTATIONS;
785 mp->b_rptr[1] = PPP_UI;
786 mp->b_rptr[2] = us->sap >> 8;
787 mp->b_rptr[3] = us->sap;
788 if (!send_data(mp, us))
792 #if DL_CURRENT_VERSION >= 2
793 case DL_SUBS_BIND_REQ:
794 case DL_SUBS_UNBIND_REQ:
795 case DL_ENABMULTI_REQ:
796 case DL_DISABMULTI_REQ:
797 case DL_PROMISCON_REQ:
798 case DL_PROMISCOFF_REQ:
799 case DL_SET_PHYS_ADDR_REQ:
802 case DL_REPLY_UPDATE_REQ:
804 case DL_DATA_ACK_REQ:
808 dlpi_error(q, d->dl_primitive, DL_NOTSUPPORTED, 0);
812 case DL_DISCONNECT_REQ:
815 dlpi_error(q, d->dl_primitive, DL_OUTSTATE, 0);
819 dlpi_error(q, d->dl_primitive, DL_BADQOSTYPE, 0);
822 #if DL_CURRENT_VERSION >= 2
829 cmn_err(CE_CONT, "ppp: unknown dlpi prim 0x%x\n", d->dl_primitive);
832 dlpi_error(q, d->dl_primitive, DL_BADPRIM, 0);
839 dlpi_error(q, prim, err, uerr)
844 dl_error_ack_t *errp;
846 reply = allocb(sizeof(dl_error_ack_t), BPRI_HI);
848 return; /* XXX should do bufcall */
849 reply->b_datap->db_type = M_PCPROTO;
850 errp = (dl_error_ack_t *) reply->b_wptr;
851 reply->b_wptr += sizeof(dl_error_ack_t);
852 errp->dl_primitive = DL_ERROR_ACK;
853 errp->dl_error_primitive = prim;
854 errp->dl_errno = err;
855 errp->dl_unix_errno = uerr;
867 reply = allocb(sizeof(dl_ok_ack_t), BPRI_HI);
869 return; /* XXX should do bufcall */
870 reply->b_datap->db_type = M_PCPROTO;
871 okp = (dl_ok_ack_t *) reply->b_wptr;
872 reply->b_wptr += sizeof(dl_ok_ack_t);
873 okp->dl_primitive = DL_OK_ACK;
874 okp->dl_correct_primitive = prim;
886 if (us->flags & US_BLOCKED)
893 if ((q = ppa->lowerq) == 0) {
894 /* try to send it up the control stream */
895 if (canputnext(ppa->q)) {
900 if (canputnext(ppa->lowerq)) {
902 * The lower write queue's put procedure just updates counters
903 * and does a putnext. We call it in order to enter the lower
904 * queues' perimeter so that the counter updates are serialized.
906 put(ppa->lowerq, mp);
910 us->flags |= US_BLOCKED;
915 * Allocate a new PPA id and link this stream into the list of PPAs.
916 * This procedure is called with an exclusive lock on all queues in
924 upperstr_t *us, **usp;
929 while ((us = *usp) != 0 && ppa_id == us->ppa_id) {
933 us = (upperstr_t *) q->q_ptr;
939 us->flags |= US_CONTROL;
945 if (us->kstats == 0) {
948 sprintf(unit, "ppp%d", us->ppa->ppa_id);
949 us->kstats = kstat_create("ppp", us->ppa->ppa_id, unit,
950 "net", KSTAT_TYPE_NAMED, 4, 0);
951 if (us->kstats != 0) {
952 kstat_named_t *kn = KSTAT_NAMED_PTR(us->kstats);
954 strcpy(kn[0].name, "ipackets");
955 kn[0].data_type = KSTAT_DATA_ULONG;
956 strcpy(kn[1].name, "ierrors");
957 kn[1].data_type = KSTAT_DATA_ULONG;
958 strcpy(kn[2].name, "opackets");
959 kn[2].data_type = KSTAT_DATA_ULONG;
960 strcpy(kn[3].name, "oerrors");
961 kn[3].data_type = KSTAT_DATA_ULONG;
962 kstat_install(us->kstats);
967 *(int *)mp->b_cont->b_rptr = ppa_id;
968 mp->b_datap->db_type = M_IOCACK;
979 us = (upperstr_t *) q->q_ptr;
980 us->state = DL_UNBOUND;
981 for (t = us->ppa; t->next != 0; t = t->next)
986 dlpi_ok(q, DL_ATTACH_REQ);
996 us = (upperstr_t *) q->q_ptr;
997 for (t = us->ppa; t->next != 0; t = t->next)
1004 us->state = DL_UNATTACHED;
1005 dlpi_ok(q, DL_DETACH_REQ);
1013 struct lowerstr *ls;
1017 us = (upperstr_t *) q->q_ptr;
1018 while ((mp = getq(q)) != 0) {
1019 if (!send_data(mp, us)) {
1025 us->flags &= ~US_BLOCKED;
1037 if (ppa != 0) { /* why wouldn't it? */
1038 ppa->stats.ppp_opackets++;
1039 ppa->stats.ppp_obytes += msgdsize(mp);
1040 if (ppa->kstats != 0)
1041 KSTAT_NAMED_PTR(ppa->kstats)[2].value.ul++;
1054 * Flow control has back-enabled this stream:
1055 * enable the write service procedures of all upper
1056 * streams feeding this lower stream.
1058 for (us = (upperstr_t *) q->q_ptr; us != NULL; us = us->next)
1059 if (us->flags & US_BLOCKED)
1068 upperstr_t *us, *as;
1070 dl_unitdata_ind_t *ud;
1074 * If this is a control stream and we don't have a lower queue attached,
1075 * run the write service routines of other streams attached to this PPA.
1077 us = (upperstr_t *) q->q_ptr;
1078 if (us->flags & US_CONTROL) {
1081 * If there is no lower queue attached, run the write service
1082 * routines of other upper streams attached to this PPA.
1084 if (us->lowerq == 0) {
1087 if (as->flags & US_BLOCKED)
1094 * A network protocol stream. Put a DLPI header on each
1095 * packet and send it on.
1097 while ((mp = getq(q)) != 0) {
1098 if (!canputnext(q)) {
1102 proto = PPP_PROTOCOL(mp->b_rptr);
1103 mp->b_rptr += PPP_HDRLEN;
1104 hdr = allocb(sizeof(dl_unitdata_ind_t) + 2 * sizeof(ulong),
1107 /* XXX should put it back and use bufcall */
1111 ud = (dl_unitdata_ind_t *) hdr->b_wptr;
1112 hdr->b_wptr += sizeof(dl_unitdata_ind_t) + 2 * sizeof(ulong);
1114 ud->dl_primitive = DL_UNITDATA_IND;
1115 ud->dl_dest_addr_length = sizeof(ulong);
1116 ud->dl_dest_addr_offset = sizeof(dl_unitdata_ind_t);
1117 ud->dl_src_addr_length = sizeof(ulong);
1118 ud->dl_src_addr_offset = ud->dl_dest_addr_offset + sizeof(ulong);
1119 #if DL_CURRENT_VERSION >= 2
1120 ud->dl_group_address = 0;
1122 /* Send the DLPI client the data with the SAP they requested,
1123 (e.g. ETHERTYPE_IP) rather than the PPP protocol number
1125 ((ulong *)(ud + 1))[0] = us->req_sap; /* dest SAP */
1126 ((ulong *)(ud + 1))[1] = us->req_sap; /* src SAP */
1134 find_dest(ppa, proto)
1140 for (us = ppa->next; us != 0; us = us->next)
1141 if (proto == us->sap)
1151 upperstr_t *ppa, *us;
1156 ppa = (upperstr_t *) q->q_ptr;
1159 cmn_err(CE_CONT, "ppplrput: q = %x, ppa = 0??\n", q);
1164 switch (mp->b_datap->db_type) {
1166 if (*mp->b_rptr & FLUSHW) {
1167 *mp->b_rptr &= ~FLUSHR;
1174 switch (*mp->b_rptr) {
1176 if (ppa->kstats != 0) {
1177 KSTAT_NAMED_PTR(ppa->kstats)[1].value.ul++;
1179 ppa->stats.ppp_ierrors++;
1182 if (ppa->kstats != 0) {
1183 KSTAT_NAMED_PTR(ppa->kstats)[3].value.ul++;
1185 ppa->stats.ppp_oerrors++;
1192 if (mp->b_datap->db_type == M_DATA) {
1194 if (mp->b_wptr - mp->b_rptr < PPP_HDRLEN) {
1195 np = msgpullup(mp, PPP_HDRLEN);
1199 cmn_err(CE_CONT, "ppp_lrput: msgpullup failed (len=%d)\n",
1206 ppa->stats.ppp_ipackets++;
1207 ppa->stats.ppp_ibytes += len;
1208 if (ppa->kstats != 0) {
1209 KSTAT_NAMED_PTR(ppa->kstats)[0].value.ul++;
1211 proto = PPP_PROTOCOL(mp->b_rptr);
1212 if (proto < 0x8000 && (us = find_dest(ppa, proto)) != 0) {
1214 * A data packet for some network protocol.
1215 * Queue it on the upper stream for that protocol.
1225 * A control frame, a frame for an unknown protocol,
1226 * or some other message type.
1227 * Send it up to pppd via the control stream.
1229 if (queclass(mp) == QPCTL || canputnext(ppa->q))
1230 putnext(ppa->q, mp);
1244 upperstr_t *ppa, *us;
1248 * Packets only get queued here for flow control reasons.
1250 ppa = (upperstr_t *) q->q_ptr;
1251 while ((mp = getq(q)) != 0) {
1252 if (mp->b_datap->db_type == M_DATA
1253 && (proto = PPP_PROTOCOL(mp->b_rptr)) < 0x8000
1254 && (us = find_dest(ppa, proto)) != 0) {
1262 if (canputnext(ppa->q))
1263 putnext(ppa->q, mp);
1274 putctl2(q, type, code, val)
1276 int type, code, val;
1280 mp = allocb(2, BPRI_HI);
1283 mp->b_datap->db_type = type;
1284 mp->b_wptr[0] = code;
1285 mp->b_wptr[1] = val;
1292 putctl4(q, type, code, val)
1294 int type, code, val;
1298 mp = allocb(4, BPRI_HI);
1301 mp->b_datap->db_type = type;
1302 mp->b_wptr[0] = code;
1303 ((short *)mp->b_wptr)[1] = val;