1dba9e9ccSRobert Watson.\" 2dba9e9ccSRobert Watson.\" Copyright (c) 2006 Robert N. M. Watson 3dba9e9ccSRobert Watson.\" All rights reserved. 4dba9e9ccSRobert Watson.\" 5dba9e9ccSRobert Watson.\" Redistribution and use in source and binary forms, with or without 6dba9e9ccSRobert Watson.\" modification, are permitted provided that the following conditions 7dba9e9ccSRobert Watson.\" are met: 8dba9e9ccSRobert Watson.\" 1. Redistributions of source code must retain the above copyright 9dba9e9ccSRobert Watson.\" notice, this list of conditions and the following disclaimer. 10dba9e9ccSRobert Watson.\" 2. Redistributions in binary form must reproduce the above copyright 11dba9e9ccSRobert Watson.\" notice, this list of conditions and the following disclaimer in the 12dba9e9ccSRobert Watson.\" documentation and/or other materials provided with the distribution. 13dba9e9ccSRobert Watson.\" 14dba9e9ccSRobert Watson.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15dba9e9ccSRobert Watson.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16dba9e9ccSRobert Watson.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17dba9e9ccSRobert Watson.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18dba9e9ccSRobert Watson.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19dba9e9ccSRobert Watson.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20dba9e9ccSRobert Watson.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21dba9e9ccSRobert Watson.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22dba9e9ccSRobert Watson.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23dba9e9ccSRobert Watson.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24dba9e9ccSRobert Watson.\" SUCH DAMAGE. 25dba9e9ccSRobert Watson.\" 26dba9e9ccSRobert Watson.\" $FreeBSD$ 27dba9e9ccSRobert Watson.\" 28dba9e9ccSRobert Watson.Dd April 28, 2006 29dba9e9ccSRobert Watson.Dt SYSCTL 9 30dba9e9ccSRobert Watson.Os 31dba9e9ccSRobert Watson.Sh NAME 32dba9e9ccSRobert Watson.Nm SYSCTL_DECL , 33dba9e9ccSRobert Watson.Nm SYSCTL_INT , 34dba9e9ccSRobert Watson.Nm SYSCTL_LONG , 35dba9e9ccSRobert Watson.Nm SYSCTL_NODE , 36dba9e9ccSRobert Watson.Nm SYSCTL_OPAQUE , 37dba9e9ccSRobert Watson.Nm SYSCTL_PROC , 38dba9e9ccSRobert Watson.Nm SYSCTL_STRING , 39dba9e9ccSRobert Watson.Nm SYSCTL_STRUCT , 40dba9e9ccSRobert Watson.Nm SYSCTL_UINT , 41dba9e9ccSRobert Watson.Nm SYSCTL_ULONG 42dba9e9ccSRobert Watson.Nd Static sysctl declaration functions 43dba9e9ccSRobert Watson.Sh SYNOPSIS 44dba9e9ccSRobert Watson.In sys/types.h 45dba9e9ccSRobert Watson.In sys/sysctl.h 46dba9e9ccSRobert Watson.Fo SYSCTL_DECL 47dba9e9ccSRobert Watson.Fa "name" 48dba9e9ccSRobert Watson.Fc 49dba9e9ccSRobert Watson.Fo SYSCTL_INT 50dba9e9ccSRobert Watson.Fa "parent" 51dba9e9ccSRobert Watson.Fa "nbr" 52dba9e9ccSRobert Watson.Fa "name" 53dba9e9ccSRobert Watson.Fa "access" 54dba9e9ccSRobert Watson.Fa "ptr" 55dba9e9ccSRobert Watson.Fa "val" 56dba9e9ccSRobert Watson.Fa "descr" 57dba9e9ccSRobert Watson.Fc 58dba9e9ccSRobert Watson.Fo SYSCTL_LONG 59dba9e9ccSRobert Watson.Fa "parent" 60dba9e9ccSRobert Watson.Fa "nbr" 61dba9e9ccSRobert Watson.Fa "name" 62dba9e9ccSRobert Watson.Fa "access" 63dba9e9ccSRobert Watson.Fa "ptr" 64dba9e9ccSRobert Watson.Fa "val" 65dba9e9ccSRobert Watson.Fa "descr" 66dba9e9ccSRobert Watson.Fc 67dba9e9ccSRobert Watson.Fo SYSCTL_NODE 68dba9e9ccSRobert Watson.Fa "parent" 69dba9e9ccSRobert Watson.Fa "nbr" 70dba9e9ccSRobert Watson.Fa "name" 71dba9e9ccSRobert Watson.Fa "access" 72dba9e9ccSRobert Watson.Fa "handler" 73dba9e9ccSRobert Watson.Fa "descr" 74dba9e9ccSRobert Watson.Fc 75dba9e9ccSRobert Watson.Fo SYSCTL_OPAQUE 76dba9e9ccSRobert Watson.Fa "parent" 77dba9e9ccSRobert Watson.Fa "nbr" 78dba9e9ccSRobert Watson.Fa "name" 79dba9e9ccSRobert Watson.Fa "access" 80dba9e9ccSRobert Watson.Fa "ptr" 81dba9e9ccSRobert Watson.Fa "len" 82dba9e9ccSRobert Watson.Fa "fmt" 83dba9e9ccSRobert Watson.Fa "descr" 84dba9e9ccSRobert Watson.Fc 85dba9e9ccSRobert Watson.Fo SYSCTL_PROC 86dba9e9ccSRobert Watson.Fa "parent" 87dba9e9ccSRobert Watson.Fa "nbr" 88dba9e9ccSRobert Watson.Fa "name" 89dba9e9ccSRobert Watson.Fa "access" 90dba9e9ccSRobert Watson.Fa "ptr" 91dba9e9ccSRobert Watson.Fa "arg" 92dba9e9ccSRobert Watson.Fa "handler" 93dba9e9ccSRobert Watson.Fa "fmt" 94dba9e9ccSRobert Watson.Fa "descr" 95dba9e9ccSRobert Watson.Fc 96dba9e9ccSRobert Watson.Fo SYSCTL_STRING 97dba9e9ccSRobert Watson.Fa "parent" 98dba9e9ccSRobert Watson.Fa "nbr" 99dba9e9ccSRobert Watson.Fa "name" 100dba9e9ccSRobert Watson.Fa "access" 101dba9e9ccSRobert Watson.Fa "arg" 102dba9e9ccSRobert Watson.Fa "len" 103dba9e9ccSRobert Watson.Fa "descr" 104dba9e9ccSRobert Watson.Fc 105dba9e9ccSRobert Watson.Fo SYSCTL_STRUCT 106dba9e9ccSRobert Watson.Fa "parent" 107dba9e9ccSRobert Watson.Fa "nbr" 108dba9e9ccSRobert Watson.Fa "name" 109dba9e9ccSRobert Watson.Fa "access" 110dba9e9ccSRobert Watson.Fa "ptr" 111dba9e9ccSRobert Watson.Fa "type" 112dba9e9ccSRobert Watson.Fa "descr" 113dba9e9ccSRobert Watson.Fc 114dba9e9ccSRobert Watson.Fo SYSCTL_UINT 115dba9e9ccSRobert Watson.Fa "parent" 116dba9e9ccSRobert Watson.Fa "nbr" 117dba9e9ccSRobert Watson.Fa "name" 118dba9e9ccSRobert Watson.Fa "access" 119dba9e9ccSRobert Watson.Fa "ptr" 120dba9e9ccSRobert Watson.Fa "val" 121dba9e9ccSRobert Watson.Fa "descr" 122dba9e9ccSRobert Watson.Fc 123dba9e9ccSRobert Watson.Fo SYSCTL_ULONG 124dba9e9ccSRobert Watson.Fa "parent" 125dba9e9ccSRobert Watson.Fa "nbr" 126dba9e9ccSRobert Watson.Fa "name" 127dba9e9ccSRobert Watson.Fa "access" 128dba9e9ccSRobert Watson.Fa "ptr" 129dba9e9ccSRobert Watson.Fa "val" 130dba9e9ccSRobert Watson.Fa "descr" 131dba9e9ccSRobert Watson.Fc 132dba9e9ccSRobert Watson.Sh DESCRIPTION 133dba9e9ccSRobert WatsonThe 134dba9e9ccSRobert Watson.Nm 135dba9e9ccSRobert Watsonkernel interfaces allow code to statically declare 136dba9e9ccSRobert Watson.Xr sysctl 8 137dba9e9ccSRobert WatsonMIB entries, which will be initialized when the kernel module containing the 138dba9e9ccSRobert Watsondeclaration is initialized. 139dba9e9ccSRobert WatsonWhen the module is unloaded, the sysctl will be automatically destroyed. 140dba9e9ccSRobert Watson.Pp 141dba9e9ccSRobert WatsonSysctl nodes are created in a hierarchal tree, with all static nodes being 142dba9e9ccSRobert Watsonrepresented by named C data structures; in order to create a new node under 143dba9e9ccSRobert Watsonan existing node in the tree, the structure representing the desired parent 144dba9e9ccSRobert Watsonnode must be declared in the current context using 145dba9e9ccSRobert Watson.Fn SYSCTL_DECL . 146dba9e9ccSRobert Watson.Pp 147dba9e9ccSRobert WatsonNew nodes are declared using one of 148dba9e9ccSRobert Watson.Nm SYSCTL_INT , 149dba9e9ccSRobert Watson.Nm SYSCTL_LONG , 150dba9e9ccSRobert Watson.Nm SYSCTL_NODE , 151dba9e9ccSRobert Watson.Nm SYSCTL_OPAQUE , 152dba9e9ccSRobert Watson.Nm SYSCTL_PROC , 153dba9e9ccSRobert Watson.Nm SYSCTL_STRING , 154dba9e9ccSRobert Watson.Nm SYSCTL_STRUCT , 155dba9e9ccSRobert Watson.Nm SYSCTL_UINT , 156dba9e9ccSRobert Watsonand 157dba9e9ccSRobert Watson.Nm SYSCTL_ULONG . 158dba9e9ccSRobert WatsonEach macro accepts a parent name, as declared using 159dba9e9ccSRobert Watson.Nm SYSCTL_DECL , 160dba9e9ccSRobert Watsonan OID number, typically 161dba9e9ccSRobert Watson.Dv OID_AUTO , 162dba9e9ccSRobert Watsona node name, a set of control and access flags, and a description. 163dba9e9ccSRobert WatsonDepending on the macro, a pointer to a variable supporting the MIB entry, a 164dba9e9ccSRobert Watsonsize, a value, and a function pointer implementing the MIB entry may also be 165dba9e9ccSRobert Watsonpresent. 166dba9e9ccSRobert Watson.Pp 167dba9e9ccSRobert WatsonFor most of the above macros, declaring a type as part of the access flags is 168dba9e9ccSRobert Watsonnot necessary -- however, when declaring a sysctl implemented by a function, 169dba9e9ccSRobert Watsonincluding a type in the access mask is required: 170dba9e9ccSRobert Watson.Bl -tag -width CTLTYPE_STRING 171dba9e9ccSRobert Watson.It Dv CTLTYPE_NODE 172dba9e9ccSRobert WatsonThis is a node intended to be a parent for other nodes. 173dba9e9ccSRobert Watson.It Dv CTLTYPE_INT 174dba9e9ccSRobert WatsonThis is a signed integer. 175dba9e9ccSRobert Watson.It Dv CTLTYPE_STRING 176dba9e9ccSRobert WatsonThis is a nul-terminated string stored in a character array. 177dba9e9ccSRobert Watson.It Dv CTLTYPE_QUAD 178dba9e9ccSRobert WatsonThis is a 64-bit signed integer. 179dba9e9ccSRobert Watson.It Dv CTLTYPE_OPAQUE 180dba9e9ccSRobert WatsonThis is an opaque data structure. 181dba9e9ccSRobert Watson.It Dv CTLTYPE_STRUCT 182dba9e9ccSRobert WatsonAlias for 183dba9e9ccSRobert Watson.Dv CTLTYPE_OPAQUE. 184dba9e9ccSRobert Watson.It Dv CTLTYPE_UINT 185dba9e9ccSRobert WatsonThis is an unsigned integer. 186dba9e9ccSRobert Watson.It Dv CTLTYPE_LONG 187dba9e9ccSRobert WatsonThis is a signed long. 188dba9e9ccSRobert Watson.It Dv CTLTYPE_ULONG 189dba9e9ccSRobert WatsonThis is an insigned long. 190dba9e9ccSRobert Watson.El 191dba9e9ccSRobert Watson.Pp 192dba9e9ccSRobert WatsonAll sysctl types except for new node declarations require one or more flags 193dba9e9ccSRobert Watsonto be set indicating the read and write disposition of the sysctl: 194dba9e9ccSRobert Watson.Bl -tag -width CTLFLAG_ANYBODY 195dba9e9ccSRobert Watson.It Dv CTLFLAG_RD 196dba9e9ccSRobert WatsonThis is a read-only sysctl. 197dba9e9ccSRobert WatsonIt Dv CTLFLAG_WR 198dba9e9ccSRobert WatsonThis is a writable sysctl. 199dba9e9ccSRobert Watson.It Dv CTLFLAG_RW 200dba9e9ccSRobert WatsonThis sysctl is readable and writable. 201dba9e9ccSRobert Watson.It Dv CTLFLAG_ANYBODY 202dba9e9ccSRobert WatsonAny user or process can write to this sysctl. 203dba9e9ccSRobert Watson.It Dv CTLFLAG_SECURE 204dba9e9ccSRobert WatsonThis sysctl can be written to only if the effective securelevel of the 205dba9e9ccSRobert Watsonprocess is <= 0. 206dba9e9ccSRobert Watson.It Dv CTLFLAG_PRISON 207dba9e9ccSRobert WatsonThis sysctl can be written to by processes in 208dba9e9ccSRobert Watson.Xr jail 2 . 209dba9e9ccSRobert Watson.It Dv CTLFLAG_SKIP 210dba9e9ccSRobert WatsonWhen iterating the sysctl name space, do not list this sysctl. 211dba9e9ccSRobert Watson.It Dv CTLFLAG_TUN 212dba9e9ccSRobert WatsonAlso declare a system tunable with the same name to initialize this variable. 213dba9e9ccSRobert Watson.It Dv CTLFLAG_RDTUN 214dba9e9ccSRobert WatsonAlso declare a system tunable with the same name to initalize this variable; 215dba9e9ccSRobert Watsonhowever, the run-time variable is read-only. 216dba9e9ccSRobert Watson.El 217dba9e9ccSRobert Watson.Pp 218dba9e9ccSRobert WatsonWhen creating new sysctls, careful attention should be paid to the security 219dba9e9ccSRobert Watsonimplications of the monitoring or management interface being created. 220dba9e9ccSRobert WatsonMost sysctls present in the kernel are read-only or writable only by the 221dba9e9ccSRobert Watsonsuperuser. 222dba9e9ccSRobert WatsonSysctls exporting extensive information on system data structures and 223dba9e9ccSRobert Watsonoperation, especially those implemented using procedures, will wish to 224dba9e9ccSRobert Watsonimplement access control to limit the undesired exposure of information about 225dba9e9ccSRobert Watsonother processes, network connections, etc. 226dba9e9ccSRobert Watson.Pp 227dba9e9ccSRobert WatsonThe following top level sysctl name spaces are commonly used: 228dba9e9ccSRobert Watson.Bl -tag -width regression 229dba9e9ccSRobert Watson.It Dv compat 230dba9e9ccSRobert WatsonCompatibility layer information. 231dba9e9ccSRobert Watson.It Dv debug 232dba9e9ccSRobert WatsonDebugging information. 233dba9e9ccSRobert WatsonVarious name spaces exist under 234dba9e9ccSRobert Watson.Dv debug . 235dba9e9ccSRobert Watson.It Dv hw 236dba9e9ccSRobert WatsonHardware and device driver information. 237dba9e9ccSRobert Watson.It Dv kern 238dba9e9ccSRobert WatsonKernel behavior tuning; generally deprecated in favor of more specific 239dba9e9ccSRobert Watsonname spaces. 240dba9e9ccSRobert Watson.It Dv machdep 241dba9e9ccSRobert WatsonMachine-dependent configuration parameters. 242dba9e9ccSRobert Watson.It Dv net 243dba9e9ccSRobert WatsonNetwork subsystem. 244dba9e9ccSRobert WatsonVarious protocols have name spaces under 245dba9e9ccSRobert Watson.Dv net . 246dba9e9ccSRobert Watson.It Dv regression 247dba9e9ccSRobert WatsonRegression test configuration and information. 248dba9e9ccSRobert Watson.It Dv security 249dba9e9ccSRobert WatsonSecurity and security policy configuration and information. 250dba9e9ccSRobert Watson.It Dv sysctl 251dba9e9ccSRobert WatsonReserved name space for the implementation of sysctl. 252dba9e9ccSRobert Watson.It Dv user 253dba9e9ccSRobert WatsonConfiguration settings relating to user application behavior. 254dba9e9ccSRobert WatsonGenerally, configuring applications using kernel sysctls is disouraged. 255dba9e9ccSRobert Watson.It Dv vfs 256dba9e9ccSRobert WatsonVirtual file system configuration and information. 257dba9e9ccSRobert Watson.It Dv vm 258dba9e9ccSRobert WatsonVirtual memory subsystem configuration and information. 259dba9e9ccSRobert Watson.El 260dba9e9ccSRobert Watson.Sh EXAMPLES 261dba9e9ccSRobert WatsonSample use of 262dba9e9ccSRobert Watson.Nm SYSCTL_DECL 263dba9e9ccSRobert Watsonto declare the "security" sysctl tree for use by new nodes: 264dba9e9ccSRobert Watson.Bd -literal -offset indent 265dba9e9ccSRobert WatsonSYSCTL_DECL(_security); 266dba9e9ccSRobert Watson.Ed 267dba9e9ccSRobert Watson.Pp 268dba9e9ccSRobert WatsonExamples of integer, opaque, string, and procedure sysctls follow: 269dba9e9ccSRobert Watson.Bd -literal -offset indent 270dba9e9ccSRobert Watson/* 271dba9e9ccSRobert Watson * Example of a constant integer value. Notice that the control 272dba9e9ccSRobert Watson * flags are CTLFLAG_RD, the variable pointer is NULL, and the 273dba9e9ccSRobert Watson * value is declared. 274dba9e9ccSRobert Watson */ 275dba9e9ccSRobert WatsonSYSCTL_INT(_debug_sizeof, OID_AUTO, bio, CTLFLAG_RD, NULL, 276dba9e9ccSRobert Watson sizeof(struct bio), "sizeof(struct bio)"); 277dba9e9ccSRobert Watson 278dba9e9ccSRobert Watson/* 279dba9e9ccSRobert Watson * Example of a variable integer value. Notice that the control 280dba9e9ccSRobert Watson * flags are CTLFLAG_RW, the variable pointer is set, and the 281dba9e9ccSRobert Watson * value is 0. 282dba9e9ccSRobert Watson */ 283dba9e9ccSRobert Watsonstatic int doingcache = 1; /* 1 => enable the cache */ 284dba9e9ccSRobert WatsonSYSCTL_INT(_debug, OID_AUTO, vfscache, CTLFLAG_RW, &doingcache, 0, 285dba9e9ccSRobert Watson "Enable name cache"); 286dba9e9ccSRobert Watson 287dba9e9ccSRobert Watson/* 288dba9e9ccSRobert Watson * Example of a variable string value. Notice that the control 289dba9e9ccSRobert Watson * flags are CTLFLAG_RW, that the variable pointer and string 290dba9e9ccSRobert Watson * size are set. Unlike newer sysctls, this older sysctl uses a 291dba9e9ccSRobert Watson * static oid number. 292dba9e9ccSRobert Watson */ 293dba9e9ccSRobert Watsonchar kernelname[MAXPATHLEN] = "/kernel"; /* XXX bloat */ 294dba9e9ccSRobert WatsonSYSCTL_STRING(_kern, KERN_BOOTFILE, bootfile, CTLFLAG_RW, 295dba9e9ccSRobert Watson kernelname, sizeof(kernelname), "Name of kernel file booted"); 296dba9e9ccSRobert Watson 297dba9e9ccSRobert Watson/* 298dba9e9ccSRobert Watson * Example of an opaque data type exported by sysctl. Notice that 299dba9e9ccSRobert Watson * the variable pointer and size are provided, as well as a format 300dba9e9ccSRobert Watson * string for sysctl(8). 301dba9e9ccSRobert Watson */ 302dba9e9ccSRobert Watsonstatic l_fp pps_freq; /* scaled frequence offset (ns/s) */ 303dba9e9ccSRobert WatsonSYSCTL_OPAQUE(_kern_ntp_pll, OID_AUTO, pps_freq, CTLFLAG_RD, 304dba9e9ccSRobert Watson &pps_freq, sizeof(pps_freq), "I", ""); 305dba9e9ccSRobert Watson 306dba9e9ccSRobert Watson/* 307dba9e9ccSRobert Watson * Example of a procedure based sysctl exporting string 308dba9e9ccSRobert Watson * information. Notice that the data type is declared, the NULL 309dba9e9ccSRobert Watson * variable pointer and 0 size, the function pointer, and the 310dba9e9ccSRobert Watson * format string for sysctl(8). 311dba9e9ccSRobert Watson */ 312dba9e9ccSRobert WatsonSYSCTL_PROC(_kern_timecounter, OID_AUTO, hardware, CTLTYPE_STRING | 313dba9e9ccSRobert Watson CTLFLAG_RW, NULL, 0, sysctl_kern_timecounter_hardware, "A", 314dba9e9ccSRobert Watson ""); 315dba9e9ccSRobert Watson.Ed 316dba9e9ccSRobert Watson.Pp 317dba9e9ccSRobert WatsonWhen adding, modifying, or removing sysctl names, it is important to be 318dba9e9ccSRobert Watsonaware that these interfaces may be used by users, libraries, applications, 319dba9e9ccSRobert Watsonand even books, and are implicitly published application interfaces. 320dba9e9ccSRobert WatsonAs with other application interfaces, caution must be taken not to break 321dba9e9ccSRobert Watsonexisting applications, and to think about future use of new name spaces so as 322dba9e9ccSRobert Watsonto avoid the need to rename or remove interfaces that might be depended on in 323dba9e9ccSRobert Watsonthe future. 324dba9e9ccSRobert Watson.Sh SEE ALSO 325dba9e9ccSRobert Watson.Xr sysctl 8 , 326dba9e9ccSRobert Watson.Xr sysctl_add_oid 9 , 327dba9e9ccSRobert Watson.Xr sysctl_ctx_free 9 , 328dba9e9ccSRobert Watson.Xr sysctl_ctx_init 9 , 329dba9e9ccSRobert Watson.Xr sysctl_remove_oid 9 330dba9e9ccSRobert Watson.Sh HISTORY 331dba9e9ccSRobert Watson.Xr sysctl 8 332dba9e9ccSRobert Watsonfirst appeared in 333dba9e9ccSRobert Watson.Bx 4.4 . 334dba9e9ccSRobert Watson.Sh AUTHORS 335dba9e9ccSRobert WatsonThe sysctl implementation originally found in 336dba9e9ccSRobert Watson.Bx 337dba9e9ccSRobert Watsonhas been extensively rewritten by 338dba9e9ccSRobert Watson.An Poul-Henning Kamp 339dba9e9ccSRobert Watsonin order to add support for name lookups, name space iteration, and dynamic 340dba9e9ccSRobert Watsonaddition of MIB nodes. 341dba9e9ccSRobert Watson.Pp 342dba9e9ccSRobert WatsonThis man page was written by 343dba9e9ccSRobert Watson.An Robert N. M. Watson . 344