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