1214333Sbz/*- 2214333Sbz * Copyright (c) 2010 Bjoern A. Zeeb <bz@FreeBSD.org> 3214333Sbz * All rights reserved. 4214333Sbz * 5214333Sbz * Redistribution and use in source and binary forms, with or without 6214333Sbz * modification, are permitted provided that the following conditions 7214333Sbz * are met: 8214333Sbz * 1. Redistributions of source code must retain the above copyright 9214333Sbz * notice, this list of conditions and the following disclaimer. 10214333Sbz * 2. Redistributions in binary form must reproduce the above copyright 11214333Sbz * notice, this list of conditions and the following disclaimer in the 12214333Sbz * documentation and/or other materials provided with the distribution. 13214333Sbz * 14214333Sbz * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15214333Sbz * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16214333Sbz * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17214333Sbz * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18214333Sbz * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19214333Sbz * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20214333Sbz * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21214333Sbz * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22214333Sbz * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23214333Sbz * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24214333Sbz * SUCH DAMAGE. 25214333Sbz */ 26214333Sbz 27214333Sbz#include <sys/cdefs.h> 28214333Sbz__FBSDID("$FreeBSD$"); 29214333Sbz 30214333Sbz#include "opt_ddb.h" 31214333Sbz 32214333Sbz#include <sys/param.h> 33214333Sbz#include <sys/socket.h> 34214333Sbz#include <sys/types.h> 35214333Sbz 36214333Sbz#ifdef DDB 37214333Sbz#include <ddb/ddb.h> 38214333Sbz#endif 39214333Sbz 40214333Sbz#include <net/if.h> 41214333Sbz#include <net/if_types.h> 42214333Sbz#include <net/if_var.h> 43214333Sbz#include <net/vnet.h> 44214333Sbz 45214333Sbz#ifdef DDB 46214333Sbzstruct ifindex_entry { 47214333Sbz struct ifnet *ife_ifnet; 48214333Sbz}; 49214333SbzVNET_DECLARE(struct ifindex_entry *, ifindex_table); 50214333Sbz#define V_ifindex_table VNET(ifindex_table) 51214333Sbz 52214333Sbzstatic void 53214333Sbzif_show_ifnet(struct ifnet *ifp) 54214333Sbz{ 55214333Sbz 56214333Sbz if (ifp == NULL) 57214333Sbz return; 58214333Sbz db_printf("%s:\n", ifp->if_xname); 59214333Sbz#define IF_DB_PRINTF(f, e) db_printf(" %s = " f "\n", #e, ifp->e); 60214333Sbz IF_DB_PRINTF("%s", if_dname); 61214333Sbz IF_DB_PRINTF("%d", if_dunit); 62214333Sbz IF_DB_PRINTF("%s", if_description); 63214333Sbz IF_DB_PRINTF("%u", if_index); 64214333Sbz IF_DB_PRINTF("%u", if_refcount); 65214333Sbz IF_DB_PRINTF("%d", if_index_reserved); 66214333Sbz IF_DB_PRINTF("%p", if_softc); 67214333Sbz IF_DB_PRINTF("%p", if_l2com); 68214333Sbz IF_DB_PRINTF("%p", if_vnet); 69214333Sbz IF_DB_PRINTF("%p", if_home_vnet); 70214333Sbz IF_DB_PRINTF("%p", if_addr); 71214333Sbz IF_DB_PRINTF("%p", if_llsoftc); 72214333Sbz IF_DB_PRINTF("%p", if_label); 73214333Sbz IF_DB_PRINTF("%u", if_pcount); 74214333Sbz IF_DB_PRINTF("0x%08x", if_flags); 75214333Sbz IF_DB_PRINTF("0x%08x", if_drv_flags); 76214333Sbz IF_DB_PRINTF("0x%08x", if_capabilities); 77214333Sbz IF_DB_PRINTF("0x%08x", if_capenable); 78214333Sbz IF_DB_PRINTF("%p", if_snd.ifq_head); 79214333Sbz IF_DB_PRINTF("%p", if_snd.ifq_tail); 80214333Sbz IF_DB_PRINTF("%d", if_snd.ifq_len); 81214333Sbz IF_DB_PRINTF("%d", if_snd.ifq_maxlen); 82214333Sbz IF_DB_PRINTF("%d", if_snd.ifq_drops); 83214333Sbz IF_DB_PRINTF("%p", if_snd.ifq_drv_head); 84214333Sbz IF_DB_PRINTF("%p", if_snd.ifq_drv_tail); 85214333Sbz IF_DB_PRINTF("%d", if_snd.ifq_drv_len); 86214333Sbz IF_DB_PRINTF("%d", if_snd.ifq_drv_maxlen); 87214333Sbz IF_DB_PRINTF("%d", if_snd.altq_type); 88214333Sbz IF_DB_PRINTF("%x", if_snd.altq_flags); 89223735Sbz IF_DB_PRINTF("%u", if_fib); 90214333Sbz#undef IF_DB_PRINTF 91214333Sbz} 92214333Sbz 93214333SbzDB_SHOW_COMMAND(ifnet, db_show_ifnet) 94214333Sbz{ 95214333Sbz 96214333Sbz if (!have_addr) { 97214333Sbz db_printf("usage: show ifnet <struct ifnet *>\n"); 98214333Sbz return; 99214333Sbz } 100214333Sbz 101214333Sbz if_show_ifnet((struct ifnet *)addr); 102214333Sbz} 103214333Sbz 104214333SbzDB_SHOW_ALL_COMMAND(ifnets, db_show_all_ifnets) 105214333Sbz{ 106214333Sbz VNET_ITERATOR_DECL(vnet_iter); 107214333Sbz struct ifnet *ifp; 108214333Sbz u_short idx; 109214333Sbz 110214333Sbz VNET_FOREACH(vnet_iter) { 111214333Sbz CURVNET_SET_QUIET(vnet_iter); 112214333Sbz#ifdef VIMAGE 113214333Sbz db_printf("vnet=%p\n", curvnet); 114214333Sbz#endif 115214333Sbz for (idx = 1; idx <= V_if_index; idx++) { 116214333Sbz ifp = V_ifindex_table[idx].ife_ifnet; 117214333Sbz if (ifp == NULL) 118214333Sbz continue; 119214333Sbz db_printf( "%20s ifp=%p\n", ifp->if_xname, ifp); 120214333Sbz if (db_pager_quit) 121214333Sbz break; 122214333Sbz } 123214333Sbz CURVNET_RESTORE(); 124214333Sbz } 125214333Sbz} 126214333Sbz#endif 127