2 * Copyright (c) 2016 Fabien Siron <fabien.siron@epita.fr>
3 * Copyright (c) 2017 JingPiao Chen <chenjingpiao@gmail.com>
4 * Copyright (c) 2016-2018 The strace developers.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #ifdef HAVE_STRUCT_BR_PORT_MSG
34 # include "netlink_route.h"
36 # include "print_fields.h"
38 # include <netinet/in.h>
39 # include <linux/if_bridge.h>
42 # ifdef HAVE_STRUCT_BR_MDB_ENTRY_FLAGS
43 # include "xlat/mdb_flags.h"
45 # include "xlat/mdb_states.h"
46 # include "xlat/multicast_router_types.h"
47 # include "xlat/rtnl_mdb_attrs.h"
48 # include "xlat/rtnl_mdba_mdb_attrs.h"
49 # include "xlat/rtnl_mdba_mdb_eattr_attrs.h"
50 # include "xlat/rtnl_mdba_mdb_entry_attrs.h"
51 # include "xlat/rtnl_mdba_router_attrs.h"
52 # include "xlat/rtnl_mdba_router_pattr_attrs.h"
54 static const nla_decoder_t mdba_mdb_eattr_nla_decoders[] = {
55 [MDBA_MDB_EATTR_TIMER] = decode_nla_u32
59 decode_mdba_mdb_entry_info(struct tcb *const tcp,
60 const kernel_ulong_t addr,
61 const unsigned int len,
62 const void *const opaque_data)
64 # ifdef HAVE_STRUCT_BR_MDB_ENTRY
65 struct br_mdb_entry entry;
67 if (len < sizeof(entry))
69 else if (!umove_or_printaddr(tcp, addr, &entry)) {
70 PRINT_FIELD_IFINDEX("{", entry, ifindex);
71 PRINT_FIELD_XVAL(", ", entry, state, mdb_states, "MDB_???");
72 # ifdef HAVE_STRUCT_BR_MDB_ENTRY_FLAGS
73 PRINT_FIELD_FLAGS(", ", entry, flags,
74 mdb_flags, "MDB_FLAGS_???");
76 # ifdef HAVE_STRUCT_BR_MDB_ENTRY_VID
77 PRINT_FIELD_U(", ", entry, vid);
80 const int proto = ntohs(entry.addr.proto);
83 print_inet_addr(proto, &entry.addr.u,
84 sizeof(entry.addr.u), "u");
85 tprints(", proto=htons(");
86 printxval(addrfams, proto, "AF_???");
90 const size_t offset = NLMSG_ALIGN(sizeof(entry));
93 decode_nlattr(tcp, addr + offset, len - offset,
94 rtnl_mdba_mdb_eattr_attrs, "MDBA_MDB_EATTR_???",
95 mdba_mdb_eattr_nla_decoders,
96 ARRAY_SIZE(mdba_mdb_eattr_nla_decoders), NULL);
102 # endif /* HAVE_STRUCT_BR_MDB_ENTRY */
105 static const nla_decoder_t mdba_mdb_entry_nla_decoders[] = {
106 [MDBA_MDB_ENTRY_INFO] = decode_mdba_mdb_entry_info
110 decode_mdba_mdb_entry(struct tcb *const tcp,
111 const kernel_ulong_t addr,
112 const unsigned int len,
113 const void *const opaque_data)
115 decode_nlattr(tcp, addr, len, rtnl_mdba_mdb_entry_attrs,
116 "MDBA_MDB_ENTRY_???", mdba_mdb_entry_nla_decoders,
117 ARRAY_SIZE(mdba_mdb_entry_nla_decoders), NULL);
122 static const nla_decoder_t mdba_mdb_nla_decoders[] = {
123 [MDBA_MDB_ENTRY] = decode_mdba_mdb_entry
127 decode_mdba_mdb(struct tcb *const tcp,
128 const kernel_ulong_t addr,
129 const unsigned int len,
130 const void *const opaque_data)
132 decode_nlattr(tcp, addr, len, rtnl_mdba_mdb_attrs, "MDBA_MDB_???",
133 mdba_mdb_nla_decoders,
134 ARRAY_SIZE(mdba_mdb_nla_decoders), NULL);
140 decode_multicast_router_type(struct tcb *const tcp,
141 const kernel_ulong_t addr,
142 const unsigned int len,
143 const void *const opaque_data)
147 if (!umove_or_printaddr(tcp, addr, &type))
148 printxval(multicast_router_types, type, "MDB_RTR_TYPE_???");
153 static const nla_decoder_t mdba_router_pattr_nla_decoders[] = {
154 [MDBA_ROUTER_PATTR_TIMER] = decode_nla_u32,
155 [MDBA_ROUTER_PATTR_TYPE] = decode_multicast_router_type
159 decode_mdba_router_port(struct tcb *const tcp,
160 const kernel_ulong_t addr,
161 const unsigned int len,
162 const void *const opaque_data)
166 if (len < sizeof(ifindex))
168 else if (!umove_or_printaddr(tcp, addr, &ifindex))
169 print_ifindex(ifindex);
171 const size_t offset = NLMSG_ALIGN(sizeof(ifindex));
174 decode_nlattr(tcp, addr + offset, len - offset,
175 rtnl_mdba_router_pattr_attrs,
176 "MDBA_ROUTER_PATTR_???",
177 mdba_router_pattr_nla_decoders,
178 ARRAY_SIZE(mdba_router_pattr_nla_decoders), NULL);
184 static const nla_decoder_t mdba_router_nla_decoders[] = {
185 [MDBA_ROUTER_PORT] = decode_mdba_router_port
189 decode_mdba_router(struct tcb *const tcp,
190 const kernel_ulong_t addr,
191 const unsigned int len,
192 const void *const opaque_data)
194 decode_nlattr(tcp, addr, len, rtnl_mdba_router_attrs, "MDBA_ROUTER_???",
195 mdba_router_nla_decoders,
196 ARRAY_SIZE(mdba_router_nla_decoders), NULL);
201 static const nla_decoder_t br_port_msg_nla_decoders[] = {
202 [MDBA_MDB] = decode_mdba_mdb,
203 [MDBA_ROUTER] = decode_mdba_router
206 DECL_NETLINK_ROUTE_DECODER(decode_br_port_msg)
208 struct br_port_msg bpm = { .family = family };
209 size_t offset = sizeof(bpm.family);
210 bool decode_nla = false;
212 PRINT_FIELD_XVAL("{", bpm, family, addrfams, "AF_???");
215 if (len >= sizeof(bpm)) {
216 if (!umoven_or_printaddr(tcp, addr + offset,
217 sizeof(bpm) - offset,
218 (char *) &bpm + offset)) {
219 PRINT_FIELD_IFINDEX("", bpm, ifindex);
226 offset = NLMSG_ALIGN(sizeof(bpm));
227 if (decode_nla && len > offset) {
229 decode_nlattr(tcp, addr + offset, len - offset,
230 rtnl_mdb_attrs, "MDBA_???",
231 br_port_msg_nla_decoders,
232 ARRAY_SIZE(br_port_msg_nla_decoders), NULL);