aboutsummaryrefslogtreecommitdiff
path: root/sys/netlink/netlink_module.c
diff options
context:
space:
mode:
authorAlexander V. Chernikov <melifaro@FreeBSD.org>2023-04-28 12:44:04 +0000
committerAlexander V. Chernikov <melifaro@FreeBSD.org>2023-04-28 13:54:54 +0000
commit30d7e724db0c9805c9cafdd70a33f546df168d8c (patch)
treef44993e126d8a419dd444e2493b541e0efc8436b /sys/netlink/netlink_module.c
parent9e79038c502433f077b4d3b5bb1c0838329f1ebc (diff)
downloadsrc-30d7e724db0c9805c9cafdd70a33f546df168d8c.tar.gz
src-30d7e724db0c9805c9cafdd70a33f546df168d8c.zip
route: show originator PID in netlink monitor
Replacing rtsock with netlink also means providing similar tracing facilities, rtsock provides `route -n monitor` interface, where each message can be traced to the originating PID. This diff closes the feature gap between rtsock and netlink in that regard. Netlink works slightly differently from rtsock, as it is a generic message "broker". It calls some kernel KPIs and returns the result to the caller. Other Netlink consumers gets notified on the changed kernel state using the relevant subsystem callbacks. Typically, it is close to impossible to pass some data through these KPIs to enhance the notification. This diff approaches the problem by using osd(9) to assign the relevant socket pointer (`'nlp`) to the per-socket taskqueue execution thread. This change allows to recover the pointer in the aforementioned notification callbacks and extract some additional data. Using `osd(9)` (and adding additional metadata) to the notification receiver comes with some additional cost attached, so this interface needs to be enabled explicitly by using a newly-created `NETLINK_MSG_INFO` `SOL_NETLINK` socket option. The actual medatadata (which includes the originator PID) is provided via control messages. To enable extensibility, the control message data is encoded in the standard netlink(TLV-based) fashion. The list of the currently-provided properties can be found in `nlmsginfo_attrs`. snl(3) is extended to enable decoding of netlink messages with metadata (`snl_read_message_dbg()` stores the parsed structure in the provided buffer). Differential Revision: https://reviews.freebsd.org/D39391
Diffstat (limited to 'sys/netlink/netlink_module.c')
-rw-r--r--sys/netlink/netlink_module.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/sys/netlink/netlink_module.c b/sys/netlink/netlink_module.c
index 31faf1d003d9..6835c4a0e730 100644
--- a/sys/netlink/netlink_module.c
+++ b/sys/netlink/netlink_module.c
@@ -189,6 +189,7 @@ const static struct nl_function_wrapper nl_module = {
.nlmsg_end_dump = _nlmsg_end_dump,
.nl_modify_ifp_generic = _nl_modify_ifp_generic,
.nl_store_ifp_cookie = _nl_store_ifp_cookie,
+ .nl_get_thread_nlp = _nl_get_thread_nlp,
};
#endif
@@ -222,6 +223,7 @@ netlink_modevent(module_t mod __unused, int what, void *priv __unused)
switch (what) {
case MOD_LOAD:
NL_LOG(LOG_DEBUG2, "Loading");
+ nl_osd_register();
#if !defined(NETLINK) && defined(NETLINK_MODULE)
nl_set_functions(&nl_module);
#endif
@@ -235,6 +237,7 @@ netlink_modevent(module_t mod __unused, int what, void *priv __unused)
#if !defined(NETLINK) && defined(NETLINK_MODULE)
nl_set_functions(NULL);
#endif
+ nl_osd_unregister();
} else
ret = EBUSY;
break;