=== sysctl improvements

Links: +
link:https://gitlab.com/alfix/sysctlinfo[sysctlinfo] URL: link:https://gitlab.com/alfix/sysctlinfo[https://gitlab.com/alfix/sysctlinfo] +
link:https://gitlab.com/alfix/sysctlbyname-improved[sysctlbyname-improved] URL: link:https://gitlab.com/alfix/sysctlbyname-improved[https://gitlab.com/alfix/sysctlbyname-improved] +
link:https://git.io/Jm9x7[BSDCan 2020 - sysctlinfo questions] URL: link:https://git.io/Jm9x7[https://git.io/Jm9x7] +
link:https://gitlab.com/alfix/sysctl-libnv[sysctl-libnv] URL:https://gitlab.com/alfix/sysctl-libnv[https://gitlab.com/alfix/sysctl-libnv] +
link:https://gitlab.com/alfix/sysctlmibinfo2[sysctlmibinfo2] URL:https://gitlab.com/alfix/sysctlmibinfo2[https://gitlab.com/alfix/sysctlmibinfo2] +
link:https://gitlab.com/alfix/sysctlview[sysctlview] URL: link:https://gitlab.com/alfix/sysctlview[https://gitlab.com/alfix/sysctlview] +
link:https://gitlab.com/alfix/nsysctl[nsysctl] URL: link:https://gitlab.com/alfix/nsysctl[https://gitlab.com/alfix/nsysctl]

Contact: Alfonso Sabato Siciliano <alfonso.siciliano@email.com>

The sysctl system call and the wrapper sysctl utility can get and set the system state at runtime; the kernel exposes the available parameters as objects of a Management Information Base.
After a recent system update with a CURRENT-GENERIC configuration, the MIB has exceeded ten thousand objects (both internal nodes and leaves, most in the vm.uma subtree) on my laptop with a Desktop environment without ZFS.
Furthermore I received tips, ideas, PRs and issues about sysctl so some improvement has been fulfilled; finally the suggestions received during BSDCan 2020 have been accomplished.

==== Kernel space
link:https://freshports.org/sysutils/sysctlinfo-kmod[sysutils/sysctlinfo] has been updated to 20210222 and is an interface to visit the MIB and to retrieve info about an object (description, type, format, flags, and so on).
It has been refactored so the new version is almost 100% more efficient to explore the MIB and to pass all info about an object to userland.
Moreover new features have been implemented: to get more info about an object, to avoid extra computation in userland, and to improve the compatibilty with the current undocumented interface.

link:https://freshports.org/sysutils/sysctlbyname-improved-kmod[sysutils/sysctlbyname-improved] has been updated to 20210223 and is an extension of sysctlinfo to handle an object name with some empty string level or extended to pass an input to the handler of a CTLTYPE_NODE; it has been updated to take advantage of the improvements (mainly efficiency) of sysctlinfo.

sysctl-libnv is a project that provides an implementation and an example of how to build a sysctl object with an nvlist value - to learn more about nvlist, see the man:libnv[9] manual page.
Properly a new sysctl handler has been defined: it is enough to create a nvlist and to pass it to a macro; then the system call uses the new handler to pass the nvlist to the userland and the nsysctl utility can manage the object value.

The following tools are been updated to give advantages from new kernel features and improvements.

==== Library
link:https://freshports.org/devel/libsysctlmibinfo2[devel/libsysctlmibinfo2] has been updated to 2.0.1; primarily the sysctlmibinfo2 library wraps the low-level interfaces described above; moreover it defines a struct sysctlmif_object with the properties of an object and provides a convenient API to build data structures of sysctlmif_object (for example: a subtree, a list of a list of a Depth First
Traversal, and so on); therefore it is useful for handling an object correctly and/or for building a sysctl-like utility.

Obviously sysctlmibinfo2 benefits from the features of sysctlinfo: handles OIDs up to CTL_MAXNAME levels, supports the Capability Mode, can seek an object matching its name (avoiding having to explore the MIB just to find the corresponding OID), gets all info about an object at a time, and manages a special name via sysctlbyname-improved.

Version 2.0.1 takes advantage from the kernel improvements: improved efficiency to build a sysctlmif_object and new features to get info about an object: "handler" and "nextbyname".
The new functions are: sysctlmif_hashandler() and sysctlmif_hashandlerbyname() to know if an object has a defined kernel handler, sysctlmif_nextnodebyname() and sysctlmif_nextleafbyname() to explore the MIB, sysctlmif_leaves() and sysctlmif_leavesbyname() to build only-leaf data structures.

==== Documentation
The APIs described above (both kernel and userspace) are really easy: "sysctl -aN", "sysctl -d kern.ostype", etc., can be implemented in a few lines of code.
Nevertheless each project provides a README with Introduction, Getting started, Features, API, Real-world use cases, FAQ, and examples in the Public Domain to build new projects.
Of course the manuals and examples have recently been updated.

==== Utilities
link:https://freshports.org/deskutils/sysctlview[deskutils/sysctlview] has been updated to 2.1; the first version of sysctlview was just a graphical representation of the MIB, now it could be considered a GUI version of sysctl.
This utility exploits the object serialization of sysctlinfo; indeed it is not feasible to have the kernel to find the same object many times to retrieve all its properties, considering the current MIB size.
Thanks to user feedbacks the new version provides a better UI, for example clicking a column title to sort the entries, moreover the "Handler" entry is been added in the "Object" window, it is useful to know if an object has a value or if the OID of a CTLTYPE_NODE can be extended.

link:https://freshports.org/sysutils/nsysctl[sysutils/nsysctl] has been updated to 2.0 and is the CLI version of sysctlview; the output is explicitly indicated by the options and is printed via libxo in human- and machine-readable formats; moreover some string value is parsed to display structured output.
The options are not mutually exclusive and allow showing the properties of a parameter so nsysctl is useful to know the info to handle an object without finding its implementation, for example: Is Multiprocessor safe? Is Capability mode available? Is the OID extensible? Does the integer represent a kelvin? Does it have a value? What is the label? And so on.
The new version supports libnv; it is useful to manage a non-primitive data type and could avoid hardcoding a generic opaque type in the future.
Finally the new features of sysctlinfo allow using nsysctl to debug the MIB without a kernel recompilation with SYSCTL_DEBUG.
Note: the project provides a tutorial to describe every feature.
