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
b87ed01b
Commit
b87ed01b
authored
Aug 16, 2018
by
Eugen Kleiner
Committed by
Yong Tang
Aug 15, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
plugin/forward: Split setup to reuse it from external plugins (#2034)
parent
81d09491
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
49 deletions
+62
-49
plugin/forward/setup.go
plugin/forward/setup.go
+62
-49
No files found.
plugin/forward/setup.go
View file @
b87ed01b
...
@@ -13,6 +13,7 @@ import (
...
@@ -13,6 +13,7 @@ import (
pkgtls
"github.com/coredns/coredns/plugin/pkg/tls"
pkgtls
"github.com/coredns/coredns/plugin/pkg/tls"
"github.com/mholt/caddy"
"github.com/mholt/caddy"
"github.com/mholt/caddy/caddyfile"
)
)
func
init
()
{
func
init
()
{
...
@@ -70,68 +71,80 @@ func (f *Forward) OnShutdown() error {
...
@@ -70,68 +71,80 @@ func (f *Forward) OnShutdown() error {
func
(
f
*
Forward
)
Close
()
{
f
.
OnShutdown
()
}
func
(
f
*
Forward
)
Close
()
{
f
.
OnShutdown
()
}
func
parseForward
(
c
*
caddy
.
Controller
)
(
*
Forward
,
error
)
{
func
parseForward
(
c
*
caddy
.
Controller
)
(
*
Forward
,
error
)
{
f
:=
New
()
var
(
f
*
Forward
protocols
:=
map
[
int
]
int
{}
err
error
i
int
i
:=
0
)
for
c
.
Next
()
{
for
c
.
Next
()
{
if
i
>
0
{
if
i
>
0
{
return
nil
,
plugin
.
ErrOnce
return
nil
,
plugin
.
ErrOnce
}
}
i
++
i
++
f
,
err
=
ParseForwardStanza
(
&
c
.
Dispenser
)
if
!
c
.
Args
(
&
f
.
from
)
{
if
err
!=
nil
{
return
f
,
c
.
ArgErr
()
return
nil
,
err
}
}
f
.
from
=
plugin
.
Host
(
f
.
from
)
.
Normalize
()
}
return
f
,
nil
}
to
:=
c
.
RemainingArgs
()
// ParseForwardStanza parses one forward stanza
if
len
(
to
)
==
0
{
func
ParseForwardStanza
(
c
*
caddyfile
.
Dispenser
)
(
*
Forward
,
error
)
{
return
f
,
c
.
ArgErr
()
f
:=
New
()
}
// A bit fiddly, but first check if we've got protocols and if so add them back in when we create the proxies.
protocols
:=
map
[
int
]
int
{}
protocols
=
make
(
map
[
int
]
int
)
for
i
:=
range
to
{
protocols
[
i
],
to
[
i
]
=
protocol
(
to
[
i
])
}
// If parseHostPortOrFile expands a file with a lot of nameserver our accounting in protocols doesn't make
if
!
c
.
Args
(
&
f
.
from
)
{
// any sense anymore... For now: lets don't care.
return
f
,
c
.
ArgErr
()
toHosts
,
err
:=
dnsutil
.
ParseHostPortOrFile
(
to
...
)
}
if
err
!=
nil
{
f
.
from
=
plugin
.
Host
(
f
.
from
)
.
Normalize
()
return
f
,
err
}
to
:=
c
.
RemainingArgs
()
if
len
(
to
)
==
0
{
return
f
,
c
.
ArgErr
()
}
// A bit fiddly, but first check if we've got protocols and if so add them back in when we create the proxies.
protocols
=
make
(
map
[
int
]
int
)
for
i
:=
range
to
{
protocols
[
i
],
to
[
i
]
=
protocol
(
to
[
i
])
}
// If parseHostPortOrFile expands a file with a lot of nameserver our accounting in protocols doesn't make
// any sense anymore... For now: lets don't care.
toHosts
,
err
:=
dnsutil
.
ParseHostPortOrFile
(
to
...
)
if
err
!=
nil
{
return
f
,
err
}
for
i
,
h
:=
range
toHosts
{
for
i
,
h
:=
range
toHosts
{
// Double check the port, if e.g. is 53 and the transport is TLS make it 853.
// Double check the port, if e.g. is 53 and the transport is TLS make it 853.
// This can be somewhat annoying because you *can't* have TLS on port 53 then.
// This can be somewhat annoying because you *can't* have TLS on port 53 then.
switch
protocols
[
i
]
{
switch
protocols
[
i
]
{
case
TLS
:
case
TLS
:
h1
,
p
,
err
:=
net
.
SplitHostPort
(
h
)
h1
,
p
,
err
:=
net
.
SplitHostPort
(
h
)
if
err
!=
nil
{
if
err
!=
nil
{
break
break
}
// This is more of a bug in dnsutil.ParseHostPortOrFile that defaults to
// 53 because it doesn't know about the tls:// // and friends (that should be fixed). Hence
// Fix the port number here, back to what the user intended.
if
p
==
"53"
{
h
=
net
.
JoinHostPort
(
h1
,
"853"
)
}
}
}
// We can't set tlsConfig here, because we haven't parsed it yet.
// This is more of a bug in dnsutil.ParseHostPortOrFile that defaults to
// We set it below at the end of parseBlock, use nil now.
// 53 because it doesn't know about the tls:// // and friends (that should be fixed). Hence
p
:=
NewProxy
(
h
,
protocols
[
i
])
// Fix the port number here, back to what the user intended.
f
.
proxies
=
append
(
f
.
proxies
,
p
)
if
p
==
"53"
{
h
=
net
.
JoinHostPort
(
h1
,
"853"
)
}
}
}
for
c
.
NextBlock
()
{
// We can't set tlsConfig here, because we haven't parsed it yet.
if
err
:=
parseBlock
(
c
,
f
);
err
!=
nil
{
// We set it below at the end of parseBlock, use nil now.
return
f
,
err
p
:=
NewProxy
(
h
,
protocols
[
i
])
}
f
.
proxies
=
append
(
f
.
proxies
,
p
)
}
for
c
.
NextBlock
()
{
if
err
:=
parseBlock
(
c
,
f
);
err
!=
nil
{
return
f
,
err
}
}
}
}
...
@@ -148,7 +161,7 @@ func parseForward(c *caddy.Controller) (*Forward, error) {
...
@@ -148,7 +161,7 @@ func parseForward(c *caddy.Controller) (*Forward, error) {
return
f
,
nil
return
f
,
nil
}
}
func
parseBlock
(
c
*
caddy
.
Controll
er
,
f
*
Forward
)
error
{
func
parseBlock
(
c
*
caddy
file
.
Dispens
er
,
f
*
Forward
)
error
{
switch
c
.
Val
()
{
switch
c
.
Val
()
{
case
"except"
:
case
"except"
:
ignore
:=
c
.
RemainingArgs
()
ignore
:=
c
.
RemainingArgs
()
...
...
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