kern_mib.c revision 91406
115103Sphk/*-
215103Sphk * Copyright (c) 1982, 1986, 1989, 1993
315103Sphk *	The Regents of the University of California.  All rights reserved.
415103Sphk *
515103Sphk * This code is derived from software contributed to Berkeley by
615103Sphk * Mike Karels at Berkeley Software Design, Inc.
715103Sphk *
815103Sphk * Quite extensively rewritten by Poul-Henning Kamp of the FreeBSD
915103Sphk * project, to make these variables more userfriendly.
1015103Sphk *
1115103Sphk * Redistribution and use in source and binary forms, with or without
1215103Sphk * modification, are permitted provided that the following conditions
1315103Sphk * are met:
1415103Sphk * 1. Redistributions of source code must retain the above copyright
1515103Sphk *    notice, this list of conditions and the following disclaimer.
1615103Sphk * 2. Redistributions in binary form must reproduce the above copyright
1715103Sphk *    notice, this list of conditions and the following disclaimer in the
1815103Sphk *    documentation and/or other materials provided with the distribution.
1915103Sphk * 3. All advertising materials mentioning features or use of this software
2015103Sphk *    must display the following acknowledgement:
2115103Sphk *	This product includes software developed by the University of
2215103Sphk *	California, Berkeley and its contributors.
2315103Sphk * 4. Neither the name of the University nor the names of its contributors
2415103Sphk *    may be used to endorse or promote products derived from this software
2515103Sphk *    without specific prior written permission.
2615103Sphk *
2715103Sphk * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2815103Sphk * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2915103Sphk * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3015103Sphk * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
3115103Sphk * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3215103Sphk * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3315103Sphk * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3415103Sphk * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3515103Sphk * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3615103Sphk * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3715103Sphk * SUCH DAMAGE.
3815103Sphk *
3915103Sphk *	@(#)kern_sysctl.c	8.4 (Berkeley) 4/14/94
4050477Speter * $FreeBSD: head/sys/kern/kern_mib.c 91406 2002-02-27 18:32:23Z jhb $
4115103Sphk */
4215103Sphk
4386190Srwatson#include "opt_posix.h"
4484611Srwatson
4515103Sphk#include <sys/param.h>
4615103Sphk#include <sys/kernel.h>
4715103Sphk#include <sys/systm.h>
4815103Sphk#include <sys/sysctl.h>
4915103Sphk#include <sys/proc.h>
5087275Srwatson#include <sys/lock.h>
5187275Srwatson#include <sys/mutex.h>
5246155Sphk#include <sys/jail.h>
5376078Sjhb#include <sys/smp.h>
5428918Skato
5515103SphkSYSCTL_NODE(, 0,	  sysctl, CTLFLAG_RW, 0,
5615103Sphk	"Sysctl internal magic");
5715103SphkSYSCTL_NODE(, CTL_KERN,	  kern,   CTLFLAG_RW, 0,
5815103Sphk	"High kernel, proc, limits &c");
5915103SphkSYSCTL_NODE(, CTL_VM,	  vm,     CTLFLAG_RW, 0,
6015103Sphk	"Virtual memory");
6123382SbdeSYSCTL_NODE(, CTL_VFS,	  vfs,     CTLFLAG_RW, 0,
6215103Sphk	"File system");
6315103SphkSYSCTL_NODE(, CTL_NET,	  net,    CTLFLAG_RW, 0,
6415103Sphk	"Network, (see socket.h)");
6515103SphkSYSCTL_NODE(, CTL_DEBUG,  debug,  CTLFLAG_RW, 0,
6615103Sphk	"Debugging");
6748891SphkSYSCTL_NODE(_debug, OID_AUTO,  sizeof,  CTLFLAG_RW, 0,
6848891Sphk	"Sizeof various things");
6915103SphkSYSCTL_NODE(, CTL_HW,	  hw,     CTLFLAG_RW, 0,
7015103Sphk	"hardware");
7115103SphkSYSCTL_NODE(, CTL_MACHDEP, machdep, CTLFLAG_RW, 0,
7215103Sphk	"machine dependent");
7315103SphkSYSCTL_NODE(, CTL_USER,	  user,   CTLFLAG_RW, 0,
7415103Sphk	"user-level");
7534925SdufaultSYSCTL_NODE(, CTL_P1003_1B,  p1003_1b,   CTLFLAG_RW, 0,
7634925Sdufault	"p1003_1b, (see p1003_1b.h)");
7734029Sdufault
7850465SmarcelSYSCTL_NODE(, OID_AUTO,  compat, CTLFLAG_RW, 0,
7950465Smarcel	"Compatibility code");
8089414SarrSYSCTL_NODE(, OID_AUTO, security, CTLFLAG_RW, 0,
8189414Sarr     	"Security");
8286190Srwatson#ifdef REGRESSION
8386190SrwatsonSYSCTL_NODE(, OID_AUTO, regression, CTLFLAG_RW, 0,
8486190Srwatson     "Regression test MIB");
8586190Srwatson#endif
8650465Smarcel
8786189SrwatsonSYSCTL_STRING(_kern, KERN_OSRELEASE, osrelease, CTLFLAG_RD,
8888019Sluigi    osrelease, 0, "Operating system release");
8915103Sphk
9086189SrwatsonSYSCTL_INT(_kern, KERN_OSREV, osrevision, CTLFLAG_RD,
9146381Sbillf    0, BSD, "Operating system revision");
9215103Sphk
9386189SrwatsonSYSCTL_STRING(_kern, KERN_VERSION, version, CTLFLAG_RD,
9446381Sbillf    version, 0, "Kernel version");
9515103Sphk
9686189SrwatsonSYSCTL_STRING(_kern, KERN_OSTYPE, ostype, CTLFLAG_RD,
9746381Sbillf    ostype, 0, "Operating system type");
9815103Sphk
9915103Sphkextern int osreldate;
10086189SrwatsonSYSCTL_INT(_kern, KERN_OSRELDATE, osreldate, CTLFLAG_RD,
10146381Sbillf    &osreldate, 0, "Operating system release date");
10215103Sphk
10386189SrwatsonSYSCTL_INT(_kern, KERN_MAXPROC, maxproc, CTLFLAG_RD,
10446381Sbillf    &maxproc, 0, "Maximum number of processes");
10515103Sphk
10686189SrwatsonSYSCTL_INT(_kern, KERN_MAXPROCPERUID, maxprocperuid, CTLFLAG_RW,
10746381Sbillf    &maxprocperuid, 0, "Maximum processes allowed per userid");
10815103Sphk
10986189SrwatsonSYSCTL_INT(_kern, OID_AUTO, maxusers, CTLFLAG_RD,
11080418Speter    &maxusers, 0, "Hint for kernel tuning");
11180418Speter
11286189SrwatsonSYSCTL_INT(_kern, KERN_ARGMAX, argmax, CTLFLAG_RD,
11346381Sbillf    0, ARG_MAX, "Maximum bytes of argument to execve(2)");
11415103Sphk
11586189SrwatsonSYSCTL_INT(_kern, KERN_POSIX1, posix1version, CTLFLAG_RD,
11646381Sbillf    0, _KPOSIX_VERSION, "Version of POSIX attempting to comply to");
11715103Sphk
11886189SrwatsonSYSCTL_INT(_kern, KERN_NGROUPS, ngroups, CTLFLAG_RD,
11946381Sbillf    0, NGROUPS_MAX, "Maximum number of groups a user can belong to");
12015103Sphk
12186189SrwatsonSYSCTL_INT(_kern, KERN_JOB_CONTROL, job_control, CTLFLAG_RD,
12246381Sbillf    0, 1, "Whether job control is available");
12315103Sphk
12415103Sphk#ifdef _POSIX_SAVED_IDS
12586189SrwatsonSYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD,
12646381Sbillf    0, 1, "Whether saved set-group/user ID is available");
12715103Sphk#else
12886189SrwatsonSYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD,
12946381Sbillf    0, 0, "Whether saved set-group/user ID is available");
13015103Sphk#endif
13115103Sphk
13215103Sphkchar kernelname[MAXPATHLEN] = "/kernel";	/* XXX bloat */
13315103Sphk
13486189SrwatsonSYSCTL_STRING(_kern, KERN_BOOTFILE, bootfile, CTLFLAG_RW,
13546381Sbillf    kernelname, sizeof kernelname, "Name of kernel file booted");
13615103Sphk
13731990Sgpalmer#ifdef SMP
13886189SrwatsonSYSCTL_INT(_hw, HW_NCPU, ncpu, CTLFLAG_RD,
13946381Sbillf    &mp_ncpus, 0, "Number of active CPUs");
14031990Sgpalmer#else
14186189SrwatsonSYSCTL_INT(_hw, HW_NCPU, ncpu, CTLFLAG_RD,
14246381Sbillf    0, 1, "Number of active CPUs");
14331990Sgpalmer#endif
14415103Sphk
14586189SrwatsonSYSCTL_INT(_hw, HW_BYTEORDER, byteorder, CTLFLAG_RD,
14646381Sbillf    0, BYTE_ORDER, "System byte order");
14715103Sphk
14886189SrwatsonSYSCTL_INT(_hw, HW_PAGESIZE, pagesize, CTLFLAG_RD,
14946381Sbillf    0, PAGE_SIZE, "System memory page size");
15015103Sphk
15128885Skatostatic char	machine_arch[] = MACHINE_ARCH;
15228885SkatoSYSCTL_STRING(_hw, HW_MACHINE_ARCH, machine_arch, CTLFLAG_RD,
15346381Sbillf    machine_arch, 0, "System architecture");
15428885Skato
15515103Sphkchar hostname[MAXHOSTNAMELEN];
15615103Sphk
15746155Sphkstatic int
15862573Sphksysctl_hostname(SYSCTL_HANDLER_ARGS)
15946155Sphk{
16087072Srwatson	struct prison *pr;
16187275Srwatson	char tmphostname[MAXHOSTNAMELEN];
16246155Sphk	int error;
16315103Sphk
16491406Sjhb	pr = req->td->td_ucred->cr_prison;
16587072Srwatson	if (pr != NULL) {
16657163Srwatson		if (!jail_set_hostname_allowed && req->newptr)
16786190Srwatson			return (EPERM);
16887275Srwatson		/*
16987275Srwatson		 * Process is in jail, so make a local copy of jail
17087275Srwatson		 * hostname to get/set so we don't have to hold the jail
17187275Srwatson		 * mutex during the sysctl copyin/copyout activities.
17287275Srwatson		 */
17387275Srwatson		mtx_lock(&pr->pr_mtx);
17487275Srwatson		bcopy(pr->pr_host, tmphostname, MAXHOSTNAMELEN);
17587275Srwatson		mtx_unlock(&pr->pr_mtx);
17687275Srwatson
17787275Srwatson		error = sysctl_handle_string(oidp, tmphostname,
17887072Srwatson		    sizeof pr->pr_host, req);
17987275Srwatson
18087275Srwatson		if (req->newptr != NULL && error == 0) {
18187275Srwatson			/*
18287275Srwatson			 * Copy the locally set hostname to the jail, if
18387275Srwatson			 * appropriate.
18487275Srwatson			 */
18587275Srwatson			mtx_lock(&pr->pr_mtx);
18687275Srwatson			bcopy(tmphostname, pr->pr_host, MAXHOSTNAMELEN);
18787275Srwatson			mtx_unlock(&pr->pr_mtx);
18887275Srwatson		}
18957111Srwatson	} else
19086189Srwatson		error = sysctl_handle_string(oidp,
19146155Sphk		    hostname, sizeof hostname, req);
19246155Sphk	return (error);
19346155Sphk}
19446155Sphk
19586189SrwatsonSYSCTL_PROC(_kern, KERN_HOSTNAME, hostname,
19646155Sphk       CTLTYPE_STRING|CTLFLAG_RW|CTLFLAG_PRISON,
19746381Sbillf       0, 0, sysctl_hostname, "A", "Hostname");
19846155Sphk
19986190Srwatsonstatic int	regression_securelevel_nonmonotonic = 0;
20084611Srwatson
20187072Srwatson#ifdef REGRESSION
20284611SrwatsonSYSCTL_INT(_regression, OID_AUTO, securelevel_nonmonotonic, CTLFLAG_RW,
20384611Srwatson    &regression_securelevel_nonmonotonic, 0, "securelevel may be lowered");
20486190Srwatson#endif
20584611Srwatson
20615103Sphkint securelevel = -1;
20715103Sphk
20815103Sphkstatic int
20962573Sphksysctl_kern_securelvl(SYSCTL_HANDLER_ARGS)
21015103Sphk{
21186145Srwatson	struct prison *pr;
21286140Srwatson	int error, level;
21315103Sphk
21491406Sjhb	pr = req->td->td_ucred->cr_prison;
21586145Srwatson
21686140Srwatson	/*
21786140Srwatson	 * If the process is in jail, return the maximum of the global and
21886140Srwatson	 * local levels; otherwise, return the global level.
21986140Srwatson	 */
22087275Srwatson	if (pr != NULL) {
22187275Srwatson		mtx_lock(&pr->pr_mtx);
22286145Srwatson		level = imax(securelevel, pr->pr_securelevel);
22387275Srwatson		mtx_unlock(&pr->pr_mtx);
22487275Srwatson	} else
22586140Srwatson		level = securelevel;
22686140Srwatson	error = sysctl_handle_int(oidp, &level, 0, req);
22786140Srwatson	if (error || !req->newptr)
22886140Srwatson		return (error);
22986140Srwatson	/*
23086140Srwatson	 * Permit update only if the new securelevel exceeds the
23186140Srwatson	 * global level, and local level if any.
23286140Srwatson	 */
23386145Srwatson	if (pr != NULL) {
23487275Srwatson		mtx_lock(&pr->pr_mtx);
23587072Srwatson		if (!regression_securelevel_nonmonotonic &&
23687275Srwatson		    (level < imax(securelevel, pr->pr_securelevel))) {
23787275Srwatson			mtx_unlock(&pr->pr_mtx);
23886140Srwatson			return (EPERM);
23987275Srwatson		}
24086145Srwatson		pr->pr_securelevel = level;
24187275Srwatson		mtx_unlock(&pr->pr_mtx);
24286140Srwatson	} else {
24387072Srwatson		if (!regression_securelevel_nonmonotonic &&
24487072Srwatson		    (level < securelevel))
24586140Srwatson			return (EPERM);
24686140Srwatson		securelevel = level;
24786140Srwatson	}
24886140Srwatson	return (error);
24915103Sphk}
25015103Sphk
25183990SrwatsonSYSCTL_PROC(_kern, KERN_SECURELVL, securelevel,
25283990Srwatson    CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_PRISON, 0, 0, sysctl_kern_securelvl,
25383990Srwatson    "I", "Current secure level");
25461370Srwatson
25515103Sphkchar domainname[MAXHOSTNAMELEN];
25617281SwollmanSYSCTL_STRING(_kern, KERN_NISDOMAINNAME, domainname, CTLFLAG_RW,
25746381Sbillf    &domainname, sizeof(domainname), "Name of the current YP/NIS domain");
25815103Sphk
25986190Srwatsonu_long hostid;
26078609SpirzykSYSCTL_ULONG(_kern, KERN_HOSTID, hostid, CTLFLAG_RW, &hostid, 0, "Host ID");
26115103Sphk
26215103Sphk/*
26315103Sphk * This is really cheating.  These actually live in the libc, something
26486189Srwatson * which I'm not quite sure is a good idea anyway, but in order for
26515103Sphk * getnext and friends to actually work, we define dummies here.
26615103Sphk */
26786189SrwatsonSYSCTL_STRING(_user, USER_CS_PATH, cs_path, CTLFLAG_RD,
26846381Sbillf    "", 0, "PATH that finds all the standard utilities");
26986189SrwatsonSYSCTL_INT(_user, USER_BC_BASE_MAX, bc_base_max, CTLFLAG_RD,
27046381Sbillf    0, 0, "Max ibase/obase values in bc(1)");
27186189SrwatsonSYSCTL_INT(_user, USER_BC_DIM_MAX, bc_dim_max, CTLFLAG_RD,
27246381Sbillf    0, 0, "Max array size in bc(1)");
27386189SrwatsonSYSCTL_INT(_user, USER_BC_SCALE_MAX, bc_scale_max, CTLFLAG_RD,
27446381Sbillf    0, 0, "Max scale value in bc(1)");
27586189SrwatsonSYSCTL_INT(_user, USER_BC_STRING_MAX, bc_string_max, CTLFLAG_RD,
27646381Sbillf    0, 0, "Max string length in bc(1)");
27786189SrwatsonSYSCTL_INT(_user, USER_COLL_WEIGHTS_MAX, coll_weights_max, CTLFLAG_RD,
27846381Sbillf    0, 0, "Maximum number of weights assigned to an LC_COLLATE locale entry");
27918540SbdeSYSCTL_INT(_user, USER_EXPR_NEST_MAX, expr_nest_max, CTLFLAG_RD, 0, 0, "");
28086189SrwatsonSYSCTL_INT(_user, USER_LINE_MAX, line_max, CTLFLAG_RD,
28146381Sbillf    0, 0, "Max length (bytes) of a text-processing utility's input line");
28286189SrwatsonSYSCTL_INT(_user, USER_RE_DUP_MAX, re_dup_max, CTLFLAG_RD,
28346381Sbillf    0, 0, "Maximum number of repeats of a regexp permitted");
28486189SrwatsonSYSCTL_INT(_user, USER_POSIX2_VERSION, posix2_version, CTLFLAG_RD,
28586189Srwatson    0, 0,
28646381Sbillf    "The version of POSIX 1003.2 with which the system attempts to comply");
28786189SrwatsonSYSCTL_INT(_user, USER_POSIX2_C_BIND, posix2_c_bind, CTLFLAG_RD,
28846381Sbillf    0, 0, "Whether C development supports the C bindings option");
28986189SrwatsonSYSCTL_INT(_user, USER_POSIX2_C_DEV, posix2_c_dev, CTLFLAG_RD,
29046381Sbillf    0, 0, "Whether system supports the C development utilities option");
29186189SrwatsonSYSCTL_INT(_user, USER_POSIX2_CHAR_TERM, posix2_char_term, CTLFLAG_RD,
29246381Sbillf    0, 0, "");
29386189SrwatsonSYSCTL_INT(_user, USER_POSIX2_FORT_DEV, posix2_fort_dev, CTLFLAG_RD,
29446381Sbillf    0, 0, "Whether system supports FORTRAN development utilities");
29586189SrwatsonSYSCTL_INT(_user, USER_POSIX2_FORT_RUN, posix2_fort_run, CTLFLAG_RD,
29646381Sbillf    0, 0, "Whether system supports FORTRAN runtime utilities");
29786189SrwatsonSYSCTL_INT(_user, USER_POSIX2_LOCALEDEF, posix2_localedef, CTLFLAG_RD,
29846381Sbillf    0, 0, "Whether system supports creation of locales");
29986189SrwatsonSYSCTL_INT(_user, USER_POSIX2_SW_DEV, posix2_sw_dev, CTLFLAG_RD,
30046381Sbillf    0, 0, "Whether system supports software development utilities");
30186189SrwatsonSYSCTL_INT(_user, USER_POSIX2_UPE, posix2_upe, CTLFLAG_RD,
30246381Sbillf    0, 0, "Whether system supports the user portability utilities");
30386189SrwatsonSYSCTL_INT(_user, USER_STREAM_MAX, stream_max, CTLFLAG_RD,
30446381Sbillf    0, 0, "Min Maximum number of streams a process may have open at one time");
30586189SrwatsonSYSCTL_INT(_user, USER_TZNAME_MAX, tzname_max, CTLFLAG_RD,
30646381Sbillf    0, 0, "Min Maximum number of types supported for timezone names");
30748891Sphk
30848891Sphk#include <sys/vnode.h>
30986189SrwatsonSYSCTL_INT(_debug_sizeof, OID_AUTO, vnode, CTLFLAG_RD,
31048891Sphk    0, sizeof(struct vnode), "sizeof(struct vnode)");
31148891Sphk
31286189SrwatsonSYSCTL_INT(_debug_sizeof, OID_AUTO, proc, CTLFLAG_RD,
31348891Sphk    0, sizeof(struct proc), "sizeof(struct proc)");
31448927Sphk
31549535Sphk#include <sys/conf.h>
31648927SphkSYSCTL_INT(_debug_sizeof, OID_AUTO, specinfo, CTLFLAG_RD,
31748927Sphk    0, sizeof(struct specinfo), "sizeof(struct specinfo)");
31858926Sphk
31960041Sphk#include <sys/bio.h>
32058926Sphk#include <sys/buf.h>
32158926SphkSYSCTL_INT(_debug_sizeof, OID_AUTO, bio, CTLFLAG_RD,
32258926Sphk    0, sizeof(struct bio), "sizeof(struct bio)");
32358926SphkSYSCTL_INT(_debug_sizeof, OID_AUTO, buf, CTLFLAG_RD,
32458926Sphk    0, sizeof(struct buf), "sizeof(struct buf)");
32572376Sjake
32672376Sjake#include <sys/user.h>
32772376SjakeSYSCTL_INT(_debug_sizeof, OID_AUTO, kinfo_proc, CTLFLAG_RD,
32872376Sjake    0, sizeof(struct kinfo_proc), "sizeof(struct kinfo_proc)");
329