4 * cc -I/usr/src/sys wildcardinfo.c -o /usr/local/bin/wildcardinfo -lkvm
8 * Dump the tcbinfo[] array and wildcard hash table for each cpu.
10 * Copyright (c) 2004 The DragonFly Project. All rights reserved.
12 * This code is derived from software contributed to The DragonFly Project
13 * by Matthew Dillon <dillon@backplane.com>
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in
23 * the documentation and/or other materials provided with the
25 * 3. Neither the name of The DragonFly Project nor the names of its
26 * contributors may be used to endorse or promote products derived
27 * from this software without specific, prior written permission.
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
32 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
33 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
34 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
35 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
36 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
37 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
38 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
39 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 * $DragonFly: src/test/debug/wildcardinfo.c,v 1.1 2005/04/05 02:49:15 dillon Exp $
45 #define _KERNEL_STRUCTURES_
46 #include <sys/param.h>
48 #include <sys/malloc.h>
49 #include <sys/signalvar.h>
50 #include <sys/socket.h>
51 #include <sys/socketvar.h>
52 #include <net/route.h>
54 #include <net/if_var.h>
55 #include <net/netisr.h>
56 #include <netinet/in_systm.h>
57 #include <netinet/in.h>
58 #include <netinet/ip.h>
59 #include <netinet/in_pcb.h>
60 #include <netinet/in_var.h>
61 #include <arpa/inet.h>
77 static void dumptcb(kvm_t *kd, intptr_t tcbinfo);
78 static void dumpinpcontainerhead(kvm_t *kd, int index, void *kptr);
79 static void kkread(kvm_t *kd, u_long addr, void *buf, size_t nbytes);
82 main(int ac, char **av)
88 const char *corefile = NULL;
89 const char *sysfile = NULL;
91 while ((ch = getopt(ac, av, "M:N:")) != -1) {
100 fprintf(stderr, "%s [-M core] [-N system]\n", av[0]);
105 if ((kd = kvm_open(sysfile, corefile, NULL, O_RDONLY, "kvm:")) == NULL) {
109 if (kvm_nlist(kd, Nl) != 0) {
113 kkread(kd, Nl[0].n_value, &ncpus, sizeof(ncpus));
114 for (i = 0; i < ncpus; ++i) {
115 printf("CPU %d\n", i);
116 dumptcb(kd, (intptr_t)Nl[1].n_value + i * sizeof(struct inpcbinfo));
123 dumptcb(kvm_t *kd, intptr_t tcbaddr)
125 struct inpcbinfo info;
126 struct inpcbportinfo pinfo;
130 kkread(kd, tcbaddr, &info, sizeof(info));
131 kkread(kd, (intptr_t)info.portinfo, &pinfo, sizeof(pinfo));
132 printf(" hashbase %p\n", info.hashbase);
133 printf(" hashmask %ld\n", info.hashmask);
134 printf(" porthashbase %p\n", pinfo.porthashbase);
135 printf(" porthashmask %lu\n", pinfo.porthashmask);
136 printf(" wildcardhashbase %p\n", info.wildcardhashbase);
137 printf(" wildcardhashmask %lu\n", info.wildcardhashmask);
138 printf(" lastport %d\n", (int)pinfo.lastport);
139 printf(" lastlow %d\n", (int)pinfo.lastlow);
140 printf(" lasthi %d\n", (int)pinfo.lasthi);
141 printf(" ipi_size %zu\n", info.ipi_size);
142 printf(" ipi_count %d\n", (int)info.ipi_count);
143 printf(" ipi_gencnt %lld\n", (long long)info.ipi_gencnt);
144 printf(" cpu %d\n", info.cpu);
145 for (i = 0; i <= info.wildcardhashmask; ++i)
146 dumpinpcontainerhead(kd, i, info.wildcardhashbase + i);
151 dumpinpcontainerhead(kvm_t *kd, int index, void *kptr)
153 struct inpcontainerhead head;
154 struct inpcontainer node;
157 kkread(kd, (intptr_t)kptr, &head, sizeof(head));
158 if (head.lh_first == NULL)
160 printf("\tinpcontainer list at index %d {\n", index);
161 for (kptr = head.lh_first; kptr; kptr = node.ic_list.le_next) {
162 kkread(kd, (intptr_t)kptr, &node, sizeof(node));
163 printf("\t inpcontainer %p inpcb %p", kptr, node.ic_inp);
166 kkread(kd, (intptr_t)node.ic_inp, &pcb, sizeof(pcb));
167 printf("\t\tlocal %s:%d foreign %s:%d\n",
168 inet_ntoa(pcb.inp_inc.inc_laddr),
169 ntohs(pcb.inp_inc.inc_lport),
170 inet_ntoa(pcb.inp_inc.inc_faddr),
171 ntohs(pcb.inp_inc.inc_fport));
180 kkread(kvm_t *kd, u_long addr, void *buf, size_t nbytes)
182 if (kvm_read(kd, addr, buf, nbytes) != nbytes) {