From efd86cc8b5b138e4076bf1657ea888dc52e62901 Mon Sep 17 00:00:00 2001 From: Dirk Date: Fri, 13 Dec 2013 20:52:00 +0100 Subject: Heavily reworked the networking for the various virtual machines: There will be three types of network interfaces for virtual machines available all will be configured for every type of virtualization tool a) br0 is the direct host bridge into the local LAN (br0 already exists) vmnet0 for VMware vboxnet0 for VirtualBox kvmnet0* for Qemu/KVM b) nat1 is an internal bridge which "NATes" into the local LAN (with DHCP) vmnet1 for VMware vboxnet1 for VirtualBox kvmnet1* for Qemu/KVM c) vsw2 is an internal host bridge to connect software defined LANs to vmnet2 for VMware vboxnet2 for VirtualBox kvmnet2* for Qemu/KVM --- .../data/opt/openslx/scripts/systemd-vmchooser_env | 52 +++++++++++++++++++-- .../data/opt/openslx/scripts/vmchooser-run_virt | 10 +++- .../data/opt/openslx/vmchooser/config/smb.conf | 21 +++++++-- .../opt/openslx/vmchooser/config/udhcpd-nat1.conf | 54 ++++++++++++++++++++++ .../data/opt/openslx/vmchooser/config/udhcpd.conf | 52 --------------------- 5 files changed, 129 insertions(+), 60 deletions(-) create mode 100644 remote/modules/vmchooser/data/opt/openslx/vmchooser/config/udhcpd-nat1.conf delete mode 100644 remote/modules/vmchooser/data/opt/openslx/vmchooser/config/udhcpd.conf (limited to 'remote/modules/vmchooser/data') diff --git a/remote/modules/vmchooser/data/opt/openslx/scripts/systemd-vmchooser_env b/remote/modules/vmchooser/data/opt/openslx/scripts/systemd-vmchooser_env index c796b3db..913d9de6 100755 --- a/remote/modules/vmchooser/data/opt/openslx/scripts/systemd-vmchooser_env +++ b/remote/modules/vmchooser/data/opt/openslx/scripts/systemd-vmchooser_env @@ -36,7 +36,7 @@ mkdir -p "${VMCHOOSER_DIR}/fd-loop" -m 1777 grep -qE "unionfs |aufs " /proc/mounts && \ mount -n -o size=1500k -t tmpfs vm-loopimg "${VMCHOOSER_DIR}/data/loopimg" -# create an empty floppy image of 1.4MByte size +# create an empty floppy image of 1.44 MByte size dd "if=/dev/zero" "of=${VMCHOOSER_DIR}/data/loopimg/fd.img" count=2880 bs=512 2>/dev/null chmod 0777 "${VMCHOOSER_DIR}/data/loopimg/fd.img" @@ -51,8 +51,7 @@ mount -n -t msdos -o loop,umask=000 "${VMCHOOSER_DIR}/data/loopimg/fd.img" "${VM #fi # setup more scratch space for virtual machines, if configured -mkdir -p /tmp/virt -mkdir -p /var/log/samba +mkdir -p /tmp/virt /var/log/samba /run/samba # enable normal users to setup the extended virtual machine redo file space # and image source via network block device (NBD only at the moment) @@ -131,3 +130,50 @@ for floppy in $(dmesg|grep -i "Floppy drive"|sed "s,.*(s): ,,;s, is .*,,"); do j=$(expr $j + 1) done +################################################################################ +### Setup VM networking +################################################################################ + +# there will be three types of network interfaces for virtual machines available +# all will be configured for every type of virtualization tool +# a) br0 is the direct host bridge into the local LAN (br0 already exists) +# vmnet0 for VMware +# vboxnet0 for VirtualBox +# kvmnet0* for Qemu/KVM +# b) nat1 is an internal bridge which "NATes" into the local LAN (with DHCP) +# vmnet1 for VMware +# vboxnet1 for VirtualBox +# kvmnet1* for Qemu/KVM +# c) vsw2 is an internal host bridge to connect software defined LANs to +# vmnet2 for VMware +# vboxnet2 for VirtualBox +# kvmnet2* for Qemu/KVM + +# creating and configuring nat0 +brctl addbr nat1 +ip link set dev nat1 up +ip addr add 192.168.101.1/24 dev nat1 +echo "1" >/proc/sys/net/ipv4/conf/nat1/forwarding +echo "1" >/proc/sys/net/ipv4/conf/br0/forwarding 2>/dev/null +iptables -t nat -A POSTROUTING -o br0 -j MASQUERADE + +for wait in 1 1 2 2 3 end; do + grep '^SLX_DNS' "/opt/openslx/config" > /dev/null && break + [ "$wait" == "end" ] && echo "No DNS config found, using google dns" && break + echo "Waiting for DNS config.." + sleep "$wait" +done + +# read the DNS configuration and configure the udhcpd +[ -z "${SLX_DNS}" ] && SLX_DNS="8.8.8.8" +sed -i "s,DNSSERVER,${SLX_DNS},;s,DOMAIN,${SLX_NET_DOMAIN}," \ + /opt/openslx/vmchooser/config/udhcpd-nat1.conf + +mkdir -p /var/lib/udhcpd +udhcpd -S /opt/openslx/vmchooser/config/udhcpd-nat1.conf + +# creating and configuring vsw2 +brctl addbr vsw2 +ip link set dev vsw2 up +echo "1" >/proc/sys/net/ipv4/conf/vsw2/forwarding + diff --git a/remote/modules/vmchooser/data/opt/openslx/scripts/vmchooser-run_virt b/remote/modules/vmchooser/data/opt/openslx/scripts/vmchooser-run_virt index 2d6dfb41..bef43dd1 100755 --- a/remote/modules/vmchooser/data/opt/openslx/scripts/vmchooser-run_virt +++ b/remote/modules/vmchooser/data/opt/openslx/scripts/vmchooser-run_virt @@ -439,7 +439,8 @@ SPOOLDIR="/var/spool" QUEUE="STANDARD" # Start the lpdaemon listening on the given port -tcpsvd -E 0.0.0.0 5515 \ +# FixMe: Solution for general printer redirection in other cases (iptables on outgoing port) +tcpsvd -E 192.168.101.1 5515 \ lpd "$SPOOLDIR" \ sh -c "printergui $USER $SPOOLDIR/$QUEUE/\$DATAFILE" & @@ -542,6 +543,13 @@ if ! kill -0 "$PID_LPD"; then slxlog "virt-lpd" "Could not start tcpsvd/lpd for virtual machine session" fi +# Configure and start samba service to provide user's home directory +#if [ -f /usr/sbin/smbd ] ; then +# sudo /opt/openslx/bin/sed -i /opt/openslx/vmchooser/smb.conf -e "s,USER,$USER," +# sudo /usr/sbin/nmbd -s /opt/openslx/vmchooser/config/smb.conf +# sudo /usr/sbin/smbd -s /opt/openslx/vmchooser/config/smb.conf +#fi + # This will start the VM eval ${VIRTCMD} ${VIRTCMDOPTS} # diff --git a/remote/modules/vmchooser/data/opt/openslx/vmchooser/config/smb.conf b/remote/modules/vmchooser/data/opt/openslx/vmchooser/config/smb.conf index ec757ce4..d8966f71 100644 --- a/remote/modules/vmchooser/data/opt/openslx/vmchooser/config/smb.conf +++ b/remote/modules/vmchooser/data/opt/openslx/vmchooser/config/smb.conf @@ -1,16 +1,29 @@ -# basic samba configuration file for OpenSLX host-internal networking +# ----------------------------------------------------------------------------- +# Copyright (c) 2009..2013 - OpenSLX GmbH +# +# This program/file is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your feedback to feedback@openslx.org +# +# General information about OpenSLX can be found at http://openslx.org +# ----------------------------------------------------------------------------- +# smb.conf +# - basic samba configuration file for OpenSLX host-internal networking +################################################################################ [global] workgroup = OPENSLX netbios name = HOMESERVER security = SHARE server string = Home and Print Provider bind interfaces only = Yes - interfaces = NWIF - pid directory = PIDDIR + interfaces = nat1 + pid directory = /run/samba [userhome] comment = Home Directory of USER - path = /home/USER + path = /home/USER/PERSISTENT create mask = 0700 guest ok = No read only = No diff --git a/remote/modules/vmchooser/data/opt/openslx/vmchooser/config/udhcpd-nat1.conf b/remote/modules/vmchooser/data/opt/openslx/vmchooser/config/udhcpd-nat1.conf new file mode 100644 index 00000000..ee862e79 --- /dev/null +++ b/remote/modules/vmchooser/data/opt/openslx/vmchooser/config/udhcpd-nat1.conf @@ -0,0 +1,54 @@ +# Copyright (c) 2013 - OpenSLX GmbH +# +# This program is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your suggestions, praise, or complaints to feedback@openslx.org +# +# General information about OpenSLX can be found at http://openslx.org/ +# ----------------------------------------------------------------------------- +# udhcpd.conf +# - This is the udhcpd configuration file servicing the nat1 interface for +# the various virtualization services. DNSSERVER and DOMAIN are replaced +# before deamon start in systemd script. +################################################################################ + +# start and end of the IP lease block +start 192.168.101.20 +end 192.168.101.100 +max_leases 80 + +# interface that udhcpd will use +interface nat1 + +# how long an offered address is reserved (leased) in seconds +offer_time 6000 + +# location of the leases file +lease_file /var/lib/udhcpd/udhcpd-nat1.leases + +# location of the pid file +pidfile /var/run/udhcpd-nat1.pid + +option dns DNSSERVER +option subnet 255.255.255.0 +option router 192.168.101.1 +option wins 192.168.101.10 +option domain DOMAIN virtual.site +option lprsvr 192.168.101.1 +#option ntpsrv NTPSERVER + +# additional options known to udhcpd not used in OpenSLX at the moment +#subnet #timezone +#router #timesvr +#namesvr #dns +#logsvr #cookiesvr +#lprsvr #bootsize +#domain #swapsvr +#rootpath #ipttl +#mtu #broadcast +#wins #lease +#ntpsrv #tftp +#bootfile #wpad + diff --git a/remote/modules/vmchooser/data/opt/openslx/vmchooser/config/udhcpd.conf b/remote/modules/vmchooser/data/opt/openslx/vmchooser/config/udhcpd.conf deleted file mode 100644 index eb510098..00000000 --- a/remote/modules/vmchooser/data/opt/openslx/vmchooser/config/udhcpd.conf +++ /dev/null @@ -1,52 +0,0 @@ -# Copyright (c) 2013 - OpenSLX GmbH -# -# This program is free software distributed under the GPL version 2. -# See http://openslx.org/COPYING -# -# If you have any feedback please consult http://openslx.org/feedback and -# send your suggestions, praise, or complaints to feedback@openslx.org -# -# General information about OpenSLX can be found at http://openslx.org/ -# ----------------------------------------------------------------------------- -# udhcpd.conf -# - This is the udhcpd configuration file servicing the nat1 interface for -# the various virtualization services. DNSSERVER and DOMAIN are replaced -# before deamon start in systemd script. -################################################################################ - -# start and end of the IP lease block -start 192.168.101.20 -end 192.168.101.100 - -# interface that udhcpd will use -interface nat1 - -# how long an offered address is reserved (leased) in seconds -offer_time 6000 - -# location of the leases file -lease_file /var/lib/udhcpd/udhcpd-nat1.leases - -# location of the pid file -pidfile /var/run/udhcpd-nat1.pid - -option dns DNSSERVER -option subnet 255.255.255.0 -option router 192.168.101.1 -option wins 192.168.101.10 -option domain DOMAIN virtual.site - - -# additional options known to udhcpd not used in OpenSLX at the moment -#subnet #timezone -#router #timesvr -#namesvr #dns -#logsvr #cookiesvr -#lprsvr #bootsize -#domain #swapsvr -#rootpath #ipttl -#mtu #broadcast -#wins #lease -#ntpsrv #tftp -#bootfile #wpad - -- cgit v1.2.3-55-g7522