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 * 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.
32 #include "netlink_route.h"
34 #include "print_fields.h"
37 #include <linux/rtnetlink.h>
38 #ifdef HAVE_LINUX_FIB_RULES_H
39 # include <linux/fib_rules.h>
42 #include "xlat/fib_rule_actions.h"
43 #include "xlat/fib_rule_flags.h"
44 #include "xlat/rtnl_rule_attrs.h"
47 decode_rule_addr(struct tcb *const tcp,
48 const kernel_ulong_t addr,
49 const unsigned int len,
50 const void *const opaque_data)
52 const struct rtmsg *const rtmsg = opaque_data;
54 decode_inet_addr(tcp, addr, len, rtmsg->rtm_family, NULL);
60 decode_fib_rule_uid_range(struct tcb *const tcp,
61 const kernel_ulong_t addr,
62 const unsigned int len,
63 const void *const opaque_data)
65 #ifdef HAVE_STRUCT_FIB_RULE_UID_RANGE
66 struct fib_rule_uid_range range;
68 if (len < sizeof(range))
70 else if (!umove_or_printaddr(tcp, addr, &range)) {
71 PRINT_FIELD_U("{", range, start);
72 PRINT_FIELD_U(", ", range, end);
82 static const nla_decoder_t fib_rule_hdr_nla_decoders[] = {
83 [FRA_DST] = decode_rule_addr,
84 [FRA_SRC] = decode_rule_addr,
85 [FRA_IIFNAME] = decode_nla_str,
86 [FRA_GOTO] = decode_nla_u32,
87 [FRA_PRIORITY] = decode_nla_u32,
88 [FRA_FWMARK] = decode_nla_u32,
89 [FRA_FLOW] = decode_nla_u32,
90 [FRA_TUN_ID] = decode_nla_be64,
91 [FRA_SUPPRESS_IFGROUP] = decode_nla_u32,
92 [FRA_SUPPRESS_PREFIXLEN] = decode_nla_u32,
93 [FRA_TABLE] = decode_nla_rt_class,
94 [FRA_FWMASK] = decode_nla_u32,
95 [FRA_OIFNAME] = decode_nla_str,
97 [FRA_L3MDEV] = decode_nla_u8,
98 [FRA_UID_RANGE] = decode_fib_rule_uid_range
101 DECL_NETLINK_ROUTE_DECODER(decode_fib_rule_hdr)
104 * struct rtmsg and struct fib_rule_hdr are essentially
105 * the same structure, use struct rtmsg but treat it as
106 * struct fib_rule_hdr.
108 struct rtmsg msg = { .rtm_family = family };
109 size_t offset = sizeof(msg.rtm_family);
110 bool decode_nla = false;
113 printxval(addrfams, msg.rtm_family, "AF_???");
116 if (len >= sizeof(msg)) {
117 if (!umoven_or_printaddr(tcp, addr + offset,
118 sizeof(msg) - offset,
119 (char *) &msg + offset)) {
120 tprintf("dst_len=%u, src_len=%u",
121 msg.rtm_dst_len, msg.rtm_src_len);
123 printflags(ip_type_of_services, msg.rtm_tos,
126 printxval(routing_table_ids, msg.rtm_table, NULL);
127 tprints(", action=");
128 printxval(fib_rule_actions, msg.rtm_type, "FR_ACT_???");
130 printflags(fib_rule_flags, msg.rtm_flags,
138 offset = NLMSG_ALIGN(sizeof(msg));
139 if (decode_nla && len > offset) {
141 decode_nlattr(tcp, addr + offset, len - offset,
142 rtnl_rule_attrs, "FRA_???",
143 fib_rule_hdr_nla_decoders,
144 ARRAY_SIZE(fib_rule_hdr_nla_decoders), &msg);