diff options
author | Hans Petter Selasky <hselasky@FreeBSD.org> | 2022-09-27 13:48:16 +0000 |
---|---|---|
committer | Hans Petter Selasky <hselasky@FreeBSD.org> | 2022-09-27 17:21:21 +0000 |
commit | c075ea46bca6d48ce9f639e4575077d06d392427 (patch) | |
tree | 0442813f5e716162e0d4adafa2bb5897942bce2f | |
parent | f2963b530e17c5eff66bc5f4860b1cd224d3d033 (diff) | |
download | src-c075ea46bca6d48ce9f639e4575077d06d392427.tar.gz src-c075ea46bca6d48ce9f639e4575077d06d392427.zip |
sysctl(3): Implement SYSCTL_FOREACH() to iterate all OIDs in a sysctl list.
To avoid using the sysctl list macros directly in external kernel modules.
Reviewed by: asomers, manu and asiciliano
Differential Revision: https://reviews.freebsd.org/D36748
MFC after: 1 week
Sponsored by: NVIDIA Networking
-rw-r--r-- | sys/kern/kern_sysctl.c | 6 | ||||
-rw-r--r-- | sys/sys/sysctl.h | 3 |
2 files changed, 6 insertions, 3 deletions
diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index e1cd6ea4bd61..1a3fcbbf8ae0 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -136,7 +136,7 @@ sysctl_find_oidname(const char *name, struct sysctl_oid_list *list) struct sysctl_oid *oidp; SYSCTL_ASSERT_LOCKED(); - RB_FOREACH(oidp, sysctl_oid_list, list) { + SYSCTL_FOREACH(oidp, list) { if (strcmp(oidp->oid_name, name) == 0) { return (oidp); } @@ -1005,7 +1005,7 @@ sysctl_sysctl_debug_dump_node(struct sysctl_oid_list *l, int i) struct sysctl_oid *oidp; SYSCTL_ASSERT_LOCKED(); - RB_FOREACH(oidp, sysctl_oid_list, l) { + SYSCTL_FOREACH(oidp, l) { for (k=0; k<i; k++) printf(" "); @@ -1327,7 +1327,7 @@ name2oid(char *name, int *oid, int *len, struct sysctl_oid **oidpp) for (*len = 0; *len < CTL_MAXNAME;) { p = strsep(&name, "."); - RB_FOREACH(oidp, sysctl_oid_list, lsp) { + SYSCTL_FOREACH(oidp, lsp) { if (strcmp(p, oidp->oid_name) == 0) break; } diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h index 3bd77cf87243..040012581087 100644 --- a/sys/sys/sysctl.h +++ b/sys/sys/sysctl.h @@ -918,6 +918,9 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); NULL); \ }) +#define SYSCTL_FOREACH(oidp, list) \ + RB_FOREACH(oidp, sysctl_oid_list, list) + /* * A macro to generate a read-only sysctl to indicate the presence of optional * kernel features. |