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
11 #ifdef HAVE_STRUCT_BR_PORT_MSG
14 # include "test_nlattr.h"
15 # include <linux/if_bridge.h>
16 # include <linux/rtnetlink.h>
19 # define MDBA_ROUTER 2
21 # ifndef MDBA_ROUTER_PORT
22 # define MDBA_ROUTER_PORT 1
24 # ifndef MDBA_ROUTER_PATTR_TYPE
25 # define MDBA_ROUTER_PATTR_TYPE 2
27 # ifndef MDB_RTR_TYPE_DISABLED
28 # define MDB_RTR_TYPE_DISABLED 0
31 const unsigned int hdrlen = sizeof(struct br_port_msg);
34 init_br_port_msg(struct nlmsghdr *const nlh, const unsigned int msg_len)
36 SET_STRUCT(struct nlmsghdr, nlh,
38 .nlmsg_type = RTM_GETMDB,
39 .nlmsg_flags = NLM_F_DUMP
42 struct br_port_msg *const msg = NLMSG_DATA(nlh);
43 SET_STRUCT(struct br_port_msg, msg,
45 .ifindex = ifindex_lo()
48 struct nlattr *nla = NLMSG_ATTR(nlh, sizeof(*msg));
49 SET_STRUCT(struct nlattr, nla,
50 .nla_len = msg_len - NLMSG_SPACE(hdrlen),
51 .nla_type = MDBA_ROUTER
56 print_br_port_msg(const unsigned int msg_len)
58 printf("{len=%u, type=RTM_GETMDB, flags=NLM_F_DUMP"
59 ", seq=0, pid=0}, {family=AF_UNIX"
60 ", ifindex=" IFINDEX_LO_STR "}"
61 ", {{nla_len=%u, nla_type=MDBA_ROUTER}",
62 msg_len, msg_len - NLMSG_SPACE(hdrlen));
68 skip_if_unavailable("/proc/self/fd/");
70 const uint32_t ifindex = ifindex_lo();
71 const uint8_t type = MDB_RTR_TYPE_DISABLED;
72 static const struct nlattr nla = {
73 .nla_len = NLA_HDRLEN + sizeof(type),
74 .nla_type = MDBA_ROUTER_PATTR_TYPE
76 char buf[NLMSG_ALIGN(ifindex) + NLA_HDRLEN + sizeof(type)];
78 const int fd = create_nl_socket(NETLINK_ROUTE);
80 void *nlh0 = midtail_alloc(NLMSG_SPACE(hdrlen),
81 NLA_HDRLEN + sizeof(buf));
83 static char pattern[4096];
84 fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
86 TEST_NESTED_NLATTR_OBJECT(fd, nlh0, hdrlen,
87 init_br_port_msg, print_br_port_msg,
88 MDBA_ROUTER_PORT, pattern, ifindex,
89 printf(IFINDEX_LO_STR));
91 memcpy(buf, &ifindex, sizeof(ifindex));
92 memcpy(buf + NLMSG_ALIGN(ifindex), &nla, sizeof(nla));
93 memcpy(buf + NLMSG_ALIGN(ifindex) + NLA_HDRLEN, &type, sizeof(type));
94 TEST_NLATTR(fd, nlh0 - NLA_HDRLEN, hdrlen + NLA_HDRLEN,
95 init_br_port_msg, print_br_port_msg,
96 MDBA_ROUTER_PORT, sizeof(buf), buf, sizeof(buf),
98 ", {{nla_len=%u, nla_type=MDBA_ROUTER_PATTR_TYPE}"
99 ", MDB_RTR_TYPE_DISABLED}}",
102 puts("+++ exited with 0 +++");
108 SKIP_MAIN_UNDEFINED("HAVE_STRUCT_BR_PORT_MSG")