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