mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 11:22:23 +00:00
Set broadcast address for IPv4 addresses on virtual network bridges
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.
This commit is contained in:
parent
86387878b0
commit
2eeeb60152
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user