[PATCH 2/4] netlink: adjust decode_nlmsgerr for extended ACK reporting

JingPiao Chen chenjingpiao at gmail.com
Mon Jul 17 15:07:44 UTC 2017


Extended ACK reporting introduced by linux kernel commit
v4.11-rc5-1382-g2d4bc93.

* netlink.h (NLM_F_CAPPED): New macro.
* netlink.c (decode_payload): Pass nlmsghdr to decode_nlmsgerr.
(decode_nlmsgerr): Adjust the length pass to
decode_nlmsghdr_with_payload.
---
 netlink.c | 14 +++++++++++---
 netlink.h |  4 ++++
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/netlink.c b/netlink.c
index 9d480d3..6184008 100644
--- a/netlink.c
+++ b/netlink.c
@@ -297,6 +297,7 @@ static void
 decode_nlmsgerr(struct tcb *const tcp,
 		const int fd,
 		const int family,
+		const struct nlmsghdr *const nlmsghdr,
 		kernel_ulong_t addr,
 		kernel_ulong_t len)
 {
@@ -321,10 +322,17 @@ decode_nlmsgerr(struct tcb *const tcp,
 	len -= offsetof(struct nlmsgerr, msg);
 
 	if (len) {
+		unsigned int payload =
+			len > nlmsghdr->nlmsg_len ? nlmsghdr->nlmsg_len : len;
+
+		if (nlmsghdr->nlmsg_flags & NLM_F_CAPPED &&
+		    payload > sizeof(err.msg))
+			payload = sizeof(err.msg);
+
 		tprints(", msg=");
-		if (fetch_nlmsghdr(tcp, &err.msg, addr, len)) {
+		if (fetch_nlmsghdr(tcp, &err.msg, addr, payload)) {
 			decode_nlmsghdr_with_payload(tcp, fd, family,
-						     &err.msg, addr, len);
+						     &err.msg, addr, payload);
 		}
 	}
 
@@ -345,7 +353,7 @@ decode_payload(struct tcb *const tcp,
 	       const kernel_ulong_t len)
 {
 	if (nlmsghdr->nlmsg_type == NLMSG_ERROR) {
-		decode_nlmsgerr(tcp, fd, family, addr, len);
+		decode_nlmsgerr(tcp, fd, family, nlmsghdr, addr, len);
 		return;
 	}
 
diff --git a/netlink.h b/netlink.h
index 5943229..31b7876 100644
--- a/netlink.h
+++ b/netlink.h
@@ -36,6 +36,10 @@
 # define NETLINK_SOCK_DIAG 4
 #endif
 
+#ifndef NLM_F_CAPPED
+# define NLM_F_CAPPED	0x100
+#endif
+
 #undef NLMSG_HDRLEN
 #define NLMSG_HDRLEN ((unsigned int) NLMSG_ALIGN(sizeof(struct nlmsghdr)))
 
-- 
2.7.4





More information about the Strace-devel mailing list