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 struct /* fib_rule_uid_range */ {
50 if (len < sizeof(range))
52 else if (!umove_or_printaddr(tcp, addr, &range)) {
53 PRINT_FIELD_U("{", range, start);
54 PRINT_FIELD_U(", ", range, end);
62 decode_rule_port_range(struct tcb *const tcp,
63 const kernel_ulong_t addr,
64 const unsigned int len,
65 const void *const opaque_data)
67 struct /* fib_rule_port_range */ {
72 if (len < sizeof(range))
74 else if (!umove_or_printaddr(tcp, addr, &range)) {
75 PRINT_FIELD_U("{", range, start);
76 PRINT_FIELD_U(", ", range, end);
83 static const nla_decoder_t fib_rule_hdr_nla_decoders[] = {
84 [FRA_DST] = decode_rule_addr,
85 [FRA_SRC] = decode_rule_addr,
86 [FRA_IIFNAME] = decode_nla_str,
87 [FRA_GOTO] = decode_nla_u32,
88 [FRA_PRIORITY] = decode_nla_u32,
89 [FRA_FWMARK] = decode_nla_u32,
90 [FRA_FLOW] = decode_nla_u32,
91 [FRA_TUN_ID] = decode_nla_be64,
92 [FRA_SUPPRESS_IFGROUP] = decode_nla_u32,
93 [FRA_SUPPRESS_PREFIXLEN] = decode_nla_u32,
94 [FRA_TABLE] = decode_nla_rt_class,
95 [FRA_FWMASK] = decode_nla_u32,
96 [FRA_OIFNAME] = decode_nla_str,
98 [FRA_L3MDEV] = decode_nla_u8,
99 [FRA_UID_RANGE] = decode_fib_rule_uid_range,
100 [FRA_PROTOCOL] = decode_nla_rt_proto,
101 [FRA_IP_PROTO] = decode_nla_ip_proto,
102 [FRA_SPORT_RANGE] = decode_rule_port_range,
103 [FRA_DPORT_RANGE] = decode_rule_port_range,
106 DECL_NETLINK_ROUTE_DECODER(decode_fib_rule_hdr)
109 * struct rtmsg and struct fib_rule_hdr are essentially
110 * the same structure, use struct rtmsg but treat it as
111 * struct fib_rule_hdr.
113 struct rtmsg msg = { .rtm_family = family };
114 size_t offset = sizeof(msg.rtm_family);
115 bool decode_nla = false;
118 printxval(addrfams, msg.rtm_family, "AF_???");
121 if (len >= sizeof(msg)) {
122 if (!umoven_or_printaddr(tcp, addr + offset,
123 sizeof(msg) - offset,
124 (char *) &msg + offset)) {
125 tprintf("dst_len=%u, src_len=%u",
126 msg.rtm_dst_len, msg.rtm_src_len);
128 printflags(ip_type_of_services, msg.rtm_tos,
131 printxval(routing_table_ids, msg.rtm_table, NULL);
132 tprints(", action=");
133 printxval(fib_rule_actions, msg.rtm_type, "FR_ACT_???");
135 printflags(fib_rule_flags, msg.rtm_flags,
143 offset = NLMSG_ALIGN(sizeof(msg));
144 if (decode_nla && len > offset) {
146 decode_nlattr(tcp, addr + offset, len - offset,
147 rtnl_rule_attrs, "FRA_???",
148 fib_rule_hdr_nla_decoders,
149 ARRAY_SIZE(fib_rule_hdr_nla_decoders), &msg);