mirror of
https://github.com/coredns/coredns.git
synced 2025-12-08 03:15:41 -05:00
add wildcard parameter to allow resolving multiple name to the same IP (#755)
* add wildcard parameter to allow resolving multiple name to the same IP * first test for the reverse wildcard middleware * update wildcard keyword test to pass code coverage
This commit is contained in:
@@ -38,6 +38,7 @@ func reverseParse(c *caddy.Controller) (nets networks, fall bool, err error) {
|
||||
// normalize zones, validation is almost done by dnsserver
|
||||
// TODO(miek): need sane helpers for these.
|
||||
zones := make([]string, len(c.ServerBlockKeys))
|
||||
wildcard := false
|
||||
|
||||
for i, str := range c.ServerBlockKeys {
|
||||
zones[i] = middleware.Host(str).Normalize()
|
||||
@@ -85,6 +86,9 @@ func reverseParse(c *caddy.Controller) (nets networks, fall bool, err error) {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
case "wildcard":
|
||||
wildcard = true
|
||||
|
||||
case "fallthrough":
|
||||
fall = true
|
||||
|
||||
@@ -117,8 +121,12 @@ func reverseParse(c *caddy.Controller) (nets networks, fall bool, err error) {
|
||||
if ipnet.IP.To4() == nil {
|
||||
regexIP = regexMatchV6
|
||||
}
|
||||
prefix := "^"
|
||||
if wildcard {
|
||||
prefix += ".*"
|
||||
}
|
||||
regex, err := regexp.Compile(
|
||||
"^" + strings.Replace( // inject ip regex into template
|
||||
prefix + strings.Replace( // inject ip regex into template
|
||||
regexp.QuoteMeta(template), // escape dots
|
||||
regexp.QuoteMeta(templateNameIP),
|
||||
regexIP,
|
||||
|
||||
Reference in New Issue
Block a user