提交 3583e75d 编写于 作者: L Laine Stump

network: prevent duplicate entries in network device pools

Prior to this patch we didn't make any attempt to prevent two entries
in the array of interfaces/PCI devices from pointing to the same
device.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1002423
上级 3a773c43
/*
* network_conf.c: network XML handling
*
* Copyright (C) 2006-2015 Red Hat, Inc.
* Copyright (C) 2006-2016 Red Hat, Inc.
* Copyright (C) 2006-2008 Daniel P. Berrange
*
* This library is free software; you can redistribute it and/or
......@@ -1799,7 +1799,7 @@ virNetworkForwardDefParseXML(const char *networkName,
xmlXPathContextPtr ctxt,
virNetworkForwardDefPtr def)
{
size_t i;
size_t i, j;
int ret = -1;
xmlNodePtr *forwardIfNodes = NULL;
xmlNodePtr *forwardPfNodes = NULL;
......@@ -1936,6 +1936,16 @@ virNetworkForwardDefParseXML(const char *networkName,
continue;
}
for (j = 0; j < i; j++) {
if (STREQ_NULLABLE(def->ifs[j].device.dev, forwardDev)) {
virReportError(VIR_ERR_XML_ERROR,
_("interface '%s' can only be "
"listed once in network %s"),
forwardDev, networkName);
goto cleanup;
}
}
def->ifs[i].device.dev = forwardDev;
forwardDev = NULL;
def->ifs[i].type = VIR_NETWORK_FORWARD_HOSTDEV_DEVICE_NETDEV;
......@@ -1963,12 +1973,25 @@ virNetworkForwardDefParseXML(const char *networkName,
switch (def->ifs[i].type) {
case VIR_NETWORK_FORWARD_HOSTDEV_DEVICE_PCI:
if (virDevicePCIAddressParseXML(forwardAddrNodes[i],
&def->ifs[i].device.pci) < 0) {
{
virDevicePCIAddressPtr addr = &def->ifs[i].device.pci;
if (virDevicePCIAddressParseXML(forwardAddrNodes[i], addr) < 0)
goto cleanup;
for (j = 0; j < i; j++) {
if (virDevicePCIAddressEqual(addr, &def->ifs[j].device.pci)) {
virReportError(VIR_ERR_XML_ERROR,
_("PCI device '%04x:%02x:%02x.%x' can "
"only be listed once in network %s"),
addr->domain, addr->bus,
addr->slot, addr->function,
networkName);
goto cleanup;
}
}
break;
}
/* Add USB case here if we ever find a reason to support it */
default:
......
<network>
<name>hostdev</name>
<uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
<forward mode='hostdev' managed='yes'>
<address type='pci' domain='0x0000' bus='0x03' slot='0x00' function='0x1'/>
<address type='pci' domain='0x0000' bus='0x03' slot='0x00' function='0x2'/>
<address type='pci' domain='0x0000' bus='0x03' slot='0x00' function='0x3'/>
<address type='pci' domain='0x0000' bus='0x03' slot='0x00' function='0x3'/>
<address type='pci' domain='0x0000' bus='0x03' slot='0x00' function='0x4'/>
</forward>
</network>
<network>
<name>passthrough-duplicate</name>
<uuid>81ff0d90-c91e-6742-64da-4a736edb9a8b</uuid>
<forward mode="passthrough">
<interface dev="eth1"/>
<interface dev="eth2"/>
<interface dev="eth3"/>
<interface dev="eth3"/>
</forward>
</network>
......@@ -151,6 +151,8 @@ mymain(void)
DO_TEST("passthrough-address-crash");
DO_TEST("nat-network-explicit-flood");
DO_TEST("host-bridge-no-flood");
DO_TEST_PARSE_ERROR("hostdev-duplicate");
DO_TEST_PARSE_ERROR("passthrough-duplicate");
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册