10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*9751Sjames.d.carlson@sun.com * Common Development and Distribution License (the "License").
6*9751Sjames.d.carlson@sun.com * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*9751Sjames.d.carlson@sun.com * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate #include <sys/types.h>
270Sstevel@tonic-gate #include <sys/stropts.h>
280Sstevel@tonic-gate #include <sys/stream.h>
290Sstevel@tonic-gate #include <sys/socket.h>
300Sstevel@tonic-gate #include <net/if.h>
310Sstevel@tonic-gate #define SOL2
320Sstevel@tonic-gate #include <net/ppp_defs.h>
330Sstevel@tonic-gate #include <net/pppio.h>
340Sstevel@tonic-gate #include <net/sppptun.h>
350Sstevel@tonic-gate #include <netinet/in.h>
360Sstevel@tonic-gate #include <netinet/ip6.h>
370Sstevel@tonic-gate #include <inet/common.h>
380Sstevel@tonic-gate #include <inet/mib2.h>
390Sstevel@tonic-gate #include <inet/ip.h>
400Sstevel@tonic-gate #include <inet/ip6.h>
410Sstevel@tonic-gate #include <sppp/sppp.h>
420Sstevel@tonic-gate #include <sppptun/sppptun_impl.h>
430Sstevel@tonic-gate
440Sstevel@tonic-gate #include <mdb/mdb_modapi.h>
450Sstevel@tonic-gate #include <mdb/mdb_ks.h>
460Sstevel@tonic-gate #include <stdio.h>
470Sstevel@tonic-gate
480Sstevel@tonic-gate /* ****************** sppp ****************** */
490Sstevel@tonic-gate
500Sstevel@tonic-gate static int
sppp_walk_init(mdb_walk_state_t * wsp)510Sstevel@tonic-gate sppp_walk_init(mdb_walk_state_t *wsp)
520Sstevel@tonic-gate {
530Sstevel@tonic-gate if (mdb_readvar(&wsp->walk_addr, "sps_list") == -1) {
540Sstevel@tonic-gate mdb_warn("failed to read sps_list");
550Sstevel@tonic-gate return (WALK_ERR);
560Sstevel@tonic-gate }
570Sstevel@tonic-gate
580Sstevel@tonic-gate return (WALK_NEXT);
590Sstevel@tonic-gate }
600Sstevel@tonic-gate
610Sstevel@tonic-gate static int
sppp_walk_step(mdb_walk_state_t * wsp)620Sstevel@tonic-gate sppp_walk_step(mdb_walk_state_t *wsp)
630Sstevel@tonic-gate {
640Sstevel@tonic-gate spppstr_t sps;
650Sstevel@tonic-gate int status;
660Sstevel@tonic-gate
670Sstevel@tonic-gate if (wsp->walk_addr == NULL)
680Sstevel@tonic-gate return (WALK_DONE);
690Sstevel@tonic-gate
700Sstevel@tonic-gate if (mdb_vread(&sps, sizeof (sps), wsp->walk_addr) == -1) {
710Sstevel@tonic-gate mdb_warn("can't read spppstr_t at %p", wsp->walk_addr);
720Sstevel@tonic-gate return (WALK_ERR);
730Sstevel@tonic-gate }
740Sstevel@tonic-gate
750Sstevel@tonic-gate status = (wsp->walk_callback(wsp->walk_addr, &sps, wsp->walk_cbdata));
760Sstevel@tonic-gate
770Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)sps.sps_nextmn;
780Sstevel@tonic-gate return (status);
790Sstevel@tonic-gate }
800Sstevel@tonic-gate
810Sstevel@tonic-gate static int
sps_format(uintptr_t addr,const spppstr_t * sps,uint_t * qfmt)820Sstevel@tonic-gate sps_format(uintptr_t addr, const spppstr_t *sps, uint_t *qfmt)
830Sstevel@tonic-gate {
840Sstevel@tonic-gate sppa_t ppa;
850Sstevel@tonic-gate queue_t upq;
860Sstevel@tonic-gate uintptr_t upaddr, illaddr;
870Sstevel@tonic-gate ill_t ill;
880Sstevel@tonic-gate ipif_t ipif;
890Sstevel@tonic-gate
900Sstevel@tonic-gate mdb_printf("%?p ", addr);
910Sstevel@tonic-gate if (*qfmt)
920Sstevel@tonic-gate mdb_printf("%?p ", sps->sps_rq);
930Sstevel@tonic-gate if (sps->sps_ppa == NULL) {
94*9751Sjames.d.carlson@sun.com mdb_printf("? unset ");
950Sstevel@tonic-gate } else if (mdb_vread(&ppa, sizeof (ppa), (uintptr_t)sps->sps_ppa) ==
960Sstevel@tonic-gate -1) {
97*9751Sjames.d.carlson@sun.com mdb_printf("? ?%p ", sps->sps_ppa);
980Sstevel@tonic-gate } else {
99*9751Sjames.d.carlson@sun.com mdb_printf("%-6d sppp%-5d ", ppa.ppa_zoneid, ppa.ppa_ppa_id);
1000Sstevel@tonic-gate }
1010Sstevel@tonic-gate if (IS_SPS_CONTROL(sps)) {
1020Sstevel@tonic-gate mdb_printf("Control\n");
1030Sstevel@tonic-gate } else if (IS_SPS_PIOATTACH(sps)) {
1040Sstevel@tonic-gate mdb_printf("Stats\n");
1050Sstevel@tonic-gate } else if (sps->sps_dlstate == DL_UNATTACHED) {
1060Sstevel@tonic-gate mdb_printf("Unknown\n");
1070Sstevel@tonic-gate } else if (sps->sps_dlstate != DL_IDLE) {
1080Sstevel@tonic-gate mdb_printf("DLPI Unbound\n");
1090Sstevel@tonic-gate } else {
1100Sstevel@tonic-gate upaddr = (uintptr_t)sps->sps_rq;
1110Sstevel@tonic-gate upq.q_ptr = NULL;
1120Sstevel@tonic-gate illaddr = 0;
1130Sstevel@tonic-gate while (upaddr != NULL) {
1140Sstevel@tonic-gate if (mdb_vread(&upq, sizeof (upq), upaddr) == -1) {
1150Sstevel@tonic-gate upq.q_ptr = NULL;
1160Sstevel@tonic-gate break;
1170Sstevel@tonic-gate }
1180Sstevel@tonic-gate if ((upaddr = (uintptr_t)upq.q_next) != 0)
1190Sstevel@tonic-gate illaddr = (uintptr_t)upq.q_ptr;
1200Sstevel@tonic-gate }
1210Sstevel@tonic-gate if (illaddr != 0) {
1220Sstevel@tonic-gate if (mdb_vread(&ill, sizeof (ill), illaddr) == -1 ||
1230Sstevel@tonic-gate mdb_vread(&ipif, sizeof (ipif),
124*9751Sjames.d.carlson@sun.com (uintptr_t)ill.ill_ipif) == -1) {
1250Sstevel@tonic-gate illaddr = 0;
1260Sstevel@tonic-gate }
1270Sstevel@tonic-gate }
1280Sstevel@tonic-gate
1290Sstevel@tonic-gate switch (sps->sps_req_sap) {
1300Sstevel@tonic-gate case ETHERTYPE_IP:
1310Sstevel@tonic-gate mdb_printf("DLPI IPv4 ");
1320Sstevel@tonic-gate if (*qfmt) {
1330Sstevel@tonic-gate mdb_printf("\n");
1340Sstevel@tonic-gate } else if (illaddr == 0) {
1350Sstevel@tonic-gate mdb_printf("(no addresses)\n");
1360Sstevel@tonic-gate } else {
1370Sstevel@tonic-gate /*
1380Sstevel@tonic-gate * SCCS oddity here -- % <capital> %
1390Sstevel@tonic-gate * suffers from keyword replacement.
1400Sstevel@tonic-gate * Avoid that by using ANSI string
1410Sstevel@tonic-gate * pasting.
1420Sstevel@tonic-gate */
1430Sstevel@tonic-gate mdb_printf("%I:%I" "%s\n",
1440Sstevel@tonic-gate ipif.ipif_lcl_addr, ipif.ipif_pp_dst_addr,
1450Sstevel@tonic-gate (ipif.ipif_next ? " ..." : ""));
1460Sstevel@tonic-gate }
1470Sstevel@tonic-gate break;
1480Sstevel@tonic-gate case ETHERTYPE_IPV6:
1490Sstevel@tonic-gate mdb_printf("DLPI IPv6 ");
1500Sstevel@tonic-gate if (*qfmt) {
1510Sstevel@tonic-gate mdb_printf("\n");
1520Sstevel@tonic-gate break;
1530Sstevel@tonic-gate }
1540Sstevel@tonic-gate if (illaddr == 0) {
1550Sstevel@tonic-gate mdb_printf("(no addresses)\n");
1560Sstevel@tonic-gate break;
1570Sstevel@tonic-gate }
1580Sstevel@tonic-gate mdb_printf("%N\n%?s%21s", &ipif.ipif_v6lcl_addr,
1590Sstevel@tonic-gate "", "");
1600Sstevel@tonic-gate mdb_printf("%N\n", &ipif.ipif_v6pp_dst_addr);
1610Sstevel@tonic-gate break;
1620Sstevel@tonic-gate case ETHERTYPE_ALLSAP:
1630Sstevel@tonic-gate mdb_printf("DLPI Snoop\n");
1640Sstevel@tonic-gate break;
1650Sstevel@tonic-gate default:
1660Sstevel@tonic-gate mdb_printf("DLPI SAP 0x%04X\n", sps->sps_req_sap);
1670Sstevel@tonic-gate break;
1680Sstevel@tonic-gate }
1690Sstevel@tonic-gate }
1700Sstevel@tonic-gate
1710Sstevel@tonic-gate return (WALK_NEXT);
1720Sstevel@tonic-gate }
1730Sstevel@tonic-gate
1740Sstevel@tonic-gate static int
sppp(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)1750Sstevel@tonic-gate sppp(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1760Sstevel@tonic-gate {
1770Sstevel@tonic-gate uint_t qfmt = FALSE;
1780Sstevel@tonic-gate spppstr_t sps;
1790Sstevel@tonic-gate
1800Sstevel@tonic-gate if (mdb_getopts(argc, argv, 'q', MDB_OPT_SETBITS, TRUE, &qfmt, NULL) !=
1810Sstevel@tonic-gate argc)
1820Sstevel@tonic-gate return (DCMD_USAGE);
1830Sstevel@tonic-gate
1840Sstevel@tonic-gate if ((flags & DCMD_LOOPFIRST) || !(flags & DCMD_LOOP)) {
1850Sstevel@tonic-gate if (qfmt) {
186*9751Sjames.d.carlson@sun.com mdb_printf("%<u>%?s %?s %-6s %-9s %s%</u>\n", "Address",
187*9751Sjames.d.carlson@sun.com "RecvQ", "ZoneID", "Interface", "Type");
1880Sstevel@tonic-gate } else {
189*9751Sjames.d.carlson@sun.com mdb_printf("%<u>%?s %-6s %-9s %s%</u>\n", "Address",
190*9751Sjames.d.carlson@sun.com "ZoneID", "Interface", "Type");
1910Sstevel@tonic-gate }
1920Sstevel@tonic-gate }
1930Sstevel@tonic-gate
1940Sstevel@tonic-gate if (flags & DCMD_ADDRSPEC) {
1950Sstevel@tonic-gate (void) mdb_vread(&sps, sizeof (sps), addr);
1960Sstevel@tonic-gate (void) sps_format(addr, &sps, &qfmt);
1970Sstevel@tonic-gate } else if (mdb_walk("sppp", (mdb_walk_cb_t)sps_format, &qfmt) == -1) {
1980Sstevel@tonic-gate mdb_warn("failed to walk sps_list");
1990Sstevel@tonic-gate return (DCMD_ERR);
2000Sstevel@tonic-gate }
2010Sstevel@tonic-gate
2020Sstevel@tonic-gate return (DCMD_OK);
2030Sstevel@tonic-gate }
2040Sstevel@tonic-gate
2050Sstevel@tonic-gate static int
sppa_walk_init(mdb_walk_state_t * wsp)2060Sstevel@tonic-gate sppa_walk_init(mdb_walk_state_t *wsp)
2070Sstevel@tonic-gate {
2080Sstevel@tonic-gate if (mdb_readvar(&wsp->walk_addr, "ppa_list") == -1) {
2090Sstevel@tonic-gate mdb_warn("failed to read ppa_list");
2100Sstevel@tonic-gate return (WALK_ERR);
2110Sstevel@tonic-gate }
2120Sstevel@tonic-gate
2130Sstevel@tonic-gate return (WALK_NEXT);
2140Sstevel@tonic-gate }
2150Sstevel@tonic-gate
2160Sstevel@tonic-gate static int
sppa_walk_step(mdb_walk_state_t * wsp)2170Sstevel@tonic-gate sppa_walk_step(mdb_walk_state_t *wsp)
2180Sstevel@tonic-gate {
2190Sstevel@tonic-gate sppa_t ppa;
2200Sstevel@tonic-gate int status;
2210Sstevel@tonic-gate
2220Sstevel@tonic-gate if (wsp->walk_addr == NULL)
2230Sstevel@tonic-gate return (WALK_DONE);
2240Sstevel@tonic-gate
2250Sstevel@tonic-gate if (mdb_vread(&ppa, sizeof (ppa), wsp->walk_addr) == -1) {
2260Sstevel@tonic-gate mdb_warn("can't read spppstr_t at %p", wsp->walk_addr);
2270Sstevel@tonic-gate return (WALK_ERR);
2280Sstevel@tonic-gate }
2290Sstevel@tonic-gate
2300Sstevel@tonic-gate status = (wsp->walk_callback(wsp->walk_addr, &ppa, wsp->walk_cbdata));
2310Sstevel@tonic-gate
2320Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)ppa.ppa_nextppa;
2330Sstevel@tonic-gate return (status);
2340Sstevel@tonic-gate }
2350Sstevel@tonic-gate
2360Sstevel@tonic-gate /* ARGSUSED */
2370Sstevel@tonic-gate static int
ppa_format(uintptr_t addr,const sppa_t * ppa,uint_t * qfmt)2380Sstevel@tonic-gate ppa_format(uintptr_t addr, const sppa_t *ppa, uint_t *qfmt)
2390Sstevel@tonic-gate {
240*9751Sjames.d.carlson@sun.com mdb_printf("%?p %-6d sppp%-5d %?p %?p\n", addr, ppa->ppa_zoneid,
241*9751Sjames.d.carlson@sun.com ppa->ppa_ppa_id, ppa->ppa_ctl, ppa->ppa_lower_wq);
2420Sstevel@tonic-gate
2430Sstevel@tonic-gate return (WALK_NEXT);
2440Sstevel@tonic-gate }
2450Sstevel@tonic-gate
2460Sstevel@tonic-gate /* ARGSUSED */
2470Sstevel@tonic-gate static int
sppa(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)2480Sstevel@tonic-gate sppa(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2490Sstevel@tonic-gate {
2500Sstevel@tonic-gate uint_t qfmt = FALSE;
2510Sstevel@tonic-gate sppa_t ppa;
2520Sstevel@tonic-gate
2530Sstevel@tonic-gate if ((flags & DCMD_LOOPFIRST) || !(flags & DCMD_LOOP)) {
254*9751Sjames.d.carlson@sun.com mdb_printf("%<u>%?s %-6s %-9s %?s %?s%</u>\n", "Address",
255*9751Sjames.d.carlson@sun.com "ZoneID", "Interface", "Control", "LowerQ");
2560Sstevel@tonic-gate }
2570Sstevel@tonic-gate
2580Sstevel@tonic-gate if (flags & DCMD_ADDRSPEC) {
2590Sstevel@tonic-gate (void) mdb_vread(&ppa, sizeof (ppa), addr);
2600Sstevel@tonic-gate (void) ppa_format(addr, &ppa, &qfmt);
2610Sstevel@tonic-gate } else if (mdb_walk("sppa", (mdb_walk_cb_t)ppa_format, &qfmt) == -1) {
2620Sstevel@tonic-gate mdb_warn("failed to walk ppa_list");
2630Sstevel@tonic-gate return (DCMD_ERR);
2640Sstevel@tonic-gate }
2650Sstevel@tonic-gate
2660Sstevel@tonic-gate return (DCMD_OK);
2670Sstevel@tonic-gate }
2680Sstevel@tonic-gate
2690Sstevel@tonic-gate static void
sppp_qinfo(const queue_t * q,char * buf,size_t nbytes)2700Sstevel@tonic-gate sppp_qinfo(const queue_t *q, char *buf, size_t nbytes)
2710Sstevel@tonic-gate {
2720Sstevel@tonic-gate spppstr_t sps;
2730Sstevel@tonic-gate sppa_t ppa;
2740Sstevel@tonic-gate
2750Sstevel@tonic-gate if (mdb_vread(&sps, sizeof (sps), (uintptr_t)q->q_ptr) ==
2760Sstevel@tonic-gate sizeof (sps)) {
2770Sstevel@tonic-gate if (sps.sps_ppa == NULL ||
2780Sstevel@tonic-gate mdb_vread(&ppa, sizeof (ppa), (uintptr_t)sps.sps_ppa) ==
2790Sstevel@tonic-gate -1) {
2800Sstevel@tonic-gate (void) mdb_snprintf(buf, nbytes, "minor %d",
2810Sstevel@tonic-gate sps.sps_mn_id);
2820Sstevel@tonic-gate } else {
2830Sstevel@tonic-gate (void) mdb_snprintf(buf, nbytes, "sppp%d",
2840Sstevel@tonic-gate ppa.ppa_ppa_id);
2850Sstevel@tonic-gate }
2860Sstevel@tonic-gate }
2870Sstevel@tonic-gate }
2880Sstevel@tonic-gate
2890Sstevel@tonic-gate static uintptr_t
sppp_rnext(const queue_t * q)2900Sstevel@tonic-gate sppp_rnext(const queue_t *q)
2910Sstevel@tonic-gate {
2920Sstevel@tonic-gate spppstr_t sps;
2930Sstevel@tonic-gate
2940Sstevel@tonic-gate if (mdb_vread(&sps, sizeof (sps), (uintptr_t)q->q_ptr) == sizeof (sps))
2950Sstevel@tonic-gate return ((uintptr_t)sps.sps_rq);
2960Sstevel@tonic-gate
2970Sstevel@tonic-gate return (NULL);
2980Sstevel@tonic-gate }
2990Sstevel@tonic-gate
3000Sstevel@tonic-gate static uintptr_t
sppp_wnext(const queue_t * q)3010Sstevel@tonic-gate sppp_wnext(const queue_t *q)
3020Sstevel@tonic-gate {
3030Sstevel@tonic-gate spppstr_t sps;
3040Sstevel@tonic-gate sppa_t ppa;
3050Sstevel@tonic-gate
3060Sstevel@tonic-gate if (mdb_vread(&sps, sizeof (sps), (uintptr_t)q->q_ptr) != sizeof (sps))
3070Sstevel@tonic-gate return (NULL);
3080Sstevel@tonic-gate
3090Sstevel@tonic-gate if (sps.sps_ppa != NULL &&
3100Sstevel@tonic-gate mdb_vread(&ppa, sizeof (ppa), (uintptr_t)sps.sps_ppa) ==
3110Sstevel@tonic-gate sizeof (ppa))
3120Sstevel@tonic-gate return ((uintptr_t)ppa.ppa_lower_wq);
3130Sstevel@tonic-gate
3140Sstevel@tonic-gate return (NULL);
3150Sstevel@tonic-gate }
3160Sstevel@tonic-gate
3170Sstevel@tonic-gate /* ****************** sppptun ****************** */
3180Sstevel@tonic-gate
3190Sstevel@tonic-gate struct tcl_walk_data {
3200Sstevel@tonic-gate size_t tcl_nslots;
3210Sstevel@tonic-gate size_t walkpos;
3220Sstevel@tonic-gate tuncl_t *tcl_slots[1];
3230Sstevel@tonic-gate };
3240Sstevel@tonic-gate
3250Sstevel@tonic-gate static void
tuncl_walk_fini(mdb_walk_state_t * wsp)3260Sstevel@tonic-gate tuncl_walk_fini(mdb_walk_state_t *wsp)
3270Sstevel@tonic-gate {
3280Sstevel@tonic-gate struct tcl_walk_data *twd;
3290Sstevel@tonic-gate
3300Sstevel@tonic-gate if (wsp != NULL && wsp->walk_addr != 0) {
3310Sstevel@tonic-gate twd = (struct tcl_walk_data *)wsp->walk_addr;
3320Sstevel@tonic-gate mdb_free(twd, sizeof (*twd) + ((twd->tcl_nslots - 1) *
3330Sstevel@tonic-gate sizeof (twd->tcl_slots[0])));
3340Sstevel@tonic-gate wsp->walk_addr = 0;
3350Sstevel@tonic-gate }
3360Sstevel@tonic-gate }
3370Sstevel@tonic-gate
3380Sstevel@tonic-gate static int
tuncl_walk_init(mdb_walk_state_t * wsp)3390Sstevel@tonic-gate tuncl_walk_init(mdb_walk_state_t *wsp)
3400Sstevel@tonic-gate {
3410Sstevel@tonic-gate size_t tcl_nslots;
3420Sstevel@tonic-gate tuncl_t **tcl_slots;
3430Sstevel@tonic-gate struct tcl_walk_data *twd;
3440Sstevel@tonic-gate
3450Sstevel@tonic-gate if (wsp == NULL)
3460Sstevel@tonic-gate return (WALK_ERR);
3470Sstevel@tonic-gate
3480Sstevel@tonic-gate if (wsp->walk_addr != 0)
3490Sstevel@tonic-gate tuncl_walk_fini(wsp);
3500Sstevel@tonic-gate
3510Sstevel@tonic-gate if (mdb_readvar(&tcl_nslots, "tcl_nslots") == -1) {
3520Sstevel@tonic-gate mdb_warn("failed to read tcl_nslots");
3530Sstevel@tonic-gate return (WALK_ERR);
3540Sstevel@tonic-gate }
3550Sstevel@tonic-gate
3560Sstevel@tonic-gate if (tcl_nslots == 0)
3570Sstevel@tonic-gate return (WALK_DONE);
3580Sstevel@tonic-gate
3590Sstevel@tonic-gate if (mdb_readvar(&tcl_slots, "tcl_slots") == -1) {
3600Sstevel@tonic-gate mdb_warn("failed to read tcl_slots");
3610Sstevel@tonic-gate return (WALK_ERR);
3620Sstevel@tonic-gate }
3630Sstevel@tonic-gate
3640Sstevel@tonic-gate twd = (struct tcl_walk_data *)mdb_alloc(sizeof (*twd) +
3650Sstevel@tonic-gate (tcl_nslots - 1) * sizeof (*tcl_slots), UM_NOSLEEP);
3660Sstevel@tonic-gate if (twd == NULL)
3670Sstevel@tonic-gate return (WALK_ERR);
3680Sstevel@tonic-gate twd->tcl_nslots = tcl_nslots;
3690Sstevel@tonic-gate twd->walkpos = 0;
3700Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)twd;
3710Sstevel@tonic-gate
3720Sstevel@tonic-gate if (mdb_vread(twd->tcl_slots, tcl_nslots * sizeof (twd->tcl_slots[0]),
3730Sstevel@tonic-gate (uintptr_t)tcl_slots) == -1) {
3740Sstevel@tonic-gate mdb_warn("can't read tcl_slots at %p", tcl_slots);
3750Sstevel@tonic-gate tuncl_walk_fini(wsp);
3760Sstevel@tonic-gate return (WALK_ERR);
3770Sstevel@tonic-gate }
3780Sstevel@tonic-gate
3790Sstevel@tonic-gate return (WALK_NEXT);
3800Sstevel@tonic-gate }
3810Sstevel@tonic-gate
3820Sstevel@tonic-gate static int
tuncl_walk_step(mdb_walk_state_t * wsp)3830Sstevel@tonic-gate tuncl_walk_step(mdb_walk_state_t *wsp)
3840Sstevel@tonic-gate {
3850Sstevel@tonic-gate tuncl_t tcl;
3860Sstevel@tonic-gate int status;
3870Sstevel@tonic-gate struct tcl_walk_data *twd;
3880Sstevel@tonic-gate uintptr_t addr;
3890Sstevel@tonic-gate
3900Sstevel@tonic-gate if (wsp == NULL || wsp->walk_addr == NULL)
3910Sstevel@tonic-gate return (WALK_DONE);
3920Sstevel@tonic-gate
3930Sstevel@tonic-gate twd = (struct tcl_walk_data *)wsp->walk_addr;
3940Sstevel@tonic-gate
3950Sstevel@tonic-gate while (twd->walkpos < twd->tcl_nslots &&
3960Sstevel@tonic-gate twd->tcl_slots[twd->walkpos] == NULL)
3970Sstevel@tonic-gate twd->walkpos++;
3980Sstevel@tonic-gate if (twd->walkpos >= twd->tcl_nslots)
3990Sstevel@tonic-gate return (WALK_DONE);
4000Sstevel@tonic-gate
4010Sstevel@tonic-gate addr = (uintptr_t)twd->tcl_slots[twd->walkpos];
4020Sstevel@tonic-gate if (mdb_vread(&tcl, sizeof (tcl), addr) == -1) {
4030Sstevel@tonic-gate mdb_warn("can't read tuncl_t at %p", addr);
4040Sstevel@tonic-gate return (WALK_ERR);
4050Sstevel@tonic-gate }
4060Sstevel@tonic-gate
4070Sstevel@tonic-gate status = wsp->walk_callback(addr, &tcl, wsp->walk_cbdata);
4080Sstevel@tonic-gate
4090Sstevel@tonic-gate twd->walkpos++;
4100Sstevel@tonic-gate return (status);
4110Sstevel@tonic-gate }
4120Sstevel@tonic-gate
4130Sstevel@tonic-gate /* ARGSUSED */
4140Sstevel@tonic-gate static int
tuncl_format(uintptr_t addr,const tuncl_t * tcl,uint_t * qfmt)4150Sstevel@tonic-gate tuncl_format(uintptr_t addr, const tuncl_t *tcl, uint_t *qfmt)
4160Sstevel@tonic-gate {
417*9751Sjames.d.carlson@sun.com mdb_printf("%?p %-6d %?p %?p", addr, tcl->tcl_zoneid, tcl->tcl_data_tll,
418*9751Sjames.d.carlson@sun.com tcl->tcl_ctrl_tll);
4190Sstevel@tonic-gate mdb_printf(" %-2d %04X %04X ", tcl->tcl_style,
4200Sstevel@tonic-gate tcl->tcl_lsessid, tcl->tcl_rsessid);
4210Sstevel@tonic-gate if (tcl->tcl_flags & TCLF_DAEMON) {
4220Sstevel@tonic-gate mdb_printf("<daemon>\n");
4230Sstevel@tonic-gate } else {
4240Sstevel@tonic-gate mdb_printf("sppp%d\n", tcl->tcl_unit);
4250Sstevel@tonic-gate }
4260Sstevel@tonic-gate
4270Sstevel@tonic-gate return (WALK_NEXT);
4280Sstevel@tonic-gate }
4290Sstevel@tonic-gate
4300Sstevel@tonic-gate /* ARGSUSED */
4310Sstevel@tonic-gate static int
tuncl(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)4320Sstevel@tonic-gate tuncl(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
4330Sstevel@tonic-gate {
4340Sstevel@tonic-gate uint_t qfmt = FALSE;
4350Sstevel@tonic-gate tuncl_t tcl;
4360Sstevel@tonic-gate
4370Sstevel@tonic-gate if ((flags & DCMD_LOOPFIRST) || !(flags & DCMD_LOOP)) {
438*9751Sjames.d.carlson@sun.com mdb_printf("%<u>%?s %-6s %?s %?s Ty LSes RSes %s%</u>\n",
439*9751Sjames.d.carlson@sun.com "Address", "ZoneID", "Data", "Control", "Interface");
4400Sstevel@tonic-gate }
4410Sstevel@tonic-gate
4420Sstevel@tonic-gate if (flags & DCMD_ADDRSPEC) {
4430Sstevel@tonic-gate if (mdb_vread(&tcl, sizeof (tcl), addr) == -1)
4440Sstevel@tonic-gate mdb_warn("failed to read tuncl_t at %p", addr);
4450Sstevel@tonic-gate else
4460Sstevel@tonic-gate tuncl_format(addr, &tcl, &qfmt);
4470Sstevel@tonic-gate } else if (mdb_walk("tuncl", (mdb_walk_cb_t)tuncl_format, &qfmt) ==
4480Sstevel@tonic-gate -1) {
4490Sstevel@tonic-gate mdb_warn("failed to walk tcl_slots");
4500Sstevel@tonic-gate return (DCMD_ERR);
4510Sstevel@tonic-gate }
4520Sstevel@tonic-gate
4530Sstevel@tonic-gate return (DCMD_OK);
4540Sstevel@tonic-gate }
4550Sstevel@tonic-gate
4560Sstevel@tonic-gate struct tll_walk_data {
4570Sstevel@tonic-gate void *listhead;
4580Sstevel@tonic-gate void *next;
4590Sstevel@tonic-gate };
4600Sstevel@tonic-gate
4610Sstevel@tonic-gate static void
tunll_walk_fini(mdb_walk_state_t * wsp)4620Sstevel@tonic-gate tunll_walk_fini(mdb_walk_state_t *wsp)
4630Sstevel@tonic-gate {
4640Sstevel@tonic-gate struct tll_walk_data *twd;
4650Sstevel@tonic-gate
4660Sstevel@tonic-gate if (wsp != NULL && wsp->walk_addr != 0) {
4670Sstevel@tonic-gate twd = (struct tll_walk_data *)wsp->walk_addr;
4680Sstevel@tonic-gate mdb_free(twd, sizeof (*twd));
4690Sstevel@tonic-gate wsp->walk_addr = 0;
4700Sstevel@tonic-gate }
4710Sstevel@tonic-gate }
4720Sstevel@tonic-gate
4730Sstevel@tonic-gate static int
tunll_walk_init(mdb_walk_state_t * wsp)4740Sstevel@tonic-gate tunll_walk_init(mdb_walk_state_t *wsp)
4750Sstevel@tonic-gate {
4760Sstevel@tonic-gate GElf_Sym sym;
4770Sstevel@tonic-gate struct tll_walk_data *twd;
4780Sstevel@tonic-gate struct qelem tunll_list;
4790Sstevel@tonic-gate
4800Sstevel@tonic-gate if (wsp->walk_addr != 0)
4810Sstevel@tonic-gate tunll_walk_fini(wsp);
4820Sstevel@tonic-gate
4830Sstevel@tonic-gate if (mdb_lookup_by_obj("sppptun", "tunll_list", &sym) != 0) {
4840Sstevel@tonic-gate mdb_warn("failed to find tunll_list");
4850Sstevel@tonic-gate return (WALK_ERR);
4860Sstevel@tonic-gate }
4870Sstevel@tonic-gate
4880Sstevel@tonic-gate if (mdb_vread(&tunll_list, sizeof (tunll_list),
4890Sstevel@tonic-gate (uintptr_t)sym.st_value) == -1) {
4900Sstevel@tonic-gate mdb_warn("can't read tunll_list at %p",
4910Sstevel@tonic-gate (uintptr_t)sym.st_value);
4920Sstevel@tonic-gate return (WALK_ERR);
4930Sstevel@tonic-gate }
4940Sstevel@tonic-gate
4950Sstevel@tonic-gate twd = (struct tll_walk_data *)mdb_alloc(sizeof (*twd), UM_NOSLEEP);
4960Sstevel@tonic-gate if (twd == NULL)
4970Sstevel@tonic-gate return (WALK_ERR);
4980Sstevel@tonic-gate twd->listhead = (void *)(uintptr_t)sym.st_value;
4990Sstevel@tonic-gate twd->next = (void *)tunll_list.q_forw;
5000Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)twd;
5010Sstevel@tonic-gate
5020Sstevel@tonic-gate return (WALK_NEXT);
5030Sstevel@tonic-gate }
5040Sstevel@tonic-gate
5050Sstevel@tonic-gate static int
tunll_walk_step(mdb_walk_state_t * wsp)5060Sstevel@tonic-gate tunll_walk_step(mdb_walk_state_t *wsp)
5070Sstevel@tonic-gate {
5080Sstevel@tonic-gate struct tll_walk_data *twd;
5090Sstevel@tonic-gate tunll_t tll;
5100Sstevel@tonic-gate int status;
5110Sstevel@tonic-gate uintptr_t addr;
5120Sstevel@tonic-gate
5130Sstevel@tonic-gate if (wsp == NULL || wsp->walk_addr == 0)
5140Sstevel@tonic-gate return (WALK_DONE);
5150Sstevel@tonic-gate
5160Sstevel@tonic-gate twd = (struct tll_walk_data *)wsp->walk_addr;
5170Sstevel@tonic-gate if (twd->next == NULL || twd->next == twd->listhead)
5180Sstevel@tonic-gate return (WALK_DONE);
5190Sstevel@tonic-gate
5200Sstevel@tonic-gate /* LINTED */
5210Sstevel@tonic-gate addr = (uintptr_t)TO_TLL(twd->next);
5220Sstevel@tonic-gate if (mdb_vread(&tll, sizeof (tll), addr) == -1) {
5230Sstevel@tonic-gate mdb_warn("can't read tunll_t at %p", addr);
5240Sstevel@tonic-gate return (WALK_ERR);
5250Sstevel@tonic-gate }
5260Sstevel@tonic-gate
5270Sstevel@tonic-gate status = wsp->walk_callback(addr, &tll, wsp->walk_cbdata);
5280Sstevel@tonic-gate
5290Sstevel@tonic-gate twd->next = (void *)tll.tll_next;
5300Sstevel@tonic-gate return (status);
5310Sstevel@tonic-gate }
5320Sstevel@tonic-gate
5330Sstevel@tonic-gate /* ARGSUSED */
5340Sstevel@tonic-gate static int
tunll_format(uintptr_t addr,const tunll_t * tll,uint_t * qfmt)5350Sstevel@tonic-gate tunll_format(uintptr_t addr, const tunll_t *tll, uint_t *qfmt)
5360Sstevel@tonic-gate {
537*9751Sjames.d.carlson@sun.com mdb_printf("%?p %-6d %-14s %?p", addr, tll->tll_zoneid, tll->tll_name,
538*9751Sjames.d.carlson@sun.com tll->tll_defcl);
5390Sstevel@tonic-gate if (tll->tll_style == PTS_PPPOE) {
5400Sstevel@tonic-gate mdb_printf(" %x:%x:%x:%x:%x:%x",
5410Sstevel@tonic-gate tll->tll_lcladdr.pta_pppoe.ptma_mac[0],
5420Sstevel@tonic-gate tll->tll_lcladdr.pta_pppoe.ptma_mac[1],
5430Sstevel@tonic-gate tll->tll_lcladdr.pta_pppoe.ptma_mac[2],
5440Sstevel@tonic-gate tll->tll_lcladdr.pta_pppoe.ptma_mac[3],
5450Sstevel@tonic-gate tll->tll_lcladdr.pta_pppoe.ptma_mac[4],
5460Sstevel@tonic-gate tll->tll_lcladdr.pta_pppoe.ptma_mac[5]);
5470Sstevel@tonic-gate }
5480Sstevel@tonic-gate mdb_printf("\n");
5490Sstevel@tonic-gate
5500Sstevel@tonic-gate return (WALK_NEXT);
5510Sstevel@tonic-gate }
5520Sstevel@tonic-gate
5530Sstevel@tonic-gate /* ARGSUSED */
5540Sstevel@tonic-gate static int
tunll(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)5550Sstevel@tonic-gate tunll(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
5560Sstevel@tonic-gate {
5570Sstevel@tonic-gate uint_t qfmt = FALSE;
5580Sstevel@tonic-gate tunll_t tll;
5590Sstevel@tonic-gate
5600Sstevel@tonic-gate if ((flags & DCMD_LOOPFIRST) || !(flags & DCMD_LOOP)) {
561*9751Sjames.d.carlson@sun.com mdb_printf("%<u>%?s %-6s %-14s %?s %s%</u>\n", "Address",
562*9751Sjames.d.carlson@sun.com "ZoneID", "Interface Name", "Daemon", "Local Address");
5630Sstevel@tonic-gate }
5640Sstevel@tonic-gate
5650Sstevel@tonic-gate if (flags & DCMD_ADDRSPEC) {
5660Sstevel@tonic-gate if (mdb_vread(&tll, sizeof (tll), addr) == -1)
5670Sstevel@tonic-gate mdb_warn("failed to read tunll_t at %p", addr);
5680Sstevel@tonic-gate else
5690Sstevel@tonic-gate tunll_format(addr, &tll, &qfmt);
5700Sstevel@tonic-gate } else if (mdb_walk("tunll", (mdb_walk_cb_t)tunll_format, &qfmt) ==
5710Sstevel@tonic-gate -1) {
5720Sstevel@tonic-gate mdb_warn("failed to walk tunll_list");
5730Sstevel@tonic-gate return (DCMD_ERR);
5740Sstevel@tonic-gate }
5750Sstevel@tonic-gate
5760Sstevel@tonic-gate return (DCMD_OK);
5770Sstevel@tonic-gate }
5780Sstevel@tonic-gate
5790Sstevel@tonic-gate union tun_state {
5800Sstevel@tonic-gate uint32_t tunflags;
5810Sstevel@tonic-gate tuncl_t tcl;
5820Sstevel@tonic-gate tunll_t tll;
5830Sstevel@tonic-gate };
5840Sstevel@tonic-gate
5850Sstevel@tonic-gate static int
tun_state_read(void * ptr,union tun_state * ts)5860Sstevel@tonic-gate tun_state_read(void *ptr, union tun_state *ts)
5870Sstevel@tonic-gate {
5880Sstevel@tonic-gate /*
5890Sstevel@tonic-gate * First, get the flags on this structure. This is either a
5900Sstevel@tonic-gate * tuncl_t or a tunll_t.
5910Sstevel@tonic-gate */
5920Sstevel@tonic-gate if (mdb_vread(&ts->tunflags, sizeof (ts->tunflags), (uintptr_t)ptr) ==
5930Sstevel@tonic-gate sizeof (ts->tunflags)) {
5940Sstevel@tonic-gate if (ts->tunflags & TCLF_ISCLIENT) {
5950Sstevel@tonic-gate if (mdb_vread(&ts->tcl, sizeof (ts->tcl),
5960Sstevel@tonic-gate (uintptr_t)ptr) == sizeof (ts->tcl)) {
5970Sstevel@tonic-gate return (0);
5980Sstevel@tonic-gate }
5990Sstevel@tonic-gate } else {
6000Sstevel@tonic-gate if (mdb_vread(&ts->tll, sizeof (ts->tll),
6010Sstevel@tonic-gate (uintptr_t)ptr) == sizeof (ts->tll)) {
6020Sstevel@tonic-gate return (0);
6030Sstevel@tonic-gate }
6040Sstevel@tonic-gate }
6050Sstevel@tonic-gate }
6060Sstevel@tonic-gate return (-1);
6070Sstevel@tonic-gate }
6080Sstevel@tonic-gate
6090Sstevel@tonic-gate static void
sppptun_qinfo(const queue_t * q,char * buf,size_t nbytes)6100Sstevel@tonic-gate sppptun_qinfo(const queue_t *q, char *buf, size_t nbytes)
6110Sstevel@tonic-gate {
6120Sstevel@tonic-gate union tun_state ts;
6130Sstevel@tonic-gate
6140Sstevel@tonic-gate if (tun_state_read(q->q_ptr, &ts) == -1)
6150Sstevel@tonic-gate return;
6160Sstevel@tonic-gate
6170Sstevel@tonic-gate if (ts.tcl.tcl_flags & TCLF_ISCLIENT)
6180Sstevel@tonic-gate mdb_snprintf(buf, nbytes, "sppp%d client %04X",
6190Sstevel@tonic-gate ts.tcl.tcl_unit, ts.tcl.tcl_lsessid);
6200Sstevel@tonic-gate else
6210Sstevel@tonic-gate mdb_snprintf(buf, nbytes, "%s", ts.tll.tll_name);
6220Sstevel@tonic-gate }
6230Sstevel@tonic-gate
6240Sstevel@tonic-gate static uintptr_t
sppptun_rnext(const queue_t * q)6250Sstevel@tonic-gate sppptun_rnext(const queue_t *q)
6260Sstevel@tonic-gate {
6270Sstevel@tonic-gate union tun_state ts;
6280Sstevel@tonic-gate
6290Sstevel@tonic-gate if (tun_state_read(q->q_ptr, &ts) == -1)
6300Sstevel@tonic-gate return (NULL);
6310Sstevel@tonic-gate
6320Sstevel@tonic-gate if (ts.tcl.tcl_flags & TCLF_ISCLIENT) {
6330Sstevel@tonic-gate return ((uintptr_t)ts.tcl.tcl_rq);
6340Sstevel@tonic-gate } else {
6350Sstevel@tonic-gate /* Not quite right, but ... */
6360Sstevel@tonic-gate return ((uintptr_t)ts.tll.tll_defcl);
6370Sstevel@tonic-gate }
6380Sstevel@tonic-gate }
6390Sstevel@tonic-gate
6400Sstevel@tonic-gate static uintptr_t
sppptun_wnext(const queue_t * q)6410Sstevel@tonic-gate sppptun_wnext(const queue_t *q)
6420Sstevel@tonic-gate {
6430Sstevel@tonic-gate union tun_state ts;
6440Sstevel@tonic-gate
6450Sstevel@tonic-gate if (tun_state_read(q->q_ptr, &ts) == -1)
6460Sstevel@tonic-gate return (NULL);
6470Sstevel@tonic-gate
6480Sstevel@tonic-gate if (ts.tcl.tcl_flags & TCLF_ISCLIENT) {
6490Sstevel@tonic-gate if (ts.tcl.tcl_data_tll == NULL)
6500Sstevel@tonic-gate return (NULL);
6510Sstevel@tonic-gate if (mdb_vread(&ts.tll, sizeof (ts.tll),
6520Sstevel@tonic-gate (uintptr_t)ts.tcl.tcl_data_tll) != sizeof (ts.tll)) {
6530Sstevel@tonic-gate return (NULL);
6540Sstevel@tonic-gate }
6550Sstevel@tonic-gate }
6560Sstevel@tonic-gate return ((uintptr_t)ts.tll.tll_wq);
6570Sstevel@tonic-gate }
6580Sstevel@tonic-gate
6590Sstevel@tonic-gate static const mdb_dcmd_t dcmds[] = {
6600Sstevel@tonic-gate { "sppp", "[-q]", "display PPP stream state structures", sppp },
6610Sstevel@tonic-gate { "sppa", "", "display PPP attachment state structures", sppa },
6620Sstevel@tonic-gate { "tuncl", "", "display sppptun client stream state structures",
6630Sstevel@tonic-gate tuncl },
6640Sstevel@tonic-gate { "tunll", "", "display sppptun lower stream state structures",
6650Sstevel@tonic-gate tunll },
6660Sstevel@tonic-gate { NULL }
6670Sstevel@tonic-gate };
6680Sstevel@tonic-gate
6690Sstevel@tonic-gate static const mdb_walker_t walkers[] = {
6700Sstevel@tonic-gate { "sppp", "walk active spppstr_t structures",
6710Sstevel@tonic-gate sppp_walk_init, sppp_walk_step, NULL },
6720Sstevel@tonic-gate { "sppa", "walk active sppa_t structures",
6730Sstevel@tonic-gate sppa_walk_init, sppa_walk_step, NULL },
6740Sstevel@tonic-gate { "tuncl", "walk active tuncl_t structures",
6750Sstevel@tonic-gate tuncl_walk_init, tuncl_walk_step, tuncl_walk_fini },
6760Sstevel@tonic-gate { "tunll", "walk active tunll_t structures",
6770Sstevel@tonic-gate tunll_walk_init, tunll_walk_step, tunll_walk_fini },
6780Sstevel@tonic-gate { NULL }
6790Sstevel@tonic-gate };
6800Sstevel@tonic-gate
6810Sstevel@tonic-gate static const mdb_qops_t sppp_qops = { sppp_qinfo, sppp_rnext, sppp_wnext };
6820Sstevel@tonic-gate static const mdb_qops_t sppptun_qops = {
6830Sstevel@tonic-gate sppptun_qinfo, sppptun_rnext, sppptun_wnext
6840Sstevel@tonic-gate };
6850Sstevel@tonic-gate static const mdb_modinfo_t modinfo = { MDB_API_VERSION, dcmds, walkers };
6860Sstevel@tonic-gate
6870Sstevel@tonic-gate const mdb_modinfo_t *
_mdb_init(void)6880Sstevel@tonic-gate _mdb_init(void)
6890Sstevel@tonic-gate {
6900Sstevel@tonic-gate GElf_Sym sym;
6910Sstevel@tonic-gate
6920Sstevel@tonic-gate if (mdb_lookup_by_obj("sppp", "sppp_uwinit", &sym) == 0)
6930Sstevel@tonic-gate mdb_qops_install(&sppp_qops, (uintptr_t)sym.st_value);
6940Sstevel@tonic-gate
6950Sstevel@tonic-gate if (mdb_lookup_by_obj("sppptun", "sppptun_uwinit", &sym) == 0)
6960Sstevel@tonic-gate mdb_qops_install(&sppptun_qops, (uintptr_t)sym.st_value);
6970Sstevel@tonic-gate
6980Sstevel@tonic-gate return (&modinfo);
6990Sstevel@tonic-gate }
7000Sstevel@tonic-gate
7010Sstevel@tonic-gate void
_mdb_fini(void)7020Sstevel@tonic-gate _mdb_fini(void)
7030Sstevel@tonic-gate {
7040Sstevel@tonic-gate GElf_Sym sym;
7050Sstevel@tonic-gate
7060Sstevel@tonic-gate if (mdb_lookup_by_obj("sppptun", "sppptun_uwinit", &sym) == 0)
7070Sstevel@tonic-gate mdb_qops_remove(&sppptun_qops, (uintptr_t)sym.st_value);
7080Sstevel@tonic-gate
7090Sstevel@tonic-gate if (mdb_lookup_by_obj("sppp", "sppp_uwinit", &sym) == 0)
7100Sstevel@tonic-gate mdb_qops_remove(&sppp_qops, (uintptr_t)sym.st_value);
7110Sstevel@tonic-gate }
712