summaryrefslogtreecommitdiff
path: root/src/rtnl_tc_action.c
blob: 55f40f29d61779d2e3ac937e8f1394bc5edcdca3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
 * Copyright (c) 2016 Fabien Siron <fabien.siron@epita.fr>
 * Copyright (c) 2017 JingPiao Chen <chenjingpiao@gmail.com>
 * Copyright (c) 2016-2022 The strace developers.
 * All rights reserved.
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#include "defs.h"
#include "netlink_route.h"
#include "nlattr.h"

#include "netlink.h"
#include <linux/pkt_cls.h>
#include <linux/rtnetlink.h>

#include "xlat/rtnl_tc_action_attrs.h"
#include "xlat/rtnl_tca_act_flags.h"
#include "xlat/rtnl_tca_act_hw_stats.h"
#include "xlat/rtnl_tca_root_flags.h"
#include "xlat/rtnl_tca_root_attrs.h"


static bool
decode_tca_act_flags(struct tcb *const tcp,
		        const kernel_ulong_t addr,
		        const unsigned int len,
		        const void *const opaque_data)
{
	static const struct decode_nla_xlat_opts opts = {
		rtnl_tca_act_flags, "TCA_ACT_FLAGS_???",
		.size = 4,
	};

	return decode_nla_flags(tcp, addr, len, &opts);
}

static bool
decode_tca_act_hw_stats(struct tcb *const tcp,
		        const kernel_ulong_t addr,
		        const unsigned int len,
		        const void *const opaque_data)
{
	static const struct decode_nla_xlat_opts opts = {
		rtnl_tca_act_hw_stats, "TCA_ACT_HW_STATS_???",
		.size = 4,
	};

	return decode_nla_flags(tcp, addr, len, &opts);
}

static const nla_decoder_t tca_act_nla_decoders[] = {
	[TCA_ACT_KIND]		= decode_nla_str,
	[TCA_ACT_OPTIONS]	= NULL, /* unimplemented */
	[TCA_ACT_INDEX]		= decode_nla_u32,
	[TCA_ACT_STATS]		= decode_nla_tc_stats,
	[TCA_ACT_PAD]		= NULL,
	[TCA_ACT_COOKIE]	= NULL, /* default parser */
	[TCA_ACT_FLAGS]		= decode_tca_act_flags,
	[TCA_ACT_HW_STATS]	= decode_tca_act_hw_stats,
	[TCA_ACT_USED_HW_STATS]	= decode_tca_act_hw_stats,
	[TCA_ACT_IN_HW_COUNT]	= decode_nla_u32,
};

static bool
decode_tca_action(struct tcb *const tcp,
		  const kernel_ulong_t addr,
		  const unsigned int len,
		  const void *const opaque_data)
{
	decode_nlattr(tcp, addr, len, rtnl_tc_action_attrs, "TCA_ACT_???",
		      ARRSZ_PAIR(tca_act_nla_decoders), NULL);

	return true;
}

static bool
decode_tca_root_act_tab(struct tcb *const tcp,
			const kernel_ulong_t addr,
			const unsigned int len,
			const void *const opaque_data)
{
	nla_decoder_t tca_action_decoder = &decode_tca_action;

	/* TCA_ROOT_TAB (nee TCA_ACT_TAB) misuses nesting for array */
	decode_nlattr(tcp, addr, len, NULL, NULL,
		      &tca_action_decoder, 0, NULL);

	return true;
}

static bool
decode_tca_root_act_flags(struct tcb *const tcp,
			  const kernel_ulong_t addr,
			  const unsigned int len,
			  const void *const opaque_data)
{
	static const struct decode_nla_xlat_opts opts = {
		rtnl_tca_root_flags, "TCA_ACT_FLAG_???",
		.size = 4,
	};

	return decode_nla_flags(tcp, addr, len, &opts);
}

static bool
decode_tca_msecs(struct tcb *const tcp,
		 const kernel_ulong_t addr,
		 const unsigned int len,
		 const void *const opaque_data)
{
	uint64_t val;

	if (len > sizeof(val))
		return false;

	if (!umoven_to_uint64_or_printaddr(tcp, addr, len, &val))
		print_ticks(val, 1000, 3);

	return true;
}

static const nla_decoder_t tcamsg_nla_decoders[] = {
	[TCA_ROOT_UNSPEC]	= NULL,
	[TCA_ROOT_TAB]		= decode_tca_root_act_tab,
	[TCA_ROOT_FLAGS]	= decode_tca_root_act_flags,
	[TCA_ROOT_COUNT]	= decode_nla_u32,
	[TCA_ROOT_TIME_DELTA]	= decode_tca_msecs,
	[TCA_ROOT_EXT_WARN_MSG]	= decode_nla_str,
};

DECL_NETLINK_ROUTE_DECODER(decode_tcamsg)
{
	struct tcamsg tca = { .tca_family = family };

	tprint_struct_begin();
	PRINT_FIELD_XVAL(tca, tca_family, addrfams, "AF_???");
	tprint_struct_end();

	const size_t offset = NLMSG_ALIGN(sizeof(tca));
	if (len > offset) {
		tprint_array_next();
		decode_nlattr(tcp, addr + offset, len - offset,
			      rtnl_tca_root_attrs, "TCA_ROOT_???",
			      tcamsg_nla_decoders,
			      ARRAY_SIZE(tcamsg_nla_decoders), NULL);
	}
}