2008-10-10 13:57:13 +00:00
|
|
|
/*
|
|
|
|
* network_driver.h: core driver methods for managing networks
|
|
|
|
*
|
2011-07-04 06:27:12 +00:00
|
|
|
* Copyright (C) 2006, 2007, 2011 Red Hat, Inc.
|
2008-10-10 13:57:13 +00:00
|
|
|
* Copyright (C) 2006 Daniel P. Berrange
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
* Author: Daniel P. Berrange <berrange@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef __VIR_NETWORK__DRIVER_H
|
2010-03-09 18:22:22 +00:00
|
|
|
# define __VIR_NETWORK__DRIVER_H
|
2008-10-10 13:57:13 +00:00
|
|
|
|
2010-03-09 18:22:22 +00:00
|
|
|
# include <config.h>
|
2008-10-10 13:57:13 +00:00
|
|
|
|
2010-03-09 18:22:22 +00:00
|
|
|
# include "internal.h"
|
2011-06-24 10:04:38 +00:00
|
|
|
# include "network_conf.h"
|
2011-07-04 06:27:12 +00:00
|
|
|
# include "domain_conf.h"
|
2011-06-24 10:04:38 +00:00
|
|
|
# include "command.h"
|
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
|
|
|
# include "dnsmasq.h"
|
2008-10-10 13:57:13 +00:00
|
|
|
|
|
|
|
int networkRegister(void);
|
2011-07-04 06:27:12 +00:00
|
|
|
|
|
|
|
# if WITH_NETWORK
|
|
|
|
int networkAllocateActualDevice(virDomainNetDefPtr iface)
|
|
|
|
ATTRIBUTE_NONNULL(1);
|
|
|
|
int networkNotifyActualDevice(virDomainNetDefPtr iface)
|
|
|
|
ATTRIBUTE_NONNULL(1);
|
|
|
|
int networkReleaseActualDevice(virDomainNetDefPtr iface)
|
|
|
|
ATTRIBUTE_NONNULL(1);
|
|
|
|
|
2011-07-07 04:24:08 +00:00
|
|
|
int networkGetNetworkAddress(const char *netname, char **netaddr)
|
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
|
|
|
|
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
|
|
|
int networkBuildDhcpDaemonCommandLine(virNetworkObjPtr network,
|
|
|
|
virCommandPtr *cmdout, char *pidfile,
|
2011-07-04 06:27:12 +00:00
|
|
|
dnsmasqContext *dctx)
|
|
|
|
;
|
|
|
|
# else
|
|
|
|
/* Define no-op replacements that don't drag in any link dependencies. */
|
|
|
|
# define networkAllocateActualDevice(iface) 0
|
|
|
|
# define networkNotifyActualDevice(iface) 0
|
|
|
|
# define networkReleaseActualDevice(iface) 0
|
2011-07-26 11:57:34 +00:00
|
|
|
# define networkGetNetworkAddress(netname, netaddr) (-2)
|
2011-07-04 06:27:12 +00:00
|
|
|
# define networkBuildDhcpDaemonCommandLine(network, cmdout, pidfile, dctx) 0
|
|
|
|
# endif
|
2008-10-10 13:57:13 +00:00
|
|
|
|
2011-06-27 14:55:13 +00:00
|
|
|
typedef char *(*networkDnsmasqLeaseFileNameFunc)(const char *netname);
|
|
|
|
|
|
|
|
/* this allows the testsuite to replace the lease filename resolver function */
|
|
|
|
extern networkDnsmasqLeaseFileNameFunc networkDnsmasqLeaseFileName;
|
|
|
|
|
2008-10-10 13:57:13 +00:00
|
|
|
#endif /* __VIR_NETWORK__DRIVER_H */
|