]> granicus.if.org Git - strace/commitdiff
netlink: decode nlmsgerr attributes
authorJingPiao Chen <chenjingpiao@gmail.com>
Wed, 19 Jul 2017 09:17:37 +0000 (17:17 +0800)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 19 Jul 2017 09:25:58 +0000 (09:25 +0000)
* netlink.c: Include "nlattr.h" and "xlat/nlmsgerr_attrs.h".
(print_cookie, decode_nlmsgerr_attr_cookie): New functions.
(nlmsgerr_nla_decoders): New array.
(decode_nlmsgerr): Use it.
* xlat/nlmsgerr_attrs.in: New file.
* NEWS: Mention this.

NEWS
netlink.c
xlat/nlmsgerr_attrs.in [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index f145094b8d176e158150affb0f4b7f64a860c79e..3c5c49170d87f6159af58f8d797ceedd32e0e05c 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -16,6 +16,7 @@ Noteworthy changes in release ?.?? (????-??-??)
     packet_diag_msg, and smc_diag_msg netlink attributes of NETLINK_SOCK_DIAG.
   * Implemented NETLINK_SELINUX protocol specific decoding.
   * Implemented decoding of netlink message ack flags.
+  * Implemented decoding of nlmsgerr netlink attributes.
   * Updated lists of BPF_*, RWF_*, SCM_*, and SO_* constants.
 
 * Bug fixes
index b0ae18d670107973f3022eab494a1a7b810ab2e2..ddaa6c202ebdffa0eb40383a820261dfcd3381fe 100644 (file)
--- a/netlink.c
+++ b/netlink.c
@@ -29,6 +29,7 @@
 
 #include "defs.h"
 #include "netlink.h"
+#include "nlattr.h"
 #include <linux/audit.h>
 #include <linux/rtnetlink.h>
 #include <linux/xfrm.h>
@@ -46,6 +47,7 @@
 #include "xlat/nl_selinux_types.h"
 #include "xlat/nl_sock_diag_types.h"
 #include "xlat/nl_xfrm_types.h"
+#include "xlat/nlmsgerr_attrs.h"
 
 /*
  * Fetch a struct nlmsghdr from the given address.
@@ -284,6 +286,38 @@ print_nlmsghdr(struct tcb *tcp,
        return family != NL_FAMILY_DEFAULT ? family : hdr_family;
 }
 
+static bool
+print_cookie(struct tcb *const tcp,
+           void *const elem_buf,
+           const size_t elem_size,
+           void *const opaque_data)
+{
+       tprintf("%" PRIu8, *(uint8_t *) elem_buf);
+
+       return true;
+}
+
+static bool
+decode_nlmsgerr_attr_cookie(struct tcb *const tcp,
+                           const kernel_ulong_t addr,
+                           const kernel_ulong_t len,
+                           const void *const opaque_data)
+{
+       uint8_t cookie;
+       const size_t nmemb = len / sizeof(cookie);
+
+       print_array(tcp, addr, nmemb, &cookie, sizeof(cookie),
+                   umoven_or_printaddr, print_cookie, 0);
+
+       return true;
+}
+
+static const nla_decoder_t nlmsgerr_nla_decoders[] = {
+       [NLMSGERR_ATTR_MSG]     = decode_nla_str,
+       [NLMSGERR_ATTR_OFFS]    = decode_nla_u32,
+       [NLMSGERR_ATTR_COOKIE]  = decode_nlmsgerr_attr_cookie
+};
+
 static void
 decode_nlmsghdr_with_payload(struct tcb *const tcp,
                             const int fd,
@@ -330,6 +364,15 @@ decode_nlmsgerr(struct tcb *const tcp,
 
                        decode_nlmsghdr_with_payload(tcp, fd, family,
                                                     &err.msg, addr, payload);
+                       if (len > payload) {
+                               tprints(", ");
+                               decode_nlattr(tcp, addr + payload,
+                                             len - payload, nlmsgerr_attrs,
+                                             "NLMSGERR_ATTR_???",
+                                             nlmsgerr_nla_decoders,
+                                             ARRAY_SIZE(nlmsgerr_nla_decoders),
+                                             NULL);
+                       }
                }
        }
 
diff --git a/xlat/nlmsgerr_attrs.in b/xlat/nlmsgerr_attrs.in
new file mode 100644 (file)
index 0000000..589bc55
--- /dev/null
@@ -0,0 +1,4 @@
+NLMSGERR_ATTR_UNUSED   0
+NLMSGERR_ATTR_MSG      1
+NLMSGERR_ATTR_OFFS     2
+NLMSGERR_ATTR_COOKIE   3