[PATCH v4 6/6] Netlink: handle multi netlink messages

Fabien Siron fabien.siron at epita.fr
Fri Jun 17 16:29:58 UTC 2016


* netlink.c (decode_netlink_or_printaddr_msg): From
decode_netlink_or_printaddr().
(decode_netlink_or_printaddr): Call decode_netlink_or_printaddr_msg().
---
 netlink.c | 42 ++++++++++++++++++++++++++----------------
 1 file changed, 26 insertions(+), 16 deletions(-)

diff --git a/netlink.c b/netlink.c
index 1211d57..a2beec6 100644
--- a/netlink.c
+++ b/netlink.c
@@ -33,32 +33,33 @@
 
 /* since our target is not in the same process, here are some utils for nlmsg */
 static int
-nlmsg_ok(struct tcb *tcp, unsigned long nlh, unsigned long len) {
-	struct nlmsghdr nlmsghdr;
+nlmsg_fetch(struct tcb *tcp, struct nlmsghdr *nlmsghdr, unsigned long addr,
+	    unsigned long len) {
+
+	if (len < (int)sizeof(struct nlmsghdr)) {
+		if (len != 0)
+			printstr(tcp, (unsigned long)addr, len);
+		return 0;
+	}
 
-	if (umoven(tcp, nlh, sizeof(struct nlmsghdr), &nlmsghdr) == -1)
+	if (umove_or_printaddr(tcp, addr, nlmsghdr) == -1)
 		return 0;
 
-	return (len >= (int)sizeof(struct nlmsghdr)) &&
-		nlmsghdr.nlmsg_len >= sizeof(struct nlmsghdr) &&
-		nlmsghdr.nlmsg_len <= len;
+	return 	nlmsghdr->nlmsg_len >= sizeof(struct nlmsghdr) &&
+		nlmsghdr->nlmsg_len <= len;
 }
 
 static unsigned long
-nlmsg_next(struct tcb *tcp, unsigned long nlh, unsigned long *len) {
-	struct nlmsghdr nlmsghdr;
-
-	if (umoven(tcp, nlh, sizeof(struct nlmsghdr), &nlmsghdr) == -1)
-		return 0;
-
-	*len -= NLMSG_ALIGN(nlmsghdr.nlmsg_len);
+nlmsg_next(struct nlmsghdr *nlmsghdr, unsigned long addr, unsigned long *len) {
+	*len -= NLMSG_ALIGN(nlmsghdr->nlmsg_len);
 
 	return (unsigned long)
-		((char *)(nlh) + NLMSG_ALIGN(nlmsghdr.nlmsg_len));
+		((char *)(addr) + NLMSG_ALIGN(nlmsghdr->nlmsg_len));
 }
 
-void
-decode_netlink(struct tcb *tcp, unsigned long addr, unsigned long size)
+static void
+decode_netlink_msg(struct tcb *tcp, unsigned long addr,
+			    unsigned long size)
 {
 	struct nlmsghdr nlmsghdr;
 
@@ -88,3 +89,12 @@ decode_netlink(struct tcb *tcp, unsigned long addr, unsigned long size)
 
 	tprints("}");
 }
+
+void
+decode_netlink(struct tcb *tcp, unsigned long addr, unsigned long size) {
+	struct nlmsghdr nlmsghdr;
+
+	for (; nlmsg_fetch(tcp, &nlmsghdr, addr, size);
+	     addr = nlmsg_next(&nlmsghdr, addr, &size))
+		decode_netlink_msg(tcp, addr, size);
+}
-- 
2.8.3





More information about the Strace-devel mailing list