Compare commits

...

3 Commits

Author SHA1 Message Date
Arаm Sаrgsyаn
f46c0cff30 Add CHANGES for [GL #2846] 2021-08-25 10:43:21 +00:00
Arаm Sаrgsyаn
5c9ade670d Add tests for the 'masterfile-format auto' feature
This commit slightly extends the 'masterformat' system test to include
several use cases for the 'masterfile-format auto' feature.
2021-08-25 10:41:42 +00:00
Arаm Sаrgsyаn
f679dd9006 Master file format auto-recognition feature
This commit adds an implementation and documentation for a
'masterfile-format auto' feature which automatically recognizes the
existing master file's format or uses the default format for the
particular zone type when there is no existing master file.
2021-08-25 10:41:42 +00:00
32 changed files with 275 additions and 48 deletions

View File

@@ -1,3 +1,9 @@
5703. [func] Implement a 'masterfile-format auto' feature which
automatically recognizes the existing master file's
format or uses the default format for the particular
zone type when there is no existing master file.
[GL #2846]
5702. [bug] Improve compatibility with DNS-over-HTTPS clients by
allowing HTTP/2 request headers in any order. [GL #2875]

View File

@@ -437,6 +437,18 @@ configure_zone(const char *vclass, const char *view, const cfg_obj_t *zconfig,
masterformat = dns_masterformat_raw;
} else if (strcasecmp(masterformatstr, "map") == 0) {
masterformat = dns_masterformat_map;
} else if (strcasecmp(masterformatstr, "auto") == 0) {
result = dns_master_masterformat_autodetect(
zfile, &masterformat);
if (result != ISC_R_SUCCESS &&
result != ISC_R_FILENOTFOUND) {
fprintf(stderr,
"%s/%s/%s: 'masterfile-format auto': "
"%s\n",
view, zname, zclass,
dns_result_totext(result));
return (result);
}
} else {
INSIST(0);
ISC_UNREACHABLE();

View File

@@ -301,7 +301,7 @@ OPTIONS
lmdb-mapsize sizeval;
lock-file ( quoted_string | none );
managed-keys-directory quoted_string;
masterfile-format ( map | raw | text );
masterfile-format ( map | raw | text | auto );
masterfile-style ( full | relative );
match-mapped-addresses boolean;
max-cache-size ( default | unlimited | sizeval | percentage );
@@ -708,7 +708,7 @@ VIEW
) integer integer
integer
quoted_string; ... };, deprecated
masterfile-format ( map | raw | text );
masterfile-format ( map | raw | text | auto );
masterfile-style ( full | relative );
match-clients { address_match_element; ... };
match-destinations { address_match_element; ... };
@@ -927,7 +927,7 @@ VIEW
ixfr-from-differences boolean;
journal quoted_string;
key-directory quoted_string;
masterfile-format ( map | raw | text );
masterfile-format ( map | raw | text | auto );
masterfile-style ( full | relative );
masters [ port integer ] [ dscp integer ] { (
remote-servers | ipv4_address [ port integer ] |
@@ -1044,7 +1044,7 @@ ZONE
ixfr-from-differences boolean;
journal quoted_string;
key-directory quoted_string;
masterfile-format ( map | raw | text );
masterfile-format ( map | raw | text | auto );
masterfile-style ( full | relative );
masters [ port integer ] [ dscp integer ] { ( remote-servers
| ipv4_address [ port integer ] | ipv6_address [ port

View File

@@ -1053,6 +1053,19 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
masterformat = dns_masterformat_raw;
} else if (strcasecmp(masterformatstr, "map") == 0) {
masterformat = dns_masterformat_map;
} else if (strcasecmp(masterformatstr, "auto") == 0) {
result = dns_master_masterformat_autodetect(
filename, &masterformat);
if (result != ISC_R_SUCCESS &&
result != ISC_R_FILENOTFOUND) {
isc_log_write(
named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR,
"zone '%s': "
"'masterfile-format auto': %s\n",
zname, dns_result_totext(result));
return (ISC_R_FAILURE);
}
} else {
INSIST(0);
ISC_UNREACHABLE();
@@ -1068,7 +1081,9 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
cfg_obj_log(obj, named_g_lctx, ISC_LOG_ERROR,
"zone '%s': 'masterfile-style' "
"can only be used with "
"'masterfile-format text'",
"'masterfile-format text' or "
"'masterfile-format auto' with an "
"auto-detected format of 'text'",
zname);
return (ISC_R_FAILURE);
}
@@ -1089,7 +1104,9 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR,
"zone '%s': 'max-zone-ttl' is not compatible "
"with 'masterfile-format map'",
"with 'masterfile-format map' or "
"'masterfile-format auto' with an "
"auto-detected format of 'map'",
zname);
return (ISC_R_FAILURE);
} else if (result == ISC_R_SUCCESS) {

View File

@@ -23,6 +23,7 @@ rm -f ./*/named.run
rm -f ./ns2/example.db
rm -f ./ns2/transfer.db.*
rm -f ./ns2/formerly-text.db
rm -f ./ns2/formerly-text-presently-auto-text.db
rm -f ./ns2/db-*
rm -f ./ns2/large.bk
rm -f ./ns3/example.db.map ./ns3/dynamic.db.map

View File

@@ -67,6 +67,17 @@ zone "transfer4" {
allow-transfer { any; };
};
zone "transfer5" {
type primary;
file "example.db";
allow-transfer { any; };
};
zone "transfer6" {
type primary;
file "example.db";
allow-transfer { any; };
};
zone "large" {
type primary;

View File

@@ -0,0 +1,46 @@
; Copyright (C) Internet Systems Consortium, Inc. ("ISC")
;
; This Source Code Form is subject to the terms of the Mozilla Public
; License, v. 2.0. If a copy of the MPL was not distributed with this
; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;
; See the COPYRIGHT file distributed with this work for additional
; information regarding copyright ownership.
$ORIGIN .
$TTL 86400 ; 1 day
transfer5 IN SOA ns.transfer5. hostmaster.transfer5. (
1 ; serial
3600 ; refresh (1 hour)
1800 ; retry (30 minutes)
1814400 ; expire (3 weeks)
3 ; minimum (3 seconds)
)
NS ns.transfer5.
$ORIGIN transfer5.
a A 10.53.0.1
A 10.53.0.2
aaaa AAAA 2001:db8::53
cname CNAME cname-target
dname DNAME dname-target
$TTL 300 ; 5 minutes
dnskey DNSKEY 256 3 13 (
TEcpWeW1mJp+OujqyInMbjGRODJIYen/4kMR
wO6zW3RzrvmNIMgFag6G uXofiSwJ6YDeQ0O
3uhPJsJ7ivpbh+w==
)
ds DS 30795 1 1 (
310D27F4D82C1FC2400704EA9939FE6E1CEAA3B9 )
$TTL 86400 ; 1 day
mx MX 10 mail
ns A 10.53.0.1
$TTL 600 ; 10 minutes
nsec NSEC nsecnext.transfer5. NS DS RRSIG NSEC
$TTL 300 ; 5 minutes
rrsig RRSIG SOA 1 0 300 (
20050714214747 20050614214747 30795 .
yi/RRPAQmn6rnjDQaCqVValBa+ICF00ZldKfZSDaoew5
mMUh83DlrrPPNeAxrzMSNzDGlJ6PfdyIFgzPn/CvthF4
kjBUAiJTp4r2zhlaUJQ+QFo+drYXYgVJo6aA36fj )
$TTL 86400 ; 1 day
txt TXT "this is text"

View File

@@ -9,15 +9,15 @@
$ORIGIN .
$TTL 86400 ; 1 day
transfer3 IN SOA ns.transfer3. hostmaster.transfer3. (
transfer4 IN SOA ns.transfer4. hostmaster.transfer4. (
1 ; serial
3600 ; refresh (1 hour)
1800 ; retry (30 minutes)
1814400 ; expire (3 weeks)
3 ; minimum (3 seconds)
)
NS ns.transfer3.
$ORIGIN transfer3.
NS ns.transfer4.
$ORIGIN transfer4.
a A 10.53.0.1
A 10.53.0.2
aaaa AAAA 2001:db8::53
@@ -35,7 +35,7 @@ $TTL 86400 ; 1 day
mx MX 10 mail
ns A 10.53.0.1
$TTL 600 ; 10 minutes
nsec NSEC nsecnext.transfer3. NS DS RRSIG NSEC
nsec NSEC nsecnext.transfer4. NS DS RRSIG NSEC
$TTL 300 ; 5 minutes
rrsig RRSIG SOA 1 0 300 (
20050714214747 20050614214747 30795 .

View File

@@ -35,17 +35,31 @@ zone "transfer1" {
zone "transfer2" {
type secondary;
primaries { 10.53.0.1; };
masterfile-format text;
file "transfer.db.txt";
masterfile-format auto;
file "transfer.db.auto.raw";
};
zone "transfer3" {
type secondary;
primaries { 10.53.0.1; };
file "formerly-text.db";
masterfile-format text;
file "transfer.db.txt";
};
zone "transfer4" {
type secondary;
primaries { 10.53.0.1; };
file "formerly-text.db";
};
zone "transfer5" {
type secondary;
primaries { 10.53.0.1; };
masterfile-format auto;
file "formerly-text-presently-auto-text.db";
};
zone "transfer6" {
type secondary;
primaries { 10.53.0.1; };
masterfile-format text;

View File

@@ -31,7 +31,7 @@ controls {
zone "example" {
type primary;
masterfile-format map;
masterfile-format auto;
file "example.db.map";
};

View File

@@ -20,6 +20,7 @@ copy_setports ns3/named.conf.in ns3/named.conf
cp ns1/example.db ns2/
cp ns2/formerly-text.db.in ns2/formerly-text.db
cp ns2/formerly-text-presently-auto-text.db.in ns2/formerly-text-presently-auto-text.db
cp ns1/large.db.in ns1/large.db
awk 'END {
for (i = 0; i < 512; i++ ) { print "a TXT", i; }

View File

@@ -144,7 +144,7 @@ status=$((status+ret))
echo_i "waiting for transfers to complete"
for i in 0 1 2 3 4 5 6 7 8 9
do
test -f ns2/transfer.db.raw -a -f ns2/transfer.db.txt && break
test -f ns2/transfer.db.raw -a -f ns2/transfer.db.auto.raw -a -f ns2/transfer.db.txt && break
sleep 1
done
@@ -155,6 +155,13 @@ n=$((n+1))
[ $ret -eq 0 ] || echo_i "failed"
status=$((status+ret))
echo_i "checking that secondary was saved in raw format when configured as auto ($n)"
ret=0
israw ns2/transfer.db.raw || ret=1
n=$((n+1))
[ $ret -eq 0 ] || echo_i "failed"
status=$((status+ret))
echo_i "checking that secondary was saved in text format when configured ($n)"
ret=0
israw ns2/transfer.db.txt && ret=1
@@ -183,6 +190,20 @@ n=$((n+1))
[ $ret -eq 0 ] || echo_i "failed"
status=$((status+ret))
echo_i "checking that secondary formerly in text format is now in text format too, using auto ($n)"
for i in 0 1 2 3 4 5 6 7 8 9
do
ret=0
test -f ns2/formerly-text-presently-auto-text.db > /dev/null 2>&1 || ret=1
israw ns2/formerly-text-presently-auto-text.db > /dev/null 2>&1 && ret=1
ismap ns2/formerly-text-presently-auto-text.db > /dev/null 2>&1 && ret=1
[ $ret -eq 0 ] && break
sleep 1
done
n=$((n+1))
[ $ret -eq 0 ] || echo_i "failed"
status=$((status+ret))
echo_i "checking that large rdatasets loaded ($n)"
for i in 0 1 2 3 4 5 6 7 8 9
do

View File

@@ -3582,10 +3582,17 @@ Tuning
``masterfile-format`` statement within the ``zone`` or ``view`` block
in the configuration file.
When set to ``auto``, BIND 9 will try to automatically detect the used
format, based on the existing file on the disk. When the file does not
exist ``auto`` will be equal to the default value of ``text``, except
for secondary and mirror zones in which case ``auto`` will be equal to
the default value of ``raw``.
``masterfile-style``
This specifies the formatting of zone files during dump, when the
``masterfile-format`` is ``text``. This option is ignored with any
other ``masterfile-format``.
``masterfile-format`` is ``text`` or when ``masterfile-format`` is
``auto`` with an auto-detected value of ``text``. This option is ignored
with any other ``masterfile-format``.
When set to ``relative``, records are printed in a multi-line format,
with owner names expressed relative to a shared origin. When set to
@@ -5125,9 +5132,10 @@ The following options can be specified in a ``dnssec-policy`` statement:
``max-zone-ttl``
Like the ``max-zone-ttl`` zone option, this specifies the maximum
permissible TTL value, in seconds, for the zone. When loading a
zone file using a ``masterfile-format`` of ``text`` or ``raw``, any
record encountered with a TTL higher than ``max-zone-ttl`` is capped
at the maximum permissible TTL value.
zone file using a ``masterfile-format`` of ``text`` or ``raw``, or
using ``masterfile-format`` of ``auto`` with auto-detected values of
either ``text`` or ``raw``, any record encountered with a TTL higher
than ``max-zone-ttl`` is capped at the maximum permissible TTL value.
This is needed in DNSSEC-maintained zones because when rolling to a
new DNSKEY, the old key needs to remain available until RRSIG

View File

@@ -368,7 +368,7 @@ options {
lmdb\-mapsize sizeval;
lock\-file ( quoted_string | none );
managed\-keys\-directory quoted_string;
masterfile\-format ( map | raw | text );
masterfile\-format ( map | raw | text | auto );
masterfile\-style ( full | relative );
match\-mapped\-addresses boolean;
max\-cache\-size ( default | unlimited | sizeval | percentage );
@@ -811,7 +811,7 @@ view string [ class ] {
) integer integer
integer
quoted_string; ... };, deprecated
masterfile\-format ( map | raw | text );
masterfile\-format ( map | raw | text | auto );
masterfile\-style ( full | relative );
match\-clients { address_match_element; ... };
match\-destinations { address_match_element; ... };
@@ -1030,7 +1030,7 @@ view string [ class ] {
ixfr\-from\-differences boolean;
journal quoted_string;
key\-directory quoted_string;
masterfile\-format ( map | raw | text );
masterfile\-format ( map | raw | text | auto );
masterfile\-style ( full | relative );
masters [ port integer ] [ dscp integer ] { (
remote\-servers | ipv4_address [ port integer ] |
@@ -1151,7 +1151,7 @@ zone string [ class ] {
ixfr\-from\-differences boolean;
journal quoted_string;
key\-directory quoted_string;
masterfile\-format ( map | raw | text );
masterfile\-format ( map | raw | text | auto );
masterfile\-style ( full | relative );
masters [ port integer ] [ dscp integer ] { ( remote\-servers
| ipv4_address [ port integer ] | ipv6_address [ port

View File

@@ -33,7 +33,7 @@ zone <string> [ <class> ] {
ixfr-from-differences <boolean>;
journal <quoted_string>;
key-directory <quoted_string>;
masterfile-format ( map | raw | text );
masterfile-format ( map | raw | text | auto );
masterfile-style ( full | relative );
max-ixfr-ratio ( unlimited | <percentage> );
max-journal-size ( default | unlimited | <sizeval> );

View File

@@ -35,7 +35,7 @@
ixfr-from-differences <boolean>;
journal <quoted_string>;
key-directory <quoted_string>;
masterfile-format ( map | raw | text );
masterfile-format ( map | raw | text | auto );
masterfile-style ( full | relative );
max-ixfr-ratio ( unlimited | <percentage> );
max-journal-size ( default | unlimited | <sizeval> );

View File

@@ -13,7 +13,7 @@ zone <string> [ <class> ] {
file <quoted_string>;
ixfr-from-differences <boolean>;
journal <quoted_string>;
masterfile-format ( map | raw | text );
masterfile-format ( map | raw | text | auto );
masterfile-style ( full | relative );
masters [ port <integer> ] [ dscp <integer> ] { ( <remote-servers> | <ipv4_address> [ port <integer> ] | <ipv6_address> [ port <integer> ] ) [ key <string> ] [ tls <string> ]; ... };
max-ixfr-ratio ( unlimited | <percentage> );

View File

@@ -15,7 +15,7 @@
file <quoted_string>;
ixfr-from-differences <boolean>;
journal <quoted_string>;
masterfile-format ( map | raw | text );
masterfile-format ( map | raw | text | auto );
masterfile-style ( full | relative );
masters [ port <integer> ] [ dscp <integer> ] { ( <remote-servers> | <ipv4_address> [ port <integer> ] | <ipv6_address> [ port <integer> ] ) [ key <string> ] [ tls <string> ]; ... };
max-ixfr-ratio ( unlimited | <percentage> );

View File

@@ -289,7 +289,7 @@ OPTIONS
lmdb-mapsize sizeval;
lock-file ( quoted_string | none );
managed-keys-directory quoted_string;
masterfile-format ( map | raw | text );
masterfile-format ( map | raw | text | auto );
masterfile-style ( full | relative );
match-mapped-addresses boolean;
max-cache-size ( default | unlimited | sizeval | percentage );
@@ -644,7 +644,7 @@ VIEW
) integer integer
integer
quoted_string; ... };, deprecated
masterfile-format ( map | raw | text );
masterfile-format ( map | raw | text | auto );
masterfile-style ( full | relative );
match-clients { address_match_element; ... };
match-destinations { address_match_element; ... };
@@ -856,7 +856,7 @@ VIEW
ixfr-from-differences boolean;
journal quoted_string;
key-directory quoted_string;
masterfile-format ( map | raw | text );
masterfile-format ( map | raw | text | auto );
masterfile-style ( full | relative );
masters [ port integer ] [ dscp integer ] { ( masters
| ipv4_address [ port integer ] | ipv6_address [
@@ -959,7 +959,7 @@ ZONE
ixfr-from-differences boolean;
journal quoted_string;
key-directory quoted_string;
masterfile-format ( map | raw | text );
masterfile-format ( map | raw | text | auto );
masterfile-style ( full | relative );
masters [ port integer ] [ dscp integer ] { ( masters |
ipv4_address [ port integer ] | ipv6_address [ port

View File

@@ -225,7 +225,7 @@ options {
lmdb-mapsize <sizeval>;
lock-file ( <quoted_string> | none );
managed-keys-directory <quoted_string>;
masterfile-format ( map | raw | text );
masterfile-format ( map | raw | text | auto );
masterfile-style ( full | relative );
match-mapped-addresses <boolean>;
max-cache-size ( default | unlimited | <sizeval> | <percentage> );
@@ -587,7 +587,7 @@ view <string> [ <class> ] {
) <integer> <integer>
<integer>
<quoted_string>; ... }; // may occur multiple times, deprecated
masterfile-format ( map | raw | text );
masterfile-format ( map | raw | text | auto );
masterfile-style ( full | relative );
match-clients { <address_match_element>; ... };
match-destinations { <address_match_element>; ... };
@@ -808,7 +808,7 @@ view <string> [ <class> ] {
ixfr-from-differences <boolean>;
journal <quoted_string>;
key-directory <quoted_string>;
masterfile-format ( map | raw | text );
masterfile-format ( map | raw | text | auto );
masterfile-style ( full | relative );
masters [ port <integer> ] [ dscp <integer> ] { (
<remote-servers> | <ipv4_address> [ port <integer> ] |
@@ -921,7 +921,7 @@ zone <string> [ <class> ] {
ixfr-from-differences <boolean>;
journal <quoted_string>;
key-directory <quoted_string>;
masterfile-format ( map | raw | text );
masterfile-format ( map | raw | text | auto );
masterfile-style ( full | relative );
masters [ port <integer> ] [ dscp <integer> ] { ( <remote-servers>
| <ipv4_address> [ port <integer> ] | <ipv6_address> [ port

View File

@@ -224,7 +224,7 @@ options {
lmdb-mapsize <sizeval>;
lock-file ( <quoted_string> | none );
managed-keys-directory <quoted_string>;
masterfile-format ( map | raw | text );
masterfile-format ( map | raw | text | auto );
masterfile-style ( full | relative );
match-mapped-addresses <boolean>;
max-cache-size ( default | unlimited | <sizeval> | <percentage> );
@@ -584,7 +584,7 @@ view <string> [ <class> ] {
) <integer> <integer>
<integer>
<quoted_string>; ... }; // may occur multiple times, deprecated
masterfile-format ( map | raw | text );
masterfile-format ( map | raw | text | auto );
masterfile-style ( full | relative );
match-clients { <address_match_element>; ... };
match-destinations { <address_match_element>; ... };
@@ -803,7 +803,7 @@ view <string> [ <class> ] {
ixfr-from-differences <boolean>;
journal <quoted_string>;
key-directory <quoted_string>;
masterfile-format ( map | raw | text );
masterfile-format ( map | raw | text | auto );
masterfile-style ( full | relative );
masters [ port <integer> ] [ dscp <integer> ] { (
<remote-servers> | <ipv4_address> [ port <integer> ] |
@@ -915,7 +915,7 @@ zone <string> [ <class> ] {
ixfr-from-differences <boolean>;
journal <quoted_string>;
key-directory <quoted_string>;
masterfile-format ( map | raw | text );
masterfile-format ( map | raw | text | auto );
masterfile-style ( full | relative );
masters [ port <integer> ] [ dscp <integer> ] { ( <remote-servers>
| <ipv4_address> [ port <integer> ] | <ipv6_address> [ port

View File

@@ -144,7 +144,7 @@
lmdb-mapsize <sizeval>;
lock-file ( <quoted_string> | none );
managed-keys-directory <quoted_string>;
masterfile-format ( map | raw | text );
masterfile-format ( map | raw | text | auto );
masterfile-style ( full | relative );
match-mapped-addresses <boolean>;
max-cache-size ( default | unlimited | <sizeval> | <percentage> );

View File

@@ -4,7 +4,7 @@ zone <string> [ <class> ] {
allow-query-on { <address_match_element>; ... };
dlz <string>;
file <quoted_string>;
masterfile-format ( map | raw | text );
masterfile-format ( map | raw | text | auto );
masterfile-style ( full | relative );
masters [ port <integer> ] [ dscp <integer> ] { ( <remote-servers> | <ipv4_address> [ port <integer> ] | <ipv6_address> [ port <integer> ] ) [ key <string> ] [ tls <string> ]; ... };
max-records <integer>;

View File

@@ -6,7 +6,7 @@
allow-query-on { <address_match_element>; ... };
dlz <string>;
file <quoted_string>;
masterfile-format ( map | raw | text );
masterfile-format ( map | raw | text | auto );
masterfile-style ( full | relative );
masters [ port <integer> ] [ dscp <integer> ] { ( <remote-servers> | <ipv4_address> [ port <integer> ] | <ipv6_address> [ port <integer> ] ) [ key <string> ] [ tls <string> ]; ... };
max-records <integer>;

View File

@@ -25,7 +25,7 @@ zone <string> [ <class> ] {
ixfr-from-differences <boolean>;
journal <quoted_string>;
key-directory <quoted_string>;
masterfile-format ( map | raw | text );
masterfile-format ( map | raw | text | auto );
masterfile-style ( full | relative );
masters [ port <integer> ] [ dscp <integer> ] { ( <remote-servers> | <ipv4_address> [ port <integer> ] | <ipv6_address> [ port <integer> ] ) [ key <string> ] [ tls <string> ]; ... };
max-ixfr-ratio ( unlimited | <percentage> );

View File

@@ -27,7 +27,7 @@
ixfr-from-differences <boolean>;
journal <quoted_string>;
key-directory <quoted_string>;
masterfile-format ( map | raw | text );
masterfile-format ( map | raw | text | auto );
masterfile-style ( full | relative );
masters [ port <integer> ] [ dscp <integer> ] { ( <remote-servers> | <ipv4_address> [ port <integer> ] | <ipv6_address> [ port <integer> ] ) [ key <string> ] [ tls <string> ]; ... };
max-ixfr-ratio ( unlimited | <percentage> );

View File

@@ -9,7 +9,7 @@ zone <string> [ <class> ] {
file <quoted_string>;
forward ( first | only );
forwarders [ port <integer> ] [ dscp <integer> ] { ( <ipv4_address> | <ipv6_address> ) [ port <integer> ] [ dscp <integer> ]; ... };
masterfile-format ( map | raw | text );
masterfile-format ( map | raw | text | auto );
masterfile-style ( full | relative );
masters [ port <integer> ] [ dscp <integer> ] { ( <remote-servers> | <ipv4_address> [ port <integer> ] | <ipv6_address> [ port <integer> ] ) [ key <string> ] [ tls <string> ]; ... };
max-records <integer>;

View File

@@ -11,7 +11,7 @@
file <quoted_string>;
forward ( first | only );
forwarders [ port <integer> ] [ dscp <integer> ] { ( <ipv4_address> | <ipv6_address> ) [ port <integer> ] [ dscp <integer> ]; ... };
masterfile-format ( map | raw | text );
masterfile-format ( map | raw | text | auto );
masterfile-style ( full | relative );
masters [ port <integer> ] [ dscp <integer> ] { ( <remote-servers> | <ipv4_address> [ port <integer> ] | <ipv6_address> [ port <integer> ] ) [ key <string> ] [ tls <string> ]; ... };
max-records <integer>;

View File

@@ -3350,6 +3350,13 @@ check_zoneconf(const cfg_obj_t *zconfig, const cfg_obj_t *voptions,
masterformat = dns_masterformat_raw;
} else if (strcasecmp(masterformatstr, "map") == 0) {
masterformat = dns_masterformat_map;
} else if (strcasecmp(masterformatstr, "auto") == 0) {
if (ztype == CFG_ZONE_SLAVE || ztype == CFG_ZONE_MIRROR)
{
masterformat = dns_masterformat_raw;
} else {
masterformat = dns_masterformat_text;
}
} else {
INSIST(0);
ISC_UNREACHABLE();

View File

@@ -257,6 +257,34 @@ dns_master_initrawheader(dns_masterrawheader_t *header);
* Initializes the header for a raw master file, setting all
* values to zero.
*/
isc_result_t
dns_master_masterformat_autodetect(const char * master_file,
dns_masterformat_t *result_masterformat);
/*%<
* Autodetects the master file's format.
*
* There are no heuristics, it is expected that the given master file is in one
* of the supported formats - "text", "raw", or "map".
*
* The "raw" and "map" type master files have a specific header, which will
* be recognized by this function. If neither of those formats are detected,
* the functions will assume that the given master file is in "text" format.
*
* Requires:
*\li 'master_file' points to a valid string.
*\li 'result_masterformat != NULL'.
*
* Ensures:
*\li '*result_masterformat' is not altered when the return value is not
* ISC_R_SUCCESS.
*
* Returns:
*\li ISC_R_SUCCESS upon successfully detection.
*\li ISC_R_FILENOTFOUND when the master_file was not found.
*\li Any isc_stdio_read() error code.
*\li Any isc_stdio_close() error code.
*/
ISC_LANG_ENDDECLS
#endif /* DNS_MASTER_H */

View File

@@ -16,6 +16,7 @@
#include <isc/atomic.h>
#include <isc/event.h>
#include <isc/file.h>
#include <isc/lex.h>
#include <isc/magic.h>
#include <isc/mem.h>
@@ -3226,3 +3227,56 @@ void
dns_master_initrawheader(dns_masterrawheader_t *header) {
memset(header, 0, sizeof(dns_masterrawheader_t));
}
isc_result_t
dns_master_masterformat_autodetect(const char *master_file,
dns_masterformat_t *result_masterformat) {
FILE *f;
dns_masterrawheader_t header;
unsigned char data[sizeof header.format + sizeof header.version];
isc_buffer_t target;
isc_result_t result;
if (!isc_file_exists(master_file)) {
return (ISC_R_FILENOTFOUND);
}
result = isc_stdio_open(master_file, "rb", &f);
if (result != ISC_R_SUCCESS) {
return (result);
}
dns_master_initrawheader(&header);
isc_buffer_init(&target, data, sizeof data);
result = isc_stdio_read(data, sizeof data, 1, f, NULL);
if (result != ISC_R_SUCCESS) {
/*
* We can't report multiple errors so ignore
* the result of isc_stdio_close().
*/
(void)isc_stdio_close(f);
return (result);
}
result = isc_stdio_close(f);
if (result != ISC_R_SUCCESS) {
return (result);
}
isc_buffer_add(&target, (unsigned int)sizeof data);
header.format = isc_buffer_getuint32(&target);
header.version = isc_buffer_getuint32(&target);
if (((dns_masterformat_t)header.format == dns_masterformat_raw ||
(dns_masterformat_t)header.format == dns_masterformat_map) &&
header.version <= (uint32_t)DNS_RAWFORMAT_VERSION)
{
*result_masterformat = (dns_masterformat_t)header.format;
} else {
*result_masterformat = dns_masterformat_text;
}
return (ISC_R_SUCCESS);
}

View File

@@ -1410,7 +1410,8 @@ static cfg_type_t cfg_type_mustbesecure = {
cfg_doc_tuple, &cfg_rep_tuple, mustbesecure_fields
};
static const char *masterformat_enums[] = { "map", "raw", "text", NULL };
static const char *masterformat_enums[] = { "map", "raw", "text", "auto",
NULL };
static cfg_type_t cfg_type_masterformat = {
"masterformat", cfg_parse_enum, cfg_print_ustring,
cfg_doc_enum, &cfg_rep_string, &masterformat_enums