mempool: use generic memory syscall wrappers
[dpdk.git] / lib / librte_fib / rte_fib.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Vladimir Medvedkin <medvedkinv@gmail.com>
3  * Copyright(c) 2019 Intel Corporation
4  */
5
6 #ifndef _RTE_FIB_H_
7 #define _RTE_FIB_H_
8
9 /**
10  * @file
11  * FIB (Forwarding information base) implementation
12  * for IPv4 Longest Prefix Match
13  */
14
15 #include <rte_compat.h>
16
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20
21 struct rte_fib;
22 struct rte_rib;
23
24 /** Maximum depth value possible for IPv4 FIB. */
25 #define RTE_FIB_MAXDEPTH        32
26
27 /** Type of FIB struct */
28 enum rte_fib_type {
29         RTE_FIB_DUMMY,          /**< RIB tree based FIB */
30         RTE_FIB_DIR24_8,        /**< DIR24_8 based FIB */
31         RTE_FIB_TYPE_MAX
32 };
33
34 /** Modify FIB function */
35 typedef int (*rte_fib_modify_fn_t)(struct rte_fib *fib, uint32_t ip,
36         uint8_t depth, uint64_t next_hop, int op);
37 /** FIB bulk lookup function */
38 typedef void (*rte_fib_lookup_fn_t)(void *fib, const uint32_t *ips,
39         uint64_t *next_hops, const unsigned int n);
40
41 enum rte_fib_op {
42         RTE_FIB_ADD,
43         RTE_FIB_DEL,
44 };
45
46 /** Size of nexthop (1 << nh_sz) bits for DIR24_8 based FIB */
47 enum rte_fib_dir24_8_nh_sz {
48         RTE_FIB_DIR24_8_1B,
49         RTE_FIB_DIR24_8_2B,
50         RTE_FIB_DIR24_8_4B,
51         RTE_FIB_DIR24_8_8B
52 };
53
54 /** FIB configuration structure */
55 struct rte_fib_conf {
56         enum rte_fib_type type; /**< Type of FIB struct */
57         /** Default value returned on lookup if there is no route */
58         uint64_t default_nh;
59         int     max_routes;
60         union {
61                 struct {
62                         enum rte_fib_dir24_8_nh_sz nh_sz;
63                         uint32_t        num_tbl8;
64                 } dir24_8;
65         };
66 };
67
68 /**
69  * Create FIB
70  *
71  * @param name
72  *  FIB name
73  * @param socket_id
74  *  NUMA socket ID for FIB table memory allocation
75  * @param conf
76  *  Structure containing the configuration
77  * @return
78  *  Handle to the FIB object on success
79  *  NULL otherwise with rte_errno set to an appropriate values.
80  */
81 __rte_experimental
82 struct rte_fib *
83 rte_fib_create(const char *name, int socket_id, struct rte_fib_conf *conf);
84
85 /**
86  * Find an existing FIB object and return a pointer to it.
87  *
88  * @param name
89  *  Name of the fib object as passed to rte_fib_create()
90  * @return
91  *  Pointer to fib object or NULL if object not found with rte_errno
92  *  set appropriately. Possible rte_errno values include:
93  *   - ENOENT - required entry not available to return.
94  */
95 __rte_experimental
96 struct rte_fib *
97 rte_fib_find_existing(const char *name);
98
99 /**
100  * Free an FIB object.
101  *
102  * @param fib
103  *   FIB object handle
104  * @return
105  *   None
106  */
107 __rte_experimental
108 void
109 rte_fib_free(struct rte_fib *fib);
110
111 /**
112  * Add a route to the FIB.
113  *
114  * @param fib
115  *   FIB object handle
116  * @param ip
117  *   IPv4 prefix address to be added to the FIB
118  * @param depth
119  *   Prefix length
120  * @param next_hop
121  *   Next hop to be added to the FIB
122  * @return
123  *   0 on success, negative value otherwise
124  */
125 __rte_experimental
126 int
127 rte_fib_add(struct rte_fib *fib, uint32_t ip, uint8_t depth, uint64_t next_hop);
128
129 /**
130  * Delete a rule from the FIB.
131  *
132  * @param fib
133  *   FIB object handle
134  * @param ip
135  *   IPv4 prefix address to be deleted from the FIB
136  * @param depth
137  *   Prefix length
138  * @return
139  *   0 on success, negative value otherwise
140  */
141 __rte_experimental
142 int
143 rte_fib_delete(struct rte_fib *fib, uint32_t ip, uint8_t depth);
144
145 /**
146  * Lookup multiple IP addresses in the FIB.
147  *
148  * @param fib
149  *   FIB object handle
150  * @param ips
151  *   Array of IPs to be looked up in the FIB
152  * @param next_hops
153  *   Next hop of the most specific rule found for IP.
154  *   This is an array of eight byte values.
155  *   If the lookup for the given IP failed, then corresponding element would
156  *   contain default nexthop value configured for a FIB.
157  * @param n
158  *   Number of elements in ips (and next_hops) array to lookup.
159  *  @return
160  *   -EINVAL for incorrect arguments, otherwise 0
161  */
162 __rte_experimental
163 int
164 rte_fib_lookup_bulk(struct rte_fib *fib, uint32_t *ips,
165                 uint64_t *next_hops, int n);
166 /**
167  * Get pointer to the dataplane specific struct
168  *
169  * @param fib
170  *   FIB object handle
171  * @return
172  *   Pointer on the dataplane struct on success
173  *   NULL othervise
174  */
175 __rte_experimental
176 void *
177 rte_fib_get_dp(struct rte_fib *fib);
178
179 /**
180  * Get pointer to the RIB
181  *
182  * @param fib
183  *   FIB object handle
184  * @return
185  *   Pointer on the RIB on success
186  *   NULL othervise
187  */
188 __rte_experimental
189 struct rte_rib *
190 rte_fib_get_rib(struct rte_fib *fib);
191
192 #ifdef __cplusplus
193 }
194 #endif
195
196 #endif /* _RTE_FIB_H_ */