ICMPv4.pm

filter: Statementstmt 81.5% 146 / 179 Branchbran 11.7% 4 / 34 Conditioncond 0.0% 0 / 26 MC/DCmcdc 0.0% 0 / 17 Subroutinesub 89.8% 44 / 49 Podpod 100% 10 / 10 totaltotal 64.7% 204 / 315 CC 28 SCAR 36.6
CC
28
Cov
63%
encapsulate
138.9
match
90.0
computeChecksums
30.0
CRAP 38.9
↑ Summary ICMPv4/DestUnreach.pm »
1 #
2 # $Id: ICMPv4.pm 56 2015-01-20 18:55:33Z gomor $
3 #
4 package Net::Frame::Layer::ICMPv4;
5 3 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 our $VERSION = '1.05';
8  
9 3 ▶use Net::Frame::Layer qw(:consts :subs);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 our @ISA = qw(Net::Frame::Layer Exporter);
12  
13 3 our %EXPORT_TAGS = (
14 consts => [qw(
15 NF_ICMPv4_HDR_LEN
16 NF_ICMPv4_CODE_ZERO
17 NF_ICMPv4_TYPE_DESTUNREACH
18 NF_ICMPv4_CODE_NETWORK
19 NF_ICMPv4_CODE_HOST
20 NF_ICMPv4_CODE_PROTOCOL
21 NF_ICMPv4_CODE_PORT
22 NF_ICMPv4_CODE_FRAGMENTATION_NEEDED
23 NF_ICMPv4_CODE_SOURCE_ROUTE_FAILED
24 NF_ICMPv4_TYPE_TIMEEXCEED
25 NF_ICMPv4_CODE_TTL_IN_TRANSIT
26 NF_ICMPv4_CODE_FRAGMENT_REASSEMBLY
27 NF_ICMPv4_TYPE_PARAMETERPROBLEM
28 NF_ICMPv4_CODE_POINTER
29 NF_ICMPv4_TYPE_SOURCEQUENCH
30 NF_ICMPv4_TYPE_REDIRECT
31 NF_ICMPv4_CODE_FOR_NETWORK
32 NF_ICMPv4_CODE_FOR_HOST
33 NF_ICMPv4_CODE_FOR_TOS_AND_NETWORK
34 NF_ICMPv4_CODE_FOR_TOS_AND_HOST
35 NF_ICMPv4_TYPE_ECHO_REQUEST
36 NF_ICMPv4_TYPE_ECHO_REPLY
37 NF_ICMPv4_TYPE_TIMESTAMP_REQUEST
38 NF_ICMPv4_TYPE_TIMESTAMP_REPLY
39 NF_ICMPv4_TYPE_INFORMATION_REQUEST
40 NF_ICMPv4_TYPE_INFORMATION_REPLY
41 NF_ICMPv4_TYPE_ADDRESS_MASK_REQUEST
42 NF_ICMPv4_TYPE_ADDRESS_MASK_REPLY
43 )],
44 );
45 our @EXPORT_OK = (
46 3 @{$EXPORT_TAGS{consts}},
47 );
48  
49 3 ▶use constant NF_ICMPv4_HDR_LEN => 8;
Subroutine BEGIN: called CC=1 SCAR=0.0
50 3 ▶use constant NF_ICMPv4_CODE_ZERO => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
51 3 ▶use constant NF_ICMPv4_TYPE_DESTUNREACH => 3;
Subroutine BEGIN: called CC=1 SCAR=0.0
52 3 ▶use constant NF_ICMPv4_CODE_NETWORK => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
53 3 ▶use constant NF_ICMPv4_CODE_HOST => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
54 3 ▶use constant NF_ICMPv4_CODE_PROTOCOL => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
55 3 ▶use constant NF_ICMPv4_CODE_PORT => 3;
Subroutine BEGIN: called CC=1 SCAR=0.0
56 3 ▶use constant NF_ICMPv4_CODE_FRAGMENTATION_NEEDED => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
57 3 ▶use constant NF_ICMPv4_CODE_SOURCE_ROUTE_FAILED => 5;
Subroutine BEGIN: called CC=1 SCAR=0.0
58 3 ▶use constant NF_ICMPv4_TYPE_TIMEEXCEED => 11;
Subroutine BEGIN: called CC=1 SCAR=0.0
59 3 ▶use constant NF_ICMPv4_CODE_TTL_IN_TRANSIT => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
60 3 ▶use constant NF_ICMPv4_CODE_FRAGMENT_REASSEMBLY => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
61 3 ▶use constant NF_ICMPv4_TYPE_PARAMETERPROBLEM => 12;
Subroutine BEGIN: called CC=1 SCAR=0.0
62 3 ▶use constant NF_ICMPv4_CODE_POINTER => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
63 3 ▶use constant NF_ICMPv4_TYPE_SOURCEQUENCH => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
64 3 ▶use constant NF_ICMPv4_TYPE_REDIRECT => 5;
Subroutine BEGIN: called CC=1 SCAR=0.0
65 3 ▶use constant NF_ICMPv4_CODE_FOR_NETWORK => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
66 3 ▶use constant NF_ICMPv4_CODE_FOR_HOST => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
67 3 ▶use constant NF_ICMPv4_CODE_FOR_TOS_AND_NETWORK => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
68 3 ▶use constant NF_ICMPv4_CODE_FOR_TOS_AND_HOST => 3;
Subroutine BEGIN: called CC=1 SCAR=0.0
69 3 ▶use constant NF_ICMPv4_TYPE_ECHO_REQUEST => 8;
Subroutine BEGIN: called CC=1 SCAR=0.0
70 3 ▶use constant NF_ICMPv4_TYPE_ECHO_REPLY => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
71 3 ▶use constant NF_ICMPv4_TYPE_TIMESTAMP_REQUEST => 13;
Subroutine BEGIN: called CC=1 SCAR=0.0
72 3 ▶use constant NF_ICMPv4_TYPE_TIMESTAMP_REPLY => 14;
Subroutine BEGIN: called CC=1 SCAR=0.0
73 3 ▶use constant NF_ICMPv4_TYPE_INFORMATION_REQUEST => 15;
Subroutine BEGIN: called CC=1 SCAR=0.0
74 3 ▶use constant NF_ICMPv4_TYPE_INFORMATION_REPLY => 16;
Subroutine BEGIN: called CC=1 SCAR=0.0
75 3 ▶use constant NF_ICMPv4_TYPE_ADDRESS_MASK_REQUEST => 17; # RFC 950
Subroutine BEGIN: called CC=1 SCAR=0.0
76 3 ▶use constant NF_ICMPv4_TYPE_ADDRESS_MASK_REPLY => 18; # RFC 950
Subroutine BEGIN: called CC=1 SCAR=0.0
77  
78 3 our @AS = qw(
79 type
80 code
81 checksum
82 );
83 3 __PACKAGE__->cgBuildIndices;
84 3 __PACKAGE__->cgBuildAccessorsScalar(\@AS);
85  
86 3 ▶use Net::Frame::Layer::ICMPv4::AddressMask;
Subroutine BEGIN: called CC=1 SCAR=0.0
87 3 ▶use Net::Frame::Layer::ICMPv4::DestUnreach;
Subroutine BEGIN: called CC=1 SCAR=0.0
88 3 ▶use Net::Frame::Layer::ICMPv4::Echo;
Subroutine BEGIN: called CC=1 SCAR=0.0
89 3 ▶use Net::Frame::Layer::ICMPv4::Information;
Subroutine BEGIN: called CC=1 SCAR=0.0
90 3 ▶use Net::Frame::Layer::ICMPv4::Redirect;
Subroutine BEGIN: called CC=1 SCAR=0.0
91 3 ▶use Net::Frame::Layer::ICMPv4::TimeExceed;
Subroutine BEGIN: called CC=1 SCAR=0.0
92 3 ▶use Net::Frame::Layer::ICMPv4::Timestamp;
Subroutine BEGIN: called CC=1 SCAR=0.0
93  
94 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
95 1 my $self = shift->SUPER::new(
96 type => NF_ICMPv4_TYPE_ECHO_REQUEST,
97 code => NF_ICMPv4_CODE_ZERO,
98 checksum => 0,
99 @_,
100 );
101  
102 1 return $self;
103 }
104  
105 0 ▶sub match {
Subroutine match: not called CC=9 SCAR=45.0
Pod documented
106 0 my $self = shift;
107 0 my ($with) = @_;
108 0 my $sType = $self->type;
109 0 my $wType = $with->type;
110 0 ▶ if ($sType eq NF_ICMPv4_TYPE_ECHO_REQUEST
Branch: 4 branches
BranchTrueFalseTotal
if ($sType eq 8 and $wType eq 0) { } 0 0 0
elsif ($sType eq 13 and $wType eq 14) { } 0 0 0
elsif ($sType eq 15 and $wType eq 16) { } 0 0 0
elsif ($sType eq 17 and $wType eq 18) { } 0 0 0
Condition0%0/3
$sType eq 8 and $wType eq 0
!ll&&!rl&&r
000
MC/DC0%0/2
$sType eq 8 and $wType eq 0
$sType eq 8 $wType eq 0
Truth table0%0/3
A and B
A= $sType eq 8B= $wType eq 0
ABresult
0X0
100
111
111 && $wType eq NF_ICMPv4_TYPE_ECHO_REPLY) {
112 0 return 1;
113 }
114 ▶ elsif ($sType eq NF_ICMPv4_TYPE_TIMESTAMP_REQUEST
Condition0%0/3
$sType eq 13 and $wType eq 14
!ll&&!rl&&r
000
MC/DC0%0/2
$sType eq 13 and $wType eq 14
$sType eq 13 $wType eq 14
Truth table0%0/3
A and B
A= $sType eq 13B= $wType eq 14
ABresult
0X0
100
111
115 && $wType eq NF_ICMPv4_TYPE_TIMESTAMP_REPLY) {
116 0 return 1;
117 }
118 ▶ elsif ($sType eq NF_ICMPv4_TYPE_INFORMATION_REQUEST
Condition0%0/3
$sType eq 15 and $wType eq 16
!ll&&!rl&&r
000
MC/DC0%0/2
$sType eq 15 and $wType eq 16
$sType eq 15 $wType eq 16
Truth table0%0/3
A and B
A= $sType eq 15B= $wType eq 16
ABresult
0X0
100
111
119 && $wType eq NF_ICMPv4_TYPE_INFORMATION_REPLY) {
120 0 return 1;
121 }
122 ▶ elsif ($sType eq NF_ICMPv4_TYPE_ADDRESS_MASK_REQUEST
Condition0%0/3
$sType eq 17 and $wType eq 18
!ll&&!rl&&r
000
MC/DC0%0/2
$sType eq 17 and $wType eq 18
$sType eq 17 $wType eq 18
Truth table0%0/3
A and B
A= $sType eq 17B= $wType eq 18
ABresult
0X0
100
111
123 && $wType eq NF_ICMPv4_TYPE_ADDRESS_MASK_REPLY) {
124 0 return 1;
125 }
126 0 0;
127 }
128  
129 # XXX: may be better, by keying on type also
130 0 ▶sub getKey { shift->layer }
Subroutine getKey: not called CC=1 SCAR=6.9
Pod documented
131 0 ▶sub getKeyReverse { shift->layer }
Subroutine getKeyReverse: not called CC=1 SCAR=6.9
Pod documented
132  
133 0 ▶sub getLength { 4 }
Subroutine getLength: not called CC=1 SCAR=6.9
Pod documented
134  
135 1 ▶sub pack {
Subroutine pack: called CC=2 SCAR=7.1
Pod documented
136 1 my $self = shift;
137  
138 1 ▶ my $raw = $self->SUPER::pack('CCn',
Branch: 1 branch
BranchTrueFalseTotal
my $raw = $self->SUPER::pack("CCn", $self->type, $self->code, $self->checksum) or return 1 0 1
139 $self->type, $self->code, $self->checksum,
140 ) or return;
141  
142 1 return $self->raw($raw);
143 }
144  
145 1 ▶sub unpack {
Subroutine unpack: called CC=2 SCAR=7.0
Pod documented
146 1 my $self = shift;
147  
148 1 ▶ my ($type, $code, $checksum, $payload) =
Branch: 1 branch
BranchTrueFalseTotal
() = $self->SUPER::unpack("CCn a*", $self->raw) or return 1 0 1
149 $self->SUPER::unpack('CCn a*', $self->raw)
150 or return;
151  
152 1 $self->type($type);
153 1 $self->code($code);
154 1 $self->checksum($checksum);
155  
156 1 $self->payload($payload);
157  
158 1 return $self;
159 }
160  
161 0 ▶sub computeChecksums {
Subroutine computeChecksums: not called CC=5 SCAR=34.0
Pod documented
162 0 my $self = shift;
163 0 my ($layers) = @_;
164  
165 0 my $icmpType;
166 0 for my $l (@$layers) {
167 0 ▶ if ($l->layer =~ /ICMPv4::/) { $icmpType = $l; last; }
Branch: 1 branch
BranchTrueFalseTotal
if ($l->layer =~ /ICMPv4::/) 0 0 0
168 }
169  
170 0 ▶ my $packed = $self->SUPER::pack('CCna*',
Branch: 1 branch
BranchTrueFalseTotal
my $packed = $self->SUPER::pack("CCna*", $self->type, $self->code, 0, $icmpType->pack) or return 0 0 0
171 $self->type, $self->code, 0, $icmpType->pack,
172 ) or return;
173  
174 0 ▶ my $payload = $layers->[-1]->payload || '';
Condition0%0/2
$layers->[-1]->payload || ''
l!l
00
MC/DC0%0/1
$layers->[-1]->payload || ''
$layers->[-1]->payload
Truth table0%0/2
A
A= $layers->[-1]->payload
Aresult
11
00
175 0 $self->checksum(inetChecksum($packed.$payload));
176  
177 0 return 1;
178 }
179  
180 1 ▶sub encapsulate {
Subroutine encapsulate: called CC=14 SCAR=49.3
Pod documented
181 1 my $self = shift;
182  
183 1 ▶ return $self->nextLayer if $self->nextLayer;
Branch: 1 branch
BranchTrueFalseTotal
if $self->nextLayer 0 1 1
184  
185 1 ▶ if ($self->payload) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->payload) 0 1 1
186 0 my $type = $self->type;
187 0 ▶ if ($type eq NF_ICMPv4_TYPE_ECHO_REQUEST
Branch: 7 branches
BranchTrueFalseTotal
if ($type eq 8 or $type eq 0) { } 0 0 0
elsif ($type eq 13 or $type eq 14) { } 0 0 0
elsif ($type eq 15 or $type eq 16) { } 0 0 0
elsif ($type eq 17 or $type eq 18) { } 0 0 0
elsif ($type eq 3) { } 0 0 0
elsif ($type eq 5) { } 0 0 0
elsif ($type eq 11) { } 0 0 0
Condition0%0/3
$type eq 8 or $type eq 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$type eq 8 or $type eq 0
$type eq 8 $type eq 0
Truth table0%0/3
A or B
A= $type eq 8B= $type eq 0
ABresult
1X1
011
000
188 || $type eq NF_ICMPv4_TYPE_ECHO_REPLY) {
189 0 return 'ICMPv4::Echo';
190 }
191 ▶ elsif ($type eq NF_ICMPv4_TYPE_TIMESTAMP_REQUEST
Condition0%0/3
$type eq 13 or $type eq 14
l!l&&r!l&&!r
000
MC/DC0%0/2
$type eq 13 or $type eq 14
$type eq 13 $type eq 14
Truth table0%0/3
A or B
A= $type eq 13B= $type eq 14
ABresult
1X1
011
000
192 || $type eq NF_ICMPv4_TYPE_TIMESTAMP_REPLY) {
193 0 return 'ICMPv4::Timestamp';
194 }
195 ▶ elsif ($type eq NF_ICMPv4_TYPE_INFORMATION_REQUEST
Condition0%0/3
$type eq 15 or $type eq 16
l!l&&r!l&&!r
000
MC/DC0%0/2
$type eq 15 or $type eq 16
$type eq 15 $type eq 16
Truth table0%0/3
A or B
A= $type eq 15B= $type eq 16
ABresult
1X1
011
000
196 || $type eq NF_ICMPv4_TYPE_INFORMATION_REPLY) {
197 0 return 'ICMPv4::Information';
198 }
199 ▶ elsif ($type eq NF_ICMPv4_TYPE_ADDRESS_MASK_REQUEST
Condition0%0/3
$type eq 17 or $type eq 18
l!l&&r!l&&!r
000
MC/DC0%0/2
$type eq 17 or $type eq 18
$type eq 17 $type eq 18
Truth table0%0/3
A or B
A= $type eq 17B= $type eq 18
ABresult
1X1
011
000
200 || $type eq NF_ICMPv4_TYPE_ADDRESS_MASK_REPLY) {
201 0 return 'ICMPv4::AddressMask';
202 }
203 elsif ($type eq NF_ICMPv4_TYPE_DESTUNREACH) {
204 0 return 'ICMPv4::DestUnreach';
205 }
206 elsif ($type eq NF_ICMPv4_TYPE_REDIRECT) {
207 0 return 'ICMPv4::Redirect';
208 }
209 elsif ($type eq NF_ICMPv4_TYPE_TIMEEXCEED) {
210 0 return 'ICMPv4::TimeExceed';
211 }
212 }
213  
214 1 return NF_LAYER_NONE;
215 }
216  
217 1 ▶sub print {
Subroutine print: called CC=1 SCAR=0.0
Pod documented
218 1 my $self = shift;
219  
220 1 my $l = $self->layer;
221 1 my $buf = sprintf "$l: type:%d code:%d checksum:0x%04x",
222 $self->type, $self->code, $self->checksum;
223  
224 1 return $buf;
225 }
226  
227 3 1;
228  
229 __END__
↑ Summary ICMPv4/DestUnreach.pm »