Compare commits

..

4 Commits

Author SHA1 Message Date
Tom Eastep
12b92acef1 Fix compiler crash from unknown interface
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-18 11:05:47 -08:00
Tom Eastep
966597ee9d Correct usage text for 'update'.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-18 11:05:27 -08:00
Tom Eastep
98aa70bcae Correct a typo in the blrules manpages
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-18 11:05:11 -08:00
Tom Eastep
71a8ffca2e Install the correct init script on Fedora 2012-02-17 13:47:49 -08:00
210 changed files with 6436 additions and 13636 deletions

View File

@@ -1,187 +0,0 @@
#!/bin/bash
#
# Shorewall Packet Filtering Firewall RPM configuration program - V4.5
#
# This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt]
#
# (c) 2012 - Tom Eastep (teastep@shorewall.net)
#
# Shorewall documentation is available at http://www.shorewall.net
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of Version 2 of the GNU General Public License
# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Usage: ./configure [ <option>=<setting> ] ...
#
#
################################################################################################
#
# Build updates this
#
VERSION=4.5.2.1
case "$BASH_VERSION" in
[4-9].*)
;;
*)
echo "ERROR: This program requires Bash 4.0 or later" >&2
exit 1
;;
esac
declare -A params
declare -A options
getfileparams() {
while read option; do
case $option in
\#*)
;;
*)
on=${option%=*}
ov=${option#*=}
ov=${ov%#*}
[ -n "$on" ] && options[${on}]="${ov}"
;;
esac
done
return 0
}
for p in $@; do
if [ -n "${p}" ]; then
declare -u pn
pn=${p%=*}
pn=${pn#--}
pv=${p#*=}
if [ -n "${pn}" ]; then
case ${pn} in
VENDOR)
pn=HOST
;;
SHAREDSTATEDIR)
pn=VARDIR
;;
DATADIR)
pn=SHAREDIR
;;
esac
params[${pn}]="${pv}"
else
echo "ERROR: Invalid option ($p)" >&2
exit 1
fi
fi
done
vendor=${params[HOST]}
if [ -z "$vendor" ]; then
case `uname` in
Darwin)
$params[HOST]=apple
rcfile=shorewallrc.apple
;;
cygwin*)
$params[HOST]=cygwin
rcfile=shorewallrc.cygwin
;;
*)
if [ -f /etc/debian_version ]; then
params[HOST]=debian
rcfile=shorewallrc.debian
elif [ -f /etc/redhat-release ]; then
params[HOST]=redhat
rcfile=shorewallrc.redhat
elif [ -f /etc/slackware-version ] ; then
params[HOST]=slackware
rcfile=shorewallrc.slackware
elif [ -f /etc/SuSE-release ]; then
params[HOST]=suse
rcfile=shorewallrc.suse
elif [ -f /etc/arch-release ] ; then
params[HOST]=archlinux
rcfile=shorewallrc.archlinux
else
params[HOST]=linux
rcfile=shorewallrc.default
fi
;;
esac
vendor=${params[HOST]}
elif [ $vendor = linux ]; then
rcfile=shorewallrc.default;
else
rcfile=shorewallrc.$vendor
if [ ! -f $rcfile ]; then
echo "ERROR: $vendor is not a recognized host type" >&2
exit 1
fi
fi
if [ $vendor = linux ]; then
echo "INFO: Creating a generic Linux installation - " `date`;
else
echo "INFO: Creating a ${vendor}-specific installation - " `date`;
fi
echo
getfileparams < $rcfile || exit 1
for p in ${!params[@]}; do
options[${p}]="${params[${p}]}"
done
echo '#' > shorewallrc
echo "# Created by Shorewall Core version $VERSION configure - " `date` >> shorewallrc
echo '#' >> shorewallrc
if [ $# -gt 0 ]; then
echo "# Input: $@" >> shorewallrc
echo '#' >> shorewallrc
fi
for on in \
HOST \
PREFIX \
SHAREDIR \
LIBEXECDIR \
PERLLIBDIR \
CONFDIR \
SBINDIR \
MANDIR \
INITDIR \
INITSOURCE \
INITFILE \
AUXINITSOURCE \
AUXINITFILE \
SYSTEMD \
SYSCONFFILE \
SYSCONFDIR \
SPARSE \
ANNOTATED \
VARDIR
do
echo "$on=${options[${on}]}"
echo "$on=${options[${on}]}" >> shorewallrc
done

View File

@@ -1,154 +0,0 @@
#! /usr/bin/perl -w
#
# Shorewall Packet Filtering Firewall RPM configuration program - V4.5
#
# This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt]
#
# (c) 2012 - Tom Eastep (teastep@shorewall.net)
#
# Shorewall documentation is available at http://www.shorewall.net
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of Version 2 of the GNU General Public License
# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Usage: ./configure.pl <option>=<setting> ...
#
#
################################################################################################
use strict;
#
# Build updates this
#
use constant {
VERSION => '4.5.2.1'
};
my %params;
my %options;
my %aliases = ( VENDOR => 'HOST',
SHAREDSTATEDIR => 'VARDIR',
DATADIR => 'SHAREDIR' );
for ( @ARGV ) {
die "ERROR: Invalid option specification ( $_ )" unless /^(?:--)?(\w+)=(.*)$/;
my $pn = uc $1;
my $pv = $2 || '';
$pn = $aliases{$pn} if exists $aliases{$pn};
$params{$pn} = $pv;
}
my $vendor = $params{HOST};
my $rcfile;
my $rcfilename;
if ( defined $vendor ) {
$rcfilename = $vendor eq 'linux' ? 'shorewallrc.default' : 'shorewallrc.' . $vendor;
die qq("ERROR: $vendor" is not a recognized host type) unless -f $rcfilename;
} else {
if ( -f '/etc/debian_version' ) {
$vendor = 'debian';
$rcfilename = 'shorewallrc.debian';
} elsif ( -f '/etc/redhat-release' ){
$vendor = 'redhat';
$rcfilename = 'shorewallrc.redhat';
} elsif ( -f '/etc/slackware-version' ) {
$vendor = 'slackware';
$rcfilename = 'shorewallrc.slackware';
} elsif ( -f '/etc/SuSE-release' ) {
$vendor = 'suse';
$rcfilename = 'shorewallrc.suse';
} elsif ( -f '/etc/arch-release' ) {
$vendor = 'archlinux';
$rcfilename = 'shorewallrc.archlinux';
} elsif ( `uname` =~ '^Darwin' ) {
$vendor = 'apple';
$rcfilename = 'shorewallrc.apple';
} elsif ( `uname` =~ '^Cygwin' ) {
$vendor = 'cygwin';
$rcfilename = 'shorewallrc.cygwin';
} else {
$vendor = 'linux';
$rcfilename = 'shorewallrc.default';
}
$params{HOST} = $vendor;
}
my @localtime = localtime;
my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
if ( $vendor eq 'linux' ) {
printf "INFO: Creating a generic Linux installation - %s %2d %04d %02d:%02d:%02d\n\n", $abbr[$localtime[4]], $localtime[3], 1900 + $localtime[5] , @localtime[2,1,0];;
} else {
printf "INFO: Creating a %s-specific installation - %s %2d %04d %02d:%02d:%02d\n\n", $vendor, $abbr[$localtime[4]], $localtime[3], 1900 + $localtime[5] , @localtime[2,1,0];;
}
open $rcfile, '<', $rcfilename or die "Unable to open $rcfilename for input: $!";
while ( <$rcfile> ) {
s/\s*#.*//;
unless ( /^\s*$/ ) {
chomp;
die "ERROR: Invalid entry ($_) in $rcfilename, line $." unless /\s*(\w+)=(.*)/;
$options{$1} = $2;
}
}
close $rcfile;
while ( my ( $p, $v ) = each %params ) {
$options{$p} = ${v};
}
my $outfile;
open $outfile, '>', 'shorewallrc' or die "Can't open 'shorewallrc' for output: $!";
printf $outfile "#\n# Created by Shorewall Core version %s configure.pl - %s %2d %04d %02d:%02d:%02d\n#\n", VERSION, $abbr[$localtime[4]], $localtime[3], 1900 + $localtime[5] , @localtime[2,1,0];
print $outfile "# Input: @ARGV\n#\n" if @ARGV;
for ( qw/ HOST
PREFIX
SHAREDIR
LIBEXECDIR
PERLLIBDIR
CONFDIR
SBINDIR
MANDIR
INITDIR
INITSOURCE
INITFILE
AUXINITSOURCE
AUXINITFILE
SYSTEMD
SYSCONFFILE
SYSCONFDIR
SPARSE
ANNOTATED
VARDIR / ) {
my $val = $options{$_} || '';
print "$_=$val\n";
print $outfile "$_=$val\n";
}
close $outfile;
1;

View File

@@ -27,18 +27,14 @@ VERSION=xxx #The Build script inserts the actual version
usage() # $1 = exit status usage() # $1 = exit status
{ {
ME=$(basename $0) ME=$(basename $0)
echo "usage: $ME [ <configuration-file> ] " echo "usage: $ME"
echo " $ME -v" echo " $ME -v"
echo " $ME -h" echo " $ME -h"
echo " $ME -s"
echo " $ME -f"
exit $1 exit $1
} }
fatal_error()
{
echo " ERROR: $@" >&2
exit 1
}
split() { split() {
local ifs local ifs
ifs=$IFS ifs=$IFS
@@ -91,117 +87,39 @@ install_file() # $1 = source $2 = target $3 = mode
run_install $T $OWNERSHIP -m $3 $1 ${2} run_install $T $OWNERSHIP -m $3 $1 ${2}
} }
require() [ -n "$DESTDIR" ] || DESTDIR="$PREFIX"
{
eval [ -n "\$$1" ] || fatal_error "Required option $1 not set"
}
cd "$(dirname $0)"
# #
# Parse the run line # Parse the run line
# #
finished=0 # ARGS is "yes" if we've already parsed an argument
while [ $finished -eq 0 ]; do
option=$1
case "$option" in
-*)
option=${option#-}
while [ -n "$option" ]; do
case $option in
h)
usage 0
;;
v)
echo "Shorewall Firewall Installer Version $VERSION"
exit 0
;;
*)
usage 1
;;
esac
done
shift
;;
*)
finished=1
;;
esac
done
# #
# Read the RC file
#
if [ $# -eq 0 ]; then
if [ -f ./shorewallrc ]; then
. ./shorewallrc
file=./shorewallrc
elif [ -f ~/.shorewallrc ]; then
. ~/.shorewallrc || exit 1
file=~/.shorewallrc
elif [ -f /usr/share/shorewall/shorewallrc ]; then
. /usr/share/shorewall/shorewallrc
file=/usr/share/shorewall/shorewallrc
else
fatal_error "No configuration file specified and /usr/share/shorewall/shorewallrc not found"
fi
elif [ $# -eq 1 ]; then
file=$1
case $file in
/*|.*)
;;
*)
file=./$file || exit 1
;;
esac
. $file
else
usage 1
fi
for var in SHAREDIR LIBEXECDIR PERLLIBDIR CONFDIR SBINDIR VARDIR; do
require $var
done
[ "${INITFILE}" != 'none/' ] && require INITSOURCE && require INITDIR
T="-T" T="-T"
[ -n "${LIBEXEC:=/usr/share}" ]
[ -n "${PERLLIB:=/usr/share/shorewall}" ]
MACHOST=
case "$LIBEXEC" in
/*)
;;
*)
LIBEXEC=/usr/${LIBEXEC}
;;
esac
case "$PERLLIB" in
/*)
;;
*)
PERLLIB=/usr/${PERLLIB}
;;
esac
INSTALLD='-D' INSTALLD='-D'
if [ -z "$BUILD" ]; then case $(uname) in
case $(uname) in CYGWIN*)
cygwin*)
BUILD=cygwin
;;
Darwin)
BUILD=apple
;;
*)
if [ -f /etc/debian_version ]; then
BUILD=debian
elif [ -f /etc/redhat-release ]; then
BUILD=redhat
elif [ -f /etc/slackware-version ] ; then
BUILD=slackware
elif [ -f /etc/SuSE-release ]; then
BUILD=suse
elif [ -f /etc/arch-release ] ; then
BUILD=archlinux
else
BUILD=linux
fi
;;
esac
fi
case $BUILD in
cygwin*)
if [ -z "$DESTDIR" ]; then if [ -z "$DESTDIR" ]; then
DEST= DEST=
INIT= INIT=
@@ -209,16 +127,18 @@ case $BUILD in
OWNER=$(id -un) OWNER=$(id -un)
GROUP=$(id -gn) GROUP=$(id -gn)
CYGWIN=Yes
;; ;;
apple) Darwin)
if [ -z "$DESTDIR" ]; then if [ -z "$DESTDIR" ]; then
DEST= DEST=
INIT= INIT=
SPARSE=Yes
fi fi
[ -z "$OWNER" ] && OWNER=root [ -z "$OWNER" ] && OWNER=root
[ -z "$GROUP" ] && GROUP=wheel [ -z "$GROUP" ] && GROUP=wheel
MAC=Yes
MACHOST=Yes
INSTALLD= INSTALLD=
T= T=
;; ;;
@@ -230,135 +150,137 @@ esac
OWNERSHIP="-o $OWNER -g $GROUP" OWNERSHIP="-o $OWNER -g $GROUP"
finished=0
while [ $finished -eq 0 ]; do
option=$1
case "$option" in
-*)
option=${option#-}
while [ -n "$option" ]; do
case $option in
h)
usage 0
;;
v)
echo "Shorewall Firewall Installer Version $VERSION"
exit 0
;;
a*)
ANNOTATED=Yes
option=${option#a}
;;
p*)
ANNOTATED=
option=${option#p}
;;
*)
usage 1
;;
esac
done
shift
;;
*)
[ -n "$option" ] && usage 1
finished=1
;;
esac
done
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
# #
# Determine where to install the firewall script # Determine where to install the firewall script
# #
[ -n "$HOST" ] || HOST=$BUILD
case "$HOST" in
cygwin)
echo "Installing Cygwin-specific configuration..."
;;
apple)
echo "Installing Mac-specific configuration...";
;;
debian|redhat|slackware|archlinux|linux|suse)
;;
*)
echo "ERROR: Unknown HOST \"$HOST\"" >&2
exit 1;
;;
esac
if [ -z "$file" ]; then
if $HOST = linux; then
file=shorewallrc.default
else
file=shorewallrc.${HOST}
fi
echo "You have not specified a configuration file and ~/.shorewallrc does not exist" >&2
echo "Shorewall-core $VERSION has determined that the $file configuration is appropriate for your system" >&2
echo "Please review the settings in that file. If you wish to change them, make a copy and modify the copy" >&2
echo "Then re-run install.sh passing either $file or the name of your modified copy" >&2
echo "" >&2
echo "Example:" >&2
echo "" >&2
echo " ./install.sh $file" &>2
fi
if [ -n "$DESTDIR" ]; then if [ -n "$DESTDIR" ]; then
if [ $BUILD != cygwin ]; then if [ -z "$CYGWIN" ]; then
if [ `id -u` != 0 ] ; then if [ `id -u` != 0 ] ; then
echo "Not setting file owner/group permissions, not running as root." echo "Not setting file owner/group permissions, not running as root."
OWNERSHIP="" OWNERSHIP=""
fi fi
fi fi
install -d $OWNERSHIP -m 755 ${DESTDIR}/sbin
install -d $OWNERSHIP -m 755 ${DESTDIR}${DEST}
CYGWIN=
MAC=
else
if [ -n "$CYGWIN" ]; then
echo "Installing Cygwin-specific configuration..."
elif [ -n "$MAC" ]; then
echo "Installing Mac-specific configuration..."
else
if [ -f /etc/debian_version ]; then
echo "Installing Debian-specific configuration..."
DEBIAN=yes
elif [ -f /etc/redhat-release ]; then
echo "Installing Redhat/Fedora-specific configuration..."
FEDORA=yes
elif [ -f /etc/slackware-version ] ; then
echo "Installing Slackware-specific configuration..."
DEST="/etc/rc.d"
MANDIR="/usr/man"
SLACKWARE=yes
elif [ -f /etc/arch-release ] ; then
echo "Installing ArchLinux-specific configuration..."
DEST="/etc/rc.d"
INIT="shorewall"
ARCHLINUX=yes
fi
fi
fi fi
#
# Change to the directory containing this script
#
cd "$(dirname $0)"
echo "Installing Shorewall Core Version $VERSION" echo "Installing Shorewall Core Version $VERSION"
# #
# Create directories # Create /usr/share/shorewall
# #
mkdir -p ${DESTDIR}${LIBEXECDIR}/shorewall mkdir -p ${DESTDIR}${LIBEXEC}/shorewall
chmod 755 ${DESTDIR}${LIBEXECDIR}/shorewall chmod 755 ${DESTDIR}/usr/share/shorewall
mkdir -p ${DESTDIR}${SHAREDIR}/shorewall
chmod 755 ${DESTDIR}${SHAREDIR}/shorewall
mkdir -p ${DESTDIR}${CONFDIR}
chmod 755 ${DESTDIR}${CONFDIR}
if [ -n "${SYSCONFDIR}" ]; then
mkdir -p ${DESTDIR}${SYSCONFDIR}
chmod 755 ${DESTDIR}${SYSCONFDIR}
fi
if [ -n "${SYSTEMD}" ]; then
mkdir -p ${DESTDIR}${SYSTEMD}
chmod 755 ${DESTDIR}${SYSTEMD}
fi
mkdir -p ${DESTDIR}${SBINDIR}
chmod 755 ${DESTDIR}${SBINDIR}
mkdir -p ${DESTDIR}${MANDIR}
chmod 755 ${DESTDIR}${MANDIR}
if [ -n "${INITFILE}" ]; then
mkdir -p ${DESTDIR}${INITDIR}
chmod 755 ${DESTDIR}${INITDIR}
if [ -n "$AUXINITSOURCE" -a -f "$AUXINITSOURCE" ]; then
install_file $AUXINITSOURCE ${DESTDIR}${INITDIR}/$AUXINITFILE 0544
[ "${SHAREDIR}" = /usr/share ] || eval sed -i \'s\|/usr/share/\|${SHAREDIR}/\|\' ${DESTDIR}${INITDIR}/$AUXINITFILE
echo "$Product script installed in ${DESTDIR}${INITDIR}/$AUXINITFILE"
fi
fi
#
# Note: ${VARDIR} is created at run-time since it has always been
# a relocatable directory on a per-product basis
# #
# Install wait4ifup # Install wait4ifup
# #
install_file wait4ifup ${DESTDIR}${LIBEXECDIR}/shorewall/wait4ifup 0755 install_file wait4ifup ${DESTDIR}${LIBEXEC}/shorewall/wait4ifup 0755
echo echo
echo "wait4ifup installed in ${DESTDIR}${LIBEXECDIR}/shorewall/wait4ifup" echo "wait4ifup installed in ${DESTDIR}${LIBEXEC}/shorewall/wait4ifup"
# #
# Install the libraries # Install the libraries
# #
for f in lib.* ; do for f in lib.* ; do
install_file $f ${DESTDIR}${SHAREDIR}/shorewall/$f 0644 install_file $f ${DESTDIR}/usr/share/shorewall/$f 0644
echo "Library ${f#*.} file installed as ${DESTDIR}${SHAREDIR}/shorewall/$f" echo "Library ${f#*.} file installed as ${DESTDIR}/usr/share/shorewall/$f"
done done
if [ -z "$MACHOST" ]; then
eval sed -i \'s\|g_libexec=.\*\|g_libexec=$LIBEXEC\|\' ${DESTDIR}/usr/share/shorewall/lib.cli
eval sed -i \'s\|g_perllib=.\*\|g_perllib=$PERLLIB\|\' ${DESTDIR}/usr/share/shorewall/lib.cli
else
eval sed -i \'\' -e \'s\|g_libexec=.\*\|g_libexec=$LIBEXEC\|\' ${DESTDIR}/usr/share/shorewall/lib.cli
eval sed -i \'\' -e \'s\|g_perllib=.\*\|g_perllib=$PERLLIB\|\' ${DESTDIR}/usr/share/shorewall/lib.cli
fi
# #
# Symbolically link 'functions' to lib.base # Symbolically link 'functions' to lib.base
# #
ln -sf lib.base ${DESTDIR}${SHAREDIR}/shorewall/functions ln -sf lib.base ${DESTDIR}/usr/share/shorewall/functions
# #
# Create the version file # Create the version file
# #
echo "$VERSION" > ${DESTDIR}${SHAREDIR}/shorewall/coreversion echo "$VERSION" > ${DESTDIR}/usr/share/shorewall/coreversion
chmod 644 ${DESTDIR}${SHAREDIR}/shorewall/coreversion chmod 644 ${DESTDIR}/usr/share/shorewall/coreversion
[ $file != "${SHAREDIR}/shorewall/shorewallrc" ] && cp $file ${DESTDIR}${SHAREDIR}/shorewall/shorewallrc
[ -z "${DESTDIR}" ] && [ ! -f ~/.shorewallrc ] && cp ${SHAREDIR}/shorewall/shorewallrc ~/.shorewallrc
if [ ${SHAREDIR} != /usr/share ]; then
for f in lib.*; do
if [ $BUILD != apple ]; then
eval sed -i \'s\|/usr/share/\|${SHAREDIR}/\|\' ${DESTDIR}/${SHAREDIR}/shorewall/$f
else
eval sed -i \'\' -e \'s\|/usr/share/\|${SHAREDIR}/\|\' ${DESTDIR}/${SHAREDIR}/shorewall/$f
fi
done
fi
# #
# Report Success # Report Success
# #

View File

@@ -27,57 +27,50 @@
# and /usr/share/shorewall[6]-lite/shorecap. # and /usr/share/shorewall[6]-lite/shorecap.
# #
SHOREWALL_LIBVERSION=40502 SHOREWALL_LIBVERSION=40500
SHOREWALL_CAPVERSION=40504 SHOREWALL_CAPVERSION=40501
[ -n "${g_program:=shorewall}" ] [ -n "${g_program:=shorewall}" ]
if [ -z "$g_readrc" ]; then
#
# This is modified by the installer when ${SHAREDIR} != /usr/share
#
. /usr/share/shorewall/shorewallrc
g_libexec="$LIBEXECDIR"
g_sharedir="$SHAREDIR"/$g_program
g_sbindir="$SBINDIR"
g_perllib="$PERLLIBDIR"
g_vardir="$VARDIR"
g_confdir="$CONFDIR"/$g_program
g_readrc=1
fi
g_basedir=${SHAREDIR}/shorewall
case $g_program in case $g_program in
shorewall) shorewall)
SHAREDIR=/usr/share/shorewall
CONFDIR=/etc/shorewall
g_product="Shorewall" g_product="Shorewall"
g_family=4 g_family=4
g_tool= g_tool=
g_basedir=/usr/share/shorewall
g_lite= g_lite=
;; ;;
shorewall6) shorewall6)
SHAREDIR=/usr/share/shorewall6
CONFDIR=/etc/shorewall6
g_product="Shorewall6" g_product="Shorewall6"
g_family=6 g_family=6
g_tool= g_tool=
g_basedir=/usr/share/shorewall
g_lite= g_lite=
;; ;;
shorewall-lite) shorewall-lite)
SHAREDIR=/usr/share/shorewall-lite
CONFDIR=/etc/shorewall-lite
g_product="Shorewall Lite" g_product="Shorewall Lite"
g_family=4 g_family=4
g_tool=iptables g_tool=iptables
g_basedir=/usr/share/shorewall-lite
g_lite=Yes g_lite=Yes
;; ;;
shorewall6-lite) shorewall6-lite)
SHAREDIR=/usr/share/shorewall6-lite
CONFDIR=/etc/shorewall6-lite
g_product="Shorewall6 Lite" g_product="Shorewall6 Lite"
g_family=6 g_family=6
g_tool=ip6tables g_tool=ip6tables
g_basedir=/usr/share/shorewall6-lite
g_lite=Yes g_lite=Yes
;; ;;
esac esac
VARDIR=${VARDIR}/${g_program}
# #
# Conditionally produce message # Conditionally produce message
# #
@@ -130,6 +123,71 @@ combine_list()
echo $o echo $o
} }
#
# Call this function to assert mutual exclusion with Shorewall. If you invoke the
# /sbin/shorewall program while holding mutual exclusion, you should pass "nolock" as
# the first argument. Example "shorewall nolock refresh"
#
# This function uses the lockfile utility from procmail if it exists.
# Otherwise, it uses a somewhat race-prone algorithm to attempt to simulate the
# behavior of lockfile.
#
mutex_on()
{
local try
try=0
local lockf
lockf=${LOCKFILE:=${VARDIR}/lock}
local lockpid
MUTEX_TIMEOUT=${MUTEX_TIMEOUT:-60}
if [ $MUTEX_TIMEOUT -gt 0 ]; then
[ -d ${VARDIR} ] || mkdir -p ${VARDIR}
if [ -f $lockf ]; then
lockpid=`cat ${lockf} 2> /dev/null`
if [ -z "$lockpid" -o $lockpid = 0 ]; then
rm -f ${lockf}
error_message "WARNING: Stale lockfile ${lockf} removed"
elif ! qt ps p ${lockpid}; then
rm -f ${lockf}
error_message "WARNING: Stale lockfile ${lockf} from pid ${lockpid} removed"
fi
fi
if qt mywhich lockfile; then
lockfile -${MUTEX_TIMEOUT} -r1 ${lockf}
chmod u+w ${lockf}
echo $$ > ${lockf}
chmod u-w ${lockf}
else
while [ -f ${lockf} -a ${try} -lt ${MUTEX_TIMEOUT} ] ; do
sleep 1
try=$((${try} + 1))
done
if [ ${try} -lt ${MUTEX_TIMEOUT} ] ; then
# Create the lockfile
echo $$ > ${lockf}
else
echo "Giving up on lock file ${lockf}" >&2
fi
fi
fi
}
#
# Call this function to release mutual exclusion
#
mutex_off()
{
rm -f ${LOCKFILE:=${VARDIR}/lock}
}
[ -z "$LEFTSHIFT" ] && . /usr/share/shorewall/lib.common
# #
# Validate an IP address # Validate an IP address
# #
@@ -258,8 +316,6 @@ ip_range_explicit() {
done done
} }
[ -z "$LEFTSHIFT" ] && . ${g_basedir}/lib.common
# #
# Netmask to VLSM # Netmask to VLSM
# #
@@ -288,7 +344,7 @@ ip_vlsm() {
# #
ensure_config_path() { ensure_config_path() {
local F local F
F=${g_sharedir}/configpath F=${SHAREDIR}/configpath
if [ -z "$CONFIG_PATH" ]; then if [ -z "$CONFIG_PATH" ]; then
[ -f $F ] || { echo " ERROR: $F does not exist"; exit 2; } [ -f $F ] || { echo " ERROR: $F does not exist"; exit 2; }
. $F . $F
@@ -399,14 +455,14 @@ mktempfile() {
else else
case "$MKTEMP" in case "$MKTEMP" in
BSD) BSD)
mktemp ${TMPDIR:-/tmp}/shorewall.XXXXXX mktemp /tmp/shorewall.XXXXXX
;; ;;
STD) STD)
mktemp -t shorewall.XXXXXX mktemp -t shorewall.XXXXXX
;; ;;
None) None)
rm -f ${TMPDIR:-/tmp}/shorewall-$$ rm -f /tmp/shorewall-$$
> ${TMPDIR:-}/shorewall-$$ && echo ${TMPDIR:-/tmp}/shorewall-$$ > /tmp/shorewall-$$ && echo /tmp/shorewall-$$
;; ;;
*) *)
error_message "ERROR:Internal error in mktempfile" error_message "ERROR:Internal error in mktempfile"

View File

@@ -23,25 +23,7 @@
# This library contains the command processing code common to /sbin/shorewall[6] and # This library contains the command processing code common to /sbin/shorewall[6] and
# /sbin/shorewall[6]-lite. # /sbin/shorewall[6]-lite.
# #
. /usr/share/shorewall/lib.base
if [ -z "$g_readrc" ]; then
#
# This is modified by the installer when ${SHAREDIR} <> /usr/share
#
. /usr/share/shorewall/shorewallrc
g_libexec="$LIBEXECDIR"
g_sharedir="$SHAREDIR"/$g_program
g_sbindir="$SBINDIR"
g_perllib="$PERLLIBDIR"
g_vardir="$VARDIR"
g_confdir="$CONFDIR"/$g_program
g_readrc=1
fi
. ${SHAREDIR}/shorewall/lib.base
# #
# Fatal Error # Fatal Error
# #
@@ -434,7 +416,7 @@ save_config() {
# order we all know and love # order we all know and love
# #
sort_routes() { sort_routes() {
local dest local dest
local rest local rest
local crvsn local crvsn
@@ -456,28 +438,16 @@ sort_routes() {
done | sort -r | while read dest rest; do echo $rest; done done | sort -r | while read dest rest; do echo $rest; done
} }
#
# Isolate the table in the routing rules being read from stdin.
# Piping through sed to remove trailing whitespace works around
# recent 'features' in dash and ip.
#
find_tables() {
sed -r 's/[[:space:]]+$//' | while read rule; do
echo ${rule##* }
done
}
# #
# Show routing configuration # Show routing configuration
# #
show_routing() { show_routing() {
local rule
local table
if [ -n "$(ip -$g_family rule list)" ]; then if [ -n "$(ip -$g_family rule list)" ]; then
heading "Routing Rules" heading "Routing Rules"
ip -$g_family rule list ip -$g_family rule list
ip -$g_family rule list | find_tables | sort -u | while read table; do ip -$g_family rule list | while read rule; do
echo ${rule##* }
done | sort -u | while read table; do
heading "Table $table:" heading "Table $table:"
if [ $g_family -eq 6 ]; then if [ $g_family -eq 6 ]; then
ip -$g_family -o route list table $table | fgrep -v cache ip -$g_family -o route list table $table | fgrep -v cache
@@ -573,11 +543,11 @@ version_command() {
[ $# -gt 0 ] && usage 1 [ $# -gt 0 ] && usage 1
if [ -n "$all" ]; then if [ -n "$all" ]; then
echo "shorewall-core: $(cat $g_sharedir/coreversion)" echo "shorewall-core: $(cat /usr/share/shorewall/coreversion)"
for product in shorewall shorewall6 shorewall-lite shorewall6-lite shorewall-init; do for product in shorewall shorewall6 shorewall-lite shorewall6-lite shorewall-init; do
if [ -f ${SHAREDIR}/$product/version ]; then if [ -f /usr/share/$product/version ]; then
echo "$product: $(cat ${SHAREDIR}/$product/version)" echo "$product: $(cat /usr/share/$product/version)"
fi fi
done done
else else
@@ -867,20 +837,16 @@ show_command() {
show_routing show_routing
;; ;;
config) config)
. ${g_sharedir}/configpath . ${SHAREDIR}/configpath
if [ -n "$g_filemode" ]; then if [ -n "$g_filemode" ]; then
echo "CONFIG_PATH=$CONFIG_PATH" echo "CONFIG_PATH=$CONFIG_PATH"
echo "VARDIR=$VARDIR" echo "VARDIR=$VARDIR"
echo "LIBEXEC=$g_libexec" echo "LIBEXEC=$g_libexec"
echo "SBINDIR=$g_sbindir" [ -n "$g_lite" ] && ${VARDIR} ne /var/lib/$program && echo "LITEDIR=${VARDIR}"
echo "CONFDIR=${CONFDIR}"
[ -n "$g_lite" ] && [ ${VARDIR} != /var/lib/$g_program ] && echo "LITEDIR=${VARDIR}"
else else
echo "Default CONFIG_PATH is $CONFIG_PATH" echo "Default CONFIG_PATH is $CONFIG_PATH"
echo "Default VARDIR is /var/lib/$g_program" echo "Default VARDIR is /var/lib/$g_program"
echo "LIBEXEC is $g_libexec" echo "LIBEXEC is $g_libexec"
echo "SBINDIR is $g_sbindir"
echo "CONFDIR is ${CONFDIR}"
[ -n "$g_lite" ] && [ ${VARDIR} != /var/lib/$g_program ] && echo "LITEDIR is ${VARDIR}" [ -n "$g_lite" ] && [ ${VARDIR} != /var/lib/$g_program ] && echo "LITEDIR is ${VARDIR}"
fi fi
;; ;;
@@ -941,10 +907,10 @@ show_command() {
echo "forwardUPnP # Allow traffic that upnpd has redirected from" echo "forwardUPnP # Allow traffic that upnpd has redirected from"
echo "rejNotSyn # Silently Reject Non-syn TCP packets" echo "rejNotSyn # Silently Reject Non-syn TCP packets"
if [ -f ${g_confdir}/actions ]; then if [ -f ${CONFDIR}/actions ]; then
cat ${g_sharedir}/actions.std ${g_confdir}/actions | grep -Ev '^\#|^$' cat ${SHAREDIR}/actions.std ${CONFDIR}/actions | grep -Ev '^\#|^$'
else else
grep -Ev '^\#|^$' ${g_sharedir}/actions.std grep -Ev '^\#|^$' ${SHAREDIR}/actions.std
fi fi
return return
@@ -1029,12 +995,12 @@ perip_accounting() {
if [ -n "$hnames" ]; then if [ -n "$hnames" ]; then
for hname in $hnames; do for hname in $hnames; do
iptaccount -l $hname | egrep '^IP:|^Show' iptaccount -l $hname | egrep '^IP:|^Show'
echo echo
done done
else else
echo " No IP Accounting Tables Defined" echo " No IP Accounting Tables Defined"
echo echo
fi fi
else else
echo " iptaccount is not installed" echo " iptaccount is not installed"
@@ -1142,11 +1108,11 @@ do_dump_command() {
echo "$g_product $SHOREWALL_VERSION Dump at $g_hostname - $(date)" echo "$g_product $SHOREWALL_VERSION Dump at $g_hostname - $(date)"
echo echo
if [ $g_family -eq 6 ] && [ -f ${SHAREDIR}/shorewall/version ]; then if [ $g_family -eq 6 ] && [ -f /usr/share/shorewall/version ]; then
echo " Shorewall $(cat ${SHAREDIR}/shorewall/version)" echo " Shorewall $(cat /usr/share/shorewall/version)"
echo echo
fi fi
show_status
show_reset show_reset
host=$(echo $g_hostname | sed 's/\..*$//') host=$(echo $g_hostname | sed 's/\..*$//')
$g_tool -L $g_ipt_options $g_tool -L $g_ipt_options
@@ -1259,7 +1225,7 @@ do_dump_command() {
netstat -${g_family}tunap netstat -${g_family}tunap
else else
netstat -tunap netstat -tunap
fi fi
if [ -n "$TC_ENABLED" ]; then if [ -n "$TC_ENABLED" ]; then
heading "Traffic Control" heading "Traffic Control"
@@ -1942,7 +1908,6 @@ determine_capabilities() {
IPRANGE_MATCH= IPRANGE_MATCH=
RECENT_MATCH= RECENT_MATCH=
OWNER_MATCH= OWNER_MATCH=
OWNER_NAME_MATCH=
IPSET_MATCH= IPSET_MATCH=
OLD_IPSET_MATCH= OLD_IPSET_MATCH=
IPSET_V5= IPSET_V5=
@@ -1992,9 +1957,6 @@ determine_capabilities() {
CT_TARGET= CT_TARGET=
STATISTIC_MATCH= STATISTIC_MATCH=
IMQ_TARGET= IMQ_TARGET=
DSCP_MATCH=
DSCP_TARGET=
GEOIP_MATCH=
chain=fooX$$ chain=fooX$$
@@ -2037,11 +1999,11 @@ determine_capabilities() {
qt $g_tool -A $chain -m conntrack --ctorigdst 192.168.1.1 -j ACCEPT && CONNTRACK_MATCH=Yes qt $g_tool -A $chain -m conntrack --ctorigdst 192.168.1.1 -j ACCEPT && CONNTRACK_MATCH=Yes
else else
qt $g_tool -A $chain -m conntrack --ctorigdst ::1 -j ACCEPT && CONNTRACK_MATCH=Yes qt $g_tool -A $chain -m conntrack --ctorigdst ::1 -j ACCEPT && CONNTRACK_MATCH=Yes
fi fi
if [ -n "$CONNTRACK_MATCH" ]; then if [ -n "$CONNTRACK_MATCH" ]; then
qt $g_tool -A $chain -m conntrack -p tcp --ctorigdstport 22 -j ACCEPT && NEW_CONNTRACK_MATCH=Yes qt $g_tool -A $chain -m conntrack -p tcp --ctorigdstport 22 -j ACCEPT && NEW_CONNTRACK_MATCH=Yes
if [ $g_family -eq 4 ]; then if [ $g_family -eq 4 ]; then
qt $g_tool -A $chain -m conntrack ! --ctorigdst 1.2.3.4 || OLD_CONNTRACK_MATCH=Yes qt $g_tool -A $chain -m conntrack ! --ctorigdst 1.2.3.4 || OLD_CONNTRACK_MATCH=Yes
else else
@@ -2082,11 +2044,6 @@ determine_capabilities() {
qt $g_tool -A $chain -m recent --update -j ACCEPT && RECENT_MATCH=Yes qt $g_tool -A $chain -m recent --update -j ACCEPT && RECENT_MATCH=Yes
qt $g_tool -A $chain -m owner --uid-owner 0 -j ACCEPT && OWNER_MATCH=Yes qt $g_tool -A $chain -m owner --uid-owner 0 -j ACCEPT && OWNER_MATCH=Yes
local name
name=$(id -un 2> /dev/null)
[ -n "$name" ] && qt $g_tool -A $chain -m owner --uid-owner $name -j ACCEPT && OWNER_NAME_MATCH=Yes
if qt $g_tool -A $chain -m connmark --mark 2 -j ACCEPT; then if qt $g_tool -A $chain -m connmark --mark 2 -j ACCEPT; then
CONNMARK_MATCH=Yes CONNMARK_MATCH=Yes
qt $g_tool -A $chain -m connmark --mark 2/0xFF -j ACCEPT && XCONNMARK_MATCH=Yes qt $g_tool -A $chain -m connmark --mark 2/0xFF -j ACCEPT && XCONNMARK_MATCH=Yes
@@ -2124,14 +2081,10 @@ determine_capabilities() {
qt $g_tool -t mangle -A $chain -j CLASSIFY --set-class 1:1 && CLASSIFY_TARGET=Yes qt $g_tool -t mangle -A $chain -j CLASSIFY --set-class 1:1 && CLASSIFY_TARGET=Yes
qt $g_tool -t mangle -A $chain -j IPMARK --addr src && IPMARK_TARGET=Yes qt $g_tool -t mangle -A $chain -j IPMARK --addr src && IPMARK_TARGET=Yes
qt $g_tool -t mangle -A $chain -p tcp -j TPROXY --on-port 0 --tproxy-mark 1 && TPROXY_TARGET=Yes qt $g_tool -t mangle -A $chain -p tcp -j TPROXY --on-port 0 --tproxy-mark 1 && TPROXY_TARGET=Yes
qt $g_tool -t mangle -A $chain -j IMQ --todev 0 && IMQ_TARGET=Yes
qt $g_tool -t mangle -A $chain -m dscp --dscp 0 && DSCP_MATCH=Yes
qt $g_tool -t mangle -A $chain -j DSCP --set-dscp 0 && DSCP_TARGET=Yes
qt $g_tool -t mangle -F $chain qt $g_tool -t mangle -F $chain
qt $g_tool -t mangle -X $chain qt $g_tool -t mangle -X $chain
qt $g_tool -t mangle -L FORWARD -n && MANGLE_FORWARD=Yes qt $g_tool -t mangle -L FORWARD -n && MANGLE_FORWARD=Yes
qt $g_tool -t mangle -A $chain -j IMQ --todev 0 && IMQ_TARGET=Yes
fi fi
qt $g_tool -t raw -L -n && RAW_TABLE=Yes qt $g_tool -t raw -L -n && RAW_TABLE=Yes
@@ -2203,7 +2156,6 @@ determine_capabilities() {
qt $g_tool -A $chain -j NFLOG && NFLOG_TARGET=Yes qt $g_tool -A $chain -j NFLOG && NFLOG_TARGET=Yes
qt $g_tool -A $chain -j MARK --set-mark 5 && MARK_ANYWHERE=Yes qt $g_tool -A $chain -j MARK --set-mark 5 && MARK_ANYWHERE=Yes
qt $g_tool -A $chain -m statistic --mode nth --every 2 --packet 1 && STATISTIC_MATCH=Yes qt $g_tool -A $chain -m statistic --mode nth --every 2 --packet 1 && STATISTIC_MATCH=Yes
qt $g_tool -A $chain -m geoip --src-cc US && GEOIP_MATCH=Yes
if [ $g_family -eq 4 ]; then if [ $g_family -eq 4 ]; then
qt $g_tool -A $chain -j ACCOUNT --addr 192.168.1.0/29 --tname $chain && ACCOUNT_TARGET=Yes qt $g_tool -A $chain -j ACCOUNT --addr 192.168.1.0/29 --tname $chain && ACCOUNT_TARGET=Yes
@@ -2225,10 +2177,10 @@ determine_capabilities() {
[ -n "$IP" ] && $IP rule add help 2>&1 | grep -q /MASK && FWMARK_RT_MASK=Yes [ -n "$IP" ] && $IP rule add help 2>&1 | grep -q /MASK && FWMARK_RT_MASK=Yes
CAPVERSION=$SHOREWALL_CAPVERSION CAPVERSION=$SHOREWALL_CAPVERSION
KERNELVERSION=$(uname -r 2> /dev/null | sed -e 's/-.*//') KERNELVERSION=$(uname -r 2> /dev/null | sed -e 's/-.*//')
case "$KERNELVERSION" in case "$KERNELVERSION" in
*.*.*) *.*.*)
KERNELVERSION=$(printf "%d%02d%02d" $(echo $KERNELVERSION | sed -e 's/^\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/\1 \2 \3/g')) KERNELVERSION=$(printf "%d%02d%02d" $(echo $KERNELVERSION | sed -e 's/^\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/\1 \2 \3/g'))
;; ;;
@@ -2251,83 +2203,79 @@ report_capabilities() {
if [ $VERBOSITY -gt 1 ]; then if [ $VERBOSITY -gt 1 ]; then
echo "$g_product has detected the following iptables/netfilter capabilities:" echo "$g_product has detected the following iptables/netfilter capabilities:"
report_capability "NAT (NAT_ENABLED)" $NAT_ENABLED report_capability "NAT" $NAT_ENABLED
report_capability "Packet Mangling (MANGLE_ENABLED)" $MANGLE_ENABLED report_capability "Packet Mangling" $MANGLE_ENABLED
report_capability "Multi-port Match (MULTIPORT)" $MULTIPORT report_capability "Multi-port Match" $MULTIPORT
[ -n "$MULTIPORT" ] && report_capability "Extended Multi-port Match (XMULIPORT)" $XMULTIPORT [ -n "$MULTIPORT" ] && report_capability "Extended Multi-port Match" $XMULTIPORT
report_capability "Connection Tracking Match (CONNTRACK_MATCH)" $CONNTRACK_MATCH report_capability "Connection Tracking Match" $CONNTRACK_MATCH
if [ -n "$CONNTRACK_MATCH" ]; then if [ -n "$CONNTRACK_MATCH" ]; then
report_capability "Extended Connection Tracking Match Support (NEW_CONNTRACK_MATCH)" $NEW_CONNTRACK_MATCH report_capability "Extended Connection Tracking Match Support" $NEW_CONNTRACK_MATCH
[ -n "$OLD_CONNTRACK_MATCH" ] && report_capability "Old Connection Tracking Match Syntax (OLD_CONNTRACK_MATCH)" $OLD_CONNTRACK_MATCH [ -n "$OLD_CONNTRACK_MATCH" ] && report_capability "Old Connection Tracking Match Syntax" $OLD_CONNTRACK_MATCH
fi fi
report_capability "Packet Type Match (USEPKTTYPE)" $USEPKTTYPE report_capability "Packet Type Match" $USEPKTTYPE
report_capability "Policy Match (POLICY_MATCH)" $POLICY_MATCH report_capability "Policy Match" $POLICY_MATCH
report_capability "Physdev Match (PHYSDEV_MATCH)" $PHYSDEV_MATCH report_capability "Physdev Match" $PHYSDEV_MATCH
report_capability "Physdev-is-bridged Support (PHYSDEV_BRIDGE)" $PHYSDEV_BRIDGE report_capability "Physdev-is-bridged Support" $PHYSDEV_BRIDGE
report_capability "Packet length Match (LENGTH_MATCH)" $LENGTH_MATCH report_capability "Packet length Match" $LENGTH_MATCH
report_capability "IP range Match(IPRANGE_MATCH)" $IPRANGE_MATCH report_capability "IP range Match" $IPRANGE_MATCH
report_capability "Recent Match (RECENT_MATCH)" $RECENT_MATCH report_capability "Recent Match" $RECENT_MATCH
report_capability "Owner Match (OWNER_MATCH)" $OWNER_MATCH report_capability "Owner Match" $OWNER_MATCH
report_capability "Owner Name Match (OWNER_NAME_MATCH)" $OWNER_NAME_MATCH
if [ -n "$IPSET_MATCH" ]; then if [ -n "$IPSET_MATCH" ]; then
report_capability "Ipset Match (IPSET_MATCH)" $IPSET_MATCH report_capability "Ipset Match" $IPSET_MATCH
[ -n "$OLD_IPSET_MATCH" ] && report_capability "OLD_Ipset Match (OLD_IPSET_MATCH)" $OLD_IPSET_MATCH [ -n "$OLD_IPSET_MATCH" ] && report_capability "OLD_Ipset Match" $OLD_IPSET_MATCH
fi fi
report_capability "CONNMARK Target (CONNMARK)" $CONNMARK report_capability "CONNMARK Target" $CONNMARK
[ -n "$CONNMARK" ] && report_capability "Extended CONNMARK Target (XCONNMARK)" $XCONNMARK [ -n "$CONNMARK" ] && report_capability "Extended CONNMARK Target" $XCONNMARK
report_capability "Connmark Match (CONNMARK_MATCH)" $CONNMARK_MATCH report_capability "Connmark Match" $CONNMARK_MATCH
[ -n "$CONNMARK_MATCH" ] && report_capability "Extended Connmark Match (XCONNMARK_MATCH)" $XCONNMARK_MATCH [ -n "$CONNMARK_MATCH" ] && report_capability "Extended Connmark Match" $XCONNMARK_MATCH
report_capability "Raw Table (RAW_TABLE)" $RAW_TABLE report_capability "Raw Table" $RAW_TABLE
report_capability "Rawpost Table (RAWPOST_TABLE)" $RAWPOST_TABLE report_capability "Rawpost Table" $RAWPOST_TABLE
report_capability "IPP2P Match (IPP2P_MATCH)" $IPP2P_MATCH report_capability "IPP2P Match" $IPP2P_MATCH
[ -n "$OLD_IPP2P_MATCH" ] && report_capability "Old IPP2P Match Syntax (OLD_IPP2P_MATCH)" $OLD_IPP2P_MATCH [ -n "$OLD_IPP2P_MATCH" ] && report_capability "Old IPP2P Match Syntax" $OLD_IPP2P_MATCH
report_capability "CLASSIFY Target (CLASSIFY_TARGET)" $CLASSIFY_TARGET report_capability "CLASSIFY Target" $CLASSIFY_TARGET
report_capability "Extended REJECT (ENHANCED_REJECT)" $ENHANCED_REJECT report_capability "Extended REJECT" $ENHANCED_REJECT
report_capability "Repeat match (KLUDGEFREE)" $KLUDGEFREE report_capability "Repeat match" $KLUDGEFREE
report_capability "MARK Target (MARK)" $MARK report_capability "MARK Target" $MARK
[ -n "$MARK" ] && report_capability "Extended MARK Target (XMARK)" $XMARK [ -n "$MARK" ] && report_capability "Extended MARK Target" $XMARK
[ -n "$XMARK" ] && report_capability "Extended MARK Target 2 (EXMARK)" $EXMARK [ -n "$XMARK" ] && report_capability "Extended MARK Target 2" $EXMARK
report_capability "Mangle FORWARD Chain (MANGLE_FORWARD)" $MANGLE_FORWARD report_capability "Mangle FORWARD Chain" $MANGLE_FORWARD
report_capability "Comments (COMMENTS)" $COMMENTS report_capability "Comments" $COMMENTS
report_capability "Address Type Match (ADDRTYPE)" $ADDRTYPE report_capability "Address Type Match" $ADDRTYPE
report_capability "TCPMSS Match (TCPMSS_MATCH)" $TCPMSS_MATCH report_capability "TCPMSS Match" $TCPMSS_MATCH
report_capability "Hashlimit Match (HASHLIMIT_MATCH)" $HASHLIMIT_MATCH report_capability "Hashlimit Match" $HASHLIMIT_MATCH
[ -n "$OLD_HL_MATCH" ] && report_capability "Old Hashlimit Match (OLD_HL_MATCH)" $OLD_HL_MATCH [ -n "$OLD_HL_MATCH" ] && report_capability "Old Hashlimit Match" $OLD_HL_MATCH
report_capability "NFQUEUE Target (NFQUEUE_TARGET)" $NFQUEUE_TARGET report_capability "NFQUEUE Target" $NFQUEUE_TARGET
report_capability "Realm Match (REALM_MATCH)" $REALM_MATCH report_capability "Realm Match" $REALM_MATCH
report_capability "Helper Match (HELPER_MATCH)" $HELPER_MATCH report_capability "Helper Match" $HELPER_MATCH
report_capability "Connlimit Match (CONNLIMIT_MATCH)" $CONNLIMIT_MATCH report_capability "Connlimit Match" $CONNLIMIT_MATCH
report_capability "Time Match (TIME_MATCH)" $TIME_MATCH report_capability "Time Match" $TIME_MATCH
report_capability "Goto Support (GOTO_TARGET)" $GOTO_TARGET report_capability "Goto Support" $GOTO_TARGET
report_capability "LOGMARK Target (LOGMARK_TARGET)" $LOGMARK_TARGET report_capability "LOGMARK Target" $LOGMARK_TARGET
report_capability "IPMARK Target (IPMARK_TARGET)" $IPMARK_TARGET report_capability "IPMARK Target" $IPMARK_TARGET
report_capability "LOG Target (LOG_TARGET)" $LOG_TARGET report_capability "LOG Target" $LOG_TARGET
report_capability "ULOG Target (ULOG_TARGET)" $ULOG_TARGET report_capability "ULOG Target" $ULOG_TARGET
report_capability "NFLOG Target (NFLOG_TARGET)" $NFLOG_TARGET report_capability "NFLOG Target" $NFLOG_TARGET
report_capability "Persistent SNAT (PERSISTENT_SNAT)" $PERSISTENT_SNAT report_capability "Persistent SNAT" $PERSISTENT_SNAT
report_capability "TPROXY Target (TPROXY_TARGET)" $TPROXY_TARGET report_capability "TPROXY Target" $TPROXY_TARGET
report_capability "FLOW Classifier (FLOW_FILTER)" $FLOW_FILTER report_capability "FLOW Classifier" $FLOW_FILTER
report_capability "fwmark route mask (FWMARK_RT_MASK)" $FWMARK_RT_MASK report_capability "fwmark route mask" $FWMARK_RT_MASK
report_capability "Mark in any table (MARK_ANYWHERE)" $MARK_ANYWHERE report_capability "Mark in any table" $MARK_ANYWHERE
report_capability "Header Match (HEADER_MATCH)" $HEADER_MATCH report_capability "Header Match" $HEADER_MATCH
report_capability "ACCOUNT Target (ACCOUNT_TARGET)" $ACCOUNT_TARGET report_capability "ACCOUNT Target" $ACCOUNT_TARGET
report_capability "AUDIT Target (AUDIT_TARGET)" $AUDIT_TARGET report_capability "AUDIT Target" $AUDIT_TARGET
report_capability "ipset V5 (IPSET_V5)" $IPSET_V5 report_capability "ipset V5" $IPSET_V5
report_capability "Condition Match (CONDITION_MATCH)" $CONDITION_MATCH report_capability "Condition Match" $CONDITION_MATCH
report_capability "Statistic Match (STATISTIC_MATCH)" $STATISTIC_MATCH report_capability "Statistic Match" $STATISTIC_MATCH
report_capability "IMQ Target (IMQ_TARGET)" $IMQ_TARGET report_capability "IMQ Target" $IMQ_TARGET
report_capability "DSCP Match (DSCP_MATCH)" $DSCP_MATCH
report_capability "DSCP Target (DSCP_TARGET)" $DSCP_TARGET
report_capability "Geo IP match" $GEOIP_MATCH
if [ $g_family -eq 4 ]; then if [ $g_family -eq 4 ]; then
report_capability "iptables -S (IPTABLES_S)" $IPTABLES_S report_capability "iptables -S" $IPTABLES_S
else else
report_capability "ip6tables -S (IPTABLES_S)" $IPTABLES_S report_capability "ip6tables -S" $IPTABLES_S
fi fi
report_capability "Basic Filter (BASIC_FILTER)" $BASIC_FILTER report_capability "Basic Filter" $BASIC_FILTER
report_capability "CT Target (CT_TARGET)" $CT_TARGET report_capability "CT Target" $CT_TARGET
fi fi
[ -n "$PKTTYPE" ] || USEPKTTYPE= [ -n "$PKTTYPE" ] || USEPKTTYPE=
@@ -2358,7 +2306,6 @@ report_capabilities1() {
report_capability1 IPRANGE_MATCH report_capability1 IPRANGE_MATCH
report_capability1 RECENT_MATCH report_capability1 RECENT_MATCH
report_capability1 OWNER_MATCH report_capability1 OWNER_MATCH
report_capability1 OWNER_NAME_MATCH
report_capability1 IPSET_MATCH report_capability1 IPSET_MATCH
report_capability1 OLD_IPSET_MATCH report_capability1 OLD_IPSET_MATCH
report_capability1 CONNMARK report_capability1 CONNMARK
@@ -2407,15 +2354,14 @@ report_capabilities1() {
report_capability1 CT_TARGET report_capability1 CT_TARGET
report_capability1 STATISTIC_MATCH report_capability1 STATISTIC_MATCH
report_capability1 IMQ_TARGET report_capability1 IMQ_TARGET
report_capability1 DSCP_MATCH
report_capability1 DSCP_TARGET
report_capability1 GEOIP_MATCH
echo CAPVERSION=$SHOREWALL_CAPVERSION echo CAPVERSION=$SHOREWALL_CAPVERSION
echo KERNELVERSION=$KERNELVERSION echo KERNELVERSION=$KERNELVERSION
} }
show_status() { status_command() {
echo "${g_product}-$SHOREWALL_VERSION Status at $g_hostname - $(date)"
echo
if product_is_started ; then if product_is_started ; then
echo "$g_product is running" echo "$g_product is running"
status=0 status=0
@@ -2435,12 +2381,6 @@ show_status() {
state=Unknown state=Unknown
fi fi
echo "State:$state" echo "State:$state"
}
status_command() {
echo "${g_product}-$SHOREWALL_VERSION Status at $g_hostname - $(date)"
echo
show_status
echo echo
exit $status exit $status
} }
@@ -2540,7 +2480,7 @@ forget_command() {
ipcalc_command() { ipcalc_command() {
local address local address
local vlsm local vlsm
[ $g_family -eq 6 ] && usage 1 [ $g_family -eq 6 ] && usage 1
if [ $# -eq 2 ]; then if [ $# -eq 2 ]; then
@@ -2571,7 +2511,7 @@ iprange_command() {
[ $g_family -eq 6 ] && usage 1 [ $g_family -eq 6 ] && usage 1
range='' range=''
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
shift shift
@@ -2633,7 +2573,7 @@ get_config() {
ensure_config_path ensure_config_path
config=$(find_file ${g_program}.conf) config=$(find_file ${g_program}.conf)
if [ -f $config ]; then if [ -f $config ]; then
if [ -r $config ]; then if [ -r $config ]; then
. $config . $config
@@ -2680,7 +2620,7 @@ get_config() {
echo " ERROR: The program specified in IPTABLES does not exist or is not executable" >&2 echo " ERROR: The program specified in IPTABLES does not exist or is not executable" >&2
exit 2 exit 2
fi fi
else else
IPTABLES=$(mywhich iptables 2> /dev/null) IPTABLES=$(mywhich iptables 2> /dev/null)
if [ -z "$IPTABLES" ] ; then if [ -z "$IPTABLES" ] ; then
echo " ERROR: Can't find iptables executable" >&2 echo " ERROR: Can't find iptables executable" >&2
@@ -2695,7 +2635,7 @@ get_config() {
echo " ERROR: The program specified in IP6TABLES does not exist or is not executable" >&2 echo " ERROR: The program specified in IP6TABLES does not exist or is not executable" >&2
exit 2 exit 2
fi fi
else else
IP6TABLES=$(mywhich ip6tables 2> /dev/null) IP6TABLES=$(mywhich ip6tables 2> /dev/null)
if [ -z "$IP6TABLES" ] ; then if [ -z "$IP6TABLES" ] ; then
echo " ERROR: Can't find ip6tables executable" >&2 echo " ERROR: Can't find ip6tables executable" >&2
@@ -2752,7 +2692,7 @@ verify_firewall_script() {
else else
echo " The file $g_firewall does not exist" >&2 echo " The file $g_firewall does not exist" >&2
fi fi
exit 2 exit 2
fi fi
} }
@@ -2996,12 +2936,14 @@ shorewall_cli() {
g_annotate= g_annotate=
g_recovering= g_recovering=
g_timestamp= g_timestamp=
g_libexec=/usr/share
g_perllib=/usr/share/shorewall
g_shorewalldir= g_shorewalldir=
VERBOSE= VERBOSE=
VERBOSITY= VERBOSITY=
[ -n "$g_lite" ] || . ${g_basedir}/lib.cli-std [ -n "$g_lite" ] || . /usr/share/shorewall/lib.cli-std
finished=0 finished=0
@@ -3106,7 +3048,7 @@ shorewall_cli() {
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
MUTEX_TIMEOUT= MUTEX_TIMEOUT=
[ -f ${g_confdir}/vardir ] && . ${g_confdir}/vardir [ -f ${CONFDIR}/vardir ] && . ${CONFDIR}/vardir
[ -n "${VARDIR:=/var/lib/$g_program}" ] [ -n "${VARDIR:=/var/lib/$g_program}" ]
@@ -3116,7 +3058,7 @@ shorewall_cli() {
g_firewall=${VARDIR}/firewall g_firewall=${VARDIR}/firewall
version_file=${g_sharedir}/version version_file=$SHAREDIR/version
if [ -f $version_file ]; then if [ -f $version_file ]; then
SHOREWALL_VERSION=$(cat $version_file) SHOREWALL_VERSION=$(cat $version_file)
else else
@@ -3193,7 +3135,7 @@ shorewall_cli() {
[ $# -eq 1 ] || usage 1 [ $# -eq 1 ] || usage 1
[ "$(id -u)" != 0 ] && fatal_error "The status command may only be run by root" [ "$(id -u)" != 0 ] && fatal_error "The status command may only be run by root"
get_config get_config
status_command status_command
;; ;;
dump) dump)
get_config Yes No Yes get_config Yes No Yes
@@ -3303,6 +3245,6 @@ shorewall_cli() {
else else
usage 1 usage 1
fi fi
;; ;;
esac esac
} }

View File

@@ -593,7 +593,7 @@ find_first_interface_address() # $1 = interface
# #
[ -n "$addr" ] || startup_error "Can't determine the IP address of $1" [ -n "$addr" ] || startup_error "Can't determine the IP address of $1"
# #
# Strip off the trailing VLSM mask (or the peer IP in case of a P-t-P link) # Strip off the trailing VLSM mask (or the peer IP in case of a P-t-P link)
# along with everything else on the line # along with everything else on the line
# #
echo $addr | sed 's/\s*inet //;s/\/.*//;s/ peer.*//' echo $addr | sed 's/\s*inet //;s/\/.*//;s/ peer.*//'
@@ -676,7 +676,7 @@ find_file()
fi fi
done done
echo ${g_confdir}/$1 echo ${CONFDIR}/$1
;; ;;
esac esac
} }
@@ -717,69 +717,3 @@ truncate() # $1 = length
{ {
cut -b -${1} cut -b -${1}
} }
#
# Call this function to assert mutual exclusion with Shorewall. If you invoke the
# /sbin/shorewall program while holding mutual exclusion, you should pass "nolock" as
# the first argument. Example "shorewall nolock refresh"
#
# This function uses the lockfile utility from procmail if it exists.
# Otherwise, it uses a somewhat race-prone algorithm to attempt to simulate the
# behavior of lockfile.
#
mutex_on()
{
local try
try=0
local lockf
lockf=${LOCKFILE:=${VARDIR}/lock}
local lockpid
MUTEX_TIMEOUT=${MUTEX_TIMEOUT:-60}
if [ $MUTEX_TIMEOUT -gt 0 ]; then
[ -d ${VARDIR} ] || mkdir -p ${VARDIR}
if [ -f $lockf ]; then
lockpid=`cat ${lockf} 2> /dev/null`
if [ -z "$lockpid" -o $lockpid = 0 ]; then
rm -f ${lockf}
error_message "WARNING: Stale lockfile ${lockf} removed"
elif [ $lockpid -eq $$ ]; then
return 0
elif ! qt ps p ${lockpid}; then
rm -f ${lockf}
error_message "WARNING: Stale lockfile ${lockf} from pid ${lockpid} removed"
fi
fi
if qt mywhich lockfile; then
lockfile -${MUTEX_TIMEOUT} -r1 ${lockf}
chmod u+w ${lockf}
echo $$ > ${lockf}
chmod u-w ${lockf}
else
while [ -f ${lockf} -a ${try} -lt ${MUTEX_TIMEOUT} ] ; do
sleep 1
try=$((${try} + 1))
done
if [ ${try} -lt ${MUTEX_TIMEOUT} ] ; then
# Create the lockfile
echo $$ > ${lockf}
else
echo "Giving up on lock file ${lockf}" >&2
fi
fi
fi
}
#
# Call this function to release mutual exclusion
#
mutex_off()
{
rm -f ${LOCKFILE:=${VARDIR}/lock}
}

View File

@@ -1,20 +0,0 @@
#
# Apple OS X Shorewall 4.5 rc file
#
BUILD=apple
HOST=apple
PREFIX=/usr #Top-level directory for shared files, libraries, etc.
SHAREDIR=${PREFIX}/share #Directory for arch-neutral files.
LIBEXECDIR=${PREFIX}/share #Directory for executable scripts.
PERLLIBDIR=${PREFIX}/share/shorewall #Directory to install Shorewall Perl module directory
CONFDIR=/etc #Directory where subsystem configurations are installed
SBINDIR=/sbin #Directory where system administration programs are installed
MANDIR=${SHAREDIR}/man #Directory where manpages are installed.
INITDIR= #Unused on OS X
INITFILE= #Unused on OS X
INITSOURCE= #Unused on OS X
ANNOTATED= #Unused on OS X
SYSTEMD= #Unused on OS X
SYSCONFDIR= #Unused on OS X
SPARSE=Yes #Only install $PRODUCT/$PRODUCT.conf in $CONFDIR.
VARDIR=/var/lib #Unused on OS X

View File

@@ -1,20 +0,0 @@
#
# Archlinux Shorewall 4.5 rc file
#
BUILD=archlinux
HOST=archlinux
PREFIX=/usr #Top-level directory for shared files, libraries, etc.
SHAREDIR=${PREFIX}/share #Directory for arch-neutral files.
LIBEXECDIR=${PREFIX}/share #Directory for executable scripts.
PERLLIBDIR=${PREFIX}/share/shorewall #Directory to install Shorewall Perl module directory
CONFDIR=/etc #Directory where subsystem configurations are installed
SBINDIR=/sbin #Directory where system administration programs are installed
MANDIR=${SHAREDIR}/man #Directory where manpages are installed.
INITDIR=/etc/rc.d #Directory where SysV init scripts are installed.
INITFILE=$PRODUCT #Name of the product's installed SysV init script
INITSOURCE=init.sh #Name of the distributed file to be installed as the SysV init script
ANNOTATED= #If non-zero, annotated configuration files are installed
SYSCONFDIR= #Directory where SysV init parameter files are installed
SYSTEMD= #Directory where .service files are installed (systems running systemd only)
SPARSE= #If non-empty, only install $PRODUCT/$PRODUCT.conf in $CONFDIR
VARDIR=/var/lib #Directory where product variable data is stored.

View File

@@ -1,20 +0,0 @@
#
# Cygwin Shorewall 4.5 rc file
#
BUILD=cygwin
HOST=cygwin
PREFIX=/usr #Top-level directory for shared files, libraries, etc.
SHAREDIR=${PREFIX}/share #Directory for arch-neutral files.
LIBEXECDIR=${PREFIX}/share #Directory for executable scripts.
PERLLIBDIR=${PREFIX}/share/shorewall #Directory to install Shorewall Perl module directory
CONFDIR=/etc #Directory where subsystem configurations are installed
SBINDIR=/bin #Directory where system administration programs are installed
MANDIR=${SHAREDIR}/man #Directory where manpages are installed.
INITDIR=/etc/init.d #Unused on Cygwin
INITFILE= #Unused on Cygwin
INITSOURCE= #Unused on Cygwin
ANNOTATED= #Unused on Cygwin
SYSTEMD= #Unused on Cygwin
SYSCONFDIR= #Unused on Cygwin
SPARSE=Yes #Only install $PRODUCT/$PRODUCT.conf in $CONFDIR.
VARDIR=/var/lib #Unused on Cygwin

View File

@@ -1,21 +0,0 @@
#
# Debian Shorewall 4.5 rc file
#
BUILD= #Default is to detect the build system
HOST=debian
PREFIX=/usr #Top-level directory for shared files, libraries, etc.
SHAREDIR=${PREFIX}/share #Directory for arch-neutral files.
LIBEXECDIR=${PREFIX}/share #Directory for executable scripts.
PERLLIBDIR=${PREFIX}/share/shorewall #Directory to install Shorewall Perl module directory
CONFDIR=/etc #Directory where subsystem configurations are installed
SBINDIR=/sbin #Directory where system administration programs are installed
MANDIR=${PREFIX}/share/man #Directory where manpages are installed.
INITDIR=/etc/init.d #Directory where SysV init scripts are installed.
INITFILE=$PRODUCT #Name of the product's installed SysV init script
INITSOURCE=init.debian.sh #Name of the distributed file to be installed as the SysV init script
ANNOTATED= #If non-zero, annotated configuration files are installed
SYSCONFFILE=default.debian #Name of the distributed file to be installed in $SYSCONFDIR
SYSCONFDIR=/etc/default #Directory where SysV init parameter files are installed
SYSTEMD= #Directory where .service files are installed (systems running systemd only)
SPARSE=Yes #If non-empty, only install $PRODUCT/$PRODUCT.conf in $CONFDIR
VARDIR=/var/lib #Directory where product variable data is stored.

View File

@@ -1,21 +0,0 @@
#
# Default Shorewall 4.5 rc file
#
HOST=linux #Generic Linux
BUILD= #Default is to detect the build system
PREFIX=/usr #Top-level directory for shared files, libraries, etc.
SHAREDIR=${PREFIX}/share #Directory for arch-neutral files.
LIBEXECDIR=${PREFIX}/share #Directory for executable scripts.
PERLLIBDIR=${PREFIX}/share/shorewall #Directory to install Shorewall Perl module directory
CONFDIR=/etc #Directory where subsystem configurations are installed
SBINDIR=/sbin #Directory where system administration programs are installed
MANDIR=${PREFIX}/man #Directory where manpages are installed.
INITDIR=etc/init.d #Directory where SysV init scripts are installed.
INITFILE=$PRODUCT #Name of the product's installed SysV init script
INITSOURCE=init.sh #Name of the distributed file to be installed as the SysV init script
ANNOTATED= #If non-zero, annotated configuration files are installed
SYSTEMD= #Directory where .service files are installed (systems running systemd only)
SYSCONFFILE= #Name of the distributed file to be installed in $SYSCONFDIR
SYSCONFDIR= #Directory where SysV init parameter files are installed
SPARSE= #If non-empty, only install $PRODUCT/$PRODUCT.conf in $CONFDIR
VARDIR=/var/lib #Directory where product variable data is stored.

View File

@@ -1,21 +0,0 @@
#
# RedHat/FedoraShorewall 4.5 rc file
#
BUILD= #Default is to detect the build system
HOST=redhat
PREFIX=/usr #Top-level directory for shared files, libraries, etc.
SHAREDIR=${PREFIX}/share #Directory for arch-neutral files.
LIBEXECDIR=${PREFIX}/libexec #Directory for executable scripts.
PERLLIBDIR=/usr/share/perl5/vendor_perl #Directory to install Shorewall Perl module directory
CONFDIR=/etc #Directory where subsystem configurations are installed
SBINDIR=/sbin #Directory where system administration programs are installed
MANDIR=${SHAREDIR}/man #Directory where manpages are installed.
INITDIR=/etc/rc.d/init.d #Directory where SysV init scripts are installed.
INITFILE=$PRODUCT #Name of the product's installed SysV init script
INITSOURCE=init.fedora.sh #Name of the distributed file to be installed as the SysV init script
ANNOTATED= #If non-zero, annotated configuration files are installed
SYSTEMD=/lib/systemd/system #Directory where .service files are installed (systems running systemd only)
SYSCONFFILE=sysconfig #Name of the distributed file to be installed as $SYSCONFDIR/$PRODUCT
SYSCONFDIR=/etc/sysconfig/ #Directory where SysV init parameter files are installed
SPARSE= #If non-empty, only install $PRODUCT/$PRODUCT.conf in $CONFDIR
VARDIR=/var/lib #Directory where product variable data is stored.

View File

@@ -1,22 +0,0 @@
#
# Slackware Shorewall 4.5 rc file
#
BUILD=slackware
HOST=slackware
PREFIX=/usr #Top-level directory for shared files, libraries, etc.
SHAREDIR=${PREFIX}/share #Directory for arch-neutral files.
LIBEXECDIR=${PREFIX}/share #Directory for executable scripts.
PERLLIBDIR=${PREFIX}/share/shorewall #Directory to install Shorewall Perl module directory
CONFDIR=/etc #Directory where subsystem configurations are installed
SBINDIR=/sbin #Directory where system administration programs are installed
MANDIR=${PREFIX}/man #Directory where manpages are installed.
INITDIR=/etc/rc.d #Directory where SysV init scripts are installed.
AUXINITSOURCE=init.slackware.firewall.sh #Name of the distributed file to be installed as the SysV init script
AUXINITFILE=rc.firewall #Name of the product's installed SysV init script
INITSOURCE=init.slackware.$PRODUCT.sh #Name of the distributed file to be installed as a second SysV init script
INITFILE=rc.$PRODUCT #Name of the product's installed second init script
SYSTEMD= #Name of the directory where .service files are installed (systems running systemd only)
SYSCONFFILE= #Name of the distributed file to be installed in $SYSCONFDIR
SYSCONFDIR= #Name of the directory where SysV init parameter files are installed.
ANNOTATED= #If non-empty, install annotated configuration files
VARDIR=/var/lib #Directory where product variable data is stored.

View File

@@ -1,21 +0,0 @@
#
# SuSE Shorewall 4.5 rc file
#
BUILD= #Default is to detect the build system
HOST=suse
PREFIX=/usr #Top-level directory for shared files, libraries, etc.
CONFDIR=/etc #Directory where subsystem configurations are installed
SHAREDIR=${PREFIX}/share #Directory for arch-neutral files.
LIBEXECDIR=${PREFIX}/lib #Directory for executable scripts.
PERLLIBDIR=${PREFIX}/lib/perl5/vendor_perl/5.14.2 #Directory to install Shorewall Perl module directory
SBINDIR=/sbin #Directory where system administration programs are installed
MANDIR=${SHAREDIR}/man/ #Directory where manpages are installed.
INITDIR=/etc/init.d #Directory where SysV init scripts are installed.
INITFILE=$PRODUCT #Name of the product's SysV init script
INITSOURCE=init.sh #Name of the distributed file to be installed as the SysV init script
ANNOTATED= #If non-zero, annotated configuration files are installed
SYSTEMD= #Directory where .service files are installed (systems running systemd only)
SYSCONFFILE= #Name of the distributed file to be installed in $SYSCONFDIR
SYSCONFDIR=/etc/sysconfig/ #Directory where SysV init parameter files are installed
SPARSE= #If non-empty, only install $PRODUCT/$PRODUCT.conf in $CONFDIR
VARDIR=/var/lib #Directory where persistent product data is stored.

View File

@@ -31,7 +31,7 @@ VERSION=xxx #The Build script inserts the actual version
usage() # $1 = exit status usage() # $1 = exit status
{ {
ME=$(basename $0) ME=$(basename $0)
echo "usage: $ME [ <shorewallrc file> ]" echo "usage: $ME"
exit $1 exit $1
} }
@@ -60,37 +60,8 @@ remove_file() # $1 = file to restore
fi fi
} }
# if [ -f /usr/share/shorewall/coreversion ]; then
# Read the RC file INSTALLED_VERSION="$(cat /usr/share/shorewall/coreversion)"
#
if [ $# -eq 0 ]; then
if [ -f ./shorewallrc ]; then
. ./shorewallrc
elif [ -f ~/.shorewallrc ]; then
. ~/.shorewallrc || exit 1
file=./.shorewallrc
elif [ -f /usr/share/shorewall/shorewallrc ]; then
. /usr/share/shorewall/shorewallrc
else
fatal_error "No configuration file specified and /usr/share/shorewall/shorewallrc not found"
fi
elif [ $# -eq 1 ]; then
file=$1
case $file in
/*|.*)
;;
*)
file=./$file
;;
esac
. $file
else
usage 1
fi
if [ -f ${SHAREDIR}/shorewall/coreversion ]; then
INSTALLED_VERSION="$(cat ${SHAREDIR}/shorewall/coreversion)"
if [ "$INSTALLED_VERSION" != "$VERSION" ]; then if [ "$INSTALLED_VERSION" != "$VERSION" ]; then
echo "WARNING: Shorewall Core Version $INSTALLED_VERSION is installed" echo "WARNING: Shorewall Core Version $INSTALLED_VERSION is installed"
echo " and this is the $VERSION uninstaller." echo " and this is the $VERSION uninstaller."
@@ -101,9 +72,12 @@ else
VERSION="" VERSION=""
fi fi
[ -n "${LIBEXEC:=/usr/share}" ]
[ -n "${PERLLIB:=/usr/share/shorewall}" ]
echo "Uninstalling Shorewall Core $VERSION" echo "Uninstalling Shorewall Core $VERSION"
rm -rf ${SHAREDIR}/shorewall rm -rf /usr/share/shorewall
echo "Shorewall Core Uninstalled" echo "Shorewall Core Uninstalled"

View File

@@ -71,11 +71,6 @@ Debian_SuSE_ppp() {
IFUPDOWN=0 IFUPDOWN=0
PRODUCTS= PRODUCTS=
#
# The installer may alter this
#
. /usr/share/shorewall/shorewallrc
if [ -f /etc/default/shorewall-init ]; then if [ -f /etc/default/shorewall-init ]; then
. /etc/default/shorewall-init . /etc/default/shorewall-init
elif [ -f /etc/sysconfig/shorewall-init ]; then elif [ -f /etc/sysconfig/shorewall-init ]; then
@@ -106,11 +101,15 @@ if [ -f /etc/debian_version ]; then
else else
exit 0 exit 0
fi fi
case "$PHASE" in
pre-*)
exit 0
;;
esac
;; ;;
esac esac
elif [ -f /etc/SuSE-release ]; then elif [ -f /etc/SuSE-release ]; then
PHASE=''
case $0 in case $0 in
/etc/ppp*) /etc/ppp*)
# #
@@ -142,8 +141,6 @@ else
# #
# Assume RedHat/Fedora/CentOS/Foobar/... # Assume RedHat/Fedora/CentOS/Foobar/...
# #
PHASE=''
case $0 in case $0 in
/etc/ppp*) /etc/ppp*)
INTERFACE="$1" INTERFACE="$1"
@@ -184,11 +181,15 @@ else
esac esac
fi fi
[ -n "$LOGFILE" ] || LOGFILE=/dev/null
for PRODUCT in $PRODUCTS; do for PRODUCT in $PRODUCTS; do
if [ -x $VARDIR/$PRODUCT/firewall ]; then VARDIR=/var/lib/$PRODUCT
( ${VARDIR}/$PRODUCT/firewall -V0 $COMMAND $INTERFACE >> $LOGFILE 2>&1 ) || true [ -f /etc/$PRODUCT/vardir ] && . /etc/$PRODUCT/vardir
if [ -x $VARDIR/firewall ]; then
( . /usr/share/$PRODUCT/lib.base
mutex_on
${VARDIR}/firewall -V0 $COMMAND $INTERFACE || echo_notdone
mutex_off
)
fi fi
done done

View File

@@ -1,10 +1,10 @@
#!/bin/sh #!/bin/sh
# #
# The Shoreline Firewall (Shorewall) Packet Filtering Firewall - V4.5 # The Shoreline Firewall (Shorewall) Packet Filtering Firewall - V4.4
# #
# This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt] # This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt]
# #
# (c) 2010,2012 - Tom Eastep (teastep@shorewall.net) # (c) 2010 - Tom Eastep (teastep@shorewall.net)
# #
# On most distributions, this file should be called /etc/init.d/shorewall. # On most distributions, this file should be called /etc/init.d/shorewall.
# #
@@ -62,15 +62,10 @@ not_configured () {
exit 0 exit 0
} }
#
# The installer may alter this
#
. /usr/share/shorewall/shorewallrc
# check if shorewall-init is configured or not # check if shorewall-init is configured or not
if [ -f "$SYSCONFDIR/shorewall-init" ] if [ -f "/etc/default/shorewall-init" ]
then then
. $SYSCONFDIR/shorewall-init . /etc/default/shorewall-init
if [ -z "$PRODUCTS" ] if [ -z "$PRODUCTS" ]
then then
not_configured not_configured

View File

@@ -13,15 +13,6 @@
# Description: Place the firewall in a safe state at boot time # Description: Place the firewall in a safe state at boot time
# prior to bringing up the network. # prior to bringing up the network.
### END INIT INFO ### END INIT INFO
#determine where the files were installed
if [ -f ~/.shorewallrc ]; then
. ~/.shorewallrc || exit 1
else
SBINDIR=/sbin
SYSCONFDIR=/etc/default
VARDIR=/var/lib
fi
prog="shorewall-init" prog="shorewall-init"
logger="logger -i -t $prog" logger="logger -i -t $prog"
lockfile="/var/lock/subsys/shorewall-init" lockfile="/var/lock/subsys/shorewall-init"
@@ -53,8 +44,10 @@ start () {
echo -n "Initializing \"Shorewall-based firewalls\": " echo -n "Initializing \"Shorewall-based firewalls\": "
for product in $PRODUCTS; do for product in $PRODUCTS; do
if [ -x ${VARDIR}/$product/firewall ]; then vardir=/var/lib/$product
${VARDIR}/$product/firewall stop 2>&1 | $logger [ -f /etc/$product/vardir ] && . /etc/$product/vardir
if [ -x ${vardir}/firewall ]; then
${vardir}/firewall stop 2>&1 | $logger
retval=${PIPESTATUS[0]} retval=${PIPESTATUS[0]}
[ retval -ne 0 ] && break [ retval -ne 0 ] && break
fi fi
@@ -77,8 +70,10 @@ stop () {
echo -n "Clearing \"Shorewall-based firewalls\": " echo -n "Clearing \"Shorewall-based firewalls\": "
for product in $PRODUCTS; do for product in $PRODUCTS; do
if [ -x ${VARDIR}/$product/firewall ]; then vardir=/var/lib/$product
${VARDIR}/$product/firewall clear 2>&1 | $logger [ -f /etc/$product/vardir ] && . /etc/$product/vardir
if [ -x ${vardir}/firewall ]; then
${vardir}/firewall clear 2>&1 | $logger
retval=${PIPESTATUS[0]} retval=${PIPESTATUS[0]}
[ retval -ne 0 ] && break [ retval -ne 0 ] && break
fi fi

View File

@@ -1,9 +1,9 @@
#! /bin/bash #! /bin/bash
# The Shoreline Firewall (Shorewall) Packet Filtering Firewall - V4.5 # The Shoreline Firewall (Shorewall) Packet Filtering Firewall - V4.4
# #
# This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt] # This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt]
# #
# (c) 2010,2012 - Tom Eastep (teastep@shorewall.net) # (c) 2010 - Tom Eastep (teastep@shorewall.net)
# #
# On most distributions, this file should be called /etc/init.d/shorewall. # On most distributions, this file should be called /etc/init.d/shorewall.
# #
@@ -53,11 +53,6 @@ else
exit 0 exit 0
fi fi
#
# The installer may alter this
#
. /usr/share/shorewall/shorewallrc
# Initialize the firewall # Initialize the firewall
shorewall_start () { shorewall_start () {
local PRODUCT local PRODUCT
@@ -65,8 +60,10 @@ shorewall_start () {
echo -n "Initializing \"Shorewall-based firewalls\": " echo -n "Initializing \"Shorewall-based firewalls\": "
for PRODUCT in $PRODUCTS; do for PRODUCT in $PRODUCTS; do
VARDIR=/var/lib/$PRODUCT
[ -f /etc/$PRODUCT/vardir ] && . /etc/$PRODUCT/vardir
if [ -x ${VARDIR}/firewall ]; then if [ -x ${VARDIR}/firewall ]; then
if ! ${SBIN}/$PRODUCT status > /dev/null 2>&1; then if ! /sbin/$PRODUCT status > /dev/null 2>&1; then
${VARDIR}/firewall stop || echo_notdone ${VARDIR}/firewall stop || echo_notdone
fi fi
fi fi
@@ -86,6 +83,8 @@ shorewall_stop () {
echo -n "Clearing \"Shorewall-based firewalls\": " echo -n "Clearing \"Shorewall-based firewalls\": "
for PRODUCT in $PRODUCTS; do for PRODUCT in $PRODUCTS; do
VARDIR=/var/lib/$PRODUCT
[ -f /etc/$PRODUCT/vardir ] && . /etc/$PRODUCT/vardir
if [ -x ${VARDIR}/firewall ]; then if [ -x ${VARDIR}/firewall ]; then
${VARDIR}/firewall clear || exit 1 ${VARDIR}/firewall clear || exit 1
fi fi

View File

@@ -28,18 +28,12 @@ VERSION=xxx #The Build script inserts the actual version.
usage() # $1 = exit status usage() # $1 = exit status
{ {
ME=$(basename $0) ME=$(basename $0)
echo "usage: $ME [ <configuration-file> ]" echo "usage: $ME"
echo " $ME -v" echo " $ME -v"
echo " $ME -h" echo " $ME -h"
exit $1 exit $1
} }
fatal_error()
{
echo " ERROR: $@" >&2
exit 1
}
split() { split() {
local ifs local ifs
ifs=$IFS ifs=$IFS
@@ -82,9 +76,9 @@ cant_autostart()
echo "WARNING: Unable to configure shorewall init to start automatically at boot" >&2 echo "WARNING: Unable to configure shorewall init to start automatically at boot" >&2
} }
require() delete_file() # $1 = file to delete
{ {
eval [ -n "\$$1" ] || fatal_error "Required option $1 not set" rm -f $1
} }
install_file() # $1 = source $2 = target $3 = mode install_file() # $1 = source $2 = target $3 = mode
@@ -92,206 +86,148 @@ install_file() # $1 = source $2 = target $3 = mode
run_install $T $OWNERSHIP -m $3 $1 ${2} run_install $T $OWNERSHIP -m $3 $1 ${2}
} }
cd "$(dirname $0)" [ -n "$DESTDIR" ] || DESTDIR="$PREFIX"
PRODUCT=shorewall-init
# DEST is the SysVInit script directory
# INIT is the name of the script in the $DEST directory
# ARGS is "yes" if we've already parsed an argument
# #
# Parse the run line ARGS=""
#
finished=0
while [ $finished -eq 0 ] ; do if [ -z "$DEST" ] ; then
case "$1" in DEST="/etc/init.d"
-*)
option=${option#-}
while [ -n "$option" ]; do
case $option in
h)
usage 0
;;
v)
echo "Shorewall-init Firewall Installer Version $VERSION"
exit 0
;;
*)
usage 1
;;
esac
done
shift
;;
*)
finished=1
;;
esac
done
#
# Read the RC file
#
if [ $# -eq 0 ]; then
#
# Load packager's settings if any
#
if [ -f ./shorewallrc ]; then
. ./shorewallrc || exit 1
file=~/.shorewallrc
elif [ -f ~/.shorewallrc ]; then
. ~/.shorewallrc || exit 1
file=./.shorewallrc
else
fatal_error "No configuration file specified and ~/.shorewallrc not found"
fi
elif [ $# -eq 1 ]; then
file=$1
case $file in
/*|.*)
;;
*)
file=./$file
;;
esac
. $file
else
usage 1
fi fi
for var in SHAREDIR LIBEXECDIR CONFDIR SBINDIR VARDIR; do if [ -z "$INIT" ] ; then
require $var INIT="shorewall-init"
fi
while [ $# -gt 0 ] ; do
case "$1" in
-h|help|?)
usage 0
;;
-v)
echo "Shorewall Init Installer Version $VERSION"
exit 0
;;
*)
usage 1
;;
esac
shift
ARGS="yes"
done done
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
if [ -z "$BUILD" ]; then [ -n "${LIBEXEC:=/usr/share}" ]
case $(uname) in
cygwin*)
BUILD=cygwin
;;
Darwin)
BUILD=apple
;;
*)
if [ -f /etc/debian_version ]; then
BUILD=debian
elif [ -f /etc/redhat-release ]; then
BUILD=redhat
elif [ -f /etc/SuSE-release ]; then
BUILD=suse
elif [ -f /etc/slackware-version ] ; then
BUILD=slackware
elif [ -f /etc/arch-release ] ; then
BUILD=archlinux
else
BUILD=linux
fi
;;
esac
fi
[ -n "$OWNER" ] || OWNER=$(id -un) case "$LIBEXEC" in
[ -n "$GROUP" ] || GROUP=$(id -gn) /*)
case $BUILD in
apple)
T=
;;
debian|redhat|suse|slackware|archlinux)
;; ;;
*) *)
[ -n "$BUILD" ] && echo "ERROR: Unknown BUILD environment ($BUILD)" >&2 || echo "ERROR: Unknown BUILD environment" LIBEXEC=/usr/${LIBEXEC}
exit 1 ;;
esac
#
# Determine where to install the firewall script
#
case $(uname) in
Darwin)
[ -z "$OWNER" ] && OWNER=root
[ -z "$GROUP" ] && GROUP=wheel
T=
;;
*)
[ -z "$OWNER" ] && OWNER=root
[ -z "$GROUP" ] && GROUP=root
;; ;;
esac esac
OWNERSHIP="-o $OWNER -g $GROUP" OWNERSHIP="-o $OWNER -g $GROUP"
[ -n "$HOST" ] || HOST=$BUILD
case "$HOST" in
debian)
echo "Installing Debian-specific configuration..."
;;
redhat|redhat)
echo "Installing Redhat/Fedora-specific configuration..."
;;
slackware)
echo "Shorewall-init is currently not supported on Slackware" >&2
exit 1
;;
archlinux)
echo "Shorewall-init is currently not supported on Arch Linux" >&2
exit 1
;;
suse|suse)
echo "Installing SuSE-specific configuration..."
;;
linux)
echo "ERROR: Shorewall-init is not supported on this system" >&2
;;
*)
echo "ERROR: Unsupported HOST distribution: \"$HOST\"" >&2
exit 1;
;;
esac
[ -z "$TARGET" ] && TARGET=$HOST
if [ -n "$DESTDIR" ]; then if [ -n "$DESTDIR" ]; then
if [ `id -u` != 0 ] ; then if [ `id -u` != 0 ] ; then
echo "Not setting file owner/group permissions, not running as root." echo "Not setting file owner/group permissions, not running as root."
OWNERSHIP="" OWNERSHIP=""
fi fi
install -d $OWNERSHIP -m 755 ${DESTDIR}${INITDIR} install -d $OWNERSHIP -m 755 ${DESTDIR}${DEST}
elif [ -f /etc/debian_version ]; then
DEBIAN=yes
elif [ -f /etc/SuSE-release ]; then
SUSE=Yes
elif [ -f /etc/redhat-release ]; then
FEDORA=Yes
elif [ -f /etc/slackware-version ] ; then
echo "Shorewall-init is currently not supported on Slackware" >&2
exit 1
# DEST="/etc/rc.d"
# INIT="rc.firewall"
elif [ -f /etc/arch-release ] ; then
echo "Shorewall-init is currently not supported on Arch Linux" >&2
exit 1
# DEST="/etc/rc.d"
# INIT="shorewall-init"
# ARCHLINUX=yes
elif [ -d /etc/sysconfig/network-scripts/ ]; then
#
# Assume RedHat-based
#
REDHAT=Yes
else
echo "Unknown distribution: Shorewall-init support is not available" >&2
exit 1
fi fi
if [ -z "$DESTDIR" ]; then
if [ -f /lib/systemd/system ]; then
SYSTEMD=Yes
fi
elif [ -n "$SYSTEMD" ]; then
mkdir -p ${DESTDIR}/lib/systemd/system
fi
#
# Change to the directory containing this script
#
cd "$(dirname $0)"
echo "Installing Shorewall Init Version $VERSION" echo "Installing Shorewall Init Version $VERSION"
# #
# Check for /usr/share/shorewall-init/version # Check for /usr/share/shorewall-init/version
# #
if [ -f ${DESTDIR}${SHAREDIR}/shorewall-init/version ]; then if [ -f ${DESTDIR}/usr/share/shorewall-init/version ]; then
first_install="" first_install=""
else else
first_install="Yes" first_install="Yes"
fi fi
if [ -n "$DESTDIR" ]; then #
mkdir -p ${DESTDIR}${CONFDIR}/logrotate.d # Install the Init Script
chmod 755 ${DESTDIR}${CONFDIR}/logrotate.d #
if [ -n "$DEBIAN" ]; then
install_file init.debian.sh ${DESTDIR}/etc/init.d/shorewall-init 0544
elif [ -n "$FEDORA" ]; then
install_file init.fedora.sh ${DESTDIR}/etc/init.d/shorewall-init 0544
#elif [ -n "$ARCHLINUX" ]; then
# install_file init.archlinux.sh ${DESTDIR}${DEST}/$INIT 0544
else
install_file init.sh ${DESTDIR}${DEST}/$INIT 0544
fi fi
# echo "Shorewall Init script installed in ${DESTDIR}${DEST}/$INIT"
# Install the Firewall Script
#
if [ -n "$INITFILE" ]; then
install_file $INITSOURCE ${DESTDIR}${INITDIR}/$INITFILE 0544
[ "${SHAREDIR}" = /usr/share ] || eval sed -i \'s\|/usr/share/\|${SHAREDIR}/\|\' ${DESTDIR}${INITDIR}/$INITFILE
if [ -n "${AUXINITSOURCE}" ]; then
install_file $INITSOURCE ${DESTDIR}${INITDIR}/$AUXINITFILE 0544
fi
echo "Shorewall-init script installed in ${DESTDIR}${INITDIR}/$INITFILE"
fi
# #
# Install the .service file # Install the .service file
# #
if [ -n "$SYSTEMD" ]; then if [ -n "$SYSTEMD" ]; then
mkdir -p ${DESTDIR}${SYSTEMD} run_install $OWNERSHIP -m 600 shorewall-init.service ${DESTDIR}/lib/systemd/system/shorewall-init.service
run_install $OWNERSHIP -m 600 shorewall-init.service ${DESTDIR}${SYSTEMD}/shorewall-init.service echo "Service file installed as ${DESTDIR}/lib/systemd/system/shorewall-init.service"
echo "Service file installed as ${DESTDIR}${SYSTEMD}/shorewall-init.service"
if [ -n "$DESTDIR" ]; then
mkdir -p ${DESTDIR}${SBINDIR}
chmod 755 ${DESTDIR}${SBINDIR}
fi
run_install $OWNERSHIP -m 700 shorewall-init ${DESTDIR}${SBINDIR}/shorewall-init
echo "CLI installed as ${DESTDIR}${SBINDIR}/shorewall-init"
fi fi
# #
@@ -300,14 +236,6 @@ fi
mkdir -p ${DESTDIR}/usr/share/shorewall-init mkdir -p ${DESTDIR}/usr/share/shorewall-init
chmod 755 ${DESTDIR}/usr/share/shorewall-init chmod 755 ${DESTDIR}/usr/share/shorewall-init
#
# Install logrotate file
#
if [ -d ${DESTDIR}${CONFDIR}/logrotate.d ]; then
run_install $OWNERSHIP -m 0644 logrotate ${DESTDIR}${CONFDIR}/logrotate.d/$PRODUCT
echo "Logrotate file installed as ${DESTDIR}${CONFDIR}/logrotate.d/$PRODUCT"
fi
# #
# Create the version file # Create the version file
# #
@@ -319,13 +247,13 @@ chmod 644 ${DESTDIR}/usr/share/shorewall-init/version
# #
if [ -z "$DESTDIR" ]; then if [ -z "$DESTDIR" ]; then
rm -f /usr/share/shorewall-init/init rm -f /usr/share/shorewall-init/init
ln -s ${INITDIR}/${INITFILE} ${SHAREDIR}/shorewall-init/init ln -s ${DEST}/${INIT} /usr/share/shorewall-init/init
fi fi
if [ $HOST = debian ]; then if [ -n "$DEBIAN" ]; then
if [ -n "${DESTDIR}" ]; then if [ -n "${DESTDIR}" ]; then
mkdir -p ${DESTDIR}/etc/network/if-up.d/ mkdir -p ${DESTDIR}/etc/network/if-up.d/
mkdir -p ${DESTDIR}/etc/network/if-down.d/ mkdir -p ${DESTDIR}/etc/network/if-post-down.d/
fi fi
if [ ! -f ${DESTDIR}/etc/default/shorewall-init ]; then if [ ! -f ${DESTDIR}/etc/default/shorewall-init ]; then
@@ -337,20 +265,20 @@ if [ $HOST = debian ]; then
fi fi
else else
if [ -n "$DESTDIR" ]; then if [ -n "$DESTDIR" ]; then
mkdir -p ${DESTDIR}${SYSCONFDIR} mkdir -p ${DESTDIR}/etc/sysconfig
if [ -z "$RPM" ]; then if [ -z "$RPM" ]; then
if [ $HOST = suse ]; then if [ -n "$SUSE" ]; then
mkdir -p ${DESTDIR}/etc/sysconfig/network/if-up.d mkdir -p ${DESTDIR}/etc/sysconfig/network/if-up.d
mkdir -p ${DESTDIR}${SYSCONFDIR}/network/if-down.d mkdir -p ${DESTDIR}/etc/sysconfig/network/if-down.d
else else
mkdir -p ${DESTDIR}/etc/NetworkManager/dispatcher.d mkdir -p ${DESTDIR}/etc/NetworkManager/dispatcher.d
fi fi
fi fi
fi fi
if [ -d ${DESTDIR}${SYSCONFDIR} -a ! -f ${DESTDIR}${SYSCONFDIR}/shorewall-init ]; then if [ -d ${DESTDIR}/etc/sysconfig -a ! -f ${DESTDIR}/etc/sysconfig/shorewall-init ]; then
install_file sysconfig ${DESTDIR}${SYSCONFDIR}/shorewall-init 0644 install_file sysconfig ${DESTDIR}/etc/sysconfig/shorewall-init 0644
fi fi
fi fi
@@ -358,119 +286,105 @@ fi
# Install the ifupdown script # Install the ifupdown script
# #
cp ifupdown.sh ifupdown mkdir -p ${DESTDIR}${LIBEXEC}/shorewall-init
[ "${SHAREDIR}" = /usr/share ] || eval sed -i \'s\|/usr/share/\|${SHAREDIR}/\|\' ifupdown install_file ifupdown.sh ${DESTDIR}${LIBEXEC}/shorewall-init/ifupdown 0544
mkdir -p ${DESTDIR}${LIBEXECDIR}/shorewall-init
install_file ifupdown ${DESTDIR}${LIBEXECDIR}/shorewall-init/ifupdown 0544
if [ -d ${DESTDIR}/etc/NetworkManager ]; then if [ -d ${DESTDIR}/etc/NetworkManager ]; then
install_file ifupdown ${DESTDIR}/etc/NetworkManager/dispatcher.d/01-shorewall 0544 install_file ifupdown.sh ${DESTDIR}/etc/NetworkManager/dispatcher.d/01-shorewall 0544
fi fi
case $HOST in if [ -n "$DEBIAN" ]; then
debian) install_file ifupdown.sh ${DESTDIR}/etc/network/if-up.d/shorewall 0544
install_file ifupdown ${DESTDIR}/etc/network/if-up.d/shorewall 0544 install_file ifupdown.sh ${DESTDIR}/etc/network/if-post-down.d/shorewall 0544
install_file ifupdown ${DESTDIR}/etc/network/if-down.d/shorewall 0544 elif [ -n "$SUSE" ]; then
install_file ifupdown ${DESTDIR}/etc/network/if-post-down.d/shorewall 0544 install_file ifupdown.sh ${DESTDIR}/etc/sysconfig/network/if-up.d/shorewall 0544
;; install_file ifupdown.sh ${DESTDIR}/etc/sysconfig/network/if-down.d/shorewall 0544
suse) elif [ -n "$REDHAT" ]; then
if [ -z "$RPM" ]; then if [ -f ${DESTDIR}/sbin/ifup-local -o -f ${DESTDIR}/sbin/ifdown-local ]; then
install_file ifupdown ${DESTDIR}${SYSCONFDIR}/network/if-up.d/shorewall 0544 echo "WARNING: /sbin/ifup-local and/or /sbin/ifdown-local already exist; up/down events will not be handled"
install_file ifupdown ${DESTDIR}${SYSCONFDIR}/network/if-down.d/shorewall 0544 else
fi install_file ifupdown.sh ${DESTDIR}/sbin/ifup-local 0544
;; install_file ifupdown.sh ${DESTDIR}/sbin/ifdown-local 0544
redhat) fi
if [ -f ${DESTDIR}${SBINDIR}/ifup-local -o -f ${DESTDIR}${SBINDIR}/ifdown-local ]; then fi
echo "WARNING: ${SBINDIR}/ifup-local and/or ${SBINDIR}/ifdown-local already exist; up/down events will not be handled"
elif [ -z "$DESTDIR" ]; then
install_file ifupdown ${DESTDIR}${SBINDIR}/ifup-local 0544
install_file ifupdown ${DESTDIR}${SBINDIR}/ifdown-local 0544
fi
;;
esac
if [ -z "$DESTDIR" ]; then if [ -z "$DESTDIR" ]; then
if [ -n "$first_install" ]; then if [ -n "$first_install" ]; then
if [ $HOST = debian ]; then if [ -n "$DEBIAN" ]; then
update-rc.d shorewall-init enable update-rc.d shorewall-init defaults
echo "Shorewall Init will start automatically at boot" echo "Shorewall Init will start automatically at boot"
else else
if [ -n "$SYSTEMD" ]; then if [ -n "$SYSTEMD" ]; then
if systemctl enable shorewall-init.service; then if systemctl enable shorewall-init; then
echo "Shorewall Init will start automatically at boot" echo "Shorewall Init will start automatically at boot"
fi fi
elif [ -x ${SBINDIR}/insserv -o -x /usr${SBINDIR}/insserv ]; then elif [ -x /sbin/insserv -o -x /usr/sbin/insserv ]; then
if insserv ${INITDIR}/shorewall-init ; then if insserv /etc/init.d/shorewall-init ; then
echo "Shorewall Init will start automatically at boot" echo "Shorewall Init will start automatically at boot"
else else
cant_autostart cant_autostart
fi fi
elif [ -x ${SBINDIR}/chkconfig -o -x /usr${SBINDIR}/chkconfig ]; then elif [ -x /sbin/chkconfig -o -x /usr/sbin/chkconfig ]; then
if chkconfig --add shorewall-init ; then if chkconfig --add shorewall-init ; then
echo "Shorewall Init will start automatically in run levels as follows:" echo "Shorewall Init will start automatically in run levels as follows:"
chkconfig --list shorewall-init chkconfig --list shorewall-init
else else
cant_autostart cant_autostart
fi fi
elif [ -x ${SBINDIR}/rc-update ]; then elif [ -x /sbin/rc-update ]; then
if rc-update add shorewall-init default; then if rc-update add shorewall-init default; then
echo "Shorewall Init will start automatically at boot" echo "Shorewall Init will start automatically at boot"
else else
cant_autostart cant_autostart
fi fi
else elif [ "$INIT" != rc.firewall ]; then #Slackware starts this automatically
cant_autostart cant_autostart
fi fi
fi fi
fi fi
else else
if [ -n "$first_install" ]; then if [ -n "$first_install" ]; then
if [ $HOST = debian ]; then if [ -n "$DEBIAN" ]; then
if [ -n "${DESTDIR}" ]; then if [ -n "${DESTDIR}" ]; then
mkdir -p ${DESTDIR}/etc/rcS.d mkdir -p ${DESTDIR}/etc/rcS.d
fi fi
ln -sf ../init.d/shorewall-init ${DESTDIR}${CONFDIR}/rcS.d/S38shorewall-init ln -sf ../init.d/shorewall-init ${DESTDIR}/etc/rcS.d/S38shorewall-init
echo "Shorewall Init will start automatically at boot" echo "Shorewall Init will start automatically at boot"
fi fi
fi fi
fi fi
[ -z "${DESTDIR}" ] && [ ! -f ~/.shorewallrc ] && cp ${SHAREDIR}/shorewall/shorewallrc .
if [ -f ${DESTDIR}/etc/ppp ]; then if [ -f ${DESTDIR}/etc/ppp ]; then
case $HOST in if [ -n "$DEBIAN" ] -o -n "$SUSE" ]; then
debian|suse) for directory in ip-up.d ip-down.d ipv6-up.d ipv6-down.d; do
for directory in ip-up.d ip-down.d ipv6-up.d ipv6-down.d; do mkdir -p ${DESTDIR}/etc/ppp/$directory #SuSE doesn't create the IPv6 directories
mkdir -p ${DESTDIR}/etc/ppp/$directory #SuSE doesn't create the IPv6 directories cp -fp ${DESTDIR}${LIBEXEC}/shorewall-init/ifupdown ${DESTDIR}/etc/ppp/$directory/shorewall
cp -fp ${DESTDIR}${LIBEXECDIR}/shorewall-init/ifupdown ${DESTDIR}${CONFDIR}/ppp/$directory/shorewall done
done elif [ -n "$REDHAT" ]; then
;; #
redhat) # Must use the dreaded ip_xxx.local file
# #
# Must use the dreaded ip_xxx.local file for file in ip-up.local ip-down.local; do
# FILE=${DESTDIR}/etc/ppp/$file
for file in ip-up.local ip-down.local; do if [ -f $FILE ]; then
FILE=${DESTDIR}/etc/ppp/$file if fgrep -q Shorewall-based $FILE ; then
if [ -f $FILE ]; then cp -fp ${DESTDIR}${LIBEXEC}/shorewall-init/ifupdown $FILE
if fgrep -q Shorewall-based $FILE ; then
cp -fp ${DESTDIR}${LIBEXECDIR}/shorewall-init/ifupdown $FILE
else
echo "$FILE already exists -- ppp devices will not be handled"
break
fi
else else
cp -fp ${DESTDIR}${LIBEXECDIR}/shorewall-init/ifupdown $FILE echo "$FILE already exists -- ppp devices will not be handled"
break
fi fi
done else
;; cp -fp ${DESTDIR}${LIBEXEC}/shorewall-init/ifupdown $FILE
esac fi
done
fi
fi fi
# #
# Report Success # Report Success
# #

View File

@@ -1,5 +0,0 @@
/var/log/shorewall-ifupdown.log {
missingok
notifempty
create 0600 root root
}

View File

@@ -1,100 +0,0 @@
#! /bin/bash
# The Shoreline Firewall (Shorewall) Packet Filtering Firewall - V4.5
#
# This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt]
#
# (c) 2012 - Tom Eastep (teastep@shorewall.net)
#
# On most distributions, this file should be called /etc/init.d/shorewall.
#
# Complete documentation is available at http://shorewall.net
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of Version 2 of the GNU General Public License
# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
#########################################################################################
#
# This is modified by the installer when ${SHAREDIR} <> /usr/share
#
. /usr/share/shorewall/shorewallrc
# check if shorewall-init is configured or not
if [ -f "$SYSCONFDIR/shorewall-init" ]; then
. $SYSCONFDIR/shorewall-init
if [ -z "$PRODUCTS" ]; then
echo "ERROR: No products configured" >&2
exit 1
fi
else
echo "ERROR: /etc/sysconfig/shorewall-init not found" >&2
exit 1
fi
# Initialize the firewall
shorewall_start () {
local PRODUCT
local VARDIR
echo -n "Initializing \"Shorewall-based firewalls\": "
for PRODUCT in $PRODUCTS; do
if [ -x ${VARDIR}/firewall ]; then
if ! /sbin/$PRODUCT status > /dev/null 2>&1; then
${VARDIR}/firewall stop || exit 1
fi
fi
done
if [ -n "$SAVE_IPSETS" -a -f "$SAVE_IPSETS" ]; then
ipset -R < "$SAVE_IPSETS"
fi
return 0
}
# Clear the firewall
shorewall_stop () {
local PRODUCT
local VARDIR
echo -n "Clearing \"Shorewall-based firewalls\": "
for PRODUCT in $PRODUCTS; do
VARDIR=/var/lib/$PRODUCT
[ -f /etc/$PRODUCT/vardir ] && . /etc/$PRODUCT/vardir
if [ -x ${VARDIR}/firewall ]; then
${VARDIR}/firewall clear || exit 1
fi
done
if [ -n "$SAVE_IPSETS" ]; then
mkdir -p $(dirname "$SAVE_IPSETS")
if ipset -S > "${SAVE_IPSETS}.tmp"; then
grep -qE -- '^(-N|create )' "${SAVE_IPSETS}.tmp" && mv -f "${SAVE_IPSETS}.tmp" "$SAVE_IPSETS"
fi
fi
return 0
}
case "$1" in
start)
shorewall_start
;;
stop)
shorewall_stop
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
exit 0

View File

@@ -16,8 +16,3 @@ IFUPDOWN=0
# during 'start' and will save them there during 'stop'. # during 'start' and will save them there during 'stop'.
# #
SAVE_IPSETS="" SAVE_IPSETS=""
#
# Where Up/Down events get logged
#
LOGFILE=/var/log/shorewall-ifupdown.log

View File

@@ -31,7 +31,7 @@ VERSION=xxx #The Build script inserts the actual version
usage() # $1 = exit status usage() # $1 = exit status
{ {
ME=$(basename $0) ME=$(basename $0)
echo "usage: $ME [ <shorewallrc file> ]" echo "usage: $ME"
exit $1 exit $1
} }
@@ -40,27 +40,6 @@ qt()
"$@" >/dev/null 2>&1 "$@" >/dev/null 2>&1
} }
split() {
local ifs
ifs=$IFS
IFS=:
set -- $1
echo $*
IFS=$ifs
}
mywhich() {
local dir
for dir in $(split $PATH); do
if [ -x $dir/$1 ]; then
return 0
fi
done
return 2
}
remove_file() # $1 = file to restore remove_file() # $1 = file to restore
{ {
if [ -f $1 -o -L $1 ] ; then if [ -f $1 -o -L $1 ] ; then
@@ -69,37 +48,8 @@ remove_file() # $1 = file to restore
fi fi
} }
# if [ -f /usr/share/shorewall-init/version ]; then
# Read the RC file INSTALLED_VERSION="$(cat /usr/share/shorewall-init/version)"
#
if [ $# -eq 0 ]; then
if [ -f ./shorewallrc ]; then
. ./shorewallrc
elif [ -f ~/.shorewallrc ]; then
. ~/.shorewallrc || exit 1
file=./.shorewallrc
elif [ -f /usr/share/shorewall/shorewallrc ]; then
. /usr/share/shorewall/shorewallrc
else
fatal_error "No configuration file specified and /usr/share/shorewall/shorewallrc not found"
fi
elif [ $# -eq 1 ]; then
file=$1
case $file in
/*|.*)
;;
*)
file=./$file
;;
esac
. $file || exit 1
else
usage 1
fi
if [ -f ${SHAREDIR}/shorewall-init/version ]; then
INSTALLED_VERSION="$(cat ${SHAREDIR}/shorewall-init/version)"
if [ "$INSTALLED_VERSION" != "$VERSION" ]; then if [ "$INSTALLED_VERSION" != "$VERSION" ]; then
echo "WARNING: Shorewall Init Version $INSTALLED_VERSION is installed" echo "WARNING: Shorewall Init Version $INSTALLED_VERSION is installed"
echo " and this is the $VERSION uninstaller." echo " and this is the $VERSION uninstaller."
@@ -110,55 +60,56 @@ else
VERSION="" VERSION=""
fi fi
[ -n "${LIBEXEC:=${SHAREDIR}}" ] [ -n "${LIBEXEC:=/usr/share}" ]
echo "Uninstalling Shorewall Init $VERSION" echo "Uninstalling Shorewall Init $VERSION"
INITSCRIPT=${CONFDIR}/init.d/shorewall-init INITSCRIPT=/etc/init.d/shorewall-init
if [ -f "$INITSCRIPT" ]; then if [ -n "$INITSCRIPT" ]; then
if mywhich updaterc.d ; then if [ -x /usr/sbin/updaterc.d ]; then
updaterc.d shorewall-init remove updaterc.d shorewall-init remove
elif mywhich insserv ; then elif [ -x /sbin/insserv -o -x /usr/sbin/insserv ]; then
insserv -r $INITSCRIPT insserv -r $INITSCRIPT
elif mywhich chkconfig ; then elif [ -x /sbin/chkconfig -o -x /usr/sbin/chkconfig ]; then
chkconfig --del $(basename $INITSCRIPT) chkconfig --del $(basename $INITSCRIPT)
elif mywhich systemctl ; then elif [ -x /sbin/systemctl ]; then
systemctl disable shorewall-init systemctl disable shorewall-init
else
rm -f /etc/rc*.d/*$(basename $INITSCRIPT)
fi fi
remove_file $INITSCRIPT remove_file $INITSCRIPT
fi fi
[ "$(readlink -m -q ${SBINDIR}/ifup-local)" = ${SHAREDIR}/shorewall-init ] && remove_file ${SBINDIR}/ifup-local [ "$(readlink -m -q /sbin/ifup-local)" = /usr/share/shorewall-init ] && remove_file /sbin/ifup-local
[ "$(readlink -m -q ${SBINDIR}/ifdown-local)" = ${SHAREDIR}/shorewall-init ] && remove_file ${SBINDIR}/ifdown-local [ "$(readlink -m -q /sbin/ifdown-local)" = /usr/share/shorewall-init ] && remove_file /sbin/ifdown-local
remove_file ${CONFDIR}/default/shorewall-init remove_file /etc/default/shorewall-init
remove_file ${CONFDIR}/sysconfig/shorewall-init remove_file /etc/sysconfig/shorewall-init
remove_file ${CONFDIR}/NetworkManager/dispatcher.d/01-shorewall remove_file /etc/NetworkManager/dispatcher.d/01-shorewall
remove_file ${CONFDIR}/network/if-up.d/shorewall remove_file /etc/network/if-up.d/shorewall
remove_file ${CONFDIR}/network/if-down.d/shorewall remove_file /etc/network/if-down.d/shorewall
remove_file ${CONFDIR}/sysconfig/network/if-up.d/shorewall remove_file /etc/sysconfig/network/if-up.d/shorewall
remove_file ${CONFDIR}/sysconfig/network/if-down.d/shorewall remove_file /etc/sysconfig/network/if-down.d/shorewall
remove_file /lib/systemd/system/shorewall.service
[ -n "$SYSTEMD" ] && remove_file ${SYSTEMD}/shorewall.service if [ -d /etc/ppp ]; then
if [ -d ${CONFDIR}/ppp ]; then
for directory in ip-up.d ip-down.d ipv6-up.d ipv6-down.d; do for directory in ip-up.d ip-down.d ipv6-up.d ipv6-down.d; do
remove_file ${CONFDIR}/ppp/$directory/shorewall remove_file /etc/ppp/$directory/shorewall
done done
for file in if-up.local if-down.local; do for file in if-up.local if-down.local; do
if fgrep -q Shorewall-based ${CONFDIR}/ppp/$FILE; then if fgrep -q Shorewall-based /etc/ppp/$FILE; then
remove_file ${CONFDIR}/ppp/$FILE remove_file /etc/ppp/$FILE
fi fi
done done
fi fi
rm -rf ${SHAREDIR}/shorewall-init rm -rf /usr/share/shorewall-init
rm -rf ${LIBEXEC}/shorewall-init rm -rf ${LIBEXEC}/shorewall-init
echo "Shorewall Init Uninstalled" echo "Shorewall Init Uninstalled"

View File

@@ -3,16 +3,16 @@ VARDIR=$(shell /sbin/shorewall-lite show vardir)
SHAREDIR=/usr/share/shorewall-lite SHAREDIR=/usr/share/shorewall-lite
RESTOREFILE?=.restore RESTOREFILE?=.restore
all: $(VARDIR)/$(RESTOREFILE) all: $(VARDIR)/${RESTOREFILE}
$(VARDIR)/$(RESTOREFILE): $(VARDIR)/firewall $(VARDIR)/${RESTOREFILE}: $(VARDIR)/firewall
@/sbin/shorewall-lite -q save >/dev/null; \ @/sbin/shorewall-lite -q save >/dev/null; \
if \ if \
/sbin/shorewall-lite -q restart >/dev/null 2>&1; \ /sbin/shorewall-lite -q restart >/dev/null 2>&1; \
then \ then \
/sbin/shorewall-lite -q save >/dev/null; \ /sbin/shorewall-lite -q save >/dev/null; \
else \ else \
/sbin/shorewall-lite -q restart 2>&1 | tail >&2; exit 1; \ /sbin/shorewall-lite -q restart 2>&1 | tail >&2; \
fi fi
# EOF # EOF

View File

@@ -23,7 +23,7 @@ export SHOREWALL_INIT_SCRIPT
test -x $SRWL || exit 0 test -x $SRWL || exit 0
test -x $WAIT_FOR_IFUP || exit 0 test -x $WAIT_FOR_IFUP || exit 0
test -n "$INITLOG" || { test -n "$INITLOG" || {
echo "INITLOG cannot be empty, please configure $0" ; echo "INITLOG cannot be empty, please configure $0" ;
exit 1; exit 1;
} }
@@ -35,9 +35,9 @@ fi
echo_notdone () { echo_notdone () {
if [ "$INITLOG" = "/dev/null" ] ; then if [ "$INITLOG" = "/dev/null" ] ; then
echo "not done." echo "not done."
else else
echo "not done (check $INITLOG)." echo "not done (check $INITLOG)."
fi fi
@@ -57,23 +57,17 @@ not_configured () {
exit 0 exit 0
} }
#
# The installer may alter this
#
. /usr/share/shorewall/shorewallrc
# parse the shorewall params file in order to use params in # parse the shorewall params file in order to use params in
# /etc/default/shorewall # /etc/default/shorewall
if [ -f "/etc/shorewall-lite/params" ]
if [ -f "$CONFDIR/shorewall-lite/params" ]
then then
. $CONFDIR/shorewall-lite/params . /etc/shorewall-lite/params
fi fi
# check if shorewall is configured or not # check if shorewall is configured or not
if [ -f "$SYSCONFDIR/shorewall-lite" ] if [ -f "/etc/default/shorewall-lite" ]
then then
. $SYSCONFDIR/shorewall-lite . /etc/default/shorewall-lite
SRWL_OPTS="$SRWL_OPTS $OPTIONS" SRWL_OPTS="$SRWL_OPTS $OPTIONS"
if [ "$startup" != "1" ] if [ "$startup" != "1" ]
then then

View File

@@ -20,31 +20,26 @@
# Source function library. # Source function library.
. /etc/rc.d/init.d/functions . /etc/rc.d/init.d/functions
#
# The installer may alter this
#
. /usr/share/shorewall/shorewallrc
prog="shorewall-lite" prog="shorewall-lite"
shorewall="${SBINDIR}/$prog" shorewall="/sbin/$prog"
logger="logger -i -t $prog" logger="logger -i -t $prog"
lockfile="/var/lock/subsys/$prog" lockfile="/var/lock/subsys/$prog"
# Get startup options (override default) # Get startup options (override default)
OPTIONS= OPTIONS=
if [ -f ${SYSCONFDIR}/$prog ]; then if [ -f /etc/sysconfig/$prog ]; then
. ${SYSCONFDIR}/$prog . /etc/sysconfig/$prog
fi fi
start() { start() {
echo -n $"Starting Shorewall: " echo -n $"Starting Shorewall: "
$shorewall $OPTIONS start 2>&1 | $logger $shorewall $OPTIONS start 2>&1 | $logger
retval=${PIPESTATUS[0]} retval=${PIPESTATUS[0]}
if [[ $retval == 0 ]]; then if [[ $retval == 0 ]]; then
touch $lockfile touch $lockfile
success success
else else
failure failure
fi fi
echo echo
@@ -55,10 +50,10 @@ stop() {
echo -n $"Stopping Shorewall: " echo -n $"Stopping Shorewall: "
$shorewall $OPTIONS stop 2>&1 | $logger $shorewall $OPTIONS stop 2>&1 | $logger
retval=${PIPESTATUS[0]} retval=${PIPESTATUS[0]}
if [[ $retval == 0 ]]; then if [[ $retval == 0 ]]; then
rm -f $lockfile rm -f $lockfile
success success
else else
failure failure
fi fi
echo echo
@@ -71,7 +66,7 @@ restart() {
echo -n $"Restarting Shorewall: " echo -n $"Restarting Shorewall: "
$shorewall $OPTIONS restart 2>&1 | $logger $shorewall $OPTIONS restart 2>&1 | $logger
retval=${PIPESTATUS[0]} retval=${PIPESTATUS[0]}
if [[ $retval == 0 ]]; then if [[ $retval == 0 ]]; then
touch $lockfile touch $lockfile
success success
else # Failed to start, clean up lock file if present else # Failed to start, clean up lock file if present

View File

@@ -1,11 +1,11 @@
#!/bin/sh #!/bin/sh
RCDLINKS="2,S41 3,S41 6,K41" RCDLINKS="2,S41 3,S41 6,K41"
# #
# The Shoreline Firewall (Shorewall) Packet Filtering Firewall - V4.5 # The Shoreline Firewall (Shorewall) Packet Filtering Firewall - V4.1
# #
# This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt] # This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt]
# #
# (c) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2012 - Tom Eastep (teastep@shorewall.net) # (c) 1999,2000,2001,2002,2003,2004,2005,2006,2007 - Tom Eastep (teastep@shorewall.net)
# #
# On most distributions, this file should be called /etc/init.d/shorewall. # On most distributions, this file should be called /etc/init.d/shorewall.
# #
@@ -61,14 +61,10 @@ usage() {
# Get startup options (override default) # Get startup options (override default)
################################################################################ ################################################################################
OPTIONS= OPTIONS=
if [ -f /etc/sysconfig/shorewall ]; then
# . /etc/sysconfig/shorewall
# The installer may alter this elif [ -f /etc/default/shorewall ] ; then
# . /etc/default/shorewall
. /usr/share/shorewall/shorewallrc
if [ -f ${SYSCONFDIR}/shorewall-lite ]; then
. ${SYSCONFDIR}/shorewall-lite
fi fi
SHOREWALL_INIT_SCRIPT=1 SHOREWALL_INIT_SCRIPT=1
@@ -80,13 +76,13 @@ command="$1"
case "$command" in case "$command" in
start) start)
exec ${SBINDIR}/shorewall-lite $OPTIONS start $STARTOPTIONS exec /sbin/shorewall-lite $OPTIONS start $STARTOPTIONS $@
;; ;;
restart|reload) restart|reload)
exec ${SBINDIR}/shorewall-lite $OPTIONS restart $RESTARTOPTIONS exec /sbin/shorewall-lite $OPTIONS restart $RESTARTOPTIONS $@
;; ;;
status|stop) status|stop)
exec ${SBINDIR}/shorewall-lite $OPTIONS $command $@ exec /sbin/shorewall-lite $OPTIONS $command $@
;; ;;
*) *)
usage usage

View File

@@ -27,18 +27,12 @@ VERSION=xxx #The Build script inserts the actual version
usage() # $1 = exit status usage() # $1 = exit status
{ {
ME=$(basename $0) ME=$(basename $0)
echo "usage: $ME [ <configuration-file> ]" echo "usage: $ME"
echo " $ME -v" echo " $ME -v"
echo " $ME -h" echo " $ME -h"
exit $1 exit $1
} }
fatal_error()
{
echo " ERROR: $@" >&2
exit 1
}
split() { split() {
local ifs local ifs
ifs=$IFS ifs=$IFS
@@ -91,11 +85,6 @@ install_file() # $1 = source $2 = target $3 = mode
run_install $T $OWNERSHIP -m $3 $1 ${2} run_install $T $OWNERSHIP -m $3 $1 ${2}
} }
require()
{
eval [ -n "\$$1" ] || fatal_error "Required option $1 not set"
}
# #
# Change to the directory containing this script # Change to the directory containing this script
# #
@@ -109,119 +98,71 @@ else
Product="Shorewall6 Lite" Product="Shorewall6 Lite"
fi fi
[ -n "$DESTDIR" ] || DESTDIR="$PREFIX"
# #
# Parse the run line # Parse the run line
# #
finished=0 # DEST is the SysVInit script directory
# INIT is the name of the script in the $DEST directory
while [ $finished -eq 0 ] ; do
case "$1" in
-*)
option=${option#-}
while [ -n "$option" ]; do
case $option in
h)
usage 0
;;
v)
echo "$Product Firewall Installer Version $VERSION"
exit 0
;;
*)
usage 1
;;
esac
done
shift
;;
*)
finished=1
;;
esac
done
# #
# Read the RC file if [ -z "$DEST" ] ; then
# DEST="/etc/init.d"
if [ $# -eq 0 ]; then
if [ -f ./shorewallrc ]; then
. ./shorewallrc || exit 1
file=./shorewallrc
elif [ -f ~/.shorewallrc ]; then
. ~/.shorewallrc
elif [ -f /usr/share/shorewall/shorewallrc ]; then
. /usr/share/shorewall/shorewallrc
else
fatal_error "No configuration file specified and /usr/share/shorewall/shorewallrc not found"
fi
elif [ $# -eq 1 ]; then
file=$1
case $file in
/*|.*)
;;
*)
file=./$file
;;
esac
. $file
else
usage 1
fi fi
for var in SHAREDIR LIBEXECDIRDIRDIR CONFDIR SBINDIR VARDIR; do if [ -z "$INIT" ] ; then
require $var INIT="$PRODUCT"
fi
while [ $# -gt 0 ] ; do
case "$1" in
-h|help|?)
usage 0
;;
-v)
echo "$Product Firewall Installer Version $VERSION"
exit 0
;;
*)
usage 1
;;
esac
shift
done done
PATH=${SBINDIR}:/bin:/usr${SBINDIR}:/usr/bin:/usr/local/bin:/usr/local${SBINDIR} PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
[ -n "${LIBEXEC:=/usr/share}" ]
case "$LIBEXEC" in
/*)
;;
*)
LIBEXEC=/usr/${LIBEXEC}
;;
esac
# #
# Determine where to install the firewall script # Determine where to install the firewall script
# #
cygwin= CYGWIN=
INSTALLD='-D' INSTALLD='-D'
INITFILE=$PRODUCT
T='-T' T='-T'
if [ -z "$BUILD" ]; then case $(uname) in
case $(uname) in CYGWIN*)
cygwin*) if [ -z "$DESTDIR" ]; then
BUILD=cygwin DEST=
;; INIT=
Darwin) fi
BUILD=apple
;;
*)
if [ -f ${CONFDIR}/debian_version ]; then
BUILD=debian
elif [ -f ${CONFDIR}/redhat-release ]; then
BUILD=redhat
elif [ -f ${CONFDIR}/SuSE-release ]; then
BUILD=suse
elif [ -f ${CONFDIR}/slackware-version ] ; then
BUILD=slackware
elif [ -f ${CONFDIR}/arch-release ] ; then
BUILD=archlinux
else
BUILD=linux
fi
;;
esac
fi
case $BUILD in
cygwin*)
OWNER=$(id -un) OWNER=$(id -un)
GROUP=$(id -gn) GROUP=$(id -gn)
;; ;;
apple) Darwin)
[ -z "$OWNER" ] && OWNER=root
[ -z "$GROUP" ] && GROUP=wheel
INSTALLD= INSTALLD=
T= T=
;; ;;
*) *)
[ -z "$OWNER" ] && OWNER=root [ -z "$OWNER" ] && OWNER=root
[ -z "$GROUP" ] && GROUP=root [ -z "$GROUP" ] && GROUP=root
@@ -230,53 +171,28 @@ esac
OWNERSHIP="-o $OWNER -g $GROUP" OWNERSHIP="-o $OWNER -g $GROUP"
[ -n "$HOST" ] || HOST=$BUILD
case "$HOST" in
cygwin)
echo "$PRODUCT is not supported on Cygwin" >&2
exit 1
;;
apple)
echo "$PRODUCT is not supported on OS X" >&2
exit 1
;;
debian)
echo "Installing Debian-specific configuration..."
;;
redhat)
echo "Installing Redhat/Fedora-specific configuration..."
;;
slackware)
echo "Installing Slackware-specific configuration..."
;;
archlinux)
echo "Installing ArchLinux-specific configuration..."
;;
linux|suse)
;;
*)
echo "ERROR: Unknown HOST \"$HOST\"" >&2
exit 1;
;;
esac
[ -z "$INITDIR" ] && INITDIR="${CONFDIR}/init.d"
if [ -n "$DESTDIR" ]; then if [ -n "$DESTDIR" ]; then
if [ `id -u` != 0 ] ; then if [ `id -u` != 0 ] ; then
echo "Not setting file owner/group permissions, not running as root." echo "Not setting file owner/group permissions, not running as root."
OWNERSHIP="" OWNERSHIP=""
fi fi
install -d $OWNERSHIP -m 755 ${DESTDIR}/sbin
install -d $OWNERSHIP -m 755 ${DESTDIR}${DEST}
elif [ -d /etc/apt -a -e /usr/bin/dpkg ]; then
DEBIAN=yes
elif [ -f /etc/redhat-release ]; then
FEDORA=yes
elif [ -f /etc/slackware-version ] ; then
DEST="/etc/rc.d"
INIT="rc.firewall"
elif [ -f /etc/arch-release ] ; then
DEST="/etc/rc.d"
INIT="$PRODUCT"
ARCHLINUX=yes
fi
install -d $OWNERSHIP -m 755 ${DESTDIR}/${SBINDIR} if [ -z "$DESTDIR" ]; then
install -d $OWNERSHIP -m 755 ${DESTDIR}${INITDIR}
if [ -n "$SYSTEMD" ]; then
mkdir -p ${DESTDIR}/lib/systemd/system
INITFILE=
fi
else
if [ ! -f /usr/share/shorewall/coreversion ]; then if [ ! -f /usr/share/shorewall/coreversion ]; then
echo "$PRODUCT $VERSION requires Shorewall Core which does not appear to be installed" >&2 echo "$PRODUCT $VERSION requires Shorewall Core which does not appear to be installed" >&2
exit 1 exit 1
@@ -284,34 +200,35 @@ else
if [ -f /lib/systemd/system ]; then if [ -f /lib/systemd/system ]; then
SYSTEMD=Yes SYSTEMD=Yes
INITFILE=
fi fi
elif [ -n "$SYSTEMD" ]; then
mkdir -p ${DESTDIR}/lib/systemd/system
fi fi
echo "Installing $Product Version $VERSION" echo "Installing $Product Version $VERSION"
# #
# Check for ${CONFDIR}/$PRODUCT # Check for /etc/$PRODUCT
# #
if [ -z "$DESTDIR" -a -d ${CONFDIR}/$PRODUCT ]; then if [ -z "$DESTDIR" -a -d /etc/$PRODUCT ]; then
if [ ! -f /usr/share/shorewall/coreversion ]; then if [ ! -f /usr/share/shorewall/coreversion ]; then
echo "$PRODUCT $VERSION requires Shorewall Core which does not appear to be installed" >&2 echo "$PRODUCT $VERSION requires Shorewall Core which does not appear to be installed" >&2
exit 1 exit 1
fi fi
[ -f ${CONFDIR}/$PRODUCT/shorewall.conf ] && \ [ -f /etc/$PRODUCT/shorewall.conf ] && \
mv -f ${CONFDIR}/$PRODUCT/shorewall.conf ${CONFDIR}/$PRODUCT/$PRODUCT.conf mv -f /etc/$PRODUCT/shorewall.conf /etc/$PRODUCT/$PRODUCT.conf
else else
rm -rf ${DESTDIR}${CONFDIR}/$PRODUCT rm -rf ${DESTDIR}/etc/$PRODUCT
rm -rf ${DESTDIR}/usr/share/$PRODUCT rm -rf ${DESTDIR}/usr/share/$PRODUCT
rm -rf ${DESTDIR}/var/lib/$PRODUCT rm -rf ${DESTDIR}/var/lib/$PRODUCT
[ "$LIBEXECDIR" = /usr/share ] || rm -rf ${DESTDIR}/usr/share/$PRODUCT/wait4ifup ${DESTDIR}/usr/share/$PRODUCT/shorecap [ "$LIBEXEC" = /usr/share ] || rm -rf /usr/share/$PRODUCT/wait4ifup /usr/share/$PRODUCT/shorecap
fi fi
# #
# Check for ${SBINDIR}/$PRODUCT # Check for /sbin/$PRODUCT
# #
if [ -f ${DESTDIR}${SBINDIR}/$PRODUCT ]; then if [ -f ${DESTDIR}/sbin/$PRODUCT ]; then
first_install="" first_install=""
else else
first_install="Yes" first_install="Yes"
@@ -319,112 +236,113 @@ fi
delete_file ${DESTDIR}/usr/share/$PRODUCT/xmodules delete_file ${DESTDIR}/usr/share/$PRODUCT/xmodules
install_file $PRODUCT ${DESTDIR}${SBINDIR}/$PRODUCT 0544 install_file $PRODUCT ${DESTDIR}/sbin/$PRODUCT 0544
echo "$Product control program installed in ${DESTDIR}${SBINDIR}/$PRODUCT" echo "$Product control program installed in ${DESTDIR}/sbin/$PRODUCT"
# #
# Create ${CONFDIR}/$PRODUCT, /usr/share/$PRODUCT and /var/lib/$PRODUCT if needed # Install the Firewall Script
# #
mkdir -p ${DESTDIR}${CONFDIR}/$PRODUCT if [ -n "$DEBIAN" ]; then
install_file init.debian.sh ${DESTDIR}/etc/init.d/$PRODUCT 0544
elif [ -n "$FEDORA" ]; then
install_file init.fedora.sh ${DESTDIR}/etc/init.d/$PRODUCT 0544
elif [ -n "$ARCHLINUX" ]; then
install_file init.archlinux.sh ${DESTDIR}/${DEST}/$INIT 0544
else
install_file init.sh ${DESTDIR}/${DEST}/$INIT 0544
fi
echo "$Product script installed in ${DESTDIR}${DEST}/$INIT"
#
# Create /etc/$PRODUCT, /usr/share/$PRODUCT and /var/lib/$PRODUCT if needed
#
mkdir -p ${DESTDIR}/etc/$PRODUCT
mkdir -p ${DESTDIR}/usr/share/$PRODUCT mkdir -p ${DESTDIR}/usr/share/$PRODUCT
mkdir -p ${DESTDIR}${LIBEXECDIR}/$PRODUCT mkdir -p ${DESTDIR}${LIBEXEC}/$PRODUCT
mkdir -p ${DESTDIR}/var/lib/$PRODUCT mkdir -p ${DESTDIR}/var/lib/$PRODUCT
chmod 755 ${DESTDIR}${CONFDIR}/$PRODUCT chmod 755 ${DESTDIR}/etc/$PRODUCT
chmod 755 ${DESTDIR}/usr/share/$PRODUCT chmod 755 ${DESTDIR}/usr/share/$PRODUCT
if [ -n "$DESTDIR" ]; then if [ -n "$DESTDIR" ]; then
mkdir -p ${DESTDIR}${CONFDIR}/logrotate.d mkdir -p ${DESTDIR}/etc/logrotate.d
chmod 755 ${DESTDIR}${CONFDIR}/logrotate.d chmod 755 ${DESTDIR}/etc/logrotate.d
mkdir -p ${DESTDIR}${INITDIR}
chmod 755 ${DESTDIR}${INITDIR}
fi fi
if [ -n "$INITFILE" ]; then
initfile="${DESTDIR}/${INITDIR}/${INITFILE}"
install_file ${INITSOURCE} "$initfile" 0544
[ "${SHAREDIR}" = /usr/share ] || eval sed -i \'s\|/usr/share/\|${SHAREDIR}/\|\' "$initfile"
echo "$Product init script installed in $initfile"
fi
# #
# Install the .service file # Install the .service file
# #
if [ -n "$SYSTEMD" ]; then if [ -n "$SYSTEMD" ]; then
run_install $OWNERSHIP -m 600 $PRODUCT.service ${DESTDIR}/${SYSTEMD}/$PRODUCT.service run_install $OWNERSHIP -m 600 $PRODUCT.service ${DESTDIR}/lib/systemd/system/$PRODUCT.service
echo "Service file installed as ${DESTDIR}/lib/systemd/system/$PRODUCT.service" echo "Service file installed as ${DESTDIR}/lib/systemd/system/$PRODUCT.service"
fi fi
# #
# Install the config file # Install the config file
# #
if [ ! -f ${DESTDIR}${CONFDIR}/$PRODUCT/$PRODUCT.conf ]; then if [ ! -f ${DESTDIR}/etc/$PRODUCT/$PRODUCT.conf ]; then
install_file $PRODUCT.conf ${DESTDIR}${CONFDIR}/$PRODUCT/$PRODUCT.conf 0744 install_file $PRODUCT.conf ${DESTDIR}/etc/$PRODUCT/$PRODUCT.conf 0744
echo "Config file installed as ${DESTDIR}${CONFDIR}/$PRODUCT/$PRODUCT.conf" echo "Config file installed as ${DESTDIR}/etc/$PRODUCT/$PRODUCT.conf"
fi fi
if [ $HOST = archlinux ] ; then if [ -n "$ARCHLINUX" ] ; then
sed -e 's!LOGFILE=/var/log/messages!LOGFILE=/var/log/messages.log!' -i ${DESTDIR}${CONFDIR}/$PRODUCT/$PRODUCT.conf sed -e 's!LOGFILE=/var/log/messages!LOGFILE=/var/log/messages.log!' -i ${DESTDIR}/etc/$PRODUCT/$PRODUCT.conf
fi fi
# #
# Install the Makefile # Install the Makefile
# #
run_install $OWNERSHIP -m 0600 Makefile ${DESTDIR}${CONFDIR}/$PRODUCT run_install $OWNERSHIP -m 0600 Makefile ${DESTDIR}/etc/$PRODUCT
[ $SHAREDIR = /usr/share ] || eval sed -i \'s\|/usr/share/\|${SHAREDIR}/\|\' ${DESTDIR}/${CONFDIR}/$PRODUCT/Makefile echo "Makefile installed as ${DESTDIR}/etc/$PRODUCT/Makefile"
[ $SBINDIR = /sbin ] || eval sed -i \'s\|/sbin/\|${SBINDIR}/\|\' ${DESTDIR}/${CONFDIR}/$PRODUCT/Makefile
echo "Makefile installed as ${DESTDIR}${CONFDIR}/$PRODUCT/Makefile"
# #
# Install the default config path file # Install the default config path file
# #
install_file configpath ${DESTDIR}${SHAREDIR}/$PRODUCT/configpath 0644 install_file configpath ${DESTDIR}/usr/share/$PRODUCT/configpath 0644
echo "Default config path file installed as ${DESTDIR}${SHAREDIR}/$PRODUCT/configpath" echo "Default config path file installed as ${DESTDIR}/usr/share/$PRODUCT/configpath"
# #
# Install the libraries # Install the libraries
# #
for f in lib.* ; do for f in lib.* ; do
if [ -f $f ]; then if [ -f $f ]; then
install_file $f ${DESTDIR}${SHAREDIR}/$PRODUCT/$f 0644 install_file $f ${DESTDIR}/usr/share/$PRODUCT/$f 0644
echo "Library ${f#*.} file installed as ${DESTDIR}/${SHAREDIR}/$PRODUCT/$f" echo "Library ${f#*.} file installed as ${DESTDIR}/usr/share/$PRODUCT/$f"
fi fi
done done
ln -sf lib.base ${DESTDIR}${SHAREDIR}/$PRODUCT/functions ln -sf lib.base ${DESTDIR}/usr/share/$PRODUCT/functions
echo "Common functions linked through ${DESTDIR}${SHAREDIR}/$PRODUCT/functions" echo "Common functions linked through ${DESTDIR}/usr/share/$PRODUCT/functions"
# #
# Install Shorecap # Install Shorecap
# #
install_file shorecap ${DESTDIR}${LIBEXECDIR}/$PRODUCT/shorecap 0755 install_file shorecap ${DESTDIR}${LIBEXEC}/$PRODUCT/shorecap 0755
[ $SHAREDIR = /usr/share ] || eval sed -i \'s\|/usr/share/\|${SHAREDIR}/\|\' ${DESTDIR}/${LIBEXECDIR}/$PRODUCT/shorecap
echo echo
echo "Capability file builder installed in ${DESTDIR}${LIBEXECDIR}/$PRODUCT/shorecap" echo "Capability file builder installed in ${DESTDIR}${LIBEXEC}/$PRODUCT/shorecap"
# #
# Install the Modules files # Install the Modules files
# #
if [ -f modules ]; then if [ -f modules ]; then
run_install $OWNERSHIP -m 0600 modules ${DESTDIR}${SHAREDIR}/$PRODUCT run_install $OWNERSHIP -m 0600 modules ${DESTDIR}/usr/share/$PRODUCT
echo "Modules file installed as ${DESTDIR}${SHAREDIR}/$PRODUCT/modules" echo "Modules file installed as ${DESTDIR}/usr/share/$PRODUCT/modules"
fi fi
if [ -f helpers ]; then if [ -f helpers ]; then
run_install $OWNERSHIP -m 0600 helpers ${DESTDIR}${SHAREDIR}/$PRODUCT run_install $OWNERSHIP -m 0600 helpers ${DESTDIR}/usr/share/$PRODUCT
echo "Helper modules file installed as ${DESTDIR}${SHAREDIR}/$PRODUCT/helpers" echo "Helper modules file installed as ${DESTDIR}/usr/share/$PRODUCT/helpers"
fi fi
for f in modules.*; do for f in modules.*; do
run_install $OWNERSHIP -m 0644 $f ${DESTDIR}${SHAREDIR}/$PRODUCT/$f run_install $OWNERSHIP -m 0644 $f ${DESTDIR}/usr/share/$PRODUCT/$f
echo "Module file $f installed as ${DESTDIR}${SHAREDIR}/$PRODUCT/$f" echo "Module file $f installed as ${DESTDIR}/usr/share/$PRODUCT/$f"
done done
# #
@@ -434,18 +352,18 @@ done
if [ -d manpages ]; then if [ -d manpages ]; then
cd manpages cd manpages
[ -n "$INSTALLD" ] || mkdir -p ${DESTDIR}${SHAREDIR}/man/man5/ ${DESTDIR}${SHAREDIR}/man/man8/ [ -n "$INSTALLD" ] || mkdir -p ${DESTDIR}/usr/share/man/man5/ ${DESTDIR}/usr/share/man/man8/
for f in *.5; do for f in *.5; do
gzip -c $f > $f.gz gzip -c $f > $f.gz
run_install $T $INSTALLD $OWNERSHIP -m 0644 $f.gz ${DESTDIR}${SHAREDIR}/man/man5/$f.gz run_install $T $INSTALLD $OWNERSHIP -m 0644 $f.gz ${DESTDIR}/usr/share/man/man5/$f.gz
echo "Man page $f.gz installed to ${DESTDIR}${SHAREDIR}/man/man5/$f.gz" echo "Man page $f.gz installed to ${DESTDIR}/usr/share/man/man5/$f.gz"
done done
for f in *.8; do for f in *.8; do
gzip -c $f > $f.gz gzip -c $f > $f.gz
run_install $T $INSTALLD $OWNERSHIP -m 0644 $f.gz ${DESTDIR}${SHAREDIR}/man/man8/$f.gz run_install $T $INSTALLD $OWNERSHIP -m 0644 $f.gz ${DESTDIR}/usr/share/man/man8/$f.gz
echo "Man page $f.gz installed to ${DESTDIR}${SHAREDIR}/man/man8/$f.gz" echo "Man page $f.gz installed to ${DESTDIR}/usr/share/man/man8/$f.gz"
done done
cd .. cd ..
@@ -453,79 +371,73 @@ if [ -d manpages ]; then
echo "Man Pages Installed" echo "Man Pages Installed"
fi fi
if [ -d ${DESTDIR}${CONFDIR}/logrotate.d ]; then if [ -d ${DESTDIR}/etc/logrotate.d ]; then
run_install $OWNERSHIP -m 0644 logrotate ${DESTDIR}${CONFDIR}/logrotate.d/$PRODUCT run_install $OWNERSHIP -m 0644 logrotate ${DESTDIR}/etc/logrotate.d/$PRODUCT
echo "Logrotate file installed as ${DESTDIR}${CONFDIR}/logrotate.d/$PRODUCT" echo "Logrotate file installed as ${DESTDIR}/etc/logrotate.d/$PRODUCT"
fi fi
# #
# Create the version file # Create the version file
# #
echo "$VERSION" > ${DESTDIR}${SHAREDIR}/$PRODUCT/version echo "$VERSION" > ${DESTDIR}/usr/share/$PRODUCT/version
chmod 644 ${DESTDIR}${SHAREDIR}/$PRODUCT/version chmod 644 ${DESTDIR}/usr/share/$PRODUCT/version
# #
# Remove and create the symbolic link to the init script # Remove and create the symbolic link to the init script
# #
if [ -z "$DESTDIR" ]; then if [ -z "$DESTDIR" ]; then
rm -f ${SHAREDIR}/$PRODUCT/init rm -f /usr/share/$PRODUCT/init
ln -s ${INITDIR}/${INITFILE} ${SHAREDIR}/$PRODUCT/init ln -s ${DEST}/${INIT} /usr/share/$PRODUCT/init
fi fi
delete_file ${DESTDIR}${SHAREDIR}/$PRODUCT/lib.common delete_file ${DESTDIR}/usr/share/$PRODUCT/lib.common
delete_file ${DESTDIR}${SHAREDIR}/$PRODUCT/lib.cli delete_file ${DESTDIR}/usr/share/$PRODUCT/lib.cli
delete_file ${DESTDIR}${SHAREDIR}/$PRODUCT/wait4ifup delete_file ${DESTDIR}/usr/share/$PRODUCT/wait4ifup
if [ -n "$SYSCONFFILE" -a ! -f ${DESTDIR}${SYSCONFDIR}/${PRODUCT} ]; then if [ -z "$DESTDIR" ]; then
if [ ${DESTDIR} ]; then touch /var/log/$PRODUCT-init.log
mkdir -p ${DESTDIR}${SYSCONFDIR}
chmod 755 ${DESTDIR}${SYSCONFDIR}
fi
run_install $OWNERSHIP -m 0644 default.debian ${DESTDIR}${SYSCONFDIR}/${PRODUCT} if [ -n "$first_install" ]; then
echo "$SYSCONFFILE installed in ${DESTDIR}${SYSCONFDIR}/${PRODUCT}" if [ -n "$DEBIAN" ]; then
fi run_install $OWNERSHIP -m 0644 default.debian /etc/default/$PRODUCT
if [ ${SHAREDIR} != /usr/share ]; then update-rc.d $PRODUCT defaults
eval sed -i \'s\|/usr/share/\|${SHAREDIR}/\|\' ${DESTDIR}/${SHAREDIR}/${PRODUCT}/lib.base
eval sed -i \'s\|/usr/share/\|${SHAREDIR}/\|\' ${DESTDIR}/${SBINDIR}/$PRODUCT if [ -x /sbin/insserv ]; then
fi insserv /etc/init.d/$PRODUCT
else
ln -s ../init.d/$PRODUCT /etc/rcS.d/S40$PRODUCT
fi
if [ -z "$DESTDIR" -a -n "$first_install" -a -z "${cygwin}${mac}" ]; then
if mywhich update-rc.d ; then
echo "$PRODUCT will start automatically at boot"
echo "Set startup=1 in ${SYSCONFDIR}/$PRODUCT to enable"
touch /var/log/$PRODUCT-init.log
perl -p -w -i -e 's/^STARTUP_ENABLED=No/STARTUP_ENABLED=Yes/;s/^IP_FORWARDING=On/IP_FORWARDING=Keep/;s/^SUBSYSLOCK=.*/SUBSYSLOCK=/;' ${CONFDIR}/${PRODUCT}/${PRODUCT}.conf
update-rc.d $PRODUCT enable defaults
elif [ -n "$SYSTEMD" ]; then
if systemctl enable ${PRODUCT}.service; then
echo "$Product will start automatically at boot" echo "$Product will start automatically at boot"
fi
elif mywhich insserv; then
if insserv ${INITDIR}/${INITFILE} ; then
echo "$PRODUCT will start automatically at boot"
echo "Set STARTUP_ENABLED=Yes in ${CONFDIR}/$PRODUCT/${PRODUCT}.conf to enable"
else else
cant_autostart if [ -n "$SYSTEMD" ]; then
if systemctl enable $PRODUCT; then
echo "$Product will start automatically at boot"
fi
elif [ -x /sbin/insserv -o -x /usr/sbin/insserv ]; then
if insserv /etc/init.d/$PRODUCT ; then
echo "$Product will start automatically at boot"
else
cant_autostart
fi
elif [ -x /sbin/chkconfig -o -x /usr/sbin/chkconfig ]; then
if chkconfig --add $PRODUCT ; then
echo "$Product will start automatically in run levels as follows:"
chkconfig --list $PRODUCT
else
cant_autostart
fi
elif [ -x /sbin/rc-update ]; then
if rc-update add $PRODUCT default; then
echo "$Product will start automatically at boot"
else
cant_autostart
fi
elif [ "$INIT" != rc.firewall ]; then #Slackware starts this automatically
cant_autostart
fi
fi fi
elif mywhich chkconfig; then
if chkconfig --add $PRODUCT ; then
echo "$PRODUCT will start automatically in run levels as follows:"
echo "Set STARTUP_ENABLED=Yes in ${CONFDIR}/$PRODUCT/${PRODUCT}.conf to enable"
chkconfig --list $PRODUCT
else
cant_autostart
fi
elif mywhich rc-update ; then
if rc-update add $PRODUCT default; then
echo "$PRODUCT will start automatically at boot"
echo "Set STARTUP_ENABLED=Yes in ${CONFDIR}/$PRODUCT/$PRODUCT.conf to enable"
else
cant_autostart
fi
elif [ "$INITFILE" != rc.${PRODUCT} ]; then #Slackware starts this automatically
cant_autostart
fi fi
fi fi

View File

@@ -24,10 +24,11 @@
g_program=shorewall-lite g_program=shorewall-lite
g_family=4 g_family=4
#
# This may be altered by the installer
#
g_basedir=/usr/share/shorewall g_basedir=/usr/share/shorewall
. ${g_basedir}/lib.base [ -n "${VARDIR:=/var/lib/$g_program}" ]
[ -n "${SHAREDIR:=/usr/share/$g_program}" ]
[ -n "${CONFDIR:=/etc/$g_program}" ]
. /usr/share/shorewall/lib.base

View File

@@ -1,6 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
<refentry> <refentry>
<refmeta> <refmeta>
<refentrytitle>shorewall-lite-vardir</refentrytitle> <refentrytitle>shorewall-lite-vardir</refentrytitle>
@@ -36,28 +34,6 @@
directory. If you add this file, you should copy the files from directory. If you add this file, you should copy the files from
<filename>/var/lib/shorewall-lite</filename> to the new directory before <filename>/var/lib/shorewall-lite</filename> to the new directory before
performing a <command>shorewall-lite restart</command>.</para> performing a <command>shorewall-lite restart</command>.</para>
<note>
<para>Beginning with Shorewall 4.5.2, use of this file is deprecated in
favor of specifying VARDIR in the <filename>shorewallrc</filename> file
used during installation of Shorewall Core. While the name of the
variable remains VARDIR, the meaning is slightly different. When set in
shorewallrc, Shorewall Lite, will create a directory under the specified
path name to hold state information.</para>
<para>Example:</para>
<blockquote>
<para>VARDIR=<filename><filename>/opt/var/lib/</filename></filename></para>
<para>The state directory for Shorewall Lite will be
/opt/var/lib/shorewall-lite/.</para>
</blockquote>
<para> When VARDIR is set in /etc/shorewall-lite/vardir, Shorewall Lite
will save its state in the <replaceable>directory</replaceable>
specified.</para>
</note>
</refsect1> </refsect1>
<refsect1> <refsect1>
@@ -85,4 +61,4 @@
shorewall-tcrules(5), shorewall-tos(5), shorewall-tunnels(5), shorewall-tcrules(5), shorewall-tos(5), shorewall-tunnels(5),
shorewall-zones(5)</para> shorewall-zones(5)</para>
</refsect1> </refsect1>
</refentry> </refentry>

View File

@@ -517,17 +517,15 @@
defined in the <ulink defined in the <ulink
url="shorewall-interfaces.html">shorewall-interfaces</ulink>(5) url="shorewall-interfaces.html">shorewall-interfaces</ulink>(5)
file. A <emphasis>host-list</emphasis> is comma-separated list whose file. A <emphasis>host-list</emphasis> is comma-separated list whose
elements are host or network addresses.</para> elements are host or network addresses.<caution>
<para>The <command>add</command> command is not very robust. If
<caution> there are errors in the <replaceable>host-list</replaceable>,
<para>The <command>add</command> command is not very robust. If you may see a large number of error messages yet a subsequent
there are errors in the <replaceable>host-list</replaceable>, you <command>shorewall-lite show zones</command> command will
may see a large number of error messages yet a subsequent indicate that all hosts were added. If this happens, replace
<command>shorewall-lite show zones</command> command will indicate <command>add</command> by <command>delete</command> and run the
that all hosts were added. If this happens, replace same command again. Then enter the correct command.</para>
<command>add</command> by <command>delete</command> and run the </caution></para>
same command again. Then enter the correct command.</para>
</caution>
</listitem> </listitem>
</varlistentry> </varlistentry>

View File

@@ -45,22 +45,17 @@
# used during firewall compilation, then the generated firewall program will likewise not # used during firewall compilation, then the generated firewall program will likewise not
# require Shorewall to be installed. # require Shorewall to be installed.
SHAREDIR=/usr/share/shorewall-lite
VARDIR=/var/lib/shorewall-lite
CONFDIR=/etc/shorewall-lite
g_program=shorewall-lite g_program=shorewall-lite
g_product="Shorewall Lite"
g_family=4
g_base=shorewall
g_basedir=/usr/share/shorewall-lite
# . /usr/share/shorewall-lite/lib.base
# This is modified by the installer when ${SHAREDIR} != /usr/share . /usr/share/shorewall/lib.cli
#
. /usr/share/shorewall/shorewallrc
g_libexec="$LIBEXECDIR"
g_sharedir="$SHAREDIR"/shorewall-lite
g_sbindir="$SBINDIR"
g_vardir="$VARDIR"
g_confdir="$CONFDIR"/shorewall-lite
g_readrc=1
. ${SHAREDIR}/shorewall/lib.cli
. /usr/share/shorewall-lite/configpath . /usr/share/shorewall-lite/configpath
[ -n "$PATH" ] || PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin [ -n "$PATH" ] || PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin

View File

@@ -4,7 +4,7 @@
# #
# This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt] # This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt]
# #
# (c) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011 - # (c) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011 -
# Tom Eastep (teastep@shorewall.net) # Tom Eastep (teastep@shorewall.net)
# #
# Shorewall documentation is available at http://www.shorewall.net # Shorewall documentation is available at http://www.shorewall.net
@@ -27,18 +27,6 @@
################################################################################################ ################################################################################################
g_program=shorewall-lite g_program=shorewall-lite
# . /usr/share/shorewall/lib.cli
# This is modified by the installer when ${SHAREDIR} != /usr/share
#
. /usr/share/shorewall/shorewallrc
g_libexec="$LIBEXECDIR"
g_sharedir="$SHAREDIR"/shorewall-lite
g_sbindir="$SBINDIR"
g_vardir="$VARDIR"
g_confdir="$CONFDIR"/shorewall-lite
g_readrc=1
. ${SHAREDIR}/shorewall/lib.cli
shorewall_cli $@ shorewall_cli $@

View File

@@ -1,5 +1,5 @@
############################################################################### ###############################################################################
# /etc/shorewall-lite/shorewall-lite.conf Version 4 - Change the following # /etc/shorewall-lite/shorewall-lite.conf Version 4 - Change the following
# variables to override the values in the shorewall.conf file used to # variables to override the values in the shorewall.conf file used to
# compile /var/lib/shorewall-lite/firewall. Those values may be found in # compile /var/lib/shorewall-lite/firewall. Those values may be found in
# /var/lib/shorewall-lite/firewall.conf. # /var/lib/shorewall-lite/firewall.conf.

View File

@@ -31,7 +31,7 @@ VERSION=xxx #The Build script inserts the actual version
usage() # $1 = exit status usage() # $1 = exit status
{ {
ME=$(basename $0) ME=$(basename $0)
echo "usage: $ME [ <shorewallrc file> ]" echo "usage: $ME"
exit $1 exit $1
} }
@@ -40,25 +40,16 @@ qt()
"$@" >/dev/null 2>&1 "$@" >/dev/null 2>&1
} }
split() { restore_file() # $1 = file to restore
local ifs {
ifs=$IFS if [ -f ${1}-shorewall.bkout ]; then
IFS=: if (mv -f ${1}-shorewall-lite.bkout $1); then
set -- $1 echo
echo $* echo "$1 restored"
IFS=$ifs else
} exit 1
fi
mywhich() { fi
local dir
for dir in $(split $PATH); do
if [ -x $dir/$1 ]; then
return 0
fi
done
return 2
} }
remove_file() # $1 = file to restore remove_file() # $1 = file to restore
@@ -69,37 +60,8 @@ remove_file() # $1 = file to restore
fi fi
} }
# if [ -f /usr/share/shorewall-lite/version ]; then
# Read the RC file INSTALLED_VERSION="$(cat /usr/share/shorewall-lite/version)"
#
if [ $# -eq 0 ]; then
if [ -f ./shorewallrc ]; then
. ./shorewallrc
elif [ -f ~/.shorewallrc ]; then
. ~/.shorewallrc || exit 1
file=./.shorewallrc
elif [ -f /usr/share/shorewall/shorewallrc ]; then
. /usr/share/shorewall/shorewallrc
else
fatal_error "No configuration file specified and /usr/share/shorewall/shorewallrc not found"
fi
elif [ $# -eq 1 ]; then
file=$1
case $file in
/*|.*)
;;
*)
file=./$file
;;
esac
. $file
else
usage 1
fi
if [ -f ${SHAREDIR}/shorewall-lite/version ]; then
INSTALLED_VERSION="$(cat ${SHAREDIR}/shorewall-lite/version)"
if [ "$INSTALLED_VERSION" != "$VERSION" ]; then if [ "$INSTALLED_VERSION" != "$VERSION" ]; then
echo "WARNING: Shorewall Lite Version $INSTALLED_VERSION is installed" echo "WARNING: Shorewall Lite Version $INSTALLED_VERSION is installed"
echo " and this is the $VERSION uninstaller." echo " and this is the $VERSION uninstaller."
@@ -110,40 +72,49 @@ else
VERSION="" VERSION=""
fi fi
[ -n "${LIBEXEC:=/usr/share}" ]
echo "Uninstalling Shorewall Lite $VERSION" echo "Uninstalling Shorewall Lite $VERSION"
if qt iptables -L shorewall -n && [ ! -f ${SBINDIR}/shorewall ]; then if qt iptables -L shorewall -n && [ ! -f /sbin/shorewall ]; then
shorewall-lite clear /sbin/shorewall-lite clear
fi fi
if [ -L ${SHAREDIR}/shorewall-lite/init ]; then if [ -L /usr/share/shorewall-lite/init ]; then
FIREWALL=$(readlink -m -q ${SHAREDIR}/shorewall-lite/init) FIREWALL=$(readlink -m -q /usr/share/shorewall-lite/init)
elIF [ -n "$INITFILE" ]; then else
FIREWALL=${INITDIR}/${INITFILE} FIREWALL=/etc/init.d/shorewall-lite
fi fi
if [ -f "$FIREWALL" ]; then if [ -n "$FIREWALL" ]; then
if mywhich updaterc.d ; then if [ -x /usr/sbin/updaterc.d ]; then
updaterc.d shorewall-lite remove updaterc.d shorewall-lite remove
elif if mywhich insserv ; then elif [ -x /sbin/insserv -o -x /usr/sbin/insserv ]; then
insserv -r $FIREWALL insserv -r $FIREWALL
elif [ mywhich chkconfig ; then elif [ -x /sbin/chkconfig -o -x /usr/sbin/chkconfig ]; then
chkconfig --del $(basename $FIREWALL) chkconfig --del $(basename $FIREWALL)
elif mywhich systemctl ; then elif [ -x /sbin/systemctl ]; then
systemctl disable shorewall-lite systemctl disable shorewall-lite
else
rm -f /etc/rc*.d/*$(basename $FIREWALL)
fi fi
remove_file $FIREWALL remove_file $FIREWALL
rm -f ${FIREWALL}-*.bkout
fi fi
rm -f ${SBINDIR}/shorewall-lite rm -f /sbin/shorewall-lite
rm -f /sbin/shorewall-lite-*.bkout
rm -rf ${SBINDIR}/shorewall-lite rm -rf /etc/shorewall-lite
rm -rf ${VARDIR}/shorewall-lite rm -rf /etc/shorewall-lite-*.bkout
rm -rf ${SHAREDIR}/shorewall-lite rm -rf /var/lib/shorewall-lite
rm -rf /var/lib/shorewall-lite-*.bkout
rm -rf /usr/share/shorewall-lite
rm -rf ${LIBEXEC}/shorewall-lite rm -rf ${LIBEXEC}/shorewall-lite
rm -f ${CONFDIR}/logrotate.d/shorewall-lite rm -rf /usr/share/shorewall-lite-*.bkout
[ -n "$SYSTEMD" ] && rm -f ${SYSTEMD}/shorewall-lite.service rm -f /etc/logrotate.d/shorewall-lite
rm -f /lib/systemd/system/shorewall-lite.service
echo "Shorewall Lite Uninstalled" echo "Shorewall Lite Uninstalled"

View File

@@ -11,7 +11,6 @@
#ACTION SOURCE DEST PROTO DEST SOURCE RATE USER/ #ACTION SOURCE DEST PROTO DEST SOURCE RATE USER/
# PORT(S) PORT(S) LIMIT GROUP # PORT(S) PORT(S) LIMIT GROUP
PARAM - - udp 10080 PARAM - - udp 10080
PARAM - - tcp 10080
# #
# You may also need this rule. With AMANDA 2.4.4 on Linux kernel 2.6, # You may also need this rule. With AMANDA 2.4.4 on Linux kernel 2.6,
# it should not be necessary to use this. The ip_conntrack_amanda # it should not be necessary to use this. The ip_conntrack_amanda

View File

@@ -1,15 +0,0 @@
#
# Shorewall version 4 - blacklist Macro
#
# /usr/share/shorewall/macro.blacklist
#
# This macro handles blacklisting using BLACKLIST_DISPOSITION and BLACKLIST_LOGLEVEL
#
###############################################################################
#ACTION SOURCE DEST PROTO DEST SOURCE RATE USER/
# PORT(S) PORT(S) LIMIT GROUP
?IF $BLACKLIST_LOGLEVEL
blacklog
?ELSE
$BLACKLIST_DISPOSITION
?ENDIF

View File

@@ -1,11 +0,0 @@
#
# Shorewall version 4 - MSSQL Macro
#
# /usr/share/shorewall/macro.MSSQL
#
# This macro handles MSSQL (Microsoft SQL Server)
#
###############################################################################
#ACTION SOURCE DEST PROTO DEST SOURCE RATE USER/
# PORT(S) PORT(S) LIMIT GROUP
PARAM - - tcp 1433

View File

@@ -1,11 +1,9 @@
# #
# Shorewall version 4 - Multicast DNS Macro -- this macro assumes that only # Shorewall version 4 - Multicast DNS Macro
# the DEST zone sends mDNS queries. If both zones send
# queries, use the mDNSbi macro.
# #
# /usr/share/shorewall/macro.mDNS # /usr/share/shorewall/macro.mDNS
# #
# This macro handles multicast DNS traffic # This macro handles multicast DNS traffic.
# #
############################################################################### ###############################################################################
#ACTION SOURCE DEST PROTO DEST SOURCE RATE USER/ #ACTION SOURCE DEST PROTO DEST SOURCE RATE USER/

View File

@@ -1,16 +0,0 @@
#
# Shorewall version 4 - Bi-directional Multicast DNS Macro.
#
# /usr/share/shorewall/macro.mDNSbi
#
# This macro handles multicast DNS traffic
#
###############################################################################
#ACTION SOURCE DEST PROTO DEST SOURCE RATE USER/
# PORT(S) PORT(S) LIMIT GROUP
PARAM - 224.0.0.251 udp 5353
PARAM - - udp 32768: 5353
PARAM - 224.0.0.251 2
PARAM DEST SOURCE:224.0.0.251 udp 5353
PARAM DEST SOURCE udp 32768: 5353
PARAM DEST SOURCE:224.0.0.251 2

View File

@@ -2,22 +2,20 @@
VARDIR=$(shell /sbin/shorewall show vardir) VARDIR=$(shell /sbin/shorewall show vardir)
CONFDIR=/etc/shorewall CONFDIR=/etc/shorewall
RESTOREFILE?=firewall RESTOREFILE?=firewall
all: $(VARDIR)/${RESTOREFILE}
all: $(VARDIR)/$(RESTOREFILE) $(VARDIR)/${RESTOREFILE}: $(CONFDIR)/*
$(VARDIR)/$(RESTOREFILE): $(CONFDIR)/*
@/sbin/shorewall -q save >/dev/null; \ @/sbin/shorewall -q save >/dev/null; \
if \ if \
/sbin/shorewall -q restart >/dev/null 2>&1; \ /sbin/shorewall -q restart >/dev/null 2>&1; \
then \ then \
/sbin/shorewall -q save >/dev/null; \ /sbin/shorewall -q save >/dev/null; \
else \ else \
/sbin/shorewall -q restart 2>&1 | tail >&2; exit 1; \ /sbin/shorewall -q restart 2>&1 | tail >&2; \
fi fi
clean: clean:
@rm -f $(CONFDIR)/*~ $(CONFDIR)/.*~ @rm -f $(CONFDIR)/*~ $(CONFDIR)/.*~
.PHONY: clean .PHONY: clean
# EOF # EOF

View File

@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<includepath />

17
Shorewall/Perl/.project Normal file
View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Shorewall</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.epic.perleditor.perlbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.epic.perleditor.perlnature</nature>
</natures>
</projectDescription>

View File

@@ -46,7 +46,6 @@ my $jumpchainref;
my %accountingjumps; my %accountingjumps;
my $asection; my $asection;
my $defaultchain; my $defaultchain;
my $ipsecdir;
my $defaultrestriction; my $defaultrestriction;
my $restriction; my $restriction;
my $accounting_commands = { COMMENT => 0, SECTION => 2 }; my $accounting_commands = { COMMENT => 0, SECTION => 2 };
@@ -86,14 +85,13 @@ sub initialize() {
# The section number is initialized to a value less thatn LEGACY. It will be set to LEGACY if a # The section number is initialized to a value less thatn LEGACY. It will be set to LEGACY if a
# the first non-commentary line in the accounting file isn't a section header # the first non-commentary line in the accounting file isn't a section header
# #
# This allows the section header processor to quickly check for correct order # This allows the section header processor to quickly check for correct order
# #
$asection = -1; $asection = -1;
# #
# These are the legacy values # These are the legacy values
# #
$defaultchain = 'accounting'; $defaultchain = 'accounting';
$ipsecdir = '';
$defaultrestriction = NO_RESTRICT; $defaultrestriction = NO_RESTRICT;
$sectionname = ''; $sectionname = '';
} }
@@ -113,25 +111,20 @@ sub process_section ($) {
if ( $sectionname eq 'INPUT' ) { if ( $sectionname eq 'INPUT' ) {
$defaultchain = 'accountin'; $defaultchain = 'accountin';
$ipsecdir = 'in';
$defaultrestriction = INPUT_RESTRICT; $defaultrestriction = INPUT_RESTRICT;
} elsif ( $sectionname eq 'OUTPUT' ) { } elsif ( $sectionname eq 'OUTPUT' ) {
$defaultchain = 'accountout'; $defaultchain = 'accountout';
$ipsecdir = 'out';
$defaultrestriction = OUTPUT_RESTRICT; $defaultrestriction = OUTPUT_RESTRICT;
} elsif ( $sectionname eq 'FORWARD' ) { } elsif ( $sectionname eq 'FORWARD' ) {
$defaultchain = 'accountfwd'; $defaultchain = 'accountfwd';
$ipsecdir = '';
$defaultrestriction = NO_RESTRICT; $defaultrestriction = NO_RESTRICT;
} else { } else {
fatal_error "The $sectionname SECTION is not allowed when ACCOUNTING_TABLE=filter" unless $acctable eq 'mangle'; fatal_error "The $sectionname SECTION is not allowed when ACCOUNTING_TABLE=filter" unless $acctable eq 'mangle';
if ( $sectionname eq 'PREROUTING' ) { if ( $sectionname eq 'PREROUTING' ) {
$defaultchain = 'accountpre'; $defaultchain = 'accountpre';
$ipsecdir = 'in';
$defaultrestriction = PREROUTE_RESTRICT; $defaultrestriction = PREROUTE_RESTRICT;
} else { } else {
$defaultchain = 'accountpost'; $defaultchain = 'accountpost';
$ipsecdir = 'out';
$defaultrestriction = POSTROUTE_RESTRICT; $defaultrestriction = POSTROUTE_RESTRICT;
} }
} }
@@ -201,7 +194,7 @@ sub process_accounting_rule( ) {
$ports = '' if $ports eq 'any' || $ports eq 'all'; $ports = '' if $ports eq 'any' || $ports eq 'all';
$sports = '' if $sports eq 'any' || $sports eq 'all'; $sports = '' if $sports eq 'any' || $sports eq 'all';
fatal_error "USER/GROUP may only be specified in the OUTPUT section" unless $user eq '-' || $asection == OUTPUT; fatal_error "USER/GROUP may only be specified in the OUTPUT section" unless $user eq '-' || $asection == OUTPUT;
my $rule = do_proto( $proto, $ports, $sports ) . do_user ( $user ) . do_test ( $mark, $globals{TC_MASK} ) . do_headers( $headers ); my $rule = do_proto( $proto, $ports, $sports ) . do_user ( $user ) . do_test ( $mark, $globals{TC_MASK} ) . do_headers( $headers );
my $rule2 = 0; my $rule2 = 0;
@@ -257,7 +250,7 @@ sub process_accounting_rule( ) {
if ( $source eq 'any' || $source eq 'all' ) { if ( $source eq 'any' || $source eq 'all' ) {
$source = ALLIP; $source = ALLIP;
} else { } else {
fatal_error "MAC addresses only allowed in the INPUT and FORWARD sections" if $source =~ /~/ && ( $asection == OUTPUT || ! $asection ); fatal_error "MAC addresses only allowed in the INPUT and FORWARD sections" if $source =~ /~/ && ( $asection == OUTPUT || ! $asection );
} }
@@ -292,25 +285,11 @@ sub process_accounting_rule( ) {
} }
my $chainref = $chain_table{$config{ACCOUNTING_TABLE}}{$chain}; my $chainref = $chain_table{$config{ACCOUNTING_TABLE}}{$chain};
my $dir = $ipsecdir; my $dir;
if ( $asection && $ipsec ne '-' ) {
if ( $ipsecdir ) {
fatal_error "Invalid IPSEC ($ipsec)" if $ipsec =~ /^(?:in|out)\b/;
} else {
if ( $ipsec =~ s/^(?:(in|out)\b)// ) {
$dir = $1;
} else {
fatal_error q(IPSEC rules in the $asection section require that the value begin with 'in' or 'out');
}
}
$rule .= do_ipsec( $dir, $ipsec );
}
if ( ! $chainref ) { if ( ! $chainref ) {
if ( reserved_chain_name( $chain ) ) { if ( reserved_chain_name( $chain ) ) {
fatal_error "May not use chain $chain in the $sectionname section" if $asection && $chain ne $defaultchain; fatal_error "May not use chain $chain in the $sectionname section" if $asection && $chain ne $defaultchain;
$chainref = ensure_accounting_chain $chain, 0 , $restriction; $chainref = ensure_accounting_chain $chain, 0 , $restriction;
} elsif ( $asection ) { } elsif ( $asection ) {
fatal_error "Unknown accounting chain ($chain)"; fatal_error "Unknown accounting chain ($chain)";
@@ -318,36 +297,32 @@ sub process_accounting_rule( ) {
$chainref = ensure_accounting_chain $chain, 0 , $restriction; $chainref = ensure_accounting_chain $chain, 0 , $restriction;
} }
unless ( $asection ) { $dir = ipsec_chain_name( $chain );
$dir = ipsec_chain_name( $chain );
if ( $ipsec ne '-' ) { if ( $ipsec ne '-' ) {
if ( $dir ) { if ( $dir ) {
$rule .= do_ipsec( $dir, $ipsec ); $rule .= do_ipsec( $dir, $ipsec );
$chainref->{ipsec} = $dir;
} else {
fatal_error "Adding an IPSEC rule to an unreferenced accounting chain is not allowed";
}
} else {
warning_message "Adding rule to unreferenced accounting chain $chain" unless reserved_chain_name( $chain );
$chainref->{ipsec} = $dir; $chainref->{ipsec} = $dir;
} else {
fatal_error "Adding an IPSEC rule to an unreferenced accounting chain is not allowed";
} }
} else {
warning_message "Adding rule to unreferenced accounting chain $chain" unless reserved_chain_name( $chain );
$chainref->{ipsec} = $dir;
} }
} else { } else {
fatal_error "$chain is not an accounting chain" unless $chainref->{accounting}; fatal_error "$chain is not an accounting chain" unless $chainref->{accounting};
unless ( $asection ) { if ( $ipsec ne '-' ) {
if ( $ipsec ne '-' ) { $dir = $chainref->{ipsec};
$dir = $chainref->{ipsec}; fatal_error "Adding an IPSEC rule into a non-IPSEC chain is not allowed" unless $dir;
fatal_error "Adding an IPSEC rule into a non-IPSEC chain is not allowed" unless $dir; $rule .= do_ipsec( $dir , $ipsec );
$rule .= do_ipsec( $dir , $ipsec ); } elsif ( $asection ) {
} elsif ( $asection ) { $restriction |= $chainref->{restriction};
$restriction |= $chainref->{restriction};
}
} }
} }
set_optflags( $chainref, DONT_OPTIMIZE ) if $target eq 'RETURN'; dont_optimize( $chainref ) if $target eq 'RETURN';
if ( $jumpchainref ) { if ( $jumpchainref ) {
if ( $asection ) { if ( $asection ) {
@@ -363,7 +338,7 @@ sub process_accounting_rule( ) {
} }
fatal_error "$chain is not an accounting chain" unless $chainref->{accounting}; fatal_error "$chain is not an accounting chain" unless $chainref->{accounting};
$restriction = $dir eq 'in' ? INPUT_RESTRICT : OUTPUT_RESTRICT if $dir; $restriction = $dir eq 'in' ? INPUT_RESTRICT : OUTPUT_RESTRICT if $dir;
expand_rule expand_rule
@@ -391,6 +366,7 @@ sub process_accounting_rule( ) {
} else { } else {
$jumpchainref->{ipsec} = $chainref->{ipsec}; $jumpchainref->{ipsec} = $chainref->{ipsec};
} }
} }
if ( $rule2 ) { if ( $rule2 ) {
@@ -418,7 +394,7 @@ sub setup_accounting() {
my $nonEmpty = 0; my $nonEmpty = 0;
$nonEmpty |= process_accounting_rule while read_a_line( NORMAL_READ ); $nonEmpty |= process_accounting_rule while read_a_line;
clear_comment; clear_comment;
@@ -431,7 +407,7 @@ sub setup_accounting() {
} }
if ( $tableref->{accounting} ) { if ( $tableref->{accounting} ) {
set_optflags( 'accounting' , DONT_OPTIMIZE ); dont_optimize( 'accounting' );
for my $chain ( qw/INPUT FORWARD/ ) { for my $chain ( qw/INPUT FORWARD/ ) {
insert_ijump( $tableref->{$chain}, j => 'accounting', 0 ); insert_ijump( $tableref->{$chain}, j => 'accounting', 0 );
} }
@@ -453,7 +429,7 @@ sub setup_accounting() {
insert_ijump( $tableref->{POSTROUTING}, j => 'accountpost', 0 ); insert_ijump( $tableref->{POSTROUTING}, j => 'accountpost', 0 );
} }
} elsif ( $tableref->{accounting} ) { } elsif ( $tableref->{accounting} ) {
set_optflags( 'accounting' , DONT_OPTIMIZE ); dont_optimize( 'accounting' );
for my $chain ( qw/INPUT FORWARD OUTPUT/ ) { for my $chain ( qw/INPUT FORWARD OUTPUT/ ) {
insert_ijump( $tableref->{$chain}, j => 'accounting', 0 ); insert_ijump( $tableref->{$chain}, j => 'accounting', 0 );
} }

File diff suppressed because it is too large Load Diff

View File

@@ -54,10 +54,10 @@ my $family;
# #
# Initilize the package-globals in the other modules # Initilize the package-globals in the other modules
# #
sub initialize_package_globals( $$ ) { sub initialize_package_globals( $ ) {
Shorewall::Config::initialize($family, $_[1]); Shorewall::Config::initialize($family);
Shorewall::Chains::initialize ($family, 1, $export ); Shorewall::Chains::initialize ($family, 1, $export );
Shorewall::Zones::initialize ($family, $_[0]); Shorewall::Zones::initialize ($family, shift);
Shorewall::Nat::initialize; Shorewall::Nat::initialize;
Shorewall::Providers::initialize($family); Shorewall::Providers::initialize($family);
Shorewall::Tc::initialize($family); Shorewall::Tc::initialize($family);
@@ -71,7 +71,7 @@ sub initialize_package_globals( $$ ) {
# #
# First stage of script generation. # First stage of script generation.
# #
# Copy lib.core and lib.common to the generated script. # Copy prog.header, lib.core and lib.common to the generated script.
# Generate the various user-exit jacket functions. # Generate the various user-exit jacket functions.
# #
# Note: This function is not called when $command eq 'check'. So it must have no side effects other # Note: This function is not called when $command eq 'check'. So it must have no side effects other
@@ -89,7 +89,13 @@ sub generate_script_1( $ ) {
emit "#!$config{SHOREWALL_SHELL}\n#\n# Compiled firewall script generated by Shorewall $globals{VERSION} - $date\n#"; emit "#!$config{SHOREWALL_SHELL}\n#\n# Compiled firewall script generated by Shorewall $globals{VERSION} - $date\n#";
copy $globals{SHAREDIRPL} . '/lib.core', 0; if ( $family == F_IPV4 ) {
copy $globals{SHAREDIRPL} . 'prog.header';
} else {
copy $globals{SHAREDIRPL} . 'prog.header6';
}
copy2 $globals{SHAREDIRPL} . '/lib.core', 0;
copy2 $globals{SHAREDIRPL} . '/lib.common', 0; copy2 $globals{SHAREDIRPL} . '/lib.common', 0;
} }
@@ -148,9 +154,7 @@ sub generate_script_2() {
' #', ' #',
' # Be sure that umask is sane', ' # Be sure that umask is sane',
' #', ' #',
' umask 077' ); ' umask 077',
emit ( '',
' #', ' #',
' # These variables are required by the library functions called in this script', ' # These variables are required by the library functions called in this script',
' #' ' #'
@@ -158,63 +162,61 @@ sub generate_script_2() {
push_indent; push_indent;
if ( $shorewallrc{TEMPDIR} ) {
emit( '',
qq(TMPDIR="$shorewallrc{TEMPDIR}") ,
q(export TMPDIR) );
}
if ( $family == F_IPV4 ) { if ( $family == F_IPV4 ) {
emit( 'g_family=4' ); emit( 'g_family=4' );
if ( $export ) { if ( $export ) {
emit ( qq(g_confdir=$shorewallrc{CONFDIR}/shorewall-lite), emit ( 'SHAREDIR=/usr/share/shorewall-lite',
'CONFDIR=/etc/shorewall-lite',
'g_product="Shorewall Lite"', 'g_product="Shorewall Lite"',
'g_program=shorewall-lite', 'g_program=shorewall-lite',
'g_basedir=/usr/share/shorewall-lite', 'g_basedir=/usr/share/shorewall-lite',
qq(CONFIG_PATH="$shorewallrc{CONFDIR}/shorewall-lite:$shorewallrc{SHAREDIR}/shorewall-lite") ,
); );
} else { } else {
emit ( qq(g_confdir=$shorewallrc{CONFDIR}/shorewall), emit ( 'SHAREDIR=/usr/share/shorewall',
'CONFDIR=/etc/shorewall',
'g_product=Shorewall', 'g_product=Shorewall',
'g_program=shorewall', 'g_program=shorewall',
'g_basedir=/usr/share/shorewall', 'g_basedir=/usr/share/shorewall',
qq(CONFIG_PATH="$config{CONFIG_PATH}") ,
); );
} }
} else { } else {
emit( 'g_family=6' ); emit( 'g_family=6' );
if ( $export ) { if ( $export ) {
emit ( qq(g_confdir=$shorewallrc{CONFDIR}/shorewall6-lite), emit ( 'SHAREDIR=/usr/share/shorewall6-lite',
'CONFDIR=/etc/shorewall6-lite',
'g_product="Shorewall6 Lite"', 'g_product="Shorewall6 Lite"',
'g_program=shorewall6-lite', 'g_program=shorewall6-lite',
'g_basedir=/usr/share/shorewall6', 'g_basedir=/usr/share/shorewall6',
qq(CONFIG_PATH="$shorewallrc{CONFDIR}/shorewall6-lite:$shorewallrc{SHAREDIR}/shorewall6-lite") ,
); );
} else { } else {
emit ( qq(g_confdir=$shorewallrc{CONFDIR}/shorewall6), emit ( 'SHAREDIR=/usr/share/shorewall6',
'CONFDIR=/etc/shorewall6',
'g_product=Shorewall6', 'g_product=Shorewall6',
'g_program=shorewall6', 'g_program=shorewall6',
'g_basedir=/usr/share/shorewall', 'g_basedir=/usr/share/shorewall'
qq(CONFIG_PATH="$config{CONFIG_PATH}") ,
); );
} }
} }
emit( '[ -f ${g_confdir}/vardir ] && . ${g_confdir}/vardir' ); emit( '[ -f ${CONFDIR}/vardir ] && . ${CONFDIR}/vardir' );
if ( $family == F_IPV4 ) { if ( $family == F_IPV4 ) {
if ( $export ) { if ( $export ) {
emit ( '[ -n "${VARDIR:=' . $shorewallrc{VARDIR} . '/shorewall-lite}" ]' ); emit ( 'CONFIG_PATH="/etc/shorewall-lite:/usr/share/shorewall-lite"' ,
'[ -n "${VARDIR:=/var/lib/shorewall-lite}" ]' );
} else { } else {
emit ( '[ -n "${VARDIR:=' . $shorewallrc{VARDIR} . '/shorewall}" ]' ); emit ( qq(CONFIG_PATH="$config{CONFIG_PATH}") ,
'[ -n "${VARDIR:=/var/lib/shorewall}" ]' );
} }
} else { } else {
if ( $export ) { if ( $export ) {
emit ( '[ -n "${VARDIR:=' . $shorewallrc{VARDIR} . '/shorewall6-lite}" ]' ); emit ( 'CONFIG_PATH="/etc/shorewall6-lite:/usr/share/shorewall6-lite"' ,
'[ -n "${VARDIR:=/var/lib/shorewall6-lite}" ]' );
} else { } else {
emit ( '[ -n "${VARDIR:=' . $shorewallrc{VARDIR} . '/shorewall6}" ]' ); emit ( qq(CONFIG_PATH="$config{CONFIG_PATH}") ,
'[ -n "${VARDIR:=/var/lib/shorewall6}" ]' );
} }
} }
@@ -354,7 +356,7 @@ sub generate_script_3($) {
emit 'cat > ${VARDIR}/.modules << EOF'; emit 'cat > ${VARDIR}/.modules << EOF';
open_file $fn; open_file $fn;
emit_unindented $currentline while read_a_line( NORMAL_READ ); emit_unindented $currentline while read_a_line;
emit_unindented 'EOF'; emit_unindented 'EOF';
emit '', 'reload_kernel_modules < ${VARDIR}/.modules'; emit '', 'reload_kernel_modules < ${VARDIR}/.modules';
@@ -425,7 +427,7 @@ sub generate_script_3($) {
emit 'cat > ${VARDIR}/proxyarp << __EOF__'; emit 'cat > ${VARDIR}/proxyarp << __EOF__';
} else { } else {
emit 'cat > ${VARDIR}/proxyndp << __EOF__'; emit 'cat > ${VARDIR}/proxyndp << __EOF__';
} }
dump_proxy_arp; dump_proxy_arp;
emit_unindented '__EOF__'; emit_unindented '__EOF__';
@@ -493,7 +495,7 @@ EOF
" set_state Started $config_dir" , " set_state Started $config_dir" ,
' else' , ' else' ,
' setup_netfilter' ); ' setup_netfilter' );
setup_load_distribution; setup_load_distribution;
emit<<"EOF"; emit<<"EOF";
@@ -545,8 +547,8 @@ EOF
# #
sub compiler { sub compiler {
my ( $scriptfilename, $directory, $verbosity, $timestamp , $debug, $chains , $log , $log_verbosity, $preview, $confess , $update , $annotate , $convert, $config_path, $shorewallrc ) = my ( $scriptfilename, $directory, $verbosity, $timestamp , $debug, $chains , $log , $log_verbosity, $preview, $confess , $update , $annotate , $convert, $config_path ) =
( '', '', -1, '', 0, '', '', -1, 0, 0, 0, 0, , 0 , '' , ''); ( '', '', -1, '', 0, '', '', -1, 0, 0, 0, 0, , 0 , '');
$export = 0; $export = 0;
$test = 0; $test = 0;
@@ -578,13 +580,12 @@ sub compiler {
log => { store => \$log }, log => { store => \$log },
log_verbosity => { store => \$log_verbosity, validate => \&validate_verbosity } , log_verbosity => { store => \$log_verbosity, validate => \&validate_verbosity } ,
test => { store => \$test }, test => { store => \$test },
preview => { store => \$preview, validate=> \&validate_boolean } , preview => { store => \$preview, validate=> \&validate_boolean } ,
confess => { store => \$confess, validate=> \&validate_boolean } , confess => { store => \$confess, validate=> \&validate_boolean } ,
update => { store => \$update, validate=> \&validate_boolean } , update => { store => \$update, validate=> \&validate_boolean } ,
convert => { store => \$convert, validate=> \&validate_boolean } , convert => { store => \$convert, validate=> \&validate_boolean } ,
annotate => { store => \$annotate, validate=> \&validate_boolean } , annotate => { store => \$annotate, validate=> \&validate_boolean } ,
config_path => { store => \$config_path } , config_path => { store => \$config_path } ,
shorewallrc => { store => \$shorewallrc } ,
); );
# #
# P A R A M E T E R P R O C E S S I N G # P A R A M E T E R P R O C E S S I N G
@@ -602,7 +603,7 @@ sub compiler {
# #
# Now that we know the address family (IPv4/IPv6), we can initialize the other modules' globals # Now that we know the address family (IPv4/IPv6), we can initialize the other modules' globals
# #
initialize_package_globals( $update, $shorewallrc ); initialize_package_globals( $update );
set_config_path( $config_path ) if $config_path; set_config_path( $config_path ) if $config_path;
@@ -708,6 +709,10 @@ sub compiler {
# Proxy Arp/Ndp # Proxy Arp/Ndp
# #
setup_proxy_arp; setup_proxy_arp;
#
# Handle MSS settings in the zones file
#
setup_zone_mss;
if ( $scriptfilename || $debug ) { if ( $scriptfilename || $debug ) {
emit 'return 0'; emit 'return 0';
@@ -812,16 +817,16 @@ sub compiler {
optimize_level0; optimize_level0;
if ( ( my $optimize = $config{OPTIMIZE} ) & 0x1E ) { if ( $config{OPTIMIZE} & 0x1E ) {
progress_message2 'Optimizing Ruleset...'; progress_message2 'Optimizing Ruleset...';
# #
# Optimize Policy Chains # Optimize Policy Chains
# #
optimize_policy_chains if ( $optimize & OPTIMIZE_POLICY_MASK2n4 ) == OPTIMIZE_POLICY_MASK; # Level 2 but not 4 optimize_policy_chains if $config{OPTIMIZE} & 2;
# #
# More Optimization # More Optimization
# #
optimize_ruleset if $config{OPTIMIZE} & OPTIMIZE_RULESET_MASK; optimize_ruleset if $config{OPTIMIZE} & 0x1C;
} }
enable_script; enable_script;
@@ -877,16 +882,16 @@ sub compiler {
optimize_level0; optimize_level0;
if ( ( my $optimize = $config{OPTIMIZE} & OPTIMIZE_MASK ) ) { if ( $config{OPTIMIZE} & OPTIMIZE_MASK ) {
progress_message2 'Optimizing Ruleset...'; progress_message2 'Optimizing Ruleset...';
# #
# Optimize Policy Chains # Optimize Policy Chains
# #
optimize_policy_chains if ( $optimize & OPTIMIZE_POLICY_MASK2n4 ) == OPTIMIZE_POLICY_MASK; # Level 2 but not 4 optimize_policy_chains if $config{OPTIMIZE} & OPTIMIZE_POLICY_MASK;
# #
# Ruleset Optimization # Ruleset Optimization
# #
optimize_ruleset if $optimize & OPTIMIZE_RULESET_MASK; optimize_ruleset if $config{OPTIMIZE} & OPTIMIZE_RULESET_MASK;
} }
enable_script if $debug; enable_script if $debug;

File diff suppressed because it is too large Load Diff

View File

@@ -76,7 +76,6 @@ our @EXPORT = qw( ALLIPv4
proto_name proto_name
validate_port validate_port
validate_portpair validate_portpair
validate_portpair1
validate_port_list validate_port_list
validate_icmp validate_icmp
validate_icmp6 validate_icmp6
@@ -293,9 +292,9 @@ sub compare_nets( $$ ) {
@net1 = decompose_net( $_[0] ); @net1 = decompose_net( $_[0] );
@net2 = decompose_net( $_[1] ); @net2 = decompose_net( $_[1] );
$net1[0] eq $net2[0] && $net1[1] == $net2[1]; $net1[0] eq $net2[0] && $net1[1] == $net2[1];
} }
sub allipv4() { sub allipv4() {
@allipv4; @allipv4;
@@ -372,7 +371,6 @@ sub validate_port( $$ ) {
sub validate_portpair( $$ ) { sub validate_portpair( $$ ) {
my ($proto, $portpair) = @_; my ($proto, $portpair) = @_;
my $what;
fatal_error "Invalid port range ($portpair)" if $portpair =~ tr/:/:/ > 1; fatal_error "Invalid port range ($portpair)" if $portpair =~ tr/:/:/ > 1;
@@ -381,57 +379,16 @@ sub validate_portpair( $$ ) {
my @ports = split /:/, $portpair, 2; my @ports = split /:/, $portpair, 2;
my $protonum = resolve_proto( $proto ) || 0; $_ = validate_port( $proto, $_) for ( grep $_, @ports );
$_ = validate_port( $protonum, $_) for grep $_, @ports;
if ( @ports == 2 ) { if ( @ports == 2 ) {
$what = 'port range';
fatal_error "Invalid port range ($portpair)" unless $ports[0] < $ports[1]; fatal_error "Invalid port range ($portpair)" unless $ports[0] < $ports[1];
} else {
$what = 'port';
} }
fatal_error "Using a $what ( $portpair ) requires PROTO TCP, UDP, SCTP or DCCP" unless
defined $protonum && ( $protonum == TCP ||
$protonum == UDP ||
$protonum == SCTP ||
$protonum == DCCP );
join ':', @ports; join ':', @ports;
} }
sub validate_portpair1( $$ ) {
my ($proto, $portpair) = @_;
my $what;
fatal_error "Invalid port range ($portpair)" if $portpair =~ tr/-/-/ > 1;
$portpair = "0$portpair" if substr( $portpair, 0, 1 ) eq ':';
$portpair = "${portpair}65535" if substr( $portpair, -1, 1 ) eq ':';
my @ports = split /-/, $portpair, 2;
my $protonum = resolve_proto( $proto ) || 0;
$_ = validate_port( $protonum, $_) for grep $_, @ports;
if ( @ports == 2 ) {
$what = 'port range';
fatal_error "Invalid port range ($portpair)" unless $ports[0] < $ports[1];
} else {
$what = 'port';
}
fatal_error "Using a $what ( $portpair ) requires PROTO TCP, UDP, SCTP or DCCP" unless
defined $protonum && ( $protonum == TCP ||
$protonum == UDP ||
$protonum == SCTP ||
$protonum == DCCP );
join '-', @ports;
}
sub validate_port_list( $$ ) { sub validate_port_list( $$ ) {
my $result = ''; my $result = '';
my ( $proto, $list ) = @_; my ( $proto, $list ) = @_;

File diff suppressed because it is too large Load Diff

View File

@@ -35,11 +35,7 @@ use strict;
our @ISA = qw(Exporter); our @ISA = qw(Exporter);
our @EXPORT = qw( setup_masq setup_nat setup_netmap add_addresses ); our @EXPORT = qw( setup_masq setup_nat setup_netmap add_addresses );
our %EXPORT_TAGS = ( rules => [ qw ( handle_nat_rule handle_nonat_rule ) ] );
our @EXPORT_OK = (); our @EXPORT_OK = ();
Exporter::export_ok_tags('rules');
our $VERSION = 'MODULEVERSION'; our $VERSION = 'MODULEVERSION';
my @addresses_to_add; my @addresses_to_add;
@@ -58,8 +54,8 @@ sub initialize() {
# #
sub process_one_masq( ) sub process_one_masq( )
{ {
my ($interfacelist, $networks, $addresses, $proto, $ports, $ipsec, $mark, $user, $condition, $origdest ) = my ($interfacelist, $networks, $addresses, $proto, $ports, $ipsec, $mark, $user ) =
split_line1 'masq file', { interface => 0, source => 1, address => 2, proto => 3, port => 4, ipsec => 5, mark => 6, user => 7, switch => 8, origdest => 9 }; split_line1 'masq file', { interface => 0, source => 1, address => 2, proto => 3, port => 4, ipsec => 5, mark => 6, user => 7 };
if ( $interfacelist eq 'COMMENT' ) { if ( $interfacelist eq 'COMMENT' ) {
process_comment; process_comment;
@@ -92,7 +88,7 @@ sub process_one_masq( )
$interfacelist = $1; $interfacelist = $1;
} elsif ( $interfacelist =~ /^([^:]+):([^:]*)$/ ) { } elsif ( $interfacelist =~ /^([^:]+):([^:]*)$/ ) {
my ( $one, $two ) = ( $1, $2 ); my ( $one, $two ) = ( $1, $2 );
if ( $2 =~ /\./ || $2 =~ /^%/ ) { if ( $2 =~ /\./ ) {
$interfacelist = $one; $interfacelist = $one;
$destnets = $two; $destnets = $two;
} }
@@ -121,9 +117,9 @@ sub process_one_masq( )
} }
# #
# Handle Protocol, Ports and Condition # Handle Protocol and Ports
# #
$baserule .= do_proto( $proto, $ports, '' ) . do_condition( $condition ); $baserule .= do_proto $proto, $ports, '';
# #
# Handle Mark # Handle Mark
# #
@@ -199,7 +195,7 @@ sub process_one_masq( )
if ( $conditional = conditional_rule( $chainref, $addr ) ) { if ( $conditional = conditional_rule( $chainref, $addr ) ) {
$addrlist .= '--to-source ' . get_interface_address $1; $addrlist .= '--to-source ' . get_interface_address $1;
} else { } else {
$addrlist .= '--to-source ' . record_runtime_address( '&', $1 ); $addrlist .= '--to-source ' . record_runtime_address $1;
} }
} elsif ( $addr =~ /^.*\..*\..*\./ ) { } elsif ( $addr =~ /^.*\..*\..*\./ ) {
$target = 'SNAT '; $target = 'SNAT ';
@@ -212,9 +208,11 @@ sub process_one_masq( )
$addrlist .= "--to-source $addr "; $addrlist .= "--to-source $addr ";
$exceptionrule = do_proto( $proto, '', '' ) if $addr =~ /:/; $exceptionrule = do_proto( $proto, '', '' ) if $addr =~ /:/;
} else { } else {
my $ports = $addr; my $ports = $addr;
$ports =~ s/^://; $ports =~ s/^://;
validate_portpair1( $proto, $ports ); my $portrange = $ports;
$portrange =~ s/-/:/;
validate_portpair( $proto, $portrange );
$addrlist .= "--to-ports $ports "; $addrlist .= "--to-ports $ports ";
$exceptionrule = do_proto( $proto, '', '' ); $exceptionrule = do_proto( $proto, '', '' );
} }
@@ -237,7 +235,7 @@ sub process_one_masq( )
$baserule . $rule , $baserule . $rule ,
$networks , $networks ,
$destnets , $destnets ,
$origdest , '' ,
$target , $target ,
'' , '' ,
'' , '' ,
@@ -280,7 +278,7 @@ sub setup_masq()
first_entry( sub { progress_message2 "$doing $fn..."; require_capability 'NAT_ENABLED' , 'a non-empty masq file' , 's'; } ); first_entry( sub { progress_message2 "$doing $fn..."; require_capability 'NAT_ENABLED' , 'a non-empty masq file' , 's'; } );
process_one_masq while read_a_line( NORMAL_READ ); process_one_masq while read_a_line;
clear_comment; clear_comment;
} }
@@ -377,7 +375,7 @@ sub setup_nat() {
first_entry( sub { progress_message2 "$doing $fn..."; require_capability 'NAT_ENABLED' , 'a non-empty nat file' , 's'; } ); first_entry( sub { progress_message2 "$doing $fn..."; require_capability 'NAT_ENABLED' , 'a non-empty nat file' , 's'; } );
while ( read_a_line( NORMAL_READ ) ) { while ( read_a_line ) {
my ( $external, $interfacelist, $internal, $allints, $localnat ) = split_line1 'nat file', { external => 0, interface => 1, internal => 2, allints => 3, local => 4 }; my ( $external, $interfacelist, $internal, $allints, $localnat ) = split_line1 'nat file', { external => 0, interface => 1, internal => 2, allints => 3, local => 4 };
@@ -413,7 +411,7 @@ sub setup_netmap() {
first_entry "$doing $fn..."; first_entry "$doing $fn...";
while ( read_a_line( NORMAL_READ ) ) { while ( read_a_line ) {
my ( $type, $net1, $interfacelist, $net2, $net3, $proto, $dport, $sport ) = split_line 'netmap file', { type => 0, net1 => 1, interface => 2, net2 => 3, net3 => 4, proto => 5, dport => 6, sport => 7 }; my ( $type, $net1, $interfacelist, $net2, $net3, $proto, $dport, $sport ) = split_line 'netmap file', { type => 0, net1 => 1, interface => 2, net2 => 3, net3 => 4, proto => 5, dport => 6, sport => 7 };
@@ -430,7 +428,7 @@ sub setup_netmap() {
unless ( $type =~ /:/ ) { unless ( $type =~ /:/ ) {
my @rulein; my @rulein;
my @ruleout; my @ruleout;
validate_net $net1, 0; validate_net $net1, 0;
validate_net $net2, 0; validate_net $net2, 0;
@@ -443,7 +441,7 @@ sub setup_netmap() {
require_capability 'NAT_ENABLED', 'Stateful NAT Entries', ''; require_capability 'NAT_ENABLED', 'Stateful NAT Entries', '';
if ( $type eq 'DNAT' ) { if ( $type eq 'DNAT' ) {
dest_iexclusion( ensure_chain( 'nat' , input_chain $interface ) , dest_iexclusion( ensure_chain( 'nat' , input_chain $interface ) ,
j => 'NETMAP' , j => 'NETMAP' ,
"--to $net2", "--to $net2",
$net1 , $net1 ,
@@ -469,10 +467,10 @@ sub setup_netmap() {
validate_net $net2, 0; validate_net $net2, 0;
unless ( $interfaceref->{root} ) { unless ( $interfaceref->{root} ) {
@match = imatch_dest_dev( $interface ); @match = imatch_dest_dev( $interface );
$interface = $interfaceref->{name}; $interface = $interfaceref->{name};
} }
if ( $chain eq 'P' ) { if ( $chain eq 'P' ) {
$chain = prerouting_chain $interface; $chain = prerouting_chain $interface;
@match = imatch_source_dev( $iface ) unless $iface eq $interface; @match = imatch_source_dev( $iface ) unless $iface eq $interface;
@@ -485,7 +483,7 @@ sub setup_netmap() {
my $chainref = ensure_chain( $table, $chain ); my $chainref = ensure_chain( $table, $chain );
if ( $target eq 'DNAT' ) { if ( $target eq 'DNAT' ) {
dest_iexclusion( $chainref , dest_iexclusion( $chainref ,
j => 'RAWDNAT' , j => 'RAWDNAT' ,
@@ -508,7 +506,7 @@ sub setup_netmap() {
fatal_error 'TYPE must be specified' if $type eq '-'; fatal_error 'TYPE must be specified' if $type eq '-';
fatal_error "Invalid TYPE ($type)"; fatal_error "Invalid TYPE ($type)";
} }
progress_message " Network $net1 on $iface mapped to $net2 ($type)"; progress_message " Network $net1 on $iface mapped to $net2 ($type)";
} }
} }
@@ -518,227 +516,6 @@ sub setup_netmap() {
} }
#
# Called from process_rule1 to add a rule to the NAT table
#
sub handle_nat_rule( $$$$$$$$$$$$ ) {
my ( $dest, # <server>[:port]
$proto, # Protocol
$ports, # Destination port list
$origdest, # Original Destination
$action_target, # If the target is an action, the name of the log action chain to jump to
$action, # The Action
$sourceref, # Reference to the Source Zone's table entry in the Zones module
$action_chain, # Name of the action chain if the rule is in an action
$rule, # Matches
$source, # Source Address
$loglevel, # [<level>[:<tag>]]
$log_action, # Action name to include in the log message
) = @_;
my ( $server, $serverport , $origdstports ) = ( '', '', '' );
my $randomize = $dest =~ s/:random$// ? ' --random' : '';
#
# Isolate server port
#
if ( $dest =~ /^(.*)(?::(.+))$/ ) {
#
# Server IP and Port
#
$server = $1; # May be empty
$serverport = $2; # Not Empty due to RE
$origdstports = validate_port( $proto, $ports ) if $ports && $ports ne '-' && port_count( $ports ) == 1;
if ( $serverport =~ /^(\d+)-(\d+)$/ ) {
#
# Server Port Range
#
fatal_error "Invalid port range ($serverport)" unless $1 < $2;
my @ports = ( $1, $2 );
$_ = validate_port( proto_name( $proto ), $_) for ( @ports );
( $ports = $serverport ) =~ tr/-/:/;
} else {
$serverport = $ports = validate_port( proto_name( $proto ), $serverport );
}
} elsif ( $dest ne ':' ) {
#
# Simple server IP address (may be empty or "-")
#
$server = $dest;
}
#
# Generate the target
#
my $target = '';
if ( $action eq 'REDIRECT' ) {
fatal_error "A server IP address ($server) may not be specified in a REDIRECT rule" if $server;
$target = 'REDIRECT';
$target .= " --to-port $serverport" if $serverport;
if ( $origdest eq '' || $origdest eq '-' ) {
$origdest = ALLIP;
} elsif ( $origdest eq 'detect' ) {
fatal_error 'ORIGINAL DEST "detect" is invalid in an action' if $action_chain;
if ( $config{DETECT_DNAT_IPADDRS} ) {
my $interfacesref = $sourceref->{interfaces};
my @interfaces = keys %$interfacesref;
$origdest = @interfaces ? "detect:@interfaces" : ALLIP;
} else {
$origdest = ALLIP;
}
}
} elsif ( $action_target ) {
fatal_error "A server port ($serverport) is not allowed in $action rule" if $serverport;
$target = $action_target;
} else {
if ( $server eq '' ) {
fatal_error "A server and/or port must be specified in the DEST column in $action rules" unless $serverport;
} elsif ( $server =~ /^(.+)-(.+)$/ ) {
validate_range( $1, $2 );
} else {
unless ( $server eq ALLIP ) {
my @servers = validate_address $server, 1;
$server = join ',', @servers;
}
}
if ( $action eq 'DNAT' ) {
$target = $action;
if ( $server ) {
$serverport = ":$serverport" if $serverport;
for my $serv ( split /,/, $server ) {
$target .= " --to-destination ${serv}${serverport}";
}
} else {
$target .= " --to-destination :$serverport";
}
}
unless ( $origdest && $origdest ne '-' && $origdest ne 'detect' ) {
if ( ! $action_chain && $config{DETECT_DNAT_IPADDRS} ) {
my $interfacesref = $sourceref->{interfaces};
my @interfaces = keys %$interfacesref;
$origdest = @interfaces ? "detect:@interfaces" : ALLIP;
} else {
$origdest = ALLIP;
}
}
}
$target .= $randomize;
#
# And generate the nat table rule(s)
#
my $firewallsource = $sourceref && ( $sourceref->{type} & ( FIREWALL | VSERVER ) );
expand_rule ( ensure_chain ('nat' ,
( $action_chain ? $action_chain :
$firewallsource ? 'OUTPUT' :
dnat_chain $sourceref->{name} ) ) ,
$firewallsource ? OUTPUT_RESTRICT : PREROUTE_RESTRICT ,
$rule ,
$source ,
$origdest ,
'' ,
$target ,
$loglevel ,
$log_action ,
$serverport ? do_proto( $proto, '', '' ) : '',
);
( $ports, $origdstports, $server );
}
#
# Called from process_rule1() to handle the nat table part of the NONAT and ACCEPT+ actions
#
sub handle_nonat_rule( $$$$$$$$$$ ) {
my ( $action, $source, $dest, $origdest, $sourceref, $inaction, $chain, $loglevel, $log_action, $rule ) = @_;
my $sourcezone = $sourceref->{name};
#
# NONAT or ACCEPT+ may not specify a destination interface
#
fatal_error "Invalid DEST ($dest) in $action rule" if $dest =~ /:/;
$origdest = '' unless $origdest and $origdest ne '-';
if ( $origdest eq 'detect' ) {
my $interfacesref = $sourceref->{interfaces};
my $interfaces = [ ( keys %$interfacesref ) ];
$origdest = $interfaces ? "detect:@$interfaces" : ALLIP;
}
my $tgt = 'RETURN';
my $nonat_chain;
my $chn;
if ( $inaction ) {
$nonat_chain = ensure_chain( 'nat', $chain );
} elsif ( $sourceref->{type} == FIREWALL ) {
$nonat_chain = $nat_table->{OUTPUT};
} else {
$nonat_chain = ensure_chain( 'nat', dnat_chain( $sourcezone ) );
my @interfaces = keys %{zone_interfaces $sourcezone};
for ( @interfaces ) {
my $ichain = input_chain $_;
if ( $nat_table->{$ichain} ) {
#
# Static NAT is defined on this interface
#
$chn = new_chain( 'nat', newnonatchain ) unless $chn;
add_ijump $chn, j => $nat_table->{$ichain}, @interfaces > 1 ? imatch_source_dev( $_ ) : ();
}
}
if ( $chn ) {
#
# Call expand_rule() to correctly handle logging. Because
# the 'logname' argument is passed, expand_rule() will
# not create a separate logging chain but will rather emit
# any logging rule in-line.
#
expand_rule( $chn,
PREROUTE_RESTRICT,
'', # Rule
'', # Source
'', # Dest
'', # Original dest
'ACCEPT',
$loglevel,
$log_action,
'',
dnat_chain( $sourcezone ) );
$loglevel = '';
$tgt = $chn->{name};
} else {
$tgt = 'ACCEPT';
}
}
set_optflags( $nonat_chain, DONT_MOVE | DONT_OPTIMIZE ) if $tgt eq 'RETURN';
expand_rule( $nonat_chain ,
PREROUTE_RESTRICT ,
$rule ,
$source ,
$dest ,
$origdest ,
$tgt,
$loglevel ,
$log_action ,
'',
);
}
sub add_addresses () { sub add_addresses () {
if ( @addresses_to_add ) { if ( @addresses_to_add ) {
my @addrs = @addresses_to_add; my @addrs = @addresses_to_add;

View File

@@ -286,7 +286,7 @@ sub setup_interface_proc( $ ) {
if ( interface_has_option( $interface, 'arp_filter' , $value ) ) { if ( interface_has_option( $interface, 'arp_filter' , $value ) ) {
push @emitted, "echo $value > /proc/sys/net/ipv4/conf/$physical/arp_filter"; push @emitted, "echo $value > /proc/sys/net/ipv4/conf/$physical/arp_filter";
} }
if ( interface_has_option( $interface, 'arp_ignore' , $value ) ) { if ( interface_has_option( $interface, 'arp_ignore' , $value ) ) {
push @emitted, "echo $value > /proc/sys/net/ipv4/conf/$physical/arp_ignore"; push @emitted, "echo $value > /proc/sys/net/ipv4/conf/$physical/arp_ignore";
} }
@@ -315,6 +315,6 @@ sub setup_interface_proc( $ ) {
emit "fi\n"; emit "fi\n";
} }
} }
1; 1;

View File

@@ -39,9 +39,7 @@ our @EXPORT = qw( process_providers
@routemarked_interfaces @routemarked_interfaces
handle_stickiness handle_stickiness
handle_optional_interfaces handle_optional_interfaces
compile_updown
setup_load_distribution setup_load_distribution
have_providers
); );
our @EXPORT_OK = qw( initialize lookup_provider ); our @EXPORT_OK = qw( initialize lookup_provider );
our $VERSION = '4.4_24'; our $VERSION = '4.4_24';
@@ -62,11 +60,9 @@ my @load_interfaces;
my $balancing; my $balancing;
my $fallback; my $fallback;
my $metrics;
my $first_default_route; my $first_default_route;
my $first_fallback_route; my $first_fallback_route;
my $maxload; my $maxload;
my $tproxies;
my %providers; my %providers;
@@ -99,11 +95,9 @@ sub initialize( $ ) {
@load_interfaces = (); @load_interfaces = ();
$balancing = 0; $balancing = 0;
$fallback = 0; $fallback = 0;
$metrics = 0;
$first_default_route = 1; $first_default_route = 1;
$first_fallback_route = 1; $first_fallback_route = 1;
$maxload = 0; $maxload = 0;
$tproxies = 0;
%providers = ( local => { number => LOCAL_TABLE , mark => 0 , optional => 0 ,routes => [], rules => [] } , %providers = ( local => { number => LOCAL_TABLE , mark => 0 , optional => 0 ,routes => [], rules => [] } ,
main => { number => MAIN_TABLE , mark => 0 , optional => 0 ,routes => [], rules => [] } , main => { number => MAIN_TABLE , mark => 0 , optional => 0 ,routes => [], rules => [] } ,
@@ -166,8 +160,10 @@ sub setup_route_marking() {
my $chainref2 = new_chain( 'mangle', load_chain( $physical ) ); my $chainref2 = new_chain( 'mangle', load_chain( $physical ) );
set_optflags( $chainref2, DONT_OPTIMIZE | DONT_MOVE | DONT_DELETE ); dont_optimize $chainref2;
dont_move $chainref2;
dont_delete $chainref2;
add_ijump ( $chainref1, add_ijump ( $chainref1,
j => $chainref2 , j => $chainref2 ,
mark => "--mark 0/$mask" ); mark => "--mark 0/$mask" );
@@ -177,7 +173,7 @@ sub setup_route_marking() {
sub copy_table( $$$ ) { sub copy_table( $$$ ) {
my ( $duplicate, $number, $realm ) = @_; my ( $duplicate, $number, $realm ) = @_;
my $filter = $family == F_IPV6 ? q(fgrep -v ' cache ' | sed 's/ via :: / /' | ) : ''; my $filter = $family == F_IPV6 ? q(fgrep -v ' cache ' | sed 's/ via :: / /' | ) : '';
emit ''; emit '';
@@ -192,7 +188,7 @@ sub copy_table( $$$ ) {
' default)', ' default)',
' ;;', ' ;;',
' *)' ); ' *)' );
if ( $family == F_IPV4 ) { if ( $family == F_IPV4 ) {
emit ( ' case $net in', emit ( ' case $net in',
' 255.255.255.255*)', ' 255.255.255.255*)',
@@ -224,7 +220,7 @@ sub copy_and_edit_table( $$$$ ) {
# Shell and iptables use a different wildcard character # Shell and iptables use a different wildcard character
# #
$copy =~ s/\+/*/g; $copy =~ s/\+/*/g;
emit ''; emit '';
if ( $realm ) { if ( $realm ) {
@@ -250,7 +246,7 @@ sub copy_and_edit_table( $$$$ ) {
); );
} else { } else {
emit ( " run_ip route add table $number \$net \$route $realm" ); emit ( " run_ip route add table $number \$net \$route $realm" );
} }
emit ( ' ;;', emit ( ' ;;',
' esac', ' esac',
@@ -402,8 +398,8 @@ sub process_a_provider() {
$gateway = ''; $gateway = '';
} }
my ( $loose, $track, $balance , $default, $default_balance, $optional, $mtu, $tproxy , $local, $load ) = my ( $loose, $track, $balance , $default, $default_balance, $optional, $mtu, $local , $load ) =
(0, $config{TRACK_PROVIDERS}, 0 , 0, $config{USE_DEFAULT_RT} ? 1 : 0, interface_is_optional( $interface ), '' , 0 , 0, 0 ); (0, $config{TRACK_PROVIDERS}, 0 , 0, $config{USE_DEFAULT_RT} ? 1 : 0, interface_is_optional( $interface ), '' , 0 , 0 );
unless ( $options eq '-' ) { unless ( $options eq '-' ) {
for my $option ( split_list $options, 'option' ) { for my $option ( split_list $options, 'option' ) {
@@ -441,14 +437,9 @@ sub process_a_provider() {
$default = -1; $default = -1;
$default_balance = 0; $default_balance = 0;
} elsif ( $option eq 'local' ) { } elsif ( $option eq 'local' ) {
warning_message q(The 'local' provider option is deprecated in favor of 'tproxy'); $local = 1;
$local = $tproxy = 1; $track = 0 if $config{TRACK_PROVIDERS};
$track = 0 if $config{TRACK_PROVIDERS}; $default_balance = 0 if $config{USE_DEFAULT_RT};
$default_balance = 0 if $config{USE_DEFAULT_RT};
} elsif ( $option eq 'tproxy' ) {
$tproxy = 1;
$track = 0 if $config{TRACK_PROVIDERS};
$default_balance = 0 if $config{USE_DEFAULT_RT};
} elsif ( $option =~ /^load=(0?\.\d{1,8})/ ) { } elsif ( $option =~ /^load=(0?\.\d{1,8})/ ) {
$load = $1; $load = $1;
require_capability 'STATISTIC_MATCH', "load=$load", 's'; require_capability 'STATISTIC_MATCH', "load=$load", 's';
@@ -467,16 +458,10 @@ sub process_a_provider() {
} }
if ( $local ) { if ( $local ) {
fatal_error "GATEWAY not valid with 'local' provider" unless $gatewaycase eq 'none'; fatal_error "GATEWAY not valid with 'local' provider" unless $gatewaycase eq 'none';
fatal_error "'track' not valid with 'local'" if $track; fatal_error "'track' not valid with 'local'" if $track;
fatal_error "DUPLICATE not valid with 'local'" if $duplicate ne '-'; fatal_error "DUPLICATE not valid with 'local'" if $duplicate ne '-';
} elsif ( $tproxy ) { fatal_error "MARK required with 'local'" unless $mark;
fatal_error "Only one 'tproxy' provider is allowed" if $tproxies++;
fatal_error "GATEWAY not valid with 'tproxy' provider" unless $gatewaycase eq 'none';
fatal_error "'track' not valid with 'tproxy'" if $track;
fatal_error "DUPLICATE not valid with 'tproxy'" if $duplicate ne '-';
fatal_error "MARK not allowed with 'tproxy'" if $mark ne '-';
$mark = $globals{TPROXY_MARK};
} }
my $val = 0; my $val = 0;
@@ -488,29 +473,24 @@ sub process_a_provider() {
require_capability( 'MANGLE_ENABLED' , 'Provider marks' , '' ); require_capability( 'MANGLE_ENABLED' , 'Provider marks' , '' );
if ( $tproxy && ! $local ) { $val = numeric_value $mark;
$val = $globals{TPROXY_MARK};
$pref = 1;
} else {
$val = numeric_value $mark;
fatal_error "Invalid Mark Value ($mark)" unless defined $val && $val; fatal_error "Invalid Mark Value ($mark)" unless defined $val && $val;
verify_mark $mark; verify_mark $mark;
fatal_error "Invalid Mark Value ($mark)" unless ( $val & $globals{PROVIDER_MASK} ) == $val; fatal_error "Invalid Mark Value ($mark)" unless ( $val & $globals{PROVIDER_MASK} ) == $val;
fatal_error "Provider MARK may not be specified when PROVIDER_BITS=0" unless $config{PROVIDER_BITS}; fatal_error "Provider MARK may not be specified when PROVIDER_BITS=0" unless $config{PROVIDER_BITS};
for my $providerref ( values %providers ) { for my $providerref ( values %providers ) {
fatal_error "Duplicate mark value ($mark)" if numeric_value( $providerref->{mark} ) == $val; fatal_error "Duplicate mark value ($mark)" if numeric_value( $providerref->{mark} ) == $val;
}
$lastmark = $val;
$pref = 10000 + $number - 1;
} }
$pref = 10000 + $number - 1;
$lastmark = $val;
} }
unless ( $loose ) { unless ( $loose ) {
@@ -549,7 +529,6 @@ sub process_a_provider() {
duplicate => $duplicate , duplicate => $duplicate ,
address => $address , address => $address ,
local => $local , local => $local ,
tproxy => $tproxy ,
load => $load , load => $load ,
rules => [] , rules => [] ,
routes => [] , routes => [] ,
@@ -580,9 +559,9 @@ sub process_a_provider() {
# Generate the start_provider_...() function for the passed provider # Generate the start_provider_...() function for the passed provider
# #
sub add_a_provider( $$ ) { sub add_a_provider( $$ ) {
my ( $providerref, $tcdevices ) = @_; my ( $providerref, $tcdevices ) = @_;
my $table = $providerref->{provider}; my $table = $providerref->{provider};
my $number = $providerref->{number}; my $number = $providerref->{number};
my $mark = $providerref->{rawmark}; my $mark = $providerref->{rawmark};
@@ -602,7 +581,6 @@ sub add_a_provider( $$ ) {
my $duplicate = $providerref->{duplicate}; my $duplicate = $providerref->{duplicate};
my $address = $providerref->{address}; my $address = $providerref->{address};
my $local = $providerref->{local}; my $local = $providerref->{local};
my $tproxy = $providerref->{tproxy};
my $load = $providerref->{load}; my $load = $providerref->{load};
my $dev = chain_base $physical; my $dev = chain_base $physical;
@@ -624,7 +602,7 @@ sub add_a_provider( $$ ) {
$provider_interfaces{$interface} = $table; $provider_interfaces{$interface} = $table;
if ( $gatewaycase eq 'none' ) { if ( $gatewaycase eq 'none' ) {
if ( $tproxy ) { if ( $local ) {
emit 'run_ip route add local ' . ALLIP . " dev $physical table $number"; emit 'run_ip route add local ' . ALLIP . " dev $physical table $number";
} else { } else {
emit "run_ip route add default dev $physical table $number"; emit "run_ip route add default dev $physical table $number";
@@ -632,18 +610,16 @@ sub add_a_provider( $$ ) {
} }
} }
emit( "echo $load > \${VARDIR}/${physical}_load", emit( qq(echo $load > \${VARDIR}/${physical}_load) ) if $load;
'echo ' . in_hex( $mark ) . '/' . in_hex( $globals{PROVIDER_MASK} ) . " > \${VARDIR}/${physical}_mark" ) if $load;
emit( '', emit( '',
"cat <<EOF >> \${VARDIR}/undo_${table}_routing" ); "cat <<EOF >> \${VARDIR}/undo_${table}_routing" );
emit_unindented 'case \$COMMAND in'; emit_unindented 'case \$COMMAND in';
emit_unindented ' enable|disable)'; emit_unindented ' enable|disable)';
emit_unindented ' ;;'; emit_unindented ' ;;';
emit_unindented ' *)'; emit_unindented ' *)';
emit_unindented " rm -f \${VARDIR}/${physical}_load" if $load; emit_unindented " rm -f \${VARDIR}/${physical}_load" if $load;
emit_unindented " rm -f \${VARDIR}/${physical}_mark" if $load;
emit_unindented <<"CEOF", 1; emit_unindented <<"CEOF", 1;
rm -f \${VARDIR}/${physical}.status rm -f \${VARDIR}/${physical}.status
;; ;;
@@ -656,13 +632,12 @@ CEOF
setup_interface_proc( $interface ); setup_interface_proc( $interface );
if ( $mark ne '-' ) { if ( $mark ne '-' ) {
my $hexmark = in_hex( $mark ); my $mask = have_capability 'FWMARK_RT_MASK' ? '/' . in_hex $globals{PROVIDER_MASK} : '';
my $mask = have_capability 'FWMARK_RT_MASK' ? '/' . in_hex( $globals{ $tproxy && ! $local ? 'TPROXY_MARK' : 'PROVIDER_MASK' } ) : '';
emit ( "qt \$IP -$family rule del fwmark ${hexmark}${mask}" ) if $config{DELETE_THEN_ADD}; emit ( "qt \$IP -$family rule del fwmark ${mark}${mask}" ) if $config{DELETE_THEN_ADD};
emit ( "run_ip rule add fwmark ${hexmark}${mask} pref $pref table $number", emit ( "run_ip rule add fwmark ${mark}${mask} pref $pref table $number",
"echo \"qt \$IP -$family rule del fwmark ${hexmark}${mask}\" >> \${VARDIR}/undo_${table}_routing" "echo \"qt \$IP -$family rule del fwmark ${mark}${mask}\" >> \${VARDIR}/undo_${table}_routing"
); );
} }
@@ -702,20 +677,19 @@ CEOF
emit ''; emit '';
if ( $gateway ) { if ( $gateway ) {
if ( $family == F_IPV4 ) { if ( $family == F_IPV4 ) {
emit qq(run_ip route replace $gateway/32 dev $physical table ) . DEFAULT_TABLE; emit qq(run_ip route replace $gateway dev $physical table ) . DEFAULT_TABLE;
emit qq(run_ip route replace default via $gateway src $address dev $physical table ) . DEFAULT_TABLE . qq( metric $number); emit qq(run_ip route replace default via $gateway src $address dev $physical table ) . DEFAULT_TABLE . qq( metric $number);
} else { } else {
emit qq(qt \$IP -6 route del default via $gateway src $address dev $physical table ) . DEFAULT_TABLE . qq( metric $number); emit qq(qt \$IP -6 route del default via $gateway src $address dev $physical table ) . DEFAULT_TABLE . qq( metric $number);
emit qq(run_ip route add default via $gateway src $address dev $physical table ) . DEFAULT_TABLE . qq( metric $number); emit qq(run_ip route add default via $gateway src $address dev $physical table ) . DEFAULT_TABLE . qq( metric $number);
} }
emit qq(echo "qt \$IP -$family route del default via $gateway table ) . DEFAULT_TABLE . qq(" >> \${VARDIR}/undo_${table}_routing); emit qq(echo "qt \$IP -$family route del default via $gateway table ) . DEFAULT_TABLE . qq(" >> \${VARDIR}/undo_${table}_routing);
emit qq(echo "qt \$IP -4 route del $gateway/32 dev $physical table ) . DEFAULT_TABLE . qq(" >> \${VARDIR}/undo_${table}_routing) if $family == F_IPV4;
} else { } else {
emit qq(run_ip route add default table ) . DEFAULT_TABLE . qq( dev $physical metric $number); emit qq(run_ip route add default table ) . DEFAULT_TABLE . qq( dev $physical metric $number);
emit qq(echo "qt \$IP -$family route del default dev $physical table ) . DEFAULT_TABLE . qq(" >> \${VARDIR}/undo_${table}_routing); emit qq(echo "qt \$IP -$family route del default dev $physical table ) . DEFAULT_TABLE . qq(" >> \${VARDIR}/undo_${table}_routing);
} }
$metrics = 1; $fallback = 1;
} }
emit( qq(\n) , emit( qq(\n) ,
@@ -723,7 +697,7 @@ CEOF
qq( qt \$IP -6 rule add from all table ) . DEFAULT_TABLE . qq( prio 32767\n) , qq( qt \$IP -6 rule add from all table ) . DEFAULT_TABLE . qq( prio 32767\n) ,
qq(fi) ) if $family == F_IPV6; qq(fi) ) if $family == F_IPV6;
unless ( $tproxy ) { unless ( $local ) {
emit ''; emit '';
if ( $loose ) { if ( $loose ) {
@@ -752,19 +726,19 @@ CEOF
emit ''; emit '';
emit $_ for @{$providers{$table}->{rules}}; emit $_ for @{$providers{$table}->{rules}};
} }
if ( @{$providerref->{routes}} ) { if ( @{$providerref->{routes}} ) {
emit ''; emit '';
emit $_ for @{$providers{$table}->{routes}}; emit $_ for @{$providers{$table}->{routes}};
} }
emit( '' ); emit( '' );
my ( $tbl, $weight ); my ( $tbl, $weight );
emit( qq(echo 0 > \${VARDIR}/${physical}.status) ); emit( qq(echo 0 > \${VARDIR}/${physical}.status) );
if ( $optional ) { if ( $optional ) {
emit( '', emit( '',
'if [ $COMMAND = enable ]; then' ); 'if [ $COMMAND = enable ]; then' );
@@ -787,7 +761,7 @@ CEOF
if ( $gateway ) { if ( $gateway ) {
emit qq(add_gateway "via $gateway dev $physical $realm" ) . $tbl; emit qq(add_gateway "via $gateway dev $physical $realm" ) . $tbl;
} else { } else {
emit qq(add_gateway "dev $physical $realm" ) . $tbl; emit qq(add_gateway "nexthop dev $physical $realm" ) . $tbl;
} }
} }
} else { } else {
@@ -803,7 +777,7 @@ CEOF
emit ( qq(progress_message2 " Provider $table ($number) Started") ); emit ( qq(progress_message2 " Provider $table ($number) Started") );
pop_indent; pop_indent;
emit( 'else' ); emit( 'else' );
emit( qq( echo $weight > \${VARDIR}/${physical}_weight) , emit( qq( echo $weight > \${VARDIR}/${physical}_weight) ,
qq( progress_message " Provider $table ($number) Started"), qq( progress_message " Provider $table ($number) Started"),
@@ -813,18 +787,18 @@ CEOF
emit( qq(echo 0 > \${VARDIR}/${physical}.status) ); emit( qq(echo 0 > \${VARDIR}/${physical}.status) );
emit( qq(progress_message "Provider $table ($number) Started") ); emit( qq(progress_message "Provider $table ($number) Started") );
} }
pop_indent; pop_indent;
emit 'else'; emit 'else';
push_indent; push_indent;
emit( qq(echo 1 > \${VARDIR}/${physical}.status) ); emit( qq(echo 1 > \${VARDIR}/${physical}.status) );
if ( $optional ) { if ( $optional ) {
if ( $shared ) { if ( $shared ) {
emit ( "error_message \"WARNING: Gateway $gateway is not reachable -- Provider $table ($number) not Started\"" ); emit ( "error_message \"WARNING: Gateway $gateway is not reachable -- Provider $table ($number) not Started\"" );
} else { } else {
emit ( "error_message \"WARNING: Interface $physical is not usable -- Provider $table ($number) not Started\"" ); emit ( "error_message \"WARNING: Interface $physical is not usable -- Provider $table ($number) not Started\"" );
} }
@@ -867,7 +841,7 @@ CEOF
if ( $gateway ) { if ( $gateway ) {
$via = "via $gateway dev $physical"; $via = "via $gateway dev $physical";
} else { } else {
$via = "dev $physical"; $via = "dev $physical";
} }
@@ -884,13 +858,12 @@ CEOF
"distribute_load $maxload @load_interfaces" ) if $load; "distribute_load $maxload @load_interfaces" ) if $load;
unless ( $shared ) { unless ( $shared ) {
emit( '', emit( '',
"qt \$TC qdisc del dev $physical root", "qt \$TC qdisc del dev $physical root",
"qt \$TC qdisc del dev $physical ingress\n" ) if $tcdevices->{$interface}; "qt \$TC qdisc del dev $physical ingress\n" ) if $tcdevices->{$interface};
} }
emit( "echo 1 > \${VARDIR}/${physical}.status", emit( "progress_message2 \" Provider $table ($number) stopped\"" );
"progress_message2 \" Provider $table ($number) stopped\"" );
pop_indent; pop_indent;
@@ -945,7 +918,7 @@ sub add_an_rtrule( ) {
if ( $source eq '-' ) { if ( $source eq '-' ) {
$source = 'from ' . ALLIP; $source = 'from ' . ALLIP;
} elsif ( $source =~ s/^&// ) { } elsif ( $source =~ s/^&// ) {
$source = 'from ' . record_runtime_address '&', $source; $source = 'from ' . record_runtime_address $source;
} elsif ( $family == F_IPV4 ) { } elsif ( $family == F_IPV4 ) {
if ( $source =~ /:/ ) { if ( $source =~ /:/ ) {
( my $interface, $source , my $remainder ) = split( /:/, $source, 3 ); ( my $interface, $source , my $remainder ) = split( /:/, $source, 3 );
@@ -957,7 +930,7 @@ sub add_an_rtrule( ) {
validate_net ( $source, 0 ); validate_net ( $source, 0 );
$source = "from $source"; $source = "from $source";
} else { } else {
$source = 'iif ' . physical_name $source; $source = "iif $source";
} }
} elsif ( $source =~ /^(.+?):<(.+)>\s*$/ || $source =~ /^(.+?):\[(.+)\]\s*$/ ) { } elsif ( $source =~ /^(.+?):<(.+)>\s*$/ || $source =~ /^(.+?):\[(.+)\]\s*$/ ) {
my ($interface, $source ) = ($1, $2); my ($interface, $source ) = ($1, $2);
@@ -968,7 +941,7 @@ sub add_an_rtrule( ) {
validate_net ( $source, 0 ); validate_net ( $source, 0 );
$source = "from $source"; $source = "from $source";
} else { } else {
$source = 'iif ' . physical_name $source; $source = "iif $source";
} }
my $mark = ''; my $mark = '';
@@ -1030,14 +1003,14 @@ sub add_a_route( ) {
my $routes = $providerref->{routes}; my $routes = $providerref->{routes};
fatal_error "You may not add routes to the $provider table" if $number == LOCAL_TABLE || $number == UNSPEC_TABLE; fatal_error "You may not add routes to the $provider table" if $number == LOCAL_TABLE || $number == UNSPEC_TABLE;
if ( $gateway ne '-' ) { if ( $gateway ne '-' ) {
if ( $device ne '-' ) { if ( $device ne '-' ) {
push @$routes, qq(run_ip route add $dest via $gateway dev $physical table $number); push @$routes, qq(run_ip route add $dest via $gateway dev $physical table $number);
emit qq(echo "qt \$IP -$family route del $dest via $gateway dev $physical table $number" >> \${VARDIR}/undo_${provider}_routing) if $number >= DEFAULT_TABLE; emit qq(echo "qt \$IP -$family route del $dest via $gateway dev $physical table $number" >> \${VARDIR}/undo_${provider}_routing) if $number >= DEFAULT_TABLE;
} else { } else {
push @$routes, qq(run_ip route add $dest via $gateway table $number); push @$routes, qq(run_ip route add $dest via $gateway table $number);
emit qq(echo "\$IP -$family route del $dest via $gateway table $number" >> \${VARDIR}/undo_${provider}_routing) if $number >= DEFAULT_TABLE; emit qq(echo "\$IP -$family route del $dest via $gateway table $number" >> \${VARDIR}/undo_${provider}_routing) if $number >= DEFAULT_TABLE;
} }
} else { } else {
fatal_error "You must specify a device for this route" unless $physical; fatal_error "You must specify a device for this route" unless $physical;
@@ -1050,11 +1023,11 @@ sub add_a_route( ) {
sub setup_null_routing() { sub setup_null_routing() {
save_progress_message "Null Routing the RFC 1918 subnets"; save_progress_message "Null Routing the RFC 1918 subnets";
emit "> \${VARDIR}/undo_rfc1918_routing\n"; emit "> \${VARDIR}undo_rfc1918_routing\n";
for ( rfc1918_networks ) { for ( rfc1918_networks ) {
emit( qq(if ! \$IP -4 route ls | grep -q '^$_.* dev '; then), emit( qq(if ! \$IP -4 route ls | grep -q '^$_.* dev '; then),
qq( run_ip route replace blackhole $_), qq( run_ip route replace unreachable $_),
qq( echo "qt \$IP -4 route del blackhole $_" >> \${VARDIR}/undo_rfc1918_routing), qq( echo "qt \$IP -4 route del unreachable $_" >> \${VARDIR}/undo_rfc1918_routing),
qq(fi\n) ); qq(fi\n) );
} }
} }
@@ -1084,7 +1057,7 @@ sub start_providers() {
emit 'DEFAULT_ROUTE='; emit 'DEFAULT_ROUTE=';
emit 'FALLBACK_ROUTE='; emit 'FALLBACK_ROUTE=';
emit ''; emit '';
for my $provider ( qw/main default/ ) { for my $provider ( qw/main default/ ) {
emit ''; emit '';
emit qq(> \${VARDIR}/undo_${provider}_routing ); emit qq(> \${VARDIR}/undo_${provider}_routing );
@@ -1097,7 +1070,7 @@ sub start_providers() {
sub finish_providers() { sub finish_providers() {
my $table = MAIN_TABLE; my $table = MAIN_TABLE;
if ( $config{USE_DEFAULT_RT} ) { if ( $config{USE_DEFAULT_RT} ) {
emit ( 'run_ip rule add from ' . ALLIP . ' table ' . MAIN_TABLE . ' pref 999', emit ( 'run_ip rule add from ' . ALLIP . ' table ' . MAIN_TABLE . ' pref 999',
'run_ip rule add from ' . ALLIP . ' table ' . BALANCE_TABLE . ' pref 32765', 'run_ip rule add from ' . ALLIP . ' table ' . BALANCE_TABLE . ' pref 32765',
@@ -1125,7 +1098,7 @@ sub finish_providers() {
'' ''
); );
} }
emit ( " progress_message \"Default route '\$(echo \$DEFAULT_ROUTE | sed 's/\$\\s*//')' Added\"", emit ( " progress_message \"Default route '\$(echo \$DEFAULT_ROUTE | sed 's/\$\\s*//')' Added\"",
'else', 'else',
' error_message "WARNING: No Default route added (all \'balance\' providers are down)"' ); ' error_message "WARNING: No Default route added (all \'balance\' providers are down)"' );
@@ -1143,10 +1116,6 @@ sub finish_providers() {
'# We don\'t have any \'balance\' providers so we restore any default route that we\'ve saved', '# We don\'t have any \'balance\' providers so we restore any default route that we\'ve saved',
'#', '#',
"restore_default_route $config{USE_DEFAULT_RT}" , "restore_default_route $config{USE_DEFAULT_RT}" ,
'#',
'# And delete any routes in the \'balance\' table',
'#',
"qt \$IP -$family route del default table " . BALANCE_TABLE,
'' ); '' );
} }
@@ -1160,17 +1129,10 @@ sub finish_providers() {
} }
emit( " progress_message \"Fallback route '\$(echo \$FALLBACK_ROUTE | sed 's/\$\\s*//')' Added\"", emit( " progress_message \"Fallback route '\$(echo \$FALLBACK_ROUTE | sed 's/\$\\s*//')' Added\"",
'else',
' #',
' # We don\'t have any \'fallback\' providers so we delete any default routes in the default table',
' #',
' delete_default_routes ' . DEFAULT_TABLE,
'fi', 'fi',
'' ); '' );
} elsif ( $config{USE_DEFAULT_RT} ) { } elsif ( $config{USE_DEFAULT_RT} ) {
emit( 'delete_default_routes ' . DEFAULT_TABLE, emit "qt \$IP -$family route del default table " . DEFAULT_TABLE;
''
);
} }
unless ( $config{KEEP_RT_TABLES} ) { unless ( $config{KEEP_RT_TABLES} ) {
@@ -1203,13 +1165,11 @@ sub process_providers( $ ) {
$lastmark = 0; $lastmark = 0;
if ( my $fn = open_file 'providers' ) { if ( my $fn = open_file 'providers' ) {
first_entry "$doing $fn..."; first_entry "$doing $fn...";
process_a_provider, $providers++ while read_a_line( NORMAL_READ ); process_a_provider, $providers++ while read_a_line;
} }
if ( $providers ) { if ( $providers ) {
fatal_error q(Either all 'fallback' providers must specify a weight or non of them can specify a weight) if $fallback && $metrics;
my $fn = open_file( 'route_rules' ); my $fn = open_file( 'route_rules' );
if ( $fn ){ if ( $fn ){
@@ -1222,10 +1182,10 @@ sub process_providers( $ ) {
if ( $fn ) { if ( $fn ) {
first_entry "$doing $fn..."; first_entry "$doing $fn...";
emit ''; emit '';
add_an_rtrule while read_a_line( NORMAL_READ ); add_an_rtrule while read_a_line;
} }
$fn = open_file 'routes'; $fn = open_file 'routes';
@@ -1233,12 +1193,12 @@ sub process_providers( $ ) {
if ( $fn ) { if ( $fn ) {
first_entry "$doing $fn..."; first_entry "$doing $fn...";
emit ''; emit '';
add_a_route while read_a_line( NORMAL_READ ); add_a_route while read_a_line;
} }
} }
add_a_provider( $providers{$_}, $tcdevices ) for @providers; add_a_provider( $providers{$_}, $tcdevices ) for @providers;
emit << 'EOF';; emit << 'EOF';;
# #
@@ -1263,7 +1223,7 @@ EOF
emit( "$providerref->{physical}|$provider)" ); emit( "$providerref->{physical}|$provider)" );
} }
emit ( " if [ -z \"`\$IP -$family route ls table $providerref->{number}`\" ]; then", emit ( " if [ -z \"`\$IP -$family route ls table $providerref->{number}`\" ]; then",
" start_provider_$provider", " start_provider_$provider",
' else', ' else',
" startup_error \"Interface $providerref->{physical} is already enabled\"", " startup_error \"Interface $providerref->{physical} is already enabled\"",
@@ -1281,7 +1241,6 @@ EOF
startup_error "$g_interface is not an optional provider or provider interface" startup_error "$g_interface is not an optional provider or provider interface"
;; ;;
esac esac
} }
# #
@@ -1300,7 +1259,7 @@ EOF
my $providerref = $providers{$provider}; my $providerref = $providers{$provider};
emit( "$providerref->{physical}|$provider)", emit( "$providerref->{physical}|$provider)",
" if [ -n \"`\$IP -$family route ls table $providerref->{number}`\" ]; then", " if [ -n \"`\$IP -$family route ls table $providerref->{number}`\" ]; then",
" stop_provider_$provider", " stop_provider_$provider",
' else', ' else',
" startup_error \"Interface $providerref->{physical} is already disabled\"", " startup_error \"Interface $providerref->{physical} is already disabled\"",
@@ -1322,20 +1281,16 @@ EOF
} }
sub have_providers() {
return our $providers;
}
sub setup_providers() { sub setup_providers() {
our $providers; our $providers;
if ( $providers ) { if ( $providers ) {
emit "\nif [ -z \"\$g_noroutes\" ]; then"; emit "\nif [ -z \"\$g_noroutes\" ]; then";
push_indent; push_indent;
start_providers; start_providers;
emit ''; emit '';
emit "start_provider_$_" for @providers; emit "start_provider_$_" for @providers;
@@ -1371,228 +1326,6 @@ sub setup_providers() {
} }
#
# Emit the updown() function
#
sub compile_updown() {
emit( '',
'#',
'# Handle the "up" and "down" commands',
'#',
'updown() # $1 = interface',
'{',
);
push_indent;
emit( 'local state',
'state=cleared',
''
);
emit 'progress_message3 "$g_product $COMMAND triggered by $1"';
emit '';
if ( $family == F_IPV4 ) {
emit 'if shorewall_is_started; then';
} else {
emit 'if shorewall6_is_started; then';
}
emit( ' state=started',
'elif [ -f ${VARDIR}/state ]; then',
' case "$(cat ${VARDIR}/state)" in',
' Stopped*)',
' state=stopped',
' ;;',
' Cleared*)',
' ;;',
' *)',
' state=unknown',
' ;;',
' esac',
'else',
' state=unknown',
'fi',
''
);
emit( 'case $1 in' );
push_indent;
my $ignore = find_interfaces_by_option 'ignore', 1;
my $required = find_interfaces_by_option 'required';
my $optional = find_interfaces_by_option 'optional';
if ( @$ignore ) {
my $interfaces = join '|', map get_physical( $_ ), @$ignore;
$interfaces =~ s/\+/*/g;
emit( "$interfaces)",
' progress_message3 "$COMMAND on interface $1 ignored"',
' exit 0',
' ;;'
);
}
my @nonshared = ( grep $providers{$_}->{optional},
sort( { $providers{$a}->{number} <=> $providers{$b}->{number} } values %provider_interfaces ) );
if ( @nonshared ) {
my $interfaces = join( '|', map $providers{$_}->{physical}, @nonshared );
emit "$interfaces)";
push_indent;
emit( q(if [ "$state" = started ]; then) ,
q( if [ "$COMMAND" = up ]; then) ,
q( progress_message3 "Attempting enable on interface $1") ,
q( COMMAND=enable) ,
q( detect_configuration),
q( enable_provider $1),
q( elif [ "$PHASE" != post-down ]; then # pre-down or not Debian) ,
q( progress_message3 "Attempting disable on interface $1") ,
q( COMMAND=disable) ,
q( detect_configuration),
q( disable_provider $1) ,
q( fi) ,
q(elif [ "$COMMAND" = up ]; then) ,
q( echo 0 > ${VARDIR}/${1}.status) ,
q( COMMAND=start),
q( progress_message3 "$g_product attempting start") ,
q( detect_configuration),
q( define_firewall),
q(else),
q( progress_message3 "$COMMAND on interface $1 ignored") ,
q(fi) ,
q(;;) );
pop_indent;
}
if ( @$required ) {
my $interfaces = join '|', map get_physical( $_ ), @$required;
my $wildcard = ( $interfaces =~ s/\+/*/g );
emit( "$interfaces)",
' if [ "$COMMAND" = up ]; then' );
if ( $wildcard ) {
emit( ' if [ "$state" = started ]; then',
' COMMAND=restart',
' else',
' COMMAND=start',
' fi' );
} else {
emit( ' COMMAND=start' );
}
emit( ' progress_message3 "$g_product attempting $COMMAND"',
' detect_configuration',
' define_firewall',
' elif [ "$PHASE" != pre-down ]; then # Not Debian pre-down phase'
);
push_indent;
if ( $wildcard ) {
emit( ' if [ "$state" = started ]; then',
' progress_message3 "$g_product attempting restart"',
' COMMAND=restart',
' detect_configuration',
' define_firewall',
' fi' );
} else {
emit( ' COMMAND=stop',
' progress_message3 "$g_product attempting stop"',
' detect_configuration',
' stop_firewall' );
}
pop_indent;
emit( ' fi',
' ;;'
);
}
if ( @$optional ) {
my @interfaces = map( get_physical( $_ ), grep( ! $provider_interfaces{$_} , @$optional ) );
my $interfaces = join '|', @interfaces;
if ( $interfaces ) {
if ( $interfaces =~ s/\+/*/g || @interfaces > 1 ) {
emit( "$interfaces)",
' if [ "$COMMAND" = up ]; then',
' echo 0 > ${VARDIR}/${1}.state',
' else',
' echo 1 > ${VARDIR}/${1}.state',
' fi' );
} else {
emit( "$interfaces)",
' if [ "$COMMAND" = up ]; then',
" echo 0 > \${VARDIR}/$interfaces.state",
' else',
" echo 1 > \${VARDIR}/$interfaces.state",
' fi' );
}
emit( '',
' if [ "$state" = started ]; then',
' COMMAND=restart',
' progress_message3 "$g_product attempting restart"',
' detect_configuration',
' define_firewall',
' elif [ "$state" = stopped ]; then',
' COMMAND=start',
' progress_message3 "$g_product attempting start"',
' detect_configuration',
' define_firewall',
' else',
' progress_message3 "$COMMAND on interface $1 ignored"',
' fi',
' ;;',
);
}
}
if ( my @plain_interfaces = all_plain_interfaces ) {
my $interfaces = join ( '|', @plain_interfaces );
$interfaces =~ s/\+/*/g;
emit( "$interfaces)",
' case $state in',
' started)',
' COMMAND=restart',
' progress_message3 "$g_product attempting restart"',
' detect_configuration',
' define_firewall',
' ;;',
' *)',
' progress_message3 "$COMMAND on interface $1 ignored"',
' ;;',
' esac',
);
}
pop_indent;
emit( 'esac' );
pop_indent;
emit( '}',
'',
);
}
sub lookup_provider( $ ) { sub lookup_provider( $ ) {
my $provider = $_[0]; my $provider = $_[0];
my $providerref = $providers{ $provider }; my $providerref = $providers{ $provider };
@@ -1784,7 +1517,7 @@ sub handle_stickiness( $ ) {
$rule1 = clone_rule( $_ ); $rule1 = clone_rule( $_ );
clear_rule_target( $rule1 ); clear_rule_target( $rule1 );
set_rule_option( $rule1, 'mark', "--mark $mark\/$mask -m recent --name $list --set" ); set_rule_option( $rule1, 'mark', "--mark $mark\/$mask -m recent --name $list --set" );
$rule2 = ''; $rule2 = '';
} }
@@ -1818,7 +1551,7 @@ sub handle_stickiness( $ ) {
while ( my ( $key, $value ) = each %$_ ) { while ( my ( $key, $value ) = each %$_ ) {
$rule2->{$key} = $value; $rule2->{$key} = $value;
} }
clear_rule_target( $rule2 ); clear_rule_target( $rule2 );
set_rule_option ( $rule2, 'mark', "--mark 0\/$mask -m recent --name $list --rdest --remove" ); set_rule_option ( $rule2, 'mark', "--mark 0\/$mask -m recent --name $list --rdest --remove" );
} else { } else {
@@ -1853,7 +1586,7 @@ sub handle_stickiness( $ ) {
sub setup_load_distribution() { sub setup_load_distribution() {
emit ( '', emit ( '',
" distribute_load $maxload @load_interfaces" , " distribute_load $maxload @load_interfaces" ,
'' ''
) if @load_interfaces; ) if @load_interfaces;
} }

View File

@@ -120,7 +120,7 @@ sub setup_proxy_arp() {
my ( %set, %reset ); my ( %set, %reset );
while ( read_a_line( NORMAL_READ ) ) { while ( read_a_line ) {
my ( $address, $interface, $external, $haveroute, $persistent ) = my ( $address, $interface, $external, $haveroute, $persistent ) =
split_line $file_opt . 'file ', { address => 0, interface => 1, external => 2, haveroute => 3, persistent => 4 }; split_line $file_opt . 'file ', { address => 0, interface => 1, external => 2, haveroute => 3, persistent => 4 };

View File

@@ -105,7 +105,7 @@ sub process_notrack_rule( $$$$$$$ ) {
'' , '' ,
$target , $target ,
$exception_rule ); $exception_rule );
progress_message " Notrack rule \"$currentline\" $done"; progress_message " Notrack rule \"$currentline\" $done";
$globals{UNTRACKED} = 1; $globals{UNTRACKED} = 1;
@@ -130,36 +130,36 @@ sub setup_notrack() {
my $nonEmpty = 0; my $nonEmpty = 0;
while ( read_a_line( NORMAL_READ ) ) { while ( read_a_line ) {
my ( $source, $dest, $proto, $ports, $sports, $user ); my ( $source, $dest, $proto, $ports, $sports, $user );
if ( $format == 1 ) { if ( $format == 1 ) {
( $source, $dest, $proto, $ports, $sports, $user ) = split_line1 'Notrack File', { source => 0, dest => 1, proto => 2, dport => 3, sport => 4, user => 5 }; ( $source, $dest, $proto, $ports, $sports, $user ) = split_line1 'Notrack File', { source => 0, dest => 1, proto => 2, dport => 3, sport => 4, user => 5 };
if ( $source eq 'FORMAT' ) { if ( $source eq 'FORMAT' ) {
$format = process_format( $dest ); $format = process_format( $dest );
next; next;
} }
if ( $source eq 'COMMENT' ) { if ( $source eq 'COMMENT' ) {
process_comment; process_comment;
next; next;
} }
} else { } else {
( $action, $source, $dest, $proto, $ports, $sports, $user ) = split_line1 'Notrack File', { action => 0, source => 1, dest => 2, proto => 3, dport => 4, sport => 5, user => 6 }, { COMMENT => 0, FORMAT => 2 }; ( $action, $source, $dest, $proto, $ports, $sports, $user ) = split_line1 'Notrack File', { action => 0, source => 1, dest => 2, proto => 3, dport => 4, sport => 5, user => 6 }, { COMMENT => 0, FORMAT => 2 };
if ( $action eq 'FORMAT' ) { if ( $action eq 'FORMAT' ) {
$format = process_format( $source ); $format = process_format( $source );
$action = 'NOTRACK'; $action = 'NOTRACK';
next; next;
} }
if ( $action eq 'COMMENT' ) { if ( $action eq 'COMMENT' ) {
process_comment; process_comment;
next; next;
} }
} }
process_notrack_rule $action, $source, $dest, $proto, $ports, $sports, $user; process_notrack_rule $action, $source, $dest, $proto, $ports, $sports, $user;
} }

View File

@@ -33,7 +33,6 @@ use Shorewall::Config qw(:DEFAULT :internal);
use Shorewall::Zones; use Shorewall::Zones;
use Shorewall::Chains qw(:DEFAULT :internal); use Shorewall::Chains qw(:DEFAULT :internal);
use Shorewall::IPAddrs; use Shorewall::IPAddrs;
use Shorewall::Nat qw(:rules);
use Scalar::Util 'reftype'; use Scalar::Util 'reftype';
use strict; use strict;
@@ -342,7 +341,7 @@ sub process_a_policy() {
fatal_error "Invalid default action ($default:$remainder)" if defined $remainder; fatal_error "Invalid default action ($default:$remainder)" if defined $remainder;
( $policy , my $queue ) = get_target_param $policy; ( $policy , my $queue ) = get_target_param $policy;
fatal_error "Invalid policy ($policy)" unless exists $validpolicies{$policy}; fatal_error "Invalid policy ($policy)" unless exists $validpolicies{$policy};
if ( $audit ) { if ( $audit ) {
@@ -493,7 +492,7 @@ sub process_policies()
for my $option ( qw( DROP_DEFAULT REJECT_DEFAULT ACCEPT_DEFAULT QUEUE_DEFAULT NFQUEUE_DEFAULT) ) { for my $option ( qw( DROP_DEFAULT REJECT_DEFAULT ACCEPT_DEFAULT QUEUE_DEFAULT NFQUEUE_DEFAULT) ) {
my $action = $config{$option}; my $action = $config{$option};
unless ( $action eq 'none' ) { unless ( $action eq 'none' ) {
my ( $act, $param ) = get_target_param( $action ); my ( $act, $param ) = get_target_param( $action );
@@ -530,7 +529,7 @@ sub process_policies()
if ( my $fn = open_file 'policy' ) { if ( my $fn = open_file 'policy' ) {
first_entry "$doing $fn..."; first_entry "$doing $fn...";
process_a_policy while read_a_line( NORMAL_READ ); process_a_policy while read_a_line;
} else { } else {
fatal_error q(The 'policy' file does not exist or has zero size); fatal_error q(The 'policy' file does not exist or has zero size);
} }
@@ -553,7 +552,7 @@ sub policy_rules( $$$$$ ) {
add_ijump $chainref, j => $default if $default && $default ne 'none'; add_ijump $chainref, j => $default if $default && $default ne 'none';
log_rule $loglevel , $chainref , $target , '' if $loglevel ne ''; log_rule $loglevel , $chainref , $target , '' if $loglevel ne '';
fatal_error "Null target in policy_rules()" unless $target; fatal_error "Null target in policy_rules()" unless $target;
add_ijump( $chainref , j => 'AUDIT', targetopts => '--type ' . lc $target ) if $chainref->{audit}; add_ijump( $chainref , j => 'AUDIT', targetopts => '--type ' . lc $target ) if $chainref->{audit};
add_ijump( $chainref , g => $target eq 'REJECT' ? 'reject' : $target ) unless $target eq 'CONTINUE'; add_ijump( $chainref , g => $target eq 'REJECT' ? 'reject' : $target ) unless $target eq 'CONTINUE';
} }
@@ -686,7 +685,7 @@ sub setup_syn_flood_chains() {
my $limit = $chainref->{synparams}; my $limit = $chainref->{synparams};
if ( $limit && ! $filter_table->{syn_flood_chain $chainref} ) { if ( $limit && ! $filter_table->{syn_flood_chain $chainref} ) {
my $level = $chainref->{loglevel}; my $level = $chainref->{loglevel};
my $synchainref = @zones > 1 ? my $synchainref = @zones > 1 ?
new_chain 'filter' , syn_flood_chain $chainref : new_chain 'filter' , syn_flood_chain $chainref :
new_chain( 'filter' , '@' . $chainref->{name} ); new_chain( 'filter' , '@' . $chainref->{name} );
add_rule $synchainref , "${limit}-j RETURN"; add_rule $synchainref , "${limit}-j RETURN";
@@ -764,7 +763,7 @@ sub finish_chain_section ($$) {
my $chain = $chainref->{name}; my $chain = $chainref->{name};
my $related_level = $config{RELATED_LOG_LEVEL}; my $related_level = $config{RELATED_LOG_LEVEL};
my $related_target = $globals{RELATED_TARGET}; my $related_target = $globals{RELATED_TARGET};
push_comment(''); #These rules should not have comments push_comment(''); #These rules should not have comments
if ( $state =~ /RELATED/ && ( $related_level || $related_target ne 'ACCEPT' ) ) { if ( $state =~ /RELATED/ && ( $related_level || $related_target ne 'ACCEPT' ) ) {
@@ -776,7 +775,7 @@ sub finish_chain_section ($$) {
$config{RELATED_DISPOSITION}, $config{RELATED_DISPOSITION},
'' ); '' );
add_ijump( $relatedref, g => $related_target ); add_ijump( $relatedref, g => $related_target );
$related_target = $relatedref->{name}; $related_target = $relatedref->{name};
} }
@@ -864,9 +863,9 @@ sub split_action ( $ ) {
# #
# Create a normalized action name from the passed pieces. # Create a normalized action name from the passed pieces.
# #
# Internally, action invocations are uniquely identified by a 4-tuple that # Internally, action invocations are uniquely identified by a 4-tuple that
# includes the action name, log level, log tag and params. The pieces of the tuple # includes the action name, log level, log tag and params. The pieces of the tuple
# are separated by ":". # are separated by ":".
# #
sub normalize_action( $$$ ) { sub normalize_action( $$$ ) {
my $action = shift; my $action = shift;
@@ -905,7 +904,7 @@ sub externalize( $ ) {
$target .= ":$tag" if $tag; $target .= ":$tag" if $tag;
$target; $target;
} }
# #
# Define an Action # Define an Action
# #
@@ -964,7 +963,7 @@ sub createlogactionchain( $$$$$ ) {
unless ( $targets{$action} & BUILTIN ) { unless ( $targets{$action} & BUILTIN ) {
set_optflags( $chainref, DONT_OPTIMIZE ); dont_optimize $chainref;
my $file = find_file $chain; my $file = find_file $chain;
@@ -989,7 +988,7 @@ sub createsimpleactionchain( $ ) {
my $normalized = normalize_action_name( $action ); my $normalized = normalize_action_name( $action );
return createlogactionchain( $normalized, $action, 'none', '', '' ) if $filter_table->{$action} || $nat_table->{$action}; return createlogactionchain( $normalized, $action, 'none', '', '' ) if $filter_table->{$action} || $nat_table->{$action};
my $chainref = new_standard_chain $action; my $chainref = new_standard_chain $action;
$usedactions{$normalized} = $chainref; $usedactions{$normalized} = $chainref;
@@ -998,7 +997,7 @@ sub createsimpleactionchain( $ ) {
unless ( $targets{$action} & BUILTIN ) { unless ( $targets{$action} & BUILTIN ) {
set_optflags( $chainref, DONT_OPTIMIZE ); dont_optimize $chainref;
my $file = find_file $action; my $file = find_file $action;
@@ -1206,7 +1205,7 @@ sub dropBcast( $$$$ ) {
log_rule_limit $level, $chainref, 'dropBcast' , 'DROP', '', $tag, 'add', join( ' ', ' -d' , IPv6_MULTICAST , '-j DROP ' ); log_rule_limit $level, $chainref, 'dropBcast' , 'DROP', '', $tag, 'add', join( ' ', ' -d' , IPv6_MULTICAST , '-j DROP ' );
} }
} }
add_ijump $chainref, j => $target, addrtype => '--dst-type BROADCAST'; add_ijump $chainref, j => $target, addrtype => '--dst-type BROADCAST';
} else { } else {
if ( $family == F_IPV4 ) { if ( $family == F_IPV4 ) {
@@ -1307,7 +1306,7 @@ sub allowInvalid ( $$$$ ) {
} }
sub forwardUPnP ( $$$$ ) { sub forwardUPnP ( $$$$ ) {
my $chainref = set_optflags( 'forwardUPnP', DONT_OPTIMIZE ); my $chainref = dont_optimize 'forwardUPnP';
add_commands( $chainref , '[ -f ${VARDIR}/.forwardUPnP ] && cat ${VARDIR}/.forwardUPnP >&3' ); add_commands( $chainref , '[ -f ${VARDIR}/.forwardUPnP ] && cat ${VARDIR}/.forwardUPnP >&3' );
} }
@@ -1395,7 +1394,7 @@ sub process_actions() {
for my $file ( qw/actions.std actions/ ) { for my $file ( qw/actions.std actions/ ) {
open_file $file; open_file $file;
while ( read_a_line( NORMAL_READ ) ) { while ( read_a_line ) {
my ( $action ) = split_line 'action file' , { action => 0 }; my ( $action ) = split_line 'action file' , { action => 0 };
if ( $action =~ /:/ ) { if ( $action =~ /:/ ) {
@@ -1455,7 +1454,7 @@ sub process_action( $) {
push_comment( '' ); push_comment( '' );
while ( read_a_line( NORMAL_READ ) ) { while ( read_a_line ) {
my ($target, $source, $dest, $proto, $ports, $sports, $origdest, $rate, $user, $mark, $connlimit, $time, $headers, $condition ); my ($target, $source, $dest, $proto, $ports, $sports, $origdest, $rate, $user, $mark, $connlimit, $time, $headers, $condition );
@@ -1483,8 +1482,8 @@ sub process_action( $) {
if ( $target eq 'DEFAULTS' ) { if ( $target eq 'DEFAULTS' ) {
default_action_params( $action, split_list $source, 'defaults' ), next if $format == 2; default_action_params( $action, split_list $source, 'defaults' ), next if $format == 2;
fatal_error 'DEFAULTS only allowed in FORMAT-2 actions'; fatal_error 'DEFAULTS only allowed in FORMAT-2 actions';
} }
process_rule1( $chainref, process_rule1( $chainref,
merge_levels( "$action:$level:$tag", $target ), merge_levels( "$action:$level:$tag", $target ),
@@ -1521,7 +1520,7 @@ sub process_action( $) {
# #
sub use_policy_action( $ ) { sub use_policy_action( $ ) {
my $ref = use_action( $_[0] ); my $ref = use_action( $_[0] );
process_action( $ref ) if $ref; process_action( $ref ) if $ref;
} }
@@ -1548,7 +1547,7 @@ sub process_macro ( $$$$$$$$$$$$$$$$$$ ) {
push_open $macrofile; push_open $macrofile;
while ( read_a_line( NORMAL_READ ) ) { while ( read_a_line ) {
my ( $mtarget, $msource, $mdest, $mproto, $mports, $msports, $morigdest, $mrate, $muser, $mmark, $mconnlimit, $mtime, $mheaders, $mcondition ); my ( $mtarget, $msource, $mdest, $mproto, $mports, $msports, $morigdest, $mrate, $muser, $mmark, $mconnlimit, $mtime, $mheaders, $mcondition );
@@ -1560,7 +1559,7 @@ sub process_macro ( $$$$$$$$$$$$$$$$$$ ) {
} }
fatal_error 'TARGET must be specified' if $mtarget eq '-'; fatal_error 'TARGET must be specified' if $mtarget eq '-';
if ( $mtarget eq 'COMMENT' ) { if ( $mtarget eq 'COMMENT' ) {
process_comment unless $nocomment; process_comment unless $nocomment;
next; next;
@@ -1590,7 +1589,7 @@ sub process_macro ( $$$$$$$$$$$$$$$$$$ ) {
my $actiontype = $targets{$action} || find_macro( $action ); my $actiontype = $targets{$action} || find_macro( $action );
fatal_error "Invalid Action ($mtarget) in macro" unless $actiontype & ( ACTION + STANDARD + NATRULE + MACRO + CHAIN ); fatal_error "Invalid Action ($mtarget) in macro" unless $actiontype & ( ACTION + STANDARD + NATRULE + MACRO );
if ( $msource ) { if ( $msource ) {
if ( $msource eq '-' ) { if ( $msource eq '-' ) {
@@ -1664,12 +1663,12 @@ sub verify_audit($;$$) {
# #
# Once a rule has been expanded via wildcards (source and/or dest zone eq 'all'), it is processed by this function. If # Once a rule has been expanded via wildcards (source and/or dest zone eq 'all'), it is processed by this function. If
# the target is a macro, the macro is expanded and this function is called recursively for each rule in the expansion. # the target is a macro, the macro is expanded and this function is called recursively for each rule in the expansion.
# Similarly, if a new action tuple is encountered, this function is called recursively for each rule in the action # Similarly, if a new action tuple is encountered, this function is called recursively for each rule in the action
# body. In this latter case, a reference to the tuple's chain is passed in the first ($chainref) argument. # body. In this latter case, a reference to the tuple's chain is passed in the first ($chainref) argument.
# #
sub process_rule1 ( $$$$$$$$$$$$$$$$$ ) { sub process_rule1 ( $$$$$$$$$$$$$$$$ $) {
my ( $chainref, #reference to Action Chain if we are being called from process_action(); undef otherwise my ( $chainref, #reference to Action Chain if we are being called from process_action(); undef otherwise
$target, $target,
$current_param, $current_param,
$source, $source,
$dest, $dest,
@@ -1686,15 +1685,15 @@ sub process_rule1 ( $$$$$$$$$$$$$$$$$ ) {
$condition, $condition,
$wildcard ) = @_; $wildcard ) = @_;
my ( $action, $loglevel) = split_action $target; my ( $action, $loglevel) = split_action $target;
my ( $basictarget, $param ) = get_target_param $action; my ( $basictarget, $param ) = get_target_param $action;
my $rule = ''; my $rule = '';
my $optimize = $wildcard ? ( $basictarget =~ /!$/ ? 0 : $config{OPTIMIZE} & 5 ) : 0; my $optimize = $wildcard ? ( $basictarget =~ /!$/ ? 0 : $config{OPTIMIZE} & 1 ) : 0;
my $inaction = ''; my $inaction = '';
my $normalized_target; my $normalized_target;
my $normalized_action; my $normalized_action;
my $blacklist = ( $section eq 'BLACKLIST' ); my $blacklist = ( $section eq 'BLACKLIST' );
( $inaction, undef, undef, undef ) = split /:/, $normalized_action = $chainref->{action}, 4 if defined $chainref; ( $inaction, undef, undef, undef ) = split /:/, $normalized_action = $chainref->{action}, 4 if defined $chainref;
$param = '' unless defined $param; $param = '' unless defined $param;
@@ -1758,7 +1757,7 @@ sub process_rule1 ( $$$$$$$$$$$$$$$$$ ) {
# #
# We can now dispense with the postfix character # We can now dispense with the postfix character
# #
fatal_error "The +, - and ! modifiers are not allowed in the blrules file" if $action =~ s/[-+!]$// && $blacklist; fatal_error "The +, - and ! modifiers are not allowed in the blrules file" if $action =~ s/[\+\-!]$// && $blacklist;
# #
# Handle actions # Handle actions
# #
@@ -1806,33 +1805,32 @@ sub process_rule1 ( $$$$$$$$$$$$$$$$$ ) {
$bt =~ s/[-+!]$//; $bt =~ s/[-+!]$//;
my %functions = my %functions = ( ACCEPT => sub() { $action = 'RETURN' if $blacklist; } ,
( ACCEPT => sub() { $action = 'RETURN' if $blacklist; } ,
REDIRECT => sub () {
my $z = $actiontype & NATONLY ? '' : firewall_zone;
if ( $dest eq '-' ) {
$dest = $inaction ? '' : join( '', $z, '::' , $ports =~ /[:,]/ ? '' : $ports );
} elsif ( $inaction ) {
$dest = ":$dest";
} else {
$dest = join( '', $z, '::', $dest ) unless $dest =~ /^[^\d].*:/;
}
} ,
REJECT => sub { $action = 'reject'; } , REDIRECT => sub () {
my $z = $actiontype & NATONLY ? '' : firewall_zone;
if ( $dest eq '-' ) {
$dest = $inaction ? '' : join( '', $z, '::' , $ports =~ /[:,]/ ? '' : $ports );
} elsif ( $inaction ) {
$dest = ":$dest";
} else {
$dest = join( '', $z, '::', $dest ) unless $dest =~ /^[^\d].*:/;
}
} ,
CONTINUE => sub { $action = 'RETURN'; } , REJECT => sub { $action = 'reject'; } ,
WHITELIST => sub { CONTINUE => sub { $action = 'RETURN'; } ,
fatal_error "'WHITELIST' may only be used in the blrules file" unless $blacklist;
$action = 'RETURN';
} ,
COUNT => sub { $action = ''; } , WHITELIST => sub {
fatal_error "'WHITELIST' may only be used in the blrules file" unless $blacklist;
$action = 'RETURN';
} ,
LOG => sub { fatal_error 'LOG requires a log level' unless supplied $loglevel; } , COUNT => sub { $action = ''; } ,
);
LOG => sub { fatal_error 'LOG requires a log level' unless supplied $loglevel; } ,
);
my $function = $functions{ $bt }; my $function = $functions{ $bt };
@@ -1840,7 +1838,7 @@ sub process_rule1 ( $$$$$$$$$$$$$$$$$ ) {
$function->(); $function->();
} elsif ( $actiontype & SET ) { } elsif ( $actiontype & SET ) {
my %xlate = ( ADD => 'add-set' , DEL => 'del-set' ); my %xlate = ( ADD => 'add-set' , DEL => 'del-set' );
my ( $setname, $flags, $rest ) = split ':', $param, 3; my ( $setname, $flags, $rest ) = split ':', $param, 3;
fatal_error "Invalid ADD/DEL parameter ($param)" if $rest; fatal_error "Invalid ADD/DEL parameter ($param)" if $rest;
fatal_error "Expected ipset name ($setname)" unless $setname =~ s/^\+// && $setname =~ /^[a-zA-Z]\w*$/; fatal_error "Expected ipset name ($setname)" unless $setname =~ s/^\+// && $setname =~ /^[a-zA-Z]\w*$/;
@@ -1866,7 +1864,7 @@ sub process_rule1 ( $$$$$$$$$$$$$$$$$ ) {
$sourcezone = $source; $sourcezone = $source;
$source = ALLIP; $source = ALLIP;
} }
if ( $dest =~ /^(.*?):(.*)/ ) { if ( $dest =~ /^(.*?):(.*)/ ) {
fatal_error "Missing DEST Qualifier ($dest)" if $2 eq ''; fatal_error "Missing DEST Qualifier ($dest)" if $2 eq '';
$destzone = $1; $destzone = $1;
@@ -1922,14 +1920,14 @@ sub process_rule1 ( $$$$$$$$$$$$$$$$$ ) {
# #
# Take care of chain # Take care of chain
# #
my $chain; my ( $chain, $policy );
if ( $inaction ) { if ( $inaction ) {
# #
# We are generating rules in an action chain -- the chain name is the name of that action chain # We are generating rules in an action chain -- the chain name is the name of that action chain
# #
$chain = $chainref->{name}; $chain = $chainref->{name};
} else { } else {
unless ( $actiontype & NATONLY ) { unless ( $actiontype & NATONLY ) {
# #
# Check for illegal bridge port rule # Check for illegal bridge port rule
@@ -1945,8 +1943,8 @@ sub process_rule1 ( $$$$$$$$$$$$$$$$$ ) {
# #
# Ensure that the chain exists but don't mark it as referenced until after optimization is checked # Ensure that the chain exists but don't mark it as referenced until after optimization is checked
# #
$chainref = ensure_chain 'filter', $chain; $chainref = ensure_chain 'filter', $chain;
my $policy = $chainref->{policy}; $policy = $chainref->{policy};
if ( $policy eq 'NONE' ) { if ( $policy eq 'NONE' ) {
return 0 if $wildcard; return 0 if $wildcard;
@@ -1955,10 +1953,10 @@ sub process_rule1 ( $$$$$$$$$$$$$$$$$ ) {
# #
# Handle Optimization # Handle Optimization
# #
if ( $optimize == 1 && $section eq 'NEW' ) { if ( $optimize > 0 && $section eq 'NEW' ) {
my $loglevel = $filter_table->{$chainref->{policychain}}{loglevel}; my $loglevel = $filter_table->{$chainref->{policychain}}{loglevel};
if ( $loglevel ne '' ) { if ( $loglevel ne '' ) {
return 0 if $target eq "${policy}:${loglevel}"; return 0 if $target eq "${policy}:$loglevel}";
} else { } else {
return 0 if $basictarget eq $policy; return 0 if $basictarget eq $policy;
} }
@@ -1973,7 +1971,7 @@ sub process_rule1 ( $$$$$$$$$$$$$$$$$ ) {
if ( $blacklist ) { if ( $blacklist ) {
my $blacklistchain = blacklist_chain( ${sourcezone}, ${destzone} ); my $blacklistchain = blacklist_chain( ${sourcezone}, ${destzone} );
my $blacklistref = $filter_table->{$blacklistchain}; my $blacklistref = $filter_table->{$blacklistchain};
unless ( $blacklistref ) { unless ( $blacklistref ) {
my @state; my @state;
$blacklistref = new_chain 'filter', $blacklistchain; $blacklistref = new_chain 'filter', $blacklistchain;
@@ -1981,7 +1979,7 @@ sub process_rule1 ( $$$$$$$$$$$$$$$$$ ) {
@state = state_imatch( 'NEW,INVALID' ) if $config{BLACKLISTNEWONLY}; @state = state_imatch( 'NEW,INVALID' ) if $config{BLACKLISTNEWONLY};
add_ijump( $chainref, j => $blacklistref, @state ); add_ijump( $chainref, j => $blacklistref, @state );
} }
$chain = $blacklistchain; $chain = $blacklistchain;
$chainref = $blacklistref; $chainref = $blacklistref;
} }
@@ -2019,10 +2017,10 @@ sub process_rule1 ( $$$$$$$$$$$$$$$$$ ) {
unless ( $section eq 'NEW' || $inaction ) { unless ( $section eq 'NEW' || $inaction ) {
if ( $config{FASTACCEPT} ) { if ( $config{FASTACCEPT} ) {
fatal_error "Entries in the $section SECTION of the rules file not permitted with FASTACCEPT=Yes" unless fatal_error "Entries in the $section SECTION of the rules file not permitted with FASTACCEPT=Yes" unless
$section eq 'BLACKLIST' || $section eq 'BLACKLIST' ||
( $section eq 'RELATED' && ( $config{RELATED_DISPOSITION} ne 'ACCEPT' || $config{RELATED_LOG_LEVEL} ) ) ( $section eq 'RELATED' && ( $config{RELATED_DISPOSITION} ne 'ACCEPT' || $config{RELATED_LOG_LEVEL} ) )
} }
fatal_error "$basictarget rules are not allowed in the $section SECTION" if $actiontype & ( NATRULE | NONAT ); fatal_error "$basictarget rules are not allowed in the $section SECTION" if $actiontype & ( NATRULE | NONAT );
$rule .= "$globals{STATEMATCH} $section " unless $section eq 'ALL' || $blacklist; $rule .= "$globals{STATEMATCH} $section " unless $section eq 'ALL' || $blacklist;
@@ -2032,29 +2030,132 @@ sub process_rule1 ( $$$$$$$$$$$$$$$$$ ) {
# Generate NAT rule(s), if any # Generate NAT rule(s), if any
# #
if ( $actiontype & NATRULE ) { if ( $actiontype & NATRULE ) {
my ( $server, $serverport );
my $randomize = $dest =~ s/:random$// ? ' --random' : '';
require_capability( 'NAT_ENABLED' , "$basictarget rules", '' ); require_capability( 'NAT_ENABLED' , "$basictarget rules", '' );
# #
# Add the appropriate rule to the nat table # Isolate server port
# #
( $ports, if ( $dest =~ /^(.*)(:(.+))$/ ) {
$origdstports, #
$dest ) = handle_nat_rule( $dest, # Server IP and Port
$proto, #
$ports, $server = $1; # May be empty
$origdest, $serverport = $3; # Not Empty due to RE
( $actiontype & ACTION ) ? $usedactions{$normalized_target}->{name} : '', $origdstports = $ports;
$action,
$sourceref, if ( $origdstports && $origdstports ne '-' && port_count( $origdstports ) == 1 ) {
$inaction ? $chain : '', $origdstports = validate_port( $proto, $origdstports );
$rule, } else {
$source, $origdstports = '';
( $actiontype & ACTION ) ? '' : $loglevel, }
$log_action
); if ( $serverport =~ /^(\d+)-(\d+)$/ ) {
#
# Server Port Range
#
fatal_error "Invalid port range ($serverport)" unless $1 < $2;
my @ports = ( $1, $2 );
$_ = validate_port( proto_name( $proto ), $_) for ( @ports );
( $ports = $serverport ) =~ tr/-/:/;
} else {
$serverport = $ports = validate_port( proto_name( $proto ), $serverport );
}
} elsif ( $dest eq ':' ) {
#
# Rule with no server IP or port ( zone:: )
#
$server = $serverport = '';
} else {
#
# Simple server IP address (may be empty or "-")
#
$server = $dest;
$serverport = '';
}
#
# Generate the target
#
my $target = '';
if ( $actiontype & REDIRECT ) {
fatal_error "A server IP address ($server) may not be specified in a REDIRECT rule" if $server;
$target = 'REDIRECT';
$target .= " --to-port $serverport" if $serverport;
if ( $origdest eq '' || $origdest eq '-' ) {
$origdest = ALLIP;
} elsif ( $origdest eq 'detect' ) {
fatal_error 'ORIGINAL DEST "detect" is invalid in an action' if $inaction;
if ( $config{DETECT_DNAT_IPADDRS} && $sourcezone ne firewall_zone ) {
my $interfacesref = $sourceref->{interfaces};
my @interfaces = keys %$interfacesref;
$origdest = @interfaces ? "detect:@interfaces" : ALLIP;
} else {
$origdest = ALLIP;
}
}
} elsif ( $actiontype & ACTION ) {
fatal_error "A server port ($serverport) is not allowed in $action rule" if $serverport;
$target = $usedactions{$normalized_target}->{name};
$loglevel = '';
} else {
if ( $server eq '' ) {
fatal_error "A server and/or port must be specified in the DEST column in $action rules" unless $serverport;
} elsif ( $server =~ /^(.+)-(.+)$/ ) {
validate_range( $1, $2 );
} else {
unless ( ( $actiontype & ACTION ) && $server eq ALLIP ) {
my @servers = validate_address $server, 1;
$server = join ',', @servers;
}
}
if ( $action eq 'DNAT' ) {
$target = 'DNAT';
if ( $server ) {
$serverport = ":$serverport" if $serverport;
for my $serv ( split /,/, $server ) {
$target .= " --to-destination ${serv}${serverport}";
}
} else {
$target .= " --to-destination :$serverport";
}
}
unless ( $origdest && $origdest ne '-' && $origdest ne 'detect' ) {
if ( ! $inaction && $config{DETECT_DNAT_IPADDRS} && $sourcezone ne firewall_zone ) {
my $interfacesref = $sourceref->{interfaces};
my @interfaces = keys %$interfacesref;
$origdest = @interfaces ? "detect:@interfaces" : ALLIP;
} else {
$origdest = ALLIP;
}
}
}
$target .= $randomize;
#
# And generate the nat table rule(s)
#
expand_rule ( ensure_chain ('nat' , $inaction ? $chain : $sourceref->{type} == FIREWALL ? 'OUTPUT' : dnat_chain $sourcezone ),
PREROUTE_RESTRICT ,
$rule ,
$source ,
$origdest ,
'' ,
$target ,
$loglevel ,
$log_action ,
$serverport ? do_proto( $proto, '', '' ) : '',
);
# #
# After NAT: # After NAT:
# - the destination port will be the server port ($ports) -- we did that above # - the destination port will be the server port ($ports) -- we did that above
# - the destination IP will be the server IP ($dest) -- also done above # - the destination IP will be the server IP ($dest)
# - there will be no log level (we log NAT rules in the nat table rather than in the filter table). # - there will be no log level (we log NAT rules in the nat table rather than in the filter table).
# - the target will be ACCEPT. # - the target will be ACCEPT.
# #
@@ -2067,24 +2168,89 @@ sub process_rule1 ( $$$$$$$$$$$$$$$$$ ) {
do_condition( $condition ) do_condition( $condition )
); );
$loglevel = ''; $loglevel = '';
$dest = $server;
$action = 'ACCEPT'; $action = 'ACCEPT';
$origdest = ALLIP if $origdest =~ /[+]/; $origdest = ALLIP if $origdest =~ /[+]/;
} }
} elsif ( $actiontype & NONAT ) { } elsif ( $actiontype & NONAT ) {
# #
# NONAT or ACCEPT+ # NONAT or ACCEPT+ -- May not specify a destination interface
# #
handle_nonat_rule( $action, fatal_error "Invalid DEST ($dest) in $action rule" if $dest =~ /:/;
$source,
$dest, $origdest = '' unless $origdest and $origdest ne '-';
$origdest,
$sourceref, if ( $origdest eq 'detect' ) {
$inaction, my $interfacesref = $sourceref->{interfaces};
$chain, my $interfaces = [ ( keys %$interfacesref ) ];
$loglevel, $origdest = $interfaces ? "detect:@$interfaces" : ALLIP;
$log_action, }
$rule
); my $tgt = 'RETURN';
my $nonat_chain;
my $chn;
if ( $inaction ) {
$nonat_chain = ensure_chain( 'nat', $chain );
} elsif ( $sourceref->{type} == FIREWALL ) {
$nonat_chain = $nat_table->{OUTPUT};
} else {
$nonat_chain = ensure_chain( 'nat', dnat_chain( $sourcezone ) );
my @interfaces = keys %{zone_interfaces $sourcezone};
for ( @interfaces ) {
my $ichain = input_chain $_;
if ( $nat_table->{$ichain} ) {
#
# Static NAT is defined on this interface
#
$chn = new_chain( 'nat', newnonatchain ) unless $chn;
add_ijump $chn, j => $nat_table->{$ichain}, @interfaces > 1 ? imatch_source_dev( $_ ) : ();
}
}
if ( $chn ) {
#
# Call expand_rule() to correctly handle logging. Because
# the 'logname' argument is passed, expand_rule() will
# not create a separate logging chain but will rather emit
# any logging rule in-line.
#
expand_rule( $chn,
PREROUTE_RESTRICT,
'', # Rule
'', # Source
'', # Dest
'', # Original dest
'ACCEPT',
$loglevel,
$log_action,
'',
dnat_chain( $sourcezone ) );
$loglevel = '';
$tgt = $chn->{name};
} else {
$tgt = 'ACCEPT';
}
}
dont_move( dont_optimize( $nonat_chain ) ) if $tgt eq 'RETURN';
expand_rule( $nonat_chain ,
PREROUTE_RESTRICT ,
$rule ,
$source ,
$dest ,
$origdest ,
$tgt,
$loglevel ,
$log_action ,
'',
);
} }
# #
@@ -2096,7 +2262,7 @@ sub process_rule1 ( $$$$$$$$$$$$$$$$$ ) {
$action = $usedactions{$normalized_target}{name}; $action = $usedactions{$normalized_target}{name};
$loglevel = ''; $loglevel = '';
} else { } else {
set_optflags( $chainref , DONT_MOVE | DONT_OPTIMIZE ) if $action eq 'RETURN'; dont_move( dont_optimize ( $chainref ) ) if $action eq 'RETURN';
} }
if ( $origdest ) { if ( $origdest ) {
@@ -2241,7 +2407,7 @@ sub process_rule ( ) {
progress_message "Rule \"$currentline\" ignored."; progress_message "Rule \"$currentline\" ignored.";
return 1; return 1;
} }
my $intrazone = 0; my $intrazone = 0;
my $wild = 0; my $wild = 0;
my $thisline = $currentline; #We must save $currentline because it is overwritten by macro expansion my $thisline = $currentline; #We must save $currentline because it is overwritten by macro expansion
@@ -2292,12 +2458,6 @@ sub process_rule ( ) {
progress_message qq( Rule "$thisline" $done); progress_message qq( Rule "$thisline" $done);
} }
sub intrazone_allowed( $$ ) {
my ( $zone, $zoneref ) = @_;
$zoneref->{complex} && $filter_table->{rules_chain( $zone, $zone )}{policy} ne 'NONE';
}
# #
# Add jumps to the blacklst and blackout chains # Add jumps to the blacklst and blackout chains
# #
@@ -2307,11 +2467,11 @@ sub classic_blacklist() {
my @vservers = vserver_zones; my @vservers = vserver_zones;
my @state = $config{BLACKLISTNEWONLY} ? $globals{UNTRACKED} ? state_imatch 'NEW,INVALID,UNTRACKED' : state_imatch 'NEW,INVALID' : (); my @state = $config{BLACKLISTNEWONLY} ? $globals{UNTRACKED} ? state_imatch 'NEW,INVALID,UNTRACKED' : state_imatch 'NEW,INVALID' : ();
my $result; my $result;
for my $zone ( @zones ) { for my $zone ( @zones ) {
my $zoneref = find_zone( $zone ); my $zoneref = find_zone( $zone );
my $simple = @zones <= 2 && ! $zoneref->{complex}; my $simple = @zones <= 2 && ! $zoneref->{options}{complex};
if ( $zoneref->{options}{in}{blacklist} ) { if ( $zoneref->{options}{in}{blacklist} ) {
my $blackref = $filter_table->{blacklst}; my $blackref = $filter_table->{blacklst};
add_ijump ensure_rules_chain( rules_chain( $zone, $_ ) ) , j => $blackref , @state for firewall_zone, @vservers; add_ijump ensure_rules_chain( rules_chain( $zone, $_ ) ) , j => $blackref , @state for firewall_zone, @vservers;
@@ -2324,7 +2484,7 @@ sub classic_blacklist() {
my $ruleschain = rules_chain( $zone, $zone1 ); my $ruleschain = rules_chain( $zone, $zone1 );
my $ruleschainref = $filter_table->{$ruleschain}; my $ruleschainref = $filter_table->{$ruleschain};
if ( $zone ne $zone1 || intrazone_allowed( $zone, $zoneref ) ) { if ( ( $zone ne $zone1 || $ruleschainref->{referenced} ) && $ruleschainref->{policy} ne 'NONE' ) {
add_ijump( ensure_rules_chain( $ruleschain ), j => $blackref, @state ); add_ijump( ensure_rules_chain( $ruleschain ), j => $blackref, @state );
} }
} }
@@ -2341,7 +2501,7 @@ sub classic_blacklist() {
my $ruleschain = rules_chain( $zone1, $zone ); my $ruleschain = rules_chain( $zone1, $zone );
my $ruleschainref = $filter_table->{$ruleschain}; my $ruleschainref = $filter_table->{$ruleschain};
if ( ( $zone ne $zone1 || intrazone_allowed( $zone, $zoneref ) ) ) { if ( ( $zone ne $zone1 || $ruleschainref->{referenced} ) && $ruleschainref->{policy} ne 'NONE' ) {
add_ijump( ensure_rules_chain( $ruleschain ), j => $blackref, @state ); add_ijump( ensure_rules_chain( $ruleschain ), j => $blackref, @state );
} }
} }
@@ -2401,25 +2561,20 @@ sub process_rules( $ ) {
} }
); );
process_rule while read_a_line( NORMAL_READ ); process_rule while read_a_line;
} }
$section = ''; $section = '';
add_interface_options( $blrules ); add_interface_options( $blrules );
#
# Handle MSS settings in the zones file
#
setup_zone_mss;
$fn = open_file 'rules'; $fn = open_file 'rules';
if ( $fn ) { if ( $fn ) {
first_entry "$doing $fn..."; first_entry "$doing $fn...";
process_rule while read_a_line( NORMAL_READ ); process_rule while read_a_line;
clear_comment; clear_comment;
} }

File diff suppressed because it is too large Load Diff

View File

@@ -2,6 +2,7 @@
# Shorewall 4.4 -- /usr/share/shorewall/Shorewall/Tunnels.pm # Shorewall 4.4 -- /usr/share/shorewall/Shorewall/Tunnels.pm
# #
# This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt] # This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt]
#
# (c) 2007,2008,2009,2010,2011 - Tom Eastep (teastep@shorewall.net) # (c) 2007,2008,2009,2010,2011 - Tom Eastep (teastep@shorewall.net)
# #
# Complete documentation is available at http://shorewall.net # Complete documentation is available at http://shorewall.net
@@ -125,9 +126,9 @@ sub setup_tunnels() {
sub setup_pptp_server { sub setup_pptp_server {
my ($inchainref, $outchainref, $kind, $source, $dest ) = @_; my ($inchainref, $outchainref, $kind, $source, $dest ) = @_;
add_tunnel_rule $inchainref, p => 47, @$source; add_tunnel_rule $inchainref, p => 47, @$dest;
add_tunnel_rule $outchainref, p => 47, @$dest; add_tunnel_rule $outchainref, p => 47, @$source;
add_tunnel_rule $inchainref, p => 'tcp --dport 1723', @$source add_tunnel_rule $inchainref, p => 'tcp --dport 1723', @$dest
} }
sub setup_one_openvpn { sub setup_one_openvpn {
@@ -233,7 +234,7 @@ sub setup_tunnels() {
} }
sub setup_one_tunnel($$$$) { sub setup_one_tunnel($$$$) {
my ( $kind , $zone, $gateways, $gatewayzones ) = @_; my ( $kind , $zone, $gateway, $gatewayzones ) = @_;
my $zonetype = zone_type( $zone ); my $zonetype = zone_type( $zone );
@@ -242,42 +243,35 @@ sub setup_tunnels() {
my $inchainref = ensure_rules_chain( rules_chain( ${zone}, ${fw} ) ); my $inchainref = ensure_rules_chain( rules_chain( ${zone}, ${fw} ) );
my $outchainref = ensure_rules_chain( rules_chain( ${fw}, ${zone} ) ); my $outchainref = ensure_rules_chain( rules_chain( ${fw}, ${zone} ) );
$gateways = ALLIP if $gateways eq '-'; $gateway = ALLIP if $gateway eq '-';
my ( $net, $excl ) = handle_network_list( $gateways , 'src' ); my @source = imatch_source_net $gateway;
( $net, $excl ) = handle_network_list( $gateways , 'dst' ); my @dest = imatch_dest_net $gateway;
fatal_error "Exclusion is not allowed in the GATEWAYS column" if $excl; my %tunneltypes = ( 'ipsec' => { function => \&setup_one_ipsec , params => [ $kind, \@source, \@dest , $gatewayzones ] } ,
'ipsecnat' => { function => \&setup_one_ipsec , params => [ $kind, \@source, \@dest , $gatewayzones ] } ,
'ipip' => { function => \&setup_one_other, params => [ \@source, \@dest , 4 ] } ,
'gre' => { function => \&setup_one_other, params => [ \@source, \@dest , 47 ] } ,
'6to4' => { function => \&setup_one_other, params => [ \@source, \@dest , 41 ] } ,
'6in4' => { function => \&setup_one_other, params => [ \@source, \@dest , 41 ] } ,
'pptpclient' => { function => \&setup_pptp_client, params => [ $kind, \@source, \@dest ] } ,
'pptpserver' => { function => \&setup_pptp_server, params => [ $kind, \@source, \@dest ] } ,
'openvpn' => { function => \&setup_one_openvpn, params => [ $kind, \@source, \@dest ] } ,
'openvpnclient' => { function => \&setup_one_openvpn_client, params => [ $kind, \@source, \@dest ] } ,
'openvpnserver' => { function => \&setup_one_openvpn_server, params => [ $kind, \@source, \@dest ] } ,
'l2tp' => { function => \&setup_one_l2tp , params => [ $kind, \@source, \@dest ] } ,
'generic' => { function => \&setup_one_generic , params => [ $kind, \@source, \@dest ] } ,
);
for my $gateway ( split_list $gateways, 'GATEWAYS' ) { $kind = "\L$kind";
my @source = imatch_source_net $gateway;
my @dest = imatch_dest_net $gateway;
my %tunneltypes = ( 'ipsec' => { function => \&setup_one_ipsec , params => [ $kind, \@source, \@dest , $gatewayzones ] } , (my $type) = split /:/, $kind;
'ipsecnat' => { function => \&setup_one_ipsec , params => [ $kind, \@source, \@dest , $gatewayzones ] } ,
'ipip' => { function => \&setup_one_other, params => [ \@source, \@dest , 4 ] } ,
'gre' => { function => \&setup_one_other, params => [ \@source, \@dest , 47 ] } ,
'6to4' => { function => \&setup_one_other, params => [ \@source, \@dest , 41 ] } ,
'6in4' => { function => \&setup_one_other, params => [ \@source, \@dest , 41 ] } ,
'pptpclient' => { function => \&setup_pptp_client, params => [ $kind, \@source, \@dest ] } ,
'pptpserver' => { function => \&setup_pptp_server, params => [ $kind, \@source, \@dest ] } ,
'openvpn' => { function => \&setup_one_openvpn, params => [ $kind, \@source, \@dest ] } ,
'openvpnclient' => { function => \&setup_one_openvpn_client, params => [ $kind, \@source, \@dest ] } ,
'openvpnserver' => { function => \&setup_one_openvpn_server, params => [ $kind, \@source, \@dest ] } ,
'l2tp' => { function => \&setup_one_l2tp , params => [ $kind, \@source, \@dest ] } ,
'generic' => { function => \&setup_one_generic , params => [ $kind, \@source, \@dest ] } ,
);
$kind = "\L$kind"; my $tunnelref = $tunneltypes{ $type };
(my $type) = split /:/, $kind; fatal_error "Tunnels of type $type are not supported" unless $tunnelref;
my $tunnelref = $tunneltypes{ $type }; $tunnelref->{function}->( $inchainref, $outchainref, @{$tunnelref->{params}} );
fatal_error "Tunnels of type $type are not supported" unless $tunnelref;
$tunnelref->{function}->( $inchainref, $outchainref, @{$tunnelref->{params}} );
}
progress_message " Tunnel \"$currentline\" $done"; progress_message " Tunnel \"$currentline\" $done";
} }
@@ -289,16 +283,16 @@ sub setup_tunnels() {
first_entry "$doing $fn..."; first_entry "$doing $fn...";
while ( read_a_line( NORMAL_READ ) ) { while ( read_a_line ) {
my ( $kind, $zone, $gateway, $gatewayzones ) = split_line1 'tunnels file', { type => 0, zone => 1, gateway => 2, gateways => 2, gateway_zone => 3 , gateway_zones => 3 }, undef, 4; my ( $kind, $zone, $gateway, $gatewayzones ) = split_line1 'tunnels file', { type => 0, zone => 1, gateway => 2, gateway_zone => 3 };
fatal_error 'TYPE must be specified' if $kind eq '-'; fatal_error 'TYPE must be specified' if $kind eq '-';
fatal_error 'ZONE must be specified' if $zone eq '-';
if ( $kind eq 'COMMENT' ) { if ( $kind eq 'COMMENT' ) {
process_comment; process_comment;
} else { } else {
fatal_error 'ZONE must be specified' if $zone eq '-';
setup_one_tunnel $kind, $zone, $gateway, $gatewayzones; setup_one_tunnel $kind, $zone, $gateway, $gatewayzones;
} }
} }

View File

@@ -41,8 +41,6 @@ our @EXPORT = qw( NOTHING
IP IP
BPORT BPORT
IPSEC IPSEC
NO_UPDOWN
NO_SFILTER
determine_zones determine_zones
zone_report zone_report
@@ -64,7 +62,6 @@ our @EXPORT = qw( NOTHING
validate_interfaces_file validate_interfaces_file
all_interfaces all_interfaces
all_real_interfaces all_real_interfaces
all_plain_interfaces
all_bridges all_bridges
interface_number interface_number
find_interface find_interface
@@ -75,7 +72,6 @@ our @EXPORT = qw( NOTHING
port_to_bridge port_to_bridge
source_port_to_bridge source_port_to_bridge
interface_is_optional interface_is_optional
interface_is_required
find_interfaces_by_option find_interfaces_by_option
find_interfaces_by_option1 find_interfaces_by_option1
get_interface_option get_interface_option
@@ -84,9 +80,9 @@ our @EXPORT = qw( NOTHING
set_interface_provider set_interface_provider
interface_zones interface_zones
verify_required_interfaces verify_required_interfaces
compile_updown
validate_hosts_file validate_hosts_file
find_hosts_by_option find_hosts_by_option
find_zone_hosts_by_option
find_zones_by_option find_zones_by_option
all_ipsets all_ipsets
have_ipsec have_ipsec
@@ -117,10 +113,11 @@ use constant { IN_OUT => 1,
# #
# @zones contains the ordered list of zones with sub-zones appearing before their parents. # @zones contains the ordered list of zones with sub-zones appearing before their parents.
# #
# %zones{<zone1> => {type => <zone type> FIREWALL, IP, IPSEC, BPORT; # %zones{<zone1> => {type = > <zone type> FIREWALL, IP, IPSEC, BPORT;
# complex => 0|1 # options => { complex => 0|1
# super => 0|1 # nested => 0|1
# options => { in_out => < policy match string > # super => 0|1
# in_out => < policy match string >
# in => < policy match string > # in => < policy match string >
# out => < policy match string > # out => < policy match string >
# } # }
@@ -176,7 +173,6 @@ my %reservedName = ( all => 1,
# number => <ordinal position in the interfaces file> # number => <ordinal position in the interfaces file>
# physical => <physical interface name> # physical => <physical interface name>
# base => <shell variable base representing this interface> # base => <shell variable base representing this interface>
# provider => <Provider Name, if interface is associated with a provider>
# zones => { zone1 => 1, ... } # zones => { zone1 => 1, ... }
# } # }
# } # }
@@ -223,36 +219,14 @@ use constant { SIMPLE_IF_OPTION => 1,
IF_OPTION_WILDOK => 64 IF_OPTION_WILDOK => 64
}; };
use constant { NO_UPDOWN => 1,
NO_SFILTER => 2 };
my %validinterfaceoptions; my %validinterfaceoptions;
my %defaultinterfaceoptions = ( routefilter => 1 , wait => 60 ); my %defaultinterfaceoptions = ( routefilter => 1 , wait => 60 );
my %maxoptionvalue = ( routefilter => 2, mss => 100000 , wait => 120 , ignore => NO_UPDOWN ); my %maxoptionvalue = ( routefilter => 2, mss => 100000 , wait => 120 );
my %validhostoptions; my %validhostoptions;
my %validzoneoptions = ( mss => NUMERIC,
nomark => NOTHING,
blacklist => NOTHING,
strict => NOTHING,
next => NOTHING,
reqid => NUMERIC,
spi => NUMERIC,
proto => IPSECPROTO,
mode => IPSECMODE,
"tunnel-src" => NETWORK,
"tunnel-dst" => NETWORK,
);
use constant { UNRESTRICTED => 1, NOFW => 2 , COMPLEX => 8, IN_OUT_ONLY => 16 };
#
# Hash of options that have their own key in the returned hash.
#
my %zonekey = ( mss => UNRESTRICTED | COMPLEX , blacklist => NOFW, nomark => NOFW | IN_OUT_ONLY );
# #
# Rather than initializing globals in an INIT block or during declaration, # Rather than initializing globals in an INIT block or during declaration,
# we initialize them in a function. This is done for two reasons: # we initialize them in a function. This is done for two reasons:
@@ -288,7 +262,6 @@ sub initialize( $$ ) {
bridge => SIMPLE_IF_OPTION, bridge => SIMPLE_IF_OPTION,
detectnets => OBSOLETE_IF_OPTION, detectnets => OBSOLETE_IF_OPTION,
dhcp => SIMPLE_IF_OPTION, dhcp => SIMPLE_IF_OPTION,
ignore => NUMERIC_IF_OPTION + IF_OPTION_WILDOK,
maclist => SIMPLE_IF_OPTION + IF_OPTION_HOST, maclist => SIMPLE_IF_OPTION + IF_OPTION_HOST,
logmartians => BINARY_IF_OPTION, logmartians => BINARY_IF_OPTION,
nets => IPLIST_IF_OPTION + IF_OPTION_ZONEONLY + IF_OPTION_VSERVER, nets => IPLIST_IF_OPTION + IF_OPTION_ZONEONLY + IF_OPTION_VSERVER,
@@ -317,14 +290,12 @@ sub initialize( $$ ) {
broadcast => 1, broadcast => 1,
destonly => 1, destonly => 1,
sourceonly => 1, sourceonly => 1,
mss => 1,
); );
%zonetypes = ( 1 => 'firewall', 2 => 'ipv4', 4 => 'bport4', 8 => 'ipsec4', 16 => 'vserver' ); %zonetypes = ( 1 => 'firewall', 2 => 'ipv4', 4 => 'bport4', 8 => 'ipsec4', 16 => 'vserver' );
} else { } else {
%validinterfaceoptions = ( blacklist => SIMPLE_IF_OPTION + IF_OPTION_HOST, %validinterfaceoptions = ( blacklist => SIMPLE_IF_OPTION + IF_OPTION_HOST,
bridge => SIMPLE_IF_OPTION, bridge => SIMPLE_IF_OPTION,
dhcp => SIMPLE_IF_OPTION, dhcp => SIMPLE_IF_OPTION,
ignore => NUMERIC_IF_OPTION + IF_OPTION_WILDOK,
maclist => SIMPLE_IF_OPTION + IF_OPTION_HOST, maclist => SIMPLE_IF_OPTION + IF_OPTION_HOST,
nets => IPLIST_IF_OPTION + IF_OPTION_ZONEONLY + IF_OPTION_VSERVER, nets => IPLIST_IF_OPTION + IF_OPTION_ZONEONLY + IF_OPTION_VSERVER,
nosmurfs => SIMPLE_IF_OPTION + IF_OPTION_HOST, nosmurfs => SIMPLE_IF_OPTION + IF_OPTION_HOST,
@@ -345,7 +316,6 @@ sub initialize( $$ ) {
maclist => 1, maclist => 1,
routeback => 1, routeback => 1,
tcpflags => 1, tcpflags => 1,
mss => 1,
); );
%zonetypes = ( 1 => 'firewall', 2 => 'ipv6', 4 => 'bport6', 8 => 'ipsec4', 16 => 'vserver' ); %zonetypes = ( 1 => 'firewall', 2 => 'ipv6', 4 => 'bport6', 8 => 'ipsec4', 16 => 'vserver' );
} }
@@ -359,6 +329,25 @@ sub initialize( $$ ) {
# #
sub parse_zone_option_list($$\$$) sub parse_zone_option_list($$\$$)
{ {
my %validoptions = ( mss => NUMERIC,
nomark => NOTHING,
blacklist => NOTHING,
strict => NOTHING,
next => NOTHING,
reqid => NUMERIC,
spi => NUMERIC,
proto => IPSECPROTO,
mode => IPSECMODE,
"tunnel-src" => NETWORK,
"tunnel-dst" => NETWORK,
);
use constant { UNRESTRICTED => 1, NOFW => 2 , COMPLEX => 8, IN_OUT_ONLY => 16 };
#
# Hash of options that have their own key in the returned hash.
#
my %key = ( mss => UNRESTRICTED | COMPLEX , blacklist => NOFW, nomark => NOFW | IN_OUT_ONLY );
my ( $list, $zonetype, $complexref, $column ) = @_; my ( $list, $zonetype, $complexref, $column ) = @_;
my %h; my %h;
my $options = ''; my $options = '';
@@ -378,7 +367,7 @@ sub parse_zone_option_list($$\$$)
$e = $1; $e = $1;
} }
$fmt = $validzoneoptions{$e}; $fmt = $validoptions{$e};
fatal_error "Invalid Option ($e)" unless $fmt; fatal_error "Invalid Option ($e)" unless $fmt;
@@ -389,7 +378,7 @@ sub parse_zone_option_list($$\$$)
fatal_error "Invalid value ($val) for option \"$e\"" unless $val =~ /^($fmt)$/; fatal_error "Invalid value ($val) for option \"$e\"" unless $val =~ /^($fmt)$/;
} }
my $key = $zonekey{$e}; my $key = $key{$e};
if ( $key ) { if ( $key ) {
fatal_error "Option '$e' not permitted with this zone type " if $key & NOFW && ($zonetype & ( FIREWALL | VSERVER) ); fatal_error "Option '$e' not permitted with this zone type " if $key & NOFW && ($zonetype & ( FIREWALL | VSERVER) );
@@ -414,13 +403,13 @@ sub parse_zone_option_list($$\$$)
# #
# Set the super option on the passed zoneref and propagate to its parents # Set the super option on the passed zoneref and propagate to its parents
# #
sub set_super( $ ); #required for recursion sub set_super( $ );
sub set_super( $ ) { sub set_super( $ ) {
my $zoneref = shift; my $zoneref = shift;
unless ( $zoneref->{super} ) { unless ( $zoneref->{options}{super} ) {
$zoneref->{super} = 1; $zoneref->{options}{super} = 1;
set_super( $zones{$_} ) for @{$zoneref->{parents}}; set_super( $zones{$_} ) for @{$zoneref->{parents}};
} }
} }
@@ -492,16 +481,16 @@ sub process_zone( \$ ) {
my $complex = 0; my $complex = 0;
my $zoneref = $zones{$zone} = { name => $zone, my $zoneref = $zones{$zone} = { type => $type,
type => $type,
parents => \@parents, parents => \@parents,
bridge => '', bridge => '',
options => { in_out => parse_zone_option_list( $options , $type, $complex , IN_OUT ) , options => { in_out => parse_zone_option_list( $options , $type, $complex , IN_OUT ) ,
in => parse_zone_option_list( $in_options , $type , $complex , IN ) , in => parse_zone_option_list( $in_options , $type , $complex , IN ) ,
out => parse_zone_option_list( $out_options , $type , $complex , OUT ) , out => parse_zone_option_list( $out_options , $type , $complex , OUT ) ,
complex => ( $type & IPSEC || $complex ) ,
nested => @parents > 0 ,
super => 0 ,
} , } ,
super => 0 ,
complex => ( $type & IPSEC || $complex ) ,
interfaces => {} , interfaces => {} ,
children => [] , children => [] ,
hosts => {} hosts => {}
@@ -517,7 +506,7 @@ sub process_zone( \$ ) {
fatal_error "Zone mark overflow - please increase the setting of ZONE_BITS" if $zonemark >= $zonemarklimit; fatal_error "Zone mark overflow - please increase the setting of ZONE_BITS" if $zonemark >= $zonemarklimit;
$mark = $zonemark; $mark = $zonemark;
$zonemark += $zonemarkincr; $zonemark += $zonemarkincr;
$zoneref->{complex} = 1; $zoneref->{options}{complex} = 1;
} }
} }
@@ -527,6 +516,7 @@ sub process_zone( \$ ) {
progress_message_nocompress " Zone $zone:\tmark value " . in_hex( $zoneref->{mark} = $mark ); progress_message_nocompress " Zone $zone:\tmark value " . in_hex( $zoneref->{mark} = $mark );
} }
} }
if ( $zoneref->{options}{in_out}{blacklist} ) { if ( $zoneref->{options}{in_out}{blacklist} ) {
for ( qw/in out/ ) { for ( qw/in out/ ) {
@@ -555,7 +545,7 @@ sub determine_zones()
if ( my $fn = open_file 'zones' ) { if ( my $fn = open_file 'zones' ) {
first_entry "$doing $fn..."; first_entry "$doing $fn...";
push @z, process_zone( $ip ) while read_a_line( NORMAL_READ ); push @z, process_zone( $ip ) while read_a_line;
} else { } else {
fatal_error q(The 'zones' file does not exist or has zero size); fatal_error q(The 'zones' file does not exist or has zero size);
} }
@@ -575,7 +565,6 @@ sub determine_zones()
for ( @{$zones{$zone}{children}} ) { for ( @{$zones{$zone}{children}} ) {
next ZONE unless $ordered{$_}; next ZONE unless $ordered{$_};
} }
$ordered{$zone} = 1; $ordered{$zone} = 1;
push @zones, $zone; push @zones, $zone;
redo PUSHED; redo PUSHED;
@@ -583,7 +572,7 @@ sub determine_zones()
} }
} }
assert( @zones == @z ); assert( scalar @zones == scalar @z );
} }
@@ -722,7 +711,7 @@ sub add_group_to_zone($$$$$)
my $interfaceref; my $interfaceref;
my $zoneref = $zones{$zone}; my $zoneref = $zones{$zone};
my $zonetype = $zoneref->{type}; my $zonetype = $zoneref->{type};
$zoneref->{interfaces}{$interface} = 1; $zoneref->{interfaces}{$interface} = 1;
@@ -780,24 +769,20 @@ sub add_group_to_zone($$$$$)
my $gtype = $type & IPSEC ? 'ipsec' : 'ip'; my $gtype = $type & IPSEC ? 'ipsec' : 'ip';
$hostsref = ( $zoneref->{hosts} ||= {} ); $hostsref = ( $zoneref->{hosts} || ( $zoneref->{hosts} = {} ) );
$typeref = ( $hostsref->{$gtype} ||= {} ); $typeref = ( $hostsref->{$gtype} || ( $hostsref->{$gtype} = {} ) );
$interfaceref = ( $typeref->{$interface} ||= [] ); $interfaceref = ( $typeref->{$interface} || ( $typeref->{$interface} = [] ) );
fatal_error "Duplicate Host Group ($interface:" . ALLIP . ") in zone $zone" if $allip && @$interfaceref; fatal_error "Duplicate Host Group ($interface:" . ALLIP . ") in zone $zone" if $allip && @$interfaceref;
$zoneref->{complex} = 1 if @$interfaceref || @newnetworks > 1 || @exclusions || $options->{routeback}; $zoneref->{options}{complex} = 1 if @$interfaceref || ( @newnetworks > 1 ) || ( @exclusions ) || $options->{routeback};
push @{$interfaceref}, { options => $options, push @{$interfaceref}, { options => $options,
hosts => \@newnetworks, hosts => \@newnetworks,
ipsec => $type & IPSEC ? 'ipsec' : 'none' , ipsec => $type & IPSEC ? 'ipsec' : 'none' ,
exclusions => \@exclusions }; exclusions => \@exclusions };
if ( $type != IPSEC ) { $interfaces{$interface}{options}{routeback} ||= ( $type != IPSEC && $options->{routeback} );
my $optref = $interfaces{$interface}{options};
$optref->{routeback} ||= $options->{routeback};
$optref->{allip} ||= $allip;
}
} }
# #
@@ -853,7 +838,7 @@ sub all_parent_zones() {
} }
sub complex_zones() { sub complex_zones() {
grep( $zones{$_}{complex} , @zones ); grep( $zones{$_}{options}{complex} , @zones );
} }
sub vserver_zones() { sub vserver_zones() {
@@ -927,26 +912,9 @@ sub process_interface( $$ ) {
my ( $nextinum, $export ) = @_; my ( $nextinum, $export ) = @_;
my $netsref = ''; my $netsref = '';
my $filterref = []; my $filterref = [];
my ($zone, $originalinterface, $bcasts, $options ); my ($zone, $originalinterface, $bcasts, $options ) = split_line 'interfaces file', { zone => 0, interface => 1, broadcast => 2, options => 3 };
my $zoneref; my $zoneref;
my $bridge = ''; my $bridge = '';
our $format;
if ( $format == 1 ) {
($zone, $originalinterface, $bcasts, $options ) = split_line1 'interfaces file', { zone => 0, interface => 1, broadcast => 2, options => 3 }, { COMMENT => 0, FORMAT => 2 };
} else {
($zone, $originalinterface, $options ) = split_line1 'interfaces file', { zone => 0, interface => 1, options => 2 }, { COMMENT => 0, FORMAT => 2 };
$bcasts = '-';
}
if ( $zone eq 'FORMAT' ) {
if ( $originalinterface =~ /^([12])$/ ) {
$format = $1;
return;
}
fatal_error "Invalid FORMAT ($originalinterface)";
}
if ( $zone eq '-' ) { if ( $zone eq '-' ) {
$zone = ''; $zone = '';
@@ -1003,7 +971,7 @@ sub process_interface( $$ ) {
$root = substr( $interface, 0, -1 ); $root = substr( $interface, 0, -1 );
$roots{$root} = $interface; $roots{$root} = $interface;
my $len = length $root; my $len = length $root;
if ( $minroot ) { if ( $minroot ) {
$minroot = $len if $minroot > $len; $minroot = $len if $minroot > $len;
} else { } else {
@@ -1040,7 +1008,7 @@ sub process_interface( $$ ) {
if ( $options eq 'ignore' ) { if ( $options eq 'ignore' ) {
fatal_error "Ignored interfaces may not be associated with a zone" if $zone; fatal_error "Ignored interfaces may not be associated with a zone" if $zone;
$options{ignore} = NO_UPDOWN | NO_SFILTER; $options{ignore} = 1;
$options = '-'; $options = '-';
} }
@@ -1101,7 +1069,7 @@ sub process_interface( $$ ) {
assert( 0 ); assert( 0 );
} }
} elsif ( $type == NUMERIC_IF_OPTION ) { } elsif ( $type == NUMERIC_IF_OPTION ) {
fatal_error "The '$option' option may not be specified on a wildcard interface" if $wildcard && ! $type && IF_OPTION_WILDOK; fatal_error "The '$option' option may not be specified on a wildcard interface" if $wildcard && ! $type && IF_OPTION_WILDOK;
$value = $defaultinterfaceoptions{$option} unless defined $value; $value = $defaultinterfaceoptions{$option} unless defined $value;
fatal_error "The '$option' option requires a value" unless defined $value; fatal_error "The '$option' option requires a value" unless defined $value;
my $numval = numeric_value $value; my $numval = numeric_value $value;
@@ -1160,16 +1128,7 @@ sub process_interface( $$ ) {
} }
} }
fatal_error "Invalid combination of interface options" fatal_error "Invalid combination of interface options" if $options{required} && $options{optional};
if ( ( $options{required} && $options{optional} ) ||
( $options{required} && $options{ignore} ) ||
( $options{optional} && $options{ignore} ) );
if ( supplied( my $ignore = $options{ignore} ) ) {
fatal_error "Invalid value ignore=0" if ! $ignore;
} else {
$options{ignore} = 0;
}
if ( $netsref eq 'dynamic' ) { if ( $netsref eq 'dynamic' ) {
my $ipset = $family == F_IPV4 ? "${zone}_" . chain_base $physical : "6_${zone}_" . chain_base $physical; my $ipset = $family == F_IPV4 ? "${zone}_" . chain_base $physical : "6_${zone}_" . chain_base $physical;
@@ -1191,10 +1150,6 @@ sub process_interface( $$ ) {
# No options specified -- auto-detect bridge # No options specified -- auto-detect bridge
# #
$hostoptionsref->{routeback} = $options{routeback} = is_a_bridge( $physical ) unless $export; $hostoptionsref->{routeback} = $options{routeback} = is_a_bridge( $physical ) unless $export;
#
# And give the 'ignore' option a defined value
#
$options{ignore} ||= 0;
} }
$physical{$physical} = $interfaces{$interface} = { name => $interface , $physical{$physical} = $interfaces{$interface} = { name => $interface ,
@@ -1230,15 +1185,14 @@ sub process_interface( $$ ) {
# Parse the interfaces file. # Parse the interfaces file.
# #
sub validate_interfaces_file( $ ) { sub validate_interfaces_file( $ ) {
my $export = shift; my $export = shift;
our $format = 1;
my @ifaces; my @ifaces;
my $nextinum = 1; my $nextinum = 1;
if ( my $fn = open_file 'interfaces' ) { if ( my $fn = open_file 'interfaces' ) {
first_entry "$doing $fn..."; first_entry "$doing $fn...";
push @ifaces, process_interface( $nextinum++, $export ) while read_a_line( NORMAL_READ ); push @ifaces, process_interface( $nextinum++, $export ) while read_a_line;
} else { } else {
fatal_error q(The 'interfaces' file does not exist or has zero size); fatal_error q(The 'interfaces' file does not exist or has zero size);
} }
@@ -1321,7 +1275,7 @@ sub known_interface($)
if ( $minroot ) { if ( $minroot ) {
while ( length $iface > $minroot ) { while ( length $iface > $minroot ) {
chop $iface; chop $iface;
if ( my $i = $roots{$iface} ) { if ( my $i = $roots{$iface} ) {
$interfaceref = $interfaces{$i}; $interfaceref = $interfaces{$i};
@@ -1397,7 +1351,7 @@ sub physical_name( $ ) {
$devref ? $devref->{physical} : $device; $devref ? $devref->{physical} : $device;
} }
# #
# Returns true if there are bridge port zones defined in the config # Returns true if there are bridge port zones defined in the config
# #
@@ -1440,65 +1394,11 @@ sub interface_is_optional($) {
$optionsref && $optionsref->{optional}; $optionsref && $optionsref->{optional};
} }
#
# Return the 'required' setting of the passed interface
#
sub interface_is_required($) {
my $optionsref = $interfaces{$_[0]}{options};
$optionsref && $optionsref->{required};
}
#
# Return true if the interface is 'plain'
#
sub interface_is_plain($) {
my $interfaceref = $interfaces{$_[0]};
my $optionsref = $interfaceref->{options};
$interfaceref->{bridge} eq $interfaceref->{name} && ! ( $optionsref && ( $optionsref->{required} || $optionsref->{optional} || $optionsref->{ignore} ) )
}
#
# Return a minimal list of physical interfaces that are neither ignored, optional, required nor a bridge port.
#
sub all_plain_interfaces() {
my @plain1 = map get_physical($_), grep $_ ne '%vserver%' && interface_is_plain( $_ ), @interfaces;
my @plain2;
my @wild1;
my @wild2;
for ( @plain1 ) {
if ( /\+$/ ) {
return ( '+' ) if $_ eq '+';
push @wild1, $_;
chop;
push @wild2, $_;
} else {
push @plain2, $_;
}
}
return @plain2 unless @wild1;
@plain1 = ();
NAME:
for my $name ( @plain2) {
for ( @wild2 ) {
next NAME if substr( $name, 0, length( $_ ) ) eq $_;
}
push @plain1, $name;
}
( @plain1, @wild1 );
}
# #
# Returns reference to array of interfaces with the passed option # Returns reference to array of interfaces with the passed option
# #
sub find_interfaces_by_option( $;$ ) { sub find_interfaces_by_option( $ ) {
my ( $option , $nonzero ) = @_; my $option = $_[0];
my @ints = (); my @ints = ();
for my $interface ( @interfaces ) { for my $interface ( @interfaces ) {
@@ -1507,11 +1407,7 @@ sub find_interfaces_by_option( $;$ ) {
next unless $interfaceref->{root}; next unless $interfaceref->{root};
my $optionsref = $interfaceref->{options}; my $optionsref = $interfaceref->{options};
if ( $nonzero ) { if ( $optionsref && defined $optionsref->{$option} ) {
if ( $optionsref && $optionsref->{$option} ) {
push @ints , $interface
}
} elsif ( $optionsref && defined $optionsref->{$option} ) {
push @ints , $interface push @ints , $interface
} }
} }
@@ -1561,7 +1457,7 @@ sub get_interface_option( $$ ) {
assert( $ref = known_interface( $interface ) ); assert( $ref = known_interface( $interface ) );
$ref->{options}{$option}; $ref->{options}{$option};
} }
# #
@@ -1622,16 +1518,16 @@ sub verify_required_interfaces( $ ) {
my $physical = get_physical $interface; my $physical = get_physical $interface;
if ( $physical =~ /\+$/ ) { if ( $physical =~ /\+$/ ) {
my $base = uc chain_base $physical;
$physical =~ s/\+$/*/; $physical =~ s/\+$/*/;
emit( "waittime=$wait", emit( 'for interface in $(find_all_interfaces); do',
'',
'for interface in $(find_all_interfaces); do',
' case $interface in', ' case $interface in',
" $physical)", " $physical)",
" waittime=$wait",
' while [ $waittime -gt 0 ]; do', ' while [ $waittime -gt 0 ]; do',
' interface_is_usable $interface && break', ' interface_is_usable $interface && break',
' sleep 1',
' waittime=$(($waittime - 1))', ' waittime=$(($waittime - 1))',
' done', ' done',
' ;;', ' ;;',
@@ -1644,8 +1540,8 @@ sub verify_required_interfaces( $ ) {
emit qq( waittime=$wait); emit qq( waittime=$wait);
emit ''; emit '';
emit q( while [ $waittime -gt 0 ]; do); emit q( while [ $waittime -gt 0 ]; do);
emit q( sleep 1);
emit qq( interface_is_usable $physical && break); emit qq( interface_is_usable $physical && break);
emit q( sleep 1);
emit ' waittime=$(($waittime - 1))'; emit ' waittime=$(($waittime - 1))';
emit q( done); emit q( done);
emit q(fi); emit q(fi);
@@ -1716,12 +1612,181 @@ sub verify_required_interfaces( $ ) {
$returnvalue; $returnvalue;
} }
#
# Emit the updown() function
#
sub compile_updown() {
emit( '',
'#',
'# Handle the "up" and "down" commands',
'#',
'updown() # $1 = interface',
'{',
);
push_indent;
emit( 'local state',
'state=cleared',
'' );
emit 'progress_message3 "$g_product $COMMAND triggered by $1"';
emit '';
if ( $family == F_IPV4 ) {
emit 'if shorewall_is_started; then';
} else {
emit 'if shorewall6_is_started; then';
}
emit( ' state=started',
'elif [ -f ${VARDIR}/state ]; then',
' case "$(cat ${VARDIR}/state)" in',
' Stopped*)',
' state=stopped',
' ;;',
' Cleared*)',
' ;;',
' *)',
' state=unknown',
' ;;',
' esac',
'else',
' state=unknown',
'fi',
''
);
emit( 'case $1 in' );
push_indent;
my $ignore = find_interfaces_by_option 'ignore';
my $required = find_interfaces_by_option 'required';
my $optional = find_interfaces_by_option 'optional';
if ( @$ignore ) {
my $interfaces = join '|', map $interfaces{$_}->{physical}, @$ignore;
$interfaces =~ s/\+/*/g;
emit( "$interfaces)",
' progress_message3 "$COMMAND on interface $1 ignored"',
' exit 0',
' ;;'
);
}
if ( @$required ) {
my $interfaces = join '|', map $interfaces{$_}->{physical}, @$required;
my $wildcard = ( $interfaces =~ s/\+/*/g );
emit( "$interfaces)",
' if [ "$COMMAND" = up ]; then' );
if ( $wildcard ) {
emit( ' if [ "$state" = started ]; then',
' COMMAND=restart',
' else',
' COMMAND=start',
' fi' );
} else {
emit( ' COMMAND=start' );
}
emit( ' progress_message3 "$g_product attempting $COMMAND"',
' detect_configuration',
' define_firewall' );
if ( $wildcard ) {
emit( ' elif [ "$state" = started ]; then',
' progress_message3 "$g_product attempting restart"',
' COMMAND=restart',
' detect_configuration',
' define_firewall' );
} else {
emit( ' else',
' COMMAND=stop',
' progress_message3 "$g_product attempting stop"',
' detect_configuration',
' stop_firewall' );
}
emit( ' fi',
' ;;'
);
}
if ( @$optional ) {
my @interfaces = map $interfaces{$_}->{physical}, @$optional;
my $interfaces = join '|', @interfaces;
if ( $interfaces =~ s/\+/*/g || @interfaces > 1 ) {
emit( "$interfaces)",
' if [ "$COMMAND" = up ]; then',
' echo 0 > ${VARDIR}/${1}.state',
' else',
' echo 1 > ${VARDIR}/${1}.state',
' fi' );
} else {
emit( "$interfaces)",
' if [ "$COMMAND" = up ]; then',
" echo 0 > \${VARDIR}/$interfaces.state",
' else',
" echo 1 > \${VARDIR}/$interfaces.state",
' fi' );
}
emit( '',
' if [ "$state" = started ]; then',
' COMMAND=restart',
' progress_message3 "$g_product attempting restart"',
' detect_configuration',
' define_firewall',
' elif [ "$state" = stopped ]; then',
' COMMAND=start',
' progress_message3 "$g_product attempting start"',
' detect_configuration',
' define_firewall',
' else',
' progress_message3 "$COMMAND on interface $1 ignored"',
' fi',
' ;;',
);
}
emit( "*)",
' case $state in',
' started)',
' COMMAND=restart',
' progress_message3 "$g_product attempting restart"',
' detect_configuration',
' define_firewall',
' ;;',
' *)',
' progress_message3 "$COMMAND on interface $1 ignored"',
' ;;',
' esac',
);
pop_indent;
emit( 'esac' );
pop_indent;
emit( '}',
'',
);
}
# #
# Process a record in the hosts file # Process a record in the hosts file
# #
sub process_host( ) { sub process_host( ) {
my $ipsec = 0; my $ipsec = 0;
my ($zone, $hosts, $options ) = split_line1 'hosts file', { zone => 0, host => 1, hosts => 1, options => 2 }, {}, 3; my ($zone, $hosts, $options ) = split_line 'hosts file', { zone => 0, hosts => 1, options => 2 };
fatal_error 'ZONE must be specified' if $zone eq '-'; fatal_error 'ZONE must be specified' if $zone eq '-';
fatal_error 'HOSTS must be specified' if $hosts eq '-'; fatal_error 'HOSTS must be specified' if $hosts eq '-';
@@ -1751,11 +1816,11 @@ sub process_host( ) {
fatal_error "Unknown interface ($interface)" unless ($interfaceref = $interfaces{$interface}) && $interfaceref->{root}; fatal_error "Unknown interface ($interface)" unless ($interfaceref = $interfaces{$interface}) && $interfaceref->{root};
} else { } else {
fatal_error "Invalid HOST(S) column contents: $hosts" fatal_error "Invalid HOST(S) column contents: $hosts"
} }
if ( $hosts =~ /^!?\+/ ) { if ( $hosts =~ /^!?\+/ ) {
$zoneref->{complex} = 1; $zoneref->{options}{complex} = 1;
fatal_error "ipset name qualification is disallowed in this file" if $hosts =~ /[\[\]]/; fatal_error "ipset name qualification is disallowed in this file" if $hosts =~ /[\[\]]/;
fatal_error "Invalid ipset name ($hosts)" unless $hosts =~ /^!?\+[a-zA-Z][-\w]*$/; fatal_error "Invalid ipset name ($hosts)" unless $hosts =~ /^!?\+[a-zA-Z][-\w]*$/;
} }
@@ -1779,16 +1844,12 @@ sub process_host( ) {
if ( $option eq 'ipsec' ) { if ( $option eq 'ipsec' ) {
require_capability 'POLICY_MATCH' , q(The 'ipsec' option), 's'; require_capability 'POLICY_MATCH' , q(The 'ipsec' option), 's';
$type = IPSEC; $type = IPSEC;
$zoneref->{complex} = 1; $zoneref->{options}{complex} = 1;
$ipsec = $interfaceref->{ipsec} = 1; $ipsec = $interfaceref->{ipsec} = 1;
} elsif ( $option eq 'norfc1918' ) { } elsif ( $option eq 'norfc1918' ) {
warning_message "The 'norfc1918' host option is no longer supported" warning_message "The 'norfc1918' host option is no longer supported"
} elsif ( $option eq 'blacklist' ) { } elsif ( $option eq 'blacklist' ) {
$zoneref->{options}{in}{blacklist} = 1; $zoneref->{options}{in}{blacklist} = 1;
} elsif ( $option =~ /^mss=(\d+)$/ ) {
fatal_error "Invalid mss ($1)" unless $1 >= 500;
$options{mss} = $1;
$zoneref->{options}{complex} = 1;
} elsif ( $validhostoptions{$option}) { } elsif ( $validhostoptions{$option}) {
fatal_error qq(The "$option" option is not allowed with Vserver zones) if $type & VSERVER && ! ( $validhostoptions{$option} & IF_OPTION_VSERVER ); fatal_error qq(The "$option" option is not allowed with Vserver zones) if $type & VSERVER && ! ( $validhostoptions{$option} & IF_OPTION_VSERVER );
$options{$option} = 1; $options{$option} = 1;
@@ -1848,12 +1909,13 @@ sub validate_hosts_file()
if ( my $fn = open_file 'hosts' ) { if ( my $fn = open_file 'hosts' ) {
first_entry "$doing $fn..."; first_entry "$doing $fn...";
$ipsec |= process_host while read_a_line( NORMAL_READ ); $ipsec |= process_host while read_a_line;
} }
$have_ipsec = $ipsec || haveipseczones; $have_ipsec = $ipsec || haveipseczones;
$_->{complex} ||= ( keys %{$_->{interfaces}} > 1 ) for values %zones; $_->{options}{complex} ||= ( keys %{$_->{interfaces}} > 1 ) for values %zones;
} }
# #
@@ -1865,7 +1927,7 @@ sub have_ipsec() {
# #
# Returns a reference to a array of host entries. Each entry is a # Returns a reference to a array of host entries. Each entry is a
# reference to an array containing ( interface , polciy match type {ipsec|none} , network , exclusions, value ); # reference to an array containing ( interface , polciy match type {ipsec|none} , network , exclusions );
# #
sub find_hosts_by_option( $ ) { sub find_hosts_by_option( $ ) {
my $option = $_[0]; my $option = $_[0];
@@ -1875,9 +1937,9 @@ sub find_hosts_by_option( $ ) {
while ( my ($type, $interfaceref) = each %{$zones{$zone}{hosts}} ) { while ( my ($type, $interfaceref) = each %{$zones{$zone}{hosts}} ) {
while ( my ( $interface, $arrayref) = ( each %{$interfaceref} ) ) { while ( my ( $interface, $arrayref) = ( each %{$interfaceref} ) ) {
for my $host ( @{$arrayref} ) { for my $host ( @{$arrayref} ) {
if ( my $value = $host->{options}{$option} ) { if ( $host->{options}{$option} ) {
for my $net ( @{$host->{hosts}} ) { for my $net ( @{$host->{hosts}} ) {
push @hosts, [ $interface, $host->{ipsec} , $net , $host->{exclusions}, $value ]; push @hosts, [ $interface, $host->{ipsec} , $net , $host->{exclusions}];
} }
} }
} }
@@ -1894,30 +1956,6 @@ sub find_hosts_by_option( $ ) {
\@hosts; \@hosts;
} }
#
# As above but for a single zone
#
sub find_zone_hosts_by_option( $$ ) {
my ($zone, $option ) = @_;
my @hosts;
unless ( $zones{$zone}{type} & FIREWALL ) {
while ( my ($type, $interfaceref) = each %{$zones{$zone}{hosts}} ) {
while ( my ( $interface, $arrayref) = ( each %{$interfaceref} ) ) {
for my $host ( @{$arrayref} ) {
if ( my $value = $host->{options}{$option} ) {
for my $net ( @{$host->{hosts}} ) {
push @hosts, [ $interface, $host->{ipsec} , $net , $host->{exclusions}, $value ];
}
}
}
}
}
}
\@hosts;
}
# #
# Returns a reference to a list of zones with the passed in/out option # Returns a reference to a list of zones with the passed in/out option
# #

View File

@@ -37,7 +37,6 @@
# --log_verbosity=<number> # Log Verbosity range -1 to 2 # --log_verbosity=<number> # Log Verbosity range -1 to 2
# --family=<number> # IP family; 4 = IPv4 (default), 6 = IPv6 # --family=<number> # IP family; 4 = IPv4 (default), 6 = IPv6
# --preview # Preview the ruleset. # --preview # Preview the ruleset.
# --shorewallrc=<path> # Path to shorewallrc file.
# --config_path=<path-list> # Search path for config files # --config_path=<path-list> # Search path for config files
# #
use strict; use strict;
@@ -66,7 +65,6 @@ sub usage( $ ) {
[ --annotate ] [ --annotate ]
[ --update ] [ --update ]
[ --convert ] [ --convert ]
[ --shorewallrc=<pathname> ]
[ --config_path=<path-list> ] [ --config_path=<path-list> ]
'; ';
@@ -93,7 +91,6 @@ my $annotate = 0;
my $update = 0; my $update = 0;
my $convert = 0; my $convert = 0;
my $config_path = ''; my $config_path = '';
my $shorewallrc = '';
Getopt::Long::Configure ('bundling'); Getopt::Long::Configure ('bundling');
@@ -125,7 +122,6 @@ my $result = GetOptions('h' => \$help,
'update' => \$update, 'update' => \$update,
'convert' => \$convert, 'convert' => \$convert,
'config_path=s' => \$config_path, 'config_path=s' => \$config_path,
'shorewallrc=s' => \$shorewallrc,
); );
usage(1) unless $result && @ARGV < 2; usage(1) unless $result && @ARGV < 2;
@@ -148,5 +144,4 @@ compiler( script => $ARGV[0] || '',
convert => $convert, convert => $convert,
annotate => $annotate, annotate => $annotate,
config_path => $config_path, config_path => $config_path,
shorewallrc => $shorewallrc
); );

View File

@@ -33,19 +33,7 @@ else
g_program=shorewall g_program=shorewall
fi fi
# . /usr/share/shorewall/lib.cli
# This is modified by the installer when ${SHAREDIR} != /usr/share
#
. /usr/share/shorewall/shorewallrc
g_libexec="$LIBEXECDIR"
g_sharedir="$SHAREDIR"/shorewall
g_sbindir="$SBINDIR"
g_perllib="$PERLLIBDIR"
g_confdir="$CONFDIR"/shorewall
g_readrc=1
. $g_sharedir/lib.cli
CONFIG_PATH="$2" CONFIG_PATH="$2"

File diff suppressed because it is too large Load Diff

View File

@@ -38,7 +38,7 @@ checkkernelversion() {
if [ $g_family -eq 6 ]; then if [ $g_family -eq 6 ]; then
kernel=$(uname -r 2> /dev/null | sed -e 's/-.*//') kernel=$(uname -r 2> /dev/null | sed -e 's/-.*//')
case "$kernel" in case "$kernel" in
*.*.*) *.*.*)
kernel=$(printf "%d%02d%02d" $(echo $kernel | sed -e 's/^\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/\1 \2 \3/g')) kernel=$(printf "%d%02d%02d" $(echo $kernel | sed -e 's/^\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/\1 \2 \3/g'))
;; ;;
@@ -62,14 +62,12 @@ checkkernelversion() {
# #
# Start trace if first arg is "debug" or "trace" # Start trace if first arg is "debug" or "trace"
# #
g_debug_iptables=
if [ $# -gt 1 ]; then if [ $# -gt 1 ]; then
if [ "x$1" = "xtrace" ]; then if [ "x$1" = "xtrace" ]; then
set -x set -x
shift shift
elif [ "x$1" = "xdebug" ]; then elif [ "x$1" = "xdebug" ]; then
g_debug_iptables=Yes DEBUG=Yes
shift shift
fi fi
fi fi
@@ -235,8 +233,8 @@ case "$COMMAND" in
status=2 status=2
elif checkkernelversion; then elif checkkernelversion; then
if [ $# -eq 1 ]; then if [ $# -eq 1 ]; then
$g_tool -Z $IP6TABLES -Z
$g_tool -t mangle -Z $IP6TABLES -t mangle -Z
date > ${VARDIR}/restarted date > ${VARDIR}/restarted
status=0 status=0
progress_message3 "$g_product Counters Reset" progress_message3 "$g_product Counters Reset"
@@ -245,7 +243,7 @@ case "$COMMAND" in
status=0 status=0
for chain in $@; do for chain in $@; do
if chain_exists $chain; then if chain_exists $chain; then
if qt $g_tool-Z $chain; then if qt $IP6TABLES -Z $chain; then
progress_message3 "Filter $chain Counters Reset" progress_message3 "Filter $chain Counters Reset"
else else
error_message "ERROR: Reset of chain $chain failed" error_message "ERROR: Reset of chain $chain failed"
@@ -348,9 +346,7 @@ case "$COMMAND" in
[ $# -eq 1 ] && exit 0 [ $# -eq 1 ] && exit 0
shift shift
[ $# -ne 1 ] && usage 2 [ $# -ne 1 ] && usage 2
mutex_on updown $1
( updown $1 )
mutex_off
status=0 status=0
;; ;;
enable) enable)

402
Shorewall/Perl/prog.header Normal file
View File

@@ -0,0 +1,402 @@
# This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt]
#
# (c) 1999-2011 - Tom Eastep (teastep@shorewall.net)
#
# Options are:
#
# -n Don't alter Routing
# -v and -q Standard Shorewall Verbosity control
# -t Timestamp progress messages
# -p Purge conntrack table
# -r Recover from failed start/restart
# -V <verbosity> Set verbosity level explicitly
# -R <restore> Overrides RESTOREFILE setting
#
# Commands are:
#
# start Starts the firewall
# refresh Refresh the firewall
# restart Restarts the firewall
# reload Reload the firewall
# clear Removes all firewall rules
# stop Stops the firewall
# status Displays firewall status
# version Displays the version of Shorewall that
# generated this program
#
################################################################################
# Functions imported from /usr/share/shorewall/prog.header
################################################################################
#
# Find the value 'weight' in the passed arguments then echo the next value
#
find_weight() {
while [ $# -gt 1 ]; do
[ "x$1" = xweight ] && echo $2 && return
shift
done
}
#
# Find the interfaces that have a route to the passed address - the default
# route is not used.
#
find_rt_interface() {
$IP -4 route list | while read addr rest; do
case $addr in
*/*)
in_network ${1%/*} $addr && echo $(find_device $rest)
;;
default)
;;
*)
if [ "$addr" = "$1" -o "$addr/32" = "$1" ]; then
echo $(find_device $rest)
fi
;;
esac
done
}
#
# Echo the name of the interface(s) that will be used to send to the
# passed address
#
find_interface_by_address() {
local dev
dev="$(find_rt_interface $1)"
local first
local rest
[ -z "$dev" ] && dev=$(find_default_interface)
[ -n "$dev" ] && echo $dev
}
#
# echo the list of networks routed out of a given interface
#
get_routed_networks() # $1 = interface name, $2-n = Fatal error message
{
local address
local rest
$IP -4 route show dev $1 2> /dev/null |
while read address rest; do
case "$address" in
default)
if [ $# -gt 1 ]; then
shift
fatal_error "$@"
else
echo "WARNING: default route ignored on interface $1" >&2
fi
;;
multicast|broadcast|prohibit|nat|throw|nexthop)
;;
*)
[ "$address" = "${address%/*}" ] && address="${address}/32"
echo $address
;;
esac
done
}
#
# Get the broadcast addresses associated with an interface
#
get_interface_bcasts() # $1 = interface
{
local addresses
addresses=
$IP -f inet addr show dev $1 2> /dev/null | grep 'inet.*brd' | sed 's/inet.*brd //; s/scope.*//;' | sort -u
}
#
# Delete IP address
#
del_ip_addr() # $1 = address, $2 = interface
{
[ $(find_first_interface_address_if_any $2) = $1 ] || qtnoin $IP addr del $1 dev $2
}
# Add IP Aliases
#
add_ip_aliases() # $* = List of addresses
{
local local
local addresses
local external
local interface
local inet
local cidr
local rest
local val
local arping
arping=$(mywhich arping)
address_details()
{
#
# Folks feel uneasy if they don't see all of the same
# decoration on these IP addresses that they see when their
# distro's net config tool adds them. In an attempt to reduce
# the anxiety level, we have the following code which sets
# the VLSM and BRD from an existing address in the same networks
#
# Get all of the lines that contain inet addresses with broadcast
#
$IP -f inet addr show $interface 2> /dev/null | grep 'inet.*brd' | while read inet cidr rest ; do
case $cidr in
*/*)
if in_network $external $cidr; then
echo "/${cidr#*/} brd $(broadcastaddress $cidr)"
break
fi
;;
esac
done
}
do_one()
{
val=$(address_details)
$IP addr add ${external}${val} dev $interface $label
[ -n "$arping" ] && qt $arping -U -c 2 -I $interface $external
echo "$external $interface" >> $VARDIR/nat
[ -n "$label" ] && label="with $label"
progress_message " IP Address $external added to interface $interface $label"
}
progress_message "Adding IP Addresses..."
while [ $# -gt 0 ]; do
external=$1
interface=$2
label=
if [ "$interface" != "${interface%:*}" ]; then
label="${interface#*:}"
interface="${interface%:*}"
label="label $interface:$label"
fi
shift 2
list_search $external $(find_interface_addresses $interface) || do_one
done
}
#
# Detect the gateway through a PPP or DHCP-configured interface
#
detect_dynamic_gateway() { # $1 = interface
local interface
interface=$1
local GATEWAYS
GATEWAYS=
local gateway
gateway=$(run_findgw_exit $1);
if [ -z "$gateway" ]; then
gateway=$( find_peer $($IP addr list $interface ) )
fi
if [ -z "$gateway" -a -f /var/lib/dhcpcd/dhcpcd-${1}.info ]; then
eval $(grep ^GATEWAYS= /var/lib/dhcpcd/dhcpcd-${1}.info 2> /dev/null)
[ -n "$GATEWAYS" ] && GATEWAYS=${GATEWAYS%,*} && gateway=$GATEWAYS
fi
if [ -z "$gateway" -a -f /var/lib/dhcp/dhclient-${1}.lease ]; then
gateway=$(grep 'option routers' /var/lib/dhcp/dhclient-${1}.lease | tail -n 1 | while read j1 j2 gateway; do echo $gateway ; return 0; done)
fi
[ -n "$gateway" ] && echo $gateway
}
#
# Detect the gateway through an interface
#
detect_gateway() # $1 = interface
{
local interface
interface=$1
local gateway
#
# First assume that this is some sort of dynamic interface
#
gateway=$( detect_dynamic_gateway $interface )
#
# Maybe there's a default route through this gateway already
#
[ -n "$gateway" ] || gateway=$(find_gateway $($IP -4 route list dev $interface | grep ^default))
#
# Last hope -- is there a load-balancing route through the interface?
#
[ -n "$gateway" ] || gateway=$(find_nexthop $interface)
#
# Be sure we found one
#
[ -n "$gateway" ] && echo $gateway
}
#
# Disable IPV6
#
disable_ipv6() {
local foo
foo="$($IP -f inet6 addr list 2> /dev/null)"
if [ -n "$foo" ]; then
if [ -x "$IP6TABLES" ]; then
$IP6TABLES -P FORWARD DROP
$IP6TABLES -P INPUT DROP
$IP6TABLES -P OUTPUT DROP
$IP6TABLES -F
$IP6TABLES -X
$IP6TABLES -A OUTPUT -o lo -j ACCEPT
$IP6TABLES -A INPUT -i lo -j ACCEPT
else
error_message "WARNING: DISABLE_IPV6=Yes in shorewall.conf but this system does not appear to have ip6tables"
fi
fi
}
#
# Add an additional gateway to the default route
#
add_gateway() # $1 = Delta $2 = Table Number
{
local route
local weight
local delta
local dev
route=`$IP -4 -o route ls table $2 | grep ^default | sed 's/default //; s/[\]//g'`
if [ -z "$route" ]; then
run_ip route add default scope global table $2 $1
else
delta=$1
if ! echo $route | fgrep -q ' nexthop '; then
route=`echo $route | sed 's/via/nexthop via/'`
dev=$(find_device $route)
if [ -f ${VARDIR}/${dev}_weight ]; then
weight=`cat ${VARDIR}/${dev}_weight`
route="$route weight $weight"
fi
fi
run_ip route replace default scope global table $2 $route $delta
fi
}
#
# Remove a gateway from the default route
#
delete_gateway() # $! = Description of the Gateway $2 = table number $3 = device
{
local route
local gateway
local dev
route=`$IP -4 -o route ls table $2 | grep ^default | sed 's/[\]//g'`
gateway=$1
if [ -n "$route" ]; then
if echo $route | fgrep -q ' nexthop '; then
gateway="nexthop $gateway"
eval route=\`echo $route \| sed \'s/$gateway/ /\'\`
run_ip route replace table $2 $route
else
dev=$(find_device $route)
[ "$dev" = "$3" ] && run_ip route delete default table $2
fi
fi
}
#
# Determine the MAC address of the passed IP through the passed interface
#
find_mac() # $1 = IP address, $2 = interface
{
if interface_is_usable $2 ; then
qt ping -nc 1 -t 2 -I $2 $1
local result
result=$($IP neigh list | awk "/^$1 / {print \$5}")
case $result in
\<*\>)
;;
*)
[ -n "$result" ] && echo $result
;;
esac
fi
}
#
# Clear Proxy Arp
#
delete_proxyarp() {
if [ -f ${VARDIR}/proxyarp ]; then
while read address interface external haveroute; do
qtnoin $IP -4 neigh del proxy $address dev $external
[ -z "${haveroute}${g_noroutes}" ] && qtnoin $IP -4 route del $address/32 dev $interface
f=/proc/sys/net/ipv4/conf/$interface/proxy_arp
[ -f $f ] && echo 0 > $f
done < ${VARDIR}/proxyarp
rm -f ${VARDIR}/proxyarp
fi
}
#
# Remove all Shorewall-added rules
#
clear_firewall() {
stop_firewall
setpolicy INPUT ACCEPT
setpolicy FORWARD ACCEPT
setpolicy OUTPUT ACCEPT
run_iptables -F
qt $IPTABLES -t raw -F
echo 1 > /proc/sys/net/ipv4/ip_forward
if [ -n "$DISABLE_IPV6" ]; then
if [ -x $IP6TABLES ]; then
$IP6TABLES -P INPUT ACCEPT 2> /dev/null
$IP6TABLES -P OUTPUT ACCEPT 2> /dev/null
$IP6TABLES -P FORWARD ACCEPT 2> /dev/null
fi
fi
run_clear_exit
set_state "Cleared"
logger -p kern.info "$g_product Cleared"
}
#
# Get a list of all configured broadcast addresses on the system
#
get_all_bcasts()
{
$IP -f inet addr show 2> /dev/null | grep 'inet.*brd' | grep -v '/32 ' | sed 's/inet.*brd //; s/scope.*//;' | sort -u
}
################################################################################
# End of functions in /usr/share/shorewall/prog.header
################################################################################

311
Shorewall/Perl/prog.header6 Normal file
View File

@@ -0,0 +1,311 @@
# This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt]
#
# (c) 1999-2011- Tom Eastep (teastep@shorewall.net)
#
# Options are:
#
# -n Don't alter Routing
# -v and -q Standard Shorewall Verbosity control
# -t Timestamp progress messages
# -p Purge conntrack table
# -r Recover from failed start/restart
# -V <verbosity> Set verbosity level explicitly
# -R <restore> Overrides RESTOREFILE setting
#
# Commands are:
#
# start Starts the firewall
# refresh Refresh the firewall
# restart Restarts the firewall
# reload Reload the firewall
# clear Removes all firewall rules
# stop Stops the firewall
# status Displays firewall status
# version Displays the version of Shorewall that
# generated this program
#
################################################################################
# Functions imported from /usr/share/shorewall/prog.header6
################################################################################
#
# Get all interface addresses with VLSMs
#
find_interface_full_addresses() # $1 = interface
{
$IP -f inet6 addr show $1 2> /dev/null | grep 'inet6 ' | sed 's/\s*inet6 //;s/ scope.*//;s/ peer.*//'
}
#
# Normalize an IPv6 Address by compressing out consecutive zero elements
#
normalize_address() # $1 = valid IPv6 Address
{
local address
address=$1
local j
while true; do
case $address in
::*)
address=0$address
;;
*::*)
list_count $(split $address)
j=$?
if [ $j -eq 7 ]; then
address=${address%::*}:0:${address#*::}
elif [ $j -eq 8 ]; then
$address=${address%::*}:${address#*::}
break 2
else
address=${address%::*}:0::${address#*::}
fi
;;
*)
echo $address
break 2
;;
esac
done
}
#
# Reads correctly-formed and fully-qualified host and subnet addresses from STDIN. For each
# that defines a /120 or larger network, it sends to STDOUT:
#
# The corresponding subnet-router anycast address (all host address bits are zero)
# The corresponding anycast addresses defined by RFC 2526 (the last 128 addresses in the subnet)
#
convert_to_anycast() {
local address
local badress
local vlsm
local host
local o
local m
m=
local z
z=65535
local l
while read address; do
case $address in
2*|3*)
vlsm=${address#*/}
vlsm=${vlsm:=128}
if [ $vlsm -le 120 ]; then
#
# Defines a viable subnet -- first get the subnet-router anycast address
#
host=$((128 - $vlsm))
address=$(normalize_address ${address%/*})
while [ $host -ge 16 ]; do
address=${address%:*}
host=$(($host - 16))
done
if [ $host -gt 0 ]; then
#
# VLSM is not a multiple of 16
#
host=$((16 - $host))
o=$((0x${address##*:}))
m=0
while [ $host -gt 0 ]; do
m=$((($m >> 1) | 0x8000))
z=$(($z >> 1))
host=$(($host - 1))
done
o=$(($o & $m))
badress=${address%:*}
address=$badress:$(printf %04x $o)
z=$(($o | $z))
if [ $vlsm -gt 112 ]; then
z=$(($z & 0xff80))
fi
badress=$badress:$(printf %04x $z)
else
badress=$address
fi
#
# Note: at this point $address and $badress are the same except possibly for
# the contents of the last half-word
#
list_count $(split $address)
l=$?
#
# Now generate the anycast addresses defined by RFC 2526
#
if [ $l -lt 8 ]; then
#
# The subnet-router address
#
echo $address::
while [ $l -lt 8 ]; do
badress=$badress:ffff
l=$(($l + 1 ))
done
else
#
# The subnet-router address
#
echo $address
fi
#
# And the RFC 2526 addresses
#
echo $badress/121
fi
;;
esac
done
}
#
# Generate a list of anycast addresses for a given interface
#
get_interface_acasts() # $1 = interface
{
local addresses
addresses=
find_interface_full_addresses $1 | convert_to_anycast | sort -u
}
#
# Get a list of all configured anycast addresses on the system
#
get_all_acasts()
{
find_interface_full_addresses | convert_to_anycast | sort -u
}
#
# Detect the gateway through an interface
#
detect_gateway() # $1 = interface
{
local interface
interface=$1
#
# First assume that this is some sort of point-to-point interface
#
gateway=$( find_peer $($IP -6 addr list $interface ) )
#
# Maybe there's a default route through this gateway already
#
[ -n "$gateway" ] || gateway=$(find_gateway $($IP -6 route list dev $interface | grep '^default'))
#
# Last hope -- is there a load-balancing route through the interface?
#
[ -n "$gateway" ] || gateway=$(find_nexthop $interface)
#
# Be sure we found one
#
[ -n "$gateway" ] && echo $gateway
}
#
# Add an additional gateway to the default route
#
add_gateway() # $1 = Delta $2 = Table Number
{
local route
local weight
local delta
local dev
run_ip route add default scope global table $2 $1
}
#
# Remove a gateway from the default route
#
delete_gateway() # $! = Description of the Gateway $2 = table number $3 = device
{
local route
local gateway
local dev
route=`$IP -6 -o route ls table $2 | grep ^default | sed 's/[\]//g'`
gateway=$1
dev=$(find_device $route)
[ "$dev" = "$3" ] && run_ip route delete default table $2
}
#
# Determine how to do "echo -e"
#
find_echo() {
local result
result=$(echo "a\tb")
[ ${#result} -eq 3 ] && { echo echo; return; }
result=$(echo -e "a\tb")
[ ${#result} -eq 3 ] && { echo "echo -e"; return; }
result=$(which echo)
[ -n "$result" ] && { echo "$result -e"; return; }
echo echo
}
#
# Clear Proxy NDP
#
delete_proxyndp() {
if [ -f ${VARDIR}/proxyndp ]; then
while read address interface external haveroute; do
qt $IP -6 neigh del proxy $address dev $external
[ -z "${haveroute}${g_noroutes}" ] && qt $IP -6 route del $address/128 dev $interface
f=/proc/sys/net/ipv6/conf/$interface/proxy_ndp
[ -f $f ] && echo 0 > $f
done < ${VARDIR}/proxyndp
rm -f ${VARDIR}/proxyndp
fi
}
#
# Remove all Shorewall-added rules
#
clear_firewall() {
stop_firewall
setpolicy INPUT ACCEPT
setpolicy FORWARD ACCEPT
setpolicy OUTPUT ACCEPT
run_iptables -F
qt $IP6TABLES -t raw -F
echo 1 > /proc/sys/net/ipv6/conf/all/forwarding
run_clear_exit
set_state "Cleared"
logger -p kern.info "$g_product Cleared"
}
################################################################################
# End of functions imported from /usr/share/shorewall/prog.header6
################################################################################

View File

@@ -55,7 +55,7 @@ modified by someone else and passed on, the recipients should know
that what they have is not the original version, so that the original that what they have is not the original version, so that the original
author's reputation will not be affected by problems that might be author's reputation will not be affected by problems that might be
introduced by others. introduced by others.
Finally, software patents pose a constant threat to the existence of Finally, software patents pose a constant threat to the existence of
any free program. We wish to make sure that a company cannot any free program. We wish to make sure that a company cannot
effectively restrict the users of a free program by obtaining a effectively restrict the users of a free program by obtaining a
@@ -111,7 +111,7 @@ modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The "work based on the library" and a "work that uses the library". The
former contains code derived from the library, whereas the latter must former contains code derived from the library, whereas the latter must
be combined with the library in order to run. be combined with the library in order to run.
GNU LESSER GENERAL PUBLIC LICENSE GNU LESSER GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
@@ -146,7 +146,7 @@ such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does. and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's 1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an you conspicuously and appropriately publish on each copy an
@@ -158,7 +158,7 @@ Library.
You may charge a fee for the physical act of transferring a copy, You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a and you may at your option offer warranty protection in exchange for a
fee. fee.
2. You may modify your copy or copies of the Library or any portion 2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1 distribute such modifications or work under the terms of Section 1
@@ -216,7 +216,7 @@ instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in that version instead if you wish.) Do not make any other change in
these notices. these notices.
Once this change is made in a given copy, it is irreversible for Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy. subsequent copies and derivative works made from that copy.
@@ -267,7 +267,7 @@ Library will still fall under Section 6.)
distribute the object code for the work under the terms of Section 6. distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6, Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself. whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also combine or 6. As an exception to the Sections above, you may also combine or
link a "work that uses the Library" with the Library to produce a link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work work containing portions of the Library, and distribute that work
@@ -329,7 +329,7 @@ restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you use both them and the Library together in an executable that you
distribute. distribute.
7. You may place library facilities that are a work based on the 7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined facilities not covered by this License, and distribute such a combined
@@ -370,7 +370,7 @@ subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein. restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties with You are not responsible for enforcing compliance by third parties with
this License. this License.
11. If, as a consequence of a court judgment or allegation of patent 11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues), infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or conditions are imposed on you (whether by court order, agreement or
@@ -422,7 +422,7 @@ conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by license version number, you may choose any version ever published by
the Free Software Foundation. the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free 14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these, programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is write to the author to ask for permission. For software which is
@@ -456,7 +456,7 @@ SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES. DAMAGES.
END OF TERMS AND CONDITIONS END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Libraries How to Apply These Terms to Your New Libraries
If you develop a new library, and you want it to be of the greatest If you develop a new library, and you want it to be of the greatest

View File

@@ -7,8 +7,6 @@
# http://www.shorewall.net/manpages/shorewall-interfaces.html # http://www.shorewall.net/manpages/shorewall-interfaces.html
# #
############################################################################### ###############################################################################
FORMAT 2 #ZONE INTERFACE BROADCAST OPTIONS
############################################################################### - lo - ignore
#ZONE INTERFACE OPTIONS net all - dhcp,physical=+,routeback,optional
- lo ignore
net all dhcp,physical=+,routeback,optional

View File

@@ -13,6 +13,6 @@
#SECTION ESTABLISHED #SECTION ESTABLISHED
#SECTION RELATED #SECTION RELATED
SECTION NEW SECTION NEW
Invalid(DROP) net $FW tcp
SSH(ACCEPT) net $FW SSH(ACCEPT) net $FW
Ping(ACCEPT) net $FW Ping(ACCEPT) net $FW

View File

@@ -53,9 +53,7 @@ TCP_FLAGS_LOG_LEVEL=info
# L O C A T I O N O F F I L E S A N D D I R E C T O R I E S # L O C A T I O N O F F I L E S A N D D I R E C T O R I E S
############################################################################### ###############################################################################
CONFIG_PATH=${CONFDIR}/shorewall:${SHAREDIR}/shorewall CONFIG_PATH=/etc/shorewall:/usr/share/shorewall
GEOIPDIR=/usr/share/xt_geoip/LE
IPTABLES= IPTABLES=
@@ -63,8 +61,6 @@ IP=
IPSET= IPSET=
LOCKFILE=
MODULESDIR= MODULESDIR=
PERL=/usr/bin/perl PERL=/usr/bin/perl
@@ -142,8 +138,6 @@ FORWARD_CLEAR_MARK=
IMPLICIT_CONTINUE=No IMPLICIT_CONTINUE=No
IPSET_WARNINGS=Yes
IP_FORWARDING=On IP_FORWARDING=On
KEEP_RT_TABLES=No KEEP_RT_TABLES=No
@@ -170,7 +164,7 @@ MUTEX_TIMEOUT=60
NULL_ROUTE_RFC1918=No NULL_ROUTE_RFC1918=No
OPTIMIZE=31 OPTIMIZE=15
OPTIMIZE_ACCOUNTING=No OPTIMIZE_ACCOUNTING=No

View File

@@ -11,7 +11,5 @@
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# For information about entries in this file, type "man shorewall-interfaces" # For information about entries in this file, type "man shorewall-interfaces"
############################################################################### ###############################################################################
FORMAT 2 #ZONE INTERFACE BROADCAST OPTIONS
############################################################################### net eth0 detect dhcp,tcpflags,logmartians,nosmurfs
#ZONE INTERFACE OPTIONS
net eth0 dhcp,tcpflags,logmartians,nosmurfs,sourceroute=0

View File

@@ -18,10 +18,6 @@
#SECTION RELATED #SECTION RELATED
SECTION NEW SECTION NEW
# Drop packets in the INVALID state
Invalid(DROP) net $FW tcp
# Drop Ping from the "bad" net zone.. and prevent your log from being flooded.. # Drop Ping from the "bad" net zone.. and prevent your log from being flooded..
Ping(DROP) net $FW Ping(DROP) net $FW

View File

@@ -13,7 +13,7 @@
# #
# For information about the settings in this file, type "man shorewall.conf" # For information about the settings in this file, type "man shorewall.conf"
# #
# The manpage is also online at # The manpage is also online at
# http://shorewall.net/manpages/shorewall.conf.html # http://shorewall.net/manpages/shorewall.conf.html
# #
############################################################################### ###############################################################################
@@ -64,9 +64,7 @@ TCP_FLAGS_LOG_LEVEL=info
# L O C A T I O N O F F I L E S A N D D I R E C T O R I E S # L O C A T I O N O F F I L E S A N D D I R E C T O R I E S
############################################################################### ###############################################################################
CONFIG_PATH=${CONFDIR}/shorewall:${SHAREDIR}/shorewall CONFIG_PATH=/etc/shorewall:/usr/share/shorewall
GEOIPDIR=/usr/share/xt_geoip/LE
IPTABLES= IPTABLES=
@@ -74,8 +72,6 @@ IP=
IPSET= IPSET=
LOCKFILE=
MODULESDIR= MODULESDIR=
PERL=/usr/bin/perl PERL=/usr/bin/perl
@@ -153,8 +149,6 @@ FORWARD_CLEAR_MARK=
IMPLICIT_CONTINUE=No IMPLICIT_CONTINUE=No
IPSET_WARNINGS=Yes
IP_FORWARDING=Off IP_FORWARDING=Off
KEEP_RT_TABLES=No KEEP_RT_TABLES=No
@@ -181,7 +175,7 @@ MUTEX_TIMEOUT=60
NULL_ROUTE_RFC1918=No NULL_ROUTE_RFC1918=No
OPTIMIZE=31 OPTIMIZE=1
OPTIMIZE_ACCOUNTING=No OPTIMIZE_ACCOUNTING=No

View File

@@ -11,9 +11,7 @@
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# For information about entries in this file, type "man shorewall-interfaces" # For information about entries in this file, type "man shorewall-interfaces"
############################################################################### ###############################################################################
FORMAT 2 #ZONE INTERFACE BROADCAST OPTIONS
############################################################################### net eth0 detect tcpflags,dhcp,nosmurfs,routefilter,logmartians
#ZONE INTERFACE OPTIONS loc eth1 detect tcpflags,nosmurfs,routefilter,logmartians
net eth0 tcpflags,dhcp,nosmurfs,routefilter,logmartians,sourceroute=0 dmz eth2 detect tcpflags,nosmurfs,routefilter,logmartians
loc eth1 tcpflags,nosmurfs,routefilter,logmartians
dmz eth2 tcpflags,nosmurfs,routefilter,logmartians

View File

@@ -10,9 +10,8 @@
# See the file README.txt for further details. # See the file README.txt for further details.
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# For information about entries in this file, type "man shorewall-masq" # For information about entries in this file, type "man shorewall-masq"
################################################################################################################ ##############################################################################
#INTERFACE:DEST SOURCE ADDRESS PROTO PORT(S) IPSEC MARK USER/ SWITCH ORIGINAL #INTERFACE SOURCE ADDRESS PROTO PORT(S) IPSEC MARK
# GROUP DEST
eth0 10.0.0.0/8,\ eth0 10.0.0.0/8,\
169.254.0.0/16,\ 169.254.0.0/16,\
172.16.0.0/12,\ 172.16.0.0/12,\

View File

@@ -20,7 +20,7 @@ SECTION NEW
# Don't allow connection pickup from the net # Don't allow connection pickup from the net
# #
Invalid(DROP) net all tcp Invalid(DROP) net all
# #
# Accept DNS connections from the firewall to the Internet # Accept DNS connections from the firewall to the Internet
# #

View File

@@ -14,7 +14,7 @@
# #
# For information about the settings in this file, type "man shorewall.conf" # For information about the settings in this file, type "man shorewall.conf"
# #
# The manpage is also online at # The manpage is also online at
# http://shorewall.net/manpages/shorewall.conf.html # http://shorewall.net/manpages/shorewall.conf.html
# #
############################################################################### ###############################################################################
@@ -62,9 +62,7 @@ TCP_FLAGS_LOG_LEVEL=info
# L O C A T I O N O F F I L E S A N D D I R E C T O R I E S # L O C A T I O N O F F I L E S A N D D I R E C T O R I E S
############################################################################### ###############################################################################
CONFIG_PATH=${CONFDIR}/shorewall:${SHAREDIR}/shorewall CONFIG_PATH=/etc/shorewall:/usr/share/shorewall
GEOIPDIR=/usr/share/xt_geoip/LE
IPTABLES= IPTABLES=
@@ -72,8 +70,6 @@ IP=
IPSET= IPSET=
LOCKFILE=
MODULESDIR= MODULESDIR=
PERL=/usr/bin/perl PERL=/usr/bin/perl
@@ -151,8 +147,6 @@ FORWARD_CLEAR_MARK=
IMPLICIT_CONTINUE=No IMPLICIT_CONTINUE=No
IPSET_WARNINGS=Yes
IP_FORWARDING=On IP_FORWARDING=On
KEEP_RT_TABLES=No KEEP_RT_TABLES=No
@@ -179,7 +173,7 @@ MUTEX_TIMEOUT=60
NULL_ROUTE_RFC1918=No NULL_ROUTE_RFC1918=No
OPTIMIZE=31 OPTIMIZE=1
OPTIMIZE_ACCOUNTING=No OPTIMIZE_ACCOUNTING=No

View File

@@ -11,8 +11,6 @@
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# For information about entries in this file, type "man shorewall-interfaces" # For information about entries in this file, type "man shorewall-interfaces"
############################################################################### ###############################################################################
FORMAT 2 #ZONE INTERFACE BROADCAST OPTIONS
############################################################################### net eth0 detect dhcp,tcpflags,nosmurfs,routefilter,logmartians
#ZONE INTERFACE OPTIONS loc eth1 detect tcpflags,nosmurfs,routefilter,logmartians
net eth0 dhcp,tcpflags,nosmurfs,routefilter,logmartians,sourceroute=0
loc eth1 tcpflags,nosmurfs,routefilter,logmartians

View File

@@ -10,9 +10,8 @@
# See the file README.txt for further details. # See the file README.txt for further details.
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# For information about entries in this file, type "man shorewall-masq" # For information about entries in this file, type "man shorewall-masq"
################################################################################################################ ###############################################################################
#INTERFACE:DEST SOURCE ADDRESS PROTO PORT(S) IPSEC MARK USER/ SWITCH ORIGINAL #INTERFACE SOURCE ADDRESS PROTO PORT(S) IPSEC MARK
# GROUP DEST
eth0 10.0.0.0/8,\ eth0 10.0.0.0/8,\
169.254.0.0/16,\ 169.254.0.0/16,\
172.16.0.0/12,\ 172.16.0.0/12,\

View File

@@ -20,7 +20,7 @@ SECTION NEW
# Don't allow connection pickup from the net # Don't allow connection pickup from the net
# #
Invalid(DROP) net all tcp Invalid(DROP) net all
# #
# Accept DNS connections from the firewall to the network # Accept DNS connections from the firewall to the network
# #

View File

@@ -3,7 +3,7 @@
# Shorewall version 4.0 - Sample shorewall.conf for two-interface # Shorewall version 4.0 - Sample shorewall.conf for two-interface
# configuration. # configuration.
# Copyright (C) 2006,2007 by the Shorewall Team # Copyright (C) 2006,2007 by the Shorewall Team
# 2011 by Thomas M. Eastep # 2011 by Thomas M. Eastep
# #
# This library is free software; you can redistribute it and/or # This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public # modify it under the terms of the GNU Lesser General Public
@@ -14,7 +14,7 @@
# #
# For information about the settings in this file, type "man shorewall.conf" # For information about the settings in this file, type "man shorewall.conf"
# #
# The manpage is also online at # The manpage is also online at
# http://shorewall.net/manpages/shorewall.conf.html # http://shorewall.net/manpages/shorewall.conf.html
# #
############################################################################### ###############################################################################
@@ -65,9 +65,7 @@ TCP_FLAGS_LOG_LEVEL=info
# L O C A T I O N O F F I L E S A N D D I R E C T O R I E S # L O C A T I O N O F F I L E S A N D D I R E C T O R I E S
############################################################################### ###############################################################################
CONFIG_PATH=${CONFDIR}/shorewall:${SHAREDIR}/shorewall CONFIG_PATH=/etc/shorewall:/usr/share/shorewall
GEOIPDIR=/usr/share/xt_geoip/LE
IPTABLES= IPTABLES=
@@ -75,8 +73,6 @@ IP=
IPSET= IPSET=
LOCKFILE=
MODULESDIR= MODULESDIR=
PERL=/usr/bin/perl PERL=/usr/bin/perl
@@ -154,8 +150,6 @@ FORWARD_CLEAR_MARK=
IMPLICIT_CONTINUE=No IMPLICIT_CONTINUE=No
IPSET_WARNINGS=Yes
IP_FORWARDING=On IP_FORWARDING=On
KEEP_RT_TABLES=No KEEP_RT_TABLES=No
@@ -182,7 +176,7 @@ MUTEX_TIMEOUT=60
NULL_ROUTE_RFC1918=No NULL_ROUTE_RFC1918=No
OPTIMIZE=31 OPTIMIZE=1
OPTIMIZE_ACCOUNTING=No OPTIMIZE_ACCOUNTING=No

View File

@@ -22,7 +22,7 @@
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# #
# Broadcast[([<action>|-[,{audit|-}])] # Broadcast[([<action>|-[,{audit|-}])]
# #
# Default action is DROP # Default action is DROP
# #
@@ -31,7 +31,7 @@ FORMAT 2
DEFAULTS DROP,- DEFAULTS DROP,-
?BEGIN PERL; BEGIN PERL;
use Shorewall::IPAddrs; use Shorewall::IPAddrs;
use Shorewall::Config; use Shorewall::Config;
@@ -51,7 +51,7 @@ if ( have_capability( 'ADDRTYPE' ) ) {
log_rule_limit $level, $chainref, 'dropBcast' , $action, '', $tag, 'add', ' -m addrtype --dst-type BROADCAST '; log_rule_limit $level, $chainref, 'dropBcast' , $action, '', $tag, 'add', ' -m addrtype --dst-type BROADCAST ';
log_rule_limit $level, $chainref, 'dropBcast' , $action, '', $tag, 'add', ' -m addrtype --dst-type MULTICAST '; log_rule_limit $level, $chainref, 'dropBcast' , $action, '', $tag, 'add', ' -m addrtype --dst-type MULTICAST ';
log_rule_limit $level, $chainref, 'dropBcast' , $action, '', $tag, 'add', ' -m addrtype --dst-type ANYCAST '; log_rule_limit $level, $chainref, 'dropBcast' , $action, '', $tag, 'add', ' -m addrtype --dst-type ANYCAST ';
} }
add_jump $chainref, $target, 0, '-m addrtype --dst-type BROADCAST '; add_jump $chainref, $target, 0, '-m addrtype --dst-type BROADCAST ';
add_jump $chainref, $target, 0, '-m addrtype --dst-type MULTICAST '; add_jump $chainref, $target, 0, '-m addrtype --dst-type MULTICAST ';
@@ -64,10 +64,10 @@ if ( have_capability( 'ADDRTYPE' ) ) {
decr_cmd_level $chainref; decr_cmd_level $chainref;
add_commands $chainref, 'done'; add_commands $chainref, 'done';
} }
log_rule_limit $level, $chainref, 'Broadcast' , $action, '', $tag, 'add', ' -d 224.0.0.0/4 ' if $level ne ''; log_rule_limit $level, $chainref, 'Broadcast' , $action, '', $tag, 'add', ' -d 224.0.0.0/4 ' if $level ne '';
add_jump $chainref, $target, 0, '-d 224.0.0.0/4 '; add_jump $chainref, $target, 0, '-d 224.0.0.0/4 ';
1; 1;
?END PERL; END PERL;

View File

@@ -33,15 +33,15 @@
############################################################################### ###############################################################################
FORMAT 2 FORMAT 2
# #
# The following magic provides different defaults for $2 thru $5, when $1 is # The following magic provides different defaults for $2 thru $5, when $1 is
# 'audit'. # 'audit'.
# #
?BEGIN PERL; BEGIN PERL;
use Shorewall::Config; use Shorewall::Config;
my ( $p1, $p2, $p3 , $p4, $p5 ) = get_action_params( 5 ); my ( $p1, $p2, $p3 , $p4, $p5 ) = get_action_params( 5 );
if ( defined $p1 ) { if ( defined $p1 ) {
if ( $p1 eq 'audit' ) { if ( $p1 eq 'audit' ) {
set_action_param( 2, 'A_REJECT') unless supplied $p2; set_action_param( 2, 'A_REJECT') unless supplied $p2;
set_action_param( 3, 'A_DROP') unless supplied $p3; set_action_param( 3, 'A_DROP') unless supplied $p3;
@@ -54,7 +54,7 @@ if ( defined $p1 ) {
1; 1;
?END PERL; END PERL;
DEFAULTS -,REJECT,DROP,ACCEPT,DROP DEFAULTS -,REJECT,DROP,ACCEPT,DROP

View File

@@ -13,7 +13,7 @@ FORMAT 2
DEFAULTS - DEFAULTS -
?BEGIN PERL; BEGIN PERL;
use strict; use strict;
use Shorewall::Config qw(:DEFAULT F_IPV4 F_IPV6); use Shorewall::Config qw(:DEFAULT F_IPV4 F_IPV6);
use Shorewall::Chains; use Shorewall::Chains;
@@ -41,15 +41,15 @@ if ( $level ne '-' || $audit ne '-' ) {
fatal_error "Invalid argument ($audit) to DropSmurfs" if $audit ne 'audit'; fatal_error "Invalid argument ($audit) to DropSmurfs" if $audit ne 'audit';
require_capability 'AUDIT_TARGET', q(Passing 'audit' to the DropSmurfs action), 's'; require_capability 'AUDIT_TARGET', q(Passing 'audit' to the DropSmurfs action), 's';
add_ijump( $logchainref, j => 'AUDIT --type DROP' ); add_ijump( $logchainref, j => 'AUDIT --type DROP' );
} }
add_ijump( $logchainref, j => 'DROP' ); add_ijump( $logchainref, j => 'DROP' );
$target = $logchainref; $target = $logchainref;
} else { } else {
$target = 'DROP'; $target = 'DROP';
} }
if ( have_capability( 'ADDRTYPE' ) ) { if ( have_capability( 'ADDRTYPE' ) ) {
if ( $family == F_IPV4 ) { if ( $family == F_IPV4 ) {
add_ijump $chainref , j => 'RETURN', s => '0.0.0.0'; ; add_ijump $chainref , j => 'RETURN', s => '0.0.0.0'; ;
@@ -64,7 +64,7 @@ if ( have_capability( 'ADDRTYPE' ) ) {
} else { } else {
add_commands $chainref, 'for address in $ALL_ACASTS; do'; add_commands $chainref, 'for address in $ALL_ACASTS; do';
} }
incr_cmd_level $chainref; incr_cmd_level $chainref;
add_ijump( $chainref, g => $target, s => '$address' ); add_ijump( $chainref, g => $target, s => '$address' );
decr_cmd_level $chainref; decr_cmd_level $chainref;
@@ -77,9 +77,9 @@ if ( $family == F_IPV4 ) {
add_ijump( $chainref, g => $target, s => IPv6_MULTICAST ); add_ijump( $chainref, g => $target, s => IPv6_MULTICAST );
} }
?END PERL; END PERL;

View File

@@ -22,7 +22,7 @@
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# #
# Invalid[([<action>|-[,{audit|-}])] # Invalid[([<action>|-[,{audit|-}])]
# #
# Default action is DROP # Default action is DROP
# #
@@ -31,7 +31,7 @@ FORMAT 2
DEFAULTS DROP,- DEFAULTS DROP,-
?BEGIN PERL; BEGIN PERL;
use Shorewall::IPAddrs; use Shorewall::IPAddrs;
use Shorewall::Config; use Shorewall::Config;
@@ -49,8 +49,8 @@ my $target = require_audit ( $action , $audit );
log_rule_limit $level, $chainref, 'Invalid' , $action, '', $tag, 'add', "$globals{STATEMATCH} INVALID " if $level ne ''; log_rule_limit $level, $chainref, 'Invalid' , $action, '', $tag, 'add', "$globals{STATEMATCH} INVALID " if $level ne '';
add_jump $chainref , $target, 0, "$globals{STATEMATCH} INVALID "; add_jump $chainref , $target, 0, "$globals{STATEMATCH} INVALID ";
allow_optimize( $chainref ); $chainref->{dont_optimize} = 0;
1; 1;
?END PERL; END PERL;

View File

@@ -22,7 +22,7 @@
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# #
# NotSyn[([<action>|-[,{audit|-}])] # NotSyn[([<action>|-[,{audit|-}])]
# #
# Default action is DROP # Default action is DROP
# #
@@ -31,7 +31,7 @@ FORMAT 2
DEFAULTS DROP,- DEFAULTS DROP,-
?BEGIN PERL; BEGIN PERL;
use Shorewall::IPAddrs; use Shorewall::IPAddrs;
use Shorewall::Config; use Shorewall::Config;
@@ -49,8 +49,8 @@ my $target = require_audit ( $action , $audit );
log_rule_limit $level, $chainref, 'NotSyn' , $action, '', $tag, 'add', '-p 6 ! --syn ' if $level ne ''; log_rule_limit $level, $chainref, 'NotSyn' , $action, '', $tag, 'add', '-p 6 ! --syn ' if $level ne '';
add_jump $chainref , $target, 0, '-p 6 ! --syn '; add_jump $chainref , $target, 0, '-p 6 ! --syn ';
allow_optimize( $chainref ); $chainref->{dont_optimize} = 0;
1; 1;
?END PERL; END PERL;

View File

@@ -1,55 +0,0 @@
#
# Shorewall 4 - RST Action
#
# /usr/share/shorewall/action.RST
#
# This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt]
#
# (c) 2012 - Tom Eastep (teastep@shorewall.net)
#
# Complete documentation is available at http://shorewall.net
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of Version 2 of the GNU General Public License
# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# RST[([<action>|-[,{audit|-}])]
#
# Default action is DROP
#
##########################################################################################
FORMAT 2
DEFAULTS DROP,-
?BEGIN PERL;
use Shorewall::Config;
use Shorewall::Chains;
my ( $action, $audit ) = get_action_params( 2 );
fatal_error "Invalid parameter ($audit) to action NotSyn" if supplied $audit && $audit ne 'audit';
fatal_error "Invalid parameter ($action) to action NotSyn" unless $action =~ /^(?:ACCEPT|DROP)$/;
my $chainref = get_action_chain;
my ( $level, $tag ) = get_action_logging;
my $target = require_audit ( $action , $audit );
log_rule_limit $level, $chainref, 'RST' , $action, '', $tag, 'add', '-p 6 --tcp-flags RST RST ' if $level ne '';
add_jump $chainref , $target, 0, '-p 6 --tcp-flags RST RST, ';
allow_optimize( $chainref );
1;
?END PERL;

View File

@@ -29,15 +29,15 @@
############################################################################### ###############################################################################
FORMAT 2 FORMAT 2
# #
# The following magic provides different defaults for $2 thru $5, when $1 is # The following magic provides different defaults for $2 thru $5, when $1 is
# 'audit'. # 'audit'.
# #
?BEGIN PERL; BEGIN PERL;
use Shorewall::Config; use Shorewall::Config;
my ( $p1, $p2, $p3 , $p4, $p5 ) = get_action_params( 5 ); my ( $p1, $p2, $p3 , $p4, $p5 ) = get_action_params( 5 );
if ( defined $p1 ) { if ( defined $p1 ) {
if ( $p1 eq 'audit' ) { if ( $p1 eq 'audit' ) {
set_action_param( 2, 'A_REJECT') unless supplied $p2; set_action_param( 2, 'A_REJECT') unless supplied $p2;
set_action_param( 3, 'A_REJECT') unless supplied $p3; set_action_param( 3, 'A_REJECT') unless supplied $p3;
@@ -50,7 +50,7 @@ if ( defined $p1 ) {
1; 1;
?END PERL; END PERL;
DEFAULTS -,REJECT,REJECT,ACCEPT,DROP DEFAULTS -,REJECT,REJECT,ACCEPT,DROP

View File

@@ -13,17 +13,18 @@ FORMAT 2
DEFAULTS DROP,- DEFAULTS DROP,-
?BEGIN PERL; BEGIN PERL;
use strict; use strict;
use Shorewall::Config qw(:DEFAULT F_IPV4 F_IPV6); use Shorewall::Config qw(:DEFAULT F_IPV4 F_IPV6);
use Shorewall::Chains; use Shorewall::Chains;
my ( $disposition, $audit ) = get_action_params( 2 ); my ( $disposition, $audit ) = get_action_params( 2 );
my $chainref = get_action_chain; my $chainref = get_action_chain;
my ( $level, $tag ) = get_action_logging; my ( $level, $tag ) = get_action_logging;
fatal_error q(The first argument to 'TCPFlags' must be ACCEPT, REJECT, or DROP) unless $disposition =~ /^(ACCEPT|REJECT|DROP)$/; fatal_error q(The first argument to 'TCPFlags' must be ACCEPT, REJECT, or DROP) unless $disposition =~ /^(ACCEPT|REJECT|DROP)$/;
if ( $level ne '-' || $audit ne '-' ) { if ( $level ne '-' || $audit ne '-' ) {
my $logchainref = ensure_filter_chain newlogchain( $chainref->{table} ), 0; my $logchainref = ensure_filter_chain newlogchain( $chainref->{table} ), 0;
@@ -41,22 +42,22 @@ if ( $level ne '-' || $audit ne '-' ) {
fatal_error "Invalid argument ($audit) to TCPFlags" if $audit ne 'audit'; fatal_error "Invalid argument ($audit) to TCPFlags" if $audit ne 'audit';
require_capability 'AUDIT_TARGET', q(Passing 'audit' to the TCPFlags action), 's'; require_capability 'AUDIT_TARGET', q(Passing 'audit' to the TCPFlags action), 's';
add_ijump( $logchainref, j => 'AUDIT --type ' . lc $disposition ); add_ijump( $logchainref, j => 'AUDIT --type ' . lc $disposition );
} }
add_ijump( $logchainref, g => $disposition ); add_ijump( $logchainref, g => $disposition );
$disposition = $logchainref; $disposition = $logchainref;
} }
add_ijump $chainref , g => $disposition, p => 'tcp --tcp-flags ALL FIN,URG,PSH'; add_ijump $chainref , g => $disposition, p => 'tcp --tcp-flags ALL FIN,URG,PSH';
add_ijump $chainref , g => $disposition, p => 'tcp --tcp-flags ALL NONE'; add_ijump $chainref , g => $disposition, p => 'tcp --tcp-flags ALL NONE';
add_ijump $chainref , g => $disposition, p => 'tcp --tcp-flags SYN,RST SYN,RST'; add_ijump $chainref , g => $disposition, p => 'tcp --tcp-flags SYN,RST SYN,RST';
add_ijump $chainref , g => $disposition, p => 'tcp --tcp-flags SYN,FIN SYN,FIN'; add_ijump $chainref , g => $disposition, p => 'tcp --tcp-flags SYN,FIN SYN,FIN';
add_ijump $chainref , g => $disposition, p => 'tcp --syn --sport 0'; add_ijump $chainref , g => $disposition, p => 'tcp --syn --sport 0';
?END PERL; END PERL;

View File

@@ -41,5 +41,4 @@ DropSmurfs # Drop smurf packets
Invalid # Handles packets in the INVALID conntrack state Invalid # Handles packets in the INVALID conntrack state
NotSyn # Handles TCP packets which do not have SYN=1 and ACK=0 NotSyn # Handles TCP packets which do not have SYN=1 and ACK=0
Reject # Default Action for REJECT policy Reject # Default Action for REJECT policy
RST # Handle packets with RST set
TCPFlags # Handle bad flag combinations. TCPFlags # Handle bad flag combinations.

View File

@@ -7,6 +7,4 @@
# http://www.shorewall.net/manpages/shorewall-interfaces.html # http://www.shorewall.net/manpages/shorewall-interfaces.html
# #
############################################################################### ###############################################################################
FORMAT 2 #ZONE INTERFACE BROADCAST OPTIONS
###############################################################################
#ZONE INTERFACE OPTIONS

View File

@@ -6,6 +6,6 @@
# The manpage is also online at # The manpage is also online at
# http://www.shorewall.net/manpages/shorewall-masq.html # http://www.shorewall.net/manpages/shorewall-masq.html
# #
################################################################################################################ #############################################################################################
#INTERFACE:DEST SOURCE ADDRESS PROTO PORT(S) IPSEC MARK USER/ SWITCH ORIGINAL #INTERFACE:DEST SOURCE ADDRESS PROTO PORT(S) IPSEC MARK USER/
# GROUP DEST # GROUP

View File

@@ -53,9 +53,7 @@ TCP_FLAGS_LOG_LEVEL=info
# L O C A T I O N O F F I L E S A N D D I R E C T O R I E S # L O C A T I O N O F F I L E S A N D D I R E C T O R I E S
############################################################################### ###############################################################################
CONFIG_PATH="${CONFDIR}/shorewall:${SHAREDIR}/shorewall" CONFIG_PATH="/etc/shorewall:/usr/share/shorewall"
GEOIPDIR=/usr/share/xt_geoip/LE
IPTABLES= IPTABLES=
@@ -63,8 +61,6 @@ IP=
IPSET= IPSET=
LOCKFILE=
MODULESDIR= MODULESDIR=
PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin" PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin"
@@ -142,8 +138,6 @@ FORWARD_CLEAR_MARK=
IMPLICIT_CONTINUE=No IMPLICIT_CONTINUE=No
IPSET_WARNINGS=Yes
IP_FORWARDING=On IP_FORWARDING=On
KEEP_RT_TABLES=No KEEP_RT_TABLES=No

View File

@@ -9,9 +9,7 @@
# #
# See http://shorewall.net/PacketMarking.html for a detailed description of # See http://shorewall.net/PacketMarking.html for a detailed description of
# the Netfilter/Shorewall packet marking mechanism. # the Netfilter/Shorewall packet marking mechanism.
########################################################################################################################################## ######################################################################################################################################
FORMAT 2 #MARK SOURCE DEST PROTO DEST SOURCE USER TEST LENGTH TOS CONNBYTES HELPER PROBABILITY
##########################################################################################################################################
#ACTION SOURCE DEST PROTO DEST SOURCE USER TEST LENGTH TOS CONNBYTES HELPER PROBABILITY DSCP
# PORT(S) PORT(S) # PORT(S) PORT(S)

View File

@@ -4,5 +4,5 @@
# For information about entries in this file, type "man shorewall-tos" # For information about entries in this file, type "man shorewall-tos"
# #
############################################################################### ###############################################################################
#SOURCE DEST PROTOCOL DEST SOURCE TOS MARK #SOURCE DEST PROTOCOL SOURCE DEST TOS MARK
# PORTS PORTS # PORTS PORTS

View File

@@ -7,5 +7,5 @@
# http://www.shorewall.net/manpages/shorewall-tunnels.html # http://www.shorewall.net/manpages/shorewall-tunnels.html
# #
############################################################################### ###############################################################################
#TYPE ZONE GATEWAY(S) GATEWAY #TYPE ZONE GATEWAY GATEWAY
# ZONE(S) # ZONE

View File

@@ -10,4 +10,4 @@
# /usr/share/shorewall/configfiles/. This prevents 'compile -e' # /usr/share/shorewall/configfiles/. This prevents 'compile -e'
# from trying to use configuration information from /etc/shorewall. # from trying to use configuration information from /etc/shorewall.
CONFIG_PATH=${CONFDIR}:${SHAREDIR}/shorewall CONFIG_PATH=${CONFDIR}:/usr/share/shorewall

View File

@@ -11,6 +11,7 @@
### END INIT INFO ### END INIT INFO
SRWL=/sbin/shorewall SRWL=/sbin/shorewall
SRWL_OPTS="-tvv" SRWL_OPTS="-tvv"
WAIT_FOR_IFUP=/usr/share/shorewall/wait4ifup WAIT_FOR_IFUP=/usr/share/shorewall/wait4ifup
@@ -53,15 +54,10 @@ not_configured () {
exit 0 exit 0
} }
#
# The installer may alter this
#
. /usr/share/shorewall/shorewallrc
# check if shorewall is configured or not # check if shorewall is configured or not
if [ -f "${SYSCONFDIR}/shorewall" ] if [ -f "/etc/default/shorewall" ]
then then
. ${SYSCONFDIR}/shorewall . /etc/default/shorewall
SRWL_OPTS="$SRWL_OPTS $OPTIONS" SRWL_OPTS="$SRWL_OPTS $OPTIONS"
if [ "$startup" != "1" ] if [ "$startup" != "1" ]
then then

View File

@@ -20,31 +20,26 @@
# Source function library. # Source function library.
. /etc/rc.d/init.d/functions . /etc/rc.d/init.d/functions
#
# The installer may alter this
#
. /usr/share/shorewall/shorewallrc
prog="shorewall" prog="shorewall"
shorewall="${SBINDIR}/$prog" shorewall="/sbin/$prog"
logger="logger -i -t $prog" logger="logger -i -t $prog"
lockfile="/var/lock/subsys/$prog" lockfile="/var/lock/subsys/$prog"
# Get startup options (override default) # Get startup options (override default)
OPTIONS= OPTIONS=
if [ -f ${SYSCONFDIR}/$prog ]; then if [ -f /etc/sysconfig/$prog ]; then
. ${SYSCONFDIR}/$prog . /etc/sysconfig/$prog
fi fi
start() { start() {
echo -n $"Starting Shorewall: " echo -n $"Starting Shorewall: "
$shorewall $OPTIONS start 2>&1 | $logger $shorewall $OPTIONS start 2>&1 | $logger
retval=${PIPESTATUS[0]} retval=${PIPESTATUS[0]}
if [[ $retval == 0 ]]; then if [[ $retval == 0 ]]; then
touch $lockfile touch $lockfile
success success
else else
failure failure
fi fi
echo echo
@@ -55,10 +50,10 @@ stop() {
echo -n $"Stopping Shorewall: " echo -n $"Stopping Shorewall: "
$shorewall $OPTIONS stop 2>&1 | $logger $shorewall $OPTIONS stop 2>&1 | $logger
retval=${PIPESTATUS[0]} retval=${PIPESTATUS[0]}
if [[ $retval == 0 ]]; then if [[ $retval == 0 ]]; then
rm -f $lockfile rm -f $lockfile
success success
else else
failure failure
fi fi
echo echo
@@ -71,7 +66,7 @@ restart() {
echo -n $"Restarting Shorewall: " echo -n $"Restarting Shorewall: "
$shorewall $OPTIONS restart 2>&1 | $logger $shorewall $OPTIONS restart 2>&1 | $logger
retval=${PIPESTATUS[0]} retval=${PIPESTATUS[0]}
if [[ $retval == 0 ]]; then if [[ $retval == 0 ]]; then
touch $lockfile touch $lockfile
success success
else # Failed to start, clean up lock file if present else # Failed to start, clean up lock file if present

View File

@@ -54,7 +54,7 @@ RCDLINKS="2,S41 3,S41 6,K41"
# Give Usage Information # # Give Usage Information #
################################################################################ ################################################################################
usage() { usage() {
echo "Usage: $0 start|stop|reload|restart|status" >&2 echo "Usage: $0 start|stop|reload|restart|status"
exit 1 exit 1
} }
@@ -62,14 +62,10 @@ usage() {
# Get startup options (override default) # Get startup options (override default)
################################################################################ ################################################################################
OPTIONS="-v0" OPTIONS="-v0"
if [ -f /etc/sysconfig/shorewall ]; then
# . /etc/sysconfig/shorewall
# The installer may alter this elif [ -f /etc/default/shorewall ] ; then
# . /etc/default/shorewall
. /usr/share/shorewall/shorewallrc
if [ -f ${SYSCONFDIR}/shorewall ]; then
. ${SYSCONFDIR}/shorewall
fi fi
export SHOREWALL_INIT_SCRIPT=1 export SHOREWALL_INIT_SCRIPT=1
@@ -82,13 +78,13 @@ shift
case "$command" in case "$command" in
start) start)
exec $SBINDIR/shorewall $OPTIONS start $STARTOPTIONS exec /sbin/shorewall $OPTIONS start $STARTOPTIONS $@
;; ;;
restart|reload) restart|reload)
exec $SBINDIR/shorewall $OPTIONS restart $RESTARTOPTIONS exec /sbin/shorewall $OPTIONS restart $RESTARTOPTIONS $@
;; ;;
status|stop) status|stop)
exec $SBINDIR/shorewall $OPTIONS $command exec /sbin/shorewall $OPTIONS $command $@
;; ;;
*) *)
usage usage

Some files were not shown because too many files have changed in this diff Show More