1/*-
2 * Copyright (c) 2010 Bjoern A. Zeeb <bz@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD$");
29
30#include "opt_ddb.h"
31
32#include <sys/param.h>
33#include <sys/socket.h>
34#include <sys/types.h>
35
36#ifdef DDB
37#include <ddb/ddb.h>
38#endif
39
40#include <net/if.h>
41#include <net/if_types.h>
42#include <net/if_var.h>
43#include <net/vnet.h>
44
45#ifdef DDB
46struct ifindex_entry {
47	struct  ifnet *ife_ifnet;
48};
49VNET_DECLARE(struct ifindex_entry *, ifindex_table);
50#define	V_ifindex_table		VNET(ifindex_table)
51
52static void
53if_show_ifnet(struct ifnet *ifp)
54{
55
56	if (ifp == NULL)
57		return;
58	db_printf("%s:\n", ifp->if_xname);
59#define	IF_DB_PRINTF(f, e)	db_printf("   %s = " f "\n", #e, ifp->e);
60	IF_DB_PRINTF("%s", if_dname);
61	IF_DB_PRINTF("%d", if_dunit);
62	IF_DB_PRINTF("%s", if_description);
63	IF_DB_PRINTF("%u", if_index);
64	IF_DB_PRINTF("%u", if_refcount);
65	IF_DB_PRINTF("%d", if_index_reserved);
66	IF_DB_PRINTF("%p", if_softc);
67	IF_DB_PRINTF("%p", if_l2com);
68	IF_DB_PRINTF("%p", if_llsoftc);
69	IF_DB_PRINTF("%d", if_amcount);
70	IF_DB_PRINTF("%p", if_addr);
71	IF_DB_PRINTF("%p", if_broadcastaddr);
72	IF_DB_PRINTF("%p", if_afdata);
73	IF_DB_PRINTF("%d", if_afdata_initialized);
74	IF_DB_PRINTF("%u", if_fib);
75	IF_DB_PRINTF("%p", if_vnet);
76	IF_DB_PRINTF("%p", if_home_vnet);
77	IF_DB_PRINTF("%p", if_vlantrunk);
78	IF_DB_PRINTF("%p", if_bpf);
79	IF_DB_PRINTF("%u", if_pcount);
80	IF_DB_PRINTF("%p", if_bridge);
81	IF_DB_PRINTF("%p", if_lagg);
82	IF_DB_PRINTF("%p", if_pf_kif);
83	IF_DB_PRINTF("%p", if_carp);
84	IF_DB_PRINTF("%p", if_label);
85	IF_DB_PRINTF("%p", if_netmap);
86	IF_DB_PRINTF("0x%08x", if_flags);
87	IF_DB_PRINTF("0x%08x", if_drv_flags);
88	IF_DB_PRINTF("0x%08x", if_capabilities);
89	IF_DB_PRINTF("0x%08x", if_capenable);
90	IF_DB_PRINTF("%p", if_snd.ifq_head);
91	IF_DB_PRINTF("%p", if_snd.ifq_tail);
92	IF_DB_PRINTF("%d", if_snd.ifq_len);
93	IF_DB_PRINTF("%d", if_snd.ifq_maxlen);
94	IF_DB_PRINTF("%p", if_snd.ifq_drv_head);
95	IF_DB_PRINTF("%p", if_snd.ifq_drv_tail);
96	IF_DB_PRINTF("%d", if_snd.ifq_drv_len);
97	IF_DB_PRINTF("%d", if_snd.ifq_drv_maxlen);
98	IF_DB_PRINTF("%d", if_snd.altq_type);
99	IF_DB_PRINTF("%x", if_snd.altq_flags);
100#undef IF_DB_PRINTF
101}
102
103DB_SHOW_COMMAND(ifnet, db_show_ifnet)
104{
105
106	if (!have_addr) {
107		db_printf("usage: show ifnet <struct ifnet *>\n");
108		return;
109	}
110
111	if_show_ifnet((struct ifnet *)addr);
112}
113
114DB_SHOW_ALL_COMMAND(ifnets, db_show_all_ifnets)
115{
116	VNET_ITERATOR_DECL(vnet_iter);
117	struct ifnet *ifp;
118	u_short idx;
119
120	VNET_FOREACH(vnet_iter) {
121		CURVNET_SET_QUIET(vnet_iter);
122#ifdef VIMAGE
123		db_printf("vnet=%p\n", curvnet);
124#endif
125		for (idx = 1; idx <= V_if_index; idx++) {
126			ifp = V_ifindex_table[idx].ife_ifnet;
127			if (ifp == NULL)
128				continue;
129			db_printf( "%20s ifp=%p\n", ifp->if_xname, ifp);
130			if (db_pager_quit)
131				break;
132		}
133		CURVNET_RESTORE();
134	}
135}
136#endif
137