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"
13 #include <linux/rtnetlink.h>
16 init_tcamsg(struct nlmsghdr *const nlh, const unsigned int msg_len)
18 SET_STRUCT(struct nlmsghdr, nlh,
20 .nlmsg_type = RTM_GETACTION,
21 .nlmsg_flags = NLM_F_DUMP
24 struct tcamsg *const msg = NLMSG_DATA(nlh);
25 SET_STRUCT(struct tcamsg, msg,
31 print_tcamsg(const unsigned int msg_len)
33 printf("{len=%u, type=RTM_GETACTION, flags=NLM_F_DUMP"
34 ", seq=0, pid=0}, {tca_family=AF_INET}",
41 skip_if_unavailable("/proc/self/fd/");
43 const int fd = create_nl_socket(NETLINK_ROUTE);
44 const unsigned int hdrlen = sizeof(struct tcamsg);
45 void *nlh0 = midtail_alloc(NLMSG_SPACE(hdrlen), NLA_HDRLEN + 4);
47 static char pattern[4096];
48 fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
50 const unsigned int nla_type = 0xffff & NLA_TYPE_MASK;
51 char nla_type_str[256];
52 sprintf(nla_type_str, "%#x /* TCA_ACT_??? */", nla_type);
53 TEST_NLATTR_(fd, nlh0, hdrlen,
54 init_tcamsg, print_tcamsg,
55 nla_type, nla_type_str,
57 print_quoted_hex(pattern, 4));
59 puts("+++ exited with 0 +++");