[libvirt] [PATCH 2/3] Set broadcast address for IPv4 addresses on virtual network bridges

Laine Stump laine at laine.org
Fri Dec 31 16:36:40 UTC 2010


On 12/31/2010 08:10 AM, Stefan Berger wrote:
> On 12/31/2010 06:33 AM, Laine Stump wrote:
>> Previously we used ioctl() to set the IP address and netmask of the
>> bridges used for virtual networks, and apparently the SIOCSIFNETMASK
>> ioctl implicitly set the broadcast address for the interface. The new
>> method of using the "ip" command requires broadcast address to be
>> explicitly specified though.
>> ---
>>   src/util/bridge.c |   12 +++++++++++-
>>   1 files changed, 11 insertions(+), 1 deletions(-)
>>
>> diff --git a/src/util/bridge.c b/src/util/bridge.c
>> index 81a043c..e53fce5 100644
>> --- a/src/util/bridge.c
>> +++ b/src/util/bridge.c
>> @@ -677,14 +677,23 @@ brAddInetAddress(brControl *ctl ATTRIBUTE_UNUSED,
>>                    unsigned int prefix)
>>   {
>>       virCommandPtr cmd = NULL;
>> -    char *addrstr;
>> +    char *addrstr = NULL, *bcaststr = NULL;
>> +    virSocketAddr broadcast;
>>       int ret = -1;
>>
>>       if (!(addrstr = virSocketFormatAddr(addr)))
>>           goto cleanup;
>> +    /* format up a broadcast address if this is IPv4 */
>> +    if ((VIR_SOCKET_IS_FAMILY(addr, AF_INET))&&
>> +        ((virSocketAddrBroadcastByPrefix(addr, prefix,&broadcast)<  
>> 0) ||
>> +         !(bcaststr = virSocketFormatAddr(&broadcast)))) {
>> +        goto cleanup;
>> +    }
>>       cmd = virCommandNew(IP_PATH);
>>       virCommandAddArgList(cmd, "addr", "add", NULL);
>>       virCommandAddArgFormat(cmd, "%s/%u", addrstr, prefix);
>> +    if (bcaststr)
>> +        virCommandAddArgList(cmd, "broadcast", bcaststr, NULL);
>>       virCommandAddArgList(cmd, "dev", ifname, NULL);
>>
>>       if (virCommandRun(cmd, NULL)<  0)
>> @@ -693,6 +702,7 @@ brAddInetAddress(brControl *ctl ATTRIBUTE_UNUSED,
>>       ret = 0;
>>   cleanup:
>>       VIR_FREE(addrstr);
>> +    VIR_FREE(bcaststr);
>>       virCommandFree(cmd);
>>       return ret;
>>   }
>
> ACK.
>     Stefan
>
>

Thanks (for the review and for finding the bug!). Pushed.




More information about the libvir-list mailing list