Page MenuHomeFreeBSD

No OneTemporary

diff --git a/sys/compat/linuxkpi/common/include/linux/sysfs.h b/sys/compat/linuxkpi/common/include/linux/sysfs.h
index 0b6b479d9362..881a72e62ed9 100644
--- a/sys/compat/linuxkpi/common/include/linux/sysfs.h
+++ b/sys/compat/linuxkpi/common/include/linux/sysfs.h
@@ -1,300 +1,300 @@
/*-
* Copyright (c) 2010 Isilon Systems, Inc.
* Copyright (c) 2010 iX Systems, Inc.
* Copyright (c) 2010 Panasas, Inc.
* Copyright (c) 2013, 2014 Mellanox Technologies, Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice unmodified, this list of conditions, and the following
* disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $FreeBSD$
*/
#ifndef _LINUXKPI_LINUX_SYSFS_H_
#define _LINUXKPI_LINUX_SYSFS_H_
#include <sys/types.h>
#include <sys/sysctl.h>
#include <sys/errno.h>
#include <linux/kobject.h>
#include <linux/stringify.h>
struct sysfs_ops {
ssize_t (*show)(struct kobject *, struct attribute *, char *);
ssize_t (*store)(struct kobject *, struct attribute *, const char *,
size_t);
};
struct attribute_group {
const char *name;
mode_t (*is_visible)(struct kobject *,
struct attribute *, int);
struct attribute **attrs;
};
#define __ATTR(_name, _mode, _show, _store) { \
.attr = { .name = __stringify(_name), .mode = _mode }, \
.show = _show, .store = _store, \
}
#define __ATTR_RO(_name) __ATTR(_name, 0444, _name##_show, NULL)
#define __ATTR_WO(_name) __ATTR(_name, 0200, NULL, _name##_store)
#define __ATTR_RW(_name) __ATTR(_name, 0644, _name##_show, _name##_store)
#define __ATTR_NULL { .attr = { .name = NULL } }
#define ATTRIBUTE_GROUPS(_name) \
static struct attribute_group _name##_group = { \
.name = __stringify(_name), \
.attrs = _name##_attrs, \
}; \
static const struct attribute_group *_name##_groups[] = { \
&_name##_group, \
NULL, \
}
/*
* Handle our generic '\0' terminated 'C' string.
* Two cases:
* a variable string: point arg1 at it, arg2 is max length.
* a constant string: point arg1 at it, arg2 is zero.
*/
static inline int
sysctl_handle_attr(SYSCTL_HANDLER_ARGS)
{
struct kobject *kobj;
struct attribute *attr;
const struct sysfs_ops *ops;
char *buf;
int error;
ssize_t len;
kobj = arg1;
attr = (struct attribute *)(intptr_t)arg2;
if (kobj->ktype == NULL || kobj->ktype->sysfs_ops == NULL)
return (ENODEV);
buf = (char *)get_zeroed_page(GFP_KERNEL);
if (buf == NULL)
return (ENOMEM);
ops = kobj->ktype->sysfs_ops;
if (ops->show) {
len = ops->show(kobj, attr, buf);
/*
* It's valid to not have a 'show' so just return an
* empty string.
*/
if (len < 0) {
error = -len;
if (error != EIO)
goto out;
buf[0] = '\0';
} else if (len) {
len--;
if (len >= PAGE_SIZE)
len = PAGE_SIZE - 1;
/* Trim trailing newline. */
buf[len] = '\0';
}
}
/* Leave one trailing byte to append a newline. */
error = sysctl_handle_string(oidp, buf, PAGE_SIZE - 1, req);
if (error != 0 || req->newptr == NULL || ops->store == NULL)
goto out;
len = strlcat(buf, "\n", PAGE_SIZE);
KASSERT(len < PAGE_SIZE, ("new attribute truncated"));
len = ops->store(kobj, attr, buf, len);
if (len < 0)
error = -len;
out:
free_page((unsigned long)buf);
return (error);
}
static inline int
sysfs_create_file(struct kobject *kobj, const struct attribute *attr)
{
struct sysctl_oid *oid;
oid = SYSCTL_ADD_OID(NULL, SYSCTL_CHILDREN(kobj->oidp), OID_AUTO,
attr->name, CTLTYPE_STRING|CTLFLAG_RW|CTLFLAG_MPSAFE, kobj,
(uintptr_t)attr, sysctl_handle_attr, "A", "");
if (!oid) {
return (-ENOMEM);
}
return (0);
}
static inline void
sysfs_remove_file(struct kobject *kobj, const struct attribute *attr)
{
if (kobj->oidp)
sysctl_remove_name(kobj->oidp, attr->name, 1, 1);
}
static inline int
sysfs_create_files(struct kobject *kobj, const struct attribute * const *attrs)
{
int error = 0;
int i;
for (i = 0; attrs[i] && !error; i++)
error = sysfs_create_file(kobj, attrs[i]);
while (error && --i >= 0)
sysfs_remove_file(kobj, attrs[i]);
return (error);
}
static inline void
sysfs_remove_files(struct kobject *kobj, const struct attribute * const *attrs)
{
int i;
for (i = 0; attrs[i]; i++)
sysfs_remove_file(kobj, attrs[i]);
}
static inline int
sysfs_create_group(struct kobject *kobj, const struct attribute_group *grp)
{
struct attribute **attr;
struct sysctl_oid *oidp;
/* Don't create the group node if grp->name is undefined. */
if (grp->name)
oidp = SYSCTL_ADD_NODE(NULL, SYSCTL_CHILDREN(kobj->oidp),
OID_AUTO, grp->name, CTLFLAG_RD|CTLFLAG_MPSAFE, NULL, grp->name);
else
oidp = kobj->oidp;
for (attr = grp->attrs; *attr != NULL; attr++) {
SYSCTL_ADD_OID(NULL, SYSCTL_CHILDREN(oidp), OID_AUTO,
(*attr)->name, CTLTYPE_STRING|CTLFLAG_RW|CTLFLAG_MPSAFE,
kobj, (uintptr_t)*attr, sysctl_handle_attr, "A", "");
}
return (0);
}
static inline void
sysfs_remove_group(struct kobject *kobj, const struct attribute_group *grp)
{
if (kobj->oidp)
sysctl_remove_name(kobj->oidp, grp->name, 1, 1);
}
static inline int
sysfs_create_groups(struct kobject *kobj, const struct attribute_group **grps)
{
int error = 0;
int i;
if (grps == NULL)
goto done;
for (i = 0; grps[i] && !error; i++)
error = sysfs_create_group(kobj, grps[i]);
while (error && --i >= 0)
sysfs_remove_group(kobj, grps[i]);
done:
return (error);
}
static inline void
sysfs_remove_groups(struct kobject *kobj, const struct attribute_group **grps)
{
int i;
if (grps == NULL)
return;
for (i = 0; grps[i]; i++)
sysfs_remove_group(kobj, grps[i]);
}
static inline int
sysfs_merge_group(struct kobject *kobj, const struct attribute_group *grp)
{
/* Really expected behavior is to return failure if group exists. */
return (sysfs_create_group(kobj, grp));
}
static inline void
sysfs_unmerge_group(struct kobject *kobj, const struct attribute_group *grp)
{
struct attribute **attr;
struct sysctl_oid *oidp;
- SLIST_FOREACH(oidp, SYSCTL_CHILDREN(kobj->oidp), oid_link) {
+ RB_FOREACH(oidp, sysctl_oid_list, SYSCTL_CHILDREN(kobj->oidp)) {
if (strcmp(oidp->oid_name, grp->name) != 0)
continue;
for (attr = grp->attrs; *attr != NULL; attr++) {
sysctl_remove_name(oidp, (*attr)->name, 1, 1);
}
}
}
static inline int
sysfs_create_dir(struct kobject *kobj)
{
struct sysctl_oid *oid;
oid = SYSCTL_ADD_NODE(NULL, SYSCTL_CHILDREN(kobj->parent->oidp),
OID_AUTO, kobj->name, CTLFLAG_RD|CTLFLAG_MPSAFE, NULL, kobj->name);
if (!oid) {
return (-ENOMEM);
}
kobj->oidp = oid;
return (0);
}
static inline void
sysfs_remove_dir(struct kobject *kobj)
{
if (kobj->oidp == NULL)
return;
sysctl_remove_oid(kobj->oidp, 1, 1);
}
static inline bool
sysfs_streq(const char *s1, const char *s2)
{
int l1, l2;
l1 = strlen(s1);
l2 = strlen(s2);
if (l1 != 0 && s1[l1-1] == '\n')
l1--;
if (l2 != 0 && s2[l2-1] == '\n')
l2--;
return (l1 == l2 && strncmp(s1, s2, l1) == 0);
}
#define sysfs_attr_init(attr) do {} while(0)
#endif /* _LINUXKPI_LINUX_SYSFS_H_ */
diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c
index 9bc595f111cc..e1cd6ea4bd61 100644
--- a/sys/kern/kern_sysctl.c
+++ b/sys/kern/kern_sysctl.c
@@ -1,3038 +1,3031 @@
/*-
* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright (c) 1982, 1986, 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Mike Karels at Berkeley Software Design, Inc.
*
* Quite extensively rewritten by Poul-Henning Kamp of the FreeBSD
* project, to make these variables more userfriendly.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)kern_sysctl.c 8.4 (Berkeley) 4/14/94
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include "opt_capsicum.h"
#include "opt_ddb.h"
#include "opt_ktrace.h"
#include "opt_sysctl.h"
#include <sys/param.h>
#include <sys/fail.h>
#include <sys/systm.h>
#include <sys/capsicum.h>
#include <sys/kernel.h>
#include <sys/limits.h>
#include <sys/sysctl.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <sys/proc.h>
#include <sys/jail.h>
#include <sys/kdb.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/rmlock.h>
#include <sys/sbuf.h>
#include <sys/sx.h>
#include <sys/sysproto.h>
#include <sys/uio.h>
#ifdef KTRACE
#include <sys/ktrace.h>
#endif
#ifdef DDB
#include <ddb/ddb.h>
#include <ddb/db_lex.h>
#endif
#include <net/vnet.h>
#include <security/mac/mac_framework.h>
#include <vm/vm.h>
#include <vm/vm_extern.h>
static MALLOC_DEFINE(M_SYSCTL, "sysctl", "sysctl internal magic");
static MALLOC_DEFINE(M_SYSCTLOID, "sysctloid", "sysctl dynamic oids");
static MALLOC_DEFINE(M_SYSCTLTMP, "sysctltmp", "sysctl temp output buffer");
+RB_GENERATE(sysctl_oid_list, sysctl_oid, oid_link, cmp_sysctl_oid);
+
/*
* The sysctllock protects the MIB tree. It also protects sysctl
* contexts used with dynamic sysctls. The sysctl_register_oid() and
* sysctl_unregister_oid() routines require the sysctllock to already
* be held, so the sysctl_wlock() and sysctl_wunlock() routines are
* provided for the few places in the kernel which need to use that
* API rather than using the dynamic API. Use of the dynamic API is
* strongly encouraged for most code.
*
* The sysctlmemlock is used to limit the amount of user memory wired for
* sysctl requests. This is implemented by serializing any userland
* sysctl requests larger than a single page via an exclusive lock.
*
* The sysctlstringlock is used to protect concurrent access to writable
* string nodes in sysctl_handle_string().
*/
static struct rmlock sysctllock;
static struct sx __exclusive_cache_line sysctlmemlock;
static struct sx sysctlstringlock;
#define SYSCTL_WLOCK() rm_wlock(&sysctllock)
#define SYSCTL_WUNLOCK() rm_wunlock(&sysctllock)
#define SYSCTL_RLOCK(tracker) rm_rlock(&sysctllock, (tracker))
#define SYSCTL_RUNLOCK(tracker) rm_runlock(&sysctllock, (tracker))
#define SYSCTL_WLOCKED() rm_wowned(&sysctllock)
#define SYSCTL_ASSERT_LOCKED() rm_assert(&sysctllock, RA_LOCKED)
#define SYSCTL_ASSERT_WLOCKED() rm_assert(&sysctllock, RA_WLOCKED)
#define SYSCTL_ASSERT_RLOCKED() rm_assert(&sysctllock, RA_RLOCKED)
#define SYSCTL_INIT() rm_init_flags(&sysctllock, "sysctl lock", \
RM_SLEEPABLE)
#define SYSCTL_SLEEP(ch, wmesg, timo) \
rm_sleep(ch, &sysctllock, 0, wmesg, timo)
static int sysctl_root(SYSCTL_HANDLER_ARGS);
/* Root list */
-struct sysctl_oid_list sysctl__children = SLIST_HEAD_INITIALIZER(&sysctl__children);
+struct sysctl_oid_list sysctl__children = RB_INITIALIZER(&sysctl__children);
static char* sysctl_escape_name(const char*);
static int sysctl_remove_oid_locked(struct sysctl_oid *oidp, int del,
int recurse);
static int sysctl_old_kernel(struct sysctl_req *, const void *, size_t);
static int sysctl_new_kernel(struct sysctl_req *, void *, size_t);
static struct sysctl_oid *
sysctl_find_oidname(const char *name, struct sysctl_oid_list *list)
{
struct sysctl_oid *oidp;
SYSCTL_ASSERT_LOCKED();
- SLIST_FOREACH(oidp, list, oid_link) {
+ RB_FOREACH(oidp, sysctl_oid_list, list) {
if (strcmp(oidp->oid_name, name) == 0) {
return (oidp);
}
}
return (NULL);
}
/*
* Initialization of the MIB tree.
*
* Order by number in each list.
*/
void
sysctl_wlock(void)
{
SYSCTL_WLOCK();
}
void
sysctl_wunlock(void)
{
SYSCTL_WUNLOCK();
}
static int
sysctl_root_handler_locked(struct sysctl_oid *oid, void *arg1, intmax_t arg2,
struct sysctl_req *req, struct rm_priotracker *tracker)
{
int error;
if (oid->oid_kind & CTLFLAG_DYN)
atomic_add_int(&oid->oid_running, 1);
if (tracker != NULL)
SYSCTL_RUNLOCK(tracker);
else
SYSCTL_WUNLOCK();
/*
* Treat set CTLFLAG_NEEDGIANT and unset CTLFLAG_MPSAFE flags the same,
* untill we're ready to remove all traces of Giant from sysctl(9).
*/
if ((oid->oid_kind & CTLFLAG_NEEDGIANT) ||
(!(oid->oid_kind & CTLFLAG_MPSAFE)))
mtx_lock(&Giant);
error = oid->oid_handler(oid, arg1, arg2, req);
if ((oid->oid_kind & CTLFLAG_NEEDGIANT) ||
(!(oid->oid_kind & CTLFLAG_MPSAFE)))
mtx_unlock(&Giant);
KFAIL_POINT_ERROR(_debug_fail_point, sysctl_running, error);
if (tracker != NULL)
SYSCTL_RLOCK(tracker);
else
SYSCTL_WLOCK();
if (oid->oid_kind & CTLFLAG_DYN) {
if (atomic_fetchadd_int(&oid->oid_running, -1) == 1 &&
(oid->oid_kind & CTLFLAG_DYING) != 0)
wakeup(&oid->oid_running);
}
return (error);
}
static void
sysctl_load_tunable_by_oid_locked(struct sysctl_oid *oidp)
{
struct sysctl_req req;
struct sysctl_oid *curr;
char *penv = NULL;
char path[96];
ssize_t rem = sizeof(path);
ssize_t len;
uint8_t data[512] __aligned(sizeof(uint64_t));
int size;
int error;
path[--rem] = 0;
for (curr = oidp; curr != NULL; curr = SYSCTL_PARENT(curr)) {
len = strlen(curr->oid_name);
rem -= len;
if (curr != oidp)
rem -= 1;
if (rem < 0) {
printf("OID path exceeds %d bytes\n", (int)sizeof(path));
return;
}
memcpy(path + rem, curr->oid_name, len);
if (curr != oidp)
path[rem + len] = '.';
}
memset(&req, 0, sizeof(req));
req.td = curthread;
req.oldfunc = sysctl_old_kernel;
req.newfunc = sysctl_new_kernel;
req.lock = REQ_UNWIRED;
switch (oidp->oid_kind & CTLTYPE) {
case CTLTYPE_INT:
if (getenv_array(path + rem, data, sizeof(data), &size,
sizeof(int), GETENV_SIGNED) == 0)
return;
req.newlen = size;
req.newptr = data;
break;
case CTLTYPE_UINT:
if (getenv_array(path + rem, data, sizeof(data), &size,
sizeof(int), GETENV_UNSIGNED) == 0)
return;
req.newlen = size;
req.newptr = data;
break;
case CTLTYPE_LONG:
if (getenv_array(path + rem, data, sizeof(data), &size,
sizeof(long), GETENV_SIGNED) == 0)
return;
req.newlen = size;
req.newptr = data;
break;
case CTLTYPE_ULONG:
if (getenv_array(path + rem, data, sizeof(data), &size,
sizeof(long), GETENV_UNSIGNED) == 0)
return;
req.newlen = size;
req.newptr = data;
break;
case CTLTYPE_S8:
if (getenv_array(path + rem, data, sizeof(data), &size,
sizeof(int8_t), GETENV_SIGNED) == 0)
return;
req.newlen = size;
req.newptr = data;
break;
case CTLTYPE_S16:
if (getenv_array(path + rem, data, sizeof(data), &size,
sizeof(int16_t), GETENV_SIGNED) == 0)
return;
req.newlen = size;
req.newptr = data;
break;
case CTLTYPE_S32:
if (getenv_array(path + rem, data, sizeof(data), &size,
sizeof(int32_t), GETENV_SIGNED) == 0)
return;
req.newlen = size;
req.newptr = data;
break;
case CTLTYPE_S64:
if (getenv_array(path + rem, data, sizeof(data), &size,
sizeof(int64_t), GETENV_SIGNED) == 0)
return;
req.newlen = size;
req.newptr = data;
break;
case CTLTYPE_U8:
if (getenv_array(path + rem, data, sizeof(data), &size,
sizeof(uint8_t), GETENV_UNSIGNED) == 0)
return;
req.newlen = size;
req.newptr = data;
break;
case CTLTYPE_U16:
if (getenv_array(path + rem, data, sizeof(data), &size,
sizeof(uint16_t), GETENV_UNSIGNED) == 0)
return;
req.newlen = size;
req.newptr = data;
break;
case CTLTYPE_U32:
if (getenv_array(path + rem, data, sizeof(data), &size,
sizeof(uint32_t), GETENV_UNSIGNED) == 0)
return;
req.newlen = size;
req.newptr = data;
break;
case CTLTYPE_U64:
if (getenv_array(path + rem, data, sizeof(data), &size,
sizeof(uint64_t), GETENV_UNSIGNED) == 0)
return;
req.newlen = size;
req.newptr = data;
break;
case CTLTYPE_STRING:
penv = kern_getenv(path + rem);
if (penv == NULL)
return;
req.newlen = strlen(penv);
req.newptr = penv;
break;
default:
return;
}
error = sysctl_root_handler_locked(oidp, oidp->oid_arg1,
oidp->oid_arg2, &req, NULL);
if (error != 0)
printf("Setting sysctl %s failed: %d\n", path + rem, error);
if (penv != NULL)
freeenv(penv);
}
/*
* Locate the path to a given oid. Returns the length of the resulting path,
* or -1 if the oid was not found. nodes must have room for CTL_MAXNAME
* elements and be NULL initialized.
*/
static int
sysctl_search_oid(struct sysctl_oid **nodes, struct sysctl_oid *needle)
{
int indx;
SYSCTL_ASSERT_LOCKED();
indx = 0;
while (indx < CTL_MAXNAME && indx >= 0) {
if (nodes[indx] == NULL && indx == 0)
- nodes[indx] = SLIST_FIRST(&sysctl__children);
+ nodes[indx] = RB_MIN(sysctl_oid_list,
+ &sysctl__children);
else if (nodes[indx] == NULL)
- nodes[indx] = SLIST_FIRST(&nodes[indx - 1]->oid_children);
+ nodes[indx] = RB_MIN(sysctl_oid_list,
+ &nodes[indx - 1]->oid_children);
else
- nodes[indx] = SLIST_NEXT(nodes[indx], oid_link);
+ nodes[indx] = RB_NEXT(sysctl_oid_list,
+ &nodes[indx - 1]->oid_children, nodes[indx]);
if (nodes[indx] == needle)
return (indx + 1);
if (nodes[indx] == NULL) {
indx--;
continue;
}
if ((nodes[indx]->oid_kind & CTLTYPE) == CTLTYPE_NODE) {
indx++;
continue;
}
}
return (-1);
}
static void
sysctl_warn_reuse(const char *func, struct sysctl_oid *leaf)
{
struct sysctl_oid *nodes[CTL_MAXNAME];
char buf[128];
struct sbuf sb;
int rc, i;
(void)sbuf_new(&sb, buf, sizeof(buf), SBUF_FIXEDLEN | SBUF_INCLUDENUL);
sbuf_set_drain(&sb, sbuf_printf_drain, NULL);
sbuf_printf(&sb, "%s: can't re-use a leaf (", __func__);
memset(nodes, 0, sizeof(nodes));
rc = sysctl_search_oid(nodes, leaf);
if (rc > 0) {
for (i = 0; i < rc; i++)
sbuf_printf(&sb, "%s%.*s", nodes[i]->oid_name,
i != (rc - 1), ".");
} else {
sbuf_printf(&sb, "%s", leaf->oid_name);
}
sbuf_printf(&sb, ")!\n");
(void)sbuf_finish(&sb);
}
#ifdef SYSCTL_DEBUG
static int
sysctl_reuse_test(SYSCTL_HANDLER_ARGS)
{
struct rm_priotracker tracker;
SYSCTL_RLOCK(&tracker);
sysctl_warn_reuse(__func__, oidp);
SYSCTL_RUNLOCK(&tracker);
return (0);
}
SYSCTL_PROC(_sysctl, OID_AUTO, reuse_test,
CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, 0, 0, sysctl_reuse_test, "-",
"");
#endif
void
sysctl_register_oid(struct sysctl_oid *oidp)
{
struct sysctl_oid_list *parent = oidp->oid_parent;
- struct sysctl_oid *p;
- struct sysctl_oid *q;
+ struct sysctl_oid *p, key;
int oid_number;
int timeout = 2;
/*
* First check if another oid with the same name already
* exists in the parent's list.
*/
SYSCTL_ASSERT_WLOCKED();
p = sysctl_find_oidname(oidp->oid_name, parent);
if (p != NULL) {
if ((p->oid_kind & CTLTYPE) == CTLTYPE_NODE) {
p->oid_refcnt++;
return;
} else {
sysctl_warn_reuse(__func__, p);
return;
}
}
/* get current OID number */
oid_number = oidp->oid_number;
#if (OID_AUTO >= 0)
#error "OID_AUTO is expected to be a negative value"
#endif
/*
* Any negative OID number qualifies as OID_AUTO. Valid OID
* numbers should always be positive.
*
* NOTE: DO NOT change the starting value here, change it in
* <sys/sysctl.h>, and make sure it is at least 256 to
* accommodate e.g. net.inet.raw as a static sysctl node.
*/
if (oid_number < 0) {
static int newoid;
/*
* By decrementing the next OID number we spend less
* time inserting the OIDs into a sorted list.
*/
if (--newoid < CTL_AUTO_START)
newoid = 0x7fffffff;
oid_number = newoid;
}
/*
* Insert the OID into the parent's list sorted by OID number.
*/
retry:
- q = NULL;
- SLIST_FOREACH(p, parent, oid_link) {
- /* check if the current OID number is in use */
- if (oid_number == p->oid_number) {
- /* get the next valid OID number */
- if (oid_number < CTL_AUTO_START ||
- oid_number == 0x7fffffff) {
- /* wraparound - restart */
- oid_number = CTL_AUTO_START;
- /* don't loop forever */
- if (!timeout--)
- panic("sysctl: Out of OID numbers\n");
- goto retry;
- } else {
- oid_number++;
- }
- } else if (oid_number < p->oid_number)
- break;
- q = p;
+ key.oid_number = oid_number;
+ p = RB_FIND(sysctl_oid_list, parent, &key);
+ if (p) {
+ /* get the next valid OID number */
+ if (oid_number < CTL_AUTO_START ||
+ oid_number == 0x7fffffff) {
+ /* wraparound - restart */
+ oid_number = CTL_AUTO_START;
+ /* don't loop forever */
+ if (!timeout--)
+ panic("sysctl: Out of OID numbers\n");
+ goto retry;
+ } else {
+ oid_number++;
+ }
}
/* check for non-auto OID number collision */
if (oidp->oid_number >= 0 && oidp->oid_number < CTL_AUTO_START &&
oid_number >= CTL_AUTO_START) {
printf("sysctl: OID number(%d) is already in use for '%s'\n",
oidp->oid_number, oidp->oid_name);
}
/* update the OID number, if any */
oidp->oid_number = oid_number;
- if (q != NULL)
- SLIST_INSERT_AFTER(q, oidp, oid_link);
- else
- SLIST_INSERT_HEAD(parent, oidp, oid_link);
+ RB_INSERT(sysctl_oid_list, parent, oidp);
if ((oidp->oid_kind & CTLTYPE) != CTLTYPE_NODE &&
#ifdef VIMAGE
(oidp->oid_kind & CTLFLAG_VNET) == 0 &&
#endif
(oidp->oid_kind & CTLFLAG_TUN) != 0 &&
(oidp->oid_kind & CTLFLAG_NOFETCH) == 0) {
/* only fetch value once */
oidp->oid_kind |= CTLFLAG_NOFETCH;
/* try to fetch value from kernel environment */
sysctl_load_tunable_by_oid_locked(oidp);
}
}
void
sysctl_register_disabled_oid(struct sysctl_oid *oidp)
{
/*
* Mark the leaf as dormant if it's not to be immediately enabled.
* We do not disable nodes as they can be shared between modules
* and it is always safe to access a node.
*/
KASSERT((oidp->oid_kind & CTLFLAG_DORMANT) == 0,
("internal flag is set in oid_kind"));
if ((oidp->oid_kind & CTLTYPE) != CTLTYPE_NODE)
oidp->oid_kind |= CTLFLAG_DORMANT;
sysctl_register_oid(oidp);
}
void
sysctl_enable_oid(struct sysctl_oid *oidp)
{
SYSCTL_ASSERT_WLOCKED();
if ((oidp->oid_kind & CTLTYPE) == CTLTYPE_NODE) {
KASSERT((oidp->oid_kind & CTLFLAG_DORMANT) == 0,
("sysctl node is marked as dormant"));
return;
}
KASSERT((oidp->oid_kind & CTLFLAG_DORMANT) != 0,
("enabling already enabled sysctl oid"));
oidp->oid_kind &= ~CTLFLAG_DORMANT;
}
void
sysctl_unregister_oid(struct sysctl_oid *oidp)
{
- struct sysctl_oid *p;
int error;
SYSCTL_ASSERT_WLOCKED();
if (oidp->oid_number == OID_AUTO) {
error = EINVAL;
} else {
error = ENOENT;
- SLIST_FOREACH(p, oidp->oid_parent, oid_link) {
- if (p == oidp) {
- SLIST_REMOVE(oidp->oid_parent, oidp,
- sysctl_oid, oid_link);
- error = 0;
- break;
- }
- }
+ if (RB_REMOVE(sysctl_oid_list, oidp->oid_parent, oidp))
+ error = 0;
}
/*
* This can happen when a module fails to register and is
* being unloaded afterwards. It should not be a panic()
* for normal use.
*/
if (error) {
printf("%s: failed(%d) to unregister sysctl(%s)\n",
__func__, error, oidp->oid_name);
}
}
/* Initialize a new context to keep track of dynamically added sysctls. */
int
sysctl_ctx_init(struct sysctl_ctx_list *c)
{
if (c == NULL) {
return (EINVAL);
}
/*
* No locking here, the caller is responsible for not adding
* new nodes to a context until after this function has
* returned.
*/
TAILQ_INIT(c);
return (0);
}
/* Free the context, and destroy all dynamic oids registered in this context */
int
sysctl_ctx_free(struct sysctl_ctx_list *clist)
{
struct sysctl_ctx_entry *e, *e1;
int error;
error = 0;
/*
* First perform a "dry run" to check if it's ok to remove oids.
* XXX FIXME
* XXX This algorithm is a hack. But I don't know any
* XXX better solution for now...
*/
SYSCTL_WLOCK();
TAILQ_FOREACH(e, clist, link) {
error = sysctl_remove_oid_locked(e->entry, 0, 0);
if (error)
break;
}
/*
* Restore deregistered entries, either from the end,
* or from the place where error occurred.
* e contains the entry that was not unregistered
*/
if (error)
e1 = TAILQ_PREV(e, sysctl_ctx_list, link);
else
e1 = TAILQ_LAST(clist, sysctl_ctx_list);
while (e1 != NULL) {
sysctl_register_oid(e1->entry);
e1 = TAILQ_PREV(e1, sysctl_ctx_list, link);
}
if (error) {
SYSCTL_WUNLOCK();
return(EBUSY);
}
/* Now really delete the entries */
e = TAILQ_FIRST(clist);
while (e != NULL) {
e1 = TAILQ_NEXT(e, link);
error = sysctl_remove_oid_locked(e->entry, 1, 0);
if (error)
panic("sysctl_remove_oid: corrupt tree, entry: %s",
e->entry->oid_name);
free(e, M_SYSCTLOID);
e = e1;
}
SYSCTL_WUNLOCK();
return (error);
}
/* Add an entry to the context */
struct sysctl_ctx_entry *
sysctl_ctx_entry_add(struct sysctl_ctx_list *clist, struct sysctl_oid *oidp)
{
struct sysctl_ctx_entry *e;
SYSCTL_ASSERT_WLOCKED();
if (clist == NULL || oidp == NULL)
return(NULL);
e = malloc(sizeof(struct sysctl_ctx_entry), M_SYSCTLOID, M_WAITOK);
e->entry = oidp;
TAILQ_INSERT_HEAD(clist, e, link);
return (e);
}
/* Find an entry in the context */
struct sysctl_ctx_entry *
sysctl_ctx_entry_find(struct sysctl_ctx_list *clist, struct sysctl_oid *oidp)
{
struct sysctl_ctx_entry *e;
SYSCTL_ASSERT_WLOCKED();
if (clist == NULL || oidp == NULL)
return(NULL);
TAILQ_FOREACH(e, clist, link) {
if (e->entry == oidp)
return(e);
}
return (e);
}
/*
* Delete an entry from the context.
* NOTE: this function doesn't free oidp! You have to remove it
* with sysctl_remove_oid().
*/
int
sysctl_ctx_entry_del(struct sysctl_ctx_list *clist, struct sysctl_oid *oidp)
{
struct sysctl_ctx_entry *e;
if (clist == NULL || oidp == NULL)
return (EINVAL);
SYSCTL_WLOCK();
e = sysctl_ctx_entry_find(clist, oidp);
if (e != NULL) {
TAILQ_REMOVE(clist, e, link);
SYSCTL_WUNLOCK();
free(e, M_SYSCTLOID);
return (0);
} else {
SYSCTL_WUNLOCK();
return (ENOENT);
}
}
/*
* Remove dynamically created sysctl trees.
* oidp - top of the tree to be removed
* del - if 0 - just deregister, otherwise free up entries as well
* recurse - if != 0 traverse the subtree to be deleted
*/
int
sysctl_remove_oid(struct sysctl_oid *oidp, int del, int recurse)
{
int error;
SYSCTL_WLOCK();
error = sysctl_remove_oid_locked(oidp, del, recurse);
SYSCTL_WUNLOCK();
return (error);
}
int
sysctl_remove_name(struct sysctl_oid *parent, const char *name,
int del, int recurse)
{
- struct sysctl_oid *p, *tmp;
+ struct sysctl_oid *p;
int error;
error = ENOENT;
SYSCTL_WLOCK();
- SLIST_FOREACH_SAFE(p, SYSCTL_CHILDREN(parent), oid_link, tmp) {
- if (strcmp(p->oid_name, name) == 0) {
- error = sysctl_remove_oid_locked(p, del, recurse);
- break;
- }
- }
+ p = sysctl_find_oidname(name, &parent->oid_children);
+ if (p)
+ error = sysctl_remove_oid_locked(p, del, recurse);
SYSCTL_WUNLOCK();
return (error);
}
/*
* Duplicate the provided string, escaping any illegal characters. The result
* must be freed when no longer in use.
*
* The list of illegal characters is ".".
*/
static char*
sysctl_escape_name(const char* orig)
{
int i, s = 0, d = 0, nillegals = 0;
char *new;
/* First count the number of illegal characters */
for (i = 0; orig[i] != '\0'; i++) {
if (orig[i] == '.')
nillegals++;
}
/* Allocate storage for new string */
new = malloc(i + 2 * nillegals + 1, M_SYSCTLOID, M_WAITOK);
/* Copy the name, escaping characters as we go */
while (orig[s] != '\0') {
if (orig[s] == '.') {
/* %25 is the hexadecimal representation of '.' */
new[d++] = '%';
new[d++] = '2';
new[d++] = '5';
s++;
} else {
new[d++] = orig[s++];
}
}
/* Finally, nul-terminate */
new[d] = '\0';
return (new);
}
static int
sysctl_remove_oid_locked(struct sysctl_oid *oidp, int del, int recurse)
{
struct sysctl_oid *p, *tmp;
int error;
SYSCTL_ASSERT_WLOCKED();
if (oidp == NULL)
return(EINVAL);
if ((oidp->oid_kind & CTLFLAG_DYN) == 0) {
printf("Warning: can't remove non-dynamic nodes (%s)!\n",
oidp->oid_name);
return (EINVAL);
}
/*
* WARNING: normal method to do this should be through
* sysctl_ctx_free(). Use recursing as the last resort
* method to purge your sysctl tree of leftovers...
* However, if some other code still references these nodes,
* it will panic.
*/
if ((oidp->oid_kind & CTLTYPE) == CTLTYPE_NODE) {
if (oidp->oid_refcnt == 1) {
- SLIST_FOREACH_SAFE(p,
- SYSCTL_CHILDREN(oidp), oid_link, tmp) {
+ for(p = RB_MIN(sysctl_oid_list, &oidp->oid_children);
+ p != NULL; p = tmp) {
if (!recurse) {
printf("Warning: failed attempt to "
"remove oid %s with child %s\n",
oidp->oid_name, p->oid_name);
return (ENOTEMPTY);
}
+ tmp = RB_NEXT(sysctl_oid_list,
+ &oidp->oid_children, p);
error = sysctl_remove_oid_locked(p, del,
recurse);
if (error)
return (error);
}
}
}
if (oidp->oid_refcnt > 1 ) {
oidp->oid_refcnt--;
} else {
if (oidp->oid_refcnt == 0) {
printf("Warning: bad oid_refcnt=%u (%s)!\n",
oidp->oid_refcnt, oidp->oid_name);
return (EINVAL);
}
sysctl_unregister_oid(oidp);
if (del) {
/*
* Wait for all threads running the handler to drain.
* This preserves the previous behavior when the
* sysctl lock was held across a handler invocation,
* and is necessary for module unload correctness.
*/
while (oidp->oid_running > 0) {
oidp->oid_kind |= CTLFLAG_DYING;
SYSCTL_SLEEP(&oidp->oid_running, "oidrm", 0);
}
if (oidp->oid_descr)
free(__DECONST(char *, oidp->oid_descr),
M_SYSCTLOID);
if (oidp->oid_label)
free(__DECONST(char *, oidp->oid_label),
M_SYSCTLOID);
free(__DECONST(char *, oidp->oid_name), M_SYSCTLOID);
free(oidp, M_SYSCTLOID);
}
}
return (0);
}
/*
* Create new sysctls at run time.
* clist may point to a valid context initialized with sysctl_ctx_init().
*/
struct sysctl_oid *
sysctl_add_oid(struct sysctl_ctx_list *clist, struct sysctl_oid_list *parent,
int number, const char *name, int kind, void *arg1, intmax_t arg2,
int (*handler)(SYSCTL_HANDLER_ARGS), const char *fmt, const char *descr,
const char *label)
{
struct sysctl_oid *oidp;
char *escaped;
/* You have to hook up somewhere.. */
if (parent == NULL)
return(NULL);
escaped = sysctl_escape_name(name);
/* Check if the node already exists, otherwise create it */
SYSCTL_WLOCK();
oidp = sysctl_find_oidname(escaped, parent);
if (oidp != NULL) {
free(escaped, M_SYSCTLOID);
if ((oidp->oid_kind & CTLTYPE) == CTLTYPE_NODE) {
oidp->oid_refcnt++;
/* Update the context */
if (clist != NULL)
sysctl_ctx_entry_add(clist, oidp);
SYSCTL_WUNLOCK();
return (oidp);
} else {
sysctl_warn_reuse(__func__, oidp);
SYSCTL_WUNLOCK();
return (NULL);
}
}
oidp = malloc(sizeof(struct sysctl_oid), M_SYSCTLOID, M_WAITOK|M_ZERO);
oidp->oid_parent = parent;
- SLIST_INIT(&oidp->oid_children);
+ RB_INIT(&oidp->oid_children);
oidp->oid_number = number;
oidp->oid_refcnt = 1;
oidp->oid_name = escaped;
oidp->oid_handler = handler;
oidp->oid_kind = CTLFLAG_DYN | kind;
oidp->oid_arg1 = arg1;
oidp->oid_arg2 = arg2;
oidp->oid_fmt = fmt;
if (descr != NULL)
oidp->oid_descr = strdup(descr, M_SYSCTLOID);
if (label != NULL)
oidp->oid_label = strdup(label, M_SYSCTLOID);
/* Update the context, if used */
if (clist != NULL)
sysctl_ctx_entry_add(clist, oidp);
/* Register this oid */
sysctl_register_oid(oidp);
SYSCTL_WUNLOCK();
return (oidp);
}
/*
* Rename an existing oid.
*/
void
sysctl_rename_oid(struct sysctl_oid *oidp, const char *name)
{
char *newname;
char *oldname;
newname = strdup(name, M_SYSCTLOID);
SYSCTL_WLOCK();
oldname = __DECONST(char *, oidp->oid_name);
oidp->oid_name = newname;
SYSCTL_WUNLOCK();
free(oldname, M_SYSCTLOID);
}
/*
* Reparent an existing oid.
*/
int
sysctl_move_oid(struct sysctl_oid *oid, struct sysctl_oid_list *parent)
{
struct sysctl_oid *oidp;
SYSCTL_WLOCK();
if (oid->oid_parent == parent) {
SYSCTL_WUNLOCK();
return (0);
}
oidp = sysctl_find_oidname(oid->oid_name, parent);
if (oidp != NULL) {
SYSCTL_WUNLOCK();
return (EEXIST);
}
sysctl_unregister_oid(oid);
oid->oid_parent = parent;
oid->oid_number = OID_AUTO;
sysctl_register_oid(oid);
SYSCTL_WUNLOCK();
return (0);
}
/*
* Register the kernel's oids on startup.
*/
SET_DECLARE(sysctl_set, struct sysctl_oid);
static void
sysctl_register_all(void *arg)
{
struct sysctl_oid **oidp;
sx_init(&sysctlmemlock, "sysctl mem");
sx_init(&sysctlstringlock, "sysctl string handler");
SYSCTL_INIT();
SYSCTL_WLOCK();
SET_FOREACH(oidp, sysctl_set)
sysctl_register_oid(*oidp);
SYSCTL_WUNLOCK();
}
SYSINIT(sysctl, SI_SUB_KMEM, SI_ORDER_FIRST, sysctl_register_all, NULL);
/*
* "Staff-functions"
*
* These functions implement a presently undocumented interface
* used by the sysctl program to walk the tree, and get the type
* so it can print the value.
* This interface is under work and consideration, and should probably
* be killed with a big axe by the first person who can find the time.
* (be aware though, that the proper interface isn't as obvious as it
* may seem, there are various conflicting requirements.
*
* {CTL_SYSCTL, CTL_SYSCTL_DEBUG} printf the entire MIB-tree.
* {CTL_SYSCTL, CTL_SYSCTL_NAME, ...} return the name of the "..."
* OID.
* {CTL_SYSCTL, CTL_SYSCTL_NEXT, ...} return the next OID, honoring
* CTLFLAG_SKIP.
* {CTL_SYSCTL, CTL_SYSCTL_NAME2OID} return the OID of the name in
* "new"
* {CTL_SYSCTL, CTL_SYSCTL_OIDFMT, ...} return the kind & format info
* for the "..." OID.
* {CTL_SYSCTL, CTL_SYSCTL_OIDDESCR, ...} return the description of the
* "..." OID.
* {CTL_SYSCTL, CTL_SYSCTL_OIDLABEL, ...} return the aggregation label of
* the "..." OID.
* {CTL_SYSCTL, CTL_SYSCTL_NEXTNOSKIP, ...} return the next OID, ignoring
* CTLFLAG_SKIP.
*/
#ifdef SYSCTL_DEBUG
static void
sysctl_sysctl_debug_dump_node(struct sysctl_oid_list *l, int i)
{
int k;
struct sysctl_oid *oidp;
SYSCTL_ASSERT_LOCKED();
- SLIST_FOREACH(oidp, l, oid_link) {
+ RB_FOREACH(oidp, sysctl_oid_list, l) {
for (k=0; k<i; k++)
printf(" ");
printf("%d %s ", oidp->oid_number, oidp->oid_name);
printf("%c%c",
oidp->oid_kind & CTLFLAG_RD ? 'R':' ',
oidp->oid_kind & CTLFLAG_WR ? 'W':' ');
if (oidp->oid_handler)
printf(" *Handler");
switch (oidp->oid_kind & CTLTYPE) {
case CTLTYPE_NODE:
printf(" Node\n");
if (!oidp->oid_handler) {
sysctl_sysctl_debug_dump_node(
SYSCTL_CHILDREN(oidp), i + 2);
}
break;
case CTLTYPE_INT: printf(" Int\n"); break;
case CTLTYPE_UINT: printf(" u_int\n"); break;
case CTLTYPE_LONG: printf(" Long\n"); break;
case CTLTYPE_ULONG: printf(" u_long\n"); break;
case CTLTYPE_STRING: printf(" String\n"); break;
case CTLTYPE_S8: printf(" int8_t\n"); break;
case CTLTYPE_S16: printf(" int16_t\n"); break;
case CTLTYPE_S32: printf(" int32_t\n"); break;
case CTLTYPE_S64: printf(" int64_t\n"); break;
case CTLTYPE_U8: printf(" uint8_t\n"); break;
case CTLTYPE_U16: printf(" uint16_t\n"); break;
case CTLTYPE_U32: printf(" uint32_t\n"); break;
case CTLTYPE_U64: printf(" uint64_t\n"); break;
case CTLTYPE_OPAQUE: printf(" Opaque/struct\n"); break;
default: printf("\n");
}
}
}
static int
sysctl_sysctl_debug(SYSCTL_HANDLER_ARGS)
{
struct rm_priotracker tracker;
int error;
error = priv_check(req->td, PRIV_SYSCTL_DEBUG);
if (error)
return (error);
SYSCTL_RLOCK(&tracker);
sysctl_sysctl_debug_dump_node(&sysctl__children, 0);
SYSCTL_RUNLOCK(&tracker);
return (ENOENT);
}
SYSCTL_PROC(_sysctl, CTL_SYSCTL_DEBUG, debug, CTLTYPE_STRING | CTLFLAG_RD |
CTLFLAG_MPSAFE, 0, 0, sysctl_sysctl_debug, "-", "");
#endif
static int
sysctl_sysctl_name(SYSCTL_HANDLER_ARGS)
{
int *name = (int *) arg1;
u_int namelen = arg2;
int error;
- struct sysctl_oid *oid;
+ struct sysctl_oid *oid, key;
struct sysctl_oid_list *lsp = &sysctl__children, *lsp2;
struct rm_priotracker tracker;
char buf[10];
error = sysctl_wire_old_buffer(req, 0);
if (error)
return (error);
SYSCTL_RLOCK(&tracker);
while (namelen) {
if (!lsp) {
snprintf(buf,sizeof(buf),"%d",*name);
if (req->oldidx)
error = SYSCTL_OUT(req, ".", 1);
if (!error)
error = SYSCTL_OUT(req, buf, strlen(buf));
if (error)
goto out;
namelen--;
name++;
continue;
}
lsp2 = NULL;
- SLIST_FOREACH(oid, lsp, oid_link) {
- if (oid->oid_number != *name)
- continue;
-
+ key.oid_number = *name;
+ oid = RB_FIND(sysctl_oid_list, lsp, &key);
+ if (oid) {
if (req->oldidx)
error = SYSCTL_OUT(req, ".", 1);
if (!error)
error = SYSCTL_OUT(req, oid->oid_name,
strlen(oid->oid_name));
if (error)
goto out;
namelen--;
name++;
- if ((oid->oid_kind & CTLTYPE) != CTLTYPE_NODE)
- break;
-
- if (oid->oid_handler)
- break;
-
- lsp2 = SYSCTL_CHILDREN(oid);
- break;
+ if ((oid->oid_kind & CTLTYPE) == CTLTYPE_NODE &&
+ !oid->oid_handler)
+ lsp2 = SYSCTL_CHILDREN(oid);
}
lsp = lsp2;
}
error = SYSCTL_OUT(req, "", 1);
out:
SYSCTL_RUNLOCK(&tracker);
return (error);
}
/*
* XXXRW/JA: Shouldn't return name data for nodes that we don't permit in
* capability mode.
*/
static SYSCTL_NODE(_sysctl, CTL_SYSCTL_NAME, name, CTLFLAG_RD |
CTLFLAG_MPSAFE | CTLFLAG_CAPRD, sysctl_sysctl_name, "");
enum sysctl_iter_action {
ITER_SIBLINGS, /* Not matched, continue iterating siblings */
ITER_CHILDREN, /* Node has children we need to iterate over them */
ITER_FOUND, /* Matching node was found */
};
/*
* Tries to find the next node for @name and @namelen.
*
* Returns next action to take.
*/
static enum sysctl_iter_action
sysctl_sysctl_next_node(struct sysctl_oid *oidp, int *name, unsigned int namelen,
bool honor_skip)
{
if ((oidp->oid_kind & CTLFLAG_DORMANT) != 0)
return (ITER_SIBLINGS);
if (honor_skip && (oidp->oid_kind & CTLFLAG_SKIP) != 0)
return (ITER_SIBLINGS);
if (namelen == 0) {
/*
* We have reached a node with a full name match and are
* looking for the next oid in its children.
*
* For CTL_SYSCTL_NEXTNOSKIP we are done.
*
* For CTL_SYSCTL_NEXT we skip CTLTYPE_NODE (unless it
* has a handler) and move on to the children.
*/
if (!honor_skip)
return (ITER_FOUND);
if ((oidp->oid_kind & CTLTYPE) != CTLTYPE_NODE)
return (ITER_FOUND);
/* If node does not have an iterator, treat it as leaf */
if (oidp->oid_handler)
return (ITER_FOUND);
/* Report oid as a node to iterate */
return (ITER_CHILDREN);
}
/*
* No match yet. Continue seeking the given name.
*
* We are iterating in order by oid_number, so skip oids lower
* than the one we are looking for.
*
* When the current oid_number is higher than the one we seek,
* that means we have reached the next oid in the sequence and
* should return it.
*
* If the oid_number matches the name at this level then we
* have to find a node to continue searching at the next level.
*/
if (oidp->oid_number < *name)
return (ITER_SIBLINGS);
if (oidp->oid_number > *name) {
/*
* We have reached the next oid.
*
* For CTL_SYSCTL_NEXTNOSKIP we are done.
*
* For CTL_SYSCTL_NEXT we skip CTLTYPE_NODE (unless it
* has a handler) and move on to the children.
*/
if (!honor_skip)
return (ITER_FOUND);
if ((oidp->oid_kind & CTLTYPE) != CTLTYPE_NODE)
return (ITER_FOUND);
/* If node does not have an iterator, treat it as leaf */
if (oidp->oid_handler)
return (ITER_FOUND);
return (ITER_CHILDREN);
}
/* match at a current level */
if ((oidp->oid_kind & CTLTYPE) != CTLTYPE_NODE)
return (ITER_SIBLINGS);
if (oidp->oid_handler)
return (ITER_SIBLINGS);
return (ITER_CHILDREN);
}
/*
* Recursively walk the sysctl subtree at lsp until we find the given name.
* Returns true and fills in next oid data in @next and @len if oid is found.
*/
static bool
sysctl_sysctl_next_action(struct sysctl_oid_list *lsp, int *name, u_int namelen,
int *next, int *len, int level, bool honor_skip)
{
- struct sysctl_oid *oidp;
+ struct sysctl_oid_list *next_lsp;
+ struct sysctl_oid *oidp = NULL, key;
bool success = false;
enum sysctl_iter_action action;
SYSCTL_ASSERT_LOCKED();
- SLIST_FOREACH(oidp, lsp, oid_link) {
- action = sysctl_sysctl_next_node(oidp, name, namelen, honor_skip);
+ /*
+ * Start the search at the requested oid. But if not found, then scan
+ * through all children.
+ */
+ if (namelen > 0) {
+ key.oid_number = *name;
+ oidp = RB_FIND(sysctl_oid_list, lsp, &key);
+ }
+ if (!oidp)
+ oidp = RB_MIN(sysctl_oid_list, lsp);
+ for(; oidp != NULL; oidp = RB_NEXT(sysctl_oid_list, lsp, oidp)) {
+ action = sysctl_sysctl_next_node(oidp, name, namelen,
+ honor_skip);
if (action == ITER_SIBLINGS)
continue;
if (action == ITER_FOUND) {
success = true;
break;
}
KASSERT((action== ITER_CHILDREN), ("ret(%d)!=ITER_CHILDREN", action));
- lsp = SYSCTL_CHILDREN(oidp);
+ next_lsp = SYSCTL_CHILDREN(oidp);
if (namelen == 0) {
- success = sysctl_sysctl_next_action(lsp, NULL, 0,
+ success = sysctl_sysctl_next_action(next_lsp, NULL, 0,
next + 1, len, level + 1, honor_skip);
} else {
- success = sysctl_sysctl_next_action(lsp, name + 1, namelen - 1,
- next + 1, len, level + 1, honor_skip);
+ success = sysctl_sysctl_next_action(next_lsp, name + 1,
+ namelen - 1, next + 1, len, level + 1, honor_skip);
if (!success) {
/*
* We maintain the invariant that current node oid
* is >= the oid provided in @name.
* As there are no usable children at this node,
* current node oid is strictly > than the requested
* oid.
* Hence, reduce namelen to 0 to allow for picking first
* nodes/leafs in the next node in list.
*/
namelen = 0;
}
}
if (success)
break;
}
if (success) {
*next = oidp->oid_number;
if (level > *len)
*len = level;
}
return (success);
}
static int
sysctl_sysctl_next(SYSCTL_HANDLER_ARGS)
{
int *name = (int *) arg1;
u_int namelen = arg2;
int len, error;
bool success;
struct sysctl_oid_list *lsp = &sysctl__children;
struct rm_priotracker tracker;
int next[CTL_MAXNAME];
len = 0;
SYSCTL_RLOCK(&tracker);
success = sysctl_sysctl_next_action(lsp, name, namelen, next, &len, 1,
oidp->oid_number == CTL_SYSCTL_NEXT);
SYSCTL_RUNLOCK(&tracker);
if (!success)
return (ENOENT);
error = SYSCTL_OUT(req, next, len * sizeof (int));
return (error);
}
/*
* XXXRW/JA: Shouldn't return next data for nodes that we don't permit in
* capability mode.
*/
static SYSCTL_NODE(_sysctl, CTL_SYSCTL_NEXT, next, CTLFLAG_RD |
CTLFLAG_MPSAFE | CTLFLAG_CAPRD, sysctl_sysctl_next, "");
static SYSCTL_NODE(_sysctl, CTL_SYSCTL_NEXTNOSKIP, nextnoskip, CTLFLAG_RD |
CTLFLAG_MPSAFE | CTLFLAG_CAPRD, sysctl_sysctl_next, "");
static int
name2oid(char *name, int *oid, int *len, struct sysctl_oid **oidpp)
{
struct sysctl_oid *oidp;
struct sysctl_oid_list *lsp = &sysctl__children;
char *p;
SYSCTL_ASSERT_LOCKED();
for (*len = 0; *len < CTL_MAXNAME;) {
p = strsep(&name, ".");
- oidp = SLIST_FIRST(lsp);
- for (;; oidp = SLIST_NEXT(oidp, oid_link)) {
- if (oidp == NULL)
- return (ENOENT);
+ RB_FOREACH(oidp, sysctl_oid_list, lsp) {
if (strcmp(p, oidp->oid_name) == 0)
break;
}
+ if (oidp == NULL)
+ return (ENOENT);
*oid++ = oidp->oid_number;
(*len)++;
if (name == NULL || *name == '\0') {
if (oidpp)
*oidpp = oidp;
return (0);
}
if ((oidp->oid_kind & CTLTYPE) != CTLTYPE_NODE)
break;
if (oidp->oid_handler)
break;
lsp = SYSCTL_CHILDREN(oidp);
}
return (ENOENT);
}
static int
sysctl_sysctl_name2oid(SYSCTL_HANDLER_ARGS)
{
char *p;
int error, oid[CTL_MAXNAME], len = 0;
struct sysctl_oid *op = NULL;
struct rm_priotracker tracker;
char buf[32];
if (!req->newlen)
return (ENOENT);
if (req->newlen >= MAXPATHLEN) /* XXX arbitrary, undocumented */
return (ENAMETOOLONG);
p = buf;
if (req->newlen >= sizeof(buf))
p = malloc(req->newlen+1, M_SYSCTL, M_WAITOK);
error = SYSCTL_IN(req, p, req->newlen);
if (error) {
if (p != buf)
free(p, M_SYSCTL);
return (error);
}
p [req->newlen] = '\0';
SYSCTL_RLOCK(&tracker);
error = name2oid(p, oid, &len, &op);
SYSCTL_RUNLOCK(&tracker);
if (p != buf)
free(p, M_SYSCTL);
if (error)
return (error);
error = SYSCTL_OUT(req, oid, len * sizeof *oid);
return (error);
}
/*
* XXXRW/JA: Shouldn't return name2oid data for nodes that we don't permit in
* capability mode.
*/
SYSCTL_PROC(_sysctl, CTL_SYSCTL_NAME2OID, name2oid, CTLTYPE_INT | CTLFLAG_RW |
CTLFLAG_ANYBODY | CTLFLAG_MPSAFE | CTLFLAG_CAPRW, 0, 0,
sysctl_sysctl_name2oid, "I", "");
static int
sysctl_sysctl_oidfmt(SYSCTL_HANDLER_ARGS)
{
struct sysctl_oid *oid;
struct rm_priotracker tracker;
int error;
error = sysctl_wire_old_buffer(req, 0);
if (error)
return (error);
SYSCTL_RLOCK(&tracker);
error = sysctl_find_oid(arg1, arg2, &oid, NULL, req);
if (error)
goto out;
if (oid->oid_fmt == NULL) {
error = ENOENT;
goto out;
}
error = SYSCTL_OUT(req, &oid->oid_kind, sizeof(oid->oid_kind));
if (error)
goto out;
error = SYSCTL_OUT(req, oid->oid_fmt, strlen(oid->oid_fmt) + 1);
out:
SYSCTL_RUNLOCK(&tracker);
return (error);
}
static SYSCTL_NODE(_sysctl, CTL_SYSCTL_OIDFMT, oidfmt, CTLFLAG_RD |
CTLFLAG_MPSAFE | CTLFLAG_CAPRD, sysctl_sysctl_oidfmt, "");
static int
sysctl_sysctl_oiddescr(SYSCTL_HANDLER_ARGS)
{
struct sysctl_oid *oid;
struct rm_priotracker tracker;
int error;
error = sysctl_wire_old_buffer(req, 0);
if (error)
return (error);
SYSCTL_RLOCK(&tracker);
error = sysctl_find_oid(arg1, arg2, &oid, NULL, req);
if (error)
goto out;
if (oid->oid_descr == NULL) {
error = ENOENT;
goto out;
}
error = SYSCTL_OUT(req, oid->oid_descr, strlen(oid->oid_descr) + 1);
out:
SYSCTL_RUNLOCK(&tracker);
return (error);
}
static SYSCTL_NODE(_sysctl, CTL_SYSCTL_OIDDESCR, oiddescr, CTLFLAG_RD |
CTLFLAG_MPSAFE|CTLFLAG_CAPRD, sysctl_sysctl_oiddescr, "");
static int
sysctl_sysctl_oidlabel(SYSCTL_HANDLER_ARGS)
{
struct sysctl_oid *oid;
struct rm_priotracker tracker;
int error;
error = sysctl_wire_old_buffer(req, 0);
if (error)
return (error);
SYSCTL_RLOCK(&tracker);
error = sysctl_find_oid(arg1, arg2, &oid, NULL, req);
if (error)
goto out;
if (oid->oid_label == NULL) {
error = ENOENT;
goto out;
}
error = SYSCTL_OUT(req, oid->oid_label, strlen(oid->oid_label) + 1);
out:
SYSCTL_RUNLOCK(&tracker);
return (error);
}
static SYSCTL_NODE(_sysctl, CTL_SYSCTL_OIDLABEL, oidlabel, CTLFLAG_RD |
CTLFLAG_MPSAFE | CTLFLAG_CAPRD, sysctl_sysctl_oidlabel, "");
/*
* Default "handler" functions.
*/
/*
* Handle a bool.
* Two cases:
* a variable: point arg1 at it.
* a constant: pass it in arg2.
*/
int
sysctl_handle_bool(SYSCTL_HANDLER_ARGS)
{
uint8_t temp;
int error;
/*
* Attempt to get a coherent snapshot by making a copy of the data.
*/
if (arg1)
temp = *(bool *)arg1 ? 1 : 0;
else
temp = arg2 ? 1 : 0;
error = SYSCTL_OUT(req, &temp, sizeof(temp));
if (error || !req->newptr)
return (error);
if (!arg1)
error = EPERM;
else {
error = SYSCTL_IN(req, &temp, sizeof(temp));
if (!error)
*(bool *)arg1 = temp ? 1 : 0;
}
return (error);
}
/*
* Handle an int8_t, signed or unsigned.
* Two cases:
* a variable: point arg1 at it.
* a constant: pass it in arg2.
*/
int
sysctl_handle_8(SYSCTL_HANDLER_ARGS)
{
int8_t tmpout;
int error = 0;
/*
* Attempt to get a coherent snapshot by making a copy of the data.
*/
if (arg1)
tmpout = *(int8_t *)arg1;
else
tmpout = arg2;
error = SYSCTL_OUT(req, &tmpout, sizeof(tmpout));
if (error || !req->newptr)
return (error);
if (!arg1)
error = EPERM;
else
error = SYSCTL_IN(req, arg1, sizeof(tmpout));
return (error);
}
/*
* Handle an int16_t, signed or unsigned.
* Two cases:
* a variable: point arg1 at it.
* a constant: pass it in arg2.
*/
int
sysctl_handle_16(SYSCTL_HANDLER_ARGS)
{
int16_t tmpout;
int error = 0;
/*
* Attempt to get a coherent snapshot by making a copy of the data.
*/
if (arg1)
tmpout = *(int16_t *)arg1;
else
tmpout = arg2;
error = SYSCTL_OUT(req, &tmpout, sizeof(tmpout));
if (error || !req->newptr)
return (error);
if (!arg1)
error = EPERM;
else
error = SYSCTL_IN(req, arg1, sizeof(tmpout));
return (error);
}
/*
* Handle an int32_t, signed or unsigned.
* Two cases:
* a variable: point arg1 at it.
* a constant: pass it in arg2.
*/
int
sysctl_handle_32(SYSCTL_HANDLER_ARGS)
{
int32_t tmpout;
int error = 0;
/*
* Attempt to get a coherent snapshot by making a copy of the data.
*/
if (arg1)
tmpout = *(int32_t *)arg1;
else
tmpout = arg2;
error = SYSCTL_OUT(req, &tmpout, sizeof(tmpout));
if (error || !req->newptr)
return (error);
if (!arg1)
error = EPERM;
else
error = SYSCTL_IN(req, arg1, sizeof(tmpout));
return (error);
}
/*
* Handle an int, signed or unsigned.
* Two cases:
* a variable: point arg1 at it.
* a constant: pass it in arg2.
*/
int
sysctl_handle_int(SYSCTL_HANDLER_ARGS)
{
int tmpout, error = 0;
/*
* Attempt to get a coherent snapshot by making a copy of the data.
*/
if (arg1)
tmpout = *(int *)arg1;
else
tmpout = arg2;
error = SYSCTL_OUT(req, &tmpout, sizeof(int));
if (error || !req->newptr)
return (error);
if (!arg1)
error = EPERM;
else
error = SYSCTL_IN(req, arg1, sizeof(int));
return (error);
}
/*
* Based on on sysctl_handle_int() convert milliseconds into ticks.
* Note: this is used by TCP.
*/
int
sysctl_msec_to_ticks(SYSCTL_HANDLER_ARGS)
{
int error, s, tt;
tt = *(int *)arg1;
s = (int)((int64_t)tt * 1000 / hz);
error = sysctl_handle_int(oidp, &s, 0, req);
if (error || !req->newptr)
return (error);
tt = (int)((int64_t)s * hz / 1000);
if (tt < 1)
return (EINVAL);
*(int *)arg1 = tt;
return (0);
}
/*
* Handle a long, signed or unsigned.
* Two cases:
* a variable: point arg1 at it.
* a constant: pass it in arg2.
*/
int
sysctl_handle_long(SYSCTL_HANDLER_ARGS)
{
int error = 0;
long tmplong;
#ifdef SCTL_MASK32
int tmpint;
#endif
/*
* Attempt to get a coherent snapshot by making a copy of the data.
*/
if (arg1)
tmplong = *(long *)arg1;
else
tmplong = arg2;
#ifdef SCTL_MASK32
if (req->flags & SCTL_MASK32) {
tmpint = tmplong;
error = SYSCTL_OUT(req, &tmpint, sizeof(int));
} else
#endif
error = SYSCTL_OUT(req, &tmplong, sizeof(long));
if (error || !req->newptr)
return (error);
if (!arg1)
error = EPERM;
#ifdef SCTL_MASK32
else if (req->flags & SCTL_MASK32) {
error = SYSCTL_IN(req, &tmpint, sizeof(int));
*(long *)arg1 = (long)tmpint;
}
#endif
else
error = SYSCTL_IN(req, arg1, sizeof(long));
return (error);
}
/*
* Handle a 64 bit int, signed or unsigned.
* Two cases:
* a variable: point arg1 at it.
* a constant: pass it in arg2.
*/
int
sysctl_handle_64(SYSCTL_HANDLER_ARGS)
{
int error = 0;
uint64_t tmpout;
/*
* Attempt to get a coherent snapshot by making a copy of the data.
*/
if (arg1)
tmpout = *(uint64_t *)arg1;
else
tmpout = arg2;
error = SYSCTL_OUT(req, &tmpout, sizeof(uint64_t));
if (error || !req->newptr)
return (error);
if (!arg1)
error = EPERM;
else
error = SYSCTL_IN(req, arg1, sizeof(uint64_t));
return (error);
}
/*
* Handle our generic '\0' terminated 'C' string.
* Two cases:
* a variable string: point arg1 at it, arg2 is max length.
* a constant string: point arg1 at it, arg2 is zero.
*/
int
sysctl_handle_string(SYSCTL_HANDLER_ARGS)
{
char *tmparg;
size_t outlen;
int error = 0, ro_string = 0;
/*
* If the sysctl isn't writable and isn't a preallocated tunable that
* can be modified by kenv(2), microoptimise and treat it as a
* read-only string.
* A zero-length buffer indicates a fixed size read-only
* string. In ddb, don't worry about trying to make a malloced
* snapshot.
*/
if ((oidp->oid_kind & (CTLFLAG_WR | CTLFLAG_TUN)) == 0 ||
arg2 == 0 || kdb_active) {
arg2 = strlen((char *)arg1) + 1;
ro_string = 1;
}
if (req->oldptr != NULL) {
if (ro_string) {
tmparg = arg1;
outlen = strlen(tmparg) + 1;
} else {
tmparg = malloc(arg2, M_SYSCTLTMP, M_WAITOK);
sx_slock(&sysctlstringlock);
memcpy(tmparg, arg1, arg2);
sx_sunlock(&sysctlstringlock);
outlen = strlen(tmparg) + 1;
}
error = SYSCTL_OUT(req, tmparg, outlen);
if (!ro_string)
free(tmparg, M_SYSCTLTMP);
} else {
if (!ro_string)
sx_slock(&sysctlstringlock);
outlen = strlen((char *)arg1) + 1;
if (!ro_string)
sx_sunlock(&sysctlstringlock);
error = SYSCTL_OUT(req, NULL, outlen);
}
if (error || !req->newptr)
return (error);
if (req->newlen - req->newidx >= arg2 ||
req->newlen - req->newidx < 0) {
error = EINVAL;
} else if (req->newlen - req->newidx == 0) {
sx_xlock(&sysctlstringlock);
((char *)arg1)[0] = '\0';
sx_xunlock(&sysctlstringlock);
} else if (req->newfunc == sysctl_new_kernel) {
arg2 = req->newlen - req->newidx;
sx_xlock(&sysctlstringlock);
error = SYSCTL_IN(req, arg1, arg2);
if (error == 0) {
((char *)arg1)[arg2] = '\0';
req->newidx += arg2;
}
sx_xunlock(&sysctlstringlock);
} else {
arg2 = req->newlen - req->newidx;
tmparg = malloc(arg2, M_SYSCTLTMP, M_WAITOK);
error = SYSCTL_IN(req, tmparg, arg2);
if (error) {
free(tmparg, M_SYSCTLTMP);
return (error);
}
sx_xlock(&sysctlstringlock);
memcpy(arg1, tmparg, arg2);
((char *)arg1)[arg2] = '\0';
sx_xunlock(&sysctlstringlock);
free(tmparg, M_SYSCTLTMP);
req->newidx += arg2;
}
return (error);
}
/*
* Handle any kind of opaque data.
* arg1 points to it, arg2 is the size.
*/
int
sysctl_handle_opaque(SYSCTL_HANDLER_ARGS)
{
int error, tries;
u_int generation;
struct sysctl_req req2;
/*
* Attempt to get a coherent snapshot, by using the thread
* pre-emption counter updated from within mi_switch() to
* determine if we were pre-empted during a bcopy() or
* copyout(). Make 3 attempts at doing this before giving up.
* If we encounter an error, stop immediately.
*/
tries = 0;
req2 = *req;
retry:
generation = curthread->td_generation;
error = SYSCTL_OUT(req, arg1, arg2);
if (error)
return (error);
tries++;
if (generation != curthread->td_generation && tries < 3) {
*req = req2;
goto retry;
}
error = SYSCTL_IN(req, arg1, arg2);
return (error);
}
/*
* Based on on sysctl_handle_int() convert microseconds to a sbintime.
*/
int
sysctl_usec_to_sbintime(SYSCTL_HANDLER_ARGS)
{
int error;
int64_t tt;
sbintime_t sb;
tt = *(int64_t *)arg1;
sb = sbttous(tt);
error = sysctl_handle_64(oidp, &sb, 0, req);
if (error || !req->newptr)
return (error);
tt = ustosbt(sb);
*(int64_t *)arg1 = tt;
return (0);
}
/*
* Based on on sysctl_handle_int() convert milliseconds to a sbintime.
*/
int
sysctl_msec_to_sbintime(SYSCTL_HANDLER_ARGS)
{
int error;
int64_t tt;
sbintime_t sb;
tt = *(int64_t *)arg1;
sb = sbttoms(tt);
error = sysctl_handle_64(oidp, &sb, 0, req);
if (error || !req->newptr)
return (error);
tt = mstosbt(sb);
*(int64_t *)arg1 = tt;
return (0);
}
/*
* Convert seconds to a struct timeval. Intended for use with
* intervals and thus does not permit negative seconds.
*/
int
sysctl_sec_to_timeval(SYSCTL_HANDLER_ARGS)
{
struct timeval *tv;
int error, secs;
tv = arg1;
secs = tv->tv_sec;
error = sysctl_handle_int(oidp, &secs, 0, req);
if (error || req->newptr == NULL)
return (error);
if (secs < 0)
return (EINVAL);
tv->tv_sec = secs;
return (0);
}
/*
* Transfer functions to/from kernel space.
* XXX: rather untested at this point
*/
static int
sysctl_old_kernel(struct sysctl_req *req, const void *p, size_t l)
{
size_t i = 0;
if (req->oldptr) {
i = l;
if (req->oldlen <= req->oldidx)
i = 0;
else
if (i > req->oldlen - req->oldidx)
i = req->oldlen - req->oldidx;
if (i > 0)
bcopy(p, (char *)req->oldptr + req->oldidx, i);
}
req->oldidx += l;
if (req->oldptr && i != l)
return (ENOMEM);
return (0);
}
static int
sysctl_new_kernel(struct sysctl_req *req, void *p, size_t l)
{
if (!req->newptr)
return (0);
if (req->newlen - req->newidx < l)
return (EINVAL);
bcopy((const char *)req->newptr + req->newidx, p, l);
req->newidx += l;
return (0);
}
int
kernel_sysctl(struct thread *td, int *name, u_int namelen, void *old,
size_t *oldlenp, void *new, size_t newlen, size_t *retval, int flags)
{
int error = 0;
struct sysctl_req req;
bzero(&req, sizeof req);
req.td = td;
req.flags = flags;
if (oldlenp) {
req.oldlen = *oldlenp;
}
req.validlen = req.oldlen;
if (old) {
req.oldptr= old;
}
if (new != NULL) {
req.newlen = newlen;
req.newptr = new;
}
req.oldfunc = sysctl_old_kernel;
req.newfunc = sysctl_new_kernel;
req.lock = REQ_UNWIRED;
error = sysctl_root(0, name, namelen, &req);
if (req.lock == REQ_WIRED && req.validlen > 0)
vsunlock(req.oldptr, req.validlen);
if (error && error != ENOMEM)
return (error);
if (retval) {
if (req.oldptr && req.oldidx > req.validlen)
*retval = req.validlen;
else
*retval = req.oldidx;
}
return (error);
}
int
kernel_sysctlbyname(struct thread *td, char *name, void *old, size_t *oldlenp,
void *new, size_t newlen, size_t *retval, int flags)
{
int oid[CTL_MAXNAME];
size_t oidlen, plen;
int error;
oid[0] = CTL_SYSCTL;
oid[1] = CTL_SYSCTL_NAME2OID;
oidlen = sizeof(oid);
error = kernel_sysctl(td, oid, 2, oid, &oidlen,
(void *)name, strlen(name), &plen, flags);
if (error)
return (error);
error = kernel_sysctl(td, oid, plen / sizeof(int), old, oldlenp,
new, newlen, retval, flags);
return (error);
}
/*
* Transfer function to/from user space.
*/
static int
sysctl_old_user(struct sysctl_req *req, const void *p, size_t l)
{
size_t i, len, origidx;
int error;
origidx = req->oldidx;
req->oldidx += l;
if (req->oldptr == NULL)
return (0);
/*
* If we have not wired the user supplied buffer and we are currently
* holding locks, drop a witness warning, as it's possible that
* write operations to the user page can sleep.
*/
if (req->lock != REQ_WIRED)
WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
"sysctl_old_user()");
i = l;
len = req->validlen;
if (len <= origidx)
i = 0;
else {
if (i > len - origidx)
i = len - origidx;
if (req->lock == REQ_WIRED) {
error = copyout_nofault(p, (char *)req->oldptr +
origidx, i);
} else
error = copyout(p, (char *)req->oldptr + origidx, i);
if (error != 0)
return (error);
}
if (i < l)
return (ENOMEM);
return (0);
}
static int
sysctl_new_user(struct sysctl_req *req, void *p, size_t l)
{
int error;
if (!req->newptr)
return (0);
if (req->newlen - req->newidx < l)
return (EINVAL);
WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
"sysctl_new_user()");
error = copyin((const char *)req->newptr + req->newidx, p, l);
req->newidx += l;
return (error);
}
/*
* Wire the user space destination buffer. If set to a value greater than
* zero, the len parameter limits the maximum amount of wired memory.
*/
int
sysctl_wire_old_buffer(struct sysctl_req *req, size_t len)
{
int ret;
size_t wiredlen;
wiredlen = (len > 0 && len < req->oldlen) ? len : req->oldlen;
ret = 0;
if (req->lock != REQ_WIRED && req->oldptr &&
req->oldfunc == sysctl_old_user) {
if (wiredlen != 0) {
ret = vslock(req->oldptr, wiredlen);
if (ret != 0) {
if (ret != ENOMEM)
return (ret);
wiredlen = 0;
}
}
req->lock = REQ_WIRED;
req->validlen = wiredlen;
}
return (0);
}
int
sysctl_find_oid(int *name, u_int namelen, struct sysctl_oid **noid,
int *nindx, struct sysctl_req *req)
{
struct sysctl_oid_list *lsp;
struct sysctl_oid *oid;
+ struct sysctl_oid key;
int indx;
SYSCTL_ASSERT_LOCKED();
lsp = &sysctl__children;
indx = 0;
while (indx < CTL_MAXNAME) {
- SLIST_FOREACH(oid, lsp, oid_link) {
- if (oid->oid_number == name[indx])
- break;
- }
+ key.oid_number = name[indx];
+ oid = RB_FIND(sysctl_oid_list, lsp, &key);
if (oid == NULL)
return (ENOENT);
indx++;
if ((oid->oid_kind & CTLTYPE) == CTLTYPE_NODE) {
if (oid->oid_handler != NULL || indx == namelen) {
*noid = oid;
if (nindx != NULL)
*nindx = indx;
KASSERT((oid->oid_kind & CTLFLAG_DYING) == 0,
("%s found DYING node %p", __func__, oid));
return (0);
}
lsp = SYSCTL_CHILDREN(oid);
} else if (indx == namelen) {
if ((oid->oid_kind & CTLFLAG_DORMANT) != 0)
return (ENOENT);
*noid = oid;
if (nindx != NULL)
*nindx = indx;
KASSERT((oid->oid_kind & CTLFLAG_DYING) == 0,
("%s found DYING node %p", __func__, oid));
return (0);
} else {
return (ENOTDIR);
}
}
return (ENOENT);
}
/*
* Traverse our tree, and find the right node, execute whatever it points
* to, and return the resulting error code.
*/
static int
sysctl_root(SYSCTL_HANDLER_ARGS)
{
struct sysctl_oid *oid;
struct rm_priotracker tracker;
int error, indx, lvl;
SYSCTL_RLOCK(&tracker);
error = sysctl_find_oid(arg1, arg2, &oid, &indx, req);
if (error)
goto out;
if ((oid->oid_kind & CTLTYPE) == CTLTYPE_NODE) {
/*
* You can't call a sysctl when it's a node, but has
* no handler. Inform the user that it's a node.
* The indx may or may not be the same as namelen.
*/
if (oid->oid_handler == NULL) {
error = EISDIR;
goto out;
}
}
/* Is this sysctl writable? */
if (req->newptr && !(oid->oid_kind & CTLFLAG_WR)) {
error = EPERM;
goto out;
}
KASSERT(req->td != NULL, ("sysctl_root(): req->td == NULL"));
#ifdef CAPABILITY_MODE
/*
* If the process is in capability mode, then don't permit reading or
* writing unless specifically granted for the node.
*/
if (IN_CAPABILITY_MODE(req->td)) {
if ((req->oldptr && !(oid->oid_kind & CTLFLAG_CAPRD)) ||
(req->newptr && !(oid->oid_kind & CTLFLAG_CAPWR))) {
error = EPERM;
goto out;
}
}
#endif
/* Is this sysctl sensitive to securelevels? */
if (req->newptr && (oid->oid_kind & CTLFLAG_SECURE)) {
lvl = (oid->oid_kind & CTLMASK_SECURE) >> CTLSHIFT_SECURE;
error = securelevel_gt(req->td->td_ucred, lvl);
if (error)
goto out;
}
/* Is this sysctl writable by only privileged users? */
if (req->newptr && !(oid->oid_kind & CTLFLAG_ANYBODY)) {
int priv;
if (oid->oid_kind & CTLFLAG_PRISON)
priv = PRIV_SYSCTL_WRITEJAIL;
#ifdef VIMAGE
else if ((oid->oid_kind & CTLFLAG_VNET) &&
prison_owns_vnet(req->td->td_ucred))
priv = PRIV_SYSCTL_WRITEJAIL;
#endif
else
priv = PRIV_SYSCTL_WRITE;
error = priv_check(req->td, priv);
if (error)
goto out;
}
if (!oid->oid_handler) {
error = EINVAL;
goto out;
}
if ((oid->oid_kind & CTLTYPE) == CTLTYPE_NODE) {
arg1 = (int *)arg1 + indx;
arg2 -= indx;
} else {
arg1 = oid->oid_arg1;
arg2 = oid->oid_arg2;
}
#ifdef MAC
error = mac_system_check_sysctl(req->td->td_ucred, oid, arg1, arg2,
req);
if (error != 0)
goto out;
#endif
#ifdef VIMAGE
if ((oid->oid_kind & CTLFLAG_VNET) && arg1 != NULL)
arg1 = (void *)(curvnet->vnet_data_base + (uintptr_t)arg1);
#endif
error = sysctl_root_handler_locked(oid, arg1, arg2, req, &tracker);
out:
SYSCTL_RUNLOCK(&tracker);
return (error);
}
#ifndef _SYS_SYSPROTO_H_
struct __sysctl_args {
int *name;
u_int namelen;
void *old;
size_t *oldlenp;
void *new;
size_t newlen;
};
#endif
int
sys___sysctl(struct thread *td, struct __sysctl_args *uap)
{
int error, i, name[CTL_MAXNAME];
size_t j;
if (uap->namelen > CTL_MAXNAME || uap->namelen < 2)
return (EINVAL);
error = copyin(uap->name, &name, uap->namelen * sizeof(int));
if (error)
return (error);
error = userland_sysctl(td, name, uap->namelen,
uap->old, uap->oldlenp, 0,
uap->new, uap->newlen, &j, 0);
if (error && error != ENOMEM)
return (error);
if (uap->oldlenp) {
i = copyout(&j, uap->oldlenp, sizeof(j));
if (i)
return (i);
}
return (error);
}
int
kern___sysctlbyname(struct thread *td, const char *oname, size_t namelen,
void *old, size_t *oldlenp, void *new, size_t newlen, size_t *retval,
int flags, bool inkernel)
{
int oid[CTL_MAXNAME];
char namebuf[16];
char *name;
size_t oidlen;
int error;
if (namelen > MAXPATHLEN || namelen == 0)
return (EINVAL);
name = namebuf;
if (namelen > sizeof(namebuf))
name = malloc(namelen, M_SYSCTL, M_WAITOK);
error = copyin(oname, name, namelen);
if (error != 0)
goto out;
oid[0] = CTL_SYSCTL;
oid[1] = CTL_SYSCTL_NAME2OID;
oidlen = sizeof(oid);
error = kernel_sysctl(td, oid, 2, oid, &oidlen, (void *)name, namelen,
retval, flags);
if (error != 0)
goto out;
error = userland_sysctl(td, oid, *retval / sizeof(int), old, oldlenp,
inkernel, new, newlen, retval, flags);
out:
if (namelen > sizeof(namebuf))
free(name, M_SYSCTL);
return (error);
}
#ifndef _SYS_SYSPROTO_H_
struct __sysctlbyname_args {
const char *name;
size_t namelen;
void *old;
size_t *oldlenp;
void *new;
size_t newlen;
};
#endif
int
sys___sysctlbyname(struct thread *td, struct __sysctlbyname_args *uap)
{
size_t rv;
int error;
error = kern___sysctlbyname(td, uap->name, uap->namelen, uap->old,
uap->oldlenp, uap->new, uap->newlen, &rv, 0, 0);
if (error != 0)
return (error);
if (uap->oldlenp != NULL)
error = copyout(&rv, uap->oldlenp, sizeof(rv));
return (error);
}
/*
* This is used from various compatibility syscalls too. That's why name
* must be in kernel space.
*/
int
userland_sysctl(struct thread *td, int *name, u_int namelen, void *old,
size_t *oldlenp, int inkernel, const void *new, size_t newlen,
size_t *retval, int flags)
{
int error = 0, memlocked;
struct sysctl_req req;
bzero(&req, sizeof req);
req.td = td;
req.flags = flags;
if (oldlenp) {
if (inkernel) {
req.oldlen = *oldlenp;
} else {
error = copyin(oldlenp, &req.oldlen, sizeof(*oldlenp));
if (error)
return (error);
}
}
req.validlen = req.oldlen;
req.oldptr = old;
if (new != NULL) {
req.newlen = newlen;
req.newptr = new;
}
req.oldfunc = sysctl_old_user;
req.newfunc = sysctl_new_user;
req.lock = REQ_UNWIRED;
#ifdef KTRACE
if (KTRPOINT(curthread, KTR_SYSCTL))
ktrsysctl(name, namelen);
#endif
memlocked = 0;
if (req.oldptr && req.oldlen > 4 * PAGE_SIZE) {
memlocked = 1;
sx_xlock(&sysctlmemlock);
}
CURVNET_SET(TD_TO_VNET(td));
for (;;) {
req.oldidx = 0;
req.newidx = 0;
error = sysctl_root(0, name, namelen, &req);
if (error != EAGAIN)
break;
kern_yield(PRI_USER);
}
CURVNET_RESTORE();
if (req.lock == REQ_WIRED && req.validlen > 0)
vsunlock(req.oldptr, req.validlen);
if (memlocked)
sx_xunlock(&sysctlmemlock);
if (error && error != ENOMEM)
return (error);
if (retval) {
if (req.oldptr && req.oldidx > req.validlen)
*retval = req.validlen;
else
*retval = req.oldidx;
}
return (error);
}
/*
* Drain into a sysctl struct. The user buffer should be wired if a page
* fault would cause issue.
*/
static int
sbuf_sysctl_drain(void *arg, const char *data, int len)
{
struct sysctl_req *req = arg;
int error;
error = SYSCTL_OUT(req, data, len);
KASSERT(error >= 0, ("Got unexpected negative value %d", error));
return (error == 0 ? len : -error);
}
struct sbuf *
sbuf_new_for_sysctl(struct sbuf *s, char *buf, int length,
struct sysctl_req *req)
{
/* Supply a default buffer size if none given. */
if (buf == NULL && length == 0)
length = 64;
s = sbuf_new(s, buf, length, SBUF_FIXEDLEN | SBUF_INCLUDENUL);
sbuf_set_drain(s, sbuf_sysctl_drain, req);
return (s);
}
#ifdef DDB
/* The current OID the debugger is working with */
static struct sysctl_oid *g_ddb_oid;
/* The current flags specified by the user */
static int g_ddb_sysctl_flags;
/* Check to see if the last sysctl printed */
static int g_ddb_sysctl_printed;
static const int ctl_sign[CTLTYPE+1] = {
[CTLTYPE_INT] = 1,
[CTLTYPE_LONG] = 1,
[CTLTYPE_S8] = 1,
[CTLTYPE_S16] = 1,
[CTLTYPE_S32] = 1,
[CTLTYPE_S64] = 1,
};
static const int ctl_size[CTLTYPE+1] = {
[CTLTYPE_INT] = sizeof(int),
[CTLTYPE_UINT] = sizeof(u_int),
[CTLTYPE_LONG] = sizeof(long),
[CTLTYPE_ULONG] = sizeof(u_long),
[CTLTYPE_S8] = sizeof(int8_t),
[CTLTYPE_S16] = sizeof(int16_t),
[CTLTYPE_S32] = sizeof(int32_t),
[CTLTYPE_S64] = sizeof(int64_t),
[CTLTYPE_U8] = sizeof(uint8_t),
[CTLTYPE_U16] = sizeof(uint16_t),
[CTLTYPE_U32] = sizeof(uint32_t),
[CTLTYPE_U64] = sizeof(uint64_t),
};
#define DB_SYSCTL_NAME_ONLY 0x001 /* Compare with -N */
#define DB_SYSCTL_VALUE_ONLY 0x002 /* Compare with -n */
#define DB_SYSCTL_OPAQUE 0x004 /* Compare with -o */
#define DB_SYSCTL_HEX 0x008 /* Compare with -x */
#define DB_SYSCTL_SAFE_ONLY 0x100 /* Only simple types */
static const char db_sysctl_modifs[] = {
'N', 'n', 'o', 'x',
};
static const int db_sysctl_modif_values[] = {
DB_SYSCTL_NAME_ONLY, DB_SYSCTL_VALUE_ONLY,
DB_SYSCTL_OPAQUE, DB_SYSCTL_HEX,
};
/* Handlers considered safe to print while recursing */
static int (* const db_safe_handlers[])(SYSCTL_HANDLER_ARGS) = {
sysctl_handle_bool,
sysctl_handle_8,
sysctl_handle_16,
sysctl_handle_32,
sysctl_handle_64,
sysctl_handle_int,
sysctl_handle_long,
sysctl_handle_string,
sysctl_handle_opaque,
};
/*
* Use in place of sysctl_old_kernel to print sysctl values.
*
* Compare to the output handling in show_var from sbin/sysctl/sysctl.c
*/
static int
sysctl_old_ddb(struct sysctl_req *req, const void *ptr, size_t len)
{
const u_char *val, *p;
const char *sep1;
size_t intlen, slen;
uintmax_t umv;
intmax_t mv;
int sign, ctltype, hexlen, xflag, error;
/* Suppress false-positive GCC uninitialized variable warnings */
mv = 0;
umv = 0;
slen = len;
val = p = ptr;
if (ptr == NULL) {
error = 0;
goto out;
}
/* We are going to print */
g_ddb_sysctl_printed = 1;
xflag = g_ddb_sysctl_flags & DB_SYSCTL_HEX;
ctltype = (g_ddb_oid->oid_kind & CTLTYPE);
sign = ctl_sign[ctltype];
intlen = ctl_size[ctltype];
switch (ctltype) {
case CTLTYPE_NODE:
case CTLTYPE_STRING:
db_printf("%.*s", (int) len, (const char *) p);
error = 0;
goto out;
case CTLTYPE_INT:
case CTLTYPE_UINT:
case CTLTYPE_LONG:
case CTLTYPE_ULONG:
case CTLTYPE_S8:
case CTLTYPE_S16:
case CTLTYPE_S32:
case CTLTYPE_S64:
case CTLTYPE_U8:
case CTLTYPE_U16:
case CTLTYPE_U32:
case CTLTYPE_U64:
hexlen = 2 + (intlen * CHAR_BIT + 3) / 4;
sep1 = "";
while (len >= intlen) {
switch (ctltype) {
case CTLTYPE_INT:
case CTLTYPE_UINT:
umv = *(const u_int *)p;
mv = *(const int *)p;
break;
case CTLTYPE_LONG:
case CTLTYPE_ULONG:
umv = *(const u_long *)p;
mv = *(const long *)p;
break;
case CTLTYPE_S8:
case CTLTYPE_U8:
umv = *(const uint8_t *)p;
mv = *(const int8_t *)p;
break;
case CTLTYPE_S16:
case CTLTYPE_U16:
umv = *(const uint16_t *)p;
mv = *(const int16_t *)p;
break;
case CTLTYPE_S32:
case CTLTYPE_U32:
umv = *(const uint32_t *)p;
mv = *(const int32_t *)p;
break;
case CTLTYPE_S64:
case CTLTYPE_U64:
umv = *(const uint64_t *)p;
mv = *(const int64_t *)p;
break;
}
db_printf("%s", sep1);
if (xflag)
db_printf("%#0*jx", hexlen, umv);
else if (!sign)
db_printf("%ju", umv);
else if (g_ddb_oid->oid_fmt[1] == 'K') {
/* Kelvins are currently unsupported. */
error = EOPNOTSUPP;
goto out;
} else
db_printf("%jd", mv);
sep1 = " ";
len -= intlen;
p += intlen;
}
error = 0;
goto out;
case CTLTYPE_OPAQUE:
/* TODO: Support struct functions. */
/* FALLTHROUGH */
default:
db_printf("Format:%s Length:%zu Dump:0x",
g_ddb_oid->oid_fmt, len);
while (len-- && (xflag || p < val + 16))
db_printf("%02x", *p++);
if (!xflag && len > 16)
db_printf("...");
error = 0;
goto out;
}
out:
req->oldidx += slen;
return (error);
}
/*
* Avoid setting new sysctl values from the debugger
*/
static int
sysctl_new_ddb(struct sysctl_req *req, void *p, size_t l)
{
if (!req->newptr)
return (0);
/* Changing sysctls from the debugger is currently unsupported */
return (EPERM);
}
/*
* Run a sysctl handler with the DDB oldfunc and newfunc attached.
* Instead of copying any output to a buffer we'll dump it right to
* the console.
*/
static int
db_sysctl(struct sysctl_oid *oidp, int *name, u_int namelen,
void *old, size_t *oldlenp, size_t *retval, int flags)
{
struct sysctl_req req;
int error;
/* Setup the request */
bzero(&req, sizeof req);
req.td = kdb_thread;
req.oldfunc = sysctl_old_ddb;
req.newfunc = sysctl_new_ddb;
req.lock = REQ_UNWIRED;
if (oldlenp) {
req.oldlen = *oldlenp;
}
req.validlen = req.oldlen;
if (old) {
req.oldptr = old;
}
/* Setup our globals for sysctl_old_ddb */
g_ddb_oid = oidp;
g_ddb_sysctl_flags = flags;
g_ddb_sysctl_printed = 0;
error = sysctl_root(0, name, namelen, &req);
/* Reset globals */
g_ddb_oid = NULL;
g_ddb_sysctl_flags = 0;
if (retval) {
if (req.oldptr && req.oldidx > req.validlen)
*retval = req.validlen;
else
*retval = req.oldidx;
}
return (error);
}
/*
* Show a sysctl's name
*/
static void
db_show_oid_name(int *oid, size_t nlen)
{
struct sysctl_oid *oidp;
int qoid[CTL_MAXNAME+2];
int error;
qoid[0] = 0;
memcpy(qoid + 2, oid, nlen * sizeof(int));
qoid[1] = 1;
error = sysctl_find_oid(qoid, nlen + 2, &oidp, NULL, NULL);
if (error)
db_error("sysctl name oid");
error = db_sysctl(oidp, qoid, nlen + 2, NULL, NULL, NULL, 0);
if (error)
db_error("sysctl name");
}
/*
* Check to see if an OID is safe to print from ddb.
*/
static bool
db_oid_safe(const struct sysctl_oid *oidp)
{
for (unsigned int i = 0; i < nitems(db_safe_handlers); ++i) {
if (oidp->oid_handler == db_safe_handlers[i])
return (true);
}
return (false);
}
/*
* Show a sysctl at a specific OID
* Compare to the input handling in show_var from sbin/sysctl/sysctl.c
*/
static int
db_show_oid(struct sysctl_oid *oidp, int *oid, size_t nlen, int flags)
{
int error, xflag, oflag, Nflag, nflag;
size_t len;
xflag = flags & DB_SYSCTL_HEX;
oflag = flags & DB_SYSCTL_OPAQUE;
nflag = flags & DB_SYSCTL_VALUE_ONLY;
Nflag = flags & DB_SYSCTL_NAME_ONLY;
if ((oidp->oid_kind & CTLTYPE) == CTLTYPE_OPAQUE &&
(!xflag && !oflag))
return (0);
if (Nflag) {
db_show_oid_name(oid, nlen);
error = 0;
goto out;
}
if (!nflag) {
db_show_oid_name(oid, nlen);
db_printf(": ");
}
if ((flags & DB_SYSCTL_SAFE_ONLY) && !db_oid_safe(oidp)) {
db_printf("Skipping, unsafe to print while recursing.");
error = 0;
goto out;
}
/* Try once, and ask about the size */
len = 0;
error = db_sysctl(oidp, oid, nlen,
NULL, NULL, &len, flags);
if (error)
goto out;
if (!g_ddb_sysctl_printed)
/* Lie about the size */
error = db_sysctl(oidp, oid, nlen,
(void *) 1, &len, NULL, flags);
out:
db_printf("\n");
return (error);
}
/*
* Show all sysctls under a specific OID
* Compare to sysctl_all from sbin/sysctl/sysctl.c
*/
static int
db_show_sysctl_all(int *oid, size_t len, int flags)
{
struct sysctl_oid *oidp;
int name1[CTL_MAXNAME + 2], name2[CTL_MAXNAME + 2];
size_t l1, l2;
name1[0] = CTL_SYSCTL;
name1[1] = CTL_SYSCTL_NEXT;
l1 = 2;
if (len) {
memcpy(name1 + 2, oid, len * sizeof(int));
l1 += len;
} else {
name1[2] = CTL_KERN;
l1++;
}
for (;;) {
int i, error;
l2 = sizeof(name2);
error = kernel_sysctl(kdb_thread, name1, l1,
name2, &l2, NULL, 0, &l2, 0);
if (error != 0) {
if (error == ENOENT)
return (0);
else
db_error("sysctl(next)");
}
l2 /= sizeof(int);
if (l2 < (unsigned int)len)
return (0);
for (i = 0; i < len; i++)
if (name2[i] != oid[i])
return (0);
/* Find the OID in question */
error = sysctl_find_oid(name2, l2, &oidp, NULL, NULL);
if (error)
return (error);
i = db_show_oid(oidp, name2, l2, flags | DB_SYSCTL_SAFE_ONLY);
if (db_pager_quit)
return (0);
memcpy(name1+2, name2, l2 * sizeof(int));
l1 = 2 + l2;
}
}
/*
* Show a sysctl by its user facing string
*/
static int
db_sysctlbyname(char *name, int flags)
{
struct sysctl_oid *oidp;
int oid[CTL_MAXNAME];
int error, nlen;
error = name2oid(name, oid, &nlen, &oidp);
if (error) {
return (error);
}
if ((oidp->oid_kind & CTLTYPE) == CTLTYPE_NODE) {
db_show_sysctl_all(oid, nlen, flags);
} else {
error = db_show_oid(oidp, oid, nlen, flags);
}
return (error);
}
static void
db_sysctl_cmd_usage(void)
{
db_printf(
" sysctl [/Nnox] <sysctl> \n"
" \n"
" <sysctl> The name of the sysctl to show. \n"
" \n"
" Show a sysctl by hooking into SYSCTL_IN and SYSCTL_OUT. \n"
" This will work for most sysctls, but should not be used \n"
" with sysctls that are known to malloc. \n"
" \n"
" While recursing any \"unsafe\" sysctls will be skipped. \n"
" Call sysctl directly on the sysctl to try printing the \n"
" skipped sysctl. This is unsafe and may make the ddb \n"
" session unusable. \n"
" \n"
" Arguments: \n"
" /N Display only the name of the sysctl. \n"
" /n Display only the value of the sysctl. \n"
" /o Display opaque values. \n"
" /x Display the sysctl in hex. \n"
" \n"
"For example: \n"
"sysctl vm.v_free_min \n"
"vn.v_free_min: 12669 \n"
);
}
/*
* Show a specific sysctl similar to sysctl (8).
*/
DB_COMMAND_FLAGS(sysctl, db_sysctl_cmd, CS_OWN)
{
char name[TOK_STRING_SIZE];
int error, i, t, flags;
/* Parse the modifiers */
t = db_read_token();
if (t == tSLASH || t == tMINUS) {
t = db_read_token();
if (t != tIDENT) {
db_printf("Bad modifier\n");
error = EINVAL;
goto out;
}
db_strcpy(modif, db_tok_string);
}
else {
db_unread_token(t);
modif[0] = '\0';
}
flags = 0;
for (i = 0; i < nitems(db_sysctl_modifs); i++) {
if (strchr(modif, db_sysctl_modifs[i])) {
flags |= db_sysctl_modif_values[i];
}
}
/* Parse the sysctl names */
t = db_read_token();
if (t != tIDENT) {
db_printf("Need sysctl name\n");
error = EINVAL;
goto out;
}
/* Copy the name into a temporary buffer */
db_strcpy(name, db_tok_string);
/* Ensure there is no trailing cruft */
t = db_read_token();
if (t != tEOL) {
db_printf("Unexpected sysctl argument\n");
error = EINVAL;
goto out;
}
error = db_sysctlbyname(name, flags);
if (error == ENOENT) {
db_printf("unknown oid: '%s'\n", db_tok_string);
goto out;
} else if (error) {
db_printf("%s: error: %d\n", db_tok_string, error);
goto out;
}
out:
/* Ensure we eat all of our text */
db_flush_lex();
if (error == EINVAL) {
db_sysctl_cmd_usage();
}
}
#endif /* DDB */
diff --git a/sys/kern/vfs_init.c b/sys/kern/vfs_init.c
index 6572a8e362c2..6e2e78aaf597 100644
--- a/sys/kern/vfs_init.c
+++ b/sys/kern/vfs_init.c
@@ -1,607 +1,607 @@
/*-
* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed
* to Berkeley by John Heidemann of the UCLA Ficus project.
*
* Source: * @(#)i405_init.c 2.10 92/04/27 UCLA Ficus project
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)vfs_init.c 8.3 (Berkeley) 1/4/94
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/fnv_hash.h>
#include <sys/jail.h>
#include <sys/kernel.h>
#include <sys/linker.h>
#include <sys/mount.h>
#include <sys/proc.h>
#include <sys/sx.h>
#include <sys/syscallsubr.h>
#include <sys/sysctl.h>
#include <sys/vnode.h>
#include <sys/malloc.h>
static int vfs_register(struct vfsconf *);
static int vfs_unregister(struct vfsconf *);
MALLOC_DEFINE(M_VNODE, "vnodes", "Dynamically allocated vnodes");
/*
* The highest defined VFS number.
*/
int maxvfsconf = VFS_GENERIC + 1;
/*
* Single-linked list of configured VFSes.
* New entries are added/deleted by vfs_register()/vfs_unregister()
*/
struct vfsconfhead vfsconf = TAILQ_HEAD_INITIALIZER(vfsconf);
struct sx vfsconf_sx;
SX_SYSINIT(vfsconf, &vfsconf_sx, "vfsconf");
/*
* Loader.conf variable vfs.typenumhash enables setting vfc_typenum using a hash
* calculation on vfc_name, so that it doesn't change when file systems are
* loaded in a different order. This will avoid the NFS server file handles from
* changing for file systems that use vfc_typenum in their fsid.
*/
static int vfs_typenumhash = 1;
SYSCTL_INT(_vfs, OID_AUTO, typenumhash, CTLFLAG_RDTUN, &vfs_typenumhash, 0,
"Set vfc_typenum using a hash calculation on vfc_name, so that it does not"
" change when file systems are loaded in a different order.");
/*
* A Zen vnode attribute structure.
*
* Initialized when the first filesystem registers by vfs_register().
*/
struct vattr va_null;
/*
* vfs_init.c
*
* Allocate and fill in operations vectors.
*
* An undocumented feature of this approach to defining operations is that
* there can be multiple entries in vfs_opv_descs for the same operations
* vector. This allows third parties to extend the set of operations
* supported by another layer in a binary compatibile way. For example,
* assume that NFS needed to be modified to support Ficus. NFS has an entry
* (probably nfs_vnopdeop_decls) declaring all the operations NFS supports by
* default. Ficus could add another entry (ficus_nfs_vnodeop_decl_entensions)
* listing those new operations Ficus adds to NFS, all without modifying the
* NFS code. (Of couse, the OTW NFS protocol still needs to be munged, but
* that is a(whole)nother story.) This is a feature.
*/
/*
* Routines having to do with the management of the vnode table.
*/
static struct vfsconf *
vfs_byname_locked(const char *name)
{
struct vfsconf *vfsp;
sx_assert(&vfsconf_sx, SA_LOCKED);
if (!strcmp(name, "ffs"))
name = "ufs";
TAILQ_FOREACH(vfsp, &vfsconf, vfc_list) {
if (!strcmp(name, vfsp->vfc_name))
return (vfsp);
}
return (NULL);
}
struct vfsconf *
vfs_byname(const char *name)
{
struct vfsconf *vfsp;
vfsconf_slock();
vfsp = vfs_byname_locked(name);
vfsconf_sunlock();
return (vfsp);
}
struct vfsconf *
vfs_byname_kld(const char *fstype, struct thread *td, int *error)
{
struct vfsconf *vfsp;
int fileid, loaded;
vfsp = vfs_byname(fstype);
if (vfsp != NULL)
return (vfsp);
/* Try to load the respective module. */
*error = kern_kldload(td, fstype, &fileid);
loaded = (*error == 0);
if (*error == EEXIST)
*error = 0;
if (*error)
return (NULL);
/* Look up again to see if the VFS was loaded. */
vfsp = vfs_byname(fstype);
if (vfsp == NULL) {
if (loaded)
(void)kern_kldunload(td, fileid, LINKER_UNLOAD_FORCE);
*error = ENODEV;
return (NULL);
}
return (vfsp);
}
static int
vfs_mount_sigdefer(struct mount *mp)
{
int prev_stops, rc;
TSRAW(curthread, TS_ENTER, "VFS_MOUNT", mp->mnt_vfc->vfc_name);
prev_stops = sigdeferstop(SIGDEFERSTOP_SILENT);
rc = (*mp->mnt_vfc->vfc_vfsops_sd->vfs_mount)(mp);
sigallowstop(prev_stops);
TSRAW(curthread, TS_EXIT, "VFS_MOUNT", mp->mnt_vfc->vfc_name);
return (rc);
}
static int
vfs_unmount_sigdefer(struct mount *mp, int mntflags)
{
int prev_stops, rc;
prev_stops = sigdeferstop(SIGDEFERSTOP_SILENT);
rc = (*mp->mnt_vfc->vfc_vfsops_sd->vfs_unmount)(mp, mntflags);
sigallowstop(prev_stops);
return (rc);
}
static int
vfs_root_sigdefer(struct mount *mp, int flags, struct vnode **vpp)
{
int prev_stops, rc;
prev_stops = sigdeferstop(SIGDEFERSTOP_SILENT);
rc = (*mp->mnt_vfc->vfc_vfsops_sd->vfs_root)(mp, flags, vpp);
sigallowstop(prev_stops);
return (rc);
}
static int
vfs_cachedroot_sigdefer(struct mount *mp, int flags, struct vnode **vpp)
{
int prev_stops, rc;
prev_stops = sigdeferstop(SIGDEFERSTOP_SILENT);
rc = (*mp->mnt_vfc->vfc_vfsops_sd->vfs_cachedroot)(mp, flags, vpp);
sigallowstop(prev_stops);
return (rc);
}
static int
vfs_quotactl_sigdefer(struct mount *mp, int cmd, uid_t uid, void *arg,
bool *mp_busy)
{
int prev_stops, rc;
prev_stops = sigdeferstop(SIGDEFERSTOP_SILENT);
rc = (*mp->mnt_vfc->vfc_vfsops_sd->vfs_quotactl)(mp, cmd, uid, arg,
mp_busy);
sigallowstop(prev_stops);
return (rc);
}
static int
vfs_statfs_sigdefer(struct mount *mp, struct statfs *sbp)
{
int prev_stops, rc;
prev_stops = sigdeferstop(SIGDEFERSTOP_SILENT);
rc = (*mp->mnt_vfc->vfc_vfsops_sd->vfs_statfs)(mp, sbp);
sigallowstop(prev_stops);
return (rc);
}
static int
vfs_sync_sigdefer(struct mount *mp, int waitfor)
{
int prev_stops, rc;
prev_stops = sigdeferstop(SIGDEFERSTOP_SILENT);
rc = (*mp->mnt_vfc->vfc_vfsops_sd->vfs_sync)(mp, waitfor);
sigallowstop(prev_stops);
return (rc);
}
static int
vfs_vget_sigdefer(struct mount *mp, ino_t ino, int flags, struct vnode **vpp)
{
int prev_stops, rc;
prev_stops = sigdeferstop(SIGDEFERSTOP_SILENT);
rc = (*mp->mnt_vfc->vfc_vfsops_sd->vfs_vget)(mp, ino, flags, vpp);
sigallowstop(prev_stops);
return (rc);
}
static int
vfs_fhtovp_sigdefer(struct mount *mp, struct fid *fidp, int flags,
struct vnode **vpp)
{
int prev_stops, rc;
prev_stops = sigdeferstop(SIGDEFERSTOP_SILENT);
rc = (*mp->mnt_vfc->vfc_vfsops_sd->vfs_fhtovp)(mp, fidp, flags, vpp);
sigallowstop(prev_stops);
return (rc);
}
static int
vfs_checkexp_sigdefer(struct mount *mp, struct sockaddr *nam, uint64_t *exflg,
struct ucred **credp, int *numsecflavors, int *secflavors)
{
int prev_stops, rc;
prev_stops = sigdeferstop(SIGDEFERSTOP_SILENT);
rc = (*mp->mnt_vfc->vfc_vfsops_sd->vfs_checkexp)(mp, nam, exflg, credp,
numsecflavors, secflavors);
sigallowstop(prev_stops);
return (rc);
}
static int
vfs_extattrctl_sigdefer(struct mount *mp, int cmd, struct vnode *filename_vp,
int attrnamespace, const char *attrname)
{
int prev_stops, rc;
prev_stops = sigdeferstop(SIGDEFERSTOP_SILENT);
rc = (*mp->mnt_vfc->vfc_vfsops_sd->vfs_extattrctl)(mp, cmd,
filename_vp, attrnamespace, attrname);
sigallowstop(prev_stops);
return (rc);
}
static int
vfs_sysctl_sigdefer(struct mount *mp, fsctlop_t op, struct sysctl_req *req)
{
int prev_stops, rc;
prev_stops = sigdeferstop(SIGDEFERSTOP_SILENT);
rc = (*mp->mnt_vfc->vfc_vfsops_sd->vfs_sysctl)(mp, op, req);
sigallowstop(prev_stops);
return (rc);
}
static void
vfs_susp_clean_sigdefer(struct mount *mp)
{
int prev_stops;
if (*mp->mnt_vfc->vfc_vfsops_sd->vfs_susp_clean == NULL)
return;
prev_stops = sigdeferstop(SIGDEFERSTOP_SILENT);
(*mp->mnt_vfc->vfc_vfsops_sd->vfs_susp_clean)(mp);
sigallowstop(prev_stops);
}
static void
vfs_reclaim_lowervp_sigdefer(struct mount *mp, struct vnode *vp)
{
int prev_stops;
if (*mp->mnt_vfc->vfc_vfsops_sd->vfs_reclaim_lowervp == NULL)
return;
prev_stops = sigdeferstop(SIGDEFERSTOP_SILENT);
(*mp->mnt_vfc->vfc_vfsops_sd->vfs_reclaim_lowervp)(mp, vp);
sigallowstop(prev_stops);
}
static void
vfs_unlink_lowervp_sigdefer(struct mount *mp, struct vnode *vp)
{
int prev_stops;
if (*mp->mnt_vfc->vfc_vfsops_sd->vfs_unlink_lowervp == NULL)
return;
prev_stops = sigdeferstop(SIGDEFERSTOP_SILENT);
(*(mp)->mnt_vfc->vfc_vfsops_sd->vfs_unlink_lowervp)(mp, vp);
sigallowstop(prev_stops);
}
static void
vfs_purge_sigdefer(struct mount *mp)
{
int prev_stops;
prev_stops = sigdeferstop(SIGDEFERSTOP_SILENT);
(*mp->mnt_vfc->vfc_vfsops_sd->vfs_purge)(mp);
sigallowstop(prev_stops);
}
static int
vfs_report_lockf_sigdefer(struct mount *mp, struct sbuf *sb)
{
int prev_stops, rc;
prev_stops = sigdeferstop(SIGDEFERSTOP_SILENT);
rc = (*mp->mnt_vfc->vfc_vfsops_sd->vfs_report_lockf)(mp, sb);
sigallowstop(prev_stops);
return (rc);
}
static struct vfsops vfsops_sigdefer = {
.vfs_mount = vfs_mount_sigdefer,
.vfs_unmount = vfs_unmount_sigdefer,
.vfs_root = vfs_root_sigdefer,
.vfs_cachedroot = vfs_cachedroot_sigdefer,
.vfs_quotactl = vfs_quotactl_sigdefer,
.vfs_statfs = vfs_statfs_sigdefer,
.vfs_sync = vfs_sync_sigdefer,
.vfs_vget = vfs_vget_sigdefer,
.vfs_fhtovp = vfs_fhtovp_sigdefer,
.vfs_checkexp = vfs_checkexp_sigdefer,
.vfs_extattrctl = vfs_extattrctl_sigdefer,
.vfs_sysctl = vfs_sysctl_sigdefer,
.vfs_susp_clean = vfs_susp_clean_sigdefer,
.vfs_reclaim_lowervp = vfs_reclaim_lowervp_sigdefer,
.vfs_unlink_lowervp = vfs_unlink_lowervp_sigdefer,
.vfs_purge = vfs_purge_sigdefer,
.vfs_report_lockf = vfs_report_lockf_sigdefer,
};
/* Register a new filesystem type in the global table */
static int
vfs_register(struct vfsconf *vfc)
{
struct sysctl_oid *oidp;
struct vfsops *vfsops;
static int once;
struct vfsconf *tvfc;
uint32_t hashval;
int secondpass;
if (!once) {
vattr_null(&va_null);
once = 1;
}
if (vfc->vfc_version != VFS_VERSION) {
printf("ERROR: filesystem %s, unsupported ABI version %x\n",
vfc->vfc_name, vfc->vfc_version);
return (EINVAL);
}
vfsconf_lock();
if (vfs_byname_locked(vfc->vfc_name) != NULL) {
vfsconf_unlock();
return (EEXIST);
}
if (vfs_typenumhash != 0) {
/*
* Calculate a hash on vfc_name to use for vfc_typenum. Unless
* all of 1<->255 are assigned, it is limited to 8bits since
* that is what ZFS uses from vfc_typenum and is also the
* preferred range for vfs_getnewfsid().
*/
hashval = fnv_32_str(vfc->vfc_name, FNV1_32_INIT);
hashval &= 0xff;
secondpass = 0;
do {
/* Look for and fix any collision. */
TAILQ_FOREACH(tvfc, &vfsconf, vfc_list) {
if (hashval == tvfc->vfc_typenum) {
if (hashval == 255 && secondpass == 0) {
hashval = 1;
secondpass = 1;
} else
hashval++;
break;
}
}
} while (tvfc != NULL);
vfc->vfc_typenum = hashval;
if (vfc->vfc_typenum >= maxvfsconf)
maxvfsconf = vfc->vfc_typenum + 1;
} else
vfc->vfc_typenum = maxvfsconf++;
TAILQ_INSERT_TAIL(&vfsconf, vfc, vfc_list);
/*
* Initialise unused ``struct vfsops'' fields, to use
* the vfs_std*() functions. Note, we need the mount
* and unmount operations, at the least. The check
* for vfsops available is just a debugging aid.
*/
KASSERT(vfc->vfc_vfsops != NULL,
("Filesystem %s has no vfsops", vfc->vfc_name));
/*
* Check the mount and unmount operations.
*/
vfsops = vfc->vfc_vfsops;
KASSERT(vfsops->vfs_mount != NULL,
("Filesystem %s has no mount op", vfc->vfc_name));
KASSERT(vfsops->vfs_unmount != NULL,
("Filesystem %s has no unmount op", vfc->vfc_name));
if (vfsops->vfs_root == NULL)
/* return file system's root vnode */
vfsops->vfs_root = vfs_stdroot;
if (vfsops->vfs_quotactl == NULL)
/* quota control */
vfsops->vfs_quotactl = vfs_stdquotactl;
if (vfsops->vfs_statfs == NULL)
/* return file system's status */
vfsops->vfs_statfs = vfs_stdstatfs;
if (vfsops->vfs_sync == NULL)
/*
* flush unwritten data (nosync)
* file systems can use vfs_stdsync
* explicitly by setting it in the
* vfsop vector.
*/
vfsops->vfs_sync = vfs_stdnosync;
if (vfsops->vfs_vget == NULL)
/* convert an inode number to a vnode */
vfsops->vfs_vget = vfs_stdvget;
if (vfsops->vfs_fhtovp == NULL)
/* turn an NFS file handle into a vnode */
vfsops->vfs_fhtovp = vfs_stdfhtovp;
if (vfsops->vfs_checkexp == NULL)
/* check if file system is exported */
vfsops->vfs_checkexp = vfs_stdcheckexp;
if (vfsops->vfs_init == NULL)
/* file system specific initialisation */
vfsops->vfs_init = vfs_stdinit;
if (vfsops->vfs_uninit == NULL)
/* file system specific uninitialisation */
vfsops->vfs_uninit = vfs_stduninit;
if (vfsops->vfs_extattrctl == NULL)
/* extended attribute control */
vfsops->vfs_extattrctl = vfs_stdextattrctl;
if (vfsops->vfs_sysctl == NULL)
vfsops->vfs_sysctl = vfs_stdsysctl;
if (vfsops->vfs_report_lockf == NULL)
vfsops->vfs_report_lockf = vfs_report_lockf;
if ((vfc->vfc_flags & VFCF_SBDRY) != 0) {
vfc->vfc_vfsops_sd = vfc->vfc_vfsops;
vfc->vfc_vfsops = &vfsops_sigdefer;
}
if (vfc->vfc_flags & VFCF_JAIL)
prison_add_vfs(vfc);
/*
* Call init function for this VFS...
*/
if ((vfc->vfc_flags & VFCF_SBDRY) != 0)
vfc->vfc_vfsops_sd->vfs_init(vfc);
else
vfc->vfc_vfsops->vfs_init(vfc);
vfsconf_unlock();
/*
* If this filesystem has a sysctl node under vfs
* (i.e. vfs.xxfs), then change the oid number of that node to
* match the filesystem's type number. This allows user code
* which uses the type number to read sysctl variables defined
* by the filesystem to continue working. Since the oids are
* in a sorted list, we need to make sure the order is
* preserved by re-registering the oid after modifying its
* number.
*/
sysctl_wlock();
- SLIST_FOREACH(oidp, SYSCTL_CHILDREN(&sysctl___vfs), oid_link) {
+ RB_FOREACH(oidp, sysctl_oid_list, SYSCTL_CHILDREN(&sysctl___vfs)) {
if (strcmp(oidp->oid_name, vfc->vfc_name) == 0) {
sysctl_unregister_oid(oidp);
oidp->oid_number = vfc->vfc_typenum;
sysctl_register_oid(oidp);
break;
}
}
sysctl_wunlock();
return (0);
}
/* Remove registration of a filesystem type */
static int
vfs_unregister(struct vfsconf *vfc)
{
struct vfsconf *vfsp;
int error, maxtypenum;
vfsconf_lock();
vfsp = vfs_byname_locked(vfc->vfc_name);
if (vfsp == NULL) {
vfsconf_unlock();
return (EINVAL);
}
if (vfsp->vfc_refcount != 0) {
vfsconf_unlock();
return (EBUSY);
}
error = 0;
if ((vfc->vfc_flags & VFCF_SBDRY) != 0) {
if (vfc->vfc_vfsops_sd->vfs_uninit != NULL)
error = vfc->vfc_vfsops_sd->vfs_uninit(vfsp);
} else {
if (vfc->vfc_vfsops->vfs_uninit != NULL)
error = vfc->vfc_vfsops->vfs_uninit(vfsp);
}
if (error != 0) {
vfsconf_unlock();
return (error);
}
TAILQ_REMOVE(&vfsconf, vfsp, vfc_list);
maxtypenum = VFS_GENERIC;
TAILQ_FOREACH(vfsp, &vfsconf, vfc_list)
if (maxtypenum < vfsp->vfc_typenum)
maxtypenum = vfsp->vfc_typenum;
maxvfsconf = maxtypenum + 1;
vfsconf_unlock();
return (0);
}
/*
* Standard kernel module handling code for filesystem modules.
* Referenced from VFS_SET().
*/
int
vfs_modevent(module_t mod, int type, void *data)
{
struct vfsconf *vfc;
int error = 0;
vfc = (struct vfsconf *)data;
switch (type) {
case MOD_LOAD:
if (vfc)
error = vfs_register(vfc);
break;
case MOD_UNLOAD:
if (vfc)
error = vfs_unregister(vfc);
break;
default:
error = EOPNOTSUPP;
break;
}
return (error);
}
diff --git a/sys/sys/param.h b/sys/sys/param.h
index f875d839d41f..3f5da06ef951 100644
--- a/sys/sys/param.h
+++ b/sys/sys/param.h
@@ -1,390 +1,390 @@
/*-
* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright (c) 1982, 1986, 1989, 1993
* The Regents of the University of California. All rights reserved.
* (c) UNIX System Laboratories, Inc.
* All or some portions of this file are derived from material licensed
* to the University of California by American Telephone and Telegraph
* Co. or Unix System Laboratories, Inc. and are reproduced herein with
* the permission of UNIX System Laboratories, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)param.h 8.3 (Berkeley) 4/4/95
* $FreeBSD$
*/
#ifndef _SYS_PARAM_H_
#define _SYS_PARAM_H_
#include <sys/_null.h>
#define BSD 199506 /* System version (year & month). */
#define BSD4_3 1
#define BSD4_4 1
/*
* __FreeBSD_version numbers are documented in the Porter's Handbook.
* If you bump the version for any reason, you should update the documentation
* there.
* Currently this lives here in the doc/ repository:
*
* documentation/content/en/books/porters-handbook/versions/_index.adoc
*
* Encoding: <major><two digit minor>Rxx
* 'R' is in the range 0 to 4 if this is a release branch or
* X.0-CURRENT before releng/X.0 is created, otherwise 'R' is
* in the range 5 to 9.
* Short hand: MMmmXXX
*
* __FreeBSD_version is bumped every time there's a change in the base system
* that's noteworthy. A noteworthy change is any change which changes the
* kernel's KBI in -CURRENT, one that changes some detail about the system that
* external software (or the ports system) would want to know about, one that
* adds a system call, one that adds or deletes a shipped library, a security
* fix, or similar change not specifically noted here. Bumps should be limited
* to one per day / a couple per week except for security fixes.
*
* The approved way to obtain this from a shell script is:
* awk '/^\#define[[:space:]]*__FreeBSD_version/ {print $3}'
* Other methods to parse this file may work, but are not guaranteed against
* future changes. The above script works back to FreeBSD 3.x when this macro
* was introduced. This number is propagated to other places needing it that
* cannot include sys/param.h and should only be updated here.
*/
#undef __FreeBSD_version
-#define __FreeBSD_version 1400070
+#define __FreeBSD_version 1400071
/*
* __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD,
* which by definition is always true on FreeBSD. This macro is also defined
* on other systems that use the kernel of FreeBSD, such as GNU/kFreeBSD.
*
* It is tempting to use this macro in userland code when we want to enable
* kernel-specific routines, and in fact it's fine to do this in code that
* is part of FreeBSD itself. However, be aware that as presence of this
* macro is still not widespread (e.g. older FreeBSD versions, 3rd party
* compilers, etc), it is STRONGLY DISCOURAGED to check for this macro in
* external applications without also checking for __FreeBSD__ as an
* alternative.
*/
#undef __FreeBSD_kernel__
#define __FreeBSD_kernel__
#if defined(_KERNEL) || defined(IN_RTLD)
#define P_OSREL_SIGWAIT 700000
#define P_OSREL_SIGSEGV 700004
#define P_OSREL_MAP_ANON 800104
#define P_OSREL_MAP_FSTRICT 1100036
#define P_OSREL_SHUTDOWN_ENOTCONN 1100077
#define P_OSREL_MAP_GUARD 1200035
#define P_OSREL_WRFSBASE 1200041
#define P_OSREL_CK_CYLGRP 1200046
#define P_OSREL_VMTOTAL64 1200054
#define P_OSREL_CK_SUPERBLOCK 1300000
#define P_OSREL_CK_INODE 1300005
#define P_OSREL_POWERPC_NEW_AUX_ARGS 1300070
#define P_OSREL_MAJOR(x) ((x) / 100000)
#endif
#ifndef LOCORE
#include <sys/types.h>
#endif
/*
* Machine-independent constants (some used in following include files).
* Redefined constants are from POSIX 1003.1 limits file.
*
* MAXCOMLEN should be >= sizeof(ac_comm) (see <acct.h>)
*/
#include <sys/syslimits.h>
#define MAXCOMLEN 19 /* max command name remembered */
#define MAXINTERP PATH_MAX /* max interpreter file name length */
#define MAXLOGNAME 33 /* max login name length (incl. NUL) */
#define MAXUPRC CHILD_MAX /* max simultaneous processes */
#define NCARGS ARG_MAX /* max bytes for an exec function */
#define NGROUPS (NGROUPS_MAX+1) /* max number groups */
#define NOFILE OPEN_MAX /* max open files per process */
#define NOGROUP 65535 /* marker for empty group set member */
#define MAXHOSTNAMELEN 256 /* max hostname size */
#define SPECNAMELEN 255 /* max length of devicename */
/* More types and definitions used throughout the kernel. */
#ifdef _KERNEL
#include <sys/cdefs.h>
#include <sys/errno.h>
#ifndef LOCORE
#include <sys/time.h>
#include <sys/priority.h>
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
#endif
#ifndef _KERNEL
#ifndef LOCORE
/* Signals. */
#include <sys/signal.h>
#endif
#endif
/* Machine type dependent parameters. */
#include <machine/param.h>
#ifndef _KERNEL
#include <sys/limits.h>
#endif
#ifndef DEV_BSHIFT
#define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */
#endif
#define DEV_BSIZE (1<<DEV_BSHIFT)
#ifndef BLKDEV_IOSIZE
#define BLKDEV_IOSIZE PAGE_SIZE /* default block device I/O size */
#endif
#ifndef DFLTPHYS
#define DFLTPHYS (64 * 1024) /* default max raw I/O transfer size */
#endif
#ifndef MAXPHYS /* max raw I/O transfer size */
#ifdef __ILP32__
#define MAXPHYS (128 * 1024)
#else
#define MAXPHYS (1024 * 1024)
#endif
#endif
#ifndef MAXDUMPPGS
#define MAXDUMPPGS (DFLTPHYS/PAGE_SIZE)
#endif
/*
* Constants related to network buffer management.
* MCLBYTES must be no larger than PAGE_SIZE.
*/
#ifndef MSIZE
#define MSIZE 256 /* size of an mbuf */
#endif
#ifndef MCLSHIFT
#define MCLSHIFT 11 /* convert bytes to mbuf clusters */
#endif /* MCLSHIFT */
#define MCLBYTES (1 << MCLSHIFT) /* size of an mbuf cluster */
#if PAGE_SIZE <= 8192
#define MJUMPAGESIZE PAGE_SIZE
#else
#define MJUMPAGESIZE (8 * 1024)
#endif
#define MJUM9BYTES (9 * 1024) /* jumbo cluster 9k */
#define MJUM16BYTES (16 * 1024) /* jumbo cluster 16k */
/*
* Some macros for units conversion
*/
/* clicks to bytes */
#ifndef ctob
#define ctob(x) ((x)<<PAGE_SHIFT)
#endif
/* bytes to clicks */
#ifndef btoc
#define btoc(x) (((vm_offset_t)(x)+PAGE_MASK)>>PAGE_SHIFT)
#endif
/*
* btodb() is messy and perhaps slow because `bytes' may be an off_t. We
* want to shift an unsigned type to avoid sign extension and we don't
* want to widen `bytes' unnecessarily. Assume that the result fits in
* a daddr_t.
*/
#ifndef btodb
#define btodb(bytes) /* calculates (bytes / DEV_BSIZE) */ \
(sizeof (bytes) > sizeof(long) \
? (daddr_t)((unsigned long long)(bytes) >> DEV_BSHIFT) \
: (daddr_t)((unsigned long)(bytes) >> DEV_BSHIFT))
#endif
#ifndef dbtob
#define dbtob(db) /* calculates (db * DEV_BSIZE) */ \
((off_t)(db) << DEV_BSHIFT)
#endif
#define PRIMASK 0x0ff
#define PCATCH 0x100 /* OR'd with pri for tsleep to check signals */
#define PDROP 0x200 /* OR'd with pri to stop re-entry of interlock mutex */
#define PNOLOCK 0x400 /* OR'd with pri to allow sleeping w/o a lock */
#define PRILASTFLAG 0x400 /* Last flag defined above */
#define NZERO 0 /* default "nice" */
#define NBBY 8 /* number of bits in a byte */
#define NBPW sizeof(int) /* number of bytes per word (integer) */
#define CMASK 022 /* default file mask: S_IWGRP|S_IWOTH */
#define NODEV (dev_t)(-1) /* non-existent device */
/*
* File system parameters and macros.
*
* MAXBSIZE - Filesystems are made out of blocks of at most MAXBSIZE bytes
* per block. MAXBSIZE may be made larger without effecting
* any existing filesystems as long as it does not exceed MAXPHYS,
* and may be made smaller at the risk of not being able to use
* filesystems which require a block size exceeding MAXBSIZE.
*
* MAXBCACHEBUF - Maximum size of a buffer in the buffer cache. This must
* be >= MAXBSIZE and can be set differently for different
* architectures by defining it in <machine/param.h>.
* Making this larger allows NFS to do larger reads/writes.
*
* BKVASIZE - Nominal buffer space per buffer, in bytes. BKVASIZE is the
* minimum KVM memory reservation the kernel is willing to make.
* Filesystems can of course request smaller chunks. Actual
* backing memory uses a chunk size of a page (PAGE_SIZE).
* The default value here can be overridden on a per-architecture
* basis by defining it in <machine/param.h>.
*
* If you make BKVASIZE too small you risk seriously fragmenting
* the buffer KVM map which may slow things down a bit. If you
* make it too big the kernel will not be able to optimally use
* the KVM memory reserved for the buffer cache and will wind
* up with too-few buffers.
*
* The default is 16384, roughly 2x the block size used by a
* normal UFS filesystem.
*/
#define MAXBSIZE 65536 /* must be power of 2 */
#ifndef MAXBCACHEBUF
#define MAXBCACHEBUF MAXBSIZE /* must be a power of 2 >= MAXBSIZE */
#endif
#ifndef BKVASIZE
#define BKVASIZE 16384 /* must be power of 2 */
#endif
#define BKVAMASK (BKVASIZE-1)
/*
* MAXPATHLEN defines the longest permissible path length after expanding
* symbolic links. It is used to allocate a temporary buffer from the buffer
* pool in which to do the name expansion, hence should be a power of two,
* and must be less than or equal to MAXBSIZE. MAXSYMLINKS defines the
* maximum number of symbolic links that may be expanded in a path name.
* It should be set high enough to allow all legitimate uses, but halt
* infinite loops reasonably quickly.
*/
#define MAXPATHLEN PATH_MAX
#define MAXSYMLINKS 32
/* Bit map related macros. */
#define setbit(a,i) (((unsigned char *)(a))[(i)/NBBY] |= 1<<((i)%NBBY))
#define clrbit(a,i) (((unsigned char *)(a))[(i)/NBBY] &= ~(1<<((i)%NBBY)))
#define isset(a,i) \
(((const unsigned char *)(a))[(i)/NBBY] & (1<<((i)%NBBY)))
#define isclr(a,i) \
((((const unsigned char *)(a))[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
/* Macros for counting and rounding. */
#ifndef howmany
#define howmany(x, y) (((x)+((y)-1))/(y))
#endif
#define nitems(x) (sizeof((x)) / sizeof((x)[0]))
#define rounddown(x, y) (((x)/(y))*(y))
#define rounddown2(x, y) __align_down(x, y) /* if y is power of two */
#define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) /* to any y */
#define roundup2(x, y) __align_up(x, y) /* if y is powers of two */
#define powerof2(x) ((((x)-1)&(x))==0)
/* Macros for min/max. */
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))
#ifdef _KERNEL
/*
* Basic byte order function prototypes for non-inline functions.
*/
#ifndef LOCORE
#ifndef _BYTEORDER_PROTOTYPED
#define _BYTEORDER_PROTOTYPED
__BEGIN_DECLS
__uint32_t htonl(__uint32_t);
__uint16_t htons(__uint16_t);
__uint32_t ntohl(__uint32_t);
__uint16_t ntohs(__uint16_t);
__END_DECLS
#endif
#endif
#ifndef _BYTEORDER_FUNC_DEFINED
#define _BYTEORDER_FUNC_DEFINED
#define htonl(x) __htonl(x)
#define htons(x) __htons(x)
#define ntohl(x) __ntohl(x)
#define ntohs(x) __ntohs(x)
#endif /* !_BYTEORDER_FUNC_DEFINED */
#endif /* _KERNEL */
/*
* Scale factor for scaled integers used to count %cpu time and load avgs.
*
* The number of CPU `tick's that map to a unique `%age' can be expressed
* by the formula (1 / (2 ^ (FSHIFT - 11))). Since the intermediate
* calculation is done with 64-bit precision, the maximum load average that can
* be calculated is approximately 2^32 / FSCALE.
*
* For the scheduler to maintain a 1:1 mapping of CPU `tick' to `%age',
* FSHIFT must be at least 11. This gives a maximum load avg of 2 million.
*/
#define FSHIFT 11 /* bits to right of fixed binary point */
#define FSCALE (1<<FSHIFT)
#define dbtoc(db) /* calculates devblks to pages */ \
((db + (ctodb(1) - 1)) >> (PAGE_SHIFT - DEV_BSHIFT))
#define ctodb(db) /* calculates pages to devblks */ \
((db) << (PAGE_SHIFT - DEV_BSHIFT))
/*
* Old spelling of __containerof().
*/
#define member2struct(s, m, x) \
((struct s *)(void *)((char *)(x) - offsetof(struct s, m)))
/*
* Access a variable length array that has been declared as a fixed
* length array.
*/
#define __PAST_END(array, offset) (((__typeof__(*(array)) *)(array))[offset])
#endif /* _SYS_PARAM_H_ */
diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h
index 451d83bbe125..3bd77cf87243 100644
--- a/sys/sys/sysctl.h
+++ b/sys/sys/sysctl.h
@@ -1,1192 +1,1211 @@
/*-
* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Mike Karels at Berkeley Software Design, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)sysctl.h 8.1 (Berkeley) 6/2/93
* $FreeBSD$
*/
#ifndef _SYS_SYSCTL_H_
#define _SYS_SYSCTL_H_
#ifdef _KERNEL
-#include <sys/queue.h>
+#include <sys/tree.h>
+#include <sys/systm.h>
#endif
/*
* Definitions for sysctl call. The sysctl call uses a hierarchical name
* for objects that can be examined or modified. The name is expressed as
* a sequence of integers. Like a file path name, the meaning of each
* component depends on its place in the hierarchy. The top-level and kern
* identifiers are defined here, and other identifiers are defined in the
* respective subsystem header files.
*
* Each subsystem defined by sysctl defines a list of variables for that
* subsystem. Each name is either a node with further levels defined below it,
* or it is a leaf of some particular type given below. Each sysctl level
* defines a set of name/type pairs to be used by sysctl(8) in manipulating the
* subsystem.
*/
#define CTL_MAXNAME 24 /* largest number of components supported */
#define CTLTYPE 0xf /* mask for the type */
#define CTLTYPE_NODE 1 /* name is a node */
#define CTLTYPE_INT 2 /* name describes an integer */
#define CTLTYPE_STRING 3 /* name describes a string */
#define CTLTYPE_S64 4 /* name describes a signed 64-bit number */
#define CTLTYPE_OPAQUE 5 /* name describes a structure */
#define CTLTYPE_STRUCT CTLTYPE_OPAQUE /* name describes a structure */
#define CTLTYPE_UINT 6 /* name describes an unsigned integer */
#define CTLTYPE_LONG 7 /* name describes a long */
#define CTLTYPE_ULONG 8 /* name describes an unsigned long */
#define CTLTYPE_U64 9 /* name describes an unsigned 64-bit number */
#define CTLTYPE_U8 0xa /* name describes an unsigned 8-bit number */
#define CTLTYPE_U16 0xb /* name describes an unsigned 16-bit number */
#define CTLTYPE_S8 0xc /* name describes a signed 8-bit number */
#define CTLTYPE_S16 0xd /* name describes a signed 16-bit number */
#define CTLTYPE_S32 0xe /* name describes a signed 32-bit number */
#define CTLTYPE_U32 0xf /* name describes an unsigned 32-bit number */
#define CTLFLAG_RD 0x80000000 /* Allow reads of variable */
#define CTLFLAG_WR 0x40000000 /* Allow writes to the variable */
#define CTLFLAG_RW (CTLFLAG_RD|CTLFLAG_WR)
#define CTLFLAG_DORMANT 0x20000000 /* This sysctl is not active yet */
#define CTLFLAG_ANYBODY 0x10000000 /* All users can set this var */
#define CTLFLAG_SECURE 0x08000000 /* Permit set only if securelevel<=0 */
#define CTLFLAG_PRISON 0x04000000 /* Prisoned roots can fiddle */
#define CTLFLAG_DYN 0x02000000 /* Dynamic oid - can be freed */
#define CTLFLAG_SKIP 0x01000000 /* Skip this sysctl when listing */
#define CTLMASK_SECURE 0x00F00000 /* Secure level */
#define CTLFLAG_TUN 0x00080000 /* Default value is loaded from getenv() */
#define CTLFLAG_RDTUN (CTLFLAG_RD|CTLFLAG_TUN)
#define CTLFLAG_RWTUN (CTLFLAG_RW|CTLFLAG_TUN)
#define CTLFLAG_MPSAFE 0x00040000 /* Handler is MP safe */
#define CTLFLAG_VNET 0x00020000 /* Prisons with vnet can fiddle */
#define CTLFLAG_DYING 0x00010000 /* Oid is being removed */
#define CTLFLAG_CAPRD 0x00008000 /* Can be read in capability mode */
#define CTLFLAG_CAPWR 0x00004000 /* Can be written in capability mode */
#define CTLFLAG_STATS 0x00002000 /* Statistics, not a tuneable */
#define CTLFLAG_NOFETCH 0x00001000 /* Don't fetch tunable from getenv() */
#define CTLFLAG_CAPRW (CTLFLAG_CAPRD|CTLFLAG_CAPWR)
/*
* This is transient flag to be used until all sysctl handlers are converted
* to not lock Giant.
* One, and only one of CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT is required
* for SYSCTL_PROC and SYSCTL_NODE.
*/
#define CTLFLAG_NEEDGIANT 0x00000800 /* Handler require Giant */
/*
* Secure level. Note that CTLFLAG_SECURE == CTLFLAG_SECURE1.
*
* Secure when the securelevel is raised to at least N.
*/
#define CTLSHIFT_SECURE 20
#define CTLFLAG_SECURE1 (CTLFLAG_SECURE | (0 << CTLSHIFT_SECURE))
#define CTLFLAG_SECURE2 (CTLFLAG_SECURE | (1 << CTLSHIFT_SECURE))
#define CTLFLAG_SECURE3 (CTLFLAG_SECURE | (2 << CTLSHIFT_SECURE))
/*
* USE THIS instead of a hardwired number from the categories below
* to get dynamically assigned sysctl entries using the linker-set
* technology. This is the way nearly all new sysctl variables should
* be implemented.
* e.g. SYSCTL_INT(_parent, OID_AUTO, name, CTLFLAG_RW, &variable, 0, "");
*/
#define OID_AUTO (-1)
/*
* The starting number for dynamically-assigned entries. WARNING!
* ALL static sysctl entries should have numbers LESS than this!
*/
#define CTL_AUTO_START 0x100
#ifdef _KERNEL
#include <sys/linker_set.h>
#ifdef KLD_MODULE
/* XXX allow overspecification of type in external kernel modules */
#define SYSCTL_CT_ASSERT_MASK CTLTYPE
#else
#define SYSCTL_CT_ASSERT_MASK 0
#endif
#define SYSCTL_HANDLER_ARGS struct sysctl_oid *oidp, void *arg1, \
intmax_t arg2, struct sysctl_req *req
/* definitions for sysctl_req 'lock' member */
#define REQ_UNWIRED 1
#define REQ_WIRED 2
/* definitions for sysctl_req 'flags' member */
#ifdef COMPAT_FREEBSD32
#define SCTL_MASK32 1 /* 32 bit emulation */
#endif
/*
* This describes the access space for a sysctl request. This is needed
* so that we can use the interface from the kernel or from user-space.
*/
struct thread;
struct sysctl_req {
struct thread *td; /* used for access checking */
int lock; /* wiring state */
void *oldptr;
size_t oldlen;
size_t oldidx;
int (*oldfunc)(struct sysctl_req *, const void *, size_t);
const void *newptr;
size_t newlen;
size_t newidx;
int (*newfunc)(struct sysctl_req *, void *, size_t);
size_t validlen;
int flags;
};
-SLIST_HEAD(sysctl_oid_list, sysctl_oid);
+struct sysctl_oid;
+
+/* RB Tree handling */
+RB_HEAD(sysctl_oid_list, sysctl_oid);
/*
* This describes one "oid" in the MIB tree. Potentially more nodes can
* be hidden behind it, expanded by the handler.
*/
struct sysctl_oid {
- struct sysctl_oid_list oid_children;
- struct sysctl_oid_list *oid_parent;
- SLIST_ENTRY(sysctl_oid) oid_link;
+ struct sysctl_oid_list oid_children;
+ struct sysctl_oid_list* oid_parent;
+ RB_ENTRY(sysctl_oid) oid_link;
+ /* Sort key for all siblings, and lookup key for userland */
int oid_number;
u_int oid_kind;
void *oid_arg1;
intmax_t oid_arg2;
+ /* Must be unique amongst all siblings. */
const char *oid_name;
int (*oid_handler)(SYSCTL_HANDLER_ARGS);
const char *oid_fmt;
int oid_refcnt;
u_int oid_running;
const char *oid_descr;
const char *oid_label;
};
+static inline int
+cmp_sysctl_oid(struct sysctl_oid *a, struct sysctl_oid *b)
+{
+ if (a->oid_number > b->oid_number)
+ return (1);
+ else if (a->oid_number < b->oid_number)
+ return (-1);
+ else
+ return (0);
+}
+
+RB_PROTOTYPE(sysctl_oid_list, sysctl_oid, oid_link, cmp_sysctl_oid);
+
#define SYSCTL_IN(r, p, l) (r->newfunc)(r, p, l)
#define SYSCTL_OUT(r, p, l) (r->oldfunc)(r, p, l)
#define SYSCTL_OUT_STR(r, p) (r->oldfunc)(r, p, strlen(p) + 1)
int sysctl_handle_bool(SYSCTL_HANDLER_ARGS);
int sysctl_handle_8(SYSCTL_HANDLER_ARGS);
int sysctl_handle_16(SYSCTL_HANDLER_ARGS);
int sysctl_handle_32(SYSCTL_HANDLER_ARGS);
int sysctl_handle_64(SYSCTL_HANDLER_ARGS);
int sysctl_handle_int(SYSCTL_HANDLER_ARGS);
int sysctl_msec_to_ticks(SYSCTL_HANDLER_ARGS);
int sysctl_handle_long(SYSCTL_HANDLER_ARGS);
int sysctl_handle_string(SYSCTL_HANDLER_ARGS);
int sysctl_handle_opaque(SYSCTL_HANDLER_ARGS);
int sysctl_handle_counter_u64(SYSCTL_HANDLER_ARGS);
int sysctl_handle_counter_u64_array(SYSCTL_HANDLER_ARGS);
int sysctl_handle_uma_zone_max(SYSCTL_HANDLER_ARGS);
int sysctl_handle_uma_zone_cur(SYSCTL_HANDLER_ARGS);
int sysctl_msec_to_sbintime(SYSCTL_HANDLER_ARGS);
int sysctl_usec_to_sbintime(SYSCTL_HANDLER_ARGS);
int sysctl_sec_to_timeval(SYSCTL_HANDLER_ARGS);
int sysctl_dpcpu_int(SYSCTL_HANDLER_ARGS);
int sysctl_dpcpu_long(SYSCTL_HANDLER_ARGS);
int sysctl_dpcpu_quad(SYSCTL_HANDLER_ARGS);
/*
* These functions are used to add/remove an oid from the mib.
*/
void sysctl_register_oid(struct sysctl_oid *oidp);
void sysctl_register_disabled_oid(struct sysctl_oid *oidp);
void sysctl_enable_oid(struct sysctl_oid *oidp);
void sysctl_unregister_oid(struct sysctl_oid *oidp);
/* Declare a static oid to allow child oids to be added to it. */
#define SYSCTL_DECL(name) \
extern struct sysctl_oid sysctl__##name
/* Hide these in macros. */
#define SYSCTL_CHILDREN(oid_ptr) (&(oid_ptr)->oid_children)
#define SYSCTL_PARENT(oid_ptr) \
(((oid_ptr)->oid_parent != &sysctl__children) ? \
__containerof((oid_ptr)->oid_parent, struct sysctl_oid, \
oid_children) : (struct sysctl_oid *)NULL)
#define SYSCTL_STATIC_CHILDREN(oid_name) (&sysctl__##oid_name.oid_children)
/* === Structs and macros related to context handling. === */
/* All dynamically created sysctls can be tracked in a context list. */
struct sysctl_ctx_entry {
struct sysctl_oid *entry;
TAILQ_ENTRY(sysctl_ctx_entry) link;
};
TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry);
#define SYSCTL_NODE_CHILDREN(parent, name) \
sysctl__##parent##_##name.oid_children
#ifndef NO_SYSCTL_DESCR
#define __DESCR(d) d
#else
#define __DESCR(d) ""
#endif
#ifdef notyet
#define SYSCTL_ENFORCE_FLAGS(x) \
_Static_assert((((x) & CTLFLAG_MPSAFE) != 0) ^ (((x) & CTLFLAG_NEEDGIANT) != 0), \
"Has to be either CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT")
#else
#define SYSCTL_ENFORCE_FLAGS(x)
#endif
/* This macro is only for internal use */
#define SYSCTL_OID_RAW(id, parent_child_head, nbr, name, kind, a1, a2, handler, fmt, descr, label) \
struct sysctl_oid id = { \
.oid_parent = (parent_child_head), \
- .oid_children = SLIST_HEAD_INITIALIZER(&id.oid_children), \
+ .oid_children = RB_INITIALIZER(&id.oid_children), \
.oid_number = (nbr), \
.oid_kind = (kind), \
.oid_arg1 = (a1), \
.oid_arg2 = (a2), \
.oid_name = (name), \
.oid_handler = (handler), \
.oid_fmt = (fmt), \
.oid_descr = __DESCR(descr), \
.oid_label = (label), \
}; \
DATA_SET(sysctl_set, id); \
SYSCTL_ENFORCE_FLAGS(kind)
/* This constructs a static "raw" MIB oid. */
#define SYSCTL_OID(parent, nbr, name, kind, a1, a2, handler, fmt, descr) \
SYSCTL_OID_WITH_LABEL(parent, nbr, name, kind, a1, a2, \
handler, fmt, descr, NULL)
#define SYSCTL_OID_WITH_LABEL(parent, nbr, name, kind, a1, a2, handler, fmt, descr, label) \
static SYSCTL_OID_RAW(sysctl__##parent##_##name, \
SYSCTL_CHILDREN(&sysctl__##parent), \
nbr, #name, kind, a1, a2, handler, fmt, descr, label)
/* This constructs a global "raw" MIB oid. */
#define SYSCTL_OID_GLOBAL(parent, nbr, name, kind, a1, a2, handler, fmt, descr, label) \
SYSCTL_OID_RAW(sysctl__##parent##_##name, \
SYSCTL_CHILDREN(&sysctl__##parent), \
nbr, #name, kind, a1, a2, handler, fmt, descr, label)
#define SYSCTL_ADD_OID(ctx, parent, nbr, name, kind, a1, a2, handler, fmt, descr) \
({ \
SYSCTL_ENFORCE_FLAGS(kind); \
sysctl_add_oid(ctx, parent, nbr, name, kind, a1, a2,handler, \
fmt, __DESCR(descr), NULL); \
})
/* This constructs a root node from which other nodes can hang. */
#define SYSCTL_ROOT_NODE(nbr, name, access, handler, descr) \
SYSCTL_OID_RAW(sysctl___##name, &sysctl__children, \
nbr, #name, CTLTYPE_NODE|(access), NULL, 0, \
handler, "N", descr, NULL); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE)
/* This constructs a node from which other oids can hang. */
#define SYSCTL_NODE(parent, nbr, name, access, handler, descr) \
SYSCTL_NODE_WITH_LABEL(parent, nbr, name, access, handler, descr, NULL)
#define SYSCTL_NODE_WITH_LABEL(parent, nbr, name, access, handler, descr, label) \
SYSCTL_OID_GLOBAL(parent, nbr, name, CTLTYPE_NODE|(access), \
NULL, 0, handler, "N", descr, label); \
SYSCTL_ENFORCE_FLAGS(access); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE)
#define SYSCTL_ADD_NODE(ctx, parent, nbr, name, access, handler, descr) \
SYSCTL_ADD_NODE_WITH_LABEL(ctx, parent, nbr, name, access, \
handler, descr, NULL)
#define SYSCTL_ADD_NODE_WITH_LABEL(ctx, parent, nbr, name, access, handler, descr, label) \
({ \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE); \
SYSCTL_ENFORCE_FLAGS(access); \
sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_NODE|(access), \
NULL, 0, handler, "N", __DESCR(descr), label); \
})
#define SYSCTL_ADD_ROOT_NODE(ctx, nbr, name, access, handler, descr) \
({ \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE); \
SYSCTL_ENFORCE_FLAGS(access); \
sysctl_add_oid(ctx, &sysctl__children, nbr, name, \
CTLTYPE_NODE|(access), \
NULL, 0, handler, "N", __DESCR(descr), NULL); \
})
/* Oid for a string. len can be 0 to indicate '\0' termination. */
#define SYSCTL_STRING(parent, nbr, name, access, arg, len, descr) \
SYSCTL_OID(parent, nbr, name, \
CTLTYPE_STRING | CTLFLAG_MPSAFE | (access), \
arg, len, sysctl_handle_string, "A", descr); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_STRING)
#define SYSCTL_ADD_STRING(ctx, parent, nbr, name, access, arg, len, descr) \
({ \
char *__arg = (arg); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_STRING); \
sysctl_add_oid(ctx, parent, nbr, name, \
CTLTYPE_STRING | CTLFLAG_MPSAFE | (access), \
__arg, len, sysctl_handle_string, "A", __DESCR(descr), \
NULL); \
})
/* Oid for a constant '\0' terminated string. */
#define SYSCTL_CONST_STRING(parent, nbr, name, access, arg, descr) \
SYSCTL_OID(parent, nbr, name, CTLTYPE_STRING | CTLFLAG_MPSAFE | (access),\
__DECONST(char *, arg), 0, sysctl_handle_string, "A", descr); \
CTASSERT(!(access & CTLFLAG_WR)); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_STRING)
#define SYSCTL_ADD_CONST_STRING(ctx, parent, nbr, name, access, arg, descr) \
({ \
char *__arg = __DECONST(char *, arg); \
CTASSERT(!(access & CTLFLAG_WR)); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_STRING); \
sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_STRING | \
CTLFLAG_MPSAFE | (access), __arg, 0, sysctl_handle_string, "A",\
__DESCR(descr), NULL); \
})
/* Oid for a bool. If ptr is NULL, val is returned. */
#define SYSCTL_NULL_BOOL_PTR ((bool *)NULL)
#define SYSCTL_BOOL(parent, nbr, name, access, ptr, val, descr) \
SYSCTL_OID(parent, nbr, name, \
CTLTYPE_U8 | CTLFLAG_MPSAFE | (access), \
ptr, val, sysctl_handle_bool, "CU", descr); \
CTASSERT(((access) & CTLTYPE) == 0 && \
sizeof(bool) == sizeof(*(ptr)))
#define SYSCTL_ADD_BOOL(ctx, parent, nbr, name, access, ptr, val, descr) \
({ \
bool *__ptr = (ptr); \
CTASSERT(((access) & CTLTYPE) == 0); \
sysctl_add_oid(ctx, parent, nbr, name, \
CTLTYPE_U8 | CTLFLAG_MPSAFE | (access), \
__ptr, val, sysctl_handle_bool, "CU", __DESCR(descr), \
NULL); \
})
/* Oid for a signed 8-bit int. If ptr is NULL, val is returned. */
#define SYSCTL_NULL_S8_PTR ((int8_t *)NULL)
#define SYSCTL_S8(parent, nbr, name, access, ptr, val, descr) \
SYSCTL_OID(parent, nbr, name, \
CTLTYPE_S8 | CTLFLAG_MPSAFE | (access), \
ptr, val, sysctl_handle_8, "C", descr); \
CTASSERT((((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S8) && \
sizeof(int8_t) == sizeof(*(ptr)))
#define SYSCTL_ADD_S8(ctx, parent, nbr, name, access, ptr, val, descr) \
({ \
int8_t *__ptr = (ptr); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S8); \
sysctl_add_oid(ctx, parent, nbr, name, \
CTLTYPE_S8 | CTLFLAG_MPSAFE | (access), \
__ptr, val, sysctl_handle_8, "C", __DESCR(descr), NULL); \
})
/* Oid for an unsigned 8-bit int. If ptr is NULL, val is returned. */
#define SYSCTL_NULL_U8_PTR ((uint8_t *)NULL)
#define SYSCTL_U8(parent, nbr, name, access, ptr, val, descr) \
SYSCTL_OID(parent, nbr, name, \
CTLTYPE_U8 | CTLFLAG_MPSAFE | (access), \
ptr, val, sysctl_handle_8, "CU", descr); \
CTASSERT((((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U8) && \
sizeof(uint8_t) == sizeof(*(ptr)))
#define SYSCTL_ADD_U8(ctx, parent, nbr, name, access, ptr, val, descr) \
({ \
uint8_t *__ptr = (ptr); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U8); \
sysctl_add_oid(ctx, parent, nbr, name, \
CTLTYPE_U8 | CTLFLAG_MPSAFE | (access), \
__ptr, val, sysctl_handle_8, "CU", __DESCR(descr), NULL); \
})
/* Oid for a signed 16-bit int. If ptr is NULL, val is returned. */
#define SYSCTL_NULL_S16_PTR ((int16_t *)NULL)
#define SYSCTL_S16(parent, nbr, name, access, ptr, val, descr) \
SYSCTL_OID(parent, nbr, name, \
CTLTYPE_S16 | CTLFLAG_MPSAFE | (access), \
ptr, val, sysctl_handle_16, "S", descr); \
CTASSERT((((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S16) && \
sizeof(int16_t) == sizeof(*(ptr)))
#define SYSCTL_ADD_S16(ctx, parent, nbr, name, access, ptr, val, descr) \
({ \
int16_t *__ptr = (ptr); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S16); \
sysctl_add_oid(ctx, parent, nbr, name, \
CTLTYPE_S16 | CTLFLAG_MPSAFE | (access), \
__ptr, val, sysctl_handle_16, "S", __DESCR(descr), NULL); \
})
/* Oid for an unsigned 16-bit int. If ptr is NULL, val is returned. */
#define SYSCTL_NULL_U16_PTR ((uint16_t *)NULL)
#define SYSCTL_U16(parent, nbr, name, access, ptr, val, descr) \
SYSCTL_OID(parent, nbr, name, \
CTLTYPE_U16 | CTLFLAG_MPSAFE | (access), \
ptr, val, sysctl_handle_16, "SU", descr); \
CTASSERT((((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U16) && \
sizeof(uint16_t) == sizeof(*(ptr)))
#define SYSCTL_ADD_U16(ctx, parent, nbr, name, access, ptr, val, descr) \
({ \
uint16_t *__ptr = (ptr); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U16); \
sysctl_add_oid(ctx, parent, nbr, name, \
CTLTYPE_U16 | CTLFLAG_MPSAFE | (access), \
__ptr, val, sysctl_handle_16, "SU", __DESCR(descr), NULL); \
})
/* Oid for a signed 32-bit int. If ptr is NULL, val is returned. */
#define SYSCTL_NULL_S32_PTR ((int32_t *)NULL)
#define SYSCTL_S32(parent, nbr, name, access, ptr, val, descr) \
SYSCTL_OID(parent, nbr, name, \
CTLTYPE_S32 | CTLFLAG_MPSAFE | (access), \
ptr, val, sysctl_handle_32, "I", descr); \
CTASSERT((((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S32) && \
sizeof(int32_t) == sizeof(*(ptr)))
#define SYSCTL_ADD_S32(ctx, parent, nbr, name, access, ptr, val, descr) \
({ \
int32_t *__ptr = (ptr); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S32); \
sysctl_add_oid(ctx, parent, nbr, name, \
CTLTYPE_S32 | CTLFLAG_MPSAFE | (access), \
__ptr, val, sysctl_handle_32, "I", __DESCR(descr), NULL); \
})
/* Oid for an unsigned 32-bit int. If ptr is NULL, val is returned. */
#define SYSCTL_NULL_U32_PTR ((uint32_t *)NULL)
#define SYSCTL_U32(parent, nbr, name, access, ptr, val, descr) \
SYSCTL_OID(parent, nbr, name, \
CTLTYPE_U32 | CTLFLAG_MPSAFE | (access), \
ptr, val, sysctl_handle_32, "IU", descr); \
CTASSERT((((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U32) && \
sizeof(uint32_t) == sizeof(*(ptr)))
#define SYSCTL_ADD_U32(ctx, parent, nbr, name, access, ptr, val, descr) \
({ \
uint32_t *__ptr = (ptr); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U32); \
sysctl_add_oid(ctx, parent, nbr, name, \
CTLTYPE_U32 | CTLFLAG_MPSAFE | (access), \
__ptr, val, sysctl_handle_32, "IU", __DESCR(descr), NULL); \
})
/* Oid for a signed 64-bit int. If ptr is NULL, val is returned. */
#define SYSCTL_NULL_S64_PTR ((int64_t *)NULL)
#define SYSCTL_S64(parent, nbr, name, access, ptr, val, descr) \
SYSCTL_OID(parent, nbr, name, \
CTLTYPE_S64 | CTLFLAG_MPSAFE | (access), \
ptr, val, sysctl_handle_64, "Q", descr); \
CTASSERT((((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64) && \
sizeof(int64_t) == sizeof(*(ptr)))
#define SYSCTL_ADD_S64(ctx, parent, nbr, name, access, ptr, val, descr) \
({ \
int64_t *__ptr = (ptr); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64); \
sysctl_add_oid(ctx, parent, nbr, name, \
CTLTYPE_S64 | CTLFLAG_MPSAFE | (access), \
__ptr, val, sysctl_handle_64, "Q", __DESCR(descr), NULL); \
})
/* Oid for an unsigned 64-bit int. If ptr is NULL, val is returned. */
#define SYSCTL_NULL_U64_PTR ((uint64_t *)NULL)
#define SYSCTL_U64(parent, nbr, name, access, ptr, val, descr) \
SYSCTL_OID(parent, nbr, name, \
CTLTYPE_U64 | CTLFLAG_MPSAFE | (access), \
ptr, val, sysctl_handle_64, "QU", descr); \
CTASSERT((((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64) && \
sizeof(uint64_t) == sizeof(*(ptr)))
#define SYSCTL_ADD_U64(ctx, parent, nbr, name, access, ptr, val, descr) \
({ \
uint64_t *__ptr = (ptr); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64); \
sysctl_add_oid(ctx, parent, nbr, name, \
CTLTYPE_U64 | CTLFLAG_MPSAFE | (access), \
__ptr, val, sysctl_handle_64, "QU", __DESCR(descr), NULL); \
})
/* Oid for an int. If ptr is SYSCTL_NULL_INT_PTR, val is returned. */
#define SYSCTL_NULL_INT_PTR ((int *)NULL)
#define SYSCTL_INT(parent, nbr, name, access, ptr, val, descr) \
SYSCTL_INT_WITH_LABEL(parent, nbr, name, access, ptr, val, descr, NULL)
#define SYSCTL_INT_WITH_LABEL(parent, nbr, name, access, ptr, val, descr, label) \
SYSCTL_OID_WITH_LABEL(parent, nbr, name, \
CTLTYPE_INT | CTLFLAG_MPSAFE | (access), \
ptr, val, sysctl_handle_int, "I", descr, label); \
CTASSERT((((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT) && \
sizeof(int) == sizeof(*(ptr)))
#define SYSCTL_ADD_INT(ctx, parent, nbr, name, access, ptr, val, descr) \
({ \
int *__ptr = (ptr); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT); \
sysctl_add_oid(ctx, parent, nbr, name, \
CTLTYPE_INT | CTLFLAG_MPSAFE | (access), \
__ptr, val, sysctl_handle_int, "I", __DESCR(descr), NULL); \
})
/* Oid for an unsigned int. If ptr is NULL, val is returned. */
#define SYSCTL_NULL_UINT_PTR ((unsigned *)NULL)
#define SYSCTL_UINT(parent, nbr, name, access, ptr, val, descr) \
SYSCTL_OID(parent, nbr, name, \
CTLTYPE_UINT | CTLFLAG_MPSAFE | (access), \
ptr, val, sysctl_handle_int, "IU", descr); \
CTASSERT((((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_UINT) && \
sizeof(unsigned) == sizeof(*(ptr)))
#define SYSCTL_ADD_UINT(ctx, parent, nbr, name, access, ptr, val, descr) \
({ \
unsigned *__ptr = (ptr); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_UINT); \
sysctl_add_oid(ctx, parent, nbr, name, \
CTLTYPE_UINT | CTLFLAG_MPSAFE | (access), \
__ptr, val, sysctl_handle_int, "IU", __DESCR(descr), NULL); \
})
/* Oid for a long. The pointer must be non NULL. */
#define SYSCTL_NULL_LONG_PTR ((long *)NULL)
#define SYSCTL_LONG(parent, nbr, name, access, ptr, val, descr) \
SYSCTL_OID(parent, nbr, name, \
CTLTYPE_LONG | CTLFLAG_MPSAFE | (access), \
ptr, val, sysctl_handle_long, "L", descr); \
CTASSERT((((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_LONG) && \
sizeof(long) == sizeof(*(ptr)))
#define SYSCTL_ADD_LONG(ctx, parent, nbr, name, access, ptr, descr) \
({ \
long *__ptr = (ptr); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_LONG); \
sysctl_add_oid(ctx, parent, nbr, name, \
CTLTYPE_LONG | CTLFLAG_MPSAFE | (access), \
__ptr, 0, sysctl_handle_long, "L", __DESCR(descr), NULL); \
})
/* Oid for an unsigned long. The pointer must be non NULL. */
#define SYSCTL_NULL_ULONG_PTR ((unsigned long *)NULL)
#define SYSCTL_ULONG(parent, nbr, name, access, ptr, val, descr) \
SYSCTL_OID(parent, nbr, name, \
CTLTYPE_ULONG | CTLFLAG_MPSAFE | (access), \
ptr, val, sysctl_handle_long, "LU", descr); \
CTASSERT((((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_ULONG) && \
sizeof(unsigned long) == sizeof(*(ptr)))
#define SYSCTL_ADD_ULONG(ctx, parent, nbr, name, access, ptr, descr) \
({ \
unsigned long *__ptr = (ptr); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_ULONG); \
sysctl_add_oid(ctx, parent, nbr, name, \
CTLTYPE_ULONG | CTLFLAG_MPSAFE | (access), \
__ptr, 0, sysctl_handle_long, "LU", __DESCR(descr), NULL); \
})
/* Oid for a quad. The pointer must be non NULL. */
#define SYSCTL_NULL_QUAD_PTR ((int64_t *)NULL)
#define SYSCTL_QUAD(parent, nbr, name, access, ptr, val, descr) \
SYSCTL_OID(parent, nbr, name, \
CTLTYPE_S64 | CTLFLAG_MPSAFE | (access), \
ptr, val, sysctl_handle_64, "Q", descr); \
CTASSERT((((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64) && \
sizeof(int64_t) == sizeof(*(ptr)))
#define SYSCTL_ADD_QUAD(ctx, parent, nbr, name, access, ptr, descr) \
({ \
int64_t *__ptr = (ptr); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64); \
sysctl_add_oid(ctx, parent, nbr, name, \
CTLTYPE_S64 | CTLFLAG_MPSAFE | (access), \
__ptr, 0, sysctl_handle_64, "Q", __DESCR(descr), NULL); \
})
#define SYSCTL_NULL_UQUAD_PTR ((uint64_t *)NULL)
#define SYSCTL_UQUAD(parent, nbr, name, access, ptr, val, descr) \
SYSCTL_OID(parent, nbr, name, \
CTLTYPE_U64 | CTLFLAG_MPSAFE | (access), \
ptr, val, sysctl_handle_64, "QU", descr); \
CTASSERT((((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64) && \
sizeof(uint64_t) == sizeof(*(ptr)))
#define SYSCTL_ADD_UQUAD(ctx, parent, nbr, name, access, ptr, descr) \
({ \
uint64_t *__ptr = (ptr); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64); \
sysctl_add_oid(ctx, parent, nbr, name, \
CTLTYPE_U64 | CTLFLAG_MPSAFE | (access), \
__ptr, 0, sysctl_handle_64, "QU", __DESCR(descr), NULL); \
})
/* Oid for a CPU dependent variable */
#define SYSCTL_ADD_UAUTO(ctx, parent, nbr, name, access, ptr, descr) \
({ \
struct sysctl_oid *__ret; \
CTASSERT((sizeof(uint64_t) == sizeof(*(ptr)) || \
sizeof(unsigned) == sizeof(*(ptr))) && \
((access) & CTLTYPE) == 0); \
if (sizeof(uint64_t) == sizeof(*(ptr))) { \
__ret = sysctl_add_oid(ctx, parent, nbr, name, \
CTLTYPE_U64 | CTLFLAG_MPSAFE | (access), \
(ptr), 0, sysctl_handle_64, "QU", \
__DESCR(descr), NULL); \
} else { \
__ret = sysctl_add_oid(ctx, parent, nbr, name, \
CTLTYPE_UINT | CTLFLAG_MPSAFE | (access), \
(ptr), 0, sysctl_handle_int, "IU", \
__DESCR(descr), NULL); \
} \
__ret; \
})
/* Oid for a 64-bit unsigned counter(9). The pointer must be non NULL. */
#define SYSCTL_COUNTER_U64(parent, nbr, name, access, ptr, descr) \
SYSCTL_OID(parent, nbr, name, \
CTLTYPE_U64 | CTLFLAG_MPSAFE | CTLFLAG_STATS | (access), \
(ptr), 0, sysctl_handle_counter_u64, "QU", descr); \
CTASSERT((((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64) && \
sizeof(counter_u64_t) == sizeof(*(ptr)) && \
sizeof(uint64_t) == sizeof(**(ptr)))
#define SYSCTL_ADD_COUNTER_U64(ctx, parent, nbr, name, access, ptr, descr) \
({ \
counter_u64_t *__ptr = (ptr); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64); \
sysctl_add_oid(ctx, parent, nbr, name, \
CTLTYPE_U64 | CTLFLAG_MPSAFE | CTLFLAG_STATS | (access), \
__ptr, 0, sysctl_handle_counter_u64, "QU", __DESCR(descr), \
NULL); \
})
/* Oid for an array of counter(9)s. The pointer and length must be non zero. */
#define SYSCTL_COUNTER_U64_ARRAY(parent, nbr, name, access, ptr, len, descr) \
SYSCTL_OID(parent, nbr, name, \
CTLTYPE_OPAQUE | CTLFLAG_MPSAFE | CTLFLAG_STATS | (access), \
(ptr), (len), sysctl_handle_counter_u64_array, "S", descr); \
CTASSERT((((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE) && \
sizeof(counter_u64_t) == sizeof(*(ptr)) && \
sizeof(uint64_t) == sizeof(**(ptr)))
#define SYSCTL_ADD_COUNTER_U64_ARRAY(ctx, parent, nbr, name, access, \
ptr, len, descr) \
({ \
counter_u64_t *__ptr = (ptr); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE); \
sysctl_add_oid(ctx, parent, nbr, name, \
CTLTYPE_OPAQUE | CTLFLAG_MPSAFE | CTLFLAG_STATS | (access), \
__ptr, len, sysctl_handle_counter_u64_array, "S", \
__DESCR(descr), NULL); \
})
/* Oid for an opaque object. Specified by a pointer and a length. */
#define SYSCTL_OPAQUE(parent, nbr, name, access, ptr, len, fmt, descr) \
SYSCTL_OID(parent, nbr, name, \
CTLTYPE_OPAQUE | CTLFLAG_MPSAFE | (access), \
ptr, len, sysctl_handle_opaque, fmt, descr); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE)
#define SYSCTL_ADD_OPAQUE(ctx, parent, nbr, name, access, ptr, len, fmt, descr) \
({ \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE); \
sysctl_add_oid(ctx, parent, nbr, name, \
CTLTYPE_OPAQUE | CTLFLAG_MPSAFE | (access), \
ptr, len, sysctl_handle_opaque, fmt, __DESCR(descr), NULL); \
})
/* Oid for a struct. Specified by a pointer and a type. */
#define SYSCTL_STRUCT(parent, nbr, name, access, ptr, type, descr) \
SYSCTL_OID(parent, nbr, name, \
CTLTYPE_OPAQUE | CTLFLAG_MPSAFE | (access), \
ptr, sizeof(struct type), sysctl_handle_opaque, \
"S," #type, descr); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE)
#define SYSCTL_ADD_STRUCT(ctx, parent, nbr, name, access, ptr, type, descr) \
({ \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE); \
sysctl_add_oid(ctx, parent, nbr, name, \
CTLTYPE_OPAQUE | CTLFLAG_MPSAFE | (access), \
(ptr), sizeof(struct type), \
sysctl_handle_opaque, "S," #type, __DESCR(descr), NULL); \
})
/* Oid for a procedure. Specified by a pointer and an arg. */
#define SYSCTL_PROC(parent, nbr, name, access, ptr, arg, handler, fmt, descr) \
SYSCTL_OID(parent, nbr, name, (access), \
ptr, arg, handler, fmt, descr); \
CTASSERT(((access) & CTLTYPE) != 0)
#define SYSCTL_ADD_PROC(ctx, parent, nbr, name, access, ptr, arg, handler, fmt, descr) \
({ \
CTASSERT(((access) & CTLTYPE) != 0); \
SYSCTL_ENFORCE_FLAGS(access); \
sysctl_add_oid(ctx, parent, nbr, name, (access), \
(ptr), (arg), (handler), (fmt), __DESCR(descr), NULL); \
})
/* Oid to handle limits on uma(9) zone specified by pointer. */
#define SYSCTL_UMA_MAX(parent, nbr, name, access, ptr, descr) \
SYSCTL_OID(parent, nbr, name, \
CTLTYPE_INT | CTLFLAG_MPSAFE | (access), \
(ptr), 0, sysctl_handle_uma_zone_max, "I", descr); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT)
#define SYSCTL_ADD_UMA_MAX(ctx, parent, nbr, name, access, ptr, descr) \
({ \
uma_zone_t __ptr = (ptr); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT); \
sysctl_add_oid(ctx, parent, nbr, name, \
CTLTYPE_INT | CTLFLAG_MPSAFE | (access), \
__ptr, 0, sysctl_handle_uma_zone_max, "I", __DESCR(descr), \
NULL); \
})
/* Oid to obtain current use of uma(9) zone specified by pointer. */
#define SYSCTL_UMA_CUR(parent, nbr, name, access, ptr, descr) \
SYSCTL_OID(parent, nbr, name, \
CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access), \
(ptr), 0, sysctl_handle_uma_zone_cur, "I", descr); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT)
#define SYSCTL_ADD_UMA_CUR(ctx, parent, nbr, name, access, ptr, descr) \
({ \
uma_zone_t __ptr = (ptr); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT); \
sysctl_add_oid(ctx, parent, nbr, name, \
CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access), \
__ptr, 0, sysctl_handle_uma_zone_cur, "I", __DESCR(descr), \
NULL); \
})
/* OID expressing a sbintime_t as microseconds */
#define SYSCTL_SBINTIME_USEC(parent, nbr, name, access, ptr, descr) \
SYSCTL_OID(parent, nbr, name, \
CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access), \
(ptr), 0, sysctl_usec_to_sbintime, "Q", descr); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64)
#define SYSCTL_ADD_SBINTIME_USEC(ctx, parent, nbr, name, access, ptr, descr) \
({ \
sbintime_t *__ptr = (ptr); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64); \
sysctl_add_oid(ctx, parent, nbr, name, \
CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access), \
__ptr, 0, sysctl_usec_to_sbintime, "Q", __DESCR(descr), \
NULL); \
})
/* OID expressing a sbintime_t as milliseconds */
#define SYSCTL_SBINTIME_MSEC(parent, nbr, name, access, ptr, descr) \
SYSCTL_OID(parent, nbr, name, \
CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access), \
(ptr), 0, sysctl_msec_to_sbintime, "Q", descr); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64)
#define SYSCTL_ADD_SBINTIME_MSEC(ctx, parent, nbr, name, access, ptr, descr) \
({ \
sbintime_t *__ptr = (ptr); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64); \
sysctl_add_oid(ctx, parent, nbr, name, \
CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access), \
__ptr, 0, sysctl_msec_to_sbintime, "Q", __DESCR(descr), \
NULL); \
})
/* OID expressing a struct timeval as seconds */
#define SYSCTL_TIMEVAL_SEC(parent, nbr, name, access, ptr, descr) \
SYSCTL_OID(parent, nbr, name, \
CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access), \
(ptr), 0, sysctl_sec_to_timeval, "I", descr); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT)
#define SYSCTL_ADD_TIMEVAL_SEC(ctx, parent, nbr, name, access, ptr, descr) \
({ \
struct timeval *__ptr = (ptr); \
CTASSERT(((access) & CTLTYPE) == 0 || \
((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT); \
sysctl_add_oid(ctx, parent, nbr, name, \
CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access), \
__ptr, 0, sysctl_sec_to_timeval, "I", __DESCR(descr), \
NULL); \
})
/*
* A macro to generate a read-only sysctl to indicate the presence of optional
* kernel features.
*/
#define FEATURE(name, desc) \
SYSCTL_INT_WITH_LABEL(_kern_features, OID_AUTO, name, \
CTLFLAG_RD | CTLFLAG_CAPRD, SYSCTL_NULL_INT_PTR, 1, desc, "feature")
#endif /* _KERNEL */
/*
* Top-level identifiers
*/
#define CTL_SYSCTL 0 /* "magic" numbers */
#define CTL_KERN 1 /* "high kernel": proc, limits */
#define CTL_VM 2 /* virtual memory */
#define CTL_VFS 3 /* filesystem, mount type is next */
#define CTL_NET 4 /* network, see socket.h */
#define CTL_DEBUG 5 /* debugging parameters */
#define CTL_HW 6 /* generic cpu/io */
#define CTL_MACHDEP 7 /* machine dependent */
#define CTL_USER 8 /* user-level */
#define CTL_P1003_1B 9 /* POSIX 1003.1B */
/*
* CTL_SYSCTL identifiers
*/
#define CTL_SYSCTL_DEBUG 0 /* printf all nodes */
#define CTL_SYSCTL_NAME 1 /* string name of OID */
#define CTL_SYSCTL_NEXT 2 /* next OID, honoring CTLFLAG_SKIP */
#define CTL_SYSCTL_NAME2OID 3 /* int array of name */
#define CTL_SYSCTL_OIDFMT 4 /* OID's kind and format */
#define CTL_SYSCTL_OIDDESCR 5 /* OID's description */
#define CTL_SYSCTL_OIDLABEL 6 /* aggregation label */
#define CTL_SYSCTL_NEXTNOSKIP 7 /* next OID, ignoring CTLFLAG_SKIP */
/*
* CTL_KERN identifiers
*/
#define KERN_OSTYPE 1 /* string: system version */
#define KERN_OSRELEASE 2 /* string: system release */
#define KERN_OSREV 3 /* int: system revision */
#define KERN_VERSION 4 /* string: compile time info */
#define KERN_MAXVNODES 5 /* int: max vnodes */
#define KERN_MAXPROC 6 /* int: max processes */
#define KERN_MAXFILES 7 /* int: max open files */
#define KERN_ARGMAX 8 /* int: max arguments to exec */
#define KERN_SECURELVL 9 /* int: system security level */
#define KERN_HOSTNAME 10 /* string: hostname */
#define KERN_HOSTID 11 /* int: host identifier */
#define KERN_CLOCKRATE 12 /* struct: struct clockrate */
#define KERN_VNODE 13 /* struct: vnode structures */
#define KERN_PROC 14 /* struct: process entries */
#define KERN_FILE 15 /* struct: file entries */
#define KERN_PROF 16 /* node: kernel profiling info */
#define KERN_POSIX1 17 /* int: POSIX.1 version */
#define KERN_NGROUPS 18 /* int: # of supplemental group ids */
#define KERN_JOB_CONTROL 19 /* int: is job control available */
#define KERN_SAVED_IDS 20 /* int: saved set-user/group-ID */
#define KERN_BOOTTIME 21 /* struct: time kernel was booted */
#define KERN_NISDOMAINNAME 22 /* string: YP domain name */
#define KERN_UPDATEINTERVAL 23 /* int: update process sleep time */
#define KERN_OSRELDATE 24 /* int: kernel release date */
#define KERN_NTP_PLL 25 /* node: NTP PLL control */
#define KERN_BOOTFILE 26 /* string: name of booted kernel */
#define KERN_MAXFILESPERPROC 27 /* int: max open files per proc */
#define KERN_MAXPROCPERUID 28 /* int: max processes per uid */
#define KERN_DUMPDEV 29 /* struct cdev *: device to dump on */
#define KERN_IPC 30 /* node: anything related to IPC */
#define KERN_DUMMY 31 /* unused */
#define KERN_PS_STRINGS 32 /* int: address of PS_STRINGS */
#define KERN_USRSTACK 33 /* int: address of USRSTACK */
#define KERN_LOGSIGEXIT 34 /* int: do we log sigexit procs? */
#define KERN_IOV_MAX 35 /* int: value of UIO_MAXIOV */
#define KERN_HOSTUUID 36 /* string: host UUID identifier */
#define KERN_ARND 37 /* int: from arc4rand() */
#define KERN_MAXPHYS 38 /* int: MAXPHYS value */
#define KERN_LOCKF 39 /* struct: lockf reports */
/*
* KERN_PROC subtypes
*/
#define KERN_PROC_ALL 0 /* everything */
#define KERN_PROC_PID 1 /* by process id */
#define KERN_PROC_PGRP 2 /* by process group id */
#define KERN_PROC_SESSION 3 /* by session of pid */
#define KERN_PROC_TTY 4 /* by controlling tty */
#define KERN_PROC_UID 5 /* by effective uid */
#define KERN_PROC_RUID 6 /* by real uid */
#define KERN_PROC_ARGS 7 /* get/set arguments/proctitle */
#define KERN_PROC_PROC 8 /* only return procs */
#define KERN_PROC_SV_NAME 9 /* get syscall vector name */
#define KERN_PROC_RGID 10 /* by real group id */
#define KERN_PROC_GID 11 /* by effective group id */
#define KERN_PROC_PATHNAME 12 /* path to executable */
#define KERN_PROC_OVMMAP 13 /* Old VM map entries for process */
#define KERN_PROC_OFILEDESC 14 /* Old file descriptors for process */
#define KERN_PROC_KSTACK 15 /* Kernel stacks for process */
#define KERN_PROC_INC_THREAD 0x10 /*
* modifier for pid, pgrp, tty,
* uid, ruid, gid, rgid and proc
* This effectively uses 16-31
*/
#define KERN_PROC_VMMAP 32 /* VM map entries for process */
#define KERN_PROC_FILEDESC 33 /* File descriptors for process */
#define KERN_PROC_GROUPS 34 /* process groups */
#define KERN_PROC_ENV 35 /* get environment */
#define KERN_PROC_AUXV 36 /* get ELF auxiliary vector */
#define KERN_PROC_RLIMIT 37 /* process resource limits */
#define KERN_PROC_PS_STRINGS 38 /* get ps_strings location */
#define KERN_PROC_UMASK 39 /* process umask */
#define KERN_PROC_OSREL 40 /* osreldate for process binary */
#define KERN_PROC_SIGTRAMP 41 /* signal trampoline location */
#define KERN_PROC_CWD 42 /* process current working directory */
#define KERN_PROC_NFDS 43 /* number of open file descriptors */
#define KERN_PROC_SIGFASTBLK 44 /* address of fastsigblk magic word */
#define KERN_PROC_VM_LAYOUT 45 /* virtual address space layout info */
/*
* KERN_IPC identifiers
*/
#define KIPC_MAXSOCKBUF 1 /* int: max size of a socket buffer */
#define KIPC_SOCKBUF_WASTE 2 /* int: wastage factor in sockbuf */
#define KIPC_SOMAXCONN 3 /* int: max length of connection q */
#define KIPC_MAX_LINKHDR 4 /* int: max length of link header */
#define KIPC_MAX_PROTOHDR 5 /* int: max length of network header */
#define KIPC_MAX_HDR 6 /* int: max total length of headers */
#define KIPC_MAX_DATALEN 7 /* int: max length of data? */
/*
* CTL_HW identifiers
*/
#define HW_MACHINE 1 /* string: machine class */
#define HW_MODEL 2 /* string: specific machine model */
#define HW_NCPU 3 /* int: number of cpus */
#define HW_BYTEORDER 4 /* int: machine byte order */
#define HW_PHYSMEM 5 /* int: total memory */
#define HW_USERMEM 6 /* int: non-kernel memory */
#define HW_PAGESIZE 7 /* int: software page size */
#define HW_DISKNAMES 8 /* strings: disk drive names */
#define HW_DISKSTATS 9 /* struct: diskstats[] */
#define HW_FLOATINGPT 10 /* int: has HW floating point? */
#define HW_MACHINE_ARCH 11 /* string: machine architecture */
#define HW_REALMEM 12 /* int: 'real' memory */
/*
* CTL_USER definitions
*/
#define USER_CS_PATH 1 /* string: _CS_PATH */
#define USER_BC_BASE_MAX 2 /* int: BC_BASE_MAX */
#define USER_BC_DIM_MAX 3 /* int: BC_DIM_MAX */
#define USER_BC_SCALE_MAX 4 /* int: BC_SCALE_MAX */
#define USER_BC_STRING_MAX 5 /* int: BC_STRING_MAX */
#define USER_COLL_WEIGHTS_MAX 6 /* int: COLL_WEIGHTS_MAX */
#define USER_EXPR_NEST_MAX 7 /* int: EXPR_NEST_MAX */
#define USER_LINE_MAX 8 /* int: LINE_MAX */
#define USER_RE_DUP_MAX 9 /* int: RE_DUP_MAX */
#define USER_POSIX2_VERSION 10 /* int: POSIX2_VERSION */
#define USER_POSIX2_C_BIND 11 /* int: POSIX2_C_BIND */
#define USER_POSIX2_C_DEV 12 /* int: POSIX2_C_DEV */
#define USER_POSIX2_CHAR_TERM 13 /* int: POSIX2_CHAR_TERM */
#define USER_POSIX2_FORT_DEV 14 /* int: POSIX2_FORT_DEV */
#define USER_POSIX2_FORT_RUN 15 /* int: POSIX2_FORT_RUN */
#define USER_POSIX2_LOCALEDEF 16 /* int: POSIX2_LOCALEDEF */
#define USER_POSIX2_SW_DEV 17 /* int: POSIX2_SW_DEV */
#define USER_POSIX2_UPE 18 /* int: POSIX2_UPE */
#define USER_STREAM_MAX 19 /* int: POSIX2_STREAM_MAX */
#define USER_TZNAME_MAX 20 /* int: POSIX2_TZNAME_MAX */
#define USER_LOCALBASE 21 /* string: _PATH_LOCALBASE */
#define CTL_P1003_1B_ASYNCHRONOUS_IO 1 /* boolean */
#define CTL_P1003_1B_MAPPED_FILES 2 /* boolean */
#define CTL_P1003_1B_MEMLOCK 3 /* boolean */
#define CTL_P1003_1B_MEMLOCK_RANGE 4 /* boolean */
#define CTL_P1003_1B_MEMORY_PROTECTION 5 /* boolean */
#define CTL_P1003_1B_MESSAGE_PASSING 6 /* boolean */
#define CTL_P1003_1B_PRIORITIZED_IO 7 /* boolean */
#define CTL_P1003_1B_PRIORITY_SCHEDULING 8 /* boolean */
#define CTL_P1003_1B_REALTIME_SIGNALS 9 /* boolean */
#define CTL_P1003_1B_SEMAPHORES 10 /* boolean */
#define CTL_P1003_1B_FSYNC 11 /* boolean */
#define CTL_P1003_1B_SHARED_MEMORY_OBJECTS 12 /* boolean */
#define CTL_P1003_1B_SYNCHRONIZED_IO 13 /* boolean */
#define CTL_P1003_1B_TIMERS 14 /* boolean */
#define CTL_P1003_1B_AIO_LISTIO_MAX 15 /* int */
#define CTL_P1003_1B_AIO_MAX 16 /* int */
#define CTL_P1003_1B_AIO_PRIO_DELTA_MAX 17 /* int */
#define CTL_P1003_1B_DELAYTIMER_MAX 18 /* int */
#define CTL_P1003_1B_MQ_OPEN_MAX 19 /* int */
#define CTL_P1003_1B_PAGESIZE 20 /* int */
#define CTL_P1003_1B_RTSIG_MAX 21 /* int */
#define CTL_P1003_1B_SEM_NSEMS_MAX 22 /* int */
#define CTL_P1003_1B_SEM_VALUE_MAX 23 /* int */
#define CTL_P1003_1B_SIGQUEUE_MAX 24 /* int */
#define CTL_P1003_1B_TIMER_MAX 25 /* int */
#ifdef _KERNEL
#define CTL_P1003_1B_MAXID 26
/*
* Declare some common oids.
*/
extern struct sysctl_oid_list sysctl__children;
SYSCTL_DECL(_kern);
SYSCTL_DECL(_kern_features);
SYSCTL_DECL(_kern_ipc);
SYSCTL_DECL(_kern_proc);
SYSCTL_DECL(_kern_sched);
SYSCTL_DECL(_kern_sched_stats);
SYSCTL_DECL(_sysctl);
SYSCTL_DECL(_vm);
SYSCTL_DECL(_vm_stats);
SYSCTL_DECL(_vm_stats_misc);
SYSCTL_DECL(_vfs);
SYSCTL_DECL(_net);
SYSCTL_DECL(_debug);
SYSCTL_DECL(_debug_sizeof);
SYSCTL_DECL(_dev);
SYSCTL_DECL(_hw);
SYSCTL_DECL(_hw_bus);
SYSCTL_DECL(_hw_bus_devices);
SYSCTL_DECL(_machdep);
SYSCTL_DECL(_machdep_mitigations);
SYSCTL_DECL(_user);
SYSCTL_DECL(_compat);
SYSCTL_DECL(_regression);
SYSCTL_DECL(_security);
SYSCTL_DECL(_security_bsd);
extern char machine[];
extern char osrelease[];
extern char ostype[];
extern char kern_ident[];
/* Dynamic oid handling */
struct sysctl_oid *sysctl_add_oid(struct sysctl_ctx_list *clist,
struct sysctl_oid_list *parent, int nbr, const char *name, int kind,
void *arg1, intmax_t arg2, int (*handler)(SYSCTL_HANDLER_ARGS),
const char *fmt, const char *descr, const char *label);
int sysctl_remove_name(struct sysctl_oid *parent, const char *name, int del,
int recurse);
void sysctl_rename_oid(struct sysctl_oid *oidp, const char *name);
int sysctl_move_oid(struct sysctl_oid *oidp,
struct sysctl_oid_list *parent);
int sysctl_remove_oid(struct sysctl_oid *oidp, int del, int recurse);
int sysctl_ctx_init(struct sysctl_ctx_list *clist);
int sysctl_ctx_free(struct sysctl_ctx_list *clist);
struct sysctl_ctx_entry *sysctl_ctx_entry_add(struct sysctl_ctx_list *clist,
struct sysctl_oid *oidp);
struct sysctl_ctx_entry *sysctl_ctx_entry_find(struct sysctl_ctx_list *clist,
struct sysctl_oid *oidp);
int sysctl_ctx_entry_del(struct sysctl_ctx_list *clist,
struct sysctl_oid *oidp);
int kernel_sysctl(struct thread *td, int *name, u_int namelen, void *old,
size_t *oldlenp, void *new, size_t newlen, size_t *retval,
int flags);
int kernel_sysctlbyname(struct thread *td, char *name, void *old,
size_t *oldlenp, void *new, size_t newlen, size_t *retval,
int flags);
int userland_sysctl(struct thread *td, int *name, u_int namelen, void *old,
size_t *oldlenp, int inkernel, const void *new, size_t newlen,
size_t *retval, int flags);
int sysctl_find_oid(int *name, u_int namelen, struct sysctl_oid **noid,
int *nindx, struct sysctl_req *req);
void sysctl_wlock(void);
void sysctl_wunlock(void);
int sysctl_wire_old_buffer(struct sysctl_req *req, size_t len);
int kern___sysctlbyname(struct thread *td, const char *name,
size_t namelen, void *old, size_t *oldlenp, void *new,
size_t newlen, size_t *retval, int flags, bool inkernel);
struct sbuf;
struct sbuf *sbuf_new_for_sysctl(struct sbuf *, char *, int,
struct sysctl_req *);
#else /* !_KERNEL */
#include <sys/cdefs.h>
#include <sys/_types.h>
#ifndef _SIZE_T_DECLARED
typedef __size_t size_t;
#define _SIZE_T_DECLARED
#endif
__BEGIN_DECLS
int sysctl(const int *, unsigned int, void *, size_t *, const void *, size_t);
int sysctlbyname(const char *, void *, size_t *, const void *, size_t);
int sysctlnametomib(const char *, int *, size_t *);
__END_DECLS
#endif /* _KERNEL */
#endif /* !_SYS_SYSCTL_H_ */

File Metadata

Mime Type
text/x-diff
Expires
Fri, Feb 21, 9:01 PM (10 h, 9 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
16744953
Default Alt Text
(163 KB)

Event Timeline