Contents of /tags/qemu-networking-2/qemu-networking.in
Parent Directory | Revision Log
Revision 1827 -
(show annotations)
(download)
Sat Jun 9 10:48:11 2012 UTC (12 years, 3 months ago) by niro
File size: 1469 byte(s)
Sat Jun 9 10:48:11 2012 UTC (12 years, 3 months ago) by niro
File size: 1469 byte(s)
tagged 'qemu-networking-2'
1 | #!/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 | if [ ! -x $(which iptables 2>/dev/null) ] |
18 | 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 | if [ ! -x $(which vde_switch 2>/dev/null) ] |
25 | 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 | if [ ! -x $(which sysctl 2>/dev/null) ] |
32 | 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 | # maquerade and forward |
58 | iptables -t nat -D POSTROUTING -s ${VMNETWORK} -o ${BRIDGEDEV} -j MASQUERADE |
59 | |
60 | # destroy interface |
61 | ifconfig ${TAPDEV} down |
62 | kill -15 $(< /var/run/vde-qemu.pid) |
63 | ;; |
64 | esac |