c401cc
From de8db3c0973742489f31f74065eb91da2da33e55 Mon Sep 17 00:00:00 2001
c401cc
Message-Id: <de8db3c0973742489f31f74065eb91da2da33e55.1391615407.git.jdenemar@redhat.com>
c401cc
From: Laine Stump <laine@laine.org>
c401cc
Date: Wed, 5 Feb 2014 03:09:11 -0700
c401cc
Subject: [PATCH] network: change default of forwardPlainNames to 'yes'
c401cc
c401cc
https://bugzilla.redhat.com/show_bug.cgi?id=1061099
c401cc
c401cc
The previous patch fixed "forwardPlainNames" so that it really is
c401cc
doing only what is intended, but left the default to be
c401cc
"forwardPlainNames='no'". Discussion around the initial version of
c401cc
that patch led to the decision that the default should instead be
c401cc
"forwardPlainNames='yes'" (i.e. the original behavior before commit
c401cc
f3886825). This patch makes that change to the default.
c401cc
c401cc
(cherry picked from commit 66f75925ebc4c37a9fa7cde3de5a6188cc64ef16)
c401cc
c401cc
Conflicts:
c401cc
tests/networkxml2xmlout/nat-network-dns-hosts.xml - small change
c401cc
  in network xml <bridge> element formatting upstream
c401cc
c401cc
src/conf/network_conf.c - <forwarder> added upstream
c401cc
c401cc
tests/networkxml2confdata/nat-network-dns-forwarders.conf
c401cc
tests/networkxml2xmlupdateout/nat-network-dns-more-hosts.xml
c401cc
tests/networkxml2xmlupdateout/nat-network-no-hosts.xml
c401cc
  these tests were added upstream
c401cc
c401cc
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c401cc
---
c401cc
 src/conf/network_conf.c                            | 32 +++++++++++++++-------
c401cc
 src/conf/network_conf.h                            | 17 ++++++++++--
c401cc
 src/network/bridge_driver.c                        |  3 +-
c401cc
 tests/networkxml2confdata/dhcp6-nat-network.conf   |  2 --
c401cc
 tests/networkxml2confdata/dhcp6-network.conf       |  2 --
c401cc
 .../dhcp6host-routed-network.conf                  |  2 --
c401cc
 tests/networkxml2confdata/isolated-network.conf    |  2 --
c401cc
 .../nat-network-dns-srv-record-minimal.conf        |  2 --
c401cc
 .../nat-network-dns-srv-record.conf                |  2 --
c401cc
 .../nat-network-dns-txt-record.conf                |  2 --
c401cc
 tests/networkxml2confdata/nat-network.conf         |  2 --
c401cc
 tests/networkxml2confdata/netboot-network.conf     |  2 --
c401cc
 .../networkxml2confdata/netboot-proxy-network.conf |  2 --
c401cc
 tests/networkxml2confdata/routed-network.conf      |  2 --
c401cc
 tests/networkxml2xmlout/nat-network-dns-hosts.xml  |  2 +-
c401cc
 15 files changed, 40 insertions(+), 36 deletions(-)
c401cc
c401cc
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
c401cc
index d611d71..9c5319f 100644
c401cc
--- a/src/conf/network_conf.c
c401cc
+++ b/src/conf/network_conf.c
c401cc
@@ -1,7 +1,7 @@
c401cc
 /*
c401cc
  * network_conf.c: network XML handling
c401cc
  *
c401cc
- * Copyright (C) 2006-2013 Red Hat, Inc.
c401cc
+ * Copyright (C) 2006-2014 Red Hat, Inc.
c401cc
  * Copyright (C) 2006-2008 Daniel P. Berrange
c401cc
  *
c401cc
  * This library is free software; you can redistribute it and/or
c401cc
@@ -66,6 +66,12 @@ VIR_ENUM_IMPL(virNetworkForwardDriverName,
c401cc
               "kvm",
c401cc
               "vfio")
c401cc
 
c401cc
+VIR_ENUM_IMPL(virNetworkDNSForwardPlainNames,
c401cc
+              VIR_NETWORK_DNS_FORWARD_PLAIN_NAMES_LAST,
c401cc
+              "default",
c401cc
+              "yes",
c401cc
+              "no")
c401cc
+
c401cc
 virNetworkObjPtr virNetworkFindByUUID(const virNetworkObjListPtr nets,
c401cc
                                       const unsigned char *uuid)
c401cc
 {
c401cc
@@ -1047,9 +1053,9 @@ virNetworkDNSDefParseXML(const char *networkName,
c401cc
 
c401cc
     forwardPlainNames = virXPathString("string(./@forwardPlainNames)", ctxt);
c401cc
     if (forwardPlainNames) {
c401cc
-        if (STREQ(forwardPlainNames, "yes")) {
c401cc
-            def->forwardPlainNames = true;
c401cc
-        } else if (STRNEQ(forwardPlainNames, "no")) {
c401cc
+        def->forwardPlainNames
c401cc
+            = virNetworkDNSForwardPlainNamesTypeFromString(forwardPlainNames);
c401cc
+        if (def->forwardPlainNames <= 0) {
c401cc
             virReportError(VIR_ERR_XML_ERROR,
c401cc
                            _("Invalid dns forwardPlainNames setting '%s' "
c401cc
                              "in network '%s'"),
c401cc
@@ -2264,18 +2270,25 @@ static int
c401cc
 virNetworkDNSDefFormat(virBufferPtr buf,
c401cc
                        virNetworkDNSDefPtr def)
c401cc
 {
c401cc
-    int result = 0;
c401cc
     size_t i, j;
c401cc
 
c401cc
     if (!(def->forwardPlainNames || def->nhosts || def->nsrvs || def->ntxts))
c401cc
-        goto out;
c401cc
+        return 0;
c401cc
 
c401cc
     virBufferAddLit(buf, "
c401cc
     if (def->forwardPlainNames) {
c401cc
-        virBufferAddLit(buf, " forwardPlainNames='yes'");
c401cc
+        const char *fwd = virNetworkDNSForwardPlainNamesTypeToString(def->forwardPlainNames);
c401cc
+
c401cc
+        if (!fwd) {
c401cc
+            virReportError(VIR_ERR_INTERNAL_ERROR,
c401cc
+                           _("Unknown forwardPlainNames type %d in network"),
c401cc
+                           def->forwardPlainNames);
c401cc
+            return -1;
c401cc
+        }
c401cc
+        virBufferAsprintf(buf, " forwardPlainNames='%s'", fwd);
c401cc
         if (!(def->nhosts || def->nsrvs || def->ntxts)) {
c401cc
             virBufferAddLit(buf, "/>\n");
c401cc
-            goto out;
c401cc
+            return 0;
c401cc
         }
c401cc
     }
c401cc
 
c401cc
@@ -2326,8 +2339,7 @@ virNetworkDNSDefFormat(virBufferPtr buf,
c401cc
     }
c401cc
     virBufferAdjustIndent(buf, -2);
c401cc
     virBufferAddLit(buf, "</dns>\n");
c401cc
-out:
c401cc
-    return result;
c401cc
+    return 0;
c401cc
 }
c401cc
 
c401cc
 static int
c401cc
diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h
c401cc
index 920e899..b8b681a 100644
c401cc
--- a/src/conf/network_conf.h
c401cc
+++ b/src/conf/network_conf.h
c401cc
@@ -1,7 +1,7 @@
c401cc
 /*
c401cc
  * network_conf.h: network XML handling
c401cc
  *
c401cc
- * Copyright (C) 2006-2013 Red Hat, Inc.
c401cc
+ * Copyright (C) 2006-2014 Red Hat, Inc.
c401cc
  * Copyright (C) 2006-2008 Daniel P. Berrange
c401cc
  *
c401cc
  * This library is free software; you can redistribute it and/or
c401cc
@@ -112,10 +112,23 @@ struct _virNetworkDNSHostDef {
c401cc
     char **names;
c401cc
 };
c401cc
 
c401cc
+/* If forwardPlainNames is 0 (default), that is equivalent to "yes",
c401cc
+ * but won't be encoded in newly formatted XML.
c401cc
+ */
c401cc
+typedef enum {
c401cc
+    VIR_NETWORK_DNS_FORWARD_PLAIN_NAMES_DEFAULT = 0, /* silent "yes" */
c401cc
+    VIR_NETWORK_DNS_FORWARD_PLAIN_NAMES_YES,
c401cc
+    VIR_NETWORK_DNS_FORWARD_PLAIN_NAMES_NO,
c401cc
+
c401cc
+    VIR_NETWORK_DNS_FORWARD_PLAIN_NAMES_LAST,
c401cc
+} virNetworkDNSForwardPlainNamesType;
c401cc
+
c401cc
+VIR_ENUM_DECL(virNetworkDNSForwardPlainNames)
c401cc
+
c401cc
 typedef struct _virNetworkDNSDef virNetworkDNSDef;
c401cc
 typedef virNetworkDNSDef *virNetworkDNSDefPtr;
c401cc
 struct _virNetworkDNSDef {
c401cc
-    bool forwardPlainNames;
c401cc
+    int forwardPlainNames; /* enum virNetworkDNSForwardPlainNamesType */
c401cc
     size_t ntxts;
c401cc
     virNetworkDNSTxtDefPtr txts;
c401cc
     size_t nhosts;
c401cc
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
c401cc
index 678ab6d..6e348f2 100644
c401cc
--- a/src/network/bridge_driver.c
c401cc
+++ b/src/network/bridge_driver.c
c401cc
@@ -705,7 +705,8 @@ networkDnsmasqConfContents(virNetworkObjPtr network,
c401cc
                           network->def->domain);
c401cc
     }
c401cc
 
c401cc
-    if (!network->def->dns.forwardPlainNames) {
c401cc
+    if (network->def->dns.forwardPlainNames
c401cc
+        == VIR_NETWORK_DNS_FORWARD_PLAIN_NAMES_NO) {
c401cc
         virBufferAddLit(&configbuf, "domain-needed\n");
c401cc
         /* need to specify local=// whether or not a domain is
c401cc
          * specified, unless the config says we should forward "plain"
c401cc
diff --git a/tests/networkxml2confdata/dhcp6-nat-network.conf b/tests/networkxml2confdata/dhcp6-nat-network.conf
c401cc
index 050f3db..f270a43 100644
c401cc
--- a/tests/networkxml2confdata/dhcp6-nat-network.conf
c401cc
+++ b/tests/networkxml2confdata/dhcp6-nat-network.conf
c401cc
@@ -5,8 +5,6 @@
c401cc
 ##
c401cc
 ## dnsmasq conf file created by libvirt
c401cc
 strict-order
c401cc
-domain-needed
c401cc
-local=//
c401cc
 except-interface=lo
c401cc
 bind-dynamic
c401cc
 interface=virbr0
c401cc
diff --git a/tests/networkxml2confdata/dhcp6-network.conf b/tests/networkxml2confdata/dhcp6-network.conf
c401cc
index 92ea2a4..f0a9660 100644
c401cc
--- a/tests/networkxml2confdata/dhcp6-network.conf
c401cc
+++ b/tests/networkxml2confdata/dhcp6-network.conf
c401cc
@@ -7,8 +7,6 @@
c401cc
 strict-order
c401cc
 domain=mynet
c401cc
 expand-hosts
c401cc
-domain-needed
c401cc
-local=//
c401cc
 except-interface=lo
c401cc
 bind-dynamic
c401cc
 interface=virbr0
c401cc
diff --git a/tests/networkxml2confdata/dhcp6host-routed-network.conf b/tests/networkxml2confdata/dhcp6host-routed-network.conf
c401cc
index f8f05c2..ad6db36 100644
c401cc
--- a/tests/networkxml2confdata/dhcp6host-routed-network.conf
c401cc
+++ b/tests/networkxml2confdata/dhcp6host-routed-network.conf
c401cc
@@ -5,8 +5,6 @@
c401cc
 ##
c401cc
 ## dnsmasq conf file created by libvirt
c401cc
 strict-order
c401cc
-domain-needed
c401cc
-local=//
c401cc
 except-interface=lo
c401cc
 bind-dynamic
c401cc
 interface=virbr1
c401cc
diff --git a/tests/networkxml2confdata/isolated-network.conf b/tests/networkxml2confdata/isolated-network.conf
c401cc
index f8997bd..6ba34ae 100644
c401cc
--- a/tests/networkxml2confdata/isolated-network.conf
c401cc
+++ b/tests/networkxml2confdata/isolated-network.conf
c401cc
@@ -5,8 +5,6 @@
c401cc
 ##
c401cc
 ## dnsmasq conf file created by libvirt
c401cc
 strict-order
c401cc
-domain-needed
c401cc
-local=//
c401cc
 except-interface=lo
c401cc
 bind-interfaces
c401cc
 listen-address=192.168.152.1
c401cc
diff --git a/tests/networkxml2confdata/nat-network-dns-srv-record-minimal.conf b/tests/networkxml2confdata/nat-network-dns-srv-record-minimal.conf
c401cc
index 1e9b59c..ce4dd6f 100644
c401cc
--- a/tests/networkxml2confdata/nat-network-dns-srv-record-minimal.conf
c401cc
+++ b/tests/networkxml2confdata/nat-network-dns-srv-record-minimal.conf
c401cc
@@ -5,8 +5,6 @@
c401cc
 ##
c401cc
 ## dnsmasq conf file created by libvirt
c401cc
 strict-order
c401cc
-domain-needed
c401cc
-local=//
c401cc
 except-interface=lo
c401cc
 bind-interfaces
c401cc
 listen-address=192.168.122.1
c401cc
diff --git a/tests/networkxml2confdata/nat-network-dns-srv-record.conf b/tests/networkxml2confdata/nat-network-dns-srv-record.conf
c401cc
index 53d044a..b47cbe7 100644
c401cc
--- a/tests/networkxml2confdata/nat-network-dns-srv-record.conf
c401cc
+++ b/tests/networkxml2confdata/nat-network-dns-srv-record.conf
c401cc
@@ -5,8 +5,6 @@
c401cc
 ##
c401cc
 ## dnsmasq conf file created by libvirt
c401cc
 strict-order
c401cc
-domain-needed
c401cc
-local=//
c401cc
 except-interface=lo
c401cc
 bind-dynamic
c401cc
 interface=virbr0
c401cc
diff --git a/tests/networkxml2confdata/nat-network-dns-txt-record.conf b/tests/networkxml2confdata/nat-network-dns-txt-record.conf
c401cc
index 921cae1..ff53f4e 100644
c401cc
--- a/tests/networkxml2confdata/nat-network-dns-txt-record.conf
c401cc
+++ b/tests/networkxml2confdata/nat-network-dns-txt-record.conf
c401cc
@@ -5,8 +5,6 @@
c401cc
 ##
c401cc
 ## dnsmasq conf file created by libvirt
c401cc
 strict-order
c401cc
-domain-needed
c401cc
-local=//
c401cc
 except-interface=lo
c401cc
 bind-dynamic
c401cc
 interface=virbr0
c401cc
diff --git a/tests/networkxml2confdata/nat-network.conf b/tests/networkxml2confdata/nat-network.conf
c401cc
index beb714b..ced4123 100644
c401cc
--- a/tests/networkxml2confdata/nat-network.conf
c401cc
+++ b/tests/networkxml2confdata/nat-network.conf
c401cc
@@ -5,8 +5,6 @@
c401cc
 ##
c401cc
 ## dnsmasq conf file created by libvirt
c401cc
 strict-order
c401cc
-domain-needed
c401cc
-local=//
c401cc
 except-interface=lo
c401cc
 bind-dynamic
c401cc
 interface=virbr0
c401cc
diff --git a/tests/networkxml2confdata/netboot-network.conf b/tests/networkxml2confdata/netboot-network.conf
c401cc
index ce33176..8ea1f67 100644
c401cc
--- a/tests/networkxml2confdata/netboot-network.conf
c401cc
+++ b/tests/networkxml2confdata/netboot-network.conf
c401cc
@@ -7,8 +7,6 @@
c401cc
 strict-order
c401cc
 domain=example.com
c401cc
 expand-hosts
c401cc
-domain-needed
c401cc
-local=//
c401cc
 except-interface=lo
c401cc
 bind-interfaces
c401cc
 listen-address=192.168.122.1
c401cc
diff --git a/tests/networkxml2confdata/netboot-proxy-network.conf b/tests/networkxml2confdata/netboot-proxy-network.conf
c401cc
index f4d3880..4774a92 100644
c401cc
--- a/tests/networkxml2confdata/netboot-proxy-network.conf
c401cc
+++ b/tests/networkxml2confdata/netboot-proxy-network.conf
c401cc
@@ -7,8 +7,6 @@
c401cc
 strict-order
c401cc
 domain=example.com
c401cc
 expand-hosts
c401cc
-domain-needed
c401cc
-local=//
c401cc
 except-interface=lo
c401cc
 bind-interfaces
c401cc
 listen-address=192.168.122.1
c401cc
diff --git a/tests/networkxml2confdata/routed-network.conf b/tests/networkxml2confdata/routed-network.conf
c401cc
index 62ffd7a..970aa3c 100644
c401cc
--- a/tests/networkxml2confdata/routed-network.conf
c401cc
+++ b/tests/networkxml2confdata/routed-network.conf
c401cc
@@ -5,8 +5,6 @@
c401cc
 ##
c401cc
 ## dnsmasq conf file created by libvirt
c401cc
 strict-order
c401cc
-domain-needed
c401cc
-local=//
c401cc
 except-interface=lo
c401cc
 bind-dynamic
c401cc
 interface=virbr1
c401cc
diff --git a/tests/networkxml2xmlout/nat-network-dns-hosts.xml b/tests/networkxml2xmlout/nat-network-dns-hosts.xml
c401cc
index b26fa03..b4d1e64 100644
c401cc
--- a/tests/networkxml2xmlout/nat-network-dns-hosts.xml
c401cc
+++ b/tests/networkxml2xmlout/nat-network-dns-hosts.xml
c401cc
@@ -5,7 +5,7 @@
c401cc
     <interface dev='eth0'/>
c401cc
   </forward>
c401cc
   <bridge name='virbr0' stp='on' delay='0' />
c401cc
-  <dns>
c401cc
+  <dns forwardPlainNames='no'>
c401cc
     <host ip='192.168.122.1'>
c401cc
       <hostname>host</hostname>
c401cc
       <hostname>gateway</hostname>
c401cc
-- 
c401cc
1.8.5.3
c401cc