Magellan Linux

Annotation of /trunk/qemu-networking/qemu-networking.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2594 - (hide annotations) (download)
Tue Mar 4 10:12:48 2014 UTC (10 years, 2 months ago) by niro
File size: 1461 byte(s)
-better attempt to kill vde_switch
1 niro 1822 #!/bin/sh
2    
3     source @@confddir@@/qemu-networking
4    
5     checkconfig()
6     {
7     if [ -z "${VMNETWORK}" ] ||
8     [ -z "${VMROUTERIP}" ] ||
9     [ -z "${BRIDGEDEV}" ] ||
10     [ -z "${TAPDEV}" ]
11     then
12     logger -s -p daemon.err -t qemu-networking.service \
13     "Qemu Networking not set up, please edit /etc/conf.d/qemu-networking"
14     return 1
15     fi
16    
17 niro 2202 if [ ! -x $(type -P iptables) ]
18 niro 1822 then
19     logger -s -p daemon.err -t qemu-networking.service \
20     "No 'iptables' executable found, please install 'net-misc/iptables'"
21     return 1
22     fi
23    
24 niro 2202 if [ ! -x $(type -P vde_switch) ]
25 niro 1822 then
26     logger -s -p daemon.err -t qemu-networking.service \
27     "No 'vde_switch' executable found, please install 'net-misc/vde2'"
28     return 1
29     fi
30    
31 niro 2202 if [ ! -x $(type -P sysctl) ]
32 niro 1822 then
33     logger -s -p daemon.err -t qemu-networking.service \
34     "No 'sysctl' executable found, please install 'sys-apps/procps'"
35     return 1
36     fi
37    
38     return 0
39     }
40    
41     case $1 in
42     start)
43     checkconfig || exit 6
44    
45     # create interface
46     vde_switch -tap ${TAPDEV} -daemon -mod 660 -group kvm -p /var/run/vde-qemu.pid
47     ifconfig ${TAPDEV} ${VMROUTERIP} up
48    
49     # maquerade and forward
50     sysctl -q -w net.ipv4.ip_forward=1
51     iptables -t nat -A POSTROUTING -s ${VMNETWORK} -o ${BRIDGEDEV} -j MASQUERADE
52     ;;
53    
54     stop)
55     checkconfig || exit 6
56    
57 niro 2201 # masquerade and forward
58 niro 1822 iptables -t nat -D POSTROUTING -s ${VMNETWORK} -o ${BRIDGEDEV} -j MASQUERADE
59    
60     # destroy interface
61     ifconfig ${TAPDEV} down
62 niro 2594 pgrep -f vde_switch | xargs --no-run-if-empty kill -TERM
63 niro 1822 ;;
64     esac