xref: /freebsd/share/man/man9/sysctl.9 (revision 651a790808d46b531062e7d4b4979b11bb45a2bb)
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*651a7908SJonathan T. Looney.Dd June 1, 2018
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 ,
361e1f3941SEd Schouten.Nm SYSCTL_ADD_NODE_WITH_LABEL ,
375eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_OPAQUE ,
385eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_PROC ,
395eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_QUAD ,
405eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_ROOT_NODE ,
41be87839eSConrad Meyer.Nm SYSCTL_ADD_S8 ,
42be87839eSConrad Meyer.Nm SYSCTL_ADD_S16 ,
43be87839eSConrad Meyer.Nm SYSCTL_ADD_S32 ,
44be87839eSConrad Meyer.Nm SYSCTL_ADD_S64 ,
455eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_STRING ,
465eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_STRUCT ,
47fb61390cSConrad Meyer.Nm SYSCTL_ADD_U8 ,
48fb61390cSConrad Meyer.Nm SYSCTL_ADD_U16 ,
49be87839eSConrad Meyer.Nm SYSCTL_ADD_U32 ,
50be87839eSConrad Meyer.Nm SYSCTL_ADD_U64 ,
51f0188618SHans Petter Selasky.Nm SYSCTL_ADD_UAUTO ,
525eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_UINT ,
535eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_ULONG ,
545eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_UQUAD ,
555eb1caa8SHans Petter Selasky.Nm SYSCTL_CHILDREN ,
565eb1caa8SHans Petter Selasky.Nm SYSCTL_STATIC_CHILDREN ,
575eb1caa8SHans Petter Selasky.Nm SYSCTL_NODE_CHILDREN ,
585eb1caa8SHans Petter Selasky.Nm SYSCTL_PARENT ,
59dba9e9ccSRobert Watson.Nm SYSCTL_INT ,
601e1f3941SEd Schouten.Nm SYSCTL_INT_WITH_LABEL ,
61dba9e9ccSRobert Watson.Nm SYSCTL_LONG ,
62dba9e9ccSRobert Watson.Nm SYSCTL_NODE ,
631e1f3941SEd Schouten.Nm SYSCTL_NODE_WITH_LABEL ,
64dba9e9ccSRobert Watson.Nm SYSCTL_OPAQUE ,
65dba9e9ccSRobert Watson.Nm SYSCTL_PROC ,
6660a77442SJohn Baldwin.Nm SYSCTL_QUAD ,
675eb1caa8SHans Petter Selasky.Nm SYSCTL_ROOT_NODE ,
68be87839eSConrad Meyer.Nm SYSCTL_S8 ,
69be87839eSConrad Meyer.Nm SYSCTL_S16 ,
70be87839eSConrad Meyer.Nm SYSCTL_S32 ,
71be87839eSConrad Meyer.Nm SYSCTL_S64 ,
72dba9e9ccSRobert Watson.Nm SYSCTL_STRING ,
73dba9e9ccSRobert Watson.Nm SYSCTL_STRUCT ,
74fb61390cSConrad Meyer.Nm SYSCTL_U8 ,
75fb61390cSConrad Meyer.Nm SYSCTL_U16 ,
76be87839eSConrad Meyer.Nm SYSCTL_U32 ,
77be87839eSConrad Meyer.Nm SYSCTL_U64 ,
78dba9e9ccSRobert Watson.Nm SYSCTL_UINT ,
79c157a036SDavid E. O'Brien.Nm SYSCTL_ULONG ,
8060a77442SJohn Baldwin.Nm SYSCTL_UQUAD
815eb1caa8SHans Petter Selasky.Nd Dynamic and static sysctl MIB creation functions
82dba9e9ccSRobert Watson.Sh SYNOPSIS
83*651a7908SJonathan T. Looney.In sys/param.h
84dba9e9ccSRobert Watson.In sys/sysctl.h
85bd84dd2fSRuslan Ermilov.Fn SYSCTL_DECL name
865eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
875eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_INT
885eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
895eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
905eb1caa8SHans Petter Selasky.Fa "int number"
915eb1caa8SHans Petter Selasky.Fa "const char *name"
925eb1caa8SHans Petter Selasky.Fa "int ctlflags"
935eb1caa8SHans Petter Selasky.Fa "int *ptr"
94be87839eSConrad Meyer.Fa "int val"
955eb1caa8SHans Petter Selasky.Fa "const char *descr"
965eb1caa8SHans Petter Selasky.Fc
975eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
985eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_LONG
995eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
1005eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
1015eb1caa8SHans Petter Selasky.Fa "int number"
1025eb1caa8SHans Petter Selasky.Fa "const char *name"
1035eb1caa8SHans Petter Selasky.Fa "int ctlflags"
1045eb1caa8SHans Petter Selasky.Fa "long *ptr"
1055eb1caa8SHans Petter Selasky.Fa "const char *descr"
1065eb1caa8SHans Petter Selasky.Fc
1075eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
1085eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_NODE
1095eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
1105eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
1115eb1caa8SHans Petter Selasky.Fa "int number"
1125eb1caa8SHans Petter Selasky.Fa "const char *name"
1135eb1caa8SHans Petter Selasky.Fa "int ctlflags"
1145eb1caa8SHans Petter Selasky.Fa "int (*handler)(SYSCTL_HANDLER_ARGS)"
1155eb1caa8SHans Petter Selasky.Fa "const char *descr"
1165eb1caa8SHans Petter Selasky.Fc
1175eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
1181e1f3941SEd Schouten.Fo SYSCTL_ADD_NODE_WITH_LABEL
1191e1f3941SEd Schouten.Fa "struct sysctl_ctx_list *ctx"
1201e1f3941SEd Schouten.Fa "struct sysctl_oid_list *parent"
1211e1f3941SEd Schouten.Fa "int number"
1221e1f3941SEd Schouten.Fa "const char *name"
1231e1f3941SEd Schouten.Fa "int ctlflags"
1241e1f3941SEd Schouten.Fa "int (*handler)(SYSCTL_HANDLER_ARGS)"
1251e1f3941SEd Schouten.Fa "const char *descr"
1261e1f3941SEd Schouten.Fa "const char *label"
1271e1f3941SEd Schouten.Fc
1281e1f3941SEd Schouten.Ft struct sysctl_oid *
1295eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_OPAQUE
1305eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
1315eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
1325eb1caa8SHans Petter Selasky.Fa "int number"
1335eb1caa8SHans Petter Selasky.Fa "const char *name"
1345eb1caa8SHans Petter Selasky.Fa "int ctlflags"
1355eb1caa8SHans Petter Selasky.Fa "void *ptr"
1365eb1caa8SHans Petter Selasky.Fa "intptr_t len"
1375eb1caa8SHans Petter Selasky.Fa "const char *format"
1383edc2b53SJoel Dahl.Fa "const char *descr"
1395eb1caa8SHans Petter Selasky.Fc
1405eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
1415eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_PROC
1425eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
1435eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
1445eb1caa8SHans Petter Selasky.Fa "int number"
1455eb1caa8SHans Petter Selasky.Fa "const char *name"
1465eb1caa8SHans Petter Selasky.Fa "int ctlflags"
1475eb1caa8SHans Petter Selasky.Fa "void *arg1"
1485eb1caa8SHans Petter Selasky.Fa "intptr_t arg2"
149ba9a5309SAndriy Voskoboinyk.Fa "int (*handler) (SYSCTL_HANDLER_ARGS)"
1505eb1caa8SHans Petter Selasky.Fa "const char *format"
1515eb1caa8SHans Petter Selasky.Fa "const char *descr"
1525eb1caa8SHans Petter Selasky.Fc
1535eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
1545eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_QUAD
1555eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
1565eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
1575eb1caa8SHans Petter Selasky.Fa "int number"
1585eb1caa8SHans Petter Selasky.Fa "const char *name"
1595eb1caa8SHans Petter Selasky.Fa "int ctlflags"
160be87839eSConrad Meyer.Fa "int64_t *ptr"
1615eb1caa8SHans Petter Selasky.Fa "const char *descr"
1625eb1caa8SHans Petter Selasky.Fc
1635eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
1645eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_ROOT_NODE
1655eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
1665eb1caa8SHans Petter Selasky.Fa "int number"
1675eb1caa8SHans Petter Selasky.Fa "const char *name"
1685eb1caa8SHans Petter Selasky.Fa "int ctlflags"
1695eb1caa8SHans Petter Selasky.Fa "int (*handler)(SYSCTL_HANDLER_ARGS)"
1705eb1caa8SHans Petter Selasky.Fa "const char *descr"
1715eb1caa8SHans Petter Selasky.Fc
1725eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
173be87839eSConrad Meyer.Fo SYSCTL_ADD_S8
174be87839eSConrad Meyer.Fa "struct sysctl_ctx_list *ctx"
175be87839eSConrad Meyer.Fa "struct sysctl_oid_list *parent"
176be87839eSConrad Meyer.Fa "int number"
177be87839eSConrad Meyer.Fa "const char *name"
178be87839eSConrad Meyer.Fa "int ctlflags"
179be87839eSConrad Meyer.Fa "int8_t *ptr"
180be87839eSConrad Meyer.Fa "int8_t val"
181be87839eSConrad Meyer.Fa "const char *descr"
182be87839eSConrad Meyer.Fc
183be87839eSConrad Meyer.Ft struct sysctl_oid *
184be87839eSConrad Meyer.Fo SYSCTL_ADD_S16
185be87839eSConrad Meyer.Fa "struct sysctl_ctx_list *ctx"
186be87839eSConrad Meyer.Fa "struct sysctl_oid_list *parent"
187be87839eSConrad Meyer.Fa "int number"
188be87839eSConrad Meyer.Fa "const char *name"
189be87839eSConrad Meyer.Fa "int ctlflags"
190be87839eSConrad Meyer.Fa "int16_t *ptr"
191be87839eSConrad Meyer.Fa "int16_t val"
192be87839eSConrad Meyer.Fa "const char *descr"
193be87839eSConrad Meyer.Fc
194be87839eSConrad Meyer.Ft struct sysctl_oid *
195be87839eSConrad Meyer.Fo SYSCTL_ADD_S32
196be87839eSConrad Meyer.Fa "struct sysctl_ctx_list *ctx"
197be87839eSConrad Meyer.Fa "struct sysctl_oid_list *parent"
198be87839eSConrad Meyer.Fa "int number"
199be87839eSConrad Meyer.Fa "const char *name"
200be87839eSConrad Meyer.Fa "int ctlflags"
201be87839eSConrad Meyer.Fa "int32_t *ptr"
202be87839eSConrad Meyer.Fa "int32_t val"
203be87839eSConrad Meyer.Fa "const char *descr"
204be87839eSConrad Meyer.Fc
205be87839eSConrad Meyer.Ft struct sysctl_oid *
206be87839eSConrad Meyer.Fo SYSCTL_ADD_S64
207be87839eSConrad Meyer.Fa "struct sysctl_ctx_list *ctx"
208be87839eSConrad Meyer.Fa "struct sysctl_oid_list *parent"
209be87839eSConrad Meyer.Fa "int number"
210be87839eSConrad Meyer.Fa "const char *name"
211be87839eSConrad Meyer.Fa "int ctlflags"
212be87839eSConrad Meyer.Fa "int64_t *ptr"
213be87839eSConrad Meyer.Fa "int64_t val"
214be87839eSConrad Meyer.Fa "const char *descr"
215be87839eSConrad Meyer.Fc
216be87839eSConrad Meyer.Ft struct sysctl_oid *
2175eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_STRING
2185eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
2195eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
2205eb1caa8SHans Petter Selasky.Fa "int number"
2215eb1caa8SHans Petter Selasky.Fa "const char *name"
2225eb1caa8SHans Petter Selasky.Fa "int ctlflags"
2235eb1caa8SHans Petter Selasky.Fa "char *ptr"
2245eb1caa8SHans Petter Selasky.Fa "intptr_t len"
2255eb1caa8SHans Petter Selasky.Fa "const char *descr"
2265eb1caa8SHans Petter Selasky.Fc
2275eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
2285eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_STRUCT
2295eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
2305eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
2315eb1caa8SHans Petter Selasky.Fa "int number"
2325eb1caa8SHans Petter Selasky.Fa "const char *name"
2335eb1caa8SHans Petter Selasky.Fa "int ctlflags"
2345eb1caa8SHans Petter Selasky.Fa "void *ptr"
2355eb1caa8SHans Petter Selasky.Fa struct_type
2365eb1caa8SHans Petter Selasky.Fa "const char *descr"
2375eb1caa8SHans Petter Selasky.Fc
2385eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
239fb61390cSConrad Meyer.Fo SYSCTL_ADD_U8
240fb61390cSConrad Meyer.Fa "struct sysctl_ctx_list *ctx"
241fb61390cSConrad Meyer.Fa "struct sysctl_oid_list *parent"
242fb61390cSConrad Meyer.Fa "int number"
243fb61390cSConrad Meyer.Fa "const char *name"
244fb61390cSConrad Meyer.Fa "int ctlflags"
245be87839eSConrad Meyer.Fa "uint8_t *ptr"
246be87839eSConrad Meyer.Fa "uint8_t val"
247fb61390cSConrad Meyer.Fa "const char *descr"
248fb61390cSConrad Meyer.Fc
249fb61390cSConrad Meyer.Ft struct sysctl_oid *
250fb61390cSConrad Meyer.Fo SYSCTL_ADD_U16
251fb61390cSConrad Meyer.Fa "struct sysctl_ctx_list *ctx"
252fb61390cSConrad Meyer.Fa "struct sysctl_oid_list *parent"
253fb61390cSConrad Meyer.Fa "int number"
254fb61390cSConrad Meyer.Fa "const char *name"
255fb61390cSConrad Meyer.Fa "int ctlflags"
256be87839eSConrad Meyer.Fa "uint16_t *ptr"
257be87839eSConrad Meyer.Fa "uint16_t val"
258be87839eSConrad Meyer.Fa "const char *descr"
259be87839eSConrad Meyer.Fc
260be87839eSConrad Meyer.Ft struct sysctl_oid *
261be87839eSConrad Meyer.Fo SYSCTL_ADD_U32
262be87839eSConrad Meyer.Fa "struct sysctl_ctx_list *ctx"
263be87839eSConrad Meyer.Fa "struct sysctl_oid_list *parent"
264be87839eSConrad Meyer.Fa "int number"
265be87839eSConrad Meyer.Fa "const char *name"
266be87839eSConrad Meyer.Fa "int ctlflags"
267be87839eSConrad Meyer.Fa "uint32_t *ptr"
268be87839eSConrad Meyer.Fa "uint32_t val"
269be87839eSConrad Meyer.Fa "const char *descr"
270be87839eSConrad Meyer.Fc
271be87839eSConrad Meyer.Ft struct sysctl_oid *
272be87839eSConrad Meyer.Fo SYSCTL_ADD_U64
273be87839eSConrad Meyer.Fa "struct sysctl_ctx_list *ctx"
274be87839eSConrad Meyer.Fa "struct sysctl_oid_list *parent"
275be87839eSConrad Meyer.Fa "int number"
276be87839eSConrad Meyer.Fa "const char *name"
277be87839eSConrad Meyer.Fa "int ctlflags"
278be87839eSConrad Meyer.Fa "uint64_t *ptr"
279be87839eSConrad Meyer.Fa "uint64_t val"
280fb61390cSConrad Meyer.Fa "const char *descr"
281fb61390cSConrad Meyer.Fc
282fb61390cSConrad Meyer.Ft struct sysctl_oid *
2835eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_UINT
2845eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
2855eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
2865eb1caa8SHans Petter Selasky.Fa "int number"
2875eb1caa8SHans Petter Selasky.Fa "const char *name"
2885eb1caa8SHans Petter Selasky.Fa "int ctlflags"
2895eb1caa8SHans Petter Selasky.Fa "unsigned int *ptr"
290be87839eSConrad Meyer.Fa "unsigned int val"
2915eb1caa8SHans Petter Selasky.Fa "const char *descr"
2925eb1caa8SHans Petter Selasky.Fc
2935eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
2945eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_ULONG
2955eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
2965eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
2975eb1caa8SHans Petter Selasky.Fa "int number"
2985eb1caa8SHans Petter Selasky.Fa "const char *name"
2995eb1caa8SHans Petter Selasky.Fa "int ctlflags"
3005eb1caa8SHans Petter Selasky.Fa "unsigned long *ptr"
3015eb1caa8SHans Petter Selasky.Fa "const char *descr"
3025eb1caa8SHans Petter Selasky.Fc
3035eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
3045eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_UQUAD
3055eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
3065eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
3075eb1caa8SHans Petter Selasky.Fa "int number"
3085eb1caa8SHans Petter Selasky.Fa "const char *name"
3095eb1caa8SHans Petter Selasky.Fa "int ctlflags"
310be87839eSConrad Meyer.Fa "uint64_t *ptr"
311f0188618SHans Petter Selasky.Fa "const char *descr"
312f0188618SHans Petter Selasky.Fc
313f0188618SHans Petter Selasky.Ft struct sysctl_oid *
314f0188618SHans Petter Selasky.Fo SYSCTL_ADD_UAUTO
315f0188618SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx"
316f0188618SHans Petter Selasky.Fa "struct sysctl_oid_list *parent"
317f0188618SHans Petter Selasky.Fa "int number"
318f0188618SHans Petter Selasky.Fa "const char *name"
319f0188618SHans Petter Selasky.Fa "int ctlflags"
320f0188618SHans Petter Selasky.Fa "void *ptr"
3215eb1caa8SHans Petter Selasky.Fa "const char *descr"
3225eb1caa8SHans Petter Selasky.Fc
3235eb1caa8SHans Petter Selasky.Ft struct sysctl_oid_list *
3245eb1caa8SHans Petter Selasky.Fo SYSCTL_CHILDREN
3255eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid *oidp"
3265eb1caa8SHans Petter Selasky.Fc
3275eb1caa8SHans Petter Selasky.Ft struct sysctl_oid_list *
3285eb1caa8SHans Petter Selasky.Fo SYSCTL_STATIC_CHILDREN
3295eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list OID_NAME"
3305eb1caa8SHans Petter Selasky.Fc
3315eb1caa8SHans Petter Selasky.Ft struct sysctl_oid_list *
3325eb1caa8SHans Petter Selasky.Fo SYSCTL_NODE_CHILDREN
3335eb1caa8SHans Petter Selasky.Fa "parent"
3345eb1caa8SHans Petter Selasky.Fa "name"
3355eb1caa8SHans Petter Selasky.Fc
3365eb1caa8SHans Petter Selasky.Ft struct sysctl_oid *
3375eb1caa8SHans Petter Selasky.Fo SYSCTL_PARENT
3385eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid *oid"
3395eb1caa8SHans Petter Selasky.Fc
3405eb1caa8SHans Petter Selasky.Fn SYSCTL_INT parent number name ctlflags ptr val descr
3411e1f3941SEd Schouten.Fn SYSCTL_INT_WITH_LABEL parent number name ctlflags ptr val descr label
3425eb1caa8SHans Petter Selasky.Fn SYSCTL_LONG parent number name ctlflags ptr val descr
3435eb1caa8SHans Petter Selasky.Fn SYSCTL_NODE parent number name ctlflags handler descr
3441e1f3941SEd Schouten.Fn SYSCTL_NODE_WITH_LABEL parent number name ctlflags handler descr label
3455eb1caa8SHans Petter Selasky.Fn SYSCTL_OPAQUE parent number name ctlflags ptr len format descr
3465eb1caa8SHans Petter Selasky.Fn SYSCTL_PROC parent number name ctlflags arg1 arg2 handler format descr
3475eb1caa8SHans Petter Selasky.Fn SYSCTL_QUAD parent number name ctlflags ptr val descr
348be87839eSConrad Meyer.Fn SYSCTL_ROOT_NODE number name ctlflags handler descr
349be87839eSConrad Meyer.Fn SYSCTL_S8 parent number name ctlflags ptr val descr
350be87839eSConrad Meyer.Fn SYSCTL_S16 parent number name ctlflags ptr val descr
351be87839eSConrad Meyer.Fn SYSCTL_S32 parent number name ctlflags ptr val descr
352be87839eSConrad Meyer.Fn SYSCTL_S64 parent number name ctlflags ptr val descr
3535eb1caa8SHans Petter Selasky.Fn SYSCTL_STRING parent number name ctlflags arg len descr
3545eb1caa8SHans Petter Selasky.Fn SYSCTL_STRUCT parent number name ctlflags ptr struct_type descr
355fb61390cSConrad Meyer.Fn SYSCTL_U8 parent number name ctlflags ptr val descr
356fb61390cSConrad Meyer.Fn SYSCTL_U16 parent number name ctlflags ptr val descr
357be87839eSConrad Meyer.Fn SYSCTL_U32 parent number name ctlflags ptr val descr
358be87839eSConrad Meyer.Fn SYSCTL_U64 parent number name ctlflags ptr val descr
3595eb1caa8SHans Petter Selasky.Fn SYSCTL_UINT parent number name ctlflags ptr val descr
3605eb1caa8SHans Petter Selasky.Fn SYSCTL_ULONG parent number name ctlflags ptr val descr
3615eb1caa8SHans Petter Selasky.Fn SYSCTL_UQUAD parent number name ctlflags ptr val descr
362dba9e9ccSRobert Watson.Sh DESCRIPTION
363dba9e9ccSRobert WatsonThe
364bd84dd2fSRuslan Ermilov.Nm SYSCTL
3655eb1caa8SHans Petter Selaskykernel interface allows dynamic or static creation of
366dba9e9ccSRobert Watson.Xr sysctl 8
3675eb1caa8SHans Petter SelaskyMIB entries.
3685eb1caa8SHans Petter SelaskyAll static sysctls are automatically destroyed when the module which
3695eb1caa8SHans Petter Selaskythey are part of is unloaded.
3705eb1caa8SHans Petter SelaskyMost top level categories are created statically and are available to
3715eb1caa8SHans Petter Selaskyall kernel code and its modules.
3725eb1caa8SHans Petter Selasky.Sh DESCRIPTION OF ARGUMENTS
3735eb1caa8SHans Petter Selasky.Bl -tag -width ctlflags
3745eb1caa8SHans Petter Selasky.It Fa ctx
3755eb1caa8SHans Petter SelaskyPointer to sysctl context or NULL, if no context.
3765eb1caa8SHans Petter SelaskySee
3775eb1caa8SHans Petter Selasky.Xr sysctl_ctx_init 9
3785eb1caa8SHans Petter Selaskyfor how to create a new sysctl context.
3795eb1caa8SHans Petter SelaskyProgrammers are strongly advised to use contexts to organize the
3805eb1caa8SHans Petter Selaskydynamic OIDs which they create because when a context is destroyed all
3815eb1caa8SHans Petter Selaskybelonging sysctls are destroyed as well.
3825eb1caa8SHans Petter SelaskyThis makes the sysctl cleanup code much simpler.
383aa88ccabSHans Petter SelaskyElse deletion of all created OIDs is required at module unload.
3845eb1caa8SHans Petter Selasky.It Fa parent
3855eb1caa8SHans Petter SelaskyA pointer to a
3865eb1caa8SHans Petter Selasky.Li struct sysctl_oid_list ,
3875eb1caa8SHans Petter Selaskywhich is the head of the parent's list of children.
388aa88ccabSHans Petter SelaskyThis pointer is retrieved using the
3895eb1caa8SHans Petter Selasky.Fn SYSCTL_STATIC_CHILDREN
3905eb1caa8SHans Petter Selaskymacro for static sysctls and the
3915eb1caa8SHans Petter Selasky.Fn SYSCTL_CHILDREN
3925eb1caa8SHans Petter Selaskymacro for dynamic sysctls.
393aa88ccabSHans Petter SelaskyThe
3945eb1caa8SHans Petter Selasky.Fn SYSCTL_PARENT
395aa88ccabSHans Petter Selaskymacro can be used to get the parent of an OID.
396aa88ccabSHans Petter SelaskyThe macro returns NULL if there is no parent.
3975eb1caa8SHans Petter Selasky.It Fa number
3985eb1caa8SHans Petter SelaskyThe OID number that will be assigned to this OID.
3995eb1caa8SHans Petter SelaskyIn almost all cases this should be set to
4005eb1caa8SHans Petter Selasky.Dv OID_AUTO ,
4015eb1caa8SHans Petter Selaskywhich will result in the assignment of the next available OID number.
4025eb1caa8SHans Petter Selasky.It Fa name
4035eb1caa8SHans Petter SelaskyThe name of the OID.
4045eb1caa8SHans Petter SelaskyThe newly created OID will contain a copy of the name.
4055eb1caa8SHans Petter Selasky.It Fa ctlflags
4065eb1caa8SHans Petter SelaskyA bit mask of sysctl control flags.
4075eb1caa8SHans Petter SelaskySee the section below describing all the control flags.
4085eb1caa8SHans Petter Selasky.It Fa arg1
4095eb1caa8SHans Petter SelaskyFirst callback argument for procedure sysctls.
4105eb1caa8SHans Petter Selasky.It Fa arg2
4115eb1caa8SHans Petter SelaskySecond callback argument for procedure sysctls.
4125eb1caa8SHans Petter Selasky.It Fa len
4135eb1caa8SHans Petter SelaskyThe length of the data pointed to by the
4145eb1caa8SHans Petter Selasky.Fa ptr
4155eb1caa8SHans Petter Selaskyargument.
4165eb1caa8SHans Petter SelaskyFor string type OIDs a length of zero means that
4175eb1caa8SHans Petter Selasky.Xr strlen 3
4185eb1caa8SHans Petter Selaskywill be used to get the length of the string at each access to the OID.
4195eb1caa8SHans Petter Selasky.It Fa ptr
4205eb1caa8SHans Petter SelaskyPointer to sysctl variable or string data.
421f0188618SHans 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
4225eb1caa8SHans Petter Selasky.Fa val
4235eb1caa8SHans Petter Selaskyargument.
4245eb1caa8SHans Petter Selasky.It Fa val
4255eb1caa8SHans Petter SelaskyIf the
4265eb1caa8SHans Petter Selasky.Fa ptr
427f0188618SHans Petter Selaskyargument is SYSCTL_NULL_XXX_PTR, gives the constant value returned by this OID.
4285eb1caa8SHans Petter SelaskyElse this argument is not used.
4295eb1caa8SHans Petter Selasky.It Fa struct_type
4305eb1caa8SHans Petter SelaskyName of structure type.
4315eb1caa8SHans Petter Selasky.It Fa handler
4325eb1caa8SHans Petter SelaskyA pointer to the function
4335eb1caa8SHans Petter Selaskythat is responsible for handling read and write requests
4345eb1caa8SHans Petter Selaskyto this OID.
4355eb1caa8SHans Petter SelaskyThere are several standard handlers
4365eb1caa8SHans Petter Selaskythat support operations on nodes,
4375eb1caa8SHans Petter Selaskyintegers, strings and opaque objects.
4385eb1caa8SHans Petter SelaskyIt is possible to define custom handlers using the
4395eb1caa8SHans Petter Selasky.Fn SYSCTL_PROC
4405eb1caa8SHans Petter Selaskymacro or the
4415eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_PROC
4425eb1caa8SHans Petter Selaskyfunction.
4435eb1caa8SHans Petter Selasky.It Fa format
4445eb1caa8SHans Petter SelaskyA pointer to a string
4455eb1caa8SHans Petter Selaskywhich specifies the format of the OID in a symbolic way.
4465eb1caa8SHans Petter SelaskyThis format is used as a hint by
4475eb1caa8SHans Petter Selasky.Xr sysctl 8
4485eb1caa8SHans Petter Selaskyto apply proper data formatting for display purposes.
449aa255ef6SWarner Losh.Pp
450aa255ef6SWarner LoshCurrent formats:
451aa255ef6SWarner Losh.Bl -tag -width "S,TYPE" -compact -offset indent
452aa255ef6SWarner Losh.It Cm N
453aa255ef6SWarner Loshnode
454aa255ef6SWarner Losh.It Cm A
455aa255ef6SWarner Losh.Li "char *"
456aa255ef6SWarner Losh.It Cm I
457aa255ef6SWarner Losh.Li "int"
458aa255ef6SWarner Losh.It Cm IK Ns Op Ar n
459aa255ef6SWarner Loshtemperature in Kelvin, multiplied by an optional single digit
460aa255ef6SWarner Loshpower of ten scaling factor: 1 (default) gives deciKelvin, 0 gives Kelvin, 3
461aa255ef6SWarner Loshgives milliKelvin
462aa255ef6SWarner Losh.It Cm IU
463aa255ef6SWarner Losh.Li "unsigned int"
464aa255ef6SWarner Losh.It Cm L
465aa255ef6SWarner Losh.Li "long"
466aa255ef6SWarner Losh.It Cm LU
467aa255ef6SWarner Losh.Li "unsigned long"
468aa255ef6SWarner Losh.It Cm Q
469aa255ef6SWarner Losh.Li "quad_t"
470aa255ef6SWarner Losh.It Cm QU
4715eb1caa8SHans Petter Selasky.Li "u_quad_t"
472aa255ef6SWarner Losh.It Cm "S,TYPE"
4735eb1caa8SHans Petter Selasky.Li "struct TYPE"
474aa255ef6SWarner Loshstructures
475aa255ef6SWarner Losh.El
4765eb1caa8SHans Petter Selasky.It Fa descr
4775eb1caa8SHans Petter SelaskyA pointer to a textual description of the OID.
4781e1f3941SEd Schouten.It Fa label
4791e1f3941SEd SchoutenA pointer to an aggregation label for this component of the OID.
4801e1f3941SEd SchoutenTo make it easier to export sysctl data to monitoring systems that
4811e1f3941SEd Schoutensupport aggregations through labels (e.g., Prometheus),
4821e1f3941SEd Schoutenthis argument can be used to attach a label name to an OID.
4831e1f3941SEd SchoutenThe label acts as a hint that this component's name should not be part
4841e1f3941SEd Schoutenof the metric's name,
4851e1f3941SEd Schoutenbut attached to the metric as a label instead.
4861e1f3941SEd Schouten.Pp
4871e1f3941SEd SchoutenLabels should only be applied to siblings that are structurally similar
4881e1f3941SEd Schoutenand encode the same type of value,
4891e1f3941SEd Schoutenas aggregation is of no use otherwise.
4905eb1caa8SHans Petter Selasky.El
4915eb1caa8SHans Petter Selasky.Sh CREATING ROOT NODES
4925eb1caa8SHans Petter SelaskySysctl MIBs or OIDs are created in a hierarchical tree.
4935eb1caa8SHans Petter SelaskyThe nodes at the bottom of the tree are called root nodes, and have no
4945eb1caa8SHans Petter Selaskyparent OID.
4955eb1caa8SHans Petter SelaskyTo create bottom tree nodes the
4965eb1caa8SHans Petter Selasky.Fn SYSCTL_ROOT_NODE
4975eb1caa8SHans Petter Selaskymacro or the
4985eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_ROOT_NODE
4995eb1caa8SHans Petter Selaskyfunction needs to be used.
5005eb1caa8SHans Petter SelaskyBy default all static sysctl node OIDs are global and need a
5015eb1caa8SHans Petter Selasky.Fn SYSCTL_DECL
5025eb1caa8SHans Petter Selaskystatement prior to their
5035eb1caa8SHans Petter Selasky.Fn SYSCTL_NODE
5045eb1caa8SHans Petter Selaskydefinition statement, typically in a so-called header file.
5055eb1caa8SHans Petter Selasky.Sh CREATING SYSCTL STRINGS
5065eb1caa8SHans Petter SelaskyZero terminated character strings sysctls are created either using the
5075eb1caa8SHans Petter Selasky.Fn SYSCTL_STRING
5085eb1caa8SHans Petter Selaskymacro or the
5095eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_STRING
5105eb1caa8SHans Petter Selaskyfunction.
5115eb1caa8SHans Petter SelaskyIf the
5125eb1caa8SHans Petter Selasky.Fa len
5135eb1caa8SHans Petter Selaskyargument in zero, the string length is computed at every access to the OID using
5145eb1caa8SHans Petter Selasky.Xr strlen 3 .
5155eb1caa8SHans Petter Selasky.Sh CREATING OPAQUE SYSCTLS
5165eb1caa8SHans Petter SelaskyThe
5175eb1caa8SHans Petter Selasky.Fn SYSCTL_OPAQUE
5185eb1caa8SHans Petter Selaskyor
5195eb1caa8SHans Petter Selasky.Fn SYSCTL_STRUCT
5205eb1caa8SHans Petter Selaskymacros or the
5215eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_OPAQUE
5225eb1caa8SHans Petter Selaskyor
5235eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_STRUCT
5245eb1caa8SHans Petter Selaskyfunctions create an OID that handle any chunk of data
5255eb1caa8SHans Petter Selaskyof the size specified by the
5265eb1caa8SHans Petter Selasky.Fa len
5275eb1caa8SHans Petter Selaskyargument and data pointed to by the
5285eb1caa8SHans Petter Selasky.Fa ptr
5295eb1caa8SHans Petter Selaskyargument.
5305eb1caa8SHans Petter SelaskyWhen using the structure version the type is encoded as part of the
5315eb1caa8SHans Petter Selaskycreated sysctl.
5325eb1caa8SHans Petter Selasky.Sh CREATING CUSTOM SYSCTLS
5335eb1caa8SHans Petter SelaskyThe
5345eb1caa8SHans Petter Selasky.Fn SYSCTL_PROC
5355eb1caa8SHans Petter Selaskymacro and the
5365eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_PROC
5375eb1caa8SHans Petter Selaskyfunction
5385eb1caa8SHans Petter Selaskycreate OIDs with the specified
5395eb1caa8SHans Petter Selasky.Pa handler
5405eb1caa8SHans Petter Selaskyfunction.
5415eb1caa8SHans Petter SelaskyThe handler is responsible for handling all read and write requests to
5425eb1caa8SHans Petter Selaskythe OID.
5435eb1caa8SHans Petter SelaskyThis OID type is especially useful if the kernel data is not easily
5445eb1caa8SHans Petter Selaskyaccessible, or needs to be processed before exporting.
5455eb1caa8SHans Petter Selasky.Sh CREATING A STATIC SYSCTL
5465eb1caa8SHans Petter SelaskyStatic sysctls are declared using one of the
547bd84dd2fSRuslan Ermilov.Fn SYSCTL_INT ,
5481e1f3941SEd Schouten.Fn SYSCTL_INT_WITH_LABEL ,
549bd84dd2fSRuslan Ermilov.Fn SYSCTL_LONG ,
550bd84dd2fSRuslan Ermilov.Fn SYSCTL_NODE ,
5511e1f3941SEd Schouten.Fn SYSCTL_NODE_WITH_LABEL ,
552bd84dd2fSRuslan Ermilov.Fn SYSCTL_OPAQUE ,
553bd84dd2fSRuslan Ermilov.Fn SYSCTL_PROC ,
55460a77442SJohn Baldwin.Fn SYSCTL_QUAD ,
5555eb1caa8SHans Petter Selasky.Fn SYSCTL_ROOT_NODE ,
556be87839eSConrad Meyer.Fn SYSCTL_S8 ,
557be87839eSConrad Meyer.Fn SYSCTL_S16 ,
558be87839eSConrad Meyer.Fn SYSCTL_S32 ,
559be87839eSConrad Meyer.Fn SYSCTL_S64 ,
560bd84dd2fSRuslan Ermilov.Fn SYSCTL_STRING ,
561bd84dd2fSRuslan Ermilov.Fn SYSCTL_STRUCT ,
562fb61390cSConrad Meyer.Fn SYSCTL_U8 ,
563fb61390cSConrad Meyer.Fn SYSCTL_U16 ,
564be87839eSConrad Meyer.Fn SYSCTL_U32 ,
565be87839eSConrad Meyer.Fn SYSCTL_U64 ,
566bd84dd2fSRuslan Ermilov.Fn SYSCTL_UINT ,
5675eb1caa8SHans Petter Selasky.Fn SYSCTL_ULONG
5685eb1caa8SHans Petter Selaskyor
5695eb1caa8SHans Petter Selasky.Fn SYSCTL_UQUAD
5705eb1caa8SHans Petter Selaskymacros.
5715eb1caa8SHans Petter Selasky.Sh CREATING A DYNAMIC SYSCTL
5725eb1caa8SHans Petter SelaskyDynamic nodes are created using one of the
5735eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_INT ,
5745eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_LONG ,
5755eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_NODE ,
5761e1f3941SEd Schouten.Fn SYSCTL_ADD_NODE_WITH_LABEL ,
5775eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_OPAQUE ,
5785eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_PROC ,
5795eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_QUAD ,
5805eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_ROOT_NODE ,
581be87839eSConrad Meyer.Fn SYSCTL_ADD_S8 ,
582be87839eSConrad Meyer.Fn SYSCTL_ADD_S16 ,
583be87839eSConrad Meyer.Fn SYSCTL_ADD_S32 ,
584be87839eSConrad Meyer.Fn SYSCTL_ADD_S64 ,
5855eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_STRING ,
5865eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_STRUCT ,
587fb61390cSConrad Meyer.Fn SYSCTL_ADD_U8 ,
588fb61390cSConrad Meyer.Fn SYSCTL_ADD_U16 ,
589be87839eSConrad Meyer.Fn SYSCTL_ADD_U32 ,
590be87839eSConrad Meyer.Fn SYSCTL_ADD_U64 ,
591f0188618SHans Petter Selasky.Fn SYSCTL_ADD_UAUTO ,
5925eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_UINT ,
593f0188618SHans Petter Selasky.Fn SYSCTL_ADD_ULONG ,
5945eb1caa8SHans Petter Selaskyor
5955eb1caa8SHans Petter Selasky.Fn SYSCTL_UQUAD
5965eb1caa8SHans Petter Selaskyfunctions.
5975eb1caa8SHans Petter SelaskySee
5985eb1caa8SHans Petter Selasky.Xr sysctl_remove_oid 9
5995eb1caa8SHans Petter Selaskyor
6005eb1caa8SHans Petter Selasky.Xr sysctl_ctx_free 9
6015eb1caa8SHans Petter Selaskyfor more information on how to destroy a dynamically created OID.
6025eb1caa8SHans Petter Selasky.Sh CONTROL FLAGS
6035eb1caa8SHans Petter SelaskyFor most of the above functions and macros, declaring a type as part
6045eb1caa8SHans Petter Selaskyof the access flags is not necessary \[em] however, when declaring a
6055eb1caa8SHans Petter Selaskysysctl implemented by a function, including a type in the access mask
6065eb1caa8SHans Petter Selaskyis required:
6075eb1caa8SHans Petter Selasky.Bl -tag -width ".Dv CTLTYPE_NOFETCH"
608dba9e9ccSRobert Watson.It Dv CTLTYPE_NODE
609dba9e9ccSRobert WatsonThis is a node intended to be a parent for other nodes.
610dba9e9ccSRobert Watson.It Dv CTLTYPE_INT
611dba9e9ccSRobert WatsonThis is a signed integer.
612dba9e9ccSRobert Watson.It Dv CTLTYPE_STRING
613dba9e9ccSRobert WatsonThis is a nul-terminated string stored in a character array.
614be87839eSConrad Meyer.It Dv CTLTYPE_S8
615be87839eSConrad MeyerThis is an 8-bit signed integer.
616be87839eSConrad Meyer.It Dv CTLTYPE_S16
617be87839eSConrad MeyerThis is a 16-bit signed integer.
618be87839eSConrad Meyer.It Dv CTLTYPE_S32
619be87839eSConrad MeyerThis is a 32-bit signed integer.
620cbc134adSMatthew D Fleming.It Dv CTLTYPE_S64
621dba9e9ccSRobert WatsonThis is a 64-bit signed integer.
622dba9e9ccSRobert Watson.It Dv CTLTYPE_OPAQUE
623dba9e9ccSRobert WatsonThis is an opaque data structure.
624dba9e9ccSRobert Watson.It Dv CTLTYPE_STRUCT
625dba9e9ccSRobert WatsonAlias for
626dba9e9ccSRobert Watson.Dv CTLTYPE_OPAQUE .
627fb61390cSConrad Meyer.It Dv CTLTYPE_U8
628fb61390cSConrad MeyerThis is an 8-bit unsigned integer.
629fb61390cSConrad Meyer.It Dv CTLTYPE_U16
630fb61390cSConrad MeyerThis is a 16-bit unsigned integer.
631be87839eSConrad Meyer.It Dv CTLTYPE_U32
632be87839eSConrad MeyerThis is a 32-bit unsigned integer.
633be87839eSConrad Meyer.It Dv CTLTYPE_U64
634be87839eSConrad MeyerThis is a 64-bit unsigned integer.
635dba9e9ccSRobert Watson.It Dv CTLTYPE_UINT
636dba9e9ccSRobert WatsonThis is an unsigned integer.
637dba9e9ccSRobert Watson.It Dv CTLTYPE_LONG
638dba9e9ccSRobert WatsonThis is a signed long.
639dba9e9ccSRobert Watson.It Dv CTLTYPE_ULONG
6408a1f4129SRobert WatsonThis is an unsigned long.
641dba9e9ccSRobert Watson.El
642dba9e9ccSRobert Watson.Pp
64360a77442SJohn BaldwinAll sysctl types except for new node declarations require one of the following
64460a77442SJohn Baldwinflags to be set indicating the read and write disposition of the sysctl:
645bd84dd2fSRuslan Ermilov.Bl -tag -width ".Dv CTLFLAG_ANYBODY"
646dba9e9ccSRobert Watson.It Dv CTLFLAG_RD
647dba9e9ccSRobert WatsonThis is a read-only sysctl.
64860a77442SJohn Baldwin.It Dv CTLFLAG_RDTUN
6495eb1caa8SHans Petter SelaskyThis is a read-only sysctl and tunable which is tried fetched once
6507c64ddd5SWarren Blockfrom the system environment early during module load or system boot.
651b470b929SDavid E. O'Brien.It Dv CTLFLAG_WR
652dba9e9ccSRobert WatsonThis is a writable sysctl.
653dba9e9ccSRobert Watson.It Dv CTLFLAG_RW
654dba9e9ccSRobert WatsonThis sysctl is readable and writable.
65560a77442SJohn Baldwin.It Dv CTLFLAG_RWTUN
6565eb1caa8SHans Petter SelaskyThis is a readable and writeable sysctl and tunable which is tried
6577c64ddd5SWarren Blockfetched once from the system environment early during module load or
6585eb1caa8SHans Petter Selaskysystem boot.
6595eb1caa8SHans Petter Selasky.It Dv CTLFLAG_NOFETCH
6605eb1caa8SHans Petter SelaskyIn case the node is marked as a tunable using the CTLFLAG_[XX]TUN,
6615eb1caa8SHans Petter Selaskythis flag will prevent fetching the initial value from the system
6627851d429SEdward Tomasz Napieralaenvironment.
6637851d429SEdward Tomasz NapieralaTypically this flag should only be used for very early
6645eb1caa8SHans Petter Selaskylow level system setup code, and not by common drivers and modules.
665982a973eSWarner Losh.It Dv CTLFLAG_MPSAFE
666982a973eSWarner LoshThis
667982a973eSWarner Losh.Xr sysctl 9
668982a973eSWarner Loshhandler is MP safe.
669982a973eSWarner LoshDo not grab Giant around calls to this handler.
670d132d4caSWarner LoshThis should only be used for
671d132d4caSWarner Losh.Fn SYSCTL_PROC
672d132d4caSWarner Loshentries.
67360a77442SJohn Baldwin.El
67460a77442SJohn Baldwin.Pp
67560a77442SJohn BaldwinAdditionally, any of the following optional flags may also be specified:
67660a77442SJohn Baldwin.Bl -tag -width ".Dv CTLFLAG_ANYBODY"
677dba9e9ccSRobert Watson.It Dv CTLFLAG_ANYBODY
678dba9e9ccSRobert WatsonAny user or process can write to this sysctl.
679e3127092SEd Maste.It Dv CTLFLAG_CAPRD
680e3127092SEd MasteA process in capability mode can read from this sysctl.
681e3127092SEd Maste.It Dv CTLFLAG_CAPWR
682e3127092SEd MasteA process in capability mode can write to this sysctl.
683dba9e9ccSRobert Watson.It Dv CTLFLAG_SECURE
684dba9e9ccSRobert WatsonThis sysctl can be written to only if the effective securelevel of the
685bd84dd2fSRuslan Ermilovprocess is \[<=] 0.
686dba9e9ccSRobert Watson.It Dv CTLFLAG_PRISON
687dba9e9ccSRobert WatsonThis sysctl can be written to by processes in
688dba9e9ccSRobert Watson.Xr jail 2 .
689dba9e9ccSRobert Watson.It Dv CTLFLAG_SKIP
690dba9e9ccSRobert WatsonWhen iterating the sysctl name space, do not list this sysctl.
691dba9e9ccSRobert Watson.It Dv CTLFLAG_TUN
6926b9597aaSAndrew ThompsonAdvisory flag that a system tunable also exists for this variable.
6935eb1caa8SHans Petter SelaskyThe initial sysctl value is tried fetched once from the system
6947c64ddd5SWarren Blockenvironment early during module load or system boot.
6955eb1caa8SHans Petter Selasky.It Dv CTLFLAG_DYN
6965eb1caa8SHans Petter SelaskyDynamically created OIDs automatically get this flag set.
69756538e4aSGleb Smirnoff.It Dv CTLFLAG_VNET
69856538e4aSGleb SmirnoffOID references a VIMAGE-enabled variable.
699dba9e9ccSRobert Watson.El
700dba9e9ccSRobert Watson.Sh EXAMPLES
701dba9e9ccSRobert WatsonSample use of
702bd84dd2fSRuslan Ermilov.Fn SYSCTL_DECL
703bd84dd2fSRuslan Ermilovto declare the
704bd84dd2fSRuslan Ermilov.Va security
705bd84dd2fSRuslan Ermilovsysctl tree for use by new nodes:
706dba9e9ccSRobert Watson.Bd -literal -offset indent
707dba9e9ccSRobert WatsonSYSCTL_DECL(_security);
708dba9e9ccSRobert Watson.Ed
709dba9e9ccSRobert Watson.Pp
710dba9e9ccSRobert WatsonExamples of integer, opaque, string, and procedure sysctls follow:
711dba9e9ccSRobert Watson.Bd -literal -offset indent
712dba9e9ccSRobert Watson/*
713dba9e9ccSRobert Watson * Example of a constant integer value.  Notice that the control
714f0188618SHans Petter Selasky * flags are CTLFLAG_RD, the variable pointer is SYSCTL_NULL_INT_PTR,
715f0188618SHans Petter Selasky * and the value is declared.
716dba9e9ccSRobert Watson */
717f0188618SHans Petter SelaskySYSCTL_INT(_debug_sizeof, OID_AUTO, bio, CTLFLAG_RD, SYSCTL_NULL_INT_PTR,
718dba9e9ccSRobert Watson    sizeof(struct bio), "sizeof(struct bio)");
719dba9e9ccSRobert Watson
720dba9e9ccSRobert Watson/*
721dba9e9ccSRobert Watson * Example of a variable integer value.  Notice that the control
722dba9e9ccSRobert Watson * flags are CTLFLAG_RW, the variable pointer is set, and the
723dba9e9ccSRobert Watson * value is 0.
724dba9e9ccSRobert Watson */
725dba9e9ccSRobert Watsonstatic int	doingcache = 1;		/* 1 => enable the cache */
726dba9e9ccSRobert WatsonSYSCTL_INT(_debug, OID_AUTO, vfscache, CTLFLAG_RW, &doingcache, 0,
727dba9e9ccSRobert Watson    "Enable name cache");
728dba9e9ccSRobert Watson
729dba9e9ccSRobert Watson/*
730dba9e9ccSRobert Watson * Example of a variable string value.  Notice that the control
731dba9e9ccSRobert Watson * flags are CTLFLAG_RW, that the variable pointer and string
732dba9e9ccSRobert Watson * size are set.  Unlike newer sysctls, this older sysctl uses a
733dba9e9ccSRobert Watson * static oid number.
734dba9e9ccSRobert Watson */
735dba9e9ccSRobert Watsonchar kernelname[MAXPATHLEN] = "/kernel";	/* XXX bloat */
736dba9e9ccSRobert WatsonSYSCTL_STRING(_kern, KERN_BOOTFILE, bootfile, CTLFLAG_RW,
737dba9e9ccSRobert Watson    kernelname, sizeof(kernelname), "Name of kernel file booted");
738dba9e9ccSRobert Watson
739dba9e9ccSRobert Watson/*
740dba9e9ccSRobert Watson * Example of an opaque data type exported by sysctl.  Notice that
741dba9e9ccSRobert Watson * the variable pointer and size are provided, as well as a format
742dba9e9ccSRobert Watson * string for sysctl(8).
743dba9e9ccSRobert Watson */
7447c64ddd5SWarren Blockstatic l_fp pps_freq;	/* scaled frequency offset (ns/s) */
745dba9e9ccSRobert WatsonSYSCTL_OPAQUE(_kern_ntp_pll, OID_AUTO, pps_freq, CTLFLAG_RD,
746dba9e9ccSRobert Watson    &pps_freq, sizeof(pps_freq), "I", "");
747dba9e9ccSRobert Watson
748dba9e9ccSRobert Watson/*
749dba9e9ccSRobert Watson * Example of a procedure based sysctl exporting string
750dba9e9ccSRobert Watson * information.  Notice that the data type is declared, the NULL
751dba9e9ccSRobert Watson * variable pointer and 0 size, the function pointer, and the
752dba9e9ccSRobert Watson * format string for sysctl(8).
753dba9e9ccSRobert Watson */
754dba9e9ccSRobert WatsonSYSCTL_PROC(_kern_timecounter, OID_AUTO, hardware, CTLTYPE_STRING |
755dba9e9ccSRobert Watson    CTLFLAG_RW, NULL, 0, sysctl_kern_timecounter_hardware, "A",
756dba9e9ccSRobert Watson    "");
757dba9e9ccSRobert Watson.Ed
7585eb1caa8SHans Petter Selasky.Pp
7595eb1caa8SHans Petter SelaskyThe following is an example of
7605eb1caa8SHans Petter Selaskyhow to create a new top-level category
7615eb1caa8SHans Petter Selaskyand how to hook up another subtree to an existing static node.
7625eb1caa8SHans Petter SelaskyThis example does not use contexts,
7635eb1caa8SHans Petter Selaskywhich results in tedious management of all intermediate oids,
7645eb1caa8SHans Petter Selaskyas they need to be freed later on:
7655eb1caa8SHans Petter Selasky.Bd -literal -offset indent
7665eb1caa8SHans Petter Selasky#include <sys/sysctl.h>
7675eb1caa8SHans Petter Selasky ...
7685eb1caa8SHans Petter Selasky/*
7695eb1caa8SHans Petter Selasky * Need to preserve pointers to newly created subtrees,
7705eb1caa8SHans Petter Selasky * to be able to free them later:
7715eb1caa8SHans Petter Selasky */
7725eb1caa8SHans Petter Selaskystatic struct sysctl_oid *root1;
7735eb1caa8SHans Petter Selaskystatic struct sysctl_oid *root2;
7745eb1caa8SHans Petter Selaskystatic struct sysctl_oid *oidp;
7755eb1caa8SHans Petter Selaskystatic int a_int;
7765eb1caa8SHans Petter Selaskystatic char *string = "dynamic sysctl";
7775eb1caa8SHans Petter Selasky ...
7785eb1caa8SHans Petter Selasky
7795eb1caa8SHans Petter Selaskyroot1 = SYSCTL_ADD_ROOT_NODE(NULL,
7805eb1caa8SHans Petter Selasky	OID_AUTO, "newtree", CTLFLAG_RW, 0, "new top level tree");
7815eb1caa8SHans Petter Selaskyoidp = SYSCTL_ADD_INT(NULL, SYSCTL_CHILDREN(root1),
7825eb1caa8SHans Petter Selasky	OID_AUTO, "newint", CTLFLAG_RW, &a_int, 0, "new int leaf");
7835eb1caa8SHans Petter Selasky ...
7845eb1caa8SHans Petter Selaskyroot2 = SYSCTL_ADD_NODE(NULL, SYSCTL_STATIC_CHILDREN(_debug),
7855eb1caa8SHans Petter Selasky	OID_AUTO, "newtree", CTLFLAG_RW, 0, "new tree under debug");
7865eb1caa8SHans Petter Selaskyoidp = SYSCTL_ADD_STRING(NULL, SYSCTL_CHILDREN(root2),
7875eb1caa8SHans Petter Selasky	OID_AUTO, "newstring", CTLFLAG_RD, string, 0, "new string leaf");
7885eb1caa8SHans Petter Selasky.Ed
7895eb1caa8SHans Petter Selasky.Pp
7905eb1caa8SHans Petter SelaskyThis example creates the following subtrees:
7915eb1caa8SHans Petter Selasky.Bd -literal -offset indent
7925eb1caa8SHans Petter Selaskydebug.newtree.newstring
7935eb1caa8SHans Petter Selaskynewtree.newint
7945eb1caa8SHans Petter Selasky.Ed
7955eb1caa8SHans Petter Selasky.Pp
7965eb1caa8SHans Petter Selasky.Em "Care should be taken to free all OIDs once they are no longer needed!"
79791f3a6dbSYaroslav Tykhiy.Sh SYSCTL NAMING
798dba9e9ccSRobert WatsonWhen adding, modifying, or removing sysctl names, it is important to be
799dba9e9ccSRobert Watsonaware that these interfaces may be used by users, libraries, applications,
800f4006affSGiorgos Keramidasor documentation (such as published books), and are implicitly published application interfaces.
801dba9e9ccSRobert WatsonAs with other application interfaces, caution must be taken not to break
802dba9e9ccSRobert Watsonexisting applications, and to think about future use of new name spaces so as
803dba9e9ccSRobert Watsonto avoid the need to rename or remove interfaces that might be depended on in
804dba9e9ccSRobert Watsonthe future.
80591f3a6dbSYaroslav Tykhiy.Pp
80691f3a6dbSYaroslav TykhiyThe semantics chosen for a new sysctl should be as clear as possible,
80791f3a6dbSYaroslav Tykhiyand the name of the sysctl must closely reflect its semantics.
80891f3a6dbSYaroslav TykhiyTherefore the sysctl name deserves a fair amount of consideration.
80991f3a6dbSYaroslav TykhiyIt should be short but yet representative of the sysctl meaning.
81091f3a6dbSYaroslav TykhiyIf the name consists of several words, they should be separated by
81191f3a6dbSYaroslav Tykhiyunderscore characters, as in
81291f3a6dbSYaroslav Tykhiy.Va compute_summary_at_mount .
81391f3a6dbSYaroslav TykhiyUnderscore characters may be omitted only if the name consists of not more
81491f3a6dbSYaroslav Tykhiythan two words, each being not longer than four characters, as in
81591f3a6dbSYaroslav Tykhiy.Va bootfile .
81691f3a6dbSYaroslav TykhiyFor boolean sysctls, negative logic should be totally avoided.
81791f3a6dbSYaroslav TykhiyThat is, do not use names like
81891f3a6dbSYaroslav Tykhiy.Va no_foobar
81991f3a6dbSYaroslav Tykhiyor
82091f3a6dbSYaroslav Tykhiy.Va foobar_disable .
82191f3a6dbSYaroslav TykhiyThey are confusing and lead to configuration errors.
82291f3a6dbSYaroslav TykhiyUse positive logic instead:
82391f3a6dbSYaroslav Tykhiy.Va foobar ,
82491f3a6dbSYaroslav Tykhiy.Va foobar_enable .
82591f3a6dbSYaroslav Tykhiy.Pp
8265eb1caa8SHans Petter SelaskyA temporary sysctl node OID that should not be relied upon must be designated
8277851d429SEdward Tomasz Napieralaas such by a leading underscore character in its name.
8287851d429SEdward Tomasz NapieralaFor example:
82991f3a6dbSYaroslav Tykhiy.Va _dirty_hack .
830dba9e9ccSRobert Watson.Sh SEE ALSO
831f3066f2bSGavin Atkinson.Xr sysctl 3 ,
832dba9e9ccSRobert Watson.Xr sysctl 8 ,
833dba9e9ccSRobert Watson.Xr sysctl_add_oid 9 ,
834dba9e9ccSRobert Watson.Xr sysctl_ctx_free 9 ,
835dba9e9ccSRobert Watson.Xr sysctl_ctx_init 9 ,
836dba9e9ccSRobert Watson.Xr sysctl_remove_oid 9
837dba9e9ccSRobert Watson.Sh HISTORY
838bd84dd2fSRuslan ErmilovThe
839dba9e9ccSRobert Watson.Xr sysctl 8
840bd84dd2fSRuslan Ermilovutility first appeared in
841dba9e9ccSRobert Watson.Bx 4.4 .
842dba9e9ccSRobert Watson.Sh AUTHORS
843bd84dd2fSRuslan Ermilov.An -nosplit
844bd84dd2fSRuslan ErmilovThe
845bd84dd2fSRuslan Ermilov.Nm sysctl
846bd84dd2fSRuslan Ermilovimplementation originally found in
847dba9e9ccSRobert Watson.Bx
848dba9e9ccSRobert Watsonhas been extensively rewritten by
849dba9e9ccSRobert Watson.An Poul-Henning Kamp
850dba9e9ccSRobert Watsonin order to add support for name lookups, name space iteration, and dynamic
851dba9e9ccSRobert Watsonaddition of MIB nodes.
852dba9e9ccSRobert Watson.Pp
853dba9e9ccSRobert WatsonThis man page was written by
854dba9e9ccSRobert Watson.An Robert N. M. Watson .
8553edc2b53SJoel Dahl.Sh SECURITY CONSIDERATIONS
8563edc2b53SJoel DahlWhen creating new sysctls, careful attention should be paid to the security
8573edc2b53SJoel Dahlimplications of the monitoring or management interface being created.
8583edc2b53SJoel DahlMost sysctls present in the kernel are read-only or writable only by the
8593edc2b53SJoel Dahlsuperuser.
8603edc2b53SJoel DahlSysctls exporting extensive information on system data structures and
8613edc2b53SJoel Dahloperation, especially those implemented using procedures, will wish to
8623edc2b53SJoel Dahlimplement access control to limit the undesired exposure of information about
8633edc2b53SJoel Dahlother processes, network connections, etc.
8643edc2b53SJoel Dahl.Pp
8653edc2b53SJoel DahlThe following top level sysctl name spaces are commonly used:
8663edc2b53SJoel Dahl.Bl -tag -width ".Va regression"
8673edc2b53SJoel Dahl.It Va compat
8683edc2b53SJoel DahlCompatibility layer information.
8693edc2b53SJoel Dahl.It Va debug
8703edc2b53SJoel DahlDebugging information.
8713edc2b53SJoel DahlVarious name spaces exist under
8723edc2b53SJoel Dahl.Va debug .
8733edc2b53SJoel Dahl.It Va hw
8743edc2b53SJoel DahlHardware and device driver information.
8753edc2b53SJoel Dahl.It Va kern
8763edc2b53SJoel DahlKernel behavior tuning; generally deprecated in favor of more specific
8773edc2b53SJoel Dahlname spaces.
8783edc2b53SJoel Dahl.It Va machdep
8793edc2b53SJoel DahlMachine-dependent configuration parameters.
8803edc2b53SJoel Dahl.It Va net
8813edc2b53SJoel DahlNetwork subsystem.
8823edc2b53SJoel DahlVarious protocols have name spaces under
8833edc2b53SJoel Dahl.Va net .
8843edc2b53SJoel Dahl.It Va regression
8853edc2b53SJoel DahlRegression test configuration and information.
8863edc2b53SJoel Dahl.It Va security
8873edc2b53SJoel DahlSecurity and security-policy configuration and information.
8883edc2b53SJoel Dahl.It Va sysctl
8893edc2b53SJoel DahlReserved name space for the implementation of sysctl.
8903edc2b53SJoel Dahl.It Va user
8913edc2b53SJoel DahlConfiguration settings relating to user application behavior.
8923edc2b53SJoel DahlGenerally, configuring applications using kernel sysctls is discouraged.
8933edc2b53SJoel Dahl.It Va vfs
8943edc2b53SJoel DahlVirtual file system configuration and information.
8953edc2b53SJoel Dahl.It Va vm
8963edc2b53SJoel DahlVirtual memory subsystem configuration and information.
8973edc2b53SJoel Dahl.El
898