summaryrefslogtreecommitdiffstats
path: root/os-plugins/plugins/qemukvm/files/qemu-ifup
blob: 6a25ad29274e010676114cb5ceb02d48cdce4ab4 (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
#!/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/
# -----------------------------------------------------------------------------
# qemu-ifup
#    - Script used for network setup of qemukvm in stage4
# -----------------------------------------------------------------------------

# Use the udhcpcd as DHCP server and brctl as provided by default in OpenSLX
# environments via uclibc-wrapper.

. /etc/opt/openslx/plugin-repo/qemukvm/network.qemukvm

# 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
  tap0)
    # Adding the tap0 interface to the existing bridge configured in stage3
    # brctl addif br0 tap0
  ;;
  tap1)
    # Configuring DHCP on host tap1 interface and enable IP masquerading
    [ -d /tmp/qemu-$USER ] || mkdir -p /tmp/qemu-$USER
    # cut the last .NNN/MM from nataddress
    sed -e "s,NWIF,tap1,;s,/misc/,/qemu/," \
        -e "s,CNETWORK,${nataddress%.*},;s,PIDFILE,/tmp/qemu-$USER/udhcpd.pid," \
        -e "s,LEASEFILE,/tmp/qemu-$USER/udhcpd.leases," \
      /etc/opt/openslx/plugin-repo/qemukvm/udhcpd.conf \
         >/tmp/qemu-$USER/udhcpd.conf
    touch /tmp/qemu-$USER/udhcpd.leases
    # ip link set tap1 up
    # ip addr add 192.168.101.254/24 dev tap1
    sudo /opt/openslx/uclib-rootfs/usr/sbin/udhcpd \
      -S /tmp/qemu-$USER/udhcpd.conf
    # iptables -t nat -A POSTROUTING -o br0 -j MASQUERADE
  ;;
  tap2)
    # Configuring DHCP on host tap2 interface
    [ -d /tmp/qemu-$USER ] || mkdir -p /tmp/qemu-$USER
    sed "s,NWIF,tap2,;s,/misc/,/qemu/,;s,USER,$USER,;s,CNETWORK,$hoaddress," \
      /etc/opt/openslx/udhcpd.qemukvm >/tmp/qemu-$USER/udhcpd.conf
    touch /tmp/qemu-$USER/udhcpd.leases
    # ip link set tap2 up
    # ip addr add 192.168.101.254/24 dev tap2
    sudo /opt/openslx/uclib-rootfs/usr/sbin/udhcpd \
      -S /tmp/qemu-$USER/udhcpd.conf
  ;;
esac

# Produce a clean exit status
exit 0