]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - share/man/man9/sysctl.9
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.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 .\" $FreeBSD$
27 .\"
28 .Dd January 16, 2010
29 .Dt SYSCTL 9
30 .Os
31 .Sh NAME
32 .Nm SYSCTL_DECL ,
33 .Nm SYSCTL_INT ,
34 .Nm SYSCTL_LONG ,
35 .Nm SYSCTL_NODE ,
36 .Nm SYSCTL_OPAQUE ,
37 .Nm SYSCTL_PROC ,
38 .Nm SYSCTL_STRING ,
39 .Nm SYSCTL_STRUCT ,
40 .Nm SYSCTL_UINT ,
41 .Nm SYSCTL_ULONG ,
42 .Nm SYSCTL_QUAD
43 .Nd Static sysctl declaration functions
44 .Sh SYNOPSIS
45 .In sys/types.h
46 .In sys/sysctl.h
47 .Fn SYSCTL_DECL name
48 .Fn SYSCTL_INT parent nbr name access ptr val descr
49 .Fn SYSCTL_LONG parent nbr name access ptr val descr
50 .Fn SYSCTL_NODE parent nbr name access handler descr
51 .Fn SYSCTL_OPAQUE parent nbr name access ptr len fmt descr
52 .Fn SYSCTL_PROC parent nbr name access ptr arg handler fmt descr
53 .Fn SYSCTL_STRING parent nbr name access arg len descr
54 .Fn SYSCTL_STRUCT parent nbr name access ptr type descr
55 .Fn SYSCTL_UINT parent nbr name access ptr val descr
56 .Fn SYSCTL_ULONG parent nbr name access ptr val descr
57 .Fn SYSCTL_QUAD parent nbr name access ptr val descr
58 .Sh DESCRIPTION
59 The
60 .Nm SYSCTL
61 kernel interfaces allow code to statically declare
62 .Xr sysctl 8
63 MIB entries, which will be initialized when the kernel module containing the
64 declaration is initialized.
65 When the module is unloaded, the sysctl will be automatically destroyed.
66 .Pp
67 Sysctl nodes are created in a hierarchical tree, with all static nodes being
68 represented by named C data structures; in order to create a new node under
69 an existing node in the tree, the structure representing the desired parent
70 node must be declared in the current context using
71 .Fn SYSCTL_DECL .
72 .Pp
73 New nodes are declared using one of
74 .Fn SYSCTL_INT ,
75 .Fn SYSCTL_LONG ,
76 .Fn SYSCTL_NODE ,
77 .Fn SYSCTL_OPAQUE ,
78 .Fn SYSCTL_PROC ,
79 .Fn SYSCTL_STRING ,
80 .Fn SYSCTL_STRUCT ,
81 .Fn SYSCTL_UINT ,
82 .Fn SYSCTL_ULONG ,
83 and
84 .Fn SYSCTL_QUAD .
85 Each macro accepts a parent name, as declared using
86 .Fn SYSCTL_DECL ,
87 an OID number, typically
88 .Dv OID_AUTO ,
89 a node name, a set of control and access flags, and a description.
90 Depending on the macro, a pointer to a variable supporting the MIB entry, a
91 size, a value, and a function pointer implementing the MIB entry may also be
92 present.
93 .Pp
94 For most of the above macros, declaring a type as part of the access flags is
95 not necessary \[em] however, when declaring a sysctl implemented by a function,
96 including a type in the access mask is required:
97 .Bl -tag -width ".Dv CTLTYPE_STRING"
98 .It Dv CTLTYPE_NODE
99 This is a node intended to be a parent for other nodes.
100 .It Dv CTLTYPE_INT
101 This is a signed integer.
102 .It Dv CTLTYPE_STRING
103 This is a nul-terminated string stored in a character array.
104 .It Dv CTLTYPE_S64
105 This is a 64-bit signed integer.
106 .It Dv CTLTYPE_OPAQUE
107 This is an opaque data structure.
108 .It Dv CTLTYPE_STRUCT
109 Alias for
110 .Dv CTLTYPE_OPAQUE .
111 .It Dv CTLTYPE_UINT
112 This is an unsigned integer.
113 .It Dv CTLTYPE_LONG
114 This is a signed long.
115 .It Dv CTLTYPE_ULONG
116 This is an unsigned long.
117 .It Dv CTLTYPE_U64
118 This is a 64-bit unsigned integer.
119 .El
120 .Pp
121 All sysctl types except for new node declarations require one or more flags
122 to be set indicating the read and write disposition of the sysctl:
123 .Bl -tag -width ".Dv CTLFLAG_ANYBODY"
124 .It Dv CTLFLAG_RD
125 This is a read-only sysctl.
126 .It Dv CTLFLAG_WR
127 This is a writable sysctl.
128 .It Dv CTLFLAG_RW
129 This sysctl is readable and writable.
130 .It Dv CTLFLAG_ANYBODY
131 Any user or process can write to this sysctl.
132 .It Dv CTLFLAG_SECURE
133 This sysctl can be written to only if the effective securelevel of the
134 process is \[<=] 0.
135 .It Dv CTLFLAG_PRISON
136 This sysctl can be written to by processes in
137 .Xr jail 2 .
138 .It Dv CTLFLAG_SKIP
139 When iterating the sysctl name space, do not list this sysctl.
140 .It Dv CTLFLAG_TUN
141 Advisory flag that a system tunable also exists for this variable.
142 .It Dv CTLFLAG_RDTUN
143 Advisory flag that a system tunable also exists for this variable;
144 however, the run-time variable is read-only.
145 .El
146 .Pp
147 When creating new sysctls, careful attention should be paid to the security
148 implications of the monitoring or management interface being created.
149 Most sysctls present in the kernel are read-only or writable only by the
150 superuser.
151 Sysctls exporting extensive information on system data structures and
152 operation, especially those implemented using procedures, will wish to
153 implement access control to limit the undesired exposure of information about
154 other processes, network connections, etc.
155 .Pp
156 The following top level sysctl name spaces are commonly used:
157 .Bl -tag -width ".Va regression"
158 .It Va compat
159 Compatibility layer information.
160 .It Va debug
161 Debugging information.
162 Various name spaces exist under
163 .Va debug .
164 .It Va hw
165 Hardware and device driver information.
166 .It Va kern
167 Kernel behavior tuning; generally deprecated in favor of more specific
168 name spaces.
169 .It Va machdep
170 Machine-dependent configuration parameters.
171 .It Va net
172 Network subsystem.
173 Various protocols have name spaces under
174 .Va net .
175 .It Va regression
176 Regression test configuration and information.
177 .It Va security
178 Security and security-policy configuration and information.
179 .It Va sysctl
180 Reserved name space for the implementation of sysctl.
181 .It Va user
182 Configuration settings relating to user application behavior.
183 Generally, configuring applications using kernel sysctls is discouraged.
184 .It Va vfs
185 Virtual file system configuration and information.
186 .It Va vm
187 Virtual memory subsystem configuration and information.
188 .El
189 .Sh EXAMPLES
190 Sample use of
191 .Fn SYSCTL_DECL
192 to declare the
193 .Va security
194 sysctl tree for use by new nodes:
195 .Bd -literal -offset indent
196 SYSCTL_DECL(_security);
197 .Ed
198 .Pp
199 Examples of integer, opaque, string, and procedure sysctls follow:
200 .Bd -literal -offset indent
201 /*
202  * Example of a constant integer value.  Notice that the control
203  * flags are CTLFLAG_RD, the variable pointer is NULL, and the
204  * value is declared.
205  */
206 SYSCTL_INT(_debug_sizeof, OID_AUTO, bio, CTLFLAG_RD, NULL,
207     sizeof(struct bio), "sizeof(struct bio)");
208
209 /*
210  * Example of a variable integer value.  Notice that the control
211  * flags are CTLFLAG_RW, the variable pointer is set, and the
212  * value is 0.
213  */
214 static int      doingcache = 1;         /* 1 => enable the cache */
215 SYSCTL_INT(_debug, OID_AUTO, vfscache, CTLFLAG_RW, &doingcache, 0,
216     "Enable name cache");
217
218 /*
219  * Example of a variable string value.  Notice that the control
220  * flags are CTLFLAG_RW, that the variable pointer and string
221  * size are set.  Unlike newer sysctls, this older sysctl uses a
222  * static oid number.
223  */
224 char kernelname[MAXPATHLEN] = "/kernel";        /* XXX bloat */
225 SYSCTL_STRING(_kern, KERN_BOOTFILE, bootfile, CTLFLAG_RW,
226     kernelname, sizeof(kernelname), "Name of kernel file booted");
227
228 /*
229  * Example of an opaque data type exported by sysctl.  Notice that
230  * the variable pointer and size are provided, as well as a format
231  * string for sysctl(8).
232  */
233 static l_fp pps_freq;   /* scaled frequence offset (ns/s) */
234 SYSCTL_OPAQUE(_kern_ntp_pll, OID_AUTO, pps_freq, CTLFLAG_RD,
235     &pps_freq, sizeof(pps_freq), "I", "");
236
237 /*
238  * Example of a procedure based sysctl exporting string
239  * information.  Notice that the data type is declared, the NULL
240  * variable pointer and 0 size, the function pointer, and the
241  * format string for sysctl(8).
242  */
243 SYSCTL_PROC(_kern_timecounter, OID_AUTO, hardware, CTLTYPE_STRING |
244     CTLFLAG_RW, NULL, 0, sysctl_kern_timecounter_hardware, "A",
245     "");
246 .Ed
247 .Sh SYSCTL NAMING
248 When adding, modifying, or removing sysctl names, it is important to be
249 aware that these interfaces may be used by users, libraries, applications,
250 or documentation (such as published books), and are implicitly published application interfaces.
251 As with other application interfaces, caution must be taken not to break
252 existing applications, and to think about future use of new name spaces so as
253 to avoid the need to rename or remove interfaces that might be depended on in
254 the future.
255 .Pp
256 The semantics chosen for a new sysctl should be as clear as possible,
257 and the name of the sysctl must closely reflect its semantics.
258 Therefore the sysctl name deserves a fair amount of consideration.
259 It should be short but yet representative of the sysctl meaning.
260 If the name consists of several words, they should be separated by
261 underscore characters, as in
262 .Va compute_summary_at_mount .
263 Underscore characters may be omitted only if the name consists of not more
264 than two words, each being not longer than four characters, as in
265 .Va bootfile .
266 For boolean sysctls, negative logic should be totally avoided.
267 That is, do not use names like
268 .Va no_foobar
269 or
270 .Va foobar_disable .
271 They are confusing and lead to configuration errors.
272 Use positive logic instead:
273 .Va foobar ,
274 .Va foobar_enable .
275 .Pp
276 A temporary sysctl node that should not be relied upon must be designated
277 as such by a leading underscore character in its name.  For example:
278 .Va _dirty_hack .
279 .Sh SEE ALSO
280 .Xr sysctl 3 ,
281 .Xr sysctl 8 ,
282 .Xr sysctl_add_oid 9 ,
283 .Xr sysctl_ctx_free 9 ,
284 .Xr sysctl_ctx_init 9 ,
285 .Xr sysctl_remove_oid 9
286 .Sh HISTORY
287 The
288 .Xr sysctl 8
289 utility first appeared in
290 .Bx 4.4 .
291 .Sh AUTHORS
292 .An -nosplit
293 The
294 .Nm sysctl
295 implementation originally found in
296 .Bx
297 has been extensively rewritten by
298 .An Poul-Henning Kamp
299 in order to add support for name lookups, name space iteration, and dynamic
300 addition of MIB nodes.
301 .Pp
302 This man page was written by
303 .An Robert N. M. Watson .