From: JingPiao Chen Date: Fri, 5 May 2017 10:21:17 +0000 (+0800) Subject: netlink: decode NLMSG_DONE messages X-Git-Tag: v4.18~136 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=852046ce0e456e5e411d7d93dcc5e4a44bae7d30;p=strace netlink: decode NLMSG_DONE messages * 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. --- diff --git a/netlink.c b/netlink.c index 678343c8..daaa745f 100644 --- 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); diff --git a/tests/netlink_protocol.c b/tests/netlink_protocol.c index 35f954fd..121c83d0 100644 --- a/tests/netlink_protocol.c +++ b/tests/netlink_protocol.c @@ -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");