xref: /freebsd/share/man/man9/sysctl.9 (revision 7851d429a6e8f958a5cd7a3a16a78497e6741346)
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.\"
28fb61390cSConrad Meyer.Dd October 23, 2015
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 ,
40be87839eSConrad Meyer.Nm SYSCTL_ADD_S8 ,
41be87839eSConrad Meyer.Nm SYSCTL_ADD_S16 ,
42be87839eSConrad Meyer.Nm SYSCTL_ADD_S32 ,
43be87839eSConrad Meyer.Nm SYSCTL_ADD_S64 ,
445eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_STRING ,
455eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_STRUCT ,
46fb61390cSConrad Meyer.Nm SYSCTL_ADD_U8 ,
47fb61390cSConrad Meyer.Nm SYSCTL_ADD_U16 ,
48be87839eSConrad Meyer.Nm SYSCTL_ADD_U32 ,
49be87839eSConrad Meyer.Nm SYSCTL_ADD_U64 ,
50f0188618SHans Petter Selasky.Nm SYSCTL_ADD_UAUTO ,
515eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_UINT ,
525eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_ULONG ,
535eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_UQUAD ,
545eb1caa8SHans Petter Selasky.Nm SYSCTL_CHILDREN ,
555eb1caa8SHans Petter Selasky.Nm SYSCTL_STATIC_CHILDREN ,
565eb1caa8SHans Petter Selasky.Nm SYSCTL_NODE_CHILDREN ,
575eb1caa8SHans Petter Selasky.Nm SYSCTL_PARENT ,
58dba9e9ccSRobert Watson.Nm SYSCTL_INT ,
59dba9e9ccSRobert Watson.Nm SYSCTL_LONG ,
60dba9e9ccSRobert Watson.Nm SYSCTL_NODE ,
61dba9e9ccSRobert Watson.Nm SYSCTL_OPAQUE ,
62dba9e9ccSRobert Watson.Nm SYSCTL_PROC ,
6360a77442SJohn Baldwin.Nm SYSCTL_QUAD ,
645eb1caa8SHans Petter Selasky.Nm SYSCTL_ROOT_NODE ,
65be87839eSConrad Meyer.Nm SYSCTL_S8 ,
66be87839eSConrad Meyer.Nm SYSCTL_S16 ,
67be87839eSConrad Meyer.Nm SYSCTL_S32 ,
68be87839eSConrad Meyer.Nm SYSCTL_S64 ,
69dba9e9ccSRobert Watson.Nm SYSCTL_STRING ,
70dba9e9ccSRobert Watson.Nm SYSCTL_STRUCT ,
71fb61390cSConrad Meyer.Nm SYSCTL_U8 ,
72fb61390cSConrad Meyer.Nm SYSCTL_U16 ,
73be87839eSConrad Meyer.Nm SYSCTL_U32 ,
74be87839eSConrad Meyer.Nm SYSCTL_U64 ,
75dba9e9ccSRobert Watson.Nm SYSCTL_UINT ,
76c157a036SDavid E. O'Brien.Nm SYSCTL_ULONG ,
7760a77442SJohn Baldwin.Nm SYSCTL_UQUAD
785eb1caa8SHans Petter Selasky.Nd Dynamic and static sysctl MIB creation functions
79dba9e9ccSRobert Watson.Sh SYNOPSIS
80dba9e9ccSRobert Watson.In sys/types.h
81dba9e9ccSRobert Watson.In sys/sysctl.h
82bd84dd2fSRuslan Ermilov.Fn SYSCTL_DECL name
835eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
845eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_INT
855eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
865eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
875eb1caa8SHans Petter Selasky.Fa "int number"
885eb1caa8SHans Petter Selasky.Fa "const char *name"
895eb1caa8SHans Petter Selasky.Fa "int ctlflags"
905eb1caa8SHans Petter Selasky.Fa "int *ptr"
91be87839eSConrad Meyer.Fa "int val"
925eb1caa8SHans Petter Selasky.Fa "const char *descr"
935eb1caa8SHans Petter Selasky.Fc
945eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
955eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_LONG
965eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
975eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
985eb1caa8SHans Petter Selasky.Fa "int number"
995eb1caa8SHans Petter Selasky.Fa "const char *name"
1005eb1caa8SHans Petter Selasky.Fa "int ctlflags"
1015eb1caa8SHans Petter Selasky.Fa "long *ptr"
1025eb1caa8SHans Petter Selasky.Fa "const char *descr"
1035eb1caa8SHans Petter Selasky.Fc
1045eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
1055eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_NODE
1065eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
1075eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
1085eb1caa8SHans Petter Selasky.Fa "int number"
1095eb1caa8SHans Petter Selasky.Fa "const char *name"
1105eb1caa8SHans Petter Selasky.Fa "int ctlflags"
1115eb1caa8SHans Petter Selasky.Fa "int (*handler)(SYSCTL_HANDLER_ARGS)"
1125eb1caa8SHans Petter Selasky.Fa "const char *descr"
1135eb1caa8SHans Petter Selasky.Fc
1145eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
1155eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_OPAQUE
1165eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
1175eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
1185eb1caa8SHans Petter Selasky.Fa "int number"
1195eb1caa8SHans Petter Selasky.Fa "const char *name"
1205eb1caa8SHans Petter Selasky.Fa "int ctlflags"
1215eb1caa8SHans Petter Selasky.Fa "void *ptr"
1225eb1caa8SHans Petter Selasky.Fa "intptr_t len"
1235eb1caa8SHans Petter Selasky.Fa "const char *format"
1243edc2b53SJoel Dahl.Fa "const char *descr"
1255eb1caa8SHans Petter Selasky.Fc
1265eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
1275eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_PROC
1285eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
1295eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
1305eb1caa8SHans Petter Selasky.Fa "int number"
1315eb1caa8SHans Petter Selasky.Fa "const char *name"
1325eb1caa8SHans Petter Selasky.Fa "int ctlflags"
1335eb1caa8SHans Petter Selasky.Fa "void *arg1"
1345eb1caa8SHans Petter Selasky.Fa "intptr_t arg2"
1355eb1caa8SHans Petter Selasky.Fa "int (*handler) (SYSCTL_HANDLERARGS)"
1365eb1caa8SHans Petter Selasky.Fa "const char *format"
1375eb1caa8SHans Petter Selasky.Fa "const char *descr"
1385eb1caa8SHans Petter Selasky.Fc
1395eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
1405eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_QUAD
1415eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
1425eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
1435eb1caa8SHans Petter Selasky.Fa "int number"
1445eb1caa8SHans Petter Selasky.Fa "const char *name"
1455eb1caa8SHans Petter Selasky.Fa "int ctlflags"
146be87839eSConrad Meyer.Fa "int64_t *ptr"
1475eb1caa8SHans Petter Selasky.Fa "const char *descr"
1485eb1caa8SHans Petter Selasky.Fc
1495eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
1505eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_ROOT_NODE
1515eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
1525eb1caa8SHans Petter Selasky.Fa "int number"
1535eb1caa8SHans Petter Selasky.Fa "const char *name"
1545eb1caa8SHans Petter Selasky.Fa "int ctlflags"
1555eb1caa8SHans Petter Selasky.Fa "int (*handler)(SYSCTL_HANDLER_ARGS)"
1565eb1caa8SHans Petter Selasky.Fa "const char *descr"
1575eb1caa8SHans Petter Selasky.Fc
1585eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
159be87839eSConrad Meyer.Fo SYSCTL_ADD_S8
160be87839eSConrad Meyer.Fa "struct sysctl_ctx_list *ctx"
161be87839eSConrad Meyer.Fa "struct sysctl_oid_list *parent"
162be87839eSConrad Meyer.Fa "int number"
163be87839eSConrad Meyer.Fa "const char *name"
164be87839eSConrad Meyer.Fa "int ctlflags"
165be87839eSConrad Meyer.Fa "int8_t *ptr"
166be87839eSConrad Meyer.Fa "int8_t val"
167be87839eSConrad Meyer.Fa "const char *descr"
168be87839eSConrad Meyer.Fc
169be87839eSConrad Meyer.Ft struct sysctl_oid *
170be87839eSConrad Meyer.Fo SYSCTL_ADD_S16
171be87839eSConrad Meyer.Fa "struct sysctl_ctx_list *ctx"
172be87839eSConrad Meyer.Fa "struct sysctl_oid_list *parent"
173be87839eSConrad Meyer.Fa "int number"
174be87839eSConrad Meyer.Fa "const char *name"
175be87839eSConrad Meyer.Fa "int ctlflags"
176be87839eSConrad Meyer.Fa "int16_t *ptr"
177be87839eSConrad Meyer.Fa "int16_t val"
178be87839eSConrad Meyer.Fa "const char *descr"
179be87839eSConrad Meyer.Fc
180be87839eSConrad Meyer.Ft struct sysctl_oid *
181be87839eSConrad Meyer.Fo SYSCTL_ADD_S32
182be87839eSConrad Meyer.Fa "struct sysctl_ctx_list *ctx"
183be87839eSConrad Meyer.Fa "struct sysctl_oid_list *parent"
184be87839eSConrad Meyer.Fa "int number"
185be87839eSConrad Meyer.Fa "const char *name"
186be87839eSConrad Meyer.Fa "int ctlflags"
187be87839eSConrad Meyer.Fa "int32_t *ptr"
188be87839eSConrad Meyer.Fa "int32_t val"
189be87839eSConrad Meyer.Fa "const char *descr"
190be87839eSConrad Meyer.Fc
191be87839eSConrad Meyer.Ft struct sysctl_oid *
192be87839eSConrad Meyer.Fo SYSCTL_ADD_S64
193be87839eSConrad Meyer.Fa "struct sysctl_ctx_list *ctx"
194be87839eSConrad Meyer.Fa "struct sysctl_oid_list *parent"
195be87839eSConrad Meyer.Fa "int number"
196be87839eSConrad Meyer.Fa "const char *name"
197be87839eSConrad Meyer.Fa "int ctlflags"
198be87839eSConrad Meyer.Fa "int64_t *ptr"
199be87839eSConrad Meyer.Fa "int64_t val"
200be87839eSConrad Meyer.Fa "const char *descr"
201be87839eSConrad Meyer.Fc
202be87839eSConrad Meyer.Ft struct sysctl_oid *
2035eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_STRING
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"
2095eb1caa8SHans Petter Selasky.Fa "char *ptr"
2105eb1caa8SHans Petter Selasky.Fa "intptr_t len"
2115eb1caa8SHans Petter Selasky.Fa "const char *descr"
2125eb1caa8SHans Petter Selasky.Fc
2135eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
2145eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_STRUCT
2155eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
2165eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
2175eb1caa8SHans Petter Selasky.Fa "int number"
2185eb1caa8SHans Petter Selasky.Fa "const char *name"
2195eb1caa8SHans Petter Selasky.Fa "int ctlflags"
2205eb1caa8SHans Petter Selasky.Fa "void *ptr"
2215eb1caa8SHans Petter Selasky.Fa struct_type
2225eb1caa8SHans Petter Selasky.Fa "const char *descr"
2235eb1caa8SHans Petter Selasky.Fc
2245eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
225fb61390cSConrad Meyer.Fo SYSCTL_ADD_U8
226fb61390cSConrad Meyer.Fa "struct sysctl_ctx_list *ctx"
227fb61390cSConrad Meyer.Fa "struct sysctl_oid_list *parent"
228fb61390cSConrad Meyer.Fa "int number"
229fb61390cSConrad Meyer.Fa "const char *name"
230fb61390cSConrad Meyer.Fa "int ctlflags"
231be87839eSConrad Meyer.Fa "uint8_t *ptr"
232be87839eSConrad Meyer.Fa "uint8_t val"
233fb61390cSConrad Meyer.Fa "const char *descr"
234fb61390cSConrad Meyer.Fc
235fb61390cSConrad Meyer.Ft struct sysctl_oid *
236fb61390cSConrad Meyer.Fo SYSCTL_ADD_U16
237fb61390cSConrad Meyer.Fa "struct sysctl_ctx_list *ctx"
238fb61390cSConrad Meyer.Fa "struct sysctl_oid_list *parent"
239fb61390cSConrad Meyer.Fa "int number"
240fb61390cSConrad Meyer.Fa "const char *name"
241fb61390cSConrad Meyer.Fa "int ctlflags"
242be87839eSConrad Meyer.Fa "uint16_t *ptr"
243be87839eSConrad Meyer.Fa "uint16_t val"
244be87839eSConrad Meyer.Fa "const char *descr"
245be87839eSConrad Meyer.Fc
246be87839eSConrad Meyer.Ft struct sysctl_oid *
247be87839eSConrad Meyer.Fo SYSCTL_ADD_U32
248be87839eSConrad Meyer.Fa "struct sysctl_ctx_list *ctx"
249be87839eSConrad Meyer.Fa "struct sysctl_oid_list *parent"
250be87839eSConrad Meyer.Fa "int number"
251be87839eSConrad Meyer.Fa "const char *name"
252be87839eSConrad Meyer.Fa "int ctlflags"
253be87839eSConrad Meyer.Fa "uint32_t *ptr"
254be87839eSConrad Meyer.Fa "uint32_t val"
255be87839eSConrad Meyer.Fa "const char *descr"
256be87839eSConrad Meyer.Fc
257be87839eSConrad Meyer.Ft struct sysctl_oid *
258be87839eSConrad Meyer.Fo SYSCTL_ADD_U64
259be87839eSConrad Meyer.Fa "struct sysctl_ctx_list *ctx"
260be87839eSConrad Meyer.Fa "struct sysctl_oid_list *parent"
261be87839eSConrad Meyer.Fa "int number"
262be87839eSConrad Meyer.Fa "const char *name"
263be87839eSConrad Meyer.Fa "int ctlflags"
264be87839eSConrad Meyer.Fa "uint64_t *ptr"
265be87839eSConrad Meyer.Fa "uint64_t val"
266fb61390cSConrad Meyer.Fa "const char *descr"
267fb61390cSConrad Meyer.Fc
268fb61390cSConrad Meyer.Ft struct sysctl_oid *
2695eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_UINT
2705eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
2715eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
2725eb1caa8SHans Petter Selasky.Fa "int number"
2735eb1caa8SHans Petter Selasky.Fa "const char *name"
2745eb1caa8SHans Petter Selasky.Fa "int ctlflags"
2755eb1caa8SHans Petter Selasky.Fa "unsigned int *ptr"
276be87839eSConrad Meyer.Fa "unsigned int val"
2775eb1caa8SHans Petter Selasky.Fa "const char *descr"
2785eb1caa8SHans Petter Selasky.Fc
2795eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
2805eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_ULONG
2815eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
2825eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
2835eb1caa8SHans Petter Selasky.Fa "int number"
2845eb1caa8SHans Petter Selasky.Fa "const char *name"
2855eb1caa8SHans Petter Selasky.Fa "int ctlflags"
2865eb1caa8SHans Petter Selasky.Fa "unsigned long *ptr"
2875eb1caa8SHans Petter Selasky.Fa "const char *descr"
2885eb1caa8SHans Petter Selasky.Fc
2895eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
2905eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_UQUAD
2915eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
2925eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
2935eb1caa8SHans Petter Selasky.Fa "int number"
2945eb1caa8SHans Petter Selasky.Fa "const char *name"
2955eb1caa8SHans Petter Selasky.Fa "int ctlflags"
296be87839eSConrad Meyer.Fa "uint64_t *ptr"
297f0188618SHans Petter Selasky.Fa "const char *descr"
298f0188618SHans Petter Selasky.Fc
299f0188618SHans Petter Selasky.Ft struct sysctl_oid *
300f0188618SHans Petter Selasky.Fo SYSCTL_ADD_UAUTO
301f0188618SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
302f0188618SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
303f0188618SHans Petter Selasky.Fa "int number"
304f0188618SHans Petter Selasky.Fa "const char *name"
305f0188618SHans Petter Selasky.Fa "int ctlflags"
306f0188618SHans Petter Selasky.Fa "void *ptr"
3075eb1caa8SHans Petter Selasky.Fa "const char *descr"
3085eb1caa8SHans Petter Selasky.Fc
3095eb1caa8SHans Petter Selasky.Ft struct sysctl_oid_list *
3105eb1caa8SHans Petter Selasky.Fo SYSCTL_CHILDREN
3115eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid *oidp"
3125eb1caa8SHans Petter Selasky.Fc
3135eb1caa8SHans Petter Selasky.Ft struct sysctl_oid_list *
3145eb1caa8SHans Petter Selasky.Fo SYSCTL_STATIC_CHILDREN
3155eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list OID_NAME"
3165eb1caa8SHans Petter Selasky.Fc
3175eb1caa8SHans Petter Selasky.Ft struct sysctl_oid_list *
3185eb1caa8SHans Petter Selasky.Fo SYSCTL_NODE_CHILDREN
3195eb1caa8SHans Petter Selasky.Fa "parent"
3205eb1caa8SHans Petter Selasky.Fa "name"
3215eb1caa8SHans Petter Selasky.Fc
3225eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
3235eb1caa8SHans Petter Selasky.Fo SYSCTL_PARENT
3245eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid *oid"
3255eb1caa8SHans Petter Selasky.Fc
3265eb1caa8SHans Petter Selasky.Fn SYSCTL_INT parent number name ctlflags ptr val descr
3275eb1caa8SHans Petter Selasky.Fn SYSCTL_LONG parent number name ctlflags ptr val descr
3285eb1caa8SHans Petter Selasky.Fn SYSCTL_NODE parent number name ctlflags handler descr
3295eb1caa8SHans Petter Selasky.Fn SYSCTL_OPAQUE parent number name ctlflags ptr len format descr
3305eb1caa8SHans Petter Selasky.Fn SYSCTL_PROC parent number name ctlflags arg1 arg2 handler format descr
3315eb1caa8SHans Petter Selasky.Fn SYSCTL_QUAD parent number name ctlflags ptr val descr
332be87839eSConrad Meyer.Fn SYSCTL_ROOT_NODE number name ctlflags handler descr
333be87839eSConrad Meyer.Fn SYSCTL_S8 parent number name ctlflags ptr val descr
334be87839eSConrad Meyer.Fn SYSCTL_S16 parent number name ctlflags ptr val descr
335be87839eSConrad Meyer.Fn SYSCTL_S32 parent number name ctlflags ptr val descr
336be87839eSConrad Meyer.Fn SYSCTL_S64 parent number name ctlflags ptr val descr
3375eb1caa8SHans Petter Selasky.Fn SYSCTL_STRING parent number name ctlflags arg len descr
3385eb1caa8SHans Petter Selasky.Fn SYSCTL_STRUCT parent number name ctlflags ptr struct_type descr
339fb61390cSConrad Meyer.Fn SYSCTL_U8 parent number name ctlflags ptr val descr
340fb61390cSConrad Meyer.Fn SYSCTL_U16 parent number name ctlflags ptr val descr
341be87839eSConrad Meyer.Fn SYSCTL_U32 parent number name ctlflags ptr val descr
342be87839eSConrad Meyer.Fn SYSCTL_U64 parent number name ctlflags ptr val descr
3435eb1caa8SHans Petter Selasky.Fn SYSCTL_UINT parent number name ctlflags ptr val descr
3445eb1caa8SHans Petter Selasky.Fn SYSCTL_ULONG parent number name ctlflags ptr val descr
3455eb1caa8SHans Petter Selasky.Fn SYSCTL_UQUAD parent number name ctlflags ptr val descr
346dba9e9ccSRobert Watson.Sh DESCRIPTION
347dba9e9ccSRobert WatsonThe
348bd84dd2fSRuslan Ermilov.Nm SYSCTL
3495eb1caa8SHans Petter Selaskykernel interface allows dynamic or static creation of
350dba9e9ccSRobert Watson.Xr sysctl 8
3515eb1caa8SHans Petter SelaskyMIB entries.
3525eb1caa8SHans Petter SelaskyAll static sysctls are automatically destroyed when the module which
3535eb1caa8SHans Petter Selaskythey are part of is unloaded.
3545eb1caa8SHans Petter SelaskyMost top level categories are created statically and are available to
3555eb1caa8SHans Petter Selaskyall kernel code and its modules.
3565eb1caa8SHans Petter Selasky.Sh DESCRIPTION OF ARGUMENTS
3575eb1caa8SHans Petter Selasky.Bl -tag -width ctlflags
3585eb1caa8SHans Petter Selasky.It Fa ctx
3595eb1caa8SHans Petter SelaskyPointer to sysctl context or NULL, if no context.
3605eb1caa8SHans Petter SelaskySee
3615eb1caa8SHans Petter Selasky.Xr sysctl_ctx_init 9
3625eb1caa8SHans Petter Selaskyfor how to create a new sysctl context.
3635eb1caa8SHans Petter SelaskyProgrammers are strongly advised to use contexts to organize the
3645eb1caa8SHans Petter Selaskydynamic OIDs which they create because when a context is destroyed all
3655eb1caa8SHans Petter Selaskybelonging sysctls are destroyed as well.
3665eb1caa8SHans Petter SelaskyThis makes the sysctl cleanup code much simpler.
367aa88ccabSHans Petter SelaskyElse deletion of all created OIDs is required at module unload.
3685eb1caa8SHans Petter Selasky.It Fa parent
3695eb1caa8SHans Petter SelaskyA pointer to a
3705eb1caa8SHans Petter Selasky.Li struct sysctl_oid_list ,
3715eb1caa8SHans Petter Selaskywhich is the head of the parent's list of children.
372aa88ccabSHans Petter SelaskyThis pointer is retrieved using the
3735eb1caa8SHans Petter Selasky.Fn SYSCTL_STATIC_CHILDREN
3745eb1caa8SHans Petter Selaskymacro for static sysctls and the
3755eb1caa8SHans Petter Selasky.Fn SYSCTL_CHILDREN
3765eb1caa8SHans Petter Selaskymacro for dynamic sysctls.
377aa88ccabSHans Petter SelaskyThe
3785eb1caa8SHans Petter Selasky.Fn SYSCTL_PARENT
379aa88ccabSHans Petter Selaskymacro can be used to get the parent of an OID.
380aa88ccabSHans Petter SelaskyThe macro returns NULL if there is no parent.
3815eb1caa8SHans Petter Selasky.It Fa number
3825eb1caa8SHans Petter SelaskyThe OID number that will be assigned to this OID.
3835eb1caa8SHans Petter SelaskyIn almost all cases this should be set to
3845eb1caa8SHans Petter Selasky.Dv OID_AUTO ,
3855eb1caa8SHans Petter Selaskywhich will result in the assignment of the next available OID number.
3865eb1caa8SHans Petter Selasky.It Fa name
3875eb1caa8SHans Petter SelaskyThe name of the OID.
3885eb1caa8SHans Petter SelaskyThe newly created OID will contain a copy of the name.
3895eb1caa8SHans Petter Selasky.It Fa ctlflags
3905eb1caa8SHans Petter SelaskyA bit mask of sysctl control flags.
3915eb1caa8SHans Petter SelaskySee the section below describing all the control flags.
3925eb1caa8SHans Petter Selasky.It Fa arg1
3935eb1caa8SHans Petter SelaskyFirst callback argument for procedure sysctls.
3945eb1caa8SHans Petter Selasky.It Fa arg2
3955eb1caa8SHans Petter SelaskySecond callback argument for procedure sysctls.
3965eb1caa8SHans Petter Selasky.It Fa len
3975eb1caa8SHans Petter SelaskyThe length of the data pointed to by the
3985eb1caa8SHans Petter Selasky.Fa ptr
3995eb1caa8SHans Petter Selaskyargument.
4005eb1caa8SHans Petter SelaskyFor string type OIDs a length of zero means that
4015eb1caa8SHans Petter Selasky.Xr strlen 3
4025eb1caa8SHans Petter Selaskywill be used to get the length of the string at each access to the OID.
4035eb1caa8SHans Petter Selasky.It Fa ptr
4045eb1caa8SHans Petter SelaskyPointer to sysctl variable or string data.
405f0188618SHans 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
4065eb1caa8SHans Petter Selasky.Fa val
4075eb1caa8SHans Petter Selaskyargument.
4085eb1caa8SHans Petter Selasky.It Fa val
4095eb1caa8SHans Petter SelaskyIf the
4105eb1caa8SHans Petter Selasky.Fa ptr
411f0188618SHans Petter Selaskyargument is SYSCTL_NULL_XXX_PTR, gives the constant value returned by this OID.
4125eb1caa8SHans Petter SelaskyElse this argument is not used.
4135eb1caa8SHans Petter Selasky.It Fa struct_type
4145eb1caa8SHans Petter SelaskyName of structure type.
4155eb1caa8SHans Petter Selasky.It Fa handler
4165eb1caa8SHans Petter SelaskyA pointer to the function
4175eb1caa8SHans Petter Selaskythat is responsible for handling read and write requests
4185eb1caa8SHans Petter Selaskyto this OID.
4195eb1caa8SHans Petter SelaskyThere are several standard handlers
4205eb1caa8SHans Petter Selaskythat support operations on nodes,
4215eb1caa8SHans Petter Selaskyintegers, strings and opaque objects.
4225eb1caa8SHans Petter SelaskyIt is possible to define custom handlers using the
4235eb1caa8SHans Petter Selasky.Fn SYSCTL_PROC
4245eb1caa8SHans Petter Selaskymacro or the
4255eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_PROC
4265eb1caa8SHans Petter Selaskyfunction.
4275eb1caa8SHans Petter Selasky.It Fa format
4285eb1caa8SHans Petter SelaskyA pointer to a string
4295eb1caa8SHans Petter Selaskywhich specifies the format of the OID in a symbolic way.
4305eb1caa8SHans Petter SelaskyThis format is used as a hint by
4315eb1caa8SHans Petter Selasky.Xr sysctl 8
4325eb1caa8SHans Petter Selaskyto apply proper data formatting for display purposes.
433aa255ef6SWarner Losh.Pp
434aa255ef6SWarner LoshCurrent formats:
435aa255ef6SWarner Losh.Bl -tag -width "S,TYPE" -compact -offset indent
436aa255ef6SWarner Losh.It Cm N
437aa255ef6SWarner Loshnode
438aa255ef6SWarner Losh.It Cm A
439aa255ef6SWarner Losh.Li "char *"
440aa255ef6SWarner Losh.It Cm I
441aa255ef6SWarner Losh.Li "int"
442aa255ef6SWarner Losh.It Cm IK Ns Op Ar n
443aa255ef6SWarner Loshtemperature in Kelvin, multiplied by an optional single digit
444aa255ef6SWarner Loshpower of ten scaling factor: 1 (default) gives deciKelvin, 0 gives Kelvin, 3
445aa255ef6SWarner Loshgives milliKelvin
446aa255ef6SWarner Losh.It Cm IU
447aa255ef6SWarner Losh.Li "unsigned int"
448aa255ef6SWarner Losh.It Cm L
449aa255ef6SWarner Losh.Li "long"
450aa255ef6SWarner Losh.It Cm LU
451aa255ef6SWarner Losh.Li "unsigned long"
452aa255ef6SWarner Losh.It Cm Q
453aa255ef6SWarner Losh.Li "quad_t"
454aa255ef6SWarner Losh.It Cm QU
4555eb1caa8SHans Petter Selasky.Li "u_quad_t"
456aa255ef6SWarner Losh.It Cm "S,TYPE"
4575eb1caa8SHans Petter Selasky.Li "struct TYPE"
458aa255ef6SWarner Loshstructures
459aa255ef6SWarner Losh.El
4605eb1caa8SHans Petter Selasky.It Fa descr
4615eb1caa8SHans Petter SelaskyA pointer to a textual description of the OID.
4625eb1caa8SHans Petter Selasky.El
4635eb1caa8SHans Petter Selasky.Sh CREATING ROOT NODES
4645eb1caa8SHans Petter SelaskySysctl MIBs or OIDs are created in a hierarchical tree.
4655eb1caa8SHans Petter SelaskyThe nodes at the bottom of the tree are called root nodes, and have no
4665eb1caa8SHans Petter Selaskyparent OID.
4675eb1caa8SHans Petter SelaskyTo create bottom tree nodes the
4685eb1caa8SHans Petter Selasky.Fn SYSCTL_ROOT_NODE
4695eb1caa8SHans Petter Selaskymacro or the
4705eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_ROOT_NODE
4715eb1caa8SHans Petter Selaskyfunction needs to be used.
4725eb1caa8SHans Petter SelaskyBy default all static sysctl node OIDs are global and need a
4735eb1caa8SHans Petter Selasky.Fn SYSCTL_DECL
4745eb1caa8SHans Petter Selaskystatement prior to their
4755eb1caa8SHans Petter Selasky.Fn SYSCTL_NODE
4765eb1caa8SHans Petter Selaskydefinition statement, typically in a so-called header file.
4775eb1caa8SHans Petter Selasky.Sh CREATING SYSCTL STRINGS
4785eb1caa8SHans Petter SelaskyZero terminated character strings sysctls are created either using the
4795eb1caa8SHans Petter Selasky.Fn SYSCTL_STRING
4805eb1caa8SHans Petter Selaskymacro or the
4815eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_STRING
4825eb1caa8SHans Petter Selaskyfunction.
4835eb1caa8SHans Petter SelaskyIf the
4845eb1caa8SHans Petter Selasky.Fa len
4855eb1caa8SHans Petter Selaskyargument in zero, the string length is computed at every access to the OID using
4865eb1caa8SHans Petter Selasky.Xr strlen 3 .
4875eb1caa8SHans Petter Selasky.Sh CREATING OPAQUE SYSCTLS
4885eb1caa8SHans Petter SelaskyThe
4895eb1caa8SHans Petter Selasky.Fn SYSCTL_OPAQUE
4905eb1caa8SHans Petter Selaskyor
4915eb1caa8SHans Petter Selasky.Fn SYSCTL_STRUCT
4925eb1caa8SHans Petter Selaskymacros or the
4935eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_OPAQUE
4945eb1caa8SHans Petter Selaskyor
4955eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_STRUCT
4965eb1caa8SHans Petter Selaskyfunctions create an OID that handle any chunk of data
4975eb1caa8SHans Petter Selaskyof the size specified by the
4985eb1caa8SHans Petter Selasky.Fa len
4995eb1caa8SHans Petter Selaskyargument and data pointed to by the
5005eb1caa8SHans Petter Selasky.Fa ptr
5015eb1caa8SHans Petter Selaskyargument.
5025eb1caa8SHans Petter SelaskyWhen using the structure version the type is encoded as part of the
5035eb1caa8SHans Petter Selaskycreated sysctl.
5045eb1caa8SHans Petter Selasky.Sh CREATING CUSTOM SYSCTLS
5055eb1caa8SHans Petter SelaskyThe
5065eb1caa8SHans Petter Selasky.Fn SYSCTL_PROC
5075eb1caa8SHans Petter Selaskymacro and the
5085eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_PROC
5095eb1caa8SHans Petter Selaskyfunction
5105eb1caa8SHans Petter Selaskycreate OIDs with the specified
5115eb1caa8SHans Petter Selasky.Pa handler
5125eb1caa8SHans Petter Selaskyfunction.
5135eb1caa8SHans Petter SelaskyThe handler is responsible for handling all read and write requests to
5145eb1caa8SHans Petter Selaskythe OID.
5155eb1caa8SHans Petter SelaskyThis OID type is especially useful if the kernel data is not easily
5165eb1caa8SHans Petter Selaskyaccessible, or needs to be processed before exporting.
5175eb1caa8SHans Petter Selasky.Sh CREATING A STATIC SYSCTL
5185eb1caa8SHans Petter SelaskyStatic sysctls are declared using one of the
519bd84dd2fSRuslan Ermilov.Fn SYSCTL_INT ,
520bd84dd2fSRuslan Ermilov.Fn SYSCTL_LONG ,
521bd84dd2fSRuslan Ermilov.Fn SYSCTL_NODE ,
522bd84dd2fSRuslan Ermilov.Fn SYSCTL_OPAQUE ,
523bd84dd2fSRuslan Ermilov.Fn SYSCTL_PROC ,
52460a77442SJohn Baldwin.Fn SYSCTL_QUAD ,
5255eb1caa8SHans Petter Selasky.Fn SYSCTL_ROOT_NODE ,
526be87839eSConrad Meyer.Fn SYSCTL_S8 ,
527be87839eSConrad Meyer.Fn SYSCTL_S16 ,
528be87839eSConrad Meyer.Fn SYSCTL_S32 ,
529be87839eSConrad Meyer.Fn SYSCTL_S64 ,
530bd84dd2fSRuslan Ermilov.Fn SYSCTL_STRING ,
531bd84dd2fSRuslan Ermilov.Fn SYSCTL_STRUCT ,
532fb61390cSConrad Meyer.Fn SYSCTL_U8 ,
533fb61390cSConrad Meyer.Fn SYSCTL_U16 ,
534be87839eSConrad Meyer.Fn SYSCTL_U32 ,
535be87839eSConrad Meyer.Fn SYSCTL_U64 ,
536bd84dd2fSRuslan Ermilov.Fn SYSCTL_UINT ,
5375eb1caa8SHans Petter Selasky.Fn SYSCTL_ULONG
5385eb1caa8SHans Petter Selaskyor
5395eb1caa8SHans Petter Selasky.Fn SYSCTL_UQUAD
5405eb1caa8SHans Petter Selaskymacros.
5415eb1caa8SHans Petter Selasky.Sh CREATING A DYNAMIC SYSCTL
5425eb1caa8SHans Petter SelaskyDynamic nodes are created using one of the
5435eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_INT ,
5445eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_LONG ,
5455eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_NODE ,
5465eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_OPAQUE ,
5475eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_PROC ,
5485eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_QUAD ,
5495eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_ROOT_NODE ,
550be87839eSConrad Meyer.Fn SYSCTL_ADD_S8 ,
551be87839eSConrad Meyer.Fn SYSCTL_ADD_S16 ,
552be87839eSConrad Meyer.Fn SYSCTL_ADD_S32 ,
553be87839eSConrad Meyer.Fn SYSCTL_ADD_S64 ,
5545eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_STRING ,
5555eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_STRUCT ,
556fb61390cSConrad Meyer.Fn SYSCTL_ADD_U8 ,
557fb61390cSConrad Meyer.Fn SYSCTL_ADD_U16 ,
558be87839eSConrad Meyer.Fn SYSCTL_ADD_U32 ,
559be87839eSConrad Meyer.Fn SYSCTL_ADD_U64 ,
560f0188618SHans Petter Selasky.Fn SYSCTL_ADD_UAUTO ,
5615eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_UINT ,
562f0188618SHans Petter Selasky.Fn SYSCTL_ADD_ULONG ,
5635eb1caa8SHans Petter Selaskyor
5645eb1caa8SHans Petter Selasky.Fn SYSCTL_UQUAD
5655eb1caa8SHans Petter Selaskyfunctions.
5665eb1caa8SHans Petter SelaskySee
5675eb1caa8SHans Petter Selasky.Xr sysctl_remove_oid 9
5685eb1caa8SHans Petter Selaskyor
5695eb1caa8SHans Petter Selasky.Xr sysctl_ctx_free 9
5705eb1caa8SHans Petter Selaskyfor more information on how to destroy a dynamically created OID.
5715eb1caa8SHans Petter Selasky.Sh CONTROL FLAGS
5725eb1caa8SHans Petter SelaskyFor most of the above functions and macros, declaring a type as part
5735eb1caa8SHans Petter Selaskyof the access flags is not necessary \[em] however, when declaring a
5745eb1caa8SHans Petter Selaskysysctl implemented by a function, including a type in the access mask
5755eb1caa8SHans Petter Selaskyis required:
5765eb1caa8SHans Petter Selasky.Bl -tag -width ".Dv CTLTYPE_NOFETCH"
577dba9e9ccSRobert Watson.It Dv CTLTYPE_NODE
578dba9e9ccSRobert WatsonThis is a node intended to be a parent for other nodes.
579dba9e9ccSRobert Watson.It Dv CTLTYPE_INT
580dba9e9ccSRobert WatsonThis is a signed integer.
581dba9e9ccSRobert Watson.It Dv CTLTYPE_STRING
582dba9e9ccSRobert WatsonThis is a nul-terminated string stored in a character array.
583be87839eSConrad Meyer.It Dv CTLTYPE_S8
584be87839eSConrad MeyerThis is an 8-bit signed integer.
585be87839eSConrad Meyer.It Dv CTLTYPE_S16
586be87839eSConrad MeyerThis is a 16-bit signed integer.
587be87839eSConrad Meyer.It Dv CTLTYPE_S32
588be87839eSConrad MeyerThis is a 32-bit signed integer.
589cbc134adSMatthew D Fleming.It Dv CTLTYPE_S64
590dba9e9ccSRobert WatsonThis is a 64-bit signed integer.
591dba9e9ccSRobert Watson.It Dv CTLTYPE_OPAQUE
592dba9e9ccSRobert WatsonThis is an opaque data structure.
593dba9e9ccSRobert Watson.It Dv CTLTYPE_STRUCT
594dba9e9ccSRobert WatsonAlias for
595dba9e9ccSRobert Watson.Dv CTLTYPE_OPAQUE .
596fb61390cSConrad Meyer.It Dv CTLTYPE_U8
597fb61390cSConrad MeyerThis is an 8-bit unsigned integer.
598fb61390cSConrad Meyer.It Dv CTLTYPE_U16
599fb61390cSConrad MeyerThis is a 16-bit unsigned integer.
600be87839eSConrad Meyer.It Dv CTLTYPE_U32
601be87839eSConrad MeyerThis is a 32-bit unsigned integer.
602be87839eSConrad Meyer.It Dv CTLTYPE_U64
603be87839eSConrad MeyerThis is a 64-bit unsigned integer.
604dba9e9ccSRobert Watson.It Dv CTLTYPE_UINT
605dba9e9ccSRobert WatsonThis is an unsigned integer.
606dba9e9ccSRobert Watson.It Dv CTLTYPE_LONG
607dba9e9ccSRobert WatsonThis is a signed long.
608dba9e9ccSRobert Watson.It Dv CTLTYPE_ULONG
6098a1f4129SRobert WatsonThis is an unsigned long.
610dba9e9ccSRobert Watson.El
611dba9e9ccSRobert Watson.Pp
61260a77442SJohn BaldwinAll sysctl types except for new node declarations require one of the following
61360a77442SJohn Baldwinflags to be set indicating the read and write disposition of the sysctl:
614bd84dd2fSRuslan Ermilov.Bl -tag -width ".Dv CTLFLAG_ANYBODY"
615dba9e9ccSRobert Watson.It Dv CTLFLAG_RD
616dba9e9ccSRobert WatsonThis is a read-only sysctl.
61760a77442SJohn Baldwin.It Dv CTLFLAG_RDTUN
6185eb1caa8SHans Petter SelaskyThis is a read-only sysctl and tunable which is tried fetched once
6197c64ddd5SWarren Blockfrom the system environment early during module load or system boot.
620b470b929SDavid E. O'Brien.It Dv CTLFLAG_WR
621dba9e9ccSRobert WatsonThis is a writable sysctl.
622dba9e9ccSRobert Watson.It Dv CTLFLAG_RW
623dba9e9ccSRobert WatsonThis sysctl is readable and writable.
62460a77442SJohn Baldwin.It Dv CTLFLAG_RWTUN
6255eb1caa8SHans Petter SelaskyThis is a readable and writeable sysctl and tunable which is tried
6267c64ddd5SWarren Blockfetched once from the system environment early during module load or
6275eb1caa8SHans Petter Selaskysystem boot.
6285eb1caa8SHans Petter Selasky.It Dv CTLFLAG_NOFETCH
6295eb1caa8SHans Petter SelaskyIn case the node is marked as a tunable using the CTLFLAG_[XX]TUN,
6305eb1caa8SHans Petter Selaskythis flag will prevent fetching the initial value from the system
631*7851d429SEdward Tomasz Napieralaenvironment.
632*7851d429SEdward Tomasz NapieralaTypically this flag should only be used for very early
6335eb1caa8SHans Petter Selaskylow level system setup code, and not by common drivers and modules.
63460a77442SJohn Baldwin.El
63560a77442SJohn Baldwin.Pp
63660a77442SJohn BaldwinAdditionally, any of the following optional flags may also be specified:
63760a77442SJohn Baldwin.Bl -tag -width ".Dv CTLFLAG_ANYBODY"
638dba9e9ccSRobert Watson.It Dv CTLFLAG_ANYBODY
639dba9e9ccSRobert WatsonAny user or process can write to this sysctl.
640dba9e9ccSRobert Watson.It Dv CTLFLAG_SECURE
641dba9e9ccSRobert WatsonThis sysctl can be written to only if the effective securelevel of the
642bd84dd2fSRuslan Ermilovprocess is \[<=] 0.
643dba9e9ccSRobert Watson.It Dv CTLFLAG_PRISON
644dba9e9ccSRobert WatsonThis sysctl can be written to by processes in
645dba9e9ccSRobert Watson.Xr jail 2 .
646dba9e9ccSRobert Watson.It Dv CTLFLAG_SKIP
647dba9e9ccSRobert WatsonWhen iterating the sysctl name space, do not list this sysctl.
648dba9e9ccSRobert Watson.It Dv CTLFLAG_TUN
6496b9597aaSAndrew ThompsonAdvisory flag that a system tunable also exists for this variable.
6505eb1caa8SHans Petter SelaskyThe initial sysctl value is tried fetched once from the system
6517c64ddd5SWarren Blockenvironment early during module load or system boot.
6525eb1caa8SHans Petter Selasky.It Dv CTLFLAG_DYN
6535eb1caa8SHans Petter SelaskyDynamically created OIDs automatically get this flag set.
65456538e4aSGleb Smirnoff.It Dv CTLFLAG_VNET
65556538e4aSGleb SmirnoffOID references a VIMAGE-enabled variable.
656dba9e9ccSRobert Watson.El
657dba9e9ccSRobert Watson.Sh EXAMPLES
658dba9e9ccSRobert WatsonSample use of
659bd84dd2fSRuslan Ermilov.Fn SYSCTL_DECL
660bd84dd2fSRuslan Ermilovto declare the
661bd84dd2fSRuslan Ermilov.Va security
662bd84dd2fSRuslan Ermilovsysctl tree for use by new nodes:
663dba9e9ccSRobert Watson.Bd -literal -offset indent
664dba9e9ccSRobert WatsonSYSCTL_DECL(_security);
665dba9e9ccSRobert Watson.Ed
666dba9e9ccSRobert Watson.Pp
667dba9e9ccSRobert WatsonExamples of integer, opaque, string, and procedure sysctls follow:
668dba9e9ccSRobert Watson.Bd -literal -offset indent
669dba9e9ccSRobert Watson/*
670dba9e9ccSRobert Watson * Example of a constant integer value.  Notice that the control
671f0188618SHans Petter Selasky * flags are CTLFLAG_RD, the variable pointer is SYSCTL_NULL_INT_PTR,
672f0188618SHans Petter Selasky * and the value is declared.
673dba9e9ccSRobert Watson */
674f0188618SHans Petter SelaskySYSCTL_INT(_debug_sizeof, OID_AUTO, bio, CTLFLAG_RD, SYSCTL_NULL_INT_PTR,
675dba9e9ccSRobert Watson    sizeof(struct bio), "sizeof(struct bio)");
676dba9e9ccSRobert Watson
677dba9e9ccSRobert Watson/*
678dba9e9ccSRobert Watson * Example of a variable integer value.  Notice that the control
679dba9e9ccSRobert Watson * flags are CTLFLAG_RW, the variable pointer is set, and the
680dba9e9ccSRobert Watson * value is 0.
681dba9e9ccSRobert Watson */
682dba9e9ccSRobert Watsonstatic int	doingcache = 1;		/* 1 => enable the cache */
683dba9e9ccSRobert WatsonSYSCTL_INT(_debug, OID_AUTO, vfscache, CTLFLAG_RW, &doingcache, 0,
684dba9e9ccSRobert Watson    "Enable name cache");
685dba9e9ccSRobert Watson
686dba9e9ccSRobert Watson/*
687dba9e9ccSRobert Watson * Example of a variable string value.  Notice that the control
688dba9e9ccSRobert Watson * flags are CTLFLAG_RW, that the variable pointer and string
689dba9e9ccSRobert Watson * size are set.  Unlike newer sysctls, this older sysctl uses a
690dba9e9ccSRobert Watson * static oid number.
691dba9e9ccSRobert Watson */
692dba9e9ccSRobert Watsonchar kernelname[MAXPATHLEN] = "/kernel";	/* XXX bloat */
693dba9e9ccSRobert WatsonSYSCTL_STRING(_kern, KERN_BOOTFILE, bootfile, CTLFLAG_RW,
694dba9e9ccSRobert Watson    kernelname, sizeof(kernelname), "Name of kernel file booted");
695dba9e9ccSRobert Watson
696dba9e9ccSRobert Watson/*
697dba9e9ccSRobert Watson * Example of an opaque data type exported by sysctl.  Notice that
698dba9e9ccSRobert Watson * the variable pointer and size are provided, as well as a format
699dba9e9ccSRobert Watson * string for sysctl(8).
700dba9e9ccSRobert Watson */
7017c64ddd5SWarren Blockstatic l_fp pps_freq;	/* scaled frequency offset (ns/s) */
702dba9e9ccSRobert WatsonSYSCTL_OPAQUE(_kern_ntp_pll, OID_AUTO, pps_freq, CTLFLAG_RD,
703dba9e9ccSRobert Watson    &pps_freq, sizeof(pps_freq), "I", "");
704dba9e9ccSRobert Watson
705dba9e9ccSRobert Watson/*
706dba9e9ccSRobert Watson * Example of a procedure based sysctl exporting string
707dba9e9ccSRobert Watson * information.  Notice that the data type is declared, the NULL
708dba9e9ccSRobert Watson * variable pointer and 0 size, the function pointer, and the
709dba9e9ccSRobert Watson * format string for sysctl(8).
710dba9e9ccSRobert Watson */
711dba9e9ccSRobert WatsonSYSCTL_PROC(_kern_timecounter, OID_AUTO, hardware, CTLTYPE_STRING |
712dba9e9ccSRobert Watson    CTLFLAG_RW, NULL, 0, sysctl_kern_timecounter_hardware, "A",
713dba9e9ccSRobert Watson    "");
714dba9e9ccSRobert Watson.Ed
7155eb1caa8SHans Petter Selasky.Pp
7165eb1caa8SHans Petter SelaskyThe following is an example of
7175eb1caa8SHans Petter Selaskyhow to create a new top-level category
7185eb1caa8SHans Petter Selaskyand how to hook up another subtree to an existing static node.
7195eb1caa8SHans Petter SelaskyThis example does not use contexts,
7205eb1caa8SHans Petter Selaskywhich results in tedious management of all intermediate oids,
7215eb1caa8SHans Petter Selaskyas they need to be freed later on:
7225eb1caa8SHans Petter Selasky.Bd -literal -offset indent
7235eb1caa8SHans Petter Selasky#include <sys/sysctl.h>
7245eb1caa8SHans Petter Selasky ...
7255eb1caa8SHans Petter Selasky/*
7265eb1caa8SHans Petter Selasky * Need to preserve pointers to newly created subtrees,
7275eb1caa8SHans Petter Selasky * to be able to free them later:
7285eb1caa8SHans Petter Selasky */
7295eb1caa8SHans Petter Selaskystatic struct sysctl_oid *root1;
7305eb1caa8SHans Petter Selaskystatic struct sysctl_oid *root2;
7315eb1caa8SHans Petter Selaskystatic struct sysctl_oid *oidp;
7325eb1caa8SHans Petter Selaskystatic int a_int;
7335eb1caa8SHans Petter Selaskystatic char *string = "dynamic sysctl";
7345eb1caa8SHans Petter Selasky ...
7355eb1caa8SHans Petter Selasky
7365eb1caa8SHans Petter Selaskyroot1 = SYSCTL_ADD_ROOT_NODE(NULL,
7375eb1caa8SHans Petter Selasky	OID_AUTO, "newtree", CTLFLAG_RW, 0, "new top level tree");
7385eb1caa8SHans Petter Selaskyoidp = SYSCTL_ADD_INT(NULL, SYSCTL_CHILDREN(root1),
7395eb1caa8SHans Petter Selasky	OID_AUTO, "newint", CTLFLAG_RW, &a_int, 0, "new int leaf");
7405eb1caa8SHans Petter Selasky ...
7415eb1caa8SHans Petter Selaskyroot2 = SYSCTL_ADD_NODE(NULL, SYSCTL_STATIC_CHILDREN(_debug),
7425eb1caa8SHans Petter Selasky	OID_AUTO, "newtree", CTLFLAG_RW, 0, "new tree under debug");
7435eb1caa8SHans Petter Selaskyoidp = SYSCTL_ADD_STRING(NULL, SYSCTL_CHILDREN(root2),
7445eb1caa8SHans Petter Selasky	OID_AUTO, "newstring", CTLFLAG_RD, string, 0, "new string leaf");
7455eb1caa8SHans Petter Selasky.Ed
7465eb1caa8SHans Petter Selasky.Pp
7475eb1caa8SHans Petter SelaskyThis example creates the following subtrees:
7485eb1caa8SHans Petter Selasky.Bd -literal -offset indent
7495eb1caa8SHans Petter Selaskydebug.newtree.newstring
7505eb1caa8SHans Petter Selaskynewtree.newint
7515eb1caa8SHans Petter Selasky.Ed
7525eb1caa8SHans Petter Selasky.Pp
7535eb1caa8SHans Petter Selasky.Em "Care should be taken to free all OIDs once they are no longer needed!"
75491f3a6dbSYaroslav Tykhiy.Sh SYSCTL NAMING
755dba9e9ccSRobert WatsonWhen adding, modifying, or removing sysctl names, it is important to be
756dba9e9ccSRobert Watsonaware that these interfaces may be used by users, libraries, applications,
757f4006affSGiorgos Keramidasor documentation (such as published books), and are implicitly published application interfaces.
758dba9e9ccSRobert WatsonAs with other application interfaces, caution must be taken not to break
759dba9e9ccSRobert Watsonexisting applications, and to think about future use of new name spaces so as
760dba9e9ccSRobert Watsonto avoid the need to rename or remove interfaces that might be depended on in
761dba9e9ccSRobert Watsonthe future.
76291f3a6dbSYaroslav Tykhiy.Pp
76391f3a6dbSYaroslav TykhiyThe semantics chosen for a new sysctl should be as clear as possible,
76491f3a6dbSYaroslav Tykhiyand the name of the sysctl must closely reflect its semantics.
76591f3a6dbSYaroslav TykhiyTherefore the sysctl name deserves a fair amount of consideration.
76691f3a6dbSYaroslav TykhiyIt should be short but yet representative of the sysctl meaning.
76791f3a6dbSYaroslav TykhiyIf the name consists of several words, they should be separated by
76891f3a6dbSYaroslav Tykhiyunderscore characters, as in
76991f3a6dbSYaroslav Tykhiy.Va compute_summary_at_mount .
77091f3a6dbSYaroslav TykhiyUnderscore characters may be omitted only if the name consists of not more
77191f3a6dbSYaroslav Tykhiythan two words, each being not longer than four characters, as in
77291f3a6dbSYaroslav Tykhiy.Va bootfile .
77391f3a6dbSYaroslav TykhiyFor boolean sysctls, negative logic should be totally avoided.
77491f3a6dbSYaroslav TykhiyThat is, do not use names like
77591f3a6dbSYaroslav Tykhiy.Va no_foobar
77691f3a6dbSYaroslav Tykhiyor
77791f3a6dbSYaroslav Tykhiy.Va foobar_disable .
77891f3a6dbSYaroslav TykhiyThey are confusing and lead to configuration errors.
77991f3a6dbSYaroslav TykhiyUse positive logic instead:
78091f3a6dbSYaroslav Tykhiy.Va foobar ,
78191f3a6dbSYaroslav Tykhiy.Va foobar_enable .
78291f3a6dbSYaroslav Tykhiy.Pp
7835eb1caa8SHans Petter SelaskyA temporary sysctl node OID that should not be relied upon must be designated
784*7851d429SEdward Tomasz Napieralaas such by a leading underscore character in its name.
785*7851d429SEdward Tomasz NapieralaFor example:
78691f3a6dbSYaroslav Tykhiy.Va _dirty_hack .
787dba9e9ccSRobert Watson.Sh SEE ALSO
788f3066f2bSGavin Atkinson.Xr sysctl 3 ,
789dba9e9ccSRobert Watson.Xr sysctl 8 ,
790dba9e9ccSRobert Watson.Xr sysctl_add_oid 9 ,
791dba9e9ccSRobert Watson.Xr sysctl_ctx_free 9 ,
792dba9e9ccSRobert Watson.Xr sysctl_ctx_init 9 ,
793dba9e9ccSRobert Watson.Xr sysctl_remove_oid 9
794dba9e9ccSRobert Watson.Sh HISTORY
795bd84dd2fSRuslan ErmilovThe
796dba9e9ccSRobert Watson.Xr sysctl 8
797bd84dd2fSRuslan Ermilovutility first appeared in
798dba9e9ccSRobert Watson.Bx 4.4 .
799dba9e9ccSRobert Watson.Sh AUTHORS
800bd84dd2fSRuslan Ermilov.An -nosplit
801bd84dd2fSRuslan ErmilovThe
802bd84dd2fSRuslan Ermilov.Nm sysctl
803bd84dd2fSRuslan Ermilovimplementation originally found in
804dba9e9ccSRobert Watson.Bx
805dba9e9ccSRobert Watsonhas been extensively rewritten by
806dba9e9ccSRobert Watson.An Poul-Henning Kamp
807dba9e9ccSRobert Watsonin order to add support for name lookups, name space iteration, and dynamic
808dba9e9ccSRobert Watsonaddition of MIB nodes.
809dba9e9ccSRobert Watson.Pp
810dba9e9ccSRobert WatsonThis man page was written by
811dba9e9ccSRobert Watson.An Robert N. M. Watson .
8123edc2b53SJoel Dahl.Sh SECURITY CONSIDERATIONS
8133edc2b53SJoel DahlWhen creating new sysctls, careful attention should be paid to the security
8143edc2b53SJoel Dahlimplications of the monitoring or management interface being created.
8153edc2b53SJoel DahlMost sysctls present in the kernel are read-only or writable only by the
8163edc2b53SJoel Dahlsuperuser.
8173edc2b53SJoel DahlSysctls exporting extensive information on system data structures and
8183edc2b53SJoel Dahloperation, especially those implemented using procedures, will wish to
8193edc2b53SJoel Dahlimplement access control to limit the undesired exposure of information about
8203edc2b53SJoel Dahlother processes, network connections, etc.
8213edc2b53SJoel Dahl.Pp
8223edc2b53SJoel DahlThe following top level sysctl name spaces are commonly used:
8233edc2b53SJoel Dahl.Bl -tag -width ".Va regression"
8243edc2b53SJoel Dahl.It Va compat
8253edc2b53SJoel DahlCompatibility layer information.
8263edc2b53SJoel Dahl.It Va debug
8273edc2b53SJoel DahlDebugging information.
8283edc2b53SJoel DahlVarious name spaces exist under
8293edc2b53SJoel Dahl.Va debug .
8303edc2b53SJoel Dahl.It Va hw
8313edc2b53SJoel DahlHardware and device driver information.
8323edc2b53SJoel Dahl.It Va kern
8333edc2b53SJoel DahlKernel behavior tuning; generally deprecated in favor of more specific
8343edc2b53SJoel Dahlname spaces.
8353edc2b53SJoel Dahl.It Va machdep
8363edc2b53SJoel DahlMachine-dependent configuration parameters.
8373edc2b53SJoel Dahl.It Va net
8383edc2b53SJoel DahlNetwork subsystem.
8393edc2b53SJoel DahlVarious protocols have name spaces under
8403edc2b53SJoel Dahl.Va net .
8413edc2b53SJoel Dahl.It Va regression
8423edc2b53SJoel DahlRegression test configuration and information.
8433edc2b53SJoel Dahl.It Va security
8443edc2b53SJoel DahlSecurity and security-policy configuration and information.
8453edc2b53SJoel Dahl.It Va sysctl
8463edc2b53SJoel DahlReserved name space for the implementation of sysctl.
8473edc2b53SJoel Dahl.It Va user
8483edc2b53SJoel DahlConfiguration settings relating to user application behavior.
8493edc2b53SJoel DahlGenerally, configuring applications using kernel sysctls is discouraged.
8503edc2b53SJoel Dahl.It Va vfs
8513edc2b53SJoel DahlVirtual file system configuration and information.
8523edc2b53SJoel Dahl.It Va vm
8533edc2b53SJoel DahlVirtual memory subsystem configuration and information.
8543edc2b53SJoel Dahl.El
855