David van Moolenbroek e4e21ee1b2 Add MIB service, sysctl(2) support
The new MIB service implements the sysctl(2) system call which, as
we adopt more NetBSD code, is an increasingly important part of the
operating system API.  The system call is implemented in the new
service rather than as part of an existing service, because it will
eventually call into many other services in order to gather data,
similar to ProcFS.  Since the sysctl(2) functionality is used even
by init(8), the MIB service is added to the boot image.

MIB stands for Management Information Base, and the MIB service
should be seen as a knowledge base of management information.

The MIB service implementation of the sysctl(2) interface is fairly
complete; it incorporates support for both static and dynamic nodes
and imitates many NetBSD-specific quirks expected by userland.  The
patch also adds trace(1) support for the new system call, and adds
a new test, test87, which tests the fundamental operation of the
MIB service rather thoroughly.

Change-Id: I4766b410b25e94e9cd4affb72244112c2910ff67
2016-01-13 20:32:37 +01:00

74 lines
2.4 KiB
C

/* MIB service - minix.c - implementation of the CTL_MINIX subtree */
#include "mib.h"
#if MINIX_TEST_SUBTREE
static char test_string[16], test_struct[12];
static struct mib_node mib_minix_test_secret_table[] = {
/* 0*/ [SECRET_VALUE] = MIB_INT(_RO, 12345, "value",
"The combination to my luggage"),
};
/*
* Note that even the descriptions here have been chosen such that returned
* description array alignment is tested. Do not change existing fields
* lightly, although adding new fields is always fine.
*/
static struct mib_node mib_minix_test_table[] = {
/* 0*/ [TEST_INT] = MIB_INT(_RO | CTLFLAG_HEX, 0x01020304, "int",
"Value test field"),
/* 1*/ [TEST_BOOL] = MIB_BOOL(_RW, 0, "bool",
"Boolean test field"),
/* 2*/ [TEST_QUAD] = MIB_QUAD(_RW, 0, "quad", "Quad test field"),
/* 3*/ [TEST_STRING] = MIB_STRING(_RW, test_string, "string",
"String test field"),
/* 4*/ [TEST_STRUCT] = MIB_STRUCT(_RW, test_struct, "struct",
"Structure test field"),
/* 5*/ [TEST_PRIVATE] = MIB_INT(_RW | CTLFLAG_PRIVATE, -5375,
"private", "Private test field"),
/* 6*/ [TEST_ANYWRITE] = MIB_INT(_RW | CTLFLAG_ANYWRITE, 0,
"anywrite", "AnyWrite test field"),
/* 7*/ [TEST_DYNAMIC] = MIB_INT(_RO, 0, "deleteme",
"This node will be destroyed"),
/* 8*/ [TEST_SECRET] = MIB_NODE(_RO | CTLFLAG_PRIVATE,
mib_minix_test_secret_table, "secret",
"Private subtree"),
/* 9*/ [TEST_PERM] = MIB_INT(_P | _RO, 1, "permanent", NULL),
/*10*/ [TEST_DESTROY1] = MIB_INT(_RO, 123, "destroy1", NULL),
/*11*/ [TEST_DESTROY2] = MIB_INT(_RO, 456, "destroy2",
"This node will be destroyed"),
};
#endif /* MINIX_TEST_SUBTREE */
static struct mib_node mib_minix_mib_table[] = {
/* 1*/ [MIB_NODES] = MIB_INTPTR(_P | _RO | CTLFLAG_UNSIGNED,
&nodes, "nodes",
"Number of nodes in the MIB tree"),
/* 2*/ [MIB_OBJECTS] = MIB_INTPTR(_P | _RO | CTLFLAG_UNSIGNED,
&objects, "objects", "Number of "
"dynamically allocated MIB objects"),
};
static struct mib_node mib_minix_table[] = {
#if MINIX_TEST_SUBTREE
/* 0*/ [MINIX_TEST] = MIB_NODE(_RW | CTLFLAG_HIDDEN,
mib_minix_test_table, "test",
"Test87 testing ground"),
#endif /* MINIX_TEST_SUBTREE */
/* 1*/ [MINIX_MIB] = MIB_NODE(_P | _RO, mib_minix_mib_table,
"mib", "MIB service information"),
};
/*
* Initialize the CTL_MINIX subtree.
*/
void
mib_minix_init(struct mib_node * node)
{
MIB_INIT_ENODE(node, mib_minix_table);
}