Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
Coredns
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Railgun
Coredns
Commits
dbc2efc4
Commit
dbc2efc4
authored
Oct 19, 2018
by
Ruslan Drozhdzh
Committed by
Chris O'Haver
Oct 19, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
plugin/cache: fix TTL for negative DNS responses (#2197)
parent
54df160a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
35 deletions
+14
-35
plugin/cache/README.md
plugin/cache/README.md
+1
-2
plugin/pkg/dnsutil/ttl.go
plugin/pkg/dnsutil/ttl.go
+9
-29
plugin/pkg/dnsutil/ttl_test.go
plugin/pkg/dnsutil/ttl_test.go
+4
-4
No files found.
plugin/cache/README.md
View file @
dbc2efc4
...
@@ -24,7 +24,6 @@ cache [TTL] [ZONES...]
...
@@ -24,7 +24,6 @@ cache [TTL] [ZONES...]
*
**ZONES**
zones it should cache for. If empty, the zones from the configuration block are used.
*
**ZONES**
zones it should cache for. If empty, the zones from the configuration block are used.
Each element in the cache is cached according to its TTL (with
**TTL**
as the max).
Each element in the cache is cached according to its TTL (with
**TTL**
as the max).
For the negative cache, the SOA's MinTTL value is used. A TTL of zero is not allowed.
A cache is divided into 256 shards, each holding up to 512 items by default - for a total size
A cache is divided into 256 shards, each holding up to 512 items by default - for a total size
of 256
*
512 = 131,072 items.
of 256
*
512 = 131,072 items.
...
@@ -101,4 +100,4 @@ Enable caching for all zones, keep a positive cache size of 5000 and a negative
...
@@ -101,4 +100,4 @@ Enable caching for all zones, keep a positive cache size of 5000 and a negative
denial 2500
denial 2500
}
}
}
}
~~~
~~~
\ No newline at end of file
plugin/pkg/dnsutil/ttl.go
View file @
dbc2efc4
...
@@ -14,34 +14,21 @@ func MinimalTTL(m *dns.Msg, mt response.Type) time.Duration {
...
@@ -14,34 +14,21 @@ func MinimalTTL(m *dns.Msg, mt response.Type) time.Duration {
return
MinimalDefaultTTL
return
MinimalDefaultTTL
}
}
// No data to examine, return a short ttl as a fail safe.
// No records or OPT is the only record, return a short ttl as a fail safe.
if
len
(
m
.
Answer
)
+
len
(
m
.
Ns
)
+
len
(
m
.
Extra
)
==
0
{
if
len
(
m
.
Answer
)
+
len
(
m
.
Ns
)
==
0
&&
(
len
(
m
.
Extra
)
==
0
||
(
len
(
m
.
Extra
)
==
1
&&
m
.
Extra
[
0
]
.
Header
()
.
Rrtype
==
dns
.
TypeOPT
))
{
return
MinimalDefaultTTL
return
MinimalDefaultTTL
}
}
minTTL
:=
MaximumDefaulTTL
minTTL
:=
MaximumDefaulTTL
for
_
,
r
:=
range
m
.
Answer
{
for
_
,
r
:=
range
m
.
Answer
{
switch
mt
{
if
r
.
Header
()
.
Ttl
<
uint32
(
minTTL
.
Seconds
())
{
case
response
.
NameError
,
response
.
NoData
:
minTTL
=
time
.
Duration
(
r
.
Header
()
.
Ttl
)
*
time
.
Second
if
r
.
Header
()
.
Rrtype
==
dns
.
TypeSOA
{
minTTL
=
time
.
Duration
(
r
.
(
*
dns
.
SOA
)
.
Minttl
)
*
time
.
Second
}
case
response
.
NoError
,
response
.
Delegation
:
if
r
.
Header
()
.
Ttl
<
uint32
(
minTTL
.
Seconds
())
{
minTTL
=
time
.
Duration
(
r
.
Header
()
.
Ttl
)
*
time
.
Second
}
}
}
}
}
for
_
,
r
:=
range
m
.
Ns
{
for
_
,
r
:=
range
m
.
Ns
{
switch
mt
{
if
r
.
Header
()
.
Ttl
<
uint32
(
minTTL
.
Seconds
())
{
case
response
.
NameError
,
response
.
NoData
:
minTTL
=
time
.
Duration
(
r
.
Header
()
.
Ttl
)
*
time
.
Second
if
r
.
Header
()
.
Rrtype
==
dns
.
TypeSOA
{
minTTL
=
time
.
Duration
(
r
.
(
*
dns
.
SOA
)
.
Minttl
)
*
time
.
Second
}
case
response
.
NoError
,
response
.
Delegation
:
if
r
.
Header
()
.
Ttl
<
uint32
(
minTTL
.
Seconds
())
{
minTTL
=
time
.
Duration
(
r
.
Header
()
.
Ttl
)
*
time
.
Second
}
}
}
}
}
...
@@ -50,15 +37,8 @@ func MinimalTTL(m *dns.Msg, mt response.Type) time.Duration {
...
@@ -50,15 +37,8 @@ func MinimalTTL(m *dns.Msg, mt response.Type) time.Duration {
// OPT records use TTL field for extended rcode and flags
// OPT records use TTL field for extended rcode and flags
continue
continue
}
}
switch
mt
{
if
r
.
Header
()
.
Ttl
<
uint32
(
minTTL
.
Seconds
())
{
case
response
.
NameError
,
response
.
NoData
:
minTTL
=
time
.
Duration
(
r
.
Header
()
.
Ttl
)
*
time
.
Second
if
r
.
Header
()
.
Rrtype
==
dns
.
TypeSOA
{
minTTL
=
time
.
Duration
(
r
.
(
*
dns
.
SOA
)
.
Minttl
)
*
time
.
Second
}
case
response
.
NoError
,
response
.
Delegation
:
if
r
.
Header
()
.
Ttl
<
uint32
(
minTTL
.
Seconds
())
{
minTTL
=
time
.
Duration
(
r
.
Header
()
.
Ttl
)
*
time
.
Second
}
}
}
}
}
return
minTTL
return
minTTL
...
...
plugin/pkg/dnsutil/ttl_test.go
View file @
dbc2efc4
...
@@ -26,8 +26,8 @@ func TestMinimalTTL(t *testing.T) {
...
@@ -26,8 +26,8 @@ func TestMinimalTTL(t *testing.T) {
t
.
Fatalf
(
"Expected type to be response.NoData, got %s"
,
mt
)
t
.
Fatalf
(
"Expected type to be response.NoData, got %s"
,
mt
)
}
}
dur
:=
MinimalTTL
(
m
,
mt
)
// minTTL on msg is 3600 (neg. ttl on SOA)
dur
:=
MinimalTTL
(
m
,
mt
)
// minTTL on msg is 3600 (neg. ttl on SOA)
if
dur
!=
time
.
Duration
(
36
00
*
time
.
Second
)
{
if
dur
!=
time
.
Duration
(
18
00
*
time
.
Second
)
{
t
.
Fatalf
(
"Expected minttl duration to be %d, got %d"
,
36
00
,
dur
)
t
.
Fatalf
(
"Expected minttl duration to be %d, got %d"
,
18
00
,
dur
)
}
}
m
.
Rcode
=
dns
.
RcodeNameError
m
.
Rcode
=
dns
.
RcodeNameError
...
@@ -36,8 +36,8 @@ func TestMinimalTTL(t *testing.T) {
...
@@ -36,8 +36,8 @@ func TestMinimalTTL(t *testing.T) {
t
.
Fatalf
(
"Expected type to be response.NameError, got %s"
,
mt
)
t
.
Fatalf
(
"Expected type to be response.NameError, got %s"
,
mt
)
}
}
dur
=
MinimalTTL
(
m
,
mt
)
// minTTL on msg is 3600 (neg. ttl on SOA)
dur
=
MinimalTTL
(
m
,
mt
)
// minTTL on msg is 3600 (neg. ttl on SOA)
if
dur
!=
time
.
Duration
(
36
00
*
time
.
Second
)
{
if
dur
!=
time
.
Duration
(
18
00
*
time
.
Second
)
{
t
.
Fatalf
(
"Expected minttl duration to be %d, got %d"
,
36
00
,
dur
)
t
.
Fatalf
(
"Expected minttl duration to be %d, got %d"
,
18
00
,
dur
)
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment