chiark / gitweb /
Much work on packaging of xen stuff; not yet attempted a build
[autopkgtest.git] / xen / initscript
1 #!/bin/sh
2 set -e
3 . ${ADT_XENLVM_SHARE:=/usr/share/autopkgtest/xenlvm}/readconfig
4 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
5
6 default=/etc/default/adt-xen
7 if test -f $default; then
8   . $default
9 fi
10
11 chains='AdtXenIn AdtXenFwd AdtXenIcmp'
12
13 if ! type iptables >/dev/null 2>&1 || ! type xm >/dev/null 2>&1; then
14   exit 0
15 fi
16
17 safety () {
18   iptables -I INPUT -j DROP
19   iptables -I FORWARD -j DROP
20   trap '
21     for chain in $chains; do iptables -I $chain -j DROP; done
22     unsafety
23     exit 127
24   ' 0
25 }
26
27 unsafety () {
28   iptables -D INPUT -j DROP
29   iptables -D FORWARD -j DROP
30   trap '' 0
31 }
32
33 case "$1" in
34 stop)
35   safety
36   for chain in $chains; do
37     if iptables -L $chain >/dev/null 2>&1; then
38       iptables -F $chain
39       iptables -X $chain
40     fi
41   done
42   unsafety
43   exit 0
44   ;;
45 start|restart|force-reload)
46   ;;
47 '')
48   echo >&2 "usage: /etc/init.d/adt-xen stop|start|restart|force-reload"
49   exit 1
50   ;;
51 *)
52   echo >&2 "init.d/adt-xen unsupported action $1"
53   exit 1
54   ;;
55 esac
56
57 safety
58 for chain in $chains; do
59   iptables -N $chain >/dev/null 2>&1 || iptables -F $chain
60   iptables -I $chain -j DROP
61 done
62 unsafety
63
64 iptables -A AdtXenIcmp -j ACCEPT -p icmp --icmp-type echo-request
65 # per RFC1122, allow ICMP echo exchanges with anyone we can talk to at all
66
67 for oktype in                                   \
68         echo-reply                              \
69         destination-unreachable source-quench   \
70         time-exceeded parameter-problem         \
71 ;do
72   iptables -A AdtXenIcmp -j ACCEPT -m conntrack --ctstate ESTABLISHED \
73                 -p icmp --icmp-type  $oktype
74 done
75
76 main=AdtXenFwd
77
78 for i in $adt_fw_localmirrors; do
79   iptables -A $main -d $i -j ACCEPT -p tcp --dport 80
80   iptables -A $main -d $i -j AdtXenIcmp -p icmp
81 done
82
83 exec </etc/resolv.conf
84 while read command rest; do
85   if [ "x$command" = "xnameserver" ]; then
86     iptables -A $main -d $rest -j ACCEPT -p tcp --dport 53
87     iptables -A $main -d $rest -j ACCEPT -p udp --dport 53
88     iptables -A $main -d $rest -j AdtXenIcmp -p icmp
89   fi
90 done
91
92 for i in $adt_fw_testbedclients; do
93   iptables -A $main -d $i -j ACCEPT -p tcp ! --syn
94   iptables -A $main -d $i -j AdtXenIcmp -p icmp
95 done
96
97 for i in $adt_fw_prohibnets; do
98   iptables -A $main -d $i -j REJECT --reject-with icmp-net-prohibited
99 done
100
101 if [ x"$adt_fw_allowglobalports" != x ]; then
102   iptables -A $main -p icmp -j AdtXenIcmp
103 fi
104 for port in $adt_fw_allowglobalports; do
105   iptables -A $main -p tcp --dport $port -j ACCEPT
106 done
107
108 if test -f $default-rules; then
109   . $default-rules
110 fi
111
112 iptables -A $main -j REJECT --reject-with icmp-admin-prohibited
113 iptables -A $main -j ACCEPT
114 iptables -D $main -j DROP
115
116 iptables -A AdtXenIn -j ACCEPT -p icmp --icmp-type echo-request
117 iptables -A AdtXenIn -j ACCEPT -m conntrack --ctstate ESTABLISHED
118 iptables -A AdtXenIn -j AdtXenFwd
119 iptables -D AdtXenIn -j DROP
120
121 echo 1 >/proc/sys/net/ipv4/conf/eth0/proxy_arp