line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# $Id: List.pm,v 1.14 2003/06/06 18:45:02 unimlo Exp $ |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Net::ACL::Match::List; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
1038
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
50
|
|
8
|
1
|
|
|
1
|
|
6
|
use vars qw( $VERSION @ISA ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
79
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
## Inheritance and Versioning ## |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
@ISA = qw( Net::ACL::Match ); |
13
|
|
|
|
|
|
|
$VERSION = '0.07'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
## Module Imports ## |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
7
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
91
|
|
18
|
1
|
|
|
1
|
|
5
|
use Scalar::Util qw( blessed ); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
59
|
|
19
|
1
|
|
|
1
|
|
653
|
use Net::ACL::Match; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
51
|
|
20
|
1
|
|
|
1
|
|
8
|
use Net::ACL::Rule qw( :rc :action ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
191
|
|
21
|
1
|
|
|
1
|
|
644
|
use Net::ACL::Bootstrap; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
602
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
## Public Class Methods ## |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub new |
26
|
|
|
|
|
|
|
{ |
27
|
3
|
|
|
3
|
1
|
965
|
my $proto = shift; |
28
|
3
|
|
33
|
|
|
22
|
my $class = ref $proto || $proto; |
29
|
|
|
|
|
|
|
|
30
|
3
|
50
|
33
|
|
|
10
|
@_ = @{$_[0]} if (scalar @_ == 1) && (ref $_[0] eq 'ARRAY'); |
|
0
|
|
|
|
|
0
|
|
31
|
|
|
|
|
|
|
|
32
|
3
|
|
|
|
|
10
|
my $this = { |
33
|
|
|
|
|
|
|
_lists => [], |
34
|
|
|
|
|
|
|
_index => shift |
35
|
|
|
|
|
|
|
}; |
36
|
|
|
|
|
|
|
|
37
|
3
|
50
|
|
|
|
20
|
croak "Index should be a number" unless $this->{_index} =~ /^[0-9]$/; |
38
|
|
|
|
|
|
|
|
39
|
3
|
|
|
|
|
10
|
bless($this, $class); |
40
|
|
|
|
|
|
|
|
41
|
3
|
|
|
|
|
8
|
$this->add_list(@_); |
42
|
|
|
|
|
|
|
|
43
|
3
|
50
|
|
|
|
24
|
croak 'Need at least one access-list to match' unless scalar $this->{_lists}; |
44
|
|
|
|
|
|
|
|
45
|
3
|
|
|
|
|
9
|
return $this; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
## Public Object Methods ## |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub add_list |
51
|
|
|
|
|
|
|
{ |
52
|
6
|
|
|
6
|
0
|
8
|
my $this = shift; |
53
|
6
|
100
|
|
|
|
27
|
if (blessed $_[0]) |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
54
|
|
|
|
|
|
|
{ |
55
|
5
|
|
|
|
|
6
|
push(@{$this->{_lists}}, shift); |
|
5
|
|
|
|
|
18
|
|
56
|
5
|
100
|
|
|
|
22
|
$this->add_list(@_) unless scalar @_ == 0; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
elsif (ref $_[0] eq 'ARRAY') |
59
|
|
|
|
|
|
|
{ |
60
|
0
|
|
|
|
|
0
|
$this->add_list(shift); |
61
|
0
|
0
|
|
|
|
0
|
$this->add_list(@_) unless scalar @_ == 0; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
elsif (ref $_[0] eq 'HASH') |
64
|
|
|
|
|
|
|
{ |
65
|
1
|
|
|
|
|
2
|
my $d = shift; |
66
|
1
|
|
|
|
|
2
|
$this->add_list(renew Net::ACL::Bootstrap(%{$d})); |
|
1
|
|
|
|
|
18
|
|
67
|
1
|
50
|
|
|
|
6
|
$this->add_list(@_) unless scalar @_ == 0; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
else |
70
|
|
|
|
|
|
|
{ |
71
|
0
|
|
|
|
|
0
|
$this->add_list(renew Net::ACL::Bootstrap(@_)); |
72
|
|
|
|
|
|
|
}; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub match |
76
|
|
|
|
|
|
|
{ |
77
|
9
|
|
|
9
|
1
|
366
|
my $this = shift; |
78
|
9
|
|
|
|
|
20
|
my @data = @_; |
79
|
9
|
|
|
|
|
15
|
foreach my $list (@{$this->{_lists}}) |
|
9
|
|
|
|
|
25
|
|
80
|
|
|
|
|
|
|
{ |
81
|
13
|
100
|
|
|
|
49
|
return ACL_NOMATCH unless $list->match($data[$this->{_index}]) == ACL_PERMIT; |
82
|
|
|
|
|
|
|
} |
83
|
4
|
|
|
|
|
13
|
return ACL_MATCH; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub type |
87
|
|
|
|
|
|
|
{ |
88
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
89
|
0
|
0
|
|
|
|
|
return unless scalar @{$this->{_lists}}; |
|
0
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
return $this->{_lists}->[0]->type; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub names |
94
|
|
|
|
|
|
|
{ |
95
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
96
|
0
|
|
|
|
|
|
return map { $_->name; } @{$this->{_lists}}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
## POD ## |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=pod |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 NAME |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Net::ACL::Match::List - Class matching data against one or more access-lists |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 SYNOPSIS |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
use Net::ACL::Match::List; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# Constructor |
112
|
|
|
|
|
|
|
$match = new Net::ACL::Match::List(2, [ |
113
|
|
|
|
|
|
|
Type => 'prefix-list' |
114
|
|
|
|
|
|
|
Name => 42 |
115
|
|
|
|
|
|
|
] ); |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# Accessor Methods |
118
|
|
|
|
|
|
|
$rc = $match->match('127.0.0.0/20'); |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 DESCRIPTION |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
This module match data against one or more access-lists. It only matches if |
123
|
|
|
|
|
|
|
data if data is permitted by all access-lists. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=over 4 |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=item new() - create a new Net::ACL::Match::List object |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
$match = new Net::ACL::Match::List(2, [ |
132
|
|
|
|
|
|
|
Type => 'prefix-list' |
133
|
|
|
|
|
|
|
Name => 42 |
134
|
|
|
|
|
|
|
] ); |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
This is the constructor for Net::ACL::Match::List objects. It |
137
|
|
|
|
|
|
|
returns a reference to the newly created object. The first |
138
|
|
|
|
|
|
|
argument is the index of the element that should be matched. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
The second argument can have one of the following types: |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=over 4 |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=item Net::ACL |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
An access-list to be matched against. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item HASH reference |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
A reference to a hash passed to Net::ACL->renew() |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item SCALAR |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
A scalar passed to Net::ACL->renew() |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=item ARRAY reference |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
A reference to an array one of the above 3 types. Used |
159
|
|
|
|
|
|
|
to match multiple lists. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=back |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=back |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 ACCESSOR METHODS |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=over 4 |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=item match() |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
The match method verifies if the data is permitted by all access-lists |
172
|
|
|
|
|
|
|
supplied to the constructor. Returns ACL_MATCH if it does, otherwise |
173
|
|
|
|
|
|
|
ACL_NOMATCH. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=item names() |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
Return a list with all match lists names. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=item type() |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Returns the type of the first list that is matched - or C if no lists are |
182
|
|
|
|
|
|
|
matched. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=back |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head1 SEE ALSO |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
Net::ACL::Match, Net::ACL::Rule, Net::ACL |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head1 AUTHOR |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
Martin Lorensen |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=cut |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
## End Package Net::ACL::Match::List ## |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
1; |