for (i = 0; i < ipdef->nhosts; i++) {
virNetworkDHCPHostDefPtr host = &(ipdef->hosts[i]);
if ((host->mac) && VIR_SOCKET_HAS_ADDR(&host->ip))
- dnsmasqAddDhcpHost(dctx, host->mac, &host->ip, host->name);
+ if (dnsmasqAddDhcpHost(dctx, host->mac, &host->ip, host->name) < 0)
+ return -1;
}
if (dnsdef) {
virNetworkDNSHostsDefPtr host = &(dnsdef->hosts[i]);
if (VIR_SOCKET_HAS_ADDR(&host->ip)) {
for (j = 0; j < host->nnames; j++)
- dnsmasqAddHost(dctx, &host->ip, host->names[j]);
+ if (dnsmasqAddHost(dctx, &host->ip, host->names[j]) < 0)
+ return -1;
}
}
}
if (network->def->domain)
virCommandAddArg(cmd, "--expand-hosts");
- if (networkBuildDnsmasqHostsfile(dctx, ipdef, network->def->dns) >= 0) {
- if (dctx->hostsfile->nhosts)
- virCommandAddArgPair(cmd, "--dhcp-hostsfile",
- dctx->hostsfile->path);
- if (dctx->addnhostsfile->nhosts)
- virCommandAddArgPair(cmd, "--addn-hosts",
- dctx->addnhostsfile->path);
- }
+ if (networkBuildDnsmasqHostsfile(dctx, ipdef, network->def->dns) < 0)
+ goto cleanup;
+
+ if (dctx->hostsfile->nhosts)
+ virCommandAddArgPair(cmd, "--dhcp-hostsfile",
+ dctx->hostsfile->path);
+ if (dctx->addnhostsfile->nhosts)
+ virCommandAddArgPair(cmd, "--addn-hosts",
+ dctx->addnhostsfile->path);
if (ipdef->tftproot) {
virCommandAddArgList(cmd, "--enable-tftp",
*
* Add dhcp-host entry.
*/
-void
+int
dnsmasqAddDhcpHost(dnsmasqContext *ctx,
const char *mac,
virSocketAddr *ip,
const char *name)
{
- if (ctx->hostsfile)
- hostsfileAdd(ctx->hostsfile, mac, ip, name);
+ return hostsfileAdd(ctx->hostsfile, mac, ip, name);
}
/*
* Add additional host entry.
*/
-void
+int
dnsmasqAddHost(dnsmasqContext *ctx,
virSocketAddr *ip,
const char *name)
{
- if (ctx->addnhostsfile)
- addnhostsAdd(ctx->addnhostsfile, ip, name);
+ return addnhostsAdd(ctx->addnhostsfile, ip, name);
}
/**
dnsmasqContext * dnsmasqContextNew(const char *network_name,
const char *config_dir);
void dnsmasqContextFree(dnsmasqContext *ctx);
-void dnsmasqAddDhcpHost(dnsmasqContext *ctx,
+int dnsmasqAddDhcpHost(dnsmasqContext *ctx,
const char *mac,
virSocketAddr *ip,
const char *name);
-void dnsmasqAddHost(dnsmasqContext *ctx,
+int dnsmasqAddHost(dnsmasqContext *ctx,
virSocketAddr *ip,
const char *name);
int dnsmasqSave(const dnsmasqContext *ctx);