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