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.18 1999/03/22 05:55:59 paulus Exp $
31 * This file is used under Solaris 2, SVR4, SunOS 4, and Digital UNIX.
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>
41 #include <sys/ioctl.h>
42 #include <sys/cmn_err.h>
43 #define queclass(mp) ((mp)->b_band & QPCTL)
45 #include <sys/ioccom.h>
49 #include <sys/cmn_err.h>
54 #include <sys/ksynch.h>
55 #include <sys/kstat.h>
56 #include <sys/sunddi.h>
58 #include <sys/socket.h>
59 #include <sys/sockio.h>
61 #include <netinet/in.h>
66 #include <net/ppp_defs.h>
67 #include <net/pppio.h>
71 * Modifications marked with #ifdef PRIOQ are for priority queueing of
72 * interactive traffic, and are due to Marko Zec <zec@japa.tel.fer.hr>.
75 #include <netinet/in.h>
85 * The IP module may use this SAP value for IP packets.
88 #define ETHERTYPE_IP 0x800
95 * We use this reader-writer lock to ensure that the lower streams
96 * stay connected to the upper streams while the lower-side put and
97 * service procedures are running. Essentially it is an existence
98 * lock for the upper stream associated with each lower stream.
100 krwlock_t ppp_lower_lock;
101 #define LOCK_LOWER_W rw_enter(&ppp_lower_lock, RW_WRITER)
102 #define LOCK_LOWER_R rw_enter(&ppp_lower_lock, RW_READER)
103 #define TRYLOCK_LOWER_R rw_tryenter(&ppp_lower_lock, RW_READER)
104 #define UNLOCK_LOWER rw_exit(&ppp_lower_lock)
106 #define MT_ENTER(x) mutex_enter(x)
107 #define MT_EXIT(x) mutex_exit(x)
110 * Notes on multithreaded implementation for Solaris 2:
112 * We use an inner perimeter around each queue pair and an outer
113 * perimeter around the whole driver. The inner perimeter is
114 * entered exclusively for all entry points (open, close, put,
115 * service). The outer perimeter is entered exclusively for open
116 * and close and shared for put and service. This is all done for
117 * us by the streams framework.
119 * I used to think that the perimeters were entered for the lower
120 * streams' put and service routines as well as for the upper streams'.
121 * Because of problems experienced by people, and after reading the
122 * documentation more closely, I now don't think that is true. So we
123 * now use ppp_lower_lock to give us an existence guarantee on the
124 * upper stream controlling each lower stream.
126 * Shared entry to the outer perimeter protects the existence of all
127 * the upper streams and their upperstr_t structures, and guarantees
128 * that the following fields of any upperstr_t won't change:
129 * nextmn, next, nextppa. It guarantees that the lowerq field of an
130 * upperstr_t won't go from non-zero to zero, that the global `ppas'
131 * won't change and that the no lower stream will get unlinked.
133 * Shared (reader) access to ppa_lower_lock guarantees that no lower
134 * stream will be unlinked and that the lowerq field of all upperstr_t
135 * structures won't change.
139 #define LOCK_LOWER_W 0
140 #define LOCK_LOWER_R 0
141 #define TRYLOCK_LOWER_R 1
142 #define UNLOCK_LOWER 0
143 #define MT_ENTER(x) 0
149 * Private information; one per upper stream.
151 typedef struct upperstr {
152 minor_t mn; /* minor device number */
153 struct upperstr *nextmn; /* next minor device */
154 queue_t *q; /* read q associated with this upper stream */
155 int flags; /* flag bits, see below */
156 int state; /* current DLPI state */
157 int sap; /* service access point */
158 int req_sap; /* which SAP the DLPI client requested */
159 struct upperstr *ppa; /* control stream for our ppa */
160 struct upperstr *next; /* next stream for this ppa */
161 uint ioc_id; /* last ioctl ID for this stream */
162 enum NPmode npmode; /* what to do with packets on this SAP */
163 unsigned char rblocked; /* flow control has blocked upper read strm */
164 /* N.B. rblocked is only changed by control stream's put/srv procs */
166 * There is exactly one control stream for each PPA.
167 * The following fields are only used for control streams.
170 queue_t *lowerq; /* write queue attached below this PPA */
171 struct upperstr *nextppa; /* next control stream */
174 struct pppstat stats; /* statistics */
175 time_t last_sent; /* time last NP packet sent */
176 time_t last_recv; /* time last NP packet rcvd */
178 kmutex_t stats_lock; /* lock for stats updates */
179 kstat_t *kstats; /* stats for netstat */
183 char ifname[IFNAMSIZ];
184 struct ifstats ifstats;
188 /* Values for flags */
189 #define US_PRIV 1 /* stream was opened by superuser */
190 #define US_CONTROL 2 /* stream is a control stream */
191 #define US_BLOCKED 4 /* flow ctrl has blocked lower write stream */
192 #define US_LASTMOD 8 /* no PPP modules below us */
193 #define US_DBGLOG 0x10 /* log various occurrences */
194 #define US_RBLOCKED 0x20 /* flow ctrl has blocked upper read stream */
198 static u_char max_band=0;
199 static u_char def_band=0;
201 #define IPPORT_DEFAULT 65535
204 * Port priority table
205 * Highest priority ports are listed first, lowest are listed last.
206 * ICMP & packets using unlisted ports will be treated as "default".
207 * If IPPORT_DEFAULT is not listed here, "default" packets will be
208 * assigned lowest priority.
209 * Each line should be terminated with "0".
210 * Line containing only "0" marks the end of the list.
213 static u_short prioq_table[]= {
215 22, 23, 513, 517, 518, 0,
219 20, 70, 80, 8001, 8008, 8080, 0, /* 8001,8008,8080 - common proxy ports */
225 static upperstr_t *minor_devs = NULL;
226 static upperstr_t *ppas = NULL;
229 static int pppopen __P((queue_t *, dev_t *, int, int, cred_t *));
230 static int pppclose __P((queue_t *, int, cred_t *));
232 static int pppopen __P((queue_t *, int, int, int));
233 static int pppclose __P((queue_t *, int));
235 static int pppurput __P((queue_t *, mblk_t *));
236 static int pppuwput __P((queue_t *, mblk_t *));
237 static int pppursrv __P((queue_t *));
238 static int pppuwsrv __P((queue_t *));
239 static int ppplrput __P((queue_t *, mblk_t *));
240 static int ppplwput __P((queue_t *, mblk_t *));
241 static int ppplrsrv __P((queue_t *));
242 static int ppplwsrv __P((queue_t *));
244 static void dlpi_request __P((queue_t *, mblk_t *, upperstr_t *));
245 static void dlpi_error __P((queue_t *, upperstr_t *, int, int, int));
246 static void dlpi_ok __P((queue_t *, int));
248 static int send_data __P((mblk_t *, upperstr_t *));
249 static void new_ppa __P((queue_t *, mblk_t *));
250 static void attach_ppa __P((queue_t *, mblk_t *));
251 static void detach_ppa __P((queue_t *, mblk_t *));
252 static void detach_lower __P((queue_t *, mblk_t *));
253 static void debug_dump __P((queue_t *, mblk_t *));
254 static upperstr_t *find_dest __P((upperstr_t *, int));
255 static int putctl2 __P((queue_t *, int, int, int));
256 static int putctl4 __P((queue_t *, int, int, int));
257 static int pass_packet __P((upperstr_t *ppa, mblk_t *mp, int outbound));
258 static int ip_hard_filter __P((upperstr_t *ppa, mblk_t *mp, int outbound));
260 #define PPP_ID 0xb1a6
261 static struct module_info ppp_info = {
263 PPP_ID, "ppp", 0, 512, 512, 384
265 PPP_ID, "ppp", 0, 512, 512, 128
269 static struct qinit pppurint = {
270 pppurput, pppursrv, pppopen, pppclose, NULL, &ppp_info, NULL
273 static struct qinit pppuwint = {
274 pppuwput, pppuwsrv, NULL, NULL, NULL, &ppp_info, NULL
277 static struct qinit ppplrint = {
278 ppplrput, ppplrsrv, NULL, NULL, NULL, &ppp_info, NULL
281 static struct qinit ppplwint = {
282 ppplwput, ppplwsrv, NULL, NULL, NULL, &ppp_info, NULL
286 extern struct ifstats *ifstats;
290 struct streamtab pppinfo = {
291 &pppurint, &pppuwint,
298 * How we maintain statistics.
301 #define INCR_IPACKETS(ppa) \
302 if (ppa->kstats != 0) { \
303 KSTAT_NAMED_PTR(ppa->kstats)[0].value.ul++; \
305 #define INCR_IERRORS(ppa) \
306 if (ppa->kstats != 0) { \
307 KSTAT_NAMED_PTR(ppa->kstats)[1].value.ul++; \
309 #define INCR_OPACKETS(ppa) \
310 if (ppa->kstats != 0) { \
311 KSTAT_NAMED_PTR(ppa->kstats)[2].value.ul++; \
313 #define INCR_OERRORS(ppa) \
314 if (ppa->kstats != 0) { \
315 KSTAT_NAMED_PTR(ppa->kstats)[3].value.ul++; \
320 #define INCR_IPACKETS(ppa) ppa->ifstats.ifs_ipackets++;
321 #define INCR_IERRORS(ppa) ppa->ifstats.ifs_ierrors++;
322 #define INCR_OPACKETS(ppa) ppa->ifstats.ifs_opackets++;
323 #define INCR_OERRORS(ppa) ppa->ifstats.ifs_oerrors++;
327 * STREAMS driver entry points.
331 pppopen(q, devp, oflag, sflag, credp)
337 pppopen(q, dev, oflag, sflag)
339 int dev; /* really dev_t */
352 DRV_OPEN_OK(dev); /* device is already open */
355 /* Calculate max_bband & def_band from definitions in prioq.h
356 This colud be done at some more approtiate time (less often)
357 but this way it works well so I'll just leave it here */
365 if (*ptr++ == IPPORT_DEFAULT) {
369 max_band += new_band;
373 def_band = max_band - def_band;
377 if (sflag == CLONEOPEN) {
379 for (prevp = &minor_devs; (up = *prevp) != 0; prevp = &up->nextmn) {
386 mn = getminor(*devp);
390 for (prevp = &minor_devs; (up = *prevp) != 0; prevp = &up->nextmn) {
395 /* this can't happen */
396 q->q_ptr = WR(q)->q_ptr = (caddr_t) up;
402 * Construct a new minor node.
404 up = (upperstr_t *) ALLOC_SLEEP(sizeof(upperstr_t));
405 bzero((caddr_t) up, sizeof(upperstr_t));
407 DPRINT("pppopen: out of kernel memory\n");
414 *devp = makedevice(getmajor(*devp), mn);
418 up->flags |= US_PRIV;
420 up->state = DL_UNATTACHED;
423 up->ifflags = IFF_UP | IFF_POINTOPOINT;
426 up->last_sent = up->last_recv = time;
427 up->npmode = NPMODE_DROP;
428 q->q_ptr = (caddr_t) up;
429 WR(q)->q_ptr = (caddr_t) up;
432 mutex_init(&up->stats_lock, NULL, MUTEX_DRIVER, NULL);
437 DRV_OPEN_OK(makedev(major(dev), mn));
442 pppclose(q, flag, credp)
452 upperstr_t *up, **upp;
453 upperstr_t *as, *asnext;
458 up = (upperstr_t *) q->q_ptr;
460 DPRINT("pppclose: q_ptr = 0\n");
463 if (up->flags & US_DBGLOG)
464 DPRINT2("ppp/%d: close, flags=%x\n", up->mn, up->flags);
465 if (up->flags & US_CONTROL) {
467 struct ifstats *ifp, *pifp;
469 if (up->lowerq != 0) {
470 /* Gack! the lower stream should have be unlinked earlier! */
471 DPRINT1("ppp%d: lower stream still connected on close?\n",
474 up->lowerq->q_ptr = 0;
475 RD(up->lowerq)->q_ptr = 0;
481 * This stream represents a PPA:
482 * For all streams attached to the PPA, clear their
483 * references to this PPA.
484 * Then remove this PPA from the list of PPAs.
486 for (as = up->next; as != 0; as = asnext) {
490 if (as->flags & US_BLOCKED) {
491 as->flags &= ~US_BLOCKED;
492 flushq(WR(as->q), FLUSHDATA);
495 for (upp = &ppas; *upp != 0; upp = &(*upp)->nextppa)
501 /* Remove the statistics from the active list. */
502 for (ifp = ifstats, pifp = 0; ifp; ifp = ifp->ifs_next) {
503 if (ifp == &up->ifstats) {
505 pifp->ifs_next = ifp->ifs_next;
507 ifstats = ifp->ifs_next;
515 * If this stream is attached to a PPA,
516 * remove it from the PPA's list.
518 if ((as = up->ppa) != 0) {
519 for (; as->next != 0; as = as->next)
520 if (as->next == up) {
529 kstat_delete(up->kstats);
530 mutex_destroy(&up->stats_lock);
536 for (prevp = &minor_devs; *prevp != 0; prevp = &(*prevp)->nextmn) {
542 FREE(up, sizeof(upperstr_t));
549 * A message from on high. We do one of three things:
551 * - put the message on the lower write stream
552 * - queue it for our service routine
559 upperstr_t *us, *usnext, *ppa, *os, *nps;
569 struct ppp_idle *pip;
575 us = (upperstr_t *) q->q_ptr;
577 DPRINT("pppuwput: q_ptr = 0!\n");
581 DPRINT1("pppuwput/%d: mp = 0!\n", us->mn);
584 if (mp->b_datap == 0) {
585 DPRINT1("pppuwput/%d: mp->b_datap = 0!\n", us->mn);
588 switch (mp->b_datap->db_type) {
592 dlpi_request(q, mp, us);
597 if (us->flags & US_DBGLOG)
598 DPRINT3("ppp/%d: uwput M_DATA len=%d flags=%x\n",
599 us->mn, msgdsize(mp), us->flags);
600 if (us->ppa == 0 || msgdsize(mp) > us->ppa->mtu + PPP_HDRLEN
602 || (us->flags & US_CONTROL) == 0
605 DPRINT1("pppuwput: junk data len=%d\n", msgdsize(mp));
610 if ((us->flags & US_CONTROL) == 0 && !pass_packet(us, mp, 1))
613 if (!send_data(mp, us))
618 iop = (struct iocblk *) mp->b_rptr;
620 if (us->flags & US_DBGLOG)
621 DPRINT3("ppp/%d: ioctl %x count=%d\n",
622 us->mn, iop->ioc_cmd, iop->ioc_count);
623 switch (iop->ioc_cmd) {
625 if ((us->flags & US_CONTROL) == 0 || us->lowerq != 0)
627 if (mp->b_cont == 0) {
628 DPRINT1("pppuwput/%d: ioctl I_LINK b_cont = 0!\n", us->mn);
631 lb = (struct linkblk *) mp->b_cont->b_rptr;
634 DPRINT1("pppuwput/%d: ioctl I_LINK l_qbot = 0!\n", us->mn);
639 lq->q_ptr = (caddr_t) q;
640 RD(lq)->q_ptr = (caddr_t) us->q;
644 us->flags &= ~US_LASTMOD;
645 /* Unblock upper streams which now feed this lower stream. */
647 /* Send useful information down to the modules which
648 are now linked below us. */
649 putctl2(lq, M_CTL, PPPCTL_UNIT, us->ppa_id);
650 putctl4(lq, M_CTL, PPPCTL_MRU, us->mru);
651 putctl4(lq, M_CTL, PPPCTL_MTU, us->mtu);
653 /* Lower tty driver's queue hiwat/lowat from default 4096/128
654 to 256/128 since we don't want queueing of data on
655 output to physical device */
658 for (tlq = lq; tlq->q_next != NULL; tlq = tlq->q_next)
660 strqset(tlq, QHIWAT, 0, 256);
661 strqset(tlq, QLOWAT, 0, 128);
667 if (mp->b_cont == 0) {
668 DPRINT1("pppuwput/%d: ioctl I_UNLINK b_cont = 0!\n", us->mn);
671 lb = (struct linkblk *) mp->b_cont->b_rptr;
673 if (us->lowerq != lb->l_qbot) {
674 DPRINT2("ppp unlink: lowerq=%x qbot=%x\n",
675 us->lowerq, lb->l_qbot);
680 qwriter(q, mp, detach_lower, PERIM_OUTER);
685 if (us->flags & US_CONTROL)
687 if ((us->flags & US_PRIV) == 0) {
691 /* Arrange to return an int */
692 if ((mq = mp->b_cont) == 0
693 || mq->b_datap->db_lim - mq->b_rptr < sizeof(int)) {
694 mq = allocb(sizeof(int), BPRI_HI);
704 iop->ioc_count = sizeof(int);
705 mq->b_wptr = mq->b_rptr + sizeof(int);
706 qwriter(q, mp, new_ppa, PERIM_OUTER);
711 /* like dlpi_attach, for programs which can't write to
712 the stream (like pppstats) */
713 if (iop->ioc_count != sizeof(int) || us->ppa != 0)
715 if (mp->b_cont == 0) {
716 DPRINT1("pppuwput/%d: ioctl PPPIO_ATTACH b_cont = 0!\n", us->mn);
719 n = *(int *)mp->b_cont->b_rptr;
720 for (ppa = ppas; ppa != 0; ppa = ppa->nextppa)
721 if (ppa->ppa_id == n)
727 qwriter(q, mp, attach_ppa, PERIM_OUTER);
733 /* Attach to a given SAP. */
734 if (iop->ioc_count != sizeof(int) || us->ppa == 0)
736 if (mp->b_cont == 0) {
737 DPRINT1("pppuwput/%d: ioctl PPPIO_BIND b_cont = 0!\n", us->mn);
740 n = *(int *)mp->b_cont->b_rptr;
741 /* n must be a valid PPP network protocol number. */
742 if (n < 0x21 || n > 0x3fff || (n & 0x101) != 1)
744 /* check that no other stream is bound to this sap already. */
745 for (os = us->ppa; os != 0; os = os->next)
757 if (iop->ioc_count != sizeof(int) || (us->flags & US_CONTROL) == 0)
759 if (mp->b_cont == 0) {
760 DPRINT1("pppuwput/%d: ioctl PPPIO_MRU b_cont = 0!\n", us->mn);
763 n = *(int *)mp->b_cont->b_rptr;
764 if (n <= 0 || n > PPP_MAXMRU)
770 putctl4(us->lowerq, M_CTL, PPPCTL_MRU, n);
776 if (iop->ioc_count != sizeof(int) || (us->flags & US_CONTROL) == 0)
778 if (mp->b_cont == 0) {
779 DPRINT1("pppuwput/%d: ioctl PPPIO_MTU b_cont = 0!\n", us->mn);
782 n = *(int *)mp->b_cont->b_rptr;
783 if (n <= 0 || n > PPP_MAXMTU)
787 /* The MTU reported in netstat, not used as IP max packet size! */
788 us->ifstats.ifs_mtu = n;
791 putctl4(us->lowerq, M_CTL, PPPCTL_MTU, n);
797 us->flags |= US_LASTMOD;
802 if (iop->ioc_count != sizeof(int))
804 if (mp->b_cont == 0) {
805 DPRINT1("pppuwput/%d: ioctl PPPIO_DEBUG b_cont = 0!\n", us->mn);
808 n = *(int *)mp->b_cont->b_rptr;
809 if (n == PPPDBG_DUMP + PPPDBG_DRIVER) {
810 qwriter(q, NULL, debug_dump, PERIM_OUTER);
813 } else if (n == PPPDBG_LOG + PPPDBG_DRIVER) {
814 DPRINT1("ppp/%d: debug log enabled\n", us->mn);
815 us->flags |= US_DBGLOG;
819 if (us->ppa == 0 || us->ppa->lowerq == 0)
821 putnext(us->ppa->lowerq, mp);
827 if (iop->ioc_count != 2 * sizeof(int))
829 if ((us->flags & US_CONTROL) == 0)
831 if (mp->b_cont == 0) {
832 DPRINT1("pppuwput/%d: ioctl PPPIO_NPMODE b_cont = 0!\n", us->mn);
835 sap = ((int *)mp->b_cont->b_rptr)[0];
836 for (nps = us->next; nps != 0; nps = nps->next)
840 if (us->flags & US_DBGLOG)
841 DPRINT2("ppp/%d: no stream for sap %x\n", us->mn, sap);
844 /* XXX possibly should use qwriter here */
845 nps->npmode = (enum NPmode) ((int *)mp->b_cont->b_rptr)[1];
846 if (nps->npmode != NPMODE_QUEUE && (nps->flags & US_BLOCKED) != 0)
853 if ((ppa = us->ppa) == 0)
855 mq = allocb(sizeof(struct ppp_idle), BPRI_HI);
864 pip = (struct ppp_idle *) mq->b_wptr;
865 pip->xmit_idle = time - ppa->last_sent;
866 pip->recv_idle = time - ppa->last_recv;
867 mq->b_wptr += sizeof(struct ppp_idle);
868 iop->ioc_count = sizeof(struct ppp_idle);
874 /* Sent from IP down to us. Attach the ifstats structure. */
875 if (iop->ioc_count != sizeof(struct ifreq) || us->ppa == 0)
877 ifr = (struct ifreq *)mp->b_cont->b_rptr;
878 /* Find the unit number in the interface name. */
879 for (i = 0; i < IFNAMSIZ; i++) {
880 if (ifr->ifr_name[i] == 0 ||
881 (ifr->ifr_name[i] >= '0' &&
882 ifr->ifr_name[i] <= '9'))
885 us->ifname[i] = ifr->ifr_name[i];
889 /* Convert the unit number to binary. */
890 for (n = 0; i < IFNAMSIZ; i++) {
891 if (ifr->ifr_name[i] == 0) {
895 n = n * 10 + ifr->ifr_name[i] - '0';
899 /* Verify the ppa. */
900 if (us->ppa->ppa_id != n)
904 /* Set up the netstat block. */
905 strncpy (ppa->ifname, us->ifname, IFNAMSIZ);
907 ppa->ifstats.ifs_name = ppa->ifname;
908 ppa->ifstats.ifs_unit = n;
909 ppa->ifstats.ifs_active = us->state != DL_UNBOUND;
910 ppa->ifstats.ifs_mtu = ppa->mtu;
912 /* Link in statistics used by netstat. */
913 ppa->ifstats.ifs_next = ifstats;
914 ifstats = &ppa->ifstats;
921 if (!(us->flags & US_CONTROL)) {
927 ((struct iocblk_in *)iop)->ioc_ifflags = us->ifflags;
932 if (!(us->flags & US_CONTROL)) {
938 us->ifflags = ((struct iocblk_in *)iop)->ioc_ifflags;
943 if (!(us->flags & US_CONTROL)) {
949 us->ifflags |= IFF_RUNNING;
950 ((struct iocblk_in *)iop)->ioc_ifflags |= IFF_RUNNING;
956 * Vanilla SVR4 systems don't handle SIOCSIFMTU, rather
957 * they take the MTU from the DL_INFO_ACK we sent in response
958 * to their DL_INFO_REQ. Fortunately, they will update the
959 * MTU if we send an unsolicited DL_INFO_ACK up.
961 if ((mq = allocb(sizeof(dl_info_req_t), BPRI_HI)) == 0)
962 break; /* should do bufcall */
963 ((union DL_primitives *)mq->b_rptr)->dl_primitive = DL_INFO_REQ;
964 mq->b_wptr = mq->b_rptr + sizeof(dl_info_req_t);
965 dlpi_request(q, mq, us);
980 if (us->ppa == 0 || us->ppa->lowerq == 0)
982 us->ioc_id = iop->ioc_id;
984 switch (iop->ioc_cmd) {
987 if (us->flags & US_LASTMOD) {
991 putnext(us->ppa->lowerq, mp);
994 if (us->flags & US_PRIV)
995 putnext(us->ppa->lowerq, mp);
997 DPRINT1("ppp ioctl %x rejected\n", iop->ioc_cmd);
1006 iop->ioc_error = error;
1007 mp->b_datap->db_type = M_IOCNAK;
1009 } else if (error == 0) {
1010 mp->b_datap->db_type = M_IOCACK;
1016 if (us->flags & US_DBGLOG)
1017 DPRINT2("ppp/%d: flush %x\n", us->mn, *mp->b_rptr);
1018 if (*mp->b_rptr & FLUSHW)
1019 flushq(q, FLUSHDATA);
1020 if (*mp->b_rptr & FLUSHR) {
1021 *mp->b_rptr &= ~FLUSHW;
1036 dlpi_request(q, mp, us)
1041 union DL_primitives *d = (union DL_primitives *) mp->b_rptr;
1042 int size = mp->b_wptr - mp->b_rptr;
1044 upperstr_t *ppa, *os;
1046 dl_info_ack_t *info;
1047 dl_bind_ack_t *ackp;
1049 if (us->flags & US_DBGLOG)
1050 DPRINT3("ppp/%d: dlpi prim %x len=%d\n", us->mn,
1051 d->dl_primitive, size);
1052 switch (d->dl_primitive) {
1054 if (size < sizeof(dl_info_req_t))
1056 if ((reply = allocb(sizeof(dl_info_ack_t), BPRI_HI)) == 0)
1057 break; /* should do bufcall */
1058 reply->b_datap->db_type = M_PCPROTO;
1059 info = (dl_info_ack_t *) reply->b_wptr;
1060 reply->b_wptr += sizeof(dl_info_ack_t);
1061 bzero((caddr_t) info, sizeof(dl_info_ack_t));
1062 info->dl_primitive = DL_INFO_ACK;
1063 info->dl_max_sdu = us->ppa? us->ppa->mtu: PPP_MAXMTU;
1064 info->dl_min_sdu = 1;
1065 info->dl_addr_length = sizeof(uint);
1068 info->dl_mac_type = DL_OTHER;
1070 info->dl_mac_type = DL_HDLC; /* a lie */
1073 info->dl_mac_type = DL_ETHER; /* a bigger lie */
1075 info->dl_current_state = us->state;
1076 info->dl_service_mode = DL_CLDLS;
1077 info->dl_provider_style = DL_STYLE2;
1078 #if DL_CURRENT_VERSION >= 2
1079 info->dl_sap_length = sizeof(uint);
1080 info->dl_version = DL_CURRENT_VERSION;
1086 if (size < sizeof(dl_attach_req_t))
1088 if (us->state != DL_UNATTACHED || us->ppa != 0) {
1089 dlpi_error(q, us, DL_ATTACH_REQ, DL_OUTSTATE, 0);
1092 for (ppa = ppas; ppa != 0; ppa = ppa->nextppa)
1093 if (ppa->ppa_id == d->attach_req.dl_ppa)
1096 dlpi_error(q, us, DL_ATTACH_REQ, DL_BADPPA, 0);
1100 qwriter(q, mp, attach_ppa, PERIM_OUTER);
1104 if (size < sizeof(dl_detach_req_t))
1106 if (us->state != DL_UNBOUND || us->ppa == 0) {
1107 dlpi_error(q, us, DL_DETACH_REQ, DL_OUTSTATE, 0);
1110 qwriter(q, mp, detach_ppa, PERIM_OUTER);
1114 if (size < sizeof(dl_bind_req_t))
1116 if (us->state != DL_UNBOUND || us->ppa == 0) {
1117 dlpi_error(q, us, DL_BIND_REQ, DL_OUTSTATE, 0);
1121 /* apparently this test fails (unnecessarily?) on some systems */
1122 if (d->bind_req.dl_service_mode != DL_CLDLS) {
1123 dlpi_error(q, us, DL_BIND_REQ, DL_UNSUPPORTED, 0);
1128 /* saps must be valid PPP network protocol numbers,
1129 except that we accept ETHERTYPE_IP in place of PPP_IP. */
1130 sap = d->bind_req.dl_sap;
1132 if (sap == ETHERTYPE_IP)
1134 if (sap < 0x21 || sap > 0x3fff || (sap & 0x101) != 1) {
1135 dlpi_error(q, us, DL_BIND_REQ, DL_BADADDR, 0);
1139 /* check that no other stream is bound to this sap already. */
1140 for (os = us->ppa; os != 0; os = os->next)
1144 dlpi_error(q, us, DL_BIND_REQ, DL_NOADDR, 0);
1149 us->state = DL_IDLE;
1151 if ((reply = allocb(sizeof(dl_bind_ack_t) + sizeof(uint),
1153 break; /* should do bufcall */
1154 ackp = (dl_bind_ack_t *) reply->b_wptr;
1155 reply->b_wptr += sizeof(dl_bind_ack_t) + sizeof(uint);
1156 reply->b_datap->db_type = M_PCPROTO;
1157 bzero((caddr_t) ackp, sizeof(dl_bind_ack_t));
1158 ackp->dl_primitive = DL_BIND_ACK;
1160 ackp->dl_addr_length = sizeof(uint);
1161 ackp->dl_addr_offset = sizeof(dl_bind_ack_t);
1162 *(uint *)(ackp+1) = sap;
1167 if (size < sizeof(dl_unbind_req_t))
1169 if (us->state != DL_IDLE) {
1170 dlpi_error(q, us, DL_UNBIND_REQ, DL_OUTSTATE, 0);
1174 us->state = DL_UNBOUND;
1176 us->ppa->ifstats.ifs_active = 0;
1178 dlpi_ok(q, DL_UNBIND_REQ);
1181 case DL_UNITDATA_REQ:
1182 if (size < sizeof(dl_unitdata_req_t))
1184 if (us->state != DL_IDLE) {
1185 dlpi_error(q, us, DL_UNITDATA_REQ, DL_OUTSTATE, 0);
1188 if ((ppa = us->ppa) == 0) {
1189 cmn_err(CE_CONT, "ppp: in state dl_idle but ppa == 0?\n");
1192 len = mp->b_cont == 0? 0: msgdsize(mp->b_cont);
1193 if (len > ppa->mtu) {
1194 DPRINT2("dlpi data too large (%d > %d)\n", len, ppa->mtu);
1199 /* Extract s_port & d_port from IP-packet, the code is a bit
1200 dirty here, but so am I, too... */
1201 if (mp->b_datap->db_type == M_PROTO && us->sap == PPP_IP
1202 && mp->b_cont != 0) {
1206 u_char band_unset, cur_band, syn;
1207 u_short s_port, d_port;
1209 bb = mp->b_cont->b_rptr; /* bb points to IP-header*/
1210 len = mp->b_cont->b_wptr - mp->b_cont->b_rptr;
1212 s_port = IPPORT_DEFAULT;
1213 d_port = IPPORT_DEFAULT;
1214 if (len >= 20) { /* 20 = minimum length of IP header */
1215 iphlen = (bb[0] & 0x0f) * 4;
1220 if (len >= 20) { /* min length of TCP header */
1221 s_port = (tlh[0] << 8) + tlh[1];
1222 d_port = (tlh[2] << 8) + tlh[3];
1223 syn = tlh[13] & 0x02;
1227 if (len >= 8) { /* min length of UDP header */
1228 s_port = (tlh[0] << 8) + tlh[1];
1229 d_port = (tlh[2] << 8) + tlh[3];
1236 * Now calculate b_band for this packet from the
1237 * port-priority table.
1240 cur_band = max_band;
1243 while (*ptr && band_unset)
1244 if (s_port == *ptr || d_port == *ptr++) {
1245 mp->b_band = cur_band;
1253 mp->b_band = def_band;
1254 /* It may be usable to urge SYN packets a bit */
1259 /* this assumes PPP_HDRLEN <= sizeof(dl_unitdata_req_t) */
1260 if (mp->b_datap->db_ref > 1) {
1261 np = allocb(PPP_HDRLEN, BPRI_HI);
1264 np->b_cont = mp->b_cont;
1269 mp->b_datap->db_type = M_DATA;
1270 /* XXX should use dl_dest_addr_offset/length here,
1271 but we would have to translate ETHERTYPE_IP -> PPP_IP */
1272 mp->b_wptr = mp->b_rptr + PPP_HDRLEN;
1273 mp->b_rptr[0] = PPP_ALLSTATIONS;
1274 mp->b_rptr[1] = PPP_UI;
1275 mp->b_rptr[2] = us->sap >> 8;
1276 mp->b_rptr[3] = us->sap;
1277 if (pass_packet(us, mp, 1)) {
1278 if (!send_data(mp, us))
1283 #if DL_CURRENT_VERSION >= 2
1284 case DL_SUBS_BIND_REQ:
1285 case DL_SUBS_UNBIND_REQ:
1286 case DL_ENABMULTI_REQ:
1287 case DL_DISABMULTI_REQ:
1288 case DL_PROMISCON_REQ:
1289 case DL_PROMISCOFF_REQ:
1290 case DL_PHYS_ADDR_REQ:
1291 case DL_SET_PHYS_ADDR_REQ:
1294 case DL_REPLY_UPDATE_REQ:
1296 case DL_DATA_ACK_REQ:
1298 case DL_CONNECT_REQ:
1300 dlpi_error(q, us, d->dl_primitive, DL_NOTSUPPORTED, 0);
1303 case DL_CONNECT_RES:
1304 case DL_DISCONNECT_REQ:
1307 dlpi_error(q, us, d->dl_primitive, DL_OUTSTATE, 0);
1311 dlpi_error(q, us, d->dl_primitive, DL_BADQOSTYPE, 0);
1314 #if DL_CURRENT_VERSION >= 2
1321 cmn_err(CE_CONT, "ppp: unknown dlpi prim 0x%x\n", d->dl_primitive);
1324 dlpi_error(q, us, d->dl_primitive, DL_BADPRIM, 0);
1331 dlpi_error(q, us, prim, err, uerr)
1334 int prim, err, uerr;
1337 dl_error_ack_t *errp;
1339 if (us->flags & US_DBGLOG)
1340 DPRINT3("ppp/%d: dlpi error, prim=%x, err=%x\n", us->mn, prim, err);
1341 reply = allocb(sizeof(dl_error_ack_t), BPRI_HI);
1343 return; /* XXX should do bufcall */
1344 reply->b_datap->db_type = M_PCPROTO;
1345 errp = (dl_error_ack_t *) reply->b_wptr;
1346 reply->b_wptr += sizeof(dl_error_ack_t);
1347 errp->dl_primitive = DL_ERROR_ACK;
1348 errp->dl_error_primitive = prim;
1349 errp->dl_errno = err;
1350 errp->dl_unix_errno = uerr;
1362 reply = allocb(sizeof(dl_ok_ack_t), BPRI_HI);
1364 return; /* XXX should do bufcall */
1365 reply->b_datap->db_type = M_PCPROTO;
1366 okp = (dl_ok_ack_t *) reply->b_wptr;
1367 reply->b_wptr += sizeof(dl_ok_ack_t);
1368 okp->dl_primitive = DL_OK_ACK;
1369 okp->dl_correct_primitive = prim;
1372 #endif /* NO_DLPI */
1375 pass_packet(us, mp, outbound)
1383 if ((ppa = us->ppa) == 0) {
1388 #ifdef FILTER_PACKETS
1389 pass = ip_hard_filter(us, mp, outbound);
1392 * Here is where we might, in future, decide whether to pass
1393 * or drop the packet, and whether it counts as link activity.
1396 #endif /* FILTER_PACKETS */
1399 /* pass only if link already up, and don't update time */
1400 if (ppa->lowerq == 0) {
1407 ppa->last_sent = time;
1409 ppa->last_recv = time;
1416 * We have some data to send down to the lower stream (or up the
1417 * control stream, if we don't have a lower stream attached).
1418 * Returns 1 if the message was dealt with, 0 if it wasn't able
1419 * to be sent on and should therefore be queued up.
1429 if ((us->flags & US_BLOCKED) || us->npmode == NPMODE_QUEUE)
1432 if (ppa == 0 || us->npmode == NPMODE_DROP || us->npmode == NPMODE_ERROR) {
1433 if (us->flags & US_DBGLOG)
1434 DPRINT2("ppp/%d: dropping pkt (npmode=%d)\n", us->mn, us->npmode);
1438 if ((q = ppa->lowerq) == 0) {
1439 /* try to send it up the control stream */
1440 if (bcanputnext(ppa->q, mp->b_band)) {
1442 * The message seems to get corrupted for some reason if
1443 * we just send the message up as it is, so we send a copy.
1445 mblk_t *np = copymsg(mp);
1448 putnext(ppa->q, np);
1452 if (bcanputnext(ppa->lowerq, mp->b_band)) {
1453 MT_ENTER(&ppa->stats_lock);
1454 ppa->stats.ppp_opackets++;
1455 ppa->stats.ppp_obytes += msgdsize(mp);
1456 #ifdef INCR_OPACKETS
1459 MT_EXIT(&ppa->stats_lock);
1461 * The lower queue is only ever detached while holding an
1462 * exclusive lock on the whole driver. So we can be confident
1463 * that the lower queue is still there.
1465 putnext(ppa->lowerq, mp);
1469 us->flags |= US_BLOCKED;
1474 * Allocate a new PPA id and link this stream into the list of PPAs.
1475 * This procedure is called with an exclusive lock on all queues in
1483 upperstr_t *us, *up, **usp;
1486 us = (upperstr_t *) q->q_ptr;
1488 DPRINT("new_ppa: q_ptr = 0!\n");
1494 while ((up = *usp) != 0 && ppa_id == up->ppa_id) {
1498 us->ppa_id = ppa_id;
1503 us->flags |= US_CONTROL;
1504 us->npmode = NPMODE_PASS;
1511 * Create a kstats record for our statistics, so netstat -i works.
1513 if (us->kstats == 0) {
1516 sprintf(unit, "ppp%d", us->ppa->ppa_id);
1517 us->kstats = kstat_create("ppp", us->ppa->ppa_id, unit,
1518 "net", KSTAT_TYPE_NAMED, 4, 0);
1519 if (us->kstats != 0) {
1520 kstat_named_t *kn = KSTAT_NAMED_PTR(us->kstats);
1522 strcpy(kn[0].name, "ipackets");
1523 kn[0].data_type = KSTAT_DATA_ULONG;
1524 strcpy(kn[1].name, "ierrors");
1525 kn[1].data_type = KSTAT_DATA_ULONG;
1526 strcpy(kn[2].name, "opackets");
1527 kn[2].data_type = KSTAT_DATA_ULONG;
1528 strcpy(kn[3].name, "oerrors");
1529 kn[3].data_type = KSTAT_DATA_ULONG;
1530 kstat_install(us->kstats);
1535 *(int *)mp->b_cont->b_rptr = ppa_id;
1536 mp->b_datap->db_type = M_IOCACK;
1547 us = (upperstr_t *) q->q_ptr;
1549 DPRINT("attach_ppa: q_ptr = 0!\n");
1554 us->state = DL_UNBOUND;
1556 for (t = us->ppa; t->next != 0; t = t->next)
1560 if (mp->b_datap->db_type == M_IOCTL) {
1561 mp->b_datap->db_type = M_IOCACK;
1565 dlpi_ok(q, DL_ATTACH_REQ);
1577 us = (upperstr_t *) q->q_ptr;
1579 DPRINT("detach_ppa: q_ptr = 0!\n");
1583 for (t = us->ppa; t->next != 0; t = t->next)
1584 if (t->next == us) {
1591 us->state = DL_UNATTACHED;
1592 dlpi_ok(q, DL_DETACH_REQ);
1597 * We call this with qwriter in order to give the upper queue procedures
1598 * the guarantee that the lower queue is not going to go away while
1599 * they are executing.
1608 us = (upperstr_t *) q->q_ptr;
1610 DPRINT("detach_lower: q_ptr = 0!\n");
1615 us->lowerq->q_ptr = 0;
1616 RD(us->lowerq)->q_ptr = 0;
1620 /* Unblock streams which now feed back up the control stream. */
1623 mp->b_datap->db_type = M_IOCACK;
1631 upperstr_t *us, *as;
1634 us = (upperstr_t *) q->q_ptr;
1636 DPRINT("pppuwsrv: q_ptr = 0!\n");
1641 * If this is a control stream, then this service procedure
1642 * probably got enabled because of flow control in the lower
1643 * stream being enabled (or because of the lower stream going
1644 * away). Therefore we enable the service procedure of all
1645 * attached upper streams.
1647 if (us->flags & US_CONTROL) {
1648 for (as = us->next; as != 0; as = as->next)
1652 /* Try to send on any data queued here. */
1653 us->flags &= ~US_BLOCKED;
1654 while ((mp = getq(q)) != 0) {
1655 if (!send_data(mp, us)) {
1664 /* should never get called... */
1681 * Flow control has back-enabled this stream:
1682 * enable the upper write service procedure for
1683 * the upper control stream for this lower stream.
1686 uq = (queue_t *) q->q_ptr;
1694 * This should only get called for control streams.
1701 upperstr_t *ppa, *us;
1707 ppa = (upperstr_t *) q->q_ptr;
1709 DPRINT("pppurput: q_ptr = 0!\n");
1713 switch (mp->b_datap->db_type) {
1715 MT_ENTER(&ppa->stats_lock);
1716 switch (*mp->b_rptr) {
1721 ppa->stats.ppp_ierrors++;
1727 ppa->stats.ppp_oerrors++;
1730 MT_EXIT(&ppa->stats_lock);
1737 * Attempt to match up the response with the stream
1738 * that the request came from.
1740 iop = (struct iocblk *) mp->b_rptr;
1741 for (us = ppa; us != 0; us = us->next)
1742 if (us->ioc_id == iop->ioc_id)
1752 * The serial device has hung up. We don't want to send
1753 * the M_HANGUP message up to pppd because that will stop
1754 * us from using the control stream any more. Instead we
1755 * send a zero-length message as an end-of-file indication.
1758 mp = allocb(1, BPRI_HI);
1760 DPRINT1("ppp/%d: couldn't allocate eof message!\n", ppa->mn);
1763 putnext(ppa->q, mp);
1767 if (mp->b_datap->db_type == M_DATA) {
1769 if (mp->b_wptr - mp->b_rptr < PPP_HDRLEN) {
1770 PULLUP(mp, PPP_HDRLEN);
1772 DPRINT1("ppp_urput: msgpullup failed (len=%d)\n", len);
1776 MT_ENTER(&ppa->stats_lock);
1777 ppa->stats.ppp_ipackets++;
1778 ppa->stats.ppp_ibytes += len;
1779 #ifdef INCR_IPACKETS
1782 MT_EXIT(&ppa->stats_lock);
1784 proto = PPP_PROTOCOL(mp->b_rptr);
1785 if (proto < 0x8000 && (us = find_dest(ppa, proto)) != 0) {
1787 * A data packet for some network protocol.
1788 * Queue it on the upper stream for that protocol.
1789 * XXX could we just putnext it? (would require thought)
1790 * The rblocked flag is there to ensure that we keep
1791 * messages in order for each network protocol.
1793 if (!pass_packet(us, mp, 0))
1795 if (!us->rblocked && !canput(us->q))
1805 * A control frame, a frame for an unknown protocol,
1806 * or some other message type.
1807 * Send it up to pppd via the control stream.
1809 if (queclass(mp) == QPCTL || canputnext(ppa->q))
1810 putnext(ppa->q, mp);
1823 upperstr_t *us, *as;
1826 dl_unitdata_ind_t *ud;
1830 us = (upperstr_t *) q->q_ptr;
1832 DPRINT("pppursrv: q_ptr = 0!\n");
1836 if (us->flags & US_CONTROL) {
1839 * If there is no lower queue attached, run the write service
1840 * routines of other upper streams attached to this PPA.
1842 if (us->lowerq == 0) {
1845 if (as->flags & US_BLOCKED)
1852 * Messages get queued on this stream's read queue if they
1853 * can't be queued on the read queue of the attached stream
1854 * that they are destined for. This is for flow control -
1855 * when this queue fills up, the lower read put procedure will
1856 * queue messages there and the flow control will propagate
1859 while ((mp = getq(q)) != 0) {
1860 proto = PPP_PROTOCOL(mp->b_rptr);
1861 if (proto < 0x8000 && (as = find_dest(us, proto)) != 0) {
1874 /* can now put stuff directly on network protocol streams again */
1875 for (as = us->next; as != 0; as = as->next)
1880 * If this stream has a lower stream attached,
1881 * enable the read queue's service routine.
1882 * XXX we should really only do this if the queue length
1883 * has dropped below the low-water mark.
1885 if (us->lowerq != 0)
1886 qenable(RD(us->lowerq));
1890 * A network protocol stream. Put a DLPI header on each
1891 * packet and send it on.
1892 * (Actually, it seems that the IP module will happily
1893 * accept M_DATA messages without the DL_UNITDATA_IND header.)
1895 while ((mp = getq(q)) != 0) {
1896 if (!canputnext(q)) {
1901 proto = PPP_PROTOCOL(mp->b_rptr);
1902 mp->b_rptr += PPP_HDRLEN;
1903 hdr = allocb(sizeof(dl_unitdata_ind_t) + 2 * sizeof(uint),
1906 /* XXX should put it back and use bufcall */
1910 hdr->b_datap->db_type = M_PROTO;
1911 ud = (dl_unitdata_ind_t *) hdr->b_wptr;
1912 hdr->b_wptr += sizeof(dl_unitdata_ind_t) + 2 * sizeof(uint);
1914 ud->dl_primitive = DL_UNITDATA_IND;
1915 ud->dl_dest_addr_length = sizeof(uint);
1916 ud->dl_dest_addr_offset = sizeof(dl_unitdata_ind_t);
1917 ud->dl_src_addr_length = sizeof(uint);
1918 ud->dl_src_addr_offset = ud->dl_dest_addr_offset + sizeof(uint);
1919 #if DL_CURRENT_VERSION >= 2
1920 ud->dl_group_address = 0;
1922 /* Send the DLPI client the data with the SAP they requested,
1923 (e.g. ETHERTYPE_IP) rather than the PPP protocol number
1925 ((uint *)(ud + 1))[0] = us->req_sap; /* dest SAP */
1926 ((uint *)(ud + 1))[1] = us->req_sap; /* src SAP */
1930 #endif /* NO_DLPI */
1933 * Now that we have consumed some packets from this queue,
1934 * enable the control stream's read service routine so that we
1935 * can process any packets for us that might have got queued
1936 * there for flow control reasons.
1939 qenable(us->ppa->q);
1946 find_dest(ppa, proto)
1952 for (us = ppa->next; us != 0; us = us->next)
1953 if (proto == us->sap)
1959 * We simply put the message on to the associated upper control stream
1960 * (either here or in ppplrsrv). That way we enter the perimeters
1961 * before looking through the list of attached streams to decide which
1962 * stream it should go up.
1972 switch (mp->b_datap->db_type) {
1974 iop = (struct iocblk *) mp->b_rptr;
1975 iop->ioc_error = EINVAL;
1976 mp->b_datap->db_type = M_IOCNAK;
1980 if (*mp->b_rptr & FLUSHR)
1981 flushq(q, FLUSHDATA);
1982 if (*mp->b_rptr & FLUSHW) {
1983 *mp->b_rptr &= ~FLUSHR;
1991 * If we can't get the lower lock straight away, queue this one
1992 * rather than blocking, to avoid the possibility of deadlock.
1994 if (!TRYLOCK_LOWER_R) {
2000 * Check that we're still connected to the driver.
2002 uq = (queue_t *) q->q_ptr;
2005 DPRINT1("ppplrput: q = %x, uq = 0??\n", q);
2011 * Try to forward the message to the put routine for the upper
2012 * control stream for this lower stream.
2013 * If there are already messages queued here, queue this one so
2014 * they don't get out of order.
2016 if (queclass(mp) == QPCTL || (qsize(q) == 0 && canput(uq)))
2033 * Packets get queued here for flow control reasons
2034 * or if the lrput routine couldn't get the lower lock
2038 uq = (queue_t *) q->q_ptr;
2041 flushq(q, FLUSHALL);
2042 DPRINT1("ppplrsrv: q = %x, uq = 0??\n", q);
2045 while ((mp = getq(q)) != 0) {
2046 if (queclass(mp) == QPCTL || canput(uq))
2058 putctl2(q, type, code, val)
2060 int type, code, val;
2064 mp = allocb(2, BPRI_HI);
2067 mp->b_datap->db_type = type;
2068 mp->b_wptr[0] = code;
2069 mp->b_wptr[1] = val;
2076 putctl4(q, type, code, val)
2078 int type, code, val;
2082 mp = allocb(4, BPRI_HI);
2085 mp->b_datap->db_type = type;
2086 mp->b_wptr[0] = code;
2087 ((short *)mp->b_wptr)[1] = val;
2095 queue_t *q; /* not used */
2096 mblk_t *mp; /* not used either */
2101 DPRINT("ppp upper streams:\n");
2102 for (us = minor_devs; us != 0; us = us->nextmn) {
2104 DPRINT3(" %d: q=%x rlev=%d",
2105 us->mn, uq, (uq? qsize(uq): 0));
2106 DPRINT3(" wlev=%d flags=0x%b", (uq? qsize(WR(uq)): 0),
2107 us->flags, "\020\1priv\2control\3blocked\4last");
2108 DPRINT3(" state=%x sap=%x req_sap=%x", us->state, us->sap,
2113 DPRINT1(" ppa=%d\n", us->ppa->ppa_id);
2114 if (us->flags & US_CONTROL) {
2116 DPRINT3(" control for %d lq=%x rlev=%d",
2117 us->ppa_id, lq, (lq? qsize(RD(lq)): 0));
2118 DPRINT3(" wlev=%d mru=%d mtu=%d\n",
2119 (lq? qsize(lq): 0), us->mru, us->mtu);
2124 #ifdef FILTER_PACKETS
2125 #include <netinet/in_systm.h>
2126 #include <netinet/ip.h>
2127 #include <netinet/udp.h>
2128 #include <netinet/tcp.h>
2130 #define MAX_IPHDR 128 /* max TCP/IP header size */
2133 /* The following table contains a hard-coded list of protocol/port pairs.
2134 * Any matching packets are either discarded unconditionally, or,
2135 * if ok_if_link_up is non-zero when a connection does not currently exist
2136 * (i.e., they go through if the connection is present, but never initiate
2138 * This idea came from a post by dm@garage.uun.org (David Mazieres)
2140 static struct pktfilt_tab {
2143 u_short ok_if_link_up;
2145 { IPPROTO_UDP, 520, 1 }, /* RIP, ok to pass if link is up */
2146 { IPPROTO_UDP, 123, 1 }, /* NTP, don't keep up the link for it */
2147 { -1, 0, 0 } /* terminator entry has port == -1 */
2152 ip_hard_filter(us, mp, outbound)
2158 struct pktfilt_tab *pft;
2164 /* Note, the PPP header has already been pulled up in all cases */
2165 proto = PPP_PROTOCOL(mp->b_rptr);
2166 if (us->flags & US_DBGLOG)
2167 DPRINT3("ppp/%d: filter, proto=0x%x, out=%d\n", us->mn, proto, outbound);
2172 if ((mp->b_wptr - mp->b_rptr) == PPP_HDRLEN && mp->b_cont != 0) {
2173 temp_mp = mp->b_cont;
2174 len = msgdsize(temp_mp);
2175 hlen = (len < MAX_IPHDR) ? len : MAX_IPHDR;
2176 PULLUP(temp_mp, hlen);
2178 DPRINT2("ppp/%d: filter, pullup next failed, len=%d\n",
2180 mp->b_cont = 0; /* PULLUP() freed the rest */
2184 ip = (struct ip *)mp->b_cont->b_rptr;
2188 hlen = (len < (PPP_HDRLEN+MAX_IPHDR)) ? len : (PPP_HDRLEN+MAX_IPHDR);
2191 DPRINT2("ppp/%d: filter, pullup failed, len=%d\n",
2195 ip = (struct ip *)(mp->b_rptr + PPP_HDRLEN);
2198 /* For IP traffic, certain packets (e.g., RIP) may be either
2199 * 1. ignored - dropped completely
2200 * 2. will not initiate a connection, but
2201 * will be passed if a connection is currently up.
2203 for (pft=pktfilt_tab; pft->proto != -1; pft++) {
2204 if (ip->ip_p == pft->proto) {
2205 switch(pft->proto) {
2207 if (((struct udphdr *) &((int *)ip)[ip->ip_hl])->uh_dport
2208 == htons(pft->port)) goto endfor;
2211 if (((struct tcphdr *) &((int *)ip)[ip->ip_hl])->th_dport
2212 == htons(pft->port)) goto endfor;
2218 if (pft->proto != -1) {
2219 if (us->flags & US_DBGLOG)
2220 DPRINT3("ppp/%d: found IP pkt, proto=0x%x (%d)\n",
2221 us->mn, pft->proto, pft->port);
2222 /* Discard if not connected, or if not pass_with_link_up */
2223 /* else, if link is up let go by, but don't update time */
2224 return pft->ok_if_link_up? -1: 0;
2227 } /* end switch (proto) */
2231 #endif /* FILTER_PACKETS */