summaryrefslogtreecommitdiffstats
path: root/core/modules
diff options
context:
space:
mode:
authorSimon Rettberg2017-11-24 14:36:46 +0100
committerSimon Rettberg2017-11-24 14:36:46 +0100
commitd919efe86f80879848e1a43007680d3c92d7c40b (patch)
treed07d80fc2ef396e1605517be8408501e7152ff2b /core/modules
parent[vmware*] Set up additional bridged vmnets if SLX_BRIDGE_OTHER_NICS is set (diff)
downloadmltk-d919efe86f80879848e1a43007680d3c92d7c40b.tar.gz
mltk-d919efe86f80879848e1a43007680d3c92d7c40b.tar.xz
mltk-d919efe86f80879848e1a43007680d3c92d7c40b.zip
[vmware*/run-virt] Implement NIC bridging
Implements #3109
Diffstat (limited to 'core/modules')
-rw-r--r--core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/set_runvirt_hardware_variables.inc15
-rwxr-xr-xcore/modules/vmware/data/opt/openslx/scripts/systemd-vmware_env5
-rw-r--r--core/modules/vmware/data/opt/openslx/vmchooser/plugins/vmware/includes/write_final_vmx.inc32
-rwxr-xr-xcore/modules/vmware12/data/opt/openslx/scripts/systemd-vmware_env5
-rw-r--r--core/modules/vmware12/data/opt/openslx/vmchooser/plugins/vmware/includes/write_final_vmx.inc32
5 files changed, 85 insertions, 4 deletions
diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/set_runvirt_hardware_variables.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/set_runvirt_hardware_variables.inc
index 48a5cf3c..04f3b22e 100644
--- a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/set_runvirt_hardware_variables.inc
+++ b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/set_runvirt_hardware_variables.inc
@@ -69,6 +69,7 @@ set_virt_memory() {
# Suffix template is taken from /opt/openslx/vmchooser/config/virtualization.conf
# and will have the VMID inserted as first byte.
set_virt_mac() {
+ local i mac byte
# First, determine prefix of the host's MAC address
isset HOSTMACADDR || writelog "Host's MAC address was not defined in ${VMCHOOSER_CONF_DIR}/virtualizer.conf"
isset MACADDRPREFIX || writelog "No MAC address prefix was defined in ${VMCHOOSER_CONF_DIR}/virtualizer.conf"
@@ -83,6 +84,20 @@ set_virt_mac() {
slxlog "virt-mac" "Could not properly generate mac address suffix (got $MACADDRSUFFIX)"
fi
declare -g VM_MAC_ADDR="$MACADDRPREFIX:$MACADDRSUFFIX"
+ declare -g OTHER_NICS=
+ # Set up additional NICs if enabled
+ if [ "$SLX_BRIDGE_OTHER_NICS" = "yes" ]; then
+ for i in /sys/class/net/br-nic-*/address; do
+ [ -s "$i" ] || continue
+ mac=$(tr '[a-f]' '[A-F]' < "$i")
+ # Calc checksum of mac by summing the bytes mod 256
+ byte=$(( $(<<<$mac sed 's/^/ ( 0x/;s/:/ + 0x/g;s/$/ ) % 256/') ))
+ byte=$(printf "%02X" "$byte")
+ # (PR:EF:IX):LA:ST:CH - use general prefix for VMs, then last two octets of source mac, plus the checksum
+ mac="${MACADDRPREFIX}:${mac:12:5}:${byte}"
+ OTHER_NICS+=" $mac"
+ done
+ fi
}
# Virtual fd/cd/dvd and drive devices, floppy b: for configuration
diff --git a/core/modules/vmware/data/opt/openslx/scripts/systemd-vmware_env b/core/modules/vmware/data/opt/openslx/scripts/systemd-vmware_env
index 0c0e5966..4e381bf0 100755
--- a/core/modules/vmware/data/opt/openslx/scripts/systemd-vmware_env
+++ b/core/modules/vmware/data/opt/openslx/scripts/systemd-vmware_env
@@ -67,18 +67,19 @@ vmnetif () {
brctl addif vsw2 vmnet2
# 2) see if we should bridge additional interfaces
NICS=
- if [ "$SLX_BRIDGE_OTHER_NICS" = "ON" ]; then
+ if [ "$SLX_BRIDGE_OTHER_NICS" = "yes" ]; then
# These will have been set up in our init
NICS=$( ls -1 /sys/class/net | grep '^br-nic-' | cut -c 8- )
+ vmnet=10
for nic in $NICS; do
if ! [ "$nic" -gt 0 ] && ! [ "$nic" -eq 0 ]; then
slxlog "vmware-other-nics" "NaN: br-nic-X has X='$nic'"
continue
fi
# create vmnet10 - vmnetN for these
- vmnet="$(( nic + 10 ))"
vmnet_create "$vmnet"
brctl addif "br-nic-${nic}" "vmnet${vmnet}"
+ vmnet="$(( vmnet + 1 ))"
done
fi
diff --git a/core/modules/vmware/data/opt/openslx/vmchooser/plugins/vmware/includes/write_final_vmx.inc b/core/modules/vmware/data/opt/openslx/vmchooser/plugins/vmware/includes/write_final_vmx.inc
index a431560f..8bc6cb3d 100644
--- a/core/modules/vmware/data/opt/openslx/vmchooser/plugins/vmware/includes/write_final_vmx.inc
+++ b/core/modules/vmware/data/opt/openslx/vmchooser/plugins/vmware/includes/write_final_vmx.inc
@@ -22,6 +22,38 @@ replace_placeholders() {
setup_ethernet() {
echo 'ethernet0.addressType = "static"' >> "${TMPCONFIG}"
echo 'ethernet0.address = "'"${VM_MAC_ADDR}"'"' >> "${TMPCONFIG}"
+ if [ -n "$OTHER_NICS" ]; then
+ local devtype mac cnt eth
+ # Copy type of eth0, in case the others don't specify a type in the vmx, we'll use the same
+ # so we know the drivers are there
+ devtype=$(grep -m1 -i '^ethernet0\.virtualDev' | sed -r 's/^[^=]+//;s/^(\s|=|")*//;s/(\s|")+$//') # TODO: Make a helper like "getVmxOption"
+ cnt=0
+ for mac in $OTHER_NICS; do
+ vmnet=$(( cnt + 10 ))
+ cnt=$(( cnt + 1 ))
+ eth="ethernet${cnt}"
+ # Check device exists
+ if ! [ -c "/dev/vmnet${vmnet}" ]; then
+ slxlog "vmware-bridge-setup" "Cannot bridge NIC into VM: /dev/vmnet${vmnet} does not exist"
+ continue
+ fi
+ # Remove lines that could break things
+ sed -i "/^${eth}\.connectionType/Id;/^${eth}\.present/Id" "${TMPCONFIG}"
+ # Set up devType
+ devline=
+ if ! grep -q -i "^${eth}\.virtualDev" "${TMPCONFIG}" && [ -n "$devtype" ]; then
+ devline="${eth}.virtualDev = "'"'"${devtype}"'"'
+ fi
+ cat >> "${TMPCONFIG}" <<-HEND
+ ${eth}.connectionType = "custom"
+ ${eth}.present = "TRUE"
+ ${eth}.vnet = "vmnet${vmnet}"
+ ${eth}.addressType = "static"
+ ${eth}.address = "${mac}"
+ ${devline}
+ HEND
+ done
+ fi
}
# DVD, CDROM
diff --git a/core/modules/vmware12/data/opt/openslx/scripts/systemd-vmware_env b/core/modules/vmware12/data/opt/openslx/scripts/systemd-vmware_env
index 0c0e5966..4e381bf0 100755
--- a/core/modules/vmware12/data/opt/openslx/scripts/systemd-vmware_env
+++ b/core/modules/vmware12/data/opt/openslx/scripts/systemd-vmware_env
@@ -67,18 +67,19 @@ vmnetif () {
brctl addif vsw2 vmnet2
# 2) see if we should bridge additional interfaces
NICS=
- if [ "$SLX_BRIDGE_OTHER_NICS" = "ON" ]; then
+ if [ "$SLX_BRIDGE_OTHER_NICS" = "yes" ]; then
# These will have been set up in our init
NICS=$( ls -1 /sys/class/net | grep '^br-nic-' | cut -c 8- )
+ vmnet=10
for nic in $NICS; do
if ! [ "$nic" -gt 0 ] && ! [ "$nic" -eq 0 ]; then
slxlog "vmware-other-nics" "NaN: br-nic-X has X='$nic'"
continue
fi
# create vmnet10 - vmnetN for these
- vmnet="$(( nic + 10 ))"
vmnet_create "$vmnet"
brctl addif "br-nic-${nic}" "vmnet${vmnet}"
+ vmnet="$(( vmnet + 1 ))"
done
fi
diff --git a/core/modules/vmware12/data/opt/openslx/vmchooser/plugins/vmware/includes/write_final_vmx.inc b/core/modules/vmware12/data/opt/openslx/vmchooser/plugins/vmware/includes/write_final_vmx.inc
index a431560f..8bc6cb3d 100644
--- a/core/modules/vmware12/data/opt/openslx/vmchooser/plugins/vmware/includes/write_final_vmx.inc
+++ b/core/modules/vmware12/data/opt/openslx/vmchooser/plugins/vmware/includes/write_final_vmx.inc
@@ -22,6 +22,38 @@ replace_placeholders() {
setup_ethernet() {
echo 'ethernet0.addressType = "static"' >> "${TMPCONFIG}"
echo 'ethernet0.address = "'"${VM_MAC_ADDR}"'"' >> "${TMPCONFIG}"
+ if [ -n "$OTHER_NICS" ]; then
+ local devtype mac cnt eth
+ # Copy type of eth0, in case the others don't specify a type in the vmx, we'll use the same
+ # so we know the drivers are there
+ devtype=$(grep -m1 -i '^ethernet0\.virtualDev' | sed -r 's/^[^=]+//;s/^(\s|=|")*//;s/(\s|")+$//') # TODO: Make a helper like "getVmxOption"
+ cnt=0
+ for mac in $OTHER_NICS; do
+ vmnet=$(( cnt + 10 ))
+ cnt=$(( cnt + 1 ))
+ eth="ethernet${cnt}"
+ # Check device exists
+ if ! [ -c "/dev/vmnet${vmnet}" ]; then
+ slxlog "vmware-bridge-setup" "Cannot bridge NIC into VM: /dev/vmnet${vmnet} does not exist"
+ continue
+ fi
+ # Remove lines that could break things
+ sed -i "/^${eth}\.connectionType/Id;/^${eth}\.present/Id" "${TMPCONFIG}"
+ # Set up devType
+ devline=
+ if ! grep -q -i "^${eth}\.virtualDev" "${TMPCONFIG}" && [ -n "$devtype" ]; then
+ devline="${eth}.virtualDev = "'"'"${devtype}"'"'
+ fi
+ cat >> "${TMPCONFIG}" <<-HEND
+ ${eth}.connectionType = "custom"
+ ${eth}.present = "TRUE"
+ ${eth}.vnet = "vmnet${vmnet}"
+ ${eth}.addressType = "static"
+ ${eth}.address = "${mac}"
+ ${devline}
+ HEND
+ done
+ fi
}
# DVD, CDROM