summaryrefslogtreecommitdiff
path: root/network/vde2/rc.vde2
blob: 9cc1beceb06363229f93aa75b7fb49930d143827 (plain)
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
73
74
#!/bin/sh

#=========================== EDIT THE FOLLOWING VARIABLES ==========================
#  _________________________________________________________________________________
# |                                                                                 |
# | Interface name to use for the TAP device					    |
# |                                                                                 |
    TAP_IF="tap0"
# |_________________________________________________________________________________|
# |                                                                                 |
# | IP Address/Subnet in CIDR Notation for the Virtual Network			    |
# |                                                                                 |
    TAP_NET="10.10.10.1/24" 
# |_________________________________________________________________________________|
#
#=========================== DO NOT EDIT BELOW THIS LINE ============================

start(){
   echo -n "Starting VDE Switch..."

   # Load tun module
   modprobe tun || { echo "Error, cannot load 'tun' module. Exiting..." ; exit 1 ; } 
   sleep 1

   # Start tap switch
   vde_switch -tap ${TAP_IF} -daemon || { echo "Error, cannot assign IP to ${TAP_IF}. Exiting..." ; exit 1 ; }

   # Bring tap interface up
   ip addr add ${TAP_NET} dev ${TAP_IF} 
   ip link set ${TAP_IF} up
   
   #chmod 666 /tmp/vde.ctl
   chmod -R a+rwx /var/run/vde.ctl

   # Apply workaround
   echo 1024 > /proc/sys/dev/rtc/max-user-freq
   echo
}


stop(){
   echo -n "Stopping VDE Switch..."

      # Bring tap interface down
      ip addr flush dev ${TAP_IF}
      ip link set ${TAP_IF} down

      # Kill VDE switch
      kill $(pgrep vde_switch)
      sleep 1

      # Remove tun module
      modprobe -r tun
      echo
}


case "$1" in
   start)
	   start
	   ;;

   stop)
	   stop
	   ;;

   restart)
	   stop
	   start
	   ;;
   *)
	   echo "Usage: $0 {start|stop|restart}"
	   ;;
esac