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