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;
128 kkread(kd, tcbaddr, &info, sizeof(info));
129 printf(" hashbase %p\n", info.hashbase);
130 printf(" hashmask %ld\n", info.hashmask);
131 printf(" porthashbase %p\n", info.porthashbase);
132 printf(" porthashmask %lu\n", info.porthashmask);
133 printf(" wildcardhashbase %p\n", info.wildcardhashbase);
134 printf(" wildcardhashmask %lu\n", info.wildcardhashmask);
135 printf(" lastport %d\n", (int)info.lastport);
136 printf(" lastlow %d\n", (int)info.lastlow);
137 printf(" lasthi %d\n", (int)info.lasthi);
138 printf(" ipi_zone %p\n", info.ipi_zone);
139 printf(" ipi_count %d\n", (int)info.ipi_count);
140 printf(" ipi_gencnt %lld\n", (long long)info.ipi_gencnt);
141 printf(" cpu %d\n", info.cpu);
142 for (i = 0; i <= info.wildcardhashmask; ++i)
143 dumpinpcontainerhead(kd, i, info.wildcardhashbase + i);
148 dumpinpcontainerhead(kvm_t *kd, int index, void *kptr)
150 struct inpcontainerhead head;
151 struct inpcontainer node;
154 kkread(kd, (intptr_t)kptr, &head, sizeof(head));
155 if (head.lh_first == NULL)
157 printf("\tinpcontainer list at index %d {\n", index);
158 for (kptr = head.lh_first; kptr; kptr = node.ic_list.le_next) {
159 kkread(kd, (intptr_t)kptr, &node, sizeof(node));
160 printf("\t inpcontainer %p inpcb %p", kptr, node.ic_inp);
163 kkread(kd, (intptr_t)node.ic_inp, &pcb, sizeof(pcb));
164 printf("\t\tlocal %s:%d foreign %s:%d\n",
165 inet_ntoa(pcb.inp_inc.inc_laddr),
166 ntohs(pcb.inp_inc.inc_lport),
167 inet_ntoa(pcb.inp_inc.inc_faddr),
168 ntohs(pcb.inp_inc.inc_fport));
177 kkread(kvm_t *kd, u_long addr, void *buf, size_t nbytes)
179 if (kvm_read(kd, addr, buf, nbytes) != nbytes) {