Compare commits

..

29 Commits

Author SHA1 Message Date
Tom Eastep
866cb04cbb Unify TRACK_RULES settings implementation
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2016-01-25 18:07:46 -08:00
Tom Eastep
6ef136a546 Add origin information for entries in shorewall[6].conf
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2016-01-25 15:49:18 -08:00
Tom Eastep
9b3b4579a2 Change TRACK_RULES setting from Internal to File
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2016-01-24 16:15:36 -08:00
Tom Eastep
3e404b765f Make .ip[6]tables-restore-input comments conditional
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2016-01-23 17:04:52 -08:00
Tom Eastep
2235641c9f Add origin to the ip[6]tables input.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2016-01-23 15:13:12 -08:00
Tom Eastep
3fe4619f66 Fix origin in interfaces and hosts
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2016-01-23 13:49:52 -08:00
Tom Eastep
247698a14d Add origin in some rules from the Misc module
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2016-01-23 12:31:53 -08:00
Tom Eastep
73b20c832c Add 'origin' member to rules
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2016-01-23 10:45:26 -08:00
Tom Eastep
8ac754caed Add 'origin' member to the interface and hosts tables
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2016-01-21 17:08:19 -08:00
Matt Darfeuille
c85ced09af Corrected sysconfig files
Removed unnecessary lines in sysconfig files

Signed-off-by: Matt Darfeuille <matdarf@gmail.com>
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2016-01-19 09:25:37 -08:00
Tom Eastep
1abb77d66d Remove restrictions on -m geoip
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2016-01-18 22:30:15 -08:00
Tom Eastep
a28f3012d5 Correct $VERSION setting in Raw.pm
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2016-01-18 09:38:35 -08:00
Tom Eastep
7d443b5e2e Eliminate return value from process_action()
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2016-01-18 09:08:35 -08:00
Tom Eastep
a945b3e0dd Tweak the process_action() changes
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2016-01-17 17:03:46 -08:00
Tom Eastep
ec6c233666 Centralize Rules module handling of @CALLER in actions
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2016-01-17 16:29:35 -08:00
Tom Eastep
4059e9de95 Clean up use_policy_action()
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2016-01-17 12:35:12 -08:00
Tom Eastep
1ee645cd79 Another determinism fix -- red and codel options are now sorted
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2016-01-17 09:50:34 -08:00
Tom Eastep
1fedb26f1d Handle @CALLER in policy chains
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2016-01-17 09:42:01 -08:00
Tom Eastep
031371f259 Improve maintainability of action-tuple code
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2016-01-16 17:26:16 -08:00
Tom Eastep
742c15b289 Improve @CALLER fix to create unique chains per caller
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2016-01-16 17:12:03 -08:00
Tom Eastep
9aa915a5e0 Avoid errors from 'status -i' when there are no optional interfaces
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2016-01-15 16:39:47 -08:00
Tom Eastep
f95c67ec6b Restore unmodified .pm files after installation
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2016-01-15 13:55:46 -08:00
matt darfeuille
f1ed963077 Shorewall 5.0.4 Beta 2
Hi Tom,

Some unnecessary lines need to be removed from the sysconfig files.
I made some more changes to the init.openwrt.sh scripts(lite and
lite6)

Attached as sysconfig-lite.patch!

In order to be able to use the build50 script I had to make a few
changes(attached as build50.patch):

- Adding a variable BASEDIR (to build shorewall  in a subdirectory)
BASEDIR=$PWD
and doing:
$BASEDIR/annotate.pl
and so on ...

- Adding a variable
CYGWINSTYLESHEET
and modifying the script to use this new variable(added cygwin clause
in case statement)

- Adding a variable GITRELEASEDIR and modifying the lines around
624(to specify an other name for the release repo)
from
../release/
to
../$GITRELEASEDIR/

- Added line to remove unnecessary *.bak files

- Added an if statement if a subdirectory is used when patches are
created

question/request:
Would it be possible to use the build50 script without the '-t'
option?
That way only the packages would be built but the tarballs wouldn't
be created.

-Matt

On 12 Jan 2016 at 7:57, Tom Eastep wrote:

> Shorewall 5.0.4 Beta 2 is now available for download.
>
> New Feature since Beta 1:
>
> 1)  The mangle file now supports an DIVERTHA action that provides
>     support for HAProxy.
>
>     To setup the HAProxy transparent configuration described at
>
> http://www.loadbalancer.org/blog/setting-up-haproxy-with-transparent-mode-on-centos-6-x,
>     place this entry in shorewall-providers(5):
>
>
>     #NAME  NUMBER   MARK    DUPLICATE  INTERFACE GATEWAY   OPTIONS
>     TProxy 1        -       -          lo        -         tproxy
>
>     and use this DIVERTHA entry:
>
>     #ACTION         SOURCE          DEST            PROTO  ...
>     DIVERTHA        -               -               tcp
>
> Thank you for testing,
> -Tom
> --
> Tom Eastep        \ When I die, I want to go like my Grandfather who
> Shoreline,         \ died peacefully in his sleep. Not screaming like
> Washington, USA     \ all of the passengers in his car
> http://shorewall.net \________________________________________________
>
>

-------------- Enclosure number 1 ----------------
>From ca4c854433e1c4c5870ea3e71225e5df8da4e255 Mon Sep 17 00:00:00 2001
From: Matt Darfeuille <matdarf@gmail.com>
Date: Wed, 13 Jan 2016 21:28:47 +0100
Subject: [PATCH 1/2] Modified lite and lite6.init.openwrt.sh

Signed-off-by: Matt Darfeuille <matdarf@gmail.com>
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2016-01-14 16:36:21 -08:00
Tom Eastep
3bce4627f8 Correct typo in the dhcp article
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2016-01-14 08:56:19 -08:00
Tom Eastep
726d1492cd Correct error message
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2016-01-13 17:08:57 -08:00
Tom Eastep
12513e24a3 Revert "Implement dynamic actions"
This reverts commit 8075ba719a.
2016-01-13 11:04:41 -08:00
Tom Eastep
21765d618d Create unique chains when @caller is used
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2016-01-13 11:04:23 -08:00
Tom Eastep
de21c59885 Correct hashlimit in logging rules
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2016-01-13 09:49:22 -08:00
Tom Eastep
8075ba719a Implement dynamic actions
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2016-01-13 09:33:38 -08:00
18 changed files with 625 additions and 354 deletions

View File

@@ -3272,9 +3272,11 @@ show_interfaces() {
local printed local printed
for f in ${VARDIR}/*.status; do for f in ${VARDIR}/*.status; do
if [ -f $f ]; then
interface=$(basename $f) interface=$(basename $f)
echo " Interface ${interface%.status} is $(interface_status $f)" echo " Interface ${interface%.status} is $(interface_status $f)"
printed=Yes printed=Yes
fi
done done
[ -n "$printed" ] && echo [ -n "$printed" ] && echo

View File

@@ -38,16 +38,13 @@
# description: Packet filtering firewall # description: Packet filtering firewall
# Product name variable
PRODUCT=shorewall-lite
+
# Openwrt related # Openwrt related
# start and stop runlevel variable # Start and stop runlevel variable
START=50 START=50
STOP=89 STOP=89
# variable to display what the status command do when /etc/init.d/shorewall-lite is invoke without argument # Displays the status command
EXTRA_COMMANDS="status" EXTRA_COMMANDS="status"
EXTRA_HELP="status displays shorewall status" EXTRA_HELP=" status Displays firewall status"
################################################################################ ################################################################################
# Get startup options (override default) # Get startup options (override default)
@@ -59,8 +56,8 @@ OPTIONS=
# #
. /usr/share/shorewall/shorewallrc . /usr/share/shorewall/shorewallrc
if [ -f ${SYSCONFDIR}/$PRODUCT ]; then if [ -f ${SYSCONFDIR}/shorewall-lite ]; then
. ${SYSCONFDIR}/$PRODUCT . ${SYSCONFDIR}/shorewall-lite
fi fi
SHOREWALL_INIT_SCRIPT=1 SHOREWALL_INIT_SCRIPT=1
@@ -68,7 +65,7 @@ SHOREWALL_INIT_SCRIPT=1
################################################################################ ################################################################################
# E X E C U T I O N B E G I N S H E R E # # E X E C U T I O N B E G I N S H E R E #
################################################################################ ################################################################################
# arg1 of init script is arg2 when rc.common is sourced; set to action variable # Arg1 of init script is arg2 when rc.common is sourced; set to action variable
command="$action" command="$action"
start() { start() {
@@ -76,8 +73,8 @@ start() {
} }
boot() { boot() {
local command="start" local command="start"
start start
} }
restart() { restart() {
@@ -93,5 +90,5 @@ stop() {
} }
status() { status() {
exec ${SBINDIR}/shorewall-lite $OPTIONS $command $STATUSOPTIONS exec ${SBINDIR}/shorewall-lite $OPTIONS $command $@
} }

View File

@@ -1,25 +1,26 @@
# sysV init file script configuration(/etc/sysconfdir/shorewall-lite) #
# Global start/restart/reload/stop options
#
OPTIONS=""
# startup option(default "-vvv") #
OPTIONS= # Start options
#
STARTOPTIONS=""
# change default start run level(if none empty; /etc/init.d/shorewall-lite enable) #
START=50 # Restart options
#
RESTARTOPTIONS=""
# change default stop run level(if none empty; /etc/init.d/shorewall-lite enable) #
STOP= # Reload options
#
RELOADOPTIONS=""
# option to pass when shorewall start is executed #
STARTOPTIONS= # Stop options
#
STOPOPTIONS=""
# option to pass when shorewall restart is executed # EOF
RESTARTOPTIONS=
# option to pass when shorewall reload is executed
RELOADOPTIONS=
# option to pass when shorewall stop is executed
STOPOPTIONS=
# option to pass when shorewall status is executed
STATUSOPTIONS=

View File

@@ -47,6 +47,7 @@ our @EXPORT = ( qw(
add_irule add_irule
add_jump add_jump
add_ijump add_ijump
add_ijump_extended
insert_rule insert_rule
insert_irule insert_irule
clone_irule clone_irule
@@ -642,6 +643,7 @@ use constant { UNIQUE => 1,
our %opttype = ( rule => CONTROL, our %opttype = ( rule => CONTROL,
cmd => CONTROL, cmd => CONTROL,
origin => CONTROL,
dhcp => CONTROL, dhcp => CONTROL,
@@ -917,7 +919,7 @@ sub set_rule_option( $$$ ) {
sub transform_rule( $;\$ ) { sub transform_rule( $;\$ ) {
my ( $input, $completeref ) = @_; my ( $input, $completeref ) = @_;
my $ruleref = { mode => CAT_MODE, matches => [], target => '' }; my $ruleref = { mode => CAT_MODE, matches => [], target => '' , origin => shortlineinfo( '' ) };
my $simple = 1; my $simple = 1;
my $target = ''; my $target = '';
my $jump = ''; my $jump = '';
@@ -1241,6 +1243,19 @@ sub add_commands ( $$;@ ) {
$chainref->{optflags} |= ( DONT_OPTIMIZE | DONT_MOVE ); $chainref->{optflags} |= ( DONT_OPTIMIZE | DONT_MOVE );
} }
sub set_rule_comment( $$ ) {
my ( $chainref, $ruleref ) = @_;
if ( $config{TRACK_RULES} eq 'Yes' && ( $ruleref->{origin} ||= $chainref->{origin} ) ) {
if ( length( my $origin = join( ' ', '@@@' , $ruleref->{origin}, '@@@' ) ) <= 255 ) {
$ruleref->{comment} = $origin;
} else {
$ruleref->{comment} = $comment;
}
} else {
$ruleref->{comment} = $comment;
}
}
# #
# Transform the passed rule and add it to the end of the passed chain's rule list. # Transform the passed rule and add it to the end of the passed chain's rule list.
# #
@@ -1252,7 +1267,8 @@ sub push_rule( $$ ) {
my $complete = 0; my $complete = 0;
my $ruleref = transform_rule( $_[1], $complete ); my $ruleref = transform_rule( $_[1], $complete );
$ruleref->{comment} = shortlineinfo($chainref->{origin}) || $comment; set_rule_comment( $chainref, $ruleref );
$ruleref->{mode} = CMD_MODE if $ruleref->{cmdlevel} = $chainref->{cmdlevel}; $ruleref->{mode} = CMD_MODE if $ruleref->{cmdlevel} = $chainref->{cmdlevel};
push @{$chainref->{rules}}, $ruleref; push @{$chainref->{rules}}, $ruleref;
@@ -1473,7 +1489,7 @@ sub create_irule( $$$;@ ) {
( $target, my $targetopts ) = split ' ', $target, 2; ( $target, my $targetopts ) = split ' ', $target, 2;
my $ruleref = { matches => [] }; my $ruleref = { matches => [] , origin => shortlineinfo( '' ) };
$ruleref->{mode} = ( $ruleref->{cmdlevel} = $chainref->{cmdlevel} ) ? CMD_MODE : CAT_MODE; $ruleref->{mode} = ( $ruleref->{cmdlevel} = $chainref->{cmdlevel} ) ? CMD_MODE : CAT_MODE;
@@ -1486,7 +1502,7 @@ sub create_irule( $$$;@ ) {
$ruleref->{target} = ''; $ruleref->{target} = '';
} }
$ruleref->{comment} = shortlineinfo($chainref->{origin}) || $ruleref->{comment} || $comment; set_rule_comment( $chainref, $ruleref );
$iprangematch = 0; $iprangematch = 0;
@@ -1642,7 +1658,7 @@ sub insert_rule1($$$)
my $ruleref = transform_rule( $rule ); my $ruleref = transform_rule( $rule );
$ruleref->{comment} = shortlineinfo($chainref->{origin}) || $comment; set_rule_comment( $chainref, $ruleref );
assert( ! ( $ruleref->{cmdlevel} = $chainref->{cmdlevel}) , $chainref->{name} ); assert( ! ( $ruleref->{cmdlevel} = $chainref->{cmdlevel}) , $chainref->{name} );
$ruleref->{mode} = CAT_MODE; $ruleref->{mode} = CAT_MODE;
@@ -1668,7 +1684,7 @@ sub insert_irule( $$$$;@ ) {
my ( $chainref, $jump, $target, $number, @matches ) = @_; my ( $chainref, $jump, $target, $number, @matches ) = @_;
my $rulesref = $chainref->{rules}; my $rulesref = $chainref->{rules};
my $ruleref = {}; my $ruleref = { origin => shortlineinfo( '' ) };
$ruleref->{mode} = ( $ruleref->{cmdlevel} = $chainref->{cmdlevel} ) ? CMD_MODE : CAT_MODE; $ruleref->{mode} = ( $ruleref->{cmdlevel} = $chainref->{cmdlevel} ) ? CMD_MODE : CAT_MODE;
@@ -1684,8 +1700,7 @@ sub insert_irule( $$$$;@ ) {
$chainref->{optflags} |= push_matches( $ruleref, @matches ); $chainref->{optflags} |= push_matches( $ruleref, @matches );
} }
set_rule_comment( $chainref, $ruleref );
$ruleref->{comment} = shortlineinfo( $chainref->{origin} ) || $ruleref->{comment} || $comment;
if ( $number >= @$rulesref ) { if ( $number >= @$rulesref ) {
# #
@@ -2300,6 +2315,7 @@ sub new_chain($$)
references => {}, references => {},
filtered => 0, filtered => 0,
optflags => 0, optflags => 0,
origin => shortlineinfo( '' ),
}; };
trace( $chainref, 'N', undef, '' ) if $debug; trace( $chainref, 'N', undef, '' ) if $debug;
@@ -2388,8 +2404,8 @@ sub add_expanded_jump( $$$$ ) {
add_reference( $chainref, $toref ) while --$splitcount > 0; add_reference( $chainref, $toref ) while --$splitcount > 0;
} }
sub add_ijump_internal( $$$$;@ ) { sub add_ijump_internal( $$$$$;@ ) {
my ( $fromref, $jump, $to, $expandports, @matches ) = @_; my ( $fromref, $jump, $to, $expandports, $origin, @matches ) = @_;
return $dummyrule if $fromref->{complete}; return $dummyrule if $fromref->{complete};
@@ -2410,6 +2426,7 @@ sub add_ijump_internal( $$$$;@ ) {
my ( $target ) = split ' ', $to; my ( $target ) = split ' ', $to;
$toref = $chain_table{$fromref->{table}}{$target}; $toref = $chain_table{$fromref->{table}}{$target};
fatal_error "Unknown rule target ($to)" unless $toref || $builtin_target{$target}; fatal_error "Unknown rule target ($to)" unless $toref || $builtin_target{$target};
$origin ||= $fromref->{origin} if $globals{TRACK_RULES};
} }
# #
@@ -2419,6 +2436,7 @@ sub add_ijump_internal( $$$$;@ ) {
$toref->{referenced} = 1; $toref->{referenced} = 1;
add_reference $fromref, $toref; add_reference $fromref, $toref;
$jump = 'j' unless have_capability 'GOTO_TARGET'; $jump = 'j' unless have_capability 'GOTO_TARGET';
$origin ||= $toref->{origin} if $globals{TRACK_RULES};
$ruleref = create_irule ($fromref, $jump => $to, @matches ); $ruleref = create_irule ($fromref, $jump => $to, @matches );
} else { } else {
$ruleref = create_irule( $fromref, 'j' => $to, @matches ); $ruleref = create_irule( $fromref, 'j' => $to, @matches );
@@ -2428,12 +2446,19 @@ sub add_ijump_internal( $$$$;@ ) {
$fromref->{complete} = 1 if $jump eq 'g' || $terminating{$to}; $fromref->{complete} = 1 if $jump eq 'g' || $terminating{$to};
} }
$ruleref->{origin} ||= $origin;
$expandports ? handle_port_ilist( $fromref, $ruleref, 1 ) : push_irule( $fromref, $ruleref ); $expandports ? handle_port_ilist( $fromref, $ruleref, 1 ) : push_irule( $fromref, $ruleref );
} }
sub add_ijump( $$$;@ ) { sub add_ijump( $$$;@ ) {
my ( $fromref, $jump, $to, @matches ) = @_; my ( $fromref, $jump, $to, @matches ) = @_;
add_ijump_internal( $fromref, $jump, $to, 0, @matches ); add_ijump_internal( $fromref, $jump, $to, 0, '', @matches );
}
sub add_ijump_extended( $$$$;@ ) {
my ( $fromref, $jump, $to, $origin, @matches ) = @_;
add_ijump_internal( $fromref, $jump, $to, 0, $origin, @matches );
} }
sub insert_ijump( $$$$;@ ) { sub insert_ijump( $$$$;@ ) {
@@ -3697,7 +3722,9 @@ sub get_multi_sports( $ ) {
# Return an array of keys for the passed rule. 'dport' and 'comment' are omitted; # Return an array of keys for the passed rule. 'dport' and 'comment' are omitted;
# #
sub get_keys( $ ) { sub get_keys( $ ) {
sort grep $_ ne 'dport' && $_ ne 'comment', keys %{$_[0]}; my %skip = ( dport => 1, comment => 1, origin => 1 );
sort grep ! $skip{$_}, keys %{$_[0]};
} }
# #
@@ -3731,6 +3758,8 @@ sub combine_dports {
my $comment = $baseref->{comment} || ''; my $comment = $baseref->{comment} || '';
my $lastcomment = $comment; my $lastcomment = $comment;
my $multi_sports = get_multi_sports( $baseref ); my $multi_sports = get_multi_sports( $baseref );
my $origin = $baseref->{origin} || '';
my $lastorigin = $origin;
RULE: RULE:
@@ -3744,6 +3773,7 @@ sub combine_dports {
# We have a candidate # We have a candidate
# #
my $comment2 = $ruleref->{comment} || ''; my $comment2 = $ruleref->{comment} || '';
my $origin2 = $ruleref->{origin} || '';
last if $comment2 ne $lastcomment && length( $comment ) + length( $comment2 ) > 253; last if $comment2 ne $lastcomment && length( $comment ) + length( $comment2 ) > 253;
@@ -3784,6 +3814,25 @@ sub combine_dports {
$lastcomment = $comment2; $lastcomment = $comment2;
} }
if ( $origin2 ) {
if ( $origin ) {
$origin .= ", $origin2" unless $origin2 eq $lastorigin;
} else {
$origin = 'Others and ';
$origin .= $origin2;
}
$lastorigin = $origin2;
} else {
if ( $origin ) {
unless ( ( $origin2 = ' and others' ) eq $lastorigin ) {
$origin .= $origin2;
}
}
$lastorigin = $origin2;
}
push @ports, split ',', $ports2; push @ports, split ',', $ports2;
trace( $chainref, 'D', $rulenum, $ruleref ) if $debug; trace( $chainref, 'D', $rulenum, $ruleref ) if $debug;
@@ -3817,6 +3866,7 @@ sub combine_dports {
} }
$baseref->{comment} = $comment if $comment; $baseref->{comment} = $comment if $comment;
$baseref->{origin} = $origin if $origin;
trace ( $chainref, 'R', $basenum, $baseref ) if $debug; trace ( $chainref, 'R', $basenum, $baseref ) if $debug;
} }
@@ -3855,6 +3905,7 @@ sub delete_duplicates {
my $lastrule = @_; my $lastrule = @_;
my $baseref = pop; my $baseref = pop;
my $ruleref; my $ruleref;
my %skip = ( comment => 1, origin => 1 );
while ( @_ ) { while ( @_ ) {
my $docheck; my $docheck;
@@ -3862,7 +3913,7 @@ sub delete_duplicates {
if ( $baseref->{mode} == CAT_MODE ) { if ( $baseref->{mode} == CAT_MODE ) {
my $ports1; my $ports1;
my @keys1 = sort( grep $_ ne 'comment', keys( %$baseref ) ); my @keys1 = sort( grep ! $skip{$_}, keys( %$baseref ) );
my $rulenum = @_; my $rulenum = @_;
my $adjacent = 1; my $adjacent = 1;
@@ -3874,7 +3925,7 @@ sub delete_duplicates {
last unless $ruleref->{mode} == CAT_MODE; last unless $ruleref->{mode} == CAT_MODE;
my @keys2 = sort(grep $_ ne 'comment', keys( %$ruleref ) ); my @keys2 = sort(grep ! $skip{$_}, keys( %$ruleref ) );
next unless @keys1 == @keys2 ; next unless @keys1 == @keys2 ;
@@ -3949,7 +4000,7 @@ sub get_conntrack( $ ) {
# Return an array of keys for the passed rule. 'conntrack' and 'comment' are omitted; # Return an array of keys for the passed rule. 'conntrack' and 'comment' are omitted;
# #
sub get_keys1( $ ) { sub get_keys1( $ ) {
sort grep $_ ne 'conntrack --ctstate' && $_ ne 'comment', keys %{$_[0]}; sort grep $_ ne 'conntrack --ctstate' && $_ ne 'comment' && $_ ne 'origin', keys %{$_[0]};
} }
# #
@@ -5753,8 +5804,6 @@ sub match_source_net( $;$\$ ) {
} }
if ( $net =~ /^(!?)\^([A-Z\d]{2})$/ || $net =~ /^(!?)\^\[([A-Z,\d]+)\]$/) { if ( $net =~ /^(!?)\^([A-Z\d]{2})$/ || $net =~ /^(!?)\^\[([A-Z,\d]+)\]$/) {
fatal_error "A countrycode list may not be used in this context" if $restriction & ( OUTPUT_RESTRICT | POSTROUTE_RESTRICT );
require_capability 'GEOIP_MATCH', 'A country-code', ''; require_capability 'GEOIP_MATCH', 'A country-code', '';
load_isocodes unless %isocodes; load_isocodes unless %isocodes;
@@ -5842,8 +5891,6 @@ sub imatch_source_net( $;$\$ ) {
} }
if ( $net =~ /^(!?)\^([A-Z\d]{2})$/ || $net =~ /^(!?)\^\[([A-Z,\d]+)\]$/) { if ( $net =~ /^(!?)\^([A-Z\d]{2})$/ || $net =~ /^(!?)\^\[([A-Z,\d]+)\]$/) {
fatal_error "A countrycode list may not be used in this context" if $restriction & ( OUTPUT_RESTRICT | POSTROUTE_RESTRICT );
require_capability 'GEOIP_MATCH', 'A country-code', ''; require_capability 'GEOIP_MATCH', 'A country-code', '';
load_isocodes unless %isocodes; load_isocodes unless %isocodes;
@@ -5928,8 +5975,6 @@ sub match_dest_net( $;$ ) {
} }
if ( $net =~ /^(!?)\^([A-Z\d]{2})$/ || $net =~ /^(!?)\^\[([A-Z,\d]+)\]$/) { if ( $net =~ /^(!?)\^([A-Z\d]{2})$/ || $net =~ /^(!?)\^\[([A-Z,\d]+)\]$/) {
fatal_error "A countrycode list may not be used in this context" if $restriction & (PREROUTE_RESTRICT | INPUT_RESTRICT );
require_capability 'GEOIP_MATCH', 'A country-code', ''; require_capability 'GEOIP_MATCH', 'A country-code', '';
load_isocodes unless %isocodes; load_isocodes unless %isocodes;
@@ -6011,8 +6056,6 @@ sub imatch_dest_net( $;$ ) {
} }
if ( $net =~ /^(!?)\^([A-Z\d]{2})$/ || $net =~ /^(!?)\^\[([A-Z,\d]+)\]$/) { if ( $net =~ /^(!?)\^([A-Z\d]{2})$/ || $net =~ /^(!?)\^\[([A-Z,\d]+)\]$/) {
fatal_error "A countrycode list may not be used in this context" if $restriction & (PREROUTE_RESTRICT | INPUT_RESTRICT );
require_capability 'GEOIP_MATCH', 'A country-code', ''; require_capability 'GEOIP_MATCH', 'A country-code', '';
load_isocodes unless %isocodes; load_isocodes unless %isocodes;
@@ -6208,14 +6251,16 @@ sub log_rule_limit( $$$$$$$$ ) {
my $prefix = ''; my $prefix = '';
my $chain = get_action_chain_name || $chn; my $chain = get_action_chain_name || $chn;
my $disposition = get_action_disposition || $dispo; my $disposition = get_action_disposition || $dispo;
my $original_matches = $matches;
my $ruleref;
$level = validate_level $level; # Do this here again because this function can be called directly from user exits. $level = validate_level $level; # Do this here again because this function can be called directly from user exits.
return 1 if $level eq ''; return $dummyrule if $level eq '';
$matches .= ' ' if $matches && substr( $matches, -1, 1 ) ne ' '; $matches .= ' ' if $matches && substr( $matches, -1, 1 ) ne ' ';
unless ( $matches =~ /-m limit / ) { unless ( $matches =~ /-m (?:limit|hashlimit) / ) {
$limit = $globals{LOGLIMIT} unless $limit && $limit ne '-'; $limit = $globals{LOGLIMIT} unless $limit && $limit ne '-';
$matches .= $limit if $limit; $matches .= $limit if $limit;
} }
@@ -6289,10 +6334,12 @@ sub log_rule_limit( $$$$$$$$ ) {
} }
if ( $command eq 'add' ) { if ( $command eq 'add' ) {
add_rule ( $chainref, $matches . $prefix , 1 ); $ruleref = add_rule ( $chainref, $matches . $prefix , $original_matches );
} else { } else {
insert_rule1 ( $chainref , 0 , $matches . $prefix ); $ruleref = insert_rule1 ( $chainref , 0 , $matches . $prefix );
} }
$ruleref;
} }
sub log_irule_limit( $$$$$$$@ ) { sub log_irule_limit( $$$$$$$@ ) {
@@ -6302,6 +6349,7 @@ sub log_irule_limit( $$$$$$$@ ) {
my %matches; my %matches;
my $chain = get_action_chain_name || $chn; my $chain = get_action_chain_name || $chn;
my $disposition = get_action_disposition || $dispo; my $disposition = get_action_disposition || $dispo;
my $original_matches = @matches;
$level = validate_level $level; # Do this here again because this function can be called directly from user exits. $level = validate_level $level; # Do this here again because this function can be called directly from user exits.
@@ -6383,7 +6431,7 @@ sub log_irule_limit( $$$$$$$@ ) {
} }
if ( $command eq 'add' ) { if ( $command eq 'add' ) {
add_ijump_internal ( $chainref, j => $prefix , 1, @matches ); add_ijump_internal ( $chainref, j => $prefix , $original_matches, '', @matches );
} else { } else {
insert_ijump ( $chainref, j => $prefix, 0 , @matches ); insert_ijump ( $chainref, j => $prefix, 0 , @matches );
} }
@@ -7895,6 +7943,11 @@ sub emitr( $$ ) {
# A rule # A rule
# #
enter_cat_mode unless $mode == CAT_MODE; enter_cat_mode unless $mode == CAT_MODE;
if ( ( my $origin = $ruleref->{origin} ) && $config{TRACK_RULES} eq 'file' ) {
emit_unindented '# ' . $origin;
}
emit_unindented format_rule( $chainref, $ruleref ); emit_unindented format_rule( $chainref, $ruleref );
} else { } else {
# #

View File

@@ -174,6 +174,7 @@ our %EXPORT_TAGS = ( internal => [ qw( create_temp_script
$comment $comment
%config %config
%origin
%globals %globals
%config_files %config_files
%shorewallrc %shorewallrc
@@ -186,6 +187,9 @@ our %EXPORT_TAGS = ( internal => [ qw( create_temp_script
%actparms %actparms
PARMSMODIFIED
USEDCALLER
F_IPV4 F_IPV4
F_IPV6 F_IPV6
@@ -294,6 +298,10 @@ our %globals;
# #
our %config; our %config;
# #
# Linenumber in shorewall[6].conf where each option was specified
#
our %origin;
#
# Entries in shorewall.conf that have been renamed # Entries in shorewall.conf that have been renamed
# #
our %renamed = ( AUTO_COMMENT => 'AUTOCOMMENT', BLACKLIST_LOGLEVEL => 'BLACKLIST_LOG_LEVEL' ); our %renamed = ( AUTO_COMMENT => 'AUTOCOMMENT', BLACKLIST_LOGLEVEL => 'BLACKLIST_LOG_LEVEL' );
@@ -546,6 +554,7 @@ our %compiler_params;
# #
our %actparms; our %actparms;
our $parmsmodified; our $parmsmodified;
our $usedcaller;
our $inline_matches; our $inline_matches;
our $currentline; # Current config file line image our $currentline; # Current config file line image
@@ -596,6 +605,9 @@ use constant { MIN_VERBOSITY => -1,
F_IPV6 => 6, F_IPV6 => 6,
}; };
use constant { PARMSMODIFIED => 1,
USEDCALLER => 2 };
our %validlevels; # Valid log levels. our %validlevels; # Valid log levels.
# #
@@ -724,6 +736,7 @@ sub initialize( $;$$) {
RPFILTER_LOG_TAG => '', RPFILTER_LOG_TAG => '',
INVALID_LOG_TAG => '', INVALID_LOG_TAG => '',
UNTRACKED_LOG_TAG => '', UNTRACKED_LOG_TAG => '',
TRACK_RULES => '',
); );
# #
# From shorewall.conf file # From shorewall.conf file
@@ -884,7 +897,10 @@ sub initialize( $;$$) {
ZONE_BITS => undef, ZONE_BITS => undef,
); );
#
# Line numbers in shorewall6.conf where options are specified
#
%origin = ();
# #
# Valid log levels # Valid log levels
# #
@@ -1045,6 +1061,7 @@ sub initialize( $;$$) {
%actparms = ( 0 => 0, loglevel => '', logtag => '', chain => '', disposition => '', caller => '' ); %actparms = ( 0 => 0, loglevel => '', logtag => '', chain => '', disposition => '', caller => '' );
$parmsmodified = 0; $parmsmodified = 0;
$usedcaller = 0;
%helpers_enabled = ( %helpers_enabled = (
amanda => 1, amanda => 1,
@@ -1184,22 +1201,18 @@ sub currentlineinfo() {
} }
} }
sub shortlineinfo( $ ) { sub shortlineinfo2() {
if ( $config{TRACK_RULES} ) {
if ( $currentfile ) { if ( $currentfile ) {
my $comment = '@@@ '. join( ':', $currentfilename, $currentlinenumber ) . ' @@@'; join( ':', $currentfilename, $currentlinenumber );
$comment = '@@@ ' . join( ':' , basename($currentfilename), $currentlinenumber) . ' @@@' if length $comment > 255;
$comment = '@@@ Filename Too Long @@@' if length $comment > 255;
$comment;
} else { } else {
# ''
# Alternate lineinfo may have been passed
#
$_[0] || ''
}
} }
} }
sub shortlineinfo( $ ) {
( $config{TRACK_RULES} ? shortlineinfo2 || $_[0] : $_[0] ) || '';
}
sub handle_first_entry(); sub handle_first_entry();
# #
@@ -2502,7 +2515,7 @@ sub evaluate_expression( $$$ ) {
my ( $first, $var, $rest ) = ( $1, $3, $4); my ( $first, $var, $rest ) = ( $1, $3, $4);
$var = numeric_value( $var ) if $var =~ /^\d/; $var = numeric_value( $var ) if $var =~ /^\d/;
$val = $var ? $actparms{$var} : $chain; $val = $var ? $actparms{$var} : $chain;
$parmsmodified ||= $var eq 'caller'; $usedcaller = USEDCALLER if $var eq 'caller';
$expression = join_parts( $first, $val, $rest ); $expression = join_parts( $first, $val, $rest );
directive_error( "Variable Expansion Loop" , $filename, $linenumber ) if ++$count > 100; directive_error( "Variable Expansion Loop" , $filename, $linenumber ) if ++$count > 100;
} }
@@ -2639,7 +2652,7 @@ sub process_compiler_directive( $$$$ ) {
my $val = $actparms{$var} = evaluate_expression ( $expression, my $val = $actparms{$var} = evaluate_expression ( $expression,
$filename, $filename,
$linenumber ); $linenumber );
$parmsmodified = 1; $parmsmodified = PARMSMODIFIED;
} else { } else {
$variables{$2} = evaluate_expression( $expression, $variables{$2} = evaluate_expression( $expression,
$filename, $filename,
@@ -3175,10 +3188,12 @@ sub push_action_params( $$$$$$ ) {
my @parms = ( undef , split_list3( $parms , 'parameter' ) ); my @parms = ( undef , split_list3( $parms , 'parameter' ) );
$actparms{modified} = $parmsmodified; $actparms{modified} = $parmsmodified;
$actparms{usedcaller} = $usedcaller;
my %oldparms = %actparms; my %oldparms = %actparms;
$parmsmodified = 0; $parmsmodified = 0;
$usedcaller = 0;
%actparms = (); %actparms = ();
@@ -3204,13 +3219,16 @@ sub push_action_params( $$$$$$ ) {
# #
# Pop the action parameters using the passed hash reference # Pop the action parameters using the passed hash reference
# Return true of the popped parameters were modified # Return:
# 1 if the popped parameters were modified
# 2 if the action used @CALLER
# #
sub pop_action_params( $ ) { sub pop_action_params( $ ) {
my $oldparms = shift; my $oldparms = shift;
%actparms = %$oldparms; %actparms = %$oldparms;
my $return = $parmsmodified; my $return = $parmsmodified | $usedcaller;
( $parmsmodified ) = delete $actparms{modified}; ( $parmsmodified ) = delete $actparms{modified} || 0;
( $usedcaller ) = delete $actparms{usedcaller} || 0;
$return; $return;
} }
@@ -3305,6 +3323,7 @@ sub expand_variables( \$ ) {
$val = $variables{$var}; $val = $variables{$var};
} elsif ( exists $actparms{$var} ) { } elsif ( exists $actparms{$var} ) {
$val = $actparms{$var}; $val = $actparms{$var};
$usedcaller = USEDCALLER if $var eq 'caller';
} else { } else {
fatal_error "Undefined shell variable (\$$var)" unless $config{IGNOREUNKNOWNVARIABLES} || exists $config{$var}; fatal_error "Undefined shell variable (\$$var)" unless $config{IGNOREUNKNOWNVARIABLES} || exists $config{$var};
} }
@@ -3323,6 +3342,7 @@ sub expand_variables( \$ ) {
while ( $$lineref =~ m( ^(.*?) \@({)? (\d+|[a-zA-Z_]\w*) (?(2)}) (.*)$ )x ) { while ( $$lineref =~ m( ^(.*?) \@({)? (\d+|[a-zA-Z_]\w*) (?(2)}) (.*)$ )x ) {
my ( $first, $var, $rest ) = ( $1, $3, $4); my ( $first, $var, $rest ) = ( $1, $3, $4);
my $val = $var ? $actparms{$var} : $actparms{chain}; my $val = $var ? $actparms{$var} : $actparms{chain};
$usedcaller = USEDCALLER if $var eq 'caller';
$val = '' unless defined $val; $val = '' unless defined $val;
$$lineref = join( '', $first , $val , $rest ); $$lineref = join( '', $first , $val , $rest );
fatal_error "Variable Expansion Loop" if ++$count > 100; fatal_error "Variable Expansion Loop" if ++$count > 100;
@@ -5022,6 +5042,8 @@ sub process_shorewall_conf( $$ ) {
warning_message "Option $var=$val is deprecated" warning_message "Option $var=$val is deprecated"
if $deprecated{$var} && supplied $val && lc $config{$var} ne $deprecated{$var}; if $deprecated{$var} && supplied $val && lc $config{$var} ne $deprecated{$var};
$origin{$var} = shortlineinfo2;
} else { } else {
fatal_error "Unrecognized $product.conf entry"; fatal_error "Unrecognized $product.conf entry";
} }
@@ -5796,7 +5818,17 @@ sub get_configuration( $$$$ ) {
default_yes_no 'MULTICAST' , ''; default_yes_no 'MULTICAST' , '';
default_yes_no 'MARK_IN_FORWARD_CHAIN' , ''; default_yes_no 'MARK_IN_FORWARD_CHAIN' , '';
default_yes_no 'CHAIN_SCRIPTS' , 'Yes'; default_yes_no 'CHAIN_SCRIPTS' , 'Yes';
if ( supplied ( $val = $config{TRACK_RULES} ) ) {
if ( lc( $val ) ne 'file' ) {
default_yes_no 'TRACK_RULES' , ''; default_yes_no 'TRACK_RULES' , '';
}
} else {
$config{TRACK_RULES} = '';
}
%origin = () unless $globals{TRACK_RULES};
default_yes_no 'INLINE_MATCHES' , ''; default_yes_no 'INLINE_MATCHES' , '';
default_yes_no 'BASIC_FILTERS' , ''; default_yes_no 'BASIC_FILTERS' , '';
default_yes_no 'WORKAROUNDS' , 'Yes'; default_yes_no 'WORKAROUNDS' , 'Yes';
@@ -5818,7 +5850,7 @@ sub get_configuration( $$$$ ) {
$config{REJECT_ACTION} = ''; $config{REJECT_ACTION} = '';
} }
require_capability 'COMMENTS', 'TRACK_RULES=Yes', 's' if $config{TRACK_RULES}; require_capability 'COMMENTS', 'TRACK_RULES=Yes', 's' if $config{TRACK_RULES} eq 'Yes';
default_yes_no 'MANGLE_ENABLED' , have_capability( 'MANGLE_ENABLED' ) ? 'Yes' : ''; default_yes_no 'MANGLE_ENABLED' , have_capability( 'MANGLE_ENABLED' ) ? 'Yes' : '';
default_yes_no 'USE_DEFAULT_RT' , ''; default_yes_no 'USE_DEFAULT_RT' , '';

View File

@@ -107,13 +107,13 @@ sub setup_ecn()
fatal_error 'INTERFACE must be specified' if $interface eq '-'; fatal_error 'INTERFACE must be specified' if $interface eq '-';
fatal_error "Unknown interface ($interface)" unless known_interface $interface; fatal_error "Unknown interface ($interface)" unless known_interface $interface;
$interfaces{$interface} = 1; $interfaces{$interface} ||= shortlineinfo1( '' );
$hosts = ALLIP if $hosts eq '-'; $hosts = ALLIP if $hosts eq '-';
for my $host( split_list $hosts, 'address' ) { for my $host( split_list $hosts, 'address' ) {
validate_host( $host , 1 ); validate_host( $host , 1 );
push @hosts, [ $interface, $host ]; push @hosts, [ $interface, shortlineinfo1( '' ), $host ];
} }
} }
@@ -125,12 +125,12 @@ sub setup_ecn()
for my $interface ( @interfaces ) { for my $interface ( @interfaces ) {
my $chainref = ensure_chain 'mangle', ecn_chain( $interface ); my $chainref = ensure_chain 'mangle', ecn_chain( $interface );
add_ijump $mangle_table->{POSTROUTING} , j => $chainref, p => 'tcp', imatch_dest_dev( $interface ) if have_capability 'MANGLE_FORWARD'; add_ijump_extended $mangle_table->{POSTROUTING} , j => $chainref, $interfaces{$interface}, p => 'tcp', imatch_dest_dev( $interface ) if have_capability 'MANGLE_FORWARD';
add_ijump $mangle_table->{OUTPUT}, j => $chainref, p => 'tcp', imatch_dest_dev( $interface ); add_ijump_extended $mangle_table->{OUTPUT}, j => $chainref, $interfaces{$interface}, p => 'tcp', imatch_dest_dev( $interface );
} }
for my $host ( @hosts ) { for my $host ( @hosts ) {
add_ijump( $mangle_table->{ecn_chain $host->[0]}, j => 'ECN', targetopts => '--ecn-tcp-remove', p => 'tcp', imatch_dest_net( $host->[1] ) ); add_ijump_extended( $mangle_table->{ecn_chain $host->[0]}, j => 'ECN', $host=>[1], targetopts => '--ecn-tcp-remove', p => 'tcp', imatch_dest_net( $host->[2] ) );
} }
} }
} }
@@ -655,7 +655,7 @@ sub add_common_rules ( $ ) {
setup_mss; setup_mss;
if ( $config{FASTACCEPT} ) { if ( $config{FASTACCEPT} ) {
add_ijump( $filter_table->{OUTPUT} , j => 'ACCEPT', state_imatch $faststate ) add_ijump_extended( $filter_table->{OUTPUT} , j => 'ACCEPT', $origin{FASTACCEPT}, state_imatch $faststate )
} }
my $policy = $config{SFILTER_DISPOSITION}; my $policy = $config{SFILTER_DISPOSITION};
@@ -663,6 +663,7 @@ sub add_common_rules ( $ ) {
$tag = $config{SFILTER_LOG_TAG}; $tag = $config{SFILTER_LOG_TAG};
my $audit = $policy =~ s/^A_//; my $audit = $policy =~ s/^A_//;
my @ipsec = have_ipsec ? ( policy => '--pol none --dir in' ) : (); my @ipsec = have_ipsec ? ( policy => '--pol none --dir in' ) : ();
my $origin = $origin{SFILTER_DISPOSITION};
if ( $level || $audit ) { if ( $level || $audit ) {
# #
@@ -670,18 +671,21 @@ sub add_common_rules ( $ ) {
# #
$chainref = new_standard_chain 'sfilter'; $chainref = new_standard_chain 'sfilter';
log_rule_limit( $level, if ( $level ne '' ) {
my $ruleref = log_rule_limit( $level,
$chainref, $chainref,
$chainref->{name}, $chainref->{name},
$policy, $policy,
$globals{LOGLIMIT}, $globals{LOGLIMIT},
$tag, $tag,
'add', 'add',
'' ) if $level ne ''; '' );
$ruleref->{origin} = $origin{SFILTER_LOG_LEVEL};
}
add_ijump( $chainref, j => 'AUDIT', targetopts => '--type ' . lc $policy ) if $audit; add_ijump_extended( $chainref, j => 'AUDIT', $origin, targetopts => '--type ' . lc $policy ) if $audit;
add_ijump $chainref, g => $policy eq 'REJECT' ? 'reject' : $policy; add_ijump_extended( $chainref, g => $policy eq 'REJECT' ? 'reject' : $policy, $origin );
$target = 'sfilter'; $target = 'sfilter';
} else { } else {
@@ -697,11 +701,22 @@ sub add_common_rules ( $ ) {
$chainref = new_standard_chain 'sfilter1'; $chainref = new_standard_chain 'sfilter1';
add_ijump ( $chainref, j => 'RETURN', policy => '--pol ipsec --dir out' ); add_ijump ( $chainref, j => 'RETURN', policy => '--pol ipsec --dir out' );
log_rule $level , $chainref , $policy , '' if $level ne '';
add_ijump( $chainref, j => 'AUDIT', targetopts => '--type ' . lc $policy ) if $audit; if ( $level ne '' ) {
my $ruleref = log_rule_limit( $level,
$chainref,
$chainref->{name},
$policy,
$globals{LOGLIMIT},
$tag,
'add',
'' );
$ruleref->{origin} = $origin;
}
add_ijump $chainref, g => $policy eq 'REJECT' ? 'reject' : $policy; add_ijump_extended( $chainref, j => 'AUDIT', $origin{SFILTER_DISPOSITION}, targetopts => '--type ' . lc $policy ) if $audit;
add_ijump_extended( $chainref, g => $policy eq 'REJECT' ? 'reject' : $policy, $origin );
$target1 = 'sfilter1'; $target1 = 'sfilter1';
} else { } else {
@@ -721,13 +736,14 @@ sub add_common_rules ( $ ) {
unless ( $interfaceref->{options}{ignore} & NO_SFILTER || $interfaceref->{options}{rpfilter} ) { unless ( $interfaceref->{options}{ignore} & NO_SFILTER || $interfaceref->{options}{rpfilter} ) {
my @filters = @{$interfaceref->{filter}}; my @filters = @{$interfaceref->{filter}};
my $origin = $interfaceref->{origin};
$chainref = $filter_table->{forward_option_chain $interface}; $chainref = $filter_table->{forward_option_chain $interface};
if ( @filters ) { if ( @filters ) {
add_ijump( $chainref , @ipsec ? 'j' : 'g' => $target1, imatch_source_net( $_ ), @ipsec ), $chainref->{filtered}++ for @filters; add_ijump_extended( $chainref , @ipsec ? 'j' : 'g' => $target1, $origin, imatch_source_net( $_ ), @ipsec ), $chainref->{filtered}++ for @filters;
} elsif ( $interfaceref->{bridge} eq $interface ) { } elsif ( $interfaceref->{bridge} eq $interface ) {
add_ijump( $chainref , @ipsec ? 'j' : 'g' => $target1, imatch_dest_dev( $interface ), @ipsec ), $chainref->{filtered}++ add_ijump_extended( $chainref , @ipsec ? 'j' : 'g' => $target1, $origin, imatch_dest_dev( $interface ), @ipsec ), $chainref->{filtered}++
unless( $config{ROUTE_FILTER} eq 'on' || unless( $config{ROUTE_FILTER} eq 'on' ||
$interfaceref->{options}{routeback} || $interfaceref->{options}{routeback} ||
$interfaceref->{options}{routefilter} || $interfaceref->{options}{routefilter} ||
@@ -737,13 +753,13 @@ sub add_common_rules ( $ ) {
if ( @filters ) { if ( @filters ) {
$chainref = $filter_table->{input_option_chain $interface}; $chainref = $filter_table->{input_option_chain $interface};
add_ijump( $chainref , g => $target, imatch_source_net( $_ ), @ipsec ), $chainref->{filtered}++ for @filters; add_ijump_extended( $chainref , g => $target, $origin, imatch_source_net( $_ ), @ipsec ), $chainref->{filtered}++ for @filters;
} }
} }
for ( option_chains( $interface ) ) { for ( option_chains( $interface ) ) {
add_ijump( $filter_table->{$_}, j => $dynamicref, @state ) if $dynamicref; add_ijump_extended( $filter_table->{$_}, j => $dynamicref, $origin{DYNAMIC_BLACKLIST}, @state ) if $dynamicref;
add_ijump( $filter_table->{$_}, j => 'ACCEPT', state_imatch $faststate )->{comment} = '' if $config{FASTACCEPT}; add_ijump_extended( $filter_table->{$_}, j => 'ACCEPT', $origin{FASTACCEPT}, state_imatch $faststate )->{comment} = '' if $config{FASTACCEPT};
} }
} }
} }
@@ -764,6 +780,8 @@ sub add_common_rules ( $ ) {
$level = $config{RPFILTER_LOG_LEVEL}; $level = $config{RPFILTER_LOG_LEVEL};
$tag = $globals{RPFILTER_LOG_TAG}; $tag = $globals{RPFILTER_LOG_TAG};
$audit = $policy =~ s/^A_//; $audit = $policy =~ s/^A_//;
my $origin
= $origin{RPFILTER_DISPOSITION};
if ( $level || $audit ) { if ( $level || $audit ) {
# #
@@ -771,18 +789,21 @@ sub add_common_rules ( $ ) {
# #
$chainref = ensure_mangle_chain 'rplog'; $chainref = ensure_mangle_chain 'rplog';
log_rule_limit( $level, if ( $level ne '' ) {
my $ruleref = log_rule_limit( $level,
$chainref, $chainref,
$chainref->{name}, $chainref->{name},
$policy, $policy,
$globals{LOGLIMIT}, $globals{LOGLIMIT},
$tag, $tag,
'add', 'add',
'' ) if $level ne ''; '' );
$ruleref->{origin} = $origin{RPFILTER_LOG_LEVEL};
}
add_ijump( $chainref, j => 'AUDIT', targetopts => '--type ' . lc $policy ) if $audit; add_ijump_extended( $chainref, j => 'AUDIT', $origin, targetopts => '--type ' . lc $policy ) if $audit;
add_ijump $chainref, g => $policy eq 'REJECT' ? 'reject' : $policy; add_ijump_extended( $chainref, g => $policy eq 'REJECT' ? 'reject' : $policy, $origin );
$target = 'rplog'; $target = 'rplog';
} else { } else {
@@ -794,8 +815,9 @@ sub add_common_rules ( $ ) {
if ( $family == F_IPV4 ) { if ( $family == F_IPV4 ) {
for $interface ( @$list ) { for $interface ( @$list ) {
if ( get_interface_option( $interface, 'dhcp' ) ) { if ( get_interface_option( $interface, 'dhcp' ) ) {
add_ijump( $rpfilterref, add_ijump_extended( $rpfilterref,
j => 'RETURN', j => 'RETURN',
get_interface_origin( $interface ),
s => NILIPv4, s => NILIPv4,
p => UDP, p => UDP,
dport => 67, dport => 67,
@@ -806,8 +828,9 @@ sub add_common_rules ( $ ) {
} }
} }
add_ijump( $rpfilterref, add_ijump_extended( $rpfilterref,
j => $target, j => $target,
$origin,
rpfilter => '--validmark --invert', rpfilter => '--validmark --invert',
state_imatch 'NEW,RELATED,INVALID', state_imatch 'NEW,RELATED,INVALID',
@ipsec @ipsec
@@ -830,19 +853,24 @@ sub add_common_rules ( $ ) {
$chainref = new_standard_chain 'smurfs'; $chainref = new_standard_chain 'smurfs';
my $smurfdest = $config{SMURF_DISPOSITION}; my $smurfdest = $config{SMURF_DISPOSITION};
my $origin = $origin{SMURF_DISPOSITION};
if ( supplied $config{SMURF_LOG_LEVEL} ) { if ( supplied $config{SMURF_LOG_LEVEL} ) {
my $smurfref = new_chain( 'filter', 'smurflog' ); my $smurfref = new_chain( 'filter', 'smurflog' );
log_irule_limit( $config{SMURF_LOG_LEVEL}, my $ruleref = log_irule_limit( $config{SMURF_LOG_LEVEL},
$smurfref, $smurfref,
'smurfs' , 'smurfs' ,
'DROP', 'DROP',
$globals{LOGILIMIT}, $globals{LOGILIMIT},
$globals{SMURF_LOG_TAG}, $globals{SMURF_LOG_TAG},
'add' ); 'add' );
add_ijump( $smurfref, j => 'AUDIT', targetopts => '--type drop' ) if $smurfdest eq 'A_DROP';
add_ijump( $smurfref, j => 'DROP' ); $ruleref->{origin} = $origin{SMURF_LOG_LEVEL};
add_ijump_extended( $smurfref, j => 'AUDIT', $origin, targetopts => '--type drop' ) if $smurfdest eq 'A_DROP';
add_ijump_extended( $smurfref, j => 'DROP' , $origin );
$smurfdest = 'smurflog'; $smurfdest = 'smurflog';
} else { } else {
@@ -856,7 +884,7 @@ sub add_common_rules ( $ ) {
add_ijump $chainref , j => 'RETURN', s => '::'; add_ijump $chainref , j => 'RETURN', s => '::';
} }
add_ijump( $chainref, g => $smurfdest, addrtype => '--src-type BROADCAST' ) ; add_ijump_extended( $chainref, g => $smurfdest, $origin, addrtype => '--src-type BROADCAST' ) ;
} else { } else {
if ( $family == F_IPV4 ) { if ( $family == F_IPV4 ) {
add_commands $chainref, 'for address in $ALL_BCASTS; do'; add_commands $chainref, 'for address in $ALL_BCASTS; do';
@@ -865,15 +893,15 @@ sub add_common_rules ( $ ) {
} }
incr_cmd_level $chainref; incr_cmd_level $chainref;
add_ijump( $chainref, g => $smurfdest, s => '$address' ); add_ijump_extended( $chainref, g => $smurfdest, $origin, s => '$address' );
decr_cmd_level $chainref; decr_cmd_level $chainref;
add_commands $chainref, 'done'; add_commands $chainref, 'done';
} }
if ( $family == F_IPV4 ) { if ( $family == F_IPV4 ) {
add_ijump( $chainref, g => $smurfdest, s => '224.0.0.0/4' ); add_ijump_extended( $chainref, g => $smurfdest, $origin, s => '224.0.0.0/4' );
} else { } else {
add_ijump( $chainref, g => $smurfdest, s => IPv6_MULTICAST ); add_ijump_extended( $chainref, g => $smurfdest, $origin, s => IPv6_MULTICAST );
} }
my @state = have_capability( 'RAW_TABLE' ) ? state_imatch 'NEW,INVALID,UNTRACKED' : state_imatch 'NEW,INVALID'; my @state = have_capability( 'RAW_TABLE' ) ? state_imatch 'NEW,INVALID,UNTRACKED' : state_imatch 'NEW,INVALID';
@@ -881,11 +909,13 @@ sub add_common_rules ( $ ) {
for my $hostref ( @$list ) { for my $hostref ( @$list ) {
$interface = $hostref->[0]; $interface = $hostref->[0];
my $ipsec = $hostref->[1]; my $ipsec = $hostref->[1];
my $net = $hostref->[2];
my @policy = $ipsec && have_ipsec ? ( policy => "--pol $ipsec --dir in" ) : (); my @policy = $ipsec && have_ipsec ? ( policy => "--pol $ipsec --dir in" ) : ();
my $target = source_exclusion( $hostref->[3], $chainref ); my $target = source_exclusion( $hostref->[3], $chainref );
my $origin = $hostref->[5];
for $chain ( option_chains $interface ) { for $chain ( option_chains $interface ) {
add_ijump( $filter_table->{$chain} , j => $target, @state, imatch_source_net( $hostref->[2] ), @policy ); add_ijump_extended( $filter_table->{$chain} , j => $target, $origin, @state, imatch_source_net( $net ), @policy );
} }
} }
} }
@@ -938,19 +968,25 @@ sub add_common_rules ( $ ) {
my $ports = $family == F_IPV4 ? '67:68' : '546:547'; my $ports = $family == F_IPV4 ? '67:68' : '546:547';
for $interface ( @$list ) { for $interface ( @$list ) {
set_rule_option( add_ijump( $filter_table->{$_} , j => 'ACCEPT', p => "udp --dport $ports" ) , my $origin = get_interface_origin($interface);
set_rule_option( add_ijump_extended( $filter_table->{$_} ,
j => 'ACCEPT',
$origin,
p => "udp --dport $ports" ) ,
'dhcp', 'dhcp',
1 ) for input_option_chain( $interface ), output_option_chain( $interface ); 1 ) for input_option_chain( $interface ), output_option_chain( $interface );
add_ijump( $filter_table->{forward_option_chain $interface} , add_ijump_extended( $filter_table->{forward_option_chain $interface} ,
j => 'ACCEPT', j => 'ACCEPT',
$origin,
p => "udp --dport $ports" , p => "udp --dport $ports" ,
imatch_dest_dev( $interface ) ) imatch_dest_dev( $interface ) )
if get_interface_option( $interface, 'bridge' ); if get_interface_option( $interface, 'bridge' );
unless ( $family == F_IPV6 || get_interface_option( $interface, 'allip' ) ) { unless ( $family == F_IPV6 || get_interface_option( $interface, 'allip' ) ) {
add_ijump( $filter_table->{input_chain( $interface ) } , add_ijump_extended( $filter_table->{input_chain( $interface ) } ,
j => 'ACCEPT' , j => 'ACCEPT' ,
$origin ,
p => "udp --dport $ports" , p => "udp --dport $ports" ,
s => NILIPv4 . '/' . VLSMv4 ); s => NILIPv4 . '/' . VLSMv4 );
} }
@@ -964,6 +1000,7 @@ sub add_common_rules ( $ ) {
my $tag = $globals{TCP_FLAGS_LOG_TAG}; my $tag = $globals{TCP_FLAGS_LOG_TAG};
my $disposition = $config{TCP_FLAGS_DISPOSITION}; my $disposition = $config{TCP_FLAGS_DISPOSITION};
my $audit = $disposition =~ /^A_/; my $audit = $disposition =~ /^A_/;
my $origin = $origin{TCP_FLAGS_DISPOSITION};
progress_message2 "$doing TCP Flags filtering..."; progress_message2 "$doing TCP Flags filtering...";
@@ -976,27 +1013,28 @@ sub add_common_rules ( $ ) {
$globals{LOGPARMS} = "$globals{LOGPARMS}--log-ip-options "; $globals{LOGPARMS} = "$globals{LOGPARMS}--log-ip-options ";
log_rule_limit( $level, my $ruleref = log_rule_limit( $level,
$logflagsref, $logflagsref,
'logflags', 'logflags',
$disposition, $disposition,
$globals{LOGLIMIT}, $globals{LOGLIMIT},
$tag, $tag,
'add', 'add',
'' '' );
);
$ruleref->{origin} = $origin{TCP_FLAGS_LOG_LEVEL};
$globals{LOGPARMS} = $savelogparms; $globals{LOGPARMS} = $savelogparms;
if ( $audit ) { if ( $audit ) {
$disposition =~ s/^A_//; $disposition =~ s/^A_//;
add_ijump( $logflagsref, j => 'AUDIT', targetopts => '--type ' . lc $disposition ); add_ijump_extended( $logflagsref, j => 'AUDIT', $origin, targetopts => '--type ' . lc $disposition );
} }
if ( $disposition eq 'REJECT' ) { if ( $disposition eq 'REJECT' ) {
add_ijump $logflagsref , j => 'REJECT', targetopts => '--reject-with tcp-reset', p => 6; add_ijump_extended $logflagsref , j => 'REJECT', $origin, targetopts => '--reject-with tcp-reset', p => 6;
} else { } else {
add_ijump $logflagsref , j => $disposition; add_ijump_extended $logflagsref , j => $disposition, $origin;
} }
$disposition = 'logflags'; $disposition = 'logflags';
@@ -1018,9 +1056,10 @@ sub add_common_rules ( $ ) {
my $target = source_exclusion( $hostref->[3], $chainref ); my $target = source_exclusion( $hostref->[3], $chainref );
my $ipsec = $hostref->[1]; my $ipsec = $hostref->[1];
my @policy = $ipsec && have_ipsec ? ( policy => "--pol $ipsec --dir in" ) : (); my @policy = $ipsec && have_ipsec ? ( policy => "--pol $ipsec --dir in" ) : ();
my $origin = $hostref->[5];
for $chain ( option_chains $interface ) { for $chain ( option_chains $interface ) {
add_ijump( $filter_table->{$chain} , j => $target, p => 'tcp', imatch_source_net( $hostref->[2] ), @policy ); add_ijump_extended( $filter_table->{$chain} , j => $target, $origin, p => 'tcp', imatch_source_net( $hostref->[2] ), @policy );
} }
} }
} }
@@ -1040,7 +1079,7 @@ sub add_common_rules ( $ ) {
$announced = 1; $announced = 1;
for $interface ( @$list ) { for $interface ( @$list ) {
add_ijump $nat_table->{PREROUTING} , j => 'UPnP', imatch_source_dev ( $interface ); add_ijump_extended $nat_table->{PREROUTING} , j => 'UPnP', get_interface_origin($interface), imatch_source_dev ( $interface );
} }
} }
@@ -1054,16 +1093,17 @@ sub add_common_rules ( $ ) {
my $base = uc var_base get_physical $interface; my $base = uc var_base get_physical $interface;
my $optional = interface_is_optional( $interface ); my $optional = interface_is_optional( $interface );
my $variable = get_interface_gateway( $interface, ! $optional ); my $variable = get_interface_gateway( $interface, ! $optional );
my $origin = get_interface_origin( $interface );
if ( $optional ) { if ( $optional ) {
add_commands( $chainref, add_commands( $chainref,
qq(if [ -n "SW_\$${base}_IS_USABLE" -a -n "$variable" ]; then) ); qq(if [ -n "SW_\$${base}_IS_USABLE" -a -n "$variable" ]; then) );
incr_cmd_level( $chainref ); incr_cmd_level( $chainref );
add_ijump( $chainref, j => 'ACCEPT', imatch_source_dev( $interface ), s => $variable, p => 'udp' ); add_ijump_extended( $chainref, j => 'ACCEPT', $origin, imatch_source_dev( $interface ), s => $variable, p => 'udp' );
decr_cmd_level( $chainref ); decr_cmd_level( $chainref );
add_commands( $chainref, 'fi' ); add_commands( $chainref, 'fi' );
} else { } else {
add_ijump( $chainref, j => 'ACCEPT', imatch_source_dev( $interface ), s => $variable, p => 'udp' ); add_ijump_extended( $chainref, j => 'ACCEPT', $origin, imatch_source_dev( $interface ), s => $variable, p => 'udp' );
} }
} }
} }
@@ -1191,6 +1231,7 @@ sub setup_mac_lists( $ ) {
my $ipsec = $hostref->[1]; my $ipsec = $hostref->[1];
my @policy = $ipsec && have_ipsec ? ( policy => "--pol $ipsec --dir in" ) : (); my @policy = $ipsec && have_ipsec ? ( policy => "--pol $ipsec --dir in" ) : ();
my @source = imatch_source_net $hostref->[2]; my @source = imatch_source_net $hostref->[2];
my $origin = $hostref->[5];
my @state = have_capability( 'RAW_TABLE' ) ? state_imatch 'NEW,UNTRACKED' : state_imatch 'NEW'; my @state = have_capability( 'RAW_TABLE' ) ? state_imatch 'NEW,UNTRACKED' : state_imatch 'NEW';
@@ -1198,11 +1239,11 @@ sub setup_mac_lists( $ ) {
my $chainref = source_exclusion( $hostref->[3], $filter_table->{mac_chain $interface} ); my $chainref = source_exclusion( $hostref->[3], $filter_table->{mac_chain $interface} );
for my $chain ( option_chains $interface ) { for my $chain ( option_chains $interface ) {
add_ijump $filter_table->{$chain} , j => $chainref, @source, @state, @policy; add_ijump_extended $filter_table->{$chain} , j => $chainref, $origin, @source, @state, @policy;
} }
} else { } else {
my $chainref = source_exclusion( $hostref->[3], $mangle_table->{mac_chain $interface} ); my $chainref = source_exclusion( $hostref->[3], $mangle_table->{mac_chain $interface} );
add_ijump $mangle_table->{PREROUTING}, j => $chainref, imatch_source_dev( $interface ), @source, @state, @policy; add_ijump_extended $mangle_table->{PREROUTING}, j => $chainref, $origin, imatch_source_dev( $interface ), @source, @state, @policy;
} }
} }
} else { } else {
@@ -1293,8 +1334,8 @@ sub rules_target( $$ ) {
# #
# Generate rules for one destination zone # Generate rules for one destination zone
# #
sub generate_dest_rules( $$$;@ ) { sub generate_dest_rules( $$$$;@ ) {
my ( $chainref, $chain, $z2, @matches ) = @_; my ( $chainref, $chain, $z2, $origin, @matches ) = @_;
my $z2ref = find_zone( $z2 ); my $z2ref = find_zone( $z2 );
my $type2 = $z2ref->{type}; my $type2 = $z2ref->{type};
@@ -1302,16 +1343,18 @@ sub generate_dest_rules( $$$;@ ) {
if ( $type2 & VSERVER ) { if ( $type2 & VSERVER ) {
for my $hostref ( @{$z2ref->{hosts}{ip}{'%vserver%'}} ) { for my $hostref ( @{$z2ref->{hosts}{ip}{'%vserver%'}} ) {
my $exclusion = dest_exclusion( $hostref->{exclusions}, $chain); my $exclusion = dest_exclusion( $hostref->{exclusions}, $chain);
my $origin = $hostref->{origin};
for my $net ( @{$hostref->{hosts}} ) { for my $net ( @{$hostref->{hosts}} ) {
add_ijump( $chainref, add_ijump_extended( $chainref,
j => $exclusion , j => $exclusion ,
$origin,
imatch_dest_net ( $net ), imatch_dest_net ( $net ),
@matches ); @matches );
} }
} }
} else { } else {
add_ijump( $chainref, j => $chain, @matches ); add_ijump_extended( $chainref, j => $chain, $origin, @matches );
} }
} }
@@ -1329,11 +1372,13 @@ sub generate_source_rules( $$$;@ ) {
for my $hostref ( @{defined_zone( $z1 )->{hosts}{ip}{'%vserver%'}} ) { for my $hostref ( @{defined_zone( $z1 )->{hosts}{ip}{'%vserver%'}} ) {
my @ipsec_match = match_ipsec_in $z1 , $hostref; my @ipsec_match = match_ipsec_in $z1 , $hostref;
my $exclusion = source_exclusion( $hostref->{exclusions}, $chain); my $exclusion = source_exclusion( $hostref->{exclusions}, $chain);
my $origin = $hostref->{origin};
for my $net ( @{$hostref->{hosts}} ) { for my $net ( @{$hostref->{hosts}} ) {
generate_dest_rules( $outchainref, generate_dest_rules( $outchainref,
$exclusion, $exclusion,
$z2, $z2,
$origin,
imatch_source_net( $net ), imatch_source_net( $net ),
@matches , @matches ,
@ipsec_match @ipsec_match
@@ -1402,7 +1447,7 @@ sub handle_loopback_traffic() {
next if $z1 eq $z2 && ( $loopback || $unmanaged ); next if $z1 eq $z2 && ( $loopback || $unmanaged );
my $chain = rules_target( $z1, $z2 ); my $chain = rules_target( $z1, $z2 );
generate_dest_rules( $outchainref, $chain, $z2, @rule ) if $chain; generate_dest_rules( $outchainref, $chain, $z2, '', @rule ) if $chain;
} }
# #
# Handle conntrack # Handle conntrack
@@ -1641,10 +1686,12 @@ sub handle_complex_zone( $$ ) {
# #
for my $hostref ( @{$arrayref} ) { for my $hostref ( @{$arrayref} ) {
my @ipsec_match = match_ipsec_in $zone , $hostref; my @ipsec_match = match_ipsec_in $zone , $hostref;
my $origin = $hostref->{origin};
for my $net ( @{$hostref->{hosts}} ) { for my $net ( @{$hostref->{hosts}} ) {
add_ijump( add_ijump_extended(
$sourcechainref, $sourcechainref,
@{$zoneref->{parents}} ? 'j' : 'g' => source_exclusion( $hostref->{exclusions}, $frwd_ref ), @{$zoneref->{parents}} ? 'j' : 'g' => source_exclusion( $hostref->{exclusions}, $frwd_ref ),
$origin,
@interfacematch , @interfacematch ,
imatch_source_net( $net ), imatch_source_net( $net ),
@ipsec_match @ipsec_match
@@ -1703,8 +1750,8 @@ sub handle_nested_zone( $$ ) {
# #
# Add output jump to the passed zone:interface:hostref:net # Add output jump to the passed zone:interface:hostref:net
# #
sub add_output_jumps( $$$$$$$ ) { sub add_output_jumps( $$$$$$$$ ) {
my ( $zone, $interface, $hostref, $net, $exclusions, $isport, $bridge, ) = @_; my ( $zone, $interface, $hostref, $net, $exclusions, $isport, $bridge, $origin ) = @_;
our @vservers; our @vservers;
our %output_jump_added; our %output_jump_added;
@@ -1733,15 +1780,16 @@ sub add_output_jumps( $$$$$$$ ) {
# #
# It is a bridge port zone -- use the bridges output chain and match the physdev # It is a bridge port zone -- use the bridges output chain and match the physdev
# #
add_ijump( $filter_table->{ output_chain $bridge }, add_ijump_extended( $filter_table->{ output_chain $bridge },
j => $outputref , j => $outputref ,
$origin ,
imatch_dest_dev( $interface, 1 ) ) imatch_dest_dev( $interface, 1 ) )
unless $output_jump_added{$interface}++; unless $output_jump_added{$interface}++;
} else { } else {
# #
# Not a bridge -- match the input interface # Not a bridge -- match the input interface
# #
add_ijump $filter_table->{OUTPUT}, j => $outputref, imatch_dest_dev( $interface ) unless $output_jump_added{$interface}++; add_ijump_extended $filter_table->{OUTPUT}, j => $outputref, $origin, imatch_dest_dev( $interface ) unless $output_jump_added{$interface}++;
} }
$use_output = 1; $use_output = 1;
@@ -1770,11 +1818,11 @@ sub add_output_jumps( $$$$$$$ ) {
# #
# Add the jump # Add the jump
# #
add_ijump $outputref , j => $nextchain, @interfacematch, @dest, @ipsec_out_match; add_ijump_extended $outputref , j => $nextchain, $origin, @interfacematch, @dest, @ipsec_out_match;
# #
# Add jump for broadcast # Add jump for broadcast
# #
add_ijump( $outputref , j => $nextchain, @interfacematch, d => '255.255.255.255' , @ipsec_out_match ) add_ijump_extended( $outputref , j => $nextchain, get_interface_origin( $interface ), @interfacematch, d => '255.255.255.255' , @ipsec_out_match )
if $family == F_IPV4 && $hostref->{options}{broadcast}; if $family == F_IPV4 && $hostref->{options}{broadcast};
# #
# Move the rules from the interface output chain if we didn't use it # Move the rules from the interface output chain if we didn't use it
@@ -1785,8 +1833,8 @@ sub add_output_jumps( $$$$$$$ ) {
# #
# Add prerouting jumps from the passed zone:interface:hostref:net # Add prerouting jumps from the passed zone:interface:hostref:net
# #
sub add_prerouting_jumps( $$$$$$$$ ) { sub add_prerouting_jumps( $$$$$$$$$ ) {
my ( $zone, $interface, $hostref, $net, $exclusions, $nested, $parenthasnat, $parenthasnotrack ) = @_; my ( $zone, $interface, $hostref, $net, $exclusions, $nested, $parenthasnat, $parenthasnotrack , $origin ) = @_;
my $dnatref = $nat_table->{dnat_chain( $zone )}; my $dnatref = $nat_table->{dnat_chain( $zone )};
my $preroutingref = $nat_table->{PREROUTING}; my $preroutingref = $nat_table->{PREROUTING};
@@ -1801,8 +1849,9 @@ sub add_prerouting_jumps( $$$$$$$$ ) {
# There are DNAT/REDIRECT rules with this zone as the source. # There are DNAT/REDIRECT rules with this zone as the source.
# Add a jump from this source network to this zone's DNAT/REDIRECT chain # Add a jump from this source network to this zone's DNAT/REDIRECT chain
# #
add_ijump( $preroutingref, add_ijump_extended( $preroutingref,
j => source_exclusion( $exclusions, $dnatref), j => source_exclusion( $exclusions, $dnatref),
$origin,
imatch_source_dev( $interface), imatch_source_dev( $interface),
@source, @source,
@ipsec_in_match ); @ipsec_in_match );
@@ -1823,7 +1872,7 @@ sub add_prerouting_jumps( $$$$$$$$ ) {
# #
if ( $nested ) { if ( $nested ) {
if ( $parenthasnat ) { if ( $parenthasnat ) {
add_ijump $preroutingref, j => 'RETURN', imatch_source_dev( $interface), @source, @ipsec_in_match; add_ijump_extended $preroutingref, j => 'RETURN', $origin, imatch_source_dev( $interface), @source, @ipsec_in_match;
} }
if ( $parenthasnotrack ) { if ( $parenthasnotrack ) {
my $rawref = $raw_table->{PREROUTING}; my $rawref = $raw_table->{PREROUTING};
@@ -1835,8 +1884,8 @@ sub add_prerouting_jumps( $$$$$$$$ ) {
# #
# Add input jump from the passed zone:interface:hostref:net # Add input jump from the passed zone:interface:hostref:net
# #
sub add_input_jumps( $$$$$$$$ ) { sub add_input_jumps( $$$$$$$$$ ) {
my ( $zone, $interface, $hostref, $net, $exclusions, $frwd_ref, $isport, $bridge ) = @_; my ( $zone, $interface, $hostref, $net, $exclusions, $frwd_ref, $isport, $bridge, $origin ) = @_;
our @vservers; our @vservers;
our %input_jump_added; our %input_jump_added;
@@ -1865,15 +1914,16 @@ sub add_input_jumps( $$$$$$$$ ) {
# #
# It is a bridge port zone -- use the bridges input chain and match the physdev # It is a bridge port zone -- use the bridges input chain and match the physdev
# #
add_ijump( $filter_table->{ input_chain $bridge }, add_ijump_extended( $filter_table->{ input_chain $bridge },
j => $inputchainref , j => $inputchainref ,
$origin ,
imatch_source_dev($interface, 1) ) imatch_source_dev($interface, 1) )
unless $input_jump_added{$interface}++; unless $input_jump_added{$interface}++;
} else { } else {
# #
# Not a bridge -- match the input interface # Not a bridge -- match the input interface
# #
add_ijump $filter_table->{INPUT}, j => $inputchainref, imatch_source_dev($interface) unless $input_jump_added{$interface}++; add_ijump_extended $filter_table->{INPUT}, j => $inputchainref, $origin, imatch_source_dev($interface) unless $input_jump_added{$interface}++;
} }
$use_input = 1; $use_input = 1;
@@ -1884,7 +1934,7 @@ sub add_input_jumps( $$$$$$$$ ) {
# #
for my $vzone ( @vservers ) { for my $vzone ( @vservers ) {
my $target = rules_target( $zone, $vzone ); my $target = rules_target( $zone, $vzone );
generate_dest_rules( $inputchainref, $target, $vzone, @source, @ipsec_in_match ) if $target; generate_dest_rules( $inputchainref, $target, $vzone, $origin, @source, @ipsec_in_match ) if $target;
} }
} }
} elsif ( $isport ) { } elsif ( $isport ) {
@@ -1905,7 +1955,7 @@ sub add_input_jumps( $$$$$$$$ ) {
# #
# Add the jump from the input chain to the rules chain # Add the jump from the input chain to the rules chain
# #
add_ijump $inputchainref, j => source_exclusion( $exclusions, $chain2 ), @interfacematch, @source, @ipsec_in_match; add_ijump_extended $inputchainref, j => source_exclusion( $exclusions, $chain2 ), $origin, @interfacematch, @source, @ipsec_in_match;
move_rules( $interfacechainref , $chain2ref ) unless $use_input; move_rules( $interfacechainref , $chain2ref ) unless $use_input;
} }
} }
@@ -1913,8 +1963,8 @@ sub add_input_jumps( $$$$$$$$ ) {
# #
# This function is called when there is forwarding and this net isn't IPSEC protected. It adds the jump for this net to the zone forwarding chain. # This function is called when there is forwarding and this net isn't IPSEC protected. It adds the jump for this net to the zone forwarding chain.
# #
sub add_forward_jump( $$$$$$$$ ) { sub add_forward_jump( $$$$$$$$$ ) {
my ( $zone, $interface, $hostref, $net, $exclusions, $frwd_ref, $isport, $bridge ) = @_; my ( $zone, $interface, $hostref, $net, $exclusions, $frwd_ref, $isport, $bridge, $origin ) = @_;
our %forward_jump_added; our %forward_jump_added;
@@ -1928,29 +1978,31 @@ sub add_forward_jump( $$$$$$$$ ) {
# #
# We must use the interface forwarding chain -- add the jump from the interface forward chain to the zone forward chain. # We must use the interface forwarding chain -- add the jump from the interface forward chain to the zone forward chain.
# #
add_ijump $forwardref , j => $ref, @source, @ipsec_in_match; add_ijump_extended $forwardref , j => $ref, $origin, @source, @ipsec_in_match;
if ( $isport ) { if ( $isport ) {
# #
# It is a bridge port zone -- use the bridges input chain and match the physdev # It is a bridge port zone -- use the bridges input chain and match the physdev
# #
add_ijump( $filter_table->{ forward_chain $bridge } , add_ijump_extended( $filter_table->{ forward_chain $bridge } ,
j => $forwardref , j => $forwardref ,
$origin ,
imatch_source_dev( $interface , 1 ) ) imatch_source_dev( $interface , 1 ) )
unless $forward_jump_added{$interface}++; unless $forward_jump_added{$interface}++;
} else { } else {
# #
# Not a bridge -- match the input interface # Not a bridge -- match the input interface
# #
add_ijump $filter_table->{FORWARD} , j => $forwardref, imatch_source_dev( $interface ) unless $forward_jump_added{$interface}++; add_ijump_extended $filter_table->{FORWARD} , j => $forwardref, $origin, imatch_source_dev( $interface ) unless $forward_jump_added{$interface}++;
} }
} else { } else {
if ( $isport ) { if ( $isport ) {
# #
# It is a bridge port zone -- use the bridges input chain and match the physdev # It is a bridge port zone -- use the bridges input chain and match the physdev
# #
add_ijump( $filter_table->{ forward_chain $bridge } , add_ijump_extended( $filter_table->{ forward_chain $bridge } ,
j => $ref , j => $ref ,
$origin ,
imatch_source_dev( $interface, 1 ) , imatch_source_dev( $interface, 1 ) ,
@source, @source,
@ipsec_in_match ); @ipsec_in_match );
@@ -1958,7 +2010,7 @@ sub add_forward_jump( $$$$$$$$ ) {
# #
# Not a bridge -- match the input interface # Not a bridge -- match the input interface
# #
add_ijump $filter_table->{FORWARD} , j => $ref, imatch_source_dev( $interface ) , @source, @ipsec_in_match; add_ijump_extended $filter_table->{FORWARD} , j => $ref, $origin, imatch_source_dev( $interface ) , @source, @ipsec_in_match;
} }
move_rules ( $forwardref , $frwd_ref ); move_rules ( $forwardref , $frwd_ref );
@@ -2099,6 +2151,7 @@ sub generate_matrix() {
for my $hostref ( @{$typeref->{$interface}} ) { for my $hostref ( @{$typeref->{$interface}} ) {
my $exclusions = $hostref->{exclusions}; my $exclusions = $hostref->{exclusions};
my $origin = $hostref->{origin};
for my $net ( @{$hostref->{hosts}} ) { for my $net ( @{$hostref->{hosts}} ) {
# #
@@ -2108,7 +2161,7 @@ sub generate_matrix() {
# #
# Policy from the firewall to this zone is not 'CONTINUE' and this isn't a bport zone # Policy from the firewall to this zone is not 'CONTINUE' and this isn't a bport zone
# #
add_output_jumps( $zone, $interface, $hostref, $net, $exclusions, $isport, $bridge ); add_output_jumps( $zone, $interface, $hostref, $net, $exclusions, $isport, $bridge, $origin );
} }
clearrule; clearrule;
@@ -2117,15 +2170,15 @@ sub generate_matrix() {
# #
# PREROUTING # PREROUTING
# #
add_prerouting_jumps( $zone, $interface, $hostref, $net, $exclusions, $nested, $parenthasnat, $parenthasnotrack ); add_prerouting_jumps( $zone, $interface, $hostref, $net, $exclusions, $nested, $parenthasnat, $parenthasnotrack , $origin );
# #
# INPUT # INPUT
# #
add_input_jumps( $zone, $interface, $hostref, $net, $exclusions, $frwd_ref, $isport, $bridge ); add_input_jumps( $zone, $interface, $hostref, $net, $exclusions, $frwd_ref, $isport, $bridge , $origin );
# #
# FORWARDING Jump for non-IPSEC host group # FORWARDING Jump for non-IPSEC host group
# #
add_forward_jump( $zone, $interface, $hostref, $net, $exclusions, $frwd_ref, $isport, $bridge ) if $frwd_ref && $hostref->{ipsec} ne 'ipsec'; add_forward_jump( $zone, $interface, $hostref, $net, $exclusions, $frwd_ref, $isport, $bridge, $origin ) if $frwd_ref && $hostref->{ipsec} ne 'ipsec';
} }
} # Subnet Loop } # Subnet Loop
} # Hostref Loop } # Hostref Loop
@@ -2177,8 +2230,9 @@ sub generate_matrix() {
if ( $zone ne $zone1 || $num_ifaces > 1 || $hostref->{options}{routeback} ) { if ( $zone ne $zone1 || $num_ifaces > 1 || $hostref->{options}{routeback} ) {
my @ipsec_out_match = match_ipsec_out $zone1 , $hostref; my @ipsec_out_match = match_ipsec_out $zone1 , $hostref;
my $dest_exclusion = dest_exclusion( $hostref->{exclusions}, $chain); my $dest_exclusion = dest_exclusion( $hostref->{exclusions}, $chain);
my $origin = $hostref->{origin};
for my $net ( @{$hostref->{hosts}} ) { for my $net ( @{$hostref->{hosts}} ) {
add_ijump $frwd_ref, j => $dest_exclusion, imatch_dest_dev( $interface) , imatch_dest_net($net), @ipsec_out_match; add_ijump_extended $frwd_ref, j => $dest_exclusion, $origin, imatch_dest_dev( $interface) , imatch_dest_net($net), @ipsec_out_match;
} }
} }
} }
@@ -2220,17 +2274,19 @@ sub generate_matrix() {
nat=> [ qw/PREROUTING OUTPUT POSTROUTING/ ] , nat=> [ qw/PREROUTING OUTPUT POSTROUTING/ ] ,
filter=> [ qw/INPUT FORWARD OUTPUT/ ] ); filter=> [ qw/INPUT FORWARD OUTPUT/ ] );
my $origin = $origin{LOGALLNEW};
for my $table ( qw/mangle nat filter/ ) { for my $table ( qw/mangle nat filter/ ) {
for my $chain ( @{$builtins{$table}} ) { for my $chain ( @{$builtins{$table}} ) {
log_rule_limit my $ruleref = log_rule_limit( $config{LOGALLNEW} ,
$config{LOGALLNEW} ,
$chain_table{$table}{$chain} , $chain_table{$table}{$chain} ,
$table , $table ,
$chain , $chain ,
'' , '' ,
'' , '' ,
'insert' , 'insert' ,
state_match('NEW'); state_match('NEW') );
$ruleref->{origin} = $origin;
} }
} }
} }

View File

@@ -36,7 +36,7 @@ use strict;
our @ISA = qw(Exporter); our @ISA = qw(Exporter);
our @EXPORT = qw( setup_conntrack ); our @EXPORT = qw( setup_conntrack );
our @EXPORT_OK = qw( handle_helper_rule ); our @EXPORT_OK = qw( handle_helper_rule );
our $VERSION = '4.6_10'; our $VERSION = 'MODULEVERSION';
our %valid_ctevent = ( new => 1, our %valid_ctevent = ( new => 1,
related => 1, related => 1,

View File

@@ -79,6 +79,10 @@ use constant { NULL_SECTION => 0x00,
NEW_SECTION => 0x40, NEW_SECTION => 0x40,
DEFAULTACTION_SECTION => 0x80 }; DEFAULTACTION_SECTION => 0x80 };
# #
# Number of elements in the action tuple
#
use constant { ACTION_TUPLE_ELEMENTS => 5 };
#
# Section => name function # Section => name function
# #
our %section_functions = ( ALL_SECTION , \&rules_chain, our %section_functions = ( ALL_SECTION , \&rules_chain,
@@ -424,6 +428,7 @@ sub print_policy($$$$) {
sub use_policy_action( $$ ); sub use_policy_action( $$ );
sub normalize_action( $$$ ); sub normalize_action( $$$ );
sub normalize_action_name( $ ); sub normalize_action_name( $ );
sub normalize_single_action( $ );
sub process_default_action( $$$$ ) { sub process_default_action( $$$$ ) {
my ( $originalpolicy, $policy, $default, $level ) = @_; my ( $originalpolicy, $policy, $default, $level ) = @_;
@@ -441,7 +446,7 @@ sub process_default_action( $$$$ ) {
if ( "\L$default" eq 'none' ) { if ( "\L$default" eq 'none' ) {
if ( supplied $param || ( supplied $level && $level ne 'none' ) ) { if ( supplied $param || ( supplied $level && $level ne 'none' ) ) {
if ( $default_option ) { if ( $default_option ) {
fatal_error "Invalid setting (originalpolicy) for $policy"; fatal_error "Invalid setting ($originalpolicy) for $policy";
} else { } else {
fatal_error "Invalid policy ($originalpolicy)"; fatal_error "Invalid policy ($originalpolicy)";
} }
@@ -560,7 +565,7 @@ sub process_a_policy() {
require_capability 'AUDIT_TARGET', ":audit", "s" if $audit; require_capability 'AUDIT_TARGET', ":audit", "s" if $audit;
my ( $policy, $default, $level, $remainder ) = split( /:/, $originalpolicy, 4 ); my ( $policy, $default, $level, undef, $remainder ) = split( /:/, $originalpolicy, ACTION_TUPLE_ELEMENTS );
fatal_error "Invalid or missing POLICY ($originalpolicy)" unless $policy; fatal_error "Invalid or missing POLICY ($originalpolicy)" unless $policy;
@@ -944,7 +949,7 @@ sub complete_standard_chain ( $$$$ ) {
( $policy, $loglevel, $defaultaction ) = @{$policychainref}{'policy', 'loglevel', 'default' }; ( $policy, $loglevel, $defaultaction ) = @{$policychainref}{'policy', 'loglevel', 'default' };
$stdchainref->{origin} = $policychainref->{origin}; $stdchainref->{origin} = $policychainref->{origin};
} elsif ( $defaultaction !~ /:/ ) { } elsif ( $defaultaction !~ /:/ ) {
$defaultaction = join(":", $defaultaction, 'none', '', '' ); $defaultaction = normalize_single_action( $defaultaction );
} }
@@ -1169,14 +1174,15 @@ sub finish_section ( $ ) {
# #
# 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 5-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, calling chain and params.
# are separated by ":". # The pieces of the tuple are separated by ":".
# #
sub normalize_action( $$$ ) { sub normalize_action( $$$ ) {
my $action = shift; my $action = shift;
my $level = shift; my $level = shift;
my $param = shift; my $param = shift;
my $caller = ''; #We assume that the function doesn't use @CALLER
( $level, my $tag ) = split ':', $level; ( $level, my $tag ) = split ':', $level;
@@ -1185,13 +1191,23 @@ sub normalize_action( $$$ ) {
$param = '' unless defined $param; $param = '' unless defined $param;
$param = '' if $param eq '-'; $param = '' if $param eq '-';
join( ':', $action, $level, $tag, $param ); join( ':', $action, $level, $tag, $caller, $param );
}
#
# Add the actual caller into an existing normalised name
#
sub insert_caller($$) {
my ( $normalized, $caller ) = @_;
my ( $action, $level, $tag, undef, $param ) = split /:/, $normalized;
join( ':', $action, $level, $tag, $caller, $param );
} }
# #
# Accepts a rule target and returns a normalized tuple # Accepts a rule target and returns a normalized tuple
# #
sub normalize_action_name( $ ) { sub normalize_action_name( $ ) {
my $target = shift; my $target = shift;
my ( $action, $loglevel) = split_action $target; my ( $action, $loglevel) = split_action $target;
@@ -1199,11 +1215,18 @@ sub normalize_action_name( $ ) {
normalize_action( $action, $loglevel, '' ); normalize_action( $action, $loglevel, '' );
} }
#
# Create an action tuple from a single target name
#
sub normalize_single_action( $ ) {
join(":", $_[0], 'none', '', '', '' );
}
# #
# Produce a recognizable target from a normalized action # Produce a recognizable target from a normalized action
# #
sub external_name( $ ) { sub external_name( $ ) {
my ( $target, $level, $tag, $params ) = split /:/, shift, 4; my ( $target, $level, $tag, undef, $params ) = split /:/, shift, ACTION_TUPLE_ELEMENTS;
$target = join( '', $target, '(', $params , ')' ) if $params; $target = join( '', $target, '(', $params , ')' ) if $params;
$target .= ":$level" if $level && $level ne 'none'; $target .= ":$level" if $level && $level ne 'none';
@@ -1333,7 +1356,7 @@ sub createsimpleactionchain( $ ) {
sub createactionchain( $ ) { sub createactionchain( $ ) {
my $normalized = shift; my $normalized = shift;
my ( $target, $level, $tag, $param ) = split /:/, $normalized, 4; my ( $target, $level, $tag, $caller, $param ) = split /:/, $normalized, ACTION_TUPLE_ELEMENTS;
assert( defined $param ); assert( defined $param );
@@ -1690,10 +1713,14 @@ sub process_rule ( $$$$$$$$$$$$$$$$$$$$ );
# Populate an action invocation chain. As new action tuples are encountered, # Populate an action invocation chain. As new action tuples are encountered,
# the function will be called recursively by process_rule(). # the function will be called recursively by process_rule().
# #
sub process_action($$) { # Note that the first two parameters are passed by reference and may be
my ( $chainref, $caller ) = @_; # modified by this function.
my $wholeaction = $chainref->{action}; #
my ( $action, $level, $tag, $param ) = split /:/, $wholeaction, 4; sub process_action(\$\$$) {
my ( $wholeactionref, $chainrefref, $caller ) = @_;
my $wholeaction = ${$wholeactionref};
my $chainref = ${$chainrefref};
my ( $action, $level, $tag, undef, $param ) = split /:/, $wholeaction, ACTION_TUPLE_ELEMENTS;
if ( $targets{$action} & BUILTIN ) { if ( $targets{$action} & BUILTIN ) {
$level = '' if $level =~ /none!?/; $level = '' if $level =~ /none!?/;
@@ -1771,10 +1798,48 @@ sub process_action($$) {
# #
# Pop the action parameters # Pop the action parameters
# Caller should delete record of this chain if the action parameters
# were modified (and this function returns true
# #
pop_action_params( $oldparms ); if ( ( my $result = pop_action_params( $oldparms ) ) & PARMSMODIFIED ) {
#
# The action modified its parameters -- delete it from %usedactions
#
delete $usedactions{$wholeaction};
} elsif ( $result & USEDCALLER ) {
#
# The chain uses @CALLER but doesn't modify the action parameters.
# We need to see if this caller has already invoked this action
#
my $renormalized_action = insert_caller( $wholeaction, $caller );
my $chain1ref = $usedactions{$renormalized_action};
if ( $chain1ref ) {
#
# It has -- use the prior chain
#
${$chainrefref} = $chain1ref;
#
# We leave the new chain in place but delete it from %usedactions below
# The optimizer will drop it from the final ruleset.
#
} else {
#
# This is the first time that the current chain has invoked this action
#
$usedactions{$renormalized_action} = $chainref;
#
# Update the action member
#
$chainref->{action} = $renormalized_action;
}
#
# Delete the usedactions entry with the original normalized key
#
delete $usedactions{$wholeaction};
#
# New normalized target
#
${$wholeactionref} = $renormalized_action;
}
} }
# #
@@ -1907,11 +1972,14 @@ sub process_actions() {
# Create a policy action if it doesn't already exist # Create a policy action if it doesn't already exist
# #
sub use_policy_action( $$ ) { sub use_policy_action( $$ ) {
my $ref = use_action( $_[0] ); my ( $normalized_target, $caller ) = @_;
my $ref = use_action( $normalized_target );
if ( $ref ) { if ( $ref ) {
delete $usedactions{$ref->{action}} if process_action( $ref, $_[1] ); process_action( $normalized_target, $ref, $caller );
} else { } else {
$ref = $usedactions{$_[0]}; $ref = $usedactions{$normalized_target};
} }
$ref; $ref;
@@ -2661,7 +2729,7 @@ sub process_rule ( $$$$$$$$$$$$$$$$$$$$ ) {
# #
# Handle actions # Handle actions
# #
my $delete_action; my $actionchain; #Name of the action chain
if ( $actiontype & ACTION ) { if ( $actiontype & ACTION ) {
# #
@@ -2677,18 +2745,29 @@ sub process_rule ( $$$$$$$$$$$$$$$$$$$$ ) {
# #
my $savestatematch = $statematch; my $savestatematch = $statematch;
$statematch = ''; $statematch = '';
#
$delete_action = process_action( $ref, $chain ); # process_action may modify both $normalized_target and $ref!!!
#
process_action( $normalized_target, $ref, $chain );
#
# Capture the name of the action chain
#
$actionchain = $ref->{name};
# #
# Processing the action may determine that the action or one of it's dependents does NAT or HELPER, so: # Processing the action may determine that the action or one of it's dependents does NAT or HELPER, so:
# #
# - Refresh $actiontype # - Refresh $actiontype
# - Create the associated nat and/or table chain if appropriate. # - Create the associated nat and/or table chain if appropriate.
# #
ensure_chain( 'nat', $ref->{name} ) if ( $actiontype = $targets{$basictarget} ) & NATRULE; ensure_chain( 'nat', $actionchain ) if ( $actiontype = $targets{$basictarget} ) & NATRULE;
ensure_chain( 'raw', $ref->{name} ) if ( $actiontype & HELPER ); ensure_chain( 'raw', $actionchain ) if ( $actiontype & HELPER );
$statematch = $savestatematch; $statematch = $savestatematch;
} else {
#
# We've seen this tuple before
#
$actionchain = $usedactions{$normalized_target}->{name};
} }
$action = $basictarget; # Remove params, if any, from $action. $action = $basictarget; # Remove params, if any, from $action.
@@ -2808,7 +2887,7 @@ sub process_rule ( $$$$$$$$$$$$$$$$$$$$ ) {
$ports, $ports,
$sports, $sports,
$sourceref, $sourceref,
( $actiontype & ACTION ) ? $usedactions{$normalized_target}->{name} : '', ( $actiontype & ACTION ) ? $actionchain : '',
$inchain ? $chain : '' , $inchain ? $chain : '' ,
$user , $user ,
$rule , $rule ,
@@ -2830,7 +2909,7 @@ sub process_rule ( $$$$$$$$$$$$$$$$$$$$ ) {
$proto, $proto,
$ports, $ports,
$origdest, $origdest,
( $actiontype & ACTION ) ? $usedactions{$normalized_target}->{name} : '', ( $actiontype & ACTION ) ? $actionchain : '',
$action, $action,
$sourceref, $sourceref,
$inaction ? $chain : '', $inaction ? $chain : '',
@@ -2887,7 +2966,7 @@ sub process_rule ( $$$$$$$$$$$$$$$$$$$$ ) {
unless ( $actiontype & NATONLY ) { unless ( $actiontype & NATONLY ) {
if ( $actiontype & ACTION ) { if ( $actiontype & ACTION ) {
$action = $usedactions{$normalized_target}{name}; $action = $actionchain;
$loglevel = ''; $loglevel = '';
} }
@@ -2918,8 +2997,6 @@ sub process_rule ( $$$$$$$$$$$$$$$$$$$$ ) {
unless unreachable_warning( $wildcard || $section == DEFAULTACTION_SECTION, $chainref ); unless unreachable_warning( $wildcard || $section == DEFAULTACTION_SECTION, $chainref );
} }
delete $usedactions{$normalized_target} if $delete_action;
return 1; return 1;
} }

View File

@@ -2954,7 +2954,9 @@ sub process_traffic_shaping() {
my ( $options, $redopts ) = ( '', $tcref->{redopts} ); my ( $options, $redopts ) = ( '', $tcref->{redopts} );
while ( my ( $option, $type ) = each %validredoptions ) { for my $option ( sort keys %validredoptions ) {
my $type = $validredoptions{$option};
if ( my $value = $redopts->{$option} ) { if ( my $value = $redopts->{$option} ) {
if ( $type == RED_NONE ) { if ( $type == RED_NONE ) {
$options = join( ' ', $options, $option ) if $value; $options = join( ' ', $options, $option ) if $value;
@@ -2971,7 +2973,9 @@ sub process_traffic_shaping() {
my ( $options, $codelopts ) = ( '', $tcref->{codelopts} ); my ( $options, $codelopts ) = ( '', $tcref->{codelopts} );
while ( my ( $option, $type ) = each %validcodeloptions ) { for my $option ( sort keys %validcodeloptions ) {
my $type = $validcodeloptions{$option};
if ( my $value = $codelopts->{$option} ) { if ( my $value = $codelopts->{$option} ) {
if ( $type == CODEL_NONE ) { if ( $type == CODEL_NONE ) {
$options = join( ' ', $options, $option ); $options = join( ' ', $options, $option );

View File

@@ -91,6 +91,7 @@ our @EXPORT = ( qw( NOTHING
find_interfaces_by_option find_interfaces_by_option
find_interfaces_by_option1 find_interfaces_by_option1
get_interface_option get_interface_option
get_interface_origin
interface_has_option interface_has_option
set_interface_option set_interface_option
set_interface_provider set_interface_provider
@@ -149,6 +150,7 @@ use constant { IN_OUT => 1,
# } # }
# hosts => [ <net1> , <net2> , ... ] # hosts => [ <net1> , <net2> , ... ]
# exclusions => [ <net1>, <net2>, ... ] # exclusions => [ <net1>, <net2>, ... ]
# origin => <where defined>
# } # }
# <interface2> => ... # <interface2> => ...
# } # }
@@ -196,6 +198,7 @@ our %reservedName = ( all => 1,
# provider => <Provider Name, if interface is associated with a provider> # provider => <Provider Name, if interface is associated with a provider>
# wildcard => undef|1 # Wildcard Name # wildcard => undef|1 # Wildcard Name
# zones => { zone1 => 1, ... } # zones => { zone1 => 1, ... }
# origin => <where defined>
# } # }
# } # }
# #
@@ -890,7 +893,9 @@ sub add_group_to_zone($$$$$$)
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 ,
origin => shortlineinfo( '' ) ,
};
if ( $type != IPSEC ) { if ( $type != IPSEC ) {
my $optref = $interfaces{$interface}{options}; my $optref = $interfaces{$interface}{options};
@@ -1858,6 +1863,22 @@ sub interface_has_option( $$\$ ) {
} }
# #
# Return the origin for an interface
#
sub get_interface_origin( $ ) {
my ( $interface ) = @_;
my $ref = $interfaces{$interface};
return $ref->{origin} if $ref;
assert( $ref = known_interface( $interface ) );
$ref->{origin};
}
##
# Set an option for an interface # Set an option for an interface
# #
sub set_interface_option( $$$ ) { sub set_interface_option( $$$ ) {
@@ -2183,10 +2204,11 @@ sub find_hosts_by_option( $ ) {
my $arrayref = $interfaceref->{$interface}; my $arrayref = $interfaceref->{$interface};
for my $host ( @{$arrayref} ) { for my $host ( @{$arrayref} ) {
my $ipsec = $host->{ipsec}; my $ipsec = $host->{ipsec};
my $origin = $host->{origin};
unless ( $done{$interface} ) { unless ( $done{$interface} ) {
if ( my $value = $host->{options}{$option} ) { if ( my $value = $host->{options}{$option} ) {
for my $net ( @{$host->{hosts}} ) { for my $net ( @{$host->{hosts}} ) {
push @hosts, [ $interface, $ipsec , $net , $host->{exclusions}, $value ]; push @hosts, [ $interface, $ipsec , $net , $host->{exclusions}, $value, $origin ];
} }
} }
} }
@@ -2213,7 +2235,7 @@ sub find_zone_hosts_by_option( $$ ) {
for my $host ( @{$arrayref} ) { for my $host ( @{$arrayref} ) {
if ( my $value = $host->{options}{$option} ) { if ( my $value = $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}, $value, $host->{origin} ];
} }
} }
} }

View File

@@ -322,6 +322,9 @@ if [ $PRODUCT = shorewall ]; then
exit 1; exit 1;
fi fi
cp -af Perl/Shorewall/Chains.pm Perl/Shorewall/Chains.pm.bak
cp -af Perl/Shorewall/Config.pm Perl/Shorewall/Config.pm.bak
eval sed -i \'s/Digest::SHA/Digest::$DIGEST/\' Perl/Shorewall/Chains.pm eval sed -i \'s/Digest::SHA/Digest::$DIGEST/\' Perl/Shorewall/Chains.pm
eval sed -i \'s/Digest::SHA/Digest::$DIGEST/\' Perl/Shorewall/Config.pm eval sed -i \'s/Digest::SHA/Digest::$DIGEST/\' Perl/Shorewall/Config.pm
fi fi
@@ -332,6 +335,9 @@ if [ $PRODUCT = shorewall ]; then
DIGEST=SHA DIGEST=SHA
if ! perl -e 'use Digest::SHA;' 2> /dev/null ; then if ! perl -e 'use Digest::SHA;' 2> /dev/null ; then
if perl -e 'use Digest::SHA1;' 2> /dev/null ; then if perl -e 'use Digest::SHA1;' 2> /dev/null ; then
cp -af Perl/Shorewall/Chains.pm Perl/Shorewall/Chains.pm.bak
cp -af Perl/Shorewall/Config.pm Perl/Shorewall/Config.pm.bak
sed -i 's/Digest::SHA/Digest::SHA1/' Perl/Shorewall/Chains.pm sed -i 's/Digest::SHA/Digest::SHA1/' Perl/Shorewall/Chains.pm
sed -i 's/Digest::SHA/Digest::SHA1/' Perl/Shorewall/Config.pm sed -i 's/Digest::SHA/Digest::SHA1/' Perl/Shorewall/Config.pm
DIGEST=SHA1 DIGEST=SHA1
@@ -1115,6 +1121,10 @@ if [ -d Perl ]; then
install_file $f ${DESTDIR}${PERLLIBDIR}/$f 0644 install_file $f ${DESTDIR}${PERLLIBDIR}/$f 0644
echo "Module ${f%.*} installed as ${DESTDIR}${PERLLIBDIR}/$f" echo "Module ${f%.*} installed as ${DESTDIR}${PERLLIBDIR}/$f"
done done
[ -f Perl/Shorewall/Chains.pm.bak ] && mv Perl/Shorewall/Chains.pm.bak Perl/Shorewall/Chains.pm
[ -f Perl/Shorewall/Config.pm.bak ] && mv Perl/Shorewall/Config.pm.bak Perl/Shorewall/Config.pm
# #
# Install the program skeleton files # Install the program skeleton files
# #

View File

@@ -1629,7 +1629,7 @@ LOG:info:,bar net fw</programlisting>
"/lib/modules/$uname/kernel/net/ipv${g_family}/netfilter:/lib/modules/$uname/kernel/net/netfilter:/lib/modules/$uname/kernel/net/sched:/lib/modules/$uname/extra:/lib/modules/$uname/extra/ipset" "/lib/modules/$uname/kernel/net/ipv${g_family}/netfilter:/lib/modules/$uname/kernel/net/netfilter:/lib/modules/$uname/kernel/net/sched:/lib/modules/$uname/extra:/lib/modules/$uname/extra/ipset"
where <emphasis role="bold">uname</emphasis> holds the output of where <emphasis role="bold">uname</emphasis> holds the output of
'<command>uname -r</command>' and <emphasis '<command>uname -r</command>' and <emphasis
role="bold">g_family</emphasis> holds '4'. </para> role="bold">g_family</emphasis> holds '4'.</para>
</listitem> </listitem>
</varlistentry> </varlistentry>
@@ -2620,7 +2620,8 @@ INLINE - - - ; -j REJECT
<varlistentry> <varlistentry>
<term><emphasis role="bold">TRACK_RULES=</emphasis>{<emphasis <term><emphasis role="bold">TRACK_RULES=</emphasis>{<emphasis
role="bold">Yes</emphasis>|<emphasis role="bold">No</emphasis>}</term> role="bold">Yes</emphasis>|<emphasis
role="bold">No</emphasis>|File}</term>
<listitem> <listitem>
<para>Added in Shorewall 4.5.20. If set to <emphasis <para>Added in Shorewall 4.5.20. If set to <emphasis
@@ -2633,6 +2634,12 @@ INLINE - - - ; -j REJECT
<para>Setting this option to <emphasis role="bold">Yes</emphasis> <para>Setting this option to <emphasis role="bold">Yes</emphasis>
requires the <firstterm>Comments</firstterm> capability in iptables requires the <firstterm>Comments</firstterm> capability in iptables
and kernel.</para> and kernel.</para>
<para>Beginning with Shorewall 5.0.5, the option may also be set to
<emphasis role="bold">File</emphasis>. That setting causes similar
comments to be added to the
<filename>.iptables-restore-input</filename> file, which is normally
created in <filename>/var/lib/shorewall</filename>.</para>
</listitem> </listitem>
</varlistentry> </varlistentry>

View File

@@ -1,25 +1,26 @@
# sysV init file script configuration(/etc/sysconfdir/shorewall-lite) #
# Global start/restart/reload/stop options
#
OPTIONS=""
# startup option(default "-vvv") #
OPTIONS= # Start options
#
STARTOPTIONS=""
# change default start run level(if none empty; /etc/init.d/shorewall-lite enable) #
START=50 # Restart options
#
RESTARTOPTIONS=""
# change default stop run level(if none empty; /etc/init.d/shorewall-lite enable) #
STOP= # Reload options
#
RELOADOPTIONS=""
# option to pass when shorewall start is executed #
STARTOPTIONS= # Stop options
#
STOPOPTIONS=""
# option to pass when shorewall restart is executed # EOF
RESTARTOPTIONS=
# option to pass when shorewall reload is executed
RELOADOPTIONS=
# option to pass when shorewall stop is executed
STOPOPTIONS=
# option to pass when shorewall status is executed
STATUSOPTIONS=

View File

@@ -39,13 +39,13 @@
# description: Packet filtering firewall # description: Packet filtering firewall
# openwrt stuph # Openwrt related
# start and stop runlevel variable # Start and stop runlevel variable
START=50 START=50
STOP=89 STOP=89
# variable to display what the status command do when /etc/init.d/shorewall6-lite is invoke without argument # Displays the status command
EXTRA_COMMANDS="status" EXTRA_COMMANDS="status"
EXTRA_HELP="status displays shorewall status" EXTRA_HELP=" status Displays firewall status"
################################################################################ ################################################################################
# Get startup options (override default) # Get startup options (override default)
@@ -57,8 +57,8 @@ OPTIONS=
# #
. /usr/share/shorewall/shorewallrc . /usr/share/shorewall/shorewallrc
if [ -f ${SYSCONFDIR}/$PRODUCT ]; then if [ -f ${SYSCONFDIR}/shorewall6-lite ]; then
. ${SYSCONFDIR}/$PRODUCT . ${SYSCONFDIR}/shorewall6-lite
fi fi
SHOREWALL_INIT_SCRIPT=1 SHOREWALL_INIT_SCRIPT=1
@@ -66,7 +66,7 @@ SHOREWALL_INIT_SCRIPT=1
################################################################################ ################################################################################
# E X E C U T I O N B E G I N S H E R E # # E X E C U T I O N B E G I N S H E R E #
################################################################################ ################################################################################
# arg1 of init script is arg2 when rc.common is sourced; set to action variable # Arg1 of init script is arg2 when rc.common is sourced; set to action variable
command="$action" command="$action"
start() { start() {
@@ -74,8 +74,8 @@ start() {
} }
boot() { boot() {
local command="start" local command="start"
start start
} }
restart() { restart() {
@@ -91,5 +91,5 @@ stop() {
} }
status() { status() {
exec ${SBINDIR}/shorewall6-lite $OPTIONS $command $STATUSOPTIONS exec ${SBINDIR}/shorewall6-lite $OPTIONS $command $@
} }

View File

@@ -1,25 +1,26 @@
# sysV init file script configuration(/etc/sysconfdir/shorewall-lite) #
# Global start/restart/reload/stop options
#
OPTIONS=""
# startup option(default "-vvv") #
OPTIONS= # Start options
#
STARTOPTIONS=""
# change default start run level(if none empty; /etc/init.d/shorewall-lite enable) #
START=50 # Restart options
#
RESTARTOPTIONS=""
# change default stop run level(if none empty; /etc/init.d/shorewall-lite enable) #
STOP= # Reload options
#
RELOADOPTIONS=""
# option to pass when shorewall start is executed #
STARTOPTIONS= # Stop options
#
STOPOPTIONS=""
# option to pass when shorewall restart is executed # EOF
RESTARTOPTIONS=
# option to pass when shorewall reload is executed
RELOADOPTIONS=
# option to pass when shorewall stop is executed
STOPOPTIONS=
# option to pass when shorewall status is executed
STATUSOPTIONS=

View File

@@ -2295,7 +2295,8 @@ INLINE - - - ; -j REJECT
<varlistentry> <varlistentry>
<term><emphasis role="bold">TRACK_RULES=</emphasis>{<emphasis <term><emphasis role="bold">TRACK_RULES=</emphasis>{<emphasis
role="bold">Yes</emphasis>|<emphasis role="bold">No</emphasis>}</term> role="bold">Yes</emphasis>|<emphasis
role="bold">No</emphasis>|File}</term>
<listitem> <listitem>
<para>Added in Shorewall 4.5.20. If set to <emphasis <para>Added in Shorewall 4.5.20. If set to <emphasis
@@ -2306,8 +2307,14 @@ INLINE - - - ; -j REJECT
added.</para> added.</para>
<para>Setting this option to <emphasis role="bold">Yes</emphasis> <para>Setting this option to <emphasis role="bold">Yes</emphasis>
requires the <firstterm>Comments</firstterm> capability in ip6tables requires the <firstterm>Comments</firstterm> capability in iptables
and kernel.</para> and kernel.</para>
<para>Beginning with Shorewall 5.0.5, the option may also be set to
<emphasis role="bold">File</emphasis>. That setting causes similar
comments to be added to the
<filename>.ip6tables-restore-input</filename> file, which is
normally created in <filename>/var/lib/shorewall</filename>6.</para>
</listitem> </listitem>
</varlistentry> </varlistentry>

View File

@@ -1,25 +1,26 @@
# sysV init file script configuration(/etc/sysconfdir/shorewall-lite) #
# Global start/restart/reload/stop options
#
OPTIONS=""
# startup option(default "-vvv") #
OPTIONS= # Start options
#
STARTOPTIONS=""
# change default start run level(if none empty; /etc/init.d/shorewall-lite enable) #
START=50 # Restart options
#
RESTARTOPTIONS=""
# change default stop run level(if none empty; /etc/init.d/shorewall-lite enable) #
STOP= # Reload options
#
RELOADOPTIONS=""
# option to pass when shorewall start is executed #
STARTOPTIONS= # Stop options
#
STOPOPTIONS=""
# option to pass when shorewall restart is executed # EOF
RESTARTOPTIONS=
# option to pass when shorewall reload is executed
RELOADOPTIONS=
# option to pass when shorewall stop is executed
STOPOPTIONS=
# option to pass when shorewall status is executed
STATUSOPTIONS=

View File

@@ -72,9 +72,9 @@
<listitem> <listitem>
<para>If you set 'ping-check' true in your <para>If you set 'ping-check' true in your
<filename>/etc/shorewall/dhcpd.conf</filename> file then you will want <filename>/etc/dhcp/dhcpd.conf</filename> file then you will want to
to <ulink url="ping.html">accept 'ping'</ulink> from your firewall to <ulink url="ping.html">accept 'ping'</ulink> from your firewall to the
the zone(s) served by the firewall's DHCP server.</para> zone(s) served by the firewall's DHCP server.</para>
</listitem> </listitem>
</itemizedlist> </itemizedlist>
</section> </section>