|
@@ -52,6 +52,7 @@ public:
|
|
const MasterLoaderCallbacks& callbacks,
|
|
const MasterLoaderCallbacks& callbacks,
|
|
const AddRRCallback& add_callback,
|
|
const AddRRCallback& add_callback,
|
|
MasterLoader::Options options) :
|
|
MasterLoader::Options options) :
|
|
|
|
+ MAX_TTL(0x7fffffff),
|
|
lexer_(),
|
|
lexer_(),
|
|
zone_origin_(zone_origin),
|
|
zone_origin_(zone_origin),
|
|
zone_class_(zone_class),
|
|
zone_class_(zone_class),
|
|
@@ -142,13 +143,38 @@ private:
|
|
pushSource(filename);
|
|
pushSource(filename);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // Upper limit check when recognizing a specific TTL value from the
|
|
|
|
+ // zone file ($TTL, the RR's TTL field, or the SOA minimum). RFC2181
|
|
|
|
+ // Section 8 limits the range of TTL values to unsigned 32-bit integers,
|
|
|
|
+ // and prohibits transmitting a TTL field exceeding this range. We
|
|
|
|
+ // guarantee that by limiting the value at the time of zone
|
|
|
|
+ // parsing/loading, following what BIND 9 does. Resetting it to 0
|
|
|
|
+ // at this point may not be exactly what the RFC states, but the end
|
|
|
|
+ // result would be the same. Again, we follow the BIND 9's behavior here.
|
|
|
|
+ //
|
|
|
|
+ // post_parsing is true iff this method is called after parsing the entire
|
|
|
|
+ // RR and the lexer is positioned at the next line. It's just for
|
|
|
|
+ // calculating the accurate source line when callback is necessary.
|
|
|
|
+ void limitTTL(RRTTL& ttl, bool post_parsing) {
|
|
|
|
+ if (ttl > MAX_TTL) {
|
|
|
|
+ const size_t src_line = lexer_.getSourceLine() -
|
|
|
|
+ (post_parsing ? 1 : 0);
|
|
|
|
+ callbacks_.warning(lexer_.getSourceName(), src_line,
|
|
|
|
+ "TTL " + ttl.toText() + " > MAXTTL, "
|
|
|
|
+ "setting to 0 per RFC2181");
|
|
|
|
+ ttl = RRTTL(0);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
// Set/reset the default TTL. Either from $TTL or SOA minimum TTL.
|
|
// Set/reset the default TTL. Either from $TTL or SOA minimum TTL.
|
|
- void setDefaultTTL(const RRTTL& ttl) {
|
|
|
|
|
|
+ // see LimitTTL() for parameter post_parsing.
|
|
|
|
+ void setDefaultTTL(const RRTTL& ttl, bool post_parsing) {
|
|
if (!default_ttl_) {
|
|
if (!default_ttl_) {
|
|
default_ttl_.reset(new RRTTL(ttl));
|
|
default_ttl_.reset(new RRTTL(ttl));
|
|
} else {
|
|
} else {
|
|
*default_ttl_ = ttl;
|
|
*default_ttl_ = ttl;
|
|
}
|
|
}
|
|
|
|
+ limitTTL(*default_ttl_, post_parsing);
|
|
}
|
|
}
|
|
|
|
|
|
// Set/reset the TTL currently being used. This can be used the last
|
|
// Set/reset the TTL currently being used. This can be used the last
|
|
@@ -168,6 +194,7 @@ private:
|
|
bool setCurrentTTL(const string& ttl_txt) {
|
|
bool setCurrentTTL(const string& ttl_txt) {
|
|
try {
|
|
try {
|
|
setCurrentTTL(RRTTL(ttl_txt));
|
|
setCurrentTTL(RRTTL(ttl_txt));
|
|
|
|
+ limitTTL(*current_ttl_, false);
|
|
return (true);
|
|
return (true);
|
|
} catch (const InvalidRRTTL&) {
|
|
} catch (const InvalidRRTTL&) {
|
|
return (false);
|
|
return (false);
|
|
@@ -197,7 +224,7 @@ private:
|
|
const uint32_t ttl_val =
|
|
const uint32_t ttl_val =
|
|
dynamic_cast<const rdata::generic::SOA&>(*rdata).
|
|
dynamic_cast<const rdata::generic::SOA&>(*rdata).
|
|
getMinimum();
|
|
getMinimum();
|
|
- setDefaultTTL(RRTTL(ttl_val));
|
|
|
|
|
|
+ setDefaultTTL(RRTTL(ttl_val), true);
|
|
setCurrentTTL(*default_ttl_);
|
|
setCurrentTTL(*default_ttl_);
|
|
} else {
|
|
} else {
|
|
// On catching the exception we'll try to reach EOL again,
|
|
// On catching the exception we'll try to reach EOL again,
|
|
@@ -227,7 +254,7 @@ private:
|
|
isc_throw(isc::NotImplemented,
|
|
isc_throw(isc::NotImplemented,
|
|
"Origin directive not implemented yet");
|
|
"Origin directive not implemented yet");
|
|
} else if (iequals(directive, "TTL")) {
|
|
} else if (iequals(directive, "TTL")) {
|
|
- setDefaultTTL(RRTTL(getString()));
|
|
|
|
|
|
+ setDefaultTTL(RRTTL(getString()), false);
|
|
eatUntilEOL(true);
|
|
eatUntilEOL(true);
|
|
} else {
|
|
} else {
|
|
isc_throw(InternalException, "Unknown directive '" <<
|
|
isc_throw(InternalException, "Unknown directive '" <<
|
|
@@ -265,6 +292,11 @@ private:
|
|
}
|
|
}
|
|
|
|
|
|
private:
|
|
private:
|
|
|
|
+ // RFC2181 Section 8 specifies TTLs are unsigned 32-bit integer,
|
|
|
|
+ // effectively limiting the maximum value to 2^32-1. This constant
|
|
|
|
+ // represent a TTL of the max value.
|
|
|
|
+ const RRTTL MAX_TTL;
|
|
|
|
+
|
|
MasterLexer lexer_;
|
|
MasterLexer lexer_;
|
|
const Name zone_origin_;
|
|
const Name zone_origin_;
|
|
const RRClass zone_class_;
|
|
const RRClass zone_class_;
|