提交 23ae3fe4 编写于 作者: P Peter Krempa

net: Move creation of dnsmasq hosts file to function starting dnsmasq

The hosts file was created in the network definition function. This
patch moves the place the file is being created to the point where
dnsmasq is being started.
上级 a3258c0e
...@@ -846,6 +846,8 @@ networkStartDhcpDaemon(virNetworkObjPtr network) ...@@ -846,6 +846,8 @@ networkStartDhcpDaemon(virNetworkObjPtr network)
char *pidfile = NULL; char *pidfile = NULL;
int ret = -1; int ret = -1;
dnsmasqContext *dctx = NULL; dnsmasqContext *dctx = NULL;
virNetworkIpDefPtr ipdef;
int i;
if (!virNetworkDefGetIpByIndex(network->def, AF_UNSPEC, 0)) { if (!virNetworkDefGetIpByIndex(network->def, AF_UNSPEC, 0)) {
/* no IPv6 addresses, so we don't need to run radvd */ /* no IPv6 addresses, so we don't need to run radvd */
...@@ -886,6 +888,18 @@ networkStartDhcpDaemon(virNetworkObjPtr network) ...@@ -886,6 +888,18 @@ networkStartDhcpDaemon(virNetworkObjPtr network)
if (ret < 0) if (ret < 0)
goto cleanup; goto cleanup;
/* populate dnsmasq hosts file */
for (i = 0; (ipdef = virNetworkDefGetIpByIndex(network->def, AF_UNSPEC, i)); i++) {
if (VIR_SOCKET_ADDR_IS_FAMILY(&ipdef->address, AF_INET) &&
(ipdef->nranges || ipdef->nhosts)) {
if (networkBuildDnsmasqHostsfile(dctx, ipdef,
network->def->dns) < 0)
goto cleanup;
break;
}
}
ret = dnsmasqSave(dctx); ret = dnsmasqSave(dctx);
if (ret < 0) if (ret < 0)
goto cleanup; goto cleanup;
...@@ -2742,7 +2756,6 @@ static virNetworkPtr networkDefine(virConnectPtr conn, const char *xml) { ...@@ -2742,7 +2756,6 @@ static virNetworkPtr networkDefine(virConnectPtr conn, const char *xml) {
virNetworkObjPtr network = NULL; virNetworkObjPtr network = NULL;
virNetworkPtr ret = NULL; virNetworkPtr ret = NULL;
int ii; int ii;
dnsmasqContext* dctx = NULL;
networkDriverLock(driver); networkDriverLock(driver);
...@@ -2799,21 +2812,12 @@ static virNetworkPtr networkDefine(virConnectPtr conn, const char *xml) { ...@@ -2799,21 +2812,12 @@ static virNetworkPtr networkDefine(virConnectPtr conn, const char *xml) {
goto cleanup; goto cleanup;
} }
if (ipv4def) {
dctx = dnsmasqContextNew(def->name, DNSMASQ_STATE_DIR);
if (dctx == NULL ||
networkBuildDnsmasqHostsfile(dctx, ipv4def, def->dns) < 0 ||
dnsmasqSave(dctx) < 0)
goto cleanup;
}
VIR_INFO("Defining network '%s'", def->name); VIR_INFO("Defining network '%s'", def->name);
ret = virGetNetwork(conn, def->name, def->uuid); ret = virGetNetwork(conn, def->name, def->uuid);
cleanup: cleanup:
if (freeDef) if (freeDef)
virNetworkDefFree(def); virNetworkDefFree(def);
dnsmasqContextFree(dctx);
if (network) if (network)
virNetworkObjUnlock(network); virNetworkObjUnlock(network);
networkDriverUnlock(driver); networkDriverUnlock(driver);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册