SYSCTL_DECL SYSCTL_INT SYSCTL_LONG SYSCTL_NODE SYSCTL_OPAQUE SYSCTL_PROC SYSCTL_STRING SYSCTL_STRUCT SYSCTL_UINT SYSCTL_ULONG SYSCTL_XINT SYSCTL_XLONG - Static sysctl declaration functions
Sysctl nodes are created in a hierarchical tree, with all static nodes being
represented by named C data structures; in order to create a new node under
an existing node in the tree, the structure representing the desired parent
node must be declared in the current context using
New nodes are declared using one of
and SYSCTL_XLONG (.);
Each macro accepts a parent name, as declared using SYSCTL_DECL (,);
an OID number, typically OID_AUTO a node name, a set of control and access flags, and a description. Depending on the macro, a pointer to a variable supporting the MIB entry, a size, a value, and a function pointer implementing the MIB entry may also be present.
For most of the above macros, declaring a type as part of the access flags is not necessary [em] however, when declaring a sysctl implemented by a function, including a type in the access mask is required:
All sysctl types except for new node declarations require one or more flags to be set indicating the read and write disposition of the sysctl:
When creating new sysctls, careful attention should be paid to the security implications of the monitoring or management interface being created. Most sysctls present in the kernel are read-only or writable only by the superuser. Sysctls exporting extensive information on system data structures and operation, especially those implemented using procedures, will wish to implement access control to limit the undesired exposure of information about other processes, network connections, etc.
The following top level sysctl name spaces are commonly used:
Examples of integer, opaque, string, and procedure sysctls follow:
/* * Example of a constant integer value. Notice that the control * flags are CTLFLAG_RD, the variable pointer is NULL, and the * value is declared. * If sysctl(8) should print this value in hex, use 'SYSCTL_XINT'. */ SYSCTL_INT(_debug_sizeof, OID_AUTO, bio, CTLFLAG_RD, NULL, sizeof(struct bio), "sizeof(struct bio)"); /* * Example of a variable integer value. Notice that the control * flags are CTLFLAG_RW, the variable pointer is set, and the * value is 0. */ static int doingcache = 1; /* 1 => enable the cache */ SYSCTL_INT(_debug, OID_AUTO, vfscache, CTLFLAG_RW, &doingcache, 0, "Enable name cache"); /* * Example of a variable string value. Notice that the control * flags are CTLFLAG_RW, that the variable pointer and string * size are set. Unlike newer sysctls, this older sysctl uses a * static oid number. */ char kernelname[MAXPATHLEN] = "/kernel"; /* XXX bloat */ SYSCTL_STRING(_kern, KERN_BOOTFILE, bootfile, CTLFLAG_RW, kernelname, sizeof(kernelname), "Name of kernel file booted"); /* * Example of an opaque data type exported by sysctl. Notice that * the variable pointer and size are provided, as well as a format * string for sysctl(8). */ static l_fp pps_freq; /* scaled frequence offset (ns/s) */ SYSCTL_OPAQUE(_kern_ntp_pll, OID_AUTO, pps_freq, CTLFLAG_RD, &pps_freq, sizeof(pps_freq), "I", ""); /* * Example of a procedure based sysctl exporting string * information. Notice that the data type is declared, the NULL * variable pointer and 0 size, the function pointer, and the * format string for sysctl(8). */ SYSCTL_PROC(_kern_timecounter, OID_AUTO, hardware, CTLTYPE_STRING | CTLFLAG_RW, NULL, 0, sysctl_kern_timecounter_hardware, "A", "");
The semantics chosen for a new sysctl should be as clear as possible, and the name of the sysctl must closely reflect its semantics. Therefore the sysctl name deserves a fair amount of consideration. It should be short but yet representative of the sysctl meaning. If the name consists of several words, they should be separated by underscore characters, as in compute_summary_at_mount Underscore characters may be omitted only if the name consists of not more than two words, each being not longer than four characters, as in bootfile For boolean sysctls, negative logic should be totally avoided. That is, do not use names like no_foobar or foobar_disable They are confusing and lead to configuration errors. Use positive logic instead: foobar foobar_enable
A temporary sysctl node that should not be relied upon must be designated as such by a leading underscore character in its name. For example: _dirty_hack
This man page was written by An Robert N. M. Watson .
Закладки на сайте
Проследить за страницей
Created 1996-2020 by Maxim Chirkov
Добавить, Поддержать, Вебмастеру