• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Bloom filter support
3  *
4  * Copyright (C) 1999-2019, Broadcom.
5  *
6  *      Unless you and Broadcom execute a separate written software license
7  * agreement governing use of this software, this software is licensed to you
8  * under the terms of the GNU General Public License version 2 (the "GPL"),
9  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
10  * following added to such license:
11  *
12  *      As a special exception, the copyright holders of this software give you
13  * permission to link this software with independent modules, and to copy and
14  * distribute the resulting executable under terms of your choice, provided that
15  * you also meet, for each linked independent module, the terms and conditions
16  * of the license of that module.  An independent module is a module which is
17  * not derived from this software.  The special exception does not apply to any
18  * modifications of the software.
19  *
20  *      Notwithstanding the above, under no circumstances may you combine this
21  * software in any way with any other Broadcom software provided under a license
22  * other than the GPL, without Broadcom's express prior written consent.
23  *
24  *
25  * <<Broadcom-WL-IPTag/Open:>>
26  *
27  * $Id: bcmbloom.h 714397 2017-08-04 08:24:38Z $
28  */
29 
30 #ifndef _bcmbloom_h_
31 #define _bcmbloom_h_
32 
33 #include <typedefs.h>
34 #ifdef BCMDRIVER
35 #include <osl.h>
36 #else
37 #include <stddef.h> /* For size_t */
38 #endif              // endif
39 
40 struct bcm_bloom_filter;
41 typedef struct bcm_bloom_filter bcm_bloom_filter_t;
42 
43 typedef void *(*bcm_bloom_alloc_t)(void *ctx, uint size);
44 typedef void (*bcm_bloom_free_t)(void *ctx, void *buf, uint size);
45 typedef uint (*bcm_bloom_hash_t)(void *ctx, uint idx, const uint8 *tag,
46                                  uint len);
47 
48 /* create/allocate a bloom filter. filter size can be 0 for validate only
49  * filters */
50 int bcm_bloom_create(bcm_bloom_alloc_t alloc_cb, bcm_bloom_free_t free_cb,
51                      void *callback_ctx, uint max_hash,
52                      uint filter_size /* bytes */, bcm_bloom_filter_t **bloom);
53 
54 /* destroy bloom filter */
55 int bcm_bloom_destroy(bcm_bloom_filter_t **bloom, bcm_bloom_free_t free_cb);
56 
57 /* add a hash function to filter, return an index */
58 int bcm_bloom_add_hash(bcm_bloom_filter_t *filter, bcm_bloom_hash_t hash,
59                        uint *idx);
60 
61 /* remove the hash function at index from filter */
62 int bcm_bloom_remove_hash(bcm_bloom_filter_t *filter, uint idx);
63 
64 /* check if given tag is member of the filter. If buf is NULL and/or buf_len is
65  * 0 then use the internal state. BCME_OK if member, BCME_NOTFOUND if not, or
66  * other error (e.g. BADARG)
67  */
68 bool bcm_bloom_is_member(bcm_bloom_filter_t *filter, const uint8 *tag,
69                          uint tag_len, const uint8 *buf, uint buf_len);
70 
71 /* add a member to the filter. invalid for validate_only filters */
72 int bcm_bloom_add_member(bcm_bloom_filter_t *filter, const uint8 *tag,
73                          uint tag_len);
74 
75 /* no support for remove member */
76 
77 /* get the filter data from state. BCME_BUFTOOSHORT w/ required length in
78  * buf_len if supplied size is insufficient
79  */
80 int bcm_bloom_get_filter_data(bcm_bloom_filter_t *filter, uint buf_size,
81                               uint8 *buf, uint *buf_len);
82 
83 #endif /* _bcmbloom_h_ */
84