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.\" 26df94ce0fSJohn-Mark Gurney.Dd September 1, 2020 27dba9e9ccSRobert Watson.Dt SYSCTL 9 28dba9e9ccSRobert Watson.Os 29dba9e9ccSRobert Watson.Sh NAME 30dba9e9ccSRobert Watson.Nm SYSCTL_DECL , 319a593520SMateusz Piotrowski.Nm SYSCTL_ADD_BOOL , 329a593520SMateusz Piotrowski.Nm SYSCTL_ADD_COUNTER_U64 , 339a593520SMateusz Piotrowski.Nm SYSCTL_ADD_COUNTER_U64_ARRAY , 345eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_INT , 355eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_LONG , 365eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_NODE , 371e1f3941SEd Schouten.Nm SYSCTL_ADD_NODE_WITH_LABEL , 385eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_OPAQUE , 395eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_PROC , 405eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_QUAD , 415eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_ROOT_NODE , 42be87839eSConrad Meyer.Nm SYSCTL_ADD_S8 , 43be87839eSConrad Meyer.Nm SYSCTL_ADD_S16 , 44be87839eSConrad Meyer.Nm SYSCTL_ADD_S32 , 45be87839eSConrad Meyer.Nm SYSCTL_ADD_S64 , 469a593520SMateusz Piotrowski.Nm SYSCTL_ADD_SBINTIME_MSEC , 479a593520SMateusz Piotrowski.Nm SYSCTL_ADD_SBINTIME_USEC , 485eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_STRING , 4910a1e981SEric Joyner.Nm SYSCTL_ADD_CONST_STRING , 505eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_STRUCT , 510f702183SJohn Baldwin.Nm SYSCTL_ADD_TIMEVAL_SEC , 52fb61390cSConrad Meyer.Nm SYSCTL_ADD_U8 , 53fb61390cSConrad Meyer.Nm SYSCTL_ADD_U16 , 54be87839eSConrad Meyer.Nm SYSCTL_ADD_U32 , 55be87839eSConrad Meyer.Nm SYSCTL_ADD_U64 , 56f0188618SHans Petter Selasky.Nm SYSCTL_ADD_UAUTO , 575eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_UINT , 585eb1caa8SHans Petter Selasky.Nm SYSCTL_ADD_ULONG , 599a593520SMateusz Piotrowski.Nm SYSCTL_ADD_UMA_CUR , 609a593520SMateusz Piotrowski.Nm SYSCTL_ADD_UMA_MAX , 61f04020edSMateusz Piotrowski.Nm SYSCTL_ADD_UQUAD , 625eb1caa8SHans Petter Selasky.Nm SYSCTL_CHILDREN , 635eb1caa8SHans Petter Selasky.Nm SYSCTL_STATIC_CHILDREN , 645eb1caa8SHans Petter Selasky.Nm SYSCTL_NODE_CHILDREN , 655eb1caa8SHans Petter Selasky.Nm SYSCTL_PARENT , 669a593520SMateusz Piotrowski.Nm SYSCTL_BOOL , 679a593520SMateusz Piotrowski.Nm SYSCTL_COUNTER_U64 , 689a593520SMateusz Piotrowski.Nm SYSCTL_COUNTER_U64_ARRAY , 69dba9e9ccSRobert Watson.Nm SYSCTL_INT , 701e1f3941SEd Schouten.Nm SYSCTL_INT_WITH_LABEL , 71dba9e9ccSRobert Watson.Nm SYSCTL_LONG , 72574b98cbSJohn Baldwin.Nm sysctl_msec_to_ticks , 73dba9e9ccSRobert Watson.Nm SYSCTL_NODE , 741e1f3941SEd Schouten.Nm SYSCTL_NODE_WITH_LABEL , 75dba9e9ccSRobert Watson.Nm SYSCTL_OPAQUE , 76dba9e9ccSRobert Watson.Nm SYSCTL_PROC , 7760a77442SJohn Baldwin.Nm SYSCTL_QUAD , 785eb1caa8SHans Petter Selasky.Nm SYSCTL_ROOT_NODE , 79be87839eSConrad Meyer.Nm SYSCTL_S8 , 80be87839eSConrad Meyer.Nm SYSCTL_S16 , 81be87839eSConrad Meyer.Nm SYSCTL_S32 , 82be87839eSConrad Meyer.Nm SYSCTL_S64 , 839a593520SMateusz Piotrowski.Nm SYSCTL_SBINTIME_MSEC , 849a593520SMateusz Piotrowski.Nm SYSCTL_SBINTIME_USEC , 85dba9e9ccSRobert Watson.Nm SYSCTL_STRING , 8610a1e981SEric Joyner.Nm SYSCTL_CONST_STRING , 87dba9e9ccSRobert Watson.Nm SYSCTL_STRUCT , 880f702183SJohn Baldwin.Nm SYSCTL_TIMEVAL_SEC , 89fb61390cSConrad Meyer.Nm SYSCTL_U8 , 90fb61390cSConrad Meyer.Nm SYSCTL_U16 , 91be87839eSConrad Meyer.Nm SYSCTL_U32 , 92be87839eSConrad Meyer.Nm SYSCTL_U64 , 93dba9e9ccSRobert Watson.Nm SYSCTL_UINT , 94c157a036SDavid E. O'Brien.Nm SYSCTL_ULONG , 959a593520SMateusz Piotrowski.Nm SYSCTL_UMA_CUR , 96bb0358d4SGordon Bergling.Nm SYSCTL_UMA_MAX , 97bb0358d4SGordon Bergling.Nm SYSCTL_UQUAD 985eb1caa8SHans Petter Selasky.Nd Dynamic and static sysctl MIB creation functions 99dba9e9ccSRobert Watson.Sh SYNOPSIS 100651a7908SJonathan T. Looney.In sys/param.h 101dba9e9ccSRobert Watson.In sys/sysctl.h 102bd84dd2fSRuslan Ermilov.Fn SYSCTL_DECL name 1035eb1caa8SHans Petter Selasky.Ft struct sysctl_oid * 1049a593520SMateusz Piotrowski.Fo SYSCTL_ADD_BOOL 1059a593520SMateusz Piotrowski.Fa "struct sysctl_ctx_list *ctx" 1069a593520SMateusz Piotrowski.Fa "struct sysctl_oid_list *parent" 1079a593520SMateusz Piotrowski.Fa "int number" 1089a593520SMateusz Piotrowski.Fa "const char *name" 1099a593520SMateusz Piotrowski.Fa "int ctlflags" 1109a593520SMateusz Piotrowski.Fa "bool *ptr" 1119a593520SMateusz Piotrowski.Fa "uint8_t val" 1129a593520SMateusz Piotrowski.Fa "const char *descr" 1139a593520SMateusz Piotrowski.Fc 1149a593520SMateusz Piotrowski.Ft struct sysctl_oid * 1159a593520SMateusz Piotrowski.Fo SYSCTL_ADD_COUNTER_U64 1169a593520SMateusz Piotrowski.Fa "struct sysctl_ctx_list *ctx" 1179a593520SMateusz Piotrowski.Fa "struct sysctl_oid_list *parent" 1189a593520SMateusz Piotrowski.Fa "int number" 1199a593520SMateusz Piotrowski.Fa "const char *name" 1209a593520SMateusz Piotrowski.Fa "int ctlflags" 1219a593520SMateusz Piotrowski.Fa "counter_u64_t *ptr" 1229a593520SMateusz Piotrowski.Fa "const char *descr" 1239a593520SMateusz Piotrowski.Fc 1249a593520SMateusz Piotrowski.Ft struct sysctl_oid * 1259a593520SMateusz Piotrowski.Fo SYSCTL_ADD_COUNTER_U64_ARRAY 1269a593520SMateusz Piotrowski.Fa "struct sysctl_ctx_list *ctx" 1279a593520SMateusz Piotrowski.Fa "struct sysctl_oid_list *parent" 1289a593520SMateusz Piotrowski.Fa "int number" 1299a593520SMateusz Piotrowski.Fa "const char *name" 1309a593520SMateusz Piotrowski.Fa "int ctlflags" 1319a593520SMateusz Piotrowski.Fa "counter_u64_t *ptr" 1329a593520SMateusz Piotrowski.Fa "intmax_t len" 1339a593520SMateusz Piotrowski.Fa "const char *descr" 1349a593520SMateusz Piotrowski.Fc 1359a593520SMateusz Piotrowski.Ft struct sysctl_oid * 1365eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_INT 1375eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx" 1385eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent" 1395eb1caa8SHans Petter Selasky.Fa "int number" 1405eb1caa8SHans Petter Selasky.Fa "const char *name" 1415eb1caa8SHans Petter Selasky.Fa "int ctlflags" 1425eb1caa8SHans Petter Selasky.Fa "int *ptr" 143be87839eSConrad Meyer.Fa "int val" 1445eb1caa8SHans Petter Selasky.Fa "const char *descr" 1455eb1caa8SHans Petter Selasky.Fc 1465eb1caa8SHans Petter Selasky.Ft struct sysctl_oid * 1475eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_LONG 1485eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx" 1495eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent" 1505eb1caa8SHans Petter Selasky.Fa "int number" 1515eb1caa8SHans Petter Selasky.Fa "const char *name" 1525eb1caa8SHans Petter Selasky.Fa "int ctlflags" 1535eb1caa8SHans Petter Selasky.Fa "long *ptr" 1545eb1caa8SHans Petter Selasky.Fa "const char *descr" 1555eb1caa8SHans Petter Selasky.Fc 1565eb1caa8SHans Petter Selasky.Ft struct sysctl_oid * 1575eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_NODE 1585eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx" 1595eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent" 1605eb1caa8SHans Petter Selasky.Fa "int number" 1615eb1caa8SHans Petter Selasky.Fa "const char *name" 1625eb1caa8SHans Petter Selasky.Fa "int ctlflags" 1635eb1caa8SHans Petter Selasky.Fa "int (*handler)(SYSCTL_HANDLER_ARGS)" 1645eb1caa8SHans Petter Selasky.Fa "const char *descr" 1655eb1caa8SHans Petter Selasky.Fc 1665eb1caa8SHans Petter Selasky.Ft struct sysctl_oid * 1671e1f3941SEd Schouten.Fo SYSCTL_ADD_NODE_WITH_LABEL 1681e1f3941SEd Schouten.Fa "struct sysctl_ctx_list *ctx" 1691e1f3941SEd Schouten.Fa "struct sysctl_oid_list *parent" 1701e1f3941SEd Schouten.Fa "int number" 1711e1f3941SEd Schouten.Fa "const char *name" 1721e1f3941SEd Schouten.Fa "int ctlflags" 1731e1f3941SEd Schouten.Fa "int (*handler)(SYSCTL_HANDLER_ARGS)" 1741e1f3941SEd Schouten.Fa "const char *descr" 1751e1f3941SEd Schouten.Fa "const char *label" 1761e1f3941SEd Schouten.Fc 1771e1f3941SEd Schouten.Ft struct sysctl_oid * 1785eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_OPAQUE 1795eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx" 1805eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent" 1815eb1caa8SHans Petter Selasky.Fa "int number" 1825eb1caa8SHans Petter Selasky.Fa "const char *name" 1835eb1caa8SHans Petter Selasky.Fa "int ctlflags" 1845eb1caa8SHans Petter Selasky.Fa "void *ptr" 1855eb1caa8SHans Petter Selasky.Fa "intptr_t len" 1865eb1caa8SHans Petter Selasky.Fa "const char *format" 1873edc2b53SJoel Dahl.Fa "const char *descr" 1885eb1caa8SHans Petter Selasky.Fc 1895eb1caa8SHans Petter Selasky.Ft struct sysctl_oid * 1905eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_PROC 1915eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx" 1925eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent" 1935eb1caa8SHans Petter Selasky.Fa "int number" 1945eb1caa8SHans Petter Selasky.Fa "const char *name" 1955eb1caa8SHans Petter Selasky.Fa "int ctlflags" 1965eb1caa8SHans Petter Selasky.Fa "void *arg1" 1975eb1caa8SHans Petter Selasky.Fa "intptr_t arg2" 198ba9a5309SAndriy Voskoboinyk.Fa "int (*handler) (SYSCTL_HANDLER_ARGS)" 1995eb1caa8SHans Petter Selasky.Fa "const char *format" 2005eb1caa8SHans Petter Selasky.Fa "const char *descr" 2015eb1caa8SHans Petter Selasky.Fc 2025eb1caa8SHans Petter Selasky.Ft struct sysctl_oid * 2035eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_QUAD 2045eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx" 2055eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent" 2065eb1caa8SHans Petter Selasky.Fa "int number" 2075eb1caa8SHans Petter Selasky.Fa "const char *name" 2085eb1caa8SHans Petter Selasky.Fa "int ctlflags" 209be87839eSConrad Meyer.Fa "int64_t *ptr" 2105eb1caa8SHans Petter Selasky.Fa "const char *descr" 2115eb1caa8SHans Petter Selasky.Fc 2125eb1caa8SHans Petter Selasky.Ft struct sysctl_oid * 2135eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_ROOT_NODE 2145eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx" 2155eb1caa8SHans Petter Selasky.Fa "int number" 2165eb1caa8SHans Petter Selasky.Fa "const char *name" 2175eb1caa8SHans Petter Selasky.Fa "int ctlflags" 2185eb1caa8SHans Petter Selasky.Fa "int (*handler)(SYSCTL_HANDLER_ARGS)" 2195eb1caa8SHans Petter Selasky.Fa "const char *descr" 2205eb1caa8SHans Petter Selasky.Fc 2215eb1caa8SHans Petter Selasky.Ft struct sysctl_oid * 222be87839eSConrad Meyer.Fo SYSCTL_ADD_S8 223be87839eSConrad Meyer.Fa "struct sysctl_ctx_list *ctx" 224be87839eSConrad Meyer.Fa "struct sysctl_oid_list *parent" 225be87839eSConrad Meyer.Fa "int number" 226be87839eSConrad Meyer.Fa "const char *name" 227be87839eSConrad Meyer.Fa "int ctlflags" 228be87839eSConrad Meyer.Fa "int8_t *ptr" 229be87839eSConrad Meyer.Fa "int8_t val" 230be87839eSConrad Meyer.Fa "const char *descr" 231be87839eSConrad Meyer.Fc 232be87839eSConrad Meyer.Ft struct sysctl_oid * 233be87839eSConrad Meyer.Fo SYSCTL_ADD_S16 234be87839eSConrad Meyer.Fa "struct sysctl_ctx_list *ctx" 235be87839eSConrad Meyer.Fa "struct sysctl_oid_list *parent" 236be87839eSConrad Meyer.Fa "int number" 237be87839eSConrad Meyer.Fa "const char *name" 238be87839eSConrad Meyer.Fa "int ctlflags" 239be87839eSConrad Meyer.Fa "int16_t *ptr" 240be87839eSConrad Meyer.Fa "int16_t val" 241be87839eSConrad Meyer.Fa "const char *descr" 242be87839eSConrad Meyer.Fc 243be87839eSConrad Meyer.Ft struct sysctl_oid * 244be87839eSConrad Meyer.Fo SYSCTL_ADD_S32 245be87839eSConrad Meyer.Fa "struct sysctl_ctx_list *ctx" 246be87839eSConrad Meyer.Fa "struct sysctl_oid_list *parent" 247be87839eSConrad Meyer.Fa "int number" 248be87839eSConrad Meyer.Fa "const char *name" 249be87839eSConrad Meyer.Fa "int ctlflags" 250be87839eSConrad Meyer.Fa "int32_t *ptr" 251be87839eSConrad Meyer.Fa "int32_t val" 252be87839eSConrad Meyer.Fa "const char *descr" 253be87839eSConrad Meyer.Fc 254be87839eSConrad Meyer.Ft struct sysctl_oid * 255be87839eSConrad Meyer.Fo SYSCTL_ADD_S64 256be87839eSConrad Meyer.Fa "struct sysctl_ctx_list *ctx" 257be87839eSConrad Meyer.Fa "struct sysctl_oid_list *parent" 258be87839eSConrad Meyer.Fa "int number" 259be87839eSConrad Meyer.Fa "const char *name" 260be87839eSConrad Meyer.Fa "int ctlflags" 261be87839eSConrad Meyer.Fa "int64_t *ptr" 262be87839eSConrad Meyer.Fa "int64_t val" 263be87839eSConrad Meyer.Fa "const char *descr" 264be87839eSConrad Meyer.Fc 265be87839eSConrad Meyer.Ft struct sysctl_oid * 2669a593520SMateusz Piotrowski.Fo SYSCTL_ADD_SBINTIME_MSEC 2679a593520SMateusz Piotrowski.Fa "struct sysctl_ctx_list *ctx" 2689a593520SMateusz Piotrowski.Fa "struct sysctl_oid_list *parent" 2699a593520SMateusz Piotrowski.Fa "int number" 2709a593520SMateusz Piotrowski.Fa "const char *name" 2719a593520SMateusz Piotrowski.Fa "int ctlflags" 2729a593520SMateusz Piotrowski.Fa "sbintime_t *ptr" 2739a593520SMateusz Piotrowski.Fa "const char *descr" 2749a593520SMateusz Piotrowski.Fc 2759a593520SMateusz Piotrowski.Ft struct sysctl_oid * 2769a593520SMateusz Piotrowski.Fo SYSCTL_ADD_SBINTIME_USEC 2779a593520SMateusz Piotrowski.Fa "struct sysctl_ctx_list *ctx" 2789a593520SMateusz Piotrowski.Fa "struct sysctl_oid_list *parent" 2799a593520SMateusz Piotrowski.Fa "int number" 2809a593520SMateusz Piotrowski.Fa "const char *name" 2819a593520SMateusz Piotrowski.Fa "int ctlflags" 2829a593520SMateusz Piotrowski.Fa "sbintime_t *ptr" 2839a593520SMateusz Piotrowski.Fa "const char *descr" 2849a593520SMateusz Piotrowski.Fc 2859a593520SMateusz Piotrowski.Ft struct sysctl_oid * 2865eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_STRING 2875eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx" 2885eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent" 2895eb1caa8SHans Petter Selasky.Fa "int number" 2905eb1caa8SHans Petter Selasky.Fa "const char *name" 2915eb1caa8SHans Petter Selasky.Fa "int ctlflags" 2925eb1caa8SHans Petter Selasky.Fa "char *ptr" 2935eb1caa8SHans Petter Selasky.Fa "intptr_t len" 2945eb1caa8SHans Petter Selasky.Fa "const char *descr" 2955eb1caa8SHans Petter Selasky.Fc 2965eb1caa8SHans Petter Selasky.Ft struct sysctl_oid * 29710a1e981SEric Joyner.Fo SYSCTL_ADD_CONST_STRING 29810a1e981SEric Joyner.Fa "struct sysctl_ctx_list *ctx" 29910a1e981SEric Joyner.Fa "struct sysctl_oid_list *parent" 30010a1e981SEric Joyner.Fa "int number" 30110a1e981SEric Joyner.Fa "const char *name" 30210a1e981SEric Joyner.Fa "int ctlflags" 30310a1e981SEric Joyner.Fa "const char *ptr" 30410a1e981SEric Joyner.Fa "const char *descr" 30510a1e981SEric Joyner.Fc 30610a1e981SEric Joyner.Ft struct sysctl_oid * 3075eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_STRUCT 3085eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx" 3095eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent" 3105eb1caa8SHans Petter Selasky.Fa "int number" 3115eb1caa8SHans Petter Selasky.Fa "const char *name" 3125eb1caa8SHans Petter Selasky.Fa "int ctlflags" 3135eb1caa8SHans Petter Selasky.Fa "void *ptr" 3145eb1caa8SHans Petter Selasky.Fa struct_type 3155eb1caa8SHans Petter Selasky.Fa "const char *descr" 3165eb1caa8SHans Petter Selasky.Fc 3175eb1caa8SHans Petter Selasky.Ft struct sysctl_oid * 3180f702183SJohn Baldwin.Fo SYSCTL_ADD_TIMEVAL_SEC 3190f702183SJohn Baldwin.Fa "struct sysctl_ctx_list *ctx" 3200f702183SJohn Baldwin.Fa "struct sysctl_oid_list *parent" 3210f702183SJohn Baldwin.Fa "int number" 3220f702183SJohn Baldwin.Fa "const char *name" 3230f702183SJohn Baldwin.Fa "int ctlflags" 3240f702183SJohn Baldwin.Fa "struct timeval *ptr" 3250f702183SJohn Baldwin.Fa "const char *descr" 3260f702183SJohn Baldwin.Fc 3270f702183SJohn Baldwin.Ft struct sysctl_oid * 328fb61390cSConrad Meyer.Fo SYSCTL_ADD_U8 329fb61390cSConrad Meyer.Fa "struct sysctl_ctx_list *ctx" 330fb61390cSConrad Meyer.Fa "struct sysctl_oid_list *parent" 331fb61390cSConrad Meyer.Fa "int number" 332fb61390cSConrad Meyer.Fa "const char *name" 333fb61390cSConrad Meyer.Fa "int ctlflags" 334be87839eSConrad Meyer.Fa "uint8_t *ptr" 335be87839eSConrad Meyer.Fa "uint8_t val" 336fb61390cSConrad Meyer.Fa "const char *descr" 337fb61390cSConrad Meyer.Fc 338fb61390cSConrad Meyer.Ft struct sysctl_oid * 339fb61390cSConrad Meyer.Fo SYSCTL_ADD_U16 340fb61390cSConrad Meyer.Fa "struct sysctl_ctx_list *ctx" 341fb61390cSConrad Meyer.Fa "struct sysctl_oid_list *parent" 342fb61390cSConrad Meyer.Fa "int number" 343fb61390cSConrad Meyer.Fa "const char *name" 344fb61390cSConrad Meyer.Fa "int ctlflags" 345be87839eSConrad Meyer.Fa "uint16_t *ptr" 346be87839eSConrad Meyer.Fa "uint16_t val" 347be87839eSConrad Meyer.Fa "const char *descr" 348be87839eSConrad Meyer.Fc 349be87839eSConrad Meyer.Ft struct sysctl_oid * 350be87839eSConrad Meyer.Fo SYSCTL_ADD_U32 351be87839eSConrad Meyer.Fa "struct sysctl_ctx_list *ctx" 352be87839eSConrad Meyer.Fa "struct sysctl_oid_list *parent" 353be87839eSConrad Meyer.Fa "int number" 354be87839eSConrad Meyer.Fa "const char *name" 355be87839eSConrad Meyer.Fa "int ctlflags" 356be87839eSConrad Meyer.Fa "uint32_t *ptr" 357be87839eSConrad Meyer.Fa "uint32_t val" 358be87839eSConrad Meyer.Fa "const char *descr" 359be87839eSConrad Meyer.Fc 360be87839eSConrad Meyer.Ft struct sysctl_oid * 361be87839eSConrad Meyer.Fo SYSCTL_ADD_U64 362be87839eSConrad Meyer.Fa "struct sysctl_ctx_list *ctx" 363be87839eSConrad Meyer.Fa "struct sysctl_oid_list *parent" 364be87839eSConrad Meyer.Fa "int number" 365be87839eSConrad Meyer.Fa "const char *name" 366be87839eSConrad Meyer.Fa "int ctlflags" 367be87839eSConrad Meyer.Fa "uint64_t *ptr" 368be87839eSConrad Meyer.Fa "uint64_t val" 369fb61390cSConrad Meyer.Fa "const char *descr" 370fb61390cSConrad Meyer.Fc 371fb61390cSConrad Meyer.Ft struct sysctl_oid * 3725eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_UINT 3735eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx" 3745eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent" 3755eb1caa8SHans Petter Selasky.Fa "int number" 3765eb1caa8SHans Petter Selasky.Fa "const char *name" 3775eb1caa8SHans Petter Selasky.Fa "int ctlflags" 3785eb1caa8SHans Petter Selasky.Fa "unsigned int *ptr" 379be87839eSConrad Meyer.Fa "unsigned int val" 3805eb1caa8SHans Petter Selasky.Fa "const char *descr" 3815eb1caa8SHans Petter Selasky.Fc 3825eb1caa8SHans Petter Selasky.Ft struct sysctl_oid * 3835eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_ULONG 3845eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx" 3855eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent" 3865eb1caa8SHans Petter Selasky.Fa "int number" 3875eb1caa8SHans Petter Selasky.Fa "const char *name" 3885eb1caa8SHans Petter Selasky.Fa "int ctlflags" 3895eb1caa8SHans Petter Selasky.Fa "unsigned long *ptr" 3905eb1caa8SHans Petter Selasky.Fa "const char *descr" 3915eb1caa8SHans Petter Selasky.Fc 3925eb1caa8SHans Petter Selasky.Ft struct sysctl_oid * 3935eb1caa8SHans Petter Selasky.Fo SYSCTL_ADD_UQUAD 3945eb1caa8SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx" 3955eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list *parent" 3965eb1caa8SHans Petter Selasky.Fa "int number" 3975eb1caa8SHans Petter Selasky.Fa "const char *name" 3985eb1caa8SHans Petter Selasky.Fa "int ctlflags" 399be87839eSConrad Meyer.Fa "uint64_t *ptr" 400f0188618SHans Petter Selasky.Fa "const char *descr" 401f0188618SHans Petter Selasky.Fc 402f0188618SHans Petter Selasky.Ft struct sysctl_oid * 4039a593520SMateusz Piotrowski.Fo SYSCTL_ADD_UMA_CUR 4049a593520SMateusz Piotrowski.Fa "struct sysctl_ctx_list *ctx" 4059a593520SMateusz Piotrowski.Fa "struct sysctl_oid_list *parent" 4069a593520SMateusz Piotrowski.Fa "int number" 4079a593520SMateusz Piotrowski.Fa "const char *name" 4089a593520SMateusz Piotrowski.Fa "int ctlflags" 4099a593520SMateusz Piotrowski.Fa "uma_zone_t ptr" 4109a593520SMateusz Piotrowski.Fa "const char *descr" 4119a593520SMateusz Piotrowski.Fc 4129a593520SMateusz Piotrowski.Ft struct sysctl_oid * 4139a593520SMateusz Piotrowski.Fo SYSCTL_ADD_UMA_MAX 4149a593520SMateusz Piotrowski.Fa "struct sysctl_ctx_list *ctx" 4159a593520SMateusz Piotrowski.Fa "struct sysctl_oid_list *parent" 4169a593520SMateusz Piotrowski.Fa "int number" 4179a593520SMateusz Piotrowski.Fa "const char *name" 4189a593520SMateusz Piotrowski.Fa "int ctlflags" 4199a593520SMateusz Piotrowski.Fa "uma_zone_t ptr" 4209a593520SMateusz Piotrowski.Fa "const char *descr" 4219a593520SMateusz Piotrowski.Fc 4229a593520SMateusz Piotrowski.Fa "const char *descr" 4239a593520SMateusz Piotrowski.Ft struct sysctl_oid * 424f0188618SHans Petter Selasky.Fo SYSCTL_ADD_UAUTO 425f0188618SHans Petter Selasky.Fa "struct sysctl_ctx_list *ctx" 426f0188618SHans Petter Selasky.Fa "struct sysctl_oid_list *parent" 427f0188618SHans Petter Selasky.Fa "int number" 428f0188618SHans Petter Selasky.Fa "const char *name" 429f0188618SHans Petter Selasky.Fa "int ctlflags" 430f0188618SHans Petter Selasky.Fa "void *ptr" 4315eb1caa8SHans Petter Selasky.Fa "const char *descr" 4325eb1caa8SHans Petter Selasky.Fc 4335eb1caa8SHans Petter Selasky.Ft struct sysctl_oid_list * 4345eb1caa8SHans Petter Selasky.Fo SYSCTL_CHILDREN 4355eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid *oidp" 4365eb1caa8SHans Petter Selasky.Fc 4375eb1caa8SHans Petter Selasky.Ft struct sysctl_oid_list * 4385eb1caa8SHans Petter Selasky.Fo SYSCTL_STATIC_CHILDREN 4395eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid_list OID_NAME" 4405eb1caa8SHans Petter Selasky.Fc 4415eb1caa8SHans Petter Selasky.Ft struct sysctl_oid_list * 4425eb1caa8SHans Petter Selasky.Fo SYSCTL_NODE_CHILDREN 4435eb1caa8SHans Petter Selasky.Fa "parent" 4445eb1caa8SHans Petter Selasky.Fa "name" 4455eb1caa8SHans Petter Selasky.Fc 4465eb1caa8SHans Petter Selasky.Ft struct sysctl_oid * 4475eb1caa8SHans Petter Selasky.Fo SYSCTL_PARENT 4485eb1caa8SHans Petter Selasky.Fa "struct sysctl_oid *oid" 4495eb1caa8SHans Petter Selasky.Fc 4509a593520SMateusz Piotrowski.Fn SYSCTL_BOOL parent number name ctlflags ptr val descr 4519a593520SMateusz Piotrowski.Fn SYSCTL_COUNTER_U64 parent number name ctlflags ptr descr 4529a593520SMateusz Piotrowski.Fn SYSCTL_COUNTER_U64_ARRAY parent number name ctlflags ptr len descr 4535eb1caa8SHans Petter Selasky.Fn SYSCTL_INT parent number name ctlflags ptr val descr 4541e1f3941SEd Schouten.Fn SYSCTL_INT_WITH_LABEL parent number name ctlflags ptr val descr label 4555eb1caa8SHans Petter Selasky.Fn SYSCTL_LONG parent number name ctlflags ptr val descr 456574b98cbSJohn Baldwin.Ft int 457574b98cbSJohn Baldwin.Fn sysctl_msec_to_ticks SYSCTL_HANDLER_ARGS 4585eb1caa8SHans Petter Selasky.Fn SYSCTL_NODE parent number name ctlflags handler descr 4591e1f3941SEd Schouten.Fn SYSCTL_NODE_WITH_LABEL parent number name ctlflags handler descr label 4605eb1caa8SHans Petter Selasky.Fn SYSCTL_OPAQUE parent number name ctlflags ptr len format descr 4615eb1caa8SHans Petter Selasky.Fn SYSCTL_PROC parent number name ctlflags arg1 arg2 handler format descr 4625eb1caa8SHans Petter Selasky.Fn SYSCTL_QUAD parent number name ctlflags ptr val descr 463be87839eSConrad Meyer.Fn SYSCTL_ROOT_NODE number name ctlflags handler descr 464be87839eSConrad Meyer.Fn SYSCTL_S8 parent number name ctlflags ptr val descr 465be87839eSConrad Meyer.Fn SYSCTL_S16 parent number name ctlflags ptr val descr 466be87839eSConrad Meyer.Fn SYSCTL_S32 parent number name ctlflags ptr val descr 467be87839eSConrad Meyer.Fn SYSCTL_S64 parent number name ctlflags ptr val descr 4689a593520SMateusz Piotrowski.Fn SYSCTL_SBINTIME_MSEC parent number name ctlflags ptr descr 4699a593520SMateusz Piotrowski.Fn SYSCTL_SBINTIME_USEC parent number name ctlflags ptr descr 4705eb1caa8SHans Petter Selasky.Fn SYSCTL_STRING parent number name ctlflags arg len descr 47110a1e981SEric Joyner.Fn SYSCTL_CONST_STRING parent number name ctlflags arg descr 4725eb1caa8SHans Petter Selasky.Fn SYSCTL_STRUCT parent number name ctlflags ptr struct_type descr 4730f702183SJohn Baldwin.Fn SYSCTL_TIMEVAL_SEC parent number name ctlflags ptr descr 474fb61390cSConrad Meyer.Fn SYSCTL_U8 parent number name ctlflags ptr val descr 475fb61390cSConrad Meyer.Fn SYSCTL_U16 parent number name ctlflags ptr val descr 476be87839eSConrad Meyer.Fn SYSCTL_U32 parent number name ctlflags ptr val descr 477be87839eSConrad Meyer.Fn SYSCTL_U64 parent number name ctlflags ptr val descr 4785eb1caa8SHans Petter Selasky.Fn SYSCTL_UINT parent number name ctlflags ptr val descr 4795eb1caa8SHans Petter Selasky.Fn SYSCTL_ULONG parent number name ctlflags ptr val descr 4805eb1caa8SHans Petter Selasky.Fn SYSCTL_UQUAD parent number name ctlflags ptr val descr 4819a593520SMateusz Piotrowski.Fn SYSCTL_UMA_MAX parent number name ctlflags ptr descr 4829a593520SMateusz Piotrowski.Fn SYSCTL_UMA_CUR parent number name ctlflags ptr descr 483dba9e9ccSRobert Watson.Sh DESCRIPTION 484dba9e9ccSRobert WatsonThe 485bd84dd2fSRuslan Ermilov.Nm SYSCTL 4865eb1caa8SHans Petter Selaskykernel interface allows dynamic or static creation of 487dba9e9ccSRobert Watson.Xr sysctl 8 4885eb1caa8SHans Petter SelaskyMIB entries. 4895eb1caa8SHans Petter SelaskyAll static sysctls are automatically destroyed when the module which 4905eb1caa8SHans Petter Selaskythey are part of is unloaded. 4915eb1caa8SHans Petter SelaskyMost top level categories are created statically and are available to 4925eb1caa8SHans Petter Selaskyall kernel code and its modules. 4935eb1caa8SHans Petter Selasky.Sh DESCRIPTION OF ARGUMENTS 4945eb1caa8SHans Petter Selasky.Bl -tag -width ctlflags 4955eb1caa8SHans Petter Selasky.It Fa ctx 4965eb1caa8SHans Petter SelaskyPointer to sysctl context or NULL, if no context. 4975eb1caa8SHans Petter SelaskySee 4985eb1caa8SHans Petter Selasky.Xr sysctl_ctx_init 9 4995eb1caa8SHans Petter Selaskyfor how to create a new sysctl context. 5005eb1caa8SHans Petter SelaskyProgrammers are strongly advised to use contexts to organize the 5015eb1caa8SHans Petter Selaskydynamic OIDs which they create because when a context is destroyed all 5025eb1caa8SHans Petter Selaskybelonging sysctls are destroyed as well. 5035eb1caa8SHans Petter SelaskyThis makes the sysctl cleanup code much simpler. 504aa88ccabSHans Petter SelaskyElse deletion of all created OIDs is required at module unload. 5055eb1caa8SHans Petter Selasky.It Fa parent 5065eb1caa8SHans Petter SelaskyA pointer to a 5075eb1caa8SHans Petter Selasky.Li struct sysctl_oid_list , 5085eb1caa8SHans Petter Selaskywhich is the head of the parent's list of children. 509aa88ccabSHans Petter SelaskyThis pointer is retrieved using the 5105eb1caa8SHans Petter Selasky.Fn SYSCTL_STATIC_CHILDREN 5115eb1caa8SHans Petter Selaskymacro for static sysctls and the 5125eb1caa8SHans Petter Selasky.Fn SYSCTL_CHILDREN 5135eb1caa8SHans Petter Selaskymacro for dynamic sysctls. 514aa88ccabSHans Petter SelaskyThe 5155eb1caa8SHans Petter Selasky.Fn SYSCTL_PARENT 516aa88ccabSHans Petter Selaskymacro can be used to get the parent of an OID. 517aa88ccabSHans Petter SelaskyThe macro returns NULL if there is no parent. 5185eb1caa8SHans Petter Selasky.It Fa number 5195eb1caa8SHans Petter SelaskyThe OID number that will be assigned to this OID. 5205eb1caa8SHans Petter SelaskyIn almost all cases this should be set to 5215eb1caa8SHans Petter Selasky.Dv OID_AUTO , 5225eb1caa8SHans Petter Selaskywhich will result in the assignment of the next available OID number. 5235eb1caa8SHans Petter Selasky.It Fa name 5245eb1caa8SHans Petter SelaskyThe name of the OID. 5255eb1caa8SHans Petter SelaskyThe newly created OID will contain a copy of the name. 5265eb1caa8SHans Petter Selasky.It Fa ctlflags 5275eb1caa8SHans Petter SelaskyA bit mask of sysctl control flags. 5285eb1caa8SHans Petter SelaskySee the section below describing all the control flags. 5295eb1caa8SHans Petter Selasky.It Fa arg1 5305eb1caa8SHans Petter SelaskyFirst callback argument for procedure sysctls. 5315eb1caa8SHans Petter Selasky.It Fa arg2 5325eb1caa8SHans Petter SelaskySecond callback argument for procedure sysctls. 5335eb1caa8SHans Petter Selasky.It Fa len 5345eb1caa8SHans Petter SelaskyThe length of the data pointed to by the 5355eb1caa8SHans Petter Selasky.Fa ptr 5365eb1caa8SHans Petter Selaskyargument. 5375eb1caa8SHans Petter SelaskyFor string type OIDs a length of zero means that 5385eb1caa8SHans Petter Selasky.Xr strlen 3 5395eb1caa8SHans Petter Selaskywill be used to get the length of the string at each access to the OID. 5409a593520SMateusz PiotrowskiFor array type OIDs the length must be greater than zero. 5415eb1caa8SHans Petter Selasky.It Fa ptr 5425eb1caa8SHans Petter SelaskyPointer to sysctl variable or string data. 543f0188618SHans 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 5445eb1caa8SHans Petter Selasky.Fa val 5455eb1caa8SHans Petter Selaskyargument. 5465eb1caa8SHans Petter Selasky.It Fa val 5475eb1caa8SHans Petter SelaskyIf the 5485eb1caa8SHans Petter Selasky.Fa ptr 549f0188618SHans Petter Selaskyargument is SYSCTL_NULL_XXX_PTR, gives the constant value returned by this OID. 5505eb1caa8SHans Petter SelaskyElse this argument is not used. 5515eb1caa8SHans Petter Selasky.It Fa struct_type 5525eb1caa8SHans Petter SelaskyName of structure type. 5535eb1caa8SHans Petter Selasky.It Fa handler 5545eb1caa8SHans Petter SelaskyA pointer to the function 5555eb1caa8SHans Petter Selaskythat is responsible for handling read and write requests 5565eb1caa8SHans Petter Selaskyto this OID. 5575eb1caa8SHans Petter SelaskyThere are several standard handlers 5585eb1caa8SHans Petter Selaskythat support operations on nodes, 5595eb1caa8SHans Petter Selaskyintegers, strings and opaque objects. 5605eb1caa8SHans Petter SelaskyIt is possible to define custom handlers using the 5615eb1caa8SHans Petter Selasky.Fn SYSCTL_PROC 5625eb1caa8SHans Petter Selaskymacro or the 5635eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_PROC 5645eb1caa8SHans Petter Selaskyfunction. 5655eb1caa8SHans Petter Selasky.It Fa format 5665eb1caa8SHans Petter SelaskyA pointer to a string 5675eb1caa8SHans Petter Selaskywhich specifies the format of the OID in a symbolic way. 5685eb1caa8SHans Petter SelaskyThis format is used as a hint by 5695eb1caa8SHans Petter Selasky.Xr sysctl 8 5705eb1caa8SHans Petter Selaskyto apply proper data formatting for display purposes. 571aa255ef6SWarner Losh.Pp 572aa255ef6SWarner LoshCurrent formats: 573aa255ef6SWarner Losh.Bl -tag -width "S,TYPE" -compact -offset indent 574aa255ef6SWarner Losh.It Cm N 575aa255ef6SWarner Loshnode 576aa255ef6SWarner Losh.It Cm A 577aa255ef6SWarner Losh.Li "char *" 578c94b4d46SStéphane Rochoy.It Cm C 579c94b4d46SStéphane Rochoy.Li "int8_t" 580c94b4d46SStéphane Rochoy.It Cm CU 581c94b4d46SStéphane Rochoy.Li "uint8_t" 582aa255ef6SWarner Losh.It Cm I 583aa255ef6SWarner Losh.Li "int" 584aa255ef6SWarner Losh.It Cm IK Ns Op Ar n 585aa255ef6SWarner Loshtemperature in Kelvin, multiplied by an optional single digit 586aa255ef6SWarner Loshpower of ten scaling factor: 1 (default) gives deciKelvin, 0 gives Kelvin, 3 587aa255ef6SWarner Loshgives milliKelvin 588aa255ef6SWarner Losh.It Cm IU 589aa255ef6SWarner Losh.Li "unsigned int" 590aa255ef6SWarner Losh.It Cm L 591aa255ef6SWarner Losh.Li "long" 592aa255ef6SWarner Losh.It Cm LU 593aa255ef6SWarner Losh.Li "unsigned long" 594aa255ef6SWarner Losh.It Cm Q 595aa255ef6SWarner Losh.Li "quad_t" 596aa255ef6SWarner Losh.It Cm QU 5975eb1caa8SHans Petter Selasky.Li "u_quad_t" 598c94b4d46SStéphane Rochoy.It Cm S 599c94b4d46SStéphane Rochoy.Li "int16_t" 600c94b4d46SStéphane Rochoy.It Cm SU 601c94b4d46SStéphane Rochoy.Li "uint16_t" 602aa255ef6SWarner Losh.It Cm "S,TYPE" 6035eb1caa8SHans Petter Selasky.Li "struct TYPE" 604aa255ef6SWarner Loshstructures 605aa255ef6SWarner Losh.El 6065eb1caa8SHans Petter Selasky.It Fa descr 6075eb1caa8SHans Petter SelaskyA pointer to a textual description of the OID. 6081e1f3941SEd Schouten.It Fa label 6091e1f3941SEd SchoutenA pointer to an aggregation label for this component of the OID. 6101e1f3941SEd SchoutenTo make it easier to export sysctl data to monitoring systems that 6111e1f3941SEd Schoutensupport aggregations through labels (e.g., Prometheus), 6121e1f3941SEd Schoutenthis argument can be used to attach a label name to an OID. 6131e1f3941SEd SchoutenThe label acts as a hint that this component's name should not be part 6141e1f3941SEd Schoutenof the metric's name, 6151e1f3941SEd Schoutenbut attached to the metric as a label instead. 6161e1f3941SEd Schouten.Pp 6171e1f3941SEd SchoutenLabels should only be applied to siblings that are structurally similar 6181e1f3941SEd Schoutenand encode the same type of value, 6191e1f3941SEd Schoutenas aggregation is of no use otherwise. 6205eb1caa8SHans Petter Selasky.El 621574b98cbSJohn Baldwin.Sh NODE VALUE TYPES 622574b98cbSJohn BaldwinMost of the macros and functions used to create sysctl nodes export a 623574b98cbSJohn Baldwinread-only constant or in-kernel variable whose type matches the type 624574b98cbSJohn Baldwinof the node's value. 625574b98cbSJohn BaldwinFor example, 626574b98cbSJohn Baldwin.Fn SYSCTL_INT 627574b98cbSJohn Baldwinreports the raw value of an associated variable of type 628574b98cbSJohn Baldwin.Vt int . 629ff9c4abdSDamien BrokaHowever, nodes may also export a value that is a translation of an internal 630574b98cbSJohn Baldwinrepresentation. 631574b98cbSJohn Baldwin.Pp 632574b98cbSJohn BaldwinThe 633574b98cbSJohn Baldwin.Fn sysctl_msec_to_ticks 634574b98cbSJohn Baldwinhandler can be used with 635574b98cbSJohn Baldwin.Fn SYSCTL_PROC 636574b98cbSJohn Baldwinor 637574b98cbSJohn Baldwin.Fn SYSCTL_ADD_PROC 638574b98cbSJohn Baldwinto export a millisecond time interval. 639574b98cbSJohn BaldwinWhen using this handler, 640574b98cbSJohn Baldwinthe 641574b98cbSJohn Baldwin.Fa arg2 642574b98cbSJohn Baldwinparameter points to an in-kernel variable of type 643574b98cbSJohn Baldwin.Vt int 644574b98cbSJohn Baldwinwhich stores a tick count suitable for use with functions like 645574b98cbSJohn Baldwin.Xr tsleep 9 . 646574b98cbSJohn BaldwinThe 647574b98cbSJohn Baldwin.Fn sysctl_msec_to_ticks 648574b98cbSJohn Baldwinfunction converts this value to milliseconds when reporting the node's value. 649574b98cbSJohn BaldwinSimilarly, 650574b98cbSJohn Baldwin.Fn sysctl_msec_to_ticks 651574b98cbSJohn Baldwinaccepts new values in milliseconds and stores an equivalent value in ticks to 652574b98cbSJohn Baldwin.Fa *arg2 . 653574b98cbSJohn BaldwinNote that new code should use kernel variables of type 654574b98cbSJohn Baldwin.Vt sbintime_t 655574b98cbSJohn Baldwininstead of tick counts. 656574b98cbSJohn Baldwin.Pp 657574b98cbSJohn BaldwinThe 658574b98cbSJohn Baldwin.Fn SYSCTL_ADD_SBINTIME_MSEC 659574b98cbSJohn Baldwinand 660574b98cbSJohn Baldwin.Fn SYSCTL_ADD_SBINTIME_USEC 661574b98cbSJohn Baldwinfunctions and 662574b98cbSJohn Baldwin.Fn SYSCTL_SBINTIME_MSEC 663574b98cbSJohn Baldwinand 664574b98cbSJohn Baldwin.Fn SYSCTL_SBINTIME_USEC 665574b98cbSJohn Baldwinmacros all create nodes which export an in-kernel variable of type 666574b98cbSJohn Baldwin.Vt sbintime_t . 667574b98cbSJohn BaldwinThese nodes do not export the raw value of the associated variable. 668574b98cbSJohn BaldwinInstead, they export a 64-bit integer containing a count of either 669574b98cbSJohn Baldwinmilliseconds (the MSEC variants) or microseconds (the USEC variants). 6700f702183SJohn Baldwin.Pp 6710f702183SJohn BaldwinThe 6720f702183SJohn Baldwin.Fn SYSCTL_ADD_TIMEVAL_SEC 6730f702183SJohn Baldwinfunction and 6740f702183SJohn Baldwin.Fn SYSCTL_TIMEVAL_SEC 6750f702183SJohn Baldwinmacro create nodes which export an in-kernel variable of type 6760f702183SJohn Baldwin.Vt struct timeval . 6770f702183SJohn BaldwinThese nodes do not export full value of the associated structure. 6780f702183SJohn BaldwinInstead, they export a count in seconds as a simple integer which is 6790f702183SJohn Baldwinstored in the 6800f702183SJohn Baldwin.Fa tv_sec 6810f702183SJohn Baldwinfield of the associated variable. 6820f702183SJohn BaldwinThis function and macro are intended to be used with variables which 6830f702183SJohn Baldwinstore a non-negative interval rather than an absolute time. 6840f702183SJohn BaldwinAs a result, they reject attempts to store negative values. 6855eb1caa8SHans Petter Selasky.Sh CREATING ROOT NODES 6865eb1caa8SHans Petter SelaskySysctl MIBs or OIDs are created in a hierarchical tree. 6875eb1caa8SHans Petter SelaskyThe nodes at the bottom of the tree are called root nodes, and have no 6885eb1caa8SHans Petter Selaskyparent OID. 6895eb1caa8SHans Petter SelaskyTo create bottom tree nodes the 6905eb1caa8SHans Petter Selasky.Fn SYSCTL_ROOT_NODE 6915eb1caa8SHans Petter Selaskymacro or the 6925eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_ROOT_NODE 6935eb1caa8SHans Petter Selaskyfunction needs to be used. 6945eb1caa8SHans Petter SelaskyBy default all static sysctl node OIDs are global and need a 6955eb1caa8SHans Petter Selasky.Fn SYSCTL_DECL 6965eb1caa8SHans Petter Selaskystatement prior to their 6975eb1caa8SHans Petter Selasky.Fn SYSCTL_NODE 6985eb1caa8SHans Petter Selaskydefinition statement, typically in a so-called header file. 6995eb1caa8SHans Petter Selasky.Sh CREATING SYSCTL STRINGS 7005eb1caa8SHans Petter SelaskyZero terminated character strings sysctls are created either using the 7015eb1caa8SHans Petter Selasky.Fn SYSCTL_STRING 7025eb1caa8SHans Petter Selaskymacro or the 7035eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_STRING 7045eb1caa8SHans Petter Selaskyfunction. 7055eb1caa8SHans Petter SelaskyIf the 7065eb1caa8SHans Petter Selasky.Fa len 70763a6bd2fSDavid E. O'Brienargument is zero, the string length is computed at every access to the OID using 7085eb1caa8SHans Petter Selasky.Xr strlen 3 . 70910a1e981SEric JoynerUse the 71010a1e981SEric Joyner.Fn SYSCTL_CONST_STRING 71110a1e981SEric Joynermacro or the 71210a1e981SEric Joyner.Fn SYSCTL_ADD_CONST_STRING 71310a1e981SEric Joynerfunction to add a sysctl for a constant string. 7145eb1caa8SHans Petter Selasky.Sh CREATING OPAQUE SYSCTLS 7155eb1caa8SHans Petter SelaskyThe 7165eb1caa8SHans Petter Selasky.Fn SYSCTL_OPAQUE 7175eb1caa8SHans Petter Selaskyor 7185eb1caa8SHans Petter Selasky.Fn SYSCTL_STRUCT 7195eb1caa8SHans Petter Selaskymacros or the 7205eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_OPAQUE 7215eb1caa8SHans Petter Selaskyor 7225eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_STRUCT 7235eb1caa8SHans Petter Selaskyfunctions create an OID that handle any chunk of data 7245eb1caa8SHans Petter Selaskyof the size specified by the 7255eb1caa8SHans Petter Selasky.Fa len 7265eb1caa8SHans Petter Selaskyargument and data pointed to by the 7275eb1caa8SHans Petter Selasky.Fa ptr 7285eb1caa8SHans Petter Selaskyargument. 7295eb1caa8SHans Petter SelaskyWhen using the structure version the type is encoded as part of the 7305eb1caa8SHans Petter Selaskycreated sysctl. 7315eb1caa8SHans Petter Selasky.Sh CREATING CUSTOM SYSCTLS 7325eb1caa8SHans Petter SelaskyThe 7335eb1caa8SHans Petter Selasky.Fn SYSCTL_PROC 7345eb1caa8SHans Petter Selaskymacro and the 7355eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_PROC 7365eb1caa8SHans Petter Selaskyfunction 7375eb1caa8SHans Petter Selaskycreate OIDs with the specified 7385eb1caa8SHans Petter Selasky.Pa handler 7395eb1caa8SHans Petter Selaskyfunction. 7405eb1caa8SHans Petter SelaskyThe handler is responsible for handling all read and write requests to 7415eb1caa8SHans Petter Selaskythe OID. 7425eb1caa8SHans Petter SelaskyThis OID type is especially useful if the kernel data is not easily 7435eb1caa8SHans Petter Selaskyaccessible, or needs to be processed before exporting. 7445eb1caa8SHans Petter Selasky.Sh CREATING A STATIC SYSCTL 7455eb1caa8SHans Petter SelaskyStatic sysctls are declared using one of the 7469a593520SMateusz Piotrowski.Fn SYSCTL_BOOL , 7479a593520SMateusz Piotrowski.Fn SYSCTL_COUNTER_U64 , 7489a593520SMateusz Piotrowski.Fn SYSCTL_COUNTER_U64_ARRAY , 749bd84dd2fSRuslan Ermilov.Fn SYSCTL_INT , 7501e1f3941SEd Schouten.Fn SYSCTL_INT_WITH_LABEL , 751bd84dd2fSRuslan Ermilov.Fn SYSCTL_LONG , 752bd84dd2fSRuslan Ermilov.Fn SYSCTL_NODE , 7531e1f3941SEd Schouten.Fn SYSCTL_NODE_WITH_LABEL , 754bd84dd2fSRuslan Ermilov.Fn SYSCTL_OPAQUE , 755bd84dd2fSRuslan Ermilov.Fn SYSCTL_PROC , 75660a77442SJohn Baldwin.Fn SYSCTL_QUAD , 7575eb1caa8SHans Petter Selasky.Fn SYSCTL_ROOT_NODE , 758be87839eSConrad Meyer.Fn SYSCTL_S8 , 759be87839eSConrad Meyer.Fn SYSCTL_S16 , 760be87839eSConrad Meyer.Fn SYSCTL_S32 , 761be87839eSConrad Meyer.Fn SYSCTL_S64 , 7629a593520SMateusz Piotrowski.Fn SYSCTL_SBINTIME_MSEC , 7639a593520SMateusz Piotrowski.Fn SYSCTL_SBINTIME_USEC , 764bd84dd2fSRuslan Ermilov.Fn SYSCTL_STRING , 76510a1e981SEric Joyner.Fn SYSCTL_CONST_STRING , 766bd84dd2fSRuslan Ermilov.Fn SYSCTL_STRUCT , 7670f702183SJohn Baldwin.Fn SYSCTL_TIMEVAL_SEC , 768fb61390cSConrad Meyer.Fn SYSCTL_U8 , 769fb61390cSConrad Meyer.Fn SYSCTL_U16 , 770be87839eSConrad Meyer.Fn SYSCTL_U32 , 771be87839eSConrad Meyer.Fn SYSCTL_U64 , 772bd84dd2fSRuslan Ermilov.Fn SYSCTL_UINT , 7739a593520SMateusz Piotrowski.Fn SYSCTL_ULONG , 7749a593520SMateusz Piotrowski.Fn SYSCTL_UQUAD , 7759a593520SMateusz Piotrowski.Fn SYSCTL_UMA_CUR 7765eb1caa8SHans Petter Selaskyor 7779a593520SMateusz Piotrowski.Fn SYSCTL_UMA_MAX 7785eb1caa8SHans Petter Selaskymacros. 7795eb1caa8SHans Petter Selasky.Sh CREATING A DYNAMIC SYSCTL 7805eb1caa8SHans Petter SelaskyDynamic nodes are created using one of the 7819a593520SMateusz Piotrowski.Fn SYSCTL_ADD_BOOL , 7829a593520SMateusz Piotrowski.Fn SYSCTL_ADD_COUNTER_U64 , 7839a593520SMateusz Piotrowski.Fn SYSCTL_ADD_COUNTER_U64_ARRAY , 7845eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_INT , 7855eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_LONG , 7865eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_NODE , 7871e1f3941SEd Schouten.Fn SYSCTL_ADD_NODE_WITH_LABEL , 7885eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_OPAQUE , 7895eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_PROC , 7905eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_QUAD , 7915eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_ROOT_NODE , 792be87839eSConrad Meyer.Fn SYSCTL_ADD_S8 , 793be87839eSConrad Meyer.Fn SYSCTL_ADD_S16 , 794be87839eSConrad Meyer.Fn SYSCTL_ADD_S32 , 795be87839eSConrad Meyer.Fn SYSCTL_ADD_S64 , 7969a593520SMateusz Piotrowski.Fn SYSCTL_ADD_SBINTIME_MSEC , 7979a593520SMateusz Piotrowski.Fn SYSCTL_ADD_SBINTIME_USEC , 7985eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_STRING , 79910a1e981SEric Joyner.Fn SYSCTL_ADD_CONST_STRING , 8005eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_STRUCT , 8010f702183SJohn Baldwin.Fn SYSCTL_ADD_TIMEVAL_SEC , 802fb61390cSConrad Meyer.Fn SYSCTL_ADD_U8 , 803fb61390cSConrad Meyer.Fn SYSCTL_ADD_U16 , 804be87839eSConrad Meyer.Fn SYSCTL_ADD_U32 , 805be87839eSConrad Meyer.Fn SYSCTL_ADD_U64 , 806f0188618SHans Petter Selasky.Fn SYSCTL_ADD_UAUTO , 8075eb1caa8SHans Petter Selasky.Fn SYSCTL_ADD_UINT , 808f0188618SHans Petter Selasky.Fn SYSCTL_ADD_ULONG , 8099a593520SMateusz Piotrowski.Fn SYSCTL_ADD_UQUAD , 8109a593520SMateusz Piotrowski.Fn SYSCTL_ADD_UMA_CUR 8115eb1caa8SHans Petter Selaskyor 8129a593520SMateusz Piotrowski.Fn SYSCTL_ADD_UMA_MAX 8135eb1caa8SHans Petter Selaskyfunctions. 8145eb1caa8SHans Petter SelaskySee 8155eb1caa8SHans Petter Selasky.Xr sysctl_remove_oid 9 8165eb1caa8SHans Petter Selaskyor 8175eb1caa8SHans Petter Selasky.Xr sysctl_ctx_free 9 8185eb1caa8SHans Petter Selaskyfor more information on how to destroy a dynamically created OID. 8195eb1caa8SHans Petter Selasky.Sh CONTROL FLAGS 8205eb1caa8SHans Petter SelaskyFor most of the above functions and macros, declaring a type as part 8215eb1caa8SHans Petter Selaskyof the access flags is not necessary \[em] however, when declaring a 8225eb1caa8SHans Petter Selaskysysctl implemented by a function, including a type in the access mask 8235eb1caa8SHans Petter Selaskyis required: 8245eb1caa8SHans Petter Selasky.Bl -tag -width ".Dv CTLTYPE_NOFETCH" 825dba9e9ccSRobert Watson.It Dv CTLTYPE_NODE 826dba9e9ccSRobert WatsonThis is a node intended to be a parent for other nodes. 827dba9e9ccSRobert Watson.It Dv CTLTYPE_INT 828dba9e9ccSRobert WatsonThis is a signed integer. 829dba9e9ccSRobert Watson.It Dv CTLTYPE_STRING 830dba9e9ccSRobert WatsonThis is a nul-terminated string stored in a character array. 831be87839eSConrad Meyer.It Dv CTLTYPE_S8 832be87839eSConrad MeyerThis is an 8-bit signed integer. 833be87839eSConrad Meyer.It Dv CTLTYPE_S16 834be87839eSConrad MeyerThis is a 16-bit signed integer. 835be87839eSConrad Meyer.It Dv CTLTYPE_S32 836be87839eSConrad MeyerThis is a 32-bit signed integer. 837cbc134adSMatthew D Fleming.It Dv CTLTYPE_S64 838dba9e9ccSRobert WatsonThis is a 64-bit signed integer. 839dba9e9ccSRobert Watson.It Dv CTLTYPE_OPAQUE 840dba9e9ccSRobert WatsonThis is an opaque data structure. 841dba9e9ccSRobert Watson.It Dv CTLTYPE_STRUCT 842dba9e9ccSRobert WatsonAlias for 843dba9e9ccSRobert Watson.Dv CTLTYPE_OPAQUE . 844fb61390cSConrad Meyer.It Dv CTLTYPE_U8 845fb61390cSConrad MeyerThis is an 8-bit unsigned integer. 846fb61390cSConrad Meyer.It Dv CTLTYPE_U16 847fb61390cSConrad MeyerThis is a 16-bit unsigned integer. 848be87839eSConrad Meyer.It Dv CTLTYPE_U32 849be87839eSConrad MeyerThis is a 32-bit unsigned integer. 850be87839eSConrad Meyer.It Dv CTLTYPE_U64 851be87839eSConrad MeyerThis is a 64-bit unsigned integer. 852dba9e9ccSRobert Watson.It Dv CTLTYPE_UINT 853dba9e9ccSRobert WatsonThis is an unsigned integer. 854dba9e9ccSRobert Watson.It Dv CTLTYPE_LONG 855dba9e9ccSRobert WatsonThis is a signed long. 856dba9e9ccSRobert Watson.It Dv CTLTYPE_ULONG 8578a1f4129SRobert WatsonThis is an unsigned long. 858dba9e9ccSRobert Watson.El 859dba9e9ccSRobert Watson.Pp 86060a77442SJohn BaldwinAll sysctl types except for new node declarations require one of the following 86160a77442SJohn Baldwinflags to be set indicating the read and write disposition of the sysctl: 862bd84dd2fSRuslan Ermilov.Bl -tag -width ".Dv CTLFLAG_ANYBODY" 863dba9e9ccSRobert Watson.It Dv CTLFLAG_RD 864dba9e9ccSRobert WatsonThis is a read-only sysctl. 86560a77442SJohn Baldwin.It Dv CTLFLAG_RDTUN 8665eb1caa8SHans Petter SelaskyThis is a read-only sysctl and tunable which is tried fetched once 8677c64ddd5SWarren Blockfrom the system environment early during module load or system boot. 868b470b929SDavid E. O'Brien.It Dv CTLFLAG_WR 869dba9e9ccSRobert WatsonThis is a writable sysctl. 870dba9e9ccSRobert Watson.It Dv CTLFLAG_RW 871dba9e9ccSRobert WatsonThis sysctl is readable and writable. 87260a77442SJohn Baldwin.It Dv CTLFLAG_RWTUN 8735eb1caa8SHans Petter SelaskyThis is a readable and writeable sysctl and tunable which is tried 8747c64ddd5SWarren Blockfetched once from the system environment early during module load or 8755eb1caa8SHans Petter Selaskysystem boot. 8765eb1caa8SHans Petter Selasky.It Dv CTLFLAG_NOFETCH 8775eb1caa8SHans Petter SelaskyIn case the node is marked as a tunable using the CTLFLAG_[XX]TUN, 8785eb1caa8SHans Petter Selaskythis flag will prevent fetching the initial value from the system 8797851d429SEdward Tomasz Napieralaenvironment. 8807851d429SEdward Tomasz NapieralaTypically this flag should only be used for very early 8815eb1caa8SHans Petter Selaskylow level system setup code, and not by common drivers and modules. 882982a973eSWarner Losh.It Dv CTLFLAG_MPSAFE 883982a973eSWarner LoshThis 884982a973eSWarner Losh.Xr sysctl 9 885982a973eSWarner Loshhandler is MP safe. 886982a973eSWarner LoshDo not grab Giant around calls to this handler. 887d132d4caSWarner LoshThis should only be used for 888d132d4caSWarner Losh.Fn SYSCTL_PROC 889d132d4caSWarner Loshentries. 89060a77442SJohn Baldwin.El 89160a77442SJohn Baldwin.Pp 89260a77442SJohn BaldwinAdditionally, any of the following optional flags may also be specified: 89360a77442SJohn Baldwin.Bl -tag -width ".Dv CTLFLAG_ANYBODY" 894dba9e9ccSRobert Watson.It Dv CTLFLAG_ANYBODY 895dba9e9ccSRobert WatsonAny user or process can write to this sysctl. 896e3127092SEd Maste.It Dv CTLFLAG_CAPRD 897e3127092SEd MasteA process in capability mode can read from this sysctl. 898e3127092SEd Maste.It Dv CTLFLAG_CAPWR 899e3127092SEd MasteA process in capability mode can write to this sysctl. 900dba9e9ccSRobert Watson.It Dv CTLFLAG_SECURE 901dba9e9ccSRobert WatsonThis sysctl can be written to only if the effective securelevel of the 902bd84dd2fSRuslan Ermilovprocess is \[<=] 0. 903dba9e9ccSRobert Watson.It Dv CTLFLAG_PRISON 904dba9e9ccSRobert WatsonThis sysctl can be written to by processes in 905dba9e9ccSRobert Watson.Xr jail 2 . 906dba9e9ccSRobert Watson.It Dv CTLFLAG_SKIP 907dba9e9ccSRobert WatsonWhen iterating the sysctl name space, do not list this sysctl. 908dba9e9ccSRobert Watson.It Dv CTLFLAG_TUN 9096b9597aaSAndrew ThompsonAdvisory flag that a system tunable also exists for this variable. 9105eb1caa8SHans Petter SelaskyThe initial sysctl value is tried fetched once from the system 9117c64ddd5SWarren Blockenvironment early during module load or system boot. 9125eb1caa8SHans Petter Selasky.It Dv CTLFLAG_DYN 9135eb1caa8SHans Petter SelaskyDynamically created OIDs automatically get this flag set. 91456538e4aSGleb Smirnoff.It Dv CTLFLAG_VNET 91556538e4aSGleb SmirnoffOID references a VIMAGE-enabled variable. 916dba9e9ccSRobert Watson.El 917dba9e9ccSRobert Watson.Sh EXAMPLES 918dba9e9ccSRobert WatsonSample use of 919bd84dd2fSRuslan Ermilov.Fn SYSCTL_DECL 920bd84dd2fSRuslan Ermilovto declare the 921bd84dd2fSRuslan Ermilov.Va security 922bd84dd2fSRuslan Ermilovsysctl tree for use by new nodes: 923dba9e9ccSRobert Watson.Bd -literal -offset indent 924dba9e9ccSRobert WatsonSYSCTL_DECL(_security); 925dba9e9ccSRobert Watson.Ed 926dba9e9ccSRobert Watson.Pp 927dba9e9ccSRobert WatsonExamples of integer, opaque, string, and procedure sysctls follow: 928dba9e9ccSRobert Watson.Bd -literal -offset indent 929dba9e9ccSRobert Watson/* 930dba9e9ccSRobert Watson * Example of a constant integer value. Notice that the control 931f0188618SHans Petter Selasky * flags are CTLFLAG_RD, the variable pointer is SYSCTL_NULL_INT_PTR, 932f0188618SHans Petter Selasky * and the value is declared. 933dba9e9ccSRobert Watson */ 934f0188618SHans Petter SelaskySYSCTL_INT(_debug_sizeof, OID_AUTO, bio, CTLFLAG_RD, SYSCTL_NULL_INT_PTR, 935dba9e9ccSRobert Watson sizeof(struct bio), "sizeof(struct bio)"); 936dba9e9ccSRobert Watson 937dba9e9ccSRobert Watson/* 938dba9e9ccSRobert Watson * Example of a variable integer value. Notice that the control 939dba9e9ccSRobert Watson * flags are CTLFLAG_RW, the variable pointer is set, and the 940dba9e9ccSRobert Watson * value is 0. 941dba9e9ccSRobert Watson */ 942dba9e9ccSRobert Watsonstatic int doingcache = 1; /* 1 => enable the cache */ 943dba9e9ccSRobert WatsonSYSCTL_INT(_debug, OID_AUTO, vfscache, CTLFLAG_RW, &doingcache, 0, 944dba9e9ccSRobert Watson "Enable name cache"); 945dba9e9ccSRobert Watson 946dba9e9ccSRobert Watson/* 947dba9e9ccSRobert Watson * Example of a variable string value. Notice that the control 948dba9e9ccSRobert Watson * flags are CTLFLAG_RW, that the variable pointer and string 949dba9e9ccSRobert Watson * size are set. Unlike newer sysctls, this older sysctl uses a 950dba9e9ccSRobert Watson * static oid number. 951dba9e9ccSRobert Watson */ 952dba9e9ccSRobert Watsonchar kernelname[MAXPATHLEN] = "/kernel"; /* XXX bloat */ 953dba9e9ccSRobert WatsonSYSCTL_STRING(_kern, KERN_BOOTFILE, bootfile, CTLFLAG_RW, 954dba9e9ccSRobert Watson kernelname, sizeof(kernelname), "Name of kernel file booted"); 955dba9e9ccSRobert Watson 956dba9e9ccSRobert Watson/* 957dba9e9ccSRobert Watson * Example of an opaque data type exported by sysctl. Notice that 958dba9e9ccSRobert Watson * the variable pointer and size are provided, as well as a format 959dba9e9ccSRobert Watson * string for sysctl(8). 960dba9e9ccSRobert Watson */ 9617c64ddd5SWarren Blockstatic l_fp pps_freq; /* scaled frequency offset (ns/s) */ 962dba9e9ccSRobert WatsonSYSCTL_OPAQUE(_kern_ntp_pll, OID_AUTO, pps_freq, CTLFLAG_RD, 963dba9e9ccSRobert Watson &pps_freq, sizeof(pps_freq), "I", ""); 964dba9e9ccSRobert Watson 965dba9e9ccSRobert Watson/* 966dba9e9ccSRobert Watson * Example of a procedure based sysctl exporting string 967dba9e9ccSRobert Watson * information. Notice that the data type is declared, the NULL 968dba9e9ccSRobert Watson * variable pointer and 0 size, the function pointer, and the 969dba9e9ccSRobert Watson * format string for sysctl(8). 970dba9e9ccSRobert Watson */ 971dba9e9ccSRobert WatsonSYSCTL_PROC(_kern_timecounter, OID_AUTO, hardware, CTLTYPE_STRING | 972dba9e9ccSRobert Watson CTLFLAG_RW, NULL, 0, sysctl_kern_timecounter_hardware, "A", 973dba9e9ccSRobert Watson ""); 974dba9e9ccSRobert Watson.Ed 9755eb1caa8SHans Petter Selasky.Pp 9765eb1caa8SHans Petter SelaskyThe following is an example of 9775eb1caa8SHans Petter Selaskyhow to create a new top-level category 9785eb1caa8SHans Petter Selaskyand how to hook up another subtree to an existing static node. 9795eb1caa8SHans Petter SelaskyThis example does not use contexts, 9805eb1caa8SHans Petter Selaskywhich results in tedious management of all intermediate oids, 9815eb1caa8SHans Petter Selaskyas they need to be freed later on: 9825eb1caa8SHans Petter Selasky.Bd -literal -offset indent 9835eb1caa8SHans Petter Selasky#include <sys/sysctl.h> 9845eb1caa8SHans Petter Selasky ... 9855eb1caa8SHans Petter Selasky/* 9865eb1caa8SHans Petter Selasky * Need to preserve pointers to newly created subtrees, 9875eb1caa8SHans Petter Selasky * to be able to free them later: 9885eb1caa8SHans Petter Selasky */ 9895eb1caa8SHans Petter Selaskystatic struct sysctl_oid *root1; 9905eb1caa8SHans Petter Selaskystatic struct sysctl_oid *root2; 9915eb1caa8SHans Petter Selaskystatic struct sysctl_oid *oidp; 9925eb1caa8SHans Petter Selaskystatic int a_int; 9935eb1caa8SHans Petter Selaskystatic char *string = "dynamic sysctl"; 9945eb1caa8SHans Petter Selasky ... 9955eb1caa8SHans Petter Selasky 9965eb1caa8SHans Petter Selaskyroot1 = SYSCTL_ADD_ROOT_NODE(NULL, 9975eb1caa8SHans Petter Selasky OID_AUTO, "newtree", CTLFLAG_RW, 0, "new top level tree"); 9985eb1caa8SHans Petter Selaskyoidp = SYSCTL_ADD_INT(NULL, SYSCTL_CHILDREN(root1), 9995eb1caa8SHans Petter Selasky OID_AUTO, "newint", CTLFLAG_RW, &a_int, 0, "new int leaf"); 10005eb1caa8SHans Petter Selasky ... 10015eb1caa8SHans Petter Selaskyroot2 = SYSCTL_ADD_NODE(NULL, SYSCTL_STATIC_CHILDREN(_debug), 10025eb1caa8SHans Petter Selasky OID_AUTO, "newtree", CTLFLAG_RW, 0, "new tree under debug"); 10035eb1caa8SHans Petter Selaskyoidp = SYSCTL_ADD_STRING(NULL, SYSCTL_CHILDREN(root2), 10045eb1caa8SHans Petter Selasky OID_AUTO, "newstring", CTLFLAG_RD, string, 0, "new string leaf"); 10055eb1caa8SHans Petter Selasky.Ed 10065eb1caa8SHans Petter Selasky.Pp 10075eb1caa8SHans Petter SelaskyThis example creates the following subtrees: 10085eb1caa8SHans Petter Selasky.Bd -literal -offset indent 10095eb1caa8SHans Petter Selaskydebug.newtree.newstring 10105eb1caa8SHans Petter Selaskynewtree.newint 10115eb1caa8SHans Petter Selasky.Ed 10125eb1caa8SHans Petter Selasky.Pp 10135eb1caa8SHans Petter Selasky.Em "Care should be taken to free all OIDs once they are no longer needed!" 101491f3a6dbSYaroslav Tykhiy.Sh SYSCTL NAMING 1015dba9e9ccSRobert WatsonWhen adding, modifying, or removing sysctl names, it is important to be 1016dba9e9ccSRobert Watsonaware that these interfaces may be used by users, libraries, applications, 1017f4006affSGiorgos Keramidasor documentation (such as published books), and are implicitly published application interfaces. 1018dba9e9ccSRobert WatsonAs with other application interfaces, caution must be taken not to break 1019dba9e9ccSRobert Watsonexisting applications, and to think about future use of new name spaces so as 1020dba9e9ccSRobert Watsonto avoid the need to rename or remove interfaces that might be depended on in 1021dba9e9ccSRobert Watsonthe future. 102291f3a6dbSYaroslav Tykhiy.Pp 102391f3a6dbSYaroslav TykhiyThe semantics chosen for a new sysctl should be as clear as possible, 102491f3a6dbSYaroslav Tykhiyand the name of the sysctl must closely reflect its semantics. 102591f3a6dbSYaroslav TykhiyTherefore the sysctl name deserves a fair amount of consideration. 102691f3a6dbSYaroslav TykhiyIt should be short but yet representative of the sysctl meaning. 102791f3a6dbSYaroslav TykhiyIf the name consists of several words, they should be separated by 102891f3a6dbSYaroslav Tykhiyunderscore characters, as in 102991f3a6dbSYaroslav Tykhiy.Va compute_summary_at_mount . 103091f3a6dbSYaroslav TykhiyUnderscore characters may be omitted only if the name consists of not more 103191f3a6dbSYaroslav Tykhiythan two words, each being not longer than four characters, as in 103291f3a6dbSYaroslav Tykhiy.Va bootfile . 1033dff1ba09SEd Maste.Pp 103491f3a6dbSYaroslav TykhiyFor boolean sysctls, negative logic should be totally avoided. 103591f3a6dbSYaroslav TykhiyThat is, do not use names like 103691f3a6dbSYaroslav Tykhiy.Va no_foobar 103791f3a6dbSYaroslav Tykhiyor 103891f3a6dbSYaroslav Tykhiy.Va foobar_disable . 103991f3a6dbSYaroslav TykhiyThey are confusing and lead to configuration errors. 104091f3a6dbSYaroslav TykhiyUse positive logic instead: 104191f3a6dbSYaroslav Tykhiy.Va foobar , 104291f3a6dbSYaroslav Tykhiy.Va foobar_enable . 104391f3a6dbSYaroslav Tykhiy.Pp 10445eb1caa8SHans Petter SelaskyA temporary sysctl node OID that should not be relied upon must be designated 10457851d429SEdward Tomasz Napieralaas such by a leading underscore character in its name. 10467851d429SEdward Tomasz NapieralaFor example: 104791f3a6dbSYaroslav Tykhiy.Va _dirty_hack . 1048dba9e9ccSRobert Watson.Sh SEE ALSO 1049f3066f2bSGavin Atkinson.Xr sysctl 3 , 1050dba9e9ccSRobert Watson.Xr sysctl 8 , 1051df94ce0fSJohn-Mark Gurney.Xr device_get_sysctl 9 , 1052dba9e9ccSRobert Watson.Xr sysctl_add_oid 9 , 1053dba9e9ccSRobert Watson.Xr sysctl_ctx_free 9 , 1054dba9e9ccSRobert Watson.Xr sysctl_ctx_init 9 , 1055dba9e9ccSRobert Watson.Xr sysctl_remove_oid 9 1056dba9e9ccSRobert Watson.Sh HISTORY 1057bd84dd2fSRuslan ErmilovThe 1058dba9e9ccSRobert Watson.Xr sysctl 8 1059bd84dd2fSRuslan Ermilovutility first appeared in 1060dba9e9ccSRobert Watson.Bx 4.4 . 1061*6e77fccfSDavid E. O'Brien.Nm SYSCTL_ADD_CONST_STRING 1062*6e77fccfSDavid E. O'Brienfirst appeared in 1063*6e77fccfSDavid E. O'Brien.Fx 12.1 . 1064dba9e9ccSRobert Watson.Sh AUTHORS 1065bd84dd2fSRuslan Ermilov.An -nosplit 1066bd84dd2fSRuslan ErmilovThe 1067bd84dd2fSRuslan Ermilov.Nm sysctl 1068bd84dd2fSRuslan Ermilovimplementation originally found in 1069dba9e9ccSRobert Watson.Bx 1070dba9e9ccSRobert Watsonhas been extensively rewritten by 1071dba9e9ccSRobert Watson.An Poul-Henning Kamp 1072dba9e9ccSRobert Watsonin order to add support for name lookups, name space iteration, and dynamic 1073dba9e9ccSRobert Watsonaddition of MIB nodes. 1074dba9e9ccSRobert Watson.Pp 1075dba9e9ccSRobert WatsonThis man page was written by 1076dba9e9ccSRobert Watson.An Robert N. M. Watson . 10773edc2b53SJoel Dahl.Sh SECURITY CONSIDERATIONS 10783edc2b53SJoel DahlWhen creating new sysctls, careful attention should be paid to the security 10793edc2b53SJoel Dahlimplications of the monitoring or management interface being created. 10803edc2b53SJoel DahlMost sysctls present in the kernel are read-only or writable only by the 10813edc2b53SJoel Dahlsuperuser. 10823edc2b53SJoel DahlSysctls exporting extensive information on system data structures and 10833edc2b53SJoel Dahloperation, especially those implemented using procedures, will wish to 10843edc2b53SJoel Dahlimplement access control to limit the undesired exposure of information about 10853edc2b53SJoel Dahlother processes, network connections, etc. 10863edc2b53SJoel Dahl.Pp 10873edc2b53SJoel DahlThe following top level sysctl name spaces are commonly used: 10883edc2b53SJoel Dahl.Bl -tag -width ".Va regression" 10893edc2b53SJoel Dahl.It Va compat 10903edc2b53SJoel DahlCompatibility layer information. 10913edc2b53SJoel Dahl.It Va debug 10923edc2b53SJoel DahlDebugging information. 10933edc2b53SJoel DahlVarious name spaces exist under 10943edc2b53SJoel Dahl.Va debug . 10953edc2b53SJoel Dahl.It Va hw 10963edc2b53SJoel DahlHardware and device driver information. 10973edc2b53SJoel Dahl.It Va kern 10983edc2b53SJoel DahlKernel behavior tuning; generally deprecated in favor of more specific 10993edc2b53SJoel Dahlname spaces. 11003edc2b53SJoel Dahl.It Va machdep 11013edc2b53SJoel DahlMachine-dependent configuration parameters. 11023edc2b53SJoel Dahl.It Va net 11033edc2b53SJoel DahlNetwork subsystem. 11043edc2b53SJoel DahlVarious protocols have name spaces under 11053edc2b53SJoel Dahl.Va net . 11063edc2b53SJoel Dahl.It Va regression 11073edc2b53SJoel DahlRegression test configuration and information. 11083edc2b53SJoel Dahl.It Va security 11093edc2b53SJoel DahlSecurity and security-policy configuration and information. 11103edc2b53SJoel Dahl.It Va sysctl 11113edc2b53SJoel DahlReserved name space for the implementation of sysctl. 11123edc2b53SJoel Dahl.It Va user 11133edc2b53SJoel DahlConfiguration settings relating to user application behavior. 11143edc2b53SJoel DahlGenerally, configuring applications using kernel sysctls is discouraged. 11153edc2b53SJoel Dahl.It Va vfs 11163edc2b53SJoel DahlVirtual file system configuration and information. 11173edc2b53SJoel Dahl.It Va vm 11183edc2b53SJoel DahlVirtual memory subsystem configuration and information. 11193edc2b53SJoel Dahl.El 1120