1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
9 * RTE Longest Prefix Match for IPv6 (LPM6)
17 #define RTE_LPM6_MAX_DEPTH 128
18 #define RTE_LPM6_IPV6_ADDR_SIZE 16
19 /** Max number of characters in LPM name. */
20 #define RTE_LPM6_NAMESIZE 32
26 struct rte_lpm6_external {
27 struct nhop_object **nh_idx; /**< # -> idx mappings */
28 uint32_t default_idx; /* nhop index of default route */
29 uint32_t fibnum; /* fib index */
32 /** LPM configuration structure. */
33 struct rte_lpm6_config {
34 uint32_t max_rules; /**< Max number of rules. */
35 uint32_t number_tbl8s; /**< Number of tbl8s to allocate. */
36 int flags; /**< This field is currently unused. */
39 #define RTE_LPM6_RULE_SIZE 32
40 struct rte_lpm6_rule *fill_rule6(char *buffer, const uint8_t *ip,
41 uint8_t depth, uint32_t next_hop);
43 * Create an LPM object.
48 * NUMA socket ID for LPM table memory allocation
50 * Structure containing the configuration
52 * Handle to LPM object on success, NULL otherwise with rte_errno set
53 * to an appropriate values. Possible rte_errno values include:
54 * - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
55 * - E_RTE_SECONDARY - function was called from a secondary process instance
56 * - EINVAL - invalid parameter passed to function
57 * - ENOSPC - the maximum number of memzones has already been allocated
58 * - EEXIST - a memzone with the same name already exists
59 * - ENOMEM - no appropriate memory area found in which to create memzone
62 rte_lpm6_create(const char *name, int socket_id,
63 const struct rte_lpm6_config *config);
66 * Find an existing LPM object and return a pointer to it.
69 * Name of the lpm object as passed to rte_lpm6_create()
71 * Pointer to lpm object or NULL if object not found with rte_errno
72 * set appropriately. Possible rte_errno values include:
73 * - ENOENT - required entry not available to return.
76 rte_lpm6_find_existing(const char *name);
87 rte_lpm6_free(struct rte_lpm6 *lpm);
90 * Add a rule to the LPM table.
95 * IP of the rule to be added to the LPM table
97 * Depth of the rule to be added to the LPM table
99 * Next hop of the rule to be added to the LPM table
101 * 0 on success, negative value otherwise
104 rte_lpm6_add(struct rte_lpm6 *lpm, const uint8_t *ip, uint8_t depth,
105 uint32_t next_hop, int is_new_rule);
108 * Check if a rule is present in the LPM table,
109 * and provide its next hop if it is.
114 * IP of the rule to be searched
116 * Depth of the rule to searched
118 * Next hop of the rule (valid only if it is found)
120 * 1 if the rule exists, 0 if it does not, a negative value on failure
123 rte_lpm6_is_rule_present(struct rte_lpm6 *lpm, const uint8_t *ip, uint8_t depth,
127 * Delete a rule from the LPM table.
132 * IP of the rule to be deleted from the LPM table
134 * Depth of the rule to be deleted from the LPM table
136 * 0 on success, negative value otherwise
139 rte_lpm6_delete(struct rte_lpm6 *lpm, const uint8_t *ip, uint8_t depth,
140 struct rte_lpm6_rule *lsp_rule);
143 * Delete a rule from the LPM table.
148 * Array of IPs to be deleted from the LPM table
150 * Array of depths of the rules to be deleted from the LPM table
152 * Number of rules to be deleted from the LPM table
154 * 0 on success, negative value otherwise.
157 rte_lpm6_delete_bulk_func(struct rte_lpm6 *lpm,
158 uint8_t ips[][RTE_LPM6_IPV6_ADDR_SIZE], uint8_t *depths, unsigned n);
161 * Delete all rules from the LPM table.
167 rte_lpm6_delete_all(struct rte_lpm6 *lpm);
170 * Lookup an IP into the LPM table.
175 * IP to be looked up in the LPM table
177 * Next hop of the most specific rule found for IP (valid on lookup hit only)
179 * -EINVAL for incorrect arguments, -ENOENT on lookup miss, 0 on lookup hit
182 rte_lpm6_lookup(const struct rte_lpm6 *lpm, const uint8_t *ip, uint32_t *next_hop);
185 * Lookup multiple IP addresses in an LPM table.
190 * Array of IPs to be looked up in the LPM table
192 * Next hop of the most specific rule found for IP (valid on lookup hit only).
193 * This is an array of two byte values. The next hop will be stored on
194 * each position on success; otherwise the position will be set to -1.
196 * Number of elements in ips (and next_hops) array to lookup.
198 * -EINVAL for incorrect arguments, otherwise 0
201 rte_lpm6_lookup_bulk_func(const struct rte_lpm6 *lpm,
202 uint8_t ips[][RTE_LPM6_IPV6_ADDR_SIZE],
203 int32_t *next_hops, unsigned int n);