bcmbloom.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Bloom filter support
  3. *
  4. * Portions of this code are copyright (c) 2020 Cypress Semiconductor Corporation
  5. *
  6. * Copyright (C) 1999-2020, 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. #ifndef _bcmbloom_h_
  32. #define _bcmbloom_h_
  33. #include <typedefs.h>
  34. #ifdef BCMDRIVER
  35. #include <osl.h>
  36. #else
  37. #include <stddef.h> /* For size_t */
  38. #endif // endif
  39. struct bcm_bloom_filter;
  40. typedef struct bcm_bloom_filter bcm_bloom_filter_t;
  41. typedef void* (*bcm_bloom_alloc_t)(void *ctx, uint size);
  42. typedef void (*bcm_bloom_free_t)(void *ctx, void *buf, uint size);
  43. typedef uint (*bcm_bloom_hash_t)(void* ctx, uint idx, const uint8 *tag, uint len);
  44. /* create/allocate a bloom filter. filter size can be 0 for validate only filters */
  45. int bcm_bloom_create(bcm_bloom_alloc_t alloc_cb,
  46. bcm_bloom_free_t free_cb, void *callback_ctx, uint max_hash,
  47. uint filter_size /* bytes */, bcm_bloom_filter_t **bloom);
  48. /* destroy bloom filter */
  49. int bcm_bloom_destroy(bcm_bloom_filter_t **bloom, bcm_bloom_free_t free_cb);
  50. /* add a hash function to filter, return an index */
  51. int bcm_bloom_add_hash(bcm_bloom_filter_t *filter, bcm_bloom_hash_t hash, uint *idx);
  52. /* remove the hash function at index from filter */
  53. int bcm_bloom_remove_hash(bcm_bloom_filter_t *filter, uint idx);
  54. /* check if given tag is member of the filter. If buf is NULL and/or buf_len is 0
  55. * then use the internal state. BCME_OK if member, BCME_NOTFOUND if not,
  56. * or other error (e.g. BADARG)
  57. */
  58. bool bcm_bloom_is_member(bcm_bloom_filter_t *filter,
  59. const uint8 *tag, uint tag_len, const uint8 *buf, uint buf_len);
  60. /* add a member to the filter. invalid for validate_only filters */
  61. int bcm_bloom_add_member(bcm_bloom_filter_t *filter, const uint8 *tag, uint tag_len);
  62. /* no support for remove member */
  63. /* get the filter data from state. BCME_BUFTOOSHORT w/ required length in buf_len
  64. * if supplied size is insufficient
  65. */
  66. int bcm_bloom_get_filter_data(bcm_bloom_filter_t *filter,
  67. uint buf_size, uint8 *buf, uint *buf_len);
  68. #endif /* _bcmbloom_h_ */