Merge branch 'vendor/DHCPCD'
[dragonfly.git] / share / man / man9 / sysctl.9
1 .\"
2 .\" Copyright (c) 2006 Robert N. M. Watson
3 .\" All rights reserved.
4 .\"
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
7 .\" are met:
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\"    notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\"    notice, this list of conditions and the following disclaimer in the
12 .\"    documentation and/or other materials provided with the distribution.
13 .\"
14 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 .\" SUCH DAMAGE.
25 .\"
26 .\"
27 .Dd December 2, 2019
28 .Dt SYSCTL 9
29 .Os
30 .Sh NAME
31 .Nm SYSCTL_BIT32 ,
32 .Nm SYSCTL BIT64 ,
33 .Nm SYSCTL_DECL ,
34 .Nm SYSCTL_INT ,
35 .Nm SYSCTL_LONG ,
36 .Nm SYSCTL_QUAD ,
37 .Nm SYSCTL_NODE ,
38 .Nm SYSCTL_OPAQUE ,
39 .Nm SYSCTL_PROC ,
40 .Nm SYSCTL_S8 ,
41 .Nm SYSCTL_S16 ,
42 .Nm SYSCTL_S32 ,
43 .Nm SYSCTL_S64 ,
44 .Nm SYSCTL_STRING ,
45 .Nm SYSCTL_STRUCT ,
46 .Nm SYSCTL_U8 ,
47 .Nm SYSCTL_U16 ,
48 .Nm SYSCTL_U32 ,
49 .Nm SYSCTL_U64 ,
50 .Nm SYSCTL_UINT ,
51 .Nm SYSCTL_ULONG ,
52 .Nm SYSCTL_UQUAD
53 .Nd Static sysctl declaration functions
54 .Sh SYNOPSIS
55 .In sys/types.h
56 .In sys/sysctl.h
57 .Fo SYSCTL_BIT32
58 .Fa "parent"
59 .Fa "nbr"
60 .Fa "name"
61 .Fa "access"
62 .Fa "ptr"
63 .Fa "val"
64 .Fa "bit"
65 .Fa "descr"
66 .Fc
67 .Fo SYSCTL_BIT64
68 .Fa "parent"
69 .Fa "nbr"
70 .Fa "name"
71 .Fa "access"
72 .Fa "ptr"
73 .Fa "val"
74 .Fa "bit"
75 .Fa "descr"
76 .Fc
77 .Fo SYSCTL_DECL
78 .Fa "name"
79 .Fc
80 .Fo SYSCTL_INT
81 .Fa "parent"
82 .Fa "nbr"
83 .Fa "name"
84 .Fa "access"
85 .Fa "ptr"
86 .Fa "val"
87 .Fa "descr"
88 .Fc
89 .Fo SYSCTL_LONG
90 .Fa "parent"
91 .Fa "nbr"
92 .Fa "name"
93 .Fa "access"
94 .Fa "ptr"
95 .Fa "val"
96 .Fa "descr"
97 .Fc
98 .Fo SYSCTL_NODE
99 .Fa "parent"
100 .Fa "nbr"
101 .Fa "name"
102 .Fa "access"
103 .Fa "handler"
104 .Fa "descr"
105 .Fc
106 .Fo SYSCTL_OPAQUE
107 .Fa "parent"
108 .Fa "nbr"
109 .Fa "name"
110 .Fa "access"
111 .Fa "ptr"
112 .Fa "len"
113 .Fa "fmt"
114 .Fa "descr"
115 .Fc
116 .Fo SYSCTL_PROC
117 .Fa "parent"
118 .Fa "nbr"
119 .Fa "name"
120 .Fa "access"
121 .Fa "ptr"
122 .Fa "arg"
123 .Fa "handler"
124 .Fa "fmt"
125 .Fa "descr"
126 .Fc
127 .Fo SYSCTL_QUAD
128 .Fa "parent"
129 .Fa "nbr"
130 .Fa "name"
131 .Fa "access"
132 .Fa "ptr"
133 .Fa "val"
134 .Fa "descr"
135 .Fc
136 .Fo SYSCTL_S8
137 .Fa "parent"
138 .Fa "number"
139 .Fa "name"
140 .Fa "access"
141 .Fa "ptr"
142 .Fa "val"
143 .Fa "descr"
144 .Fc
145 .Fo SYSCTL_S16
146 .Fa "parent"
147 .Fa "number"
148 .Fa "name"
149 .Fa "access"
150 .Fa "ptr"
151 .Fa "val"
152 .Fa "descr"
153 .Fc
154 .Fo SYSCTL_S32
155 .Fa "parent"
156 .Fa "number"
157 .Fa "name"
158 .Fa "access"
159 .Fa "ptr"
160 .Fa "val"
161 .Fa "descr"
162 .Fc
163 .Fo SYSCTL_S64
164 .Fa "parent"
165 .Fa "number"
166 .Fa "name"
167 .Fa "access"
168 .Fa "ptr"
169 .Fa "val"
170 .Fa "descr"
171 .Fc
172 .Fo SYSCTL_STRING
173 .Fa "parent"
174 .Fa "nbr"
175 .Fa "name"
176 .Fa "access"
177 .Fa "arg"
178 .Fa "len"
179 .Fa "descr"
180 .Fc
181 .Fo SYSCTL_STRUCT
182 .Fa "parent"
183 .Fa "nbr"
184 .Fa "name"
185 .Fa "access"
186 .Fa "ptr"
187 .Fa "type"
188 .Fa "descr"
189 .Fc
190 .Fo SYSCTL_U8
191 .Fa "parent"
192 .Fa "number"
193 .Fa "name"
194 .Fa "access"
195 .Fa "ptr"
196 .Fa "val"
197 .Fa "descr"
198 .Fc
199 .Fo SYSCTL_U16
200 .Fa "parent"
201 .Fa "number"
202 .Fa "name"
203 .Fa "access"
204 .Fa "ptr"
205 .Fa "val"
206 .Fa "descr"
207 .Fc
208 .Fo SYSCTL_U32
209 .Fa "parent"
210 .Fa "number"
211 .Fa "name"
212 .Fa "access"
213 .Fa "ptr"
214 .Fa "val"
215 .Fa "descr"
216 .Fc
217 .Fo SYSCTL_U64
218 .Fa "parent"
219 .Fa "number"
220 .Fa "name"
221 .Fa "access"
222 .Fa "ptr"
223 .Fa "val"
224 .Fa "descr"
225 .Fc
226 .Fo SYSCTL_UINT
227 .Fa "parent"
228 .Fa "nbr"
229 .Fa "name"
230 .Fa "access"
231 .Fa "ptr"
232 .Fa "val"
233 .Fa "descr"
234 .Fc
235 .Fo SYSCTL_ULONG
236 .Fa "parent"
237 .Fa "nbr"
238 .Fa "name"
239 .Fa "access"
240 .Fa "ptr"
241 .Fa "val"
242 .Fa "descr"
243 .Fc
244 .Fo SYSCTL_UQUAD
245 .Fa "parent"
246 .Fa "nbr"
247 .Fa "name"
248 .Fa "access"
249 .Fa "ptr"
250 .Fa "val"
251 .Fa "descr"
252 .Fc
253 .Sh DESCRIPTION
254 The
255 .Nm
256 kernel interfaces allow code to statically declare
257 .Xr sysctl 8
258 MIB entries, which will be initialized when the kernel module containing the
259 declaration is initialized.
260 When the module is unloaded, the sysctl will be automatically destroyed.
261 .Pp
262 Sysctl nodes are created in a hierarchical tree, with all static nodes being
263 represented by named C data structures; in order to create a new node under
264 an existing node in the tree, the structure representing the desired parent
265 node must be declared in the current context using
266 .Fn SYSCTL_DECL .
267 .Pp
268 New nodes are declared using one of
269 .Nm SYSCTL_BIT32 ,
270 .Nm SYSCTL_BIT64 ,
271 .Nm SYSCTL_INT ,
272 .Nm SYSCTL_LONG ,
273 .Nm SYSCTL_QUAD ,
274 .Nm SYSCTL_NODE ,
275 .Nm SYSCTL_OPAQUE ,
276 .Nm SYSCTL_PROC ,
277 .Nm SYSCTL_S8 ,
278 .Nm SYSCTL_S16 ,
279 .Nm SYSCTL_S32 ,
280 .Nm SYSCTL_S64 ,
281 .Nm SYSCTL_STRING ,
282 .Nm SYSCTL_STRUCT ,
283 .Nm SYSCTL_U8 ,
284 .Nm SYSCTL_U16 ,
285 .Nm SYSCTL_U32 ,
286 .Nm SYSCTL_U64 ,
287 .Nm SYSCTL_UINT ,
288 .Nm SYSCTL_ULONG ,
289 and
290 .Nm SYSCTL_UQUAD .
291 Each macro accepts a parent name, as declared using
292 .Nm SYSCTL_DECL ,
293 an OID number, typically
294 .Dv OID_AUTO ,
295 a node name, a set of control and access flags, and a description.
296 Depending on the macro, a pointer to a variable supporting the MIB entry, a
297 size, a value, and a function pointer implementing the MIB entry may also be
298 present.
299 .Pp
300 For most of the above macros, declaring a type as part of the access flags is
301 not necessary -- however, when declaring a sysctl implemented by a function,
302 including a type in the access mask is required:
303 .Bl -tag -width ".Dv CTLTYPE_STRING"
304 .It Dv CTLTYPE_NODE
305 This is a node intended to be a parent for other nodes.
306 .It Dv CTLTYPE_INT
307 This is a signed integer.
308 .It Dv CTLTYPE_S8
309 This is an 8-bit signed integer.
310 .It Dv CTLTYPE_S16
311 This is a 16-bit signed integer.
312 .It Dv CTLTYPE_S32
313 This is a 32-bit signed integer.
314 .It Dv CTLTYPE_S64
315 This is a 64-bit signed integer.
316 .It Dv CTLTYPE_STRING
317 This is a nul-terminated string stored in a character array.
318 .It Dv CTLTYPE_QUAD
319 This is a 64-bit signed integer.
320 .It Dv CTLTYPE_OPAQUE
321 This is an opaque data structure.
322 .It Dv CTLTYPE_STRUCT
323 Alias for
324 .Dv CTLTYPE_OPAQUE .
325 .It Dv CTLTYPE_U8
326 This is an 8-bit unsigned integer.
327 .It Dv CTLTYPE_U16
328 This is a 16-bit unsigned integer.
329 .It Dv CTLTYPE_U32
330 This is a 32-bit unsigned integer.
331 .It Dv CTLTYPE_U64
332 This is a 64-bit unsigned integer.
333 .It Dv CTLTYPE_UINT
334 This is an unsigned integer.
335 .It Dv CTLTYPE_LONG
336 This is a signed long.
337 .It Dv CTLTYPE_ULONG
338 This is an unsigned long.
339 .It Dv CTLTYPE_UQUAD
340 This is a 64-bit unsigned integer.
341 .El
342 .Pp
343 All sysctl types except for new node declarations require one or more flags
344 to be set indicating the read and write disposition of the sysctl:
345 .Bl -tag -width ".Dv CTLFLAG_ANYBODY"
346 .It Dv CTLFLAG_RD
347 This is a read-only sysctl.
348 .It Dv CTLFLAG_WR
349 This is a writable sysctl.
350 .It Dv CTLFLAG_RW
351 This sysctl is readable and writable.
352 .It Dv CTLFLAG_ANYBODY
353 Any user or process can write to this sysctl.
354 .It Dv CTLFLAG_SECURE
355 This sysctl can be written to only if the effective securelevel of the
356 process is <= 0.
357 .It Dv CTLFLAG_PRISON
358 This sysctl can be written to by processes in
359 .Xr jail 2 .
360 .\".It Dv CTLFLAG_SKIP
361 .\"When iterating the sysctl name space, do not list this sysctl.
362 .El
363 .Pp
364 When creating new sysctls, careful attention should be paid to the security
365 implications of the monitoring or management interface being created.
366 Most sysctls present in the kernel are read-only or writable only by the
367 superuser.
368 Sysctls exporting extensive information on system data structures and
369 operation, especially those implemented using procedures, will wish to
370 implement access control to limit the undesired exposure of information about
371 other processes, network connections, etc.
372 .Pp
373 The following top level sysctl name spaces are commonly used:
374 .Bl -tag -width ".Va machdep"
375 .It Va compat
376 Compatibility layer information.
377 .It Va debug
378 Debugging information.
379 Various name spaces exist under
380 .Va debug .
381 .It Va hw
382 Hardware and device driver information.
383 .It Va lwkt
384 Information about the
385 .Xr lwkt 9
386 subsystem.
387 .It Va kern
388 Kernel behavior tuning; generally deprecated in favor of more specific
389 name spaces.
390 .It Va machdep
391 Machine-dependent configuration parameters.
392 .It Va net
393 Network subsystem.
394 Various protocols have name spaces under
395 .Va net .
396 .It Va sysctl
397 Reserved name space for the implementation of sysctl.
398 .It Va user
399 Configuration settings relating to user application behavior.
400 Generally, configuring applications using kernel sysctls is discouraged.
401 .It Va vfs
402 Virtual file system configuration and information.
403 .It Va vm
404 Virtual memory subsystem configuration and information.
405 .El
406 .Sh EXAMPLES
407 Sample use of
408 .Nm SYSCTL_DECL
409 to declare the "machdep" sysctl tree for use by new nodes:
410 .Bd -literal -offset indent
411 SYSCTL_DECL(_machdep);
412 .Ed
413 .Pp
414 Examples of integer, opaque, string, and procedure sysctls follow:
415 .Bd -literal -offset indent
416 /*
417  * Example of a constant integer value.  Notice that the control
418  * flags are CTLFLAG_RD, the variable pointer is NULL, and the
419  * value is declared.
420  */
421 SYSCTL_INT(_debug_sizeof, OID_AUTO, bio, CTLFLAG_RD, NULL,
422     sizeof(struct bio), "sizeof(struct bio)");
423
424 /*
425  * Example of a variable integer value.  Notice that the control
426  * flags are CTLFLAG_RW, the variable pointer is set, and the
427  * value is 0.
428  */
429 static int      doingcache = 1;         /* 1 => enable the cache */
430 SYSCTL_INT(_debug, OID_AUTO, vfscache, CTLFLAG_RW, &doingcache, 0,
431     "Enable name cache");
432
433 /*
434  * Example of a variable string value.  Notice that the control
435  * flags are CTLFLAG_RW, that the variable pointer and string
436  * size are set.  Unlike newer sysctls, this older sysctl uses a
437  * static oid number.
438  */
439 char kernelname[MAXPATHLEN] = "/boot/kernel";   /* XXX bloat */
440 SYSCTL_STRING(_kern, KERN_BOOTFILE, bootfile, CTLFLAG_RW,
441     kernelname, sizeof(kernelname), "Name of kernel file booted");
442
443 /*
444  * Example of an opaque data type exported by sysctl.  Notice that
445  * the variable pointer and size are provided, as well as a format
446  * string for sysctl(8).
447  */
448 static l_fp pps_freq;   /* scaled frequency offset (ns/s) */
449 SYSCTL_OPAQUE(_kern_ntp_pll, OID_AUTO, pps_freq, CTLFLAG_RD,
450     &pps_freq, sizeof(pps_freq), "I", "");
451
452 /*
453  * Example of a procedure based sysctl exporting string
454  * information.  Notice that the data type is declared, the NULL
455  * variable pointer and 0 size, the function pointer, and the
456  * format string for sysctl(8).
457  */
458 SYSCTL_PROC(_kern, OID_AUTO, msgbuf, CTLTYPE_STRING | CTLFLAG_RD,
459     0, 0, sysctl_kern_msgbuf, "A", "Contents of kernel message buffer");
460 .Ed
461 .Pp
462 When adding, modifying, or removing sysctl names, it is important to be
463 aware that these interfaces may be used by users, libraries, applications,
464 or documentation (such as published books), and are implicitly published
465 application interfaces.
466 As with other application interfaces, caution must be taken not to break
467 existing applications, and to think about future use of new name spaces so as
468 to avoid the need to rename or remove interfaces that might be depended on in
469 the future.
470 .Sh SEE ALSO
471 .Xr sysctl 8 ,
472 .Xr sysctl_add_oid 9 ,
473 .Xr sysctl_ctx_free 9 ,
474 .Xr sysctl_ctx_init 9 ,
475 .Xr sysctl_remove_oid 9
476 .Sh HISTORY
477 .Xr sysctl 8
478 first appeared in
479 .Bx 4.4 .
480 .Sh AUTHORS
481 .An -nosplit
482 The sysctl implementation originally found in
483 .Bx
484 has been extensively rewritten by
485 .An Poul-Henning Kamp
486 in order to add support for name lookups, name space iteration, and dynamic
487 addition of MIB nodes.
488 .Pp
489 This man page was written by
490 .An Robert N. M. Watson .