]> granicus.if.org Git - strace/blob - rtnl_neightbl.c
bfin, csky, m68k, sh: fix build regression
[strace] / rtnl_neightbl.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 #include "netlink_route.h"
12 #include "nlattr.h"
13 #include "print_fields.h"
14
15 #include "netlink.h"
16 #include <linux/rtnetlink.h>
17 #ifdef HAVE_LINUX_NEIGHBOUR_H
18 # include <linux/neighbour.h>
19 #endif
20
21 #include "xlat/rtnl_neightbl_attrs.h"
22 #include "xlat/rtnl_neightbl_parms_attrs.h"
23
24 typedef struct {
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;
34 } struct_ndt_config;
35
36 typedef struct {
37         uint64_t ndts_allocs;
38         uint64_t ndts_destroys;
39         uint64_t ndts_hash_grows;
40         uint64_t ndts_res_failed;
41         uint64_t ndts_lookups;
42         uint64_t ndts_hits;
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 */
48 } struct_ndt_stats;
49
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");
53 # endif
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");
57 # endif
58
59
60 static bool
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)
65 {
66         struct_ndt_config ndtc;
67
68         if (len < sizeof(ndtc))
69                 return false;
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);
80                 tprints("}");
81         }
82
83         return true;
84 }
85
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,
104         [NDTPA_PAD]                     = NULL
105 };
106
107 static bool
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)
112 {
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);
116
117         return true;
118 }
119
120 static bool
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)
125 {
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);
133
134         if (!size)
135                 return false;
136
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);
148                 if (len >= def_size)
149                         PRINT_FIELD_U(", ", ndtst, ndts_table_fulls);
150                 tprints("}");
151         }
152
153         return true;
154 }
155
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,
165         [NDTA_PAD]              = NULL,
166 };
167
168 DECL_NETLINK_ROUTE_DECODER(decode_ndtmsg)
169 {
170         struct ndtmsg ndtmsg = { .ndtm_family = family };
171
172         PRINT_FIELD_XVAL("{", ndtmsg, ndtm_family, addrfams, "AF_???");
173         tprints("}");
174
175         const size_t offset = NLMSG_ALIGN(sizeof(ndtmsg));
176         if (len > offset) {
177                 tprints(", ");
178                 decode_nlattr(tcp, addr + offset, len - offset,
179                               rtnl_neightbl_attrs, "NDTA_???",
180                               ndtmsg_nla_decoders,
181                               ARRAY_SIZE(ndtmsg_nla_decoders), NULL);
182         }
183 }