test mbuf attach
[dpdk.git] / lib / librte_lpm / rte_lpm6.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation
3  */
4 #ifndef _RTE_LPM6_H_
5 #define _RTE_LPM6_H_
6
7 /**
8  * @file
9  * RTE Longest Prefix Match for IPv6 (LPM6)
10  */
11
12 #include <stdint.h>
13 #include <rte_compat.h>
14
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18
19
20 #define RTE_LPM6_MAX_DEPTH               128
21 #define RTE_LPM6_IPV6_ADDR_SIZE           16
22 /** Max number of characters in LPM name. */
23 #define RTE_LPM6_NAMESIZE                 32
24
25 /** LPM structure. */
26 struct rte_lpm6;
27
28 /** LPM configuration structure. */
29 struct rte_lpm6_config {
30         uint32_t max_rules;      /**< Max number of rules. */
31         uint32_t number_tbl8s;   /**< Number of tbl8s to allocate. */
32         int flags;               /**< This field is currently unused. */
33 };
34
35 /**
36  * Create an LPM object.
37  *
38  * @param name
39  *   LPM object name
40  * @param socket_id
41  *   NUMA socket ID for LPM table memory allocation
42  * @param config
43  *   Structure containing the configuration
44  * @return
45  *   Handle to LPM object on success, NULL otherwise with rte_errno set
46  *   to an appropriate values. Possible rte_errno values include:
47  *    - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
48  *    - E_RTE_SECONDARY - function was called from a secondary process instance
49  *    - EINVAL - invalid parameter passed to function
50  *    - ENOSPC - the maximum number of memzones has already been allocated
51  *    - EEXIST - a memzone with the same name already exists
52  *    - ENOMEM - no appropriate memory area found in which to create memzone
53  */
54 struct rte_lpm6 *
55 rte_lpm6_create(const char *name, int socket_id,
56                 const struct rte_lpm6_config *config);
57
58 /**
59  * Find an existing LPM object and return a pointer to it.
60  *
61  * @param name
62  *   Name of the lpm object as passed to rte_lpm6_create()
63  * @return
64  *   Pointer to lpm object or NULL if object not found with rte_errno
65  *   set appropriately. Possible rte_errno values include:
66  *    - ENOENT - required entry not available to return.
67  */
68 struct rte_lpm6 *
69 rte_lpm6_find_existing(const char *name);
70
71 /**
72  * Free an LPM object.
73  *
74  * @param lpm
75  *   LPM object handle
76  * @return
77  *   None
78  */
79 void
80 rte_lpm6_free(struct rte_lpm6 *lpm);
81
82 /**
83  * Add a rule to the LPM table.
84  *
85  * @param lpm
86  *   LPM object handle
87  * @param ip
88  *   IP of the rule to be added to the LPM table
89  * @param depth
90  *   Depth of the rule to be added to the LPM table
91  * @param next_hop
92  *   Next hop of the rule to be added to the LPM table
93  * @return
94  *   0 on success, negative value otherwise
95  */
96 int
97 rte_lpm6_add(struct rte_lpm6 *lpm, const uint8_t *ip, uint8_t depth,
98              uint32_t next_hop);
99
100 /**
101  * Check if a rule is present in the LPM table,
102  * and provide its next hop if it is.
103  *
104  * @param lpm
105  *   LPM object handle
106  * @param ip
107  *   IP of the rule to be searched
108  * @param depth
109  *   Depth of the rule to searched
110  * @param next_hop
111  *   Next hop of the rule (valid only if it is found)
112  * @return
113  *   1 if the rule exists, 0 if it does not, a negative value on failure
114  */
115 int
116 rte_lpm6_is_rule_present(struct rte_lpm6 *lpm, const uint8_t *ip, uint8_t depth,
117                          uint32_t *next_hop);
118
119 /**
120  * Delete a rule from the LPM table.
121  *
122  * @param lpm
123  *   LPM object handle
124  * @param ip
125  *   IP of the rule to be deleted from the LPM table
126  * @param depth
127  *   Depth of the rule to be deleted from the LPM table
128  * @return
129  *   0 on success, negative value otherwise
130  */
131 int
132 rte_lpm6_delete(struct rte_lpm6 *lpm, const uint8_t *ip, uint8_t depth);
133
134 /**
135  * Delete a rule from the LPM table.
136  *
137  * @param lpm
138  *   LPM object handle
139  * @param ips
140  *   Array of IPs to be deleted from the LPM table
141  * @param depths
142  *   Array of depths of the rules to be deleted from the LPM table
143  * @param n
144  *   Number of rules to be deleted from the LPM table
145  * @return
146  *   0 on success, negative value otherwise.
147  */
148 int
149 rte_lpm6_delete_bulk_func(struct rte_lpm6 *lpm,
150                 uint8_t ips[][RTE_LPM6_IPV6_ADDR_SIZE], uint8_t *depths, unsigned n);
151
152 /**
153  * Delete all rules from the LPM table.
154  *
155  * @param lpm
156  *   LPM object handle
157  */
158 void
159 rte_lpm6_delete_all(struct rte_lpm6 *lpm);
160
161 /**
162  * Lookup an IP into the LPM table.
163  *
164  * @param lpm
165  *   LPM object handle
166  * @param ip
167  *   IP to be looked up in the LPM table
168  * @param next_hop
169  *   Next hop of the most specific rule found for IP (valid on lookup hit only)
170  * @return
171  *   -EINVAL for incorrect arguments, -ENOENT on lookup miss, 0 on lookup hit
172  */
173 int
174 rte_lpm6_lookup(const struct rte_lpm6 *lpm, const uint8_t *ip, uint32_t *next_hop);
175
176 /**
177  * Lookup multiple IP addresses in an LPM table.
178  *
179  * @param lpm
180  *   LPM object handle
181  * @param ips
182  *   Array of IPs to be looked up in the LPM table
183  * @param next_hops
184  *   Next hop of the most specific rule found for IP (valid on lookup hit only).
185  *   This is an array of two byte values. The next hop will be stored on
186  *   each position on success; otherwise the position will be set to -1.
187  * @param n
188  *   Number of elements in ips (and next_hops) array to lookup.
189  *  @return
190  *   -EINVAL for incorrect arguments, otherwise 0
191  */
192 int
193 rte_lpm6_lookup_bulk_func(const struct rte_lpm6 *lpm,
194                 uint8_t ips[][RTE_LPM6_IPV6_ADDR_SIZE],
195                 int32_t *next_hops, unsigned int n);
196
197 #ifdef __cplusplus
198 }
199 #endif
200
201 #endif