Browse Source

- dst blacklist and DNS cache measurements added

Gergely Kovacs 18 years ago
parent
commit
021e7e0e54
4 changed files with 100 additions and 26 deletions
  1. 7 1
      Makefile.defs
  2. 24 1
      core_cmd.c
  3. 23 6
      globals.h
  4. 46 18
      main.c

+ 7 - 1
Makefile.defs

@@ -61,6 +61,7 @@
 #               -flat_namespace -undefined suppress) (andrei)
 #  2007-07-07  added HAVE_SCHED_SETSCHEDULER for linux (andrei)
 #  2007-07-18  added DNS_WATCHDOG_SUPPORT (Miklos)
+#  2007-07-30  added USE_DNS_CACHE_STATS and USE_DST_BLACKLIST_STATS (Gergo)
 
 # check if already included/exported
 
@@ -388,12 +389,16 @@ endif
 #		which (mis)uses this parameter.
 # -DUSE_DNS_CACHE
 #		use an internal dns cache instead of making dns requests each time
+# -DUSE_DNS_CACHE_STATS
+#		turns on DNS cache measurements
 # -DUSE_DNS_FAILOVER
 #		if the destination resolves to multiple ips, on send error fall back
 #		to the others
 # -DUSE_DST_BLACKLIST
 #		blacklist bad destination (timeout, failed to connect, error sending
 #        a.s.o)
+# -DUSE_DST_BLACKLIST_STATS
+#		turns on blacklist bad destination measurements
 # -DPROFILING
 #		if enabled profiling will be enabled for child processes
 #		Don't forget to set PROFILE (see below)
@@ -409,7 +414,6 @@ endif
 #		core that the DNS servers are down. No DNS query is performed
 #		when the servers are unreachable, and even expired resource
 #		records are used from the cache. (requires external watchdog)
-
 # Sometimes is needes correct non-quoted $OS. HACK: gcc translates known OS to number ('linux'), so there is added underscore
 
 DEFS+= $(extra_defs) \
@@ -429,6 +433,8 @@ DEFS+= $(extra_defs) \
 	 -DUSE_DNS_FAILOVER \
 	 -DUSE_DST_BLACKLIST \
 	 -DUSE_NAPTR \
+	 #-DUSE_DNS_CACHE_STATS \
+	 #-DUSE_DST_BLACKLIST_STATS \
 	 #-DDNS_WATCHDOG_SUPPORT \
 	 #-DLL_MALLOC \
 	 #-DSF_MALLOC \

+ 24 - 1
core_cmd.c

@@ -106,6 +106,14 @@ static const char* dns_cache_delete_srv_doc[] = {
 	0
 };
 
+#ifdef USE_DNS_CACHE_STATS
+void dns_cache_stats_get(rpc_t* rpc, void* ctx);
+
+static const char* dns_cache_stats_get_doc[] = {
+	"returns the dns measurement counters.",
+	0
+};
+#endif /* USE_DNS_CACHE_STATS */
 #ifdef DNS_WATCHDOG_SUPPORT
 void dns_set_server_state_rpc(rpc_t* rpc, void* ctx);
 
@@ -143,6 +151,14 @@ static const char* dst_blst_add_doc[] = {
 	"Adds a new entry to the dst blacklist.",  /* Documentation string */
 	0                               /* Method signature(s) */
 };
+#ifdef USE_DST_BLACKLIST_STATS
+void dst_blst_stats_get(rpc_t* rpc, void* ctx);
+
+static const char* dst_blst_stats_get_doc[] = {
+	"returns the dst blacklist measurement counters.",
+	0
+};
+#endif /* USE_DST_BLACKLIST_STATS */
 
 #endif
 
@@ -489,6 +505,7 @@ static const char* core_sfmalloc_doc[] = {
 	"Returns sfmalloc debugging  info.",  /* Documentation string */
 	0                                     /* Method signature(s) */
 };
+
 #endif
 
 
@@ -503,7 +520,7 @@ static void core_tcpinfo(rpc_t* rpc, void* c)
 	void *handle;
 #ifdef USE_TCP
 	struct tcp_gen_info ti;
-	
+
 	if (!tcp_disable){
 		tcp_get_info(&ti);
 		rpc->add(c, "{", &handle);
@@ -551,6 +568,9 @@ rpc_export_t core_rpc_methods[] = {
 	{"dns.delete_a",           dns_cache_delete_a,    dns_cache_delete_a_doc,    0	},
 	{"dns.delete_aaaa",        dns_cache_delete_aaaa, dns_cache_delete_aaaa_doc, 0	},
 	{"dns.delete_srv",         dns_cache_delete_srv,  dns_cache_delete_srv_doc,  0	},
+#ifdef USE_DNS_CACHE_STATS
+	{"dns.stats_get",    dns_cache_stats_get,   dns_cache_stats_get_doc,        0	},
+#endif /* USE_DNS_CACHE_STATS */
 #ifdef DNS_WATCHDOG_SUPPORT
 	{"dns.set_server_state",   dns_set_server_state_rpc, dns_set_server_state_doc, 0 },
 #endif
@@ -561,6 +581,9 @@ rpc_export_t core_rpc_methods[] = {
 	{"dst_blacklist.view",     dst_blst_view,         dst_blst_view_doc,         0	},
 	{"dst_blacklist.delete_all", dst_blst_delete_all, dst_blst_delete_all_doc,   0	},
 	{"dst_blacklist.add",      dst_blst_add,          dst_blst_add_doc,          0	},
+#ifdef USE_DST_BLACKLIST_STATS
+	{"dst_blacklist.stats_get", dst_blst_stats_get, dst_blst_stats_get_doc, 0 },
+#endif /* USE_DST_BLACKLIST_STATS */
 #endif
 	{0, 0, 0, 0}
 };

+ 23 - 6
globals.h

@@ -23,8 +23,8 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
@@ -179,7 +179,7 @@ extern int shm_force_alloc;
 extern int mlock_pages;
 
 /* real time stuff */
-extern int real_time; 
+extern int real_time;
 extern int rt_prio;
 extern int rt_policy; /* SCHED_OTHER */
 extern int rt_timer1_prio;  /* "fast" timer */
@@ -197,23 +197,40 @@ extern int dns_search_list;
 #ifdef USE_DNS_CACHE
 extern int use_dns_cache; /* 1 if the cache is enabled, 0 otherwise */
 extern int use_dns_failover; /* 1 if failover is enabled, 0 otherwise */
-extern unsigned int dns_cache_max_mem; /* maximum memory used for the cached 
+extern unsigned int dns_cache_max_mem; /* maximum memory used for the cached
 										  entries*/
 extern unsigned int dns_neg_cache_ttl; /* neg. cache ttl */
 extern unsigned int dns_cache_max_ttl; /* maximum ttl */
 extern unsigned int dns_cache_min_ttl; /* minimum ttl */
 extern unsigned int dns_timer_interval; /* gc timer interval in s */
-extern int dns_flags; /* default flags used for the  dns_*resolvehost 
+extern int dns_flags; /* default flags used for the  dns_*resolvehost
                     (compatibility wrappers) */
 extern int dns_srv_lb; /* default SRV LB support value */
 
+#ifdef USE_DNS_CACHE_STATS
+struct t_dns_cache_stats{
+	unsigned long dns_req_cnt;
+	unsigned long dc_hits_cnt;
+	unsigned long dc_neg_hits_cnt;
+	unsigned long dc_lru_cnt;
+};
+extern struct t_dns_cache_stats* dns_cache_stats;
+#endif /* USE_DNS_CACHE_STATS */
 #endif
 #ifdef USE_DST_BLACKLIST
 extern int use_dst_blacklist; /* 1 if the blacklist is enabled */
-extern unsigned int  blst_max_mem; /* maximum memory used for the blacklist 
+extern unsigned int  blst_max_mem; /* maximum memory used for the blacklist
 									  entries*/
 extern unsigned int blst_timeout; /* blacklist entry ttl */
 extern unsigned int blst_timer_interval; /*blacklist gc timer interval (in s)*/
+
+#ifdef USE_DST_BLACKLIST_STATS
+struct t_dst_blacklist_stats{
+	unsigned long bkl_hit_cnt;
+	unsigned long bkl_lru_cnt;
+};
+extern struct t_dst_blacklist_stats* dst_blacklist_stats;
+#endif /* USE_DST_BLACKLIST_STATS */
 #endif
 
 #endif

+ 46 - 18
main.c

@@ -70,10 +70,11 @@
  *               tcp usage for module started processes (andrei)
  * 2007-01-18  children shutdown procedure moved into shutdown_children;
  *               safer shutdown on start-up error (andrei)
- * 2007-02-09  TLS support split into tls-in-core (CORE_TLS) and generic TLS 
+ * 2007-02-09  TLS support split into tls-in-core (CORE_TLS) and generic TLS
  *             (USE_TLS)  (andrei)
  * 2007-06-07  added support for locking pages in mem. and using real time
  *              scheduling policies (andrei)
+ * 2007-07-30  dst blacklist and DNS cache measurements added (Gergo)
  */
 
 
@@ -279,7 +280,7 @@ int tls_disable = 1;  /* tls disabled by default */
 
 struct process_table *pt=0;		/*array with children pids, 0= main proc,
 									alloc'ed in shared mem if possible*/
-int *process_count = 0;			/* Total number of SER processes currently 
+int *process_count = 0;			/* Total number of SER processes currently
 								   running */
 gen_lock_t* process_lock;		/* lock on the process table */
 int process_no = 0;				/* index of process in the pt */
@@ -343,7 +344,7 @@ int mlock_pages=0; /* default off, try to disable swapping */
 /* real time options */
 int real_time=0; /* default off, flags: 1 on only timer, 2  slow timer,
 					                    4 all procs (7=all) */
-int rt_prio=0;  
+int rt_prio=0;
 int rt_policy=0; /* SCHED_OTHER */
 int rt_timer1_prio=0;  /* "fast" timer */
 int rt_timer2_prio=0;  /* "slow" timer */
@@ -522,7 +523,7 @@ static void kill_all_children(int signum)
 		  * (only main can add processes, so from main is safe not to lock
 		  *  and moreover it avoids the lock-holding suicidal children problem)
 		  */
-		if (!is_main) lock_get(process_lock); 
+		if (!is_main) lock_get(process_lock);
 		for (r=1; r<*process_count; r++){
 			if (r==process_no) continue; /* try not to be suicidal */
 			if (pt[r].pid) {
@@ -569,7 +570,7 @@ static void shutdown_children(int sig, int show_status)
 		 * alarm is installed which is exactly what we want */
 	}
 	alarm(ser_kill_timeout);
-	while((wait(0) > 0) || (errno==EINTR)); /* wait for all the 
+	while((wait(0) > 0) || (errno==EINTR)); /* wait for all the
 											   children to terminate*/
 	set_sig_h(SIGALRM, sig_alarm_abort);
 	cleanup(show_status); /* cleanup & show status*/
@@ -915,12 +916,12 @@ int main_loop()
 		   as new processes are forked (while skipping 0 reserved for main
 		*/
 
-		/* init childs with rank==PROC_INIT before forking any process, 
+		/* init childs with rank==PROC_INIT before forking any process,
 		 * this is a place for delayed (after mod_init) initializations
 		 * (e.g. shared vars that depend on the total number of processes
 		 * that is known only after all mod_inits have been executed )
 		 * WARNING: the same init_child will be called latter, a second time
-		 * for the "main" process with rank PROC_MAIN (make sure things are 
+		 * for the "main" process with rank PROC_MAIN (make sure things are
 		 * not initialized twice)*/
 		if (init_child(PROC_INIT) < 0) {
 			LOG(L_ERR, "ERROR: main_dontfork: init_child(PROC_INT) --"
@@ -941,7 +942,7 @@ int main_loop()
 					/* process_bit = 0; */
 					if (real_time&2)
 						set_rt_prio(rt_timer2_prio, rt_timer2_policy);
-					
+
 					if (arm_slow_timer()<0) goto error;
 					slow_timer_main();
 				}else{
@@ -971,7 +972,7 @@ int main_loop()
 		snprintf(pt[process_no].desc, MAX_PT_DESC,
 			"stand-alone receiver @ %s:%s",
 			 bind_address->name.s, bind_address->port_no_str.s );
-	
+
 	/* call it also w/ PROC_MAIN to make sure modules that init things only
 	 * in PROC_MAIN get a chance to run */
 	if (init_child(PROC_MAIN) < 0) {
@@ -1041,12 +1042,12 @@ int main_loop()
 			 * so we open all first*/
 		if (do_suid()==-1) goto error; /* try to drop privileges */
 
-		/* init childs with rank==PROC_INIT before forking any process, 
+		/* init childs with rank==PROC_INIT before forking any process,
 		 * this is a place for delayed (after mod_init) initializations
 		 * (e.g. shared vars that depend on the total number of processes
 		 * that is known only after all mod_inits have been executed )
 		 * WARNING: the same init_child will be called latter, a second time
-		 * for the "main" process with rank PROC_MAIN (make sure things are 
+		 * for the "main" process with rank PROC_MAIN (make sure things are
 		 * not initialized twice)*/
 		if (init_child(PROC_INIT) < 0) {
 			LOG(L_ERR, "ERROR: main: error in init_child(PROC_INT) --"
@@ -1059,7 +1060,7 @@ int main_loop()
 		for(si=udp_listen; si; si=si->next){
 			for(i=0;i<children_no;i++){
 				snprintf(si_desc, MAX_PT_DESC, "receiver child=%d sock=%s:%s",
-					i, si->name.s, si->port_no_str.s);	
+					i, si->name.s, si->port_no_str.s);
 				child_rank++;
 				pid = fork_process(child_rank, si_desc, 1);
 				if (pid<0){
@@ -1115,7 +1116,7 @@ int main_loop()
 		}
 	}
 
-/* init childs with rank==MAIN before starting tcp main (in case they want to 
+/* init childs with rank==MAIN before starting tcp main (in case they want to
  *  fork  a tcp capable process, the corresponding tcp. comm. fds in pt[] must
  *  be set before calling tcp_main_loop()) */
 	if (init_child(PROC_MAIN) < 0) {
@@ -1321,7 +1322,7 @@ int main(int argc, char** argv)
 					abort();
 		}
 	}
-	
+
 	if (init_routes()<0) goto error;
 	if (init_nonsip_hooks()<0) goto error;
 	/* fill missing arguments with the default values*/
@@ -1586,12 +1587,26 @@ try_again:
 	}
 	if (use_dns_cache==0)
 		use_dns_failover=0; /* cannot work w/o dns_cache support */
+#ifdef USE_DNS_CACHE_STATS
+	/* preinitializing before the nubmer of processes is determined */
+	if (init_dns_cache_stats(1)<0){
+		LOG(L_CRIT, "could not initialize the dns cache measurement\n");
+		goto error;
+	}
+#endif /* USE_DNS_CACHE_STATS */
 #endif
 #ifdef USE_DST_BLACKLIST
 	if (init_dst_blacklist()<0){
 		LOG(L_CRIT, "could not initialize the dst blacklist, exiting...\n");
 		goto error;
 	}
+#ifdef USE_DST_BLACKLIST_STATS
+	/* preinitializing before the nubmer of processes is determined */
+	if (init_dst_blacklist_stats(1)<0){
+		LOG(L_CRIT, "could not initialize the dst blacklist measurement\n");
+		goto error;
+	}
+#endif /* USE_DST_BLACKLIST_STATS */
 #endif
 	if (init_avps()<0) goto error;
 	if (rpc_init_time() < 0) goto error;
@@ -1624,15 +1639,15 @@ try_again:
 	}
 	if (mlock_pages)
 		mem_lock_pages();
-	
+
 	if (real_time&4)
 			set_rt_prio(rt_prio, rt_policy);
-	
+
 	if (init_modules() != 0) {
 		fprintf(stderr, "ERROR: error while initializing modules\n");
 		goto error;
 	}
-	/* initialize process_table, add core process no. (calc_proc_no()) to the 
+	/* initialize process_table, add core process no. (calc_proc_no()) to the
 	 * processes registered from the modules*/
 	if (init_pt(calc_proc_no())==-1)
 		goto error;
@@ -1653,7 +1668,7 @@ try_again:
 	}
 #endif /* USE_TLS */
 #endif /* USE_TCP */
-	
+
 	/* The total number of processes is now known, note that no
 	 * function being called before this point may rely on the
 	 * number of processes !
@@ -1661,6 +1676,19 @@ try_again:
 	DBG("Expect (at least) %d SER processes in your process list\n",
 			get_max_procs());
 
+#if defined USE_DNS_CACHE && defined USE_DNS_CACHE_STATS
+	if (init_dns_cache_stats(get_max_procs())<0){
+		LOG(L_CRIT, "could not initialize the dns cache measurement\n");
+		goto error;
+	}
+#endif
+#if defined USE_DST_BLACKLIST && defined USE_DST_BLACKLIST_STATS
+	if (init_dst_blacklist_stats(get_max_procs())<0){
+		LOG(L_CRIT, "could not initialize the dst blacklist measurement\n");
+		goto error;
+	}
+#endif
+
 	/* fix routing lists */
 	if ( (r=fix_rls())!=0){
 		fprintf(stderr, "ERROR: error %d while trying to fix configuration\n",