]> granicus.if.org Git - strace/blob - rtnl_neigh.c
bfin, csky, m68k, sh: fix build regression
[strace] / rtnl_neigh.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-2019 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/neighbor_cache_entry_flags.h"
22 #include "xlat/neighbor_cache_entry_states.h"
23 #include "xlat/rtnl_neigh_attrs.h"
24
25 static bool
26 decode_neigh_addr(struct tcb *const tcp,
27                   const kernel_ulong_t addr,
28                   const unsigned int len,
29                   const void *const opaque_data)
30 {
31         const struct ndmsg *const ndmsg = opaque_data;
32
33         decode_inet_addr(tcp, addr, len, ndmsg->ndm_family, NULL);
34
35         return true;
36 }
37
38 static bool
39 decode_nda_cacheinfo(struct tcb *const tcp,
40                      const kernel_ulong_t addr,
41                      const unsigned int len,
42                      const void *const opaque_data)
43 {
44         struct nda_cacheinfo ci;
45
46         if (len < sizeof(ci))
47                 return false;
48         else if (!umove_or_printaddr(tcp, addr, &ci)) {
49                 PRINT_FIELD_U("{", ci, ndm_confirmed);
50                 PRINT_FIELD_U(", ", ci, ndm_used);
51                 PRINT_FIELD_U(", ", ci, ndm_updated);
52                 PRINT_FIELD_U(", ", ci, ndm_refcnt);
53                 tprints("}");
54         }
55
56         return true;
57 }
58
59 static const nla_decoder_t ndmsg_nla_decoders[] = {
60         [NDA_DST]               = decode_neigh_addr,
61         [NDA_LLADDR]            = decode_neigh_addr,
62         [NDA_CACHEINFO]         = decode_nda_cacheinfo,
63         [NDA_PROBES]            = decode_nla_u32,
64         [NDA_VLAN]              = decode_nla_u16,
65         [NDA_PORT]              = decode_nla_be16,
66         [NDA_VNI]               = decode_nla_u32,
67         [NDA_IFINDEX]           = decode_nla_ifindex,
68         [NDA_MASTER]            = decode_nla_ifindex,
69         [NDA_LINK_NETNSID]      = decode_nla_u32,
70         [NDA_SRC_VNI]           = NULL,
71         [NDA_PROTOCOL]          = decode_nla_u8,
72 };
73
74 DECL_NETLINK_ROUTE_DECODER(decode_ndmsg)
75 {
76         struct ndmsg ndmsg = { .ndm_family = family };
77         size_t offset = sizeof(ndmsg.ndm_family);
78         bool decode_nla = false;
79
80         PRINT_FIELD_XVAL("{", ndmsg, ndm_family, addrfams, "AF_???");
81
82         tprints(", ");
83         if (len >= sizeof(ndmsg)) {
84                 if (!umoven_or_printaddr(tcp, addr + offset,
85                                          sizeof(ndmsg) - offset,
86                                          (char *) &ndmsg + offset)) {
87                         PRINT_FIELD_IFINDEX("", ndmsg, ndm_ifindex);
88                         PRINT_FIELD_FLAGS(", ", ndmsg, ndm_state,
89                                           neighbor_cache_entry_states,
90                                           "NUD_???");
91                         PRINT_FIELD_FLAGS(", ", ndmsg, ndm_flags,
92                                           neighbor_cache_entry_flags,
93                                           "NTF_???");
94                         PRINT_FIELD_XVAL(", ", ndmsg, ndm_type,
95                                          routing_types, "RTN_???");
96                         decode_nla = true;
97                 }
98         } else
99                 tprints("...");
100         tprints("}");
101
102         offset = NLMSG_ALIGN(sizeof(ndmsg));
103         if (decode_nla && len > offset) {
104                 tprints(", ");
105                 decode_nlattr(tcp, addr + offset, len - offset,
106                               rtnl_neigh_attrs, "NDA_???",
107                               ndmsg_nla_decoders,
108                               ARRAY_SIZE(ndmsg_nla_decoders), &ndmsg);
109         }
110 }
111
112 DECL_NETLINK_ROUTE_DECODER(decode_rtm_getneigh)
113 {
114         if (family == AF_BRIDGE)
115                 decode_ifinfomsg(tcp, nlmsghdr, family, addr, len);
116         else
117                 decode_ndmsg(tcp, nlmsghdr, family, addr, len);
118 }