summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominique Martinet <asmadeus@codewreck.org>2015-12-04 12:51:51 +0100
committerDominique Martinet <asmadeus@codewreck.org>2015-12-04 12:52:12 +0100
commit31e7dc0e0d1b307d7905f579ee3d65ac026bbc11 (patch)
tree9187257939afe412c80f8c2824c782c2d14759db
parenta02fe896f5158e5e19991b2b3d676a1d2b172f14 (diff)
net: cap TAPDEV length (ip silently truncates to 15 chars)
-rwxr-xr-xkvm-wrapper.sh8
1 files changed, 7 insertions, 1 deletions
diff --git a/kvm-wrapper.sh b/kvm-wrapper.sh
index 0a4afb2..f864661 100755
--- a/kvm-wrapper.sh
+++ b/kvm-wrapper.sh
@@ -680,7 +680,13 @@ function kvm_start_vm ()
KVM_IF[$i]="${KVM_IF[i]:-${KVM_IF[@]:0:1}}"
KVM_NET_OPT[$i]="${KVM_NET_OPT[i]-${KVM_NET_OPT[@]:0:1}}"
KVM_NET_MTU[$i]="${KVM_NET_MTU[i]-${KVM_NET_MTU[@]:0:1}}"
- local TAPDEV=tap-${VM_NAME}-${i}
+ local TAPDEV
+
+ # tapdev can only be 15 chars long, if VM_NAME is too long keep start + last 2 chars
+ # and pray for no collision...
+ [[ $(( ${#VM_NAME} + ${#i} )) -le 10 ]] && \
+ TAPDEV=tap-${VM_NAME:0:$((10-${#i}))}-${i} || \
+ TAPDEV=tap-${VM_NAME:0:$((8-${#i}))}${VM_NAME:(-2)}-${i}
KVM_NET+="-netdev type=tap,id=guest${i},ifname=${TAPDEV},script=no,downscript=no${KVM_NET_OPT[i]} -device ${KVM_IF[i]},netdev=guest${i},mac=${KVM_MACADDR[i]} "
ip tuntap add dev $TAPDEV mode tap ${KVM_USER+user $KVM_USER}
ip link set $TAPDEV ${KVM_NET_MTU[$i]:+mtu ${KVM_NET_MTU[$i]}} up