kern_sysctl.c revision 1.86.2.13 1 /* $NetBSD: kern_sysctl.c,v 1.86.2.13 2002/04/01 07:47:55 nathanw Exp $ */
2
3 /*-
4 * Copyright (c) 1982, 1986, 1989, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Mike Karels at Berkeley Software Design, Inc.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)kern_sysctl.c 8.9 (Berkeley) 5/20/95
39 */
40
41 /*
42 * sysctl system call.
43 */
44
45 #include <sys/cdefs.h>
46 __KERNEL_RCSID(0, "$NetBSD: kern_sysctl.c,v 1.86.2.13 2002/04/01 07:47:55 nathanw Exp $");
47
48 #include "opt_ddb.h"
49 #include "opt_insecure.h"
50 #include "opt_defcorename.h"
51 #include "opt_pipe.h"
52 #include "opt_sysv.h"
53 #include "pty.h"
54
55 #include <sys/param.h>
56 #include <sys/systm.h>
57 #include <sys/kernel.h>
58 #include <sys/buf.h>
59 #include <sys/device.h>
60 #include <sys/disklabel.h>
61 #include <sys/dkstat.h>
62 #include <sys/exec.h>
63 #include <sys/file.h>
64 #include <sys/ioctl.h>
65 #include <sys/malloc.h>
66 #include <sys/mount.h>
67 #include <sys/msgbuf.h>
68 #include <sys/pool.h>
69 #include <sys/lwp.h>
70 #include <sys/proc.h>
71 #include <sys/resource.h>
72 #include <sys/resourcevar.h>
73 #include <sys/syscallargs.h>
74 #include <sys/tty.h>
75 #include <sys/unistd.h>
76 #include <sys/vnode.h>
77 #include <sys/socketvar.h>
78 #define __SYSCTL_PRIVATE
79 #include <sys/sysctl.h>
80 #include <sys/lock.h>
81 #include <sys/namei.h>
82
83 #if defined(SYSVMSG) || defined(SYSVSEM) || defined(SYSVSHM)
84 #include <sys/ipc.h>
85 #endif
86 #ifdef SYSVMSG
87 #include <sys/msg.h>
88 #endif
89 #ifdef SYSVSEM
90 #include <sys/sem.h>
91 #endif
92 #ifdef SYSVSHM
93 #include <sys/shm.h>
94 #endif
95
96 #include <dev/cons.h>
97
98 #if defined(DDB)
99 #include <ddb/ddbvar.h>
100 #endif
101
102 #ifndef PIPE_SOCKETPAIR
103 #include <sys/pipe.h>
104 #endif
105
106 #define PTRTOINT64(foo) ((u_int64_t)(uintptr_t)(foo))
107
108 static int sysctl_file(void *, size_t *);
109 #if defined(SYSVMSG) || defined(SYSVSEM) || defined(SYSVSHM)
110 static int sysctl_sysvipc(int *, u_int, void *, size_t *);
111 #endif
112 static int sysctl_msgbuf(void *, size_t *);
113 static int sysctl_doeproc(int *, u_int, void *, size_t *);
114 static int sysctl_dotkstat(int *, u_int, void *, size_t *, void *);
115 #ifdef MULTIPROCESSOR
116 static int sysctl_docptime(void *, size_t *, void *);
117 static int sysctl_ncpus(void);
118 #endif
119 static void fill_kproc2(struct proc *, struct kinfo_proc2 *);
120 static int sysctl_procargs(int *, u_int, void *, size_t *, struct proc *);
121 #if NPTY > 0
122 static int sysctl_pty(void *, size_t *, void *, size_t);
123 #endif
124
125 /*
126 * The `sysctl_memlock' is intended to keep too many processes from
127 * locking down memory by doing sysctls at once. Whether or not this
128 * is really a good idea to worry about it probably a subject of some
129 * debate.
130 */
131 struct lock sysctl_memlock;
132
133 void
134 sysctl_init(void)
135 {
136
137 lockinit(&sysctl_memlock, PRIBIO|PCATCH, "sysctl", 0, 0);
138 }
139
140 int
141 sys___sysctl(struct lwp *l, void *v, register_t *retval)
142 {
143 struct sys___sysctl_args /* {
144 syscallarg(int *) name;
145 syscallarg(u_int) namelen;
146 syscallarg(void *) old;
147 syscallarg(size_t *) oldlenp;
148 syscallarg(void *) new;
149 syscallarg(size_t) newlen;
150 } */ *uap = v;
151 struct proc *p = l->l_proc;
152 int error;
153 size_t savelen = 0, oldlen = 0;
154 sysctlfn *fn;
155 int name[CTL_MAXNAME];
156 size_t *oldlenp;
157
158 /*
159 * all top-level sysctl names are non-terminal
160 */
161 if (SCARG(uap, namelen) > CTL_MAXNAME || SCARG(uap, namelen) < 2)
162 return (EINVAL);
163 error = copyin(SCARG(uap, name), &name,
164 SCARG(uap, namelen) * sizeof(int));
165 if (error)
166 return (error);
167
168 /*
169 * For all but CTL_PROC, must be root to change a value.
170 * For CTL_PROC, must be root, or owner of the proc (and not suid),
171 * this is checked in proc_sysctl() (once we know the targer proc).
172 */
173 if (SCARG(uap, new) != NULL && name[0] != CTL_PROC &&
174 (error = suser(p->p_ucred, &p->p_acflag)))
175 return error;
176
177 switch (name[0]) {
178 case CTL_KERN:
179 fn = kern_sysctl;
180 break;
181 case CTL_HW:
182 fn = hw_sysctl;
183 break;
184 case CTL_VM:
185 fn = uvm_sysctl;
186 break;
187 case CTL_NET:
188 fn = net_sysctl;
189 break;
190 case CTL_VFS:
191 fn = vfs_sysctl;
192 break;
193 case CTL_MACHDEP:
194 fn = cpu_sysctl;
195 break;
196 #ifdef DEBUG
197 case CTL_DEBUG:
198 fn = debug_sysctl;
199 break;
200 #endif
201 #ifdef DDB
202 case CTL_DDB:
203 fn = ddb_sysctl;
204 break;
205 #endif
206 case CTL_PROC:
207 fn = proc_sysctl;
208 break;
209
210 case CTL_EMUL:
211 fn = emul_sysctl;
212 break;
213 default:
214 return (EOPNOTSUPP);
215 }
216
217 /*
218 * XXX Hey, we wire `old', but what about `new'?
219 */
220
221 oldlenp = SCARG(uap, oldlenp);
222 if (oldlenp) {
223 if ((error = copyin(oldlenp, &oldlen, sizeof(oldlen))))
224 return (error);
225 oldlenp = &oldlen;
226 }
227 if (SCARG(uap, old) != NULL) {
228 error = lockmgr(&sysctl_memlock, LK_EXCLUSIVE, NULL);
229 if (error)
230 return (error);
231 error = uvm_vslock(p, SCARG(uap, old), oldlen, VM_PROT_WRITE);
232 if (error) {
233 (void) lockmgr(&sysctl_memlock, LK_RELEASE, NULL);
234 return error;
235 }
236 savelen = oldlen;
237 }
238 error = (*fn)(name + 1, SCARG(uap, namelen) - 1, SCARG(uap, old),
239 oldlenp, SCARG(uap, new), SCARG(uap, newlen), p);
240 if (SCARG(uap, old) != NULL) {
241 uvm_vsunlock(p, SCARG(uap, old), savelen);
242 (void) lockmgr(&sysctl_memlock, LK_RELEASE, NULL);
243 }
244 if (error)
245 return (error);
246 if (SCARG(uap, oldlenp))
247 error = copyout(&oldlen, SCARG(uap, oldlenp), sizeof(oldlen));
248 return (error);
249 }
250
251 /*
252 * Attributes stored in the kernel.
253 */
254 char hostname[MAXHOSTNAMELEN];
255 int hostnamelen;
256
257 char domainname[MAXHOSTNAMELEN];
258 int domainnamelen;
259
260 long hostid;
261
262 #ifdef INSECURE
263 int securelevel = -1;
264 #else
265 int securelevel = 0;
266 #endif
267
268 #ifndef DEFCORENAME
269 #define DEFCORENAME "%n.core"
270 #endif
271 char defcorename[MAXPATHLEN] = DEFCORENAME;
272 int defcorenamelen = sizeof(DEFCORENAME);
273
274 extern int kern_logsigexit;
275 extern fixpt_t ccpu;
276
277 #ifndef MULTIPROCESSOR
278 #define sysctl_ncpus() 1
279 #endif
280
281 #ifdef MULTIPROCESSOR
282
283 #ifndef CPU_INFO_FOREACH
284 #define CPU_INFO_ITERATOR int
285 #define CPU_INFO_FOREACH(cii, ci) cii = 0, ci = curcpu(); ci != NULL; ci = NULL
286 #endif
287
288 static int
289 sysctl_docptime(void *oldp, size_t *oldlenp, void *newp)
290 {
291 u_int64_t cp_time[CPUSTATES];
292 int i;
293 struct cpu_info *ci;
294 CPU_INFO_ITERATOR cii;
295
296 for (i=0; i<CPUSTATES; i++)
297 cp_time[i] = 0;
298
299 for (CPU_INFO_FOREACH(cii, ci)) {
300 for (i=0; i<CPUSTATES; i++)
301 cp_time[i] += ci->ci_schedstate.spc_cp_time[i];
302 }
303 return (sysctl_rdstruct(oldp, oldlenp, newp,
304 cp_time, sizeof(cp_time)));
305 }
306
307 static int
308 sysctl_ncpus(void)
309 {
310 struct cpu_info *ci;
311 CPU_INFO_ITERATOR cii;
312
313 int ncpus = 0;
314 for (CPU_INFO_FOREACH(cii, ci))
315 ncpus++;
316 return ncpus;
317 }
318
319 #endif
320
321 /*
322 * kernel related system variables.
323 */
324 int
325 kern_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp,
326 void *newp, size_t newlen, struct proc *p)
327 {
328 int error, level, inthostid;
329 int old_autonicetime;
330 int old_vnodes;
331 dev_t consdev;
332
333 /* All sysctl names at this level, except for a few, are terminal. */
334 switch (name[0]) {
335 case KERN_PROC:
336 case KERN_PROC2:
337 case KERN_PROF:
338 case KERN_MBUF:
339 case KERN_PROC_ARGS:
340 case KERN_SYSVIPC_INFO:
341 case KERN_PIPE:
342 case KERN_TKSTAT:
343 /* Not terminal. */
344 break;
345 default:
346 if (namelen != 1)
347 return (ENOTDIR); /* overloaded */
348 }
349
350 switch (name[0]) {
351 case KERN_OSTYPE:
352 return (sysctl_rdstring(oldp, oldlenp, newp, ostype));
353 case KERN_OSRELEASE:
354 return (sysctl_rdstring(oldp, oldlenp, newp, osrelease));
355 case KERN_OSREV:
356 return (sysctl_rdint(oldp, oldlenp, newp, __NetBSD_Version__));
357 case KERN_VERSION:
358 return (sysctl_rdstring(oldp, oldlenp, newp, version));
359 case KERN_MAXVNODES:
360 old_vnodes = desiredvnodes;
361 error = sysctl_int(oldp, oldlenp, newp, newlen, &desiredvnodes);
362 if (newp && !error) {
363 if (old_vnodes > desiredvnodes) {
364 desiredvnodes = old_vnodes;
365 return (EINVAL);
366 }
367 vfs_reinit();
368 nchreinit();
369 }
370 return (error);
371 case KERN_MAXPROC:
372 return (sysctl_int(oldp, oldlenp, newp, newlen, &maxproc));
373 case KERN_MAXFILES:
374 return (sysctl_int(oldp, oldlenp, newp, newlen, &maxfiles));
375 case KERN_ARGMAX:
376 return (sysctl_rdint(oldp, oldlenp, newp, ARG_MAX));
377 case KERN_SECURELVL:
378 level = securelevel;
379 if ((error = sysctl_int(oldp, oldlenp, newp, newlen, &level)) ||
380 newp == NULL)
381 return (error);
382 if (level < securelevel && p->p_pid != 1)
383 return (EPERM);
384 securelevel = level;
385 return (0);
386 case KERN_HOSTNAME:
387 error = sysctl_string(oldp, oldlenp, newp, newlen,
388 hostname, sizeof(hostname));
389 if (newp && !error)
390 hostnamelen = newlen;
391 return (error);
392 case KERN_DOMAINNAME:
393 error = sysctl_string(oldp, oldlenp, newp, newlen,
394 domainname, sizeof(domainname));
395 if (newp && !error)
396 domainnamelen = newlen;
397 return (error);
398 case KERN_HOSTID:
399 inthostid = hostid; /* XXX assumes sizeof long <= sizeof int */
400 error = sysctl_int(oldp, oldlenp, newp, newlen, &inthostid);
401 if (newp && !error)
402 hostid = inthostid;
403 return (error);
404 case KERN_CLOCKRATE:
405 return (sysctl_clockrate(oldp, oldlenp));
406 case KERN_BOOTTIME:
407 return (sysctl_rdstruct(oldp, oldlenp, newp, &boottime,
408 sizeof(struct timeval)));
409 case KERN_VNODE:
410 return (sysctl_vnode(oldp, oldlenp, p));
411 case KERN_PROC:
412 case KERN_PROC2:
413 return (sysctl_doeproc(name, namelen, oldp, oldlenp));
414 case KERN_PROC_ARGS:
415 return (sysctl_procargs(name + 1, namelen - 1,
416 oldp, oldlenp, p));
417 case KERN_FILE:
418 return (sysctl_file(oldp, oldlenp));
419 #ifdef GPROF
420 case KERN_PROF:
421 return (sysctl_doprof(name + 1, namelen - 1, oldp, oldlenp,
422 newp, newlen));
423 #endif
424 case KERN_POSIX1:
425 return (sysctl_rdint(oldp, oldlenp, newp, _POSIX_VERSION));
426 case KERN_NGROUPS:
427 return (sysctl_rdint(oldp, oldlenp, newp, NGROUPS_MAX));
428 case KERN_JOB_CONTROL:
429 return (sysctl_rdint(oldp, oldlenp, newp, 1));
430 case KERN_SAVED_IDS:
431 #ifdef _POSIX_SAVED_IDS
432 return (sysctl_rdint(oldp, oldlenp, newp, 1));
433 #else
434 return (sysctl_rdint(oldp, oldlenp, newp, 0));
435 #endif
436 case KERN_MAXPARTITIONS:
437 return (sysctl_rdint(oldp, oldlenp, newp, MAXPARTITIONS));
438 case KERN_RAWPARTITION:
439 return (sysctl_rdint(oldp, oldlenp, newp, RAW_PART));
440 #ifdef NTP
441 case KERN_NTPTIME:
442 return (sysctl_ntptime(oldp, oldlenp));
443 #endif
444 case KERN_AUTONICETIME:
445 old_autonicetime = autonicetime;
446 error = sysctl_int(oldp, oldlenp, newp, newlen, &autonicetime);
447 if (autonicetime < 0)
448 autonicetime = old_autonicetime;
449 return (error);
450 case KERN_AUTONICEVAL:
451 error = sysctl_int(oldp, oldlenp, newp, newlen, &autoniceval);
452 if (autoniceval < PRIO_MIN)
453 autoniceval = PRIO_MIN;
454 if (autoniceval > PRIO_MAX)
455 autoniceval = PRIO_MAX;
456 return (error);
457 case KERN_RTC_OFFSET:
458 return (sysctl_rdint(oldp, oldlenp, newp, rtc_offset));
459 case KERN_ROOT_DEVICE:
460 return (sysctl_rdstring(oldp, oldlenp, newp,
461 root_device->dv_xname));
462 case KERN_MSGBUFSIZE:
463 /*
464 * deal with cases where the message buffer has
465 * become corrupted.
466 */
467 if (!msgbufenabled || msgbufp->msg_magic != MSG_MAGIC) {
468 msgbufenabled = 0;
469 return (ENXIO);
470 }
471 return (sysctl_rdint(oldp, oldlenp, newp, msgbufp->msg_bufs));
472 case KERN_FSYNC:
473 return (sysctl_rdint(oldp, oldlenp, newp, 1));
474 case KERN_SYSVMSG:
475 #ifdef SYSVMSG
476 return (sysctl_rdint(oldp, oldlenp, newp, 1));
477 #else
478 return (sysctl_rdint(oldp, oldlenp, newp, 0));
479 #endif
480 case KERN_SYSVSEM:
481 #ifdef SYSVSEM
482 return (sysctl_rdint(oldp, oldlenp, newp, 1));
483 #else
484 return (sysctl_rdint(oldp, oldlenp, newp, 0));
485 #endif
486 case KERN_SYSVSHM:
487 #ifdef SYSVSHM
488 return (sysctl_rdint(oldp, oldlenp, newp, 1));
489 #else
490 return (sysctl_rdint(oldp, oldlenp, newp, 0));
491 #endif
492 case KERN_DEFCORENAME:
493 if (newp && newlen < 1)
494 return (EINVAL);
495 error = sysctl_string(oldp, oldlenp, newp, newlen,
496 defcorename, sizeof(defcorename));
497 if (newp && !error)
498 defcorenamelen = newlen;
499 return (error);
500 case KERN_SYNCHRONIZED_IO:
501 return (sysctl_rdint(oldp, oldlenp, newp, 1));
502 case KERN_IOV_MAX:
503 return (sysctl_rdint(oldp, oldlenp, newp, IOV_MAX));
504 case KERN_MBUF:
505 return (sysctl_dombuf(name + 1, namelen - 1, oldp, oldlenp,
506 newp, newlen));
507 case KERN_MAPPED_FILES:
508 return (sysctl_rdint(oldp, oldlenp, newp, 1));
509 case KERN_MEMLOCK:
510 return (sysctl_rdint(oldp, oldlenp, newp, 1));
511 case KERN_MEMLOCK_RANGE:
512 return (sysctl_rdint(oldp, oldlenp, newp, 1));
513 case KERN_MEMORY_PROTECTION:
514 return (sysctl_rdint(oldp, oldlenp, newp, 1));
515 case KERN_LOGIN_NAME_MAX:
516 return (sysctl_rdint(oldp, oldlenp, newp, LOGIN_NAME_MAX));
517 case KERN_LOGSIGEXIT:
518 return (sysctl_int(oldp, oldlenp, newp, newlen,
519 &kern_logsigexit));
520 case KERN_FSCALE:
521 return (sysctl_rdint(oldp, oldlenp, newp, FSCALE));
522 case KERN_CCPU:
523 return (sysctl_rdint(oldp, oldlenp, newp, ccpu));
524 case KERN_CP_TIME:
525 #ifndef MULTIPROCESSOR
526 return (sysctl_rdstruct(oldp, oldlenp, newp,
527 curcpu()->ci_schedstate.spc_cp_time,
528 sizeof(curcpu()->ci_schedstate.spc_cp_time)));
529 #else
530 return (sysctl_docptime(oldp, oldlenp, newp));
531 #endif
532 #if defined(SYSVMSG) || defined(SYSVSEM) || defined(SYSVSHM)
533 case KERN_SYSVIPC_INFO:
534 return (sysctl_sysvipc(name + 1, namelen - 1, oldp, oldlenp));
535 #endif
536 case KERN_MSGBUF:
537 return (sysctl_msgbuf(oldp, oldlenp));
538 case KERN_CONSDEV:
539 if (cn_tab != NULL)
540 consdev = cn_tab->cn_dev;
541 else
542 consdev = NODEV;
543 return (sysctl_rdstruct(oldp, oldlenp, newp, &consdev,
544 sizeof consdev));
545 #if NPTY > 0
546 case KERN_MAXPTYS:
547 return sysctl_pty(oldp, oldlenp, newp, newlen);
548 #endif
549 #ifndef PIPE_SOCKETPAIR
550 case KERN_PIPE:
551 return (sysctl_dopipe(name + 1, namelen - 1, oldp, oldlenp,
552 newp, newlen));
553 #endif
554 case KERN_MAXPHYS:
555 return (sysctl_rdint(oldp, oldlenp, newp, MAXPHYS));
556 case KERN_SBMAX:
557 {
558 int new_sbmax = sb_max;
559
560 error = sysctl_int(oldp, oldlenp, newp, newlen, &new_sbmax);
561 if (newp && !error) {
562 if (new_sbmax < (16 * 1024)) /* sanity */
563 return (EINVAL);
564 sb_max = new_sbmax;
565 }
566 return (error);
567 }
568 case KERN_TKSTAT:
569 return (sysctl_dotkstat(name + 1, namelen - 1, oldp, oldlenp,
570 newp));
571 case KERN_MONOTONIC_CLOCK: /* XXX _POSIX_VERSION */
572 return (sysctl_rdint(oldp, oldlenp, newp, 200112));
573 default:
574 return (EOPNOTSUPP);
575 }
576 /* NOTREACHED */
577 }
578
579 /*
580 * hardware related system variables.
581 */
582 int
583 hw_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp,
584 void *newp, size_t newlen, struct proc *p)
585 {
586
587 /* All sysctl names at this level, except for a few, are terminal. */
588 switch (name[0]) {
589 case HW_DISKSTATS:
590 /* Not terminal. */
591 break;
592 default:
593 if (namelen != 1)
594 return (ENOTDIR); /* overloaded */
595 }
596
597 switch (name[0]) {
598 case HW_MACHINE:
599 return (sysctl_rdstring(oldp, oldlenp, newp, machine));
600 case HW_MACHINE_ARCH:
601 return (sysctl_rdstring(oldp, oldlenp, newp, machine_arch));
602 case HW_MODEL:
603 return (sysctl_rdstring(oldp, oldlenp, newp, cpu_model));
604 case HW_NCPU:
605 return (sysctl_rdint(oldp, oldlenp, newp, sysctl_ncpus()));
606 case HW_BYTEORDER:
607 return (sysctl_rdint(oldp, oldlenp, newp, BYTE_ORDER));
608 case HW_PHYSMEM:
609 return (sysctl_rdint(oldp, oldlenp, newp, ctob(physmem)));
610 case HW_USERMEM:
611 return (sysctl_rdint(oldp, oldlenp, newp,
612 ctob(physmem - uvmexp.wired)));
613 case HW_PAGESIZE:
614 return (sysctl_rdint(oldp, oldlenp, newp, PAGE_SIZE));
615 case HW_ALIGNBYTES:
616 return (sysctl_rdint(oldp, oldlenp, newp, ALIGNBYTES));
617 case HW_DISKNAMES:
618 return (sysctl_disknames(oldp, oldlenp));
619 case HW_DISKSTATS:
620 return (sysctl_diskstats(name + 1, namelen - 1, oldp, oldlenp));
621 case HW_CNMAGIC: {
622 char magic[CNS_LEN];
623 int error;
624
625 if (oldp)
626 cn_get_magic(magic, CNS_LEN);
627 error = sysctl_string(oldp, oldlenp, newp, newlen,
628 magic, sizeof(magic));
629 if (newp && !error) {
630 error = cn_set_magic(magic);
631 }
632 return (error);
633 }
634 default:
635 return (EOPNOTSUPP);
636 }
637 /* NOTREACHED */
638 }
639
640 #ifdef DEBUG
641 /*
642 * Debugging related system variables.
643 */
644 struct ctldebug debug0, debug1, debug2, debug3, debug4;
645 struct ctldebug debug5, debug6, debug7, debug8, debug9;
646 struct ctldebug debug10, debug11, debug12, debug13, debug14;
647 struct ctldebug debug15, debug16, debug17, debug18, debug19;
648 static struct ctldebug *debugvars[CTL_DEBUG_MAXID] = {
649 &debug0, &debug1, &debug2, &debug3, &debug4,
650 &debug5, &debug6, &debug7, &debug8, &debug9,
651 &debug10, &debug11, &debug12, &debug13, &debug14,
652 &debug15, &debug16, &debug17, &debug18, &debug19,
653 };
654
655 int
656 debug_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp,
657 void *newp, size_t newlen, struct proc *p)
658 {
659 struct ctldebug *cdp;
660
661 /* all sysctl names at this level are name and field */
662 if (namelen != 2)
663 return (ENOTDIR); /* overloaded */
664 if (name[0] >= CTL_DEBUG_MAXID)
665 return (EOPNOTSUPP);
666 cdp = debugvars[name[0]];
667 if (cdp->debugname == 0)
668 return (EOPNOTSUPP);
669 switch (name[1]) {
670 case CTL_DEBUG_NAME:
671 return (sysctl_rdstring(oldp, oldlenp, newp, cdp->debugname));
672 case CTL_DEBUG_VALUE:
673 return (sysctl_int(oldp, oldlenp, newp, newlen, cdp->debugvar));
674 default:
675 return (EOPNOTSUPP);
676 }
677 /* NOTREACHED */
678 }
679 #endif /* DEBUG */
680
681 int
682 proc_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp,
683 void *newp, size_t newlen, struct proc *p)
684 {
685 struct proc *ptmp = NULL;
686 const struct proclist_desc *pd;
687 int error = 0;
688 struct rlimit alim;
689 struct plimit *newplim;
690 char *tmps = NULL;
691 int i, curlen, len;
692
693 if (namelen < 2)
694 return EINVAL;
695
696 if (name[0] == PROC_CURPROC) {
697 ptmp = p;
698 } else {
699 proclist_lock_read();
700 for (pd = proclists; pd->pd_list != NULL; pd++) {
701 for (ptmp = LIST_FIRST(pd->pd_list); ptmp != NULL;
702 ptmp = LIST_NEXT(ptmp, p_list)) {
703 /* Skip embryonic processes. */
704 if (ptmp->p_stat == SIDL)
705 continue;
706 if (ptmp->p_pid == (pid_t)name[0])
707 break;
708 }
709 if (ptmp != NULL)
710 break;
711 }
712 proclist_unlock_read();
713 if (ptmp == NULL)
714 return(ESRCH);
715 if (p->p_ucred->cr_uid != 0) {
716 if(p->p_cred->p_ruid != ptmp->p_cred->p_ruid ||
717 p->p_cred->p_ruid != ptmp->p_cred->p_svuid)
718 return EPERM;
719 if (ptmp->p_cred->p_rgid != ptmp->p_cred->p_svgid)
720 return EPERM; /* sgid proc */
721 for (i = 0; i < p->p_ucred->cr_ngroups; i++) {
722 if (p->p_ucred->cr_groups[i] ==
723 ptmp->p_cred->p_rgid)
724 break;
725 }
726 if (i == p->p_ucred->cr_ngroups)
727 return EPERM;
728 }
729 }
730 if (name[1] == PROC_PID_CORENAME) {
731 if (namelen != 2)
732 return EINVAL;
733 /*
734 * Can't use sysctl_string() here because we may malloc a new
735 * area during the process, so we have to do it by hand.
736 */
737 curlen = strlen(ptmp->p_limit->pl_corename) + 1;
738 if (oldlenp && *oldlenp < curlen) {
739 if (!oldp)
740 *oldlenp = curlen;
741 return (ENOMEM);
742 }
743 if (newp) {
744 if (securelevel > 2)
745 return EPERM;
746 if (newlen > MAXPATHLEN)
747 return ENAMETOOLONG;
748 tmps = malloc(newlen + 1, M_TEMP, M_WAITOK);
749 if (tmps == NULL)
750 return ENOMEM;
751 error = copyin(newp, tmps, newlen + 1);
752 tmps[newlen] = '\0';
753 if (error)
754 goto cleanup;
755 /* Enforce to be either 'core' for end with '.core' */
756 if (newlen < 4) { /* c.o.r.e */
757 error = EINVAL;
758 goto cleanup;
759 }
760 len = newlen - 4;
761 if (len > 0) {
762 if (tmps[len - 1] != '.' &&
763 tmps[len - 1] != '/') {
764 error = EINVAL;
765 goto cleanup;
766 }
767 }
768 if (strcmp(&tmps[len], "core") != 0) {
769 error = EINVAL;
770 goto cleanup;
771 }
772 }
773 if (oldp && oldlenp) {
774 *oldlenp = curlen;
775 error = copyout(ptmp->p_limit->pl_corename, oldp,
776 curlen);
777 }
778 if (newp && error == 0) {
779 /* if the 2 strings are identical, don't limcopy() */
780 if (strcmp(tmps, ptmp->p_limit->pl_corename) == 0) {
781 error = 0;
782 goto cleanup;
783 }
784 if (ptmp->p_limit->p_refcnt > 1 &&
785 (ptmp->p_limit->p_lflags & PL_SHAREMOD) == 0) {
786 newplim = limcopy(ptmp->p_limit);
787 limfree(ptmp->p_limit);
788 ptmp->p_limit = newplim;
789 }
790 if (ptmp->p_limit->pl_corename != defcorename) {
791 free(ptmp->p_limit->pl_corename, M_TEMP);
792 }
793 ptmp->p_limit->pl_corename = tmps;
794 return (0);
795 }
796 cleanup:
797 if (tmps)
798 free(tmps, M_TEMP);
799 return (error);
800 }
801 if (name[1] == PROC_PID_LIMIT) {
802 if (namelen != 4 || name[2] >= PROC_PID_LIMIT_MAXID)
803 return EINVAL;
804 memcpy(&alim, &ptmp->p_rlimit[name[2] - 1], sizeof(alim));
805 if (name[3] == PROC_PID_LIMIT_TYPE_HARD)
806 error = sysctl_quad(oldp, oldlenp, newp, newlen,
807 &alim.rlim_max);
808 else if (name[3] == PROC_PID_LIMIT_TYPE_SOFT)
809 error = sysctl_quad(oldp, oldlenp, newp, newlen,
810 &alim.rlim_cur);
811 else
812 error = EINVAL;
813
814 if (error)
815 return error;
816
817 if (newp)
818 error = dosetrlimit(ptmp, p->p_cred,
819 name[2] - 1, &alim);
820 return error;
821 }
822 return (EINVAL);
823 }
824
825 int
826 emul_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp,
827 void *newp, size_t newlen, struct proc *p)
828 {
829 extern int nexecs_builtin;
830 extern const struct execsw execsw_builtin[];
831 static struct {
832 const char *name;
833 int type;
834 } emulations[] = CTL_EMUL_NAMES;
835 const char *ename;
836 int i;
837
838 /* all sysctl names at this level are name and field */
839 if (namelen < 2)
840 return (ENOTDIR); /* overloaded */
841
842 if (name[0] >= EMUL_MAXID || name[0] == 0)
843 return (EOPNOTSUPP);
844
845 ename = emulations[name[0]].name;
846
847 for (i = 0; i < nexecs_builtin; i++) {
848 const struct emul *e = execsw_builtin[i].es_emul;
849 if (e != NULL && strcmp(ename, e->e_name) == 0 &&
850 execsw_builtin[i].es_sysctl != NULL)
851 return (*execsw_builtin[i].es_sysctl)(name + 1, namelen - 1,
852 oldp, oldlenp, newp, newlen, p);
853 }
854
855 return (EOPNOTSUPP);
856 }
857 /*
858 * Convenience macros.
859 */
860
861 #define SYSCTL_SCALAR_CORE_LEN(oldp, oldlenp, valp, len) \
862 if (oldlenp) { \
863 if (!oldp) \
864 *oldlenp = len; \
865 else { \
866 if (*oldlenp < len) \
867 return(ENOMEM); \
868 *oldlenp = len; \
869 error = copyout((caddr_t)valp, oldp, len); \
870 } \
871 }
872
873 #define SYSCTL_SCALAR_CORE_TYP(oldp, oldlenp, valp, typ) \
874 SYSCTL_SCALAR_CORE_LEN(oldp, oldlenp, valp, sizeof(typ))
875
876 #define SYSCTL_SCALAR_NEWPCHECK_LEN(newp, newlen, len) \
877 if (newp && newlen != len) \
878 return (EINVAL);
879
880 #define SYSCTL_SCALAR_NEWPCHECK_TYP(newp, newlen, typ) \
881 SYSCTL_SCALAR_NEWPCHECK_LEN(newp, newlen, sizeof(typ))
882
883 #define SYSCTL_SCALAR_NEWPCOP_LEN(newp, valp, len) \
884 if (error == 0 && newp) \
885 error = copyin(newp, valp, len);
886
887 #define SYSCTL_SCALAR_NEWPCOP_TYP(newp, valp, typ) \
888 SYSCTL_SCALAR_NEWPCOP_LEN(newp, valp, sizeof(typ))
889
890 #define SYSCTL_STRING_CORE(oldp, oldlenp, str) \
891 if (oldlenp) { \
892 len = strlen(str) + 1; \
893 if (!oldp) \
894 *oldlenp = len; \
895 else { \
896 if (*oldlenp < len) { \
897 err2 = ENOMEM; \
898 len = *oldlenp; \
899 } else \
900 *oldlenp = len; \
901 error = copyout(str, oldp, len);\
902 if (error == 0) \
903 error = err2; \
904 } \
905 }
906
907 /*
908 * Validate parameters and get old / set new parameters
909 * for an integer-valued sysctl function.
910 */
911 int
912 sysctl_int(void *oldp, size_t *oldlenp, void *newp, size_t newlen, int *valp)
913 {
914 int error = 0;
915
916 SYSCTL_SCALAR_NEWPCHECK_TYP(newp, newlen, int)
917 SYSCTL_SCALAR_CORE_TYP(oldp, oldlenp, valp, int)
918 SYSCTL_SCALAR_NEWPCOP_TYP(newp, valp, int)
919
920 return (error);
921 }
922
923
924 /*
925 * As above, but read-only.
926 */
927 int
928 sysctl_rdint(void *oldp, size_t *oldlenp, void *newp, int val)
929 {
930 int error = 0;
931
932 if (newp)
933 return (EPERM);
934
935 SYSCTL_SCALAR_CORE_TYP(oldp, oldlenp, &val, int)
936
937 return (error);
938 }
939
940 /*
941 * Validate parameters and get old / set new parameters
942 * for an quad-valued sysctl function.
943 */
944 int
945 sysctl_quad(void *oldp, size_t *oldlenp, void *newp, size_t newlen,
946 quad_t *valp)
947 {
948 int error = 0;
949
950 SYSCTL_SCALAR_NEWPCHECK_TYP(newp, newlen, quad_t)
951 SYSCTL_SCALAR_CORE_TYP(oldp, oldlenp, valp, quad_t)
952 SYSCTL_SCALAR_NEWPCOP_TYP(newp, valp, quad_t)
953
954 return (error);
955 }
956
957 /*
958 * As above, but read-only.
959 */
960 int
961 sysctl_rdquad(void *oldp, size_t *oldlenp, void *newp, quad_t val)
962 {
963 int error = 0;
964
965 if (newp)
966 return (EPERM);
967
968 SYSCTL_SCALAR_CORE_TYP(oldp, oldlenp, &val, quad_t)
969
970 return (error);
971 }
972
973 /*
974 * Validate parameters and get old / set new parameters
975 * for a string-valued sysctl function.
976 */
977 int
978 sysctl_string(void *oldp, size_t *oldlenp, void *newp, size_t newlen, char *str,
979 int maxlen)
980 {
981 int len, error = 0, err2 = 0;
982
983 if (newp && newlen >= maxlen)
984 return (EINVAL);
985
986 SYSCTL_STRING_CORE(oldp, oldlenp, str);
987
988 if (error == 0 && newp) {
989 error = copyin(newp, str, newlen);
990 str[newlen] = 0;
991 }
992 return (error);
993 }
994
995 /*
996 * As above, but read-only.
997 */
998 int
999 sysctl_rdstring(void *oldp, size_t *oldlenp, void *newp, const char *str)
1000 {
1001 int len, error = 0, err2 = 0;
1002
1003 if (newp)
1004 return (EPERM);
1005
1006 SYSCTL_STRING_CORE(oldp, oldlenp, str);
1007
1008 return (error);
1009 }
1010
1011 /*
1012 * Validate parameters and get old / set new parameters
1013 * for a structure oriented sysctl function.
1014 */
1015 int
1016 sysctl_struct(void *oldp, size_t *oldlenp, void *newp, size_t newlen, void *sp,
1017 int len)
1018 {
1019 int error = 0;
1020
1021 SYSCTL_SCALAR_NEWPCHECK_LEN(newp, newlen, len)
1022 SYSCTL_SCALAR_CORE_LEN(oldp, oldlenp, sp, len)
1023 SYSCTL_SCALAR_NEWPCOP_LEN(newp, sp, len)
1024
1025 return (error);
1026 }
1027
1028 /*
1029 * Validate parameters and get old parameters
1030 * for a structure oriented sysctl function.
1031 */
1032 int
1033 sysctl_rdstruct(void *oldp, size_t *oldlenp, void *newp, const void *sp,
1034 int len)
1035 {
1036 int error = 0;
1037
1038 if (newp)
1039 return (EPERM);
1040
1041 SYSCTL_SCALAR_CORE_LEN(oldp, oldlenp, sp, len)
1042
1043 return (error);
1044 }
1045
1046 /*
1047 * As above, but can return a truncated result.
1048 */
1049 int
1050 sysctl_rdminstruct(void *oldp, size_t *oldlenp, void *newp, const void *sp,
1051 int len)
1052 {
1053 int error = 0;
1054
1055 if (newp)
1056 return (EPERM);
1057
1058 len = min(*oldlenp, len);
1059 SYSCTL_SCALAR_CORE_LEN(oldp, oldlenp, sp, len)
1060
1061 return (error);
1062 }
1063
1064 /*
1065 * Get file structures.
1066 */
1067 static int
1068 sysctl_file(void *vwhere, size_t *sizep)
1069 {
1070 int buflen, error;
1071 struct file *fp;
1072 char *start, *where;
1073
1074 start = where = vwhere;
1075 buflen = *sizep;
1076 if (where == NULL) {
1077 /*
1078 * overestimate by 10 files
1079 */
1080 *sizep = sizeof(filehead) + (nfiles + 10) * sizeof(struct file);
1081 return (0);
1082 }
1083
1084 /*
1085 * first copyout filehead
1086 */
1087 if (buflen < sizeof(filehead)) {
1088 *sizep = 0;
1089 return (0);
1090 }
1091 error = copyout((caddr_t)&filehead, where, sizeof(filehead));
1092 if (error)
1093 return (error);
1094 buflen -= sizeof(filehead);
1095 where += sizeof(filehead);
1096
1097 /*
1098 * followed by an array of file structures
1099 */
1100 for (fp = filehead.lh_first; fp != 0; fp = fp->f_list.le_next) {
1101 if (buflen < sizeof(struct file)) {
1102 *sizep = where - start;
1103 return (ENOMEM);
1104 }
1105 error = copyout((caddr_t)fp, where, sizeof(struct file));
1106 if (error)
1107 return (error);
1108 buflen -= sizeof(struct file);
1109 where += sizeof(struct file);
1110 }
1111 *sizep = where - start;
1112 return (0);
1113 }
1114
1115 #if defined(SYSVMSG) || defined(SYSVSEM) || defined(SYSVSHM)
1116 #define FILL_PERM(src, dst) do { \
1117 (dst)._key = (src)._key; \
1118 (dst).uid = (src).uid; \
1119 (dst).gid = (src).gid; \
1120 (dst).cuid = (src).cuid; \
1121 (dst).cgid = (src).cgid; \
1122 (dst).mode = (src).mode; \
1123 (dst)._seq = (src)._seq; \
1124 } while (0);
1125 #define FILL_MSG(src, dst) do { \
1126 FILL_PERM((src).msg_perm, (dst).msg_perm); \
1127 (dst).msg_qnum = (src).msg_qnum; \
1128 (dst).msg_qbytes = (src).msg_qbytes; \
1129 (dst)._msg_cbytes = (src)._msg_cbytes; \
1130 (dst).msg_lspid = (src).msg_lspid; \
1131 (dst).msg_lrpid = (src).msg_lrpid; \
1132 (dst).msg_stime = (src).msg_stime; \
1133 (dst).msg_rtime = (src).msg_rtime; \
1134 (dst).msg_ctime = (src).msg_ctime; \
1135 } while (0)
1136 #define FILL_SEM(src, dst) do { \
1137 FILL_PERM((src).sem_perm, (dst).sem_perm); \
1138 (dst).sem_nsems = (src).sem_nsems; \
1139 (dst).sem_otime = (src).sem_otime; \
1140 (dst).sem_ctime = (src).sem_ctime; \
1141 } while (0)
1142 #define FILL_SHM(src, dst) do { \
1143 FILL_PERM((src).shm_perm, (dst).shm_perm); \
1144 (dst).shm_segsz = (src).shm_segsz; \
1145 (dst).shm_lpid = (src).shm_lpid; \
1146 (dst).shm_cpid = (src).shm_cpid; \
1147 (dst).shm_atime = (src).shm_atime; \
1148 (dst).shm_dtime = (src).shm_dtime; \
1149 (dst).shm_ctime = (src).shm_ctime; \
1150 (dst).shm_nattch = (src).shm_nattch; \
1151 } while (0)
1152
1153 static int
1154 sysctl_sysvipc(int *name, u_int namelen, void *where, size_t *sizep)
1155 {
1156 #ifdef SYSVMSG
1157 struct msg_sysctl_info *msgsi;
1158 #endif
1159 #ifdef SYSVSEM
1160 struct sem_sysctl_info *semsi;
1161 #endif
1162 #ifdef SYSVSHM
1163 struct shm_sysctl_info *shmsi;
1164 #endif
1165 size_t infosize, dssize, tsize, buflen;
1166 void *buf = NULL, *buf2;
1167 char *start;
1168 int32_t nds;
1169 int i, error, ret;
1170
1171 if (namelen != 1)
1172 return (EINVAL);
1173
1174 start = where;
1175 buflen = *sizep;
1176
1177 switch (*name) {
1178 case KERN_SYSVIPC_MSG_INFO:
1179 #ifdef SYSVMSG
1180 infosize = sizeof(msgsi->msginfo);
1181 nds = msginfo.msgmni;
1182 dssize = sizeof(msgsi->msgids[0]);
1183 break;
1184 #else
1185 return (EINVAL);
1186 #endif
1187 case KERN_SYSVIPC_SEM_INFO:
1188 #ifdef SYSVSEM
1189 infosize = sizeof(semsi->seminfo);
1190 nds = seminfo.semmni;
1191 dssize = sizeof(semsi->semids[0]);
1192 break;
1193 #else
1194 return (EINVAL);
1195 #endif
1196 case KERN_SYSVIPC_SHM_INFO:
1197 #ifdef SYSVSHM
1198 infosize = sizeof(shmsi->shminfo);
1199 nds = shminfo.shmmni;
1200 dssize = sizeof(shmsi->shmids[0]);
1201 break;
1202 #else
1203 return (EINVAL);
1204 #endif
1205 default:
1206 return (EINVAL);
1207 }
1208 /*
1209 * Round infosize to 64 bit boundary if requesting more than just
1210 * the info structure or getting the total data size.
1211 */
1212 if (where == NULL || *sizep > infosize)
1213 infosize = ((infosize + 7) / 8) * 8;
1214 tsize = infosize + nds * dssize;
1215
1216 /* Return just the total size required. */
1217 if (where == NULL) {
1218 *sizep = tsize;
1219 return (0);
1220 }
1221
1222 /* Not enough room for even the info struct. */
1223 if (buflen < infosize) {
1224 *sizep = 0;
1225 return (ENOMEM);
1226 }
1227 buf = malloc(min(tsize, buflen), M_TEMP, M_WAITOK);
1228 memset(buf, 0, min(tsize, buflen));
1229
1230 switch (*name) {
1231 #ifdef SYSVMSG
1232 case KERN_SYSVIPC_MSG_INFO:
1233 msgsi = (struct msg_sysctl_info *)buf;
1234 buf2 = &msgsi->msgids[0];
1235 msgsi->msginfo = msginfo;
1236 break;
1237 #endif
1238 #ifdef SYSVSEM
1239 case KERN_SYSVIPC_SEM_INFO:
1240 semsi = (struct sem_sysctl_info *)buf;
1241 buf2 = &semsi->semids[0];
1242 semsi->seminfo = seminfo;
1243 break;
1244 #endif
1245 #ifdef SYSVSHM
1246 case KERN_SYSVIPC_SHM_INFO:
1247 shmsi = (struct shm_sysctl_info *)buf;
1248 buf2 = &shmsi->shmids[0];
1249 shmsi->shminfo = shminfo;
1250 break;
1251 #endif
1252 }
1253 buflen -= infosize;
1254
1255 ret = 0;
1256 if (buflen > 0) {
1257 /* Fill in the IPC data structures. */
1258 for (i = 0; i < nds; i++) {
1259 if (buflen < dssize) {
1260 ret = ENOMEM;
1261 break;
1262 }
1263 switch (*name) {
1264 #ifdef SYSVMSG
1265 case KERN_SYSVIPC_MSG_INFO:
1266 FILL_MSG(msqids[i], msgsi->msgids[i]);
1267 break;
1268 #endif
1269 #ifdef SYSVSEM
1270 case KERN_SYSVIPC_SEM_INFO:
1271 FILL_SEM(sema[i], semsi->semids[i]);
1272 break;
1273 #endif
1274 #ifdef SYSVSHM
1275 case KERN_SYSVIPC_SHM_INFO:
1276 FILL_SHM(shmsegs[i], shmsi->shmids[i]);
1277 break;
1278 #endif
1279 }
1280 buflen -= dssize;
1281 }
1282 }
1283 *sizep -= buflen;
1284 error = copyout(buf, start, *sizep);
1285 /* If copyout succeeded, use return code set earlier. */
1286 if (error == 0)
1287 error = ret;
1288 if (buf)
1289 free(buf, M_TEMP);
1290 return (error);
1291 }
1292 #endif /* SYSVMSG || SYSVSEM || SYSVSHM */
1293
1294 static int
1295 sysctl_msgbuf(void *vwhere, size_t *sizep)
1296 {
1297 char *where = vwhere;
1298 size_t len, maxlen = *sizep;
1299 long beg, end;
1300 int error;
1301
1302 /*
1303 * deal with cases where the message buffer has
1304 * become corrupted.
1305 */
1306 if (!msgbufenabled || msgbufp->msg_magic != MSG_MAGIC) {
1307 msgbufenabled = 0;
1308 return (ENXIO);
1309 }
1310
1311 if (where == NULL) {
1312 /* always return full buffer size */
1313 *sizep = msgbufp->msg_bufs;
1314 return (0);
1315 }
1316
1317 error = 0;
1318 maxlen = min(msgbufp->msg_bufs, maxlen);
1319
1320 /*
1321 * First, copy from the write pointer to the end of
1322 * message buffer.
1323 */
1324 beg = msgbufp->msg_bufx;
1325 end = msgbufp->msg_bufs;
1326 while (maxlen > 0) {
1327 len = min(end - beg, maxlen);
1328 if (len == 0)
1329 break;
1330 error = copyout(&msgbufp->msg_bufc[beg], where, len);
1331 if (error)
1332 break;
1333 where += len;
1334 maxlen -= len;
1335
1336 /*
1337 * ... then, copy from the beginning of message buffer to
1338 * the write pointer.
1339 */
1340 beg = 0;
1341 end = msgbufp->msg_bufx;
1342 }
1343 return (error);
1344 }
1345
1346 /*
1347 * try over estimating by 5 procs
1348 */
1349 #define KERN_PROCSLOP (5 * sizeof(struct kinfo_proc))
1350
1351 static int
1352 sysctl_doeproc(int *name, u_int namelen, void *vwhere, size_t *sizep)
1353 {
1354 struct eproc eproc;
1355 struct kinfo_proc2 kproc2;
1356 struct kinfo_proc *dp;
1357 struct proc *p;
1358 const struct proclist_desc *pd;
1359 char *where, *dp2;
1360 int type, op, arg, elem_size, elem_count;
1361 int buflen, needed, error;
1362
1363 dp = vwhere;
1364 dp2 = where = vwhere;
1365 buflen = where != NULL ? *sizep : 0;
1366 error = needed = 0;
1367 type = name[0];
1368
1369 if (type == KERN_PROC) {
1370 if (namelen != 3 && !(namelen == 2 && name[1] == KERN_PROC_ALL))
1371 return (EINVAL);
1372 op = name[1];
1373 if (op != KERN_PROC_ALL)
1374 arg = name[2];
1375 } else {
1376 if (namelen != 5)
1377 return (EINVAL);
1378 op = name[1];
1379 arg = name[2];
1380 elem_size = name[3];
1381 elem_count = name[4];
1382 }
1383
1384 proclist_lock_read();
1385
1386 pd = proclists;
1387 again:
1388 for (p = LIST_FIRST(pd->pd_list); p != NULL; p = LIST_NEXT(p, p_list)) {
1389 /*
1390 * Skip embryonic processes.
1391 */
1392 if (p->p_stat == SIDL)
1393 continue;
1394 /*
1395 * TODO - make more efficient (see notes below).
1396 * do by session.
1397 */
1398 switch (op) {
1399
1400 case KERN_PROC_PID:
1401 /* could do this with just a lookup */
1402 if (p->p_pid != (pid_t)arg)
1403 continue;
1404 break;
1405
1406 case KERN_PROC_PGRP:
1407 /* could do this by traversing pgrp */
1408 if (p->p_pgrp->pg_id != (pid_t)arg)
1409 continue;
1410 break;
1411
1412 case KERN_PROC_SESSION:
1413 if (p->p_session->s_sid != (pid_t)arg)
1414 continue;
1415 break;
1416
1417 case KERN_PROC_TTY:
1418 if (arg == KERN_PROC_TTY_REVOKE) {
1419 if ((p->p_flag & P_CONTROLT) == 0 ||
1420 p->p_session->s_ttyp == NULL ||
1421 p->p_session->s_ttyvp != NULL)
1422 continue;
1423 } else if ((p->p_flag & P_CONTROLT) == 0 ||
1424 p->p_session->s_ttyp == NULL) {
1425 if ((dev_t)arg != KERN_PROC_TTY_NODEV)
1426 continue;
1427 } else if (p->p_session->s_ttyp->t_dev != (dev_t)arg)
1428 continue;
1429 break;
1430
1431 case KERN_PROC_UID:
1432 if (p->p_ucred->cr_uid != (uid_t)arg)
1433 continue;
1434 break;
1435
1436 case KERN_PROC_RUID:
1437 if (p->p_cred->p_ruid != (uid_t)arg)
1438 continue;
1439 break;
1440
1441 case KERN_PROC_GID:
1442 if (p->p_ucred->cr_gid != (uid_t)arg)
1443 continue;
1444 break;
1445
1446 case KERN_PROC_RGID:
1447 if (p->p_cred->p_rgid != (uid_t)arg)
1448 continue;
1449 break;
1450
1451 case KERN_PROC_ALL:
1452 /* allow everything */
1453 break;
1454
1455 default:
1456 error = EINVAL;
1457 goto cleanup;
1458 }
1459 if (type == KERN_PROC) {
1460 if (buflen >= sizeof(struct kinfo_proc)) {
1461 fill_eproc(p, &eproc);
1462 error = copyout((caddr_t)p, &dp->kp_proc,
1463 sizeof(struct proc));
1464 if (error)
1465 goto cleanup;
1466 error = copyout((caddr_t)&eproc, &dp->kp_eproc,
1467 sizeof(eproc));
1468 if (error)
1469 goto cleanup;
1470 dp++;
1471 buflen -= sizeof(struct kinfo_proc);
1472 }
1473 needed += sizeof(struct kinfo_proc);
1474 } else { /* KERN_PROC2 */
1475 if (buflen >= elem_size && elem_count > 0) {
1476 fill_kproc2(p, &kproc2);
1477 /*
1478 * Copy out elem_size, but not larger than
1479 * the size of a struct kinfo_proc2.
1480 */
1481 error = copyout(&kproc2, dp2,
1482 min(sizeof(kproc2), elem_size));
1483 if (error)
1484 goto cleanup;
1485 dp2 += elem_size;
1486 buflen -= elem_size;
1487 elem_count--;
1488 }
1489 needed += elem_size;
1490 }
1491 }
1492 pd++;
1493 if (pd->pd_list != NULL)
1494 goto again;
1495 proclist_unlock_read();
1496
1497 if (where != NULL) {
1498 if (type == KERN_PROC)
1499 *sizep = (caddr_t)dp - where;
1500 else
1501 *sizep = dp2 - where;
1502 if (needed > *sizep)
1503 return (ENOMEM);
1504 } else {
1505 needed += KERN_PROCSLOP;
1506 *sizep = needed;
1507 }
1508 return (0);
1509 cleanup:
1510 proclist_unlock_read();
1511 return (error);
1512 }
1513
1514 /*
1515 * Fill in an eproc structure for the specified process.
1516 */
1517 void
1518 fill_eproc(struct proc *p, struct eproc *ep)
1519 {
1520 struct tty *tp;
1521 struct lwp *l;
1522
1523 ep->e_paddr = p;
1524 ep->e_sess = p->p_session;
1525 ep->e_pcred = *p->p_cred;
1526 ep->e_ucred = *p->p_ucred;
1527 if (p->p_stat == SIDL || P_ZOMBIE(p)) {
1528 ep->e_vm.vm_rssize = 0;
1529 ep->e_vm.vm_tsize = 0;
1530 ep->e_vm.vm_dsize = 0;
1531 ep->e_vm.vm_ssize = 0;
1532 /* ep->e_vm.vm_pmap = XXX; */
1533 } else {
1534 struct vmspace *vm = p->p_vmspace;
1535
1536 ep->e_vm.vm_rssize = vm_resident_count(vm);
1537 ep->e_vm.vm_tsize = vm->vm_tsize;
1538 ep->e_vm.vm_dsize = vm->vm_dsize;
1539 ep->e_vm.vm_ssize = vm->vm_ssize;
1540
1541 /* Pick a "representative" LWP */
1542 l = proc_representative_lwp(p);
1543
1544 if (l->l_wmesg)
1545 strncpy(ep->e_wmesg, l->l_wmesg, WMESGLEN);
1546 }
1547 if (p->p_pptr)
1548 ep->e_ppid = p->p_pptr->p_pid;
1549 else
1550 ep->e_ppid = 0;
1551 ep->e_pgid = p->p_pgrp->pg_id;
1552 ep->e_sid = ep->e_sess->s_sid;
1553 ep->e_jobc = p->p_pgrp->pg_jobc;
1554 if ((p->p_flag & P_CONTROLT) &&
1555 (tp = ep->e_sess->s_ttyp)) {
1556 ep->e_tdev = tp->t_dev;
1557 ep->e_tpgid = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PID;
1558 ep->e_tsess = tp->t_session;
1559 } else
1560 ep->e_tdev = NODEV;
1561
1562 ep->e_xsize = ep->e_xrssize = 0;
1563 ep->e_xccount = ep->e_xswrss = 0;
1564 ep->e_flag = ep->e_sess->s_ttyvp ? EPROC_CTTY : 0;
1565 if (SESS_LEADER(p))
1566 ep->e_flag |= EPROC_SLEADER;
1567 strncpy(ep->e_login, ep->e_sess->s_login, MAXLOGNAME);
1568 }
1569
1570 /*
1571 * Fill in an eproc structure for the specified process.
1572 */
1573 static void
1574 fill_kproc2(struct proc *p, struct kinfo_proc2 *ki)
1575 {
1576 struct tty *tp;
1577 struct lwp *l;
1578 memset(ki, 0, sizeof(*ki));
1579
1580 /* XXX NJWLWP
1581 * These are likely not what the caller was looking for.
1582 * The perils of playing with the kernel data structures...
1583 */
1584 ki->p_paddr = PTRTOINT64(p);
1585 ki->p_fd = PTRTOINT64(p->p_fd);
1586 ki->p_cwdi = PTRTOINT64(p->p_cwdi);
1587 ki->p_stats = PTRTOINT64(p->p_stats);
1588 ki->p_limit = PTRTOINT64(p->p_limit);
1589 ki->p_vmspace = PTRTOINT64(p->p_vmspace);
1590 ki->p_sigacts = PTRTOINT64(p->p_sigacts);
1591 ki->p_sess = PTRTOINT64(p->p_session);
1592 ki->p_tsess = 0; /* may be changed if controlling tty below */
1593 ki->p_ru = PTRTOINT64(p->p_ru);
1594
1595 ki->p_eflag = 0;
1596 ki->p_exitsig = p->p_exitsig;
1597 ki->p_flag = p->p_flag;
1598
1599 ki->p_pid = p->p_pid;
1600 if (p->p_pptr)
1601 ki->p_ppid = p->p_pptr->p_pid;
1602 else
1603 ki->p_ppid = 0;
1604 ki->p_sid = p->p_session->s_sid;
1605 ki->p__pgid = p->p_pgrp->pg_id;
1606
1607 ki->p_tpgid = NO_PID; /* may be changed if controlling tty below */
1608
1609 ki->p_uid = p->p_ucred->cr_uid;
1610 ki->p_ruid = p->p_cred->p_ruid;
1611 ki->p_gid = p->p_ucred->cr_gid;
1612 ki->p_rgid = p->p_cred->p_rgid;
1613
1614 memcpy(ki->p_groups, p->p_cred->pc_ucred->cr_groups,
1615 min(sizeof(ki->p_groups), sizeof(p->p_cred->pc_ucred->cr_groups)));
1616 ki->p_ngroups = p->p_cred->pc_ucred->cr_ngroups;
1617
1618 ki->p_jobc = p->p_pgrp->pg_jobc;
1619 if ((p->p_flag & P_CONTROLT) && (tp = p->p_session->s_ttyp)) {
1620 ki->p_tdev = tp->t_dev;
1621 ki->p_tpgid = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PID;
1622 ki->p_tsess = PTRTOINT64(tp->t_session);
1623 } else {
1624 ki->p_tdev = NODEV;
1625 }
1626
1627 ki->p_estcpu = p->p_estcpu;
1628 ki->p_rtime_sec = p->p_rtime.tv_sec;
1629 ki->p_rtime_usec = p->p_rtime.tv_usec;
1630 ki->p_cpticks = p->p_cpticks;
1631 ki->p_pctcpu = p->p_pctcpu;
1632
1633 ki->p_uticks = p->p_uticks;
1634 ki->p_sticks = p->p_sticks;
1635 ki->p_iticks = p->p_iticks;
1636
1637 ki->p_tracep = PTRTOINT64(p->p_tracep);
1638 ki->p_traceflag = p->p_traceflag;
1639
1640
1641 memcpy(&ki->p_siglist, &p->p_sigctx.ps_siglist, sizeof(ki_sigset_t));
1642 memcpy(&ki->p_sigmask, &p->p_sigctx.ps_sigmask, sizeof(ki_sigset_t));
1643 memcpy(&ki->p_sigignore, &p->p_sigctx.ps_sigignore,sizeof(ki_sigset_t));
1644 memcpy(&ki->p_sigcatch, &p->p_sigctx.ps_sigcatch, sizeof(ki_sigset_t));
1645
1646 ki->p_stat = p->p_stat;
1647 ki->p_nice = p->p_nice;
1648
1649 ki->p_xstat = p->p_xstat;
1650 ki->p_acflag = p->p_acflag;
1651
1652 strncpy(ki->p_comm, p->p_comm,
1653 min(sizeof(ki->p_comm), sizeof(p->p_comm)));
1654
1655 strncpy(ki->p_login, p->p_session->s_login, sizeof(ki->p_login));
1656
1657 if (p->p_stat == SIDL || P_ZOMBIE(p)) {
1658 ki->p_vm_rssize = 0;
1659 ki->p_vm_tsize = 0;
1660 ki->p_vm_dsize = 0;
1661 ki->p_vm_ssize = 0;
1662 } else {
1663 struct vmspace *vm = p->p_vmspace;
1664
1665 ki->p_vm_rssize = vm_resident_count(vm);
1666 ki->p_vm_tsize = vm->vm_tsize;
1667 ki->p_vm_dsize = vm->vm_dsize;
1668 ki->p_vm_ssize = vm->vm_ssize;
1669
1670 /* Pick a "representative" LWP */
1671 l = proc_representative_lwp(p);
1672 ki->p_forw = PTRTOINT64(l->l_forw);
1673 ki->p_back = PTRTOINT64(l->l_back);
1674 ki->p_addr = PTRTOINT64(l->l_addr);
1675 ki->p_stat = l->l_stat;
1676 ki->p_flag |= l->l_flag;
1677 ki->p_swtime = l->l_swtime;
1678 ki->p_slptime = l->l_slptime;
1679 if (l->l_stat == LSONPROC) {
1680 KDASSERT(l->l_cpu != NULL);
1681 ki->p_schedflags = l->l_cpu->ci_schedstate.spc_flags;
1682 } else
1683 ki->p_schedflags = 0;
1684 ki->p_holdcnt = l->l_holdcnt;
1685 ki->p_priority = l->l_priority;
1686 ki->p_usrpri = l->l_usrpri;
1687 if (l->l_wmesg)
1688 strncpy(ki->p_wmesg, l->l_wmesg, sizeof(ki->p_wmesg));
1689 ki->p_wchan = PTRTOINT64(l->l_wchan);
1690
1691 }
1692
1693 if (p->p_session->s_ttyvp)
1694 ki->p_eflag |= EPROC_CTTY;
1695 if (SESS_LEADER(p))
1696 ki->p_eflag |= EPROC_SLEADER;
1697
1698 /* XXX Is this double check necessary? */
1699 if (P_ZOMBIE(p)) {
1700 ki->p_uvalid = 0;
1701 } else {
1702 ki->p_uvalid = 1;
1703
1704 ki->p_ustart_sec = p->p_stats->p_start.tv_sec;
1705 ki->p_ustart_usec = p->p_stats->p_start.tv_usec;
1706
1707 ki->p_uutime_sec = p->p_stats->p_ru.ru_utime.tv_sec;
1708 ki->p_uutime_usec = p->p_stats->p_ru.ru_utime.tv_usec;
1709 ki->p_ustime_sec = p->p_stats->p_ru.ru_stime.tv_sec;
1710 ki->p_ustime_usec = p->p_stats->p_ru.ru_stime.tv_usec;
1711
1712 ki->p_uru_maxrss = p->p_stats->p_ru.ru_maxrss;
1713 ki->p_uru_ixrss = p->p_stats->p_ru.ru_ixrss;
1714 ki->p_uru_idrss = p->p_stats->p_ru.ru_idrss;
1715 ki->p_uru_isrss = p->p_stats->p_ru.ru_isrss;
1716 ki->p_uru_minflt = p->p_stats->p_ru.ru_minflt;
1717 ki->p_uru_majflt = p->p_stats->p_ru.ru_majflt;
1718 ki->p_uru_nswap = p->p_stats->p_ru.ru_nswap;
1719 ki->p_uru_inblock = p->p_stats->p_ru.ru_inblock;
1720 ki->p_uru_oublock = p->p_stats->p_ru.ru_oublock;
1721 ki->p_uru_msgsnd = p->p_stats->p_ru.ru_msgsnd;
1722 ki->p_uru_msgrcv = p->p_stats->p_ru.ru_msgrcv;
1723 ki->p_uru_nsignals = p->p_stats->p_ru.ru_nsignals;
1724 ki->p_uru_nvcsw = p->p_stats->p_ru.ru_nvcsw;
1725 ki->p_uru_nivcsw = p->p_stats->p_ru.ru_nivcsw;
1726
1727 ki->p_uctime_sec = p->p_stats->p_cru.ru_utime.tv_sec +
1728 p->p_stats->p_cru.ru_stime.tv_sec;
1729 ki->p_uctime_usec = p->p_stats->p_cru.ru_utime.tv_usec +
1730 p->p_stats->p_cru.ru_stime.tv_usec;
1731 }
1732 #ifdef MULTIPROCESSOR
1733 if (p->p_cpu != NULL)
1734 ki->p_cpuid = p->p_cpu->ci_cpuid;
1735 else
1736 #endif
1737 ki->p_cpuid = KI_NOCPU;
1738
1739 }
1740
1741
1742
1743
1744 int
1745 sysctl_procargs(int *name, u_int namelen, void *where, size_t *sizep,
1746 struct proc *up)
1747 {
1748 struct ps_strings pss;
1749 struct proc *p;
1750 size_t len, upper_bound, xlen;
1751 struct uio auio;
1752 struct iovec aiov;
1753 vaddr_t argv;
1754 pid_t pid;
1755 int nargv, type, error, i;
1756 char *arg;
1757 char *tmp;
1758
1759 if (namelen != 2)
1760 return (EINVAL);
1761 pid = name[0];
1762 type = name[1];
1763
1764 switch (type) {
1765 case KERN_PROC_ARGV:
1766 case KERN_PROC_NARGV:
1767 case KERN_PROC_ENV:
1768 case KERN_PROC_NENV:
1769 /* ok */
1770 break;
1771 default:
1772 return (EINVAL);
1773 }
1774
1775 /* check pid */
1776 if ((p = pfind(pid)) == NULL)
1777 return (EINVAL);
1778
1779 /* only root or same user change look at the environment */
1780 if (type == KERN_PROC_ENV || type == KERN_PROC_NENV) {
1781 if (up->p_ucred->cr_uid != 0) {
1782 if (up->p_cred->p_ruid != p->p_cred->p_ruid ||
1783 up->p_cred->p_ruid != p->p_cred->p_svuid)
1784 return (EPERM);
1785 }
1786 }
1787
1788 if (sizep != NULL && where == NULL) {
1789 if (type == KERN_PROC_NARGV || type == KERN_PROC_NENV)
1790 *sizep = sizeof (int);
1791 else
1792 *sizep = ARG_MAX; /* XXX XXX XXX */
1793 return (0);
1794 }
1795 if (where == NULL || sizep == NULL)
1796 return (EINVAL);
1797
1798 /*
1799 * Zombies don't have a stack, so we can't read their psstrings.
1800 * System processes also don't have a user stack.
1801 */
1802 if (P_ZOMBIE(p) || (p->p_flag & P_SYSTEM) != 0)
1803 return (EINVAL);
1804
1805 /*
1806 * Lock the process down in memory.
1807 */
1808 /* XXXCDC: how should locking work here? */
1809 if ((p->p_flag & P_WEXIT) || (p->p_vmspace->vm_refcnt < 1))
1810 return (EFAULT);
1811
1812 p->p_vmspace->vm_refcnt++; /* XXX */
1813
1814 /*
1815 * Allocate a temporary buffer to hold the arguments.
1816 */
1817 arg = malloc(PAGE_SIZE, M_TEMP, M_WAITOK);
1818
1819 /*
1820 * Read in the ps_strings structure.
1821 */
1822 aiov.iov_base = &pss;
1823 aiov.iov_len = sizeof(pss);
1824 auio.uio_iov = &aiov;
1825 auio.uio_iovcnt = 1;
1826 auio.uio_offset = (vaddr_t)p->p_psstr;
1827 auio.uio_resid = sizeof(pss);
1828 auio.uio_segflg = UIO_SYSSPACE;
1829 auio.uio_rw = UIO_READ;
1830 auio.uio_procp = NULL;
1831 error = uvm_io(&p->p_vmspace->vm_map, &auio);
1832 if (error)
1833 goto done;
1834
1835 if (type == KERN_PROC_ARGV || type == KERN_PROC_NARGV)
1836 memcpy(&nargv, (char *)&pss + p->p_psnargv, sizeof(nargv));
1837 else
1838 memcpy(&nargv, (char *)&pss + p->p_psnenv, sizeof(nargv));
1839 if (type == KERN_PROC_NARGV || type == KERN_PROC_NENV) {
1840 error = copyout(&nargv, where, sizeof(nargv));
1841 *sizep = sizeof(nargv);
1842 goto done;
1843 }
1844 /*
1845 * Now read the address of the argument vector.
1846 */
1847 switch (type) {
1848 case KERN_PROC_ARGV:
1849 /* XXX compat32 stuff here */
1850 memcpy(&tmp, (char *)&pss + p->p_psargv, sizeof(tmp));
1851 break;
1852 case KERN_PROC_ENV:
1853 memcpy(&tmp, (char *)&pss + p->p_psenv, sizeof(tmp));
1854 break;
1855 default:
1856 return (EINVAL);
1857 }
1858 auio.uio_offset = (off_t)(long)tmp;
1859 aiov.iov_base = &argv;
1860 aiov.iov_len = sizeof(argv);
1861 auio.uio_iov = &aiov;
1862 auio.uio_iovcnt = 1;
1863 auio.uio_resid = sizeof(argv);
1864 auio.uio_segflg = UIO_SYSSPACE;
1865 auio.uio_rw = UIO_READ;
1866 auio.uio_procp = NULL;
1867 error = uvm_io(&p->p_vmspace->vm_map, &auio);
1868 if (error)
1869 goto done;
1870
1871 /*
1872 * Now copy in the actual argument vector, one page at a time,
1873 * since we don't know how long the vector is (though, we do
1874 * know how many NUL-terminated strings are in the vector).
1875 */
1876 len = 0;
1877 upper_bound = *sizep;
1878 for (; nargv != 0 && len < upper_bound; len += xlen) {
1879 aiov.iov_base = arg;
1880 aiov.iov_len = PAGE_SIZE;
1881 auio.uio_iov = &aiov;
1882 auio.uio_iovcnt = 1;
1883 auio.uio_offset = argv + len;
1884 xlen = PAGE_SIZE - ((argv + len) & PAGE_MASK);
1885 auio.uio_resid = xlen;
1886 auio.uio_segflg = UIO_SYSSPACE;
1887 auio.uio_rw = UIO_READ;
1888 auio.uio_procp = NULL;
1889 error = uvm_io(&p->p_vmspace->vm_map, &auio);
1890 if (error)
1891 goto done;
1892
1893 for (i = 0; i < xlen && nargv != 0; i++) {
1894 if (arg[i] == '\0')
1895 nargv--; /* one full string */
1896 }
1897
1898 /* make sure we don't copyout past the end of the user's buffer */
1899 if (len + i > upper_bound)
1900 i = upper_bound - len;
1901
1902 error = copyout(arg, (char *)where + len, i);
1903 if (error)
1904 break;
1905
1906 if (nargv == 0) {
1907 len += i;
1908 break;
1909 }
1910 }
1911 *sizep = len;
1912
1913 done:
1914 uvmspace_free(p->p_vmspace);
1915
1916 free(arg, M_TEMP);
1917 return (error);
1918 }
1919
1920 #if NPTY > 0
1921 int pty_maxptys(int, int); /* defined in kern/tty_pty.c */
1922
1923 /*
1924 * Validate parameters and get old / set new parameters
1925 * for pty sysctl function.
1926 */
1927 static int
1928 sysctl_pty(void *oldp, size_t *oldlenp, void *newp, size_t newlen)
1929 {
1930 int error = 0;
1931 int oldmax = 0, newmax = 0;
1932
1933 /* get current value of maxptys */
1934 oldmax = pty_maxptys(0, 0);
1935
1936 SYSCTL_SCALAR_CORE_TYP(oldp, oldlenp, &oldmax, int)
1937
1938 if (!error && newp) {
1939 SYSCTL_SCALAR_NEWPCHECK_TYP(newp, newlen, int)
1940 SYSCTL_SCALAR_NEWPCOP_TYP(newp, &newmax, int)
1941
1942 if (newmax != pty_maxptys(newmax, (newp != NULL)))
1943 return (EINVAL);
1944
1945 }
1946
1947 return (error);
1948 }
1949 #endif /* NPTY > 0 */
1950
1951 static int
1952 sysctl_dotkstat(name, namelen, where, sizep, newp)
1953 int *name;
1954 u_int namelen;
1955 void *where;
1956 size_t *sizep;
1957 void *newp;
1958 {
1959 /* all sysctl names at this level are terminal */
1960 if (namelen != 1)
1961 return (ENOTDIR); /* overloaded */
1962
1963 switch (name[0]) {
1964 case KERN_TKSTAT_NIN:
1965 return (sysctl_rdquad(where, sizep, newp, tk_nin));
1966 case KERN_TKSTAT_NOUT:
1967 return (sysctl_rdquad(where, sizep, newp, tk_nout));
1968 case KERN_TKSTAT_CANCC:
1969 return (sysctl_rdquad(where, sizep, newp, tk_cancc));
1970 case KERN_TKSTAT_RAWCC:
1971 return (sysctl_rdquad(where, sizep, newp, tk_rawcc));
1972 default:
1973 return (EOPNOTSUPP);
1974 }
1975 }
1976