diff --git a/bind.go b/bind.go index 4a800a41..60e24127 100644 --- a/bind.go +++ b/bind.go @@ -5,6 +5,8 @@ import ( "io" "net" "os" + "regexp" + "strconv" "strings" "github.com/aws/aws-sdk-go/aws" @@ -77,6 +79,16 @@ func ConvertBindToRR(record dns.RR) *route53.ResourceRecord { return &route53.ResourceRecord{ Value: aws.String(value), } + case *dns.NAPTR: + var value string + if record.Replacement == "." { + value = fmt.Sprintf("%d %d \"%s\" \"%s\" \"%s\" .", record.Order, record.Preference, record.Flags, record.Service, record.Regexp) + } else { + value = fmt.Sprintf("%d %d \"%s\" \"%s\" \"\" \"%s\"", record.Order, record.Preference, record.Flags, record.Service, record.Replacement) + } + return &route53.ResourceRecord{ + Value: aws.String(value), + } case *dns.NS: return &route53.ResourceRecord{ Value: aws.String(record.Ns), @@ -200,6 +212,8 @@ func absolute(name string) string { return name } +var reNaptr = regexp.MustCompile(`^([[:digit:]]+) ([[:digit:]]+) "([^"]*)" "([^"]*)" "([^"]*)" "?([^"]+)"?$`) + // ConvertRRSetToBind will convert a ResourceRecordSet to an array of RR entries func ConvertRRSetToBind(rrset *route53.ResourceRecordSet) []dns.RR { ret := []dns.RR{} @@ -294,6 +308,29 @@ func ConvertRRSetToBind(rrset *route53.ResourceRecordSet) []dns.RR { } ret = append(ret, dnsrr) } + case "NAPTR": + for _, rr := range rrset.ResourceRecords { + // parse value + naptr := reNaptr.FindStringSubmatch(*rr.Value) + order, _ := strconv.Atoi(naptr[1]) + preference, _ := strconv.Atoi(naptr[2]) + + dnsrr := &dns.NAPTR{ + Hdr: dns.RR_Header{ + Name: name, + Rrtype: dns.TypeNAPTR, + Class: dns.ClassINET, + Ttl: uint32(*rrset.TTL), + }, + Order: uint16(order), + Preference: uint16(preference), + Flags: naptr[3], + Service: naptr[4], + Regexp: naptr[5], + Replacement: naptr[6], + } + ret = append(ret, dnsrr) + } case "NS": for _, rr := range rrset.ResourceRecords { dnsrr := &dns.NS{ diff --git a/bind_test.go b/bind_test.go index 43c9ed98..9b1d1f51 100644 --- a/bind_test.go +++ b/bind_test.go @@ -291,6 +291,34 @@ var testConvertRRSetToBindTable = []struct { }, }, }, + { + Input: route53.ResourceRecordSet{ + Type: aws.String("NAPTR"), + Name: aws.String("example.com."), + ResourceRecords: []*route53.ResourceRecord{ + &route53.ResourceRecord{ + Value: aws.String(`100 10 "u" "sip+E2U" "!^.*$!sip:information@foo.se!i" .`), + }, + }, + TTL: aws.Int64(86400), + }, + Output: []dns.RR{ + &dns.NAPTR{ + Hdr: dns.RR_Header{ + Name: "example.com.", + Rrtype: dns.TypeNAPTR, + Class: dns.ClassINET, + Ttl: uint32(86400), + }, + Order: 100, + Preference: 10, + Flags: "u", + Service: "sip+E2U", + Regexp: "!^.*$!sip:information@foo.se!i", + Replacement: ".", + }, + }, + }, { Input: route53.ResourceRecordSet{ Type: aws.String("A"), diff --git a/tests/basic.txt b/tests/basic.txt index 466ad4e2..836a7d05 100644 --- a/tests/basic.txt +++ b/tests/basic.txt @@ -13,3 +13,5 @@ test 86400 IN TXT "multivalued" " txt \"quoted\" record" www 86400 IN A 10.0.0.1 web 86400 IN CNAME www google 86400 IN CNAME www.google.com. +rfc3403-1 86400 IN NAPTR 100 10 "u" "sip+E2U" "!^.*$!sip:information@foo.se!i" . +rfc3403-2 86400 IN NAPTR 100 50 "a" "z3950+N2L+N2C" "" cidserver.example.com.