Skip to content

Commit 0de2288

Browse files
authored
Merge pull request #10 from shadow3x3x3/wildcard-support
support wildcard records
2 parents 1e57db0 + 11f8c00 commit 0de2288

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ mysql {
3232

3333
## Supported Record Types
3434

35-
A, AAAA, CNAME, SOA, TXT, NS, MX, CAA and SRV. This backend doesn't support AXFR requests. It also doesn't support wildcard records yet.
35+
A, AAAA, CNAME, SOA, TXT, NS, MX, CAA and SRV. Wildcard records are supported as well. This backend doesn't support AXFR requests.
3636

3737
## Setup (as an external plugin)
3838

mysql.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,32 @@ func (handler *CoreDNSMySql) findRecord(zone string, name string, types ...strin
4949
})
5050
}
5151

52+
// If no records found, check for wildcard records.
53+
if len(records) == 0 && name != zone {
54+
return handler.findWildcardRecords(zone, name, types...)
55+
}
56+
5257
return records, nil
5358
}
5459

60+
// findWildcardRecords attempts to find wildcard records
61+
// recursively until it finds matching records.
62+
// e.g. zone: example.com
63+
// x.y.z.example.com -> *.y.z.example.com -> *.z.example.com -> *.example.com
64+
func (handler *CoreDNSMySql) findWildcardRecords(zone string, name string, types ...string) ([]*Record, error) {
65+
const dot = "."
66+
67+
subNames := strings.Split(name, dot)
68+
nextSubNames := subNames[1:]
69+
if subNames[0] == "*" {
70+
nextSubNames = subNames[2:]
71+
}
72+
73+
names := append([]string{"*"}, nextSubNames...)
74+
target := strings.Join(names, dot)
75+
return handler.findRecord(zone, target, types...)
76+
}
77+
5578
func (handler *CoreDNSMySql) loadZones() error {
5679
db, err := handler.db()
5780
if err != nil {

0 commit comments

Comments
 (0)