2 * Copyright (c) 2017 JingPiao Chen <chenjingpiao@gmail.com>
3 * Copyright (c) 2017-2018 The strace developers.
6 * SPDX-License-Identifier: GPL-2.0-or-later
12 #include "test_nlattr.h"
14 #define NLMSGERR_ATTR_COOKIE 3
17 init_nlmsgerr(struct nlmsghdr *const nlh, const unsigned int msg_len)
19 SET_STRUCT(struct nlmsghdr, nlh,
21 .nlmsg_type = NLMSG_ERROR,
22 .nlmsg_flags = NLM_F_REQUEST | NLM_F_CAPPED
25 struct nlmsgerr *const err = NLMSG_DATA(nlh);
26 SET_STRUCT(struct nlmsgerr, err,
29 .nlmsg_len = NLMSG_HDRLEN + 4,
30 .nlmsg_type = NLMSG_NOOP,
31 .nlmsg_flags = NLM_F_REQUEST,
37 print_nlmsgerr(const unsigned int msg_len)
39 printf("{len=%u, type=NLMSG_ERROR"
40 ", flags=NLM_F_REQUEST|NLM_F_CAPPED"
41 ", seq=0, pid=0}, {error=-EACCES"
42 ", msg={len=%u, type=NLMSG_NOOP"
43 ", flags=NLM_F_REQUEST, seq=0, pid=0}",
44 msg_len, NLMSG_HDRLEN + 4);
50 skip_if_unavailable("/proc/self/fd/");
52 static const uint8_t cookie[] = { 0xab, 0xfe };
54 const int fd = create_nl_socket(NETLINK_SOCK_DIAG);
55 const unsigned int hdrlen = sizeof(struct nlmsgerr);
56 void *const nlh0 = midtail_alloc(NLMSG_SPACE(hdrlen),
57 NLA_HDRLEN + sizeof(cookie));
59 TEST_NLATTR(fd, nlh0, hdrlen,
60 init_nlmsgerr, print_nlmsgerr,
62 sizeof(cookie), cookie, sizeof(cookie),
63 printf("[%u, %u]", cookie[0], cookie[1]);
66 printf("+++ exited with 0 +++\n");