1dba9e9ccSRobert Watson.\" 2dba9e9ccSRobert Watson.\" Copyright (c) 2006 Robert N. M. Watson 3dba9e9ccSRobert Watson.\" All rights reserved. 4dba9e9ccSRobert Watson.\" 5dba9e9ccSRobert Watson.\" Redistribution and use in source and binary forms, with or without 6dba9e9ccSRobert Watson.\" modification, are permitted provided that the following conditions 7dba9e9ccSRobert Watson.\" are met: 8dba9e9ccSRobert Watson.\" 1. Redistributions of source code must retain the above copyright 9dba9e9ccSRobert Watson.\" notice, this list of conditions and the following disclaimer. 10dba9e9ccSRobert Watson.\" 2. Redistributions in binary form must reproduce the above copyright 11dba9e9ccSRobert Watson.\" notice, this list of conditions and the following disclaimer in the 12dba9e9ccSRobert Watson.\" documentation and/or other materials provided with the distribution. 13dba9e9ccSRobert Watson.\" 14dba9e9ccSRobert Watson.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15dba9e9ccSRobert Watson.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16dba9e9ccSRobert Watson.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17dba9e9ccSRobert Watson.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18dba9e9ccSRobert Watson.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19dba9e9ccSRobert Watson.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20dba9e9ccSRobert Watson.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21dba9e9ccSRobert Watson.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22dba9e9ccSRobert Watson.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23dba9e9ccSRobert Watson.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24dba9e9ccSRobert Watson.\" SUCH DAMAGE. 25dba9e9ccSRobert Watson.\" 26dba9e9ccSRobert Watson.\" $FreeBSD$ 27dba9e9ccSRobert Watson.\" 28*df94ce0fSJohn-Mark Gurney.Dd September 1, 2020 29dba9e9ccSRobert Watson.Dt SYSCTL 9 30dba9e9ccSRobert Watson.Os 31dba9e9ccSRobert Watson.Sh NAME 32dba9e9ccSRobert Watson.Nm SYSCTL_DECL , 339a593520SMateusz Piotrowski.Nm SYSCTL_ADD_BOOL , 349a593520SMateusz Piotrowski.Nm SYSCTL_ADD_COUNTER_U64 , 359a593520SMateusz Piotrowski.Nm SYSCTL_ADD_COUNTER_U64_ARRAY , 365eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_INT , 375eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_LONG , 385eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_NODE , 391e1f3941SEd Schouten.Nm SYSCTL_ADD_NODE_WITH_LABEL , 405eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_OPAQUE , 415eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_PROC , 425eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_QUAD , 435eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_ROOT_NODE , 44be87839eSConrad Meyer.Nm SYSCTL_ADD_S8 , 45be87839eSConrad Meyer.Nm SYSCTL_ADD_S16 , 46be87839eSConrad Meyer.Nm SYSCTL_ADD_S32 , 47be87839eSConrad Meyer.Nm SYSCTL_ADD_S64 , 489a593520SMateusz Piotrowski.Nm SYSCTL_ADD_SBINTIME_MSEC , 499a593520SMateusz Piotrowski.Nm SYSCTL_ADD_SBINTIME_USEC , 505eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_STRING , 5110a1e981SEric Joyner.Nm SYSCTL_ADD_CONST_STRING , 525eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_STRUCT , 530f702183SJohn Baldwin.Nm SYSCTL_ADD_TIMEVAL_SEC , 54fb61390cSConrad Meyer.Nm SYSCTL_ADD_U8 , 55fb61390cSConrad Meyer.Nm SYSCTL_ADD_U16 , 56be87839eSConrad Meyer.Nm SYSCTL_ADD_U32 , 57be87839eSConrad Meyer.Nm SYSCTL_ADD_U64 , 58f0188618SHans Petter Selasky.Nm SYSCTL_ADD_UAUTO , 595eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_UINT , 605eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_ULONG , 619a593520SMateusz Piotrowski.Nm SYSCTL_ADD_UMA_CUR , 629a593520SMateusz Piotrowski.Nm SYSCTL_ADD_UMA_MAX , 63f04020edSMateusz Piotrowski.Nm SYSCTL_ADD_UQUAD , 645eb1caa8SHans Petter Selasky.Nm SYSCTL_CHILDREN , 655eb1caa8SHans Petter Selasky.Nm SYSCTL_STATIC_CHILDREN , 665eb1caa8SHans Petter Selasky.Nm SYSCTL_NODE_CHILDREN , 675eb1caa8SHans Petter Selasky.Nm SYSCTL_PARENT , 689a593520SMateusz Piotrowski.Nm SYSCTL_BOOL , 699a593520SMateusz Piotrowski.Nm SYSCTL_COUNTER_U64 , 709a593520SMateusz Piotrowski.Nm SYSCTL_COUNTER_U64_ARRAY , 71dba9e9ccSRobert Watson.Nm SYSCTL_INT , 721e1f3941SEd Schouten.Nm SYSCTL_INT_WITH_LABEL , 73dba9e9ccSRobert Watson.Nm SYSCTL_LONG , 74574b98cbSJohn Baldwin.Nm sysctl_msec_to_ticks , 75dba9e9ccSRobert Watson.Nm SYSCTL_NODE , 761e1f3941SEd Schouten.Nm SYSCTL_NODE_WITH_LABEL , 77dba9e9ccSRobert Watson.Nm SYSCTL_OPAQUE , 78dba9e9ccSRobert Watson.Nm SYSCTL_PROC , 7960a77442SJohn Baldwin.Nm SYSCTL_QUAD , 805eb1caa8SHans Petter Selasky.Nm SYSCTL_ROOT_NODE , 81be87839eSConrad Meyer.Nm SYSCTL_S8 , 82be87839eSConrad Meyer.Nm SYSCTL_S16 , 83be87839eSConrad Meyer.Nm SYSCTL_S32 , 84be87839eSConrad Meyer.Nm SYSCTL_S64 , 859a593520SMateusz Piotrowski.Nm SYSCTL_SBINTIME_MSEC , 869a593520SMateusz Piotrowski.Nm SYSCTL_SBINTIME_USEC , 87dba9e9ccSRobert Watson.Nm SYSCTL_STRING , 8810a1e981SEric Joyner.Nm SYSCTL_CONST_STRING , 89dba9e9ccSRobert Watson.Nm SYSCTL_STRUCT , 900f702183SJohn Baldwin.Nm SYSCTL_TIMEVAL_SEC , 91fb61390cSConrad Meyer.Nm SYSCTL_U8 , 92fb61390cSConrad Meyer.Nm SYSCTL_U16 , 93be87839eSConrad Meyer.Nm SYSCTL_U32 , 94be87839eSConrad Meyer.Nm SYSCTL_U64 , 95dba9e9ccSRobert Watson.Nm SYSCTL_UINT , 96c157a036SDavid E. O'Brien.Nm SYSCTL_ULONG , 979a593520SMateusz Piotrowski.Nm SYSCTL_UMA_CUR , 989a593520SMateusz Piotrowski.Nm SYSCTL_UMA_MAX 99f04020edSMateusz Piotrowski.Nm SYSCTL_UQUAD , 1005eb1caa8SHans Petter Selasky.Nd Dynamic and static sysctl MIB creation functions 101dba9e9ccSRobert Watson.Sh SYNOPSIS 102651a7908SJonathan T. Looney.In sys/param.h 103dba9e9ccSRobert Watson.In sys/sysctl.h 104bd84dd2fSRuslan Ermilov.Fn SYSCTL_DECL name 1055eb1caa8SHans Petter Selasky.Ft struct sysctl_oid * 1069a593520SMateusz Piotrowski.Fo SYSCTL_ADD_BOOL 1079a593520SMateusz Piotrowski.Fa "struct sysctl_ctx_list *ctx" 1089a593520SMateusz Piotrowski.Fa "struct sysctl_oid_list *parent" 1099a593520SMateusz Piotrowski.Fa "int number" 1109a593520SMateusz Piotrowski.Fa "const char *name" 1119a593520SMateusz Piotrowski.Fa "int ctlflags" 1129a593520SMateusz Piotrowski.Fa "bool *ptr" 1139a593520SMateusz Piotrowski.Fa "uint8_t val" 1149a593520SMateusz Piotrowski.Fa "const char *descr" 1159a593520SMateusz Piotrowski.Fc 1169a593520SMateusz Piotrowski.Ft struct sysctl_oid * 1179a593520SMateusz Piotrowski.Fo SYSCTL_ADD_COUNTER_U64 1189a593520SMateusz Piotrowski.Fa "struct sysctl_ctx_list *ctx" 1199a593520SMateusz Piotrowski.Fa "struct sysctl_oid_list *parent" 1209a593520SMateusz Piotrowski.Fa "int number" 1219a593520SMateusz Piotrowski.Fa "const char *name" 1229a593520SMateusz Piotrowski.Fa "int ctlflags" 1239a593520SMateusz Piotrowski.Fa "counter_u64_t *ptr" 1249a593520SMateusz Piotrowski.Fa "const char *descr" 1259a593520SMateusz Piotrowski.Fc 1269a593520SMateusz Piotrowski.Ft struct sysctl_oid * 1279a593520SMateusz Piotrowski.Fo SYSCTL_ADD_COUNTER_U64_ARRAY 1289a593520SMateusz Piotrowski.Fa "struct sysctl_ctx_list *ctx" 1299a593520SMateusz Piotrowski.Fa "struct sysctl_oid_list *parent" 1309a593520SMateusz Piotrowski.Fa "int number" 1319a593520SMateusz Piotrowski.Fa "const char *name" 1329a593520SMateusz Piotrowski.Fa "int ctlflags" 1339a593520SMateusz Piotrowski.Fa "counter_u64_t *ptr" 1349a593520SMateusz Piotrowski.Fa "intmax_t len" 1359a593520SMateusz Piotrowski.Fa "const char *descr" 1369a593520SMateusz Piotrowski.Fc 1379a593520SMateusz Piotrowski.Ft struct sysctl_oid * 1385eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_INT 1395eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx" 1405eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent" 1415eb1caa8SHans Petter Selasky.Fa "int number" 1425eb1caa8SHans Petter Selasky.Fa "const char *name" 1435eb1caa8SHans Petter Selasky.Fa "int ctlflags" 1445eb1caa8SHans Petter Selasky.Fa "int *ptr" 145be87839eSConrad Meyer.Fa "int val" 1465eb1caa8SHans Petter Selasky.Fa "const char *descr" 1475eb1caa8SHans Petter Selasky.Fc 1485eb1caa8SHans Petter Selasky.Ft struct sysctl_oid * 1495eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_LONG 1505eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx" 1515eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent" 1525eb1caa8SHans Petter Selasky.Fa "int number" 1535eb1caa8SHans Petter Selasky.Fa "const char *name" 1545eb1caa8SHans Petter Selasky.Fa "int ctlflags" 1555eb1caa8SHans Petter Selasky.Fa "long *ptr" 1565eb1caa8SHans Petter Selasky.Fa "const char *descr" 1575eb1caa8SHans Petter Selasky.Fc 1585eb1caa8SHans Petter Selasky.Ft struct sysctl_oid * 1595eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_NODE 1605eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx" 1615eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent" 1625eb1caa8SHans Petter Selasky.Fa "int number" 1635eb1caa8SHans Petter Selasky.Fa "const char *name" 1645eb1caa8SHans Petter Selasky.Fa "int ctlflags" 1655eb1caa8SHans Petter Selasky.Fa "int (*handler)(SYSCTL_HANDLER_ARGS)" 1665eb1caa8SHans Petter Selasky.Fa "const char *descr" 1675eb1caa8SHans Petter Selasky.Fc 1685eb1caa8SHans Petter Selasky.Ft struct sysctl_oid * 1691e1f3941SEd Schouten.Fo SYSCTL_ADD_NODE_WITH_LABEL 1701e1f3941SEd Schouten.Fa "struct sysctl_ctx_list *ctx" 1711e1f3941SEd Schouten.Fa "struct sysctl_oid_list *parent" 1721e1f3941SEd Schouten.Fa "int number" 1731e1f3941SEd Schouten.Fa "const char *name" 1741e1f3941SEd Schouten.Fa "int ctlflags" 1751e1f3941SEd Schouten.Fa "int (*handler)(SYSCTL_HANDLER_ARGS)" 1761e1f3941SEd Schouten.Fa "const char *descr" 1771e1f3941SEd Schouten.Fa "const char *label" 1781e1f3941SEd Schouten.Fc 1791e1f3941SEd Schouten.Ft struct sysctl_oid * 1805eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_OPAQUE 1815eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx" 1825eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent" 1835eb1caa8SHans Petter Selasky.Fa "int number" 1845eb1caa8SHans Petter Selasky.Fa "const char *name" 1855eb1caa8SHans Petter Selasky.Fa "int ctlflags" 1865eb1caa8SHans Petter Selasky.Fa "void *ptr" 1875eb1caa8SHans Petter Selasky.Fa "intptr_t len" 1885eb1caa8SHans Petter Selasky.Fa "const char *format" 1893edc2b53SJoel Dahl.Fa "const char *descr" 1905eb1caa8SHans Petter Selasky.Fc 1915eb1caa8SHans Petter Selasky.Ft struct sysctl_oid * 1925eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_PROC 1935eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx" 1945eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent" 1955eb1caa8SHans Petter Selasky.Fa "int number" 1965eb1caa8SHans Petter Selasky.Fa "const char *name" 1975eb1caa8SHans Petter Selasky.Fa "int ctlflags" 1985eb1caa8SHans Petter Selasky.Fa "void *arg1" 1995eb1caa8SHans Petter Selasky.Fa "intptr_t arg2" 200ba9a5309SAndriy Voskoboinyk.Fa "int (*handler) (SYSCTL_HANDLER_ARGS)" 2015eb1caa8SHans Petter Selasky.Fa "const char *format" 2025eb1caa8SHans Petter Selasky.Fa "const char *descr" 2035eb1caa8SHans Petter Selasky.Fc 2045eb1caa8SHans Petter Selasky.Ft struct sysctl_oid * 2055eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_QUAD 2065eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx" 2075eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent" 2085eb1caa8SHans Petter Selasky.Fa "int number" 2095eb1caa8SHans Petter Selasky.Fa "const char *name" 2105eb1caa8SHans Petter Selasky.Fa "int ctlflags" 211be87839eSConrad Meyer.Fa "int64_t *ptr" 2125eb1caa8SHans Petter Selasky.Fa "const char *descr" 2135eb1caa8SHans Petter Selasky.Fc 2145eb1caa8SHans Petter Selasky.Ft struct sysctl_oid * 2155eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_ROOT_NODE 2165eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx" 2175eb1caa8SHans Petter Selasky.Fa "int number" 2185eb1caa8SHans Petter Selasky.Fa "const char *name" 2195eb1caa8SHans Petter Selasky.Fa "int ctlflags" 2205eb1caa8SHans Petter Selasky.Fa "int (*handler)(SYSCTL_HANDLER_ARGS)" 2215eb1caa8SHans Petter Selasky.Fa "const char *descr" 2225eb1caa8SHans Petter Selasky.Fc 2235eb1caa8SHans Petter Selasky.Ft struct sysctl_oid * 224be87839eSConrad Meyer.Fo SYSCTL_ADD_S8 225be87839eSConrad Meyer.Fa "struct sysctl_ctx_list *ctx" 226be87839eSConrad Meyer.Fa "struct sysctl_oid_list *parent" 227be87839eSConrad Meyer.Fa "int number" 228be87839eSConrad Meyer.Fa "const char *name" 229be87839eSConrad Meyer.Fa "int ctlflags" 230be87839eSConrad Meyer.Fa "int8_t *ptr" 231be87839eSConrad Meyer.Fa "int8_t val" 232be87839eSConrad Meyer.Fa "const char *descr" 233be87839eSConrad Meyer.Fc 234be87839eSConrad Meyer.Ft struct sysctl_oid * 235be87839eSConrad Meyer.Fo SYSCTL_ADD_S16 236be87839eSConrad Meyer.Fa "struct sysctl_ctx_list *ctx" 237be87839eSConrad Meyer.Fa "struct sysctl_oid_list *parent" 238be87839eSConrad Meyer.Fa "int number" 239be87839eSConrad Meyer.Fa "const char *name" 240be87839eSConrad Meyer.Fa "int ctlflags" 241be87839eSConrad Meyer.Fa "int16_t *ptr" 242be87839eSConrad Meyer.Fa "int16_t val" 243be87839eSConrad Meyer.Fa "const char *descr" 244be87839eSConrad Meyer.Fc 245be87839eSConrad Meyer.Ft struct sysctl_oid * 246be87839eSConrad Meyer.Fo SYSCTL_ADD_S32 247be87839eSConrad Meyer.Fa "struct sysctl_ctx_list *ctx" 248be87839eSConrad Meyer.Fa "struct sysctl_oid_list *parent" 249be87839eSConrad Meyer.Fa "int number" 250be87839eSConrad Meyer.Fa "const char *name" 251be87839eSConrad Meyer.Fa "int ctlflags" 252be87839eSConrad Meyer.Fa "int32_t *ptr" 253be87839eSConrad Meyer.Fa "int32_t val" 254be87839eSConrad Meyer.Fa "const char *descr" 255be87839eSConrad Meyer.Fc 256be87839eSConrad Meyer.Ft struct sysctl_oid * 257be87839eSConrad Meyer.Fo SYSCTL_ADD_S64 258be87839eSConrad Meyer.Fa "struct sysctl_ctx_list *ctx" 259be87839eSConrad Meyer.Fa "struct sysctl_oid_list *parent" 260be87839eSConrad Meyer.Fa "int number" 261be87839eSConrad Meyer.Fa "const char *name" 262be87839eSConrad Meyer.Fa "int ctlflags" 263be87839eSConrad Meyer.Fa "int64_t *ptr" 264be87839eSConrad Meyer.Fa "int64_t val" 265be87839eSConrad Meyer.Fa "const char *descr" 266be87839eSConrad Meyer.Fc 267be87839eSConrad Meyer.Ft struct sysctl_oid * 2689a593520SMateusz Piotrowski.Fo SYSCTL_ADD_SBINTIME_MSEC 2699a593520SMateusz Piotrowski.Fa "struct sysctl_ctx_list *ctx" 2709a593520SMateusz Piotrowski.Fa "struct sysctl_oid_list *parent" 2719a593520SMateusz Piotrowski.Fa "int number" 2729a593520SMateusz Piotrowski.Fa "const char *name" 2739a593520SMateusz Piotrowski.Fa "int ctlflags" 2749a593520SMateusz Piotrowski.Fa "sbintime_t *ptr" 2759a593520SMateusz Piotrowski.Fa "const char *descr" 2769a593520SMateusz Piotrowski.Fc 2779a593520SMateusz Piotrowski.Ft struct sysctl_oid * 2789a593520SMateusz Piotrowski.Fo SYSCTL_ADD_SBINTIME_USEC 2799a593520SMateusz Piotrowski.Fa "struct sysctl_ctx_list *ctx" 2809a593520SMateusz Piotrowski.Fa "struct sysctl_oid_list *parent" 2819a593520SMateusz Piotrowski.Fa "int number" 2829a593520SMateusz Piotrowski.Fa "const char *name" 2839a593520SMateusz Piotrowski.Fa "int ctlflags" 2849a593520SMateusz Piotrowski.Fa "sbintime_t *ptr" 2859a593520SMateusz Piotrowski.Fa "const char *descr" 2869a593520SMateusz Piotrowski.Fc 2879a593520SMateusz Piotrowski.Ft struct sysctl_oid * 2885eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_STRING 2895eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx" 2905eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent" 2915eb1caa8SHans Petter Selasky.Fa "int number" 2925eb1caa8SHans Petter Selasky.Fa "const char *name" 2935eb1caa8SHans Petter Selasky.Fa "int ctlflags" 2945eb1caa8SHans Petter Selasky.Fa "char *ptr" 2955eb1caa8SHans Petter Selasky.Fa "intptr_t len" 2965eb1caa8SHans Petter Selasky.Fa "const char *descr" 2975eb1caa8SHans Petter Selasky.Fc 2985eb1caa8SHans Petter Selasky.Ft struct sysctl_oid * 29910a1e981SEric Joyner.Fo SYSCTL_ADD_CONST_STRING 30010a1e981SEric Joyner.Fa "struct sysctl_ctx_list *ctx" 30110a1e981SEric Joyner.Fa "struct sysctl_oid_list *parent" 30210a1e981SEric Joyner.Fa "int number" 30310a1e981SEric Joyner.Fa "const char *name" 30410a1e981SEric Joyner.Fa "int ctlflags" 30510a1e981SEric Joyner.Fa "const char *ptr" 30610a1e981SEric Joyner.Fa "const char *descr" 30710a1e981SEric Joyner.Fc 30810a1e981SEric Joyner.Ft struct sysctl_oid * 3095eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_STRUCT 3105eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx" 3115eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent" 3125eb1caa8SHans Petter Selasky.Fa "int number" 3135eb1caa8SHans Petter Selasky.Fa "const char *name" 3145eb1caa8SHans Petter Selasky.Fa "int ctlflags" 3155eb1caa8SHans Petter Selasky.Fa "void *ptr" 3165eb1caa8SHans Petter Selasky.Fa struct_type 3175eb1caa8SHans Petter Selasky.Fa "const char *descr" 3185eb1caa8SHans Petter Selasky.Fc 3195eb1caa8SHans Petter Selasky.Ft struct sysctl_oid * 3200f702183SJohn Baldwin.Fo SYSCTL_ADD_TIMEVAL_SEC 3210f702183SJohn Baldwin.Fa "struct sysctl_ctx_list *ctx" 3220f702183SJohn Baldwin.Fa "struct sysctl_oid_list *parent" 3230f702183SJohn Baldwin.Fa "int number" 3240f702183SJohn Baldwin.Fa "const char *name" 3250f702183SJohn Baldwin.Fa "int ctlflags" 3260f702183SJohn Baldwin.Fa "struct timeval *ptr" 3270f702183SJohn Baldwin.Fa "const char *descr" 3280f702183SJohn Baldwin.Fc 3290f702183SJohn Baldwin.Ft struct sysctl_oid * 330fb61390cSConrad Meyer.Fo SYSCTL_ADD_U8 331fb61390cSConrad Meyer.Fa "struct sysctl_ctx_list *ctx" 332fb61390cSConrad Meyer.Fa "struct sysctl_oid_list *parent" 333fb61390cSConrad Meyer.Fa "int number" 334fb61390cSConrad Meyer.Fa "const char *name" 335fb61390cSConrad Meyer.Fa "int ctlflags" 336be87839eSConrad Meyer.Fa "uint8_t *ptr" 337be87839eSConrad Meyer.Fa "uint8_t val" 338fb61390cSConrad Meyer.Fa "const char *descr" 339fb61390cSConrad Meyer.Fc 340fb61390cSConrad Meyer.Ft struct sysctl_oid * 341fb61390cSConrad Meyer.Fo SYSCTL_ADD_U16 342fb61390cSConrad Meyer.Fa "struct sysctl_ctx_list *ctx" 343fb61390cSConrad Meyer.Fa "struct sysctl_oid_list *parent" 344fb61390cSConrad Meyer.Fa "int number" 345fb61390cSConrad Meyer.Fa "const char *name" 346fb61390cSConrad Meyer.Fa "int ctlflags" 347be87839eSConrad Meyer.Fa "uint16_t *ptr" 348be87839eSConrad Meyer.Fa "uint16_t val" 349be87839eSConrad Meyer.Fa "const char *descr" 350be87839eSConrad Meyer.Fc 351be87839eSConrad Meyer.Ft struct sysctl_oid * 352be87839eSConrad Meyer.Fo SYSCTL_ADD_U32 353be87839eSConrad Meyer.Fa "struct sysctl_ctx_list *ctx" 354be87839eSConrad Meyer.Fa "struct sysctl_oid_list *parent" 355be87839eSConrad Meyer.Fa "int number" 356be87839eSConrad Meyer.Fa "const char *name" 357be87839eSConrad Meyer.Fa "int ctlflags" 358be87839eSConrad Meyer.Fa "uint32_t *ptr" 359be87839eSConrad Meyer.Fa "uint32_t val" 360be87839eSConrad Meyer.Fa "const char *descr" 361be87839eSConrad Meyer.Fc 362be87839eSConrad Meyer.Ft struct sysctl_oid * 363be87839eSConrad Meyer.Fo SYSCTL_ADD_U64 364be87839eSConrad Meyer.Fa "struct sysctl_ctx_list *ctx" 365be87839eSConrad Meyer.Fa "struct sysctl_oid_list *parent" 366be87839eSConrad Meyer.Fa "int number" 367be87839eSConrad Meyer.Fa "const char *name" 368be87839eSConrad Meyer.Fa "int ctlflags" 369be87839eSConrad Meyer.Fa "uint64_t *ptr" 370be87839eSConrad Meyer.Fa "uint64_t val" 371fb61390cSConrad Meyer.Fa "const char *descr" 372fb61390cSConrad Meyer.Fc 373fb61390cSConrad Meyer.Ft struct sysctl_oid * 3745eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_UINT 3755eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx" 3765eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent" 3775eb1caa8SHans Petter Selasky.Fa "int number" 3785eb1caa8SHans Petter Selasky.Fa "const char *name" 3795eb1caa8SHans Petter Selasky.Fa "int ctlflags" 3805eb1caa8SHans Petter Selasky.Fa "unsigned int *ptr" 381be87839eSConrad Meyer.Fa "unsigned int val" 3825eb1caa8SHans Petter Selasky.Fa "const char *descr" 3835eb1caa8SHans Petter Selasky.Fc 3845eb1caa8SHans Petter Selasky.Ft struct sysctl_oid * 3855eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_ULONG 3865eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx" 3875eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent" 3885eb1caa8SHans Petter Selasky.Fa "int number" 3895eb1caa8SHans Petter Selasky.Fa "const char *name" 3905eb1caa8SHans Petter Selasky.Fa "int ctlflags" 3915eb1caa8SHans Petter Selasky.Fa "unsigned long *ptr" 3925eb1caa8SHans Petter Selasky.Fa "const char *descr" 3935eb1caa8SHans Petter Selasky.Fc 3945eb1caa8SHans Petter Selasky.Ft struct sysctl_oid * 3955eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_UQUAD 3965eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx" 3975eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent" 3985eb1caa8SHans Petter Selasky.Fa "int number" 3995eb1caa8SHans Petter Selasky.Fa "const char *name" 4005eb1caa8SHans Petter Selasky.Fa "int ctlflags" 401be87839eSConrad Meyer.Fa "uint64_t *ptr" 402f0188618SHans Petter Selasky.Fa "const char *descr" 403f0188618SHans Petter Selasky.Fc 404f0188618SHans Petter Selasky.Ft struct sysctl_oid * 4059a593520SMateusz Piotrowski.Fo SYSCTL_ADD_UMA_CUR 4069a593520SMateusz Piotrowski.Fa "struct sysctl_ctx_list *ctx" 4079a593520SMateusz Piotrowski.Fa "struct sysctl_oid_list *parent" 4089a593520SMateusz Piotrowski.Fa "int number" 4099a593520SMateusz Piotrowski.Fa "const char *name" 4109a593520SMateusz Piotrowski.Fa "int ctlflags" 4119a593520SMateusz Piotrowski.Fa "uma_zone_t ptr" 4129a593520SMateusz Piotrowski.Fa "const char *descr" 4139a593520SMateusz Piotrowski.Fc 4149a593520SMateusz Piotrowski.Ft struct sysctl_oid * 4159a593520SMateusz Piotrowski.Fo SYSCTL_ADD_UMA_MAX 4169a593520SMateusz Piotrowski.Fa "struct sysctl_ctx_list *ctx" 4179a593520SMateusz Piotrowski.Fa "struct sysctl_oid_list *parent" 4189a593520SMateusz Piotrowski.Fa "int number" 4199a593520SMateusz Piotrowski.Fa "const char *name" 4209a593520SMateusz Piotrowski.Fa "int ctlflags" 4219a593520SMateusz Piotrowski.Fa "uma_zone_t ptr" 4229a593520SMateusz Piotrowski.Fa "const char *descr" 4239a593520SMateusz Piotrowski.Fc 4249a593520SMateusz Piotrowski.Fa "const char *descr" 4259a593520SMateusz Piotrowski.Ft struct sysctl_oid * 426f0188618SHans Petter Selasky.Fo SYSCTL_ADD_UAUTO 427f0188618SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx" 428f0188618SHans Petter Selasky.Fa "struct sysctl_oid_list *parent" 429f0188618SHans Petter Selasky.Fa "int number" 430f0188618SHans Petter Selasky.Fa "const char *name" 431f0188618SHans Petter Selasky.Fa "int ctlflags" 432f0188618SHans Petter Selasky.Fa "void *ptr" 4335eb1caa8SHans Petter Selasky.Fa "const char *descr" 4345eb1caa8SHans Petter Selasky.Fc 4355eb1caa8SHans Petter Selasky.Ft struct sysctl_oid_list * 4365eb1caa8SHans Petter Selasky.Fo SYSCTL_CHILDREN 4375eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid *oidp" 4385eb1caa8SHans Petter Selasky.Fc 4395eb1caa8SHans Petter Selasky.Ft struct sysctl_oid_list * 4405eb1caa8SHans Petter Selasky.Fo SYSCTL_STATIC_CHILDREN 4415eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list OID_NAME" 4425eb1caa8SHans Petter Selasky.Fc 4435eb1caa8SHans Petter Selasky.Ft struct sysctl_oid_list * 4445eb1caa8SHans Petter Selasky.Fo SYSCTL_NODE_CHILDREN 4455eb1caa8SHans Petter Selasky.Fa "parent" 4465eb1caa8SHans Petter Selasky.Fa "name" 4475eb1caa8SHans Petter Selasky.Fc 4485eb1caa8SHans Petter Selasky.Ft struct sysctl_oid * 4495eb1caa8SHans Petter Selasky.Fo SYSCTL_PARENT 4505eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid *oid" 4515eb1caa8SHans Petter Selasky.Fc 4529a593520SMateusz Piotrowski.Fn SYSCTL_BOOL parent number name ctlflags ptr val descr 4539a593520SMateusz Piotrowski.Fn SYSCTL_COUNTER_U64 parent number name ctlflags ptr descr 4549a593520SMateusz Piotrowski.Fn SYSCTL_COUNTER_U64_ARRAY parent number name ctlflags ptr len descr 4555eb1caa8SHans Petter Selasky.Fn SYSCTL_INT parent number name ctlflags ptr val descr 4561e1f3941SEd Schouten.Fn SYSCTL_INT_WITH_LABEL parent number name ctlflags ptr val descr label 4575eb1caa8SHans Petter Selasky.Fn SYSCTL_LONG parent number name ctlflags ptr val descr 458574b98cbSJohn Baldwin.Ft int 459574b98cbSJohn Baldwin.Fn sysctl_msec_to_ticks SYSCTL_HANDLER_ARGS 4605eb1caa8SHans Petter Selasky.Fn SYSCTL_NODE parent number name ctlflags handler descr 4611e1f3941SEd Schouten.Fn SYSCTL_NODE_WITH_LABEL parent number name ctlflags handler descr label 4625eb1caa8SHans Petter Selasky.Fn SYSCTL_OPAQUE parent number name ctlflags ptr len format descr 4635eb1caa8SHans Petter Selasky.Fn SYSCTL_PROC parent number name ctlflags arg1 arg2 handler format descr 4645eb1caa8SHans Petter Selasky.Fn SYSCTL_QUAD parent number name ctlflags ptr val descr 465be87839eSConrad Meyer.Fn SYSCTL_ROOT_NODE number name ctlflags handler descr 466be87839eSConrad Meyer.Fn SYSCTL_S8 parent number name ctlflags ptr val descr 467be87839eSConrad Meyer.Fn SYSCTL_S16 parent number name ctlflags ptr val descr 468be87839eSConrad Meyer.Fn SYSCTL_S32 parent number name ctlflags ptr val descr 469be87839eSConrad Meyer.Fn SYSCTL_S64 parent number name ctlflags ptr val descr 4709a593520SMateusz Piotrowski.Fn SYSCTL_SBINTIME_MSEC parent number name ctlflags ptr descr 4719a593520SMateusz Piotrowski.Fn SYSCTL_SBINTIME_USEC parent number name ctlflags ptr descr 4725eb1caa8SHans Petter Selasky.Fn SYSCTL_STRING parent number name ctlflags arg len descr 47310a1e981SEric Joyner.Fn SYSCTL_CONST_STRING parent number name ctlflags arg descr 4745eb1caa8SHans Petter Selasky.Fn SYSCTL_STRUCT parent number name ctlflags ptr struct_type descr 4750f702183SJohn Baldwin.Fn SYSCTL_TIMEVAL_SEC parent number name ctlflags ptr descr 476fb61390cSConrad Meyer.Fn SYSCTL_U8 parent number name ctlflags ptr val descr 477fb61390cSConrad Meyer.Fn SYSCTL_U16 parent number name ctlflags ptr val descr 478be87839eSConrad Meyer.Fn SYSCTL_U32 parent number name ctlflags ptr val descr 479be87839eSConrad Meyer.Fn SYSCTL_U64 parent number name ctlflags ptr val descr 4805eb1caa8SHans Petter Selasky.Fn SYSCTL_UINT parent number name ctlflags ptr val descr 4815eb1caa8SHans Petter Selasky.Fn SYSCTL_ULONG parent number name ctlflags ptr val descr 4825eb1caa8SHans Petter Selasky.Fn SYSCTL_UQUAD parent number name ctlflags ptr val descr 4839a593520SMateusz Piotrowski.Fn SYSCTL_UMA_MAX parent number name ctlflags ptr descr 4849a593520SMateusz Piotrowski.Fn SYSCTL_UMA_CUR parent number name ctlflags ptr descr 485dba9e9ccSRobert Watson.Sh DESCRIPTION 486dba9e9ccSRobert WatsonThe 487bd84dd2fSRuslan Ermilov.Nm SYSCTL 4885eb1caa8SHans Petter Selaskykernel interface allows dynamic or static creation of 489dba9e9ccSRobert Watson.Xr sysctl 8 4905eb1caa8SHans Petter SelaskyMIB entries. 4915eb1caa8SHans Petter SelaskyAll static sysctls are automatically destroyed when the module which 4925eb1caa8SHans Petter Selaskythey are part of is unloaded. 4935eb1caa8SHans Petter SelaskyMost top level categories are created statically and are available to 4945eb1caa8SHans Petter Selaskyall kernel code and its modules. 4955eb1caa8SHans Petter Selasky.Sh DESCRIPTION OF ARGUMENTS 4965eb1caa8SHans Petter Selasky.Bl -tag -width ctlflags 4975eb1caa8SHans Petter Selasky.It Fa ctx 4985eb1caa8SHans Petter SelaskyPointer to sysctl context or NULL, if no context. 4995eb1caa8SHans Petter SelaskySee 5005eb1caa8SHans Petter Selasky.Xr sysctl_ctx_init 9 5015eb1caa8SHans Petter Selaskyfor how to create a new sysctl context. 5025eb1caa8SHans Petter SelaskyProgrammers are strongly advised to use contexts to organize the 5035eb1caa8SHans Petter Selaskydynamic OIDs which they create because when a context is destroyed all 5045eb1caa8SHans Petter Selaskybelonging sysctls are destroyed as well. 5055eb1caa8SHans Petter SelaskyThis makes the sysctl cleanup code much simpler. 506aa88ccabSHans Petter SelaskyElse deletion of all created OIDs is required at module unload. 5075eb1caa8SHans Petter Selasky.It Fa parent 5085eb1caa8SHans Petter SelaskyA pointer to a 5095eb1caa8SHans Petter Selasky.Li struct sysctl_oid_list , 5105eb1caa8SHans Petter Selaskywhich is the head of the parent's list of children. 511aa88ccabSHans Petter SelaskyThis pointer is retrieved using the 5125eb1caa8SHans Petter Selasky.Fn SYSCTL_STATIC_CHILDREN 5135eb1caa8SHans Petter Selaskymacro for static sysctls and the 5145eb1caa8SHans Petter Selasky.Fn SYSCTL_CHILDREN 5155eb1caa8SHans Petter Selaskymacro for dynamic sysctls. 516aa88ccabSHans Petter SelaskyThe 5175eb1caa8SHans Petter Selasky.Fn SYSCTL_PARENT 518aa88ccabSHans Petter Selaskymacro can be used to get the parent of an OID. 519aa88ccabSHans Petter SelaskyThe macro returns NULL if there is no parent. 5205eb1caa8SHans Petter Selasky.It Fa number 5215eb1caa8SHans Petter SelaskyThe OID number that will be assigned to this OID. 5225eb1caa8SHans Petter SelaskyIn almost all cases this should be set to 5235eb1caa8SHans Petter Selasky.Dv OID_AUTO , 5245eb1caa8SHans Petter Selaskywhich will result in the assignment of the next available OID number. 5255eb1caa8SHans Petter Selasky.It Fa name 5265eb1caa8SHans Petter SelaskyThe name of the OID. 5275eb1caa8SHans Petter SelaskyThe newly created OID will contain a copy of the name. 5285eb1caa8SHans Petter Selasky.It Fa ctlflags 5295eb1caa8SHans Petter SelaskyA bit mask of sysctl control flags. 5305eb1caa8SHans Petter SelaskySee the section below describing all the control flags. 5315eb1caa8SHans Petter Selasky.It Fa arg1 5325eb1caa8SHans Petter SelaskyFirst callback argument for procedure sysctls. 5335eb1caa8SHans Petter Selasky.It Fa arg2 5345eb1caa8SHans Petter SelaskySecond callback argument for procedure sysctls. 5355eb1caa8SHans Petter Selasky.It Fa len 5365eb1caa8SHans Petter SelaskyThe length of the data pointed to by the 5375eb1caa8SHans Petter Selasky.Fa ptr 5385eb1caa8SHans Petter Selaskyargument. 5395eb1caa8SHans Petter SelaskyFor string type OIDs a length of zero means that 5405eb1caa8SHans Petter Selasky.Xr strlen 3 5415eb1caa8SHans Petter Selaskywill be used to get the length of the string at each access to the OID. 5429a593520SMateusz PiotrowskiFor array type OIDs the length must be greater than zero. 5435eb1caa8SHans Petter Selasky.It Fa ptr 5445eb1caa8SHans Petter SelaskyPointer to sysctl variable or string data. 545f0188618SHans Petter SelaskyFor sysctl values the pointer can be SYSCTL_NULL_XXX_PTR which means the OID is read-only and the returned value should be taken from the 5465eb1caa8SHans Petter Selasky.Fa val 5475eb1caa8SHans Petter Selaskyargument. 5485eb1caa8SHans Petter Selasky.It Fa val 5495eb1caa8SHans Petter SelaskyIf the 5505eb1caa8SHans Petter Selasky.Fa ptr 551f0188618SHans Petter Selaskyargument is SYSCTL_NULL_XXX_PTR, gives the constant value returned by this OID. 5525eb1caa8SHans Petter SelaskyElse this argument is not used. 5535eb1caa8SHans Petter Selasky.It Fa struct_type 5545eb1caa8SHans Petter SelaskyName of structure type. 5555eb1caa8SHans Petter Selasky.It Fa handler 5565eb1caa8SHans Petter SelaskyA pointer to the function 5575eb1caa8SHans Petter Selaskythat is responsible for handling read and write requests 5585eb1caa8SHans Petter Selaskyto this OID. 5595eb1caa8SHans Petter SelaskyThere are several standard handlers 5605eb1caa8SHans Petter Selaskythat support operations on nodes, 5615eb1caa8SHans Petter Selaskyintegers, strings and opaque objects. 5625eb1caa8SHans Petter SelaskyIt is possible to define custom handlers using the 5635eb1caa8SHans Petter Selasky.Fn SYSCTL_PROC 5645eb1caa8SHans Petter Selaskymacro or the 5655eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_PROC 5665eb1caa8SHans Petter Selaskyfunction. 5675eb1caa8SHans Petter Selasky.It Fa format 5685eb1caa8SHans Petter SelaskyA pointer to a string 5695eb1caa8SHans Petter Selaskywhich specifies the format of the OID in a symbolic way. 5705eb1caa8SHans Petter SelaskyThis format is used as a hint by 5715eb1caa8SHans Petter Selasky.Xr sysctl 8 5725eb1caa8SHans Petter Selaskyto apply proper data formatting for display purposes. 573aa255ef6SWarner Losh.Pp 574aa255ef6SWarner LoshCurrent formats: 575aa255ef6SWarner Losh.Bl -tag -width "S,TYPE" -compact -offset indent 576aa255ef6SWarner Losh.It Cm N 577aa255ef6SWarner Loshnode 578aa255ef6SWarner Losh.It Cm A 579aa255ef6SWarner Losh.Li "char *" 580aa255ef6SWarner Losh.It Cm I 581aa255ef6SWarner Losh.Li "int" 582aa255ef6SWarner Losh.It Cm IK Ns Op Ar n 583aa255ef6SWarner Loshtemperature in Kelvin, multiplied by an optional single digit 584aa255ef6SWarner Loshpower of ten scaling factor: 1 (default) gives deciKelvin, 0 gives Kelvin, 3 585aa255ef6SWarner Loshgives milliKelvin 586aa255ef6SWarner Losh.It Cm IU 587aa255ef6SWarner Losh.Li "unsigned int" 588aa255ef6SWarner Losh.It Cm L 589aa255ef6SWarner Losh.Li "long" 590aa255ef6SWarner Losh.It Cm LU 591aa255ef6SWarner Losh.Li "unsigned long" 592aa255ef6SWarner Losh.It Cm Q 593aa255ef6SWarner Losh.Li "quad_t" 594aa255ef6SWarner Losh.It Cm QU 5955eb1caa8SHans Petter Selasky.Li "u_quad_t" 596aa255ef6SWarner Losh.It Cm "S,TYPE" 5975eb1caa8SHans Petter Selasky.Li "struct TYPE" 598aa255ef6SWarner Loshstructures 599aa255ef6SWarner Losh.El 6005eb1caa8SHans Petter Selasky.It Fa descr 6015eb1caa8SHans Petter SelaskyA pointer to a textual description of the OID. 6021e1f3941SEd Schouten.It Fa label 6031e1f3941SEd SchoutenA pointer to an aggregation label for this component of the OID. 6041e1f3941SEd SchoutenTo make it easier to export sysctl data to monitoring systems that 6051e1f3941SEd Schoutensupport aggregations through labels (e.g., Prometheus), 6061e1f3941SEd Schoutenthis argument can be used to attach a label name to an OID. 6071e1f3941SEd SchoutenThe label acts as a hint that this component's name should not be part 6081e1f3941SEd Schoutenof the metric's name, 6091e1f3941SEd Schoutenbut attached to the metric as a label instead. 6101e1f3941SEd Schouten.Pp 6111e1f3941SEd SchoutenLabels should only be applied to siblings that are structurally similar 6121e1f3941SEd Schoutenand encode the same type of value, 6131e1f3941SEd Schoutenas aggregation is of no use otherwise. 6145eb1caa8SHans Petter Selasky.El 615574b98cbSJohn Baldwin.Sh NODE VALUE TYPES 616574b98cbSJohn BaldwinMost of the macros and functions used to create sysctl nodes export a 617574b98cbSJohn Baldwinread-only constant or in-kernel variable whose type matches the type 618574b98cbSJohn Baldwinof the node's value. 619574b98cbSJohn BaldwinFor example, 620574b98cbSJohn Baldwin.Fn SYSCTL_INT 621574b98cbSJohn Baldwinreports the raw value of an associated variable of type 622574b98cbSJohn Baldwin.Vt int . 623574b98cbSJohn BaldwinHowever, nodes may also export a value that is a translatation of an internal 624574b98cbSJohn Baldwinrepresentation. 625574b98cbSJohn Baldwin.Pp 626574b98cbSJohn BaldwinThe 627574b98cbSJohn Baldwin.Fn sysctl_msec_to_ticks 628574b98cbSJohn Baldwinhandler can be used with 629574b98cbSJohn Baldwin.Fn SYSCTL_PROC 630574b98cbSJohn Baldwinor 631574b98cbSJohn Baldwin.Fn SYSCTL_ADD_PROC 632574b98cbSJohn Baldwinto export a millisecond time interval. 633574b98cbSJohn BaldwinWhen using this handler, 634574b98cbSJohn Baldwinthe 635574b98cbSJohn Baldwin.Fa arg2 636574b98cbSJohn Baldwinparameter points to an in-kernel variable of type 637574b98cbSJohn Baldwin.Vt int 638574b98cbSJohn Baldwinwhich stores a tick count suitable for use with functions like 639574b98cbSJohn Baldwin.Xr tsleep 9 . 640574b98cbSJohn BaldwinThe 641574b98cbSJohn Baldwin.Fn sysctl_msec_to_ticks 642574b98cbSJohn Baldwinfunction converts this value to milliseconds when reporting the node's value. 643574b98cbSJohn BaldwinSimilarly, 644574b98cbSJohn Baldwin.Fn sysctl_msec_to_ticks 645574b98cbSJohn Baldwinaccepts new values in milliseconds and stores an equivalent value in ticks to 646574b98cbSJohn Baldwin.Fa *arg2 . 647574b98cbSJohn BaldwinNote that new code should use kernel variables of type 648574b98cbSJohn Baldwin.Vt sbintime_t 649574b98cbSJohn Baldwininstead of tick counts. 650574b98cbSJohn Baldwin.Pp 651574b98cbSJohn BaldwinThe 652574b98cbSJohn Baldwin.Fn SYSCTL_ADD_SBINTIME_MSEC 653574b98cbSJohn Baldwinand 654574b98cbSJohn Baldwin.Fn SYSCTL_ADD_SBINTIME_USEC 655574b98cbSJohn Baldwinfunctions and 656574b98cbSJohn Baldwin.Fn SYSCTL_SBINTIME_MSEC 657574b98cbSJohn Baldwinand 658574b98cbSJohn Baldwin.Fn SYSCTL_SBINTIME_USEC 659574b98cbSJohn Baldwinmacros all create nodes which export an in-kernel variable of type 660574b98cbSJohn Baldwin.Vt sbintime_t . 661574b98cbSJohn BaldwinThese nodes do not export the raw value of the associated variable. 662574b98cbSJohn BaldwinInstead, they export a 64-bit integer containing a count of either 663574b98cbSJohn Baldwinmilliseconds (the MSEC variants) or microseconds (the USEC variants). 6640f702183SJohn Baldwin.Pp 6650f702183SJohn BaldwinThe 6660f702183SJohn Baldwin.Fn SYSCTL_ADD_TIMEVAL_SEC 6670f702183SJohn Baldwinfunction and 6680f702183SJohn Baldwin.Fn SYSCTL_TIMEVAL_SEC 6690f702183SJohn Baldwinmacro create nodes which export an in-kernel variable of type 6700f702183SJohn Baldwin.Vt struct timeval . 6710f702183SJohn BaldwinThese nodes do not export full value of the associated structure. 6720f702183SJohn BaldwinInstead, they export a count in seconds as a simple integer which is 6730f702183SJohn Baldwinstored in the 6740f702183SJohn Baldwin.Fa tv_sec 6750f702183SJohn Baldwinfield of the associated variable. 6760f702183SJohn BaldwinThis function and macro are intended to be used with variables which 6770f702183SJohn Baldwinstore a non-negative interval rather than an absolute time. 6780f702183SJohn BaldwinAs a result, they reject attempts to store negative values. 6795eb1caa8SHans Petter Selasky.Sh CREATING ROOT NODES 6805eb1caa8SHans Petter SelaskySysctl MIBs or OIDs are created in a hierarchical tree. 6815eb1caa8SHans Petter SelaskyThe nodes at the bottom of the tree are called root nodes, and have no 6825eb1caa8SHans Petter Selaskyparent OID. 6835eb1caa8SHans Petter SelaskyTo create bottom tree nodes the 6845eb1caa8SHans Petter Selasky.Fn SYSCTL_ROOT_NODE 6855eb1caa8SHans Petter Selaskymacro or the 6865eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_ROOT_NODE 6875eb1caa8SHans Petter Selaskyfunction needs to be used. 6885eb1caa8SHans Petter SelaskyBy default all static sysctl node OIDs are global and need a 6895eb1caa8SHans Petter Selasky.Fn SYSCTL_DECL 6905eb1caa8SHans Petter Selaskystatement prior to their 6915eb1caa8SHans Petter Selasky.Fn SYSCTL_NODE 6925eb1caa8SHans Petter Selaskydefinition statement, typically in a so-called header file. 6935eb1caa8SHans Petter Selasky.Sh CREATING SYSCTL STRINGS 6945eb1caa8SHans Petter SelaskyZero terminated character strings sysctls are created either using the 6955eb1caa8SHans Petter Selasky.Fn SYSCTL_STRING 6965eb1caa8SHans Petter Selaskymacro or the 6975eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_STRING 6985eb1caa8SHans Petter Selaskyfunction. 6995eb1caa8SHans Petter SelaskyIf the 7005eb1caa8SHans Petter Selasky.Fa len 7015eb1caa8SHans Petter Selaskyargument in zero, the string length is computed at every access to the OID using 7025eb1caa8SHans Petter Selasky.Xr strlen 3 . 70310a1e981SEric JoynerUse the 70410a1e981SEric Joyner.Fn SYSCTL_CONST_STRING 70510a1e981SEric Joynermacro or the 70610a1e981SEric Joyner.Fn SYSCTL_ADD_CONST_STRING 70710a1e981SEric Joynerfunction to add a sysctl for a constant string. 7085eb1caa8SHans Petter Selasky.Sh CREATING OPAQUE SYSCTLS 7095eb1caa8SHans Petter SelaskyThe 7105eb1caa8SHans Petter Selasky.Fn SYSCTL_OPAQUE 7115eb1caa8SHans Petter Selaskyor 7125eb1caa8SHans Petter Selasky.Fn SYSCTL_STRUCT 7135eb1caa8SHans Petter Selaskymacros or the 7145eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_OPAQUE 7155eb1caa8SHans Petter Selaskyor 7165eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_STRUCT 7175eb1caa8SHans Petter Selaskyfunctions create an OID that handle any chunk of data 7185eb1caa8SHans Petter Selaskyof the size specified by the 7195eb1caa8SHans Petter Selasky.Fa len 7205eb1caa8SHans Petter Selaskyargument and data pointed to by the 7215eb1caa8SHans Petter Selasky.Fa ptr 7225eb1caa8SHans Petter Selaskyargument. 7235eb1caa8SHans Petter SelaskyWhen using the structure version the type is encoded as part of the 7245eb1caa8SHans Petter Selaskycreated sysctl. 7255eb1caa8SHans Petter Selasky.Sh CREATING CUSTOM SYSCTLS 7265eb1caa8SHans Petter SelaskyThe 7275eb1caa8SHans Petter Selasky.Fn SYSCTL_PROC 7285eb1caa8SHans Petter Selaskymacro and the 7295eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_PROC 7305eb1caa8SHans Petter Selaskyfunction 7315eb1caa8SHans Petter Selaskycreate OIDs with the specified 7325eb1caa8SHans Petter Selasky.Pa handler 7335eb1caa8SHans Petter Selaskyfunction. 7345eb1caa8SHans Petter SelaskyThe handler is responsible for handling all read and write requests to 7355eb1caa8SHans Petter Selaskythe OID. 7365eb1caa8SHans Petter SelaskyThis OID type is especially useful if the kernel data is not easily 7375eb1caa8SHans Petter Selaskyaccessible, or needs to be processed before exporting. 7385eb1caa8SHans Petter Selasky.Sh CREATING A STATIC SYSCTL 7395eb1caa8SHans Petter SelaskyStatic sysctls are declared using one of the 7409a593520SMateusz Piotrowski.Fn SYSCTL_BOOL , 7419a593520SMateusz Piotrowski.Fn SYSCTL_COUNTER_U64 , 7429a593520SMateusz Piotrowski.Fn SYSCTL_COUNTER_U64_ARRAY , 743bd84dd2fSRuslan Ermilov.Fn SYSCTL_INT , 7441e1f3941SEd Schouten.Fn SYSCTL_INT_WITH_LABEL , 745bd84dd2fSRuslan Ermilov.Fn SYSCTL_LONG , 746bd84dd2fSRuslan Ermilov.Fn SYSCTL_NODE , 7471e1f3941SEd Schouten.Fn SYSCTL_NODE_WITH_LABEL , 748bd84dd2fSRuslan Ermilov.Fn SYSCTL_OPAQUE , 749bd84dd2fSRuslan Ermilov.Fn SYSCTL_PROC , 75060a77442SJohn Baldwin.Fn SYSCTL_QUAD , 7515eb1caa8SHans Petter Selasky.Fn SYSCTL_ROOT_NODE , 752be87839eSConrad Meyer.Fn SYSCTL_S8 , 753be87839eSConrad Meyer.Fn SYSCTL_S16 , 754be87839eSConrad Meyer.Fn SYSCTL_S32 , 755be87839eSConrad Meyer.Fn SYSCTL_S64 , 7569a593520SMateusz Piotrowski.Fn SYSCTL_SBINTIME_MSEC , 7579a593520SMateusz Piotrowski.Fn SYSCTL_SBINTIME_USEC , 758bd84dd2fSRuslan Ermilov.Fn SYSCTL_STRING , 75910a1e981SEric Joyner.Fn SYSCTL_CONST_STRING , 760bd84dd2fSRuslan Ermilov.Fn SYSCTL_STRUCT , 7610f702183SJohn Baldwin.Fn SYSCTL_TIMEVAL_SEC , 762fb61390cSConrad Meyer.Fn SYSCTL_U8 , 763fb61390cSConrad Meyer.Fn SYSCTL_U16 , 764be87839eSConrad Meyer.Fn SYSCTL_U32 , 765be87839eSConrad Meyer.Fn SYSCTL_U64 , 766bd84dd2fSRuslan Ermilov.Fn SYSCTL_UINT , 7679a593520SMateusz Piotrowski.Fn SYSCTL_ULONG , 7689a593520SMateusz Piotrowski.Fn SYSCTL_UQUAD , 7699a593520SMateusz Piotrowski.Fn SYSCTL_UMA_CUR 7705eb1caa8SHans Petter Selaskyor 7719a593520SMateusz Piotrowski.Fn SYSCTL_UMA_MAX 7725eb1caa8SHans Petter Selaskymacros. 7735eb1caa8SHans Petter Selasky.Sh CREATING A DYNAMIC SYSCTL 7745eb1caa8SHans Petter SelaskyDynamic nodes are created using one of the 7759a593520SMateusz Piotrowski.Fn SYSCTL_ADD_BOOL , 7769a593520SMateusz Piotrowski.Fn SYSCTL_ADD_COUNTER_U64 , 7779a593520SMateusz Piotrowski.Fn SYSCTL_ADD_COUNTER_U64_ARRAY , 7785eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_INT , 7795eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_LONG , 7805eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_NODE , 7811e1f3941SEd Schouten.Fn SYSCTL_ADD_NODE_WITH_LABEL , 7825eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_OPAQUE , 7835eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_PROC , 7845eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_QUAD , 7855eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_ROOT_NODE , 786be87839eSConrad Meyer.Fn SYSCTL_ADD_S8 , 787be87839eSConrad Meyer.Fn SYSCTL_ADD_S16 , 788be87839eSConrad Meyer.Fn SYSCTL_ADD_S32 , 789be87839eSConrad Meyer.Fn SYSCTL_ADD_S64 , 7909a593520SMateusz Piotrowski.Fn SYSCTL_ADD_SBINTIME_MSEC , 7919a593520SMateusz Piotrowski.Fn SYSCTL_ADD_SBINTIME_USEC , 7925eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_STRING , 79310a1e981SEric Joyner.Fn SYSCTL_ADD_CONST_STRING , 7945eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_STRUCT , 7950f702183SJohn Baldwin.Fn SYSCTL_ADD_TIMEVAL_SEC , 796fb61390cSConrad Meyer.Fn SYSCTL_ADD_U8 , 797fb61390cSConrad Meyer.Fn SYSCTL_ADD_U16 , 798be87839eSConrad Meyer.Fn SYSCTL_ADD_U32 , 799be87839eSConrad Meyer.Fn SYSCTL_ADD_U64 , 800f0188618SHans Petter Selasky.Fn SYSCTL_ADD_UAUTO , 8015eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_UINT , 802f0188618SHans Petter Selasky.Fn SYSCTL_ADD_ULONG , 8039a593520SMateusz Piotrowski.Fn SYSCTL_ADD_UQUAD , 8049a593520SMateusz Piotrowski.Fn SYSCTL_ADD_UMA_CUR 8055eb1caa8SHans Petter Selaskyor 8069a593520SMateusz Piotrowski.Fn SYSCTL_ADD_UMA_MAX 8075eb1caa8SHans Petter Selaskyfunctions. 8085eb1caa8SHans Petter SelaskySee 8095eb1caa8SHans Petter Selasky.Xr sysctl_remove_oid 9 8105eb1caa8SHans Petter Selaskyor 8115eb1caa8SHans Petter Selasky.Xr sysctl_ctx_free 9 8125eb1caa8SHans Petter Selaskyfor more information on how to destroy a dynamically created OID. 8135eb1caa8SHans Petter Selasky.Sh CONTROL FLAGS 8145eb1caa8SHans Petter SelaskyFor most of the above functions and macros, declaring a type as part 8155eb1caa8SHans Petter Selaskyof the access flags is not necessary \[em] however, when declaring a 8165eb1caa8SHans Petter Selaskysysctl implemented by a function, including a type in the access mask 8175eb1caa8SHans Petter Selaskyis required: 8185eb1caa8SHans Petter Selasky.Bl -tag -width ".Dv CTLTYPE_NOFETCH" 819dba9e9ccSRobert Watson.It Dv CTLTYPE_NODE 820dba9e9ccSRobert WatsonThis is a node intended to be a parent for other nodes. 821dba9e9ccSRobert Watson.It Dv CTLTYPE_INT 822dba9e9ccSRobert WatsonThis is a signed integer. 823dba9e9ccSRobert Watson.It Dv CTLTYPE_STRING 824dba9e9ccSRobert WatsonThis is a nul-terminated string stored in a character array. 825be87839eSConrad Meyer.It Dv CTLTYPE_S8 826be87839eSConrad MeyerThis is an 8-bit signed integer. 827be87839eSConrad Meyer.It Dv CTLTYPE_S16 828be87839eSConrad MeyerThis is a 16-bit signed integer. 829be87839eSConrad Meyer.It Dv CTLTYPE_S32 830be87839eSConrad MeyerThis is a 32-bit signed integer. 831cbc134adSMatthew D Fleming.It Dv CTLTYPE_S64 832dba9e9ccSRobert WatsonThis is a 64-bit signed integer. 833dba9e9ccSRobert Watson.It Dv CTLTYPE_OPAQUE 834dba9e9ccSRobert WatsonThis is an opaque data structure. 835dba9e9ccSRobert Watson.It Dv CTLTYPE_STRUCT 836dba9e9ccSRobert WatsonAlias for 837dba9e9ccSRobert Watson.Dv CTLTYPE_OPAQUE . 838fb61390cSConrad Meyer.It Dv CTLTYPE_U8 839fb61390cSConrad MeyerThis is an 8-bit unsigned integer. 840fb61390cSConrad Meyer.It Dv CTLTYPE_U16 841fb61390cSConrad MeyerThis is a 16-bit unsigned integer. 842be87839eSConrad Meyer.It Dv CTLTYPE_U32 843be87839eSConrad MeyerThis is a 32-bit unsigned integer. 844be87839eSConrad Meyer.It Dv CTLTYPE_U64 845be87839eSConrad MeyerThis is a 64-bit unsigned integer. 846dba9e9ccSRobert Watson.It Dv CTLTYPE_UINT 847dba9e9ccSRobert WatsonThis is an unsigned integer. 848dba9e9ccSRobert Watson.It Dv CTLTYPE_LONG 849dba9e9ccSRobert WatsonThis is a signed long. 850dba9e9ccSRobert Watson.It Dv CTLTYPE_ULONG 8518a1f4129SRobert WatsonThis is an unsigned long. 852dba9e9ccSRobert Watson.El 853dba9e9ccSRobert Watson.Pp 85460a77442SJohn BaldwinAll sysctl types except for new node declarations require one of the following 85560a77442SJohn Baldwinflags to be set indicating the read and write disposition of the sysctl: 856bd84dd2fSRuslan Ermilov.Bl -tag -width ".Dv CTLFLAG_ANYBODY" 857dba9e9ccSRobert Watson.It Dv CTLFLAG_RD 858dba9e9ccSRobert WatsonThis is a read-only sysctl. 85960a77442SJohn Baldwin.It Dv CTLFLAG_RDTUN 8605eb1caa8SHans Petter SelaskyThis is a read-only sysctl and tunable which is tried fetched once 8617c64ddd5SWarren Blockfrom the system environment early during module load or system boot. 862b470b929SDavid E. O'Brien.It Dv CTLFLAG_WR 863dba9e9ccSRobert WatsonThis is a writable sysctl. 864dba9e9ccSRobert Watson.It Dv CTLFLAG_RW 865dba9e9ccSRobert WatsonThis sysctl is readable and writable. 86660a77442SJohn Baldwin.It Dv CTLFLAG_RWTUN 8675eb1caa8SHans Petter SelaskyThis is a readable and writeable sysctl and tunable which is tried 8687c64ddd5SWarren Blockfetched once from the system environment early during module load or 8695eb1caa8SHans Petter Selaskysystem boot. 8705eb1caa8SHans Petter Selasky.It Dv CTLFLAG_NOFETCH 8715eb1caa8SHans Petter SelaskyIn case the node is marked as a tunable using the CTLFLAG_[XX]TUN, 8725eb1caa8SHans Petter Selaskythis flag will prevent fetching the initial value from the system 8737851d429SEdward Tomasz Napieralaenvironment. 8747851d429SEdward Tomasz NapieralaTypically this flag should only be used for very early 8755eb1caa8SHans Petter Selaskylow level system setup code, and not by common drivers and modules. 876982a973eSWarner Losh.It Dv CTLFLAG_MPSAFE 877982a973eSWarner LoshThis 878982a973eSWarner Losh.Xr sysctl 9 879982a973eSWarner Loshhandler is MP safe. 880982a973eSWarner LoshDo not grab Giant around calls to this handler. 881d132d4caSWarner LoshThis should only be used for 882d132d4caSWarner Losh.Fn SYSCTL_PROC 883d132d4caSWarner Loshentries. 88460a77442SJohn Baldwin.El 88560a77442SJohn Baldwin.Pp 88660a77442SJohn BaldwinAdditionally, any of the following optional flags may also be specified: 88760a77442SJohn Baldwin.Bl -tag -width ".Dv CTLFLAG_ANYBODY" 888dba9e9ccSRobert Watson.It Dv CTLFLAG_ANYBODY 889dba9e9ccSRobert WatsonAny user or process can write to this sysctl. 890e3127092SEd Maste.It Dv CTLFLAG_CAPRD 891e3127092SEd MasteA process in capability mode can read from this sysctl. 892e3127092SEd Maste.It Dv CTLFLAG_CAPWR 893e3127092SEd MasteA process in capability mode can write to this sysctl. 894dba9e9ccSRobert Watson.It Dv CTLFLAG_SECURE 895dba9e9ccSRobert WatsonThis sysctl can be written to only if the effective securelevel of the 896bd84dd2fSRuslan Ermilovprocess is \[<=] 0. 897dba9e9ccSRobert Watson.It Dv CTLFLAG_PRISON 898dba9e9ccSRobert WatsonThis sysctl can be written to by processes in 899dba9e9ccSRobert Watson.Xr jail 2 . 900dba9e9ccSRobert Watson.It Dv CTLFLAG_SKIP 901dba9e9ccSRobert WatsonWhen iterating the sysctl name space, do not list this sysctl. 902dba9e9ccSRobert Watson.It Dv CTLFLAG_TUN 9036b9597aaSAndrew ThompsonAdvisory flag that a system tunable also exists for this variable. 9045eb1caa8SHans Petter SelaskyThe initial sysctl value is tried fetched once from the system 9057c64ddd5SWarren Blockenvironment early during module load or system boot. 9065eb1caa8SHans Petter Selasky.It Dv CTLFLAG_DYN 9075eb1caa8SHans Petter SelaskyDynamically created OIDs automatically get this flag set. 90856538e4aSGleb Smirnoff.It Dv CTLFLAG_VNET 90956538e4aSGleb SmirnoffOID references a VIMAGE-enabled variable. 910dba9e9ccSRobert Watson.El 911dba9e9ccSRobert Watson.Sh EXAMPLES 912dba9e9ccSRobert WatsonSample use of 913bd84dd2fSRuslan Ermilov.Fn SYSCTL_DECL 914bd84dd2fSRuslan Ermilovto declare the 915bd84dd2fSRuslan Ermilov.Va security 916bd84dd2fSRuslan Ermilovsysctl tree for use by new nodes: 917dba9e9ccSRobert Watson.Bd -literal -offset indent 918dba9e9ccSRobert WatsonSYSCTL_DECL(_security); 919dba9e9ccSRobert Watson.Ed 920dba9e9ccSRobert Watson.Pp 921dba9e9ccSRobert WatsonExamples of integer, opaque, string, and procedure sysctls follow: 922dba9e9ccSRobert Watson.Bd -literal -offset indent 923dba9e9ccSRobert Watson/* 924dba9e9ccSRobert Watson * Example of a constant integer value. Notice that the control 925f0188618SHans Petter Selasky * flags are CTLFLAG_RD, the variable pointer is SYSCTL_NULL_INT_PTR, 926f0188618SHans Petter Selasky * and the value is declared. 927dba9e9ccSRobert Watson */ 928f0188618SHans Petter SelaskySYSCTL_INT(_debug_sizeof, OID_AUTO, bio, CTLFLAG_RD, SYSCTL_NULL_INT_PTR, 929dba9e9ccSRobert Watson sizeof(struct bio), "sizeof(struct bio)"); 930dba9e9ccSRobert Watson 931dba9e9ccSRobert Watson/* 932dba9e9ccSRobert Watson * Example of a variable integer value. Notice that the control 933dba9e9ccSRobert Watson * flags are CTLFLAG_RW, the variable pointer is set, and the 934dba9e9ccSRobert Watson * value is 0. 935dba9e9ccSRobert Watson */ 936dba9e9ccSRobert Watsonstatic int doingcache = 1; /* 1 => enable the cache */ 937dba9e9ccSRobert WatsonSYSCTL_INT(_debug, OID_AUTO, vfscache, CTLFLAG_RW, &doingcache, 0, 938dba9e9ccSRobert Watson "Enable name cache"); 939dba9e9ccSRobert Watson 940dba9e9ccSRobert Watson/* 941dba9e9ccSRobert Watson * Example of a variable string value. Notice that the control 942dba9e9ccSRobert Watson * flags are CTLFLAG_RW, that the variable pointer and string 943dba9e9ccSRobert Watson * size are set. Unlike newer sysctls, this older sysctl uses a 944dba9e9ccSRobert Watson * static oid number. 945dba9e9ccSRobert Watson */ 946dba9e9ccSRobert Watsonchar kernelname[MAXPATHLEN] = "/kernel"; /* XXX bloat */ 947dba9e9ccSRobert WatsonSYSCTL_STRING(_kern, KERN_BOOTFILE, bootfile, CTLFLAG_RW, 948dba9e9ccSRobert Watson kernelname, sizeof(kernelname), "Name of kernel file booted"); 949dba9e9ccSRobert Watson 950dba9e9ccSRobert Watson/* 951dba9e9ccSRobert Watson * Example of an opaque data type exported by sysctl. Notice that 952dba9e9ccSRobert Watson * the variable pointer and size are provided, as well as a format 953dba9e9ccSRobert Watson * string for sysctl(8). 954dba9e9ccSRobert Watson */ 9557c64ddd5SWarren Blockstatic l_fp pps_freq; /* scaled frequency offset (ns/s) */ 956dba9e9ccSRobert WatsonSYSCTL_OPAQUE(_kern_ntp_pll, OID_AUTO, pps_freq, CTLFLAG_RD, 957dba9e9ccSRobert Watson &pps_freq, sizeof(pps_freq), "I", ""); 958dba9e9ccSRobert Watson 959dba9e9ccSRobert Watson/* 960dba9e9ccSRobert Watson * Example of a procedure based sysctl exporting string 961dba9e9ccSRobert Watson * information. Notice that the data type is declared, the NULL 962dba9e9ccSRobert Watson * variable pointer and 0 size, the function pointer, and the 963dba9e9ccSRobert Watson * format string for sysctl(8). 964dba9e9ccSRobert Watson */ 965dba9e9ccSRobert WatsonSYSCTL_PROC(_kern_timecounter, OID_AUTO, hardware, CTLTYPE_STRING | 966dba9e9ccSRobert Watson CTLFLAG_RW, NULL, 0, sysctl_kern_timecounter_hardware, "A", 967dba9e9ccSRobert Watson ""); 968dba9e9ccSRobert Watson.Ed 9695eb1caa8SHans Petter Selasky.Pp 9705eb1caa8SHans Petter SelaskyThe following is an example of 9715eb1caa8SHans Petter Selaskyhow to create a new top-level category 9725eb1caa8SHans Petter Selaskyand how to hook up another subtree to an existing static node. 9735eb1caa8SHans Petter SelaskyThis example does not use contexts, 9745eb1caa8SHans Petter Selaskywhich results in tedious management of all intermediate oids, 9755eb1caa8SHans Petter Selaskyas they need to be freed later on: 9765eb1caa8SHans Petter Selasky.Bd -literal -offset indent 9775eb1caa8SHans Petter Selasky#include <sys/sysctl.h> 9785eb1caa8SHans Petter Selasky ... 9795eb1caa8SHans Petter Selasky/* 9805eb1caa8SHans Petter Selasky * Need to preserve pointers to newly created subtrees, 9815eb1caa8SHans Petter Selasky * to be able to free them later: 9825eb1caa8SHans Petter Selasky */ 9835eb1caa8SHans Petter Selaskystatic struct sysctl_oid *root1; 9845eb1caa8SHans Petter Selaskystatic struct sysctl_oid *root2; 9855eb1caa8SHans Petter Selaskystatic struct sysctl_oid *oidp; 9865eb1caa8SHans Petter Selaskystatic int a_int; 9875eb1caa8SHans Petter Selaskystatic char *string = "dynamic sysctl"; 9885eb1caa8SHans Petter Selasky ... 9895eb1caa8SHans Petter Selasky 9905eb1caa8SHans Petter Selaskyroot1 = SYSCTL_ADD_ROOT_NODE(NULL, 9915eb1caa8SHans Petter Selasky OID_AUTO, "newtree", CTLFLAG_RW, 0, "new top level tree"); 9925eb1caa8SHans Petter Selaskyoidp = SYSCTL_ADD_INT(NULL, SYSCTL_CHILDREN(root1), 9935eb1caa8SHans Petter Selasky OID_AUTO, "newint", CTLFLAG_RW, &a_int, 0, "new int leaf"); 9945eb1caa8SHans Petter Selasky ... 9955eb1caa8SHans Petter Selaskyroot2 = SYSCTL_ADD_NODE(NULL, SYSCTL_STATIC_CHILDREN(_debug), 9965eb1caa8SHans Petter Selasky OID_AUTO, "newtree", CTLFLAG_RW, 0, "new tree under debug"); 9975eb1caa8SHans Petter Selaskyoidp = SYSCTL_ADD_STRING(NULL, SYSCTL_CHILDREN(root2), 9985eb1caa8SHans Petter Selasky OID_AUTO, "newstring", CTLFLAG_RD, string, 0, "new string leaf"); 9995eb1caa8SHans Petter Selasky.Ed 10005eb1caa8SHans Petter Selasky.Pp 10015eb1caa8SHans Petter SelaskyThis example creates the following subtrees: 10025eb1caa8SHans Petter Selasky.Bd -literal -offset indent 10035eb1caa8SHans Petter Selaskydebug.newtree.newstring 10045eb1caa8SHans Petter Selaskynewtree.newint 10055eb1caa8SHans Petter Selasky.Ed 10065eb1caa8SHans Petter Selasky.Pp 10075eb1caa8SHans Petter Selasky.Em "Care should be taken to free all OIDs once they are no longer needed!" 100891f3a6dbSYaroslav Tykhiy.Sh SYSCTL NAMING 1009dba9e9ccSRobert WatsonWhen adding, modifying, or removing sysctl names, it is important to be 1010dba9e9ccSRobert Watsonaware that these interfaces may be used by users, libraries, applications, 1011f4006affSGiorgos Keramidasor documentation (such as published books), and are implicitly published application interfaces. 1012dba9e9ccSRobert WatsonAs with other application interfaces, caution must be taken not to break 1013dba9e9ccSRobert Watsonexisting applications, and to think about future use of new name spaces so as 1014dba9e9ccSRobert Watsonto avoid the need to rename or remove interfaces that might be depended on in 1015dba9e9ccSRobert Watsonthe future. 101691f3a6dbSYaroslav Tykhiy.Pp 101791f3a6dbSYaroslav TykhiyThe semantics chosen for a new sysctl should be as clear as possible, 101891f3a6dbSYaroslav Tykhiyand the name of the sysctl must closely reflect its semantics. 101991f3a6dbSYaroslav TykhiyTherefore the sysctl name deserves a fair amount of consideration. 102091f3a6dbSYaroslav TykhiyIt should be short but yet representative of the sysctl meaning. 102191f3a6dbSYaroslav TykhiyIf the name consists of several words, they should be separated by 102291f3a6dbSYaroslav Tykhiyunderscore characters, as in 102391f3a6dbSYaroslav Tykhiy.Va compute_summary_at_mount . 102491f3a6dbSYaroslav TykhiyUnderscore characters may be omitted only if the name consists of not more 102591f3a6dbSYaroslav Tykhiythan two words, each being not longer than four characters, as in 102691f3a6dbSYaroslav Tykhiy.Va bootfile . 102791f3a6dbSYaroslav TykhiyFor boolean sysctls, negative logic should be totally avoided. 102891f3a6dbSYaroslav TykhiyThat is, do not use names like 102991f3a6dbSYaroslav Tykhiy.Va no_foobar 103091f3a6dbSYaroslav Tykhiyor 103191f3a6dbSYaroslav Tykhiy.Va foobar_disable . 103291f3a6dbSYaroslav TykhiyThey are confusing and lead to configuration errors. 103391f3a6dbSYaroslav TykhiyUse positive logic instead: 103491f3a6dbSYaroslav Tykhiy.Va foobar , 103591f3a6dbSYaroslav Tykhiy.Va foobar_enable . 103691f3a6dbSYaroslav Tykhiy.Pp 10375eb1caa8SHans Petter SelaskyA temporary sysctl node OID that should not be relied upon must be designated 10387851d429SEdward Tomasz Napieralaas such by a leading underscore character in its name. 10397851d429SEdward Tomasz NapieralaFor example: 104091f3a6dbSYaroslav Tykhiy.Va _dirty_hack . 1041dba9e9ccSRobert Watson.Sh SEE ALSO 1042f3066f2bSGavin Atkinson.Xr sysctl 3 , 1043dba9e9ccSRobert Watson.Xr sysctl 8 , 1044*df94ce0fSJohn-Mark Gurney.Xr device_get_sysctl 9 , 1045dba9e9ccSRobert Watson.Xr sysctl_add_oid 9 , 1046dba9e9ccSRobert Watson.Xr sysctl_ctx_free 9 , 1047dba9e9ccSRobert Watson.Xr sysctl_ctx_init 9 , 1048dba9e9ccSRobert Watson.Xr sysctl_remove_oid 9 1049dba9e9ccSRobert Watson.Sh HISTORY 1050bd84dd2fSRuslan ErmilovThe 1051dba9e9ccSRobert Watson.Xr sysctl 8 1052bd84dd2fSRuslan Ermilovutility first appeared in 1053dba9e9ccSRobert Watson.Bx 4.4 . 1054dba9e9ccSRobert Watson.Sh AUTHORS 1055bd84dd2fSRuslan Ermilov.An -nosplit 1056bd84dd2fSRuslan ErmilovThe 1057bd84dd2fSRuslan Ermilov.Nm sysctl 1058bd84dd2fSRuslan Ermilovimplementation originally found in 1059dba9e9ccSRobert Watson.Bx 1060dba9e9ccSRobert Watsonhas been extensively rewritten by 1061dba9e9ccSRobert Watson.An Poul-Henning Kamp 1062dba9e9ccSRobert Watsonin order to add support for name lookups, name space iteration, and dynamic 1063dba9e9ccSRobert Watsonaddition of MIB nodes. 1064dba9e9ccSRobert Watson.Pp 1065dba9e9ccSRobert WatsonThis man page was written by 1066dba9e9ccSRobert Watson.An Robert N. M. Watson . 10673edc2b53SJoel Dahl.Sh SECURITY CONSIDERATIONS 10683edc2b53SJoel DahlWhen creating new sysctls, careful attention should be paid to the security 10693edc2b53SJoel Dahlimplications of the monitoring or management interface being created. 10703edc2b53SJoel DahlMost sysctls present in the kernel are read-only or writable only by the 10713edc2b53SJoel Dahlsuperuser. 10723edc2b53SJoel DahlSysctls exporting extensive information on system data structures and 10733edc2b53SJoel Dahloperation, especially those implemented using procedures, will wish to 10743edc2b53SJoel Dahlimplement access control to limit the undesired exposure of information about 10753edc2b53SJoel Dahlother processes, network connections, etc. 10763edc2b53SJoel Dahl.Pp 10773edc2b53SJoel DahlThe following top level sysctl name spaces are commonly used: 10783edc2b53SJoel Dahl.Bl -tag -width ".Va regression" 10793edc2b53SJoel Dahl.It Va compat 10803edc2b53SJoel DahlCompatibility layer information. 10813edc2b53SJoel Dahl.It Va debug 10823edc2b53SJoel DahlDebugging information. 10833edc2b53SJoel DahlVarious name spaces exist under 10843edc2b53SJoel Dahl.Va debug . 10853edc2b53SJoel Dahl.It Va hw 10863edc2b53SJoel DahlHardware and device driver information. 10873edc2b53SJoel Dahl.It Va kern 10883edc2b53SJoel DahlKernel behavior tuning; generally deprecated in favor of more specific 10893edc2b53SJoel Dahlname spaces. 10903edc2b53SJoel Dahl.It Va machdep 10913edc2b53SJoel DahlMachine-dependent configuration parameters. 10923edc2b53SJoel Dahl.It Va net 10933edc2b53SJoel DahlNetwork subsystem. 10943edc2b53SJoel DahlVarious protocols have name spaces under 10953edc2b53SJoel Dahl.Va net . 10963edc2b53SJoel Dahl.It Va regression 10973edc2b53SJoel DahlRegression test configuration and information. 10983edc2b53SJoel Dahl.It Va security 10993edc2b53SJoel DahlSecurity and security-policy configuration and information. 11003edc2b53SJoel Dahl.It Va sysctl 11013edc2b53SJoel DahlReserved name space for the implementation of sysctl. 11023edc2b53SJoel Dahl.It Va user 11033edc2b53SJoel DahlConfiguration settings relating to user application behavior. 11043edc2b53SJoel DahlGenerally, configuring applications using kernel sysctls is discouraged. 11053edc2b53SJoel Dahl.It Va vfs 11063edc2b53SJoel DahlVirtual file system configuration and information. 11073edc2b53SJoel Dahl.It Va vm 11083edc2b53SJoel DahlVirtual memory subsystem configuration and information. 11093edc2b53SJoel Dahl.El 1110