1 /*
2 * Copyright (c) 2016 Fabien Siron <fabien.siron@epita.fr>
3 * Copyright (c) 2017 JingPiao Chen <chenjingpiao@gmail.com>
4 * Copyright (c) 2016-2023 The strace developers.
5 * All rights reserved.
6 *
7 * SPDX-License-Identifier: LGPL-2.1-or-later
8 */
9
10 #include "defs.h"
11 #include "netlink_route.h"
12 #include "nlattr.h"
13
14 #include "netlink.h"
15
16 #include <netinet/in.h>
17
18 #include <linux/rtnetlink.h>
19 #include <linux/if_bridge.h>
20 #include <linux/if_link.h>
21 #include <linux/if_bridge.h>
22
23 #include "xlat/in6_addr_gen_mode.h"
24 #include "xlat/inet_devconf_indices.h"
25 #include "xlat/inet6_devconf_indices.h"
26 #include "xlat/inet6_if_flags.h"
27 #include "xlat/rtnl_ifla_af_spec_bridge_attrs.h"
28 #include "xlat/rtnl_ifla_af_spec_bridge_vlan_tunnel_info_attrs.h"
29 #include "xlat/rtnl_ifla_af_spec_inet_attrs.h"
30 #include "xlat/rtnl_ifla_af_spec_inet6_attrs.h"
31 #include "xlat/rtnl_ifla_af_spec_mctp_attrs.h"
32 #include "xlat/rtnl_ifla_bridge_flags.h"
33 #include "xlat/rtnl_ifla_bridge_modes.h"
34 #include "xlat/rtnl_ifla_brport_attrs.h"
35 #include "xlat/rtnl_ifla_br_boolopts.h"
36 #include "xlat/rtnl_ifla_br_boolopt_flags.h"
37 #include "xlat/rtnl_ifla_br_mcast_querier_attrs.h"
38 #include "xlat/rtnl_ifla_events.h"
39 #include "xlat/rtnl_ifla_ext_filter_flags.h"
40 #include "xlat/rtnl_ifla_info_attrs.h"
41 #include "xlat/rtnl_ifla_info_data_bridge_attrs.h"
42 #include "xlat/rtnl_ifla_info_data_tun_attrs.h"
43 #include "xlat/rtnl_ifla_port_attrs.h"
44 #include "xlat/rtnl_ifla_proto_down_reason_attrs.h"
45 #include "xlat/rtnl_ifla_vf_info_attrs.h"
46 #include "xlat/rtnl_ifla_vf_link_states.h"
47 #include "xlat/rtnl_ifla_vf_port_attrs.h"
48 #include "xlat/rtnl_ifla_vf_stats_attrs.h"
49 #include "xlat/rtnl_ifla_vf_vlan_list_attrs.h"
50 #include "xlat/rtnl_ifla_vfinfo_list_attrs.h"
51 #include "xlat/rtnl_ifla_xdp_attached_mode.h"
52 #include "xlat/rtnl_ifla_xdp_attrs.h"
53 #include "xlat/rtnl_link_attrs.h"
54 #include "xlat/snmp_icmp6_stats.h"
55 #include "xlat/snmp_ip_stats.h"
56 #include "xlat/tun_device_types.h"
57 #include "xlat/xdp_flags.h"
58
59 #define XLAT_MACROS_ONLY
60 # include "xlat/addrfams.h"
61 #undef XLAT_MACROS_ONLY
62
63 static bool
64 decode_ifla_hwaddr(struct tcb *const tcp,
65 const kernel_ulong_t addr,
66 const unsigned int len,
67 const void *const opaque_data)
68 {
69 const struct ifinfomsg *ifinfo = (const struct ifinfomsg *) opaque_data;
70
71 return decode_nla_hwaddr_family(tcp, addr, len, ifinfo->ifi_family);
72 }
73
74 static bool
75 decode_rtnl_link_stats(struct tcb *const tcp,
76 const kernel_ulong_t addr,
77 const unsigned int len,
78 const void *const opaque_data)
79 {
80 struct rtnl_link_stats st;
81 const unsigned int min_size =
82 offsetofend(struct rtnl_link_stats, tx_compressed);
83 const unsigned int def_size = sizeof(st);
84 const unsigned int size =
85 (len >= def_size) ? def_size :
86 ((len == min_size) ? min_size : 0);
87
88 if (!size)
89 return false;
90
91 if (!umoven_or_printaddr(tcp, addr, size, &st)) {
92 tprint_struct_begin();
93 PRINT_FIELD_U(st, rx_packets);
94 tprint_struct_next();
95 PRINT_FIELD_U(st, tx_packets);
96 tprint_struct_next();
97 PRINT_FIELD_U(st, rx_bytes);
98 tprint_struct_next();
99 PRINT_FIELD_U(st, tx_bytes);
100 tprint_struct_next();
101 PRINT_FIELD_U(st, rx_errors);
102 tprint_struct_next();
103 PRINT_FIELD_U(st, tx_errors);
104 tprint_struct_next();
105 PRINT_FIELD_U(st, rx_dropped);
106 tprint_struct_next();
107 PRINT_FIELD_U(st, tx_dropped);
108 tprint_struct_next();
109 PRINT_FIELD_U(st, multicast);
110 tprint_struct_next();
111 PRINT_FIELD_U(st, collisions);
112
113 tprint_struct_next();
114 PRINT_FIELD_U(st, rx_length_errors);
115 tprint_struct_next();
116 PRINT_FIELD_U(st, rx_over_errors);
117 tprint_struct_next();
118 PRINT_FIELD_U(st, rx_crc_errors);
119 tprint_struct_next();
120 PRINT_FIELD_U(st, rx_frame_errors);
121 tprint_struct_next();
122 PRINT_FIELD_U(st, rx_fifo_errors);
123 tprint_struct_next();
124 PRINT_FIELD_U(st, rx_missed_errors);
125
126 tprint_struct_next();
127 PRINT_FIELD_U(st, tx_aborted_errors);
128 tprint_struct_next();
129 PRINT_FIELD_U(st, tx_carrier_errors);
130 tprint_struct_next();
131 PRINT_FIELD_U(st, tx_fifo_errors);
132 tprint_struct_next();
133 PRINT_FIELD_U(st, tx_heartbeat_errors);
134 tprint_struct_next();
135 PRINT_FIELD_U(st, tx_window_errors);
136
137 tprint_struct_next();
138 PRINT_FIELD_U(st, rx_compressed);
139 tprint_struct_next();
140 PRINT_FIELD_U(st, tx_compressed);
141
142 if (len >= def_size) {
143 tprint_struct_next();
144 PRINT_FIELD_U(st, rx_nohandler);
145 }
146 tprint_struct_end();
147 }
148
149 return true;
150 }
151
152 static bool
153 decode_ifla_bridge_id(struct tcb *const tcp,
154 const kernel_ulong_t addr,
155 const unsigned int len,
156 const void *const opaque_data)
157 {
158 struct ifla_bridge_id id;
159
160 if (len < sizeof(id))
161 return false;
162 else if (!umove_or_printaddr(tcp, addr, &id)) {
163 tprint_struct_begin();
164 PRINT_FIELD_ARRAY(id, prio, tcp,
165 print_uint_array_member);
166 tprint_struct_next();
167 PRINT_FIELD_MAC(id, addr);
168 tprint_struct_end();
169 }
170
171 return true;
172 }
173
174 static const nla_decoder_t ifla_brport_nla_decoders[] = {
175 [IFLA_BRPORT_STATE] = decode_nla_u8,
176 [IFLA_BRPORT_PRIORITY] = decode_nla_u16,
177 [IFLA_BRPORT_COST] = decode_nla_u32,
178 [IFLA_BRPORT_MODE] = decode_nla_u8,
179 [IFLA_BRPORT_GUARD] = decode_nla_u8,
180 [IFLA_BRPORT_PROTECT] = decode_nla_u8,
181 [IFLA_BRPORT_FAST_LEAVE] = decode_nla_u8,
182 [IFLA_BRPORT_LEARNING] = decode_nla_u8,
183 [IFLA_BRPORT_UNICAST_FLOOD] = decode_nla_u8,
184 [IFLA_BRPORT_PROXYARP] = decode_nla_u8,
185 [IFLA_BRPORT_LEARNING_SYNC] = decode_nla_u8,
186 [IFLA_BRPORT_PROXYARP_WIFI] = decode_nla_u8,
187 [IFLA_BRPORT_ROOT_ID] = decode_ifla_bridge_id,
188 [IFLA_BRPORT_BRIDGE_ID] = decode_ifla_bridge_id,
189 [IFLA_BRPORT_DESIGNATED_PORT] = decode_nla_u16,
190 [IFLA_BRPORT_DESIGNATED_COST] = decode_nla_u16,
191 [IFLA_BRPORT_ID] = decode_nla_u16,
192 [IFLA_BRPORT_NO] = decode_nla_u16,
193 [IFLA_BRPORT_TOPOLOGY_CHANGE_ACK] = decode_nla_u8,
194 [IFLA_BRPORT_CONFIG_PENDING] = decode_nla_u8,
195 [IFLA_BRPORT_MESSAGE_AGE_TIMER] = decode_nla_clock_t,
196 [IFLA_BRPORT_FORWARD_DELAY_TIMER] = decode_nla_clock_t,
197 [IFLA_BRPORT_HOLD_TIMER] = decode_nla_clock_t,
198 [IFLA_BRPORT_FLUSH] = NULL,
199 [IFLA_BRPORT_MULTICAST_ROUTER] = decode_nla_u8,
200 [IFLA_BRPORT_PAD] = NULL,
201 [IFLA_BRPORT_MCAST_FLOOD] = decode_nla_u8,
202 [IFLA_BRPORT_MCAST_TO_UCAST] = decode_nla_u8,
203 [IFLA_BRPORT_VLAN_TUNNEL] = decode_nla_u8,
204 [IFLA_BRPORT_BCAST_FLOOD] = decode_nla_u8,
205 [IFLA_BRPORT_GROUP_FWD_MASK] = decode_nla_x16,
206 [IFLA_BRPORT_NEIGH_SUPPRESS] = decode_nla_u8,
207 [IFLA_BRPORT_ISOLATED] = decode_nla_u8,
208 [IFLA_BRPORT_BACKUP_PORT] = decode_nla_ifindex,
209 [IFLA_BRPORT_MRP_RING_OPEN] = decode_nla_u8,
210 [IFLA_BRPORT_MRP_IN_OPEN] = decode_nla_u8,
211 [IFLA_BRPORT_MCAST_EHT_HOSTS_LIMIT] = decode_nla_u32,
212 [IFLA_BRPORT_MCAST_EHT_HOSTS_CNT] = decode_nla_u32,
213 [IFLA_BRPORT_LOCKED] = decode_nla_u8,
214 [IFLA_BRPORT_MAB] = decode_nla_u8,
215 [IFLA_BRPORT_MCAST_N_GROUPS] = decode_nla_u32,
216 [IFLA_BRPORT_MCAST_MAX_GROUPS] = decode_nla_u32,
217 [IFLA_BRPORT_NEIGH_VLAN_SUPPRESS] = decode_nla_u8,
218 };
219
220 static bool
221 decode_ifla_inet6_flags(struct tcb *const tcp,
222 const kernel_ulong_t addr,
223 const unsigned int len,
224 const void *const opaque_data)
225 {
226 static const struct decode_nla_xlat_opts opts = {
227 inet6_if_flags, "IF_???",
228 .size = 4,
229 };
230
231 return decode_nla_flags(tcp, addr, len, &opts);
232 }
233
234 static bool
235 decode_ifla_inet6_conf(struct tcb *const tcp,
236 const kernel_ulong_t addr,
237 const unsigned int len,
238 const void *const opaque_data)
239 {
240 int elem;
241 size_t cnt = len / sizeof(elem);
242
243 if (!cnt)
244 return false;
245
246 print_array_ex(tcp, addr, cnt, &elem, sizeof(elem),
247 tfetch_mem, print_int_array_member, NULL,
248 PAF_PRINT_INDICES | XLAT_STYLE_FMT_D,
249 inet6_devconf_indices, "DEVCONF_???");
250
251 return true;
252 }
253
254 static bool
255 decode_ifla_inet6_stats(struct tcb *const tcp,
256 const kernel_ulong_t addr,
257 const unsigned int len,
258 const void *const opaque_data)
259 {
260 uint64_t elem;
261 size_t cnt = len / sizeof(elem);
262
263 if (!cnt)
264 return false;
265
266 print_array_ex(tcp, addr, cnt, &elem, sizeof(elem),
267 tfetch_mem, print_uint_array_member, NULL,
268 PAF_PRINT_INDICES | XLAT_STYLE_FMT_U,
269 snmp_ip_stats, "IPSTATS_MIB_???");
270
271 return true;
272 }
273
274 static bool
275 decode_ifla_inet6_cacheinfo(struct tcb *const tcp,
276 const kernel_ulong_t addr,
277 const unsigned int len,
278 const void *const opaque_data)
279 {
280 struct ifla_cacheinfo ci;
281
282 if (len < sizeof(ci))
283 return false;
284 else if (!umove_or_printaddr(tcp, addr, &ci)) {
285 tprint_struct_begin();
286 PRINT_FIELD_U(ci, max_reasm_len);
287 tprint_struct_next();
288 PRINT_FIELD_U(ci, tstamp);
289 tprint_struct_next();
290 PRINT_FIELD_U(ci, reachable_time);
291 tprint_struct_next();
292 PRINT_FIELD_U(ci, retrans_time);
293 tprint_struct_end();
294 }
295
296 return true;
297 }
298
299 static bool
300 decode_ifla_inet6_icmp6_stats(struct tcb *const tcp,
301 const kernel_ulong_t addr,
302 const unsigned int len,
303 const void *const opaque_data)
304 {
305 uint64_t elem;
306 size_t cnt = len / sizeof(elem);
307
308 if (!cnt)
309 return false;
310
311 print_array_ex(tcp, addr, cnt, &elem, sizeof(elem),
312 tfetch_mem, print_uint_array_member, NULL,
313 PAF_PRINT_INDICES | XLAT_STYLE_FMT_U,
314 snmp_icmp6_stats, "ICMP6_MIB_???");
315
316 return true;
317 }
318
319 static bool
320 decode_ifla_inet6_agm(struct tcb *const tcp,
321 const kernel_ulong_t addr,
322 const unsigned int len,
323 const void *const opaque_data)
324 {
325 static const struct decode_nla_xlat_opts opts = {
326 in6_addr_gen_mode, "IN6_ADDR_GEN_MODE_???",
327 .size = 1,
328 };
329
330 return decode_nla_xval(tcp, addr, len, &opts);
331 }
332
333 static const nla_decoder_t ifla_inet6_nla_decoders[] = {
334 [IFLA_INET6_FLAGS] = decode_ifla_inet6_flags,
335 [IFLA_INET6_CONF] = decode_ifla_inet6_conf,
336 [IFLA_INET6_STATS] = decode_ifla_inet6_stats,
337 [IFLA_INET6_MCAST] = NULL, /* unused */
338 [IFLA_INET6_CACHEINFO] = decode_ifla_inet6_cacheinfo,
339 [IFLA_INET6_ICMP6STATS] = decode_ifla_inet6_icmp6_stats,
340 [IFLA_INET6_TOKEN] = decode_nla_in6_addr,
341 [IFLA_INET6_ADDR_GEN_MODE] = decode_ifla_inet6_agm,
342 [IFLA_INET6_RA_MTU] = decode_nla_u32,
343 };
344
345 static bool
346 decode_ifla_protinfo(struct tcb *const tcp,
347 const kernel_ulong_t addr,
348 const unsigned int len,
349 const void *const opaque_data)
350 {
351 static const struct af_spec_decoder_desc protos[] = {
352 { AF_BRIDGE, rtnl_ifla_brport_attrs, "IFLA_BRPORT_???",
353 ARRSZ_PAIR(ifla_brport_nla_decoders) },
354 /*
355 * For AF_INET6, it is the same as for IFLA_AF_SPEC, see
356 * the call sites of net/ipv6/addrconf.c:inet6_fill_ifla6_attrs.
357 */
358 { AF_INET6, rtnl_ifla_af_spec_inet6_attrs, "IFLA_INET6_???",
359 ARRSZ_PAIR(ifla_inet6_nla_decoders) },
360 };
361
362 const struct ifinfomsg *ifinfo = (const struct ifinfomsg *) opaque_data;
363
364 decode_nla_af_spec(tcp, addr, len,
365 ifinfo->ifi_family, ARRSZ_PAIR(protos));
366
367 return true;
368 }
369
370 static bool
371 decode_rtnl_link_ifmap(struct tcb *const tcp,
372 const kernel_ulong_t addr,
373 const unsigned int len,
374 const void *const opaque_data)
375 {
376 struct rtnl_link_ifmap map;
377 const unsigned int sizeof_ifmap =
378 offsetofend(struct rtnl_link_ifmap, port);
379
380 if (len < sizeof_ifmap)
381 return false;
382 else if (!umoven_or_printaddr(tcp, addr, sizeof_ifmap, &map)) {
383 tprint_struct_begin();
384 PRINT_FIELD_X(map, mem_start);
385 tprint_struct_next();
386 PRINT_FIELD_X(map, mem_end);
387 tprint_struct_next();
388 PRINT_FIELD_X(map, base_addr);
389 tprint_struct_next();
390 PRINT_FIELD_U(map, irq);
391 tprint_struct_next();
392 PRINT_FIELD_U(map, dma);
393 tprint_struct_next();
394 PRINT_FIELD_U(map, port);
395 tprint_struct_end();
396 }
397
398 return true;
399 }
400
401 static void
402 update_ctx_str(struct tcb *const tcp,
403 const kernel_ulong_t addr, const unsigned int len,
404 char *const str, const size_t sz)
405 {
406 memset(str, '\0', sz);
407
408 if (len >= sz)
409 return;
410
411 if (umoven(tcp, addr, len, str) < 0 || strnlen(str, sz) > len) {
412 /*
413 * If we haven't seen NUL or an error occurred, set str
414 * to an empty string.
415 */
416 str[0] = '\0';
417 return;
418 }
419 }
420
421 static bool
422 decode_nla_linkinfo_kind(struct tcb *const tcp,
423 const kernel_ulong_t addr,
424 const unsigned int len,
425 const void *const opaque_data)
426 {
427 struct ifla_linkinfo_ctx *ctx = (void *) opaque_data;
428
429 update_ctx_str(tcp, addr, len, ARRSZ_PAIR(ctx->kind));
430
431 printstr_ex(tcp, addr, len, QUOTE_0_TERMINATED);
432
433 return true;
434 }
435
436 static bool
437 decode_nla_linkinfo_xstats_can(struct tcb *const tcp,
438 const kernel_ulong_t addr,
439 const unsigned int len,
440 const void *const opaque_data)
441 {
442 struct strace_can_device_stats {
443 uint32_t bus_error;
444 uint32_t error_warning;
445 uint32_t error_passive;
446 uint32_t bus_off;
447 uint32_t arbitration_lost;
448 uint32_t restarts;
449 } st;
450 const unsigned int def_size = sizeof(st);
451 const unsigned int size = (len >= def_size) ? def_size : 0;
452
453 if (!size)
454 return false;
455
456 if (umoven_or_printaddr(tcp, addr, size, &st))
457 return true;
458
459 tprint_struct_begin();
460 PRINT_FIELD_U(st, bus_error);
461 tprint_struct_next();
462 PRINT_FIELD_U(st, error_warning);
463 tprint_struct_next();
464 PRINT_FIELD_U(st, error_passive);
465 tprint_struct_next();
466 PRINT_FIELD_U(st, bus_off);
467 tprint_struct_next();
468 PRINT_FIELD_U(st, arbitration_lost);
469 tprint_struct_next();
470 PRINT_FIELD_U(st, restarts);
471 tprint_struct_end();
472
473 return true;
474 }
475
476 static bool
477 decode_nla_linkinfo_xstats(struct tcb *const tcp,
478 const kernel_ulong_t addr,
479 const unsigned int len,
480 const void *const opaque_data)
481 {
482 struct ifla_linkinfo_ctx *ctx = (void *) opaque_data;
483 nla_decoder_t func = NULL;
484
485 if (!strcmp(ctx->kind, "can"))
486 func = decode_nla_linkinfo_xstats_can;
487
488 if (func)
489 return func(tcp, addr, len, opaque_data);
490
491 return false;
492 }
493
494 static bool
495 decode_ifla_br_boolopt(struct tcb *const tcp,
496 const kernel_ulong_t addr,
497 const unsigned int len,
498 const void *const opaque_data)
499 {
500 struct br_boolopt_multi bom;
501
502 if (len < sizeof(bom))
503 return false;
504
505 if (umoven_or_printaddr(tcp, addr, sizeof(bom), &bom))
506 return true;
507
508 tprint_struct_begin();
509 PRINT_FIELD_FLAGS(bom, optval, rtnl_ifla_br_boolopt_flags,
510 "1<<BR_BOOLOPT_???");
511 tprint_struct_next();
512 PRINT_FIELD_FLAGS(bom, optmask, rtnl_ifla_br_boolopt_flags,
513 "1<<BR_BOOLOPT_???");
514 tprint_struct_end();
515
516 return true;
517 }
518
519 static const nla_decoder_t ifla_br_mcast_querier_decoders[] = {
520 [BRIDGE_QUERIER_UNSPEC] = NULL,
521 [BRIDGE_QUERIER_IP_ADDRESS] = decode_nla_in_addr,
522 [BRIDGE_QUERIER_IP_PORT] = decode_nla_ifindex,
523 [BRIDGE_QUERIER_IP_OTHER_TIMER] = decode_nla_clock_t,
524 [BRIDGE_QUERIER_PAD] = NULL,
525 [BRIDGE_QUERIER_IPV6_ADDRESS] = decode_nla_in6_addr,
526 [BRIDGE_QUERIER_IPV6_PORT] = decode_nla_ifindex,
527 [BRIDGE_QUERIER_IPV6_OTHER_TIMER] = decode_nla_clock_t,
528 };
529
530 static bool
531 decode_ifla_br_mcast_qstate(struct tcb *const tcp,
532 const kernel_ulong_t addr,
533 const unsigned int len,
534 const void *const opaque_data)
535 {
536 decode_nlattr(tcp, addr, len, rtnl_ifla_br_mcast_querier_attrs,
537 "BRIDGE_QUERIER_???",
538 ARRSZ_PAIR(ifla_br_mcast_querier_decoders), opaque_data);
539
540 return true;
541 }
542
543 static const nla_decoder_t ifla_info_data_bridge_nla_decoders[] = {
544 [IFLA_BR_UNSPEC] = NULL,
545 [IFLA_BR_FORWARD_DELAY] = decode_nla_clock_t,
546 [IFLA_BR_HELLO_TIME] = decode_nla_clock_t,
547 [IFLA_BR_MAX_AGE] = decode_nla_clock_t,
548 [IFLA_BR_AGEING_TIME] = decode_nla_clock_t,
549 [IFLA_BR_STP_STATE] = decode_nla_u32,
550 [IFLA_BR_PRIORITY] = decode_nla_u16,
551 [IFLA_BR_VLAN_FILTERING] = decode_nla_u8,
552 [IFLA_BR_VLAN_PROTOCOL] = decode_nla_ether_proto,
553 [IFLA_BR_GROUP_FWD_MASK] = decode_nla_x16,
554 [IFLA_BR_ROOT_ID] = decode_ifla_bridge_id,
555 [IFLA_BR_BRIDGE_ID] = decode_ifla_bridge_id,
556 [IFLA_BR_ROOT_PORT] = decode_nla_u16,
557 [IFLA_BR_ROOT_PATH_COST] = decode_nla_u32,
558 [IFLA_BR_TOPOLOGY_CHANGE] = decode_nla_u8,
559 [IFLA_BR_TOPOLOGY_CHANGE_DETECTED] = decode_nla_u8,
560 [IFLA_BR_HELLO_TIMER] = decode_nla_clock_t,
561 [IFLA_BR_TCN_TIMER] = decode_nla_clock_t,
562 [IFLA_BR_TOPOLOGY_CHANGE_TIMER] = decode_nla_clock_t,
563 [IFLA_BR_GC_TIMER] = decode_nla_clock_t,
564 [IFLA_BR_GROUP_ADDR] = decode_nla_hwaddr_nofamily,
565 [IFLA_BR_FDB_FLUSH] = NULL, /* unspecified */
566 [IFLA_BR_MCAST_ROUTER] = decode_nla_u8,
567 [IFLA_BR_MCAST_SNOOPING] = decode_nla_u8,
568 [IFLA_BR_MCAST_QUERY_USE_IFADDR] = decode_nla_u8,
569 [IFLA_BR_MCAST_QUERIER] = decode_nla_u8,
570 [IFLA_BR_MCAST_HASH_ELASTICITY] = decode_nla_u32,
571 [IFLA_BR_MCAST_HASH_MAX] = decode_nla_u32,
572 [IFLA_BR_MCAST_LAST_MEMBER_CNT] = decode_nla_u32,
573 [IFLA_BR_MCAST_STARTUP_QUERY_CNT] = decode_nla_u32,
574 [IFLA_BR_MCAST_LAST_MEMBER_INTVL] = decode_nla_clock_t,
575 [IFLA_BR_MCAST_MEMBERSHIP_INTVL] = decode_nla_clock_t,
576 [IFLA_BR_MCAST_QUERIER_INTVL] = decode_nla_clock_t,
577 [IFLA_BR_MCAST_QUERY_INTVL] = decode_nla_clock_t,
578 [IFLA_BR_MCAST_QUERY_RESPONSE_INTVL] = decode_nla_clock_t,
579 [IFLA_BR_MCAST_STARTUP_QUERY_INTVL] = decode_nla_clock_t,
580 [IFLA_BR_NF_CALL_IPTABLES] = decode_nla_u8,
581 [IFLA_BR_NF_CALL_IP6TABLES] = decode_nla_u8,
582 [IFLA_BR_NF_CALL_ARPTABLES] = decode_nla_u8,
583 [IFLA_BR_VLAN_DEFAULT_PVID] = decode_nla_u16,
584 [IFLA_BR_PAD] = NULL,
585 [IFLA_BR_VLAN_STATS_ENABLED] = decode_nla_u8,
586 [IFLA_BR_MCAST_STATS_ENABLED] = decode_nla_u8,
587 [IFLA_BR_MCAST_IGMP_VERSION] = decode_nla_u8,
588 [IFLA_BR_MCAST_MLD_VERSION] = decode_nla_u8,
589 [IFLA_BR_VLAN_STATS_PER_PORT] = decode_nla_u8,
590 [IFLA_BR_MULTI_BOOLOPT] = decode_ifla_br_boolopt,
591 [IFLA_BR_MCAST_QUERIER_STATE] = decode_ifla_br_mcast_qstate,
592 };
593
594 static bool
595 decode_nla_linkinfo_data_bridge(struct tcb *const tcp,
596 const kernel_ulong_t addr,
597 const unsigned int len,
598 const void *const opaque_data)
599 {
600 decode_nlattr(tcp, addr, len, rtnl_ifla_info_data_bridge_attrs,
601 "IFLA_BR_???",
602 ARRSZ_PAIR(ifla_info_data_bridge_nla_decoders),
603 opaque_data);
604
605 return true;
606 }
607
608 static bool
609 decode_nla_tun_type(struct tcb *const tcp,
610 const kernel_ulong_t addr,
611 const unsigned int len,
612 const void *const opaque_data)
613 {
614 static const struct decode_nla_xlat_opts opts = {
615 .xlat = tun_device_types,
616 .dflt = "IFF_???",
617 .size = 1,
618 };
619
620 return decode_nla_xval(tcp, addr, len, &opts);
621 }
622
623 static const nla_decoder_t ifla_info_data_tun_nla_decoders[] = {
624 [IFLA_TUN_UNSPEC] = NULL,
625 [IFLA_TUN_OWNER] = decode_nla_uid,
626 [IFLA_TUN_GROUP] = decode_nla_gid,
627 [IFLA_TUN_TYPE] = decode_nla_tun_type,
628 [IFLA_TUN_PI] = decode_nla_u8,
629 [IFLA_TUN_VNET_HDR] = decode_nla_u8,
630 [IFLA_TUN_PERSIST] = decode_nla_u8,
631 [IFLA_TUN_MULTI_QUEUE] = decode_nla_u8,
632 [IFLA_TUN_NUM_QUEUES] = decode_nla_u32,
633 [IFLA_TUN_NUM_DISABLED_QUEUES] = decode_nla_u32,
634 };
635
636 static bool
637 decode_nla_linkinfo_data_tun(struct tcb *const tcp,
638 const kernel_ulong_t addr,
639 const unsigned int len,
640 const void *const opaque_data)
641 {
642 decode_nlattr(tcp, addr, len, rtnl_ifla_info_data_tun_attrs,
643 "IFLA_TUN_???",
644 ARRSZ_PAIR(ifla_info_data_tun_nla_decoders),
645 opaque_data);
646
647 return true;
648 }
649
650 static bool
651 decode_nla_linkinfo_data(struct tcb *const tcp,
652 const kernel_ulong_t addr,
653 const unsigned int len,
654 const void *const opaque_data)
655 {
656 struct ifla_linkinfo_ctx *ctx = (void *) opaque_data;
657 nla_decoder_t func = NULL;
658
659 if (!strcmp(ctx->kind, "bridge"))
660 func = decode_nla_linkinfo_data_bridge;
661 else if (!strcmp(ctx->kind, "tun"))
662 func = decode_nla_linkinfo_data_tun;
663
664 if (func)
665 return func(tcp, addr, len, opaque_data);
666
667 return false;
668 }
669
670 static bool
671 decode_nla_linkinfo_slave_kind(struct tcb *const tcp,
672 const kernel_ulong_t addr,
673 const unsigned int len,
674 const void *const opaque_data)
675 {
676 struct ifla_linkinfo_ctx *ctx = (void *) opaque_data;
677
678 update_ctx_str(tcp, addr, len, ARRSZ_PAIR(ctx->slave_kind));
679
680 printstr_ex(tcp, addr, len, QUOTE_0_TERMINATED);
681
682 return true;
683 }
684
685 static bool
686 decode_nla_linkinfo_slave_data_bridge(struct tcb *const tcp,
687 const kernel_ulong_t addr,
688 const unsigned int len,
689 const void *const opaque_data)
690 {
691 decode_nlattr(tcp, addr, len, rtnl_ifla_brport_attrs,
692 "IFLA_BRPORT_???",
693 ARRSZ_PAIR(ifla_brport_nla_decoders),
694 opaque_data);
695
696 return true;
697 }
698
699 static bool
700 decode_nla_linkinfo_slave_data(struct tcb *const tcp,
701 const kernel_ulong_t addr,
702 const unsigned int len,
703 const void *const opaque_data)
704 {
705 struct ifla_linkinfo_ctx *ctx = (void *) opaque_data;
706 nla_decoder_t func = NULL;
707
708 if (!strcmp(ctx->slave_kind, "bridge"))
709 func = decode_nla_linkinfo_slave_data_bridge;
710
711 if (func)
712 return func(tcp, addr, len, opaque_data);
713
714 return false;
715 }
716
717 static const nla_decoder_t ifla_linkinfo_nla_decoders[] = {
718 [IFLA_INFO_KIND] = decode_nla_linkinfo_kind,
719 [IFLA_INFO_DATA] = decode_nla_linkinfo_data,
720 [IFLA_INFO_XSTATS] = decode_nla_linkinfo_xstats,
721 [IFLA_INFO_SLAVE_KIND] = decode_nla_linkinfo_slave_kind,
722 [IFLA_INFO_SLAVE_DATA] = decode_nla_linkinfo_slave_data,
723 };
724
725 static bool
726 decode_ifla_linkinfo(struct tcb *const tcp,
727 const kernel_ulong_t addr,
728 const unsigned int len,
729 const void *const opaque_data)
730 {
731 struct ifla_linkinfo_ctx ctx = { .kind = "", };
732
733 decode_nlattr(tcp, addr, len, rtnl_ifla_info_attrs,
734 "IFLA_INFO_???", ARRSZ_PAIR(ifla_linkinfo_nla_decoders),
735 &ctx);
736
737 return true;
738 }
739
740 static bool
741 decode_ifla_vf_mac(struct tcb *const tcp,
742 const kernel_ulong_t addr,
743 const unsigned int len,
744 const void *const opaque_data)
745 {
746 struct ifla_vf_mac ivm;
747
748 if (len < sizeof(ivm))
749 return false;
750 if (umove_or_printaddr(tcp, addr, &ivm))
751 return true;
752
753 tprint_struct_begin();
754 PRINT_FIELD_U(ivm, vf);
755 tprint_struct_next();
756 PRINT_FIELD_MAC(ivm, mac);
757 tprint_struct_end();
758
759 return true;
760 }
761
762 static bool
763 decode_ifla_vf_vlan(struct tcb *const tcp,
764 const kernel_ulong_t addr,
765 const unsigned int len,
766 const void *const opaque_data)
767 {
768 struct ifla_vf_vlan ivv;
769
770 if (len < sizeof(ivv))
771 return false;
772 if (umove_or_printaddr(tcp, addr, &ivv))
773 return true;
774
775 tprint_struct_begin();
776 PRINT_FIELD_U(ivv, vf);
777 tprint_struct_next();
778 PRINT_FIELD_U(ivv, vlan);
779 tprint_struct_next();
780 PRINT_FIELD_U(ivv, qos);
781 tprint_struct_end();
782
783 return true;
784 }
785
786 static bool
787 decode_ifla_vf_tx_rate(struct tcb *const tcp,
788 const kernel_ulong_t addr,
789 const unsigned int len,
790 const void *const opaque_data)
791 {
792 struct ifla_vf_tx_rate ivtr;
793
794 if (len < sizeof(ivtr))
795 return false;
796 if (umove_or_printaddr(tcp, addr, &ivtr))
797 return true;
798
799 tprint_struct_begin();
800 PRINT_FIELD_U(ivtr, vf);
801 tprint_struct_next();
802 PRINT_FIELD_U(ivtr, rate);
803 tprint_struct_end();
804
805 return true;
806 }
807
808 static bool
809 decode_ifla_vf_spoofchk(struct tcb *const tcp,
810 const kernel_ulong_t addr,
811 const unsigned int len,
812 const void *const opaque_data)
813 {
814 struct ifla_vf_spoofchk ivs;
815
816 if (len < sizeof(ivs))
817 return false;
818 if (umove_or_printaddr(tcp, addr, &ivs))
819 return true;
820
821 tprint_struct_begin();
822 PRINT_FIELD_U(ivs, vf);
823 tprint_struct_next();
824 PRINT_FIELD_U(ivs, setting);
825 tprint_struct_end();
826
827 return true;
828 }
829
830 static bool
831 decode_ifla_vf_link_state(struct tcb *const tcp,
832 const kernel_ulong_t addr,
833 const unsigned int len,
834 const void *const opaque_data)
835 {
836 struct ifla_vf_link_state ivls;
837
838 if (len < sizeof(ivls))
839 return false;
840 if (umove_or_printaddr(tcp, addr, &ivls))
841 return true;
842
843 tprint_struct_begin();
844 PRINT_FIELD_U(ivls, vf);
845 tprint_struct_next();
846 PRINT_FIELD_XVAL(ivls, link_state, rtnl_ifla_vf_link_states,
847 "IFLA_VF_LINK_STATE_???");
848 tprint_struct_end();
849
850 return true;
851 }
852
853 static bool
854 decode_ifla_vf_rate(struct tcb *const tcp,
855 const kernel_ulong_t addr,
856 const unsigned int len,
857 const void *const opaque_data)
858 {
859 struct ifla_vf_rate ivr;
860
861 if (len < sizeof(ivr))
862 return false;
863 if (umove_or_printaddr(tcp, addr, &ivr))
864 return true;
865
866 tprint_struct_begin();
867 PRINT_FIELD_U(ivr, vf);
868 tprint_struct_next();
869 PRINT_FIELD_U(ivr, min_tx_rate);
870 tprint_struct_next();
871 PRINT_FIELD_U(ivr, max_tx_rate);
872 tprint_struct_end();
873
874 return true;
875 }
876
877 static bool
878 decode_ifla_vf_rss_query_en(struct tcb *const tcp,
879 const kernel_ulong_t addr,
880 const unsigned int len,
881 const void *const opaque_data)
882 {
883 struct ifla_vf_rss_query_en ivrqe;
884
885 if (len < sizeof(ivrqe))
886 return false;
887 if (umove_or_printaddr(tcp, addr, &ivrqe))
888 return true;
889
890 tprint_struct_begin();
891 PRINT_FIELD_U(ivrqe, vf);
892 tprint_struct_next();
893 PRINT_FIELD_U(ivrqe, setting);
894 tprint_struct_end();
895
896 return true;
897 }
898
899 static const nla_decoder_t ifla_vf_stats_nla_decoders[] = {
900 [IFLA_VF_STATS_RX_PACKETS] = decode_nla_u64,
901 [IFLA_VF_STATS_TX_PACKETS] = decode_nla_u64,
902 [IFLA_VF_STATS_RX_BYTES] = decode_nla_u64,
903 [IFLA_VF_STATS_TX_BYTES] = decode_nla_u64,
904 [IFLA_VF_STATS_BROADCAST] = decode_nla_u64,
905 [IFLA_VF_STATS_MULTICAST] = decode_nla_u64,
906 [IFLA_VF_STATS_PAD] = NULL,
907 [IFLA_VF_STATS_RX_DROPPED] = decode_nla_u64,
908 [IFLA_VF_STATS_TX_DROPPED] = decode_nla_u64,
909 };
910
911 static bool
912 decode_ifla_vf_stats(struct tcb *const tcp,
913 const kernel_ulong_t addr,
914 const unsigned int len,
915 const void *const opaque_data)
916 {
917 decode_nlattr(tcp, addr, len, rtnl_ifla_vf_stats_attrs,
918 "IFLA_VF_STATS_???",
919 ARRSZ_PAIR(ifla_vf_stats_nla_decoders),
920 opaque_data);
921
922 return true;
923 }
924
925 static bool
926 decode_ifla_vf_trust(struct tcb *const tcp,
927 const kernel_ulong_t addr,
928 const unsigned int len,
929 const void *const opaque_data)
930 {
931 struct ifla_vf_trust ivt;
932
933 if (len < sizeof(ivt))
934 return false;
935 if (umove_or_printaddr(tcp, addr, &ivt))
936 return true;
937
938 tprint_struct_begin();
939 PRINT_FIELD_U(ivt, vf);
940 tprint_struct_next();
941 PRINT_FIELD_U(ivt, setting);
942 tprint_struct_end();
943
944 return true;
945 }
946
947 static bool
948 decode_ifla_vf_guid(struct tcb *const tcp,
949 const kernel_ulong_t addr,
950 const unsigned int len,
951 const void *const opaque_data)
952 {
953 /*
954 * This all is broken because struct ifla_vf_guid.guid is not naturally
955 * aligned; trying to handle both possible attribute sizes.
956 */
957 union {
958 struct {
959 uint32_t vf;
960 uint64_t guid;
961 } ATTRIBUTE_PACKED ivg_32;
962 struct {
963 uint32_t vf;
964 uint64_t ATTRIBUTE_ALIGNED(8) guid;
965 } ivg_64;
966 } ivg;
967
968 static_assert(sizeof(struct ifla_vf_guid) == sizeof(ivg.ivg_32)
969 || sizeof(struct ifla_vf_guid) == sizeof(ivg.ivg_64),
970 "Unexpected struct ifla_vf_guid size");
971 CHECK_TYPE_SIZE(ivg.ivg_32, 12);
972 CHECK_TYPE_SIZE(ivg.ivg_64, 16);
973
974 switch (len) {
975 case sizeof(ivg.ivg_32):
976 case sizeof(ivg.ivg_64):
977 break;
978 default:
979 return false;
980 }
981
982 if (umoven_or_printaddr(tcp, addr, len, &ivg))
983 return true;
984
985 switch (len) {
986 case sizeof(ivg.ivg_32):
987 tprint_struct_begin();
988 PRINT_FIELD_U(ivg.ivg_32, vf);
989 tprint_struct_next();
990 PRINT_FIELD_X(ivg.ivg_32, guid);
991 tprint_struct_end();
992 break;
993
994 case sizeof(ivg.ivg_64):
995 tprint_struct_begin();
996 PRINT_FIELD_U(ivg.ivg_64, vf);
997 tprint_struct_next();
998 PRINT_FIELD_X(ivg.ivg_64, guid);
999 tprint_struct_end();
1000 break;
1001 }
1002
1003 return true;
1004 }
1005
1006 static bool
1007 decode_ifla_vf_vlan_info(struct tcb *const tcp,
1008 const kernel_ulong_t addr,
1009 const unsigned int len,
1010 const void *const opaque_data)
1011 {
1012 struct ifla_vf_vlan_info ivvi;
1013
1014 if (len < sizeof(ivvi))
1015 return false;
1016 if (umove_or_printaddr(tcp, addr, &ivvi))
1017 return true;
1018
1019 tprint_struct_begin();
1020 PRINT_FIELD_U(ivvi, vf);
1021 tprint_struct_next();
1022 PRINT_FIELD_U(ivvi, vlan);
1023 tprint_struct_next();
1024 PRINT_FIELD_U(ivvi, qos);
1025 tprint_struct_next();
1026 tprints_field_name("vlan_proto");
1027 tprints_arg_begin("htons");
1028 printxval(ethernet_protocols, ntohs(ivvi.vlan_proto), "ETH_P_???");
1029 tprint_arg_end();
1030 tprint_struct_end();
1031
1032 return true;
1033 }
1034
1035 static const nla_decoder_t ifla_vf_vlan_list_nla_decoders[] = {
1036 [IFLA_VF_VLAN_INFO_UNSPEC] = NULL,
1037 [IFLA_VF_VLAN_INFO] = decode_ifla_vf_vlan_info,
1038 };
1039
1040 static bool
1041 decode_ifla_vf_vlan_list(struct tcb *const tcp,
1042 const kernel_ulong_t addr,
1043 const unsigned int len,
1044 const void *const opaque_data)
1045 {
1046 decode_nlattr(tcp, addr, len, rtnl_ifla_vf_vlan_list_attrs,
1047 "IFLA_VF_VLAN_INFO_???",
1048 ARRSZ_PAIR(ifla_vf_vlan_list_nla_decoders),
1049 opaque_data);
1050
1051 return true;
1052 }
1053
1054 static bool
1055 decode_ifla_vf_broadcast(struct tcb *const tcp,
1056 const kernel_ulong_t addr,
1057 const unsigned int len,
1058 const void *const opaque_data)
1059 {
1060 struct ifla_vf_broadcast ivb;
1061
1062 if (len < sizeof(ivb))
1063 return false;
1064 if (umove_or_printaddr(tcp, addr, &ivb))
1065 return true;
1066
1067 tprint_struct_begin();
1068 PRINT_FIELD_MAC(ivb, broadcast);
1069 tprint_struct_end();
1070
1071 return true;
1072 }
1073
1074 static const nla_decoder_t ifla_vf_info_nla_decoders[] = {
1075 [IFLA_VF_UNSPEC] = NULL,
1076 [IFLA_VF_MAC] = decode_ifla_vf_mac,
1077 [IFLA_VF_VLAN] = decode_ifla_vf_vlan,
1078 [IFLA_VF_TX_RATE] = decode_ifla_vf_tx_rate,
1079 [IFLA_VF_SPOOFCHK] = decode_ifla_vf_spoofchk,
1080 [IFLA_VF_LINK_STATE] = decode_ifla_vf_link_state,
1081 [IFLA_VF_RATE] = decode_ifla_vf_rate,
1082 [IFLA_VF_RSS_QUERY_EN] = decode_ifla_vf_rss_query_en,
1083 [IFLA_VF_STATS] = decode_ifla_vf_stats,
1084 [IFLA_VF_TRUST] = decode_ifla_vf_trust,
1085 [IFLA_VF_IB_NODE_GUID] = decode_ifla_vf_guid,
1086 [IFLA_VF_IB_PORT_GUID] = decode_ifla_vf_guid,
1087 [IFLA_VF_VLAN_LIST] = decode_ifla_vf_vlan_list,
1088 [IFLA_VF_BROADCAST] = decode_ifla_vf_broadcast,
1089 };
1090
1091 static bool
1092 decode_ifla_vf_info(struct tcb *const tcp,
1093 const kernel_ulong_t addr,
1094 const unsigned int len,
1095 const void *const opaque_data)
1096 {
1097 decode_nlattr(tcp, addr, len, rtnl_ifla_vf_info_attrs,
1098 "IFLA_VF_???", ARRSZ_PAIR(ifla_vf_info_nla_decoders),
1099 opaque_data);
1100
1101 return true;
1102 }
1103
1104 static const nla_decoder_t ifla_vfinfo_list_nla_decoders[] = {
1105 [IFLA_VF_INFO_UNSPEC] = NULL,
1106 [IFLA_VF_INFO] = decode_ifla_vf_info,
1107 };
1108
1109 static bool
1110 decode_ifla_vfinfo_list(struct tcb *const tcp,
1111 const kernel_ulong_t addr,
1112 const unsigned int len,
1113 const void *const opaque_data)
1114 {
1115 decode_nlattr(tcp, addr, len, rtnl_ifla_vfinfo_list_attrs,
1116 "IFLA_VF_INFO_???",
1117 ARRSZ_PAIR(ifla_vfinfo_list_nla_decoders),
1118 opaque_data);
1119
1120 return true;
1121 }
1122
1123 bool
1124 decode_nla_rtnl_link_stats64(struct tcb *const tcp,
1125 const kernel_ulong_t addr,
1126 const unsigned int len,
1127 const void *const opaque_data)
1128 {
1129 struct rtnl_link_stats64 st;
1130 const unsigned int min_size =
1131 offsetofend(struct rtnl_link_stats64, tx_compressed);
1132 const unsigned int rx_nohandler_size =
1133 offsetofend(struct rtnl_link_stats64, rx_nohandler);
1134 const unsigned int def_size = sizeof(st);
1135 const unsigned int size =
1136 (len >= def_size)
1137 ? def_size
1138 : ((len == rx_nohandler_size)
1139 ? rx_nohandler_size
1140 : ((len == min_size) ? min_size : 0));
1141
1142 if (!size)
1143 return false;
1144
1145 if (!umoven_or_printaddr(tcp, addr, size, &st)) {
1146 tprint_struct_begin();
1147 PRINT_FIELD_U(st, rx_packets);
1148 tprint_struct_next();
1149 PRINT_FIELD_U(st, tx_packets);
1150 tprint_struct_next();
1151 PRINT_FIELD_U(st, rx_bytes);
1152 tprint_struct_next();
1153 PRINT_FIELD_U(st, tx_bytes);
1154 tprint_struct_next();
1155 PRINT_FIELD_U(st, rx_errors);
1156 tprint_struct_next();
1157 PRINT_FIELD_U(st, tx_errors);
1158 tprint_struct_next();
1159 PRINT_FIELD_U(st, rx_dropped);
1160 tprint_struct_next();
1161 PRINT_FIELD_U(st, tx_dropped);
1162 tprint_struct_next();
1163 PRINT_FIELD_U(st, multicast);
1164 tprint_struct_next();
1165 PRINT_FIELD_U(st, collisions);
1166
1167 tprint_struct_next();
1168 PRINT_FIELD_U(st, rx_length_errors);
1169 tprint_struct_next();
1170 PRINT_FIELD_U(st, rx_over_errors);
1171 tprint_struct_next();
1172 PRINT_FIELD_U(st, rx_crc_errors);
1173 tprint_struct_next();
1174 PRINT_FIELD_U(st, rx_frame_errors);
1175 tprint_struct_next();
1176 PRINT_FIELD_U(st, rx_fifo_errors);
1177 tprint_struct_next();
1178 PRINT_FIELD_U(st, rx_missed_errors);
1179
1180 tprint_struct_next();
1181 PRINT_FIELD_U(st, tx_aborted_errors);
1182 tprint_struct_next();
1183 PRINT_FIELD_U(st, tx_carrier_errors);
1184 tprint_struct_next();
1185 PRINT_FIELD_U(st, tx_fifo_errors);
1186 tprint_struct_next();
1187 PRINT_FIELD_U(st, tx_heartbeat_errors);
1188 tprint_struct_next();
1189 PRINT_FIELD_U(st, tx_window_errors);
1190
1191 tprint_struct_next();
1192 PRINT_FIELD_U(st, rx_compressed);
1193 tprint_struct_next();
1194 PRINT_FIELD_U(st, tx_compressed);
1195
1196 if (len >= rx_nohandler_size) {
1197 tprint_struct_next();
1198 PRINT_FIELD_U(st, rx_nohandler);
1199
1200 if (len >= def_size) {
1201 tprint_struct_next();
1202 PRINT_FIELD_U(st, rx_otherhost_dropped);
1203 }
1204 }
1205 tprint_struct_end();
1206 }
1207
1208 return true;
1209 }
1210
1211 static bool
1212 decode_ifla_port_vsi(struct tcb *const tcp,
1213 const kernel_ulong_t addr,
1214 const unsigned int len,
1215 const void *const opaque_data)
1216 {
1217 struct ifla_port_vsi vsi;
1218
1219 if (len < sizeof(vsi))
1220 return false;
1221 if (umove_or_printaddr(tcp, addr, &vsi))
1222 return true;
1223
1224 tprint_struct_begin();
1225 PRINT_FIELD_U(vsi, vsi_mgr_id);
1226 tprint_struct_next();
1227 PRINT_FIELD_STRING(vsi, vsi_type_id, sizeof(vsi.vsi_type_id),
1228 QUOTE_FORCE_HEX);
1229 tprint_struct_next();
1230 PRINT_FIELD_U(vsi, vsi_type_version);
1231
1232 if (!IS_ARRAY_ZERO(vsi.pad)) {
1233 tprint_struct_next();
1234 PRINT_FIELD_HEX_ARRAY(vsi, pad);
1235 }
1236
1237 tprint_struct_end();
1238
1239 return true;
1240 }
1241
1242 static const nla_decoder_t ifla_port_nla_decoders[] = {
1243 [IFLA_PORT_VF] = decode_nla_u32,
1244 [IFLA_PORT_PROFILE] = decode_nla_str,
1245 [IFLA_PORT_VSI_TYPE] = decode_ifla_port_vsi,
1246 [IFLA_PORT_INSTANCE_UUID] = NULL, /* default parser */
1247 [IFLA_PORT_HOST_UUID] = NULL, /* default parser */
1248 [IFLA_PORT_REQUEST] = decode_nla_u8,
1249 [IFLA_PORT_RESPONSE] = decode_nla_u16
1250 };
1251
1252 static bool
1253 decode_ifla_port(struct tcb *const tcp,
1254 const kernel_ulong_t addr,
1255 const unsigned int len,
1256 const void *const opaque_data)
1257 {
1258 decode_nlattr(tcp, addr, len, rtnl_ifla_port_attrs,
1259 "IFLA_VF_PORT_???", ARRSZ_PAIR(ifla_port_nla_decoders),
1260 opaque_data);
1261
1262 return true;
1263 }
1264
1265 static const nla_decoder_t ifla_vf_port_nla_decoders[] = {
1266 [IFLA_VF_PORT] = decode_ifla_port
1267 };
1268
1269 static bool
1270 decode_ifla_vf_ports(struct tcb *const tcp,
1271 const kernel_ulong_t addr,
1272 const unsigned int len,
1273 const void *const opaque_data)
1274 {
1275 decode_nlattr(tcp, addr, len, rtnl_ifla_vf_port_attrs,
1276 "IFLA_VF_PORT_???", ARRSZ_PAIR(ifla_vf_port_nla_decoders),
1277 opaque_data);
1278
1279 return true;
1280 }
1281
1282 static bool
1283 decode_ifla_ext_mask(struct tcb *const tcp,
1284 const kernel_ulong_t addr,
1285 const unsigned int len,
1286 const void *const opaque_data)
1287 {
1288 static const struct decode_nla_xlat_opts opts = {
1289 rtnl_ifla_ext_filter_flags, "RTEXT_FILTER_???", .size = 4,
1290 };
1291
1292 return decode_nla_flags(tcp, addr, len, &opts);
1293 }
1294
1295 static bool
1296 decode_ifla_xdp_flags(struct tcb *const tcp,
1297 const kernel_ulong_t addr,
1298 const unsigned int len,
1299 const void *const opaque_data)
1300 {
1301 uint32_t flags;
1302
1303 if (len < sizeof(flags))
1304 return false;
1305 else if (!umove_or_printaddr(tcp, addr, &flags))
1306 printflags(xdp_flags, flags, "XDP_FLAGS_???");
1307
1308 return true;
1309 }
1310
1311 static bool
1312 decode_ifla_xdp_attached(struct tcb *const tcp,
1313 const kernel_ulong_t addr,
1314 const unsigned int len,
1315 const void *const opaque_data)
1316 {
1317 static const struct decode_nla_xlat_opts opts = {
1318 .xlat = rtnl_ifla_xdp_attached_mode,
1319 .dflt = "XDP_ATTACHED_???",
1320 .size = 1,
1321 };
1322
1323 return decode_nla_xval(tcp, addr, len, &opts);
1324 }
1325
1326 static const nla_decoder_t ifla_xdp_nla_decoders[] = {
1327 [IFLA_XDP_FD] = decode_nla_fd,
1328 [IFLA_XDP_ATTACHED] = decode_ifla_xdp_attached,
1329 [IFLA_XDP_FLAGS] = decode_ifla_xdp_flags,
1330 [IFLA_XDP_PROG_ID] = decode_nla_u32,
1331 [IFLA_XDP_DRV_PROG_ID] = decode_nla_u32,
1332 [IFLA_XDP_SKB_PROG_ID] = decode_nla_u32,
1333 [IFLA_XDP_HW_PROG_ID] = decode_nla_u32,
1334 [IFLA_XDP_EXPECTED_FD] = decode_nla_fd,
1335 };
1336
1337 static bool
1338 decode_ifla_xdp(struct tcb *const tcp,
1339 const kernel_ulong_t addr,
1340 const unsigned int len,
1341 const void *const opaque_data)
1342 {
1343 decode_nlattr(tcp, addr, len, rtnl_ifla_xdp_attrs,
1344 "IFLA_XDP_???", ARRSZ_PAIR(ifla_xdp_nla_decoders),
1345 opaque_data);
1346
1347 return true;
1348 }
1349
1350 static bool
1351 decode_ifla_event(struct tcb *const tcp,
1352 const kernel_ulong_t addr,
1353 const unsigned int len,
1354 const void *const opaque_data)
1355 {
1356 uint32_t ev;
1357
1358 if (len < sizeof(ev))
1359 return false;
1360 else if (!umove_or_printaddr(tcp, addr, &ev))
1361 printxval(rtnl_ifla_events, ev, "IFLA_EVENT_???");
1362
1363 return true;
1364 }
1365
1366
1367 static bool
1368 decode_ifla_inet_conf(struct tcb *const tcp,
1369 const kernel_ulong_t addr,
1370 const unsigned int len,
1371 const void *const opaque_data)
1372 {
1373 int elem;
1374 size_t cnt = len / sizeof(elem);
1375
1376 if (!cnt)
1377 return false;
1378
1379 print_array_ex(tcp, addr, cnt, &elem, sizeof(elem),
1380 tfetch_mem, print_int_array_member, NULL,
1381 PAF_PRINT_INDICES | XLAT_STYLE_FMT_D,
1382 inet_devconf_indices, "IPV4_DEVCONF_???");
1383
1384 return true;
1385 }
1386
1387 static const nla_decoder_t ifla_inet_nla_decoders[] = {
1388 [IFLA_INET_CONF] = decode_ifla_inet_conf,
1389 };
1390
1391 static const nla_decoder_t ifla_mctp_nla_decoders[] = {
1392 [IFLA_MCTP_UNSPEC] = NULL,
1393 [IFLA_MCTP_NET] = decode_nla_u32,
1394 };
1395
1396 static bool
1397 decode_ifla_af(struct tcb *const tcp,
1398 const kernel_ulong_t addr,
1399 const unsigned int len,
1400 const void *const opaque_data)
1401 {
1402 static const struct af_spec_decoder_desc protos[] = {
1403 { AF_INET, rtnl_ifla_af_spec_inet_attrs, "IFLA_INET_???",
1404 ARRSZ_PAIR(ifla_inet_nla_decoders) },
1405 { AF_INET6, rtnl_ifla_af_spec_inet6_attrs, "IFLA_INET6_???",
1406 ARRSZ_PAIR(ifla_inet6_nla_decoders) },
1407 { AF_MCTP, rtnl_ifla_af_spec_mctp_attrs, "IFLA_MCTP_???",
1408 ARRSZ_PAIR(ifla_mctp_nla_decoders) },
1409 };
1410
1411 decode_nla_af_spec(tcp, addr, len,
1412 (uintptr_t) opaque_data, ARRSZ_PAIR(protos));
1413
1414 return true;
1415 }
1416
1417 static bool
1418 decode_ifla_bridge_flags(struct tcb *const tcp,
1419 const kernel_ulong_t addr,
1420 const unsigned int len,
1421 const void *const opaque_data)
1422 {
1423 static const struct decode_nla_xlat_opts opts = {
1424 rtnl_ifla_bridge_flags, "BRIDGE_FLAGS_???", .size = 2,
1425 };
1426
1427 return decode_nla_flags(tcp, addr, len, &opts);
1428 }
1429
1430 static bool
1431 decode_ifla_bridge_mode(struct tcb *const tcp,
1432 const kernel_ulong_t addr,
1433 const unsigned int len,
1434 const void *const opaque_data)
1435 {
1436 static const struct decode_nla_xlat_opts opts = {
1437 rtnl_ifla_bridge_modes, "BRIDGE_MODE_???", .size = 2,
1438 };
1439
1440 return decode_nla_xval(tcp, addr, len, &opts);
1441 }
1442
1443 static bool
1444 decode_ifla_bridge_vlan_info(struct tcb *const tcp,
1445 const kernel_ulong_t addr,
1446 const unsigned int len,
1447 const void *const opaque_data)
1448 {
1449 struct bridge_vlan_info bvi;
1450
1451 if (len < sizeof(bvi))
1452 return false;
1453
1454 if (umove_or_printaddr(tcp, addr, &bvi))
1455 return true;
1456
1457 tprint_struct_begin();
1458 PRINT_FIELD_FLAGS(bvi, flags, nl_bridge_vlan_flags,
1459 "BRIDGE_VLAN_INFO_???");
1460 tprint_struct_next();
1461 PRINT_FIELD_U(bvi, vid);
1462 tprint_struct_end();
1463
1464 if (len > sizeof(bvi)) {
1465 tprint_array_next();
1466 printstr_ex(tcp, addr + sizeof(bvi), len - sizeof(bvi),
1467 QUOTE_FORCE_HEX);
1468 }
1469
1470 return true;
1471 }
1472
1473 static bool
1474 decode_bridge_vlan_info_flags(struct tcb *const tcp,
1475 const kernel_ulong_t addr,
1476 const unsigned int len,
1477 const void *const opaque_data)
1478 {
1479 static const struct decode_nla_xlat_opts opts = {
1480 nl_bridge_vlan_flags, "BRIDGE_VLAN_INFO_???", .size = 2,
1481 };
1482
1483 return decode_nla_flags(tcp, addr, len, &opts);
1484 }
1485
1486 static const nla_decoder_t ifla_af_spec_bridge_vlan_tunnel_info_decoders[] = {
1487 [IFLA_BRIDGE_VLAN_TUNNEL_UNSPEC] = NULL,
1488 [IFLA_BRIDGE_VLAN_TUNNEL_ID] = decode_nla_u32,
1489 [IFLA_BRIDGE_VLAN_TUNNEL_VID] = decode_nla_u16,
1490 [IFLA_BRIDGE_VLAN_TUNNEL_FLAGS] = decode_bridge_vlan_info_flags,
1491 };
1492
1493 static bool
1494 decode_ifla_bridge_vlan_tunnel_info(struct tcb *const tcp,
1495 const kernel_ulong_t addr,
1496 const unsigned int len,
1497 const void *const opaque_data)
1498 {
1499 decode_nlattr(tcp, addr, len,
1500 rtnl_ifla_af_spec_bridge_vlan_tunnel_info_attrs,
1501 "IFLA_BRIDGE_VLAN_TUNNEL_???",
1502 ARRSZ_PAIR(ifla_af_spec_bridge_vlan_tunnel_info_decoders),
1503 opaque_data);
1504
1505 return true;
1506 }
1507
1508 static const nla_decoder_t ifla_af_spec_bridge_nla_decoders[] = {
1509 [IFLA_BRIDGE_FLAGS] = decode_ifla_bridge_flags,
1510 [IFLA_BRIDGE_MODE] = decode_ifla_bridge_mode,
1511 [IFLA_BRIDGE_VLAN_INFO] = decode_ifla_bridge_vlan_info,
1512 [IFLA_BRIDGE_VLAN_TUNNEL_INFO] = decode_ifla_bridge_vlan_tunnel_info,
1513 [IFLA_BRIDGE_MRP] = NULL, /* unimplemented */
1514 [IFLA_BRIDGE_CFM] = NULL, /* unimplemented */
1515 [IFLA_BRIDGE_MST] = NULL, /* unimplemented */
1516 };
1517
1518 /**
1519 * In a wonderful world of netlink interfaces (thanks, the author
1520 * of Linux commit v3.8-rc1~139^2~542 who completely ignored the original
1521 * IFLA_AF_SPEC attribute description provided in if_link.h since
1522 * v2.6.38-rc1~476^2~532!), IFLA_AF_SPEC has different structure depending
1523 * on context, cf. the original IFLA_AF_SPEC comment in if_link.h
1524 * and the IFLA_AF_SPEC description in if_bridge.h:
1525 *
1526 * <if_link.h>
1527 * IFLA_AF_SPEC
1528 * Contains nested attributes for address family specific attributes.
1529 * Each address family may create a attribute with the address family
1530 * number as type and create its own attribute structure in it.
1531 *
1532 * Example:
1533 * [IFLA_AF_SPEC] = {
1534 * [AF_INET] = {
1535 * [IFLA_INET_CONF] = ...,
1536 * },
1537 * [AF_INET6] = {
1538 * [IFLA_INET6_FLAGS] = ...,
1539 * [IFLA_INET6_CONF] = ...,
1540 * }
1541 * }
1542 *
1543 * <if_bridge.h>
1544 * Bridge management nested attributes
1545 * [IFLA_AF_SPEC] = {
1546 * [IFLA_BRIDGE_FLAGS]
1547 * [IFLA_BRIDGE_MODE]
1548 * [IFLA_BRIDGE_VLAN_INFO]
1549 * }
1550 */
1551 static bool
1552 decode_ifla_af_spec(struct tcb *const tcp,
1553 const kernel_ulong_t addr,
1554 const unsigned int len,
1555 const void *const opaque_data)
1556 {
1557 const struct ifinfomsg *ifinfo = (const struct ifinfomsg *) opaque_data;
1558
1559 /* AF_BRIDGE is a special snowflake */
1560 if (ifinfo->ifi_family == AF_BRIDGE) {
1561 decode_nlattr(tcp, addr, len, rtnl_ifla_af_spec_bridge_attrs,
1562 "IFLA_BRIDGE_???",
1563 ARRSZ_PAIR(ifla_af_spec_bridge_nla_decoders),
1564 opaque_data);
1565 } else {
1566 nla_decoder_t af_spec_decoder = &decode_ifla_af;
1567
1568 decode_nlattr(tcp, addr, len, addrfams, "AF_???",
1569 &af_spec_decoder, 0, 0);
1570 }
1571
1572 return true;
1573 }
1574
1575 static bool
1576 decode_ifla_prop_list_attr(struct tcb *const tcp,
1577 const kernel_ulong_t addr,
1578 const unsigned int len,
1579 const void *const opaque_data)
1580 {
1581 const uintptr_t type = (uintptr_t) opaque_data;
1582
1583 switch (type) {
1584 case IFLA_ALT_IFNAME:
1585 return decode_nla_str(tcp, addr, len, NULL);
1586 default:
1587 return false;
1588 }
1589
1590 return true;
1591 }
1592
1593 static bool
1594 decode_ifla_prop_list(struct tcb *const tcp,
1595 const kernel_ulong_t addr,
1596 const unsigned int len,
1597 const void *const opaque_data)
1598 {
1599 nla_decoder_t ifla_prop_list_decoder = &decode_ifla_prop_list_attr;
1600
1601 /*
1602 * We're using the zero-size decoder list in order to avoid large table,
1603 * as IFLA_ALT_IFNAME is the only attribute type we need to decode
1604 * inside the IFLA_PROP_LIST attribute so far, and it has rather large
1605 * value of 53.
1606 */
1607 decode_nlattr(tcp, addr, len, rtnl_link_attrs, "IFLA_???",
1608 &ifla_prop_list_decoder, 0, NULL);
1609
1610 return true;
1611 }
1612
1613 static const nla_decoder_t ifla_proto_down_reason_nla_decoders[] = {
1614 [IFLA_PROTO_DOWN_REASON_UNSPEC] = NULL,
1615 [IFLA_PROTO_DOWN_REASON_MASK] = decode_nla_x32,
1616 [IFLA_PROTO_DOWN_REASON_VALUE] = decode_nla_x32,
1617 };
1618
1619 static bool
1620 decode_ifla_proto_down_reason(struct tcb *const tcp,
1621 const kernel_ulong_t addr,
1622 const unsigned int len,
1623 const void *const opaque_data)
1624 {
1625 decode_nlattr(tcp, addr, len, rtnl_ifla_proto_down_reason_attrs,
1626 "IFLA_PROTO_DOWN_REASON_???",
1627 ARRSZ_PAIR(ifla_proto_down_reason_nla_decoders),
1628 opaque_data);
1629
1630 return true;
1631 }
1632
1633 static const nla_decoder_t ifinfomsg_nla_decoders[] = {
1634 [IFLA_ADDRESS] = decode_ifla_hwaddr,
1635 [IFLA_BROADCAST] = decode_ifla_hwaddr,
1636 [IFLA_IFNAME] = decode_nla_str,
1637 [IFLA_MTU] = decode_nla_u32,
1638 [IFLA_LINK] = decode_nla_u32,
1639 [IFLA_QDISC] = decode_nla_str,
1640 [IFLA_STATS] = decode_rtnl_link_stats,
1641 [IFLA_COST] = NULL, /* unused */
1642 [IFLA_PRIORITY] = NULL, /* unused */
1643 [IFLA_MASTER] = decode_nla_u32,
1644 [IFLA_WIRELESS] = NULL, /* unimplemented */
1645 [IFLA_PROTINFO] = decode_ifla_protinfo,
1646 [IFLA_TXQLEN] = decode_nla_u32,
1647 [IFLA_MAP] = decode_rtnl_link_ifmap,
1648 [IFLA_WEIGHT] = decode_nla_u32,
1649 [IFLA_OPERSTATE] = decode_nla_u8,
1650 [IFLA_LINKMODE] = decode_nla_u8,
1651 [IFLA_LINKINFO] = decode_ifla_linkinfo,
1652 [IFLA_NET_NS_PID] = decode_nla_u32,
1653 [IFLA_IFALIAS] = decode_nla_str,
1654 [IFLA_NUM_VF] = decode_nla_u32,
1655 [IFLA_VFINFO_LIST] = decode_ifla_vfinfo_list,
1656 [IFLA_STATS64] = decode_nla_rtnl_link_stats64,
1657 [IFLA_VF_PORTS] = decode_ifla_vf_ports,
1658 [IFLA_PORT_SELF] = decode_ifla_port,
1659 [IFLA_AF_SPEC] = decode_ifla_af_spec,
1660 [IFLA_GROUP] = decode_nla_u32,
1661 [IFLA_NET_NS_FD] = decode_nla_fd,
1662 [IFLA_EXT_MASK] = decode_ifla_ext_mask,
1663 [IFLA_PROMISCUITY] = decode_nla_u32,
1664 [IFLA_NUM_TX_QUEUES] = decode_nla_u32,
1665 [IFLA_NUM_RX_QUEUES] = decode_nla_u32,
1666 [IFLA_CARRIER] = decode_nla_u8,
1667 [IFLA_PHYS_PORT_ID] = NULL, /* default parser */
1668 [IFLA_CARRIER_CHANGES] = decode_nla_u32,
1669 [IFLA_PHYS_SWITCH_ID] = NULL, /* default parser */
1670 [IFLA_LINK_NETNSID] = decode_nla_s32,
1671 [IFLA_PHYS_PORT_NAME] = decode_nla_str,
1672 [IFLA_PROTO_DOWN] = decode_nla_u8,
1673 [IFLA_GSO_MAX_SEGS] = decode_nla_u32,
1674 [IFLA_GSO_MAX_SIZE] = decode_nla_u32,
1675 [IFLA_PAD] = NULL,
1676 [IFLA_XDP] = decode_ifla_xdp,
1677 [IFLA_EVENT] = decode_ifla_event,
1678 [IFLA_NEW_NETNSID] = decode_nla_s32,
1679 [IFLA_IF_NETNSID] = decode_nla_s32,
1680 [IFLA_CARRIER_UP_COUNT] = decode_nla_u32,
1681 [IFLA_CARRIER_DOWN_COUNT] = decode_nla_u32,
1682 [IFLA_NEW_IFINDEX] = decode_nla_ifindex,
1683 [IFLA_MIN_MTU] = decode_nla_u32,
1684 [IFLA_MAX_MTU] = decode_nla_u32,
1685 [IFLA_PROP_LIST] = decode_ifla_prop_list,
1686 [IFLA_ALT_IFNAME] = decode_nla_str,
1687 [IFLA_PERM_ADDRESS] = decode_ifla_hwaddr,
1688 [IFLA_PROTO_DOWN_REASON] = decode_ifla_proto_down_reason,
1689 [IFLA_PARENT_DEV_NAME] = decode_nla_str,
1690 [IFLA_PARENT_DEV_BUS_NAME] = decode_nla_str,
1691 [IFLA_GRO_MAX_SIZE] = decode_nla_u32,
1692 [IFLA_TSO_MAX_SIZE] = decode_nla_u32,
1693 [IFLA_TSO_MAX_SEGS] = decode_nla_u32,
1694 [IFLA_ALLMULTI] = decode_nla_u32,
1695 [IFLA_DEVLINK_PORT] = decode_nla_u32,
1696 [IFLA_GSO_IPV4_MAX_SIZE] = decode_nla_u32,
1697 [IFLA_GRO_IPV4_MAX_SIZE] = decode_nla_u32,
1698 };
1699
1700 DECL_NETLINK_ROUTE_DECODER(decode_ifinfomsg)
1701 {
1702 struct ifinfomsg ifinfo = { .ifi_family = family };
1703 size_t offset = sizeof(ifinfo.ifi_family);
1704 bool decode_nla = false;
1705
1706 tprint_struct_begin();
1707 PRINT_FIELD_XVAL(ifinfo, ifi_family, addrfams, "AF_???");
1708 tprint_struct_next();
1709
1710 if (len >= sizeof(ifinfo)) {
1711 if (!umoven_or_printaddr(tcp, addr + offset,
1712 sizeof(ifinfo) - offset,
1713 (char *) &ifinfo + offset)) {
1714 PRINT_FIELD_XVAL(ifinfo, ifi_type,
1715 arp_hardware_types, "ARPHRD_???");
1716 tprint_struct_next();
1717 PRINT_FIELD_IFINDEX(ifinfo, ifi_index);
1718 tprint_struct_next();
1719 PRINT_FIELD_FLAGS(ifinfo, ifi_flags,
1720 iffflags, "IFF_???");
1721 tprint_struct_next();
1722 PRINT_FIELD_X(ifinfo, ifi_change);
1723 decode_nla = true;
1724 }
1725 } else
1726 tprint_more_data_follows();
1727 tprint_struct_end();
1728
1729 offset = NLMSG_ALIGN(sizeof(ifinfo));
1730 if (decode_nla && len > offset) {
1731 tprint_array_next();
1732 decode_nlattr(tcp, addr + offset, len - offset,
1733 rtnl_link_attrs, "IFLA_???",
1734 ARRSZ_PAIR(ifinfomsg_nla_decoders), &ifinfo);
1735 }
1736 }