xref: /titanic_41/usr/src/cmd/mdb/common/modules/neti/neti.c (revision 1402f64f9efa57c2c2cba776f3f45c67e6055deb)
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 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #include <sys/types.h>
27 #include <sys/rwlock.h>
28 #include <mdb/mdb_modapi.h>
29 #include <sys/queue.h>
30 #include <sys/neti.h>
31 
32 
33 /*
34  * PROT_LENGTH is the max length. If the true length is bigger
35  * it is truncated.
36  */
37 #define	PROT_LENGTH 32
38 
39 /*
40  * List pfhooks netinfo information.
41  */
42 /*ARGSUSED*/
43 int
44 netinfolist(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
45 {
46 	struct neti_stack *nts;
47 	struct netd_listhead nlh;
48 	struct net_data nd, *p;
49 	char str[PROT_LENGTH];
50 
51 	if (argc)
52 		return (DCMD_USAGE);
53 
54 	if (mdb_vread((void *)&nts, sizeof (nts),
55 	    (uintptr_t)(addr + OFFSETOF(netstack_t, netstack_neti))) == -1) {
56 		mdb_warn("couldn't read netstack_neti");
57 		return (DCMD_ERR);
58 	}
59 
60 	if (mdb_vread((void *)&nlh, sizeof (nlh), (uintptr_t)((uintptr_t)nts +
61 	    OFFSETOF(neti_stack_t, nts_netd_head))) == -1) {
62 		mdb_warn("couldn't read netd list head");
63 		return (DCMD_ERR);
64 	}
65 	mdb_printf("%<u>%?s %?s %10s%</u>\n",
66 	    "ADDR(netinfo)", "ADDR(hookevent)", "netinfo");
67 	p = LIST_FIRST(&nlh);
68 	while (p) {
69 		if (mdb_vread((void *)&nd, sizeof (nd), (uintptr_t)p) == -1) {
70 			mdb_warn("couldn't read netinfo at %p", p);
71 			return (DCMD_ERR);
72 		}
73 		if (!nd.netd_info.netp_name) {
74 			mdb_warn("netinfo at %p has null protocol",
75 			    nd.netd_info.netp_name);
76 			return (DCMD_ERR);
77 		}
78 		if (mdb_readstr((char *)str, sizeof (str),
79 		    (uintptr_t)nd.netd_info.netp_name) == -1) {
80 			mdb_warn("couldn't read protocol at %p",
81 			    nd.netd_info.netp_name);
82 			return (DCMD_ERR);
83 		}
84 
85 		mdb_printf("%0?p %0?p %10s\n",
86 		    (char *)p + (uintptr_t)&((struct net_data *)0)->netd_info,
87 		    nd.netd_hooks, str);
88 
89 		p = LIST_NEXT(&nd, netd_list);
90 	}
91 
92 	return (DCMD_OK);
93 }
94 
95 static const mdb_dcmd_t dcmds[] = {
96 	{ "netinfolist", "", "display netinfo information",
97 		netinfolist, NULL },
98 	{ NULL }
99 };
100 
101 static const mdb_modinfo_t modinfo = { MDB_API_VERSION, dcmds };
102 
103 const mdb_modinfo_t *
104 _mdb_init(void)
105 {
106 	return (&modinfo);
107 }
108