xref: /freebsd/sys/kern/kern_mib.c (revision 370f990d30b3a85fe5831e0b1d8cf37eccc65369)
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  * 4. Neither the name of the University nor the names of its contributors
2045ec3b38SPoul-Henning Kamp  *    may be used to endorse or promote products derived from this software
2145ec3b38SPoul-Henning Kamp  *    without specific prior written permission.
2245ec3b38SPoul-Henning Kamp  *
2345ec3b38SPoul-Henning Kamp  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2445ec3b38SPoul-Henning Kamp  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2545ec3b38SPoul-Henning Kamp  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2645ec3b38SPoul-Henning Kamp  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2745ec3b38SPoul-Henning Kamp  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2845ec3b38SPoul-Henning Kamp  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2945ec3b38SPoul-Henning Kamp  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3045ec3b38SPoul-Henning Kamp  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3145ec3b38SPoul-Henning Kamp  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3245ec3b38SPoul-Henning Kamp  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3345ec3b38SPoul-Henning Kamp  * SUCH DAMAGE.
3445ec3b38SPoul-Henning Kamp  *
3545ec3b38SPoul-Henning Kamp  *	@(#)kern_sysctl.c	8.4 (Berkeley) 4/14/94
3645ec3b38SPoul-Henning Kamp  */
3745ec3b38SPoul-Henning Kamp 
38677b542eSDavid E. O'Brien #include <sys/cdefs.h>
39677b542eSDavid E. O'Brien __FBSDID("$FreeBSD$");
40677b542eSDavid E. O'Brien 
412c179010SJohn Baldwin #include "opt_compat.h"
42eacb362fSRobert Watson #include "opt_posix.h"
435f9974aeSWojciech A. Koszek #include "opt_config.h"
44c175d222SRobert Watson 
4545ec3b38SPoul-Henning Kamp #include <sys/param.h>
4645ec3b38SPoul-Henning Kamp #include <sys/kernel.h>
47744b947eSWojciech A. Koszek #include <sys/sbuf.h>
4845ec3b38SPoul-Henning Kamp #include <sys/systm.h>
4945ec3b38SPoul-Henning Kamp #include <sys/sysctl.h>
5045ec3b38SPoul-Henning Kamp #include <sys/proc.h>
5101137630SRobert Watson #include <sys/lock.h>
5201137630SRobert Watson #include <sys/mutex.h>
5375c13541SPoul-Henning Kamp #include <sys/jail.h>
546caa8a15SJohn Baldwin #include <sys/smp.h>
55eeea998cSMike Barcroft #include <sys/unistd.h>
56662f9a69SKATO Takenori 
5745ec3b38SPoul-Henning Kamp SYSCTL_NODE(, 0,	  sysctl, CTLFLAG_RW, 0,
5845ec3b38SPoul-Henning Kamp 	"Sysctl internal magic");
5945ec3b38SPoul-Henning Kamp SYSCTL_NODE(, CTL_KERN,	  kern,   CTLFLAG_RW, 0,
6045ec3b38SPoul-Henning Kamp 	"High kernel, proc, limits &c");
6145ec3b38SPoul-Henning Kamp SYSCTL_NODE(, CTL_VM,	  vm,     CTLFLAG_RW, 0,
6245ec3b38SPoul-Henning Kamp 	"Virtual memory");
634a8b9660SBruce Evans SYSCTL_NODE(, CTL_VFS,	  vfs,     CTLFLAG_RW, 0,
6445ec3b38SPoul-Henning Kamp 	"File system");
6545ec3b38SPoul-Henning Kamp SYSCTL_NODE(, CTL_NET,	  net,    CTLFLAG_RW, 0,
6645ec3b38SPoul-Henning Kamp 	"Network, (see socket.h)");
6745ec3b38SPoul-Henning Kamp SYSCTL_NODE(, CTL_DEBUG,  debug,  CTLFLAG_RW, 0,
6845ec3b38SPoul-Henning Kamp 	"Debugging");
696f13bfc2SPoul-Henning Kamp SYSCTL_NODE(_debug, OID_AUTO,  sizeof,  CTLFLAG_RW, 0,
706f13bfc2SPoul-Henning Kamp 	"Sizeof various things");
7145ec3b38SPoul-Henning Kamp SYSCTL_NODE(, CTL_HW,	  hw,     CTLFLAG_RW, 0,
7245ec3b38SPoul-Henning Kamp 	"hardware");
7345ec3b38SPoul-Henning Kamp SYSCTL_NODE(, CTL_MACHDEP, machdep, CTLFLAG_RW, 0,
7445ec3b38SPoul-Henning Kamp 	"machine dependent");
7545ec3b38SPoul-Henning Kamp SYSCTL_NODE(, CTL_USER,	  user,   CTLFLAG_RW, 0,
7645ec3b38SPoul-Henning Kamp 	"user-level");
778a6472b7SPeter Dufault SYSCTL_NODE(, CTL_P1003_1B,  p1003_1b,   CTLFLAG_RW, 0,
788a6472b7SPeter Dufault 	"p1003_1b, (see p1003_1b.h)");
79644d85f4SPeter Dufault 
80c6dfea0eSMarcel Moolenaar SYSCTL_NODE(, OID_AUTO,  compat, CTLFLAG_RW, 0,
81c6dfea0eSMarcel Moolenaar 	"Compatibility code");
82d0615c64SAndrew R. Reiter SYSCTL_NODE(, OID_AUTO, security, CTLFLAG_RW, 0,
83d0615c64SAndrew R. Reiter      	"Security");
84eacb362fSRobert Watson #ifdef REGRESSION
85eacb362fSRobert Watson SYSCTL_NODE(, OID_AUTO, regression, CTLFLAG_RW, 0,
86eacb362fSRobert Watson      "Regression test MIB");
87eacb362fSRobert Watson #endif
88c6dfea0eSMarcel Moolenaar 
89da1186f2SJuli Mallett SYSCTL_STRING(_kern, OID_AUTO, ident, CTLFLAG_RD,
90c02d7621SJuli Mallett     kern_ident, 0, "Kernel identifier");
91da1186f2SJuli Mallett 
923d177f46SBill Fumerola SYSCTL_STRING(_kern, KERN_OSRELEASE, osrelease, CTLFLAG_RD,
93af1408e3SLuigi Rizzo     osrelease, 0, "Operating system release");
9445ec3b38SPoul-Henning Kamp 
953d177f46SBill Fumerola SYSCTL_INT(_kern, KERN_OSREV, osrevision, CTLFLAG_RD,
963d177f46SBill Fumerola     0, BSD, "Operating system revision");
9745ec3b38SPoul-Henning Kamp 
983d177f46SBill Fumerola SYSCTL_STRING(_kern, KERN_VERSION, version, CTLFLAG_RD,
993d177f46SBill Fumerola     version, 0, "Kernel version");
10045ec3b38SPoul-Henning Kamp 
1013d177f46SBill Fumerola SYSCTL_STRING(_kern, KERN_OSTYPE, ostype, CTLFLAG_RD,
1023d177f46SBill Fumerola     ostype, 0, "Operating system type");
10345ec3b38SPoul-Henning Kamp 
104effb9ebdSEivind Eklund /*
105effb9ebdSEivind Eklund  * NOTICE: The *userland* release date is available in
106effb9ebdSEivind Eklund  * /usr/include/osreldate.h
107effb9ebdSEivind Eklund  */
1083d177f46SBill Fumerola SYSCTL_INT(_kern, KERN_OSRELDATE, osreldate, CTLFLAG_RD,
109effb9ebdSEivind Eklund     &osreldate, 0, "Kernel release date");
11045ec3b38SPoul-Henning Kamp 
111184dcdc7SMike Silbersack SYSCTL_INT(_kern, KERN_MAXPROC, maxproc, CTLFLAG_RDTUN,
1123d177f46SBill Fumerola     &maxproc, 0, "Maximum number of processes");
11345ec3b38SPoul-Henning Kamp 
1143d177f46SBill Fumerola SYSCTL_INT(_kern, KERN_MAXPROCPERUID, maxprocperuid, CTLFLAG_RW,
1153d177f46SBill Fumerola     &maxprocperuid, 0, "Maximum processes allowed per userid");
11645ec3b38SPoul-Henning Kamp 
117184dcdc7SMike Silbersack SYSCTL_INT(_kern, OID_AUTO, maxusers, CTLFLAG_RDTUN,
118ee342e1bSPeter Wemm     &maxusers, 0, "Hint for kernel tuning");
119ee342e1bSPeter Wemm 
1203d177f46SBill Fumerola SYSCTL_INT(_kern, KERN_ARGMAX, argmax, CTLFLAG_RD,
1213d177f46SBill Fumerola     0, ARG_MAX, "Maximum bytes of argument to execve(2)");
12245ec3b38SPoul-Henning Kamp 
1233d177f46SBill Fumerola SYSCTL_INT(_kern, KERN_POSIX1, posix1version, CTLFLAG_RD,
124eeea998cSMike Barcroft     0, _POSIX_VERSION, "Version of POSIX attempting to comply to");
12545ec3b38SPoul-Henning Kamp 
1263d177f46SBill Fumerola SYSCTL_INT(_kern, KERN_NGROUPS, ngroups, CTLFLAG_RD,
1273d177f46SBill Fumerola     0, NGROUPS_MAX, "Maximum number of groups a user can belong to");
12845ec3b38SPoul-Henning Kamp 
1293d177f46SBill Fumerola SYSCTL_INT(_kern, KERN_JOB_CONTROL, job_control, CTLFLAG_RD,
1303d177f46SBill Fumerola     0, 1, "Whether job control is available");
13145ec3b38SPoul-Henning Kamp 
13245ec3b38SPoul-Henning Kamp #ifdef _POSIX_SAVED_IDS
1333d177f46SBill Fumerola SYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD,
1343d177f46SBill Fumerola     0, 1, "Whether saved set-group/user ID is available");
13545ec3b38SPoul-Henning Kamp #else
1363d177f46SBill Fumerola SYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD,
1373d177f46SBill Fumerola     0, 0, "Whether saved set-group/user ID is available");
13845ec3b38SPoul-Henning Kamp #endif
13945ec3b38SPoul-Henning Kamp 
14045ec3b38SPoul-Henning Kamp char kernelname[MAXPATHLEN] = "/kernel";	/* XXX bloat */
14145ec3b38SPoul-Henning Kamp 
1423d177f46SBill Fumerola SYSCTL_STRING(_kern, KERN_BOOTFILE, bootfile, CTLFLAG_RW,
1433d177f46SBill Fumerola     kernelname, sizeof kernelname, "Name of kernel file booted");
14445ec3b38SPoul-Henning Kamp 
1453d177f46SBill Fumerola SYSCTL_INT(_hw, HW_NCPU, ncpu, CTLFLAG_RD,
1463d177f46SBill Fumerola     &mp_ncpus, 0, "Number of active CPUs");
14745ec3b38SPoul-Henning Kamp 
1483d177f46SBill Fumerola SYSCTL_INT(_hw, HW_BYTEORDER, byteorder, CTLFLAG_RD,
1493d177f46SBill Fumerola     0, BYTE_ORDER, "System byte order");
15045ec3b38SPoul-Henning Kamp 
1513d177f46SBill Fumerola SYSCTL_INT(_hw, HW_PAGESIZE, pagesize, CTLFLAG_RD,
1523d177f46SBill Fumerola     0, PAGE_SIZE, "System memory page size");
15345ec3b38SPoul-Henning Kamp 
1540fca57b8SThomas Moestl static int
155ee9f4661SAlexander Kabaev sysctl_kern_arnd(SYSCTL_HANDLER_ARGS)
156ee9f4661SAlexander Kabaev {
157370f990dSAntoine Brodin 	char buf[256];
158370f990dSAntoine Brodin 	size_t len;
159ee9f4661SAlexander Kabaev 
160370f990dSAntoine Brodin 	len = req->oldlen;
161370f990dSAntoine Brodin 	if (len > sizeof(buf))
162370f990dSAntoine Brodin 		len = sizeof(buf);
163370f990dSAntoine Brodin 	arc4rand(buf, len, 0);
164370f990dSAntoine Brodin 	return (SYSCTL_OUT(req, buf, len));
165ee9f4661SAlexander Kabaev }
166ee9f4661SAlexander Kabaev 
167370f990dSAntoine Brodin SYSCTL_PROC(_kern, KERN_ARND, arandom, CTLTYPE_OPAQUE | CTLFLAG_RD,
168370f990dSAntoine Brodin     NULL, 0, sysctl_kern_arnd, "", "arc4rand");
169ee9f4661SAlexander Kabaev 
170ee9f4661SAlexander Kabaev static int
1710fca57b8SThomas Moestl sysctl_hw_physmem(SYSCTL_HANDLER_ARGS)
1720fca57b8SThomas Moestl {
1730fca57b8SThomas Moestl 	u_long val;
1740fca57b8SThomas Moestl 
1750fca57b8SThomas Moestl 	val = ctob(physmem);
1760fca57b8SThomas Moestl 	return (sysctl_handle_long(oidp, &val, 0, req));
1770fca57b8SThomas Moestl }
1780fca57b8SThomas Moestl 
1790fca57b8SThomas Moestl SYSCTL_PROC(_hw, HW_PHYSMEM, physmem, CTLTYPE_ULONG | CTLFLAG_RD,
1800fca57b8SThomas Moestl 	0, 0, sysctl_hw_physmem, "LU", "");
1810fca57b8SThomas Moestl 
1820fca57b8SThomas Moestl static int
183a0915044SWes Peters sysctl_hw_realmem(SYSCTL_HANDLER_ARGS)
184a0915044SWes Peters {
185a0915044SWes Peters 	u_long val;
186a0915044SWes Peters 	val = ctob(realmem);
187a0915044SWes Peters 	return (sysctl_handle_long(oidp, &val, 0, req));
188a0915044SWes Peters }
189a0915044SWes Peters SYSCTL_PROC(_hw, HW_REALMEM, realmem, CTLTYPE_ULONG | CTLFLAG_RD,
190a0915044SWes Peters 	0, 0, sysctl_hw_realmem, "LU", "");
191a0915044SWes Peters static int
1920fca57b8SThomas Moestl sysctl_hw_usermem(SYSCTL_HANDLER_ARGS)
1930fca57b8SThomas Moestl {
1940fca57b8SThomas Moestl 	u_long val;
1950fca57b8SThomas Moestl 
1962feb50bfSAttilio Rao 	val = ctob(physmem - cnt.v_wire_count);
1970fca57b8SThomas Moestl 	return (sysctl_handle_long(oidp, &val, 0, req));
1980fca57b8SThomas Moestl }
1990fca57b8SThomas Moestl 
2000fca57b8SThomas Moestl SYSCTL_PROC(_hw, HW_USERMEM, usermem, CTLTYPE_ULONG | CTLFLAG_RD,
2010fca57b8SThomas Moestl 	0, 0, sysctl_hw_usermem, "LU", "");
2020fca57b8SThomas Moestl 
2030fca57b8SThomas Moestl SYSCTL_ULONG(_hw, OID_AUTO, availpages, CTLFLAG_RD, &physmem, 0, "");
2040fca57b8SThomas Moestl 
205664f8517SKATO Takenori static char	machine_arch[] = MACHINE_ARCH;
206664f8517SKATO Takenori SYSCTL_STRING(_hw, HW_MACHINE_ARCH, machine_arch, CTLFLAG_RD,
2073d177f46SBill Fumerola     machine_arch, 0, "System architecture");
208664f8517SKATO Takenori 
20945ec3b38SPoul-Henning Kamp char hostname[MAXHOSTNAMELEN];
21045ec3b38SPoul-Henning Kamp 
21175c13541SPoul-Henning Kamp static int
21282d9ae4eSPoul-Henning Kamp sysctl_hostname(SYSCTL_HANDLER_ARGS)
21375c13541SPoul-Henning Kamp {
2141e4b531bSRobert Watson 	struct prison *pr;
21501137630SRobert Watson 	char tmphostname[MAXHOSTNAMELEN];
21675c13541SPoul-Henning Kamp 	int error;
21775c13541SPoul-Henning Kamp 
218a854ed98SJohn Baldwin 	pr = req->td->td_ucred->cr_prison;
2191e4b531bSRobert Watson 	if (pr != NULL) {
22083f1e257SRobert Watson 		if (!jail_set_hostname_allowed && req->newptr)
2216c144e75SRobert Watson 			return (EPERM);
22201137630SRobert Watson 		/*
22301137630SRobert Watson 		 * Process is in jail, so make a local copy of jail
22401137630SRobert Watson 		 * hostname to get/set so we don't have to hold the jail
22501137630SRobert Watson 		 * mutex during the sysctl copyin/copyout activities.
22601137630SRobert Watson 		 */
22701137630SRobert Watson 		mtx_lock(&pr->pr_mtx);
22801137630SRobert Watson 		bcopy(pr->pr_host, tmphostname, MAXHOSTNAMELEN);
22901137630SRobert Watson 		mtx_unlock(&pr->pr_mtx);
23001137630SRobert Watson 
23101137630SRobert Watson 		error = sysctl_handle_string(oidp, tmphostname,
2321e4b531bSRobert Watson 		    sizeof pr->pr_host, req);
23301137630SRobert Watson 
23401137630SRobert Watson 		if (req->newptr != NULL && error == 0) {
23501137630SRobert Watson 			/*
23601137630SRobert Watson 			 * Copy the locally set hostname to the jail, if
23701137630SRobert Watson 			 * appropriate.
23801137630SRobert Watson 			 */
23901137630SRobert Watson 			mtx_lock(&pr->pr_mtx);
24001137630SRobert Watson 			bcopy(tmphostname, pr->pr_host, MAXHOSTNAMELEN);
24101137630SRobert Watson 			mtx_unlock(&pr->pr_mtx);
24201137630SRobert Watson 		}
2436c144e75SRobert Watson 	} else
24475c13541SPoul-Henning Kamp 		error = sysctl_handle_string(oidp,
24575c13541SPoul-Henning Kamp 		    hostname, sizeof hostname, req);
24675c13541SPoul-Henning Kamp 	return (error);
24775c13541SPoul-Henning Kamp }
24875c13541SPoul-Henning Kamp 
24975c13541SPoul-Henning Kamp SYSCTL_PROC(_kern, KERN_HOSTNAME, hostname,
25075c13541SPoul-Henning Kamp        CTLTYPE_STRING|CTLFLAG_RW|CTLFLAG_PRISON,
2513d177f46SBill Fumerola        0, 0, sysctl_hostname, "A", "Hostname");
25245ec3b38SPoul-Henning Kamp 
253eacb362fSRobert Watson static int	regression_securelevel_nonmonotonic = 0;
254c175d222SRobert Watson 
2551e4b531bSRobert Watson #ifdef REGRESSION
256c175d222SRobert Watson SYSCTL_INT(_regression, OID_AUTO, securelevel_nonmonotonic, CTLFLAG_RW,
257c175d222SRobert Watson     &regression_securelevel_nonmonotonic, 0, "securelevel may be lowered");
258eacb362fSRobert Watson #endif
259c175d222SRobert Watson 
26045ec3b38SPoul-Henning Kamp int securelevel = -1;
26151da11a2SMark Murray static struct mtx securelevel_mtx;
26272a492caSAndrew R. Reiter 
26372a492caSAndrew R. Reiter MTX_SYSINIT(securelevel_lock, &securelevel_mtx, "securelevel mutex lock",
26472a492caSAndrew R. Reiter     MTX_DEF);
26545ec3b38SPoul-Henning Kamp 
26645ec3b38SPoul-Henning Kamp static int
26782d9ae4eSPoul-Henning Kamp sysctl_kern_securelvl(SYSCTL_HANDLER_ARGS)
26845ec3b38SPoul-Henning Kamp {
269d3c9fa04SRobert Watson 	struct prison *pr;
27045ec3b38SPoul-Henning Kamp 	int error, level;
27145ec3b38SPoul-Henning Kamp 
272a854ed98SJohn Baldwin 	pr = req->td->td_ucred->cr_prison;
273d3c9fa04SRobert Watson 
2748a528812SRobert Watson 	/*
2759afc1eeeSRobert Watson 	 * If the process is in jail, return the maximum of the global and
2764261ed50SRobert Watson 	 * local levels; otherwise, return the global level.  Perform a
27778bb1895SRobert Watson 	 * lockless read since the securelevel is an integer.
2788a528812SRobert Watson 	 */
2794261ed50SRobert Watson 	if (pr != NULL)
280d3c9fa04SRobert Watson 		level = imax(securelevel, pr->pr_securelevel);
2814261ed50SRobert Watson 	else
28245ec3b38SPoul-Henning Kamp 		level = securelevel;
28345ec3b38SPoul-Henning Kamp 	error = sysctl_handle_int(oidp, &level, 0, req);
28445ec3b38SPoul-Henning Kamp 	if (error || !req->newptr)
28545ec3b38SPoul-Henning Kamp 		return (error);
2868a528812SRobert Watson 	/*
2878a528812SRobert Watson 	 * Permit update only if the new securelevel exceeds the
2888a528812SRobert Watson 	 * global level, and local level if any.
2898a528812SRobert Watson 	 */
290d3c9fa04SRobert Watson 	if (pr != NULL) {
29101137630SRobert Watson 		mtx_lock(&pr->pr_mtx);
2921e4b531bSRobert Watson 		if (!regression_securelevel_nonmonotonic &&
29301137630SRobert Watson 		    (level < imax(securelevel, pr->pr_securelevel))) {
29401137630SRobert Watson 			mtx_unlock(&pr->pr_mtx);
2958a528812SRobert Watson 			return (EPERM);
29601137630SRobert Watson 		}
297d3c9fa04SRobert Watson 		pr->pr_securelevel = level;
29801137630SRobert Watson 		mtx_unlock(&pr->pr_mtx);
2998a528812SRobert Watson 	} else {
30072a492caSAndrew R. Reiter 		mtx_lock(&securelevel_mtx);
3011e4b531bSRobert Watson 		if (!regression_securelevel_nonmonotonic &&
30272a492caSAndrew R. Reiter 		    (level < securelevel)) {
30372a492caSAndrew R. Reiter 			mtx_unlock(&securelevel_mtx);
30445ec3b38SPoul-Henning Kamp 			return (EPERM);
30572a492caSAndrew R. Reiter 		}
30645ec3b38SPoul-Henning Kamp 		securelevel = level;
30772a492caSAndrew R. Reiter 		mtx_unlock(&securelevel_mtx);
3088a528812SRobert Watson 	}
30945ec3b38SPoul-Henning Kamp 	return (error);
31045ec3b38SPoul-Henning Kamp }
31145ec3b38SPoul-Henning Kamp 
3128a528812SRobert Watson SYSCTL_PROC(_kern, KERN_SECURELVL, securelevel,
3138a528812SRobert Watson     CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_PRISON, 0, 0, sysctl_kern_securelvl,
3148a528812SRobert Watson     "I", "Current secure level");
315e812e491SRobert Watson 
3165f9974aeSWojciech A. Koszek #ifdef INCLUDE_CONFIG_FILE
317744b947eSWojciech A. Koszek /* Actual kernel configuration options. */
318744b947eSWojciech A. Koszek extern char kernconfstring[];
319744b947eSWojciech A. Koszek 
320744b947eSWojciech A. Koszek static int
321744b947eSWojciech A. Koszek sysctl_kern_config(SYSCTL_HANDLER_ARGS)
322744b947eSWojciech A. Koszek {
323cfa7a8beSWarner Losh 	return (sysctl_handle_string(oidp, kernconfstring,
324cfa7a8beSWarner Losh 	    strlen(kernconfstring), req));
325cfa7a8beSWarner Losh }
326744b947eSWojciech A. Koszek 
327744b947eSWojciech A. Koszek SYSCTL_PROC(_kern, OID_AUTO, conftxt, CTLTYPE_STRING|CTLFLAG_RW,
328744b947eSWojciech A. Koszek     0, 0, sysctl_kern_config, "", "Kernel configuration file");
3293627f737SWarner Losh #endif
330744b947eSWojciech A. Koszek 
33145ec3b38SPoul-Henning Kamp char domainname[MAXHOSTNAMELEN];
332949f380fSGarrett Wollman SYSCTL_STRING(_kern, KERN_NISDOMAINNAME, domainname, CTLFLAG_RW,
3333d177f46SBill Fumerola     &domainname, sizeof(domainname), "Name of the current YP/NIS domain");
33445ec3b38SPoul-Henning Kamp 
335eacb362fSRobert Watson u_long hostid;
336f83ae79fSJim Pirzyk SYSCTL_ULONG(_kern, KERN_HOSTID, hostid, CTLFLAG_RW, &hostid, 0, "Host ID");
33782068fe7SPawel Jakub Dawidek char hostuuid[64] = "00000000-0000-0000-0000-000000000000";
33882068fe7SPawel Jakub Dawidek SYSCTL_STRING(_kern, KERN_HOSTUUID, hostuuid, CTLFLAG_RW, hostuuid,
33982068fe7SPawel Jakub Dawidek     sizeof(hostuuid), "Host UUID");
34045ec3b38SPoul-Henning Kamp 
3410deabe7eSJohn Baldwin SYSCTL_NODE(_kern, OID_AUTO, features, CTLFLAG_RD, 0, "Kernel Features");
3420deabe7eSJohn Baldwin 
3432c179010SJohn Baldwin #ifdef COMPAT_FREEBSD4
3442c179010SJohn Baldwin FEATURE(compat_freebsd4, "Compatible with FreeBSD 4");
3452c179010SJohn Baldwin #endif
3462c179010SJohn Baldwin 
3472c179010SJohn Baldwin #ifdef COMPAT_FREEBSD5
3482c179010SJohn Baldwin FEATURE(compat_freebsd5, "Compatible with FreeBSD 5");
3492c179010SJohn Baldwin #endif
3502c179010SJohn Baldwin 
3512c179010SJohn Baldwin #ifdef COMPAT_FREEBSD6
3522c179010SJohn Baldwin FEATURE(compat_freebsd6, "Compatible with FreeBSD 6");
3532c179010SJohn Baldwin #endif
3542c179010SJohn Baldwin 
3552c179010SJohn Baldwin #ifdef COMPAT_FREEBSD7
3562c179010SJohn Baldwin FEATURE(compat_freebsd7, "Compatible with FreeBSD 7");
3572c179010SJohn Baldwin #endif
3582c179010SJohn Baldwin 
35945ec3b38SPoul-Henning Kamp /*
36045ec3b38SPoul-Henning Kamp  * This is really cheating.  These actually live in the libc, something
36145ec3b38SPoul-Henning Kamp  * which I'm not quite sure is a good idea anyway, but in order for
36245ec3b38SPoul-Henning Kamp  * getnext and friends to actually work, we define dummies here.
36345ec3b38SPoul-Henning Kamp  */
3643d177f46SBill Fumerola SYSCTL_STRING(_user, USER_CS_PATH, cs_path, CTLFLAG_RD,
3653d177f46SBill Fumerola     "", 0, "PATH that finds all the standard utilities");
3663d177f46SBill Fumerola SYSCTL_INT(_user, USER_BC_BASE_MAX, bc_base_max, CTLFLAG_RD,
3673d177f46SBill Fumerola     0, 0, "Max ibase/obase values in bc(1)");
3683d177f46SBill Fumerola SYSCTL_INT(_user, USER_BC_DIM_MAX, bc_dim_max, CTLFLAG_RD,
3693d177f46SBill Fumerola     0, 0, "Max array size in bc(1)");
3703d177f46SBill Fumerola SYSCTL_INT(_user, USER_BC_SCALE_MAX, bc_scale_max, CTLFLAG_RD,
3713d177f46SBill Fumerola     0, 0, "Max scale value in bc(1)");
3723d177f46SBill Fumerola SYSCTL_INT(_user, USER_BC_STRING_MAX, bc_string_max, CTLFLAG_RD,
3733d177f46SBill Fumerola     0, 0, "Max string length in bc(1)");
3743d177f46SBill Fumerola SYSCTL_INT(_user, USER_COLL_WEIGHTS_MAX, coll_weights_max, CTLFLAG_RD,
3753d177f46SBill Fumerola     0, 0, "Maximum number of weights assigned to an LC_COLLATE locale entry");
3767c1aacb5SBruce Evans SYSCTL_INT(_user, USER_EXPR_NEST_MAX, expr_nest_max, CTLFLAG_RD, 0, 0, "");
3773d177f46SBill Fumerola SYSCTL_INT(_user, USER_LINE_MAX, line_max, CTLFLAG_RD,
3783d177f46SBill Fumerola     0, 0, "Max length (bytes) of a text-processing utility's input line");
3793d177f46SBill Fumerola SYSCTL_INT(_user, USER_RE_DUP_MAX, re_dup_max, CTLFLAG_RD,
3803d177f46SBill Fumerola     0, 0, "Maximum number of repeats of a regexp permitted");
3813d177f46SBill Fumerola SYSCTL_INT(_user, USER_POSIX2_VERSION, posix2_version, CTLFLAG_RD,
3823d177f46SBill Fumerola     0, 0,
3833d177f46SBill Fumerola     "The version of POSIX 1003.2 with which the system attempts to comply");
3843d177f46SBill Fumerola SYSCTL_INT(_user, USER_POSIX2_C_BIND, posix2_c_bind, CTLFLAG_RD,
3853d177f46SBill Fumerola     0, 0, "Whether C development supports the C bindings option");
3863d177f46SBill Fumerola SYSCTL_INT(_user, USER_POSIX2_C_DEV, posix2_c_dev, CTLFLAG_RD,
3873d177f46SBill Fumerola     0, 0, "Whether system supports the C development utilities option");
3883d177f46SBill Fumerola SYSCTL_INT(_user, USER_POSIX2_CHAR_TERM, posix2_char_term, CTLFLAG_RD,
3893d177f46SBill Fumerola     0, 0, "");
3903d177f46SBill Fumerola SYSCTL_INT(_user, USER_POSIX2_FORT_DEV, posix2_fort_dev, CTLFLAG_RD,
3913d177f46SBill Fumerola     0, 0, "Whether system supports FORTRAN development utilities");
3923d177f46SBill Fumerola SYSCTL_INT(_user, USER_POSIX2_FORT_RUN, posix2_fort_run, CTLFLAG_RD,
3933d177f46SBill Fumerola     0, 0, "Whether system supports FORTRAN runtime utilities");
3943d177f46SBill Fumerola SYSCTL_INT(_user, USER_POSIX2_LOCALEDEF, posix2_localedef, CTLFLAG_RD,
3953d177f46SBill Fumerola     0, 0, "Whether system supports creation of locales");
3963d177f46SBill Fumerola SYSCTL_INT(_user, USER_POSIX2_SW_DEV, posix2_sw_dev, CTLFLAG_RD,
3973d177f46SBill Fumerola     0, 0, "Whether system supports software development utilities");
3983d177f46SBill Fumerola SYSCTL_INT(_user, USER_POSIX2_UPE, posix2_upe, CTLFLAG_RD,
3993d177f46SBill Fumerola     0, 0, "Whether system supports the user portability utilities");
4003d177f46SBill Fumerola SYSCTL_INT(_user, USER_STREAM_MAX, stream_max, CTLFLAG_RD,
4013d177f46SBill Fumerola     0, 0, "Min Maximum number of streams a process may have open at one time");
4023d177f46SBill Fumerola SYSCTL_INT(_user, USER_TZNAME_MAX, tzname_max, CTLFLAG_RD,
4033d177f46SBill Fumerola     0, 0, "Min Maximum number of types supported for timezone names");
4046f13bfc2SPoul-Henning Kamp 
4056f13bfc2SPoul-Henning Kamp #include <sys/vnode.h>
4066f13bfc2SPoul-Henning Kamp SYSCTL_INT(_debug_sizeof, OID_AUTO, vnode, CTLFLAG_RD,
4076f13bfc2SPoul-Henning Kamp     0, sizeof(struct vnode), "sizeof(struct vnode)");
4086f13bfc2SPoul-Henning Kamp 
4096f13bfc2SPoul-Henning Kamp SYSCTL_INT(_debug_sizeof, OID_AUTO, proc, CTLFLAG_RD,
4106f13bfc2SPoul-Henning Kamp     0, sizeof(struct proc), "sizeof(struct proc)");
411d7bf417dSPoul-Henning Kamp 
4129626b608SPoul-Henning Kamp #include <sys/bio.h>
4138c125869SPoul-Henning Kamp #include <sys/buf.h>
4148c125869SPoul-Henning Kamp SYSCTL_INT(_debug_sizeof, OID_AUTO, bio, CTLFLAG_RD,
4158c125869SPoul-Henning Kamp     0, sizeof(struct bio), "sizeof(struct bio)");
4168c125869SPoul-Henning Kamp SYSCTL_INT(_debug_sizeof, OID_AUTO, buf, CTLFLAG_RD,
4178c125869SPoul-Henning Kamp     0, sizeof(struct buf), "sizeof(struct buf)");
418d5a08a60SJake Burkholder 
419d5a08a60SJake Burkholder #include <sys/user.h>
420d5a08a60SJake Burkholder SYSCTL_INT(_debug_sizeof, OID_AUTO, kinfo_proc, CTLFLAG_RD,
421d5a08a60SJake Burkholder     0, sizeof(struct kinfo_proc), "sizeof(struct kinfo_proc)");
422a360a43dSJake Burkholder 
423e548a1d4SJake Burkholder /* XXX compatibility, remove for 6.0 */
424e548a1d4SJake Burkholder #include <sys/imgact.h>
425e548a1d4SJake Burkholder #include <sys/imgact_elf.h>
426e548a1d4SJake Burkholder SYSCTL_INT(_kern, OID_AUTO, fallback_elf_brand, CTLFLAG_RW,
427e548a1d4SJake Burkholder     &__elfN(fallback_brand), sizeof(__elfN(fallback_brand)),
428e548a1d4SJake Burkholder     "compatibility for kern.fallback_elf_brand");
429