]> granicus.if.org Git - strace/blob - rtnl_neightbl.c
Update debian/watch
[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 static bool
25 decode_ndt_config(struct tcb *const tcp,
26                   const kernel_ulong_t addr,
27                   const unsigned int len,
28                   const void *const opaque_data)
29 {
30 #ifdef HAVE_STRUCT_NDT_CONFIG
31         struct ndt_config ndtc;
32
33         if (len < sizeof(ndtc))
34                 return false;
35         else if (!umove_or_printaddr(tcp, addr, &ndtc)) {
36                 PRINT_FIELD_U("{", ndtc, ndtc_key_len);
37                 PRINT_FIELD_U(", ", ndtc, ndtc_entry_size);
38                 PRINT_FIELD_U(", ", ndtc, ndtc_entries);
39                 PRINT_FIELD_U(", ", ndtc, ndtc_last_flush);
40                 PRINT_FIELD_U(", ", ndtc, ndtc_last_rand);
41                 PRINT_FIELD_U(", ", ndtc, ndtc_hash_rnd);
42                 PRINT_FIELD_0X(", ", ndtc, ndtc_hash_mask);
43                 PRINT_FIELD_U(", ", ndtc, ndtc_hash_chain_gc);
44                 PRINT_FIELD_U(", ", ndtc, ndtc_proxy_qlen);
45                 tprints("}");
46         }
47
48         return true;
49 #else
50         return false;
51 #endif
52 }
53
54 static const nla_decoder_t ndt_parms_nla_decoders[] = {
55         [NDTPA_IFINDEX]                 = decode_nla_ifindex,
56         [NDTPA_REFCNT]                  = decode_nla_u32,
57         [NDTPA_REACHABLE_TIME]          = decode_nla_u64,
58         [NDTPA_BASE_REACHABLE_TIME]     = decode_nla_u64,
59         [NDTPA_RETRANS_TIME]            = decode_nla_u64,
60         [NDTPA_GC_STALETIME]            = decode_nla_u64,
61         [NDTPA_DELAY_PROBE_TIME]        = decode_nla_u64,
62         [NDTPA_QUEUE_LEN]               = decode_nla_u32,
63         [NDTPA_APP_PROBES]              = decode_nla_u32,
64         [NDTPA_UCAST_PROBES]            = decode_nla_u32,
65         [NDTPA_MCAST_PROBES]            = decode_nla_u32,
66         [NDTPA_ANYCAST_DELAY]           = decode_nla_u64,
67         [NDTPA_PROXY_DELAY]             = decode_nla_u64,
68         [NDTPA_PROXY_QLEN]              = decode_nla_u32,
69         [NDTPA_LOCKTIME]                = decode_nla_u64,
70         [NDTPA_QUEUE_LENBYTES]          = decode_nla_u32,
71         [NDTPA_MCAST_REPROBES]          = decode_nla_u32,
72         [NDTPA_PAD]                     = NULL
73 };
74
75 static bool
76 decode_ndta_parms(struct tcb *const tcp,
77                   const kernel_ulong_t addr,
78                   const unsigned int len,
79                   const void *const opaque_data)
80 {
81         decode_nlattr(tcp, addr, len, rtnl_neightbl_parms_attrs, "NDTPA_???",
82                       ndt_parms_nla_decoders,
83                       ARRAY_SIZE(ndt_parms_nla_decoders), opaque_data);
84
85         return true;
86 }
87
88 static bool
89 decode_ndt_stats(struct tcb *const tcp,
90                  const kernel_ulong_t addr,
91                  const unsigned int len,
92                  const void *const opaque_data)
93 {
94 #ifdef HAVE_STRUCT_NDT_STATS
95         struct ndt_stats ndtst;
96         const unsigned int min_size =
97                 offsetofend(struct ndt_stats, ndts_forced_gc_runs);
98         const unsigned int def_size = sizeof(ndtst);
99         const unsigned int size =
100                 (len >= def_size) ? def_size :
101                                     ((len == min_size) ? min_size : 0);
102
103         if (!size)
104                 return false;
105
106         if (!umoven_or_printaddr(tcp, addr, size, &ndtst)) {
107                 PRINT_FIELD_U("{", ndtst, ndts_allocs);
108                 PRINT_FIELD_U(", ", ndtst, ndts_destroys);
109                 PRINT_FIELD_U(", ", ndtst, ndts_hash_grows);
110                 PRINT_FIELD_U(", ", ndtst, ndts_res_failed);
111                 PRINT_FIELD_U(", ", ndtst, ndts_lookups);
112                 PRINT_FIELD_U(", ", ndtst, ndts_hits);
113                 PRINT_FIELD_U(", ", ndtst, ndts_rcv_probes_mcast);
114                 PRINT_FIELD_U(", ", ndtst, ndts_rcv_probes_ucast);
115                 PRINT_FIELD_U(", ", ndtst, ndts_periodic_gc_runs);
116                 PRINT_FIELD_U(", ", ndtst, ndts_forced_gc_runs);
117 # ifdef HAVE_STRUCT_NDT_STATS_NDTS_TABLE_FULLS
118                 if (len >= def_size)
119                         PRINT_FIELD_U(", ", ndtst, ndts_table_fulls);
120 # endif
121                 tprints("}");
122         }
123
124         return true;
125 #else
126         return false;
127 #endif
128 }
129
130 static const nla_decoder_t ndtmsg_nla_decoders[] = {
131         [NDTA_NAME]             = decode_nla_str,
132         [NDTA_THRESH1]          = decode_nla_u32,
133         [NDTA_THRESH2]          = decode_nla_u32,
134         [NDTA_THRESH3]          = decode_nla_u32,
135         [NDTA_CONFIG]           = decode_ndt_config,
136         [NDTA_PARMS]            = decode_ndta_parms,
137         [NDTA_STATS]            = decode_ndt_stats,
138         [NDTA_GC_INTERVAL]      = decode_nla_u64,
139         [NDTA_PAD]              = NULL,
140 };
141
142 DECL_NETLINK_ROUTE_DECODER(decode_ndtmsg)
143 {
144         struct ndtmsg ndtmsg = { .ndtm_family = family };
145
146         PRINT_FIELD_XVAL("{", ndtmsg, ndtm_family, addrfams, "AF_???");
147         tprints("}");
148
149         const size_t offset = NLMSG_ALIGN(sizeof(ndtmsg));
150         if (len > offset) {
151                 tprints(", ");
152                 decode_nlattr(tcp, addr + offset, len - offset,
153                               rtnl_neightbl_attrs, "NDTA_???",
154                               ndtmsg_nla_decoders,
155                               ARRAY_SIZE(ndtmsg_nla_decoders), NULL);
156         }
157 }