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
20 #include <rte_compat.h>
27 * rte_rib_get_nxt() flags
30 /** flag to get all subroutes in a RIB tree */
32 /** flag to get first matched subroutes in a RIB tree */
39 /** RIB configuration structure */
42 * Size of extension block inside rte_rib_node.
43 * This space could be used to store additional user
47 /* size of rte_rib_node's pool */
52 * Get an IPv4 mask from prefix length
53 * It is caller responsibility to make sure depth is not bigger than 32
60 static inline uint32_t
61 rte_rib_depth_to_mask(uint8_t depth)
63 return (uint32_t)(UINT64_MAX << (32 - depth));
67 * Lookup an IP into the RIB structure
72 * IP to be looked up in the RIB
74 * pointer to struct rte_rib_node on success
78 rte_rib_lookup(struct rte_rib *rib, uint32_t ip);
81 * Lookup less specific route into the RIB structure
84 * Pointer to struct rte_rib_node that represents target route
86 * pointer to struct rte_rib_node that represents
87 * less specific route on success
91 rte_rib_lookup_parent(struct rte_rib_node *ent);
94 * Lookup prefix into the RIB structure
99 * net to be looked up in the RIB
103 * 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
132 struct rte_rib_node *
133 rte_rib_get_nxt(struct rte_rib *rib, uint32_t ip, uint8_t depth,
134 struct rte_rib_node *last, int flag);
137 * Remove prefix from the RIB
142 * net to be removed from the RIB
147 rte_rib_remove(struct rte_rib *rib, uint32_t ip, uint8_t depth);
150 * Insert prefix into the RIB
155 * net to be inserted to the RIB
159 * pointer to new rte_rib_node on success
162 struct rte_rib_node *
163 rte_rib_insert(struct rte_rib *rib, uint32_t ip, uint8_t depth);
166 * Get an ip from rte_rib_node
169 * pointer to the rib node
171 * pointer to the ip to save
174 * -1 on failure with rte_errno indicating reason for failure.
177 rte_rib_get_ip(const struct rte_rib_node *node, uint32_t *ip);
180 * Get a depth from rte_rib_node
183 * pointer to the rib node
185 * pointer to the depth to save
188 * -1 on failure with rte_errno indicating reason for failure.
191 rte_rib_get_depth(const struct rte_rib_node *node, uint8_t *depth);
194 * Get ext field from the rib node
195 * It is caller responsibility to make sure there are necessary space
196 * for the ext field inside rib node.
199 * pointer to the rib node
204 rte_rib_get_ext(struct rte_rib_node *node);
207 * Get nexthop from the rib node
210 * pointer to the rib node
212 * pointer to the nexthop to save
215 * -1 on failure with rte_errno indicating reason for failure.
218 rte_rib_get_nh(const 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.
232 rte_rib_set_nh(struct rte_rib_node *node, uint64_t nh);
240 * NUMA socket ID for RIB table memory allocation
242 * Structure containing the configuration
244 * Handle to RIB object on success
245 * NULL otherwise with rte_errno indicating reason for failure.
248 rte_rib_create(const char *name, int socket_id,
249 const struct rte_rib_conf *conf);
252 * Find an existing RIB object and return a pointer to it.
255 * Name of the rib object as passed to rte_rib_create()
257 * Pointer to RIB object on success
258 * NULL otherwise with rte_errno indicating reason for failure.
261 rte_rib_find_existing(const char *name);
264 * Free an RIB object.
272 rte_rib_free(struct rte_rib *rib);
278 #endif /* _RTE_RIB_H_ */