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
12 #include "netlink_route.h"
14 #include <linux/rtnetlink.h>
16 #include "xlat/nl_route_types.h"
19 decode_family(struct tcb *const tcp, const uint8_t family,
20 const kernel_ulong_t addr, const unsigned int len)
23 printxval(addrfams, family, "AF_???");
24 if (len > sizeof(family)) {
26 printstr_ex(tcp, addr + sizeof(family),
27 len - sizeof(family), QUOTE_FORCE_HEX);
32 typedef DECL_NETLINK_ROUTE_DECODER((*netlink_route_decoder_t));
34 static const netlink_route_decoder_t route_decoders[] = {
35 [RTM_DELLINK - RTM_BASE] = decode_ifinfomsg,
36 [RTM_GETLINK - RTM_BASE] = decode_ifinfomsg,
37 [RTM_NEWLINK - RTM_BASE] = decode_ifinfomsg,
38 [RTM_SETLINK - RTM_BASE] = decode_ifinfomsg,
40 [RTM_DELADDR - RTM_BASE] = decode_ifaddrmsg,
41 [RTM_GETADDR - RTM_BASE] = decode_ifaddrmsg,
42 [RTM_GETANYCAST - RTM_BASE] = decode_ifaddrmsg,
43 [RTM_GETMULTICAST - RTM_BASE] = decode_ifaddrmsg,
44 [RTM_NEWADDR - RTM_BASE] = decode_ifaddrmsg,
46 [RTM_DELROUTE - RTM_BASE] = decode_rtmsg,
47 [RTM_GETROUTE - RTM_BASE] = decode_rtmsg,
48 [RTM_NEWROUTE - RTM_BASE] = decode_rtmsg,
50 [RTM_DELRULE - RTM_BASE] = decode_fib_rule_hdr,
51 [RTM_GETRULE - RTM_BASE] = decode_fib_rule_hdr,
52 [RTM_NEWRULE - RTM_BASE] = decode_fib_rule_hdr,
54 [RTM_DELNEIGH - RTM_BASE] = decode_ndmsg,
55 [RTM_GETNEIGH - RTM_BASE] = decode_rtm_getneigh,
56 [RTM_NEWNEIGH - RTM_BASE] = decode_ndmsg,
58 [RTM_GETNEIGHTBL - RTM_BASE] = decode_ndtmsg,
59 [RTM_NEWNEIGHTBL - RTM_BASE] = decode_ndtmsg,
60 [RTM_SETNEIGHTBL - RTM_BASE] = decode_ndtmsg,
62 [RTM_DELQDISC - RTM_BASE] = decode_tcmsg,
63 [RTM_GETQDISC - RTM_BASE] = decode_tcmsg,
64 [RTM_NEWQDISC - RTM_BASE] = decode_tcmsg,
65 [RTM_DELTCLASS - RTM_BASE] = decode_tcmsg,
66 [RTM_GETTCLASS - RTM_BASE] = decode_tcmsg,
67 [RTM_NEWTCLASS - RTM_BASE] = decode_tcmsg,
68 [RTM_DELTFILTER - RTM_BASE] = decode_tcmsg,
69 [RTM_GETTFILTER - RTM_BASE] = decode_tcmsg,
70 [RTM_NEWTFILTER - RTM_BASE] = decode_tcmsg,
72 [RTM_DELACTION - RTM_BASE] = decode_tcamsg,
73 [RTM_GETACTION - RTM_BASE] = decode_tcamsg,
74 [RTM_NEWACTION - RTM_BASE] = decode_tcamsg,
76 #ifdef HAVE_STRUCT_IFADDRLBLMSG
77 [RTM_DELADDRLABEL - RTM_BASE] = decode_ifaddrlblmsg,
78 [RTM_GETADDRLABEL - RTM_BASE] = decode_ifaddrlblmsg,
79 [RTM_NEWADDRLABEL - RTM_BASE] = decode_ifaddrlblmsg,
82 #ifdef HAVE_STRUCT_DCBMSG
83 [RTM_GETDCB - RTM_BASE] = decode_dcbmsg,
84 [RTM_SETDCB - RTM_BASE] = decode_dcbmsg,
87 #ifdef HAVE_STRUCT_NETCONFMSG
88 [RTM_DELNETCONF - RTM_BASE] = decode_netconfmsg,
89 [RTM_GETNETCONF - RTM_BASE] = decode_netconfmsg,
90 [RTM_NEWNETCONF - RTM_BASE] = decode_netconfmsg,
93 [RTM_DELMDB - RTM_BASE] = decode_br_port_msg,
94 [RTM_GETMDB - RTM_BASE] = decode_br_port_msg,
95 [RTM_NEWMDB - RTM_BASE] = decode_br_port_msg,
97 [RTM_DELNSID - RTM_BASE] = decode_rtgenmsg,
98 [RTM_GETNSID - RTM_BASE] = decode_rtgenmsg,
99 [RTM_NEWNSID - RTM_BASE] = decode_rtgenmsg,
101 [RTM_NEWCHAIN - RTM_BASE] = decode_tcmsg,
102 [RTM_DELCHAIN - RTM_BASE] = decode_tcmsg,
103 [RTM_GETCHAIN - RTM_BASE] = decode_tcmsg,
107 decode_netlink_route(struct tcb *const tcp,
108 const struct nlmsghdr *const nlmsghdr,
109 const kernel_ulong_t addr,
110 const unsigned int len)
114 if (nlmsghdr->nlmsg_type == NLMSG_DONE)
117 if (!umove_or_printaddr(tcp, addr, &family)) {
118 const unsigned int index = nlmsghdr->nlmsg_type - RTM_BASE;
120 if (index < ARRAY_SIZE(route_decoders)
121 && route_decoders[index]) {
122 route_decoders[index](tcp, nlmsghdr, family, addr, len);
124 decode_family(tcp, family, addr, len);