summaryrefslogtreecommitdiffstats
path: root/os-plugins/plugins/qemukvm/files/qemu-ifup
blob: 6f75913540e6c1bdb09cc48b6f656776b38697fa (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
#!/bin/sh
# Copyright (c) 2009 - 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.
brctlcmd="LD_LIBRARY_PATH=/opt/openslx/uclib-rootfs/lib\
          /opt/openslx/uclib-rootfs/usr/sbin/brctl"
dhcpdcmd="LD_LIBRARY_PATH=/opt/openslx/uclib-rootfs/lib\
          /opt/openslx/uclib-rootfs/usr/sbin/udhcpd"

# 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
    eval ${brctlcmd} addif br0 tap0
  ;;
  tap1)
    # Configuring DHCP on host tap1 interface and enable IP masquerading
    mkdir /var/lib/qemu
    sed "s,NWIF,tap1,;s,/misc/,/qemu/," /etc/opt/openslx/udhcpd.qemukvm \
      >/var/lib/qemu/udhcpd.conf
    eval ${dhcpdcmd} /var/lib/qemu/udhcpd.conf
    echo "1" >/proc/sys/net/ipv4/conf/br0/forwarding
    echo "1" >/proc/sys/net/ipv4/conf/tap1/forwarding
    iptables -t nat -A POSTROUTING -o br0 -j MASQUERADE
  ;;
  tap2)
    :
  ;;
esac

# Produce a clean exit status
exit 0