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