kern_mib.c revision 224159
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: head/sys/kern/kern_mib.c 224159 2011-07-17 23:05:24Z rwatson $");
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
5815103SphkSYSCTL_NODE(, 0,	  sysctl, CTLFLAG_RW, 0,
5915103Sphk	"Sysctl internal magic");
60224159SrwatsonSYSCTL_NODE(, CTL_KERN,	  kern,   CTLFLAG_RW|CTLFLAG_CAPRD, 0,
6115103Sphk	"High kernel, proc, limits &c");
6215103SphkSYSCTL_NODE(, CTL_VM,	  vm,     CTLFLAG_RW, 0,
6315103Sphk	"Virtual memory");
6423382SbdeSYSCTL_NODE(, CTL_VFS,	  vfs,     CTLFLAG_RW, 0,
6515103Sphk	"File system");
6615103SphkSYSCTL_NODE(, CTL_NET,	  net,    CTLFLAG_RW, 0,
6715103Sphk	"Network, (see socket.h)");
6815103SphkSYSCTL_NODE(, CTL_DEBUG,  debug,  CTLFLAG_RW, 0,
6915103Sphk	"Debugging");
7048891SphkSYSCTL_NODE(_debug, OID_AUTO,  sizeof,  CTLFLAG_RW, 0,
7148891Sphk	"Sizeof various things");
7215103SphkSYSCTL_NODE(, CTL_HW,	  hw,     CTLFLAG_RW, 0,
7315103Sphk	"hardware");
7415103SphkSYSCTL_NODE(, CTL_MACHDEP, machdep, CTLFLAG_RW, 0,
7515103Sphk	"machine dependent");
7615103SphkSYSCTL_NODE(, CTL_USER,	  user,   CTLFLAG_RW, 0,
7715103Sphk	"user-level");
7834925SdufaultSYSCTL_NODE(, CTL_P1003_1B,  p1003_1b,   CTLFLAG_RW, 0,
7934925Sdufault	"p1003_1b, (see p1003_1b.h)");
8034029Sdufault
8150465SmarcelSYSCTL_NODE(, OID_AUTO,  compat, CTLFLAG_RW, 0,
8250465Smarcel	"Compatibility code");
8389414SarrSYSCTL_NODE(, OID_AUTO, security, CTLFLAG_RW, 0,
8489414Sarr     	"Security");
8586190Srwatson#ifdef REGRESSION
8686190SrwatsonSYSCTL_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
102224159SrwatsonSYSCTL_STRING(_kern, KERN_OSTYPE, ostype, CTLFLAG_RD|CTLFLAG_MPSAFE|
103224159Srwatson    CTLFLAG_CAPRD, ostype, 0, "Operating system type");
10415103Sphk
105119203Seivind/*
106119203Seivind * NOTICE: The *userland* release date is available in
107119203Seivind * /usr/include/osreldate.h
108119203Seivind */
109224159SrwatsonSYSCTL_INT(_kern, KERN_OSRELDATE, osreldate, CTLFLAG_RD|CTLFLAG_CAPRD,
110119203Seivind    &osreldate, 0, "Kernel release date");
11115103Sphk
112121307SsilbySYSCTL_INT(_kern, KERN_MAXPROC, maxproc, CTLFLAG_RDTUN,
11346381Sbillf    &maxproc, 0, "Maximum number of processes");
11415103Sphk
11586189SrwatsonSYSCTL_INT(_kern, KERN_MAXPROCPERUID, maxprocperuid, CTLFLAG_RW,
11646381Sbillf    &maxprocperuid, 0, "Maximum processes allowed per userid");
11715103Sphk
118121307SsilbySYSCTL_INT(_kern, OID_AUTO, maxusers, CTLFLAG_RDTUN,
11980418Speter    &maxusers, 0, "Hint for kernel tuning");
12080418Speter
121224159SrwatsonSYSCTL_INT(_kern, KERN_ARGMAX, argmax, CTLFLAG_RD|CTLFLAG_CAPRD,
12246381Sbillf    0, ARG_MAX, "Maximum bytes of argument to execve(2)");
12315103Sphk
124224159SrwatsonSYSCTL_INT(_kern, KERN_POSIX1, posix1version, CTLFLAG_RD|CTLFLAG_CAPRD,
125105046Smike    0, _POSIX_VERSION, "Version of POSIX attempting to comply to");
12615103Sphk
127224159SrwatsonSYSCTL_INT(_kern, KERN_NGROUPS, ngroups, CTLFLAG_RDTUN|CTLFLAG_CAPRD,
128202143Sbrooks    &ngroups_max, 0,
129201953Sbrooks    "Maximum number of supplemental groups a user can belong to");
13015103Sphk
131224159SrwatsonSYSCTL_INT(_kern, KERN_JOB_CONTROL, job_control, CTLFLAG_RD|CTLFLAG_CAPRD,
13246381Sbillf    0, 1, "Whether job control is available");
13315103Sphk
13415103Sphk#ifdef _POSIX_SAVED_IDS
135224159SrwatsonSYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD|CTLFLAG_CAPRD,
13646381Sbillf    0, 1, "Whether saved set-group/user ID is available");
13715103Sphk#else
138224159SrwatsonSYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD|CTLFLAG_CAPRD,
13946381Sbillf    0, 0, "Whether saved set-group/user ID is available");
14015103Sphk#endif
14115103Sphk
14215103Sphkchar kernelname[MAXPATHLEN] = "/kernel";	/* XXX bloat */
14315103Sphk
14486189SrwatsonSYSCTL_STRING(_kern, KERN_BOOTFILE, bootfile, CTLFLAG_RW,
14546381Sbillf    kernelname, sizeof kernelname, "Name of kernel file booted");
14615103Sphk
147224159SrwatsonSYSCTL_INT(_hw, HW_NCPU, ncpu, CTLFLAG_RD|CTLFLAG_CAPRD,
14846381Sbillf    &mp_ncpus, 0, "Number of active CPUs");
14915103Sphk
150224159SrwatsonSYSCTL_INT(_hw, HW_BYTEORDER, byteorder, CTLFLAG_RD|CTLFLAG_CAPRD,
15146381Sbillf    0, BYTE_ORDER, "System byte order");
15215103Sphk
153224159SrwatsonSYSCTL_INT(_hw, HW_PAGESIZE, pagesize, CTLFLAG_RD|CTLFLAG_CAPRD,
15446381Sbillf    0, PAGE_SIZE, "System memory page size");
15515103Sphk
156106605Stmmstatic int
157169727Skansysctl_kern_arnd(SYSCTL_HANDLER_ARGS)
158169727Skan{
159176367Santoine	char buf[256];
160176367Santoine	size_t len;
161169727Skan
162176367Santoine	len = req->oldlen;
163176367Santoine	if (len > sizeof(buf))
164176367Santoine		len = sizeof(buf);
165176367Santoine	arc4rand(buf, len, 0);
166176367Santoine	return (SYSCTL_OUT(req, buf, len));
167169727Skan}
168169727Skan
169187864SedSYSCTL_PROC(_kern, KERN_ARND, arandom,
170224159Srwatson    CTLTYPE_OPAQUE | CTLFLAG_RD | CTLFLAG_MPSAFE | CTLFLAG_CAPRD, NULL, 0,
171187864Sed    sysctl_kern_arnd, "", "arc4rand");
172169727Skan
173169727Skanstatic int
174106605Stmmsysctl_hw_physmem(SYSCTL_HANDLER_ARGS)
175106605Stmm{
176106605Stmm	u_long val;
177106605Stmm
178106605Stmm	val = ctob(physmem);
179106605Stmm	return (sysctl_handle_long(oidp, &val, 0, req));
180106605Stmm}
181106605Stmm
182106605StmmSYSCTL_PROC(_hw, HW_PHYSMEM, physmem, CTLTYPE_ULONG | CTLFLAG_RD,
183106605Stmm	0, 0, sysctl_hw_physmem, "LU", "");
184106605Stmm
185106605Stmmstatic int
186142834Swessysctl_hw_realmem(SYSCTL_HANDLER_ARGS)
187142834Swes{
188142834Swes	u_long val;
189142834Swes	val = ctob(realmem);
190142834Swes	return (sysctl_handle_long(oidp, &val, 0, req));
191142834Swes}
192142834SwesSYSCTL_PROC(_hw, HW_REALMEM, realmem, CTLTYPE_ULONG | CTLFLAG_RD,
193142834Swes	0, 0, sysctl_hw_realmem, "LU", "");
194142834Swesstatic int
195106605Stmmsysctl_hw_usermem(SYSCTL_HANDLER_ARGS)
196106605Stmm{
197106605Stmm	u_long val;
198106605Stmm
199170170Sattilio	val = ctob(physmem - cnt.v_wire_count);
200106605Stmm	return (sysctl_handle_long(oidp, &val, 0, req));
201106605Stmm}
202106605Stmm
203106605StmmSYSCTL_PROC(_hw, HW_USERMEM, usermem, CTLTYPE_ULONG | CTLFLAG_RD,
204106605Stmm	0, 0, sysctl_hw_usermem, "LU", "");
205106605Stmm
206217326SmdfSYSCTL_LONG(_hw, OID_AUTO, availpages, CTLFLAG_RD, &physmem, 0, "");
207106605Stmm
208197316Salcu_long pagesizes[MAXPAGESIZES] = { PAGE_SIZE };
209197316Salc
210197316Salcstatic int
211197316Salcsysctl_hw_pagesizes(SYSCTL_HANDLER_ARGS)
212197316Salc{
213197316Salc	int error;
214197316Salc#ifdef SCTL_MASK32
215197316Salc	int i;
216197316Salc	uint32_t pagesizes32[MAXPAGESIZES];
217197316Salc
218197316Salc	if (req->flags & SCTL_MASK32) {
219197316Salc		/*
220197316Salc		 * Recreate the "pagesizes" array with 32-bit elements.  Truncate
221197316Salc		 * any page size greater than UINT32_MAX to zero.
222197316Salc		 */
223197316Salc		for (i = 0; i < MAXPAGESIZES; i++)
224197316Salc			pagesizes32[i] = (uint32_t)pagesizes[i];
225197316Salc
226197316Salc		error = SYSCTL_OUT(req, pagesizes32, sizeof(pagesizes32));
227197316Salc	} else
228197316Salc#endif
229197316Salc		error = SYSCTL_OUT(req, pagesizes, sizeof(pagesizes));
230197316Salc	return (error);
231197316Salc}
232197316SalcSYSCTL_PROC(_hw, OID_AUTO, pagesizes, CTLTYPE_ULONG | CTLFLAG_RD,
233197316Salc    NULL, 0, sysctl_hw_pagesizes, "LU", "Supported page sizes");
234197316Salc
235210369Skib#ifdef SCTL_MASK32
236210369Skibint adaptive_machine_arch = 1;
237210369SkibSYSCTL_INT(_debug, OID_AUTO, adaptive_machine_arch, CTLFLAG_RW,
238210369Skib    &adaptive_machine_arch, 1,
239210369Skib    "Adapt reported machine architecture to the ABI of the binary");
240210369Skib#endif
24128885Skato
24246155Sphkstatic int
243210369Skibsysctl_hw_machine_arch(SYSCTL_HANDLER_ARGS)
244210369Skib{
245210369Skib	int error;
246210369Skib	static const char machine_arch[] = MACHINE_ARCH;
247210369Skib#ifdef SCTL_MASK32
248210369Skib	static const char machine_arch32[] = MACHINE_ARCH32;
249210369Skib
250210369Skib	if ((req->flags & SCTL_MASK32) != 0 && adaptive_machine_arch)
251210369Skib		error = SYSCTL_OUT(req, machine_arch32, sizeof(machine_arch32));
252210369Skib	else
253210369Skib#endif
254210369Skib		error = SYSCTL_OUT(req, machine_arch, sizeof(machine_arch));
255210369Skib	return (error);
256210369Skib
257210369Skib}
258210369SkibSYSCTL_PROC(_hw, HW_MACHINE_ARCH, machine_arch, CTLTYPE_STRING | CTLFLAG_RD,
259210369Skib    NULL, 0, sysctl_hw_machine_arch, "A", "System architecture");
260210369Skib
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
380169507Swkoszekstatic int
381169507Swkoszeksysctl_kern_config(SYSCTL_HANDLER_ARGS)
382169507Swkoszek{
383170071Simp	return (sysctl_handle_string(oidp, kernconfstring,
384170071Simp	    strlen(kernconfstring), req));
385170071Simp}
386169507Swkoszek
387169507SwkoszekSYSCTL_PROC(_kern, OID_AUTO, conftxt, CTLTYPE_STRING|CTLFLAG_RW,
388169507Swkoszek    0, 0, sysctl_kern_config, "", "Kernel configuration file");
389169650Simp#endif
390169507Swkoszek
391180291Srwatsonstatic int
392193066Sjamiesysctl_hostid(SYSCTL_HANDLER_ARGS)
393180291Srwatson{
394193066Sjamie	struct prison *pr, *cpr;
395193066Sjamie	u_long tmpid;
396193066Sjamie	int descend, error;
397180291Srwatson
398193066Sjamie	/*
399193066Sjamie	 * Like sysctl_hostname, except it operates on a u_long
400193066Sjamie	 * instead of a string, and is used only for hostid.
401193066Sjamie	 */
402193066Sjamie	pr = req->td->td_ucred->cr_prison;
403193066Sjamie	if (!(pr->pr_allow & PR_ALLOW_SET_HOSTNAME) && req->newptr)
404193066Sjamie		return (EPERM);
405193066Sjamie	tmpid = pr->pr_hostid;
406193066Sjamie	error = sysctl_handle_long(oidp, &tmpid, 0, req);
407193066Sjamie
408180291Srwatson	if (req->newptr != NULL && error == 0) {
409193066Sjamie		sx_slock(&allprison_lock);
410193066Sjamie		while (!(pr->pr_flags & PR_HOST))
411193066Sjamie			pr = pr->pr_parent;
412193066Sjamie		mtx_lock(&pr->pr_mtx);
413193066Sjamie		pr->pr_hostid = tmpid;
414193066Sjamie		FOREACH_PRISON_DESCENDANT_LOCKED(pr, cpr, descend)
415193066Sjamie			if (cpr->pr_flags & PR_HOST)
416193066Sjamie				descend = 0;
417193066Sjamie			else
418193066Sjamie				cpr->pr_hostid = tmpid;
419193066Sjamie		mtx_unlock(&pr->pr_mtx);
420193066Sjamie		sx_sunlock(&allprison_lock);
421180291Srwatson	}
422180291Srwatson	return (error);
423180291Srwatson}
424180291Srwatson
425193066SjamieSYSCTL_PROC(_kern, KERN_HOSTID, hostid,
426193066Sjamie    CTLTYPE_ULONG | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE,
427193066Sjamie    NULL, 0, sysctl_hostid, "LU", "Host ID");
428180291Srwatson
429175021SjhbSYSCTL_NODE(_kern, OID_AUTO, features, CTLFLAG_RD, 0, "Kernel Features");
430175021Sjhb
431175417Sjhb#ifdef COMPAT_FREEBSD4
432175417SjhbFEATURE(compat_freebsd4, "Compatible with FreeBSD 4");
433175417Sjhb#endif
434175417Sjhb
435175417Sjhb#ifdef COMPAT_FREEBSD5
436175417SjhbFEATURE(compat_freebsd5, "Compatible with FreeBSD 5");
437175417Sjhb#endif
438175417Sjhb
439175417Sjhb#ifdef COMPAT_FREEBSD6
440175417SjhbFEATURE(compat_freebsd6, "Compatible with FreeBSD 6");
441175417Sjhb#endif
442175417Sjhb
443175417Sjhb#ifdef COMPAT_FREEBSD7
444175417SjhbFEATURE(compat_freebsd7, "Compatible with FreeBSD 7");
445175417Sjhb#endif
446175417Sjhb
44715103Sphk/*
44815103Sphk * This is really cheating.  These actually live in the libc, something
44986189Srwatson * which I'm not quite sure is a good idea anyway, but in order for
45015103Sphk * getnext and friends to actually work, we define dummies here.
451224159Srwatson *
452224159Srwatson * XXXRW: These probably should be CTLFLAG_CAPRD.
45315103Sphk */
45486189SrwatsonSYSCTL_STRING(_user, USER_CS_PATH, cs_path, CTLFLAG_RD,
45546381Sbillf    "", 0, "PATH that finds all the standard utilities");
45686189SrwatsonSYSCTL_INT(_user, USER_BC_BASE_MAX, bc_base_max, CTLFLAG_RD,
45746381Sbillf    0, 0, "Max ibase/obase values in bc(1)");
45886189SrwatsonSYSCTL_INT(_user, USER_BC_DIM_MAX, bc_dim_max, CTLFLAG_RD,
45946381Sbillf    0, 0, "Max array size in bc(1)");
46086189SrwatsonSYSCTL_INT(_user, USER_BC_SCALE_MAX, bc_scale_max, CTLFLAG_RD,
46146381Sbillf    0, 0, "Max scale value in bc(1)");
46286189SrwatsonSYSCTL_INT(_user, USER_BC_STRING_MAX, bc_string_max, CTLFLAG_RD,
46346381Sbillf    0, 0, "Max string length in bc(1)");
46486189SrwatsonSYSCTL_INT(_user, USER_COLL_WEIGHTS_MAX, coll_weights_max, CTLFLAG_RD,
46546381Sbillf    0, 0, "Maximum number of weights assigned to an LC_COLLATE locale entry");
46618540SbdeSYSCTL_INT(_user, USER_EXPR_NEST_MAX, expr_nest_max, CTLFLAG_RD, 0, 0, "");
46786189SrwatsonSYSCTL_INT(_user, USER_LINE_MAX, line_max, CTLFLAG_RD,
46846381Sbillf    0, 0, "Max length (bytes) of a text-processing utility's input line");
46986189SrwatsonSYSCTL_INT(_user, USER_RE_DUP_MAX, re_dup_max, CTLFLAG_RD,
47046381Sbillf    0, 0, "Maximum number of repeats of a regexp permitted");
47186189SrwatsonSYSCTL_INT(_user, USER_POSIX2_VERSION, posix2_version, CTLFLAG_RD,
47286189Srwatson    0, 0,
47346381Sbillf    "The version of POSIX 1003.2 with which the system attempts to comply");
47486189SrwatsonSYSCTL_INT(_user, USER_POSIX2_C_BIND, posix2_c_bind, CTLFLAG_RD,
47546381Sbillf    0, 0, "Whether C development supports the C bindings option");
47686189SrwatsonSYSCTL_INT(_user, USER_POSIX2_C_DEV, posix2_c_dev, CTLFLAG_RD,
47746381Sbillf    0, 0, "Whether system supports the C development utilities option");
47886189SrwatsonSYSCTL_INT(_user, USER_POSIX2_CHAR_TERM, posix2_char_term, CTLFLAG_RD,
47946381Sbillf    0, 0, "");
48086189SrwatsonSYSCTL_INT(_user, USER_POSIX2_FORT_DEV, posix2_fort_dev, CTLFLAG_RD,
48146381Sbillf    0, 0, "Whether system supports FORTRAN development utilities");
48286189SrwatsonSYSCTL_INT(_user, USER_POSIX2_FORT_RUN, posix2_fort_run, CTLFLAG_RD,
48346381Sbillf    0, 0, "Whether system supports FORTRAN runtime utilities");
48486189SrwatsonSYSCTL_INT(_user, USER_POSIX2_LOCALEDEF, posix2_localedef, CTLFLAG_RD,
48546381Sbillf    0, 0, "Whether system supports creation of locales");
48686189SrwatsonSYSCTL_INT(_user, USER_POSIX2_SW_DEV, posix2_sw_dev, CTLFLAG_RD,
48746381Sbillf    0, 0, "Whether system supports software development utilities");
48886189SrwatsonSYSCTL_INT(_user, USER_POSIX2_UPE, posix2_upe, CTLFLAG_RD,
48946381Sbillf    0, 0, "Whether system supports the user portability utilities");
49086189SrwatsonSYSCTL_INT(_user, USER_STREAM_MAX, stream_max, CTLFLAG_RD,
49146381Sbillf    0, 0, "Min Maximum number of streams a process may have open at one time");
49286189SrwatsonSYSCTL_INT(_user, USER_TZNAME_MAX, tzname_max, CTLFLAG_RD,
49346381Sbillf    0, 0, "Min Maximum number of types supported for timezone names");
49448891Sphk
49548891Sphk#include <sys/vnode.h>
49686189SrwatsonSYSCTL_INT(_debug_sizeof, OID_AUTO, vnode, CTLFLAG_RD,
49748891Sphk    0, sizeof(struct vnode), "sizeof(struct vnode)");
49848891Sphk
49986189SrwatsonSYSCTL_INT(_debug_sizeof, OID_AUTO, proc, CTLFLAG_RD,
50048891Sphk    0, sizeof(struct proc), "sizeof(struct proc)");
50148927Sphk
50260041Sphk#include <sys/bio.h>
50358926Sphk#include <sys/buf.h>
50458926SphkSYSCTL_INT(_debug_sizeof, OID_AUTO, bio, CTLFLAG_RD,
50558926Sphk    0, sizeof(struct bio), "sizeof(struct bio)");
50658926SphkSYSCTL_INT(_debug_sizeof, OID_AUTO, buf, CTLFLAG_RD,
50758926Sphk    0, sizeof(struct buf), "sizeof(struct buf)");
50872376Sjake
50972376Sjake#include <sys/user.h>
51072376SjakeSYSCTL_INT(_debug_sizeof, OID_AUTO, kinfo_proc, CTLFLAG_RD,
51172376Sjake    0, sizeof(struct kinfo_proc), "sizeof(struct kinfo_proc)");
512108685Sjake
513108696Sjake/* XXX compatibility, remove for 6.0 */
514108696Sjake#include <sys/imgact.h>
515108696Sjake#include <sys/imgact_elf.h>
516108696SjakeSYSCTL_INT(_kern, OID_AUTO, fallback_elf_brand, CTLFLAG_RW,
517108696Sjake    &__elfN(fallback_brand), sizeof(__elfN(fallback_brand)),
518108696Sjake    "compatibility for kern.fallback_elf_brand");
519