Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor tunneldns dnsserver configuration #1292

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions tunneldns/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"net"
"strconv"
"sync"
"os"

"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin"
Expand Down Expand Up @@ -90,20 +91,37 @@ func CreateListener(address string, port uint16, upstreams []string, bootstraps
upstreamList = append(upstreamList, upstream)
}

// Create a local cache with HTTPS proxy plugin
chain := cache.New()
chain.Next = ProxyPlugin{
Upstreams: upstreamList,
}

// Format an endpoint
endpoint := "dns://" + net.JoinHostPort(address, strconv.FormatUint(uint64(port), 10))

// get middlewares for DNS Server
middlewares := getMiddlewares(upstreamList)
chain := NewMetricsPlugin(middlewares)

// Create the actual middleware server
server, err := dnsserver.NewServer(endpoint, []*dnsserver.Config{createConfig(address, port, NewMetricsPlugin(chain))})
server, err := dnsserver.NewServer(endpoint, []*dnsserver.Config{createConfig(address, port, chain)})
if err != nil {
return nil, err
}


return &Listener{server: server, log: log}, nil
}

// getMiddlewares() returns the middleware chain for DNS Server
//
// Middleware includes features like...
// * Response Cache
// * HTTP Proxy Settings
func getMiddlewares(upstreamList []Upstream) plugin.Handler {
proxyPlugin := ProxyPlugin{
Upstreams: upstreamList,
}
cachePlugin := cache.New()
cachePlugin.Next = proxyPlugin

if os.Getenv("DISABLE_TUNNELDNS_CACHE") == "true" {
return cachePlugin
}
return proxyPlugin
}