[PATCH 1/4] netlink: decode netlink message ack flags
JingPiao Chen
chenjingpiao at gmail.com
Mon Jul 17 15:07:43 UTC 2017
* 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.
* tests/netlink_protocol.c (test_ack_flags): New function, check this.
(main): Use it.
---
netlink.c | 5 +++++
tests/netlink_protocol.c | 42 ++++++++++++++++++++++++++++++++++++++++++
xlat/netlink_ack_flags.in | 2 ++
3 files changed, 49 insertions(+)
create mode 100644 xlat/netlink_ack_flags.in
diff --git a/netlink.c b/netlink.c
index e054ae3..9d480d3 100644
--- 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"
@@ -198,6 +199,10 @@ decode_nlmsg_flags(const uint16_t flags, const uint16_t type, const int family)
if (type == NLMSG_DONE)
goto end;
+ if (type == NLMSG_ERROR) {
+ table = netlink_ack_flags;
+ goto end;
+ }
switch (family) {
case NETLINK_CRYPTO:
diff --git a/tests/netlink_protocol.c b/tests/netlink_protocol.c
index ee5bf0f..be1a652 100644
--- a/tests/netlink_protocol.c
+++ b/tests/netlink_protocol.c
@@ -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
index 0000000..2aabb84
--- /dev/null
+++ b/xlat/netlink_ack_flags.in
@@ -0,0 +1,2 @@
+NLM_F_CAPPED
+NLM_F_ACK_TLVS
--
2.7.4
More information about the Strace-devel
mailing list