]> granicus.if.org Git - strace/commitdiff
netlink: decode NLMSG_DONE messages
authorJingPiao Chen <chenjingpiao@gmail.com>
Fri, 5 May 2017 10:21:17 +0000 (18:21 +0800)
committerDmitry V. Levin <ldv@altlinux.org>
Sun, 4 Jun 2017 13:17:06 +0000 (13:17 +0000)
* netlink.c (decode_payload): Decode NLMSG_DONE messages.
* tests/netlink_protocol.c (test_nlmsg_done): New function
for checking decoding of NLMSG_DONE messages.
(main): Use it.

netlink.c
tests/netlink_protocol.c

index 678343c8f05b171a94e04631abf561f229c1260f..daaa745f5fd0eb78914957f0e6a5e1d3a44d5ca4 100644 (file)
--- a/netlink.c
+++ b/netlink.c
@@ -120,6 +120,12 @@ decode_payload(struct tcb *const tcp,
        if (nlmsghdr->nlmsg_type == NLMSG_ERROR) {
                decode_nlmsgerr(tcp, addr, len);
                return;
+       } else if (nlmsghdr->nlmsg_type == NLMSG_DONE && len == sizeof(int)) {
+               int num;
+
+               if (!umove_or_printaddr(tcp, addr, &num))
+                       tprintf("%d", num);
+               return;
        }
 
        printstrn(tcp, addr, len);
index 35f954fdb755a8b5aacb766330878b2c47ef77b9..121c83d0994f0f20113efba47630ccd558c530b1 100644 (file)
@@ -314,6 +314,42 @@ test_nlmsgerr(const int fd)
               nlh->nlmsg_len, sprintrc(rc));
 }
 
+static void
+test_nlmsg_done(const int fd)
+{
+       struct nlmsghdr *nlh;
+       int total_len;
+       void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
+       long rc;
+
+       nlh = nlh0;
+       nlh->nlmsg_len = NLMSG_HDRLEN + sizeof(int);
+       nlh->nlmsg_type = NLMSG_DONE;
+       nlh->nlmsg_flags = NLM_F_MULTI;
+       nlh->nlmsg_seq = 0;
+       nlh->nlmsg_pid = 0;
+
+       rc = sendto(fd, nlh, nlh->nlmsg_len, MSG_DONTWAIT, NULL, 0);
+       printf("sendto(%d, {{len=%u, type=NLMSG_DONE, flags=NLM_F_MULTI"
+              ", seq=0, pid=0}, %p}, %u, MSG_DONTWAIT, NULL, 0) = %s\n",
+              fd, nlh->nlmsg_len, nlh0 + NLMSG_HDRLEN,
+              nlh->nlmsg_len, sprintrc(rc));
+
+       nlh = nlh0 - sizeof(int);
+       nlh->nlmsg_len = NLMSG_HDRLEN + sizeof(int);
+       nlh->nlmsg_type = NLMSG_DONE;
+       nlh->nlmsg_flags = NLM_F_MULTI;
+       nlh->nlmsg_seq = 0;
+       nlh->nlmsg_pid = 0;
+       total_len = nlh->nlmsg_len;
+       memcpy(NLMSG_DATA(nlh), &total_len, sizeof(total_len));
+
+       rc = sendto(fd, nlh, nlh->nlmsg_len, MSG_DONTWAIT, NULL, 0);
+       printf("sendto(%d, {{len=%u, type=NLMSG_DONE, flags=NLM_F_MULTI"
+              ", seq=0, pid=0}, %d}, %u, MSG_DONTWAIT, NULL, 0) = %s\n",
+              fd, nlh->nlmsg_len, nlh->nlmsg_len, total_len, sprintrc(rc));
+}
+
 int main(void)
 {
        struct sockaddr_nl addr;
@@ -343,6 +379,7 @@ int main(void)
 
        send_query(fd);
        test_nlmsgerr(fd);
+       test_nlmsg_done(fd);
 
        printf("+++ exited with 0 +++\n");