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