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