mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
Fix SRV record handling when target is shortname (#422)
* models/record.go: SRV targets are case insensitive. Downcase them. * models/t_srv.go: Rename setTargetIntAndStrings() to setTargetSRVIntAndStrings() (makes it easier to search for /setTargetSRV/). * pkg/js/parse_tests/021-srv.js*: SRV: Add parse_tests * pkg/normalize/validate.go: SRV targets are hostnames, turn into FQDNs. * Add #rtype_variations warnings for future developers
This commit is contained in:
@@ -292,10 +292,12 @@ func downcase(recs []*RecordConfig) {
|
|||||||
for _, r := range recs {
|
for _, r := range recs {
|
||||||
r.Name = strings.ToLower(r.Name)
|
r.Name = strings.ToLower(r.Name)
|
||||||
r.NameFQDN = strings.ToLower(r.NameFQDN)
|
r.NameFQDN = strings.ToLower(r.NameFQDN)
|
||||||
switch r.Type {
|
switch r.Type { // #rtype_variations
|
||||||
case "ANAME", "CNAME", "MX", "NS", "PTR":
|
case "ANAME", "CNAME", "MX", "NS", "PTR", "SRV":
|
||||||
|
// These record types have a target that is case insensitive, so we downcase it.
|
||||||
r.Target = strings.ToLower(r.Target)
|
r.Target = strings.ToLower(r.Target)
|
||||||
case "A", "AAAA", "ALIAS", "CAA", "IMPORT_TRANSFORM", "SRV", "TLSA", "TXT", "SOA", "CF_REDIRECT", "CF_TEMP_REDIRECT":
|
case "A", "AAAA", "ALIAS", "CAA", "IMPORT_TRANSFORM", "TLSA", "TXT", "SOA", "CF_REDIRECT", "CF_TEMP_REDIRECT":
|
||||||
|
// These record types have a target that is case sensitive, or is an IP address. We leave them alone.
|
||||||
// Do nothing.
|
// Do nothing.
|
||||||
default:
|
default:
|
||||||
// TODO: we'd like to panic here, but custom record types complicate things.
|
// TODO: we'd like to panic here, but custom record types complicate things.
|
||||||
|
@@ -22,8 +22,8 @@ func (rc *RecordConfig) SetTargetSRV(priority, weight, port uint16, target strin
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// setTargetIntAndStrings is like SetTargetSRV but accepts priority as an int, the other parameters as strings.
|
// setTargetSRVIntAndStrings is like SetTargetSRV but accepts priority as an int, the other parameters as strings.
|
||||||
func (rc *RecordConfig) setTargetIntAndStrings(priority uint16, weight, port, target string) (err error) {
|
func (rc *RecordConfig) setTargetSRVIntAndStrings(priority uint16, weight, port, target string) (err error) {
|
||||||
var i64weight, i64port uint64
|
var i64weight, i64port uint64
|
||||||
if i64weight, err = strconv.ParseUint(weight, 10, 16); err == nil {
|
if i64weight, err = strconv.ParseUint(weight, 10, 16); err == nil {
|
||||||
if i64port, err = strconv.ParseUint(port, 10, 16); err == nil {
|
if i64port, err = strconv.ParseUint(port, 10, 16); err == nil {
|
||||||
@@ -37,7 +37,7 @@ func (rc *RecordConfig) setTargetIntAndStrings(priority uint16, weight, port, ta
|
|||||||
func (rc *RecordConfig) SetTargetSRVStrings(priority, weight, port, target string) (err error) {
|
func (rc *RecordConfig) SetTargetSRVStrings(priority, weight, port, target string) (err error) {
|
||||||
var i64priority uint64
|
var i64priority uint64
|
||||||
if i64priority, err = strconv.ParseUint(priority, 10, 16); err == nil {
|
if i64priority, err = strconv.ParseUint(priority, 10, 16); err == nil {
|
||||||
return rc.setTargetIntAndStrings(uint16(i64priority), weight, port, target)
|
return rc.setTargetSRVIntAndStrings(uint16(i64priority), weight, port, target)
|
||||||
}
|
}
|
||||||
return errors.Wrap(err, "SRV value too big for uint16")
|
return errors.Wrap(err, "SRV value too big for uint16")
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,7 @@ func (rc *RecordConfig) SetTargetSRVPriorityString(priority uint16, s string) er
|
|||||||
if len(part) != 3 {
|
if len(part) != 3 {
|
||||||
return errors.Errorf("SRV value does not contain 3 fields: (%#v)", s)
|
return errors.Errorf("SRV value does not contain 3 fields: (%#v)", s)
|
||||||
}
|
}
|
||||||
return rc.setTargetIntAndStrings(priority, part[0], part[1], part[2])
|
return rc.setTargetSRVIntAndStrings(priority, part[0], part[1], part[2])
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetTargetSRVString is like SetTargetSRV but accepts one big string to be parsed.
|
// SetTargetSRVString is like SetTargetSRV but accepts one big string to be parsed.
|
||||||
|
7
pkg/js/parse_tests/021-srv.js
Normal file
7
pkg/js/parse_tests/021-srv.js
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
D("foo.com","none"
|
||||||
|
, SRV('_ntp._udp', 1, 100, 123, 'one.foo.com.')
|
||||||
|
, SRV('_ntp._udp', 2, 100, 123, 'two')
|
||||||
|
, SRV('_ntp._udp', 3, 100, 123, 'localhost')
|
||||||
|
, SRV('_ntp._udp', 4, 100, 123, 'three.example.com.')
|
||||||
|
, SRV('_ntp._udp', 0, 0, 1, 'zeros')
|
||||||
|
);
|
51
pkg/js/parse_tests/021-srv.json
Normal file
51
pkg/js/parse_tests/021-srv.json
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
{
|
||||||
|
"dns_providers": [],
|
||||||
|
"domains": [
|
||||||
|
{
|
||||||
|
"dnsProviders": {},
|
||||||
|
"name": "foo.com",
|
||||||
|
"records": [
|
||||||
|
{
|
||||||
|
"name": "_ntp._udp",
|
||||||
|
"srvport": 123,
|
||||||
|
"srvpriority": 1,
|
||||||
|
"srvweight": 100,
|
||||||
|
"target": "one.foo.com.",
|
||||||
|
"type": "SRV"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "_ntp._udp",
|
||||||
|
"srvport": 123,
|
||||||
|
"srvpriority": 2,
|
||||||
|
"srvweight": 100,
|
||||||
|
"target": "two",
|
||||||
|
"type": "SRV"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "_ntp._udp",
|
||||||
|
"srvport": 123,
|
||||||
|
"srvpriority": 3,
|
||||||
|
"srvweight": 100,
|
||||||
|
"target": "localhost",
|
||||||
|
"type": "SRV"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "_ntp._udp",
|
||||||
|
"srvport": 123,
|
||||||
|
"srvpriority": 4,
|
||||||
|
"srvweight": 100,
|
||||||
|
"target": "three.example.com.",
|
||||||
|
"type": "SRV"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "_ntp._udp",
|
||||||
|
"srvport": 1,
|
||||||
|
"target": "zeros",
|
||||||
|
"type": "SRV"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"registrar": "none"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"registrars": []
|
||||||
|
}
|
@@ -285,7 +285,11 @@ func NormalizeAndValidateConfig(config *models.DNSConfig) (errs []error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Canonicalize Targets.
|
// Canonicalize Targets.
|
||||||
if rec.Type == "CNAME" || rec.Type == "MX" || rec.Type == "NS" {
|
if rec.Type == "CNAME" || rec.Type == "MX" || rec.Type == "NS" || rec.Type == "SRV" {
|
||||||
|
// #rtype_variations
|
||||||
|
// These record types have a target that is a hostname.
|
||||||
|
// We normalize them to a FQDN so there is less variation to handle. If a
|
||||||
|
// provider API requires a shortname, the provider must do the shortening.
|
||||||
rec.SetTarget(dnsutil.AddOrigin(rec.GetTargetField(), domain.Name+"."))
|
rec.SetTarget(dnsutil.AddOrigin(rec.GetTargetField(), domain.Name+"."))
|
||||||
} else if rec.Type == "A" || rec.Type == "AAAA" {
|
} else if rec.Type == "A" || rec.Type == "AAAA" {
|
||||||
rec.SetTarget(net.ParseIP(rec.GetTargetField()).String())
|
rec.SetTarget(net.ParseIP(rec.GetTargetField()).String())
|
||||||
|
Reference in New Issue
Block a user