[PATCH] bridge_driver: use conffile for dnsmasq if it exists

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



By default dnsmasq is spawned with option --conf-file="" which disables
reading of global configuration file -- this is fine for most situations.
This patch adds possibility to run customized DNS/DHCP environment, by
spawning dnsmasq with alternative configuration file if such file exists.
This allows you to set any parameter described in dnsmasq(8).
Configuration file is expected to be located in file named
"<network_name>-dnsmasq.conf" in DNSMASQ_STATE_DIR directory.
If configuration file doesn't exists dnsmasq is spawned as before.

Patch should be applied after my earlier one.
---
 src/network/bridge_driver.c |   26 +++++++++++++++++++-------
 1 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index f2857b4..702ec95 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -391,6 +391,7 @@ networkSaveDnsmasqHostsfile(virNetworkObjPtr network,
 static int
 networkBuildDnsmasqArgv(virNetworkObjPtr network,
                         const char *pidfile,
+                        const char *conffile,
                         virCommandPtr cmd) {
     int r, ret = -1;
     int nbleases = 0;
@@ -428,8 +429,11 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,

     virCommandAddArgPair(cmd, "--pid-file", pidfile);

-    /* *no* conf file */
-    virCommandAddArgList(cmd, "--conf-file=", "", NULL);
+    /* if conf file exists use it */
+    if (virFileExists(conffile))
+        virCommandAddArgPair(cmd, "--conf-file", conffile);
+    else
+        virCommandAddArgList(cmd, "--conf-file=", "", NULL);

     /*
      * XXX does not actually work, due to some kind of
@@ -528,35 +532,41 @@ dhcpStartDhcpDaemon(virNetworkObjPtr network)
     virCommandPtr cmd = NULL;
     char *pidfile = NULL;
     int ret = -1, err;
+    char *conffile = NULL;

     network->dnsmasqPid = -1;

     if (!VIR_SOCKET_IS_FAMILY(&network->def->ipAddress, AF_INET)) {
         networkReportError(VIR_ERR_INTERNAL_ERROR,
                            "%s", _("cannot start dhcp daemon without
IPv4 address for server"));
-        goto cleanup2;
+        goto cleanup3;
     }

     if ((err = virFileMakePath(NETWORK_PID_DIR)) != 0) {
         virReportSystemError(err,
                              _("cannot create directory %s"),
                              NETWORK_PID_DIR);
-        goto cleanup2;
+        goto cleanup3;
     }
     if ((err = virFileMakePath(NETWORK_STATE_DIR)) != 0) {
         virReportSystemError(err,
                              _("cannot create directory %s"),
                              NETWORK_STATE_DIR);
-        goto cleanup2;
+        goto cleanup3;
     }

     if (!(pidfile = virFilePid(NETWORK_PID_DIR, network->def->name))) {
         virReportOOMError();
+        goto cleanup3;
+    }
+
+    if (virAsprintf(&conffile, DNSMASQ_STATE_DIR "/%s-dnsmasq.conf",
network->def->name) < 0) {
+        virReportOOMError();
         goto cleanup2;
     }

     cmd = virCommandNew(DNSMASQ);
-    if (networkBuildDnsmasqArgv(network, pidfile, cmd) < 0) {
+    if (networkBuildDnsmasqArgv(network, pidfile, conffile, cmd) < 0) {
         goto cleanup1;
     }

@@ -577,9 +587,11 @@ dhcpStartDhcpDaemon(virNetworkObjPtr network)

     ret = 0;
 cleanup1:
-    VIR_FREE(pidfile);
     virCommandFree(cmd);
+    VIR_FREE(conffile);
 cleanup2:
+    VIR_FREE(pidfile);
+cleanup3:
     return ret;
 }

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]