2 * Copyright (c) 2016 Fabien Siron <fabien.siron@epita.fr>
3 * Copyright (c) 2017 JingPiao Chen <chenjingpiao@gmail.com>
4 * Copyright (c) 2016-2017 The strace developers.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include "netlink_route.h"
33 #include "print_fields.h"
36 #include <linux/rtnetlink.h>
37 #ifdef HAVE_LINUX_NEIGHBOUR_H
38 # include <linux/neighbour.h>
41 #include "xlat/neighbor_cache_entry_flags.h"
42 #include "xlat/neighbor_cache_entry_states.h"
43 #include "xlat/rtnl_neigh_attrs.h"
46 decode_neigh_addr(struct tcb *const tcp,
47 const kernel_ulong_t addr,
48 const unsigned int len,
49 const void *const opaque_data)
51 const struct ndmsg *const ndmsg = opaque_data;
53 decode_inet_addr(tcp, addr, len, ndmsg->ndm_family, NULL);
59 decode_nda_cacheinfo(struct tcb *const tcp,
60 const kernel_ulong_t addr,
61 const unsigned int len,
62 const void *const opaque_data)
64 struct nda_cacheinfo ci;
68 else if (!umove_or_printaddr(tcp, addr, &ci)) {
69 PRINT_FIELD_U("{", ci, ndm_confirmed);
70 PRINT_FIELD_U(", ", ci, ndm_used);
71 PRINT_FIELD_U(", ", ci, ndm_updated);
72 PRINT_FIELD_U(", ", ci, ndm_refcnt);
79 static const nla_decoder_t ndmsg_nla_decoders[] = {
80 [NDA_DST] = decode_neigh_addr,
81 [NDA_LLADDR] = decode_neigh_addr,
82 [NDA_CACHEINFO] = decode_nda_cacheinfo,
83 [NDA_PROBES] = decode_nla_u32,
84 [NDA_VLAN] = decode_nla_u16,
85 [NDA_PORT] = decode_nla_be16,
86 [NDA_VNI] = decode_nla_u32,
87 [NDA_IFINDEX] = decode_nla_ifindex,
88 [NDA_MASTER] = decode_nla_ifindex,
89 [NDA_LINK_NETNSID] = decode_nla_u32,
93 DECL_NETLINK_ROUTE_DECODER(decode_ndmsg)
95 struct ndmsg ndmsg = { .ndm_family = family };
96 size_t offset = sizeof(ndmsg.ndm_family);
97 bool decode_nla = false;
99 PRINT_FIELD_XVAL("{", ndmsg, ndm_family, addrfams, "AF_???");
102 if (len >= sizeof(ndmsg)) {
103 if (!umoven_or_printaddr(tcp, addr + offset,
104 sizeof(ndmsg) - offset,
105 (void *) &ndmsg + offset)) {
106 PRINT_FIELD_IFINDEX("", ndmsg, ndm_ifindex);
107 PRINT_FIELD_FLAGS(", ", ndmsg, ndm_state,
108 neighbor_cache_entry_states,
110 PRINT_FIELD_FLAGS(", ", ndmsg, ndm_flags,
111 neighbor_cache_entry_flags,
113 PRINT_FIELD_XVAL(", ", ndmsg, ndm_type,
114 routing_types, "RTN_???");
121 offset = NLMSG_ALIGN(sizeof(ndmsg));
122 if (decode_nla && len > offset) {
124 decode_nlattr(tcp, addr + offset, len - offset,
125 rtnl_neigh_attrs, "NDA_???",
127 ARRAY_SIZE(ndmsg_nla_decoders), &ndmsg);
131 DECL_NETLINK_ROUTE_DECODER(decode_rtm_getneigh)
133 if (family == AF_BRIDGE)
134 decode_ifinfomsg(tcp, nlmsghdr, family, addr, len);
136 decode_ndmsg(tcp, nlmsghdr, family, addr, len);