+#ifndef NO_DLPI
+ proto = PPP_PROTOCOL(mp->b_rptr);
+ mp->b_rptr += PPP_HDRLEN;
+ hdr = allocb(sizeof(dl_unitdata_ind_t) + 2 * sizeof(uint),
+ BPRI_MED);
+ if (hdr == 0) {
+ /* XXX should put it back and use bufcall */
+ freemsg(mp);
+ continue;
+ }
+ hdr->b_datap->db_type = M_PROTO;
+ ud = (dl_unitdata_ind_t *) hdr->b_wptr;
+ hdr->b_wptr += sizeof(dl_unitdata_ind_t) + 2 * sizeof(uint);
+ hdr->b_cont = mp;
+ ud->dl_primitive = DL_UNITDATA_IND;
+ ud->dl_dest_addr_length = sizeof(uint);
+ ud->dl_dest_addr_offset = sizeof(dl_unitdata_ind_t);
+ ud->dl_src_addr_length = sizeof(uint);
+ ud->dl_src_addr_offset = ud->dl_dest_addr_offset + sizeof(uint);
+#if DL_CURRENT_VERSION >= 2
+ ud->dl_group_address = 0;
+#endif
+ /* Send the DLPI client the data with the SAP they requested,
+ (e.g. ETHERTYPE_IP) rather than the PPP protocol number
+ (e.g. PPP_IP) */
+ ((uint *)(ud + 1))[0] = us->req_sap; /* dest SAP */
+ ((uint *)(ud + 1))[1] = us->req_sap; /* src SAP */
+ putnext(q, hdr);
+#else /* NO_DLPI */
+ putnext(q, mp);
+#endif /* NO_DLPI */
+ }
+ /*
+ * Now that we have consumed some packets from this queue,
+ * enable the control stream's read service routine so that we
+ * can process any packets for us that might have got queued
+ * there for flow control reasons.
+ */
+ if (us->ppa)
+ qenable(us->ppa->q);
+ }
+
+ return 0;
+}
+
+static upperstr_t *
+find_dest(ppa, proto)
+ upperstr_t *ppa;
+ int proto;
+{
+ upperstr_t *us;
+
+ for (us = ppa->next; us != 0; us = us->next)
+ if (proto == us->sap)
+ break;
+ return us;
+}
+
+/*
+ * We simply put the message on to the associated upper control stream
+ * (either here or in ppplrsrv). That way we enter the perimeters
+ * before looking through the list of attached streams to decide which
+ * stream it should go up.
+ */
+static int
+ppplrput(q, mp)
+ queue_t *q;
+ mblk_t *mp;
+{
+ queue_t *uq;
+
+ /*
+ * If we can't get the lower lock straight away, queue this one
+ * rather than blocking, to avoid the possibility of deadlock.
+ */
+ if (!TRYLOCK_LOWER_R) {
+ putq(q, mp);
+ return 0;
+ }
+
+ /*
+ * Check that we're still connected to the driver.
+ */
+ uq = (queue_t *) q->q_ptr;
+ if (uq == 0) {
+ UNLOCK_LOWER;
+ DPRINT1("ppplrput: q = %x, uq = 0??\n", q);
+ freemsg(mp);
+ return 0;
+ }
+
+ /*
+ * Try to forward the message to the put routine for the upper
+ * control stream for this lower stream.
+ * If there are already messages queued here, queue this one so
+ * they don't get out of order.
+ */
+ if (queclass(mp) == QPCTL || (qsize(q) == 0 && canput(uq)))
+ put(uq, mp);
+ else
+ putq(q, mp);
+
+ UNLOCK_LOWER;
+ return 0;
+}
+
+static int
+ppplrsrv(q)
+ queue_t *q;
+{
+ mblk_t *mp;
+ queue_t *uq;
+
+ /*
+ * Packets get queued here for flow control reasons
+ * or if the lrput routine couldn't get the lower lock
+ * without blocking.
+ */
+ LOCK_LOWER_R;
+ uq = (queue_t *) q->q_ptr;
+ if (uq == 0) {
+ UNLOCK_LOWER;
+ flushq(q, FLUSHALL);
+ DPRINT1("ppplrsrv: q = %x, uq = 0??\n", q);
+ return 0;
+ }
+ while ((mp = getq(q)) != 0) {
+ if (queclass(mp) == QPCTL || canput(uq))
+ put(uq, mp);
+ else {
+ putbq(q, mp);
+ break;