[PATCH 5/6] netlink: decode "family" field of Netlink GENERIC protocol

Masatake YAMATO yamato at redhat.com
Sat Jun 10 06:32:46 UTC 2017


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

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

diff --git a/netlink.c b/netlink.c
index 049843d..d8a735e 100644
--- a/netlink.c
+++ b/netlink.c
@@ -100,8 +100,8 @@ get_fd_nl_family(struct tcb *const tcp, const int fd)
 	return NL_FAMILY_ERROR;
 }
 
-static const struct {
-	const struct xlat *const xlat;
+static struct {
+	const struct xlat * xlat;
 	const char *const dflt;
 } nlmsg_types[] = {
 	[NETLINK_AUDIT] = { nl_audit_types, "AUDIT_???" },
@@ -109,7 +109,8 @@ static const struct {
 	[NETLINK_ROUTE] = { nl_route_types, "RTM_???" },
 	[NETLINK_SELINUX] = { nl_selinux_types, "SELNL_MSG_???" },
 	[NETLINK_SOCK_DIAG] = { nl_sock_diag_types, "SOCK_DIAG_???" },
-	[NETLINK_XFRM] = { nl_xfrm_types, "XFRM_MSG_???" }
+	[NETLINK_XFRM] = { nl_xfrm_types, "XFRM_MSG_???" },
+	[NETLINK_GENERIC] = { NULL, "GENERIC_FAMILY_???" }
 };
 
 /*
@@ -119,6 +120,9 @@ static const struct {
 static void
 decode_nlmsg_type(const uint16_t type, const unsigned int family)
 {
+	if (!nlmsg_types [NETLINK_GENERIC].xlat)
+		nlmsg_types [NETLINK_GENERIC].xlat = genl_families_xlat();
+
 	if (family < ARRAY_SIZE(nlmsg_types)
 	    && nlmsg_types[family].xlat) {
 		if (family == NETLINK_NETFILTER) {
-- 
2.9.4





More information about the Strace-devel mailing list