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