sysctl.9 (f3066f2be73aa3fe83f9d56b1977e130659da3f3) sysctl.9 (dba9e9ccbfd771d5521657cc68cc537c7da99e41)
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

--- 11 unchanged lines hidden (view full) ---

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.\"
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

--- 11 unchanged lines hidden (view full) ---

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
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 ,
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.Nm SYSCTL_QUAD
41.Nm SYSCTL_ULONG
45.Nd Static sysctl declaration functions
46.Sh SYNOPSIS
47.In sys/types.h
48.In sys/sysctl.h
42.Nd Static sysctl declaration functions
43.Sh SYNOPSIS
44.In sys/types.h
45.In sys/sysctl.h
49.Fn SYSCTL_DECL name
50.Fn SYSCTL_INT parent nbr name access ptr val descr
51.Fn SYSCTL_LONG parent nbr name access ptr val descr
52.Fn SYSCTL_NODE parent nbr name access handler descr
53.Fn SYSCTL_OPAQUE parent nbr name access ptr len fmt descr
54.Fn SYSCTL_PROC parent nbr name access ptr arg handler fmt descr
55.Fn SYSCTL_STRING parent nbr name access arg len descr
56.Fn SYSCTL_STRUCT parent nbr name access ptr type descr
57.Fn SYSCTL_UINT parent nbr name access ptr val descr
58.Fn SYSCTL_ULONG parent nbr name access ptr val descr
59.Fn SYSCTL_XINT parent nbr name access ptr val descr
60.Fn SYSCTL_XLONG parent nbr name access ptr val descr
61.Fn SYSCTL_QUAD parent nbr name access ptr val descr
46.Fo SYSCTL_DECL
47.Fa "name"
48.Fc
49.Fo SYSCTL_INT
50.Fa "parent"
51.Fa "nbr"
52.Fa "name"
53.Fa "access"
54.Fa "ptr"
55.Fa "val"
56.Fa "descr"
57.Fc
58.Fo SYSCTL_LONG
59.Fa "parent"
60.Fa "nbr"
61.Fa "name"
62.Fa "access"
63.Fa "ptr"
64.Fa "val"
65.Fa "descr"
66.Fc
67.Fo SYSCTL_NODE
68.Fa "parent"
69.Fa "nbr"
70.Fa "name"
71.Fa "access"
72.Fa "handler"
73.Fa "descr"
74.Fc
75.Fo SYSCTL_OPAQUE
76.Fa "parent"
77.Fa "nbr"
78.Fa "name"
79.Fa "access"
80.Fa "ptr"
81.Fa "len"
82.Fa "fmt"
83.Fa "descr"
84.Fc
85.Fo SYSCTL_PROC
86.Fa "parent"
87.Fa "nbr"
88.Fa "name"
89.Fa "access"
90.Fa "ptr"
91.Fa "arg"
92.Fa "handler"
93.Fa "fmt"
94.Fa "descr"
95.Fc
96.Fo SYSCTL_STRING
97.Fa "parent"
98.Fa "nbr"
99.Fa "name"
100.Fa "access"
101.Fa "arg"
102.Fa "len"
103.Fa "descr"
104.Fc
105.Fo SYSCTL_STRUCT
106.Fa "parent"
107.Fa "nbr"
108.Fa "name"
109.Fa "access"
110.Fa "ptr"
111.Fa "type"
112.Fa "descr"
113.Fc
114.Fo SYSCTL_UINT
115.Fa "parent"
116.Fa "nbr"
117.Fa "name"
118.Fa "access"
119.Fa "ptr"
120.Fa "val"
121.Fa "descr"
122.Fc
123.Fo SYSCTL_ULONG
124.Fa "parent"
125.Fa "nbr"
126.Fa "name"
127.Fa "access"
128.Fa "ptr"
129.Fa "val"
130.Fa "descr"
131.Fc
62.Sh DESCRIPTION
63The
132.Sh DESCRIPTION
133The
64.Nm SYSCTL
134.Nm
65kernel interfaces allow code to statically declare
66.Xr sysctl 8
67MIB entries, which will be initialized when the kernel module containing the
68declaration is initialized.
69When the module is unloaded, the sysctl will be automatically destroyed.
70.Pp
135kernel interfaces allow code to statically declare
136.Xr sysctl 8
137MIB entries, which will be initialized when the kernel module containing the
138declaration is initialized.
139When the module is unloaded, the sysctl will be automatically destroyed.
140.Pp
71Sysctl nodes are created in a hierarchical tree, with all static nodes being
141Sysctl nodes are created in a hierarchal tree, with all static nodes being
72represented by named C data structures; in order to create a new node under
73an existing node in the tree, the structure representing the desired parent
74node must be declared in the current context using
75.Fn SYSCTL_DECL .
76.Pp
77New nodes are declared using one of
142represented by named C data structures; in order to create a new node under
143an existing node in the tree, the structure representing the desired parent
144node must be declared in the current context using
145.Fn SYSCTL_DECL .
146.Pp
147New nodes are declared using one of
78.Fn SYSCTL_INT ,
79.Fn SYSCTL_LONG ,
80.Fn SYSCTL_NODE ,
81.Fn SYSCTL_OPAQUE ,
82.Fn SYSCTL_PROC ,
83.Fn SYSCTL_STRING ,
84.Fn SYSCTL_STRUCT ,
85.Fn SYSCTL_UINT ,
86.Fn SYSCTL_ULONG ,
87.Fn SYSCTL_XINT ,
88.Fn SYSCTL_XLONG ,
148.Nm SYSCTL_INT ,
149.Nm SYSCTL_LONG ,
150.Nm SYSCTL_NODE ,
151.Nm SYSCTL_OPAQUE ,
152.Nm SYSCTL_PROC ,
153.Nm SYSCTL_STRING ,
154.Nm SYSCTL_STRUCT ,
155.Nm SYSCTL_UINT ,
89and
156and
90.Fn SYSCTL_QUAD .
157.Nm SYSCTL_ULONG .
91Each macro accepts a parent name, as declared using
158Each macro accepts a parent name, as declared using
92.Fn SYSCTL_DECL ,
159.Nm SYSCTL_DECL ,
93an OID number, typically
94.Dv OID_AUTO ,
95a node name, a set of control and access flags, and a description.
96Depending on the macro, a pointer to a variable supporting the MIB entry, a
97size, a value, and a function pointer implementing the MIB entry may also be
98present.
99.Pp
100For most of the above macros, declaring a type as part of the access flags is
160an OID number, typically
161.Dv OID_AUTO ,
162a node name, a set of control and access flags, and a description.
163Depending on the macro, a pointer to a variable supporting the MIB entry, a
164size, a value, and a function pointer implementing the MIB entry may also be
165present.
166.Pp
167For most of the above macros, declaring a type as part of the access flags is
101not necessary \[em] however, when declaring a sysctl implemented by a function,
168not necessary -- however, when declaring a sysctl implemented by a function,
102including a type in the access mask is required:
169including a type in the access mask is required:
103.Bl -tag -width ".Dv CTLTYPE_STRING"
170.Bl -tag -width CTLTYPE_STRING
104.It Dv CTLTYPE_NODE
105This is a node intended to be a parent for other nodes.
106.It Dv CTLTYPE_INT
107This is a signed integer.
108.It Dv CTLTYPE_STRING
109This is a nul-terminated string stored in a character array.
110.It Dv CTLTYPE_QUAD
111This is a 64-bit signed integer.
112.It Dv CTLTYPE_OPAQUE
113This is an opaque data structure.
114.It Dv CTLTYPE_STRUCT
115Alias for
116.Dv CTLTYPE_OPAQUE.
117.It Dv CTLTYPE_UINT
118This is an unsigned integer.
119.It Dv CTLTYPE_LONG
120This is a signed long.
121.It Dv CTLTYPE_ULONG
171.It Dv CTLTYPE_NODE
172This is a node intended to be a parent for other nodes.
173.It Dv CTLTYPE_INT
174This is a signed integer.
175.It Dv CTLTYPE_STRING
176This is a nul-terminated string stored in a character array.
177.It Dv CTLTYPE_QUAD
178This is a 64-bit signed integer.
179.It Dv CTLTYPE_OPAQUE
180This is an opaque data structure.
181.It Dv CTLTYPE_STRUCT
182Alias for
183.Dv CTLTYPE_OPAQUE.
184.It Dv CTLTYPE_UINT
185This is an unsigned integer.
186.It Dv CTLTYPE_LONG
187This is a signed long.
188.It Dv CTLTYPE_ULONG
122This is an unsigned long.
189This is an insigned long.
123.El
124.Pp
125All sysctl types except for new node declarations require one or more flags
126to be set indicating the read and write disposition of the sysctl:
190.El
191.Pp
192All sysctl types except for new node declarations require one or more flags
193to be set indicating the read and write disposition of the sysctl:
127.Bl -tag -width ".Dv CTLFLAG_ANYBODY"
194.Bl -tag -width CTLFLAG_ANYBODY
128.It Dv CTLFLAG_RD
129This is a read-only sysctl.
195.It Dv CTLFLAG_RD
196This is a read-only sysctl.
130.It Dv CTLFLAG_WR
197It Dv CTLFLAG_WR
131This is a writable sysctl.
132.It Dv CTLFLAG_RW
133This sysctl is readable and writable.
134.It Dv CTLFLAG_ANYBODY
135Any user or process can write to this sysctl.
136.It Dv CTLFLAG_SECURE
137This sysctl can be written to only if the effective securelevel of the
198This is a writable sysctl.
199.It Dv CTLFLAG_RW
200This sysctl is readable and writable.
201.It Dv CTLFLAG_ANYBODY
202Any user or process can write to this sysctl.
203.It Dv CTLFLAG_SECURE
204This sysctl can be written to only if the effective securelevel of the
138process is \[<=] 0.
205process is <= 0.
139.It Dv CTLFLAG_PRISON
140This sysctl can be written to by processes in
141.Xr jail 2 .
142.It Dv CTLFLAG_SKIP
143When iterating the sysctl name space, do not list this sysctl.
144.It Dv CTLFLAG_TUN
145Also declare a system tunable with the same name to initialize this variable.
146.It Dv CTLFLAG_RDTUN
206.It Dv CTLFLAG_PRISON
207This sysctl can be written to by processes in
208.Xr jail 2 .
209.It Dv CTLFLAG_SKIP
210When iterating the sysctl name space, do not list this sysctl.
211.It Dv CTLFLAG_TUN
212Also declare a system tunable with the same name to initialize this variable.
213.It Dv CTLFLAG_RDTUN
147Also declare a system tunable with the same name to initialize this variable;
214Also declare a system tunable with the same name to initalize this variable;
148however, the run-time variable is read-only.
149.El
150.Pp
151When creating new sysctls, careful attention should be paid to the security
152implications of the monitoring or management interface being created.
153Most sysctls present in the kernel are read-only or writable only by the
154superuser.
155Sysctls exporting extensive information on system data structures and
156operation, especially those implemented using procedures, will wish to
157implement access control to limit the undesired exposure of information about
158other processes, network connections, etc.
159.Pp
160The following top level sysctl name spaces are commonly used:
215however, the run-time variable is read-only.
216.El
217.Pp
218When creating new sysctls, careful attention should be paid to the security
219implications of the monitoring or management interface being created.
220Most sysctls present in the kernel are read-only or writable only by the
221superuser.
222Sysctls exporting extensive information on system data structures and
223operation, especially those implemented using procedures, will wish to
224implement access control to limit the undesired exposure of information about
225other processes, network connections, etc.
226.Pp
227The following top level sysctl name spaces are commonly used:
161.Bl -tag -width ".Va regression"
162.It Va compat
228.Bl -tag -width regression
229.It Dv compat
163Compatibility layer information.
230Compatibility layer information.
164.It Va debug
231.It Dv debug
165Debugging information.
166Various name spaces exist under
232Debugging information.
233Various name spaces exist under
167.Va debug .
168.It Va hw
234.Dv debug .
235.It Dv hw
169Hardware and device driver information.
236Hardware and device driver information.
170.It Va kern
237.It Dv kern
171Kernel behavior tuning; generally deprecated in favor of more specific
172name spaces.
238Kernel behavior tuning; generally deprecated in favor of more specific
239name spaces.
173.It Va machdep
240.It Dv machdep
174Machine-dependent configuration parameters.
241Machine-dependent configuration parameters.
175.It Va net
242.It Dv net
176Network subsystem.
177Various protocols have name spaces under
243Network subsystem.
244Various protocols have name spaces under
178.Va net .
179.It Va regression
245.Dv net .
246.It Dv regression
180Regression test configuration and information.
247Regression test configuration and information.
181.It Va security
182Security and security-policy configuration and information.
183.It Va sysctl
248.It Dv security
249Security and security policy configuration and information.
250.It Dv sysctl
184Reserved name space for the implementation of sysctl.
251Reserved name space for the implementation of sysctl.
185.It Va user
252.It Dv user
186Configuration settings relating to user application behavior.
253Configuration settings relating to user application behavior.
187Generally, configuring applications using kernel sysctls is discouraged.
188.It Va vfs
254Generally, configuring applications using kernel sysctls is disouraged.
255.It Dv vfs
189Virtual file system configuration and information.
256Virtual file system configuration and information.
190.It Va vm
257.It Dv vm
191Virtual memory subsystem configuration and information.
192.El
193.Sh EXAMPLES
194Sample use of
258Virtual memory subsystem configuration and information.
259.El
260.Sh EXAMPLES
261Sample use of
195.Fn SYSCTL_DECL
196to declare the
197.Va security
198sysctl tree for use by new nodes:
262.Nm SYSCTL_DECL
263to declare the "security" sysctl tree for use by new nodes:
199.Bd -literal -offset indent
200SYSCTL_DECL(_security);
201.Ed
202.Pp
203Examples of integer, opaque, string, and procedure sysctls follow:
204.Bd -literal -offset indent
205/*
206 * Example of a constant integer value. Notice that the control
207 * flags are CTLFLAG_RD, the variable pointer is NULL, and the
208 * value is declared.
264.Bd -literal -offset indent
265SYSCTL_DECL(_security);
266.Ed
267.Pp
268Examples of integer, opaque, string, and procedure sysctls follow:
269.Bd -literal -offset indent
270/*
271 * Example of a constant integer value. Notice that the control
272 * flags are CTLFLAG_RD, the variable pointer is NULL, and the
273 * value is declared.
209 * If sysctl(8) should print this value in hex, use 'SYSCTL_XINT'.
210 */
211SYSCTL_INT(_debug_sizeof, OID_AUTO, bio, CTLFLAG_RD, NULL,
212 sizeof(struct bio), "sizeof(struct bio)");
213
214/*
215 * Example of a variable integer value. Notice that the control
216 * flags are CTLFLAG_RW, the variable pointer is set, and the
217 * value is 0.

--- 26 unchanged lines hidden (view full) ---

244 * information. Notice that the data type is declared, the NULL
245 * variable pointer and 0 size, the function pointer, and the
246 * format string for sysctl(8).
247 */
248SYSCTL_PROC(_kern_timecounter, OID_AUTO, hardware, CTLTYPE_STRING |
249 CTLFLAG_RW, NULL, 0, sysctl_kern_timecounter_hardware, "A",
250 "");
251.Ed
274 */
275SYSCTL_INT(_debug_sizeof, OID_AUTO, bio, CTLFLAG_RD, NULL,
276 sizeof(struct bio), "sizeof(struct bio)");
277
278/*
279 * Example of a variable integer value. Notice that the control
280 * flags are CTLFLAG_RW, the variable pointer is set, and the
281 * value is 0.

--- 26 unchanged lines hidden (view full) ---

308 * information. Notice that the data type is declared, the NULL
309 * variable pointer and 0 size, the function pointer, and the
310 * format string for sysctl(8).
311 */
312SYSCTL_PROC(_kern_timecounter, OID_AUTO, hardware, CTLTYPE_STRING |
313 CTLFLAG_RW, NULL, 0, sysctl_kern_timecounter_hardware, "A",
314 "");
315.Ed
252.Sh SYSCTL NAMING
316.Pp
253When adding, modifying, or removing sysctl names, it is important to be
254aware that these interfaces may be used by users, libraries, applications,
317When adding, modifying, or removing sysctl names, it is important to be
318aware that these interfaces may be used by users, libraries, applications,
255or documentation (such as published books), and are implicitly published application interfaces.
319and even books, and are implicitly published application interfaces.
256As with other application interfaces, caution must be taken not to break
257existing applications, and to think about future use of new name spaces so as
258to avoid the need to rename or remove interfaces that might be depended on in
259the future.
320As with other application interfaces, caution must be taken not to break
321existing applications, and to think about future use of new name spaces so as
322to avoid the need to rename or remove interfaces that might be depended on in
323the future.
260.Pp
261The semantics chosen for a new sysctl should be as clear as possible,
262and the name of the sysctl must closely reflect its semantics.
263Therefore the sysctl name deserves a fair amount of consideration.
264It should be short but yet representative of the sysctl meaning.
265If the name consists of several words, they should be separated by
266underscore characters, as in
267.Va compute_summary_at_mount .
268Underscore characters may be omitted only if the name consists of not more
269than two words, each being not longer than four characters, as in
270.Va bootfile .
271For boolean sysctls, negative logic should be totally avoided.
272That is, do not use names like
273.Va no_foobar
274or
275.Va foobar_disable .
276They are confusing and lead to configuration errors.
277Use positive logic instead:
278.Va foobar ,
279.Va foobar_enable .
280.Pp
281A temporary sysctl node that should not be relied upon must be designated
282as such by a leading underscore character in its name. For example:
283.Va _dirty_hack .
284.Sh SEE ALSO
324.Sh SEE ALSO
285.Xr sysctl 3 ,
286.Xr sysctl 8 ,
287.Xr sysctl_add_oid 9 ,
288.Xr sysctl_ctx_free 9 ,
289.Xr sysctl_ctx_init 9 ,
290.Xr sysctl_remove_oid 9
291.Sh HISTORY
325.Xr sysctl 8 ,
326.Xr sysctl_add_oid 9 ,
327.Xr sysctl_ctx_free 9 ,
328.Xr sysctl_ctx_init 9 ,
329.Xr sysctl_remove_oid 9
330.Sh HISTORY
292The
293.Xr sysctl 8
331.Xr sysctl 8
294utility first appeared in
332first appeared in
295.Bx 4.4 .
296.Sh AUTHORS
333.Bx 4.4 .
334.Sh AUTHORS
297.An -nosplit
298The
299.Nm sysctl
300implementation originally found in
335The sysctl implementation originally found in
301.Bx
302has been extensively rewritten by
303.An Poul-Henning Kamp
304in order to add support for name lookups, name space iteration, and dynamic
305addition of MIB nodes.
306.Pp
307This man page was written by
308.An Robert N. M. Watson .
336.Bx
337has been extensively rewritten by
338.An Poul-Henning Kamp
339in order to add support for name lookups, name space iteration, and dynamic
340addition of MIB nodes.
341.Pp
342This man page was written by
343.An Robert N. M. Watson .