Changeset View
Changeset View
Standalone View
Standalone View
sys/sys/sysctl.h
Show First 20 Lines • Show All 175 Lines • ▼ Show 20 Lines | struct sysctl_req { | ||||
size_t newidx; | size_t newidx; | ||||
int (*newfunc)(struct sysctl_req *, void *, size_t); | int (*newfunc)(struct sysctl_req *, void *, size_t); | ||||
size_t validlen; | size_t validlen; | ||||
int flags; | int flags; | ||||
}; | }; | ||||
SLIST_HEAD(sysctl_oid_list, sysctl_oid); | SLIST_HEAD(sysctl_oid_list, sysctl_oid); | ||||
struct sysctl_oid; | |||||
typedef bool oid_handler_next_oid_t(struct sysctl_oid *oidp, | |||||
const int *name, int namelen, int *next, int *plen, int level, | |||||
bool honor_skip); | |||||
typedef int oid_handler_name2oid_t(char *name, int *oid, int *len); | |||||
typedef int oid_handler_oidfmt_t(struct sysctl_oid *oidp, | |||||
const int *name, int namelen, unsigned int *oid_kind, | |||||
char *oid_fmt, size_t fmt_sz); | |||||
struct sysctl_node_handlers { | |||||
oid_handler_next_oid_t *nextoid; | |||||
oid_handler_name2oid_t *name2oid; | |||||
oid_handler_oidfmt_t *oidfmt; | |||||
}; | |||||
/* | /* | ||||
* This describes one "oid" in the MIB tree. Potentially more nodes can | * This describes one "oid" in the MIB tree. Potentially more nodes can | ||||
* be hidden behind it, expanded by the handler. | * be hidden behind it, expanded by the handler. | ||||
*/ | */ | ||||
struct sysctl_oid { | struct sysctl_oid { | ||||
struct sysctl_oid_list oid_children; | struct sysctl_oid_list oid_children; | ||||
struct sysctl_oid_list *oid_parent; | struct sysctl_oid_list *oid_parent; | ||||
SLIST_ENTRY(sysctl_oid) oid_link; | SLIST_ENTRY(sysctl_oid) oid_link; | ||||
int oid_number; | int oid_number; | ||||
u_int oid_kind; | u_int oid_kind; | ||||
void *oid_arg1; | union { | ||||
void *oid_arg1; /* !CTLTYPE_NODE */ | |||||
struct sysctl_node_handlers *oid_handlers; /* Node */ | |||||
}; | |||||
intmax_t oid_arg2; | intmax_t oid_arg2; | ||||
const char *oid_name; | const char *oid_name; | ||||
int (*oid_handler)(SYSCTL_HANDLER_ARGS); | int (*oid_handler)(SYSCTL_HANDLER_ARGS); | ||||
const char *oid_fmt; | const char *oid_fmt; | ||||
int oid_refcnt; | int oid_refcnt; | ||||
u_int oid_running; | u_int oid_running; | ||||
const char *oid_descr; | const char *oid_descr; | ||||
const char *oid_label; | const char *oid_label; | ||||
Show All 22 Lines | |||||
int sysctl_msec_to_sbintime(SYSCTL_HANDLER_ARGS); | int sysctl_msec_to_sbintime(SYSCTL_HANDLER_ARGS); | ||||
int sysctl_usec_to_sbintime(SYSCTL_HANDLER_ARGS); | int sysctl_usec_to_sbintime(SYSCTL_HANDLER_ARGS); | ||||
int sysctl_sec_to_timeval(SYSCTL_HANDLER_ARGS); | int sysctl_sec_to_timeval(SYSCTL_HANDLER_ARGS); | ||||
int sysctl_dpcpu_int(SYSCTL_HANDLER_ARGS); | int sysctl_dpcpu_int(SYSCTL_HANDLER_ARGS); | ||||
int sysctl_dpcpu_long(SYSCTL_HANDLER_ARGS); | int sysctl_dpcpu_long(SYSCTL_HANDLER_ARGS); | ||||
int sysctl_dpcpu_quad(SYSCTL_HANDLER_ARGS); | int sysctl_dpcpu_quad(SYSCTL_HANDLER_ARGS); | ||||
uint32_t sysctl_get_oid_version(SYSCTL_HANDLER_ARGS); | |||||
int sysctl_copyout_ver(SYSCTL_HANDLER_ARGS, void *new_data, size_t new_datalen); | |||||
/* | /* | ||||
* These functions are used to add/remove an oid from the mib. | * These functions are used to add/remove an oid from the mib. | ||||
*/ | */ | ||||
void sysctl_register_oid(struct sysctl_oid *oidp); | void sysctl_register_oid(struct sysctl_oid *oidp); | ||||
void sysctl_register_disabled_oid(struct sysctl_oid *oidp); | void sysctl_register_disabled_oid(struct sysctl_oid *oidp); | ||||
void sysctl_enable_oid(struct sysctl_oid *oidp); | void sysctl_enable_oid(struct sysctl_oid *oidp); | ||||
void sysctl_unregister_oid(struct sysctl_oid *oidp); | void sysctl_unregister_oid(struct sysctl_oid *oidp); | ||||
Show All 16 Lines | struct sysctl_ctx_entry { | ||||
struct sysctl_oid *entry; | struct sysctl_oid *entry; | ||||
TAILQ_ENTRY(sysctl_ctx_entry) link; | TAILQ_ENTRY(sysctl_ctx_entry) link; | ||||
}; | }; | ||||
TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); | TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); | ||||
#define SYSCTL_NODE_CHILDREN(parent, name) \ | #define SYSCTL_NODE_CHILDREN(parent, name) \ | ||||
sysctl__##parent##_##name.oid_children | sysctl__##parent##_##name.oid_children | ||||
#define SYSCTL_IS_NODE(_n) (((_n)->oid_kind & CTLTYPE) == CTLTYPE_NODE) | |||||
#define SYSCTL_NODE_CAN_ITERATE(_n) \ | |||||
(((_n)->oid_handler == NULL) || ((_n)->oid_handlers != NULL)) | |||||
#ifndef NO_SYSCTL_DESCR | #ifndef NO_SYSCTL_DESCR | ||||
#define __DESCR(d) d | #define __DESCR(d) d | ||||
#else | #else | ||||
#define __DESCR(d) "" | #define __DESCR(d) "" | ||||
#endif | #endif | ||||
#ifdef notyet | #ifdef notyet | ||||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | #define SYSCTL_ROOT_NODE(nbr, name, access, handler, descr) \ | ||||
CTASSERT(((access) & CTLTYPE) == 0 || \ | CTASSERT(((access) & CTLTYPE) == 0 || \ | ||||
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE) | ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE) | ||||
/* This constructs a node from which other oids can hang. */ | /* This constructs a node from which other oids can hang. */ | ||||
#define SYSCTL_NODE(parent, nbr, name, access, handler, descr) \ | #define SYSCTL_NODE(parent, nbr, name, access, handler, descr) \ | ||||
SYSCTL_NODE_WITH_LABEL(parent, nbr, name, access, handler, descr, NULL) | SYSCTL_NODE_WITH_LABEL(parent, nbr, name, access, handler, descr, NULL) | ||||
#define SYSCTL_NODE_WITH_LABEL(parent, nbr, name, access, handler, descr, label) \ | #define SYSCTL_NODE_WITH_LABEL(parent, nbr, name, access, handler, descr, label) \ | ||||
SYSCTL_NODE_RAW(parent, nbr, name, access, handler, NULL, descr, label) | |||||
/* TODO: static checks on handlers */ | |||||
#define SYSCTL_NODE_WITH_HANDLERS(parent, nbr, name, access, handler, handlers, descr) \ | |||||
SYSCTL_NODE_RAW(parent, nbr, name, access, handler, handlers, descr, NULL) | |||||
#define SYSCTL_NODE_RAW(parent, nbr, name, access, handler, handlers, descr, label) \ | |||||
SYSCTL_OID_GLOBAL(parent, nbr, name, CTLTYPE_NODE|(access), \ | SYSCTL_OID_GLOBAL(parent, nbr, name, CTLTYPE_NODE|(access), \ | ||||
NULL, 0, handler, "N", descr, label); \ | handlers, 0, handler, "N", descr, label); \ | ||||
SYSCTL_ENFORCE_FLAGS(access); \ | SYSCTL_ENFORCE_FLAGS(access); \ | ||||
CTASSERT(((access) & CTLTYPE) == 0 || \ | CTASSERT(((access) & CTLTYPE) == 0 || \ | ||||
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE) | ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE) | ||||
#define SYSCTL_ADD_NODE(ctx, parent, nbr, name, access, handler, descr) \ | #define SYSCTL_ADD_NODE(ctx, parent, nbr, name, access, handler, descr) \ | ||||
SYSCTL_ADD_NODE_WITH_LABEL(ctx, parent, nbr, name, access, \ | SYSCTL_ADD_NODE_WITH_LABEL(ctx, parent, nbr, name, access, \ | ||||
handler, descr, NULL) | handler, descr, NULL) | ||||
▲ Show 20 Lines • Show All 555 Lines • ▼ Show 20 Lines | ({ \ | ||||
struct timeval *__ptr = (ptr); \ | struct timeval *__ptr = (ptr); \ | ||||
CTASSERT(((access) & CTLTYPE) == 0 || \ | CTASSERT(((access) & CTLTYPE) == 0 || \ | ||||
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT); \ | ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT); \ | ||||
sysctl_add_oid(ctx, parent, nbr, name, \ | sysctl_add_oid(ctx, parent, nbr, name, \ | ||||
CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access), \ | CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access), \ | ||||
__ptr, 0, sysctl_sec_to_timeval, "I", __DESCR(descr), \ | __ptr, 0, sysctl_sec_to_timeval, "I", __DESCR(descr), \ | ||||
NULL); \ | NULL); \ | ||||
}) | }) | ||||
/* Opaque versioned structures helpers */ | |||||
#define SYSCTL_OPAQUE_VER_HANDLERS(_array,_min_v,_max_v) \ | |||||
static bool \ | |||||
_array##_sysctl_iterator(struct sysctl_oid *oidp, const int *name, int namelen,\ | |||||
int *next, int *plen, int level, bool honor_skip) \ | |||||
{ \ | |||||
if (namelen == 0) { \ | |||||
*next = _min_v; \ | |||||
*plen = level; \ | |||||
return (true); \ | |||||
} \ | |||||
if (*name >= _min_v && *name < _max_v) { \ | |||||
*next = *name + 1; \ | |||||
*plen = level; \ | |||||
return (true); \ | |||||
} \ | |||||
return (false); \ | |||||
} \ | |||||
static int \ | |||||
_array##_sysctl_oidfmt(struct sysctl_oid *oidp, const int *name, int namelen,\ | |||||
unsigned int *oid_kind, char *oidfmt, size_t oidfmt_sz) \ | |||||
{ \ | |||||
if ((namelen != 1) || (*name < _min_v) || (*name > _max_v)) \ | |||||
return (ENOENT); \ | |||||
*oid_kind = CTLTYPE_OPAQUE; \ | |||||
strlcpy(oidfmt, "S", oidfmt_sz); \ | |||||
return (0); \ | |||||
} \ | |||||
static int \ | |||||
_array##_sysctl_name2oid(char *name, int *oid, int *len) \ | |||||
{ \ | |||||
char *endptr; \ | |||||
int ret; \ | |||||
ret = strtol(name, &endptr, 10); \ | |||||
if ((ret >= _min_v) && (ret <= _max_v) && (*endptr == '\0')) { \ | |||||
*oid = ret; \ | |||||
(*len)++; \ | |||||
return (0); \ | |||||
} \ | |||||
return (ENOENT); \ | |||||
} \ | |||||
static struct sysctl_node_handlers _array##_sysctl_handlers = { \ | |||||
.nextoid = _array##_sysctl_iterator, \ | |||||
.name2oid = _array##_sysctl_name2oid, \ | |||||
.oidfmt = _array##_sysctl_oidfmt \ | |||||
}; \ | |||||
#define SYSCTL_OPAQUE_VER(_parent, _nbr, _name, _type, _array, _desc) \ | |||||
SYSCTL_NODE_WITH_HANDLERS(_parent, _nbr, _name, \ | |||||
CTLFLAG_RW | CTLFLAG_MPSAFE, \ | |||||
_array##_sysctl_versioned, &_array##_sysctl_handlers, \ | |||||
_desc) | |||||
/* | /* | ||||
* A macro to generate a read-only sysctl to indicate the presence of optional | * A macro to generate a read-only sysctl to indicate the presence of optional | ||||
* kernel features. | * kernel features. | ||||
*/ | */ | ||||
#define FEATURE(name, desc) \ | #define FEATURE(name, desc) \ | ||||
SYSCTL_INT_WITH_LABEL(_kern_features, OID_AUTO, name, \ | SYSCTL_INT_WITH_LABEL(_kern_features, OID_AUTO, name, \ | ||||
CTLFLAG_RD | CTLFLAG_CAPRD, SYSCTL_NULL_INT_PTR, 1, desc, "feature") | CTLFLAG_RD | CTLFLAG_CAPRD, SYSCTL_NULL_INT_PTR, 1, desc, "feature") | ||||
▲ Show 20 Lines • Show All 277 Lines • Show Last 20 Lines |