-
Notifications
You must be signed in to change notification settings - Fork 3
/
rte_flow_dump.c
235 lines (215 loc) · 7.03 KB
/
rte_flow_dump.c
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2019 Microsoft Corporation
* All rights reserved.
*/
#include <stdio.h>
#include <rte_flow.h>
#include "rte_flow_dump.h"
void
rte_flow_attr_dump(FILE *f,
const struct rte_flow_attr *attr)
{
fprintf(f, "Flow attr group %u priority %u%s%s%s\n",
attr->group, attr->priority,
attr->ingress ? " ingress" : "",
attr->egress ? " egress" : "",
attr->transfer ? " transfer" : "");
}
static const char *rte_flow_item_names[] = {
[RTE_FLOW_ITEM_TYPE_END] = "END",
[RTE_FLOW_ITEM_TYPE_VOID] = "VOID",
[RTE_FLOW_ITEM_TYPE_INVERT] = "INVERT",
[RTE_FLOW_ITEM_TYPE_ANY] = "ANY",
[RTE_FLOW_ITEM_TYPE_PF] = "PF",
[RTE_FLOW_ITEM_TYPE_VF] = "VF",
[RTE_FLOW_ITEM_TYPE_PHY_PORT] = "PHY_PORT",
[RTE_FLOW_ITEM_TYPE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H] = "ICMP6_ND_OPT_SLA_ETH",
[RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_TLA_ETH] = "ICMP6_ND_OPT_TLA_ETH",
[RTE_FLOW_ITEM_TYPE_MARK] = "MARK",
[RTE_FLOW_ITEM_TYPE_META] = "META",
};
static void
flow_item_any_dump(FILE *f, const char *prefix,
const struct rte_flow_item_any *a)
{
if (a)
fprintf(f, "\t %s %u\n", prefix, a->num);
}
static void
flow_item_eth_dump(FILE *f, const char *prefix,
const struct rte_flow_item_eth *e)
{
char b1[RTE_ETHER_ADDR_FMT_SIZE];
char b2[RTE_ETHER_ADDR_FMT_SIZE];
if (!e)
return;
rte_ether_format_addr(b1, sizeof(b1), &e->dst);
rte_ether_format_addr(b2, sizeof(b2), &e->src);
fprintf(f, "\t %s dst %s src %s type %u\n",
prefix, b1, b2, ntohs(e->type));
}
void
rte_flow_item_dump(FILE *f,
const struct rte_flow_item *pattern)
{
fprintf(f, "%s\n",
rte_flow_item_names[pattern->type]);
switch (pattern->type) {
case RTE_FLOW_ITEM_TYPE_ANY:
flow_item_any_dump(f, "Spec", pattern->spec);
flow_item_any_dump(f, "Mask", pattern->mask);
break;
case RTE_FLOW_ITEM_TYPE_ETH:
flow_item_eth_dump(f, "Spec", pattern->spec);
flow_item_eth_dump(f, "Mask", pattern->mask);
break;
default:
fprintf(f, "spec %p mask %p last %p\n",
pattern->spec, pattern->mask, pattern->last);
/* fall through */
case RTE_FLOW_ITEM_TYPE_END:
break;
}
}
static const char *rte_flow_action_names[] = {
[RTE_FLOW_ACTION_TYPE_END] = "END",
[RTE_FLOW_ACTION_TYPE_VOID] = "VOID",
[RTE_FLOW_ACTION_TYPE_PASSTHRU] = "PASSTHRU",
[RTE_FLOW_ACTION_TYPE_JUMP] = "JUMP",
[RTE_FLOW_ACTION_TYPE_MARK] = "MARK",
[RTE_FLOW_ACTION_TYPE_FLAG] = "FLAG",
[RTE_FLOW_ACTION_TYPE_QUEUE] = "QUEUE",
[RTE_FLOW_ACTION_TYPE_DROP] = "DROP",
[RTE_FLOW_ACTION_TYPE_COUNT] = "COUNT",
[RTE_FLOW_ACTION_TYPE_RSS] = "RSS",
[RTE_FLOW_ACTION_TYPE_PF] = "PF",
[RTE_FLOW_ACTION_TYPE_VF] = "VF",
[RTE_FLOW_ACTION_TYPE_PHY_PORT] = "PHY_PORT",
[RTE_FLOW_ACTION_TYPE_PORT_ID] = "PORT_ID",
[RTE_FLOW_ACTION_TYPE_METER] = "METER",
[RTE_FLOW_ACTION_TYPE_SECURITY] = "SECURITY",
[RTE_FLOW_ACTION_TYPE_OF_SET_MPLS_TTL] = "OF_SET_MPLS_TTL",
[RTE_FLOW_ACTION_TYPE_OF_DEC_MPLS_TTL] = "OF_DEC_MPLS_TTL",
[RTE_FLOW_ACTION_TYPE_OF_SET_NW_TTL] = "OF_SET_NW_TTL",
[RTE_FLOW_ACTION_TYPE_OF_DEC_NW_TTL] = "OF_DEC_NW_TTL",
[RTE_FLOW_ACTION_TYPE_OF_COPY_TTL_OUT] = "OF_COPY_TTL_OUT",
[RTE_FLOW_ACTION_TYPE_OF_COPY_TTL_IN] = "OF_COPY_TTL_IN",
[RTE_FLOW_ACTION_TYPE_OF_POP_VLAN] = "OF_POP_VLAN",
[RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN] = "OF_PUSH_VLAN",
[RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID] = "OF_SET_VLAN_VID",
[RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP] = "OF_SET_VLAN_PCP",
[RTE_FLOW_ACTION_TYPE_OF_POP_MPLS] = "OF_POP_MPLS",
[RTE_FLOW_ACTION_TYPE_OF_PUSH_MPLS] = "OF_PUSH_MPLS",
[RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP] = "VXLAN_ENCAP",
[RTE_FLOW_ACTION_TYPE_VXLAN_DECAP] = "VXLAN_DECAP",
[RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP] = "NVGRE_ENCAP",
[RTE_FLOW_ACTION_TYPE_NVGRE_DECAP] = "NVGRE_DECAP",
[RTE_FLOW_ACTION_TYPE_RAW_ENCAP] = "RAW_ENCAP",
[RTE_FLOW_ACTION_TYPE_RAW_DECAP] = "RAW_DECAP",
[RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC] = "SET_IPV4_SRC",
[RTE_FLOW_ACTION_TYPE_SET_IPV4_DST] = "SET_IPV4_DST",
[RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC] = "SET_IPV6_SRC",
[RTE_FLOW_ACTION_TYPE_SET_IPV6_DST] = "SET_IPV6_DST",
[RTE_FLOW_ACTION_TYPE_SET_TP_SRC] = "SET_TP_SRC",
[RTE_FLOW_ACTION_TYPE_SET_TP_DST] = "SET_TP_DST",
[RTE_FLOW_ACTION_TYPE_MAC_SWAP] = "MAC_SWAP",
[RTE_FLOW_ACTION_TYPE_DEC_TTL] = "DEC_TTL",
[RTE_FLOW_ACTION_TYPE_SET_TTL] = "SET_TTL",
[RTE_FLOW_ACTION_TYPE_SET_MAC_SRC] = "SET_MAC_SRC",
[RTE_FLOW_ACTION_TYPE_SET_MAC_DST] = "SET_MAC_DST",
};
void
rte_flow_action_dump(FILE *f,
const struct rte_flow_action *action)
{
fprintf(f, "%s", rte_flow_action_names[action->type]);
switch (action->type) {
case RTE_FLOW_ACTION_TYPE_MARK: {
const struct rte_flow_action_mark *m = action->conf;
fprintf(f, " id %u", m->id);
break;
}
case RTE_FLOW_ACTION_TYPE_JUMP: {
const struct rte_flow_action_jump *j = action->conf;
fprintf(f, " group %u", j->group);
break;
}
case RTE_FLOW_ACTION_TYPE_QUEUE: {
const struct rte_flow_action_queue *q = action->conf;
fprintf(f, " index %u", q->index);
break;
}
case RTE_FLOW_ACTION_TYPE_COUNT: {
const struct rte_flow_action_count *c = action->conf;
fprintf(f, " count %u%s", c->id, c->shared ? " shared" : "");
break;
}
case RTE_FLOW_ACTION_TYPE_RSS: {
const struct rte_flow_action_rss *rss = action->conf;
uint32_t i;
fprintf(f, " level %u types %#"PRIx64" [",
rss->level, rss->types);
for (i = 0; i < rss->queue_num; i++)
fprintf(f, " %u", rss->queue[i]);
putc(']', f);
if (rss->key_len > 0) {
fprintf(f, " key [");
for (i = 0; i < rss->key_len; i++)
fprintf(f, "%02x", rss->key[i]);
putc(']', f);
}
break;
}
default:
break;
}
fprintf(f, "\n");
}
void
rte_flow_dump(FILE *f,
const struct rte_flow_attr *attr,
const struct rte_flow_item pattern[],
const struct rte_flow_action actions[])
{
int i;
rte_flow_attr_dump(f, attr);
i = 0;
do {
putc('\t', f);
rte_flow_item_dump(f, &pattern[i]);
} while (pattern[i++].type != RTE_FLOW_ITEM_TYPE_END);
i = 0;
fprintf(f, "Action\n");
do {
putc('\t', f);
rte_flow_action_dump(f, &actions[i]);
} while (actions[i++].type != RTE_FLOW_ACTION_TYPE_END);
}