2010-04-26 13:52:02 +00:00
|
|
|
/*
|
2012-12-12 16:43:54 +00:00
|
|
|
* virdnsmasq.c: Helper APIs for managing dnsmasq
|
|
|
|
*
|
2013-05-02 19:35:26 +00:00
|
|
|
* Copyright (C) 2007-2013 Red Hat, Inc.
|
2010-04-26 13:52:02 +00:00
|
|
|
* Copyright (C) 2010 Satoru SATOH <satoru.satoh@gmail.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2010-04-26 13:52:02 +00:00
|
|
|
*
|
|
|
|
* Based on iptables.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
#include "internal.h"
|
|
|
|
#include "datatypes.h"
|
2012-12-04 11:56:32 +00:00
|
|
|
#include "virbitmap.h"
|
2012-12-12 16:43:54 +00:00
|
|
|
#include "virdnsmasq.h"
|
2012-12-13 17:44:57 +00:00
|
|
|
#include "virutil.h"
|
2012-12-12 16:27:01 +00:00
|
|
|
#include "vircommand.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2012-12-13 18:21:53 +00:00
|
|
|
#include "virerror.h"
|
2012-12-12 17:59:27 +00:00
|
|
|
#include "virlog.h"
|
2011-07-19 18:32:58 +00:00
|
|
|
#include "virfile.h"
|
2013-04-03 10:36:23 +00:00
|
|
|
#include "virstring.h"
|
2010-04-26 13:52:02 +00:00
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_NETWORK
|
2014-02-28 12:16:17 +00:00
|
|
|
|
|
|
|
VIR_LOG_INIT("util.dnsmasq");
|
|
|
|
|
2022-01-10 15:19:31 +00:00
|
|
|
#define DNSMASQ "dnsmasq"
|
2010-04-26 13:52:02 +00:00
|
|
|
#define DNSMASQ_HOSTSFILE_SUFFIX "hostsfile"
|
2011-06-24 10:04:39 +00:00
|
|
|
#define DNSMASQ_ADDNHOSTSFILE_SUFFIX "addnhosts"
|
2010-04-26 13:52:02 +00:00
|
|
|
|
2021-12-14 16:36:23 +00:00
|
|
|
#define DNSMASQ_MIN_MAJOR 2
|
|
|
|
#define DNSMASQ_MIN_MINOR 67
|
|
|
|
|
2010-04-26 13:52:02 +00:00
|
|
|
static void
|
util: rename two *Free() functions while changing VIR_FREE to g_free
dhcpHostFree() and addnHostFree() don't follow the normal pattern of
*Free functions in the rest of libvirt code - they are actually more
similar to the *Dispose() functions, in that they free all subordinate
objects, but not the object pointed to by the argument
itself. However, the arguments aren't virObjects, so it wouldn't be
proper to name them *Dispose() either.
They *currently* behave similar to a *Clear() function, in that they
free all the subordinate objects and nullify the pointers of those
objects. HOWEVER, we don't actually need or want that behavior - the
two functions in question are only called as part of a higher level
*Free() function, and the pointers are not referenced in any way
between the time they are freed and when the parent object is freed.
So, since the current name isn't correct, nor is *Dispose(), and we
want to change the behavior in such a way that *Clear() also wouldn't
be correct, lets name the functions *FreeContent(), which is an
accurate description of what the functions do, and what we *want* them
to do.
And since it's such a small patch, we can go ahead and change that
behavior - replacing the VIR_FREEs with g_free.
Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2021-02-04 02:38:59 +00:00
|
|
|
dhcphostFreeContent(dnsmasqDhcpHost *host)
|
2010-04-26 13:52:02 +00:00
|
|
|
{
|
util: rename two *Free() functions while changing VIR_FREE to g_free
dhcpHostFree() and addnHostFree() don't follow the normal pattern of
*Free functions in the rest of libvirt code - they are actually more
similar to the *Dispose() functions, in that they free all subordinate
objects, but not the object pointed to by the argument
itself. However, the arguments aren't virObjects, so it wouldn't be
proper to name them *Dispose() either.
They *currently* behave similar to a *Clear() function, in that they
free all the subordinate objects and nullify the pointers of those
objects. HOWEVER, we don't actually need or want that behavior - the
two functions in question are only called as part of a higher level
*Free() function, and the pointers are not referenced in any way
between the time they are freed and when the parent object is freed.
So, since the current name isn't correct, nor is *Dispose(), and we
want to change the behavior in such a way that *Clear() also wouldn't
be correct, lets name the functions *FreeContent(), which is an
accurate description of what the functions do, and what we *want* them
to do.
And since it's such a small patch, we can go ahead and change that
behavior - replacing the VIR_FREEs with g_free.
Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2021-02-04 02:38:59 +00:00
|
|
|
g_free(host->host);
|
2010-04-26 13:52:02 +00:00
|
|
|
}
|
|
|
|
|
2011-06-24 10:04:39 +00:00
|
|
|
static void
|
util: rename two *Free() functions while changing VIR_FREE to g_free
dhcpHostFree() and addnHostFree() don't follow the normal pattern of
*Free functions in the rest of libvirt code - they are actually more
similar to the *Dispose() functions, in that they free all subordinate
objects, but not the object pointed to by the argument
itself. However, the arguments aren't virObjects, so it wouldn't be
proper to name them *Dispose() either.
They *currently* behave similar to a *Clear() function, in that they
free all the subordinate objects and nullify the pointers of those
objects. HOWEVER, we don't actually need or want that behavior - the
two functions in question are only called as part of a higher level
*Free() function, and the pointers are not referenced in any way
between the time they are freed and when the parent object is freed.
So, since the current name isn't correct, nor is *Dispose(), and we
want to change the behavior in such a way that *Clear() also wouldn't
be correct, lets name the functions *FreeContent(), which is an
accurate description of what the functions do, and what we *want* them
to do.
And since it's such a small patch, we can go ahead and change that
behavior - replacing the VIR_FREEs with g_free.
Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2021-02-04 02:38:59 +00:00
|
|
|
addnhostFreeContent(dnsmasqAddnHost *host)
|
2011-06-24 10:04:39 +00:00
|
|
|
{
|
Convert 'int i' to 'size_t i' in src/util/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2011-06-24 10:04:39 +00:00
|
|
|
|
|
|
|
for (i = 0; i < host->nhostnames; i++)
|
util: rename two *Free() functions while changing VIR_FREE to g_free
dhcpHostFree() and addnHostFree() don't follow the normal pattern of
*Free functions in the rest of libvirt code - they are actually more
similar to the *Dispose() functions, in that they free all subordinate
objects, but not the object pointed to by the argument
itself. However, the arguments aren't virObjects, so it wouldn't be
proper to name them *Dispose() either.
They *currently* behave similar to a *Clear() function, in that they
free all the subordinate objects and nullify the pointers of those
objects. HOWEVER, we don't actually need or want that behavior - the
two functions in question are only called as part of a higher level
*Free() function, and the pointers are not referenced in any way
between the time they are freed and when the parent object is freed.
So, since the current name isn't correct, nor is *Dispose(), and we
want to change the behavior in such a way that *Clear() also wouldn't
be correct, lets name the functions *FreeContent(), which is an
accurate description of what the functions do, and what we *want* them
to do.
And since it's such a small patch, we can go ahead and change that
behavior - replacing the VIR_FREEs with g_free.
Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2021-02-04 02:38:59 +00:00
|
|
|
g_free(host->hostnames[i]);
|
|
|
|
g_free(host->hostnames);
|
|
|
|
g_free(host->ip);
|
2011-06-24 10:04:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
addnhostsFree(dnsmasqAddnHostsfile *addnhostsfile)
|
|
|
|
{
|
Convert 'int i' to 'size_t i' in src/util/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2011-06-24 10:04:39 +00:00
|
|
|
|
|
|
|
if (addnhostsfile->hosts) {
|
|
|
|
for (i = 0; i < addnhostsfile->nhosts; i++)
|
util: rename two *Free() functions while changing VIR_FREE to g_free
dhcpHostFree() and addnHostFree() don't follow the normal pattern of
*Free functions in the rest of libvirt code - they are actually more
similar to the *Dispose() functions, in that they free all subordinate
objects, but not the object pointed to by the argument
itself. However, the arguments aren't virObjects, so it wouldn't be
proper to name them *Dispose() either.
They *currently* behave similar to a *Clear() function, in that they
free all the subordinate objects and nullify the pointers of those
objects. HOWEVER, we don't actually need or want that behavior - the
two functions in question are only called as part of a higher level
*Free() function, and the pointers are not referenced in any way
between the time they are freed and when the parent object is freed.
So, since the current name isn't correct, nor is *Dispose(), and we
want to change the behavior in such a way that *Clear() also wouldn't
be correct, lets name the functions *FreeContent(), which is an
accurate description of what the functions do, and what we *want* them
to do.
And since it's such a small patch, we can go ahead and change that
behavior - replacing the VIR_FREEs with g_free.
Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2021-02-04 02:38:59 +00:00
|
|
|
addnhostFreeContent(&addnhostsfile->hosts[i]);
|
2011-06-24 10:04:39 +00:00
|
|
|
|
2021-02-03 19:32:34 +00:00
|
|
|
g_free(addnhostsfile->hosts);
|
2011-06-24 10:04:39 +00:00
|
|
|
|
|
|
|
addnhostsfile->nhosts = 0;
|
|
|
|
}
|
|
|
|
|
2021-02-03 19:32:34 +00:00
|
|
|
g_free(addnhostsfile->path);
|
2011-06-24 10:04:39 +00:00
|
|
|
|
2021-02-03 19:32:34 +00:00
|
|
|
g_free(addnhostsfile);
|
2011-06-24 10:04:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
addnhostsAdd(dnsmasqAddnHostsfile *addnhostsfile,
|
|
|
|
virSocketAddr *ip,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
char *ipstr = NULL;
|
|
|
|
int idx = -1;
|
Convert 'int i' to 'size_t i' in src/util/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2011-06-24 10:04:39 +00:00
|
|
|
|
Santize naming of socket address APIs
The socket address APIs in src/util/network.h either take the
form virSocketAddrXXX, virSocketXXX or virSocketXXXAddr.
Sanitize this so everything is virSocketAddrXXXX, and ensure
that the virSocketAddr parameter is always the first one.
* src/util/network.c, src/util/network.h: Santize socket
address API naming
* src/conf/domain_conf.c, src/conf/network_conf.c,
src/conf/nwfilter_conf.c, src/network/bridge_driver.c,
src/nwfilter/nwfilter_ebiptables_driver.c,
src/nwfilter/nwfilter_learnipaddr.c,
src/qemu/qemu_command.c, src/rpc/virnetsocket.c,
src/util/dnsmasq.c, src/util/iptables.c,
src/util/virnetdev.c, src/vbox/vbox_tmpl.c: Update for
API renaming
2011-11-02 14:06:59 +00:00
|
|
|
if (!(ipstr = virSocketAddrFormat(ip)))
|
2011-06-24 10:04:39 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
for (i = 0; i < addnhostsfile->nhosts; i++) {
|
|
|
|
if (STREQ((const char *)addnhostsfile->hosts[i].ip, (const char *)ipstr)) {
|
|
|
|
idx = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (idx < 0) {
|
2021-03-19 23:37:05 +00:00
|
|
|
VIR_REALLOC_N(addnhostsfile->hosts, addnhostsfile->nhosts + 1);
|
2011-06-24 10:04:39 +00:00
|
|
|
|
|
|
|
idx = addnhostsfile->nhosts;
|
2020-10-05 17:12:37 +00:00
|
|
|
addnhostsfile->hosts[idx].hostnames = g_new0(char *, 1);
|
2011-06-24 10:04:39 +00:00
|
|
|
|
2019-10-20 11:49:46 +00:00
|
|
|
addnhostsfile->hosts[idx].ip = g_strdup(ipstr);
|
2011-06-24 10:04:39 +00:00
|
|
|
|
|
|
|
addnhostsfile->hosts[idx].nhostnames = 0;
|
|
|
|
addnhostsfile->nhosts++;
|
|
|
|
}
|
|
|
|
|
2021-03-19 23:37:05 +00:00
|
|
|
VIR_REALLOC_N(addnhostsfile->hosts[idx].hostnames, addnhostsfile->hosts[idx].nhostnames + 1);
|
2011-06-24 10:04:39 +00:00
|
|
|
|
2019-10-20 11:49:46 +00:00
|
|
|
addnhostsfile->hosts[idx].hostnames[addnhostsfile->hosts[idx].nhostnames] = g_strdup(name);
|
2011-06-24 10:04:39 +00:00
|
|
|
|
|
|
|
VIR_FREE(ipstr);
|
|
|
|
|
|
|
|
addnhostsfile->hosts[idx].nhostnames++;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static dnsmasqAddnHostsfile *
|
|
|
|
addnhostsNew(const char *name,
|
|
|
|
const char *config_dir)
|
|
|
|
{
|
|
|
|
dnsmasqAddnHostsfile *addnhostsfile;
|
2020-07-03 02:30:20 +00:00
|
|
|
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
2011-06-24 10:04:39 +00:00
|
|
|
|
2020-10-05 17:12:37 +00:00
|
|
|
addnhostsfile = g_new0(dnsmasqAddnHostsfile, 1);
|
2011-06-24 10:04:39 +00:00
|
|
|
|
|
|
|
addnhostsfile->hosts = NULL;
|
|
|
|
addnhostsfile->nhosts = 0;
|
|
|
|
|
2015-06-01 08:10:04 +00:00
|
|
|
virBufferAsprintf(&buf, "%s", config_dir);
|
|
|
|
virBufferEscapeString(&buf, "/%s", name);
|
|
|
|
virBufferAsprintf(&buf, ".%s", DNSMASQ_ADDNHOSTSFILE_SUFFIX);
|
|
|
|
|
|
|
|
if (!(addnhostsfile->path = virBufferContentAndReset(&buf)))
|
2011-06-24 10:04:39 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
return addnhostsfile;
|
|
|
|
|
|
|
|
error:
|
|
|
|
addnhostsFree(addnhostsfile);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
addnhostsWrite(const char *path,
|
|
|
|
dnsmasqAddnHost *hosts,
|
|
|
|
unsigned int nhosts)
|
|
|
|
{
|
2020-11-23 22:09:39 +00:00
|
|
|
g_autofree char *tmp = NULL;
|
2011-06-24 10:04:39 +00:00
|
|
|
FILE *f;
|
|
|
|
bool istmp = true;
|
Convert 'int i' to 'size_t i' in src/util/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i, j;
|
2011-06-24 10:04:39 +00:00
|
|
|
int rc = 0;
|
|
|
|
|
network: always create dnsmasq hosts and addnhosts files, even if empty
This fixes the problem reported in:
https://bugzilla.redhat.com/show_bug.cgi?id=868389
Previously, the dnsmasq hosts file (used for static dhcp entries, and
addnhosts file (used for additional dns host entries) were only
created/referenced on the dnsmasq commandline if there was something
to put in them at the time the network was started. Once we can update
a network definition while it's active (which is now possible with
virNetworkUpdate), this is no longer a valid strategy - if there were
0 dhcp static hosts (resulting in no reference to the hosts file on the
commandline), then one was later added, the commandline wouldn't have
linked dnsmasq up to the file, so even though we create it, dnsmasq
doesn't pay any attention.
The solution is to just always create these files and reference them
on the dnsmasq commandline (almost always, anyway). That way dnsmasq
can notice when a new entry is added at runtime (a SIGHUP is sent to
dnsmasq by virNetworkUdpate whenever a host entry is added or removed)
The exception to this is that the dhcp static hosts file isn't created
if there are no lease ranges *and* no static hosts. This is because in
this case dnsmasq won't be setup to listen for dhcp requests anyway -
in that case, if the count of dhcp hosts goes from 0 to 1, dnsmasq
will need to be restarted anyway (to get it listening on the dhcp
port). Likewise, if the dhcp hosts count goes from 1 to 0 (and there
are no dhcp ranges) we need to restart dnsmasq so that it will stop
listening on port 67. These special situations are handled in the
bridge driver's networkUpdate() by checking for ((bool)
nranges||nhosts) both before and after the update, and triggering a
dnsmasq restart if the before and after don't match.
2012-10-19 20:15:44 +00:00
|
|
|
/* even if there are 0 hosts, create a 0 length file, to allow
|
|
|
|
* for runtime addition.
|
|
|
|
*/
|
2011-06-24 10:04:39 +00:00
|
|
|
|
2019-10-22 13:26:14 +00:00
|
|
|
tmp = g_strdup_printf("%s.new", path);
|
2011-06-24 10:04:39 +00:00
|
|
|
|
|
|
|
if (!(f = fopen(tmp, "w"))) {
|
|
|
|
istmp = false;
|
2021-11-04 14:26:07 +00:00
|
|
|
if (!(f = fopen(path, "w")))
|
|
|
|
return -errno;
|
2011-06-24 10:04:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < nhosts; i++) {
|
|
|
|
if (fputs(hosts[i].ip, f) == EOF || fputc('\t', f) == EOF) {
|
2011-06-28 23:50:06 +00:00
|
|
|
rc = -errno;
|
2011-06-24 10:04:39 +00:00
|
|
|
VIR_FORCE_FCLOSE(f);
|
|
|
|
|
|
|
|
if (istmp)
|
|
|
|
unlink(tmp);
|
|
|
|
|
2021-11-04 14:26:07 +00:00
|
|
|
return rc;
|
2011-06-24 10:04:39 +00:00
|
|
|
}
|
|
|
|
|
Convert 'int i' to 'size_t i' in src/util/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
for (j = 0; j < hosts[i].nhostnames; j++) {
|
|
|
|
if (fputs(hosts[i].hostnames[j], f) == EOF || fputc('\t', f) == EOF) {
|
2011-06-28 23:50:06 +00:00
|
|
|
rc = -errno;
|
2011-06-24 10:04:39 +00:00
|
|
|
VIR_FORCE_FCLOSE(f);
|
|
|
|
|
|
|
|
if (istmp)
|
|
|
|
unlink(tmp);
|
|
|
|
|
2021-11-04 14:26:07 +00:00
|
|
|
return rc;
|
2011-06-24 10:04:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fputc('\n', f) == EOF) {
|
2011-06-28 23:50:06 +00:00
|
|
|
rc = -errno;
|
2011-06-24 10:04:39 +00:00
|
|
|
VIR_FORCE_FCLOSE(f);
|
|
|
|
|
|
|
|
if (istmp)
|
|
|
|
unlink(tmp);
|
|
|
|
|
2021-11-04 14:26:07 +00:00
|
|
|
return rc;
|
2011-06-24 10:04:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-04 14:26:07 +00:00
|
|
|
if (VIR_FCLOSE(f) == EOF)
|
|
|
|
return -errno;
|
2011-06-24 10:04:39 +00:00
|
|
|
|
2011-06-28 23:50:06 +00:00
|
|
|
if (istmp && rename(tmp, path) < 0) {
|
|
|
|
rc = -errno;
|
|
|
|
unlink(tmp);
|
2021-11-04 14:26:07 +00:00
|
|
|
return rc;
|
2011-06-24 10:04:39 +00:00
|
|
|
}
|
|
|
|
|
2021-11-04 14:26:07 +00:00
|
|
|
return 0;
|
2011-06-24 10:04:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
addnhostsSave(dnsmasqAddnHostsfile *addnhostsfile)
|
|
|
|
{
|
|
|
|
int err = addnhostsWrite(addnhostsfile->path, addnhostsfile->hosts,
|
|
|
|
addnhostsfile->nhosts);
|
|
|
|
|
|
|
|
if (err < 0) {
|
2011-06-28 23:50:06 +00:00
|
|
|
virReportSystemError(-err, _("cannot write config file '%s'"),
|
2011-06-24 10:04:39 +00:00
|
|
|
addnhostsfile->path);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
genericFileDelete(char *path)
|
|
|
|
{
|
|
|
|
if (!virFileExists(path))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (unlink(path) < 0) {
|
|
|
|
virReportSystemError(errno, _("cannot remove config file '%s'"),
|
|
|
|
path);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-04-26 13:52:02 +00:00
|
|
|
static void
|
|
|
|
hostsfileFree(dnsmasqHostsfile *hostsfile)
|
|
|
|
{
|
Convert 'int i' to 'size_t i' in src/util/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2010-04-26 13:52:02 +00:00
|
|
|
|
|
|
|
if (hostsfile->hosts) {
|
|
|
|
for (i = 0; i < hostsfile->nhosts; i++)
|
util: rename two *Free() functions while changing VIR_FREE to g_free
dhcpHostFree() and addnHostFree() don't follow the normal pattern of
*Free functions in the rest of libvirt code - they are actually more
similar to the *Dispose() functions, in that they free all subordinate
objects, but not the object pointed to by the argument
itself. However, the arguments aren't virObjects, so it wouldn't be
proper to name them *Dispose() either.
They *currently* behave similar to a *Clear() function, in that they
free all the subordinate objects and nullify the pointers of those
objects. HOWEVER, we don't actually need or want that behavior - the
two functions in question are only called as part of a higher level
*Free() function, and the pointers are not referenced in any way
between the time they are freed and when the parent object is freed.
So, since the current name isn't correct, nor is *Dispose(), and we
want to change the behavior in such a way that *Clear() also wouldn't
be correct, lets name the functions *FreeContent(), which is an
accurate description of what the functions do, and what we *want* them
to do.
And since it's such a small patch, we can go ahead and change that
behavior - replacing the VIR_FREEs with g_free.
Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2021-02-04 02:38:59 +00:00
|
|
|
dhcphostFreeContent(&hostsfile->hosts[i]);
|
2010-04-26 13:52:02 +00:00
|
|
|
|
2021-02-03 19:32:34 +00:00
|
|
|
g_free(hostsfile->hosts);
|
2010-04-26 13:52:02 +00:00
|
|
|
|
|
|
|
hostsfile->nhosts = 0;
|
|
|
|
}
|
|
|
|
|
2021-02-03 19:32:34 +00:00
|
|
|
g_free(hostsfile->path);
|
2010-04-26 13:52:02 +00:00
|
|
|
|
2021-02-03 19:32:34 +00:00
|
|
|
g_free(hostsfile);
|
2010-04-26 13:52:02 +00:00
|
|
|
}
|
|
|
|
|
2012-12-06 17:20:38 +00:00
|
|
|
/* Note: There are many additional dhcp-host specifications
|
|
|
|
* supported by dnsmasq. There are only the basic ones.
|
|
|
|
*/
|
2010-04-26 13:52:02 +00:00
|
|
|
static int
|
|
|
|
hostsfileAdd(dnsmasqHostsfile *hostsfile,
|
|
|
|
const char *mac,
|
Convert virNetwork to use virSocketAddr everywhere
Instead of storing the IP address string in virNetwork related
structs, store the parsed virSocketAddr. This will make it
easier to add IPv6 support in the future, by letting driver
code directly check what address family is present
* src/conf/network_conf.c, src/conf/network_conf.h,
src/network/bridge_driver.c: Convert to use virSocketAddr
in virNetwork, instead of char *.
* src/util/bridge.c, src/util/bridge.h,
src/util/dnsmasq.c, src/util/dnsmasq.h,
src/util/iptables.c, src/util/iptables.h: Convert to
take a virSocketAddr instead of char * for any IP
address parameters
* src/util/network.h: Add macros to determine if an address
is set, and what address family is set.
2010-10-21 12:14:33 +00:00
|
|
|
virSocketAddr *ip,
|
2012-12-06 17:20:38 +00:00
|
|
|
const char *name,
|
2013-02-15 19:02:26 +00:00
|
|
|
const char *id,
|
2020-04-22 20:05:57 +00:00
|
|
|
const char *leasetime,
|
2012-12-06 17:20:38 +00:00
|
|
|
bool ipv6)
|
2010-04-26 13:52:02 +00:00
|
|
|
{
|
2020-04-22 20:05:57 +00:00
|
|
|
g_autofree char *ipstr = NULL;
|
|
|
|
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
|
|
|
|
2021-03-19 23:37:05 +00:00
|
|
|
VIR_REALLOC_N(hostsfile->hosts, hostsfile->nhosts + 1);
|
2010-04-26 13:52:02 +00:00
|
|
|
|
Santize naming of socket address APIs
The socket address APIs in src/util/network.h either take the
form virSocketAddrXXX, virSocketXXX or virSocketXXXAddr.
Sanitize this so everything is virSocketAddrXXXX, and ensure
that the virSocketAddr parameter is always the first one.
* src/util/network.c, src/util/network.h: Santize socket
address API naming
* src/conf/domain_conf.c, src/conf/network_conf.c,
src/conf/nwfilter_conf.c, src/network/bridge_driver.c,
src/nwfilter/nwfilter_ebiptables_driver.c,
src/nwfilter/nwfilter_learnipaddr.c,
src/qemu/qemu_command.c, src/rpc/virnetsocket.c,
src/util/dnsmasq.c, src/util/iptables.c,
src/util/virnetdev.c, src/vbox/vbox_tmpl.c: Update for
API renaming
2011-11-02 14:06:59 +00:00
|
|
|
if (!(ipstr = virSocketAddrFormat(ip)))
|
Convert virNetwork to use virSocketAddr everywhere
Instead of storing the IP address string in virNetwork related
structs, store the parsed virSocketAddr. This will make it
easier to add IPv6 support in the future, by letting driver
code directly check what address family is present
* src/conf/network_conf.c, src/conf/network_conf.h,
src/network/bridge_driver.c: Convert to use virSocketAddr
in virNetwork, instead of char *.
* src/util/bridge.c, src/util/bridge.h,
src/util/dnsmasq.c, src/util/dnsmasq.h,
src/util/iptables.c, src/util/iptables.h: Convert to
take a virSocketAddr instead of char * for any IP
address parameters
* src/util/network.h: Add macros to determine if an address
is set, and what address family is set.
2010-10-21 12:14:33 +00:00
|
|
|
return -1;
|
|
|
|
|
2012-12-06 17:20:38 +00:00
|
|
|
/* the first test determines if it is a dhcpv6 host */
|
|
|
|
if (ipv6) {
|
2013-02-15 19:02:26 +00:00
|
|
|
if (name && id) {
|
2020-04-22 20:05:57 +00:00
|
|
|
virBufferAsprintf(&buf, "id:%s,%s", id, name);
|
2013-02-15 19:02:26 +00:00
|
|
|
} else if (name && !id) {
|
2020-04-22 20:05:57 +00:00
|
|
|
virBufferAsprintf(&buf, "%s", name);
|
2013-02-15 19:02:26 +00:00
|
|
|
} else if (!name && id) {
|
2020-04-22 20:05:57 +00:00
|
|
|
virBufferAsprintf(&buf, "id:%s", id);
|
2013-02-15 19:02:26 +00:00
|
|
|
}
|
2020-04-22 20:05:57 +00:00
|
|
|
virBufferAsprintf(&buf, ",[%s]", ipstr);
|
2013-02-15 19:02:26 +00:00
|
|
|
} else if (name && mac) {
|
2020-04-22 20:05:57 +00:00
|
|
|
virBufferAsprintf(&buf, "%s,%s,%s", mac, ipstr, name);
|
2014-08-20 11:00:30 +00:00
|
|
|
} else if (name && !mac) {
|
2020-04-22 20:05:57 +00:00
|
|
|
virBufferAsprintf(&buf, "%s,%s", name, ipstr);
|
2010-04-26 13:52:02 +00:00
|
|
|
} else {
|
2020-04-22 20:05:57 +00:00
|
|
|
virBufferAsprintf(&buf, "%s,%s", mac, ipstr);
|
2010-04-26 13:52:02 +00:00
|
|
|
}
|
2020-04-22 20:05:57 +00:00
|
|
|
|
|
|
|
if (leasetime)
|
|
|
|
virBufferAsprintf(&buf, ",%s", leasetime);
|
|
|
|
|
|
|
|
if (!(hostsfile->hosts[hostsfile->nhosts].host = virBufferContentAndReset(&buf)))
|
|
|
|
return -1;
|
2010-04-26 13:52:02 +00:00
|
|
|
|
|
|
|
hostsfile->nhosts++;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static dnsmasqHostsfile *
|
|
|
|
hostsfileNew(const char *name,
|
|
|
|
const char *config_dir)
|
|
|
|
{
|
|
|
|
dnsmasqHostsfile *hostsfile;
|
2020-07-03 02:30:20 +00:00
|
|
|
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
2010-04-26 13:52:02 +00:00
|
|
|
|
2020-10-05 17:12:37 +00:00
|
|
|
hostsfile = g_new0(dnsmasqHostsfile, 1);
|
2010-04-26 13:52:02 +00:00
|
|
|
|
|
|
|
hostsfile->hosts = NULL;
|
|
|
|
hostsfile->nhosts = 0;
|
|
|
|
|
2015-06-01 08:10:04 +00:00
|
|
|
virBufferAsprintf(&buf, "%s", config_dir);
|
|
|
|
virBufferEscapeString(&buf, "/%s", name);
|
|
|
|
virBufferAsprintf(&buf, ".%s", DNSMASQ_HOSTSFILE_SUFFIX);
|
2010-04-26 13:52:02 +00:00
|
|
|
|
2015-06-01 08:10:04 +00:00
|
|
|
if (!(hostsfile->path = virBufferContentAndReset(&buf)))
|
|
|
|
goto error;
|
2010-04-26 13:52:02 +00:00
|
|
|
return hostsfile;
|
|
|
|
|
|
|
|
error:
|
|
|
|
hostsfileFree(hostsfile);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
hostsfileWrite(const char *path,
|
|
|
|
dnsmasqDhcpHost *hosts,
|
|
|
|
unsigned int nhosts)
|
|
|
|
{
|
2020-11-23 22:09:39 +00:00
|
|
|
g_autofree char *tmp = NULL;
|
2010-04-26 13:52:02 +00:00
|
|
|
FILE *f;
|
|
|
|
bool istmp = true;
|
Convert 'int i' to 'size_t i' in src/util/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2010-04-26 13:52:02 +00:00
|
|
|
int rc = 0;
|
|
|
|
|
network: always create dnsmasq hosts and addnhosts files, even if empty
This fixes the problem reported in:
https://bugzilla.redhat.com/show_bug.cgi?id=868389
Previously, the dnsmasq hosts file (used for static dhcp entries, and
addnhosts file (used for additional dns host entries) were only
created/referenced on the dnsmasq commandline if there was something
to put in them at the time the network was started. Once we can update
a network definition while it's active (which is now possible with
virNetworkUpdate), this is no longer a valid strategy - if there were
0 dhcp static hosts (resulting in no reference to the hosts file on the
commandline), then one was later added, the commandline wouldn't have
linked dnsmasq up to the file, so even though we create it, dnsmasq
doesn't pay any attention.
The solution is to just always create these files and reference them
on the dnsmasq commandline (almost always, anyway). That way dnsmasq
can notice when a new entry is added at runtime (a SIGHUP is sent to
dnsmasq by virNetworkUdpate whenever a host entry is added or removed)
The exception to this is that the dhcp static hosts file isn't created
if there are no lease ranges *and* no static hosts. This is because in
this case dnsmasq won't be setup to listen for dhcp requests anyway -
in that case, if the count of dhcp hosts goes from 0 to 1, dnsmasq
will need to be restarted anyway (to get it listening on the dhcp
port). Likewise, if the dhcp hosts count goes from 1 to 0 (and there
are no dhcp ranges) we need to restart dnsmasq so that it will stop
listening on port 67. These special situations are handled in the
bridge driver's networkUpdate() by checking for ((bool)
nranges||nhosts) both before and after the update, and triggering a
dnsmasq restart if the before and after don't match.
2012-10-19 20:15:44 +00:00
|
|
|
/* even if there are 0 hosts, create a 0 length file, to allow
|
|
|
|
* for runtime addition.
|
|
|
|
*/
|
2010-04-26 13:52:02 +00:00
|
|
|
|
2019-10-22 13:26:14 +00:00
|
|
|
tmp = g_strdup_printf("%s.new", path);
|
2010-04-26 13:52:02 +00:00
|
|
|
|
|
|
|
if (!(f = fopen(tmp, "w"))) {
|
|
|
|
istmp = false;
|
2021-11-04 14:26:07 +00:00
|
|
|
if (!(f = fopen(path, "w")))
|
|
|
|
return -errno;
|
2010-04-26 13:52:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < nhosts; i++) {
|
|
|
|
if (fputs(hosts[i].host, f) == EOF || fputc('\n', f) == EOF) {
|
2011-04-27 18:11:14 +00:00
|
|
|
rc = -errno;
|
2010-11-17 02:13:29 +00:00
|
|
|
VIR_FORCE_FCLOSE(f);
|
2010-04-26 13:52:02 +00:00
|
|
|
|
|
|
|
if (istmp)
|
|
|
|
unlink(tmp);
|
|
|
|
|
2021-11-04 14:26:07 +00:00
|
|
|
return rc;
|
2010-04-26 13:52:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-04 14:26:07 +00:00
|
|
|
if (VIR_FCLOSE(f) == EOF)
|
|
|
|
return -errno;
|
2010-04-26 13:52:02 +00:00
|
|
|
|
2011-06-28 23:50:06 +00:00
|
|
|
if (istmp && rename(tmp, path) < 0) {
|
|
|
|
rc = -errno;
|
|
|
|
unlink(tmp);
|
2021-11-04 14:26:07 +00:00
|
|
|
return rc;
|
2010-04-26 13:52:02 +00:00
|
|
|
}
|
|
|
|
|
2021-11-04 14:26:07 +00:00
|
|
|
return 0;
|
2010-04-26 13:52:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
hostsfileSave(dnsmasqHostsfile *hostsfile)
|
|
|
|
{
|
|
|
|
int err = hostsfileWrite(hostsfile->path, hostsfile->hosts,
|
2010-05-03 10:26:42 +00:00
|
|
|
hostsfile->nhosts);
|
2010-04-26 13:52:02 +00:00
|
|
|
|
|
|
|
if (err < 0) {
|
2011-06-28 23:50:06 +00:00
|
|
|
virReportSystemError(-err, _("cannot write config file '%s'"),
|
2010-05-03 10:26:42 +00:00
|
|
|
hostsfile->path);
|
2010-04-26 13:52:02 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* dnsmasqContextNew:
|
|
|
|
*
|
|
|
|
* Create a new Dnsmasq context
|
|
|
|
*
|
|
|
|
* Returns a pointer to the new structure or NULL in case of error
|
|
|
|
*/
|
|
|
|
dnsmasqContext *
|
|
|
|
dnsmasqContextNew(const char *network_name,
|
|
|
|
const char *config_dir)
|
|
|
|
{
|
|
|
|
dnsmasqContext *ctx;
|
|
|
|
|
2020-10-05 17:12:37 +00:00
|
|
|
ctx = g_new0(dnsmasqContext, 1);
|
2010-04-26 13:52:02 +00:00
|
|
|
|
2019-10-20 11:49:46 +00:00
|
|
|
ctx->config_dir = g_strdup(config_dir);
|
network: Fix dnsmasq hostsfile creation logic and related tests
networkSaveDnsmasqHostsfile was added in 8fa9c2214247 (Apr 2010).
It has a force flag. If the dnsmasq hostsfile already exists force
needs to be true to overwrite it. networkBuildDnsmasqArgv sets force
to false, networkDefine sets it to true. This results in the
hostsfile being written only in networkDefine in the common case.
If no error occurred networkSaveDnsmasqHostsfile returns true and
networkBuildDnsmasqArgv adds the --dhcp-hostsfile to the dnsmasq
command line.
networkSaveDnsmasqHostsfile was changed in 89ae9849f744 (24 Jun 2011)
to return a new dnsmasqContext instead of reusing one. This change broke
the logic of the force flag as now networkSaveDnsmasqHostsfile returns
NULL on error, but the early return -- if force was not set and the
hostsfile exists -- returns 0. This turned the early return in an error
case and networkBuildDnsmasqArgv didn't add the --dhcp-hostsfile option
anymore if the hostsfile already exists. It did because networkDefine
created the hostsfile already.
Then 9d4e2845d498 fixed the return 0 case in networkSaveDnsmasqHostsfile
but didn't apply the force option correctly to the new addnhosts file.
Now force doesn't control an early return anymore, but influences the
handling of the hostsfile context creation and dnsmasqSave is always
called now. This commit also added test cases that reveal several
problems. First, the tests now calls functions that try to write the
dnsmasq config files to disk. If someone runs this tests as root this
might overwrite actively used dnsmasq config files, this is a no-go. Also
the tests depend on configure --localstatedir, this needs to be fixed as
well, because it makes the tests fail when localstatedir is different
from /var.
This patch does several things to fix this:
1) Move dnsmasqContext creation and saving out of networkBuildDnsmasqArgv
to the caller to separate the command line generation from the config
file writing. This makes the command line generation testable without the
risk of interfering with system files, because the tests just don't call
dnsmasqSave.
2) This refactoring of networkSaveDnsmasqHostsfile makes the force flag
useless as the saving happens somewhere else now. This fixes the wrong
usage of the force flag in combination with then newly added addnhosts
file by removing the force flag.
3) Adapt the wrong test cases to the correct behavior, by adding the
missing --dhcp-hostsfile option. Both affected tests contain DHCP host
elements but missed the necessary --dhcp-hostsfile option.
4) Rename networkSaveDnsmasqHostsfile to networkBuildDnsmasqHostsfile,
because it doesn't save the dnsmasqContext anymore.
5) Move all directory creations in dnsmasq context handling code from
the *New functions to dnsmasqSave to avoid directory creations in system
paths in the test cases.
6) Now that networkBuildDnsmasqArgv doesn't create the dnsmasqContext
anymore the test case can create one with the localstatedir that is
expected by the tests instead of the configure --localstatedir given one.
2011-06-28 11:07:59 +00:00
|
|
|
|
2010-04-26 13:52:02 +00:00
|
|
|
if (!(ctx->hostsfile = hostsfileNew(network_name, config_dir)))
|
|
|
|
goto error;
|
2011-06-24 10:04:39 +00:00
|
|
|
if (!(ctx->addnhostsfile = addnhostsNew(network_name, config_dir)))
|
|
|
|
goto error;
|
2010-04-26 13:52:02 +00:00
|
|
|
|
|
|
|
return ctx;
|
|
|
|
|
|
|
|
error:
|
|
|
|
dnsmasqContextFree(ctx);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* dnsmasqContextFree:
|
|
|
|
* @ctx: pointer to the dnsmasq context
|
|
|
|
*
|
2011-12-04 00:06:07 +00:00
|
|
|
* Free the resources associated with a dnsmasq context
|
2010-04-26 13:52:02 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
dnsmasqContextFree(dnsmasqContext *ctx)
|
|
|
|
{
|
|
|
|
if (!ctx)
|
|
|
|
return;
|
|
|
|
|
2021-02-03 19:32:34 +00:00
|
|
|
g_free(ctx->config_dir);
|
network: Fix dnsmasq hostsfile creation logic and related tests
networkSaveDnsmasqHostsfile was added in 8fa9c2214247 (Apr 2010).
It has a force flag. If the dnsmasq hostsfile already exists force
needs to be true to overwrite it. networkBuildDnsmasqArgv sets force
to false, networkDefine sets it to true. This results in the
hostsfile being written only in networkDefine in the common case.
If no error occurred networkSaveDnsmasqHostsfile returns true and
networkBuildDnsmasqArgv adds the --dhcp-hostsfile to the dnsmasq
command line.
networkSaveDnsmasqHostsfile was changed in 89ae9849f744 (24 Jun 2011)
to return a new dnsmasqContext instead of reusing one. This change broke
the logic of the force flag as now networkSaveDnsmasqHostsfile returns
NULL on error, but the early return -- if force was not set and the
hostsfile exists -- returns 0. This turned the early return in an error
case and networkBuildDnsmasqArgv didn't add the --dhcp-hostsfile option
anymore if the hostsfile already exists. It did because networkDefine
created the hostsfile already.
Then 9d4e2845d498 fixed the return 0 case in networkSaveDnsmasqHostsfile
but didn't apply the force option correctly to the new addnhosts file.
Now force doesn't control an early return anymore, but influences the
handling of the hostsfile context creation and dnsmasqSave is always
called now. This commit also added test cases that reveal several
problems. First, the tests now calls functions that try to write the
dnsmasq config files to disk. If someone runs this tests as root this
might overwrite actively used dnsmasq config files, this is a no-go. Also
the tests depend on configure --localstatedir, this needs to be fixed as
well, because it makes the tests fail when localstatedir is different
from /var.
This patch does several things to fix this:
1) Move dnsmasqContext creation and saving out of networkBuildDnsmasqArgv
to the caller to separate the command line generation from the config
file writing. This makes the command line generation testable without the
risk of interfering with system files, because the tests just don't call
dnsmasqSave.
2) This refactoring of networkSaveDnsmasqHostsfile makes the force flag
useless as the saving happens somewhere else now. This fixes the wrong
usage of the force flag in combination with then newly added addnhosts
file by removing the force flag.
3) Adapt the wrong test cases to the correct behavior, by adding the
missing --dhcp-hostsfile option. Both affected tests contain DHCP host
elements but missed the necessary --dhcp-hostsfile option.
4) Rename networkSaveDnsmasqHostsfile to networkBuildDnsmasqHostsfile,
because it doesn't save the dnsmasqContext anymore.
5) Move all directory creations in dnsmasq context handling code from
the *New functions to dnsmasqSave to avoid directory creations in system
paths in the test cases.
6) Now that networkBuildDnsmasqArgv doesn't create the dnsmasqContext
anymore the test case can create one with the localstatedir that is
expected by the tests instead of the configure --localstatedir given one.
2011-06-28 11:07:59 +00:00
|
|
|
|
2010-04-26 13:52:02 +00:00
|
|
|
if (ctx->hostsfile)
|
|
|
|
hostsfileFree(ctx->hostsfile);
|
2011-06-24 10:04:39 +00:00
|
|
|
if (ctx->addnhostsfile)
|
|
|
|
addnhostsFree(ctx->addnhostsfile);
|
2010-04-26 13:52:02 +00:00
|
|
|
|
2021-02-03 19:32:34 +00:00
|
|
|
g_free(ctx);
|
2010-04-26 13:52:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* dnsmasqAddDhcpHost:
|
|
|
|
* @ctx: pointer to the dnsmasq context for each network
|
|
|
|
* @mac: pointer to the string contains mac address of the host
|
Convert virNetwork to use virSocketAddr everywhere
Instead of storing the IP address string in virNetwork related
structs, store the parsed virSocketAddr. This will make it
easier to add IPv6 support in the future, by letting driver
code directly check what address family is present
* src/conf/network_conf.c, src/conf/network_conf.h,
src/network/bridge_driver.c: Convert to use virSocketAddr
in virNetwork, instead of char *.
* src/util/bridge.c, src/util/bridge.h,
src/util/dnsmasq.c, src/util/dnsmasq.h,
src/util/iptables.c, src/util/iptables.h: Convert to
take a virSocketAddr instead of char * for any IP
address parameters
* src/util/network.h: Add macros to determine if an address
is set, and what address family is set.
2010-10-21 12:14:33 +00:00
|
|
|
* @ip: pointer to the socket address contains ip of the host
|
2010-04-26 13:52:02 +00:00
|
|
|
* @name: pointer to the string contains hostname of the host or NULL
|
|
|
|
*
|
|
|
|
* Add dhcp-host entry.
|
|
|
|
*/
|
2011-06-28 12:07:46 +00:00
|
|
|
int
|
2010-04-26 13:52:02 +00:00
|
|
|
dnsmasqAddDhcpHost(dnsmasqContext *ctx,
|
|
|
|
const char *mac,
|
Convert virNetwork to use virSocketAddr everywhere
Instead of storing the IP address string in virNetwork related
structs, store the parsed virSocketAddr. This will make it
easier to add IPv6 support in the future, by letting driver
code directly check what address family is present
* src/conf/network_conf.c, src/conf/network_conf.h,
src/network/bridge_driver.c: Convert to use virSocketAddr
in virNetwork, instead of char *.
* src/util/bridge.c, src/util/bridge.h,
src/util/dnsmasq.c, src/util/dnsmasq.h,
src/util/iptables.c, src/util/iptables.h: Convert to
take a virSocketAddr instead of char * for any IP
address parameters
* src/util/network.h: Add macros to determine if an address
is set, and what address family is set.
2010-10-21 12:14:33 +00:00
|
|
|
virSocketAddr *ip,
|
2012-12-06 17:20:38 +00:00
|
|
|
const char *name,
|
2013-02-15 19:02:26 +00:00
|
|
|
const char *id,
|
2020-04-22 20:05:57 +00:00
|
|
|
const char *leasetime,
|
2012-12-06 17:20:38 +00:00
|
|
|
bool ipv6)
|
2010-04-26 13:52:02 +00:00
|
|
|
{
|
2020-04-22 20:05:57 +00:00
|
|
|
return hostsfileAdd(ctx->hostsfile, mac, ip, name, id, leasetime, ipv6);
|
2010-04-26 13:52:02 +00:00
|
|
|
}
|
|
|
|
|
2011-06-24 10:04:39 +00:00
|
|
|
/*
|
|
|
|
* dnsmasqAddHost:
|
|
|
|
* @ctx: pointer to the dnsmasq context for each network
|
|
|
|
* @ip: pointer to the socket address contains ip of the host
|
|
|
|
* @name: pointer to the string contains hostname of the host
|
|
|
|
*
|
|
|
|
* Add additional host entry.
|
|
|
|
*/
|
|
|
|
|
2011-06-28 12:07:46 +00:00
|
|
|
int
|
2011-06-24 10:04:39 +00:00
|
|
|
dnsmasqAddHost(dnsmasqContext *ctx,
|
|
|
|
virSocketAddr *ip,
|
|
|
|
const char *name)
|
|
|
|
{
|
2011-06-28 12:07:46 +00:00
|
|
|
return addnhostsAdd(ctx->addnhostsfile, ip, name);
|
2011-06-24 10:04:39 +00:00
|
|
|
}
|
|
|
|
|
2010-04-26 13:52:02 +00:00
|
|
|
/**
|
|
|
|
* dnsmasqSave:
|
|
|
|
* @ctx: pointer to the dnsmasq context for each network
|
|
|
|
*
|
|
|
|
* Saves all the configurations associated with a context to disk.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
dnsmasqSave(const dnsmasqContext *ctx)
|
|
|
|
{
|
2011-06-24 10:04:39 +00:00
|
|
|
int ret = 0;
|
|
|
|
|
2021-02-26 08:37:10 +00:00
|
|
|
if (g_mkdir_with_parents(ctx->config_dir, 0777) < 0) {
|
2011-07-05 21:02:53 +00:00
|
|
|
virReportSystemError(errno, _("cannot create config directory '%s'"),
|
network: Fix dnsmasq hostsfile creation logic and related tests
networkSaveDnsmasqHostsfile was added in 8fa9c2214247 (Apr 2010).
It has a force flag. If the dnsmasq hostsfile already exists force
needs to be true to overwrite it. networkBuildDnsmasqArgv sets force
to false, networkDefine sets it to true. This results in the
hostsfile being written only in networkDefine in the common case.
If no error occurred networkSaveDnsmasqHostsfile returns true and
networkBuildDnsmasqArgv adds the --dhcp-hostsfile to the dnsmasq
command line.
networkSaveDnsmasqHostsfile was changed in 89ae9849f744 (24 Jun 2011)
to return a new dnsmasqContext instead of reusing one. This change broke
the logic of the force flag as now networkSaveDnsmasqHostsfile returns
NULL on error, but the early return -- if force was not set and the
hostsfile exists -- returns 0. This turned the early return in an error
case and networkBuildDnsmasqArgv didn't add the --dhcp-hostsfile option
anymore if the hostsfile already exists. It did because networkDefine
created the hostsfile already.
Then 9d4e2845d498 fixed the return 0 case in networkSaveDnsmasqHostsfile
but didn't apply the force option correctly to the new addnhosts file.
Now force doesn't control an early return anymore, but influences the
handling of the hostsfile context creation and dnsmasqSave is always
called now. This commit also added test cases that reveal several
problems. First, the tests now calls functions that try to write the
dnsmasq config files to disk. If someone runs this tests as root this
might overwrite actively used dnsmasq config files, this is a no-go. Also
the tests depend on configure --localstatedir, this needs to be fixed as
well, because it makes the tests fail when localstatedir is different
from /var.
This patch does several things to fix this:
1) Move dnsmasqContext creation and saving out of networkBuildDnsmasqArgv
to the caller to separate the command line generation from the config
file writing. This makes the command line generation testable without the
risk of interfering with system files, because the tests just don't call
dnsmasqSave.
2) This refactoring of networkSaveDnsmasqHostsfile makes the force flag
useless as the saving happens somewhere else now. This fixes the wrong
usage of the force flag in combination with then newly added addnhosts
file by removing the force flag.
3) Adapt the wrong test cases to the correct behavior, by adding the
missing --dhcp-hostsfile option. Both affected tests contain DHCP host
elements but missed the necessary --dhcp-hostsfile option.
4) Rename networkSaveDnsmasqHostsfile to networkBuildDnsmasqHostsfile,
because it doesn't save the dnsmasqContext anymore.
5) Move all directory creations in dnsmasq context handling code from
the *New functions to dnsmasqSave to avoid directory creations in system
paths in the test cases.
6) Now that networkBuildDnsmasqArgv doesn't create the dnsmasqContext
anymore the test case can create one with the localstatedir that is
expected by the tests instead of the configure --localstatedir given one.
2011-06-28 11:07:59 +00:00
|
|
|
ctx->config_dir);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-04-26 13:52:02 +00:00
|
|
|
if (ctx->hostsfile)
|
2011-06-24 10:04:39 +00:00
|
|
|
ret = hostsfileSave(ctx->hostsfile);
|
|
|
|
if (ret == 0) {
|
|
|
|
if (ctx->addnhostsfile)
|
|
|
|
ret = addnhostsSave(ctx->addnhostsfile);
|
|
|
|
}
|
2010-04-26 13:52:02 +00:00
|
|
|
|
2011-06-24 10:04:39 +00:00
|
|
|
return ret;
|
2010-04-26 13:52:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* dnsmasqDelete:
|
|
|
|
* @ctx: pointer to the dnsmasq context for each network
|
|
|
|
*
|
|
|
|
* Delete all the configuration files associated with a context.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
dnsmasqDelete(const dnsmasqContext *ctx)
|
|
|
|
{
|
2011-06-24 10:04:39 +00:00
|
|
|
int ret = 0;
|
|
|
|
|
2010-04-26 13:52:02 +00:00
|
|
|
if (ctx->hostsfile)
|
2011-06-24 10:04:39 +00:00
|
|
|
ret = genericFileDelete(ctx->hostsfile->path);
|
|
|
|
if (ctx->addnhostsfile)
|
|
|
|
ret = genericFileDelete(ctx->addnhostsfile->path);
|
2010-04-26 13:52:02 +00:00
|
|
|
|
2011-06-24 10:04:39 +00:00
|
|
|
return ret;
|
2010-04-26 13:52:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* dnsmasqReload:
|
|
|
|
* @pid: the pid of the target dnsmasq process
|
|
|
|
*
|
|
|
|
* Reloads all the configurations associated to a context
|
|
|
|
*/
|
|
|
|
int
|
2019-10-14 12:45:33 +00:00
|
|
|
dnsmasqReload(pid_t pid G_GNUC_UNUSED)
|
2010-04-26 13:52:02 +00:00
|
|
|
{
|
2010-05-03 18:23:50 +00:00
|
|
|
#ifndef WIN32
|
2010-04-26 13:52:02 +00:00
|
|
|
if (kill(pid, SIGHUP) != 0) {
|
|
|
|
virReportSystemError(errno,
|
2018-09-19 08:38:14 +00:00
|
|
|
_("Failed to make dnsmasq (PID: %d)"
|
|
|
|
" reload config files."),
|
|
|
|
pid);
|
2010-04-26 13:52:02 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2010-05-03 18:23:50 +00:00
|
|
|
#endif /* WIN32 */
|
2010-04-26 13:52:02 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
util: capabilities detection for dnsmasq
In order to optionally take advantage of new features in dnsmasq when
the host's version of dnsmasq supports them, but still be able to run
on hosts that don't support the new features, we need to be able to
detect the version of dnsmasq running on the host, and possibly
determine from the help output what options are in this dnsmasq.
This patch implements a greatly simplified version of the capabilities
code we already have for qemu. A dnsmasqCaps device can be created and
populated either from running a program on disk, reading a file with
the concatenated output of "dnsmasq --version; dnsmasq --help", or
examining a buffer in memory that contains the concatenated output of
those two commands. Simple functions to retrieve capabilities flags,
the version number, and the path of the binary are also included.
bridge_driver.c creates a single dnsmasqCaps object at driver startup,
and disposes of it at driver shutdown. Any time it must be used, the
dnsmasqCapsRefresh method is called - it checks the mtime of the
binary, and re-runs the checks if the binary has changed.
networkxml2argvtest.c creates 2 "artificial" dnsmasqCaps objects at
startup - one "restricted" (doesn't support --bind-dynamic) and one
"full" (does support --bind-dynamic). Some of the test cases use one
and some the other, to make sure both code pathes are tested.
2012-11-20 17:22:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* dnsmasqCapabilities functions - provide useful information about the
|
|
|
|
* version of dnsmasq on this machine.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
struct _dnsmasqCaps {
|
2018-04-13 11:51:23 +00:00
|
|
|
virObject parent;
|
util: capabilities detection for dnsmasq
In order to optionally take advantage of new features in dnsmasq when
the host's version of dnsmasq supports them, but still be able to run
on hosts that don't support the new features, we need to be able to
detect the version of dnsmasq running on the host, and possibly
determine from the help output what options are in this dnsmasq.
This patch implements a greatly simplified version of the capabilities
code we already have for qemu. A dnsmasqCaps device can be created and
populated either from running a program on disk, reading a file with
the concatenated output of "dnsmasq --version; dnsmasq --help", or
examining a buffer in memory that contains the concatenated output of
those two commands. Simple functions to retrieve capabilities flags,
the version number, and the path of the binary are also included.
bridge_driver.c creates a single dnsmasqCaps object at driver startup,
and disposes of it at driver shutdown. Any time it must be used, the
dnsmasqCapsRefresh method is called - it checks the mtime of the
binary, and re-runs the checks if the binary has changed.
networkxml2argvtest.c creates 2 "artificial" dnsmasqCaps objects at
startup - one "restricted" (doesn't support --bind-dynamic) and one
"full" (does support --bind-dynamic). Some of the test cases use one
and some the other, to make sure both code pathes are tested.
2012-11-20 17:22:15 +00:00
|
|
|
char *binaryPath;
|
|
|
|
unsigned long version;
|
|
|
|
};
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
static virClass *dnsmasqCapsClass;
|
util: capabilities detection for dnsmasq
In order to optionally take advantage of new features in dnsmasq when
the host's version of dnsmasq supports them, but still be able to run
on hosts that don't support the new features, we need to be able to
detect the version of dnsmasq running on the host, and possibly
determine from the help output what options are in this dnsmasq.
This patch implements a greatly simplified version of the capabilities
code we already have for qemu. A dnsmasqCaps device can be created and
populated either from running a program on disk, reading a file with
the concatenated output of "dnsmasq --version; dnsmasq --help", or
examining a buffer in memory that contains the concatenated output of
those two commands. Simple functions to retrieve capabilities flags,
the version number, and the path of the binary are also included.
bridge_driver.c creates a single dnsmasqCaps object at driver startup,
and disposes of it at driver shutdown. Any time it must be used, the
dnsmasqCapsRefresh method is called - it checks the mtime of the
binary, and re-runs the checks if the binary has changed.
networkxml2argvtest.c creates 2 "artificial" dnsmasqCaps objects at
startup - one "restricted" (doesn't support --bind-dynamic) and one
"full" (does support --bind-dynamic). Some of the test cases use one
and some the other, to make sure both code pathes are tested.
2012-11-20 17:22:15 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
dnsmasqCapsDispose(void *obj)
|
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
dnsmasqCaps *caps = obj;
|
util: capabilities detection for dnsmasq
In order to optionally take advantage of new features in dnsmasq when
the host's version of dnsmasq supports them, but still be able to run
on hosts that don't support the new features, we need to be able to
detect the version of dnsmasq running on the host, and possibly
determine from the help output what options are in this dnsmasq.
This patch implements a greatly simplified version of the capabilities
code we already have for qemu. A dnsmasqCaps device can be created and
populated either from running a program on disk, reading a file with
the concatenated output of "dnsmasq --version; dnsmasq --help", or
examining a buffer in memory that contains the concatenated output of
those two commands. Simple functions to retrieve capabilities flags,
the version number, and the path of the binary are also included.
bridge_driver.c creates a single dnsmasqCaps object at driver startup,
and disposes of it at driver shutdown. Any time it must be used, the
dnsmasqCapsRefresh method is called - it checks the mtime of the
binary, and re-runs the checks if the binary has changed.
networkxml2argvtest.c creates 2 "artificial" dnsmasqCaps objects at
startup - one "restricted" (doesn't support --bind-dynamic) and one
"full" (does support --bind-dynamic). Some of the test cases use one
and some the other, to make sure both code pathes are tested.
2012-11-20 17:22:15 +00:00
|
|
|
|
2021-02-03 20:15:23 +00:00
|
|
|
g_free(caps->binaryPath);
|
util: capabilities detection for dnsmasq
In order to optionally take advantage of new features in dnsmasq when
the host's version of dnsmasq supports them, but still be able to run
on hosts that don't support the new features, we need to be able to
detect the version of dnsmasq running on the host, and possibly
determine from the help output what options are in this dnsmasq.
This patch implements a greatly simplified version of the capabilities
code we already have for qemu. A dnsmasqCaps device can be created and
populated either from running a program on disk, reading a file with
the concatenated output of "dnsmasq --version; dnsmasq --help", or
examining a buffer in memory that contains the concatenated output of
those two commands. Simple functions to retrieve capabilities flags,
the version number, and the path of the binary are also included.
bridge_driver.c creates a single dnsmasqCaps object at driver startup,
and disposes of it at driver shutdown. Any time it must be used, the
dnsmasqCapsRefresh method is called - it checks the mtime of the
binary, and re-runs the checks if the binary has changed.
networkxml2argvtest.c creates 2 "artificial" dnsmasqCaps objects at
startup - one "restricted" (doesn't support --bind-dynamic) and one
"full" (does support --bind-dynamic). Some of the test cases use one
and some the other, to make sure both code pathes are tested.
2012-11-20 17:22:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int dnsmasqCapsOnceInit(void)
|
|
|
|
{
|
2018-04-17 15:42:33 +00:00
|
|
|
if (!VIR_CLASS_NEW(dnsmasqCaps, virClassForObject()))
|
util: capabilities detection for dnsmasq
In order to optionally take advantage of new features in dnsmasq when
the host's version of dnsmasq supports them, but still be able to run
on hosts that don't support the new features, we need to be able to
detect the version of dnsmasq running on the host, and possibly
determine from the help output what options are in this dnsmasq.
This patch implements a greatly simplified version of the capabilities
code we already have for qemu. A dnsmasqCaps device can be created and
populated either from running a program on disk, reading a file with
the concatenated output of "dnsmasq --version; dnsmasq --help", or
examining a buffer in memory that contains the concatenated output of
those two commands. Simple functions to retrieve capabilities flags,
the version number, and the path of the binary are also included.
bridge_driver.c creates a single dnsmasqCaps object at driver startup,
and disposes of it at driver shutdown. Any time it must be used, the
dnsmasqCapsRefresh method is called - it checks the mtime of the
binary, and re-runs the checks if the binary has changed.
networkxml2argvtest.c creates 2 "artificial" dnsmasqCaps objects at
startup - one "restricted" (doesn't support --bind-dynamic) and one
"full" (does support --bind-dynamic). Some of the test cases use one
and some the other, to make sure both code pathes are tested.
2012-11-20 17:22:15 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-01-20 17:23:29 +00:00
|
|
|
VIR_ONCE_GLOBAL_INIT(dnsmasqCaps);
|
util: capabilities detection for dnsmasq
In order to optionally take advantage of new features in dnsmasq when
the host's version of dnsmasq supports them, but still be able to run
on hosts that don't support the new features, we need to be able to
detect the version of dnsmasq running on the host, and possibly
determine from the help output what options are in this dnsmasq.
This patch implements a greatly simplified version of the capabilities
code we already have for qemu. A dnsmasqCaps device can be created and
populated either from running a program on disk, reading a file with
the concatenated output of "dnsmasq --version; dnsmasq --help", or
examining a buffer in memory that contains the concatenated output of
those two commands. Simple functions to retrieve capabilities flags,
the version number, and the path of the binary are also included.
bridge_driver.c creates a single dnsmasqCaps object at driver startup,
and disposes of it at driver shutdown. Any time it must be used, the
dnsmasqCapsRefresh method is called - it checks the mtime of the
binary, and re-runs the checks if the binary has changed.
networkxml2argvtest.c creates 2 "artificial" dnsmasqCaps objects at
startup - one "restricted" (doesn't support --bind-dynamic) and one
"full" (does support --bind-dynamic). Some of the test cases use one
and some the other, to make sure both code pathes are tested.
2012-11-20 17:22:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
#define DNSMASQ_VERSION_STR "Dnsmasq version "
|
|
|
|
|
|
|
|
static int
|
2021-03-11 07:16:13 +00:00
|
|
|
dnsmasqCapsSetFromBuffer(dnsmasqCaps *caps, const char *buf)
|
util: capabilities detection for dnsmasq
In order to optionally take advantage of new features in dnsmasq when
the host's version of dnsmasq supports them, but still be able to run
on hosts that don't support the new features, we need to be able to
detect the version of dnsmasq running on the host, and possibly
determine from the help output what options are in this dnsmasq.
This patch implements a greatly simplified version of the capabilities
code we already have for qemu. A dnsmasqCaps device can be created and
populated either from running a program on disk, reading a file with
the concatenated output of "dnsmasq --version; dnsmasq --help", or
examining a buffer in memory that contains the concatenated output of
those two commands. Simple functions to retrieve capabilities flags,
the version number, and the path of the binary are also included.
bridge_driver.c creates a single dnsmasqCaps object at driver startup,
and disposes of it at driver shutdown. Any time it must be used, the
dnsmasqCapsRefresh method is called - it checks the mtime of the
binary, and re-runs the checks if the binary has changed.
networkxml2argvtest.c creates 2 "artificial" dnsmasqCaps objects at
startup - one "restricted" (doesn't support --bind-dynamic) and one
"full" (does support --bind-dynamic). Some of the test cases use one
and some the other, to make sure both code pathes are tested.
2012-11-20 17:22:15 +00:00
|
|
|
{
|
2020-01-14 10:43:37 +00:00
|
|
|
int len;
|
util: capabilities detection for dnsmasq
In order to optionally take advantage of new features in dnsmasq when
the host's version of dnsmasq supports them, but still be able to run
on hosts that don't support the new features, we need to be able to
detect the version of dnsmasq running on the host, and possibly
determine from the help output what options are in this dnsmasq.
This patch implements a greatly simplified version of the capabilities
code we already have for qemu. A dnsmasqCaps device can be created and
populated either from running a program on disk, reading a file with
the concatenated output of "dnsmasq --version; dnsmasq --help", or
examining a buffer in memory that contains the concatenated output of
those two commands. Simple functions to retrieve capabilities flags,
the version number, and the path of the binary are also included.
bridge_driver.c creates a single dnsmasqCaps object at driver startup,
and disposes of it at driver shutdown. Any time it must be used, the
dnsmasqCapsRefresh method is called - it checks the mtime of the
binary, and re-runs the checks if the binary has changed.
networkxml2argvtest.c creates 2 "artificial" dnsmasqCaps objects at
startup - one "restricted" (doesn't support --bind-dynamic) and one
"full" (does support --bind-dynamic). Some of the test cases use one
and some the other, to make sure both code pathes are tested.
2012-11-20 17:22:15 +00:00
|
|
|
const char *p;
|
|
|
|
|
2012-12-10 13:00:02 +00:00
|
|
|
p = STRSKIP(buf, DNSMASQ_VERSION_STR);
|
|
|
|
if (!p)
|
2021-12-14 16:35:07 +00:00
|
|
|
goto error;
|
2021-01-08 01:03:05 +00:00
|
|
|
|
|
|
|
virSkipToDigit(&p);
|
|
|
|
|
util: capabilities detection for dnsmasq
In order to optionally take advantage of new features in dnsmasq when
the host's version of dnsmasq supports them, but still be able to run
on hosts that don't support the new features, we need to be able to
detect the version of dnsmasq running on the host, and possibly
determine from the help output what options are in this dnsmasq.
This patch implements a greatly simplified version of the capabilities
code we already have for qemu. A dnsmasqCaps device can be created and
populated either from running a program on disk, reading a file with
the concatenated output of "dnsmasq --version; dnsmasq --help", or
examining a buffer in memory that contains the concatenated output of
those two commands. Simple functions to retrieve capabilities flags,
the version number, and the path of the binary are also included.
bridge_driver.c creates a single dnsmasqCaps object at driver startup,
and disposes of it at driver shutdown. Any time it must be used, the
dnsmasqCapsRefresh method is called - it checks the mtime of the
binary, and re-runs the checks if the binary has changed.
networkxml2argvtest.c creates 2 "artificial" dnsmasqCaps objects at
startup - one "restricted" (doesn't support --bind-dynamic) and one
"full" (does support --bind-dynamic). Some of the test cases use one
and some the other, to make sure both code pathes are tested.
2012-11-20 17:22:15 +00:00
|
|
|
if (virParseVersionString(p, &caps->version, true) < 0)
|
2021-12-14 16:35:07 +00:00
|
|
|
goto error;
|
util: capabilities detection for dnsmasq
In order to optionally take advantage of new features in dnsmasq when
the host's version of dnsmasq supports them, but still be able to run
on hosts that don't support the new features, we need to be able to
detect the version of dnsmasq running on the host, and possibly
determine from the help output what options are in this dnsmasq.
This patch implements a greatly simplified version of the capabilities
code we already have for qemu. A dnsmasqCaps device can be created and
populated either from running a program on disk, reading a file with
the concatenated output of "dnsmasq --version; dnsmasq --help", or
examining a buffer in memory that contains the concatenated output of
those two commands. Simple functions to retrieve capabilities flags,
the version number, and the path of the binary are also included.
bridge_driver.c creates a single dnsmasqCaps object at driver startup,
and disposes of it at driver shutdown. Any time it must be used, the
dnsmasqCapsRefresh method is called - it checks the mtime of the
binary, and re-runs the checks if the binary has changed.
networkxml2argvtest.c creates 2 "artificial" dnsmasqCaps objects at
startup - one "restricted" (doesn't support --bind-dynamic) and one
"full" (does support --bind-dynamic). Some of the test cases use one
and some the other, to make sure both code pathes are tested.
2012-11-20 17:22:15 +00:00
|
|
|
|
2021-12-14 16:36:23 +00:00
|
|
|
if (caps->version < DNSMASQ_MIN_MAJOR * 1000000 + DNSMASQ_MIN_MINOR * 1000) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("dnsmasq version >= %u.%u required but %lu.%lu found"),
|
|
|
|
DNSMASQ_MIN_MAJOR, DNSMASQ_MIN_MINOR,
|
|
|
|
caps->version / 1000000,
|
|
|
|
caps->version % 1000000 / 1000);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2021-12-14 18:40:41 +00:00
|
|
|
VIR_INFO("dnsmasq version is %d.%d",
|
2012-12-17 17:49:18 +00:00
|
|
|
(int)caps->version / 1000000,
|
2021-12-14 18:40:41 +00:00
|
|
|
(int)(caps->version % 1000000) / 1000);
|
util: capabilities detection for dnsmasq
In order to optionally take advantage of new features in dnsmasq when
the host's version of dnsmasq supports them, but still be able to run
on hosts that don't support the new features, we need to be able to
detect the version of dnsmasq running on the host, and possibly
determine from the help output what options are in this dnsmasq.
This patch implements a greatly simplified version of the capabilities
code we already have for qemu. A dnsmasqCaps device can be created and
populated either from running a program on disk, reading a file with
the concatenated output of "dnsmasq --version; dnsmasq --help", or
examining a buffer in memory that contains the concatenated output of
those two commands. Simple functions to retrieve capabilities flags,
the version number, and the path of the binary are also included.
bridge_driver.c creates a single dnsmasqCaps object at driver startup,
and disposes of it at driver shutdown. Any time it must be used, the
dnsmasqCapsRefresh method is called - it checks the mtime of the
binary, and re-runs the checks if the binary has changed.
networkxml2argvtest.c creates 2 "artificial" dnsmasqCaps objects at
startup - one "restricted" (doesn't support --bind-dynamic) and one
"full" (does support --bind-dynamic). Some of the test cases use one
and some the other, to make sure both code pathes are tested.
2012-11-20 17:22:15 +00:00
|
|
|
return 0;
|
|
|
|
|
2021-12-14 16:35:07 +00:00
|
|
|
error:
|
2020-01-14 10:43:37 +00:00
|
|
|
p = strchr(buf, '\n');
|
|
|
|
if (!p)
|
|
|
|
len = strlen(buf);
|
|
|
|
else
|
|
|
|
len = p - buf;
|
util: capabilities detection for dnsmasq
In order to optionally take advantage of new features in dnsmasq when
the host's version of dnsmasq supports them, but still be able to run
on hosts that don't support the new features, we need to be able to
detect the version of dnsmasq running on the host, and possibly
determine from the help output what options are in this dnsmasq.
This patch implements a greatly simplified version of the capabilities
code we already have for qemu. A dnsmasqCaps device can be created and
populated either from running a program on disk, reading a file with
the concatenated output of "dnsmasq --version; dnsmasq --help", or
examining a buffer in memory that contains the concatenated output of
those two commands. Simple functions to retrieve capabilities flags,
the version number, and the path of the binary are also included.
bridge_driver.c creates a single dnsmasqCaps object at driver startup,
and disposes of it at driver shutdown. Any time it must be used, the
dnsmasqCapsRefresh method is called - it checks the mtime of the
binary, and re-runs the checks if the binary has changed.
networkxml2argvtest.c creates 2 "artificial" dnsmasqCaps objects at
startup - one "restricted" (doesn't support --bind-dynamic) and one
"full" (does support --bind-dynamic). Some of the test cases use one
and some the other, to make sure both code pathes are tested.
2012-11-20 17:22:15 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("cannot parse %s version number in '%.*s'"),
|
2020-01-14 10:43:37 +00:00
|
|
|
caps->binaryPath, len, buf);
|
util: capabilities detection for dnsmasq
In order to optionally take advantage of new features in dnsmasq when
the host's version of dnsmasq supports them, but still be able to run
on hosts that don't support the new features, we need to be able to
detect the version of dnsmasq running on the host, and possibly
determine from the help output what options are in this dnsmasq.
This patch implements a greatly simplified version of the capabilities
code we already have for qemu. A dnsmasqCaps device can be created and
populated either from running a program on disk, reading a file with
the concatenated output of "dnsmasq --version; dnsmasq --help", or
examining a buffer in memory that contains the concatenated output of
those two commands. Simple functions to retrieve capabilities flags,
the version number, and the path of the binary are also included.
bridge_driver.c creates a single dnsmasqCaps object at driver startup,
and disposes of it at driver shutdown. Any time it must be used, the
dnsmasqCapsRefresh method is called - it checks the mtime of the
binary, and re-runs the checks if the binary has changed.
networkxml2argvtest.c creates 2 "artificial" dnsmasqCaps objects at
startup - one "restricted" (doesn't support --bind-dynamic) and one
"full" (does support --bind-dynamic). Some of the test cases use one
and some the other, to make sure both code pathes are tested.
2012-11-20 17:22:15 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2022-01-17 12:17:42 +00:00
|
|
|
dnsmasqCapsRefreshInternal(dnsmasqCaps *caps)
|
util: capabilities detection for dnsmasq
In order to optionally take advantage of new features in dnsmasq when
the host's version of dnsmasq supports them, but still be able to run
on hosts that don't support the new features, we need to be able to
detect the version of dnsmasq running on the host, and possibly
determine from the help output what options are in this dnsmasq.
This patch implements a greatly simplified version of the capabilities
code we already have for qemu. A dnsmasqCaps device can be created and
populated either from running a program on disk, reading a file with
the concatenated output of "dnsmasq --version; dnsmasq --help", or
examining a buffer in memory that contains the concatenated output of
those two commands. Simple functions to retrieve capabilities flags,
the version number, and the path of the binary are also included.
bridge_driver.c creates a single dnsmasqCaps object at driver startup,
and disposes of it at driver shutdown. Any time it must be used, the
dnsmasqCapsRefresh method is called - it checks the mtime of the
binary, and re-runs the checks if the binary has changed.
networkxml2argvtest.c creates 2 "artificial" dnsmasqCaps objects at
startup - one "restricted" (doesn't support --bind-dynamic) and one
"full" (does support --bind-dynamic). Some of the test cases use one
and some the other, to make sure both code pathes are tested.
2012-11-20 17:22:15 +00:00
|
|
|
{
|
2021-12-10 16:21:27 +00:00
|
|
|
g_autoptr(virCommand) vercmd = NULL;
|
2020-11-23 22:09:39 +00:00
|
|
|
g_autofree char *version = NULL;
|
util: capabilities detection for dnsmasq
In order to optionally take advantage of new features in dnsmasq when
the host's version of dnsmasq supports them, but still be able to run
on hosts that don't support the new features, we need to be able to
detect the version of dnsmasq running on the host, and possibly
determine from the help output what options are in this dnsmasq.
This patch implements a greatly simplified version of the capabilities
code we already have for qemu. A dnsmasqCaps device can be created and
populated either from running a program on disk, reading a file with
the concatenated output of "dnsmasq --version; dnsmasq --help", or
examining a buffer in memory that contains the concatenated output of
those two commands. Simple functions to retrieve capabilities flags,
the version number, and the path of the binary are also included.
bridge_driver.c creates a single dnsmasqCaps object at driver startup,
and disposes of it at driver shutdown. Any time it must be used, the
dnsmasqCapsRefresh method is called - it checks the mtime of the
binary, and re-runs the checks if the binary has changed.
networkxml2argvtest.c creates 2 "artificial" dnsmasqCaps objects at
startup - one "restricted" (doesn't support --bind-dynamic) and one
"full" (does support --bind-dynamic). Some of the test cases use one
and some the other, to make sure both code pathes are tested.
2012-11-20 17:22:15 +00:00
|
|
|
|
2021-12-10 16:21:27 +00:00
|
|
|
vercmd = virCommandNewArgList(caps->binaryPath, "--version", NULL);
|
|
|
|
virCommandSetOutputBuffer(vercmd, &version);
|
|
|
|
virCommandAddEnvPassCommon(vercmd);
|
|
|
|
virCommandClearCaps(vercmd);
|
|
|
|
if (virCommandRun(vercmd, NULL) < 0)
|
|
|
|
return -1;
|
util: capabilities detection for dnsmasq
In order to optionally take advantage of new features in dnsmasq when
the host's version of dnsmasq supports them, but still be able to run
on hosts that don't support the new features, we need to be able to
detect the version of dnsmasq running on the host, and possibly
determine from the help output what options are in this dnsmasq.
This patch implements a greatly simplified version of the capabilities
code we already have for qemu. A dnsmasqCaps device can be created and
populated either from running a program on disk, reading a file with
the concatenated output of "dnsmasq --version; dnsmasq --help", or
examining a buffer in memory that contains the concatenated output of
those two commands. Simple functions to retrieve capabilities flags,
the version number, and the path of the binary are also included.
bridge_driver.c creates a single dnsmasqCaps object at driver startup,
and disposes of it at driver shutdown. Any time it must be used, the
dnsmasqCapsRefresh method is called - it checks the mtime of the
binary, and re-runs the checks if the binary has changed.
networkxml2argvtest.c creates 2 "artificial" dnsmasqCaps objects at
startup - one "restricted" (doesn't support --bind-dynamic) and one
"full" (does support --bind-dynamic). Some of the test cases use one
and some the other, to make sure both code pathes are tested.
2012-11-20 17:22:15 +00:00
|
|
|
|
2022-01-17 12:22:09 +00:00
|
|
|
return dnsmasqCapsSetFromBuffer(caps, version);
|
util: capabilities detection for dnsmasq
In order to optionally take advantage of new features in dnsmasq when
the host's version of dnsmasq supports them, but still be able to run
on hosts that don't support the new features, we need to be able to
detect the version of dnsmasq running on the host, and possibly
determine from the help output what options are in this dnsmasq.
This patch implements a greatly simplified version of the capabilities
code we already have for qemu. A dnsmasqCaps device can be created and
populated either from running a program on disk, reading a file with
the concatenated output of "dnsmasq --version; dnsmasq --help", or
examining a buffer in memory that contains the concatenated output of
those two commands. Simple functions to retrieve capabilities flags,
the version number, and the path of the binary are also included.
bridge_driver.c creates a single dnsmasqCaps object at driver startup,
and disposes of it at driver shutdown. Any time it must be used, the
dnsmasqCapsRefresh method is called - it checks the mtime of the
binary, and re-runs the checks if the binary has changed.
networkxml2argvtest.c creates 2 "artificial" dnsmasqCaps objects at
startup - one "restricted" (doesn't support --bind-dynamic) and one
"full" (does support --bind-dynamic). Some of the test cases use one
and some the other, to make sure both code pathes are tested.
2012-11-20 17:22:15 +00:00
|
|
|
}
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
static dnsmasqCaps *
|
2022-01-10 15:15:29 +00:00
|
|
|
dnsmasqCapsNewEmpty(void)
|
util: capabilities detection for dnsmasq
In order to optionally take advantage of new features in dnsmasq when
the host's version of dnsmasq supports them, but still be able to run
on hosts that don't support the new features, we need to be able to
detect the version of dnsmasq running on the host, and possibly
determine from the help output what options are in this dnsmasq.
This patch implements a greatly simplified version of the capabilities
code we already have for qemu. A dnsmasqCaps device can be created and
populated either from running a program on disk, reading a file with
the concatenated output of "dnsmasq --version; dnsmasq --help", or
examining a buffer in memory that contains the concatenated output of
those two commands. Simple functions to retrieve capabilities flags,
the version number, and the path of the binary are also included.
bridge_driver.c creates a single dnsmasqCaps object at driver startup,
and disposes of it at driver shutdown. Any time it must be used, the
dnsmasqCapsRefresh method is called - it checks the mtime of the
binary, and re-runs the checks if the binary has changed.
networkxml2argvtest.c creates 2 "artificial" dnsmasqCaps objects at
startup - one "restricted" (doesn't support --bind-dynamic) and one
"full" (does support --bind-dynamic). Some of the test cases use one
and some the other, to make sure both code pathes are tested.
2012-11-20 17:22:15 +00:00
|
|
|
{
|
2022-01-11 15:51:32 +00:00
|
|
|
g_autoptr(dnsmasqCaps) caps = NULL;
|
util: capabilities detection for dnsmasq
In order to optionally take advantage of new features in dnsmasq when
the host's version of dnsmasq supports them, but still be able to run
on hosts that don't support the new features, we need to be able to
detect the version of dnsmasq running on the host, and possibly
determine from the help output what options are in this dnsmasq.
This patch implements a greatly simplified version of the capabilities
code we already have for qemu. A dnsmasqCaps device can be created and
populated either from running a program on disk, reading a file with
the concatenated output of "dnsmasq --version; dnsmasq --help", or
examining a buffer in memory that contains the concatenated output of
those two commands. Simple functions to retrieve capabilities flags,
the version number, and the path of the binary are also included.
bridge_driver.c creates a single dnsmasqCaps object at driver startup,
and disposes of it at driver shutdown. Any time it must be used, the
dnsmasqCapsRefresh method is called - it checks the mtime of the
binary, and re-runs the checks if the binary has changed.
networkxml2argvtest.c creates 2 "artificial" dnsmasqCaps objects at
startup - one "restricted" (doesn't support --bind-dynamic) and one
"full" (does support --bind-dynamic). Some of the test cases use one
and some the other, to make sure both code pathes are tested.
2012-11-20 17:22:15 +00:00
|
|
|
|
|
|
|
if (dnsmasqCapsInitialize() < 0)
|
|
|
|
return NULL;
|
|
|
|
if (!(caps = virObjectNew(dnsmasqCapsClass)))
|
|
|
|
return NULL;
|
2022-01-10 15:19:31 +00:00
|
|
|
|
|
|
|
if (!(caps->binaryPath = virFindFileInPath(DNSMASQ))) {
|
|
|
|
virReportSystemError(ENOENT, "%s",
|
|
|
|
_("Unable to find 'dnsmasq' binary in $PATH"));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2022-01-11 15:51:32 +00:00
|
|
|
return g_steal_pointer(&caps);
|
util: capabilities detection for dnsmasq
In order to optionally take advantage of new features in dnsmasq when
the host's version of dnsmasq supports them, but still be able to run
on hosts that don't support the new features, we need to be able to
detect the version of dnsmasq running on the host, and possibly
determine from the help output what options are in this dnsmasq.
This patch implements a greatly simplified version of the capabilities
code we already have for qemu. A dnsmasqCaps device can be created and
populated either from running a program on disk, reading a file with
the concatenated output of "dnsmasq --version; dnsmasq --help", or
examining a buffer in memory that contains the concatenated output of
those two commands. Simple functions to retrieve capabilities flags,
the version number, and the path of the binary are also included.
bridge_driver.c creates a single dnsmasqCaps object at driver startup,
and disposes of it at driver shutdown. Any time it must be used, the
dnsmasqCapsRefresh method is called - it checks the mtime of the
binary, and re-runs the checks if the binary has changed.
networkxml2argvtest.c creates 2 "artificial" dnsmasqCaps objects at
startup - one "restricted" (doesn't support --bind-dynamic) and one
"full" (does support --bind-dynamic). Some of the test cases use one
and some the other, to make sure both code pathes are tested.
2012-11-20 17:22:15 +00:00
|
|
|
}
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
dnsmasqCaps *
|
2021-04-14 15:57:08 +00:00
|
|
|
dnsmasqCapsNewFromBinary(void)
|
util: capabilities detection for dnsmasq
In order to optionally take advantage of new features in dnsmasq when
the host's version of dnsmasq supports them, but still be able to run
on hosts that don't support the new features, we need to be able to
detect the version of dnsmasq running on the host, and possibly
determine from the help output what options are in this dnsmasq.
This patch implements a greatly simplified version of the capabilities
code we already have for qemu. A dnsmasqCaps device can be created and
populated either from running a program on disk, reading a file with
the concatenated output of "dnsmasq --version; dnsmasq --help", or
examining a buffer in memory that contains the concatenated output of
those two commands. Simple functions to retrieve capabilities flags,
the version number, and the path of the binary are also included.
bridge_driver.c creates a single dnsmasqCaps object at driver startup,
and disposes of it at driver shutdown. Any time it must be used, the
dnsmasqCapsRefresh method is called - it checks the mtime of the
binary, and re-runs the checks if the binary has changed.
networkxml2argvtest.c creates 2 "artificial" dnsmasqCaps objects at
startup - one "restricted" (doesn't support --bind-dynamic) and one
"full" (does support --bind-dynamic). Some of the test cases use one
and some the other, to make sure both code pathes are tested.
2012-11-20 17:22:15 +00:00
|
|
|
{
|
2022-01-11 15:51:32 +00:00
|
|
|
g_autoptr(dnsmasqCaps) caps = dnsmasqCapsNewEmpty();
|
util: capabilities detection for dnsmasq
In order to optionally take advantage of new features in dnsmasq when
the host's version of dnsmasq supports them, but still be able to run
on hosts that don't support the new features, we need to be able to
detect the version of dnsmasq running on the host, and possibly
determine from the help output what options are in this dnsmasq.
This patch implements a greatly simplified version of the capabilities
code we already have for qemu. A dnsmasqCaps device can be created and
populated either from running a program on disk, reading a file with
the concatenated output of "dnsmasq --version; dnsmasq --help", or
examining a buffer in memory that contains the concatenated output of
those two commands. Simple functions to retrieve capabilities flags,
the version number, and the path of the binary are also included.
bridge_driver.c creates a single dnsmasqCaps object at driver startup,
and disposes of it at driver shutdown. Any time it must be used, the
dnsmasqCapsRefresh method is called - it checks the mtime of the
binary, and re-runs the checks if the binary has changed.
networkxml2argvtest.c creates 2 "artificial" dnsmasqCaps objects at
startup - one "restricted" (doesn't support --bind-dynamic) and one
"full" (does support --bind-dynamic). Some of the test cases use one
and some the other, to make sure both code pathes are tested.
2012-11-20 17:22:15 +00:00
|
|
|
|
|
|
|
if (!caps)
|
|
|
|
return NULL;
|
|
|
|
|
2022-01-17 12:17:42 +00:00
|
|
|
if (dnsmasqCapsRefreshInternal(caps) < 0)
|
util: capabilities detection for dnsmasq
In order to optionally take advantage of new features in dnsmasq when
the host's version of dnsmasq supports them, but still be able to run
on hosts that don't support the new features, we need to be able to
detect the version of dnsmasq running on the host, and possibly
determine from the help output what options are in this dnsmasq.
This patch implements a greatly simplified version of the capabilities
code we already have for qemu. A dnsmasqCaps device can be created and
populated either from running a program on disk, reading a file with
the concatenated output of "dnsmasq --version; dnsmasq --help", or
examining a buffer in memory that contains the concatenated output of
those two commands. Simple functions to retrieve capabilities flags,
the version number, and the path of the binary are also included.
bridge_driver.c creates a single dnsmasqCaps object at driver startup,
and disposes of it at driver shutdown. Any time it must be used, the
dnsmasqCapsRefresh method is called - it checks the mtime of the
binary, and re-runs the checks if the binary has changed.
networkxml2argvtest.c creates 2 "artificial" dnsmasqCaps objects at
startup - one "restricted" (doesn't support --bind-dynamic) and one
"full" (does support --bind-dynamic). Some of the test cases use one
and some the other, to make sure both code pathes are tested.
2012-11-20 17:22:15 +00:00
|
|
|
return NULL;
|
2022-01-11 15:51:32 +00:00
|
|
|
|
|
|
|
return g_steal_pointer(&caps);
|
util: capabilities detection for dnsmasq
In order to optionally take advantage of new features in dnsmasq when
the host's version of dnsmasq supports them, but still be able to run
on hosts that don't support the new features, we need to be able to
detect the version of dnsmasq running on the host, and possibly
determine from the help output what options are in this dnsmasq.
This patch implements a greatly simplified version of the capabilities
code we already have for qemu. A dnsmasqCaps device can be created and
populated either from running a program on disk, reading a file with
the concatenated output of "dnsmasq --version; dnsmasq --help", or
examining a buffer in memory that contains the concatenated output of
those two commands. Simple functions to retrieve capabilities flags,
the version number, and the path of the binary are also included.
bridge_driver.c creates a single dnsmasqCaps object at driver startup,
and disposes of it at driver shutdown. Any time it must be used, the
dnsmasqCapsRefresh method is called - it checks the mtime of the
binary, and re-runs the checks if the binary has changed.
networkxml2argvtest.c creates 2 "artificial" dnsmasqCaps objects at
startup - one "restricted" (doesn't support --bind-dynamic) and one
"full" (does support --bind-dynamic). Some of the test cases use one
and some the other, to make sure both code pathes are tested.
2012-11-20 17:22:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
2021-03-11 07:16:13 +00:00
|
|
|
dnsmasqCapsGetBinaryPath(dnsmasqCaps *caps)
|
util: capabilities detection for dnsmasq
In order to optionally take advantage of new features in dnsmasq when
the host's version of dnsmasq supports them, but still be able to run
on hosts that don't support the new features, we need to be able to
detect the version of dnsmasq running on the host, and possibly
determine from the help output what options are in this dnsmasq.
This patch implements a greatly simplified version of the capabilities
code we already have for qemu. A dnsmasqCaps device can be created and
populated either from running a program on disk, reading a file with
the concatenated output of "dnsmasq --version; dnsmasq --help", or
examining a buffer in memory that contains the concatenated output of
those two commands. Simple functions to retrieve capabilities flags,
the version number, and the path of the binary are also included.
bridge_driver.c creates a single dnsmasqCaps object at driver startup,
and disposes of it at driver shutdown. Any time it must be used, the
dnsmasqCapsRefresh method is called - it checks the mtime of the
binary, and re-runs the checks if the binary has changed.
networkxml2argvtest.c creates 2 "artificial" dnsmasqCaps objects at
startup - one "restricted" (doesn't support --bind-dynamic) and one
"full" (does support --bind-dynamic). Some of the test cases use one
and some the other, to make sure both code pathes are tested.
2012-11-20 17:22:15 +00:00
|
|
|
{
|
2022-01-10 15:25:18 +00:00
|
|
|
return caps->binaryPath;
|
util: capabilities detection for dnsmasq
In order to optionally take advantage of new features in dnsmasq when
the host's version of dnsmasq supports them, but still be able to run
on hosts that don't support the new features, we need to be able to
detect the version of dnsmasq running on the host, and possibly
determine from the help output what options are in this dnsmasq.
This patch implements a greatly simplified version of the capabilities
code we already have for qemu. A dnsmasqCaps device can be created and
populated either from running a program on disk, reading a file with
the concatenated output of "dnsmasq --version; dnsmasq --help", or
examining a buffer in memory that contains the concatenated output of
those two commands. Simple functions to retrieve capabilities flags,
the version number, and the path of the binary are also included.
bridge_driver.c creates a single dnsmasqCaps object at driver startup,
and disposes of it at driver shutdown. Any time it must be used, the
dnsmasqCapsRefresh method is called - it checks the mtime of the
binary, and re-runs the checks if the binary has changed.
networkxml2argvtest.c creates 2 "artificial" dnsmasqCaps objects at
startup - one "restricted" (doesn't support --bind-dynamic) and one
"full" (does support --bind-dynamic). Some of the test cases use one
and some the other, to make sure both code pathes are tested.
2012-11-20 17:22:15 +00:00
|
|
|
}
|
|
|
|
|
2020-04-22 20:05:57 +00:00
|
|
|
/** dnsmasqDhcpHostsToString:
|
|
|
|
*
|
|
|
|
* Turns a vector of dnsmasqDhcpHost into the string that is ought to be
|
|
|
|
* stored in the hostsfile, this functionality is split to make hostsfiles
|
2020-07-09 04:42:21 +00:00
|
|
|
* testable. Returns NULL if nhosts is 0.
|
2020-04-22 20:05:57 +00:00
|
|
|
*/
|
|
|
|
char *
|
|
|
|
dnsmasqDhcpHostsToString(dnsmasqDhcpHost *hosts,
|
|
|
|
unsigned int nhosts)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
|
|
|
|
|
|
|
for (i = 0; i < nhosts; i++)
|
|
|
|
virBufferAsprintf(&buf, "%s\n", hosts[i].host);
|
|
|
|
|
|
|
|
return virBufferContentAndReset(&buf);
|
|
|
|
}
|