1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Vladimir Medvedkin <medvedkinv@gmail.com>
3 * Copyright(c) 2019 Intel Corporation
11 * Level compressed tree implementation for IPv4 Longest Prefix Match
14 #include <rte_compat.h>
17 * rte_rib_get_nxt() flags
20 /** flag to get all subroutes in a RIB tree */
22 /** flag to get first matched subroutes in a RIB tree */
29 /** RIB configuration structure */
32 * Size of extension block inside rte_rib_node.
33 * This space could be used to store additional user
37 /* size of rte_rib_node's pool */
42 * Get an IPv4 mask from prefix length
43 * It is caller responsibility to make sure depth is not bigger than 32
50 static inline uint32_t
51 rte_rib_depth_to_mask(uint8_t depth)
53 return (uint32_t)(UINT64_MAX << (32 - depth));
57 * Lookup an IP into the RIB structure
62 * IP to be looked up in the RIB
64 * pointer to struct rte_rib_node on success
69 rte_rib_lookup(struct rte_rib *rib, uint32_t ip);
72 * Lookup less specific route into the RIB structure
75 * Pointer to struct rte_rib_node that represents target route
77 * pointer to struct rte_rib_node that represents
78 * less specific route on success
83 rte_rib_lookup_parent(struct rte_rib_node *ent);
86 * Lookup prefix into the RIB structure
91 * net to be looked up in the RIB
95 * pointer to struct rte_rib_node on success
100 rte_rib_lookup_exact(struct rte_rib *rib, uint32_t ip, uint8_t depth);
103 * Retrieve next more specific prefix from the RIB
104 * that is covered by ip/depth supernet in an ascending order
109 * net address of supernet prefix that covers returned more specific prefixes
111 * supernet prefix length
113 * pointer to the last returned prefix to get next prefix
115 * NULL to get first more specific prefix
117 * -RTE_RIB_GET_NXT_ALL
118 * get all prefixes from subtrie
119 * -RTE_RIB_GET_NXT_COVER
120 * get only first more specific prefix even if it have more specifics
122 * pointer to the next more specific prefix
123 * NULL if there is no prefixes left
126 struct rte_rib_node *
127 rte_rib_get_nxt(struct rte_rib *rib, uint32_t ip, uint8_t depth,
128 struct rte_rib_node *last, int flag);
131 * Remove prefix from the RIB
136 * net to be removed from the RIB
142 rte_rib_remove(struct rte_rib *rib, uint32_t ip, uint8_t depth);
145 * Insert prefix into the RIB
150 * net to be inserted to the RIB
154 * pointer to new rte_rib_node on success
158 struct rte_rib_node *
159 rte_rib_insert(struct rte_rib *rib, uint32_t ip, uint8_t depth);
162 * Get an ip from rte_rib_node
165 * pointer to the rib node
167 * pointer to the ip to save
170 * -1 on failure with rte_errno indicating reason for failure.
174 rte_rib_get_ip(struct rte_rib_node *node, uint32_t *ip);
177 * Get a depth from rte_rib_node
180 * pointer to the rib node
182 * pointer to the depth to save
185 * -1 on failure with rte_errno indicating reason for failure.
189 rte_rib_get_depth(struct rte_rib_node *node, uint8_t *depth);
192 * Get ext field from the rib node
193 * It is caller responsibility to make sure there are necessary space
194 * for the ext field inside rib node.
197 * pointer to the rib node
203 rte_rib_get_ext(struct rte_rib_node *node);
206 * Get nexthop from the rib node
209 * pointer to the rib node
211 * pointer to the nexthop to save
214 * -1 on failure with rte_errno indicating reason for failure.
218 rte_rib_get_nh(struct rte_rib_node *node, uint64_t *nh);
221 * Set nexthop into the rib node
224 * pointer to the rib node
226 * nexthop value to set to the rib node
229 * -1 on failure with rte_errno indicating reason for failure.
233 rte_rib_set_nh(struct rte_rib_node *node, uint64_t nh);
241 * NUMA socket ID for RIB table memory allocation
243 * Structure containing the configuration
245 * Handle to RIB object on success
246 * NULL otherwise with rte_errno indicating reason for failure.
250 rte_rib_create(const char *name, int socket_id, struct rte_rib_conf *conf);
253 * Find an existing RIB object and return a pointer to it.
256 * Name of the rib object as passed to rte_rib_create()
258 * Pointer to RIB object on success
259 * NULL otherwise with rte_errno indicating reason for failure.
263 rte_rib_find_existing(const char *name);
266 * Free an RIB object.
275 rte_rib_free(struct rte_rib *rib);
277 #endif /* _RTE_RIB_H_ */