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 HAS 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.5 1996/05/28 00:56:18 paulus Exp $
31 * This file is used under Solaris 2, SVR4, and SunOS 4.
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/ioccom.h>
43 #include <sys/cmn_err.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>
59 #include <net/ppp_defs.h>
60 #include <net/pppio.h>
70 * The IP module may use this SAP value for IP packets.
73 #define ETHERTYPE_IP 0x800
77 #define PPP_MAXMTU 65535
83 * Private information; one per upper stream.
85 typedef struct upperstr {
86 minor_t mn; /* minor device number */
87 struct upperstr *nextmn; /* next minor device */
88 queue_t *q; /* read q associated with this upper stream */
89 int flags; /* flag bits, see below */
90 int state; /* current DLPI state */
91 int sap; /* service access point */
92 int req_sap; /* which SAP the DLPI client requested */
93 struct upperstr *ppa; /* control stream for our ppa */
94 struct upperstr *next; /* next stream for this ppa */
95 uint ioc_id; /* last ioctl ID for this stream */
96 enum NPmode npmode; /* what to do with packets on this SAP */
98 * There is exactly one control stream for each PPA.
99 * The following fields are only used for control streams.
102 queue_t *lowerq; /* write queue attached below this PPA */
103 struct upperstr *nextppa; /* next control stream */
106 struct pppstat stats; /* statistics */
107 time_t last_sent; /* time last NP packet sent */
108 time_t last_recv; /* time last NP packet rcvd */
110 kstat_t *kstats; /* stats for netstat */
114 char ifname[IFNAMSIZ];
115 struct ifstats ifstats;
119 /* Values for flags */
120 #define US_PRIV 1 /* stream was opened by superuser */
121 #define US_CONTROL 2 /* stream is a control stream */
122 #define US_BLOCKED 4 /* flow ctrl has blocked lower write stream */
123 #define US_LASTMOD 8 /* no PPP modules below us */
124 #define US_DBGLOG 0x10 /* log various occurrences */
126 static upperstr_t *minor_devs = NULL;
127 static upperstr_t *ppas = NULL;
130 static int pppopen __P((queue_t *, dev_t *, int, int, cred_t *));
131 static int pppclose __P((queue_t *, int, cred_t *));
133 static int pppopen __P((queue_t *, int, int, int));
134 static int pppclose __P((queue_t *, int));
136 static int pppuwput __P((queue_t *, mblk_t *));
137 static int pppursrv __P((queue_t *));
138 static int pppuwsrv __P((queue_t *));
139 static int ppplrput __P((queue_t *, mblk_t *));
140 static int ppplwput __P((queue_t *, mblk_t *));
141 static int ppplrsrv __P((queue_t *));
142 static int ppplwsrv __P((queue_t *));
144 static void dlpi_request __P((queue_t *, mblk_t *, upperstr_t *));
145 static void dlpi_error __P((queue_t *, int, int, int));
146 static void dlpi_ok __P((queue_t *, int));
148 static int send_data __P((mblk_t *, upperstr_t *));
149 static void new_ppa __P((queue_t *, mblk_t *));
150 static void attach_ppa __P((queue_t *, mblk_t *));
151 static void detach_ppa __P((queue_t *, mblk_t *));
152 static void debug_dump __P((queue_t *, mblk_t *));
153 static upperstr_t *find_dest __P((upperstr_t *, int));
154 static int putctl2 __P((queue_t *, int, int, int));
155 static int putctl4 __P((queue_t *, int, int, int));
157 static struct module_info ppp_info = {
158 0xb1a6, "ppp", 0, 512, 512, 128
161 static struct qinit pppurint = {
162 NULL, pppursrv, pppopen, pppclose, NULL, &ppp_info, NULL
165 static struct qinit pppuwint = {
166 pppuwput, pppuwsrv, NULL, NULL, NULL, &ppp_info, NULL
169 static struct qinit ppplrint = {
170 ppplrput, ppplrsrv, NULL, NULL, NULL, &ppp_info, NULL
173 static struct qinit ppplwint = {
174 ppplwput, ppplwsrv, NULL, NULL, NULL, &ppp_info, NULL
178 extern struct ifstats *ifstats;
182 struct streamtab pppinfo = {
183 &pppurint, &pppuwint,
190 * How we maintain statistics.
193 #define INCR_IPACKETS(ppa) \
194 if (ppa->kstats != 0) { \
195 KSTAT_NAMED_PTR(ppa->kstats)[0].value.ul++; \
197 #define INCR_IERRORS(ppa) \
198 if (ppa->kstats != 0) { \
199 KSTAT_NAMED_PTR(ppa->kstats)[1].value.ul++; \
201 #define INCR_OPACKETS(ppa) \
202 if (ppa->kstats != 0) { \
203 KSTAT_NAMED_PTR(ppa->kstats)[2].value.ul++; \
205 #define INCR_OERRORS(ppa) \
206 if (ppa->kstats != 0) { \
207 KSTAT_NAMED_PTR(ppa->kstats)[3].value.ul++; \
212 #define INCR_IPACKETS(ppa) ppa->ifstats.ifs_ipackets++;
213 #define INCR_IERRORS(ppa) ppa->ifstats.ifs_ierrors++;
214 #define INCR_OPACKETS(ppa) ppa->ifstats.ifs_opackets++;
215 #define INCR_OERRORS(ppa) ppa->ifstats.ifs_oerrors++;
219 * STREAMS driver entry points.
223 pppopen(q, devp, oflag, sflag, credp)
229 pppopen(q, dev, oflag, sflag)
231 int dev; /* really dev_t */
240 DRV_OPEN_OK(dev); /* device is already open */
242 if (sflag == CLONEOPEN) {
244 for (prevp = &minor_devs; (up = *prevp) != 0; prevp = &up->nextmn) {
251 mn = getminor(*devp);
255 for (prevp = &minor_devs; (up = *prevp) != 0; prevp = &up->nextmn) {
260 /* this can't happen */
261 q->q_ptr = WR(q)->q_ptr = (caddr_t) up;
267 * Construct a new minor node.
269 up = (upperstr_t *) ALLOC_SLEEP(sizeof(upperstr_t));
270 bzero((caddr_t) up, sizeof(upperstr_t));
272 DPRINT("pppopen: out of kernel memory\n");
279 *devp = makedevice(getmajor(*devp), mn);
283 up->flags |= US_PRIV;
285 up->state = DL_UNATTACHED;
288 up->ifflags = IFF_UP | IFF_POINTOPOINT;
291 up->last_sent = up->last_recv = time;
292 up->npmode = NPMODE_DROP;
293 q->q_ptr = (caddr_t) up;
294 WR(q)->q_ptr = (caddr_t) up;
299 DRV_OPEN_OK(makedev(major(dev), mn));
304 pppclose(q, flag, credp)
314 upperstr_t *up, **upp;
315 upperstr_t *as, *asnext;
320 up = (upperstr_t *) q->q_ptr;
321 if (up->flags & US_DBGLOG)
322 DPRINT2("ppp/%d: close, flags=%x\n", up->mn, up->flags);
325 if (up->flags & US_CONTROL) {
327 struct ifstats *ifp, *pifp;
330 * This stream represents a PPA:
331 * For all streams attached to the PPA, clear their
332 * references to this PPA.
333 * Then remove this PPA from the list of PPAs.
335 for (as = up->next; as != 0; as = asnext) {
339 if (as->flags & US_BLOCKED) {
340 as->flags &= ~US_BLOCKED;
341 flushq(WR(as->q), FLUSHDATA);
344 for (upp = &ppas; *upp != 0; upp = &(*upp)->nextppa)
350 /* Remove the statistics from the active list. */
351 for (ifp = ifstats, pifp = 0; ifp; ifp = ifp->ifs_next) {
352 if (ifp == &up->ifstats) {
354 pifp->ifs_next = ifp->ifs_next;
356 ifstats = ifp->ifs_next;
364 * If this stream is attached to a PPA,
365 * remove it from the PPA's list.
367 if ((as = up->ppa) != 0) {
368 for (; as->next != 0; as = as->next)
369 if (as->next == up) {
378 kstat_delete(up->kstats);
384 for (prevp = &minor_devs; *prevp != 0; prevp = &(*prevp)->nextmn) {
390 kmem_free(up, sizeof(upperstr_t));
397 * A message from on high. We do one of three things:
399 * - put the message on the lower write stream
400 * - queue it for our service routine
407 upperstr_t *us, *usnext, *ppa, *os, *nps;
417 struct ppp_idle *pip;
420 us = (upperstr_t *) q->q_ptr;
421 switch (mp->b_datap->db_type) {
425 dlpi_request(q, mp, us);
430 if (us->flags & US_DBGLOG)
431 DPRINT3("ppp/%d: uwput M_DATA len=%d flags=%x\n",
432 us->mn, msgdsize(mp), us->flags);
433 if (us->ppa == 0 || msgdsize(mp) > us->ppa->mtu + PPP_HDRLEN
435 || (us->flags & US_CONTROL) == 0
438 DPRINT1("pppuwput: junk data len=%d\n", msgdsize(mp));
443 if (!pass_packet(us->ppa, mp, 1)) {
448 if (!send_data(mp, us))
453 iop = (struct iocblk *) mp->b_rptr;
455 if (us->flags & US_DBGLOG)
456 DPRINT3("ppp/%d: ioctl %x count=%d\n",
457 us->mn, iop->ioc_cmd, iop->ioc_count);
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;
464 lq->q_ptr = (caddr_t) us;
465 RD(lq)->q_ptr = (caddr_t) us;
467 flushq(RD(lq), FLUSHALL);
470 us->flags &= ~US_LASTMOD;
471 /* Unblock upper streams which now feed this lower stream. */
473 /* Send useful information down to the modules which
474 are now linked below us. */
475 putctl2(lq, M_CTL, PPPCTL_UNIT, us->ppa_id);
476 putctl4(lq, M_CTL, PPPCTL_MRU, us->mru);
477 putctl4(lq, M_CTL, PPPCTL_MTU, us->mtu);
481 lb = (struct linkblk *) mp->b_cont->b_rptr;
483 if (us->lowerq != lb->l_qbot)
484 DPRINT2("ppp unlink: lowerq=%x qbot=%x\n",
485 us->lowerq, lb->l_qbot);
490 /* Unblock streams which now feed back up the control stream. */
495 if (us->flags & US_CONTROL)
497 if ((us->flags & US_PRIV) == 0) {
501 /* Arrange to return an int */
502 if ((mq = mp->b_cont) == 0
503 || mq->b_datap->db_lim - mq->b_rptr < sizeof(int)) {
504 mq = allocb(sizeof(int), BPRI_HI);
514 iop->ioc_count = sizeof(int);
515 mq->b_wptr = mq->b_rptr + sizeof(int);
516 qwriter(q, mp, new_ppa, PERIM_OUTER);
521 /* like dlpi_attach, for programs which can't write to
522 the stream (like pppstats) */
523 if (iop->ioc_count != sizeof(int) || us->ppa != 0)
525 n = *(int *)mp->b_cont->b_rptr;
526 for (ppa = ppas; ppa != 0; ppa = ppa->nextppa)
527 if (ppa->ppa_id == n)
533 qwriter(q, mp, attach_ppa, PERIM_OUTER);
539 /* Attach to a given SAP. */
540 if (iop->ioc_count != sizeof(int) || us->ppa == 0)
542 n = *(int *)mp->b_cont->b_rptr;
543 /* n must be a valid PPP network protocol number. */
544 if (n < 0x21 || n > 0x3fff || (n & 0x101) != 1)
546 /* check that no other stream is bound to this sap already. */
547 for (os = us->ppa; os != 0; os = os->next)
559 if (iop->ioc_count != sizeof(int) || (us->flags & US_CONTROL) == 0)
561 n = *(int *)mp->b_cont->b_rptr;
562 if (n <= 0 || n > PPP_MAXMTU)
568 putctl4(us->lowerq, M_CTL, PPPCTL_MRU, n);
574 if (iop->ioc_count != sizeof(int) || (us->flags & US_CONTROL) == 0)
576 n = *(int *)mp->b_cont->b_rptr;
577 if (n <= 0 || n > PPP_MAXMTU)
583 us->ifstats.ifs_mtu = n;
586 putctl4(us->lowerq, M_CTL, PPPCTL_MTU, n);
592 us->flags |= US_LASTMOD;
597 if (iop->ioc_count != sizeof(int))
599 n = *(int *)mp->b_cont->b_rptr;
600 if (n == PPPDBG_DUMP + PPPDBG_DRIVER) {
601 qwriter(q, NULL, debug_dump, PERIM_OUTER);
604 } else if (n == PPPDBG_LOG + PPPDBG_DRIVER) {
605 DPRINT1("ppp/%d: debug log enabled\n", us->mn);
606 us->flags |= US_DBGLOG;
610 if (us->ppa == 0 || us->ppa->lowerq == 0)
612 putnext(us->ppa->lowerq, mp);
618 if (iop->ioc_count != 2 * sizeof(int))
620 if ((us->flags & US_CONTROL) == 0)
622 sap = ((int *)mp->b_cont->b_rptr)[0];
623 for (nps = us->next; nps != 0; nps = nps->next)
627 if (us->flags & US_DBGLOG)
628 DPRINT2("ppp/%d: no stream for sap %x\n", us->mn, sap);
631 nps->npmode = (enum NPmode) ((int *)mp->b_cont->b_rptr)[1];
632 if (nps->npmode == NPMODE_DROP || nps->npmode == NPMODE_ERROR)
633 flushq(WR(nps->q), FLUSHDATA);
634 else if (nps->npmode == NPMODE_PASS && qsize(WR(nps->q)) > 0
635 && (nps->flags & US_BLOCKED) == 0)
642 if ((ppa = us->ppa) == 0)
644 mq = allocb(sizeof(struct ppp_idle), BPRI_HI);
653 pip = (struct ppp_idle *) mq->b_wptr;
654 pip->xmit_idle = time - ppa->last_sent;
655 pip->recv_idle = time - ppa->last_recv;
656 mq->b_wptr += sizeof(struct ppp_idle);
657 iop->ioc_count = sizeof(struct ppp_idle);
663 printf("SIOCSIFNAME\n");
664 /* Sent from IP down to us. Attach the ifstats structure. */
665 if (iop->ioc_count != sizeof(struct ifreq) || us->ppa == 0)
667 ifr = (struct ifreq *)mp->b_cont->b_rptr;
668 /* Find the unit number in the interface name. */
669 for (i = 0; i < IFNAMSIZ; i++) {
670 if (ifr->ifr_name[i] == 0 ||
671 (ifr->ifr_name[i] >= '0' &&
672 ifr->ifr_name[i] <= '9'))
675 us->ifname[i] = ifr->ifr_name[i];
679 /* Convert the unit number to binary. */
680 for (n = 0; i < IFNAMSIZ; i++) {
681 if (ifr->ifr_name[i] == 0) {
685 n = n * 10 + ifr->ifr_name[i] - '0';
689 /* Verify the ppa. */
690 if (us->ppa->ppa_id != n)
694 /* Set up the netstat block. */
695 strncpy (ppa->ifname, us->ifname, IFNAMSIZ);
697 ppa->ifstats.ifs_name = ppa->ifname;
698 ppa->ifstats.ifs_unit = n;
699 ppa->ifstats.ifs_active = us->state != DL_UNBOUND;
700 ppa->ifstats.ifs_mtu = ppa->mtu;
702 /* Link in statistics used by netstat. */
703 ppa->ifstats.ifs_next = ifstats;
704 ifstats = &ppa->ifstats;
711 printf("SIOCGIFFLAGS\n");
712 if (!(us->flags & US_CONTROL)) {
718 ((struct iocblk_in *)iop)->ioc_ifflags = us->ifflags;
723 printf("SIOCSIFFLAGS\n");
724 if (!(us->flags & US_CONTROL)) {
730 us->ifflags = ((struct iocblk_in *)iop)->ioc_ifflags;
735 printf("SIOCSIFADDR\n");
736 if (!(us->flags & US_CONTROL)) {
742 us->ifflags |= IFF_RUNNING;
743 ((struct iocblk_in *)iop)->ioc_ifflags |= IFF_RUNNING;
758 if (us->ppa == 0 || us->ppa->lowerq == 0)
760 us->ioc_id = iop->ioc_id;
762 switch (iop->ioc_cmd) {
765 if (us->flags & US_LASTMOD) {
769 putnext(us->ppa->lowerq, mp);
772 if (us->flags & US_PRIV)
773 putnext(us->ppa->lowerq, mp);
775 DPRINT1("ppp ioctl %x rejected\n", iop->ioc_cmd);
784 iop->ioc_error = error;
785 mp->b_datap->db_type = M_IOCNAK;
787 } else if (error == 0) {
788 mp->b_datap->db_type = M_IOCACK;
794 if (us->flags & US_DBGLOG)
795 DPRINT2("ppp/%d: flush %x\n", us->mn, *mp->b_rptr);
796 if (*mp->b_rptr & FLUSHW)
797 flushq(q, FLUSHDATA);
798 if (*mp->b_rptr & FLUSHR) {
799 *mp->b_rptr &= ~FLUSHW;
814 dlpi_request(q, mp, us)
819 union DL_primitives *d = (union DL_primitives *) mp->b_rptr;
820 int size = mp->b_wptr - mp->b_rptr;
822 upperstr_t *ppa, *os;
827 if (us->flags & US_DBGLOG)
828 DPRINT3("ppp/%d: dlpi prim %x len=%d\n", us->mn,
829 d->dl_primitive, size);
830 switch (d->dl_primitive) {
832 if (size < sizeof(dl_info_req_t))
834 if ((reply = allocb(sizeof(dl_info_ack_t), BPRI_HI)) == 0)
835 break; /* should do bufcall */
836 reply->b_datap->db_type = M_PCPROTO;
837 info = (dl_info_ack_t *) reply->b_wptr;
838 reply->b_wptr += sizeof(dl_info_ack_t);
839 bzero((caddr_t) info, sizeof(dl_info_ack_t));
840 info->dl_primitive = DL_INFO_ACK;
841 info->dl_max_sdu = PPP_MAXMTU;
842 info->dl_min_sdu = 1;
843 info->dl_addr_length = sizeof(ulong);
845 info->dl_mac_type = DL_OTHER;
847 info->dl_mac_type = DL_HDLC; /* a lie */
849 info->dl_current_state = us->state;
850 info->dl_service_mode = DL_CLDLS;
851 info->dl_provider_style = DL_STYLE2;
852 #if DL_CURRENT_VERSION >= 2
853 info->dl_sap_length = sizeof(ulong);
854 info->dl_version = DL_CURRENT_VERSION;
860 if (size < sizeof(dl_attach_req_t))
862 if (us->state != DL_UNATTACHED || us->ppa != 0) {
863 dlpi_error(q, DL_ATTACH_REQ, DL_OUTSTATE, 0);
866 for (ppa = ppas; ppa != 0; ppa = ppa->nextppa)
867 if (ppa->ppa_id == d->attach_req.dl_ppa)
870 dlpi_error(q, DL_ATTACH_REQ, DL_BADPPA, 0);
874 qwriter(q, mp, attach_ppa, PERIM_OUTER);
878 if (size < sizeof(dl_detach_req_t))
880 if (us->state != DL_UNBOUND || us->ppa == 0) {
881 dlpi_error(q, DL_DETACH_REQ, DL_OUTSTATE, 0);
884 qwriter(q, mp, detach_ppa, PERIM_OUTER);
888 if (size < sizeof(dl_bind_req_t))
890 if (us->state != DL_UNBOUND || us->ppa == 0) {
891 dlpi_error(q, DL_BIND_REQ, DL_OUTSTATE, 0);
894 if (d->bind_req.dl_service_mode != DL_CLDLS) {
895 dlpi_error(q, DL_BIND_REQ, DL_UNSUPPORTED, 0);
899 /* saps must be valid PPP network protocol numbers,
900 except that we accept ETHERTYPE_IP in place of PPP_IP. */
901 sap = d->bind_req.dl_sap;
903 DPRINT1("ppp bind %x\n", sap);
904 if (sap == ETHERTYPE_IP)
906 if (sap < 0x21 || sap > 0x3fff || (sap & 0x101) != 1) {
907 dlpi_error(q, DL_BIND_REQ, DL_BADADDR, 0);
911 /* check that no other stream is bound to this sap already. */
912 for (os = us->ppa; os != 0; os = os->next)
916 dlpi_error(q, DL_BIND_REQ, DL_NOADDR, 0);
923 if ((reply = allocb(sizeof(dl_bind_ack_t) + sizeof(ulong),
925 break; /* should do bufcall */
926 ackp = (dl_bind_ack_t *) reply->b_wptr;
927 reply->b_wptr += sizeof(dl_bind_ack_t) + sizeof(ulong);
928 reply->b_datap->db_type = M_PCPROTO;
929 bzero((caddr_t) ackp, sizeof(dl_bind_ack_t));
930 ackp->dl_primitive = DL_BIND_ACK;
932 ackp->dl_addr_length = sizeof(ulong);
933 ackp->dl_addr_offset = sizeof(dl_bind_ack_t);
934 *(ulong *)(ackp+1) = sap;
939 if (size < sizeof(dl_unbind_req_t))
941 if (us->state != DL_IDLE) {
942 dlpi_error(q, DL_UNBIND_REQ, DL_OUTSTATE, 0);
946 us->state = DL_UNBOUND;
948 us->ppa->ifstats.ifs_active = 0;
950 dlpi_ok(q, DL_UNBIND_REQ);
953 case DL_UNITDATA_REQ:
954 if (size < sizeof(dl_unitdata_req_t))
956 if (us->state != DL_IDLE) {
957 dlpi_error(q, DL_UNITDATA_REQ, DL_OUTSTATE, 0);
960 if ((ppa = us->ppa) == 0) {
961 cmn_err(CE_CONT, "ppp: in state dl_idle but ppa == 0?\n");
964 len = mp->b_cont == 0? 0: msgdsize(mp->b_cont);
965 if (len > ppa->mtu) {
966 DPRINT2("dlpi data too large (%d > %d)\n", len, ppa->mtu);
969 /* this assumes PPP_HDRLEN <= sizeof(dl_unitdata_req_t) */
970 if (mp->b_datap->db_ref > 1) {
971 np = allocb(PPP_HDRLEN, BPRI_HI);
974 np->b_cont = mp->b_cont;
979 mp->b_datap->db_type = M_DATA;
980 /* XXX should use dl_dest_addr_offset/length here,
981 but we would have to translate ETHERTYPE_IP -> PPP_IP */
982 mp->b_wptr = mp->b_rptr + PPP_HDRLEN;
983 mp->b_rptr[0] = PPP_ALLSTATIONS;
984 mp->b_rptr[1] = PPP_UI;
985 mp->b_rptr[2] = us->sap >> 8;
986 mp->b_rptr[3] = us->sap;
987 if (!pass_packet(ppa, mp, 1)) {
990 if (!send_data(mp, us))
995 #if DL_CURRENT_VERSION >= 2
996 case DL_SUBS_BIND_REQ:
997 case DL_SUBS_UNBIND_REQ:
998 case DL_ENABMULTI_REQ:
999 case DL_DISABMULTI_REQ:
1000 case DL_PROMISCON_REQ:
1001 case DL_PROMISCOFF_REQ:
1002 case DL_PHYS_ADDR_REQ:
1003 case DL_SET_PHYS_ADDR_REQ:
1006 case DL_REPLY_UPDATE_REQ:
1008 case DL_DATA_ACK_REQ:
1010 case DL_CONNECT_REQ:
1012 dlpi_error(q, d->dl_primitive, DL_NOTSUPPORTED, 0);
1015 case DL_CONNECT_RES:
1016 case DL_DISCONNECT_REQ:
1019 dlpi_error(q, d->dl_primitive, DL_OUTSTATE, 0);
1023 dlpi_error(q, d->dl_primitive, DL_BADQOSTYPE, 0);
1026 #if DL_CURRENT_VERSION >= 2
1033 cmn_err(CE_CONT, "ppp: unknown dlpi prim 0x%x\n", d->dl_primitive);
1036 dlpi_error(q, d->dl_primitive, DL_BADPRIM, 0);
1043 dlpi_error(q, prim, err, uerr)
1045 int prim, err, uerr;
1048 dl_error_ack_t *errp;
1050 reply = allocb(sizeof(dl_error_ack_t), BPRI_HI);
1052 return; /* XXX should do bufcall */
1053 reply->b_datap->db_type = M_PCPROTO;
1054 errp = (dl_error_ack_t *) reply->b_wptr;
1055 reply->b_wptr += sizeof(dl_error_ack_t);
1056 errp->dl_primitive = DL_ERROR_ACK;
1057 errp->dl_error_primitive = prim;
1058 errp->dl_errno = err;
1059 errp->dl_unix_errno = uerr;
1071 reply = allocb(sizeof(dl_ok_ack_t), BPRI_HI);
1073 return; /* XXX should do bufcall */
1074 reply->b_datap->db_type = M_PCPROTO;
1075 okp = (dl_ok_ack_t *) reply->b_wptr;
1076 reply->b_wptr += sizeof(dl_ok_ack_t);
1077 okp->dl_primitive = DL_OK_ACK;
1078 okp->dl_correct_primitive = prim;
1081 #endif /* NO_DLPI */
1084 pass_packet(ppa, mp, outbound)
1090 * Here is where we might, in future, decide whether to pass
1091 * or drop the packet, and whether it counts as link activity.
1094 ppa->last_sent = time;
1096 ppa->last_recv = time;
1108 if ((us->flags & US_BLOCKED) || us->npmode == NPMODE_QUEUE)
1111 if (ppa == 0 || us->npmode == NPMODE_DROP || us->npmode == NPMODE_ERROR) {
1112 if (us->flags & US_DBGLOG)
1113 DPRINT2("ppp/%d: dropping pkt (npmode=%d)\n", us->mn, us->npmode);
1117 if ((q = ppa->lowerq) == 0) {
1118 /* try to send it up the control stream */
1119 if (canputnext(ppa->q)) {
1120 putnext(ppa->q, mp);
1124 if (canputnext(ppa->lowerq)) {
1126 * The lower write queue's put procedure just updates counters
1127 * and does a putnext. We call it so that on SMP systems, we
1128 * enter the lower queues' perimeter so that the counter
1129 * updates are serialized.
1131 put(ppa->lowerq, mp);
1135 us->flags |= US_BLOCKED;
1140 * Allocate a new PPA id and link this stream into the list of PPAs.
1141 * This procedure is called with an exclusive lock on all queues in
1149 upperstr_t *us, **usp;
1154 while ((us = *usp) != 0 && ppa_id == us->ppa_id) {
1158 us = (upperstr_t *) q->q_ptr;
1159 us->ppa_id = ppa_id;
1164 us->flags |= US_CONTROL;
1165 us->npmode = NPMODE_PASS;
1172 * Create a kstats record for our statistics, so netstat -i works.
1174 if (us->kstats == 0) {
1177 sprintf(unit, "ppp%d", us->ppa->ppa_id);
1178 us->kstats = kstat_create("ppp", us->ppa->ppa_id, unit,
1179 "net", KSTAT_TYPE_NAMED, 4, 0);
1180 if (us->kstats != 0) {
1181 kstat_named_t *kn = KSTAT_NAMED_PTR(us->kstats);
1183 strcpy(kn[0].name, "ipackets");
1184 kn[0].data_type = KSTAT_DATA_ULONG;
1185 strcpy(kn[1].name, "ierrors");
1186 kn[1].data_type = KSTAT_DATA_ULONG;
1187 strcpy(kn[2].name, "opackets");
1188 kn[2].data_type = KSTAT_DATA_ULONG;
1189 strcpy(kn[3].name, "oerrors");
1190 kn[3].data_type = KSTAT_DATA_ULONG;
1191 kstat_install(us->kstats);
1196 *(int *)mp->b_cont->b_rptr = ppa_id;
1197 mp->b_datap->db_type = M_IOCACK;
1208 us = (upperstr_t *) q->q_ptr;
1210 us->state = DL_UNBOUND;
1212 for (t = us->ppa; t->next != 0; t = t->next)
1216 if (mp->b_datap->db_type == M_IOCTL) {
1217 mp->b_datap->db_type = M_IOCACK;
1221 dlpi_ok(q, DL_ATTACH_REQ);
1233 us = (upperstr_t *) q->q_ptr;
1234 for (t = us->ppa; t->next != 0; t = t->next)
1235 if (t->next == us) {
1242 us->state = DL_UNATTACHED;
1243 dlpi_ok(q, DL_DETACH_REQ);
1252 struct lowerstr *ls;
1256 us = (upperstr_t *) q->q_ptr;
1257 us->flags &= ~US_BLOCKED;
1258 while ((mp = getq(q)) != 0) {
1259 if (!send_data(mp, us)) {
1274 ppa = (upperstr_t *) q->q_ptr;
1275 if (ppa != 0) { /* why wouldn't it? */
1276 ppa->stats.ppp_opackets++;
1277 ppa->stats.ppp_obytes += msgdsize(mp);
1278 #ifdef INCR_OPACKETS
1293 * Flow control has back-enabled this stream:
1294 * enable the write service procedures of all upper
1295 * streams feeding this lower stream.
1297 for (us = (upperstr_t *) q->q_ptr; us != NULL; us = us->next)
1298 if (us->flags & US_BLOCKED)
1307 upperstr_t *us, *as;
1310 dl_unitdata_ind_t *ud;
1314 us = (upperstr_t *) q->q_ptr;
1315 if (us->flags & US_CONTROL) {
1318 * If there is no lower queue attached, run the write service
1319 * routines of other upper streams attached to this PPA.
1321 if (us->lowerq == 0) {
1324 if (as->flags & US_BLOCKED)
1331 * A network protocol stream. Put a DLPI header on each
1332 * packet and send it on.
1333 * (Actually, it seems that the IP module will happily
1334 * accept M_DATA messages without the DL_UNITDATA_IND header.)
1336 while ((mp = getq(q)) != 0) {
1337 if (!canputnext(q)) {
1342 proto = PPP_PROTOCOL(mp->b_rptr);
1343 mp->b_rptr += PPP_HDRLEN;
1344 hdr = allocb(sizeof(dl_unitdata_ind_t) + 2 * sizeof(ulong),
1347 /* XXX should put it back and use bufcall */
1351 hdr->b_datap->db_type = M_PROTO;
1352 ud = (dl_unitdata_ind_t *) hdr->b_wptr;
1353 hdr->b_wptr += sizeof(dl_unitdata_ind_t) + 2 * sizeof(ulong);
1355 ud->dl_primitive = DL_UNITDATA_IND;
1356 ud->dl_dest_addr_length = sizeof(ulong);
1357 ud->dl_dest_addr_offset = sizeof(dl_unitdata_ind_t);
1358 ud->dl_src_addr_length = sizeof(ulong);
1359 ud->dl_src_addr_offset = ud->dl_dest_addr_offset + sizeof(ulong);
1360 #if DL_CURRENT_VERSION >= 2
1361 ud->dl_group_address = 0;
1363 /* Send the DLPI client the data with the SAP they requested,
1364 (e.g. ETHERTYPE_IP) rather than the PPP protocol number
1366 ((ulong *)(ud + 1))[0] = us->req_sap; /* dest SAP */
1367 ((ulong *)(ud + 1))[1] = us->req_sap; /* src SAP */
1371 #endif /* NO_DLPI */
1376 * If this stream is attached to a PPA with a lower queue pair,
1377 * enable the read queue's service routine if it has data queued.
1378 * XXX there is a possibility that packets could get out of order
1379 * if ppplrput now runs before ppplrsrv.
1381 if (us->ppa != 0 && us->ppa->lowerq != 0)
1382 qenable(RD(us->ppa->lowerq));
1388 find_dest(ppa, proto)
1394 for (us = ppa->next; us != 0; us = us->next)
1395 if (proto == us->sap)
1405 upperstr_t *ppa, *us;
1411 ppa = (upperstr_t *) q->q_ptr;
1413 DPRINT1("ppplrput: q = %x, ppa = 0??\n", q);
1417 switch (mp->b_datap->db_type) {
1419 if (*mp->b_rptr & FLUSHW) {
1420 *mp->b_rptr &= ~FLUSHR;
1427 switch (*mp->b_rptr) {
1432 ppa->stats.ppp_ierrors++;
1438 ppa->stats.ppp_oerrors++;
1447 * Attempt to match up the response with the stream
1448 * that the request came from.
1450 iop = (struct iocblk *) mp->b_rptr;
1451 for (us = ppa; us != 0; us = us->next)
1452 if (us->ioc_id == iop->ioc_id)
1461 if (mp->b_datap->db_type == M_DATA) {
1463 if (mp->b_wptr - mp->b_rptr < PPP_HDRLEN) {
1464 PULLUP(mp, PPP_HDRLEN);
1466 DPRINT1("ppp_lrput: msgpullup failed (len=%d)\n", len);
1470 ppa->stats.ppp_ipackets++;
1471 ppa->stats.ppp_ibytes += len;
1472 #ifdef INCR_IPACKETS
1475 if (!pass_packet(ppa, mp, 0)) {
1479 proto = PPP_PROTOCOL(mp->b_rptr);
1480 if (proto < 0x8000 && (us = find_dest(ppa, proto)) != 0) {
1482 * A data packet for some network protocol.
1483 * Queue it on the upper stream for that protocol.
1493 * A control frame, a frame for an unknown protocol,
1494 * or some other message type.
1495 * Send it up to pppd via the control stream.
1497 if (queclass(mp) == QPCTL || canputnext(ppa->q))
1498 putnext(ppa->q, mp);
1512 upperstr_t *ppa, *us;
1516 * Packets only get queued here for flow control reasons.
1518 ppa = (upperstr_t *) q->q_ptr;
1519 while ((mp = getq(q)) != 0) {
1520 if (mp->b_datap->db_type == M_DATA
1521 && (proto = PPP_PROTOCOL(mp->b_rptr)) < 0x8000
1522 && (us = find_dest(ppa, proto)) != 0) {
1530 if (canputnext(ppa->q))
1531 putnext(ppa->q, mp);
1542 putctl2(q, type, code, val)
1544 int type, code, val;
1548 mp = allocb(2, BPRI_HI);
1551 mp->b_datap->db_type = type;
1552 mp->b_wptr[0] = code;
1553 mp->b_wptr[1] = val;
1560 putctl4(q, type, code, val)
1562 int type, code, val;
1566 mp = allocb(4, BPRI_HI);
1569 mp->b_datap->db_type = type;
1570 mp->b_wptr[0] = code;
1571 ((short *)mp->b_wptr)[1] = val;
1579 queue_t *q; /* not used */
1580 mblk_t *mp; /* not used either */
1585 DPRINT("ppp upper streams:\n");
1586 for (us = minor_devs; us != 0; us = us->nextmn) {
1588 DPRINT3(" %d: q=%x rlev=%d",
1589 us->mn, uq, (uq? qsize(uq): 0));
1590 DPRINT3(" wlev=%d flags=0x%b", (uq? qsize(WR(uq)): 0),
1591 us->flags, "\020\1priv\2control\3blocked\4last");
1592 DPRINT3(" state=%x sap=%x req_sap=%x", us->state, us->sap,
1597 DPRINT1(" ppa=%d\n", us->ppa->ppa_id);
1598 if (us->flags & US_CONTROL) {
1600 DPRINT3(" control for %d lq=%x rlev=%d",
1601 us->ppa_id, lq, (lq? qsize(RD(lq)): 0));
1602 DPRINT3(" wlev=%d mru=%d mtu=%d\n",
1603 (lq? qsize(lq): 0), us->mru, us->mtu);