maddy/internal/dns/resolver.go
fox.cpp 48e21f566e
Extend .debug.* flags and hide them by default
Allow to override DNS resolver address via the -debug.dnsoverride flag
and SMTP port via -debug.smtpport.

All flags are not available unless maddy is built using the 'debugflags'
tag.
2019-12-13 17:31:35 +03:00

43 lines
1.3 KiB
Go

// Package dns defines interfaces used by maddy modules to perform DNS
// lookups.
//
// Currently, there is only Resolver interface which is implemented
// by dns.DefaultResolver(). In the future, DNSSEC-enabled stub resolver
// implementation will be added here.
package dns
import (
"context"
"net"
"strings"
)
// Resolver is an interface that describes DNS-related methods used by maddy.
//
// It is implemented by dns.DefaultResolver(). Methods behave the same way.
type Resolver interface {
LookupAddr(ctx context.Context, addr string) (names []string, err error)
LookupHost(ctx context.Context, host string) (addrs []string, err error)
LookupMX(ctx context.Context, name string) ([]*net.MX, error)
LookupTXT(ctx context.Context, name string) ([]string, error)
LookupIPAddr(ctx context.Context, host string) ([]net.IPAddr, error)
}
// LookupAddr is a convenience wrapper for Resolver.LookupAddr.
//
// It returns the first name with trailing dot stripped.
func LookupAddr(ctx context.Context, r Resolver, ip net.IP) (string, error) {
names, err := r.LookupAddr(ctx, ip.String())
if err != nil || len(names) == 0 {
return "", err
}
return strings.TrimRight(names[0], "."), nil
}
func DefaultResolver() Resolver {
if overrideServ != "" && overrideServ != "system-default" {
override(overrideServ)
}
return net.DefaultResolver
}