Start the dns resolver process on demand

Change-Id: Iab27b405fb3ca7aed94ae974d57c286c41298c3a
Signed-off-by: Dave Barach <dave@barachs.net>
diff --git a/src/vnet/dns/dns.c b/src/vnet/dns/dns.c
index 2951679..bae6cb4 100644
--- a/src/vnet/dns/dns.c
+++ b/src/vnet/dns/dns.c
@@ -74,6 +74,9 @@
   u32 n_vlib_mains = tm->n_vlib_mains;
   vlib_main_t *vm = dm->vlib_main;
 
+  /* Create the resolver process if not done already */
+  vnet_dns_create_resolver_process (dm);
+
   if (is_enable)
     {
       if (vec_len (dm->ip4_name_servers) == 0
diff --git a/src/vnet/dns/dns.h b/src/vnet/dns/dns.h
index c747e2e..b2e3e9b 100644
--- a/src/vnet/dns/dns.h
+++ b/src/vnet/dns/dns.h
@@ -108,6 +108,9 @@
   ip4_address_t *ip4_name_servers;
   ip6_address_t *ip6_name_servers;
 
+  /** resolver process node index */
+  u32 resolver_process_node_index;
+
   /** config parameters */
   u32 name_cache_size;
   u32 max_ttl_in_seconds;
@@ -183,6 +186,8 @@
 u8 *vnet_dns_labels_to_name (u8 * label, u8 * full_text,
 			     u8 ** parse_from_here);
 
+void vnet_dns_create_resolver_process (dns_main_t * dm);
+
 format_function_t format_dns_reply;
 
 static inline void
diff --git a/src/vnet/dns/resolver_process.c b/src/vnet/dns/resolver_process.c
index 5f43fad..cba6592 100644
--- a/src/vnet/dns/resolver_process.c
+++ b/src/vnet/dns/resolver_process.c
@@ -322,15 +322,18 @@
   return 0;			/* or not */
 }
 
-/* *INDENT-OFF* */
-VLIB_REGISTER_NODE (dns_resolver_node) =
+void
+vnet_dns_create_resolver_process (dns_main_t * dm)
 {
-  .function = dns_resolver_process,
-  .type = VLIB_NODE_TYPE_PROCESS,
-  .name = "dns-resolver-process",
-};
-/* *INDENT-ON* */
+  /* Already created the resolver process? */
+  if (dm->resolver_process_node_index > 0)
+    return;
 
+  /* No, create it now and make a note of the node index */
+  dm->resolver_process_node_index = vlib_process_create
+    (dm->vlib_main, "dns-resolver-process",
+     dns_resolver_process, 16 /* log2_n_stack_bytes */ );
+}
 
 /*
  * fd.io coding-style-patch-verification: ON