[PATCH] netlink: add type decoding

Masatake YAMATO yamato at redhat.com
Tue Jun 6 04:09:21 UTC 2017


On Mon, 5 Jun 2pp017 19:53:00 +0300, "Dmitry V. Levin" <ldv at altlinux.org> wrote:
> On Mon, Jun 05, 2017 at 03:07:04PM +0800, JingPiao Chen wrote:
>> On Sun, Jun 04, 2017 at 10:40:09PM +0300, Dmitry V. Levin wrote:
> [...]
>> > getfdnlproto (get_fd_nl_family in my edition) is not cheap
>> > (it invokes syscalls), needless calls should be avoided.
>> 
>> I have read your code, I will rebase my code after you merge
>> ldv/netlink branch.
> 
> The first portion of netlink commits is merged now,
> it's time to rebase.  Thanks!

JingPiao, great work! I have really wanted this.

Do you have a plan to work on decoding NETLINK_GENERIC?

I'm interested in the area. If you don't have a plan,
I would like to finish the following stub.

Masatake YAMATO

diff --git a/netlink.c b/netlink.c
index f9ff465..215807a 100644
--- a/netlink.c
+++ b/netlink.c
@@ -110,6 +110,26 @@ static const struct {
 	[NETLINK_XFRM] = { nl_xfrm_types, "XFRM_MSG_???" }
 };
 
+static struct xlat *build_genl_types_cache(void)
+{
+	static bool tried_once;
+	if (tried_once)
+		return NULL;
+	tried_once = true;
+
+	/* STUB: This must be built dynamically. */
+	static struct xlat dummy [] = {
+		{
+			0x0010, "nlctrl",
+		},
+		{
+			0x0019, "tcp_metrics",
+		},
+		XLAT_END
+	};
+	return &(dummy[0]);
+}
+
 /*
  * As all valid netlink families are positive integers, use unsigned int
  * for family here to filter out NL_FAMILY_ERROR and NL_FAMILY_DEFAULT.
@@ -117,6 +137,18 @@ static const struct {
 static void
 decode_nlmsg_type(const uint16_t type, const unsigned int family)
 {
+	if (family == NETLINK_GENERIC) {
+		static struct xlat *genl_types;
+
+		if (!genl_types)
+			genl_types = build_genl_types_cache();
+		if (genl_types) {
+			printxval(genl_types, type,
+				  "GENERIC_TYPE_???");
+			return;
+		}
+	}
+
 	if (family < ARRAY_SIZE(nlmsg_types)
 	    && nlmsg_types[family].xlat) {
 		if (family == NETLINK_NETFILTER) {




More information about the Strace-devel mailing list