xref: /onnv-gate/usr/src/cmd/mdb/common/modules/neti/neti.c (revision 7513:18aa777d3f09)
12958Sdr146992 /*
22958Sdr146992  * CDDL HEADER START
32958Sdr146992  *
42958Sdr146992  * The contents of this file are subject to the terms of the
52958Sdr146992  * Common Development and Distribution License (the "License").
62958Sdr146992  * You may not use this file except in compliance with the License.
72958Sdr146992  *
82958Sdr146992  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
92958Sdr146992  * or http://www.opensolaris.org/os/licensing.
102958Sdr146992  * See the License for the specific language governing permissions
112958Sdr146992  * and limitations under the License.
122958Sdr146992  *
132958Sdr146992  * When distributing Covered Code, include this CDDL HEADER in each
142958Sdr146992  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
152958Sdr146992  * If applicable, add the following below this CDDL HEADER, with the
162958Sdr146992  * fields enclosed by brackets "[]" replaced with your own identifying
172958Sdr146992  * information: Portions Copyright [yyyy] [name of copyright owner]
182958Sdr146992  *
192958Sdr146992  * CDDL HEADER END
202958Sdr146992  */
212958Sdr146992 /*
22*7513SDarren.Reed@Sun.COM  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
232958Sdr146992  * Use is subject to license terms.
242958Sdr146992  */
252958Sdr146992 
262958Sdr146992 #include <sys/types.h>
272958Sdr146992 #include <sys/rwlock.h>
282958Sdr146992 #include <mdb/mdb_modapi.h>
292958Sdr146992 #include <sys/queue.h>
302958Sdr146992 #include <sys/neti.h>
312958Sdr146992 
322958Sdr146992 
332958Sdr146992 /*
342958Sdr146992  * PROT_LENGTH is the max length. If the true length is bigger
352958Sdr146992  * it is truncated.
362958Sdr146992  */
372958Sdr146992 #define	PROT_LENGTH 32
382958Sdr146992 
392958Sdr146992 /*
402958Sdr146992  * List pfhooks netinfo information.
412958Sdr146992  */
422958Sdr146992 /*ARGSUSED*/
432958Sdr146992 int
netinfolist(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)442958Sdr146992 netinfolist(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
452958Sdr146992 {
463448Sdh155122 	struct neti_stack *nts;
472958Sdr146992 	struct netd_listhead nlh;
482958Sdr146992 	struct net_data nd, *p;
492958Sdr146992 	char str[PROT_LENGTH];
502958Sdr146992 
512958Sdr146992 	if (argc)
522958Sdr146992 		return (DCMD_USAGE);
532958Sdr146992 
543448Sdh155122 	if (mdb_vread((void *)&nts, sizeof (nts),
553448Sdh155122 	    (uintptr_t)(addr + OFFSETOF(netstack_t, netstack_neti))) == -1) {
563448Sdh155122 		mdb_warn("couldn't read netstack_neti");
573448Sdh155122 		return (DCMD_ERR);
583448Sdh155122 	}
593448Sdh155122 
603448Sdh155122 	if (mdb_vread((void *)&nlh, sizeof (nlh), (uintptr_t)((uintptr_t)nts +
613448Sdh155122 	    OFFSETOF(neti_stack_t, nts_netd_head))) == -1) {
623448Sdh155122 		mdb_warn("couldn't read netd list head");
632958Sdr146992 		return (DCMD_ERR);
642958Sdr146992 	}
652958Sdr146992 	mdb_printf("%<u>%?s %?s %10s%</u>\n",
662958Sdr146992 	    "ADDR(netinfo)", "ADDR(hookevent)", "netinfo");
672958Sdr146992 	p = LIST_FIRST(&nlh);
682958Sdr146992 	while (p) {
692958Sdr146992 		if (mdb_vread((void *)&nd, sizeof (nd), (uintptr_t)p) == -1) {
702958Sdr146992 			mdb_warn("couldn't read netinfo at %p", p);
712958Sdr146992 			return (DCMD_ERR);
722958Sdr146992 		}
73*7513SDarren.Reed@Sun.COM 		if (!nd.netd_info.netp_name) {
742958Sdr146992 			mdb_warn("netinfo at %p has null protocol",
75*7513SDarren.Reed@Sun.COM 			    nd.netd_info.netp_name);
762958Sdr146992 			return (DCMD_ERR);
772958Sdr146992 		}
782958Sdr146992 		if (mdb_readstr((char *)str, sizeof (str),
79*7513SDarren.Reed@Sun.COM 		    (uintptr_t)nd.netd_info.netp_name) == -1) {
802958Sdr146992 			mdb_warn("couldn't read protocol at %p",
81*7513SDarren.Reed@Sun.COM 			    nd.netd_info.netp_name);
822958Sdr146992 			return (DCMD_ERR);
832958Sdr146992 		}
842958Sdr146992 
852958Sdr146992 		mdb_printf("%0?p %0?p %10s\n",
862958Sdr146992 		    (char *)p + (uintptr_t)&((struct net_data *)0)->netd_info,
872958Sdr146992 		    nd.netd_hooks, str);
882958Sdr146992 
892958Sdr146992 		p = LIST_NEXT(&nd, netd_list);
902958Sdr146992 	}
912958Sdr146992 
922958Sdr146992 	return (DCMD_OK);
932958Sdr146992 }
942958Sdr146992 
952958Sdr146992 static const mdb_dcmd_t dcmds[] = {
962958Sdr146992 	{ "netinfolist", "", "display netinfo information",
972958Sdr146992 		netinfolist, NULL },
982958Sdr146992 	{ NULL }
992958Sdr146992 };
1002958Sdr146992 
1012958Sdr146992 static const mdb_modinfo_t modinfo = { MDB_API_VERSION, dcmds };
1022958Sdr146992 
1032958Sdr146992 const mdb_modinfo_t *
_mdb_init(void)1042958Sdr146992 _mdb_init(void)
1052958Sdr146992 {
1062958Sdr146992 	return (&modinfo);
1072958Sdr146992 }
108