xref: /netbsd-src/share/man/man9/sysctl.9 (revision 0996b25df120f7259f9a28950153238bbef06f93)
1*0996b25dSpgoyette.\"	$NetBSD: sysctl.9,v 1.24 2022/09/07 01:18:32 pgoyette Exp $
26024d1b5Satatat.\"
36024d1b5Satatat.\" Copyright (c) 2004 The NetBSD Foundation, Inc.
46024d1b5Satatat.\" All rights reserved.
56024d1b5Satatat.\"
66024d1b5Satatat.\" This code is derived from software contributed to The NetBSD Foundation
76024d1b5Satatat.\" by Andrew Brown.
86024d1b5Satatat.\"
96024d1b5Satatat.\" Redistribution and use in source and binary forms, with or without
106024d1b5Satatat.\" modification, are permitted provided that the following conditions
116024d1b5Satatat.\" are met:
126024d1b5Satatat.\" 1. Redistributions of source code must retain the above copyright
136024d1b5Satatat.\"    notice, this list of conditions and the following disclaimer.
146024d1b5Satatat.\" 2. Redistributions in binary form must reproduce the above copyright
156024d1b5Satatat.\"    notice, this list of conditions and the following disclaimer in the
166024d1b5Satatat.\"    documentation and/or other materials provided with the distribution.
176024d1b5Satatat.\"
186024d1b5Satatat.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
196024d1b5Satatat.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
206024d1b5Satatat.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
216024d1b5Satatat.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
226024d1b5Satatat.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
236024d1b5Satatat.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
246024d1b5Satatat.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
256024d1b5Satatat.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
266024d1b5Satatat.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
276024d1b5Satatat.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
286024d1b5Satatat.\" POSSIBILITY OF SUCH DAMAGE.
296024d1b5Satatat.\"
30*0996b25dSpgoyette.Dd September 6, 2022
316024d1b5Satatat.Dt SYSCTL 9
326024d1b5Satatat.Os
336024d1b5Satatat.Sh NAME
346024d1b5Satatat.Nm sysctl
356024d1b5Satatat.Nd system variable control interfaces
366024d1b5Satatat.Sh SYNOPSIS
376024d1b5Satatat.In sys/param.h
386024d1b5Satatat.In sys/sysctl.h
396024d1b5Satatat.Pp
406024d1b5SatatatPrimary external interfaces:
416024d1b5Satatat.Ft void
426024d1b5Satatat.Fn sysctl_init void
436024d1b5Satatat.Ft int
446024d1b5Satatat.Fn sysctl_lock "struct lwp *l" "void *oldp" "size_t savelen"
456024d1b5Satatat.Ft int
466024d1b5Satatat.Fn sysctl_dispatch "const int *name" "u_int namelen" "void *oldp" \
476024d1b5Satatat"size_t *oldlenp" "const void *newp" "size_t newlen" "const int *oname" \
486024d1b5Satatat"struct lwp *l" "const struct sysctlnode *rnode"
496024d1b5Satatat.Ft void
506024d1b5Satatat.Fn sysctl_unlock "struct lwp *l"
516024d1b5Satatat.Ft int
524723bb21Satatat.Fn sysctl_createv "struct sysctllog **log" "int cflags" \
53df13e357Satatat"const struct sysctlnode **rnode" "const struct sysctlnode **cnode" \
54df13e357Satatat"int flags" "int type" "const char *namep" "const char *desc" \
554723bb21Satatat"sysctlfn func" "u_quad_t qv" "void *newp" "size_t newlen" ...
566024d1b5Satatat.Ft int
576024d1b5Satatat.Fn sysctl_destroyv "struct sysctlnode *rnode" ...
586024d1b5Satatat.Ft void
596024d1b5Satatat.Fn sysctl_free "struct sysctlnode *rnode"
604723bb21Satatat.Ft void
614723bb21Satatat.Fn sysctl_teardown "struct sysctllog **"
626024d1b5Satatat.Ft int
636024d1b5Satatat.Fn old_sysctl "int *name" "u_int namelen" "void *oldp" \
646024d1b5Satatat"size_t *oldlenp" "void *newp" "size_t newlen" "struct lwp *l"
656024d1b5Satatat.Pp
666024d1b5SatatatCore internal functions:
676024d1b5Satatat.Ft int
686024d1b5Satatat.Fn sysctl_locate "struct lwp *l" "const int *name" "u_int namelen" \
69df13e357Satatat"const struct sysctlnode **rnode" "int *nip"
706024d1b5Satatat.Ft int
716024d1b5Satatat.Fn sysctl_lookup "const int *name" "u_int namelen" "void *oldp" \
726024d1b5Satatat"size_t *oldlenp" "const void *newp" "size_t newlen" "const int *oname" \
73df13e357Satatat"struct lwp *l" "const struct sysctlnode *rnode"
746024d1b5Satatat.Ft int
756024d1b5Satatat.Fn sysctl_create "const int *name" "u_int namelen" "void *oldp" \
766024d1b5Satatat"size_t *oldlenp" "const void *newp" "size_t newlen" "const int *oname" \
77df13e357Satatat"struct lwp *l" "const struct sysctlnode *rnode"
786024d1b5Satatat.Ft int
796024d1b5Satatat.Fn sysctl_destroy "const int *name" "u_int namelen" "void *oldp" \
806024d1b5Satatat"size_t *oldlenp" "const void *newp" "size_t newlen" "const int *oname" \
81df13e357Satatat"struct lwp *l" "const struct sysctlnode *rnode"
826024d1b5Satatat.Ft int
836024d1b5Satatat.Fn sysctl_query  "const int *name" "u_int namelen" "void *oldp" \
846024d1b5Satatat"size_t *oldlenp" "const void *newp" "size_t newlen" "const int *oname" \
856024d1b5Satatat"struct lwp *l" "const struct sysctlnode *rnode"
866024d1b5Satatat.Pp
876024d1b5SatatatSimple
886024d1b5Satatat.Dq helper
896024d1b5Satatatfunctions:
906024d1b5Satatat.Ft int
916024d1b5Satatat.Fn sysctl_needfunc "const int *name" "u_int namelen" "void *oldp" \
926024d1b5Satatat"size_t *oldlenp" "const void *newp" "size_t newlen" "const int *oname" \
936024d1b5Satatat"struct lwp *l" "const struct sysctlnode *rnode"
946024d1b5Satatat.Ft int
956024d1b5Satatat.Fn sysctl_notavail "const int *name" "u_int namelen" "void *oldp" \
966024d1b5Satatat"size_t *oldlenp" "const void *newp" "size_t newlen" "const int *oname" \
976024d1b5Satatat"struct lwp *l" "const struct sysctlnode *rnode"
986024d1b5Satatat.Ft int
996024d1b5Satatat.Fn sysctl_null "const int *name" "u_int namelen" "void *oldp" \
1006024d1b5Satatat"size_t *oldlenp" "const void *newp" "size_t newlen" "const int *oname" \
10136bb9495Salc"struct lwp *l" "const struct sysctlnode *rnode"
1026024d1b5Satatat.Sh DESCRIPTION
1036024d1b5SatatatThe SYSCTL subsystem instruments a number of kernel tunables and other
1046024d1b5Satatatdata structures via a simple MIB-like interface, primarily for
1056024d1b5Satatatconsumption by userland programs, but also for use internally by the
1066024d1b5Satatatkernel.
1076024d1b5Satatat.Sh LOCKING
1086024d1b5SatatatAll operations on the SYSCTL tree must be protected by acquiring the
1096024d1b5Satatatmain SYSCTL lock.
1106024d1b5SatatatThe only functions that can be called when the lock is not held are
1116024d1b5Satatat.Fn sysctl_lock ,
1126024d1b5Satatat.Fn sysctl_createv ,
1136024d1b5Satatat.Fn sysctl_destroyv ,
1146024d1b5Satatatand
1156024d1b5Satatat.Fn old_sysctl .
1166024d1b5SatatatAll other functions require the tree to be locked.
1176024d1b5SatatatThis is to prevent other users of the tree from moving nodes around
1186024d1b5Satatatduring an add operation, or from destroying nodes or subtrees that are
1196024d1b5Satatatactively being used.
1206024d1b5SatatatThe lock is acquired by calling
1216024d1b5Satatat.Fn sysctl_lock
1226024d1b5Satatatwith a pointer to the process's lwp
1236024d1b5Satatat.Fa l
1246024d1b5Satatat.Dv ( NULL
1256024d1b5Satatatmay be passed to all functions as the lwp pointer if no lwp is
1266024d1b5Satatatappropriate, though any changes made via
1276024d1b5Satatat.Fn sysctl_create ,
1286024d1b5Satatat.Fn sysctl_destroy ,
1296024d1b5Satatat.Fn sysctl_lookup ,
1306024d1b5Satatator by any helper function will be done with effective superuser
1316024d1b5Satatatprivileges).
132b8e30895Sjruoho.Pp
1336024d1b5SatatatThe
1346024d1b5Satatat.Fa oldp
1356024d1b5Satatatand
1366024d1b5Satatat.Fa savelen
1376024d1b5Satatatarguments are a pointer to and the size of the memory region the
1386024d1b5Satatatcaller will be using to collect data from SYSCTL.
1396024d1b5SatatatThese may also be
1406024d1b5Satatat.Dv NULL
1416024d1b5Satatatand 0, respectively.
1426024d1b5Satatat.Pp
1436024d1b5SatatatThe memory region will be locked via
1446024d1b5Satatat.Fn uvm_vslock
1456024d1b5Satatatif it is a region in userspace.
1466024d1b5SatatatThe address and size of the region are recorded so that when the
1476024d1b5SatatatSYSCTL lock is to be released via
1486024d1b5Satatat.Fn sysctl_unlock ,
1496024d1b5Satatatonly the lwp pointer
1506024d1b5Satatat.Fa l
1516024d1b5Satatatis required.
1526024d1b5Satatat.Sh LOOKUPS
1536024d1b5SatatatOnce the lock has been acquired, it is typical to call
1546024d1b5Satatat.Fn sysctl_dispatch
1556024d1b5Satatatto handle the request.
1566024d1b5Satatat.Fn sysctl_dispatch
1576024d1b5Satatatwill examine the contents of
1586024d1b5Satatat.Fa name ,
1596024d1b5Satatatan array of integers at least
1606024d1b5Satatat.Fa namelen
1616024d1b5Satatatlong, which is to be located in kernel space, in order to determine
1626024d1b5Satatatwhich function to call to handle the specific request.
1636024d1b5Satatat.Pp
164b8e30895SjruohoThe following algorithm is used by
1656024d1b5Satatat.Fn sysctl_dispatch
166b8e30895Sjruohoto determine the function to call:
167b8e30895Sjruoho.Bl -bullet -offset indent
1686024d1b5Satatat.It
1696024d1b5SatatatScan the tree using
170b8e30895Sjruoho.Fn sysctl_locate .
1716024d1b5Satatat.It
1726024d1b5SatatatIf the node returned has a
1736024d1b5Satatat.Dq helper
174b8e30895Sjruohofunction, call it.
1756024d1b5Satatat.It
1766024d1b5SatatatIf the requested node was found but has no function, call
177b8e30895Sjruoho.Fn sysctl_lookup .
1786024d1b5Satatat.It
1796024d1b5SatatatIf the node was not found and
1806024d1b5Satatat.Fa name
1816024d1b5Satatatspecifies one of
1826024d1b5Satatat.Fn sysctl_query ,
1836024d1b5Satatat.Fn sysctl_create ,
1846024d1b5Satatator
1856024d1b5Satatat.Fn sysctl_destroy ,
186b8e30895Sjruohocall the appropriate function.
1876024d1b5Satatat.It
1886024d1b5SatatatIf none of these options applies and no other error was yet recorded,
1896024d1b5Satatatreturn
190b8e30895Sjruoho.Er EOPNOTSUPP .
1916024d1b5Satatat.El
1926024d1b5SatatatThe
1936024d1b5Satatat.Fa oldp
1946024d1b5Satatatand
1956024d1b5Satatat.Fa oldlenp
1966024d1b5Satatatarguments to
1976024d1b5Satatat.Fn sysctl_dispatch ,
1986024d1b5Satatatas with all the other core functions, describe an area into which the
1996024d1b5Satatatcurrent or requested value may be copied.
2006024d1b5Satatat.Fa oldp
2016024d1b5Satatatmay or may not be a pointer into userspace (as dictated by whether
2026024d1b5Satatat.Fa l
2036024d1b5Satatatis
2046024d1b5Satatat.Dv NULL
2056024d1b5Satatator not).
2066024d1b5Satatat.Fa oldlenp
2076024d1b5Satatatis a
2086024d1b5Satatat.No non- Ns Dv NULL
2096024d1b5Satatatpointer to a size_t.
2106024d1b5Satatat.Fa newp
2116024d1b5Satatatand
2126024d1b5Satatat.Fa newlen
2136024d1b5Satatatdescribe an area where the new value for the request may be found;
2146024d1b5Satatat.Fa newp
2156024d1b5Satatatmay also be a pointer into userspace.
2166024d1b5SatatatThe
2176024d1b5Satatat.Fa oname
2186024d1b5Satatatargument is a
2196024d1b5Satatat.No non- Ns Dv NULL
2206024d1b5Satatatpointer to the base of the request currently
2216024d1b5Satatatbeing processed.
2226024d1b5SatatatBy simple arithmetic on
2236024d1b5Satatat.Fa name ,
2246024d1b5Satatat.Fa namelen ,
2256024d1b5Satatatand
2266024d1b5Satatat.Fa oname ,
2276024d1b5Satatatone can easily determine the entire original request and
2286024d1b5Satatat.Fa namelen
2296024d1b5Satatatvalues, if needed.
2306024d1b5SatatatThe
2316024d1b5Satatat.Fa rnode
2326024d1b5Satatatvalue, as passed to
2336024d1b5Satatat.Fn sysctl_dispatch
2346024d1b5Satatatrepresents the root of the tree into which the current request is to
2356024d1b5Satatatbe dispatched.
2366024d1b5SatatatIf
2376024d1b5Satatat.Dv NULL ,
2386024d1b5Satatatthe main tree will be used.
2396024d1b5Satatat.Pp
240b8e30895SjruohoThe
2416024d1b5Satatat.Fn sysctl_locate
242b8e30895Sjruohofunction scans a tree for the node most specific to a request.
2436024d1b5SatatatIf the pointer referenced by
2446024d1b5Satatat.Fa rnode
2456024d1b5Satatatis not
2466024d1b5Satatat.Dv NULL ,
2476024d1b5Satatatthe tree indicated is searched, otherwise the main tree
2486024d1b5Satatatwill be used.
2496024d1b5SatatatThe address of the most relevant node will be returned via
2506024d1b5Satatat.Fa rnode
2516024d1b5Satatatand the number of MIB entries consumed will be returned via
2526024d1b5Satatat.Fa nip ,
2536024d1b5Satatatif it is not
2546024d1b5Satatat.Dv NULL .
2556024d1b5Satatat.Pp
2566024d1b5SatatatThe
2576024d1b5Satatat.Fn sysctl_lookup
2586024d1b5Satatatfunction takes the same arguments as
2596024d1b5Satatat.Fn sysctl_dispatch
2606024d1b5Satatatwith the caveat that the value for
2616024d1b5Satatat.Fa namelen
2626024d1b5Satatatmust be zero in order to indicate that the node referenced by the
2636024d1b5Satatat.Fa rnode
2646024d1b5Satatatargument is the one to which the lookup is being applied.
2656024d1b5Satatat.Sh CREATION AND DESTRUCTION OF NODES
2666024d1b5SatatatNew nodes are created and destroyed by the
2676024d1b5Satatat.Fn sysctl_create
2686024d1b5Satatatand
2696024d1b5Satatat.Fn sysctl_destroy
2706024d1b5Satatatfunctions.
2716024d1b5SatatatThese functions take the same arguments as
2726024d1b5Satatat.Fn sysctl_dispatch
2736024d1b5Satatatwith the additional requirement that the
2746024d1b5Satatat.Fa namelen
2756024d1b5Satatatargument must be 1 and the
2766024d1b5Satatat.Fa name
2776024d1b5Satatatargument must point to an integer valued either
2786024d1b5Satatat.Dv CTL_CREATE
2796024d1b5Satatator
2806024d1b5Satatat.Dv CTL_CREATESYM
2816024d1b5Satatatwhen creating a new node, or
2826024d1b5Satatat.Dv CTL_DESTROY
2836024d1b5Satatatwhen destroying
2846024d1b5Satatata node.
285b8e30895Sjruoho.Pp
2866024d1b5SatatatThe
2876024d1b5Satatat.Fa newp
2886024d1b5Satatatand
2896024d1b5Satatat.Fa newlen
2906024d1b5Satatatarguments should point to a copy of the node to be created or
2916024d1b5Satatatdestroyed.
2926024d1b5SatatatIf the create or destroy operation was successful, a copy of the node
2936024d1b5Satatatcreated or destroyed will be placed in the space indicated by
2946024d1b5Satatat.Fa oldp
2956024d1b5Satatatand
2966024d1b5Satatat.Fa oldlenp .
2976024d1b5SatatatIf the create operation fails because of a conflict with an existing
2986024d1b5Satatatnode, a copy of that node will be returned instead.
2996024d1b5Satatat.Pp
3006024d1b5SatatatIn order to facilitate the creation and destruction of nodes from a
3016024d1b5Satatatgiven tree by kernel subsystems, the functions
3026024d1b5Satatat.Fn sysctl_createv
3036024d1b5Satatatand
3046024d1b5Satatat.Fn sysctl_destroyv
3056024d1b5Satatatare provided.
3066024d1b5SatatatThese functions take care of the overhead of filling in the contents
3076024d1b5Satatatof the create or destroy request, dealing with locking, locating the
3086024d1b5Satatatappropriate parent node, etc.
3096024d1b5Satatat.Pp
3106024d1b5SatatatThe arguments to
3116024d1b5Satatat.Fn sysctl_createv
3126024d1b5Satatatare used to construct the new node.
3134723bb21SatatatIf the
3144723bb21Satatat.Fa log
3154723bb21Satatatargument is not
3164723bb21Satatat.Dv NULL ,
317b8e30895Sjruohoa
318b8e30895Sjruoho.Em sysctllog
319b8e30895Sjruohostructure will be allocated and the pointer referenced
3204723bb21Satatatwill be changed to address it.
3214723bb21SatatatThe same log may be used for any number of nodes, provided they are
3224723bb21Satatatall inserted into the same tree.
3234723bb21SatatatThis allows for a series of nodes to be created and later removed from
3244723bb21Satatatthe tree in a single transaction (via
3254723bb21Satatat.Fn sysctl_teardown )
3264723bb21Satatatwithout the need for any record
3274723bb21Satatatkeeping on the caller's part.
328b8e30895Sjruoho.Pp
3294723bb21SatatatThe
3304723bb21Satatat.Fa cflags
3314723bb21Satatatargument is currently unused and must be zero.
3324723bb21SatatatThe
3334723bb21Satatat.Fa rnode
3344723bb21Satatatargument must either be
3354723bb21Satatat.Dv NULL
336d811bd02Swizor a valid pointer to a reference to the root of the tree into which
3374723bb21Satatatthe new node must be placed.
3384723bb21SatatatIf it is
3394723bb21Satatat.Dv NULL ,
3404723bb21Satatatthe main tree will be used.
341d811bd02SwizIt is illegal for
3424723bb21Satatat.Fa rnode
343d811bd02Swizto refer to a
3444723bb21Satatat.Dv NULL
3454723bb21Satatatpointer.
346d811bd02SwizIf the
3474723bb21Satatat.Fa cnode
348d811bd02Swizargument is not
3494723bb21Satatat.Dv NULL ,
3504723bb21Satataton return it will be adjusted to point to the address of the new node.
3514723bb21Satatat.Pp
3526024d1b5SatatatThe
3536024d1b5Satatat.Fa flags
3546024d1b5Satatatand
3556024d1b5Satatat.Fa type
3566024d1b5Satatatarguments are combined into the
3576024d1b5Satatat.Fa sysctl_flags
3584723bb21Satatatfield, and the current value for
3594723bb21Satatat.Dv SYSCTL_VERSION
3604723bb21Satatatis added in.
361b8e30895SjruohoThe following types are defined:
362b8e30895Sjruoho.Bl -tag -width ".Dv CTLTYPE_STRING    " -offset indent
363b8e30895Sjruoho.It Dv CTLTYPE_NODE
364b8e30895SjruohoA node intended to be a parent for other nodes.
365b8e30895Sjruoho.It Dv CTLTYPE_INT
366b8e30895SjruohoA signed integer.
367b8e30895Sjruoho.It Dv CTLTYPE_STRING
368b8e30895SjruohoA NUL-terminated string.
369b8e30895Sjruoho.It Dv CTLTYPE_QUAD
370b8e30895SjruohoAn unsigned 64-bit integer.
371b8e30895Sjruoho.It Dv CTLTYPE_STRUCT
372b8e30895SjruohoA structure.
373b8e30895Sjruoho.It Dv CTLTYPE_BOOL
374b8e30895SjruohoA boolean.
375b8e30895Sjruoho.El
376b8e30895Sjruoho.Pp
3776024d1b5SatatatThe
3786024d1b5Satatat.Fa namep
3796024d1b5Satatatargument is copied into the
3806024d1b5Satatat.Fa sysctl_name
3816024d1b5Satatatfield and must be less than
3826024d1b5Satatat.Dv SYSCTL_NAMELEN
3836024d1b5Satatatcharacters in length.
3844723bb21SatatatThe string indicated by
3854723bb21Satatat.Fa desc
3864723bb21Satatatwill be copied if the
3874723bb21Satatat.Dv CTLFLAG_OWNDESC
3884723bb21Satatatflag is set, and will be used as the node's description.
389b8e30895Sjruoho.Pp
390b8e30895SjruohoTwo additional remarks:
391b8e30895Sjruoho.Bl -enum -offset indent
392b8e30895Sjruoho.It
393b8e30895SjruohoThe
394b8e30895Sjruoho.Dv CTLFLAG_PERMANENT
395b8e30895Sjruohoflag can only be set from SYSCTL setup routines (see
396b8e30895Sjruoho.Sx SETUP FUNCTIONS )
397b8e30895Sjruohoas called by
398b8e30895Sjruoho.Fn sysctl_init .
399b8e30895Sjruoho.It
400b8e30895SjruohoIf
4014723bb21Satatat.Fn sysctl_destroyv
4024723bb21Satatatattempts to delete a node that does not own its own description (and
4034723bb21Satatatis not marked as permanent), but the deletion fails, the description
4044723bb21Satatatwill be copied and
4054723bb21Satatat.Fn sysctl_destroyv
4064723bb21Satatatwill set the
4074723bb21Satatat.Dv CTLFLAG_OWNDESC
4084723bb21Satatatflag.
409b8e30895Sjruoho.El
4104723bb21Satatat.Pp
4116024d1b5SatatatThe
4126024d1b5Satatat.Fa func
4136024d1b5Satatatargument is the name of a
4146024d1b5Satatat.Dq helper
4156024d1b5Satatatfunction (see
4166024d1b5Satatat.Sx HELPER FUNCTIONS AND MACROS ) .
4176024d1b5SatatatIf the
4184723bb21Satatat.Dv CTLFLAG_IMMEDIATE
4196024d1b5Satatatflag is set, the
4206024d1b5Satatat.Fa qv
4216024d1b5Satatatargument will be interpreted as the initial value for the new
422d96481c6Sjym.Dq bool ,
4236024d1b5Satatat.Dq int
4246024d1b5Satatator
4256024d1b5Satatat.Dq quad
4266024d1b5Satatatnode.
4276024d1b5SatatatThis flag does not apply to any other type of node.
4286024d1b5SatatatThe
4296024d1b5Satatat.Fa newp
4306024d1b5Satatatand
4316024d1b5Satatat.Fa newlen
4326024d1b5Satatatarguments describe the data external to SYSCTL that is to be
4336024d1b5Satatatinstrumented.
4346024d1b5SatatatOne of
4356024d1b5Satatat.Fa func ,
4366024d1b5Satatat.Fa qv
4376024d1b5Satatatand the
4384723bb21Satatat.Dv CTLFLAG_IMMEDIATE
4396024d1b5Satatatflag, or
4406024d1b5Satatat.Fa newp
4416024d1b5Satatatand
4426024d1b5Satatat.Fa newlen
4436024d1b5Satatatmust be given for nodes that instrument data, otherwise an error is
4446024d1b5Satatatreturned.
4456024d1b5Satatat.Pp
4466024d1b5SatatatThe remaining arguments are a list of integers specifying the path
4476024d1b5Satatatthrough the MIB to the node being created.
4486024d1b5SatatatThe list must be terminated by the
4496024d1b5Satatat.Dv CTL_EOL
4506024d1b5Satatatvalue.
4516024d1b5SatatatThe penultimate value in the list may be
4526024d1b5Satatat.Dv CTL_CREATE
4536024d1b5Satatatif a dynamic MIB entry is to be made for this node.
4546024d1b5Satatat.Fn sysctl_createv
4556024d1b5Satatatspecifically does not support
4566024d1b5Satatat.Dv CTL_CREATESYM ,
4576024d1b5Satatatsince setup routines are
4586024d1b5Satatatexpected to be able to use the in-kernel
4596024d1b5Satatat.Xr ksyms 4
4606024d1b5Satatatinterface to discover the location of the data to be instrumented.
4616024d1b5SatatatIf the node to be created matches a node that already exists, a return
4626024d1b5Satatatcode of 0 is given, indicating success.
4636024d1b5Satatat.Pp
4646024d1b5SatatatWhen using
4656024d1b5Satatat.Fn sysctl_destroyv
4666024d1b5Satatatto destroy a given node, the
4676024d1b5Satatat.Fa rnode
4686024d1b5Satatatargument, if not
4696024d1b5Satatat.Dv NULL ,
4706024d1b5Satatatis taken to be the root of the tree from which
4716024d1b5Satatatthe node is to be destroyed, otherwise the main tree is used.
4726024d1b5SatatatThe rest of the arguments are a list of integers specifying the path
4736024d1b5Satatatthrough the MIB to the node being destroyed.
4746024d1b5SatatatIf the node being destroyed does not exist, a successful return code
4756024d1b5Satatatis given.
4766024d1b5SatatatNodes marked with the
4774723bb21Satatat.Dv CTLFLAG_PERMANENT
4786024d1b5Satatatflag cannot be destroyed.
4796024d1b5Satatat.Sh HELPER FUNCTIONS AND MACROS
4806024d1b5SatatatHelper functions are invoked with the same common argument set as
4816024d1b5Satatat.Fn sysctl_dispatch
4826024d1b5Satatatexcept that the
4836024d1b5Satatat.Fa rnode
4846024d1b5Satatatargument will never be
4856024d1b5Satatat.Dv NULL .
4866024d1b5SatatatIt will be set to point to the node that corresponds most closely to
4876024d1b5Satatatthe current request.
4886024d1b5SatatatHelpers are forbidden from modifying the node they are passed; they
4896024d1b5Satatatshould instead copy the structure if changes are required in order to
4906024d1b5Satatateffect access control or other checks.
4916024d1b5SatatatThe
4926024d1b5Satatat.Dq helper
4936024d1b5Satatatprototype and function that needs to ensure that a newly assigned
4946024d1b5Satatatvalue is within a certain range (presuming external data) would look
4956024d1b5Satatatlike the following:
4966024d1b5Satatat.Pp
4976024d1b5Satatat.Bd -literal -offset indent -compact
4986024d1b5Satatatstatic int sysctl_helper(SYSCTLFN_PROTO);
4996e936e04Sjoerg
5006024d1b5Satatatstatic int
5016024d1b5Satatatsysctl_helper(SYSCTLFN_ARGS)
5026024d1b5Satatat{
5036024d1b5Satatat	struct sysctlnode node;
5046024d1b5Satatat	int t, error;
5056e936e04Sjoerg
50601869ca4Swiz	t = *(int *)rnode->sysctl_data;
507d96481c6Sjym
5086024d1b5Satatat	node = *rnode;
50901869ca4Swiz	node.sysctl_data = &t;
51001869ca4Swiz	error = sysctl_lookup(SYSCTLFN_CALL(&node));
5116024d1b5Satatat	if (error || newp == NULL)
5126024d1b5Satatat		return (error);
5136e936e04Sjoerg
51401869ca4Swiz	if (t < 0 || t > 20)
5156024d1b5Satatat		return (EINVAL);
5166e936e04Sjoerg
51701869ca4Swiz	*(int *)rnode->sysctl_data = t;
5186024d1b5Satatat	return (0);
5196024d1b5Satatat}
5206024d1b5Satatat.Ed
5216024d1b5Satatat.Pp
5226024d1b5SatatatThe use of the
5236024d1b5Satatat.Dv SYSCTLFN_PROTO ,
5246024d1b5Satatat.Dv SYSCTLFN_ARGS, and
5256024d1b5Satatat.Dv SYSCTLFN_CALL
5266024d1b5Satatat macros ensure that all arguments are passed properly.
5276024d1b5SatatatThe single argument to the
5286024d1b5Satatat.Dv SYSCTLFN_CALL
5296024d1b5Satatatmacro is the pointer to the node being examined.
5306024d1b5Satatat.Pp
5316024d1b5SatatatThree basic helper functions are available for use.
5326024d1b5Satatat.Fn sysctl_needfunc
5336024d1b5Satatatwill emit a warning to the system console whenever it is invoked and
5346024d1b5Satatatprovides a simplistic read-only interface to the given node.
5356024d1b5Satatat.Fn sysctl_notavail
5366024d1b5Satatatwill forward
5376024d1b5Satatat.Dq queries
5386024d1b5Satatatto
5396024d1b5Satatat.Fn sysctl_query
5406024d1b5Satatatso that subtrees can be discovered, but will return
5416024d1b5Satatat.Er EOPNOTSUPP
5426024d1b5Satatatfor any other condition.
5436024d1b5Satatat.Fn sysctl_null
5446024d1b5Satatatspecifically ignores any arguments given, sets the value indicated by
5456024d1b5Satatat.Fa oldlenp
5466024d1b5Satatatto zero, and returns success.
5476024d1b5Satatat.Sh SETUP FUNCTIONS
5489ca5a508SpgoyetteAlthough nodes can be added to the SYSCTL tree at any time, in order to
549*0996b25dSpgoyetteadd nodes during the kernel bootstrap phase (and during loadable module
550*0996b25dSpgoyetteinitialization), a proper
5516024d1b5Satatat.Dq setup
5526024d1b5Satatatfunction must be used.
5536024d1b5SatatatSetup functions are declared using the
5546024d1b5Satatat.Dv SYSCTL_SETUP
5556024d1b5Satatatmacro, which takes the name of the function and a short string
5566024d1b5Satatatdescription of the function as arguments.
5573cb285acSreed.Po
5583cb285acSreedSee the
5593cb285acSreed.Dv SYSCTL_DEBUG_SETUP
5603cb285acSreedkernel configuration in
5613cb285acSreed.Xr options 4 .
5623cb285acSreed.Pc
5639ca5a508Spgoyette.Pp
5646024d1b5SatatatThe address of the function is added to a list of functions that
5656024d1b5Satatat.Fn sysctl_init
5666024d1b5Satatattraverses during initialization.
5679ca5a508SpgoyetteFor loadable kernel modules (see
568d9c1d28aSwiz.Xr module 9 ) ,
569*0996b25dSpgoyettethe list of functions is called from the module loader before the module's
5709ca5a508Spgoyetteinitialization routine.
5719ca5a508SpgoyetteAny sysctl nodes created for the loadable module are removed using
5729ca5a508Spgoyette.Fn sysctl_teardown
573*0996b25dSpgoyetteafter calling the module's termination code.
5746024d1b5Satatat.Pp
5758c7664bbSrumbleSetup functions do not have to add nodes to the main tree, but can set
5766024d1b5Satatatup their own trees for emulation or other purposes.
5776024d1b5SatatatEmulations that require use of a main tree but with some nodes changed
5786024d1b5Satatatto suit their own purposes can arrange to overlay a sparse private
5796024d1b5Satatattree onto their main tree by making the
5806024d1b5Satatat.Fa e_sysctlovly
5816024d1b5Satatatmember of their struct emul definition point to the overlaid tree.
5826024d1b5Satatat.Pp
5836024d1b5SatatatSetup functions should take care to create all nodes from the root
5846024d1b5Satatatdown to the subtree they are creating, since the order in which setup
5856024d1b5Satatatfunctions are called is arbitrary (the order in which setup functions
5866024d1b5Satatatare called is only determined by the ordering of the object files as
5876024d1b5Satatatpassed to the linker when the kernel is built).
5886024d1b5Satatat.Sh MISCELLANEOUS FUNCTIONS
5896024d1b5Satatat.Fn sysctl_init
5906024d1b5Satatatis called early in the kernel bootstrap process.
5916024d1b5SatatatIt initializes the SYSCTL lock, calls all the registered setup
5926024d1b5Satatatfunctions, and marks the tree as permanent.
5936024d1b5Satatat.Pp
5946024d1b5Satatat.Fn sysctl_free
5956024d1b5Satatatwill unconditionally delete any and all nodes below the given node.
5966024d1b5SatatatIts intended use is for the deletion of entire trees, not subtrees.
5976024d1b5SatatatIf a subtree is to be removed,
5986024d1b5Satatat.Fn sysctl_destroy
5996024d1b5Satatator
6006024d1b5Satatat.Fn sysctl_destroyv
6016024d1b5Satatatshould be used to ensure that nodes not owned by the sub-system being
6026024d1b5Satatatdeactivated are not mistakenly destroyed.
6036024d1b5SatatatThe SYSCTL lock must be held when calling this function.
6046024d1b5Satatat.Pp
6054723bb21Satatat.Fn sysctl_teardown
606b8e30895Sjruohounwinds a
607b8e30895Sjruoho.Em sysctllog
608b8e30895Sjruohoand deletes the nodes in the opposite order in
6094723bb21Satatatwhich they were created.
6104723bb21Satatat.Pp
6116024d1b5Satatat.Fn old_sysctl
6126024d1b5Satatatprovides an interface similar to the old SYSCTL implementation, with
6136024d1b5Satatatthe exception that access checks on a per-node basis are performed if
6146024d1b5Satatatthe
6156024d1b5Satatat.Fa l
6166024d1b5Satatatargument is
6176024d1b5Satatat.No non- Ns Dv NULL .
6186024d1b5SatatatIf called with a
6196024d1b5Satatat.Dv NULL
6206024d1b5Satatatargument, the values for
6216024d1b5Satatat.Fa newp
6226024d1b5Satatatand
6236024d1b5Satatat.Fa oldp
6246024d1b5Satatatare interpreted as kernel addresses, and access is performed as for
6256024d1b5Satatatthe superuser.
6264dc3500dSjruoho.Sh NOTES
6276024d1b5SatatatIt is expected that nodes will be added to (or removed from) the tree
6286024d1b5Satatatduring the following stages of a machine's lifetime:
6296024d1b5Satatat.Pp
6306024d1b5Satatat.Bl -bullet -compact
6316024d1b5Satatat.It
63288f86411Sriastradhinitialization \(em when the kernel is booting
6336024d1b5Satatat.It
63488f86411Sriastradhautoconfiguration \(em when devices are being probed at boot time
6356024d1b5Satatat.It
6366024d1b5Satatat.Dq plug and play
63788f86411Sriastradhdevice attachment \(em when a PC-Card, USB, or other device is plugged
6386024d1b5Satatatin or attached
6396024d1b5Satatat.It
64088f86411Sriastradhmodule initialization \(em when a module is being loaded
6416024d1b5Satatat.It
6426024d1b5Satatat.Dq run-time
64388f86411Sriastradh\(em when a process creates a node via the
6446024d1b5Satatat.Xr sysctl 3
6456024d1b5Satatatinterface
6466024d1b5Satatat.El
6476024d1b5Satatat.Pp
6486024d1b5SatatatNodes marked with
6494723bb21Satatat.Dv CTLFLAG_PERMANENT
6506024d1b5Satatatcan only be added to a tree during the first or initialization phase,
6516024d1b5Satatatand can never be removed.
6526024d1b5SatatatThe initialization phase terminates when the main tree's root is
6536024d1b5Satatatmarked with the
6544723bb21Satatat.Dv CTLFLAG_PERMANENT
6556024d1b5Satatatflag.
6566024d1b5SatatatOnce the main tree is marked in this manner, no nodes can be added to
6576024d1b5Satatatany tree that is marked with
6584723bb21Satatat.Dv CTLFLAG_READONLY
6596024d1b5Satatatat its root, and no nodes can be added at all if the main tree's root
6606024d1b5Satatatis so marked.
6616024d1b5Satatat.Pp
6620efea177SadNodes added by device drivers, modules, and at device insertion time can
6636024d1b5Satatatbe added to (and removed from)
6646024d1b5Satatat.Dq read-only
6656024d1b5Satatatparent nodes.
6666024d1b5Satatat.Pp
6676024d1b5SatatatNodes created by processes can only be added to
668528c020eSwiz.Dq writable
6696024d1b5Satatatparent nodes.
6706024d1b5SatatatSee
6716024d1b5Satatat.Xr sysctl 3
6726024d1b5Satatatfor a description of the flags that are allowed to be used by
6736024d1b5Satatatwhen creating nodes.
6746024d1b5Satatat.Sh SEE ALSO
6756024d1b5Satatat.Xr sysctl 3
6766024d1b5Satatat.Sh HISTORY
6776024d1b5SatatatThe dynamic SYSCTL implementation first appeared in
6786024d1b5Satatat.Nx 2.0 .
6796024d1b5Satatat.Sh AUTHORS
6806024d1b5Satatat.An Andrew Brown
6816024d1b5Satatat.Aq atatat@NetBSD.org
6826024d1b5Satatatdesigned and implemented the dynamic SYSCTL implementation.
683