summaryrefslogtreecommitdiffstats
path: root/src/os-plugins/plugins/qemukvm/files/ifup
blob: d061fe0b7abf215d0307b578f3ddc8444bd6f935 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/sh
# Copyright (c) 2009..2010 - 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/
# -----------------------------------------------------------------------------
# ifup
#    - Script used for network setup of qemukvm in stage4
# -----------------------------------------------------------------------------

. /etc/opt/openslx/openslx.conf

PLUGINCONFDIR=${OPENSLX_DEFAULT_CONFDIR}/plugins/qemukvm

# get VM_ID through tap name
VM_ID=$(echo $1 | grep -oE "0[0-4]$")
QKTMPDIR=/tmp/qemukvm/${USER}/${VM_ID}

# Use the udhcpcd as DHCP server and brctl as provided by default in OpenSLX
# environments.
. ${PLUGINCONFDIR}/network.conf

# Just decide by the virtual network device used which kind of connection
# should be set up (passed in $1): tap0 = bridge, tap1 = nat, tap2 = hostonly.
case "$1" in
  tapbridge0*)
    sudo /opt/openslx/rootfs/bin/ip link set dev $1 up
    # TODO: forwarding?, where needed
    echo "1" >${QKTMPDIR}/forwarding
    sudo /sbin/sysctl -q -w net.ipv4.conf.br0.forwarding=1
    sudo /sbin/sysctl -q -w net.ipv4.conf.$1.forwarding=1
  ;;
  tapnat0*)
    # Configuring DHCP on host tapnat interface and enable IP masquerading
    # Fixme: Addressing sudo /opt/openslx/rootfs/bin/ip addr add ${nataddress} dev $1
    sudo /opt/openslx/rootfs/bin/ip addr add 192.168.1${VM_ID}.1/24 dev $1
    sudo /opt/openslx/rootfs/bin/ip link set dev $1 up
    # TODO: forwarding?, where needed
    sudo /sbin/sysctl -q -w net.ipv4.conf.br0.forwarding=1
    sudo /sbin/sysctl -q -w net.ipv4.conf.$1.forwarding=1
    # TODO: we use here static address, maybe change later
    sed -e "s,NWIF,$1,;s,CNETWORK,192.168.1${VM_ID}," \
        -e "s,PIDFILE,${QKTMPDIR}/udhcpd.pid," \
        -e "s,LEASEFILE,${QKTMPDIR}/udhcpd.leases," \
           ${OPENSLX_DEFAULT_CONFDIR}/udhcpd.conf \
      >${QKTMPDIR}/udhcpd.conf
    touch ${QKTMPDIR}/udhcpd.leases
    sudo /opt/openslx/rootfs/usr/sbin/udhcpd \
      -S ${QKTMPDIR}/udhcpd.conf
    sudo /sbin/iptables -t nat -A POSTROUTING -s 192.168.1${VM_ID}.0/24 -o br0 -j MASQUERADE
  ;;
  taphost0*)
    # Configuring DHCP on host taphost interface
    # Fixme: sudo /opt/openslx/rootfs/bin/ip addr add ${hoaddress} dev $1
    sudo /opt/openslx/rootfs/bin/ip addr add 192.168.1${VM_ID}.1/24 dev $1
    sudo /opt/openslx/rootfs/bin/ip link set dev $1 up
    sed -e "s,NWIF,$1,;s,USER,${USER},;s,CNETWORK,192.168.1${VM_ID}," \
        -e "s,PIDFILE,${QKTMPDIR}/udhcpd.pid," \
        -e "s,LEASEFILE,${QKTMPDIR}/udhcpd.leases," \
      ${OPENSLX_DEFAULT_CONFDIR}/udhcpd.conf >${QKTMPDIR}/udhcpd.conf
    touch ${QKTMPDIR}/udhcpd.leases
    sudo /opt/openslx/rootfs/usr/sbin/udhcpd \
      -S ${QKTMPDIR}/udhcpd.conf
  ;;
esac

exit 0