[sr-dev] git:andrei/blst_send_flags: blst: global config variables for ignoring blacklist events

Andrei Pelinescu-Onciul andrei at iptel.org
Mon Feb 15 21:41:27 CET 2010


Module: sip-router
Branch: andrei/blst_send_flags
Commit: 0f9e9908055fe15d26d953f5477559254ef37436
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=0f9e9908055fe15d26d953f5477559254ef37436

Author: Andrei Pelinescu-Onciul <andrei at iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei at iptel.org>
Date:   Mon Feb 15 21:37:28 2010 +0100

blst: global config variables for ignoring blacklist events

Blacklist events can now be ignored on a per protocol basis, by
setting the corresponding new config variable:
 dst_blacklist_udp_imask
 dst_blacklist_tcp_imask
 dst_blacklist_tls_imask
 dst_blacklist_sctp_imask

E.g.: sercmd cfg.set_now_int core dst_blacklist_tcp_imask 6
 (ignore send and connect errors on tcp when deciding whether or
  not to blacklist)

---

 cfg_core.c      |   15 ++++++++++++++-
 cfg_core.h      |    4 ++++
 dst_blacklist.c |   36 ++++++++++++++++++++++++++++++++++++
 dst_blacklist.h |   12 +++++++++---
 4 files changed, 63 insertions(+), 4 deletions(-)

diff --git a/cfg_core.c b/cfg_core.c
index edebb9b..6f91740 100644
--- a/cfg_core.c
+++ b/cfg_core.c
@@ -54,6 +54,10 @@ struct cfg_group_core default_core_cfg = {
 	0, /* dst blacklist is disabled by default */
 	DEFAULT_BLST_TIMEOUT,
 	DEFAULT_BLST_MAX_MEM,
+	0, /* blst_udp_imask */
+	0, /* blst_tcp_imask */
+	0, /* blst_tls_imask */
+	0, /* blst_sctp_imask */
 #endif
 	/* resolver */
 #ifdef USE_IPV6
@@ -114,7 +118,16 @@ cfg_def_t core_cfg_def[] = {
 	{"dst_blacklist_expire",	CFG_VAR_INT,	0, 0, 0, 0,
 		"how much time (in s) a blacklisted destination is kept in the list"},
 	{"dst_blacklist_mem",	CFG_VAR_INT,	0, 0, blst_max_mem_fixup, 0,
-		"maximum shared memory amount (in KB) used for keeping the blacklisted destinations"},
+		"maximum shared memory amount (in KB) used for keeping the blacklisted"
+			" destinations"},
+	{"dst_blacklist_udp_imask", CFG_VAR_INT, 0, 0, 0, blst_reinit_ign_masks,
+		"blacklist event ignore mask for UDP"},
+	{"dst_blacklist_tcp_imask", CFG_VAR_INT, 0, 0, 0, blst_reinit_ign_masks,
+		"blacklist event ignore mask for TCP"},
+	{"dst_blacklist_tls_imask", CFG_VAR_INT, 0, 0, 0, blst_reinit_ign_masks,
+		"blacklist event ignore mask for TLS"},
+	{"dst_blacklist_sctp_imask", CFG_VAR_INT, 0, 0, 0, blst_reinit_ign_masks,
+		"blacklist event ignore mask for SCTP"},
 #endif
 	/* resolver */
 #ifdef USE_DNS_CACHE
diff --git a/cfg_core.h b/cfg_core.h
index b37aacc..9fa26f6 100644
--- a/cfg_core.h
+++ b/cfg_core.h
@@ -54,6 +54,10 @@ struct cfg_group_core {
 	unsigned int	blst_timeout; /* blacklist entry ttl */
 	unsigned int	blst_max_mem; /* maximum memory used for the
 					blacklist entries */
+	unsigned int	blst_udp_imask;  /* ignore mask for udp */
+	unsigned int	blst_tcp_imask;  /* ignore mask for tcp */
+	unsigned int	blst_tls_imask;  /* ignore mask for tls */
+	unsigned int	blst_sctp_imask; /* ignore mask for sctp */
 #endif
 	/* resolver */
 	int dns_try_ipv6;
diff --git a/dst_blacklist.c b/dst_blacklist.c
index 2c3653b..0e22727 100644
--- a/dst_blacklist.c
+++ b/dst_blacklist.c
@@ -136,6 +136,9 @@ struct dst_blst_lst_head* dst_blst_hash=0;
 struct t_dst_blacklist_stats* dst_blacklist_stats=0;
 #endif
 
+/* blacklist per protocol event ignore mask array */
+unsigned blst_proto_imask[PROTO_LAST+1];
+
 #ifdef DST_BLACKLIST_HOOKS
 
 /* there 2 types of callbacks supported: on add new entry to the blacklist
@@ -296,6 +299,26 @@ inline static int blacklist_run_hooks(struct blst_callbacks_lst *cb_lst,
 #endif /* DST_BLACKLIST_HOOKS */
 
 
+/** init per protocol blacklist event ignore masks.
+ * @return 0 on success, < 0 on error.
+ */
+int blst_init_ign_masks()
+{
+	if ((PROTO_UDP > PROTO_LAST) || (PROTO_TCP > PROTO_LAST) ||
+		(PROTO_TLS > PROTO_LAST) || (PROTO_SCTP > PROTO_LAST)){
+		BUG("protocol array too small\n");
+		return -1;
+	}
+	blst_proto_imask[PROTO_UDP]=cfg_get(core, core_cfg, blst_udp_imask);
+	blst_proto_imask[PROTO_TCP]=cfg_get(core, core_cfg, blst_tcp_imask);
+	blst_proto_imask[PROTO_TLS]=cfg_get(core, core_cfg, blst_tls_imask);
+	blst_proto_imask[PROTO_SCTP]=cfg_get(core, core_cfg, blst_sctp_imask);
+	blst_proto_imask[PROTO_NONE]=blst_proto_imask[PROTO_UDP];
+	return 0;
+}
+
+
+
 inline static void blst_destroy_entry(struct dst_blst_entry* e)
 {
 	shm_free(e);
@@ -478,6 +501,10 @@ int init_dst_blacklist()
 			goto error;
 		}
 	}
+	if (blst_init_ign_masks() < 0){
+		ret=E_BUG;
+		goto error;
+	}
 	return 0;
 error:
 	destroy_dst_blacklist();
@@ -1197,5 +1224,14 @@ int blst_max_mem_fixup(void *handle, str *gname, str *name, void **val)
 	return 0;
 }
 
+
+
+/** re-inint per child blst_proto_ign_mask array. */
+void blst_reinit_ign_masks(str* gname, str* name)
+{
+	blst_init_ign_masks();
+}
+
+
 #endif /* USE_DST_BLACKLIST */
 
diff --git a/dst_blacklist.h b/dst_blacklist.h
index 175ce78..c079167 100644
--- a/dst_blacklist.h
+++ b/dst_blacklist.h
@@ -65,6 +65,9 @@
 #define DST_BLACKLIST_ADD_CB 1
 #define DST_BLACKLIST_SEARCH_CB 2
 
+
+extern unsigned blst_proto_imask[PROTO_LAST+1];
+
 #ifdef DST_BLACKLIST_HOOKS
 struct blacklist_hook{
 	/* WARNING: msg might be NULL, and it might point to shared memory
@@ -109,14 +112,15 @@ int dst_blacklist_force_su_to(	unsigned char err_flags,
 
 /** checks if blacklist should be used.
   * @param  err_flags - blacklist reason
-  * @param si - filled dst_info structure pointer.
+  * @param si - filled dest_info structure pointer.
   * @return 1 if blacklist is enabled (core_cfg) and the event/error
   *           is not in the ignore list.
   *         0 otherwise
   */
 #define should_blacklist(err_flags, si) \
 	(cfg_get(core, core_cfg, use_dst_blacklist) && \
-		((err_flags) & (si)->send_flags.blst_imask))
+		((err_flags) & ~blst_proto_imask[(unsigned)((si)->proto)] & \
+		 			   ~(si)->send_flags.blst_imask ))
 
 
 /** checks if blacklist should be used, long version.
@@ -130,7 +134,7 @@ int dst_blacklist_force_su_to(	unsigned char err_flags,
   */
 #define should_blacklist_su(err_flags, snd_flags, proto, su) \
 	(cfg_get(core, core_cfg, use_dst_blacklist) && \
-		((err_flags) & \
+		((err_flags) & ~blst_proto_imask[(unsigned)(proto)] & \
 		 			~((snd_flags)?((snd_flags_t*)(snd_flags))->blst_imask:0)))
 
 
@@ -205,4 +209,6 @@ int use_dst_blacklist_fixup(void *handle, str *gname, str *name, void **val);
 /* KByte to Byte conversion */
 int blst_max_mem_fixup(void *handle, str *gname, str *name, void **val);
 
+void blst_reinit_ign_masks(str* gname, str* name);
+
 #endif




More information about the sr-dev mailing list