| 1 | package Parse::Snort::Strict; | ||||||||||||||
| 2 | 2 | ▶ | use base qw(Parse::Snort); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | |||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 2 | ▶ | use Carp qw(croak); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 2 | ▶ | use List::Util qw(any); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 2 | ▶ | use Sub::Util qw(set_subname); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | 2 | our $VERSION = '0.9'; | |||||||||||||
| 11 | |||||||||||||||
| 12 | # valid values for rule parts | ||||||||||||||
| 13 | 2 | my $rule_parts_validation = { | |||||||||||||
| 14 | action => [qw( alert pass drop sdrop log activate dynamic reject )], | ||||||||||||||
| 15 | proto => [qw( tcp udp ip icmp )], | ||||||||||||||
| 16 | direction => [qw( -> <> <- )], | ||||||||||||||
| 17 | }; | ||||||||||||||
| 18 | |||||||||||||||
| 19 | # method generator for simple rule parts, copypasta reduction | ||||||||||||||
| 20 | { | ||||||||||||||
| 21 | 6 | ▶ | my $generator = sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.5
| |||||||||||||||
| 22 | # closures are teh awesome. | ||||||||||||||
| 23 | 6 | my ($part,$value_ref) = @_; | |||||||||||||
| 24 | 6 | my $method = "SUPER::$part"; | |||||||||||||
| 25 | |||||||||||||||
| 26 | 21 | ▶ | return sub { | ||||||||||||
|
Subroutine
action: called CC=2 SCAR=8.7
Subroutine
__ANON__: not called CC=2 SCAR=8.7
Pod
documented
| |||||||||||||||
| 27 | 0 | my ($self,$value) = @_; | |||||||||||||
| 28 | |||||||||||||||
| 29 | # do validation | ||||||||||||||
| 30 | 0 | ▶ | croak "Invalid rule $part: '$value'" unless (any { $value eq $_ } @{ $value_ref }); | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.8
Branch: 2 branches
| |||||||||||||||
| 31 | |||||||||||||||
| 32 | # call parent's method for value setting | ||||||||||||||
| 33 | 0 | $self->$method($value); | |||||||||||||
| 34 | 6 | }; | |||||||||||||
| 35 | 2 | }; | |||||||||||||
| 36 | |||||||||||||||
| 37 | 2 | ▶ | no strict qw(refs); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 38 | 2 | ▶ | while (my ($part,$value_ref) = each %$rule_parts_validation) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 39 | 6 | *{$part} = set_subname($part,$generator->($part,$value_ref)); | |||||||||||||
| 40 | } | ||||||||||||||
| 41 | 2 | ▶ | use strict qw(refs); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 42 | } | ||||||||||||||
| 43 | |||||||||||||||
| 44 | # TODO: validate formatting of src/dst address and port, make sure they look like $VARIABLEs or [a:range] | ||||||||||||||
| 45 | |||||||||||||||
| 46 | 2 | 1; | |||||||||||||
| 47 | |||||||||||||||
| 48 | __END__; | ||||||||||||||