1 /* $NetBSD: cmdtab.c,v 1.23 2007/02/18 17:00:08 dsl Exp $ */ 2 3 /*- 4 * Copyright (c) 1980, 1992, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. Neither the name of the University nor the names of its contributors 16 * may be used to endorse or promote products derived from this software 17 * without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 */ 31 32 #include <sys/cdefs.h> 33 #ifndef lint 34 #if 0 35 static char sccsid[] = "@(#)cmdtab.c 8.1 (Berkeley) 6/6/93"; 36 #endif 37 __RCSID("$NetBSD: cmdtab.c,v 1.23 2007/02/18 17:00:08 dsl Exp $"); 38 #endif /* not lint */ 39 40 #include "systat.h" 41 #include "extern.h" 42 43 /* 44 * NOTE: if one command is a substring of another, the shorter string 45 * MUST come first, or it will be shadowed by the longer 46 */ 47 48 struct command global_commands[] = { 49 { "help", global_help, "show help"}, 50 { "interval", global_interval, "set update interval"}, 51 { "load", global_load, "show system load averages"}, 52 { "quit", global_quit, "exit systat"}, 53 { "start", global_interval, "restart updating display"}, 54 { "stop", global_stop, "stop updating display"}, 55 { .c_name = NULL } 56 }; 57 58 struct command df_commands[] = { 59 { "all", df_all, "show all filesystems"}, 60 { "some", df_some, "show only some filesystems"}, 61 { .c_name = NULL } 62 }; 63 64 struct command icmp_commands[] = { 65 { "boot", icmp_boot, "show total stats since boot"}, 66 { "run", icmp_run, "show running total stats"}, 67 { "time", icmp_time, "show stats for each sample time"}, 68 { "zero", icmp_zero, "re-zero running totals"}, 69 { .c_name = NULL } 70 }; 71 72 struct command iostat_commands[] = { 73 { "bars", iostat_bars, "show io stats as a bar graph"}, 74 { "numbers", iostat_numbers, "show io stats numerically"}, 75 { "secs", iostat_secs, "include time statistics"}, 76 { "rw", iostat_rw, "show read/write disk stats"}, 77 { "all", iostat_all, "show combined disk stats"}, 78 /* from disks.c */ 79 { "display", disks_add, "add a disk to displayed disks"}, 80 { "ignore", disks_remove, "remove a disk from displayed disks"}, 81 { "drives", disks_drives, "list all disks/set disk list"}, 82 { .c_name = NULL } 83 }; 84 85 struct command ip_commands[] = { 86 { "boot", ip_boot, "show total stats since boot"}, 87 { "run", ip_run, "show running total stats"}, 88 { "time", ip_time, "show stats for each sample time"}, 89 { "zero", ip_zero, "re-zero running totals"}, 90 { .c_name = NULL } 91 }; 92 93 #ifdef INET6 94 struct command ip6_commands[] = { 95 { "boot", ip6_boot, "show total stats since boot"}, 96 { "run", ip6_run, "show running total stats"}, 97 { "time", ip6_time, "show stats for each sample time"}, 98 { "zero", ip6_zero, "re-zero running totals"}, 99 { .c_name = NULL } 100 }; 101 #endif 102 103 #ifdef IPSEC 104 struct command ipsec_commands[] = { 105 { "boot", ipsec_boot, "show total stats since boot"}, 106 { "run", ipsec_run, "show running total stats"}, 107 { "time", ipsec_time, "show stats for each sample time"}, 108 { "zero", ipsec_zero, "re-zero running totals"}, 109 { .c_name = NULL } 110 }; 111 #endif 112 113 struct command netstat_commands[] = { 114 { "all", netstat_all, "include server sockets"}, 115 { "display", netstat_display, "show specified hosts or ports"}, 116 { "ignore", netstat_ignore, "hide specified hosts or ports"}, 117 { "names", netstat_names, "show names instead of addresses"}, 118 { "numbers", netstat_numbers, "show addresses instead of names"}, 119 { "reset", netstat_reset, "return to default display"}, 120 { "show", netstat_show, "show current display/ignore settings"}, 121 { "tcp", netstat_tcp, "show only tcp connections"}, 122 { "udp", netstat_udp, "show only udp connections"}, 123 { .c_name = NULL } 124 }; 125 126 struct command ps_commands[] = { 127 { "user", ps_user, "limit displayed processes to a user"}, 128 { .c_name = NULL } 129 }; 130 131 struct command tcp_commands[] = { 132 { "boot", tcp_boot, "show total stats since boot"}, 133 { "run", tcp_run, "show running total stats"}, 134 { "time", tcp_time, "show stats for each sample time"}, 135 { "zero", tcp_zero, "re-zero running totals"}, 136 { .c_name = NULL } 137 }; 138 139 struct command vmstat_commands[] = { 140 { "boot", vmstat_boot, "show total vm stats since boot"}, 141 { "run", vmstat_run, "show running total vm stats"}, 142 { "time", vmstat_time, "show vm stats for each sample time"}, 143 { "zero", vmstat_zero, "re-zero running totals"}, 144 /* from disks.c */ 145 { "display", disks_add, "add a disk to displayed disks"}, 146 { "ignore", disks_remove, "remove a disk from displayed disks"}, 147 { "drives", disks_drives, "list all disks/set disk list"}, 148 { .c_name = NULL } 149 }; 150 151 struct command syscall_commands[] = { 152 { "boot", syscall_boot, "show total syscall stats since boot"}, 153 { "run", syscall_run, "show running total syscall stats"}, 154 { "time", syscall_time, "show syscall stats for each sample time"}, 155 { "zero", syscall_zero, "re-zero running totals"}, 156 { "sort", syscall_order, "sort by [name|count|syscall]"}, 157 { "show", syscall_show, "show [count|time]"}, 158 { .c_name = NULL } 159 }; 160 161 struct mode modes[] = { 162 /* "pigs" is the default, it must be first. */ 163 { "pigs", showpigs, fetchpigs, labelpigs, 164 initpigs, openpigs, closepigs, 0, 165 CF_LOADAV }, 166 { "bufcache", showbufcache, fetchbufcache, labelbufcache, 167 initbufcache, openbufcache, closebufcache, 0, 168 CF_LOADAV }, 169 { "df", showdf, fetchdf, labeldf, 170 initdf, opendf, closedf, df_commands, 171 CF_LOADAV }, 172 { "inet.icmp", showicmp, fetchicmp, labelicmp, 173 initicmp, openicmp, closeicmp, icmp_commands, 174 CF_LOADAV }, 175 { "inet.ip", showip, fetchip, labelip, 176 initip, openip, closeip, ip_commands, 177 CF_LOADAV }, 178 { "inet.tcp", showtcp, fetchtcp, labeltcp, 179 inittcp, opentcp, closetcp, tcp_commands, 180 CF_LOADAV }, 181 { "inet.tcpsyn",showtcpsyn, fetchtcp, labeltcpsyn, 182 inittcp, opentcp, closetcp, tcp_commands, 183 CF_LOADAV }, 184 #ifdef INET6 185 { "inet6.ip6", showip6, fetchip6, labelip6, 186 initip6, openip6, closeip6, ip6_commands, 187 CF_LOADAV }, 188 #endif 189 #ifdef IPSEC 190 { "ipsec", showipsec, fetchipsec, labelipsec, 191 initipsec, openipsec, closeipsec, ipsec_commands, 192 CF_LOADAV }, 193 #endif 194 { "iostat", showiostat, fetchiostat, labeliostat, 195 initiostat, openiostat, closeiostat, iostat_commands, 196 CF_LOADAV }, 197 { "mbufs", showmbufs, fetchmbufs, labelmbufs, 198 initmbufs, openmbufs, closembufs, 0, 199 CF_LOADAV }, 200 { "netstat", shownetstat, fetchnetstat, labelnetstat, 201 initnetstat, opennetstat, closenetstat, netstat_commands, 202 CF_LOADAV }, 203 { "ps", showps, fetchpigs, labelps, 204 initpigs, openpigs, closepigs, ps_commands, 205 CF_LOADAV }, 206 { "swap", showswap, fetchswap, labelswap, 207 initswap, openswap, closeswap, 0, 208 CF_LOADAV }, 209 { "vmstat", showvmstat, fetchvmstat, labelvmstat, 210 initvmstat, openvmstat, closevmstat, vmstat_commands, 211 0 }, 212 { "syscall", showsyscall, fetchsyscall, labelsyscall, 213 initsyscall, opensyscall, closesyscall, syscall_commands, 214 0 }, 215 { .c_name = NULL } 216 }; 217 struct mode *curmode = &modes[0]; 218