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 {
11207c478bd9