[PATCH v4 4/5] netlink: decode family name of Netlink GENERIC protocol

Masatake YAMATO yamato at redhat.com
Mon Jun 19 03:45:51 UTC 2017

GENERIC is a protocol stacked on Netlink protocol.  Via GENERIC
protocol, a process can communicate with a kernel subsystem.

An integer named "family" is assigned to each subsystem that can be
communicated via GENERIC protocol. A process sets the integer to the
type field of Netlink packet.

A subsystem registers its name to the kernel at run-time, and gets an
integer for family. So even strace can know the integer that the
target process uses in the communication, a user of strace cannot know
the subsystem which the target process communicates with.

This change decodes the integer for family which is stored to the
type field by accessing kernel at run-time.

Example session:

  $ ./strace -yy -e 'sendto' ip tcp_metrics > /dev/null
  sendto(4<NETLINK:[GENERIC:7939]>, {{len=20, type=tcp_metrics, ...
  +++ exited with 0 +++

type= that specifies a family in Netlink GENERIC protocol
is decoded well.

* netlink.c (nlmsg_types): Remove const modifiers to allow to
install a xlat table for decoding the field made at run-time.
Add an element for NETLINK_GENERIC.
(decode_nlmsg_type): Install the xlat table to the NETLINK_GENERIC
element of nlmsg_types.

Changes in v4:

	* Update this log to clear the relationship between an integer
	for "family" and "type" field.

Signed-off-by: Masatake YAMATO <yamato at redhat.com>
 netlink.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/netlink.c b/netlink.c
index 4bef949..ff837f4 100644
--- a/netlink.c
+++ b/netlink.c
@@ -109,6 +109,15 @@ decode_nlmsg_type_default(const struct xlat *const xlat,
 static void
+decode_nlmsg_type_generic(const struct xlat *const xlat,
+			  const uint16_t type,
+			  const char *const dflt)
+	const struct xlat *const my_xlat = genl_families_xlat();
+	printxval(my_xlat, type, dflt);
+static void
 decode_nlmsg_type_netfilter(const struct xlat *const xlat,
 			    const uint16_t type,
 			    const char *const dflt)
@@ -146,6 +155,11 @@ static const struct {
 	const char *const dflt;
 } nlmsg_types[] = {
 	[NETLINK_AUDIT] = { NULL, nl_audit_types, "AUDIT_???" },
+		decode_nlmsg_type_generic,
+		NULL,
+	},

More information about the Strace-devel mailing list