kern_mib.c revision 84611
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 84611 2001-10-07 03:51:22Z rwatson $ 4115103Sphk */ 4215103Sphk 4384611Srwatson#include "opt_global.h" 4484611Srwatson 4515103Sphk#include <sys/param.h> 4615103Sphk#include <sys/kernel.h> 4715103Sphk#include <sys/systm.h> 4815103Sphk#include <sys/sysctl.h> 4915103Sphk#include <sys/proc.h> 5046155Sphk#include <sys/jail.h> 5176078Sjhb#include <sys/smp.h> 5228918Skato 5315103SphkSYSCTL_NODE(, 0, sysctl, CTLFLAG_RW, 0, 5415103Sphk "Sysctl internal magic"); 5515103SphkSYSCTL_NODE(, CTL_KERN, kern, CTLFLAG_RW, 0, 5615103Sphk "High kernel, proc, limits &c"); 5715103SphkSYSCTL_NODE(, CTL_VM, vm, CTLFLAG_RW, 0, 5815103Sphk "Virtual memory"); 5923382SbdeSYSCTL_NODE(, CTL_VFS, vfs, CTLFLAG_RW, 0, 6015103Sphk "File system"); 6115103SphkSYSCTL_NODE(, CTL_NET, net, CTLFLAG_RW, 0, 6215103Sphk "Network, (see socket.h)"); 6315103SphkSYSCTL_NODE(, CTL_DEBUG, debug, CTLFLAG_RW, 0, 6415103Sphk "Debugging"); 6548891SphkSYSCTL_NODE(_debug, OID_AUTO, sizeof, CTLFLAG_RW, 0, 6648891Sphk "Sizeof various things"); 6715103SphkSYSCTL_NODE(, CTL_HW, hw, CTLFLAG_RW, 0, 6815103Sphk "hardware"); 6915103SphkSYSCTL_NODE(, CTL_MACHDEP, machdep, CTLFLAG_RW, 0, 7015103Sphk "machine dependent"); 7115103SphkSYSCTL_NODE(, CTL_USER, user, CTLFLAG_RW, 0, 7215103Sphk "user-level"); 7334925SdufaultSYSCTL_NODE(, CTL_P1003_1B, p1003_1b, CTLFLAG_RW, 0, 7434925Sdufault "p1003_1b, (see p1003_1b.h)"); 7534029Sdufault 7650465SmarcelSYSCTL_NODE(, OID_AUTO, compat, CTLFLAG_RW, 0, 7750465Smarcel "Compatibility code"); 7850465Smarcel 7946381SbillfSYSCTL_STRING(_kern, KERN_OSRELEASE, osrelease, CTLFLAG_RD, 8046381Sbillf osrelease, 0, "Operating system type"); 8115103Sphk 8246381SbillfSYSCTL_INT(_kern, KERN_OSREV, osrevision, CTLFLAG_RD, 8346381Sbillf 0, BSD, "Operating system revision"); 8415103Sphk 8546381SbillfSYSCTL_STRING(_kern, KERN_VERSION, version, CTLFLAG_RD, 8646381Sbillf version, 0, "Kernel version"); 8715103Sphk 8846381SbillfSYSCTL_STRING(_kern, KERN_OSTYPE, ostype, CTLFLAG_RD, 8946381Sbillf ostype, 0, "Operating system type"); 9015103Sphk 9115103Sphkextern int osreldate; 9246381SbillfSYSCTL_INT(_kern, KERN_OSRELDATE, osreldate, CTLFLAG_RD, 9346381Sbillf &osreldate, 0, "Operating system release date"); 9415103Sphk 9546381SbillfSYSCTL_INT(_kern, KERN_MAXPROC, maxproc, CTLFLAG_RD, 9646381Sbillf &maxproc, 0, "Maximum number of processes"); 9715103Sphk 9846381SbillfSYSCTL_INT(_kern, KERN_MAXPROCPERUID, maxprocperuid, CTLFLAG_RW, 9946381Sbillf &maxprocperuid, 0, "Maximum processes allowed per userid"); 10015103Sphk 10180447SpeterSYSCTL_INT(_kern, OID_AUTO, maxusers, CTLFLAG_RD, 10280418Speter &maxusers, 0, "Hint for kernel tuning"); 10380418Speter 10446381SbillfSYSCTL_INT(_kern, KERN_ARGMAX, argmax, CTLFLAG_RD, 10546381Sbillf 0, ARG_MAX, "Maximum bytes of argument to execve(2)"); 10615103Sphk 10746381SbillfSYSCTL_INT(_kern, KERN_POSIX1, posix1version, CTLFLAG_RD, 10846381Sbillf 0, _KPOSIX_VERSION, "Version of POSIX attempting to comply to"); 10915103Sphk 11046381SbillfSYSCTL_INT(_kern, KERN_NGROUPS, ngroups, CTLFLAG_RD, 11146381Sbillf 0, NGROUPS_MAX, "Maximum number of groups a user can belong to"); 11215103Sphk 11346381SbillfSYSCTL_INT(_kern, KERN_JOB_CONTROL, job_control, CTLFLAG_RD, 11446381Sbillf 0, 1, "Whether job control is available"); 11515103Sphk 11615103Sphk#ifdef _POSIX_SAVED_IDS 11746381SbillfSYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD, 11846381Sbillf 0, 1, "Whether saved set-group/user ID is available"); 11915103Sphk#else 12046381SbillfSYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD, 12146381Sbillf 0, 0, "Whether saved set-group/user ID is available"); 12215103Sphk#endif 12315103Sphk 12415103Sphkchar kernelname[MAXPATHLEN] = "/kernel"; /* XXX bloat */ 12515103Sphk 12646381SbillfSYSCTL_STRING(_kern, KERN_BOOTFILE, bootfile, CTLFLAG_RW, 12746381Sbillf kernelname, sizeof kernelname, "Name of kernel file booted"); 12815103Sphk 12931990Sgpalmer#ifdef SMP 13046381SbillfSYSCTL_INT(_hw, HW_NCPU, ncpu, CTLFLAG_RD, 13146381Sbillf &mp_ncpus, 0, "Number of active CPUs"); 13231990Sgpalmer#else 13346381SbillfSYSCTL_INT(_hw, HW_NCPU, ncpu, CTLFLAG_RD, 13446381Sbillf 0, 1, "Number of active CPUs"); 13531990Sgpalmer#endif 13615103Sphk 13746381SbillfSYSCTL_INT(_hw, HW_BYTEORDER, byteorder, CTLFLAG_RD, 13846381Sbillf 0, BYTE_ORDER, "System byte order"); 13915103Sphk 14046381SbillfSYSCTL_INT(_hw, HW_PAGESIZE, pagesize, CTLFLAG_RD, 14146381Sbillf 0, PAGE_SIZE, "System memory page size"); 14215103Sphk 14328885Skatostatic char machine_arch[] = MACHINE_ARCH; 14428885SkatoSYSCTL_STRING(_hw, HW_MACHINE_ARCH, machine_arch, CTLFLAG_RD, 14546381Sbillf machine_arch, 0, "System architecture"); 14628885Skato 14784611Srwatson#ifdef REGRESSION 14884611SrwatsonSYSCTL_NODE(, OID_AUTO, regression, CTLFLAG_RW, 0, "Regression test MIB"); 14984611Srwatson#endif /* !REGRESSION */ 15084611Srwatson 15115103Sphkchar hostname[MAXHOSTNAMELEN]; 15215103Sphk 15346155Sphkstatic int 15462573Sphksysctl_hostname(SYSCTL_HANDLER_ARGS) 15546155Sphk{ 15646155Sphk int error; 15715103Sphk 15872786Srwatson if (jailed(req->p->p_ucred)) { 15957163Srwatson if (!jail_set_hostname_allowed && req->newptr) 16057111Srwatson return(EPERM); 16146155Sphk error = sysctl_handle_string(oidp, 16272786Srwatson req->p->p_ucred->cr_prison->pr_host, 16372786Srwatson sizeof req->p->p_ucred->cr_prison->pr_host, req); 16457111Srwatson } else 16546155Sphk error = sysctl_handle_string(oidp, 16646155Sphk hostname, sizeof hostname, req); 16746155Sphk return (error); 16846155Sphk} 16946155Sphk 17046155SphkSYSCTL_PROC(_kern, KERN_HOSTNAME, hostname, 17146155Sphk CTLTYPE_STRING|CTLFLAG_RW|CTLFLAG_PRISON, 17246381Sbillf 0, 0, sysctl_hostname, "A", "Hostname"); 17346155Sphk 17484611Srwatson#ifdef REGRESSION 17584611Srwatsonint regression_securelevel_nonmonotonic=0; 17684611Srwatson 17784611SrwatsonSYSCTL_INT(_regression, OID_AUTO, securelevel_nonmonotonic, CTLFLAG_RW, 17884611Srwatson ®ression_securelevel_nonmonotonic, 0, "securelevel may be lowered"); 17984611Srwatson#endif /* !REGRESSION */ 18084611Srwatson 18115103Sphkint securelevel = -1; 18215103Sphk 18315103Sphkstatic int 18462573Sphksysctl_kern_securelvl(SYSCTL_HANDLER_ARGS) 18515103Sphk{ 18615103Sphk int error, level; 18715103Sphk 18883990Srwatson /* 18983990Srwatson * If the process is in jail, return the maximum of the 19083990Srwatson * global and local levels; otherwise, return the global 19183990Srwatson * level. 19283990Srwatson */ 19383990Srwatson if (req->p->p_ucred->cr_prison != NULL) 19483990Srwatson level = imax(securelevel, 19583990Srwatson req->p->p_ucred->cr_prison->pr_securelevel); 19683990Srwatson else 19783990Srwatson level = securelevel; 19815103Sphk error = sysctl_handle_int(oidp, &level, 0, req); 19915103Sphk if (error || !req->newptr) 20015103Sphk return (error); 20183990Srwatson /* 20283990Srwatson * Permit update only if the new securelevel exceeds the 20383990Srwatson * global level, and local level if any. 20483990Srwatson */ 20583990Srwatson if (req->p->p_ucred->cr_prison != NULL) { 20684611Srwatson#ifdef REGRESSION 20784611Srwatson if (!regression_securelevel_nonmonotonic) 20884611Srwatson#endif /* !REGRESSION */ 20983990Srwatson if (level < imax(securelevel, 21083990Srwatson req->p->p_ucred->cr_prison->pr_securelevel)) 21183990Srwatson return (EPERM); 21283990Srwatson req->p->p_ucred->cr_prison->pr_securelevel = level; 21383990Srwatson } else { 21484611Srwatson#ifdef REGRESSION 21584611Srwatson if (!regression_securelevel_nonmonotonic) 21684611Srwatson#endif /* !REGRESSION */ 21783990Srwatson if (level < securelevel) 21883990Srwatson return (EPERM); 21983990Srwatson securelevel = level; 22083990Srwatson } 22115103Sphk return (error); 22215103Sphk} 22315103Sphk 22483990SrwatsonSYSCTL_PROC(_kern, KERN_SECURELVL, securelevel, 22583990Srwatson CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_PRISON, 0, 0, sysctl_kern_securelvl, 22683990Srwatson "I", "Current secure level"); 22761370Srwatson 22815103Sphkchar domainname[MAXHOSTNAMELEN]; 22917281SwollmanSYSCTL_STRING(_kern, KERN_NISDOMAINNAME, domainname, CTLFLAG_RW, 23046381Sbillf &domainname, sizeof(domainname), "Name of the current YP/NIS domain"); 23115103Sphk 23278609Spirzykunsigned long hostid; 23378609SpirzykSYSCTL_ULONG(_kern, KERN_HOSTID, hostid, CTLFLAG_RW, &hostid, 0, "Host ID"); 23415103Sphk 23515103Sphk/* 23615103Sphk * This is really cheating. These actually live in the libc, something 23715103Sphk * which I'm not quite sure is a good idea anyway, but in order for 23815103Sphk * getnext and friends to actually work, we define dummies here. 23915103Sphk */ 24046381SbillfSYSCTL_STRING(_user, USER_CS_PATH, cs_path, CTLFLAG_RD, 24146381Sbillf "", 0, "PATH that finds all the standard utilities"); 24246381SbillfSYSCTL_INT(_user, USER_BC_BASE_MAX, bc_base_max, CTLFLAG_RD, 24346381Sbillf 0, 0, "Max ibase/obase values in bc(1)"); 24446381SbillfSYSCTL_INT(_user, USER_BC_DIM_MAX, bc_dim_max, CTLFLAG_RD, 24546381Sbillf 0, 0, "Max array size in bc(1)"); 24646381SbillfSYSCTL_INT(_user, USER_BC_SCALE_MAX, bc_scale_max, CTLFLAG_RD, 24746381Sbillf 0, 0, "Max scale value in bc(1)"); 24846381SbillfSYSCTL_INT(_user, USER_BC_STRING_MAX, bc_string_max, CTLFLAG_RD, 24946381Sbillf 0, 0, "Max string length in bc(1)"); 25046381SbillfSYSCTL_INT(_user, USER_COLL_WEIGHTS_MAX, coll_weights_max, CTLFLAG_RD, 25146381Sbillf 0, 0, "Maximum number of weights assigned to an LC_COLLATE locale entry"); 25218540SbdeSYSCTL_INT(_user, USER_EXPR_NEST_MAX, expr_nest_max, CTLFLAG_RD, 0, 0, ""); 25346381SbillfSYSCTL_INT(_user, USER_LINE_MAX, line_max, CTLFLAG_RD, 25446381Sbillf 0, 0, "Max length (bytes) of a text-processing utility's input line"); 25546381SbillfSYSCTL_INT(_user, USER_RE_DUP_MAX, re_dup_max, CTLFLAG_RD, 25646381Sbillf 0, 0, "Maximum number of repeats of a regexp permitted"); 25746381SbillfSYSCTL_INT(_user, USER_POSIX2_VERSION, posix2_version, CTLFLAG_RD, 25846381Sbillf 0, 0, 25946381Sbillf "The version of POSIX 1003.2 with which the system attempts to comply"); 26046381SbillfSYSCTL_INT(_user, USER_POSIX2_C_BIND, posix2_c_bind, CTLFLAG_RD, 26146381Sbillf 0, 0, "Whether C development supports the C bindings option"); 26246381SbillfSYSCTL_INT(_user, USER_POSIX2_C_DEV, posix2_c_dev, CTLFLAG_RD, 26346381Sbillf 0, 0, "Whether system supports the C development utilities option"); 26446381SbillfSYSCTL_INT(_user, USER_POSIX2_CHAR_TERM, posix2_char_term, CTLFLAG_RD, 26546381Sbillf 0, 0, ""); 26646381SbillfSYSCTL_INT(_user, USER_POSIX2_FORT_DEV, posix2_fort_dev, CTLFLAG_RD, 26746381Sbillf 0, 0, "Whether system supports FORTRAN development utilities"); 26846381SbillfSYSCTL_INT(_user, USER_POSIX2_FORT_RUN, posix2_fort_run, CTLFLAG_RD, 26946381Sbillf 0, 0, "Whether system supports FORTRAN runtime utilities"); 27046381SbillfSYSCTL_INT(_user, USER_POSIX2_LOCALEDEF, posix2_localedef, CTLFLAG_RD, 27146381Sbillf 0, 0, "Whether system supports creation of locales"); 27246381SbillfSYSCTL_INT(_user, USER_POSIX2_SW_DEV, posix2_sw_dev, CTLFLAG_RD, 27346381Sbillf 0, 0, "Whether system supports software development utilities"); 27446381SbillfSYSCTL_INT(_user, USER_POSIX2_UPE, posix2_upe, CTLFLAG_RD, 27546381Sbillf 0, 0, "Whether system supports the user portability utilities"); 27646381SbillfSYSCTL_INT(_user, USER_STREAM_MAX, stream_max, CTLFLAG_RD, 27746381Sbillf 0, 0, "Min Maximum number of streams a process may have open at one time"); 27846381SbillfSYSCTL_INT(_user, USER_TZNAME_MAX, tzname_max, CTLFLAG_RD, 27946381Sbillf 0, 0, "Min Maximum number of types supported for timezone names"); 28048891Sphk 28148891Sphk#include <sys/vnode.h> 28248891SphkSYSCTL_INT(_debug_sizeof, OID_AUTO, vnode, CTLFLAG_RD, 28348891Sphk 0, sizeof(struct vnode), "sizeof(struct vnode)"); 28448891Sphk 28548891SphkSYSCTL_INT(_debug_sizeof, OID_AUTO, proc, CTLFLAG_RD, 28648891Sphk 0, sizeof(struct proc), "sizeof(struct proc)"); 28748927Sphk 28849535Sphk#include <sys/conf.h> 28948927SphkSYSCTL_INT(_debug_sizeof, OID_AUTO, specinfo, CTLFLAG_RD, 29048927Sphk 0, sizeof(struct specinfo), "sizeof(struct specinfo)"); 29158926Sphk 29260041Sphk#include <sys/bio.h> 29358926Sphk#include <sys/buf.h> 29458926SphkSYSCTL_INT(_debug_sizeof, OID_AUTO, bio, CTLFLAG_RD, 29558926Sphk 0, sizeof(struct bio), "sizeof(struct bio)"); 29658926SphkSYSCTL_INT(_debug_sizeof, OID_AUTO, buf, CTLFLAG_RD, 29758926Sphk 0, sizeof(struct buf), "sizeof(struct buf)"); 29872376Sjake 29972376Sjake#include <sys/user.h> 30072376SjakeSYSCTL_INT(_debug_sizeof, OID_AUTO, kinfo_proc, CTLFLAG_RD, 30172376Sjake 0, sizeof(struct kinfo_proc), "sizeof(struct kinfo_proc)"); 302