dst_blacklist.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * $Id$
  3. *
  4. * resolver related functions
  5. *
  6. * Copyright (C) 2006 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. * For a license to use the ser software under conditions
  16. * other than those described here, or to purchase support for this
  17. * software, please contact iptel.org by e-mail at the following addresses:
  18. * [email protected]
  19. *
  20. * ser is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  28. */
  29. /* History:
  30. * --------
  31. * 2006-07-29 created by andrei
  32. * 2007-07-30 dst blacklist measurements added (Gergo)
  33. */
  34. #ifndef dst_black_list_h
  35. #define dst_black_list_h
  36. #include "ip_addr.h"
  37. #include "parser/msg_parser.h"
  38. #include "timer_ticks.h"
  39. #include "cfg_core.h"
  40. #define DEFAULT_BLST_TIMEOUT 60 /* 1 min. */
  41. #define DEFAULT_BLST_MAX_MEM 250 /* 250 KB */
  42. /* flags: */
  43. #define BLST_IS_IPV6 1 /* set if the address is ipv6 */
  44. #define BLST_ERR_SEND (1<<1) /* set if send is denied/failed */
  45. #define BLST_ERR_CONNECT (1<<2) /* set if connect failed (tcp/tls) */
  46. #define BLST_ICMP_RCVD (1<<3) /* set if icmp error */
  47. #define BLST_ERR_TIMEOUT (1<<4) /* set if sip timeout */
  48. #define BLST_503 (1<<5) /* set for 503 replies */
  49. #define BLST_ADM_PROHIBITED (1<<6) /* administratively prohibited */
  50. #define BLST_PERMANENT (1<<7) /* never deleted, never expires */
  51. /* uncomment the define above to enable blacklist callbacks support */
  52. /*#define DST_BLACKLIST_HOOKS*/
  53. #define DST_BLACKLIST_CONTINUE 0 /* add: do nothing/ignore, search: ignore */
  54. #define DST_BLACKLIST_ACCEPT 1 /* add: force accept, search: force match */
  55. #define DST_BLACKLIST_DENY -1 /* add: deny, search: force no match */
  56. #define DST_BLACKLIST_ADD_CB 1
  57. #define DST_BLACKLIST_SEARCH_CB 2
  58. #ifdef DST_BLACKLIST_HOOKS
  59. struct blacklist_hook{
  60. /* WARNING: msg might be NULL, and it might point to shared memory
  61. * without locking, do not modify it! msg can be used typically for checking
  62. * the message flags with isflagset() */
  63. int (*on_blst_action)(struct dest_info* si, unsigned char* err_flags,
  64. struct sip_msg* msg);
  65. /* called before ser shutdown */
  66. void (*destroy)(void);
  67. };
  68. int register_blacklist_hook(struct blacklist_hook *h, int type);
  69. #endif /* DST_BLACKLIST_HOOKS */
  70. int init_dst_blacklist();
  71. #ifdef USE_DST_BLACKLIST_STATS
  72. int init_dst_blacklist_stats(int iproc_num);
  73. #define DST_BLACKLIST_ALL_STATS "bkl_all_stats"
  74. #endif
  75. void destroy_dst_blacklist();
  76. /* like dst_blacklist_add, but the timeout can be also set */
  77. int dst_blacklist_add_to(unsigned char err_flags, struct dest_info* si,
  78. struct sip_msg* msg, ticks_t timeout);
  79. /* adds a dst to the blacklist with default timeout */
  80. #define dst_blacklist_add(err_flags, si, msg) \
  81. dst_blacklist_add_to((err_flags), (si), (msg), \
  82. S_TO_TICKS(cfg_get(core, core_cfg, blst_timeout)))
  83. int dst_is_blacklisted(struct dest_info* si, struct sip_msg* msg);
  84. /* delete an entry from the blacklist */
  85. int dst_blacklist_del(struct dest_info* si, struct sip_msg* msg);
  86. /* deletes all the entries from the blacklist except the permanent ones
  87. * (which are marked with BLST_PERMANENT)
  88. */
  89. void dst_blst_flush(void);
  90. int use_dst_blacklist_fixup(void *handle, str *name, void **val);
  91. /* KByte to Byte conversion */
  92. int blst_max_mem_fixup(void *handle, str *name, void **val);
  93. #endif