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