3 # Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC")
5 # Permission to use, copy, modify, and/or distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
9 # THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 # AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 # PERFORMANCE OF THIS SOFTWARE.
20 my $boilerplate_header = <<'EOB';
21 # common configuration
22 include "named.conf.header";
30 # policy configuration to be tested
34 my $no_option = <<'EOB';
37 # policy zones to be tested
40 my $qname_wait_recurse = <<'EOB';
41 } qname-wait-recurse no;
43 # policy zones to be tested
46 my $boilerplate_end = <<'EOB';
50 my $policy_option = $qname_wait_recurse;
53 my $policy_zone_header = <<'EOH';
55 @ IN SOA root.ns ns SERIAL 3600 1800 86400 60
60 sub policy_client_ip
{
61 return "32.1.0.0.127.rpz-client-ip CNAME .\n";
65 my $query_nbr = shift;
66 return sprintf "q%02d.l2.l1.l0 CNAME .\n", $query_nbr;
70 return "32.255.255.255.255.rpz-ip CNAME .\n";
74 return "ns.example.org.rpz-nsdname CNAME .\n";
78 return "32.255.255.255.255.rpz-ip CNAME .\n";
81 my %static_triggers = (
82 'client-ip' => \
&policy_client_ip
,
84 'nsdname' => \
&policy_nsdname
,
85 'nsip' => \
&policy_nsip
,
90 my $n_queries = shift;
92 { # generate the query list
93 my $query_list_filename = "ns2/$case_id.queries";
96 open $query_list_fh, ">$query_list_filename" or die;
98 for( my $i = 1; $i <= $n_queries; $i++ ) {
99 print $query_list_fh sprintf "q%02d.l2.l1.l0\n", $i;
105 { # generate the conf file
106 my $conf_filename = "ns2/named.$case_id.conf";
110 open $conf_fh, ">$conf_filename" or die;
112 print $conf_fh $boilerplate_header;
118 sprintf( "$case_id.%02d.policy.local", $zone_seq++ ),
123 print $conf_fh map { qq{ zone
"$_->[0]";\n} } @zones;
125 print $conf_fh $policy_option;
127 print $conf_fh map { qq{ zone
"$_->[0]" { type master
; file
"db.$_->[0]"; };\n} } @zones;
129 print $conf_fh $boilerplate_end;
132 # generate the policy zone contents
133 foreach my $policy_zone_info( @zones ) {
134 my $policy_zone_name = $policy_zone_info->[0];
135 my $policy_zone_contents = $policy_zone_info->[1];
137 my $policy_zone_filename = "ns2/db.$policy_zone_name";
140 open $policy_zone_fh, ">$policy_zone_filename" or die;
142 my $header = $policy_zone_header;
143 $header =~ s/SERIAL/$serialnum/;
144 print $policy_zone_fh $header;
146 foreach my $trigger( @
$policy_zone_contents ) {
147 if( exists $static_triggers{$trigger} ) {
148 # matches a trigger type with a static value
149 print $policy_zone_fh $static_triggers{$trigger}->();
152 # a qname trigger, where what was specified is the query number it should match
153 print $policy_zone_fh policy_qname
( $trigger );
180 map { [ $_ ]; } 1 .. 32
223 while( $seq_nbr < 32 ) {
228 ( map { [ $_ ]; } 1 .. $seq_nbr ),
229 [ 'ip', $seq_nbr + 2 ],
230 ( map { [ $_ + 2 ]; } ($seq_nbr + 1) .. 31 ),
248 $policy_option = $no_option;
273 32.1.0.0.127.rpz
-client
-ip CNAME
.
277 32.255.255.255.255.rpz
-ip CNAME
.
279 ns
.example
.org
.rpz
-nsdname CNAME
.
281 32.255.255.255.255.rpz
-nsip CNAME
.
283 $case.$seq.policy
.local
317 case
4aa
= 0x12,0x02{31}
324 case
4__
= 0x02{n
(1->30)},0x12,0x02{31-n
}
327 .q
(n
+1) = (n
,0x10)=+r
328 .q
(n
+2) = (n
,0x02)=-r
331 case
4bf
= 0x02{31},0x12
339 case
5a
= 0x02,0x12,0x02,0x12,0x02