[PATCH v2 6/7] Netlink: Introduce nlmsg_* functions

Fabien Siron fabien.siron at epita.fr
Mon Jun 13 14:37:26 UTC 2016


Since our target is not in the same process, the netlink macros NLMSG_*
must be rewritten for strace.

* netlink.c (nlmsg_ok, nlmsg_next): New functions.
---
 netlink.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/netlink.c b/netlink.c
index 738c639..bb2c3a7 100644
--- a/netlink.c
+++ b/netlink.c
@@ -33,6 +33,32 @@
 #include "xlat/netlink_flags.h"
 #include "xlat/netlink_types.h"
 
+/* 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;
+
+	if (umoven(tcp, nlh, sizeof(struct nlmsghdr), &nlmsghdr) == -1)
+		return 0;
+
+	return (len >= (int)sizeof(struct nlmsghdr)) &&
+		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);
+
+	return (unsigned long)
+		((char *)(nlh) + NLMSG_ALIGN(nlmsghdr.nlmsg_len));
+}
+
 void
 decode_netlink_or_printaddr(struct tcb *tcp, unsigned long addr,
 			    unsigned long size)
-- 
2.8.3





More information about the Strace-devel mailing list