Browse code

- dst blacklist and DNS cache measurements added

Gergely Kovacs authored on 31/07/2007 13:26:05
Showing 4 changed files
... ...
@@ -61,6 +61,7 @@
61 61
 #               -flat_namespace -undefined suppress) (andrei)
62 62
 #  2007-07-07  added HAVE_SCHED_SETSCHEDULER for linux (andrei)
63 63
 #  2007-07-18  added DNS_WATCHDOG_SUPPORT (Miklos)
64
+#  2007-07-30  added USE_DNS_CACHE_STATS and USE_DST_BLACKLIST_STATS (Gergo)
64 65
 
65 66
 # check if already included/exported
66 67
 
... ...
@@ -388,12 +389,16 @@ endif
388 388
 #		which (mis)uses this parameter.
389 389
 # -DUSE_DNS_CACHE
390 390
 #		use an internal dns cache instead of making dns requests each time
391
+# -DUSE_DNS_CACHE_STATS
392
+#		turns on DNS cache measurements
391 393
 # -DUSE_DNS_FAILOVER
392 394
 #		if the destination resolves to multiple ips, on send error fall back
393 395
 #		to the others
394 396
 # -DUSE_DST_BLACKLIST
395 397
 #		blacklist bad destination (timeout, failed to connect, error sending
396 398
 #        a.s.o)
399
+# -DUSE_DST_BLACKLIST_STATS
400
+#		turns on blacklist bad destination measurements
397 401
 # -DPROFILING
398 402
 #		if enabled profiling will be enabled for child processes
399 403
 #		Don't forget to set PROFILE (see below)
... ...
@@ -409,7 +414,6 @@ endif
409 409
 #		core that the DNS servers are down. No DNS query is performed
410 410
 #		when the servers are unreachable, and even expired resource
411 411
 #		records are used from the cache. (requires external watchdog)
412
-
413 412
 # Sometimes is needes correct non-quoted $OS. HACK: gcc translates known OS to number ('linux'), so there is added underscore
414 413
 
415 414
 DEFS+= $(extra_defs) \
... ...
@@ -429,6 +433,8 @@ DEFS+= $(extra_defs) \
429 429
 	 -DUSE_DNS_FAILOVER \
430 430
 	 -DUSE_DST_BLACKLIST \
431 431
 	 -DUSE_NAPTR \
432
+	 #-DUSE_DNS_CACHE_STATS \
433
+	 #-DUSE_DST_BLACKLIST_STATS \
432 434
 	 #-DDNS_WATCHDOG_SUPPORT \
433 435
 	 #-DLL_MALLOC \
434 436
 	 #-DSF_MALLOC \
... ...
@@ -106,6 +106,14 @@ static const char* dns_cache_delete_srv_doc[] = {
106 106
 	0
107 107
 };
108 108
 
109
+#ifdef USE_DNS_CACHE_STATS
110
+void dns_cache_stats_get(rpc_t* rpc, void* ctx);
111
+
112
+static const char* dns_cache_stats_get_doc[] = {
113
+	"returns the dns measurement counters.",
114
+	0
115
+};
116
+#endif /* USE_DNS_CACHE_STATS */
109 117
 #ifdef DNS_WATCHDOG_SUPPORT
110 118
 void dns_set_server_state_rpc(rpc_t* rpc, void* ctx);
111 119
 
... ...
@@ -143,6 +151,14 @@ static const char* dst_blst_add_doc[] = {
143 143
 	"Adds a new entry to the dst blacklist.",  /* Documentation string */
144 144
 	0                               /* Method signature(s) */
145 145
 };
146
+#ifdef USE_DST_BLACKLIST_STATS
147
+void dst_blst_stats_get(rpc_t* rpc, void* ctx);
148
+
149
+static const char* dst_blst_stats_get_doc[] = {
150
+	"returns the dst blacklist measurement counters.",
151
+	0
152
+};
153
+#endif /* USE_DST_BLACKLIST_STATS */
146 154
 
147 155
 #endif
148 156
 
... ...
@@ -489,6 +505,7 @@ static const char* core_sfmalloc_doc[] = {
489 489
 	"Returns sfmalloc debugging  info.",  /* Documentation string */
490 490
 	0                                     /* Method signature(s) */
491 491
 };
492
+
492 493
 #endif
493 494
 
494 495
 
... ...
@@ -503,7 +520,7 @@ static void core_tcpinfo(rpc_t* rpc, void* c)
503 503
 	void *handle;
504 504
 #ifdef USE_TCP
505 505
 	struct tcp_gen_info ti;
506
-	
506
+
507 507
 	if (!tcp_disable){
508 508
 		tcp_get_info(&ti);
509 509
 		rpc->add(c, "{", &handle);
... ...
@@ -551,6 +568,9 @@ rpc_export_t core_rpc_methods[] = {
551 551
 	{"dns.delete_a",           dns_cache_delete_a,    dns_cache_delete_a_doc,    0	},
552 552
 	{"dns.delete_aaaa",        dns_cache_delete_aaaa, dns_cache_delete_aaaa_doc, 0	},
553 553
 	{"dns.delete_srv",         dns_cache_delete_srv,  dns_cache_delete_srv_doc,  0	},
554
+#ifdef USE_DNS_CACHE_STATS
555
+	{"dns.stats_get",    dns_cache_stats_get,   dns_cache_stats_get_doc,        0	},
556
+#endif /* USE_DNS_CACHE_STATS */
554 557
 #ifdef DNS_WATCHDOG_SUPPORT
555 558
 	{"dns.set_server_state",   dns_set_server_state_rpc, dns_set_server_state_doc, 0 },
556 559
 #endif
... ...
@@ -561,6 +581,9 @@ rpc_export_t core_rpc_methods[] = {
561 561
 	{"dst_blacklist.view",     dst_blst_view,         dst_blst_view_doc,         0	},
562 562
 	{"dst_blacklist.delete_all", dst_blst_delete_all, dst_blst_delete_all_doc,   0	},
563 563
 	{"dst_blacklist.add",      dst_blst_add,          dst_blst_add_doc,          0	},
564
+#ifdef USE_DST_BLACKLIST_STATS
565
+	{"dst_blacklist.stats_get", dst_blst_stats_get, dst_blst_stats_get_doc, 0 },
566
+#endif /* USE_DST_BLACKLIST_STATS */
564 567
 #endif
565 568
 	{0, 0, 0, 0}
566 569
 };
... ...
@@ -23,8 +23,8 @@
23 23
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 24
  * GNU General Public License for more details.
25 25
  *
26
- * You should have received a copy of the GNU General Public License 
27
- * along with this program; if not, write to the Free Software 
26
+ * You should have received a copy of the GNU General Public License
27
+ * along with this program; if not, write to the Free Software
28 28
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
29 29
  */
30 30
 
... ...
@@ -179,7 +179,7 @@ extern int shm_force_alloc;
179 179
 extern int mlock_pages;
180 180
 
181 181
 /* real time stuff */
182
-extern int real_time; 
182
+extern int real_time;
183 183
 extern int rt_prio;
184 184
 extern int rt_policy; /* SCHED_OTHER */
185 185
 extern int rt_timer1_prio;  /* "fast" timer */
... ...
@@ -197,23 +197,40 @@ extern int dns_search_list;
197 197
 #ifdef USE_DNS_CACHE
198 198
 extern int use_dns_cache; /* 1 if the cache is enabled, 0 otherwise */
199 199
 extern int use_dns_failover; /* 1 if failover is enabled, 0 otherwise */
200
-extern unsigned int dns_cache_max_mem; /* maximum memory used for the cached 
200
+extern unsigned int dns_cache_max_mem; /* maximum memory used for the cached
201 201
 										  entries*/
202 202
 extern unsigned int dns_neg_cache_ttl; /* neg. cache ttl */
203 203
 extern unsigned int dns_cache_max_ttl; /* maximum ttl */
204 204
 extern unsigned int dns_cache_min_ttl; /* minimum ttl */
205 205
 extern unsigned int dns_timer_interval; /* gc timer interval in s */
206
-extern int dns_flags; /* default flags used for the  dns_*resolvehost 
206
+extern int dns_flags; /* default flags used for the  dns_*resolvehost
207 207
                     (compatibility wrappers) */
208 208
 extern int dns_srv_lb; /* default SRV LB support value */
209 209
 
210
+#ifdef USE_DNS_CACHE_STATS
211
+struct t_dns_cache_stats{
212
+	unsigned long dns_req_cnt;
213
+	unsigned long dc_hits_cnt;
214
+	unsigned long dc_neg_hits_cnt;
215
+	unsigned long dc_lru_cnt;
216
+};
217
+extern struct t_dns_cache_stats* dns_cache_stats;
218
+#endif /* USE_DNS_CACHE_STATS */
210 219
 #endif
211 220
 #ifdef USE_DST_BLACKLIST
212 221
 extern int use_dst_blacklist; /* 1 if the blacklist is enabled */
213
-extern unsigned int  blst_max_mem; /* maximum memory used for the blacklist 
222
+extern unsigned int  blst_max_mem; /* maximum memory used for the blacklist
214 223
 									  entries*/
215 224
 extern unsigned int blst_timeout; /* blacklist entry ttl */
216 225
 extern unsigned int blst_timer_interval; /*blacklist gc timer interval (in s)*/
226
+
227
+#ifdef USE_DST_BLACKLIST_STATS
228
+struct t_dst_blacklist_stats{
229
+	unsigned long bkl_hit_cnt;
230
+	unsigned long bkl_lru_cnt;
231
+};
232
+extern struct t_dst_blacklist_stats* dst_blacklist_stats;
233
+#endif /* USE_DST_BLACKLIST_STATS */
217 234
 #endif
218 235
 
219 236
 #endif
... ...
@@ -70,10 +70,11 @@
70 70
  *               tcp usage for module started processes (andrei)
71 71
  * 2007-01-18  children shutdown procedure moved into shutdown_children;
72 72
  *               safer shutdown on start-up error (andrei)
73
- * 2007-02-09  TLS support split into tls-in-core (CORE_TLS) and generic TLS 
73
+ * 2007-02-09  TLS support split into tls-in-core (CORE_TLS) and generic TLS
74 74
  *             (USE_TLS)  (andrei)
75 75
  * 2007-06-07  added support for locking pages in mem. and using real time
76 76
  *              scheduling policies (andrei)
77
+ * 2007-07-30  dst blacklist and DNS cache measurements added (Gergo)
77 78
  */
78 79
 
79 80
 
... ...
@@ -279,7 +280,7 @@ int tls_disable = 1;  /* tls disabled by default */
279 279
 
280 280
 struct process_table *pt=0;		/*array with children pids, 0= main proc,
281 281
 									alloc'ed in shared mem if possible*/
282
-int *process_count = 0;			/* Total number of SER processes currently 
282
+int *process_count = 0;			/* Total number of SER processes currently
283 283
 								   running */
284 284
 gen_lock_t* process_lock;		/* lock on the process table */
285 285
 int process_no = 0;				/* index of process in the pt */
... ...
@@ -343,7 +344,7 @@ int mlock_pages=0; /* default off, try to disable swapping */
343 343
 /* real time options */
344 344
 int real_time=0; /* default off, flags: 1 on only timer, 2  slow timer,
345 345
 					                    4 all procs (7=all) */
346
-int rt_prio=0;  
346
+int rt_prio=0;
347 347
 int rt_policy=0; /* SCHED_OTHER */
348 348
 int rt_timer1_prio=0;  /* "fast" timer */
349 349
 int rt_timer2_prio=0;  /* "slow" timer */
... ...
@@ -522,7 +523,7 @@ static void kill_all_children(int signum)
522 522
 		  * (only main can add processes, so from main is safe not to lock
523 523
 		  *  and moreover it avoids the lock-holding suicidal children problem)
524 524
 		  */
525
-		if (!is_main) lock_get(process_lock); 
525
+		if (!is_main) lock_get(process_lock);
526 526
 		for (r=1; r<*process_count; r++){
527 527
 			if (r==process_no) continue; /* try not to be suicidal */
528 528
 			if (pt[r].pid) {
... ...
@@ -569,7 +570,7 @@ static void shutdown_children(int sig, int show_status)
569 569
 		 * alarm is installed which is exactly what we want */
570 570
 	}
571 571
 	alarm(ser_kill_timeout);
572
-	while((wait(0) > 0) || (errno==EINTR)); /* wait for all the 
572
+	while((wait(0) > 0) || (errno==EINTR)); /* wait for all the
573 573
 											   children to terminate*/
574 574
 	set_sig_h(SIGALRM, sig_alarm_abort);
575 575
 	cleanup(show_status); /* cleanup & show status*/
... ...
@@ -915,12 +916,12 @@ int main_loop()
915 915
 		   as new processes are forked (while skipping 0 reserved for main
916 916
 		*/
917 917
 
918
-		/* init childs with rank==PROC_INIT before forking any process, 
918
+		/* init childs with rank==PROC_INIT before forking any process,
919 919
 		 * this is a place for delayed (after mod_init) initializations
920 920
 		 * (e.g. shared vars that depend on the total number of processes
921 921
 		 * that is known only after all mod_inits have been executed )
922 922
 		 * WARNING: the same init_child will be called latter, a second time
923
-		 * for the "main" process with rank PROC_MAIN (make sure things are 
923
+		 * for the "main" process with rank PROC_MAIN (make sure things are
924 924
 		 * not initialized twice)*/
925 925
 		if (init_child(PROC_INIT) < 0) {
926 926
 			LOG(L_ERR, "ERROR: main_dontfork: init_child(PROC_INT) --"
... ...
@@ -941,7 +942,7 @@ int main_loop()
941 941
 					/* process_bit = 0; */
942 942
 					if (real_time&2)
943 943
 						set_rt_prio(rt_timer2_prio, rt_timer2_policy);
944
-					
944
+
945 945
 					if (arm_slow_timer()<0) goto error;
946 946
 					slow_timer_main();
947 947
 				}else{
... ...
@@ -971,7 +972,7 @@ int main_loop()
971 971
 		snprintf(pt[process_no].desc, MAX_PT_DESC,
972 972
 			"stand-alone receiver @ %s:%s",
973 973
 			 bind_address->name.s, bind_address->port_no_str.s );
974
-	
974
+
975 975
 	/* call it also w/ PROC_MAIN to make sure modules that init things only
976 976
 	 * in PROC_MAIN get a chance to run */
977 977
 	if (init_child(PROC_MAIN) < 0) {
... ...
@@ -1041,12 +1042,12 @@ int main_loop()
1041 1041
 			 * so we open all first*/
1042 1042
 		if (do_suid()==-1) goto error; /* try to drop privileges */
1043 1043
 
1044
-		/* init childs with rank==PROC_INIT before forking any process, 
1044
+		/* init childs with rank==PROC_INIT before forking any process,
1045 1045
 		 * this is a place for delayed (after mod_init) initializations
1046 1046
 		 * (e.g. shared vars that depend on the total number of processes
1047 1047
 		 * that is known only after all mod_inits have been executed )
1048 1048
 		 * WARNING: the same init_child will be called latter, a second time
1049
-		 * for the "main" process with rank PROC_MAIN (make sure things are 
1049
+		 * for the "main" process with rank PROC_MAIN (make sure things are
1050 1050
 		 * not initialized twice)*/
1051 1051
 		if (init_child(PROC_INIT) < 0) {
1052 1052
 			LOG(L_ERR, "ERROR: main: error in init_child(PROC_INT) --"
... ...
@@ -1059,7 +1060,7 @@ int main_loop()
1059 1059
 		for(si=udp_listen; si; si=si->next){
1060 1060
 			for(i=0;i<children_no;i++){
1061 1061
 				snprintf(si_desc, MAX_PT_DESC, "receiver child=%d sock=%s:%s",
1062
-					i, si->name.s, si->port_no_str.s);	
1062
+					i, si->name.s, si->port_no_str.s);
1063 1063
 				child_rank++;
1064 1064
 				pid = fork_process(child_rank, si_desc, 1);
1065 1065
 				if (pid<0){
... ...
@@ -1115,7 +1116,7 @@ int main_loop()
1115 1115
 		}
1116 1116
 	}
1117 1117
 
1118
-/* init childs with rank==MAIN before starting tcp main (in case they want to 
1118
+/* init childs with rank==MAIN before starting tcp main (in case they want to
1119 1119
  *  fork  a tcp capable process, the corresponding tcp. comm. fds in pt[] must
1120 1120
  *  be set before calling tcp_main_loop()) */
1121 1121
 	if (init_child(PROC_MAIN) < 0) {
... ...
@@ -1321,7 +1322,7 @@ int main(int argc, char** argv)
1321 1321
 					abort();
1322 1322
 		}
1323 1323
 	}
1324
-	
1324
+
1325 1325
 	if (init_routes()<0) goto error;
1326 1326
 	if (init_nonsip_hooks()<0) goto error;
1327 1327
 	/* fill missing arguments with the default values*/
... ...
@@ -1586,12 +1587,26 @@ try_again:
1586 1586
 	}
1587 1587
 	if (use_dns_cache==0)
1588 1588
 		use_dns_failover=0; /* cannot work w/o dns_cache support */
1589
+#ifdef USE_DNS_CACHE_STATS
1590
+	/* preinitializing before the nubmer of processes is determined */
1591
+	if (init_dns_cache_stats(1)<0){
1592
+		LOG(L_CRIT, "could not initialize the dns cache measurement\n");
1593
+		goto error;
1594
+	}
1595
+#endif /* USE_DNS_CACHE_STATS */
1589 1596
 #endif
1590 1597
 #ifdef USE_DST_BLACKLIST
1591 1598
 	if (init_dst_blacklist()<0){
1592 1599
 		LOG(L_CRIT, "could not initialize the dst blacklist, exiting...\n");
1593 1600
 		goto error;
1594 1601
 	}
1602
+#ifdef USE_DST_BLACKLIST_STATS
1603
+	/* preinitializing before the nubmer of processes is determined */
1604
+	if (init_dst_blacklist_stats(1)<0){
1605
+		LOG(L_CRIT, "could not initialize the dst blacklist measurement\n");
1606
+		goto error;
1607
+	}
1608
+#endif /* USE_DST_BLACKLIST_STATS */
1595 1609
 #endif
1596 1610
 	if (init_avps()<0) goto error;
1597 1611
 	if (rpc_init_time() < 0) goto error;
... ...
@@ -1624,15 +1639,15 @@ try_again:
1624 1624
 	}
1625 1625
 	if (mlock_pages)
1626 1626
 		mem_lock_pages();
1627
-	
1627
+
1628 1628
 	if (real_time&4)
1629 1629
 			set_rt_prio(rt_prio, rt_policy);
1630
-	
1630
+
1631 1631
 	if (init_modules() != 0) {
1632 1632
 		fprintf(stderr, "ERROR: error while initializing modules\n");
1633 1633
 		goto error;
1634 1634
 	}
1635
-	/* initialize process_table, add core process no. (calc_proc_no()) to the 
1635
+	/* initialize process_table, add core process no. (calc_proc_no()) to the
1636 1636
 	 * processes registered from the modules*/
1637 1637
 	if (init_pt(calc_proc_no())==-1)
1638 1638
 		goto error;
... ...
@@ -1653,7 +1668,7 @@ try_again:
1653 1653
 	}
1654 1654
 #endif /* USE_TLS */
1655 1655
 #endif /* USE_TCP */
1656
-	
1656
+
1657 1657
 	/* The total number of processes is now known, note that no
1658 1658
 	 * function being called before this point may rely on the
1659 1659
 	 * number of processes !
... ...
@@ -1661,6 +1676,19 @@ try_again:
1661 1661
 	DBG("Expect (at least) %d SER processes in your process list\n",
1662 1662
 			get_max_procs());
1663 1663
 
1664
+#if defined USE_DNS_CACHE && defined USE_DNS_CACHE_STATS
1665
+	if (init_dns_cache_stats(get_max_procs())<0){
1666
+		LOG(L_CRIT, "could not initialize the dns cache measurement\n");
1667
+		goto error;
1668
+	}
1669
+#endif
1670
+#if defined USE_DST_BLACKLIST && defined USE_DST_BLACKLIST_STATS
1671
+	if (init_dst_blacklist_stats(get_max_procs())<0){
1672
+		LOG(L_CRIT, "could not initialize the dst blacklist measurement\n");
1673
+		goto error;
1674
+	}
1675
+#endif
1676
+
1664 1677
 	/* fix routing lists */
1665 1678
 	if ( (r=fix_rls())!=0){
1666 1679
 		fprintf(stderr, "ERROR: error %d while trying to fix configuration\n",