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.1.1.4 2003/10/14 08:09:54 sparq 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>
57 #include <sys/ethernet.h>
59 #include <sys/socket.h>
60 #include <sys/sockio.h>
62 #include <netinet/in.h>
67 #include <net/ppp_defs.h>
68 #include <net/pppio.h>
72 * Modifications marked with #ifdef PRIOQ are for priority queueing of
73 * interactive traffic, and are due to Marko Zec <zec@japa.tel.fer.hr>.
78 #include <netinet/in.h> /* leave this outside of PRIOQ for htons */
87 * The IP module may use this SAP value for IP packets.
90 #define ETHERTYPE_IP 0x800
93 #if !defined(ETHERTYPE_IPV6)
94 #define ETHERTYPE_IPV6 0x86dd
95 #endif /* !defined(ETHERTYPE_IPV6) */
97 #if !defined(ETHERTYPE_ALLSAP) && defined(SOL2)
98 #define ETHERTYPE_ALLSAP 0
99 #endif /* !defined(ETHERTYPE_ALLSAP) && defined(SOL2) */
101 #if !defined(PPP_ALLSAP) && defined(SOL2)
102 #define PPP_ALLSAP PPP_ALLSTATIONS
103 #endif /* !defined(PPP_ALLSAP) && defined(SOL2) */
109 * We use this reader-writer lock to ensure that the lower streams
110 * stay connected to the upper streams while the lower-side put and
111 * service procedures are running. Essentially it is an existence
112 * lock for the upper stream associated with each lower stream.
114 krwlock_t ppp_lower_lock
;
115 #define LOCK_LOWER_W rw_enter(&ppp_lower_lock, RW_WRITER)
116 #define LOCK_LOWER_R rw_enter(&ppp_lower_lock, RW_READER)
117 #define TRYLOCK_LOWER_R rw_tryenter(&ppp_lower_lock, RW_READER)
118 #define UNLOCK_LOWER rw_exit(&ppp_lower_lock)
120 #define MT_ENTER(x) mutex_enter(x)
121 #define MT_EXIT(x) mutex_exit(x)
124 * Notes on multithreaded implementation for Solaris 2:
126 * We use an inner perimeter around each queue pair and an outer
127 * perimeter around the whole driver. The inner perimeter is
128 * entered exclusively for all entry points (open, close, put,
129 * service). The outer perimeter is entered exclusively for open
130 * and close and shared for put and service. This is all done for
131 * us by the streams framework.
133 * I used to think that the perimeters were entered for the lower
134 * streams' put and service routines as well as for the upper streams'.
135 * Because of problems experienced by people, and after reading the
136 * documentation more closely, I now don't think that is true. So we
137 * now use ppp_lower_lock to give us an existence guarantee on the
138 * upper stream controlling each lower stream.
140 * Shared entry to the outer perimeter protects the existence of all
141 * the upper streams and their upperstr_t structures, and guarantees
142 * that the following fields of any upperstr_t won't change:
143 * nextmn, next, nextppa. It guarantees that the lowerq field of an
144 * upperstr_t won't go from non-zero to zero, that the global `ppas'
145 * won't change and that the no lower stream will get unlinked.
147 * Shared (reader) access to ppa_lower_lock guarantees that no lower
148 * stream will be unlinked and that the lowerq field of all upperstr_t
149 * structures won't change.
153 #define LOCK_LOWER_W 0
154 #define LOCK_LOWER_R 0
155 #define TRYLOCK_LOWER_R 1
156 #define UNLOCK_LOWER 0
157 #define MT_ENTER(x) 0
163 * Private information; one per upper stream.
165 typedef struct upperstr
{
166 minor_t mn
; /* minor device number */
167 struct upperstr
*nextmn
; /* next minor device */
168 queue_t
*q
; /* read q associated with this upper stream */
169 int flags
; /* flag bits, see below */
170 int state
; /* current DLPI state */
171 int sap
; /* service access point */
172 int req_sap
; /* which SAP the DLPI client requested */
173 struct upperstr
*ppa
; /* control stream for our ppa */
174 struct upperstr
*next
; /* next stream for this ppa */
175 uint ioc_id
; /* last ioctl ID for this stream */
176 enum NPmode npmode
; /* what to do with packets on this SAP */
177 unsigned char rblocked
; /* flow control has blocked upper read strm */
178 /* N.B. rblocked is only changed by control stream's put/srv procs */
180 * There is exactly one control stream for each PPA.
181 * The following fields are only used for control streams.
184 queue_t
*lowerq
; /* write queue attached below this PPA */
185 struct upperstr
*nextppa
; /* next control stream */
188 struct pppstat stats
; /* statistics */
189 time_t last_sent
; /* time last NP packet sent */
190 time_t last_recv
; /* time last NP packet rcvd */
192 kmutex_t stats_lock
; /* lock for stats updates */
193 kstat_t
*kstats
; /* stats for netstat */
197 char ifname
[IFNAMSIZ
];
198 struct ifstats ifstats
;
202 /* Values for flags */
203 #define US_PRIV 1 /* stream was opened by superuser */
204 #define US_CONTROL 2 /* stream is a control stream */
205 #define US_BLOCKED 4 /* flow ctrl has blocked lower write stream */
206 #define US_LASTMOD 8 /* no PPP modules below us */
207 #define US_DBGLOG 0x10 /* log various occurrences */
208 #define US_RBLOCKED 0x20 /* flow ctrl has blocked upper read stream */
211 #if DL_CURRENT_VERSION >= 2
212 #define US_PROMISC 0x40 /* stream is promiscuous */
213 #endif /* DL_CURRENT_VERSION >= 2 */
214 #define US_RAWDATA 0x80 /* raw M_DATA, no DLPI header */
215 #endif /* defined(SOL2) */
218 static u_char max_band
=0;
219 static u_char def_band
=0;
221 #define IPPORT_DEFAULT 65535
224 * Port priority table
225 * Highest priority ports are listed first, lowest are listed last.
226 * ICMP & packets using unlisted ports will be treated as "default".
227 * If IPPORT_DEFAULT is not listed here, "default" packets will be
228 * assigned lowest priority.
229 * Each line should be terminated with "0".
230 * Line containing only "0" marks the end of the list.
233 static u_short prioq_table
[]= {
235 22, 23, 513, 517, 518, 0,
239 20, 70, 80, 8001, 8008, 8080, 0, /* 8001,8008,8080 - common proxy ports */
245 static upperstr_t
*minor_devs
= NULL
;
246 static upperstr_t
*ppas
= NULL
;
249 static int pppopen
__P((queue_t
*, dev_t
*, int, int, cred_t
*));
250 static int pppclose
__P((queue_t
*, int, cred_t
*));
252 static int pppopen
__P((queue_t
*, int, int, int));
253 static int pppclose
__P((queue_t
*, int));
255 static int pppurput
__P((queue_t
*, mblk_t
*));
256 static int pppuwput
__P((queue_t
*, mblk_t
*));
257 static int pppursrv
__P((queue_t
*));
258 static int pppuwsrv
__P((queue_t
*));
259 static int ppplrput
__P((queue_t
*, mblk_t
*));
260 static int ppplwput
__P((queue_t
*, mblk_t
*));
261 static int ppplrsrv
__P((queue_t
*));
262 static int ppplwsrv
__P((queue_t
*));
264 static void dlpi_request
__P((queue_t
*, mblk_t
*, upperstr_t
*));
265 static void dlpi_error
__P((queue_t
*, upperstr_t
*, int, int, int));
266 static void dlpi_ok
__P((queue_t
*, int));
268 static int send_data
__P((mblk_t
*, upperstr_t
*));
269 static void new_ppa
__P((queue_t
*, mblk_t
*));
270 static void attach_ppa
__P((queue_t
*, mblk_t
*));
271 static void detach_ppa
__P((queue_t
*, mblk_t
*));
272 static void detach_lower
__P((queue_t
*, mblk_t
*));
273 static void debug_dump
__P((queue_t
*, mblk_t
*));
274 static upperstr_t
*find_dest
__P((upperstr_t
*, int));
276 static upperstr_t
*find_promisc
__P((upperstr_t
*, int));
277 static mblk_t
*prepend_ether
__P((upperstr_t
*, mblk_t
*, int));
278 static mblk_t
*prepend_udind
__P((upperstr_t
*, mblk_t
*, int));
279 static void promisc_sendup
__P((upperstr_t
*, mblk_t
*, int, int));
280 #endif /* defined(SOL2) */
281 static int putctl2
__P((queue_t
*, int, int, int));
282 static int putctl4
__P((queue_t
*, int, int, int));
283 static int pass_packet
__P((upperstr_t
*ppa
, mblk_t
*mp
, int outbound
));
284 #ifdef FILTER_PACKETS
285 static int ip_hard_filter
__P((upperstr_t
*ppa
, mblk_t
*mp
, int outbound
));
286 #endif /* FILTER_PACKETS */
288 #define PPP_ID 0xb1a6
289 static struct module_info ppp_info
= {
291 PPP_ID
, "ppp", 0, 512, 512, 384
293 PPP_ID
, "ppp", 0, 512, 512, 128
297 static struct qinit pppurint
= {
298 pppurput
, pppursrv
, pppopen
, pppclose
, NULL
, &ppp_info
, NULL
301 static struct qinit pppuwint
= {
302 pppuwput
, pppuwsrv
, NULL
, NULL
, NULL
, &ppp_info
, NULL
305 static struct qinit ppplrint
= {
306 ppplrput
, ppplrsrv
, NULL
, NULL
, NULL
, &ppp_info
, NULL
309 static struct qinit ppplwint
= {
310 ppplwput
, ppplwsrv
, NULL
, NULL
, NULL
, &ppp_info
, NULL
314 extern struct ifstats
*ifstats
;
318 struct streamtab pppinfo
= {
319 &pppurint
, &pppuwint
,
326 * How we maintain statistics.
329 #define INCR_IPACKETS(ppa) \
330 if (ppa->kstats != 0) { \
331 KSTAT_NAMED_PTR(ppa->kstats)[0].value.ul++; \
333 #define INCR_IERRORS(ppa) \
334 if (ppa->kstats != 0) { \
335 KSTAT_NAMED_PTR(ppa->kstats)[1].value.ul++; \
337 #define INCR_OPACKETS(ppa) \
338 if (ppa->kstats != 0) { \
339 KSTAT_NAMED_PTR(ppa->kstats)[2].value.ul++; \
341 #define INCR_OERRORS(ppa) \
342 if (ppa->kstats != 0) { \
343 KSTAT_NAMED_PTR(ppa->kstats)[3].value.ul++; \
348 #define INCR_IPACKETS(ppa) ppa->ifstats.ifs_ipackets++;
349 #define INCR_IERRORS(ppa) ppa->ifstats.ifs_ierrors++;
350 #define INCR_OPACKETS(ppa) ppa->ifstats.ifs_opackets++;
351 #define INCR_OERRORS(ppa) ppa->ifstats.ifs_oerrors++;
355 * STREAMS driver entry points.
359 pppopen(q
, devp
, oflag
, sflag
, credp
)
365 pppopen(q
, dev
, oflag
, sflag
)
367 int dev
; /* really dev_t */
380 DRV_OPEN_OK(dev
); /* device is already open */
383 /* Calculate max_bband & def_band from definitions in prioq.h
384 This colud be done at some more approtiate time (less often)
385 but this way it works well so I'll just leave it here */
393 if (*ptr
++ == IPPORT_DEFAULT
) {
397 max_band
+= new_band
;
401 def_band
= max_band
- def_band
;
405 if (sflag
== CLONEOPEN
) {
407 for (prevp
= &minor_devs
; (up
= *prevp
) != 0; prevp
= &up
->nextmn
) {
414 mn
= getminor(*devp
);
418 for (prevp
= &minor_devs
; (up
= *prevp
) != 0; prevp
= &up
->nextmn
) {
423 /* this can't happen */
424 q
->q_ptr
= WR(q
)->q_ptr
= (caddr_t
) up
;
430 * Construct a new minor node.
432 up
= (upperstr_t
*) ALLOC_SLEEP(sizeof(upperstr_t
));
433 bzero((caddr_t
) up
, sizeof(upperstr_t
));
435 DPRINT("pppopen: out of kernel memory\n");
442 *devp
= makedevice(getmajor(*devp
), mn
);
446 up
->flags
|= US_PRIV
;
448 up
->state
= DL_UNATTACHED
;
451 up
->ifflags
= IFF_UP
| IFF_POINTOPOINT
;
454 up
->last_sent
= up
->last_recv
= time
;
455 up
->npmode
= NPMODE_DROP
;
456 q
->q_ptr
= (caddr_t
) up
;
457 WR(q
)->q_ptr
= (caddr_t
) up
;
460 mutex_init(&up
->stats_lock
, NULL
, MUTEX_DRIVER
, NULL
);
465 DRV_OPEN_OK(makedev(major(dev
), mn
));
470 pppclose(q
, flag
, credp
)
480 upperstr_t
*up
, **upp
;
481 upperstr_t
*as
, *asnext
;
486 up
= (upperstr_t
*) q
->q_ptr
;
488 DPRINT("pppclose: q_ptr = 0\n");
491 if (up
->flags
& US_DBGLOG
)
492 DPRINT2("ppp/%d: close, flags=%x\n", up
->mn
, up
->flags
);
493 if (up
->flags
& US_CONTROL
) {
495 struct ifstats
*ifp
, *pifp
;
497 if (up
->lowerq
!= 0) {
498 /* Gack! the lower stream should have be unlinked earlier! */
499 DPRINT1("ppp%d: lower stream still connected on close?\n",
502 up
->lowerq
->q_ptr
= 0;
503 RD(up
->lowerq
)->q_ptr
= 0;
509 * This stream represents a PPA:
510 * For all streams attached to the PPA, clear their
511 * references to this PPA.
512 * Then remove this PPA from the list of PPAs.
514 for (as
= up
->next
; as
!= 0; as
= asnext
) {
518 if (as
->flags
& US_BLOCKED
) {
519 as
->flags
&= ~US_BLOCKED
;
520 flushq(WR(as
->q
), FLUSHDATA
);
523 for (upp
= &ppas
; *upp
!= 0; upp
= &(*upp
)->nextppa
)
529 /* Remove the statistics from the active list. */
530 for (ifp
= ifstats
, pifp
= 0; ifp
; ifp
= ifp
->ifs_next
) {
531 if (ifp
== &up
->ifstats
) {
533 pifp
->ifs_next
= ifp
->ifs_next
;
535 ifstats
= ifp
->ifs_next
;
543 * If this stream is attached to a PPA,
544 * remove it from the PPA's list.
546 if ((as
= up
->ppa
) != 0) {
547 for (; as
->next
!= 0; as
= as
->next
)
548 if (as
->next
== up
) {
557 kstat_delete(up
->kstats
);
558 mutex_destroy(&up
->stats_lock
);
564 for (prevp
= &minor_devs
; *prevp
!= 0; prevp
= &(*prevp
)->nextmn
) {
570 FREE(up
, sizeof(upperstr_t
));
577 * A message from on high. We do one of three things:
579 * - put the message on the lower write stream
580 * - queue it for our service routine
587 upperstr_t
*us
, *ppa
, *nps
;
597 struct ppp_idle
*pip
;
605 us
= (upperstr_t
*) q
->q_ptr
;
607 DPRINT("pppuwput: q_ptr = 0!\n");
611 DPRINT1("pppuwput/%d: mp = 0!\n", us
->mn
);
614 if (mp
->b_datap
== 0) {
615 DPRINT1("pppuwput/%d: mp->b_datap = 0!\n", us
->mn
);
618 switch (mp
->b_datap
->db_type
) {
622 dlpi_request(q
, mp
, us
);
627 if (us
->flags
& US_DBGLOG
)
628 DPRINT3("ppp/%d: uwput M_DATA len=%d flags=%x\n",
629 us
->mn
, msgdsize(mp
), us
->flags
);
630 if (us
->ppa
== 0 || msgdsize(mp
) > us
->ppa
->mtu
+ PPP_HDRLEN
632 || (us
->flags
& US_CONTROL
) == 0
635 DPRINT1("pppuwput: junk data len=%d\n", msgdsize(mp
));
640 if ((us
->flags
& US_CONTROL
) == 0 && !pass_packet(us
, mp
, 1))
643 if (!send_data(mp
, us
))
648 iop
= (struct iocblk
*) mp
->b_rptr
;
650 if (us
->flags
& US_DBGLOG
)
651 DPRINT3("ppp/%d: ioctl %x count=%d\n",
652 us
->mn
, iop
->ioc_cmd
, iop
->ioc_count
);
653 switch (iop
->ioc_cmd
) {
655 case DLIOCRAW
: /* raw M_DATA mode */
656 us
->flags
|= US_RAWDATA
;
659 #endif /* defined(SOL2) */
661 if ((us
->flags
& US_CONTROL
) == 0 || us
->lowerq
!= 0)
663 if (mp
->b_cont
== 0) {
664 DPRINT1("pppuwput/%d: ioctl I_LINK b_cont = 0!\n", us
->mn
);
667 lb
= (struct linkblk
*) mp
->b_cont
->b_rptr
;
670 DPRINT1("pppuwput/%d: ioctl I_LINK l_qbot = 0!\n", us
->mn
);
675 lq
->q_ptr
= (caddr_t
) q
;
676 RD(lq
)->q_ptr
= (caddr_t
) us
->q
;
680 us
->flags
&= ~US_LASTMOD
;
681 /* Unblock upper streams which now feed this lower stream. */
683 /* Send useful information down to the modules which
684 are now linked below us. */
685 putctl2(lq
, M_CTL
, PPPCTL_UNIT
, us
->ppa_id
);
686 putctl4(lq
, M_CTL
, PPPCTL_MRU
, us
->mru
);
687 putctl4(lq
, M_CTL
, PPPCTL_MTU
, us
->mtu
);
689 /* Lower tty driver's queue hiwat/lowat from default 4096/128
690 to 256/128 since we don't want queueing of data on
691 output to physical device */
694 for (tlq
= lq
; tlq
->q_next
!= NULL
; tlq
= tlq
->q_next
)
696 strqset(tlq
, QHIWAT
, 0, 256);
697 strqset(tlq
, QLOWAT
, 0, 128);
703 if (mp
->b_cont
== 0) {
704 DPRINT1("pppuwput/%d: ioctl I_UNLINK b_cont = 0!\n", us
->mn
);
707 lb
= (struct linkblk
*) mp
->b_cont
->b_rptr
;
709 if (us
->lowerq
!= lb
->l_qbot
) {
710 DPRINT2("ppp unlink: lowerq=%x qbot=%x\n",
711 us
->lowerq
, lb
->l_qbot
);
716 qwriter(q
, mp
, detach_lower
, PERIM_OUTER
);
721 if (us
->flags
& US_CONTROL
)
723 if ((us
->flags
& US_PRIV
) == 0) {
727 /* Arrange to return an int */
728 if ((mq
= mp
->b_cont
) == 0
729 || mq
->b_datap
->db_lim
- mq
->b_rptr
< sizeof(int)) {
730 mq
= allocb(sizeof(int), BPRI_HI
);
740 iop
->ioc_count
= sizeof(int);
741 mq
->b_wptr
= mq
->b_rptr
+ sizeof(int);
742 qwriter(q
, mp
, new_ppa
, PERIM_OUTER
);
747 /* like dlpi_attach, for programs which can't write to
748 the stream (like pppstats) */
749 if (iop
->ioc_count
!= sizeof(int) || us
->ppa
!= 0)
751 if (mp
->b_cont
== 0) {
752 DPRINT1("pppuwput/%d: ioctl PPPIO_ATTACH b_cont = 0!\n", us
->mn
);
755 n
= *(int *)mp
->b_cont
->b_rptr
;
756 for (ppa
= ppas
; ppa
!= 0; ppa
= ppa
->nextppa
)
757 if (ppa
->ppa_id
== n
)
763 qwriter(q
, mp
, attach_ppa
, PERIM_OUTER
);
769 /* Attach to a given SAP. */
770 if (iop
->ioc_count
!= sizeof(int) || us
->ppa
== 0)
772 if (mp
->b_cont
== 0) {
773 DPRINT1("pppuwput/%d: ioctl PPPIO_BIND b_cont = 0!\n", us
->mn
);
776 n
= *(int *)mp
->b_cont
->b_rptr
;
777 /* n must be a valid PPP network protocol number. */
778 if (n
< 0x21 || n
> 0x3fff || (n
& 0x101) != 1)
780 /* check that no other stream is bound to this sap already. */
781 for (os
= us
->ppa
; os
!= 0; os
= os
->next
)
793 if (iop
->ioc_count
!= sizeof(int) || (us
->flags
& US_CONTROL
) == 0)
795 if (mp
->b_cont
== 0) {
796 DPRINT1("pppuwput/%d: ioctl PPPIO_MRU b_cont = 0!\n", us
->mn
);
799 n
= *(int *)mp
->b_cont
->b_rptr
;
800 if (n
<= 0 || n
> PPP_MAXMRU
)
806 putctl4(us
->lowerq
, M_CTL
, PPPCTL_MRU
, n
);
812 if (iop
->ioc_count
!= sizeof(int) || (us
->flags
& US_CONTROL
) == 0)
814 if (mp
->b_cont
== 0) {
815 DPRINT1("pppuwput/%d: ioctl PPPIO_MTU b_cont = 0!\n", us
->mn
);
818 n
= *(int *)mp
->b_cont
->b_rptr
;
819 if (n
<= 0 || n
> PPP_MAXMTU
)
823 /* The MTU reported in netstat, not used as IP max packet size! */
824 us
->ifstats
.ifs_mtu
= n
;
827 putctl4(us
->lowerq
, M_CTL
, PPPCTL_MTU
, n
);
833 us
->flags
|= US_LASTMOD
;
838 if (iop
->ioc_count
!= sizeof(int))
840 if (mp
->b_cont
== 0) {
841 DPRINT1("pppuwput/%d: ioctl PPPIO_DEBUG b_cont = 0!\n", us
->mn
);
844 n
= *(int *)mp
->b_cont
->b_rptr
;
845 if (n
== PPPDBG_DUMP
+ PPPDBG_DRIVER
) {
846 qwriter(q
, NULL
, debug_dump
, PERIM_OUTER
);
849 } else if (n
== PPPDBG_LOG
+ PPPDBG_DRIVER
) {
850 DPRINT1("ppp/%d: debug log enabled\n", us
->mn
);
851 us
->flags
|= US_DBGLOG
;
855 if (us
->ppa
== 0 || us
->ppa
->lowerq
== 0)
857 putnext(us
->ppa
->lowerq
, mp
);
863 if (iop
->ioc_count
!= 2 * sizeof(int))
865 if ((us
->flags
& US_CONTROL
) == 0)
867 if (mp
->b_cont
== 0) {
868 DPRINT1("pppuwput/%d: ioctl PPPIO_NPMODE b_cont = 0!\n", us
->mn
);
871 sap
= ((int *)mp
->b_cont
->b_rptr
)[0];
872 for (nps
= us
->next
; nps
!= 0; nps
= nps
->next
) {
873 if (us
->flags
& US_DBGLOG
)
874 DPRINT2("us = 0x%x, us->next->sap = 0x%x\n", nps
, nps
->sap
);
879 if (us
->flags
& US_DBGLOG
)
880 DPRINT2("ppp/%d: no stream for sap %x\n", us
->mn
, sap
);
883 nps
->npmode
= (enum NPmode
) ((int *)mp
->b_cont
->b_rptr
)[1];
884 if (nps
->npmode
!= NPMODE_QUEUE
&& (nps
->flags
& US_BLOCKED
) != 0)
891 if ((ppa
= us
->ppa
) == 0)
893 mq
= allocb(sizeof(struct ppp_idle
), BPRI_HI
);
902 pip
= (struct ppp_idle
*) mq
->b_wptr
;
903 pip
->xmit_idle
= time
- ppa
->last_sent
;
904 pip
->recv_idle
= time
- ppa
->last_recv
;
905 mq
->b_wptr
+= sizeof(struct ppp_idle
);
906 iop
->ioc_count
= sizeof(struct ppp_idle
);
912 /* Sent from IP down to us. Attach the ifstats structure. */
913 if (iop
->ioc_count
!= sizeof(struct ifreq
) || us
->ppa
== 0)
915 ifr
= (struct ifreq
*)mp
->b_cont
->b_rptr
;
916 /* Find the unit number in the interface name. */
917 for (i
= 0; i
< IFNAMSIZ
; i
++) {
918 if (ifr
->ifr_name
[i
] == 0 ||
919 (ifr
->ifr_name
[i
] >= '0' &&
920 ifr
->ifr_name
[i
] <= '9'))
923 us
->ifname
[i
] = ifr
->ifr_name
[i
];
927 /* Convert the unit number to binary. */
928 for (n
= 0; i
< IFNAMSIZ
; i
++) {
929 if (ifr
->ifr_name
[i
] == 0) {
933 n
= n
* 10 + ifr
->ifr_name
[i
] - '0';
937 /* Verify the ppa. */
938 if (us
->ppa
->ppa_id
!= n
)
942 /* Set up the netstat block. */
943 strncpy (ppa
->ifname
, us
->ifname
, IFNAMSIZ
);
945 ppa
->ifstats
.ifs_name
= ppa
->ifname
;
946 ppa
->ifstats
.ifs_unit
= n
;
947 ppa
->ifstats
.ifs_active
= us
->state
!= DL_UNBOUND
;
948 ppa
->ifstats
.ifs_mtu
= ppa
->mtu
;
950 /* Link in statistics used by netstat. */
951 ppa
->ifstats
.ifs_next
= ifstats
;
952 ifstats
= &ppa
->ifstats
;
959 if (!(us
->flags
& US_CONTROL
)) {
965 ((struct iocblk_in
*)iop
)->ioc_ifflags
= us
->ifflags
;
970 if (!(us
->flags
& US_CONTROL
)) {
976 us
->ifflags
= ((struct iocblk_in
*)iop
)->ioc_ifflags
;
981 if (!(us
->flags
& US_CONTROL
)) {
987 us
->ifflags
|= IFF_RUNNING
;
988 ((struct iocblk_in
*)iop
)->ioc_ifflags
|= IFF_RUNNING
;
994 * Vanilla SVR4 systems don't handle SIOCSIFMTU, rather
995 * they take the MTU from the DL_INFO_ACK we sent in response
996 * to their DL_INFO_REQ. Fortunately, they will update the
997 * MTU if we send an unsolicited DL_INFO_ACK up.
999 if ((mq
= allocb(sizeof(dl_info_req_t
), BPRI_HI
)) == 0)
1000 break; /* should do bufcall */
1001 ((union DL_primitives
*)mq
->b_rptr
)->dl_primitive
= DL_INFO_REQ
;
1002 mq
->b_wptr
= mq
->b_rptr
+ sizeof(dl_info_req_t
);
1003 dlpi_request(q
, mq
, us
);
1007 case SIOCGIFNETMASK
:
1008 case SIOCSIFNETMASK
:
1010 case SIOCGIFDSTADDR
:
1011 case SIOCSIFDSTADDR
:
1015 #endif /* LACHTCP */
1018 if (us
->ppa
== 0 || us
->ppa
->lowerq
== 0)
1020 us
->ioc_id
= iop
->ioc_id
;
1022 switch (iop
->ioc_cmd
) {
1024 case PPPIO_GETCSTAT
:
1025 if (us
->flags
& US_LASTMOD
) {
1029 putnext(us
->ppa
->lowerq
, mp
);
1032 if (us
->flags
& US_PRIV
)
1033 putnext(us
->ppa
->lowerq
, mp
);
1035 DPRINT1("ppp ioctl %x rejected\n", iop
->ioc_cmd
);
1044 iop
->ioc_error
= error
;
1045 mp
->b_datap
->db_type
= M_IOCNAK
;
1047 } else if (error
== 0) {
1048 mp
->b_datap
->db_type
= M_IOCACK
;
1054 if (us
->flags
& US_DBGLOG
)
1055 DPRINT2("ppp/%d: flush %x\n", us
->mn
, *mp
->b_rptr
);
1056 if (*mp
->b_rptr
& FLUSHW
)
1057 flushq(q
, FLUSHDATA
);
1058 if (*mp
->b_rptr
& FLUSHR
) {
1059 *mp
->b_rptr
&= ~FLUSHW
;
1074 dlpi_request(q
, mp
, us
)
1079 union DL_primitives
*d
= (union DL_primitives
*) mp
->b_rptr
;
1080 int size
= mp
->b_wptr
- mp
->b_rptr
;
1082 upperstr_t
*ppa
, *os
;
1084 dl_info_ack_t
*info
;
1085 dl_bind_ack_t
*ackp
;
1086 #if DL_CURRENT_VERSION >= 2
1087 dl_phys_addr_ack_t
*paddrack
;
1088 static struct ether_addr eaddr
= {0};
1091 if (us
->flags
& US_DBGLOG
)
1092 DPRINT3("ppp/%d: dlpi prim %x len=%d\n", us
->mn
,
1093 d
->dl_primitive
, size
);
1094 switch (d
->dl_primitive
) {
1096 if (size
< sizeof(dl_info_req_t
))
1098 if ((reply
= allocb(sizeof(dl_info_ack_t
), BPRI_HI
)) == 0)
1099 break; /* should do bufcall */
1100 reply
->b_datap
->db_type
= M_PCPROTO
;
1101 info
= (dl_info_ack_t
*) reply
->b_wptr
;
1102 reply
->b_wptr
+= sizeof(dl_info_ack_t
);
1103 bzero((caddr_t
) info
, sizeof(dl_info_ack_t
));
1104 info
->dl_primitive
= DL_INFO_ACK
;
1105 info
->dl_max_sdu
= us
->ppa
? us
->ppa
->mtu
: PPP_MAXMTU
;
1106 info
->dl_min_sdu
= 1;
1107 info
->dl_addr_length
= sizeof(uint
);
1108 info
->dl_mac_type
= DL_ETHER
; /* a bigger lie */
1109 info
->dl_current_state
= us
->state
;
1110 info
->dl_service_mode
= DL_CLDLS
;
1111 info
->dl_provider_style
= DL_STYLE2
;
1112 #if DL_CURRENT_VERSION >= 2
1113 info
->dl_sap_length
= sizeof(uint
);
1114 info
->dl_version
= DL_CURRENT_VERSION
;
1120 if (size
< sizeof(dl_attach_req_t
))
1122 if (us
->state
!= DL_UNATTACHED
|| us
->ppa
!= 0) {
1123 dlpi_error(q
, us
, DL_ATTACH_REQ
, DL_OUTSTATE
, 0);
1126 for (ppa
= ppas
; ppa
!= 0; ppa
= ppa
->nextppa
)
1127 if (ppa
->ppa_id
== d
->attach_req
.dl_ppa
)
1130 dlpi_error(q
, us
, DL_ATTACH_REQ
, DL_BADPPA
, 0);
1134 qwriter(q
, mp
, attach_ppa
, PERIM_OUTER
);
1138 if (size
< sizeof(dl_detach_req_t
))
1140 if (us
->state
!= DL_UNBOUND
|| us
->ppa
== 0) {
1141 dlpi_error(q
, us
, DL_DETACH_REQ
, DL_OUTSTATE
, 0);
1144 qwriter(q
, mp
, detach_ppa
, PERIM_OUTER
);
1148 if (size
< sizeof(dl_bind_req_t
))
1150 if (us
->state
!= DL_UNBOUND
|| us
->ppa
== 0) {
1151 dlpi_error(q
, us
, DL_BIND_REQ
, DL_OUTSTATE
, 0);
1155 /* saps must be valid PPP network protocol numbers,
1156 except that we accept ETHERTYPE_IP in place of PPP_IP. */
1157 sap
= d
->bind_req
.dl_sap
;
1161 if (us
->flags
& US_DBGLOG
)
1162 DPRINT2("DL_BIND_REQ: ip gives sap = 0x%x, us = 0x%x", sap
, us
);
1164 if (sap
== ETHERTYPE_IP
) /* normal IFF_IPV4 */
1166 else if (sap
== ETHERTYPE_IPV6
) /* when IFF_IPV6 is set */
1168 else if (sap
== ETHERTYPE_ALLSAP
) /* snoop gives sap of 0 */
1171 DPRINT2("DL_BIND_REQ: unrecognized sap = 0x%x, us = 0x%x", sap
, us
);
1172 dlpi_error(q
, us
, DL_BIND_REQ
, DL_BADADDR
, 0);
1176 if (sap
== ETHERTYPE_IP
)
1178 if (sap
< 0x21 || sap
> 0x3fff || (sap
& 0x101) != 1) {
1179 dlpi_error(q
, us
, DL_BIND_REQ
, DL_BADADDR
, 0);
1182 #endif /* defined(SOL2) */
1184 /* check that no other stream is bound to this sap already. */
1185 for (os
= us
->ppa
; os
!= 0; os
= os
->next
)
1189 dlpi_error(q
, us
, DL_BIND_REQ
, DL_NOADDR
, 0);
1194 us
->state
= DL_IDLE
;
1196 if ((reply
= allocb(sizeof(dl_bind_ack_t
) + sizeof(uint
),
1198 break; /* should do bufcall */
1199 ackp
= (dl_bind_ack_t
*) reply
->b_wptr
;
1200 reply
->b_wptr
+= sizeof(dl_bind_ack_t
) + sizeof(uint
);
1201 reply
->b_datap
->db_type
= M_PCPROTO
;
1202 bzero((caddr_t
) ackp
, sizeof(dl_bind_ack_t
));
1203 ackp
->dl_primitive
= DL_BIND_ACK
;
1205 ackp
->dl_addr_length
= sizeof(uint
);
1206 ackp
->dl_addr_offset
= sizeof(dl_bind_ack_t
);
1207 *(uint
*)(ackp
+1) = sap
;
1212 if (size
< sizeof(dl_unbind_req_t
))
1214 if (us
->state
!= DL_IDLE
) {
1215 dlpi_error(q
, us
, DL_UNBIND_REQ
, DL_OUTSTATE
, 0);
1219 us
->state
= DL_UNBOUND
;
1221 us
->ppa
->ifstats
.ifs_active
= 0;
1223 dlpi_ok(q
, DL_UNBIND_REQ
);
1226 case DL_UNITDATA_REQ
:
1227 if (size
< sizeof(dl_unitdata_req_t
))
1229 if (us
->state
!= DL_IDLE
) {
1230 dlpi_error(q
, us
, DL_UNITDATA_REQ
, DL_OUTSTATE
, 0);
1233 if ((ppa
= us
->ppa
) == 0) {
1234 cmn_err(CE_CONT
, "ppp: in state dl_idle but ppa == 0?\n");
1237 len
= mp
->b_cont
== 0? 0: msgdsize(mp
->b_cont
);
1238 if (len
> ppa
->mtu
) {
1239 DPRINT2("dlpi data too large (%d > %d)\n", len
, ppa
->mtu
);
1245 * Should there be any promiscuous stream(s), send the data
1246 * up for each promiscuous stream that we recognize.
1249 promisc_sendup(ppa
, mp
->b_cont
, us
->sap
, 0);
1250 #endif /* defined(SOL2) */
1254 /* Extract s_port & d_port from IP-packet, the code is a bit
1255 dirty here, but so am I, too... */
1256 if (mp
->b_datap
->db_type
== M_PROTO
&& us
->sap
== PPP_IP
1257 && mp
->b_cont
!= 0) {
1261 u_char band_unset
, cur_band
, syn
;
1262 u_short s_port
, d_port
;
1264 bb
= mp
->b_cont
->b_rptr
; /* bb points to IP-header*/
1265 len
= mp
->b_cont
->b_wptr
- mp
->b_cont
->b_rptr
;
1267 s_port
= IPPORT_DEFAULT
;
1268 d_port
= IPPORT_DEFAULT
;
1269 if (len
>= 20) { /* 20 = minimum length of IP header */
1270 iphlen
= (bb
[0] & 0x0f) * 4;
1275 if (len
>= 20) { /* min length of TCP header */
1276 s_port
= (tlh
[0] << 8) + tlh
[1];
1277 d_port
= (tlh
[2] << 8) + tlh
[3];
1278 syn
= tlh
[13] & 0x02;
1282 if (len
>= 8) { /* min length of UDP header */
1283 s_port
= (tlh
[0] << 8) + tlh
[1];
1284 d_port
= (tlh
[2] << 8) + tlh
[3];
1291 * Now calculate b_band for this packet from the
1292 * port-priority table.
1295 cur_band
= max_band
;
1298 while (*ptr
&& band_unset
)
1299 if (s_port
== *ptr
|| d_port
== *ptr
++) {
1300 mp
->b_band
= cur_band
;
1308 mp
->b_band
= def_band
;
1309 /* It may be usable to urge SYN packets a bit */
1314 /* this assumes PPP_HDRLEN <= sizeof(dl_unitdata_req_t) */
1315 if (mp
->b_datap
->db_ref
> 1) {
1316 np
= allocb(PPP_HDRLEN
, BPRI_HI
);
1319 np
->b_cont
= mp
->b_cont
;
1324 mp
->b_datap
->db_type
= M_DATA
;
1325 mp
->b_wptr
= mp
->b_rptr
+ PPP_HDRLEN
;
1326 mp
->b_rptr
[0] = PPP_ALLSTATIONS
;
1327 mp
->b_rptr
[1] = PPP_UI
;
1328 mp
->b_rptr
[2] = us
->sap
>> 8;
1329 mp
->b_rptr
[3] = us
->sap
;
1330 if (pass_packet(us
, mp
, 1)) {
1331 if (!send_data(mp
, us
))
1336 #if DL_CURRENT_VERSION >= 2
1337 case DL_PHYS_ADDR_REQ
:
1338 if (size
< sizeof(dl_phys_addr_req_t
))
1342 * Don't check state because ifconfig sends this one down too
1345 if ((reply
= allocb(sizeof(dl_phys_addr_ack_t
)+ETHERADDRL
,
1347 break; /* should do bufcall */
1348 reply
->b_datap
->db_type
= M_PCPROTO
;
1349 paddrack
= (dl_phys_addr_ack_t
*) reply
->b_wptr
;
1350 reply
->b_wptr
+= sizeof(dl_phys_addr_ack_t
);
1351 bzero((caddr_t
) paddrack
, sizeof(dl_phys_addr_ack_t
)+ETHERADDRL
);
1352 paddrack
->dl_primitive
= DL_PHYS_ADDR_ACK
;
1353 paddrack
->dl_addr_length
= ETHERADDRL
;
1354 paddrack
->dl_addr_offset
= sizeof(dl_phys_addr_ack_t
);
1355 bcopy(&eaddr
, reply
->b_wptr
, ETHERADDRL
);
1356 reply
->b_wptr
+= ETHERADDRL
;
1361 case DL_PROMISCON_REQ
:
1362 if (size
< sizeof(dl_promiscon_req_t
))
1364 us
->flags
|= US_PROMISC
;
1365 dlpi_ok(q
, DL_PROMISCON_REQ
);
1368 case DL_PROMISCOFF_REQ
:
1369 if (size
< sizeof(dl_promiscoff_req_t
))
1371 us
->flags
&= ~US_PROMISC
;
1372 dlpi_ok(q
, DL_PROMISCOFF_REQ
);
1375 case DL_PROMISCON_REQ
: /* fall thru */
1376 case DL_PROMISCOFF_REQ
: /* fall thru */
1377 #endif /* defined(SOL2) */
1378 #endif /* DL_CURRENT_VERSION >= 2 */
1380 #if DL_CURRENT_VERSION >= 2
1381 case DL_SET_PHYS_ADDR_REQ
:
1382 case DL_SUBS_BIND_REQ
:
1383 case DL_SUBS_UNBIND_REQ
:
1384 case DL_ENABMULTI_REQ
:
1385 case DL_DISABMULTI_REQ
:
1388 case DL_REPLY_UPDATE_REQ
:
1390 case DL_DATA_ACK_REQ
:
1392 case DL_CONNECT_REQ
:
1394 dlpi_error(q
, us
, d
->dl_primitive
, DL_NOTSUPPORTED
, 0);
1397 case DL_CONNECT_RES
:
1398 case DL_DISCONNECT_REQ
:
1401 dlpi_error(q
, us
, d
->dl_primitive
, DL_OUTSTATE
, 0);
1405 dlpi_error(q
, us
, d
->dl_primitive
, DL_BADQOSTYPE
, 0);
1408 #if DL_CURRENT_VERSION >= 2
1415 cmn_err(CE_CONT
, "ppp: unknown dlpi prim 0x%x\n", d
->dl_primitive
);
1418 dlpi_error(q
, us
, d
->dl_primitive
, DL_BADPRIM
, 0);
1425 dlpi_error(q
, us
, prim
, err
, uerr
)
1428 int prim
, err
, uerr
;
1431 dl_error_ack_t
*errp
;
1433 if (us
->flags
& US_DBGLOG
)
1434 DPRINT3("ppp/%d: dlpi error, prim=%x, err=%x\n", us
->mn
, prim
, err
);
1435 reply
= allocb(sizeof(dl_error_ack_t
), BPRI_HI
);
1438 reply
->b_datap
->db_type
= M_PCPROTO
;
1439 errp
= (dl_error_ack_t
*) reply
->b_wptr
;
1440 reply
->b_wptr
+= sizeof(dl_error_ack_t
);
1441 errp
->dl_primitive
= DL_ERROR_ACK
;
1442 errp
->dl_error_primitive
= prim
;
1443 errp
->dl_errno
= err
;
1444 errp
->dl_unix_errno
= uerr
;
1456 reply
= allocb(sizeof(dl_ok_ack_t
), BPRI_HI
);
1459 reply
->b_datap
->db_type
= M_PCPROTO
;
1460 okp
= (dl_ok_ack_t
*) reply
->b_wptr
;
1461 reply
->b_wptr
+= sizeof(dl_ok_ack_t
);
1462 okp
->dl_primitive
= DL_OK_ACK
;
1463 okp
->dl_correct_primitive
= prim
;
1466 #endif /* NO_DLPI */
1469 pass_packet(us
, mp
, outbound
)
1477 if ((ppa
= us
->ppa
) == 0) {
1482 #ifdef FILTER_PACKETS
1483 pass
= ip_hard_filter(us
, mp
, outbound
);
1486 * Here is where we might, in future, decide whether to pass
1487 * or drop the packet, and whether it counts as link activity.
1490 #endif /* FILTER_PACKETS */
1493 /* pass only if link already up, and don't update time */
1494 if (ppa
->lowerq
== 0) {
1501 ppa
->last_sent
= time
;
1503 ppa
->last_recv
= time
;
1510 * We have some data to send down to the lower stream (or up the
1511 * control stream, if we don't have a lower stream attached).
1512 * Returns 1 if the message was dealt with, 0 if it wasn't able
1513 * to be sent on and should therefore be queued up.
1522 if ((us
->flags
& US_BLOCKED
) || us
->npmode
== NPMODE_QUEUE
)
1525 if (ppa
== 0 || us
->npmode
== NPMODE_DROP
|| us
->npmode
== NPMODE_ERROR
) {
1526 if (us
->flags
& US_DBGLOG
)
1527 DPRINT2("ppp/%d: dropping pkt (npmode=%d)\n", us
->mn
, us
->npmode
);
1531 if (ppa
->lowerq
== 0) {
1532 /* try to send it up the control stream */
1533 if (bcanputnext(ppa
->q
, mp
->b_band
)) {
1535 * The message seems to get corrupted for some reason if
1536 * we just send the message up as it is, so we send a copy.
1538 mblk_t
*np
= copymsg(mp
);
1541 putnext(ppa
->q
, np
);
1545 if (bcanputnext(ppa
->lowerq
, mp
->b_band
)) {
1546 MT_ENTER(&ppa
->stats_lock
);
1547 ppa
->stats
.ppp_opackets
++;
1548 ppa
->stats
.ppp_obytes
+= msgdsize(mp
);
1549 #ifdef INCR_OPACKETS
1552 MT_EXIT(&ppa
->stats_lock
);
1554 * The lower queue is only ever detached while holding an
1555 * exclusive lock on the whole driver. So we can be confident
1556 * that the lower queue is still there.
1558 putnext(ppa
->lowerq
, mp
);
1562 us
->flags
|= US_BLOCKED
;
1567 * Allocate a new PPA id and link this stream into the list of PPAs.
1568 * This procedure is called with an exclusive lock on all queues in
1576 upperstr_t
*us
, *up
, **usp
;
1579 us
= (upperstr_t
*) q
->q_ptr
;
1581 DPRINT("new_ppa: q_ptr = 0!\n");
1587 while ((up
= *usp
) != 0 && ppa_id
== up
->ppa_id
) {
1591 us
->ppa_id
= ppa_id
;
1596 us
->flags
|= US_CONTROL
;
1597 us
->npmode
= NPMODE_PASS
;
1604 * Create a kstats record for our statistics, so netstat -i works.
1606 if (us
->kstats
== 0) {
1609 sprintf(unit
, "ppp%d", us
->ppa
->ppa_id
);
1610 us
->kstats
= kstat_create("ppp", us
->ppa
->ppa_id
, unit
,
1611 "net", KSTAT_TYPE_NAMED
, 4, 0);
1612 if (us
->kstats
!= 0) {
1613 kstat_named_t
*kn
= KSTAT_NAMED_PTR(us
->kstats
);
1615 strcpy(kn
[0].name
, "ipackets");
1616 kn
[0].data_type
= KSTAT_DATA_ULONG
;
1617 strcpy(kn
[1].name
, "ierrors");
1618 kn
[1].data_type
= KSTAT_DATA_ULONG
;
1619 strcpy(kn
[2].name
, "opackets");
1620 kn
[2].data_type
= KSTAT_DATA_ULONG
;
1621 strcpy(kn
[3].name
, "oerrors");
1622 kn
[3].data_type
= KSTAT_DATA_ULONG
;
1623 kstat_install(us
->kstats
);
1628 *(int *)mp
->b_cont
->b_rptr
= ppa_id
;
1629 mp
->b_datap
->db_type
= M_IOCACK
;
1640 us
= (upperstr_t
*) q
->q_ptr
;
1642 DPRINT("attach_ppa: q_ptr = 0!\n");
1647 us
->state
= DL_UNBOUND
;
1649 for (t
= us
->ppa
; t
->next
!= 0; t
= t
->next
)
1653 if (mp
->b_datap
->db_type
== M_IOCTL
) {
1654 mp
->b_datap
->db_type
= M_IOCACK
;
1658 dlpi_ok(q
, DL_ATTACH_REQ
);
1670 us
= (upperstr_t
*) q
->q_ptr
;
1672 DPRINT("detach_ppa: q_ptr = 0!\n");
1676 for (t
= us
->ppa
; t
->next
!= 0; t
= t
->next
)
1677 if (t
->next
== us
) {
1684 us
->state
= DL_UNATTACHED
;
1685 dlpi_ok(q
, DL_DETACH_REQ
);
1690 * We call this with qwriter in order to give the upper queue procedures
1691 * the guarantee that the lower queue is not going to go away while
1692 * they are executing.
1701 us
= (upperstr_t
*) q
->q_ptr
;
1703 DPRINT("detach_lower: q_ptr = 0!\n");
1708 us
->lowerq
->q_ptr
= 0;
1709 RD(us
->lowerq
)->q_ptr
= 0;
1713 /* Unblock streams which now feed back up the control stream. */
1716 mp
->b_datap
->db_type
= M_IOCACK
;
1724 upperstr_t
*us
, *as
;
1727 us
= (upperstr_t
*) q
->q_ptr
;
1729 DPRINT("pppuwsrv: q_ptr = 0!\n");
1734 * If this is a control stream, then this service procedure
1735 * probably got enabled because of flow control in the lower
1736 * stream being enabled (or because of the lower stream going
1737 * away). Therefore we enable the service procedure of all
1738 * attached upper streams.
1740 if (us
->flags
& US_CONTROL
) {
1741 for (as
= us
->next
; as
!= 0; as
= as
->next
)
1745 /* Try to send on any data queued here. */
1746 us
->flags
&= ~US_BLOCKED
;
1747 while ((mp
= getq(q
)) != 0) {
1748 if (!send_data(mp
, us
)) {
1757 /* should never get called... */
1774 * Flow control has back-enabled this stream:
1775 * enable the upper write service procedure for
1776 * the upper control stream for this lower stream.
1779 uq
= (queue_t
*) q
->q_ptr
;
1787 * This should only get called for control streams.
1794 upperstr_t
*ppa
, *us
;
1798 ppa
= (upperstr_t
*) q
->q_ptr
;
1800 DPRINT("pppurput: q_ptr = 0!\n");
1804 switch (mp
->b_datap
->db_type
) {
1806 MT_ENTER(&ppa
->stats_lock
);
1807 switch (*mp
->b_rptr
) {
1812 ppa
->stats
.ppp_ierrors
++;
1818 ppa
->stats
.ppp_oerrors
++;
1821 MT_EXIT(&ppa
->stats_lock
);
1828 * Attempt to match up the response with the stream
1829 * that the request came from.
1831 iop
= (struct iocblk
*) mp
->b_rptr
;
1832 for (us
= ppa
; us
!= 0; us
= us
->next
)
1833 if (us
->ioc_id
== iop
->ioc_id
)
1843 * The serial device has hung up. We don't want to send
1844 * the M_HANGUP message up to pppd because that will stop
1845 * us from using the control stream any more. Instead we
1846 * send a zero-length message as an end-of-file indication.
1849 mp
= allocb(1, BPRI_HI
);
1851 DPRINT1("ppp/%d: couldn't allocate eof message!\n", ppa
->mn
);
1854 putnext(ppa
->q
, mp
);
1858 if (mp
->b_datap
->db_type
== M_DATA
) {
1860 if (mp
->b_wptr
- mp
->b_rptr
< PPP_HDRLEN
) {
1861 PULLUP(mp
, PPP_HDRLEN
);
1863 DPRINT1("ppp_urput: msgpullup failed (len=%d)\n", len
);
1867 MT_ENTER(&ppa
->stats_lock
);
1868 ppa
->stats
.ppp_ipackets
++;
1869 ppa
->stats
.ppp_ibytes
+= len
;
1870 #ifdef INCR_IPACKETS
1873 MT_EXIT(&ppa
->stats_lock
);
1875 proto
= PPP_PROTOCOL(mp
->b_rptr
);
1879 * Should there be any promiscuous stream(s), send the data
1880 * up for each promiscuous stream that we recognize.
1882 promisc_sendup(ppa
, mp
, proto
, 1);
1883 #endif /* defined(SOL2) */
1885 if (proto
< 0x8000 && (us
= find_dest(ppa
, proto
)) != 0) {
1886 if (!pass_packet(us
, mp
, 0))
1888 if (!us
->rblocked
&& !canput(us
->q
))
1898 * A control frame, a frame for an unknown protocol,
1899 * or some other message type.
1900 * Send it up to pppd via the control stream.
1902 if (queclass(mp
) == QPCTL
|| canputnext(ppa
->q
))
1903 putnext(ppa
->q
, mp
);
1916 upperstr_t
*us
, *as
;
1919 dl_unitdata_ind_t
*ud
;
1923 us
= (upperstr_t
*) q
->q_ptr
;
1925 DPRINT("pppursrv: q_ptr = 0!\n");
1929 if (us
->flags
& US_CONTROL
) {
1932 * If there is no lower queue attached, run the write service
1933 * routines of other upper streams attached to this PPA.
1935 if (us
->lowerq
== 0) {
1938 if (as
->flags
& US_BLOCKED
)
1945 * Messages get queued on this stream's read queue if they
1946 * can't be queued on the read queue of the attached stream
1947 * that they are destined for. This is for flow control -
1948 * when this queue fills up, the lower read put procedure will
1949 * queue messages there and the flow control will propagate
1952 while ((mp
= getq(q
)) != 0) {
1953 proto
= PPP_PROTOCOL(mp
->b_rptr
);
1954 if (proto
< 0x8000 && (as
= find_dest(us
, proto
)) != 0) {
1967 /* can now put stuff directly on network protocol streams again */
1968 for (as
= us
->next
; as
!= 0; as
= as
->next
)
1972 if (us
->lowerq
!= 0)
1973 qenable(RD(us
->lowerq
));
1977 * A network protocol stream. Put a DLPI header on each
1978 * packet and send it on.
1979 * (Actually, it seems that the IP module will happily
1980 * accept M_DATA messages without the DL_UNITDATA_IND header.)
1982 while ((mp
= getq(q
)) != 0) {
1983 if (!canputnext(q
)) {
1988 proto
= PPP_PROTOCOL(mp
->b_rptr
);
1989 mp
->b_rptr
+= PPP_HDRLEN
;
1990 hdr
= allocb(sizeof(dl_unitdata_ind_t
) + 2 * sizeof(uint
),
1996 hdr
->b_datap
->db_type
= M_PROTO
;
1997 ud
= (dl_unitdata_ind_t
*) hdr
->b_wptr
;
1998 hdr
->b_wptr
+= sizeof(dl_unitdata_ind_t
) + 2 * sizeof(uint
);
2000 ud
->dl_primitive
= DL_UNITDATA_IND
;
2001 ud
->dl_dest_addr_length
= sizeof(uint
);
2002 ud
->dl_dest_addr_offset
= sizeof(dl_unitdata_ind_t
);
2003 ud
->dl_src_addr_length
= sizeof(uint
);
2004 ud
->dl_src_addr_offset
= ud
->dl_dest_addr_offset
+ sizeof(uint
);
2005 #if DL_CURRENT_VERSION >= 2
2006 ud
->dl_group_address
= 0;
2008 /* Send the DLPI client the data with the SAP they requested,
2009 (e.g. ETHERTYPE_IP) rather than the PPP protocol number
2011 ((uint
*)(ud
+ 1))[0] = us
->req_sap
; /* dest SAP */
2012 ((uint
*)(ud
+ 1))[1] = us
->req_sap
; /* src SAP */
2016 #endif /* NO_DLPI */
2019 * Now that we have consumed some packets from this queue,
2020 * enable the control stream's read service routine so that we
2021 * can process any packets for us that might have got queued
2022 * there for flow control reasons.
2025 qenable(us
->ppa
->q
);
2032 find_dest(ppa
, proto
)
2038 for (us
= ppa
->next
; us
!= 0; us
= us
->next
)
2039 if (proto
== us
->sap
)
2046 * Test upstream promiscuous conditions. As of now, only pass IPv4 and
2047 * Ipv6 packets upstream (let PPP packets be decoded elsewhere).
2050 find_promisc(us
, proto
)
2055 if ((proto
!= PPP_IP
) && (proto
!= PPP_IPV6
))
2056 return (upperstr_t
*)0;
2058 for ( ; us
; us
= us
->next
) {
2059 if ((us
->flags
& US_PROMISC
) && (us
->state
== DL_IDLE
))
2063 return (upperstr_t
*)0;
2067 * Prepend an empty Ethernet header to msg for snoop, et al.
2070 prepend_ether(us
, mp
, proto
)
2078 if ((eh
= allocb(sizeof(struct ether_header
), BPRI_HI
)) == 0) {
2083 if (proto
== PPP_IP
)
2084 type
= ETHERTYPE_IP
;
2085 else if (proto
== PPP_IPV6
)
2086 type
= ETHERTYPE_IPV6
;
2088 type
= proto
; /* What else? Let decoder decide */
2090 eh
->b_wptr
+= sizeof(struct ether_header
);
2091 bzero((caddr_t
)eh
->b_rptr
, sizeof(struct ether_header
));
2092 ((struct ether_header
*)eh
->b_rptr
)->ether_type
= htons((short)type
);
2098 * Prepend DL_UNITDATA_IND mblk to msg
2101 prepend_udind(us
, mp
, proto
)
2106 dl_unitdata_ind_t
*dlu
;
2110 size
= sizeof(dl_unitdata_ind_t
);
2111 if ((dh
= allocb(size
, BPRI_MED
)) == 0) {
2116 dh
->b_datap
->db_type
= M_PROTO
;
2117 dh
->b_wptr
= dh
->b_datap
->db_lim
;
2118 dh
->b_rptr
= dh
->b_wptr
- size
;
2120 dlu
= (dl_unitdata_ind_t
*)dh
->b_rptr
;
2121 dlu
->dl_primitive
= DL_UNITDATA_IND
;
2122 dlu
->dl_dest_addr_length
= 0;
2123 dlu
->dl_dest_addr_offset
= sizeof(dl_unitdata_ind_t
);
2124 dlu
->dl_src_addr_length
= 0;
2125 dlu
->dl_src_addr_offset
= sizeof(dl_unitdata_ind_t
);
2126 dlu
->dl_group_address
= 0;
2133 * For any recognized promiscuous streams, send data upstream
2136 promisc_sendup(ppa
, mp
, proto
, skip
)
2141 mblk_t
*dup_mp
, *dup_dup_mp
;
2142 upperstr_t
*prus
, *nprus
;
2144 if ((prus
= find_promisc(ppa
, proto
)) != 0) {
2145 if (dup_mp
= dupmsg(mp
)) {
2148 dup_mp
->b_rptr
+= PPP_HDRLEN
;
2150 for ( ; nprus
= find_promisc(prus
->next
, proto
);
2153 if (dup_dup_mp
= dupmsg(dup_mp
)) {
2154 if (canputnext(prus
->q
)) {
2155 if (prus
->flags
& US_RAWDATA
) {
2156 dup_dup_mp
= prepend_ether(prus
, dup_dup_mp
, proto
);
2157 putnext(prus
->q
, dup_dup_mp
);
2159 dup_dup_mp
= prepend_udind(prus
, dup_dup_mp
, proto
);
2160 putnext(prus
->q
, dup_dup_mp
);
2163 DPRINT("ppp_urput: data to promisc q dropped\n");
2164 freemsg(dup_dup_mp
);
2169 if (canputnext(prus
->q
)) {
2170 if (prus
->flags
& US_RAWDATA
) {
2171 dup_mp
= prepend_ether(prus
, dup_mp
, proto
);
2172 putnext(prus
->q
, dup_mp
);
2174 dup_mp
= prepend_udind(prus
, dup_mp
, proto
);
2175 putnext(prus
->q
, dup_mp
);
2178 DPRINT("ppp_urput: data to promisc q dropped\n");
2184 #endif /* defined(SOL2) */
2187 * We simply put the message on to the associated upper control stream
2188 * (either here or in ppplrsrv). That way we enter the perimeters
2189 * before looking through the list of attached streams to decide which
2190 * stream it should go up.
2200 switch (mp
->b_datap
->db_type
) {
2202 iop
= (struct iocblk
*) mp
->b_rptr
;
2203 iop
->ioc_error
= EINVAL
;
2204 mp
->b_datap
->db_type
= M_IOCNAK
;
2208 if (*mp
->b_rptr
& FLUSHR
)
2209 flushq(q
, FLUSHDATA
);
2210 if (*mp
->b_rptr
& FLUSHW
) {
2211 *mp
->b_rptr
&= ~FLUSHR
;
2219 * If we can't get the lower lock straight away, queue this one
2220 * rather than blocking, to avoid the possibility of deadlock.
2222 if (!TRYLOCK_LOWER_R
) {
2228 * Check that we're still connected to the driver.
2230 uq
= (queue_t
*) q
->q_ptr
;
2233 DPRINT1("ppplrput: q = %x, uq = 0??\n", q
);
2239 * Try to forward the message to the put routine for the upper
2240 * control stream for this lower stream.
2241 * If there are already messages queued here, queue this one so
2242 * they don't get out of order.
2244 if (queclass(mp
) == QPCTL
|| (qsize(q
) == 0 && canput(uq
)))
2261 * Packets get queued here for flow control reasons
2262 * or if the lrput routine couldn't get the lower lock
2266 uq
= (queue_t
*) q
->q_ptr
;
2269 flushq(q
, FLUSHALL
);
2270 DPRINT1("ppplrsrv: q = %x, uq = 0??\n", q
);
2273 while ((mp
= getq(q
)) != 0) {
2274 if (queclass(mp
) == QPCTL
|| canput(uq
))
2286 putctl2(q
, type
, code
, val
)
2288 int type
, code
, val
;
2292 mp
= allocb(2, BPRI_HI
);
2295 mp
->b_datap
->db_type
= type
;
2296 mp
->b_wptr
[0] = code
;
2297 mp
->b_wptr
[1] = val
;
2304 putctl4(q
, type
, code
, val
)
2306 int type
, code
, val
;
2310 mp
= allocb(4, BPRI_HI
);
2313 mp
->b_datap
->db_type
= type
;
2314 mp
->b_wptr
[0] = code
;
2315 ((short *)mp
->b_wptr
)[1] = val
;
2329 DPRINT("ppp upper streams:\n");
2330 for (us
= minor_devs
; us
!= 0; us
= us
->nextmn
) {
2332 DPRINT3(" %d: q=%x rlev=%d",
2333 us
->mn
, uq
, (uq
? qsize(uq
): 0));
2334 DPRINT3(" wlev=%d flags=0x%b", (uq
? qsize(WR(uq
)): 0),
2335 us
->flags
, "\020\1priv\2control\3blocked\4last");
2336 DPRINT3(" state=%x sap=%x req_sap=%x", us
->state
, us
->sap
,
2341 DPRINT1(" ppa=%d\n", us
->ppa
->ppa_id
);
2342 if (us
->flags
& US_CONTROL
) {
2344 DPRINT3(" control for %d lq=%x rlev=%d",
2345 us
->ppa_id
, lq
, (lq
? qsize(RD(lq
)): 0));
2346 DPRINT3(" wlev=%d mru=%d mtu=%d\n",
2347 (lq
? qsize(lq
): 0), us
->mru
, us
->mtu
);
2350 mp
->b_datap
->db_type
= M_IOCACK
;
2354 #ifdef FILTER_PACKETS
2355 #include <netinet/in_systm.h>
2356 #include <netinet/ip.h>
2357 #include <netinet/udp.h>
2358 #include <netinet/tcp.h>
2360 #define MAX_IPHDR 128 /* max TCP/IP header size */
2363 /* The following table contains a hard-coded list of protocol/port pairs.
2364 * Any matching packets are either discarded unconditionally, or,
2365 * if ok_if_link_up is non-zero when a connection does not currently exist
2366 * (i.e., they go through if the connection is present, but never initiate
2368 * This idea came from a post by dm@garage.uun.org (David Mazieres)
2370 static struct pktfilt_tab
{
2373 u_short ok_if_link_up
;
2375 { IPPROTO_UDP
, 520, 1 }, /* RIP, ok to pass if link is up */
2376 { IPPROTO_UDP
, 123, 1 }, /* NTP, don't keep up the link for it */
2377 { -1, 0, 0 } /* terminator entry has port == -1 */
2382 ip_hard_filter(us
, mp
, outbound
)
2388 struct pktfilt_tab
*pft
;
2394 /* Note, the PPP header has already been pulled up in all cases */
2395 proto
= PPP_PROTOCOL(mp
->b_rptr
);
2396 if (us
->flags
& US_DBGLOG
)
2397 DPRINT3("ppp/%d: filter, proto=0x%x, out=%d\n", us
->mn
, proto
, outbound
);
2402 if ((mp
->b_wptr
- mp
->b_rptr
) == PPP_HDRLEN
&& mp
->b_cont
!= 0) {
2403 temp_mp
= mp
->b_cont
;
2404 len
= msgdsize(temp_mp
);
2405 hlen
= (len
< MAX_IPHDR
) ? len
: MAX_IPHDR
;
2406 PULLUP(temp_mp
, hlen
);
2408 DPRINT2("ppp/%d: filter, pullup next failed, len=%d\n",
2410 mp
->b_cont
= 0; /* PULLUP() freed the rest */
2414 ip
= (struct ip
*)mp
->b_cont
->b_rptr
;
2418 hlen
= (len
< (PPP_HDRLEN
+MAX_IPHDR
)) ? len
: (PPP_HDRLEN
+MAX_IPHDR
);
2421 DPRINT2("ppp/%d: filter, pullup failed, len=%d\n",
2425 ip
= (struct ip
*)(mp
->b_rptr
+ PPP_HDRLEN
);
2428 /* For IP traffic, certain packets (e.g., RIP) may be either
2429 * 1. ignored - dropped completely
2430 * 2. will not initiate a connection, but
2431 * will be passed if a connection is currently up.
2433 for (pft
=pktfilt_tab
; pft
->proto
!= -1; pft
++) {
2434 if (ip
->ip_p
== pft
->proto
) {
2435 switch(pft
->proto
) {
2437 if (((struct udphdr
*) &((int *)ip
)[ip
->ip_hl
])->uh_dport
2438 == htons(pft
->port
)) goto endfor
;
2441 if (((struct tcphdr
*) &((int *)ip
)[ip
->ip_hl
])->th_dport
2442 == htons(pft
->port
)) goto endfor
;
2448 if (pft
->proto
!= -1) {
2449 if (us
->flags
& US_DBGLOG
)
2450 DPRINT3("ppp/%d: found IP pkt, proto=0x%x (%d)\n",
2451 us
->mn
, pft
->proto
, pft
->port
);
2452 /* Discard if not connected, or if not pass_with_link_up */
2453 /* else, if link is up let go by, but don't update time */
2454 return pft
->ok_if_link_up
? -1: 0;
2457 } /* end switch (proto) */
2461 #endif /* FILTER_PACKETS */