mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 21:55:25 +00:00
network: verify proper address family in updates to <host> and <range>
By specifying parentIndex in a call to virNetworkUpdate(), it was possible to direct libvirt to add a dhcp range or static host of a non-matching address family to the <dhcp> element of an <ip>. For example, given: <ip address='192.168.122.1' netmask='255.255.255.0'/> <ip family='ipv6' address='2001:db6:ca3:45::1' prefix='64'/> you could provide a static host entry with an IPv4 address, and specify that it be added to the 2nd <ip> element (index 1): virsh net-update default add ip-dhcp-host --parent-index 1 \ '<host mac="52:54:00:00:00:01" ip="192.168.122.45"/>' This would be happily added with no error (and no concern of any possible future consequences). This patch checks that any dhcp range or host element being added to a network ip's <dhcp> subelement has addresses of the same family as the ip element they are being added to. This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1184736
This commit is contained in:
parent
7d69387cd6
commit
6a21bc119e
@ -3500,6 +3500,15 @@ virNetworkDefUpdateIPDHCPHost(virNetworkDefPtr def,
|
||||
&host, partialOkay) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (!partialOkay &&
|
||||
VIR_SOCKET_ADDR_FAMILY(&ipdef->address)
|
||||
!= VIR_SOCKET_ADDR_FAMILY(&host.ip)) {
|
||||
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||
_("the address family of a host entry IP must match "
|
||||
"the address family of the dhcp element's parent"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (command == VIR_NETWORK_UPDATE_COMMAND_MODIFY) {
|
||||
|
||||
/* search for the entry with this (ip|mac|name),
|
||||
@ -3637,6 +3646,14 @@ virNetworkDefUpdateIPDHCPRange(virNetworkDefPtr def,
|
||||
if (virSocketAddrRangeParseXML(def->name, ipdef, ctxt->node, &range) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (VIR_SOCKET_ADDR_FAMILY(&ipdef->address)
|
||||
!= VIR_SOCKET_ADDR_FAMILY(&range.start)) {
|
||||
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||
_("the address family of a dhcp range must match "
|
||||
"the address family of the dhcp element's parent"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* check if an entry with same name/address/ip already exists */
|
||||
for (i = 0; i < ipdef->nranges; i++) {
|
||||
if (virSocketAddrEqual(&range.start, &ipdef->ranges[i].start) &&
|
||||
|
Loading…
Reference in New Issue
Block a user