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 118
 	{"dst_blacklist_expire",	CFG_VAR_INT,	0, 0, 0, 0,
115 119
 		"how much time (in s) a blacklisted destination is kept in the list"},
116 120
 	{"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"},
121
+		"maximum shared memory amount (in KB) used for keeping the blacklisted"
122
+			" destinations"},
123
+	{"dst_blacklist_udp_imask", CFG_VAR_INT, 0, 0, 0, blst_reinit_ign_masks,
124
+		"blacklist event ignore mask for UDP"},
125
+	{"dst_blacklist_tcp_imask", CFG_VAR_INT, 0, 0, 0, blst_reinit_ign_masks,
126
+		"blacklist event ignore mask for TCP"},
127
+	{"dst_blacklist_tls_imask", CFG_VAR_INT, 0, 0, 0, blst_reinit_ign_masks,
128
+		"blacklist event ignore mask for TLS"},
129
+	{"dst_blacklist_sctp_imask", CFG_VAR_INT, 0, 0, 0, blst_reinit_ign_masks,
130
+		"blacklist event ignore mask for SCTP"},
118 131
 #endif
119 132
 	/* resolver */
120 133
 #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 299
 #endif /* DST_BLACKLIST_HOOKS */
297 300
 
298 301
 
302
+/** init per protocol blacklist event ignore masks.
303
+ * @return 0 on success, < 0 on error.
304
+ */
305
+int blst_init_ign_masks()
306
+{
307
+	if ((PROTO_UDP > PROTO_LAST) || (PROTO_TCP > PROTO_LAST) ||
308
+		(PROTO_TLS > PROTO_LAST) || (PROTO_SCTP > PROTO_LAST)){
309
+		BUG("protocol array too small\n");
310
+		return -1;
311
+	}
312
+	blst_proto_imask[PROTO_UDP]=cfg_get(core, core_cfg, blst_udp_imask);
313
+	blst_proto_imask[PROTO_TCP]=cfg_get(core, core_cfg, blst_tcp_imask);
314
+	blst_proto_imask[PROTO_TLS]=cfg_get(core, core_cfg, blst_tls_imask);
315
+	blst_proto_imask[PROTO_SCTP]=cfg_get(core, core_cfg, blst_sctp_imask);
316
+	blst_proto_imask[PROTO_NONE]=blst_proto_imask[PROTO_UDP];
317
+	return 0;
318
+}
319
+
320
+
321
+
299 322
 inline static void blst_destroy_entry(struct dst_blst_entry* e)
300 323
 {
301 324
 	shm_free(e);
... ...
@@ -478,6 +501,10 @@ int init_dst_blacklist()
478 501
 			goto error;
479 502
 		}
480 503
 	}
504
+	if (blst_init_ign_masks() < 0){
505
+		ret=E_BUG;
506
+		goto error;
507
+	}
481 508
 	return 0;
482 509
 error:
483 510
 	destroy_dst_blacklist();
... ...
@@ -1197,5 +1224,14 @@ int blst_max_mem_fixup(void *handle, str *gname, str *name, void **val)
1197 1224
 	return 0;
1198 1225
 }
1199 1226
 
1227
+
1228
+
1229
+/** re-inint per child blst_proto_ign_mask array. */
1230
+void blst_reinit_ign_masks(str* gname, str* name)
1231
+{
1232
+	blst_init_ign_masks();
1233
+}
1234
+
1235
+
1200 1236
 #endif /* USE_DST_BLACKLIST */
1201 1237
 
... ...
@@ -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 112
 
110 113
 /** checks if blacklist should be used.
111 114
   * @param  err_flags - blacklist reason
112
-  * @param si - filled dst_info structure pointer.
115
+  * @param si - filled dest_info structure pointer.
113 116
   * @return 1 if blacklist is enabled (core_cfg) and the event/error
114 117
   *           is not in the ignore list.
115 118
   *         0 otherwise
116 119
   */
117 120
 #define should_blacklist(err_flags, si) \
118 121
 	(cfg_get(core, core_cfg, use_dst_blacklist) && \
119
-		((err_flags) & (si)->send_flags.blst_imask))
122
+		((err_flags) & ~blst_proto_imask[(unsigned)((si)->proto)] & \
123
+		 			   ~(si)->send_flags.blst_imask ))
120 124
 
121 125
 
122 126
 /** checks if blacklist should be used, long version.
... ...
@@ -130,7 +134,7 @@ int dst_blacklist_force_su_to(	unsigned char err_flags,
130 134
   */
131 135
 #define should_blacklist_su(err_flags, snd_flags, proto, su) \
132 136
 	(cfg_get(core, core_cfg, use_dst_blacklist) && \
133
-		((err_flags) & \
137
+		((err_flags) & ~blst_proto_imask[(unsigned)(proto)] & \
134 138
 		 			~((snd_flags)?((snd_flags_t*)(snd_flags))->blst_imask:0)))
135 139
 
136 140
 
... ...
@@ -205,4 +209,6 @@ int use_dst_blacklist_fixup(void *handle, str *gname, str *name, void **val);
205 209
 /* KByte to Byte conversion */
206 210
 int blst_max_mem_fixup(void *handle, str *gname, str *name, void **val);
207 211
 
212
+void blst_reinit_ign_masks(str* gname, str* name);
213
+
208 214
 #endif