diff --git a/run/network.sh b/run/network.sh index b599460..08b015f 100644 --- a/run/network.sh +++ b/run/network.sh @@ -22,48 +22,23 @@ set -Eeuo pipefail configureDHCP() { - VM_NET_VLAN="${VM_NET_TAP}_vlan" - NETWORK=$(ip -o route | grep "${VM_NET_DEV}" | grep -v default | awk '{print $1}') - IP=$(ip address show dev "${VM_NET_DEV}" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/) - - [[ "${DEBUG}" == [Yy1]* ]] && set -x - - # Create a macvlan network to allow for communication from the VM guest to the host - { ip link add link "${VM_NET_DEV}" "${VM_NET_VLAN}" type macvlan mode bridge ; rc=$?; } || : - - if (( rc != 0 )); then - error "Cannot create macvlan interface. Please make sure the network type is 'macvlan' and not 'ipvlan'," - error "and that the NET_ADMIN capability has been added to the container config: --cap-add NET_ADMIN" && exit 15 - fi - - ip address add "${IP}" dev "${VM_NET_VLAN}" - ip link set dev "${VM_NET_VLAN}" up - ip route flush dev "${VM_NET_VLAN}" - - ip route del "${NETWORK}" dev "${VM_NET_DEV}" - ip route add "${NETWORK}" dev "${VM_NET_VLAN}" metric 0 - # Create a macvtap network for the VM guest - { ip link add link "${VM_NET_DEV}" name "${VM_NET_TAP}" address "${VM_NET_MAC}" type macvtap mode bridge ; rc=$?; } || : + { ip link add link "${VM_NET_DEV}" name "${VM_NET_TAP}" address "${VM_NET_MAC}" type macvtap mode bridge ; rc=$?; } |: + if (( rc != 0 )); then - error "Capability NET_ADMIN has not been set most likely. Please add the " - error "following docker setting to your container: --cap-add NET_ADMIN" && exit 16 + error "Cannot create macvtap interface. Please make sure the network type is 'macvlan' and not 'ipvlan'," + error "and that the NET_ADMIN capability has been added to the container config: --cap-add NET_ADMIN" && exit 16 fi ip link set "${VM_NET_TAP}" up - { set +x; } 2>/dev/null - TAP_NR=$(/dev/null + + [[ "${DEBUG}" == [Yy1]* ]] && echo } # ###################################### @@ -235,6 +213,4 @@ fi NET_OPTS="${NET_OPTS} -device virtio-net-pci,romfile=,netdev=hostnet0,mac=${VM_NET_MAC},id=net0" -[[ "${DEBUG}" == [Yy1]* ]] && echo && info "Finished network setup.." && echo - return 0