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.7 1995/10/27 03:55:56 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 <sys/socket.h>
52 #include <sys/sockio.h>
54 #include <netinet/in.h>
56 #include <net/ppp_defs.h>
57 #include <net/pppio.h>
66 * The IP module uses this SAP value for IP packets.
69 #define ETHERTYPE_IP 0x800
73 #define PPP_MAXMTU 65535
77 * Private information; one per upper stream.
79 typedef struct upperstr {
80 minor_t mn; /* minor device number */
81 struct upperstr *nextmn; /* next minor device */
82 queue_t *q; /* read q associated with this upper stream */
83 int flags; /* flag bits, see below */
84 int state; /* current DLPI state */
85 int sap; /* service access point */
86 int req_sap; /* which SAP the DLPI client requested */
87 struct upperstr *ppa; /* control stream for our ppa */
88 struct upperstr *next; /* next stream for this ppa */
89 uint ioc_id; /* last ioctl ID for this stream */
91 * There is exactly one control stream for each PPA.
92 * The following fields are only used for control streams.
95 queue_t *lowerq; /* write queue attached below this PPA */
96 struct upperstr *nextppa; /* next control stream */
99 struct pppstat stats; /* statistics */
101 kstat_t *kstats; /* stats for netstat */
104 char ifname[IFNAMSIZ];
105 struct ifstats ifstats;
109 /* Values for flags */
110 #define US_PRIV 1 /* stream was opened by superuser */
111 #define US_CONTROL 2 /* stream is a control stream */
112 #define US_BLOCKED 4 /* flow ctrl has blocked lower write stream */
113 #define US_LASTMOD 8 /* no PPP modules below us */
114 #define US_DBGLOG 0x10 /* log various occurrences */
116 static upperstr_t *minor_devs = NULL;
117 static upperstr_t *ppas = NULL;
120 static int ppp_identify __P((dev_info_t *));
121 static int ppp_attach __P((dev_info_t *, ddi_attach_cmd_t));
122 static int ppp_detach __P((dev_info_t *, ddi_detach_cmd_t));
123 static int ppp_devinfo __P((dev_info_t *, ddi_info_cmd_t, void *, void **));
125 static int pppopen __P((queue_t *, dev_t *, int, int, cred_t *));
126 static int pppclose __P((queue_t *, int, cred_t *));
127 static int pppuwput __P((queue_t *, mblk_t *));
128 static int pppursrv __P((queue_t *));
129 static int pppuwsrv __P((queue_t *));
130 static int ppplrput __P((queue_t *, mblk_t *));
131 static int ppplwput __P((queue_t *, mblk_t *));
132 static int ppplrsrv __P((queue_t *));
133 static int ppplwsrv __P((queue_t *));
134 static void dlpi_request __P((queue_t *, mblk_t *, upperstr_t *));
135 static void dlpi_error __P((queue_t *, int, int, int));
136 static void dlpi_ok __P((queue_t *, int));
137 static int send_data __P((mblk_t *, upperstr_t *));
138 static void new_ppa __P((queue_t *, mblk_t *));
139 static void attach_ppa __P((queue_t *, mblk_t *));
140 static void detach_ppa __P((queue_t *, mblk_t *));
141 static void debug_dump __P((queue_t *, mblk_t *));
142 static upperstr_t *find_dest __P((upperstr_t *, int));
143 static int putctl2 __P((queue_t *, int, int, int));
144 static int putctl4 __P((queue_t *, int, int, int));
146 static struct module_info ppp_info = {
147 0xb1a6, "ppp", 0, 512, 512, 128
150 static struct qinit pppurint = {
151 NULL, pppursrv, pppopen, pppclose, NULL, &ppp_info, NULL
154 static struct qinit pppuwint = {
155 pppuwput, pppuwsrv, NULL, NULL, NULL, &ppp_info, NULL
158 static struct qinit ppplrint = {
159 ppplrput, ppplrsrv, NULL, NULL, NULL, &ppp_info, NULL
162 static struct qinit ppplwint = {
163 ppplwput, ppplwsrv, NULL, NULL, NULL, &ppp_info, NULL
167 extern struct ifstats *ifstats;
172 struct streamtab pppinfo = {
173 &pppurint, &pppuwint,
178 static dev_info_t *ppp_dip;
180 static struct cb_ops cb_ppp_ops = {
181 nulldev, nulldev, nodev, nodev, /* cb_open, ... */
182 nodev, nodev, nodev, nodev, /* cb_dump, ... */
183 nodev, nodev, nodev, nochpoll, /* cb_devmap, ... */
184 ddi_prop_op, /* cb_prop_op */
185 &pppinfo, /* cb_stream */
186 D_NEW|D_MP|D_MTQPAIR|D_MTOUTPERIM|D_MTOCEXCL /* cb_flag */
189 static struct dev_ops ppp_ops = {
190 DEVO_REV, /* devo_rev */
192 ppp_devinfo, /* devo_getinfo */
193 ppp_identify, /* devo_identify */
194 nulldev, /* devo_probe */
195 ppp_attach, /* devo_attach */
196 ppp_detach, /* devo_detach */
197 nodev, /* devo_reset */
198 &cb_ppp_ops, /* devo_cb_ops */
199 NULL /* devo_bus_ops */
203 * Module linkage information
206 static struct modldrv modldrv = {
207 &mod_driverops, /* says this is a pseudo driver */
208 "PPP-2.2 multiplexing driver",
209 &ppp_ops /* driver ops */
212 static struct modlinkage modlinkage = {
221 return mod_install(&modlinkage);
227 return mod_remove(&modlinkage);
234 return mod_info(&modlinkage, mip);
241 return strcmp(ddi_get_name(dip), "ppp") == 0? DDI_IDENTIFIED:
248 ddi_attach_cmd_t cmd;
251 if (cmd != DDI_ATTACH)
253 if (ddi_create_minor_node(dip, "ppp", S_IFCHR, 0, DDI_PSEUDO, CLONE_DEV)
255 ddi_remove_minor_node(dip, NULL);
264 ddi_detach_cmd_t cmd;
266 ddi_remove_minor_node(dip, NULL);
271 ppp_devinfo(dip, cmd, arg, result)
281 case DDI_INFO_DEVT2DEVINFO:
285 *result = (void *) ppp_dip;
287 case DDI_INFO_DEVT2INSTANCE:
298 #define put(q, mp) ((*(q)->q_qinfo->qi_putp)((q), (mp)))
300 # define qprocsoff(q)
301 # define canputnext(q) canput((q)->q_next)
302 # define qwriter(q, mp, func, scope) (func)((q), (mp))
306 pppopen(q, devp, oflag, sflag, credp)
317 return 0; /* device is already open */
319 if (sflag == CLONEOPEN) {
321 for (prevp = &minor_devs; (up = *prevp) != 0; prevp = &up->nextmn) {
327 mn = getminor(*devp);
328 for (prevp = &minor_devs; (up = *prevp) != 0; prevp = &up->nextmn) {
333 /* this can't happen */
334 q->q_ptr = WR(q)->q_ptr = up;
340 * Construct a new minor node.
342 up = (upperstr_t *) kmem_zalloc(sizeof(upperstr_t), KM_SLEEP);
344 cmn_err(CE_CONT, "pppopen: out of kernel memory\n");
350 *devp = makedevice(getmajor(*devp), mn);
352 if (drv_priv(credp) == 0)
353 up->flags |= US_PRIV;
354 up->state = DL_UNATTACHED;
356 up->ifflags = IFF_UP | IFF_POINTOPOINT;
368 pppclose(q, flag, credp)
373 upperstr_t *up, **upp;
374 upperstr_t *as, *asnext;
379 up = (upperstr_t *) q->q_ptr;
380 if (up->flags & US_DBGLOG)
381 cmn_err(CE_CONT, "ppp/%d: close, flags=%x\n", up->mn, up->flags);
384 if (up->flags & US_CONTROL) {
386 struct ifstats *ifp, *pifp;
389 * This stream represents a PPA:
390 * For all streams attached to the PPA, clear their
391 * references to this PPA.
392 * Then remove this PPA from the list of PPAs.
394 for (as = up->next; as != 0; as = asnext) {
398 if (as->flags & US_BLOCKED) {
399 as->flags &= ~US_BLOCKED;
400 flushq(WR(as->q), FLUSHDATA);
403 for (upp = &ppas; *upp != 0; upp = &(*upp)->nextppa)
409 /* Remove the statistics from the active list. */
410 for (ifp = ifstats, pifp = 0; ifp; ifp = ifp->ifs_next) {
411 if (ifp == &up->ifstats) {
413 pifp->ifs_next = ifp->ifs_next;
415 ifstats = ifp->ifs_next;
423 * If this stream is attached to a PPA,
424 * remove it from the PPA's list.
426 if ((as = up->ppa) != 0) {
427 for (; as->next != 0; as = as->next)
428 if (as->next == up) {
437 kstat_delete(up->kstats);
443 for (prevp = &minor_devs; *prevp != 0; prevp = &(*prevp)->nextmn) {
449 kmem_free(up, sizeof(upperstr_t));
455 * A message from on high. We do one of three things:
457 * - put the message on the lower write stream
458 * - queue it for our service routine
465 upperstr_t *us, *usnext, *ppa;
476 us = (upperstr_t *) q->q_ptr;
477 switch (mp->b_datap->db_type) {
480 dlpi_request(q, mp, us);
484 if (us->flags & US_DBGLOG)
485 cmn_err(CE_CONT, "ppp/%d: uwput M_DATA len=%d flags=%x\n",
486 us->mn, msgdsize(mp), us->flags);
487 if ((us->flags & US_CONTROL) == 0
488 || msgdsize(mp) > us->mtu + PPP_HDRLEN) {
490 cmn_err(CE_CONT, "pppuwput: junk data len=%d\n", msgdsize(mp));
495 if (!send_data(mp, us))
500 iop = (struct iocblk *) mp->b_rptr;
502 if (us->flags & US_DBGLOG)
503 cmn_err(CE_CONT, "ppp/%d: ioctl %x count=%d\n",
504 us->mn, iop->ioc_cmd, iop->ioc_count);
505 switch (iop->ioc_cmd) {
507 if ((us->flags & US_CONTROL) == 0 || us->lowerq != 0)
509 lb = (struct linkblk *) mp->b_cont->b_rptr;
510 us->lowerq = lq = lb->l_qbot;
516 us->flags &= ~US_LASTMOD;
517 /* Unblock upper streams which now feed this lower stream. */
519 /* Send useful information down to the modules which
520 are now linked below us. */
521 putctl2(lq, M_CTL, PPPCTL_UNIT, us->ppa_id);
522 putctl4(lq, M_CTL, PPPCTL_MRU, us->mru);
523 putctl4(lq, M_CTL, PPPCTL_MTU, us->mtu);
527 lb = (struct linkblk *) mp->b_cont->b_rptr;
529 if (us->lowerq != lb->l_qbot)
530 cmn_err(CE_CONT, "ppp unlink: lowerq=%x qbot=%x\n",
531 us->lowerq, lb->l_qbot);
536 /* Unblock streams which now feed back up the control stream. */
541 if (us->flags & US_CONTROL)
543 if ((us->flags & US_PRIV) == 0) {
547 /* Arrange to return an int */
548 if ((mq = mp->b_cont) == 0
549 || mq->b_datap->db_lim - mq->b_rptr < sizeof(int)) {
550 mq = allocb(sizeof(int), BPRI_HI);
560 iop->ioc_count = sizeof(int);
561 mq->b_wptr = mq->b_rptr + sizeof(int);
562 qwriter(q, mp, new_ppa, PERIM_OUTER);
567 /* like dlpi_attach, for programs which can't write to
568 the stream (like pppstats) */
569 if (iop->ioc_count != sizeof(int) || us->ppa != 0)
571 n = *(int *)mp->b_cont->b_rptr;
572 for (ppa = ppas; ppa != 0; ppa = ppa->nextppa)
573 if (ppa->ppa_id == n)
579 qwriter(q, mp, attach_ppa, PERIM_OUTER);
584 if (iop->ioc_count != sizeof(int) || (us->flags & US_CONTROL) == 0)
586 n = *(int *)mp->b_cont->b_rptr;
587 if (n <= 0 || n > PPP_MAXMTU)
593 putctl4(us->lowerq, M_CTL, PPPCTL_MRU, n);
599 if (iop->ioc_count != sizeof(int) || (us->flags & US_CONTROL) == 0)
601 n = *(int *)mp->b_cont->b_rptr;
602 if (n <= 0 || n > PPP_MAXMTU)
608 us->ifstats.ifs_mtu = n;
611 putctl4(us->lowerq, M_CTL, PPPCTL_MTU, n);
617 us->flags |= US_LASTMOD;
622 if (iop->ioc_count != sizeof(int))
624 n = *(int *)mp->b_cont->b_rptr;
625 if (n == PPPDBG_DUMP + PPPDBG_DRIVER) {
626 qwriter(q, NULL, debug_dump, PERIM_OUTER);
629 } else if (n == PPPDBG_LOG + PPPDBG_DRIVER) {
630 cmn_err(CE_CONT, "ppp/%d: debug log enabled\n", us->mn);
631 us->flags |= US_DBGLOG;
635 if (us->ppa == 0 || us->ppa->lowerq == 0)
637 putnext(us->ppa->lowerq, mp);
644 printf("SIOCSIFNAME\n");
645 /* Sent from IP down to us. Attach the ifstats structure. */
646 if (iop->ioc_count != sizeof(struct ifreq) || us->ppa == 0)
648 ifr = (struct ifreq *)mp->b_cont->b_rptr;
649 /* Find the unit number in the interface name. */
650 for (i = 0; i < IFNAMSIZ; i++) {
651 if (ifr->ifr_name[i] == 0 ||
652 (ifr->ifr_name[i] >= '0' &&
653 ifr->ifr_name[i] <= '9'))
656 us->ifname[i] = ifr->ifr_name[i];
660 /* Convert the unit number to binary. */
661 for (n = 0; i < IFNAMSIZ; i++) {
662 if (ifr->ifr_name[i] == 0) {
666 n = n * 10 + ifr->ifr_name[i] - '0';
670 /* Verify the ppa. */
671 if (us->ppa->ppa_id != n)
675 /* Set up the netstat block. */
676 strncpy (ppa->ifname, us->ifname, IFNAMSIZ);
678 ppa->ifstats.ifs_name = ppa->ifname;
679 ppa->ifstats.ifs_unit = n;
680 ppa->ifstats.ifs_active = us->state != DL_UNBOUND;
681 ppa->ifstats.ifs_mtu = ppa->mtu;
683 /* Link in statistics used by netstat. */
684 ppa->ifstats.ifs_next = ifstats;
685 ifstats = &ppa->ifstats;
692 printf("SIOCGIFFLAGS\n");
693 if (!(us->flags & US_CONTROL)) {
699 ((struct iocblk_in *)iop)->ioc_ifflags = us->ifflags;
704 printf("SIOCSIFFLAGS\n");
705 if (!(us->flags & US_CONTROL)) {
711 us->ifflags = ((struct iocblk_in *)iop)->ioc_ifflags;
716 printf("SIOCSIFADDR\n");
717 if (!(us->flags & US_CONTROL)) {
723 us->ifflags |= IFF_RUNNING;
724 ((struct iocblk_in *)iop)->ioc_ifflags |= IFF_RUNNING;
739 if (us->ppa == 0 || us->ppa->lowerq == 0)
741 us->ioc_id = iop->ioc_id;
743 switch (iop->ioc_cmd) {
746 if (us->flags & US_LASTMOD) {
750 putnext(us->ppa->lowerq, mp);
753 if (us->flags & US_PRIV)
754 putnext(us->ppa->lowerq, mp);
757 cmn_err(CE_CONT, "ppp ioctl %x rejected\n", iop->ioc_cmd);
767 iop->ioc_error = error;
768 mp->b_datap->db_type = M_IOCNAK;
770 } else if (error == 0) {
771 mp->b_datap->db_type = M_IOCACK;
777 if (us->flags & US_DBGLOG)
778 cmn_err(CE_CONT, "ppp/%d: flush %x\n", us->mn, *mp->b_rptr);
779 if (*mp->b_rptr & FLUSHW)
780 flushq(q, FLUSHDATA);
781 if (*mp->b_rptr & FLUSHR) {
782 *mp->b_rptr &= ~FLUSHW;
796 dlpi_request(q, mp, us)
801 union DL_primitives *d = (union DL_primitives *) mp->b_rptr;
802 int size = mp->b_wptr - mp->b_rptr;
804 upperstr_t *ppa, *os;
809 if (us->flags & US_DBGLOG)
810 cmn_err(CE_CONT, "ppp/%d: dlpi prim %x len=%d\n", us->mn,
811 d->dl_primitive, size);
812 switch (d->dl_primitive) {
814 if (size < sizeof(dl_info_req_t))
816 if ((reply = allocb(sizeof(dl_info_ack_t), BPRI_HI)) == 0)
817 break; /* should do bufcall */
818 reply->b_datap->db_type = M_PCPROTO;
819 info = (dl_info_ack_t *) reply->b_wptr;
820 reply->b_wptr += sizeof(dl_info_ack_t);
821 bzero((caddr_t) info, sizeof(dl_info_ack_t));
822 info->dl_primitive = DL_INFO_ACK;
823 info->dl_max_sdu = PPP_MAXMTU;
824 info->dl_min_sdu = 1;
825 info->dl_addr_length = sizeof(ulong);
827 info->dl_mac_type = DL_OTHER;
829 info->dl_mac_type = DL_HDLC; /* a lie */
831 info->dl_current_state = us->state;
832 info->dl_service_mode = DL_CLDLS;
833 info->dl_provider_style = DL_STYLE2;
834 #if DL_CURRENT_VERSION >= 2
835 info->dl_sap_length = sizeof(ulong);
836 info->dl_version = DL_CURRENT_VERSION;
842 if (size < sizeof(dl_attach_req_t))
844 if (us->state != DL_UNATTACHED || us->ppa != 0) {
845 dlpi_error(q, DL_ATTACH_REQ, DL_OUTSTATE, 0);
848 for (ppa = ppas; ppa != 0; ppa = ppa->nextppa)
849 if (ppa->ppa_id == d->attach_req.dl_ppa)
852 dlpi_error(q, DL_ATTACH_REQ, DL_BADPPA, 0);
856 qwriter(q, mp, attach_ppa, PERIM_OUTER);
860 if (size < sizeof(dl_detach_req_t))
862 if (us->state != DL_UNBOUND || us->ppa == 0) {
863 dlpi_error(q, DL_DETACH_REQ, DL_OUTSTATE, 0);
866 qwriter(q, mp, detach_ppa, PERIM_OUTER);
870 if (size < sizeof(dl_bind_req_t))
872 if (us->state != DL_UNBOUND || us->ppa == 0) {
873 dlpi_error(q, DL_BIND_REQ, DL_OUTSTATE, 0);
876 if (d->bind_req.dl_service_mode != DL_CLDLS) {
877 dlpi_error(q, DL_BIND_REQ, DL_UNSUPPORTED, 0);
881 /* saps must be valid PPP network protocol numbers,
882 except that we accept ETHERTYPE_IP in place of PPP_IP. */
883 sap = d->bind_req.dl_sap;
886 cmn_err(CE_CONT, "ppp bind %x\n", sap);
888 if (sap == ETHERTYPE_IP)
890 if (sap < 0x21 || sap > 0x3fff || (sap & 0x101) != 1) {
891 dlpi_error(q, DL_BIND_REQ, DL_BADADDR, 0);
895 /* check that no other stream is bound to this sap already. */
896 for (os = us->ppa; os != 0; os = os->next)
900 dlpi_error(q, DL_BIND_REQ, DL_NOADDR, 0);
907 if ((reply = allocb(sizeof(dl_bind_ack_t) + sizeof(ulong),
909 break; /* should do bufcall */
910 ackp = (dl_bind_ack_t *) reply->b_wptr;
911 reply->b_wptr += sizeof(dl_bind_ack_t) + sizeof(ulong);
912 reply->b_datap->db_type = M_PCPROTO;
913 bzero((caddr_t) ackp, sizeof(dl_bind_ack_t));
914 ackp->dl_primitive = DL_BIND_ACK;
916 ackp->dl_addr_length = sizeof(ulong);
917 ackp->dl_addr_offset = sizeof(dl_bind_ack_t);
918 *(ulong *)(ackp+1) = sap;
923 if (size < sizeof(dl_unbind_req_t))
925 if (us->state != DL_IDLE) {
926 dlpi_error(q, DL_UNBIND_REQ, DL_OUTSTATE, 0);
930 us->state = DL_UNBOUND;
932 us->ppa->ifstats.ifs_active = 0;
934 dlpi_ok(q, DL_UNBIND_REQ);
937 case DL_UNITDATA_REQ:
938 if (size < sizeof(dl_unitdata_req_t))
940 if (us->state != DL_IDLE) {
941 dlpi_error(q, DL_UNITDATA_REQ, DL_OUTSTATE, 0);
945 cmn_err(CE_CONT, "ppp: in state dl_idle but ppa == 0?\n");
948 len = mp->b_cont == 0? 0: msgdsize(mp->b_cont);
949 if (len > us->ppa->mtu) {
951 cmn_err(CE_CONT, "dlpi data too large (%d > %d)\n", len, us->mtu);
955 /* this assumes PPP_HDRLEN <= sizeof(dl_unitdata_req_t) */
956 if (mp->b_datap->db_ref > 1) {
957 np = allocb(PPP_HDRLEN, BPRI_HI);
960 np->b_cont = mp->b_cont;
965 mp->b_datap->db_type = M_DATA;
966 /* XXX should use dl_dest_addr_offset/length here,
967 but we would have to translate ETHERTYPE_IP -> PPP_IP */
968 mp->b_wptr = mp->b_rptr + PPP_HDRLEN;
969 mp->b_rptr[0] = PPP_ALLSTATIONS;
970 mp->b_rptr[1] = PPP_UI;
971 mp->b_rptr[2] = us->sap >> 8;
972 mp->b_rptr[3] = us->sap;
973 if (!send_data(mp, us))
977 #if DL_CURRENT_VERSION >= 2
978 case DL_SUBS_BIND_REQ:
979 case DL_SUBS_UNBIND_REQ:
980 case DL_ENABMULTI_REQ:
981 case DL_DISABMULTI_REQ:
982 case DL_PROMISCON_REQ:
983 case DL_PROMISCOFF_REQ:
984 case DL_PHYS_ADDR_REQ:
985 case DL_SET_PHYS_ADDR_REQ:
988 case DL_REPLY_UPDATE_REQ:
990 case DL_DATA_ACK_REQ:
994 dlpi_error(q, d->dl_primitive, DL_NOTSUPPORTED, 0);
998 case DL_DISCONNECT_REQ:
1001 dlpi_error(q, d->dl_primitive, DL_OUTSTATE, 0);
1005 dlpi_error(q, d->dl_primitive, DL_BADQOSTYPE, 0);
1008 #if DL_CURRENT_VERSION >= 2
1015 cmn_err(CE_CONT, "ppp: unknown dlpi prim 0x%x\n", d->dl_primitive);
1018 dlpi_error(q, d->dl_primitive, DL_BADPRIM, 0);
1025 dlpi_error(q, prim, err, uerr)
1027 int prim, err, uerr;
1030 dl_error_ack_t *errp;
1032 reply = allocb(sizeof(dl_error_ack_t), BPRI_HI);
1034 return; /* XXX should do bufcall */
1035 reply->b_datap->db_type = M_PCPROTO;
1036 errp = (dl_error_ack_t *) reply->b_wptr;
1037 reply->b_wptr += sizeof(dl_error_ack_t);
1038 errp->dl_primitive = DL_ERROR_ACK;
1039 errp->dl_error_primitive = prim;
1040 errp->dl_errno = err;
1041 errp->dl_unix_errno = uerr;
1053 reply = allocb(sizeof(dl_ok_ack_t), BPRI_HI);
1055 return; /* XXX should do bufcall */
1056 reply->b_datap->db_type = M_PCPROTO;
1057 okp = (dl_ok_ack_t *) reply->b_wptr;
1058 reply->b_wptr += sizeof(dl_ok_ack_t);
1059 okp->dl_primitive = DL_OK_ACK;
1060 okp->dl_correct_primitive = prim;
1072 if (us->flags & US_BLOCKED)
1079 if ((q = ppa->lowerq) == 0) {
1080 /* try to send it up the control stream */
1081 if (canputnext(ppa->q)) {
1082 putnext(ppa->q, mp);
1086 if (canputnext(ppa->lowerq)) {
1088 * The lower write queue's put procedure just updates counters
1089 * and does a putnext. We call it in order to enter the lower
1090 * queues' perimeter so that the counter updates are serialized.
1092 put(ppa->lowerq, mp);
1096 us->flags |= US_BLOCKED;
1101 * Allocate a new PPA id and link this stream into the list of PPAs.
1102 * This procedure is called with an exclusive lock on all queues in
1110 upperstr_t *us, **usp;
1115 while ((us = *usp) != 0 && ppa_id == us->ppa_id) {
1119 us = (upperstr_t *) q->q_ptr;
1120 us->ppa_id = ppa_id;
1125 us->flags |= US_CONTROL;
1131 if (us->kstats == 0) {
1134 sprintf(unit, "ppp%d", us->ppa->ppa_id);
1135 us->kstats = kstat_create("ppp", us->ppa->ppa_id, unit,
1136 "net", KSTAT_TYPE_NAMED, 4, 0);
1137 if (us->kstats != 0) {
1138 kstat_named_t *kn = KSTAT_NAMED_PTR(us->kstats);
1140 strcpy(kn[0].name, "ipackets");
1141 kn[0].data_type = KSTAT_DATA_ULONG;
1142 strcpy(kn[1].name, "ierrors");
1143 kn[1].data_type = KSTAT_DATA_ULONG;
1144 strcpy(kn[2].name, "opackets");
1145 kn[2].data_type = KSTAT_DATA_ULONG;
1146 strcpy(kn[3].name, "oerrors");
1147 kn[3].data_type = KSTAT_DATA_ULONG;
1148 kstat_install(us->kstats);
1153 *(int *)mp->b_cont->b_rptr = ppa_id;
1154 mp->b_datap->db_type = M_IOCACK;
1165 us = (upperstr_t *) q->q_ptr;
1166 us->state = DL_UNBOUND;
1167 for (t = us->ppa; t->next != 0; t = t->next)
1171 if (mp->b_datap->db_type == M_IOCTL) {
1172 mp->b_datap->db_type = M_IOCACK;
1175 dlpi_ok(q, DL_ATTACH_REQ);
1186 us = (upperstr_t *) q->q_ptr;
1187 for (t = us->ppa; t->next != 0; t = t->next)
1188 if (t->next == us) {
1194 us->state = DL_UNATTACHED;
1195 dlpi_ok(q, DL_DETACH_REQ);
1203 struct lowerstr *ls;
1207 us = (upperstr_t *) q->q_ptr;
1208 us->flags &= ~US_BLOCKED;
1209 while ((mp = getq(q)) != 0) {
1210 if (!send_data(mp, us)) {
1226 if (ppa != 0) { /* why wouldn't it? */
1227 ppa->stats.ppp_opackets++;
1228 ppa->stats.ppp_obytes += msgdsize(mp);
1230 if (ppa->kstats != 0)
1231 KSTAT_NAMED_PTR(ppa->kstats)[2].value.ul++;
1233 ppa->ifstats.ifs_opackets++;
1247 * Flow control has back-enabled this stream:
1248 * enable the write service procedures of all upper
1249 * streams feeding this lower stream.
1251 for (us = (upperstr_t *) q->q_ptr; us != NULL; us = us->next)
1252 if (us->flags & US_BLOCKED)
1261 upperstr_t *us, *as;
1263 dl_unitdata_ind_t *ud;
1266 us = (upperstr_t *) q->q_ptr;
1267 if (us->flags & US_CONTROL) {
1270 * If there is no lower queue attached, run the write service
1271 * routines of other upper streams attached to this PPA.
1273 if (us->lowerq == 0) {
1276 if (as->flags & US_BLOCKED)
1283 * A network protocol stream. Put a DLPI header on each
1284 * packet and send it on.
1285 * (Actually, it seems that the IP module will happily
1286 * accept M_DATA messages without the DL_UNITDATA_IND header.)
1288 while ((mp = getq(q)) != 0) {
1289 if (!canputnext(q)) {
1293 proto = PPP_PROTOCOL(mp->b_rptr);
1294 mp->b_rptr += PPP_HDRLEN;
1295 hdr = allocb(sizeof(dl_unitdata_ind_t) + 2 * sizeof(ulong),
1298 /* XXX should put it back and use bufcall */
1302 hdr->b_datap->db_type = M_PROTO;
1303 ud = (dl_unitdata_ind_t *) hdr->b_wptr;
1304 hdr->b_wptr += sizeof(dl_unitdata_ind_t) + 2 * sizeof(ulong);
1306 ud->dl_primitive = DL_UNITDATA_IND;
1307 ud->dl_dest_addr_length = sizeof(ulong);
1308 ud->dl_dest_addr_offset = sizeof(dl_unitdata_ind_t);
1309 ud->dl_src_addr_length = sizeof(ulong);
1310 ud->dl_src_addr_offset = ud->dl_dest_addr_offset + sizeof(ulong);
1311 #if DL_CURRENT_VERSION >= 2
1312 ud->dl_group_address = 0;
1314 /* Send the DLPI client the data with the SAP they requested,
1315 (e.g. ETHERTYPE_IP) rather than the PPP protocol number
1317 ((ulong *)(ud + 1))[0] = us->req_sap; /* dest SAP */
1318 ((ulong *)(ud + 1))[1] = us->req_sap; /* src SAP */
1324 * If this stream is attached to a PPA with a lower queue pair,
1325 * enable the read queue's service routine if it has data queued.
1326 * XXX there is a possibility that packets could get out of order
1327 * if ppplrput now runs before ppplrsrv.
1329 if (us->ppa != 0 && us->ppa->lowerq != 0)
1330 qenable(RD(us->ppa->lowerq));
1336 find_dest(ppa, proto)
1342 for (us = ppa->next; us != 0; us = us->next)
1343 if (proto == us->sap)
1353 upperstr_t *ppa, *us;
1359 ppa = (upperstr_t *) q->q_ptr;
1362 cmn_err(CE_CONT, "ppplrput: q = %x, ppa = 0??\n", q);
1367 switch (mp->b_datap->db_type) {
1369 if (*mp->b_rptr & FLUSHW) {
1370 *mp->b_rptr &= ~FLUSHR;
1377 switch (*mp->b_rptr) {
1380 if (ppa->kstats != 0) {
1381 KSTAT_NAMED_PTR(ppa->kstats)[1].value.ul++;
1384 ppa->ifstats.ifs_ierrors++;
1386 ppa->stats.ppp_ierrors++;
1390 if (ppa->kstats != 0) {
1391 KSTAT_NAMED_PTR(ppa->kstats)[3].value.ul++;
1394 ppa->ifstats.ifs_oerrors++;
1396 ppa->stats.ppp_oerrors++;
1405 * Attempt to match up the response with the stream
1406 * that the request came from.
1408 iop = (struct iocblk *) mp->b_rptr;
1409 for (us = ppa; us != 0; us = us->next)
1410 if (us->ioc_id == iop->ioc_id)
1419 if (mp->b_datap->db_type == M_DATA) {
1421 if (mp->b_wptr - mp->b_rptr < PPP_HDRLEN) {
1422 #ifdef USE_MSGPULLUP
1423 np = msgpullup(mp, PPP_HDRLEN);
1427 cmn_err(CE_CONT, "ppp_lrput: msgpullup failed (len=%d)\n",
1434 if (!pullupmsg (mp, PPP_HDRLEN)) {
1436 cmn_err(CE_CONT, "ppp_lrput: pullupmsg failed (len=%d)\n",
1443 ppa->stats.ppp_ipackets++;
1444 ppa->stats.ppp_ibytes += len;
1446 if (ppa->kstats != 0) {
1447 KSTAT_NAMED_PTR(ppa->kstats)[0].value.ul++;
1450 ppa->ifstats.ifs_ipackets++;
1452 proto = PPP_PROTOCOL(mp->b_rptr);
1453 if (proto < 0x8000 && (us = find_dest(ppa, proto)) != 0) {
1455 * A data packet for some network protocol.
1456 * Queue it on the upper stream for that protocol.
1466 * A control frame, a frame for an unknown protocol,
1467 * or some other message type.
1468 * Send it up to pppd via the control stream.
1470 if (queclass(mp) == QPCTL || canputnext(ppa->q))
1471 putnext(ppa->q, mp);
1485 upperstr_t *ppa, *us;
1489 * Packets only get queued here for flow control reasons.
1491 ppa = (upperstr_t *) q->q_ptr;
1492 while ((mp = getq(q)) != 0) {
1493 if (mp->b_datap->db_type == M_DATA
1494 && (proto = PPP_PROTOCOL(mp->b_rptr)) < 0x8000
1495 && (us = find_dest(ppa, proto)) != 0) {
1503 if (canputnext(ppa->q))
1504 putnext(ppa->q, mp);
1515 putctl2(q, type, code, val)
1517 int type, code, val;
1521 mp = allocb(2, BPRI_HI);
1524 mp->b_datap->db_type = type;
1525 mp->b_wptr[0] = code;
1526 mp->b_wptr[1] = val;
1533 putctl4(q, type, code, val)
1535 int type, code, val;
1539 mp = allocb(4, BPRI_HI);
1542 mp->b_datap->db_type = type;
1543 mp->b_wptr[0] = code;
1544 ((short *)mp->b_wptr)[1] = val;
1552 queue_t *q; /* not used */
1553 mblk_t *mp; /* not used either */
1558 cmn_err(CE_CONT, "ppp upper streams:\n");
1559 for (us = minor_devs; us != 0; us = us->nextmn) {
1561 cmn_err(CE_CONT, " %d: q=%x rlev=%d wlev=%d flags=0x%b",
1562 us->mn, uq, (uq? qsize(uq): 0), (uq? qsize(WR(uq)): 0),
1563 us->flags, "\020\1priv\2control\3blocked\4last");
1564 cmn_err(CE_CONT, " state=%x sap=%x req_sap=%x", us->state, us->sap,
1567 cmn_err(CE_CONT, " ppa=?\n");
1569 cmn_err(CE_CONT, " ppa=%d\n", us->ppa->ppa_id);
1570 if (us->flags & US_CONTROL) {
1572 cmn_err(CE_CONT, " control for %d lq=%x rlev=%d wlev=%d",
1573 us->ppa_id, lq, (lq? qsize(RD(lq)): 0),
1574 (lq? qsize(lq): 0));
1575 cmn_err(CE_CONT, " mru=%d mtu=%d\n", us->mru, us->mtu);