[libvirt] [PATCH v2 4/5] Network: Add additional hosts internal infrastructure

Michal Novotny minovotn at redhat.com
Thu Apr 28 15:00:07 UTC 2011


On 04/28/2011 03:31 AM, Laine Stump wrote:
> Coming back to this now that I see how it's being used...
>
> On 04/01/2011 06:45 AM, Michal Novotny wrote:
>> Hi,
>> this is the patch to introduce the internal infrastructure for
>> additional hosts for network bridge driver using the addnhosts*
>> API functions.
>>
>> This is necessary for next part of the patch to support DNS
>> hosts definition in the network XML description.
>>
>> Michal
>>
>> Signed-off-by: Michal Novotny<minovotn at redhat.com>
>> ---
>>   src/libvirt_private.syms    |    1 +
>>   src/network/bridge_driver.c |    3 +
>>   src/util/dnsmasq.c          |  266 ++++++++++++++++++++++++++++++++++++++++++-
>>   src/util/dnsmasq.h          |   22 ++++-
>>   4 files changed, 287 insertions(+), 5 deletions(-)
>>
>> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
>> index 65a86d3..73c3f77 100644
>> --- a/src/libvirt_private.syms
>> +++ b/src/libvirt_private.syms
>> @@ -186,6 +186,7 @@ virUnrefStream;
>>
>>   # dnsmasq.h
>>   dnsmasqAddDhcpHost;
>> +dnsmasqAddHost;
>>   dnsmasqContextFree;
>>   dnsmasqContextNew;
>>   dnsmasqDelete;
>> diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
>> index 41b14f9..4ad3143 100644
>> --- a/src/network/bridge_driver.c
>> +++ b/src/network/bridge_driver.c
>> @@ -589,6 +589,9 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
>>               if (dctx->hostsfile->nhosts)
>>                   virCommandAddArgPair(cmd, "--dhcp-hostsfile",
>>                                        dctx->hostsfile->path);
>> +            if (dctx->addnhostsfile->nhosts)
>> +                virCommandAddArgPair(cmd, "--addn-hosts",
>> +                                     dctx->addnhostsfile->path);
>>
>>               dnsmasqContextFree(dctx);
>>           }
>> diff --git a/src/util/dnsmasq.c b/src/util/dnsmasq.c
>> index be230e1..fee3b90 100644
>> --- a/src/util/dnsmasq.c
>> +++ b/src/util/dnsmasq.c
>> @@ -48,6 +48,7 @@
>>
>>   #define VIR_FROM_THIS VIR_FROM_NETWORK
>>   #define DNSMASQ_HOSTSFILE_SUFFIX "hostsfile"
>> +#define DNSMASQ_ADDNHOSTSFILE_SUFFIX "addnhosts"
>>
>>   static void
>>   dhcphostFree(dnsmasqDhcpHost *host)
>> @@ -56,6 +57,231 @@ dhcphostFree(dnsmasqDhcpHost *host)
>>   }
>>
>>   static void
>> +addnhostFree(dnsmasqAddnHost *host)
>> +{
>> +    VIR_FREE(host->hostnames);
> You haven't freed host->hostnames[0], hostnames[1], etc; you've only 
> freed the array of pointers.
>
>
>> +    VIR_FREE(host->ip);
>> +}
>> +
>> +static void
>> +addnhostsFree(dnsmasqAddnHostsfile *addnhostsfile)
>> +{
>> +    unsigned int i;
>> +
>> +    if (addnhostsfile->hosts) {
>> +        for (i = 0; i<  addnhostsfile->nhosts; i++)
>> +            addnhostFree(&addnhostsfile->hosts[i]);
>> +
>> +        VIR_FREE(addnhostsfile->hosts);
>> +
>> +        addnhostsfile->nhosts = 0;
>> +    }
>> +
>> +    VIR_FREE(addnhostsfile->path);
>> +
>> +    VIR_FREE(addnhostsfile);
>> +}
>> +
>> +static int
>> +addnhostsAdd(dnsmasqAddnHostsfile *addnhostsfile,
>> +             virSocketAddr *ip,
> You could also mark ip as a const.

Well, not really since I was unable to compile it anymore when prefixing
it with const keyword.

Michal

-- 
Michal Novotny <minovotn at redhat.com>, RHCE
Virtualization Team (xen userspace), Red Hat




More information about the libvir-list mailing list