2002-05-01 01:13:15 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2006-01-16 16:15:43 +01:00
|
|
|
# The Shoreline Firewall (Shorewall) Packet Filtering Firewall - V3.2
|
2002-05-01 01:13:15 +02:00
|
|
|
#
|
2003-02-23 15:10:37 +01:00
|
|
|
# This program is under GPL [http://www.gnu.org/copyleft/gpl.htm]
|
2002-05-01 01:13:15 +02:00
|
|
|
#
|
2006-01-15 20:27:57 +01:00
|
|
|
# (c) 1999,2000,2001,2002,2003,2004,2005,2006 - Tom Eastep (teastep@shorewall.net)
|
2005-10-07 00:46:17 +02:00
|
|
|
#
|
2005-10-06 00:51:29 +02:00
|
|
|
# tcstart from tc4shorewall Version 0.5
|
|
|
|
# (c) 2005 Arne Bernin <arne@ucbering.de>
|
|
|
|
# Modified by Tom Eastep for integration into the Shorewall distribution
|
|
|
|
# published under GPL Version 2#
|
2002-05-01 01:13:15 +02:00
|
|
|
#
|
|
|
|
# Complete documentation is available at http://shorewall.net
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
2003-02-23 15:10:37 +01:00
|
|
|
# it under the terms of Version 2 of the GNU General Public License
|
2002-05-01 01:13:15 +02:00
|
|
|
# as published by the Free Software Foundation.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA
|
|
|
|
#
|
|
|
|
# If an error occurs while starting or restarting the firewall, the
|
|
|
|
# firewall is automatically stopped.
|
|
|
|
#
|
|
|
|
# Commands are:
|
|
|
|
#
|
2003-02-23 15:10:37 +01:00
|
|
|
# shorewall start Starts the firewall
|
2002-05-01 01:13:15 +02:00
|
|
|
# shorewall restart Restarts the firewall
|
|
|
|
# shorewall stop Stops the firewall
|
2005-07-09 07:45:05 +02:00
|
|
|
# shorewall reset Resets iptables packet and
|
2002-05-01 01:13:15 +02:00
|
|
|
# byte counts
|
2003-02-23 15:10:37 +01:00
|
|
|
# shorewall clear Remove all Shorewall chains
|
2002-05-01 01:13:15 +02:00
|
|
|
# and rules/policies.
|
2002-10-23 18:48:40 +02:00
|
|
|
#
|
|
|
|
# Mutual exclusion -- These functions are jackets for the mutual exclusion
|
2003-01-07 00:01:23 +01:00
|
|
|
# routines in $FUNCTIONS. They invoke
|
2002-10-23 18:48:40 +02:00
|
|
|
# the corresponding function in that file if the user did
|
|
|
|
# not specify "nolock" on the runline.
|
|
|
|
#
|
2006-01-16 22:29:00 +01:00
|
|
|
my_mutex_on() {
|
2006-01-17 18:34:34 +01:00
|
|
|
[ -n "$NOLOCK" ] || { mutex_on; HAVE_MUTEX=Yes; }
|
2006-01-16 22:29:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
my_mutex_off() {
|
|
|
|
[ -n "$HAVE_MUTEX" ] && { mutex_off; HAVE_MUTEX=; }
|
|
|
|
}
|
|
|
|
|
2002-10-23 18:48:40 +02:00
|
|
|
#
|
|
|
|
# Fatal error -- stops the firewall after issuing the error message
|
|
|
|
#
|
2002-05-01 01:13:15 +02:00
|
|
|
fatal_error() # $* = Error Message
|
|
|
|
{
|
2005-07-26 01:08:09 +02:00
|
|
|
echo " ERROR: $@" >&2
|
2006-01-23 00:41:56 +01:00
|
|
|
stop_firewall
|
2002-05-01 01:13:15 +02:00
|
|
|
exit 2
|
|
|
|
}
|
|
|
|
|
2002-10-23 18:48:40 +02:00
|
|
|
#
|
2005-07-09 07:45:05 +02:00
|
|
|
# Fatal error during startup -- generate an error message and abend without
|
2002-10-23 18:48:40 +02:00
|
|
|
# altering the state of the firewall
|
|
|
|
#
|
2002-05-01 01:13:15 +02:00
|
|
|
startup_error() # $* = Error Message
|
|
|
|
{
|
2005-07-26 01:08:09 +02:00
|
|
|
echo " ERROR: $@" >&2
|
2002-05-01 01:13:15 +02:00
|
|
|
my_mutex_off
|
|
|
|
[ -n "$TMP_DIR" ] && rm -rf $TMP_DIR
|
2005-07-09 06:45:32 +02:00
|
|
|
[ -n "$RESTOREBASE" ] && rm -f $RESTOREBASE
|
2002-05-01 01:13:15 +02:00
|
|
|
kill $$
|
|
|
|
exit 2
|
|
|
|
}
|
|
|
|
|
2002-10-23 18:48:40 +02:00
|
|
|
#
|
|
|
|
# Send a message to STDOUT and the System Log
|
|
|
|
#
|
2002-05-03 00:56:27 +02:00
|
|
|
report () { # $* = message
|
2006-01-25 01:13:45 +01:00
|
|
|
progress_message3 "$@"
|
2002-05-03 00:56:27 +02:00
|
|
|
logger "$@"
|
|
|
|
}
|
|
|
|
|
2002-10-23 18:48:40 +02:00
|
|
|
#
|
|
|
|
# Run iptables and if an error occurs, stop the firewall and quit
|
|
|
|
#
|
2002-05-01 01:13:15 +02:00
|
|
|
run_iptables() {
|
2006-04-11 00:52:10 +02:00
|
|
|
if [ -z "$KLUDGEFREE" ]; then
|
|
|
|
#
|
|
|
|
# Purge the temporary files that we use to prevent duplicate '-m' specifications
|
|
|
|
#
|
|
|
|
[ -n "$BRIDGING" ] && [ -f $TMP_DIR/physdev ] && rm -f $TMP_DIR/physdev
|
|
|
|
[ -n "$IPRANGE_MATCH" ] && [ -f $TMP_DIR/iprange ] && rm -f $TMP_DIR/iprange
|
|
|
|
fi
|
2005-07-09 06:45:32 +02:00
|
|
|
|
2006-04-11 00:52:10 +02:00
|
|
|
if ! $IPTABLES $@ ; then
|
2005-09-08 22:57:29 +02:00
|
|
|
if [ -z "$STOPPING" ]; then
|
2005-07-09 07:45:05 +02:00
|
|
|
error_message "ERROR: Command \"$IPTABLES $@\" Failed"
|
|
|
|
stop_firewall
|
|
|
|
exit 2
|
|
|
|
fi
|
2002-12-18 22:26:03 +01:00
|
|
|
fi
|
|
|
|
}
|
2002-12-18 22:58:21 +01:00
|
|
|
|
2002-12-18 22:26:03 +01:00
|
|
|
#
|
|
|
|
# Version of 'run_iptables' that inserts white space after "!" in the arg list
|
|
|
|
#
|
|
|
|
run_iptables2() {
|
|
|
|
|
2005-07-09 07:45:05 +02:00
|
|
|
case "$@" in
|
|
|
|
*!*)
|
|
|
|
run_iptables $(fix_bang $@)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
run_iptables $@
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2005-07-09 06:45:32 +02:00
|
|
|
}
|
|
|
|
|
2006-01-12 00:30:33 +01:00
|
|
|
#
|
|
|
|
# Quietly run iptables
|
|
|
|
#
|
|
|
|
qt_iptables() {
|
2006-04-11 00:52:10 +02:00
|
|
|
if [ -z "$KLUDGEFREE" ]; then
|
|
|
|
#
|
|
|
|
# Purge the temporary files that we use to prevent duplicate '-m' specifications
|
|
|
|
#
|
|
|
|
[ -n "$BRIDGING" ] && [ -f $TMP_DIR/physdev ] && rm -f $TMP_DIR/physdev
|
|
|
|
[ -n "$IPRANGE_MATCH" ] && [ -f $TMP_DIR/iprange ] && rm -f $TMP_DIR/iprange
|
|
|
|
fi
|
2006-01-12 00:30:33 +01:00
|
|
|
|
|
|
|
qt $IPTABLES $@
|
|
|
|
}
|
|
|
|
|
2002-10-23 18:48:40 +02:00
|
|
|
#
|
|
|
|
# Run ip and if an error occurs, stop the firewall and quit
|
|
|
|
#
|
2002-05-01 01:13:15 +02:00
|
|
|
run_ip() {
|
|
|
|
if ! ip $@ ; then
|
2005-09-08 22:57:29 +02:00
|
|
|
if [ -z "$STOPPING" ]; then
|
2005-07-09 07:45:05 +02:00
|
|
|
error_message "ERROR: Command \"ip $@\" Failed"
|
|
|
|
stop_firewall
|
|
|
|
exit 2
|
|
|
|
fi
|
2002-05-01 01:13:15 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2002-10-23 18:48:40 +02:00
|
|
|
#
|
|
|
|
# Run tc and if an error occurs, stop the firewall and quit
|
|
|
|
#
|
2002-05-01 01:13:15 +02:00
|
|
|
run_tc() {
|
|
|
|
if ! tc $@ ; then
|
2005-09-08 22:57:29 +02:00
|
|
|
if [ -z "$STOPPING" ]; then
|
2005-07-09 07:45:05 +02:00
|
|
|
error_message "ERROR: Command \"tc $@\" Failed"
|
|
|
|
stop_firewall
|
|
|
|
exit 2
|
|
|
|
fi
|
2002-05-01 01:13:15 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2006-01-17 00:15:51 +01:00
|
|
|
#
|
|
|
|
# Delete a chain if it exists
|
|
|
|
#
|
|
|
|
deletechain() # $1 = name of chain
|
|
|
|
{
|
|
|
|
qt $IPTABLES -L $1 -n && qt $IPTABLES -F $1 && qt $IPTABLES -X $1
|
|
|
|
}
|
|
|
|
|
2006-01-25 01:13:45 +01:00
|
|
|
#
|
|
|
|
# Find broadcast addresses -- if we are compiling a script and 'detect' is specified for an interface
|
|
|
|
# the function returns nothing for that interface
|
|
|
|
#
|
|
|
|
find_broadcasts() {
|
|
|
|
for interface in $ALL_INTERFACES; do
|
|
|
|
eval bcast=\$$(chain_base $interface)_broadcast
|
|
|
|
if [ "x$bcast" = "xdetect" ]; then
|
|
|
|
ip -f inet addr show $interface 2> /dev/null | grep 'inet.*brd' | sed 's/inet.*brd //; s/scope.*//;' | sort -u
|
|
|
|
elif [ "x${bcast}" != "x-" ]; then
|
|
|
|
echo $(separate_list $bcast)
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
2005-10-06 18:35:20 +02:00
|
|
|
|
2005-07-26 01:08:09 +02:00
|
|
|
#
|
|
|
|
# For each entry in the CRITICALHOSTS global list, add INPUT and OUTPUT rules to
|
|
|
|
# enable traffic to/from those hosts.
|
|
|
|
#
|
2005-08-02 18:46:30 +02:00
|
|
|
enable_critical_hosts()
|
2005-07-26 01:08:09 +02:00
|
|
|
{
|
|
|
|
for host in $CRITICALHOSTS; do
|
|
|
|
interface=${host%:*}
|
|
|
|
networks=${host#*:}
|
2006-01-25 01:13:45 +01:00
|
|
|
$IPTABLES -A INPUT -i $interface $(source_ip_range $networks) -j ACCEPT
|
|
|
|
$IPTABLES -A OUTPUT -o $interface $(dest_ip_range $networks) -j ACCEPT
|
2005-07-26 01:08:09 +02:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# For each entry in the CRITICALHOSTS global list, delete the INPUT and OUTPUT rules that
|
|
|
|
# enable traffic to/from those hosts.
|
|
|
|
#
|
2005-08-02 18:46:30 +02:00
|
|
|
disable_critical_hosts()
|
2005-07-26 01:08:09 +02:00
|
|
|
{
|
|
|
|
for host in $CRITICALHOSTS; do
|
|
|
|
interface=${host%:*}
|
|
|
|
networks=${host#*:}
|
2006-01-25 01:13:45 +01:00
|
|
|
$IPTABLES -D INPUT -i $interface $(source_ip_range $networks) -j ACCEPT
|
|
|
|
$IPTABLES -D OUTPUT -o $interface $(dest_ip_range $networks) -j ACCEPT
|
2005-07-26 01:08:09 +02:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2006-01-17 00:15:51 +01:00
|
|
|
#
|
|
|
|
# Stop the Firewall
|
|
|
|
#
|
|
|
|
stop_firewall() {
|
|
|
|
#
|
|
|
|
# Turn off trace unless we were tracing "stop" or "clear"
|
|
|
|
#
|
|
|
|
|
|
|
|
[ -n "$RESTOREBASE" ] && rm -f $RESTOREBASE
|
|
|
|
|
|
|
|
case $COMMAND in
|
|
|
|
stop|clear)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
set +x
|
|
|
|
|
|
|
|
[ -n "${RESTOREFILE:=restore}" ]
|
|
|
|
|
2006-06-09 18:35:55 +02:00
|
|
|
RESTOREPATH=${VARDIR}/$RESTOREFILE
|
2006-01-17 00:15:51 +01:00
|
|
|
|
|
|
|
if [ -x $RESTOREPATH ]; then
|
|
|
|
|
|
|
|
if [ -x ${RESTOREPATH}-ipsets ]; then
|
|
|
|
progress_message2 Restoring Ipsets...
|
|
|
|
#
|
|
|
|
# We must purge iptables to be sure that there are no
|
|
|
|
# references to ipsets
|
|
|
|
#
|
|
|
|
for table in mangle nat filter; do
|
|
|
|
iptables -t $table -F
|
|
|
|
iptables -t $table -X
|
|
|
|
done
|
|
|
|
|
|
|
|
${RESTOREPATH}-ipsets
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo Restoring Shorewall...
|
|
|
|
|
2006-01-25 23:33:50 +01:00
|
|
|
if $RESTOREPATH restore; then
|
2006-01-17 00:15:51 +01:00
|
|
|
echo "Shorewall restored from $RESTOREPATH"
|
|
|
|
set_state "Started"
|
|
|
|
else
|
|
|
|
set_state "Unknown"
|
|
|
|
fi
|
|
|
|
|
|
|
|
my_mutex_off
|
|
|
|
kill $$
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
set_state "Stopping"
|
|
|
|
|
|
|
|
STOPPING="Yes"
|
|
|
|
|
|
|
|
TERMINATOR=
|
|
|
|
|
|
|
|
deletechain shorewall
|
|
|
|
|
|
|
|
run_user_exit stop
|
|
|
|
|
|
|
|
if [ -n "$MANGLE_ENABLED" ]; then
|
|
|
|
run_iptables -t mangle -F
|
|
|
|
run_iptables -t mangle -X
|
|
|
|
for chain in PREROUTING INPUT FORWARD POSTROUTING; do
|
|
|
|
qt $IPTABLES -t mangle -P $chain ACCEPT
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$RAW_TABLE" ]; then
|
|
|
|
run_iptables -t raw -F
|
|
|
|
run_iptables -t raw -X
|
|
|
|
for chain in PREROUTING OUTPUT; do
|
|
|
|
qt $IPTABLES -t raw -P $chain ACCEPT
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$NAT_ENABLED" ]; then
|
|
|
|
delete_nat
|
|
|
|
for chain in PREROUTING POSTROUTING OUTPUT; do
|
|
|
|
qt $IPTABLES -t nat -P $chain ACCEPT
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
delete_proxy_arp
|
|
|
|
[ -n "$CLEAR_TC" ] && delete_tc1
|
|
|
|
|
|
|
|
[ -n "$DISABLE_IPV6" ] && disable_ipv6
|
|
|
|
|
|
|
|
process_criticalhosts
|
|
|
|
|
|
|
|
if [ -n "$CRITICALHOSTS" ]; then
|
|
|
|
if [ -z "$ADMINISABSENTMINDED" ]; then
|
|
|
|
for chain in INPUT OUTPUT; do
|
|
|
|
setpolicy $chain ACCEPT
|
|
|
|
done
|
|
|
|
|
|
|
|
setpolicy FORWARD DROP
|
|
|
|
|
|
|
|
deleteallchains
|
|
|
|
|
|
|
|
enable_critical_hosts
|
|
|
|
|
|
|
|
for chain in INPUT OUTPUT; do
|
|
|
|
setpolicy $chain DROP
|
|
|
|
done
|
|
|
|
else
|
|
|
|
for chain in INPUT OUTPUT; do
|
|
|
|
setpolicy $chain ACCEPT
|
|
|
|
done
|
|
|
|
|
|
|
|
setpolicy FORWARD DROP
|
|
|
|
|
|
|
|
deleteallchains
|
|
|
|
|
|
|
|
enable_critical_hosts
|
|
|
|
|
|
|
|
setpolicy INPUT DROP
|
|
|
|
|
|
|
|
for chain in INPUT FORWARD; do
|
|
|
|
setcontinue $chain
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
elif [ -z "$ADMINISABSENTMINDED" ]; then
|
|
|
|
for chain in INPUT OUTPUT FORWARD; do
|
|
|
|
setpolicy $chain DROP
|
|
|
|
done
|
|
|
|
|
|
|
|
deleteallchains
|
|
|
|
else
|
|
|
|
for chain in INPUT FORWARD; do
|
|
|
|
setpolicy $chain DROP
|
|
|
|
done
|
|
|
|
|
|
|
|
setpolicy OUTPUT ACCEPT
|
|
|
|
|
|
|
|
deleteallchains
|
|
|
|
|
|
|
|
for chain in INPUT FORWARD; do
|
|
|
|
setcontinue $chain
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
process_routestopped -A
|
|
|
|
|
|
|
|
$IPTABLES -A INPUT -i lo -j ACCEPT
|
|
|
|
[ -z "$ADMINISABSENTMINDED" ] && \
|
|
|
|
$IPTABLES -A OUTPUT -o lo -j ACCEPT
|
|
|
|
|
|
|
|
for interface in $(find_interfaces_by_option dhcp); do
|
|
|
|
$IPTABLES -A INPUT -p udp -i $interface --dport 67:68 -j ACCEPT
|
|
|
|
[ -z "$ADMINISABSENTMINDED" ] && \
|
|
|
|
$IPTABLES -A OUTPUT -p udp -o $interface --dport 67:68 -j ACCEPT
|
|
|
|
#
|
|
|
|
# This might be a bridge
|
|
|
|
#
|
|
|
|
$IPTABLES -A FORWARD -p udp -i $interface -o $interface --dport 67:68 -j ACCEPT
|
|
|
|
done
|
|
|
|
|
|
|
|
case "$IP_FORWARDING" in
|
|
|
|
[Oo][Nn])
|
|
|
|
echo 1 > /proc/sys/net/ipv4/ip_forward
|
|
|
|
progress_message2 "IP Forwarding Enabled"
|
|
|
|
;;
|
|
|
|
[Oo][Ff][Ff])
|
|
|
|
echo 0 > /proc/sys/net/ipv4/ip_forward
|
|
|
|
progress_message2 "IP Forwarding Disabled!"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
run_user_exit stopped
|
|
|
|
|
|
|
|
set_state "Stopped"
|
|
|
|
|
|
|
|
logger "Shorewall Stopped"
|
|
|
|
|
|
|
|
rm -rf $TMP_DIR
|
|
|
|
|
|
|
|
case $COMMAND in
|
|
|
|
stop|clear)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
#
|
|
|
|
# The firewall is being stopped when we were trying to do something
|
|
|
|
# else. Remove the lock file and Kill the shell in case we're in a
|
|
|
|
# subshell
|
|
|
|
#
|
|
|
|
my_mutex_off
|
|
|
|
kill $$
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Remove all rules and remove all user-defined chains
|
|
|
|
#
|
|
|
|
clear_firewall() {
|
|
|
|
stop_firewall
|
|
|
|
|
|
|
|
setpolicy INPUT ACCEPT
|
|
|
|
setpolicy FORWARD ACCEPT
|
|
|
|
setpolicy OUTPUT ACCEPT
|
|
|
|
|
|
|
|
run_iptables -F
|
|
|
|
|
|
|
|
echo 1 > /proc/sys/net/ipv4/ip_forward
|
|
|
|
|
2006-01-18 02:42:24 +01:00
|
|
|
if [ -n "$DISABLE_IPV6" ] && qt mywhich ip6tables; then
|
2006-01-17 00:15:51 +01:00
|
|
|
ip6tables -P INPUT ACCEPT 2> /dev/null
|
|
|
|
ip6tables -P OUTPUT ACCEPT 2> /dev/null
|
|
|
|
ip6tables -P FORWARD ACCEPT 2> /dev/null
|
|
|
|
fi
|
|
|
|
|
|
|
|
run_user_exit clear
|
|
|
|
|
|
|
|
set_state "Cleared"
|
|
|
|
|
|
|
|
logger "Shorewall Cleared"
|
|
|
|
}
|
|
|
|
|
2002-10-23 18:48:40 +02:00
|
|
|
#
|
2006-01-25 01:13:45 +01:00
|
|
|
# Delete existing Proxy ARP
|
|
|
|
#
|
|
|
|
delete_proxy_arp() {
|
2006-06-09 18:35:55 +02:00
|
|
|
if [ -f ${VARDIR}/proxyarp ]; then
|
2006-01-25 01:13:45 +01:00
|
|
|
while read address interface external haveroute; do
|
|
|
|
case $COMMAND in
|
|
|
|
stop|clear)
|
|
|
|
qt arp -i $external -d $address pub
|
|
|
|
[ -z "${haveroute}${NOROUTES}" ] && qt ip route del $address dev $interface
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
if [ -n "$STOPPING" ]; then
|
|
|
|
qt arp -i $external -d $address pub
|
|
|
|
qt arp -i $external -d $address pub
|
|
|
|
[ -z "${haveroute}${NOROUTES}" ] && qt ip route del $address dev $interface
|
|
|
|
else
|
|
|
|
qt arp -i $external -d $address pub
|
|
|
|
if [ -z "$haveroute" ];then
|
|
|
|
[ -n "$NOROUTE" ] || qt ip route del $address dev $interface
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
2006-06-09 18:35:55 +02:00
|
|
|
done < ${VARDIR}/proxyarp
|
2005-07-09 06:45:32 +02:00
|
|
|
|
2006-06-09 18:35:55 +02:00
|
|
|
rm -f ${VARDIR}/proxyarp
|
2006-01-25 01:13:45 +01:00
|
|
|
fi
|
2005-07-09 06:45:32 +02:00
|
|
|
|
2006-08-02 22:18:17 +02:00
|
|
|
[ -d ${VARDIR} ] && touch ${VARDIR}/proxyarp
|
2005-07-09 06:45:32 +02:00
|
|
|
|
2006-01-25 01:13:45 +01:00
|
|
|
case $COMMAND in
|
|
|
|
stop|clear)
|
|
|
|
for f in /proc/sys/net/ipv4/conf/*; do
|
|
|
|
[ -f $f/proxy_arp ] && echo 0 > $f/proxy_arp
|
|
|
|
done
|
2002-05-01 01:13:15 +02:00
|
|
|
;;
|
2002-07-06 00:24:40 +02:00
|
|
|
*)
|
2006-01-25 01:13:45 +01:00
|
|
|
if [ -n "$STOPPING" ]; then
|
|
|
|
for f in /proc/sys/net/ipv4/conf/*; do
|
|
|
|
[ -f $f/proxy_arp ] && echo 0 > $f/proxy_arp
|
|
|
|
done
|
|
|
|
else
|
|
|
|
for f in /proc/sys/net/ipv4/conf/*; do
|
|
|
|
[ -f $f/proxy_arp ] && echo 0 > $f/proxy_arp
|
|
|
|
done
|
2002-07-06 00:24:40 +02:00
|
|
|
fi
|
2002-05-01 01:13:15 +02:00
|
|
|
;;
|
2006-01-25 01:13:45 +01:00
|
|
|
esac
|
|
|
|
}
|
2002-05-01 01:13:15 +02:00
|
|
|
|
2006-01-25 01:13:45 +01:00
|
|
|
#
|
|
|
|
# Delete existing Static NAT
|
|
|
|
#
|
|
|
|
delete_nat() {
|
|
|
|
run_iptables -t nat -F
|
|
|
|
run_iptables -t nat -X
|
2005-07-09 06:45:32 +02:00
|
|
|
|
2006-06-09 18:35:55 +02:00
|
|
|
if [ -f ${VARDIR}/nat ]; then
|
2006-01-25 01:13:45 +01:00
|
|
|
while read external interface; do
|
|
|
|
qt ip addr del $external dev $interface
|
2006-06-09 18:35:55 +02:00
|
|
|
done < ${VARDIR}/nat
|
2006-01-14 21:40:15 +01:00
|
|
|
|
2006-06-09 18:35:55 +02:00
|
|
|
rm -f ${VARDIR}/nat
|
2006-01-25 01:13:45 +01:00
|
|
|
fi
|
2006-01-14 21:40:15 +01:00
|
|
|
|
2006-08-02 22:18:17 +02:00
|
|
|
[ -d ${VARDIR} ] && touch ${VARDIR}/nat
|
2006-01-25 01:13:45 +01:00
|
|
|
}
|
2005-07-09 06:45:32 +02:00
|
|
|
|
2003-02-24 16:24:55 +01:00
|
|
|
#
|
2006-08-27 19:27:48 +02:00
|
|
|
# Display elements of a list with leading white space
|
2003-12-04 03:01:08 +01:00
|
|
|
#
|
2006-01-25 01:13:45 +01:00
|
|
|
display_list() # $1 = List Title, rest of $* = list to display
|
2003-12-04 03:01:08 +01:00
|
|
|
{
|
2006-01-25 01:13:45 +01:00
|
|
|
[ $# -gt 1 ] && echo " $*"
|
2003-12-04 03:01:08 +01:00
|
|
|
}
|
|
|
|
|
2006-01-25 01:13:45 +01:00
|
|
|
#
|
|
|
|
# Verify that kernel has netfilter support
|
|
|
|
#
|
|
|
|
verify_os_version() {
|
2005-08-02 18:46:30 +02:00
|
|
|
|
2006-01-25 01:13:45 +01:00
|
|
|
osversion=$(uname -r)
|
2005-07-09 07:45:05 +02:00
|
|
|
|
2006-01-25 01:13:45 +01:00
|
|
|
case $osversion in
|
|
|
|
2.4.*|2.5.*|2.6.*)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
startup_error "Shorewall version $VERSION does not work with kernel version $osversion"
|
|
|
|
;;
|
|
|
|
esac
|
2005-07-09 07:45:05 +02:00
|
|
|
|
2006-01-25 01:13:45 +01:00
|
|
|
[ $COMMAND = start -a -n "$(lsmod 2> /dev/null | grep '^ipchains')" ] && \
|
|
|
|
startup_error "Shorewall can't start with the ipchains kernel module loaded - see FAQ #8"
|
2002-05-01 01:13:15 +02:00
|
|
|
}
|
|
|
|
|
2002-10-23 18:48:40 +02:00
|
|
|
#
|
2003-07-28 19:32:41 +02:00
|
|
|
# Check for disabled startup
|
2002-10-23 18:48:40 +02:00
|
|
|
#
|
2003-07-28 19:32:41 +02:00
|
|
|
check_disabled_startup() {
|
2005-07-09 07:45:05 +02:00
|
|
|
if [ -z "$STARTUP_ENABLED" ]; then
|
2002-09-19 22:40:10 +02:00
|
|
|
echo " Shorewall Startup is disabled -- to enable startup"
|
|
|
|
echo " after you have completed Shorewall configuration,"
|
2005-07-09 07:45:05 +02:00
|
|
|
echo " change the setting of STARTUP_ENABLED to Yes in"
|
2006-06-09 18:35:55 +02:00
|
|
|
echo " ${CONFDIR}/shorewall.conf"
|
2002-09-19 22:40:10 +02:00
|
|
|
|
2002-09-29 23:28:44 +02:00
|
|
|
[ -n "$TMP_DIR" ] && rm -rf $TMP_DIR
|
2002-09-19 22:40:10 +02:00
|
|
|
my_mutex_off
|
|
|
|
exit 2
|
|
|
|
fi
|
2003-07-28 19:32:41 +02:00
|
|
|
}
|
|
|
|
|
2006-05-06 18:15:33 +02:00
|
|
|
#
|
2006-08-27 19:27:48 +02:00
|
|
|
# Add a host or networks to a zone
|
2006-05-06 18:15:33 +02:00
|
|
|
#
|
2006-08-27 19:27:48 +02:00
|
|
|
add_to_zone() # $1...${n-1} = <interface>[:<hosts>] $n = zone
|
|
|
|
{
|
|
|
|
local interface host zone z h z1 z2 chain
|
|
|
|
local dhcp_interfaces blacklist_interfaces maclist_interfaces
|
|
|
|
local tcpflags_interfaces newhostlist=
|
|
|
|
local rulenum source_chain dest_hosts iface hosts hostlist=
|
|
|
|
|
|
|
|
nat_chain_exists() # $1 = chain name
|
2006-05-10 16:34:50 +02:00
|
|
|
{
|
2006-08-27 19:27:48 +02:00
|
|
|
qt $IPTABLES -t nat -L $1 -n
|
2006-05-10 16:34:50 +02:00
|
|
|
}
|
2006-05-06 18:15:33 +02:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
do_iptables() # $@ = command
|
|
|
|
{
|
|
|
|
[ -n "$BRIDGING" ] && [ -f $TMP_DIR/physdev ] && rm -f $TMP_DIR/physdev
|
|
|
|
[ -n "$IPRANGE_MATCH" ] && [ -f $TMP_DIR/iprange ] && rm -f $TMP_DIR/iprange
|
2006-05-06 18:15:33 +02:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
if ! $IPTABLES $@ ; then
|
|
|
|
error_message "ERROR: Can't add $newhost to zone $zone"
|
|
|
|
fi
|
|
|
|
}
|
2006-05-06 18:15:33 +02:00
|
|
|
|
|
|
|
#
|
2006-08-27 19:27:48 +02:00
|
|
|
# Load $zones
|
2006-05-06 18:15:33 +02:00
|
|
|
#
|
2006-08-27 19:27:48 +02:00
|
|
|
determine_zones
|
2006-05-06 18:15:33 +02:00
|
|
|
#
|
2006-08-27 19:27:48 +02:00
|
|
|
# Validate Interfaces File
|
2006-05-06 18:15:33 +02:00
|
|
|
#
|
2006-08-27 19:27:48 +02:00
|
|
|
validate_interfaces_file
|
2006-05-06 18:15:33 +02:00
|
|
|
#
|
2006-08-27 19:27:48 +02:00
|
|
|
# Validate Hosts File
|
2006-05-06 18:15:33 +02:00
|
|
|
#
|
2006-08-27 19:27:48 +02:00
|
|
|
validate_hosts_file
|
|
|
|
#
|
|
|
|
# Validate IPSec File
|
|
|
|
#
|
|
|
|
f=$(find_file $IPSECFILE)
|
2006-08-22 22:20:42 +02:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
[ -f $f ] && setup_ipsec $f
|
|
|
|
#
|
|
|
|
# Normalize host list
|
|
|
|
#
|
|
|
|
while [ $# -gt 1 ]; do
|
|
|
|
interface=${1%%:*}
|
|
|
|
host=${1#*:}
|
|
|
|
#
|
|
|
|
# Be sure that the interface was dynamic at last [re]start
|
|
|
|
#
|
|
|
|
if ! chain_exists $(input_chain $interface) ; then
|
|
|
|
startup_error "Unknown interface $interface"
|
|
|
|
fi
|
2006-05-06 18:15:33 +02:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
if ! chain_exists $(dynamic_in $interface) ; then
|
|
|
|
startup_error "At last Shorewall [re]start, DYNAMIC_ZONES=No in shorewall.conf"
|
|
|
|
fi
|
2006-08-22 22:20:42 +02:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
if [ -z "$host" ]; then
|
|
|
|
hostlist="$hostlist $interface:0.0.0.0/0"
|
|
|
|
else
|
|
|
|
for h in $(separate_list $host); do
|
|
|
|
hostlist="$hostlist $interface:$h"
|
|
|
|
done
|
2006-08-22 22:20:42 +02:00
|
|
|
fi
|
2006-05-06 18:15:33 +02:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
shift
|
|
|
|
done
|
|
|
|
#
|
|
|
|
# Validate Zone
|
|
|
|
#
|
|
|
|
zone=$1
|
2006-05-06 18:15:33 +02:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
validate_zone $zone || startup_error "Unknown zone: $zone"
|
2006-01-17 21:03:00 +01:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
[ "$zone" = $FW ] && startup_error "Can't add $1 to firewall zone"
|
2006-01-17 21:03:00 +01:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
#
|
|
|
|
# Be sure that Shorewall has been restarted using a DZ-aware version of the code
|
|
|
|
#
|
|
|
|
[ -f ${VARDIR}/chains ] || startup_error "${VARDIR}/chains -- file not found"
|
|
|
|
[ -f ${VARDIR}/zones ] || startup_error "${VARDIR}/zones -- file not found"
|
|
|
|
#
|
|
|
|
# Check for duplicates and create a new zone state file
|
|
|
|
#
|
|
|
|
> ${VARDIR}/zones_$$
|
|
|
|
|
|
|
|
while read z type hosts; do
|
|
|
|
if [ "$z" = "$zone" ]; then
|
|
|
|
for h in $hostlist; do
|
|
|
|
list_search $h $hosts
|
|
|
|
if [ "$?" -gt 0 ]; then
|
|
|
|
newhostlist="$newhostlist $h"
|
|
|
|
else
|
|
|
|
error_message "$h already in zone $zone"
|
|
|
|
fi
|
|
|
|
done
|
2006-01-17 21:03:00 +01:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
[ -z "$hosts" ] && hosts=$newhostlist || hosts="$hosts $newhostlist"
|
|
|
|
fi
|
2006-01-17 21:03:00 +01:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
eval ${z}_hosts=\"$hosts\"
|
2006-01-17 21:03:00 +01:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
echo "$z $type $hosts" >> ${VARDIR}/zones_$$
|
|
|
|
done < ${VARDIR}/zones
|
2006-01-17 21:03:00 +01:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
mv -f ${VARDIR}/zones_$$ ${VARDIR}/zones
|
2006-01-17 21:03:00 +01:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
TERMINATOR=fatal_error
|
2006-01-23 00:41:56 +01:00
|
|
|
#
|
2006-08-27 19:27:48 +02:00
|
|
|
# Create a new Zone state file
|
2006-01-23 00:41:56 +01:00
|
|
|
#
|
2006-08-27 19:27:48 +02:00
|
|
|
for newhost in $newhostlist; do
|
|
|
|
#
|
|
|
|
# Isolate interface and host parts
|
|
|
|
#
|
|
|
|
interface=${newhost%%:*}
|
|
|
|
host=${newhost#*:}
|
|
|
|
#
|
|
|
|
# If the zone passed in the command has a dnat chain then insert a rule in
|
|
|
|
# the nat table PREROUTING chain to jump to that chain when the source
|
|
|
|
# matches the new host(s)#
|
|
|
|
#
|
|
|
|
chain=${zone}_dnat
|
|
|
|
|
|
|
|
if nat_chain_exists $chain; then
|
|
|
|
do_iptables -t nat -A $(dynamic_in $interface) $(source_ip_range $host) $(match_ipsec_in $zone $newhost) -j $chain
|
|
|
|
fi
|
|
|
|
#
|
|
|
|
# Insert new rules into the filter table for the passed interface
|
|
|
|
#
|
|
|
|
while read z1 z2 chain; do
|
|
|
|
[ "$z1" = "$z2" ] && op="-I" || op="-A"
|
|
|
|
if [ "$z1" = "$zone" ]; then
|
|
|
|
if [ "$z2" = "$FW" ]; then
|
|
|
|
do_iptables $op $(dynamic_in $interface) $(match_source_hosts $host) $(match_ipsec_in $z1 $newhost) -j $chain
|
|
|
|
else
|
|
|
|
source_chain=$(dynamic_fwd $interface)
|
|
|
|
if is_ipsec_host $z1 $newhost ; then
|
|
|
|
do_iptables $op $source_chain $(match_source_hosts $host) $(match_ipsec_in $z1 $newhost) -j ${z1}_frwd
|
|
|
|
else
|
|
|
|
eval dest_hosts=\"\$${z2}_hosts\"
|
2006-08-22 22:20:42 +02:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
for h in $dest_hosts; do
|
|
|
|
iface=${h%%:*}
|
|
|
|
hosts=${h#*:}
|
2006-01-17 21:03:00 +01:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
if [ "$iface" != "$interface" -o "$hosts" != "$host" ]; then
|
|
|
|
do_iptables $op $source_chain $(match_source_hosts $host) -o $iface $(match_dest_hosts $hosts) $(match_ipsec_out $z2 $h) -j $chain
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
elif [ "$z2" = "$zone" ]; then
|
|
|
|
if [ "$z1" = "$FW" ]; then
|
|
|
|
#
|
|
|
|
# Add a rule to the dynamic out chain for the interface
|
|
|
|
#
|
|
|
|
do_iptables $op $(dynamic_out $interface) $(match_dest_hosts $host) $(match_ipsec_out $z2 $newhost) -j $chain
|
|
|
|
else
|
|
|
|
eval source_hosts=\"\$${z1}_hosts\"
|
2006-01-17 21:03:00 +01:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
for h in $source_hosts; do
|
|
|
|
iface=${h%%:*}
|
|
|
|
hosts=${h#*:}
|
2006-01-17 21:03:00 +01:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
if [ "$iface" != "$interface" -o "$hosts" != "$host" ]; then
|
|
|
|
if is_ipsec_host $z1 $h; then
|
|
|
|
do_iptables $op ${z1}_dyn -o $interface $(match_dest_hosts $host) $(match_ipsec_out $z2 $newhost) -j $chain
|
|
|
|
else
|
|
|
|
do_iptables $op $(dynamic_fwd $iface) $(match_source_hosts $hosts) -o $interface $(match_dest_hosts $host) $(match_ipsec_out $z2 $newhost) -j $chain
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done < ${VARDIR}/chains
|
2006-05-06 18:15:33 +02:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
progress_message "$newhost added to zone $zone"
|
2006-03-13 01:50:29 +01:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
done
|
2006-01-17 21:03:00 +01:00
|
|
|
|
2006-01-23 00:41:56 +01:00
|
|
|
rm -rf $TMP_DIR
|
|
|
|
}
|
2006-01-17 21:03:00 +01:00
|
|
|
|
2002-10-23 18:48:40 +02:00
|
|
|
#
|
2006-08-27 19:27:48 +02:00
|
|
|
# Delete a host or networks from a zone
|
2002-10-23 18:48:40 +02:00
|
|
|
#
|
2006-08-27 19:27:48 +02:00
|
|
|
delete_from_zone() # $1 = <interface>[:<hosts>] $2 = zone
|
2002-05-01 01:13:15 +02:00
|
|
|
{
|
2006-08-27 19:27:48 +02:00
|
|
|
local interface host zone z h z1 z2 chain delhost
|
|
|
|
local dhcp_interfaces blacklist_interfaces maclist_interfaces tcpflags_interfaces
|
|
|
|
local rulenum source_chain dest_hosts iface hosts hostlist=
|
2002-05-01 01:13:15 +02:00
|
|
|
|
|
|
|
#
|
2006-08-27 19:27:48 +02:00
|
|
|
# Load $zones
|
2003-02-23 15:10:37 +01:00
|
|
|
#
|
2006-08-27 19:27:48 +02:00
|
|
|
determine_zones
|
2003-02-23 15:10:37 +01:00
|
|
|
#
|
2006-08-27 19:27:48 +02:00
|
|
|
# Validate Interfaces File
|
2002-05-01 01:13:15 +02:00
|
|
|
#
|
2006-08-27 19:27:48 +02:00
|
|
|
validate_interfaces_file
|
2003-07-22 16:25:36 +02:00
|
|
|
#
|
2006-08-27 19:27:48 +02:00
|
|
|
# Validate Hosts File
|
2005-07-09 06:45:32 +02:00
|
|
|
#
|
2006-08-27 19:27:48 +02:00
|
|
|
validate_hosts_file
|
2005-07-09 06:45:32 +02:00
|
|
|
#
|
2006-08-27 19:27:48 +02:00
|
|
|
# Validate IPSec File
|
2003-07-22 16:25:36 +02:00
|
|
|
#
|
2006-08-27 19:27:48 +02:00
|
|
|
f=$(find_file ipsec)
|
2005-07-09 06:45:32 +02:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
[ -f $f ] && setup_ipsec $f
|
2006-01-20 22:41:03 +01:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
#
|
|
|
|
# Normalize host list
|
|
|
|
#
|
|
|
|
while [ $# -gt 1 ]; do
|
|
|
|
interface=${1%%:*}
|
|
|
|
host=${1#*:}
|
|
|
|
#
|
|
|
|
# Be sure that the interface was dynamic at last [re]start
|
|
|
|
#
|
|
|
|
if ! chain_exists $(input_chain $interface) ; then
|
|
|
|
startup_error "Unknown interface $interface"
|
|
|
|
fi
|
2005-07-09 07:45:05 +02:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
if ! chain_exists $(dynamic_in $interface) ; then
|
|
|
|
startup_error "At last Shorewall [re]start, DYNAMIC_ZONES=No in shorewall.conf"
|
|
|
|
fi
|
2005-07-09 07:45:05 +02:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
if [ -z "$host" ]; then
|
|
|
|
hostlist="$hostlist $interface:0.0.0.0/0"
|
2006-01-20 22:41:03 +01:00
|
|
|
else
|
2006-08-27 19:27:48 +02:00
|
|
|
for h in $(separate_list $host); do
|
|
|
|
hostlist="$hostlist $interface:$h"
|
|
|
|
done
|
2006-01-20 22:41:03 +01:00
|
|
|
fi
|
2005-07-09 07:45:05 +02:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
shift
|
|
|
|
done
|
|
|
|
#
|
|
|
|
# Validate Zone
|
|
|
|
#
|
|
|
|
zone=$1
|
2005-08-02 18:46:30 +02:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
validate_zone $zone || startup_error "Unknown zone: $zone"
|
2005-08-02 18:46:30 +02:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
[ "$zone" = $FW ] && startup_error "Can't delete from the firewall zone"
|
2002-10-22 20:07:52 +02:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
#
|
|
|
|
# Be sure that Shorewall has been restarted using a DZ-aware version of the code
|
|
|
|
#
|
|
|
|
[ -f ${VARDIR}/chains ] || startup_error "${VARDIR}/chains -- file not found"
|
|
|
|
[ -f ${VARDIR}/zones ] || startup_error "${VARDIR}/zones -- file not found"
|
|
|
|
#
|
|
|
|
# Delete the passed hosts from the zone state file
|
|
|
|
#
|
|
|
|
> ${VARDIR}/zones_$$
|
|
|
|
|
|
|
|
while read z hosts; do
|
|
|
|
if [ "$z" = "$zone" ]; then
|
|
|
|
temp=$hosts
|
|
|
|
hosts=
|
|
|
|
|
|
|
|
for host in $hostlist; do
|
|
|
|
found=
|
|
|
|
for h in $temp; do
|
|
|
|
if [ "$h" = "$host" ]; then
|
|
|
|
found=Yes
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
2002-11-10 22:34:20 +01:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
[ -n "$found" ] || error_message "WARNING: $host does not appear to be in zone $zone"
|
|
|
|
done
|
2005-07-09 06:45:32 +02:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
for h in $temp; do
|
|
|
|
found=
|
|
|
|
for host in $hostlist; do
|
|
|
|
if [ "$h" = "$host" ]; then
|
|
|
|
found=Yes
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
2005-08-02 18:46:30 +02:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
[ -n "$found" ] || hosts="$hosts $h"
|
|
|
|
done
|
2003-05-22 22:37:24 +02:00
|
|
|
fi
|
2003-05-28 21:20:23 +02:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
eval ${z}_hosts=\"$hosts\"
|
|
|
|
|
|
|
|
echo "$z $hosts" >> ${VARDIR}/zones_$$
|
|
|
|
done < ${VARDIR}/zones
|
|
|
|
|
|
|
|
mv -f ${VARDIR}/zones_$$ ${VARDIR}/zones
|
|
|
|
|
|
|
|
TERMINATOR=fatal_error
|
|
|
|
|
|
|
|
for delhost in $hostlist; do
|
|
|
|
interface=${delhost%%:*}
|
|
|
|
host=${delhost#*:}
|
|
|
|
#
|
|
|
|
# Delete any nat table entries for the host(s)
|
|
|
|
#
|
|
|
|
qt_iptables -t nat -D $(dynamic_in $interface) $(match_source_hosts $host) $(match_ipsec_in $zone $delhost) -j ${zone}_dnat
|
|
|
|
#
|
|
|
|
# Delete rules rules the input chains for the passed interface
|
|
|
|
#
|
|
|
|
while read z1 z2 chain; do
|
|
|
|
if [ "$z1" = "$zone" ]; then
|
|
|
|
if [ "$z2" = "$FW" ]; then
|
|
|
|
qt_iptables -D $(dynamic_in $interface) $(match_source_hosts $host) $(match_ipsec_in $z1 $delhost) -j $chain
|
|
|
|
else
|
|
|
|
source_chain=$(dynamic_fwd $interface)
|
|
|
|
if is_ipsec_host $z1 $delhost ; then
|
|
|
|
qt_iptables -D $source_chain $(match_source_hosts $host) $(match_ipsec_in $z1 $newhost) -j ${z1}_frwd
|
|
|
|
else
|
|
|
|
eval dest_hosts=\"\$${z2}_hosts\"
|
2005-10-09 17:47:47 +02:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
[ "$z2" = "$zone" ] && dest_hosts="$dest_hosts $hostlist"
|
2005-10-08 00:16:03 +02:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
for h in $dest_hosts; do
|
|
|
|
iface=${h%%:*}
|
|
|
|
hosts=${h#*:}
|
2005-07-26 01:08:09 +02:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
if [ "$iface" != "$interface" -o "$hosts" != "$host" ]; then
|
|
|
|
qt_iptables -D $source_chain $(match_source_hosts $host) -o $iface $(match_dest_hosts $hosts) $(match_ipsec_out $z2 $h) -j $chain
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
elif [ "$z2" = "$zone" ]; then
|
|
|
|
if [ "$z1" = "$FW" ]; then
|
|
|
|
qt_iptables -D $(dynamic_out $interface) $(match_dest_hosts $host) $(match_ipsec_out $z2 $delhost) -j $chain
|
|
|
|
else
|
|
|
|
eval source_hosts=\"\$${z1}_hosts\"
|
|
|
|
|
|
|
|
for h in $source_hosts; do
|
|
|
|
iface=${h%%:*}
|
|
|
|
hosts=${h#*:}
|
|
|
|
|
|
|
|
if [ "$iface" != "$interface" -o "$hosts" != "$host" ]; then
|
|
|
|
if is_ipsec_host $z1 $h; then
|
|
|
|
qt_iptables -D ${z1}_dyn -o $interface $(match_dest_hosts $host) $(match_ipsec_out $z2 $delhost) -j $chain
|
|
|
|
else
|
|
|
|
qt_iptables -D $(dynamic_fwd $iface) $(match_source_hosts $hosts) -o $interface $(match_dest_hosts $host) $(match_ipsec_out $z2 $delhost) -j $chain
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done < ${VARDIR}/chains
|
2003-06-27 23:02:52 +02:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
progress_message "$delhost removed from zone $zone"
|
2005-07-09 06:45:32 +02:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
done
|
2006-04-11 00:52:10 +02:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
rm -rf $TMP_DIR
|
2002-05-01 01:13:15 +02:00
|
|
|
}
|
|
|
|
|
2002-10-23 18:48:40 +02:00
|
|
|
#
|
|
|
|
# Give Usage Information
|
|
|
|
#
|
2002-05-01 01:13:15 +02:00
|
|
|
usage() {
|
2006-08-27 19:27:48 +02:00
|
|
|
echo "Usage: $0 [debug] {start|stop|reset|restart|clear}"
|
2002-05-01 01:13:15 +02:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2002-10-23 18:48:40 +02:00
|
|
|
#
|
|
|
|
# E X E C U T I O N B E G I N S H E R E
|
|
|
|
#
|
2002-05-01 01:13:15 +02:00
|
|
|
#
|
|
|
|
# Start trace if first arg is "debug"
|
|
|
|
#
|
|
|
|
[ $# -gt 1 ] && [ "$1" = "debug" ] && { set -x ; shift ; }
|
|
|
|
|
2006-01-17 18:34:34 +01:00
|
|
|
NOLOCK=
|
2002-05-01 01:13:15 +02:00
|
|
|
|
2006-01-17 18:34:34 +01:00
|
|
|
[ $# -gt 1 ] && [ "$1" = "nolock" ] && { NOLOCK=Yes; shift ; }
|
2002-05-01 01:13:15 +02:00
|
|
|
|
2002-07-30 01:53:26 +02:00
|
|
|
trap "my_mutex_off; exit 2" 1 2 3 4 5 6 9
|
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
SHAREDIR=/usr/share/shorewall
|
|
|
|
VARDIR=/var/lib/shorewall
|
|
|
|
CONFDIR=/etc/shorewall
|
|
|
|
|
|
|
|
FUNCTIONS=${SHAREDIR}/functions
|
|
|
|
|
|
|
|
if [ -f $FUNCTIONS ]; then
|
|
|
|
[ $VERBOSE -ge 2 ] && echo "Loading $FUNCTIONS..."
|
|
|
|
. $FUNCTIONS
|
|
|
|
else
|
|
|
|
startup_error "$FUNCTIONS does not exist!"
|
|
|
|
fi
|
|
|
|
|
|
|
|
PROGRAM=firewall
|
|
|
|
|
2005-07-09 06:45:32 +02:00
|
|
|
COMMAND="$1"
|
2002-05-01 01:13:15 +02:00
|
|
|
|
2005-07-09 06:45:32 +02:00
|
|
|
case "$COMMAND" in
|
2002-05-01 01:13:15 +02:00
|
|
|
stop)
|
2002-10-01 22:54:42 +02:00
|
|
|
[ $# -ne 1 ] && usage
|
2002-05-01 01:13:15 +02:00
|
|
|
do_initialize
|
|
|
|
my_mutex_on
|
2003-07-28 19:32:41 +02:00
|
|
|
#
|
|
|
|
# Don't want to do a 'stop' when startup is disabled
|
|
|
|
#
|
2005-08-02 18:46:30 +02:00
|
|
|
check_disabled_startup
|
2006-01-25 01:13:45 +01:00
|
|
|
progress_message3 "Stopping Shorewall..."
|
2002-05-01 01:13:15 +02:00
|
|
|
stop_firewall
|
|
|
|
[ -n "$SUBSYSLOCK" ] && rm -f $SUBSYSLOCK
|
2006-01-25 01:13:45 +01:00
|
|
|
progress_message3 "done."
|
2002-05-01 01:13:15 +02:00
|
|
|
my_mutex_off
|
|
|
|
;;
|
2002-05-30 14:55:47 +02:00
|
|
|
|
2002-05-01 01:13:15 +02:00
|
|
|
reset)
|
2002-10-01 22:54:42 +02:00
|
|
|
[ $# -ne 1 ] && usage
|
2002-10-30 16:56:46 +01:00
|
|
|
do_initialize
|
|
|
|
my_mutex_on
|
2005-08-01 22:35:28 +02:00
|
|
|
if ! shorewall_is_started ; then
|
2002-10-30 16:56:46 +01:00
|
|
|
echo "Shorewall Not Started"
|
|
|
|
[ -n "$TMP_DIR" ] && rm -rf $TMP_DIR
|
|
|
|
my_mutex_off
|
|
|
|
exit 2;
|
|
|
|
fi
|
2005-07-09 07:45:05 +02:00
|
|
|
$IPTABLES -Z
|
|
|
|
$IPTABLES -t nat -Z
|
|
|
|
$IPTABLES -t mangle -Z
|
2002-05-03 00:56:27 +02:00
|
|
|
report "Shorewall Counters Reset"
|
2006-06-09 18:35:55 +02:00
|
|
|
date > ${VARDIR}/restarted
|
2002-10-30 16:56:46 +01:00
|
|
|
my_mutex_off
|
2002-05-01 01:13:15 +02:00
|
|
|
;;
|
2002-05-30 14:55:47 +02:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
clear)
|
2002-10-01 22:54:42 +02:00
|
|
|
[ $# -ne 1 ] && usage
|
2002-05-01 01:13:15 +02:00
|
|
|
do_initialize
|
|
|
|
my_mutex_on
|
2006-08-27 19:27:48 +02:00
|
|
|
progress_message3 "Clearing Shorewall..."
|
|
|
|
clear_firewall
|
|
|
|
[ -n "$SUBSYSLOCK" ] && rm -f $SUBSYSLOCK
|
|
|
|
progress_message3 "done."
|
|
|
|
my_mutex_off
|
|
|
|
;;
|
|
|
|
|
|
|
|
add)
|
|
|
|
[ $# -lt 3 ] && usage
|
|
|
|
do_initialize
|
|
|
|
my_mutex_on
|
2005-08-01 22:35:28 +02:00
|
|
|
if ! shorewall_is_started ; then
|
2006-08-27 19:27:48 +02:00
|
|
|
echo "Shorewall Not Started"
|
2002-09-29 23:28:44 +02:00
|
|
|
[ -n "$TMP_DIR" ] && rm -rf $TMP_DIR
|
2002-05-01 01:13:15 +02:00
|
|
|
my_mutex_off
|
|
|
|
exit 2;
|
2002-07-06 00:24:40 +02:00
|
|
|
fi
|
2006-08-27 19:27:48 +02:00
|
|
|
shift
|
|
|
|
add_to_zone $@
|
2002-05-01 01:13:15 +02:00
|
|
|
my_mutex_off
|
|
|
|
;;
|
2002-05-30 14:55:47 +02:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
delete)
|
|
|
|
[ $# -lt 3 ] && usage
|
2002-05-01 01:13:15 +02:00
|
|
|
do_initialize
|
|
|
|
my_mutex_on
|
2006-08-27 19:27:48 +02:00
|
|
|
if ! shorewall_is_started ; then
|
|
|
|
echo "Shorewall Not Started"
|
|
|
|
[ -n "$TMP_DIR" ] && rm -rf $TMP_DIR
|
|
|
|
my_mutex_off
|
|
|
|
exit 2;
|
|
|
|
fi
|
|
|
|
shift
|
|
|
|
delete_from_zone $@
|
2002-05-01 01:13:15 +02:00
|
|
|
my_mutex_off
|
|
|
|
;;
|
2002-05-30 14:55:47 +02:00
|
|
|
|
2006-01-12 00:30:33 +01:00
|
|
|
call)
|
2003-07-05 19:55:43 +02:00
|
|
|
#
|
2006-06-09 18:35:55 +02:00
|
|
|
# Undocumented way to call functions in ${SHAREDIR}/firewall directly
|
2003-07-05 19:55:43 +02:00
|
|
|
#
|
2006-01-05 00:34:07 +01:00
|
|
|
shift
|
2003-07-05 19:55:43 +02:00
|
|
|
do_initialize
|
2003-07-05 21:52:34 +02:00
|
|
|
EMPTY=
|
2003-07-05 19:55:43 +02:00
|
|
|
$@
|
|
|
|
;;
|
2005-07-09 07:55:29 +02:00
|
|
|
|
2002-05-01 01:13:15 +02:00
|
|
|
*)
|
|
|
|
usage
|
|
|
|
;;
|
2002-05-30 14:55:47 +02:00
|
|
|
|
2002-05-01 01:13:15 +02:00
|
|
|
esac
|