kern_mib.c revision 80418
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 80418 2001-07-26 23:04:03Z peter $
4115103Sphk */
4215103Sphk
4315103Sphk#include <sys/param.h>
4415103Sphk#include <sys/kernel.h>
4515103Sphk#include <sys/systm.h>
4615103Sphk#include <sys/sysctl.h>
4715103Sphk#include <sys/proc.h>
4846155Sphk#include <sys/jail.h>
4976078Sjhb#include <sys/smp.h>
5028918Skato
5115103SphkSYSCTL_NODE(, 0,	  sysctl, CTLFLAG_RW, 0,
5215103Sphk	"Sysctl internal magic");
5315103SphkSYSCTL_NODE(, CTL_KERN,	  kern,   CTLFLAG_RW, 0,
5415103Sphk	"High kernel, proc, limits &c");
5515103SphkSYSCTL_NODE(, CTL_VM,	  vm,     CTLFLAG_RW, 0,
5615103Sphk	"Virtual memory");
5723382SbdeSYSCTL_NODE(, CTL_VFS,	  vfs,     CTLFLAG_RW, 0,
5815103Sphk	"File system");
5915103SphkSYSCTL_NODE(, CTL_NET,	  net,    CTLFLAG_RW, 0,
6015103Sphk	"Network, (see socket.h)");
6115103SphkSYSCTL_NODE(, CTL_DEBUG,  debug,  CTLFLAG_RW, 0,
6215103Sphk	"Debugging");
6348891SphkSYSCTL_NODE(_debug, OID_AUTO,  sizeof,  CTLFLAG_RW, 0,
6448891Sphk	"Sizeof various things");
6515103SphkSYSCTL_NODE(, CTL_HW,	  hw,     CTLFLAG_RW, 0,
6615103Sphk	"hardware");
6715103SphkSYSCTL_NODE(, CTL_MACHDEP, machdep, CTLFLAG_RW, 0,
6815103Sphk	"machine dependent");
6915103SphkSYSCTL_NODE(, CTL_USER,	  user,   CTLFLAG_RW, 0,
7015103Sphk	"user-level");
7134925SdufaultSYSCTL_NODE(, CTL_P1003_1B,  p1003_1b,   CTLFLAG_RW, 0,
7234925Sdufault	"p1003_1b, (see p1003_1b.h)");
7334029Sdufault
7450465SmarcelSYSCTL_NODE(, OID_AUTO,  compat, CTLFLAG_RW, 0,
7550465Smarcel	"Compatibility code");
7650465Smarcel
7746381SbillfSYSCTL_STRING(_kern, KERN_OSRELEASE, osrelease, CTLFLAG_RD,
7846381Sbillf    osrelease, 0, "Operating system type");
7915103Sphk
8046381SbillfSYSCTL_INT(_kern, KERN_OSREV, osrevision, CTLFLAG_RD,
8146381Sbillf    0, BSD, "Operating system revision");
8215103Sphk
8346381SbillfSYSCTL_STRING(_kern, KERN_VERSION, version, CTLFLAG_RD,
8446381Sbillf    version, 0, "Kernel version");
8515103Sphk
8646381SbillfSYSCTL_STRING(_kern, KERN_OSTYPE, ostype, CTLFLAG_RD,
8746381Sbillf    ostype, 0, "Operating system type");
8815103Sphk
8915103Sphkextern int osreldate;
9046381SbillfSYSCTL_INT(_kern, KERN_OSRELDATE, osreldate, CTLFLAG_RD,
9146381Sbillf    &osreldate, 0, "Operating system release date");
9215103Sphk
9346381SbillfSYSCTL_INT(_kern, KERN_MAXPROC, maxproc, CTLFLAG_RD,
9446381Sbillf    &maxproc, 0, "Maximum number of processes");
9515103Sphk
9646381SbillfSYSCTL_INT(_kern, KERN_MAXPROCPERUID, maxprocperuid, CTLFLAG_RW,
9746381Sbillf    &maxprocperuid, 0, "Maximum processes allowed per userid");
9815103Sphk
9980418SpeterSYSCTL_INT(_kern, KERN_MAXPROCPERUID, maxusers, CTLFLAG_RD,
10080418Speter    &maxusers, 0, "Hint for kernel tuning");
10180418Speter
10246381SbillfSYSCTL_INT(_kern, KERN_ARGMAX, argmax, CTLFLAG_RD,
10346381Sbillf    0, ARG_MAX, "Maximum bytes of argument to execve(2)");
10415103Sphk
10546381SbillfSYSCTL_INT(_kern, KERN_POSIX1, posix1version, CTLFLAG_RD,
10646381Sbillf    0, _KPOSIX_VERSION, "Version of POSIX attempting to comply to");
10715103Sphk
10846381SbillfSYSCTL_INT(_kern, KERN_NGROUPS, ngroups, CTLFLAG_RD,
10946381Sbillf    0, NGROUPS_MAX, "Maximum number of groups a user can belong to");
11015103Sphk
11146381SbillfSYSCTL_INT(_kern, KERN_JOB_CONTROL, job_control, CTLFLAG_RD,
11246381Sbillf    0, 1, "Whether job control is available");
11315103Sphk
11415103Sphk#ifdef _POSIX_SAVED_IDS
11546381SbillfSYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD,
11646381Sbillf    0, 1, "Whether saved set-group/user ID is available");
11715103Sphk#else
11846381SbillfSYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD,
11946381Sbillf    0, 0, "Whether saved set-group/user ID is available");
12015103Sphk#endif
12115103Sphk
12215103Sphkchar kernelname[MAXPATHLEN] = "/kernel";	/* XXX bloat */
12315103Sphk
12446381SbillfSYSCTL_STRING(_kern, KERN_BOOTFILE, bootfile, CTLFLAG_RW,
12546381Sbillf    kernelname, sizeof kernelname, "Name of kernel file booted");
12615103Sphk
12731990Sgpalmer#ifdef SMP
12846381SbillfSYSCTL_INT(_hw, HW_NCPU, ncpu, CTLFLAG_RD,
12946381Sbillf    &mp_ncpus, 0, "Number of active CPUs");
13031990Sgpalmer#else
13146381SbillfSYSCTL_INT(_hw, HW_NCPU, ncpu, CTLFLAG_RD,
13246381Sbillf    0, 1, "Number of active CPUs");
13331990Sgpalmer#endif
13415103Sphk
13546381SbillfSYSCTL_INT(_hw, HW_BYTEORDER, byteorder, CTLFLAG_RD,
13646381Sbillf    0, BYTE_ORDER, "System byte order");
13715103Sphk
13846381SbillfSYSCTL_INT(_hw, HW_PAGESIZE, pagesize, CTLFLAG_RD,
13946381Sbillf    0, PAGE_SIZE, "System memory page size");
14015103Sphk
14128885Skatostatic char	machine_arch[] = MACHINE_ARCH;
14228885SkatoSYSCTL_STRING(_hw, HW_MACHINE_ARCH, machine_arch, CTLFLAG_RD,
14346381Sbillf    machine_arch, 0, "System architecture");
14428885Skato
14515103Sphkchar hostname[MAXHOSTNAMELEN];
14615103Sphk
14746155Sphkstatic int
14862573Sphksysctl_hostname(SYSCTL_HANDLER_ARGS)
14946155Sphk{
15046155Sphk	int error;
15115103Sphk
15272786Srwatson	if (jailed(req->p->p_ucred)) {
15357163Srwatson		if (!jail_set_hostname_allowed && req->newptr)
15457111Srwatson			return(EPERM);
15546155Sphk		error = sysctl_handle_string(oidp,
15672786Srwatson		    req->p->p_ucred->cr_prison->pr_host,
15772786Srwatson		    sizeof req->p->p_ucred->cr_prison->pr_host, req);
15857111Srwatson	} else
15946155Sphk		error = sysctl_handle_string(oidp,
16046155Sphk		    hostname, sizeof hostname, req);
16146155Sphk	return (error);
16246155Sphk}
16346155Sphk
16446155SphkSYSCTL_PROC(_kern, KERN_HOSTNAME, hostname,
16546155Sphk       CTLTYPE_STRING|CTLFLAG_RW|CTLFLAG_PRISON,
16646381Sbillf       0, 0, sysctl_hostname, "A", "Hostname");
16746155Sphk
16815103Sphkint securelevel = -1;
16915103Sphk
17015103Sphkstatic int
17162573Sphksysctl_kern_securelvl(SYSCTL_HANDLER_ARGS)
17215103Sphk{
17315103Sphk		int error, level;
17415103Sphk
17515103Sphk		level = securelevel;
17615103Sphk		error = sysctl_handle_int(oidp, &level, 0, req);
17715103Sphk		if (error || !req->newptr)
17815103Sphk			return (error);
17926923Sjoerg		if (level < securelevel)
18015103Sphk			return (EPERM);
18115103Sphk		securelevel = level;
18215103Sphk		return (error);
18315103Sphk}
18415103Sphk
18561370SrwatsonSYSCTL_PROC(_kern, KERN_SECURELVL, securelevel, CTLTYPE_INT|CTLFLAG_RW,
18661370Srwatson    0, 0, sysctl_kern_securelvl, "I", "Current secure level");
18761370Srwatson
18815103Sphkchar domainname[MAXHOSTNAMELEN];
18917281SwollmanSYSCTL_STRING(_kern, KERN_NISDOMAINNAME, domainname, CTLFLAG_RW,
19046381Sbillf    &domainname, sizeof(domainname), "Name of the current YP/NIS domain");
19115103Sphk
19278609Spirzykunsigned long hostid;
19378609SpirzykSYSCTL_ULONG(_kern, KERN_HOSTID, hostid, CTLFLAG_RW, &hostid, 0, "Host ID");
19415103Sphk
19515103Sphk/*
19615103Sphk * This is really cheating.  These actually live in the libc, something
19715103Sphk * which I'm not quite sure is a good idea anyway, but in order for
19815103Sphk * getnext and friends to actually work, we define dummies here.
19915103Sphk */
20046381SbillfSYSCTL_STRING(_user, USER_CS_PATH, cs_path, CTLFLAG_RD,
20146381Sbillf    "", 0, "PATH that finds all the standard utilities");
20246381SbillfSYSCTL_INT(_user, USER_BC_BASE_MAX, bc_base_max, CTLFLAG_RD,
20346381Sbillf    0, 0, "Max ibase/obase values in bc(1)");
20446381SbillfSYSCTL_INT(_user, USER_BC_DIM_MAX, bc_dim_max, CTLFLAG_RD,
20546381Sbillf    0, 0, "Max array size in bc(1)");
20646381SbillfSYSCTL_INT(_user, USER_BC_SCALE_MAX, bc_scale_max, CTLFLAG_RD,
20746381Sbillf    0, 0, "Max scale value in bc(1)");
20846381SbillfSYSCTL_INT(_user, USER_BC_STRING_MAX, bc_string_max, CTLFLAG_RD,
20946381Sbillf    0, 0, "Max string length in bc(1)");
21046381SbillfSYSCTL_INT(_user, USER_COLL_WEIGHTS_MAX, coll_weights_max, CTLFLAG_RD,
21146381Sbillf    0, 0, "Maximum number of weights assigned to an LC_COLLATE locale entry");
21218540SbdeSYSCTL_INT(_user, USER_EXPR_NEST_MAX, expr_nest_max, CTLFLAG_RD, 0, 0, "");
21346381SbillfSYSCTL_INT(_user, USER_LINE_MAX, line_max, CTLFLAG_RD,
21446381Sbillf    0, 0, "Max length (bytes) of a text-processing utility's input line");
21546381SbillfSYSCTL_INT(_user, USER_RE_DUP_MAX, re_dup_max, CTLFLAG_RD,
21646381Sbillf    0, 0, "Maximum number of repeats of a regexp permitted");
21746381SbillfSYSCTL_INT(_user, USER_POSIX2_VERSION, posix2_version, CTLFLAG_RD,
21846381Sbillf    0, 0,
21946381Sbillf    "The version of POSIX 1003.2 with which the system attempts to comply");
22046381SbillfSYSCTL_INT(_user, USER_POSIX2_C_BIND, posix2_c_bind, CTLFLAG_RD,
22146381Sbillf    0, 0, "Whether C development supports the C bindings option");
22246381SbillfSYSCTL_INT(_user, USER_POSIX2_C_DEV, posix2_c_dev, CTLFLAG_RD,
22346381Sbillf    0, 0, "Whether system supports the C development utilities option");
22446381SbillfSYSCTL_INT(_user, USER_POSIX2_CHAR_TERM, posix2_char_term, CTLFLAG_RD,
22546381Sbillf    0, 0, "");
22646381SbillfSYSCTL_INT(_user, USER_POSIX2_FORT_DEV, posix2_fort_dev, CTLFLAG_RD,
22746381Sbillf    0, 0, "Whether system supports FORTRAN development utilities");
22846381SbillfSYSCTL_INT(_user, USER_POSIX2_FORT_RUN, posix2_fort_run, CTLFLAG_RD,
22946381Sbillf    0, 0, "Whether system supports FORTRAN runtime utilities");
23046381SbillfSYSCTL_INT(_user, USER_POSIX2_LOCALEDEF, posix2_localedef, CTLFLAG_RD,
23146381Sbillf    0, 0, "Whether system supports creation of locales");
23246381SbillfSYSCTL_INT(_user, USER_POSIX2_SW_DEV, posix2_sw_dev, CTLFLAG_RD,
23346381Sbillf    0, 0, "Whether system supports software development utilities");
23446381SbillfSYSCTL_INT(_user, USER_POSIX2_UPE, posix2_upe, CTLFLAG_RD,
23546381Sbillf    0, 0, "Whether system supports the user portability utilities");
23646381SbillfSYSCTL_INT(_user, USER_STREAM_MAX, stream_max, CTLFLAG_RD,
23746381Sbillf    0, 0, "Min Maximum number of streams a process may have open at one time");
23846381SbillfSYSCTL_INT(_user, USER_TZNAME_MAX, tzname_max, CTLFLAG_RD,
23946381Sbillf    0, 0, "Min Maximum number of types supported for timezone names");
24048891Sphk
24148891Sphk#include <sys/vnode.h>
24248891SphkSYSCTL_INT(_debug_sizeof, OID_AUTO, vnode, CTLFLAG_RD,
24348891Sphk    0, sizeof(struct vnode), "sizeof(struct vnode)");
24448891Sphk
24548891SphkSYSCTL_INT(_debug_sizeof, OID_AUTO, proc, CTLFLAG_RD,
24648891Sphk    0, sizeof(struct proc), "sizeof(struct proc)");
24748927Sphk
24849535Sphk#include <sys/conf.h>
24948927SphkSYSCTL_INT(_debug_sizeof, OID_AUTO, specinfo, CTLFLAG_RD,
25048927Sphk    0, sizeof(struct specinfo), "sizeof(struct specinfo)");
25158926Sphk
25260041Sphk#include <sys/bio.h>
25358926Sphk#include <sys/buf.h>
25458926SphkSYSCTL_INT(_debug_sizeof, OID_AUTO, bio, CTLFLAG_RD,
25558926Sphk    0, sizeof(struct bio), "sizeof(struct bio)");
25658926SphkSYSCTL_INT(_debug_sizeof, OID_AUTO, buf, CTLFLAG_RD,
25758926Sphk    0, sizeof(struct buf), "sizeof(struct buf)");
25872376Sjake
25972376Sjake#include <sys/user.h>
26072376SjakeSYSCTL_INT(_debug_sizeof, OID_AUTO, kinfo_proc, CTLFLAG_RD,
26172376Sjake    0, sizeof(struct kinfo_proc), "sizeof(struct kinfo_proc)");
262