4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
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.
38 * RTE Longest Prefix Match for IPv6 (LPM6)
42 #include <rte_compat.h>
49 #define RTE_LPM6_MAX_DEPTH 128
50 #define RTE_LPM6_IPV6_ADDR_SIZE 16
51 /** Max number of characters in LPM name. */
52 #define RTE_LPM6_NAMESIZE 32
57 /** LPM configuration structure. */
58 struct rte_lpm6_config {
59 uint32_t max_rules; /**< Max number of rules. */
60 uint32_t number_tbl8s; /**< Number of tbl8s to allocate. */
61 int flags; /**< This field is currently unused. */
65 * Create an LPM object.
70 * NUMA socket ID for LPM table memory allocation
72 * Structure containing the configuration
74 * Handle to LPM object on success, NULL otherwise with rte_errno set
75 * to an appropriate values. Possible rte_errno values include:
76 * - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
77 * - E_RTE_SECONDARY - function was called from a secondary process instance
78 * - EINVAL - invalid parameter passed to function
79 * - ENOSPC - the maximum number of memzones has already been allocated
80 * - EEXIST - a memzone with the same name already exists
81 * - ENOMEM - no appropriate memory area found in which to create memzone
84 rte_lpm6_create(const char *name, int socket_id,
85 const struct rte_lpm6_config *config);
88 * Find an existing LPM object and return a pointer to it.
91 * Name of the lpm object as passed to rte_lpm6_create()
93 * Pointer to lpm object or NULL if object not found with rte_errno
94 * set appropriately. Possible rte_errno values include:
95 * - ENOENT - required entry not available to return.
98 rte_lpm6_find_existing(const char *name);
101 * Free an LPM object.
109 rte_lpm6_free(struct rte_lpm6 *lpm);
112 * Add a rule to the LPM table.
117 * IP of the rule to be added to the LPM table
119 * Depth of the rule to be added to the LPM table
121 * Next hop of the rule to be added to the LPM table
123 * 0 on success, negative value otherwise
126 rte_lpm6_add(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth,
129 rte_lpm6_add_v20(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth,
132 rte_lpm6_add_v1705(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth,
136 * Check if a rule is present in the LPM table,
137 * and provide its next hop if it is.
142 * IP of the rule to be searched
144 * Depth of the rule to searched
146 * Next hop of the rule (valid only if it is found)
148 * 1 if the rule exists, 0 if it does not, a negative value on failure
151 rte_lpm6_is_rule_present(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth,
154 rte_lpm6_is_rule_present_v20(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth,
157 rte_lpm6_is_rule_present_v1705(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth,
161 * Delete a rule from the LPM table.
166 * IP of the rule to be deleted from the LPM table
168 * Depth of the rule to be deleted from the LPM table
170 * 0 on success, negative value otherwise
173 rte_lpm6_delete(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth);
176 * Delete a rule from the LPM table.
181 * Array of IPs to be deleted from the LPM table
183 * Array of depths of the rules to be deleted from the LPM table
185 * Number of rules to be deleted from the LPM table
187 * 0 on success, negative value otherwise.
190 rte_lpm6_delete_bulk_func(struct rte_lpm6 *lpm,
191 uint8_t ips[][RTE_LPM6_IPV6_ADDR_SIZE], uint8_t *depths, unsigned n);
194 * Delete all rules from the LPM table.
200 rte_lpm6_delete_all(struct rte_lpm6 *lpm);
203 * Lookup an IP into the LPM table.
208 * IP to be looked up in the LPM table
210 * Next hop of the most specific rule found for IP (valid on lookup hit only)
212 * -EINVAL for incorrect arguments, -ENOENT on lookup miss, 0 on lookup hit
215 rte_lpm6_lookup(const struct rte_lpm6 *lpm, uint8_t *ip, uint32_t *next_hop);
217 rte_lpm6_lookup_v20(const struct rte_lpm6 *lpm, uint8_t *ip, uint8_t *next_hop);
219 rte_lpm6_lookup_v1705(const struct rte_lpm6 *lpm, uint8_t *ip,
223 * Lookup multiple IP addresses in an LPM table.
228 * Array of IPs to be looked up in the LPM table
230 * Next hop of the most specific rule found for IP (valid on lookup hit only).
231 * This is an array of two byte values. The next hop will be stored on
232 * each position on success; otherwise the position will be set to -1.
234 * Number of elements in ips (and next_hops) array to lookup.
236 * -EINVAL for incorrect arguments, otherwise 0
239 rte_lpm6_lookup_bulk_func(const struct rte_lpm6 *lpm,
240 uint8_t ips[][RTE_LPM6_IPV6_ADDR_SIZE],
241 int32_t *next_hops, unsigned int n);
243 rte_lpm6_lookup_bulk_func_v20(const struct rte_lpm6 *lpm,
244 uint8_t ips[][RTE_LPM6_IPV6_ADDR_SIZE],
245 int16_t *next_hops, unsigned int n);
247 rte_lpm6_lookup_bulk_func_v1705(const struct rte_lpm6 *lpm,
248 uint8_t ips[][RTE_LPM6_IPV6_ADDR_SIZE],
249 int32_t *next_hops, unsigned int n);