I would like to have a psuedo-wire between two guests in KVM. I cannot use a bridge of any type as the guest VMs are actually virtual switches themselves.
Conceptually, it seems that a veth-pair is the way to go, but after much reading I don't see a way to do this. I can put each guest into its own network namespace, and I can link two net-ns together using veth, but I can't get KVM to recognize the interfaces within the namespaces.
Any help is appreciated.
A VM is usually handled with a tap interface, because its internal NIC is emulated by userspace (usually QEMU): on the other side of this interface presented by the kernel, there's a user space process handling traffic, while on the other side of a veth interface, there's yet again the kernel and its peer veth interface.
Unless QEMU has a feature to connect directly those two interfaces (it's possible this feature does exist, but I didn't find it), like OpenVPN can connect two clients without involving the kernel network stack, then usually a bridge is expected to be used to connect them.
If you can't use a bridge to move data from tap1 to tap2 and from tap2 to tap1 because it could interfere with bridge protocols, it's possible to use a lower level interface, working at the network interface level:
tc
and itstc ... mirred
action which can move a packet from an interface to an other interface. Currentlytc ... mirred
can only have egress as direction for its action which is fine, that's the direction needed here to move ingress from one side to egress on the other side, as seen by the host. So Whatever VM1 outputs (to host's ingress), it's moved to VM2 (host's egress). Whatever VM2 outputs, it's moved to VM1.If the tap interfaces are named tap1 and tap2, you can then "connect" them with this:
These commands create two half-duplex data transfer, for a full-duplex result. On older kernels
matchall
can be replaced withu32 match u32 0 0
For real interfaces the interfaces should also be put in promiscuous mode to not filter by MAC, but I'm not sure that's really needed for virtual non hardware-accelerated interfaces. Else:
The host's network stack will not see redirected packets, as can be seen in this schematic: everything between ingress and egress is short-circuited. Tools like
tcpdump
will still capture those packets, since AF_PACKET is outside the short-circuit. But care should be taken to not have the host inject packets: interfaces should have IPv6 disabled (to avoid SLAAC, NDP, DAD etc.) and no IPv4 address assigned:This will hardly interfere with any KVM usage (including libvirt), but it's related to interfaces. Those commands can be run only once the interfaces exist, and will have to be run again if they disappear and are recreated (VM stopped and restarted).
You can get activity stats with:
If you have more than two VMs and must flood every flow to every other, it's possible, but filters and/or actions must be adapted to not be terminating and allow to first mirror (rather than redirect) as many times as needed and then do a final redirect action (or even no redirect if you want the host's network stack to see traffic).
While this is old, I still can suggest a solution.
You can dedicate a physical NIC to the guest. For example, forward it as a PCI device.
You can connect VMs with L2TPv3 or using various TCP and UDP raw tunneling ("socket") modes:
On the other side you have to reverse addresses and ports. It still works, however, it appears to be undocumented.
For the details read the Networking section in the QEMU manual.