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
ae841ae3
Commit
ae841ae3
authored
Mar 22, 2016
by
Miek Gieben
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
it compiles
parent
1a7f0dea
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
47 additions
and
46 deletions
+47
-46
core/directives.go
core/directives.go
+1
-0
middleware/etcd/etcd.md
middleware/etcd/etcd.md
+2
-2
middleware/etcd/handler.go
middleware/etcd/handler.go
+34
-36
middleware/etcd/lookup.go
middleware/etcd/lookup.go
+8
-6
middleware/etcd/msg/service.go
middleware/etcd/msg/service.go
+2
-2
No files found.
core/directives.go
View file @
ae841ae3
...
...
@@ -58,6 +58,7 @@ var directiveOrder = []directive{
{
"log"
,
setup
.
Log
},
{
"errors"
,
setup
.
Errors
},
{
"proxy"
,
setup
.
Proxy
},
{
"etcd"
,
setup
.
Etcd
},
}
// RegisterDirective adds the given directive to caddy's list of directives.
...
...
middleware/etcd/etcd.md
View file @
ae841ae3
...
...
@@ -19,13 +19,13 @@ If you want to `round robin` A and AAAA responses look at the `round_robin` midd
~~~
etcd {
path /skydns
endpoint
address
...
endpoint
endpoint
...
stubzones
}
~~~
*
`path`
/skydns
*
`endpoint`
addres
s...
*
`endpoint`
endpoint
s...
*
`stubzones`
## Examples
middleware/etcd/handler.go
View file @
ae841ae3
...
...
@@ -8,34 +8,38 @@ import (
func
(
e
Etcd
)
ServeDNS
(
ctx
context
.
Context
,
w
dns
.
ResponseWriter
,
r
*
dns
.
Msg
)
(
int
,
error
)
{
println
(
"ETCD MIDDLEWARE HIT"
)
state
:=
middleware
.
State
{
W
:
w
,
Req
:
r
}
zone
:=
middleware
.
Zones
(
e
.
Zones
)
.
Matches
(
state
.
Name
())
if
zone
==
""
{
return
e
.
Next
.
ServeDNS
(
ctx
,
w
,
r
)
}
m
:=
state
.
AnswerMessage
()
m
.
Authoritative
=
true
m
.
RecursionAvailable
=
true
m
.
Compress
=
true
// TODO(miek): get current zone when serving multiple
zone
:=
"."
m
.
Authoritative
,
m
.
RecursionAvailable
,
m
.
Compress
=
true
,
true
,
true
var
(
records
,
extra
[]
dns
.
RR
err
error
)
switch
state
.
Type
()
{
case
"A"
:
records
,
err
:
=
e
.
A
(
zone
,
state
,
nil
)
records
,
err
=
e
.
A
(
zone
,
state
,
nil
)
case
"AAAA"
:
records
,
err
:=
e
.
AAAA
(
zone
,
state
,
nil
)
fallthrough
records
,
err
=
e
.
AAAA
(
zone
,
state
,
nil
)
case
"TXT"
:
records
,
err
:=
e
.
TXT
(
zone
,
state
)
fallthrough
records
,
err
=
e
.
TXT
(
zone
,
state
)
case
"CNAME"
:
records
,
err
:=
e
.
CNAME
(
zone
,
state
)
fallthrough
records
,
err
=
e
.
CNAME
(
zone
,
state
)
case
"MX"
:
records
,
extra
,
err
:=
e
.
MX
(
zone
,
state
)
fallthrough
records
,
extra
,
err
=
e
.
MX
(
zone
,
state
)
case
"SRV"
:
records
,
extra
,
err
:=
e
.
SRV
(
zone
,
state
)
records
,
extra
,
err
=
e
.
SRV
(
zone
,
state
)
default
:
// rwrite and return
// Nodata response
// also catch other types, so that they return NODATA
return
0
,
nil
}
if
isEtcdNameError
(
err
)
{
NameError
(
zone
,
state
)
return
dns
.
RcodeNameError
,
nil
...
...
@@ -50,21 +54,15 @@ func (e Etcd) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (i
if
len
(
extra
)
>
0
{
m
.
Extra
=
append
(
m
.
Extra
,
extra
...
)
}
default
:
// Nodata response
// also catch other types, so that they return NODATA
}
return
e
.
Next
.
ServeDNS
(
ctx
,
w
,
r
)
state
.
W
.
WriteMsg
(
m
)
return
0
,
nil
}
// NameError writes a name error to the client.
func
NameError
(
zone
string
,
state
middleware
.
State
)
{
m
:=
new
(
dns
.
Msg
)
m
.
SetRcode
(
state
.
Req
,
dns
.
RcodeNameError
)
m
.
Ns
=
[]
dns
.
RR
{
NewSOA
()}
m
.
Ns
[
0
]
.
Header
()
.
Ttl
=
minTtl
m
.
Ns
=
[]
dns
.
RR
{
SOA
(
zone
)}
state
.
W
.
WriteMsg
(
m
)
}
...
...
middleware/etcd/lookup.go
View file @
ae841ae3
...
...
@@ -10,7 +10,8 @@ import (
"github.com/miekg/dns"
)
// need current zone argument.
// TODO(miek): factor out common code a bit
func
(
e
Etcd
)
A
(
zone
string
,
state
middleware
.
State
,
previousRecords
[]
dns
.
RR
)
(
records
[]
dns
.
RR
,
err
error
)
{
services
,
err
:=
e
.
Records
(
state
.
Name
(),
false
)
if
err
!=
nil
{
...
...
@@ -24,13 +25,13 @@ func (e Etcd) A(zone string, state middleware.State, previousRecords []dns.RR) (
switch
{
case
ip
==
nil
:
// Try to resolve as CNAME if it's not an IP, but only if we don't create loops.
// TODO(miek): lowercasing, use Match in middleware
/
// TODO(miek): lowercasing, use Match in middleware
?
if
state
.
Name
()
==
dns
.
Fqdn
(
serv
.
Host
)
{
// x CNAME x is a direct loop, don't add those
continue
}
newRecord
:=
serv
.
NewCNAME
(
state
.
QName
(),
dns
.
Fqdn
(
serv
.
Host
)
)
newRecord
:=
serv
.
NewCNAME
(
state
.
QName
(),
serv
.
Host
)
if
len
(
previousRecords
)
>
7
{
// don't add it, and just continue
continue
...
...
@@ -93,7 +94,7 @@ func (e Etcd) AAAA(zone string, state middleware.State, previousRecords []dns.RR
continue
}
newRecord
:=
serv
.
NewCNAME
(
state
.
QName
(),
dns
.
Fqdn
(
serv
.
Host
)
)
newRecord
:=
serv
.
NewCNAME
(
state
.
QName
(),
serv
.
Host
)
if
len
(
previousRecords
)
>
7
{
// don't add it, and just continue
continue
...
...
@@ -297,7 +298,7 @@ func (e Etcd) CNAME(zone string, state middleware.State) (records []dns.RR, err
if
len
(
services
)
>
0
{
serv
:=
services
[
0
]
if
ip
:=
net
.
ParseIP
(
serv
.
Host
);
ip
==
nil
{
records
=
append
(
records
,
serv
.
NewCNAME
(
state
.
QName
(),
dns
.
Fqdn
(
serv
.
Host
)
))
records
=
append
(
records
,
serv
.
NewCNAME
(
state
.
QName
(),
serv
.
Host
))
}
}
return
records
,
nil
...
...
@@ -320,7 +321,8 @@ func (e Etcd) TXT(zone string, state middleware.State) (records []dns.RR, err er
return
records
,
nil
}
func
(
e
Etcd
)
SOA
(
zone
string
,
state
middleware
.
State
)
*
dns
.
SOA
{
// synthesis a SOA Record.
func
SOA
(
zone
string
)
*
dns
.
SOA
{
return
nil
}
...
...
middleware/etcd/msg/service.go
View file @
ae841ae3
...
...
@@ -40,7 +40,7 @@ func (s *Service) NewSRV(name string, weight uint16) *dns.SRV {
host
:=
targetStrip
(
dns
.
Fqdn
(
s
.
Host
),
s
.
TargetStrip
)
return
&
dns
.
SRV
{
Hdr
:
dns
.
RR_Header
{
Name
:
name
,
Rrtype
:
dns
.
TypeSRV
,
Class
:
dns
.
ClassINET
,
Ttl
:
s
.
Ttl
},
Priority
:
uint16
(
s
.
Priority
),
Weight
:
weight
,
Port
:
uint16
(
s
.
Port
),
Target
:
host
}
Priority
:
uint16
(
s
.
Priority
),
Weight
:
weight
,
Port
:
uint16
(
s
.
Port
),
Target
:
dns
.
Fqdn
(
host
)
}
}
// NewMX returns a new MX record based on the Service.
...
...
@@ -63,7 +63,7 @@ func (s *Service) NewAAAA(name string, ip net.IP) *dns.AAAA {
// NewCNAME returns a new CNAME record based on the Service.
func
(
s
*
Service
)
NewCNAME
(
name
string
,
target
string
)
*
dns
.
CNAME
{
return
&
dns
.
CNAME
{
Hdr
:
dns
.
RR_Header
{
Name
:
name
,
Rrtype
:
dns
.
TypeCNAME
,
Class
:
dns
.
ClassINET
,
Ttl
:
s
.
Ttl
},
Target
:
target
}
return
&
dns
.
CNAME
{
Hdr
:
dns
.
RR_Header
{
Name
:
name
,
Rrtype
:
dns
.
TypeCNAME
,
Class
:
dns
.
ClassINET
,
Ttl
:
s
.
Ttl
},
Target
:
dns
.
Fqdn
(
target
)
}
}
// NewTXT returns a new TXT record based on the Service.
...
...
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