Page MenuHomeFreeBSD

route: show originator PID in netlink monitor
ClosedPublic

Authored by melifaro on Apr 2 2023, 6:07 PM.
Tags
None
Referenced Files
Unknown Object (File)
May 11 2024, 1:34 PM
Unknown Object (File)
May 4 2024, 7:46 PM
Unknown Object (File)
Apr 27 2024, 3:54 AM
Unknown Object (File)
Apr 27 2024, 3:53 AM
Unknown Object (File)
Apr 27 2024, 3:53 AM
Unknown Object (File)
Apr 27 2024, 3:53 AM
Unknown Object (File)
Apr 27 2024, 3:53 AM
Unknown Object (File)
Apr 27 2024, 3:53 AM
Subscribers

Details

Summary

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 - 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 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).

Test Plan
18:05 [0] m@devel0 /usr/obj/usr/home/melifaro/free/head/amd64.amd64/sbin/route/route -n monitor

-> s route add -net 11.0.0.0/24 10.0.0.77

18:05:35.928 PID  765 add/repl route 11.0.0.0/24 gw 10.0.0.77 iface vtnet0 mtu 1500 table inet.0

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

melifaro added a reviewer: network.

It is a useful feature. Does it deserve a flag to turn on / off ?

In D39391#896585, @zlei wrote:

It is a useful feature. Do it deserve a flag to turn it on ?

Well, a number of popular Netlink users don't expect anything except 0 or it's own socket PID in that field - like iproute2. That's why I'd rather put it under the flag.

melifaro edited the test plan for this revision. (Show Details)

Change reporting approach: use control message w/ netlink serialisation format.

Remove debugging leftovers.

In D39391#896585, @zlei wrote:

It is a useful feature. Does it deserve a flag to turn on / off ?

That's a good and absolutely valid question. I've updated the diff description to provide a longer answer (and I should have done this in the beginning). TL;DR is that this functionality has some performance implications and is typically not used by any of the consumers.

Fix the case when the reply message spans multiple mbufs.
Properly zero cinfo in _dbg() reader.

This revision was not accepted when it landed; it landed in state Needs Review.Apr 28 2023, 1:56 PM
This revision was automatically updated to reflect the committed changes.