sysctl.c revision 1.24 1 1.24 itojun /* $NetBSD: sysctl.c,v 1.24 2000/02/06 11:12:40 itojun Exp $ */
2 1.9 thorpej
3 1.1 cgd /*
4 1.1 cgd * Copyright (c) 1993
5 1.1 cgd * The Regents of the University of California. All rights reserved.
6 1.1 cgd *
7 1.1 cgd * Redistribution and use in source and binary forms, with or without
8 1.1 cgd * modification, are permitted provided that the following conditions
9 1.1 cgd * are met:
10 1.1 cgd * 1. Redistributions of source code must retain the above copyright
11 1.1 cgd * notice, this list of conditions and the following disclaimer.
12 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 cgd * notice, this list of conditions and the following disclaimer in the
14 1.1 cgd * documentation and/or other materials provided with the distribution.
15 1.1 cgd * 3. All advertising materials mentioning features or use of this software
16 1.1 cgd * must display the following acknowledgement:
17 1.1 cgd * This product includes software developed by the University of
18 1.1 cgd * California, Berkeley and its contributors.
19 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
20 1.1 cgd * may be used to endorse or promote products derived from this software
21 1.1 cgd * without specific prior written permission.
22 1.1 cgd *
23 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.1 cgd * SUCH DAMAGE.
34 1.1 cgd */
35 1.1 cgd
36 1.14 christos #include <sys/cdefs.h>
37 1.1 cgd #ifndef lint
38 1.14 christos __COPYRIGHT(
39 1.1 cgd "@(#) Copyright (c) 1993\n\
40 1.14 christos The Regents of the University of California. All rights reserved.\n");
41 1.1 cgd #endif /* not lint */
42 1.1 cgd
43 1.1 cgd #ifndef lint
44 1.9 thorpej #if 0
45 1.9 thorpej static char sccsid[] = "@(#)sysctl.c 8.1 (Berkeley) 6/6/93";
46 1.9 thorpej #else
47 1.24 itojun __RCSID("$NetBSD: sysctl.c,v 1.24 2000/02/06 11:12:40 itojun Exp $");
48 1.9 thorpej #endif
49 1.1 cgd #endif /* not lint */
50 1.1 cgd
51 1.1 cgd #include <sys/param.h>
52 1.1 cgd #include <sys/gmon.h>
53 1.1 cgd #include <sys/stat.h>
54 1.1 cgd #include <sys/sysctl.h>
55 1.1 cgd #include <sys/socket.h>
56 1.17 thorpej #include <sys/mount.h>
57 1.19 thorpej #include <sys/mbuf.h>
58 1.22 bouyer #include <sys/resource.h>
59 1.1 cgd #include <vm/vm_param.h>
60 1.1 cgd #include <machine/cpu.h>
61 1.1 cgd
62 1.17 thorpej #include <ufs/ufs/dinode.h>
63 1.17 thorpej #include <ufs/ufs/dir.h>
64 1.17 thorpej #include <ufs/ffs/fs.h>
65 1.17 thorpej #include <ufs/ffs/ffs_extern.h>
66 1.17 thorpej
67 1.17 thorpej #include <nfs/rpcv2.h>
68 1.17 thorpej #include <nfs/nfsproto.h>
69 1.17 thorpej #include <nfs/nfs.h>
70 1.17 thorpej
71 1.1 cgd #include <netinet/in.h>
72 1.1 cgd #include <netinet/in_systm.h>
73 1.1 cgd #include <netinet/ip.h>
74 1.1 cgd #include <netinet/ip_icmp.h>
75 1.1 cgd #include <netinet/icmp_var.h>
76 1.1 cgd #include <netinet/ip_var.h>
77 1.1 cgd #include <netinet/udp.h>
78 1.1 cgd #include <netinet/udp_var.h>
79 1.8 thorpej #include <netinet/tcp.h>
80 1.8 thorpej #include <netinet/tcp_timer.h>
81 1.8 thorpej #include <netinet/tcp_var.h>
82 1.1 cgd
83 1.20 itojun #ifdef INET6
84 1.24 itojun #include <netinet/ip6.h>
85 1.24 itojun #include <netinet/icmp6.h>
86 1.20 itojun #include <netinet6/ip6_var.h>
87 1.20 itojun #include <netinet6/udp6.h>
88 1.20 itojun #include <netinet6/udp6_var.h>
89 1.20 itojun #ifdef TCP6
90 1.20 itojun #include <netinet6/tcp6.h>
91 1.20 itojun #include <netinet6/tcp6_timer.h>
92 1.20 itojun #include <netinet6/tcp6_var.h>
93 1.20 itojun #endif
94 1.20 itojun #include <netinet6/pim6_var.h>
95 1.20 itojun #endif /* INET6 */
96 1.20 itojun
97 1.20 itojun #ifdef IPSEC
98 1.20 itojun #include <net/route.h>
99 1.20 itojun #include <netinet6/ipsec.h>
100 1.20 itojun #include <netkey/key_var.h>
101 1.20 itojun #endif /* IPSEC */
102 1.20 itojun
103 1.14 christos #include <err.h>
104 1.14 christos #include <ctype.h>
105 1.1 cgd #include <errno.h>
106 1.1 cgd #include <stdio.h>
107 1.1 cgd #include <stdlib.h>
108 1.1 cgd #include <string.h>
109 1.15 tron #include <unistd.h>
110 1.1 cgd
111 1.1 cgd struct ctlname topname[] = CTL_NAMES;
112 1.1 cgd struct ctlname kernname[] = CTL_KERN_NAMES;
113 1.1 cgd struct ctlname vmname[] = CTL_VM_NAMES;
114 1.17 thorpej struct ctlname vfsname[] = CTL_VFS_NAMES;
115 1.1 cgd struct ctlname netname[] = CTL_NET_NAMES;
116 1.1 cgd struct ctlname hwname[] = CTL_HW_NAMES;
117 1.1 cgd struct ctlname username[] = CTL_USER_NAMES;
118 1.10 thorpej struct ctlname ddbname[] = CTL_DDB_NAMES;
119 1.1 cgd struct ctlname debugname[CTL_DEBUG_MAXID];
120 1.1 cgd #ifdef CTL_MACHDEP_NAMES
121 1.1 cgd struct ctlname machdepname[] = CTL_MACHDEP_NAMES;
122 1.1 cgd #endif
123 1.22 bouyer /* this one is dummy, it's used only for '-a' or '-A' */
124 1.22 bouyer struct ctlname procname[] = { {0, 0}, {"curproc", CTLTYPE_NODE} };
125 1.22 bouyer
126 1.1 cgd char names[BUFSIZ];
127 1.1 cgd
128 1.1 cgd struct list {
129 1.1 cgd struct ctlname *list;
130 1.1 cgd int size;
131 1.1 cgd };
132 1.1 cgd struct list toplist = { topname, CTL_MAXID };
133 1.1 cgd struct list secondlevel[] = {
134 1.1 cgd { 0, 0 }, /* CTL_UNSPEC */
135 1.1 cgd { kernname, KERN_MAXID }, /* CTL_KERN */
136 1.1 cgd { vmname, VM_MAXID }, /* CTL_VM */
137 1.17 thorpej { vfsname, VFS_MAXID }, /* CTL_VFS */
138 1.1 cgd { netname, NET_MAXID }, /* CTL_NET */
139 1.1 cgd { 0, CTL_DEBUG_MAXID }, /* CTL_DEBUG */
140 1.1 cgd { hwname, HW_MAXID }, /* CTL_HW */
141 1.1 cgd #ifdef CTL_MACHDEP_NAMES
142 1.1 cgd { machdepname, CPU_MAXID }, /* CTL_MACHDEP */
143 1.1 cgd #else
144 1.1 cgd { 0, 0 }, /* CTL_MACHDEP */
145 1.1 cgd #endif
146 1.1 cgd { username, USER_MAXID }, /* CTL_USER_NAMES */
147 1.10 thorpej { ddbname, DDBCTL_MAXID }, /* CTL_DDB_NAMES */
148 1.22 bouyer { procname, 2 }, /* dummy name */
149 1.1 cgd };
150 1.1 cgd
151 1.1 cgd int Aflag, aflag, nflag, wflag;
152 1.1 cgd
153 1.1 cgd /*
154 1.1 cgd * Variables requiring special processing.
155 1.1 cgd */
156 1.1 cgd #define CLOCK 0x00000001
157 1.1 cgd #define BOOTTIME 0x00000002
158 1.1 cgd #define CONSDEV 0x00000004
159 1.1 cgd
160 1.22 bouyer /*
161 1.22 bouyer * A dummy type for limits, which requires special parsing
162 1.22 bouyer */
163 1.22 bouyer #define CTLTYPE_LIMIT ((~0x1) << 31)
164 1.22 bouyer
165 1.14 christos int main __P((int, char *[]));
166 1.14 christos
167 1.14 christos static void listall __P((char *, struct list *));
168 1.14 christos static void parse __P((char *, int));
169 1.14 christos static void debuginit __P((void));
170 1.14 christos static int sysctl_inet __P((char *, char **, int[], int, int *));
171 1.20 itojun #ifdef INET6
172 1.20 itojun static int sysctl_inet6 __P((char *, char **, int[], int, int *));
173 1.20 itojun #endif
174 1.20 itojun #ifdef IPSEC
175 1.20 itojun static int sysctl_key __P((char *, char **, int[], int, int *));
176 1.20 itojun #endif
177 1.17 thorpej static int sysctl_vfs __P((char *, char **, int[], int, int *));
178 1.17 thorpej static int sysctl_vfsgen __P((char *, char **, int[], int, int *));
179 1.19 thorpej static int sysctl_mbuf __P((char *, char **, int[], int, int *));
180 1.22 bouyer static int sysctl_proc __P((char *, char **, int[], int, int *));
181 1.14 christos static int findname __P((char *, char *, char **, struct list *));
182 1.14 christos static void usage __P((void));
183 1.14 christos
184 1.1 cgd int
185 1.1 cgd main(argc, argv)
186 1.1 cgd int argc;
187 1.1 cgd char *argv[];
188 1.1 cgd {
189 1.1 cgd extern char *optarg;
190 1.1 cgd extern int optind;
191 1.1 cgd int ch, lvl1;
192 1.1 cgd
193 1.11 lukem while ((ch = getopt(argc, argv, "Aanw")) != -1) {
194 1.1 cgd switch (ch) {
195 1.1 cgd
196 1.1 cgd case 'A':
197 1.1 cgd Aflag = 1;
198 1.1 cgd break;
199 1.1 cgd
200 1.1 cgd case 'a':
201 1.1 cgd aflag = 1;
202 1.1 cgd break;
203 1.1 cgd
204 1.1 cgd case 'n':
205 1.1 cgd nflag = 1;
206 1.1 cgd break;
207 1.1 cgd
208 1.1 cgd case 'w':
209 1.1 cgd wflag = 1;
210 1.1 cgd break;
211 1.1 cgd
212 1.1 cgd default:
213 1.1 cgd usage();
214 1.1 cgd }
215 1.1 cgd }
216 1.1 cgd argc -= optind;
217 1.1 cgd argv += optind;
218 1.1 cgd
219 1.1 cgd if (Aflag || aflag) {
220 1.1 cgd debuginit();
221 1.1 cgd for (lvl1 = 1; lvl1 < CTL_MAXID; lvl1++)
222 1.1 cgd listall(topname[lvl1].ctl_name, &secondlevel[lvl1]);
223 1.14 christos return 0;
224 1.1 cgd }
225 1.1 cgd if (argc == 0)
226 1.1 cgd usage();
227 1.1 cgd while (argc-- > 0)
228 1.2 cgd parse(*argv++, 1);
229 1.14 christos return 0;
230 1.1 cgd }
231 1.1 cgd
232 1.1 cgd /*
233 1.1 cgd * List all variables known to the system.
234 1.1 cgd */
235 1.14 christos static void
236 1.1 cgd listall(prefix, lp)
237 1.1 cgd char *prefix;
238 1.1 cgd struct list *lp;
239 1.1 cgd {
240 1.1 cgd int lvl2;
241 1.1 cgd char *cp, name[BUFSIZ];
242 1.1 cgd
243 1.1 cgd if (lp->list == 0)
244 1.1 cgd return;
245 1.1 cgd strcpy(name, prefix);
246 1.1 cgd cp = &name[strlen(name)];
247 1.1 cgd *cp++ = '.';
248 1.1 cgd for (lvl2 = 0; lvl2 < lp->size; lvl2++) {
249 1.1 cgd if (lp->list[lvl2].ctl_name == 0)
250 1.1 cgd continue;
251 1.1 cgd strcpy(cp, lp->list[lvl2].ctl_name);
252 1.1 cgd parse(name, Aflag);
253 1.1 cgd }
254 1.1 cgd }
255 1.1 cgd
256 1.1 cgd /*
257 1.1 cgd * Parse a name into a MIB entry.
258 1.1 cgd * Lookup and print out the MIB entry if it exists.
259 1.1 cgd * Set a new value if requested.
260 1.1 cgd */
261 1.14 christos static void
262 1.1 cgd parse(string, flags)
263 1.1 cgd char *string;
264 1.1 cgd int flags;
265 1.1 cgd {
266 1.5 cgd int indx, type, state, len;
267 1.1 cgd int special = 0;
268 1.1 cgd void *newval = 0;
269 1.1 cgd int intval, newsize = 0;
270 1.1 cgd quad_t quadval;
271 1.5 cgd size_t size;
272 1.1 cgd struct list *lp;
273 1.1 cgd int mib[CTL_MAXNAME];
274 1.14 christos char *cp, *bufp, buf[BUFSIZ];
275 1.1 cgd
276 1.1 cgd bufp = buf;
277 1.1 cgd snprintf(buf, BUFSIZ, "%s", string);
278 1.1 cgd if ((cp = strchr(string, '=')) != NULL) {
279 1.14 christos if (!wflag)
280 1.14 christos errx(2, "Must specify -w to set variables");
281 1.1 cgd *strchr(buf, '=') = '\0';
282 1.1 cgd *cp++ = '\0';
283 1.14 christos while (isspace((unsigned char) *cp))
284 1.1 cgd cp++;
285 1.1 cgd newval = cp;
286 1.1 cgd newsize = strlen(cp);
287 1.1 cgd }
288 1.1 cgd if ((indx = findname(string, "top", &bufp, &toplist)) == -1)
289 1.1 cgd return;
290 1.1 cgd mib[0] = indx;
291 1.1 cgd if (indx == CTL_DEBUG)
292 1.1 cgd debuginit();
293 1.22 bouyer if (mib[0] == CTL_PROC) {
294 1.22 bouyer type = CTLTYPE_NODE;
295 1.22 bouyer len = 1;
296 1.22 bouyer } else {
297 1.22 bouyer lp = &secondlevel[indx];
298 1.22 bouyer if (lp->list == 0) {
299 1.22 bouyer warnx("Class `%s' is not implemented",
300 1.22 bouyer topname[indx].ctl_name);
301 1.22 bouyer return;
302 1.22 bouyer }
303 1.22 bouyer if (bufp == NULL) {
304 1.22 bouyer listall(topname[indx].ctl_name, lp);
305 1.22 bouyer return;
306 1.22 bouyer }
307 1.22 bouyer if ((indx = findname(string, "second", &bufp, lp)) == -1)
308 1.22 bouyer return;
309 1.22 bouyer mib[1] = indx;
310 1.22 bouyer type = lp->list[indx].ctl_type;
311 1.22 bouyer len = 2;
312 1.1 cgd }
313 1.1 cgd switch (mib[0]) {
314 1.1 cgd
315 1.1 cgd case CTL_KERN:
316 1.1 cgd switch (mib[1]) {
317 1.1 cgd case KERN_PROF:
318 1.1 cgd mib[2] = GPROF_STATE;
319 1.1 cgd size = sizeof state;
320 1.1 cgd if (sysctl(mib, 3, &state, &size, NULL, 0) < 0) {
321 1.1 cgd if (flags == 0)
322 1.1 cgd return;
323 1.1 cgd if (!nflag)
324 1.1 cgd fprintf(stdout, "%s: ", string);
325 1.14 christos warnx("Kernel is not compiled for profiling");
326 1.1 cgd return;
327 1.1 cgd }
328 1.1 cgd if (!nflag)
329 1.1 cgd fprintf(stdout, "%s: %s\n", string,
330 1.1 cgd state == GMON_PROF_OFF ? "off" : "running");
331 1.1 cgd return;
332 1.1 cgd case KERN_VNODE:
333 1.1 cgd case KERN_FILE:
334 1.1 cgd if (flags == 0)
335 1.1 cgd return;
336 1.14 christos warnx("Use pstat to view %s information", string);
337 1.1 cgd return;
338 1.1 cgd case KERN_PROC:
339 1.1 cgd if (flags == 0)
340 1.1 cgd return;
341 1.14 christos warnx("Use ps to view %s information", string);
342 1.1 cgd return;
343 1.1 cgd case KERN_CLOCKRATE:
344 1.1 cgd special |= CLOCK;
345 1.1 cgd break;
346 1.1 cgd case KERN_BOOTTIME:
347 1.1 cgd special |= BOOTTIME;
348 1.1 cgd break;
349 1.12 jonathan case KERN_NTPTIME:
350 1.12 jonathan if (flags == 0)
351 1.12 jonathan return;
352 1.14 christos warnx("Use xntpdc -c kerninfo to view %s information",
353 1.12 jonathan string);
354 1.12 jonathan return;
355 1.19 thorpej case KERN_MBUF:
356 1.19 thorpej len = sysctl_mbuf(string, &bufp, mib, flags, &type);
357 1.19 thorpej if (len < 0)
358 1.19 thorpej return;
359 1.19 thorpej break;
360 1.1 cgd }
361 1.1 cgd break;
362 1.1 cgd
363 1.1 cgd case CTL_HW:
364 1.1 cgd break;
365 1.1 cgd
366 1.1 cgd case CTL_VM:
367 1.1 cgd if (mib[1] == VM_LOADAVG) {
368 1.1 cgd double loads[3];
369 1.1 cgd
370 1.1 cgd getloadavg(loads, 3);
371 1.1 cgd if (!nflag)
372 1.1 cgd fprintf(stdout, "%s: ", string);
373 1.1 cgd fprintf(stdout, "%.2f %.2f %.2f\n",
374 1.1 cgd loads[0], loads[1], loads[2]);
375 1.1 cgd return;
376 1.1 cgd }
377 1.1 cgd if (flags == 0)
378 1.1 cgd return;
379 1.14 christos warnx("Use vmstat or systat to view %s information", string);
380 1.1 cgd return;
381 1.1 cgd
382 1.1 cgd case CTL_NET:
383 1.1 cgd if (mib[1] == PF_INET) {
384 1.1 cgd len = sysctl_inet(string, &bufp, mib, flags, &type);
385 1.1 cgd if (len >= 0)
386 1.1 cgd break;
387 1.1 cgd return;
388 1.1 cgd }
389 1.20 itojun #ifdef INET6
390 1.20 itojun else if (mib[1] == PF_INET6) {
391 1.20 itojun len = sysctl_inet6(string, &bufp, mib, flags, &type);
392 1.20 itojun if (len >= 0)
393 1.20 itojun break;
394 1.20 itojun return;
395 1.20 itojun }
396 1.20 itojun #endif /* INET6 */
397 1.20 itojun #ifdef IPSEC
398 1.20 itojun else if (mib[1] == PF_KEY) {
399 1.20 itojun len = sysctl_key(string, &bufp, mib, flags, &type);
400 1.20 itojun if (len >= 0)
401 1.20 itojun break;
402 1.20 itojun return;
403 1.20 itojun }
404 1.20 itojun #endif /* IPSEC */
405 1.1 cgd if (flags == 0)
406 1.1 cgd return;
407 1.14 christos warnx("Use netstat to view %s information", string);
408 1.1 cgd return;
409 1.1 cgd
410 1.1 cgd case CTL_DEBUG:
411 1.1 cgd mib[2] = CTL_DEBUG_VALUE;
412 1.1 cgd len = 3;
413 1.1 cgd break;
414 1.1 cgd
415 1.1 cgd case CTL_MACHDEP:
416 1.1 cgd #ifdef CPU_CONSDEV
417 1.1 cgd if (mib[1] == CPU_CONSDEV)
418 1.1 cgd special |= CONSDEV;
419 1.1 cgd #endif
420 1.1 cgd break;
421 1.1 cgd
422 1.13 fvdl case CTL_VFS:
423 1.17 thorpej if (mib[1] == VFS_GENERIC)
424 1.17 thorpej len = sysctl_vfsgen(string, &bufp, mib, flags, &type);
425 1.17 thorpej else
426 1.17 thorpej len = sysctl_vfs(string, &bufp, mib, flags, &type);
427 1.18 thorpej if (len < 0)
428 1.18 thorpej return;
429 1.18 thorpej
430 1.18 thorpej /* XXX Special-case for NFS stats. */
431 1.18 thorpej if (mib[1] == 2 && mib[2] == NFS_NFSSTATS) {
432 1.18 thorpej if (flags == 0)
433 1.18 thorpej return;
434 1.18 thorpej warnx("Use nfsstat to view %s information", string);
435 1.18 thorpej return;
436 1.18 thorpej }
437 1.18 thorpej break;
438 1.17 thorpej
439 1.1 cgd case CTL_USER:
440 1.10 thorpej case CTL_DDB:
441 1.1 cgd break;
442 1.22 bouyer case CTL_PROC:
443 1.22 bouyer len = sysctl_proc(string, &bufp, mib, flags, &type);
444 1.22 bouyer if (len < 0)
445 1.22 bouyer return;
446 1.22 bouyer break;
447 1.1 cgd default:
448 1.14 christos warnx("Illegal top level value: %d", mib[0]);
449 1.1 cgd return;
450 1.1 cgd
451 1.1 cgd }
452 1.1 cgd if (bufp) {
453 1.14 christos warnx("Name %s in %s is unknown", bufp, string);
454 1.1 cgd return;
455 1.1 cgd }
456 1.1 cgd if (newsize > 0) {
457 1.1 cgd switch (type) {
458 1.1 cgd case CTLTYPE_INT:
459 1.1 cgd intval = atoi(newval);
460 1.1 cgd newval = &intval;
461 1.1 cgd newsize = sizeof intval;
462 1.1 cgd break;
463 1.1 cgd
464 1.22 bouyer case CTLTYPE_LIMIT:
465 1.22 bouyer if (strcmp(newval, "unlimited") == 0) {
466 1.22 bouyer quadval = RLIM_INFINITY;
467 1.22 bouyer newval = &quadval;
468 1.22 bouyer newsize = sizeof quadval;
469 1.22 bouyer break;
470 1.22 bouyer }
471 1.22 bouyer /* FALLTHROUGH */
472 1.1 cgd case CTLTYPE_QUAD:
473 1.16 thorpej sscanf(newval, "%qd", (long long *)&quadval);
474 1.1 cgd newval = &quadval;
475 1.1 cgd newsize = sizeof quadval;
476 1.1 cgd break;
477 1.1 cgd }
478 1.1 cgd }
479 1.1 cgd size = BUFSIZ;
480 1.1 cgd if (sysctl(mib, len, buf, &size, newsize ? newval : 0, newsize) == -1) {
481 1.1 cgd if (flags == 0)
482 1.1 cgd return;
483 1.1 cgd switch (errno) {
484 1.1 cgd case EOPNOTSUPP:
485 1.14 christos warnx("The value of %s is not available", string);
486 1.1 cgd return;
487 1.1 cgd case ENOTDIR:
488 1.14 christos warnx("The specification of %s is incomplete",
489 1.1 cgd string);
490 1.1 cgd return;
491 1.1 cgd case ENOMEM:
492 1.14 christos warnx("The type %s is unknown to this program",
493 1.1 cgd string);
494 1.1 cgd return;
495 1.1 cgd default:
496 1.14 christos warn("sysctl() for %s failed", string);
497 1.1 cgd return;
498 1.1 cgd }
499 1.1 cgd }
500 1.1 cgd if (special & CLOCK) {
501 1.1 cgd struct clockinfo *clkp = (struct clockinfo *)buf;
502 1.1 cgd
503 1.1 cgd if (!nflag)
504 1.1 cgd fprintf(stdout, "%s: ", string);
505 1.1 cgd fprintf(stdout,
506 1.4 mycroft "tick = %d, tickadj = %d, hz = %d, profhz = %d, stathz = %d\n",
507 1.4 mycroft clkp->tick, clkp->tickadj, clkp->hz, clkp->profhz, clkp->stathz);
508 1.1 cgd return;
509 1.1 cgd }
510 1.1 cgd if (special & BOOTTIME) {
511 1.1 cgd struct timeval *btp = (struct timeval *)buf;
512 1.7 cgd time_t boottime;
513 1.1 cgd
514 1.7 cgd if (!nflag) {
515 1.7 cgd boottime = btp->tv_sec;
516 1.7 cgd fprintf(stdout, "%s = %s\n", string, ctime(&boottime));
517 1.7 cgd } else
518 1.14 christos fprintf(stdout, "%ld\n", (long) btp->tv_sec);
519 1.1 cgd return;
520 1.1 cgd }
521 1.1 cgd if (special & CONSDEV) {
522 1.1 cgd dev_t dev = *(dev_t *)buf;
523 1.1 cgd
524 1.1 cgd if (!nflag)
525 1.1 cgd fprintf(stdout, "%s = %s\n", string,
526 1.1 cgd devname(dev, S_IFCHR));
527 1.1 cgd else
528 1.1 cgd fprintf(stdout, "0x%x\n", dev);
529 1.1 cgd return;
530 1.1 cgd }
531 1.1 cgd switch (type) {
532 1.1 cgd case CTLTYPE_INT:
533 1.1 cgd if (newsize == 0) {
534 1.1 cgd if (!nflag)
535 1.1 cgd fprintf(stdout, "%s = ", string);
536 1.1 cgd fprintf(stdout, "%d\n", *(int *)buf);
537 1.1 cgd } else {
538 1.1 cgd if (!nflag)
539 1.1 cgd fprintf(stdout, "%s: %d -> ", string,
540 1.1 cgd *(int *)buf);
541 1.1 cgd fprintf(stdout, "%d\n", *(int *)newval);
542 1.1 cgd }
543 1.1 cgd return;
544 1.1 cgd
545 1.1 cgd case CTLTYPE_STRING:
546 1.1 cgd if (newsize == 0) {
547 1.1 cgd if (!nflag)
548 1.1 cgd fprintf(stdout, "%s = ", string);
549 1.1 cgd fprintf(stdout, "%s\n", buf);
550 1.1 cgd } else {
551 1.1 cgd if (!nflag)
552 1.1 cgd fprintf(stdout, "%s: %s -> ", string, buf);
553 1.14 christos fprintf(stdout, "%s\n", (char *) newval);
554 1.1 cgd }
555 1.1 cgd return;
556 1.1 cgd
557 1.22 bouyer case CTLTYPE_LIMIT:
558 1.22 bouyer #define PRINTF_LIMIT(lim) { \
559 1.22 bouyer if ((lim) == RLIM_INFINITY) \
560 1.22 bouyer fprintf(stdout, "unlimited");\
561 1.22 bouyer else \
562 1.22 bouyer fprintf(stdout, "%qd", (lim)); \
563 1.22 bouyer }
564 1.22 bouyer
565 1.22 bouyer if (newsize == 0) {
566 1.22 bouyer if (!nflag)
567 1.22 bouyer fprintf(stdout, "%s = ", string);
568 1.22 bouyer PRINTF_LIMIT((long long)(*(quad_t *)buf));
569 1.22 bouyer } else {
570 1.22 bouyer if (!nflag) {
571 1.22 bouyer fprintf(stdout, "%s: ", string);
572 1.22 bouyer PRINTF_LIMIT((long long)(*(quad_t *)buf));
573 1.22 bouyer fprintf(stdout, " -> ");
574 1.22 bouyer }
575 1.22 bouyer PRINTF_LIMIT((long long)(*(quad_t *)newval));
576 1.22 bouyer }
577 1.22 bouyer fprintf(stdout, "\n");
578 1.22 bouyer return;
579 1.22 bouyer #undef PRINTF_LIMIT
580 1.22 bouyer
581 1.1 cgd case CTLTYPE_QUAD:
582 1.1 cgd if (newsize == 0) {
583 1.1 cgd if (!nflag)
584 1.1 cgd fprintf(stdout, "%s = ", string);
585 1.16 thorpej fprintf(stdout, "%qd\n", (long long)(*(quad_t *)buf));
586 1.1 cgd } else {
587 1.1 cgd if (!nflag)
588 1.1 cgd fprintf(stdout, "%s: %qd -> ", string,
589 1.16 thorpej (long long)(*(quad_t *)buf));
590 1.16 thorpej fprintf(stdout, "%qd\n",
591 1.16 thorpej (long long)(*(quad_t *)newval));
592 1.1 cgd }
593 1.1 cgd return;
594 1.1 cgd
595 1.1 cgd case CTLTYPE_STRUCT:
596 1.14 christos warnx("%s: unknown structure returned", string);
597 1.1 cgd return;
598 1.1 cgd
599 1.1 cgd default:
600 1.1 cgd case CTLTYPE_NODE:
601 1.14 christos warnx("%s: unknown type returned", string);
602 1.1 cgd return;
603 1.1 cgd }
604 1.1 cgd }
605 1.1 cgd
606 1.1 cgd /*
607 1.1 cgd * Initialize the set of debugging names
608 1.1 cgd */
609 1.14 christos static void
610 1.1 cgd debuginit()
611 1.1 cgd {
612 1.5 cgd int mib[3], loc, i;
613 1.5 cgd size_t size;
614 1.1 cgd
615 1.1 cgd if (secondlevel[CTL_DEBUG].list != 0)
616 1.1 cgd return;
617 1.1 cgd secondlevel[CTL_DEBUG].list = debugname;
618 1.1 cgd mib[0] = CTL_DEBUG;
619 1.1 cgd mib[2] = CTL_DEBUG_NAME;
620 1.1 cgd for (loc = 0, i = 0; i < CTL_DEBUG_MAXID; i++) {
621 1.1 cgd mib[1] = i;
622 1.1 cgd size = BUFSIZ - loc;
623 1.1 cgd if (sysctl(mib, 3, &names[loc], &size, NULL, 0) == -1)
624 1.1 cgd continue;
625 1.1 cgd debugname[i].ctl_name = &names[loc];
626 1.1 cgd debugname[i].ctl_type = CTLTYPE_INT;
627 1.1 cgd loc += size;
628 1.1 cgd }
629 1.1 cgd }
630 1.1 cgd
631 1.1 cgd struct ctlname inetname[] = CTL_IPPROTO_NAMES;
632 1.1 cgd struct ctlname ipname[] = IPCTL_NAMES;
633 1.1 cgd struct ctlname icmpname[] = ICMPCTL_NAMES;
634 1.8 thorpej struct ctlname tcpname[] = TCPCTL_NAMES;
635 1.1 cgd struct ctlname udpname[] = UDPCTL_NAMES;
636 1.20 itojun #ifdef IPSEC
637 1.20 itojun struct ctlname ipsecname[] = IPSECCTL_NAMES;
638 1.20 itojun #endif
639 1.1 cgd struct list inetlist = { inetname, IPPROTO_MAXID };
640 1.1 cgd struct list inetvars[] = {
641 1.20 itojun /*0*/ { ipname, IPCTL_MAXID }, /* ip */
642 1.1 cgd { icmpname, ICMPCTL_MAXID }, /* icmp */
643 1.1 cgd { 0, 0 }, /* igmp */
644 1.1 cgd { 0, 0 }, /* ggmp */
645 1.1 cgd { 0, 0 },
646 1.1 cgd { 0, 0 },
647 1.8 thorpej { tcpname, TCPCTL_MAXID }, /* tcp */
648 1.1 cgd { 0, 0 },
649 1.1 cgd { 0, 0 }, /* egp */
650 1.1 cgd { 0, 0 },
651 1.20 itojun /*10*/ { 0, 0 },
652 1.1 cgd { 0, 0 },
653 1.1 cgd { 0, 0 }, /* pup */
654 1.1 cgd { 0, 0 },
655 1.1 cgd { 0, 0 },
656 1.1 cgd { 0, 0 },
657 1.1 cgd { 0, 0 },
658 1.1 cgd { udpname, UDPCTL_MAXID }, /* udp */
659 1.20 itojun { 0, 0 },
660 1.20 itojun { 0, 0 },
661 1.20 itojun /*20*/ { 0, 0 },
662 1.20 itojun { 0, 0 },
663 1.20 itojun { 0, 0 }, /* idp */
664 1.20 itojun { 0, 0 },
665 1.20 itojun { 0, 0 },
666 1.20 itojun { 0, 0 },
667 1.20 itojun { 0, 0 },
668 1.20 itojun { 0, 0 },
669 1.20 itojun { 0, 0 },
670 1.20 itojun { 0, 0 },
671 1.20 itojun /*30*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
672 1.20 itojun { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
673 1.20 itojun /*40*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
674 1.20 itojun { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
675 1.20 itojun #ifdef IPSEC
676 1.20 itojun { ipsecname, IPSECCTL_MAXID }, /* esp - for backward compatibility */
677 1.20 itojun { ipsecname, IPSECCTL_MAXID }, /* ah */
678 1.20 itojun #else
679 1.20 itojun { 0, 0 },
680 1.20 itojun { 0, 0 },
681 1.20 itojun #endif
682 1.1 cgd };
683 1.1 cgd
684 1.1 cgd /*
685 1.1 cgd * handle internet requests
686 1.1 cgd */
687 1.14 christos static int
688 1.1 cgd sysctl_inet(string, bufpp, mib, flags, typep)
689 1.1 cgd char *string;
690 1.1 cgd char **bufpp;
691 1.1 cgd int mib[];
692 1.1 cgd int flags;
693 1.1 cgd int *typep;
694 1.1 cgd {
695 1.1 cgd struct list *lp;
696 1.1 cgd int indx;
697 1.1 cgd
698 1.1 cgd if (*bufpp == NULL) {
699 1.1 cgd listall(string, &inetlist);
700 1.1 cgd return (-1);
701 1.1 cgd }
702 1.1 cgd if ((indx = findname(string, "third", bufpp, &inetlist)) == -1)
703 1.1 cgd return (-1);
704 1.1 cgd mib[2] = indx;
705 1.20 itojun if (indx <= IPPROTO_MAXID && inetvars[indx].list != NULL)
706 1.1 cgd lp = &inetvars[indx];
707 1.1 cgd else if (!flags)
708 1.1 cgd return (-1);
709 1.1 cgd else {
710 1.14 christos warnx("No variables defined for protocol %s", string);
711 1.1 cgd return (-1);
712 1.1 cgd }
713 1.1 cgd if (*bufpp == NULL) {
714 1.1 cgd listall(string, lp);
715 1.1 cgd return (-1);
716 1.1 cgd }
717 1.1 cgd if ((indx = findname(string, "fourth", bufpp, lp)) == -1)
718 1.1 cgd return (-1);
719 1.1 cgd mib[3] = indx;
720 1.1 cgd *typep = lp->list[indx].ctl_type;
721 1.1 cgd return (4);
722 1.17 thorpej }
723 1.20 itojun
724 1.20 itojun #ifdef INET6
725 1.20 itojun struct ctlname inet6name[] = CTL_IPV6PROTO_NAMES;
726 1.20 itojun struct ctlname ip6name[] = IPV6CTL_NAMES;
727 1.20 itojun struct ctlname icmp6name[] = ICMPV6CTL_NAMES;
728 1.20 itojun #ifdef TCP6
729 1.20 itojun struct ctlname tcp6name[] = TCP6CTL_NAMES;
730 1.20 itojun #endif
731 1.20 itojun struct ctlname udp6name[] = UDP6CTL_NAMES;
732 1.20 itojun struct ctlname pim6name[] = PIMCTL_NAMES;
733 1.20 itojun struct ctlname ipsec6name[] = IPSEC6CTL_NAMES;
734 1.20 itojun struct list inet6list = { inet6name, IPV6PROTO_MAXID };
735 1.20 itojun struct list inet6vars[] = {
736 1.20 itojun /*0*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
737 1.20 itojun { 0, 0 },
738 1.20 itojun #ifdef TCP6
739 1.20 itojun { tcp6name, TCP6CTL_MAXID }, /* tcp6 */
740 1.20 itojun #else
741 1.20 itojun { 0, 0 },
742 1.20 itojun #endif
743 1.20 itojun { 0, 0 },
744 1.20 itojun { 0, 0 },
745 1.20 itojun { 0, 0 },
746 1.20 itojun /*10*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
747 1.20 itojun { 0, 0 },
748 1.20 itojun { 0, 0 },
749 1.20 itojun { udp6name, UDP6CTL_MAXID }, /* udp6 */
750 1.20 itojun { 0, 0 },
751 1.20 itojun { 0, 0 },
752 1.20 itojun /*20*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
753 1.20 itojun { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
754 1.20 itojun /*30*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
755 1.20 itojun { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
756 1.20 itojun /*40*/ { 0, 0 },
757 1.20 itojun { ip6name, IPV6CTL_MAXID }, /* ipv6 */
758 1.20 itojun { 0, 0 },
759 1.20 itojun { 0, 0 },
760 1.20 itojun { 0, 0 },
761 1.20 itojun { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
762 1.20 itojun #ifdef IPSEC
763 1.20 itojun /*50*/ { ipsec6name, IPSECCTL_MAXID }, /* esp6 - for backward compatibility */
764 1.20 itojun { ipsec6name, IPSECCTL_MAXID }, /* ah6 */
765 1.20 itojun #else
766 1.20 itojun { 0, 0 },
767 1.20 itojun { 0, 0 },
768 1.20 itojun #endif
769 1.20 itojun { 0, 0 },
770 1.20 itojun { 0, 0 },
771 1.20 itojun { 0, 0 },
772 1.20 itojun { 0, 0 },
773 1.20 itojun { 0, 0 },
774 1.20 itojun { 0, 0 },
775 1.20 itojun { icmp6name, ICMPV6CTL_MAXID }, /* icmp6 */
776 1.20 itojun { 0, 0 },
777 1.20 itojun /*60*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
778 1.20 itojun { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
779 1.20 itojun /*70*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
780 1.20 itojun { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
781 1.20 itojun /*80*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
782 1.20 itojun { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
783 1.20 itojun /*90*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
784 1.20 itojun { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
785 1.20 itojun /*100*/ { 0, 0 },
786 1.20 itojun { 0, 0 },
787 1.20 itojun { 0, 0 },
788 1.20 itojun { pim6name, PIMCTL_MAXID }, /* pim6 */
789 1.20 itojun };
790 1.20 itojun
791 1.20 itojun /*
792 1.20 itojun * handle internet6 requests
793 1.20 itojun */
794 1.20 itojun static int
795 1.20 itojun sysctl_inet6(string, bufpp, mib, flags, typep)
796 1.20 itojun char *string;
797 1.20 itojun char **bufpp;
798 1.20 itojun int mib[];
799 1.20 itojun int flags;
800 1.20 itojun int *typep;
801 1.20 itojun {
802 1.20 itojun struct list *lp;
803 1.20 itojun int indx;
804 1.20 itojun
805 1.20 itojun if (*bufpp == NULL) {
806 1.20 itojun listall(string, &inet6list);
807 1.20 itojun return (-1);
808 1.20 itojun }
809 1.20 itojun if ((indx = findname(string, "third", bufpp, &inet6list)) == -1)
810 1.20 itojun return (-1);
811 1.20 itojun mib[2] = indx;
812 1.20 itojun if (indx <= sizeof(inet6vars)/sizeof(inet6vars[0])
813 1.20 itojun && inet6vars[indx].list != NULL) {
814 1.20 itojun lp = &inet6vars[indx];
815 1.20 itojun } else if (!flags) {
816 1.20 itojun return (-1);
817 1.20 itojun } else {
818 1.20 itojun fprintf(stderr, "%s: no variables defined for this protocol\n",
819 1.20 itojun string);
820 1.20 itojun return (-1);
821 1.20 itojun }
822 1.20 itojun if (*bufpp == NULL) {
823 1.20 itojun listall(string, lp);
824 1.20 itojun return (-1);
825 1.20 itojun }
826 1.20 itojun if ((indx = findname(string, "fourth", bufpp, lp)) == -1)
827 1.20 itojun return (-1);
828 1.20 itojun mib[3] = indx;
829 1.20 itojun *typep = lp->list[indx].ctl_type;
830 1.20 itojun return (4);
831 1.20 itojun }
832 1.20 itojun #endif /* INET6 */
833 1.20 itojun
834 1.20 itojun #ifdef IPSEC
835 1.20 itojun struct ctlname keynames[] = KEYCTL_NAMES;
836 1.20 itojun struct list keylist = { keynames, KEYCTL_MAXID };
837 1.20 itojun
838 1.20 itojun /*
839 1.20 itojun * handle key requests
840 1.20 itojun */
841 1.20 itojun static int
842 1.20 itojun sysctl_key(string, bufpp, mib, flags, typep)
843 1.20 itojun char *string;
844 1.20 itojun char **bufpp;
845 1.20 itojun int mib[];
846 1.20 itojun int flags;
847 1.20 itojun int *typep;
848 1.20 itojun {
849 1.20 itojun struct list *lp;
850 1.20 itojun int indx;
851 1.20 itojun
852 1.20 itojun if (*bufpp == NULL) {
853 1.20 itojun listall(string, &keylist);
854 1.20 itojun return (-1);
855 1.20 itojun }
856 1.20 itojun if ((indx = findname(string, "third", bufpp, &keylist)) == -1)
857 1.20 itojun return (-1);
858 1.20 itojun mib[2] = indx;
859 1.20 itojun lp = &keylist;
860 1.20 itojun *typep = lp->list[indx].ctl_type;
861 1.20 itojun return 3;
862 1.20 itojun }
863 1.20 itojun #endif /*IPSEC*/
864 1.17 thorpej
865 1.17 thorpej struct ctlname ffsname[] = FFS_NAMES;
866 1.17 thorpej struct ctlname nfsname[] = NFS_NAMES;
867 1.17 thorpej struct list vfsvars[] = {
868 1.17 thorpej { 0, 0 }, /* generic */
869 1.17 thorpej { ffsname, FFS_MAXID }, /* FFS */
870 1.17 thorpej { nfsname, NFS_MAXID }, /* NFS */
871 1.17 thorpej { 0, 0 }, /* MFS */
872 1.17 thorpej { 0, 0 }, /* MSDOS */
873 1.17 thorpej { 0, 0 }, /* LFS */
874 1.17 thorpej { 0, 0 }, /* old LOFS */
875 1.17 thorpej { 0, 0 }, /* FDESC */
876 1.17 thorpej { 0, 0 }, /* PORTAL */
877 1.17 thorpej { 0, 0 }, /* NULL */
878 1.17 thorpej { 0, 0 }, /* UMAP */
879 1.17 thorpej { 0, 0 }, /* KERNFS */
880 1.17 thorpej { 0, 0 }, /* PROCFS */
881 1.17 thorpej { 0, 0 }, /* AFS */
882 1.17 thorpej { 0, 0 }, /* CD9660 */
883 1.17 thorpej { 0, 0 }, /* UNION */
884 1.17 thorpej { 0, 0 }, /* ADOSFS */
885 1.17 thorpej { 0, 0 }, /* EXT2FS */
886 1.17 thorpej { 0, 0 }, /* CODA */
887 1.17 thorpej { 0, 0 }, /* FILECORE */
888 1.17 thorpej };
889 1.17 thorpej
890 1.17 thorpej /*
891 1.17 thorpej * handle vfs requests
892 1.17 thorpej */
893 1.17 thorpej static int
894 1.17 thorpej sysctl_vfs(string, bufpp, mib, flags, typep)
895 1.17 thorpej char *string;
896 1.17 thorpej char **bufpp;
897 1.17 thorpej int mib[];
898 1.17 thorpej int flags;
899 1.17 thorpej int *typep;
900 1.17 thorpej {
901 1.17 thorpej struct list *lp = &vfsvars[mib[1]];
902 1.17 thorpej int indx;
903 1.17 thorpej
904 1.17 thorpej if (lp->list == NULL) {
905 1.17 thorpej if (flags)
906 1.17 thorpej warnx("No variables defined for file system %s",
907 1.17 thorpej string);
908 1.17 thorpej return (-1);
909 1.17 thorpej }
910 1.17 thorpej if (*bufpp == NULL) {
911 1.17 thorpej listall(string, lp);
912 1.17 thorpej return (-1);
913 1.17 thorpej }
914 1.17 thorpej if ((indx = findname(string, "third", bufpp, lp)) == -1)
915 1.17 thorpej return (-1);
916 1.17 thorpej mib[2] = indx;
917 1.17 thorpej *typep = lp->list[indx].ctl_type;
918 1.17 thorpej return (3);
919 1.17 thorpej }
920 1.17 thorpej
921 1.17 thorpej struct ctlname vfsgenname[] = CTL_VFSGENCTL_NAMES;
922 1.17 thorpej struct list vfsgenvars = { vfsgenname, VFSGEN_MAXID };
923 1.17 thorpej
924 1.17 thorpej /*
925 1.17 thorpej * handle vfs.generic requests
926 1.17 thorpej */
927 1.17 thorpej static int
928 1.17 thorpej sysctl_vfsgen(string, bufpp, mib, flags, typep)
929 1.17 thorpej char *string;
930 1.17 thorpej char **bufpp;
931 1.17 thorpej int mib[];
932 1.17 thorpej int flags;
933 1.17 thorpej int *typep;
934 1.17 thorpej {
935 1.17 thorpej struct list *lp = &vfsgenvars;
936 1.17 thorpej int indx;
937 1.17 thorpej
938 1.17 thorpej if (*bufpp == NULL) {
939 1.17 thorpej listall(string, lp);
940 1.17 thorpej return (-1);
941 1.17 thorpej }
942 1.17 thorpej if ((indx = findname(string, "third", bufpp, lp)) == -1)
943 1.17 thorpej return (-1);
944 1.17 thorpej /* Don't bother with VFS_CONF. */
945 1.17 thorpej if (indx == VFS_CONF)
946 1.19 thorpej return (-1);
947 1.19 thorpej mib[2] = indx;
948 1.19 thorpej *typep = lp->list[indx].ctl_type;
949 1.19 thorpej return (3);
950 1.19 thorpej }
951 1.19 thorpej
952 1.22 bouyer struct ctlname procnames[] = PROC_PID_NAMES;
953 1.22 bouyer struct list procvars = {procnames, PROC_PID_MAXID};
954 1.22 bouyer struct ctlname proclimitnames[] = PROC_PID_LIMIT_NAMES;
955 1.22 bouyer struct list proclimitvars = {proclimitnames, PROC_PID_LIMIT_MAXID};
956 1.22 bouyer struct ctlname proclimittypenames[] = PROC_PID_LIMIT_TYPE_NAMES;
957 1.22 bouyer struct list proclimittypevars = {proclimittypenames,
958 1.22 bouyer PROC_PID_LIMIT_TYPE_MAXID};
959 1.22 bouyer /*
960 1.22 bouyer * handle kern.proc requests
961 1.22 bouyer */
962 1.22 bouyer static int
963 1.22 bouyer sysctl_proc(string, bufpp, mib, flags, typep)
964 1.22 bouyer char *string;
965 1.22 bouyer char **bufpp;
966 1.22 bouyer int mib[];
967 1.22 bouyer int flags;
968 1.22 bouyer int *typep;
969 1.22 bouyer {
970 1.22 bouyer char *cp, name[BUFSIZ];
971 1.22 bouyer struct list *lp;
972 1.22 bouyer int indx;
973 1.22 bouyer
974 1.22 bouyer if (*bufpp == NULL) {
975 1.22 bouyer strcpy(name, string);
976 1.22 bouyer cp = &name[strlen(name)];
977 1.22 bouyer *cp++ = '.';
978 1.22 bouyer strcpy(cp, "curproc");
979 1.22 bouyer parse (name, Aflag);
980 1.22 bouyer return (-1);
981 1.22 bouyer }
982 1.22 bouyer cp = strsep(bufpp, ".");
983 1.22 bouyer if (cp == NULL) {
984 1.22 bouyer warnx("%s: incomplete specification", string);
985 1.22 bouyer return (-1);
986 1.22 bouyer }
987 1.22 bouyer if (strcmp(cp, "curproc") == 0) {
988 1.22 bouyer mib[1] = PROC_CURPROC;
989 1.22 bouyer } else {
990 1.22 bouyer mib[1] = atoi(cp);
991 1.22 bouyer if (mib[1] == 0) {
992 1.22 bouyer warnx("second level name %s in %s is invalid", cp,
993 1.22 bouyer string);
994 1.22 bouyer return (-1);
995 1.22 bouyer }
996 1.22 bouyer }
997 1.22 bouyer *typep = CTLTYPE_NODE;
998 1.22 bouyer lp = &procvars;
999 1.22 bouyer if (*bufpp == NULL) {
1000 1.22 bouyer listall(string, lp);
1001 1.22 bouyer return (-1);
1002 1.22 bouyer }
1003 1.22 bouyer if ((indx = findname(string, "third", bufpp, lp)) == -1)
1004 1.22 bouyer return (-1);
1005 1.22 bouyer mib[2] = indx;
1006 1.22 bouyer *typep = lp->list[indx].ctl_type;
1007 1.22 bouyer if (*typep != CTLTYPE_NODE)
1008 1.22 bouyer return(3);
1009 1.22 bouyer lp = &proclimitvars;
1010 1.22 bouyer if (*bufpp == NULL) {
1011 1.22 bouyer listall(string, lp);
1012 1.22 bouyer return (-1);
1013 1.22 bouyer }
1014 1.22 bouyer if ((indx = findname(string, "fourth", bufpp, lp)) == -1)
1015 1.22 bouyer return (-1);
1016 1.22 bouyer mib[3] = indx;
1017 1.22 bouyer lp = &proclimittypevars;
1018 1.22 bouyer if (*bufpp == NULL) {
1019 1.22 bouyer listall(string, lp);
1020 1.22 bouyer return (-1);
1021 1.22 bouyer }
1022 1.22 bouyer if ((indx = findname(string, "fifth", bufpp, lp)) == -1)
1023 1.22 bouyer return (-1);
1024 1.22 bouyer mib[4] = indx;
1025 1.22 bouyer *typep = CTLTYPE_LIMIT;
1026 1.22 bouyer return(5);
1027 1.22 bouyer }
1028 1.22 bouyer
1029 1.19 thorpej struct ctlname mbufnames[] = CTL_MBUF_NAMES;
1030 1.19 thorpej struct list mbufvars = { mbufnames, MBUF_MAXID };
1031 1.19 thorpej /*
1032 1.19 thorpej * handle kern.mbuf requests
1033 1.19 thorpej */
1034 1.19 thorpej static int
1035 1.19 thorpej sysctl_mbuf(string, bufpp, mib, flags, typep)
1036 1.19 thorpej char *string;
1037 1.19 thorpej char **bufpp;
1038 1.19 thorpej int mib[];
1039 1.19 thorpej int flags;
1040 1.19 thorpej int *typep;
1041 1.19 thorpej {
1042 1.19 thorpej struct list *lp = &mbufvars;
1043 1.19 thorpej int indx;
1044 1.19 thorpej
1045 1.19 thorpej if (*bufpp == NULL) {
1046 1.19 thorpej listall(string, lp);
1047 1.19 thorpej return (-1);
1048 1.19 thorpej }
1049 1.19 thorpej if ((indx = findname(string, "third", bufpp, lp)) == -1)
1050 1.17 thorpej return (-1);
1051 1.17 thorpej mib[2] = indx;
1052 1.17 thorpej *typep = lp->list[indx].ctl_type;
1053 1.17 thorpej return (3);
1054 1.1 cgd }
1055 1.1 cgd
1056 1.1 cgd /*
1057 1.1 cgd * Scan a list of names searching for a particular name.
1058 1.1 cgd */
1059 1.14 christos static int
1060 1.1 cgd findname(string, level, bufp, namelist)
1061 1.1 cgd char *string;
1062 1.1 cgd char *level;
1063 1.1 cgd char **bufp;
1064 1.1 cgd struct list *namelist;
1065 1.1 cgd {
1066 1.1 cgd char *name;
1067 1.1 cgd int i;
1068 1.1 cgd
1069 1.1 cgd if (namelist->list == 0 || (name = strsep(bufp, ".")) == NULL) {
1070 1.14 christos warnx("%s: incomplete specification", string);
1071 1.1 cgd return (-1);
1072 1.1 cgd }
1073 1.1 cgd for (i = 0; i < namelist->size; i++)
1074 1.1 cgd if (namelist->list[i].ctl_name != NULL &&
1075 1.1 cgd strcmp(name, namelist->list[i].ctl_name) == 0)
1076 1.1 cgd break;
1077 1.1 cgd if (i == namelist->size) {
1078 1.14 christos warnx("%s level name %s in %s is invalid",
1079 1.1 cgd level, name, string);
1080 1.1 cgd return (-1);
1081 1.1 cgd }
1082 1.1 cgd return (i);
1083 1.1 cgd }
1084 1.1 cgd
1085 1.14 christos static void
1086 1.1 cgd usage()
1087 1.1 cgd {
1088 1.14 christos extern char *__progname;
1089 1.1 cgd
1090 1.14 christos (void)fprintf(stderr, "Usage:\t%s %s\n\t%s %s\n\t%s %s\n\t%s %s\n",
1091 1.14 christos __progname, "[-n] variable ...",
1092 1.14 christos __progname, "[-n] -w variable=value ...",
1093 1.14 christos __progname, "[-n] -a",
1094 1.14 christos __progname, "[-n] -A");
1095 1.1 cgd exit(1);
1096 1.1 cgd }
1097