From 58686c3dd8bffbd228226eab50df5de6fbef2ac4 Mon Sep 17 00:00:00 2001
From: Daniel Veillard <veillard@redhat.com>
Date: Mon, 8 Sep 2008 12:45:29 +0000
Subject: [PATCH] add domain name in network configurations suport and on
 OpenVZ config bugfix * src/network_conf.c src/network_conf.h
 src/qemu_driver.c: add   support for a domain name in network configurations,
 patch by   JJ Reynolds with bugfix raised by Dan * src/openvz_conf.c: fix to
 small bug in openvzReadConfigParam   by Evgeniy Sokolov Daniel

---
 ChangeLog          |  8 ++++++++
 src/network_conf.c |  4 ++++
 src/network_conf.h |  1 +
 src/openvz_conf.c  | 11 +++++++----
 src/qemu_driver.c  |  6 ++++++
 5 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 10860821ce..b47bf02f62 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Mon Sep  8 14:42:23 CEST 2008 Daniel Veillard <veillard@redhat.com>
+
+	* src/network_conf.c src/network_conf.h src/qemu_driver.c: add
+	  support for a domain name in network configurations, patch by
+	  JJ Reynolds with bugfix raised by Dan
+	* src/openvz_conf.c: fix to small bug in openvzReadConfigParam
+	  by Evgeniy Sokolov
+
 Mon Sep  8 13:14:17 BST 2008 Daniel P. Berrange <berrange@redhat.com>
 
 	* src/openvz_driver.c: Fix potential NULL dereference
diff --git a/src/network_conf.c b/src/network_conf.c
index 2755ca6304..4627fba17c 100644
--- a/src/network_conf.c
+++ b/src/network_conf.c
@@ -109,6 +109,7 @@ void virNetworkDefFree(virNetworkDefPtr def)
     VIR_FREE(def->ipAddress);
     VIR_FREE(def->network);
     VIR_FREE(def->netmask);
+    VIR_FREE(def->domain);
 
     for (i = 0 ; i < def->nranges && def->ranges ; i++) {
         VIR_FREE(def->ranges[i].start);
@@ -326,6 +327,9 @@ virNetworkDefParseXML(virConnectPtr conn,
         VIR_FREE(tmp);
     }
 
+    /* Parse network domain information */
+    def->domain = virXPathString(conn, "string(./domain[1]/@name)", ctxt);
+
     /* Parse bridge information */
     def->bridge = virXPathString(conn, "string(./bridge[1]/@name)", ctxt);
     tmp = virXPathString(conn, "string(./bridge[1]/@stp)", ctxt);
diff --git a/src/network_conf.h b/src/network_conf.h
index 25750a6c41..7d9490e438 100644
--- a/src/network_conf.h
+++ b/src/network_conf.h
@@ -57,6 +57,7 @@ struct _virNetworkDef {
     char *name;
 
     char *bridge;       /* Name of bridge device */
+    char *domain;
     unsigned long delay;   /* Bridge forward delay (ms) */
     int stp : 1; /* Spanning tree protocol */
 
diff --git a/src/openvz_conf.c b/src/openvz_conf.c
index 25bd10fe69..34c77b1f64 100644
--- a/src/openvz_conf.c
+++ b/src/openvz_conf.c
@@ -298,10 +298,13 @@ openvzReadConfigParam(int vpsid ,const char * param, char *value, int maxlen)
         if (STREQLEN(line, param, strlen(param))) {
             sf = line;
             sf += strlen(param);
-            if (sf[0] == '=' && (token = strtok_r(sf,"\"\t=\n", &saveptr)) != NULL) {
-                strncpy(value, token, maxlen) ;
-                value[maxlen-1] = '\0';
-                found = 1;
+            if (sf[0] == '=' && sf[1] != '\0' ) {
+                sf ++;
+                if ((token = strtok_r(sf,"\"\t\n", &saveptr)) != NULL) {
+                    strncpy(value, token, maxlen) ;
+                    value[maxlen-1] = '\0';
+                    found = 1;
+                }
             }
        }
     }
diff --git a/src/qemu_driver.c b/src/qemu_driver.c
index 8f8fb613e5..8cc32bcd69 100644
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -1113,6 +1113,7 @@ qemudBuildDnsmasqArgv(virConnectPtr conn,
         1 + /* --keep-in-foreground */
         1 + /* --strict-order */
         1 + /* --bind-interfaces */
+        (network->def->domain?2:0) + /* --domain name */
         2 + /* --pid-file "" */
         2 + /* --conf-file "" */
         /*2 + *//* --interface virbr0 */
@@ -1144,6 +1145,11 @@ qemudBuildDnsmasqArgv(virConnectPtr conn,
     APPEND_ARG(*argv, i++, "--strict-order");
     APPEND_ARG(*argv, i++, "--bind-interfaces");
 
+    if (network->def->domain) {
+       APPEND_ARG(*argv, i++, "--domain");
+       APPEND_ARG(*argv, i++, network->def->domain);
+    }
+
     APPEND_ARG(*argv, i++, "--pid-file");
     APPEND_ARG(*argv, i++, "");