xref: /freebsd/lib/libc/gen/sysctl.3 (revision 266f97b5)
1.\" Copyright (c) 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.\"	@(#)sysctl.3	8.4 (Berkeley) 5/9/95
29.\" $FreeBSD$
30.\"
31.Dd October 18, 2021
32.Dt SYSCTL 3
33.Os
34.Sh NAME
35.Nm sysctl ,
36.Nm sysctlbyname ,
37.Nm sysctlnametomib
38.Nd get or set system information
39.Sh LIBRARY
40.Lb libc
41.Sh SYNOPSIS
42.In sys/sysctl.h
43.Ft int
44.Fn sysctl "const int *name" "u_int namelen" "void *oldp" "size_t *oldlenp" "const void *newp" "size_t newlen"
45.Ft int
46.Fn sysctlbyname "const char *name" "void *oldp" "size_t *oldlenp" "const void *newp" "size_t newlen"
47.Ft int
48.Fn sysctlnametomib "const char *name" "int *mibp" "size_t *sizep"
49.Sh DESCRIPTION
50The
51.Fn sysctl
52function retrieves system information and allows processes with
53appropriate privileges to set system information.
54The information available from
55.Fn sysctl
56consists of integers, strings, and tables.
57Information may be retrieved and set from the command interface
58using the
59.Xr sysctl 8
60utility.
61.Pp
62Unless explicitly noted below,
63.Fn sysctl
64returns a consistent snapshot of the data requested.
65Consistency is obtained by locking the destination
66buffer into memory so that the data may be copied out without blocking.
67Calls to
68.Fn sysctl
69are serialized to avoid deadlock.
70.Pp
71The state is described using a ``Management Information Base'' (MIB)
72style name, listed in
73.Fa name ,
74which is a
75.Fa namelen
76length array of integers.
77.Pp
78The
79.Fn sysctlbyname
80function accepts an ASCII representation of the name and internally
81looks up the integer name vector.
82Apart from that, it behaves the same
83as the standard
84.Fn sysctl
85function.
86.Pp
87The information is copied into the buffer specified by
88.Fa oldp .
89The size of the buffer is given by the location specified by
90.Fa oldlenp
91before the call,
92and that location gives the amount of data copied after a successful call
93and after a call that returns with the error code
94.Er ENOMEM .
95If the amount of data available is greater
96than the size of the buffer supplied,
97the call supplies as much data as fits in the buffer provided
98and returns with the error code
99.Er ENOMEM .
100If the old value is not desired,
101.Fa oldp
102and
103.Fa oldlenp
104should be set to NULL.
105.Pp
106The size of the available data can be determined by calling
107.Fn sysctl
108with the
109.Dv NULL
110argument for
111.Fa oldp .
112The size of the available data will be returned in the location pointed to by
113.Fa oldlenp .
114For some operations, the amount of space may change often.
115For these operations,
116the system attempts to round up so that the returned size is
117large enough for a call to return the data shortly thereafter.
118.Pp
119To set a new value,
120.Fa newp
121is set to point to a buffer of length
122.Fa newlen
123from which the requested value is to be taken.
124If a new value is not to be set,
125.Fa newp
126should be set to NULL and
127.Fa newlen
128set to 0.
129.Pp
130The
131.Fn sysctlnametomib
132function accepts an ASCII representation of the name,
133looks up the integer name vector,
134and returns the numeric representation in the mib array pointed to by
135.Fa mibp .
136The number of elements in the mib array is given by the location specified by
137.Fa sizep
138before the call,
139and that location gives the number of entries copied after a successful call.
140The resulting
141.Fa mib
142and
143.Fa size
144may be used in subsequent
145.Fn sysctl
146calls to get the data associated with the requested ASCII name.
147This interface is intended for use by applications that want to
148repeatedly request the same variable (the
149.Fn sysctl
150function runs in about a third the time as the same request made via the
151.Fn sysctlbyname
152function).
153The
154.Fn sysctlnametomib
155function is also useful for fetching mib prefixes and then adding
156a final component.
157For example, to fetch process information
158for processes with pid's less than 100:
159.Pp
160.Bd -literal -offset indent -compact
161int i, mib[4];
162size_t len;
163struct kinfo_proc kp;
164
165/* Fill out the first three components of the mib */
166len = 4;
167sysctlnametomib("kern.proc.pid", mib, &len);
168
169/* Fetch and print entries for pid's < 100 */
170for (i = 0; i < 100; i++) {
171	mib[3] = i;
172	len = sizeof(kp);
173	if (sysctl(mib, 4, &kp, &len, NULL, 0) == -1)
174		perror("sysctl");
175	else if (len > 0)
176		printkproc(&kp);
177}
178.Ed
179.Pp
180The top level names are defined with a CTL_ prefix in
181.In sys/sysctl.h ,
182and are as follows.
183The next and subsequent levels down are found in the include files
184listed here, and described in separate sections below.
185.Bl -column CTLXMACHDEPXXX "Next Level NamesXXXXXX" -offset indent
186.It Sy Name Ta Sy Next Level Names Ta Sy Description
187.It Dv CTL_DEBUG Ta In sys/sysctl.h Ta Debugging
188.It Dv CTL_VFS Ta In sys/mount.h Ta File system
189.It Dv CTL_HW Ta In sys/sysctl.h Ta Generic CPU, I/O
190.It Dv CTL_KERN Ta In sys/sysctl.h Ta High kernel limits
191.It Dv CTL_MACHDEP Ta In sys/sysctl.h Ta Machine dependent
192.It Dv CTL_NET Ta In sys/socket.h Ta Networking
193.It Dv CTL_USER Ta In sys/sysctl.h Ta User-level
194.It Dv CTL_VM Ta In vm/vm_param.h Ta Virtual memory
195.El
196.Pp
197For example, the following retrieves the maximum number of processes allowed
198in the system:
199.Pp
200.Bd -literal -offset indent -compact
201int mib[2], maxproc;
202size_t len;
203
204mib[0] = CTL_KERN;
205mib[1] = KERN_MAXPROC;
206len = sizeof(maxproc);
207sysctl(mib, 2, &maxproc, &len, NULL, 0);
208.Ed
209.Pp
210To retrieve the standard search path for the system utilities:
211.Pp
212.Bd -literal -offset indent -compact
213int mib[2];
214size_t len;
215char *p;
216
217mib[0] = CTL_USER;
218mib[1] = USER_CS_PATH;
219sysctl(mib, 2, NULL, &len, NULL, 0);
220p = malloc(len);
221sysctl(mib, 2, p, &len, NULL, 0);
222.Ed
223.Ss CTL_DEBUG
224The debugging variables vary from system to system.
225A debugging variable may be added or deleted without need to recompile
226.Fn sysctl
227to know about it.
228Each time it runs,
229.Fn sysctl
230gets the list of debugging variables from the kernel and
231displays their current values.
232The system defines twenty
233.Pq Vt "struct ctldebug"
234variables named
235.Va debug0
236through
237.Va debug19 .
238They are declared as separate variables so that they can be
239individually initialized at the location of their associated variable.
240The loader prevents multiple use of the same variable by issuing errors
241if a variable is initialized in more than one place.
242For example, to export the variable
243.Va dospecialcheck
244as a debugging variable, the following declaration would be used:
245.Pp
246.Bd -literal -offset indent -compact
247int dospecialcheck = 1;
248struct ctldebug debug5 = { "dospecialcheck", &dospecialcheck };
249.Ed
250.Ss CTL_VFS
251A distinguished second level name, VFS_GENERIC,
252is used to get general information about all file systems.
253One of its third level identifiers is VFS_MAXTYPENUM
254that gives the highest valid file system type number.
255Its other third level identifier is VFS_CONF that
256returns configuration information about the file system
257type given as a fourth level identifier (see
258.Xr getvfsbyname 3
259as an example of its use).
260The remaining second level identifiers are the
261file system type number returned by a
262.Xr statfs 2
263call or from VFS_CONF.
264The third level identifiers available for each file system
265are given in the header file that defines the mount
266argument structure for that file system.
267.Ss CTL_HW
268The string and integer information available for the CTL_HW level
269is detailed below.
270The changeable column shows whether a process with appropriate
271privilege may change the value.
272.Bl -column "Second Level Name" integerXXX Changeable -offset indent
273.It Sy Second Level Name Ta Sy Type Ta Sy Changeable
274.It Dv HW_MACHINE Ta string Ta no
275.It Dv HW_MODEL Ta string Ta no
276.It Dv HW_NCPU Ta integer Ta no
277.It Dv HW_BYTEORDER Ta integer Ta no
278.It Dv HW_PHYSMEM Ta integer Ta no
279.It Dv HW_USERMEM Ta integer Ta no
280.It Dv HW_PAGESIZE Ta integer Ta no
281.\".It Dv HW_DISKNAMES Ta integer Ta no
282.\".It Dv HW_DISKSTATS Ta integer Ta no
283.It Dv HW_FLOATINGPT Ta integer Ta no
284.It Dv HW_MACHINE_ARCH Ta string Ta no
285.It Dv HW_REALMEM Ta integer Ta no
286.It Dv HW_AVAILPAGES Ta integer Ta no
287.El
288.Bl -tag -width 6n
289.It Li HW_MACHINE
290The machine class.
291.It Li HW_MODEL
292The machine model
293.It Li HW_NCPU
294The number of cpus.
295.It Li HW_BYTEORDER
296The byteorder (4321 or 1234).
297.It Li HW_PHYSMEM
298Amount of physical memory (in bytes), minus the amount used by the kernel,
299pre-loaded modules, and (on x86) the dcons buffer.
300.It Li HW_USERMEM
301Amount of memory (in bytes) which is not wired.
302.It Li HW_PAGESIZE
303The software page size.
304.\".It Fa HW_DISKNAMES
305.\".It Fa HW_DISKSTATS
306.It Li HW_FLOATINGPT
307Nonzero if the floating point support is in hardware.
308.It Li HW_MACHINE_ARCH
309The machine dependent architecture type.
310.It Li HW_REALMEM
311Amount of memory (in bytes) reported by the firmware.
312That value is sometimes not sane; in that case, the kernel reports the max
313memory address instead.
314.It Li HW_AVAILPAGES
315The same value as
316.Li HW_PHYSMEM ,
317measured in pages rather than bytes.
318.El
319.Ss CTL_KERN
320The string and integer information available for the CTL_KERN level
321is detailed below.
322The changeable column shows whether a process with appropriate
323privilege may change the value.
324The types of data currently available are process information,
325system vnodes, the open file entries, routing table entries,
326virtual memory statistics, load average history, and clock rate
327information.
328.Bl -column "KERNXMAXFILESPERPROCXXX" "struct clockrateXXX" -offset indent
329.It Sy Second Level Name Ta Sy Type Ta Sy Changeable
330.It Dv KERN_ARGMAX Ta integer Ta no
331.It Dv KERN_BOOTFILE Ta string Ta yes
332.It Dv KERN_BOOTTIME Ta struct timeval Ta no
333.It Dv KERN_CLOCKRATE Ta struct clockinfo Ta no
334.It Dv KERN_FILE Ta struct xfile Ta no
335.It Dv KERN_HOSTID Ta integer Ta yes
336.It Dv KERN_HOSTUUID Ta string Ta yes
337.It Dv KERN_HOSTNAME Ta string Ta yes
338.It Dv KERN_JOB_CONTROL Ta integer Ta no
339.It Dv KERN_MAXFILES Ta integer Ta yes
340.It Dv KERN_MAXFILESPERPROC Ta integer Ta yes
341.It Dv KERN_MAXPROC Ta integer Ta no
342.It Dv KERN_MAXPROCPERUID Ta integer Ta yes
343.It Dv KERN_MAXVNODES Ta integer Ta yes
344.It Dv KERN_NGROUPS Ta integer Ta no
345.It Dv KERN_NISDOMAINNAME Ta string Ta yes
346.It Dv KERN_OSRELDATE Ta integer Ta no
347.It Dv KERN_OSRELEASE Ta string Ta no
348.It Dv KERN_OSREV Ta integer Ta no
349.It Dv KERN_OSTYPE Ta string Ta no
350.It Dv KERN_POSIX1 Ta integer Ta no
351.It Dv KERN_PROC Ta node Ta not applicable
352.It Dv KERN_PROF Ta node Ta not applicable
353.It Dv KERN_QUANTUM Ta integer Ta yes
354.It Dv KERN_SAVED_IDS Ta integer Ta no
355.It Dv KERN_SECURELVL Ta integer Ta raise only
356.It Dv KERN_UPDATEINTERVAL Ta integer Ta no
357.It Dv KERN_VERSION Ta string Ta no
358.It Dv KERN_VNODE Ta struct xvnode Ta no
359.El
360.Bl -tag -width 6n
361.It Li KERN_ARGMAX
362The maximum bytes of argument to
363.Xr execve 2 .
364.It Li KERN_BOOTFILE
365The full pathname of the file from which the kernel was loaded.
366.It Li KERN_BOOTTIME
367A
368.Va struct timeval
369structure is returned.
370This structure contains the time that the system was booted.
371.It Li KERN_CLOCKRATE
372A
373.Va struct clockinfo
374structure is returned.
375This structure contains the clock, statistics clock and profiling clock
376frequencies, the number of micro-seconds per hz tick and the skew rate.
377.It Li KERN_FILE
378Return the entire file table.
379The returned data consists of an array of
380.Va struct xfile ,
381whose size depends on the current number of such objects in the system.
382.It Li KERN_HOSTID
383Get or set the host ID.
384.It Li KERN_HOSTUUID
385Get or set the host's universally unique identifier (UUID).
386.It Li KERN_HOSTNAME
387Get or set the hostname.
388.It Li KERN_JOB_CONTROL
389Return 1 if job control is available on this system, otherwise 0.
390.It Li KERN_MAXFILES
391The maximum number of files that may be open in the system.
392.It Li KERN_MAXFILESPERPROC
393The maximum number of files that may be open for a single process.
394This limit only applies to processes with an effective uid of nonzero
395at the time of the open request.
396Files that have already been opened are not affected if the limit
397or the effective uid is changed.
398.It Li KERN_MAXPROC
399The maximum number of concurrent processes the system will allow.
400.It Li KERN_MAXPROCPERUID
401The maximum number of concurrent processes the system will allow
402for a single effective uid.
403This limit only applies to processes with an effective uid of nonzero
404at the time of a fork request.
405Processes that have already been started are not affected if the limit
406is changed.
407.It Li KERN_MAXVNODES
408The maximum number of vnodes available on the system.
409.It Li KERN_NGROUPS
410The maximum number of supplemental groups.
411.It Li KERN_NISDOMAINNAME
412The name of the current YP/NIS domain.
413.It Li KERN_OSRELDATE
414The kernel release version in the format
415.Ar M Ns Ar mm Ns Ar R Ns Ar xx ,
416where
417.Ar M
418is the major version,
419.Ar mm
420is the two digit minor version,
421.Ar R
422is 0 if release branch, otherwise 1,
423and
424.Ar xx
425is updated when the available APIs change.
426.Pp
427The userland release version is available from
428.In osreldate.h ;
429parse this file if you need to get the release version of
430the currently installed userland.
431.It Li KERN_OSRELEASE
432The system release string.
433.It Li KERN_OSREV
434The system revision string.
435.It Li KERN_OSTYPE
436The system type string.
437.It Li KERN_POSIX1
438The version of
439.St -p1003.1
440with which the system
441attempts to comply.
442.It Li KERN_PROC
443Return selected information about specific running processes.
444.Pp
445For the following names, an array of
446.Va struct kinfo_proc
447structures is returned,
448whose size depends on the current number of such objects in the system.
449.Bl -column "Third Level NameXXXXXX" "Fourth LevelXXXXXX" -offset indent
450.It Sy Third Level Name Ta Sy Fourth Level
451.It Dv KERN_PROC_ALL Ta None
452.It Dv KERN_PROC_PID Ta A process ID
453.It Dv KERN_PROC_PGRP Ta A process group
454.It Dv KERN_PROC_TTY Ta A tty device
455.It Dv KERN_PROC_UID Ta A user ID
456.It Dv KERN_PROC_RUID Ta A real user ID
457.El
458.Pp
459If the third level name is
460.Dv KERN_PROC_ARGS
461then the command line argument
462array is returned in a flattened form, i.e., zero-terminated arguments
463follow each other.
464The total size of array is returned.
465It is also possible for a process to set its own process title this way.
466If the third level name is
467.Dv KERN_PROC_PATHNAME ,
468the path of the
469process' text file is stored.
470For
471.Dv KERN_PROC_PATHNAME ,
472a process ID of
473.Li \-1
474implies the current process.
475.Bl -column "Third Level NameXXXXXX" "Fourth LevelXXXXXX" -offset indent
476.It Sy Third Level Name Ta Sy Fourth Level
477.It Dv KERN_PROC_ARGS Ta "A process ID"
478.It Dv KERN_PROC_PATHNAME Ta "A process ID"
479.El
480.It Li KERN_PROF
481Return profiling information about the kernel.
482If the kernel is not compiled for profiling,
483attempts to retrieve any of the KERN_PROF values will
484fail with
485.Er ENOENT .
486The third level names for the string and integer profiling information
487is detailed below.
488The changeable column shows whether a process with appropriate
489privilege may change the value.
490.Bl -column "GPROFXGMONPARAMXXX" "struct gmonparamXXX" -offset indent
491.It Sy Third Level Name Ta Sy Type Ta Sy Changeable
492.It Dv GPROF_STATE Ta integer Ta yes
493.It Dv GPROF_COUNT Ta u_short[\|] Ta yes
494.It Dv GPROF_FROMS Ta u_short[\|] Ta yes
495.It Dv GPROF_TOS Ta struct tostruct Ta yes
496.It Dv GPROF_GMONPARAM Ta struct gmonparam Ta no
497.El
498.Pp
499The variables are as follows:
500.Bl -tag -width 6n
501.It Li GPROF_STATE
502Returns GMON_PROF_ON or GMON_PROF_OFF to show that profiling
503is running or stopped.
504.It Li GPROF_COUNT
505Array of statistical program counter counts.
506.It Li GPROF_FROMS
507Array indexed by program counter of call-from points.
508.It Li GPROF_TOS
509Array of
510.Va struct tostruct
511describing destination of calls and their counts.
512.It Li GPROF_GMONPARAM
513Structure giving the sizes of the above arrays.
514.El
515.It Li KERN_QUANTUM
516The maximum period of time, in microseconds, for which a process is allowed
517to run without being preempted if other processes are in the run queue.
518.It Li KERN_SAVED_IDS
519Returns 1 if saved set-group and saved set-user ID is available.
520.It Li KERN_SECURELVL
521The system security level.
522This level may be raised by processes with appropriate privilege.
523It may not be lowered.
524.It Li KERN_VERSION
525The system version string.
526.It Li KERN_VNODE
527Return the entire vnode table.
528Note, the vnode table is not necessarily a consistent snapshot of
529the system.
530The returned data consists of an array whose size depends on the
531current number of such objects in the system.
532Each element of the array consists of a
533.Va struct xvnode .
534.El
535.Ss CTL_NET
536The string and integer information available for the CTL_NET level
537is detailed below.
538The changeable column shows whether a process with appropriate
539privilege may change the value.
540.Bl -column "Second Level NameXXXXXX" "routing messagesXXX" -offset indent
541.It Sy Second Level Name Ta Sy Type Ta Sy Changeable
542.It Dv PF_ROUTE Ta routing messages Ta no
543.It Dv PF_INET Ta IPv4 values Ta yes
544.It Dv PF_INET6 Ta IPv6 values Ta yes
545.El
546.Bl -tag -width 6n
547.It Li PF_ROUTE
548Return the entire routing table or a subset of it.
549The data is returned as a sequence of routing messages (see
550.Xr route 4
551for the header file, format and meaning).
552The length of each message is contained in the message header.
553.Pp
554The third level name is a protocol number, which is currently always 0.
555The fourth level name is an address family, which may be set to 0 to
556select all address families.
557The fifth, sixth, and seventh level names are as follows:
558.Bl -column -offset indent "Fifth Level" "Sixth Level" "Seventh Level"
559.It Sy Fifth level Ta Sy Sixth Level Ta Sy Seventh Level
560.It Dv NET_RT_FLAGS Ta rtflags Ta None
561.It Dv NET_RT_DUMP Ta None Ta None or fib number
562.It Dv NET_RT_IFLIST Ta 0 or if_index Ta None
563.It Dv NET_RT_IFMALIST Ta 0 or if_index Ta None
564.It Dv NET_RT_IFLISTL Ta 0 or if_index Ta None
565.It Dv NET_RT_NHOPS Ta None Ta fib number
566.El
567.Pp
568The
569.Dv NET_RT_IFMALIST
570name returns information about multicast group memberships on all interfaces
571if 0 is specified, or for the interface specified by
572.Va if_index .
573.Pp
574The
575.Dv NET_RT_IFLISTL
576is like
577.Dv NET_RT_IFLIST ,
578just returning message header structs with additional fields allowing the
579interface to be extended without breaking binary compatibility.
580The
581.Dv NET_RT_IFLISTL
582uses 'l' versions of the message header structures:
583.Va struct if_msghdrl
584and
585.Va struct ifa_msghdrl .
586.Pp
587.Dv NET_RT_NHOPS
588returns all nexthops for specified address family in given fib.
589.It Li PF_INET
590Get or set various global information about the IPv4
591(Internet Protocol version 4).
592The third level name is the protocol.
593The fourth level name is the variable name.
594The currently defined protocols and names are:
595.Bl -column ProtocolXX VariableXX TypeXX ChangeableXX
596.It Sy Protocol Ta Sy Variable Ta Sy Type Ta Sy Changeable
597.It icmp Ta bmcastecho Ta integer Ta yes
598.It icmp Ta maskrepl Ta integer Ta yes
599.It ip Ta forwarding Ta integer Ta yes
600.It ip Ta redirect Ta integer Ta yes
601.It ip Ta ttl Ta integer Ta yes
602.It udp Ta checksum Ta integer Ta yes
603.El
604.Pp
605The variables are as follows:
606.Bl -tag -width 6n
607.It Li icmp.bmcastecho
608Returns 1 if an ICMP echo request to a broadcast or multicast address is
609to be answered.
610.It Li icmp.maskrepl
611Returns 1 if ICMP network mask requests are to be answered.
612.It Li ip.forwarding
613Returns 1 when IP forwarding is enabled for the host,
614meaning that the host is acting as a router.
615.It Li ip.redirect
616Returns 1 when ICMP redirects may be sent by the host.
617This option is ignored unless the host is routing IP packets,
618and should normally be enabled on all systems.
619.It Li ip.ttl
620The maximum time-to-live (hop count) value for an IP packet sourced by
621the system.
622This value applies to normal transport protocols, not to ICMP.
623.It Li udp.checksum
624Returns 1 when UDP checksums are being computed and checked.
625Disabling UDP checksums is strongly discouraged.
626.Pp
627For variables net.inet.*.ipsec, please refer to
628.Xr ipsec 4 .
629.El
630.It Li PF_INET6
631Get or set various global information about the IPv6
632(Internet Protocol version 6).
633The third level name is the protocol.
634The fourth level name is the variable name.
635.Pp
636For variables net.inet6.* please refer to
637.Xr inet6 4 .
638For variables net.inet6.*.ipsec6, please refer to
639.Xr ipsec 4 .
640.El
641.Ss CTL_USER
642The string and integer information available for the CTL_USER level
643is detailed below.
644The changeable column shows whether a process with appropriate
645privilege may change the value.
646.Bl -column "USER_COLL_WEIGHTS_MAXXXX" "integerXXX" -offset indent
647.It Sy Second Level Name Ta Sy Type Ta Sy Changeable
648.It Dv USER_BC_BASE_MAX Ta integer Ta no
649.It Dv USER_BC_DIM_MAX Ta integer Ta no
650.It Dv USER_BC_SCALE_MAX Ta integer Ta no
651.It Dv USER_BC_STRING_MAX Ta integer Ta no
652.It Dv USER_COLL_WEIGHTS_MAX Ta integer Ta no
653.It Dv USER_CS_PATH Ta string Ta no
654.It Dv USER_EXPR_NEST_MAX Ta integer Ta no
655.It Dv USER_LINE_MAX Ta integer Ta no
656.It Dv USER_LOCALBASE Ta string Ta no
657.It Dv USER_POSIX2_CHAR_TERM Ta integer Ta no
658.It Dv USER_POSIX2_C_BIND Ta integer Ta no
659.It Dv USER_POSIX2_C_DEV Ta integer Ta no
660.It Dv USER_POSIX2_FORT_DEV Ta integer Ta no
661.It Dv USER_POSIX2_FORT_RUN Ta integer Ta no
662.It Dv USER_POSIX2_LOCALEDEF Ta integer Ta no
663.It Dv USER_POSIX2_SW_DEV Ta integer Ta no
664.It Dv USER_POSIX2_UPE Ta integer Ta no
665.It Dv USER_POSIX2_VERSION Ta integer Ta no
666.It Dv USER_RE_DUP_MAX Ta integer Ta no
667.It Dv USER_STREAM_MAX Ta integer Ta no
668.It Dv USER_TZNAME_MAX Ta integer Ta no
669.El
670.Bl -tag -width 6n
671.It Li USER_BC_BASE_MAX
672The maximum ibase/obase values in the
673.Xr bc 1
674utility.
675.It Li USER_BC_DIM_MAX
676The maximum array size in the
677.Xr bc 1
678utility.
679.It Li USER_BC_SCALE_MAX
680The maximum scale value in the
681.Xr bc 1
682utility.
683.It Li USER_BC_STRING_MAX
684The maximum string length in the
685.Xr bc 1
686utility.
687.It Li USER_COLL_WEIGHTS_MAX
688The maximum number of weights that can be assigned to any entry of
689the LC_COLLATE order keyword in the locale definition file.
690.It Li USER_CS_PATH
691Return a value for the
692.Ev PATH
693environment variable that finds all the standard utilities.
694.It Li USER_EXPR_NEST_MAX
695The maximum number of expressions that can be nested within
696parenthesis by the
697.Xr expr 1
698utility.
699.It Li USER_LINE_MAX
700The maximum length in bytes of a text-processing utility's input
701line.
702.It Li USER_LOCALBASE
703Return the value of localbase that has been compiled into system utilities
704that need to have access to resources provided by a port or package.
705.It Li USER_POSIX2_CHAR_TERM
706Return 1 if the system supports at least one terminal type capable of
707all operations described in
708.St -p1003.2 ,
709otherwise 0.
710.It Li USER_POSIX2_C_BIND
711Return 1 if the system's C-language development facilities support the
712C-Language Bindings Option, otherwise 0.
713.It Li USER_POSIX2_C_DEV
714Return 1 if the system supports the C-Language Development Utilities Option,
715otherwise 0.
716.It Li USER_POSIX2_FORT_DEV
717Return 1 if the system supports the FORTRAN Development Utilities Option,
718otherwise 0.
719.It Li USER_POSIX2_FORT_RUN
720Return 1 if the system supports the FORTRAN Runtime Utilities Option,
721otherwise 0.
722.It Li USER_POSIX2_LOCALEDEF
723Return 1 if the system supports the creation of locales, otherwise 0.
724.It Li USER_POSIX2_SW_DEV
725Return 1 if the system supports the Software Development Utilities Option,
726otherwise 0.
727.It Li USER_POSIX2_UPE
728Return 1 if the system supports the User Portability Utilities Option,
729otherwise 0.
730.It Li USER_POSIX2_VERSION
731The version of
732.St -p1003.2
733with which the system attempts to comply.
734.It Li USER_RE_DUP_MAX
735The maximum number of repeated occurrences of a regular expression
736permitted when using interval notation.
737.It Li USER_STREAM_MAX
738The minimum maximum number of streams that a process may have open
739at any one time.
740.It Li USER_TZNAME_MAX
741The minimum maximum number of types supported for the name of a
742timezone.
743.El
744.Ss CTL_VM
745The string and integer information available for the CTL_VM level
746is detailed below.
747The changeable column shows whether a process with appropriate
748privilege may change the value.
749.Bl -column "Second Level NameXXXXXX" "struct loadavgXXX" -offset indent
750.It Sy Second Level Name Ta Sy Type Ta Sy Changeable
751.It Dv VM_LOADAVG Ta struct loadavg Ta no
752.It Dv VM_TOTAL Ta struct vmtotal Ta no
753.It Dv VM_SWAPPING_ENABLED Ta integer Ta maybe
754.It Dv VM_V_FREE_MIN Ta integer Ta yes
755.It Dv VM_V_FREE_RESERVED Ta integer Ta yes
756.It Dv VM_V_FREE_TARGET Ta integer Ta yes
757.It Dv VM_V_INACTIVE_TARGET Ta integer Ta yes
758.It Dv VM_V_PAGEOUT_FREE_MIN Ta integer Ta yes
759.It Dv VM_OVERCOMMIT Ta integer Ta yes
760.El
761.Bl -tag -width 6n
762.It Li VM_LOADAVG
763Return the load average history.
764The returned data consists of a
765.Va struct loadavg .
766.It Li VM_TOTAL
767Return the system wide virtual memory statistics.
768The returned data consists of a
769.Va struct vmtotal .
770.It Li VM_SWAPPING_ENABLED
7711 if process swapping is enabled or 0 if disabled.
772This variable is
773permanently set to 0 if the kernel was built with swapping disabled.
774.It Li VM_V_FREE_MIN
775Minimum amount of memory (cache memory plus free memory)
776required to be available before a process waiting on memory will be
777awakened.
778.It Li VM_V_FREE_RESERVED
779Processes will awaken the pageout daemon and wait for memory if the
780number of free and cached pages drops below this value.
781.It Li VM_V_FREE_TARGET
782The total amount of free memory (including cache memory) that the
783pageout daemon tries to maintain.
784.It Li VM_V_INACTIVE_TARGET
785The desired number of inactive pages that the pageout daemon should
786achieve when it runs.
787Inactive pages can be quickly inserted into
788process address space when needed.
789.It Li VM_V_PAGEOUT_FREE_MIN
790If the amount of free and cache memory falls below this value, the
791pageout daemon will enter "memory conserving mode" to avoid deadlock.
792.It Li VM_OVERCOMMIT
793Overcommit behaviour, as described in
794.Xr tuning 7 .
795.El
796.Sh RETURN VALUES
797.Rv -std
798.Sh FILES
799.Bl -tag -width <netinet/icmpXvar.h> -compact
800.It In sys/sysctl.h
801definitions for top level identifiers, second level kernel and hardware
802identifiers, and user level identifiers
803.It In sys/socket.h
804definitions for second level network identifiers
805.It In sys/gmon.h
806definitions for third level profiling identifiers
807.It In vm/vm_param.h
808definitions for second level virtual memory identifiers
809.It In netinet/in.h
810definitions for third level IPv4/IPv6 identifiers and
811fourth level IPv4/v6 identifiers
812.It In netinet/icmp_var.h
813definitions for fourth level ICMP identifiers
814.It In netinet/icmp6.h
815definitions for fourth level ICMPv6 identifiers
816.It In netinet/udp_var.h
817definitions for fourth level UDP identifiers
818.El
819.Sh ERRORS
820The following errors may be reported:
821.Bl -tag -width Er
822.It Bq Er EFAULT
823The buffer
824.Fa name ,
825.Fa oldp ,
826.Fa newp ,
827or length pointer
828.Fa oldlenp
829contains an invalid address.
830.It Bq Er EINVAL
831The
832.Fa name
833array is less than two or greater than CTL_MAXNAME.
834.It Bq Er EINVAL
835A non-null
836.Fa newp
837is given and its specified length in
838.Fa newlen
839is too large or too small.
840.It Bq Er ENOMEM
841The length pointed to by
842.Fa oldlenp
843is too short to hold the requested value.
844.It Bq Er ENOMEM
845The smaller of either the length pointed to by
846.Fa oldlenp
847or the estimated size of the returned data exceeds the
848system limit on locked memory.
849.It Bq Er ENOMEM
850Locking the buffer
851.Fa oldp ,
852or a portion of the buffer if the estimated size of the data
853to be returned is smaller,
854would cause the process to exceed its per-process locked memory limit.
855.It Bq Er ENOTDIR
856The
857.Fa name
858array specifies an intermediate rather than terminal name.
859.It Bq Er EISDIR
860The
861.Fa name
862array specifies a terminal name, but the actual name is not terminal.
863.It Bq Er ENOENT
864The
865.Fa name
866array specifies a value that is unknown.
867.It Bq Er EPERM
868An attempt is made to set a read-only value.
869.It Bq Er EPERM
870A process without appropriate privilege attempts to set a value.
871.El
872.Sh SEE ALSO
873.Xr confstr 3 ,
874.Xr kvm 3 ,
875.Xr sysconf 3 ,
876.Xr sysctl 8
877.Sh HISTORY
878The
879.Fn sysctl
880function first appeared in
881.Bx 4.4 .
882