1/*- 2 * SPDX-License-Identifier: BSD-3-Clause 3 * 4 * Copyright (c) 1989, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Mike Karels at Berkeley Software Design, Inc. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. Neither the name of the University nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)sysctl.h 8.1 (Berkeley) 6/2/93 35 * $FreeBSD$ 36 */ 37 38#ifndef _SYS_SYSCTL_H_ 39#define _SYS_SYSCTL_H_ 40 41#ifdef _KERNEL 42#include <sys/queue.h> 43#endif 44 45struct thread; 46/* 47 * Definitions for sysctl call. The sysctl call uses a hierarchical name 48 * for objects that can be examined or modified. The name is expressed as 49 * a sequence of integers. Like a file path name, the meaning of each 50 * component depends on its place in the hierarchy. The top-level and kern 51 * identifiers are defined here, and other identifiers are defined in the 52 * respective subsystem header files. 53 */ 54 55#define CTL_MAXNAME 24 /* largest number of components supported */ 56 57/* 58 * Each subsystem defined by sysctl defines a list of variables 59 * for that subsystem. Each name is either a node with further 60 * levels defined below it, or it is a leaf of some particular 61 * type given below. Each sysctl level defines a set of name/type 62 * pairs to be used by sysctl(8) in manipulating the subsystem. 63 */ 64struct ctlname { 65 char *ctl_name; /* subsystem name */ 66 int ctl_type; /* type of name */ 67}; 68 69#define CTLTYPE 0xf /* mask for the type */ 70#define CTLTYPE_NODE 1 /* name is a node */ 71#define CTLTYPE_INT 2 /* name describes an integer */ 72#define CTLTYPE_STRING 3 /* name describes a string */ 73#define CTLTYPE_S64 4 /* name describes a signed 64-bit number */ 74#define CTLTYPE_OPAQUE 5 /* name describes a structure */ 75#define CTLTYPE_STRUCT CTLTYPE_OPAQUE /* name describes a structure */ 76#define CTLTYPE_UINT 6 /* name describes an unsigned integer */ 77#define CTLTYPE_LONG 7 /* name describes a long */ 78#define CTLTYPE_ULONG 8 /* name describes an unsigned long */ 79#define CTLTYPE_U64 9 /* name describes an unsigned 64-bit number */ 80#define CTLTYPE_U8 0xa /* name describes an unsigned 8-bit number */ 81#define CTLTYPE_U16 0xb /* name describes an unsigned 16-bit number */ 82#define CTLTYPE_S8 0xc /* name describes a signed 8-bit number */ 83#define CTLTYPE_S16 0xd /* name describes a signed 16-bit number */ 84#define CTLTYPE_S32 0xe /* name describes a signed 32-bit number */ 85#define CTLTYPE_U32 0xf /* name describes an unsigned 32-bit number */ 86 87#define CTLFLAG_RD 0x80000000 /* Allow reads of variable */ 88#define CTLFLAG_WR 0x40000000 /* Allow writes to the variable */ 89#define CTLFLAG_RW (CTLFLAG_RD|CTLFLAG_WR) 90#define CTLFLAG_DORMANT 0x20000000 /* This sysctl is not active yet */ 91#define CTLFLAG_ANYBODY 0x10000000 /* All users can set this var */ 92#define CTLFLAG_SECURE 0x08000000 /* Permit set only if securelevel<=0 */ 93#define CTLFLAG_PRISON 0x04000000 /* Prisoned roots can fiddle */ 94#define CTLFLAG_DYN 0x02000000 /* Dynamic oid - can be freed */ 95#define CTLFLAG_SKIP 0x01000000 /* Skip this sysctl when listing */ 96#define CTLMASK_SECURE 0x00F00000 /* Secure level */ 97#define CTLFLAG_TUN 0x00080000 /* Default value is loaded from getenv() */ 98#define CTLFLAG_RDTUN (CTLFLAG_RD|CTLFLAG_TUN) 99#define CTLFLAG_RWTUN (CTLFLAG_RW|CTLFLAG_TUN) 100#define CTLFLAG_MPSAFE 0x00040000 /* Handler is MP safe */ 101#define CTLFLAG_VNET 0x00020000 /* Prisons with vnet can fiddle */ 102#define CTLFLAG_DYING 0x00010000 /* Oid is being removed */ 103#define CTLFLAG_CAPRD 0x00008000 /* Can be read in capability mode */ 104#define CTLFLAG_CAPWR 0x00004000 /* Can be written in capability mode */ 105#define CTLFLAG_STATS 0x00002000 /* Statistics, not a tuneable */ 106#define CTLFLAG_NOFETCH 0x00001000 /* Don't fetch tunable from getenv() */ 107#define CTLFLAG_CAPRW (CTLFLAG_CAPRD|CTLFLAG_CAPWR) 108/* 109 * This is transient flag to be used until all sysctl handlers are converted 110 * to not lock Giant. 111 * One, and only one of CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT is required 112 * for SYSCTL_PROC and SYSCTL_NODE. 113 */ 114#define CTLFLAG_NEEDGIANT 0x00000800 /* Handler require Giant */ 115 116/* 117 * Secure level. Note that CTLFLAG_SECURE == CTLFLAG_SECURE1. 118 * 119 * Secure when the securelevel is raised to at least N. 120 */ 121#define CTLSHIFT_SECURE 20 122#define CTLFLAG_SECURE1 (CTLFLAG_SECURE | (0 << CTLSHIFT_SECURE)) 123#define CTLFLAG_SECURE2 (CTLFLAG_SECURE | (1 << CTLSHIFT_SECURE)) 124#define CTLFLAG_SECURE3 (CTLFLAG_SECURE | (2 << CTLSHIFT_SECURE)) 125 126/* 127 * USE THIS instead of a hardwired number from the categories below 128 * to get dynamically assigned sysctl entries using the linker-set 129 * technology. This is the way nearly all new sysctl variables should 130 * be implemented. 131 * e.g. SYSCTL_INT(_parent, OID_AUTO, name, CTLFLAG_RW, &variable, 0, ""); 132 */ 133#define OID_AUTO (-1) 134 135/* 136 * The starting number for dynamically-assigned entries. WARNING! 137 * ALL static sysctl entries should have numbers LESS than this! 138 */ 139#define CTL_AUTO_START 0x100 140 141#ifdef _KERNEL 142#include <sys/linker_set.h> 143 144#ifdef KLD_MODULE 145/* XXX allow overspecification of type in external kernel modules */ 146#define SYSCTL_CT_ASSERT_MASK CTLTYPE 147#else 148#define SYSCTL_CT_ASSERT_MASK 0 149#endif 150 151#define SYSCTL_HANDLER_ARGS struct sysctl_oid *oidp, void *arg1, \ 152 intmax_t arg2, struct sysctl_req *req 153 154/* definitions for sysctl_req 'lock' member */ 155#define REQ_UNWIRED 1 156#define REQ_WIRED 2 157 158/* definitions for sysctl_req 'flags' member */ 159#ifdef COMPAT_FREEBSD32 160#define SCTL_MASK32 1 /* 32 bit emulation */ 161#endif 162 163/* 164 * This describes the access space for a sysctl request. This is needed 165 * so that we can use the interface from the kernel or from user-space. 166 */ 167struct sysctl_req { 168 struct thread *td; /* used for access checking */ 169 int lock; /* wiring state */ 170 void *oldptr; 171 size_t oldlen; 172 size_t oldidx; 173 int (*oldfunc)(struct sysctl_req *, const void *, size_t); 174 const void *newptr; 175 size_t newlen; 176 size_t newidx; 177 int (*newfunc)(struct sysctl_req *, void *, size_t); 178 size_t validlen; 179 int flags; 180}; 181 182SLIST_HEAD(sysctl_oid_list, sysctl_oid); 183 184/* 185 * This describes one "oid" in the MIB tree. Potentially more nodes can 186 * be hidden behind it, expanded by the handler. 187 */ 188struct sysctl_oid { 189 struct sysctl_oid_list oid_children; 190 struct sysctl_oid_list *oid_parent; 191 SLIST_ENTRY(sysctl_oid) oid_link; 192 int oid_number; 193 u_int oid_kind; 194 void *oid_arg1; 195 intmax_t oid_arg2; 196 const char *oid_name; 197 int (*oid_handler)(SYSCTL_HANDLER_ARGS); 198 const char *oid_fmt; 199 int oid_refcnt; 200 u_int oid_running; 201 const char *oid_descr; 202 const char *oid_label; 203}; 204 205#define SYSCTL_IN(r, p, l) (r->newfunc)(r, p, l) 206#define SYSCTL_OUT(r, p, l) (r->oldfunc)(r, p, l) 207#define SYSCTL_OUT_STR(r, p) (r->oldfunc)(r, p, strlen(p) + 1) 208 209int sysctl_handle_bool(SYSCTL_HANDLER_ARGS); 210int sysctl_handle_8(SYSCTL_HANDLER_ARGS); 211int sysctl_handle_16(SYSCTL_HANDLER_ARGS); 212int sysctl_handle_32(SYSCTL_HANDLER_ARGS); 213int sysctl_handle_64(SYSCTL_HANDLER_ARGS); 214int sysctl_handle_int(SYSCTL_HANDLER_ARGS); 215int sysctl_msec_to_ticks(SYSCTL_HANDLER_ARGS); 216int sysctl_handle_long(SYSCTL_HANDLER_ARGS); 217int sysctl_handle_string(SYSCTL_HANDLER_ARGS); 218int sysctl_handle_opaque(SYSCTL_HANDLER_ARGS); 219int sysctl_handle_counter_u64(SYSCTL_HANDLER_ARGS); 220int sysctl_handle_counter_u64_array(SYSCTL_HANDLER_ARGS); 221 222int sysctl_handle_uma_zone_max(SYSCTL_HANDLER_ARGS); 223int sysctl_handle_uma_zone_cur(SYSCTL_HANDLER_ARGS); 224 225int sysctl_msec_to_sbintime(SYSCTL_HANDLER_ARGS); 226int sysctl_usec_to_sbintime(SYSCTL_HANDLER_ARGS); 227int sysctl_sec_to_timeval(SYSCTL_HANDLER_ARGS); 228 229int sysctl_dpcpu_int(SYSCTL_HANDLER_ARGS); 230int sysctl_dpcpu_long(SYSCTL_HANDLER_ARGS); 231int sysctl_dpcpu_quad(SYSCTL_HANDLER_ARGS); 232 233/* 234 * These functions are used to add/remove an oid from the mib. 235 */ 236void sysctl_register_oid(struct sysctl_oid *oidp); 237void sysctl_register_disabled_oid(struct sysctl_oid *oidp); 238void sysctl_enable_oid(struct sysctl_oid *oidp); 239void sysctl_unregister_oid(struct sysctl_oid *oidp); 240 241/* Declare a static oid to allow child oids to be added to it. */ 242#define SYSCTL_DECL(name) \ 243 extern struct sysctl_oid sysctl__##name 244 245/* Hide these in macros. */ 246#define SYSCTL_CHILDREN(oid_ptr) (&(oid_ptr)->oid_children) 247#define SYSCTL_PARENT(oid_ptr) \ 248 (((oid_ptr)->oid_parent != &sysctl__children) ? \ 249 __containerof((oid_ptr)->oid_parent, struct sysctl_oid, \ 250 oid_children) : (struct sysctl_oid *)NULL) 251#define SYSCTL_STATIC_CHILDREN(oid_name) (&sysctl__##oid_name.oid_children) 252 253/* === Structs and macros related to context handling. === */ 254 255/* All dynamically created sysctls can be tracked in a context list. */ 256struct sysctl_ctx_entry { 257 struct sysctl_oid *entry; 258 TAILQ_ENTRY(sysctl_ctx_entry) link; 259}; 260 261TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); 262 263#define SYSCTL_NODE_CHILDREN(parent, name) \ 264 sysctl__##parent##_##name.oid_children 265 266#ifndef NO_SYSCTL_DESCR 267#define __DESCR(d) d 268#else 269#define __DESCR(d) "" 270#endif 271 272#ifdef notyet 273#define SYSCTL_ENFORCE_FLAGS(x) \ 274 _Static_assert((((x) & CTLFLAG_MPSAFE) != 0) ^ (((x) & CTLFLAG_NEEDGIANT) != 0), \ 275 "Has to be either CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT") 276#else 277#define SYSCTL_ENFORCE_FLAGS(x) 278#endif 279 280/* This macro is only for internal use */ 281#define SYSCTL_OID_RAW(id, parent_child_head, nbr, name, kind, a1, a2, handler, fmt, descr, label) \ 282 struct sysctl_oid id = { \ 283 .oid_parent = (parent_child_head), \ 284 .oid_children = SLIST_HEAD_INITIALIZER(&id.oid_children), \ 285 .oid_number = (nbr), \ 286 .oid_kind = (kind), \ 287 .oid_arg1 = (a1), \ 288 .oid_arg2 = (a2), \ 289 .oid_name = (name), \ 290 .oid_handler = (handler), \ 291 .oid_fmt = (fmt), \ 292 .oid_descr = __DESCR(descr), \ 293 .oid_label = (label), \ 294 }; \ 295 DATA_SET(sysctl_set, id); \ 296 SYSCTL_ENFORCE_FLAGS(kind) 297 298/* This constructs a static "raw" MIB oid. */ 299#define SYSCTL_OID(parent, nbr, name, kind, a1, a2, handler, fmt, descr) \ 300 SYSCTL_OID_WITH_LABEL(parent, nbr, name, kind, a1, a2, \ 301 handler, fmt, descr, NULL) 302 303#define SYSCTL_OID_WITH_LABEL(parent, nbr, name, kind, a1, a2, handler, fmt, descr, label) \ 304 static SYSCTL_OID_RAW(sysctl__##parent##_##name, \ 305 SYSCTL_CHILDREN(&sysctl__##parent), \ 306 nbr, #name, kind, a1, a2, handler, fmt, descr, label) 307 308/* This constructs a global "raw" MIB oid. */ 309#define SYSCTL_OID_GLOBAL(parent, nbr, name, kind, a1, a2, handler, fmt, descr, label) \ 310 SYSCTL_OID_RAW(sysctl__##parent##_##name, \ 311 SYSCTL_CHILDREN(&sysctl__##parent), \ 312 nbr, #name, kind, a1, a2, handler, fmt, descr, label) 313 314#define SYSCTL_ADD_OID(ctx, parent, nbr, name, kind, a1, a2, handler, fmt, descr) \ 315({ \ 316 SYSCTL_ENFORCE_FLAGS(kind); \ 317 sysctl_add_oid(ctx, parent, nbr, name, kind, a1, a2,handler, \ 318 fmt, __DESCR(descr), NULL); \ 319}) 320 321/* This constructs a root node from which other nodes can hang. */ 322#define SYSCTL_ROOT_NODE(nbr, name, access, handler, descr) \ 323 SYSCTL_OID_RAW(sysctl___##name, &sysctl__children, \ 324 nbr, #name, CTLTYPE_NODE|(access), NULL, 0, \ 325 handler, "N", descr, NULL); \ 326 CTASSERT(((access) & CTLTYPE) == 0 || \ 327 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE) 328 329/* This constructs a node from which other oids can hang. */ 330#define SYSCTL_NODE(parent, nbr, name, access, handler, descr) \ 331 SYSCTL_NODE_WITH_LABEL(parent, nbr, name, access, handler, descr, NULL) 332 333#define SYSCTL_NODE_WITH_LABEL(parent, nbr, name, access, handler, descr, label) \ 334 SYSCTL_OID_GLOBAL(parent, nbr, name, CTLTYPE_NODE|(access), \ 335 NULL, 0, handler, "N", descr, label); \ 336 SYSCTL_ENFORCE_FLAGS(access); \ 337 CTASSERT(((access) & CTLTYPE) == 0 || \ 338 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE) 339 340#define SYSCTL_ADD_NODE(ctx, parent, nbr, name, access, handler, descr) \ 341 SYSCTL_ADD_NODE_WITH_LABEL(ctx, parent, nbr, name, access, \ 342 handler, descr, NULL) 343 344#define SYSCTL_ADD_NODE_WITH_LABEL(ctx, parent, nbr, name, access, handler, descr, label) \ 345({ \ 346 CTASSERT(((access) & CTLTYPE) == 0 || \ 347 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE); \ 348 SYSCTL_ENFORCE_FLAGS(access); \ 349 sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_NODE|(access), \ 350 NULL, 0, handler, "N", __DESCR(descr), label); \ 351}) 352 353#define SYSCTL_ADD_ROOT_NODE(ctx, nbr, name, access, handler, descr) \ 354({ \ 355 CTASSERT(((access) & CTLTYPE) == 0 || \ 356 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE); \ 357 SYSCTL_ENFORCE_FLAGS(access); \ 358 sysctl_add_oid(ctx, &sysctl__children, nbr, name, \ 359 CTLTYPE_NODE|(access), \ 360 NULL, 0, handler, "N", __DESCR(descr), NULL); \ 361}) 362 363/* Oid for a string. len can be 0 to indicate '\0' termination. */ 364#define SYSCTL_STRING(parent, nbr, name, access, arg, len, descr) \ 365 SYSCTL_OID(parent, nbr, name, \ 366 CTLTYPE_STRING | CTLFLAG_MPSAFE | (access), \ 367 arg, len, sysctl_handle_string, "A", descr); \ 368 CTASSERT(((access) & CTLTYPE) == 0 || \ 369 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_STRING) 370 371#define SYSCTL_ADD_STRING(ctx, parent, nbr, name, access, arg, len, descr) \ 372({ \ 373 char *__arg = (arg); \ 374 CTASSERT(((access) & CTLTYPE) == 0 || \ 375 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_STRING); \ 376 sysctl_add_oid(ctx, parent, nbr, name, \ 377 CTLTYPE_STRING | CTLFLAG_MPSAFE | (access), \ 378 __arg, len, sysctl_handle_string, "A", __DESCR(descr), \ 379 NULL); \ 380}) 381 382/* Oid for a constant '\0' terminated string. */ 383#define SYSCTL_CONST_STRING(parent, nbr, name, access, arg, descr) \ 384 SYSCTL_OID(parent, nbr, name, CTLTYPE_STRING | CTLFLAG_MPSAFE | (access),\ 385 __DECONST(char *, arg), 0, sysctl_handle_string, "A", descr); \ 386 CTASSERT(!(access & CTLFLAG_WR)); \ 387 CTASSERT(((access) & CTLTYPE) == 0 || \ 388 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_STRING) 389 390#define SYSCTL_ADD_CONST_STRING(ctx, parent, nbr, name, access, arg, descr) \ 391({ \ 392 char *__arg = __DECONST(char *, arg); \ 393 CTASSERT(!(access & CTLFLAG_WR)); \ 394 CTASSERT(((access) & CTLTYPE) == 0 || \ 395 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_STRING); \ 396 sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_STRING | \ 397 CTLFLAG_MPSAFE | (access), __arg, 0, sysctl_handle_string, "A",\ 398 __DESCR(descr), NULL); \ 399}) 400 401/* Oid for a bool. If ptr is NULL, val is returned. */ 402#define SYSCTL_NULL_BOOL_PTR ((bool *)NULL) 403#define SYSCTL_BOOL(parent, nbr, name, access, ptr, val, descr) \ 404 SYSCTL_OID(parent, nbr, name, \ 405 CTLTYPE_U8 | CTLFLAG_MPSAFE | (access), \ 406 ptr, val, sysctl_handle_bool, "CU", descr); \ 407 CTASSERT(((access) & CTLTYPE) == 0 && \ 408 sizeof(bool) == sizeof(*(ptr))) 409 410#define SYSCTL_ADD_BOOL(ctx, parent, nbr, name, access, ptr, val, descr) \ 411({ \ 412 bool *__ptr = (ptr); \ 413 CTASSERT(((access) & CTLTYPE) == 0); \ 414 sysctl_add_oid(ctx, parent, nbr, name, \ 415 CTLTYPE_U8 | CTLFLAG_MPSAFE | (access), \ 416 __ptr, val, sysctl_handle_bool, "CU", __DESCR(descr), \ 417 NULL); \ 418}) 419 420/* Oid for a signed 8-bit int. If ptr is NULL, val is returned. */ 421#define SYSCTL_NULL_S8_PTR ((int8_t *)NULL) 422#define SYSCTL_S8(parent, nbr, name, access, ptr, val, descr) \ 423 SYSCTL_OID(parent, nbr, name, \ 424 CTLTYPE_S8 | CTLFLAG_MPSAFE | (access), \ 425 ptr, val, sysctl_handle_8, "C", descr); \ 426 CTASSERT((((access) & CTLTYPE) == 0 || \ 427 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S8) && \ 428 sizeof(int8_t) == sizeof(*(ptr))) 429 430#define SYSCTL_ADD_S8(ctx, parent, nbr, name, access, ptr, val, descr) \ 431({ \ 432 int8_t *__ptr = (ptr); \ 433 CTASSERT(((access) & CTLTYPE) == 0 || \ 434 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S8); \ 435 sysctl_add_oid(ctx, parent, nbr, name, \ 436 CTLTYPE_S8 | CTLFLAG_MPSAFE | (access), \ 437 __ptr, val, sysctl_handle_8, "C", __DESCR(descr), NULL); \ 438}) 439 440/* Oid for an unsigned 8-bit int. If ptr is NULL, val is returned. */ 441#define SYSCTL_NULL_U8_PTR ((uint8_t *)NULL) 442#define SYSCTL_U8(parent, nbr, name, access, ptr, val, descr) \ 443 SYSCTL_OID(parent, nbr, name, \ 444 CTLTYPE_U8 | CTLFLAG_MPSAFE | (access), \ 445 ptr, val, sysctl_handle_8, "CU", descr); \ 446 CTASSERT((((access) & CTLTYPE) == 0 || \ 447 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U8) && \ 448 sizeof(uint8_t) == sizeof(*(ptr))) 449 450#define SYSCTL_ADD_U8(ctx, parent, nbr, name, access, ptr, val, descr) \ 451({ \ 452 uint8_t *__ptr = (ptr); \ 453 CTASSERT(((access) & CTLTYPE) == 0 || \ 454 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U8); \ 455 sysctl_add_oid(ctx, parent, nbr, name, \ 456 CTLTYPE_U8 | CTLFLAG_MPSAFE | (access), \ 457 __ptr, val, sysctl_handle_8, "CU", __DESCR(descr), NULL); \ 458}) 459 460/* Oid for a signed 16-bit int. If ptr is NULL, val is returned. */ 461#define SYSCTL_NULL_S16_PTR ((int16_t *)NULL) 462#define SYSCTL_S16(parent, nbr, name, access, ptr, val, descr) \ 463 SYSCTL_OID(parent, nbr, name, \ 464 CTLTYPE_S16 | CTLFLAG_MPSAFE | (access), \ 465 ptr, val, sysctl_handle_16, "S", descr); \ 466 CTASSERT((((access) & CTLTYPE) == 0 || \ 467 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S16) && \ 468 sizeof(int16_t) == sizeof(*(ptr))) 469 470#define SYSCTL_ADD_S16(ctx, parent, nbr, name, access, ptr, val, descr) \ 471({ \ 472 int16_t *__ptr = (ptr); \ 473 CTASSERT(((access) & CTLTYPE) == 0 || \ 474 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S16); \ 475 sysctl_add_oid(ctx, parent, nbr, name, \ 476 CTLTYPE_S16 | CTLFLAG_MPSAFE | (access), \ 477 __ptr, val, sysctl_handle_16, "S", __DESCR(descr), NULL); \ 478}) 479 480/* Oid for an unsigned 16-bit int. If ptr is NULL, val is returned. */ 481#define SYSCTL_NULL_U16_PTR ((uint16_t *)NULL) 482#define SYSCTL_U16(parent, nbr, name, access, ptr, val, descr) \ 483 SYSCTL_OID(parent, nbr, name, \ 484 CTLTYPE_U16 | CTLFLAG_MPSAFE | (access), \ 485 ptr, val, sysctl_handle_16, "SU", descr); \ 486 CTASSERT((((access) & CTLTYPE) == 0 || \ 487 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U16) && \ 488 sizeof(uint16_t) == sizeof(*(ptr))) 489 490#define SYSCTL_ADD_U16(ctx, parent, nbr, name, access, ptr, val, descr) \ 491({ \ 492 uint16_t *__ptr = (ptr); \ 493 CTASSERT(((access) & CTLTYPE) == 0 || \ 494 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U16); \ 495 sysctl_add_oid(ctx, parent, nbr, name, \ 496 CTLTYPE_U16 | CTLFLAG_MPSAFE | (access), \ 497 __ptr, val, sysctl_handle_16, "SU", __DESCR(descr), NULL); \ 498}) 499 500/* Oid for a signed 32-bit int. If ptr is NULL, val is returned. */ 501#define SYSCTL_NULL_S32_PTR ((int32_t *)NULL) 502#define SYSCTL_S32(parent, nbr, name, access, ptr, val, descr) \ 503 SYSCTL_OID(parent, nbr, name, \ 504 CTLTYPE_S32 | CTLFLAG_MPSAFE | (access), \ 505 ptr, val, sysctl_handle_32, "I", descr); \ 506 CTASSERT((((access) & CTLTYPE) == 0 || \ 507 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S32) && \ 508 sizeof(int32_t) == sizeof(*(ptr))) 509 510#define SYSCTL_ADD_S32(ctx, parent, nbr, name, access, ptr, val, descr) \ 511({ \ 512 int32_t *__ptr = (ptr); \ 513 CTASSERT(((access) & CTLTYPE) == 0 || \ 514 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S32); \ 515 sysctl_add_oid(ctx, parent, nbr, name, \ 516 CTLTYPE_S32 | CTLFLAG_MPSAFE | (access), \ 517 __ptr, val, sysctl_handle_32, "I", __DESCR(descr), NULL); \ 518}) 519 520/* Oid for an unsigned 32-bit int. If ptr is NULL, val is returned. */ 521#define SYSCTL_NULL_U32_PTR ((uint32_t *)NULL) 522#define SYSCTL_U32(parent, nbr, name, access, ptr, val, descr) \ 523 SYSCTL_OID(parent, nbr, name, \ 524 CTLTYPE_U32 | CTLFLAG_MPSAFE | (access), \ 525 ptr, val, sysctl_handle_32, "IU", descr); \ 526 CTASSERT((((access) & CTLTYPE) == 0 || \ 527 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U32) && \ 528 sizeof(uint32_t) == sizeof(*(ptr))) 529 530#define SYSCTL_ADD_U32(ctx, parent, nbr, name, access, ptr, val, descr) \ 531({ \ 532 uint32_t *__ptr = (ptr); \ 533 CTASSERT(((access) & CTLTYPE) == 0 || \ 534 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U32); \ 535 sysctl_add_oid(ctx, parent, nbr, name, \ 536 CTLTYPE_U32 | CTLFLAG_MPSAFE | (access), \ 537 __ptr, val, sysctl_handle_32, "IU", __DESCR(descr), NULL); \ 538}) 539 540/* Oid for a signed 64-bit int. If ptr is NULL, val is returned. */ 541#define SYSCTL_NULL_S64_PTR ((int64_t *)NULL) 542#define SYSCTL_S64(parent, nbr, name, access, ptr, val, descr) \ 543 SYSCTL_OID(parent, nbr, name, \ 544 CTLTYPE_S64 | CTLFLAG_MPSAFE | (access), \ 545 ptr, val, sysctl_handle_64, "Q", descr); \ 546 CTASSERT((((access) & CTLTYPE) == 0 || \ 547 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64) && \ 548 sizeof(int64_t) == sizeof(*(ptr))) 549 550#define SYSCTL_ADD_S64(ctx, parent, nbr, name, access, ptr, val, descr) \ 551({ \ 552 int64_t *__ptr = (ptr); \ 553 CTASSERT(((access) & CTLTYPE) == 0 || \ 554 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64); \ 555 sysctl_add_oid(ctx, parent, nbr, name, \ 556 CTLTYPE_S64 | CTLFLAG_MPSAFE | (access), \ 557 __ptr, val, sysctl_handle_64, "Q", __DESCR(descr), NULL); \ 558}) 559 560/* Oid for an unsigned 64-bit int. If ptr is NULL, val is returned. */ 561#define SYSCTL_NULL_U64_PTR ((uint64_t *)NULL) 562#define SYSCTL_U64(parent, nbr, name, access, ptr, val, descr) \ 563 SYSCTL_OID(parent, nbr, name, \ 564 CTLTYPE_U64 | CTLFLAG_MPSAFE | (access), \ 565 ptr, val, sysctl_handle_64, "QU", descr); \ 566 CTASSERT((((access) & CTLTYPE) == 0 || \ 567 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64) && \ 568 sizeof(uint64_t) == sizeof(*(ptr))) 569 570#define SYSCTL_ADD_U64(ctx, parent, nbr, name, access, ptr, val, descr) \ 571({ \ 572 uint64_t *__ptr = (ptr); \ 573 CTASSERT(((access) & CTLTYPE) == 0 || \ 574 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64); \ 575 sysctl_add_oid(ctx, parent, nbr, name, \ 576 CTLTYPE_U64 | CTLFLAG_MPSAFE | (access), \ 577 __ptr, val, sysctl_handle_64, "QU", __DESCR(descr), NULL); \ 578}) 579 580/* Oid for an int. If ptr is SYSCTL_NULL_INT_PTR, val is returned. */ 581#define SYSCTL_NULL_INT_PTR ((int *)NULL) 582#define SYSCTL_INT(parent, nbr, name, access, ptr, val, descr) \ 583 SYSCTL_INT_WITH_LABEL(parent, nbr, name, access, ptr, val, descr, NULL) 584 585#define SYSCTL_INT_WITH_LABEL(parent, nbr, name, access, ptr, val, descr, label) \ 586 SYSCTL_OID_WITH_LABEL(parent, nbr, name, \ 587 CTLTYPE_INT | CTLFLAG_MPSAFE | (access), \ 588 ptr, val, sysctl_handle_int, "I", descr, label); \ 589 CTASSERT((((access) & CTLTYPE) == 0 || \ 590 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT) && \ 591 sizeof(int) == sizeof(*(ptr))) 592 593#define SYSCTL_ADD_INT(ctx, parent, nbr, name, access, ptr, val, descr) \ 594({ \ 595 int *__ptr = (ptr); \ 596 CTASSERT(((access) & CTLTYPE) == 0 || \ 597 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT); \ 598 sysctl_add_oid(ctx, parent, nbr, name, \ 599 CTLTYPE_INT | CTLFLAG_MPSAFE | (access), \ 600 __ptr, val, sysctl_handle_int, "I", __DESCR(descr), NULL); \ 601}) 602 603/* Oid for an unsigned int. If ptr is NULL, val is returned. */ 604#define SYSCTL_NULL_UINT_PTR ((unsigned *)NULL) 605#define SYSCTL_UINT(parent, nbr, name, access, ptr, val, descr) \ 606 SYSCTL_OID(parent, nbr, name, \ 607 CTLTYPE_UINT | CTLFLAG_MPSAFE | (access), \ 608 ptr, val, sysctl_handle_int, "IU", descr); \ 609 CTASSERT((((access) & CTLTYPE) == 0 || \ 610 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_UINT) && \ 611 sizeof(unsigned) == sizeof(*(ptr))) 612 613#define SYSCTL_ADD_UINT(ctx, parent, nbr, name, access, ptr, val, descr) \ 614({ \ 615 unsigned *__ptr = (ptr); \ 616 CTASSERT(((access) & CTLTYPE) == 0 || \ 617 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_UINT); \ 618 sysctl_add_oid(ctx, parent, nbr, name, \ 619 CTLTYPE_UINT | CTLFLAG_MPSAFE | (access), \ 620 __ptr, val, sysctl_handle_int, "IU", __DESCR(descr), NULL); \ 621}) 622 623/* Oid for a long. The pointer must be non NULL. */ 624#define SYSCTL_NULL_LONG_PTR ((long *)NULL) 625#define SYSCTL_LONG(parent, nbr, name, access, ptr, val, descr) \ 626 SYSCTL_OID(parent, nbr, name, \ 627 CTLTYPE_LONG | CTLFLAG_MPSAFE | (access), \ 628 ptr, val, sysctl_handle_long, "L", descr); \ 629 CTASSERT((((access) & CTLTYPE) == 0 || \ 630 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_LONG) && \ 631 sizeof(long) == sizeof(*(ptr))) 632 633#define SYSCTL_ADD_LONG(ctx, parent, nbr, name, access, ptr, descr) \ 634({ \ 635 long *__ptr = (ptr); \ 636 CTASSERT(((access) & CTLTYPE) == 0 || \ 637 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_LONG); \ 638 sysctl_add_oid(ctx, parent, nbr, name, \ 639 CTLTYPE_LONG | CTLFLAG_MPSAFE | (access), \ 640 __ptr, 0, sysctl_handle_long, "L", __DESCR(descr), NULL); \ 641}) 642 643/* Oid for an unsigned long. The pointer must be non NULL. */ 644#define SYSCTL_NULL_ULONG_PTR ((unsigned long *)NULL) 645#define SYSCTL_ULONG(parent, nbr, name, access, ptr, val, descr) \ 646 SYSCTL_OID(parent, nbr, name, \ 647 CTLTYPE_ULONG | CTLFLAG_MPSAFE | (access), \ 648 ptr, val, sysctl_handle_long, "LU", descr); \ 649 CTASSERT((((access) & CTLTYPE) == 0 || \ 650 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_ULONG) && \ 651 sizeof(unsigned long) == sizeof(*(ptr))) 652 653#define SYSCTL_ADD_ULONG(ctx, parent, nbr, name, access, ptr, descr) \ 654({ \ 655 unsigned long *__ptr = (ptr); \ 656 CTASSERT(((access) & CTLTYPE) == 0 || \ 657 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_ULONG); \ 658 sysctl_add_oid(ctx, parent, nbr, name, \ 659 CTLTYPE_ULONG | CTLFLAG_MPSAFE | (access), \ 660 __ptr, 0, sysctl_handle_long, "LU", __DESCR(descr), NULL); \ 661}) 662 663/* Oid for a quad. The pointer must be non NULL. */ 664#define SYSCTL_NULL_QUAD_PTR ((int64_t *)NULL) 665#define SYSCTL_QUAD(parent, nbr, name, access, ptr, val, descr) \ 666 SYSCTL_OID(parent, nbr, name, \ 667 CTLTYPE_S64 | CTLFLAG_MPSAFE | (access), \ 668 ptr, val, sysctl_handle_64, "Q", descr); \ 669 CTASSERT((((access) & CTLTYPE) == 0 || \ 670 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64) && \ 671 sizeof(int64_t) == sizeof(*(ptr))) 672 673#define SYSCTL_ADD_QUAD(ctx, parent, nbr, name, access, ptr, descr) \ 674({ \ 675 int64_t *__ptr = (ptr); \ 676 CTASSERT(((access) & CTLTYPE) == 0 || \ 677 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64); \ 678 sysctl_add_oid(ctx, parent, nbr, name, \ 679 CTLTYPE_S64 | CTLFLAG_MPSAFE | (access), \ 680 __ptr, 0, sysctl_handle_64, "Q", __DESCR(descr), NULL); \ 681}) 682 683#define SYSCTL_NULL_UQUAD_PTR ((uint64_t *)NULL) 684#define SYSCTL_UQUAD(parent, nbr, name, access, ptr, val, descr) \ 685 SYSCTL_OID(parent, nbr, name, \ 686 CTLTYPE_U64 | CTLFLAG_MPSAFE | (access), \ 687 ptr, val, sysctl_handle_64, "QU", descr); \ 688 CTASSERT((((access) & CTLTYPE) == 0 || \ 689 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64) && \ 690 sizeof(uint64_t) == sizeof(*(ptr))) 691 692#define SYSCTL_ADD_UQUAD(ctx, parent, nbr, name, access, ptr, descr) \ 693({ \ 694 uint64_t *__ptr = (ptr); \ 695 CTASSERT(((access) & CTLTYPE) == 0 || \ 696 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64); \ 697 sysctl_add_oid(ctx, parent, nbr, name, \ 698 CTLTYPE_U64 | CTLFLAG_MPSAFE | (access), \ 699 __ptr, 0, sysctl_handle_64, "QU", __DESCR(descr), NULL); \ 700}) 701 702/* Oid for a CPU dependent variable */ 703#define SYSCTL_ADD_UAUTO(ctx, parent, nbr, name, access, ptr, descr) \ 704({ \ 705 struct sysctl_oid *__ret; \ 706 CTASSERT((sizeof(uint64_t) == sizeof(*(ptr)) || \ 707 sizeof(unsigned) == sizeof(*(ptr))) && \ 708 ((access) & CTLTYPE) == 0); \ 709 if (sizeof(uint64_t) == sizeof(*(ptr))) { \ 710 __ret = sysctl_add_oid(ctx, parent, nbr, name, \ 711 CTLTYPE_U64 | CTLFLAG_MPSAFE | (access), \ 712 (ptr), 0, sysctl_handle_64, "QU", \ 713 __DESCR(descr), NULL); \ 714 } else { \ 715 __ret = sysctl_add_oid(ctx, parent, nbr, name, \ 716 CTLTYPE_UINT | CTLFLAG_MPSAFE | (access), \ 717 (ptr), 0, sysctl_handle_int, "IU", \ 718 __DESCR(descr), NULL); \ 719 } \ 720 __ret; \ 721}) 722 723/* Oid for a 64-bit unsigned counter(9). The pointer must be non NULL. */ 724#define SYSCTL_COUNTER_U64(parent, nbr, name, access, ptr, descr) \ 725 SYSCTL_OID(parent, nbr, name, \ 726 CTLTYPE_U64 | CTLFLAG_MPSAFE | CTLFLAG_STATS | (access), \ 727 (ptr), 0, sysctl_handle_counter_u64, "QU", descr); \ 728 CTASSERT((((access) & CTLTYPE) == 0 || \ 729 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64) && \ 730 sizeof(counter_u64_t) == sizeof(*(ptr)) && \ 731 sizeof(uint64_t) == sizeof(**(ptr))) 732 733#define SYSCTL_ADD_COUNTER_U64(ctx, parent, nbr, name, access, ptr, descr) \ 734({ \ 735 counter_u64_t *__ptr = (ptr); \ 736 CTASSERT(((access) & CTLTYPE) == 0 || \ 737 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64); \ 738 sysctl_add_oid(ctx, parent, nbr, name, \ 739 CTLTYPE_U64 | CTLFLAG_MPSAFE | CTLFLAG_STATS | (access), \ 740 __ptr, 0, sysctl_handle_counter_u64, "QU", __DESCR(descr), \ 741 NULL); \ 742}) 743 744/* Oid for an array of counter(9)s. The pointer and length must be non zero. */ 745#define SYSCTL_COUNTER_U64_ARRAY(parent, nbr, name, access, ptr, len, descr) \ 746 SYSCTL_OID(parent, nbr, name, \ 747 CTLTYPE_OPAQUE | CTLFLAG_MPSAFE | CTLFLAG_STATS | (access), \ 748 (ptr), (len), sysctl_handle_counter_u64_array, "S", descr); \ 749 CTASSERT((((access) & CTLTYPE) == 0 || \ 750 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE) && \ 751 sizeof(counter_u64_t) == sizeof(*(ptr)) && \ 752 sizeof(uint64_t) == sizeof(**(ptr))) 753 754#define SYSCTL_ADD_COUNTER_U64_ARRAY(ctx, parent, nbr, name, access, \ 755 ptr, len, descr) \ 756({ \ 757 counter_u64_t *__ptr = (ptr); \ 758 CTASSERT(((access) & CTLTYPE) == 0 || \ 759 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE); \ 760 sysctl_add_oid(ctx, parent, nbr, name, \ 761 CTLTYPE_OPAQUE | CTLFLAG_MPSAFE | CTLFLAG_STATS | (access), \ 762 __ptr, len, sysctl_handle_counter_u64_array, "S", \ 763 __DESCR(descr), NULL); \ 764}) 765 766/* Oid for an opaque object. Specified by a pointer and a length. */ 767#define SYSCTL_OPAQUE(parent, nbr, name, access, ptr, len, fmt, descr) \ 768 SYSCTL_OID(parent, nbr, name, \ 769 CTLTYPE_OPAQUE | CTLFLAG_MPSAFE | (access), \ 770 ptr, len, sysctl_handle_opaque, fmt, descr); \ 771 CTASSERT(((access) & CTLTYPE) == 0 || \ 772 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE) 773 774#define SYSCTL_ADD_OPAQUE(ctx, parent, nbr, name, access, ptr, len, fmt, descr) \ 775({ \ 776 CTASSERT(((access) & CTLTYPE) == 0 || \ 777 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE); \ 778 sysctl_add_oid(ctx, parent, nbr, name, \ 779 CTLTYPE_OPAQUE | CTLFLAG_MPSAFE | (access), \ 780 ptr, len, sysctl_handle_opaque, fmt, __DESCR(descr), NULL); \ 781}) 782 783/* Oid for a struct. Specified by a pointer and a type. */ 784#define SYSCTL_STRUCT(parent, nbr, name, access, ptr, type, descr) \ 785 SYSCTL_OID(parent, nbr, name, \ 786 CTLTYPE_OPAQUE | CTLFLAG_MPSAFE | (access), \ 787 ptr, sizeof(struct type), sysctl_handle_opaque, \ 788 "S," #type, descr); \ 789 CTASSERT(((access) & CTLTYPE) == 0 || \ 790 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE) 791 792#define SYSCTL_ADD_STRUCT(ctx, parent, nbr, name, access, ptr, type, descr) \ 793({ \ 794 CTASSERT(((access) & CTLTYPE) == 0 || \ 795 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE); \ 796 sysctl_add_oid(ctx, parent, nbr, name, \ 797 CTLTYPE_OPAQUE | CTLFLAG_MPSAFE | (access), \ 798 (ptr), sizeof(struct type), \ 799 sysctl_handle_opaque, "S," #type, __DESCR(descr), NULL); \ 800}) 801 802/* Oid for a procedure. Specified by a pointer and an arg. */ 803#define SYSCTL_PROC(parent, nbr, name, access, ptr, arg, handler, fmt, descr) \ 804 SYSCTL_OID(parent, nbr, name, (access), \ 805 ptr, arg, handler, fmt, descr); \ 806 CTASSERT(((access) & CTLTYPE) != 0) 807 808#define SYSCTL_ADD_PROC(ctx, parent, nbr, name, access, ptr, arg, handler, fmt, descr) \ 809({ \ 810 CTASSERT(((access) & CTLTYPE) != 0); \ 811 SYSCTL_ENFORCE_FLAGS(access); \ 812 sysctl_add_oid(ctx, parent, nbr, name, (access), \ 813 (ptr), (arg), (handler), (fmt), __DESCR(descr), NULL); \ 814}) 815 816/* Oid to handle limits on uma(9) zone specified by pointer. */ 817#define SYSCTL_UMA_MAX(parent, nbr, name, access, ptr, descr) \ 818 SYSCTL_OID(parent, nbr, name, \ 819 CTLTYPE_INT | CTLFLAG_MPSAFE | (access), \ 820 (ptr), 0, sysctl_handle_uma_zone_max, "I", descr); \ 821 CTASSERT(((access) & CTLTYPE) == 0 || \ 822 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT) 823 824#define SYSCTL_ADD_UMA_MAX(ctx, parent, nbr, name, access, ptr, descr) \ 825({ \ 826 uma_zone_t __ptr = (ptr); \ 827 CTASSERT(((access) & CTLTYPE) == 0 || \ 828 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT); \ 829 sysctl_add_oid(ctx, parent, nbr, name, \ 830 CTLTYPE_INT | CTLFLAG_MPSAFE | (access), \ 831 __ptr, 0, sysctl_handle_uma_zone_max, "I", __DESCR(descr), \ 832 NULL); \ 833}) 834 835/* Oid to obtain current use of uma(9) zone specified by pointer. */ 836#define SYSCTL_UMA_CUR(parent, nbr, name, access, ptr, descr) \ 837 SYSCTL_OID(parent, nbr, name, \ 838 CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access), \ 839 (ptr), 0, sysctl_handle_uma_zone_cur, "I", descr); \ 840 CTASSERT(((access) & CTLTYPE) == 0 || \ 841 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT) 842 843#define SYSCTL_ADD_UMA_CUR(ctx, parent, nbr, name, access, ptr, descr) \ 844({ \ 845 uma_zone_t __ptr = (ptr); \ 846 CTASSERT(((access) & CTLTYPE) == 0 || \ 847 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT); \ 848 sysctl_add_oid(ctx, parent, nbr, name, \ 849 CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access), \ 850 __ptr, 0, sysctl_handle_uma_zone_cur, "I", __DESCR(descr), \ 851 NULL); \ 852}) 853 854/* OID expressing a sbintime_t as microseconds */ 855#define SYSCTL_SBINTIME_USEC(parent, nbr, name, access, ptr, descr) \ 856 SYSCTL_OID(parent, nbr, name, \ 857 CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access), \ 858 (ptr), 0, sysctl_usec_to_sbintime, "Q", descr); \ 859 CTASSERT(((access) & CTLTYPE) == 0 || \ 860 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64) 861#define SYSCTL_ADD_SBINTIME_USEC(ctx, parent, nbr, name, access, ptr, descr) \ 862({ \ 863 sbintime_t *__ptr = (ptr); \ 864 CTASSERT(((access) & CTLTYPE) == 0 || \ 865 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64); \ 866 sysctl_add_oid(ctx, parent, nbr, name, \ 867 CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access), \ 868 __ptr, 0, sysctl_usec_to_sbintime, "Q", __DESCR(descr), \ 869 NULL); \ 870}) 871 872/* OID expressing a sbintime_t as milliseconds */ 873#define SYSCTL_SBINTIME_MSEC(parent, nbr, name, access, ptr, descr) \ 874 SYSCTL_OID(parent, nbr, name, \ 875 CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access), \ 876 (ptr), 0, sysctl_msec_to_sbintime, "Q", descr); \ 877 CTASSERT(((access) & CTLTYPE) == 0 || \ 878 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64) 879#define SYSCTL_ADD_SBINTIME_MSEC(ctx, parent, nbr, name, access, ptr, descr) \ 880({ \ 881 sbintime_t *__ptr = (ptr); \ 882 CTASSERT(((access) & CTLTYPE) == 0 || \ 883 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64); \ 884 sysctl_add_oid(ctx, parent, nbr, name, \ 885 CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access), \ 886 __ptr, 0, sysctl_msec_to_sbintime, "Q", __DESCR(descr), \ 887 NULL); \ 888}) 889 890/* OID expressing a struct timeval as seconds */ 891#define SYSCTL_TIMEVAL_SEC(parent, nbr, name, access, ptr, descr) \ 892 SYSCTL_OID(parent, nbr, name, \ 893 CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access), \ 894 (ptr), 0, sysctl_sec_to_timeval, "I", descr); \ 895 CTASSERT(((access) & CTLTYPE) == 0 || \ 896 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT) 897#define SYSCTL_ADD_TIMEVAL_SEC(ctx, parent, nbr, name, access, ptr, descr) \ 898({ \ 899 struct timeval *__ptr = (ptr); \ 900 CTASSERT(((access) & CTLTYPE) == 0 || \ 901 ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT); \ 902 sysctl_add_oid(ctx, parent, nbr, name, \ 903 CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access), \ 904 __ptr, 0, sysctl_sec_to_timeval, "I", __DESCR(descr), \ 905 NULL); \ 906}) 907 908/* 909 * A macro to generate a read-only sysctl to indicate the presence of optional 910 * kernel features. 911 */ 912#define FEATURE(name, desc) \ 913 SYSCTL_INT_WITH_LABEL(_kern_features, OID_AUTO, name, \ 914 CTLFLAG_RD | CTLFLAG_CAPRD, SYSCTL_NULL_INT_PTR, 1, desc, "feature") 915 916#endif /* _KERNEL */ 917 918/* 919 * Top-level identifiers 920 */ 921#define CTL_SYSCTL 0 /* "magic" numbers */ 922#define CTL_KERN 1 /* "high kernel": proc, limits */ 923#define CTL_VM 2 /* virtual memory */ 924#define CTL_VFS 3 /* filesystem, mount type is next */ 925#define CTL_NET 4 /* network, see socket.h */ 926#define CTL_DEBUG 5 /* debugging parameters */ 927#define CTL_HW 6 /* generic cpu/io */ 928#define CTL_MACHDEP 7 /* machine dependent */ 929#define CTL_USER 8 /* user-level */ 930#define CTL_P1003_1B 9 /* POSIX 1003.1B */ 931 932/* 933 * CTL_SYSCTL identifiers 934 */ 935#define CTL_SYSCTL_DEBUG 0 /* printf all nodes */ 936#define CTL_SYSCTL_NAME 1 /* string name of OID */ 937#define CTL_SYSCTL_NEXT 2 /* next OID, honoring CTLFLAG_SKIP */ 938#define CTL_SYSCTL_NAME2OID 3 /* int array of name */ 939#define CTL_SYSCTL_OIDFMT 4 /* OID's kind and format */ 940#define CTL_SYSCTL_OIDDESCR 5 /* OID's description */ 941#define CTL_SYSCTL_OIDLABEL 6 /* aggregation label */ 942#define CTL_SYSCTL_NEXTNOSKIP 7 /* next OID, ignoring CTLFLAG_SKIP */ 943 944/* 945 * CTL_KERN identifiers 946 */ 947#define KERN_OSTYPE 1 /* string: system version */ 948#define KERN_OSRELEASE 2 /* string: system release */ 949#define KERN_OSREV 3 /* int: system revision */ 950#define KERN_VERSION 4 /* string: compile time info */ 951#define KERN_MAXVNODES 5 /* int: max vnodes */ 952#define KERN_MAXPROC 6 /* int: max processes */ 953#define KERN_MAXFILES 7 /* int: max open files */ 954#define KERN_ARGMAX 8 /* int: max arguments to exec */ 955#define KERN_SECURELVL 9 /* int: system security level */ 956#define KERN_HOSTNAME 10 /* string: hostname */ 957#define KERN_HOSTID 11 /* int: host identifier */ 958#define KERN_CLOCKRATE 12 /* struct: struct clockrate */ 959#define KERN_VNODE 13 /* struct: vnode structures */ 960#define KERN_PROC 14 /* struct: process entries */ 961#define KERN_FILE 15 /* struct: file entries */ 962#define KERN_PROF 16 /* node: kernel profiling info */ 963#define KERN_POSIX1 17 /* int: POSIX.1 version */ 964#define KERN_NGROUPS 18 /* int: # of supplemental group ids */ 965#define KERN_JOB_CONTROL 19 /* int: is job control available */ 966#define KERN_SAVED_IDS 20 /* int: saved set-user/group-ID */ 967#define KERN_BOOTTIME 21 /* struct: time kernel was booted */ 968#define KERN_NISDOMAINNAME 22 /* string: YP domain name */ 969#define KERN_UPDATEINTERVAL 23 /* int: update process sleep time */ 970#define KERN_OSRELDATE 24 /* int: kernel release date */ 971#define KERN_NTP_PLL 25 /* node: NTP PLL control */ 972#define KERN_BOOTFILE 26 /* string: name of booted kernel */ 973#define KERN_MAXFILESPERPROC 27 /* int: max open files per proc */ 974#define KERN_MAXPROCPERUID 28 /* int: max processes per uid */ 975#define KERN_DUMPDEV 29 /* struct cdev *: device to dump on */ 976#define KERN_IPC 30 /* node: anything related to IPC */ 977#define KERN_DUMMY 31 /* unused */ 978#define KERN_PS_STRINGS 32 /* int: address of PS_STRINGS */ 979#define KERN_USRSTACK 33 /* int: address of USRSTACK */ 980#define KERN_LOGSIGEXIT 34 /* int: do we log sigexit procs? */ 981#define KERN_IOV_MAX 35 /* int: value of UIO_MAXIOV */ 982#define KERN_HOSTUUID 36 /* string: host UUID identifier */ 983#define KERN_ARND 37 /* int: from arc4rand() */ 984#define KERN_MAXPHYS 38 /* int: MAXPHYS value */ 985/* 986 * KERN_PROC subtypes 987 */ 988#define KERN_PROC_ALL 0 /* everything */ 989#define KERN_PROC_PID 1 /* by process id */ 990#define KERN_PROC_PGRP 2 /* by process group id */ 991#define KERN_PROC_SESSION 3 /* by session of pid */ 992#define KERN_PROC_TTY 4 /* by controlling tty */ 993#define KERN_PROC_UID 5 /* by effective uid */ 994#define KERN_PROC_RUID 6 /* by real uid */ 995#define KERN_PROC_ARGS 7 /* get/set arguments/proctitle */ 996#define KERN_PROC_PROC 8 /* only return procs */ 997#define KERN_PROC_SV_NAME 9 /* get syscall vector name */ 998#define KERN_PROC_RGID 10 /* by real group id */ 999#define KERN_PROC_GID 11 /* by effective group id */ 1000#define KERN_PROC_PATHNAME 12 /* path to executable */ 1001#define KERN_PROC_OVMMAP 13 /* Old VM map entries for process */ 1002#define KERN_PROC_OFILEDESC 14 /* Old file descriptors for process */ 1003#define KERN_PROC_KSTACK 15 /* Kernel stacks for process */ 1004#define KERN_PROC_INC_THREAD 0x10 /* 1005 * modifier for pid, pgrp, tty, 1006 * uid, ruid, gid, rgid and proc 1007 * This effectively uses 16-31 1008 */ 1009#define KERN_PROC_VMMAP 32 /* VM map entries for process */ 1010#define KERN_PROC_FILEDESC 33 /* File descriptors for process */ 1011#define KERN_PROC_GROUPS 34 /* process groups */ 1012#define KERN_PROC_ENV 35 /* get environment */ 1013#define KERN_PROC_AUXV 36 /* get ELF auxiliary vector */ 1014#define KERN_PROC_RLIMIT 37 /* process resource limits */ 1015#define KERN_PROC_PS_STRINGS 38 /* get ps_strings location */ 1016#define KERN_PROC_UMASK 39 /* process umask */ 1017#define KERN_PROC_OSREL 40 /* osreldate for process binary */ 1018#define KERN_PROC_SIGTRAMP 41 /* signal trampoline location */ 1019#define KERN_PROC_CWD 42 /* process current working directory */ 1020#define KERN_PROC_NFDS 43 /* number of open file descriptors */ 1021#define KERN_PROC_SIGFASTBLK 44 /* address of fastsigblk magic word */ 1022 1023/* 1024 * KERN_IPC identifiers 1025 */ 1026#define KIPC_MAXSOCKBUF 1 /* int: max size of a socket buffer */ 1027#define KIPC_SOCKBUF_WASTE 2 /* int: wastage factor in sockbuf */ 1028#define KIPC_SOMAXCONN 3 /* int: max length of connection q */ 1029#define KIPC_MAX_LINKHDR 4 /* int: max length of link header */ 1030#define KIPC_MAX_PROTOHDR 5 /* int: max length of network header */ 1031#define KIPC_MAX_HDR 6 /* int: max total length of headers */ 1032#define KIPC_MAX_DATALEN 7 /* int: max length of data? */ 1033 1034/* 1035 * CTL_HW identifiers 1036 */ 1037#define HW_MACHINE 1 /* string: machine class */ 1038#define HW_MODEL 2 /* string: specific machine model */ 1039#define HW_NCPU 3 /* int: number of cpus */ 1040#define HW_BYTEORDER 4 /* int: machine byte order */ 1041#define HW_PHYSMEM 5 /* int: total memory */ 1042#define HW_USERMEM 6 /* int: non-kernel memory */ 1043#define HW_PAGESIZE 7 /* int: software page size */ 1044#define HW_DISKNAMES 8 /* strings: disk drive names */ 1045#define HW_DISKSTATS 9 /* struct: diskstats[] */ 1046#define HW_FLOATINGPT 10 /* int: has HW floating point? */ 1047#define HW_MACHINE_ARCH 11 /* string: machine architecture */ 1048#define HW_REALMEM 12 /* int: 'real' memory */ 1049 1050/* 1051 * CTL_USER definitions 1052 */ 1053#define USER_CS_PATH 1 /* string: _CS_PATH */ 1054#define USER_BC_BASE_MAX 2 /* int: BC_BASE_MAX */ 1055#define USER_BC_DIM_MAX 3 /* int: BC_DIM_MAX */ 1056#define USER_BC_SCALE_MAX 4 /* int: BC_SCALE_MAX */ 1057#define USER_BC_STRING_MAX 5 /* int: BC_STRING_MAX */ 1058#define USER_COLL_WEIGHTS_MAX 6 /* int: COLL_WEIGHTS_MAX */ 1059#define USER_EXPR_NEST_MAX 7 /* int: EXPR_NEST_MAX */ 1060#define USER_LINE_MAX 8 /* int: LINE_MAX */ 1061#define USER_RE_DUP_MAX 9 /* int: RE_DUP_MAX */ 1062#define USER_POSIX2_VERSION 10 /* int: POSIX2_VERSION */ 1063#define USER_POSIX2_C_BIND 11 /* int: POSIX2_C_BIND */ 1064#define USER_POSIX2_C_DEV 12 /* int: POSIX2_C_DEV */ 1065#define USER_POSIX2_CHAR_TERM 13 /* int: POSIX2_CHAR_TERM */ 1066#define USER_POSIX2_FORT_DEV 14 /* int: POSIX2_FORT_DEV */ 1067#define USER_POSIX2_FORT_RUN 15 /* int: POSIX2_FORT_RUN */ 1068#define USER_POSIX2_LOCALEDEF 16 /* int: POSIX2_LOCALEDEF */ 1069#define USER_POSIX2_SW_DEV 17 /* int: POSIX2_SW_DEV */ 1070#define USER_POSIX2_UPE 18 /* int: POSIX2_UPE */ 1071#define USER_STREAM_MAX 19 /* int: POSIX2_STREAM_MAX */ 1072#define USER_TZNAME_MAX 20 /* int: POSIX2_TZNAME_MAX */ 1073#define USER_LOCALBASE 21 /* string: _PATH_LOCALBASE */ 1074 1075#define CTL_P1003_1B_ASYNCHRONOUS_IO 1 /* boolean */ 1076#define CTL_P1003_1B_MAPPED_FILES 2 /* boolean */ 1077#define CTL_P1003_1B_MEMLOCK 3 /* boolean */ 1078#define CTL_P1003_1B_MEMLOCK_RANGE 4 /* boolean */ 1079#define CTL_P1003_1B_MEMORY_PROTECTION 5 /* boolean */ 1080#define CTL_P1003_1B_MESSAGE_PASSING 6 /* boolean */ 1081#define CTL_P1003_1B_PRIORITIZED_IO 7 /* boolean */ 1082#define CTL_P1003_1B_PRIORITY_SCHEDULING 8 /* boolean */ 1083#define CTL_P1003_1B_REALTIME_SIGNALS 9 /* boolean */ 1084#define CTL_P1003_1B_SEMAPHORES 10 /* boolean */ 1085#define CTL_P1003_1B_FSYNC 11 /* boolean */ 1086#define CTL_P1003_1B_SHARED_MEMORY_OBJECTS 12 /* boolean */ 1087#define CTL_P1003_1B_SYNCHRONIZED_IO 13 /* boolean */ 1088#define CTL_P1003_1B_TIMERS 14 /* boolean */ 1089#define CTL_P1003_1B_AIO_LISTIO_MAX 15 /* int */ 1090#define CTL_P1003_1B_AIO_MAX 16 /* int */ 1091#define CTL_P1003_1B_AIO_PRIO_DELTA_MAX 17 /* int */ 1092#define CTL_P1003_1B_DELAYTIMER_MAX 18 /* int */ 1093#define CTL_P1003_1B_MQ_OPEN_MAX 19 /* int */ 1094#define CTL_P1003_1B_PAGESIZE 20 /* int */ 1095#define CTL_P1003_1B_RTSIG_MAX 21 /* int */ 1096#define CTL_P1003_1B_SEM_NSEMS_MAX 22 /* int */ 1097#define CTL_P1003_1B_SEM_VALUE_MAX 23 /* int */ 1098#define CTL_P1003_1B_SIGQUEUE_MAX 24 /* int */ 1099#define CTL_P1003_1B_TIMER_MAX 25 /* int */ 1100 1101#ifdef _KERNEL 1102 1103#define CTL_P1003_1B_MAXID 26 1104 1105/* 1106 * Declare some common oids. 1107 */ 1108extern struct sysctl_oid_list sysctl__children; 1109SYSCTL_DECL(_kern); 1110SYSCTL_DECL(_kern_features); 1111SYSCTL_DECL(_kern_ipc); 1112SYSCTL_DECL(_kern_proc); 1113SYSCTL_DECL(_kern_sched); 1114SYSCTL_DECL(_kern_sched_stats); 1115SYSCTL_DECL(_sysctl); 1116SYSCTL_DECL(_vm); 1117SYSCTL_DECL(_vm_stats); 1118SYSCTL_DECL(_vm_stats_misc); 1119SYSCTL_DECL(_vfs); 1120SYSCTL_DECL(_net); 1121SYSCTL_DECL(_debug); 1122SYSCTL_DECL(_debug_sizeof); 1123SYSCTL_DECL(_dev); 1124SYSCTL_DECL(_hw); 1125SYSCTL_DECL(_hw_bus); 1126SYSCTL_DECL(_hw_bus_devices); 1127SYSCTL_DECL(_machdep); 1128SYSCTL_DECL(_machdep_mitigations); 1129SYSCTL_DECL(_user); 1130SYSCTL_DECL(_compat); 1131SYSCTL_DECL(_regression); 1132SYSCTL_DECL(_security); 1133SYSCTL_DECL(_security_bsd); 1134 1135extern char machine[]; 1136extern char osrelease[]; 1137extern char ostype[]; 1138extern char kern_ident[]; 1139 1140/* Dynamic oid handling */ 1141struct sysctl_oid *sysctl_add_oid(struct sysctl_ctx_list *clist, 1142 struct sysctl_oid_list *parent, int nbr, const char *name, int kind, 1143 void *arg1, intmax_t arg2, int (*handler)(SYSCTL_HANDLER_ARGS), 1144 const char *fmt, const char *descr, const char *label); 1145int sysctl_remove_name(struct sysctl_oid *parent, const char *name, int del, 1146 int recurse); 1147void sysctl_rename_oid(struct sysctl_oid *oidp, const char *name); 1148int sysctl_move_oid(struct sysctl_oid *oidp, 1149 struct sysctl_oid_list *parent); 1150int sysctl_remove_oid(struct sysctl_oid *oidp, int del, int recurse); 1151int sysctl_ctx_init(struct sysctl_ctx_list *clist); 1152int sysctl_ctx_free(struct sysctl_ctx_list *clist); 1153struct sysctl_ctx_entry *sysctl_ctx_entry_add(struct sysctl_ctx_list *clist, 1154 struct sysctl_oid *oidp); 1155struct sysctl_ctx_entry *sysctl_ctx_entry_find(struct sysctl_ctx_list *clist, 1156 struct sysctl_oid *oidp); 1157int sysctl_ctx_entry_del(struct sysctl_ctx_list *clist, 1158 struct sysctl_oid *oidp); 1159 1160int kernel_sysctl(struct thread *td, int *name, u_int namelen, void *old, 1161 size_t *oldlenp, void *new, size_t newlen, size_t *retval, 1162 int flags); 1163int kernel_sysctlbyname(struct thread *td, char *name, void *old, 1164 size_t *oldlenp, void *new, size_t newlen, size_t *retval, 1165 int flags); 1166int userland_sysctl(struct thread *td, int *name, u_int namelen, void *old, 1167 size_t *oldlenp, int inkernel, const void *new, size_t newlen, 1168 size_t *retval, int flags); 1169int sysctl_find_oid(int *name, u_int namelen, struct sysctl_oid **noid, 1170 int *nindx, struct sysctl_req *req); 1171void sysctl_wlock(void); 1172void sysctl_wunlock(void); 1173int sysctl_wire_old_buffer(struct sysctl_req *req, size_t len); 1174int kern___sysctlbyname(struct thread *td, const char *name, 1175 size_t namelen, void *old, size_t *oldlenp, void *new, 1176 size_t newlen, size_t *retval, int flags, bool inkernel); 1177 1178struct sbuf; 1179struct sbuf *sbuf_new_for_sysctl(struct sbuf *, char *, int, 1180 struct sysctl_req *); 1181#else /* !_KERNEL */ 1182#include <sys/cdefs.h> 1183 1184__BEGIN_DECLS 1185int sysctl(const int *, u_int, void *, size_t *, const void *, size_t); 1186int sysctlbyname(const char *, void *, size_t *, const void *, size_t); 1187int sysctlnametomib(const char *, int *, size_t *); 1188__END_DECLS 1189#endif /* _KERNEL */ 1190 1191#endif /* !_SYS_SYSCTL_H_ */ 1192