Multiline errors
Multiline errors
This commit is contained in:
commit
6c83d531ac
1 changed files with 19 additions and 21 deletions
|
@ -28,11 +28,13 @@ configureDHCP() {
|
||||||
IP=$(ip address show dev "${VM_NET_DEV}" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/)
|
IP=$(ip address show dev "${VM_NET_DEV}" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/)
|
||||||
|
|
||||||
[[ "${DEBUG}" == [Yy1]* ]] && set -x
|
[[ "${DEBUG}" == [Yy1]* ]] && set -x
|
||||||
|
|
||||||
|
# Create a macvlan network to allow for communication between the host and the VM guest
|
||||||
{ ip link add link "${VM_NET_DEV}" "${VM_NET_VLAN}" type macvlan mode bridge ; rc=$?; } || :
|
{ ip link add link "${VM_NET_DEV}" "${VM_NET_VLAN}" type macvlan mode bridge ; rc=$?; } || :
|
||||||
|
|
||||||
if (( rc != 0 )); then
|
if (( rc != 0 )); then
|
||||||
echo -n "ERROR: Cannot create macvlan interface. Please make sure the network type is 'macvlan' and not 'ipvlan'."
|
echo "ERROR: Cannot create macvlan interface. Please make sure the network type is 'macvlan' and not 'ipvlan',"
|
||||||
echo " And that the NET_ADMIN capability has been added to the container config: --cap-add NET_ADMIN" && exit 15
|
echo "ERROR: and that the NET_ADMIN capability has been added to the container config: --cap-add NET_ADMIN" && exit 15
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ip address add "${IP}" dev "${VM_NET_VLAN}"
|
ip address add "${IP}" dev "${VM_NET_VLAN}"
|
||||||
|
@ -44,18 +46,16 @@ configureDHCP() {
|
||||||
ip route add "${NETWORK}" dev "${VM_NET_VLAN}" metric 0
|
ip route add "${NETWORK}" dev "${VM_NET_VLAN}" metric 0
|
||||||
ip route add default via "${GATEWAY}"
|
ip route add default via "${GATEWAY}"
|
||||||
|
|
||||||
|
# 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
|
if (( rc != 0 )); then
|
||||||
echo -n "ERROR: Capability NET_ADMIN has not been set most likely. Please add the "
|
echo "ERROR: Capability NET_ADMIN has not been set most likely. Please add the "
|
||||||
echo "following docker setting to your container: --cap-add NET_ADMIN" && exit 16
|
echo "ERROR: following docker setting to your container: --cap-add NET_ADMIN" && exit 16
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ip link set "${VM_NET_TAP}" up
|
ip link set "${VM_NET_TAP}" up
|
||||||
|
|
||||||
ip address flush "${VM_NET_DEV}"
|
|
||||||
ip address flush "${VM_NET_TAP}"
|
|
||||||
|
|
||||||
{ set +x; } 2>/dev/null
|
{ set +x; } 2>/dev/null
|
||||||
|
|
||||||
TAP_NR=$(</sys/class/net/"${VM_NET_TAP}"/ifindex)
|
TAP_NR=$(</sys/class/net/"${VM_NET_TAP}"/ifindex)
|
||||||
|
@ -78,15 +78,15 @@ configureDHCP() {
|
||||||
{ exec 30>>"$TAP_PATH"; rc=$?; } || :
|
{ exec 30>>"$TAP_PATH"; rc=$?; } || :
|
||||||
|
|
||||||
if (( rc != 0 )); then
|
if (( rc != 0 )); then
|
||||||
echo -n "ERROR: Cannot create TAP interface ($rc). Please add the following docker settings to your "
|
echo "ERROR: Cannot create TAP interface ($rc). Please add the following docker settings to your "
|
||||||
echo "container: --device-cgroup-rule='c ${MAJOR}:* rwm' --device=/dev/vhost-net" && exit 21
|
echo "ERROR: container: --device-cgroup-rule='c ${MAJOR}:* rwm' --device=/dev/vhost-net" && exit 21
|
||||||
fi
|
fi
|
||||||
|
|
||||||
{ exec 40>>/dev/vhost-net; rc=$?; } || :
|
{ exec 40>>/dev/vhost-net; rc=$?; } || :
|
||||||
|
|
||||||
if (( rc != 0 )); then
|
if (( rc != 0 )); then
|
||||||
echo -n "ERROR: VHOST can not be found ($rc). Please add the following "
|
echo "ERROR: VHOST can not be found ($rc). Please add the following "
|
||||||
echo "docker setting to your container: --device=/dev/vhost-net" && exit 22
|
echo "ERROR: docker setting to your container: --device=/dev/vhost-net" && exit 22
|
||||||
fi
|
fi
|
||||||
|
|
||||||
NET_OPTS="-netdev tap,id=hostnet0,vhost=on,vhostfd=40,fd=30"
|
NET_OPTS="-netdev tap,id=hostnet0,vhost=on,vhostfd=40,fd=30"
|
||||||
|
@ -97,24 +97,23 @@ configureNAT () {
|
||||||
VM_NET_IP='20.20.20.21'
|
VM_NET_IP='20.20.20.21'
|
||||||
[[ "${DEBUG}" == [Yy1]* ]] && set -x
|
[[ "${DEBUG}" == [Yy1]* ]] && set -x
|
||||||
|
|
||||||
#Create bridge with static IP for the VM guest
|
# Create bridge with static IP for the VM guest
|
||||||
|
|
||||||
{ ip link add dev dockerbridge type bridge ; rc=$?; } || :
|
{ ip link add dev dockerbridge type bridge ; rc=$?; } || :
|
||||||
|
|
||||||
if (( rc != 0 )); then
|
if (( rc != 0 )); then
|
||||||
echo -n "ERROR: Capability NET_ADMIN has not been set most likely. Please add the "
|
echo "ERROR: Capability NET_ADMIN has not been set most likely. Please add the "
|
||||||
echo "following docker setting to your container: --cap-add NET_ADMIN" && exit 23
|
echo "ERROR: following docker setting to your container: --cap-add NET_ADMIN" && exit 23
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ip address add ${VM_NET_IP%.*}.1/24 broadcast ${VM_NET_IP%.*}.255 dev dockerbridge
|
ip address add ${VM_NET_IP%.*}.1/24 broadcast ${VM_NET_IP%.*}.255 dev dockerbridge
|
||||||
ip link set dockerbridge up
|
ip link set dockerbridge up
|
||||||
|
|
||||||
#QEMU Works with taps, set tap to the bridge created
|
# QEMU Works with taps, set tap to the bridge created
|
||||||
ip tuntap add dev "${VM_NET_TAP}" mode tap
|
ip tuntap add dev "${VM_NET_TAP}" mode tap
|
||||||
ip link set "${VM_NET_TAP}" up promisc on
|
ip link set "${VM_NET_TAP}" up promisc on
|
||||||
ip link set dev "${VM_NET_TAP}" master dockerbridge
|
ip link set dev "${VM_NET_TAP}" master dockerbridge
|
||||||
|
|
||||||
#Add internet connection to the VM
|
# Add internet connection to the VM
|
||||||
iptables -t nat -A POSTROUTING -o "${VM_NET_DEV}" -j MASQUERADE
|
iptables -t nat -A POSTROUTING -o "${VM_NET_DEV}" -j MASQUERADE
|
||||||
iptables -t nat -A PREROUTING -i "${VM_NET_DEV}" -p tcp -j DNAT --to $VM_NET_IP
|
iptables -t nat -A PREROUTING -i "${VM_NET_DEV}" -p tcp -j DNAT --to $VM_NET_IP
|
||||||
iptables -t nat -A PREROUTING -i "${VM_NET_DEV}" -p udp -j DNAT --to $VM_NET_IP
|
iptables -t nat -A PREROUTING -i "${VM_NET_DEV}" -p udp -j DNAT --to $VM_NET_IP
|
||||||
|
@ -127,12 +126,11 @@ configureNAT () {
|
||||||
{ set +x; } 2>/dev/null
|
{ set +x; } 2>/dev/null
|
||||||
[[ "${DEBUG}" == [Yy1]* ]] && echo
|
[[ "${DEBUG}" == [Yy1]* ]] && echo
|
||||||
|
|
||||||
#Check port forwarding flag
|
# Check port forwarding flag
|
||||||
if [[ $(< /proc/sys/net/ipv4/ip_forward) -eq 0 ]]; then
|
if [[ $(< /proc/sys/net/ipv4/ip_forward) -eq 0 ]]; then
|
||||||
{ sysctl -w net.ipv4.ip_forward=1 ; rc=$?; } || :
|
{ sysctl -w net.ipv4.ip_forward=1 ; rc=$?; } || :
|
||||||
if (( rc != 0 )); then
|
if (( rc != 0 )); then
|
||||||
echo -n "ERROR: IP forwarding is disabled ($rc). Please add the following "
|
echo "ERROR: Please add the following docker setting to your container: --sysctl net.ipv4.ip_forward=1" && exit 24
|
||||||
echo "docker setting to your container: --sysctl net.ipv4.ip_forward=1" && exit 24
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue