2 .\" Copyright (c) 2006 Robert N. M. Watson
3 .\" All rights reserved.
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
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.
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
34 .Nm SYSCTL_ADD_COUNTER_U64 ,
35 .Nm SYSCTL_ADD_COUNTER_U64_ARRAY ,
39 .Nm SYSCTL_ADD_NODE_WITH_LABEL ,
40 .Nm SYSCTL_ADD_OPAQUE ,
43 .Nm SYSCTL_ADD_ROOT_NODE ,
48 .Nm SYSCTL_ADD_SBINTIME_MSEC ,
49 .Nm SYSCTL_ADD_SBINTIME_USEC ,
50 .Nm SYSCTL_ADD_STRING ,
51 .Nm SYSCTL_ADD_CONST_STRING ,
52 .Nm SYSCTL_ADD_STRUCT ,
57 .Nm SYSCTL_ADD_UAUTO ,
59 .Nm SYSCTL_ADD_ULONG ,
60 .Nm SYSCTL_ADD_UQUAD ,
61 .Nm SYSCTL_ADD_UMA_CUR ,
62 .Nm SYSCTL_ADD_UMA_MAX ,
64 .Nm SYSCTL_STATIC_CHILDREN ,
65 .Nm SYSCTL_NODE_CHILDREN ,
68 .Nm SYSCTL_COUNTER_U64 ,
69 .Nm SYSCTL_COUNTER_U64_ARRAY ,
71 .Nm SYSCTL_INT_WITH_LABEL ,
73 .Nm sysctl_msec_to_ticks ,
75 .Nm SYSCTL_NODE_WITH_LABEL ,
79 .Nm SYSCTL_ROOT_NODE ,
84 .Nm SYSCTL_SBINTIME_MSEC ,
85 .Nm SYSCTL_SBINTIME_USEC ,
87 .Nm SYSCTL_CONST_STRING ,
98 .Nd Dynamic and static sysctl MIB creation functions
103 .Ft struct sysctl_oid *
105 .Fa "struct sysctl_ctx_list *ctx"
106 .Fa "struct sysctl_oid_list *parent"
108 .Fa "const char *name"
112 .Fa "const char *descr"
114 .Ft struct sysctl_oid *
115 .Fo SYSCTL_ADD_COUNTER_U64
116 .Fa "struct sysctl_ctx_list *ctx"
117 .Fa "struct sysctl_oid_list *parent"
119 .Fa "const char *name"
121 .Fa "counter_u64_t *ptr"
122 .Fa "const char *descr"
124 .Ft struct sysctl_oid *
125 .Fo SYSCTL_ADD_COUNTER_U64_ARRAY
126 .Fa "struct sysctl_ctx_list *ctx"
127 .Fa "struct sysctl_oid_list *parent"
129 .Fa "const char *name"
131 .Fa "counter_u64_t *ptr"
133 .Fa "const char *descr"
135 .Ft struct sysctl_oid *
137 .Fa "struct sysctl_ctx_list *ctx"
138 .Fa "struct sysctl_oid_list *parent"
140 .Fa "const char *name"
144 .Fa "const char *descr"
146 .Ft struct sysctl_oid *
148 .Fa "struct sysctl_ctx_list *ctx"
149 .Fa "struct sysctl_oid_list *parent"
151 .Fa "const char *name"
154 .Fa "const char *descr"
156 .Ft struct sysctl_oid *
158 .Fa "struct sysctl_ctx_list *ctx"
159 .Fa "struct sysctl_oid_list *parent"
161 .Fa "const char *name"
163 .Fa "int (*handler)(SYSCTL_HANDLER_ARGS)"
164 .Fa "const char *descr"
166 .Ft struct sysctl_oid *
167 .Fo SYSCTL_ADD_NODE_WITH_LABEL
168 .Fa "struct sysctl_ctx_list *ctx"
169 .Fa "struct sysctl_oid_list *parent"
171 .Fa "const char *name"
173 .Fa "int (*handler)(SYSCTL_HANDLER_ARGS)"
174 .Fa "const char *descr"
175 .Fa "const char *label"
177 .Ft struct sysctl_oid *
178 .Fo SYSCTL_ADD_OPAQUE
179 .Fa "struct sysctl_ctx_list *ctx"
180 .Fa "struct sysctl_oid_list *parent"
182 .Fa "const char *name"
186 .Fa "const char *format"
187 .Fa "const char *descr"
189 .Ft struct sysctl_oid *
191 .Fa "struct sysctl_ctx_list *ctx"
192 .Fa "struct sysctl_oid_list *parent"
194 .Fa "const char *name"
198 .Fa "int (*handler) (SYSCTL_HANDLER_ARGS)"
199 .Fa "const char *format"
200 .Fa "const char *descr"
202 .Ft struct sysctl_oid *
204 .Fa "struct sysctl_ctx_list *ctx"
205 .Fa "struct sysctl_oid_list *parent"
207 .Fa "const char *name"
210 .Fa "const char *descr"
212 .Ft struct sysctl_oid *
213 .Fo SYSCTL_ADD_ROOT_NODE
214 .Fa "struct sysctl_ctx_list *ctx"
216 .Fa "const char *name"
218 .Fa "int (*handler)(SYSCTL_HANDLER_ARGS)"
219 .Fa "const char *descr"
221 .Ft struct sysctl_oid *
223 .Fa "struct sysctl_ctx_list *ctx"
224 .Fa "struct sysctl_oid_list *parent"
226 .Fa "const char *name"
230 .Fa "const char *descr"
232 .Ft struct sysctl_oid *
234 .Fa "struct sysctl_ctx_list *ctx"
235 .Fa "struct sysctl_oid_list *parent"
237 .Fa "const char *name"
241 .Fa "const char *descr"
243 .Ft struct sysctl_oid *
245 .Fa "struct sysctl_ctx_list *ctx"
246 .Fa "struct sysctl_oid_list *parent"
248 .Fa "const char *name"
252 .Fa "const char *descr"
254 .Ft struct sysctl_oid *
256 .Fa "struct sysctl_ctx_list *ctx"
257 .Fa "struct sysctl_oid_list *parent"
259 .Fa "const char *name"
263 .Fa "const char *descr"
265 .Ft struct sysctl_oid *
266 .Fo SYSCTL_ADD_SBINTIME_MSEC
267 .Fa "struct sysctl_ctx_list *ctx"
268 .Fa "struct sysctl_oid_list *parent"
270 .Fa "const char *name"
272 .Fa "sbintime_t *ptr"
273 .Fa "const char *descr"
275 .Ft struct sysctl_oid *
276 .Fo SYSCTL_ADD_SBINTIME_USEC
277 .Fa "struct sysctl_ctx_list *ctx"
278 .Fa "struct sysctl_oid_list *parent"
280 .Fa "const char *name"
282 .Fa "sbintime_t *ptr"
283 .Fa "const char *descr"
285 .Ft struct sysctl_oid *
286 .Fo SYSCTL_ADD_STRING
287 .Fa "struct sysctl_ctx_list *ctx"
288 .Fa "struct sysctl_oid_list *parent"
290 .Fa "const char *name"
294 .Fa "const char *descr"
296 .Ft struct sysctl_oid *
297 .Fo SYSCTL_ADD_CONST_STRING
298 .Fa "struct sysctl_ctx_list *ctx"
299 .Fa "struct sysctl_oid_list *parent"
301 .Fa "const char *name"
303 .Fa "const char *ptr"
304 .Fa "const char *descr"
306 .Ft struct sysctl_oid *
307 .Fo SYSCTL_ADD_STRUCT
308 .Fa "struct sysctl_ctx_list *ctx"
309 .Fa "struct sysctl_oid_list *parent"
311 .Fa "const char *name"
315 .Fa "const char *descr"
317 .Ft struct sysctl_oid *
319 .Fa "struct sysctl_ctx_list *ctx"
320 .Fa "struct sysctl_oid_list *parent"
322 .Fa "const char *name"
326 .Fa "const char *descr"
328 .Ft struct sysctl_oid *
330 .Fa "struct sysctl_ctx_list *ctx"
331 .Fa "struct sysctl_oid_list *parent"
333 .Fa "const char *name"
337 .Fa "const char *descr"
339 .Ft struct sysctl_oid *
341 .Fa "struct sysctl_ctx_list *ctx"
342 .Fa "struct sysctl_oid_list *parent"
344 .Fa "const char *name"
348 .Fa "const char *descr"
350 .Ft struct sysctl_oid *
352 .Fa "struct sysctl_ctx_list *ctx"
353 .Fa "struct sysctl_oid_list *parent"
355 .Fa "const char *name"
359 .Fa "const char *descr"
361 .Ft struct sysctl_oid *
363 .Fa "struct sysctl_ctx_list *ctx"
364 .Fa "struct sysctl_oid_list *parent"
366 .Fa "const char *name"
368 .Fa "unsigned int *ptr"
369 .Fa "unsigned int val"
370 .Fa "const char *descr"
372 .Ft struct sysctl_oid *
374 .Fa "struct sysctl_ctx_list *ctx"
375 .Fa "struct sysctl_oid_list *parent"
377 .Fa "const char *name"
379 .Fa "unsigned long *ptr"
380 .Fa "const char *descr"
382 .Ft struct sysctl_oid *
384 .Fa "struct sysctl_ctx_list *ctx"
385 .Fa "struct sysctl_oid_list *parent"
387 .Fa "const char *name"
390 .Fa "const char *descr"
392 .Ft struct sysctl_oid *
393 .Fo SYSCTL_ADD_UMA_CUR
394 .Fa "struct sysctl_ctx_list *ctx"
395 .Fa "struct sysctl_oid_list *parent"
397 .Fa "const char *name"
400 .Fa "const char *descr"
402 .Ft struct sysctl_oid *
403 .Fo SYSCTL_ADD_UMA_MAX
404 .Fa "struct sysctl_ctx_list *ctx"
405 .Fa "struct sysctl_oid_list *parent"
407 .Fa "const char *name"
410 .Fa "const char *descr"
412 .Fa "const char *descr"
413 .Ft struct sysctl_oid *
415 .Fa "struct sysctl_ctx_list *ctx"
416 .Fa "struct sysctl_oid_list *parent"
418 .Fa "const char *name"
421 .Fa "const char *descr"
423 .Ft struct sysctl_oid_list *
425 .Fa "struct sysctl_oid *oidp"
427 .Ft struct sysctl_oid_list *
428 .Fo SYSCTL_STATIC_CHILDREN
429 .Fa "struct sysctl_oid_list OID_NAME"
431 .Ft struct sysctl_oid_list *
432 .Fo SYSCTL_NODE_CHILDREN
436 .Ft struct sysctl_oid *
438 .Fa "struct sysctl_oid *oid"
440 .Fn SYSCTL_BOOL parent number name ctlflags ptr val descr
441 .Fn SYSCTL_COUNTER_U64 parent number name ctlflags ptr descr
442 .Fn SYSCTL_COUNTER_U64_ARRAY parent number name ctlflags ptr len descr
443 .Fn SYSCTL_INT parent number name ctlflags ptr val descr
444 .Fn SYSCTL_INT_WITH_LABEL parent number name ctlflags ptr val descr label
445 .Fn SYSCTL_LONG parent number name ctlflags ptr val descr
447 .Fn sysctl_msec_to_ticks SYSCTL_HANDLER_ARGS
448 .Fn SYSCTL_NODE parent number name ctlflags handler descr
449 .Fn SYSCTL_NODE_WITH_LABEL parent number name ctlflags handler descr label
450 .Fn SYSCTL_OPAQUE parent number name ctlflags ptr len format descr
451 .Fn SYSCTL_PROC parent number name ctlflags arg1 arg2 handler format descr
452 .Fn SYSCTL_QUAD parent number name ctlflags ptr val descr
453 .Fn SYSCTL_ROOT_NODE number name ctlflags handler descr
454 .Fn SYSCTL_S8 parent number name ctlflags ptr val descr
455 .Fn SYSCTL_S16 parent number name ctlflags ptr val descr
456 .Fn SYSCTL_S32 parent number name ctlflags ptr val descr
457 .Fn SYSCTL_S64 parent number name ctlflags ptr val descr
458 .Fn SYSCTL_SBINTIME_MSEC parent number name ctlflags ptr descr
459 .Fn SYSCTL_SBINTIME_USEC parent number name ctlflags ptr descr
460 .Fn SYSCTL_STRING parent number name ctlflags arg len descr
461 .Fn SYSCTL_CONST_STRING parent number name ctlflags arg descr
462 .Fn SYSCTL_STRUCT parent number name ctlflags ptr struct_type descr
463 .Fn SYSCTL_U8 parent number name ctlflags ptr val descr
464 .Fn SYSCTL_U16 parent number name ctlflags ptr val descr
465 .Fn SYSCTL_U32 parent number name ctlflags ptr val descr
466 .Fn SYSCTL_U64 parent number name ctlflags ptr val descr
467 .Fn SYSCTL_UINT parent number name ctlflags ptr val descr
468 .Fn SYSCTL_ULONG parent number name ctlflags ptr val descr
469 .Fn SYSCTL_UQUAD parent number name ctlflags ptr val descr
470 .Fn SYSCTL_UMA_MAX parent number name ctlflags ptr descr
471 .Fn SYSCTL_UMA_CUR parent number name ctlflags ptr descr
476 kernel interface allows dynamic or static creation of
479 All static sysctls are automatically destroyed when the module which
480 they are part of is unloaded.
481 Most top level categories are created statically and are available to
482 all kernel code and its modules.
483 .Sh DESCRIPTION OF ARGUMENTS
484 .Bl -tag -width ctlflags
486 Pointer to sysctl context or NULL, if no context.
488 .Xr sysctl_ctx_init 9
489 for how to create a new sysctl context.
490 Programmers are strongly advised to use contexts to organize the
491 dynamic OIDs which they create because when a context is destroyed all
492 belonging sysctls are destroyed as well.
493 This makes the sysctl cleanup code much simpler.
494 Else deletion of all created OIDs is required at module unload.
497 .Li struct sysctl_oid_list ,
498 which is the head of the parent's list of children.
499 This pointer is retrieved using the
500 .Fn SYSCTL_STATIC_CHILDREN
501 macro for static sysctls and the
503 macro for dynamic sysctls.
506 macro can be used to get the parent of an OID.
507 The macro returns NULL if there is no parent.
509 The OID number that will be assigned to this OID.
510 In almost all cases this should be set to
512 which will result in the assignment of the next available OID number.
515 The newly created OID will contain a copy of the name.
517 A bit mask of sysctl control flags.
518 See the section below describing all the control flags.
520 First callback argument for procedure sysctls.
522 Second callback argument for procedure sysctls.
524 The length of the data pointed to by the
527 For string type OIDs a length of zero means that
529 will be used to get the length of the string at each access to the OID.
530 For array type OIDs the length must be greater than zero.
532 Pointer to sysctl variable or string data.
533 For 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
539 argument is SYSCTL_NULL_XXX_PTR, gives the constant value returned by this OID.
540 Else this argument is not used.
542 Name of structure type.
544 A pointer to the function
545 that is responsible for handling read and write requests
547 There are several standard handlers
548 that support operations on nodes,
549 integers, strings and opaque objects.
550 It is possible to define custom handlers using the
556 A pointer to a string
557 which specifies the format of the OID in a symbolic way.
558 This format is used as a hint by
560 to apply proper data formatting for display purposes.
563 .Bl -tag -width "S,TYPE" -compact -offset indent
571 temperature in Kelvin, multiplied by an optional single digit
572 power of ten scaling factor: 1 (default) gives deciKelvin, 0 gives Kelvin, 3
589 A pointer to a textual description of the OID.
591 A pointer to an aggregation label for this component of the OID.
592 To make it easier to export sysctl data to monitoring systems that
593 support aggregations through labels (e.g., Prometheus),
594 this argument can be used to attach a label name to an OID.
595 The label acts as a hint that this component's name should not be part
596 of the metric's name,
597 but attached to the metric as a label instead.
599 Labels should only be applied to siblings that are structurally similar
600 and encode the same type of value,
601 as aggregation is of no use otherwise.
604 Most of the macros and functions used to create sysctl nodes export a
605 read-only constant or in-kernel variable whose type matches the type
609 reports the raw value of an associated variable of type
611 However, nodes may also export a value that is a translatation of an internal
615 .Fn sysctl_msec_to_ticks
616 handler can be used with
620 to export a millisecond time interval.
621 When using this handler,
624 parameter points to an in-kernel variable of type
626 which stores a tick count suitable for use with functions like
629 .Fn sysctl_msec_to_ticks
630 function converts this value to milliseconds when reporting the node's value.
632 .Fn sysctl_msec_to_ticks
633 accepts new values in milliseconds and stores an equivalent value in ticks to
635 Note that new code should use kernel variables of type
637 instead of tick counts.
640 .Fn SYSCTL_ADD_SBINTIME_MSEC
642 .Fn SYSCTL_ADD_SBINTIME_USEC
644 .Fn SYSCTL_SBINTIME_MSEC
646 .Fn SYSCTL_SBINTIME_USEC
647 macros all create nodes which export an in-kernel variable of type
649 These nodes do not export the raw value of the associated variable.
650 Instead, they export a 64-bit integer containing a count of either
651 milliseconds (the MSEC variants) or microseconds (the USEC variants).
652 .Sh CREATING ROOT NODES
653 Sysctl MIBs or OIDs are created in a hierarchical tree.
654 The nodes at the bottom of the tree are called root nodes, and have no
656 To create bottom tree nodes the
659 .Fn SYSCTL_ADD_ROOT_NODE
660 function needs to be used.
661 By default all static sysctl node OIDs are global and need a
663 statement prior to their
665 definition statement, typically in a so-called header file.
666 .Sh CREATING SYSCTL STRINGS
667 Zero terminated character strings sysctls are created either using the
670 .Fn SYSCTL_ADD_STRING
674 argument in zero, the string length is computed at every access to the OID using
677 .Fn SYSCTL_CONST_STRING
679 .Fn SYSCTL_ADD_CONST_STRING
680 function to add a sysctl for a constant string.
681 .Sh CREATING OPAQUE SYSCTLS
687 .Fn SYSCTL_ADD_OPAQUE
689 .Fn SYSCTL_ADD_STRUCT
690 functions create an OID that handle any chunk of data
691 of the size specified by the
693 argument and data pointed to by the
696 When using the structure version the type is encoded as part of the
698 .Sh CREATING CUSTOM SYSCTLS
704 create OIDs with the specified
707 The handler is responsible for handling all read and write requests to
709 This OID type is especially useful if the kernel data is not easily
710 accessible, or needs to be processed before exporting.
711 .Sh CREATING A STATIC SYSCTL
712 Static sysctls are declared using one of the
714 .Fn SYSCTL_COUNTER_U64 ,
715 .Fn SYSCTL_COUNTER_U64_ARRAY ,
717 .Fn SYSCTL_INT_WITH_LABEL ,
720 .Fn SYSCTL_NODE_WITH_LABEL ,
724 .Fn SYSCTL_ROOT_NODE ,
729 .Fn SYSCTL_SBINTIME_MSEC ,
730 .Fn SYSCTL_SBINTIME_USEC ,
732 .Fn SYSCTL_CONST_STRING ,
745 .Sh CREATING A DYNAMIC SYSCTL
746 Dynamic nodes are created using one of the
747 .Fn SYSCTL_ADD_BOOL ,
748 .Fn SYSCTL_ADD_COUNTER_U64 ,
749 .Fn SYSCTL_ADD_COUNTER_U64_ARRAY ,
751 .Fn SYSCTL_ADD_LONG ,
752 .Fn SYSCTL_ADD_NODE ,
753 .Fn SYSCTL_ADD_NODE_WITH_LABEL ,
754 .Fn SYSCTL_ADD_OPAQUE ,
755 .Fn SYSCTL_ADD_PROC ,
756 .Fn SYSCTL_ADD_QUAD ,
757 .Fn SYSCTL_ADD_ROOT_NODE ,
762 .Fn SYSCTL_ADD_SBINTIME_MSEC ,
763 .Fn SYSCTL_ADD_SBINTIME_USEC ,
764 .Fn SYSCTL_ADD_STRING ,
765 .Fn SYSCTL_ADD_CONST_STRING ,
766 .Fn SYSCTL_ADD_STRUCT ,
771 .Fn SYSCTL_ADD_UAUTO ,
772 .Fn SYSCTL_ADD_UINT ,
773 .Fn SYSCTL_ADD_ULONG ,
774 .Fn SYSCTL_ADD_UQUAD ,
775 .Fn SYSCTL_ADD_UMA_CUR
777 .Fn SYSCTL_ADD_UMA_MAX
780 .Xr sysctl_remove_oid 9
782 .Xr sysctl_ctx_free 9
783 for more information on how to destroy a dynamically created OID.
785 For most of the above functions and macros, declaring a type as part
786 of the access flags is not necessary \[em] however, when declaring a
787 sysctl implemented by a function, including a type in the access mask
789 .Bl -tag -width ".Dv CTLTYPE_NOFETCH"
791 This is a node intended to be a parent for other nodes.
793 This is a signed integer.
794 .It Dv CTLTYPE_STRING
795 This is a nul-terminated string stored in a character array.
797 This is an 8-bit signed integer.
799 This is a 16-bit signed integer.
801 This is a 32-bit signed integer.
803 This is a 64-bit signed integer.
804 .It Dv CTLTYPE_OPAQUE
805 This is an opaque data structure.
806 .It Dv CTLTYPE_STRUCT
810 This is an 8-bit unsigned integer.
812 This is a 16-bit unsigned integer.
814 This is a 32-bit unsigned integer.
816 This is a 64-bit unsigned integer.
818 This is an unsigned integer.
820 This is a signed long.
822 This is an unsigned long.
825 All sysctl types except for new node declarations require one of the following
826 flags to be set indicating the read and write disposition of the sysctl:
827 .Bl -tag -width ".Dv CTLFLAG_ANYBODY"
829 This is a read-only sysctl.
831 This is a read-only sysctl and tunable which is tried fetched once
832 from the system environment early during module load or system boot.
834 This is a writable sysctl.
836 This sysctl is readable and writable.
838 This is a readable and writeable sysctl and tunable which is tried
839 fetched once from the system environment early during module load or
841 .It Dv CTLFLAG_NOFETCH
842 In case the node is marked as a tunable using the CTLFLAG_[XX]TUN,
843 this flag will prevent fetching the initial value from the system
845 Typically this flag should only be used for very early
846 low level system setup code, and not by common drivers and modules.
847 .It Dv CTLFLAG_MPSAFE
851 Do not grab Giant around calls to this handler.
852 This should only be used for
857 Additionally, any of the following optional flags may also be specified:
858 .Bl -tag -width ".Dv CTLFLAG_ANYBODY"
859 .It Dv CTLFLAG_ANYBODY
860 Any user or process can write to this sysctl.
862 A process in capability mode can read from this sysctl.
864 A process in capability mode can write to this sysctl.
865 .It Dv CTLFLAG_SECURE
866 This sysctl can be written to only if the effective securelevel of the
868 .It Dv CTLFLAG_PRISON
869 This sysctl can be written to by processes in
872 When iterating the sysctl name space, do not list this sysctl.
874 Advisory flag that a system tunable also exists for this variable.
875 The initial sysctl value is tried fetched once from the system
876 environment early during module load or system boot.
878 Dynamically created OIDs automatically get this flag set.
880 OID references a VIMAGE-enabled variable.
887 sysctl tree for use by new nodes:
888 .Bd -literal -offset indent
889 SYSCTL_DECL(_security);
892 Examples of integer, opaque, string, and procedure sysctls follow:
893 .Bd -literal -offset indent
895 * Example of a constant integer value. Notice that the control
896 * flags are CTLFLAG_RD, the variable pointer is SYSCTL_NULL_INT_PTR,
897 * and the value is declared.
899 SYSCTL_INT(_debug_sizeof, OID_AUTO, bio, CTLFLAG_RD, SYSCTL_NULL_INT_PTR,
900 sizeof(struct bio), "sizeof(struct bio)");
903 * Example of a variable integer value. Notice that the control
904 * flags are CTLFLAG_RW, the variable pointer is set, and the
907 static int doingcache = 1; /* 1 => enable the cache */
908 SYSCTL_INT(_debug, OID_AUTO, vfscache, CTLFLAG_RW, &doingcache, 0,
909 "Enable name cache");
912 * Example of a variable string value. Notice that the control
913 * flags are CTLFLAG_RW, that the variable pointer and string
914 * size are set. Unlike newer sysctls, this older sysctl uses a
917 char kernelname[MAXPATHLEN] = "/kernel"; /* XXX bloat */
918 SYSCTL_STRING(_kern, KERN_BOOTFILE, bootfile, CTLFLAG_RW,
919 kernelname, sizeof(kernelname), "Name of kernel file booted");
922 * Example of an opaque data type exported by sysctl. Notice that
923 * the variable pointer and size are provided, as well as a format
924 * string for sysctl(8).
926 static l_fp pps_freq; /* scaled frequency offset (ns/s) */
927 SYSCTL_OPAQUE(_kern_ntp_pll, OID_AUTO, pps_freq, CTLFLAG_RD,
928 &pps_freq, sizeof(pps_freq), "I", "");
931 * Example of a procedure based sysctl exporting string
932 * information. Notice that the data type is declared, the NULL
933 * variable pointer and 0 size, the function pointer, and the
934 * format string for sysctl(8).
936 SYSCTL_PROC(_kern_timecounter, OID_AUTO, hardware, CTLTYPE_STRING |
937 CTLFLAG_RW, NULL, 0, sysctl_kern_timecounter_hardware, "A",
941 The following is an example of
942 how to create a new top-level category
943 and how to hook up another subtree to an existing static node.
944 This example does not use contexts,
945 which results in tedious management of all intermediate oids,
946 as they need to be freed later on:
947 .Bd -literal -offset indent
948 #include <sys/sysctl.h>
951 * Need to preserve pointers to newly created subtrees,
952 * to be able to free them later:
954 static struct sysctl_oid *root1;
955 static struct sysctl_oid *root2;
956 static struct sysctl_oid *oidp;
958 static char *string = "dynamic sysctl";
961 root1 = SYSCTL_ADD_ROOT_NODE(NULL,
962 OID_AUTO, "newtree", CTLFLAG_RW, 0, "new top level tree");
963 oidp = SYSCTL_ADD_INT(NULL, SYSCTL_CHILDREN(root1),
964 OID_AUTO, "newint", CTLFLAG_RW, &a_int, 0, "new int leaf");
966 root2 = SYSCTL_ADD_NODE(NULL, SYSCTL_STATIC_CHILDREN(_debug),
967 OID_AUTO, "newtree", CTLFLAG_RW, 0, "new tree under debug");
968 oidp = SYSCTL_ADD_STRING(NULL, SYSCTL_CHILDREN(root2),
969 OID_AUTO, "newstring", CTLFLAG_RD, string, 0, "new string leaf");
972 This example creates the following subtrees:
973 .Bd -literal -offset indent
974 debug.newtree.newstring
978 .Em "Care should be taken to free all OIDs once they are no longer needed!"
980 When adding, modifying, or removing sysctl names, it is important to be
981 aware that these interfaces may be used by users, libraries, applications,
982 or documentation (such as published books), and are implicitly published application interfaces.
983 As with other application interfaces, caution must be taken not to break
984 existing applications, and to think about future use of new name spaces so as
985 to avoid the need to rename or remove interfaces that might be depended on in
988 The semantics chosen for a new sysctl should be as clear as possible,
989 and the name of the sysctl must closely reflect its semantics.
990 Therefore the sysctl name deserves a fair amount of consideration.
991 It should be short but yet representative of the sysctl meaning.
992 If the name consists of several words, they should be separated by
993 underscore characters, as in
994 .Va compute_summary_at_mount .
995 Underscore characters may be omitted only if the name consists of not more
996 than two words, each being not longer than four characters, as in
998 For boolean sysctls, negative logic should be totally avoided.
999 That is, do not use names like
1002 .Va foobar_disable .
1003 They are confusing and lead to configuration errors.
1004 Use positive logic instead:
1008 A temporary sysctl node OID that should not be relied upon must be designated
1009 as such by a leading underscore character in its name.
1015 .Xr sysctl_add_oid 9 ,
1016 .Xr sysctl_ctx_free 9 ,
1017 .Xr sysctl_ctx_init 9 ,
1018 .Xr sysctl_remove_oid 9
1022 utility first appeared in
1028 implementation originally found in
1030 has been extensively rewritten by
1031 .An Poul-Henning Kamp
1032 in order to add support for name lookups, name space iteration, and dynamic
1033 addition of MIB nodes.
1035 This man page was written by
1036 .An Robert N. M. Watson .
1037 .Sh SECURITY CONSIDERATIONS
1038 When creating new sysctls, careful attention should be paid to the security
1039 implications of the monitoring or management interface being created.
1040 Most sysctls present in the kernel are read-only or writable only by the
1042 Sysctls exporting extensive information on system data structures and
1043 operation, especially those implemented using procedures, will wish to
1044 implement access control to limit the undesired exposure of information about
1045 other processes, network connections, etc.
1047 The following top level sysctl name spaces are commonly used:
1048 .Bl -tag -width ".Va regression"
1050 Compatibility layer information.
1052 Debugging information.
1053 Various name spaces exist under
1056 Hardware and device driver information.
1058 Kernel behavior tuning; generally deprecated in favor of more specific
1061 Machine-dependent configuration parameters.
1064 Various protocols have name spaces under
1067 Regression test configuration and information.
1069 Security and security-policy configuration and information.
1071 Reserved name space for the implementation of sysctl.
1073 Configuration settings relating to user application behavior.
1074 Generally, configuring applications using kernel sysctls is discouraged.
1076 Virtual file system configuration and information.
1078 Virtual memory subsystem configuration and information.