Browse code

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)

Andrei Pelinescu-Onciul authored on 15/02/2010 20:37:28
Showing 4 changed files
... ...
@@ -54,6 +54,10 @@ struct cfg_group_core default_core_cfg = {
54 54
 	0, /* dst blacklist is disabled by default */
55 55
 	DEFAULT_BLST_TIMEOUT,
56 56
 	DEFAULT_BLST_MAX_MEM,
57
+	0, /* blst_udp_imask */
58
+	0, /* blst_tcp_imask */
59
+	0, /* blst_tls_imask */
60
+	0, /* blst_sctp_imask */
57 61
 #endif
58 62
 	/* resolver */
59 63
 #ifdef USE_IPV6
... ...
@@ -114,7 +118,16 @@ cfg_def_t core_cfg_def[] = {
114 114
 	{"dst_blacklist_expire",	CFG_VAR_INT,	0, 0, 0, 0,
115 115
 		"how much time (in s) a blacklisted destination is kept in the list"},
116 116
 	{"dst_blacklist_mem",	CFG_VAR_INT,	0, 0, blst_max_mem_fixup, 0,
117
-		"maximum shared memory amount (in KB) used for keeping the blacklisted destinations"},
117
+		"maximum shared memory amount (in KB) used for keeping the blacklisted"
118
+			" destinations"},
119
+	{"dst_blacklist_udp_imask", CFG_VAR_INT, 0, 0, 0, blst_reinit_ign_masks,
120
+		"blacklist event ignore mask for UDP"},
121
+	{"dst_blacklist_tcp_imask", CFG_VAR_INT, 0, 0, 0, blst_reinit_ign_masks,
122
+		"blacklist event ignore mask for TCP"},
123
+	{"dst_blacklist_tls_imask", CFG_VAR_INT, 0, 0, 0, blst_reinit_ign_masks,
124
+		"blacklist event ignore mask for TLS"},
125
+	{"dst_blacklist_sctp_imask", CFG_VAR_INT, 0, 0, 0, blst_reinit_ign_masks,
126
+		"blacklist event ignore mask for SCTP"},
118 127
 #endif
119 128
 	/* resolver */
120 129
 #ifdef USE_DNS_CACHE
... ...
@@ -54,6 +54,10 @@ struct cfg_group_core {
54 54
 	unsigned int	blst_timeout; /* blacklist entry ttl */
55 55
 	unsigned int	blst_max_mem; /* maximum memory used for the
56 56
 					blacklist entries */
57
+	unsigned int	blst_udp_imask;  /* ignore mask for udp */
58
+	unsigned int	blst_tcp_imask;  /* ignore mask for tcp */
59
+	unsigned int	blst_tls_imask;  /* ignore mask for tls */
60
+	unsigned int	blst_sctp_imask; /* ignore mask for sctp */
57 61
 #endif
58 62
 	/* resolver */
59 63
 	int dns_try_ipv6;
... ...
@@ -136,6 +136,9 @@ struct dst_blst_lst_head* dst_blst_hash=0;
136 136
 struct t_dst_blacklist_stats* dst_blacklist_stats=0;
137 137
 #endif
138 138
 
139
+/* blacklist per protocol event ignore mask array */
140
+unsigned blst_proto_imask[PROTO_LAST+1];
141
+
139 142
 #ifdef DST_BLACKLIST_HOOKS
140 143
 
141 144
 /* 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,
296 296
 #endif /* DST_BLACKLIST_HOOKS */
297 297
 
298 298
 
299
+/** init per protocol blacklist event ignore masks.
300
+ * @return 0 on success, < 0 on error.
301
+ */
302
+int blst_init_ign_masks()
303
+{
304
+	if ((PROTO_UDP > PROTO_LAST) || (PROTO_TCP > PROTO_LAST) ||
305
+		(PROTO_TLS > PROTO_LAST) || (PROTO_SCTP > PROTO_LAST)){
306
+		BUG("protocol array too small\n");
307
+		return -1;
308
+	}
309
+	blst_proto_imask[PROTO_UDP]=cfg_get(core, core_cfg, blst_udp_imask);
310
+	blst_proto_imask[PROTO_TCP]=cfg_get(core, core_cfg, blst_tcp_imask);
311
+	blst_proto_imask[PROTO_TLS]=cfg_get(core, core_cfg, blst_tls_imask);
312
+	blst_proto_imask[PROTO_SCTP]=cfg_get(core, core_cfg, blst_sctp_imask);
313
+	blst_proto_imask[PROTO_NONE]=blst_proto_imask[PROTO_UDP];
314
+	return 0;
315
+}
316
+
317
+
318
+
299 319
 inline static void blst_destroy_entry(struct dst_blst_entry* e)
300 320
 {
301 321
 	shm_free(e);
... ...
@@ -478,6 +501,10 @@ int init_dst_blacklist()
478 478
 			goto error;
479 479
 		}
480 480
 	}
481
+	if (blst_init_ign_masks() < 0){
482
+		ret=E_BUG;
483
+		goto error;
484
+	}
481 485
 	return 0;
482 486
 error:
483 487
 	destroy_dst_blacklist();
... ...
@@ -1197,5 +1224,14 @@ int blst_max_mem_fixup(void *handle, str *gname, str *name, void **val)
1197 1197
 	return 0;
1198 1198
 }
1199 1199
 
1200
+
1201
+
1202
+/** re-inint per child blst_proto_ign_mask array. */
1203
+void blst_reinit_ign_masks(str* gname, str* name)
1204
+{
1205
+	blst_init_ign_masks();
1206
+}
1207
+
1208
+
1200 1209
 #endif /* USE_DST_BLACKLIST */
1201 1210
 
... ...
@@ -65,6 +65,9 @@
65 65
 #define DST_BLACKLIST_ADD_CB 1
66 66
 #define DST_BLACKLIST_SEARCH_CB 2
67 67
 
68
+
69
+extern unsigned blst_proto_imask[PROTO_LAST+1];
70
+
68 71
 #ifdef DST_BLACKLIST_HOOKS
69 72
 struct blacklist_hook{
70 73
 	/* 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,
109 109
 
110 110
 /** checks if blacklist should be used.
111 111
   * @param  err_flags - blacklist reason
112
-  * @param si - filled dst_info structure pointer.
112
+  * @param si - filled dest_info structure pointer.
113 113
   * @return 1 if blacklist is enabled (core_cfg) and the event/error
114 114
   *           is not in the ignore list.
115 115
   *         0 otherwise
116 116
   */
117 117
 #define should_blacklist(err_flags, si) \
118 118
 	(cfg_get(core, core_cfg, use_dst_blacklist) && \
119
-		((err_flags) & (si)->send_flags.blst_imask))
119
+		((err_flags) & ~blst_proto_imask[(unsigned)((si)->proto)] & \
120
+		 			   ~(si)->send_flags.blst_imask ))
120 121
 
121 122
 
122 123
 /** checks if blacklist should be used, long version.
... ...
@@ -130,7 +134,7 @@ int dst_blacklist_force_su_to(	unsigned char err_flags,
130 130
   */
131 131
 #define should_blacklist_su(err_flags, snd_flags, proto, su) \
132 132
 	(cfg_get(core, core_cfg, use_dst_blacklist) && \
133
-		((err_flags) & \
133
+		((err_flags) & ~blst_proto_imask[(unsigned)(proto)] & \
134 134
 		 			~((snd_flags)?((snd_flags_t*)(snd_flags))->blst_imask:0)))
135 135
 
136 136
 
... ...
@@ -205,4 +209,6 @@ int use_dst_blacklist_fixup(void *handle, str *gname, str *name, void **val);
205 205
 /* KByte to Byte conversion */
206 206
 int blst_max_mem_fixup(void *handle, str *gname, str *name, void **val);
207 207
 
208
+void blst_reinit_ign_masks(str* gname, str* name);
209
+
208 210
 #endif