From aa985af212c89002dddcb87d900a3d59399f11f5 Mon Sep 17 00:00:00 2001 From: Pavel Mores Date: Fri, 14 Feb 2020 17:26:20 +0100 Subject: [PATCH] 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 Signed-off-by: Michal Privoznik --- src/conf/netdev_bandwidth_conf.c | 20 ++++++++++++++++++++ src/conf/netdev_bandwidth_conf.h | 2 ++ src/libvirt_private.syms | 1 + src/network/bridge_driver.c | 9 +++++++++ 4 files changed, 32 insertions(+) diff --git a/src/conf/netdev_bandwidth_conf.c b/src/conf/netdev_bandwidth_conf.c index 6307ac4d56..5cbb9f46e4 100644 --- a/src/conf/netdev_bandwidth_conf.c +++ b/src/conf/netdev_bandwidth_conf.c @@ -304,3 +304,23 @@ virNetDevBandwidthHasFloor(const virNetDevBandwidth *b) { 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; +} diff --git a/src/conf/netdev_bandwidth_conf.h b/src/conf/netdev_bandwidth_conf.h index 0e10a4cb01..b9e57168be 100644 --- a/src/conf/netdev_bandwidth_conf.h +++ b/src/conf/netdev_bandwidth_conf.h @@ -23,6 +23,7 @@ #include "virbuffer.h" #include "virxml.h" #include "domain_conf.h" +#include "network_conf.h" int virNetDevBandwidthParse(virNetDevBandwidthPtr *bandwidth, unsigned int *class_id, @@ -60,3 +61,4 @@ static inline bool virNetDevSupportBandwidth(virDomainNetType type) bool virNetDevBandwidthHasFloor(const virNetDevBandwidth *b); +bool virNetDevBandwidthSupportsFloor(virNetworkForwardType type); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 73c94ed81a..125d1836dd 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -735,6 +735,7 @@ virDomainClearNetBandwidth; virNetDevBandwidthFormat; virNetDevBandwidthHasFloor; virNetDevBandwidthParse; +virNetDevBandwidthSupportsFloor; # conf/netdev_vlan_conf.h diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 6d7eadad43..8b1f722eb6 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -5065,6 +5065,15 @@ networkCheckBandwidth(virNetworkObjPtr obj, 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) && !(netBand && netBand->in)) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, -- GitLab