2011-10-03 03:41:58 +02:00
|
|
|
#
|
2015-07-28 19:59:11 +02:00
|
|
|
# Shorewall version 5 - Drop Smurfs Action
|
2011-10-03 03:41:58 +02:00
|
|
|
#
|
|
|
|
# /usr/share/shorewall/action.DropSmurfs
|
|
|
|
#
|
|
|
|
# Accepts a single optional parameter:
|
|
|
|
#
|
|
|
|
# - = Do not Audit
|
|
|
|
# audit = Audit dropped packets.
|
|
|
|
#
|
|
|
|
#################################################################################
|
2013-06-20 19:39:39 +02:00
|
|
|
?format 2
|
2011-10-03 03:41:58 +02:00
|
|
|
|
|
|
|
DEFAULTS -
|
|
|
|
|
2013-06-20 19:39:39 +02:00
|
|
|
?begin perl;
|
2011-10-05 18:32:26 +02:00
|
|
|
use strict;
|
2011-10-03 03:41:58 +02:00
|
|
|
use Shorewall::Config qw(:DEFAULT F_IPV4 F_IPV6);
|
2012-12-02 16:11:58 +01:00
|
|
|
use Shorewall::IPAddrs qw( IPv6_MULTICAST );
|
2011-10-03 03:41:58 +02:00
|
|
|
use Shorewall::Chains;
|
|
|
|
use Shorewall::Rules;
|
|
|
|
|
|
|
|
my ( $audit ) = get_action_params( 1 );
|
|
|
|
|
|
|
|
my $chainref = get_action_chain;
|
2012-11-29 00:03:08 +01:00
|
|
|
|
2011-10-03 03:41:58 +02:00
|
|
|
my ( $level, $tag ) = get_action_logging;
|
2011-10-05 18:32:26 +02:00
|
|
|
my $target;
|
2011-10-03 03:41:58 +02:00
|
|
|
|
|
|
|
if ( $level ne '-' || $audit ne '-' ) {
|
|
|
|
my $logchainref = ensure_filter_chain newlogchain( $chainref->{table} ), 0;
|
|
|
|
|
|
|
|
log_rule_limit( $level,
|
|
|
|
$logchainref,
|
|
|
|
$chainref->{name},
|
2011-10-05 18:32:26 +02:00
|
|
|
'DROP',
|
2011-10-03 03:41:58 +02:00
|
|
|
'',
|
|
|
|
$tag,
|
|
|
|
'add',
|
|
|
|
'' );
|
|
|
|
|
|
|
|
if ( supplied $audit ) {
|
|
|
|
fatal_error "Invalid argument ($audit) to DropSmurfs" if $audit ne 'audit';
|
|
|
|
require_capability 'AUDIT_TARGET', q(Passing 'audit' to the DropSmurfs action), 's';
|
2011-10-05 18:32:26 +02:00
|
|
|
add_ijump( $logchainref, j => 'AUDIT --type DROP' );
|
2012-04-24 23:52:57 +02:00
|
|
|
}
|
|
|
|
|
2011-10-03 03:41:58 +02:00
|
|
|
add_ijump( $logchainref, j => 'DROP' );
|
|
|
|
|
2011-10-05 18:32:26 +02:00
|
|
|
$target = $logchainref;
|
|
|
|
} else {
|
|
|
|
$target = 'DROP';
|
2011-10-03 03:41:58 +02:00
|
|
|
}
|
2012-04-24 23:52:57 +02:00
|
|
|
|
2012-03-19 15:20:31 +01:00
|
|
|
if ( have_capability( 'ADDRTYPE' ) ) {
|
|
|
|
if ( $family == F_IPV4 ) {
|
|
|
|
add_ijump $chainref , j => 'RETURN', s => '0.0.0.0'; ;
|
|
|
|
} else {
|
|
|
|
add_ijump $chainref , j => 'RETURN', s => '::';
|
|
|
|
}
|
2011-10-03 03:41:58 +02:00
|
|
|
|
2011-10-05 18:32:26 +02:00
|
|
|
add_ijump( $chainref, g => $target, addrtype => '--src-type BROADCAST' ) ;
|
2012-03-19 15:20:31 +01:00
|
|
|
} else {
|
|
|
|
if ( $family == F_IPV4 ) {
|
|
|
|
add_commands $chainref, 'for address in $ALL_BCASTS; do';
|
|
|
|
} else {
|
|
|
|
add_commands $chainref, 'for address in $ALL_ACASTS; do';
|
|
|
|
}
|
2012-04-24 23:52:57 +02:00
|
|
|
|
2011-10-03 03:41:58 +02:00
|
|
|
incr_cmd_level $chainref;
|
2011-10-05 18:32:26 +02:00
|
|
|
add_ijump( $chainref, g => $target, s => '$address' );
|
2011-10-03 03:41:58 +02:00
|
|
|
decr_cmd_level $chainref;
|
|
|
|
add_commands $chainref, 'done';
|
2012-03-19 15:20:31 +01:00
|
|
|
}
|
2011-10-03 03:41:58 +02:00
|
|
|
|
2012-03-19 15:20:31 +01:00
|
|
|
if ( $family == F_IPV4 ) {
|
2011-10-05 18:32:26 +02:00
|
|
|
add_ijump( $chainref, g => $target, s => '224.0.0.0/4' );
|
2012-03-19 15:20:31 +01:00
|
|
|
} else {
|
2011-10-05 18:32:26 +02:00
|
|
|
add_ijump( $chainref, g => $target, s => IPv6_MULTICAST );
|
2012-03-19 15:20:31 +01:00
|
|
|
}
|
2011-10-03 03:41:58 +02:00
|
|
|
|
2013-06-20 19:39:39 +02:00
|
|
|
?end perl;
|
2011-10-03 03:41:58 +02:00
|
|
|
|
|
|
|
|
2012-04-24 23:52:57 +02:00
|
|
|
|
2011-10-03 03:41:58 +02:00
|
|
|
|
|
|
|
|