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 ,
74 .Nm SYSCTL_NODE_WITH_LABEL ,
78 .Nm SYSCTL_ROOT_NODE ,
83 .Nm SYSCTL_SBINTIME_MSEC ,
84 .Nm SYSCTL_SBINTIME_USEC ,
86 .Nm SYSCTL_CONST_STRING ,
97 .Nd Dynamic and static sysctl MIB creation functions
102 .Ft struct sysctl_oid *
104 .Fa "struct sysctl_ctx_list *ctx"
105 .Fa "struct sysctl_oid_list *parent"
107 .Fa "const char *name"
111 .Fa "const char *descr"
113 .Ft struct sysctl_oid *
114 .Fo SYSCTL_ADD_COUNTER_U64
115 .Fa "struct sysctl_ctx_list *ctx"
116 .Fa "struct sysctl_oid_list *parent"
118 .Fa "const char *name"
120 .Fa "counter_u64_t *ptr"
121 .Fa "const char *descr"
123 .Ft struct sysctl_oid *
124 .Fo SYSCTL_ADD_COUNTER_U64_ARRAY
125 .Fa "struct sysctl_ctx_list *ctx"
126 .Fa "struct sysctl_oid_list *parent"
128 .Fa "const char *name"
130 .Fa "counter_u64_t *ptr"
132 .Fa "const char *descr"
134 .Ft struct sysctl_oid *
136 .Fa "struct sysctl_ctx_list *ctx"
137 .Fa "struct sysctl_oid_list *parent"
139 .Fa "const char *name"
143 .Fa "const char *descr"
145 .Ft struct sysctl_oid *
147 .Fa "struct sysctl_ctx_list *ctx"
148 .Fa "struct sysctl_oid_list *parent"
150 .Fa "const char *name"
153 .Fa "const char *descr"
155 .Ft struct sysctl_oid *
157 .Fa "struct sysctl_ctx_list *ctx"
158 .Fa "struct sysctl_oid_list *parent"
160 .Fa "const char *name"
162 .Fa "int (*handler)(SYSCTL_HANDLER_ARGS)"
163 .Fa "const char *descr"
165 .Ft struct sysctl_oid *
166 .Fo SYSCTL_ADD_NODE_WITH_LABEL
167 .Fa "struct sysctl_ctx_list *ctx"
168 .Fa "struct sysctl_oid_list *parent"
170 .Fa "const char *name"
172 .Fa "int (*handler)(SYSCTL_HANDLER_ARGS)"
173 .Fa "const char *descr"
174 .Fa "const char *label"
176 .Ft struct sysctl_oid *
177 .Fo SYSCTL_ADD_OPAQUE
178 .Fa "struct sysctl_ctx_list *ctx"
179 .Fa "struct sysctl_oid_list *parent"
181 .Fa "const char *name"
185 .Fa "const char *format"
186 .Fa "const char *descr"
188 .Ft struct sysctl_oid *
190 .Fa "struct sysctl_ctx_list *ctx"
191 .Fa "struct sysctl_oid_list *parent"
193 .Fa "const char *name"
197 .Fa "int (*handler) (SYSCTL_HANDLER_ARGS)"
198 .Fa "const char *format"
199 .Fa "const char *descr"
201 .Ft struct sysctl_oid *
203 .Fa "struct sysctl_ctx_list *ctx"
204 .Fa "struct sysctl_oid_list *parent"
206 .Fa "const char *name"
209 .Fa "const char *descr"
211 .Ft struct sysctl_oid *
212 .Fo SYSCTL_ADD_ROOT_NODE
213 .Fa "struct sysctl_ctx_list *ctx"
215 .Fa "const char *name"
217 .Fa "int (*handler)(SYSCTL_HANDLER_ARGS)"
218 .Fa "const char *descr"
220 .Ft struct sysctl_oid *
222 .Fa "struct sysctl_ctx_list *ctx"
223 .Fa "struct sysctl_oid_list *parent"
225 .Fa "const char *name"
229 .Fa "const char *descr"
231 .Ft struct sysctl_oid *
233 .Fa "struct sysctl_ctx_list *ctx"
234 .Fa "struct sysctl_oid_list *parent"
236 .Fa "const char *name"
240 .Fa "const char *descr"
242 .Ft struct sysctl_oid *
244 .Fa "struct sysctl_ctx_list *ctx"
245 .Fa "struct sysctl_oid_list *parent"
247 .Fa "const char *name"
251 .Fa "const char *descr"
253 .Ft struct sysctl_oid *
255 .Fa "struct sysctl_ctx_list *ctx"
256 .Fa "struct sysctl_oid_list *parent"
258 .Fa "const char *name"
262 .Fa "const char *descr"
264 .Ft struct sysctl_oid *
265 .Fo SYSCTL_ADD_SBINTIME_MSEC
266 .Fa "struct sysctl_ctx_list *ctx"
267 .Fa "struct sysctl_oid_list *parent"
269 .Fa "const char *name"
271 .Fa "sbintime_t *ptr"
272 .Fa "const char *descr"
274 .Ft struct sysctl_oid *
275 .Fo SYSCTL_ADD_SBINTIME_USEC
276 .Fa "struct sysctl_ctx_list *ctx"
277 .Fa "struct sysctl_oid_list *parent"
279 .Fa "const char *name"
281 .Fa "sbintime_t *ptr"
282 .Fa "const char *descr"
284 .Ft struct sysctl_oid *
285 .Fo SYSCTL_ADD_STRING
286 .Fa "struct sysctl_ctx_list *ctx"
287 .Fa "struct sysctl_oid_list *parent"
289 .Fa "const char *name"
293 .Fa "const char *descr"
295 .Ft struct sysctl_oid *
296 .Fo SYSCTL_ADD_CONST_STRING
297 .Fa "struct sysctl_ctx_list *ctx"
298 .Fa "struct sysctl_oid_list *parent"
300 .Fa "const char *name"
302 .Fa "const char *ptr"
303 .Fa "const char *descr"
305 .Ft struct sysctl_oid *
306 .Fo SYSCTL_ADD_STRUCT
307 .Fa "struct sysctl_ctx_list *ctx"
308 .Fa "struct sysctl_oid_list *parent"
310 .Fa "const char *name"
314 .Fa "const char *descr"
316 .Ft struct sysctl_oid *
318 .Fa "struct sysctl_ctx_list *ctx"
319 .Fa "struct sysctl_oid_list *parent"
321 .Fa "const char *name"
325 .Fa "const char *descr"
327 .Ft struct sysctl_oid *
329 .Fa "struct sysctl_ctx_list *ctx"
330 .Fa "struct sysctl_oid_list *parent"
332 .Fa "const char *name"
336 .Fa "const char *descr"
338 .Ft struct sysctl_oid *
340 .Fa "struct sysctl_ctx_list *ctx"
341 .Fa "struct sysctl_oid_list *parent"
343 .Fa "const char *name"
347 .Fa "const char *descr"
349 .Ft struct sysctl_oid *
351 .Fa "struct sysctl_ctx_list *ctx"
352 .Fa "struct sysctl_oid_list *parent"
354 .Fa "const char *name"
358 .Fa "const char *descr"
360 .Ft struct sysctl_oid *
362 .Fa "struct sysctl_ctx_list *ctx"
363 .Fa "struct sysctl_oid_list *parent"
365 .Fa "const char *name"
367 .Fa "unsigned int *ptr"
368 .Fa "unsigned int val"
369 .Fa "const char *descr"
371 .Ft struct sysctl_oid *
373 .Fa "struct sysctl_ctx_list *ctx"
374 .Fa "struct sysctl_oid_list *parent"
376 .Fa "const char *name"
378 .Fa "unsigned long *ptr"
379 .Fa "const char *descr"
381 .Ft struct sysctl_oid *
383 .Fa "struct sysctl_ctx_list *ctx"
384 .Fa "struct sysctl_oid_list *parent"
386 .Fa "const char *name"
389 .Fa "const char *descr"
391 .Ft struct sysctl_oid *
392 .Fo SYSCTL_ADD_UMA_CUR
393 .Fa "struct sysctl_ctx_list *ctx"
394 .Fa "struct sysctl_oid_list *parent"
396 .Fa "const char *name"
399 .Fa "const char *descr"
401 .Ft struct sysctl_oid *
402 .Fo SYSCTL_ADD_UMA_MAX
403 .Fa "struct sysctl_ctx_list *ctx"
404 .Fa "struct sysctl_oid_list *parent"
406 .Fa "const char *name"
409 .Fa "const char *descr"
411 .Fa "const char *descr"
412 .Ft struct sysctl_oid *
414 .Fa "struct sysctl_ctx_list *ctx"
415 .Fa "struct sysctl_oid_list *parent"
417 .Fa "const char *name"
420 .Fa "const char *descr"
422 .Ft struct sysctl_oid_list *
424 .Fa "struct sysctl_oid *oidp"
426 .Ft struct sysctl_oid_list *
427 .Fo SYSCTL_STATIC_CHILDREN
428 .Fa "struct sysctl_oid_list OID_NAME"
430 .Ft struct sysctl_oid_list *
431 .Fo SYSCTL_NODE_CHILDREN
435 .Ft struct sysctl_oid *
437 .Fa "struct sysctl_oid *oid"
439 .Fn SYSCTL_BOOL parent number name ctlflags ptr val descr
440 .Fn SYSCTL_COUNTER_U64 parent number name ctlflags ptr descr
441 .Fn SYSCTL_COUNTER_U64_ARRAY parent number name ctlflags ptr len descr
442 .Fn SYSCTL_INT parent number name ctlflags ptr val descr
443 .Fn SYSCTL_INT_WITH_LABEL parent number name ctlflags ptr val descr label
444 .Fn SYSCTL_LONG parent number name ctlflags ptr val descr
445 .Fn SYSCTL_NODE parent number name ctlflags handler descr
446 .Fn SYSCTL_NODE_WITH_LABEL parent number name ctlflags handler descr label
447 .Fn SYSCTL_OPAQUE parent number name ctlflags ptr len format descr
448 .Fn SYSCTL_PROC parent number name ctlflags arg1 arg2 handler format descr
449 .Fn SYSCTL_QUAD parent number name ctlflags ptr val descr
450 .Fn SYSCTL_ROOT_NODE number name ctlflags handler descr
451 .Fn SYSCTL_S8 parent number name ctlflags ptr val descr
452 .Fn SYSCTL_S16 parent number name ctlflags ptr val descr
453 .Fn SYSCTL_S32 parent number name ctlflags ptr val descr
454 .Fn SYSCTL_S64 parent number name ctlflags ptr val descr
455 .Fn SYSCTL_SBINTIME_MSEC parent number name ctlflags ptr descr
456 .Fn SYSCTL_SBINTIME_USEC parent number name ctlflags ptr descr
457 .Fn SYSCTL_STRING parent number name ctlflags arg len descr
458 .Fn SYSCTL_CONST_STRING parent number name ctlflags arg descr
459 .Fn SYSCTL_STRUCT parent number name ctlflags ptr struct_type descr
460 .Fn SYSCTL_U8 parent number name ctlflags ptr val descr
461 .Fn SYSCTL_U16 parent number name ctlflags ptr val descr
462 .Fn SYSCTL_U32 parent number name ctlflags ptr val descr
463 .Fn SYSCTL_U64 parent number name ctlflags ptr val descr
464 .Fn SYSCTL_UINT parent number name ctlflags ptr val descr
465 .Fn SYSCTL_ULONG parent number name ctlflags ptr val descr
466 .Fn SYSCTL_UQUAD parent number name ctlflags ptr val descr
467 .Fn SYSCTL_UMA_MAX parent number name ctlflags ptr descr
468 .Fn SYSCTL_UMA_CUR parent number name ctlflags ptr descr
472 kernel interface allows dynamic or static creation of
475 All static sysctls are automatically destroyed when the module which
476 they are part of is unloaded.
477 Most top level categories are created statically and are available to
478 all kernel code and its modules.
479 .Sh DESCRIPTION OF ARGUMENTS
480 .Bl -tag -width ctlflags
482 Pointer to sysctl context or NULL, if no context.
484 .Xr sysctl_ctx_init 9
485 for how to create a new sysctl context.
486 Programmers are strongly advised to use contexts to organize the
487 dynamic OIDs which they create because when a context is destroyed all
488 belonging sysctls are destroyed as well.
489 This makes the sysctl cleanup code much simpler.
490 Else deletion of all created OIDs is required at module unload.
493 .Li struct sysctl_oid_list ,
494 which is the head of the parent's list of children.
495 This pointer is retrieved using the
496 .Fn SYSCTL_STATIC_CHILDREN
497 macro for static sysctls and the
499 macro for dynamic sysctls.
502 macro can be used to get the parent of an OID.
503 The macro returns NULL if there is no parent.
505 The OID number that will be assigned to this OID.
506 In almost all cases this should be set to
508 which will result in the assignment of the next available OID number.
511 The newly created OID will contain a copy of the name.
513 A bit mask of sysctl control flags.
514 See the section below describing all the control flags.
516 First callback argument for procedure sysctls.
518 Second callback argument for procedure sysctls.
520 The length of the data pointed to by the
523 For string type OIDs a length of zero means that
525 will be used to get the length of the string at each access to the OID.
526 For array type OIDs the length must be greater than zero.
528 Pointer to sysctl variable or string data.
529 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
535 argument is SYSCTL_NULL_XXX_PTR, gives the constant value returned by this OID.
536 Else this argument is not used.
538 Name of structure type.
540 A pointer to the function
541 that is responsible for handling read and write requests
543 There are several standard handlers
544 that support operations on nodes,
545 integers, strings and opaque objects.
546 It is possible to define custom handlers using the
552 A pointer to a string
553 which specifies the format of the OID in a symbolic way.
554 This format is used as a hint by
556 to apply proper data formatting for display purposes.
559 .Bl -tag -width "S,TYPE" -compact -offset indent
567 temperature in Kelvin, multiplied by an optional single digit
568 power of ten scaling factor: 1 (default) gives deciKelvin, 0 gives Kelvin, 3
585 A pointer to a textual description of the OID.
587 A pointer to an aggregation label for this component of the OID.
588 To make it easier to export sysctl data to monitoring systems that
589 support aggregations through labels (e.g., Prometheus),
590 this argument can be used to attach a label name to an OID.
591 The label acts as a hint that this component's name should not be part
592 of the metric's name,
593 but attached to the metric as a label instead.
595 Labels should only be applied to siblings that are structurally similar
596 and encode the same type of value,
597 as aggregation is of no use otherwise.
599 .Sh CREATING ROOT NODES
600 Sysctl MIBs or OIDs are created in a hierarchical tree.
601 The nodes at the bottom of the tree are called root nodes, and have no
603 To create bottom tree nodes the
606 .Fn SYSCTL_ADD_ROOT_NODE
607 function needs to be used.
608 By default all static sysctl node OIDs are global and need a
610 statement prior to their
612 definition statement, typically in a so-called header file.
613 .Sh CREATING SYSCTL STRINGS
614 Zero terminated character strings sysctls are created either using the
617 .Fn SYSCTL_ADD_STRING
621 argument in zero, the string length is computed at every access to the OID using
624 .Fn SYSCTL_CONST_STRING
626 .Fn SYSCTL_ADD_CONST_STRING
627 function to add a sysctl for a constant string.
628 .Sh CREATING OPAQUE SYSCTLS
634 .Fn SYSCTL_ADD_OPAQUE
636 .Fn SYSCTL_ADD_STRUCT
637 functions create an OID that handle any chunk of data
638 of the size specified by the
640 argument and data pointed to by the
643 When using the structure version the type is encoded as part of the
645 .Sh CREATING CUSTOM SYSCTLS
651 create OIDs with the specified
654 The handler is responsible for handling all read and write requests to
656 This OID type is especially useful if the kernel data is not easily
657 accessible, or needs to be processed before exporting.
658 .Sh CREATING A STATIC SYSCTL
659 Static sysctls are declared using one of the
661 .Fn SYSCTL_COUNTER_U64 ,
662 .Fn SYSCTL_COUNTER_U64_ARRAY ,
664 .Fn SYSCTL_INT_WITH_LABEL ,
667 .Fn SYSCTL_NODE_WITH_LABEL ,
671 .Fn SYSCTL_ROOT_NODE ,
676 .Fn SYSCTL_SBINTIME_MSEC ,
677 .Fn SYSCTL_SBINTIME_USEC ,
679 .Fn SYSCTL_CONST_STRING ,
692 .Sh CREATING A DYNAMIC SYSCTL
693 Dynamic nodes are created using one of the
694 .Fn SYSCTL_ADD_BOOL ,
695 .Fn SYSCTL_ADD_COUNTER_U64 ,
696 .Fn SYSCTL_ADD_COUNTER_U64_ARRAY ,
698 .Fn SYSCTL_ADD_LONG ,
699 .Fn SYSCTL_ADD_NODE ,
700 .Fn SYSCTL_ADD_NODE_WITH_LABEL ,
701 .Fn SYSCTL_ADD_OPAQUE ,
702 .Fn SYSCTL_ADD_PROC ,
703 .Fn SYSCTL_ADD_QUAD ,
704 .Fn SYSCTL_ADD_ROOT_NODE ,
709 .Fn SYSCTL_ADD_SBINTIME_MSEC ,
710 .Fn SYSCTL_ADD_SBINTIME_USEC ,
711 .Fn SYSCTL_ADD_STRING ,
712 .Fn SYSCTL_ADD_CONST_STRING ,
713 .Fn SYSCTL_ADD_STRUCT ,
718 .Fn SYSCTL_ADD_UAUTO ,
719 .Fn SYSCTL_ADD_UINT ,
720 .Fn SYSCTL_ADD_ULONG ,
721 .Fn SYSCTL_ADD_UQUAD ,
722 .Fn SYSCTL_ADD_UMA_CUR
724 .Fn SYSCTL_ADD_UMA_MAX
727 .Xr sysctl_remove_oid 9
729 .Xr sysctl_ctx_free 9
730 for more information on how to destroy a dynamically created OID.
732 For most of the above functions and macros, declaring a type as part
733 of the access flags is not necessary \[em] however, when declaring a
734 sysctl implemented by a function, including a type in the access mask
736 .Bl -tag -width ".Dv CTLTYPE_NOFETCH"
738 This is a node intended to be a parent for other nodes.
740 This is a signed integer.
741 .It Dv CTLTYPE_STRING
742 This is a nul-terminated string stored in a character array.
744 This is an 8-bit signed integer.
746 This is a 16-bit signed integer.
748 This is a 32-bit signed integer.
750 This is a 64-bit signed integer.
751 .It Dv CTLTYPE_OPAQUE
752 This is an opaque data structure.
753 .It Dv CTLTYPE_STRUCT
757 This is an 8-bit unsigned integer.
759 This is a 16-bit unsigned integer.
761 This is a 32-bit unsigned integer.
763 This is a 64-bit unsigned integer.
765 This is an unsigned integer.
767 This is a signed long.
769 This is an unsigned long.
772 All sysctl types except for new node declarations require one of the following
773 flags to be set indicating the read and write disposition of the sysctl:
774 .Bl -tag -width ".Dv CTLFLAG_ANYBODY"
776 This is a read-only sysctl.
778 This is a read-only sysctl and tunable which is tried fetched once
779 from the system environment early during module load or system boot.
781 This is a writable sysctl.
783 This sysctl is readable and writable.
785 This is a readable and writeable sysctl and tunable which is tried
786 fetched once from the system environment early during module load or
788 .It Dv CTLFLAG_NOFETCH
789 In case the node is marked as a tunable using the CTLFLAG_[XX]TUN,
790 this flag will prevent fetching the initial value from the system
792 Typically this flag should only be used for very early
793 low level system setup code, and not by common drivers and modules.
794 .It Dv CTLFLAG_MPSAFE
798 Do not grab Giant around calls to this handler.
799 This should only be used for
804 Additionally, any of the following optional flags may also be specified:
805 .Bl -tag -width ".Dv CTLFLAG_ANYBODY"
806 .It Dv CTLFLAG_ANYBODY
807 Any user or process can write to this sysctl.
809 A process in capability mode can read from this sysctl.
811 A process in capability mode can write to this sysctl.
812 .It Dv CTLFLAG_SECURE
813 This sysctl can be written to only if the effective securelevel of the
815 .It Dv CTLFLAG_PRISON
816 This sysctl can be written to by processes in
819 When iterating the sysctl name space, do not list this sysctl.
821 Advisory flag that a system tunable also exists for this variable.
822 The initial sysctl value is tried fetched once from the system
823 environment early during module load or system boot.
825 Dynamically created OIDs automatically get this flag set.
827 OID references a VIMAGE-enabled variable.
834 sysctl tree for use by new nodes:
835 .Bd -literal -offset indent
836 SYSCTL_DECL(_security);
839 Examples of integer, opaque, string, and procedure sysctls follow:
840 .Bd -literal -offset indent
842 * Example of a constant integer value. Notice that the control
843 * flags are CTLFLAG_RD, the variable pointer is SYSCTL_NULL_INT_PTR,
844 * and the value is declared.
846 SYSCTL_INT(_debug_sizeof, OID_AUTO, bio, CTLFLAG_RD, SYSCTL_NULL_INT_PTR,
847 sizeof(struct bio), "sizeof(struct bio)");
850 * Example of a variable integer value. Notice that the control
851 * flags are CTLFLAG_RW, the variable pointer is set, and the
854 static int doingcache = 1; /* 1 => enable the cache */
855 SYSCTL_INT(_debug, OID_AUTO, vfscache, CTLFLAG_RW, &doingcache, 0,
856 "Enable name cache");
859 * Example of a variable string value. Notice that the control
860 * flags are CTLFLAG_RW, that the variable pointer and string
861 * size are set. Unlike newer sysctls, this older sysctl uses a
864 char kernelname[MAXPATHLEN] = "/kernel"; /* XXX bloat */
865 SYSCTL_STRING(_kern, KERN_BOOTFILE, bootfile, CTLFLAG_RW,
866 kernelname, sizeof(kernelname), "Name of kernel file booted");
869 * Example of an opaque data type exported by sysctl. Notice that
870 * the variable pointer and size are provided, as well as a format
871 * string for sysctl(8).
873 static l_fp pps_freq; /* scaled frequency offset (ns/s) */
874 SYSCTL_OPAQUE(_kern_ntp_pll, OID_AUTO, pps_freq, CTLFLAG_RD,
875 &pps_freq, sizeof(pps_freq), "I", "");
878 * Example of a procedure based sysctl exporting string
879 * information. Notice that the data type is declared, the NULL
880 * variable pointer and 0 size, the function pointer, and the
881 * format string for sysctl(8).
883 SYSCTL_PROC(_kern_timecounter, OID_AUTO, hardware, CTLTYPE_STRING |
884 CTLFLAG_RW, NULL, 0, sysctl_kern_timecounter_hardware, "A",
888 The following is an example of
889 how to create a new top-level category
890 and how to hook up another subtree to an existing static node.
891 This example does not use contexts,
892 which results in tedious management of all intermediate oids,
893 as they need to be freed later on:
894 .Bd -literal -offset indent
895 #include <sys/sysctl.h>
898 * Need to preserve pointers to newly created subtrees,
899 * to be able to free them later:
901 static struct sysctl_oid *root1;
902 static struct sysctl_oid *root2;
903 static struct sysctl_oid *oidp;
905 static char *string = "dynamic sysctl";
908 root1 = SYSCTL_ADD_ROOT_NODE(NULL,
909 OID_AUTO, "newtree", CTLFLAG_RW, 0, "new top level tree");
910 oidp = SYSCTL_ADD_INT(NULL, SYSCTL_CHILDREN(root1),
911 OID_AUTO, "newint", CTLFLAG_RW, &a_int, 0, "new int leaf");
913 root2 = SYSCTL_ADD_NODE(NULL, SYSCTL_STATIC_CHILDREN(_debug),
914 OID_AUTO, "newtree", CTLFLAG_RW, 0, "new tree under debug");
915 oidp = SYSCTL_ADD_STRING(NULL, SYSCTL_CHILDREN(root2),
916 OID_AUTO, "newstring", CTLFLAG_RD, string, 0, "new string leaf");
919 This example creates the following subtrees:
920 .Bd -literal -offset indent
921 debug.newtree.newstring
925 .Em "Care should be taken to free all OIDs once they are no longer needed!"
927 When adding, modifying, or removing sysctl names, it is important to be
928 aware that these interfaces may be used by users, libraries, applications,
929 or documentation (such as published books), and are implicitly published application interfaces.
930 As with other application interfaces, caution must be taken not to break
931 existing applications, and to think about future use of new name spaces so as
932 to avoid the need to rename or remove interfaces that might be depended on in
935 The semantics chosen for a new sysctl should be as clear as possible,
936 and the name of the sysctl must closely reflect its semantics.
937 Therefore the sysctl name deserves a fair amount of consideration.
938 It should be short but yet representative of the sysctl meaning.
939 If the name consists of several words, they should be separated by
940 underscore characters, as in
941 .Va compute_summary_at_mount .
942 Underscore characters may be omitted only if the name consists of not more
943 than two words, each being not longer than four characters, as in
945 For boolean sysctls, negative logic should be totally avoided.
946 That is, do not use names like
950 They are confusing and lead to configuration errors.
951 Use positive logic instead:
955 A temporary sysctl node OID that should not be relied upon must be designated
956 as such by a leading underscore character in its name.
962 .Xr sysctl_add_oid 9 ,
963 .Xr sysctl_ctx_free 9 ,
964 .Xr sysctl_ctx_init 9 ,
965 .Xr sysctl_remove_oid 9
969 utility first appeared in
975 implementation originally found in
977 has been extensively rewritten by
978 .An Poul-Henning Kamp
979 in order to add support for name lookups, name space iteration, and dynamic
980 addition of MIB nodes.
982 This man page was written by
983 .An Robert N. M. Watson .
984 .Sh SECURITY CONSIDERATIONS
985 When creating new sysctls, careful attention should be paid to the security
986 implications of the monitoring or management interface being created.
987 Most sysctls present in the kernel are read-only or writable only by the
989 Sysctls exporting extensive information on system data structures and
990 operation, especially those implemented using procedures, will wish to
991 implement access control to limit the undesired exposure of information about
992 other processes, network connections, etc.
994 The following top level sysctl name spaces are commonly used:
995 .Bl -tag -width ".Va regression"
997 Compatibility layer information.
999 Debugging information.
1000 Various name spaces exist under
1003 Hardware and device driver information.
1005 Kernel behavior tuning; generally deprecated in favor of more specific
1008 Machine-dependent configuration parameters.
1011 Various protocols have name spaces under
1014 Regression test configuration and information.
1016 Security and security-policy configuration and information.
1018 Reserved name space for the implementation of sysctl.
1020 Configuration settings relating to user application behavior.
1021 Generally, configuring applications using kernel sysctls is discouraged.
1023 Virtual file system configuration and information.
1025 Virtual memory subsystem configuration and information.