]> granicus.if.org Git - strace/blob - netlink_route.c
tests: add ioctl_evdev-success* test binaries to .gitignore
[strace] / netlink_route.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.h"
12 #include "netlink_route.h"
13
14 #include <linux/rtnetlink.h>
15
16 #include "xlat/nl_route_types.h"
17
18 static void
19 decode_family(struct tcb *const tcp, const uint8_t family,
20               const kernel_ulong_t addr, const unsigned int len)
21 {
22         tprints("{family=");
23         printxval(addrfams, family, "AF_???");
24         if (len > sizeof(family)) {
25                 tprints(", ");
26                 printstr_ex(tcp, addr + sizeof(family),
27                             len - sizeof(family), QUOTE_FORCE_HEX);
28         }
29         tprints("}");
30 }
31
32 typedef DECL_NETLINK_ROUTE_DECODER((*netlink_route_decoder_t));
33
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,
39
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,
45
46         [RTM_DELROUTE - RTM_BASE] = decode_rtmsg,
47         [RTM_GETROUTE - RTM_BASE] = decode_rtmsg,
48         [RTM_NEWROUTE - RTM_BASE] = decode_rtmsg,
49
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,
53
54         [RTM_DELNEIGH - RTM_BASE] = decode_ndmsg,
55         [RTM_GETNEIGH - RTM_BASE] = decode_rtm_getneigh,
56         [RTM_NEWNEIGH - RTM_BASE] = decode_ndmsg,
57
58         [RTM_GETNEIGHTBL - RTM_BASE] = decode_ndtmsg,
59         [RTM_NEWNEIGHTBL - RTM_BASE] = decode_ndtmsg,
60         [RTM_SETNEIGHTBL - RTM_BASE] = decode_ndtmsg,
61
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,
71
72         [RTM_DELACTION - RTM_BASE] = decode_tcamsg,
73         [RTM_GETACTION - RTM_BASE] = decode_tcamsg,
74         [RTM_NEWACTION - RTM_BASE] = decode_tcamsg,
75
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,
80 #endif
81
82 #ifdef HAVE_STRUCT_DCBMSG
83         [RTM_GETDCB - RTM_BASE] = decode_dcbmsg,
84         [RTM_SETDCB - RTM_BASE] = decode_dcbmsg,
85 #endif
86
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,
91 #endif
92
93 #ifdef HAVE_STRUCT_BR_PORT_MSG
94         [RTM_DELMDB - RTM_BASE] = decode_br_port_msg,
95         [RTM_GETMDB - RTM_BASE] = decode_br_port_msg,
96         [RTM_NEWMDB - RTM_BASE] = decode_br_port_msg,
97 #endif
98
99         [RTM_DELNSID - RTM_BASE] = decode_rtgenmsg,
100         [RTM_GETNSID - RTM_BASE] = decode_rtgenmsg,
101         [RTM_NEWNSID - RTM_BASE] = decode_rtgenmsg,
102
103         [RTM_NEWCHAIN - RTM_BASE] = decode_tcmsg,
104         [RTM_DELCHAIN - RTM_BASE] = decode_tcmsg,
105         [RTM_GETCHAIN - RTM_BASE] = decode_tcmsg,
106 };
107
108 bool
109 decode_netlink_route(struct tcb *const tcp,
110                      const struct nlmsghdr *const nlmsghdr,
111                      const kernel_ulong_t addr,
112                      const unsigned int len)
113 {
114         uint8_t family;
115
116         if (nlmsghdr->nlmsg_type == NLMSG_DONE)
117                 return false;
118
119         if (!umove_or_printaddr(tcp, addr, &family)) {
120                 const unsigned int index = nlmsghdr->nlmsg_type - RTM_BASE;
121
122                 if (index < ARRAY_SIZE(route_decoders)
123                     && route_decoders[index]) {
124                         route_decoders[index](tcp, nlmsghdr, family, addr, len);
125                 } else {
126                         decode_family(tcp, family, addr, len);
127                 }
128         }
129
130         return true;
131 }