1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Intel Corporation
5 #ifndef _RTE_FLOW_CLASSIFY_H_
6 #define _RTE_FLOW_CLASSIFY_H_
11 * RTE Flow Classify Library
13 * @b EXPERIMENTAL: this API may change without prior notice
15 * This library provides flow record information with some measured properties.
17 * Application should define the flow and measurement criteria (action) for it.
19 * The Library doesn't maintain any flow records itself, instead flow
20 * information is returned to upper layer only for given packets.
22 * It is application's responsibility to call rte_flow_classifier_query()
23 * for a burst of packets, just after receiving them or before transmitting
25 * Application should provide the flow type interested in, measurement to apply
26 * to that flow in rte_flow_classify_table_entry_add() API, and should provide
27 * the rte_flow_classifier object and storage to put results in for the
28 * rte_flow_classifier_query() API.
31 * - application calls rte_flow_classifier_create() to create an
32 * rte_flow_classifier object.
33 * - application calls rte_flow_classify_table_create() to create a table
34 * in the rte_flow_classifier object.
35 * - application calls rte_flow_classify_table_entry_add() to add a rule to
36 * the table in the rte_flow_classifier object.
37 * - application calls rte_flow_classifier_query() in a polling manner,
38 * preferably after rte_eth_rx_burst(). This will cause the library to
39 * match packet information to flow information with some measurements.
40 * - rte_flow_classifier object can be destroyed when it is no longer needed
41 * with rte_flow_classifier_free()
44 #include <rte_ethdev.h>
45 #include <rte_ether.h>
48 #include <rte_table_acl.h>
54 extern int librte_flow_classify_logtype;
56 #define RTE_FLOW_CLASSIFY_LOG(level, fmt, args...) \
57 rte_log(RTE_LOG_ ## level, librte_flow_classify_logtype, "%s(): " fmt, \
60 /** Opaque data type for flow classifier */
61 struct rte_flow_classifier;
63 /** Opaque data type for flow classify rule */
64 struct rte_flow_classify_rule;
66 /** Flow classify rule type */
67 enum rte_flow_classify_rule_type {
69 RTE_FLOW_CLASSIFY_RULE_TYPE_NONE,
70 /** IPv4 5tuple type */
71 RTE_FLOW_CLASSIFY_RULE_TYPE_IPV4_5TUPLE,
74 /** Flow classify table type */
75 enum rte_flow_classify_table_type {
77 RTE_FLOW_CLASSIFY_TABLE_TYPE_NONE,
79 RTE_FLOW_CLASSIFY_TABLE_TYPE_ACL,
83 * Maximum number of tables allowed for any Flow Classifier instance.
84 * The value of this parameter cannot be changed.
86 #define RTE_FLOW_CLASSIFY_TABLE_MAX 64
88 /** Parameters for flow classifier creation */
89 struct rte_flow_classifier_params {
90 /** flow classifier name */
93 /** CPU socket ID where memory for the flow classifier and its */
94 /** elements (tables) should be allocated */
98 enum rte_flow_classify_table_type type;
101 /** Parameters for table creation */
102 struct rte_flow_classify_table_params {
103 /** Table operations (specific to each table type) */
104 struct rte_table_ops *ops;
106 /** Opaque param to be passed to the table create operation */
110 /** IPv4 5-tuple data */
111 struct rte_flow_classify_ipv4_5tuple {
112 uint32_t dst_ip; /**< Destination IP address in big endian. */
113 uint32_t dst_ip_mask; /**< Mask of destination IP address. */
114 uint32_t src_ip; /**< Source IP address in big endian. */
115 uint32_t src_ip_mask; /**< Mask of destination IP address. */
116 uint16_t dst_port; /**< Destination port in big endian. */
117 uint16_t dst_port_mask; /**< Mask of destination port. */
118 uint16_t src_port; /**< Source Port in big endian. */
119 uint16_t src_port_mask; /**< Mask of source port. */
120 uint8_t proto; /**< L4 protocol. */
121 uint8_t proto_mask; /**< Mask of L4 protocol. */
127 * For the count action, stats can be returned by the query API.
129 * Storage for stats is provided by application.
131 struct rte_flow_classify_stats {
135 struct rte_flow_classify_ipv4_5tuple_stats {
136 /** count of packets that match IPv4 5tuple pattern */
138 /** IPv4 5tuple data */
139 struct rte_flow_classify_ipv4_5tuple ipv4_5tuple;
143 * Flow classifier create
146 * Parameters for flow classifier creation
148 * Handle to flow classifier instance on success or NULL otherwise
150 struct rte_flow_classifier *
151 rte_flow_classifier_create(struct rte_flow_classifier_params *params);
154 * Flow classifier free
157 * Handle to flow classifier instance
159 * 0 on success, error code otherwise
162 rte_flow_classifier_free(struct rte_flow_classifier *cls);
165 * Flow classify table create
168 * Handle to flow classifier instance
170 * Parameters for flow_classify table creation
172 * Table ID. Valid only within the scope of table IDs of the current
173 * classifier. Only returned after a successful invocation.
175 * 0 on success, error code otherwise
178 rte_flow_classify_table_create(struct rte_flow_classifier *cls,
179 struct rte_flow_classify_table_params *params,
183 * Add a flow classify rule to the flow_classifer table.
186 * Flow classifier handle
187 * @param[in] table_id
189 * @param[out] key_found
190 * returns 1 if key present already, 0 otherwise.
192 * Flow rule attributes
194 * Pattern specification (list terminated by the END pattern item).
196 * Associated actions (list terminated by the END pattern item).
198 * Perform verbose error reporting if not NULL. Structure
199 * initialised in case of error only.
201 * A valid handle in case of success, NULL otherwise.
203 struct rte_flow_classify_rule *
204 rte_flow_classify_table_entry_add(struct rte_flow_classifier *cls,
207 const struct rte_flow_attr *attr,
208 const struct rte_flow_item pattern[],
209 const struct rte_flow_action actions[],
210 struct rte_flow_error *error);
213 * Delete a flow classify rule from the flow_classifer table.
216 * Flow classifier handle
217 * @param[in] table_id
222 * 0 on success, error code otherwise.
225 rte_flow_classify_table_entry_delete(struct rte_flow_classifier *cls,
227 struct rte_flow_classify_rule *rule);
230 * Query flow classifier for given rule.
233 * Flow classifier handle
234 * @param[in] table_id
237 * Pointer to packets to process
239 * Number of packets to process
243 * Flow classify stats
246 * 0 on success, error code otherwise.
249 rte_flow_classifier_query(struct rte_flow_classifier *cls,
251 struct rte_mbuf **pkts,
252 const uint16_t nb_pkts,
253 struct rte_flow_classify_rule *rule,
254 struct rte_flow_classify_stats *stats);
260 #endif /* _RTE_FLOW_CLASSIFY_H_ */