xref: /onnv-gate/usr/src/cmd/mdb/common/modules/neti/neti.c (revision 2958:98aa41c076f5)
1*2958Sdr146992 /*
2*2958Sdr146992  * CDDL HEADER START
3*2958Sdr146992  *
4*2958Sdr146992  * The contents of this file are subject to the terms of the
5*2958Sdr146992  * Common Development and Distribution License (the "License").
6*2958Sdr146992  * You may not use this file except in compliance with the License.
7*2958Sdr146992  *
8*2958Sdr146992  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*2958Sdr146992  * or http://www.opensolaris.org/os/licensing.
10*2958Sdr146992  * See the License for the specific language governing permissions
11*2958Sdr146992  * and limitations under the License.
12*2958Sdr146992  *
13*2958Sdr146992  * When distributing Covered Code, include this CDDL HEADER in each
14*2958Sdr146992  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*2958Sdr146992  * If applicable, add the following below this CDDL HEADER, with the
16*2958Sdr146992  * fields enclosed by brackets "[]" replaced with your own identifying
17*2958Sdr146992  * information: Portions Copyright [yyyy] [name of copyright owner]
18*2958Sdr146992  *
19*2958Sdr146992  * CDDL HEADER END
20*2958Sdr146992  */
21*2958Sdr146992 /*
22*2958Sdr146992  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23*2958Sdr146992  * Use is subject to license terms.
24*2958Sdr146992  */
25*2958Sdr146992 
26*2958Sdr146992 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27*2958Sdr146992 
28*2958Sdr146992 #include <sys/types.h>
29*2958Sdr146992 #include <sys/rwlock.h>
30*2958Sdr146992 #include <mdb/mdb_modapi.h>
31*2958Sdr146992 #include <sys/queue.h>
32*2958Sdr146992 #include <sys/neti.h>
33*2958Sdr146992 
34*2958Sdr146992 
35*2958Sdr146992 /*
36*2958Sdr146992  * PROT_LENGTH is the max length. If the true length is bigger
37*2958Sdr146992  * it is truncated.
38*2958Sdr146992  */
39*2958Sdr146992 #define	PROT_LENGTH 32
40*2958Sdr146992 
41*2958Sdr146992 LIST_HEAD(netd_listhead, net_data);
42*2958Sdr146992 
43*2958Sdr146992 /*
44*2958Sdr146992  * List pfhooks netinfo information.
45*2958Sdr146992  */
46*2958Sdr146992 /*ARGSUSED*/
47*2958Sdr146992 int
48*2958Sdr146992 netinfolist(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
49*2958Sdr146992 {
50*2958Sdr146992 	struct netd_listhead nlh;
51*2958Sdr146992 	struct net_data nd, *p;
52*2958Sdr146992 	char str[PROT_LENGTH];
53*2958Sdr146992 
54*2958Sdr146992 	if (argc)
55*2958Sdr146992 		return (DCMD_USAGE);
56*2958Sdr146992 
57*2958Sdr146992 	if (mdb_readvar(&nlh, "netd_head") == -1) {
58*2958Sdr146992 		mdb_warn("couldn't read symbol 'netd_head'");
59*2958Sdr146992 		return (DCMD_ERR);
60*2958Sdr146992 	}
61*2958Sdr146992 	mdb_printf("%<u>%?s %?s %10s%</u>\n",
62*2958Sdr146992 	    "ADDR(netinfo)", "ADDR(hookevent)", "netinfo");
63*2958Sdr146992 	p = LIST_FIRST(&nlh);
64*2958Sdr146992 	while (p) {
65*2958Sdr146992 		if (mdb_vread((void *)&nd, sizeof (nd), (uintptr_t)p) == -1) {
66*2958Sdr146992 			mdb_warn("couldn't read netinfo at %p", p);
67*2958Sdr146992 			return (DCMD_ERR);
68*2958Sdr146992 		}
69*2958Sdr146992 		if (!nd.netd_info.neti_protocol) {
70*2958Sdr146992 			mdb_warn("netinfo at %p has null protocol",
71*2958Sdr146992 			    nd.netd_info.neti_protocol);
72*2958Sdr146992 			return (DCMD_ERR);
73*2958Sdr146992 		}
74*2958Sdr146992 		if (mdb_readstr((char *)str, sizeof (str),
75*2958Sdr146992 		    (uintptr_t)nd.netd_info.neti_protocol) == -1) {
76*2958Sdr146992 			mdb_warn("couldn't read protocol at %p",
77*2958Sdr146992 			    nd.netd_info.neti_protocol);
78*2958Sdr146992 			return (DCMD_ERR);
79*2958Sdr146992 		}
80*2958Sdr146992 
81*2958Sdr146992 		mdb_printf("%0?p %0?p %10s\n",
82*2958Sdr146992 		    (char *)p + (uintptr_t)&((struct net_data *)0)->netd_info,
83*2958Sdr146992 		    nd.netd_hooks, str);
84*2958Sdr146992 
85*2958Sdr146992 		p = LIST_NEXT(&nd, netd_list);
86*2958Sdr146992 	}
87*2958Sdr146992 
88*2958Sdr146992 	return (DCMD_OK);
89*2958Sdr146992 }
90*2958Sdr146992 
91*2958Sdr146992 static const mdb_dcmd_t dcmds[] = {
92*2958Sdr146992 	{ "netinfolist", "", "display netinfo information",
93*2958Sdr146992 		netinfolist, NULL },
94*2958Sdr146992 	{ NULL }
95*2958Sdr146992 };
96*2958Sdr146992 
97*2958Sdr146992 static const mdb_modinfo_t modinfo = { MDB_API_VERSION, dcmds };
98*2958Sdr146992 
99*2958Sdr146992 const mdb_modinfo_t *
100*2958Sdr146992 _mdb_init(void)
101*2958Sdr146992 {
102*2958Sdr146992 	return (&modinfo);
103*2958Sdr146992 }
104