Changeset 864 for trunk/DNSDB
- Timestamp:
- 09/20/22 17:09:46 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB/ExportBIND.pm
r863 r864 273 273 elsif ($typemap{$type} eq 'AAAA') { 274 274 # ($host,$val) = __revswap($host,$val) if $revrec eq 'y'; 275 my $altgrp = 0;276 my @altconv;277 # Split in to up to 8 groups of hex digits (allows for IPv6 :: 0-collapsing)278 foreach (split /:/, $val) {279 if (/^$/) {280 # flag blank entry; this is a series of 0's of (currently) unknown length281 $altconv[$altgrp++] = 's';282 } else {283 # call sub to convert 1-4 hex digits to 2 string-rep octal bytes284 $altconv[$altgrp++] = octalize($_)285 }286 }287 my $prefix = ":$host:28:";288 foreach my $octet (@altconv) {289 # if not 's', output290 $prefix .= $octet unless $octet =~ /^s$/;291 # if 's', output (9-array length)x literal '\000\000'292 $prefix .= '\000\000'x(9-$altgrp) if $octet =~ /^s$/;293 }294 275 print {$zonefiles->{$loc}} "$host $ttl IN AAAA $val\n" or die $!; 295 276 } # AAAA … … 317 298 318 299 elsif ($typemap{$type} eq 'PTR') { 319 #$$recflags{$val}++;300 $$recflags{$val}++; 320 301 if ($revrec eq 'y') { 321 302 … … 352 333 # Recurse to PTR or A as appropriate because BIND et al don't share 353 334 # the tinydns concept of merged forward/reverse records 354 #$$recflags{$val}++;335 $$recflags{$val}++; 355 336 if ($revrec eq 'y') { 356 337 printrec_bind($zonefiles, $recid, $revrec, $loclist, $zone, $host, 12, $val, $distance, $weight, $port, $ttl, … … 367 348 } # A+PTR 368 349 350 elsif ($type == 65282) { # PTR template 351 # only useful for v4 with standard DNS software, since this expands all 352 # IPs in $zone (or possibly $val?) with autogenerated records 353 $val = NetAddr::IP->new($val); 354 return if $val->{isv6}; 355 356 sub __publish_template_bind { 357 my $sub = shift; 358 my $recflags = shift; 359 my $hpat = shift; 360 my $fh = shift; 361 my $ttl = shift; 362 my $stamp = shift; 363 my $loc = shift; 364 my $zone = new NetAddr::IP shift; 365 my $ptrflag = shift || 0; ##fixme: default to PTR instead of A record for the BIND variant of this sub? 366 367 # do this conversion once, not (number-of-ips-in-subnet) times 368 my $arpabase = _ZONE($zone, 'ZONE.in-addr.arpa', 'r', '.'); 369 370 my $iplist = $sub->splitref(32); 371 my $ipindex = -1; 372 foreach (@$iplist) { 373 my $ip = $_->addr; 374 $ipindex++; 375 # make as if we split the non-octet-aligned block into octet-aligned blocks as with SOA 376 my $lastoct = (split /\./, $ip)[3]; 377 378 # Allow smaller entries to override longer ones, eg, a specific PTR will 379 # always publish, overriding any template record containing that IP. 380 # %blank% also needs to be per-IP here to properly cascade overrides with 381 # multiple nested templates 382 next if $$recflags{$ip}; # && $self->{skip_bcast_255} 383 $$recflags{$ip}++; 384 next if $hpat eq '%blank%'; 385 386 my $rec = $hpat; # start fresh with the template for each IP 387 ##fixme: there really isn't a good way to handle sub-/24 zones here. This way at least 388 # seems less bad than some alternatives. 389 $dnsdb->_template4_expand(\$rec, $ip, \$sub, $ipindex); 390 # _template4_expand may blank $rec; if so, don't publish a record 391 next if !$rec; 392 ##fixme: trim merged record type voodoo. "if ($ptrflag) {} else {}" ? 393 if ($ptrflag || $zone->masklen > 24) { 394 # print $fh "^$lastoct.$arpabase:$rec:$ttl:$stamp:$loc\n" or die $!; 395 print $fh "$lastoct.$arpabase $ttl IN PTR $rec\n" or die $!; 396 if (!$ptrflag) { 397 # print a separate A record. Arguably we could use an = record here instead. 398 # print $fh "+$rec:$ip:$ttl:$stamp:$loc\n" or die $!; 399 } 400 } else { 401 # A record, not merged 402 # print $fh "=$rec:$ip:$ttl:$stamp:$loc\n" or die $!; 403 print $fh "$rec $ttl IN A $ip\n" or die $!; 404 } 405 } 406 } # __publish_subnet_bind() 407 408 if ($val->masklen <= 16) { 409 foreach my $sub ($val->split(16)) { 410 __publish_subnet($sub, $recflags, $host, $zonefiles->{$loc}, $ttl, $stamp, $loc, $zone, 1); 411 } 412 } else { 413 __publish_subnet($val, $recflags, $host, $zonefiles->{$loc}, $ttl, $stamp, $loc, $zone, 1); 414 } 415 } # PTR template 416 369 417 } # printrec_bind() 370 418
Note:
See TracChangeset
for help on using the changeset viewer.