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