]> granicus.if.org Git - strace/commitdiff
netlink: decode netlink message ack flags
authorJingPiao Chen <chenjingpiao@gmail.com>
Wed, 19 Jul 2017 09:17:35 +0000 (17:17 +0800)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 19 Jul 2017 09:25:58 +0000 (09:25 +0000)
* netlink.c: Include "xlat/netlink_ack_flags.h".
(decode_nlmsg_flags): Decode ack flags when type == NLMSG_ERROR.
* xlat/netlink_ack_flags.in: New file.
* NEWS: Mention this.
* tests/netlink_protocol.c (test_ack_flags): New function, check this.
(main): Use it.

NEWS
netlink.c
tests/netlink_protocol.c
xlat/netlink_ack_flags.in [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 305e419f72fa871c632e948d6b7fd3aae12640ce..f145094b8d176e158150affb0f4b7f64a860c79e 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,7 @@ Noteworthy changes in release ?.?? (????-??-??)
   * Implemented decoding of inet_diag_req_v2, inet_diag_req_compat,
     packet_diag_msg, and smc_diag_msg netlink attributes of NETLINK_SOCK_DIAG.
   * Implemented NETLINK_SELINUX protocol specific decoding.
+  * Implemented decoding of netlink message ack flags.
   * Updated lists of BPF_*, RWF_*, SCM_*, and SO_* constants.
 
 * Bug fixes
index e054ae30e2a3e32fce26324ce81a4f4535d530d3..d3ad8b09030312cae13a9fb41f46bb00a63be80e 100644 (file)
--- a/netlink.c
+++ b/netlink.c
@@ -32,6 +32,7 @@
 #include <linux/audit.h>
 #include <linux/rtnetlink.h>
 #include <linux/xfrm.h>
+#include "xlat/netlink_ack_flags.h"
 #include "xlat/netlink_flags.h"
 #include "xlat/netlink_get_flags.h"
 #include "xlat/netlink_new_flags.h"
@@ -196,8 +197,11 @@ decode_nlmsg_flags(const uint16_t flags, const uint16_t type, const int family)
 {
        const struct xlat *table = NULL;
 
-       if (type == NLMSG_DONE)
+       if (type < NLMSG_MIN_TYPE) {
+               if (type == NLMSG_ERROR)
+                       table = netlink_ack_flags;
                goto end;
+       }
 
        switch (family) {
        case NETLINK_CRYPTO:
index ee5bf0fe5afd4d1697cd1336abc1e10c92ad394c..be1a6528a95a335e302d93b640bbcd56815ed0c8 100644 (file)
@@ -363,6 +363,45 @@ test_nlmsg_done(const int fd)
               fd, nlh->nlmsg_len, num, nlh->nlmsg_len, sprintrc(rc));
 }
 
+#if defined NLM_F_CAPPED || defined NLM_F_ACK_TLVS
+static void
+test_ack_flags(const int fd)
+{
+       long rc;
+       struct nlmsghdr nlh = {
+               .nlmsg_len = sizeof(nlh),
+               .nlmsg_type = NLMSG_ERROR,
+       };
+
+#ifdef NLM_F_CAPPED
+       nlh.nlmsg_flags = NLM_F_REQUEST | NLM_F_CAPPED,
+       rc = sendto(fd, &nlh, sizeof(nlh), MSG_DONTWAIT, NULL, 0);
+       printf("sendto(%d, {len=%u, type=NLMSG_ERROR"
+              ", flags=NLM_F_REQUEST|NLM_F_CAPPED, seq=0, pid=0}"
+              ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
+              fd, nlh.nlmsg_len, (unsigned) sizeof(nlh), sprintrc(rc));
+#endif
+
+#ifdef NLM_F_ACK_TLVS
+       nlh.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK_TLVS;
+       rc = sendto(fd, &nlh, sizeof(nlh), MSG_DONTWAIT, NULL, 0);
+       printf("sendto(%d, {len=%u, type=NLMSG_ERROR"
+              ", flags=NLM_F_REQUEST|NLM_F_ACK_TLVS, seq=0, pid=0}"
+              ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
+              fd, nlh.nlmsg_len, (unsigned) sizeof(nlh), sprintrc(rc));
+#endif
+
+#if defined NLM_F_CAPPED && defined NLM_F_ACK_TLVS
+       nlh.nlmsg_flags = NLM_F_REQUEST | NLM_F_CAPPED | NLM_F_ACK_TLVS;
+       rc = sendto(fd, &nlh, sizeof(nlh), MSG_DONTWAIT, NULL, 0);
+       printf("sendto(%d, {len=%u, type=NLMSG_ERROR"
+              ", flags=NLM_F_REQUEST|NLM_F_CAPPED|NLM_F_ACK_TLVS, seq=0, pid=0}"
+              ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
+              fd, nlh.nlmsg_len, (unsigned) sizeof(nlh), sprintrc(rc));
+#endif
+}
+#endif
+
 int main(void)
 {
        const int fd = create_nl_socket(NETLINK_SOCK_DIAG);
@@ -378,6 +417,9 @@ int main(void)
        send_query(fd);
        test_nlmsgerr(fd);
        test_nlmsg_done(fd);
+#if defined NLM_F_CAPPED || defined NLM_F_ACK_TLVS
+       test_ack_flags(fd);
+#endif
 
        puts("+++ exited with 0 +++");
        return 0;
diff --git a/xlat/netlink_ack_flags.in b/xlat/netlink_ack_flags.in
new file mode 100644 (file)
index 0000000..2aabb84
--- /dev/null
@@ -0,0 +1,2 @@
+NLM_F_CAPPED
+NLM_F_ACK_TLVS