Skip to content

Commit

Permalink
Merge pull request #5950 from da2x/dnslink-fqdn
Browse files Browse the repository at this point in the history
Only perform DNSLink lookups on fully qualified domain names (FQDN)
  • Loading branch information
Stebalien authored Jan 29, 2019
2 parents 7ab32c3 + a70dc91 commit 04fa5cf
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 22 deletions.
11 changes: 9 additions & 2 deletions namesys/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type lookupRes struct {
// TXT records for a given domain name should contain a b58
// encoded multihash.
func (r *DNSResolver) resolveOnceAsync(ctx context.Context, name string, options opts.ResolveOpts) <-chan onceResult {
var fqdn string
out := make(chan onceResult, 1)
segments := strings.SplitN(name, "/", 2)
domain := segments[0]
Expand All @@ -56,11 +57,17 @@ func (r *DNSResolver) resolveOnceAsync(ctx context.Context, name string, options
}
log.Debugf("DNSResolver resolving %s", domain)

if strings.HasSuffix(domain, ".") {
fqdn = domain
} else {
fqdn = domain + "."
}

rootChan := make(chan lookupRes, 1)
go workDomain(r, domain, rootChan)
go workDomain(r, fqdn, rootChan)

subChan := make(chan lookupRes, 1)
go workDomain(r, "_dnslink."+domain, subChan)
go workDomain(r, "_dnslink."+fqdn, subChan)

appendPath := func(p path.Path) (path.Path, error) {
if len(segments) > 1 {
Expand Down
44 changes: 24 additions & 20 deletions namesys/dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,68 +61,71 @@ func TestDnsEntryParsing(t *testing.T) {
func newMockDNS() *mockDNS {
return &mockDNS{
entries: map[string][]string{
"multihash.example.com": []string{
"multihash.example.com.": []string{
"dnslink=QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD",
},
"ipfs.example.com": []string{
"ipfs.example.com.": []string{
"dnslink=/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD",
},
"_dnslink.dipfs.example.com": []string{
"_dnslink.dipfs.example.com.": []string{
"dnslink=/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD",
},
"dns1.example.com": []string{
"dns1.example.com.": []string{
"dnslink=/ipns/ipfs.example.com",
},
"dns2.example.com": []string{
"dns2.example.com.": []string{
"dnslink=/ipns/dns1.example.com",
},
"multi.example.com": []string{
"multi.example.com.": []string{
"some stuff",
"dnslink=/ipns/dns1.example.com",
"masked dnslink=/ipns/example.invalid",
},
"equals.example.com": []string{
"equals.example.com.": []string{
"dnslink=/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/=equals",
},
"loop1.example.com": []string{
"loop1.example.com.": []string{
"dnslink=/ipns/loop2.example.com",
},
"loop2.example.com": []string{
"loop2.example.com.": []string{
"dnslink=/ipns/loop1.example.com",
},
"_dnslink.dloop1.example.com": []string{
"_dnslink.dloop1.example.com.": []string{
"dnslink=/ipns/loop2.example.com",
},
"_dnslink.dloop2.example.com": []string{
"_dnslink.dloop2.example.com.": []string{
"dnslink=/ipns/loop1.example.com",
},
"bad.example.com": []string{
"bad.example.com.": []string{
"dnslink=",
},
"withsegment.example.com": []string{
"withsegment.example.com.": []string{
"dnslink=/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/sub/segment",
},
"withrecsegment.example.com": []string{
"withrecsegment.example.com.": []string{
"dnslink=/ipns/withsegment.example.com/subsub",
},
"withtrailing.example.com": []string{
"withtrailing.example.com.": []string{
"dnslink=/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/sub/",
},
"withtrailingrec.example.com": []string{
"withtrailingrec.example.com.": []string{
"dnslink=/ipns/withtrailing.example.com/segment/",
},
"double.example.com": []string{
"double.example.com.": []string{
"dnslink=/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD",
},
"_dnslink.double.example.com": []string{
"_dnslink.double.example.com.": []string{
"dnslink=/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD",
},
"double.conflict.com": []string{
"double.conflict.com.": []string{
"dnslink=/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD",
},
"_dnslink.conflict.example.com": []string{
"_dnslink.conflict.example.com.": []string{
"dnslink=/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjE",
},
"fqdn.example.com.": []string{
"dnslink=/ipfs/QmYvMB9yrsSf7RKBghkfwmHJkzJhW2ZgVwq3LxBXXPasFr",
},
},
}
}
Expand Down Expand Up @@ -159,4 +162,5 @@ func TestDNSResolution(t *testing.T) {
testResolution(t, r, "withtrailingrec.example.com", opts.DefaultDepthLimit, "/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/sub/segment/", nil)
testResolution(t, r, "double.example.com", opts.DefaultDepthLimit, "/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD", nil)
testResolution(t, r, "conflict.example.com", opts.DefaultDepthLimit, "/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjE", nil)
testResolution(t, r, "fqdn.example.com.", opts.DefaultDepthLimit, "/ipfs/QmYvMB9yrsSf7RKBghkfwmHJkzJhW2ZgVwq3LxBXXPasFr", nil)
}

0 comments on commit 04fa5cf

Please sign in to comment.