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_INT(_kern, KERN_OSREV, osrevision, CTLFLAG_RD|CTLFLAG_CAPRD,
94273736Shselasky    SYSCTL_NULL_INT_PTR, BSD, "Operating system revision");
9515103Sphk
96187864SedSYSCTL_STRING(_kern, KERN_VERSION, version, CTLFLAG_RD|CTLFLAG_MPSAFE,
9746381Sbillf    version, 0, "Kernel version");
9815103Sphk
99246254SavgSYSCTL_STRING(_kern, OID_AUTO, compiler_version, CTLFLAG_RD|CTLFLAG_MPSAFE,
100246246Savg    compiler_version, 0, "Version of compiler used to compile kernel");
101246246Savg
102224159SrwatsonSYSCTL_STRING(_kern, KERN_OSTYPE, ostype, CTLFLAG_RD|CTLFLAG_MPSAFE|
103224159Srwatson    CTLFLAG_CAPRD, ostype, 0, "Operating system type");
10415103Sphk
105121307SsilbySYSCTL_INT(_kern, KERN_MAXPROC, maxproc, CTLFLAG_RDTUN,
10646381Sbillf    &maxproc, 0, "Maximum number of processes");
10715103Sphk
10886189SrwatsonSYSCTL_INT(_kern, KERN_MAXPROCPERUID, maxprocperuid, CTLFLAG_RW,
10946381Sbillf    &maxprocperuid, 0, "Maximum processes allowed per userid");
11015103Sphk
111121307SsilbySYSCTL_INT(_kern, OID_AUTO, maxusers, CTLFLAG_RDTUN,
11280418Speter    &maxusers, 0, "Hint for kernel tuning");
11380418Speter
114224159SrwatsonSYSCTL_INT(_kern, KERN_ARGMAX, argmax, CTLFLAG_RD|CTLFLAG_CAPRD,
115273736Shselasky    SYSCTL_NULL_INT_PTR, ARG_MAX, "Maximum bytes of argument to execve(2)");
11615103Sphk
117224159SrwatsonSYSCTL_INT(_kern, KERN_POSIX1, posix1version, CTLFLAG_RD|CTLFLAG_CAPRD,
118273736Shselasky    SYSCTL_NULL_INT_PTR, _POSIX_VERSION, "Version of POSIX attempting to comply to");
11915103Sphk
120224159SrwatsonSYSCTL_INT(_kern, KERN_NGROUPS, ngroups, CTLFLAG_RDTUN|CTLFLAG_CAPRD,
121202143Sbrooks    &ngroups_max, 0,
122201953Sbrooks    "Maximum number of supplemental groups a user can belong to");
12315103Sphk
124224159SrwatsonSYSCTL_INT(_kern, KERN_JOB_CONTROL, job_control, CTLFLAG_RD|CTLFLAG_CAPRD,
125273736Shselasky    SYSCTL_NULL_INT_PTR, 1, "Whether job control is available");
12615103Sphk
12715103Sphk#ifdef _POSIX_SAVED_IDS
128224159SrwatsonSYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD|CTLFLAG_CAPRD,
129273736Shselasky    SYSCTL_NULL_INT_PTR, 1, "Whether saved set-group/user ID is available");
13015103Sphk#else
131224159SrwatsonSYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD|CTLFLAG_CAPRD,
132273736Shselasky    SYSCTL_NULL_INT_PTR, 0, "Whether saved set-group/user ID is available");
13315103Sphk#endif
13415103Sphk
13515103Sphkchar kernelname[MAXPATHLEN] = "/kernel";	/* XXX bloat */
13615103Sphk
137244103SalfredSYSCTL_STRING(_kern, KERN_BOOTFILE, bootfile, CTLFLAG_RW,
13846381Sbillf    kernelname, sizeof kernelname, "Name of kernel file booted");
13915103Sphk
140224159SrwatsonSYSCTL_INT(_hw, HW_NCPU, ncpu, CTLFLAG_RD|CTLFLAG_CAPRD,
14146381Sbillf    &mp_ncpus, 0, "Number of active CPUs");
14215103Sphk
143224159SrwatsonSYSCTL_INT(_hw, HW_BYTEORDER, byteorder, CTLFLAG_RD|CTLFLAG_CAPRD,
144273736Shselasky    SYSCTL_NULL_INT_PTR, BYTE_ORDER, "System byte order");
14515103Sphk
146224159SrwatsonSYSCTL_INT(_hw, HW_PAGESIZE, pagesize, CTLFLAG_RD|CTLFLAG_CAPRD,
147273736Shselasky    SYSCTL_NULL_INT_PTR, PAGE_SIZE, "System memory page size");
14815103Sphk
149106605Stmmstatic int
150169727Skansysctl_kern_arnd(SYSCTL_HANDLER_ARGS)
151169727Skan{
152176367Santoine	char buf[256];
153176367Santoine	size_t len;
154169727Skan
155176367Santoine	len = req->oldlen;
156176367Santoine	if (len > sizeof(buf))
157176367Santoine		len = sizeof(buf);
158176367Santoine	arc4rand(buf, len, 0);
159176367Santoine	return (SYSCTL_OUT(req, buf, len));
160169727Skan}
161169727Skan
162187864SedSYSCTL_PROC(_kern, KERN_ARND, arandom,
163224159Srwatson    CTLTYPE_OPAQUE | CTLFLAG_RD | CTLFLAG_MPSAFE | CTLFLAG_CAPRD, NULL, 0,
164187864Sed    sysctl_kern_arnd, "", "arc4rand");
165169727Skan
166169727Skanstatic int
167106605Stmmsysctl_hw_physmem(SYSCTL_HANDLER_ARGS)
168106605Stmm{
169106605Stmm	u_long val;
170106605Stmm
171106605Stmm	val = ctob(physmem);
172106605Stmm	return (sysctl_handle_long(oidp, &val, 0, req));
173106605Stmm}
174106605Stmm
175106605StmmSYSCTL_PROC(_hw, HW_PHYSMEM, physmem, CTLTYPE_ULONG | CTLFLAG_RD,
176106605Stmm	0, 0, sysctl_hw_physmem, "LU", "");
177106605Stmm
178106605Stmmstatic int
179142834Swessysctl_hw_realmem(SYSCTL_HANDLER_ARGS)
180142834Swes{
181142834Swes	u_long val;
182142834Swes	val = ctob(realmem);
183142834Swes	return (sysctl_handle_long(oidp, &val, 0, req));
184142834Swes}
185142834SwesSYSCTL_PROC(_hw, HW_REALMEM, realmem, CTLTYPE_ULONG | CTLFLAG_RD,
186142834Swes	0, 0, sysctl_hw_realmem, "LU", "");
187142834Swesstatic int
188106605Stmmsysctl_hw_usermem(SYSCTL_HANDLER_ARGS)
189106605Stmm{
190106605Stmm	u_long val;
191106605Stmm
192170170Sattilio	val = ctob(physmem - cnt.v_wire_count);
193106605Stmm	return (sysctl_handle_long(oidp, &val, 0, req));
194106605Stmm}
195106605Stmm
196106605StmmSYSCTL_PROC(_hw, HW_USERMEM, usermem, CTLTYPE_ULONG | CTLFLAG_RD,
197106605Stmm	0, 0, sysctl_hw_usermem, "LU", "");
198106605Stmm
199217326SmdfSYSCTL_LONG(_hw, OID_AUTO, availpages, CTLFLAG_RD, &physmem, 0, "");
200106605Stmm
201197316Salcu_long pagesizes[MAXPAGESIZES] = { PAGE_SIZE };
202197316Salc
203197316Salcstatic int
204197316Salcsysctl_hw_pagesizes(SYSCTL_HANDLER_ARGS)
205197316Salc{
206197316Salc	int error;
207197316Salc#ifdef SCTL_MASK32
208197316Salc	int i;
209197316Salc	uint32_t pagesizes32[MAXPAGESIZES];
210197316Salc
211197316Salc	if (req->flags & SCTL_MASK32) {
212197316Salc		/*
213197316Salc		 * Recreate the "pagesizes" array with 32-bit elements.  Truncate
214197316Salc		 * any page size greater than UINT32_MAX to zero.
215197316Salc		 */
216197316Salc		for (i = 0; i < MAXPAGESIZES; i++)
217197316Salc			pagesizes32[i] = (uint32_t)pagesizes[i];
218197316Salc
219197316Salc		error = SYSCTL_OUT(req, pagesizes32, sizeof(pagesizes32));
220197316Salc	} else
221197316Salc#endif
222197316Salc		error = SYSCTL_OUT(req, pagesizes, sizeof(pagesizes));
223197316Salc	return (error);
224197316Salc}
225197316SalcSYSCTL_PROC(_hw, OID_AUTO, pagesizes, CTLTYPE_ULONG | CTLFLAG_RD,
226197316Salc    NULL, 0, sysctl_hw_pagesizes, "LU", "Supported page sizes");
227197316Salc
228210369Skib#ifdef SCTL_MASK32
229210369Skibint adaptive_machine_arch = 1;
230210369SkibSYSCTL_INT(_debug, OID_AUTO, adaptive_machine_arch, CTLFLAG_RW,
231210369Skib    &adaptive_machine_arch, 1,
232210369Skib    "Adapt reported machine architecture to the ABI of the binary");
233210369Skib#endif
23428885Skato
23546155Sphkstatic int
236210369Skibsysctl_hw_machine_arch(SYSCTL_HANDLER_ARGS)
237210369Skib{
238210369Skib	int error;
239210369Skib	static const char machine_arch[] = MACHINE_ARCH;
240210369Skib#ifdef SCTL_MASK32
241210369Skib	static const char machine_arch32[] = MACHINE_ARCH32;
242210369Skib
243210369Skib	if ((req->flags & SCTL_MASK32) != 0 && adaptive_machine_arch)
244210369Skib		error = SYSCTL_OUT(req, machine_arch32, sizeof(machine_arch32));
245210369Skib	else
246210369Skib#endif
247210369Skib		error = SYSCTL_OUT(req, machine_arch, sizeof(machine_arch));
248210369Skib	return (error);
249210369Skib
250210369Skib}
251210369SkibSYSCTL_PROC(_hw, HW_MACHINE_ARCH, machine_arch, CTLTYPE_STRING | CTLFLAG_RD,
252210369Skib    NULL, 0, sysctl_hw_machine_arch, "A", "System architecture");
253210369Skib
254259465SnwhitehornSYSCTL_STRING(_kern, OID_AUTO, supported_archs, CTLFLAG_RD | CTLFLAG_MPSAFE,
255259465Snwhitehorn#ifdef COMPAT_FREEBSD32
256259465Snwhitehorn    MACHINE_ARCH " " MACHINE_ARCH32, 0, "Supported architectures for binaries");
257259465Snwhitehorn#else
258259465Snwhitehorn    MACHINE_ARCH, 0, "Supported architectures for binaries");
259259465Snwhitehorn#endif
260259465Snwhitehorn
261210369Skibstatic int
26262573Sphksysctl_hostname(SYSCTL_HANDLER_ARGS)
26346155Sphk{
264193066Sjamie	struct prison *pr, *cpr;
265193066Sjamie	size_t pr_offset;
266193066Sjamie	char tmpname[MAXHOSTNAMELEN];
267193066Sjamie	int descend, error, len;
26815103Sphk
269193066Sjamie	/*
270193066Sjamie	 * This function can set: hostname domainname hostuuid.
271193066Sjamie	 * Keep that in mind when comments say "hostname".
272193066Sjamie	 */
273193066Sjamie	pr_offset = (size_t)arg1;
274193066Sjamie	len = arg2;
275193066Sjamie	KASSERT(len <= sizeof(tmpname),
276193066Sjamie	    ("length %d too long for %s", len, __func__));
277193066Sjamie
27891406Sjhb	pr = req->td->td_ucred->cr_prison;
279193066Sjamie	if (!(pr->pr_allow & PR_ALLOW_SET_HOSTNAME) && req->newptr)
280193066Sjamie		return (EPERM);
281193066Sjamie	/*
282193066Sjamie	 * Make a local copy of hostname to get/set so we don't have to hold
283193066Sjamie	 * the jail mutex during the sysctl copyin/copyout activities.
284193066Sjamie	 */
285193066Sjamie	mtx_lock(&pr->pr_mtx);
286193066Sjamie	bcopy((char *)pr + pr_offset, tmpname, len);
287193066Sjamie	mtx_unlock(&pr->pr_mtx);
288193066Sjamie
289193066Sjamie	error = sysctl_handle_string(oidp, tmpname, len, req);
290193066Sjamie
291193066Sjamie	if (req->newptr != NULL && error == 0) {
29287275Srwatson		/*
293193066Sjamie		 * Copy the locally set hostname to all jails that share
294193066Sjamie		 * this host info.
29587275Srwatson		 */
296193066Sjamie		sx_slock(&allprison_lock);
297193066Sjamie		while (!(pr->pr_flags & PR_HOST))
298193066Sjamie			pr = pr->pr_parent;
29987275Srwatson		mtx_lock(&pr->pr_mtx);
300193066Sjamie		bcopy(tmpname, (char *)pr + pr_offset, len);
301193066Sjamie		FOREACH_PRISON_DESCENDANT_LOCKED(pr, cpr, descend)
302193066Sjamie			if (cpr->pr_flags & PR_HOST)
303193066Sjamie				descend = 0;
304193066Sjamie			else
305193066Sjamie				bcopy(tmpname, (char *)cpr + pr_offset, len);
30687275Srwatson		mtx_unlock(&pr->pr_mtx);
307193066Sjamie		sx_sunlock(&allprison_lock);
308180291Srwatson	}
30946155Sphk	return (error);
31046155Sphk}
31146155Sphk
31286189SrwatsonSYSCTL_PROC(_kern, KERN_HOSTNAME, hostname,
313193066Sjamie    CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE,
314194118Sjamie    (void *)(offsetof(struct prison, pr_hostname)), MAXHOSTNAMELEN,
315193066Sjamie    sysctl_hostname, "A", "Hostname");
316193066SjamieSYSCTL_PROC(_kern, KERN_NISDOMAINNAME, domainname,
317193066Sjamie    CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE,
318194118Sjamie    (void *)(offsetof(struct prison, pr_domainname)), MAXHOSTNAMELEN,
319193066Sjamie    sysctl_hostname, "A", "Name of the current YP/NIS domain");
320193066SjamieSYSCTL_PROC(_kern, KERN_HOSTUUID, hostuuid,
321193066Sjamie    CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE,
322194118Sjamie    (void *)(offsetof(struct prison, pr_hostuuid)), HOSTUUIDLEN,
323193066Sjamie    sysctl_hostname, "A", "Host UUID");
32446155Sphk
32586190Srwatsonstatic int	regression_securelevel_nonmonotonic = 0;
32684611Srwatson
32787072Srwatson#ifdef REGRESSION
32884611SrwatsonSYSCTL_INT(_regression, OID_AUTO, securelevel_nonmonotonic, CTLFLAG_RW,
32984611Srwatson    &regression_securelevel_nonmonotonic, 0, "securelevel may be lowered");
33086190Srwatson#endif
33184611Srwatson
33215103Sphkstatic int
33362573Sphksysctl_kern_securelvl(SYSCTL_HANDLER_ARGS)
33415103Sphk{
335192895Sjamie	struct prison *pr, *cpr;
336192895Sjamie	int descend, error, level;
33715103Sphk
33891406Sjhb	pr = req->td->td_ucred->cr_prison;
33986145Srwatson
34086140Srwatson	/*
341192895Sjamie	 * Reading the securelevel is easy, since the current jail's level
342192895Sjamie	 * is known to be at least as secure as any higher levels.  Perform
343192895Sjamie	 * a lockless read since the securelevel is an integer.
34486140Srwatson	 */
345192895Sjamie	level = pr->pr_securelevel;
34686140Srwatson	error = sysctl_handle_int(oidp, &level, 0, req);
34786140Srwatson	if (error || !req->newptr)
34886140Srwatson		return (error);
349192895Sjamie	/* Permit update only if the new securelevel exceeds the old. */
350192895Sjamie	sx_slock(&allprison_lock);
351192895Sjamie	mtx_lock(&pr->pr_mtx);
352192895Sjamie	if (!regression_securelevel_nonmonotonic &&
353192895Sjamie	    level < pr->pr_securelevel) {
354192895Sjamie		mtx_unlock(&pr->pr_mtx);
355192895Sjamie		sx_sunlock(&allprison_lock);
356192895Sjamie		return (EPERM);
357192895Sjamie	}
358192895Sjamie	pr->pr_securelevel = level;
35986140Srwatson	/*
360192895Sjamie	 * Set all child jails to be at least this level, but do not lower
361192895Sjamie	 * them (even if regression_securelevel_nonmonotonic).
36286140Srwatson	 */
363192895Sjamie	FOREACH_PRISON_DESCENDANT_LOCKED(pr, cpr, descend) {
364192895Sjamie		if (cpr->pr_securelevel < level)
365192895Sjamie			cpr->pr_securelevel = level;
36686140Srwatson	}
367192895Sjamie	mtx_unlock(&pr->pr_mtx);
368192895Sjamie	sx_sunlock(&allprison_lock);
36986140Srwatson	return (error);
37015103Sphk}
37115103Sphk
37283990SrwatsonSYSCTL_PROC(_kern, KERN_SECURELVL, securelevel,
37383990Srwatson    CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_PRISON, 0, 0, sysctl_kern_securelvl,
37483990Srwatson    "I", "Current secure level");
37561370Srwatson
376169604Swkoszek#ifdef INCLUDE_CONFIG_FILE
377169507Swkoszek/* Actual kernel configuration options. */
378169507Swkoszekextern char kernconfstring[];
379169507Swkoszek
380244098SalfredSYSCTL_STRING(_kern, OID_AUTO, conftxt, CTLFLAG_RD, kernconfstring, 0,
381244098Salfred    "Kernel configuration file");
382169650Simp#endif
383169507Swkoszek
384180291Srwatsonstatic int
385193066Sjamiesysctl_hostid(SYSCTL_HANDLER_ARGS)
386180291Srwatson{
387193066Sjamie	struct prison *pr, *cpr;
388193066Sjamie	u_long tmpid;
389193066Sjamie	int descend, error;
390180291Srwatson
391193066Sjamie	/*
392193066Sjamie	 * Like sysctl_hostname, except it operates on a u_long
393193066Sjamie	 * instead of a string, and is used only for hostid.
394193066Sjamie	 */
395193066Sjamie	pr = req->td->td_ucred->cr_prison;
396193066Sjamie	if (!(pr->pr_allow & PR_ALLOW_SET_HOSTNAME) && req->newptr)
397193066Sjamie		return (EPERM);
398193066Sjamie	tmpid = pr->pr_hostid;
399193066Sjamie	error = sysctl_handle_long(oidp, &tmpid, 0, req);
400193066Sjamie
401180291Srwatson	if (req->newptr != NULL && error == 0) {
402193066Sjamie		sx_slock(&allprison_lock);
403193066Sjamie		while (!(pr->pr_flags & PR_HOST))
404193066Sjamie			pr = pr->pr_parent;
405193066Sjamie		mtx_lock(&pr->pr_mtx);
406193066Sjamie		pr->pr_hostid = tmpid;
407193066Sjamie		FOREACH_PRISON_DESCENDANT_LOCKED(pr, cpr, descend)
408193066Sjamie			if (cpr->pr_flags & PR_HOST)
409193066Sjamie				descend = 0;
410193066Sjamie			else
411193066Sjamie				cpr->pr_hostid = tmpid;
412193066Sjamie		mtx_unlock(&pr->pr_mtx);
413193066Sjamie		sx_sunlock(&allprison_lock);
414180291Srwatson	}
415180291Srwatson	return (error);
416180291Srwatson}
417180291Srwatson
418193066SjamieSYSCTL_PROC(_kern, KERN_HOSTID, hostid,
419193066Sjamie    CTLTYPE_ULONG | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE,
420193066Sjamie    NULL, 0, sysctl_hostid, "LU", "Host ID");
421180291Srwatson
422280632Sian/*
423280632Sian * The osrelease string is copied from the global (osrelease in vers.c) into
424280632Sian * prison0 by a sysinit and is inherited by child jails if not changed at jail
425280632Sian * creation, so we always return the copy from the current prison data.
426280632Sian */
427280632Sianstatic int
428280632Siansysctl_osrelease(SYSCTL_HANDLER_ARGS)
429280632Sian{
430280632Sian	struct prison *pr;
431280632Sian
432280632Sian	pr = req->td->td_ucred->cr_prison;
433280632Sian	return (SYSCTL_OUT(req, pr->pr_osrelease, strlen(pr->pr_osrelease) + 1));
434280632Sian
435280632Sian}
436280632Sian
437280632SianSYSCTL_PROC(_kern, KERN_OSRELEASE, osrelease,
438280632Sian    CTLTYPE_STRING | CTLFLAG_CAPRD | CTLFLAG_RD | CTLFLAG_MPSAFE,
439280632Sian    NULL, 0, sysctl_osrelease, "A", "Operating system release");
440280632Sian
441280632Sian/*
442280632Sian * The osreldate number is copied from the global (osreldate in vers.c) into
443280632Sian * prison0 by a sysinit and is inherited by child jails if not changed at jail
444280632Sian * creation, so we always return the value from the current prison data.
445280632Sian */
446280632Sianstatic int
447280632Siansysctl_osreldate(SYSCTL_HANDLER_ARGS)
448280632Sian{
449280632Sian	struct prison *pr;
450280632Sian
451280632Sian	pr = req->td->td_ucred->cr_prison;
452280632Sian	return (SYSCTL_OUT(req, &pr->pr_osreldate, sizeof(pr->pr_osreldate)));
453280632Sian
454280632Sian}
455280632Sian
456280632Sian/*
457280632Sian * NOTICE: The *userland* release date is available in
458280632Sian * /usr/include/osreldate.h
459280632Sian */
460280632SianSYSCTL_PROC(_kern, KERN_OSRELDATE, osreldate,
461280632Sian    CTLTYPE_INT | CTLFLAG_CAPRD | CTLFLAG_RD | CTLFLAG_MPSAFE,
462280632Sian    NULL, 0, sysctl_osreldate, "I", "Kernel release date");
463280632Sian
464175021SjhbSYSCTL_NODE(_kern, OID_AUTO, features, CTLFLAG_RD, 0, "Kernel Features");
465175021Sjhb
466175417Sjhb#ifdef COMPAT_FREEBSD4
467175417SjhbFEATURE(compat_freebsd4, "Compatible with FreeBSD 4");
468175417Sjhb#endif
469175417Sjhb
470175417Sjhb#ifdef COMPAT_FREEBSD5
471175417SjhbFEATURE(compat_freebsd5, "Compatible with FreeBSD 5");
472175417Sjhb#endif
473175417Sjhb
474175417Sjhb#ifdef COMPAT_FREEBSD6
475175417SjhbFEATURE(compat_freebsd6, "Compatible with FreeBSD 6");
476175417Sjhb#endif
477175417Sjhb
478175417Sjhb#ifdef COMPAT_FREEBSD7
479175417SjhbFEATURE(compat_freebsd7, "Compatible with FreeBSD 7");
480175417Sjhb#endif
481175417Sjhb
48215103Sphk/*
48315103Sphk * This is really cheating.  These actually live in the libc, something
48486189Srwatson * which I'm not quite sure is a good idea anyway, but in order for
48515103Sphk * getnext and friends to actually work, we define dummies here.
486224159Srwatson *
487224159Srwatson * XXXRW: These probably should be CTLFLAG_CAPRD.
48815103Sphk */
48986189SrwatsonSYSCTL_STRING(_user, USER_CS_PATH, cs_path, CTLFLAG_RD,
49046381Sbillf    "", 0, "PATH that finds all the standard utilities");
49186189SrwatsonSYSCTL_INT(_user, USER_BC_BASE_MAX, bc_base_max, CTLFLAG_RD,
492273736Shselasky    SYSCTL_NULL_INT_PTR, 0, "Max ibase/obase values in bc(1)");
49386189SrwatsonSYSCTL_INT(_user, USER_BC_DIM_MAX, bc_dim_max, CTLFLAG_RD,
494273736Shselasky    SYSCTL_NULL_INT_PTR, 0, "Max array size in bc(1)");
49586189SrwatsonSYSCTL_INT(_user, USER_BC_SCALE_MAX, bc_scale_max, CTLFLAG_RD,
496273736Shselasky    SYSCTL_NULL_INT_PTR, 0, "Max scale value in bc(1)");
49786189SrwatsonSYSCTL_INT(_user, USER_BC_STRING_MAX, bc_string_max, CTLFLAG_RD,
498273736Shselasky    SYSCTL_NULL_INT_PTR, 0, "Max string length in bc(1)");
49986189SrwatsonSYSCTL_INT(_user, USER_COLL_WEIGHTS_MAX, coll_weights_max, CTLFLAG_RD,
500273736Shselasky    SYSCTL_NULL_INT_PTR, 0, "Maximum number of weights assigned to an LC_COLLATE locale entry");
501273736ShselaskySYSCTL_INT(_user, USER_EXPR_NEST_MAX, expr_nest_max, CTLFLAG_RD,
502273736Shselasky    SYSCTL_NULL_INT_PTR, 0, "");
50386189SrwatsonSYSCTL_INT(_user, USER_LINE_MAX, line_max, CTLFLAG_RD,
504273736Shselasky    SYSCTL_NULL_INT_PTR, 0, "Max length (bytes) of a text-processing utility's input line");
50586189SrwatsonSYSCTL_INT(_user, USER_RE_DUP_MAX, re_dup_max, CTLFLAG_RD,
506273736Shselasky    SYSCTL_NULL_INT_PTR, 0, "Maximum number of repeats of a regexp permitted");
50786189SrwatsonSYSCTL_INT(_user, USER_POSIX2_VERSION, posix2_version, CTLFLAG_RD,
508273736Shselasky    SYSCTL_NULL_INT_PTR, 0,
50946381Sbillf    "The version of POSIX 1003.2 with which the system attempts to comply");
51086189SrwatsonSYSCTL_INT(_user, USER_POSIX2_C_BIND, posix2_c_bind, CTLFLAG_RD,
511273736Shselasky    SYSCTL_NULL_INT_PTR, 0, "Whether C development supports the C bindings option");
51286189SrwatsonSYSCTL_INT(_user, USER_POSIX2_C_DEV, posix2_c_dev, CTLFLAG_RD,
513273736Shselasky    SYSCTL_NULL_INT_PTR, 0, "Whether system supports the C development utilities option");
51486189SrwatsonSYSCTL_INT(_user, USER_POSIX2_CHAR_TERM, posix2_char_term, CTLFLAG_RD,
515273736Shselasky    SYSCTL_NULL_INT_PTR, 0, "");
51686189SrwatsonSYSCTL_INT(_user, USER_POSIX2_FORT_DEV, posix2_fort_dev, CTLFLAG_RD,
517273736Shselasky    SYSCTL_NULL_INT_PTR, 0, "Whether system supports FORTRAN development utilities");
51886189SrwatsonSYSCTL_INT(_user, USER_POSIX2_FORT_RUN, posix2_fort_run, CTLFLAG_RD,
519273736Shselasky    SYSCTL_NULL_INT_PTR, 0, "Whether system supports FORTRAN runtime utilities");
52086189SrwatsonSYSCTL_INT(_user, USER_POSIX2_LOCALEDEF, posix2_localedef, CTLFLAG_RD,
521273736Shselasky    SYSCTL_NULL_INT_PTR, 0, "Whether system supports creation of locales");
52286189SrwatsonSYSCTL_INT(_user, USER_POSIX2_SW_DEV, posix2_sw_dev, CTLFLAG_RD,
523273736Shselasky    SYSCTL_NULL_INT_PTR, 0, "Whether system supports software development utilities");
52486189SrwatsonSYSCTL_INT(_user, USER_POSIX2_UPE, posix2_upe, CTLFLAG_RD,
525273736Shselasky    SYSCTL_NULL_INT_PTR, 0, "Whether system supports the user portability utilities");
52686189SrwatsonSYSCTL_INT(_user, USER_STREAM_MAX, stream_max, CTLFLAG_RD,
527273736Shselasky    SYSCTL_NULL_INT_PTR, 0, "Min Maximum number of streams a process may have open at one time");
52886189SrwatsonSYSCTL_INT(_user, USER_TZNAME_MAX, tzname_max, CTLFLAG_RD,
529273736Shselasky    SYSCTL_NULL_INT_PTR, 0, "Min Maximum number of types supported for timezone names");
53048891Sphk
53148891Sphk#include <sys/vnode.h>
53286189SrwatsonSYSCTL_INT(_debug_sizeof, OID_AUTO, vnode, CTLFLAG_RD,
533273736Shselasky    SYSCTL_NULL_INT_PTR, sizeof(struct vnode), "sizeof(struct vnode)");
53448891Sphk
53586189SrwatsonSYSCTL_INT(_debug_sizeof, OID_AUTO, proc, CTLFLAG_RD,
536273736Shselasky    SYSCTL_NULL_INT_PTR, sizeof(struct proc), "sizeof(struct proc)");
53748927Sphk
538239301Skibstatic int
539239301Skibsysctl_kern_pid_max(SYSCTL_HANDLER_ARGS)
540239301Skib{
541239301Skib	int error, pm;
542239301Skib
543239301Skib	pm = pid_max;
544239301Skib	error = sysctl_handle_int(oidp, &pm, 0, req);
545239301Skib	if (error || !req->newptr)
546239301Skib		return (error);
547239301Skib	sx_xlock(&proctree_lock);
548239301Skib	sx_xlock(&allproc_lock);
549239329Skib
550239329Skib	/*
551239329Skib	 * Only permit the values less then PID_MAX.
552239329Skib	 * As a safety measure, do not allow to limit the pid_max too much.
553239329Skib	 */
554239329Skib	if (pm < 300 || pm > PID_MAX)
555239301Skib		error = EINVAL;
556239301Skib	else
557239301Skib		pid_max = pm;
558239301Skib	sx_xunlock(&allproc_lock);
559239301Skib	sx_xunlock(&proctree_lock);
560239301Skib	return (error);
561239301Skib}
562239301SkibSYSCTL_PROC(_kern, OID_AUTO, pid_max, CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_TUN |
563239301Skib    CTLFLAG_MPSAFE, 0, 0, sysctl_kern_pid_max, "I",
564239301Skib    "Maximum allowed pid");
565239301Skib
56660041Sphk#include <sys/bio.h>
56758926Sphk#include <sys/buf.h>
56858926SphkSYSCTL_INT(_debug_sizeof, OID_AUTO, bio, CTLFLAG_RD,
569273736Shselasky    SYSCTL_NULL_INT_PTR, sizeof(struct bio), "sizeof(struct bio)");
57058926SphkSYSCTL_INT(_debug_sizeof, OID_AUTO, buf, CTLFLAG_RD,
571273736Shselasky    SYSCTL_NULL_INT_PTR, sizeof(struct buf), "sizeof(struct buf)");
57272376Sjake
57372376Sjake#include <sys/user.h>
57472376SjakeSYSCTL_INT(_debug_sizeof, OID_AUTO, kinfo_proc, CTLFLAG_RD,
575273736Shselasky    SYSCTL_NULL_INT_PTR, sizeof(struct kinfo_proc), "sizeof(struct kinfo_proc)");
576108685Sjake
577294283Sjhb/* Used by kernel debuggers. */
578294283Sjhbconst int pcb_size = sizeof(struct pcb);
579294283SjhbSYSCTL_INT(_debug_sizeof, OID_AUTO, pcb, CTLFLAG_RD,
580294283Sjhb    SYSCTL_NULL_INT_PTR, sizeof(struct pcb), "sizeof(struct pcb)");
581294283Sjhb
582108696Sjake/* XXX compatibility, remove for 6.0 */
583108696Sjake#include <sys/imgact.h>
584108696Sjake#include <sys/imgact_elf.h>
585108696SjakeSYSCTL_INT(_kern, OID_AUTO, fallback_elf_brand, CTLFLAG_RW,
586108696Sjake    &__elfN(fallback_brand), sizeof(__elfN(fallback_brand)),
587108696Sjake    "compatibility for kern.fallback_elf_brand");
588