From: JingPiao Chen Date: Wed, 19 Jul 2017 09:17:35 +0000 (+0800) Subject: netlink: decode netlink message ack flags X-Git-Tag: v4.19~245 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9ec9ad9c0f8d3cefc9b75d767489c54e60a6d973;p=strace netlink: decode netlink message ack flags * 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. --- diff --git a/NEWS b/NEWS index 305e419f..f145094b 100644 --- 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 diff --git a/netlink.c b/netlink.c index e054ae30..d3ad8b09 100644 --- a/netlink.c +++ b/netlink.c @@ -32,6 +32,7 @@ #include #include #include +#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: diff --git a/tests/netlink_protocol.c b/tests/netlink_protocol.c index ee5bf0fe..be1a6528 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 00000000..2aabb840 --- /dev/null +++ b/xlat/netlink_ack_flags.in @@ -0,0 +1,2 @@ +NLM_F_CAPPED +NLM_F_ACK_TLVS