• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • Directories
  • File List
  • Globals

dst_blacklist.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2006 iptelorg GmbH
00003  *
00004  * This file is part of ser, a free SIP server.
00005  *
00006  * ser is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version
00010  *
00011  * ser is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00027 /* History:
00028  * --------
00029  *  2006-07-29  created by andrei
00030  *  2007-07-30  dst blacklist measurements added (Gergo)
00031  *  2009-12-22  blacklist ignore mask support and dst_blacklist_{add,su}
00032  *               switched to macros (andrei)
00033  */
00034 
00035 #ifndef dst_black_list_h
00036 #define dst_black_list_h
00037 
00038 #include "ip_addr.h"
00039 #include "parser/msg_parser.h"
00040 #include "timer_ticks.h"
00041 #include "cfg_core.h"
00042 
00043 #define DEFAULT_BLST_TIMEOUT            60  
00044 #define DEFAULT_BLST_MAX_MEM            250 
00047 
00049 #define BLST_IS_IPV6            1               
00050 #define BLST_ERR_SEND           (1<<1)  
00051 #define BLST_ERR_CONNECT        (1<<2)  
00052 #define BLST_ICMP_RCVD          (1<<3)  
00053 #define BLST_ERR_TIMEOUT        (1<<4)  
00054 #define BLST_503                        (1<<5)  
00055 #define BLST_ADM_PROHIBITED     (1<<6)  
00056 #define BLST_PERMANENT          (1<<7)  
00057 
00059 /* uncomment the define above to enable blacklist callbacks support */
00060 /*#define DST_BLACKLIST_HOOKS*/
00061 
00062 #define DST_BLACKLIST_CONTINUE 0 
00063 #define DST_BLACKLIST_ACCEPT 1   
00064 #define DST_BLACKLIST_DENY  -1   
00066 #define DST_BLACKLIST_ADD_CB 1
00067 #define DST_BLACKLIST_SEARCH_CB 2
00068 
00069 
00070 extern unsigned blst_proto_imask[PROTO_LAST+1];
00071 
00072 #ifdef DST_BLACKLIST_HOOKS
00073 struct blacklist_hook{
00074         /* WARNING: msg might be NULL, and it might point to shared memory
00075          * without locking, do not modify it! msg can be used typically for checking
00076          * the message flags with isflagset() */
00077         int (*on_blst_action)(struct dest_info* si, unsigned char* err_flags,
00078                                                         struct sip_msg* msg);
00079         /* called before ser shutdown */
00080         void (*destroy)(void);
00081 };
00082 
00083 int register_blacklist_hook(struct blacklist_hook *h, int type);
00084 #endif /* DST_BLACKLIST_HOOKS */
00085 
00086 int init_dst_blacklist(void);
00087 #ifdef USE_DST_BLACKLIST_STATS
00088 int init_dst_blacklist_stats(int iproc_num);
00089 #define DST_BLACKLIST_ALL_STATS "bkl_all_stats"
00090 #endif
00091 void destroy_dst_blacklist(void);
00092 
00093 
00099 int dst_blacklist_force_add_to(unsigned char err_flags, struct dest_info* si,
00100                                                                 struct sip_msg* msg, ticks_t timeout);
00101 
00107 int dst_blacklist_force_su_to(  unsigned char err_flags,
00108                                                                 unsigned char proto,
00109                                                                 union sockaddr_union* dst,
00110                                                                 struct sip_msg* msg,
00111                                                                 ticks_t timeout);
00112 
00113 
00121 #define should_blacklist(err_flags, si) \
00122         (cfg_get(core, core_cfg, use_dst_blacklist) && \
00123                 ((err_flags) & ~blst_proto_imask[(unsigned)((si)->proto)] & \
00124                                            ~(si)->send_flags.blst_imask ))
00125 
00126 
00135 #define should_blacklist_su(err_flags, snd_flags, proto, su) \
00136         (cfg_get(core, core_cfg, use_dst_blacklist) && \
00137                 ((err_flags) & ~blst_proto_imask[(unsigned)(proto)] & \
00138                                         ~((snd_flags)?((snd_flags_t*)(snd_flags))->blst_imask:0)))
00139 
00140 
00149 #define dst_blacklist_add_to(err_flags, si, msg, timeout) \
00150         (should_blacklist(err_flags, si)? \
00151                 dst_blacklist_force_add_to((err_flags), (si), (msg), (timeout))\
00152                 : 0)
00153 
00154 
00165 #define dst_blacklist_su_to(err_flags, proto, dst, snd_flags, msg, timeout) \
00166         (should_blacklist_su(err_flags, snd_flags, proto, dst) ? \
00167                 dst_blacklist_force_su_to((err_flags), (proto), (dst), (msg), \
00168                                                                         (timeout))\
00169                 : 0)
00170 
00171 
00180 #define dst_blacklist_add(err_flags, si, msg) \
00181         dst_blacklist_add_to(err_flags, si, msg, \
00182                                                         S_TO_TICKS(cfg_get(core, core_cfg, blst_timeout)))
00183 
00184 
00195 #define dst_blacklist_su(err_flags, proto, dst, snd_flags, msg) \
00196         dst_blacklist_su_to(err_flags, proto, dst, snd_flags, msg, \
00197                                                         S_TO_TICKS(cfg_get(core, core_cfg, blst_timeout)))
00198 
00199 int dst_is_blacklisted(struct dest_info* si, struct sip_msg* msg);
00200 
00202 int dst_blacklist_del(struct dest_info* si, struct sip_msg* msg);
00203 
00207 void dst_blst_flush(void);
00208 
00209 int use_dst_blacklist_fixup(void *handle, str *gname, str *name, void **val);
00210 
00212 int blst_max_mem_fixup(void *handle, str *gname, str *name, void **val);
00213 
00214 void blst_reinit_ign_masks(str* gname, str* name);
00215 
00216 #endif

Generated on Tue May 22 2012 13:10:06 for SIP Router by  doxygen 1.7.1