]> git.pld-linux.org Git - packages/iptables.git/blob - ip6tables.init
- removed outdated notes and patches:
[packages/iptables.git] / ip6tables.init
1 #!/bin/sh
2 #
3 # Startup script to implement /etc/sysconfig/ip6tables pre-defined rules.
4 #
5 # chkconfig: 2345 08 92
6 #
7 # description: Automates a packet filtering firewall with ip6tables.
8 #
9 # by bero@redhat.com, based on the ipchains script:
10 # Script Author:        Joshua Jensen <joshua@redhat.com>
11 #   -- hacked up by gafton with help from notting
12 # modified by Anton Altaparmakov <aia21@cam.ac.uk>:
13 # modified by Nils Philippsen <nils@redhat.de>
14 #
15 # config: /etc/sysconfig/ip6tables
16
17 IPTABLES_CONFIG=/etc/sysconfig/ip6tables
18
19 if [ ! -f $IPTABLES_CONFIG ]; then
20         case "$1" in
21         start|restart|force-reload)
22                 exit 0
23                 ;;
24         esac
25 fi
26
27 # Source 'em up
28 . /etc/rc.d/init.d/functions
29
30 if [ "$(kernelver)" -lt "002003000" ]; then
31         exit 0
32 fi
33
34 if /sbin/lsmod 2>/dev/null | grep -q ipchains; then
35         # Don't do both
36         exit 0
37 fi
38
39 iftable() {
40         if fgrep -qsx $1 /proc/net/ip6_tables_names; then
41                 ip6tables -t "$@"
42         fi
43 }
44
45 start() {
46         # don't do squat if we don't have the config file
47         if [ -f $IPTABLES_CONFIG ]; then
48                 # If we don't clear these first, we might be adding to
49                 #  pre-existing rules.
50                 tables=`cat /proc/net/ip6_tables_names 2>/dev/null`
51                 show "Flushing all current rules and user defined chains"
52                 let ret=0
53                 for i in $tables; do ip6tables -t $i -F; let ret+=$?; done
54                 if [ $ret -eq 0 ]; then
55                         ok
56                 else
57                         fail
58                 fi
59                 show "Clearing all current rules and user defined chains"
60                 let ret=0
61                 for i in $tables; do ip6tables -t $i -X; let ret+=$?; done
62                 if [ $ret -eq 0 ]; then
63                         ok
64                 else
65                         fail
66                 fi
67
68                 for i in $tables; do ip6tables -t $i -Z; done
69
70                 show "Applying ip6tables firewall rules"
71                 grep -v "^[[:space:]]*#" $IPTABLES_CONFIG | grep -v '^[[:space:]]*$' | /usr/sbin/ip6tables-restore -c && \
72                         ok || fail
73                 touch /var/lock/subsys/ip6tables
74         fi
75 }
76
77 stop() {
78         tables=`cat /proc/net/ip6_tables_names 2>/dev/null`
79         show "Flushing all chains"
80         let ret=0
81         for i in $tables; do ip6tables -t $i -F; let ret+=$?; done
82         if [ $ret -eq 0 ]; then
83                 ok
84         else
85                 fail
86         fi
87
88         show "Removing user defined chains"
89         let ret=0
90         for i in $tables; do ip6tables -t $i -X; let ret+=$?; done
91         if [ $ret -eq 0 ]; then
92                 ok
93         else
94                 fail
95         fi
96         show "Resetting built-in chains to the default ACCEPT policy"
97         iftable filter -P INPUT ACCEPT && \
98         iftable filter -P OUTPUT ACCEPT && \
99         iftable filter -P FORWARD ACCEPT && \
100         iftable nat -P PREROUTING ACCEPT && \
101         iftable nat -P POSTROUTING ACCEPT && \
102         iftable nat -P OUTPUT ACCEPT && \
103         iftable mangle -P PREROUTING ACCEPT && \
104         iftable mangle -P OUTPUT ACCEPT && \
105         ok || fail
106         rm -f /var/lock/subsys/ip6tables
107 }
108
109 case "$1" in
110   start|load)
111         start
112         ;;
113
114   stop|clear)
115         stop
116         ;;
117
118   restart|force-reload)
119         # "restart" is really just "start" as this isn't a daemon,
120         #  and "start" clears any pre-defined rules anyway.
121         #  This is really only here to make those who expect it happy
122         start
123         ;;
124
125   panic)
126         show "Changing target policies to DROP"
127         iftable filter -P INPUT DROP && \
128         iftable filter -P FORWARD DROP && \
129         iftable filter -P OUTPUT DROP && \
130         iftable nat -P PREROUTING DROP && \
131         iftable nat -P POSTROUTING DROP && \
132         iftable nat -P OUTPUT DROP && \
133         iftable mangle -P PREROUTING DROP && \
134         iftable mangle -P OUTPUT DROP && \
135         ok || fail
136         iftable filter -F INPUT && \
137         iftable filter -F FORWARD && \
138         iftable filter -F OUTPUT && \
139         iftable nat -F PREROUTING && \
140         iftable nat -F POSTROUTING && \
141         iftable nat -F OUTPUT && \
142         iftable mangle -F PREROUTING && \
143         iftable mangle -F OUTPUT && \
144         ok || fail
145         iftable filter -X INPUT && \
146         iftable filter -X FORWARD && \
147         iftable filter -X OUTPUT && \
148         iftable nat -X PREROUTING && \
149         iftable nat -X POSTROUTING && \
150         iftable nat -X OUTPUT && \
151         iftable mangle -X PREROUTING && \
152         iftable mangle -X OUTPUT && \
153         ok || fail
154         ;;
155
156   save)
157         show "Saving current rules to %s" $IPTABLES_CONFIG
158         touch $IPTABLES_CONFIG
159         chmod 600 $IPTABLES_CONFIG
160         /usr/sbin/ip6tables-save -c > $IPTABLES_CONFIG  2>/dev/null && ok || fail
161         ;;
162
163   status)
164         tables=`cat /proc/net/ip6_tables_names 2>/dev/null`
165         for table in $tables; do
166                 echo "Table: $table"
167                 ip6tables -t $table -n --list
168         done
169         ;;
170
171   *)
172         msg_usage "$0 {start|stop|restart|force-reload|panic|load|save|clear|status}"
173         exit 3
174 esac
175
176 exit 0
This page took 0.036396 seconds and 3 git commands to generate.