update Intel copyright years to 2014
[dpdk.git] / lib / librte_lpm / rte_lpm6.h
1 /*-
2  *   BSD LICENSE
3  * 
4  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  * 
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  * 
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  * 
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 #ifndef _RTE_LPM6_H_
34 #define _RTE_LPM6_H_
35
36 /**
37  * @file
38  * RTE Longest Prefix Match for IPv6 (LPM6)
39  */
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44
45
46 #define RTE_LPM6_MAX_DEPTH               128
47 #define RTE_LPM6_IPV6_ADDR_SIZE           16
48 /** Max number of characters in LPM name. */
49 #define RTE_LPM6_NAMESIZE                 32
50
51 /** LPM structure. */
52 struct rte_lpm6;
53
54 /** LPM configuration structure. */
55 struct rte_lpm6_config {
56         uint32_t max_rules;      /**< Max number of rules. */
57         uint32_t number_tbl8s;   /**< Number of tbl8s to allocate. */
58         int flags;               /**< This field is currently unused. */
59 };
60
61 /**
62  * Create an LPM object.
63  *
64  * @param name
65  *   LPM object name
66  * @param socket_id
67  *   NUMA socket ID for LPM table memory allocation
68  * @param config
69  *   Structure containing the configuration
70  * @return
71  *   Handle to LPM object on success, NULL otherwise with rte_errno set
72  *   to an appropriate values. Possible rte_errno values include:
73  *    - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
74  *    - E_RTE_SECONDARY - function was called from a secondary process instance
75  *    - E_RTE_NO_TAILQ - no tailq list could be got for the lpm object list
76  *    - EINVAL - invalid parameter passed to function
77  *    - ENOSPC - the maximum number of memzones has already been allocated
78  *    - EEXIST - a memzone with the same name already exists
79  *    - ENOMEM - no appropriate memory area found in which to create memzone
80  */
81 struct rte_lpm6 *
82 rte_lpm6_create(const char *name, int socket_id,
83                 const struct rte_lpm6_config *config);
84
85 /**
86  * Find an existing LPM object and return a pointer to it.
87  *
88  * @param name
89  *   Name of the lpm object as passed to rte_lpm6_create()
90  * @return
91  *   Pointer to lpm object or NULL if object not found with rte_errno
92  *   set appropriately. Possible rte_errno values include:
93  *    - ENOENT - required entry not available to return.
94  */
95 struct rte_lpm6 *
96 rte_lpm6_find_existing(const char *name);
97
98 /**
99  * Free an LPM object.
100  *
101  * @param lpm
102  *   LPM object handle
103  * @return
104  *   None
105  */
106 void
107 rte_lpm6_free(struct rte_lpm6 *lpm);
108
109 /**
110  * Add a rule to the LPM table.
111  *
112  * @param lpm
113  *   LPM object handle
114  * @param ip
115  *   IP of the rule to be added to the LPM table
116  * @param depth
117  *   Depth of the rule to be added to the LPM table
118  * @param next_hop
119  *   Next hop of the rule to be added to the LPM table
120  * @return
121  *   0 on success, negative value otherwise
122  */
123 int
124 rte_lpm6_add(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth,
125                 uint8_t next_hop);
126
127 /**
128  * Delete a rule from the LPM table.
129  *
130  * @param lpm
131  *   LPM object handle
132  * @param ip
133  *   IP of the rule to be deleted from the LPM table
134  * @param depth
135  *   Depth of the rule to be deleted from the LPM table
136  * @return
137  *   0 on success, negative value otherwise
138  */
139 int
140 rte_lpm6_delete(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth);
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, uint8_t *ip, uint8_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                 int16_t * next_hops, unsigned n);
204
205 #ifdef __cplusplus
206 }
207 #endif
208
209 #endif