1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Vladimir Medvedkin <medvedkinv@gmail.com>
3 * Copyright(c) 2019 Intel Corporation
14 * Level compressed tree implementation for IPv4 Longest Prefix Match
26 * rte_rib_get_nxt() flags
29 /** flag to get all subroutes in a RIB tree */
31 /** flag to get first matched subroutes in a RIB tree */
38 /** RIB configuration structure */
41 * Size of extension block inside rte_rib_node.
42 * This space could be used to store additional user
46 /* size of rte_rib_node's pool */
51 * Get an IPv4 mask from prefix length
52 * It is caller responsibility to make sure depth is not bigger than 32
59 static inline uint32_t
60 rte_rib_depth_to_mask(uint8_t depth)
62 return (uint32_t)(UINT64_MAX << (32 - depth));
66 * Lookup an IP into the RIB structure
71 * IP to be looked up in the RIB
73 * pointer to struct rte_rib_node on success
77 rte_rib_lookup(struct rte_rib *rib, uint32_t ip);
80 * Lookup less specific route into the RIB structure
83 * Pointer to struct rte_rib_node that represents target route
85 * pointer to struct rte_rib_node that represents
86 * 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
105 struct rte_rib_node *
106 rte_rib_lookup_exact(struct rte_rib *rib, uint32_t ip, uint8_t depth);
109 * Retrieve next more specific prefix from the RIB
110 * that is covered by ip/depth supernet in an ascending order
115 * net address of supernet prefix that covers returned more specific prefixes
117 * supernet prefix length
119 * pointer to the last returned prefix to get next prefix
121 * NULL to get first more specific prefix
123 * -RTE_RIB_GET_NXT_ALL
124 * get all prefixes from subtrie
125 * -RTE_RIB_GET_NXT_COVER
126 * get only first more specific prefix even if it have more specifics
128 * pointer to the next more specific prefix
129 * NULL if there is no prefixes left
131 struct rte_rib_node *
132 rte_rib_get_nxt(struct rte_rib *rib, uint32_t ip, uint8_t depth,
133 struct rte_rib_node *last, int flag);
136 * Remove prefix from the RIB
141 * net to be removed from the RIB
146 rte_rib_remove(struct rte_rib *rib, uint32_t ip, uint8_t depth);
149 * Insert prefix into the RIB
154 * net to be inserted to the RIB
158 * pointer to new rte_rib_node on success
161 struct rte_rib_node *
162 rte_rib_insert(struct rte_rib *rib, uint32_t ip, uint8_t depth);
165 * Get an ip from rte_rib_node
168 * pointer to the rib node
170 * pointer to the ip to save
173 * -1 on failure with rte_errno indicating reason for failure.
176 rte_rib_get_ip(const struct rte_rib_node *node, uint32_t *ip);
179 * Get a depth from rte_rib_node
182 * pointer to the rib node
184 * pointer to the depth to save
187 * -1 on failure with rte_errno indicating reason for failure.
190 rte_rib_get_depth(const struct rte_rib_node *node, uint8_t *depth);
193 * Get ext field from the rib node
194 * It is caller responsibility to make sure there are necessary space
195 * for the ext field inside rib node.
198 * 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.
217 rte_rib_get_nh(const struct rte_rib_node *node, uint64_t *nh);
220 * Set nexthop into the rib node
223 * pointer to the rib node
225 * nexthop value to set to the rib node
228 * -1 on failure with rte_errno indicating reason for failure.
231 rte_rib_set_nh(struct rte_rib_node *node, uint64_t nh);
239 * NUMA socket ID for RIB table memory allocation
241 * Structure containing the configuration
243 * Handle to RIB object on success
244 * NULL otherwise with rte_errno indicating reason for failure.
247 rte_rib_create(const char *name, int socket_id,
248 const struct rte_rib_conf *conf);
251 * Find an existing RIB object and return a pointer to it.
254 * Name of the rib object as passed to rte_rib_create()
256 * Pointer to RIB object on success
257 * NULL otherwise with rte_errno indicating reason for failure.
260 rte_rib_find_existing(const char *name);
263 * Free an RIB object.
271 rte_rib_free(struct rte_rib *rib);
277 #endif /* _RTE_RIB_H_ */