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