xref: /onnv-gate/usr/src/cmd/mdb/common/modules/sockfs/sockfs.c (revision 8348:4137e18bfaf0)
1*8348SEric.Yu@Sun.COM /*
2*8348SEric.Yu@Sun.COM  * CDDL HEADER START
3*8348SEric.Yu@Sun.COM  *
4*8348SEric.Yu@Sun.COM  * The contents of this file are subject to the terms of the
5*8348SEric.Yu@Sun.COM  * Common Development and Distribution License (the "License").
6*8348SEric.Yu@Sun.COM  * You may not use this file except in compliance with the License.
7*8348SEric.Yu@Sun.COM  *
8*8348SEric.Yu@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*8348SEric.Yu@Sun.COM  * or http://www.opensolaris.org/os/licensing.
10*8348SEric.Yu@Sun.COM  * See the License for the specific language governing permissions
11*8348SEric.Yu@Sun.COM  * and limitations under the License.
12*8348SEric.Yu@Sun.COM  *
13*8348SEric.Yu@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
14*8348SEric.Yu@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*8348SEric.Yu@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
16*8348SEric.Yu@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
17*8348SEric.Yu@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
18*8348SEric.Yu@Sun.COM  *
19*8348SEric.Yu@Sun.COM  * CDDL HEADER END
20*8348SEric.Yu@Sun.COM  */
21*8348SEric.Yu@Sun.COM /*
22*8348SEric.Yu@Sun.COM  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23*8348SEric.Yu@Sun.COM  * Use is subject to license terms.
24*8348SEric.Yu@Sun.COM  */
25*8348SEric.Yu@Sun.COM 
26*8348SEric.Yu@Sun.COM #include <sys/types.h>
27*8348SEric.Yu@Sun.COM #include <sys/stropts.h>
28*8348SEric.Yu@Sun.COM #include <sys/socket.h>
29*8348SEric.Yu@Sun.COM #include <sys/socketvar.h>
30*8348SEric.Yu@Sun.COM 
31*8348SEric.Yu@Sun.COM #include <mdb/mdb_modapi.h>
32*8348SEric.Yu@Sun.COM #include <mdb/mdb_ks.h>
33*8348SEric.Yu@Sun.COM 
34*8348SEric.Yu@Sun.COM /*
35*8348SEric.Yu@Sun.COM  * Look up the symbol name for the given sockparams list and walk
36*8348SEric.Yu@Sun.COM  * all the entries.
37*8348SEric.Yu@Sun.COM  */
38*8348SEric.Yu@Sun.COM static boolean_t
sockparams_walk_list(const char * symname,int argc,const mdb_arg_t * argv)39*8348SEric.Yu@Sun.COM sockparams_walk_list(const char *symname, int argc, const mdb_arg_t *argv)
40*8348SEric.Yu@Sun.COM {
41*8348SEric.Yu@Sun.COM 	GElf_Sym sym;
42*8348SEric.Yu@Sun.COM 
43*8348SEric.Yu@Sun.COM 	if (mdb_lookup_by_name(symname, &sym)) {
44*8348SEric.Yu@Sun.COM 		mdb_warn("can't find symbol %s", symname);
45*8348SEric.Yu@Sun.COM 		return (B_FALSE);
46*8348SEric.Yu@Sun.COM 	}
47*8348SEric.Yu@Sun.COM 
48*8348SEric.Yu@Sun.COM 	if (mdb_pwalk_dcmd("list", "sockfs`sockparams", argc, argv,
49*8348SEric.Yu@Sun.COM 	    sym.st_value) != 0) {
50*8348SEric.Yu@Sun.COM 		mdb_warn("can't walk %s", symname);
51*8348SEric.Yu@Sun.COM 		return (B_FALSE);
52*8348SEric.Yu@Sun.COM 	}
53*8348SEric.Yu@Sun.COM 
54*8348SEric.Yu@Sun.COM 	return (B_TRUE);
55*8348SEric.Yu@Sun.COM }
56*8348SEric.Yu@Sun.COM 
57*8348SEric.Yu@Sun.COM /*
58*8348SEric.Yu@Sun.COM  * dcmd to print sockparams info.
59*8348SEric.Yu@Sun.COM  *
60*8348SEric.Yu@Sun.COM  * If no address is given then the default is to print all sockparams on the
61*8348SEric.Yu@Sun.COM  * global list (i.e., installed with soconfig(1)). To also print the ephemeral
62*8348SEric.Yu@Sun.COM  * entries the '-e' flag should be used. Only ephemeral entries can be printed
63*8348SEric.Yu@Sun.COM  * by specifying the '-E' flag.
64*8348SEric.Yu@Sun.COM  */
65*8348SEric.Yu@Sun.COM static int
sockparams_prt(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)66*8348SEric.Yu@Sun.COM sockparams_prt(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
67*8348SEric.Yu@Sun.COM {
68*8348SEric.Yu@Sun.COM 	struct sockparams sp;
69*8348SEric.Yu@Sun.COM 
70*8348SEric.Yu@Sun.COM 	if ((flags & DCMD_ADDRSPEC) == 0) {
71*8348SEric.Yu@Sun.COM 		uint_t opt_e = 0;
72*8348SEric.Yu@Sun.COM 		uint_t opt_E = 0;
73*8348SEric.Yu@Sun.COM 
74*8348SEric.Yu@Sun.COM 		/*
75*8348SEric.Yu@Sun.COM 		 * Determine what lists should be printed
76*8348SEric.Yu@Sun.COM 		 */
77*8348SEric.Yu@Sun.COM 		if (mdb_getopts(argc, argv,
78*8348SEric.Yu@Sun.COM 		    'e', MDB_OPT_SETBITS, 1, &opt_e,
79*8348SEric.Yu@Sun.COM 		    'E', MDB_OPT_SETBITS, 1, &opt_E) != argc)
80*8348SEric.Yu@Sun.COM 			return (DCMD_USAGE);
81*8348SEric.Yu@Sun.COM 
82*8348SEric.Yu@Sun.COM 		if (!opt_E) {
83*8348SEric.Yu@Sun.COM 			if (!sockparams_walk_list("sphead", argc, argv))
84*8348SEric.Yu@Sun.COM 				return (DCMD_ERR);
85*8348SEric.Yu@Sun.COM 		}
86*8348SEric.Yu@Sun.COM 
87*8348SEric.Yu@Sun.COM 		if (opt_e || opt_E) {
88*8348SEric.Yu@Sun.COM 			if (!sockparams_walk_list("sp_ephem_list", argc, argv))
89*8348SEric.Yu@Sun.COM 				return (DCMD_ERR);
90*8348SEric.Yu@Sun.COM 		}
91*8348SEric.Yu@Sun.COM 
92*8348SEric.Yu@Sun.COM 		return (DCMD_OK);
93*8348SEric.Yu@Sun.COM 	}
94*8348SEric.Yu@Sun.COM 
95*8348SEric.Yu@Sun.COM 	/*
96*8348SEric.Yu@Sun.COM 	 * If we are piping the output, then just print out the address,
97*8348SEric.Yu@Sun.COM 	 * otherwise summarize the sockparams info.
98*8348SEric.Yu@Sun.COM 	 */
99*8348SEric.Yu@Sun.COM 	if ((flags & DCMD_PIPE_OUT) != 0) {
100*8348SEric.Yu@Sun.COM 		mdb_printf("%#lr\n", addr);
101*8348SEric.Yu@Sun.COM 		return (DCMD_OK);
102*8348SEric.Yu@Sun.COM 	}
103*8348SEric.Yu@Sun.COM 
104*8348SEric.Yu@Sun.COM 	if (DCMD_HDRSPEC(flags)) {
105*8348SEric.Yu@Sun.COM 		mdb_printf("%-?s %3s %3s %3s %15s %15s %6s %6s\n",
106*8348SEric.Yu@Sun.COM 		    "ADDR", "FAM", "TYP", "PRO", "STRDEV", "SOCKMOD", "REFS",
107*8348SEric.Yu@Sun.COM 		    "FLGS");
108*8348SEric.Yu@Sun.COM 	}
109*8348SEric.Yu@Sun.COM 
110*8348SEric.Yu@Sun.COM 	if (mdb_vread(&sp, sizeof (sp), addr) == -1) {
111*8348SEric.Yu@Sun.COM 		mdb_warn("failed to read sockparams at %0?p", addr);
112*8348SEric.Yu@Sun.COM 		return (DCMD_ERR);
113*8348SEric.Yu@Sun.COM 	}
114*8348SEric.Yu@Sun.COM 
115*8348SEric.Yu@Sun.COM 	mdb_printf("%0?p %3u %3u %3u %15s %15s %6u %#6x\n",
116*8348SEric.Yu@Sun.COM 	    addr,
117*8348SEric.Yu@Sun.COM 	    sp.sp_family, sp.sp_type, sp.sp_protocol,
118*8348SEric.Yu@Sun.COM 	    (sp.sp_sdev_info.sd_devpath != 0) ?
119*8348SEric.Yu@Sun.COM 	    sp.sp_sdev_info.sd_devpath : "-",
120*8348SEric.Yu@Sun.COM 	    sp.sp_smod_name, sp.sp_refcnt,
121*8348SEric.Yu@Sun.COM 	    sp.sp_flags);
122*8348SEric.Yu@Sun.COM 
123*8348SEric.Yu@Sun.COM 
124*8348SEric.Yu@Sun.COM 	return (DCMD_OK);
125*8348SEric.Yu@Sun.COM }
126*8348SEric.Yu@Sun.COM 
127*8348SEric.Yu@Sun.COM /*
128*8348SEric.Yu@Sun.COM  * Help function
129*8348SEric.Yu@Sun.COM  */
130*8348SEric.Yu@Sun.COM void
sockparams_help(void)131*8348SEric.Yu@Sun.COM sockparams_help(void)
132*8348SEric.Yu@Sun.COM {
133*8348SEric.Yu@Sun.COM 	mdb_printf("Print sockparams information for a give sockparams ptr.\n"
134*8348SEric.Yu@Sun.COM 	    "Without the address, list available sockparams. Default "
135*8348SEric.Yu@Sun.COM 	    "behavior is to list only entries that were installed by the "
136*8348SEric.Yu@Sun.COM 	    "admin (via soconfig(1M)).\n\n"
137*8348SEric.Yu@Sun.COM 	    "Options:\n"
138*8348SEric.Yu@Sun.COM 	    "	-e:\t\tlist ephemeral sockparams\n"
139*8348SEric.Yu@Sun.COM 	    "	-E:\t\tonly list ephemeral sockparams\n");
140*8348SEric.Yu@Sun.COM }
141*8348SEric.Yu@Sun.COM 
142*8348SEric.Yu@Sun.COM static const mdb_dcmd_t dcmds[] = {
143*8348SEric.Yu@Sun.COM 	{ "sockparams", "[-eE]", "print sockparams", sockparams_prt,
144*8348SEric.Yu@Sun.COM 	    sockparams_help },
145*8348SEric.Yu@Sun.COM 	{ NULL }
146*8348SEric.Yu@Sun.COM };
147*8348SEric.Yu@Sun.COM 
148*8348SEric.Yu@Sun.COM static const mdb_modinfo_t modinfo = { MDB_API_VERSION, dcmds, NULL };
149*8348SEric.Yu@Sun.COM 
150*8348SEric.Yu@Sun.COM const mdb_modinfo_t *
_mdb_init(void)151*8348SEric.Yu@Sun.COM _mdb_init(void)
152*8348SEric.Yu@Sun.COM {
153*8348SEric.Yu@Sun.COM 	return (&modinfo);
154*8348SEric.Yu@Sun.COM }
155