blib/lib/Langertha/Holmgang/Sim/Linux/Nft.pm

filter: Statementstmt 93.0% 363 / 390 Branchbran 72.8% 290 / 398 Conditioncond 58.6% 187 / 319 MC/DCmcdc 32.5% 57 / 175 Subroutinesub 100% 26 / 26 Podpod 100% 5 / 5 totaltotal 70.6% 928 / 1313 CC 321 SCAR 53.0
CC
321
Cov
76%
parse
543.4
_have
86.2
_check_val
43.6
CRAP 200.2
« blib/lib/Langertha/Holmgang/Expectation.pm ↑ Summary blib/lib/Langertha/Holmgang/ToolSchema.pm »
1 package Langertha::Holmgang::Sim::Linux::Nft;
2 # ABSTRACT: Evaluates the nftables ruleset of a simulated Linux device against a packet
3  
4 82 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 82 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 82 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 82 ▶use Socket qw( inet_pton AF_INET AF_INET6 );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 82 our $VERSION = '0.001';
11  
12  
13 82 my %PRIO = ( raw => -300, mangle => -150, dstnat => -100, filter => 0, security => 50, srcnat => 100 );
14 82 my %SERVICE = (
15 ssh => 22, http => 80, https => 443, domain => 53, smtp => 25, submission => 587, submissions => 465,
16 imap => 143, imaps => 993, pop3 => 110, pop3s => 995, ntp => 123, snmp => 161, ldap => 389, ldaps => 636,
17 'http-alt' => 8080, mysql => 3306, postgresql => 5432, bgp => 179, telnet => 23, ftp => 21, rsync => 873,
18 'openvpn' => 1194, 'sip' => 5060, 'syslog' => 514, 'bootps' => 67, 'bootpc' => 68, 'tftp' => 69, 'kerberos' => 88,
19 'microsoft-ds' => 445, 'ms-wbt-server' => 3389, 'redis' => 6379, 'zabbix-agent' => 10050, ipp => 631, printer => 515,
20 nfs => 2049, sunrpc => 111, 'netbios-ns' => 137, 'netbios-dgm' => 138, 'netbios-ssn' => 139, mdns => 5353, git => 9418,
21 'domain-s' => 853, 'http-alt' => 8080, 'webcache' => 8080, 'xmpp-client' => 5222, 'mqtt' => 1883, 'ntp' => 123,
22 );
23 82 my %PROTO = ( tcp => 6, udp => 17, icmp => 1, icmpv6 => 58, ipv6icmp => 58, 'ipv6-icmp' => 58, gre => 47, esp => 50, ah => 51 );
24 82 my %CTSTATUS = map { $_ => 1 } qw( expected seen-reply assured confirmed snat dnat dying );
25 82 my %CTSTATE = map { $_ => 1 } qw( new established related invalid untracked );
26 82 my %VERDICT = map { $_ => 1 } qw( accept drop reject continue return );
27 82 my %ICMP = map { $_ => 1 } qw( echo-request echo-reply destination-unreachable time-exceeded parameter-problem
28 source-quench redirect router-advertisement router-solicitation timestamp-request timestamp-reply
29 packet-too-big nd-router-solicit nd-router-advert nd-neighbor-solicit nd-neighbor-advert mld-listener-query
30 mld-listener-report mld-listener-done mld2-listener-report );
31  
32 82 my %ICMPCODE = map { $_ => 1 } qw( net-unreachable host-unreachable prot-unreachable port-unreachable frag-needed
33 net-prohibited host-prohibited admin-prohibited no-route addr-unreachable reject-route policy-fail );
34  
35 # --- Zerlegen --------------------------------------------------------------------
36  
37 141 ▶sub _tokens {
Subroutine _tokens: called CC=9 SCAR=22.5
38 141 my ($text) = @_;
39 141 my @t;
40 141 pos($text) = 0;
41 141 ▶ while ( pos($text) < length $text ) {
Branch: 1 branch
BranchTrueFalseTotal
if (pos $text < length $text) 1454 141 1595
42 1454 ▶ if ( $text =~ /\G\s+/gc ) { next }
Branch: 4 branches
BranchTrueFalseTotal
if ($text =~ /\G\s+/cg) { } 637 817 1454
elsif ($text =~ /\G"((?:[^"\\]|\\.)*)"/cg) { } 41 776 817
elsif ($text =~ /\G(!=|==|[{},;])/cg) { } 59 717 776
elsif ($text =~ /\G([^\s{},;"]+)/cg) { } 717 0 717
43 41 elsif ( $text =~ /\G"((?:[^"\\]|\\.)*)"/gc ) { push @t, { q => $1 } }
44 59 elsif ( $text =~ /\G(!=|==|[{},;])/gc ) { push @t, $1 }
45 elsif ( $text =~ /\G([^\s{},;"]+)/gc ) {
46 717 my $w = $1;
47 # IPv6 bleibt ein Wort; "established : accept" bzw. "established:accept" (vmap) nicht
48 717 ▶ if ( $w eq ':' ) { push @t, ':' }
Branch: 3 branches
BranchTrueFalseTotal
if ($w eq ':') { } 19 698 717
elsif ($w =~ /\A([a-z][\w-]*):\z/) { } 0 698 698
elsif ($w =~ /\A([a-z][\w-]*):([a-z][\w-]*)\z/) { } 0 698 698
49 0 elsif ( $w =~ /\A([a-z][\w-]*):\z/ ) { push @t, $1, ':' }
50 0 elsif ( $w =~ /\A([a-z][\w-]*):([a-z][\w-]*)\z/ ) { push @t, $1, ':', $2 }
51 698 else { push @t, $w }
52 }
53 0 else { die "unerwartetes Zeichen\n" }
54 }
55 141 return \@t;
56 }
57  
58 # Wert oder Menge { a, b } (mit vmap: { a : verdict, … })
59 180 ▶sub _value {
Subroutine _value: called CC=17 SCAR=28.7
60 180 my ( $t, $map ) = @_;
61 180 ▶ my $x = shift @$t // die "Wert fehlt\n";
Condition50%1/2
shift @$t // die("Wert fehlt\n")
l!l
1800
MC/DC0%0/1
shift @$t // die("Wert fehlt\n")
shift @$t
Truth table50%1/2
A
A= shift @$t
Aresult
11
00
62 180 ▶ if ( !ref $x && $x eq '{' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $x and $x eq "{") 14 166 180
Condition100%3/3
not ref $x and $x eq "{"
!ll&&!rl&&r
3513114
MC/DC100%2/2
not ref $x and $x eq "{"
not ref $x $x eq "{"
Truth table100%3/3
not(A) and B
A= not ref $xB= $x eq "{"
ABresult
0X0
100
111
63 14 my @items;
64 14 while (1) {
65 62 ▶ my $y = shift @$t // die "} fehlt\n";
Condition50%1/2
shift @$t // die("} fehlt\n")
l!l
620
MC/DC0%0/1
shift @$t // die("} fehlt\n")
shift @$t
Truth table50%1/2
A
A= shift @$t
Aresult
11
00
66 62 ▶ last if !ref $y && $y eq '}';
Branch: 1 branch
BranchTrueFalseTotal
if not ref $y and $y eq "}" 14 48 62
Condition100%3/3
not ref $y and $y eq "}"
!ll&&!rl&&r
44414
MC/DC100%2/2
not ref $y and $y eq "}"
not ref $y $y eq "}"
Truth table100%3/3
not(A) and B
A= not ref $yB= $y eq "}"
ABresult
0X0
100
111
67 48 ▶ next if !ref $y && $y eq ',';
Branch: 1 branch
BranchTrueFalseTotal
if not ref $y and $y eq "," 17 31 48
Condition100%3/3
not ref $y and $y eq ","
!ll&&!rl&&r
42717
MC/DC100%2/2
not ref $y and $y eq ","
not ref $y $y eq ","
Truth table100%3/3
not(A) and B
A= not ref $yB= $y eq ","
ABresult
0X0
100
111
68 31 ▶ my $v = ref $y ? $y->{q} : $y;
Branch: 1 branch
BranchTrueFalseTotal
ref $y ? : 4 27 31
69 31 ▶ if ($map) {
Branch: 1 branch
BranchTrueFalseTotal
if ($map) { } 19 12 31
70 19 my $c = shift @$t;
71 19 ▶ die "vmap ohne :\n" unless defined $c && !ref $c && $c eq ':';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $c and not ref $c and $c eq ":" 0 19 19
Condition33%2/6
defined $c and not ref $c and $c eq ":"
!ll&&!rl&&r
0019
defined $c and not ref $c
!ll&&!rl&&r
0019
MC/DC0%0/3
defined $c and not ref $c and $c eq ":"
defined $c not ref $c $c eq ":"
Truth table25%1/4
A and not(B) and C
A= defined $cB= not ref $cC= $c eq ":"
ABCresult
0XX0
10X0
1100
1111
72 19 my $verd = _verdict_tokens($t);
73 19 push @items, [ $v, $verd ];
74 }
75 12 else { push @items, $v }
76 }
77 14 return { set => \@items };
78 }
79 166 ▶ return { named => $1 } if !ref $x && $x =~ /\A@([\w-]+)\z/;
Branch: 1 branch
BranchTrueFalseTotal
if not ref $x and $x =~ /\A@([\w-]+)\z/ 19 147 166
Condition100%3/3
not ref $x and $x =~ /\A@([\w-]+)\z/
!ll&&!rl&&r
3511219
MC/DC100%2/2
not ref $x and $x =~ /\A@([\w-]+)\z/
not ref $x $x =~ /\A@([\w-]+)\z/
Truth table100%3/3
not(A) and B
A= not ref $xB= $x =~ /\A@([\w-]+)\z/
ABresult
0X0
100
111
80 147 ▶ return { one => ref $x ? $x->{q} : $x };
Branch: 1 branch
BranchTrueFalseTotal
ref $x ? : 35 112 147
81 }
82  
83 143 ▶sub _verdict_tokens {
Subroutine _verdict_tokens: called CC=8 SCAR=22.1
84 143 my ($t) = @_;
85 143 ▶ my $v = shift @$t // die "Urteil fehlt\n";
Condition50%1/2
shift @$t // die("Urteil fehlt\n")
l!l
1430
MC/DC0%0/1
shift @$t // die("Urteil fehlt\n")
shift @$t
Truth table50%1/2
A
A= shift @$t
Aresult
11
00
86 143 ▶ die "Urteil erwartet\n" if ref $v;
Branch: 1 branch
BranchTrueFalseTotal
if ref $v 0 143 143
87 143 ▶ if ( $v eq 'jump' || $v eq 'goto' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v eq "jump" or $v eq "goto") 5 138 143
Condition66%2/3
$v eq "jump" or $v eq "goto"
l!l&&r!l&&!r
50138
MC/DC50%1/2
$v eq "jump" or $v eq "goto"
$v eq "jump" $v eq "goto"
Truth table66%2/3
A or B
A= $v eq "jump"B= $v eq "goto"
ABresult
1X1
011
000
88 5 ▶ my $c = shift @$t // die "Kette fehlt\n";
Condition50%1/2
shift @$t // die("Kette fehlt\n")
l!l
50
MC/DC0%0/1
shift @$t // die("Kette fehlt\n")
shift @$t
Truth table50%1/2
A
A= shift @$t
Aresult
11
00
89 5 ▶ return { $v => ref $c ? $c->{q} : $c };
Branch: 1 branch
BranchTrueFalseTotal
ref $c ? : 0 5 5
90 }
91 138 ▶ die "unbekanntes Urteil $v\n" unless $VERDICT{$v};
Branch: 1 branch
BranchTrueFalseTotal
unless $VERDICT{$v} 0 138 138
92 138 return { $v => 1 };
93 }
94  
95 82 my %FIELD = (
96 'iifname' => 'iif', 'oifname' => 'oif', 'iif' => 'iif', 'oif' => 'oif',
97 );
98  
99  
100 141 ▶sub parse {
Subroutine parse: called CC=115 SCAR=63.0
Pod documented
101 141 my ($text) = @_;
102 141 ▶ my $t = eval { _tokens($text) } or return ( undef, "nicht zerlegbar: $text" );
Branch: 1 branch
BranchTrueFalseTotal
my $t = eval { do { _tokens($text) } } or return undef, "nicht zerlegbar: $text" 141 0 141
103 141 my ( @m, $verdict );
104 141 my $res = eval {
105 141 ▶ while (@$t) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$t) 316 0 316
106 316 my $w = shift @$t;
107 316 ▶ die "unerwartet\n" if ref $w;
Branch: 1 branch
BranchTrueFalseTotal
if ref $w 0 316 316
108 316 ▶ next if $w eq ';';
Branch: 1 branch
BranchTrueFalseTotal
if $w eq ";" 0 316 316
109 316 ▶ if ( $w eq 'counter' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($w eq "counter") 2 314 316
110 0 ▶ if ( @$t >= 4 && $t->[0] eq 'packets' ) { splice @$t, 0, 4 }
Branch: 1 branch
BranchTrueFalseTotal
if (@$t >= 4 and $$t[0] eq "packets") 0 2 2
Condition33%1/3
@$t >= 4 and $$t[0] eq "packets"
!ll&&!rl&&r
200
MC/DC0%0/2
@$t >= 4 and $$t[0] eq "packets"
@$t >= 4 $$t[0] eq "packets"
Truth table33%1/3
A and B
A= @$t >= 4B= $$t[0] eq "packets"
ABresult
0X0
100
111
111 2 next;
112 }
113 0 ▶ if ( $w eq 'comment' ) { shift @$t; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($w eq "comment") 0 314 314
114 314 ▶ if ( $w eq 'log' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($w eq "log") 1 313 314
115 1 ▶ while ( @$t && !ref $t->[0] && $t->[0] =~ /\A(?:prefix|level|flags|group)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$t and not ref $$t[0] and $$t[0] =~ /\A(?:prefix|level|flags|group)\z/) 1 1 2
Condition50%3/6
@$t and not ref $$t[0] and $$t[0] =~ /\A(?:prefix|level|flags|group)\z/
!ll&&!rl&&r
011
@$t and not ref $$t[0]
!ll&&!rl&&r
002
MC/DC33%1/3
@$t and not ref $$t[0] and $$t[0] =~ /\A(?:prefix|level|flags|group)\z/
@$t not ref $$t[0] $$t[0] =~ /\A(?:prefix|level|flags|group)\z/
Truth table50%2/4
A and not(B) and C
A= @$tB= not ref $$t[0]C= $$t[0] =~ /\A(?:prefix|level|flags|group)\z/
ABCresult
0XX0
10X0
1100
1111
116 1 my $k = shift @$t;
117 1 shift @$t;
118 1 ▶ shift @$t if $k eq 'flags' && @$t && !ref $t->[0] && $t->[0] =~ /\A(?:tcp|ip)\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $k eq "flags" and @$t and not ref $$t[0] and $$t[0] =~ /\A(?:tcp|ip)\z/ 0 1 1
Condition33%3/9
$k eq "flags" and @$t and not ref $$t[0] and $$t[0] =~ /\A(?:tcp|ip)\z/
!ll&&!rl&&r
100
$k eq "flags" and @$t and not ref $$t[0]
!ll&&!rl&&r
100
$k eq "flags" and @$t
!ll&&!rl&&r
100
MC/DC0%0/4
$k eq "flags" and @$t and not ref $$t[0] and $$t[0] =~ /\A(?:tcp|ip)\z/
$k eq "flags" @$t not ref $$t[0] $$t[0] =~ /\A(?:tcp|ip)\z/
Truth table20%1/5
A and B and not(C) and D
A= $k eq "flags"B= @$tC= not ref $$t[0]D= $$t[0] =~ /\A(?:tcp|ip)\z/
ABCDresult
0XXX0
10XX0
110X0
11100
11111
119 }
120 1 next;
121 }
122 313 ▶ if ( $w eq 'limit' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($w eq "limit") 2 311 313
123 2 ▶ die "limit ohne rate\n" unless ( shift(@$t) // '' ) eq 'rate';
Branch: 1 branch
BranchTrueFalseTotal
unless (shift @$t // "") eq "rate" 0 2 2
Condition50%1/2
shift @$t // ""
l!l
20
MC/DC0%0/1
shift @$t // ""
shift @$t
Truth table50%1/2
A
A= shift @$t
Aresult
11
00
124 2 my $over = 0;
125 2 ▶ if ( @$t && $t->[0] eq 'over' ) { shift @$t; $over = 1 }
Branch: 1 branch
BranchTrueFalseTotal
if (@$t and $$t[0] eq "over") 1 1 2
Condition66%2/3
@$t and $$t[0] eq "over"
!ll&&!rl&&r
011
MC/DC50%1/2
@$t and $$t[0] eq "over"
@$t $$t[0] eq "over"
Truth table66%2/3
A and B
A= @$tB= $$t[0] eq "over"
ABresult
0X0
100
111
126 2 ▶ my $r = shift @$t // die "rate fehlt\n";
Condition50%1/2
shift @$t // die("rate fehlt\n")
l!l
20
MC/DC0%0/1
shift @$t // die("rate fehlt\n")
shift @$t
Truth table50%1/2
A
A= shift @$t
Aresult
11
00
127 0 ▶ if ( @$t && $t->[0] =~ m{\A/} ) { $r .= shift @$t }
Branch: 1 branch
BranchTrueFalseTotal
if (@$t and $$t[0] =~ m[\A/]) 0 2 2
Condition33%1/3
@$t and $$t[0] =~ m[\A/]
!ll&&!rl&&r
020
MC/DC0%0/2
@$t and $$t[0] =~ m[\A/]
@$t $$t[0] =~ m[\A/]
Truth table33%1/3
A and B
A= @$tB= $$t[0] =~ m[\A/]
ABresult
0X0
100
111
128 2 ▶ die "rate unklar\n" unless $r =~ m{\A\d+(?:/|\s*)?(?:second|minute|hour|day|\w*bytes/\w+)?};
Branch: 1 branch
BranchTrueFalseTotal
unless $r =~ m[\A\d+(?:/|\s*)?(?:second|minute|hour|day|\w*bytes/\w+)?] 0 2 2
129 2 ▶ shift @$t if @$t && $t->[0] =~ m{\A/(?:second|minute|hour|day)\z};
Branch: 1 branch
BranchTrueFalseTotal
if @$t and $$t[0] =~ m[\A/(?:second|minute|hour|day)\z] 0 2 2
Condition33%1/3
@$t and $$t[0] =~ m[\A/(?:second|minute|hour|day)\z]
!ll&&!rl&&r
020
MC/DC0%0/2
@$t and $$t[0] =~ m[\A/(?:second|minute|hour|day)\z]
@$t $$t[0] =~ m[\A/(?:second|minute|hour|day)\z]
Truth table33%1/3
A and B
A= @$tB= $$t[0] =~ m[\A/(?:second|minute|hour|day)\z]
ABresult
0X0
100
111
130 2 ▶ if ( @$t && $t->[0] eq 'burst' ) { shift @$t; shift @$t; shift @$t if @$t && $t->[0] =~ /\A(?:packets|bytes|kbytes|mbytes)\z/ }
Branch: 2 branches
BranchTrueFalseTotal
if (@$t and $$t[0] eq "burst") 1 1 2
if @$t and $$t[0] =~ /\A(?:packets|bytes|kbytes|mbytes)\z/ 1 0 1
Condition50%3/6
@$t and $$t[0] eq "burst"
!ll&&!rl&&r
011
@$t and $$t[0] =~ /\A(?:packets|bytes|kbytes|mbytes)\z/
!ll&&!rl&&r
001
MC/DC50%1/2
@$t and $$t[0] eq "burst"
@$t $$t[0] eq "burst"
MC/DC0%0/2
@$t and $$t[0] =~ /\A(?:packets|bytes|kbytes|mbytes)\z/
@$t $$t[0] =~ /\A(?:packets|bytes|kbytes|mbytes)\z/
Truth table66%2/3
A and B
A= @$tB= $$t[0] eq "burst"
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= @$tB= $$t[0] =~ /\A(?:packets|bytes|kbytes|mbytes)\z/
ABresult
0X0
100
111
131 2 ▶ push @m, { field => 'never' } if $over;
Branch: 1 branch
BranchTrueFalseTotal
if $over 1 1 2
132 2 next;
133 }
134 311 ▶ if ( $VERDICT{$w} || $w eq 'jump' || $w eq 'goto' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($VERDICT{$w} or $w eq "jump" or $w eq "goto") 124 187 311
Condition66%4/6
$VERDICT{$w} or $w eq "jump" or $w eq "goto"
l!l&&r!l&&!r
1240187
$VERDICT{$w} or $w eq "jump"
l!l&&r!l&&!r
1240187
MC/DC33%1/3
$VERDICT{$w} or $w eq "jump" or $w eq "goto"
$VERDICT{$w} $w eq "jump" $w eq "goto"
Truth table50%2/4
A or B or C
A= $VERDICT{$w}B= $w eq "jump"C= $w eq "goto"
ABCresult
1XX1
01X1
0011
0000
135 124 unshift @$t, $w;
136 124 $verdict = _verdict_tokens($t);
137 124 ▶ if ( $w eq 'reject' && @$t && !ref $t->[0] && $t->[0] eq 'with' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($w eq "reject" and @$t and not ref $$t[0] and $$t[0] eq "with") 2 122 124
Condition66%6/9
$w eq "reject" and @$t and not ref $$t[0] and $$t[0] eq "with"
!ll&&!rl&&r
12202
$w eq "reject" and @$t and not ref $$t[0]
!ll&&!rl&&r
12202
$w eq "reject" and @$t
!ll&&!rl&&r
12202
MC/DC25%1/4
$w eq "reject" and @$t and not ref $$t[0] and $$t[0] eq "with"
$w eq "reject" @$t not ref $$t[0] $$t[0] eq "with"
Truth table40%2/5
A and B and not(C) and D
A= $w eq "reject"B= @$tC= not ref $$t[0]D= $$t[0] eq "with"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
138 2 ▶ shift @$t while @$t && !( !ref $t->[0] && $t->[0] eq 'comment' );
Branch: 1 branch
BranchTrueFalseTotal
@$t and not !ref($$t[0]) && $$t[0] eq "comment" and do { shift @$t } 7 2 9
Condition50%3/6
@$t and not !ref($$t[0]) && $$t[0] eq "comment"
!ll&&!rl&&r
207
!ref($$t[0]) && $$t[0] eq 'comment'
!ll&&!rl&&r
070
MC/DC33%1/3
@$t and not !ref($$t[0]) && $$t[0] eq "comment"
@$t !ref($$t[0]) $$t[0] eq 'comment'
Truth table50%2/4
A and not(not(B) && C)
A= @$tB= !ref($$t[0])C= $$t[0] eq 'comment'
ABCresult
0XX0
1110
10X1
1101
139 }
140 # hinter dem Urteil: counter, log …, comment "…" (wirken nicht auf das Urteil)
141 124 ▶ while ( @$t && !ref $t->[0] && $t->[0] =~ /\A(?:comment|counter|log)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$t and not ref $$t[0] and $$t[0] =~ /\A(?:comment|counter|log)\z/) 1 124 125
Condition83%5/6
@$t and not ref $$t[0] and $$t[0] =~ /\A(?:comment|counter|log)\z/
!ll&&!rl&&r
12311
@$t and not ref $$t[0]
!ll&&!rl&&r
12302
MC/DC66%2/3
@$t and not ref $$t[0] and $$t[0] =~ /\A(?:comment|counter|log)\z/
@$t not ref $$t[0] $$t[0] =~ /\A(?:comment|counter|log)\z/
Truth table75%3/4
A and not(B) and C
A= @$tB= not ref $$t[0]C= $$t[0] =~ /\A(?:comment|counter|log)\z/
ABCresult
0XX0
10X0
1100
1111
142 1 my $k = shift @$t;
143 1 ▶ if ( $k eq 'comment' ) { shift @$t }
Branch: 2 branches
BranchTrueFalseTotal
if ($k eq 'comment') { } 1 0 1
elsif ($k eq 'log') { } 0 0 0
144 0 ▶ elsif ( $k eq 'log' ) { while ( @$t && !ref $t->[0] && $t->[0] =~ /\A(?:prefix|level|flags|group)\z/ ) { shift @$t; shift @$t } }
Branch: 1 branch
BranchTrueFalseTotal
if (@$t and not ref $$t[0] and $$t[0] =~ /\A(?:prefix|level|flags|group)\z/) 0 0 0
Condition0%0/6
@$t and not ref $$t[0] and $$t[0] =~ /\A(?:prefix|level|flags|group)\z/
!ll&&!rl&&r
000
@$t and not ref $$t[0]
!ll&&!rl&&r
000
MC/DC0%0/3
@$t and not ref $$t[0] and $$t[0] =~ /\A(?:prefix|level|flags|group)\z/
@$t not ref $$t[0] $$t[0] =~ /\A(?:prefix|level|flags|group)\z/
Truth table0%0/4
A and not(B) and C
A= @$tB= not ref $$t[0]C= $$t[0] =~ /\A(?:prefix|level|flags|group)\z/
ABCresult
0XX0
10X0
1100
1111
145 }
146 124 ▶ die "nach dem Urteil: " . join( ' ', map { ref $_ ? qq{"$_->{q}"} : $_ } @$t ) . "\n" if @$t;
Branch: 2 branches
BranchTrueFalseTotal
if @$t 1 123 124
ref $_ ? : 0 1 1
147 123 last;
148 }
149 187 my $field;
150 187 ▶ if ( $w eq 'meta' ) {
Branch: 6 branches
BranchTrueFalseTotal
if ($w eq 'meta') { } 7 180 187
elsif ($FIELD{$w}) { } 41 139 180
elsif ($w eq 'ip' or $w eq 'ip6') { } 40 99 139
elsif ($w eq 'tcp' or $w eq 'udp' or $w eq 'th') { } 74 25 99
elsif ($w eq 'ct') { } 16 9 25
elsif ($w eq 'icmp' or $w eq 'icmpv6') { } 7 2 9
151 7 ▶ my $k = shift @$t // die "meta ohne Schluessel\n";
Condition50%1/2
shift @$t // die("meta ohne Schluessel\n")
l!l
70
MC/DC0%0/1
shift @$t // die("meta ohne Schluessel\n")
shift @$t
Truth table50%1/2
A
A= shift @$t
Aresult
11
00
152 7 ▶ if ( $FIELD{$k} ) { $field = $FIELD{$k} }
Branch: 3 branches
BranchTrueFalseTotal
if ($FIELD{$k}) { } 1 6 7
elsif ($k eq 'l4proto') { } 1 5 6
elsif ($k eq 'nfproto') { } 1 4 5
153 1 elsif ( $k eq 'l4proto' ) { $field = 'l4proto' }
154 1 elsif ( $k eq 'nfproto' ) { $field = 'nfproto' }
155 4 else { die "meta $k\n" }
156 }
157 41 elsif ( $FIELD{$w} ) { $field = $FIELD{$w} }
158 ▶ elsif ( $w eq 'ip' || $w eq 'ip6' ) {
Condition100%3/3
$w eq "ip" or $w eq "ip6"
l!l&&r!l&&!r
38299
MC/DC100%2/2
$w eq "ip" or $w eq "ip6"
$w eq "ip" $w eq "ip6"
Truth table100%3/3
A or B
A= $w eq "ip"B= $w eq "ip6"
ABresult
1X1
011
000
159 40 ▶ my $k = shift @$t // die "$w ohne Feld\n";
Condition50%1/2
shift @$t // die("$w ohne Feld\n")
l!l
400
MC/DC0%0/1
shift @$t // die("$w ohne Feld\n")
shift @$t
Truth table50%1/2
A
A= shift @$t
Aresult
11
00
160 40 ▶ if ( $k eq 'saddr' || $k eq 'daddr' ) { $field = "$w $k" }
Branch: 3 branches
BranchTrueFalseTotal
if ($k eq 'saddr' or $k eq 'daddr') { } 39 1 40
elsif ($w eq 'ip' and $k eq 'protocol') { } 1 0 1
elsif ($w eq 'ip6' and $k eq 'nexthdr') { } 0 0 0
Condition100%3/3
$k eq "saddr" or $k eq "daddr"
l!l&&r!l&&!r
3811
MC/DC100%2/2
$k eq "saddr" or $k eq "daddr"
$k eq "saddr" $k eq "daddr"
Truth table100%3/3
A or B
A= $k eq "saddr"B= $k eq "daddr"
ABresult
1X1
011
000
161 1 ▶ elsif ( $w eq 'ip' && $k eq 'protocol' ) { $field = 'ipproto4' }
Condition33%1/3
$w eq "ip" and $k eq "protocol"
!ll&&!rl&&r
001
MC/DC0%0/2
$w eq "ip" and $k eq "protocol"
$w eq "ip" $k eq "protocol"
Truth table33%1/3
A and B
A= $w eq "ip"B= $k eq "protocol"
ABresult
0X0
100
111
162 0 ▶ elsif ( $w eq 'ip6' && $k eq 'nexthdr' ) { $field = 'ipproto6' }
Condition0%0/3
$w eq "ip6" and $k eq "nexthdr"
!ll&&!rl&&r
000
MC/DC0%0/2
$w eq "ip6" and $k eq "nexthdr"
$w eq "ip6" $k eq "nexthdr"
Truth table0%0/3
A and B
A= $w eq "ip6"B= $k eq "nexthdr"
ABresult
0X0
100
111
163 0 else { die "$w $k\n" }
164 }
165 ▶ elsif ( $w eq 'tcp' || $w eq 'udp' || $w eq 'th' ) {
Condition100%6/6
$w eq "tcp" or $w eq "udp" or $w eq "th"
l!l&&r!l&&!r
73125
$w eq "tcp" or $w eq "udp"
l!l&&r!l&&!r
611226
MC/DC100%3/3
$w eq "tcp" or $w eq "udp" or $w eq "th"
$w eq "tcp" $w eq "udp" $w eq "th"
Truth table100%4/4
A or B or C
A= $w eq "tcp"B= $w eq "udp"C= $w eq "th"
ABCresult
1XX1
01X1
0011
0000
166 74 ▶ my $k = shift @$t // die "$w ohne Feld\n";
Condition50%1/2
shift @$t // die("$w ohne Feld\n")
l!l
740
MC/DC0%0/1
shift @$t // die("$w ohne Feld\n")
shift @$t
Truth table50%1/2
A
A= shift @$t
Aresult
11
00
167 # MSS-Anpassung: Anweisung ohne Wirkung auf das Urteil
168 0 ▶ if ( $w eq 'tcp' && $k eq 'option' && @$t >= 4 && !( grep {ref} @$t[ 0 .. 3 ] ) && "@$t[0..3]" =~ /\Amaxseg size set (?:rt mtu|\d+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($w eq "tcp" and $k eq "option" and @$t >= 4 and not grep({ref $_;} @$t[0..3]) and join($", @$t[0..3]) =~ /\Amaxseg size set (?:rt mtu|\d+)/) 0 74 74
Condition41%5/12
$w eq "tcp" and $k eq "option" and @$t >= 4 and not grep({ref $_;} @$t[0..3]) and join($", @$t[0..3]) =~ /\Amaxseg size set (?:rt mtu|\d+)/
!ll&&!rl&&r
7400
$w eq "tcp" and $k eq "option" and @$t >= 4 and not grep({ref $_;} @$t[0..3])
!ll&&!rl&&r
7400
$w eq "tcp" and $k eq "option" and @$t >= 4
!ll&&!rl&&r
7400
$w eq "tcp" and $k eq "option"
!ll&&!rl&&r
13610
MC/DC0%0/5
$w eq "tcp" and $k eq "option" and @$t >= 4 and not grep({ref $_;} @$t[0..3]) and join($", @$t[0..3]) =~ /\Amaxseg size set (?:rt mtu|\d+)/
$w eq "tcp" $k eq "option" @$t >= 4 not grep({ref $_;} @$t[0..3]) join($", @$t[0..3]) =~ /\Amaxseg size set (?:rt mtu|\d+)/
Truth table33%2/6
A and B and C and not(D) and E
A= $w eq "tcp"B= $k eq "option"C= @$t >= 4D= not grep({ref $_;} @$t[0..3])E= join($", @$t[0..3]) =~ /\Amaxseg size set (?:rt mtu|\d+)/
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
169 0 ▶ splice @$t, 0, ( $t->[3] eq 'rt' ? 5 : 4 );
Branch: 1 branch
BranchTrueFalseTotal
$$t[3] eq 'rt' ? : 0 0 0
170 0 next;
171 }
172 74 ▶ die "$w $k\n" unless $k eq 'dport' || $k eq 'sport';
Branch: 1 branch
BranchTrueFalseTotal
unless $k eq "dport" or $k eq "sport" 1 73 74
Condition66%2/3
$k eq "dport" or $k eq "sport"
l!l&&r!l&&!r
7301
MC/DC50%1/2
$k eq "dport" or $k eq "sport"
$k eq "dport" $k eq "sport"
Truth table66%2/3
A or B
A= $k eq "dport"B= $k eq "sport"
ABresult
1X1
011
000
173 73 $field = "$w $k";
174 }
175 elsif ( $w eq 'ct' ) {
176 16 ▶ my $k = shift @$t // die "ct ohne Feld\n";
Condition50%1/2
shift @$t // die("ct ohne Feld\n")
l!l
160
MC/DC0%0/1
shift @$t // die("ct ohne Feld\n")
shift @$t
Truth table50%1/2
A
A= shift @$t
Aresult
11
00
177 16 ▶ die "ct $k\n" unless $k eq 'state' || $k eq 'status';
Branch: 1 branch
BranchTrueFalseTotal
unless $k eq "state" or $k eq "status" 0 16 16
Condition33%1/3
$k eq "state" or $k eq "status"
l!l&&r!l&&!r
1600
MC/DC0%0/2
$k eq "state" or $k eq "status"
$k eq "state" $k eq "status"
Truth table33%1/3
A or B
A= $k eq "state"B= $k eq "status"
ABresult
1X1
011
000
178 16 ▶ $field = $k eq 'state' ? 'ct' : 'ct status';
Branch: 1 branch
BranchTrueFalseTotal
$k eq 'state' ? : 16 0 16
179 }
180 ▶ elsif ( $w eq 'icmp' || $w eq 'icmpv6' ) {
Condition100%3/3
$w eq "icmp" or $w eq "icmpv6"
l!l&&r!l&&!r
342
MC/DC100%2/2
$w eq "icmp" or $w eq "icmpv6"
$w eq "icmp" $w eq "icmpv6"
Truth table100%3/3
A or B
A= $w eq "icmp"B= $w eq "icmpv6"
ABresult
1X1
011
000
181 7 ▶ my $k = shift @$t // die "$w ohne Feld\n";
Condition50%1/2
shift @$t // die("$w ohne Feld\n")
l!l
70
MC/DC0%0/1
shift @$t // die("$w ohne Feld\n")
shift @$t
Truth table50%1/2
A
A= shift @$t
Aresult
11
00
182 7 ▶ die "$w $k\n" unless $k eq 'type' || $k eq 'code';
Branch: 1 branch
BranchTrueFalseTotal
unless $k eq "type" or $k eq "code" 0 7 7
Condition33%1/3
$k eq "type" or $k eq "code"
l!l&&r!l&&!r
700
MC/DC0%0/2
$k eq "type" or $k eq "code"
$k eq "type" $k eq "code"
Truth table33%1/3
A or B
A= $k eq "type"B= $k eq "code"
ABresult
1X1
011
000
183 7 $field = "$w $k";
184 }
185 2 else { die "unbekannt: $w\n" }
186 180 my $neg = 0;
187 180 ▶ if ( @$t && !ref $t->[0] && $t->[0] eq '!=' ) { shift @$t; $neg = 1 }
Branch: 2 branches
BranchTrueFalseTotal
if (@$t and not ref $$t[0] and $$t[0] eq '!=') { } 3 177 180
elsif (@$t and not ref $$t[0] and $$t[0] eq '==') { } 0 212 212
Condition83%5/6
@$t and not ref $$t[0] and $$t[0] eq "!="
!ll&&!rl&&r
351423
@$t and not ref $$t[0]
!ll&&!rl&&r
035145
MC/DC66%2/3
@$t and not ref $$t[0] and $$t[0] eq "!="
@$t not ref $$t[0] $$t[0] eq "!="
Truth table75%3/4
A and not(B) and C
A= @$tB= not ref $$t[0]C= $$t[0] eq "!="
ABCresult
0XX0
10X0
1100
1111
188 0 ▶ elsif ( @$t && !ref $t->[0] && $t->[0] eq '==' ) { shift @$t }
Condition66%4/6
@$t and not ref $$t[0] and $$t[0] eq "=="
!ll&&!rl&&r
351420
@$t and not ref $$t[0]
!ll&&!rl&&r
035142
MC/DC0%0/3
@$t and not ref $$t[0] and $$t[0] eq "=="
@$t not ref $$t[0] $$t[0] eq "=="
Truth table50%2/4
A and not(B) and C
A= @$tB= not ref $$t[0]C= $$t[0] eq "=="
ABCresult
0XX0
10X0
1100
1111
189 180 ▶ if ( @$t && !ref $t->[0] && $t->[0] eq 'vmap' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$t and not ref $$t[0] and $$t[0] eq "vmap") 9 171 180
Condition83%5/6
@$t and not ref $$t[0] and $$t[0] eq "vmap"
!ll&&!rl&&r
351369
@$t and not ref $$t[0]
!ll&&!rl&&r
035145
MC/DC66%2/3
@$t and not ref $$t[0] and $$t[0] eq "vmap"
@$t not ref $$t[0] $$t[0] eq "vmap"
Truth table75%3/4
A and not(B) and C
A= @$tB= not ref $$t[0]C= $$t[0] eq "vmap"
ABCresult
0XX0
10X0
1100
1111
190 9 shift @$t;
191 9 my $v = _value( $t, 1 );
192 9 ▶ die "vmap braucht { }\n" unless $v->{set};
Branch: 1 branch
BranchTrueFalseTotal
unless $$v{"set"} 0 9 9
193 9 push @m, { field => $field, vmap => $v->{set} };
194 0 ▶ while ( @$t && !ref $t->[0] && $t->[0] eq 'comment' ) { shift @$t; shift @$t }
Branch: 1 branch
BranchTrueFalseTotal
if (@$t and not ref $$t[0] and $$t[0] eq "comment") 0 9 9
Condition33%2/6
@$t and not ref $$t[0] and $$t[0] eq "comment"
!ll&&!rl&&r
900
@$t and not ref $$t[0]
!ll&&!rl&&r
900
MC/DC0%0/3
@$t and not ref $$t[0] and $$t[0] eq "comment"
@$t not ref $$t[0] $$t[0] eq "comment"
Truth table25%1/4
A and not(B) and C
A= @$tB= not ref $$t[0]C= $$t[0] eq "comment"
ABCresult
0XX0
10X0
1100
1111
195 0 ▶ die "nach vmap: " . join( ' ', map { ref $_ ? qq{"$_->{q}"} : $_ } @$t ) . "\n" if @$t;
Branch: 2 branches
BranchTrueFalseTotal
if @$t 0 9 9
ref $_ ? : 0 0 0
196 9 last;
197 }
198 171 my $v = _value($t);
199 # ct state established,related ohne Klammern
200 0 ▶ if ( $field =~ /\Act/ && $v->{one} && $v->{one} =~ /,/ ) { $v = { set => [ split /,/, $v->{one} ] } }
Branch: 1 branch
BranchTrueFalseTotal
if ($field =~ /\Act/ and $$v{"one"} and $$v{"one"} =~ /,/) 0 171 171
Condition66%4/6
$field =~ /\Act/ and $$v{"one"} and $$v{"one"} =~ /,/
!ll&&!rl&&r
159120
$field =~ /\Act/ and $$v{"one"}
!ll&&!rl&&r
159012
MC/DC0%0/3
$field =~ /\Act/ and $$v{"one"} and $$v{"one"} =~ /,/
$field =~ /\Act/ $$v{"one"} $$v{"one"} =~ /,/
Truth table50%2/4
A and B and C
A= $field =~ /\Act/B= $$v{"one"}C= $$v{"one"} =~ /,/
ABCresult
0XX0
10X0
1100
1111
201 0 ▶ while ( $field =~ /\Act/ && @$t && !ref $t->[0] && $t->[0] eq ',' ) { shift @$t; my $n = shift @$t; $v = { set => [ ( $v->{set} ? @{ $v->{set} } : $v->{one} ), $n ] } }
Branch: 2 branches
BranchTrueFalseTotal
if ($field =~ /\Act/ and @$t and not ref $$t[0] and $$t[0] eq ",") 11 171 182
$$v{'set'} ? : 0 11 11
Condition77%7/9
$field =~ /\Act/ and @$t and not ref $$t[0] and $$t[0] eq ","
!ll&&!rl&&r
1591211
$field =~ /\Act/ and @$t and not ref $$t[0]
!ll&&!rl&&r
159023
$field =~ /\Act/ and @$t
!ll&&!rl&&r
159023
MC/DC50%2/4
$field =~ /\Act/ and @$t and not ref $$t[0] and $$t[0] eq ","
$field =~ /\Act/ @$t not ref $$t[0] $$t[0] eq ","
Truth table60%3/5
A and B and not(C) and D
A= $field =~ /\Act/B= @$tC= not ref $$t[0]D= $$t[0] eq ","
ABCDresult
0XXX0
10XX0
110X0
11100
11111
202 171 _check_val( $field, $v );
203 170 push @m, { field => $field, neg => $neg, val => $v };
204 }
205 132 1;
206 };
207 141 ▶ return ( undef, "nicht auswertbar: $text" . ( $@ ? " ($@)" =~ s/\n//r : '' ) ) unless $res;
Branch: 2 branches
BranchTrueFalseTotal
unless $res 9 132 141
$@ ? : 9 0 9
208 132 return ( { matches => \@m, verdict => $verdict } );
209 }
210  
211 171 ▶sub _check_val {
Subroutine _check_val: called CC=23 SCAR=37.8
212 171 my ( $field, $v ) = @_;
213 171 ▶ my @vals = $v->{set} ? @{ $v->{set} } : defined $v->{one} ? ( $v->{one} ) : ();
Branch: 2 branches
BranchTrueFalseTotal
$$v{'set'} ? : 16 155 171
defined $$v{'one'} ? : 136 19 155
214 171 for my $x (@vals) {
215 170 ▶ if ( $field =~ /addr\z/ ) { die "Adresse $x\n" unless _range($x) }
Branch: 9 branches
BranchTrueFalseTotal
if ($field =~ /addr\z/) { } 21 149 170
elsif ($field =~ /port\z/) { } 74 75 149
elsif ($field eq 'ct') { } 23 52 75
elsif ($field eq 'ct status') { } 0 52 52
elsif ($field eq 'nfproto') { } 1 51 52
elsif ($field =~ /proto/) { } 2 49 51
elsif ($field =~ /type\z/) { } 12 37 49
elsif ($field =~ /code\z/) { } 0 37 37
unless _range($x) 0 21 21
216 74 ▶ elsif ( $field =~ /port\z/ ) { die "Port $x\n" unless _port_range($x) }
Branch: 1 branch
BranchTrueFalseTotal
unless _port_range($x) 1 73 74
217 23 ▶ elsif ( $field eq 'ct' ) { die "ct state $x\n" unless $CTSTATE{$x} }
Branch: 1 branch
BranchTrueFalseTotal
unless $CTSTATE{$x} 0 23 23
218 0 ▶ elsif ( $field eq 'ct status' ) { die "ct status $x\n" unless $CTSTATUS{$x} }
Branch: 1 branch
BranchTrueFalseTotal
unless $CTSTATUS{$x} 0 0 0
219 1 ▶ elsif ( $field eq 'nfproto' ) { die "nfproto $x\n" unless $x =~ /\Aipv[46]\z/ }
Branch: 1 branch
BranchTrueFalseTotal
unless $x =~ /\Aipv[46]\z/ 0 1 1
220 2 ▶ elsif ( $field =~ /proto/ ) { die "Protokoll $x\n" unless exists $PROTO{$x} || $x =~ /\A\d+\z/ }
Branch: 1 branch
BranchTrueFalseTotal
unless exists $PROTO{$x} or $x =~ /\A\d+\z/ 0 2 2
Condition33%1/3
exists $PROTO{$x} or $x =~ /\A\d+\z/
l!l&&r!l&&!r
200
MC/DC0%0/2
exists $PROTO{$x} or $x =~ /\A\d+\z/
exists $PROTO{$x} $x =~ /\A\d+\z/
Truth table33%1/3
A or B
A= exists $PROTO{$x}B= $x =~ /\A\d+\z/
ABresult
1X1
011
000
221 12 ▶ elsif ( $field =~ /type\z/ ) { die "$field $x\n" unless $ICMP{$x} || $x =~ /\A\d+\z/ }
Branch: 1 branch
BranchTrueFalseTotal
unless $ICMP{$x} or $x =~ /\A\d+\z/ 0 12 12
Condition33%1/3
$ICMP{$x} or $x =~ /\A\d+\z/
l!l&&r!l&&!r
1200
MC/DC0%0/2
$ICMP{$x} or $x =~ /\A\d+\z/
$ICMP{$x} $x =~ /\A\d+\z/
Truth table33%1/3
A or B
A= $ICMP{$x}B= $x =~ /\A\d+\z/
ABresult
1X1
011
000
222 0 ▶ elsif ( $field =~ /code\z/ ) { die "$field $x\n" unless $ICMPCODE{$x} || $x =~ /\A\d+\z/ }
Branch: 1 branch
BranchTrueFalseTotal
unless $ICMPCODE{$x} or $x =~ /\A\d+\z/ 0 0 0
Condition0%0/3
$ICMPCODE{$x} or $x =~ /\A\d+\z/
l!l&&r!l&&!r
000
MC/DC0%0/2
$ICMPCODE{$x} or $x =~ /\A\d+\z/
$ICMPCODE{$x} $x =~ /\A\d+\z/
Truth table0%0/3
A or B
A= $ICMPCODE{$x}B= $x =~ /\A\d+\z/
ABresult
1X1
011
000
223 }
224 170 return;
225 }
226  
227  
228 39 ▶sub parse_error { my ( undef, $e ) = parse( $_[0] ); return $e }
Subroutine parse_error: called CC=1 SCAR=0.0
Pod documented
229  
230  
231 82 my %KEYWORD = map { $_ => 1 } qw( meta fib rt ether vlan arp ip ip6 tcp udp udplite sctp dccp ah esp comp icmp icmpv6
232 igmp th ct mark iif oif iifname oifname iiftype oiftype skuid skgid pkttype cpu nftrace priority socket osf ipsec
233 exthdr hbh frag dst mh srh numgen jhash symhash quota limit counter log reject drop accept queue continue return
234 jump goto masquerade snat dnat redirect notrack dup fwd synproxy tproxy flow add update delete set map vmap comment
235 xt l4proto nfproto length protocol );
236  
237 31 ▶sub syntax_error {
Subroutine syntax_error: called CC=10 SCAR=26.2
Pod documented
238 31 my ($text) = @_;
239 31 my ( undef, $e ) = parse($text);
240 31 ▶ return undef unless defined $e;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $e 28 3 31
241 0 ▶ if ( $e =~ /\((icmpv6|icmp) (?:type|code) (\S+)\)/ ) { return "Error: Could not parse " . ( $1 eq 'icmpv6' ? 'ICMPv6' : 'ICMP' ) . " type\n$text" }
Branch: 2 branches
BranchTrueFalseTotal
if ($e =~ /\((icmpv6|icmp) (?:type|code) (\S+)\)/) 0 3 3
$1 eq 'icmpv6' ? : 0 0 0
242 3 ▶ return "Error: Could not resolve service: Servname not supported for ai_socktype\n$text" if $e =~ /\(Port \S+\)/;
Branch: 1 branch
BranchTrueFalseTotal
if $e =~ /\(Port \S+\)/ 1 2 3
243 2 ▶ return "Error: Could not resolve hostname: Name or service not known\n$text" if $e =~ /\(Adresse \S+\)/;
Branch: 1 branch
BranchTrueFalseTotal
if $e =~ /\(Adresse \S+\)/ 0 2 2
244 2 ▶ return "Error: Could not parse conntrack state\n$text" if $e =~ /\(ct state \S+\)/;
Branch: 1 branch
BranchTrueFalseTotal
if $e =~ /\(ct state \S+\)/ 0 2 2
245 2 ▶ return undef unless $e =~ /\(unbekannt: (\S+)\)/;
Branch: 1 branch
BranchTrueFalseTotal
unless $e =~ /\(unbekannt: (\S+)\)/ 1 1 2
246 1 my $w = $1;
247 1 ▶ return undef if $KEYWORD{$w};
Branch: 1 branch
BranchTrueFalseTotal
if $KEYWORD{$w} 1 0 1
248 0 ▶ return "Error: syntax error, unexpected " . ( $w =~ /\A\d+\z/ ? 'number' : 'string' ) . "\n$text";
Branch: 1 branch
BranchTrueFalseTotal
$w =~ /\A\d+\z/ ? : 0 0 0
249 }
250  
251 # --- Werte ------------------------------------------------------------------------
252  
253 91 ▶sub _addr_bin {
Subroutine _addr_bin: called CC=5 SCAR=16.2
254 91 my ($a) = @_;
255 91 ▶ return ( 4, inet_pton( AF_INET, $a ) ) if $a =~ /\A\d+\.\d+\.\d+\.\d+\z/ && inet_pton( AF_INET, $a );
Branch: 1 branch
BranchTrueFalseTotal
if $a =~ /\A\d+\.\d+\.\d+\.\d+\z/ and inet_pton(2, $a) 84 7 91
Condition66%2/3
$a =~ /\A\d+\.\d+\.\d+\.\d+\z/ and inet_pton(2, $a)
!ll&&!rl&&r
7084
MC/DC50%1/2
$a =~ /\A\d+\.\d+\.\d+\.\d+\z/ and inet_pton(2, $a)
$a =~ /\A\d+\.\d+\.\d+\.\d+\z/ inet_pton(2, $a)
Truth table66%2/3
A and B
A= $a =~ /\A\d+\.\d+\.\d+\.\d+\z/B= inet_pton(2, $a)
ABresult
0X0
100
111
256 7 ▶ return ( 6, inet_pton( AF_INET6, $a ) ) if $a =~ /:/ && inet_pton( AF_INET6, $a );
Branch: 1 branch
BranchTrueFalseTotal
if $a =~ /:/ and inet_pton(10, $a) 4 3 7
Condition66%2/3
$a =~ /:/ and inet_pton(10, $a)
!ll&&!rl&&r
304
MC/DC50%1/2
$a =~ /:/ and inet_pton(10, $a)
$a =~ /:/ inet_pton(10, $a)
Truth table66%2/3
A and B
A= $a =~ /:/B= inet_pton(10, $a)
ABresult
0X0
100
111
257 3 return;
258 }
259  
260 # Adresse, Praefix oder Bereich -> [ familie, von, bis ] (Bitfolgen)
261 55 ▶sub _range {
Subroutine _range: called CC=10 SCAR=23.6
262 55 my ($x) = @_;
263 55 ▶ if ( $x =~ m{\A([^/\-]+)/(\d+)\z} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x =~ m[\A([^/\-]+)/(\d+)\z]) 40 15 55
264 40 ▶ my ( $f, $b ) = _addr_bin($1) or return;
Branch: 1 branch
BranchTrueFalseTotal
() = _addr_bin($1) or return 40 0 40
265 40 ▶ my $len = $f == 4 ? 32 : 128;
Branch: 1 branch
BranchTrueFalseTotal
$f == 4 ? : 37 3 40
266 40 ▶ return if $2 > $len;
Branch: 1 branch
BranchTrueFalseTotal
if $2 > $len 0 40 40
267 40 my $bits = unpack( 'B*', $b );
268 40 my $p = substr( $bits, 0, $2 );
269 40 return [ $f, $p . ( '0' x ( $len - $2 ) ), $p . ( '1' x ( $len - $2 ) ) ];
270 }
271 15 ▶ if ( $x =~ /\A([^\-]+)-([^\-]+)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x =~ /\A([^\-]+)-([^\-]+)\z/) 2 13 15
272 2 ▶ my ( $f1, $b1 ) = _addr_bin($1) or return;
Branch: 1 branch
BranchTrueFalseTotal
() = _addr_bin($1) or return 2 0 2
273 2 ▶ my ( $f2, $b2 ) = _addr_bin($2) or return;
Branch: 1 branch
BranchTrueFalseTotal
() = _addr_bin($2) or return 2 0 2
274 2 ▶ return unless $f1 == $f2;
Branch: 1 branch
BranchTrueFalseTotal
unless $f1 == $f2 0 2 2
275 2 return [ $f1, unpack( 'B*', $b1 ), unpack( 'B*', $b2 ) ];
276 }
277 13 ▶ my ( $f, $b ) = _addr_bin($x) or return;
Branch: 1 branch
BranchTrueFalseTotal
() = _addr_bin($x) or return 13 0 13
278 13 my $bits = unpack( 'B*', $b );
279 13 return [ $f, $bits, $bits ];
280 }
281  
282 110 ▶sub _port { my ($p) = @_; return $p =~ /\A\d+\z/ && $p <= 65535 ? 0 + $p : $SERVICE{$p} }
Subroutine _port: called CC=3 SCAR=11.1
Branch: 1 branch
BranchTrueFalseTotal
$p =~ /\A\d+\z/ && $p <= 65535 ? : 107 3 110
Condition66%2/3
$p =~ /\A\d+\z/ and $p <= 65535
!ll&&!rl&&r
30107
MC/DC50%1/2
$p =~ /\A\d+\z/ and $p <= 65535
$p =~ /\A\d+\z/ $p <= 65535
Truth table66%2/3
A and B
A= $p =~ /\A\d+\z/B= $p <= 65535
ABresult
0X0
100
111
283  
284 108 ▶sub _port_range {
Subroutine _port_range: called CC=5 SCAR=16.5
285 108 my ($x) = @_;
286 108 ▶ if ( $x =~ /\A([^\-]+)-([^\-]+)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x =~ /\A([^\-]+)-([^\-]+)\z/) 2 106 108
287 2 my ( $a, $b ) = ( _port($1), _port($2) );
288 2 ▶ return defined $a && defined $b ? [ $a, $b ] : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $a && defined $b ? : 2 0 2
Condition33%1/3
defined $a and defined $b
!ll&&!rl&&r
002
MC/DC0%0/2
defined $a and defined $b
defined $a defined $b
Truth table33%1/3
A and B
A= defined $aB= defined $b
ABresult
0X0
100
111
289 }
290 106 my $p = _port($x);
291 106 ▶ return defined $p ? [ $p, $p ] : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $p ? : 105 1 106
292 }
293  
294 148 ▶sub _family { my ($a) = @_; return defined $a && $a =~ /:/ ? 6 : 4 }
Subroutine _family: called CC=3 SCAR=11.1
Branch: 1 branch
BranchTrueFalseTotal
defined $a && $a =~ /:/ ? : 6 142 148
Condition66%2/3
defined $a and $a =~ /:/
!ll&&!rl&&r
01426
MC/DC50%1/2
defined $a and $a =~ /:/
defined $a $a =~ /:/
Truth table66%2/3
A and B
A= defined $aB= $a =~ /:/
ABresult
0X0
100
111
295  
296 87 ▶sub _l4 {
Subroutine _l4: called CC=5 SCAR=18.1
297 87 my ($pkt) = @_;
298 87 ▶ my $p = $pkt->{proto} // '';
Condition50%1/2
$$pkt{"proto"} // ""
l!l
870
MC/DC0%0/1
$$pkt{"proto"} // ""
$$pkt{"proto"}
Truth table50%1/2
A
A= $$pkt{"proto"}
Aresult
11
00
299 87 ▶ $p = 'icmpv6' if $p eq 'icmp' && _family( $pkt->{saddr} // $pkt->{daddr} ) == 6;
Branch: 1 branch
BranchTrueFalseTotal
if $p eq "icmp" and _family($$pkt{"saddr"} // $$pkt{"daddr"}) == 6 0 87 87
Condition50%3/6
$p eq "icmp" and _family($$pkt{"saddr"} // $$pkt{"daddr"}) == 6
!ll&&!rl&&r
8610
$$pkt{"saddr"} // $$pkt{"daddr"}
l!l&&r!l&&!r
100
MC/DC0%0/2
$p eq "icmp" and _family($$pkt{"saddr"} // $$pkt{"daddr"}) == 6
$p eq "icmp" _family($$pkt{"saddr"} // $$pkt{"daddr"}) == 6
MC/DC0%0/2
$$pkt{"saddr"} // $$pkt{"daddr"}
$$pkt{"saddr"} $$pkt{"daddr"}
Truth table66%2/3
A and B
A= $p eq "icmp"B= _family($$pkt{"saddr"} // $$pkt{"daddr"}) == 6
ABresult
0X0
100
111
Truth table33%1/3
A // B
A= $$pkt{"saddr"}B= $$pkt{"daddr"}
ABresult
1X1
011
000
300 87 return $p;
301 }
302  
303 4 ▶sub _proto_num { my ($p) = @_; return $p =~ /\A\d+\z/ ? 0 + $p : $PROTO{$p} }
Subroutine _proto_num: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
$p =~ /\A\d+\z/ ? : 0 4 4
304  
305 # Passt ein einzelner Wert des Pakets auf einen Ausdruckswert?
306 108 ▶sub _one {
Subroutine _one: called CC=21 SCAR=31.7
307 108 my ( $field, $have, $want ) = @_;
308 108 ▶ return 0 unless defined $have;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $have 0 108 108
309 108 ▶ if ( $field =~ /addr\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field =~ /addr\z/) 23 85 108
310 23 ▶ my $r = _range($want) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $r = _range($want) or return 0 23 0 23
311 23 ▶ my ( $f, $b ) = _addr_bin($have) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
() = _addr_bin($have) or return 0 23 0 23
312 23 ▶ return 0 unless $f == $r->[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $f == $$r[0] 0 23 23
313 23 my $bits = unpack( 'B*', $b );
314 23 ▶ return $bits ge $r->[1] && $bits le $r->[2] ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$bits ge $$r[1] && $bits le $$r[2] ? : 12 11 23
Condition100%3/3
$bits ge $$r[1] and $bits le $$r[2]
!ll&&!rl&&r
5612
MC/DC100%2/2
$bits ge $$r[1] and $bits le $$r[2]
$bits ge $$r[1] $bits le $$r[2]
Truth table100%3/3
A and B
A= $bits ge $$r[1]B= $bits le $$r[2]
ABresult
0X0
100
111
315 }
316 85 ▶ if ( $field =~ /port\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field =~ /port\z/) 34 51 85
317 34 ▶ my $r = _port_range($want) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $r = _port_range($want) or return 0 34 0 34
318 34 ▶ return $have >= $r->[0] && $have <= $r->[1] ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$have >= $$r[0] && $have <= $$r[1] ? : 31 3 34
Condition100%3/3
$have >= $$r[0] and $have <= $$r[1]
!ll&&!rl&&r
1231
MC/DC100%2/2
$have >= $$r[0] and $have <= $$r[1]
$have >= $$r[0] $have <= $$r[1]
Truth table100%3/3
A and B
A= $have >= $$r[0]B= $have <= $$r[1]
ABresult
0X0
100
111
319 }
320 51 ▶ if ( $field eq 'iif' || $field eq 'oif' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field eq "iif" or $field eq "oif") 20 31 51
Condition66%2/3
$field eq "iif" or $field eq "oif"
l!l&&r!l&&!r
20031
MC/DC50%1/2
$field eq "iif" or $field eq "oif"
$field eq "iif" $field eq "oif"
Truth table66%2/3
A or B
A= $field eq "iif"B= $field eq "oif"
ABresult
1X1
011
000
321 20 my $re = quotemeta $want;
322 20 $re =~ s/\\\*/.*/g;
323 20 ▶ return $have =~ /\A$re\z/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$have =~ /\A$re\z/ ? : 13 7 20
324 }
325 31 ▶ if ( $field =~ /proto/ && $field ne 'nfproto' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field =~ /proto/ and $field ne "nfproto") 2 29 31
Condition66%2/3
$field =~ /proto/ and $field ne "nfproto"
!ll&&!rl&&r
2902
MC/DC50%1/2
$field =~ /proto/ and $field ne "nfproto"
$field =~ /proto/ $field ne "nfproto"
Truth table66%2/3
A and B
A= $field =~ /proto/B= $field ne "nfproto"
ABresult
0X0
100
111
326 2 my ( $a, $b ) = ( _proto_num($have), _proto_num($want) );
327 2 ▶ return defined $a && defined $b && $a == $b ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $a && defined $b && $a == $b ? : 2 0 2
Condition33%2/6
defined $a and defined $b and $a == $b
!ll&&!rl&&r
002
defined $a and defined $b
!ll&&!rl&&r
002
MC/DC0%0/3
defined $a and defined $b and $a == $b
defined $a defined $b $a == $b
Truth table25%1/4
A and B and C
A= defined $aB= defined $bC= $a == $b
ABCresult
0XX0
10X0
1100
1111
328 }
329 29 ▶ return $have eq $want ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$have eq $want ? : 5 24 29
330 }
331  
332 # Wert des Pakets fuer ein Feld; undef = das Feld gibt es an diesem Paket nicht
333 # (dann passt der Ausdruck nicht — auch nicht mit !=, wie in nft).
334 87 ▶sub _have {
Subroutine _have: called CC=37 SCAR=44.6
335 87 my ( $field, $pkt ) = @_;
336 87 my $l4 = _l4($pkt);
337 87 ▶ my $fam = _family( $pkt->{saddr} // $pkt->{daddr} );
Condition33%1/3
$$pkt{"saddr"} // $$pkt{"daddr"}
l!l&&r!l&&!r
8700
MC/DC0%0/2
$$pkt{"saddr"} // $$pkt{"daddr"}
$$pkt{"saddr"} $$pkt{"daddr"}
Truth table33%1/3
A // B
A= $$pkt{"saddr"}B= $$pkt{"daddr"}
ABresult
1X1
011
000
338 87 ▶ return $pkt->{iif} if $field eq 'iif';
Branch: 1 branch
BranchTrueFalseTotal
if $field eq "iif" 18 69 87
339 69 ▶ return $pkt->{oif} if $field eq 'oif';
Branch: 1 branch
BranchTrueFalseTotal
if $field eq "oif" 0 69 69
340 69 ▶ return $fam == 4 ? $pkt->{saddr} : undef if $field eq 'ip saddr';
Branch: 2 branches
BranchTrueFalseTotal
if $field eq "ip saddr" 17 52 69
$fam == 4 ? : 17 0 17
341 52 ▶ return $fam == 4 ? $pkt->{daddr} : undef if $field eq 'ip daddr';
Branch: 2 branches
BranchTrueFalseTotal
if $field eq "ip daddr" 1 51 52
$fam == 4 ? : 1 0 1
342 51 ▶ return $fam == 6 ? $pkt->{saddr} : undef if $field eq 'ip6 saddr';
Branch: 2 branches
BranchTrueFalseTotal
if $field eq "ip6 saddr" 2 49 51
$fam == 6 ? : 1 1 2
343 49 ▶ return $fam == 6 ? $pkt->{daddr} : undef if $field eq 'ip6 daddr';
Branch: 2 branches
BranchTrueFalseTotal
if $field eq "ip6 daddr" 0 49 49
$fam == 6 ? : 0 0 0
344 49 ▶ return $fam == 4 ? $l4 : undef if $field eq 'ipproto4';
Branch: 2 branches
BranchTrueFalseTotal
if $field eq "ipproto4" 1 48 49
$fam == 4 ? : 1 0 1
345 48 ▶ return $fam == 6 ? $l4 : undef if $field eq 'ipproto6';
Branch: 2 branches
BranchTrueFalseTotal
if $field eq "ipproto6" 0 48 48
$fam == 6 ? : 0 0 0
346 48 ▶ return $l4 if $field eq 'l4proto';
Branch: 1 branch
BranchTrueFalseTotal
if $field eq "l4proto" 1 47 48
347 47 ▶ return "ipv$fam" if $field eq 'nfproto';
Branch: 1 branch
BranchTrueFalseTotal
if $field eq "nfproto" 0 47 47
348 47 ▶ if ( $field =~ /\A(tcp|udp|th) (dport|sport)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field =~ /\A(tcp|udp|th) (dport|sport)\z/) 34 13 47
349 34 my ( $p, $k ) = ( $1, $2 );
350 34 ▶ return undef if $p ne 'th' && $p ne $l4;
Branch: 1 branch
BranchTrueFalseTotal
if $p ne "th" and $p ne $l4 1 33 34
Condition100%3/3
$p ne "th" and $p ne $l4
!ll&&!rl&&r
1321
MC/DC100%2/2
$p ne "th" and $p ne $l4
$p ne "th" $p ne $l4
Truth table100%3/3
A and B
A= $p ne "th"B= $p ne $l4
ABresult
0X0
100
111
351 33 ▶ return undef if $p eq 'th' && $l4 ne 'tcp' && $l4 ne 'udp';
Branch: 1 branch
BranchTrueFalseTotal
if $p eq "th" and $l4 ne "tcp" and $l4 ne "udp" 0 33 33
Condition50%3/6
$p eq "th" and $l4 ne "tcp" and $l4 ne "udp"
!ll&&!rl&&r
3300
$p eq "th" and $l4 ne "tcp"
!ll&&!rl&&r
3210
MC/DC0%0/3
$p eq "th" and $l4 ne "tcp" and $l4 ne "udp"
$p eq "th" $l4 ne "tcp" $l4 ne "udp"
Truth table50%2/4
A and B and C
A= $p eq "th"B= $l4 ne "tcp"C= $l4 ne "udp"
ABCresult
0XX0
10X0
1100
1111
352 33 return $pkt->{$k};
353 }
354 13 ▶ return $pkt->{ct} // 'new' if $field eq 'ct';
Branch: 1 branch
BranchTrueFalseTotal
if $field eq "ct" 11 2 13
Condition100%2/2
$$pkt{"ct"} // "new"
l!l
56
MC/DC100%1/1
$$pkt{"ct"} // "new"
$$pkt{"ct"}
Truth table100%2/2
A
A= $$pkt{"ct"}
Aresult
11
00
355 2 ▶ return [ split /\s*,\s*/, $pkt->{ct_status} // '' ] if $field eq 'ct status';
Branch: 1 branch
BranchTrueFalseTotal
if $field eq "ct status" 0 2 2
Condition0%0/2
$$pkt{"ct_status"} // ""
l!l
00
MC/DC0%0/1
$$pkt{"ct_status"} // ""
$$pkt{"ct_status"}
Truth table0%0/2
A
A= $$pkt{"ct_status"}
Aresult
11
00
356 2 ▶ return $l4 eq 'icmp' ? ( $pkt->{icmp_type} // 'echo-request' ) : undef if $field eq 'icmp type';
Branch: 2 branches
BranchTrueFalseTotal
if $field eq "icmp type" 1 1 2
$l4 eq 'icmp' ? : 1 0 1
Condition50%1/2
$$pkt{"icmp_type"} // "echo-request"
l!l
01
MC/DC0%0/1
$$pkt{"icmp_type"} // "echo-request"
$$pkt{"icmp_type"}
Truth table50%1/2
A
A= $$pkt{"icmp_type"}
Aresult
11
00
357 1 ▶ return $l4 eq 'icmpv6' ? ( $pkt->{icmp_type} // 'echo-request' ) : undef if $field eq 'icmpv6 type';
Branch: 2 branches
BranchTrueFalseTotal
if $field eq "icmpv6 type" 1 0 1
$l4 eq 'icmpv6' ? : 1 0 1
Condition50%1/2
$$pkt{"icmp_type"} // "echo-request"
l!l
10
MC/DC0%0/1
$$pkt{"icmp_type"} // "echo-request"
$$pkt{"icmp_type"}
Truth table50%1/2
A
A= $$pkt{"icmp_type"}
Aresult
11
00
358 0 ▶ return $l4 eq ( $field =~ /\Aicmpv6/ ? 'icmpv6' : 'icmp' ) ? $pkt->{icmp_code} : undef if $field =~ /code\z/;
Branch: 3 branches
BranchTrueFalseTotal
if $field =~ /code\z/ 0 0 0
$l4 eq ($field =~ /\Aicmpv6/ ? 'icmpv6' : 'icmp') ? : 0 0 0
$field =~ /\Aicmpv6/ ? : 0 0 0
359 0 return undef;
360 }
361  
362 78 ▶sub _elements {
Subroutine _elements: called CC=6 SCAR=17.9
363 78 my ( $table, $v, $why ) = @_;
364 78 ▶ return @{ $v->{set} } if $v->{set};
Branch: 1 branch
BranchTrueFalseTotal
if $$v{"set"} 10 68 78
365 68 ▶ return ( $v->{one} ) if defined $v->{one};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$v{"one"} 59 9 68
366 9 ▶ my $s = ( $table->{sets} || {} )->{ $v->{named} };
Condition100%2/2
$$table{'sets'} || {}
l!l
81
MC/DC100%1/1
$$table{'sets'} || {}
$$table{'sets'}
Truth table100%2/2
A
A= $$table{'sets'}
Aresult
11
00
367 9 ▶ die "Set \@$v->{named} gibt es nicht\n" unless ref $s eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $s eq "HASH" 1 8 9
368 8 ▶ return @{ $s->{elements} || [] };
Condition50%1/2
$$s{'elements'} || []
l!l
80
MC/DC0%0/1
$$s{'elements'} || []
$$s{'elements'}
Truth table50%1/2
A
A= $$s{'elements'}
Aresult
11
00
369 }
370  
371 81 ▶sub _match {
Subroutine _match: called CC=6 SCAR=17.9
372 81 my ( $m, $pkt, $table ) = @_;
373 81 ▶ return 0 if $m->{field} eq 'never';
Branch: 1 branch
BranchTrueFalseTotal
if $$m{"field"} eq "never" 1 80 81
374 80 my $have = _have( $m->{field}, $pkt );
375 80 ▶ return 0 unless defined $have;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $have 2 78 80
376 78 ▶ my @have = ref $have eq 'ARRAY' ? @$have : ($have);
Branch: 1 branch
BranchTrueFalseTotal
ref $have eq 'ARRAY' ? : 0 78 78
377 78 my @want = _elements( $table, $m->{val} );
378 77 my $hit = grep { my $h = $_; grep { _one( $m->{field}, $h, $_ ) } @want } @have;
379 77 ▶ return $m->{neg} ? !$hit : $hit ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
$$m{'neg'} ? : 3 74 77
$hit ? : 56 18 74
380 }
381  
382 # --- Auswerten --------------------------------------------------------------------
383  
384 59 ▶sub _prio {
Subroutine _prio: called CC=7 SCAR=20.1
385 59 my ($p) = @_;
386 59 ▶ $p //= 0;
Condition50%1/2
$p //= 0
l!l
590
MC/DC0%0/1
$p //= 0
$p
Truth table50%1/2
A
A= $p
Aresult
11
00
387 59 ▶ return 0 + $p if $p =~ /\A-?\d+\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $p =~ /\A-?\d+\z/ 56 3 59
388 3 ▶ if ( $p =~ /\A(\w+)\s*([+-])\s*(\d+)\z/ && exists $PRIO{$1} ) { return $PRIO{$1} + ( $2 eq '+' ? $3 : -$3 ) }
Branch: 2 branches
BranchTrueFalseTotal
if ($p =~ /\A(\w+)\s*([+-])\s*(\d+)\z/ and exists $PRIO{$1}) 1 2 3
$2 eq '+' ? : 0 1 1
Condition66%2/3
$p =~ /\A(\w+)\s*([+-])\s*(\d+)\z/ and exists $PRIO{$1}
!ll&&!rl&&r
201
MC/DC50%1/2
$p =~ /\A(\w+)\s*([+-])\s*(\d+)\z/ and exists $PRIO{$1}
$p =~ /\A(\w+)\s*([+-])\s*(\d+)\z/ exists $PRIO{$1}
Truth table66%2/3
A and B
A= $p =~ /\A(\w+)\s*([+-])\s*(\d+)\z/B= exists $PRIO{$1}
ABresult
0X0
100
111
389 2 ▶ return $PRIO{$p} // 0;
Condition50%1/2
$PRIO{$p} // 0
l!l
20
MC/DC0%0/1
$PRIO{$p} // 0
$PRIO{$p}
Truth table50%1/2
A
A= $PRIO{$p}
Aresult
11
00
390 }
391  
392 # Eine Kette durchlaufen -> ( 'accept'|'drop'|'return'|undef (Ende), Spur )
393 61 ▶sub _chain {
Subroutine _chain: called CC=21 SCAR=30.7
394 61 my ( $tname, $table, $cname, $pkt, $depth ) = @_;
395 61 ▶ die "Ketten zu tief verschachtelt\n" if $depth > 16;
Branch: 1 branch
BranchTrueFalseTotal
if $depth > 16 0 61 61
396 61 ▶ my $ch = $table->{chains}{$cname} or die "Kette $cname gibt es nicht\n";
Branch: 1 branch
BranchTrueFalseTotal
my $ch = $$table{"chains"}{$cname} or die "Kette $cname gibt es nicht\n" 61 0 61
397 61 ▶ for my $text ( @{ $ch->{rules} || [] } ) {
Condition50%1/2
$$ch{'rules'} || []
l!l
610
MC/DC0%0/1
$$ch{'rules'} || []
$$ch{'rules'}
Truth table50%1/2
A
A= $$ch{'rules'}
Aresult
11
00
398 71 my ( $r, $err ) = parse($text);
399 71 ▶ die "$err\n" unless $r;
Branch: 1 branch
BranchTrueFalseTotal
unless $r 1 70 71
400 70 my $all = 1;
401 70 my $verdict = $r->{verdict};
402 70 for my $m ( @{ $r->{matches} } ) {
403 88 ▶ if ( $m->{vmap} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$m{"vmap"}) 7 81 88
404 7 my $have = _have( $m->{field}, $pkt );
405 7 ▶ my ($hit) = defined $have ? grep { _one( $m->{field}, $have, $_->[0] ) } @{ $m->{vmap} } : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $have ? : 7 0 7
406 7 ▶ if ($hit) { $verdict = $hit->[1] } else { $all = 0 }
Branch: 1 branch
BranchTrueFalseTotal
if ($hit) { } 5 2 7
407 7 last;
408 }
409 81 ▶ next if _match( $m, $pkt, $table );
Branch: 1 branch
BranchTrueFalseTotal
if _match($m, $pkt, $table) 57 23 80
410 23 $all = 0;
411 23 last;
412 }
413 69 ▶ next unless $all && $verdict;
Branch: 1 branch
BranchTrueFalseTotal
unless $all and $verdict 25 44 69
Condition66%2/3
$all and $verdict
!ll&&!rl&&r
25044
MC/DC50%1/2
$all and $verdict
$all $verdict
Truth table66%2/3
A and B
A= $allB= $verdict
ABresult
0X0
100
111
414 44 my $where = "$tname $cname: $text";
415 44 ▶ return ( 'accept', $where ) if $verdict->{accept};
Branch: 1 branch
BranchTrueFalseTotal
if $$verdict{"accept"} 32 12 44
416 12 ▶ return ( 'drop', $where ) if $verdict->{drop} || $verdict->{reject};
Branch: 1 branch
BranchTrueFalseTotal
if $$verdict{"drop"} or $$verdict{"reject"} 8 4 12
Condition66%2/3
$$verdict{"drop"} or $$verdict{"reject"}
l!l&&r!l&&!r
804
MC/DC50%1/2
$$verdict{"drop"} or $$verdict{"reject"}
$$verdict{"drop"} $$verdict{"reject"}
Truth table66%2/3
A or B
A= $$verdict{"drop"}B= $$verdict{"reject"}
ABresult
1X1
011
000
417 4 ▶ return ( 'return', $where ) if $verdict->{return};
Branch: 1 branch
BranchTrueFalseTotal
if $$verdict{"return"} 1 3 4
418 3 ▶ next if $verdict->{continue};
Branch: 1 branch
BranchTrueFalseTotal
if $$verdict{"continue"} 0 3 3
419 3 my ($to) = grep {defined} @{$verdict}{qw( jump goto )};
420 3 my ( $v, $w ) = _chain( $tname, $table, $to, $pkt, $depth + 1 );
421 3 ▶ return ( $v, $w ) if defined $v && $v ne 'return';
Branch: 1 branch
BranchTrueFalseTotal
if defined $v and $v ne "return" 1 2 3
Condition100%3/3
defined $v and $v ne "return"
!ll&&!rl&&r
111
MC/DC100%2/2
defined $v and $v ne "return"
defined $v $v ne "return"
Truth table100%3/3
A and B
A= defined $vB= $v ne "return"
ABresult
0X0
100
111
422 2 ▶ return ( undef, "$tname $to: Ende (goto)" ) if $verdict->{goto};
Branch: 1 branch
BranchTrueFalseTotal
if $$verdict{"goto"} 0 2 2
423 }
424 17 return ( undef, "$tname $cname: Ende" );
425 }
426  
427  
428 60 ▶sub verdict {
Subroutine verdict: called CC=24 SCAR=33.5
Pod documented
429 60 my ( $dev, $pkt ) = @_;
430 60 ▶ my $fam = _family( $pkt->{saddr} // $pkt->{daddr} );
Condition33%1/3
$$pkt{"saddr"} // $$pkt{"daddr"}
l!l&&r!l&&!r
6000
MC/DC0%0/2
$$pkt{"saddr"} // $$pkt{"daddr"}
$$pkt{"saddr"} $$pkt{"daddr"}
Truth table33%1/3
A // B
A= $$pkt{"saddr"}B= $$pkt{"daddr"}
ABresult
1X1
011
000
431 60 ▶ my $T = ref $dev->{nft} eq 'HASH' ? $dev->{nft} : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $$dev{'nft'} eq 'HASH' ? : 60 0 60
432 60 my @base;
433 60 for my $tn ( sort keys %$T ) {
434 64 my ($f) = split / /, $tn;
435 64 ▶ next unless $f eq 'inet' || ( $f eq 'ip' && $fam == 4 ) || ( $f eq 'ip6' && $fam == 6 );
Branch: 1 branch
BranchTrueFalseTotal
unless $f eq "inet" or $f eq "ip" and $fam == 4 or $f eq "ip6" and $fam == 6 1 63 64
Condition66%8/12
$f eq "inet" or $f eq "ip" and $fam == 4 or $f eq "ip6" and $fam == 6
l!l&&r!l&&!r
6301
$f eq "inet" or $f eq "ip" and $fam == 4
l!l&&r!l&&!r
6031
$f eq "ip" and $fam == 4
!ll&&!rl&&r
013
$f eq "ip6" and $fam == 6
!ll&&!rl&&r
100
MC/DC40%2/5
$f eq "inet" or $f eq "ip" and $fam == 4 or $f eq "ip6" and $fam == 6
$f eq "inet" $f eq "ip" $fam == 4 $f eq "ip6" $fam == 6
Truth table37%3/8
A or B and C or D and E
A= $f eq "inet"B= $f eq "ip"C= $fam == 4D= $f eq "ip6"E= $fam == 6
ABCDEresult
1XXXX1
011XX1
00X111
010111
00X0X0
00X100
0100X0
010100
436 63 ▶ my $chains = $T->{$tn}{chains} || {};
Condition50%1/2
$$T{$tn}{'chains'} || {}
l!l
630
MC/DC0%0/1
$$T{$tn}{'chains'} || {}
$$T{$tn}{'chains'}
Truth table50%1/2
A
A= $$T{$tn}{'chains'}
Aresult
11
00
437 63 for my $cn ( sort keys %$chains ) {
438 72 my $c = $chains->{$cn};
439 72 ▶ next unless ( $c->{hook} // '' ) eq $pkt->{hook} && ( $c->{type} // '' ) eq 'filter';
Branch: 1 branch
BranchTrueFalseTotal
unless ($$c{"hook"} // "") eq $$pkt{"hook"} and ($$c{"type"} // "") eq "filter" 13 59 72
Condition85%6/7
($$c{"hook"} // "") eq $$pkt{"hook"} and ($$c{"type"} // "") eq "filter"
!ll&&!rl&&r
12159
$$c{"hook"} // ""
l!l
675
$$c{"type"} // ""
l!l
600
MC/DC50%1/2
($$c{"hook"} // "") eq $$pkt{"hook"} and ($$c{"type"} // "") eq "filter"
$$c{"hook"} $$c{"type"}
Truth table66%2/3
A and B
A= $$c{"hook"}B= $$c{"type"}
ABresult
0X0
100
111
440 59 push @base, [ _prio( $c->{priority} ), $tn, $cn ];
441 }
442 }
443 60 my @why;
444 60 my $ok = eval {
445 60 ▶ for my $b ( sort { $a->[0] <=> $b->[0] || $a->[1] cmp $b->[1] || $a->[2] cmp $b->[2] } @base ) {
Condition33%2/6
$$a[0] <=> $$b[0] || $$a[1] cmp $$b[1] || $$a[2] cmp $$b[2]
l!l&&r!l&&!r
200
$$a[0] <=> $$b[0] or $$a[1] cmp $$b[1]
l!l&&r!l&&!r
200
MC/DC0%0/3
$$a[0] <=> $$b[0] || $$a[1] cmp $$b[1] || $$a[2] cmp $$b[2]
$$a[0] <=> $$b[0] $$a[1] cmp $$b[1] $$a[2] cmp $$b[2]
Truth table25%1/4
A or B || C
A= $$a[0] <=> $$b[0]B= $$a[1] cmp $$b[1]C= $$a[2] cmp $$b[2]
ABCresult
1XX1
01X1
0011
0000
446 58 my ( undef, $tn, $cn ) = @$b;
447 58 my ( $v, $w ) = _chain( $tn, $T->{$tn}, $cn, $pkt, 0 );
448 56 ▶ if ( !defined $v || $v eq 'return' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $v or $v eq "return") 16 40 56
Condition66%2/3
not defined $v or $v eq "return"
l!l&&r!l&&!r
16040
MC/DC50%1/2
not defined $v or $v eq "return"
not defined $v $v eq "return"
Truth table66%2/3
not(A) or B
A= not defined $vB= $v eq "return"
ABresult
1X1
011
000
449 16 ▶ my $pol = $T->{$tn}{chains}{$cn}{policy} // 'accept';
Condition50%1/2
$$T{$tn}{"chains"}{$cn}{"policy"} // "accept"
l!l
160
MC/DC0%0/1
$$T{$tn}{"chains"}{$cn}{"policy"} // "accept"
$$T{$tn}{"chains"}{$cn}{"policy"}
Truth table50%1/2
A
A= $$T{$tn}{"chains"}{$cn}{"policy"}
Aresult
11
00
450 16 $v = $pol;
451 16 $w = "$tn $cn: policy $pol";
452 }
453 56 push @why, $w;
454 56 ▶ return ( 'drop' ) if $v eq 'drop';
Branch: 1 branch
BranchTrueFalseTotal
if $v eq "drop" 23 33 56
455 }
456 35 'accept';
457 };
458 60 ▶ return ( undef, ( $@ =~ s/\n\z//r ) ) unless defined $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ok 2 58 60
459 58 ▶ return ( $ok, @why ? join( '; ', @why ) : 'keine Basiskette' );
Branch: 1 branch
BranchTrueFalseTotal
@why ? : 55 3 58
460 }
461  
462  
463 6 ▶sub boot_verdict {
Subroutine boot_verdict: called CC=4 SCAR=13.9
Pod documented
464 6 my ( $dev, $pkt, $file ) = @_;
465 6 ▶ $file //= '/etc/nftables.conf';
Condition100%2/2
$file //= "/etc/nftables.conf"
l!l
42
MC/DC100%1/1
$file //= "/etc/nftables.conf"
$file
Truth table100%2/2
A
A= $file
Aresult
11
00
466 6 require Langertha::Holmgang::Sim::Linux;
467 6 my $text = Langertha::Holmgang::Sim::Linux::_file_text( $dev, $file );
468 6 my $boot = Langertha::Holmgang::Sim::Linux::clone_state($dev);
469 6 $boot->{nft} = {};
470 6 ▶ return ( undef, "$file fehlt" ) unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 2 4 6
471 4 local @Langertha::Holmgang::Sim::Linux::GAPS;
472 4 my ( $out, $ok ) = Langertha::Holmgang::Sim::Linux::_nft_load( $boot, $text, $file );
473 4 ▶ return ( undef, "$file lädt nicht: $out" ) unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 4 4
474 4 return verdict( $boot, $pkt );
475 }
476  
477 82 1;
478  
479 __END__
« blib/lib/Langertha/Holmgang/Expectation.pm ↑ Summary blib/lib/Langertha/Holmgang/ToolSchema.pm »