Browse code

Destination blacklist parameters have been updated to the config framework, the following variables are changeable runtime:

- use_dst_blacklist
- dst_blacklist_expire
- dst_blacklist_mem

Miklos Tirpak authored on 13/12/2007 15:29:55
Showing 11 changed files
... ...
@@ -645,11 +645,11 @@ assign_stm:
645 645
 	| DNS_CACHE_GC_INT error { yyerror("boolean value expected"); }
646 646
 	| DNS_CACHE_DEL_NONEXP EQUAL NUMBER   { IF_DNS_CACHE(dns_cache_del_nonexp=$3); }
647 647
 	| DNS_CACHE_DEL_NONEXP error { yyerror("boolean value expected"); }
648
-	| USE_DST_BLST EQUAL NUMBER   { IF_DST_BLACKLIST(use_dst_blacklist=$3); }
648
+	| USE_DST_BLST EQUAL NUMBER   { IF_DST_BLACKLIST(default_core_cfg.use_dst_blacklist=$3); }
649 649
 	| USE_DST_BLST error { yyerror("boolean value expected"); }
650
-	| DST_BLST_MEM EQUAL NUMBER   { IF_DST_BLACKLIST(blst_max_mem=$3); }
650
+	| DST_BLST_MEM EQUAL NUMBER   { IF_DST_BLACKLIST(default_core_cfg.blst_max_mem=$3); }
651 651
 	| DST_BLST_MEM error { yyerror("boolean value expected"); }
652
-	| DST_BLST_TTL EQUAL NUMBER   { IF_DST_BLACKLIST(blst_timeout=$3); }
652
+	| DST_BLST_TTL EQUAL NUMBER   { IF_DST_BLACKLIST(default_core_cfg.blst_timeout=$3); }
653 653
 	| DST_BLST_TTL error { yyerror("boolean value expected"); }
654 654
 	| DST_BLST_GC_INT EQUAL NUMBER { IF_DST_BLACKLIST(blst_timer_interval=$3);}
655 655
 	| DST_BLST_GC_INT error { yyerror("boolean value expected"); }
... ...
@@ -30,16 +30,30 @@
30 30
  */
31 31
 
32 32
 #include "dprint.h"
33
+#include "dst_blacklist.h"
33 34
 #include "cfg/cfg.h"
34 35
 #include "cfg_core.h"
35 36
 
36 37
 struct cfg_group_core default_core_cfg = {
37
-	L_DEFAULT /*  print only msg. < L_WARN */
38
+	L_DEFAULT, /*  print only msg. < L_WARN */
39
+#ifdef USE_DST_BLACKLIST
40
+	0, /* dst blacklist is disabled by default */
41
+	DEFAULT_BLST_TIMEOUT,
42
+	DEFAULT_BLST_MAX_MEM,
43
+#endif
38 44
 };
39 45
 
40 46
 void	*core_cfg = &default_core_cfg;
41 47
 
42 48
 cfg_def_t core_cfg_def[] = {
43 49
 	{"debug",	CFG_VAR_INT,	0, 0, 0, 0, "debug level"},
50
+#ifdef USE_DST_BLACKLIST
51
+	{"use_dst_blacklist",	CFG_VAR_INT,	0, 0, 0, 0,
52
+		"enable/disable destination blacklisting"},
53
+	{"dst_blacklist_expire",	CFG_VAR_INT,	0, 0, 0, 0,
54
+		"how much time (in s) a blacklisted destination is kept in the list"},
55
+	{"dst_blacklist_mem",	CFG_VAR_INT,	0, 0, blst_max_mem_fixup, 0,
56
+		"maximum shared memory amount (in KB) used for keeping the blacklisted destinations"},
57
+#endif
44 58
 	{0, 0, 0, 0, 0, 0}
45 59
 };
... ...
@@ -46,6 +46,12 @@ extern void	*core_cfg;
46 46
 
47 47
 struct cfg_group_core {
48 48
 	int	debug;
49
+#ifdef USE_DST_BLACKLIST
50
+	int	use_dst_blacklist; /* 1 if blacklist is enabled */
51
+	unsigned int	blst_timeout; /* blacklist entry ttl */
52
+	unsigned int	blst_max_mem; /* maximum memory used for the
53
+					blacklist entries */
54
+#endif
49 55
 };
50 56
 
51 57
 extern struct cfg_group_core default_core_cfg;
... ...
@@ -40,6 +40,7 @@
40 40
 
41 41
 #include "dst_blacklist.h"
42 42
 #include "globals.h"
43
+#include "cfg_core.h"
43 44
 #include "mem/shm_mem.h"
44 45
 #include "hashes.h"
45 46
 #include "locking.h"
... ...
@@ -71,7 +72,6 @@ struct dst_blst_entry{
71 71
 
72 72
 
73 73
 #define DST_BLST_HASH_SIZE		1024
74
-#define DEFAULT_BLST_MAX_MEM	250 /* 1 Kb FIXME (debugging)*/
75 74
 #define DEFAULT_BLST_TIMER_INTERVAL		60 /* 1 min */
76 75
 
77 76
 
... ...
@@ -126,9 +126,6 @@ struct dst_blst_lst_head{
126 126
 static struct timer_ln* blst_timer_h=0;
127 127
 
128 128
 static volatile unsigned int* blst_mem_used=0;
129
-unsigned int  blst_max_mem=DEFAULT_BLST_MAX_MEM; /* maximum memory used
130
-													for the blacklist entries*/
131
-unsigned int blst_timeout=DEFAULT_BLST_TIMEOUT;
132 129
 unsigned int blst_timer_interval=DEFAULT_BLST_TIMER_INTERVAL;
133 130
 struct dst_blst_lst_head* dst_blst_hash=0;
134 131
 
... ...
@@ -452,7 +449,7 @@ int init_dst_blacklist()
452 452
 		goto error;
453 453
 	}
454 454
 	/* fix options */
455
-	blst_max_mem<<=10; /* in Kb */ /* TODO: test with 0 */
455
+	default_core_cfg.blst_max_mem<<=10; /* in Kb */ /* TODO: test with 0 */
456 456
 	if (blst_timer_interval){
457 457
 		timer_init(blst_timer_h, blst_timer, 0 ,0); /* slow timer */
458 458
 		if (timer_add(blst_timer_h, S_TO_TICKS(blst_timer_interval))<0){
... ...
@@ -691,7 +688,8 @@ inline static int dst_blacklist_add_ip(unsigned char err_flags,
691 691
 			e->flags|=err_flags;
692 692
 			e->expire=now+timeout; /* update the timeout */
693 693
 		}else{
694
-			if (unlikely((*blst_mem_used+size)>=blst_max_mem)){
694
+			if (unlikely((*blst_mem_used+size) >=
695
+					cfg_get(core, core_cfg, blst_max_mem))){
695 696
 #ifdef USE_DST_BLACKLIST_STATS
696 697
 				dst_blacklist_stats[process_no].bkl_lru_cnt++;
697 698
 #endif
... ...
@@ -700,7 +698,8 @@ inline static int dst_blacklist_add_ip(unsigned char err_flags,
700 700
 				 * spend more then 250 ms*/
701 701
 				dst_blacklist_clean_expired(*blst_mem_used/16*14, 0,
702 702
 															MS_TO_TICKS(250));
703
-				if (unlikely(*blst_mem_used+size>=blst_max_mem)){
703
+				if (unlikely(*blst_mem_used+size >=
704
+						cfg_get(core, core_cfg, blst_max_mem))){
704 705
 					ret=-1;
705 706
 					goto error;
706 707
 				}
... ...
@@ -829,11 +828,11 @@ int dst_blacklist_del(struct dest_info* si, struct sip_msg* msg)
829 829
 /* rpc functions */
830 830
 void dst_blst_mem_info(rpc_t* rpc, void* ctx)
831 831
 {
832
-	if (!use_dst_blacklist){
832
+	if (!cfg_get(core, core_cfg, use_dst_blacklist)){
833 833
 		rpc->fault(ctx, 500, "dst blacklist support disabled");
834 834
 		return;
835 835
 	}
836
-	rpc->add(ctx, "dd",  *blst_mem_used, blst_max_mem);
836
+	rpc->add(ctx, "dd",  *blst_mem_used, cfg_get(core, core_cfg, blst_max_mem));
837 837
 }
838 838
 
839 839
 
... ...
@@ -891,7 +890,7 @@ void dst_blst_stats_get(rpc_t* rpc, void* c)
891 891
 		NULL
892 892
 	};
893 893
 	
894
-	if (!use_dst_blacklist){
894
+	if (!cfg_get(core, core_cfg, use_dst_blacklist)){
895 895
 		rpc->fault(c, 500, "dst blacklist support disabled");
896 896
 		return;
897 897
 	}
... ...
@@ -934,7 +933,7 @@ void dst_blst_debug(rpc_t* rpc, void* ctx)
934 934
 	ticks_t now;
935 935
 	struct ip_addr ip;
936 936
 
937
-	if (!use_dst_blacklist){
937
+	if (!cfg_get(core, core_cfg, use_dst_blacklist)){
938 938
 		rpc->fault(ctx, 500, "dst blacklist support disabled");
939 939
 		return;
940 940
 	}
... ...
@@ -964,7 +963,7 @@ void dst_blst_hash_stats(rpc_t* rpc, void* ctx)
964 964
 
965 965
 	n=0;
966 966
 #endif
967
-	if (!use_dst_blacklist){
967
+	if (!cfg_get(core, core_cfg, use_dst_blacklist)){
968 968
 		rpc->fault(ctx, 500, "dst blacklist support disabled");
969 969
 		return;
970 970
 	}
... ...
@@ -989,7 +988,7 @@ void dst_blst_view(rpc_t* rpc, void* ctx)
989 989
 	ticks_t now;
990 990
 	struct ip_addr ip;
991 991
 
992
-	if (!use_dst_blacklist){
992
+	if (!cfg_get(core, core_cfg, use_dst_blacklist)){
993 993
 		rpc->fault(ctx, 500, "dst blacklist support disabled");
994 994
 		return;
995 995
 	}
... ...
@@ -1046,7 +1045,7 @@ void dst_blst_flush(void)
1046 1046
 /* rpc wrapper function for dst_blst_flush() */
1047 1047
 void dst_blst_delete_all(rpc_t* rpc, void* ctx)
1048 1048
 {
1049
-	if (!use_dst_blacklist){
1049
+	if (!cfg_get(core, core_cfg, use_dst_blacklist)){
1050 1050
 		rpc->fault(ctx, 500, "dst blacklist support disabled");
1051 1051
 		return;
1052 1052
 	}
... ...
@@ -1061,7 +1060,7 @@ void dst_blst_add(rpc_t* rpc, void* ctx)
1061 1061
 	unsigned char err_flags;
1062 1062
 	struct ip_addr *ip_addr;
1063 1063
 
1064
-	if (!use_dst_blacklist){
1064
+	if (!cfg_get(core, core_cfg, use_dst_blacklist)){
1065 1065
 		rpc->fault(ctx, 500, "dst blacklist support disabled");
1066 1066
 		return;
1067 1067
 	}
... ...
@@ -1092,9 +1091,19 @@ void dst_blst_add(rpc_t* rpc, void* ctx)
1092 1092
 	}
1093 1093
 
1094 1094
 	if (dst_blacklist_add_ip(err_flags, proto, ip_addr, port, 
1095
-											S_TO_TICKS(blst_timeout)))
1095
+				    S_TO_TICKS(cfg_get(core, core_cfg, blst_timeout))))
1096 1096
 		rpc->fault(ctx, 400, "Failed to add the entry to the blacklist");
1097 1097
 }
1098 1098
 
1099
+/* KByte to Byte conversion */
1100
+int blst_max_mem_fixup(void *handle, str *name, void **val)
1101
+{
1102
+	unsigned int	u;
1103
+
1104
+	u = ((unsigned int)(long)(*val))<<10;
1105
+	(*val) = (void *)(long)u;
1106
+	return 0;
1107
+}
1108
+
1099 1109
 #endif /* USE_DST_BLACKLIST */
1100 1110
 
... ...
@@ -38,8 +38,10 @@
38 38
 #include "ip_addr.h"
39 39
 #include "parser/msg_parser.h"
40 40
 #include "timer_ticks.h"
41
+#include "cfg_core.h"
41 42
 
42 43
 #define DEFAULT_BLST_TIMEOUT		60  /* 1 min. */
44
+#define DEFAULT_BLST_MAX_MEM		250 /* 250 KB */
43 45
 
44 46
 /* flags: */
45 47
 #define BLST_IS_IPV6		1		/* set if the address is ipv6 */
... ...
@@ -89,7 +91,8 @@ int dst_blacklist_add_to(unsigned char err_flags, struct dest_info* si,
89 89
 
90 90
 /* adds a dst to the blacklist with default timeout */
91 91
 #define dst_blacklist_add(err_flags, si, msg) \
92
-	dst_blacklist_add_to((err_flags), (si), (msg), S_TO_TICKS(blst_timeout))
92
+	dst_blacklist_add_to((err_flags), (si), (msg), \
93
+		S_TO_TICKS(cfg_get(core, core_cfg, blst_timeout)))
93 94
 
94 95
 int dst_is_blacklisted(struct dest_info* si, struct sip_msg* msg);
95 96
 /* delete an entry from the blacklist */
... ...
@@ -100,4 +103,7 @@ int dst_blacklist_del(struct dest_info* si, struct sip_msg* msg);
100 100
  */
101 101
 void dst_blst_flush(void);
102 102
 
103
+/* KByte to Byte conversion */
104
+int blst_max_mem_fixup(void *handle, str *name, void **val);
105
+
103 106
 #endif
... ...
@@ -74,6 +74,7 @@
74 74
 #include "route.h"
75 75
 #include "dprint.h"
76 76
 #include "globals.h"
77
+#include "cfg_core.h"
77 78
 #include "data_lump.h"
78 79
 #include "ut.h"
79 80
 #include "mem/mem.h"
... ...
@@ -419,7 +420,7 @@ int forward_request(struct sip_msg* msg, str* dst, unsigned short port,
419 419
 #endif
420 420
 		}
421 421
 #ifdef USE_DST_BLACKLIST
422
-		if (use_dst_blacklist){
422
+		if (cfg_get(core, core_cfg, use_dst_blacklist)){
423 423
 			if (dst_is_blacklisted(send_info, msg)){
424 424
 				su2ip_addr(&ip, &send_info->to);
425 425
 				LOG(L_DBG, "DEBUG: blacklisted destination:%s:%d (%d)\n",
... ...
@@ -437,7 +438,7 @@ int forward_request(struct sip_msg* msg, str* dst, unsigned short port,
437 437
 		if (msg_send(send_info, buf, len)<0){
438 438
 			ret=ser_error=E_SEND;
439 439
 #ifdef USE_DST_BLACKLIST
440
-			if (use_dst_blacklist)
440
+			if (cfg_get(core, core_cfg, use_dst_blacklist))
441 441
 				dst_blacklist_add(BLST_ERR_SEND, send_info, msg);
442 442
 #endif
443 443
 #ifdef USE_DNS_FAILOVER
... ...
@@ -222,10 +222,6 @@ extern struct t_dns_cache_stats* dns_cache_stats;
222 222
 #endif /* USE_DNS_CACHE_STATS */
223 223
 #endif
224 224
 #ifdef USE_DST_BLACKLIST
225
-extern int use_dst_blacklist; /* 1 if the blacklist is enabled */
226
-extern unsigned int  blst_max_mem; /* maximum memory used for the blacklist
227
-									  entries*/
228
-extern unsigned int blst_timeout; /* blacklist entry ttl */
229 225
 extern unsigned int blst_timer_interval; /*blacklist gc timer interval (in s)*/
230 226
 
231 227
 #ifdef USE_DST_BLACKLIST_STATS
... ...
@@ -375,9 +375,6 @@ int mcast_ttl = -1; /* if -1, don't touch it, use the default (usually 1) */
375 375
 int use_dns_cache=1; /* 1 if the cache is enabled, 0 otherwise */
376 376
 int use_dns_failover=0; /* 1 if failover is enabled, 0 otherwise */
377 377
 #endif
378
-#ifdef USE_DST_BLACKLIST
379
-int use_dst_blacklist=0; /* 1 if the blacklist is enabled */
380
-#endif
381 378
 
382 379
 int tos = IPTOS_LOWDELAY;
383 380
 int pmtu_discovery = 0;
... ...
@@ -84,6 +84,7 @@
84 84
 #include "../../timer.h"
85 85
 #include "../../hash_func.h"
86 86
 #include "../../globals.h"
87
+#include "../../cfg_core.h"
87 88
 #include "../../mem/mem.h"
88 89
 #include "../../dset.h"
89 90
 #include "../../action.h"
... ...
@@ -690,7 +691,7 @@ int t_send_branch( struct cell *t, int branch, struct sip_msg* p_msg ,
690 690
 		return -1; /* drop, try next branch */
691 691
 	}
692 692
 #ifdef USE_DST_BLACKLIST
693
-	if (use_dst_blacklist
693
+	if (cfg_get(core, core_cfg, use_dst_blacklist)
694 694
 		&& p_msg
695 695
 		&& (p_msg->REQ_METHOD & tm_blst_methods_lookup)
696 696
 	){
... ...
@@ -737,7 +738,7 @@ int t_send_branch( struct cell *t, int branch, struct sip_msg* p_msg ,
737 737
 							ip_addr2a(&ip), su_getport(&uac->request.dst.to),
738 738
 							uac->request.dst.proto);
739 739
 #ifdef USE_DST_BLACKLIST
740
-		if (use_dst_blacklist)
740
+		if (cfg_get(core, core_cfg, use_dst_blacklist))
741 741
 			dst_blacklist_add(BLST_ERR_SEND, &uac->request.dst, p_msg);
742 742
 #endif
743 743
 #ifdef USE_DNS_FAILOVER
... ...
@@ -1806,7 +1806,7 @@ int reply_received( struct sip_msg  *p_msg )
1806 1806
 	}
1807 1807
 #ifdef USE_DST_BLACKLIST
1808 1808
 		/* add temporary to the blacklist the source of a 503 reply */
1809
-		if (tm_blst_503 && use_dst_blacklist && (msg_status==503)){
1809
+		if (tm_blst_503 && cfg_get(core, core_cfg, use_dst_blacklist) && (msg_status==503)){
1810 1810
 			blst_503_timeout=tm_blst_503_default;
1811 1811
 			if ((parse_headers(p_msg, HDR_RETRY_AFTER_F, 0)==0) && 
1812 1812
 				(p_msg->parsed_flag & HDR_RETRY_AFTER_F)){
... ...
@@ -455,7 +455,7 @@ inline static void final_response_handler(	struct retr_buf* r_buf,
455 455
 			(t->uac[r_buf->branch].last_received==0)){
456 456
 		/* no reply received */
457 457
 #ifdef USE_DST_BLACKLIST
458
-		if (use_dst_blacklist
458
+		if (cfg_get(core, core_cfg, use_dst_blacklist)
459 459
         		&& r_buf->my_T
460 460
 			&& r_buf->my_T->uas.request
461 461
 			&& (r_buf->my_T->uas.request->REQ_METHOD & tm_blst_methods_add)