nc.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * $Id$
  3. *
  4. * nonce-count (nc) tracking
  5. *
  6. * Copyright (C) 2008 iptelorg GmbH
  7. *
  8. * This file is part of ser, a free SIP server.
  9. *
  10. * ser is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version
  14. *
  15. * ser is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. */
  24. /*
  25. * Defines:
  26. * USE_NC - if not defined no NC specific code will be compiled
  27. */
  28. /*
  29. * History:
  30. * --------
  31. * 2008-07-04 initial version (andrei)
  32. */
  33. #ifndef _nc_h
  34. #define _nc_h
  35. extern int nc_enabled;
  36. /* instead of storing only the 2^k size we store also k
  37. * for faster operations */
  38. extern unsigned nc_array_k; /* array size bits (k in 2^k) */
  39. extern unsigned nc_array_size; /* 2^k == 1<<nc_array_bits */
  40. #ifdef USE_NC
  41. #include "nid.h" /* nid_t */
  42. #include "../../atomic_ops.h"
  43. /* default number of maximum in-flight nonces */
  44. #define DEFAULT_NC_ARRAY_SIZE 1024*1024 /* uses 1Mb of memory */
  45. #define MIN_NC_ARRAY_SIZE 102400 /* warn if size < 100k */
  46. #define MAX_NC_ARRAY_SIZE 1024*1024*1024 /* warn if size > 1Gb */
  47. #define MIN_NC_ARRAY_PARTITION 65536 /* warn if a partition is < 65k */
  48. typedef unsigned char nc_t;
  49. int init_nonce_count();
  50. void destroy_nonce_count();
  51. enum nc_check_ret{
  52. NC_OK=0, NC_INV_POOL=-1, NC_ID_OVERFLOW=-2, NC_TOO_BIG=-3,
  53. NC_REPLAY=-4
  54. };
  55. /* check if nonce-count nc w/ index i is expected/valid and record its
  56. * value */
  57. enum nc_check_ret nc_check_val(nid_t i, unsigned pool, unsigned int nc);
  58. /* re-init the stored nc for nonce id in pool pool_no */
  59. nid_t nc_new(nid_t id, unsigned char pool_no);
  60. #endif /* USE_NC */
  61. #endif /* _nc_h */