Browse Source

dns_get_server_state() implemented which returns the state of the DNS servers

Miklos Tirpak 18 years ago
parent
commit
5015222069
3 changed files with 25 additions and 0 deletions
  1. 10 0
      core_cmd.c
  2. 12 0
      dns_cache.c
  3. 3 0
      dns_cache.h

+ 10 - 0
core_cmd.c

@@ -122,6 +122,15 @@ static const char* dns_set_server_state_doc[] = {
 	"(0: all the servers are down, 1: at least one server is up)",    /* Documentation string */
 	0                              /* Method signature(s) */
 };
+
+void dns_get_server_state_rpc(rpc_t* rpc, void* ctx);
+
+static const char* dns_get_server_state_doc[] = {
+	"prints the state of the DNS servers " \
+	"(0: all the servers are down, 1: at least one server is up)",	/* Documentation string */
+	0				/* Method signature(s) */
+};
+
 #endif /* DNS_WATCHDOG_SUPPORT */
 #endif /* USE_DNS_CACHE */
 #ifdef USE_DST_BLACKLIST
@@ -573,6 +582,7 @@ rpc_export_t core_rpc_methods[] = {
 #endif /* USE_DNS_CACHE_STATS */
 #ifdef DNS_WATCHDOG_SUPPORT
 	{"dns.set_server_state",   dns_set_server_state_rpc, dns_set_server_state_doc, 0 },
+	{"dns.get_server_state",   dns_get_server_state_rpc, dns_get_server_state_doc, 0 },
 #endif
 #endif
 #ifdef USE_DST_BLACKLIST

+ 12 - 0
dns_cache.c

@@ -3120,6 +3120,12 @@ void dns_set_server_state(int state)
 {
 	atomic_set(dns_servers_up, state);
 }
+
+/* returns the state of the DNS servers */
+int dns_get_server_state(void)
+{
+	return atomic_get(dns_servers_up);
+}
 #endif /* DNS_WATCHDOG_SUPPORT */
 
 /* rpc functions */
@@ -3796,6 +3802,12 @@ void dns_set_server_state_rpc(rpc_t* rpc, void* ctx)
 		return;
 	dns_set_server_state(state);
 }
+
+/* prints the DNS server state */
+void dns_get_server_state_rpc(rpc_t* rpc, void* ctx)
+{
+	rpc->add(ctx, "d", dns_get_server_state());
+}
 #endif /* DNS_WATCHDOG_SUPPORT */
 
 #endif

+ 3 - 0
dns_cache.h

@@ -327,6 +327,9 @@ void dns_cache_flush(void);
  * 0: all the servers are down
  */
 void dns_set_server_state(int state);
+
+/* returns the state of the DNS servers */
+int dns_get_server_state(void);
 #endif /* DNS_WATCHDOG_SUPPORT */
 
 #endif