New upstream version 18.02
[deb_dpdk.git] / lib / librte_lpm / rte_lpm6.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation
3  */
4 #ifndef _RTE_LPM6_H_
5 #define _RTE_LPM6_H_
6
7 /**
8  * @file
9  * RTE Longest Prefix Match for IPv6 (LPM6)
10  */
11
12 #include <stdint.h>
13 #include <rte_compat.h>
14
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18
19
20 #define RTE_LPM6_MAX_DEPTH               128
21 #define RTE_LPM6_IPV6_ADDR_SIZE           16
22 /** Max number of characters in LPM name. */
23 #define RTE_LPM6_NAMESIZE                 32
24
25 /** LPM structure. */
26 struct rte_lpm6;
27
28 /** LPM configuration structure. */
29 struct rte_lpm6_config {
30         uint32_t max_rules;      /**< Max number of rules. */
31         uint32_t number_tbl8s;   /**< Number of tbl8s to allocate. */
32         int flags;               /**< This field is currently unused. */
33 };
34
35 /**
36  * Create an LPM object.
37  *
38  * @param name
39  *   LPM object name
40  * @param socket_id
41  *   NUMA socket ID for LPM table memory allocation
42  * @param config
43  *   Structure containing the configuration
44  * @return
45  *   Handle to LPM object on success, NULL otherwise with rte_errno set
46  *   to an appropriate values. Possible rte_errno values include:
47  *    - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
48  *    - E_RTE_SECONDARY - function was called from a secondary process instance
49  *    - EINVAL - invalid parameter passed to function
50  *    - ENOSPC - the maximum number of memzones has already been allocated
51  *    - EEXIST - a memzone with the same name already exists
52  *    - ENOMEM - no appropriate memory area found in which to create memzone
53  */
54 struct rte_lpm6 *
55 rte_lpm6_create(const char *name, int socket_id,
56                 const struct rte_lpm6_config *config);
57
58 /**
59  * Find an existing LPM object and return a pointer to it.
60  *
61  * @param name
62  *   Name of the lpm object as passed to rte_lpm6_create()
63  * @return
64  *   Pointer to lpm object or NULL if object not found with rte_errno
65  *   set appropriately. Possible rte_errno values include:
66  *    - ENOENT - required entry not available to return.
67  */
68 struct rte_lpm6 *
69 rte_lpm6_find_existing(const char *name);
70
71 /**
72  * Free an LPM object.
73  *
74  * @param lpm
75  *   LPM object handle
76  * @return
77  *   None
78  */
79 void
80 rte_lpm6_free(struct rte_lpm6 *lpm);
81
82 /**
83  * Add a rule to the LPM table.
84  *
85  * @param lpm
86  *   LPM object handle
87  * @param ip
88  *   IP of the rule to be added to the LPM table
89  * @param depth
90  *   Depth of the rule to be added to the LPM table
91  * @param next_hop
92  *   Next hop of the rule to be added to the LPM table
93  * @return
94  *   0 on success, negative value otherwise
95  */
96 int
97 rte_lpm6_add(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth,
98                 uint32_t next_hop);
99 int
100 rte_lpm6_add_v20(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth,
101                 uint8_t next_hop);
102 int
103 rte_lpm6_add_v1705(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth,
104                 uint32_t next_hop);
105
106 /**
107  * Check if a rule is present in the LPM table,
108  * and provide its next hop if it is.
109  *
110  * @param lpm
111  *   LPM object handle
112  * @param ip
113  *   IP of the rule to be searched
114  * @param depth
115  *   Depth of the rule to searched
116  * @param next_hop
117  *   Next hop of the rule (valid only if it is found)
118  * @return
119  *   1 if the rule exists, 0 if it does not, a negative value on failure
120  */
121 int
122 rte_lpm6_is_rule_present(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth,
123                 uint32_t *next_hop);
124 int
125 rte_lpm6_is_rule_present_v20(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth,
126                 uint8_t *next_hop);
127 int
128 rte_lpm6_is_rule_present_v1705(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth,
129                 uint32_t *next_hop);
130
131 /**
132  * Delete a rule from the LPM table.
133  *
134  * @param lpm
135  *   LPM object handle
136  * @param ip
137  *   IP of the rule to be deleted from the LPM table
138  * @param depth
139  *   Depth of the rule to be deleted from the LPM table
140  * @return
141  *   0 on success, negative value otherwise
142  */
143 int
144 rte_lpm6_delete(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth);
145
146 /**
147  * Delete a rule from the LPM table.
148  *
149  * @param lpm
150  *   LPM object handle
151  * @param ips
152  *   Array of IPs to be deleted from the LPM table
153  * @param depths
154  *   Array of depths of the rules to be deleted from the LPM table
155  * @param n
156  *   Number of rules to be deleted from the LPM table
157  * @return
158  *   0 on success, negative value otherwise.
159  */
160 int
161 rte_lpm6_delete_bulk_func(struct rte_lpm6 *lpm,
162                 uint8_t ips[][RTE_LPM6_IPV6_ADDR_SIZE], uint8_t *depths, unsigned n);
163
164 /**
165  * Delete all rules from the LPM table.
166  *
167  * @param lpm
168  *   LPM object handle
169  */
170 void
171 rte_lpm6_delete_all(struct rte_lpm6 *lpm);
172
173 /**
174  * Lookup an IP into the LPM table.
175  *
176  * @param lpm
177  *   LPM object handle
178  * @param ip
179  *   IP to be looked up in the LPM table
180  * @param next_hop
181  *   Next hop of the most specific rule found for IP (valid on lookup hit only)
182  * @return
183  *   -EINVAL for incorrect arguments, -ENOENT on lookup miss, 0 on lookup hit
184  */
185 int
186 rte_lpm6_lookup(const struct rte_lpm6 *lpm, uint8_t *ip, uint32_t *next_hop);
187 int
188 rte_lpm6_lookup_v20(const struct rte_lpm6 *lpm, uint8_t *ip, uint8_t *next_hop);
189 int
190 rte_lpm6_lookup_v1705(const struct rte_lpm6 *lpm, uint8_t *ip,
191                 uint32_t *next_hop);
192
193 /**
194  * Lookup multiple IP addresses in an LPM table.
195  *
196  * @param lpm
197  *   LPM object handle
198  * @param ips
199  *   Array of IPs to be looked up in the LPM table
200  * @param next_hops
201  *   Next hop of the most specific rule found for IP (valid on lookup hit only).
202  *   This is an array of two byte values. The next hop will be stored on
203  *   each position on success; otherwise the position will be set to -1.
204  * @param n
205  *   Number of elements in ips (and next_hops) array to lookup.
206  *  @return
207  *   -EINVAL for incorrect arguments, otherwise 0
208  */
209 int
210 rte_lpm6_lookup_bulk_func(const struct rte_lpm6 *lpm,
211                 uint8_t ips[][RTE_LPM6_IPV6_ADDR_SIZE],
212                 int32_t *next_hops, unsigned int n);
213 int
214 rte_lpm6_lookup_bulk_func_v20(const struct rte_lpm6 *lpm,
215                 uint8_t ips[][RTE_LPM6_IPV6_ADDR_SIZE],
216                 int16_t *next_hops, unsigned int n);
217 int
218 rte_lpm6_lookup_bulk_func_v1705(const struct rte_lpm6 *lpm,
219                 uint8_t ips[][RTE_LPM6_IPV6_ADDR_SIZE],
220                 int32_t *next_hops, unsigned int n);
221
222 #ifdef __cplusplus
223 }
224 #endif
225
226 #endif