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 * 4. Neither the name of the University nor the names of its contributors
2015103Sphk *    may be used to endorse or promote products derived from this software
2115103Sphk *    without specific prior written permission.
2215103Sphk *
2315103Sphk * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2415103Sphk * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2515103Sphk * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2615103Sphk * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2715103Sphk * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2815103Sphk * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2915103Sphk * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3015103Sphk * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3115103Sphk * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3215103Sphk * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3315103Sphk * SUCH DAMAGE.
3415103Sphk *
3515103Sphk *	@(#)kern_sysctl.c	8.4 (Berkeley) 4/14/94
3615103Sphk */
3715103Sphk
38116182Sobrien#include <sys/cdefs.h>
39116182Sobrien__FBSDID("$FreeBSD$");
40116182Sobrien
41175417Sjhb#include "opt_compat.h"
4286190Srwatson#include "opt_posix.h"
43169604Swkoszek#include "opt_config.h"
4484611Srwatson
4515103Sphk#include <sys/param.h>
4615103Sphk#include <sys/kernel.h>
47169507Swkoszek#include <sys/sbuf.h>
4815103Sphk#include <sys/systm.h>
4915103Sphk#include <sys/sysctl.h>
5015103Sphk#include <sys/proc.h>
5187275Srwatson#include <sys/lock.h>
5287275Srwatson#include <sys/mutex.h>
5346155Sphk#include <sys/jail.h>
5476078Sjhb#include <sys/smp.h>
55192895Sjamie#include <sys/sx.h>
56105046Smike#include <sys/unistd.h>
5728918Skato
58269446ShselaskySYSCTL_ROOT_NODE(0,	  sysctl, CTLFLAG_RW, 0,
5915103Sphk	"Sysctl internal magic");
60269446ShselaskySYSCTL_ROOT_NODE(CTL_KERN,	  kern,   CTLFLAG_RW|CTLFLAG_CAPRD, 0,
6115103Sphk	"High kernel, proc, limits &c");
62269446ShselaskySYSCTL_ROOT_NODE(CTL_VM,	  vm,     CTLFLAG_RW, 0,
6315103Sphk	"Virtual memory");
64269446ShselaskySYSCTL_ROOT_NODE(CTL_VFS,	  vfs,     CTLFLAG_RW, 0,
6515103Sphk	"File system");
66269446ShselaskySYSCTL_ROOT_NODE(CTL_NET,	  net,    CTLFLAG_RW, 0,
6715103Sphk	"Network, (see socket.h)");
68269446ShselaskySYSCTL_ROOT_NODE(CTL_DEBUG,  debug,  CTLFLAG_RW, 0,
6915103Sphk	"Debugging");
7048891SphkSYSCTL_NODE(_debug, OID_AUTO,  sizeof,  CTLFLAG_RW, 0,
7148891Sphk	"Sizeof various things");
72269446ShselaskySYSCTL_ROOT_NODE(CTL_HW,	  hw,     CTLFLAG_RW, 0,
7315103Sphk	"hardware");
74269446ShselaskySYSCTL_ROOT_NODE(CTL_MACHDEP, machdep, CTLFLAG_RW, 0,
7515103Sphk	"machine dependent");
76269446ShselaskySYSCTL_ROOT_NODE(CTL_USER,	  user,   CTLFLAG_RW, 0,
7715103Sphk	"user-level");
78269446ShselaskySYSCTL_ROOT_NODE(CTL_P1003_1B,  p1003_1b,   CTLFLAG_RW, 0,
7934925Sdufault	"p1003_1b, (see p1003_1b.h)");
8034029Sdufault
81269446ShselaskySYSCTL_ROOT_NODE(OID_AUTO,  compat, CTLFLAG_RW, 0,
8250465Smarcel	"Compatibility code");
83269446ShselaskySYSCTL_ROOT_NODE(OID_AUTO, security, CTLFLAG_RW, 0,
8489414Sarr     	"Security");
8586190Srwatson#ifdef REGRESSION
86269446ShselaskySYSCTL_ROOT_NODE(OID_AUTO, regression, CTLFLAG_RW, 0,
8786190Srwatson     "Regression test MIB");
8886190Srwatson#endif
8950465Smarcel
90187864SedSYSCTL_STRING(_kern, OID_AUTO, ident, CTLFLAG_RD|CTLFLAG_MPSAFE,
91116105Sjmallett    kern_ident, 0, "Kernel identifier");
92116090Sjmallett
93224159SrwatsonSYSCTL_STRING(_kern, KERN_OSRELEASE, osrelease, CTLFLAG_RD|CTLFLAG_MPSAFE|
94224159Srwatson    CTLFLAG_CAPRD, osrelease, 0, "Operating system release");
9515103Sphk
96224159SrwatsonSYSCTL_INT(_kern, KERN_OSREV, osrevision, CTLFLAG_RD|CTLFLAG_CAPRD,
9746381Sbillf    0, BSD, "Operating system revision");
9815103Sphk
99187864SedSYSCTL_STRING(_kern, KERN_VERSION, version, CTLFLAG_RD|CTLFLAG_MPSAFE,
10046381Sbillf    version, 0, "Kernel version");
10115103Sphk
102246254SavgSYSCTL_STRING(_kern, OID_AUTO, compiler_version, CTLFLAG_RD|CTLFLAG_MPSAFE,
103246246Savg    compiler_version, 0, "Version of compiler used to compile kernel");
104246246Savg
105224159SrwatsonSYSCTL_STRING(_kern, KERN_OSTYPE, ostype, CTLFLAG_RD|CTLFLAG_MPSAFE|
106224159Srwatson    CTLFLAG_CAPRD, ostype, 0, "Operating system type");
10715103Sphk
108119203Seivind/*
109119203Seivind * NOTICE: The *userland* release date is available in
110119203Seivind * /usr/include/osreldate.h
111119203Seivind */
112224159SrwatsonSYSCTL_INT(_kern, KERN_OSRELDATE, osreldate, CTLFLAG_RD|CTLFLAG_CAPRD,
113119203Seivind    &osreldate, 0, "Kernel release date");
11415103Sphk
115121307SsilbySYSCTL_INT(_kern, KERN_MAXPROC, maxproc, CTLFLAG_RDTUN,
11646381Sbillf    &maxproc, 0, "Maximum number of processes");
11715103Sphk
11886189SrwatsonSYSCTL_INT(_kern, KERN_MAXPROCPERUID, maxprocperuid, CTLFLAG_RW,
11946381Sbillf    &maxprocperuid, 0, "Maximum processes allowed per userid");
12015103Sphk
121121307SsilbySYSCTL_INT(_kern, OID_AUTO, maxusers, CTLFLAG_RDTUN,
12280418Speter    &maxusers, 0, "Hint for kernel tuning");
12380418Speter
124224159SrwatsonSYSCTL_INT(_kern, KERN_ARGMAX, argmax, CTLFLAG_RD|CTLFLAG_CAPRD,
12546381Sbillf    0, ARG_MAX, "Maximum bytes of argument to execve(2)");
12615103Sphk
127224159SrwatsonSYSCTL_INT(_kern, KERN_POSIX1, posix1version, CTLFLAG_RD|CTLFLAG_CAPRD,
128105046Smike    0, _POSIX_VERSION, "Version of POSIX attempting to comply to");
12915103Sphk
130224159SrwatsonSYSCTL_INT(_kern, KERN_NGROUPS, ngroups, CTLFLAG_RDTUN|CTLFLAG_CAPRD,
131202143Sbrooks    &ngroups_max, 0,
132201953Sbrooks    "Maximum number of supplemental groups a user can belong to");
13315103Sphk
134224159SrwatsonSYSCTL_INT(_kern, KERN_JOB_CONTROL, job_control, CTLFLAG_RD|CTLFLAG_CAPRD,
13546381Sbillf    0, 1, "Whether job control is available");
13615103Sphk
13715103Sphk#ifdef _POSIX_SAVED_IDS
138224159SrwatsonSYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD|CTLFLAG_CAPRD,
13946381Sbillf    0, 1, "Whether saved set-group/user ID is available");
14015103Sphk#else
141224159SrwatsonSYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD|CTLFLAG_CAPRD,
14246381Sbillf    0, 0, "Whether saved set-group/user ID is available");
14315103Sphk#endif
14415103Sphk
14515103Sphkchar kernelname[MAXPATHLEN] = "/kernel";	/* XXX bloat */
14615103Sphk
147244103SalfredSYSCTL_STRING(_kern, KERN_BOOTFILE, bootfile, CTLFLAG_RW,
14846381Sbillf    kernelname, sizeof kernelname, "Name of kernel file booted");
14915103Sphk
150224159SrwatsonSYSCTL_INT(_hw, HW_NCPU, ncpu, CTLFLAG_RD|CTLFLAG_CAPRD,
15146381Sbillf    &mp_ncpus, 0, "Number of active CPUs");
15215103Sphk
153224159SrwatsonSYSCTL_INT(_hw, HW_BYTEORDER, byteorder, CTLFLAG_RD|CTLFLAG_CAPRD,
15446381Sbillf    0, BYTE_ORDER, "System byte order");
15515103Sphk
156224159SrwatsonSYSCTL_INT(_hw, HW_PAGESIZE, pagesize, CTLFLAG_RD|CTLFLAG_CAPRD,
15746381Sbillf    0, PAGE_SIZE, "System memory page size");
15815103Sphk
159106605Stmmstatic int
160169727Skansysctl_kern_arnd(SYSCTL_HANDLER_ARGS)
161169727Skan{
162176367Santoine	char buf[256];
163176367Santoine	size_t len;
164169727Skan
165176367Santoine	len = req->oldlen;
166176367Santoine	if (len > sizeof(buf))
167176367Santoine		len = sizeof(buf);
168176367Santoine	arc4rand(buf, len, 0);
169176367Santoine	return (SYSCTL_OUT(req, buf, len));
170169727Skan}
171169727Skan
172187864SedSYSCTL_PROC(_kern, KERN_ARND, arandom,
173224159Srwatson    CTLTYPE_OPAQUE | CTLFLAG_RD | CTLFLAG_MPSAFE | CTLFLAG_CAPRD, NULL, 0,
174187864Sed    sysctl_kern_arnd, "", "arc4rand");
175169727Skan
176169727Skanstatic int
177106605Stmmsysctl_hw_physmem(SYSCTL_HANDLER_ARGS)
178106605Stmm{
179106605Stmm	u_long val;
180106605Stmm
181106605Stmm	val = ctob(physmem);
182106605Stmm	return (sysctl_handle_long(oidp, &val, 0, req));
183106605Stmm}
184106605Stmm
185106605StmmSYSCTL_PROC(_hw, HW_PHYSMEM, physmem, CTLTYPE_ULONG | CTLFLAG_RD,
186106605Stmm	0, 0, sysctl_hw_physmem, "LU", "");
187106605Stmm
188106605Stmmstatic int
189142834Swessysctl_hw_realmem(SYSCTL_HANDLER_ARGS)
190142834Swes{
191142834Swes	u_long val;
192142834Swes	val = ctob(realmem);
193142834Swes	return (sysctl_handle_long(oidp, &val, 0, req));
194142834Swes}
195142834SwesSYSCTL_PROC(_hw, HW_REALMEM, realmem, CTLTYPE_ULONG | CTLFLAG_RD,
196142834Swes	0, 0, sysctl_hw_realmem, "LU", "");
197142834Swesstatic int
198106605Stmmsysctl_hw_usermem(SYSCTL_HANDLER_ARGS)
199106605Stmm{
200106605Stmm	u_long val;
201106605Stmm
202170170Sattilio	val = ctob(physmem - cnt.v_wire_count);
203106605Stmm	return (sysctl_handle_long(oidp, &val, 0, req));
204106605Stmm}
205106605Stmm
206106605StmmSYSCTL_PROC(_hw, HW_USERMEM, usermem, CTLTYPE_ULONG | CTLFLAG_RD,
207106605Stmm	0, 0, sysctl_hw_usermem, "LU", "");
208106605Stmm
209217326SmdfSYSCTL_LONG(_hw, OID_AUTO, availpages, CTLFLAG_RD, &physmem, 0, "");
210106605Stmm
211197316Salcu_long pagesizes[MAXPAGESIZES] = { PAGE_SIZE };
212197316Salc
213197316Salcstatic int
214197316Salcsysctl_hw_pagesizes(SYSCTL_HANDLER_ARGS)
215197316Salc{
216197316Salc	int error;
217197316Salc#ifdef SCTL_MASK32
218197316Salc	int i;
219197316Salc	uint32_t pagesizes32[MAXPAGESIZES];
220197316Salc
221197316Salc	if (req->flags & SCTL_MASK32) {
222197316Salc		/*
223197316Salc		 * Recreate the "pagesizes" array with 32-bit elements.  Truncate
224197316Salc		 * any page size greater than UINT32_MAX to zero.
225197316Salc		 */
226197316Salc		for (i = 0; i < MAXPAGESIZES; i++)
227197316Salc			pagesizes32[i] = (uint32_t)pagesizes[i];
228197316Salc
229197316Salc		error = SYSCTL_OUT(req, pagesizes32, sizeof(pagesizes32));
230197316Salc	} else
231197316Salc#endif
232197316Salc		error = SYSCTL_OUT(req, pagesizes, sizeof(pagesizes));
233197316Salc	return (error);
234197316Salc}
235197316SalcSYSCTL_PROC(_hw, OID_AUTO, pagesizes, CTLTYPE_ULONG | CTLFLAG_RD,
236197316Salc    NULL, 0, sysctl_hw_pagesizes, "LU", "Supported page sizes");
237197316Salc
238210369Skib#ifdef SCTL_MASK32
239210369Skibint adaptive_machine_arch = 1;
240210369SkibSYSCTL_INT(_debug, OID_AUTO, adaptive_machine_arch, CTLFLAG_RW,
241210369Skib    &adaptive_machine_arch, 1,
242210369Skib    "Adapt reported machine architecture to the ABI of the binary");
243210369Skib#endif
24428885Skato
24546155Sphkstatic int
246210369Skibsysctl_hw_machine_arch(SYSCTL_HANDLER_ARGS)
247210369Skib{
248210369Skib	int error;
249210369Skib	static const char machine_arch[] = MACHINE_ARCH;
250210369Skib#ifdef SCTL_MASK32
251210369Skib	static const char machine_arch32[] = MACHINE_ARCH32;
252210369Skib
253210369Skib	if ((req->flags & SCTL_MASK32) != 0 && adaptive_machine_arch)
254210369Skib		error = SYSCTL_OUT(req, machine_arch32, sizeof(machine_arch32));
255210369Skib	else
256210369Skib#endif
257210369Skib		error = SYSCTL_OUT(req, machine_arch, sizeof(machine_arch));
258210369Skib	return (error);
259210369Skib
260210369Skib}
261210369SkibSYSCTL_PROC(_hw, HW_MACHINE_ARCH, machine_arch, CTLTYPE_STRING | CTLFLAG_RD,
262210369Skib    NULL, 0, sysctl_hw_machine_arch, "A", "System architecture");
263210369Skib
264259465SnwhitehornSYSCTL_STRING(_kern, OID_AUTO, supported_archs, CTLFLAG_RD | CTLFLAG_MPSAFE,
265259465Snwhitehorn#ifdef COMPAT_FREEBSD32
266259465Snwhitehorn    MACHINE_ARCH " " MACHINE_ARCH32, 0, "Supported architectures for binaries");
267259465Snwhitehorn#else
268259465Snwhitehorn    MACHINE_ARCH, 0, "Supported architectures for binaries");
269259465Snwhitehorn#endif
270259465Snwhitehorn
271210369Skibstatic int
27262573Sphksysctl_hostname(SYSCTL_HANDLER_ARGS)
27346155Sphk{
274193066Sjamie	struct prison *pr, *cpr;
275193066Sjamie	size_t pr_offset;
276193066Sjamie	char tmpname[MAXHOSTNAMELEN];
277193066Sjamie	int descend, error, len;
27815103Sphk
279193066Sjamie	/*
280193066Sjamie	 * This function can set: hostname domainname hostuuid.
281193066Sjamie	 * Keep that in mind when comments say "hostname".
282193066Sjamie	 */
283193066Sjamie	pr_offset = (size_t)arg1;
284193066Sjamie	len = arg2;
285193066Sjamie	KASSERT(len <= sizeof(tmpname),
286193066Sjamie	    ("length %d too long for %s", len, __func__));
287193066Sjamie
28891406Sjhb	pr = req->td->td_ucred->cr_prison;
289193066Sjamie	if (!(pr->pr_allow & PR_ALLOW_SET_HOSTNAME) && req->newptr)
290193066Sjamie		return (EPERM);
291193066Sjamie	/*
292193066Sjamie	 * Make a local copy of hostname to get/set so we don't have to hold
293193066Sjamie	 * the jail mutex during the sysctl copyin/copyout activities.
294193066Sjamie	 */
295193066Sjamie	mtx_lock(&pr->pr_mtx);
296193066Sjamie	bcopy((char *)pr + pr_offset, tmpname, len);
297193066Sjamie	mtx_unlock(&pr->pr_mtx);
298193066Sjamie
299193066Sjamie	error = sysctl_handle_string(oidp, tmpname, len, req);
300193066Sjamie
301193066Sjamie	if (req->newptr != NULL && error == 0) {
30287275Srwatson		/*
303193066Sjamie		 * Copy the locally set hostname to all jails that share
304193066Sjamie		 * this host info.
30587275Srwatson		 */
306193066Sjamie		sx_slock(&allprison_lock);
307193066Sjamie		while (!(pr->pr_flags & PR_HOST))
308193066Sjamie			pr = pr->pr_parent;
30987275Srwatson		mtx_lock(&pr->pr_mtx);
310193066Sjamie		bcopy(tmpname, (char *)pr + pr_offset, len);
311193066Sjamie		FOREACH_PRISON_DESCENDANT_LOCKED(pr, cpr, descend)
312193066Sjamie			if (cpr->pr_flags & PR_HOST)
313193066Sjamie				descend = 0;
314193066Sjamie			else
315193066Sjamie				bcopy(tmpname, (char *)cpr + pr_offset, len);
31687275Srwatson		mtx_unlock(&pr->pr_mtx);
317193066Sjamie		sx_sunlock(&allprison_lock);
318180291Srwatson	}
31946155Sphk	return (error);
32046155Sphk}
32146155Sphk
32286189SrwatsonSYSCTL_PROC(_kern, KERN_HOSTNAME, hostname,
323193066Sjamie    CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE,
324194118Sjamie    (void *)(offsetof(struct prison, pr_hostname)), MAXHOSTNAMELEN,
325193066Sjamie    sysctl_hostname, "A", "Hostname");
326193066SjamieSYSCTL_PROC(_kern, KERN_NISDOMAINNAME, domainname,
327193066Sjamie    CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE,
328194118Sjamie    (void *)(offsetof(struct prison, pr_domainname)), MAXHOSTNAMELEN,
329193066Sjamie    sysctl_hostname, "A", "Name of the current YP/NIS domain");
330193066SjamieSYSCTL_PROC(_kern, KERN_HOSTUUID, hostuuid,
331193066Sjamie    CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE,
332194118Sjamie    (void *)(offsetof(struct prison, pr_hostuuid)), HOSTUUIDLEN,
333193066Sjamie    sysctl_hostname, "A", "Host UUID");
33446155Sphk
33586190Srwatsonstatic int	regression_securelevel_nonmonotonic = 0;
33684611Srwatson
33787072Srwatson#ifdef REGRESSION
33884611SrwatsonSYSCTL_INT(_regression, OID_AUTO, securelevel_nonmonotonic, CTLFLAG_RW,
33984611Srwatson    &regression_securelevel_nonmonotonic, 0, "securelevel may be lowered");
34086190Srwatson#endif
34184611Srwatson
34215103Sphkstatic int
34362573Sphksysctl_kern_securelvl(SYSCTL_HANDLER_ARGS)
34415103Sphk{
345192895Sjamie	struct prison *pr, *cpr;
346192895Sjamie	int descend, error, level;
34715103Sphk
34891406Sjhb	pr = req->td->td_ucred->cr_prison;
34986145Srwatson
35086140Srwatson	/*
351192895Sjamie	 * Reading the securelevel is easy, since the current jail's level
352192895Sjamie	 * is known to be at least as secure as any higher levels.  Perform
353192895Sjamie	 * a lockless read since the securelevel is an integer.
35486140Srwatson	 */
355192895Sjamie	level = pr->pr_securelevel;
35686140Srwatson	error = sysctl_handle_int(oidp, &level, 0, req);
35786140Srwatson	if (error || !req->newptr)
35886140Srwatson		return (error);
359192895Sjamie	/* Permit update only if the new securelevel exceeds the old. */
360192895Sjamie	sx_slock(&allprison_lock);
361192895Sjamie	mtx_lock(&pr->pr_mtx);
362192895Sjamie	if (!regression_securelevel_nonmonotonic &&
363192895Sjamie	    level < pr->pr_securelevel) {
364192895Sjamie		mtx_unlock(&pr->pr_mtx);
365192895Sjamie		sx_sunlock(&allprison_lock);
366192895Sjamie		return (EPERM);
367192895Sjamie	}
368192895Sjamie	pr->pr_securelevel = level;
36986140Srwatson	/*
370192895Sjamie	 * Set all child jails to be at least this level, but do not lower
371192895Sjamie	 * them (even if regression_securelevel_nonmonotonic).
37286140Srwatson	 */
373192895Sjamie	FOREACH_PRISON_DESCENDANT_LOCKED(pr, cpr, descend) {
374192895Sjamie		if (cpr->pr_securelevel < level)
375192895Sjamie			cpr->pr_securelevel = level;
37686140Srwatson	}
377192895Sjamie	mtx_unlock(&pr->pr_mtx);
378192895Sjamie	sx_sunlock(&allprison_lock);
37986140Srwatson	return (error);
38015103Sphk}
38115103Sphk
38283990SrwatsonSYSCTL_PROC(_kern, KERN_SECURELVL, securelevel,
38383990Srwatson    CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_PRISON, 0, 0, sysctl_kern_securelvl,
38483990Srwatson    "I", "Current secure level");
38561370Srwatson
386169604Swkoszek#ifdef INCLUDE_CONFIG_FILE
387169507Swkoszek/* Actual kernel configuration options. */
388169507Swkoszekextern char kernconfstring[];
389169507Swkoszek
390244098SalfredSYSCTL_STRING(_kern, OID_AUTO, conftxt, CTLFLAG_RD, kernconfstring, 0,
391244098Salfred    "Kernel configuration file");
392169650Simp#endif
393169507Swkoszek
394180291Srwatsonstatic int
395193066Sjamiesysctl_hostid(SYSCTL_HANDLER_ARGS)
396180291Srwatson{
397193066Sjamie	struct prison *pr, *cpr;
398193066Sjamie	u_long tmpid;
399193066Sjamie	int descend, error;
400180291Srwatson
401193066Sjamie	/*
402193066Sjamie	 * Like sysctl_hostname, except it operates on a u_long
403193066Sjamie	 * instead of a string, and is used only for hostid.
404193066Sjamie	 */
405193066Sjamie	pr = req->td->td_ucred->cr_prison;
406193066Sjamie	if (!(pr->pr_allow & PR_ALLOW_SET_HOSTNAME) && req->newptr)
407193066Sjamie		return (EPERM);
408193066Sjamie	tmpid = pr->pr_hostid;
409193066Sjamie	error = sysctl_handle_long(oidp, &tmpid, 0, req);
410193066Sjamie
411180291Srwatson	if (req->newptr != NULL && error == 0) {
412193066Sjamie		sx_slock(&allprison_lock);
413193066Sjamie		while (!(pr->pr_flags & PR_HOST))
414193066Sjamie			pr = pr->pr_parent;
415193066Sjamie		mtx_lock(&pr->pr_mtx);
416193066Sjamie		pr->pr_hostid = tmpid;
417193066Sjamie		FOREACH_PRISON_DESCENDANT_LOCKED(pr, cpr, descend)
418193066Sjamie			if (cpr->pr_flags & PR_HOST)
419193066Sjamie				descend = 0;
420193066Sjamie			else
421193066Sjamie				cpr->pr_hostid = tmpid;
422193066Sjamie		mtx_unlock(&pr->pr_mtx);
423193066Sjamie		sx_sunlock(&allprison_lock);
424180291Srwatson	}
425180291Srwatson	return (error);
426180291Srwatson}
427180291Srwatson
428193066SjamieSYSCTL_PROC(_kern, KERN_HOSTID, hostid,
429193066Sjamie    CTLTYPE_ULONG | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE,
430193066Sjamie    NULL, 0, sysctl_hostid, "LU", "Host ID");
431180291Srwatson
432175021SjhbSYSCTL_NODE(_kern, OID_AUTO, features, CTLFLAG_RD, 0, "Kernel Features");
433175021Sjhb
434175417Sjhb#ifdef COMPAT_FREEBSD4
435175417SjhbFEATURE(compat_freebsd4, "Compatible with FreeBSD 4");
436175417Sjhb#endif
437175417Sjhb
438175417Sjhb#ifdef COMPAT_FREEBSD5
439175417SjhbFEATURE(compat_freebsd5, "Compatible with FreeBSD 5");
440175417Sjhb#endif
441175417Sjhb
442175417Sjhb#ifdef COMPAT_FREEBSD6
443175417SjhbFEATURE(compat_freebsd6, "Compatible with FreeBSD 6");
444175417Sjhb#endif
445175417Sjhb
446175417Sjhb#ifdef COMPAT_FREEBSD7
447175417SjhbFEATURE(compat_freebsd7, "Compatible with FreeBSD 7");
448175417Sjhb#endif
449175417Sjhb
45015103Sphk/*
45115103Sphk * This is really cheating.  These actually live in the libc, something
45286189Srwatson * which I'm not quite sure is a good idea anyway, but in order for
45315103Sphk * getnext and friends to actually work, we define dummies here.
454224159Srwatson *
455224159Srwatson * XXXRW: These probably should be CTLFLAG_CAPRD.
45615103Sphk */
45786189SrwatsonSYSCTL_STRING(_user, USER_CS_PATH, cs_path, CTLFLAG_RD,
45846381Sbillf    "", 0, "PATH that finds all the standard utilities");
45986189SrwatsonSYSCTL_INT(_user, USER_BC_BASE_MAX, bc_base_max, CTLFLAG_RD,
46046381Sbillf    0, 0, "Max ibase/obase values in bc(1)");
46186189SrwatsonSYSCTL_INT(_user, USER_BC_DIM_MAX, bc_dim_max, CTLFLAG_RD,
46246381Sbillf    0, 0, "Max array size in bc(1)");
46386189SrwatsonSYSCTL_INT(_user, USER_BC_SCALE_MAX, bc_scale_max, CTLFLAG_RD,
46446381Sbillf    0, 0, "Max scale value in bc(1)");
46586189SrwatsonSYSCTL_INT(_user, USER_BC_STRING_MAX, bc_string_max, CTLFLAG_RD,
46646381Sbillf    0, 0, "Max string length in bc(1)");
46786189SrwatsonSYSCTL_INT(_user, USER_COLL_WEIGHTS_MAX, coll_weights_max, CTLFLAG_RD,
46846381Sbillf    0, 0, "Maximum number of weights assigned to an LC_COLLATE locale entry");
46918540SbdeSYSCTL_INT(_user, USER_EXPR_NEST_MAX, expr_nest_max, CTLFLAG_RD, 0, 0, "");
47086189SrwatsonSYSCTL_INT(_user, USER_LINE_MAX, line_max, CTLFLAG_RD,
47146381Sbillf    0, 0, "Max length (bytes) of a text-processing utility's input line");
47286189SrwatsonSYSCTL_INT(_user, USER_RE_DUP_MAX, re_dup_max, CTLFLAG_RD,
47346381Sbillf    0, 0, "Maximum number of repeats of a regexp permitted");
47486189SrwatsonSYSCTL_INT(_user, USER_POSIX2_VERSION, posix2_version, CTLFLAG_RD,
47586189Srwatson    0, 0,
47646381Sbillf    "The version of POSIX 1003.2 with which the system attempts to comply");
47786189SrwatsonSYSCTL_INT(_user, USER_POSIX2_C_BIND, posix2_c_bind, CTLFLAG_RD,
47846381Sbillf    0, 0, "Whether C development supports the C bindings option");
47986189SrwatsonSYSCTL_INT(_user, USER_POSIX2_C_DEV, posix2_c_dev, CTLFLAG_RD,
48046381Sbillf    0, 0, "Whether system supports the C development utilities option");
48186189SrwatsonSYSCTL_INT(_user, USER_POSIX2_CHAR_TERM, posix2_char_term, CTLFLAG_RD,
48246381Sbillf    0, 0, "");
48386189SrwatsonSYSCTL_INT(_user, USER_POSIX2_FORT_DEV, posix2_fort_dev, CTLFLAG_RD,
48446381Sbillf    0, 0, "Whether system supports FORTRAN development utilities");
48586189SrwatsonSYSCTL_INT(_user, USER_POSIX2_FORT_RUN, posix2_fort_run, CTLFLAG_RD,
48646381Sbillf    0, 0, "Whether system supports FORTRAN runtime utilities");
48786189SrwatsonSYSCTL_INT(_user, USER_POSIX2_LOCALEDEF, posix2_localedef, CTLFLAG_RD,
48846381Sbillf    0, 0, "Whether system supports creation of locales");
48986189SrwatsonSYSCTL_INT(_user, USER_POSIX2_SW_DEV, posix2_sw_dev, CTLFLAG_RD,
49046381Sbillf    0, 0, "Whether system supports software development utilities");
49186189SrwatsonSYSCTL_INT(_user, USER_POSIX2_UPE, posix2_upe, CTLFLAG_RD,
49246381Sbillf    0, 0, "Whether system supports the user portability utilities");
49386189SrwatsonSYSCTL_INT(_user, USER_STREAM_MAX, stream_max, CTLFLAG_RD,
49446381Sbillf    0, 0, "Min Maximum number of streams a process may have open at one time");
49586189SrwatsonSYSCTL_INT(_user, USER_TZNAME_MAX, tzname_max, CTLFLAG_RD,
49646381Sbillf    0, 0, "Min Maximum number of types supported for timezone names");
49748891Sphk
49848891Sphk#include <sys/vnode.h>
49986189SrwatsonSYSCTL_INT(_debug_sizeof, OID_AUTO, vnode, CTLFLAG_RD,
50048891Sphk    0, sizeof(struct vnode), "sizeof(struct vnode)");
50148891Sphk
50286189SrwatsonSYSCTL_INT(_debug_sizeof, OID_AUTO, proc, CTLFLAG_RD,
50348891Sphk    0, sizeof(struct proc), "sizeof(struct proc)");
50448927Sphk
505239301Skibstatic int
506239301Skibsysctl_kern_pid_max(SYSCTL_HANDLER_ARGS)
507239301Skib{
508239301Skib	int error, pm;
509239301Skib
510239301Skib	pm = pid_max;
511239301Skib	error = sysctl_handle_int(oidp, &pm, 0, req);
512239301Skib	if (error || !req->newptr)
513239301Skib		return (error);
514239301Skib	sx_xlock(&proctree_lock);
515239301Skib	sx_xlock(&allproc_lock);
516239329Skib
517239329Skib	/*
518239329Skib	 * Only permit the values less then PID_MAX.
519239329Skib	 * As a safety measure, do not allow to limit the pid_max too much.
520239329Skib	 */
521239329Skib	if (pm < 300 || pm > PID_MAX)
522239301Skib		error = EINVAL;
523239301Skib	else
524239301Skib		pid_max = pm;
525239301Skib	sx_xunlock(&allproc_lock);
526239301Skib	sx_xunlock(&proctree_lock);
527239301Skib	return (error);
528239301Skib}
529239301SkibSYSCTL_PROC(_kern, OID_AUTO, pid_max, CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_TUN |
530239301Skib    CTLFLAG_MPSAFE, 0, 0, sysctl_kern_pid_max, "I",
531239301Skib    "Maximum allowed pid");
532239301Skib
53360041Sphk#include <sys/bio.h>
53458926Sphk#include <sys/buf.h>
53558926SphkSYSCTL_INT(_debug_sizeof, OID_AUTO, bio, CTLFLAG_RD,
53658926Sphk    0, sizeof(struct bio), "sizeof(struct bio)");
53758926SphkSYSCTL_INT(_debug_sizeof, OID_AUTO, buf, CTLFLAG_RD,
53858926Sphk    0, sizeof(struct buf), "sizeof(struct buf)");
53972376Sjake
54072376Sjake#include <sys/user.h>
54172376SjakeSYSCTL_INT(_debug_sizeof, OID_AUTO, kinfo_proc, CTLFLAG_RD,
54272376Sjake    0, sizeof(struct kinfo_proc), "sizeof(struct kinfo_proc)");
543108685Sjake
544108696Sjake/* XXX compatibility, remove for 6.0 */
545108696Sjake#include <sys/imgact.h>
546108696Sjake#include <sys/imgact_elf.h>
547108696SjakeSYSCTL_INT(_kern, OID_AUTO, fallback_elf_brand, CTLFLAG_RW,
548108696Sjake    &__elfN(fallback_brand), sizeof(__elfN(fallback_brand)),
549108696Sjake    "compatibility for kern.fallback_elf_brand");
550