1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Vladimir Medvedkin <medvedkinv@gmail.com>
3 * Copyright(c) 2019 Intel Corporation
16 * All functions in this file may be changed or removed without prior notice.
18 * Level compressed tree implementation for IPv4 Longest Prefix Match
21 #include <rte_compat.h>
28 * rte_rib_get_nxt() flags
31 /** flag to get all subroutes in a RIB tree */
33 /** flag to get first matched subroutes in a RIB tree */
40 /** RIB configuration structure */
43 * Size of extension block inside rte_rib_node.
44 * This space could be used to store additional user
48 /* size of rte_rib_node's pool */
53 * Get an IPv4 mask from prefix length
54 * It is caller responsibility to make sure depth is not bigger than 32
61 static inline uint32_t
62 rte_rib_depth_to_mask(uint8_t depth)
64 return (uint32_t)(UINT64_MAX << (32 - depth));
68 * Lookup an IP into the RIB structure
73 * IP to be looked up in the RIB
75 * pointer to struct rte_rib_node on success
80 rte_rib_lookup(struct rte_rib *rib, uint32_t ip);
83 * Lookup less specific route into the RIB structure
86 * Pointer to struct rte_rib_node that represents target route
88 * pointer to struct rte_rib_node that represents
89 * less specific route on success
94 rte_rib_lookup_parent(struct rte_rib_node *ent);
97 * Lookup prefix into the RIB structure
102 * net to be looked up in the RIB
106 * pointer to struct rte_rib_node on success
110 struct rte_rib_node *
111 rte_rib_lookup_exact(struct rte_rib *rib, uint32_t ip, uint8_t depth);
114 * Retrieve next more specific prefix from the RIB
115 * that is covered by ip/depth supernet in an ascending order
120 * net address of supernet prefix that covers returned more specific prefixes
122 * supernet prefix length
124 * pointer to the last returned prefix to get next prefix
126 * NULL to get first more specific prefix
128 * -RTE_RIB_GET_NXT_ALL
129 * get all prefixes from subtrie
130 * -RTE_RIB_GET_NXT_COVER
131 * get only first more specific prefix even if it have more specifics
133 * pointer to the next more specific prefix
134 * NULL if there is no prefixes left
137 struct rte_rib_node *
138 rte_rib_get_nxt(struct rte_rib *rib, uint32_t ip, uint8_t depth,
139 struct rte_rib_node *last, int flag);
142 * Remove prefix from the RIB
147 * net to be removed from the RIB
153 rte_rib_remove(struct rte_rib *rib, uint32_t ip, uint8_t depth);
156 * Insert prefix into the RIB
161 * net to be inserted to the RIB
165 * pointer to new rte_rib_node on success
169 struct rte_rib_node *
170 rte_rib_insert(struct rte_rib *rib, uint32_t ip, uint8_t depth);
173 * Get an ip from rte_rib_node
176 * pointer to the rib node
178 * pointer to the ip to save
181 * -1 on failure with rte_errno indicating reason for failure.
185 rte_rib_get_ip(const struct rte_rib_node *node, uint32_t *ip);
188 * Get a depth from rte_rib_node
191 * pointer to the rib node
193 * pointer to the depth to save
196 * -1 on failure with rte_errno indicating reason for failure.
200 rte_rib_get_depth(const struct rte_rib_node *node, uint8_t *depth);
203 * Get ext field from the rib node
204 * It is caller responsibility to make sure there are necessary space
205 * for the ext field inside rib node.
208 * pointer to the rib node
214 rte_rib_get_ext(struct rte_rib_node *node);
217 * Get nexthop from the rib node
220 * pointer to the rib node
222 * pointer to the nexthop to save
225 * -1 on failure with rte_errno indicating reason for failure.
229 rte_rib_get_nh(const struct rte_rib_node *node, uint64_t *nh);
232 * Set nexthop into the rib node
235 * pointer to the rib node
237 * nexthop value to set to the rib node
240 * -1 on failure with rte_errno indicating reason for failure.
244 rte_rib_set_nh(struct rte_rib_node *node, uint64_t nh);
252 * NUMA socket ID for RIB table memory allocation
254 * Structure containing the configuration
256 * Handle to RIB object on success
257 * NULL otherwise with rte_errno indicating reason for failure.
261 rte_rib_create(const char *name, int socket_id,
262 const struct rte_rib_conf *conf);
265 * Find an existing RIB object and return a pointer to it.
268 * Name of the rib object as passed to rte_rib_create()
270 * Pointer to RIB object on success
271 * NULL otherwise with rte_errno indicating reason for failure.
275 rte_rib_find_existing(const char *name);
278 * Free an RIB object.
287 rte_rib_free(struct rte_rib *rib);
293 #endif /* _RTE_RIB_H_ */