From 0ec36c824a031a5f1e8f2f520abb5935eb6826f2 Mon Sep 17 00:00:00 2001 From: Mehmet Dogan Date: Tue, 6 May 2014 15:39:59 +0300 Subject: [PATCH] Added matching hostname when interface has wildcards. Fixes #2396. --- .../com/hazelcast/impl/AddressPicker.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/hazelcast/src/main/java/com/hazelcast/impl/AddressPicker.java b/hazelcast/src/main/java/com/hazelcast/impl/AddressPicker.java index 0db293a98cc7..b32c0922a0a7 100644 --- a/hazelcast/src/main/java/com/hazelcast/impl/AddressPicker.java +++ b/hazelcast/src/main/java/com/hazelcast/impl/AddressPicker.java @@ -197,7 +197,8 @@ private Collection getInterfaces(final NetworkConfig networ final Collection configInterfaces = networkConfig.getInterfaces().getInterfaces(); for (String configInterface : configInterfaces) { if (AddressUtil.isIpAddress(configInterface)) { - interfaces.add(new InterfaceDefinition(addressDomainMap.get(configInterface), configInterface)); + String hostname = findHostnameMatchingInterface(addressDomainMap, configInterface); + interfaces.add(new InterfaceDefinition(hostname, configInterface)); } else { logger.log(Level.INFO, "'" + configInterface + "' is not an IP address! Removing from interface list."); @@ -215,6 +216,20 @@ private Collection getInterfaces(final NetworkConfig networ return interfaces; } + private String findHostnameMatchingInterface(Map addressDomainMap, String configInterface) { + String hostname = addressDomainMap.get(configInterface); + if (hostname != null) { + return hostname; + } + for (Entry entry : addressDomainMap.entrySet()) { + String address = entry.getKey(); + if (AddressUtil.matchInterface(address, configInterface)) { + return entry.getValue(); + } + } + return null; + } + private Collection resolveDomainNames(final String domainName) throws UnknownHostException { final InetAddress[] inetAddresses = InetAddress.getAllByName(domainName); @@ -298,7 +313,8 @@ private AddressDefinition pickMatchingAddress(final Collection interfaces) { for (final InterfaceDefinition inf : interfaces) { - if (AddressUtil.matchInterface(address.getHostAddress(), inf.address)) { + String interfaceMask = inf.address; + if (AddressUtil.matchInterface(address.getHostAddress(), interfaceMask)) { return new AddressDefinition(inf.host, address); } }