aboutsummaryrefslogtreecommitdiff
path: root/sys/sys/sysctl.h
diff options
context:
space:
mode:
authorHans Petter Selasky <hselasky@FreeBSD.org>2014-06-28 03:56:17 +0000
committerHans Petter Selasky <hselasky@FreeBSD.org>2014-06-28 03:56:17 +0000
commitaf3b2549c4ba2ef00a7cbb4cb6836598bf0aefbe (patch)
tree2ebc46d89e79d747fa284f379b1979658216c719 /sys/sys/sysctl.h
parentb152235544f6d8515906c119c210fbd77827b511 (diff)
downloadsrc-af3b2549c4ba2ef00a7cbb4cb6836598bf0aefbe.tar.gz
src-af3b2549c4ba2ef00a7cbb4cb6836598bf0aefbe.zip
Pull in r267961 and r267973 again. Fix for issues reported will follow.
Notes
Notes: svn path=/head/; revision=267992
Diffstat (limited to 'sys/sys/sysctl.h')
-rw-r--r--sys/sys/sysctl.h56
1 files changed, 39 insertions, 17 deletions
diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h
index 02faa934bef2..0473eb72ebb1 100644
--- a/sys/sys/sysctl.h
+++ b/sys/sys/sysctl.h
@@ -83,7 +83,7 @@ struct ctlname {
#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 /* Tunable variable */
+#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 */
@@ -92,6 +92,7 @@ struct ctlname {
#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)
/*
@@ -161,6 +162,7 @@ SLIST_HEAD(sysctl_oid_list, sysctl_oid);
* 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;
int oid_number;
@@ -200,14 +202,16 @@ void sysctl_register_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_list sysctl_##name##_children
+#define SYSCTL_DECL(name) \
+ extern struct sysctl_oid sysctl__##name
/* Hide these in macros. */
-#define SYSCTL_CHILDREN(oid_ptr) \
- (struct sysctl_oid_list *)(oid_ptr)->oid_arg1
-#define SYSCTL_CHILDREN_SET(oid_ptr, val) (oid_ptr)->oid_arg1 = (val)
-#define SYSCTL_STATIC_CHILDREN(oid_name) (&sysctl_##oid_name##_children)
+#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. === */
@@ -220,7 +224,7 @@ struct sysctl_ctx_entry {
TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry);
#define SYSCTL_NODE_CHILDREN(parent, name) \
- sysctl_##parent##_##name##_children
+ sysctl__##parent##_##name.oid_children
/*
* These macros provide type safety for sysctls. SYSCTL_ALLOWED_TYPES()
@@ -275,29 +279,47 @@ SYSCTL_ALLOWED_TYPES(UINT64, uint64_t *a; unsigned long long *b; );
#define __DESCR(d) ""
#endif
-/* This constructs a "raw" MIB oid. */
-#define SYSCTL_OID(parent, nbr, name, kind, a1, a2, handler, fmt, descr)\
- static struct sysctl_oid sysctl__##parent##_##name = { \
- .oid_parent = &sysctl_##parent##_children, \
+/* This macro is only for internal use */
+#define SYSCTL_OID_RAW(id, parent_child_head, nbr, name, kind, a1, a2, handler, fmt, descr) \
+ struct sysctl_oid id = { \
+ .oid_parent = (parent_child_head), \
+ .oid_children = SLIST_HEAD_INITIALIZER(&id.oid_children), \
.oid_number = (nbr), \
.oid_kind = (kind), \
.oid_arg1 = (a1), \
.oid_arg2 = (a2), \
- .oid_name = #name, \
+ .oid_name = (name), \
.oid_handler = (handler), \
.oid_fmt = (fmt), \
.oid_descr = __DESCR(descr) \
}; \
- DATA_SET(sysctl_set, sysctl__##parent##_##name)
+ DATA_SET(sysctl_set, id)
+
+/* This constructs a static "raw" MIB oid. */
+#define SYSCTL_OID(parent, nbr, name, kind, a1, a2, handler, fmt, descr) \
+ static SYSCTL_OID_RAW(sysctl__##parent##_##name, \
+ SYSCTL_CHILDREN(&sysctl__##parent), \
+ nbr, #name, kind, a1, a2, handler, fmt, descr)
+
+/* This constructs a global "raw" MIB oid. */
+#define SYSCTL_OID_GLOBAL(parent, nbr, name, kind, a1, a2, handler, fmt, descr) \
+ SYSCTL_OID_RAW(sysctl__##parent##_##name, \
+ SYSCTL_CHILDREN(&sysctl__##parent), \
+ nbr, #name, kind, a1, a2, handler, fmt, descr)
#define SYSCTL_ADD_OID(ctx, parent, nbr, name, kind, a1, a2, handler, fmt, descr) \
sysctl_add_oid(ctx, parent, nbr, name, kind, a1, a2, handler, fmt, __DESCR(descr))
+/* 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)
+
/* This constructs a node from which other oids can hang. */
#define SYSCTL_NODE(parent, nbr, name, access, handler, descr) \
- struct sysctl_oid_list SYSCTL_NODE_CHILDREN(parent, name); \
- SYSCTL_OID(parent, nbr, name, CTLTYPE_NODE|(access), \
- (void*)&SYSCTL_NODE_CHILDREN(parent, name), 0, handler, "N", descr)
+ SYSCTL_OID_GLOBAL(parent, nbr, name, CTLTYPE_NODE|(access), \
+ NULL, 0, handler, "N", descr)
#define SYSCTL_ADD_NODE(ctx, parent, nbr, name, access, handler, descr) \
sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_NODE|(access), \