cisco_acl_intp 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/README.md +64 -3
- data/cisco_acl_intp.gemspec +2 -2
- data/lib/cisco_acl_intp/ace.rb +9 -286
- data/lib/cisco_acl_intp/ace_ip.rb +24 -22
- data/lib/cisco_acl_intp/ace_other_qualifiers.rb +23 -6
- data/lib/cisco_acl_intp/ace_port.rb +37 -182
- data/lib/cisco_acl_intp/ace_port_opr.rb +251 -0
- data/lib/cisco_acl_intp/ace_port_opr_base.rb +138 -0
- data/lib/cisco_acl_intp/ace_proto.rb +133 -328
- data/lib/cisco_acl_intp/ace_proto_base.rb +163 -0
- data/lib/cisco_acl_intp/ace_srcdst.rb +30 -40
- data/lib/cisco_acl_intp/ace_tcp_flags.rb +9 -3
- data/lib/cisco_acl_intp/acl.rb +1 -251
- data/lib/cisco_acl_intp/acl_base.rb +1 -1
- data/lib/cisco_acl_intp/acl_utils.rb +120 -0
- data/lib/cisco_acl_intp/extended_ace.rb +149 -0
- data/lib/cisco_acl_intp/mono_function_acl.rb +161 -0
- data/lib/cisco_acl_intp/parser.rb +237 -395
- data/lib/cisco_acl_intp/parser.ry +85 -243
- data/lib/cisco_acl_intp/parser_api.rb +2 -2
- data/lib/cisco_acl_intp/single_acl_base.rb +137 -0
- data/lib/cisco_acl_intp/standard_ace.rb +105 -0
- data/lib/cisco_acl_intp/version.rb +1 -1
- data/spec/cisco_acl_intp/ace_ip_spec.rb +63 -0
- data/spec/cisco_acl_intp/ace_other_qualifier_spec.rb +52 -1
- data/spec/cisco_acl_intp/ace_port_operator_spec.rb +340 -0
- data/spec/cisco_acl_intp/ace_port_spec.rb +67 -217
- data/spec/cisco_acl_intp/ace_proto_spec.rb +118 -41
- data/spec/cisco_acl_intp/ace_spec.rb +38 -547
- data/spec/cisco_acl_intp/ace_srcdst_spec.rb +115 -226
- data/spec/cisco_acl_intp/ace_tcp_flags_spec.rb +36 -4
- data/spec/cisco_acl_intp/acl_base_spec.rb +2 -2
- data/spec/cisco_acl_intp/extended_ace_spec.rb +411 -0
- data/spec/cisco_acl_intp/extended_acl_spec.rb +265 -0
- data/spec/cisco_acl_intp/scanner_spec.rb +13 -12
- data/spec/cisco_acl_intp/standard_ace_spec.rb +77 -0
- data/spec/cisco_acl_intp/standard_acl_spec.rb +245 -0
- data/spec/conf/scanner_spec_data.yml +32 -0
- data/spec/spec_helper.rb +2 -2
- metadata +20 -4
- data/spec/cisco_acl_intp/acl_spec.rb +0 -525
@@ -1,36 +1,25 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
-
|
2
|
+
require 'forwardable'
|
3
3
|
require 'cisco_acl_intp/ace_proto'
|
4
|
+
require 'cisco_acl_intp/ace_port_opr'
|
4
5
|
|
5
6
|
module CiscoAclIntp
|
6
7
|
# IP(TCP/UDP) port number and operator container
|
7
8
|
class AcePortSpec < AclContainerBase
|
8
|
-
|
9
|
-
# @return [String]
|
10
|
-
attr_reader :operator
|
11
|
-
|
12
|
-
# @param [Symbol] value Protocol name [:tcp, :udp]
|
13
|
-
# @return [String]
|
14
|
-
attr_reader :protocol
|
15
|
-
|
16
|
-
# @param [AceProtoSpecBase] value Port No. (single/lower)
|
17
|
-
# @return [AceProtoSpecBase]
|
18
|
-
attr_reader :begin_port
|
9
|
+
extend Forwardable
|
19
10
|
|
20
|
-
#
|
21
|
-
|
22
|
-
|
23
|
-
# @param [AceProtoSpecBase] value Port No. (higher)
|
24
|
-
# @return [AceProtoSpecBase]
|
25
|
-
attr_reader :end_port
|
11
|
+
# @return [AcePortOperatorBase] value Port-set operator
|
12
|
+
attr_reader :operator
|
13
|
+
def_delegators :@operator, :begin_port, :port, :end_port, :to_s
|
26
14
|
|
27
15
|
# Constructor
|
28
16
|
# @param [Hash] opts Options
|
29
|
-
# @option opts [String] :operator Port operator,
|
30
|
-
#
|
17
|
+
# @option opts [String, Symbol] :operator Port operator,
|
18
|
+
# (any, strict_anyeq, neq, lt, gt, range)
|
19
|
+
# @option opts [AceProtoSpecBase] :port Port (single/lower)
|
31
20
|
# (same as :begin_port, alias for unary operator)
|
32
|
-
# @option opts [AceProtoSpecBase] :begin_port Port
|
33
|
-
# @option opts [AceProtoSpecBase] :end_port Port
|
21
|
+
# @option opts [AceProtoSpecBase] :begin_port Port (single/lower)
|
22
|
+
# @option opts [AceProtoSpecBase] :end_port Port (higher)
|
34
23
|
# @raise [AclArgumentError]
|
35
24
|
# @return [AcePortSpec]
|
36
25
|
# @note '@begin_port' and '@end_port' should managed
|
@@ -39,10 +28,9 @@ module CiscoAclIntp
|
|
39
28
|
# and need the name when stringize the object.
|
40
29
|
# @todo in ACL, can "eq/neq" receive port list? IOS15 later?
|
41
30
|
def initialize(opts)
|
42
|
-
@protocol = :tcp_udp
|
43
31
|
if opts.key?(:operator)
|
44
32
|
@options = opts
|
45
|
-
|
33
|
+
define_operator_and_ports
|
46
34
|
else
|
47
35
|
fail AclArgumentError, 'Not specified port operator'
|
48
36
|
end
|
@@ -51,178 +39,45 @@ module CiscoAclIntp
|
|
51
39
|
# @param [AcePortSpec] other RHS Object
|
52
40
|
# @return [Boolean]
|
53
41
|
def ==(other)
|
54
|
-
@
|
55
|
-
@operator == other.operator &&
|
56
|
-
@begin_port == other.begin_port &&
|
57
|
-
@end_port == other.end_port
|
58
|
-
end
|
59
|
-
|
60
|
-
# Generate string for Cisco IOS access list
|
61
|
-
# @return [String]
|
62
|
-
def to_s
|
63
|
-
if @operator == 'any'
|
64
|
-
''
|
65
|
-
else
|
66
|
-
tag_port(
|
67
|
-
clean_acl_string(
|
68
|
-
sprintf('%s %s %s', @operator, @begin_port, @end_port)
|
69
|
-
)
|
70
|
-
)
|
71
|
-
end
|
42
|
+
@operator == other.operator
|
72
43
|
end
|
73
44
|
|
74
|
-
#
|
75
|
-
|
76
|
-
'any' => proc do |begin_port, end_port, port|
|
77
|
-
true
|
78
|
-
end,
|
79
|
-
'eq' => proc do |begin_port, end_port, port|
|
80
|
-
begin_port == port
|
81
|
-
end,
|
82
|
-
'neq' => proc do |begin_port, end_port, port|
|
83
|
-
begin_port != port
|
84
|
-
end,
|
85
|
-
'gt' => proc do |begin_port, end_port, port|
|
86
|
-
begin_port < port
|
87
|
-
end,
|
88
|
-
'lt' => proc do |begin_port, end_port, port|
|
89
|
-
begin_port > port
|
90
|
-
end,
|
91
|
-
'range' => proc do |begin_port, end_port, port|
|
92
|
-
(begin_port .. end_port).include?(port)
|
93
|
-
end
|
94
|
-
}
|
95
|
-
|
96
|
-
# Check the port number matches this?
|
97
|
-
# @param [Integer,String] port TCP/UDP Port No./Name
|
45
|
+
# Check if self contains other port-set?
|
46
|
+
# @param [AcePortSpec] other TCP/UDP Port spec
|
98
47
|
# @raise [AclArgumentError]
|
99
48
|
# @return [Boolean]
|
100
|
-
def
|
101
|
-
|
102
|
-
when String
|
103
|
-
if port =~ /\d+/
|
104
|
-
convert_proto_spec_by_number(port.to_i)
|
105
|
-
else
|
106
|
-
convert_proto_spec_by_name(port)
|
107
|
-
end
|
108
|
-
else
|
109
|
-
convert_proto_spec_by_number(port)
|
110
|
-
end
|
111
|
-
# @operator was validated in constructor
|
112
|
-
PORT_OPERATE[@operator].call(@begin_port.to_i, @end_port.to_i, port.to_i)
|
49
|
+
def contains?(other)
|
50
|
+
@operator.contains?(other.operator)
|
113
51
|
end
|
114
52
|
|
115
53
|
private
|
116
54
|
|
117
|
-
#
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
# Convert from port number integer to AceTcpUdpProtoSpec object
|
129
|
-
# @param [Integer] number TCP Port Number
|
130
|
-
# @raise [AclArgumentError]
|
131
|
-
# @return [AceProtoSpecBase]
|
132
|
-
def convert_proto_spec_by_number(number)
|
133
|
-
AceTcpUdpProtoSpec.new(number: number)
|
134
|
-
end
|
55
|
+
# Port set operator table
|
56
|
+
OPERATOR_CLASS = {
|
57
|
+
strict_any: AcePortOpStrictAny,
|
58
|
+
any: AcePortOpAny,
|
59
|
+
eq: AcePortOpEq,
|
60
|
+
neq: AcePortOpNeq,
|
61
|
+
lt: AcePortOpLt,
|
62
|
+
gt: AcePortOpGt,
|
63
|
+
range: AcePortOpRange
|
64
|
+
}
|
135
65
|
|
136
66
|
# Set instance variables
|
137
|
-
def define_operator_and_ports
|
138
|
-
@operator = @options[:operator] || 'any'
|
139
|
-
@begin_port = @options[:port] || @options[:begin_port] || nil
|
140
|
-
@end_port = @options[:end_port] || nil
|
141
|
-
end
|
142
|
-
|
143
|
-
# Varidate options
|
144
67
|
# @raise [AclArgumentError]
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
if
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
end
|
154
|
-
|
155
|
-
# Varidate combination operator and port number
|
156
|
-
# @return [Boolean]
|
157
|
-
def valid_operator_and_port?
|
158
|
-
case @operator
|
159
|
-
when 'any'
|
160
|
-
true
|
161
|
-
when 'range'
|
162
|
-
@begin_port &&
|
163
|
-
@end_port &&
|
164
|
-
@begin_port < @end_port
|
68
|
+
# @return [AcePortOperatorBase] Port set operator object.
|
69
|
+
def define_operator_and_ports
|
70
|
+
opr = @options.key?(:operator) ? @options[:operator].intern : :any
|
71
|
+
if OPERATOR_CLASS.key?(opr)
|
72
|
+
@operator = OPERATOR_CLASS[opr].new(
|
73
|
+
(@options[:port] || @options[:begin_port]),
|
74
|
+
@options[:end_port]
|
75
|
+
)
|
165
76
|
else
|
166
|
-
|
77
|
+
fail AclArgumentError, 'Unknown operator'
|
167
78
|
end
|
168
79
|
end
|
169
|
-
end
|
170
|
-
|
171
|
-
# TCP port number and operator container
|
172
|
-
class AceTcpPortSpec < AcePortSpec
|
173
|
-
# Constructor
|
174
|
-
# @see AcePortSpec#initialize
|
175
|
-
def initialize(opts)
|
176
|
-
super
|
177
|
-
@protocol = :tcp
|
178
|
-
end
|
179
|
-
|
180
|
-
private
|
181
|
-
|
182
|
-
# Convert from port name string to AceTcpProtoSpecBase object
|
183
|
-
# @param [String] name TCP Port Name
|
184
|
-
# @raise [AclArgumentError]
|
185
|
-
# @return [AceTcpProtoSpec]
|
186
|
-
def convert_proto_spec_by_name(name)
|
187
|
-
AceTcpProtoSpec.new(name: name)
|
188
|
-
end
|
189
|
-
|
190
|
-
# Convert from port number integer to AceTcpProtoSpecBase object
|
191
|
-
# @param [Integer] number TCP Port Number
|
192
|
-
# @raise [AclArgumentError]
|
193
|
-
# @return [AceTcpProtoSpec]
|
194
|
-
def convert_proto_spec_by_number(number)
|
195
|
-
AceTcpProtoSpec.new(number: number)
|
196
|
-
end
|
197
|
-
end # class AceTcpPortSpec
|
198
|
-
|
199
|
-
# UDP port number and operator container
|
200
|
-
class AceUdpPortSpec < AcePortSpec
|
201
|
-
# Constructor
|
202
|
-
# @see AcePortSpec#initialize
|
203
|
-
def initialize(opts)
|
204
|
-
super
|
205
|
-
@protocol = :udp
|
206
|
-
end
|
207
|
-
|
208
|
-
private
|
209
|
-
|
210
|
-
# Convert from port name stringto AceUdpProtoSpecBase object
|
211
|
-
# @param [String] name UDP Port Name
|
212
|
-
# @raise [AclArgumentError]
|
213
|
-
# @return [AceUdpProtoSpec]
|
214
|
-
def convert_proto_spec_by_name(name)
|
215
|
-
AceUdpProtoSpec.new(name: name)
|
216
|
-
end
|
217
|
-
|
218
|
-
# Convert from port number integer to AceUdpProtoSpecBase object
|
219
|
-
# @param [Integer] number UDP Port Number
|
220
|
-
# @raise [AclArgumentError]
|
221
|
-
# @return [AceUdpProtoSpec]
|
222
|
-
def convert_proto_spec_by_number(number)
|
223
|
-
AceUdpProtoSpec.new(number: number)
|
224
|
-
end
|
225
|
-
end # class AceUdpPortSpec
|
80
|
+
end
|
226
81
|
end # module
|
227
82
|
|
228
83
|
### Local variables:
|
@@ -0,0 +1,251 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'cisco_acl_intp/ace_port_opr_base'
|
3
|
+
|
4
|
+
module CiscoAclIntp
|
5
|
+
# ANY operator class
|
6
|
+
class AcePortOpAny < AceUnaryOpBase
|
7
|
+
# Constructor
|
8
|
+
def initialize(*args)
|
9
|
+
@begin_port = nil
|
10
|
+
@end_port = nil
|
11
|
+
@operator = :any
|
12
|
+
end
|
13
|
+
|
14
|
+
# Specified port-set is contained or not?
|
15
|
+
# @param [AcePortOperator] other Another operator
|
16
|
+
# @return [Boolean]
|
17
|
+
def contains?(other)
|
18
|
+
other.kind_of?(AcePortOperatorBase) # match any conditions
|
19
|
+
end
|
20
|
+
|
21
|
+
# Generate string for Cisco IOS access list
|
22
|
+
# @return [String]
|
23
|
+
def to_s
|
24
|
+
# no need to print tcp/udp ANY in Cisco ACL
|
25
|
+
''
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# SSTRICT-ANY operator class
|
30
|
+
class AcePortOpStrictAny < AcePortOpAny
|
31
|
+
# Constructor
|
32
|
+
def initialize(*args)
|
33
|
+
super
|
34
|
+
@operator = :strict_any
|
35
|
+
end
|
36
|
+
|
37
|
+
# Specified port-set is contained or not?
|
38
|
+
# @param [AcePortOperator] other Another operator
|
39
|
+
# @return [Boolean]
|
40
|
+
def contains?(other)
|
41
|
+
case other
|
42
|
+
when AcePortOpAny, AcePortOpStrictAny
|
43
|
+
true
|
44
|
+
else
|
45
|
+
false
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# EQUAL operator class
|
51
|
+
class AcePortOpEq < AceUnaryOpBase
|
52
|
+
# Constructor
|
53
|
+
def initialize(*args)
|
54
|
+
super
|
55
|
+
@operator = :eq
|
56
|
+
end
|
57
|
+
|
58
|
+
# Specified port-set is contained or not?
|
59
|
+
# @param [AcePortOperator] other Another operator
|
60
|
+
# @return [Boolean]
|
61
|
+
def contains?(other)
|
62
|
+
case other
|
63
|
+
when AcePortOpEq
|
64
|
+
other.port == @begin_port
|
65
|
+
else
|
66
|
+
contains_default(other)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# NOT_EQUAL operator class
|
72
|
+
class AcePortOpNeq < AceUnaryOpBase
|
73
|
+
# Constructor
|
74
|
+
def initialize(*args)
|
75
|
+
super
|
76
|
+
@operator = :neq
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
# Operate EQUAL containing check
|
82
|
+
# @param [AcePortOperator] other Another operator
|
83
|
+
# @return [Boolean]
|
84
|
+
def compare_eq(other)
|
85
|
+
other.port != @begin_port
|
86
|
+
end
|
87
|
+
|
88
|
+
# Operate NOT_EQUAL containing check
|
89
|
+
# @param [AcePortOperator] other Another operator
|
90
|
+
# @return [Boolean]
|
91
|
+
def compare_neq(other)
|
92
|
+
other.port == @begin_port
|
93
|
+
end
|
94
|
+
|
95
|
+
# Operate LOWER_THAN containing check
|
96
|
+
# @param [AcePortOperator] other Another operator
|
97
|
+
# @return [Boolean]
|
98
|
+
def compare_lt(other)
|
99
|
+
other.port <= @begin_port
|
100
|
+
end
|
101
|
+
|
102
|
+
# Operate GREATER_THAN containing check
|
103
|
+
# @param [AcePortOperator] other Another operator
|
104
|
+
# @return [Boolean]
|
105
|
+
def compare_gt(other)
|
106
|
+
@begin_port <= other.port
|
107
|
+
end
|
108
|
+
|
109
|
+
# Operate RANGE containing check
|
110
|
+
# @param [AcePortOperator] other Another operator
|
111
|
+
# @return [Boolean]
|
112
|
+
def compare_range(other)
|
113
|
+
other.end_port < @begin_port || @begin_port < other.begin_port
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
# LOWER_THAN operator class
|
118
|
+
class AcePortOpLt < AceUnaryOpBase
|
119
|
+
# Constructor
|
120
|
+
def initialize(*args)
|
121
|
+
super
|
122
|
+
@operator = :lt
|
123
|
+
end
|
124
|
+
|
125
|
+
private
|
126
|
+
|
127
|
+
# Operate EQUAL containing check
|
128
|
+
# @param [AcePortOperator] other Another operator
|
129
|
+
# @return [Boolean]
|
130
|
+
def compare_eq(other)
|
131
|
+
other.port < @begin_port
|
132
|
+
end
|
133
|
+
|
134
|
+
# Operate NOT_EQUAL containing check
|
135
|
+
# @param [AcePortOperator] other Another operator
|
136
|
+
# @return [Boolean]
|
137
|
+
def compare_neq(other)
|
138
|
+
other.port.max? && @begin_port.max?
|
139
|
+
end
|
140
|
+
|
141
|
+
# Operate LOWER_THAN containing check
|
142
|
+
# @param [AcePortOperator] other Another operator
|
143
|
+
# @return [Boolean]
|
144
|
+
def compare_lt(other)
|
145
|
+
other.port <= @begin_port
|
146
|
+
end
|
147
|
+
|
148
|
+
# Operate RANGE containing check
|
149
|
+
# @param [AcePortOperator] other Another operator
|
150
|
+
# @return [Boolean]
|
151
|
+
def compare_range(other)
|
152
|
+
other.end_port < @begin_port
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
# GREATER_THAN operator class
|
157
|
+
class AcePortOpGt < AceUnaryOpBase
|
158
|
+
# Constructor
|
159
|
+
def initialize(*args)
|
160
|
+
super
|
161
|
+
@operator = :gt
|
162
|
+
end
|
163
|
+
|
164
|
+
private
|
165
|
+
|
166
|
+
# Operate EQUAL containing check
|
167
|
+
# @param [AcePortOperator] other Another operator
|
168
|
+
# @return [Boolean]
|
169
|
+
def compare_eq(other)
|
170
|
+
@begin_port < other.port
|
171
|
+
end
|
172
|
+
|
173
|
+
# Operate NOT_EQUAL containing check
|
174
|
+
# @param [AcePortOperator] other Another operator
|
175
|
+
# @return [Boolean]
|
176
|
+
def compare_neq(other)
|
177
|
+
@begin_port.min? && other.port.min?
|
178
|
+
end
|
179
|
+
|
180
|
+
# Operate GREATER_THAN containing check
|
181
|
+
# @param [AcePortOperator] other Another operator
|
182
|
+
# @return [Boolean]
|
183
|
+
def compare_gt(other)
|
184
|
+
@begin_port <= other.port
|
185
|
+
end
|
186
|
+
|
187
|
+
# Operate RANGE containing check
|
188
|
+
# @param [AcePortOperator] other Another operator
|
189
|
+
# @return [Boolean]
|
190
|
+
def compare_range(other)
|
191
|
+
@begin_port < other.begin_port
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
# RANGE operator class
|
196
|
+
class AcePortOpRange < AcePortOperatorBase
|
197
|
+
# Constructor
|
198
|
+
def initialize(*args)
|
199
|
+
super
|
200
|
+
unless @begin_port < @end_port
|
201
|
+
fail AclArgumentError, 'Invalid port sequence'
|
202
|
+
end
|
203
|
+
@operator = :range
|
204
|
+
end
|
205
|
+
|
206
|
+
private
|
207
|
+
|
208
|
+
# Operate EQUAL containing check
|
209
|
+
# @param [AcePortOperator] other Another operator
|
210
|
+
# @return [Boolean]
|
211
|
+
def compare_eq(other)
|
212
|
+
@begin_port <= other.port && other.port <= @end_port
|
213
|
+
end
|
214
|
+
|
215
|
+
# Operate NOT_EQUAL containing check
|
216
|
+
# @param [AcePortOperator] other Another operator
|
217
|
+
# @return [Boolean]
|
218
|
+
def compare_neq(other)
|
219
|
+
@begin_port.min? && @end_port.max? &&
|
220
|
+
(other.port.min? || other.port.max?)
|
221
|
+
end
|
222
|
+
|
223
|
+
# Operate LOWER_THAN containing check
|
224
|
+
# @param [AcePortOperator] other Another operator
|
225
|
+
# @return [Boolean]
|
226
|
+
def compare_lt(other)
|
227
|
+
@begin_port.min? && other.port < @end_port
|
228
|
+
end
|
229
|
+
|
230
|
+
# Operate GREATER_THAN containing check
|
231
|
+
# @param [AcePortOperator] other Another operator
|
232
|
+
# @return [Boolean]
|
233
|
+
def compare_gt(other)
|
234
|
+
@begin_port < other.port && @end_port.max?
|
235
|
+
end
|
236
|
+
|
237
|
+
# Operate RANGE containing check
|
238
|
+
# @param [AcePortOperator] other Another operator
|
239
|
+
# @return [Boolean]
|
240
|
+
def compare_range(other)
|
241
|
+
@begin_port <= other.begin_port &&
|
242
|
+
other.end_port <= @end_port
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end # module
|
246
|
+
|
247
|
+
### Local variables:
|
248
|
+
### mode: Ruby
|
249
|
+
### coding: utf-8-unix
|
250
|
+
### indent-tabs-mode: nil
|
251
|
+
### End:
|
@@ -0,0 +1,138 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'cisco_acl_intp/acl_base'
|
3
|
+
|
4
|
+
module CiscoAclIntp
|
5
|
+
# TCP/UDP Port Set Operator Class
|
6
|
+
class AcePortOperatorBase < AclContainerBase
|
7
|
+
# @return
|
8
|
+
attr_reader :operator
|
9
|
+
|
10
|
+
# @param [AceProtoSpecBase] value Port No. (single/lower)
|
11
|
+
# @return [AceProtoSpecBase]
|
12
|
+
attr_reader :begin_port
|
13
|
+
# alias for unary operator
|
14
|
+
alias_method :port, :begin_port
|
15
|
+
|
16
|
+
# @param [AceProtoSpecBase] value Port No. (higher)
|
17
|
+
# @return [AceProtoSpecBase]
|
18
|
+
attr_reader :end_port
|
19
|
+
|
20
|
+
# Constructor
|
21
|
+
# @param [AceProtoSpecBase] begin_port Begin port object.
|
22
|
+
# @param [AceProtoSpecBase] end_port End port object.
|
23
|
+
# @raise [AclArgumentError]
|
24
|
+
def initialize(begin_port, end_port = nil)
|
25
|
+
@operator = :any # default
|
26
|
+
@begin_port = begin_port
|
27
|
+
@end_port = end_port
|
28
|
+
end
|
29
|
+
|
30
|
+
# Check equality
|
31
|
+
# @param [AceProtoSpecBase] other RHS object.
|
32
|
+
# @return [Boolean]
|
33
|
+
def ==(other)
|
34
|
+
@operator == other.operator &&
|
35
|
+
@begin_port == other.begin_port &&
|
36
|
+
@end_port == other.end_port
|
37
|
+
end
|
38
|
+
|
39
|
+
# Generate string for Cisco IOS access list
|
40
|
+
# @return [String]
|
41
|
+
def to_s
|
42
|
+
tag_port(
|
43
|
+
clean_acl_string(
|
44
|
+
format('%s %s %s', @operator, @begin_port, @end_port)
|
45
|
+
)
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Specified port-set is contained or not?
|
50
|
+
# @param [AcePortOperator] other Another operator
|
51
|
+
# @return [Boolean]
|
52
|
+
def contains?(other)
|
53
|
+
case other
|
54
|
+
when AcePortOpEq
|
55
|
+
compare_eq(other)
|
56
|
+
when AcePortOpNeq
|
57
|
+
compare_neq(other)
|
58
|
+
when AcePortOpLt
|
59
|
+
compare_lt(other)
|
60
|
+
when AcePortOpGt
|
61
|
+
compare_gt(other)
|
62
|
+
when AcePortOpRange
|
63
|
+
compare_range(other)
|
64
|
+
else
|
65
|
+
contains_default(other)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
# Operate EQUAL containing check
|
72
|
+
# @param [AcePortOperator] other Another operator
|
73
|
+
# @return [Boolean]
|
74
|
+
def compare_eq(other)
|
75
|
+
false
|
76
|
+
end
|
77
|
+
|
78
|
+
# Operate NOT_EQUAL containing check
|
79
|
+
# @param [AcePortOperator] other Another operator
|
80
|
+
# @return [Boolean]
|
81
|
+
def compare_neq(other)
|
82
|
+
false
|
83
|
+
end
|
84
|
+
|
85
|
+
# Operate LOWER_THAN containing check
|
86
|
+
# @param [AcePortOperator] other Another operator
|
87
|
+
# @return [Boolean]
|
88
|
+
def compare_lt(other)
|
89
|
+
false
|
90
|
+
end
|
91
|
+
|
92
|
+
# Operate GREATER_THAN containing check
|
93
|
+
# @param [AcePortOperator] other Another operator
|
94
|
+
# @return [Boolean]
|
95
|
+
def compare_gt(other)
|
96
|
+
false
|
97
|
+
end
|
98
|
+
|
99
|
+
# Operate RANGE containing check
|
100
|
+
# @param [AcePortOperator] other Another operator
|
101
|
+
# @return [Boolean]
|
102
|
+
def compare_range(other)
|
103
|
+
false
|
104
|
+
end
|
105
|
+
|
106
|
+
# Operate *ANY containing check
|
107
|
+
# @param [AcePortOperator] other Another operator
|
108
|
+
# @return [Boolean]
|
109
|
+
def contains_default(other)
|
110
|
+
case other
|
111
|
+
when AcePortOpAny
|
112
|
+
true
|
113
|
+
when AcePortOpStrictAny
|
114
|
+
false
|
115
|
+
else
|
116
|
+
false
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
# Unary operator base class
|
122
|
+
class AceUnaryOpBase < AcePortOperatorBase
|
123
|
+
# Constructor
|
124
|
+
def initialize(*args)
|
125
|
+
super
|
126
|
+
if @begin_port.nil?
|
127
|
+
fail AclArgumentError, 'Port did not specified in unary operator'
|
128
|
+
end
|
129
|
+
@end_port = nil
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end # module
|
133
|
+
|
134
|
+
### Local variables:
|
135
|
+
### mode: Ruby
|
136
|
+
### coding: utf-8-unix
|
137
|
+
### indent-tabs-mode: nil
|
138
|
+
### End:
|