source: SVN/cambria/redboot/packages/devs/eth/intel/npe/ethDB/current/src/IxEthDBSearch.c @ 1

Last change on this file since 1 was 1, checked in by Tim Harvey, 2 years ago

restored latest version of files from server backup

Signed-off-by: Tim Harvey <tharvey@…>

File size: 11.8 KB
Line 
1/**
2 * @file IxEthDBSearch.c
3 *
4 * @par
5 * IXP400 SW Release version 2.3
6 *
7 * -- Copyright Notice --
8 *
9 * @par
10 * Copyright (c) 2001-2005, Intel Corporation.
11 * All rights reserved.
12 *
13 * @par
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 *    notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 *    notice, this list of conditions and the following disclaimer in the
21 *    documentation and/or other materials provided with the distribution.
22 * 3. Neither the name of the Intel Corporation nor the names of its contributors
23 *    may be used to endorse or promote products derived from this software
24 *    without specific prior written permission.
25 *
26 *
27 * @par
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
29 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * SUCH DAMAGE.
39 *
40 *
41 * @par
42 * -- End of Copyright Notice --
43 */
44
45#include "IxEthDB_p.h"
46
47extern HashTable dbHashtable;
48
49/**
50 * @brief matches two database records based on their MAC addresses
51 *
52 * @param untypedReference record to match against
53 * @param untypedEntry record to match
54 *
55 * @return TRUE if the match is successful or FALSE otherwise
56 *
57 * @internal
58 */
59IX_ETH_DB_PUBLIC
60BOOL ixEthDBAddressRecordMatch(void *untypedReference, void *untypedEntry)
61{
62    MacDescriptor *entry     = (MacDescriptor *) untypedEntry;
63    MacDescriptor *reference = (MacDescriptor *) untypedReference;
64   
65    /* check accepted record types */
66    if ((entry->type & reference->type) == 0) return FALSE;
67       
68    return (ixEthDBAddressCompare((UINT8 *) entry->macAddress, (UINT8 *) reference->macAddress) == 0);
69}
70
71/**
72 * @brief matches two database records based on their MAC addresses
73 * and VLAN IDs
74 *
75 * @param untypedReference record to match against
76 * @param untypedEntry record to match
77 *
78 * @return TRUE if the match is successful or FALSE otherwise
79 *
80 * @internal
81 */
82IX_ETH_DB_PUBLIC
83BOOL ixEthDBVlanRecordMatch(void *untypedReference, void *untypedEntry)
84{
85    MacDescriptor *entry     = (MacDescriptor *) untypedEntry;
86    MacDescriptor *reference = (MacDescriptor *) untypedReference;
87   
88    /* check accepted record types */
89    if ((entry->type & reference->type) == 0) return FALSE;
90   
91    return (IX_ETH_DB_GET_VLAN_ID(entry->recordData.filteringVlanData.ieee802_1qTag) ==
92        IX_ETH_DB_GET_VLAN_ID(reference->recordData.filteringVlanData.ieee802_1qTag)) &&
93        (ixEthDBAddressCompare(entry->macAddress, reference->macAddress) == 0);
94}
95
96/**
97 * @brief matches two database records based on their MAC addresses
98 * and port IDs
99 *
100 * @param untypedReference record to match against
101 * @param untypedEntry record to match
102 *
103 * @return TRUE if the match is successful or FALSE otherwise
104 *
105 * @internal
106 */
107IX_ETH_DB_PUBLIC
108BOOL ixEthDBPortRecordMatch(void *untypedReference, void *untypedEntry)
109{
110    MacDescriptor *entry     = (MacDescriptor *) untypedEntry;
111    MacDescriptor *reference = (MacDescriptor *) untypedReference;
112   
113    /* check accepted record types */
114    if ((entry->type & reference->type) == 0) return FALSE;
115   
116    return (entry->portID == reference->portID) &&
117        (ixEthDBAddressCompare(entry->macAddress, reference->macAddress) == 0);
118}
119
120/**
121 * @brief matches two database records based on their
122 * MAC addresses, masks and port IDs
123 *
124 * @param untypedReference record to match against
125 * @param untypedEntry record to match
126 *
127 * @return TRUE if the match is successful or FALSE otherwise
128 *
129 * @internal
130 */
131IX_ETH_DB_PUBLIC
132BOOL ixEthDBFirewallMaskedRecordMatch(void *untypedReference, void *untypedEntry)
133{
134    MacDescriptor *entry     = (MacDescriptor *) untypedEntry;
135    MacDescriptor *reference = (MacDescriptor *) untypedReference;
136   
137    /* check accepted record types */
138    if ((entry->type & reference->type) == 0) return FALSE;
139   
140    return (entry->portID == reference->portID) &&
141        (ixEthDBAddressCompare(entry->macAddress, reference->macAddress) == 0) &&
142        (ixEthDBAddressCompare(entry->recordData.firewallData.addressMask, reference->recordData.firewallData.addressMask) == 0);
143}
144
145/**
146 * @brief matches two database records based on their MAC addresses
147 * , aging type and port IDs
148 *
149 * @param untypedReference record to match against
150 * @param untypedEntry record to match
151 *
152 * @return TRUE if the match is successful or FALSE otherwise
153 *
154 * @internal
155 */
156IX_ETH_DB_PUBLIC
157BOOL ixEthDBPortAgeTypeRecordMatch(void *untypedReference, void *untypedEntry)
158{
159    MacDescriptor *entry     = (MacDescriptor *) untypedEntry;
160    MacDescriptor *reference = (MacDescriptor *) untypedReference;
161   
162    /* check accepted record types */
163    if ((entry->type & reference->type) == 0) return FALSE;
164   
165    return ((entry->portID == reference->portID) &&
166        (ixEthDBAddressCompare(entry->macAddress, reference->macAddress) == 0) && 
167            (entry->recordData.filteringData.staticEntry == 
168            reference->recordData.filteringData.staticEntry));
169}
170
171/**
172 * @brief dummy matching function, registered for safety
173 *
174 * @param reference record to match against (unused)
175 * @param entry record to match (unused)
176 *
177 * This function is registered in the matching functions
178 * array on invalid types. Calling it will display an
179 * error message, indicating an error in the component logic.
180 *
181 * @return FALSE
182 *
183 * @internal
184 */
185IX_ETH_DB_PUBLIC
186BOOL ixEthDBNullMatch(void *reference, void *entry)
187{
188    /* display an error message */
189
190    ixOsalLog(IX_OSAL_LOG_LVL_WARNING, IX_OSAL_LOG_DEV_STDOUT, "DB: (Search) The NullMatch function was called, wrong key type?\n", 0, 0, 0, 0, 0, 0);
191
192
193    return FALSE;
194}
195
196/**
197 * @brief registers hash matching methods
198 *
199 * @param matchFunctions table of match functions to be populated
200 *
201 * This function registers the available record matching functions
202 * by indexing them on record types into the given function array.
203 *
204 * Note that it is compulsory to call this in ixEthDBInit(),
205 * otherwise hashtable searching and removal will not work
206 *
207 * @return number of registered functions
208 *
209 * @internal
210 */
211IX_ETH_DB_PUBLIC
212UINT32 ixEthDBMatchMethodsRegister(MatchFunction *matchFunctions)
213{
214    UINT32 i;
215   
216    /* safety first */
217    for ( i = 0 ; i < IX_ETH_DB_MAX_KEY_INDEX + 1 ; i++)
218    {
219        matchFunctions[i] = ixEthDBNullMatch;
220    }
221   
222    /* register MAC search method */
223    matchFunctions[IX_ETH_DB_MAC_KEY] = ixEthDBAddressRecordMatch;
224   
225    /* register MAC/PortID search method */
226    matchFunctions[IX_ETH_DB_MAC_PORT_KEY] = ixEthDBPortRecordMatch;
227   
228    /* register MAC/VLAN ID search method */
229    matchFunctions[IX_ETH_DB_MAC_VLAN_KEY] = ixEthDBVlanRecordMatch;
230   
231    /* register MAC/VLAN ID search method */
232    matchFunctions[IX_ETH_DB_MAC_MASK_PORT_KEY] = ixEthDBFirewallMaskedRecordMatch;
233
234    /* register MAC/PortID/Aging Type search method */
235    matchFunctions[IX_ETH_DB_MAC_PORT_AGETYPE_KEY] = ixEthDBPortAgeTypeRecordMatch;
236 
237    return IX_ETH_DB_MAX_KEY_INDEX;
238}
239
240/**
241 * @brief search a record in the Ethernet datbase
242 *
243 * @param macAddress MAC address to perform the search on
244 * @param typeFilter type of records to consider for matching
245 *
246 * @warning if searching is successful an implicit write lock
247 * to the search result is granted, therefore unlock the
248 * entry using @ref ixEthDBReleaseHashNode() as soon as possible.
249 *
250 * @see ixEthDBReleaseHashNode()
251 *
252 * @return the search result, or NULL if a record with the given
253 * MAC address was not found
254 *
255 * @internal
256 */
257IX_ETH_DB_PUBLIC
258HashNode* ixEthDBSearch(IxEthDBMacAddr *macAddress, IxEthDBRecordType typeFilter)
259{
260    HashNode *searchResult = NULL;
261    MacDescriptor reference;
262   
263    TEST_FIXTURE_INCREMENT_DB_CORE_ACCESS_COUNTER;
264
265    if (macAddress == NULL)
266    {
267        return NULL;
268    }
269
270    /* fill search fields */
271    ixOsalMemCopy(reference.macAddress, macAddress, IX_IEEE803_MAC_ADDRESS_SIZE);
272   
273    /* set acceptable record types */
274    reference.type = typeFilter;
275   
276    BUSY_RETRY(ixEthDBSearchHashEntry(&dbHashtable, IX_ETH_DB_MAC_KEY, &reference, &searchResult));
277
278    return searchResult;
279}
280
281IX_ETH_DB_PUBLIC
282IxEthDBStatus ixEthDBPeek(IxEthDBMacAddr *macAddress, IxEthDBRecordType typeFilter)
283{
284    MacDescriptor reference;
285    IxEthDBStatus result;
286   
287    TEST_FIXTURE_INCREMENT_DB_CORE_ACCESS_COUNTER;
288
289    if (macAddress == NULL)
290    {
291        return IX_ETH_DB_INVALID_ARG;
292    }
293
294    /* fill search fields */
295    ixOsalMemCopy(reference.macAddress, macAddress, IX_IEEE803_MAC_ADDRESS_SIZE);
296   
297    /* set acceptable record types */
298    reference.type = typeFilter;
299   
300    result = ixEthDBPeekHashEntry(&dbHashtable, IX_ETH_DB_MAC_KEY, &reference);
301
302    return result;
303}
304
305/**
306 * @brief search a record in the Ethernet datbase
307 *
308 * @param macAddress MAC address to perform the search on
309 * @param portID port ID to perform the search on
310 * @param typeFilter type of records to consider for matching
311 *
312 * @warning if searching is successful an implicit write lock
313 * to the search result is granted, therefore unlock the
314 * entry using @ref ixEthDBReleaseHashNode() as soon as possible.
315 *
316 * @see ixEthDBReleaseHashNode()
317 *
318 * @return the search result, or NULL if a record with the given
319 * MAC address/port ID combination was not found
320 *
321 * @internal
322 */
323IX_ETH_DB_PUBLIC
324HashNode* ixEthDBPortSearch(IxEthDBMacAddr *macAddress, IxEthDBPortId portID, IxEthDBRecordType typeFilter)
325{
326    HashNode *searchResult = NULL;
327    MacDescriptor reference;
328   
329    if (macAddress == NULL)
330    {
331        return NULL;
332    }
333   
334    /* fill search fields */
335    ixOsalMemCopy(reference.macAddress, macAddress, IX_IEEE803_MAC_ADDRESS_SIZE);
336    reference.portID = portID;
337   
338    /* set acceptable record types */
339    reference.type = typeFilter;
340
341    BUSY_RETRY(ixEthDBSearchHashEntry(&dbHashtable, IX_ETH_DB_MAC_PORT_KEY, &reference, &searchResult));
342
343    return searchResult;
344}
345
346/**
347 * @brief search a record in the Ethernet datbase
348 *
349 * @param macAddress MAC address to perform the search on
350 * @param vlanID VLAN ID to perform the search on
351 * @param typeFilter type of records to consider for matching
352 *
353 * @warning if searching is successful an implicit write lock
354 * to the search result is granted, therefore unlock the
355 * entry using @ref ixEthDBReleaseHashNode() as soon as possible.
356 *
357 * @see ixEthDBReleaseHashNode()
358 *
359 * @return the search result, or NULL if a record with the given
360 * MAC address/VLAN ID combination was not found
361 *
362 * @internal
363 */
364IX_ETH_DB_PUBLIC
365HashNode* ixEthDBVlanSearch(IxEthDBMacAddr *macAddress, IxEthDBVlanId vlanID, IxEthDBRecordType typeFilter)
366{
367    HashNode *searchResult = NULL;
368    MacDescriptor reference;
369   
370    if (macAddress == NULL)
371    {
372        return NULL;
373    }
374   
375    /* fill search fields */
376    ixOsalMemCopy(reference.macAddress, macAddress, IX_IEEE803_MAC_ADDRESS_SIZE);
377    reference.recordData.filteringVlanData.ieee802_1qTag = 
378            IX_ETH_DB_SET_VLAN_ID(reference.recordData.filteringVlanData.ieee802_1qTag, vlanID);
379   
380    /* set acceptable record types */
381    reference.type = typeFilter;
382
383    BUSY_RETRY(ixEthDBSearchHashEntry(&dbHashtable, IX_ETH_DB_MAC_VLAN_KEY, &reference, &searchResult));
384
385    return searchResult;
386}
Note: See TracBrowser for help on using the repository browser.