1 /*
2 * Copyright (c) 2017 JingPiao Chen <chenjingpiao@gmail.com>
3 * Copyright (c) 2017-2021 The strace developers.
4 * All rights reserved.
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
9 #include "tests.h"
10
11 #include <stdio.h>
12 #include "test_nlattr.h"
13 #include <linux/netconf.h>
14 #include <linux/rtnetlink.h>
15
16 static void
17 init_netconfmsg(struct nlmsghdr *const nlh, const unsigned int msg_len)
18 {
19 SET_STRUCT(struct nlmsghdr, nlh,
20 .nlmsg_len = msg_len,
21 .nlmsg_type = RTM_GETNETCONF,
22 .nlmsg_flags = NLM_F_DUMP
23 );
24
25 struct netconfmsg *const msg = NLMSG_DATA(nlh);
26 SET_STRUCT(struct netconfmsg, msg,
27 .ncm_family = AF_INET
28 );
29 }
30
31 static void
32 print_netconfmsg(const unsigned int msg_len)
33 {
34 printf("{nlmsg_len=%u, nlmsg_type=RTM_GETNETCONF"
35 ", nlmsg_flags=NLM_F_DUMP, nlmsg_seq=0, nlmsg_pid=0}"
36 ", {ncm_family=AF_INET}",
37 msg_len);
38 }
39
40 int
41 main(void)
42 {
43 skip_if_unavailable("/proc/self/fd/");
44
45 const int fd = create_nl_socket(NETLINK_ROUTE);
46
47 const unsigned int hdrlen = sizeof(struct netconfmsg);
48 void *nlh0 = midtail_alloc(NLMSG_SPACE(hdrlen), NLA_HDRLEN + 4);
49
50 static char pattern[4096];
51 fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
52
53 const unsigned int nla_type = 0xffff & NLA_TYPE_MASK;
54 char nla_type_str[256];
55 sprintf(nla_type_str, "%#x /* NETCONFA_??? */", nla_type);
56 TEST_NLATTR_(fd, nlh0, hdrlen,
57 init_netconfmsg, print_netconfmsg,
58 nla_type, nla_type_str,
59 4, pattern, 4,
60 print_quoted_hex(pattern, 4));
61
62 puts("+++ exited with 0 +++");
63 return 0;
64 }