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>
24 * rte_rib_get_nxt() flags
27 /** flag to get all subroutes in a RIB tree */
29 /** flag to get first matched subroutes in a RIB tree */
36 /** RIB configuration structure */
39 * Size of extension block inside rte_rib_node.
40 * This space could be used to store additional user
44 /* size of rte_rib_node's pool */
49 * Get an IPv4 mask from prefix length
50 * It is caller responsibility to make sure depth is not bigger than 32
57 static inline uint32_t
58 rte_rib_depth_to_mask(uint8_t depth)
60 return (uint32_t)(UINT64_MAX << (32 - depth));
64 * Lookup an IP into the RIB structure
69 * IP to be looked up in the RIB
71 * pointer to struct rte_rib_node on success
76 rte_rib_lookup(struct rte_rib *rib, uint32_t ip);
79 * Lookup less specific route into the RIB structure
82 * Pointer to struct rte_rib_node that represents target route
84 * pointer to struct rte_rib_node that represents
85 * less specific route on success
90 rte_rib_lookup_parent(struct rte_rib_node *ent);
93 * Lookup prefix into the RIB structure
98 * net to be looked up in the RIB
102 * pointer to struct rte_rib_node on success
106 struct rte_rib_node *
107 rte_rib_lookup_exact(struct rte_rib *rib, uint32_t ip, uint8_t depth);
110 * Retrieve next more specific prefix from the RIB
111 * that is covered by ip/depth supernet in an ascending order
116 * net address of supernet prefix that covers returned more specific prefixes
118 * supernet prefix length
120 * pointer to the last returned prefix to get next prefix
122 * NULL to get first more specific prefix
124 * -RTE_RIB_GET_NXT_ALL
125 * get all prefixes from subtrie
126 * -RTE_RIB_GET_NXT_COVER
127 * get only first more specific prefix even if it have more specifics
129 * pointer to the next more specific prefix
130 * NULL if there is no prefixes left
133 struct rte_rib_node *
134 rte_rib_get_nxt(struct rte_rib *rib, uint32_t ip, uint8_t depth,
135 struct rte_rib_node *last, int flag);
138 * Remove prefix from the RIB
143 * net to be removed from the RIB
149 rte_rib_remove(struct rte_rib *rib, uint32_t ip, uint8_t depth);
152 * Insert prefix into the RIB
157 * net to be inserted to the RIB
161 * pointer to new rte_rib_node on success
165 struct rte_rib_node *
166 rte_rib_insert(struct rte_rib *rib, uint32_t ip, uint8_t depth);
169 * Get an ip from rte_rib_node
172 * pointer to the rib node
174 * pointer to the ip to save
177 * -1 on failure with rte_errno indicating reason for failure.
181 rte_rib_get_ip(struct rte_rib_node *node, uint32_t *ip);
184 * Get a depth from rte_rib_node
187 * pointer to the rib node
189 * pointer to the depth to save
192 * -1 on failure with rte_errno indicating reason for failure.
196 rte_rib_get_depth(struct rte_rib_node *node, uint8_t *depth);
199 * Get ext field from the rib node
200 * It is caller responsibility to make sure there are necessary space
201 * for the ext field inside rib node.
204 * pointer to the rib node
210 rte_rib_get_ext(struct rte_rib_node *node);
213 * Get nexthop from the rib node
216 * pointer to the rib node
218 * pointer to the nexthop to save
221 * -1 on failure with rte_errno indicating reason for failure.
225 rte_rib_get_nh(struct rte_rib_node *node, uint64_t *nh);
228 * Set nexthop into the rib node
231 * pointer to the rib node
233 * nexthop value to set to the rib node
236 * -1 on failure with rte_errno indicating reason for failure.
240 rte_rib_set_nh(struct rte_rib_node *node, uint64_t nh);
248 * NUMA socket ID for RIB table memory allocation
250 * Structure containing the configuration
252 * Handle to RIB object on success
253 * NULL otherwise with rte_errno indicating reason for failure.
257 rte_rib_create(const char *name, int socket_id, struct rte_rib_conf *conf);
260 * Find an existing RIB object and return a pointer to it.
263 * Name of the rib object as passed to rte_rib_create()
265 * Pointer to RIB object on success
266 * NULL otherwise with rte_errno indicating reason for failure.
270 rte_rib_find_existing(const char *name);
273 * Free an RIB object.
282 rte_rib_free(struct rte_rib *rib);
284 #endif /* _RTE_RIB_H_ */