2002-05-01 01:13:15 +02:00
#!/bin/sh
#
2006-01-16 16:15:43 +01:00
# Shorewall Packet Filtering Firewall Control Program - 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)
2002-05-01 01:13:15 +02:00
#
2002-07-06 00:24:40 +02:00
# This file should be placed in /sbin/shorewall.
2002-05-01 01:13:15 +02:00
#
2002-07-06 00:24:40 +02:00
# Shorewall documentation is available at http://shorewall.sourceforge.net
2002-05-01 01:13:15 +02:00
#
2002-07-06 00:24:40 +02:00
# 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-07-06 00:24:40 +02:00
# as published by the Free Software Foundation.
2002-05-01 01:13:15 +02:00
#
2002-07-06 00:24:40 +02:00
# 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.
2002-05-01 01:13:15 +02:00
#
2002-07-06 00:24:40 +02:00
# 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
2003-02-23 15:10:37 +01:00
#
2002-07-06 00:24:40 +02:00
# If an error occurs while starting or restarting the firewall, the
# firewall is automatically stopped.
2002-05-01 01:13:15 +02:00
#
2002-07-06 00:24:40 +02:00
# The firewall uses configuration files in /etc/shorewall/ - skeleton
# files is included with the firewall.
2002-05-01 01:13:15 +02:00
#
2002-07-06 00:24:40 +02:00
# Commands are:
2002-05-01 01:13:15 +02:00
#
2005-07-28 16:37:56 +02:00
# shorewall dump Dumps all Shorewall-related information
# for problem analysis
2005-07-09 07:45:05 +02:00
# shorewall start Starts the firewall
2002-07-06 00:24:40 +02:00
# shorewall restart Restarts the firewall
# shorewall stop Stops the firewall
2003-02-23 15:10:37 +01:00
# shorewall status Displays firewall status
2002-07-06 00:24:40 +02:00
# shorewall reset Resets iptables packet and
# byte counts
# shorewall clear Open the floodgates by
# removing all iptables rules
# and setting the three permanent
# chain policies to ACCEPT
2002-05-01 01:13:15 +02:00
# shorewall refresh Rebuild the common chain to
# compensate for a change of
# broadcast address on any "detect"
# interface.
2006-06-17 19:17:45 +02:00
# shorewall [re]load [ <directory> ] <system>
# Compile a script and install it on a
# remote Shorewall Lite system.
2003-08-15 02:59:06 +02:00
# shorewall show <chain> [ <chain> ... ] Display the rules in each <chain> listed
2005-07-24 18:27:21 +02:00
# shorewall show actions Displays the available actions
2002-07-06 00:24:40 +02:00
# shorewall show log Print the last 20 log messages
# shorewall show connections Show the kernel's connection
# tracking table
# shorewall show nat Display the rules in the nat table
# shorewall show {mangle|tos} Display the rules in the mangle table
# shorewall show tc Display traffic control info
2002-12-10 21:42:19 +01:00
# shorewall show classifiers Display classifiers
2005-07-09 07:45:05 +02:00
# shorewall show capabilities Display iptables/kernel capabilities
2002-05-01 01:13:15 +02:00
# shorewall version Display the installed version id
2003-02-27 23:28:06 +01:00
# shorewall check Verify the more heavily-used
# configuration files.
2002-07-06 00:24:40 +02:00
# shorewall try <directory> [ <timeout> ] Try a new configuration and if
# it doesn't work, revert to the
# standard one. If a timeout is supplied
2002-05-01 01:13:15 +02:00
# the command reverts back to the
# standard configuration after that many
# seconds have elapsed after successfully
# starting the new configuration.
2002-06-04 17:08:50 +02:00
# shorewall logwatch [ refresh-interval ] Monitor the local log for Shorewall
# messages.
2002-07-06 00:24:40 +02:00
# shorewall drop <address> ... Temporarily drop all packets from the
2002-06-04 22:17:46 +02:00
# listed address(es)
2002-07-06 00:24:40 +02:00
# shorewall reject <address> ... Temporarily reject all packets from the
2002-06-04 22:17:46 +02:00
# listed address(es)
2003-02-23 15:10:37 +01:00
# shorewall allow <address> ... Reenable address(es) previously
2002-06-04 22:58:53 +02:00
# disabled with "drop" or "reject"
2005-07-09 06:45:32 +02:00
# shorewall save [ <file> ] Save the list of "rejected" and
2002-06-04 22:58:53 +02:00
# "dropped" addresses so that it will
# be automatically reinstated the
2002-06-11 22:14:58 +02:00
# next time that Shorewall starts.
2005-07-09 06:45:32 +02:00
# Save the current state so that 'shorewall
# restore' can be used.
#
# shorewall forget [ <file> ] Discard the data saved by 'shorewall save'
#
# shorewall restore [ <file> ] Restore the state of the firewall from
# previously saved information.
2002-05-01 01:13:15 +02:00
#
2005-12-03 00:58:57 +01:00
# shorewall ipaddr { <address>/<cidr> | <address> <netmask> }
2003-07-05 19:14:21 +02:00
#
# Displays information about the network
# defined by the argument[s]
2003-07-06 15:24:23 +02:00
#
# shorewall iprange <address>-<address> Decomposes a range of IP addresses into
# a list of network/host addresses.
#
2005-12-03 00:58:57 +01:00
# shorewall ipdecimal { <address> | <integer> }
#
# Displays the decimal equivalent of an IP
# address and vice versa.
#
2005-07-09 07:55:29 +02:00
# shorewall safe-start Starts the firewall and promtp for a c
2005-08-02 18:46:30 +02:00
# confirmation to accept or reject the new
2005-07-09 07:55:29 +02:00
# configuration
#
2005-08-02 18:46:30 +02:00
# shorewall safe-restart Restarts the firewall and prompt for a
# confirmation to accept or reject the new
2005-07-09 07:55:29 +02:00
# configuration
#
2006-06-16 23:43:55 +02:00
# shorewall compile [ -e ] [ <directory> ] <filename>
2006-02-03 16:10:46 +01:00
# Compile a firewall program file.
2006-01-07 02:08:23 +01:00
#
2003-07-06 15:24:23 +02:00
# Fatal Error
#
fatal_error() # $@ = Message
{
echo " $@" >&2
exit 2
}
2002-05-01 01:13:15 +02:00
# Display a chain if it exists
#
2003-02-25 17:21:41 +01:00
2002-05-01 01:13:15 +02:00
showfirstchain() # $1 = name of chain
{
awk \
2002-07-06 00:24:40 +02:00
'BEGIN {prnt=0; rslt=1; }; \
/^$/ { next; };\
/^Chain/ {if ( prnt == 1 ) { rslt=0; exit 0; }; };\
2002-05-01 01:13:15 +02:00
/Chain '$1'/ { prnt=1; }; \
2002-07-06 00:24:40 +02:00
{ if (prnt == 1) print; };\
2005-07-09 06:45:32 +02:00
END { exit rslt; }' $TMPFILE
2002-05-01 01:13:15 +02:00
}
showchain() # $1 = name of chain
{
if [ "$firstchain" = "Yes" ]; then
2002-05-30 14:55:47 +02:00
if showfirstchain $1; then
firstchain=
fi
2002-05-01 01:13:15 +02:00
else
awk \
2002-07-06 00:24:40 +02:00
'BEGIN {prnt=0;};\
/^$|^ pkts/ { next; };\
/^Chain/ {if ( prnt == 1 ) exit; };\
/Chain '$1'/ { prnt=1; };\
2005-07-09 06:45:32 +02:00
{ if (prnt == 1) print; }' $TMPFILE
2002-05-01 01:13:15 +02:00
fi
}
2005-07-09 07:45:05 +02:00
#
2005-07-09 07:55:29 +02:00
# The 'awk' hack that compensates for bugs in iptables-save (or rather in the extension modules).
2005-07-09 07:45:05 +02:00
#
iptablesbug()
{
2005-07-27 22:30:16 +02:00
if qt mywhich awk ; then
2006-05-11 16:52:00 +02:00
awk 'BEGIN { sline=""; };\
2005-07-09 07:45:05 +02:00
/^-j/ { print sline $0; next };\
/-m policy.*-j/ { print $0; next };\
/-m policy/ { sline=$0; next };\
2005-07-09 07:55:29 +02:00
/--mask ff/ { sub( /--mask ff/, "--mask 0xff" ) };\
2006-05-11 16:52:00 +02:00
{ print ; sline="" }'
2005-07-09 07:45:05 +02:00
else
2005-07-26 01:08:09 +02:00
echo " WARNING: You don't have 'awk' on this system so the output of the save command may be unusable" >&2
2005-07-09 07:45:05 +02:00
cat
fi
}
2005-07-09 06:45:32 +02:00
#
# Validate the value of RESTOREFILE
#
validate_restorefile() # $* = label
{
case $RESTOREFILE in
*/*)
2006-01-26 00:58:12 +01:00
error_message "ERROR: $@ must specify a simple file name: $RESTOREFILE"
exit 2
;;
.*)
error_message "ERROR: Reserved File Name: $RESTOREFILE"
2005-07-09 06:45:32 +02:00
exit 2
;;
2005-08-02 18:46:30 +02:00
esac
2005-07-09 06:45:32 +02:00
}
2002-10-23 18:48:40 +02:00
#
# Set the configuration variables from shorewall.conf
#
2002-05-01 01:13:15 +02:00
get_config() {
2006-06-16 23:43:55 +02:00
if [ -z "$EXPORT" -a "$(whoami)" = root ]; then
2006-06-17 00:40:36 +02:00
#
# This block is avoided for compile for export and when the user isn't root
#
2006-06-17 00:19:18 +02:00
export CONFIG_PATH
2006-06-17 19:17:45 +02:00
2006-06-16 23:43:55 +02:00
[ -z "$LOGFILE" ] && LOGFILE=/var/log/messages
2002-05-01 01:13:15 +02:00
2006-06-16 23:43:55 +02:00
if [ ! -f $LOGFILE ]; then
echo "LOGFILE ($LOGFILE) does not exist!" >&2
exit 2
fi
2006-06-17 19:17:45 +02:00
2006-06-16 23:43:55 +02:00
if [ -n "$IPTABLES" ]; then
if [ ! -e "$IPTABLES" ]; then
echo " ERROR: The program specified in IPTABLES does not exist or is not executable" >&2
exit 2
fi
else
IPTABLES=$(mywhich iptables 2> /dev/null)
if [ -z "$IPTABLES" ] ; then
echo " ERROR: Can't find iptables executable" >&2
exit 2
fi
fi
2006-06-17 19:17:45 +02:00
2006-06-16 23:43:55 +02:00
export IPTABLES
2006-06-17 19:17:45 +02:00
2006-06-16 23:43:55 +02:00
#
# See if we have a real version of "tail" -- use separate redirection so
# that ash (aka /bin/sh on LRP) doesn't crap
#
if ( tail -n5 $LOGFILE > /dev/null 2> /dev/null ) ; then
realtail="Yes"
else
realtail=""
fi
2006-06-17 00:40:36 +02:00
#
# Compile by non-root needs no restore file
#
2006-06-16 23:43:55 +02:00
[ -n "$RESTOREFILE" ] || RESTOREFILE=restore
validate_restorefile RESTOREFILE
export RESTOREFILE
2006-06-17 19:17:45 +02:00
2006-06-16 23:43:55 +02:00
case $STARTUP_ENABLED in
No|no|NO)
echo " WARNING: Shorewall startup is disabled. To enable startup, set STARTUP_ENABLED=Yes in ${CONFDIR}/shorewall.conf" >&2
STARTUP_ENABLED=
;;
Yes|yes|YES)
;;
*)
if [ -n "$STARTUP_ENABLED" ]; then
echo " ERROR: Invalid Value for STARTUP_ENABLE: $STARTUP_ENABLED" >&2
exit 2
fi
;;
esac
2006-06-17 19:17:45 +02:00
2006-06-16 23:43:55 +02:00
case ${TC_ENABLED:=Internal} in
No|NO|no)
TC_ENABLED=
;;
esac
2006-06-08 23:49:34 +02:00
2006-06-17 00:40:36 +02:00
[ -n "LOGFORMAT" ] && LOGFORMAT="${LOGFORMAT%%%*}"
2006-06-17 19:17:45 +02:00
2006-06-17 00:40:36 +02:00
[ -n "$LOGFORMAT" ] || LOGFORMAT="Shorewall:"
export LOGFORMAT
2006-06-16 23:43:55 +02:00
2006-06-17 00:40:36 +02:00
fi
2006-06-08 23:49:34 +02:00
2003-06-28 17:22:22 +02:00
if [ -n "$SHOREWALL_SHELL" ]; then
if [ ! -e "$SHOREWALL_SHELL" ]; then
2005-07-09 06:45:32 +02:00
echo " ERROR: The program specified in SHOREWALL_SHELL does not exist or is not executable" >&2
2003-06-28 17:22:22 +02:00
exit 2
fi
fi
2005-07-09 06:45:32 +02:00
2006-01-24 18:44:19 +01:00
[ -n "${VERBOSITY:=2}" ]
2006-03-24 00:26:41 +01:00
VERBOSE=$(($VERBOSE_OFFSET + $VERBOSITY))
2006-01-24 18:44:19 +01:00
export VERBOSE
2006-01-24 16:41:38 +01:00
2002-05-01 01:13:15 +02:00
}
2006-07-15 18:22:55 +02:00
#
# Determine the value for a parameter that defaults to Yes
#
added_param_value_yes() # $1 = Parameter Name, $2 = Parameter value
{
local val="$2"
if [ -z "$val" ]; then
echo "Yes"
else case $val in
[Yy][Ee][Ss])
echo "Yes"
;;
[Nn][Oo])
echo ""
;;
*)
fatal_error "Invalid value ($val) for $1"
;;
esac
fi
}
#
# Determine the value for a parameter that defaults to No
#
added_param_value_no() # $1 = Parameter Name, $2 = Parameter value
{
local val="$2"
if [ -z "$val" ]; then
echo ""
else case $val in
[Yy][Ee][Ss])
echo "Yes"
;;
[Nn][Oo])
echo ""
;;
*)
fatal_error "Invalid value ($val) for $1"
;;
esac
fi
}
#
# Process the shell-style configuration files that set variables needed by the compiler
# To allow the compiler to be rewritten in a language other than Bourne Shell, we need
# to pass all of those setting to the compiler in environmental variables
#
do_initialize() {
#
# Generate a sequence of 'export' commands corresponding to the variables set in
# the user's params file.
#
export_params() {
f=$(find_file params)
if [ -f $f ]; then
read_file $f 0 | cut -d'#' -f1 | grep -v '^[[:space:]]*$' | while read line; do
case $line in
*=*)
echo export ${line%=*}
;;
esac
done
fi
}
# Run all utility programs using the C locale
#
# Thanks to Vincent Planchenault for this tip #
export LC_ALL=C
# Make sure umask is sane
umask 077
#
# Establish termination function
#
TERMINATOR=fatal_error
#
# Clear all configuration variables
#
IPTABLES=
FW=
SUBSYSLOCK=
LOGRATE=
LOGBURST=
LOGPARMS=
LOGLIMIT=
ADD_IP_ALIASES=
ADD_SNAT_ALIASES=
TC_ENABLED=
BLACKLIST_DISPOSITION=
BLACKLIST_LOGLEVEL=
CLAMPMSS=
ROUTE_FILTER=
LOG_MARTIANS=
DETECT_DNAT_IPADDRS=
MUTEX_TIMEOUT=
FORWARDPING=
MACLIST_DISPOSITION=
MACLIST_LOG_LEVEL=
TCP_FLAGS_DISPOSITION=
TCP_FLAGS_LOG_LEVEL=
RFC1918_LOG_LEVEL=
MARK_IN_FORWARD_CHAIN=
LOGFORMAT=
LOGRULENUMBERS=
ADMINISABSENTMINDED=
BLACKLISTNEWONLY=
MODULE_SUFFIX=
SMURF_LOG_LEVEL=
DISABLE_IPV6=
BRIDGING=
PKTTYPE=
RETAIN_ALIASES=
DELAYBLACKLISTLOAD=
LOGTAGONLY=
LOGALLNEW=
RFC1918_STRICT=
MACLIST_TTL=
SAVE_IPSETS=
RESTOREFILE=
MAPOLDACTIONS=
IMPLICIT_CONTINUE=
HIGH_ROUTE_MARKS=
IPSECFILE=
CLEAR_TC=
FASTACCEPT=
run_user_exit params
config=$(find_file shorewall.conf)
if [ -f $config ]; then
if [ -r $config ]; then
progress_message "Processing $config..."
. $config
else
fatal_error "Cannot read $config (Hint: Are you root?)"
fi
else
fatal_error "$config does not exist!"
fi
#
# Restore CONFIG_PATH if the shorewall.conf file cleared it
#
ensure_config_path
#
# Determine the capabilities of the installed iptables/netfilter
# We load the kernel modules here to accurately determine
# capabilities when module autoloading isn't enabled.
#
PKTTYPE=$(added_param_value_no PKTTYPE $PKTTYPE)
[ -n "${MODULE_SUFFIX:=o gz ko o.gz ko.gz}" ]
if [ -z "$EXPORT" -a "$(whoami)" = root ]; then
load_kernel_modules
if [ -z "$IPTABLES" ]; then
IPTABLES=$(mywhich iptables 2> /dev/null)
[ -z "$IPTABLES" ] && fatal_error "Can't find iptables executable"
else
[ -e "$IPTABLES" ] || fatal_error "\$IPTABLES=$IPTABLES does not exist or is not executable"
fi
determine_capabilities
else
f=$(find_file capabilities)
[ -f $f ] && . $f || fatal_error "The -e flag requires a capabilities file"
fi
ADD_IP_ALIASES="$(added_param_value_yes ADD_IP_ALIASES $ADD_IP_ALIASES)"
if [ -n "${LOGRATE}${LOGBURST}" ]; then
LOGLIMIT="--match limit"
[ -n "$LOGRATE" ] && LOGLIMIT="$LOGLIMIT --limit $LOGRATE"
[ -n "$LOGBURST" ] && LOGLIMIT="$LOGLIMIT --limit-burst $LOGBURST"
fi
if [ -n "$IP_FORWARDING" ]; then
case "$IP_FORWARDING" in
[Oo][Nn]|[Oo][Ff][Ff]|[Kk][Ee][Ee][Pp])
;;
*)
fatal_error "Invalid value ($IP_FORWARDING) for IP_FORWARDING"
;;
esac
else
IP_FORWARDING=On
fi
[ -n "${BLACKLIST_DISPOSITION:=DROP}" ]
case "$CLAMPMSS" in
[0-9]*)
;;
*)
CLAMPMSS=$(added_param_value_no CLAMPMSS $CLAMPMSS)
;;
esac
ADD_SNAT_ALIASES=$(added_param_value_no ADD_SNAT_ALIASES $ADD_SNAT_ALIASES)
ROUTE_FILTER=$(added_param_value_no ROUTE_FILTER $ROUTE_FILTER)
LOG_MARTIANS=$(added_param_value_no LOG_MARTIANS $LOG_MARTIANS)
DETECT_DNAT_IPADDRS=$(added_param_value_no DETECT_DNAT_IPADDRS $DETECT_DNAT_IPADDRS)
maclist_target=reject
if [ -n "$MACLIST_DISPOSITION" ] ; then
case $MACLIST_DISPOSITION in
REJECT)
;;
DROP)
maclist_target=DROP
;;
ACCEPT)
maclist_target=RETURN
;;
*)
fatal_error "Invalid value ($MACLIST_DISPOSITION) for MACLIST_DISPOSITION"
;;
esac
else
MACLIST_DISPOSITION=REJECT
fi
if [ -n "$TCP_FLAGS_DISPOSITION" ] ; then
case $TCP_FLAGS_DISPOSITION in
REJECT|ACCEPT|DROP)
;;
*)
fatal_error "Invalid value ($TCP_FLAGS_DISPOSITION) for TCP_FLAGS_DISPOSITION"
;;
esac
else
TCP_FLAGS_DISPOSITION=DROP
fi
[ -n "${RFC1918_LOG_LEVEL:=info}" ]
MARK_IN_FORWARD_CHAIN=$(added_param_value_no MARK_IN_FORWARD_CHAIN $MARK_IN_FORWARD_CHAIN)
[ -n "$MARK_IN_FORWARD_CHAIN" ] && MARKING_CHAIN=tcfor || MARKING_CHAIN=tcpre
CLEAR_TC=$(added_param_value_yes CLEAR_TC $CLEAR_TC)
if [ -n "$LOGFORMAT" ]; then
if [ -n "$(echo $LOGFORMAT | grep '%d')" ]; then
LOGRULENUMBERS=Yes
temp=$(printf "$LOGFORMAT" fooxx 1 barxx 2> /dev/null)
if [ $? -ne 0 ]; then
fatal_error "Invalid LOGFORMAT string: \"$LOGFORMAT\""
fi
else
temp=$(printf "$LOGFORMAT" fooxx barxx 2> /dev/null)
if [ $? -ne 0 ]; then
fatal_error "Invalid LOGFORMAT string: \"$LOGFORMAT\""
fi
fi
[ ${#temp} -le 29 ] || fatal_error "LOGFORMAT string is longer than 29 characters: \"$LOGFORMAT\""
else
LOGFORMAT="Shorewall:%s:%s:"
fi
ADMINISABSENTMINDED=$(added_param_value_no ADMINISABSENTMINDED $ADMINISABSENTMINDED)
BLACKLISTNEWONLY=$(added_param_value_no BLACKLISTNEWONLY $BLACKLISTNEWONLY)
DISABLE_IPV6=$(added_param_value_no DISABLE_IPV6 $DISABLE_IPV6)
BRIDGING=$(added_param_value_no BRIDGING $BRIDGING)
STARTUP_ENABLED=$(added_param_value_yes STARTUP_ENABLED $STARTUP_ENABLED)
RETAIN_ALIASES=$(added_param_value_no RETAIN_ALIASES $RETAIN_ALIASES)
[ -n "${ADD_IP_ALIASES}${ADD_SNAT_ALIASES}" ] || RETAIN_ALIASES=
DELAYBLACKLISTLOAD=$(added_param_value_no DELAYBLACKLISTLOAD $DELAYBLACKLISTLOAD)
LOGTAGONLY=$(added_param_value_no LOGTAGONLY $LOGTAGONLY)
RFC1918_STRICT=$(added_param_value_no RFC1918_STRICT $RFC1918_STRICT)
SAVE_IPSETS=$(added_param_value_no SAVE_IPSETS $SAVE_IPSETS)
MAPOLDACTIONS=$(added_param_value_yes MAPOLDACTIONS $MAPOLDACTIONS)
FASTACCEPT=$(added_param_value_no FASTACCEPT $FASTACCEPT)
IMPLICIT_CONTINUE=$(added_param_value_no IMPLICIT_CONTINUE $IMPLICIT_CONTINUE)
HIGH_ROUTE_MARKS=$(added_param_value_no HIGH_ROUTE_MARKS $HIGH_ROUTE_MARKS)
[ -n "$XCONNMARK_MATCH" ] || XCONNMARK=
[ -n "$XMARK" ] || XCONNMARK=
[ -n "$HIGH_ROUTE_MARKS" -a -z "$XCONNMARK" ] && fatal_error "HIGH_ROUTE_MARKS=Yes requires extended CONNMARK target, extended CONNMARK match support and extended MARK support"
case ${IPSECFILE:=ipsec} in
ipsec|zones)
;;
*)
fatal_error "Invalid value ($IPSECFILE) for IPSECFILE option"
;;
esac
case ${MACLIST_TABLE:=filter} in
filter)
;;
mangle)
[ $MACLIST_DISPOSITION = reject ] && fatal_error "MACLIST_DISPOSITION=REJECT is not allowed with MACLIST_TABLE=mangle"
;; *)
fatal_error "Invalid value ($MACLIST_TABLE) for MACLIST_TABLE option"
;;
esac
TC_SCRIPT=
if [ -n "$TC_ENABLED" ] ; then
case "$TC_ENABLED" in
[Yy][Ee][Ss])
TC_ENABLED=
TC_SCRIPT=$(find_file tcstart)
[ -f $TC_SCRIPT ] || fatal_error "Unable to find tcstart file"
;;
[Ii][Nn][Tt][Ee][Rr][Nn][Aa][Ll])
TC_ENABLED=Yes
;;
[Nn][Oo])
TC_ENABLED=
;;
esac
else
TC_ENABLED=Yes
fi
if [ -n "$TC_ENABLED" ];then
[ -n "$MANGLE_ENABLED" ] || fatal_error "Traffic Shaping requires mangle support in your kernel and iptables"
fi
[ "x${SHOREWALL_DIR}" = "x." ] && SHOREWALL_DIR="$PWD"
#
# Check out the user's shell
#
[ -n "${SHOREWALL_SHELL:=/bin/sh}" ]
temp=$(decodeaddr 192.168.1.1)
if [ $(encodeaddr $temp) != 192.168.1.1 ]; then
fatal_error "Shell $SHOREWALL_SHELL is broken and may not be used with Shorewall"
fi
#
# Export variables set in shorewall.conf
#
# Logging
export LOGFORMAT
export LOGTAGONLY
export LOGRATE
export LOGBURST
export LOGALLNEW
export BLACKLIST_LOGLEVEL
export MACLIST_LOG_LEVEL
export TCP_FLAGS_LOG_LEVEL
export RFC1918_LOG_LEVEL
export SMURF_LOG_LEVEL
export LOG_MARTIANS
# Files and directories
export IPTABLES
export SHOREWALL_SHELL
export SUBSYSLOCK
export MODULESDIR
export CONFIG_PATH
export RESTOREFILE
export IPSECFILE
# Firewall options
export FW
export IP_FORWARDING
export ADD_IP_ALIASES
export ADD_SNAT_ALIASES
export RETAIN_ALIASES
export TC_ENABLED
export CLEAR_TC
export MARK_IN_FORWARD_CHAIN
export CLAMPMSS
export ROUTE_FILTER
export DETECT_DNAT_IPADDRS
export MUTEX_TIMEOUT
export ADMINISABSENTMINDED
export BLACKLISTNEWONLY
export DELAYBLACKLISTLOAD
export MODULE_SUFFIX
export DISABLE_IPV6
export BRIDGING
export PKTTYPE
export RFC1918_STRICT
export MACLIST_TABLE
export MACLIST_TTL
export SAVE_IPSETS
export MAPOLDACTIONS
export FASTACCEPT
export IMPLICIT_CONTINUE
export HIGH_ROUTE_MARKS
# Packet Disposition
export BLACKLIST_DISPOSITION
export MACLIST_DISPOSITION
export TCP_FLAGS_DISPOSITION
# Generated values
export LOGPARMS
export LOGLIMIT
export LOGRULENUMBERS
export VERSION
#
# Export capabilities
#
export NAT_ENABLED
export MANGLE_ENABLED
export CONNTRACK_MATCH
export MULTIPORT
export XMULTIPORT
export POLICY_MATCH
export PHYSDEV_MATCH
export IPRANGE_MATCH
export RECENT_MATCH
export OWNER_MATCH
export IPSET_MATCH
export CONNMARK
export XCONNMARK
export CONNMARK_MATCH
export XCONNMARK_MATCH
export RAW_TABLE
export IPP2P_MATCH
export LENGTH_MATCH
export CLASSIFY_TARGET
export ENHANCED_REJECT
export USEPKTTYPE
export KLUDGEFREE
export MARK
export XMARK
export MANGLE_FORWARD
#
# Export user's params
#
$(export_params)
}
#
# Give Usage Information
#
usage() {
echo "Usage: $0 [debug] check|compile <filename>}"
exit 1
}
2005-07-09 07:45:05 +02:00
#
# Clear descriptor 1 if it is a terminal
#
clear_term() {
[ -t 1 ] && clear
}
2002-10-23 18:48:40 +02:00
#
# Delay $timeout seconds -- if we're running on a recent bash2 then allow
# <enter> to terminate the delay
#
2003-02-23 15:10:37 +01:00
timed_read ()
2002-05-01 01:13:15 +02:00
{
read -t $timeout foo 2> /dev/null
test $? -eq 2 && sleep $timeout
}
2002-10-23 18:48:40 +02:00
#
# Display the last $1 packets logged
#
2003-02-23 15:10:37 +01:00
packet_log() # $1 = number of messages
2002-05-01 01:13:15 +02:00
{
local options
2002-06-02 19:05:51 +02:00
[ -n "$realtail" ] && options="-n$1"
2002-05-01 01:13:15 +02:00
2006-04-18 00:24:18 +02:00
if [ -n "$SHOWMACS" -o $VERBOSE -gt 2 ]; then
2005-07-09 07:45:05 +02:00
grep "${LOGFORMAT}" $LOGFILE | \
sed s/" kernel:"// | \
sed s/" $host $LOGFORMAT"/" "/ | \
tail $options
else
grep "${LOGFORMAT}" $LOGFILE | \
sed s/" kernel:"// | \
sed s/" $host $LOGFORMAT"/" "/ | \
sed 's/MAC=.* SRC=/SRC=/' | \
tail $options
fi
2002-05-01 01:13:15 +02:00
}
2002-10-23 18:48:40 +02:00
#
# Show traffic control information
#
2002-05-01 01:13:15 +02:00
show_tc() {
show_one_tc() {
2002-07-06 00:24:40 +02:00
local device=${1%@*}
2005-07-09 06:45:32 +02:00
qdisc=$(tc qdisc list dev $device)
2002-05-01 01:13:15 +02:00
if [ -n "$qdisc" ]; then
echo Device $device:
tc -s -d qdisc show dev $device
tc -s -d class show dev $device
echo
fi
}
ip link list | \
while read inx interface details; do
case $inx in
[0-9]*)
show_one_tc ${interface%:}
2002-07-06 00:24:40 +02:00
;;
2002-05-01 01:13:15 +02:00
*)
;;
esac
done
}
2002-12-10 21:42:19 +01:00
#
# Show classifier information
#
show_classifiers() {
show_one_classifier() {
local device=${1%@*}
2005-07-09 06:45:32 +02:00
qdisc=$(tc qdisc list dev $device)
2002-12-10 21:42:19 +01:00
if [ -n "$qdisc" ]; then
echo Device $device:
tc -s filter ls dev $device
echo
fi
}
ip link list | \
while read inx interface details; do
case $inx in
[0-9]*)
show_one_classifier ${interface%:}
;;
*)
;;
esac
done
}
2002-05-01 01:13:15 +02:00
2002-10-23 18:48:40 +02:00
#
# Watch the Firewall Log
#
2002-06-02 19:05:51 +02:00
logwatch() # $1 = timeout -- if negative, prompt each time that
2002-07-06 00:24:40 +02:00
# an 'interesting' packet count changes
2002-06-02 19:05:51 +02:00
{
2005-07-09 06:45:32 +02:00
host=$(echo $HOSTNAME | sed 's/\..*$//')
2005-07-09 07:45:05 +02:00
oldrejects=$($IPTABLES -L -v -n | grep 'LOG')
2003-02-23 15:10:37 +01:00
2002-06-02 19:05:51 +02:00
if [ $1 -lt 0 ]; then
timeout=$((- $1))
pause="Yes"
else
pause="No"
timeout=$1
fi
2005-07-27 22:30:16 +02:00
qt mywhich awk && haveawk=Yes || haveawk=
2002-06-02 19:05:51 +02:00
while true; do
2005-07-09 07:45:05 +02:00
clear_term
2005-07-09 06:45:32 +02:00
echo "$banner $(date)"
2002-11-11 00:15:53 +01:00
echo
2002-06-02 19:05:51 +02:00
2002-11-11 00:15:53 +01:00
echo "Dropped/Rejected Packet Log"
echo
2002-06-02 19:05:51 +02:00
2002-09-18 01:53:46 +02:00
show_reset
2005-07-09 07:45:05 +02:00
rejects=$($IPTABLES -L -v -n | grep 'LOG')
2002-06-02 19:05:51 +02:00
if [ "$rejects" != "$oldrejects" ]; then
oldrejects="$rejects"
2002-11-11 00:15:53 +01:00
2002-11-11 17:46:50 +01:00
$RING_BELL
2002-11-11 00:15:53 +01:00
2002-06-02 19:05:51 +02:00
packet_log 40
if [ "$pause" = "Yes" ]; then
2002-11-11 00:15:53 +01:00
echo
2002-11-11 17:46:50 +01:00
echo $ECHO_N 'Enter any character to continue: '
2002-06-02 19:05:51 +02:00
read foo
else
timed_read
fi
else
echo
packet_log 40
timed_read
fi
done
}
2005-07-09 07:55:29 +02:00
#
# Save currently running configuration
#
save_config() {
2005-07-29 21:06:37 +02:00
if shorewall_is_started ; then
2006-06-09 18:35:55 +02:00
[ -d ${VARDIR} ] || mkdir -p ${VARDIR}
2005-09-30 18:54:24 +02:00
2005-07-09 07:55:29 +02:00
if [ -f $RESTOREPATH -a ! -x $RESTOREPATH ]; then
echo " ERROR: $RESTOREPATH exists and is not a saved Shorewall configuration"
else
case $RESTOREFILE in
save|restore-base)
echo " ERROR: Reserved file name: $RESTOREFILE"
;;
*)
2006-06-09 18:35:55 +02:00
if $IPTABLES -L dynamic -n > ${VARDIR}/save; then
2005-07-09 07:55:29 +02:00
echo " Dynamic Rules Saved"
2006-06-09 18:35:55 +02:00
if [ -f ${VARDIR}/.restore ]; then
if iptables-save | iptablesbug > ${VARDIR}/restore-$$; then
cp -f ${VARDIR}/.restore $RESTOREPATH
mv -f ${VARDIR}/restore-$$ ${RESTOREPATH}-iptables
2006-01-25 18:33:38 +01:00
chmod +x $RESTOREPATH
echo " Currently-running Configuration Saved to $RESTOREPATH"
rm -f ${RESTOREPATH}-ipsets
case ${SAVE_IPSETS:-No} in
[Yy][Ee][Ss])
RESTOREPATH=${RESTOREPATH}-ipsets
2006-06-09 18:35:55 +02:00
f=${VARDIR}/restore-$$
2006-01-25 18:33:38 +01:00
echo "#!/bin/sh" > $f
2006-07-15 18:22:55 +02:00
echo "#This ipset restore file generated $(date) by Shorewall $VERSION" >> $f
2006-01-25 18:33:38 +01:00
echo >> $f
2006-06-09 18:35:55 +02:00
echo ". ${SHAREDIR}/functions" >> $f
2006-01-25 18:33:38 +01:00
echo >> $f
2006-06-09 18:35:55 +02:00
grep '^MODULE' ${VARDIR}/restore-base >> $f
2006-01-25 18:33:38 +01:00
echo "reload_kernel_modules << __EOF__" >> $f
2006-06-09 18:35:55 +02:00
grep 'loadmodule ip_set' ${VARDIR}/restore-base >> $f
2006-01-25 18:33:38 +01:00
echo "__EOF__" >> $f
echo >> $f
echo "ipset -U :all: :all:" >> $f
echo "ipset -F" >> $f
echo "ipset -X" >> $f
echo "ipset -R << __EOF__" >> $f
ipset -S >> $f
echo "__EOF__" >> $f
mv -f $f $RESTOREPATH
chmod +x $RESTOREPATH
echo " Current Ipset Contents Saved to $RESTOREPATH"
;;
[Nn][Oo])
;;
*)
echo " WARNING: Invalid value ($SAVE_IPSETS) for SAVE_IPSETS. Ipset contents not saved"
;;
esac
else
2006-06-09 18:35:55 +02:00
rm -f ${VARDIR}/restore-$$
2006-01-25 18:33:38 +01:00
echo " ERROR: Currently-running Configuration Not Saved"
fi
2005-07-09 07:55:29 +02:00
else
2006-06-14 18:32:13 +02:00
echo " ERROR: ${VARDIR}/.restore does not exist"
2005-07-09 07:55:29 +02:00
fi
else
echo "Error Saving the Dynamic Rules"
fi
;;
esac
fi
else
echo "Shorewall isn't started"
fi
2005-08-02 18:46:30 +02:00
2005-07-09 07:55:29 +02:00
}
2006-01-26 00:58:12 +01:00
2006-01-22 03:35:15 +01:00
#
# Start Command Executor
#
2006-01-19 01:20:23 +01:00
start_command() {
2006-07-15 18:22:55 +02:00
local finished=0 shell=$SHOREWALL_SHELL
2006-01-19 01:20:23 +01:00
2006-01-24 00:30:58 +01:00
do_it() {
[ -n "$nolock" ] || mutex_on
progress_message3 "Compiling..."
2006-07-15 18:22:55 +02:00
do_initialize
if $shell ${SHAREDIR}/compiler $debugging $nolock compile ${VARDIR}/.start; then
$SHOREWALL_SHELL ${VARDIR}/.start $debugging start
2006-01-24 00:30:58 +01:00
fi
[ -n "$nolock" ] || mutex_off
}
if shorewall_is_started; then
error_message "Shorewall is already running"
exit 1
fi
2006-02-04 04:45:03 +01:00
if [ -z "$STARTUP_ENABLED" ]; then
error_message "ERROR: Startup is disabled"
exit 2
fi
2006-01-19 01:20:23 +01:00
while [ $finished -eq 0 -a $# -gt 0 ]; do
option=$1
case $option in
-*)
option=${option#-}
while [ -n "$option" ]; do
case $option in
-)
finished=1
option=
;;
f*)
FAST=Yes
option=${option#f}
;;
*)
usage 1
;;
esac
done
shift
;;
*)
finished=1
;;
esac
done
case $# in
0)
;;
1)
[ -n "$SHOREWALL_DIR" -o -n "$FAST" ] && usage 2
if [ ! -d $1 ]; then
if [ -e $1 ]; then
echo "$1 is not a directory" >&2 && exit 2
else
echo "Directory $1 does not exist" >&2 && exit 2
fi
fi
SHOREWALL_DIR=$
export SHOREWALL_DIR
;;
*)
usage 1
;;
esac
export NOROUTES
if [ -n "$FAST" ]; then
if qt mywhich make; then
2006-03-12 01:19:33 +01:00
#
# RESTOREFILE is exported by get_config()
#
2006-06-09 18:35:55 +02:00
make -qf ${CONFDIR}/Makefile || FAST=
2006-01-19 01:20:23 +01:00
fi
if [ -n "$FAST" ]; then
2006-06-09 18:35:55 +02:00
RESTOREPATH=${VARDIR}/$RESTOREFILE
2006-01-19 01:20:23 +01:00
if [ -x $RESTOREPATH ]; then
if [ -x ${RESTOREPATH}-ipsets ]; then
echo Restoring Ipsets...
#
# We must purge iptables to be sure that there are no
# references to ipsets
#
iptables -F
iptables -X
2006-06-09 17:40:31 +02:00
$SHOREWALL_SHELL ${RESTOREPATH}-ipsets
2006-01-19 01:20:23 +01:00
fi
echo Restoring Shorewall...
2006-06-09 17:40:31 +02:00
$SHOREWALL_SHELL $RESTOREPATH restore
2006-06-09 18:35:55 +02:00
date > ${VARDIR}/restarted
2006-05-10 22:11:37 +02:00
progress_message3 Shorewall restored from $RESTOREPATH
2006-01-19 01:20:23 +01:00
else
2006-01-24 00:30:58 +01:00
do_it
2006-01-19 01:20:23 +01:00
fi
else
2006-01-24 00:30:58 +01:00
do_it
2006-01-19 01:20:23 +01:00
fi
else
2006-01-24 00:30:58 +01:00
do_it
2006-01-19 01:20:23 +01:00
fi
}
2006-01-22 03:35:15 +01:00
#
# Compile Command Executor
#
2006-01-19 01:20:23 +01:00
compile_command() {
2006-07-15 18:22:55 +02:00
local finished=0 shell=$SHOREWALL_SHELL
2006-01-19 01:20:23 +01:00
while [ $finished -eq 0 ]; do
[ $# -eq 0 ] && usage 1
option=$1
case $option in
-*)
2006-02-03 18:08:37 +01:00
shift
2006-01-19 01:20:23 +01:00
option=${option#-}
[ -z "$option" ] && usage 1
while [ -n "$option" ]; do
case $option in
e*)
EXPORT=Yes
option=${option#e}
;;
-)
finished=1
option=
;;
*)
usage 1
;;
esac
done
;;
*)
finished=1
;;
esac
done
file=
case $# in
1)
file=$1
;;
2)
[ -n "$SHOREWALL_DIR" ] && usage 2
if [ ! -d $1 ]; then
if [ -e $1 ]; then
echo "$1 is not a directory" >&2 && exit 2
else
echo "Directory $1 does not exist" >&2 && exit 2
fi
fi
SHOREWALL_DIR=$1
export SHOREWALL_DIR
file=$2
;;
*)
usage 1
;;
esac
export EXPORT
2006-02-03 22:39:00 +01:00
progress_message3 "Compiling..."
2006-07-15 18:22:55 +02:00
do_initialize
exec $shell ${SHAREDIR}/compiler $debugging compile $file
2006-01-19 01:20:23 +01:00
}
2006-01-22 03:35:15 +01:00
#
2006-01-24 00:30:58 +01:00
# Check Command Executor
2006-01-22 03:35:15 +01:00
#
2006-01-24 00:30:58 +01:00
check_command() {
2006-07-15 18:22:55 +02:00
local finished=0 shell=$SHOREWALL_SHELL
2006-01-19 01:20:23 +01:00
while [ $finished -eq 0 -a $# -gt 0 ]; do
option=$1
case $option in
-*)
option=${option#-}
while [ -n "$option" ]; do
case $option in
-)
finished=1
option=
;;
2006-02-03 16:27:54 +01:00
e*)
EXPORT=Yes
option=${option#e}
2006-01-23 02:41:24 +01:00
;;
2006-01-19 01:20:23 +01:00
*)
usage 1
;;
esac
done
shift
;;
*)
finished=1
;;
esac
done
case $# in
0)
;;
1)
[ -n "$SHOREWALL_DIR" ] && usage 2
if [ ! -d $1 ]; then
if [ -e $1 ]; then
echo "$1 is not a directory" >&2 && exit 2
else
echo "Directory $1 does not exist" >&2 && exit 2
fi
fi
SHOREWALL_DIR=$1
export SHOREWALL_DIR
;;
*)
usage 1
;;
esac
2006-02-10 19:45:05 +01:00
export EXPORT
2006-01-19 01:20:23 +01:00
2006-02-03 22:39:00 +01:00
progress_message3 "Checking..."
2006-07-15 18:22:55 +02:00
do_initialize
exec $shell ${SHAREDIR}/compiler $debugging $nolock check
2006-01-19 01:20:23 +01:00
}
2006-01-24 00:30:58 +01:00
2006-01-22 03:35:15 +01:00
#
2006-01-24 00:30:58 +01:00
# Restart Command Executor
2006-01-22 03:35:15 +01:00
#
2006-01-24 00:30:58 +01:00
restart_command() {
2006-07-15 18:22:55 +02:00
local finished=0 shell=$SHOREWALL_SHELL
2006-01-19 01:20:23 +01:00
while [ $finished -eq 0 -a $# -gt 0 ]; do
option=$1
case $option in
-*)
option=${option#-}
while [ -n "$option" ]; do
case $option in
-)
finished=1
option=
;;
n*)
NOROUTES=Yes
option=${option#n}
;;
*)
usage 1
;;
esac
done
shift
;;
*)
finished=1
;;
esac
done
case $# in
0)
;;
1)
[ -n "$SHOREWALL_DIR" ] && usage 2
if [ ! -d $1 ]; then
if [ -e $1 ]; then
echo "$1 is not a directory" >&2 && exit 2
else
echo "Directory $1 does not exist" >&2 && exit 2
fi
fi
SHOREWALL_DIR=$1
export SHOREWALL_DIR
;;
*)
usage 1
;;
esac
2006-02-04 04:45:03 +01:00
if [ -z "$STARTUP_ENABLED" ]; then
error_message "ERROR: Startup is disabled"
exit 2
fi
2006-01-19 01:20:23 +01:00
export NOROUTES
[ -n "$nolock" ] || mutex_on
2006-01-23 21:44:31 +01:00
progress_message3 "Compiling..."
2006-07-15 18:22:55 +02:00
do_initialize
if $shell ${SHAREDIR}/compiler $debugging $nolock compile ${VARDIR}/.restart; then
2006-06-09 18:35:55 +02:00
$SHOREWALL_SHELL ${VARDIR}/.restart $debugging restart
2006-01-19 01:20:23 +01:00
fi
[ -n "$nolock" ] || mutex_off
}
2006-01-24 00:30:58 +01:00
2006-01-22 03:35:15 +01:00
#
# Show Command Executor
#
2006-01-19 01:20:23 +01:00
show_command() {
local finished=0
while [ $finished -eq 0 -a $# -gt 0 ]; do
option=$1
case $option in
-*)
option=${option#-}
while [ -n "$option" ]; do
case $option in
-)
finished=1
option=
;;
v*)
2006-03-24 00:52:47 +01:00
VERBOSE=$(($VERBOSE + 1 ))
2006-01-24 17:10:41 +01:00
option=${option#v}
2006-01-19 01:20:23 +01:00
;;
2006-02-03 16:27:54 +01:00
x*)
IPT_OPTIONS="-xnv"
option=${option#x}
;;
2006-04-18 00:24:18 +02:00
m*)
SHOWMACS=Yes
option=${option#m}
;;
2006-01-19 01:20:23 +01:00
*)
usage 1
;;
esac
done
shift
;;
*)
finished=1
;;
esac
done
[ -n "$debugging" ] && set -x
case "$1" in
2006-06-17 17:58:48 +02:00
connections)
[ $# -gt 1 ] && usage 1
2006-07-15 18:22:55 +02:00
echo "Shorewall-$VERSION Connections at $HOSTNAME - $(date)"
2006-01-19 01:20:23 +01:00
echo
2006-06-17 17:58:48 +02:00
cat /proc/net/ip_conntrack
;;
nat)
[ $# -gt 1 ] && usage 1
2006-07-15 18:22:55 +02:00
echo "Shorewall-$VERSION NAT Table at $HOSTNAME - $(date)"
2006-01-19 01:20:23 +01:00
echo
2006-06-17 17:58:48 +02:00
show_reset
$IPTABLES -t nat -L $IPT_OPTIONS
;;
tos|mangle)
[ $# -gt 1 ] && usage 1
2006-07-15 18:22:55 +02:00
echo "Shorewall-$VERSION Mangle Table at $HOSTNAME - $(date)"
2006-06-17 17:58:48 +02:00
echo
show_reset
$IPTABLES -t mangle -L $IPT_OPTIONS
;;
log)
[ $# -gt 1 ] && usage 1
2006-07-15 18:22:55 +02:00
echo "Shorewall-$VERSION Log at $HOSTNAME - $(date)"
2006-06-17 17:58:48 +02:00
echo
show_reset
host=$(echo $HOSTNAME | sed 's/\..*$//')
packet_log 20
;;
tc)
[ $# -gt 1 ] && usage 1
2006-07-15 18:22:55 +02:00
echo "Shorewall-$VERSION Traffic Control at $HOSTNAME - $(date)"
2006-06-17 17:58:48 +02:00
echo
show_tc
;;
classifiers)
[ $# -gt 1 ] && usage 1
2006-07-15 18:22:55 +02:00
echo "Shorewall-$VERSION Clasifiers at $HOSTNAME - $(date)"
2006-06-17 17:58:48 +02:00
echo
show_classifiers
;;
zones)
[ $# -gt 1 ] && usage 1
if [ -f ${VARDIR}/zones ]; then
2006-07-15 18:22:55 +02:00
echo "Shorewall-$VERSION Zones at $HOSTNAME - $(date)"
2006-06-17 17:58:48 +02:00
echo
while read zone type hosts; do
echo "$zone ($type)"
for host in $hosts; do
echo " $host"
done
done < ${VARDIR}/zones
echo
else
echo " ERROR: ${VARDIR}/zones does not exist" >&2
exit 1
2006-01-19 01:20:23 +01:00
fi
2006-06-17 17:58:48 +02:00
;;
capabilities)
[ $# -gt 1 ] && usage 1
determine_capabilities
VERBOSE=2
report_capabilities
;;
actions)
[ $# -gt 1 ] && usage 1
echo "allowBcast # Silently Allow Broadcast/multicast"
echo "dropBcast # Silently Drop Broadcast/multicast"
echo "dropNotSyn # Silently Drop Non-syn TCP packets"
echo "rejNotSyn # Silently Reject Non-syn TCP packets"
echo "dropInvalid # Silently Drop packets that are in the INVALID conntrack state"
echo "allowInvalid # Accept packets that are in the INVALID conntrack state."
echo "allowoutUPnP # Allow traffic from local command 'upnpd'"
echo "allowinUPnP # Allow UPnP inbound (to firewall) traffic"
echo "forwardUPnP # Allow traffic that upnpd has redirected from"
cat ${SHAREDIR}/actions.std ${CONFDIR}/actions | grep -Ev '^\#|^$'
;;
macros)
[ $# -gt 1 ] && usage 1
for macro in ${SHAREDIR}/macro.*; do
foo=`grep 'This macro' $macro | head -n 1`
if [ -n "$foo" ]; then
macro=${macro#*.}
foo=${foo%.*}
echo " $macro ${foo#\#}" | sed 's/This macro //'
fi
2006-01-19 01:20:23 +01:00
done
2006-06-17 17:58:48 +02:00
;;
config)
. ${SHAREDIR}/configpath
echo "Default CONFIG_PATH is $CONFIG_PATH"
echo "LITEDIR is $LITEDIR"
;;
*)
2006-07-15 18:22:55 +02:00
echo "Shorewall-$VERSION $([ $# -gt 0 ] && echo Chains || echo Chain) $* at $HOSTNAME - $(date)"
2006-06-17 17:58:48 +02:00
echo
show_reset
if [ $# -gt 0 ]; then
for chain in $*; do
$IPTABLES -L $chain $IPT_OPTIONS
done
else
$IPTABLES -L $IPT_OPTIONS
fi
;;
2006-01-19 01:20:23 +01:00
esac
}
2006-01-22 03:35:15 +01:00
#
# Dump Command Executor
#
2006-01-19 01:20:23 +01:00
dump_command() {
local finished=0
while [ $finished -eq 0 -a $# -gt 0 ]; do
option=$1
case $option in
-*)
option=${option#-}
while [ -n "$option" ]; do
case $option in
-)
finished=1
option=
;;
2006-02-03 16:27:54 +01:00
x*)
IPT_OPTIONS="-xnv"
option=${option#x}
2006-01-19 01:20:23 +01:00
;;
*)
usage 1
;;
esac
done
shift
;;
*)
finished=1
;;
esac
done
[ -n "$debugging" ] && set -x
[ $# -eq 0 ] || usage 1
clear_term
2006-07-15 18:22:55 +02:00
echo "Shorewall-$VERSION Dump at $HOSTNAME - $(date)"
2006-01-19 01:20:23 +01:00
echo
show_reset
host=$(echo $HOSTNAME | sed 's/\..*$//')
$IPTABLES -L $IPT_OPTIONS
2006-05-04 16:51:29 +02:00
heading "Log ($LOGFILE)"
2006-01-19 01:20:23 +01:00
packet_log 20
heading "NAT Table"
$IPTABLES -t nat -L $IPT_OPTIONS
heading "Mangle Table"
$IPTABLES -t mangle -L $IPT_OPTIONS
2006-05-04 16:51:29 +02:00
heading "Conntrack Table"
2006-01-19 01:20:23 +01:00
cat /proc/net/ip_conntrack
heading "IP Configuration"
ip addr ls
heading "IP Stats"
ip -stat link ls
if qt mywhich brctl; then
heading "Bridges"
brctl show
fi
heading "/proc"
show_proc /proc/version
show_proc /proc/sys/net/ipv4/ip_forward
show_proc /proc/sys/net/ipv4/icmp_echo_ignore_all
for directory in /proc/sys/net/ipv4/conf/*; do
for file in proxy_arp arp_filter arp_ignore rp_filter log_martians; do
show_proc $directory/$file
done
done
if [ -n "$(ip rule ls)" ]; then
heading "Routing Rules"
ip rule ls
ip rule ls | while read rule; do
echo ${rule##* }
done | sort -u | while read table; do
heading "Table $table:"
ip route ls table $table
done
else
heading "Routing Table"
ip route ls
fi
heading "ARP"
arp -na
if qt mywhich lsmod; then
heading "Modules"
lsmod | grep -E '^ip_|^ipt_|^iptable_'
fi
determine_capabilities
echo
report_capabilities
if [ -n "$TC_ENABLED" ]; then
2006-05-04 16:51:29 +02:00
heading "Traffic Control"
2006-01-19 01:20:23 +01:00
show_tc
2006-05-04 16:51:29 +02:00
heading "TC Filters"
2006-01-19 01:20:23 +01:00
show_classifiers
fi
}
2006-01-24 16:24:20 +01:00
#
# Safe-start/safe-restart Command Executor
#
safe_commands() {
local finished=0
# test is the shell supports timed read
read -t 0 junk 2> /dev/null
if [ $? -eq 2 -a ! -x /bin/bash ];then
echo "Your shell does not support a feature required to execute this command".
exit 2
fi
while [ $finished -eq 0 -a $# -gt 0 ]; do
option=$1
case $option in
-*)
option=${option#-}
while [ -n "$option" ]; do
case $option in
-)
finished=1
option=
;;
n*)
NOROUTES=Yes
option=${option#n}
;;
*)
usage 1
;;
esac
done
shift
;;
*)
finished=1
;;
esac
done
[ $# -eq 0 ] || usage 2
2006-02-04 04:45:03 +01:00
if [ -z "$STARTUP_ENABLED" ]; then
error_message "ERROR: Startup is disabled"
exit 2
fi
2006-01-24 16:24:20 +01:00
mutex_on
if shorewall_is_started; then
running=Yes
else
running=
fi
if [ "$COMMAND" = "safe-start" -a -n "$running" ]; then
# the command is safe-start but the firewall is already running
error_message "Shorewall is already started"
mutex_off
exit 1
fi
if [ "$COMMAND" = "safe-start" -o -z "$running" ]; then
# the command is safe-start or shorewall is not started yet
command="start"
else
# the command is safe-restart and the firewall is already running
command="restart"
fi
2006-02-03 22:39:00 +01:00
progress_message3 "Compiling..."
2006-06-09 18:35:55 +02:00
if ! $SHOREWALL_SHELL ${SHAREDIR}/compiler $debugging nolock compile ${VARDIR}/.$command; then
2006-01-24 16:24:20 +01:00
status=$?
mutex_off
exit $status
fi
2006-01-25 23:33:50 +01:00
RESTOREFILE=.safe
2006-06-09 18:35:55 +02:00
RESTOREPATH=${VARDIR}/.safe
2006-01-24 16:24:20 +01:00
save_config
2006-02-03 22:39:00 +01:00
case $command in
start)
progress_message3 "Starting..."
;;
restart)
progress_message3 "Restarting..."
;;
esac
2006-06-09 18:35:55 +02:00
${VARDIR}/.$command $command
2006-01-24 16:24:20 +01:00
echo -n "Do you want to accept the new firewall configuration? [y/n] "
if read_yesno_with_timeout; then
echo "New configuration has been accepted"
else
if [ "$command" = "restart" ]; then
2006-06-09 18:35:55 +02:00
${VARDIR}/.safe restore
2006-01-24 16:24:20 +01:00
else
2006-06-09 18:35:55 +02:00
${VARDIR}/.$command clear
2006-01-24 16:24:20 +01:00
fi
mutex_off
echo "New configuration has been rejected and the old one restored"
exit 2
fi
mutex_off
[ $? -eq 0 ] && [ -n "$SUBSYSLOCK" ] && touch $SUBSYSLOCK
}
2006-01-22 03:35:15 +01:00
#
# Restore Comand Executor
#
2006-01-19 01:20:23 +01:00
restore_command() {
local finished=0
while [ $finished -eq 0 -a $# -gt 0 ]; do
option=$1
case $option in
-*)
option=${option#-}
while [ -n "$option" ]; do
case $option in
-)
finished=1
option=
;;
n*)
NOROUTES=Yes
option=${option#n}
;;
*)
usage 1
;;
esac
done
shift
;;
*)
finished=1
;;
esac
done
case $# in
0)
;;
1)
RESTOREFILE="$1"
validate_restorefile '<restore file>'
;;
*)
usage 1
;;
esac
2006-02-04 04:45:03 +01:00
if [ -z "$STARTUP_ENABLED" ]; then
error_message "ERROR: Startup is disabled"
exit 2
fi
2006-06-09 18:35:55 +02:00
RESTOREPATH=${VARDIR}/$RESTOREFILE
2006-01-19 01:20:23 +01:00
export NOROUTES
[ -n "$nolock" ] || mutex_on
if [ -x $RESTOREPATH ]; then
if [ -x ${RESTOREPATH}-ipsets ] ; then
echo Restoring Ipsets...
iptables -F
iptables -X
2006-05-11 16:52:00 +02:00
$SHOREWALL_SHELL ${RESTOREPATH}-ipsets
2006-01-19 01:20:23 +01:00
fi
2006-02-03 22:39:00 +01:00
progress_message3 "Restoring Shorewall..."
2006-06-09 18:35:55 +02:00
$SHOREWALL_SHELL $RESTOREPATH restore && progress_message3 "Shorewall restored from ${VARDIR}/$RESTOREFILE"
2006-01-19 01:20:23 +01:00
[ -n "$nolock" ] || mutex_off
else
2006-06-09 18:35:55 +02:00
echo "File ${VARDIR}/$RESTOREFILE: file not found"
2006-01-19 01:20:23 +01:00
[ -n "$nolock" ] || mutex_off
exit 2
fi
}
2003-07-27 20:17:39 +02:00
#
2006-06-17 19:17:45 +02:00
# [Re]load command executor
2006-06-14 19:25:37 +02:00
#
2006-06-17 19:17:45 +02:00
reload_command()
2006-06-14 19:25:37 +02:00
{
2006-06-17 01:04:12 +02:00
local verbose=$(make_verbose)
2006-06-19 17:54:30 +02:00
[ -n "$LITEDIR" ] || { echo " ERROR: LITEDIR not defined in ${SHAREDIR}/configpath" >&2; exit 2; }
2006-06-17 19:17:45 +02:00
if shorewall $debugging $verbose compile -e $1 $1/firewall && \
2006-06-30 23:00:59 +02:00
echo "Copying $(resolve_file ${1}/firewall) to ${2}:${LITEDIR}..." && \
2006-06-17 19:17:45 +02:00
scp $1/firewall root@${2}:${LITEDIR}
then
echo "Copy complete"
if [ $COMMAND = reload ]; then
ssh root@${2} "/sbin/shorewall-lite $debugging $verbose restart" && \
progress_message3 "System $2 reloaded"
else
ssh root@${2} "/sbin/shorewall-lite $debugging $verbose restart" && \
progress_message3 "System $2 reloaded"
fi
fi
2006-06-14 19:25:37 +02:00
}
#
2003-07-27 20:17:39 +02:00
# Help information
#
help()
{
2006-07-15 18:22:55 +02:00
[ -x $HELP ] && { export version=$VERSION; exec $HELP $*; }
2003-07-27 20:17:39 +02:00
echo "Help subsystem is not installed at $HELP"
}
2005-08-02 18:46:30 +02:00
2002-10-23 18:48:40 +02:00
#
# Give Usage Information
#
2002-05-01 01:13:15 +02:00
usage() # $1 = exit status
{
2006-02-15 16:20:17 +01:00
echo "Usage: $(basename $0) [debug|trace] [nolock] [ -q ] [ -v ] [ -t ] <command>"
2002-05-01 01:13:15 +02:00
echo "where <command> is one of:"
2003-07-27 20:17:39 +02:00
echo " allow <address> ..."
2006-02-10 19:45:05 +01:00
echo " check [ -e ] [ <directory> ]"
2003-07-27 20:17:39 +02:00
echo " clear"
2006-06-03 19:05:43 +02:00
echo " compile [ -e ] [ <directory name> ] <path name>"
2003-08-24 03:24:23 +02:00
echo " drop <address> ..."
2006-02-03 16:27:54 +01:00
echo " dump [ -x ]"
2005-07-09 06:45:32 +02:00
echo " forget [ <file name> ]"
2003-07-27 20:17:39 +02:00
echo " help [ <command > | host | address ]"
echo " hits"
2005-12-03 00:58:57 +01:00
echo " ipcalc { <address>/<vlsm> | <address> <netmask> }"
echo " ipdecimal { <address> | <integer> }"
2003-07-27 20:17:39 +02:00
echo " iprange <address>-<address>"
2006-06-17 19:17:45 +02:00
echo " load [ <directory> ] <system>"
2006-03-23 17:37:45 +01:00
echo " logdrop <address> ..."
echo " logreject <address> ..."
2006-01-25 23:33:50 +01:00
echo " logwatch [<refresh interval>]"
2003-07-27 20:17:39 +02:00
echo " refresh"
2003-08-24 03:24:23 +02:00
echo " reject <address> ..."
2006-06-14 21:46:37 +02:00
echo " reload [ <directory> ] <system>"
2003-07-27 20:17:39 +02:00
echo " reset"
2006-02-03 16:27:54 +01:00
echo " restart [ -n ] [ <directory> ]"
echo " restore [ -n ] [ <file name> ]"
2005-07-09 06:45:32 +02:00
echo " save [ <file name> ]"
2006-06-17 17:58:48 +02:00
echo " show [ -x ] [ -m ] [<chain> [ <chain> ... ]|actions|capabilities|classifiers|config|connections|log|macros|mangle|nat|tc|zones]"
2006-02-03 16:27:54 +01:00
echo " start [ -f ] [ -n ] [ <directory> ]"
2002-05-01 01:13:15 +02:00
echo " stop"
echo " status"
echo " try <directory> [ <timeout> ]"
2003-07-27 20:17:39 +02:00
echo " version"
2005-07-09 07:55:29 +02:00
echo " safe-start"
echo " safe-restart"
2005-08-02 18:46:30 +02:00
echo
2002-05-01 01:13:15 +02:00
exit $1
}
2002-10-23 18:48:40 +02:00
#
# Display the time that the counters were last reset
#
2002-07-23 00:31:07 +02:00
show_reset() {
2006-06-09 18:35:55 +02:00
[ -f ${VARDIR}/restarted ] && \
echo "Counters reset $(cat ${VARDIR}/restarted)" && \
2002-11-11 00:15:53 +01:00
echo
2002-07-23 00:31:07 +02:00
}
2005-07-09 07:55:29 +02:00
2005-07-09 07:45:05 +02:00
#
# Display's the passed file name followed by "=" and the file's contents.
#
2005-08-02 18:46:30 +02:00
show_proc() # $1 = name of a file
2005-07-09 07:45:05 +02:00
{
2005-07-09 06:45:32 +02:00
[ -f $1 ] && echo " $1 = $(cat $1)"
}
2005-08-02 18:46:30 +02:00
read_yesno_with_timeout() {
2005-07-09 07:55:29 +02:00
read -t 60 yn 2> /dev/null
if [ $? -eq 2 ]
then
# read doesn't support timeout
test -x /bin/bash || return 2 # bash is not installed so the feature is not available
/bin/bash -c 'read -t 60 yn ; if [ "$yn" == "y" ] ; then exit 0 ; else exit 1 ; fi' # invoke bash and use its version of read
return $?
else
# read supports timeout
case "$yn" in
y|Y)
return 0
;;
*)
return 1
;;
esac
fi
}
2005-08-08 20:05:22 +02:00
#
# Print a heading with leading and trailing black lines
#
heading() {
echo
echo "$@"
echo
}
2006-01-09 18:11:30 +01:00
#
2006-03-24 00:26:41 +01:00
# Create the appropriate -q option to pass onward
2006-01-09 18:11:30 +01:00
#
2006-01-23 02:41:24 +01:00
make_verbose() {
2006-03-24 00:26:41 +01:00
local v=$VERBOSE_OFFSET option=-
2006-01-09 18:11:30 +01:00
2006-03-24 00:26:41 +01:00
if [ $VERBOSE_OFFSET -gt 0 ]; then
2006-01-23 02:41:24 +01:00
while [ $v -gt 0 ]; do
option="${option}v"
v=$(($v - 1))
2006-01-09 18:11:30 +01:00
done
2006-03-24 00:26:41 +01:00
echo $option
elif [ $VERBOSE_OFFSET -lt 0 ]; then
while [ $v -lt 0 ]; do
option="${option}q"
v=$(($v + 1))
done
2006-01-09 18:11:30 +01:00
echo $option
fi
}
2006-01-19 01:20:23 +01:00
2002-10-23 18:48:40 +02:00
#
# Execution begins here
#
2002-05-01 01:13:15 +02:00
debugging=
2005-07-09 06:45:32 +02:00
if [ $# -gt 0 ] && [ "$1" = "debug" -o "$1" = "trace" ]; then
2002-05-01 01:13:15 +02:00
debugging=debug
shift
fi
nolock=
if [ $# -gt 0 ] && [ "$1" = "nolock" ]; then
nolock=nolock
shift
fi
SHOREWALL_DIR=
2005-07-09 06:45:32 +02:00
IPT_OPTIONS="-nv"
FAST=
2006-03-24 00:26:41 +01:00
VERBOSE_OFFSET=0
2005-09-15 01:01:13 +02:00
NOROUTES=
2006-01-13 00:26:37 +01:00
EXPORT=
2006-02-15 16:20:17 +01:00
export TIMESTAMP=
2005-09-15 03:07:12 +02:00
noroutes=
2005-07-09 06:45:32 +02:00
2006-01-17 18:00:54 +01:00
finished=0
2002-05-01 01:13:15 +02:00
2006-01-17 18:00:54 +01:00
while [ $finished -eq 0 ]; do
2002-05-01 01:13:15 +02:00
[ $# -eq 0 ] && usage 1
2005-07-09 06:45:32 +02:00
option=$1
case $option in
2006-01-17 18:08:41 +01:00
-)
finished=1
;;
2005-07-09 06:45:32 +02:00
-*)
option=${option#-}
2002-05-01 01:13:15 +02:00
2005-07-09 06:45:32 +02:00
[ -z "$option" ] && usage 1
2005-09-30 18:54:24 +02:00
2005-07-09 06:45:32 +02:00
while [ -n "$option" ]; do
case $option in
c)
[ $# -eq 1 ] && usage 1
if [ ! -d $2 ]; then
if [ -e $2 ]; then
echo "$2 is not a directory" >&2 && exit 2
else
echo "Directory $2 does not exist" >&2 && exit 2
fi
fi
2005-09-30 18:54:24 +02:00
2005-07-09 06:45:32 +02:00
SHOREWALL_DIR=$2
option=
shift
;;
2006-01-13 00:26:37 +01:00
e*)
EXPORT=Yes
option=${option#e}
;;
2005-07-09 06:45:32 +02:00
x*)
IPT_OPTIONS="-xnv"
option=${option#x}
;;
q*)
2006-03-24 00:26:41 +01:00
VERBOSE_OFFSET=$(($VERBOSE_OFFSET - 1 ))
2005-07-09 06:45:32 +02:00
option=${option#q}
;;
f*)
FAST=Yes
option=${option#f}
;;
2005-07-09 07:45:05 +02:00
v*)
2006-03-24 00:26:41 +01:00
VERBOSE_OFFSET=$(($VERBOSE_OFFSET + 1 ))
2006-01-24 17:10:41 +01:00
option=${option#v}
2005-07-09 07:45:05 +02:00
;;
2005-09-15 01:01:13 +02:00
n*)
NOROUTES=Yes
option=${option#n}
2005-09-30 18:54:24 +02:00
;;
2006-02-15 16:20:17 +01:00
t*)
TIMESTAMP=Yes
option=${option#t}
;;
2006-01-17 18:00:54 +01:00
-)
finished=1
option=
;;
2005-07-09 06:45:32 +02:00
*)
usage 1
;;
esac
done
shift
;;
*)
2006-01-17 18:00:54 +01:00
finished=1
2005-07-09 06:45:32 +02:00
;;
2002-05-01 01:13:15 +02:00
esac
done
2002-06-04 17:08:50 +02:00
if [ $# -eq 0 ]; then
2002-05-01 01:13:15 +02:00
usage 1
fi
2002-06-15 19:27:41 +02:00
[ -n "$SHOREWALL_DIR" ] && export SHOREWALL_DIR
2003-01-07 00:01:23 +01:00
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
MUTEX_TIMEOUT=
2006-06-11 17:07:34 +02:00
SHAREDIR=/usr/share/shorewall
VARDIR=/var/lib/shorewall
CONFDIR=/etc/shorewall
2006-06-14 18:32:13 +02:00
export PRODUCT="Shorewall"
2006-06-11 17:07:34 +02:00
FIREWALL=$SHAREDIR/firewall
FUNCTIONS=$SHAREDIR/functions
VERSION_FILE=$SHAREDIR/version
HELP=$SHAREDIR/help
2003-01-07 00:01:23 +01:00
if [ -f $FUNCTIONS ]; then
. $FUNCTIONS
else
echo "$FUNCTIONS does not exist!" >&2
exit 2
fi
2002-05-01 01:13:15 +02:00
2005-07-09 06:45:32 +02:00
ensure_config_path
config=$(find_file shorewall.conf)
2003-03-08 19:01:32 +01:00
if [ -f $config ]; then
2005-07-09 06:45:32 +02:00
if [ -r $config ]; then
. $config
else
echo "Cannot read $config! (Hint: Are you root?)" >&2
exit 1
fi
2003-03-08 19:01:32 +01:00
else
echo "$config does not exist!" >&2
exit 2
fi
2005-07-09 06:45:32 +02:00
ensure_config_path
2005-07-09 07:45:05 +02:00
get_config
2003-01-07 00:01:23 +01:00
if [ ! -f $FIREWALL ]; then
2006-06-12 18:48:07 +02:00
echo " ERROR: Shorewall is not properly installed" >&2
2003-01-07 00:01:23 +01:00
if [ -L $FIREWALL ]; then
2006-06-12 18:48:07 +02:00
echo " $FIREWALL is a symbolic link to a" >&2
echo " non-existant file" >&2
2002-05-01 01:13:15 +02:00
else
2006-06-12 18:48:07 +02:00
echo " The file $FIREWALL does not exist" >&2
2002-05-01 01:13:15 +02:00
fi
exit 2
fi
2003-01-07 00:01:23 +01:00
if [ -f $VERSION_FILE ]; then
2006-07-15 18:22:55 +02:00
VERSION=$(cat $VERSION_FILE)
2002-05-01 01:13:15 +02:00
else
2006-06-12 18:48:07 +02:00
echo " ERROR: Shorewall is not properly installed" >&2
echo " The file $VERSION_FILE does not exist" >&2
2002-05-01 01:13:15 +02:00
exit 1
fi
banner="Shorewall-$version Status at $HOSTNAME -"
2005-07-09 06:45:32 +02:00
case $(echo -e) in
2002-11-11 17:46:50 +01:00
-e*)
2003-01-06 20:54:50 +01:00
RING_BELL="echo \a"
2002-11-11 17:46:50 +01:00
;;
*)
2003-01-06 20:54:50 +01:00
RING_BELL="echo -e \a"
2002-11-11 17:46:50 +01:00
;;
esac
2005-07-09 06:45:32 +02:00
case $(echo -n "Testing") in
2002-11-11 17:46:50 +01:00
-n*)
ECHO_N=
;;
*)
ECHO_N=-n
;;
esac
2006-01-18 21:17:58 +01:00
COMMAND=$1
case "$COMMAND" in
2005-07-09 06:45:32 +02:00
start)
2006-01-18 21:17:58 +01:00
shift
2006-01-19 01:20:23 +01:00
start_command $@
2005-07-09 06:45:32 +02:00
;;
2005-07-09 07:45:05 +02:00
stop|reset|clear|refresh)
2002-05-01 01:13:15 +02:00
[ $# -ne 1 ] && usage 1
2005-09-15 01:01:13 +02:00
export NOROUTES
2006-01-18 21:17:58 +01:00
exec $SHOREWALL_SHELL $FIREWALL $debugging $nolock $COMMAND
2005-07-09 07:45:05 +02:00
;;
2006-02-03 16:10:46 +01:00
compile)
2006-01-15 17:35:09 +01:00
shift
2006-01-19 01:20:23 +01:00
compile_command $@
2006-01-07 02:08:23 +01:00
;;
2006-01-18 21:17:58 +01:00
restart)
shift
2006-01-19 01:20:23 +01:00
restart_command $@
2006-01-18 21:17:58 +01:00
;;
check)
2006-01-19 01:20:23 +01:00
shift
check_command $@
2006-01-07 07:04:16 +01:00
;;
2003-01-23 02:13:36 +01:00
show|list)
2006-01-19 01:20:23 +01:00
shift
show_command $@
2002-05-01 01:13:15 +02:00
;;
2006-06-17 19:17:45 +02:00
load|reload)
2006-06-14 19:25:37 +02:00
shift
2006-06-14 20:12:06 +02:00
case $# in
1)
directory="."
system=$1
;;
2)
directory=$1
system=$2
;;
*)
usage 1
;;
esac
2006-06-17 19:17:45 +02:00
2006-06-14 20:12:06 +02:00
reload_command $directory $system
2006-06-14 19:25:37 +02:00
;;
2002-05-01 01:13:15 +02:00
status)
2005-07-28 16:37:56 +02:00
[ $# -eq 1 ] || usage 1
2006-07-15 18:22:55 +02:00
echo "Shorewall-$VERSION Status at $HOSTNAME - $(date)"
2005-07-30 23:59:12 +02:00
echo
2005-07-29 21:06:37 +02:00
if shorewall_is_started ; then
2005-07-29 20:32:50 +02:00
echo "Shorewall is running"
2005-07-30 23:59:12 +02:00
status=0
else
echo "Shorewall is stopped"
status=4
2005-07-29 20:32:50 +02:00
fi
2006-06-09 18:35:55 +02:00
if [ -f ${VARDIR}/state ]; then
state="$(cat ${VARDIR}/state)"
2006-01-17 18:34:34 +01:00
case $state in
2005-07-29 20:32:50 +02:00
Stopped*|Clear*)
status=3
;;
esac
2005-07-28 16:37:56 +02:00
else
2005-07-29 20:32:50 +02:00
state=Unknown
2005-07-28 16:37:56 +02:00
fi
2005-07-30 23:59:12 +02:00
echo "State:$state"
2005-07-29 20:32:50 +02:00
echo
2005-08-02 18:46:30 +02:00
exit $status
2005-07-28 16:37:56 +02:00
;;
dump)
2006-01-19 01:20:23 +01:00
shift
dump_command $@
2002-05-01 01:13:15 +02:00
;;
hits)
2005-12-03 00:58:57 +01:00
[ -n "$debugging" ] && set -x
2002-07-06 00:24:40 +02:00
[ $# -eq 1 ] || usage 1
2005-07-09 07:45:05 +02:00
clear_term
2006-07-15 18:22:55 +02:00
echo "Shorewall-$VERSION Hits at $HOSTNAME - $(date)"
2002-11-11 00:15:53 +01:00
echo
2002-05-01 01:13:15 +02:00
timeout=30
2005-07-09 06:45:32 +02:00
if [ $(grep -c "$LOGFORMAT" $LOGFILE ) -gt 0 ] ; then
2002-07-06 00:24:40 +02:00
echo " HITS IP DATE"
echo " ---- --------------- ------"
2003-05-21 23:36:05 +02:00
grep "$LOGFORMAT" $LOGFILE | sed 's/\(.\{6\}\)\(.*SRC=\)\(.*\)\( DST=.*\)/\3 \1/' | sort | uniq -c | sort -rn
2002-07-06 00:24:40 +02:00
echo ""
2002-05-01 01:13:15 +02:00
2002-07-06 00:24:40 +02:00
echo " HITS IP PORT"
echo " ---- --------------- -----"
2003-05-21 23:36:05 +02:00
grep "$LOGFORMAT" $LOGFILE | sed 's/\(.*SRC=\)\(.*\)\( DST=.*DPT=\)\([0-9]\{1,5\}\)\(.*\)/\2 \4/
2002-06-30 00:41:30 +02:00
t
s/\(.*SRC=\)\(.*\)\( DST=.*\)/\2/' | sort | uniq -c | sort -rn
2002-07-06 00:24:40 +02:00
echo ""
echo " HITS DATE"
echo " ---- ------"
2003-05-21 23:36:05 +02:00
grep "$LOGFORMAT" $LOGFILE | sed 's/\(.\{6\}\)\(.*\)/\1/' | sort | uniq -c | sort -rn
2002-07-06 00:24:40 +02:00
echo ""
echo " HITS PORT SERVICE(S)"
2003-02-23 15:10:37 +01:00
echo " ---- ----- ----------"
2003-06-01 05:14:20 +02:00
grep "$LOGFORMAT.*DPT" $LOGFILE | sed 's/\(.*DPT=\)\([0-9]\{1,5\}\)\(.*\)/\2/' | sort | uniq -c | sort -rn | \
2002-07-06 00:24:40 +02:00
while read count port ; do
# List all services defined for the given port
2005-07-09 06:45:32 +02:00
srv=$(grep "^[^#].*\\b$port/" /etc/services | cut -f 1 | sort -u)
srv=$(echo $srv | sed 's/ /,/g')
2002-07-06 00:24:40 +02:00
if [ -n "$srv" ] ; then
printf '%7d %5d %s\n' $count $port $srv
else
printf '%7d %5d\n' $count $port
fi
done
fi
;;
2002-05-01 01:13:15 +02:00
version)
2006-07-15 18:22:55 +02:00
echo $VERSION
2002-05-01 01:13:15 +02:00
;;
try)
2005-07-26 01:08:09 +02:00
[ -n "$SHOREWALL_DIR" ] && startup_error "ERROR: -c option may not be used with \"try\""
2002-05-01 01:13:15 +02:00
[ $# -lt 2 -o $# -gt 3 ] && usage 1
2006-03-24 00:26:41 +01:00
VERBOSE=$(make_verbose)
2005-09-15 03:07:12 +02:00
[ -n "$NOROUTES" ] && NOROUTES=-n
2006-06-20 16:20:21 +02:00
export -n CONFIG_PATH
2006-01-23 02:41:24 +01:00
if ! $0 $debugging $VERBOSE -c $2 restart; then
2005-07-09 07:45:05 +02:00
if ! $IPTABLES -L shorewall > /dev/null 2> /dev/null; then
2006-01-23 02:41:24 +01:00
$0 $VERBOSE $NOROUTES start
2002-06-04 17:08:50 +02:00
fi
2005-07-09 07:45:05 +02:00
elif ! $IPTABLES -L shorewall > /dev/null 2> /dev/null; then
2006-01-23 02:41:24 +01:00
$0 $VERBOSE $NOROUTES start
2002-05-01 01:13:15 +02:00
elif [ $# -eq 3 ]; then
sleep $3
2006-01-23 02:41:24 +01:00
$0 $VERBOSE $NOROUTES restart
2002-07-06 00:24:40 +02:00
fi
2002-05-01 01:13:15 +02:00
;;
2002-06-02 19:05:51 +02:00
logwatch)
2006-01-19 01:20:23 +01:00
shift
finished=0
2006-01-25 23:33:50 +01:00
while [ $finished -eq 0 -a $# -ne 0 ]; do
2006-01-19 01:20:23 +01:00
option=$1
case $option in
-*)
option=${option#-}
[ -z "$option" ] && usage 1
while [ -n "$option" ]; do
case $option in
v*)
2006-01-23 02:41:24 +01:00
VERBOSE=$(($VERBOSE + 1 ))
2006-01-24 17:10:41 +01:00
option=${option#v}
2006-01-19 01:20:23 +01:00
;;
2006-01-26 00:58:12 +01:00
q*)
VERBOSE=$(($VERBOSE - 1 ))
option=${option#q}
;;
2006-04-18 00:24:18 +02:00
m*)
SHOWMACS=Yes
option=${option#m}
;;
2006-01-19 01:20:23 +01:00
-)
finished=1
option=
;;
*)
usage 1
;;
esac
done
shift
;;
*)
finished=1
;;
esac
done
2005-12-03 00:58:57 +01:00
[ -n "$debugging" ] && set -x
2006-01-19 01:20:23 +01:00
if [ $# -eq 1 ]; then
logwatch $1
elif [ $# -eq 0 ]; then
2002-06-02 19:05:51 +02:00
logwatch 30
else
usage 1
fi
2002-07-06 00:24:40 +02:00
;;
2002-06-04 22:17:46 +02:00
drop)
2005-12-03 00:58:57 +01:00
[ -n "$debugging" ] && set -x
2002-07-06 00:24:40 +02:00
[ $# -eq 1 ] && usage 1
2006-02-04 18:14:46 +01:00
if shorewall_is_started ; then
mutex_on
while [ $# -gt 1 ]; do
shift
qt $IPTABLES -D dynamic -s $1 -j reject
qt $IPTABLES -D dynamic -s $1 -j DROP
2006-03-23 17:37:45 +01:00
qt $IPTABLES -D dynamic -s $1 -j logreject
qt $IPTABLES -D dynamic -s $1 -j logdrop
2006-02-04 18:14:46 +01:00
$IPTABLES -A dynamic -s $1 -j DROP || break 1
echo "$1 Dropped"
done
mutex_off
else
error_message "ERROR: Shorewall is not started"
exit 2
fi
2002-06-04 17:08:50 +02:00
;;
2006-03-23 17:37:45 +01:00
logdrop)
2005-12-03 00:58:57 +01:00
[ -n "$debugging" ] && set -x
2002-07-06 00:24:40 +02:00
[ $# -eq 1 ] && usage 1
2006-02-04 18:14:46 +01:00
if shorewall_is_started ; then
mutex_on
while [ $# -gt 1 ]; do
shift
qt $IPTABLES -D dynamic -s $1 -j reject
qt $IPTABLES -D dynamic -s $1 -j DROP
2006-03-23 17:37:45 +01:00
qt $IPTABLES -D dynamic -s $1 -j logreject
qt $IPTABLES -D dynamic -s $1 -j logdrop
$IPTABLES -A dynamic -s $1 -j logdrop || break 1
echo "$1 Dropped"
done
mutex_off
else
error_message "ERROR: Shorewall is not started"
exit 2
fi
;;
reject|logreject)
[ -n "$debugging" ] && set -x
[ $# -eq 1 ] && usage 1
if shorewall_is_started ; then
mutex_on
while [ $# -gt 1 ]; do
shift
qt $IPTABLES -D dynamic -s $1 -j reject
qt $IPTABLES -D dynamic -s $1 -j DROP
qt $IPTABLES -D dynamic -s $1 -j logreject
qt $IPTABLES -D dynamic -s $1 -j logdrop
$IPTABLES -A dynamic -s $1 -j $COMMAND || break 1
2006-02-04 18:14:46 +01:00
echo "$1 Rejected"
done
mutex_off
else
error_message "ERROR: Shorewall is not started"
exit 2
fi
2002-06-04 22:17:46 +02:00
;;
allow)
2005-12-03 00:58:57 +01:00
[ -n "$debugging" ] && set -x
2002-07-06 00:24:40 +02:00
[ $# -eq 1 ] && usage 1
2006-02-04 18:14:46 +01:00
if shorewall_is_started ; then
mutex_on
while [ $# -gt 1 ]; do
shift
2006-03-23 17:37:45 +01:00
if qt $IPTABLES -D dynamic -s $1 -j reject ||\
qt $IPTABLES -D dynamic -s $1 -j DROP ||\
qt $IPTABLES -D dynamic -s $1 -j logdrop ||\
qt $IPTABLES -D dynamic -s $1 -j logreject
then
2006-02-04 18:14:46 +01:00
echo "$1 Allowed"
else
echo "$1 Not Dropped or Rejected"
fi
done
mutex_off
else
error_message "ERROR: Shorewall is not started"
exit 2
fi
2002-06-04 22:17:46 +02:00
;;
save)
2005-12-03 00:58:57 +01:00
[ -n "$debugging" ] && set -x
2005-07-09 06:45:32 +02:00
case $# in
1)
;;
2)
RESTOREFILE="$2"
validate_restorefile '<restore file>'
;;
*)
usage 1
;;
esac
2006-06-09 18:35:55 +02:00
RESTOREPATH=${VARDIR}/$RESTOREFILE
2005-07-09 06:45:32 +02:00
2006-01-24 16:24:20 +01:00
[ "$nolock" ] || mutex_on
2005-07-09 07:55:29 +02:00
save_config
2003-08-24 03:24:23 +02:00
2006-01-24 16:24:20 +01:00
[ "$nolock" ] || mutex_off
2002-06-04 22:17:46 +02:00
;;
2005-07-09 06:45:32 +02:00
forget)
case $# in
1)
;;
2)
RESTOREFILE="$2"
validate_restorefile '<restore file>'
;;
*)
usage 1
;;
esac
2006-06-09 18:35:55 +02:00
RESTOREPATH=${VARDIR}/$RESTOREFILE
2005-07-09 06:45:32 +02:00
if [ -x $RESTOREPATH ]; then
2005-07-09 07:55:29 +02:00
if [ -x ${RESTOREPATH}-ipsets ]; then
rm -f ${RESTOREPATH}-ipsets
echo " ${RESTOREPATH}-ipsets removed"
fi
2005-07-09 06:45:32 +02:00
rm -f $RESTOREPATH
2006-01-25 18:33:38 +01:00
rm -f ${RESTOREPATH}-iptables
2005-07-09 06:45:32 +02:00
echo " $RESTOREPATH removed"
elif [ -f $RESTOREPATH ]; then
2005-07-09 07:45:05 +02:00
echo " $RESTOREPATH exists and is not a saved Shorewall configuration"
2005-07-09 06:45:32 +02:00
fi
2006-06-09 18:35:55 +02:00
rm -f ${VARDIR}/save
2005-07-09 06:45:32 +02:00
;;
2003-07-05 19:14:21 +02:00
ipcalc)
2005-07-09 06:45:32 +02:00
[ -n "$debugging" ] && set -x
2003-07-05 19:14:21 +02:00
if [ $# -eq 2 ]; then
address=${2%/*}
2003-07-05 19:23:53 +02:00
vlsm=${2#*/}
2003-07-05 19:14:21 +02:00
elif [ $# -eq 3 ]; then
address=$2
2005-07-09 06:45:32 +02:00
vlsm=$(ip_vlsm $3)
2003-07-05 19:14:21 +02:00
else
usage 1
fi
2005-09-30 18:54:24 +02:00
2003-07-05 19:23:53 +02:00
[ -z "$vlsm" ] && exit 2
[ "x$address" = "x$vlsm" ] && usage 2
2003-07-05 19:41:28 +02:00
[ $vlsm -gt 32 ] && echo "Invalid VLSM: /$vlsm" >&2 && exit 2
2003-07-05 19:14:21 +02:00
2003-07-05 19:23:53 +02:00
address=$address/$vlsm
2003-07-05 19:14:21 +02:00
2005-07-09 06:45:32 +02:00
echo " CIDR=$address"
temp=$(ip_netmask $address); echo " NETMASK=$(encodeaddr $temp)"
temp=$(ip_network $address); echo " NETWORK=$temp"
temp=$(broadcastaddress $address); echo " BROADCAST=$temp"
2003-07-05 19:14:21 +02:00
;;
2003-07-06 15:24:23 +02:00
iprange)
2005-12-03 00:58:57 +01:00
[ -n "$debugging" ] && set -x
2003-07-06 15:24:23 +02:00
case $2 in
*.*.*.*-*.*.*.*)
ip_range $2
;;
*)
usage 1
;;
esac
;;
2005-12-03 00:58:57 +01:00
ipdecimal)
[ -n "$debugging" ] && set -x
case $2 in
*.*.*.*)
echo " $(decodeaddr $2)"
;;
*)
echo " $(encodeaddr $2)"
;;
esac
;;
2005-07-09 06:45:32 +02:00
restore)
2006-01-18 21:17:58 +01:00
shift
2006-01-19 01:20:23 +01:00
restore_command $@
2005-07-09 06:45:32 +02:00
;;
2005-08-02 18:46:30 +02:00
call)
2005-12-03 00:58:57 +01:00
[ -n "$debugging" ] && set -x
2003-07-05 19:55:43 +02:00
#
2006-06-09 18:35:55 +02:00
# Undocumented way to call functions in ${SHAREDIR}/functions 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
$@
;;
2003-07-27 20:17:39 +02:00
help)
shift
[ $# -ne 1 ] && usage 1
help $@
;;
2005-07-09 07:55:29 +02:00
safe-restart|safe-start)
2006-01-24 16:24:20 +01:00
shift
safe_commands $@
2005-07-09 07:55:29 +02:00
;;
2002-05-01 01:13:15 +02:00
*)
usage 1
;;
2003-07-05 19:14:21 +02:00
2003-02-23 15:10:37 +01:00
esac