and added files
[bcm963xx.git] / userapps / opensource / reaim / firewall.sh
1 #!/bin/sh
2 #
3 # Project: ReAim
4 #
5 # Release : 0.8 pre
6 #
7 # Homepage:  http://reaim.sourceforge.net/
8 #
9 # Copyright: Mark Cooke, March 2002.  All Rights Reserved.
10
11 # License: GNU General Public License, Version 2.
12 #
13 # CVS Data: $Id: firewall.sh,v 1.6 2003/03/27 14:39:36 mark-c Exp $
14 #
15 # Description:
16 #
17 # Sample script to configure the necessary firewall rules
18 # for ReAim using iptables.  See the source for an ipt/NetBSD example.
19 #
20 # Final words:
21 #
22 # No warranty. Patches, bug reports, success stories and other contributions
23 # most welcome.
24
25
26 # -------------------------
27 # User configurable section
28 # -------------------------
29 #
30 # The user must uncomment the INSIDE_IF and OUTSIDE_IF
31 # lines, and select the appropriate network interfaces
32 # for this script to use to configure networking.
33 #
34 # Example ethernet-connected cable / corporate firewall:
35 # INSIDE_IF=eth0
36 # OUTSIDE_IF=eth1
37 #
38 # Example home LAN with dialup:
39 # INSIDE_IF=eth0
40 # OUTSIDE_IF=ppp0
41
42 #--------------------------------------------------------------
43 # SHOULD NOT HAVE TO CHANGE ANYTHING BELOW HERE
44 #--------------------------------------------------------------
45
46 newchain() {
47     # Check syntax
48     if [ $# = 0 ]; then
49         echo "Usage: newchain {name}"
50     fi
51
52     # If chain already exists just flush it, else create it.
53     $IPT $2 -L -n | grep "$1 " > /dev/null
54     if test "$?" = 0
55     then
56         $IPT_X $2 -F "$1"
57     else
58         $IPT_X $2 -N "$1"
59     fi
60 }
61
62 # Just in case we don't have the sbin directories in the
63 # path, tag them to the end.
64 export PATH=$PATH:/sbin:/usr/sbin
65
66 # Sanity check the user supplied interfaces...
67 #
68 if [ X${INSIDE_IF} = "X" ];
69 then
70         echo "INSIDE_IF was not defined. Please adjust the start of the script."
71         exit 1
72 else
73         grep -q "${INSIDE_IF}:" /proc/net/dev
74         if [ $? != 0 ];
75         then
76                 echo "INSIDE_IF (${INSIDE_IF}) is not listed as an interface in /proc/net/dev."
77                 exit 1
78         fi
79 fi
80
81 if [ X${OUTSIDE_IF} = "X" ];
82 then
83         echo "OUTSIDE_IF was not defined. Please adjust the start of the script."
84         exit 1
85 else
86         grep -q "${OUTSIDE_IF}:" /proc/net/dev
87         if [ $? != 0 ];
88         then
89                 echo "OUTSIDE_IF (${OUTSIDE_IF}) is not listed as an interface in /proc/net/dev."
90                 exit 1
91         fi
92 fi
93
94 if [ ${INSIDE_IF} = ${OUTSIDE_IF} ];
95 then
96         echo "INSIDE_IF and OUTSIDE_IF are not allowed to be the same device!"
97         exit 1
98 fi
99
100 # Find the iptables tool...
101 #
102 IPT=`which iptables 2>/dev/null`
103 if [ X${IPT} = "X" ];
104 then
105         echo "Unable to locate iptables.  Please ensure you have it installed."
106         exit 1
107 fi
108
109 # Check to see if iptables is available by looking in /proc
110 #
111 # This basically ensures that the user's already loaded the iptables
112 # modules
113 #
114 if [ ! -f /proc/net/ip_tables_names ];
115 then
116         echo "Unable to find iptables information in /proc."
117         exit 1
118 fi
119
120 # Check we have root privs
121 if [ $UID != "0" ];
122 then
123         echo "iptables requires root privs to run."
124         exit 1
125 fi
126
127 echo "--------------------------------------------------------------"
128 echo "WARNING: This script has not been production tested."
129 echo "         Uncomment the IPT_X="\$IPT" line if you're brave!"
130 echo "         The following is what would be done..."
131 echo "--------------------------------------------------------------"
132
133 IPT_X="echo $IPT"
134 # IPT_X=$IPT
135
136 # Create new chains or flush existing ones with these names.
137 #
138 newchain REAIM_IN
139 newchain REAIM_PRE "-t nat"
140
141 # Add the AIM accept rules to the outside interface...
142 $IPT_X -I REAIM_IN 1  -i ${OUTSIDE_IF} -p tcp --dport 4443 -j ACCEPT
143 $IPT_X -I REAIM_IN 1  -i ${OUTSIDE_IF} -p tcp --dport 5190 -j ACCEPT
144 $IPT_X -I REAIM_IN 1  -i ${OUTSIDE_IF} -p tcp --dport 5566 -j ACCEPT
145
146 # Add the MSN accept rules to the outside interface...
147 $IPT_X -I REAIM_IN 1  -i ${OUTSIDE_IF} -p tcp --dport 1864 -j ACCEPT
148
149 # Add the DYNAMIC DCC port range to the outside interface...
150 $IPT_X -I REAIM_IN 1  -i ${OUTSIDE_IF} -p tcp --dport 40000:40099 -j ACCEPT
151
152 # Add the AIM port interception rules to the inside interface...
153 $IPT_X -I REAIM_PRE 1 -t nat  -i ${INSIDE_IF} -p tcp --dport 5190 -j REDIRECT --to-port 5190
154 $IPT_X -I REAIM_IN 1  -i ${INSIDE_IF} -p tcp --dport 4443 -j ACCEPT
155 $IPT_X -I REAIM_IN 1  -i ${INSIDE_IF} -p tcp --dport 5190 -j ACCEPT
156 $IPT_X -I REAIM_IN 1  -i ${INSIDE_IF} -p tcp --dport 5566 -j ACCEPT
157
158 # Add the MSN port interception rules to the inside interface...
159 $IPT_X -I REAIM_PRE 1 -t nat  -i ${INSIDE_IF} -p tcp --dport 1863 -j REDIRECT --to-port 1863
160 $IPT_X -I REAIM_IN 1 -i ${INSIDE_IF} -p tcp --dport 1863:1864 -j ACCEPT
161
162
163 # Add the REAIM_* chains to the appropriate place, but only if they
164 # didn't already exist.
165 $IPT -L INPUT -n | grep "^REAIM_IN " > /dev/null
166 if [ $? = 1 ];
167 then
168         $IPT_X -I INPUT 1 -j REAIM_IN
169 fi
170
171 $IPT -L PREROUTING -t nat -n | grep "^REAIM_PRE " > /dev/null
172 if [ $? = 1 ];
173 then
174         $IPT_X -I PREROUTING 1 -t nat -j REAIM_PRE
175 fi