render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From de8db3c0973742489f31f74065eb91da2da33e55 Mon Sep 17 00:00:00 2001
Message-Id: <de8db3c0973742489f31f74065eb91da2da33e55.1391615407.git.jdenemar@redhat.com>
From: Laine Stump <laine@laine.org>
Date: Wed, 5 Feb 2014 03:09:11 -0700
Subject: [PATCH] network: change default of forwardPlainNames to 'yes'

https://bugzilla.redhat.com/show_bug.cgi?id=1061099

The previous patch fixed "forwardPlainNames" so that it really is
doing only what is intended, but left the default to be
"forwardPlainNames='no'". Discussion around the initial version of
that patch led to the decision that the default should instead be
"forwardPlainNames='yes'" (i.e. the original behavior before commit
f3886825). This patch makes that change to the default.

(cherry picked from commit 66f75925ebc4c37a9fa7cde3de5a6188cc64ef16)

Conflicts:
tests/networkxml2xmlout/nat-network-dns-hosts.xml - small change
  in network xml <bridge> element formatting upstream

src/conf/network_conf.c - <forwarder> added upstream

tests/networkxml2confdata/nat-network-dns-forwarders.conf
tests/networkxml2xmlupdateout/nat-network-dns-more-hosts.xml
tests/networkxml2xmlupdateout/nat-network-no-hosts.xml
  these tests were added upstream

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/conf/network_conf.c                            | 32 +++++++++++++++-------
 src/conf/network_conf.h                            | 17 ++++++++++--
 src/network/bridge_driver.c                        |  3 +-
 tests/networkxml2confdata/dhcp6-nat-network.conf   |  2 --
 tests/networkxml2confdata/dhcp6-network.conf       |  2 --
 .../dhcp6host-routed-network.conf                  |  2 --
 tests/networkxml2confdata/isolated-network.conf    |  2 --
 .../nat-network-dns-srv-record-minimal.conf        |  2 --
 .../nat-network-dns-srv-record.conf                |  2 --
 .../nat-network-dns-txt-record.conf                |  2 --
 tests/networkxml2confdata/nat-network.conf         |  2 --
 tests/networkxml2confdata/netboot-network.conf     |  2 --
 .../networkxml2confdata/netboot-proxy-network.conf |  2 --
 tests/networkxml2confdata/routed-network.conf      |  2 --
 tests/networkxml2xmlout/nat-network-dns-hosts.xml  |  2 +-
 15 files changed, 40 insertions(+), 36 deletions(-)

diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index d611d71..9c5319f 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -1,7 +1,7 @@
 /*
  * network_conf.c: network XML handling
  *
- * Copyright (C) 2006-2013 Red Hat, Inc.
+ * Copyright (C) 2006-2014 Red Hat, Inc.
  * Copyright (C) 2006-2008 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -66,6 +66,12 @@ VIR_ENUM_IMPL(virNetworkForwardDriverName,
               "kvm",
               "vfio")
 
+VIR_ENUM_IMPL(virNetworkDNSForwardPlainNames,
+              VIR_NETWORK_DNS_FORWARD_PLAIN_NAMES_LAST,
+              "default",
+              "yes",
+              "no")
+
 virNetworkObjPtr virNetworkFindByUUID(const virNetworkObjListPtr nets,
                                       const unsigned char *uuid)
 {
@@ -1047,9 +1053,9 @@ virNetworkDNSDefParseXML(const char *networkName,
 
     forwardPlainNames = virXPathString("string(./@forwardPlainNames)", ctxt);
     if (forwardPlainNames) {
-        if (STREQ(forwardPlainNames, "yes")) {
-            def->forwardPlainNames = true;
-        } else if (STRNEQ(forwardPlainNames, "no")) {
+        def->forwardPlainNames
+            = virNetworkDNSForwardPlainNamesTypeFromString(forwardPlainNames);
+        if (def->forwardPlainNames <= 0) {
             virReportError(VIR_ERR_XML_ERROR,
                            _("Invalid dns forwardPlainNames setting '%s' "
                              "in network '%s'"),
@@ -2264,18 +2270,25 @@ static int
 virNetworkDNSDefFormat(virBufferPtr buf,
                        virNetworkDNSDefPtr def)
 {
-    int result = 0;
     size_t i, j;
 
     if (!(def->forwardPlainNames || def->nhosts || def->nsrvs || def->ntxts))
-        goto out;
+        return 0;
 
     virBufferAddLit(buf, "<dns");
     if (def->forwardPlainNames) {
-        virBufferAddLit(buf, " forwardPlainNames='yes'");
+        const char *fwd = virNetworkDNSForwardPlainNamesTypeToString(def->forwardPlainNames);
+
+        if (!fwd) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("Unknown forwardPlainNames type %d in network"),
+                           def->forwardPlainNames);
+            return -1;
+        }
+        virBufferAsprintf(buf, " forwardPlainNames='%s'", fwd);
         if (!(def->nhosts || def->nsrvs || def->ntxts)) {
             virBufferAddLit(buf, "/>\n");
-            goto out;
+            return 0;
         }
     }
 
@@ -2326,8 +2339,7 @@ virNetworkDNSDefFormat(virBufferPtr buf,
     }
     virBufferAdjustIndent(buf, -2);
     virBufferAddLit(buf, "</dns>\n");
-out:
-    return result;
+    return 0;
 }
 
 static int
diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h
index 920e899..b8b681a 100644
--- a/src/conf/network_conf.h
+++ b/src/conf/network_conf.h
@@ -1,7 +1,7 @@
 /*
  * network_conf.h: network XML handling
  *
- * Copyright (C) 2006-2013 Red Hat, Inc.
+ * Copyright (C) 2006-2014 Red Hat, Inc.
  * Copyright (C) 2006-2008 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -112,10 +112,23 @@ struct _virNetworkDNSHostDef {
     char **names;
 };
 
+/* If forwardPlainNames is 0 (default), that is equivalent to "yes",
+ * but won't be encoded in newly formatted XML.
+ */
+typedef enum {
+    VIR_NETWORK_DNS_FORWARD_PLAIN_NAMES_DEFAULT = 0, /* silent "yes" */
+    VIR_NETWORK_DNS_FORWARD_PLAIN_NAMES_YES,
+    VIR_NETWORK_DNS_FORWARD_PLAIN_NAMES_NO,
+
+    VIR_NETWORK_DNS_FORWARD_PLAIN_NAMES_LAST,
+} virNetworkDNSForwardPlainNamesType;
+
+VIR_ENUM_DECL(virNetworkDNSForwardPlainNames)
+
 typedef struct _virNetworkDNSDef virNetworkDNSDef;
 typedef virNetworkDNSDef *virNetworkDNSDefPtr;
 struct _virNetworkDNSDef {
-    bool forwardPlainNames;
+    int forwardPlainNames; /* enum virNetworkDNSForwardPlainNamesType */
     size_t ntxts;
     virNetworkDNSTxtDefPtr txts;
     size_t nhosts;
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 678ab6d..6e348f2 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -705,7 +705,8 @@ networkDnsmasqConfContents(virNetworkObjPtr network,
                           network->def->domain);
     }
 
-    if (!network->def->dns.forwardPlainNames) {
+    if (network->def->dns.forwardPlainNames
+        == VIR_NETWORK_DNS_FORWARD_PLAIN_NAMES_NO) {
         virBufferAddLit(&configbuf, "domain-needed\n");
         /* need to specify local=// whether or not a domain is
          * specified, unless the config says we should forward "plain"
diff --git a/tests/networkxml2confdata/dhcp6-nat-network.conf b/tests/networkxml2confdata/dhcp6-nat-network.conf
index 050f3db..f270a43 100644
--- a/tests/networkxml2confdata/dhcp6-nat-network.conf
+++ b/tests/networkxml2confdata/dhcp6-nat-network.conf
@@ -5,8 +5,6 @@
 ##
 ## dnsmasq conf file created by libvirt
 strict-order
-domain-needed
-local=//
 except-interface=lo
 bind-dynamic
 interface=virbr0
diff --git a/tests/networkxml2confdata/dhcp6-network.conf b/tests/networkxml2confdata/dhcp6-network.conf
index 92ea2a4..f0a9660 100644
--- a/tests/networkxml2confdata/dhcp6-network.conf
+++ b/tests/networkxml2confdata/dhcp6-network.conf
@@ -7,8 +7,6 @@
 strict-order
 domain=mynet
 expand-hosts
-domain-needed
-local=//
 except-interface=lo
 bind-dynamic
 interface=virbr0
diff --git a/tests/networkxml2confdata/dhcp6host-routed-network.conf b/tests/networkxml2confdata/dhcp6host-routed-network.conf
index f8f05c2..ad6db36 100644
--- a/tests/networkxml2confdata/dhcp6host-routed-network.conf
+++ b/tests/networkxml2confdata/dhcp6host-routed-network.conf
@@ -5,8 +5,6 @@
 ##
 ## dnsmasq conf file created by libvirt
 strict-order
-domain-needed
-local=//
 except-interface=lo
 bind-dynamic
 interface=virbr1
diff --git a/tests/networkxml2confdata/isolated-network.conf b/tests/networkxml2confdata/isolated-network.conf
index f8997bd..6ba34ae 100644
--- a/tests/networkxml2confdata/isolated-network.conf
+++ b/tests/networkxml2confdata/isolated-network.conf
@@ -5,8 +5,6 @@
 ##
 ## dnsmasq conf file created by libvirt
 strict-order
-domain-needed
-local=//
 except-interface=lo
 bind-interfaces
 listen-address=192.168.152.1
diff --git a/tests/networkxml2confdata/nat-network-dns-srv-record-minimal.conf b/tests/networkxml2confdata/nat-network-dns-srv-record-minimal.conf
index 1e9b59c..ce4dd6f 100644
--- a/tests/networkxml2confdata/nat-network-dns-srv-record-minimal.conf
+++ b/tests/networkxml2confdata/nat-network-dns-srv-record-minimal.conf
@@ -5,8 +5,6 @@
 ##
 ## dnsmasq conf file created by libvirt
 strict-order
-domain-needed
-local=//
 except-interface=lo
 bind-interfaces
 listen-address=192.168.122.1
diff --git a/tests/networkxml2confdata/nat-network-dns-srv-record.conf b/tests/networkxml2confdata/nat-network-dns-srv-record.conf
index 53d044a..b47cbe7 100644
--- a/tests/networkxml2confdata/nat-network-dns-srv-record.conf
+++ b/tests/networkxml2confdata/nat-network-dns-srv-record.conf
@@ -5,8 +5,6 @@
 ##
 ## dnsmasq conf file created by libvirt
 strict-order
-domain-needed
-local=//
 except-interface=lo
 bind-dynamic
 interface=virbr0
diff --git a/tests/networkxml2confdata/nat-network-dns-txt-record.conf b/tests/networkxml2confdata/nat-network-dns-txt-record.conf
index 921cae1..ff53f4e 100644
--- a/tests/networkxml2confdata/nat-network-dns-txt-record.conf
+++ b/tests/networkxml2confdata/nat-network-dns-txt-record.conf
@@ -5,8 +5,6 @@
 ##
 ## dnsmasq conf file created by libvirt
 strict-order
-domain-needed
-local=//
 except-interface=lo
 bind-dynamic
 interface=virbr0
diff --git a/tests/networkxml2confdata/nat-network.conf b/tests/networkxml2confdata/nat-network.conf
index beb714b..ced4123 100644
--- a/tests/networkxml2confdata/nat-network.conf
+++ b/tests/networkxml2confdata/nat-network.conf
@@ -5,8 +5,6 @@
 ##
 ## dnsmasq conf file created by libvirt
 strict-order
-domain-needed
-local=//
 except-interface=lo
 bind-dynamic
 interface=virbr0
diff --git a/tests/networkxml2confdata/netboot-network.conf b/tests/networkxml2confdata/netboot-network.conf
index ce33176..8ea1f67 100644
--- a/tests/networkxml2confdata/netboot-network.conf
+++ b/tests/networkxml2confdata/netboot-network.conf
@@ -7,8 +7,6 @@
 strict-order
 domain=example.com
 expand-hosts
-domain-needed
-local=//
 except-interface=lo
 bind-interfaces
 listen-address=192.168.122.1
diff --git a/tests/networkxml2confdata/netboot-proxy-network.conf b/tests/networkxml2confdata/netboot-proxy-network.conf
index f4d3880..4774a92 100644
--- a/tests/networkxml2confdata/netboot-proxy-network.conf
+++ b/tests/networkxml2confdata/netboot-proxy-network.conf
@@ -7,8 +7,6 @@
 strict-order
 domain=example.com
 expand-hosts
-domain-needed
-local=//
 except-interface=lo
 bind-interfaces
 listen-address=192.168.122.1
diff --git a/tests/networkxml2confdata/routed-network.conf b/tests/networkxml2confdata/routed-network.conf
index 62ffd7a..970aa3c 100644
--- a/tests/networkxml2confdata/routed-network.conf
+++ b/tests/networkxml2confdata/routed-network.conf
@@ -5,8 +5,6 @@
 ##
 ## dnsmasq conf file created by libvirt
 strict-order
-domain-needed
-local=//
 except-interface=lo
 bind-dynamic
 interface=virbr1
diff --git a/tests/networkxml2xmlout/nat-network-dns-hosts.xml b/tests/networkxml2xmlout/nat-network-dns-hosts.xml
index b26fa03..b4d1e64 100644
--- a/tests/networkxml2xmlout/nat-network-dns-hosts.xml
+++ b/tests/networkxml2xmlout/nat-network-dns-hosts.xml
@@ -5,7 +5,7 @@
     <interface dev='eth0'/>
   </forward>
   <bridge name='virbr0' stp='on' delay='0' />
-  <dns>
+  <dns forwardPlainNames='no'>
     <host ip='192.168.122.1'>
       <hostname>host</hostname>
       <hostname>gateway</hostname>
-- 
1.8.5.3