xref: /freebsd/sys/kern/kern_mib.c (revision 45ec3b383832e0e21e98feb8ce57f657ea522212)
145ec3b38SPoul-Henning Kamp /*-
245ec3b38SPoul-Henning Kamp  * Copyright (c) 1982, 1986, 1989, 1993
345ec3b38SPoul-Henning Kamp  *	The Regents of the University of California.  All rights reserved.
445ec3b38SPoul-Henning Kamp  *
545ec3b38SPoul-Henning Kamp  * This code is derived from software contributed to Berkeley by
645ec3b38SPoul-Henning Kamp  * Mike Karels at Berkeley Software Design, Inc.
745ec3b38SPoul-Henning Kamp  *
845ec3b38SPoul-Henning Kamp  * Quite extensively rewritten by Poul-Henning Kamp of the FreeBSD
945ec3b38SPoul-Henning Kamp  * project, to make these variables more userfriendly.
1045ec3b38SPoul-Henning Kamp  *
1145ec3b38SPoul-Henning Kamp  * Redistribution and use in source and binary forms, with or without
1245ec3b38SPoul-Henning Kamp  * modification, are permitted provided that the following conditions
1345ec3b38SPoul-Henning Kamp  * are met:
1445ec3b38SPoul-Henning Kamp  * 1. Redistributions of source code must retain the above copyright
1545ec3b38SPoul-Henning Kamp  *    notice, this list of conditions and the following disclaimer.
1645ec3b38SPoul-Henning Kamp  * 2. Redistributions in binary form must reproduce the above copyright
1745ec3b38SPoul-Henning Kamp  *    notice, this list of conditions and the following disclaimer in the
1845ec3b38SPoul-Henning Kamp  *    documentation and/or other materials provided with the distribution.
1945ec3b38SPoul-Henning Kamp  * 3. All advertising materials mentioning features or use of this software
2045ec3b38SPoul-Henning Kamp  *    must display the following acknowledgement:
2145ec3b38SPoul-Henning Kamp  *	This product includes software developed by the University of
2245ec3b38SPoul-Henning Kamp  *	California, Berkeley and its contributors.
2345ec3b38SPoul-Henning Kamp  * 4. Neither the name of the University nor the names of its contributors
2445ec3b38SPoul-Henning Kamp  *    may be used to endorse or promote products derived from this software
2545ec3b38SPoul-Henning Kamp  *    without specific prior written permission.
2645ec3b38SPoul-Henning Kamp  *
2745ec3b38SPoul-Henning Kamp  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2845ec3b38SPoul-Henning Kamp  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2945ec3b38SPoul-Henning Kamp  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3045ec3b38SPoul-Henning Kamp  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
3145ec3b38SPoul-Henning Kamp  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3245ec3b38SPoul-Henning Kamp  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3345ec3b38SPoul-Henning Kamp  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3445ec3b38SPoul-Henning Kamp  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3545ec3b38SPoul-Henning Kamp  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3645ec3b38SPoul-Henning Kamp  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3745ec3b38SPoul-Henning Kamp  * SUCH DAMAGE.
3845ec3b38SPoul-Henning Kamp  *
3945ec3b38SPoul-Henning Kamp  *	@(#)kern_sysctl.c	8.4 (Berkeley) 4/14/94
4045ec3b38SPoul-Henning Kamp  * $Id: kern_sysctl.c,v 1.60 1996/03/11 02:18:22 hsu Exp $
4145ec3b38SPoul-Henning Kamp  */
4245ec3b38SPoul-Henning Kamp 
4345ec3b38SPoul-Henning Kamp #include <sys/param.h>
4445ec3b38SPoul-Henning Kamp #include <sys/kernel.h>
4545ec3b38SPoul-Henning Kamp #include <sys/systm.h>
4645ec3b38SPoul-Henning Kamp #include <sys/sysctl.h>
4745ec3b38SPoul-Henning Kamp #include <sys/conf.h>
4845ec3b38SPoul-Henning Kamp #include <sys/proc.h>
4945ec3b38SPoul-Henning Kamp #include <sys/unistd.h>
5045ec3b38SPoul-Henning Kamp 
5145ec3b38SPoul-Henning Kamp SYSCTL_NODE(, 0,	  sysctl, CTLFLAG_RW, 0,
5245ec3b38SPoul-Henning Kamp 	"Sysctl internal magic");
5345ec3b38SPoul-Henning Kamp SYSCTL_NODE(, CTL_KERN,	  kern,   CTLFLAG_RW, 0,
5445ec3b38SPoul-Henning Kamp 	"High kernel, proc, limits &c");
5545ec3b38SPoul-Henning Kamp SYSCTL_NODE(, CTL_VM,	  vm,     CTLFLAG_RW, 0,
5645ec3b38SPoul-Henning Kamp 	"Virtual memory");
5745ec3b38SPoul-Henning Kamp SYSCTL_NODE(, CTL_VFS,	  vfs,     CTLFLAG_RW, 0,
5845ec3b38SPoul-Henning Kamp 	"File system");
5945ec3b38SPoul-Henning Kamp SYSCTL_NODE(, CTL_NET,	  net,    CTLFLAG_RW, 0,
6045ec3b38SPoul-Henning Kamp 	"Network, (see socket.h)");
6145ec3b38SPoul-Henning Kamp SYSCTL_NODE(, CTL_DEBUG,  debug,  CTLFLAG_RW, 0,
6245ec3b38SPoul-Henning Kamp 	"Debugging");
6345ec3b38SPoul-Henning Kamp SYSCTL_NODE(, CTL_HW,	  hw,     CTLFLAG_RW, 0,
6445ec3b38SPoul-Henning Kamp 	"hardware");
6545ec3b38SPoul-Henning Kamp SYSCTL_NODE(, CTL_MACHDEP, machdep, CTLFLAG_RW, 0,
6645ec3b38SPoul-Henning Kamp 	"machine dependent");
6745ec3b38SPoul-Henning Kamp SYSCTL_NODE(, CTL_USER,	  user,   CTLFLAG_RW, 0,
6845ec3b38SPoul-Henning Kamp 	"user-level");
6945ec3b38SPoul-Henning Kamp 
7045ec3b38SPoul-Henning Kamp SYSCTL_STRING(_kern, KERN_OSRELEASE, osrelease, CTLFLAG_RD, osrelease, 0, "");
7145ec3b38SPoul-Henning Kamp 
7245ec3b38SPoul-Henning Kamp SYSCTL_INT(_kern, KERN_OSREV, osrevision, CTLFLAG_RD, 0, BSD, "");
7345ec3b38SPoul-Henning Kamp 
7445ec3b38SPoul-Henning Kamp SYSCTL_STRING(_kern, KERN_VERSION, version, CTLFLAG_RD, version, 0, "");
7545ec3b38SPoul-Henning Kamp 
7645ec3b38SPoul-Henning Kamp SYSCTL_STRING(_kern, KERN_OSTYPE, ostype, CTLFLAG_RD, ostype, 0, "");
7745ec3b38SPoul-Henning Kamp 
7845ec3b38SPoul-Henning Kamp extern int osreldate;
7945ec3b38SPoul-Henning Kamp SYSCTL_INT(_kern, KERN_OSRELDATE, osreldate, CTLFLAG_RD, &osreldate, 0, "");
8045ec3b38SPoul-Henning Kamp 
8145ec3b38SPoul-Henning Kamp SYSCTL_INT(_kern, KERN_MAXPROC, maxproc, CTLFLAG_RD, &maxproc, 0, "");
8245ec3b38SPoul-Henning Kamp 
8345ec3b38SPoul-Henning Kamp SYSCTL_INT(_kern, KERN_MAXPROCPERUID, maxprocperuid,
8445ec3b38SPoul-Henning Kamp 	CTLFLAG_RD, &maxprocperuid, 0, "");
8545ec3b38SPoul-Henning Kamp 
8645ec3b38SPoul-Henning Kamp SYSCTL_INT(_kern, KERN_ARGMAX, argmax, CTLFLAG_RD, 0, ARG_MAX, "");
8745ec3b38SPoul-Henning Kamp 
8845ec3b38SPoul-Henning Kamp SYSCTL_INT(_kern, KERN_POSIX1, posix1version, CTLFLAG_RD, 0, _POSIX_VERSION, "");
8945ec3b38SPoul-Henning Kamp 
9045ec3b38SPoul-Henning Kamp SYSCTL_INT(_kern, KERN_NGROUPS, ngroups, CTLFLAG_RD, 0, NGROUPS_MAX, "");
9145ec3b38SPoul-Henning Kamp 
9245ec3b38SPoul-Henning Kamp SYSCTL_INT(_kern, KERN_JOB_CONTROL, job_control, CTLFLAG_RD, 0, 1, "");
9345ec3b38SPoul-Henning Kamp 
9445ec3b38SPoul-Henning Kamp #ifdef _POSIX_SAVED_IDS
9545ec3b38SPoul-Henning Kamp SYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD, 0, 1, "");
9645ec3b38SPoul-Henning Kamp #else
9745ec3b38SPoul-Henning Kamp SYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD, 0, 0, "");
9845ec3b38SPoul-Henning Kamp #endif
9945ec3b38SPoul-Henning Kamp 
10045ec3b38SPoul-Henning Kamp char kernelname[MAXPATHLEN] = "/kernel";	/* XXX bloat */
10145ec3b38SPoul-Henning Kamp 
10245ec3b38SPoul-Henning Kamp SYSCTL_STRING(_kern, KERN_BOOTFILE, bootfile,
10345ec3b38SPoul-Henning Kamp 	CTLFLAG_RW, kernelname, sizeof kernelname, "");
10445ec3b38SPoul-Henning Kamp 
10545ec3b38SPoul-Henning Kamp SYSCTL_INT(_hw, HW_NCPU, ncpu, CTLFLAG_RD, 0, 1, "");
10645ec3b38SPoul-Henning Kamp 
10745ec3b38SPoul-Henning Kamp SYSCTL_INT(_hw, HW_BYTEORDER, byteorder, CTLFLAG_RD, 0, BYTE_ORDER, "");
10845ec3b38SPoul-Henning Kamp 
10945ec3b38SPoul-Henning Kamp SYSCTL_INT(_hw, HW_PAGESIZE, pagesize, CTLFLAG_RD, 0, PAGE_SIZE, "");
11045ec3b38SPoul-Henning Kamp 
11145ec3b38SPoul-Henning Kamp char hostname[MAXHOSTNAMELEN];
11245ec3b38SPoul-Henning Kamp 
11345ec3b38SPoul-Henning Kamp SYSCTL_STRING(_kern, KERN_HOSTNAME, hostname, CTLFLAG_RW,
11445ec3b38SPoul-Henning Kamp 	hostname, sizeof(hostname), "");
11545ec3b38SPoul-Henning Kamp 
11645ec3b38SPoul-Henning Kamp int securelevel = -1;
11745ec3b38SPoul-Henning Kamp 
11845ec3b38SPoul-Henning Kamp static int
11945ec3b38SPoul-Henning Kamp sysctl_kern_securelvl SYSCTL_HANDLER_ARGS
12045ec3b38SPoul-Henning Kamp {
12145ec3b38SPoul-Henning Kamp 		int error, level;
12245ec3b38SPoul-Henning Kamp 
12345ec3b38SPoul-Henning Kamp 		level = securelevel;
12445ec3b38SPoul-Henning Kamp 		error = sysctl_handle_int(oidp, &level, 0, req);
12545ec3b38SPoul-Henning Kamp 		if (error || !req->newptr)
12645ec3b38SPoul-Henning Kamp 			return (error);
12745ec3b38SPoul-Henning Kamp 		if (level < securelevel && req->p->p_pid != 1)
12845ec3b38SPoul-Henning Kamp 			return (EPERM);
12945ec3b38SPoul-Henning Kamp 		securelevel = level;
13045ec3b38SPoul-Henning Kamp 		return (error);
13145ec3b38SPoul-Henning Kamp }
13245ec3b38SPoul-Henning Kamp 
13345ec3b38SPoul-Henning Kamp SYSCTL_PROC(_kern, KERN_SECURELVL, securelevel, CTLTYPE_INT|CTLFLAG_RW,
13445ec3b38SPoul-Henning Kamp 	0, 0, sysctl_kern_securelvl, "I", "");
13545ec3b38SPoul-Henning Kamp 
13645ec3b38SPoul-Henning Kamp char domainname[MAXHOSTNAMELEN];
13745ec3b38SPoul-Henning Kamp SYSCTL_STRING(_kern, KERN_DOMAINNAME, domainname, CTLFLAG_RW,
13845ec3b38SPoul-Henning Kamp 	&domainname, sizeof(domainname), "");
13945ec3b38SPoul-Henning Kamp 
14045ec3b38SPoul-Henning Kamp long hostid;
14145ec3b38SPoul-Henning Kamp /* Some trouble here, if sizeof (int) != sizeof (long) */
14245ec3b38SPoul-Henning Kamp SYSCTL_INT(_kern, KERN_HOSTID, hostid, CTLFLAG_RW, &hostid, 0, "");
14345ec3b38SPoul-Henning Kamp 
14445ec3b38SPoul-Henning Kamp /*
14545ec3b38SPoul-Henning Kamp  * This is really cheating.  These actually live in the libc, something
14645ec3b38SPoul-Henning Kamp  * which I'm not quite sure is a good idea anyway, but in order for
14745ec3b38SPoul-Henning Kamp  * getnext and friends to actually work, we define dummies here.
14845ec3b38SPoul-Henning Kamp  */
14945ec3b38SPoul-Henning Kamp 
15045ec3b38SPoul-Henning Kamp SYSCTL_STRING(_user, USER_CS_PATH, cs_path, CTLFLAG_RW, "", 0, "");
15145ec3b38SPoul-Henning Kamp SYSCTL_INT(_user, USER_BC_BASE_MAX, bc_base_max, CTLFLAG_RW, 0, 0, "");
15245ec3b38SPoul-Henning Kamp SYSCTL_INT(_user, USER_BC_DIM_MAX, bc_dim_max, CTLFLAG_RW, 0, 0, "");
15345ec3b38SPoul-Henning Kamp SYSCTL_INT(_user, USER_BC_SCALE_MAX, bc_scale_max, CTLFLAG_RW, 0, 0, "");
15445ec3b38SPoul-Henning Kamp SYSCTL_INT(_user, USER_BC_STRING_MAX, bc_string_max, CTLFLAG_RW, 0, 0, "");
15545ec3b38SPoul-Henning Kamp SYSCTL_INT(_user, USER_COLL_WEIGHTS_MAX, coll_weights_max, CTLFLAG_RW, 0, 0, "");
15645ec3b38SPoul-Henning Kamp SYSCTL_INT(_user, USER_EXPR_NEST_MAX, expr_nest_max, CTLFLAG_RW, 0, 0, "");
15745ec3b38SPoul-Henning Kamp SYSCTL_INT(_user, USER_LINE_MAX, line_max, CTLFLAG_RW, 0, 0, "");
15845ec3b38SPoul-Henning Kamp SYSCTL_INT(_user, USER_RE_DUP_MAX, re_dup_max, CTLFLAG_RW, 0, 0, "");
15945ec3b38SPoul-Henning Kamp SYSCTL_INT(_user, USER_POSIX2_VERSION, posix2_version, CTLFLAG_RW, 0, 0, "");
16045ec3b38SPoul-Henning Kamp SYSCTL_INT(_user, USER_POSIX2_C_BIND, posix2_c_bind, CTLFLAG_RW, 0, 0, "");
16145ec3b38SPoul-Henning Kamp SYSCTL_INT(_user, USER_POSIX2_C_DEV, posix2_c_dev, CTLFLAG_RW, 0, 0, "");
16245ec3b38SPoul-Henning Kamp SYSCTL_INT(_user, USER_POSIX2_CHAR_TERM, posix2_char_term, CTLFLAG_RW, 0, 0, "");
16345ec3b38SPoul-Henning Kamp SYSCTL_INT(_user, USER_POSIX2_FORT_DEV, posix2_fort_dev, CTLFLAG_RW, 0, 0, "");
16445ec3b38SPoul-Henning Kamp SYSCTL_INT(_user, USER_POSIX2_FORT_RUN, posix2_fort_run, CTLFLAG_RW, 0, 0, "");
16545ec3b38SPoul-Henning Kamp SYSCTL_INT(_user, USER_POSIX2_LOCALEDEF, posix2_localedef, CTLFLAG_RW, 0, 0, "");
16645ec3b38SPoul-Henning Kamp SYSCTL_INT(_user, USER_POSIX2_SW_DEV, posix2_sw_dev, CTLFLAG_RW, 0, 0, "");
16745ec3b38SPoul-Henning Kamp SYSCTL_INT(_user, USER_POSIX2_UPE, posix2_upe, CTLFLAG_RW, 0, 0, "");
16845ec3b38SPoul-Henning Kamp SYSCTL_INT(_user, USER_STREAM_MAX, stream_max, CTLFLAG_RW, 0, 0, "");
16945ec3b38SPoul-Henning Kamp SYSCTL_INT(_user, USER_TZNAME_MAX, tzname_max, CTLFLAG_RW, 0, 0, "");
17045ec3b38SPoul-Henning Kamp 
171