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
24 #include <rte_compat.h>
31 * rte_rib_get_nxt() flags
34 /** flag to get all subroutes in a RIB tree */
36 /** flag to get first matched subroutes in a RIB tree */
43 /** RIB configuration structure */
46 * Size of extension block inside rte_rib_node.
47 * This space could be used to store additional user
51 /* size of rte_rib_node's pool */
56 * Get an IPv4 mask from prefix length
57 * It is caller responsibility to make sure depth is not bigger than 32
64 static inline uint32_t
65 rte_rib_depth_to_mask(uint8_t depth)
67 return (uint32_t)(UINT64_MAX << (32 - depth));
71 * Lookup an IP into the RIB structure
76 * IP to be looked up in the RIB
78 * pointer to struct rte_rib_node on success
83 rte_rib_lookup(struct rte_rib *rib, uint32_t ip);
86 * Lookup less specific route into the RIB structure
89 * Pointer to struct rte_rib_node that represents target route
91 * pointer to struct rte_rib_node that represents
92 * less specific route on success
97 rte_rib_lookup_parent(struct rte_rib_node *ent);
100 * Lookup prefix into the RIB structure
105 * net to be looked up in the RIB
109 * pointer to struct rte_rib_node on success
113 struct rte_rib_node *
114 rte_rib_lookup_exact(struct rte_rib *rib, uint32_t ip, uint8_t depth);
117 * Retrieve next more specific prefix from the RIB
118 * that is covered by ip/depth supernet in an ascending order
123 * net address of supernet prefix that covers returned more specific prefixes
125 * supernet prefix length
127 * pointer to the last returned prefix to get next prefix
129 * NULL to get first more specific prefix
131 * -RTE_RIB_GET_NXT_ALL
132 * get all prefixes from subtrie
133 * -RTE_RIB_GET_NXT_COVER
134 * get only first more specific prefix even if it have more specifics
136 * pointer to the next more specific prefix
137 * NULL if there is no prefixes left
140 struct rte_rib_node *
141 rte_rib_get_nxt(struct rte_rib *rib, uint32_t ip, uint8_t depth,
142 struct rte_rib_node *last, int flag);
145 * Remove prefix from the RIB
150 * net to be removed from the RIB
156 rte_rib_remove(struct rte_rib *rib, uint32_t ip, uint8_t depth);
159 * Insert prefix into the RIB
164 * net to be inserted to the RIB
168 * pointer to new rte_rib_node on success
172 struct rte_rib_node *
173 rte_rib_insert(struct rte_rib *rib, uint32_t ip, uint8_t depth);
176 * Get an ip from rte_rib_node
179 * pointer to the rib node
181 * pointer to the ip to save
184 * -1 on failure with rte_errno indicating reason for failure.
188 rte_rib_get_ip(const struct rte_rib_node *node, uint32_t *ip);
191 * Get a depth from rte_rib_node
194 * pointer to the rib node
196 * pointer to the depth to save
199 * -1 on failure with rte_errno indicating reason for failure.
203 rte_rib_get_depth(const struct rte_rib_node *node, uint8_t *depth);
206 * Get ext field from the rib node
207 * It is caller responsibility to make sure there are necessary space
208 * for the ext field inside rib node.
211 * pointer to the rib node
217 rte_rib_get_ext(struct rte_rib_node *node);
220 * Get nexthop from the rib node
223 * pointer to the rib node
225 * pointer to the nexthop to save
228 * -1 on failure with rte_errno indicating reason for failure.
232 rte_rib_get_nh(const struct rte_rib_node *node, uint64_t *nh);
235 * Set nexthop into the rib node
238 * pointer to the rib node
240 * nexthop value to set to the rib node
243 * -1 on failure with rte_errno indicating reason for failure.
247 rte_rib_set_nh(struct rte_rib_node *node, uint64_t nh);
255 * NUMA socket ID for RIB table memory allocation
257 * Structure containing the configuration
259 * Handle to RIB object on success
260 * NULL otherwise with rte_errno indicating reason for failure.
264 rte_rib_create(const char *name, int socket_id,
265 const struct rte_rib_conf *conf);
268 * Find an existing RIB object and return a pointer to it.
271 * Name of the rib object as passed to rte_rib_create()
273 * Pointer to RIB object on success
274 * NULL otherwise with rte_errno indicating reason for failure.
278 rte_rib_find_existing(const char *name);
281 * Free an RIB object.
290 rte_rib_free(struct rte_rib *rib);
296 #endif /* _RTE_RIB_H_ */