xref: /freebsd/share/man/man9/sysctl.9 (revision 574b98cbd9a9a3b59e5b272f3dce5e54bc2e8939)
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*574b98cbSJohn Baldwin.Dd June 11, 2019
29dba9e9ccSRobert Watson.Dt SYSCTL 9
30dba9e9ccSRobert Watson.Os
31dba9e9ccSRobert Watson.Sh NAME
32dba9e9ccSRobert Watson.Nm SYSCTL_DECL ,
339a593520SMateusz Piotrowski.Nm SYSCTL_ADD_BOOL ,
349a593520SMateusz Piotrowski.Nm SYSCTL_ADD_COUNTER_U64 ,
359a593520SMateusz Piotrowski.Nm SYSCTL_ADD_COUNTER_U64_ARRAY ,
365eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_INT ,
375eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_LONG ,
385eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_NODE ,
391e1f3941SEd Schouten.Nm SYSCTL_ADD_NODE_WITH_LABEL ,
405eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_OPAQUE ,
415eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_PROC ,
425eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_QUAD ,
435eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_ROOT_NODE ,
44be87839eSConrad Meyer.Nm SYSCTL_ADD_S8 ,
45be87839eSConrad Meyer.Nm SYSCTL_ADD_S16 ,
46be87839eSConrad Meyer.Nm SYSCTL_ADD_S32 ,
47be87839eSConrad Meyer.Nm SYSCTL_ADD_S64 ,
489a593520SMateusz Piotrowski.Nm SYSCTL_ADD_SBINTIME_MSEC ,
499a593520SMateusz Piotrowski.Nm SYSCTL_ADD_SBINTIME_USEC ,
505eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_STRING ,
5110a1e981SEric Joyner.Nm SYSCTL_ADD_CONST_STRING ,
525eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_STRUCT ,
53fb61390cSConrad Meyer.Nm SYSCTL_ADD_U8 ,
54fb61390cSConrad Meyer.Nm SYSCTL_ADD_U16 ,
55be87839eSConrad Meyer.Nm SYSCTL_ADD_U32 ,
56be87839eSConrad Meyer.Nm SYSCTL_ADD_U64 ,
57f0188618SHans Petter Selasky.Nm SYSCTL_ADD_UAUTO ,
585eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_UINT ,
595eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_ULONG ,
605eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_UQUAD ,
619a593520SMateusz Piotrowski.Nm SYSCTL_ADD_UMA_CUR ,
629a593520SMateusz Piotrowski.Nm SYSCTL_ADD_UMA_MAX ,
635eb1caa8SHans Petter Selasky.Nm SYSCTL_CHILDREN ,
645eb1caa8SHans Petter Selasky.Nm SYSCTL_STATIC_CHILDREN ,
655eb1caa8SHans Petter Selasky.Nm SYSCTL_NODE_CHILDREN ,
665eb1caa8SHans Petter Selasky.Nm SYSCTL_PARENT ,
679a593520SMateusz Piotrowski.Nm SYSCTL_BOOL ,
689a593520SMateusz Piotrowski.Nm SYSCTL_COUNTER_U64 ,
699a593520SMateusz Piotrowski.Nm SYSCTL_COUNTER_U64_ARRAY ,
70dba9e9ccSRobert Watson.Nm SYSCTL_INT ,
711e1f3941SEd Schouten.Nm SYSCTL_INT_WITH_LABEL ,
72dba9e9ccSRobert Watson.Nm SYSCTL_LONG ,
73*574b98cbSJohn Baldwin.Nm sysctl_msec_to_ticks ,
74dba9e9ccSRobert Watson.Nm SYSCTL_NODE ,
751e1f3941SEd Schouten.Nm SYSCTL_NODE_WITH_LABEL ,
76dba9e9ccSRobert Watson.Nm SYSCTL_OPAQUE ,
77dba9e9ccSRobert Watson.Nm SYSCTL_PROC ,
7860a77442SJohn Baldwin.Nm SYSCTL_QUAD ,
795eb1caa8SHans Petter Selasky.Nm SYSCTL_ROOT_NODE ,
80be87839eSConrad Meyer.Nm SYSCTL_S8 ,
81be87839eSConrad Meyer.Nm SYSCTL_S16 ,
82be87839eSConrad Meyer.Nm SYSCTL_S32 ,
83be87839eSConrad Meyer.Nm SYSCTL_S64 ,
849a593520SMateusz Piotrowski.Nm SYSCTL_SBINTIME_MSEC ,
859a593520SMateusz Piotrowski.Nm SYSCTL_SBINTIME_USEC ,
86dba9e9ccSRobert Watson.Nm SYSCTL_STRING ,
8710a1e981SEric Joyner.Nm SYSCTL_CONST_STRING ,
88dba9e9ccSRobert Watson.Nm SYSCTL_STRUCT ,
89fb61390cSConrad Meyer.Nm SYSCTL_U8 ,
90fb61390cSConrad Meyer.Nm SYSCTL_U16 ,
91be87839eSConrad Meyer.Nm SYSCTL_U32 ,
92be87839eSConrad Meyer.Nm SYSCTL_U64 ,
93dba9e9ccSRobert Watson.Nm SYSCTL_UINT ,
94c157a036SDavid E. O'Brien.Nm SYSCTL_ULONG ,
959a593520SMateusz Piotrowski.Nm SYSCTL_UQUAD ,
969a593520SMateusz Piotrowski.Nm SYSCTL_UMA_CUR ,
979a593520SMateusz Piotrowski.Nm SYSCTL_UMA_MAX
985eb1caa8SHans Petter Selasky.Nd Dynamic and static sysctl MIB creation functions
99dba9e9ccSRobert Watson.Sh SYNOPSIS
100651a7908SJonathan T. Looney.In sys/param.h
101dba9e9ccSRobert Watson.In sys/sysctl.h
102bd84dd2fSRuslan Ermilov.Fn SYSCTL_DECL name
1035eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
1049a593520SMateusz Piotrowski.Fo SYSCTL_ADD_BOOL
1059a593520SMateusz Piotrowski.Fa "struct sysctl_ctx_list *ctx"
1069a593520SMateusz Piotrowski.Fa "struct sysctl_oid_list *parent"
1079a593520SMateusz Piotrowski.Fa "int number"
1089a593520SMateusz Piotrowski.Fa "const char *name"
1099a593520SMateusz Piotrowski.Fa "int ctlflags"
1109a593520SMateusz Piotrowski.Fa "bool *ptr"
1119a593520SMateusz Piotrowski.Fa "uint8_t val"
1129a593520SMateusz Piotrowski.Fa "const char *descr"
1139a593520SMateusz Piotrowski.Fc
1149a593520SMateusz Piotrowski.Ft struct sysctl_oid *
1159a593520SMateusz Piotrowski.Fo SYSCTL_ADD_COUNTER_U64
1169a593520SMateusz Piotrowski.Fa "struct sysctl_ctx_list *ctx"
1179a593520SMateusz Piotrowski.Fa "struct sysctl_oid_list *parent"
1189a593520SMateusz Piotrowski.Fa "int number"
1199a593520SMateusz Piotrowski.Fa "const char *name"
1209a593520SMateusz Piotrowski.Fa "int ctlflags"
1219a593520SMateusz Piotrowski.Fa "counter_u64_t *ptr"
1229a593520SMateusz Piotrowski.Fa "const char *descr"
1239a593520SMateusz Piotrowski.Fc
1249a593520SMateusz Piotrowski.Ft struct sysctl_oid *
1259a593520SMateusz Piotrowski.Fo SYSCTL_ADD_COUNTER_U64_ARRAY
1269a593520SMateusz Piotrowski.Fa "struct sysctl_ctx_list *ctx"
1279a593520SMateusz Piotrowski.Fa "struct sysctl_oid_list *parent"
1289a593520SMateusz Piotrowski.Fa "int number"
1299a593520SMateusz Piotrowski.Fa "const char *name"
1309a593520SMateusz Piotrowski.Fa "int ctlflags"
1319a593520SMateusz Piotrowski.Fa "counter_u64_t *ptr"
1329a593520SMateusz Piotrowski.Fa "intmax_t len"
1339a593520SMateusz Piotrowski.Fa "const char *descr"
1349a593520SMateusz Piotrowski.Fc
1359a593520SMateusz Piotrowski.Ft struct sysctl_oid *
1365eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_INT
1375eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
1385eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
1395eb1caa8SHans Petter Selasky.Fa "int number"
1405eb1caa8SHans Petter Selasky.Fa "const char *name"
1415eb1caa8SHans Petter Selasky.Fa "int ctlflags"
1425eb1caa8SHans Petter Selasky.Fa "int *ptr"
143be87839eSConrad Meyer.Fa "int val"
1445eb1caa8SHans Petter Selasky.Fa "const char *descr"
1455eb1caa8SHans Petter Selasky.Fc
1465eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
1475eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_LONG
1485eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
1495eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
1505eb1caa8SHans Petter Selasky.Fa "int number"
1515eb1caa8SHans Petter Selasky.Fa "const char *name"
1525eb1caa8SHans Petter Selasky.Fa "int ctlflags"
1535eb1caa8SHans Petter Selasky.Fa "long *ptr"
1545eb1caa8SHans Petter Selasky.Fa "const char *descr"
1555eb1caa8SHans Petter Selasky.Fc
1565eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
1575eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_NODE
1585eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
1595eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
1605eb1caa8SHans Petter Selasky.Fa "int number"
1615eb1caa8SHans Petter Selasky.Fa "const char *name"
1625eb1caa8SHans Petter Selasky.Fa "int ctlflags"
1635eb1caa8SHans Petter Selasky.Fa "int (*handler)(SYSCTL_HANDLER_ARGS)"
1645eb1caa8SHans Petter Selasky.Fa "const char *descr"
1655eb1caa8SHans Petter Selasky.Fc
1665eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
1671e1f3941SEd Schouten.Fo SYSCTL_ADD_NODE_WITH_LABEL
1681e1f3941SEd Schouten.Fa "struct sysctl_ctx_list *ctx"
1691e1f3941SEd Schouten.Fa "struct sysctl_oid_list *parent"
1701e1f3941SEd Schouten.Fa "int number"
1711e1f3941SEd Schouten.Fa "const char *name"
1721e1f3941SEd Schouten.Fa "int ctlflags"
1731e1f3941SEd Schouten.Fa "int (*handler)(SYSCTL_HANDLER_ARGS)"
1741e1f3941SEd Schouten.Fa "const char *descr"
1751e1f3941SEd Schouten.Fa "const char *label"
1761e1f3941SEd Schouten.Fc
1771e1f3941SEd Schouten.Ft struct sysctl_oid *
1785eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_OPAQUE
1795eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
1805eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
1815eb1caa8SHans Petter Selasky.Fa "int number"
1825eb1caa8SHans Petter Selasky.Fa "const char *name"
1835eb1caa8SHans Petter Selasky.Fa "int ctlflags"
1845eb1caa8SHans Petter Selasky.Fa "void *ptr"
1855eb1caa8SHans Petter Selasky.Fa "intptr_t len"
1865eb1caa8SHans Petter Selasky.Fa "const char *format"
1873edc2b53SJoel Dahl.Fa "const char *descr"
1885eb1caa8SHans Petter Selasky.Fc
1895eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
1905eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_PROC
1915eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
1925eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
1935eb1caa8SHans Petter Selasky.Fa "int number"
1945eb1caa8SHans Petter Selasky.Fa "const char *name"
1955eb1caa8SHans Petter Selasky.Fa "int ctlflags"
1965eb1caa8SHans Petter Selasky.Fa "void *arg1"
1975eb1caa8SHans Petter Selasky.Fa "intptr_t arg2"
198ba9a5309SAndriy Voskoboinyk.Fa "int (*handler) (SYSCTL_HANDLER_ARGS)"
1995eb1caa8SHans Petter Selasky.Fa "const char *format"
2005eb1caa8SHans Petter Selasky.Fa "const char *descr"
2015eb1caa8SHans Petter Selasky.Fc
2025eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
2035eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_QUAD
2045eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
2055eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
2065eb1caa8SHans Petter Selasky.Fa "int number"
2075eb1caa8SHans Petter Selasky.Fa "const char *name"
2085eb1caa8SHans Petter Selasky.Fa "int ctlflags"
209be87839eSConrad Meyer.Fa "int64_t *ptr"
2105eb1caa8SHans Petter Selasky.Fa "const char *descr"
2115eb1caa8SHans Petter Selasky.Fc
2125eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
2135eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_ROOT_NODE
2145eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
2155eb1caa8SHans Petter Selasky.Fa "int number"
2165eb1caa8SHans Petter Selasky.Fa "const char *name"
2175eb1caa8SHans Petter Selasky.Fa "int ctlflags"
2185eb1caa8SHans Petter Selasky.Fa "int (*handler)(SYSCTL_HANDLER_ARGS)"
2195eb1caa8SHans Petter Selasky.Fa "const char *descr"
2205eb1caa8SHans Petter Selasky.Fc
2215eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
222be87839eSConrad Meyer.Fo SYSCTL_ADD_S8
223be87839eSConrad Meyer.Fa "struct sysctl_ctx_list *ctx"
224be87839eSConrad Meyer.Fa "struct sysctl_oid_list *parent"
225be87839eSConrad Meyer.Fa "int number"
226be87839eSConrad Meyer.Fa "const char *name"
227be87839eSConrad Meyer.Fa "int ctlflags"
228be87839eSConrad Meyer.Fa "int8_t *ptr"
229be87839eSConrad Meyer.Fa "int8_t val"
230be87839eSConrad Meyer.Fa "const char *descr"
231be87839eSConrad Meyer.Fc
232be87839eSConrad Meyer.Ft struct sysctl_oid *
233be87839eSConrad Meyer.Fo SYSCTL_ADD_S16
234be87839eSConrad Meyer.Fa "struct sysctl_ctx_list *ctx"
235be87839eSConrad Meyer.Fa "struct sysctl_oid_list *parent"
236be87839eSConrad Meyer.Fa "int number"
237be87839eSConrad Meyer.Fa "const char *name"
238be87839eSConrad Meyer.Fa "int ctlflags"
239be87839eSConrad Meyer.Fa "int16_t *ptr"
240be87839eSConrad Meyer.Fa "int16_t val"
241be87839eSConrad Meyer.Fa "const char *descr"
242be87839eSConrad Meyer.Fc
243be87839eSConrad Meyer.Ft struct sysctl_oid *
244be87839eSConrad Meyer.Fo SYSCTL_ADD_S32
245be87839eSConrad Meyer.Fa "struct sysctl_ctx_list *ctx"
246be87839eSConrad Meyer.Fa "struct sysctl_oid_list *parent"
247be87839eSConrad Meyer.Fa "int number"
248be87839eSConrad Meyer.Fa "const char *name"
249be87839eSConrad Meyer.Fa "int ctlflags"
250be87839eSConrad Meyer.Fa "int32_t *ptr"
251be87839eSConrad Meyer.Fa "int32_t val"
252be87839eSConrad Meyer.Fa "const char *descr"
253be87839eSConrad Meyer.Fc
254be87839eSConrad Meyer.Ft struct sysctl_oid *
255be87839eSConrad Meyer.Fo SYSCTL_ADD_S64
256be87839eSConrad Meyer.Fa "struct sysctl_ctx_list *ctx"
257be87839eSConrad Meyer.Fa "struct sysctl_oid_list *parent"
258be87839eSConrad Meyer.Fa "int number"
259be87839eSConrad Meyer.Fa "const char *name"
260be87839eSConrad Meyer.Fa "int ctlflags"
261be87839eSConrad Meyer.Fa "int64_t *ptr"
262be87839eSConrad Meyer.Fa "int64_t val"
263be87839eSConrad Meyer.Fa "const char *descr"
264be87839eSConrad Meyer.Fc
265be87839eSConrad Meyer.Ft struct sysctl_oid *
2669a593520SMateusz Piotrowski.Fo SYSCTL_ADD_SBINTIME_MSEC
2679a593520SMateusz Piotrowski.Fa "struct sysctl_ctx_list *ctx"
2689a593520SMateusz Piotrowski.Fa "struct sysctl_oid_list *parent"
2699a593520SMateusz Piotrowski.Fa "int number"
2709a593520SMateusz Piotrowski.Fa "const char *name"
2719a593520SMateusz Piotrowski.Fa "int ctlflags"
2729a593520SMateusz Piotrowski.Fa "sbintime_t *ptr"
2739a593520SMateusz Piotrowski.Fa "const char *descr"
2749a593520SMateusz Piotrowski.Fc
2759a593520SMateusz Piotrowski.Ft struct sysctl_oid *
2769a593520SMateusz Piotrowski.Fo SYSCTL_ADD_SBINTIME_USEC
2779a593520SMateusz Piotrowski.Fa "struct sysctl_ctx_list *ctx"
2789a593520SMateusz Piotrowski.Fa "struct sysctl_oid_list *parent"
2799a593520SMateusz Piotrowski.Fa "int number"
2809a593520SMateusz Piotrowski.Fa "const char *name"
2819a593520SMateusz Piotrowski.Fa "int ctlflags"
2829a593520SMateusz Piotrowski.Fa "sbintime_t *ptr"
2839a593520SMateusz Piotrowski.Fa "const char *descr"
2849a593520SMateusz Piotrowski.Fc
2859a593520SMateusz Piotrowski.Ft struct sysctl_oid *
2865eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_STRING
2875eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
2885eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
2895eb1caa8SHans Petter Selasky.Fa "int number"
2905eb1caa8SHans Petter Selasky.Fa "const char *name"
2915eb1caa8SHans Petter Selasky.Fa "int ctlflags"
2925eb1caa8SHans Petter Selasky.Fa "char *ptr"
2935eb1caa8SHans Petter Selasky.Fa "intptr_t len"
2945eb1caa8SHans Petter Selasky.Fa "const char *descr"
2955eb1caa8SHans Petter Selasky.Fc
2965eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
29710a1e981SEric Joyner.Fo SYSCTL_ADD_CONST_STRING
29810a1e981SEric Joyner.Fa "struct sysctl_ctx_list *ctx"
29910a1e981SEric Joyner.Fa "struct sysctl_oid_list *parent"
30010a1e981SEric Joyner.Fa "int number"
30110a1e981SEric Joyner.Fa "const char *name"
30210a1e981SEric Joyner.Fa "int ctlflags"
30310a1e981SEric Joyner.Fa "const char *ptr"
30410a1e981SEric Joyner.Fa "const char *descr"
30510a1e981SEric Joyner.Fc
30610a1e981SEric Joyner.Ft struct sysctl_oid *
3075eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_STRUCT
3085eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
3095eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
3105eb1caa8SHans Petter Selasky.Fa "int number"
3115eb1caa8SHans Petter Selasky.Fa "const char *name"
3125eb1caa8SHans Petter Selasky.Fa "int ctlflags"
3135eb1caa8SHans Petter Selasky.Fa "void *ptr"
3145eb1caa8SHans Petter Selasky.Fa struct_type
3155eb1caa8SHans Petter Selasky.Fa "const char *descr"
3165eb1caa8SHans Petter Selasky.Fc
3175eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
318fb61390cSConrad Meyer.Fo SYSCTL_ADD_U8
319fb61390cSConrad Meyer.Fa "struct sysctl_ctx_list *ctx"
320fb61390cSConrad Meyer.Fa "struct sysctl_oid_list *parent"
321fb61390cSConrad Meyer.Fa "int number"
322fb61390cSConrad Meyer.Fa "const char *name"
323fb61390cSConrad Meyer.Fa "int ctlflags"
324be87839eSConrad Meyer.Fa "uint8_t *ptr"
325be87839eSConrad Meyer.Fa "uint8_t val"
326fb61390cSConrad Meyer.Fa "const char *descr"
327fb61390cSConrad Meyer.Fc
328fb61390cSConrad Meyer.Ft struct sysctl_oid *
329fb61390cSConrad Meyer.Fo SYSCTL_ADD_U16
330fb61390cSConrad Meyer.Fa "struct sysctl_ctx_list *ctx"
331fb61390cSConrad Meyer.Fa "struct sysctl_oid_list *parent"
332fb61390cSConrad Meyer.Fa "int number"
333fb61390cSConrad Meyer.Fa "const char *name"
334fb61390cSConrad Meyer.Fa "int ctlflags"
335be87839eSConrad Meyer.Fa "uint16_t *ptr"
336be87839eSConrad Meyer.Fa "uint16_t val"
337be87839eSConrad Meyer.Fa "const char *descr"
338be87839eSConrad Meyer.Fc
339be87839eSConrad Meyer.Ft struct sysctl_oid *
340be87839eSConrad Meyer.Fo SYSCTL_ADD_U32
341be87839eSConrad Meyer.Fa "struct sysctl_ctx_list *ctx"
342be87839eSConrad Meyer.Fa "struct sysctl_oid_list *parent"
343be87839eSConrad Meyer.Fa "int number"
344be87839eSConrad Meyer.Fa "const char *name"
345be87839eSConrad Meyer.Fa "int ctlflags"
346be87839eSConrad Meyer.Fa "uint32_t *ptr"
347be87839eSConrad Meyer.Fa "uint32_t val"
348be87839eSConrad Meyer.Fa "const char *descr"
349be87839eSConrad Meyer.Fc
350be87839eSConrad Meyer.Ft struct sysctl_oid *
351be87839eSConrad Meyer.Fo SYSCTL_ADD_U64
352be87839eSConrad Meyer.Fa "struct sysctl_ctx_list *ctx"
353be87839eSConrad Meyer.Fa "struct sysctl_oid_list *parent"
354be87839eSConrad Meyer.Fa "int number"
355be87839eSConrad Meyer.Fa "const char *name"
356be87839eSConrad Meyer.Fa "int ctlflags"
357be87839eSConrad Meyer.Fa "uint64_t *ptr"
358be87839eSConrad Meyer.Fa "uint64_t val"
359fb61390cSConrad Meyer.Fa "const char *descr"
360fb61390cSConrad Meyer.Fc
361fb61390cSConrad Meyer.Ft struct sysctl_oid *
3625eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_UINT
3635eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
3645eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
3655eb1caa8SHans Petter Selasky.Fa "int number"
3665eb1caa8SHans Petter Selasky.Fa "const char *name"
3675eb1caa8SHans Petter Selasky.Fa "int ctlflags"
3685eb1caa8SHans Petter Selasky.Fa "unsigned int *ptr"
369be87839eSConrad Meyer.Fa "unsigned int val"
3705eb1caa8SHans Petter Selasky.Fa "const char *descr"
3715eb1caa8SHans Petter Selasky.Fc
3725eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
3735eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_ULONG
3745eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
3755eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
3765eb1caa8SHans Petter Selasky.Fa "int number"
3775eb1caa8SHans Petter Selasky.Fa "const char *name"
3785eb1caa8SHans Petter Selasky.Fa "int ctlflags"
3795eb1caa8SHans Petter Selasky.Fa "unsigned long *ptr"
3805eb1caa8SHans Petter Selasky.Fa "const char *descr"
3815eb1caa8SHans Petter Selasky.Fc
3825eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
3835eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_UQUAD
3845eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
3855eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
3865eb1caa8SHans Petter Selasky.Fa "int number"
3875eb1caa8SHans Petter Selasky.Fa "const char *name"
3885eb1caa8SHans Petter Selasky.Fa "int ctlflags"
389be87839eSConrad Meyer.Fa "uint64_t *ptr"
390f0188618SHans Petter Selasky.Fa "const char *descr"
391f0188618SHans Petter Selasky.Fc
392f0188618SHans Petter Selasky.Ft struct sysctl_oid *
3939a593520SMateusz Piotrowski.Fo SYSCTL_ADD_UMA_CUR
3949a593520SMateusz Piotrowski.Fa "struct sysctl_ctx_list *ctx"
3959a593520SMateusz Piotrowski.Fa "struct sysctl_oid_list *parent"
3969a593520SMateusz Piotrowski.Fa "int number"
3979a593520SMateusz Piotrowski.Fa "const char *name"
3989a593520SMateusz Piotrowski.Fa "int ctlflags"
3999a593520SMateusz Piotrowski.Fa "uma_zone_t ptr"
4009a593520SMateusz Piotrowski.Fa "const char *descr"
4019a593520SMateusz Piotrowski.Fc
4029a593520SMateusz Piotrowski.Ft struct sysctl_oid *
4039a593520SMateusz Piotrowski.Fo SYSCTL_ADD_UMA_MAX
4049a593520SMateusz Piotrowski.Fa "struct sysctl_ctx_list *ctx"
4059a593520SMateusz Piotrowski.Fa "struct sysctl_oid_list *parent"
4069a593520SMateusz Piotrowski.Fa "int number"
4079a593520SMateusz Piotrowski.Fa "const char *name"
4089a593520SMateusz Piotrowski.Fa "int ctlflags"
4099a593520SMateusz Piotrowski.Fa "uma_zone_t ptr"
4109a593520SMateusz Piotrowski.Fa "const char *descr"
4119a593520SMateusz Piotrowski.Fc
4129a593520SMateusz Piotrowski.Fa "const char *descr"
4139a593520SMateusz Piotrowski.Ft struct sysctl_oid *
414f0188618SHans Petter Selasky.Fo SYSCTL_ADD_UAUTO
415f0188618SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
416f0188618SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
417f0188618SHans Petter Selasky.Fa "int number"
418f0188618SHans Petter Selasky.Fa "const char *name"
419f0188618SHans Petter Selasky.Fa "int ctlflags"
420f0188618SHans Petter Selasky.Fa "void *ptr"
4215eb1caa8SHans Petter Selasky.Fa "const char *descr"
4225eb1caa8SHans Petter Selasky.Fc
4235eb1caa8SHans Petter Selasky.Ft struct sysctl_oid_list *
4245eb1caa8SHans Petter Selasky.Fo SYSCTL_CHILDREN
4255eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid *oidp"
4265eb1caa8SHans Petter Selasky.Fc
4275eb1caa8SHans Petter Selasky.Ft struct sysctl_oid_list *
4285eb1caa8SHans Petter Selasky.Fo SYSCTL_STATIC_CHILDREN
4295eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list OID_NAME"
4305eb1caa8SHans Petter Selasky.Fc
4315eb1caa8SHans Petter Selasky.Ft struct sysctl_oid_list *
4325eb1caa8SHans Petter Selasky.Fo SYSCTL_NODE_CHILDREN
4335eb1caa8SHans Petter Selasky.Fa "parent"
4345eb1caa8SHans Petter Selasky.Fa "name"
4355eb1caa8SHans Petter Selasky.Fc
4365eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
4375eb1caa8SHans Petter Selasky.Fo SYSCTL_PARENT
4385eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid *oid"
4395eb1caa8SHans Petter Selasky.Fc
4409a593520SMateusz Piotrowski.Fn SYSCTL_BOOL parent number name ctlflags ptr val descr
4419a593520SMateusz Piotrowski.Fn SYSCTL_COUNTER_U64 parent number name ctlflags ptr descr
4429a593520SMateusz Piotrowski.Fn SYSCTL_COUNTER_U64_ARRAY parent number name ctlflags ptr len descr
4435eb1caa8SHans Petter Selasky.Fn SYSCTL_INT parent number name ctlflags ptr val descr
4441e1f3941SEd Schouten.Fn SYSCTL_INT_WITH_LABEL parent number name ctlflags ptr val descr label
4455eb1caa8SHans Petter Selasky.Fn SYSCTL_LONG parent number name ctlflags ptr val descr
446*574b98cbSJohn Baldwin.Ft int
447*574b98cbSJohn Baldwin.Fn sysctl_msec_to_ticks SYSCTL_HANDLER_ARGS
4485eb1caa8SHans Petter Selasky.Fn SYSCTL_NODE parent number name ctlflags handler descr
4491e1f3941SEd Schouten.Fn SYSCTL_NODE_WITH_LABEL parent number name ctlflags handler descr label
4505eb1caa8SHans Petter Selasky.Fn SYSCTL_OPAQUE parent number name ctlflags ptr len format descr
4515eb1caa8SHans Petter Selasky.Fn SYSCTL_PROC parent number name ctlflags arg1 arg2 handler format descr
4525eb1caa8SHans Petter Selasky.Fn SYSCTL_QUAD parent number name ctlflags ptr val descr
453be87839eSConrad Meyer.Fn SYSCTL_ROOT_NODE number name ctlflags handler descr
454be87839eSConrad Meyer.Fn SYSCTL_S8 parent number name ctlflags ptr val descr
455be87839eSConrad Meyer.Fn SYSCTL_S16 parent number name ctlflags ptr val descr
456be87839eSConrad Meyer.Fn SYSCTL_S32 parent number name ctlflags ptr val descr
457be87839eSConrad Meyer.Fn SYSCTL_S64 parent number name ctlflags ptr val descr
4589a593520SMateusz Piotrowski.Fn SYSCTL_SBINTIME_MSEC parent number name ctlflags ptr descr
4599a593520SMateusz Piotrowski.Fn SYSCTL_SBINTIME_USEC parent number name ctlflags ptr descr
4605eb1caa8SHans Petter Selasky.Fn SYSCTL_STRING parent number name ctlflags arg len descr
46110a1e981SEric Joyner.Fn SYSCTL_CONST_STRING parent number name ctlflags arg descr
4625eb1caa8SHans Petter Selasky.Fn SYSCTL_STRUCT parent number name ctlflags ptr struct_type descr
463fb61390cSConrad Meyer.Fn SYSCTL_U8 parent number name ctlflags ptr val descr
464fb61390cSConrad Meyer.Fn SYSCTL_U16 parent number name ctlflags ptr val descr
465be87839eSConrad Meyer.Fn SYSCTL_U32 parent number name ctlflags ptr val descr
466be87839eSConrad Meyer.Fn SYSCTL_U64 parent number name ctlflags ptr val descr
4675eb1caa8SHans Petter Selasky.Fn SYSCTL_UINT parent number name ctlflags ptr val descr
4685eb1caa8SHans Petter Selasky.Fn SYSCTL_ULONG parent number name ctlflags ptr val descr
4695eb1caa8SHans Petter Selasky.Fn SYSCTL_UQUAD parent number name ctlflags ptr val descr
4709a593520SMateusz Piotrowski.Fn SYSCTL_UMA_MAX parent number name ctlflags ptr descr
4719a593520SMateusz Piotrowski.Fn SYSCTL_UMA_CUR parent number name ctlflags ptr descr
472*574b98cbSJohn Baldwin
473dba9e9ccSRobert Watson.Sh DESCRIPTION
474dba9e9ccSRobert WatsonThe
475bd84dd2fSRuslan Ermilov.Nm SYSCTL
4765eb1caa8SHans Petter Selaskykernel interface allows dynamic or static creation of
477dba9e9ccSRobert Watson.Xr sysctl 8
4785eb1caa8SHans Petter SelaskyMIB entries.
4795eb1caa8SHans Petter SelaskyAll static sysctls are automatically destroyed when the module which
4805eb1caa8SHans Petter Selaskythey are part of is unloaded.
4815eb1caa8SHans Petter SelaskyMost top level categories are created statically and are available to
4825eb1caa8SHans Petter Selaskyall kernel code and its modules.
4835eb1caa8SHans Petter Selasky.Sh DESCRIPTION OF ARGUMENTS
4845eb1caa8SHans Petter Selasky.Bl -tag -width ctlflags
4855eb1caa8SHans Petter Selasky.It Fa ctx
4865eb1caa8SHans Petter SelaskyPointer to sysctl context or NULL, if no context.
4875eb1caa8SHans Petter SelaskySee
4885eb1caa8SHans Petter Selasky.Xr sysctl_ctx_init 9
4895eb1caa8SHans Petter Selaskyfor how to create a new sysctl context.
4905eb1caa8SHans Petter SelaskyProgrammers are strongly advised to use contexts to organize the
4915eb1caa8SHans Petter Selaskydynamic OIDs which they create because when a context is destroyed all
4925eb1caa8SHans Petter Selaskybelonging sysctls are destroyed as well.
4935eb1caa8SHans Petter SelaskyThis makes the sysctl cleanup code much simpler.
494aa88ccabSHans Petter SelaskyElse deletion of all created OIDs is required at module unload.
4955eb1caa8SHans Petter Selasky.It Fa parent
4965eb1caa8SHans Petter SelaskyA pointer to a
4975eb1caa8SHans Petter Selasky.Li struct sysctl_oid_list ,
4985eb1caa8SHans Petter Selaskywhich is the head of the parent's list of children.
499aa88ccabSHans Petter SelaskyThis pointer is retrieved using the
5005eb1caa8SHans Petter Selasky.Fn SYSCTL_STATIC_CHILDREN
5015eb1caa8SHans Petter Selaskymacro for static sysctls and the
5025eb1caa8SHans Petter Selasky.Fn SYSCTL_CHILDREN
5035eb1caa8SHans Petter Selaskymacro for dynamic sysctls.
504aa88ccabSHans Petter SelaskyThe
5055eb1caa8SHans Petter Selasky.Fn SYSCTL_PARENT
506aa88ccabSHans Petter Selaskymacro can be used to get the parent of an OID.
507aa88ccabSHans Petter SelaskyThe macro returns NULL if there is no parent.
5085eb1caa8SHans Petter Selasky.It Fa number
5095eb1caa8SHans Petter SelaskyThe OID number that will be assigned to this OID.
5105eb1caa8SHans Petter SelaskyIn almost all cases this should be set to
5115eb1caa8SHans Petter Selasky.Dv OID_AUTO ,
5125eb1caa8SHans Petter Selaskywhich will result in the assignment of the next available OID number.
5135eb1caa8SHans Petter Selasky.It Fa name
5145eb1caa8SHans Petter SelaskyThe name of the OID.
5155eb1caa8SHans Petter SelaskyThe newly created OID will contain a copy of the name.
5165eb1caa8SHans Petter Selasky.It Fa ctlflags
5175eb1caa8SHans Petter SelaskyA bit mask of sysctl control flags.
5185eb1caa8SHans Petter SelaskySee the section below describing all the control flags.
5195eb1caa8SHans Petter Selasky.It Fa arg1
5205eb1caa8SHans Petter SelaskyFirst callback argument for procedure sysctls.
5215eb1caa8SHans Petter Selasky.It Fa arg2
5225eb1caa8SHans Petter SelaskySecond callback argument for procedure sysctls.
5235eb1caa8SHans Petter Selasky.It Fa len
5245eb1caa8SHans Petter SelaskyThe length of the data pointed to by the
5255eb1caa8SHans Petter Selasky.Fa ptr
5265eb1caa8SHans Petter Selaskyargument.
5275eb1caa8SHans Petter SelaskyFor string type OIDs a length of zero means that
5285eb1caa8SHans Petter Selasky.Xr strlen 3
5295eb1caa8SHans Petter Selaskywill be used to get the length of the string at each access to the OID.
5309a593520SMateusz PiotrowskiFor array type OIDs the length must be greater than zero.
5315eb1caa8SHans Petter Selasky.It Fa ptr
5325eb1caa8SHans Petter SelaskyPointer to sysctl variable or string data.
533f0188618SHans Petter SelaskyFor sysctl values the pointer can be SYSCTL_NULL_XXX_PTR which means the OID is read-only and the returned value should be taken from the
5345eb1caa8SHans Petter Selasky.Fa val
5355eb1caa8SHans Petter Selaskyargument.
5365eb1caa8SHans Petter Selasky.It Fa val
5375eb1caa8SHans Petter SelaskyIf the
5385eb1caa8SHans Petter Selasky.Fa ptr
539f0188618SHans Petter Selaskyargument is SYSCTL_NULL_XXX_PTR, gives the constant value returned by this OID.
5405eb1caa8SHans Petter SelaskyElse this argument is not used.
5415eb1caa8SHans Petter Selasky.It Fa struct_type
5425eb1caa8SHans Petter SelaskyName of structure type.
5435eb1caa8SHans Petter Selasky.It Fa handler
5445eb1caa8SHans Petter SelaskyA pointer to the function
5455eb1caa8SHans Petter Selaskythat is responsible for handling read and write requests
5465eb1caa8SHans Petter Selaskyto this OID.
5475eb1caa8SHans Petter SelaskyThere are several standard handlers
5485eb1caa8SHans Petter Selaskythat support operations on nodes,
5495eb1caa8SHans Petter Selaskyintegers, strings and opaque objects.
5505eb1caa8SHans Petter SelaskyIt is possible to define custom handlers using the
5515eb1caa8SHans Petter Selasky.Fn SYSCTL_PROC
5525eb1caa8SHans Petter Selaskymacro or the
5535eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_PROC
5545eb1caa8SHans Petter Selaskyfunction.
5555eb1caa8SHans Petter Selasky.It Fa format
5565eb1caa8SHans Petter SelaskyA pointer to a string
5575eb1caa8SHans Petter Selaskywhich specifies the format of the OID in a symbolic way.
5585eb1caa8SHans Petter SelaskyThis format is used as a hint by
5595eb1caa8SHans Petter Selasky.Xr sysctl 8
5605eb1caa8SHans Petter Selaskyto apply proper data formatting for display purposes.
561aa255ef6SWarner Losh.Pp
562aa255ef6SWarner LoshCurrent formats:
563aa255ef6SWarner Losh.Bl -tag -width "S,TYPE" -compact -offset indent
564aa255ef6SWarner Losh.It Cm N
565aa255ef6SWarner Loshnode
566aa255ef6SWarner Losh.It Cm A
567aa255ef6SWarner Losh.Li "char *"
568aa255ef6SWarner Losh.It Cm I
569aa255ef6SWarner Losh.Li "int"
570aa255ef6SWarner Losh.It Cm IK Ns Op Ar n
571aa255ef6SWarner Loshtemperature in Kelvin, multiplied by an optional single digit
572aa255ef6SWarner Loshpower of ten scaling factor: 1 (default) gives deciKelvin, 0 gives Kelvin, 3
573aa255ef6SWarner Loshgives milliKelvin
574aa255ef6SWarner Losh.It Cm IU
575aa255ef6SWarner Losh.Li "unsigned int"
576aa255ef6SWarner Losh.It Cm L
577aa255ef6SWarner Losh.Li "long"
578aa255ef6SWarner Losh.It Cm LU
579aa255ef6SWarner Losh.Li "unsigned long"
580aa255ef6SWarner Losh.It Cm Q
581aa255ef6SWarner Losh.Li "quad_t"
582aa255ef6SWarner Losh.It Cm QU
5835eb1caa8SHans Petter Selasky.Li "u_quad_t"
584aa255ef6SWarner Losh.It Cm "S,TYPE"
5855eb1caa8SHans Petter Selasky.Li "struct TYPE"
586aa255ef6SWarner Loshstructures
587aa255ef6SWarner Losh.El
5885eb1caa8SHans Petter Selasky.It Fa descr
5895eb1caa8SHans Petter SelaskyA pointer to a textual description of the OID.
5901e1f3941SEd Schouten.It Fa label
5911e1f3941SEd SchoutenA pointer to an aggregation label for this component of the OID.
5921e1f3941SEd SchoutenTo make it easier to export sysctl data to monitoring systems that
5931e1f3941SEd Schoutensupport aggregations through labels (e.g., Prometheus),
5941e1f3941SEd Schoutenthis argument can be used to attach a label name to an OID.
5951e1f3941SEd SchoutenThe label acts as a hint that this component's name should not be part
5961e1f3941SEd Schoutenof the metric's name,
5971e1f3941SEd Schoutenbut attached to the metric as a label instead.
5981e1f3941SEd Schouten.Pp
5991e1f3941SEd SchoutenLabels should only be applied to siblings that are structurally similar
6001e1f3941SEd Schoutenand encode the same type of value,
6011e1f3941SEd Schoutenas aggregation is of no use otherwise.
6025eb1caa8SHans Petter Selasky.El
603*574b98cbSJohn Baldwin.Sh NODE VALUE TYPES
604*574b98cbSJohn BaldwinMost of the macros and functions used to create sysctl nodes export a
605*574b98cbSJohn Baldwinread-only constant or in-kernel variable whose type matches the type
606*574b98cbSJohn Baldwinof the node's value.
607*574b98cbSJohn BaldwinFor example,
608*574b98cbSJohn Baldwin.Fn SYSCTL_INT
609*574b98cbSJohn Baldwinreports the raw value of an associated variable of type
610*574b98cbSJohn Baldwin.Vt int .
611*574b98cbSJohn BaldwinHowever, nodes may also export a value that is a translatation of an internal
612*574b98cbSJohn Baldwinrepresentation.
613*574b98cbSJohn Baldwin.Pp
614*574b98cbSJohn BaldwinThe
615*574b98cbSJohn Baldwin.Fn sysctl_msec_to_ticks
616*574b98cbSJohn Baldwinhandler can be used with
617*574b98cbSJohn Baldwin.Fn SYSCTL_PROC
618*574b98cbSJohn Baldwinor
619*574b98cbSJohn Baldwin.Fn SYSCTL_ADD_PROC
620*574b98cbSJohn Baldwinto export a millisecond time interval.
621*574b98cbSJohn BaldwinWhen using this handler,
622*574b98cbSJohn Baldwinthe
623*574b98cbSJohn Baldwin.Fa arg2
624*574b98cbSJohn Baldwinparameter points to an in-kernel variable of type
625*574b98cbSJohn Baldwin.Vt int
626*574b98cbSJohn Baldwinwhich stores a tick count suitable for use with functions like
627*574b98cbSJohn Baldwin.Xr tsleep 9 .
628*574b98cbSJohn BaldwinThe
629*574b98cbSJohn Baldwin.Fn sysctl_msec_to_ticks
630*574b98cbSJohn Baldwinfunction converts this value to milliseconds when reporting the node's value.
631*574b98cbSJohn BaldwinSimilarly,
632*574b98cbSJohn Baldwin.Fn sysctl_msec_to_ticks
633*574b98cbSJohn Baldwinaccepts new values in milliseconds and stores an equivalent value in ticks to
634*574b98cbSJohn Baldwin.Fa *arg2 .
635*574b98cbSJohn BaldwinNote that new code should use kernel variables of type
636*574b98cbSJohn Baldwin.Vt sbintime_t
637*574b98cbSJohn Baldwininstead of tick counts.
638*574b98cbSJohn Baldwin.Pp
639*574b98cbSJohn BaldwinThe
640*574b98cbSJohn Baldwin.Fn SYSCTL_ADD_SBINTIME_MSEC
641*574b98cbSJohn Baldwinand
642*574b98cbSJohn Baldwin.Fn SYSCTL_ADD_SBINTIME_USEC
643*574b98cbSJohn Baldwinfunctions and
644*574b98cbSJohn Baldwin.Fn SYSCTL_SBINTIME_MSEC
645*574b98cbSJohn Baldwinand
646*574b98cbSJohn Baldwin.Fn SYSCTL_SBINTIME_USEC
647*574b98cbSJohn Baldwinmacros all create nodes which export an in-kernel variable of type
648*574b98cbSJohn Baldwin.Vt sbintime_t .
649*574b98cbSJohn BaldwinThese nodes do not export the raw value of the associated variable.
650*574b98cbSJohn BaldwinInstead, they export a 64-bit integer containing a count of either
651*574b98cbSJohn Baldwinmilliseconds (the MSEC variants) or microseconds (the USEC variants).
6525eb1caa8SHans Petter Selasky.Sh CREATING ROOT NODES
6535eb1caa8SHans Petter SelaskySysctl MIBs or OIDs are created in a hierarchical tree.
6545eb1caa8SHans Petter SelaskyThe nodes at the bottom of the tree are called root nodes, and have no
6555eb1caa8SHans Petter Selaskyparent OID.
6565eb1caa8SHans Petter SelaskyTo create bottom tree nodes the
6575eb1caa8SHans Petter Selasky.Fn SYSCTL_ROOT_NODE
6585eb1caa8SHans Petter Selaskymacro or the
6595eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_ROOT_NODE
6605eb1caa8SHans Petter Selaskyfunction needs to be used.
6615eb1caa8SHans Petter SelaskyBy default all static sysctl node OIDs are global and need a
6625eb1caa8SHans Petter Selasky.Fn SYSCTL_DECL
6635eb1caa8SHans Petter Selaskystatement prior to their
6645eb1caa8SHans Petter Selasky.Fn SYSCTL_NODE
6655eb1caa8SHans Petter Selaskydefinition statement, typically in a so-called header file.
6665eb1caa8SHans Petter Selasky.Sh CREATING SYSCTL STRINGS
6675eb1caa8SHans Petter SelaskyZero terminated character strings sysctls are created either using the
6685eb1caa8SHans Petter Selasky.Fn SYSCTL_STRING
6695eb1caa8SHans Petter Selaskymacro or the
6705eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_STRING
6715eb1caa8SHans Petter Selaskyfunction.
6725eb1caa8SHans Petter SelaskyIf the
6735eb1caa8SHans Petter Selasky.Fa len
6745eb1caa8SHans Petter Selaskyargument in zero, the string length is computed at every access to the OID using
6755eb1caa8SHans Petter Selasky.Xr strlen 3 .
67610a1e981SEric JoynerUse the
67710a1e981SEric Joyner.Fn SYSCTL_CONST_STRING
67810a1e981SEric Joynermacro or the
67910a1e981SEric Joyner.Fn SYSCTL_ADD_CONST_STRING
68010a1e981SEric Joynerfunction to add a sysctl for a constant string.
6815eb1caa8SHans Petter Selasky.Sh CREATING OPAQUE SYSCTLS
6825eb1caa8SHans Petter SelaskyThe
6835eb1caa8SHans Petter Selasky.Fn SYSCTL_OPAQUE
6845eb1caa8SHans Petter Selaskyor
6855eb1caa8SHans Petter Selasky.Fn SYSCTL_STRUCT
6865eb1caa8SHans Petter Selaskymacros or the
6875eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_OPAQUE
6885eb1caa8SHans Petter Selaskyor
6895eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_STRUCT
6905eb1caa8SHans Petter Selaskyfunctions create an OID that handle any chunk of data
6915eb1caa8SHans Petter Selaskyof the size specified by the
6925eb1caa8SHans Petter Selasky.Fa len
6935eb1caa8SHans Petter Selaskyargument and data pointed to by the
6945eb1caa8SHans Petter Selasky.Fa ptr
6955eb1caa8SHans Petter Selaskyargument.
6965eb1caa8SHans Petter SelaskyWhen using the structure version the type is encoded as part of the
6975eb1caa8SHans Petter Selaskycreated sysctl.
6985eb1caa8SHans Petter Selasky.Sh CREATING CUSTOM SYSCTLS
6995eb1caa8SHans Petter SelaskyThe
7005eb1caa8SHans Petter Selasky.Fn SYSCTL_PROC
7015eb1caa8SHans Petter Selaskymacro and the
7025eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_PROC
7035eb1caa8SHans Petter Selaskyfunction
7045eb1caa8SHans Petter Selaskycreate OIDs with the specified
7055eb1caa8SHans Petter Selasky.Pa handler
7065eb1caa8SHans Petter Selaskyfunction.
7075eb1caa8SHans Petter SelaskyThe handler is responsible for handling all read and write requests to
7085eb1caa8SHans Petter Selaskythe OID.
7095eb1caa8SHans Petter SelaskyThis OID type is especially useful if the kernel data is not easily
7105eb1caa8SHans Petter Selaskyaccessible, or needs to be processed before exporting.
7115eb1caa8SHans Petter Selasky.Sh CREATING A STATIC SYSCTL
7125eb1caa8SHans Petter SelaskyStatic sysctls are declared using one of the
7139a593520SMateusz Piotrowski.Fn SYSCTL_BOOL ,
7149a593520SMateusz Piotrowski.Fn SYSCTL_COUNTER_U64 ,
7159a593520SMateusz Piotrowski.Fn SYSCTL_COUNTER_U64_ARRAY ,
716bd84dd2fSRuslan Ermilov.Fn SYSCTL_INT ,
7171e1f3941SEd Schouten.Fn SYSCTL_INT_WITH_LABEL ,
718bd84dd2fSRuslan Ermilov.Fn SYSCTL_LONG ,
719bd84dd2fSRuslan Ermilov.Fn SYSCTL_NODE ,
7201e1f3941SEd Schouten.Fn SYSCTL_NODE_WITH_LABEL ,
721bd84dd2fSRuslan Ermilov.Fn SYSCTL_OPAQUE ,
722bd84dd2fSRuslan Ermilov.Fn SYSCTL_PROC ,
72360a77442SJohn Baldwin.Fn SYSCTL_QUAD ,
7245eb1caa8SHans Petter Selasky.Fn SYSCTL_ROOT_NODE ,
725be87839eSConrad Meyer.Fn SYSCTL_S8 ,
726be87839eSConrad Meyer.Fn SYSCTL_S16 ,
727be87839eSConrad Meyer.Fn SYSCTL_S32 ,
728be87839eSConrad Meyer.Fn SYSCTL_S64 ,
7299a593520SMateusz Piotrowski.Fn SYSCTL_SBINTIME_MSEC ,
7309a593520SMateusz Piotrowski.Fn SYSCTL_SBINTIME_USEC ,
731bd84dd2fSRuslan Ermilov.Fn SYSCTL_STRING ,
73210a1e981SEric Joyner.Fn SYSCTL_CONST_STRING ,
733bd84dd2fSRuslan Ermilov.Fn SYSCTL_STRUCT ,
734fb61390cSConrad Meyer.Fn SYSCTL_U8 ,
735fb61390cSConrad Meyer.Fn SYSCTL_U16 ,
736be87839eSConrad Meyer.Fn SYSCTL_U32 ,
737be87839eSConrad Meyer.Fn SYSCTL_U64 ,
738bd84dd2fSRuslan Ermilov.Fn SYSCTL_UINT ,
7399a593520SMateusz Piotrowski.Fn SYSCTL_ULONG ,
7409a593520SMateusz Piotrowski.Fn SYSCTL_UQUAD ,
7419a593520SMateusz Piotrowski.Fn SYSCTL_UMA_CUR
7425eb1caa8SHans Petter Selaskyor
7439a593520SMateusz Piotrowski.Fn SYSCTL_UMA_MAX
7445eb1caa8SHans Petter Selaskymacros.
7455eb1caa8SHans Petter Selasky.Sh CREATING A DYNAMIC SYSCTL
7465eb1caa8SHans Petter SelaskyDynamic nodes are created using one of the
7479a593520SMateusz Piotrowski.Fn SYSCTL_ADD_BOOL ,
7489a593520SMateusz Piotrowski.Fn SYSCTL_ADD_COUNTER_U64 ,
7499a593520SMateusz Piotrowski.Fn SYSCTL_ADD_COUNTER_U64_ARRAY ,
7505eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_INT ,
7515eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_LONG ,
7525eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_NODE ,
7531e1f3941SEd Schouten.Fn SYSCTL_ADD_NODE_WITH_LABEL ,
7545eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_OPAQUE ,
7555eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_PROC ,
7565eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_QUAD ,
7575eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_ROOT_NODE ,
758be87839eSConrad Meyer.Fn SYSCTL_ADD_S8 ,
759be87839eSConrad Meyer.Fn SYSCTL_ADD_S16 ,
760be87839eSConrad Meyer.Fn SYSCTL_ADD_S32 ,
761be87839eSConrad Meyer.Fn SYSCTL_ADD_S64 ,
7629a593520SMateusz Piotrowski.Fn SYSCTL_ADD_SBINTIME_MSEC ,
7639a593520SMateusz Piotrowski.Fn SYSCTL_ADD_SBINTIME_USEC ,
7645eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_STRING ,
76510a1e981SEric Joyner.Fn SYSCTL_ADD_CONST_STRING ,
7665eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_STRUCT ,
767fb61390cSConrad Meyer.Fn SYSCTL_ADD_U8 ,
768fb61390cSConrad Meyer.Fn SYSCTL_ADD_U16 ,
769be87839eSConrad Meyer.Fn SYSCTL_ADD_U32 ,
770be87839eSConrad Meyer.Fn SYSCTL_ADD_U64 ,
771f0188618SHans Petter Selasky.Fn SYSCTL_ADD_UAUTO ,
7725eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_UINT ,
773f0188618SHans Petter Selasky.Fn SYSCTL_ADD_ULONG ,
7749a593520SMateusz Piotrowski.Fn SYSCTL_ADD_UQUAD ,
7759a593520SMateusz Piotrowski.Fn SYSCTL_ADD_UMA_CUR
7765eb1caa8SHans Petter Selaskyor
7779a593520SMateusz Piotrowski.Fn SYSCTL_ADD_UMA_MAX
7785eb1caa8SHans Petter Selaskyfunctions.
7795eb1caa8SHans Petter SelaskySee
7805eb1caa8SHans Petter Selasky.Xr sysctl_remove_oid 9
7815eb1caa8SHans Petter Selaskyor
7825eb1caa8SHans Petter Selasky.Xr sysctl_ctx_free 9
7835eb1caa8SHans Petter Selaskyfor more information on how to destroy a dynamically created OID.
7845eb1caa8SHans Petter Selasky.Sh CONTROL FLAGS
7855eb1caa8SHans Petter SelaskyFor most of the above functions and macros, declaring a type as part
7865eb1caa8SHans Petter Selaskyof the access flags is not necessary \[em] however, when declaring a
7875eb1caa8SHans Petter Selaskysysctl implemented by a function, including a type in the access mask
7885eb1caa8SHans Petter Selaskyis required:
7895eb1caa8SHans Petter Selasky.Bl -tag -width ".Dv CTLTYPE_NOFETCH"
790dba9e9ccSRobert Watson.It Dv CTLTYPE_NODE
791dba9e9ccSRobert WatsonThis is a node intended to be a parent for other nodes.
792dba9e9ccSRobert Watson.It Dv CTLTYPE_INT
793dba9e9ccSRobert WatsonThis is a signed integer.
794dba9e9ccSRobert Watson.It Dv CTLTYPE_STRING
795dba9e9ccSRobert WatsonThis is a nul-terminated string stored in a character array.
796be87839eSConrad Meyer.It Dv CTLTYPE_S8
797be87839eSConrad MeyerThis is an 8-bit signed integer.
798be87839eSConrad Meyer.It Dv CTLTYPE_S16
799be87839eSConrad MeyerThis is a 16-bit signed integer.
800be87839eSConrad Meyer.It Dv CTLTYPE_S32
801be87839eSConrad MeyerThis is a 32-bit signed integer.
802cbc134adSMatthew D Fleming.It Dv CTLTYPE_S64
803dba9e9ccSRobert WatsonThis is a 64-bit signed integer.
804dba9e9ccSRobert Watson.It Dv CTLTYPE_OPAQUE
805dba9e9ccSRobert WatsonThis is an opaque data structure.
806dba9e9ccSRobert Watson.It Dv CTLTYPE_STRUCT
807dba9e9ccSRobert WatsonAlias for
808dba9e9ccSRobert Watson.Dv CTLTYPE_OPAQUE .
809fb61390cSConrad Meyer.It Dv CTLTYPE_U8
810fb61390cSConrad MeyerThis is an 8-bit unsigned integer.
811fb61390cSConrad Meyer.It Dv CTLTYPE_U16
812fb61390cSConrad MeyerThis is a 16-bit unsigned integer.
813be87839eSConrad Meyer.It Dv CTLTYPE_U32
814be87839eSConrad MeyerThis is a 32-bit unsigned integer.
815be87839eSConrad Meyer.It Dv CTLTYPE_U64
816be87839eSConrad MeyerThis is a 64-bit unsigned integer.
817dba9e9ccSRobert Watson.It Dv CTLTYPE_UINT
818dba9e9ccSRobert WatsonThis is an unsigned integer.
819dba9e9ccSRobert Watson.It Dv CTLTYPE_LONG
820dba9e9ccSRobert WatsonThis is a signed long.
821dba9e9ccSRobert Watson.It Dv CTLTYPE_ULONG
8228a1f4129SRobert WatsonThis is an unsigned long.
823dba9e9ccSRobert Watson.El
824dba9e9ccSRobert Watson.Pp
82560a77442SJohn BaldwinAll sysctl types except for new node declarations require one of the following
82660a77442SJohn Baldwinflags to be set indicating the read and write disposition of the sysctl:
827bd84dd2fSRuslan Ermilov.Bl -tag -width ".Dv CTLFLAG_ANYBODY"
828dba9e9ccSRobert Watson.It Dv CTLFLAG_RD
829dba9e9ccSRobert WatsonThis is a read-only sysctl.
83060a77442SJohn Baldwin.It Dv CTLFLAG_RDTUN
8315eb1caa8SHans Petter SelaskyThis is a read-only sysctl and tunable which is tried fetched once
8327c64ddd5SWarren Blockfrom the system environment early during module load or system boot.
833b470b929SDavid E. O'Brien.It Dv CTLFLAG_WR
834dba9e9ccSRobert WatsonThis is a writable sysctl.
835dba9e9ccSRobert Watson.It Dv CTLFLAG_RW
836dba9e9ccSRobert WatsonThis sysctl is readable and writable.
83760a77442SJohn Baldwin.It Dv CTLFLAG_RWTUN
8385eb1caa8SHans Petter SelaskyThis is a readable and writeable sysctl and tunable which is tried
8397c64ddd5SWarren Blockfetched once from the system environment early during module load or
8405eb1caa8SHans Petter Selaskysystem boot.
8415eb1caa8SHans Petter Selasky.It Dv CTLFLAG_NOFETCH
8425eb1caa8SHans Petter SelaskyIn case the node is marked as a tunable using the CTLFLAG_[XX]TUN,
8435eb1caa8SHans Petter Selaskythis flag will prevent fetching the initial value from the system
8447851d429SEdward Tomasz Napieralaenvironment.
8457851d429SEdward Tomasz NapieralaTypically this flag should only be used for very early
8465eb1caa8SHans Petter Selaskylow level system setup code, and not by common drivers and modules.
847982a973eSWarner Losh.It Dv CTLFLAG_MPSAFE
848982a973eSWarner LoshThis
849982a973eSWarner Losh.Xr sysctl 9
850982a973eSWarner Loshhandler is MP safe.
851982a973eSWarner LoshDo not grab Giant around calls to this handler.
852d132d4caSWarner LoshThis should only be used for
853d132d4caSWarner Losh.Fn SYSCTL_PROC
854d132d4caSWarner Loshentries.
85560a77442SJohn Baldwin.El
85660a77442SJohn Baldwin.Pp
85760a77442SJohn BaldwinAdditionally, any of the following optional flags may also be specified:
85860a77442SJohn Baldwin.Bl -tag -width ".Dv CTLFLAG_ANYBODY"
859dba9e9ccSRobert Watson.It Dv CTLFLAG_ANYBODY
860dba9e9ccSRobert WatsonAny user or process can write to this sysctl.
861e3127092SEd Maste.It Dv CTLFLAG_CAPRD
862e3127092SEd MasteA process in capability mode can read from this sysctl.
863e3127092SEd Maste.It Dv CTLFLAG_CAPWR
864e3127092SEd MasteA process in capability mode can write to this sysctl.
865dba9e9ccSRobert Watson.It Dv CTLFLAG_SECURE
866dba9e9ccSRobert WatsonThis sysctl can be written to only if the effective securelevel of the
867bd84dd2fSRuslan Ermilovprocess is \[<=] 0.
868dba9e9ccSRobert Watson.It Dv CTLFLAG_PRISON
869dba9e9ccSRobert WatsonThis sysctl can be written to by processes in
870dba9e9ccSRobert Watson.Xr jail 2 .
871dba9e9ccSRobert Watson.It Dv CTLFLAG_SKIP
872dba9e9ccSRobert WatsonWhen iterating the sysctl name space, do not list this sysctl.
873dba9e9ccSRobert Watson.It Dv CTLFLAG_TUN
8746b9597aaSAndrew ThompsonAdvisory flag that a system tunable also exists for this variable.
8755eb1caa8SHans Petter SelaskyThe initial sysctl value is tried fetched once from the system
8767c64ddd5SWarren Blockenvironment early during module load or system boot.
8775eb1caa8SHans Petter Selasky.It Dv CTLFLAG_DYN
8785eb1caa8SHans Petter SelaskyDynamically created OIDs automatically get this flag set.
87956538e4aSGleb Smirnoff.It Dv CTLFLAG_VNET
88056538e4aSGleb SmirnoffOID references a VIMAGE-enabled variable.
881dba9e9ccSRobert Watson.El
882dba9e9ccSRobert Watson.Sh EXAMPLES
883dba9e9ccSRobert WatsonSample use of
884bd84dd2fSRuslan Ermilov.Fn SYSCTL_DECL
885bd84dd2fSRuslan Ermilovto declare the
886bd84dd2fSRuslan Ermilov.Va security
887bd84dd2fSRuslan Ermilovsysctl tree for use by new nodes:
888dba9e9ccSRobert Watson.Bd -literal -offset indent
889dba9e9ccSRobert WatsonSYSCTL_DECL(_security);
890dba9e9ccSRobert Watson.Ed
891dba9e9ccSRobert Watson.Pp
892dba9e9ccSRobert WatsonExamples of integer, opaque, string, and procedure sysctls follow:
893dba9e9ccSRobert Watson.Bd -literal -offset indent
894dba9e9ccSRobert Watson/*
895dba9e9ccSRobert Watson * Example of a constant integer value.  Notice that the control
896f0188618SHans Petter Selasky * flags are CTLFLAG_RD, the variable pointer is SYSCTL_NULL_INT_PTR,
897f0188618SHans Petter Selasky * and the value is declared.
898dba9e9ccSRobert Watson */
899f0188618SHans Petter SelaskySYSCTL_INT(_debug_sizeof, OID_AUTO, bio, CTLFLAG_RD, SYSCTL_NULL_INT_PTR,
900dba9e9ccSRobert Watson    sizeof(struct bio), "sizeof(struct bio)");
901dba9e9ccSRobert Watson
902dba9e9ccSRobert Watson/*
903dba9e9ccSRobert Watson * Example of a variable integer value.  Notice that the control
904dba9e9ccSRobert Watson * flags are CTLFLAG_RW, the variable pointer is set, and the
905dba9e9ccSRobert Watson * value is 0.
906dba9e9ccSRobert Watson */
907dba9e9ccSRobert Watsonstatic int	doingcache = 1;		/* 1 => enable the cache */
908dba9e9ccSRobert WatsonSYSCTL_INT(_debug, OID_AUTO, vfscache, CTLFLAG_RW, &doingcache, 0,
909dba9e9ccSRobert Watson    "Enable name cache");
910dba9e9ccSRobert Watson
911dba9e9ccSRobert Watson/*
912dba9e9ccSRobert Watson * Example of a variable string value.  Notice that the control
913dba9e9ccSRobert Watson * flags are CTLFLAG_RW, that the variable pointer and string
914dba9e9ccSRobert Watson * size are set.  Unlike newer sysctls, this older sysctl uses a
915dba9e9ccSRobert Watson * static oid number.
916dba9e9ccSRobert Watson */
917dba9e9ccSRobert Watsonchar kernelname[MAXPATHLEN] = "/kernel";	/* XXX bloat */
918dba9e9ccSRobert WatsonSYSCTL_STRING(_kern, KERN_BOOTFILE, bootfile, CTLFLAG_RW,
919dba9e9ccSRobert Watson    kernelname, sizeof(kernelname), "Name of kernel file booted");
920dba9e9ccSRobert Watson
921dba9e9ccSRobert Watson/*
922dba9e9ccSRobert Watson * Example of an opaque data type exported by sysctl.  Notice that
923dba9e9ccSRobert Watson * the variable pointer and size are provided, as well as a format
924dba9e9ccSRobert Watson * string for sysctl(8).
925dba9e9ccSRobert Watson */
9267c64ddd5SWarren Blockstatic l_fp pps_freq;	/* scaled frequency offset (ns/s) */
927dba9e9ccSRobert WatsonSYSCTL_OPAQUE(_kern_ntp_pll, OID_AUTO, pps_freq, CTLFLAG_RD,
928dba9e9ccSRobert Watson    &pps_freq, sizeof(pps_freq), "I", "");
929dba9e9ccSRobert Watson
930dba9e9ccSRobert Watson/*
931dba9e9ccSRobert Watson * Example of a procedure based sysctl exporting string
932dba9e9ccSRobert Watson * information.  Notice that the data type is declared, the NULL
933dba9e9ccSRobert Watson * variable pointer and 0 size, the function pointer, and the
934dba9e9ccSRobert Watson * format string for sysctl(8).
935dba9e9ccSRobert Watson */
936dba9e9ccSRobert WatsonSYSCTL_PROC(_kern_timecounter, OID_AUTO, hardware, CTLTYPE_STRING |
937dba9e9ccSRobert Watson    CTLFLAG_RW, NULL, 0, sysctl_kern_timecounter_hardware, "A",
938dba9e9ccSRobert Watson    "");
939dba9e9ccSRobert Watson.Ed
9405eb1caa8SHans Petter Selasky.Pp
9415eb1caa8SHans Petter SelaskyThe following is an example of
9425eb1caa8SHans Petter Selaskyhow to create a new top-level category
9435eb1caa8SHans Petter Selaskyand how to hook up another subtree to an existing static node.
9445eb1caa8SHans Petter SelaskyThis example does not use contexts,
9455eb1caa8SHans Petter Selaskywhich results in tedious management of all intermediate oids,
9465eb1caa8SHans Petter Selaskyas they need to be freed later on:
9475eb1caa8SHans Petter Selasky.Bd -literal -offset indent
9485eb1caa8SHans Petter Selasky#include <sys/sysctl.h>
9495eb1caa8SHans Petter Selasky ...
9505eb1caa8SHans Petter Selasky/*
9515eb1caa8SHans Petter Selasky * Need to preserve pointers to newly created subtrees,
9525eb1caa8SHans Petter Selasky * to be able to free them later:
9535eb1caa8SHans Petter Selasky */
9545eb1caa8SHans Petter Selaskystatic struct sysctl_oid *root1;
9555eb1caa8SHans Petter Selaskystatic struct sysctl_oid *root2;
9565eb1caa8SHans Petter Selaskystatic struct sysctl_oid *oidp;
9575eb1caa8SHans Petter Selaskystatic int a_int;
9585eb1caa8SHans Petter Selaskystatic char *string = "dynamic sysctl";
9595eb1caa8SHans Petter Selasky ...
9605eb1caa8SHans Petter Selasky
9615eb1caa8SHans Petter Selaskyroot1 = SYSCTL_ADD_ROOT_NODE(NULL,
9625eb1caa8SHans Petter Selasky	OID_AUTO, "newtree", CTLFLAG_RW, 0, "new top level tree");
9635eb1caa8SHans Petter Selaskyoidp = SYSCTL_ADD_INT(NULL, SYSCTL_CHILDREN(root1),
9645eb1caa8SHans Petter Selasky	OID_AUTO, "newint", CTLFLAG_RW, &a_int, 0, "new int leaf");
9655eb1caa8SHans Petter Selasky ...
9665eb1caa8SHans Petter Selaskyroot2 = SYSCTL_ADD_NODE(NULL, SYSCTL_STATIC_CHILDREN(_debug),
9675eb1caa8SHans Petter Selasky	OID_AUTO, "newtree", CTLFLAG_RW, 0, "new tree under debug");
9685eb1caa8SHans Petter Selaskyoidp = SYSCTL_ADD_STRING(NULL, SYSCTL_CHILDREN(root2),
9695eb1caa8SHans Petter Selasky	OID_AUTO, "newstring", CTLFLAG_RD, string, 0, "new string leaf");
9705eb1caa8SHans Petter Selasky.Ed
9715eb1caa8SHans Petter Selasky.Pp
9725eb1caa8SHans Petter SelaskyThis example creates the following subtrees:
9735eb1caa8SHans Petter Selasky.Bd -literal -offset indent
9745eb1caa8SHans Petter Selaskydebug.newtree.newstring
9755eb1caa8SHans Petter Selaskynewtree.newint
9765eb1caa8SHans Petter Selasky.Ed
9775eb1caa8SHans Petter Selasky.Pp
9785eb1caa8SHans Petter Selasky.Em "Care should be taken to free all OIDs once they are no longer needed!"
97991f3a6dbSYaroslav Tykhiy.Sh SYSCTL NAMING
980dba9e9ccSRobert WatsonWhen adding, modifying, or removing sysctl names, it is important to be
981dba9e9ccSRobert Watsonaware that these interfaces may be used by users, libraries, applications,
982f4006affSGiorgos Keramidasor documentation (such as published books), and are implicitly published application interfaces.
983dba9e9ccSRobert WatsonAs with other application interfaces, caution must be taken not to break
984dba9e9ccSRobert Watsonexisting applications, and to think about future use of new name spaces so as
985dba9e9ccSRobert Watsonto avoid the need to rename or remove interfaces that might be depended on in
986dba9e9ccSRobert Watsonthe future.
98791f3a6dbSYaroslav Tykhiy.Pp
98891f3a6dbSYaroslav TykhiyThe semantics chosen for a new sysctl should be as clear as possible,
98991f3a6dbSYaroslav Tykhiyand the name of the sysctl must closely reflect its semantics.
99091f3a6dbSYaroslav TykhiyTherefore the sysctl name deserves a fair amount of consideration.
99191f3a6dbSYaroslav TykhiyIt should be short but yet representative of the sysctl meaning.
99291f3a6dbSYaroslav TykhiyIf the name consists of several words, they should be separated by
99391f3a6dbSYaroslav Tykhiyunderscore characters, as in
99491f3a6dbSYaroslav Tykhiy.Va compute_summary_at_mount .
99591f3a6dbSYaroslav TykhiyUnderscore characters may be omitted only if the name consists of not more
99691f3a6dbSYaroslav Tykhiythan two words, each being not longer than four characters, as in
99791f3a6dbSYaroslav Tykhiy.Va bootfile .
99891f3a6dbSYaroslav TykhiyFor boolean sysctls, negative logic should be totally avoided.
99991f3a6dbSYaroslav TykhiyThat is, do not use names like
100091f3a6dbSYaroslav Tykhiy.Va no_foobar
100191f3a6dbSYaroslav Tykhiyor
100291f3a6dbSYaroslav Tykhiy.Va foobar_disable .
100391f3a6dbSYaroslav TykhiyThey are confusing and lead to configuration errors.
100491f3a6dbSYaroslav TykhiyUse positive logic instead:
100591f3a6dbSYaroslav Tykhiy.Va foobar ,
100691f3a6dbSYaroslav Tykhiy.Va foobar_enable .
100791f3a6dbSYaroslav Tykhiy.Pp
10085eb1caa8SHans Petter SelaskyA temporary sysctl node OID that should not be relied upon must be designated
10097851d429SEdward Tomasz Napieralaas such by a leading underscore character in its name.
10107851d429SEdward Tomasz NapieralaFor example:
101191f3a6dbSYaroslav Tykhiy.Va _dirty_hack .
1012dba9e9ccSRobert Watson.Sh SEE ALSO
1013f3066f2bSGavin Atkinson.Xr sysctl 3 ,
1014dba9e9ccSRobert Watson.Xr sysctl 8 ,
1015dba9e9ccSRobert Watson.Xr sysctl_add_oid 9 ,
1016dba9e9ccSRobert Watson.Xr sysctl_ctx_free 9 ,
1017dba9e9ccSRobert Watson.Xr sysctl_ctx_init 9 ,
1018dba9e9ccSRobert Watson.Xr sysctl_remove_oid 9
1019dba9e9ccSRobert Watson.Sh HISTORY
1020bd84dd2fSRuslan ErmilovThe
1021dba9e9ccSRobert Watson.Xr sysctl 8
1022bd84dd2fSRuslan Ermilovutility first appeared in
1023dba9e9ccSRobert Watson.Bx 4.4 .
1024dba9e9ccSRobert Watson.Sh AUTHORS
1025bd84dd2fSRuslan Ermilov.An -nosplit
1026bd84dd2fSRuslan ErmilovThe
1027bd84dd2fSRuslan Ermilov.Nm sysctl
1028bd84dd2fSRuslan Ermilovimplementation originally found in
1029dba9e9ccSRobert Watson.Bx
1030dba9e9ccSRobert Watsonhas been extensively rewritten by
1031dba9e9ccSRobert Watson.An Poul-Henning Kamp
1032dba9e9ccSRobert Watsonin order to add support for name lookups, name space iteration, and dynamic
1033dba9e9ccSRobert Watsonaddition of MIB nodes.
1034dba9e9ccSRobert Watson.Pp
1035dba9e9ccSRobert WatsonThis man page was written by
1036dba9e9ccSRobert Watson.An Robert N. M. Watson .
10373edc2b53SJoel Dahl.Sh SECURITY CONSIDERATIONS
10383edc2b53SJoel DahlWhen creating new sysctls, careful attention should be paid to the security
10393edc2b53SJoel Dahlimplications of the monitoring or management interface being created.
10403edc2b53SJoel DahlMost sysctls present in the kernel are read-only or writable only by the
10413edc2b53SJoel Dahlsuperuser.
10423edc2b53SJoel DahlSysctls exporting extensive information on system data structures and
10433edc2b53SJoel Dahloperation, especially those implemented using procedures, will wish to
10443edc2b53SJoel Dahlimplement access control to limit the undesired exposure of information about
10453edc2b53SJoel Dahlother processes, network connections, etc.
10463edc2b53SJoel Dahl.Pp
10473edc2b53SJoel DahlThe following top level sysctl name spaces are commonly used:
10483edc2b53SJoel Dahl.Bl -tag -width ".Va regression"
10493edc2b53SJoel Dahl.It Va compat
10503edc2b53SJoel DahlCompatibility layer information.
10513edc2b53SJoel Dahl.It Va debug
10523edc2b53SJoel DahlDebugging information.
10533edc2b53SJoel DahlVarious name spaces exist under
10543edc2b53SJoel Dahl.Va debug .
10553edc2b53SJoel Dahl.It Va hw
10563edc2b53SJoel DahlHardware and device driver information.
10573edc2b53SJoel Dahl.It Va kern
10583edc2b53SJoel DahlKernel behavior tuning; generally deprecated in favor of more specific
10593edc2b53SJoel Dahlname spaces.
10603edc2b53SJoel Dahl.It Va machdep
10613edc2b53SJoel DahlMachine-dependent configuration parameters.
10623edc2b53SJoel Dahl.It Va net
10633edc2b53SJoel DahlNetwork subsystem.
10643edc2b53SJoel DahlVarious protocols have name spaces under
10653edc2b53SJoel Dahl.Va net .
10663edc2b53SJoel Dahl.It Va regression
10673edc2b53SJoel DahlRegression test configuration and information.
10683edc2b53SJoel Dahl.It Va security
10693edc2b53SJoel DahlSecurity and security-policy configuration and information.
10703edc2b53SJoel Dahl.It Va sysctl
10713edc2b53SJoel DahlReserved name space for the implementation of sysctl.
10723edc2b53SJoel Dahl.It Va user
10733edc2b53SJoel DahlConfiguration settings relating to user application behavior.
10743edc2b53SJoel DahlGenerally, configuring applications using kernel sysctls is discouraged.
10753edc2b53SJoel Dahl.It Va vfs
10763edc2b53SJoel DahlVirtual file system configuration and information.
10773edc2b53SJoel Dahl.It Va vm
10783edc2b53SJoel DahlVirtual memory subsystem configuration and information.
10793edc2b53SJoel Dahl.El
1080