Browse Source

kvm: Update qemu-hook to allow setting MTU of VM interfaces.

  Save domain XML which was given to us on stdin, so we can poke around in it.
  Yes this is ugly. But I don't see another way storing the MTU for an device
  within the libvirt domain config when NOT using a libvirt network.
  If you happen to now a better way than specifying this within custom domain
  metadata PLEASE let me know.

  As the <mtu/> attribute on interfaces does sadly not work when not uing a
  libvirt <network/> and any given <mtu/> value is silently discared in the
  current version we are running, we work around that by using <metadata/>:

  <metadata>
    <ffho:mtu xmlns:ffho="http://ffho.net/libvirt/">
      <interface name="gw02_v1205">1610</interface>
    </ffho:mtu>
  </metadata>

Signed-off-by: Maximilian Wilhelm <max@sdn.clinic>
Maximilian Wilhelm 3 years ago
parent
commit
2747bf6a97
1 changed files with 13 additions and 1 deletions
  1. 13 1
      kvm/qemu-hook

+ 13 - 1
kvm/qemu-hook

@@ -27,7 +27,14 @@ if ! which xmlstarlet >/dev/null 2>/dev/null; then
 	exit 1
 fi
 
-xmlstarlet sel -t -m '//interface[@type="bridge"]' -v 'concat(target/@dev, " ", source/@bridge)'  --nl | while read iface bridge; do
+# Save domain XML which was given to us on stdin, so we can poke around in it.
+# Yes this is ugly. But I don't see another way storing the MTU for an device
+# within the libvirt domain config when NOT using a libvirt network.
+# If you happen to now a better way than specifying this within custom domain
+# metadata PLEASE let me know.
+export domain_xml="$(cat)"
+
+echo "${domain_xml}" | xmlstarlet sel -t -m '//interface[@type="bridge"]' -v 'concat(target/@dev, " ", source/@bridge)'  --nl | while read iface bridge; do
 	if [ ! -d "/sys/class/net/${bridge}/bridge" ]; then
 		logger -t "${my_name}" "Bridge \"${bridge}\" for iface \"${iface}\" doesn't exist or isn't a bridge."
 		exit 2
@@ -62,6 +69,11 @@ xmlstarlet sel -t -m '//interface[@type="bridge"]' -v 'concat(target/@dev, " ",
 
 	# We dont' care about "no vlan filtering AND no vlan id" as well as "vlan filtering AND no vlan id"
 
+	mtu=$(echo "${domain_xml}" | xmlstarlet sel -t -m "//metadata/ffho/interface[@name='${iface}']" -v 'mtu/@size'  --nl || true)
+	if [ "${mtu}" ]; then
+		ip link set mtu "${mtu}" dev "${iface}"
+		logger -t "${my_name}" "Setting MTU of ${iface} to ${mtu}."
+	fi
 
 	# If there is an configuration stanza in /etc/network/interfaces
 	# for this interfaces, we try to get it up and running. Proceed