aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2018-01-08 15:03:42 +0000
committerGravatar GitHub <noreply@github.com> 2018-01-08 15:03:42 +0000
commita7590897fbe433129e661d7d85f4635a8601ade1 (patch)
tree7c2fe5ad056b944036ef4f05ce0a42fdc6544fca
parentdd37627e8e42aeb9410b697fa18c8157accf74f9 (diff)
downloadcoredns-a7590897fbe433129e661d7d85f4635a8601ade1.tar.gz
coredns-a7590897fbe433129e661d7d85f4635a8601ade1.tar.zst
coredns-a7590897fbe433129e661d7d85f4635a8601ade1.zip
plugin/proxy: max the number of upstreams (#1359)
* plugin/proxy: max the number of upstreams Put a max of 15 on the number of upstreams.
-rw-r--r--plugin/proxy/upstream.go6
-rw-r--r--plugin/proxy/upstream_test.go12
2 files changed, 17 insertions, 1 deletions
diff --git a/plugin/proxy/upstream.go b/plugin/proxy/upstream.go
index 151fcad60..bcb921973 100644
--- a/plugin/proxy/upstream.go
+++ b/plugin/proxy/upstream.go
@@ -53,6 +53,10 @@ func NewStaticUpstreams(c *caddyfile.Dispenser) ([]Upstream, error) {
return upstreams, err
}
+ if len(toHosts) > max {
+ return upstreams, fmt.Errorf("more than %d TOs configured: %d", max, len(toHosts))
+ }
+
for c.NextBlock() {
if err := parseBlock(c, upstream); err != nil {
return upstreams, err
@@ -192,3 +196,5 @@ func (u *staticUpstream) IsAllowedDomain(name string) bool {
func (u *staticUpstream) Exchanger() Exchanger { return u.ex }
func (u *staticUpstream) From() string { return u.from }
+
+const max = 15
diff --git a/plugin/proxy/upstream_test.go b/plugin/proxy/upstream_test.go
index 98509f738..6fec3e30a 100644
--- a/plugin/proxy/upstream_test.go
+++ b/plugin/proxy/upstream_test.go
@@ -259,7 +259,7 @@ proxy . FILE
proxy example.org 2.2.2.2:1234
`,
`
-junky resolve.conf
+junky resolv.conf
`,
false,
[]string{"1.1.1.1:5000", "2.2.2.2:1234"},
@@ -303,6 +303,16 @@ junky resolve.conf
}
}
+func TestMaxTo(t *testing.T) {
+ // Has 16 IP addresses.
+ config := `proxy . 1.1.1.1 1.1.1.1 1.1.1.1 1.1.1.1 1.1.1.1 1.1.1.1 1.1.1.1 1.1.1.1 1.1.1.1 1.1.1.1 1.1.1.1 1.1.1.1 1.1.1.1 1.1.1.1 1.1.1.1 1.1.1.1`
+ c := caddy.NewTestController("dns", config)
+ _, err := NewStaticUpstreams(&c.Dispenser)
+ if err == nil {
+ t.Error("Expected to many TOs configured, but nil")
+ }
+}
+
func getPEMFiles(t *testing.T) (rmFunc func(), cert, key, ca string) {
tempDir, rmFunc, err := test.WritePEMFiles("")
if err != nil {