[PATCH v4 05/10] netlink: add a dummy netlink attribute parser of AF_INET diag

JingPiao Chen chenjingpiao at gmail.com
Tue Jun 20 09:23:50 UTC 2017


* linux/inet_diag.h (INET_DIAG_REQ_*): New enum.
* netlink_sock_diag.c: Include "xlat/inet_diag_attrs.h"
and "xlat/inet_diag_req_attrs.h".
(decode_inet_diag_req_compat, decode_inet_diag_req_v2,
 decode_inet_diag_msg): Use decode_nlattr.
* xlat/inet_diag_attrs.in: New file.
* xlat/inet_diag_req_attrs.in: Likewise.

Co-authored-by: Fabien Siron <fabien.siron at epita.fr>
---
 linux/inet_diag.h           |  5 +++++
 netlink_sock_diag.c         | 35 ++++++++++++++++++++++++++++++++---
 xlat/inet_diag_attrs.in     | 18 ++++++++++++++++++
 xlat/inet_diag_req_attrs.in |  3 +++
 4 files changed, 58 insertions(+), 3 deletions(-)
 create mode 100644 xlat/inet_diag_attrs.in
 create mode 100644 xlat/inet_diag_req_attrs.in

diff --git a/linux/inet_diag.h b/linux/inet_diag.h
index 245e476..e1df3bb 100644
--- a/linux/inet_diag.h
+++ b/linux/inet_diag.h
@@ -34,6 +34,11 @@ struct inet_diag_req_v2 {
 	struct inet_diag_sockid id;
 };
 
+enum {
+	INET_DIAG_REQ_NONE,
+	INET_DIAG_REQ_BYTECODE,
+};
+
 /* Info structure */
 struct inet_diag_msg {
 	uint8_t idiag_family;
diff --git a/netlink_sock_diag.c b/netlink_sock_diag.c
index 6241e52..a37292c 100644
--- a/netlink_sock_diag.c
+++ b/netlink_sock_diag.c
@@ -41,7 +41,9 @@
 #endif
 #include <linux/unix_diag.h>
 
+#include "xlat/inet_diag_attrs.h"
 #include "xlat/inet_diag_extended_flags.h"
+#include "xlat/inet_diag_req_attrs.h"
 
 #include "xlat/tcp_states.h"
 #include "xlat/tcp_state_flags.h"
@@ -336,7 +338,8 @@ decode_inet_diag_req_compat(struct tcb *const tcp,
 			    const kernel_ulong_t len)
 {
 	struct inet_diag_req req = { .idiag_family = family };
-	const size_t offset = sizeof(req.idiag_family);
+	size_t offset = sizeof(req.idiag_family);
+	bool decode_nla = false;
 
 	tprints("{idiag_family=");
 	printxval(addrfams, req.idiag_family, "AF_???");
@@ -359,10 +362,18 @@ decode_inet_diag_req_compat(struct tcb *const tcp,
 			printflags(tcp_state_flags, req.idiag_states,
 				   "1<<TCP_???");
 			tprintf(", idiag_dbs=%" PRIu32, req.idiag_dbs);
+			decode_nla = true;
 		}
 	} else
 		tprints("...");
 	tprints("}");
+
+	offset = NLA_ALIGN(sizeof(req));
+	if (decode_nla && len > offset) {
+		tprints(", ");
+		decode_nlattr(tcp, addr + offset, len - offset,
+			      inet_diag_req_attrs, "INET_DIAG_REQ_???");
+	}
 }
 
 static void
@@ -373,7 +384,8 @@ decode_inet_diag_req_v2(struct tcb *const tcp,
 			const kernel_ulong_t len)
 {
 	struct inet_diag_req_v2 req = { .sdiag_family = family };
-	const size_t offset = sizeof(req.sdiag_family);
+	size_t offset = sizeof(req.sdiag_family);
+	bool decode_nla = false;
 
 	tprints("{sdiag_family=");
 	printxval(addrfams, req.sdiag_family, "AF_???");
@@ -394,10 +406,18 @@ decode_inet_diag_req_v2(struct tcb *const tcp,
 				   "1<<TCP_???");
 			tprints(", id=");
 			print_inet_diag_sockid(&req.id, req.sdiag_family);
+			decode_nla = true;
 		}
 	} else
 		tprints("...");
 	tprints("}");
+
+	offset = NLA_ALIGN(sizeof(req));
+	if (decode_nla && len > offset) {
+		tprints(", ");
+		decode_nlattr(tcp, addr + offset, len - offset,
+			      inet_diag_req_attrs, "INET_DIAG_REQ_???");
+	}
 }
 
 static void
@@ -424,7 +444,8 @@ decode_inet_diag_msg(struct tcb *const tcp,
 		     const kernel_ulong_t len)
 {
 	struct inet_diag_msg msg = { .idiag_family = family };
-	const size_t offset = sizeof(msg.idiag_family);
+	size_t offset = sizeof(msg.idiag_family);
+	bool decode_nla = false;
 
 	tprints("{idiag_family=");
 	printxval(addrfams, msg.idiag_family, "AF_???");
@@ -451,10 +472,18 @@ decode_inet_diag_msg(struct tcb *const tcp,
 				msg.idiag_wqueue,
 				msg.idiag_uid,
 				msg.idiag_inode);
+			decode_nla = true;
 		}
 	} else
 		tprints("...");
 	tprints("}");
+
+	offset = NLA_ALIGN(sizeof(msg));
+	if (decode_nla && len > offset) {
+		tprints(", ");
+		decode_nlattr(tcp, addr + offset, len - offset,
+			      inet_diag_attrs, "INET_DIAG_???");
+	}
 }
 
 #ifdef AF_SMC
diff --git a/xlat/inet_diag_attrs.in b/xlat/inet_diag_attrs.in
new file mode 100644
index 0000000..17519c8
--- /dev/null
+++ b/xlat/inet_diag_attrs.in
@@ -0,0 +1,18 @@
+#unconditional
+INET_DIAG_NONE
+INET_DIAG_MEMINFO
+INET_DIAG_INFO
+INET_DIAG_VEGASINFO
+INET_DIAG_CONG
+INET_DIAG_TOS
+INET_DIAG_TCLASS
+INET_DIAG_SKMEMINFO
+INET_DIAG_SHUTDOWN
+INET_DIAG_DCTCPINFO
+INET_DIAG_PROTOCOL
+INET_DIAG_SKV6ONLY
+INET_DIAG_LOCALS
+INET_DIAG_PEERS
+INET_DIAG_PAD
+INET_DIAG_MARK
+INET_DIAG_BBRINFO
diff --git a/xlat/inet_diag_req_attrs.in b/xlat/inet_diag_req_attrs.in
new file mode 100644
index 0000000..c36369e
--- /dev/null
+++ b/xlat/inet_diag_req_attrs.in
@@ -0,0 +1,3 @@
+#unconditional
+INET_DIAG_REQ_NONE
+INET_DIAG_REQ_BYTECODE
-- 
2.7.4





More information about the Strace-devel mailing list