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); 68302086Sbz IF_DB_PRINTF("%p", if_llsoftc); 69302086Sbz IF_DB_PRINTF("%d", if_amcount); 70302086Sbz IF_DB_PRINTF("%p", if_addr); 71302086Sbz IF_DB_PRINTF("%p", if_broadcastaddr); 72298373Sbz IF_DB_PRINTF("%p", if_afdata); 73298373Sbz IF_DB_PRINTF("%d", if_afdata_initialized); 74298373Sbz IF_DB_PRINTF("%u", if_fib); 75214333Sbz IF_DB_PRINTF("%p", if_vnet); 76214333Sbz IF_DB_PRINTF("%p", if_home_vnet); 77297471Sbz IF_DB_PRINTF("%p", if_vlantrunk); 78297471Sbz IF_DB_PRINTF("%p", if_bpf); 79302086Sbz IF_DB_PRINTF("%u", if_pcount); 80302086Sbz IF_DB_PRINTF("%p", if_bridge); 81302086Sbz IF_DB_PRINTF("%p", if_lagg); 82302086Sbz IF_DB_PRINTF("%p", if_pf_kif); 83302086Sbz IF_DB_PRINTF("%p", if_carp); 84214333Sbz IF_DB_PRINTF("%p", if_label); 85302086Sbz IF_DB_PRINTF("%p", if_netmap); 86214333Sbz IF_DB_PRINTF("0x%08x", if_flags); 87214333Sbz IF_DB_PRINTF("0x%08x", if_drv_flags); 88214333Sbz IF_DB_PRINTF("0x%08x", if_capabilities); 89214333Sbz IF_DB_PRINTF("0x%08x", if_capenable); 90214333Sbz IF_DB_PRINTF("%p", if_snd.ifq_head); 91214333Sbz IF_DB_PRINTF("%p", if_snd.ifq_tail); 92214333Sbz IF_DB_PRINTF("%d", if_snd.ifq_len); 93214333Sbz IF_DB_PRINTF("%d", if_snd.ifq_maxlen); 94214333Sbz IF_DB_PRINTF("%p", if_snd.ifq_drv_head); 95214333Sbz IF_DB_PRINTF("%p", if_snd.ifq_drv_tail); 96214333Sbz IF_DB_PRINTF("%d", if_snd.ifq_drv_len); 97214333Sbz IF_DB_PRINTF("%d", if_snd.ifq_drv_maxlen); 98214333Sbz IF_DB_PRINTF("%d", if_snd.altq_type); 99214333Sbz IF_DB_PRINTF("%x", if_snd.altq_flags); 100214333Sbz#undef IF_DB_PRINTF 101214333Sbz} 102214333Sbz 103214333SbzDB_SHOW_COMMAND(ifnet, db_show_ifnet) 104214333Sbz{ 105214333Sbz 106214333Sbz if (!have_addr) { 107214333Sbz db_printf("usage: show ifnet <struct ifnet *>\n"); 108214333Sbz return; 109214333Sbz } 110214333Sbz 111214333Sbz if_show_ifnet((struct ifnet *)addr); 112214333Sbz} 113214333Sbz 114214333SbzDB_SHOW_ALL_COMMAND(ifnets, db_show_all_ifnets) 115214333Sbz{ 116214333Sbz VNET_ITERATOR_DECL(vnet_iter); 117214333Sbz struct ifnet *ifp; 118214333Sbz u_short idx; 119214333Sbz 120214333Sbz VNET_FOREACH(vnet_iter) { 121214333Sbz CURVNET_SET_QUIET(vnet_iter); 122214333Sbz#ifdef VIMAGE 123214333Sbz db_printf("vnet=%p\n", curvnet); 124214333Sbz#endif 125214333Sbz for (idx = 1; idx <= V_if_index; idx++) { 126214333Sbz ifp = V_ifindex_table[idx].ife_ifnet; 127214333Sbz if (ifp == NULL) 128214333Sbz continue; 129214333Sbz db_printf( "%20s ifp=%p\n", ifp->if_xname, ifp); 130214333Sbz if (db_pager_quit) 131214333Sbz break; 132214333Sbz } 133214333Sbz CURVNET_RESTORE(); 134214333Sbz } 135214333Sbz} 136214333Sbz#endif 137