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 * SPDX-License-Identifier: LGPL-2.1-or-later
11 #include "netlink_route.h"
13 #include "print_fields.h"
16 #include <linux/rtnetlink.h>
17 #ifdef HAVE_LINUX_NEIGHBOUR_H
18 # include <linux/neighbour.h>
21 #include "xlat/rtnl_neightbl_attrs.h"
22 #include "xlat/rtnl_neightbl_parms_attrs.h"
25 uint16_t ndtc_key_len;
26 uint16_t ndtc_entry_size;
27 uint32_t ndtc_entries;
28 uint32_t ndtc_last_flush;
29 uint32_t ndtc_last_rand;
30 uint32_t ndtc_hash_rnd;
31 uint32_t ndtc_hash_mask;
32 uint32_t ndtc_hash_chain_gc;
33 uint32_t ndtc_proxy_qlen;
38 uint64_t ndts_destroys;
39 uint64_t ndts_hash_grows;
40 uint64_t ndts_res_failed;
41 uint64_t ndts_lookups;
43 uint64_t ndts_rcv_probes_mcast;
44 uint64_t ndts_rcv_probes_ucast;
45 uint64_t ndts_periodic_gc_runs;
46 uint64_t ndts_forced_gc_runs;
47 uint64_t ndts_table_fulls; /**< Added by v4.3-rc1~96^2~202 */
50 # ifdef HAVE_STRUCT_NDT_CONFIG
51 static_assert(sizeof(struct ndt_config) == sizeof(struct_ndt_config),
52 "Unexpected struct ndt_config size, please update the decoder");
54 # ifdef HAVE_STRUCT_NDT_STATS
55 static_assert(sizeof(struct ndt_stats) <= sizeof(struct_ndt_stats),
56 "Unexpected struct ndt_stats size, please update the decoder");
61 decode_ndt_config(struct tcb *const tcp,
62 const kernel_ulong_t addr,
63 const unsigned int len,
64 const void *const opaque_data)
66 struct_ndt_config ndtc;
68 if (len < sizeof(ndtc))
70 else if (!umove_or_printaddr(tcp, addr, &ndtc)) {
71 PRINT_FIELD_U("{", ndtc, ndtc_key_len);
72 PRINT_FIELD_U(", ", ndtc, ndtc_entry_size);
73 PRINT_FIELD_U(", ", ndtc, ndtc_entries);
74 PRINT_FIELD_U(", ", ndtc, ndtc_last_flush);
75 PRINT_FIELD_U(", ", ndtc, ndtc_last_rand);
76 PRINT_FIELD_U(", ", ndtc, ndtc_hash_rnd);
77 PRINT_FIELD_0X(", ", ndtc, ndtc_hash_mask);
78 PRINT_FIELD_U(", ", ndtc, ndtc_hash_chain_gc);
79 PRINT_FIELD_U(", ", ndtc, ndtc_proxy_qlen);
86 static const nla_decoder_t ndt_parms_nla_decoders[] = {
87 [NDTPA_IFINDEX] = decode_nla_ifindex,
88 [NDTPA_REFCNT] = decode_nla_u32,
89 [NDTPA_REACHABLE_TIME] = decode_nla_u64,
90 [NDTPA_BASE_REACHABLE_TIME] = decode_nla_u64,
91 [NDTPA_RETRANS_TIME] = decode_nla_u64,
92 [NDTPA_GC_STALETIME] = decode_nla_u64,
93 [NDTPA_DELAY_PROBE_TIME] = decode_nla_u64,
94 [NDTPA_QUEUE_LEN] = decode_nla_u32,
95 [NDTPA_APP_PROBES] = decode_nla_u32,
96 [NDTPA_UCAST_PROBES] = decode_nla_u32,
97 [NDTPA_MCAST_PROBES] = decode_nla_u32,
98 [NDTPA_ANYCAST_DELAY] = decode_nla_u64,
99 [NDTPA_PROXY_DELAY] = decode_nla_u64,
100 [NDTPA_PROXY_QLEN] = decode_nla_u32,
101 [NDTPA_LOCKTIME] = decode_nla_u64,
102 [NDTPA_QUEUE_LENBYTES] = decode_nla_u32,
103 [NDTPA_MCAST_REPROBES] = decode_nla_u32,
108 decode_ndta_parms(struct tcb *const tcp,
109 const kernel_ulong_t addr,
110 const unsigned int len,
111 const void *const opaque_data)
113 decode_nlattr(tcp, addr, len, rtnl_neightbl_parms_attrs, "NDTPA_???",
114 ndt_parms_nla_decoders,
115 ARRAY_SIZE(ndt_parms_nla_decoders), opaque_data);
121 decode_ndt_stats(struct tcb *const tcp,
122 const kernel_ulong_t addr,
123 const unsigned int len,
124 const void *const opaque_data)
126 struct_ndt_stats ndtst;
127 const unsigned int min_size =
128 offsetofend(struct ndt_stats, ndts_forced_gc_runs);
129 const unsigned int def_size = sizeof(ndtst);
130 const unsigned int size =
131 (len >= def_size) ? def_size :
132 ((len == min_size) ? min_size : 0);
137 if (!umoven_or_printaddr(tcp, addr, size, &ndtst)) {
138 PRINT_FIELD_U("{", ndtst, ndts_allocs);
139 PRINT_FIELD_U(", ", ndtst, ndts_destroys);
140 PRINT_FIELD_U(", ", ndtst, ndts_hash_grows);
141 PRINT_FIELD_U(", ", ndtst, ndts_res_failed);
142 PRINT_FIELD_U(", ", ndtst, ndts_lookups);
143 PRINT_FIELD_U(", ", ndtst, ndts_hits);
144 PRINT_FIELD_U(", ", ndtst, ndts_rcv_probes_mcast);
145 PRINT_FIELD_U(", ", ndtst, ndts_rcv_probes_ucast);
146 PRINT_FIELD_U(", ", ndtst, ndts_periodic_gc_runs);
147 PRINT_FIELD_U(", ", ndtst, ndts_forced_gc_runs);
149 PRINT_FIELD_U(", ", ndtst, ndts_table_fulls);
156 static const nla_decoder_t ndtmsg_nla_decoders[] = {
157 [NDTA_NAME] = decode_nla_str,
158 [NDTA_THRESH1] = decode_nla_u32,
159 [NDTA_THRESH2] = decode_nla_u32,
160 [NDTA_THRESH3] = decode_nla_u32,
161 [NDTA_CONFIG] = decode_ndt_config,
162 [NDTA_PARMS] = decode_ndta_parms,
163 [NDTA_STATS] = decode_ndt_stats,
164 [NDTA_GC_INTERVAL] = decode_nla_u64,
168 DECL_NETLINK_ROUTE_DECODER(decode_ndtmsg)
170 struct ndtmsg ndtmsg = { .ndtm_family = family };
172 PRINT_FIELD_XVAL("{", ndtmsg, ndtm_family, addrfams, "AF_???");
175 const size_t offset = NLMSG_ALIGN(sizeof(ndtmsg));
178 decode_nlattr(tcp, addr + offset, len - offset,
179 rtnl_neightbl_attrs, "NDTA_???",
181 ARRAY_SIZE(ndtmsg_nla_decoders), NULL);