qemu: check if 'floor' is supported for given interface and network

Even if an interface of type 'network', setting 'floor' is only supported
if the network's forward type is nat, route, open or none.

Signed-off-by: Pavel Mores <pmores@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Pavel Mores 2020-02-14 17:26:20 +01:00 committed by Michal Privoznik
parent 92a71456ac
commit aa985af212
4 changed files with 32 additions and 0 deletions

View File

@ -304,3 +304,23 @@ virNetDevBandwidthHasFloor(const virNetDevBandwidth *b)
{ {
return b && b->in && b->in->floor != 0; return b && b->in && b->in->floor != 0;
} }
bool virNetDevBandwidthSupportsFloor(virNetworkForwardType type)
{
switch (type) {
case VIR_NETWORK_FORWARD_NONE:
case VIR_NETWORK_FORWARD_NAT:
case VIR_NETWORK_FORWARD_ROUTE:
case VIR_NETWORK_FORWARD_OPEN:
return true;
case VIR_NETWORK_FORWARD_BRIDGE:
case VIR_NETWORK_FORWARD_PRIVATE:
case VIR_NETWORK_FORWARD_VEPA:
case VIR_NETWORK_FORWARD_PASSTHROUGH:
case VIR_NETWORK_FORWARD_HOSTDEV:
case VIR_NETWORK_FORWARD_LAST:
break;
}
return false;
}

View File

@ -23,6 +23,7 @@
#include "virbuffer.h" #include "virbuffer.h"
#include "virxml.h" #include "virxml.h"
#include "domain_conf.h" #include "domain_conf.h"
#include "network_conf.h"
int virNetDevBandwidthParse(virNetDevBandwidthPtr *bandwidth, int virNetDevBandwidthParse(virNetDevBandwidthPtr *bandwidth,
unsigned int *class_id, unsigned int *class_id,
@ -60,3 +61,4 @@ static inline bool virNetDevSupportBandwidth(virDomainNetType type)
bool virNetDevBandwidthHasFloor(const virNetDevBandwidth *b); bool virNetDevBandwidthHasFloor(const virNetDevBandwidth *b);
bool virNetDevBandwidthSupportsFloor(virNetworkForwardType type);

View File

@ -735,6 +735,7 @@ virDomainClearNetBandwidth;
virNetDevBandwidthFormat; virNetDevBandwidthFormat;
virNetDevBandwidthHasFloor; virNetDevBandwidthHasFloor;
virNetDevBandwidthParse; virNetDevBandwidthParse;
virNetDevBandwidthSupportsFloor;
# conf/netdev_vlan_conf.h # conf/netdev_vlan_conf.h

View File

@ -5065,6 +5065,15 @@ networkCheckBandwidth(virNetworkObjPtr obj,
virMacAddrFormat(ifaceMac, ifmac); virMacAddrFormat(ifaceMac, ifmac);
if (virNetDevBandwidthHasFloor(ifaceBand) &&
!virNetDevBandwidthSupportsFloor(def->forward.type)) {
virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
_("Invalid use of 'floor' on interface with MAC address %s "
"- 'floor' is only supported for interface type 'network' with forward type 'nat', 'route', 'open' or none"),
ifmac);
return -1;
}
if (virNetDevBandwidthHasFloor(ifaceBand) && if (virNetDevBandwidthHasFloor(ifaceBand) &&
!(netBand && netBand->in)) { !(netBand && netBand->in)) {
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, virReportError(VIR_ERR_OPERATION_UNSUPPORTED,