xref: /freebsd/share/man/man9/sysctl.9 (revision 56538e4af90b091ec84a2fcfb690b93987409bc7)
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.\"
28*56538e4aSGleb Smirnoff.Dd September 15, 2014
29dba9e9ccSRobert Watson.Dt SYSCTL 9
30dba9e9ccSRobert Watson.Os
31dba9e9ccSRobert Watson.Sh NAME
32dba9e9ccSRobert Watson.Nm SYSCTL_DECL ,
335eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_INT ,
345eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_LONG ,
355eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_NODE ,
365eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_OPAQUE ,
375eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_PROC ,
385eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_QUAD ,
395eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_ROOT_NODE ,
405eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_STRING ,
415eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_STRUCT ,
425eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_UINT ,
435eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_ULONG ,
445eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_UQUAD ,
455eb1caa8SHans Petter Selasky.Nm SYSCTL_CHILDREN ,
465eb1caa8SHans Petter Selasky.Nm SYSCTL_STATIC_CHILDREN ,
475eb1caa8SHans Petter Selasky.Nm SYSCTL_NODE_CHILDREN ,
485eb1caa8SHans Petter Selasky.Nm SYSCTL_PARENT ,
49dba9e9ccSRobert Watson.Nm SYSCTL_INT ,
50dba9e9ccSRobert Watson.Nm SYSCTL_LONG ,
51dba9e9ccSRobert Watson.Nm SYSCTL_NODE ,
52dba9e9ccSRobert Watson.Nm SYSCTL_OPAQUE ,
53dba9e9ccSRobert Watson.Nm SYSCTL_PROC ,
5460a77442SJohn Baldwin.Nm SYSCTL_QUAD ,
555eb1caa8SHans Petter Selasky.Nm SYSCTL_ROOT_NODE ,
56dba9e9ccSRobert Watson.Nm SYSCTL_STRING ,
57dba9e9ccSRobert Watson.Nm SYSCTL_STRUCT ,
58dba9e9ccSRobert Watson.Nm SYSCTL_UINT ,
59c157a036SDavid E. O'Brien.Nm SYSCTL_ULONG ,
6060a77442SJohn Baldwin.Nm SYSCTL_UQUAD
615eb1caa8SHans Petter Selasky.Nd Dynamic and static sysctl MIB creation functions
62dba9e9ccSRobert Watson.Sh SYNOPSIS
63dba9e9ccSRobert Watson.In sys/types.h
64dba9e9ccSRobert Watson.In sys/sysctl.h
65bd84dd2fSRuslan Ermilov.Fn SYSCTL_DECL name
665eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
675eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_INT
685eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
695eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
705eb1caa8SHans Petter Selasky.Fa "int number"
715eb1caa8SHans Petter Selasky.Fa "const char *name"
725eb1caa8SHans Petter Selasky.Fa "int ctlflags"
735eb1caa8SHans Petter Selasky.Fa "int *ptr"
745eb1caa8SHans Petter Selasky.Fa "intptr_t val"
755eb1caa8SHans Petter Selasky.Fa "const char *descr"
765eb1caa8SHans Petter Selasky.Fc
775eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
785eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_LONG
795eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
805eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
815eb1caa8SHans Petter Selasky.Fa "int number"
825eb1caa8SHans Petter Selasky.Fa "const char *name"
835eb1caa8SHans Petter Selasky.Fa "int ctlflags"
845eb1caa8SHans Petter Selasky.Fa "long *ptr"
855eb1caa8SHans Petter Selasky.Fa "intptr_t val"
865eb1caa8SHans Petter Selasky.Fa "const char *descr"
875eb1caa8SHans Petter Selasky.Fc
885eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
895eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_NODE
905eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
915eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
925eb1caa8SHans Petter Selasky.Fa "int number"
935eb1caa8SHans Petter Selasky.Fa "const char *name"
945eb1caa8SHans Petter Selasky.Fa "int ctlflags"
955eb1caa8SHans Petter Selasky.Fa "int (*handler)(SYSCTL_HANDLER_ARGS)"
965eb1caa8SHans Petter Selasky.Fa "const char *descr"
975eb1caa8SHans Petter Selasky.Fc
985eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
995eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_OPAQUE
1005eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
1015eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
1025eb1caa8SHans Petter Selasky.Fa "int number"
1035eb1caa8SHans Petter Selasky.Fa "const char *name"
1045eb1caa8SHans Petter Selasky.Fa "int ctlflags"
1055eb1caa8SHans Petter Selasky.Fa "void *ptr"
1065eb1caa8SHans Petter Selasky.Fa "intptr_t len"
1075eb1caa8SHans Petter Selasky.Fa "const char *format"
1083edc2b53SJoel Dahl.Fa "const char *descr"
1095eb1caa8SHans Petter Selasky.Fc
1105eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
1115eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_PROC
1125eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
1135eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
1145eb1caa8SHans Petter Selasky.Fa "int number"
1155eb1caa8SHans Petter Selasky.Fa "const char *name"
1165eb1caa8SHans Petter Selasky.Fa "int ctlflags"
1175eb1caa8SHans Petter Selasky.Fa "void *arg1"
1185eb1caa8SHans Petter Selasky.Fa "intptr_t arg2"
1195eb1caa8SHans Petter Selasky.Fa "int (*handler) (SYSCTL_HANDLERARGS)"
1205eb1caa8SHans Petter Selasky.Fa "const char *format"
1215eb1caa8SHans Petter Selasky.Fa "const char *descr"
1225eb1caa8SHans Petter Selasky.Fc
1235eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
1245eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_QUAD
1255eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
1265eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
1275eb1caa8SHans Petter Selasky.Fa "int number"
1285eb1caa8SHans Petter Selasky.Fa "const char *name"
1295eb1caa8SHans Petter Selasky.Fa "int ctlflags"
1305eb1caa8SHans Petter Selasky.Fa "quad_t *ptr"
1315eb1caa8SHans Petter Selasky.Fa "intptr_t val"
1325eb1caa8SHans Petter Selasky.Fa "const char *descr"
1335eb1caa8SHans Petter Selasky.Fc
1345eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
1355eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_ROOT_NODE
1365eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
1375eb1caa8SHans Petter Selasky.Fa "int number"
1385eb1caa8SHans Petter Selasky.Fa "const char *name"
1395eb1caa8SHans Petter Selasky.Fa "int ctlflags"
1405eb1caa8SHans Petter Selasky.Fa "int (*handler)(SYSCTL_HANDLER_ARGS)"
1415eb1caa8SHans Petter Selasky.Fa "const char *descr"
1425eb1caa8SHans Petter Selasky.Fc
1435eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
1445eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_STRING
1455eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
1465eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
1475eb1caa8SHans Petter Selasky.Fa "int number"
1485eb1caa8SHans Petter Selasky.Fa "const char *name"
1495eb1caa8SHans Petter Selasky.Fa "int ctlflags"
1505eb1caa8SHans Petter Selasky.Fa "char *ptr"
1515eb1caa8SHans Petter Selasky.Fa "intptr_t len"
1525eb1caa8SHans Petter Selasky.Fa "const char *descr"
1535eb1caa8SHans Petter Selasky.Fc
1545eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
1555eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_STRUCT
1565eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
1575eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
1585eb1caa8SHans Petter Selasky.Fa "int number"
1595eb1caa8SHans Petter Selasky.Fa "const char *name"
1605eb1caa8SHans Petter Selasky.Fa "int ctlflags"
1615eb1caa8SHans Petter Selasky.Fa "void *ptr"
1625eb1caa8SHans Petter Selasky.Fa struct_type
1635eb1caa8SHans Petter Selasky.Fa "const char *descr"
1645eb1caa8SHans Petter Selasky.Fc
1655eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
1665eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_UINT
1675eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
1685eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
1695eb1caa8SHans Petter Selasky.Fa "int number"
1705eb1caa8SHans Petter Selasky.Fa "const char *name"
1715eb1caa8SHans Petter Selasky.Fa "int ctlflags"
1725eb1caa8SHans Petter Selasky.Fa "unsigned int *ptr"
1735eb1caa8SHans Petter Selasky.Fa "intptr_t val"
1745eb1caa8SHans Petter Selasky.Fa "const char *descr"
1755eb1caa8SHans Petter Selasky.Fc
1765eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
1775eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_ULONG
1785eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
1795eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
1805eb1caa8SHans Petter Selasky.Fa "int number"
1815eb1caa8SHans Petter Selasky.Fa "const char *name"
1825eb1caa8SHans Petter Selasky.Fa "int ctlflags"
1835eb1caa8SHans Petter Selasky.Fa "unsigned long *ptr"
1845eb1caa8SHans Petter Selasky.Fa "intptr_t val"
1855eb1caa8SHans Petter Selasky.Fa "const char *descr"
1865eb1caa8SHans Petter Selasky.Fc
1875eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
1885eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_UQUAD
1895eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
1905eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
1915eb1caa8SHans Petter Selasky.Fa "int number"
1925eb1caa8SHans Petter Selasky.Fa "const char *name"
1935eb1caa8SHans Petter Selasky.Fa "int ctlflags"
1945eb1caa8SHans Petter Selasky.Fa "u_quad_t *ptr"
1955eb1caa8SHans Petter Selasky.Fa "intptr_t val"
1965eb1caa8SHans Petter Selasky.Fa "const char *descr"
1975eb1caa8SHans Petter Selasky.Fc
1985eb1caa8SHans Petter Selasky.Ft struct sysctl_oid_list *
1995eb1caa8SHans Petter Selasky.Fo SYSCTL_CHILDREN
2005eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid *oidp"
2015eb1caa8SHans Petter Selasky.Fc
2025eb1caa8SHans Petter Selasky.Ft struct sysctl_oid_list *
2035eb1caa8SHans Petter Selasky.Fo SYSCTL_STATIC_CHILDREN
2045eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list OID_NAME"
2055eb1caa8SHans Petter Selasky.Fc
2065eb1caa8SHans Petter Selasky.Ft struct sysctl_oid_list *
2075eb1caa8SHans Petter Selasky.Fo SYSCTL_NODE_CHILDREN
2085eb1caa8SHans Petter Selasky.Fa "parent"
2095eb1caa8SHans Petter Selasky.Fa "name"
2105eb1caa8SHans Petter Selasky.Fc
2115eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
2125eb1caa8SHans Petter Selasky.Fo SYSCTL_PARENT
2135eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid *oid"
2145eb1caa8SHans Petter Selasky.Fc
2155eb1caa8SHans Petter Selasky.Fn SYSCTL_INT parent number name ctlflags ptr val descr
2165eb1caa8SHans Petter Selasky.Fn SYSCTL_LONG parent number name ctlflags ptr val descr
2175eb1caa8SHans Petter Selasky.Fn SYSCTL_NODE parent number name ctlflags handler descr
2185eb1caa8SHans Petter Selasky.Fn SYSCTL_OPAQUE parent number name ctlflags ptr len format descr
2195eb1caa8SHans Petter Selasky.Fn SYSCTL_PROC parent number name ctlflags arg1 arg2 handler format descr
2205eb1caa8SHans Petter Selasky.Fn SYSCTL_QUAD parent number name ctlflags ptr val descr
2215eb1caa8SHans Petter Selasky.Fn SYSCTL_STRING parent number name ctlflags arg len descr
2225eb1caa8SHans Petter Selasky.Fn SYSCTL_STRUCT parent number name ctlflags ptr struct_type descr
2235eb1caa8SHans Petter Selasky.Fn SYSCTL_ROOT_NODE number name ctlflags handler descr
2245eb1caa8SHans Petter Selasky.Fn SYSCTL_UINT parent number name ctlflags ptr val descr
2255eb1caa8SHans Petter Selasky.Fn SYSCTL_ULONG parent number name ctlflags ptr val descr
2265eb1caa8SHans Petter Selasky.Fn SYSCTL_UQUAD parent number name ctlflags ptr val descr
227dba9e9ccSRobert Watson.Sh DESCRIPTION
228dba9e9ccSRobert WatsonThe
229bd84dd2fSRuslan Ermilov.Nm SYSCTL
2305eb1caa8SHans Petter Selaskykernel interface allows dynamic or static creation of
231dba9e9ccSRobert Watson.Xr sysctl 8
2325eb1caa8SHans Petter SelaskyMIB entries.
2335eb1caa8SHans Petter SelaskyAll static sysctls are automatically destroyed when the module which
2345eb1caa8SHans Petter Selaskythey are part of is unloaded.
2355eb1caa8SHans Petter SelaskyMost top level categories are created statically and are available to
2365eb1caa8SHans Petter Selaskyall kernel code and its modules.
2375eb1caa8SHans Petter Selasky.Sh DESCRIPTION OF ARGUMENTS
2385eb1caa8SHans Petter Selasky.Bl -tag -width ctlflags
2395eb1caa8SHans Petter Selasky.It Fa ctx
2405eb1caa8SHans Petter SelaskyPointer to sysctl context or NULL, if no context.
2415eb1caa8SHans Petter SelaskySee
2425eb1caa8SHans Petter Selasky.Xr sysctl_ctx_init 9
2435eb1caa8SHans Petter Selaskyfor how to create a new sysctl context.
2445eb1caa8SHans Petter SelaskyProgrammers are strongly advised to use contexts to organize the
2455eb1caa8SHans Petter Selaskydynamic OIDs which they create because when a context is destroyed all
2465eb1caa8SHans Petter Selaskybelonging sysctls are destroyed as well.
2475eb1caa8SHans Petter SelaskyThis makes the sysctl cleanup code much simpler.
248aa88ccabSHans Petter SelaskyElse deletion of all created OIDs is required at module unload.
2495eb1caa8SHans Petter Selasky.It Fa parent
2505eb1caa8SHans Petter SelaskyA pointer to a
2515eb1caa8SHans Petter Selasky.Li struct sysctl_oid_list ,
2525eb1caa8SHans Petter Selaskywhich is the head of the parent's list of children.
253aa88ccabSHans Petter SelaskyThis pointer is retrieved using the
2545eb1caa8SHans Petter Selasky.Fn SYSCTL_STATIC_CHILDREN
2555eb1caa8SHans Petter Selaskymacro for static sysctls and the
2565eb1caa8SHans Petter Selasky.Fn SYSCTL_CHILDREN
2575eb1caa8SHans Petter Selaskymacro for dynamic sysctls.
258aa88ccabSHans Petter SelaskyThe
2595eb1caa8SHans Petter Selasky.Fn SYSCTL_PARENT
260aa88ccabSHans Petter Selaskymacro can be used to get the parent of an OID.
261aa88ccabSHans Petter SelaskyThe macro returns NULL if there is no parent.
2625eb1caa8SHans Petter Selasky.It Fa number
2635eb1caa8SHans Petter SelaskyThe OID number that will be assigned to this OID.
2645eb1caa8SHans Petter SelaskyIn almost all cases this should be set to
2655eb1caa8SHans Petter Selasky.Dv OID_AUTO ,
2665eb1caa8SHans Petter Selaskywhich will result in the assignment of the next available OID number.
2675eb1caa8SHans Petter Selasky.It Fa name
2685eb1caa8SHans Petter SelaskyThe name of the OID.
2695eb1caa8SHans Petter SelaskyThe newly created OID will contain a copy of the name.
2705eb1caa8SHans Petter Selasky.It Fa ctlflags
2715eb1caa8SHans Petter SelaskyA bit mask of sysctl control flags.
2725eb1caa8SHans Petter SelaskySee the section below describing all the control flags.
2735eb1caa8SHans Petter Selasky.It Fa arg1
2745eb1caa8SHans Petter SelaskyFirst callback argument for procedure sysctls.
2755eb1caa8SHans Petter Selasky.It Fa arg2
2765eb1caa8SHans Petter SelaskySecond callback argument for procedure sysctls.
2775eb1caa8SHans Petter Selasky.It Fa len
2785eb1caa8SHans Petter SelaskyThe length of the data pointed to by the
2795eb1caa8SHans Petter Selasky.Fa ptr
2805eb1caa8SHans Petter Selaskyargument.
2815eb1caa8SHans Petter SelaskyFor string type OIDs a length of zero means that
2825eb1caa8SHans Petter Selasky.Xr strlen 3
2835eb1caa8SHans Petter Selaskywill be used to get the length of the string at each access to the OID.
2845eb1caa8SHans Petter Selasky.It Fa ptr
2855eb1caa8SHans Petter SelaskyPointer to sysctl variable or string data.
2865eb1caa8SHans Petter SelaskyFor sysctl values the pointer can be NULL which means the OID is read-only and the returned value should be taken from the
2875eb1caa8SHans Petter Selasky.Fa val
2885eb1caa8SHans Petter Selaskyargument.
2895eb1caa8SHans Petter Selasky.It Fa val
2905eb1caa8SHans Petter SelaskyIf the
2915eb1caa8SHans Petter Selasky.Fa ptr
2925eb1caa8SHans Petter Selaskyargument is NULL, gives the constant value returned by this OID.
2935eb1caa8SHans Petter SelaskyElse this argument is not used.
2945eb1caa8SHans Petter Selasky.It Fa struct_type
2955eb1caa8SHans Petter SelaskyName of structure type.
2965eb1caa8SHans Petter Selasky.It Fa handler
2975eb1caa8SHans Petter SelaskyA pointer to the function
2985eb1caa8SHans Petter Selaskythat is responsible for handling read and write requests
2995eb1caa8SHans Petter Selaskyto this OID.
3005eb1caa8SHans Petter SelaskyThere are several standard handlers
3015eb1caa8SHans Petter Selaskythat support operations on nodes,
3025eb1caa8SHans Petter Selaskyintegers, strings and opaque objects.
3035eb1caa8SHans Petter SelaskyIt is possible to define custom handlers using the
3045eb1caa8SHans Petter Selasky.Fn SYSCTL_PROC
3055eb1caa8SHans Petter Selaskymacro or the
3065eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_PROC
3075eb1caa8SHans Petter Selaskyfunction.
3085eb1caa8SHans Petter Selasky.It Fa format
3095eb1caa8SHans Petter SelaskyA pointer to a string
3105eb1caa8SHans Petter Selaskywhich specifies the format of the OID in a symbolic way.
3115eb1caa8SHans Petter SelaskyThis format is used as a hint by
3125eb1caa8SHans Petter Selasky.Xr sysctl 8
3135eb1caa8SHans Petter Selaskyto apply proper data formatting for display purposes.
3145eb1caa8SHans Petter SelaskyCurrently used format names are:
3155eb1caa8SHans Petter Selasky.Dq N
3165eb1caa8SHans Petter Selaskyfor node,
3175eb1caa8SHans Petter Selasky.Dq A
3185eb1caa8SHans Petter Selaskyfor
3195eb1caa8SHans Petter Selasky.Li "char *" ,
3205eb1caa8SHans Petter Selasky.Dq I
3215eb1caa8SHans Petter Selaskyfor
3225eb1caa8SHans Petter Selasky.Li "int" ,
3235eb1caa8SHans Petter Selasky.Dq IU
3245eb1caa8SHans Petter Selaskyfor
3255eb1caa8SHans Petter Selasky.Li "unsigned int" ,
3265eb1caa8SHans Petter Selasky.Dq L
3275eb1caa8SHans Petter Selaskyfor
3285eb1caa8SHans Petter Selasky.Li "long" ,
3295eb1caa8SHans Petter Selasky.Dq LU
3305eb1caa8SHans Petter Selaskyfor
3315eb1caa8SHans Petter Selasky.Li "unsigned long" ,
3325eb1caa8SHans Petter Selasky.Dq Q
3335eb1caa8SHans Petter Selaskyfor
3345eb1caa8SHans Petter Selasky.Li "quad_t" ,
3355eb1caa8SHans Petter Selasky.Dq QU
3365eb1caa8SHans Petter Selaskyfor
3375eb1caa8SHans Petter Selasky.Li "u_quad_t"
3385eb1caa8SHans Petter Selaskyand
3395eb1caa8SHans Petter Selasky.Dq S,TYPE
3405eb1caa8SHans Petter Selaskyfor
3415eb1caa8SHans Petter Selasky.Li "struct TYPE"
3425eb1caa8SHans Petter Selaskystructures.
3435eb1caa8SHans Petter Selasky.It Fa descr
3445eb1caa8SHans Petter SelaskyA pointer to a textual description of the OID.
3455eb1caa8SHans Petter Selasky.El
3465eb1caa8SHans Petter Selasky.Sh CREATING ROOT NODES
3475eb1caa8SHans Petter SelaskySysctl MIBs or OIDs are created in a hierarchical tree.
3485eb1caa8SHans Petter SelaskyThe nodes at the bottom of the tree are called root nodes, and have no
3495eb1caa8SHans Petter Selaskyparent OID.
3505eb1caa8SHans Petter SelaskyTo create bottom tree nodes the
3515eb1caa8SHans Petter Selasky.Fn SYSCTL_ROOT_NODE
3525eb1caa8SHans Petter Selaskymacro or the
3535eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_ROOT_NODE
3545eb1caa8SHans Petter Selaskyfunction needs to be used.
3555eb1caa8SHans Petter SelaskyBy default all static sysctl node OIDs are global and need a
3565eb1caa8SHans Petter Selasky.Fn SYSCTL_DECL
3575eb1caa8SHans Petter Selaskystatement prior to their
3585eb1caa8SHans Petter Selasky.Fn SYSCTL_NODE
3595eb1caa8SHans Petter Selaskydefinition statement, typically in a so-called header file.
3605eb1caa8SHans Petter Selasky.Sh CREATING SYSCTL STRINGS
3615eb1caa8SHans Petter SelaskyZero terminated character strings sysctls are created either using the
3625eb1caa8SHans Petter Selasky.Fn SYSCTL_STRING
3635eb1caa8SHans Petter Selaskymacro or the
3645eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_STRING
3655eb1caa8SHans Petter Selaskyfunction.
3665eb1caa8SHans Petter SelaskyIf the
3675eb1caa8SHans Petter Selasky.Fa len
3685eb1caa8SHans Petter Selaskyargument in zero, the string length is computed at every access to the OID using
3695eb1caa8SHans Petter Selasky.Xr strlen 3 .
3705eb1caa8SHans Petter Selasky.Sh CREATING OPAQUE SYSCTLS
3715eb1caa8SHans Petter SelaskyThe
3725eb1caa8SHans Petter Selasky.Fn SYSCTL_OPAQUE
3735eb1caa8SHans Petter Selaskyor
3745eb1caa8SHans Petter Selasky.Fn SYSCTL_STRUCT
3755eb1caa8SHans Petter Selaskymacros or the
3765eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_OPAQUE
3775eb1caa8SHans Petter Selaskyor
3785eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_STRUCT
3795eb1caa8SHans Petter Selaskyfunctions create an OID that handle any chunk of data
3805eb1caa8SHans Petter Selaskyof the size specified by the
3815eb1caa8SHans Petter Selasky.Fa len
3825eb1caa8SHans Petter Selaskyargument and data pointed to by the
3835eb1caa8SHans Petter Selasky.Fa ptr
3845eb1caa8SHans Petter Selaskyargument.
3855eb1caa8SHans Petter SelaskyWhen using the structure version the type is encoded as part of the
3865eb1caa8SHans Petter Selaskycreated sysctl.
3875eb1caa8SHans Petter Selasky.Sh CREATING CUSTOM SYSCTLS
3885eb1caa8SHans Petter SelaskyThe
3895eb1caa8SHans Petter Selasky.Fn SYSCTL_PROC
3905eb1caa8SHans Petter Selaskymacro and the
3915eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_PROC
3925eb1caa8SHans Petter Selaskyfunction
3935eb1caa8SHans Petter Selaskycreate OIDs with the specified
3945eb1caa8SHans Petter Selasky.Pa handler
3955eb1caa8SHans Petter Selaskyfunction.
3965eb1caa8SHans Petter SelaskyThe handler is responsible for handling all read and write requests to
3975eb1caa8SHans Petter Selaskythe OID.
3985eb1caa8SHans Petter SelaskyThis OID type is especially useful if the kernel data is not easily
3995eb1caa8SHans Petter Selaskyaccessible, or needs to be processed before exporting.
4005eb1caa8SHans Petter Selasky.Sh CREATING A STATIC SYSCTL
4015eb1caa8SHans Petter SelaskyStatic sysctls are declared using one of the
402bd84dd2fSRuslan Ermilov.Fn SYSCTL_INT ,
403bd84dd2fSRuslan Ermilov.Fn SYSCTL_LONG ,
404bd84dd2fSRuslan Ermilov.Fn SYSCTL_NODE ,
405bd84dd2fSRuslan Ermilov.Fn SYSCTL_OPAQUE ,
406bd84dd2fSRuslan Ermilov.Fn SYSCTL_PROC ,
40760a77442SJohn Baldwin.Fn SYSCTL_QUAD ,
4085eb1caa8SHans Petter Selasky.Fn SYSCTL_ROOT_NODE ,
409bd84dd2fSRuslan Ermilov.Fn SYSCTL_STRING ,
410bd84dd2fSRuslan Ermilov.Fn SYSCTL_STRUCT ,
411bd84dd2fSRuslan Ermilov.Fn SYSCTL_UINT ,
4125eb1caa8SHans Petter Selasky.Fn SYSCTL_ULONG
4135eb1caa8SHans Petter Selaskyor
4145eb1caa8SHans Petter Selasky.Fn SYSCTL_UQUAD
4155eb1caa8SHans Petter Selaskymacros.
4165eb1caa8SHans Petter Selasky.Sh CREATING A DYNAMIC SYSCTL
4175eb1caa8SHans Petter SelaskyDynamic nodes are created using one of the
4185eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_INT ,
4195eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_LONG ,
4205eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_NODE ,
4215eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_OPAQUE ,
4225eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_PROC ,
4235eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_QUAD ,
4245eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_ROOT_NODE ,
4255eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_STRING ,
4265eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_STRUCT ,
4275eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_UINT ,
4285eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_ULONG
4295eb1caa8SHans Petter Selaskyor
4305eb1caa8SHans Petter Selasky.Fn SYSCTL_UQUAD
4315eb1caa8SHans Petter Selaskyfunctions.
4325eb1caa8SHans Petter SelaskySee
4335eb1caa8SHans Petter Selasky.Xr sysctl_remove_oid 9
4345eb1caa8SHans Petter Selaskyor
4355eb1caa8SHans Petter Selasky.Xr sysctl_ctx_free 9
4365eb1caa8SHans Petter Selaskyfor more information on how to destroy a dynamically created OID.
4375eb1caa8SHans Petter Selasky.Sh CONTROL FLAGS
4385eb1caa8SHans Petter SelaskyFor most of the above functions and macros, declaring a type as part
4395eb1caa8SHans Petter Selaskyof the access flags is not necessary \[em] however, when declaring a
4405eb1caa8SHans Petter Selaskysysctl implemented by a function, including a type in the access mask
4415eb1caa8SHans Petter Selaskyis required:
4425eb1caa8SHans Petter Selasky.Bl -tag -width ".Dv CTLTYPE_NOFETCH"
443dba9e9ccSRobert Watson.It Dv CTLTYPE_NODE
444dba9e9ccSRobert WatsonThis is a node intended to be a parent for other nodes.
445dba9e9ccSRobert Watson.It Dv CTLTYPE_INT
446dba9e9ccSRobert WatsonThis is a signed integer.
447dba9e9ccSRobert Watson.It Dv CTLTYPE_STRING
448dba9e9ccSRobert WatsonThis is a nul-terminated string stored in a character array.
449cbc134adSMatthew D Fleming.It Dv CTLTYPE_S64
450dba9e9ccSRobert WatsonThis is a 64-bit signed integer.
451dba9e9ccSRobert Watson.It Dv CTLTYPE_OPAQUE
452dba9e9ccSRobert WatsonThis is an opaque data structure.
453dba9e9ccSRobert Watson.It Dv CTLTYPE_STRUCT
454dba9e9ccSRobert WatsonAlias for
455dba9e9ccSRobert Watson.Dv CTLTYPE_OPAQUE .
456dba9e9ccSRobert Watson.It Dv CTLTYPE_UINT
457dba9e9ccSRobert WatsonThis is an unsigned integer.
458dba9e9ccSRobert Watson.It Dv CTLTYPE_LONG
459dba9e9ccSRobert WatsonThis is a signed long.
460dba9e9ccSRobert Watson.It Dv CTLTYPE_ULONG
4618a1f4129SRobert WatsonThis is an unsigned long.
462cbc134adSMatthew D Fleming.It Dv CTLTYPE_U64
463cbc134adSMatthew D FlemingThis is a 64-bit unsigned integer.
464dba9e9ccSRobert Watson.El
465dba9e9ccSRobert Watson.Pp
46660a77442SJohn BaldwinAll sysctl types except for new node declarations require one of the following
46760a77442SJohn Baldwinflags to be set indicating the read and write disposition of the sysctl:
468bd84dd2fSRuslan Ermilov.Bl -tag -width ".Dv CTLFLAG_ANYBODY"
469dba9e9ccSRobert Watson.It Dv CTLFLAG_RD
470dba9e9ccSRobert WatsonThis is a read-only sysctl.
47160a77442SJohn Baldwin.It Dv CTLFLAG_RDTUN
4725eb1caa8SHans Petter SelaskyThis is a read-only sysctl and tunable which is tried fetched once
4735eb1caa8SHans Petter Selaskyfrom the system enviroment early during module load or system boot.
474b470b929SDavid E. O'Brien.It Dv CTLFLAG_WR
475dba9e9ccSRobert WatsonThis is a writable sysctl.
476dba9e9ccSRobert Watson.It Dv CTLFLAG_RW
477dba9e9ccSRobert WatsonThis sysctl is readable and writable.
47860a77442SJohn Baldwin.It Dv CTLFLAG_RWTUN
4795eb1caa8SHans Petter SelaskyThis is a readable and writeable sysctl and tunable which is tried
4805eb1caa8SHans Petter Selaskyfetched once from the system enviroment early during module load or
4815eb1caa8SHans Petter Selaskysystem boot.
4825eb1caa8SHans Petter Selasky.It Dv CTLFLAG_NOFETCH
4835eb1caa8SHans Petter SelaskyIn case the node is marked as a tunable using the CTLFLAG_[XX]TUN,
4845eb1caa8SHans Petter Selaskythis flag will prevent fetching the initial value from the system
4855eb1caa8SHans Petter Selaskyenvironment. Typically this flag should only be used for very early
4865eb1caa8SHans Petter Selaskylow level system setup code, and not by common drivers and modules.
48760a77442SJohn Baldwin.El
48860a77442SJohn Baldwin.Pp
48960a77442SJohn BaldwinAdditionally, any of the following optional flags may also be specified:
49060a77442SJohn Baldwin.Bl -tag -width ".Dv CTLFLAG_ANYBODY"
491dba9e9ccSRobert Watson.It Dv CTLFLAG_ANYBODY
492dba9e9ccSRobert WatsonAny user or process can write to this sysctl.
493dba9e9ccSRobert Watson.It Dv CTLFLAG_SECURE
494dba9e9ccSRobert WatsonThis sysctl can be written to only if the effective securelevel of the
495bd84dd2fSRuslan Ermilovprocess is \[<=] 0.
496dba9e9ccSRobert Watson.It Dv CTLFLAG_PRISON
497dba9e9ccSRobert WatsonThis sysctl can be written to by processes in
498dba9e9ccSRobert Watson.Xr jail 2 .
499dba9e9ccSRobert Watson.It Dv CTLFLAG_SKIP
500dba9e9ccSRobert WatsonWhen iterating the sysctl name space, do not list this sysctl.
501dba9e9ccSRobert Watson.It Dv CTLFLAG_TUN
5026b9597aaSAndrew ThompsonAdvisory flag that a system tunable also exists for this variable.
5035eb1caa8SHans Petter SelaskyThe initial sysctl value is tried fetched once from the system
5045eb1caa8SHans Petter Selaskyenviroment early during module load or system boot.
5055eb1caa8SHans Petter Selasky.It Dv CTLFLAG_DYN
5065eb1caa8SHans Petter SelaskyDynamically created OIDs automatically get this flag set.
507*56538e4aSGleb Smirnoff.It Dv CTLFLAG_VNET
508*56538e4aSGleb SmirnoffOID references a VIMAGE-enabled variable.
509dba9e9ccSRobert Watson.El
510dba9e9ccSRobert Watson.Sh EXAMPLES
511dba9e9ccSRobert WatsonSample use of
512bd84dd2fSRuslan Ermilov.Fn SYSCTL_DECL
513bd84dd2fSRuslan Ermilovto declare the
514bd84dd2fSRuslan Ermilov.Va security
515bd84dd2fSRuslan Ermilovsysctl tree for use by new nodes:
516dba9e9ccSRobert Watson.Bd -literal -offset indent
517dba9e9ccSRobert WatsonSYSCTL_DECL(_security);
518dba9e9ccSRobert Watson.Ed
519dba9e9ccSRobert Watson.Pp
520dba9e9ccSRobert WatsonExamples of integer, opaque, string, and procedure sysctls follow:
521dba9e9ccSRobert Watson.Bd -literal -offset indent
522dba9e9ccSRobert Watson/*
523dba9e9ccSRobert Watson * Example of a constant integer value.  Notice that the control
524dba9e9ccSRobert Watson * flags are CTLFLAG_RD, the variable pointer is NULL, and the
525dba9e9ccSRobert Watson * value is declared.
526dba9e9ccSRobert Watson */
527dba9e9ccSRobert WatsonSYSCTL_INT(_debug_sizeof, OID_AUTO, bio, CTLFLAG_RD, NULL,
528dba9e9ccSRobert Watson    sizeof(struct bio), "sizeof(struct bio)");
529dba9e9ccSRobert Watson
530dba9e9ccSRobert Watson/*
531dba9e9ccSRobert Watson * Example of a variable integer value.  Notice that the control
532dba9e9ccSRobert Watson * flags are CTLFLAG_RW, the variable pointer is set, and the
533dba9e9ccSRobert Watson * value is 0.
534dba9e9ccSRobert Watson */
535dba9e9ccSRobert Watsonstatic int	doingcache = 1;		/* 1 => enable the cache */
536dba9e9ccSRobert WatsonSYSCTL_INT(_debug, OID_AUTO, vfscache, CTLFLAG_RW, &doingcache, 0,
537dba9e9ccSRobert Watson    "Enable name cache");
538dba9e9ccSRobert Watson
539dba9e9ccSRobert Watson/*
540dba9e9ccSRobert Watson * Example of a variable string value.  Notice that the control
541dba9e9ccSRobert Watson * flags are CTLFLAG_RW, that the variable pointer and string
542dba9e9ccSRobert Watson * size are set.  Unlike newer sysctls, this older sysctl uses a
543dba9e9ccSRobert Watson * static oid number.
544dba9e9ccSRobert Watson */
545dba9e9ccSRobert Watsonchar kernelname[MAXPATHLEN] = "/kernel";	/* XXX bloat */
546dba9e9ccSRobert WatsonSYSCTL_STRING(_kern, KERN_BOOTFILE, bootfile, CTLFLAG_RW,
547dba9e9ccSRobert Watson    kernelname, sizeof(kernelname), "Name of kernel file booted");
548dba9e9ccSRobert Watson
549dba9e9ccSRobert Watson/*
550dba9e9ccSRobert Watson * Example of an opaque data type exported by sysctl.  Notice that
551dba9e9ccSRobert Watson * the variable pointer and size are provided, as well as a format
552dba9e9ccSRobert Watson * string for sysctl(8).
553dba9e9ccSRobert Watson */
554dba9e9ccSRobert Watsonstatic l_fp pps_freq;	/* scaled frequence offset (ns/s) */
555dba9e9ccSRobert WatsonSYSCTL_OPAQUE(_kern_ntp_pll, OID_AUTO, pps_freq, CTLFLAG_RD,
556dba9e9ccSRobert Watson    &pps_freq, sizeof(pps_freq), "I", "");
557dba9e9ccSRobert Watson
558dba9e9ccSRobert Watson/*
559dba9e9ccSRobert Watson * Example of a procedure based sysctl exporting string
560dba9e9ccSRobert Watson * information.  Notice that the data type is declared, the NULL
561dba9e9ccSRobert Watson * variable pointer and 0 size, the function pointer, and the
562dba9e9ccSRobert Watson * format string for sysctl(8).
563dba9e9ccSRobert Watson */
564dba9e9ccSRobert WatsonSYSCTL_PROC(_kern_timecounter, OID_AUTO, hardware, CTLTYPE_STRING |
565dba9e9ccSRobert Watson    CTLFLAG_RW, NULL, 0, sysctl_kern_timecounter_hardware, "A",
566dba9e9ccSRobert Watson    "");
567dba9e9ccSRobert Watson.Ed
5685eb1caa8SHans Petter Selasky.Pp
5695eb1caa8SHans Petter SelaskyThe following is an example of
5705eb1caa8SHans Petter Selaskyhow to create a new top-level category
5715eb1caa8SHans Petter Selaskyand how to hook up another subtree to an existing static node.
5725eb1caa8SHans Petter SelaskyThis example does not use contexts,
5735eb1caa8SHans Petter Selaskywhich results in tedious management of all intermediate oids,
5745eb1caa8SHans Petter Selaskyas they need to be freed later on:
5755eb1caa8SHans Petter Selasky.Bd -literal -offset indent
5765eb1caa8SHans Petter Selasky#include <sys/sysctl.h>
5775eb1caa8SHans Petter Selasky ...
5785eb1caa8SHans Petter Selasky/*
5795eb1caa8SHans Petter Selasky * Need to preserve pointers to newly created subtrees,
5805eb1caa8SHans Petter Selasky * to be able to free them later:
5815eb1caa8SHans Petter Selasky */
5825eb1caa8SHans Petter Selaskystatic struct sysctl_oid *root1;
5835eb1caa8SHans Petter Selaskystatic struct sysctl_oid *root2;
5845eb1caa8SHans Petter Selaskystatic struct sysctl_oid *oidp;
5855eb1caa8SHans Petter Selaskystatic int a_int;
5865eb1caa8SHans Petter Selaskystatic char *string = "dynamic sysctl";
5875eb1caa8SHans Petter Selasky ...
5885eb1caa8SHans Petter Selasky
5895eb1caa8SHans Petter Selaskyroot1 = SYSCTL_ADD_ROOT_NODE(NULL,
5905eb1caa8SHans Petter Selasky	OID_AUTO, "newtree", CTLFLAG_RW, 0, "new top level tree");
5915eb1caa8SHans Petter Selaskyoidp = SYSCTL_ADD_INT(NULL, SYSCTL_CHILDREN(root1),
5925eb1caa8SHans Petter Selasky	OID_AUTO, "newint", CTLFLAG_RW, &a_int, 0, "new int leaf");
5935eb1caa8SHans Petter Selasky ...
5945eb1caa8SHans Petter Selaskyroot2 = SYSCTL_ADD_NODE(NULL, SYSCTL_STATIC_CHILDREN(_debug),
5955eb1caa8SHans Petter Selasky	OID_AUTO, "newtree", CTLFLAG_RW, 0, "new tree under debug");
5965eb1caa8SHans Petter Selaskyoidp = SYSCTL_ADD_STRING(NULL, SYSCTL_CHILDREN(root2),
5975eb1caa8SHans Petter Selasky	OID_AUTO, "newstring", CTLFLAG_RD, string, 0, "new string leaf");
5985eb1caa8SHans Petter Selasky.Ed
5995eb1caa8SHans Petter Selasky.Pp
6005eb1caa8SHans Petter SelaskyThis example creates the following subtrees:
6015eb1caa8SHans Petter Selasky.Bd -literal -offset indent
6025eb1caa8SHans Petter Selaskydebug.newtree.newstring
6035eb1caa8SHans Petter Selaskynewtree.newint
6045eb1caa8SHans Petter Selasky.Ed
6055eb1caa8SHans Petter Selasky.Pp
6065eb1caa8SHans Petter Selasky.Em "Care should be taken to free all OIDs once they are no longer needed!"
60791f3a6dbSYaroslav Tykhiy.Sh SYSCTL NAMING
608dba9e9ccSRobert WatsonWhen adding, modifying, or removing sysctl names, it is important to be
609dba9e9ccSRobert Watsonaware that these interfaces may be used by users, libraries, applications,
610f4006affSGiorgos Keramidasor documentation (such as published books), and are implicitly published application interfaces.
611dba9e9ccSRobert WatsonAs with other application interfaces, caution must be taken not to break
612dba9e9ccSRobert Watsonexisting applications, and to think about future use of new name spaces so as
613dba9e9ccSRobert Watsonto avoid the need to rename or remove interfaces that might be depended on in
614dba9e9ccSRobert Watsonthe future.
61591f3a6dbSYaroslav Tykhiy.Pp
61691f3a6dbSYaroslav TykhiyThe semantics chosen for a new sysctl should be as clear as possible,
61791f3a6dbSYaroslav Tykhiyand the name of the sysctl must closely reflect its semantics.
61891f3a6dbSYaroslav TykhiyTherefore the sysctl name deserves a fair amount of consideration.
61991f3a6dbSYaroslav TykhiyIt should be short but yet representative of the sysctl meaning.
62091f3a6dbSYaroslav TykhiyIf the name consists of several words, they should be separated by
62191f3a6dbSYaroslav Tykhiyunderscore characters, as in
62291f3a6dbSYaroslav Tykhiy.Va compute_summary_at_mount .
62391f3a6dbSYaroslav TykhiyUnderscore characters may be omitted only if the name consists of not more
62491f3a6dbSYaroslav Tykhiythan two words, each being not longer than four characters, as in
62591f3a6dbSYaroslav Tykhiy.Va bootfile .
62691f3a6dbSYaroslav TykhiyFor boolean sysctls, negative logic should be totally avoided.
62791f3a6dbSYaroslav TykhiyThat is, do not use names like
62891f3a6dbSYaroslav Tykhiy.Va no_foobar
62991f3a6dbSYaroslav Tykhiyor
63091f3a6dbSYaroslav Tykhiy.Va foobar_disable .
63191f3a6dbSYaroslav TykhiyThey are confusing and lead to configuration errors.
63291f3a6dbSYaroslav TykhiyUse positive logic instead:
63391f3a6dbSYaroslav Tykhiy.Va foobar ,
63491f3a6dbSYaroslav Tykhiy.Va foobar_enable .
63591f3a6dbSYaroslav Tykhiy.Pp
6365eb1caa8SHans Petter SelaskyA temporary sysctl node OID that should not be relied upon must be designated
63791f3a6dbSYaroslav Tykhiyas such by a leading underscore character in its name. For example:
63891f3a6dbSYaroslav Tykhiy.Va _dirty_hack .
639dba9e9ccSRobert Watson.Sh SEE ALSO
640f3066f2bSGavin Atkinson.Xr sysctl 3 ,
641dba9e9ccSRobert Watson.Xr sysctl 8 ,
642dba9e9ccSRobert Watson.Xr sysctl_add_oid 9 ,
643dba9e9ccSRobert Watson.Xr sysctl_ctx_free 9 ,
644dba9e9ccSRobert Watson.Xr sysctl_ctx_init 9 ,
645dba9e9ccSRobert Watson.Xr sysctl_remove_oid 9
646dba9e9ccSRobert Watson.Sh HISTORY
647bd84dd2fSRuslan ErmilovThe
648dba9e9ccSRobert Watson.Xr sysctl 8
649bd84dd2fSRuslan Ermilovutility first appeared in
650dba9e9ccSRobert Watson.Bx 4.4 .
651dba9e9ccSRobert Watson.Sh AUTHORS
652bd84dd2fSRuslan Ermilov.An -nosplit
653bd84dd2fSRuslan ErmilovThe
654bd84dd2fSRuslan Ermilov.Nm sysctl
655bd84dd2fSRuslan Ermilovimplementation originally found in
656dba9e9ccSRobert Watson.Bx
657dba9e9ccSRobert Watsonhas been extensively rewritten by
658dba9e9ccSRobert Watson.An Poul-Henning Kamp
659dba9e9ccSRobert Watsonin order to add support for name lookups, name space iteration, and dynamic
660dba9e9ccSRobert Watsonaddition of MIB nodes.
661dba9e9ccSRobert Watson.Pp
662dba9e9ccSRobert WatsonThis man page was written by
663dba9e9ccSRobert Watson.An Robert N. M. Watson .
6643edc2b53SJoel Dahl.Sh SECURITY CONSIDERATIONS
6653edc2b53SJoel DahlWhen creating new sysctls, careful attention should be paid to the security
6663edc2b53SJoel Dahlimplications of the monitoring or management interface being created.
6673edc2b53SJoel DahlMost sysctls present in the kernel are read-only or writable only by the
6683edc2b53SJoel Dahlsuperuser.
6693edc2b53SJoel DahlSysctls exporting extensive information on system data structures and
6703edc2b53SJoel Dahloperation, especially those implemented using procedures, will wish to
6713edc2b53SJoel Dahlimplement access control to limit the undesired exposure of information about
6723edc2b53SJoel Dahlother processes, network connections, etc.
6733edc2b53SJoel Dahl.Pp
6743edc2b53SJoel DahlThe following top level sysctl name spaces are commonly used:
6753edc2b53SJoel Dahl.Bl -tag -width ".Va regression"
6763edc2b53SJoel Dahl.It Va compat
6773edc2b53SJoel DahlCompatibility layer information.
6783edc2b53SJoel Dahl.It Va debug
6793edc2b53SJoel DahlDebugging information.
6803edc2b53SJoel DahlVarious name spaces exist under
6813edc2b53SJoel Dahl.Va debug .
6823edc2b53SJoel Dahl.It Va hw
6833edc2b53SJoel DahlHardware and device driver information.
6843edc2b53SJoel Dahl.It Va kern
6853edc2b53SJoel DahlKernel behavior tuning; generally deprecated in favor of more specific
6863edc2b53SJoel Dahlname spaces.
6873edc2b53SJoel Dahl.It Va machdep
6883edc2b53SJoel DahlMachine-dependent configuration parameters.
6893edc2b53SJoel Dahl.It Va net
6903edc2b53SJoel DahlNetwork subsystem.
6913edc2b53SJoel DahlVarious protocols have name spaces under
6923edc2b53SJoel Dahl.Va net .
6933edc2b53SJoel Dahl.It Va regression
6943edc2b53SJoel DahlRegression test configuration and information.
6953edc2b53SJoel Dahl.It Va security
6963edc2b53SJoel DahlSecurity and security-policy configuration and information.
6973edc2b53SJoel Dahl.It Va sysctl
6983edc2b53SJoel DahlReserved name space for the implementation of sysctl.
6993edc2b53SJoel Dahl.It Va user
7003edc2b53SJoel DahlConfiguration settings relating to user application behavior.
7013edc2b53SJoel DahlGenerally, configuring applications using kernel sysctls is discouraged.
7023edc2b53SJoel Dahl.It Va vfs
7033edc2b53SJoel DahlVirtual file system configuration and information.
7043edc2b53SJoel Dahl.It Va vm
7053edc2b53SJoel DahlVirtual memory subsystem configuration and information.
7063edc2b53SJoel Dahl.El
707