Commit 6e244c added the ability to set the IP address and peer address
for the tap interface used by <interface type='ethernet'> in
qemu. However, it sets the "address" on the host-side of the tap, and
the "peer" on the guest side. This is opposite to what is done with
veth interfaces in the lxc driver, where "address" is the guest veth
of the pair, and "peer" is the host side veth.
This patch makes the two operate consistently from the user's point of
view, by swapping peer and address when setting the IP info of the tap
device.
Although the peer device is optional in the virNetDevSetIPAddress
call, once we've swapped them, it is the "address" from the config
that is being set as the peer in the device, and vice versa; Since
address is *not* optional when calling virNetDevSetIPAddress, this
means that "peer" is required in the config, so we check that "peer"
is present, and log an error if it isn't.
---
src/qemu/qemu_interface.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/src/qemu/qemu_interface.c b/src/qemu/qemu_interface.c
index 58bbe71..6326b0a 100644
--- a/src/qemu/qemu_interface.c
+++ b/src/qemu/qemu_interface.c
@@ -457,10 +457,17 @@ qemuInterfaceEthernetConnect(virDomainDefPtr def,
VIR_FREE(peerStr);
ipStr = virSocketAddrFormat(&ip->address);
- if (VIR_SOCKET_ADDR_VALID(&ip->peer))
+ if (VIR_SOCKET_ADDR_VALID(&ip->peer)) {
peerStr = virSocketAddrFormat(&ip->peer);
- else if (VIR_STRDUP(peerStr, "[none]") < 0)
+ } else {
+ /* for qemu tap devices, the "peer" address is actually
+ * the address of the interface itself, so it must be set
+ */
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Missing required peer for address
'%s'"),
+ ipStr);
goto cleanup;
+ }
if ((prefix = virSocketAddrGetIpPrefix(&ip->address,
NULL, ip->prefix)) < 0) {
@@ -473,7 +480,7 @@ qemuInterfaceEthernetConnect(virDomainDefPtr def,
VIR_DEBUG("Adding IP address '%s/%d' (peer %s) to
'%s'",
ipStr, prefix, peerStr, net->ifname);
- if (virNetDevSetIPAddress(net->ifname, &ip->address, &ip->peer,
prefix) < 0) {
+ if (virNetDevSetIPAddress(net->ifname, &ip->peer, &ip->address,
prefix) < 0) {
virReportError(VIR_ERR_SYSTEM_ERROR,
_("Failed to set IP address '%s/%u' (peer %s) on
%s"),
ipStr, prefix, peerStr, net->ifname);
--
2.5.5