Package io.netty.resolver.dns
Class UnixResolverDnsServerAddressStreamProvider
- java.lang.Object
-
- io.netty.resolver.dns.UnixResolverDnsServerAddressStreamProvider
-
- All Implemented Interfaces:
DnsServerAddressStreamProvider
public final class UnixResolverDnsServerAddressStreamProvider extends java.lang.Object implements DnsServerAddressStreamProvider
Able to parse files such as /etc/resolv.conf and /etc/resolver to respect the system default domain servers.
-
-
Field Summary
Fields Modifier and Type Field Description private DnsServerAddressesdefaultNameServerAddressesprivate static java.lang.StringDOMAIN_ROW_LABELprivate java.util.Map<java.lang.String,DnsServerAddresses>domainToNameServerStreamMapprivate static java.lang.StringETC_RESOLV_CONF_FILEprivate static java.lang.StringETC_RESOLVER_DIRprivate static InternalLoggerloggerprivate static java.lang.StringNAMESERVER_ROW_LABELprivate static java.lang.StringOPTIONS_ROTATE_FLAGprivate static java.lang.StringOPTIONS_ROW_LABELprivate static java.lang.StringPORT_ROW_LABELprivate static java.lang.StringRES_OPTIONSprivate static java.lang.StringSEARCH_ROW_LABELprivate static java.lang.StringSORTLIST_ROW_LABELprivate static java.util.regex.PatternWHITESPACE_PATTERN
-
Constructor Summary
Constructors Constructor Description UnixResolverDnsServerAddressStreamProvider(java.io.File etcResolvConf, java.io.File... etcResolverFiles)Parse a file of the format /etc/resolv.conf which may contain the default DNS server to use, and also overrides for individual domains.UnixResolverDnsServerAddressStreamProvider(java.lang.String etcResolvConf, java.lang.String etcResolverDir)Parse a file of the format /etc/resolv.conf which may contain the default DNS server to use, and also overrides for individual domains.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private booleanmayOverrideNameServers()DnsServerAddressStreamnameServerAddressStream(java.lang.String hostname)Ask this provider for the name servers to query forhostname.private static java.util.Map<java.lang.String,DnsServerAddresses>parse(java.io.File... etcResolverFiles)(package private) static UnixResolverOptionsparseEtcResolverOptions()Parse /etc/resolv.conf and return options of interest, namely: timeout, attempts and ndots.(package private) static UnixResolverOptionsparseEtcResolverOptions(java.io.File etcResolvConf)Parse a file of the format /etc/resolv.conf and return options of interest, namely: timeout, attempts and ndots.(package private) static java.util.List<java.lang.String>parseEtcResolverSearchDomains()Parse a file of the format /etc/resolv.conf and return the list of search domains found in it or an empty list if not found.(package private) static java.util.List<java.lang.String>parseEtcResolverSearchDomains(java.io.File etcResolvConf)Parse a file of the format /etc/resolv.conf and return the list of search domains found in it or an empty list if not found.private static intparseResIntOption(java.lang.String opt, java.lang.String fullLabel)private static voidparseResOptions(java.lang.String line, UnixResolverOptions.Builder builder)(package private) static DnsServerAddressStreamProviderparseSilently()Attempt to parse/etc/resolv.confand files in the/etc/resolverdirectory by default.private static voidputIfAbsent(java.util.Map<java.lang.String,DnsServerAddresses> domainToNameServerStreamMap, java.lang.String domainName, DnsServerAddresses addresses)private static voidputIfAbsent(java.util.Map<java.lang.String,DnsServerAddresses> domainToNameServerStreamMap, java.lang.String domainName, java.util.List<java.net.InetSocketAddress> addresses, boolean rotate)
-
-
-
Field Detail
-
logger
private static final InternalLogger logger
-
WHITESPACE_PATTERN
private static final java.util.regex.Pattern WHITESPACE_PATTERN
-
RES_OPTIONS
private static final java.lang.String RES_OPTIONS
-
ETC_RESOLV_CONF_FILE
private static final java.lang.String ETC_RESOLV_CONF_FILE
- See Also:
- Constant Field Values
-
ETC_RESOLVER_DIR
private static final java.lang.String ETC_RESOLVER_DIR
- See Also:
- Constant Field Values
-
NAMESERVER_ROW_LABEL
private static final java.lang.String NAMESERVER_ROW_LABEL
- See Also:
- Constant Field Values
-
SORTLIST_ROW_LABEL
private static final java.lang.String SORTLIST_ROW_LABEL
- See Also:
- Constant Field Values
-
OPTIONS_ROW_LABEL
private static final java.lang.String OPTIONS_ROW_LABEL
- See Also:
- Constant Field Values
-
OPTIONS_ROTATE_FLAG
private static final java.lang.String OPTIONS_ROTATE_FLAG
- See Also:
- Constant Field Values
-
DOMAIN_ROW_LABEL
private static final java.lang.String DOMAIN_ROW_LABEL
- See Also:
- Constant Field Values
-
SEARCH_ROW_LABEL
private static final java.lang.String SEARCH_ROW_LABEL
- See Also:
- Constant Field Values
-
PORT_ROW_LABEL
private static final java.lang.String PORT_ROW_LABEL
- See Also:
- Constant Field Values
-
defaultNameServerAddresses
private final DnsServerAddresses defaultNameServerAddresses
-
domainToNameServerStreamMap
private final java.util.Map<java.lang.String,DnsServerAddresses> domainToNameServerStreamMap
-
-
Constructor Detail
-
UnixResolverDnsServerAddressStreamProvider
public UnixResolverDnsServerAddressStreamProvider(java.io.File etcResolvConf, java.io.File... etcResolverFiles) throws java.io.IOExceptionParse a file of the format /etc/resolv.conf which may contain the default DNS server to use, and also overrides for individual domains. Also parse list of files of the format /etc/resolver which may contain multiple files to override the name servers used for multimple domains.- Parameters:
etcResolvConf- /etc/resolv.conf.etcResolverFiles- List of files of the format defined in /etc/resolver.- Throws:
java.io.IOException- If an error occurs while parsing the input files.
-
UnixResolverDnsServerAddressStreamProvider
public UnixResolverDnsServerAddressStreamProvider(java.lang.String etcResolvConf, java.lang.String etcResolverDir) throws java.io.IOExceptionParse a file of the format /etc/resolv.conf which may contain the default DNS server to use, and also overrides for individual domains. Also parse a directory of the format /etc/resolver which may contain multiple files to override the name servers used for multimple domains.- Parameters:
etcResolvConf- /etc/resolv.conf.etcResolverDir- Directory containing files of the format defined in /etc/resolver.- Throws:
java.io.IOException- If an error occurs while parsing the input files.
-
-
Method Detail
-
parseSilently
static DnsServerAddressStreamProvider parseSilently()
Attempt to parse/etc/resolv.confand files in the/etc/resolverdirectory by default. A failure to parse will returnDefaultDnsServerAddressStreamProvider.
-
nameServerAddressStream
public DnsServerAddressStream nameServerAddressStream(java.lang.String hostname)
Description copied from interface:DnsServerAddressStreamProviderAsk this provider for the name servers to query forhostname.- Specified by:
nameServerAddressStreamin interfaceDnsServerAddressStreamProvider- Parameters:
hostname- The hostname for which to lookup the DNS server addressed to use. If this is the finalDnsServerAddressStreamProviderto be queried then generally empty string or'.'correspond to the defaultDnsServerAddressStream.- Returns:
- The
DnsServerAddressStreamwhich should be used to resolvehostname.
-
mayOverrideNameServers
private boolean mayOverrideNameServers()
-
parse
private static java.util.Map<java.lang.String,DnsServerAddresses> parse(java.io.File... etcResolverFiles) throws java.io.IOException
- Throws:
java.io.IOException
-
putIfAbsent
private static void putIfAbsent(java.util.Map<java.lang.String,DnsServerAddresses> domainToNameServerStreamMap, java.lang.String domainName, java.util.List<java.net.InetSocketAddress> addresses, boolean rotate)
-
putIfAbsent
private static void putIfAbsent(java.util.Map<java.lang.String,DnsServerAddresses> domainToNameServerStreamMap, java.lang.String domainName, DnsServerAddresses addresses)
-
parseEtcResolverOptions
static UnixResolverOptions parseEtcResolverOptions() throws java.io.IOException
Parse /etc/resolv.conf and return options of interest, namely: timeout, attempts and ndots.- Returns:
- The options values provided by /etc/resolve.conf.
- Throws:
java.io.IOException- If a failure occurs parsing the file.
-
parseEtcResolverOptions
static UnixResolverOptions parseEtcResolverOptions(java.io.File etcResolvConf) throws java.io.IOException
Parse a file of the format /etc/resolv.conf and return options of interest, namely: timeout, attempts and ndots.- Parameters:
etcResolvConf- a file of the format /etc/resolv.conf.- Returns:
- The options values provided by /etc/resolve.conf.
- Throws:
java.io.IOException- If a failure occurs parsing the file.
-
parseResOptions
private static void parseResOptions(java.lang.String line, UnixResolverOptions.Builder builder)
-
parseResIntOption
private static int parseResIntOption(java.lang.String opt, java.lang.String fullLabel)
-
parseEtcResolverSearchDomains
static java.util.List<java.lang.String> parseEtcResolverSearchDomains() throws java.io.IOExceptionParse a file of the format /etc/resolv.conf and return the list of search domains found in it or an empty list if not found.- Returns:
- List of search domains.
- Throws:
java.io.IOException- If a failure occurs parsing the file.
-
parseEtcResolverSearchDomains
static java.util.List<java.lang.String> parseEtcResolverSearchDomains(java.io.File etcResolvConf) throws java.io.IOExceptionParse a file of the format /etc/resolv.conf and return the list of search domains found in it or an empty list if not found.- Parameters:
etcResolvConf- a file of the format /etc/resolv.conf.- Returns:
- List of search domains.
- Throws:
java.io.IOException- If a failure occurs parsing the file.
-
-