xref: /titanic_50/usr/src/cmd/mdb/common/modules/neti/neti.c (revision 67e3a03ed4a2813074d36330f062ed6e593a4937)
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 2007 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 /*
42  * List pfhooks netinfo information.
43  */
44 /*ARGSUSED*/
45 int
46 netinfolist(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
47 {
48 	struct neti_stack *nts;
49 	struct netd_listhead nlh;
50 	struct net_data nd, *p;
51 	char str[PROT_LENGTH];
52 
53 	if (argc)
54 		return (DCMD_USAGE);
55 
56 	if (mdb_vread((void *)&nts, sizeof (nts),
57 	    (uintptr_t)(addr + OFFSETOF(netstack_t, netstack_neti))) == -1) {
58 		mdb_warn("couldn't read netstack_neti");
59 		return (DCMD_ERR);
60 	}
61 
62 	if (mdb_vread((void *)&nlh, sizeof (nlh), (uintptr_t)((uintptr_t)nts +
63 	    OFFSETOF(neti_stack_t, nts_netd_head))) == -1) {
64 		mdb_warn("couldn't read netd list head");
65 		return (DCMD_ERR);
66 	}
67 	mdb_printf("%<u>%?s %?s %10s%</u>\n",
68 	    "ADDR(netinfo)", "ADDR(hookevent)", "netinfo");
69 	p = LIST_FIRST(&nlh);
70 	while (p) {
71 		if (mdb_vread((void *)&nd, sizeof (nd), (uintptr_t)p) == -1) {
72 			mdb_warn("couldn't read netinfo at %p", p);
73 			return (DCMD_ERR);
74 		}
75 		if (!nd.netd_info.neti_protocol) {
76 			mdb_warn("netinfo at %p has null protocol",
77 			    nd.netd_info.neti_protocol);
78 			return (DCMD_ERR);
79 		}
80 		if (mdb_readstr((char *)str, sizeof (str),
81 		    (uintptr_t)nd.netd_info.neti_protocol) == -1) {
82 			mdb_warn("couldn't read protocol at %p",
83 			    nd.netd_info.neti_protocol);
84 			return (DCMD_ERR);
85 		}
86 
87 		mdb_printf("%0?p %0?p %10s\n",
88 		    (char *)p + (uintptr_t)&((struct net_data *)0)->netd_info,
89 		    nd.netd_hooks, str);
90 
91 		p = LIST_NEXT(&nd, netd_list);
92 	}
93 
94 	return (DCMD_OK);
95 }
96 
97 static const mdb_dcmd_t dcmds[] = {
98 	{ "netinfolist", "", "display netinfo information",
99 		netinfolist, NULL },
100 	{ NULL }
101 };
102 
103 static const mdb_modinfo_t modinfo = { MDB_API_VERSION, dcmds };
104 
105 const mdb_modinfo_t *
106 _mdb_init(void)
107 {
108 	return (&modinfo);
109 }
110