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 "print_fields.h"
17 #include <linux/rtnetlink.h>
18 #ifdef HAVE_LINUX_FIB_RULES_H
19 # include <linux/fib_rules.h>
22 #include "xlat/fib_rule_actions.h"
23 #include "xlat/fib_rule_flags.h"
24 #include "xlat/rtnl_rule_attrs.h"
27 decode_rule_addr(struct tcb *const tcp,
28 const kernel_ulong_t addr,
29 const unsigned int len,
30 const void *const opaque_data)
32 const struct rtmsg *const rtmsg = opaque_data;
34 decode_inet_addr(tcp, addr, len, rtmsg->rtm_family, NULL);
40 decode_fib_rule_uid_range(struct tcb *const tcp,
41 const kernel_ulong_t addr,
42 const unsigned int len,
43 const void *const opaque_data)
45 #ifdef HAVE_STRUCT_FIB_RULE_UID_RANGE
46 struct fib_rule_uid_range range;
48 if (len < sizeof(range))
50 else if (!umove_or_printaddr(tcp, addr, &range)) {
51 PRINT_FIELD_U("{", range, start);
52 PRINT_FIELD_U(", ", range, end);
63 decode_rule_port_range(struct tcb *const tcp,
64 const kernel_ulong_t addr,
65 const unsigned int len,
66 const void *const opaque_data)
68 struct /* fib_rule_port_range */ {
73 if (len < sizeof(range))
75 else if (!umove_or_printaddr(tcp, addr, &range)) {
76 PRINT_FIELD_U("{", range, start);
77 PRINT_FIELD_U(", ", range, end);
84 static const nla_decoder_t fib_rule_hdr_nla_decoders[] = {
85 [FRA_DST] = decode_rule_addr,
86 [FRA_SRC] = decode_rule_addr,
87 [FRA_IIFNAME] = decode_nla_str,
88 [FRA_GOTO] = decode_nla_u32,
89 [FRA_PRIORITY] = decode_nla_u32,
90 [FRA_FWMARK] = decode_nla_u32,
91 [FRA_FLOW] = decode_nla_u32,
92 [FRA_TUN_ID] = decode_nla_be64,
93 [FRA_SUPPRESS_IFGROUP] = decode_nla_u32,
94 [FRA_SUPPRESS_PREFIXLEN] = decode_nla_u32,
95 [FRA_TABLE] = decode_nla_rt_class,
96 [FRA_FWMASK] = decode_nla_u32,
97 [FRA_OIFNAME] = decode_nla_str,
99 [FRA_L3MDEV] = decode_nla_u8,
100 [FRA_UID_RANGE] = decode_fib_rule_uid_range,
101 [FRA_PROTOCOL] = decode_nla_rt_proto,
102 [FRA_IP_PROTO] = decode_nla_ip_proto,
103 [FRA_SPORT_RANGE] = decode_rule_port_range,
104 [FRA_DPORT_RANGE] = decode_rule_port_range,
107 DECL_NETLINK_ROUTE_DECODER(decode_fib_rule_hdr)
110 * struct rtmsg and struct fib_rule_hdr are essentially
111 * the same structure, use struct rtmsg but treat it as
112 * struct fib_rule_hdr.
114 struct rtmsg msg = { .rtm_family = family };
115 size_t offset = sizeof(msg.rtm_family);
116 bool decode_nla = false;
119 printxval(addrfams, msg.rtm_family, "AF_???");
122 if (len >= sizeof(msg)) {
123 if (!umoven_or_printaddr(tcp, addr + offset,
124 sizeof(msg) - offset,
125 (char *) &msg + offset)) {
126 tprintf("dst_len=%u, src_len=%u",
127 msg.rtm_dst_len, msg.rtm_src_len);
129 printflags(ip_type_of_services, msg.rtm_tos,
132 printxval(routing_table_ids, msg.rtm_table, NULL);
133 tprints(", action=");
134 printxval(fib_rule_actions, msg.rtm_type, "FR_ACT_???");
136 printflags(fib_rule_flags, msg.rtm_flags,
144 offset = NLMSG_ALIGN(sizeof(msg));
145 if (decode_nla && len > offset) {
147 decode_nlattr(tcp, addr + offset, len - offset,
148 rtnl_rule_attrs, "FRA_???",
149 fib_rule_hdr_nla_decoders,
150 ARRAY_SIZE(fib_rule_hdr_nla_decoders), &msg);