ip.c revision 1.3 1 1.3 msaitoh /* $NetBSD: ip.c,v 1.3 2000/01/04 15:17:00 msaitoh Exp $ */
2 1.1 ad
3 1.1 ad /*
4 1.1 ad * Copyright (c) 1999 Andy Doran <ad (at) NetBSD.org>
5 1.1 ad * All rights reserved.
6 1.1 ad *
7 1.1 ad * Redistribution and use in source and binary forms, with or without
8 1.1 ad * modification, are permitted provided that the following conditions
9 1.1 ad * are met:
10 1.1 ad * 1. Redistributions of source code must retain the above copyright
11 1.1 ad * notice, this list of conditions and the following disclaimer.
12 1.1 ad * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 ad * notice, this list of conditions and the following disclaimer in the
14 1.1 ad * documentation and/or other materials provided with the distribution.
15 1.1 ad *
16 1.1 ad * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 1.1 ad * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 1.1 ad * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 1.1 ad * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 1.1 ad * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 1.1 ad * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 1.1 ad * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.1 ad * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 1.1 ad * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1 ad * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1 ad * SUCH DAMAGE.
27 1.1 ad *
28 1.1 ad */
29 1.1 ad
30 1.1 ad #include <sys/cdefs.h>
31 1.1 ad #ifndef lint
32 1.3 msaitoh __RCSID("$NetBSD: ip.c,v 1.3 2000/01/04 15:17:00 msaitoh Exp $");
33 1.1 ad #endif /* not lint */
34 1.1 ad
35 1.1 ad #include <sys/param.h>
36 1.1 ad #include <sys/types.h>
37 1.1 ad #include <sys/socket.h>
38 1.1 ad #include <sys/sysctl.h>
39 1.1 ad
40 1.1 ad #include <netinet/in.h>
41 1.1 ad #include <netinet/in_systm.h>
42 1.1 ad #include <netinet/ip.h>
43 1.1 ad #include <netinet/ip_var.h>
44 1.1 ad #include <netinet/udp.h>
45 1.1 ad #include <netinet/udp_var.h>
46 1.1 ad
47 1.1 ad #include <stdlib.h>
48 1.1 ad #include <string.h>
49 1.1 ad #include <paths.h>
50 1.1 ad #include <nlist.h>
51 1.1 ad #include <kvm.h>
52 1.1 ad #include "systat.h"
53 1.1 ad #include "extern.h"
54 1.1 ad
55 1.1 ad #define LHD(row, str) mvwprintw(wnd, row, 10, str)
56 1.1 ad #define RHD(row, str) mvwprintw(wnd, row, 45, str);
57 1.3 msaitoh #define SHOW(stat, row, col) mvwprintw(wnd, row, col, "%9llu", curstat.stat)
58 1.1 ad
59 1.1 ad struct mystat {
60 1.1 ad struct ipstat i;
61 1.1 ad struct udpstat u;
62 1.1 ad };
63 1.1 ad
64 1.1 ad static struct mystat curstat;
65 1.1 ad
66 1.1 ad static struct nlist namelist[] = {
67 1.1 ad { "_ipstat" },
68 1.1 ad { "_udpstat" },
69 1.1 ad { "" }
70 1.1 ad };
71 1.1 ad
72 1.1 ad WINDOW *
73 1.1 ad openip(void)
74 1.1 ad {
75 1.1 ad
76 1.1 ad return (subwin(stdscr, LINES-5-1, 0, 5, 0));
77 1.1 ad }
78 1.1 ad
79 1.1 ad void
80 1.1 ad closeip(w)
81 1.1 ad WINDOW *w;
82 1.1 ad {
83 1.1 ad
84 1.1 ad if (w != NULL) {
85 1.1 ad wclear(w);
86 1.1 ad wrefresh(w);
87 1.1 ad delwin(w);
88 1.1 ad }
89 1.1 ad }
90 1.1 ad
91 1.1 ad void
92 1.1 ad labelip(void)
93 1.1 ad {
94 1.2 ad
95 1.1 ad wmove(wnd, 0, 0); wclrtoeol(wnd);
96 1.1 ad
97 1.1 ad LHD(0, "total packets received");
98 1.1 ad LHD(1, " passed to upper layers");
99 1.1 ad LHD(2, " with bad checksums");
100 1.1 ad LHD(3, " too short for header");
101 1.1 ad LHD(4, " too short for data");
102 1.1 ad LHD(5, " with invalid hlen");
103 1.1 ad LHD(6, " with invalid length");
104 1.1 ad LHD(7, " with invalid version");
105 1.1 ad LHD(8, " too large");
106 1.1 ad LHD(9, " option errors");
107 1.1 ad LHD(10, " fragments received");
108 1.1 ad LHD(11, " fragments dropped");
109 1.1 ad LHD(12, " fragments timed out");
110 1.1 ad LHD(13, " packets reassembled ok");
111 1.1 ad
112 1.1 ad LHD(15, "packets forwarded");
113 1.1 ad LHD(16, " fast forwarded");
114 1.1 ad LHD(17, " unreachable dests");
115 1.1 ad LHD(18, " redirects generated");
116 1.1 ad
117 1.1 ad RHD(0, "total packets sent");
118 1.1 ad RHD(1, " generated locally");
119 1.1 ad RHD(2, " output drops");
120 1.1 ad RHD(3, " output fragments generated");
121 1.1 ad RHD(4, " fragmentation failed");
122 1.1 ad RHD(5, " destinations unreachable");
123 1.1 ad RHD(6, " packets output via raw IP");
124 1.1 ad RHD(7, " total UDP packets sent");
125 1.1 ad
126 1.1 ad RHD(9, "total UDP packets recieved");
127 1.1 ad RHD(10, " too short for header");
128 1.1 ad RHD(11, " invalid checksum");
129 1.1 ad RHD(12, " invalid length");
130 1.1 ad RHD(13, " no socket for dest port");
131 1.1 ad RHD(14, " no socket for broadcast");
132 1.1 ad RHD(15, " socket buffer full");
133 1.1 ad }
134 1.1 ad
135 1.1 ad void
136 1.1 ad showip(void)
137 1.1 ad {
138 1.3 msaitoh u_quad_t totalout;
139 1.1 ad
140 1.1 ad totalout = curstat.i.ips_forward + curstat.i.ips_localout;
141 1.1 ad
142 1.1 ad SHOW(i.ips_total, 0, 0);
143 1.3 msaitoh mvwprintw(wnd, 0, 35, "%9llu", totalout);
144 1.1 ad SHOW(i.ips_delivered, 1, 0);
145 1.1 ad SHOW(i.ips_badsum, 2, 0);
146 1.1 ad SHOW(i.ips_tooshort, 3, 0);
147 1.1 ad SHOW(i.ips_toosmall, 4, 0);
148 1.1 ad SHOW(i.ips_badhlen, 5, 0);
149 1.1 ad SHOW(i.ips_badlen, 6, 0);
150 1.1 ad SHOW(i.ips_badvers, 7, 0);
151 1.1 ad SHOW(i.ips_toolong, 8, 0);
152 1.1 ad SHOW(i.ips_badoptions, 9, 0);
153 1.1 ad
154 1.1 ad SHOW(i.ips_localout, 1, 35);
155 1.1 ad SHOW(i.ips_odropped, 2, 35);
156 1.1 ad SHOW(i.ips_ofragments, 3, 35);
157 1.1 ad SHOW(i.ips_cantfrag, 4, 35);
158 1.1 ad SHOW(i.ips_noroute, 5, 35);
159 1.1 ad SHOW(i.ips_rawout, 6, 35);
160 1.1 ad SHOW(u.udps_opackets, 7, 35);
161 1.1 ad
162 1.1 ad SHOW(i.ips_fragments, 10, 0);
163 1.1 ad SHOW(i.ips_fragdropped, 11, 0);
164 1.1 ad SHOW(i.ips_fragtimeout, 12, 0);
165 1.1 ad SHOW(i.ips_reassembled, 13, 0);
166 1.1 ad
167 1.1 ad SHOW(i.ips_forward, 15, 0);
168 1.1 ad SHOW(i.ips_fastforward, 16, 0);
169 1.1 ad SHOW(i.ips_cantforward, 17, 0);
170 1.1 ad SHOW(i.ips_redirectsent, 18, 0);
171 1.1 ad
172 1.1 ad SHOW(u.udps_ipackets, 9, 35);
173 1.1 ad SHOW(u.udps_hdrops, 10, 35);
174 1.1 ad SHOW(u.udps_badsum, 11, 35);
175 1.1 ad SHOW(u.udps_badlen, 12, 35);
176 1.1 ad SHOW(u.udps_noport, 13, 35);
177 1.1 ad SHOW(u.udps_noportbcast, 14, 35);
178 1.1 ad SHOW(u.udps_fullsock, 15, 35);
179 1.1 ad }
180 1.1 ad
181 1.1 ad int
182 1.1 ad initip(void)
183 1.1 ad {
184 1.2 ad
185 1.1 ad if (namelist[0].n_type == 0) {
186 1.1 ad if (kvm_nlist(kd, namelist)) {
187 1.1 ad nlisterr(namelist);
188 1.1 ad return(0);
189 1.1 ad }
190 1.1 ad if ((namelist[0].n_type | namelist[1].n_type) == 0) {
191 1.1 ad error("No namelist");
192 1.1 ad return(0);
193 1.1 ad }
194 1.1 ad }
195 1.1 ad return 1;
196 1.1 ad }
197 1.1 ad
198 1.1 ad void
199 1.1 ad fetchip(void)
200 1.1 ad {
201 1.2 ad
202 1.1 ad KREAD((void *)namelist[0].n_value, &curstat.i, sizeof(curstat.i));
203 1.1 ad KREAD((void *)namelist[1].n_value, &curstat.u, sizeof(curstat.u));
204 1.1 ad }
205