]> granicus.if.org Git - strace/blob - rtnl_mdb.c
tests: implement ioctl_evdev-success-v.test via ioctl_evdev-success.test
[strace] / rtnl_mdb.c
1 /*
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.
5  * All rights reserved.
6  *
7  * SPDX-License-Identifier: LGPL-2.1-or-later
8  */
9
10 #include "defs.h"
11
12 #ifdef HAVE_STRUCT_BR_PORT_MSG
13
14 # include "netlink_route.h"
15 # include "nlattr.h"
16 # include "print_fields.h"
17
18 # include <netinet/in.h>
19 # include <linux/if_bridge.h>
20 # include "netlink.h"
21
22 # ifdef HAVE_STRUCT_BR_MDB_ENTRY_FLAGS
23 #  include "xlat/mdb_flags.h"
24 # endif
25 # include "xlat/mdb_states.h"
26 # include "xlat/multicast_router_types.h"
27 # include "xlat/rtnl_mdb_attrs.h"
28 # include "xlat/rtnl_mdba_mdb_attrs.h"
29 # include "xlat/rtnl_mdba_mdb_eattr_attrs.h"
30 # include "xlat/rtnl_mdba_mdb_entry_attrs.h"
31 # include "xlat/rtnl_mdba_router_attrs.h"
32 # include "xlat/rtnl_mdba_router_pattr_attrs.h"
33
34 static const nla_decoder_t mdba_mdb_eattr_nla_decoders[] = {
35         [MDBA_MDB_EATTR_TIMER]  = decode_nla_u32
36 };
37
38 static bool
39 decode_mdba_mdb_entry_info(struct tcb *const tcp,
40                            const kernel_ulong_t addr,
41                            const unsigned int len,
42                            const void *const opaque_data)
43 {
44 # ifdef HAVE_STRUCT_BR_MDB_ENTRY
45         struct br_mdb_entry entry;
46
47         if (len < sizeof(entry))
48                 return false;
49         else if (!umove_or_printaddr(tcp, addr, &entry)) {
50                 PRINT_FIELD_IFINDEX("{", entry, ifindex);
51                 PRINT_FIELD_XVAL(", ", entry, state, mdb_states, "MDB_???");
52 #  ifdef HAVE_STRUCT_BR_MDB_ENTRY_FLAGS
53                 PRINT_FIELD_FLAGS(", ", entry, flags,
54                                   mdb_flags, "MDB_FLAGS_???");
55 #  endif
56 #  ifdef HAVE_STRUCT_BR_MDB_ENTRY_VID
57                 PRINT_FIELD_U(", ", entry, vid);
58 #  endif
59
60                 const int proto = ntohs(entry.addr.proto);
61
62                 tprints(", addr={");
63                 print_inet_addr(proto, &entry.addr.u,
64                                 sizeof(entry.addr.u), "u");
65                 tprints(", proto=htons(");
66                 printxval(addrfams, proto, "AF_???");
67                 tprints(")}}");
68         }
69
70         const size_t offset = NLMSG_ALIGN(sizeof(entry));
71         if (len > offset) {
72                 tprints(", ");
73                 decode_nlattr(tcp, addr + offset, len - offset,
74                               rtnl_mdba_mdb_eattr_attrs, "MDBA_MDB_EATTR_???",
75                               mdba_mdb_eattr_nla_decoders,
76                               ARRAY_SIZE(mdba_mdb_eattr_nla_decoders), NULL);
77         }
78
79         return true;
80 # else
81         return false;
82 # endif /* HAVE_STRUCT_BR_MDB_ENTRY */
83 }
84
85 static const nla_decoder_t mdba_mdb_entry_nla_decoders[] = {
86         [MDBA_MDB_ENTRY_INFO]   = decode_mdba_mdb_entry_info
87 };
88
89 static bool
90 decode_mdba_mdb_entry(struct tcb *const tcp,
91                       const kernel_ulong_t addr,
92                       const unsigned int len,
93                       const void *const opaque_data)
94 {
95         decode_nlattr(tcp, addr, len, rtnl_mdba_mdb_entry_attrs,
96                       "MDBA_MDB_ENTRY_???", mdba_mdb_entry_nla_decoders,
97                       ARRAY_SIZE(mdba_mdb_entry_nla_decoders), NULL);
98
99         return true;
100 }
101
102 static const nla_decoder_t mdba_mdb_nla_decoders[] = {
103         [MDBA_MDB_ENTRY]        = decode_mdba_mdb_entry
104 };
105
106 static bool
107 decode_mdba_mdb(struct tcb *const tcp,
108                 const kernel_ulong_t addr,
109                 const unsigned int len,
110                 const void *const opaque_data)
111 {
112         decode_nlattr(tcp, addr, len, rtnl_mdba_mdb_attrs, "MDBA_MDB_???",
113                       mdba_mdb_nla_decoders,
114                       ARRAY_SIZE(mdba_mdb_nla_decoders), NULL);
115
116         return true;
117 }
118
119 static bool
120 decode_multicast_router_type(struct tcb *const tcp,
121                              const kernel_ulong_t addr,
122                              const unsigned int len,
123                              const void *const opaque_data)
124 {
125         uint8_t type;
126
127         if (!umove_or_printaddr(tcp, addr, &type))
128                 printxval(multicast_router_types, type, "MDB_RTR_TYPE_???");
129
130         return true;
131 }
132
133 static const nla_decoder_t mdba_router_pattr_nla_decoders[] = {
134         [MDBA_ROUTER_PATTR_TIMER]       = decode_nla_u32,
135         [MDBA_ROUTER_PATTR_TYPE]        = decode_multicast_router_type
136 };
137
138 static bool
139 decode_mdba_router_port(struct tcb *const tcp,
140                         const kernel_ulong_t addr,
141                         const unsigned int len,
142                         const void *const opaque_data)
143 {
144         uint32_t ifindex;
145
146         if (len < sizeof(ifindex))
147                 return false;
148         else if (!umove_or_printaddr(tcp, addr, &ifindex))
149                 print_ifindex(ifindex);
150
151         const size_t offset = NLMSG_ALIGN(sizeof(ifindex));
152         if (len > offset) {
153                 tprints(", ");
154                 decode_nlattr(tcp, addr + offset, len - offset,
155                               rtnl_mdba_router_pattr_attrs,
156                               "MDBA_ROUTER_PATTR_???",
157                               mdba_router_pattr_nla_decoders,
158                               ARRAY_SIZE(mdba_router_pattr_nla_decoders), NULL);
159         }
160
161         return true;
162 }
163
164 static const nla_decoder_t mdba_router_nla_decoders[] = {
165         [MDBA_ROUTER_PORT]      = decode_mdba_router_port
166 };
167
168 static bool
169 decode_mdba_router(struct tcb *const tcp,
170                    const kernel_ulong_t addr,
171                    const unsigned int len,
172                    const void *const opaque_data)
173 {
174         decode_nlattr(tcp, addr, len, rtnl_mdba_router_attrs, "MDBA_ROUTER_???",
175                       mdba_router_nla_decoders,
176                       ARRAY_SIZE(mdba_router_nla_decoders), NULL);
177
178         return true;
179 }
180
181 static const nla_decoder_t br_port_msg_nla_decoders[] = {
182         [MDBA_MDB]      = decode_mdba_mdb,
183         [MDBA_ROUTER]   = decode_mdba_router
184 };
185
186 DECL_NETLINK_ROUTE_DECODER(decode_br_port_msg)
187 {
188         struct br_port_msg bpm = { .family = family };
189         size_t offset = sizeof(bpm.family);
190         bool decode_nla = false;
191
192         PRINT_FIELD_XVAL("{", bpm, family, addrfams, "AF_???");
193
194         tprints(", ");
195         if (len >= sizeof(bpm)) {
196                 if (!umoven_or_printaddr(tcp, addr + offset,
197                                          sizeof(bpm) - offset,
198                                          (char *) &bpm + offset)) {
199                         PRINT_FIELD_IFINDEX("", bpm, ifindex);
200                         decode_nla = true;
201                 }
202         } else
203                 tprints("...");
204         tprints("}");
205
206         offset = NLMSG_ALIGN(sizeof(bpm));
207         if (decode_nla && len > offset) {
208                 tprints(", ");
209                 decode_nlattr(tcp, addr + offset, len - offset,
210                               rtnl_mdb_attrs, "MDBA_???",
211                               br_port_msg_nla_decoders,
212                               ARRAY_SIZE(br_port_msg_nla_decoders), NULL);
213         }
214 }
215
216 #endif