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.
This commit is contained in:
parent
f8444b32f3
commit
9ec9ad9c0f
1
NEWS
1
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
|
||||
|
@ -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:
|
||||
|
@ -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;
|
||||
|
2
xlat/netlink_ack_flags.in
Normal file
2
xlat/netlink_ack_flags.in
Normal file
@ -0,0 +1,2 @@
|
||||
NLM_F_CAPPED
|
||||
NLM_F_ACK_TLVS
|
Loading…
x
Reference in New Issue
Block a user