net/i40e: fix bitmap free
[dpdk.git] / lib / librte_fib / rte_fib6.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_FIB6_H_
7 #define _RTE_FIB6_H_
8
9 /**
10  * @file
11  *
12  * RTE FIB6 library.
13  *
14  * @warning
15  * @b EXPERIMENTAL:
16  * All functions in this file may be changed or removed without prior notice.
17  *
18  * FIB (Forwarding information base) implementation
19  * for IPv6 Longest Prefix Match
20  */
21
22 #include <rte_compat.h>
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 #define RTE_FIB6_IPV6_ADDR_SIZE         16
29 /** Maximum depth value possible for IPv6 FIB. */
30 #define RTE_FIB6_MAXDEPTH       128
31
32 struct rte_fib6;
33 struct rte_rib6;
34
35 /** Type of FIB struct */
36 enum rte_fib6_type {
37         RTE_FIB6_DUMMY,         /**< RIB6 tree based FIB */
38         RTE_FIB6_TRIE,          /**< TRIE based fib  */
39         RTE_FIB6_TYPE_MAX
40 };
41
42 /** Modify FIB function */
43 typedef int (*rte_fib6_modify_fn_t)(struct rte_fib6 *fib,
44         const uint8_t ip[RTE_FIB6_IPV6_ADDR_SIZE], uint8_t depth,
45         uint64_t next_hop, int op);
46 /** FIB bulk lookup function */
47 typedef void (*rte_fib6_lookup_fn_t)(void *fib,
48         uint8_t ips[][RTE_FIB6_IPV6_ADDR_SIZE],
49         uint64_t *next_hops, const unsigned int n);
50
51 enum rte_fib6_op {
52         RTE_FIB6_ADD,
53         RTE_FIB6_DEL,
54 };
55
56 enum rte_fib_trie_nh_sz {
57         RTE_FIB6_TRIE_2B = 1,
58         RTE_FIB6_TRIE_4B,
59         RTE_FIB6_TRIE_8B
60 };
61
62 /** FIB configuration structure */
63 struct rte_fib6_conf {
64         enum rte_fib6_type type; /**< Type of FIB struct */
65         /** Default value returned on lookup if there is no route */
66         uint64_t default_nh;
67         int     max_routes;
68         union {
69                 struct {
70                         enum rte_fib_trie_nh_sz nh_sz;
71                         uint32_t        num_tbl8;
72                 } trie;
73         };
74 };
75
76 /**
77  * Create FIB
78  *
79  * @param name
80  *  FIB name
81  * @param socket_id
82  *  NUMA socket ID for FIB table memory allocation
83  * @param conf
84  *  Structure containing the configuration
85  * @return
86  *  Handle to FIB object on success
87  *  NULL otherwise with rte_errno set to an appropriate values.
88  */
89 __rte_experimental
90 struct rte_fib6 *
91 rte_fib6_create(const char *name, int socket_id, struct rte_fib6_conf *conf);
92
93 /**
94  * Find an existing FIB object and return a pointer to it.
95  *
96  * @param name
97  *  Name of the fib object as passed to rte_fib6_create()
98  * @return
99  *  Pointer to fib object or NULL if object not found with rte_errno
100  *  set appropriately. Possible rte_errno values include:
101  *   - ENOENT - required entry not available to return.
102  */
103 __rte_experimental
104 struct rte_fib6 *
105 rte_fib6_find_existing(const char *name);
106
107 /**
108  * Free an FIB object.
109  *
110  * @param fib
111  *   FIB object handle
112  * @return
113  *   None
114  */
115 __rte_experimental
116 void
117 rte_fib6_free(struct rte_fib6 *fib);
118
119 /**
120  * Add a route to the FIB.
121  *
122  * @param fib
123  *   FIB object handle
124  * @param ip
125  *   IPv6 prefix address to be added to the FIB
126  * @param depth
127  *   Prefix length
128  * @param next_hop
129  *   Next hop to be added to the FIB
130  * @return
131  *   0 on success, negative value otherwise
132  */
133 __rte_experimental
134 int
135 rte_fib6_add(struct rte_fib6 *fib, const uint8_t ip[RTE_FIB6_IPV6_ADDR_SIZE],
136         uint8_t depth, uint64_t next_hop);
137
138 /**
139  * Delete a rule from the FIB.
140  *
141  * @param fib
142  *   FIB object handle
143  * @param ip
144  *   IPv6 prefix address to be deleted from the FIB
145  * @param depth
146  *   Prefix length
147  * @return
148  *   0 on success, negative value otherwise
149  */
150 __rte_experimental
151 int
152 rte_fib6_delete(struct rte_fib6 *fib,
153         const uint8_t ip[RTE_FIB6_IPV6_ADDR_SIZE], uint8_t depth);
154
155 /**
156  * Lookup multiple IP addresses in the FIB.
157  *
158  * @param fib
159  *   FIB object handle
160  * @param ips
161  *   Array of IPv6s to be looked up in the FIB
162  * @param next_hops
163  *   Next hop of the most specific rule found for IP.
164  *   This is an array of eight byte values.
165  *   If the lookup for the given IP failed, then corresponding element would
166  *   contain default nexthop value configured for a FIB.
167  * @param n
168  *   Number of elements in ips (and next_hops) array to lookup.
169  *  @return
170  *   -EINVAL for incorrect arguments, otherwise 0
171  */
172 __rte_experimental
173 int
174 rte_fib6_lookup_bulk(struct rte_fib6 *fib,
175         uint8_t ips[][RTE_FIB6_IPV6_ADDR_SIZE],
176         uint64_t *next_hops, int n);
177
178 /**
179  * Get pointer to the dataplane specific struct
180  *
181  * @param fib
182  *   FIB6 object handle
183  * @return
184  *   Pointer on the dataplane struct on success
185  *   NULL othervise
186  */
187 __rte_experimental
188 void *
189 rte_fib6_get_dp(struct rte_fib6 *fib);
190
191 /**
192  * Get pointer to the RIB6
193  *
194  * @param fib
195  *   FIB object handle
196  * @return
197  *   Pointer on the RIB6 on success
198  *   NULL othervise
199  */
200 __rte_experimental
201 struct rte_rib6 *
202 rte_fib6_get_rib(struct rte_fib6 *fib);
203
204 #ifdef __cplusplus
205 }
206 #endif
207
208 #endif /* _RTE_FIB6_H_ */