xref: /illumos-gate/usr/src/uts/common/io/ppp/sppp/sppp.c (revision 78a53e20)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * sppp.c - Solaris STREAMS PPP multiplexing pseudo-driver
37c478bd9Sstevel@tonic-gate  *
4f53eecf5SJames Carlson  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
57c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
648bbca81SDaniel Hoffman  * Copyright (c) 2016 by Delphix. All rights reserved.
7*78a53e20SJohn Levon  * Copyright 2019, Joyent, Inc.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * Permission to use, copy, modify, and distribute this software and its
107c478bd9Sstevel@tonic-gate  * documentation is hereby granted, provided that the above copyright
117c478bd9Sstevel@tonic-gate  * notice appears in all copies.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * SUN MAKES NO REPRESENTATION OR WARRANTIES ABOUT THE SUITABILITY OF
147c478bd9Sstevel@tonic-gate  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
157c478bd9Sstevel@tonic-gate  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
167c478bd9Sstevel@tonic-gate  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT.  SUN SHALL NOT BE LIABLE FOR
177c478bd9Sstevel@tonic-gate  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
187c478bd9Sstevel@tonic-gate  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * Copyright (c) 1994 The Australian National University.
217c478bd9Sstevel@tonic-gate  * All rights reserved.
227c478bd9Sstevel@tonic-gate  *
237c478bd9Sstevel@tonic-gate  * Permission to use, copy, modify, and distribute this software and its
247c478bd9Sstevel@tonic-gate  * documentation is hereby granted, provided that the above copyright
257c478bd9Sstevel@tonic-gate  * notice appears in all copies.  This software is provided without any
267c478bd9Sstevel@tonic-gate  * warranty, express or implied. The Australian National University
277c478bd9Sstevel@tonic-gate  * makes no representations about the suitability of this software for
287c478bd9Sstevel@tonic-gate  * any purpose.
297c478bd9Sstevel@tonic-gate  *
307c478bd9Sstevel@tonic-gate  * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
317c478bd9Sstevel@tonic-gate  * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
327c478bd9Sstevel@tonic-gate  * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
337c478bd9Sstevel@tonic-gate  * THE AUSTRALIAN NATIONAL UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY
347c478bd9Sstevel@tonic-gate  * OF SUCH DAMAGE.
357c478bd9Sstevel@tonic-gate  *
367c478bd9Sstevel@tonic-gate  * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
377c478bd9Sstevel@tonic-gate  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
387c478bd9Sstevel@tonic-gate  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
397c478bd9Sstevel@tonic-gate  * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
407c478bd9Sstevel@tonic-gate  * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
417c478bd9Sstevel@tonic-gate  * OR MODIFICATIONS.
427c478bd9Sstevel@tonic-gate  *
437c478bd9Sstevel@tonic-gate  * This driver is derived from the original SVR4 STREAMS PPP driver
447c478bd9Sstevel@tonic-gate  * originally written by Paul Mackerras <paul.mackerras@cs.anu.edu.au>.
457c478bd9Sstevel@tonic-gate  *
467c478bd9Sstevel@tonic-gate  * Adi Masputra <adi.masputra@sun.com> rewrote and restructured the code
477c478bd9Sstevel@tonic-gate  * for improved performance and scalability.
487c478bd9Sstevel@tonic-gate  */
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate #define	RCSID	"$Id: sppp.c,v 1.0 2000/05/08 01:10:12 masputra Exp $"
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate #include <sys/types.h>
537c478bd9Sstevel@tonic-gate #include <sys/debug.h>
547c478bd9Sstevel@tonic-gate #include <sys/param.h>
557c478bd9Sstevel@tonic-gate #include <sys/stat.h>
567c478bd9Sstevel@tonic-gate #include <sys/stream.h>
577c478bd9Sstevel@tonic-gate #include <sys/stropts.h>
587c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
597c478bd9Sstevel@tonic-gate #include <sys/errno.h>
607c478bd9Sstevel@tonic-gate #include <sys/time.h>
617c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
627c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
637c478bd9Sstevel@tonic-gate #include <sys/conf.h>
647c478bd9Sstevel@tonic-gate #include <sys/dlpi.h>
657c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
667c478bd9Sstevel@tonic-gate #include <sys/kstat.h>
677c478bd9Sstevel@tonic-gate #include <sys/strsun.h>
687c478bd9Sstevel@tonic-gate #include <sys/ethernet.h>
697c478bd9Sstevel@tonic-gate #include <sys/policy.h>
70f53eecf5SJames Carlson #include <sys/zone.h>
717c478bd9Sstevel@tonic-gate #include <net/ppp_defs.h>
727c478bd9Sstevel@tonic-gate #include <net/pppio.h>
737c478bd9Sstevel@tonic-gate #include "sppp.h"
747c478bd9Sstevel@tonic-gate #include "s_common.h"
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate /*
777c478bd9Sstevel@tonic-gate  * This is used to tag official Solaris sources.  Please do not define
787c478bd9Sstevel@tonic-gate  * "INTERNAL_BUILD" when building this software outside of Sun Microsystems.
797c478bd9Sstevel@tonic-gate  */
807c478bd9Sstevel@tonic-gate #ifdef INTERNAL_BUILD
817c478bd9Sstevel@tonic-gate /* MODINFO is limited to 32 characters. */
82002c70ffScarlsonj const char sppp_module_description[] = "PPP 4.0 mux";
837c478bd9Sstevel@tonic-gate #else /* INTERNAL_BUILD */
8419397407SSherry Moore const char sppp_module_description[] = "ANU PPP mux";
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate /* LINTED */
877c478bd9Sstevel@tonic-gate static const char buildtime[] = "Built " __DATE__ " at " __TIME__
887c478bd9Sstevel@tonic-gate #ifdef DEBUG
897c478bd9Sstevel@tonic-gate " DEBUG"
907c478bd9Sstevel@tonic-gate #endif
917c478bd9Sstevel@tonic-gate "\n";
927c478bd9Sstevel@tonic-gate #endif /* INTERNAL_BUILD */
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate static void	sppp_inner_ioctl(queue_t *, mblk_t *);
957c478bd9Sstevel@tonic-gate static void	sppp_outer_ioctl(queue_t *, mblk_t *);
967c478bd9Sstevel@tonic-gate static queue_t	*sppp_send(queue_t *, mblk_t **, spppstr_t *);
977c478bd9Sstevel@tonic-gate static queue_t	*sppp_recv(queue_t *, mblk_t **, spppstr_t *);
987c478bd9Sstevel@tonic-gate static void	sppp_recv_nondata(queue_t *, mblk_t *, spppstr_t *);
997c478bd9Sstevel@tonic-gate static queue_t	*sppp_outpkt(queue_t *, mblk_t **, int, spppstr_t *);
1007c478bd9Sstevel@tonic-gate static spppstr_t *sppp_inpkt(queue_t *, mblk_t *, spppstr_t *);
1017c478bd9Sstevel@tonic-gate static int	sppp_kstat_update(kstat_t *, int);
1022bcc9601SToomas Soome static void	sppp_release_pkts(sppa_t *, uint16_t);
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate /*
1057c478bd9Sstevel@tonic-gate  * sps_list contains the list of active per-stream instance state structures
1067c478bd9Sstevel@tonic-gate  * ordered on the minor device number (see sppp.h for details). All streams
1077c478bd9Sstevel@tonic-gate  * opened to this driver are threaded together in this list.
1087c478bd9Sstevel@tonic-gate  */
1097c478bd9Sstevel@tonic-gate static spppstr_t *sps_list = NULL;
1107c478bd9Sstevel@tonic-gate /*
1117c478bd9Sstevel@tonic-gate  * ppa_list contains the list of active per-attachment instance state
1127c478bd9Sstevel@tonic-gate  * structures ordered on the ppa id number (see sppp.h for details). All of
1137c478bd9Sstevel@tonic-gate  * the ppa structures created once per PPPIO_NEWPPA ioctl are threaded together
1147c478bd9Sstevel@tonic-gate  * in this list. There is exactly one ppa structure for a given PPP interface,
1157c478bd9Sstevel@tonic-gate  * and multiple sps streams (upper streams) may share a ppa by performing
1167c478bd9Sstevel@tonic-gate  * an attachment explicitly (PPPIO_ATTACH) or implicitly (DL_ATTACH_REQ).
1177c478bd9Sstevel@tonic-gate  */
1187c478bd9Sstevel@tonic-gate static sppa_t *ppa_list = NULL;
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate static const char *kstats_names[] = { SPPP_KSTATS_NAMES };
1217c478bd9Sstevel@tonic-gate static const char *kstats64_names[] = { SPPP_KSTATS64_NAMES };
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate /*
1247c478bd9Sstevel@tonic-gate  * map proto (which is an IANA defined ppp network protocol) to
1257c478bd9Sstevel@tonic-gate  * a bit position indicated by NP_* in ppa_npflag
1267c478bd9Sstevel@tonic-gate  */
1277c478bd9Sstevel@tonic-gate static uint32_t
sppp_ppp2np(uint16_t proto)1287c478bd9Sstevel@tonic-gate sppp_ppp2np(uint16_t proto)
1297c478bd9Sstevel@tonic-gate {
1307c478bd9Sstevel@tonic-gate 	switch (proto) {
1317c478bd9Sstevel@tonic-gate 	case PPP_IP:
1327c478bd9Sstevel@tonic-gate 		return (NP_IP);
1337c478bd9Sstevel@tonic-gate 	case PPP_IPV6:
1347c478bd9Sstevel@tonic-gate 		return (NP_IPV6);
1357c478bd9Sstevel@tonic-gate 	default:
1367c478bd9Sstevel@tonic-gate 		return (0);
1377c478bd9Sstevel@tonic-gate 	}
1387c478bd9Sstevel@tonic-gate }
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate /*
1417c478bd9Sstevel@tonic-gate  * sppp_open()
1427c478bd9Sstevel@tonic-gate  *
1437c478bd9Sstevel@tonic-gate  * MT-Perimeters:
1447c478bd9Sstevel@tonic-gate  *    exclusive inner, exclusive outer.
1457c478bd9Sstevel@tonic-gate  *
1467c478bd9Sstevel@tonic-gate  * Description:
1477c478bd9Sstevel@tonic-gate  *    Common open procedure for module.
1487c478bd9Sstevel@tonic-gate  */
1497c478bd9Sstevel@tonic-gate /* ARGSUSED */
1507c478bd9Sstevel@tonic-gate int
sppp_open(queue_t * q,dev_t * devp,int oflag,int sflag,cred_t * credp)1517c478bd9Sstevel@tonic-gate sppp_open(queue_t *q, dev_t *devp, int oflag, int sflag, cred_t *credp)
1527c478bd9Sstevel@tonic-gate {
1537c478bd9Sstevel@tonic-gate 	spppstr_t	*sps;
1547c478bd9Sstevel@tonic-gate 	spppstr_t	**nextmn;
1557c478bd9Sstevel@tonic-gate 	minor_t		mn;
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate 	ASSERT(q != NULL && devp != NULL);
1587c478bd9Sstevel@tonic-gate 	ASSERT(sflag != MODOPEN);
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate 	if (q->q_ptr != NULL) {
1617c478bd9Sstevel@tonic-gate 		return (0);		/* already open */
1627c478bd9Sstevel@tonic-gate 	}
1637c478bd9Sstevel@tonic-gate 	if (sflag != CLONEOPEN) {
1647c478bd9Sstevel@tonic-gate 		return (OPENFAIL);
1657c478bd9Sstevel@tonic-gate 	}
1667c478bd9Sstevel@tonic-gate 	/*
1677c478bd9Sstevel@tonic-gate 	 * The sps list is sorted using the minor number as the key. The
1687c478bd9Sstevel@tonic-gate 	 * following code walks the list to find the lowest valued minor
1697c478bd9Sstevel@tonic-gate 	 * number available to be used.
1707c478bd9Sstevel@tonic-gate 	 */
1717c478bd9Sstevel@tonic-gate 	mn = 0;
1727c478bd9Sstevel@tonic-gate 	for (nextmn = &sps_list; (sps = *nextmn) != NULL;
1737c478bd9Sstevel@tonic-gate 	    nextmn = &sps->sps_nextmn) {
1747c478bd9Sstevel@tonic-gate 		if (sps->sps_mn_id != mn) {
1757c478bd9Sstevel@tonic-gate 			break;
1767c478bd9Sstevel@tonic-gate 		}
1777c478bd9Sstevel@tonic-gate 		++mn;
1787c478bd9Sstevel@tonic-gate 	}
1797c478bd9Sstevel@tonic-gate 	sps = (spppstr_t *)kmem_zalloc(sizeof (spppstr_t), KM_SLEEP);
1807c478bd9Sstevel@tonic-gate 	ASSERT(sps != NULL);		/* KM_SLEEP must never return NULL */
1817c478bd9Sstevel@tonic-gate 	sps->sps_nextmn = *nextmn;	/* insert stream in global list */
1827c478bd9Sstevel@tonic-gate 	*nextmn = sps;
1837c478bd9Sstevel@tonic-gate 	sps->sps_mn_id = mn;		/* save minor id for this stream */
1847c478bd9Sstevel@tonic-gate 	sps->sps_rq = q;		/* save read queue pointer */
1857c478bd9Sstevel@tonic-gate 	sps->sps_sap = -1;		/* no sap bound to stream */
1867c478bd9Sstevel@tonic-gate 	sps->sps_dlstate = DL_UNATTACHED; /* dlpi state is unattached */
1877c478bd9Sstevel@tonic-gate 	sps->sps_npmode = NPMODE_DROP;	/* drop all packets initially */
188f53eecf5SJames Carlson 	sps->sps_zoneid = crgetzoneid(credp);
1897c478bd9Sstevel@tonic-gate 	q->q_ptr = WR(q)->q_ptr = (caddr_t)sps;
1907c478bd9Sstevel@tonic-gate 	/*
1917c478bd9Sstevel@tonic-gate 	 * We explicitly disable the automatic queue scheduling for the
1927c478bd9Sstevel@tonic-gate 	 * write-side to obtain complete control over queuing during transmit.
1937c478bd9Sstevel@tonic-gate 	 * Packets will be queued at the upper write queue and the service
1947c478bd9Sstevel@tonic-gate 	 * routine will not be called until it gets scheduled by having the
1957c478bd9Sstevel@tonic-gate 	 * lower write service routine call the qenable(WR(uq)) for all streams
1967c478bd9Sstevel@tonic-gate 	 * attached to the same ppa instance.
1977c478bd9Sstevel@tonic-gate 	 */
1987c478bd9Sstevel@tonic-gate 	noenable(WR(q));
1997c478bd9Sstevel@tonic-gate 	*devp = makedevice(getmajor(*devp), mn);
2007c478bd9Sstevel@tonic-gate 	qprocson(q);
2017c478bd9Sstevel@tonic-gate 	return (0);
2027c478bd9Sstevel@tonic-gate }
2037c478bd9Sstevel@tonic-gate 
2047c478bd9Sstevel@tonic-gate /*
2057c478bd9Sstevel@tonic-gate  * Free storage used by a PPA.  This is not called until the last PPA
20648bbca81SDaniel Hoffman  * user closes their connection or reattaches to a different PPA.
2077c478bd9Sstevel@tonic-gate  */
2087c478bd9Sstevel@tonic-gate static void
sppp_free_ppa(sppa_t * ppa)2097c478bd9Sstevel@tonic-gate sppp_free_ppa(sppa_t *ppa)
2107c478bd9Sstevel@tonic-gate {
2117c478bd9Sstevel@tonic-gate 	sppa_t **nextppa;
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate 	ASSERT(ppa->ppa_refcnt == 1);
2147c478bd9Sstevel@tonic-gate 	if (ppa->ppa_kstats != NULL) {
2157c478bd9Sstevel@tonic-gate 		kstat_delete(ppa->ppa_kstats);
2167c478bd9Sstevel@tonic-gate 		ppa->ppa_kstats = NULL;
2177c478bd9Sstevel@tonic-gate 	}
2187c478bd9Sstevel@tonic-gate 	mutex_destroy(&ppa->ppa_sta_lock);
2197c478bd9Sstevel@tonic-gate 	mutex_destroy(&ppa->ppa_npmutex);
2207c478bd9Sstevel@tonic-gate 	rw_destroy(&ppa->ppa_sib_lock);
2217c478bd9Sstevel@tonic-gate 	nextppa = &ppa_list;
2227c478bd9Sstevel@tonic-gate 	while (*nextppa != NULL) {
2237c478bd9Sstevel@tonic-gate 		if (*nextppa == ppa) {
2247c478bd9Sstevel@tonic-gate 			*nextppa = ppa->ppa_nextppa;
2257c478bd9Sstevel@tonic-gate 			break;
2267c478bd9Sstevel@tonic-gate 		}
2277c478bd9Sstevel@tonic-gate 		nextppa = &(*nextppa)->ppa_nextppa;
2287c478bd9Sstevel@tonic-gate 	}
2297c478bd9Sstevel@tonic-gate 	kmem_free(ppa, sizeof (*ppa));
2307c478bd9Sstevel@tonic-gate }
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate /*
2337c478bd9Sstevel@tonic-gate  * Create a new PPA.  Caller must be exclusive on outer perimeter.
2347c478bd9Sstevel@tonic-gate  */
2357c478bd9Sstevel@tonic-gate sppa_t *
sppp_create_ppa(uint32_t ppa_id,zoneid_t zoneid)236f53eecf5SJames Carlson sppp_create_ppa(uint32_t ppa_id, zoneid_t zoneid)
2377c478bd9Sstevel@tonic-gate {
2387c478bd9Sstevel@tonic-gate 	sppa_t *ppa;
2397c478bd9Sstevel@tonic-gate 	sppa_t *curppa;
2407c478bd9Sstevel@tonic-gate 	sppa_t **availppa;
2417c478bd9Sstevel@tonic-gate 	char unit[32];		/* Unit name */
2427c478bd9Sstevel@tonic-gate 	const char **cpp;
2437c478bd9Sstevel@tonic-gate 	kstat_t *ksp;
2447c478bd9Sstevel@tonic-gate 	kstat_named_t *knt;
2457c478bd9Sstevel@tonic-gate 
2467c478bd9Sstevel@tonic-gate 	/*
2477c478bd9Sstevel@tonic-gate 	 * NOTE: unit *must* be named for the driver
2487c478bd9Sstevel@tonic-gate 	 * name plus the ppa number so that netstat
2497c478bd9Sstevel@tonic-gate 	 * can find the statistics.
2507c478bd9Sstevel@tonic-gate 	 */
251002c70ffScarlsonj 	(void) sprintf(unit, "%s" "%d", PPP_DRV_NAME, ppa_id);
2527c478bd9Sstevel@tonic-gate 	/*
2537c478bd9Sstevel@tonic-gate 	 * Make sure we can allocate a buffer to
2547c478bd9Sstevel@tonic-gate 	 * contain the ppa to be sent upstream, as
2557c478bd9Sstevel@tonic-gate 	 * well as the actual ppa structure and its
2567c478bd9Sstevel@tonic-gate 	 * associated kstat structure.
2577c478bd9Sstevel@tonic-gate 	 */
2587c478bd9Sstevel@tonic-gate 	ppa = (sppa_t *)kmem_zalloc(sizeof (sppa_t),
2597c478bd9Sstevel@tonic-gate 	    KM_NOSLEEP);
2607c478bd9Sstevel@tonic-gate 	ksp = kstat_create(PPP_DRV_NAME, ppa_id, unit, "net", KSTAT_TYPE_NAMED,
2617c478bd9Sstevel@tonic-gate 	    sizeof (sppp_kstats_t) / sizeof (kstat_named_t), 0);
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate 	if (ppa == NULL || ksp == NULL) {
2647c478bd9Sstevel@tonic-gate 		if (ppa != NULL) {
2657c478bd9Sstevel@tonic-gate 			kmem_free(ppa, sizeof (sppa_t));
2667c478bd9Sstevel@tonic-gate 		}
2677c478bd9Sstevel@tonic-gate 		if (ksp != NULL) {
2687c478bd9Sstevel@tonic-gate 			kstat_delete(ksp);
2697c478bd9Sstevel@tonic-gate 		}
2707c478bd9Sstevel@tonic-gate 		return (NULL);
2717c478bd9Sstevel@tonic-gate 	}
2727c478bd9Sstevel@tonic-gate 	ppa->ppa_kstats = ksp;		/* chain kstat structure */
2737c478bd9Sstevel@tonic-gate 	ppa->ppa_ppa_id = ppa_id;	/* record ppa id */
274f53eecf5SJames Carlson 	ppa->ppa_zoneid = zoneid;	/* zone that owns this PPA */
2757c478bd9Sstevel@tonic-gate 	ppa->ppa_mtu = PPP_MAXMTU;	/* 65535-(PPP_HDRLEN+PPP_FCSLEN) */
2767c478bd9Sstevel@tonic-gate 	ppa->ppa_mru = PPP_MAXMRU;	/* 65000 */
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate 	mutex_init(&ppa->ppa_sta_lock, NULL, MUTEX_DRIVER, NULL);
2797c478bd9Sstevel@tonic-gate 	mutex_init(&ppa->ppa_npmutex, NULL, MUTEX_DRIVER, NULL);
2807c478bd9Sstevel@tonic-gate 	rw_init(&ppa->ppa_sib_lock, NULL, RW_DRIVER, NULL);
2817c478bd9Sstevel@tonic-gate 
2827c478bd9Sstevel@tonic-gate 	/*
2837c478bd9Sstevel@tonic-gate 	 * Prepare and install kstat counters.  Note that for netstat
2847c478bd9Sstevel@tonic-gate 	 * -i to work, there needs to be "ipackets", "opackets",
2857c478bd9Sstevel@tonic-gate 	 * "ierrors", and "oerrors" kstat named variables.
2867c478bd9Sstevel@tonic-gate 	 */
2877c478bd9Sstevel@tonic-gate 	knt = (kstat_named_t *)ksp->ks_data;
2887c478bd9Sstevel@tonic-gate 	for (cpp = kstats_names; cpp < kstats_names + Dim(kstats_names);
2897c478bd9Sstevel@tonic-gate 	    cpp++) {
290d624471bSelowe 		kstat_named_init(knt, *cpp, KSTAT_DATA_UINT32);
2917c478bd9Sstevel@tonic-gate 		knt++;
2927c478bd9Sstevel@tonic-gate 	}
2937c478bd9Sstevel@tonic-gate 	for (cpp = kstats64_names; cpp < kstats64_names + Dim(kstats64_names);
2947c478bd9Sstevel@tonic-gate 	    cpp++) {
295d624471bSelowe 		kstat_named_init(knt, *cpp, KSTAT_DATA_UINT64);
2967c478bd9Sstevel@tonic-gate 		knt++;
2977c478bd9Sstevel@tonic-gate 	}
2987c478bd9Sstevel@tonic-gate 	ksp->ks_update = sppp_kstat_update;
2997c478bd9Sstevel@tonic-gate 	ksp->ks_private = (void *)ppa;
3007c478bd9Sstevel@tonic-gate 	kstat_install(ksp);
3017c478bd9Sstevel@tonic-gate 
3027c478bd9Sstevel@tonic-gate 	/* link to the next ppa and insert into global list */
3037c478bd9Sstevel@tonic-gate 	availppa = &ppa_list;
3047c478bd9Sstevel@tonic-gate 	while ((curppa = *availppa) != NULL) {
3057c478bd9Sstevel@tonic-gate 		if (ppa_id < curppa->ppa_ppa_id)
3067c478bd9Sstevel@tonic-gate 			break;
3077c478bd9Sstevel@tonic-gate 		availppa = &curppa->ppa_nextppa;
3087c478bd9Sstevel@tonic-gate 	}
3097c478bd9Sstevel@tonic-gate 	ppa->ppa_nextppa = *availppa;
3107c478bd9Sstevel@tonic-gate 	*availppa = ppa;
3117c478bd9Sstevel@tonic-gate 	return (ppa);
3127c478bd9Sstevel@tonic-gate }
3137c478bd9Sstevel@tonic-gate 
3147c478bd9Sstevel@tonic-gate /*
3157c478bd9Sstevel@tonic-gate  * sppp_close()
3167c478bd9Sstevel@tonic-gate  *
3177c478bd9Sstevel@tonic-gate  * MT-Perimeters:
3187c478bd9Sstevel@tonic-gate  *    exclusive inner, exclusive outer.
3197c478bd9Sstevel@tonic-gate  *
3207c478bd9Sstevel@tonic-gate  * Description:
3217c478bd9Sstevel@tonic-gate  *    Common close procedure for module.
3227c478bd9Sstevel@tonic-gate  */
3235e1743f0SToomas Soome /* ARGSUSED */
3247c478bd9Sstevel@tonic-gate int
sppp_close(queue_t * q,int flags __unused,cred_t * credp __unused)3255e1743f0SToomas Soome sppp_close(queue_t *q, int flags __unused, cred_t *credp __unused)
3267c478bd9Sstevel@tonic-gate {
3277c478bd9Sstevel@tonic-gate 	spppstr_t	*sps;
3287c478bd9Sstevel@tonic-gate 	spppstr_t	**nextmn;
3297c478bd9Sstevel@tonic-gate 	spppstr_t	*sib;
3307c478bd9Sstevel@tonic-gate 	sppa_t		*ppa;
3317c478bd9Sstevel@tonic-gate 	mblk_t		*mp;
3327c478bd9Sstevel@tonic-gate 
3337c478bd9Sstevel@tonic-gate 	ASSERT(q != NULL && q->q_ptr != NULL);
3347c478bd9Sstevel@tonic-gate 	sps = (spppstr_t *)q->q_ptr;
3357c478bd9Sstevel@tonic-gate 	qprocsoff(q);
3367c478bd9Sstevel@tonic-gate 
3377c478bd9Sstevel@tonic-gate 	ppa = sps->sps_ppa;
3387c478bd9Sstevel@tonic-gate 	if (ppa == NULL) {
3397c478bd9Sstevel@tonic-gate 		ASSERT(!IS_SPS_CONTROL(sps));
3407c478bd9Sstevel@tonic-gate 		goto close_unattached;
3417c478bd9Sstevel@tonic-gate 	}
3427c478bd9Sstevel@tonic-gate 	if (IS_SPS_CONTROL(sps)) {
3437c478bd9Sstevel@tonic-gate 		uint32_t	cnt = 0;
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate 		ASSERT(ppa != NULL);
3467c478bd9Sstevel@tonic-gate 		ASSERT(ppa->ppa_ctl == sps);
3477c478bd9Sstevel@tonic-gate 		ppa->ppa_ctl = NULL;
3487c478bd9Sstevel@tonic-gate 		/*
3497c478bd9Sstevel@tonic-gate 		 * STREAMS framework always issues I_UNLINK prior to close,
3507c478bd9Sstevel@tonic-gate 		 * since we only allow I_LINK under the control stream.
3517c478bd9Sstevel@tonic-gate 		 * A given ppa structure has at most one lower stream pointed
3527c478bd9Sstevel@tonic-gate 		 * by the ppa_lower_wq field, because we only allow a single
3537c478bd9Sstevel@tonic-gate 		 * linkage (I_LINK) to be done on the control stream.
3547c478bd9Sstevel@tonic-gate 		 */
3557c478bd9Sstevel@tonic-gate 		ASSERT(ppa->ppa_lower_wq == NULL);
3567c478bd9Sstevel@tonic-gate 		/*
3577c478bd9Sstevel@tonic-gate 		 * Walk through all of sibling streams attached to this ppa,
3587c478bd9Sstevel@tonic-gate 		 * and remove all references to this ppa. We have exclusive
3597c478bd9Sstevel@tonic-gate 		 * access for the entire driver here, so there's no need
3607c478bd9Sstevel@tonic-gate 		 * to hold ppa_sib_lock.
3617c478bd9Sstevel@tonic-gate 		 */
3627c478bd9Sstevel@tonic-gate 		cnt++;
3637c478bd9Sstevel@tonic-gate 		sib = ppa->ppa_streams;
3647c478bd9Sstevel@tonic-gate 		while (sib != NULL) {
3657c478bd9Sstevel@tonic-gate 			ASSERT(ppa == sib->sps_ppa);
3667c478bd9Sstevel@tonic-gate 			sib->sps_npmode = NPMODE_DROP;
3677c478bd9Sstevel@tonic-gate 			sib->sps_flags &= ~(SPS_PIOATTACH | SPS_CACHED);
3687c478bd9Sstevel@tonic-gate 			/*
3697c478bd9Sstevel@tonic-gate 			 * There should be a preallocated hangup
3707c478bd9Sstevel@tonic-gate 			 * message here.  Fetch it and send it up to
3717c478bd9Sstevel@tonic-gate 			 * the stream head.  This will cause IP to
3727c478bd9Sstevel@tonic-gate 			 * mark the interface as "down."
3737c478bd9Sstevel@tonic-gate 			 */
3747c478bd9Sstevel@tonic-gate 			if ((mp = sib->sps_hangup) != NULL) {
3757c478bd9Sstevel@tonic-gate 				sib->sps_hangup = NULL;
3767c478bd9Sstevel@tonic-gate 				/*
3777c478bd9Sstevel@tonic-gate 				 * M_HANGUP works with IP, but snoop
3787c478bd9Sstevel@tonic-gate 				 * is lame and requires M_ERROR.  Send
3797c478bd9Sstevel@tonic-gate 				 * up a clean error code instead.
3807c478bd9Sstevel@tonic-gate 				 *
3817c478bd9Sstevel@tonic-gate 				 * XXX if snoop is fixed, fix this, too.
3827c478bd9Sstevel@tonic-gate 				 */
3837c478bd9Sstevel@tonic-gate 				MTYPE(mp) = M_ERROR;
3847c478bd9Sstevel@tonic-gate 				*mp->b_wptr++ = ENXIO;
3857c478bd9Sstevel@tonic-gate 				putnext(sib->sps_rq, mp);
3867c478bd9Sstevel@tonic-gate 			}
3877c478bd9Sstevel@tonic-gate 			qenable(WR(sib->sps_rq));
3887c478bd9Sstevel@tonic-gate 			cnt++;
3897c478bd9Sstevel@tonic-gate 			sib = sib->sps_nextsib;
3907c478bd9Sstevel@tonic-gate 		}
3917c478bd9Sstevel@tonic-gate 		ASSERT(ppa->ppa_refcnt == cnt);
3927c478bd9Sstevel@tonic-gate 	} else {
3937c478bd9Sstevel@tonic-gate 		ASSERT(ppa->ppa_streams != NULL);
3947c478bd9Sstevel@tonic-gate 		ASSERT(ppa->ppa_ctl != sps);
3957c478bd9Sstevel@tonic-gate 		mp = NULL;
3967c478bd9Sstevel@tonic-gate 		if (sps->sps_sap == PPP_IP) {
3977c478bd9Sstevel@tonic-gate 			ppa->ppa_ip_cache = NULL;
3987c478bd9Sstevel@tonic-gate 			mp = create_lsmsg(PPP_LINKSTAT_IPV4_UNBOUND);
3997c478bd9Sstevel@tonic-gate 		} else if (sps->sps_sap == PPP_IPV6) {
4007c478bd9Sstevel@tonic-gate 			ppa->ppa_ip6_cache = NULL;
4017c478bd9Sstevel@tonic-gate 			mp = create_lsmsg(PPP_LINKSTAT_IPV6_UNBOUND);
4027c478bd9Sstevel@tonic-gate 		}
4037c478bd9Sstevel@tonic-gate 		/* Tell the daemon the bad news. */
4047c478bd9Sstevel@tonic-gate 		if (mp != NULL && ppa->ppa_ctl != NULL &&
4057c478bd9Sstevel@tonic-gate 		    (sps->sps_npmode == NPMODE_PASS ||
4067c478bd9Sstevel@tonic-gate 		    sps->sps_npmode == NPMODE_QUEUE)) {
4077c478bd9Sstevel@tonic-gate 			putnext(ppa->ppa_ctl->sps_rq, mp);
4087c478bd9Sstevel@tonic-gate 		} else {
4097c478bd9Sstevel@tonic-gate 			freemsg(mp);
4107c478bd9Sstevel@tonic-gate 		}
4117c478bd9Sstevel@tonic-gate 		/*
4127c478bd9Sstevel@tonic-gate 		 * Walk through all of sibling streams attached to the
4137c478bd9Sstevel@tonic-gate 		 * same ppa, and remove this stream from the sibling
4147c478bd9Sstevel@tonic-gate 		 * streams list. We have exclusive access for the
4157c478bd9Sstevel@tonic-gate 		 * entire driver here, so there's no need to hold
4167c478bd9Sstevel@tonic-gate 		 * ppa_sib_lock.
4177c478bd9Sstevel@tonic-gate 		 */
4187c478bd9Sstevel@tonic-gate 		sib = ppa->ppa_streams;
4197c478bd9Sstevel@tonic-gate 		if (sib == sps) {
4207c478bd9Sstevel@tonic-gate 			ppa->ppa_streams = sps->sps_nextsib;
4217c478bd9Sstevel@tonic-gate 		} else {
4227c478bd9Sstevel@tonic-gate 			while (sib->sps_nextsib != NULL) {
4237c478bd9Sstevel@tonic-gate 				if (sib->sps_nextsib == sps) {
4247c478bd9Sstevel@tonic-gate 					sib->sps_nextsib = sps->sps_nextsib;
4257c478bd9Sstevel@tonic-gate 					break;
4267c478bd9Sstevel@tonic-gate 				}
4277c478bd9Sstevel@tonic-gate 				sib = sib->sps_nextsib;
4287c478bd9Sstevel@tonic-gate 			}
4297c478bd9Sstevel@tonic-gate 		}
4307c478bd9Sstevel@tonic-gate 		sps->sps_nextsib = NULL;
4317c478bd9Sstevel@tonic-gate 		freemsg(sps->sps_hangup);
4327c478bd9Sstevel@tonic-gate 		sps->sps_hangup = NULL;
4337c478bd9Sstevel@tonic-gate 		/*
4347c478bd9Sstevel@tonic-gate 		 * Check if this is a promiscous stream. If the SPS_PROMISC bit
4357c478bd9Sstevel@tonic-gate 		 * is still set, it means that the stream is closed without
4367c478bd9Sstevel@tonic-gate 		 * ever having issued DL_DETACH_REQ or DL_PROMISCOFF_REQ.
4377c478bd9Sstevel@tonic-gate 		 * In this case, we simply decrement the promiscous counter,
4387c478bd9Sstevel@tonic-gate 		 * and it's safe to do it without holding ppa_sib_lock since
4397c478bd9Sstevel@tonic-gate 		 * we're exclusive (inner and outer) at this point.
4407c478bd9Sstevel@tonic-gate 		 */
4417c478bd9Sstevel@tonic-gate 		if (IS_SPS_PROMISC(sps)) {
4427c478bd9Sstevel@tonic-gate 			ASSERT(ppa->ppa_promicnt > 0);
4437c478bd9Sstevel@tonic-gate 			ppa->ppa_promicnt--;
4447c478bd9Sstevel@tonic-gate 		}
4457c478bd9Sstevel@tonic-gate 	}
4467c478bd9Sstevel@tonic-gate 	/* If we're the only one left, then delete now. */
4477c478bd9Sstevel@tonic-gate 	if (ppa->ppa_refcnt <= 1)
4487c478bd9Sstevel@tonic-gate 		sppp_free_ppa(ppa);
4497c478bd9Sstevel@tonic-gate 	else
4507c478bd9Sstevel@tonic-gate 		ppa->ppa_refcnt--;
4517c478bd9Sstevel@tonic-gate close_unattached:
4527c478bd9Sstevel@tonic-gate 	q->q_ptr = WR(q)->q_ptr = NULL;
4537c478bd9Sstevel@tonic-gate 	for (nextmn = &sps_list; *nextmn != NULL;
4547c478bd9Sstevel@tonic-gate 	    nextmn = &(*nextmn)->sps_nextmn) {
4557c478bd9Sstevel@tonic-gate 		if (*nextmn == sps) {
4567c478bd9Sstevel@tonic-gate 			*nextmn = sps->sps_nextmn;
4577c478bd9Sstevel@tonic-gate 			break;
4587c478bd9Sstevel@tonic-gate 		}
4597c478bd9Sstevel@tonic-gate 	}
4607c478bd9Sstevel@tonic-gate 	kmem_free(sps, sizeof (spppstr_t));
4617c478bd9Sstevel@tonic-gate 	return (0);
4627c478bd9Sstevel@tonic-gate }
4637c478bd9Sstevel@tonic-gate 
4647c478bd9Sstevel@tonic-gate static void
sppp_ioctl(struct queue * q,mblk_t * mp)4657c478bd9Sstevel@tonic-gate sppp_ioctl(struct queue *q, mblk_t *mp)
4667c478bd9Sstevel@tonic-gate {
4677c478bd9Sstevel@tonic-gate 	spppstr_t	*sps;
4687c478bd9Sstevel@tonic-gate 	spppstr_t	*nextsib;
4697c478bd9Sstevel@tonic-gate 	sppa_t		*ppa;
4707c478bd9Sstevel@tonic-gate 	struct iocblk	*iop;
4717c478bd9Sstevel@tonic-gate 	mblk_t		*nmp;
4727c478bd9Sstevel@tonic-gate 	enum NPmode	npmode;
4737c478bd9Sstevel@tonic-gate 	struct ppp_idle	*pip;
4747c478bd9Sstevel@tonic-gate 	struct ppp_stats64 *psp;
4757c478bd9Sstevel@tonic-gate 	struct ppp_comp_stats *pcsp;
4767c478bd9Sstevel@tonic-gate 	hrtime_t	hrtime;
4777c478bd9Sstevel@tonic-gate 	int		sap;
4787c478bd9Sstevel@tonic-gate 	int		count = 0;
4797c478bd9Sstevel@tonic-gate 	int		error = EINVAL;
4807c478bd9Sstevel@tonic-gate 
4817c478bd9Sstevel@tonic-gate 	sps = (spppstr_t *)q->q_ptr;
4827c478bd9Sstevel@tonic-gate 	ppa = sps->sps_ppa;
4837c478bd9Sstevel@tonic-gate 
4847c478bd9Sstevel@tonic-gate 	iop = (struct iocblk *)mp->b_rptr;
4857c478bd9Sstevel@tonic-gate 	switch (iop->ioc_cmd) {
4867c478bd9Sstevel@tonic-gate 	case PPPIO_NPMODE:
4877c478bd9Sstevel@tonic-gate 		if (!IS_SPS_CONTROL(sps)) {
4887c478bd9Sstevel@tonic-gate 			break;		/* return EINVAL */
4897c478bd9Sstevel@tonic-gate 		} else if (iop->ioc_count != 2 * sizeof (uint32_t) ||
4907c478bd9Sstevel@tonic-gate 		    (mp->b_cont == NULL)) {
4917c478bd9Sstevel@tonic-gate 			error = EPROTO;
4927c478bd9Sstevel@tonic-gate 			break;
4937c478bd9Sstevel@tonic-gate 		}
4947c478bd9Sstevel@tonic-gate 		ASSERT(ppa != NULL);
4957c478bd9Sstevel@tonic-gate 		ASSERT(mp->b_cont->b_rptr != NULL);
4967c478bd9Sstevel@tonic-gate 		ASSERT(sps->sps_npmode == NPMODE_PASS);
4977c478bd9Sstevel@tonic-gate 		sap = ((uint32_t *)mp->b_cont->b_rptr)[0];
4987c478bd9Sstevel@tonic-gate 		npmode = (enum NPmode)((uint32_t *)mp->b_cont->b_rptr)[1];
4997c478bd9Sstevel@tonic-gate 		/*
5007c478bd9Sstevel@tonic-gate 		 * Walk the sibling streams which belong to the same
5017c478bd9Sstevel@tonic-gate 		 * ppa, and try to find a stream with matching sap
5027c478bd9Sstevel@tonic-gate 		 * number.
5037c478bd9Sstevel@tonic-gate 		 */
5047c478bd9Sstevel@tonic-gate 		rw_enter(&ppa->ppa_sib_lock, RW_WRITER);
5057c478bd9Sstevel@tonic-gate 		for (nextsib = ppa->ppa_streams; nextsib != NULL;
5067c478bd9Sstevel@tonic-gate 		    nextsib = nextsib->sps_nextsib) {
5077c478bd9Sstevel@tonic-gate 			if (nextsib->sps_sap == sap) {
5087c478bd9Sstevel@tonic-gate 				break;	/* found it */
5097c478bd9Sstevel@tonic-gate 			}
5107c478bd9Sstevel@tonic-gate 		}
5117c478bd9Sstevel@tonic-gate 		if (nextsib == NULL) {
5127c478bd9Sstevel@tonic-gate 			rw_exit(&ppa->ppa_sib_lock);
5137c478bd9Sstevel@tonic-gate 			break;		/* return EINVAL */
5147c478bd9Sstevel@tonic-gate 		} else {
5157c478bd9Sstevel@tonic-gate 			nextsib->sps_npmode = npmode;
5167c478bd9Sstevel@tonic-gate 			if ((nextsib->sps_npmode != NPMODE_QUEUE) &&
5177c478bd9Sstevel@tonic-gate 			    (WR(nextsib->sps_rq)->q_first != NULL)) {
5187c478bd9Sstevel@tonic-gate 				qenable(WR(nextsib->sps_rq));
5197c478bd9Sstevel@tonic-gate 			}
5207c478bd9Sstevel@tonic-gate 		}
5217c478bd9Sstevel@tonic-gate 		rw_exit(&ppa->ppa_sib_lock);
5227c478bd9Sstevel@tonic-gate 		error = 0;	/* return success */
5237c478bd9Sstevel@tonic-gate 		break;
5247c478bd9Sstevel@tonic-gate 	case PPPIO_GIDLE:
5257c478bd9Sstevel@tonic-gate 		if (ppa == NULL) {
5267c478bd9Sstevel@tonic-gate 			ASSERT(!IS_SPS_CONTROL(sps));
5277c478bd9Sstevel@tonic-gate 			error = ENOLINK;
5287c478bd9Sstevel@tonic-gate 			break;
5297c478bd9Sstevel@tonic-gate 		} else if (!IS_PPA_TIMESTAMP(ppa)) {
5307c478bd9Sstevel@tonic-gate 			break;		/* return EINVAL */
5317c478bd9Sstevel@tonic-gate 		}
5327c478bd9Sstevel@tonic-gate 		if ((nmp = allocb(sizeof (struct ppp_idle),
5337c478bd9Sstevel@tonic-gate 		    BPRI_MED)) == NULL) {
5347c478bd9Sstevel@tonic-gate 			mutex_enter(&ppa->ppa_sta_lock);
5357c478bd9Sstevel@tonic-gate 			ppa->ppa_allocbfail++;
5367c478bd9Sstevel@tonic-gate 			mutex_exit(&ppa->ppa_sta_lock);
5377c478bd9Sstevel@tonic-gate 			error = ENOSR;
5387c478bd9Sstevel@tonic-gate 			break;
5397c478bd9Sstevel@tonic-gate 		}
5407c478bd9Sstevel@tonic-gate 		if (mp->b_cont != NULL) {
5417c478bd9Sstevel@tonic-gate 			freemsg(mp->b_cont);
5427c478bd9Sstevel@tonic-gate 		}
5437c478bd9Sstevel@tonic-gate 		mp->b_cont = nmp;
5447c478bd9Sstevel@tonic-gate 		pip = (struct ppp_idle *)nmp->b_wptr;
5457c478bd9Sstevel@tonic-gate 		nmp->b_wptr += sizeof (struct ppp_idle);
5467c478bd9Sstevel@tonic-gate 		/*
5477c478bd9Sstevel@tonic-gate 		 * Get current timestamp and subtract the tx and rx
5487c478bd9Sstevel@tonic-gate 		 * timestamps to get the actual idle time to be
5497c478bd9Sstevel@tonic-gate 		 * returned.
5507c478bd9Sstevel@tonic-gate 		 */
5517c478bd9Sstevel@tonic-gate 		hrtime = gethrtime();
5527c478bd9Sstevel@tonic-gate 		pip->xmit_idle = (hrtime - ppa->ppa_lasttx) / 1000000000ul;
5537c478bd9Sstevel@tonic-gate 		pip->recv_idle = (hrtime - ppa->ppa_lastrx) / 1000000000ul;
5547c478bd9Sstevel@tonic-gate 		count = msgsize(nmp);
5557c478bd9Sstevel@tonic-gate 		error = 0;
5567c478bd9Sstevel@tonic-gate 		break;		/* return success (error is 0) */
5577c478bd9Sstevel@tonic-gate 	case PPPIO_GTYPE:
5587c478bd9Sstevel@tonic-gate 		nmp = allocb(sizeof (uint32_t), BPRI_MED);
5597c478bd9Sstevel@tonic-gate 		if (nmp == NULL) {
5607c478bd9Sstevel@tonic-gate 			error = ENOSR;
5617c478bd9Sstevel@tonic-gate 			break;
5627c478bd9Sstevel@tonic-gate 		}
5637c478bd9Sstevel@tonic-gate 		if (mp->b_cont != NULL) {
5647c478bd9Sstevel@tonic-gate 			freemsg(mp->b_cont);
5657c478bd9Sstevel@tonic-gate 		}
5667c478bd9Sstevel@tonic-gate 		mp->b_cont = nmp;
5677c478bd9Sstevel@tonic-gate 		/*
5687c478bd9Sstevel@tonic-gate 		 * Let the requestor know that we are the PPP
5697c478bd9Sstevel@tonic-gate 		 * multiplexer (PPPTYP_MUX).
5707c478bd9Sstevel@tonic-gate 		 */
5717c478bd9Sstevel@tonic-gate 		*(uint32_t *)nmp->b_wptr = PPPTYP_MUX;
5727c478bd9Sstevel@tonic-gate 		nmp->b_wptr += sizeof (uint32_t);
5737c478bd9Sstevel@tonic-gate 		count = msgsize(nmp);
5747c478bd9Sstevel@tonic-gate 		error = 0;		/* return success */
5757c478bd9Sstevel@tonic-gate 		break;
5767c478bd9Sstevel@tonic-gate 	case PPPIO_GETSTAT64:
5777c478bd9Sstevel@tonic-gate 		if (ppa == NULL) {
5787c478bd9Sstevel@tonic-gate 			break;		/* return EINVAL */
5797c478bd9Sstevel@tonic-gate 		} else if ((ppa->ppa_lower_wq != NULL) &&
5807c478bd9Sstevel@tonic-gate 		    !IS_PPA_LASTMOD(ppa)) {
5817c478bd9Sstevel@tonic-gate 			mutex_enter(&ppa->ppa_sta_lock);
5827c478bd9Sstevel@tonic-gate 			/*
5839f7c4232SAnil udupa 			 * We match sps_ioc_id on the M_IOC{ACK,NAK},
5849f7c4232SAnil udupa 			 * so if the response hasn't come back yet,
5859f7c4232SAnil udupa 			 * new ioctls must be queued instead.
5867c478bd9Sstevel@tonic-gate 			 */
5879f7c4232SAnil udupa 			if (IS_SPS_IOCQ(sps)) {
5889f7c4232SAnil udupa 				mutex_exit(&ppa->ppa_sta_lock);
5899f7c4232SAnil udupa 				if (!putq(q, mp)) {
5909f7c4232SAnil udupa 					error = EAGAIN;
5919f7c4232SAnil udupa 					break;
5929f7c4232SAnil udupa 				}
5939f7c4232SAnil udupa 				return;
5949f7c4232SAnil udupa 			} else {
5959f7c4232SAnil udupa 				ppa->ppa_ioctlsfwd++;
5969f7c4232SAnil udupa 				/*
5979f7c4232SAnil udupa 				 * Record the ioctl CMD & ID - this will be
5989f7c4232SAnil udupa 				 * used to check the ACK or NAK responses
5999f7c4232SAnil udupa 				 * coming from below.
6009f7c4232SAnil udupa 				 */
6019f7c4232SAnil udupa 				sps->sps_ioc_id = iop->ioc_id;
6029f7c4232SAnil udupa 				sps->sps_flags |= SPS_IOCQ;
6039f7c4232SAnil udupa 				mutex_exit(&ppa->ppa_sta_lock);
6049f7c4232SAnil udupa 			}
6057c478bd9Sstevel@tonic-gate 			putnext(ppa->ppa_lower_wq, mp);
6067c478bd9Sstevel@tonic-gate 			return;	/* don't ack or nak the request */
6077c478bd9Sstevel@tonic-gate 		}
6087c478bd9Sstevel@tonic-gate 		nmp = allocb(sizeof (*psp), BPRI_MED);
6097c478bd9Sstevel@tonic-gate 		if (nmp == NULL) {
6107c478bd9Sstevel@tonic-gate 			mutex_enter(&ppa->ppa_sta_lock);
6117c478bd9Sstevel@tonic-gate 			ppa->ppa_allocbfail++;
6127c478bd9Sstevel@tonic-gate 			mutex_exit(&ppa->ppa_sta_lock);
6137c478bd9Sstevel@tonic-gate 			error = ENOSR;
6147c478bd9Sstevel@tonic-gate 			break;
6157c478bd9Sstevel@tonic-gate 		}
6167c478bd9Sstevel@tonic-gate 		if (mp->b_cont != NULL) {
6177c478bd9Sstevel@tonic-gate 			freemsg(mp->b_cont);
6187c478bd9Sstevel@tonic-gate 		}
6197c478bd9Sstevel@tonic-gate 		mp->b_cont = nmp;
6207c478bd9Sstevel@tonic-gate 		psp = (struct ppp_stats64 *)nmp->b_wptr;
6217c478bd9Sstevel@tonic-gate 		/*
6227c478bd9Sstevel@tonic-gate 		 * Copy the contents of ppp_stats64 structure for this
6237c478bd9Sstevel@tonic-gate 		 * ppa and return them to the caller.
6247c478bd9Sstevel@tonic-gate 		 */
6257c478bd9Sstevel@tonic-gate 		mutex_enter(&ppa->ppa_sta_lock);
6267c478bd9Sstevel@tonic-gate 		bcopy(&ppa->ppa_stats, psp, sizeof (*psp));
6277c478bd9Sstevel@tonic-gate 		mutex_exit(&ppa->ppa_sta_lock);
6287c478bd9Sstevel@tonic-gate 		nmp->b_wptr += sizeof (*psp);
6297c478bd9Sstevel@tonic-gate 		count = sizeof (*psp);
6307c478bd9Sstevel@tonic-gate 		error = 0;		/* return success */
6317c478bd9Sstevel@tonic-gate 		break;
6327c478bd9Sstevel@tonic-gate 	case PPPIO_GETCSTAT:
6337c478bd9Sstevel@tonic-gate 		if (ppa == NULL) {
6347c478bd9Sstevel@tonic-gate 			break;		/* return EINVAL */
6357c478bd9Sstevel@tonic-gate 		} else if ((ppa->ppa_lower_wq != NULL) &&
6367c478bd9Sstevel@tonic-gate 		    !IS_PPA_LASTMOD(ppa)) {
6377c478bd9Sstevel@tonic-gate 			mutex_enter(&ppa->ppa_sta_lock);
6387c478bd9Sstevel@tonic-gate 			/*
6399f7c4232SAnil udupa 			 * See comments in PPPIO_GETSTAT64 case
6409f7c4232SAnil udupa 			 * in sppp_ioctl().
6417c478bd9Sstevel@tonic-gate 			 */
6429f7c4232SAnil udupa 			if (IS_SPS_IOCQ(sps)) {
6439f7c4232SAnil udupa 				mutex_exit(&ppa->ppa_sta_lock);
6449f7c4232SAnil udupa 				if (!putq(q, mp)) {
6459f7c4232SAnil udupa 					error = EAGAIN;
6469f7c4232SAnil udupa 					break;
6479f7c4232SAnil udupa 				}
6489f7c4232SAnil udupa 				return;
6499f7c4232SAnil udupa 			} else {
6509f7c4232SAnil udupa 				ppa->ppa_ioctlsfwd++;
6519f7c4232SAnil udupa 				/*
6529f7c4232SAnil udupa 				 * Record the ioctl CMD & ID - this will be
6539f7c4232SAnil udupa 				 * used to check the ACK or NAK responses
6549f7c4232SAnil udupa 				 * coming from below.
6559f7c4232SAnil udupa 				 */
6569f7c4232SAnil udupa 				sps->sps_ioc_id = iop->ioc_id;
6579f7c4232SAnil udupa 				sps->sps_flags |= SPS_IOCQ;
6589f7c4232SAnil udupa 				mutex_exit(&ppa->ppa_sta_lock);
6599f7c4232SAnil udupa 			}
6607c478bd9Sstevel@tonic-gate 			putnext(ppa->ppa_lower_wq, mp);
6617c478bd9Sstevel@tonic-gate 			return;	/* don't ack or nak the request */
6627c478bd9Sstevel@tonic-gate 		}
6637c478bd9Sstevel@tonic-gate 		nmp = allocb(sizeof (struct ppp_comp_stats), BPRI_MED);
6647c478bd9Sstevel@tonic-gate 		if (nmp == NULL) {
6657c478bd9Sstevel@tonic-gate 			mutex_enter(&ppa->ppa_sta_lock);
6667c478bd9Sstevel@tonic-gate 			ppa->ppa_allocbfail++;
6677c478bd9Sstevel@tonic-gate 			mutex_exit(&ppa->ppa_sta_lock);
6687c478bd9Sstevel@tonic-gate 			error = ENOSR;
6697c478bd9Sstevel@tonic-gate 			break;
6707c478bd9Sstevel@tonic-gate 		}
6717c478bd9Sstevel@tonic-gate 		if (mp->b_cont != NULL) {
6727c478bd9Sstevel@tonic-gate 			freemsg(mp->b_cont);
6737c478bd9Sstevel@tonic-gate 		}
6747c478bd9Sstevel@tonic-gate 		mp->b_cont = nmp;
6757c478bd9Sstevel@tonic-gate 		pcsp = (struct ppp_comp_stats *)nmp->b_wptr;
6767c478bd9Sstevel@tonic-gate 		nmp->b_wptr += sizeof (struct ppp_comp_stats);
6777c478bd9Sstevel@tonic-gate 		bzero((caddr_t)pcsp, sizeof (struct ppp_comp_stats));
6787c478bd9Sstevel@tonic-gate 		count = msgsize(nmp);
6797c478bd9Sstevel@tonic-gate 		error = 0;		/* return success */
6807c478bd9Sstevel@tonic-gate 		break;
6817c478bd9Sstevel@tonic-gate 	}
6827c478bd9Sstevel@tonic-gate 
6837c478bd9Sstevel@tonic-gate 	if (error == 0) {
6847c478bd9Sstevel@tonic-gate 		/* Success; tell the user. */
6857c478bd9Sstevel@tonic-gate 		miocack(q, mp, count, 0);
6867c478bd9Sstevel@tonic-gate 	} else {
6877c478bd9Sstevel@tonic-gate 		/* Failure; send error back upstream. */
6887c478bd9Sstevel@tonic-gate 		miocnak(q, mp, 0, error);
6897c478bd9Sstevel@tonic-gate 	}
6907c478bd9Sstevel@tonic-gate }
6917c478bd9Sstevel@tonic-gate 
6927c478bd9Sstevel@tonic-gate /*
6937c478bd9Sstevel@tonic-gate  * sppp_uwput()
6947c478bd9Sstevel@tonic-gate  *
6957c478bd9Sstevel@tonic-gate  * MT-Perimeters:
6967c478bd9Sstevel@tonic-gate  *    shared inner, shared outer.
6977c478bd9Sstevel@tonic-gate  *
6987c478bd9Sstevel@tonic-gate  * Description:
6997c478bd9Sstevel@tonic-gate  *    Upper write-side put procedure. Messages from above arrive here.
7007c478bd9Sstevel@tonic-gate  */
7012bcc9601SToomas Soome int
sppp_uwput(queue_t * q,mblk_t * mp)7027c478bd9Sstevel@tonic-gate sppp_uwput(queue_t *q, mblk_t *mp)
7037c478bd9Sstevel@tonic-gate {
7047c478bd9Sstevel@tonic-gate 	queue_t		*nextq;
7057c478bd9Sstevel@tonic-gate 	spppstr_t	*sps;
7067c478bd9Sstevel@tonic-gate 	sppa_t		*ppa;
7077c478bd9Sstevel@tonic-gate 	struct iocblk	*iop;
7087c478bd9Sstevel@tonic-gate 	int		error;
7097c478bd9Sstevel@tonic-gate 
7107c478bd9Sstevel@tonic-gate 	ASSERT(q != NULL && q->q_ptr != NULL);
7117c478bd9Sstevel@tonic-gate 	ASSERT(mp != NULL && mp->b_rptr != NULL);
7127c478bd9Sstevel@tonic-gate 	sps = (spppstr_t *)q->q_ptr;
7137c478bd9Sstevel@tonic-gate 	ppa = sps->sps_ppa;
7147c478bd9Sstevel@tonic-gate 
7157c478bd9Sstevel@tonic-gate 	switch (MTYPE(mp)) {
7167c478bd9Sstevel@tonic-gate 	case M_PCPROTO:
7177c478bd9Sstevel@tonic-gate 	case M_PROTO:
7187c478bd9Sstevel@tonic-gate 		if (IS_SPS_CONTROL(sps)) {
7197c478bd9Sstevel@tonic-gate 			ASSERT(ppa != NULL);
7207c478bd9Sstevel@tonic-gate 			/*
7217c478bd9Sstevel@tonic-gate 			 * Intentionally change this to a high priority
7227c478bd9Sstevel@tonic-gate 			 * message so it doesn't get queued up. M_PROTO is
7237c478bd9Sstevel@tonic-gate 			 * specifically used for signalling between pppd and its
7247c478bd9Sstevel@tonic-gate 			 * kernel-level component(s), such as ppptun, so we
7257c478bd9Sstevel@tonic-gate 			 * make sure that it doesn't get queued up behind
7267c478bd9Sstevel@tonic-gate 			 * data messages.
7277c478bd9Sstevel@tonic-gate 			 */
7287c478bd9Sstevel@tonic-gate 			MTYPE(mp) = M_PCPROTO;
7297c478bd9Sstevel@tonic-gate 			if ((ppa->ppa_lower_wq != NULL) &&
7307c478bd9Sstevel@tonic-gate 			    canputnext(ppa->ppa_lower_wq)) {
7317c478bd9Sstevel@tonic-gate 				mutex_enter(&ppa->ppa_sta_lock);
7327c478bd9Sstevel@tonic-gate 				ppa->ppa_mctlsfwd++;
7337c478bd9Sstevel@tonic-gate 				mutex_exit(&ppa->ppa_sta_lock);
7347c478bd9Sstevel@tonic-gate 				putnext(ppa->ppa_lower_wq, mp);
7357c478bd9Sstevel@tonic-gate 			} else {
7367c478bd9Sstevel@tonic-gate 				mutex_enter(&ppa->ppa_sta_lock);
7377c478bd9Sstevel@tonic-gate 				ppa->ppa_mctlsfwderr++;
7387c478bd9Sstevel@tonic-gate 				mutex_exit(&ppa->ppa_sta_lock);
7397c478bd9Sstevel@tonic-gate 				freemsg(mp);
7407c478bd9Sstevel@tonic-gate 			}
7417c478bd9Sstevel@tonic-gate 		} else {
742002c70ffScarlsonj 			(void) sppp_mproto(q, mp, sps);
7432bcc9601SToomas Soome 			return (0);
7447c478bd9Sstevel@tonic-gate 		}
7457c478bd9Sstevel@tonic-gate 		break;
7467c478bd9Sstevel@tonic-gate 	case M_DATA:
7477c478bd9Sstevel@tonic-gate 		if ((nextq = sppp_send(q, &mp, sps)) != NULL)
7487c478bd9Sstevel@tonic-gate 			putnext(nextq, mp);
7497c478bd9Sstevel@tonic-gate 		break;
7507c478bd9Sstevel@tonic-gate 	case M_IOCTL:
7517c478bd9Sstevel@tonic-gate 		error = EINVAL;
7527c478bd9Sstevel@tonic-gate 		iop = (struct iocblk *)mp->b_rptr;
7537c478bd9Sstevel@tonic-gate 		switch (iop->ioc_cmd) {
7547c478bd9Sstevel@tonic-gate 		case DLIOCRAW:
7557c478bd9Sstevel@tonic-gate 		case DL_IOC_HDR_INFO:
7567c478bd9Sstevel@tonic-gate 		case PPPIO_ATTACH:
7577c478bd9Sstevel@tonic-gate 		case PPPIO_DEBUG:
7587c478bd9Sstevel@tonic-gate 		case PPPIO_DETACH:
7597c478bd9Sstevel@tonic-gate 		case PPPIO_LASTMOD:
7607c478bd9Sstevel@tonic-gate 		case PPPIO_MRU:
7617c478bd9Sstevel@tonic-gate 		case PPPIO_MTU:
7627c478bd9Sstevel@tonic-gate 		case PPPIO_USETIMESTAMP:
7637c478bd9Sstevel@tonic-gate 		case PPPIO_BLOCKNP:
7647c478bd9Sstevel@tonic-gate 		case PPPIO_UNBLOCKNP:
7657c478bd9Sstevel@tonic-gate 			qwriter(q, mp, sppp_inner_ioctl, PERIM_INNER);
7662bcc9601SToomas Soome 			return (0);
7677c478bd9Sstevel@tonic-gate 		case I_LINK:
7687c478bd9Sstevel@tonic-gate 		case I_UNLINK:
7697c478bd9Sstevel@tonic-gate 		case PPPIO_NEWPPA:
7707c478bd9Sstevel@tonic-gate 			qwriter(q, mp, sppp_outer_ioctl, PERIM_OUTER);
7712bcc9601SToomas Soome 			return (0);
7727c478bd9Sstevel@tonic-gate 		case PPPIO_NPMODE:
7737c478bd9Sstevel@tonic-gate 		case PPPIO_GIDLE:
7747c478bd9Sstevel@tonic-gate 		case PPPIO_GTYPE:
7757c478bd9Sstevel@tonic-gate 		case PPPIO_GETSTAT64:
7767c478bd9Sstevel@tonic-gate 		case PPPIO_GETCSTAT:
7777c478bd9Sstevel@tonic-gate 			/*
7787c478bd9Sstevel@tonic-gate 			 * These require additional auto variables to
7797c478bd9Sstevel@tonic-gate 			 * handle, so (for optimization reasons)
7807c478bd9Sstevel@tonic-gate 			 * they're moved off to a separate function.
7817c478bd9Sstevel@tonic-gate 			 */
7827c478bd9Sstevel@tonic-gate 			sppp_ioctl(q, mp);
7832bcc9601SToomas Soome 			return (0);
7847c478bd9Sstevel@tonic-gate 		case PPPIO_GETSTAT:
7857c478bd9Sstevel@tonic-gate 			break;			/* 32 bit interface gone */
7867c478bd9Sstevel@tonic-gate 		default:
7877c478bd9Sstevel@tonic-gate 			if (iop->ioc_cr == NULL ||
788f53eecf5SJames Carlson 			    secpolicy_ppp_config(iop->ioc_cr) != 0) {
7897c478bd9Sstevel@tonic-gate 				error = EPERM;
7907c478bd9Sstevel@tonic-gate 				break;
7917c478bd9Sstevel@tonic-gate 			} else if ((ppa == NULL) ||
7927c478bd9Sstevel@tonic-gate 			    (ppa->ppa_lower_wq == NULL)) {
7937c478bd9Sstevel@tonic-gate 				break;		/* return EINVAL */
7947c478bd9Sstevel@tonic-gate 			}
7957c478bd9Sstevel@tonic-gate 			mutex_enter(&ppa->ppa_sta_lock);
7967c478bd9Sstevel@tonic-gate 			/*
7979f7c4232SAnil udupa 			 * See comments in PPPIO_GETSTAT64 case
7989f7c4232SAnil udupa 			 * in sppp_ioctl().
7997c478bd9Sstevel@tonic-gate 			 */
8009f7c4232SAnil udupa 			if (IS_SPS_IOCQ(sps)) {
8019f7c4232SAnil udupa 				mutex_exit(&ppa->ppa_sta_lock);
8029f7c4232SAnil udupa 				if (!putq(q, mp)) {
8039f7c4232SAnil udupa 					error = EAGAIN;
8049f7c4232SAnil udupa 					break;
8059f7c4232SAnil udupa 				}
8062bcc9601SToomas Soome 				return (0);
8079f7c4232SAnil udupa 			} else {
8089f7c4232SAnil udupa 				ppa->ppa_ioctlsfwd++;
8099f7c4232SAnil udupa 				/*
8109f7c4232SAnil udupa 				 * Record the ioctl CMD & ID -
8119f7c4232SAnil udupa 				 * this will be used to check the
8129f7c4232SAnil udupa 				 * ACK or NAK responses coming from below.
8139f7c4232SAnil udupa 				 */
8149f7c4232SAnil udupa 				sps->sps_ioc_id = iop->ioc_id;
8159f7c4232SAnil udupa 				sps->sps_flags |= SPS_IOCQ;
8169f7c4232SAnil udupa 				mutex_exit(&ppa->ppa_sta_lock);
8179f7c4232SAnil udupa 			}
8187c478bd9Sstevel@tonic-gate 			putnext(ppa->ppa_lower_wq, mp);
8192bcc9601SToomas Soome 			return (0);	/* don't ack or nak the request */
8207c478bd9Sstevel@tonic-gate 		}
8217c478bd9Sstevel@tonic-gate 		/* Failure; send error back upstream. */
8227c478bd9Sstevel@tonic-gate 		miocnak(q, mp, 0, error);
8237c478bd9Sstevel@tonic-gate 		break;
8247c478bd9Sstevel@tonic-gate 	case M_FLUSH:
8257c478bd9Sstevel@tonic-gate 		if (*mp->b_rptr & FLUSHW) {
8267c478bd9Sstevel@tonic-gate 			flushq(q, FLUSHDATA);
8277c478bd9Sstevel@tonic-gate 		}
8287c478bd9Sstevel@tonic-gate 		if (*mp->b_rptr & FLUSHR) {
8297c478bd9Sstevel@tonic-gate 			*mp->b_rptr &= ~FLUSHW;
8307c478bd9Sstevel@tonic-gate 			qreply(q, mp);
8317c478bd9Sstevel@tonic-gate 		} else {
8327c478bd9Sstevel@tonic-gate 			freemsg(mp);
8337c478bd9Sstevel@tonic-gate 		}
8347c478bd9Sstevel@tonic-gate 		break;
8357c478bd9Sstevel@tonic-gate 	default:
8367c478bd9Sstevel@tonic-gate 		freemsg(mp);
8377c478bd9Sstevel@tonic-gate 		break;
8387c478bd9Sstevel@tonic-gate 	}
8392bcc9601SToomas Soome 	return (0);
8407c478bd9Sstevel@tonic-gate }
8417c478bd9Sstevel@tonic-gate 
8427c478bd9Sstevel@tonic-gate /*
8437c478bd9Sstevel@tonic-gate  * sppp_uwsrv()
8447c478bd9Sstevel@tonic-gate  *
8457c478bd9Sstevel@tonic-gate  * MT-Perimeters:
8467c478bd9Sstevel@tonic-gate  *    exclusive inner, shared outer.
8477c478bd9Sstevel@tonic-gate  *
8487c478bd9Sstevel@tonic-gate  * Description:
8497c478bd9Sstevel@tonic-gate  *    Upper write-side service procedure. Note that this procedure does
8507c478bd9Sstevel@tonic-gate  *    not get called when a message is placed on our write-side queue, since
8517c478bd9Sstevel@tonic-gate  *    automatic queue scheduling has been turned off by noenable() when
8527c478bd9Sstevel@tonic-gate  *    the queue was opened. We do this on purpose, as we explicitly control
8537c478bd9Sstevel@tonic-gate  *    the write-side queue. Therefore, this procedure gets called when
8547c478bd9Sstevel@tonic-gate  *    the lower write service procedure qenable() the upper write stream queue.
8557c478bd9Sstevel@tonic-gate  */
8562bcc9601SToomas Soome int
sppp_uwsrv(queue_t * q)8577c478bd9Sstevel@tonic-gate sppp_uwsrv(queue_t *q)
8587c478bd9Sstevel@tonic-gate {
8597c478bd9Sstevel@tonic-gate 	spppstr_t	*sps;
8609f7c4232SAnil udupa 	sppa_t		*ppa;
8617c478bd9Sstevel@tonic-gate 	mblk_t		*mp;
8627c478bd9Sstevel@tonic-gate 	queue_t		*nextq;
8639f7c4232SAnil udupa 	struct iocblk	*iop;
8647c478bd9Sstevel@tonic-gate 
8657c478bd9Sstevel@tonic-gate 	ASSERT(q != NULL && q->q_ptr != NULL);
8667c478bd9Sstevel@tonic-gate 	sps = (spppstr_t *)q->q_ptr;
8679f7c4232SAnil udupa 
8687c478bd9Sstevel@tonic-gate 	while ((mp = getq(q)) != NULL) {
8699f7c4232SAnil udupa 		if (MTYPE(mp) == M_IOCTL) {
8709f7c4232SAnil udupa 			ppa = sps->sps_ppa;
8719f7c4232SAnil udupa 			if ((ppa == NULL) || (ppa->ppa_lower_wq == NULL)) {
8729f7c4232SAnil udupa 				miocnak(q, mp, 0, EINVAL);
8739f7c4232SAnil udupa 				continue;
8749f7c4232SAnil udupa 			}
8759f7c4232SAnil udupa 
8769f7c4232SAnil udupa 			iop = (struct iocblk *)mp->b_rptr;
8779f7c4232SAnil udupa 			mutex_enter(&ppa->ppa_sta_lock);
8789f7c4232SAnil udupa 			/*
8799f7c4232SAnil udupa 			 * See comments in PPPIO_GETSTAT64 case
8809f7c4232SAnil udupa 			 * in sppp_ioctl().
8819f7c4232SAnil udupa 			 */
8829f7c4232SAnil udupa 			if (IS_SPS_IOCQ(sps)) {
8839f7c4232SAnil udupa 				mutex_exit(&ppa->ppa_sta_lock);
8849f7c4232SAnil udupa 				if (putbq(q, mp) == 0)
8859f7c4232SAnil udupa 					miocnak(q, mp, 0, EAGAIN);
8869f7c4232SAnil udupa 				break;
8879f7c4232SAnil udupa 			} else {
8889f7c4232SAnil udupa 				ppa->ppa_ioctlsfwd++;
8899f7c4232SAnil udupa 				sps->sps_ioc_id = iop->ioc_id;
8909f7c4232SAnil udupa 				sps->sps_flags |= SPS_IOCQ;
8919f7c4232SAnil udupa 				mutex_exit(&ppa->ppa_sta_lock);
8929f7c4232SAnil udupa 				putnext(ppa->ppa_lower_wq, mp);
8939f7c4232SAnil udupa 			}
8949f7c4232SAnil udupa 		} else if ((nextq =
8959f7c4232SAnil udupa 		    sppp_outpkt(q, &mp, msgdsize(mp), sps)) == NULL) {
8967c478bd9Sstevel@tonic-gate 			if (mp != NULL) {
8977c478bd9Sstevel@tonic-gate 				if (putbq(q, mp) == 0)
8987c478bd9Sstevel@tonic-gate 					freemsg(mp);
8997c478bd9Sstevel@tonic-gate 				break;
9007c478bd9Sstevel@tonic-gate 			}
9017c478bd9Sstevel@tonic-gate 		} else {
9027c478bd9Sstevel@tonic-gate 			putnext(nextq, mp);
9037c478bd9Sstevel@tonic-gate 		}
9047c478bd9Sstevel@tonic-gate 	}
9052bcc9601SToomas Soome 	return (0);
9067c478bd9Sstevel@tonic-gate }
9077c478bd9Sstevel@tonic-gate 
9087c478bd9Sstevel@tonic-gate void
sppp_remove_ppa(spppstr_t * sps)9097c478bd9Sstevel@tonic-gate sppp_remove_ppa(spppstr_t *sps)
9107c478bd9Sstevel@tonic-gate {
9117c478bd9Sstevel@tonic-gate 	spppstr_t *nextsib;
9127c478bd9Sstevel@tonic-gate 	sppa_t *ppa = sps->sps_ppa;
9137c478bd9Sstevel@tonic-gate 
9147c478bd9Sstevel@tonic-gate 	rw_enter(&ppa->ppa_sib_lock, RW_WRITER);
9157c478bd9Sstevel@tonic-gate 	if (ppa->ppa_refcnt <= 1) {
9167c478bd9Sstevel@tonic-gate 		rw_exit(&ppa->ppa_sib_lock);
9177c478bd9Sstevel@tonic-gate 		sppp_free_ppa(ppa);
9187c478bd9Sstevel@tonic-gate 	} else {
9197c478bd9Sstevel@tonic-gate 		nextsib = ppa->ppa_streams;
9207c478bd9Sstevel@tonic-gate 		if (nextsib == sps) {
9217c478bd9Sstevel@tonic-gate 			ppa->ppa_streams = sps->sps_nextsib;
9227c478bd9Sstevel@tonic-gate 		} else {
9237c478bd9Sstevel@tonic-gate 			while (nextsib->sps_nextsib != NULL) {
9247c478bd9Sstevel@tonic-gate 				if (nextsib->sps_nextsib == sps) {
9257c478bd9Sstevel@tonic-gate 					nextsib->sps_nextsib =
9267c478bd9Sstevel@tonic-gate 					    sps->sps_nextsib;
9277c478bd9Sstevel@tonic-gate 					break;
9287c478bd9Sstevel@tonic-gate 				}
9297c478bd9Sstevel@tonic-gate 				nextsib = nextsib->sps_nextsib;
9307c478bd9Sstevel@tonic-gate 			}
9317c478bd9Sstevel@tonic-gate 		}
9327c478bd9Sstevel@tonic-gate 		ppa->ppa_refcnt--;
9337c478bd9Sstevel@tonic-gate 		/*
9347c478bd9Sstevel@tonic-gate 		 * And if this stream was marked as promiscuous
9357c478bd9Sstevel@tonic-gate 		 * (SPS_PROMISC), then we need to update the
9367c478bd9Sstevel@tonic-gate 		 * promiscuous streams count. This should only happen
9377c478bd9Sstevel@tonic-gate 		 * when DL_DETACH_REQ is issued prior to marking the
9387c478bd9Sstevel@tonic-gate 		 * stream as non-promiscuous, through
9397c478bd9Sstevel@tonic-gate 		 * DL_PROMISCOFF_REQ request.
9407c478bd9Sstevel@tonic-gate 		 */
9417c478bd9Sstevel@tonic-gate 		if (IS_SPS_PROMISC(sps)) {
9427c478bd9Sstevel@tonic-gate 			ASSERT(ppa->ppa_promicnt > 0);
9437c478bd9Sstevel@tonic-gate 			ppa->ppa_promicnt--;
9447c478bd9Sstevel@tonic-gate 		}
9457c478bd9Sstevel@tonic-gate 		rw_exit(&ppa->ppa_sib_lock);
9467c478bd9Sstevel@tonic-gate 	}
9477c478bd9Sstevel@tonic-gate 	sps->sps_nextsib = NULL;
9487c478bd9Sstevel@tonic-gate 	sps->sps_ppa = NULL;
9497c478bd9Sstevel@tonic-gate 	freemsg(sps->sps_hangup);
9507c478bd9Sstevel@tonic-gate 	sps->sps_hangup = NULL;
9517c478bd9Sstevel@tonic-gate }
9527c478bd9Sstevel@tonic-gate 
9537c478bd9Sstevel@tonic-gate sppa_t *
sppp_find_ppa(uint32_t ppa_id)9547c478bd9Sstevel@tonic-gate sppp_find_ppa(uint32_t ppa_id)
9557c478bd9Sstevel@tonic-gate {
9567c478bd9Sstevel@tonic-gate 	sppa_t *ppa;
9577c478bd9Sstevel@tonic-gate 
9587c478bd9Sstevel@tonic-gate 	for (ppa = ppa_list; ppa != NULL; ppa = ppa->ppa_nextppa) {
9597c478bd9Sstevel@tonic-gate 		if (ppa->ppa_ppa_id == ppa_id) {
9607c478bd9Sstevel@tonic-gate 			break;	/* found the ppa */
9617c478bd9Sstevel@tonic-gate 		}
9627c478bd9Sstevel@tonic-gate 	}
9637c478bd9Sstevel@tonic-gate 	return (ppa);
9647c478bd9Sstevel@tonic-gate }
9657c478bd9Sstevel@tonic-gate 
9667c478bd9Sstevel@tonic-gate /*
9677c478bd9Sstevel@tonic-gate  * sppp_inner_ioctl()
9687c478bd9Sstevel@tonic-gate  *
9697c478bd9Sstevel@tonic-gate  * MT-Perimeters:
9707c478bd9Sstevel@tonic-gate  *    exclusive inner, shared outer
9717c478bd9Sstevel@tonic-gate  *
9727c478bd9Sstevel@tonic-gate  * Description:
9737c478bd9Sstevel@tonic-gate  *    Called by sppp_uwput as a result of receiving ioctls which require
9747c478bd9Sstevel@tonic-gate  *    an exclusive access at the inner perimeter.
9757c478bd9Sstevel@tonic-gate  */
9767c478bd9Sstevel@tonic-gate static void
sppp_inner_ioctl(queue_t * q,mblk_t * mp)9777c478bd9Sstevel@tonic-gate sppp_inner_ioctl(queue_t *q, mblk_t *mp)
9787c478bd9Sstevel@tonic-gate {
9797c478bd9Sstevel@tonic-gate 	spppstr_t	*sps;
9807c478bd9Sstevel@tonic-gate 	sppa_t		*ppa;
9817c478bd9Sstevel@tonic-gate 	struct iocblk	*iop;
9827c478bd9Sstevel@tonic-gate 	mblk_t		*nmp;
9837c478bd9Sstevel@tonic-gate 	int		error = EINVAL;
9847c478bd9Sstevel@tonic-gate 	int		count = 0;
9857c478bd9Sstevel@tonic-gate 	int		dbgcmd;
9867c478bd9Sstevel@tonic-gate 	int		mru, mtu;
9877c478bd9Sstevel@tonic-gate 	uint32_t	ppa_id;
9887c478bd9Sstevel@tonic-gate 	hrtime_t	hrtime;
9897c478bd9Sstevel@tonic-gate 	uint16_t	proto;
9907c478bd9Sstevel@tonic-gate 
9917c478bd9Sstevel@tonic-gate 	ASSERT(q != NULL && q->q_ptr != NULL);
9927c478bd9Sstevel@tonic-gate 	ASSERT(mp != NULL && mp->b_rptr != NULL);
9937c478bd9Sstevel@tonic-gate 
9947c478bd9Sstevel@tonic-gate 	sps = (spppstr_t *)q->q_ptr;
9957c478bd9Sstevel@tonic-gate 	ppa = sps->sps_ppa;
9967c478bd9Sstevel@tonic-gate 	iop = (struct iocblk *)mp->b_rptr;
9977c478bd9Sstevel@tonic-gate 	switch (iop->ioc_cmd) {
9987c478bd9Sstevel@tonic-gate 	case DLIOCRAW:
9997c478bd9Sstevel@tonic-gate 		if (IS_SPS_CONTROL(sps)) {
10007c478bd9Sstevel@tonic-gate 			break;		/* return EINVAL */
10017c478bd9Sstevel@tonic-gate 		}
10027c478bd9Sstevel@tonic-gate 		sps->sps_flags |= SPS_RAWDATA;
10037c478bd9Sstevel@tonic-gate 		error = 0;		/* return success */
10047c478bd9Sstevel@tonic-gate 		break;
10057c478bd9Sstevel@tonic-gate 	case DL_IOC_HDR_INFO:
10067c478bd9Sstevel@tonic-gate 		if (IS_SPS_CONTROL(sps)) {
10077c478bd9Sstevel@tonic-gate 			break;		/* return EINVAL */
10087c478bd9Sstevel@tonic-gate 		} else if ((mp->b_cont == NULL) ||
10097c478bd9Sstevel@tonic-gate 		    *((t_uscalar_t *)mp->b_cont->b_rptr) != DL_UNITDATA_REQ ||
10107c478bd9Sstevel@tonic-gate 		    (MBLKL(mp->b_cont) < (sizeof (dl_unitdata_req_t) +
1011002c70ffScarlsonj 		    SPPP_ADDRL))) {
10127c478bd9Sstevel@tonic-gate 			error = EPROTO;
10137c478bd9Sstevel@tonic-gate 			break;
10147c478bd9Sstevel@tonic-gate 		} else if (ppa == NULL) {
10157c478bd9Sstevel@tonic-gate 			error = ENOLINK;
10167c478bd9Sstevel@tonic-gate 			break;
10177c478bd9Sstevel@tonic-gate 		}
10187c478bd9Sstevel@tonic-gate 		if ((nmp = allocb(PPP_HDRLEN, BPRI_MED)) == NULL) {
10197c478bd9Sstevel@tonic-gate 			mutex_enter(&ppa->ppa_sta_lock);
10207c478bd9Sstevel@tonic-gate 			ppa->ppa_allocbfail++;
10217c478bd9Sstevel@tonic-gate 			mutex_exit(&ppa->ppa_sta_lock);
10227c478bd9Sstevel@tonic-gate 			error = ENOMEM;
10237c478bd9Sstevel@tonic-gate 			break;
10247c478bd9Sstevel@tonic-gate 		}
10257c478bd9Sstevel@tonic-gate 		*(uchar_t *)nmp->b_wptr++ = PPP_ALLSTATIONS;
10267c478bd9Sstevel@tonic-gate 		*(uchar_t *)nmp->b_wptr++ = PPP_UI;
10277c478bd9Sstevel@tonic-gate 		*(uchar_t *)nmp->b_wptr++ = sps->sps_sap >> 8;
10287c478bd9Sstevel@tonic-gate 		*(uchar_t *)nmp->b_wptr++ = sps->sps_sap & 0xff;
10297c478bd9Sstevel@tonic-gate 		ASSERT(MBLKL(nmp) == PPP_HDRLEN);
10307c478bd9Sstevel@tonic-gate 
10317c478bd9Sstevel@tonic-gate 		linkb(mp, nmp);
10327c478bd9Sstevel@tonic-gate 		sps->sps_flags |= SPS_FASTPATH;
10337c478bd9Sstevel@tonic-gate 		error = 0;		/* return success */
10347c478bd9Sstevel@tonic-gate 		count = msgsize(nmp);
10357c478bd9Sstevel@tonic-gate 		break;
10367c478bd9Sstevel@tonic-gate 	case PPPIO_ATTACH:
10377c478bd9Sstevel@tonic-gate 		if (IS_SPS_CONTROL(sps) || IS_SPS_PIOATTACH(sps) ||
10387c478bd9Sstevel@tonic-gate 		    (sps->sps_dlstate != DL_UNATTACHED) ||
10397c478bd9Sstevel@tonic-gate 		    (iop->ioc_count != sizeof (uint32_t))) {
10407c478bd9Sstevel@tonic-gate 			break;		/* return EINVAL */
10417c478bd9Sstevel@tonic-gate 		} else if (mp->b_cont == NULL) {
10427c478bd9Sstevel@tonic-gate 			error = EPROTO;
10437c478bd9Sstevel@tonic-gate 			break;
10447c478bd9Sstevel@tonic-gate 		}
10457c478bd9Sstevel@tonic-gate 		ASSERT(mp->b_cont->b_rptr != NULL);
10467c478bd9Sstevel@tonic-gate 		/* If there's something here, it's detached. */
10477c478bd9Sstevel@tonic-gate 		if (ppa != NULL) {
10487c478bd9Sstevel@tonic-gate 			sppp_remove_ppa(sps);
10497c478bd9Sstevel@tonic-gate 		}
10507c478bd9Sstevel@tonic-gate 		ppa_id = *(uint32_t *)mp->b_cont->b_rptr;
10517c478bd9Sstevel@tonic-gate 		ppa = sppp_find_ppa(ppa_id);
10527c478bd9Sstevel@tonic-gate 		/*
10537c478bd9Sstevel@tonic-gate 		 * If we can't find it, then it's either because the requestor
10547c478bd9Sstevel@tonic-gate 		 * has supplied a wrong ppa_id to be attached to, or because
10557c478bd9Sstevel@tonic-gate 		 * the control stream for the specified ppa_id has been closed
10567c478bd9Sstevel@tonic-gate 		 * before we get here.
10577c478bd9Sstevel@tonic-gate 		 */
10587c478bd9Sstevel@tonic-gate 		if (ppa == NULL) {
10597c478bd9Sstevel@tonic-gate 			error = ENOENT;
10607c478bd9Sstevel@tonic-gate 			break;
10617c478bd9Sstevel@tonic-gate 		}
1062f53eecf5SJames Carlson 		if (iop->ioc_cr == NULL ||
1063f53eecf5SJames Carlson 		    ppa->ppa_zoneid != crgetzoneid(iop->ioc_cr)) {
1064f53eecf5SJames Carlson 			error = EPERM;
1065f53eecf5SJames Carlson 			break;
1066f53eecf5SJames Carlson 		}
10677c478bd9Sstevel@tonic-gate 		/*
10687c478bd9Sstevel@tonic-gate 		 * Preallocate the hangup message so that we're always
10697c478bd9Sstevel@tonic-gate 		 * able to send this upstream in the event of a
10707c478bd9Sstevel@tonic-gate 		 * catastrophic failure.
10717c478bd9Sstevel@tonic-gate 		 */
10727c478bd9Sstevel@tonic-gate 		if ((sps->sps_hangup = allocb(1, BPRI_MED)) == NULL) {
10737c478bd9Sstevel@tonic-gate 			error = ENOSR;
10747c478bd9Sstevel@tonic-gate 			break;
10757c478bd9Sstevel@tonic-gate 		}
10767c478bd9Sstevel@tonic-gate 		/*
10777c478bd9Sstevel@tonic-gate 		 * There are two ways to attach a stream to a ppa: one is
10787c478bd9Sstevel@tonic-gate 		 * through DLPI (DL_ATTACH_REQ) and the other is through
10797c478bd9Sstevel@tonic-gate 		 * PPPIO_ATTACH. This is why we need to distinguish whether or
10807c478bd9Sstevel@tonic-gate 		 * not a stream was allocated via PPPIO_ATTACH, so that we can
10817c478bd9Sstevel@tonic-gate 		 * properly detach it when we receive PPPIO_DETACH ioctl
10827c478bd9Sstevel@tonic-gate 		 * request.
10837c478bd9Sstevel@tonic-gate 		 */
10847c478bd9Sstevel@tonic-gate 		sps->sps_flags |= SPS_PIOATTACH;
10857c478bd9Sstevel@tonic-gate 		sps->sps_ppa = ppa;
10867c478bd9Sstevel@tonic-gate 		/*
10877c478bd9Sstevel@tonic-gate 		 * Add this stream to the head of the list of sibling streams
10887c478bd9Sstevel@tonic-gate 		 * which belong to the same ppa as specified.
10897c478bd9Sstevel@tonic-gate 		 */
10907c478bd9Sstevel@tonic-gate 		rw_enter(&ppa->ppa_sib_lock, RW_WRITER);
10917c478bd9Sstevel@tonic-gate 		ppa->ppa_refcnt++;
10927c478bd9Sstevel@tonic-gate 		sps->sps_nextsib = ppa->ppa_streams;
10937c478bd9Sstevel@tonic-gate 		ppa->ppa_streams = sps;
10947c478bd9Sstevel@tonic-gate 		rw_exit(&ppa->ppa_sib_lock);
10957c478bd9Sstevel@tonic-gate 		error = 0;		/* return success */
10967c478bd9Sstevel@tonic-gate 		break;
10977c478bd9Sstevel@tonic-gate 	case PPPIO_BLOCKNP:
10987c478bd9Sstevel@tonic-gate 	case PPPIO_UNBLOCKNP:
10997c478bd9Sstevel@tonic-gate 		if (iop->ioc_cr == NULL ||
1100f53eecf5SJames Carlson 		    secpolicy_ppp_config(iop->ioc_cr) != 0) {
11017c478bd9Sstevel@tonic-gate 			error = EPERM;
11027c478bd9Sstevel@tonic-gate 			break;
11037c478bd9Sstevel@tonic-gate 		}
11047c478bd9Sstevel@tonic-gate 		error = miocpullup(mp, sizeof (uint16_t));
11057c478bd9Sstevel@tonic-gate 		if (error != 0)
11067c478bd9Sstevel@tonic-gate 			break;
11077c478bd9Sstevel@tonic-gate 		ASSERT(mp->b_cont->b_rptr != NULL);
11087c478bd9Sstevel@tonic-gate 		proto = *(uint16_t *)mp->b_cont->b_rptr;
11097c478bd9Sstevel@tonic-gate 		if (iop->ioc_cmd == PPPIO_BLOCKNP) {
11107c478bd9Sstevel@tonic-gate 			uint32_t npflagpos = sppp_ppp2np(proto);
11117c478bd9Sstevel@tonic-gate 			/*
11127c478bd9Sstevel@tonic-gate 			 * Mark proto as blocked in ppa_npflag until the
11137c478bd9Sstevel@tonic-gate 			 * corresponding queues for proto have been plumbed.
11147c478bd9Sstevel@tonic-gate 			 */
11157c478bd9Sstevel@tonic-gate 			if (npflagpos != 0) {
11167c478bd9Sstevel@tonic-gate 				mutex_enter(&ppa->ppa_npmutex);
11177c478bd9Sstevel@tonic-gate 				ppa->ppa_npflag |= (1 << npflagpos);
11187c478bd9Sstevel@tonic-gate 				mutex_exit(&ppa->ppa_npmutex);
11197c478bd9Sstevel@tonic-gate 			} else {
11207c478bd9Sstevel@tonic-gate 				error = EINVAL;
11217c478bd9Sstevel@tonic-gate 			}
11227c478bd9Sstevel@tonic-gate 		} else {
11237c478bd9Sstevel@tonic-gate 			/*
11247c478bd9Sstevel@tonic-gate 			 * reset ppa_npflag and release proto
11257c478bd9Sstevel@tonic-gate 			 * packets that were being held in control queue.
11267c478bd9Sstevel@tonic-gate 			 */
11277c478bd9Sstevel@tonic-gate 			sppp_release_pkts(ppa, proto);
11287c478bd9Sstevel@tonic-gate 		}
11297c478bd9Sstevel@tonic-gate 		break;
11307c478bd9Sstevel@tonic-gate 	case PPPIO_DEBUG:
11317c478bd9Sstevel@tonic-gate 		if (iop->ioc_cr == NULL ||
1132f53eecf5SJames Carlson 		    secpolicy_ppp_config(iop->ioc_cr) != 0) {
11337c478bd9Sstevel@tonic-gate 			error = EPERM;
11347c478bd9Sstevel@tonic-gate 			break;
11357c478bd9Sstevel@tonic-gate 		} else if (iop->ioc_count != sizeof (uint32_t)) {
11367c478bd9Sstevel@tonic-gate 			break;		/* return EINVAL */
11377c478bd9Sstevel@tonic-gate 		} else if (mp->b_cont == NULL) {
11387c478bd9Sstevel@tonic-gate 			error = EPROTO;
11397c478bd9Sstevel@tonic-gate 			break;
11407c478bd9Sstevel@tonic-gate 		}
11417c478bd9Sstevel@tonic-gate 		ASSERT(mp->b_cont->b_rptr != NULL);
11427c478bd9Sstevel@tonic-gate 		dbgcmd = *(uint32_t *)mp->b_cont->b_rptr;
11437c478bd9Sstevel@tonic-gate 		/*
11447c478bd9Sstevel@tonic-gate 		 * We accept PPPDBG_LOG + PPPDBG_DRIVER value as an indication
11457c478bd9Sstevel@tonic-gate 		 * that SPS_KDEBUG needs to be enabled for this upper stream.
11467c478bd9Sstevel@tonic-gate 		 */
11477c478bd9Sstevel@tonic-gate 		if (dbgcmd == PPPDBG_LOG + PPPDBG_DRIVER) {
11487c478bd9Sstevel@tonic-gate 			sps->sps_flags |= SPS_KDEBUG;
11497c478bd9Sstevel@tonic-gate 			error = 0;	/* return success */
11507c478bd9Sstevel@tonic-gate 			break;
11517c478bd9Sstevel@tonic-gate 		}
11527c478bd9Sstevel@tonic-gate 		/*
11537c478bd9Sstevel@tonic-gate 		 * Otherwise, for any other values, we send them down only if
11547c478bd9Sstevel@tonic-gate 		 * there is an attachment and if the attachment has something
11557c478bd9Sstevel@tonic-gate 		 * linked underneath it.
11567c478bd9Sstevel@tonic-gate 		 */
11577c478bd9Sstevel@tonic-gate 		if ((ppa == NULL) || (ppa->ppa_lower_wq == NULL)) {
11587c478bd9Sstevel@tonic-gate 			error = ENOLINK;
11597c478bd9Sstevel@tonic-gate 			break;
11607c478bd9Sstevel@tonic-gate 		}
11617c478bd9Sstevel@tonic-gate 		mutex_enter(&ppa->ppa_sta_lock);
11627c478bd9Sstevel@tonic-gate 		/*
11639f7c4232SAnil udupa 		 * See comments in PPPIO_GETSTAT64 case
11649f7c4232SAnil udupa 		 * in sppp_ioctl().
11657c478bd9Sstevel@tonic-gate 		 */
11669f7c4232SAnil udupa 		if (IS_SPS_IOCQ(sps)) {
11679f7c4232SAnil udupa 			mutex_exit(&ppa->ppa_sta_lock);
11689f7c4232SAnil udupa 			if (!putq(q, mp)) {
11699f7c4232SAnil udupa 				error = EAGAIN;
11709f7c4232SAnil udupa 				break;
11719f7c4232SAnil udupa 			}
11729f7c4232SAnil udupa 			return;
11739f7c4232SAnil udupa 		} else {
11749f7c4232SAnil udupa 			ppa->ppa_ioctlsfwd++;
11759f7c4232SAnil udupa 			/*
11769f7c4232SAnil udupa 			 * Record the ioctl CMD & ID -
11779f7c4232SAnil udupa 			 * this will be used to check the
11789f7c4232SAnil udupa 			 * ACK or NAK responses coming from below.
11799f7c4232SAnil udupa 			 */
11809f7c4232SAnil udupa 			sps->sps_ioc_id = iop->ioc_id;
11819f7c4232SAnil udupa 			sps->sps_flags |= SPS_IOCQ;
11829f7c4232SAnil udupa 			mutex_exit(&ppa->ppa_sta_lock);
11839f7c4232SAnil udupa 		}
11847c478bd9Sstevel@tonic-gate 		putnext(ppa->ppa_lower_wq, mp);
11857c478bd9Sstevel@tonic-gate 		return;			/* don't ack or nak the request */
11867c478bd9Sstevel@tonic-gate 	case PPPIO_DETACH:
11877c478bd9Sstevel@tonic-gate 		if (!IS_SPS_PIOATTACH(sps)) {
11887c478bd9Sstevel@tonic-gate 			break;		/* return EINVAL */
11897c478bd9Sstevel@tonic-gate 		}
11907c478bd9Sstevel@tonic-gate 		/*
11917c478bd9Sstevel@tonic-gate 		 * The SPS_PIOATTACH flag set on the stream tells us that
11927c478bd9Sstevel@tonic-gate 		 * the ppa field is still valid. In the event that the control
11937c478bd9Sstevel@tonic-gate 		 * stream be closed prior to this stream's detachment, the
11947c478bd9Sstevel@tonic-gate 		 * SPS_PIOATTACH flag would have been cleared from this stream
11957c478bd9Sstevel@tonic-gate 		 * during close; in that case we won't get here.
11967c478bd9Sstevel@tonic-gate 		 */
11977c478bd9Sstevel@tonic-gate 		ASSERT(ppa != NULL);
11987c478bd9Sstevel@tonic-gate 		ASSERT(ppa->ppa_ctl != sps);
11997c478bd9Sstevel@tonic-gate 		ASSERT(sps->sps_dlstate == DL_UNATTACHED);
12007c478bd9Sstevel@tonic-gate 
12017c478bd9Sstevel@tonic-gate 		/*
12027c478bd9Sstevel@tonic-gate 		 * We don't actually detach anything until the stream is
12037c478bd9Sstevel@tonic-gate 		 * closed or reattached.
12047c478bd9Sstevel@tonic-gate 		 */
12057c478bd9Sstevel@tonic-gate 
12067c478bd9Sstevel@tonic-gate 		sps->sps_flags &= ~SPS_PIOATTACH;
12077c478bd9Sstevel@tonic-gate 		error = 0;		/* return success */
12087c478bd9Sstevel@tonic-gate 		break;
12097c478bd9Sstevel@tonic-gate 	case PPPIO_LASTMOD:
12107c478bd9Sstevel@tonic-gate 		if (!IS_SPS_CONTROL(sps)) {
12117c478bd9Sstevel@tonic-gate 			break;		/* return EINVAL */
12127c478bd9Sstevel@tonic-gate 		}
12137c478bd9Sstevel@tonic-gate 		ASSERT(ppa != NULL);
12147c478bd9Sstevel@tonic-gate 		ppa->ppa_flags |= PPA_LASTMOD;
12157c478bd9Sstevel@tonic-gate 		error = 0;		/* return success */
12167c478bd9Sstevel@tonic-gate 		break;
12177c478bd9Sstevel@tonic-gate 	case PPPIO_MRU:
12187c478bd9Sstevel@tonic-gate 		if (!IS_SPS_CONTROL(sps) ||
12197c478bd9Sstevel@tonic-gate 		    (iop->ioc_count != sizeof (uint32_t))) {
12207c478bd9Sstevel@tonic-gate 			break;		/* return EINVAL */
12217c478bd9Sstevel@tonic-gate 		} else if (mp->b_cont == NULL) {
12227c478bd9Sstevel@tonic-gate 			error = EPROTO;
12237c478bd9Sstevel@tonic-gate 			break;
12247c478bd9Sstevel@tonic-gate 		}
12257c478bd9Sstevel@tonic-gate 		ASSERT(ppa != NULL);
12267c478bd9Sstevel@tonic-gate 		ASSERT(mp->b_cont->b_rptr != NULL);
12277c478bd9Sstevel@tonic-gate 		mru = *(uint32_t *)mp->b_cont->b_rptr;
12287c478bd9Sstevel@tonic-gate 		if ((mru <= 0) || (mru > PPP_MAXMRU)) {
12297c478bd9Sstevel@tonic-gate 			error = EPROTO;
12307c478bd9Sstevel@tonic-gate 			break;
12317c478bd9Sstevel@tonic-gate 		}
12327c478bd9Sstevel@tonic-gate 		if (mru < PPP_MRU) {
12337c478bd9Sstevel@tonic-gate 			mru = PPP_MRU;
12347c478bd9Sstevel@tonic-gate 		}
12357c478bd9Sstevel@tonic-gate 		ppa->ppa_mru = (uint16_t)mru;
12367c478bd9Sstevel@tonic-gate 		/*
12377c478bd9Sstevel@tonic-gate 		 * If there's something beneath this driver for the ppa, then
12387c478bd9Sstevel@tonic-gate 		 * inform it (or them) of the MRU size. Only do this is we
12397c478bd9Sstevel@tonic-gate 		 * are not the last PPP module on the stream.
12407c478bd9Sstevel@tonic-gate 		 */
12417c478bd9Sstevel@tonic-gate 		if (!IS_PPA_LASTMOD(ppa) && (ppa->ppa_lower_wq != NULL)) {
12427c478bd9Sstevel@tonic-gate 			(void) putctl4(ppa->ppa_lower_wq, M_CTL, PPPCTL_MRU,
12437c478bd9Sstevel@tonic-gate 			    mru);
12447c478bd9Sstevel@tonic-gate 		}
12457c478bd9Sstevel@tonic-gate 		error = 0;		/* return success */
12467c478bd9Sstevel@tonic-gate 		break;
12477c478bd9Sstevel@tonic-gate 	case PPPIO_MTU:
12487c478bd9Sstevel@tonic-gate 		if (!IS_SPS_CONTROL(sps) ||
12497c478bd9Sstevel@tonic-gate 		    (iop->ioc_count != sizeof (uint32_t))) {
12507c478bd9Sstevel@tonic-gate 			break;		/* return EINVAL */
12517c478bd9Sstevel@tonic-gate 		} else if (mp->b_cont == NULL) {
12527c478bd9Sstevel@tonic-gate 			error = EPROTO;
12537c478bd9Sstevel@tonic-gate 			break;
12547c478bd9Sstevel@tonic-gate 		}
12557c478bd9Sstevel@tonic-gate 		ASSERT(ppa != NULL);
12567c478bd9Sstevel@tonic-gate 		ASSERT(mp->b_cont->b_rptr != NULL);
12577c478bd9Sstevel@tonic-gate 		mtu = *(uint32_t *)mp->b_cont->b_rptr;
12587c478bd9Sstevel@tonic-gate 		if ((mtu <= 0) || (mtu > PPP_MAXMTU)) {
12597c478bd9Sstevel@tonic-gate 			error = EPROTO;
12607c478bd9Sstevel@tonic-gate 			break;
12617c478bd9Sstevel@tonic-gate 		}
12627c478bd9Sstevel@tonic-gate 		ppa->ppa_mtu = (uint16_t)mtu;
12637c478bd9Sstevel@tonic-gate 		/*
12647c478bd9Sstevel@tonic-gate 		 * If there's something beneath this driver for the ppa, then
12657c478bd9Sstevel@tonic-gate 		 * inform it (or them) of the MTU size. Only do this if we
12667c478bd9Sstevel@tonic-gate 		 * are not the last PPP module on the stream.
12677c478bd9Sstevel@tonic-gate 		 */
12687c478bd9Sstevel@tonic-gate 		if (!IS_PPA_LASTMOD(ppa) && (ppa->ppa_lower_wq != NULL)) {
12697c478bd9Sstevel@tonic-gate 			(void) putctl4(ppa->ppa_lower_wq, M_CTL, PPPCTL_MTU,
12707c478bd9Sstevel@tonic-gate 			    mtu);
12717c478bd9Sstevel@tonic-gate 		}
12727c478bd9Sstevel@tonic-gate 		error = 0;		/* return success */
12737c478bd9Sstevel@tonic-gate 		break;
12747c478bd9Sstevel@tonic-gate 	case PPPIO_USETIMESTAMP:
12757c478bd9Sstevel@tonic-gate 		if (!IS_SPS_CONTROL(sps)) {
12767c478bd9Sstevel@tonic-gate 			break;		/* return EINVAL */
12777c478bd9Sstevel@tonic-gate 		}
12787c478bd9Sstevel@tonic-gate 		if (!IS_PPA_TIMESTAMP(ppa)) {
12797c478bd9Sstevel@tonic-gate 			hrtime = gethrtime();
12807c478bd9Sstevel@tonic-gate 			ppa->ppa_lasttx = ppa->ppa_lastrx = hrtime;
12817c478bd9Sstevel@tonic-gate 			ppa->ppa_flags |= PPA_TIMESTAMP;
12827c478bd9Sstevel@tonic-gate 		}
12837c478bd9Sstevel@tonic-gate 		error = 0;
12847c478bd9Sstevel@tonic-gate 		break;
12857c478bd9Sstevel@tonic-gate 	}
12867c478bd9Sstevel@tonic-gate 
12877c478bd9Sstevel@tonic-gate 	if (error == 0) {
12887c478bd9Sstevel@tonic-gate 		/* Success; tell the user */
12897c478bd9Sstevel@tonic-gate 		miocack(q, mp, count, 0);
12907c478bd9Sstevel@tonic-gate 	} else {
12917c478bd9Sstevel@tonic-gate 		/* Failure; send error back upstream */
12927c478bd9Sstevel@tonic-gate 		miocnak(q, mp, 0, error);
12937c478bd9Sstevel@tonic-gate 	}
12947c478bd9Sstevel@tonic-gate }
12957c478bd9Sstevel@tonic-gate 
12967c478bd9Sstevel@tonic-gate /*
12977c478bd9Sstevel@tonic-gate  * sppp_outer_ioctl()
12987c478bd9Sstevel@tonic-gate  *
12997c478bd9Sstevel@tonic-gate  * MT-Perimeters:
13007c478bd9Sstevel@tonic-gate  *    exclusive inner, exclusive outer
13017c478bd9Sstevel@tonic-gate  *
13027c478bd9Sstevel@tonic-gate  * Description:
13037c478bd9Sstevel@tonic-gate  *    Called by sppp_uwput as a result of receiving ioctls which require
13047c478bd9Sstevel@tonic-gate  *    an exclusive access at the outer perimeter.
13057c478bd9Sstevel@tonic-gate  */
13067c478bd9Sstevel@tonic-gate static void
sppp_outer_ioctl(queue_t * q,mblk_t * mp)13077c478bd9Sstevel@tonic-gate sppp_outer_ioctl(queue_t *q, mblk_t *mp)
13087c478bd9Sstevel@tonic-gate {
1309f53eecf5SJames Carlson 	spppstr_t	*sps = q->q_ptr;
13107c478bd9Sstevel@tonic-gate 	spppstr_t	*nextsib;
13117c478bd9Sstevel@tonic-gate 	queue_t		*lwq;
13127c478bd9Sstevel@tonic-gate 	sppa_t		*ppa;
13137c478bd9Sstevel@tonic-gate 	struct iocblk	*iop;
13147c478bd9Sstevel@tonic-gate 	int		error = EINVAL;
13157c478bd9Sstevel@tonic-gate 	int		count = 0;
13167c478bd9Sstevel@tonic-gate 	uint32_t	ppa_id;
13177c478bd9Sstevel@tonic-gate 	mblk_t		*nmp;
1318f53eecf5SJames Carlson 	zoneid_t	zoneid;
13197c478bd9Sstevel@tonic-gate 
13207c478bd9Sstevel@tonic-gate 	sps = (spppstr_t *)q->q_ptr;
13217c478bd9Sstevel@tonic-gate 	ppa = sps->sps_ppa;
13227c478bd9Sstevel@tonic-gate 	iop = (struct iocblk *)mp->b_rptr;
13237c478bd9Sstevel@tonic-gate 	switch (iop->ioc_cmd) {
13247c478bd9Sstevel@tonic-gate 	case I_LINK:
13257c478bd9Sstevel@tonic-gate 		if (!IS_SPS_CONTROL(sps)) {
13267c478bd9Sstevel@tonic-gate 			break;		/* return EINVAL */
13277c478bd9Sstevel@tonic-gate 		} else if (ppa->ppa_lower_wq != NULL) {
13287c478bd9Sstevel@tonic-gate 			error = EEXIST;
13297c478bd9Sstevel@tonic-gate 			break;
13307c478bd9Sstevel@tonic-gate 		}
13317c478bd9Sstevel@tonic-gate 		ASSERT(ppa->ppa_ctl != NULL);
13327c478bd9Sstevel@tonic-gate 		ASSERT(sps->sps_npmode == NPMODE_PASS);
13337c478bd9Sstevel@tonic-gate 		ASSERT(mp->b_cont != NULL && mp->b_cont->b_rptr != NULL);
13347c478bd9Sstevel@tonic-gate 
13357c478bd9Sstevel@tonic-gate 		lwq = ((struct linkblk *)mp->b_cont->b_rptr)->l_qbot;
13367c478bd9Sstevel@tonic-gate 		ASSERT(lwq != NULL);
13377c478bd9Sstevel@tonic-gate 
13387c478bd9Sstevel@tonic-gate 		ppa->ppa_lower_wq = lwq;
13397c478bd9Sstevel@tonic-gate 		lwq->q_ptr = RD(lwq)->q_ptr = (caddr_t)ppa;
13407c478bd9Sstevel@tonic-gate 		/*
13417c478bd9Sstevel@tonic-gate 		 * Unblock upper network streams which now feed this lower
13427c478bd9Sstevel@tonic-gate 		 * stream. We don't need to hold ppa_sib_lock here, since we
13437c478bd9Sstevel@tonic-gate 		 * are writer at the outer perimeter.
13447c478bd9Sstevel@tonic-gate 		 */
13457c478bd9Sstevel@tonic-gate 		if (WR(sps->sps_rq)->q_first != NULL)
13467c478bd9Sstevel@tonic-gate 			qenable(WR(sps->sps_rq));
13477c478bd9Sstevel@tonic-gate 		for (nextsib = ppa->ppa_streams; nextsib != NULL;
13487c478bd9Sstevel@tonic-gate 		    nextsib = nextsib->sps_nextsib) {
13497c478bd9Sstevel@tonic-gate 			nextsib->sps_npmode = NPMODE_PASS;
13507c478bd9Sstevel@tonic-gate 			if (WR(nextsib->sps_rq)->q_first != NULL) {
13517c478bd9Sstevel@tonic-gate 				qenable(WR(nextsib->sps_rq));
13527c478bd9Sstevel@tonic-gate 			}
13537c478bd9Sstevel@tonic-gate 		}
1354f53eecf5SJames Carlson 
1355f53eecf5SJames Carlson 		/*
1356f53eecf5SJames Carlson 		 * Also unblock (run once) our lower read-side queue.  This is
1357f53eecf5SJames Carlson 		 * where packets received while doing the I_LINK may be
1358f53eecf5SJames Carlson 		 * languishing; see sppp_lrsrv.
1359f53eecf5SJames Carlson 		 */
1360f53eecf5SJames Carlson 		qenable(RD(lwq));
1361f53eecf5SJames Carlson 
13627c478bd9Sstevel@tonic-gate 		/*
13637c478bd9Sstevel@tonic-gate 		 * Send useful information down to the modules which are now
13647c478bd9Sstevel@tonic-gate 		 * linked below this driver (for this particular ppa). Only
13657c478bd9Sstevel@tonic-gate 		 * do this if we are not the last PPP module on the stream.
13667c478bd9Sstevel@tonic-gate 		 */
13677c478bd9Sstevel@tonic-gate 		if (!IS_PPA_LASTMOD(ppa)) {
13687c478bd9Sstevel@tonic-gate 			(void) putctl8(lwq, M_CTL, PPPCTL_UNIT,
13697c478bd9Sstevel@tonic-gate 			    ppa->ppa_ppa_id);
13707c478bd9Sstevel@tonic-gate 			(void) putctl4(lwq, M_CTL, PPPCTL_MRU, ppa->ppa_mru);
13717c478bd9Sstevel@tonic-gate 			(void) putctl4(lwq, M_CTL, PPPCTL_MTU, ppa->ppa_mtu);
13727c478bd9Sstevel@tonic-gate 		}
13737c478bd9Sstevel@tonic-gate 
13747c478bd9Sstevel@tonic-gate 		if (IS_SPS_KDEBUG(sps)) {
13757c478bd9Sstevel@tonic-gate 			SPDEBUG(PPP_DRV_NAME
13767c478bd9Sstevel@tonic-gate 			    "/%d: I_LINK lwq=0x%p sps=0x%p flags=0x%b ppa=0x%p "
13777c478bd9Sstevel@tonic-gate 			    "flags=0x%b\n", sps->sps_mn_id,
13787c478bd9Sstevel@tonic-gate 			    (void *)ppa->ppa_lower_wq, (void *)sps,
13797c478bd9Sstevel@tonic-gate 			    sps->sps_flags, SPS_FLAGS_STR,
13807c478bd9Sstevel@tonic-gate 			    (void *)ppa, ppa->ppa_flags,
13817c478bd9Sstevel@tonic-gate 			    PPA_FLAGS_STR);
13827c478bd9Sstevel@tonic-gate 		}
13837c478bd9Sstevel@tonic-gate 		error = 0;		/* return success */
13847c478bd9Sstevel@tonic-gate 		break;
13857c478bd9Sstevel@tonic-gate 	case I_UNLINK:
13867c478bd9Sstevel@tonic-gate 		ASSERT(IS_SPS_CONTROL(sps));
13877c478bd9Sstevel@tonic-gate 		ASSERT(ppa != NULL);
13887c478bd9Sstevel@tonic-gate 		lwq = ppa->ppa_lower_wq;
13897c478bd9Sstevel@tonic-gate 		ASSERT(mp->b_cont != NULL && mp->b_cont->b_rptr != NULL);
13907c478bd9Sstevel@tonic-gate 		ASSERT(lwq == ((struct linkblk *)mp->b_cont->b_rptr)->l_qbot);
13917c478bd9Sstevel@tonic-gate 
13927c478bd9Sstevel@tonic-gate 		if (IS_SPS_KDEBUG(sps)) {
13937c478bd9Sstevel@tonic-gate 			SPDEBUG(PPP_DRV_NAME
13947c478bd9Sstevel@tonic-gate 			    "/%d: I_UNLINK lwq=0x%p sps=0x%p flags=0x%b "
13957c478bd9Sstevel@tonic-gate 			    "ppa=0x%p flags=0x%b\n", sps->sps_mn_id,
13967c478bd9Sstevel@tonic-gate 			    (void *)lwq, (void *)sps, sps->sps_flags,
13977c478bd9Sstevel@tonic-gate 			    SPS_FLAGS_STR, (void *)ppa, ppa->ppa_flags,
13987c478bd9Sstevel@tonic-gate 			    PPA_FLAGS_STR);
13997c478bd9Sstevel@tonic-gate 		}
14007c478bd9Sstevel@tonic-gate 		/*
14017c478bd9Sstevel@tonic-gate 		 * While accessing the outer perimeter exclusively, we
14027c478bd9Sstevel@tonic-gate 		 * disassociate our ppa's lower_wq from the lower stream linked
14037c478bd9Sstevel@tonic-gate 		 * beneath us, and we also disassociate our control stream from
14047c478bd9Sstevel@tonic-gate 		 * the q_ptr of the lower stream.
14057c478bd9Sstevel@tonic-gate 		 */
14067c478bd9Sstevel@tonic-gate 		lwq->q_ptr = RD(lwq)->q_ptr = NULL;
14077c478bd9Sstevel@tonic-gate 		ppa->ppa_lower_wq = NULL;
14087c478bd9Sstevel@tonic-gate 		/*
14097c478bd9Sstevel@tonic-gate 		 * Unblock streams which now feed back up the control stream,
14107c478bd9Sstevel@tonic-gate 		 * and acknowledge the request. We don't need to hold
14117c478bd9Sstevel@tonic-gate 		 * ppa_sib_lock here, since we are writer at the outer
14127c478bd9Sstevel@tonic-gate 		 * perimeter.
14137c478bd9Sstevel@tonic-gate 		 */
14147c478bd9Sstevel@tonic-gate 		if (WR(sps->sps_rq)->q_first != NULL)
14157c478bd9Sstevel@tonic-gate 			qenable(WR(sps->sps_rq));
14167c478bd9Sstevel@tonic-gate 		for (nextsib = ppa->ppa_streams; nextsib != NULL;
14177c478bd9Sstevel@tonic-gate 		    nextsib = nextsib->sps_nextsib) {
14187c478bd9Sstevel@tonic-gate 			if (WR(nextsib->sps_rq)->q_first != NULL) {
14197c478bd9Sstevel@tonic-gate 				qenable(WR(nextsib->sps_rq));
14207c478bd9Sstevel@tonic-gate 			}
14217c478bd9Sstevel@tonic-gate 		}
14227c478bd9Sstevel@tonic-gate 		error = 0;		/* return success */
14237c478bd9Sstevel@tonic-gate 		break;
14247c478bd9Sstevel@tonic-gate 	case PPPIO_NEWPPA:
14257c478bd9Sstevel@tonic-gate 		/*
14267c478bd9Sstevel@tonic-gate 		 * Do sanity check to ensure that we don't accept PPPIO_NEWPPA
14277c478bd9Sstevel@tonic-gate 		 * on a stream which DLPI is used (since certain DLPI messages
14287c478bd9Sstevel@tonic-gate 		 * will cause state transition reflected in sps_dlstate,
14297c478bd9Sstevel@tonic-gate 		 * changing it from its default DL_UNATTACHED value). In other
14307c478bd9Sstevel@tonic-gate 		 * words, we won't allow a network/snoop stream to become
14317c478bd9Sstevel@tonic-gate 		 * a control stream.
14327c478bd9Sstevel@tonic-gate 		 */
14337c478bd9Sstevel@tonic-gate 		if (iop->ioc_cr == NULL ||
1434f53eecf5SJames Carlson 		    secpolicy_ppp_config(iop->ioc_cr) != 0) {
14357c478bd9Sstevel@tonic-gate 			error = EPERM;
14367c478bd9Sstevel@tonic-gate 			break;
14377c478bd9Sstevel@tonic-gate 		} else if (IS_SPS_CONTROL(sps) || IS_SPS_PIOATTACH(sps) ||
14387c478bd9Sstevel@tonic-gate 		    (ppa != NULL) || (sps->sps_dlstate != DL_UNATTACHED)) {
14397c478bd9Sstevel@tonic-gate 			break;		/* return EINVAL */
14407c478bd9Sstevel@tonic-gate 		}
14417c478bd9Sstevel@tonic-gate 		/* Get requested unit number (if any) */
14427c478bd9Sstevel@tonic-gate 		if (iop->ioc_count == sizeof (uint32_t) && mp->b_cont != NULL)
14437c478bd9Sstevel@tonic-gate 			ppa_id = *(uint32_t *)mp->b_cont->b_rptr;
14447c478bd9Sstevel@tonic-gate 		else
14457c478bd9Sstevel@tonic-gate 			ppa_id = 0;
14467c478bd9Sstevel@tonic-gate 		/* Get mblk to use for response message */
14477c478bd9Sstevel@tonic-gate 		nmp = allocb(sizeof (uint32_t), BPRI_MED);
14487c478bd9Sstevel@tonic-gate 		if (nmp == NULL) {
14497c478bd9Sstevel@tonic-gate 			error = ENOSR;
14507c478bd9Sstevel@tonic-gate 			break;
14517c478bd9Sstevel@tonic-gate 		}
14527c478bd9Sstevel@tonic-gate 		if (mp->b_cont != NULL) {
14537c478bd9Sstevel@tonic-gate 			freemsg(mp->b_cont);
14547c478bd9Sstevel@tonic-gate 		}
14557c478bd9Sstevel@tonic-gate 		mp->b_cont = nmp;		/* chain our response mblk */
14567c478bd9Sstevel@tonic-gate 		/*
14577c478bd9Sstevel@tonic-gate 		 * Walk the global ppa list and determine the lowest
14587c478bd9Sstevel@tonic-gate 		 * available ppa_id number to be used.
14597c478bd9Sstevel@tonic-gate 		 */
14607c478bd9Sstevel@tonic-gate 		if (ppa_id == (uint32_t)-1)
14617c478bd9Sstevel@tonic-gate 			ppa_id = 0;
1462f53eecf5SJames Carlson 		zoneid = crgetzoneid(iop->ioc_cr);
14637c478bd9Sstevel@tonic-gate 		for (ppa = ppa_list; ppa != NULL; ppa = ppa->ppa_nextppa) {
14647c478bd9Sstevel@tonic-gate 			if (ppa_id == (uint32_t)-2) {
1465f53eecf5SJames Carlson 				if (ppa->ppa_ctl == NULL &&
1466f53eecf5SJames Carlson 				    ppa->ppa_zoneid == zoneid)
14677c478bd9Sstevel@tonic-gate 					break;
14687c478bd9Sstevel@tonic-gate 			} else {
14697c478bd9Sstevel@tonic-gate 				if (ppa_id < ppa->ppa_ppa_id)
14707c478bd9Sstevel@tonic-gate 					break;
14717c478bd9Sstevel@tonic-gate 				if (ppa_id == ppa->ppa_ppa_id)
14727c478bd9Sstevel@tonic-gate 					++ppa_id;
14737c478bd9Sstevel@tonic-gate 			}
14747c478bd9Sstevel@tonic-gate 		}
14757c478bd9Sstevel@tonic-gate 		if (ppa_id == (uint32_t)-2) {
14767c478bd9Sstevel@tonic-gate 			if (ppa == NULL) {
14777c478bd9Sstevel@tonic-gate 				error = ENXIO;
14787c478bd9Sstevel@tonic-gate 				break;
14797c478bd9Sstevel@tonic-gate 			}
14807c478bd9Sstevel@tonic-gate 			/* Clear timestamp and lastmod flags */
14817c478bd9Sstevel@tonic-gate 			ppa->ppa_flags = 0;
14827c478bd9Sstevel@tonic-gate 		} else {
1483f53eecf5SJames Carlson 			ppa = sppp_create_ppa(ppa_id, zoneid);
14847c478bd9Sstevel@tonic-gate 			if (ppa == NULL) {
14857c478bd9Sstevel@tonic-gate 				error = ENOMEM;
14867c478bd9Sstevel@tonic-gate 				break;
14877c478bd9Sstevel@tonic-gate 			}
14887c478bd9Sstevel@tonic-gate 		}
14897c478bd9Sstevel@tonic-gate 
14907c478bd9Sstevel@tonic-gate 		sps->sps_ppa = ppa;		/* chain the ppa structure */
14917c478bd9Sstevel@tonic-gate 		sps->sps_npmode = NPMODE_PASS;	/* network packets may travel */
14927c478bd9Sstevel@tonic-gate 		sps->sps_flags |= SPS_CONTROL;	/* this is the control stream */
14937c478bd9Sstevel@tonic-gate 
14947c478bd9Sstevel@tonic-gate 		ppa->ppa_refcnt++;		/* new PPA reference */
14957c478bd9Sstevel@tonic-gate 		ppa->ppa_ctl = sps;		/* back ptr to upper stream */
14967c478bd9Sstevel@tonic-gate 		/*
14977c478bd9Sstevel@tonic-gate 		 * Return the newly created ppa_id to the requestor and
14987c478bd9Sstevel@tonic-gate 		 * acnowledge the request.
14997c478bd9Sstevel@tonic-gate 		 */
15007c478bd9Sstevel@tonic-gate 		*(uint32_t *)nmp->b_wptr = ppa->ppa_ppa_id;
15017c478bd9Sstevel@tonic-gate 		nmp->b_wptr += sizeof (uint32_t);
15027c478bd9Sstevel@tonic-gate 
15037c478bd9Sstevel@tonic-gate 		if (IS_SPS_KDEBUG(sps)) {
15047c478bd9Sstevel@tonic-gate 			SPDEBUG(PPP_DRV_NAME
15057c478bd9Sstevel@tonic-gate 			    "/%d: PPPIO_NEWPPA ppa_id=%d sps=0x%p flags=0x%b "
15067c478bd9Sstevel@tonic-gate 			    "ppa=0x%p flags=0x%b\n", sps->sps_mn_id, ppa_id,
15077c478bd9Sstevel@tonic-gate 			    (void *)sps, sps->sps_flags, SPS_FLAGS_STR,
15087c478bd9Sstevel@tonic-gate 			    (void *)ppa, ppa->ppa_flags,
15097c478bd9Sstevel@tonic-gate 			    PPA_FLAGS_STR);
15107c478bd9Sstevel@tonic-gate 		}
15117c478bd9Sstevel@tonic-gate 		count = msgsize(nmp);
15127c478bd9Sstevel@tonic-gate 		error = 0;
15137c478bd9Sstevel@tonic-gate 		break;
15147c478bd9Sstevel@tonic-gate 	}
15157c478bd9Sstevel@tonic-gate 
15167c478bd9Sstevel@tonic-gate 	if (error == 0) {
15177c478bd9Sstevel@tonic-gate 		/* Success; tell the user. */
15187c478bd9Sstevel@tonic-gate 		miocack(q, mp, count, 0);
15197c478bd9Sstevel@tonic-gate 	} else {
15207c478bd9Sstevel@tonic-gate 		/* Failure; send error back upstream. */
15217c478bd9Sstevel@tonic-gate 		miocnak(q, mp, 0, error);
15227c478bd9Sstevel@tonic-gate 	}
15237c478bd9Sstevel@tonic-gate }
15247c478bd9Sstevel@tonic-gate 
15257c478bd9Sstevel@tonic-gate /*
15267c478bd9Sstevel@tonic-gate  * sppp_send()
15277c478bd9Sstevel@tonic-gate  *
15287c478bd9Sstevel@tonic-gate  * MT-Perimeters:
15297c478bd9Sstevel@tonic-gate  *    shared inner, shared outer.
15307c478bd9Sstevel@tonic-gate  *
15317c478bd9Sstevel@tonic-gate  * Description:
15327c478bd9Sstevel@tonic-gate  *    Called by sppp_uwput to handle M_DATA message type.  Returns
15337c478bd9Sstevel@tonic-gate  *    queue_t for putnext, or NULL to mean that the packet was
15347c478bd9Sstevel@tonic-gate  *    handled internally.
15357c478bd9Sstevel@tonic-gate  */
15367c478bd9Sstevel@tonic-gate static queue_t *
sppp_send(queue_t * q,mblk_t ** mpp,spppstr_t * sps)15377c478bd9Sstevel@tonic-gate sppp_send(queue_t *q, mblk_t **mpp, spppstr_t *sps)
15387c478bd9Sstevel@tonic-gate {
15397c478bd9Sstevel@tonic-gate 	mblk_t	*mp;
15407c478bd9Sstevel@tonic-gate 	sppa_t	*ppa;
15417c478bd9Sstevel@tonic-gate 	int	is_promisc;
15427c478bd9Sstevel@tonic-gate 	int	msize;
15437c478bd9Sstevel@tonic-gate 	int	error = 0;
15447c478bd9Sstevel@tonic-gate 	queue_t	*nextq;
15457c478bd9Sstevel@tonic-gate 
15467c478bd9Sstevel@tonic-gate 	ASSERT(mpp != NULL);
15477c478bd9Sstevel@tonic-gate 	mp = *mpp;
15487c478bd9Sstevel@tonic-gate 	ASSERT(q != NULL && q->q_ptr != NULL);
15497c478bd9Sstevel@tonic-gate 	ASSERT(mp != NULL && mp->b_rptr != NULL);
15507c478bd9Sstevel@tonic-gate 	ASSERT(sps != NULL);
15517c478bd9Sstevel@tonic-gate 	ASSERT(q->q_ptr == sps);
15527c478bd9Sstevel@tonic-gate 	/*
15537c478bd9Sstevel@tonic-gate 	 * We only let M_DATA through if the sender is either the control
15547c478bd9Sstevel@tonic-gate 	 * stream (for PPP control packets) or one of the network streams
15557c478bd9Sstevel@tonic-gate 	 * (for IP packets) in IP fastpath mode. If this stream is not attached
15567c478bd9Sstevel@tonic-gate 	 * to any ppas, then discard data coming down through this stream.
15577c478bd9Sstevel@tonic-gate 	 */
15587c478bd9Sstevel@tonic-gate 	ppa = sps->sps_ppa;
15597c478bd9Sstevel@tonic-gate 	if (ppa == NULL) {
15607c478bd9Sstevel@tonic-gate 		ASSERT(!IS_SPS_CONTROL(sps));
15617c478bd9Sstevel@tonic-gate 		error = ENOLINK;
15627c478bd9Sstevel@tonic-gate 	} else if (!IS_SPS_CONTROL(sps) && !IS_SPS_FASTPATH(sps)) {
15637c478bd9Sstevel@tonic-gate 		error = EPROTO;
15647c478bd9Sstevel@tonic-gate 	}
15657c478bd9Sstevel@tonic-gate 	if (error != 0) {
15667c478bd9Sstevel@tonic-gate 		merror(q, mp, error);
15677c478bd9Sstevel@tonic-gate 		return (NULL);
15687c478bd9Sstevel@tonic-gate 	}
15697c478bd9Sstevel@tonic-gate 	msize = msgdsize(mp);
15707c478bd9Sstevel@tonic-gate 	if (msize > (ppa->ppa_mtu + PPP_HDRLEN)) {
15717c478bd9Sstevel@tonic-gate 		/* Log, and send it anyway */
15727c478bd9Sstevel@tonic-gate 		mutex_enter(&ppa->ppa_sta_lock);
15737c478bd9Sstevel@tonic-gate 		ppa->ppa_otoolongs++;
15747c478bd9Sstevel@tonic-gate 		mutex_exit(&ppa->ppa_sta_lock);
15757c478bd9Sstevel@tonic-gate 	} else if (msize < PPP_HDRLEN) {
15767c478bd9Sstevel@tonic-gate 		/*
15777c478bd9Sstevel@tonic-gate 		 * Log, and send it anyway. We log it because we get things
15787c478bd9Sstevel@tonic-gate 		 * in M_DATA form here, which tells us that the sender is
15797c478bd9Sstevel@tonic-gate 		 * either IP in fastpath transmission mode, or pppd. In both
15807c478bd9Sstevel@tonic-gate 		 * cases, they are currently expected to send the 4-bytes
15817c478bd9Sstevel@tonic-gate 		 * PPP header in front of any possible payloads.
15827c478bd9Sstevel@tonic-gate 		 */
15837c478bd9Sstevel@tonic-gate 		mutex_enter(&ppa->ppa_sta_lock);
15847c478bd9Sstevel@tonic-gate 		ppa->ppa_orunts++;
15857c478bd9Sstevel@tonic-gate 		mutex_exit(&ppa->ppa_sta_lock);
15867c478bd9Sstevel@tonic-gate 	}
15877c478bd9Sstevel@tonic-gate 
15887c478bd9Sstevel@tonic-gate 	if (IS_SPS_KDEBUG(sps)) {
15897c478bd9Sstevel@tonic-gate 		SPDEBUG(PPP_DRV_NAME
15907c478bd9Sstevel@tonic-gate 		    "/%d: M_DATA send (%d bytes) sps=0x%p flags=0x%b "
15917c478bd9Sstevel@tonic-gate 		    "ppa=0x%p flags=0x%b\n", sps->sps_mn_id, msize,
15927c478bd9Sstevel@tonic-gate 		    (void *)sps, sps->sps_flags, SPS_FLAGS_STR,
15937c478bd9Sstevel@tonic-gate 		    (void *)ppa, ppa->ppa_flags, PPA_FLAGS_STR);
15947c478bd9Sstevel@tonic-gate 	}
15957c478bd9Sstevel@tonic-gate 	/*
15967c478bd9Sstevel@tonic-gate 	 * Should there be any promiscuous stream(s), send the data up
15977c478bd9Sstevel@tonic-gate 	 * for each promiscuous stream that we recognize. Make sure that
15987c478bd9Sstevel@tonic-gate 	 * for fastpath, we skip the PPP header in the M_DATA mblk. We skip
15997c478bd9Sstevel@tonic-gate 	 * the control stream as we obviously never allow the control stream
16007c478bd9Sstevel@tonic-gate 	 * to become promiscous and bind to PPP_ALLSAP.
16017c478bd9Sstevel@tonic-gate 	 */
16027c478bd9Sstevel@tonic-gate 	rw_enter(&ppa->ppa_sib_lock, RW_READER);
16037c478bd9Sstevel@tonic-gate 	is_promisc = sps->sps_ppa->ppa_promicnt;
16047c478bd9Sstevel@tonic-gate 	if (is_promisc) {
16057c478bd9Sstevel@tonic-gate 		ASSERT(ppa->ppa_streams != NULL);
16067c478bd9Sstevel@tonic-gate 		sppp_dlprsendup(ppa->ppa_streams, mp, sps->sps_sap, B_TRUE);
16077c478bd9Sstevel@tonic-gate 	}
16087c478bd9Sstevel@tonic-gate 	rw_exit(&ppa->ppa_sib_lock);
16097c478bd9Sstevel@tonic-gate 	/*
16107c478bd9Sstevel@tonic-gate 	 * Only time-stamp the packet with hrtime if the upper stream
16117c478bd9Sstevel@tonic-gate 	 * is configured to do so.  PPP control (negotiation) messages
16127c478bd9Sstevel@tonic-gate 	 * are never considered link activity; only data is activity.
16137c478bd9Sstevel@tonic-gate 	 */
16147c478bd9Sstevel@tonic-gate 	if (!IS_SPS_CONTROL(sps) && IS_PPA_TIMESTAMP(ppa)) {
16157c478bd9Sstevel@tonic-gate 		ppa->ppa_lasttx = gethrtime();
16167c478bd9Sstevel@tonic-gate 	}
16177c478bd9Sstevel@tonic-gate 	/*
16187c478bd9Sstevel@tonic-gate 	 * If there's already a message in the write-side service queue,
16197c478bd9Sstevel@tonic-gate 	 * then queue this message there as well, otherwise, try to send
16207c478bd9Sstevel@tonic-gate 	 * it down to the module immediately below us.
16217c478bd9Sstevel@tonic-gate 	 */
16227c478bd9Sstevel@tonic-gate 	if (q->q_first != NULL ||
16237c478bd9Sstevel@tonic-gate 	    (nextq = sppp_outpkt(q, mpp, msize, sps)) == NULL) {
16247c478bd9Sstevel@tonic-gate 		mp = *mpp;
16257c478bd9Sstevel@tonic-gate 		if (mp != NULL && putq(q, mp) == 0) {
16267c478bd9Sstevel@tonic-gate 			mutex_enter(&ppa->ppa_sta_lock);
16277c478bd9Sstevel@tonic-gate 			ppa->ppa_oqdropped++;
16287c478bd9Sstevel@tonic-gate 			mutex_exit(&ppa->ppa_sta_lock);
16297c478bd9Sstevel@tonic-gate 			freemsg(mp);
16307c478bd9Sstevel@tonic-gate 		}
16317c478bd9Sstevel@tonic-gate 		return (NULL);
16327c478bd9Sstevel@tonic-gate 	}
16337c478bd9Sstevel@tonic-gate 	return (nextq);
16347c478bd9Sstevel@tonic-gate }
16357c478bd9Sstevel@tonic-gate 
16367c478bd9Sstevel@tonic-gate /*
16377c478bd9Sstevel@tonic-gate  * sppp_outpkt()
16387c478bd9Sstevel@tonic-gate  *
16397c478bd9Sstevel@tonic-gate  * MT-Perimeters:
16407c478bd9Sstevel@tonic-gate  *    shared inner, shared outer (if called from sppp_wput, sppp_dlunitdatareq).
16417c478bd9Sstevel@tonic-gate  *    exclusive inner, shared outer (if called from sppp_wsrv).
16427c478bd9Sstevel@tonic-gate  *
16437c478bd9Sstevel@tonic-gate  * Description:
16447c478bd9Sstevel@tonic-gate  *    Called from 1) sppp_uwput when processing a M_DATA fastpath message,
16457c478bd9Sstevel@tonic-gate  *    or 2) sppp_uwsrv when processing the upper write-side service queue.
16467c478bd9Sstevel@tonic-gate  *    For both cases, it prepares to send the data to the module below
16477c478bd9Sstevel@tonic-gate  *    this driver if there is a lower stream linked underneath. If none, then
16487c478bd9Sstevel@tonic-gate  *    the data will be sent upstream via the control channel to pppd.
16497c478bd9Sstevel@tonic-gate  *
16507c478bd9Sstevel@tonic-gate  * Returns:
16517c478bd9Sstevel@tonic-gate  *	Non-NULL queue_t if message should be sent now, otherwise
16527c478bd9Sstevel@tonic-gate  *	if *mpp == NULL, then message was freed, otherwise put *mpp
16537c478bd9Sstevel@tonic-gate  *	(back) on the queue.  (Does not do putq/putbq, since it's
16547c478bd9Sstevel@tonic-gate  *	called both from srv and put procedures.)
16557c478bd9Sstevel@tonic-gate  */
16567c478bd9Sstevel@tonic-gate static queue_t *
sppp_outpkt(queue_t * q,mblk_t ** mpp,int msize,spppstr_t * sps)16577c478bd9Sstevel@tonic-gate sppp_outpkt(queue_t *q, mblk_t **mpp, int msize, spppstr_t *sps)
16587c478bd9Sstevel@tonic-gate {
16597c478bd9Sstevel@tonic-gate 	mblk_t		*mp;
16607c478bd9Sstevel@tonic-gate 	sppa_t		*ppa;
16617c478bd9Sstevel@tonic-gate 	enum NPmode	npmode;
16627c478bd9Sstevel@tonic-gate 	mblk_t		*mpnew;
16637c478bd9Sstevel@tonic-gate 
16647c478bd9Sstevel@tonic-gate 	ASSERT(mpp != NULL);
16657c478bd9Sstevel@tonic-gate 	mp = *mpp;
16667c478bd9Sstevel@tonic-gate 	ASSERT(q != NULL && q->q_ptr != NULL);
16677c478bd9Sstevel@tonic-gate 	ASSERT(mp != NULL && mp->b_rptr != NULL);
16687c478bd9Sstevel@tonic-gate 	ASSERT(sps != NULL);
16697c478bd9Sstevel@tonic-gate 
16707c478bd9Sstevel@tonic-gate 	ppa = sps->sps_ppa;
16717c478bd9Sstevel@tonic-gate 	npmode = sps->sps_npmode;
16727c478bd9Sstevel@tonic-gate 
16737c478bd9Sstevel@tonic-gate 	if (npmode == NPMODE_QUEUE) {
16747c478bd9Sstevel@tonic-gate 		ASSERT(!IS_SPS_CONTROL(sps));
16757c478bd9Sstevel@tonic-gate 		return (NULL);	/* queue it for later */
16767c478bd9Sstevel@tonic-gate 	} else if (ppa == NULL || ppa->ppa_ctl == NULL ||
16777c478bd9Sstevel@tonic-gate 	    npmode == NPMODE_DROP || npmode == NPMODE_ERROR) {
16787c478bd9Sstevel@tonic-gate 		/*
16797c478bd9Sstevel@tonic-gate 		 * This can not be the control stream, as it must always have
16807c478bd9Sstevel@tonic-gate 		 * a valid ppa, and its npmode must always be NPMODE_PASS.
16817c478bd9Sstevel@tonic-gate 		 */
16827c478bd9Sstevel@tonic-gate 		ASSERT(!IS_SPS_CONTROL(sps));
16837c478bd9Sstevel@tonic-gate 		if (npmode == NPMODE_DROP) {
16847c478bd9Sstevel@tonic-gate 			freemsg(mp);
16857c478bd9Sstevel@tonic-gate 		} else {
16867c478bd9Sstevel@tonic-gate 			/*
16877c478bd9Sstevel@tonic-gate 			 * If we no longer have the control stream, or if the
16887c478bd9Sstevel@tonic-gate 			 * mode is set to NPMODE_ERROR, then we need to tell IP
16897c478bd9Sstevel@tonic-gate 			 * that the interface need to be marked as down. In
16907c478bd9Sstevel@tonic-gate 			 * other words, we tell IP to be quiescent.
16917c478bd9Sstevel@tonic-gate 			 */
16927c478bd9Sstevel@tonic-gate 			merror(q, mp, EPROTO);
16937c478bd9Sstevel@tonic-gate 		}
16947c478bd9Sstevel@tonic-gate 		*mpp = NULL;
16957c478bd9Sstevel@tonic-gate 		return (NULL);	/* don't queue it */
16967c478bd9Sstevel@tonic-gate 	}
16977c478bd9Sstevel@tonic-gate 	/*
16987c478bd9Sstevel@tonic-gate 	 * Do we have a driver stream linked underneath ? If not, we need to
16997c478bd9Sstevel@tonic-gate 	 * notify pppd that the link needs to be brought up and configure
17007c478bd9Sstevel@tonic-gate 	 * this upper stream to drop subsequent outgoing packets. This is
17017c478bd9Sstevel@tonic-gate 	 * for demand-dialing, in which case pppd has done the IP plumbing
17027c478bd9Sstevel@tonic-gate 	 * but hasn't linked the driver stream underneath us. Therefore, when
17037c478bd9Sstevel@tonic-gate 	 * a packet is sent down the IP interface, a notification message
17047c478bd9Sstevel@tonic-gate 	 * will be sent up the control stream to pppd in order for it to
17057c478bd9Sstevel@tonic-gate 	 * establish the physical link. The driver stream is then expected
17067c478bd9Sstevel@tonic-gate 	 * to be linked underneath after physical link establishment is done.
17077c478bd9Sstevel@tonic-gate 	 */
17087c478bd9Sstevel@tonic-gate 	if (ppa->ppa_lower_wq == NULL) {
17097c478bd9Sstevel@tonic-gate 		ASSERT(ppa->ppa_ctl != NULL);
17107c478bd9Sstevel@tonic-gate 		ASSERT(ppa->ppa_ctl->sps_rq != NULL);
17117c478bd9Sstevel@tonic-gate 
17127c478bd9Sstevel@tonic-gate 		*mpp = NULL;
17137c478bd9Sstevel@tonic-gate 		mpnew = create_lsmsg(PPP_LINKSTAT_NEEDUP);
17147c478bd9Sstevel@tonic-gate 		if (mpnew == NULL) {
17157c478bd9Sstevel@tonic-gate 			freemsg(mp);
17167c478bd9Sstevel@tonic-gate 			mutex_enter(&ppa->ppa_sta_lock);
17177c478bd9Sstevel@tonic-gate 			ppa->ppa_allocbfail++;
17187c478bd9Sstevel@tonic-gate 			mutex_exit(&ppa->ppa_sta_lock);
17197c478bd9Sstevel@tonic-gate 			return (NULL);	/* don't queue it */
17207c478bd9Sstevel@tonic-gate 		}
17217c478bd9Sstevel@tonic-gate 		/* Include the data in the message for logging. */
17227c478bd9Sstevel@tonic-gate 		mpnew->b_cont = mp;
17237c478bd9Sstevel@tonic-gate 		mutex_enter(&ppa->ppa_sta_lock);
17247c478bd9Sstevel@tonic-gate 		ppa->ppa_lsneedup++;
17257c478bd9Sstevel@tonic-gate 		mutex_exit(&ppa->ppa_sta_lock);
17267c478bd9Sstevel@tonic-gate 		/*
17277c478bd9Sstevel@tonic-gate 		 * We need to set the mode to NPMODE_DROP, but should only
17287c478bd9Sstevel@tonic-gate 		 * do so when this stream is not the control stream.
17297c478bd9Sstevel@tonic-gate 		 */
17307c478bd9Sstevel@tonic-gate 		if (!IS_SPS_CONTROL(sps)) {
17317c478bd9Sstevel@tonic-gate 			sps->sps_npmode = NPMODE_DROP;
17327c478bd9Sstevel@tonic-gate 		}
17337c478bd9Sstevel@tonic-gate 		putnext(ppa->ppa_ctl->sps_rq, mpnew);
17347c478bd9Sstevel@tonic-gate 		return (NULL);	/* don't queue it */
17357c478bd9Sstevel@tonic-gate 	}
17367c478bd9Sstevel@tonic-gate 	/*
17377c478bd9Sstevel@tonic-gate 	 * If so, then try to send it down. The lower queue is only ever
17387c478bd9Sstevel@tonic-gate 	 * detached while holding an exclusive lock on the whole driver,
17397c478bd9Sstevel@tonic-gate 	 * so we can be confident that the lower queue is still there.
17407c478bd9Sstevel@tonic-gate 	 */
17417c478bd9Sstevel@tonic-gate 	if (bcanputnext(ppa->ppa_lower_wq, mp->b_band)) {
17427c478bd9Sstevel@tonic-gate 		mutex_enter(&ppa->ppa_sta_lock);
17437c478bd9Sstevel@tonic-gate 		ppa->ppa_stats.p.ppp_opackets++;
17447c478bd9Sstevel@tonic-gate 		if (IS_SPS_CONTROL(sps)) {
17457c478bd9Sstevel@tonic-gate 			ppa->ppa_opkt_ctl++;
17467c478bd9Sstevel@tonic-gate 		}
17477c478bd9Sstevel@tonic-gate 		ppa->ppa_stats.p.ppp_obytes += msize;
17487c478bd9Sstevel@tonic-gate 		mutex_exit(&ppa->ppa_sta_lock);
17497c478bd9Sstevel@tonic-gate 		return (ppa->ppa_lower_wq);	/* don't queue it */
17507c478bd9Sstevel@tonic-gate 	}
17517c478bd9Sstevel@tonic-gate 	return (NULL);	/* queue it for later */
17527c478bd9Sstevel@tonic-gate }
17537c478bd9Sstevel@tonic-gate 
17547c478bd9Sstevel@tonic-gate /*
17557c478bd9Sstevel@tonic-gate  * sppp_lwsrv()
17567c478bd9Sstevel@tonic-gate  *
17577c478bd9Sstevel@tonic-gate  * MT-Perimeters:
17587c478bd9Sstevel@tonic-gate  *    exclusive inner, shared outer.
17597c478bd9Sstevel@tonic-gate  *
17607c478bd9Sstevel@tonic-gate  * Description:
17617c478bd9Sstevel@tonic-gate  *    Lower write-side service procedure. No messages are ever placed on
17627c478bd9Sstevel@tonic-gate  *    the write queue here, this just back-enables all upper write side
17637c478bd9Sstevel@tonic-gate  *    service procedures.
17647c478bd9Sstevel@tonic-gate  */
17652bcc9601SToomas Soome int
sppp_lwsrv(queue_t * q)17667c478bd9Sstevel@tonic-gate sppp_lwsrv(queue_t *q)
17677c478bd9Sstevel@tonic-gate {
17687c478bd9Sstevel@tonic-gate 	sppa_t		*ppa;
17697c478bd9Sstevel@tonic-gate 	spppstr_t	*nextsib;
17707c478bd9Sstevel@tonic-gate 
17717c478bd9Sstevel@tonic-gate 	ASSERT(q != NULL && q->q_ptr != NULL);
17727c478bd9Sstevel@tonic-gate 	ppa = (sppa_t *)q->q_ptr;
17737c478bd9Sstevel@tonic-gate 	ASSERT(ppa != NULL);
17747c478bd9Sstevel@tonic-gate 
17757c478bd9Sstevel@tonic-gate 	rw_enter(&ppa->ppa_sib_lock, RW_READER);
17767c478bd9Sstevel@tonic-gate 	if ((nextsib = ppa->ppa_ctl) != NULL &&
17777c478bd9Sstevel@tonic-gate 	    WR(nextsib->sps_rq)->q_first != NULL)
17787c478bd9Sstevel@tonic-gate 		qenable(WR(nextsib->sps_rq));
17797c478bd9Sstevel@tonic-gate 	for (nextsib = ppa->ppa_streams; nextsib != NULL;
17807c478bd9Sstevel@tonic-gate 	    nextsib = nextsib->sps_nextsib) {
17817c478bd9Sstevel@tonic-gate 		if (WR(nextsib->sps_rq)->q_first != NULL) {
17827c478bd9Sstevel@tonic-gate 			qenable(WR(nextsib->sps_rq));
17837c478bd9Sstevel@tonic-gate 		}
17847c478bd9Sstevel@tonic-gate 	}
17857c478bd9Sstevel@tonic-gate 	rw_exit(&ppa->ppa_sib_lock);
17862bcc9601SToomas Soome 	return (0);
17877c478bd9Sstevel@tonic-gate }
17887c478bd9Sstevel@tonic-gate 
17897c478bd9Sstevel@tonic-gate /*
17907c478bd9Sstevel@tonic-gate  * sppp_lrput()
17917c478bd9Sstevel@tonic-gate  *
17927c478bd9Sstevel@tonic-gate  * MT-Perimeters:
17937c478bd9Sstevel@tonic-gate  *    shared inner, shared outer.
17947c478bd9Sstevel@tonic-gate  *
17957c478bd9Sstevel@tonic-gate  * Description:
17967c478bd9Sstevel@tonic-gate  *    Lower read-side put procedure. Messages from below get here.
17977c478bd9Sstevel@tonic-gate  *    Data messages are handled separately to limit stack usage
17987c478bd9Sstevel@tonic-gate  *    going into IP.
1799002c70ffScarlsonj  *
1800002c70ffScarlsonj  *    Note that during I_UNLINK processing, it's possible for a downstream
1801002c70ffScarlsonj  *    message to enable upstream data (due to pass_wput() removing the
1802002c70ffScarlsonj  *    SQ_BLOCKED flag), and thus we must protect against a NULL sppa pointer.
1803002c70ffScarlsonj  *    In this case, the only thing above us is passthru, and we might as well
1804002c70ffScarlsonj  *    discard.
18057c478bd9Sstevel@tonic-gate  */
18062bcc9601SToomas Soome int
sppp_lrput(queue_t * q,mblk_t * mp)18077c478bd9Sstevel@tonic-gate sppp_lrput(queue_t *q, mblk_t *mp)
18087c478bd9Sstevel@tonic-gate {
18097c478bd9Sstevel@tonic-gate 	sppa_t		*ppa;
18107c478bd9Sstevel@tonic-gate 	spppstr_t	*sps;
18117c478bd9Sstevel@tonic-gate 
1812002c70ffScarlsonj 	if ((ppa = q->q_ptr) == NULL) {
1813002c70ffScarlsonj 		freemsg(mp);
18142bcc9601SToomas Soome 		return (0);
1815002c70ffScarlsonj 	}
1816002c70ffScarlsonj 
18177c478bd9Sstevel@tonic-gate 	sps = ppa->ppa_ctl;
18187c478bd9Sstevel@tonic-gate 
18197c478bd9Sstevel@tonic-gate 	if (MTYPE(mp) != M_DATA) {
18207c478bd9Sstevel@tonic-gate 		sppp_recv_nondata(q, mp, sps);
18217c478bd9Sstevel@tonic-gate 	} else if (sps == NULL) {
18227c478bd9Sstevel@tonic-gate 		freemsg(mp);
18237c478bd9Sstevel@tonic-gate 	} else if ((q = sppp_recv(q, &mp, sps)) != NULL) {
18247c478bd9Sstevel@tonic-gate 		putnext(q, mp);
18257c478bd9Sstevel@tonic-gate 	}
18262bcc9601SToomas Soome 	return (0);
18277c478bd9Sstevel@tonic-gate }
18287c478bd9Sstevel@tonic-gate 
1829f53eecf5SJames Carlson /*
1830f53eecf5SJames Carlson  * sppp_lrsrv()
1831f53eecf5SJames Carlson  *
1832f53eecf5SJames Carlson  * MT-Perimeters:
1833f53eecf5SJames Carlson  *    exclusive inner, shared outer.
1834f53eecf5SJames Carlson  *
1835f53eecf5SJames Carlson  * Description:
1836f53eecf5SJames Carlson  *    Lower read-side service procedure.  This is run once after the I_LINK
1837f53eecf5SJames Carlson  *    occurs in order to clean up any packets that came in while we were
1838f53eecf5SJames Carlson  *    transferring in the lower stream.  Otherwise, it's not used.
1839f53eecf5SJames Carlson  */
18402bcc9601SToomas Soome int
sppp_lrsrv(queue_t * q)1841f53eecf5SJames Carlson sppp_lrsrv(queue_t *q)
1842f53eecf5SJames Carlson {
1843f53eecf5SJames Carlson 	mblk_t *mp;
1844f53eecf5SJames Carlson 
1845f53eecf5SJames Carlson 	while ((mp = getq(q)) != NULL)
1846*78a53e20SJohn Levon 		(void) sppp_lrput(q, mp);
18472bcc9601SToomas Soome 	return (0);
1848f53eecf5SJames Carlson }
1849f53eecf5SJames Carlson 
18507c478bd9Sstevel@tonic-gate /*
18517c478bd9Sstevel@tonic-gate  * sppp_recv_nondata()
18527c478bd9Sstevel@tonic-gate  *
18537c478bd9Sstevel@tonic-gate  * MT-Perimeters:
18547c478bd9Sstevel@tonic-gate  *    shared inner, shared outer.
18557c478bd9Sstevel@tonic-gate  *
18567c478bd9Sstevel@tonic-gate  * Description:
18577c478bd9Sstevel@tonic-gate  *    All received non-data messages come through here.
18587c478bd9Sstevel@tonic-gate  */
18597c478bd9Sstevel@tonic-gate static void
sppp_recv_nondata(queue_t * q,mblk_t * mp,spppstr_t * ctlsps)18607c478bd9Sstevel@tonic-gate sppp_recv_nondata(queue_t *q, mblk_t *mp, spppstr_t *ctlsps)
18617c478bd9Sstevel@tonic-gate {
18627c478bd9Sstevel@tonic-gate 	sppa_t		*ppa;
18637c478bd9Sstevel@tonic-gate 	spppstr_t	*destsps;
18647c478bd9Sstevel@tonic-gate 	struct iocblk	*iop;
18657c478bd9Sstevel@tonic-gate 
18667c478bd9Sstevel@tonic-gate 	ppa = (sppa_t *)q->q_ptr;
18677c478bd9Sstevel@tonic-gate 	ctlsps = ppa->ppa_ctl;
18687c478bd9Sstevel@tonic-gate 
18697c478bd9Sstevel@tonic-gate 	switch (MTYPE(mp)) {
18707c478bd9Sstevel@tonic-gate 	case M_CTL:
18717c478bd9Sstevel@tonic-gate 		mutex_enter(&ppa->ppa_sta_lock);
18727c478bd9Sstevel@tonic-gate 		if (*mp->b_rptr == PPPCTL_IERROR) {
18737c478bd9Sstevel@tonic-gate 			ppa->ppa_stats.p.ppp_ierrors++;
18747c478bd9Sstevel@tonic-gate 			ppa->ppa_ierr_low++;
18757c478bd9Sstevel@tonic-gate 			ppa->ppa_mctlsknown++;
18767c478bd9Sstevel@tonic-gate 		} else if (*mp->b_rptr == PPPCTL_OERROR) {
18777c478bd9Sstevel@tonic-gate 			ppa->ppa_stats.p.ppp_oerrors++;
18787c478bd9Sstevel@tonic-gate 			ppa->ppa_oerr_low++;
18797c478bd9Sstevel@tonic-gate 			ppa->ppa_mctlsknown++;
18807c478bd9Sstevel@tonic-gate 		} else {
18817c478bd9Sstevel@tonic-gate 			ppa->ppa_mctlsunknown++;
18827c478bd9Sstevel@tonic-gate 		}
18837c478bd9Sstevel@tonic-gate 		mutex_exit(&ppa->ppa_sta_lock);
18847c478bd9Sstevel@tonic-gate 		freemsg(mp);
18857c478bd9Sstevel@tonic-gate 		break;
18867c478bd9Sstevel@tonic-gate 	case M_IOCTL:
18877c478bd9Sstevel@tonic-gate 		miocnak(q, mp, 0, EINVAL);
18887c478bd9Sstevel@tonic-gate 		break;
18897c478bd9Sstevel@tonic-gate 	case M_IOCACK:
18907c478bd9Sstevel@tonic-gate 	case M_IOCNAK:
18917c478bd9Sstevel@tonic-gate 		iop = (struct iocblk *)mp->b_rptr;
18927c478bd9Sstevel@tonic-gate 		ASSERT(iop != NULL);
18937c478bd9Sstevel@tonic-gate 		/*
18947c478bd9Sstevel@tonic-gate 		 * Attempt to match up the response with the stream that the
18957c478bd9Sstevel@tonic-gate 		 * request came from. If ioc_id doesn't match the one that we
18967c478bd9Sstevel@tonic-gate 		 * recorded, then discard this message.
18977c478bd9Sstevel@tonic-gate 		 */
18987c478bd9Sstevel@tonic-gate 		rw_enter(&ppa->ppa_sib_lock, RW_READER);
18997c478bd9Sstevel@tonic-gate 		if ((destsps = ctlsps) == NULL ||
19007c478bd9Sstevel@tonic-gate 		    destsps->sps_ioc_id != iop->ioc_id) {
19017c478bd9Sstevel@tonic-gate 			destsps = ppa->ppa_streams;
19027c478bd9Sstevel@tonic-gate 			while (destsps != NULL) {
19037c478bd9Sstevel@tonic-gate 				if (destsps->sps_ioc_id == iop->ioc_id) {
19047c478bd9Sstevel@tonic-gate 					break;	/* found the upper stream */
19057c478bd9Sstevel@tonic-gate 				}
19067c478bd9Sstevel@tonic-gate 				destsps = destsps->sps_nextsib;
19077c478bd9Sstevel@tonic-gate 			}
19087c478bd9Sstevel@tonic-gate 		}
19097c478bd9Sstevel@tonic-gate 		rw_exit(&ppa->ppa_sib_lock);
19107c478bd9Sstevel@tonic-gate 		if (destsps == NULL) {
19117c478bd9Sstevel@tonic-gate 			mutex_enter(&ppa->ppa_sta_lock);
19127c478bd9Sstevel@tonic-gate 			ppa->ppa_ioctlsfwderr++;
19137c478bd9Sstevel@tonic-gate 			mutex_exit(&ppa->ppa_sta_lock);
19147c478bd9Sstevel@tonic-gate 			freemsg(mp);
19157c478bd9Sstevel@tonic-gate 			break;
19167c478bd9Sstevel@tonic-gate 		}
19177c478bd9Sstevel@tonic-gate 		mutex_enter(&ppa->ppa_sta_lock);
19187c478bd9Sstevel@tonic-gate 		ppa->ppa_ioctlsfwdok++;
19199f7c4232SAnil udupa 
19209f7c4232SAnil udupa 		/*
19219f7c4232SAnil udupa 		 * Clear SPS_IOCQ and enable the lower write side queue,
19229f7c4232SAnil udupa 		 * this would allow the upper stream service routine
19239f7c4232SAnil udupa 		 * to start processing the queue for pending messages.
19249f7c4232SAnil udupa 		 * sppp_lwsrv -> sppp_uwsrv.
19259f7c4232SAnil udupa 		 */
19269f7c4232SAnil udupa 		destsps->sps_flags &= ~SPS_IOCQ;
19277c478bd9Sstevel@tonic-gate 		mutex_exit(&ppa->ppa_sta_lock);
19289f7c4232SAnil udupa 		qenable(WR(destsps->sps_rq));
19299f7c4232SAnil udupa 
19307c478bd9Sstevel@tonic-gate 		putnext(destsps->sps_rq, mp);
19317c478bd9Sstevel@tonic-gate 		break;
19327c478bd9Sstevel@tonic-gate 	case M_HANGUP:
19337c478bd9Sstevel@tonic-gate 		/*
19347c478bd9Sstevel@tonic-gate 		 * Free the original mblk_t. We don't really want to send
19357c478bd9Sstevel@tonic-gate 		 * a M_HANGUP message upstream, so we need to translate this
19367c478bd9Sstevel@tonic-gate 		 * message into something else.
19377c478bd9Sstevel@tonic-gate 		 */
19387c478bd9Sstevel@tonic-gate 		freemsg(mp);
19397c478bd9Sstevel@tonic-gate 		if (ctlsps == NULL)
19407c478bd9Sstevel@tonic-gate 			break;
19417c478bd9Sstevel@tonic-gate 		mp = create_lsmsg(PPP_LINKSTAT_HANGUP);
19427c478bd9Sstevel@tonic-gate 		if (mp == NULL) {
19437c478bd9Sstevel@tonic-gate 			mutex_enter(&ppa->ppa_sta_lock);
19447c478bd9Sstevel@tonic-gate 			ppa->ppa_allocbfail++;
19457c478bd9Sstevel@tonic-gate 			mutex_exit(&ppa->ppa_sta_lock);
19467c478bd9Sstevel@tonic-gate 			break;
19477c478bd9Sstevel@tonic-gate 		}
19487c478bd9Sstevel@tonic-gate 		mutex_enter(&ppa->ppa_sta_lock);
19497c478bd9Sstevel@tonic-gate 		ppa->ppa_lsdown++;
19507c478bd9Sstevel@tonic-gate 		mutex_exit(&ppa->ppa_sta_lock);
19517c478bd9Sstevel@tonic-gate 		putnext(ctlsps->sps_rq, mp);
19527c478bd9Sstevel@tonic-gate 		break;
19537c478bd9Sstevel@tonic-gate 	case M_FLUSH:
19547c478bd9Sstevel@tonic-gate 		if (*mp->b_rptr & FLUSHR) {
19557c478bd9Sstevel@tonic-gate 			flushq(q, FLUSHDATA);
19567c478bd9Sstevel@tonic-gate 		}
19577c478bd9Sstevel@tonic-gate 		if (*mp->b_rptr & FLUSHW) {
19587c478bd9Sstevel@tonic-gate 			*mp->b_rptr &= ~FLUSHR;
19597c478bd9Sstevel@tonic-gate 			qreply(q, mp);
19607c478bd9Sstevel@tonic-gate 		} else {
19617c478bd9Sstevel@tonic-gate 			freemsg(mp);
19627c478bd9Sstevel@tonic-gate 		}
19637c478bd9Sstevel@tonic-gate 		break;
19647c478bd9Sstevel@tonic-gate 	default:
19657c478bd9Sstevel@tonic-gate 		if (ctlsps != NULL &&
19667c478bd9Sstevel@tonic-gate 		    (queclass(mp) == QPCTL) || canputnext(ctlsps->sps_rq)) {
19677c478bd9Sstevel@tonic-gate 			putnext(ctlsps->sps_rq, mp);
19687c478bd9Sstevel@tonic-gate 		} else {
19697c478bd9Sstevel@tonic-gate 			mutex_enter(&ppa->ppa_sta_lock);
19707c478bd9Sstevel@tonic-gate 			ppa->ppa_iqdropped++;
19717c478bd9Sstevel@tonic-gate 			mutex_exit(&ppa->ppa_sta_lock);
19727c478bd9Sstevel@tonic-gate 			freemsg(mp);
19737c478bd9Sstevel@tonic-gate 		}
19747c478bd9Sstevel@tonic-gate 		break;
19757c478bd9Sstevel@tonic-gate 	}
19767c478bd9Sstevel@tonic-gate }
19777c478bd9Sstevel@tonic-gate 
19787c478bd9Sstevel@tonic-gate /*
19797c478bd9Sstevel@tonic-gate  * sppp_recv()
19807c478bd9Sstevel@tonic-gate  *
19817c478bd9Sstevel@tonic-gate  * MT-Perimeters:
19827c478bd9Sstevel@tonic-gate  *    shared inner, shared outer.
19837c478bd9Sstevel@tonic-gate  *
19847c478bd9Sstevel@tonic-gate  * Description:
19857c478bd9Sstevel@tonic-gate  *    Receive function called by sppp_lrput.  Finds appropriate
19867c478bd9Sstevel@tonic-gate  *    receive stream and does accounting.
19877c478bd9Sstevel@tonic-gate  */
19887c478bd9Sstevel@tonic-gate static queue_t *
sppp_recv(queue_t * q,mblk_t ** mpp,spppstr_t * ctlsps)19897c478bd9Sstevel@tonic-gate sppp_recv(queue_t *q, mblk_t **mpp, spppstr_t *ctlsps)
19907c478bd9Sstevel@tonic-gate {
19917c478bd9Sstevel@tonic-gate 	mblk_t		*mp;
19927c478bd9Sstevel@tonic-gate 	int		len;
19937c478bd9Sstevel@tonic-gate 	sppa_t		*ppa;
19947c478bd9Sstevel@tonic-gate 	spppstr_t	*destsps;
19957c478bd9Sstevel@tonic-gate 	mblk_t		*zmp;
19967c478bd9Sstevel@tonic-gate 	uint32_t	npflagpos;
19977c478bd9Sstevel@tonic-gate 
19987c478bd9Sstevel@tonic-gate 	ASSERT(mpp != NULL);
19997c478bd9Sstevel@tonic-gate 	mp = *mpp;
20007c478bd9Sstevel@tonic-gate 	ASSERT(q != NULL && q->q_ptr != NULL);
20017c478bd9Sstevel@tonic-gate 	ASSERT(mp != NULL && mp->b_rptr != NULL);
20027c478bd9Sstevel@tonic-gate 	ASSERT(ctlsps != NULL);
20037c478bd9Sstevel@tonic-gate 	ASSERT(IS_SPS_CONTROL(ctlsps));
20047c478bd9Sstevel@tonic-gate 	ppa = ctlsps->sps_ppa;
20057c478bd9Sstevel@tonic-gate 	ASSERT(ppa != NULL && ppa->ppa_ctl != NULL);
20067c478bd9Sstevel@tonic-gate 
20077c478bd9Sstevel@tonic-gate 	len = msgdsize(mp);
20087c478bd9Sstevel@tonic-gate 	mutex_enter(&ppa->ppa_sta_lock);
20097c478bd9Sstevel@tonic-gate 	ppa->ppa_stats.p.ppp_ibytes += len;
20107c478bd9Sstevel@tonic-gate 	mutex_exit(&ppa->ppa_sta_lock);
20117c478bd9Sstevel@tonic-gate 	/*
20127c478bd9Sstevel@tonic-gate 	 * If the entire data size of the mblk is less than the length of the
20137c478bd9Sstevel@tonic-gate 	 * PPP header, then free it. We can't do much with such message anyway,
20147c478bd9Sstevel@tonic-gate 	 * since we can't really determine what the PPP protocol type is.
20157c478bd9Sstevel@tonic-gate 	 */
20167c478bd9Sstevel@tonic-gate 	if (len < PPP_HDRLEN) {
20177c478bd9Sstevel@tonic-gate 		/* Log, and free it */
20187c478bd9Sstevel@tonic-gate 		mutex_enter(&ppa->ppa_sta_lock);
20197c478bd9Sstevel@tonic-gate 		ppa->ppa_irunts++;
20207c478bd9Sstevel@tonic-gate 		mutex_exit(&ppa->ppa_sta_lock);
20217c478bd9Sstevel@tonic-gate 		freemsg(mp);
20227c478bd9Sstevel@tonic-gate 		return (NULL);
20237c478bd9Sstevel@tonic-gate 	} else if (len > (ppa->ppa_mru + PPP_HDRLEN)) {
20247c478bd9Sstevel@tonic-gate 		/* Log, and accept it anyway */
20257c478bd9Sstevel@tonic-gate 		mutex_enter(&ppa->ppa_sta_lock);
20267c478bd9Sstevel@tonic-gate 		ppa->ppa_itoolongs++;
20277c478bd9Sstevel@tonic-gate 		mutex_exit(&ppa->ppa_sta_lock);
20287c478bd9Sstevel@tonic-gate 	}
20297c478bd9Sstevel@tonic-gate 	/*
20307c478bd9Sstevel@tonic-gate 	 * We need at least be able to read the PPP protocol from the header,
20317c478bd9Sstevel@tonic-gate 	 * so if the first message block is too small, then we concatenate the
20327c478bd9Sstevel@tonic-gate 	 * rest of the following blocks into one message.
20337c478bd9Sstevel@tonic-gate 	 */
20347c478bd9Sstevel@tonic-gate 	if (MBLKL(mp) < PPP_HDRLEN) {
20357c478bd9Sstevel@tonic-gate 		zmp = msgpullup(mp, PPP_HDRLEN);
20367c478bd9Sstevel@tonic-gate 		freemsg(mp);
20377c478bd9Sstevel@tonic-gate 		mp = zmp;
20387c478bd9Sstevel@tonic-gate 		if (mp == NULL) {
20397c478bd9Sstevel@tonic-gate 			mutex_enter(&ppa->ppa_sta_lock);
20407c478bd9Sstevel@tonic-gate 			ppa->ppa_allocbfail++;
20417c478bd9Sstevel@tonic-gate 			mutex_exit(&ppa->ppa_sta_lock);
20427c478bd9Sstevel@tonic-gate 			return (NULL);
20437c478bd9Sstevel@tonic-gate 		}
20447c478bd9Sstevel@tonic-gate 		*mpp = mp;
20457c478bd9Sstevel@tonic-gate 	}
20467c478bd9Sstevel@tonic-gate 	/*
20477c478bd9Sstevel@tonic-gate 	 * Hold this packet in the control-queue until
20487c478bd9Sstevel@tonic-gate 	 * the matching network-layer upper stream for the PPP protocol (sap)
20497c478bd9Sstevel@tonic-gate 	 * has not been plumbed and configured
20507c478bd9Sstevel@tonic-gate 	 */
20517c478bd9Sstevel@tonic-gate 	npflagpos = sppp_ppp2np(PPP_PROTOCOL(mp->b_rptr));
20527c478bd9Sstevel@tonic-gate 	mutex_enter(&ppa->ppa_npmutex);
20537c478bd9Sstevel@tonic-gate 	if (npflagpos != 0 && (ppa->ppa_npflag & (1 << npflagpos))) {
20547c478bd9Sstevel@tonic-gate 		/*
20557c478bd9Sstevel@tonic-gate 		 * proto is currently blocked; Hold up to 4 packets
20567c478bd9Sstevel@tonic-gate 		 * in the kernel.
20577c478bd9Sstevel@tonic-gate 		 */
20587c478bd9Sstevel@tonic-gate 		if (ppa->ppa_holdpkts[npflagpos] > 3 ||
20597c478bd9Sstevel@tonic-gate 		    putq(ctlsps->sps_rq, mp) == 0)
20607c478bd9Sstevel@tonic-gate 			freemsg(mp);
20617c478bd9Sstevel@tonic-gate 		else
20627c478bd9Sstevel@tonic-gate 			ppa->ppa_holdpkts[npflagpos]++;
20637c478bd9Sstevel@tonic-gate 		mutex_exit(&ppa->ppa_npmutex);
20647c478bd9Sstevel@tonic-gate 		return (NULL);
20657c478bd9Sstevel@tonic-gate 	}
20667c478bd9Sstevel@tonic-gate 	mutex_exit(&ppa->ppa_npmutex);
20677c478bd9Sstevel@tonic-gate 	/*
20687c478bd9Sstevel@tonic-gate 	 * Try to find a matching network-layer upper stream for the specified
20697c478bd9Sstevel@tonic-gate 	 * PPP protocol (sap), and if none is found, send this frame up the
20707c478bd9Sstevel@tonic-gate 	 * control stream.
20717c478bd9Sstevel@tonic-gate 	 */
20727c478bd9Sstevel@tonic-gate 	destsps = sppp_inpkt(q, mp, ctlsps);
20737c478bd9Sstevel@tonic-gate 	if (destsps == NULL) {
20747c478bd9Sstevel@tonic-gate 		mutex_enter(&ppa->ppa_sta_lock);
20757c478bd9Sstevel@tonic-gate 		ppa->ppa_ipkt_ctl++;
20767c478bd9Sstevel@tonic-gate 		mutex_exit(&ppa->ppa_sta_lock);
20777c478bd9Sstevel@tonic-gate 		if (canputnext(ctlsps->sps_rq)) {
20787c478bd9Sstevel@tonic-gate 			if (IS_SPS_KDEBUG(ctlsps)) {
20797c478bd9Sstevel@tonic-gate 				SPDEBUG(PPP_DRV_NAME
20807c478bd9Sstevel@tonic-gate 				    "/%d: M_DATA recv (%d bytes) sps=0x%p "
20817c478bd9Sstevel@tonic-gate 				    "flags=0x%b ppa=0x%p flags=0x%b\n",
20827c478bd9Sstevel@tonic-gate 				    ctlsps->sps_mn_id, len, (void *)ctlsps,
20837c478bd9Sstevel@tonic-gate 				    ctlsps->sps_flags, SPS_FLAGS_STR,
20847c478bd9Sstevel@tonic-gate 				    (void *)ppa, ppa->ppa_flags,
20857c478bd9Sstevel@tonic-gate 				    PPA_FLAGS_STR);
20867c478bd9Sstevel@tonic-gate 			}
20877c478bd9Sstevel@tonic-gate 			return (ctlsps->sps_rq);
20887c478bd9Sstevel@tonic-gate 		} else {
20897c478bd9Sstevel@tonic-gate 			mutex_enter(&ppa->ppa_sta_lock);
20907c478bd9Sstevel@tonic-gate 			ppa->ppa_iqdropped++;
20917c478bd9Sstevel@tonic-gate 			mutex_exit(&ppa->ppa_sta_lock);
20927c478bd9Sstevel@tonic-gate 			freemsg(mp);
20937c478bd9Sstevel@tonic-gate 			return (NULL);
20947c478bd9Sstevel@tonic-gate 		}
20957c478bd9Sstevel@tonic-gate 	}
20967c478bd9Sstevel@tonic-gate 	if (canputnext(destsps->sps_rq)) {
20977c478bd9Sstevel@tonic-gate 		if (IS_SPS_KDEBUG(destsps)) {
20987c478bd9Sstevel@tonic-gate 			SPDEBUG(PPP_DRV_NAME
20997c478bd9Sstevel@tonic-gate 			    "/%d: M_DATA recv (%d bytes) sps=0x%p flags=0x%b "
21007c478bd9Sstevel@tonic-gate 			    "ppa=0x%p flags=0x%b\n", destsps->sps_mn_id, len,
21017c478bd9Sstevel@tonic-gate 			    (void *)destsps, destsps->sps_flags,
21027c478bd9Sstevel@tonic-gate 			    SPS_FLAGS_STR, (void *)ppa, ppa->ppa_flags,
21037c478bd9Sstevel@tonic-gate 			    PPA_FLAGS_STR);
21047c478bd9Sstevel@tonic-gate 		}
21057c478bd9Sstevel@tonic-gate 		/*
21067c478bd9Sstevel@tonic-gate 		 * If fastpath is enabled on the network-layer stream, then
21077c478bd9Sstevel@tonic-gate 		 * make sure we skip over the PPP header, otherwise, we wrap
21087c478bd9Sstevel@tonic-gate 		 * the message in a DLPI message.
21097c478bd9Sstevel@tonic-gate 		 */
21107c478bd9Sstevel@tonic-gate 		if (IS_SPS_FASTPATH(destsps)) {
21117c478bd9Sstevel@tonic-gate 			mp->b_rptr += PPP_HDRLEN;
21127c478bd9Sstevel@tonic-gate 			return (destsps->sps_rq);
21137c478bd9Sstevel@tonic-gate 		} else {
21147c478bd9Sstevel@tonic-gate 			spppstr_t *uqs = (spppstr_t *)destsps->sps_rq->q_ptr;
21157c478bd9Sstevel@tonic-gate 			ASSERT(uqs != NULL);
21167c478bd9Sstevel@tonic-gate 			mp->b_rptr += PPP_HDRLEN;
21177c478bd9Sstevel@tonic-gate 			mp = sppp_dladdud(uqs, mp, uqs->sps_sap, B_FALSE);
21187c478bd9Sstevel@tonic-gate 			if (mp != NULL) {
21197c478bd9Sstevel@tonic-gate 				*mpp = mp;
21207c478bd9Sstevel@tonic-gate 				return (destsps->sps_rq);
21217c478bd9Sstevel@tonic-gate 			} else {
21227c478bd9Sstevel@tonic-gate 				mutex_enter(&ppa->ppa_sta_lock);
21237c478bd9Sstevel@tonic-gate 				ppa->ppa_allocbfail++;
21247c478bd9Sstevel@tonic-gate 				mutex_exit(&ppa->ppa_sta_lock);
21257c478bd9Sstevel@tonic-gate 				/* mp already freed by sppp_dladdud */
21267c478bd9Sstevel@tonic-gate 				return (NULL);
21277c478bd9Sstevel@tonic-gate 			}
21287c478bd9Sstevel@tonic-gate 		}
21297c478bd9Sstevel@tonic-gate 	} else {
21307c478bd9Sstevel@tonic-gate 		mutex_enter(&ppa->ppa_sta_lock);
21317c478bd9Sstevel@tonic-gate 		ppa->ppa_iqdropped++;
21327c478bd9Sstevel@tonic-gate 		mutex_exit(&ppa->ppa_sta_lock);
21337c478bd9Sstevel@tonic-gate 		freemsg(mp);
21347c478bd9Sstevel@tonic-gate 		return (NULL);
21357c478bd9Sstevel@tonic-gate 	}
21367c478bd9Sstevel@tonic-gate }
21377c478bd9Sstevel@tonic-gate 
21387c478bd9Sstevel@tonic-gate /*
21397c478bd9Sstevel@tonic-gate  * sppp_inpkt()
21407c478bd9Sstevel@tonic-gate  *
21417c478bd9Sstevel@tonic-gate  * MT-Perimeters:
21427c478bd9Sstevel@tonic-gate  *    shared inner, shared outer.
21437c478bd9Sstevel@tonic-gate  *
21447c478bd9Sstevel@tonic-gate  * Description:
21457c478bd9Sstevel@tonic-gate  *    Find the destination upper stream for the received packet, called
21467c478bd9Sstevel@tonic-gate  *    from sppp_recv.
21477c478bd9Sstevel@tonic-gate  *
21487c478bd9Sstevel@tonic-gate  * Returns:
21497c478bd9Sstevel@tonic-gate  *    ptr to destination upper network stream, or NULL for control stream.
21507c478bd9Sstevel@tonic-gate  */
21517c478bd9Sstevel@tonic-gate /* ARGSUSED */
21527c478bd9Sstevel@tonic-gate static spppstr_t *
sppp_inpkt(queue_t * q,mblk_t * mp,spppstr_t * ctlsps)21537c478bd9Sstevel@tonic-gate sppp_inpkt(queue_t *q, mblk_t *mp, spppstr_t *ctlsps)
21547c478bd9Sstevel@tonic-gate {
21557c478bd9Sstevel@tonic-gate 	spppstr_t	*destsps = NULL;
21567c478bd9Sstevel@tonic-gate 	sppa_t		*ppa;
21577c478bd9Sstevel@tonic-gate 	uint16_t	proto;
21587c478bd9Sstevel@tonic-gate 	int		is_promisc;
21597c478bd9Sstevel@tonic-gate 
21607c478bd9Sstevel@tonic-gate 	ASSERT(q != NULL && q->q_ptr != NULL);
21617c478bd9Sstevel@tonic-gate 	ASSERT(mp != NULL && mp->b_rptr != NULL);
21627c478bd9Sstevel@tonic-gate 	ASSERT(IS_SPS_CONTROL(ctlsps));
21637c478bd9Sstevel@tonic-gate 	ppa = ctlsps->sps_ppa;
21647c478bd9Sstevel@tonic-gate 	ASSERT(ppa != NULL);
21657c478bd9Sstevel@tonic-gate 	/*
21667c478bd9Sstevel@tonic-gate 	 * From RFC 1661 (Section 2):
21677c478bd9Sstevel@tonic-gate 	 *
21687c478bd9Sstevel@tonic-gate 	 * The Protocol field is one or two octets, and its value identifies
21697c478bd9Sstevel@tonic-gate 	 * the datagram encapsulated in the Information field of the packet.
21707c478bd9Sstevel@tonic-gate 	 * The field is transmitted and received most significant octet first.
21717c478bd9Sstevel@tonic-gate 	 *
21727c478bd9Sstevel@tonic-gate 	 * The structure of this field is consistent with the ISO 3309
21737c478bd9Sstevel@tonic-gate 	 * extension mechanism for address fields.  All Protocols MUST be odd;
21747c478bd9Sstevel@tonic-gate 	 * the least significant bit of the least significant octet MUST equal
21757c478bd9Sstevel@tonic-gate 	 * "1".  Also, all Protocols MUST be assigned such that the least
21767c478bd9Sstevel@tonic-gate 	 * significant bit of the most significant octet equals "0". Frames
21777c478bd9Sstevel@tonic-gate 	 * received which don't comply with these rules MUST be treated as
21787c478bd9Sstevel@tonic-gate 	 * having an unrecognized Protocol.
21797c478bd9Sstevel@tonic-gate 	 *
21807c478bd9Sstevel@tonic-gate 	 * Protocol field values in the "0***" to "3***" range identify the
21817c478bd9Sstevel@tonic-gate 	 * network-layer protocol of specific packets, and values in the
21827c478bd9Sstevel@tonic-gate 	 * "8***" to "b***" range identify packets belonging to the associated
21837c478bd9Sstevel@tonic-gate 	 * Network Control Protocols (NCPs), if any.
21847c478bd9Sstevel@tonic-gate 	 *
21857c478bd9Sstevel@tonic-gate 	 * Protocol field values in the "4***" to "7***" range are used for
21867c478bd9Sstevel@tonic-gate 	 * protocols with low volume traffic which have no associated NCP.
21877c478bd9Sstevel@tonic-gate 	 * Protocol field values in the "c***" to "f***" range identify packets
21887c478bd9Sstevel@tonic-gate 	 * as link-layer Control Protocols (such as LCP).
21897c478bd9Sstevel@tonic-gate 	 */
21907c478bd9Sstevel@tonic-gate 	proto = PPP_PROTOCOL(mp->b_rptr);
21917c478bd9Sstevel@tonic-gate 	mutex_enter(&ppa->ppa_sta_lock);
21927c478bd9Sstevel@tonic-gate 	ppa->ppa_stats.p.ppp_ipackets++;
21937c478bd9Sstevel@tonic-gate 	mutex_exit(&ppa->ppa_sta_lock);
21947c478bd9Sstevel@tonic-gate 	/*
21957c478bd9Sstevel@tonic-gate 	 * We check if this is not a network-layer protocol, and if so,
21967c478bd9Sstevel@tonic-gate 	 * then send this packet up the control stream.
21977c478bd9Sstevel@tonic-gate 	 */
21987c478bd9Sstevel@tonic-gate 	if (proto > 0x7fff) {
21997c478bd9Sstevel@tonic-gate 		goto inpkt_done;	/* send it up the control stream */
22007c478bd9Sstevel@tonic-gate 	}
22017c478bd9Sstevel@tonic-gate 	/*
22027c478bd9Sstevel@tonic-gate 	 * Try to grab the destination upper stream from the network-layer
22037c478bd9Sstevel@tonic-gate 	 * stream cache for this ppa for PPP_IP (0x0021) or PPP_IPV6 (0x0057)
22047c478bd9Sstevel@tonic-gate 	 * protocol types. Otherwise, if the type is not known to the cache,
22057c478bd9Sstevel@tonic-gate 	 * or if its sap can't be matched with any of the upper streams, then
22067c478bd9Sstevel@tonic-gate 	 * send this packet up the control stream so that it can be rejected.
22077c478bd9Sstevel@tonic-gate 	 */
22087c478bd9Sstevel@tonic-gate 	if (proto == PPP_IP) {
22097c478bd9Sstevel@tonic-gate 		destsps = ppa->ppa_ip_cache;
22107c478bd9Sstevel@tonic-gate 	} else if (proto == PPP_IPV6) {
22117c478bd9Sstevel@tonic-gate 		destsps = ppa->ppa_ip6_cache;
22127c478bd9Sstevel@tonic-gate 	}
22137c478bd9Sstevel@tonic-gate 	/*
22147c478bd9Sstevel@tonic-gate 	 * Toss this one away up the control stream if there's no matching sap;
22157c478bd9Sstevel@tonic-gate 	 * this way the protocol can be rejected (destsps is NULL).
22167c478bd9Sstevel@tonic-gate 	 */
22177c478bd9Sstevel@tonic-gate 
22187c478bd9Sstevel@tonic-gate inpkt_done:
22197c478bd9Sstevel@tonic-gate 	/*
22207c478bd9Sstevel@tonic-gate 	 * Only time-stamp the packet with hrtime if the upper stream
22217c478bd9Sstevel@tonic-gate 	 * is configured to do so.  PPP control (negotiation) messages
22227c478bd9Sstevel@tonic-gate 	 * are never considered link activity; only data is activity.
22237c478bd9Sstevel@tonic-gate 	 */
22247c478bd9Sstevel@tonic-gate 	if (destsps != NULL && IS_PPA_TIMESTAMP(ppa)) {
22257c478bd9Sstevel@tonic-gate 		ppa->ppa_lastrx = gethrtime();
22267c478bd9Sstevel@tonic-gate 	}
22277c478bd9Sstevel@tonic-gate 	/*
22287c478bd9Sstevel@tonic-gate 	 * Should there be any promiscuous stream(s), send the data up for
22297c478bd9Sstevel@tonic-gate 	 * each promiscuous stream that we recognize. We skip the control
22307c478bd9Sstevel@tonic-gate 	 * stream as we obviously never allow the control stream to become
22317c478bd9Sstevel@tonic-gate 	 * promiscous and bind to PPP_ALLSAP.
22327c478bd9Sstevel@tonic-gate 	 */
22337c478bd9Sstevel@tonic-gate 	rw_enter(&ppa->ppa_sib_lock, RW_READER);
22347c478bd9Sstevel@tonic-gate 	is_promisc = ppa->ppa_promicnt;
22357c478bd9Sstevel@tonic-gate 	if (is_promisc) {
22367c478bd9Sstevel@tonic-gate 		ASSERT(ppa->ppa_streams != NULL);
22377c478bd9Sstevel@tonic-gate 		sppp_dlprsendup(ppa->ppa_streams, mp, proto, B_TRUE);
22387c478bd9Sstevel@tonic-gate 	}
22397c478bd9Sstevel@tonic-gate 	rw_exit(&ppa->ppa_sib_lock);
22407c478bd9Sstevel@tonic-gate 	return (destsps);
22417c478bd9Sstevel@tonic-gate }
22427c478bd9Sstevel@tonic-gate 
22437c478bd9Sstevel@tonic-gate /*
22447c478bd9Sstevel@tonic-gate  * sppp_kstat_update()
22457c478bd9Sstevel@tonic-gate  *
22467c478bd9Sstevel@tonic-gate  * Description:
22477c478bd9Sstevel@tonic-gate  *    Update per-ppa kstat interface statistics.
22487c478bd9Sstevel@tonic-gate  */
22497c478bd9Sstevel@tonic-gate static int
sppp_kstat_update(kstat_t * ksp,int rw)22507c478bd9Sstevel@tonic-gate sppp_kstat_update(kstat_t *ksp, int rw)
22517c478bd9Sstevel@tonic-gate {
22527c478bd9Sstevel@tonic-gate 	register sppa_t		*ppa;
22537c478bd9Sstevel@tonic-gate 	register sppp_kstats_t	*pppkp;
22547c478bd9Sstevel@tonic-gate 	register struct pppstat64 *sp;
22557c478bd9Sstevel@tonic-gate 
22567c478bd9Sstevel@tonic-gate 	if (rw == KSTAT_WRITE) {
22577c478bd9Sstevel@tonic-gate 		return (EACCES);
22587c478bd9Sstevel@tonic-gate 	}
22597c478bd9Sstevel@tonic-gate 
22607c478bd9Sstevel@tonic-gate 	ppa = (sppa_t *)ksp->ks_private;
22617c478bd9Sstevel@tonic-gate 	ASSERT(ppa != NULL);
22627c478bd9Sstevel@tonic-gate 
22637c478bd9Sstevel@tonic-gate 	pppkp = (sppp_kstats_t *)ksp->ks_data;
22647c478bd9Sstevel@tonic-gate 	sp = &ppa->ppa_stats.p;
22657c478bd9Sstevel@tonic-gate 
22667c478bd9Sstevel@tonic-gate 	mutex_enter(&ppa->ppa_sta_lock);
22677c478bd9Sstevel@tonic-gate 	pppkp->allocbfail.value.ui32	= ppa->ppa_allocbfail;
22687c478bd9Sstevel@tonic-gate 	pppkp->mctlsfwd.value.ui32	= ppa->ppa_mctlsfwd;
22697c478bd9Sstevel@tonic-gate 	pppkp->mctlsfwderr.value.ui32	= ppa->ppa_mctlsfwderr;
22707c478bd9Sstevel@tonic-gate 	pppkp->rbytes.value.ui32	= sp->ppp_ibytes;
22717c478bd9Sstevel@tonic-gate 	pppkp->rbytes64.value.ui64	= sp->ppp_ibytes;
22727c478bd9Sstevel@tonic-gate 	pppkp->ierrors.value.ui32	= sp->ppp_ierrors;
22737c478bd9Sstevel@tonic-gate 	pppkp->ierrors_lower.value.ui32	= ppa->ppa_ierr_low;
22747c478bd9Sstevel@tonic-gate 	pppkp->ioctlsfwd.value.ui32	= ppa->ppa_ioctlsfwd;
22757c478bd9Sstevel@tonic-gate 	pppkp->ioctlsfwdok.value.ui32	= ppa->ppa_ioctlsfwdok;
22767c478bd9Sstevel@tonic-gate 	pppkp->ioctlsfwderr.value.ui32	= ppa->ppa_ioctlsfwderr;
22777c478bd9Sstevel@tonic-gate 	pppkp->ipackets.value.ui32	= sp->ppp_ipackets;
22787c478bd9Sstevel@tonic-gate 	pppkp->ipackets64.value.ui64	= sp->ppp_ipackets;
22797c478bd9Sstevel@tonic-gate 	pppkp->ipackets_ctl.value.ui32	= ppa->ppa_ipkt_ctl;
22807c478bd9Sstevel@tonic-gate 	pppkp->iqdropped.value.ui32	= ppa->ppa_iqdropped;
22817c478bd9Sstevel@tonic-gate 	pppkp->irunts.value.ui32	= ppa->ppa_irunts;
22827c478bd9Sstevel@tonic-gate 	pppkp->itoolongs.value.ui32	= ppa->ppa_itoolongs;
22837c478bd9Sstevel@tonic-gate 	pppkp->lsneedup.value.ui32	= ppa->ppa_lsneedup;
22847c478bd9Sstevel@tonic-gate 	pppkp->lsdown.value.ui32	= ppa->ppa_lsdown;
22857c478bd9Sstevel@tonic-gate 	pppkp->mctlsknown.value.ui32	= ppa->ppa_mctlsknown;
22867c478bd9Sstevel@tonic-gate 	pppkp->mctlsunknown.value.ui32	= ppa->ppa_mctlsunknown;
22877c478bd9Sstevel@tonic-gate 	pppkp->obytes.value.ui32	= sp->ppp_obytes;
22887c478bd9Sstevel@tonic-gate 	pppkp->obytes64.value.ui64	= sp->ppp_obytes;
22897c478bd9Sstevel@tonic-gate 	pppkp->oerrors.value.ui32	= sp->ppp_oerrors;
22907c478bd9Sstevel@tonic-gate 	pppkp->oerrors_lower.value.ui32	= ppa->ppa_oerr_low;
22917c478bd9Sstevel@tonic-gate 	pppkp->opackets.value.ui32	= sp->ppp_opackets;
22927c478bd9Sstevel@tonic-gate 	pppkp->opackets64.value.ui64	= sp->ppp_opackets;
22937c478bd9Sstevel@tonic-gate 	pppkp->opackets_ctl.value.ui32	= ppa->ppa_opkt_ctl;
22947c478bd9Sstevel@tonic-gate 	pppkp->oqdropped.value.ui32	= ppa->ppa_oqdropped;
22957c478bd9Sstevel@tonic-gate 	pppkp->otoolongs.value.ui32	= ppa->ppa_otoolongs;
22967c478bd9Sstevel@tonic-gate 	pppkp->orunts.value.ui32	= ppa->ppa_orunts;
22977c478bd9Sstevel@tonic-gate 	mutex_exit(&ppa->ppa_sta_lock);
22987c478bd9Sstevel@tonic-gate 
22997c478bd9Sstevel@tonic-gate 	return (0);
23007c478bd9Sstevel@tonic-gate }
23017c478bd9Sstevel@tonic-gate 
23027c478bd9Sstevel@tonic-gate /*
23037c478bd9Sstevel@tonic-gate  * Turn off proto in ppa_npflag to indicate that
23047c478bd9Sstevel@tonic-gate  * the corresponding network protocol has been plumbed.
23057c478bd9Sstevel@tonic-gate  * Release proto packets that were being held in the control
23067c478bd9Sstevel@tonic-gate  * queue in anticipation of this event.
23077c478bd9Sstevel@tonic-gate  */
23087c478bd9Sstevel@tonic-gate static void
sppp_release_pkts(sppa_t * ppa,uint16_t proto)23097c478bd9Sstevel@tonic-gate sppp_release_pkts(sppa_t *ppa, uint16_t proto)
23107c478bd9Sstevel@tonic-gate {
23117c478bd9Sstevel@tonic-gate 	uint32_t npflagpos = sppp_ppp2np(proto);
23127c478bd9Sstevel@tonic-gate 	int count;
23137c478bd9Sstevel@tonic-gate 	mblk_t *mp;
23147c478bd9Sstevel@tonic-gate 	uint16_t mp_proto;
23157c478bd9Sstevel@tonic-gate 	queue_t *q;
23167c478bd9Sstevel@tonic-gate 	spppstr_t *destsps;
23177c478bd9Sstevel@tonic-gate 
23187c478bd9Sstevel@tonic-gate 	ASSERT(ppa != NULL);
23197c478bd9Sstevel@tonic-gate 
23207c478bd9Sstevel@tonic-gate 	if (npflagpos == 0 || (ppa->ppa_npflag & (1 << npflagpos)) == 0)
23217c478bd9Sstevel@tonic-gate 		return;
23227c478bd9Sstevel@tonic-gate 
23237c478bd9Sstevel@tonic-gate 	mutex_enter(&ppa->ppa_npmutex);
23247c478bd9Sstevel@tonic-gate 	ppa->ppa_npflag &= ~(1 << npflagpos);
23257c478bd9Sstevel@tonic-gate 	count = ppa->ppa_holdpkts[npflagpos];
23267c478bd9Sstevel@tonic-gate 	ppa->ppa_holdpkts[npflagpos] = 0;
23277c478bd9Sstevel@tonic-gate 	mutex_exit(&ppa->ppa_npmutex);
23287c478bd9Sstevel@tonic-gate 
23297c478bd9Sstevel@tonic-gate 	q = ppa->ppa_ctl->sps_rq;
23307c478bd9Sstevel@tonic-gate 
23317c478bd9Sstevel@tonic-gate 	while (count > 0) {
23327c478bd9Sstevel@tonic-gate 		mp = getq(q);
23337c478bd9Sstevel@tonic-gate 		ASSERT(mp != NULL);
23347c478bd9Sstevel@tonic-gate 
23357c478bd9Sstevel@tonic-gate 		mp_proto = PPP_PROTOCOL(mp->b_rptr);
23367c478bd9Sstevel@tonic-gate 		if (mp_proto !=  proto) {
23377c478bd9Sstevel@tonic-gate 			(void) putq(q, mp);
23387c478bd9Sstevel@tonic-gate 			continue;
23397c478bd9Sstevel@tonic-gate 		}
23407c478bd9Sstevel@tonic-gate 		count--;
23417c478bd9Sstevel@tonic-gate 		destsps = NULL;
23427c478bd9Sstevel@tonic-gate 		if (mp_proto == PPP_IP) {
23437c478bd9Sstevel@tonic-gate 			destsps = ppa->ppa_ip_cache;
23447c478bd9Sstevel@tonic-gate 		} else if (mp_proto == PPP_IPV6) {
23457c478bd9Sstevel@tonic-gate 			destsps = ppa->ppa_ip6_cache;
23467c478bd9Sstevel@tonic-gate 		}
23477c478bd9Sstevel@tonic-gate 		ASSERT(destsps != NULL);
23487c478bd9Sstevel@tonic-gate 
23497c478bd9Sstevel@tonic-gate 		if (IS_SPS_FASTPATH(destsps)) {
23507c478bd9Sstevel@tonic-gate 			mp->b_rptr += PPP_HDRLEN;
23517c478bd9Sstevel@tonic-gate 		} else {
23527c478bd9Sstevel@tonic-gate 			spppstr_t *uqs = (spppstr_t *)destsps->sps_rq->q_ptr;
23537c478bd9Sstevel@tonic-gate 			ASSERT(uqs != NULL);
23547c478bd9Sstevel@tonic-gate 			mp->b_rptr += PPP_HDRLEN;
23557c478bd9Sstevel@tonic-gate 			mp = sppp_dladdud(uqs, mp, uqs->sps_sap, B_FALSE);
23567c478bd9Sstevel@tonic-gate 			if (mp == NULL) {
23577c478bd9Sstevel@tonic-gate 				mutex_enter(&ppa->ppa_sta_lock);
23587c478bd9Sstevel@tonic-gate 				ppa->ppa_allocbfail++;
23597c478bd9Sstevel@tonic-gate 				mutex_exit(&ppa->ppa_sta_lock);
23607c478bd9Sstevel@tonic-gate 				/* mp already freed by sppp_dladdud */
23617c478bd9Sstevel@tonic-gate 				continue;
23627c478bd9Sstevel@tonic-gate 			}
23637c478bd9Sstevel@tonic-gate 		}
23647c478bd9Sstevel@tonic-gate 
23657c478bd9Sstevel@tonic-gate 		if (canputnext(destsps->sps_rq)) {
23667c478bd9Sstevel@tonic-gate 			putnext(destsps->sps_rq, mp);
23677c478bd9Sstevel@tonic-gate 		} else {
23687c478bd9Sstevel@tonic-gate 			mutex_enter(&ppa->ppa_sta_lock);
23697c478bd9Sstevel@tonic-gate 			ppa->ppa_iqdropped++;
23707c478bd9Sstevel@tonic-gate 			mutex_exit(&ppa->ppa_sta_lock);
23717c478bd9Sstevel@tonic-gate 			freemsg(mp);
23727c478bd9Sstevel@tonic-gate 			continue;
23737c478bd9Sstevel@tonic-gate 		}
23747c478bd9Sstevel@tonic-gate 	}
23757c478bd9Sstevel@tonic-gate }
2376