]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/man/man9/sysctl.9
This commit was generated by cvs2svn to compensate for changes in r161351,
[FreeBSD/FreeBSD.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 April 28, 2006
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_XINT ,
43 .Nm SYSCTL_XLONG
44 .Nd Static sysctl declaration functions
45 .Sh SYNOPSIS
46 .In sys/types.h
47 .In sys/sysctl.h
48 .Fo SYSCTL_DECL
49 .Fa "name"
50 .Fc
51 .Fo SYSCTL_INT
52 .Fa "parent"
53 .Fa "nbr"
54 .Fa "name"
55 .Fa "access"
56 .Fa "ptr"
57 .Fa "val"
58 .Fa "descr"
59 .Fc
60 .Fo SYSCTL_LONG
61 .Fa "parent"
62 .Fa "nbr"
63 .Fa "name"
64 .Fa "access"
65 .Fa "ptr"
66 .Fa "val"
67 .Fa "descr"
68 .Fc
69 .Fo SYSCTL_NODE
70 .Fa "parent"
71 .Fa "nbr"
72 .Fa "name"
73 .Fa "access"
74 .Fa "handler"
75 .Fa "descr"
76 .Fc
77 .Fo SYSCTL_OPAQUE
78 .Fa "parent"
79 .Fa "nbr"
80 .Fa "name"
81 .Fa "access"
82 .Fa "ptr"
83 .Fa "len"
84 .Fa "fmt"
85 .Fa "descr"
86 .Fc
87 .Fo SYSCTL_PROC
88 .Fa "parent"
89 .Fa "nbr"
90 .Fa "name"
91 .Fa "access"
92 .Fa "ptr"
93 .Fa "arg"
94 .Fa "handler"
95 .Fa "fmt"
96 .Fa "descr"
97 .Fc
98 .Fo SYSCTL_STRING
99 .Fa "parent"
100 .Fa "nbr"
101 .Fa "name"
102 .Fa "access"
103 .Fa "arg"
104 .Fa "len"
105 .Fa "descr"
106 .Fc
107 .Fo SYSCTL_STRUCT
108 .Fa "parent"
109 .Fa "nbr"
110 .Fa "name"
111 .Fa "access"
112 .Fa "ptr"
113 .Fa "type"
114 .Fa "descr"
115 .Fc
116 .Fo SYSCTL_UINT
117 .Fa "parent"
118 .Fa "nbr"
119 .Fa "name"
120 .Fa "access"
121 .Fa "ptr"
122 .Fa "val"
123 .Fa "descr"
124 .Fc
125 .Fo SYSCTL_ULONG
126 .Fa "parent"
127 .Fa "nbr"
128 .Fa "name"
129 .Fa "access"
130 .Fa "ptr"
131 .Fa "val"
132 .Fa "descr"
133 .Fc
134 .Fo SYSCTL_XINT
135 .Fa "parent"
136 .Fa "nbr"
137 .Fa "name"
138 .Fa "access"
139 .Fa "ptr"
140 .Fa "val"
141 .Fa "descr"
142 .Fc
143 .Fo SYSCTL_XLONG
144 .Fa "parent"
145 .Fa "nbr"
146 .Fa "name"
147 .Fa "access"
148 .Fa "ptr"
149 .Fa "val"
150 .Fa "descr"
151 .Fc
152 .Sh DESCRIPTION
153 The
154 .Nm
155 kernel interfaces allow code to statically declare
156 .Xr sysctl 8
157 MIB entries, which will be initialized when the kernel module containing the
158 declaration is initialized.
159 When the module is unloaded, the sysctl will be automatically destroyed.
160 .Pp
161 Sysctl nodes are created in a hierarchical tree, with all static nodes being
162 represented by named C data structures; in order to create a new node under
163 an existing node in the tree, the structure representing the desired parent
164 node must be declared in the current context using
165 .Fn SYSCTL_DECL .
166 .Pp
167 New nodes are declared using one of
168 .Nm SYSCTL_INT ,
169 .Nm SYSCTL_LONG ,
170 .Nm SYSCTL_NODE ,
171 .Nm SYSCTL_OPAQUE ,
172 .Nm SYSCTL_PROC ,
173 .Nm SYSCTL_STRING ,
174 .Nm SYSCTL_STRUCT ,
175 .Nm SYSCTL_UINT ,
176 .Nm SYSCTL_ULONG ,
177 .Nm SYSCTL_XINT ,
178 and
179 .Nm SYSCTL_XLONG .
180 Each macro accepts a parent name, as declared using
181 .Nm SYSCTL_DECL ,
182 an OID number, typically
183 .Dv OID_AUTO ,
184 a node name, a set of control and access flags, and a description.
185 Depending on the macro, a pointer to a variable supporting the MIB entry, a
186 size, a value, and a function pointer implementing the MIB entry may also be
187 present.
188 .Pp
189 For most of the above macros, declaring a type as part of the access flags is
190 not necessary -- however, when declaring a sysctl implemented by a function,
191 including a type in the access mask is required:
192 .Bl -tag -width CTLTYPE_STRING
193 .It Dv CTLTYPE_NODE
194 This is a node intended to be a parent for other nodes.
195 .It Dv CTLTYPE_INT
196 This is a signed integer.
197 .It Dv CTLTYPE_STRING
198 This is a nul-terminated string stored in a character array.
199 .It Dv CTLTYPE_QUAD
200 This is a 64-bit signed integer.
201 .It Dv CTLTYPE_OPAQUE
202 This is an opaque data structure.
203 .It Dv CTLTYPE_STRUCT
204 Alias for
205 .Dv CTLTYPE_OPAQUE.
206 .It Dv CTLTYPE_UINT
207 This is an unsigned integer.
208 .It Dv CTLTYPE_LONG
209 This is a signed long.
210 .It Dv CTLTYPE_ULONG
211 This is an unsigned long.
212 .El
213 .Pp
214 All sysctl types except for new node declarations require one or more flags
215 to be set indicating the read and write disposition of the sysctl:
216 .Bl -tag -width CTLFLAG_ANYBODY
217 .It Dv CTLFLAG_RD
218 This is a read-only sysctl.
219 .It Dv CTLFLAG_WR
220 This is a writable sysctl.
221 .It Dv CTLFLAG_RW
222 This sysctl is readable and writable.
223 .It Dv CTLFLAG_ANYBODY
224 Any user or process can write to this sysctl.
225 .It Dv CTLFLAG_SECURE
226 This sysctl can be written to only if the effective securelevel of the
227 process is <= 0.
228 .It Dv CTLFLAG_PRISON
229 This sysctl can be written to by processes in
230 .Xr jail 2 .
231 .It Dv CTLFLAG_SKIP
232 When iterating the sysctl name space, do not list this sysctl.
233 .It Dv CTLFLAG_TUN
234 Also declare a system tunable with the same name to initialize this variable.
235 .It Dv CTLFLAG_RDTUN
236 Also declare a system tunable with the same name to initalize this variable;
237 however, the run-time variable is read-only.
238 .El
239 .Pp
240 When creating new sysctls, careful attention should be paid to the security
241 implications of the monitoring or management interface being created.
242 Most sysctls present in the kernel are read-only or writable only by the
243 superuser.
244 Sysctls exporting extensive information on system data structures and
245 operation, especially those implemented using procedures, will wish to
246 implement access control to limit the undesired exposure of information about
247 other processes, network connections, etc.
248 .Pp
249 The following top level sysctl name spaces are commonly used:
250 .Bl -tag -width regression
251 .It Dv compat
252 Compatibility layer information.
253 .It Dv debug
254 Debugging information.
255 Various name spaces exist under
256 .Dv debug .
257 .It Dv hw
258 Hardware and device driver information.
259 .It Dv kern
260 Kernel behavior tuning; generally deprecated in favor of more specific
261 name spaces.
262 .It Dv machdep
263 Machine-dependent configuration parameters.
264 .It Dv net
265 Network subsystem.
266 Various protocols have name spaces under
267 .Dv net .
268 .It Dv regression
269 Regression test configuration and information.
270 .It Dv security
271 Security and security-policy configuration and information.
272 .It Dv sysctl
273 Reserved name space for the implementation of sysctl.
274 .It Dv user
275 Configuration settings relating to user application behavior.
276 Generally, configuring applications using kernel sysctls is discouraged.
277 .It Dv vfs
278 Virtual file system configuration and information.
279 .It Dv vm
280 Virtual memory subsystem configuration and information.
281 .El
282 .Sh EXAMPLES
283 Sample use of
284 .Nm SYSCTL_DECL
285 to declare the "security" sysctl tree for use by new nodes:
286 .Bd -literal -offset indent
287 SYSCTL_DECL(_security);
288 .Ed
289 .Pp
290 Examples of integer, opaque, string, and procedure sysctls follow:
291 .Bd -literal -offset indent
292 /*
293  * Example of a constant integer value.  Notice that the control
294  * flags are CTLFLAG_RD, the variable pointer is NULL, and the
295  * value is declared.
296  * If sysctl(8) should print this value in hex, use 'SYSCTL_XINT'.
297  */
298 SYSCTL_INT(_debug_sizeof, OID_AUTO, bio, CTLFLAG_RD, NULL,
299     sizeof(struct bio), "sizeof(struct bio)");
300
301 /*
302  * Example of a variable integer value.  Notice that the control
303  * flags are CTLFLAG_RW, the variable pointer is set, and the
304  * value is 0.
305  */
306 static int      doingcache = 1;         /* 1 => enable the cache */
307 SYSCTL_INT(_debug, OID_AUTO, vfscache, CTLFLAG_RW, &doingcache, 0,
308     "Enable name cache");
309
310 /*
311  * Example of a variable string value.  Notice that the control
312  * flags are CTLFLAG_RW, that the variable pointer and string
313  * size are set.  Unlike newer sysctls, this older sysctl uses a
314  * static oid number.
315  */
316 char kernelname[MAXPATHLEN] = "/kernel";        /* XXX bloat */
317 SYSCTL_STRING(_kern, KERN_BOOTFILE, bootfile, CTLFLAG_RW,
318     kernelname, sizeof(kernelname), "Name of kernel file booted");
319
320 /*
321  * Example of an opaque data type exported by sysctl.  Notice that
322  * the variable pointer and size are provided, as well as a format
323  * string for sysctl(8).
324  */
325 static l_fp pps_freq;   /* scaled frequence offset (ns/s) */
326 SYSCTL_OPAQUE(_kern_ntp_pll, OID_AUTO, pps_freq, CTLFLAG_RD,
327     &pps_freq, sizeof(pps_freq), "I", "");
328
329 /*
330  * Example of a procedure based sysctl exporting string
331  * information.  Notice that the data type is declared, the NULL
332  * variable pointer and 0 size, the function pointer, and the
333  * format string for sysctl(8).
334  */
335 SYSCTL_PROC(_kern_timecounter, OID_AUTO, hardware, CTLTYPE_STRING |
336     CTLFLAG_RW, NULL, 0, sysctl_kern_timecounter_hardware, "A",
337     "");
338 .Ed
339 .Pp
340 When adding, modifying, or removing sysctl names, it is important to be
341 aware that these interfaces may be used by users, libraries, applications,
342 or documentation (such as published books), and are implicitly published application interfaces.
343 As with other application interfaces, caution must be taken not to break
344 existing applications, and to think about future use of new name spaces so as
345 to avoid the need to rename or remove interfaces that might be depended on in
346 the future.
347 .Sh SEE ALSO
348 .Xr sysctl 8 ,
349 .Xr sysctl_add_oid 9 ,
350 .Xr sysctl_ctx_free 9 ,
351 .Xr sysctl_ctx_init 9 ,
352 .Xr sysctl_remove_oid 9
353 .Sh HISTORY
354 .Xr sysctl 8
355 first appeared in
356 .Bx 4.4 .
357 .Sh AUTHORS
358 The sysctl implementation originally found in
359 .Bx
360 has been extensively rewritten by
361 .An Poul-Henning Kamp
362 in order to add support for name lookups, name space iteration, and dynamic
363 addition of MIB nodes.
364 .Pp
365 This man page was written by
366 .An Robert N. M. Watson .