DPDK  2.1.0
rte_acl.h
Go to the documentation of this file.
1 /*-
2  * BSD LICENSE
3  *
4  * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  * * Neither the name of Intel Corporation nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #ifndef _RTE_ACL_H_
35 #define _RTE_ACL_H_
36 
43 #include <rte_acl_osdep.h>
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 #define RTE_ACL_MAX_CATEGORIES 16
50 
51 #define RTE_ACL_RESULTS_MULTIPLIER (XMM_SIZE / sizeof(uint32_t))
52 
53 #define RTE_ACL_MAX_LEVELS 64
54 #define RTE_ACL_MAX_FIELDS 64
55 
56 union rte_acl_field_types {
57  uint8_t u8;
58  uint16_t u16;
59  uint32_t u32;
60  uint64_t u64;
61 };
62 
63 enum {
64  RTE_ACL_FIELD_TYPE_MASK = 0,
65  RTE_ACL_FIELD_TYPE_RANGE,
66  RTE_ACL_FIELD_TYPE_BITMASK
67 };
68 
81  uint8_t type;
82  uint8_t size;
83  uint8_t field_index;
84  uint8_t input_index;
85  uint32_t offset;
86 };
87 
93  uint32_t num_categories;
94  uint32_t num_fields;
95  struct rte_acl_field_def defs[RTE_ACL_MAX_FIELDS];
97  size_t max_size;
99 };
100 
105  union rte_acl_field_types value;
107  union rte_acl_field_types mask_range;
114 };
115 
116 enum {
117  RTE_ACL_TYPE_SHIFT = 29,
118  RTE_ACL_MAX_INDEX = RTE_LEN2MASK(RTE_ACL_TYPE_SHIFT, uint32_t),
119  RTE_ACL_MAX_PRIORITY = RTE_ACL_MAX_INDEX,
120  RTE_ACL_MIN_PRIORITY = 0,
121 };
122 
123 #define RTE_ACL_INVALID_USERDATA 0
124 
125 #define RTE_ACL_MASKLEN_TO_BITMASK(v, s) \
126 ((v) == 0 ? (v) : (typeof(v))((uint64_t)-1 << ((s) * CHAR_BIT - (v))))
127 
132  uint32_t category_mask;
133  int32_t priority;
134  uint32_t userdata;
135 };
136 
142 #define RTE_ACL_RULE_DEF(name, fld_num) struct name {\
143  struct rte_acl_rule_data data; \
144  struct rte_acl_field field[fld_num]; \
145 }
146 
147 RTE_ACL_RULE_DEF(rte_acl_rule, 0);
148 
149 #define RTE_ACL_RULE_SZ(fld_num) \
150  (sizeof(struct rte_acl_rule) + sizeof(struct rte_acl_field) * (fld_num))
151 
152 
154 #define RTE_ACL_NAMESIZE 32
155 
160  const char *name;
161  int socket_id;
162  uint32_t rule_size;
163  uint32_t max_rule_num;
164 };
165 
166 
178 struct rte_acl_ctx *
179 rte_acl_create(const struct rte_acl_param *param);
180 
191 struct rte_acl_ctx *
192 rte_acl_find_existing(const char *name);
193 
200 void
201 rte_acl_free(struct rte_acl_ctx *ctx);
202 
222 int
223 rte_acl_add_rules(struct rte_acl_ctx *ctx, const struct rte_acl_rule *rules,
224  uint32_t num);
225 
234 void
235 rte_acl_reset_rules(struct rte_acl_ctx *ctx);
236 
251 int
252 rte_acl_build(struct rte_acl_ctx *ctx, const struct rte_acl_config *cfg);
253 
262 void
263 rte_acl_reset(struct rte_acl_ctx *ctx);
264 
269  RTE_ACL_CLASSIFY_DEFAULT = 0,
273  RTE_ACL_CLASSIFY_NUM /* should always be the last one. */
274 };
275 
305 extern int
306 rte_acl_classify(const struct rte_acl_ctx *ctx,
307  const uint8_t **data,
308  uint32_t *results, uint32_t num,
309  uint32_t categories);
310 
345 extern int
346 rte_acl_classify_alg(const struct rte_acl_ctx *ctx,
347  const uint8_t **data,
348  uint32_t *results, uint32_t num,
349  uint32_t categories,
350  enum rte_acl_classify_alg alg);
351 
352 /*
353  * Override the default classifier function for a given ACL context.
354  * @param ctx
355  * ACL context to change classify function for.
356  * @param alg
357  * New default classify algorithm for given ACL context.
358  * It is the caller responsibility to ensure that the value refers to the
359  * existing algorithm, and that it could be run on the given CPU.
360  * @return
361  * - -EINVAL if the parameters are invalid.
362  * - Zero if operation completed successfully.
363  */
364 extern int
365 rte_acl_set_ctx_classify(struct rte_acl_ctx *ctx,
366  enum rte_acl_classify_alg alg);
367 
374 void
375 rte_acl_dump(const struct rte_acl_ctx *ctx);
376 
380 void
381 rte_acl_list_dump(void);
382 
389  uint8_t proto;
390  uint8_t proto_mask;
391  uint16_t vlan;
392  uint16_t vlan_mask;
393  uint16_t domain;
394  uint16_t domain_mask;
395  uint32_t src_addr;
396  uint32_t src_mask_len;
397  uint32_t dst_addr;
398  uint32_t dst_mask_len;
399  uint16_t src_port_low;
400  uint16_t src_port_high;
401  uint16_t dst_port_low;
402  uint16_t dst_port_high;
403 };
404 
408 enum {
409  RTE_ACL_IPV4VLAN_PROTO_FIELD,
410  RTE_ACL_IPV4VLAN_VLAN1_FIELD,
411  RTE_ACL_IPV4VLAN_VLAN2_FIELD,
412  RTE_ACL_IPV4VLAN_SRC_FIELD,
413  RTE_ACL_IPV4VLAN_DST_FIELD,
414  RTE_ACL_IPV4VLAN_SRCP_FIELD,
415  RTE_ACL_IPV4VLAN_DSTP_FIELD,
416  RTE_ACL_IPV4VLAN_NUM_FIELDS
417 };
418 
422 #define RTE_ACL_IPV4VLAN_RULE_SZ \
423  RTE_ACL_RULE_SZ(RTE_ACL_IPV4VLAN_NUM_FIELDS)
424 
425 /*
426  * That effectively defines order of IPV4VLAN classifications:
427  * - PROTO
428  * - VLAN (TAG and DOMAIN)
429  * - SRC IP ADDRESS
430  * - DST IP ADDRESS
431  * - PORTS (SRC and DST)
432  */
433 enum {
434  RTE_ACL_IPV4VLAN_PROTO,
435  RTE_ACL_IPV4VLAN_VLAN,
436  RTE_ACL_IPV4VLAN_SRC,
437  RTE_ACL_IPV4VLAN_DST,
438  RTE_ACL_IPV4VLAN_PORTS,
439  RTE_ACL_IPV4VLAN_NUM
440 };
441 
459 int
460 rte_acl_ipv4vlan_add_rules(struct rte_acl_ctx *ctx,
461  const struct rte_acl_ipv4vlan_rule *rules,
462  uint32_t num);
463 
481 int
482 rte_acl_ipv4vlan_build(struct rte_acl_ctx *ctx,
483  const uint32_t layout[RTE_ACL_IPV4VLAN_NUM],
484  uint32_t num_categories);
485 
486 
487 #ifdef __cplusplus
488 }
489 #endif
490 
491 #endif /* _RTE_ACL_H_ */